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