/src/net-snmp/snmplib/snmp_debug.c
Line | Count | Source |
1 | | /* |
2 | | * Portions of this file are subject to the following copyright(s). See |
3 | | * the Net-SNMP's COPYING file for more details and other copyrights |
4 | | * that may apply: |
5 | | * |
6 | | * Portions of this file are copyrighted by: |
7 | | * Copyright (c) 2016 VMware, Inc. All rights reserved. |
8 | | * Use is subject to license terms specified in the COPYING file |
9 | | * distributed with the Net-SNMP package. |
10 | | */ |
11 | | |
12 | | #include <net-snmp/net-snmp-config.h> |
13 | | |
14 | | #define SYSLOG_NAMES |
15 | | |
16 | | #include <limits.h> |
17 | | #include <stdio.h> |
18 | | #ifndef HAVE_PRIORITYNAMES |
19 | | #include <errno.h> |
20 | | #endif |
21 | | #ifdef HAVE_STDLIB_H |
22 | | #include <stdlib.h> |
23 | | #endif |
24 | | #ifdef HAVE_STRING_H |
25 | | #include <string.h> |
26 | | #else |
27 | | #include <strings.h> |
28 | | #endif |
29 | | #include <sys/types.h> |
30 | | #ifdef HAVE_NETINET_IN_H |
31 | | #include <netinet/in.h> |
32 | | #endif |
33 | | #include <stdarg.h> |
34 | | |
35 | | #ifdef HAVE_UNISTD_H |
36 | | #include <unistd.h> |
37 | | #endif |
38 | | |
39 | | #ifdef HAVE_PRIORITYNAMES |
40 | | #if defined( HAVE_SYSLOG_H ) |
41 | | #include <syslog.h> |
42 | | #elif defined ( HAVE_SYS_SYSLOG_H ) |
43 | | #include <sys/syslog.h> |
44 | | #endif |
45 | | #endif |
46 | | |
47 | | #include <net-snmp/types.h> |
48 | | #include <net-snmp/output_api.h> |
49 | | #include <net-snmp/library/snmp_debug.h> /* For this file's "internal" definitions */ |
50 | | #include <net-snmp/config_api.h> |
51 | | #include <net-snmp/utilities.h> |
52 | | |
53 | | #include <net-snmp/library/mib.h> |
54 | | #include <net-snmp/library/snmp_api.h> |
55 | | #include <net-snmp/library/snmp_assert.h> |
56 | | |
57 | 0 | #define SNMP_DEBUG_DISABLED 0 |
58 | 0 | #define SNMP_DEBUG_ACTIVE 1 |
59 | | #define SNMP_DEBUG_EXCLUDED 2 |
60 | | |
61 | | #ifndef NETSNMP_NO_DEBUGGING |
62 | | |
63 | | static int dodebug = NETSNMP_ALWAYS_DEBUG; |
64 | | int debug_num_tokens = 0; |
65 | | static int debug_print_everything = 0; |
66 | | #ifndef NETSNMP_DISABLE_DYNAMIC_LOG_LEVEL |
67 | | static int debug_log_level = LOG_DEBUG; |
68 | | #else |
69 | | #define debug_log_level LOG_DEBUG |
70 | | #endif /* NETSNMP_DISABLE_DYNAMIC_LOG_LEVEL */ |
71 | | |
72 | | netsnmp_token_descr dbg_tokens[MAX_DEBUG_TOKENS]; |
73 | | |
74 | | /* |
75 | | * Number of spaces to indent debug output. Valid range is [0,INT_MAX] |
76 | | */ |
77 | | static int debugindent = 0; |
78 | | |
79 | | int |
80 | | debug_indent_get(void) |
81 | 0 | { |
82 | 0 | return debugindent; |
83 | 0 | } |
84 | | |
85 | | const char* |
86 | | debug_indent(void) |
87 | 0 | { |
88 | 0 | static const char SPACES[] = " " |
89 | 0 | " "; |
90 | |
|
91 | 0 | if ((sizeof(SPACES) - 1) < (unsigned int)debugindent) { |
92 | 0 | snmp_log(LOG_ERR, "Too deep indentation for debug_indent. " |
93 | 0 | "Consider using \"%%*s\", debug_indent_get(), \"\" instead."); |
94 | 0 | return SPACES; |
95 | 0 | } |
96 | 0 | return &SPACES[sizeof(SPACES) - 1 - debugindent]; |
97 | 0 | } |
98 | | |
99 | | void |
100 | | debug_indent_add(int amount) |
101 | 0 | { |
102 | 0 | if (-debugindent <= amount && amount <= INT_MAX - debugindent) |
103 | 0 | debugindent += amount; |
104 | 0 | netsnmp_assert( debugindent >= 0 ); /* no negative indents */ |
105 | 0 | } |
106 | | |
107 | | NETSNMP_IMPORT void |
108 | | debug_config_register_tokens(const char *configtoken, char *tokens); |
109 | | |
110 | | void |
111 | | debug_indent_reset(void) |
112 | 0 | { |
113 | 0 | if (debugindent != 0) |
114 | 0 | DEBUGMSGTL(("dump_indent","indent reset from %d\n", debugindent)); |
115 | 0 | debugindent = 0; |
116 | 0 | } |
117 | | |
118 | | void |
119 | | debug_config_register_tokens(const char *configtoken, char *tokens) |
120 | 0 | { |
121 | 0 | debug_register_tokens(tokens); |
122 | 0 | } |
123 | | |
124 | | NETSNMP_IMPORT void |
125 | | debug_config_turn_on_debugging(const char *configtoken, char *line); |
126 | | |
127 | | void |
128 | | debug_config_turn_on_debugging(const char *configtoken, char *line) |
129 | 0 | { |
130 | 0 | snmp_set_do_debugging(atoi(line)); |
131 | 0 | } |
132 | | |
133 | | #ifndef NETSNMP_DISABLE_DYNAMIC_LOG_LEVEL |
134 | | |
135 | | void |
136 | | netsnmp_set_debug_log_level(int val) |
137 | 0 | { |
138 | 0 | if (val < LOG_EMERG) |
139 | 0 | val = LOG_EMERG; |
140 | 0 | else if (val > LOG_DEBUG) |
141 | 0 | val = LOG_DEBUG; |
142 | 0 | debug_log_level = val; |
143 | 0 | } |
144 | | |
145 | | int |
146 | | netsnmp_get_debug_log_level(void) |
147 | 0 | { |
148 | 0 | return debug_log_level; |
149 | 0 | } |
150 | | |
151 | | static void |
152 | | debug_config_debug_log_level(const char *configtoken, char *line) |
153 | 0 | { |
154 | | #ifndef HAVE_PRIORITYNAMES |
155 | | static const struct strval_s { |
156 | | const char *c_name; |
157 | | int c_val; |
158 | | } prioritynames[] = { |
159 | | { "alert", LOG_ALERT }, |
160 | | { "crit", LOG_CRIT }, |
161 | | { "debug", LOG_DEBUG }, |
162 | | { "emerg", LOG_EMERG }, |
163 | | { "err", LOG_ERR }, |
164 | | { "info", LOG_INFO }, |
165 | | { "notice", LOG_NOTICE }, |
166 | | { "warning", LOG_WARNING }, |
167 | | { NULL, 0 } |
168 | | }; |
169 | | #endif |
170 | 0 | int i = 0, len_l, len_p; |
171 | |
|
172 | 0 | len_l = strlen(line); |
173 | 0 | for(;prioritynames[i].c_name;++i) { |
174 | 0 | len_p = strlen(prioritynames[i].c_name); |
175 | 0 | if ((len_p != len_l) || |
176 | 0 | (strcasecmp(line,prioritynames[i].c_name) != 0)) |
177 | 0 | continue; |
178 | 0 | netsnmp_set_debug_log_level(prioritynames[i].c_val); |
179 | 0 | return; |
180 | 0 | } |
181 | 0 | config_perror("unknown debug log level, using debug"); |
182 | 0 | netsnmp_set_debug_log_level(LOG_DEBUG); |
183 | 0 | } |
184 | | #endif /* NETSNMP_DISABLE_DYNAMIC_LOG_LEVEL */ |
185 | | |
186 | | void |
187 | | debug_register_tokens(const char *tokens) |
188 | 0 | { |
189 | 0 | char *newp, *cp; |
190 | 0 | char *st = NULL; |
191 | 0 | int status; |
192 | |
|
193 | 0 | if (tokens == NULL || *tokens == 0) |
194 | 0 | return; |
195 | | |
196 | 0 | newp = strdup(tokens); /* strtok_r messes it up */ |
197 | 0 | if (!newp) |
198 | 0 | return; |
199 | 0 | cp = strtok_r(newp, DEBUG_TOKEN_DELIMITER, &st); |
200 | 0 | while (cp) { |
201 | 0 | if (strlen(cp) < MAX_DEBUG_TOKEN_LEN) { |
202 | 0 | if (strcasecmp(cp, DEBUG_ALWAYS_TOKEN) == 0) { |
203 | 0 | debug_print_everything = 1; |
204 | 0 | } else if (debug_num_tokens < MAX_DEBUG_TOKENS) { |
205 | 0 | if ('-' == *cp) { |
206 | 0 | ++cp; |
207 | 0 | status = SNMP_DEBUG_DISABLED; |
208 | 0 | } |
209 | 0 | else |
210 | 0 | status = SNMP_DEBUG_ACTIVE; |
211 | 0 | dbg_tokens[debug_num_tokens].token_name = strdup(cp); |
212 | 0 | dbg_tokens[debug_num_tokens++].enabled = status; |
213 | 0 | snmp_log(LOG_NOTICE, "registered debug token %s, %d\n", cp, status); |
214 | 0 | } else { |
215 | 0 | snmp_log(LOG_NOTICE, "Unable to register debug token %s\n", cp); |
216 | 0 | } |
217 | 0 | } else { |
218 | 0 | snmp_log(LOG_NOTICE, "Debug token %s over length\n", cp); |
219 | 0 | } |
220 | 0 | cp = strtok_r(NULL, DEBUG_TOKEN_DELIMITER, &st); |
221 | 0 | } |
222 | 0 | free(newp); |
223 | 0 | } |
224 | | |
225 | | /* |
226 | | * Print all registered tokens along with their current status |
227 | | */ |
228 | | void |
229 | 0 | debug_print_registered_tokens(void) { |
230 | 0 | int i; |
231 | |
|
232 | 0 | snmp_log(LOG_INFO, "%d tokens registered :\n", debug_num_tokens); |
233 | 0 | for (i=0; i<debug_num_tokens; i++) { |
234 | 0 | snmp_log( LOG_INFO, "%d) %s : %d\n", |
235 | 0 | i, dbg_tokens [i].token_name, dbg_tokens [i].enabled); |
236 | 0 | } |
237 | 0 | } |
238 | | |
239 | | |
240 | | /* |
241 | | * Enable logs on a given token |
242 | | */ |
243 | | int |
244 | 0 | debug_enable_token_logs (const char *token) { |
245 | 0 | int i; |
246 | | |
247 | | /* debugging flag is on or off */ |
248 | 0 | if (!dodebug) |
249 | 0 | return SNMPERR_GENERR; |
250 | | |
251 | 0 | if (debug_num_tokens == 0 || debug_print_everything) { |
252 | | /* no tokens specified, print everything */ |
253 | 0 | return SNMPERR_SUCCESS; |
254 | 0 | } else { |
255 | 0 | for(i=0; i < debug_num_tokens; i++) { |
256 | 0 | if (dbg_tokens[i].token_name && |
257 | 0 | strncmp(dbg_tokens[i].token_name, token, |
258 | 0 | strlen(dbg_tokens[i].token_name)) == 0) { |
259 | 0 | dbg_tokens[i].enabled = SNMP_DEBUG_ACTIVE; |
260 | 0 | return SNMPERR_SUCCESS; |
261 | 0 | } |
262 | 0 | } |
263 | 0 | } |
264 | 0 | return SNMPERR_GENERR; |
265 | 0 | } |
266 | | |
267 | | /* |
268 | | * Disable logs on a given token |
269 | | */ |
270 | | int |
271 | 0 | debug_disable_token_logs (const char *token) { |
272 | 0 | int i; |
273 | | |
274 | | /* debugging flag is on or off */ |
275 | 0 | if (!dodebug) |
276 | 0 | return SNMPERR_GENERR; |
277 | | |
278 | 0 | if (debug_num_tokens == 0 || debug_print_everything) { |
279 | | /* no tokens specified, print everything */ |
280 | 0 | return SNMPERR_SUCCESS; |
281 | 0 | } else { |
282 | 0 | for(i=0; i < debug_num_tokens; i++) { |
283 | 0 | if (strncmp(dbg_tokens[i].token_name, token, |
284 | 0 | strlen(dbg_tokens[i].token_name)) == 0) { |
285 | 0 | dbg_tokens[i].enabled = SNMP_DEBUG_DISABLED; |
286 | 0 | return SNMPERR_SUCCESS; |
287 | 0 | } |
288 | 0 | } |
289 | 0 | } |
290 | 0 | return SNMPERR_GENERR; |
291 | 0 | } |
292 | | |
293 | | /* |
294 | | * debug_is_token_registered(char *TOKEN): |
295 | | * |
296 | | * returns SNMPERR_SUCCESS |
297 | | * or SNMPERR_GENERR |
298 | | * |
299 | | * if TOKEN has been registered and debugging support is turned on. |
300 | | */ |
301 | | int |
302 | | debug_is_token_registered(const char *token) |
303 | 0 | { |
304 | 0 | int i, rc; |
305 | | |
306 | | /* |
307 | | * debugging flag is on or off |
308 | | */ |
309 | 0 | if (!dodebug) |
310 | 0 | return SNMPERR_GENERR; |
311 | | |
312 | 0 | if (debug_num_tokens == 0 || debug_print_everything) { |
313 | | /* |
314 | | * no tokens specified, print everything |
315 | | */ |
316 | 0 | return SNMPERR_SUCCESS; |
317 | 0 | } |
318 | 0 | else |
319 | 0 | rc = SNMPERR_GENERR; /* ! found = err */ |
320 | | |
321 | 0 | for (i = 0; i < debug_num_tokens; i++) { |
322 | 0 | if (SNMP_DEBUG_DISABLED == dbg_tokens[i].enabled) |
323 | 0 | continue; |
324 | 0 | if (dbg_tokens[i].token_name && |
325 | 0 | strncmp(dbg_tokens[i].token_name, token, |
326 | 0 | strlen(dbg_tokens[i].token_name)) == 0) { |
327 | 0 | if (SNMP_DEBUG_ACTIVE == dbg_tokens[i].enabled) |
328 | 0 | return SNMPERR_SUCCESS; /* active */ |
329 | 0 | else |
330 | 0 | return SNMPERR_GENERR; /* excluded */ |
331 | 0 | } |
332 | 0 | } |
333 | 0 | return rc; |
334 | 0 | } |
335 | | |
336 | | void |
337 | | debugmsg(const char *token, const char *format, ...) |
338 | 0 | { |
339 | 0 | if (debug_is_token_registered(token) == SNMPERR_SUCCESS) { |
340 | 0 | va_list debugargs; |
341 | |
|
342 | 0 | va_start(debugargs, format); |
343 | 0 | snmp_vlog(debug_log_level, format, debugargs); |
344 | 0 | va_end(debugargs); |
345 | 0 | } |
346 | 0 | } |
347 | | |
348 | | void |
349 | | debugmsg_oid(const char *token, const oid * theoid, size_t len) |
350 | 0 | { |
351 | 0 | u_char *buf = NULL; |
352 | 0 | size_t buf_len = 0, out_len = 0; |
353 | |
|
354 | 0 | if (sprint_realloc_objid(&buf, &buf_len, &out_len, 1, theoid, len)) { |
355 | 0 | if (buf != NULL) { |
356 | 0 | debugmsg(token, "%s", buf); |
357 | 0 | } |
358 | 0 | } else { |
359 | 0 | if (buf != NULL) { |
360 | 0 | debugmsg(token, "%s [TRUNCATED]", buf); |
361 | 0 | } |
362 | 0 | } |
363 | |
|
364 | 0 | if (buf != NULL) { |
365 | 0 | free(buf); |
366 | 0 | } |
367 | 0 | } |
368 | | |
369 | | void |
370 | | debugmsg_suboid(const char *token, const oid * theoid, size_t len) |
371 | 0 | { |
372 | 0 | u_char *buf = NULL; |
373 | 0 | size_t buf_len = 0, out_len = 0; |
374 | 0 | int buf_overflow = 0; |
375 | |
|
376 | 0 | netsnmp_sprint_realloc_objid(&buf, &buf_len, &out_len, 1, |
377 | 0 | &buf_overflow, theoid, len); |
378 | 0 | if(buf_overflow) { |
379 | 0 | if (buf != NULL) { |
380 | 0 | debugmsg(token, "%s [TRUNCATED]", buf); |
381 | 0 | } |
382 | 0 | } else { |
383 | 0 | if (buf != NULL) { |
384 | 0 | debugmsg(token, "%s", buf); |
385 | 0 | } |
386 | 0 | } |
387 | |
|
388 | 0 | if (buf != NULL) { |
389 | 0 | free(buf); |
390 | 0 | } |
391 | 0 | } |
392 | | |
393 | | void |
394 | | debugmsg_var(const char *token, netsnmp_variable_list * var) |
395 | 0 | { |
396 | 0 | u_char *buf = NULL; |
397 | 0 | size_t buf_len = 0, out_len = 0; |
398 | |
|
399 | 0 | if (var == NULL || token == NULL) { |
400 | 0 | return; |
401 | 0 | } |
402 | | |
403 | 0 | if (sprint_realloc_variable(&buf, &buf_len, &out_len, 1, |
404 | 0 | var->name, var->name_length, var)) { |
405 | 0 | if (buf != NULL) { |
406 | 0 | debugmsg(token, "%s", buf); |
407 | 0 | } |
408 | 0 | } else { |
409 | 0 | if (buf != NULL) { |
410 | 0 | debugmsg(token, "%s [TRUNCATED]", buf); |
411 | 0 | } |
412 | 0 | } |
413 | |
|
414 | 0 | if (buf != NULL) { |
415 | 0 | free(buf); |
416 | 0 | } |
417 | 0 | } |
418 | | |
419 | | void |
420 | | debugmsg_oidrange(const char *token, const oid * theoid, size_t len, |
421 | | size_t var_subid, oid range_ubound) |
422 | 0 | { |
423 | 0 | u_char *buf = NULL; |
424 | 0 | size_t buf_len = 0, out_len = 0, i = 0; |
425 | 0 | int rc = 0; |
426 | |
|
427 | 0 | if (var_subid == 0) { |
428 | 0 | rc = sprint_realloc_objid(&buf, &buf_len, &out_len, 1, theoid, |
429 | 0 | len); |
430 | 0 | } else { |
431 | 0 | char tmpbuf[128]; |
432 | | /* XXX - ? check for 0 == var_subid -1 ? */ |
433 | 0 | rc = sprint_realloc_objid(&buf, &buf_len, &out_len, 1, theoid, |
434 | 0 | var_subid-1); /* Adjust for C's 0-based array indexing */ |
435 | 0 | if (rc) { |
436 | 0 | sprintf(tmpbuf, ".%" NETSNMP_PRIo "u--%" NETSNMP_PRIo "u", |
437 | 0 | theoid[var_subid - 1], range_ubound); |
438 | 0 | rc = snmp_cstrcat(&buf, &buf_len, &out_len, 1, tmpbuf); |
439 | 0 | if (rc) { |
440 | 0 | for (i = var_subid; i < len; i++) { |
441 | 0 | sprintf(tmpbuf, ".%" NETSNMP_PRIo "u", theoid[i]); |
442 | 0 | if (!snmp_cstrcat(&buf, &buf_len, &out_len, 1, tmpbuf)) { |
443 | 0 | break; |
444 | 0 | } |
445 | 0 | } |
446 | 0 | } |
447 | 0 | } |
448 | 0 | } |
449 | | |
450 | |
|
451 | 0 | if (buf != NULL) { |
452 | 0 | debugmsg(token, "%s%s", buf, rc ? "" : " [TRUNCATED]"); |
453 | 0 | free(buf); |
454 | 0 | } |
455 | 0 | } |
456 | | |
457 | | void |
458 | | debugmsg_hex(const char *token, const u_char * thedata, size_t len) |
459 | 0 | { |
460 | 0 | u_char *buf = NULL; |
461 | 0 | size_t buf_len = 0, out_len = 0; |
462 | |
|
463 | 0 | if (sprint_realloc_hexstring |
464 | 0 | (&buf, &buf_len, &out_len, 1, thedata, len)) { |
465 | 0 | if (buf != NULL) { |
466 | 0 | debugmsg(token, "%s", buf); |
467 | 0 | } |
468 | 0 | } else { |
469 | 0 | if (buf != NULL) { |
470 | 0 | debugmsg(token, "%s [TRUNCATED]", buf); |
471 | 0 | } |
472 | 0 | } |
473 | |
|
474 | 0 | if (buf != NULL) { |
475 | 0 | free(buf); |
476 | 0 | } |
477 | 0 | } |
478 | | |
479 | | void |
480 | | debugmsg_hextli(const char *token, const u_char * thedata, size_t len) |
481 | 0 | { |
482 | 0 | char buf[SPRINT_MAX_LEN], token2[SPRINT_MAX_LEN]; |
483 | 0 | u_char *b3 = NULL; |
484 | 0 | size_t b3_len = 0, o3_len = 0; |
485 | 0 | int incr; |
486 | 0 | sprintf(token2, "dumpx_%s", token); |
487 | | |
488 | | /* |
489 | | * XX tracing lines removed from this function DEBUGTRACE; |
490 | | */ |
491 | 0 | DEBUGIF(token2) { |
492 | 0 | for (incr = 16; len > 0; len -= incr, thedata += incr) { |
493 | 0 | if ((int) len < incr) { |
494 | 0 | incr = len; |
495 | 0 | } |
496 | | /* |
497 | | * XXnext two lines were DEBUGPRINTINDENT(token); |
498 | | */ |
499 | 0 | sprintf(buf, "dumpx%s", token); |
500 | 0 | debugmsg(buf, "%s: %*s", token2, debug_indent_get(), ""); |
501 | 0 | if (sprint_realloc_hexstring |
502 | 0 | (&b3, &b3_len, &o3_len, 1, thedata, incr)) { |
503 | 0 | if (b3 != NULL) { |
504 | 0 | debugmsg(token2, "%s", b3); |
505 | 0 | } |
506 | 0 | } else { |
507 | 0 | if (b3 != NULL) { |
508 | 0 | debugmsg(token2, "%s [TRUNCATED]", b3); |
509 | 0 | } |
510 | 0 | } |
511 | 0 | o3_len = 0; |
512 | 0 | } |
513 | 0 | } |
514 | 0 | if (b3 != NULL) { |
515 | 0 | free(b3); |
516 | 0 | } |
517 | 0 | } |
518 | | |
519 | | void |
520 | | debugmsgtoken(const char *token, const char *format, ...) |
521 | 0 | { |
522 | 0 | va_list debugargs; |
523 | |
|
524 | 0 | va_start(debugargs, format); |
525 | 0 | debugmsg(token, "%s: ", token); |
526 | 0 | va_end(debugargs); |
527 | 0 | } |
528 | | |
529 | | void |
530 | | debug_combo_nc(const char *token, const char *format, ...) |
531 | 0 | { |
532 | 0 | va_list debugargs; |
533 | |
|
534 | 0 | va_start(debugargs, format); |
535 | 0 | snmp_log(debug_log_level, "%s: ", token); |
536 | 0 | snmp_vlog(debug_log_level, format, debugargs); |
537 | 0 | va_end(debugargs); |
538 | 0 | } |
539 | | |
540 | | /* |
541 | | * for speed, these shouldn't be in default_storage space |
542 | | */ |
543 | | void |
544 | | snmp_set_do_debugging(int val) |
545 | 0 | { |
546 | 0 | dodebug = val; |
547 | 0 | } |
548 | | |
549 | | int |
550 | | snmp_get_do_debugging(void) |
551 | 3.41M | { |
552 | 3.41M | return dodebug; |
553 | 3.41M | } |
554 | | |
555 | | void |
556 | | snmp_set_do_debugoutputall(int val) |
557 | 0 | { |
558 | 0 | debug_print_everything = val; |
559 | 0 | } |
560 | | |
561 | | int |
562 | | snmp_get_do_debugoutputall(void) |
563 | 0 | { |
564 | 0 | return debug_print_everything; |
565 | 0 | } |
566 | | |
567 | | void |
568 | | snmp_debug_shutdown(void) |
569 | 0 | { |
570 | 0 | int i; |
571 | |
|
572 | 0 | for (i = 0; i < debug_num_tokens; i++) |
573 | 0 | SNMP_FREE(dbg_tokens[i].token_name); |
574 | 0 | } |
575 | | |
576 | | #else /* ! NETSNMP_NO_DEBUGGING */ |
577 | | |
578 | | int debug_indent_get(void) { return 0; } |
579 | | |
580 | | const char* debug_indent(void) { return ""; } |
581 | | |
582 | | void debug_indent_add(int amount) |
583 | | { } |
584 | | |
585 | | NETSNMP_IMPORT void |
586 | | debug_config_register_tokens(const char *configtoken, char *tokens); |
587 | | |
588 | | void |
589 | | debug_indent_reset(void) |
590 | | { } |
591 | | |
592 | | void |
593 | | debug_config_register_tokens(const char *configtoken, char *tokens) |
594 | | { } |
595 | | |
596 | | #ifndef NETSNMP_DISABLE_DYNAMIC_LOG_LEVEL |
597 | | static void |
598 | | debug_config_debug_log_level(const char *configtoken NETSNMP_ATTRIBUTE_UNUSED, |
599 | | char *tokens NETSNMP_ATTRIBUTE_UNUSED) |
600 | | { } |
601 | | |
602 | | NETSNMP_IMPORT void |
603 | | netsnmp_set_debug_log_level(int val NETSNMP_ATTRIBUTE_UNUSED) |
604 | | { } |
605 | | |
606 | | NETSNMP_IMPORT int |
607 | | netsnmp_get_debug_log_level(void) |
608 | | { |
609 | | return 0; |
610 | | } |
611 | | #endif /* NETSNMP_DISABLE_DYNAMIC_LOG_LEVEL */ |
612 | | |
613 | | NETSNMP_IMPORT void |
614 | | debug_config_turn_on_debugging(const char *configtoken, char *line); |
615 | | |
616 | | void |
617 | | debug_config_turn_on_debugging(const char *configtokenu, char *line) |
618 | | { } |
619 | | |
620 | | void |
621 | | debug_register_tokens(const char *tokens) |
622 | | { } |
623 | | |
624 | | void |
625 | | debug_print_registered_tokens(void) |
626 | | { } |
627 | | |
628 | | |
629 | | int |
630 | | debug_enable_token_logs (const char *token) |
631 | | { |
632 | | return SNMPERR_GENERR; |
633 | | } |
634 | | |
635 | | int |
636 | | debug_disable_token_logs (const char *token) |
637 | | { |
638 | | return SNMPERR_GENERR; |
639 | | } |
640 | | |
641 | | int |
642 | | debug_is_token_registered(const char *token) |
643 | | { |
644 | | return SNMPERR_GENERR; |
645 | | } |
646 | | |
647 | | void |
648 | | debugmsg(const char *token, const char *format, ...) |
649 | | { } |
650 | | |
651 | | void debugmsg_oid(const char *token, const oid * theoid, size_t len) |
652 | | { } |
653 | | |
654 | | void |
655 | | debugmsg_suboid(const char *token, const oid * theoid, size_t len) |
656 | | { } |
657 | | |
658 | | void |
659 | | debugmsg_var(const char *token, netsnmp_variable_list * var) |
660 | | { } |
661 | | |
662 | | void |
663 | | debugmsg_oidrange(const char *token, const oid * theoid, size_t len, |
664 | | size_t var_subid, oid range_ubound) |
665 | | { } |
666 | | |
667 | | void |
668 | | debugmsg_hex(const char *token, const u_char * thedata, size_t len) |
669 | | { } |
670 | | |
671 | | void |
672 | | debugmsg_hextli(const char *token, const u_char * thedata, size_t len) |
673 | | { } |
674 | | |
675 | | void |
676 | | debugmsgtoken(const char *token, const char *format, ...) |
677 | | { } |
678 | | |
679 | | void |
680 | | debug_combo_nc(const char *token, const char *format, ...) |
681 | | { } |
682 | | |
683 | | void |
684 | | snmp_set_do_debugging(int val) |
685 | | { } |
686 | | |
687 | | int |
688 | | snmp_get_do_debugging(void) |
689 | | { |
690 | | return 0; |
691 | | } |
692 | | |
693 | | void |
694 | | snmp_set_do_debugoutputall(int val) |
695 | | { } |
696 | | |
697 | | int |
698 | | snmp_get_do_debugoutputall(void) |
699 | | { |
700 | | return 0; |
701 | | } |
702 | | |
703 | | void |
704 | | snmp_debug_shutdown(void) |
705 | | { } |
706 | | |
707 | | #endif /* NETSNMP_NO_DEBUGGING */ |
708 | | |
709 | | #ifdef HAVE_WOLFSSL_WOLFCRYPT_LOGGING_H |
710 | | #include <wolfssl/options.h> |
711 | | #include <wolfssl/wolfcrypt/logging.h> |
712 | | |
713 | | static void snmp_log_wolfssl_msg(const int logLevel NETSNMP_ATTRIBUTE_UNUSED, |
714 | | const char* const msg) |
715 | | { |
716 | | DEBUGMSGTL(("snmp_openssl", msg, "\n")); |
717 | | } |
718 | | #endif |
719 | | |
720 | | void |
721 | | snmp_debug_init(void) |
722 | 0 | { |
723 | | #ifdef HAVE_WOLFSSL_WOLFCRYPT_LOGGING_H |
724 | | wolfSSL_Debugging_ON(); |
725 | | wolfSSL_SetLoggingCb(snmp_log_wolfssl_msg); |
726 | | #endif |
727 | |
|
728 | 0 | register_prenetsnmp_mib_handler("snmp", "doDebugging", |
729 | 0 | debug_config_turn_on_debugging, NULL, |
730 | 0 | "(1|0)"); |
731 | 0 | register_prenetsnmp_mib_handler("snmp", "debugTokens", |
732 | 0 | debug_config_register_tokens, NULL, |
733 | 0 | "token[,token...]"); |
734 | 0 | #ifndef NETSNMP_DISABLE_DYNAMIC_LOG_LEVEL |
735 | 0 | register_prenetsnmp_mib_handler("snmp", "debugLogLevel", |
736 | | debug_config_debug_log_level, NULL, |
737 | 0 | "(emerg|alert|crit|err|warning|notice|info|debug)"); |
738 | 0 | #endif /* NETSNMP_DISABLE_DYNAMIC_LOG_LEVEL */ |
739 | 0 | } |
740 | | |