| 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 |
{ |
| 27 |
return netsnmp_register_null_context(loc, loc_len, NULL); |
| 28 |
} |
| 29 |
|
| 30 |
int |
| 31 |
netsnmp_register_null_context(oid * loc, size_t loc_len, |
| 32 |
const char *contextName) |
| 33 |
{ |
| 34 |
netsnmp_handler_registration *reginfo; |
| 35 |
reginfo = SNMP_MALLOC_TYPEDEF(netsnmp_handler_registration); |
| 36 |
if (reginfo != NULL) { |
| 37 |
reginfo->handlerName = strdup(""); |
| 38 |
reginfo->rootoid = loc; |
| 39 |
reginfo->rootoid_len = loc_len; |
| 40 |
reginfo->handler = |
| 41 |
netsnmp_create_handler("null", netsnmp_null_handler); |
| 42 |
if (contextName) |
| 43 |
reginfo->contextName = strdup(contextName); |
| 44 |
reginfo->modes = HANDLER_CAN_DEFAULT | HANDLER_CAN_GETBULK; |
| 45 |
|
| 46 |
if (!reginfo->handlerName || !reginfo->handler || |
| 47 |
(contextName && !reginfo->contextName)) { |
| 48 |
snmp_log(LOG_ERR,"null context allocation failure(s)\n"); |
| 49 |
netsnmp_handler_registration_free(reginfo); |
| 50 |
return MIB_REGISTRATION_FAILED; |
| 51 |
} |
| 52 |
} else { |
| 53 |
snmp_log(LOG_ERR,"null context allocation failure\n"); |
| 54 |
return MIB_REGISTRATION_FAILED; |
| 55 |
} |
| 56 |
return netsnmp_register_handler(reginfo); |
| 57 |
} |
| 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 |
{ |
| 65 |
DEBUGMSGTL(("helper:null", "Got request\n")); |
| 66 |
|
| 67 |
DEBUGMSGTL(("helper:null", " oid:")); |
| 68 |
DEBUGMSGOID(("helper:null", requests->requestvb->name, |
| 69 |
requests->requestvb->name_length)); |
| 70 |
DEBUGMSG(("helper:null", "\n")); |
| 71 |
|
| 72 |
switch (reqinfo->mode) { |
| 73 |
case MODE_GETNEXT: |
| 74 |
case MODE_GETBULK: |
| 75 |
return SNMP_ERR_NOERROR; |
| 76 |
|
| 77 |
case MODE_GET: |
| 78 |
netsnmp_request_set_error_all(requests, SNMP_NOSUCHOBJECT); |
| 79 |
return SNMP_ERR_NOERROR; |
| 80 |
|
| 81 |
default: |
| 82 |
netsnmp_request_set_error_all(requests, SNMP_ERR_NOSUCHNAME); |
| 83 |
return SNMP_ERR_NOERROR; |
| 84 |
} |
| 85 |
} |