net-snmp
5.4.1
|
00001 /* Portions of this file are subject to the following copyright(s). See 00002 * the Net-SNMP's COPYING file for more details and other copyrights 00003 * that may apply: 00004 */ 00005 /* 00006 * Portions of this file are copyrighted by: 00007 * Copyright © 2003 Sun Microsystems, Inc. All rights reserved. 00008 * Use is subject to license terms specified in the COPYING file 00009 * distributed with the Net-SNMP package. 00010 */ 00011 #include <net-snmp/net-snmp-config.h> 00012 00013 #include <stdlib.h> 00014 #if HAVE_STRING_H 00015 #include <string.h> 00016 #else 00017 #include <strings.h> 00018 #endif 00019 00020 #include <net-snmp/net-snmp-includes.h> 00021 #include <net-snmp/agent/net-snmp-agent-includes.h> 00022 00023 #include <net-snmp/agent/scalar.h> 00024 #include <net-snmp/agent/instance.h> 00025 #include <net-snmp/agent/serialize.h> 00026 #include <net-snmp/agent/read_only.h> 00027 00045 netsnmp_mib_handler * 00046 netsnmp_get_scalar_handler(void) 00047 { 00048 return netsnmp_create_handler("scalar", 00049 netsnmp_scalar_helper_handler); 00050 } 00051 00073 int 00074 netsnmp_register_scalar(netsnmp_handler_registration *reginfo) 00075 { 00076 /* 00077 * Extend the registered OID with space for the instance subid 00078 * (but don't extend the length just yet!) 00079 */ 00080 reginfo->rootoid = realloc(reginfo->rootoid, 00081 (reginfo->rootoid_len+1) * sizeof(oid) ); 00082 reginfo->rootoid[ reginfo->rootoid_len ] = 0; 00083 00084 netsnmp_inject_handler(reginfo, netsnmp_get_instance_handler()); 00085 netsnmp_inject_handler(reginfo, netsnmp_get_scalar_handler()); 00086 return netsnmp_register_serialize(reginfo); 00087 } 00088 00089 00108 int 00109 netsnmp_register_read_only_scalar(netsnmp_handler_registration *reginfo) 00110 { 00111 /* 00112 * Extend the registered OID with space for the instance subid 00113 * (but don't extend the length just yet!) 00114 */ 00115 reginfo->rootoid = realloc(reginfo->rootoid, 00116 (reginfo->rootoid_len+1) * sizeof(oid) ); 00117 reginfo->rootoid[ reginfo->rootoid_len ] = 0; 00118 00119 netsnmp_inject_handler(reginfo, netsnmp_get_instance_handler()); 00120 netsnmp_inject_handler(reginfo, netsnmp_get_scalar_handler()); 00121 netsnmp_inject_handler(reginfo, netsnmp_get_read_only_handler()); 00122 return netsnmp_register_serialize(reginfo); 00123 } 00124 00125 00126 00127 int 00128 netsnmp_scalar_helper_handler(netsnmp_mib_handler *handler, 00129 netsnmp_handler_registration *reginfo, 00130 netsnmp_agent_request_info *reqinfo, 00131 netsnmp_request_info *requests) 00132 { 00133 00134 netsnmp_variable_list *var = requests->requestvb; 00135 00136 int ret, cmp; 00137 int namelen; 00138 00139 DEBUGMSGTL(("helper:scalar", "Got request:\n")); 00140 namelen = SNMP_MIN(requests->requestvb->name_length, 00141 reginfo->rootoid_len); 00142 cmp = snmp_oid_compare(requests->requestvb->name, namelen, 00143 reginfo->rootoid, reginfo->rootoid_len); 00144 00145 DEBUGMSGTL(("helper:scalar", " oid:", cmp)); 00146 DEBUGMSGOID(("helper:scalar", var->name, var->name_length)); 00147 DEBUGMSG(("helper:scalar", "\n")); 00148 00149 switch (reqinfo->mode) { 00150 case MODE_GET: 00151 if (cmp != 0) { 00152 netsnmp_set_request_error(reqinfo, requests, 00153 SNMP_NOSUCHOBJECT); 00154 return SNMP_ERR_NOERROR; 00155 } else { 00156 reginfo->rootoid[reginfo->rootoid_len++] = 0; 00157 ret = netsnmp_call_next_handler(handler, reginfo, reqinfo, 00158 requests); 00159 reginfo->rootoid_len--; 00160 return ret; 00161 } 00162 break; 00163 00164 case MODE_SET_RESERVE1: 00165 case MODE_SET_RESERVE2: 00166 case MODE_SET_ACTION: 00167 case MODE_SET_COMMIT: 00168 case MODE_SET_UNDO: 00169 case MODE_SET_FREE: 00170 if (cmp != 0) { 00171 netsnmp_set_request_error(reqinfo, requests, 00172 SNMP_ERR_NOCREATION); 00173 return SNMP_ERR_NOERROR; 00174 } else { 00175 reginfo->rootoid[reginfo->rootoid_len++] = 0; 00176 ret = netsnmp_call_next_handler(handler, reginfo, reqinfo, 00177 requests); 00178 reginfo->rootoid_len--; 00179 return ret; 00180 } 00181 break; 00182 00183 case MODE_GETNEXT: 00184 reginfo->rootoid[reginfo->rootoid_len++] = 0; 00185 ret = netsnmp_call_next_handler(handler, reginfo, reqinfo, requests); 00186 reginfo->rootoid_len--; 00187 return ret; 00188 } 00189 /* 00190 * got here only if illegal mode found 00191 */ 00192 return SNMP_ERR_GENERR; 00193 } 00194