/** * @internal * initialize the container with functions or wrappers */ void _ipv4InterfaceTable_container_init(ipv4InterfaceTable_interface_ctx * if_ctx) { DEBUGMSGTL(("internal:ipv4InterfaceTable:_ipv4InterfaceTable_container_init", "called\n")); /* * container init */ ipv4InterfaceTable_container_init(&if_ctx->container); if (NULL == if_ctx->container) if_ctx->container = netsnmp_container_find("ipv4InterfaceTable:table_container"); if (NULL == if_ctx->container) { snmp_log(LOG_ERR, "error creating container in " "ipv4InterfaceTable_container_init\n"); return; } if_ctx->container->container_name = strdup("ipv4InterfaceTable"); } /* _ipv4InterfaceTable_container_init */
/** * check entry for update */ static void _check_entry_for_updates (ipDefaultRouterTable_rowreq_ctx * rowreq_ctx, void **magic) { netsnmp_container *defaultrouter_container = magic[0]; netsnmp_container *to_delete = (netsnmp_container *) magic[1]; /* * check for matching entry using secondary index. */ netsnmp_defaultrouter_entry *defaultrouter_entry = CONTAINER_FIND (defaultrouter_container, rowreq_ctx->data); if (NULL == defaultrouter_entry) { DEBUGMSGTL (("ipDefaultRouterTable:access", "removing missing entry\n")); if (NULL == to_delete) { magic[1] = to_delete = netsnmp_container_find ("lifo"); if (NULL == to_delete) snmp_log (LOG_ERR, "couldn't create delete container\n"); } if (NULL != to_delete) CONTAINER_INSERT (to_delete, rowreq_ctx); } else { DEBUGMSGTL (("ipDefaultRouterTable:access", "updating existing entry\n")); /* * Check for changes & update */ netsnmp_access_defaultrouter_entry_update (rowreq_ctx->data, defaultrouter_entry); /* * remove entry from ifcontainer */ CONTAINER_REMOVE (defaultrouter_container, defaultrouter_entry); netsnmp_access_defaultrouter_entry_free (defaultrouter_entry); } }
int process_set_requests (netsnmp_agent_request_info * agtreq_info, netsnmp_request_info * requests, table_container_data * tad, char *handler_name) { set_context context; netsnmp_container *request_group; /* * create and save structure for set info */ request_group = (netsnmp_container *) netsnmp_agent_get_list_data (agtreq_info, handler_name); if (request_group == NULL) { netsnmp_data_list *tmp; request_group = netsnmp_container_find ("request_group:" "table_container"); request_group->compare = netsnmp_compare_netsnmp_index; request_group->ncompare = netsnmp_ncompare_netsnmp_index; DEBUGMSGTL (("table_array", "Grouping requests by oid\n")); tmp = netsnmp_create_data_list (handler_name, request_group, release_netsnmp_request_groups); netsnmp_agent_add_list_data (agtreq_info, tmp); /* * group requests. */ group_requests (agtreq_info, requests, request_group, tad); } /* * process each group one at a time */ context.agtreq_info = agtreq_info; context.tad = tad; context.status = SNMP_ERR_NOERROR; CONTAINER_FOR_EACH (request_group, (netsnmp_container_obj_func *) process_set_group, &context); return context.status; }
/** * @internal * initialize the container with functions or wrappers */ void _ipv6ScopeZoneIndexTable_container_init (ipv6ScopeZoneIndexTable_interface_ctx * if_ctx) { DEBUGMSGTL(("internal:ipv6ScopeZoneIndexTable:_ipv6ScopeZoneIndexTable_container_init", "called\n")); /* * container init */ if_ctx->cache = netsnmp_cache_create(30, /* timeout in seconds */ _cache_load, _cache_free, ipv6ScopeZoneIndexTable_oid, ipv6ScopeZoneIndexTable_oid_size); if (NULL == if_ctx->cache) { snmp_log(LOG_ERR, "error creating cache for ipScopeZoneIndexTable\n"); return; } if_ctx->cache->flags = NETSNMP_CACHE_DONT_INVALIDATE_ON_SET; ipv6ScopeZoneIndexTable_container_init(&if_ctx->container, if_ctx->cache); if (NULL == if_ctx->container) { if_ctx->container = netsnmp_container_find ("ipv6ScopeZoneIndexTable:table_container"); if (if_ctx->container) if_ctx->container->container_name = strdup("ipv6ScopeZoneIndexTable"); } if (NULL == if_ctx->container) { snmp_log(LOG_ERR, "error creating container in " "ipv6ScopeZoneIndexTable_container_init\n"); return; } if (NULL != if_ctx->cache) if_ctx->cache->magic = (void *) if_ctx->container; } /* _ipv6ScopeZoneIndexTable_container_init */
/** * check entry for update */ static void _check_entry_for_updates(ipAddressTable_rowreq_ctx * rowreq_ctx, void **magic) { netsnmp_container *ipaddress_container = (netsnmp_container*)magic[0]; netsnmp_container *to_delete = (netsnmp_container*)magic[1]; /* * check for matching entry using secondary index. */ netsnmp_ipaddress_entry *ipaddress_entry = (netsnmp_ipaddress_entry*) CONTAINER_FIND(ipaddress_container, rowreq_ctx->data); if (NULL == ipaddress_entry) { DEBUGMSGTL(("ipAddressTable:access", "removing missing entry\n")); if (NULL == to_delete) { magic[1] = to_delete = netsnmp_container_find("lifo"); if (NULL == to_delete) snmp_log(LOG_ERR, "couldn't create delete container\n"); } if (NULL != to_delete) CONTAINER_INSERT(to_delete, rowreq_ctx); } else { DEBUGMSGTL(("ipAddressTable:access", "updating existing entry\n")); /* * Check for changes & update */ if (netsnmp_access_ipaddress_entry_update(rowreq_ctx->data, ipaddress_entry) > 0) rowreq_ctx->ipAddressLastChanged = netsnmp_get_agent_uptime(); /* * remove entry from ifcontainer */ CONTAINER_REMOVE(ipaddress_container, ipaddress_entry); netsnmp_access_ipaddress_entry_free(ipaddress_entry); } }
/** * container initialization * * @param container_ptr_ptr A pointer to a container pointer. If you * create a custom container, use this parameter to return it * to the MFD helper. If set to NULL, the MFD helper will * allocate a container for you. * @param cache A pointer to a cache structure. You can set the timeout * and other cache flags using this pointer. * * This function is called at startup to allow you to customize certain * aspects of the access method. For the most part, it is for advanced * users. The default code should suffice for most cases. If no custom * container is allocated, the MFD code will create one for your. * * This is also the place to set up cache behavior. The default, to * simply set the cache timeout, will work well with the default * container. If you are using a custom container, you may want to * look at the cache helper documentation to see if there are any * flags you want to set. * * @remark * This would also be a good place to do any initialization needed * for you data source. For example, opening a connection to another * process that will supply the data, opening a database, etc. */ void wmanIfBsRegisteredSsTable_container_init(netsnmp_container ** container_ptr_ptr, netsnmp_cache * cache) { DEBUGMSGTL(("verbose:wmanIfBsRegisteredSsTable:wmanIfBsRegisteredSsTable_container_init", "called\n")); if (NULL == container_ptr_ptr) { snmp_log(LOG_ERR, "bad container param to wmanIfBsRegisteredSsTable_container_init\n"); return; } /* * For advanced users, you can use a custom container. If you * do not create one, one will be created for you. */ //*container_ptr_ptr = NULL; *container_ptr_ptr = netsnmp_container_find("wmanIfBsRegisteredSsTable:table_container"); wmanIfBsRegisteredSsTable_container_load(*container_ptr_ptr); if (NULL == cache) { snmp_log(LOG_ERR, "bad cache param to wmanIfBsRegisteredSsTable_container_init\n"); return; } /* * TODO:345:A: Set up wmanIfBsRegisteredSsTable cache properties. * * Also for advanced users, you can set parameters for the * cache. Do not change the magic pointer, as it is used * by the MFD helper. To completely disable caching, set * cache->enabled to 0. */ cache->timeout = WMANIFBSREGISTEREDSSTABLE_CACHE_TIMEOUT; /* seconds */ } /* wmanIfBsRegisteredSsTable_container_init */
/** * @retval NULL error * @retval !NULL pointer to container */ netsnmp_container* netsnmp_access_route_container_load(netsnmp_container* container, u_int load_flags) { int rc; DEBUGMSGTL(("access:route:container", "load\n")); if (NULL == container) container = netsnmp_container_find("access:_route:table_container"); if (NULL == container) { snmp_log(LOG_ERR, "no container specified/found for access_route\n"); return NULL; } rc = netsnmp_access_route_container_arch_load(container, load_flags); if (0 != rc) { netsnmp_access_route_container_free(container, NETSNMP_ACCESS_ROUTE_FREE_NOFLAGS); container = NULL; } return container; }
void init_hw_sensors( void ) { if ( _sensor_container ) return; /* Already initialised */ DEBUGMSGTL(("sensors", "Initialise Hardware Sensors module\n")); /* * Define a container to hold the basic list of sensors * The four LM-SENSOR-MIB containers will be created in * the relevant initialisation routine(s) */ _sensor_container = netsnmp_container_find("sensorTable:table_container"); if ( NULL == _sensor_container ) { snmp_log( LOG_ERR, "failed to create container for sensorTable"); return; } netsnmp_sensor_arch_init( ); /* * If we're sampling the sensor information automatically, * then arrange for this to be triggered regularly. * * If we're not sampling these values regularly, * create a suitable cache handler instead. */ if ( _sensorAutoUpdate ) { DEBUGMSGTL(("sensors", "Reloading Hardware Sensors automatically (%d)\n", _sensorAutoUpdate)); snmp_alarm_register( _sensorAutoUpdate, SA_REPEAT, _sensor_update_stats, NULL ); } else { _sensor_cache = netsnmp_cache_create( 5, netsnmp_sensor_load, netsnmp_sensor_free, NULL, 0 ); DEBUGMSGTL(("sensors", "Reloading Hardware Sensors on-demand (%p)\n", _sensor_cache)); } }
/** * @internal * initialize the container with functions or wrappers */ void _jmfcNamespaceHttpServerTable_container_init (jmfcNamespaceHttpServerTable_interface_ctx * if_ctx) { DEBUGMSGTL(("internal:jmfcNamespaceHttpServerTable:_jmfcNamespaceHttpServerTable_container_init","called\n")); /* * cache init */ if_ctx->cache = netsnmp_cache_create(30, /* timeout in seconds */ _cache_load, _cache_free, jmfcNamespaceHttpServerTable_oid, jmfcNamespaceHttpServerTable_oid_size); if(NULL == if_ctx->cache) { snmp_log(LOG_ERR, "error creating cache for jmfcNamespaceHttpServerTable\n"); return; } if_ctx->cache->flags = NETSNMP_CACHE_DONT_INVALIDATE_ON_SET; jmfcNamespaceHttpServerTable_container_init(&if_ctx->container, if_ctx->cache); if(NULL == if_ctx->container) if_ctx->container = netsnmp_container_find ("jmfcNamespaceHttpServerTable:table_container"); if(NULL == if_ctx->container) { snmp_log(LOG_ERR,"error creating container in " "jmfcNamespaceHttpServerTable_container_init\n"); return; } if (NULL != if_ctx->cache) if_ctx->cache->magic = (void*)if_ctx->container; } /* _jmfcNamespaceHttpServerTable_container_init */
void init_hw_fsys( void ) { if ( _fsys_container ) return; /* Already initialised */ DEBUGMSGTL(("fsys", "Initialise Hardware FileSystem module\n")); /* * Define a container to hold the list of filesystems */ _fsys_container = netsnmp_container_find("fsysTable:table_container"); if ( NULL == _fsys_container ) { snmp_log( LOG_ERR, "failed to create container for fsysTable"); return; } netsnmp_fsys_arch_init( ); /* * If we're sampling the file system information automatically, * then arrange for this to be triggered regularly. * * If we're not sampling these values regularly, * create a suitable cache handler instead. */ if ( _fsysAutoUpdate ) { DEBUGMSGTL(("fsys", "Reloading Hardware FileSystems automatically (%d)\n", _fsysAutoUpdate)); snmp_alarm_register( _fsysAutoUpdate, SA_REPEAT, _fsys_update_stats, NULL ); } else { _fsys_cache = netsnmp_cache_create( 5, netsnmp_fsys_load, netsnmp_fsys_free, NULL, 0 ); DEBUGMSGTL(("fsys", "Reloading Hardware FileSystems on-demand (%p)\n", _fsys_cache)); } }
/* * load a container with installed software. If user_container is NULL, * a new container will be allocated and returned, and the caller * is responsible for releasing the allocated memory when done. * * if flags contains NETSNMP_SWINST_ALL_OR_NONE and any error occurs, * the container will be completely cleared. */ netsnmp_container * netsnmp_swinst_container_load( netsnmp_container *user_container, int flags ) { netsnmp_container *container = user_container; int arch_rc; DEBUGMSGTL(("swinst:container", "load\n")); /* * create the container, if needed */ if (NULL == container) { container = netsnmp_container_find("swinst:table_container"); if (NULL == container) return NULL; } if (NULL == container->container_name) container->container_name = strdup("swinst container"); /* * call the arch specific code to load the container */ arch_rc = netsnmp_swinst_arch_load( container, flags ); if (arch_rc && (flags & NETSNMP_SWINST_ALL_OR_NONE)) { /* * caller does not want a partial load, so empty the container. * if we created the container, destroy it. */ netsnmp_swinst_container_free_items(container); if (container != user_container) { netsnmp_swinst_container_free(container, flags); } } return container; }
/* * read file names in a directory, with an optional filter */ netsnmp_container * netsnmp_directory_container_read_some(netsnmp_container *user_container, const char *dirname, netsnmp_directory_filter *filter, void *filter_ctx, u_int flags) { DIR *dir; netsnmp_container *container = user_container; struct dirent *file; char path[SNMP_MAXPATH]; size_t dirname_len; int rc; struct stat statbuf; netsnmp_file ns_file_tmp; if ((flags & NETSNMP_DIR_RELATIVE_PATH) && (flags & NETSNMP_DIR_RECURSE)) { DEBUGMSGTL(("directory:container", "no support for relative path with recursion\n")); return NULL; } DEBUGMSGTL(("directory:container", "reading %s\n", dirname)); /* * create the container, if needed */ if (NULL == container) { if (flags & NETSNMP_DIR_NSFILE) { container = netsnmp_container_find("nsfile_directory_container:" "binary_array"); if (container) { container->compare = (netsnmp_container_compare*) netsnmp_file_compare_name; container->free_item = (netsnmp_container_obj_func *) netsnmp_file_container_free; } } else container = netsnmp_container_find("directory_container:cstring"); if (NULL == container) return NULL; container->container_name = strdup(dirname); /** default to unsorted */ if (! (flags & NETSNMP_DIR_SORTED)) CONTAINER_SET_OPTIONS(container, CONTAINER_KEY_UNSORTED, rc); } dir = opendir(dirname); if (NULL == dir) { DEBUGMSGTL(("directory:container", " not a dir\n")); if (container != user_container) netsnmp_directory_container_free(container); return NULL; } /** copy dirname into path */ if (flags & NETSNMP_DIR_RELATIVE_PATH) dirname_len = 0; else { dirname_len = strlen(dirname); strncpy(path, dirname, sizeof(path)); if ((dirname_len + 2) > sizeof(path)) { /** not enough room for files */ closedir(dir); if (container != user_container) netsnmp_directory_container_free(container); return NULL; } path[dirname_len] = '/'; path[++dirname_len] = 0; } /** iterate over dir */ while ((file = readdir(dir))) { if ((file->d_name == NULL) || (file->d_name[0] == 0)) continue; /** skip '.' and '..' */ if ((file->d_name[0] == '.') && ((file->d_name[1] == 0) || ((file->d_name[1] == '.') && ((file->d_name[2] == 0))))) continue; strncpy(&path[dirname_len], file->d_name, sizeof(path) - dirname_len); if (NULL != filter) { if (flags & NETSNMP_DIR_NSFILE_STATS) { /** use local vars for now */ if (stat(path, &statbuf) != 0) { snmp_log(LOG_ERR, "could not stat %s\n", file->d_name); break; } ns_file_tmp.stats = &statbuf; ns_file_tmp.name = path; rc = (*filter)(&ns_file_tmp, filter_ctx); } else rc = (*filter)(path, filter_ctx); if (0 == rc) { DEBUGMSGTL(("directory:container:filtered", "%s\n", file->d_name)); continue; } } DEBUGMSGTL(("directory:container:found", "%s\n", path)); if ((flags & NETSNMP_DIR_RECURSE) #if defined(HAVE_STRUCT_DIRENT_D_TYPE) && defined(DT_DIR) && (file->d_type == DT_DIR) #elif defined(S_ISDIR) && (stat(file->d_name, &statbuf) != 0) && (S_ISDIR(statbuf.st_mode)) #endif ) { /** xxx add the dir as well? not for now.. maybe another flag? */ netsnmp_directory_container_read(container, path, flags); } else if (flags & NETSNMP_DIR_NSFILE) { if (_insert_nsfile( container, file->d_name, filter ? &statbuf : NULL, flags ) < 0) break; } else { char *dup = strdup(path); if (NULL == dup) { snmp_log(LOG_ERR, "strdup failed while building directory container\n"); break; } rc = CONTAINER_INSERT(container, dup); if (-1 == rc ) { DEBUGMSGTL(("directory:container", " err adding %s\n", path)); free(dup); } } } /* while */ closedir(dir); rc = CONTAINER_SIZE(container); DEBUGMSGTL(("directory:container", " container now has %d items\n", rc)); if ((0 == rc) && !(flags & NETSNMP_DIR_EMPTY_OK)) { netsnmp_directory_container_free(container); return NULL; } return container; }
/* * Initialize the openserSIPStatusCodesTable table by defining how it is * structured. * * This function is mostly auto-generated. */ void initialize_table_openserSIPStatusCodesTable(void) { netsnmp_table_registration_info *table_info; if(my_handler) { snmp_log(LOG_ERR, "initialize_table_openserSIPStatusCodes" "Table_handler called again\n"); return; } memset(&cb, 0x00, sizeof(cb)); /** create the table structure itself */ table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info); my_handler = netsnmp_create_handler_registration( "openserSIPStatusCodesTable", netsnmp_table_array_helper_handler, openserSIPStatusCodesTable_oid, openserSIPStatusCodesTable_oid_len, HANDLER_CAN_RWRITE); if (!my_handler || !table_info) { snmp_log(LOG_ERR, "malloc failed in initialize_table_openserSIP" "StatusCodesTable_handler\n"); return; /** mallocs failed */ } /** index: openserSIPStatusCodeMethod */ netsnmp_table_helper_add_index(table_info, ASN_UNSIGNED); /** index: openserSIPStatusCodeValue */ netsnmp_table_helper_add_index(table_info, ASN_UNSIGNED); table_info->min_column = openserSIPStatusCodesTable_COL_MIN; table_info->max_column = openserSIPStatusCodesTable_COL_MAX; /*************************************************** * registering the table with the master agent */ cb.get_value = openserSIPStatusCodesTable_get_value; cb.container = netsnmp_container_find("openserSIPStatusCodesTable_primary:" "openserSIPStatusCodesTable:" "table_container"); #ifdef openserSIPStatusCodesTable_CUSTOM_SORT netsnmp_container_add_index(cb.container, netsnmp_container_find( "openserSIPStatusCodesTable_custom:" "openserSIPStatusCodesTable:" "table_container")); cb.container->next->compare = openserSIPStatusCodesTable_cmp; #endif cb.can_set = 1; cb.create_row = (UserRowMethod*)openserSIPStatusCodesTable_create_row; cb.duplicate_row = (UserRowMethod*)openserSIPStatusCodesTable_duplicate_row; cb.delete_row = (UserRowMethod*)openserSIPStatusCodesTable_delete_row; cb.row_copy = (Netsnmp_User_Row_Operation *) openserSIPStatusCodesTable_row_copy; cb.can_activate = (Netsnmp_User_Row_Action *) openserSIPStatusCodesTable_can_activate; cb.can_deactivate = (Netsnmp_User_Row_Action *) openserSIPStatusCodesTable_can_deactivate; cb.can_delete = (Netsnmp_User_Row_Action *)openserSIPStatusCodesTable_can_delete; cb.set_reserve1 = openserSIPStatusCodesTable_set_reserve1; cb.set_reserve2 = openserSIPStatusCodesTable_set_reserve2; cb.set_action = openserSIPStatusCodesTable_set_action; cb.set_commit = openserSIPStatusCodesTable_set_commit; cb.set_free = openserSIPStatusCodesTable_set_free; cb.set_undo = openserSIPStatusCodesTable_set_undo; DEBUGMSGTL(("initialize_table_openserSIPStatusCodesTable", "Registering table openserSIPStatusCodesTable " "as a table array\n")); netsnmp_table_container_register(my_handler, table_info, &cb, cb.container, 1); }
/** Initialize the cpqSasPhyDrvTable table by defining its contents and how it's structured */ void initialize_table_cpqSasPhyDrvTable(void) { netsnmp_handler_registration *reg = NULL; netsnmp_mib_handler *handler = NULL; netsnmp_container *container = NULL; netsnmp_table_registration_info *table_info = NULL; netsnmp_cache *cache = NULL; int reg_tbl_ret = SNMPERR_SUCCESS; DEBUGMSGTL(("cpqSasPhyDrvTable:init", "initializing table cpqSasPhyDrvTable\n")); reg = netsnmp_create_handler_registration("cpqSasPhyDrvTable", cpqSasPhyDrvTable_handler, cpqSasPhyDrvTable_oid, cpqSasPhyDrvTable_oid_len, HANDLER_CAN_RONLY); if (NULL == reg) { snmp_log(LOG_ERR, "error creating handler registration for cpqSasPhyDrvTable\n"); goto bail; } container = netsnmp_container_find("cpqSasPhyDrvTable:table_container"); if (NULL == container) { snmp_log(LOG_ERR, "error creating container for cpqSasPhyDrvTable\n"); goto bail; } table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info); if (NULL == table_info) { snmp_log(LOG_ERR, "error allocating table registration for cpqSasPhyDrvTable\n"); goto bail; } netsnmp_table_helper_add_indexes(table_info, ASN_INTEGER, /* index: cpqSasPhyDrvHbaIndex */ ASN_INTEGER, /* index: cpqSasPhyDrvIndex */ 0); table_info->min_column = COLUMN_CPQSASPHYDRVHBAINDEX; table_info->max_column = COLUMN_CPQSASPHYDRVTEMPERATURETHRESHOLD; /************************************************* * * inject container_table helper */ handler = netsnmp_container_table_handler_get(table_info, container, TABLE_CONTAINER_KEY_NETSNMP_INDEX); if (NULL == handler) { snmp_log(LOG_ERR, "error allocating table registration for cpqSasPhyDrvTable\n"); goto bail; } if (SNMPERR_SUCCESS != netsnmp_inject_handler(reg, handler)) { snmp_log(LOG_ERR, "error injecting container_table handler for cpqSasPhyDrvTable\n"); goto bail; } handler = NULL; /* reg has it, will reuse below */ /************************************************* * * inject cache helper */ cache = netsnmp_cache_create(300, /* timeout in seconds */ _cache_load, _cache_free, cpqSasPhyDrvTable_oid, cpqSasPhyDrvTable_oid_len); if (NULL == cache) { snmp_log(LOG_ERR, "error creating cache for cpqSasPhyDrvTable\n"); goto bail; } cache->flags = NETSNMP_CACHE_PRELOAD | NETSNMP_CACHE_DONT_FREE_BEFORE_LOAD | NETSNMP_CACHE_DONT_FREE_EXPIRED | NETSNMP_CACHE_DONT_AUTO_RELEASE | NETSNMP_CACHE_DONT_INVALIDATE_ON_SET; cache->magic = container; handler = netsnmp_cache_handler_get(cache); if (NULL == handler) { snmp_log(LOG_ERR, "error creating cache handler for cpqSasPhyDrvTable\n"); goto bail; } if (SNMPERR_SUCCESS != netsnmp_inject_handler(reg, handler)) { snmp_log(LOG_ERR, "error injecting cache handler for cpqSasPhyDrvTable\n"); goto bail; } handler = NULL; /* reg has it */ /* * register the table */ reg_tbl_ret = netsnmp_register_table(reg, table_info); if (reg_tbl_ret != SNMPERR_SUCCESS) { snmp_log(LOG_ERR, "error registering table handler for cpqSasPhyDrvTable\n"); goto bail; } /* * Initialise the contents of the table here */ return; /* ok */ /* * Some error occurred during registration. Clean up and bail. */ bail: /* not ok */ if (handler) netsnmp_handler_free(handler); if (cache) netsnmp_cache_free(cache); if (table_info) netsnmp_table_registration_info_free(table_info); if (container) CONTAINER_FREE(container); if (reg_tbl_ret == SNMPERR_SUCCESS) if (reg) netsnmp_handler_registration_free(reg); }
int netsnmp_parse_args(int argc, char **argv, netsnmp_session * session, const char *localOpts, void (*proc) (int, char *const *, int), int flags) { static char *sensitive[4] = { NULL, NULL, NULL, NULL }; int arg, sp = 0, testcase = 0; char *cp; char *Apsz = NULL; char *Xpsz = NULL; char *Cpsz = NULL; char Opts[BUF_SIZE]; int zero_sensitive = !( flags & NETSNMP_PARSE_ARGS_NOZERO ); char *backup_NETSNMP_DS_LIB_OUTPUT_PRECISION = NULL; /* * initialize session to default values */ snmp_sess_init(session); strcpy(Opts, "Y:VhHm:M:O:I:P:D:dv:r:t:c:Z:e:E:n:u:l:x:X:a:A:p:T:-:3:s:S:L:"); if (localOpts) { if (strlen(localOpts) + strlen(Opts) >= sizeof(Opts)) { snmp_log(LOG_ERR, "Too many localOpts in snmp_parse_args()\n"); return -1; } strcat(Opts, localOpts); } /* * get the options */ DEBUGMSGTL(("snmp_parse_args", "starting: %d/%d\n", optind, argc)); for (arg = 0; arg < argc; arg++) { DEBUGMSGTL(("snmp_parse_args", " arg %d = %s\n", arg, argv[arg])); } optind = 1; while ((arg = getopt(argc, argv, Opts)) != EOF) { DEBUGMSGTL(("snmp_parse_args", "handling (#%d): %c\n", optind, arg)); switch (arg) { case '-': if (strcasecmp(optarg, "help") == 0) { return (NETSNMP_PARSE_ARGS_ERROR_USAGE); } if (strcasecmp(optarg, "version") == 0) { fprintf(stderr,"NET-SNMP version: %s\n",netsnmp_get_version()); return (NETSNMP_PARSE_ARGS_SUCCESS_EXIT); } handle_long_opt(optarg); break; case 'V': fprintf(stderr, "NET-SNMP version: %s\n", netsnmp_get_version()); return (NETSNMP_PARSE_ARGS_SUCCESS_EXIT); case 'h': return (NETSNMP_PARSE_ARGS_ERROR_USAGE); break; case 'H': init_snmp("snmpapp"); fprintf(stderr, "Configuration directives understood:\n"); read_config_print_usage(" "); return (NETSNMP_PARSE_ARGS_SUCCESS_EXIT); case 'Y': netsnmp_config_remember(optarg); break; #ifndef NETSNMP_DISABLE_MIB_LOADING case 'm': setenv("MIBS", optarg, 1); break; case 'M': netsnmp_get_mib_directory(); /* prepare the default directories */ netsnmp_set_mib_directory(optarg); break; #endif /* NETSNMP_DISABLE_MIB_LOADING */ case 'O': cp = snmp_out_options(optarg, argc, argv); if (cp != NULL) { fprintf(stderr, "Unknown output option passed to -O: %c.\n", *cp); return (NETSNMP_PARSE_ARGS_ERROR_USAGE); } break; case 'I': cp = snmp_in_options(optarg, argc, argv); if (cp != NULL) { fprintf(stderr, "Unknown input option passed to -I: %c.\n", *cp); return (NETSNMP_PARSE_ARGS_ERROR_USAGE); } break; #ifndef NETSNMP_DISABLE_MIB_LOADING case 'P': cp = snmp_mib_toggle_options(optarg); if (cp != NULL) { fprintf(stderr, "Unknown parsing option passed to -P: %c.\n", *cp); return (NETSNMP_PARSE_ARGS_ERROR_USAGE); } break; #endif /* NETSNMP_DISABLE_MIB_LOADING */ case 'D': debug_register_tokens(optarg); snmp_set_do_debugging(1); break; case 'd': netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_DUMP_PACKET, 1); break; case 'v': session->version = -1; #ifndef NETSNMP_DISABLE_SNMPV1 if (!strcmp(optarg, "1")) { session->version = SNMP_VERSION_1; } #endif #ifndef NETSNMP_DISABLE_SNMPV2C if (!strcasecmp(optarg, "2c")) { session->version = SNMP_VERSION_2c; } #endif if (!strcasecmp(optarg, "3")) { session->version = SNMP_VERSION_3; } if (session->version == -1) { fprintf(stderr, "Invalid version specified after -v flag: %s\n", optarg); return (NETSNMP_PARSE_ARGS_ERROR_USAGE); } break; case 'p': fprintf(stderr, "Warning: -p option is no longer used - "); fprintf(stderr, "specify the remote host as HOST:PORT\n"); return (NETSNMP_PARSE_ARGS_ERROR_USAGE); break; case 'T': { char leftside[SNMP_MAXBUF_MEDIUM], rightside[SNMP_MAXBUF_MEDIUM]; char *tmpcp, *tmpopt; /* ensure we have a proper argument */ tmpopt = strdup(optarg); tmpcp = strchr(tmpopt, '='); if (!tmpcp) { fprintf(stderr, "-T expects a NAME=VALUE pair.\n"); return (NETSNMP_PARSE_ARGS_ERROR_USAGE); } *tmpcp++ = '\0'; /* create the transport config container if this is the first */ if (!session->transport_configuration) { netsnmp_container_init_list(); session->transport_configuration = netsnmp_container_find("transport_configuration:fifo"); if (!session->transport_configuration) { fprintf(stderr, "failed to initialize the transport configuration container\n"); free(tmpopt); return (NETSNMP_PARSE_ARGS_ERROR); } session->transport_configuration->compare = (netsnmp_container_compare*) netsnmp_transport_config_compare; } /* set the config */ strlcpy(leftside, tmpopt, sizeof(leftside)); strlcpy(rightside, tmpcp, sizeof(rightside)); CONTAINER_INSERT(session->transport_configuration, netsnmp_transport_create_config(leftside, rightside)); free(tmpopt); } break; case 't': session->timeout = (long)(atof(optarg) * 1000000L); if (session->timeout <= 0) { fprintf(stderr, "Invalid timeout in seconds after -t flag.\n"); return (NETSNMP_PARSE_ARGS_ERROR_USAGE); } break; case 'r': session->retries = atoi(optarg); if (session->retries < 0 || !isdigit((unsigned char)(optarg[0]))) { fprintf(stderr, "Invalid number of retries after -r flag.\n"); return (NETSNMP_PARSE_ARGS_ERROR_USAGE); } break; case 'c': if (zero_sensitive) { if ((sensitive[sp] = strdup(optarg)) != NULL) { Cpsz = sensitive[sp]; memset(optarg, '\0', strlen(optarg)); sp++; } else { fprintf(stderr, "malloc failure processing -c flag.\n"); return NETSNMP_PARSE_ARGS_ERROR; } } else { Cpsz = optarg; } break; case '3': /* TODO: This needs to zero things too. */ if (snmpv3_options(optarg, session, &Apsz, &Xpsz, argc, argv) < 0){ return (NETSNMP_PARSE_ARGS_ERROR_USAGE); } break; case 'L': if (snmp_log_options(optarg, argc, argv) < 0) { return (NETSNMP_PARSE_ARGS_ERROR_USAGE); } break; #define SNMPV3_CMD_OPTIONS #ifdef SNMPV3_CMD_OPTIONS case 'Z': errno = 0; session->engineBoots = strtoul(optarg, &cp, 10); if (errno || cp == optarg) { fprintf(stderr, "Need engine boots value after -Z flag.\n"); return (NETSNMP_PARSE_ARGS_ERROR_USAGE); } if (*cp == ',') { char *endptr; cp++; session->engineTime = strtoul(cp, &endptr, 10); if (errno || cp == endptr) { fprintf(stderr, "Need engine time after \"-Z engineBoot,\".\n"); return (NETSNMP_PARSE_ARGS_ERROR_USAGE); } } /* * Handle previous '-Z boot time' syntax */ else if (optind < argc) { session->engineTime = strtoul(argv[optind], &cp, 10); if (errno || cp == argv[optind]) { fprintf(stderr, "Need engine time after \"-Z engineBoot\".\n"); return (NETSNMP_PARSE_ARGS_ERROR_USAGE); } } else { fprintf(stderr, "Need engine time after \"-Z engineBoot\".\n"); return (NETSNMP_PARSE_ARGS_ERROR_USAGE); } break; case 'e':{ size_t ebuf_len = 32, eout_len = 0; u_char *ebuf = (u_char *)malloc(ebuf_len); if (ebuf == NULL) { fprintf(stderr, "malloc failure processing -e flag.\n"); return (NETSNMP_PARSE_ARGS_ERROR); } if (!snmp_hex_to_binary (&ebuf, &ebuf_len, &eout_len, 1, optarg)) { fprintf(stderr, "Bad engine ID value after -e flag.\n"); free(ebuf); return (NETSNMP_PARSE_ARGS_ERROR_USAGE); } if ((eout_len < 5) || (eout_len > 32)) { fprintf(stderr, "Invalid engine ID value after -e flag.\n"); free(ebuf); return (NETSNMP_PARSE_ARGS_ERROR_USAGE); } session->securityEngineID = ebuf; session->securityEngineIDLen = eout_len; break; } case 'E':{ size_t ebuf_len = 32, eout_len = 0; u_char *ebuf = (u_char *)malloc(ebuf_len); if (ebuf == NULL) { fprintf(stderr, "malloc failure processing -E flag.\n"); return (NETSNMP_PARSE_ARGS_ERROR); } if (!snmp_hex_to_binary(&ebuf, &ebuf_len, &eout_len, 1, optarg)) { fprintf(stderr, "Bad engine ID value after -E flag.\n"); free(ebuf); return (NETSNMP_PARSE_ARGS_ERROR_USAGE); } if ((eout_len < 5) || (eout_len > 32)) { fprintf(stderr, "Invalid engine ID value after -E flag.\n"); free(ebuf); return (NETSNMP_PARSE_ARGS_ERROR_USAGE); } session->contextEngineID = ebuf; session->contextEngineIDLen = eout_len; break; } case 'n': session->contextName = optarg; session->contextNameLen = strlen(optarg); break; case 'u': if (zero_sensitive) { if ((sensitive[sp] = strdup(optarg)) != NULL) { session->securityName = sensitive[sp]; session->securityNameLen = strlen(sensitive[sp]); memset(optarg, '\0', strlen(optarg)); sp++; } else { fprintf(stderr, "malloc failure processing -u flag.\n"); return NETSNMP_PARSE_ARGS_ERROR; } } else { session->securityName = optarg; session->securityNameLen = strlen(optarg); } break; case 'l': if (!strcasecmp(optarg, "noAuthNoPriv") || !strcmp(optarg, "1") || !strcasecmp(optarg, "noauth") || !strcasecmp(optarg, "nanp")) { session->securityLevel = SNMP_SEC_LEVEL_NOAUTH; } else if (!strcasecmp(optarg, "authNoPriv") || !strcmp(optarg, "2") || !strcasecmp(optarg, "auth") || !strcasecmp(optarg, "anp")) { session->securityLevel = SNMP_SEC_LEVEL_AUTHNOPRIV; } else if (!strcasecmp(optarg, "authPriv") || !strcmp(optarg, "3") || !strcasecmp(optarg, "priv") || !strcasecmp(optarg, "ap")) { session->securityLevel = SNMP_SEC_LEVEL_AUTHPRIV; } else { fprintf(stderr, "Invalid security level specified after -l flag: %s\n", optarg); return (NETSNMP_PARSE_ARGS_ERROR_USAGE); } break; #ifdef NETSNMP_SECMOD_USM case 'a': #ifndef NETSNMP_DISABLE_MD5 if (!strcasecmp(optarg, "MD5")) { session->securityAuthProto = usmHMACMD5AuthProtocol; session->securityAuthProtoLen = USM_AUTH_PROTO_MD5_LEN; } else #endif if (!strcasecmp(optarg, "SHA")) { session->securityAuthProto = usmHMACSHA1AuthProtocol; session->securityAuthProtoLen = USM_AUTH_PROTO_SHA_LEN; } else { fprintf(stderr, "Invalid authentication protocol specified after -a flag: %s\n", optarg); return (NETSNMP_PARSE_ARGS_ERROR_USAGE); } break; case 'x': testcase = 0; #ifndef NETSNMP_DISABLE_DES if (!strcasecmp(optarg, "DES")) { testcase = 1; session->securityPrivProto = usmDESPrivProtocol; session->securityPrivProtoLen = USM_PRIV_PROTO_DES_LEN; } #endif #ifdef HAVE_AES if (!strcasecmp(optarg, "AES128") || !strcasecmp(optarg, "AES")) { testcase = 1; session->securityPrivProto = usmAESPrivProtocol; session->securityPrivProtoLen = USM_PRIV_PROTO_AES_LEN; } #endif if (testcase == 0) { fprintf(stderr, "Invalid privacy protocol specified after -x flag: %s\n", optarg); return (NETSNMP_PARSE_ARGS_ERROR_USAGE); } break; case 'A': if (zero_sensitive) { if ((sensitive[sp] = strdup(optarg)) != NULL) { Apsz = sensitive[sp]; memset(optarg, '\0', strlen(optarg)); sp++; } else { fprintf(stderr, "malloc failure processing -A flag.\n"); return NETSNMP_PARSE_ARGS_ERROR; } } else { Apsz = optarg; } break; case 'X': if (zero_sensitive) { if ((sensitive[sp] = strdup(optarg)) != NULL) { Xpsz = sensitive[sp]; memset(optarg, '\0', strlen(optarg)); sp++; } else { fprintf(stderr, "malloc failure processing -X flag.\n"); return NETSNMP_PARSE_ARGS_ERROR; } } else { Xpsz = optarg; } break; #endif /* SNMPV3_CMD_OPTIONS */ #endif /* NETSNMP_SECMOD_USM */ case '?': return (NETSNMP_PARSE_ARGS_ERROR_USAGE); break; default: proc(argc, argv, arg); break; } } DEBUGMSGTL(("snmp_parse_args", "finished: %d/%d\n", optind, argc)); /* * save command line parameters which should have precedence above config file settings * (There ought to be a more scalable approach than this....) */ if (netsnmp_ds_get_string(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_OUTPUT_PRECISION)) { backup_NETSNMP_DS_LIB_OUTPUT_PRECISION = strdup(netsnmp_ds_get_string(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_OUTPUT_PRECISION)); } /* * read in MIB database and initialize the snmp library, read the config file */ init_snmp("snmpapp"); /* * restore command line parameters which should have precedence above config file settings */ if(backup_NETSNMP_DS_LIB_OUTPUT_PRECISION) { netsnmp_ds_set_string(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_OUTPUT_PRECISION, backup_NETSNMP_DS_LIB_OUTPUT_PRECISION); free(backup_NETSNMP_DS_LIB_OUTPUT_PRECISION); } /* * session default version */ if (session->version == SNMP_DEFAULT_VERSION) { /* * run time default version */ session->version = netsnmp_ds_get_int(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_SNMPVERSION); /* * compile time default version */ if (!session->version) { switch (NETSNMP_DEFAULT_SNMP_VERSION) { #ifndef NETSNMP_DISABLE_SNMPV1 case 1: session->version = SNMP_VERSION_1; break; #endif #ifndef NETSNMP_DISABLE_SNMPV2C case 2: session->version = SNMP_VERSION_2c; break; #endif case 3: session->version = SNMP_VERSION_3; break; default: snmp_log(LOG_ERR, "Can't determine a valid SNMP version for the session\n"); return(NETSNMP_PARSE_ARGS_ERROR); } } else { #ifndef NETSNMP_DISABLE_SNMPV1 if (session->version == NETSNMP_DS_SNMP_VERSION_1) /* bogus value. version 1 actually = 0 */ session->version = SNMP_VERSION_1; #endif } } #ifdef NETSNMP_SECMOD_USM /* XXX: this should ideally be moved to snmpusm.c somehow */ /* * make master key from pass phrases */ if (Apsz) { session->securityAuthKeyLen = USM_AUTH_KU_LEN; if (session->securityAuthProto == NULL) { /* * get .conf set default */ const oid *def = get_default_authtype(&session->securityAuthProtoLen); session->securityAuthProto = snmp_duplicate_objid(def, session->securityAuthProtoLen); } if (session->securityAuthProto == NULL) { #ifndef NETSNMP_DISABLE_MD5 /* * assume MD5 */ session->securityAuthProto = snmp_duplicate_objid(usmHMACMD5AuthProtocol, USM_AUTH_PROTO_MD5_LEN); session->securityAuthProtoLen = USM_AUTH_PROTO_MD5_LEN; #else session->securityAuthProto = snmp_duplicate_objid(usmHMACSHA1AuthProtocol, USM_AUTH_PROTO_SHA_LEN); session->securityAuthProtoLen = USM_AUTH_PROTO_SHA_LEN; #endif } if (generate_Ku(session->securityAuthProto, session->securityAuthProtoLen, (u_char *) Apsz, strlen(Apsz), session->securityAuthKey, &session->securityAuthKeyLen) != SNMPERR_SUCCESS) { snmp_perror(argv[0]); fprintf(stderr, "Error generating a key (Ku) from the supplied authentication pass phrase. \n"); return (NETSNMP_PARSE_ARGS_ERROR); } } if (Xpsz) { session->securityPrivKeyLen = USM_PRIV_KU_LEN; if (session->securityPrivProto == NULL) { /* * get .conf set default */ const oid *def = get_default_privtype(&session->securityPrivProtoLen); session->securityPrivProto = snmp_duplicate_objid(def, session->securityPrivProtoLen); } if (session->securityPrivProto == NULL) { /* * assume DES */ #ifndef NETSNMP_DISABLE_DES session->securityPrivProto = snmp_duplicate_objid(usmDESPrivProtocol, USM_PRIV_PROTO_DES_LEN); session->securityPrivProtoLen = USM_PRIV_PROTO_DES_LEN; #else session->securityPrivProto = snmp_duplicate_objid(usmAESPrivProtocol, USM_PRIV_PROTO_AES_LEN); session->securityPrivProtoLen = USM_PRIV_PROTO_AES_LEN; #endif } if (generate_Ku(session->securityAuthProto, session->securityAuthProtoLen, (u_char *) Xpsz, strlen(Xpsz), session->securityPrivKey, &session->securityPrivKeyLen) != SNMPERR_SUCCESS) { snmp_perror(argv[0]); fprintf(stderr, "Error generating a key (Ku) from the supplied privacy pass phrase. \n"); return (NETSNMP_PARSE_ARGS_ERROR); } } #endif /* NETSNMP_SECMOD_USM */ /* * get the hostname */ if (optind == argc) { fprintf(stderr, "No hostname specified.\n"); return (NETSNMP_PARSE_ARGS_ERROR_USAGE); } session->peername = argv[optind++]; /* hostname */ #if !defined(NETSNMP_DISABLE_SNMPV1) || !defined(NETSNMP_DISABLE_SNMPV2C) /* * If v1 or v2c, check community has been set, either by a -c option above, * or via a default token somewhere. * If neither, it will be taken from the incoming request PDU. */ #if defined(NETSNMP_DISABLE_SNMPV1) if (session->version == SNMP_VERSION_2c) #else #if defined(NETSNMP_DISABLE_SNMPV2C) if (session->version == SNMP_VERSION_1) #else if (session->version == SNMP_VERSION_1 || session->version == SNMP_VERSION_2c) #endif #endif { if (Cpsz == NULL) { Cpsz = netsnmp_ds_get_string(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_COMMUNITY); if (Cpsz == NULL) { if (netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_IGNORE_NO_COMMUNITY)){ DEBUGMSGTL(("snmp_parse_args", "ignoring that the community string is not present\n")); session->community = NULL; session->community_len = 0; } else { fprintf(stderr, "No community name specified.\n"); return (NETSNMP_PARSE_ARGS_ERROR_USAGE); } } } else { session->community = (unsigned char *)Cpsz; session->community_len = strlen(Cpsz); } } #endif /* support for community based SNMP */ return optind; }
/** Initialize the hrSWInstalledTable table by defining its contents and how it's structured */ void initialize_table_hrSWInstalledTable(void) { static oid hrSWInstalledTable_oid[] = { 1, 3, 6, 1, 2, 1, 25, 6, 3 }; size_t hrSWInstalledTable_oid_len = OID_LENGTH(hrSWInstalledTable_oid); netsnmp_handler_registration *reg; netsnmp_mib_handler *handler = NULL; netsnmp_container *container = NULL; netsnmp_cache *cache = NULL; DEBUGMSGTL(("hrSWInstalled", "initialize\n")); reg = netsnmp_create_handler_registration("hrSWInstalledTable", hrSWInstalledTable_handler, hrSWInstalledTable_oid, hrSWInstalledTable_oid_len, HANDLER_CAN_RONLY); if (NULL == reg) { snmp_log(LOG_ERR,"error creating handler registration for " MYTABLE "\n"); goto bail; } container = netsnmp_container_find("hrSWInstalledTable:table_container"); if (NULL == container) { snmp_log(LOG_ERR,"error creating container for " MYTABLE "\n"); goto bail; } table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info); if (NULL == table_info) { snmp_log(LOG_ERR,"error allocating table registration for " MYTABLE "\n"); goto bail; } netsnmp_table_helper_add_indexes(table_info, ASN_INTEGER, /* index: hrSWInstalledIndex */ 0); table_info->min_column = COLUMN_HRSWINSTALLEDINDEX; table_info->max_column = COLUMN_HRSWINSTALLEDDATE; /************************************************* * * inject container_table helper */ handler = netsnmp_container_table_handler_get(table_info, container, TABLE_CONTAINER_KEY_NETSNMP_INDEX); if (NULL == handler) { snmp_log(LOG_ERR,"error allocating table registration for " MYTABLE "\n"); goto bail; } if (SNMPERR_SUCCESS != netsnmp_inject_handler(reg, handler)) { snmp_log(LOG_ERR,"error injecting container_table handler for " MYTABLE "\n"); goto bail; } handler = NULL; /* reg has it, will reuse below */ /************************************************* * * inject cache helper */ cache = netsnmp_cache_create(30, /* timeout in seconds */ _cache_load, _cache_free, hrSWInstalledTable_oid, hrSWInstalledTable_oid_len); if (NULL == cache) { snmp_log(LOG_ERR, "error creating cache for " MYTABLE "\n"); goto bail; } cache->magic = container; handler = netsnmp_cache_handler_get(cache); if (NULL == handler) { snmp_log(LOG_ERR, "error creating cache handler for " MYTABLE "\n"); goto bail; } if (SNMPERR_SUCCESS != netsnmp_inject_handler(reg, handler)) { snmp_log(LOG_ERR,"error injecting cache handler for " MYTABLE "\n"); goto bail; } handler = NULL; /* reg has it*/ if (SNMPERR_SUCCESS != netsnmp_register_table(reg, table_info)) { snmp_log(LOG_ERR,"error registering table handler for " MYTABLE "\n"); reg = NULL; /* it was freed inside netsnmp_register_table */ goto bail; } return; /* ok */ bail: /* not ok */ if (handler) netsnmp_handler_free(handler); if (cache) netsnmp_cache_free(cache); if (table_info) netsnmp_table_registration_info_free(table_info); if (container) CONTAINER_FREE(container); if (reg) netsnmp_handler_registration_free(reg); }
/* General initialization */ void init_custom_queries(void) { netsnmp_table_registration_info *table_info; pgsnmpd_query *curquery; int i; PGresult *res; if (custom_query_config_file == NULL) return; /* ASN_INTEGER = 0 ASN_FLOAT = 1 ASN_BOOLEAN = 2 ASN_OCTET_STR = 3 */ res = PQprepare(dbconn, "TYPEQUERY", "SELECT CASE " "WHEN typname LIKE 'int%' OR typname = 'xid' OR typname = 'oid'" "THEN 0 " "WHEN typname LIKE 'float%' THEN 1 " "WHEN typname = 'bool' THEN 2 " "ELSE 3 " "END " "FROM pg_catalog.pg_type WHERE oid = $1", 1, NULL); if (PQresultStatus(res) != PGRES_COMMAND_OK) { snmp_log(LOG_ERR, "Failed to prepare statement (error: %s)\n", PQresStatus(PQresultStatus(res))); return; } PQclear(res); head = parse_config(custom_query_config_file); if (head == NULL) { snmp_log(LOG_INFO, "No custom queries initialized\n"); return; } for (curquery = head; curquery != NULL; curquery = curquery->next) { run_query(curquery); if (curquery->typeslen < curquery->colcount) curquery->types = realloc(curquery->types, sizeof(u_char) * curquery->colcount); if (curquery->types == NULL) { snmp_log(LOG_ERR, "Memory allocation problem"); return; } init_types_array(curquery->types, curquery->typeslen, curquery->colcount); fill_query_column_types(curquery); if (curquery->my_handler) { snmp_log(LOG_ERR, "init_custom_queries called again for query %s\n", curquery->table_name); return; } memset(&(curquery->cb), 0x00, sizeof(curquery->cb)); /** create the table structure itself */ snmp_log(LOG_INFO, "Initializing table name %s\n", curquery->table_name); table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info); curquery->my_handler = netsnmp_create_handler_registration( curquery->table_name, netsnmp_table_array_helper_handler, curquery->table_oid, curquery->oid_len, HANDLER_CAN_RONLY ); if (!curquery->my_handler || !table_info) { snmp_log(LOG_ERR, "malloc failed in init_custom_queries\n"); return; /** mallocs failed */ } netsnmp_table_helper_add_index(table_info, ASN_INTEGER); /* pgsnmpdConnID */ netsnmp_table_helper_add_index(table_info, ASN_INTEGER); /* rdbmsDbIndex */ for (i = 0; i < curquery->num_indexes; i++) netsnmp_table_helper_add_index(table_info, curquery->types[i]); table_info->min_column = curquery->min_colnum; table_info->max_column = curquery->colcount; curquery->cb.get_value = custom_query_get_value; curquery->cb.container = netsnmp_container_find("table_container"); DEBUGMSGTL(("init_custom_queries", "Registering table for query " "as a table array\n")); switch (netsnmp_table_container_register(curquery->my_handler, table_info, &curquery->cb, curquery->cb.container, 1)) { case MIB_REGISTRATION_FAILED: snmp_log(LOG_INFO, "Failed to register table %s\n", curquery->table_name); break; case MIB_DUPLICATE_REGISTRATION: snmp_log(LOG_INFO, "Duplicate registration for table %s\n", curquery->table_name); break; case MIB_REGISTERED_OK: DEBUGMSGTL(("init_custom_queries", "Successfully registered table %s\n", curquery->table_name)); break; default: snmp_log(LOG_INFO, "Unknown registration result for table %s\n", curquery->table_name); } /* Having set everything up, fill the table's container with data */ fill_query_container(curquery); } snmp_log(LOG_DEBUG, "Finished intializing queries\n"); }
/** one-time initialization for mysql */ int netsnmp_mysql_init(void) { int not_argc = 0, i; char *not_args[] = { NULL }; char **not_argv = not_args; netsnmp_trapd_handler *traph; DEBUGMSGTL(("sql:init","called\n")); /** negative or 0 interval disables sql logging */ if (_sql.queue_interval <= 0) { DEBUGMSGTL(("sql:init", "mysql not enabled (sqlSaveInterval is <= 0)\n")); return 0; } /** create queue for storing traps til they are written to the db */ _sql.queue = netsnmp_container_find("fifo"); if (NULL == _sql.queue) { snmp_log(LOG_ERR, "Could not allocate sql buf container\n"); return -1; } #ifdef HAVE_BROKEN_LIBMYSQLCLIENT my_init(); #else MY_INIT("snmptrapd"); #endif /** load .my.cnf values */ load_defaults ("my", _sql.groups, ¬_argc, ¬_argv); for(i=0; i < not_argc; ++i) { if (NULL == not_argv[i]) continue; if (strncmp(not_argv[i],"--password="******"--host=",7) == 0) _sql.host_name = ¬_argv[i][7]; else if (strncmp(not_argv[i],"--user="******"--port=",7) == 0) _sql.port_num = atoi(¬_argv[i][7]); else if (strncmp(not_argv[i],"--socket=",9) == 0) _sql.socket_name = ¬_argv[i][9]; else snmp_log(LOG_WARNING, "unknown argument[%d] %s\n", i, not_argv[i]); } /** init bind structures */ memset(_tbind, 0x0, sizeof(_tbind)); memset(_vbind, 0x0, sizeof(_vbind)); /** trap static bindings */ _tbind[TBIND_HOST].buffer_type = MYSQL_TYPE_STRING; _tbind[TBIND_HOST].length = &_tbind[TBIND_HOST].buffer_length; _tbind[TBIND_OID].buffer_type = MYSQL_TYPE_STRING; _tbind[TBIND_OID].length = &_tbind[TBIND_OID].buffer_length; _tbind[TBIND_REQID].buffer_type = MYSQL_TYPE_LONG; _tbind[TBIND_REQID].is_unsigned = 1; _tbind[TBIND_VER].buffer_type = MYSQL_TYPE_SHORT; _tbind[TBIND_VER].is_unsigned = 1; _tbind[TBIND_TYPE].buffer_type = MYSQL_TYPE_SHORT; _tbind[TBIND_TYPE].is_unsigned = 1; _tbind[TBIND_DATE].buffer_type = MYSQL_TYPE_DATETIME; _tbind[TBIND_USER].buffer_type = MYSQL_TYPE_STRING; _tbind[TBIND_USER].length = &_tbind[TBIND_USER].buffer_length; _tbind[TBIND_TRANSPORT].buffer_type = MYSQL_TYPE_STRING; _tbind[TBIND_TRANSPORT].length = &_tbind[TBIND_TRANSPORT].buffer_length; _tbind[TBIND_SECURITY_MODEL].buffer_type = MYSQL_TYPE_SHORT; _tbind[TBIND_SECURITY_MODEL].is_unsigned = 1; _tbind[TBIND_v3_MSGID].buffer_type = MYSQL_TYPE_LONG; _tbind[TBIND_v3_MSGID].is_unsigned = 1; _tbind[TBIND_v3_SECURITY_LEVEL].buffer_type = MYSQL_TYPE_SHORT; _tbind[TBIND_v3_SECURITY_LEVEL].is_unsigned = 1; _tbind[TBIND_v3_CONTEXT_NAME].buffer_type = MYSQL_TYPE_STRING; _tbind[TBIND_v3_CONTEXT_ENGINE].buffer_type = MYSQL_TYPE_STRING; _tbind[TBIND_v3_SECURITY_NAME].buffer_type = MYSQL_TYPE_STRING; _tbind[TBIND_v3_SECURITY_NAME].length = &_tbind[TBIND_v3_SECURITY_NAME].buffer_length; _tbind[TBIND_v3_CONTEXT_NAME].length = &_tbind[TBIND_v3_CONTEXT_NAME].buffer_length; _tbind[TBIND_v3_SECURITY_ENGINE].buffer_type = MYSQL_TYPE_STRING; _tbind[TBIND_v3_SECURITY_ENGINE].length = &_tbind[TBIND_v3_SECURITY_ENGINE].buffer_length; _tbind[TBIND_v3_CONTEXT_ENGINE].length = &_tbind[TBIND_v3_CONTEXT_ENGINE].buffer_length; _tbind[TBIND_v3_MSGID].is_null = _tbind[TBIND_v3_SECURITY_LEVEL].is_null = _tbind[TBIND_v3_CONTEXT_NAME].is_null = _tbind[TBIND_v3_CONTEXT_ENGINE].is_null = _tbind[TBIND_v3_SECURITY_NAME].is_null = _tbind[TBIND_v3_SECURITY_ENGINE].is_null = &_no_v3; /** variable static bindings */ _vbind[VBIND_ID].buffer_type = MYSQL_TYPE_LONG; _vbind[VBIND_ID].is_unsigned = 1; _vbind[VBIND_OID].buffer_type = MYSQL_TYPE_STRING; _vbind[VBIND_OID].length = &_vbind[VBIND_OID].buffer_length; _vbind[VBIND_TYPE].buffer_type = MYSQL_TYPE_SHORT; _vbind[VBIND_TYPE].is_unsigned = 1; #ifdef NETSNMP_MYSQL_TRAP_VALUE_TEXT _vbind[VBIND_VAL].buffer_type = MYSQL_TYPE_STRING; #else _vbind[VBIND_VAL].buffer_type = MYSQL_TYPE_BLOB; #endif _vbind[VBIND_VAL].length = &_vbind[VBIND_VAL].buffer_length; _sql.conn = mysql_init (NULL); if (_sql.conn == NULL) { netsnmp_sql_error("mysql_init() failed (out of memory?)"); return -1; } /** try to connect; we'll try again later if we fail */ (void) netsnmp_mysql_connect(); /** register periodic queue save */ _sql.alarm_id = snmp_alarm_register(_sql.queue_interval, /* seconds */ 1, /* repeat */ _sql_process_queue, /* function */ NULL); /* client args */ /** add handler */ traph = netsnmp_add_global_traphandler(NETSNMPTRAPD_PRE_HANDLER, mysql_handler); if (NULL == traph) { snmp_log(LOG_ERR, "Could not allocate sql trap handler\n"); return -1; } traph->authtypes = TRAP_AUTH_LOG; atexit(netsnmp_mysql_cleanup); return 0; }
/** Initialize the cpqLinOsProcessorTable table by defining its contents * and how it's structured */ void initialize_table_cpqLinOsProcessorTable(void) { netsnmp_handler_registration *reg = NULL; netsnmp_mib_handler *handler = NULL; netsnmp_container *container = NULL; netsnmp_table_registration_info *table_info = NULL; netsnmp_cache *cache = NULL; DEBUGMSGTL(("cpqLinOsProcessorTable:init", "initializing table cpqLinOsProcessorTable\n")); reg = netsnmp_create_handler_registration("cpqLinOsProcessorTable", cpqLinOsProcessorTable_handler, cpqLinOsProcessorTable_oid, cpqLinOsProcessorTable_oid_len, HANDLER_CAN_RONLY); if (NULL == reg) { snmp_log(LOG_ERR, "error creating handler registration for cpqLinOsProcessorTable\n"); goto bail; } container = netsnmp_container_find("cpqLinOsProcessorTable:table_container"); if (NULL == container) { snmp_log(LOG_ERR, "error creating container for cpqLinOsProcessorTable\n"); goto bail; } container->container_name = strdup("cpqLinOsProcessorTable container"); table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info); if (NULL == table_info) { snmp_log(LOG_ERR, "error allocating table registration for cpqLinOsProcessorTable\n"); goto bail; } netsnmp_table_helper_add_indexes(table_info, ASN_INTEGER, /* index: cpqLinOsCpuIndex */ 0); table_info->min_column = COLUMN_CPQLINOSCPUINDEX; table_info->max_column = COLUMN_CPQLINOSCPUPRIVILEGEDTIMEPERCENT; /************************************************* * * inject container_table helper */ handler = netsnmp_container_table_handler_get(table_info, container, TABLE_CONTAINER_KEY_NETSNMP_INDEX); if (NULL == handler) { snmp_log(LOG_ERR, "error allocating table registration for cpqLinOsProcessorTable\n"); goto bail; } if (SNMPERR_SUCCESS != netsnmp_inject_handler(reg, handler)) { snmp_log(LOG_ERR, "error injecting container_table handler for cpqLinOsProcessorTable\n"); goto bail; } handler = NULL; /* reg has it, will reuse below */ /************************************************* * * inject cache helper */ cache = netsnmp_cache_create(5, /* timeout in seconds */ _cache_load, _cache_free, cpqLinOsProcessorTable_oid, cpqLinOsProcessorTable_oid_len); if (NULL == cache) { snmp_log(LOG_ERR, "error creating cache for cpqLinOsProcessorTable\n"); goto bail; } cache->flags = NETSNMP_CACHE_PRELOAD | NETSNMP_CACHE_DONT_FREE_EXPIRED | NETSNMP_CACHE_DONT_AUTO_RELEASE | NETSNMP_CACHE_DONT_FREE_BEFORE_LOAD | NETSNMP_CACHE_DONT_INVALIDATE_ON_SET; cache->magic = container; handler = netsnmp_cache_handler_get(cache); if (NULL == handler) { snmp_log(LOG_ERR, "error creating cache handler for cpqLinOsProcessorTable\n"); goto bail; } if (SNMPERR_SUCCESS != netsnmp_inject_handler(reg, handler)) { snmp_log(LOG_ERR, "error injecting cache handler for cpqLinOsProcessorTable\n"); goto bail; } handler = NULL; /* reg has it */ /* * register the table */ if (SNMPERR_SUCCESS != netsnmp_register_table(reg, table_info)) { snmp_log(LOG_ERR, "error registering table handler for cpqLinOsProcessorTable\n"); reg = NULL; /* it was freed inside netsnmp_register_table */ goto bail; } return; /* ok */ /* * Some error occurred during registration. Clean up and bail. */ bail: /* not ok */ if (handler) netsnmp_handler_free(handler); if (cache) netsnmp_cache_free(cache); if (table_info) netsnmp_table_registration_info_free(table_info); if (container) CONTAINER_FREE(container); if (reg) netsnmp_handler_registration_free(reg); }
/************************************************************ * * Initialize the memTable table by defining its contents and how it's structured */ void initialize_table_memTable(void) { netsnmp_table_registration_info *table_info; if (my_handler) { log_print(LOGN_CRI, "initialize_table_memTable_handler called again\n"); return; } memset(&cb, 0x00, sizeof(cb)); /** create the table structure itself */ table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info); /* * if your table is read only, it's easiest to change the * HANDLER_CAN_RWRITE definition below to HANDLER_CAN_RONLY */ my_handler = netsnmp_create_handler_registration("memTable", netsnmp_table_array_helper_handler, memTable_oid, memTable_oid_len, HANDLER_CAN_RWRITE); if (!my_handler || !table_info) { log_print(LOGN_CRI, "malloc failed in " "initialize_table_memTable_handler\n"); return; /** mallocs failed */ } /*************************************************** * Setting up the table's definition */ /* * TODO: add any external indexes here. */ /* * internal indexes */ /** index: memIndex */ netsnmp_table_helper_add_index(table_info, ASN_INTEGER); table_info->min_column = memTable_COL_MIN; table_info->max_column = memTable_COL_MAX; /*************************************************** * registering the table with the master agent */ cb.get_value = memTable_get_value; cb.container = netsnmp_container_find("memTable_primary:" "memTable:" "table_container"); #ifdef memTable_IDX2 netsnmp_container_add_index(cb.container, netsnmp_container_find ("memTable_secondary:" "memTable:" "table_container")); cb.container->next->compare = memTable_cmp; #endif #ifdef memTable_SET_HANDLING cb.can_set = 1; #ifdef memTable_ROW_CREATION cb.create_row = (UserRowMethod *) memTable_create_row; #endif cb.duplicate_row = (UserRowMethod *) memTable_duplicate_row; cb.delete_row = (UserRowMethod *) memTable_delete_row; cb.row_copy = (Netsnmp_User_Row_Operation *) memTable_row_copy; cb.can_delete = (Netsnmp_User_Row_Action *) memTable_can_delete; cb.set_reserve1 = memTable_set_reserve1; cb.set_reserve2 = memTable_set_reserve2; cb.set_action = memTable_set_action; cb.set_commit = memTable_set_commit; cb.set_free = memTable_set_free; cb.set_undo = memTable_set_undo; #endif DEBUGMSGTL(("initialize_table_memTable", "Registering table memTable " "as a table array\n")); netsnmp_table_container_register(my_handler, table_info, &cb, cb.container, 1); }
/************************************************************ * * Initialize the saHpiSensorTable table by defining its contents and how it's structured */ void initialize_table_saHpiSensorTable (void) { netsnmp_table_registration_info *table_info; if (my_handler) { snmp_log (LOG_ERR, "initialize_table_saHpiSensorTable_handler called again\n"); return; } memset (&cb, 0x00, sizeof (cb)); /** create the table structure itself */ table_info = SNMP_MALLOC_TYPEDEF (netsnmp_table_registration_info); /* * if your table is read only, it's easiest to change the * HANDLER_CAN_RWRITE definition below to HANDLER_CAN_RONLY */ my_handler = netsnmp_create_handler_registration ("saHpiSensorTable", netsnmp_table_array_helper_handler, saHpiSensorTable_oid, saHpiSensorTable_oid_len, HANDLER_CAN_RWRITE); if (!my_handler || !table_info) { snmp_log (LOG_ERR, "malloc failed in " "initialize_table_saHpiSensorTable_handler\n"); return; /** mallocs failed */ } /*************************************************** * Setting up the table's definition */ /* * internal indexes */ /** index: saHpiSensorIndex */ netsnmp_table_helper_add_index (table_info, ASN_UNSIGNED); netsnmp_table_helper_add_index (table_info, ASN_UNSIGNED); netsnmp_table_helper_add_index (table_info, ASN_UNSIGNED); table_info->min_column = saHpiSensorTable_COL_MIN; table_info->max_column = saHpiSensorTable_COL_MAX; /*************************************************** * registering the table with the master agent */ cb.get_value = saHpiSensorTable_get_value; cb.container = netsnmp_container_find ("saHpiSensorTable_primary:" "saHpiSensorTable:" "table_container"); // cb.can_set = 1; cb.create_row = (UserRowMethod *) saHpiSensorTable_create_row; cb.duplicate_row = (UserRowMethod *) saHpiSensorTable_duplicate_row; cb.delete_row = (UserRowMethod *) saHpiSensorTable_delete_row; cb.row_copy = (Netsnmp_User_Row_Operation *) saHpiSensorTable_row_copy; cb.can_delete = (Netsnmp_User_Row_Action *) saHpiSensorTable_can_delete; cb.set_reserve1 = saHpiSensorTable_set_reserve1; cb.set_reserve2 = saHpiSensorTable_set_reserve2; cb.set_action = saHpiSensorTable_set_action; cb.set_commit = saHpiSensorTable_set_commit; cb.set_free = saHpiSensorTable_set_free; cb.set_undo = saHpiSensorTable_set_undo; DEBUGMSGTL (("initialize_table_saHpiSensorTable", "Registering table saHpiSensorTable " "as a table array\n")); netsnmp_table_container_register (my_handler, table_info, &cb, cb.container, 1); netsnmp_register_read_only_counter32_instance ("sensor_count", saHpiSensorCount_oid, OID_LENGTH (saHpiSensorCount_oid), &sensor_count, NULL); }
/** Initializes the sysORTable module */ void init_sysORTable(void) { const oid sysORLastChange_oid[] = { 1, 3, 6, 1, 2, 1, 1, 8 }; const oid sysORTable_oid[] = { 1, 3, 6, 1, 2, 1, 1, 9 }; sysORTable_table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info); table = netsnmp_container_find("sysORTable:table_container"); if (sysORTable_table_info == NULL || table == NULL) { SNMP_FREE(sysORTable_table_info); CONTAINER_FREE(table); return; } table->container_name = strdup("sysORTable"); netsnmp_table_helper_add_indexes(sysORTable_table_info, ASN_INTEGER, /** index: sysORIndex */ 0); sysORTable_table_info->min_column = COLUMN_SYSORID; sysORTable_table_info->max_column = COLUMN_SYSORUPTIME; sysORLastChange_reg = netsnmp_create_handler_registration( "mibII/sysORLastChange", NULL, sysORLastChange_oid, OID_LENGTH(sysORLastChange_oid), HANDLER_CAN_RONLY); netsnmp_init_watcher_info( &sysORLastChange_winfo, &sysORLastChange, sizeof(u_long), ASN_TIMETICKS, WATCHER_FIXED_SIZE); netsnmp_register_watched_scalar(sysORLastChange_reg, &sysORLastChange_winfo); sysORTable_reg = netsnmp_create_handler_registration( "mibII/sysORTable", sysORTable_handler, sysORTable_oid, OID_LENGTH(sysORTable_oid), HANDLER_CAN_RONLY); netsnmp_container_table_register(sysORTable_reg, sysORTable_table_info, table, TABLE_CONTAINER_KEY_NETSNMP_INDEX); sysORLastChange = netsnmp_get_agent_uptime(); /* * Initialise the contents of the table here */ netsnmp_sysORTable_foreach(®ister_foreach, NULL); /* * Register callbacks */ snmp_register_callback(SNMP_CALLBACK_APPLICATION, SNMPD_CALLBACK_REG_SYSOR, register_cb, NULL); snmp_register_callback(SNMP_CALLBACK_APPLICATION, SNMPD_CALLBACK_UNREG_SYSOR, unregister_cb, NULL); #ifdef USING_MIBII_SYSTEM_MIB_MODULE if (++system_module_count == 3) REGISTER_SYSOR_TABLE(system_module_oid, system_module_oid_len, "The MIB module for SNMPv2 entities"); #endif }
/** Initialize the sctpLookupRemPortTable table by defining its contents and how it's structured */ void initialize_table_sctpLookupRemPortTable(void) { static oid sctpLookupRemPortTable_oid[] = { 1, 3, 6, 1, 2, 1, 104, 1, 7 }; size_t sctpLookupRemPortTable_oid_len = OID_LENGTH(sctpLookupRemPortTable_oid); netsnmp_handler_registration *reg = NULL; netsnmp_mib_handler *handler = NULL; netsnmp_container *container = NULL; reg = netsnmp_create_handler_registration("sctpLookupRemPortTable", sctpLookupRemPortTable_handler, sctpLookupRemPortTable_oid, sctpLookupRemPortTable_oid_len, HANDLER_CAN_RONLY); if (NULL == reg) { snmp_log(LOG_ERR, "error creating handler registration for sctpLookupRemPortTable\n"); goto bail; } container = netsnmp_container_find("sctpLookupRemPortTable:table_container"); if (NULL == container) { snmp_log(LOG_ERR, "error creating container for sctpLookupRemPortTable\n"); goto bail; } sctpLookupRemPortTable_container = container; table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info); if (NULL == table_info) { snmp_log(LOG_ERR, "error allocating table registration for sctpLookupRemPortTable\n"); goto bail; } netsnmp_table_helper_add_indexes(table_info, ASN_UNSIGNED, /* index: sctpAssocRemPort */ ASN_UNSIGNED, /* index: sctpAssocId */ 0); table_info->min_column = COLUMN_SCTPLOOKUPREMPORTSTARTTIME; table_info->max_column = COLUMN_SCTPLOOKUPREMPORTSTARTTIME; /************************************************* * * inject container_table helper */ handler = netsnmp_container_table_handler_get(table_info, container, TABLE_CONTAINER_KEY_NETSNMP_INDEX); if (NULL == handler) { snmp_log(LOG_ERR, "error allocating table registration for sctpLookupRemPortTable\n"); goto bail; } if (SNMPERR_SUCCESS != netsnmp_inject_handler(reg, handler)) { snmp_log(LOG_ERR, "error injecting container_table handler for sctpLookupRemPortTable\n"); goto bail; } handler = NULL; /* reg has it, will reuse below */ /* * register the table */ if (SNMPERR_SUCCESS != netsnmp_register_table(reg, table_info)) { snmp_log(LOG_ERR, "error registering table handler for sctpLookupRemPortTable\n"); reg = NULL; /* it was freed inside netsnmp_register_table */ goto bail; } return; /* ok */ /* * Some error occurred during registration. Clean up and bail. */ bail: /* not ok */ if (handler) netsnmp_handler_free(handler); if (table_info) netsnmp_table_registration_info_free(table_info); if (container) CONTAINER_FREE(container); if (reg) netsnmp_handler_registration_free(reg); }
/* * Initialize the kamailioSIPRegUserLookupTable table by defining how it is * structured. * * This function is mostly auto-generated. */ void initialize_table_kamailioSIPRegUserLookupTable(void) { netsnmp_table_registration_info *table_info; if(my_handler) { snmp_log(LOG_ERR, "initialize_table_kamailioSIPRegUserLookup" "Table_handler called again\n"); return; } memset(&cb, 0x00, sizeof(cb)); /** create the table structure itself */ table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info); my_handler = netsnmp_create_handler_registration( "kamailioSIPRegUserLookupTable", netsnmp_table_array_helper_handler, kamailioSIPRegUserLookupTable_oid, kamailioSIPRegUserLookupTable_oid_len, HANDLER_CAN_RWRITE); if (!my_handler || !table_info) { snmp_log(LOG_ERR, "malloc failed in " "initialize_table_kamailioSIPRegUserLookup" "Table_handler\n"); return; /** mallocs failed */ } /* * Setting up the table's definition */ netsnmp_table_helper_add_index(table_info, ASN_UNSIGNED); table_info->min_column = kamailioSIPRegUserLookupTable_COL_MIN; table_info->max_column = kamailioSIPRegUserLookupTable_COL_MAX; /* * registering the table with the master agent */ cb.get_value = kamailioSIPRegUserLookupTable_get_value; cb.container = netsnmp_container_find( "kamailioSIPRegUserLookupTable_primary:" "kamailioSIPRegUserLookupTable:" "table_container"); cb.can_set = 1; cb.create_row = (UserRowMethod*)kamailioSIPRegUserLookupTable_create_row; cb.duplicate_row = (UserRowMethod*)kamailioSIPRegUserLookupTable_duplicate_row; cb.delete_row = (UserRowMethod*)kamailioSIPRegUserLookupTable_delete_row; cb.row_copy = (Netsnmp_User_Row_Operation *) kamailioSIPRegUserLookupTable_row_copy; cb.can_activate = (Netsnmp_User_Row_Action *) kamailioSIPRegUserLookupTable_can_activate; cb.can_deactivate = (Netsnmp_User_Row_Action *) kamailioSIPRegUserLookupTable_can_deactivate; cb.can_delete = (Netsnmp_User_Row_Action *) kamailioSIPRegUserLookupTable_can_delete; cb.set_reserve1 = kamailioSIPRegUserLookupTable_set_reserve1; cb.set_reserve2 = kamailioSIPRegUserLookupTable_set_reserve2; cb.set_action = kamailioSIPRegUserLookupTable_set_action; cb.set_commit = kamailioSIPRegUserLookupTable_set_commit; cb.set_free = kamailioSIPRegUserLookupTable_set_free; cb.set_undo = kamailioSIPRegUserLookupTable_set_undo; DEBUGMSGTL(("initialize_table_kamailioSIPRegUserLookupTable", "Registering table kamailioSIPRegUserLookupTable " "as a table array\n")); netsnmp_table_container_register(my_handler, table_info, &cb, cb.container, 1); }
/************************************************************ * * Initialize the saHpiRdrTable table by defining its contents and how it's structured */ void initialize_table_saHpiRdrTable (void) { netsnmp_table_registration_info *table_info; if (my_handler) { snmp_log (LOG_ERR, "initialize_table_saHpiRdrTable_handler called again\n"); return; } memset (&cb, 0x00, sizeof (cb)); /** create the table structure itself */ table_info = SNMP_MALLOC_TYPEDEF (netsnmp_table_registration_info); /* * if your table is read only, it's easiest to change the * HANDLER_CAN_RWRITE definition below to HANDLER_CAN_RONLY */ my_handler = netsnmp_create_handler_registration ("saHpiRdrTable", netsnmp_table_array_helper_handler, saHpiRdrTable_oid, saHpiRdrTable_oid_len, HANDLER_CAN_RONLY); if (!my_handler || !table_info) { snmp_log (LOG_ERR, "malloc failed in " "initialize_table_saHpiRdrTable_handler\n"); return; /** mallocs failed */ } /** index: saHpiRdrRecordId */ netsnmp_table_helper_add_index (table_info, ASN_UNSIGNED); netsnmp_table_helper_add_index (table_info, ASN_UNSIGNED); netsnmp_table_helper_add_index (table_info, ASN_UNSIGNED); /** index: saHpiRdrType */ netsnmp_table_helper_add_index (table_info, ASN_INTEGER); table_info->min_column = saHpiRdrTable_COL_MIN; table_info->max_column = saHpiRdrTable_COL_MAX; /*************************************************** * registering the table with the master agent */ cb.get_value = saHpiRdrTable_get_value; cb.container = netsnmp_container_find ("saHpiRdrTable_primary:" "saHpiRdrTable:" "table_container"); cb.create_row = (UserRowMethod *) saHpiRdrTable_create_row; DEBUGMSGTL (("initialize_table_saHpiRdrTable", "Registering table saHpiRdrTable " "as a table array\n")); netsnmp_table_container_register (my_handler, table_info, &cb, cb.container, 1); netsnmp_register_read_only_counter32_instance ("rdr_count", saHpiRdrCount_oid, OID_LENGTH (saHpiRdrCount_oid), &rdr_count, NULL); }
/** Initialize the sctpAssocTable table by defining its contents and how it's structured */ void initialize_table_sctpAssocTable(void) { static oid sctpAssocTable_oid[] = { 1, 3, 6, 1, 2, 1, 104, 1, 3 }; size_t sctpAssocTable_oid_len = OID_LENGTH(sctpAssocTable_oid); netsnmp_handler_registration *reg = NULL; netsnmp_mib_handler *handler = NULL; netsnmp_container *container = NULL; netsnmp_table_registration_info *table_info = NULL; netsnmp_cache *cache = NULL; reg = netsnmp_create_handler_registration("sctpAssocTable", sctpAssocTable_handler, sctpAssocTable_oid, sctpAssocTable_oid_len, HANDLER_CAN_RWRITE); if (NULL == reg) { snmp_log(LOG_ERR, "error creating handler registration for sctpAssocTable\n"); goto bail; } /** should a set on a non-existent row create a new one? */ /** reg->modes |= HANDLER_CAN_NOT_CREATE; */ container = netsnmp_container_find("sctpAssocTable:table_container"); if (NULL == container) { snmp_log(LOG_ERR, "error creating container for sctpAssocTable\n"); goto bail; } sctpAssocTable_container = container; table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info); if (NULL == table_info) { snmp_log(LOG_ERR, "error allocating table registration for sctpAssocTable\n"); goto bail; } netsnmp_table_helper_add_indexes(table_info, ASN_UNSIGNED, /* index: sctpAssocId */ 0); table_info->min_column = COLUMN_SCTPASSOCREMHOSTNAME; table_info->max_column = COLUMN_SCTPASSOCDISCONTINUITYTIME; /************************************************* * * inject container_table helper */ handler = netsnmp_container_table_handler_get(table_info, container, TABLE_CONTAINER_KEY_NETSNMP_INDEX); if (NULL == handler) { snmp_log(LOG_ERR, "error allocating table registration for sctpAssocTable\n"); goto bail; } if (SNMPERR_SUCCESS != netsnmp_inject_handler(reg, handler)) { snmp_log(LOG_ERR, "error injecting container_table handler for sctpAssocTable\n"); goto bail; } handler = NULL; /* reg has it, will reuse below */ /************************************************* * * inject cache helper */ cache = netsnmp_cache_create(SCTP_TABLES_CACHE_TIMEOUT, /* timeout in seconds */ _cache_load, _cache_free, sctpAssocTable_oid, sctpAssocTable_oid_len); if (NULL == cache) { snmp_log(LOG_ERR, "error creating cache for sctpAssocTable\n"); goto bail; } cache->flags = NETSNMP_CACHE_DONT_INVALIDATE_ON_SET | NETSNMP_CACHE_AUTO_RELOAD | NETSNMP_CACHE_PRELOAD; cache->magic = container; handler = netsnmp_cache_handler_get(cache); if (NULL == handler) { snmp_log(LOG_ERR, "error creating cache handler for sctpAssocTable\n"); goto bail; } if (SNMPERR_SUCCESS != netsnmp_inject_handler(reg, handler)) { snmp_log(LOG_ERR, "error injecting cache handler for sctpAssocTable\n"); goto bail; } handler = NULL; /* reg has it */ /* * register the table */ if (SNMPERR_SUCCESS != netsnmp_register_table(reg, table_info)) { snmp_log(LOG_ERR, "error registering table handler for sctpAssocTable\n"); goto bail; } /* * Initialise the contents of the table here */ return; /* ok */ /* * Some error occurred during registration. Clean up and bail. */ bail: /* not ok */ if (handler) netsnmp_handler_free(handler); if (container) CONTAINER_FREE(container); if (reg) netsnmp_handler_registration_free(reg); }
/** Initialize the cpqNicIfLogMapTable table by defining its contents and how it's structured */ void initialize_table_cpqNicIfLogMapTable(void) { const oid cpqNicIfLogMapTable_oid[] = { 1, 3, 6, 1, 4, 1, 232, 18, 2, 2, 1 }; const size_t cpqNicIfLogMapTable_oid_len = OID_LENGTH(cpqNicIfLogMapTable_oid); netsnmp_handler_registration *reg = NULL; netsnmp_mib_handler *handler = NULL; netsnmp_container *container = NULL; netsnmp_table_registration_info *table_info = NULL; netsnmp_cache *cache = NULL; int reg_tbl_ret = SNMPERR_SUCCESS; DEBUGMSGTL(("cpqNicIfLogMapTable:init", "initializing table cpqNicIfLogMapTable\n")); reg = netsnmp_create_handler_registration("cpqNicIfLogMapTable", cpqNicIfLogMapTable_handler, cpqNicIfLogMapTable_oid, cpqNicIfLogMapTable_oid_len, HANDLER_CAN_RONLY); if (NULL == reg) { snmp_log(LOG_ERR, "error creating handler registration for cpqNicIfLogMapTable\n"); goto bail; } container = netsnmp_container_find("cpqNicIfLogMapTable:table_container"); if (NULL == container) { snmp_log(LOG_ERR, "error creating container for cpqNicIfLogMapTable\n"); goto bail; } container->container_name = strdup("cpqNicIfLogMapTable container"); table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info); if (NULL == table_info) { snmp_log(LOG_ERR, "error allocating table registration for cpqNicIfLogMapTable\n"); goto bail; } netsnmp_table_helper_add_indexes(table_info, ASN_INTEGER, /* index: cpqNicIfLogMapIndex */ 0); table_info->min_column = COLUMN_CPQNICIFLOGMAPINDEX; table_info->max_column = COLUMN_CPQNICIFLOGMAPPCILOCATION; /************************************************* * * inject container_table helper */ handler = netsnmp_container_table_handler_get(table_info, container, TABLE_CONTAINER_KEY_NETSNMP_INDEX); if (NULL == handler) { snmp_log(LOG_ERR, "error allocating table registration for cpqNicIfLogMapTable\n"); goto bail; } if (SNMPERR_SUCCESS != netsnmp_inject_handler(reg, handler)) { snmp_log(LOG_ERR, "error injecting container_table handler for cpqNicIfLogMapTable\n"); goto bail; } handler = NULL; /* reg has it, will reuse below */ /************************************************* * * inject cache helper */ cache = netsnmp_cache_create(30, /* timeout in seconds */ _cache_load, _cache_free, cpqNicIfLogMapTable_oid, cpqNicIfLogMapTable_oid_len); if (NULL == cache) { snmp_log(LOG_ERR, "error creating cache for cpqNicIfLogMapTable\n"); goto bail; } cache->flags = NETSNMP_CACHE_PRELOAD | NETSNMP_CACHE_DONT_FREE_EXPIRED | NETSNMP_CACHE_DONT_AUTO_RELEASE | NETSNMP_CACHE_DONT_FREE_BEFORE_LOAD | NETSNMP_CACHE_DONT_INVALIDATE_ON_SET; cache->magic = container; handler = netsnmp_cache_handler_get(cache); if (NULL == handler) { snmp_log(LOG_ERR, "error creating cache handler for cpqNicIfLogMapTable\n"); goto bail; } if (SNMPERR_SUCCESS != netsnmp_inject_handler(reg, handler)) { snmp_log(LOG_ERR, "error injecting cache handler for cpqNicIfLogMapTable\n"); goto bail; } handler = NULL; /* reg has it */ /* * register the table */ reg_tbl_ret = netsnmp_register_table(reg, table_info); if (reg_tbl_ret != SNMPERR_SUCCESS) { snmp_log(LOG_ERR, "error registering table handler for cpqNicIfLogMapTable\n"); goto bail; } return; /* ok */ /* * Some error occurred during registration. Clean up and bail. */ bail: /* not ok */ if (handler) netsnmp_handler_free(handler); if (cache) netsnmp_cache_free(cache); if (table_info) netsnmp_table_registration_info_free(table_info); if (container) CONTAINER_FREE(container); if (reg_tbl_ret == SNMPERR_SUCCESS) if (reg) netsnmp_handler_registration_free(reg); }
/************************************************************ * * Initialize the saHpiDomainEventTable table by defining its contents and how it's structured */ void initialize_table_saHpiDomainEventTable(void) { netsnmp_table_registration_info *table_info; if(my_handler) { snmp_log(LOG_ERR, "initialize_table_saHpiDomainEventTable_handler called again\n"); return; } memset(&cb, 0x00, sizeof(cb)); /** create the table structure itself */ table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info); /* if your table is read only, it's easiest to change the HANDLER_CAN_RWRITE definition below to HANDLER_CAN_RONLY */ my_handler = netsnmp_create_handler_registration("saHpiDomainEventTable", netsnmp_table_array_helper_handler, saHpiDomainEventTable_oid, saHpiDomainEventTable_oid_len, HANDLER_CAN_RWRITE); if (!my_handler || !table_info) { snmp_log(LOG_ERR, "malloc failed in " "initialize_table_saHpiDomainEventTable_handler\n"); return; /** mallocs failed */ } /*************************************************** * Setting up the table's definition */ /* * TODO: add any external indexes here. */ /** TODO: add code for external index(s)! */ /* * internal indexes */ /** index: saHpiDomainId */ netsnmp_table_helper_add_index(table_info, ASN_UNSIGNED); /** index: saHpiDomainEventEntryId */ netsnmp_table_helper_add_index(table_info, ASN_UNSIGNED); /** index: saHpiEventSeverity */ netsnmp_table_helper_add_index(table_info, ASN_INTEGER); table_info->min_column = saHpiDomainEventTable_COL_MIN; table_info->max_column = saHpiDomainEventTable_COL_MAX; /*************************************************** * registering the table with the master agent */ cb.get_value = saHpiDomainEventTable_get_value; cb.container = netsnmp_container_find("saHpiDomainEventTable_primary:" "saHpiDomainEventTable:" "table_container"); netsnmp_container_add_index(cb.container, netsnmp_container_find("saHpiDomainEventTable_secondary:" "saHpiDomainEventTable:" "table_container")); cb.container->next->compare = saHpiDomainEventTable_cmp; cb.can_set = 1; cb.create_row = (UserRowMethod*)saHpiDomainEventTable_create_row; cb.duplicate_row = (UserRowMethod*)saHpiDomainEventTable_duplicate_row; cb.delete_row = (UserRowMethod*)saHpiDomainEventTable_delete_row; cb.row_copy = (Netsnmp_User_Row_Operation *)saHpiDomainEventTable_row_copy; cb.can_activate = (Netsnmp_User_Row_Action *)saHpiDomainEventTable_can_activate; cb.can_deactivate = (Netsnmp_User_Row_Action *)saHpiDomainEventTable_can_deactivate; cb.can_delete = (Netsnmp_User_Row_Action *)saHpiDomainEventTable_can_delete; cb.set_reserve1 = saHpiDomainEventTable_set_reserve1; cb.set_reserve2 = saHpiDomainEventTable_set_reserve2; cb.set_action = saHpiDomainEventTable_set_action; cb.set_commit = saHpiDomainEventTable_set_commit; cb.set_free = saHpiDomainEventTable_set_free; cb.set_undo = saHpiDomainEventTable_set_undo; DEBUGMSGTL(("initialize_table_saHpiDomainEventTable", "Registering table saHpiDomainEventTable " "as a table array\n")); netsnmp_table_container_register(my_handler, table_info, &cb, cb.container, 1); }
/** * process text file, reading into extras */ netsnmp_container * netsnmp_file_text_parse(netsnmp_file *f, netsnmp_container *cin, int parse_mode, u_int flags, void *context) { netsnmp_container *c = cin; FILE *fin; int rc; if (NULL == f) return NULL; if ((NULL == c) && (!(flags & PM_FLAG_NO_CONTAINER))) { c = netsnmp_container_find("text_parse:binary_array"); if (NULL == c) return NULL; } rc = netsnmp_file_open(f); if (rc < 0) { /** error already logged */ if ((NULL !=c) && (c != cin)) CONTAINER_FREE(c); return NULL; } /* * get a stream from the file descriptor. This DOES NOT rewind the * file (if fd was previously opened). */ fin = fdopen(f->fd, "r"); if (NULL == fin) { if (NS_FI_AUTOCLOSE(f->ns_flags)) close(f->fd); if ((NULL !=c) && (c != cin)) CONTAINER_FREE(c); return NULL; } switch (parse_mode) { case PM_SAVE_EVERYTHING: _pm_save_everything(fin, c, flags); break; case PM_INDEX_STRING_STRING: _pm_save_index_string_string(fin, c, flags); break; case PM_USER_FUNCTION: if (NULL != context) _pm_user_function(fin, c, (netsnmp_line_process_info*)context, flags); break; default: snmp_log(LOG_ERR, "unknown parse mode %d\n", parse_mode); break; } /* * close the stream, which will have the side effect of also closing * the file descriptor, so we need to reset it. */ fclose(fin); f->fd = -1; return c; }