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