/** * This function injects a "read only" handler into the handler chain * prior to serializing/registering the handler. * * The only purpose of this "read only" handler is to return an * appropriate error for any requests passed to it in a SET mode. * Inserting it into your handler chain will ensure you're never * asked to perform a SET request so you can ignore those error * conditions. * * @param reginfo a handler registration structure which could get created * using netsnmp_create_handler_registration. Used to register * a read only instance helper handler. * * @return * MIB_REGISTERED_OK is returned if the registration was a success. * Failures are MIB_REGISTRATION_FAILED and MIB_DUPLICATE_REGISTRATION. */ int netsnmp_register_read_only_instance(netsnmp_handler_registration *reginfo) { netsnmp_inject_handler(reginfo, netsnmp_get_instance_handler()); netsnmp_inject_handler(reginfo, netsnmp_get_read_only_handler()); return netsnmp_register_serialize(reginfo); }
/** registers a handler as a read-only data table * If table_info != NULL, it registers it as a normal table too. */ int netsnmp_register_read_only_table_data(netsnmp_handler_registration *reginfo, netsnmp_table_data *table, netsnmp_table_registration_info *table_info) { netsnmp_inject_handler(reginfo, netsnmp_get_read_only_handler()); return netsnmp_register_table_data(reginfo, table, table_info); }
int netsnmp_register_read_only_scalar(netsnmp_handler_registration *reginfo) { /* * Extend the registered OID with space for the instance subid * (but don't extend the length just yet!) */ reginfo->rootoid = realloc(reginfo->rootoid, (reginfo->rootoid_len+1) * sizeof(oid) ); reginfo->rootoid[ reginfo->rootoid_len ] = 0; netsnmp_inject_handler(reginfo, netsnmp_get_instance_handler()); netsnmp_inject_handler(reginfo, netsnmp_get_scalar_handler()); netsnmp_inject_handler(reginfo, netsnmp_get_read_only_handler()); return netsnmp_register_serialize(reginfo); }
/** * This function injects a "read only" handler into the handler chain * prior to serializing/registering the handler. * * The only purpose of this "read only" handler is to return an * appropriate error for any requests passed to it in a SET mode. * Inserting it into your handler chain will ensure you're never * asked to perform a SET request so you can ignore those error * conditions. * * @param reginfo a handler registration structure which could get created * using netsnmp_create_handler_registration. Used to register * a read only instance helper handler. * * @return * MIB_REGISTERED_OK is returned if the registration was a success. * Failures are MIB_REGISTRATION_FAILED and MIB_DUPLICATE_REGISTRATION. */ int netsnmp_register_read_only_instance(netsnmp_handler_registration *reginfo) { netsnmp_mib_handler *h1, *h2; if (!reginfo) return MIB_REGISTRATION_FAILED; h1 = netsnmp_get_instance_handler(); h2 = netsnmp_get_read_only_handler(); if (h1 && h2 && netsnmp_inject_handler(reginfo, h1) == SNMPERR_SUCCESS) { h1 = NULL; if (netsnmp_inject_handler(reginfo, h2) == SNMPERR_SUCCESS) return netsnmp_register_serialize(reginfo); } snmp_log(LOG_ERR, "failed to register read only instance\n"); netsnmp_handler_free(h1); netsnmp_handler_free(h2); netsnmp_handler_registration_free(reginfo); return MIB_REGISTRATION_FAILED; }
/** initializes the read_only helper which then registers a read_only * handler as a run-time injectable handler for configuration file * use. */ void netsnmp_init_read_only_helper(void) { netsnmp_register_handler_by_name("read_only", netsnmp_get_read_only_handler()); }