libnxsl, libnxdb, libnxsrv, nxget, and nxdbmgr are now UNICODE compatible; libtre...
[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
73869331
VK
112#define MAX_LINE_SIZE 4096
113#define GROUP_FLAG_BIT ((DWORD)0x80000000)
114#define CHECKPOINT_SNMP_PORT 260
115#define DEFAULT_AFFINITY_MASK 0xFFFFFFFF
5039dede
AK
116
117typedef void * HSNMPSESSION;
118
5039dede 119
df8a4ca2
VK
120//
121// Prefixes for poller messages
122//
123
124#define POLLER_ERROR _T("\x7F") _T("e")
125#define POLLER_WARNING _T("\x7Fw")
126#define POLLER_INFO _T("\x7Fi")
127
128
5039dede
AK
129//
130// Unique identifier group codes
131//
132
133#define IDG_NETWORK_OBJECT 0
134#define IDG_CONTAINER_CAT 1
135#define IDG_EVENT 2
136#define IDG_ITEM 3
137#define IDG_SNMP_TRAP 4
6e53f004 138//#define IDG_IMAGE 5
5039dede
AK
139#define IDG_ACTION 6
140#define IDG_EVENT_GROUP 7
141#define IDG_THRESHOLD 8
142#define IDG_USER 9
143#define IDG_USER_GROUP 10
144#define IDG_ALARM 11
145#define IDG_ALARM_NOTE 12
146#define IDG_PACKAGE 13
47912c44 147//#define IDG_LPP 14
5039dede
AK
148#define IDG_OBJECT_TOOL 15
149#define IDG_SCRIPT 16
150#define IDG_AGENT_CONFIG 17
151#define IDG_GRAPH 18
152#define IDG_CERTIFICATE 19
153#define IDG_SITUATION 20
154#define IDG_MAP 21
155
156
157//
158// Exit codes for console commands
159//
160
161#define CMD_EXIT_CONTINUE 0
162#define CMD_EXIT_CLOSE_SESSION 1
163#define CMD_EXIT_SHUTDOWN 2
164
165
166//
167// Network discovery mode
168//
169
170#define DISCOVERY_DISABLED 0
171#define DISCOVERY_PASSIVE_ONLY 1
172#define DISCOVERY_ACTIVE 2
173
174
175//
176// Client session flags
177//
178
5039dede
AK
179#define CSF_EPP_LOCKED ((DWORD)0x0002)
180#define CSF_PACKAGE_DB_LOCKED ((DWORD)0x0004)
181#define CSF_USER_DB_LOCKED ((DWORD)0x0008)
182#define CSF_EPP_UPLOAD ((DWORD)0x0010)
5039dede 183#define CSF_AUTHENTICATED ((DWORD)0x0080)
5039dede
AK
184#define CSF_RECEIVING_MAP_DATA ((DWORD)0x0200)
185#define CSF_SYNC_OBJECT_COMMENTS ((DWORD)0x0400)
186
187
188//
189// Client session states
190//
191
192#define SESSION_STATE_INIT 0
193#define SESSION_STATE_IDLE 1
194#define SESSION_STATE_PROCESSING 2
195
196
197//
198// Information categories for UPDATE_INFO structure
199//
200
201#define INFO_CAT_EVENT 1
202#define INFO_CAT_OBJECT_CHANGE 2
203#define INFO_CAT_ALARM 3
204#define INFO_CAT_ACTION 4
205#define INFO_CAT_SYSLOG_MSG 5
206#define INFO_CAT_SNMP_TRAP 6
207#define INFO_CAT_AUDIT_RECORD 7
208#define INFO_CAT_SITUATION 8
209
210
211//
212// Certificate types
213//
214
215#define CERT_TYPE_TRUSTED_CA 0
216#define CERT_TYPE_USER 1
217
218
219//
220// Audit subsystems
221//
222
223#define AUDIT_SECURITY _T("SECURITY")
224#define AUDIT_OBJECTS _T("OBJECTS")
225#define AUDIT_SYSCFG _T("SYSCFG")
226#define AUDIT_CONSOLE _T("CONSOLE")
227
228
229//
230// Event handling subsystem definitions
231//
232
233#include "nms_events.h"
234#include "nms_actions.h"
235#include "nms_alarm.h"
236
237
238//
239// New node information
240//
241
242typedef struct
243{
244 DWORD dwIpAddr;
245 DWORD dwNetMask;
246 BOOL ignoreFilter;
247} NEW_NODE;
248
249
250//
251// New node flags
252//
253
254#define NNF_IS_SNMP 0x0001
255#define NNF_IS_AGENT 0x0002
256#define NNF_IS_ROUTER 0x0004
257#define NNF_IS_BRIDGE 0x0008
258#define NNF_IS_PRINTER 0x0010
259#define NNF_IS_CDP 0x0020
260#define NNF_IS_SONMP 0x0040
261#define NNF_IS_LLDP 0x0080
262
263
264//
265// Node information for autodiscovery filter
266//
267
268typedef struct
269{
270 DWORD dwIpAddr;
271 DWORD dwNetMask;
272 DWORD dwSubnetAddr;
273 DWORD dwFlags;
274 int nSNMPVersion;
275 char szObjectId[MAX_OID_LEN * 4]; // SNMP OID
276 char szAgentVersion[MAX_AGENT_VERSION_LEN];
277 char szPlatform[MAX_PLATFORM_NAME_LEN];
278} DISCOVERY_FILTER_DATA;
279
280
281//
282// Data update structure for client sessions
283//
284
285typedef struct
286{
287 DWORD dwCategory; // Data category - event, network object, etc.
288 DWORD dwCode; // Data-specific update code
289 void *pData; // Pointer to data block
290} UPDATE_INFO;
291
292
293//
294// Extended agent connection
295//
296
297class AgentConnectionEx : public AgentConnection
298{
299protected:
f480bdd4
VK
300 virtual void onTrap(CSCPMessage *msg);
301 virtual void onDataPush(CSCPMessage *msg);
5039dede
AK
302
303public:
5039dede
AK
304 AgentConnectionEx(DWORD dwAddr, WORD wPort = AGENT_LISTEN_PORT,
305 int iAuthMethod = AUTH_NONE, TCHAR *pszSecret = NULL) :
306 AgentConnection(dwAddr, wPort, iAuthMethod, pszSecret) { }
307 virtual ~AgentConnectionEx();
45d84f8a
VK
308
309 DWORD deployPolicy(AgentPolicy *policy);
93599cfd 310 DWORD uninstallPolicy(AgentPolicy *policy);
5039dede
AK
311};
312
313
314//
315// Client session
316//
317
318#define DECLARE_THREAD_STARTER(func) static THREAD_RESULT THREAD_CALL ThreadStarter_##func(void *);
319
a0e3917e 320class NXCORE_EXPORTABLE ClientSession
5039dede
AK
321{
322private:
323 SOCKET m_hSocket;
324 Queue *m_pSendQueue;
325 Queue *m_pMessageQueue;
326 Queue *m_pUpdateQueue;
327 DWORD m_dwIndex;
328 int m_iState;
329 WORD m_wCurrentCmd;
330 DWORD m_dwUserId;
331 DWORD m_dwSystemAccess; // User's system access rights
332 DWORD m_dwFlags; // Session flags
333 CSCP_BUFFER *m_pMsgBuffer;
334 CSCP_ENCRYPTION_CONTEXT *m_pCtx;
335 BYTE m_challenge[CLIENT_CHALLENGE_SIZE];
336 THREAD m_hWriteThread;
337 THREAD m_hProcessingThread;
338 THREAD m_hUpdateThread;
339 MUTEX m_mutexSendEvents;
340 MUTEX m_mutexSendSyslog;
341 MUTEX m_mutexSendTrapLog;
342 MUTEX m_mutexSendObjects;
343 MUTEX m_mutexSendAlarms;
344 MUTEX m_mutexSendActions;
345 MUTEX m_mutexSendAuditLog;
346 MUTEX m_mutexSendSituations;
347 MUTEX m_mutexPollerInit;
348 DWORD m_dwHostAddr; // IP address of connected host (network byte order)
349 TCHAR m_szWorkstation[16]; // IP address of conneced host in textual form
350 TCHAR m_szUserName[MAX_SESSION_NAME]; // String in form login_name@host
351 TCHAR m_szClientInfo[96]; // Client app info string
352 DWORD m_dwOpenDCIListSize; // Number of open DCI lists
353 DWORD *m_pOpenDCIList; // List of nodes with DCI lists open
354 DWORD m_dwNumRecordsToUpload; // Number of records to be uploaded
355 DWORD m_dwRecordsUploaded;
356 EPRule **m_ppEPPRuleList; // List of loaded EPP rules
357 int m_hCurrFile;
358 DWORD m_dwFileRqId;
359 DWORD m_dwUploadCommand;
360 DWORD m_dwUploadData;
361 TCHAR m_szCurrFileName[MAX_PATH];
362 DWORD m_dwRefCount;
363 DWORD m_dwEncryptionRqId;
364 DWORD m_dwEncryptionResult;
365 CONDITION m_condEncryptionSetup;
366 DWORD m_dwActiveChannels; // Active data channels
367 DWORD m_dwMapSaveRqId; // ID of currently active map saving request
368 nxMapSrv *m_pActiveMap; // Map currenly being saved
369
370 static THREAD_RESULT THREAD_CALL ReadThreadStarter(void *);
371 static THREAD_RESULT THREAD_CALL WriteThreadStarter(void *);
372 static THREAD_RESULT THREAD_CALL ProcessingThreadStarter(void *);
373 static THREAD_RESULT THREAD_CALL UpdateThreadStarter(void *);
374 static THREAD_RESULT THREAD_CALL PollerThreadStarter(void *);
375
376 DECLARE_THREAD_STARTER(GetCollectedData)
377 DECLARE_THREAD_STARTER(ClearDCIData)
378 DECLARE_THREAD_STARTER(QueryL2Topology)
379 DECLARE_THREAD_STARTER(SendEventLog)
380 DECLARE_THREAD_STARTER(SendSyslog)
1da08bc6
VK
381 DECLARE_THREAD_STARTER(createObject)
382 DECLARE_THREAD_STARTER(getServerFile)
e05b1945
VK
383 DECLARE_THREAD_STARTER(queryServerLog)
384 DECLARE_THREAD_STARTER(getServerLogQueryData)
e31c8e60 385 DECLARE_THREAD_STARTER(executeAction)
5039dede
AK
386
387 void ReadThread(void);
388 void WriteThread(void);
389 void ProcessingThread(void);
390 void UpdateThread(void);
391 void PollerThread(Node *pNode, int iPollType, DWORD dwRqId);
392
e05b1945 393 void setupEncryption(DWORD dwRqId);
5039dede 394 void RespondToKeepalive(DWORD dwRqId);
e05b1945 395 void onFileUpload(BOOL bSuccess);
5039dede
AK
396 void DebugPrintf(int level, const TCHAR *format, ...);
397 void SendServerInfo(DWORD dwRqId);
398 void Login(CSCPMessage *pRequest);
399 void SendAllObjects(CSCPMessage *pRequest);
400 void SendEventLog(CSCPMessage *pRequest);
401 void SendAllConfigVars(DWORD dwRqId);
402 void SetConfigVariable(CSCPMessage *pRequest);
403 void DeleteConfigVariable(CSCPMessage *pRequest);
404 void SendUserDB(DWORD dwRqId);
405 void SendAllAlarms(DWORD dwRqId, BOOL bIncludeAck);
406 void CreateUser(CSCPMessage *pRequest);
407 void UpdateUser(CSCPMessage *pRequest);
408 void DeleteUser(CSCPMessage *pRequest);
409 void SetPassword(CSCPMessage *pRequest);
410 void LockUserDB(DWORD dwRqId, BOOL bLock);
8eb2d92b
VK
411 void sendEventDB(DWORD dwRqId);
412 void modifyEventTemplate(CSCPMessage *pRequest);
413 void deleteEventTemplate(CSCPMessage *pRequest);
414 void generateEventCode(DWORD dwRqId);
5039dede 415 void ModifyObject(CSCPMessage *pRequest);
1da08bc6 416 void changeObjectMgmtStatus(CSCPMessage *pRequest);
5039dede
AK
417 void OpenNodeDCIList(CSCPMessage *pRequest);
418 void CloseNodeDCIList(CSCPMessage *pRequest);
419 void ModifyNodeDCI(CSCPMessage *pRequest);
420 void CopyDCI(CSCPMessage *pRequest);
421 void ApplyTemplate(CSCPMessage *pRequest);
422 void GetCollectedData(CSCPMessage *pRequest);
423 void ClearDCIData(CSCPMessage *pRequest);
424 void ChangeDCIStatus(CSCPMessage *pRequest);
425 void SendLastValues(CSCPMessage *pRequest);
426 void OpenEPP(DWORD dwRqId);
427 void CloseEPP(DWORD dwRqId);
428 void SaveEPP(CSCPMessage *pRequest);
429 void ProcessEPPRecord(CSCPMessage *pRequest);
430 void SendMIBTimestamp(DWORD dwRqId);
431 void SendMIB(DWORD dwRqId);
1da08bc6
VK
432 void createObject(CSCPMessage *pRequest);
433 void changeObjectBinding(CSCPMessage *pRequest, BOOL bBind);
f5d16551 434 void deleteObject(CSCPMessage *pRequest);
5039dede
AK
435 void AcknowledgeAlarm(CSCPMessage *pRequest);
436 void TerminateAlarm(CSCPMessage *pRequest);
437 void DeleteAlarm(CSCPMessage *pRequest);
438 void CreateAction(CSCPMessage *pRequest);
439 void UpdateAction(CSCPMessage *pRequest);
440 void DeleteAction(CSCPMessage *pRequest);
5039dede
AK
441 void SendAllActions(DWORD dwRqId);
442 void SendContainerCategories(DWORD dwRqId);
443 void ForcedNodePoll(CSCPMessage *pRequest);
444 void OnTrap(CSCPMessage *pRequest);
445 void OnWakeUpNode(CSCPMessage *pRequest);
446 void QueryParameter(CSCPMessage *pRequest);
447 void EditTrap(int iOperation, CSCPMessage *pRequest);
448 void LockTrapCfg(DWORD dwRqId, BOOL bLock);
449 void SendAllTraps(DWORD dwRqId);
450 void SendAllTraps2(DWORD dwRqId);
451 void LockPackageDB(DWORD dwRqId, BOOL bLock);
452 void SendAllPackages(DWORD dwRqId);
453 void InstallPackage(CSCPMessage *pRequest);
454 void RemovePackage(CSCPMessage *pRequest);
455 void DeployPackage(CSCPMessage *pRequest);
456 void SendParametersList(CSCPMessage *pRequest);
457 void GetUserVariable(CSCPMessage *pRequest);
458 void SetUserVariable(CSCPMessage *pRequest);
459 void CopyUserVariable(CSCPMessage *pRequest);
460 void EnumUserVariables(CSCPMessage *pRequest);
461 void DeleteUserVariable(CSCPMessage *pRequest);
462 void ChangeObjectIP(CSCPMessage *pRequest);
463 void GetAgentConfig(CSCPMessage *pRequest);
464 void UpdateAgentConfig(CSCPMessage *pRequest);
e31c8e60 465 void executeAction(CSCPMessage *pRequest);
0e950f45
VK
466 void sendObjectTools(DWORD dwRqId);
467 void sendObjectToolDetails(CSCPMessage *pRequest);
468 void updateObjectTool(CSCPMessage *pRequest);
469 void deleteObjectTool(CSCPMessage *pRequest);
470 void generateObjectToolId(DWORD dwRqId);
471 void execTableTool(CSCPMessage *pRequest);
5039dede
AK
472 void ChangeSubscription(CSCPMessage *pRequest);
473 void SendSyslog(CSCPMessage *pRequest);
5039dede 474 void SendServerStats(DWORD dwRqId);
0c7aca90
VK
475 void sendScriptList(DWORD dwRqId);
476 void sendScript(CSCPMessage *pRequest);
477 void updateScript(CSCPMessage *pRequest);
478 void renameScript(CSCPMessage *pRequest);
479 void deleteScript(CSCPMessage *pRequest);
5039dede
AK
480 void SendSessionList(DWORD dwRqId);
481 void KillSession(CSCPMessage *pRequest);
482 void SendTrapLog(CSCPMessage *pRequest);
483 void StartSnmpWalk(CSCPMessage *pRequest);
484 void SendMapList(DWORD dwRqId);
485 void ResolveMapName(CSCPMessage *pRequest);
486 void SaveMap(CSCPMessage *pRequest);
0b514e86 487 void DeleteMap(CSCPMessage *pRequest);
5039dede
AK
488 void ProcessSubmapData(CSCPMessage *pRequest);
489 void CreateMap(CSCPMessage *pRequest);
490 void RenameMap(CSCPMessage *pRequest);
491 void LoadMap(CSCPMessage *pRequest);
492 void SendSubmapBkImage(CSCPMessage *pRequest);
493 void RecvSubmapBkImage(CSCPMessage *pRequest);
494 void ResolveDCINames(CSCPMessage *pRequest);
495 DWORD ResolveDCIName(DWORD dwNode, DWORD dwItem, TCHAR **ppszName);
496 void SendConfigForAgent(CSCPMessage *pRequest);
497 void SendAgentCfgList(DWORD dwRqId);
498 void OpenAgentConfig(CSCPMessage *pRequest);
499 void SaveAgentConfig(CSCPMessage *pRequest);
500 void DeleteAgentConfig(CSCPMessage *pRequest);
501 void SwapAgentConfigs(CSCPMessage *pRequest);
502 void SendObjectComments(CSCPMessage *pRequest);
503 void UpdateObjectComments(CSCPMessage *pRequest);
504 void PushDCIData(CSCPMessage *pRequest);
505 void GetAddrList(CSCPMessage *pRequest);
506 void SetAddrList(CSCPMessage *pRequest);
507 void ResetComponent(CSCPMessage *pRequest);
7a46028e 508 void sendDCIEventList(CSCPMessage *request);
5039dede 509 void SendDCIInfo(CSCPMessage *pRequest);
74526d25 510 void sendPerfTabDCIList(CSCPMessage *pRequest);
a7ff20a5
VK
511 void exportConfiguration(CSCPMessage *pRequest);
512 void importConfiguration(CSCPMessage *pRequest);
5039dede
AK
513 void SendGraphList(DWORD dwRqId);
514 void DefineGraph(CSCPMessage *pRequest);
515 void DeleteGraph(CSCPMessage *pRequest);
516 void AddCACertificate(CSCPMessage *pRequest);
517 void DeleteCertificate(CSCPMessage *pRequest);
518 void UpdateCertificateComments(CSCPMessage *pRequest);
519 void SendCertificateList(DWORD dwRqId);
520 void QueryL2Topology(CSCPMessage *pRequest);
521 void SendSMS(CSCPMessage *pRequest);
522 void SendCommunityList(DWORD dwRqId);
523 void UpdateCommunityList(CSCPMessage *pRequest);
524 void SendSituationList(DWORD dwRqId);
525 void CreateSituation(CSCPMessage *pRequest);
526 void UpdateSituation(CSCPMessage *pRequest);
527 void DeleteSituation(CSCPMessage *pRequest);
528 void DeleteSituationInstance(CSCPMessage *pRequest);
1da08bc6
VK
529 void setConfigCLOB(CSCPMessage *pRequest);
530 void getConfigCLOB(CSCPMessage *pRequest);
5039dede
AK
531 void WebMapAdd(CSCPMessage *pRequest);
532 void WebMapUpdateData(CSCPMessage *pRequest);
533 void WebMapUpdateProps(CSCPMessage *pRequest);
534 void WebMapDelete(CSCPMessage *pRequest);
535 void WebMapGetData(CSCPMessage *pRequest);
536 void WebMapGetList(DWORD dwRqId);
1da08bc6
VK
537 void registerAgent(CSCPMessage *pRequest);
538 void getServerFile(CSCPMessage *pRequest);
539 void testDCITransformation(CSCPMessage *pRequest);
45d84f8a
VK
540 void sendJobList(DWORD dwRqId);
541 void cancelJob(CSCPMessage *pRequest);
93599cfd 542 void deployAgentPolicy(CSCPMessage *pRequest, bool uninstallFlag);
d83dc1f0
VK
543 void getUserCustomAttribute(CSCPMessage *request);
544 void setUserCustomAttribute(CSCPMessage *request);
e05b1945
VK
545 void openServerLog(CSCPMessage *request);
546 void closeServerLog(CSCPMessage *request);
547 void queryServerLog(CSCPMessage *request);
548 void getServerLogQueryData(CSCPMessage *request);
df8a4ca2
VK
549 void sendUsmCredentials(DWORD dwRqId);
550 void updateUsmCredentials(CSCPMessage *pRequest);
071fd171 551 void sendDCIThresholds(CSCPMessage *request);
1da08bc6 552 void addClusterNode(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[];
73869331 771extern DWORD NXCORE_EXPORTABLE g_processAffinityMask;
5039dede
AK
772extern QWORD g_qwServerId;
773extern RSA *g_pServerKey;
774extern DWORD g_dwPingSize;
775extern DWORD g_dwAuditFlags;
776extern time_t g_tServerStartTime;
777extern DWORD g_dwLockTimeout;
778extern DWORD g_dwSNMPTimeout;
779extern DWORD g_dwAgentCommandTimeout;
780extern DWORD g_dwThresholdRepeatInterval;
781extern int g_nRequiredPolls;
782
b8c1ec69
VK
783extern TCHAR g_szDbDriver[];
784extern TCHAR g_szDbDrvParams[];
785extern TCHAR g_szDbServer[];
786extern TCHAR g_szDbLogin[];
787extern TCHAR g_szDbPassword[];
788extern TCHAR g_szDbName[];
789extern DB_DRIVER g_dbDriver;
5039dede
AK
790extern DB_HANDLE NXCORE_EXPORTABLE g_hCoreDB;
791extern Queue *g_pLazyRequestQueue;
792
28f5b9a4 793extern int NXCORE_EXPORTABLE g_nDBSyntax;
5039dede
AK
794
795#endif /* _nms_core_h_ */