1
/** allows overriding of a given oid with a new type and value */
3
/* Portions of this file are subject to the following copyright(s). See
4
* the Net-SNMP's COPYING file for more details and other copyrights
8
* Portions of this file are copyrighted by:
9
* Copyright � 2003 Sun Microsystems, Inc. All rights reserved.
10
* Use is subject to license terms specified in the COPYING file
11
* distributed with the Net-SNMP package.
14
#include <net-snmp/net-snmp-config.h>
15
#include <net-snmp/net-snmp-includes.h>
16
#include <net-snmp/agent/net-snmp-agent-includes.h>
18
#include "util_funcs.h"
20
typedef struct override_data_s {
26
/** @todo: (optionally) save values persistently when configured for
29
override_handler(netsnmp_mib_handler *handler,
30
netsnmp_handler_registration *reginfo,
31
netsnmp_agent_request_info *reqinfo,
32
netsnmp_request_info *requests)
35
override_data *data = handler->myvoid;
37
netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_GENERR);
38
return SNMP_ERR_NOERROR;
41
switch (reqinfo->mode) {
43
DEBUGMSGTL(("override", "overriding oid "));
44
DEBUGMSGOID(("override", requests->requestvb->name,
45
requests->requestvb->name_length));
46
DEBUGMSG(("override", "\n"));
47
snmp_set_var_typed_value(requests->requestvb, (u_char)data->type,
48
(u_char *) data->value, data->value_len);
52
snmp_log(LOG_ERR, "unsupported mode in override handler\n");
53
netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_GENERR);
54
return SNMP_ERR_GENERR;
56
return SNMP_ERR_NOERROR;
59
#define MALLOC_OR_DIE(x) \
60
thedata->value = malloc(x); \
61
thedata->value_len = x; \
62
if (!thedata->value) { \
64
config_perror("memory allocation failure"); \
69
netsnmp_parse_override(const char *token, char *line)
72
char buf[SNMP_MAXBUF];
74
oid oidbuf[MAX_OID_LEN];
75
size_t oidbuf_len = sizeof(oidbuf);
77
override_data *thedata;
78
netsnmp_handler_registration *the_reg;
80
cp = copy_nword(line, buf, sizeof(buf) - 1);
81
if (strcmp(buf, "-rw") == 0) {
83
cp = copy_nword(cp, buf, sizeof(buf) - 1);
87
config_perror("no oid specified");
91
if (!snmp_parse_oid(buf, oidbuf, &oidbuf_len)) {
92
config_perror("illegal oid");
95
cp = copy_nword(cp, buf, sizeof(buf) - 1);
97
if (!cp && strcmp(buf, "null") != 0) {
98
config_perror("no variable value specified");
102
type = se_find_value_in_slist("asntypes", buf);
104
config_perror("unknown type specified");
109
copy_nword(cp, buf, sizeof(buf) - 1);
113
thedata = SNMP_MALLOC_TYPEDEF(override_data);
114
thedata->type = type;
116
config_perror("memory allocation failure");
122
MALLOC_OR_DIE(sizeof(long));
123
*((long *) thedata->value) = strtol(buf, NULL, 0);
128
MALLOC_OR_DIE(sizeof(u_long));
129
*((u_long *) thedata->value) = strtoul(buf, NULL, 0);
134
if (buf[0] == '0' && buf[1] == 'x') {
139
hex_to_binary2(buf + 2, strlen(buf) - 2,
140
(char **) &thedata->value);
142
thedata->value = strdup(buf);
143
thedata->value_len = strlen(buf);
148
read_config_read_objid(buf, (oid **) & thedata->value,
149
&thedata->value_len);
153
thedata->value_len = 0;
157
config_perror("illegal/unsupported type specified");
161
if (!thedata->value && thedata->type != ASN_NULL) {
162
config_perror("memory allocation failure");
167
the_reg = SNMP_MALLOC_TYPEDEF(netsnmp_handler_registration);
169
config_perror("memory allocation failure");
174
the_reg->priority = 255;
175
the_reg->modes = (readwrite) ? HANDLER_CAN_RWRITE : HANDLER_CAN_RONLY;
177
netsnmp_create_handler("override", override_handler);
178
memdup((u_char **) & the_reg->rootoid, (const u_char *) oidbuf,
179
oidbuf_len * sizeof(oid));
180
the_reg->rootoid_len = oidbuf_len;
181
if (!the_reg->rootoid) {
182
config_perror("memory allocation failure");
186
the_reg->handler->myvoid = thedata;
188
if (netsnmp_register_instance(the_reg)) {
189
config_perror("oid registration failed within the agent");
190
SNMP_FREE(thedata->value);
201
snmpd_register_config_handler("override", netsnmp_parse_override, NULL, /* XXX: free func */
202
"[-rw] mibnode type value");