| 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 |
#include <net-snmp/net-snmp-features.h> |
| 14 |
#include <net-snmp/net-snmp-includes.h> |
| 15 |
#include <net-snmp/agent/net-snmp-agent-includes.h> |
| 16 |
#include <net-snmp/agent/sysORTable.h> |
| 17 |
|
| 18 |
#include <net-snmp/agent/snmp_get_statistic.h> |
| 19 |
|
| 20 |
#include "snmp_mib.h" |
| 21 |
#include "system_mib.h" |
| 22 |
#include "updates.h" |
| 23 |
#include "agent_global_vars.h" |
| 24 |
|
| 25 |
netsnmp_feature_require(helper_statistics); |
| 26 |
#ifndef NETSNMP_NO_WRITE_SUPPORT |
| 27 |
netsnmp_feature_require(check_vb_truthvalue); |
| 28 |
#endif /* NETSNMP_NO_WRITE_SUPPORT */ |
| 29 |
|
| 30 |
#define SNMP_OID 1, 3, 6, 1, 2, 1, 11 |
| 31 |
|
| 32 |
static const oid snmp_oid[] = { SNMP_OID }; |
| 33 |
|
| 34 |
static int |
| 35 |
snmp_enableauthentraps_store(int a, int b, void *c, void *d) |
| 36 |
{ |
| 37 |
char line[SNMP_MAXBUF_SMALL]; |
| 38 |
|
| 39 |
if (snmp_enableauthentrapsset > 0) { |
| 40 |
snprintf(line, SNMP_MAXBUF_SMALL, "pauthtrapenable %ld", |
| 41 |
snmp_enableauthentraps); |
| 42 |
snmpd_store_config(line); |
| 43 |
} |
| 44 |
return 0; |
| 45 |
} |
| 46 |
|
| 47 |
static int |
| 48 |
handle_truthvalue(netsnmp_mib_handler *handler, |
| 49 |
netsnmp_handler_registration *reginfo, |
| 50 |
netsnmp_agent_request_info *reqinfo, |
| 51 |
netsnmp_request_info *requests) |
| 52 |
{ |
| 53 |
#ifndef NETSNMP_NO_WRITE_SUPPORT |
| 54 |
if (reqinfo->mode == MODE_SET_RESERVE1) { |
| 55 |
int res = netsnmp_check_vb_truthvalue(requests->requestvb); |
| 56 |
if (res != SNMP_ERR_NOERROR) |
| 57 |
netsnmp_request_set_error(requests, res); |
| 58 |
} |
| 59 |
#endif /* !NETSNMP_NO_WRITE_SUPPORT */ |
| 60 |
return SNMP_ERR_NOERROR; |
| 61 |
} |
| 62 |
|
| 63 |
static netsnmp_mib_handler* |
| 64 |
netsnmp_get_truthvalue(void) |
| 65 |
{ |
| 66 |
netsnmp_mib_handler* hnd = |
| 67 |
netsnmp_create_handler("truthvalue", handle_truthvalue); |
| 68 |
if (hnd) |
| 69 |
hnd->flags |= MIB_HANDLER_AUTO_NEXT; |
| 70 |
return hnd; |
| 71 |
} |
| 72 |
|
| 73 |
static int |
| 74 |
handle_snmp(netsnmp_mib_handler *handler, |
| 75 |
netsnmp_handler_registration *reginfo, |
| 76 |
netsnmp_agent_request_info *reqinfo, |
| 77 |
netsnmp_request_info *requests) |
| 78 |
{ |
| 79 |
switch(requests->requestvb->name[OID_LENGTH(snmp_oid)]) { |
| 80 |
case 7: |
| 81 |
case 23: |
| 82 |
case 30: |
| 83 |
netsnmp_set_request_error(reqinfo, requests, SNMP_NOSUCHOBJECT); |
| 84 |
break; |
| 85 |
default: |
| 86 |
break; |
| 87 |
} |
| 88 |
return SNMP_ERR_NOERROR; |
| 89 |
} |
| 90 |
|
| 91 |
/** Initializes the snmp module */ |
| 92 |
void |
| 93 |
init_snmp_mib(void) |
| 94 |
{ |
| 95 |
DEBUGMSGTL(("snmp", "Initializing\n")); |
| 96 |
|
| 97 |
NETSNMP_REGISTER_STATISTIC_HANDLER( |
| 98 |
netsnmp_create_handler_registration( |
| 99 |
"mibII/snmp", handle_snmp, snmp_oid, OID_LENGTH(snmp_oid), |
| 100 |
HANDLER_CAN_RONLY), |
| 101 |
1, SNMP); |
| 102 |
{ |
| 103 |
oid snmpEnableAuthenTraps_oid[] = { SNMP_OID, 30, 0 }; |
| 104 |
static netsnmp_watcher_info enableauthen_info; |
| 105 |
netsnmp_mib_handler *handler; |
| 106 |
netsnmp_handler_registration *reg = |
| 107 |
netsnmp_create_update_handler_registration( |
| 108 |
"mibII/snmpEnableAuthenTraps", |
| 109 |
snmpEnableAuthenTraps_oid, |
| 110 |
OID_LENGTH(snmpEnableAuthenTraps_oid), |
| 111 |
#ifndef NETSNMP_NO_WRITE_SUPPORT |
| 112 |
HANDLER_CAN_RWRITE, |
| 113 |
#else |
| 114 |
HANDLER_CAN_RONLY, |
| 115 |
#endif /* !NETSNMP_NO_WRITE_SUPPORT */ |
| 116 |
&snmp_enableauthentrapsset); |
| 117 |
handler = netsnmp_get_truthvalue(); |
| 118 |
if (!handler || |
| 119 |
(netsnmp_inject_handler(reg, handler) != SNMPERR_SUCCESS)) { |
| 120 |
snmp_log(LOG_ERR, |
| 121 |
"could not create mibII/snmpEnableAuthenTraps handler\n"); |
| 122 |
if (handler) |
| 123 |
netsnmp_handler_free(handler); |
| 124 |
netsnmp_handler_registration_free(reg); |
| 125 |
return; |
| 126 |
} |
| 127 |
netsnmp_register_watched_instance( |
| 128 |
reg, |
| 129 |
netsnmp_init_watcher_info( |
| 130 |
&enableauthen_info, |
| 131 |
&snmp_enableauthentraps, sizeof(snmp_enableauthentraps), |
| 132 |
ASN_INTEGER, WATCHER_FIXED_SIZE)); |
| 133 |
} |
| 134 |
|
| 135 |
#ifdef USING_MIBII_SYSTEM_MIB_MODULE |
| 136 |
if (++system_module_count == 3) |
| 137 |
REGISTER_SYSOR_TABLE(system_module_oid, system_module_oid_len, |
| 138 |
"The MIB module for SNMPv2 entities"); |
| 139 |
#endif |
| 140 |
snmp_register_callback(SNMP_CALLBACK_LIBRARY, SNMP_CALLBACK_STORE_DATA, |
| 141 |
snmp_enableauthentraps_store, NULL); |
| 142 |
} |