/src/net-snmp/agent/helpers/null.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 | | #include <net-snmp/net-snmp-config.h> |
12 | | |
13 | | #include <net-snmp/net-snmp-includes.h> |
14 | | #include <net-snmp/agent/net-snmp-agent-includes.h> |
15 | | |
16 | | #include <net-snmp/agent/null.h> |
17 | | |
18 | | #ifdef HAVE_STRING_H |
19 | | #include <string.h> |
20 | | #else |
21 | | #include <strings.h> |
22 | | #endif |
23 | | |
24 | | int |
25 | | netsnmp_register_null(oid * loc, size_t loc_len) |
26 | 10.0k | { |
27 | 10.0k | return netsnmp_register_null_context(loc, loc_len, NULL); |
28 | 10.0k | } |
29 | | |
30 | | int |
31 | | netsnmp_register_null_context(oid * loc, size_t loc_len, |
32 | | const char *contextName) |
33 | 20.1k | { |
34 | 20.1k | netsnmp_handler_registration *reginfo; |
35 | 20.1k | reginfo = SNMP_MALLOC_TYPEDEF(netsnmp_handler_registration); |
36 | 20.1k | if (reginfo != NULL) { |
37 | 20.1k | reginfo->handlerName = strdup(""); |
38 | 20.1k | reginfo->rootoid = loc; |
39 | 20.1k | reginfo->rootoid_len = loc_len; |
40 | 20.1k | reginfo->handler = |
41 | 20.1k | netsnmp_create_handler("null", netsnmp_null_handler); |
42 | 20.1k | if (contextName) |
43 | 0 | reginfo->contextName = strdup(contextName); |
44 | 20.1k | reginfo->modes = HANDLER_CAN_DEFAULT | HANDLER_CAN_GETBULK; |
45 | | |
46 | 20.1k | if (!reginfo->handlerName || !reginfo->handler || |
47 | 20.1k | (contextName && !reginfo->contextName)) { |
48 | 0 | snmp_log(LOG_ERR,"null context allocation failure(s)\n"); |
49 | 0 | netsnmp_handler_registration_free(reginfo); |
50 | 0 | return MIB_REGISTRATION_FAILED; |
51 | 0 | } |
52 | 20.1k | } else { |
53 | 0 | snmp_log(LOG_ERR,"null context allocation failure\n"); |
54 | 0 | return MIB_REGISTRATION_FAILED; |
55 | 0 | } |
56 | 20.1k | return netsnmp_register_handler(reginfo); |
57 | 20.1k | } |
58 | | |
59 | | int |
60 | | netsnmp_null_handler(netsnmp_mib_handler *handler, |
61 | | netsnmp_handler_registration *reginfo, |
62 | | netsnmp_agent_request_info *reqinfo, |
63 | | netsnmp_request_info *requests) |
64 | 187 | { |
65 | 187 | DEBUGMSGTL(("helper:null", "Got request\n")); |
66 | | |
67 | 187 | DEBUGMSGTL(("helper:null", " oid:")); |
68 | 187 | DEBUGMSGOID(("helper:null", requests->requestvb->name, |
69 | 187 | requests->requestvb->name_length)); |
70 | 187 | DEBUGMSG(("helper:null", "\n")); |
71 | | |
72 | 187 | switch (reqinfo->mode) { |
73 | 0 | case MODE_GETNEXT: |
74 | 0 | case MODE_GETBULK: |
75 | 0 | return SNMP_ERR_NOERROR; |
76 | | |
77 | 187 | case MODE_GET: |
78 | 187 | netsnmp_request_set_error_all(requests, SNMP_NOSUCHOBJECT); |
79 | 187 | return SNMP_ERR_NOERROR; |
80 | | |
81 | 0 | default: |
82 | 0 | netsnmp_request_set_error_all(requests, SNMP_ERR_NOSUCHNAME); |
83 | 0 | return SNMP_ERR_NOERROR; |
84 | 187 | } |
85 | 187 | } |