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