schema-related information (like schema version, DB syntax, etc.) moved from "config...
[public/netxms.git] / src / server / include / nms_core.h
CommitLineData
5039dede
AK
1/* $Id$ */
2/*
3** NetXMS - Network Management System
4** Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Victor Kirhenshtein
5**
6** This program is free software; you can redistribute it and/or modify
7** it under the terms of the GNU General Public License as published by
8** the Free Software Foundation; either version 2 of the License, or
9** (at your option) any later version.
10**
11** This program is distributed in the hope that it will be useful,
12** but WITHOUT ANY WARRANTY; without even the implied warranty of
13** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14** GNU General Public License for more details.
15**
16** You should have received a copy of the GNU General Public License
17** along with this program; if not, write to the Free Software
18** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19**
20** File: nms_core.h
21**
22**/
23
24#ifndef _nms_core_h_
25#define _nms_core_h_
26
27#ifdef _WIN32
28#ifdef NXCORE_EXPORTS
29#define NXCORE_EXPORTABLE __declspec(dllexport)
30#else
31#define NXCORE_EXPORTABLE __declspec(dllimport)
32#endif
33#else /* _WIN32 */
34#define NXCORE_EXPORTABLE
35#endif
36
37#define LIBNXCL_NO_DECLARATIONS 1
38
39#include <nms_common.h>
40
41#ifndef _WIN32
42
43#if HAVE_SYS_TYPES_H
44# include <sys/types.h>
45#endif
46
47#if HAVE_DLFCN_H
48#include <dlfcn.h>
49#endif
50
51#define WSAGetLastError() (errno)
52
53#endif /* _WIN32 */
54
55#include <time.h>
56#include <stdio.h>
57#include <string.h>
58#include <stdarg.h>
59
60#define SHOW_FLAG_VALUE(x) _T(" %-32s = %d\n"), _T(#x), (g_dwFlags & x) ? 1 : 0
61
62
63//
64// Common includes
65//
66
67#include <nms_util.h>
68#include <dbdrv.h>
69#include <nms_cscp.h>
70#include <uuid.h>
71#include <nxsrvapi.h>
72#include <nximage.h>
73#include <nxqueue.h>
74#include <nxsnmp.h>
75#include <nxmodule.h>
76#include <nxsl.h>
77
78
79//
80// Console context
81//
82
83struct __console_ctx
84{
85 SOCKET hSocket;
86 CSCPMessage *pMsg;
87};
88
89typedef __console_ctx * CONSOLE_CTX;
90
91
92//
93// Server includes
94//
95
96#include "nms_dcoll.h"
97#include "nms_users.h"
98#include "nms_objects.h"
5039dede
AK
99#include "nms_locks.h"
100#include "nms_pkg.h"
101#include "nms_topo.h"
102#include "nms_script.h"
103#include "nxcore_maps.h"
104#include "nxcore_situations.h"
105
106
107//
108// Common constants and macros
109//
110
111#define MAX_LINE_SIZE 4096
112
113#define GROUP_FLAG_BIT ((DWORD)0x80000000)
114
115typedef void * HSNMPSESSION;
116
117#define CHECKPOINT_SNMP_PORT 260
118
119
5039dede
AK
120//
121// Unique identifier group codes
122//
123
124#define IDG_NETWORK_OBJECT 0
125#define IDG_CONTAINER_CAT 1
126#define IDG_EVENT 2
127#define IDG_ITEM 3
128#define IDG_SNMP_TRAP 4
129#define IDG_IMAGE 5
130#define IDG_ACTION 6
131#define IDG_EVENT_GROUP 7
132#define IDG_THRESHOLD 8
133#define IDG_USER 9
134#define IDG_USER_GROUP 10
135#define IDG_ALARM 11
136#define IDG_ALARM_NOTE 12
137#define IDG_PACKAGE 13
47912c44 138//#define IDG_LPP 14
5039dede
AK
139#define IDG_OBJECT_TOOL 15
140#define IDG_SCRIPT 16
141#define IDG_AGENT_CONFIG 17
142#define IDG_GRAPH 18
143#define IDG_CERTIFICATE 19
144#define IDG_SITUATION 20
145#define IDG_MAP 21
146
147
148//
149// Exit codes for console commands
150//
151
152#define CMD_EXIT_CONTINUE 0
153#define CMD_EXIT_CLOSE_SESSION 1
154#define CMD_EXIT_SHUTDOWN 2
155
156
157//
158// Network discovery mode
159//
160
161#define DISCOVERY_DISABLED 0
162#define DISCOVERY_PASSIVE_ONLY 1
163#define DISCOVERY_ACTIVE 2
164
165
166//
167// Client session flags
168//
169
170#define CSF_EVENT_DB_LOCKED ((DWORD)0x0001)
171#define CSF_EPP_LOCKED ((DWORD)0x0002)
172#define CSF_PACKAGE_DB_LOCKED ((DWORD)0x0004)
173#define CSF_USER_DB_LOCKED ((DWORD)0x0008)
174#define CSF_EPP_UPLOAD ((DWORD)0x0010)
175#define CSF_ACTION_DB_LOCKED ((DWORD)0x0020)
176#define CSF_TRAP_CFG_LOCKED ((DWORD)0x0040)
177#define CSF_AUTHENTICATED ((DWORD)0x0080)
178#define CSF_OBJECT_TOOLS_LOCKED ((DWORD)0x0100)
179#define CSF_RECEIVING_MAP_DATA ((DWORD)0x0200)
180#define CSF_SYNC_OBJECT_COMMENTS ((DWORD)0x0400)
181
182
183//
184// Client session states
185//
186
187#define SESSION_STATE_INIT 0
188#define SESSION_STATE_IDLE 1
189#define SESSION_STATE_PROCESSING 2
190
191
192//
193// Information categories for UPDATE_INFO structure
194//
195
196#define INFO_CAT_EVENT 1
197#define INFO_CAT_OBJECT_CHANGE 2
198#define INFO_CAT_ALARM 3
199#define INFO_CAT_ACTION 4
200#define INFO_CAT_SYSLOG_MSG 5
201#define INFO_CAT_SNMP_TRAP 6
202#define INFO_CAT_AUDIT_RECORD 7
203#define INFO_CAT_SITUATION 8
204
205
206//
207// Certificate types
208//
209
210#define CERT_TYPE_TRUSTED_CA 0
211#define CERT_TYPE_USER 1
212
213
214//
215// Audit subsystems
216//
217
218#define AUDIT_SECURITY _T("SECURITY")
219#define AUDIT_OBJECTS _T("OBJECTS")
220#define AUDIT_SYSCFG _T("SYSCFG")
221#define AUDIT_CONSOLE _T("CONSOLE")
222
223
224//
225// Event handling subsystem definitions
226//
227
228#include "nms_events.h"
229#include "nms_actions.h"
230#include "nms_alarm.h"
231
232
233//
234// New node information
235//
236
237typedef struct
238{
239 DWORD dwIpAddr;
240 DWORD dwNetMask;
241 BOOL ignoreFilter;
242} NEW_NODE;
243
244
245//
246// New node flags
247//
248
249#define NNF_IS_SNMP 0x0001
250#define NNF_IS_AGENT 0x0002
251#define NNF_IS_ROUTER 0x0004
252#define NNF_IS_BRIDGE 0x0008
253#define NNF_IS_PRINTER 0x0010
254#define NNF_IS_CDP 0x0020
255#define NNF_IS_SONMP 0x0040
256#define NNF_IS_LLDP 0x0080
257
258
259//
260// Node information for autodiscovery filter
261//
262
263typedef struct
264{
265 DWORD dwIpAddr;
266 DWORD dwNetMask;
267 DWORD dwSubnetAddr;
268 DWORD dwFlags;
269 int nSNMPVersion;
270 char szObjectId[MAX_OID_LEN * 4]; // SNMP OID
271 char szAgentVersion[MAX_AGENT_VERSION_LEN];
272 char szPlatform[MAX_PLATFORM_NAME_LEN];
273} DISCOVERY_FILTER_DATA;
274
275
276//
277// Data update structure for client sessions
278//
279
280typedef struct
281{
282 DWORD dwCategory; // Data category - event, network object, etc.
283 DWORD dwCode; // Data-specific update code
284 void *pData; // Pointer to data block
285} UPDATE_INFO;
286
287
288//
289// Extended agent connection
290//
291
292class AgentConnectionEx : public AgentConnection
293{
294protected:
295 virtual void OnTrap(CSCPMessage *pMsg);
296
297public:
298 AgentConnectionEx() : AgentConnection() { }
299 AgentConnectionEx(DWORD dwAddr, WORD wPort = AGENT_LISTEN_PORT,
300 int iAuthMethod = AUTH_NONE, TCHAR *pszSecret = NULL) :
301 AgentConnection(dwAddr, wPort, iAuthMethod, pszSecret) { }
302 virtual ~AgentConnectionEx();
303};
304
305
306//
307// Client session
308//
309
310#define DECLARE_THREAD_STARTER(func) static THREAD_RESULT THREAD_CALL ThreadStarter_##func(void *);
311
312class ClientSession
313{
314private:
315 SOCKET m_hSocket;
316 Queue *m_pSendQueue;
317 Queue *m_pMessageQueue;
318 Queue *m_pUpdateQueue;
319 DWORD m_dwIndex;
320 int m_iState;
321 WORD m_wCurrentCmd;
322 DWORD m_dwUserId;
323 DWORD m_dwSystemAccess; // User's system access rights
324 DWORD m_dwFlags; // Session flags
325 CSCP_BUFFER *m_pMsgBuffer;
326 CSCP_ENCRYPTION_CONTEXT *m_pCtx;
327 BYTE m_challenge[CLIENT_CHALLENGE_SIZE];
328 THREAD m_hWriteThread;
329 THREAD m_hProcessingThread;
330 THREAD m_hUpdateThread;
331 MUTEX m_mutexSendEvents;
332 MUTEX m_mutexSendSyslog;
333 MUTEX m_mutexSendTrapLog;
334 MUTEX m_mutexSendObjects;
335 MUTEX m_mutexSendAlarms;
336 MUTEX m_mutexSendActions;
337 MUTEX m_mutexSendAuditLog;
338 MUTEX m_mutexSendSituations;
339 MUTEX m_mutexPollerInit;
340 DWORD m_dwHostAddr; // IP address of connected host (network byte order)
341 TCHAR m_szWorkstation[16]; // IP address of conneced host in textual form
342 TCHAR m_szUserName[MAX_SESSION_NAME]; // String in form login_name@host
343 TCHAR m_szClientInfo[96]; // Client app info string
344 DWORD m_dwOpenDCIListSize; // Number of open DCI lists
345 DWORD *m_pOpenDCIList; // List of nodes with DCI lists open
346 DWORD m_dwNumRecordsToUpload; // Number of records to be uploaded
347 DWORD m_dwRecordsUploaded;
348 EPRule **m_ppEPPRuleList; // List of loaded EPP rules
349 int m_hCurrFile;
350 DWORD m_dwFileRqId;
351 DWORD m_dwUploadCommand;
352 DWORD m_dwUploadData;
353 TCHAR m_szCurrFileName[MAX_PATH];
354 DWORD m_dwRefCount;
355 DWORD m_dwEncryptionRqId;
356 DWORD m_dwEncryptionResult;
357 CONDITION m_condEncryptionSetup;
358 DWORD m_dwActiveChannels; // Active data channels
359 DWORD m_dwMapSaveRqId; // ID of currently active map saving request
360 nxMapSrv *m_pActiveMap; // Map currenly being saved
361
362 static THREAD_RESULT THREAD_CALL ReadThreadStarter(void *);
363 static THREAD_RESULT THREAD_CALL WriteThreadStarter(void *);
364 static THREAD_RESULT THREAD_CALL ProcessingThreadStarter(void *);
365 static THREAD_RESULT THREAD_CALL UpdateThreadStarter(void *);
366 static THREAD_RESULT THREAD_CALL PollerThreadStarter(void *);
367
368 DECLARE_THREAD_STARTER(GetCollectedData)
369 DECLARE_THREAD_STARTER(ClearDCIData)
370 DECLARE_THREAD_STARTER(QueryL2Topology)
371 DECLARE_THREAD_STARTER(SendEventLog)
372 DECLARE_THREAD_STARTER(SendSyslog)
373 DECLARE_THREAD_STARTER(CreateObject)
374 DECLARE_THREAD_STARTER(GetServerFile)
375
376 void ReadThread(void);
377 void WriteThread(void);
378 void ProcessingThread(void);
379 void UpdateThread(void);
380 void PollerThread(Node *pNode, int iPollType, DWORD dwRqId);
381
382 BOOL CheckSysAccessRights(DWORD dwRequiredAccess)
383 {
384 return m_dwUserId == 0 ? TRUE :
385 ((dwRequiredAccess & m_dwSystemAccess) ? TRUE : FALSE);
386 }
387
388 void SetupEncryption(DWORD dwRqId);
389 void RespondToKeepalive(DWORD dwRqId);
390 void OnFileUpload(BOOL bSuccess);
391 void DebugPrintf(int level, const TCHAR *format, ...);
392 void SendServerInfo(DWORD dwRqId);
393 void Login(CSCPMessage *pRequest);
394 void SendAllObjects(CSCPMessage *pRequest);
395 void SendEventLog(CSCPMessage *pRequest);
396 void SendAllConfigVars(DWORD dwRqId);
397 void SetConfigVariable(CSCPMessage *pRequest);
398 void DeleteConfigVariable(CSCPMessage *pRequest);
399 void SendUserDB(DWORD dwRqId);
400 void SendAllAlarms(DWORD dwRqId, BOOL bIncludeAck);
401 void CreateUser(CSCPMessage *pRequest);
402 void UpdateUser(CSCPMessage *pRequest);
403 void DeleteUser(CSCPMessage *pRequest);
404 void SetPassword(CSCPMessage *pRequest);
405 void LockUserDB(DWORD dwRqId, BOOL bLock);
406 void SendEventDB(DWORD dwRqId);
407 void LockEventDB(DWORD dwRqId);
408 void UnlockEventDB(DWORD dwRqId);
409 void SetEventInfo(CSCPMessage *pRequest);
410 void DeleteEventTemplate(CSCPMessage *pRequest);
411 void GenerateEventCode(DWORD dwRqId);
412 void ModifyObject(CSCPMessage *pRequest);
413 void ChangeObjectMgmtStatus(CSCPMessage *pRequest);
414 void OpenNodeDCIList(CSCPMessage *pRequest);
415 void CloseNodeDCIList(CSCPMessage *pRequest);
416 void ModifyNodeDCI(CSCPMessage *pRequest);
417 void CopyDCI(CSCPMessage *pRequest);
418 void ApplyTemplate(CSCPMessage *pRequest);
419 void GetCollectedData(CSCPMessage *pRequest);
420 void ClearDCIData(CSCPMessage *pRequest);
421 void ChangeDCIStatus(CSCPMessage *pRequest);
422 void SendLastValues(CSCPMessage *pRequest);
423 void OpenEPP(DWORD dwRqId);
424 void CloseEPP(DWORD dwRqId);
425 void SaveEPP(CSCPMessage *pRequest);
426 void ProcessEPPRecord(CSCPMessage *pRequest);
427 void SendMIBTimestamp(DWORD dwRqId);
428 void SendMIB(DWORD dwRqId);
429 void CreateObject(CSCPMessage *pRequest);
430 void ChangeObjectBinding(CSCPMessage *pRequest, BOOL bBind);
431 void DeleteObject(CSCPMessage *pRequest);
432 void AcknowledgeAlarm(CSCPMessage *pRequest);
433 void TerminateAlarm(CSCPMessage *pRequest);
434 void DeleteAlarm(CSCPMessage *pRequest);
435 void CreateAction(CSCPMessage *pRequest);
436 void UpdateAction(CSCPMessage *pRequest);
437 void DeleteAction(CSCPMessage *pRequest);
438 void LockActionDB(DWORD dwRqId, BOOL bLock);
439 void SendAllActions(DWORD dwRqId);
440 void SendContainerCategories(DWORD dwRqId);
441 void ForcedNodePoll(CSCPMessage *pRequest);
442 void OnTrap(CSCPMessage *pRequest);
443 void OnWakeUpNode(CSCPMessage *pRequest);
444 void QueryParameter(CSCPMessage *pRequest);
445 void EditTrap(int iOperation, CSCPMessage *pRequest);
446 void LockTrapCfg(DWORD dwRqId, BOOL bLock);
447 void SendAllTraps(DWORD dwRqId);
448 void SendAllTraps2(DWORD dwRqId);
449 void LockPackageDB(DWORD dwRqId, BOOL bLock);
450 void SendAllPackages(DWORD dwRqId);
451 void InstallPackage(CSCPMessage *pRequest);
452 void RemovePackage(CSCPMessage *pRequest);
453 void DeployPackage(CSCPMessage *pRequest);
454 void SendParametersList(CSCPMessage *pRequest);
455 void GetUserVariable(CSCPMessage *pRequest);
456 void SetUserVariable(CSCPMessage *pRequest);
457 void CopyUserVariable(CSCPMessage *pRequest);
458 void EnumUserVariables(CSCPMessage *pRequest);
459 void DeleteUserVariable(CSCPMessage *pRequest);
460 void ChangeObjectIP(CSCPMessage *pRequest);
461 void GetAgentConfig(CSCPMessage *pRequest);
462 void UpdateAgentConfig(CSCPMessage *pRequest);
463 void ExecuteAction(CSCPMessage *pRequest);
464 void SendObjectTools(DWORD dwRqId);
465 void SendObjectToolDetails(CSCPMessage *pRequest);
466 void UpdateObjectTool(CSCPMessage *pRequest);
467 void DeleteObjectTool(CSCPMessage *pRequest);
468 void GenerateObjectToolId(DWORD dwRqId);
469 void ExecTableTool(CSCPMessage *pRequest);
470 void LockObjectTools(DWORD dwRqId, BOOL bLock);
471 void ChangeSubscription(CSCPMessage *pRequest);
472 void SendSyslog(CSCPMessage *pRequest);
5039dede
AK
473 void SendServerStats(DWORD dwRqId);
474 void SendScriptList(DWORD dwRqId);
475 void SendScript(CSCPMessage *pRequest);
476 void UpdateScript(CSCPMessage *pRequest);
477 void RenameScript(CSCPMessage *pRequest);
478 void DeleteScript(CSCPMessage *pRequest);
479 void SendSessionList(DWORD dwRqId);
480 void KillSession(CSCPMessage *pRequest);
481 void SendTrapLog(CSCPMessage *pRequest);
482 void StartSnmpWalk(CSCPMessage *pRequest);
483 void SendMapList(DWORD dwRqId);
484 void ResolveMapName(CSCPMessage *pRequest);
485 void SaveMap(CSCPMessage *pRequest);
0b514e86 486 void DeleteMap(CSCPMessage *pRequest);
5039dede
AK
487 void ProcessSubmapData(CSCPMessage *pRequest);
488 void CreateMap(CSCPMessage *pRequest);
489 void RenameMap(CSCPMessage *pRequest);
490 void LoadMap(CSCPMessage *pRequest);
491 void SendSubmapBkImage(CSCPMessage *pRequest);
492 void RecvSubmapBkImage(CSCPMessage *pRequest);
493 void ResolveDCINames(CSCPMessage *pRequest);
494 DWORD ResolveDCIName(DWORD dwNode, DWORD dwItem, TCHAR **ppszName);
495 void SendConfigForAgent(CSCPMessage *pRequest);
496 void SendAgentCfgList(DWORD dwRqId);
497 void OpenAgentConfig(CSCPMessage *pRequest);
498 void SaveAgentConfig(CSCPMessage *pRequest);
499 void DeleteAgentConfig(CSCPMessage *pRequest);
500 void SwapAgentConfigs(CSCPMessage *pRequest);
501 void SendObjectComments(CSCPMessage *pRequest);
502 void UpdateObjectComments(CSCPMessage *pRequest);
503 void PushDCIData(CSCPMessage *pRequest);
504 void GetAddrList(CSCPMessage *pRequest);
505 void SetAddrList(CSCPMessage *pRequest);
506 void ResetComponent(CSCPMessage *pRequest);
507 void SendDCIEventList(CSCPMessage *pRequest);
508 void SendDCIInfo(CSCPMessage *pRequest);
509 void SendSystemDCIList(CSCPMessage *pRequest);
510 void CreateManagementPack(CSCPMessage *pRequest);
511 void InstallManagementPack(CSCPMessage *pRequest);
512 void SendGraphList(DWORD dwRqId);
513 void DefineGraph(CSCPMessage *pRequest);
514 void DeleteGraph(CSCPMessage *pRequest);
515 void AddCACertificate(CSCPMessage *pRequest);
516 void DeleteCertificate(CSCPMessage *pRequest);
517 void UpdateCertificateComments(CSCPMessage *pRequest);
518 void SendCertificateList(DWORD dwRqId);
519 void QueryL2Topology(CSCPMessage *pRequest);
520 void SendSMS(CSCPMessage *pRequest);
521 void SendCommunityList(DWORD dwRqId);
522 void UpdateCommunityList(CSCPMessage *pRequest);
523 void SendSituationList(DWORD dwRqId);
524 void CreateSituation(CSCPMessage *pRequest);
525 void UpdateSituation(CSCPMessage *pRequest);
526 void DeleteSituation(CSCPMessage *pRequest);
527 void DeleteSituationInstance(CSCPMessage *pRequest);
528 void SetConfigCLOB(CSCPMessage *pRequest);
529 void GetConfigCLOB(CSCPMessage *pRequest);
530 void WebMapAdd(CSCPMessage *pRequest);
531 void WebMapUpdateData(CSCPMessage *pRequest);
532 void WebMapUpdateProps(CSCPMessage *pRequest);
533 void WebMapDelete(CSCPMessage *pRequest);
534 void WebMapGetData(CSCPMessage *pRequest);
535 void WebMapGetList(DWORD dwRqId);
536 void RegisterAgent(CSCPMessage *pRequest);
537 void GetServerFile(CSCPMessage *pRequest);
538
539public:
540 ClientSession(SOCKET hSocket, DWORD dwHostAddr);
541 ~ClientSession();
542
543 void IncRefCount(void) { m_dwRefCount++; }
544 void DecRefCount(void) { if (m_dwRefCount > 0) m_dwRefCount--; }
545
546 void Run(void);
547
548 void SendMessage(CSCPMessage *pMsg) { m_pSendQueue->Put(pMsg->CreateMessage()); }
549 void SendPollerMsg(DWORD dwRqId, const TCHAR *pszMsg);
550
551 DWORD GetIndex(void) { return m_dwIndex; }
552 void SetIndex(DWORD dwIndex) { if (m_dwIndex == INVALID_INDEX) m_dwIndex = dwIndex; }
553 int GetState(void) { return m_iState; }
554 const TCHAR *GetUserName(void) { return m_szUserName; }
555 const TCHAR *GetClientInfo(void) { return m_szClientInfo; }
556 DWORD GetUserId(void) { return m_dwUserId; }
557 BOOL IsAuthenticated(void) { return (m_dwFlags & CSF_AUTHENTICATED) ? TRUE : FALSE; }
558 BOOL IsSubscribed(DWORD dwChannel) { return (m_dwActiveChannels & dwChannel) ? TRUE : FALSE; }
559 WORD GetCurrentCmd(void) { return m_wCurrentCmd; }
560 int GetCipher(void) { return (m_pCtx == NULL) ? -1 : m_pCtx->nCipher; }
561
562 void Kill(void);
563 void Notify(DWORD dwCode, DWORD dwData = 0);
564
565 void QueueUpdate(UPDATE_INFO *pUpdate) { m_pUpdateQueue->Put(pUpdate); }
566 void OnNewEvent(Event *pEvent);
567 void OnSyslogMessage(NX_LOG_RECORD *pRec);
568 void OnNewSNMPTrap(CSCPMessage *pMsg);
569 void OnObjectChange(NetObj *pObject);
570 void OnUserDBUpdate(int iCode, DWORD dwUserId, NETXMS_USER *pUser, NETXMS_USER_GROUP *pGroup);
571 void OnAlarmUpdate(DWORD dwCode, NXC_ALARM *pAlarm);
572 void OnActionDBUpdate(DWORD dwCode, NXC_ACTION *pAction);
573 void OnSituationChange(CSCPMessage *msg);
574};
575
576
577//
578// Functions
579//
580
581BOOL NXCORE_EXPORTABLE ConfigReadStr(const TCHAR *szVar, TCHAR *szBuffer, int iBufSize,
582 const TCHAR *szDefault);
583int NXCORE_EXPORTABLE ConfigReadInt(const TCHAR *szVar, int iDefault);
584DWORD NXCORE_EXPORTABLE ConfigReadULong(const TCHAR *szVar, DWORD dwDefault);
585BOOL NXCORE_EXPORTABLE ConfigReadByteArray(const TCHAR *pszVar, int *pnArray,
586 int nSize, int nDefault);
587BOOL NXCORE_EXPORTABLE ConfigWriteStr(const TCHAR *szVar, const TCHAR *szValue, BOOL bCreate,
588 BOOL isVisible = TRUE, BOOL needRestart = FALSE);
589BOOL NXCORE_EXPORTABLE ConfigWriteInt(const TCHAR *szVar, int iValue, BOOL bCreate,
590 BOOL isVisible = TRUE, BOOL needRestart = FALSE);
591BOOL NXCORE_EXPORTABLE ConfigWriteULong(const TCHAR *szVar, DWORD dwValue, BOOL bCreate,
592 BOOL isVisible = TRUE, BOOL needRestart = FALSE);
593BOOL NXCORE_EXPORTABLE ConfigWriteByteArray(const TCHAR *pszVar, int *pnArray,
594 int nSize, BOOL bCreate,
595 BOOL isVisible = TRUE, BOOL needRestart = FALSE);
596TCHAR NXCORE_EXPORTABLE *ConfigReadCLOB(const TCHAR *var, const TCHAR *defValue);
597BOOL NXCORE_EXPORTABLE ConfigWriteCLOB(const TCHAR *var, const TCHAR *value, BOOL bCreate);
598
28f5b9a4
VK
599BOOL NXCORE_EXPORTABLE MetaDataReadStr(const TCHAR *szVar, TCHAR *szBuffer, int iBufSize, const TCHAR *szDefault);
600
5039dede
AK
601BOOL NXCORE_EXPORTABLE LoadConfig(void);
602
603void NXCORE_EXPORTABLE Shutdown(void);
604void NXCORE_EXPORTABLE FastShutdown(void);
605BOOL NXCORE_EXPORTABLE Initialize(void);
606THREAD_RESULT NXCORE_EXPORTABLE THREAD_CALL Main(void *);
607void NXCORE_EXPORTABLE ShutdownDB(void);
608void InitiateShutdown(void);
609
610BOOL NXCORE_EXPORTABLE SleepAndCheckForShutdown(int iSeconds);
611
612void ConsolePrintf(CONSOLE_CTX pCtx, const char *pszFormat, ...);
613int ProcessConsoleCommand(char *pszCmdLine, CONSOLE_CTX pCtx);
614
615void SaveObjects(DB_HANDLE hdb);
616
617void NXCORE_EXPORTABLE QueueSQLRequest(char *szQuery);
618void StartDBWriter(void);
619void StopDBWriter(void);
620
621void DecodeSQLStringAndSetVariable(CSCPMessage *pMsg, DWORD dwVarId, TCHAR *pszStr);
622
623void SnmpInit(void);
624DWORD SnmpNewRequestId(void);
625DWORD SnmpGet(DWORD dwVersion, SNMP_Transport *pTransport, const char *szCommunity,
626 const char *szOidStr, const DWORD *oidBinary, DWORD dwOidLen, void *pValue,
627 DWORD dwBufferSize, BOOL bVerbose, BOOL bStringResult);
628DWORD SnmpEnumerate(DWORD dwVersion, SNMP_Transport *pTransport, const char *szCommunity,
629 const char *szRootOid,
630 DWORD (* pHandler)(DWORD, const char *, SNMP_Variable *, SNMP_Transport *, void *),
631 void *pUserArg, BOOL bVerbose);
632BOOL SnmpCheckCommSettings(SNMP_Transport *pTransport, const char *currCommunity,
633 int *version, char *community);
634void StrToMac(char *pszStr, BYTE *pBuffer);
635DWORD OidToType(TCHAR *pszOid, DWORD *pdwFlags);
636
637void InitLocalNetInfo(void);
638
639ARP_CACHE *GetLocalArpCache(void);
640ARP_CACHE *SnmpGetArpCache(DWORD dwVersion, SNMP_Transport *pTransport, const char *szCommunity);
641
642INTERFACE_LIST *SnmpGetInterfaceList(DWORD dwVersion, SNMP_Transport *pTransport,
643 const char *szCommunity, DWORD dwNodeType,
644 BOOL useIfXTable);
645INTERFACE_LIST *GetLocalInterfaceList(void);
646void CleanInterfaceList(INTERFACE_LIST *pIfList);
647int SnmpGetInterfaceStatus(DWORD dwVersion, SNMP_Transport *pTransport, char *pszCommunity, DWORD dwIfIndex);
648
649ROUTING_TABLE *SnmpGetRoutingTable(DWORD dwVersion, SNMP_Transport *pTransport, const char *szCommunity);
650
651void WatchdogInit(void);
652DWORD WatchdogAddThread(const TCHAR *szName, time_t tNotifyInterval);
653void WatchdogNotify(DWORD dwId);
654void WatchdogPrintStatus(CONSOLE_CTX pCtx);
655
656void CheckForMgmtNode(void);
657NetObj *PollNewNode(DWORD dwIpAddr, DWORD dwNetMask, DWORD dwCreationFlags,
658 TCHAR *pszName, DWORD dwProxyNode, DWORD dwSNMPProxy, Cluster *pCluster);
659
660void NXCORE_EXPORTABLE EnumerateClientSessions(void (*pHandler)(ClientSession *, void *), void *pArg);
661void NXCORE_EXPORTABLE NotifyClientSessions(DWORD dwCode, DWORD dwData);
662int GetSessionCount(void);
663
664void GetSysInfoStr(char *pszBuffer, int nMaxSize);
665DWORD GetLocalIpAddr(void);
666
667BOOL ExecCommand(char *pszCommand);
668BOOL SendMagicPacket(DWORD dwIpAddr, BYTE *pbMacAddr, int iNumPackets);
669
670BOOL InitIdTable(void);
671DWORD CreateUniqueId(int iGroup);
672QWORD CreateUniqueEventId(void);
673
674void UpdateImageHashes(void);
675void SendImageCatalogue(ClientSession *pSession, DWORD dwRqId, WORD wFormat);
676void SendImageFile(ClientSession *pSession, DWORD dwRqId, DWORD dwImageId, WORD wFormat);
677void SendDefaultImageList(ClientSession *pSession, DWORD dwRqId);
678
679void InitMailer(void);
680void ShutdownMailer(void);
681void NXCORE_EXPORTABLE PostMail(char *pszRcpt, char *pszSubject, char *pszText);
682
683void InitSMSSender(void);
684void ShutdownSMSSender(void);
685void NXCORE_EXPORTABLE PostSMS(TCHAR *pszRcpt, TCHAR *pszText);
686
687void GetAccelarVLANIfList(DWORD dwVersion, SNMP_Transport *pTransport,
688 const TCHAR *pszCommunity, INTERFACE_LIST *pIfList);
689
690void InitTraps(void);
691void SendTrapsToClient(ClientSession *pSession, DWORD dwRqId);
692void CreateTrapCfgMessage(CSCPMessage &msg);
693DWORD CreateNewTrap(DWORD *pdwTrapId);
694DWORD CreateNewTrap(NXC_TRAP_CFG_ENTRY *pTrap);
695DWORD UpdateTrapFromMsg(CSCPMessage *pMsg);
696DWORD DeleteTrap(DWORD dwId);
697void CreateNXMPTrapRecord(String &str, DWORD dwId);
698
699BOOL IsTableTool(DWORD dwToolId);
700BOOL CheckObjectToolAccess(DWORD dwToolId, DWORD dwUserId);
701DWORD ExecuteTableTool(DWORD dwToolId, Node *pNode, DWORD dwRqId, ClientSession *pSession);
702DWORD DeleteObjectToolFromDB(DWORD dwToolId);
703DWORD UpdateObjectToolFromMessage(CSCPMessage *pMsg);
704
5039dede
AK
705void CreateMessageFromSyslogMsg(CSCPMessage *pMsg, NX_LOG_RECORD *pRec);
706
707void EscapeString(String &str);
708
709void InitAuditLog(void);
710void NXCORE_EXPORTABLE WriteAuditLog(const TCHAR *pszSubsys, BOOL bSuccess, DWORD dwUserId,
711 const TCHAR *pszWorkstation, DWORD dwObjectId, const TCHAR *pszFormat, ...);
712
713void AddObjectToIndex(INDEX **ppIndex, DWORD *pdwIndexSize, DWORD dwKey, void *pObject);
714void DeleteObjectFromIndex(INDEX **ppIndex, DWORD *pdwIndexSize, DWORD dwKey);
715DWORD SearchIndex(INDEX *pIndex, DWORD dwIndexSize, DWORD dwKey);
716
717#ifdef _WITH_ENCRYPTION
718X509 *CertificateFromLoginMessage(CSCPMessage *pMsg);
719BOOL ValidateUserCertificate(X509 *pCert, TCHAR *pszLogin, BYTE *pChallenge,
720 BYTE *pSignature, DWORD dwSigLen, int nMappingMethod,
721 TCHAR *pszMappingData);
722void ReloadCertificates(void);
723#endif
724
725#ifndef _WIN32
726THREAD_RESULT NXCORE_EXPORTABLE THREAD_CALL SignalHandler(void *);
727#endif /* not _WIN32 */
728
729void DbgTestMutex(MUTEX hMutex, const TCHAR *szName, CONSOLE_CTX pCtx);
730void DbgTestRWLock(RWLOCK hLock, const TCHAR *szName, CONSOLE_CTX pCtx);
731void DumpSessions(CONSOLE_CTX pCtx);
732void ShowPollerState(CONSOLE_CTX pCtx);
733void SetPollerInfo(int nIdx, const char *pszMsg);
734void ShowServerStats(CONSOLE_CTX pCtx);
735void ShowQueueStats(CONSOLE_CTX pCtx, Queue *pQueue, const char *pszName);
736void DumpProcess(CONSOLE_CTX pCtx);
737
738
739//
740// Global variables
741//
742
743extern TCHAR NXCORE_EXPORTABLE g_szConfigFile[];
744extern TCHAR NXCORE_EXPORTABLE g_szLogFile[];
745extern TCHAR NXCORE_EXPORTABLE g_szDumpDir[];
746extern TCHAR NXCORE_EXPORTABLE g_szListenAddress[];
747#ifndef _WIN32
748extern TCHAR NXCORE_EXPORTABLE g_szPIDFile[];
749#endif
750extern TCHAR g_szDataDir[];
751extern QWORD g_qwServerId;
752extern RSA *g_pServerKey;
753extern DWORD g_dwPingSize;
754extern DWORD g_dwAuditFlags;
755extern time_t g_tServerStartTime;
756extern DWORD g_dwLockTimeout;
757extern DWORD g_dwSNMPTimeout;
758extern DWORD g_dwAgentCommandTimeout;
759extern DWORD g_dwThresholdRepeatInterval;
760extern int g_nRequiredPolls;
761
762extern DB_HANDLE NXCORE_EXPORTABLE g_hCoreDB;
763extern Queue *g_pLazyRequestQueue;
764
28f5b9a4 765extern int NXCORE_EXPORTABLE g_nDBSyntax;
5039dede
AK
766
767#endif /* _nms_core_h_ */