Commit | Line | Data |
---|---|---|
76b4edb5 | 1 | /* |
5039dede AK |
2 | ** NetXMS - Network Management System |
3 | ** Server Library | |
33560996 | 4 | ** Copyright (C) 2003-2015 Victor Kirhenshtein |
5039dede AK |
5 | ** |
6 | ** This program is free software; you can redistribute it and/or modify | |
0702ed69 VK |
7 | ** it under the terms of the GNU Lesser General Public License as published by |
8 | ** the Free Software Foundation; either version 3 of the License, or | |
5039dede AK |
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 | ** | |
0702ed69 | 16 | ** You should have received a copy of the GNU Lesser General Public License |
5039dede AK |
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: nxsrvapi.h | |
21 | ** | |
22 | **/ | |
23 | ||
24 | #ifndef _nxsrvapi_h_ | |
25 | #define _nxsrvapi_h_ | |
26 | ||
27 | #ifdef _WIN32 | |
28 | #ifdef LIBNXSRV_EXPORTS | |
29 | #define LIBNXSRV_EXPORTABLE __declspec(dllexport) | |
30 | #else | |
31 | #define LIBNXSRV_EXPORTABLE __declspec(dllimport) | |
32 | #endif | |
33 | #else /* _WIN32 */ | |
34 | #define LIBNXSRV_EXPORTABLE | |
35 | #endif | |
36 | ||
5039dede | 37 | #include <nxcpapi.h> |
bf6fb6c3 | 38 | #include <nms_util.h> |
5039dede | 39 | #include <nms_agent.h> |
5039dede AK |
40 | #include <nxsnmp.h> |
41 | #include <netxms_isc.h> | |
bf6fb6c3 | 42 | #include <nxcldefs.h> |
5039dede | 43 | |
f1a3b4fe | 44 | #ifdef INCLUDE_LIBNXSRV_MESSAGES |
45 | #include "../libnxsrv/messages.h" | |
46 | #endif | |
47 | ||
f375019e VK |
48 | /** |
49 | * Default files | |
50 | */ | |
5039dede AK |
51 | #ifdef _WIN32 |
52 | ||
1288683d | 53 | #define DEFAULT_LOG_FILE _T("C:\\netxmsd.log") |
1039d7ee | 54 | #define DEFAULT_DUMP_DIR _T("C:\\") |
9796ce45 | 55 | |
9796ce45 VK |
56 | #define DDIR_PACKAGES _T("\\packages") |
57 | #define DDIR_BACKGROUNDS _T("\\backgrounds") | |
9796ce45 | 58 | #define DFILE_KEYS _T("\\server_key") |
1039d7ee | 59 | #define DFILE_COMPILED_MIB _T("\\netxms.mib") |
9796ce45 VK |
60 | #define DDIR_IMAGES _T("\\images") |
61 | #define DDIR_FILES _T("\\files") | |
5039dede | 62 | |
1039d7ee VK |
63 | #define LDIR_NDD _T("\\ndd") |
64 | #define LDIR_PDSDRV _T("\\pdsdrv") | |
5039dede | 65 | |
1039d7ee | 66 | #else /* _WIN32 */ |
5039dede | 67 | |
9796ce45 | 68 | #ifndef DATADIR |
1039d7ee VK |
69 | #define DATADIR _T("/usr/share/netxms") |
70 | #endif | |
71 | ||
72 | #ifndef STATEDIR | |
73 | #define STATEDIR _T("/var/lib/netxms") | |
9796ce45 | 74 | #endif |
5039dede | 75 | |
9796ce45 VK |
76 | #ifndef LIBDIR |
77 | #define LIBDIR _T("/usr/lib") | |
78 | #endif | |
5039dede | 79 | |
644f97f5 VK |
80 | #ifndef PKGLIBDIR |
81 | #define PKGLIBDIR _T("/usr/lib/netxms") | |
82 | #endif | |
83 | ||
1288683d | 84 | #define DEFAULT_LOG_FILE _T("/var/log/netxmsd.log") |
1288683d | 85 | #define DEFAULT_DUMP_DIR _T("/var/tmp") |
9796ce45 VK |
86 | |
87 | #define LDIR_NDD _T("/ndd") | |
8fd95c92 | 88 | #define LDIR_PDSDRV _T("/pdsdrv") |
9796ce45 | 89 | |
9796ce45 VK |
90 | #define DDIR_PACKAGES _T("/packages") |
91 | #define DDIR_BACKGROUNDS _T("/backgrounds") | |
9796ce45 | 92 | #define DFILE_KEYS _T("/.server_key") |
1039d7ee | 93 | #define DFILE_COMPILED_MIB _T("/netxms.mib") |
9796ce45 VK |
94 | #define DDIR_IMAGES _T("/images") |
95 | #define DDIR_FILES _T("/files") | |
5039dede AK |
96 | |
97 | #endif /* _WIN32 */ | |
98 | ||
f375019e VK |
99 | /** |
100 | * Application flags | |
101 | */ | |
c8076b19 VK |
102 | #define AF_DAEMON _ULL(0x0000000000000001) |
103 | #define AF_USE_SYSLOG _ULL(0x0000000000000002) | |
104 | #define AF_ENABLE_NETWORK_DISCOVERY _ULL(0x0000000000000004) | |
105 | #define AF_ACTIVE_NETWORK_DISCOVERY _ULL(0x0000000000000008) | |
106 | #define AF_LOG_SQL_ERRORS _ULL(0x0000000000000010) | |
107 | #define AF_DELETE_EMPTY_SUBNETS _ULL(0x0000000000000020) | |
108 | #define AF_ENABLE_SNMP_TRAPD _ULL(0x0000000000000040) | |
109 | #define AF_ENABLE_ZONING _ULL(0x0000000000000080) | |
110 | #define AF_SYNC_NODE_NAMES_WITH_DNS _ULL(0x0000000000000100) | |
111 | #define AF_CHECK_TRUSTED_NODES _ULL(0x0000000000000200) | |
112 | #define AF_ENABLE_NXSL_CONTAINER_FUNCS _ULL(0x0000000000000400) | |
113 | #define AF_USE_FQDN_FOR_NODE_NAMES _ULL(0x0000000000000800) | |
114 | #define AF_APPLY_TO_DISABLED_DCI_FROM_TEMPLATE _ULL(0x0000000000001000) | |
115 | #define AF_DEBUG_CONSOLE_DISABLED _ULL(0x0000000000002000) | |
116 | #define AF_ENABLE_OBJECT_TRANSACTIONS _ULL(0x0000000000004000) | |
117 | #define AF_WRITE_FULL_DUMP _ULL(0x0000000000080000) | |
118 | #define AF_RESOLVE_NODE_NAMES _ULL(0x0000000000100000) | |
119 | #define AF_CATCH_EXCEPTIONS _ULL(0x0000000000200000) | |
120 | #define AF_HELPDESK_LINK_ACTIVE _ULL(0x0000000000400000) | |
c8076b19 | 121 | #define AF_DB_LOCKED _ULL(0x0000000001000000) |
c8076b19 VK |
122 | #define AF_DB_CONNECTION_LOST _ULL(0x0000000004000000) |
123 | #define AF_NO_NETWORK_CONNECTIVITY _ULL(0x0000000008000000) | |
124 | #define AF_EVENT_STORM_DETECTED _ULL(0x0000000010000000) | |
125 | #define AF_SNMP_TRAP_DISCOVERY _ULL(0x0000000020000000) | |
126 | #define AF_TRAPS_FROM_UNMANAGED_NODES _ULL(0x0000000040000000) | |
385b1f20 | 127 | #define AF_RESOLVE_IP_FOR_EACH_STATUS_POLL _ULL(0x0000000080000000) |
4e0e77e6 VK |
128 | #define AF_PERFDATA_STORAGE_DRIVER_LOADED _ULL(0x0000000100000000) |
129 | #define AF_BACKGROUND_LOG_WRITER _ULL(0x0000000200000000) | |
8a1519ce | 130 | #define AF_CASE_INSENSITIVE_LOGINS _ULL(0x0000000400000000) |
0eff2ce4 | 131 | #define AF_TRAP_SOURCES_IN_ALL_ZONES _ULL(0x0000000800000000) |
c8076b19 VK |
132 | #define AF_SERVER_INITIALIZED _ULL(0x4000000000000000) |
133 | #define AF_SHUTDOWN _ULL(0x8000000000000000) | |
5039dede | 134 | |
f375019e VK |
135 | /** |
136 | * Encryption usage policies | |
137 | */ | |
5039dede AK |
138 | #define ENCRYPTION_DISABLED 0 |
139 | #define ENCRYPTION_ALLOWED 1 | |
140 | #define ENCRYPTION_PREFERRED 2 | |
141 | #define ENCRYPTION_REQUIRED 3 | |
142 | ||
908d71bd VK |
143 | /** |
144 | * Agent action output callback events | |
145 | */ | |
146 | enum ActionCallbackEvent | |
147 | { | |
148 | ACE_CONNECTED = 0, | |
149 | ACE_DATA = 1, | |
150 | ACE_DISCONNECTED = 2 | |
151 | }; | |
152 | ||
f375019e VK |
153 | /** |
154 | * Win32 service and syslog constants | |
155 | */ | |
5039dede AK |
156 | #ifdef _WIN32 |
157 | ||
158 | #define CORE_SERVICE_NAME _T("NetXMSCore") | |
159 | #define CORE_EVENT_SOURCE _T("NetXMSCore") | |
160 | #define NETXMSD_SYSLOG_NAME CORE_EVENT_SOURCE | |
161 | ||
162 | #else | |
163 | ||
164 | #define NETXMSD_SYSLOG_NAME _T("netxmsd") | |
165 | ||
166 | #endif /* _WIN32 */ | |
167 | ||
f375019e VK |
168 | /** |
169 | * Single ARP cache entry | |
170 | */ | |
5039dede AK |
171 | typedef struct |
172 | { | |
967893bb | 173 | UINT32 dwIndex; // Interface index |
c75e9ee4 | 174 | InetAddress ipAddr; |
5039dede AK |
175 | BYTE bMacAddr[MAC_ADDR_LENGTH]; |
176 | } ARP_ENTRY; | |
177 | ||
f375019e VK |
178 | /** |
179 | * ARP cache structure used by discovery functions and AgentConnection class | |
180 | */ | |
5039dede AK |
181 | typedef struct |
182 | { | |
967893bb | 183 | UINT32 dwNumEntries; |
5039dede AK |
184 | ARP_ENTRY *pEntries; |
185 | } ARP_CACHE; | |
186 | ||
f375019e VK |
187 | /** |
188 | * Interface information structure used by discovery functions and AgentConnection class | |
189 | */ | |
c30c0c0f | 190 | class InterfaceInfo |
5039dede | 191 | { |
3d37f7bf VK |
192 | private: |
193 | void init() | |
194 | { | |
195 | name[0] = 0; | |
196 | description[0] = 0; | |
197 | alias[0] = 0; | |
198 | type = IFTYPE_OTHER; | |
199 | mtu = 0; | |
200 | speed = 0; | |
201 | bridgePort = 0; | |
202 | slot = 0; | |
203 | port = 0; | |
204 | memset(macAddr, 0, sizeof(macAddr)); | |
205 | isPhysicalPort = false; | |
206 | isSystem = false; | |
207 | } | |
208 | ||
c30c0c0f VK |
209 | public: |
210 | UINT32 index; | |
e95680e5 VK |
211 | TCHAR name[MAX_DB_STRING]; // Interface display name |
212 | TCHAR description[MAX_DB_STRING]; // Value of ifDescr MIB variable for SNMP agents | |
213 | TCHAR alias[MAX_DB_STRING]; // Value of ifDescr MIB variable for SNMP agents | |
e95680e5 VK |
214 | UINT32 type; |
215 | UINT32 mtu; | |
3d37f7bf | 216 | UINT64 speed; // interface speed in bits/sec |
e95680e5 VK |
217 | UINT32 bridgePort; |
218 | UINT32 slot; | |
219 | UINT32 port; | |
c30c0c0f | 220 | InetAddressList ipAddrList; |
e95680e5 | 221 | BYTE macAddr[MAC_ADDR_LENGTH]; |
4c16cdc7 | 222 | bool isPhysicalPort; |
01152a54 | 223 | bool isSystem; |
3d37f7bf VK |
224 | UINT32 ifTableSuffix[16]; // actual ifTable suffix |
225 | int ifTableSuffixLength; | |
c30c0c0f VK |
226 | |
227 | InterfaceInfo(UINT32 ifIndex) | |
e13420c1 | 228 | { |
c30c0c0f | 229 | index = ifIndex; |
3d37f7bf VK |
230 | ifTableSuffixLength = 0; |
231 | init(); | |
232 | } | |
233 | ||
e5f4e3ac | 234 | InterfaceInfo(UINT32 ifIndex, int suffixLen, const UINT32 *suffix) |
3d37f7bf VK |
235 | { |
236 | index = ifIndex; | |
237 | ifTableSuffixLength = ((suffixLen >= 0) && (suffixLen < 16)) ? suffixLen : 0; | |
238 | memcpy(ifTableSuffix, suffix, ifTableSuffixLength * sizeof(UINT32)); | |
239 | init(); | |
c30c0c0f VK |
240 | } |
241 | ||
242 | bool hasAddress(const InetAddress& addr) { return ipAddrList.hasAddress(addr); } | |
243 | }; | |
5039dede | 244 | |
f375019e VK |
245 | /** |
246 | * Interface list used by discovery functions and AgentConnection class | |
247 | */ | |
98762401 | 248 | class LIBNXSRV_EXPORTABLE InterfaceList |
5039dede | 249 | { |
98762401 | 250 | private: |
c30c0c0f | 251 | ObjectArray<InterfaceInfo> *m_interfaces; |
98762401 | 252 | void *m_data; // Can be used by custom enumeration handlers |
f34e7a6e | 253 | bool m_needPrefixWalk; |
98762401 VK |
254 | |
255 | public: | |
256 | InterfaceList(int initialAlloc = 8); | |
257 | ~InterfaceList(); | |
258 | ||
c30c0c0f VK |
259 | void add(InterfaceInfo *iface) { m_interfaces->add(iface); } |
260 | void remove(int index) { m_interfaces->remove(index); } | |
98762401 | 261 | |
c30c0c0f VK |
262 | int size() { return m_interfaces->size(); } |
263 | InterfaceInfo *get(int index) { return m_interfaces->get(index); } | |
264 | InterfaceInfo *findByIfIndex(UINT32 ifIndex); | |
98762401 VK |
265 | |
266 | void setData(void *data) { m_data = data; } | |
267 | void *getData() { return m_data; } | |
f34e7a6e VK |
268 | |
269 | bool isPrefixWalkNeeded() { return m_needPrefixWalk; } | |
270 | void setPrefixWalkNeeded() { m_needPrefixWalk = true; } | |
98762401 | 271 | }; |
5039dede | 272 | |
f375019e VK |
273 | /** |
274 | * Vlan information | |
275 | */ | |
0208aa8c VK |
276 | #define VLAN_PRM_IFINDEX 0 |
277 | #define VLAN_PRM_SLOTPORT 1 | |
5eb3a790 | 278 | #define VLAN_PRM_BPORT 2 |
0208aa8c | 279 | |
77c7801c VK |
280 | class LIBNXSRV_EXPORTABLE VlanInfo |
281 | { | |
282 | private: | |
283 | int m_vlanId; | |
284 | TCHAR *m_name; | |
0208aa8c | 285 | int m_portRefMode; // Port reference mode - by ifIndex or by slot/port |
77c7801c VK |
286 | int m_allocated; |
287 | int m_numPorts; // Number of ports in VLAN | |
967893bb VK |
288 | UINT32 *m_ports; // member ports (slot/port pairs or ifIndex) |
289 | UINT32 *m_indexes; // ifIndexes for ports | |
290 | UINT32 *m_ids; // Interface object IDs for ports | |
77c7801c VK |
291 | |
292 | public: | |
0208aa8c | 293 | VlanInfo(int vlanId, int prm); |
77c7801c VK |
294 | ~VlanInfo(); |
295 | ||
296 | int getVlanId() { return m_vlanId; } | |
0208aa8c | 297 | int getPortReferenceMode() { return m_portRefMode; } |
77c7801c VK |
298 | const TCHAR *getName() { return CHECK_NULL_EX(m_name); } |
299 | int getNumPorts() { return m_numPorts; } | |
967893bb VK |
300 | UINT32 *getPorts() { return m_ports; } |
301 | UINT32 *getIfIndexes() { return m_indexes; } | |
302 | UINT32 *getIfIds() { return m_ids; } | |
77c7801c | 303 | |
967893bb VK |
304 | void add(UINT32 slot, UINT32 port); |
305 | void add(UINT32 ifIndex); | |
77c7801c | 306 | void setName(const TCHAR *name); |
b1bd1fb2 VK |
307 | |
308 | void prepareForResolve(); | |
967893bb | 309 | void resolvePort(int index, UINT32 sp, UINT32 ifIndex, UINT32 id); |
77c7801c VK |
310 | }; |
311 | ||
a3050773 VK |
312 | /** |
313 | * Vlan list | |
314 | */ | |
7f632dfe | 315 | class LIBNXSRV_EXPORTABLE VlanList : public RefCountObject |
77c7801c VK |
316 | { |
317 | private: | |
318 | int m_size; // Number of valid entries | |
319 | int m_allocated; // Number of allocated entries | |
320 | void *m_data; // Can be used by custom enumeration handlers | |
321 | VlanInfo **m_vlans; // VLAN entries | |
322 | ||
323 | public: | |
324 | VlanList(int initialAlloc = 8); | |
7f632dfe | 325 | virtual ~VlanList(); |
77c7801c VK |
326 | |
327 | void add(VlanInfo *vlan); | |
967893bb | 328 | void addMemberPort(int vlanId, UINT32 portId); |
77c7801c | 329 | |
a6312bd6 | 330 | int size() { return m_size; } |
77c7801c | 331 | VlanInfo *get(int index) { return ((index >= 0) && (index < m_size)) ? m_vlans[index] : NULL; } |
0208aa8c | 332 | VlanInfo *findById(int id); |
0239cfea | 333 | VlanInfo *findByName(const TCHAR *name); |
77c7801c VK |
334 | |
335 | void setData(void *data) { m_data = data; } | |
336 | void *getData() { return m_data; } | |
7f632dfe | 337 | |
b368969c | 338 | void fillMessage(NXCPMessage *msg); |
77c7801c VK |
339 | }; |
340 | ||
a3050773 VK |
341 | /** |
342 | * Route information | |
343 | */ | |
5039dede AK |
344 | typedef struct |
345 | { | |
967893bb VK |
346 | UINT32 dwDestAddr; |
347 | UINT32 dwDestMask; | |
348 | UINT32 dwNextHop; | |
349 | UINT32 dwIfIndex; | |
350 | UINT32 dwRouteType; | |
5039dede AK |
351 | } ROUTE; |
352 | ||
a3050773 VK |
353 | /** |
354 | * Routing table | |
355 | */ | |
5039dede AK |
356 | typedef struct |
357 | { | |
358 | int iNumEntries; // Number of entries | |
359 | ROUTE *pRoutes; // Route list | |
360 | } ROUTING_TABLE; | |
361 | ||
a3050773 VK |
362 | /** |
363 | * Information about policies installed on agent | |
364 | */ | |
1f385e47 VK |
365 | class LIBNXSRV_EXPORTABLE AgentPolicyInfo |
366 | { | |
367 | private: | |
368 | int m_size; | |
369 | BYTE *m_guidList; | |
370 | int *m_typeList; | |
371 | TCHAR **m_serverList; | |
372 | ||
373 | public: | |
b368969c | 374 | AgentPolicyInfo(NXCPMessage *msg); |
1f385e47 VK |
375 | ~AgentPolicyInfo(); |
376 | ||
a6312bd6 | 377 | int size() { return m_size; } |
de4af576 | 378 | uuid getGuid(int index); |
1f385e47 VK |
379 | int getType(int index) { return ((index >= 0) && (index < m_size)) ? m_typeList[index] : -1; } |
380 | const TCHAR *getServer(int index) { return ((index >= 0) && (index < m_size)) ? m_serverList[index] : NULL; } | |
381 | }; | |
382 | ||
86c126f5 VK |
383 | /** |
384 | * Agent parameter definition | |
385 | */ | |
386 | class LIBNXSRV_EXPORTABLE AgentParameterDefinition | |
387 | { | |
388 | private: | |
389 | TCHAR *m_name; | |
390 | TCHAR *m_description; | |
391 | int m_dataType; | |
392 | ||
393 | public: | |
b368969c | 394 | AgentParameterDefinition(NXCPMessage *msg, UINT32 baseId); |
86c126f5 VK |
395 | AgentParameterDefinition(AgentParameterDefinition *src); |
396 | ~AgentParameterDefinition(); | |
397 | ||
b368969c | 398 | UINT32 fillMessage(NXCPMessage *msg, UINT32 baseId); |
86c126f5 VK |
399 | |
400 | const TCHAR *getName() { return m_name; } | |
401 | const TCHAR *getDescription() { return m_description; } | |
402 | int getDataType() { return m_dataType; } | |
403 | }; | |
404 | ||
405 | /** | |
406 | * Agent table column definition | |
407 | */ | |
408 | struct AgentTableColumnDefinition | |
409 | { | |
410 | TCHAR m_name[MAX_COLUMN_NAME]; | |
411 | int m_dataType; | |
412 | ||
413 | AgentTableColumnDefinition(AgentTableColumnDefinition *src) | |
414 | { | |
415 | nx_strncpy(m_name, src->m_name, MAX_COLUMN_NAME); | |
416 | m_dataType = src->m_dataType; | |
417 | } | |
418 | }; | |
419 | ||
420 | /** | |
421 | * Agent table definition | |
422 | */ | |
423 | class LIBNXSRV_EXPORTABLE AgentTableDefinition | |
424 | { | |
425 | private: | |
426 | TCHAR *m_name; | |
427 | TCHAR *m_description; | |
428 | StringList *m_instanceColumns; | |
429 | ObjectArray<AgentTableColumnDefinition> *m_columns; | |
430 | ||
431 | public: | |
b368969c | 432 | AgentTableDefinition(NXCPMessage *msg, UINT32 baseId); |
86c126f5 VK |
433 | AgentTableDefinition(AgentTableDefinition *src); |
434 | ~AgentTableDefinition(); | |
435 | ||
b368969c | 436 | UINT32 fillMessage(NXCPMessage *msg, UINT32 baseId); |
86c126f5 VK |
437 | |
438 | const TCHAR *getName() { return m_name; } | |
439 | const TCHAR *getDescription() { return m_description; } | |
440 | }; | |
441 | ||
a3050773 VK |
442 | /** |
443 | * Agent connection | |
444 | */ | |
5039dede AK |
445 | class LIBNXSRV_EXPORTABLE AgentConnection |
446 | { | |
447 | private: | |
c11eee9b | 448 | InetAddress m_addr; |
5039dede AK |
449 | int m_nProtocolVersion; |
450 | int m_iAuthMethod; | |
08b214c6 | 451 | char m_szSecret[MAX_SECRET_LENGTH]; |
5039dede AK |
452 | time_t m_tLastCommandTime; |
453 | SOCKET m_hSocket; | |
967893bb | 454 | UINT32 m_dwNumDataLines; |
e9902466 | 455 | VolatileCounter m_requestId; |
967893bb VK |
456 | UINT32 m_dwCommandTimeout; |
457 | UINT32 m_connectionTimeout; | |
458 | UINT32 m_dwRecvTimeout; | |
5039dede AK |
459 | TCHAR **m_ppDataLines; |
460 | MsgWaitQueue *m_pMsgWaitQueue; | |
9fd816cc | 461 | bool m_isConnected; |
5039dede | 462 | MUTEX m_mutexDataLock; |
d3a7cf4c | 463 | MUTEX m_mutexSocketWrite; |
5039dede | 464 | THREAD m_hReceiverThread; |
98abc9f1 | 465 | NXCPEncryptionContext *m_pCtx; |
5039dede AK |
466 | int m_iEncryptionPolicy; |
467 | BOOL m_bUseProxy; | |
c11eee9b | 468 | InetAddress m_proxyAddr; |
5039dede AK |
469 | WORD m_wPort; |
470 | WORD m_wProxyPort; | |
471 | int m_iProxyAuth; | |
08b214c6 | 472 | char m_szProxySecret[MAX_SECRET_LENGTH]; |
5039dede | 473 | int m_hCurrFile; |
9f6d453a | 474 | TCHAR m_currentFileName[MAX_PATH]; |
967893bb | 475 | UINT32 m_dwDownloadRequestId; |
bb85e341 VK |
476 | CONDITION m_condFileDownload; |
477 | BOOL m_fileDownloadSucceeded; | |
478 | void (*m_downloadProgressCallback)(size_t, void *); | |
479 | void *m_downloadProgressCallbackArg; | |
901a5a9b | 480 | bool m_deleteFileOnDownloadFailure; |
b368969c | 481 | void (*m_sendToClientMessageCallback)(NXCP_MESSAGE*, void *); |
4685a2ad | 482 | bool m_fileUploadInProgress; |
5039dede | 483 | |
a3050773 VK |
484 | void receiverThread(); |
485 | static THREAD_RESULT THREAD_CALL receiverThreadStarter(void *); | |
5039dede AK |
486 | |
487 | protected: | |
7c521895 | 488 | void destroyResultData(); |
967893bb VK |
489 | UINT32 waitForRCC(UINT32 dwRqId, UINT32 dwTimeOut); |
490 | UINT32 setupEncryption(RSA *pServerKey); | |
491 | UINT32 authenticate(BOOL bProxyData); | |
492 | UINT32 setupProxyConnection(); | |
c11eee9b | 493 | const InetAddress& getIpAddr() { return m_addr; } |
b368969c | 494 | UINT32 prepareFileDownload(const TCHAR *fileName, UINT32 rqId, bool append, void (*downloadProgressCallback)(size_t, void *), void (*fileResendCallback)(NXCP_MESSAGE*, void *), void *cbArg); |
5039dede | 495 | |
af21affe | 496 | virtual void printMsg(const TCHAR *format, ...); |
b368969c VK |
497 | virtual void onTrap(NXCPMessage *pMsg); |
498 | virtual void onDataPush(NXCPMessage *msg); | |
499 | virtual void onFileMonitoringData(NXCPMessage *msg); | |
500 | virtual void onSnmpTrap(NXCPMessage *pMsg); | |
f480bdd4 | 501 | virtual void onFileDownload(BOOL success); |
02d936bd | 502 | virtual UINT32 processCollectedData(NXCPMessage *msg); |
6fbaa926 | 503 | virtual bool processCustomMessage(NXCPMessage *pMsg); |
5039dede | 504 | |
a3050773 VK |
505 | void lock() { MutexLock(m_mutexDataLock); } |
506 | void unlock() { MutexUnlock(m_mutexDataLock); } | |
98abc9f1 | 507 | NXCPEncryptionContext *acquireEncryptionContext(); |
5039dede AK |
508 | |
509 | public: | |
b368969c VK |
510 | BOOL sendMessage(NXCPMessage *pMsg); |
511 | NXCPMessage *waitForMessage(WORD wCode, UINT32 dwId, UINT32 dwTimeOut) { return m_pMsgWaitQueue->waitForMessage(wCode, dwId, dwTimeOut); } | |
c11eee9b | 512 | AgentConnection(InetAddress addr, WORD port = AGENT_LISTEN_PORT, int authMethod = AUTH_NONE, const TCHAR *secret = NULL); |
5039dede AK |
513 | virtual ~AgentConnection(); |
514 | ||
9fd816cc | 515 | bool connect(RSA *pServerKey = NULL, BOOL bVerbose = FALSE, UINT32 *pdwError = NULL, UINT32 *pdwSocketError = NULL); |
7c521895 | 516 | void disconnect(); |
9fd816cc | 517 | bool isConnected() { return m_isConnected; } |
7c521895 | 518 | int getProtocolVersion() { return m_nProtocolVersion; } |
5039dede | 519 | |
45d84f8a | 520 | SOCKET getSocket() { return m_hSocket; } |
5a9e58a3 | 521 | |
4687826e | 522 | ARP_CACHE *getArpCache(); |
98762401 | 523 | InterfaceList *getInterfaceList(); |
4687826e | 524 | ROUTING_TABLE *getRoutingTable(); |
967893bb VK |
525 | UINT32 getParameter(const TCHAR *pszParam, UINT32 dwBufSize, TCHAR *pszBuffer); |
526 | UINT32 getList(const TCHAR *pszParam); | |
527 | UINT32 getTable(const TCHAR *pszParam, Table **table); | |
528 | UINT32 nop(); | |
ea3993c8 | 529 | UINT32 enableIPv6(); |
e9902466 | 530 | UINT32 setServerId(UINT64 serverId); |
908d71bd | 531 | UINT32 execAction(const TCHAR *pszAction, int argc, TCHAR **argv, bool withOutput = false, void (* outputCallback)(ActionCallbackEvent, const TCHAR *, void *) = NULL, void *cbData = NULL); |
503da871 | 532 | UINT32 uploadFile(const TCHAR *localFile, const TCHAR *destinationFile = NULL, void (* progressCallback)(INT64, void *) = NULL, void *cbArg = NULL, NXCPCompressionMethod compMethod = NXCP_COMPRESSION_NONE); |
967893bb | 533 | UINT32 startUpgrade(const TCHAR *pszPkgName); |
c75e9ee4 | 534 | UINT32 checkNetworkService(UINT32 *pdwStatus, const InetAddress& addr, int iServiceType, WORD wPort = 0, |
b8014eee | 535 | WORD wProto = 0, const TCHAR *pszRequest = NULL, const TCHAR *pszResponse = NULL, UINT32 *responseTime = NULL); |
967893bb VK |
536 | UINT32 getSupportedParameters(ObjectArray<AgentParameterDefinition> **paramList, ObjectArray<AgentTableDefinition> **tableList); |
537 | UINT32 getConfigFile(TCHAR **ppszConfig, UINT32 *pdwSize); | |
538 | UINT32 updateConfigFile(const TCHAR *pszConfig); | |
539 | UINT32 enableTraps(); | |
e13420c1 | 540 | UINT32 enableFileUpdates(); |
967893bb VK |
541 | UINT32 getPolicyInventory(AgentPolicyInfo **info); |
542 | UINT32 uninstallPolicy(uuid_t guid); | |
9c786c0f | 543 | UINT32 takeScreenshot(const TCHAR *sessionName, BYTE **data, size_t *size); |
967893bb | 544 | |
e9902466 | 545 | UINT32 generateRequestId() { return (UINT32)InterlockedIncrement(&m_requestId); } |
b368969c VK |
546 | NXCPMessage *customRequest(NXCPMessage *pRequest, const TCHAR *recvFile = NULL, bool append = false, void (*downloadProgressCallback)(size_t, void *) = NULL, |
547 | void (*fileResendCallback)(NXCP_MESSAGE*, void *) = NULL, void *cbArg = NULL); | |
5039dede | 548 | |
967893bb VK |
549 | UINT32 getNumDataLines() { return m_dwNumDataLines; } |
550 | const TCHAR *getDataLine(UINT32 dwIndex) { return dwIndex < m_dwNumDataLines ? m_ppDataLines[dwIndex] : _T("(error)"); } | |
5039dede | 551 | |
967893bb VK |
552 | void setConnectionTimeout(UINT32 dwTimeout) { m_connectionTimeout = max(dwTimeout, 1000); } |
553 | UINT32 getConnectionTimeout() { return m_connectionTimeout; } | |
554 | void setCommandTimeout(UINT32 dwTimeout) { m_dwCommandTimeout = max(dwTimeout, 500); } | |
555 | UINT32 getCommandTimeout() { return m_dwCommandTimeout; } | |
556 | void setRecvTimeout(UINT32 dwTimeout) { m_dwRecvTimeout = max(dwTimeout, 10000); } | |
7c521895 | 557 | void setEncryptionPolicy(int iPolicy) { m_iEncryptionPolicy = iPolicy; } |
c11eee9b | 558 | void setProxy(InetAddress addr, WORD wPort = AGENT_LISTEN_PORT, |
5039dede | 559 | int iAuthMethod = AUTH_NONE, const TCHAR *pszSecret = NULL); |
7c521895 | 560 | void setPort(WORD wPort) { m_wPort = wPort; } |
af21affe | 561 | void setAuthData(int method, const TCHAR *secret); |
76b4edb5 | 562 | void setDeleteFileOnDownloadFailure(bool flag) { m_deleteFileOnDownloadFailure = flag; } |
b368969c | 563 | BOOL sendRawMessage(NXCP_MESSAGE *pMsg); |
5039dede AK |
564 | }; |
565 | ||
a3050773 VK |
566 | /** |
567 | * Proxy SNMP transport | |
568 | */ | |
5039dede AK |
569 | class LIBNXSRV_EXPORTABLE SNMP_ProxyTransport : public SNMP_Transport |
570 | { | |
571 | protected: | |
c75e9ee4 VK |
572 | AgentConnection *m_agentConnection; |
573 | NXCPMessage *m_response; | |
574 | InetAddress m_ipAddr; | |
575 | WORD m_port; | |
489b117b | 576 | bool m_waitForResponse; |
5039dede AK |
577 | |
578 | public: | |
c75e9ee4 | 579 | SNMP_ProxyTransport(AgentConnection *conn, const InetAddress& ipAddr, WORD port); |
5039dede AK |
580 | virtual ~SNMP_ProxyTransport(); |
581 | ||
967893bb | 582 | virtual int readMessage(SNMP_PDU **ppData, UINT32 dwTimeout = INFINITE, |
cd9f247e VK |
583 | struct sockaddr *pSender = NULL, socklen_t *piAddrSize = NULL, |
584 | SNMP_SecurityContext* (*contextFinder)(struct sockaddr *, socklen_t) = NULL); | |
c4366266 | 585 | virtual int sendMessage(SNMP_PDU *pdu); |
c75e9ee4 | 586 | virtual InetAddress getPeerIpAddress(); |
d0a2ada6 | 587 | WORD getPort() { return m_port; } |
b368969c VK |
588 | |
589 | void setWaitForResponse(bool wait) { m_waitForResponse = wait; } | |
5039dede AK |
590 | }; |
591 | ||
596dc3aa VK |
592 | /** |
593 | * ISC flags | |
594 | */ | |
967893bb VK |
595 | #define ISCF_IS_CONNECTED ((UINT32)0x00000001) |
596 | #define ISCF_REQUIRE_ENCRYPTION ((UINT32)0x00000002) | |
5039dede | 597 | |
ed950274 VK |
598 | /** |
599 | * Inter-server connection (ISC) | |
600 | */ | |
5039dede AK |
601 | class LIBNXSRV_EXPORTABLE ISC |
602 | { | |
603 | private: | |
967893bb | 604 | UINT32 m_flags; |
9d061c7b | 605 | InetAddress m_addr; |
5039dede AK |
606 | WORD m_port; |
607 | SOCKET m_socket; | |
608 | int m_protocolVersion; | |
bc7767c4 | 609 | VolatileCounter m_requestId; |
967893bb | 610 | UINT32 m_recvTimeout; |
5039dede AK |
611 | MsgWaitQueue *m_msgWaitQueue; |
612 | MUTEX m_mutexDataLock; | |
7b8b337e | 613 | MUTEX m_socketLock; |
5039dede | 614 | THREAD m_hReceiverThread; |
98abc9f1 | 615 | NXCPEncryptionContext *m_ctx; |
967893bb | 616 | UINT32 m_commandTimeout; |
5039dede | 617 | |
bc7767c4 VK |
618 | void receiverThread(); |
619 | static THREAD_RESULT THREAD_CALL receiverThreadStarter(void *); | |
5039dede AK |
620 | |
621 | protected: | |
bc7767c4 VK |
622 | UINT32 setupEncryption(RSA *pServerKey); |
623 | UINT32 connectToService(UINT32 service); | |
5039dede | 624 | |
796baedf VK |
625 | void lock() { MutexLock(m_mutexDataLock); } |
626 | void unlock() { MutexUnlock(m_mutexDataLock); } | |
5039dede | 627 | |
796baedf | 628 | virtual void printMessage(const TCHAR *format, ...); |
b368969c VK |
629 | virtual void onBinaryMessage(NXCP_MESSAGE *rawMsg); |
630 | virtual bool onMessage(NXCPMessage *msg); | |
5039dede AK |
631 | |
632 | public: | |
633 | ISC(); | |
9d061c7b | 634 | ISC(const InetAddress& addr, WORD port = NETXMS_ISC_PORT); |
5039dede AK |
635 | virtual ~ISC(); |
636 | ||
bc7767c4 VK |
637 | UINT32 connect(UINT32 service, RSA *serverKey = NULL, BOOL requireEncryption = FALSE); |
638 | void disconnect(); | |
e7aff566 | 639 | bool connected() { return m_flags & ISCF_IS_CONNECTED; }; |
5039dede | 640 | |
b368969c VK |
641 | BOOL sendMessage(NXCPMessage *msg); |
642 | NXCPMessage *waitForMessage(WORD code, UINT32 id, UINT32 timeOut) { return m_msgWaitQueue->waitForMessage(code, id, timeOut); } | |
bc7767c4 VK |
643 | UINT32 waitForRCC(UINT32 rqId, UINT32 timeOut); |
644 | UINT32 generateMessageId() { return (UINT32)InterlockedIncrement(&m_requestId); } | |
5039dede | 645 | |
bc7767c4 | 646 | UINT32 nop(); |
5039dede AK |
647 | }; |
648 | ||
649 | ||
650 | // | |
651 | // Functions | |
652 | // | |
653 | ||
654 | void LIBNXSRV_EXPORTABLE DestroyArpCache(ARP_CACHE *pArpCache); | |
5039dede AK |
655 | void LIBNXSRV_EXPORTABLE DestroyRoutingTable(ROUTING_TABLE *pRT); |
656 | void LIBNXSRV_EXPORTABLE SortRoutingTable(ROUTING_TABLE *pRT); | |
bf6fb6c3 VK |
657 | const TCHAR LIBNXSRV_EXPORTABLE *AgentErrorCodeToText(UINT32 err); |
658 | UINT32 LIBNXSRV_EXPORTABLE AgentErrorToRCC(UINT32 err); | |
5039dede | 659 | |
640b6719 | 660 | void LIBNXSRV_EXPORTABLE WriteLogOther(WORD wType, const TCHAR *format, ...) |
6e383343 | 661 | #if !defined(UNICODE) && (defined(__GNUC__) || defined(__clang__)) |
640b6719 VK |
662 | __attribute__ ((format(printf, 2, 3))) |
663 | #endif | |
664 | ; | |
665 | ||
666 | void LIBNXSRV_EXPORTABLE DbgPrintf(int level, const TCHAR *format, ...) | |
6e383343 | 667 | #if !defined(UNICODE) && (defined(__GNUC__) || defined(__clang__)) |
640b6719 VK |
668 | __attribute__ ((format(printf, 2, 3))) |
669 | #endif | |
670 | ; | |
671 | ||
9d88cdc9 | 672 | void LIBNXSRV_EXPORTABLE DbgPrintf2(int level, const TCHAR *format, va_list args); |
c20b2798 | 673 | |
5039dede AK |
674 | void LIBNXSRV_EXPORTABLE SetAgentDEP(int iPolicy); |
675 | ||
967893bb | 676 | const TCHAR LIBNXSRV_EXPORTABLE *ISCErrorCodeToText(UINT32 code); |
5039dede | 677 | |
640b6719 VK |
678 | /** |
679 | * Variables | |
680 | */ | |
c8076b19 | 681 | extern UINT64 LIBNXSRV_EXPORTABLE g_flags; |
967893bb | 682 | extern UINT32 LIBNXSRV_EXPORTABLE g_debugLevel; |
5039dede | 683 | |
640b6719 VK |
684 | /** |
685 | * Helper finctions for checking server flags | |
686 | */ | |
89135050 VK |
687 | inline bool IsStandalone() |
688 | { | |
c8076b19 | 689 | return !(g_flags & AF_DAEMON) ? true : false; |
89135050 VK |
690 | } |
691 | ||
692 | inline bool IsZoningEnabled() | |
693 | { | |
c8076b19 | 694 | return (g_flags & AF_ENABLE_ZONING) ? true : false; |
89135050 VK |
695 | } |
696 | ||
697 | inline bool IsShutdownInProgress() | |
698 | { | |
c8076b19 | 699 | return (g_flags & AF_SHUTDOWN) ? true : false; |
89135050 VK |
700 | } |
701 | ||
702 | ||
5039dede | 703 | #endif /* _nxsrvapi_h_ */ |