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