void se_store_enum_list(struct snmp_enum_list *new_list, const char *token, const char *type) { struct snmp_enum_list *listp = new_list; char line[2048]; char buf[512]; int len; snprintf(line, sizeof(line), "enum %s", token); while (listp) { snprintf(buf, sizeof(buf), " %d:%s", listp->value, listp->label); /* * Calculate the space left in the buffer. * If this is not sufficient to include the next enum, * then save the line so far, and start again. */ len = sizeof(line) - strlen(line); if ((int)strlen(buf) > len) { read_config_store(type, line); snprintf(line, sizeof(line), "enum %s", token); len = sizeof(line) - strlen(line); } strncat(line, buf, len); listp = listp->next; } read_config_store(type, line); }
/*******************************************************************-o-****** * store_snmpv3 * * Parameters: * *type */ int snmpv3_store(int majorID, int minorID, void *serverarg, void *clientarg) { char line[SNMP_MAXBUF_SMALL]; u_char c_engineID[SNMP_MAXBUF_SMALL]; int engineIDLen; const char *type = (const char *) clientarg; if (type == NULL) /* should never happen, since the arg is ours */ type = "unknown"; sprintf(line, "engineBoots %ld", engineBoots); read_config_store(type, line); engineIDLen = snmpv3_get_engineID(c_engineID, SNMP_MAXBUF_SMALL); if (engineIDLen) { /* * store the engineID used for this run */ sprintf(line, "oldEngineID "); read_config_save_octet_string(line + strlen(line), c_engineID, engineIDLen); read_config_store(type, line); } return SNMPERR_SUCCESS; } /* snmpv3_store() */
static int _debug_stats_callback(int majorID, int minorID, void *serverarg, void *clientarg) { char sep[] = "##############################################################"; char buf[] = "#\n" "# debug stats\n" "#"; char *type = netsnmp_ds_get_string(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_APPTYPE); read_config_store((char *) type, sep); read_config_store((char *) type, buf); /* * save all rows */ CONTAINER_FOR_EACH((netsnmp_container *) clientarg, (netsnmp_container_obj_func *) _save_debug_stat, type); read_config_store((char *) type, sep); read_config_store((char *) type, "\n"); /* * never fails */ return SNMPERR_SUCCESS; }
static int _save_map(netsnmp_cert_map *map, int row_status, void *app_type) { char buf[SNMP_MAXBUF_SMALL], *hashType, *mapType, *data = NULL; if (NULL == map) return SNMP_ERR_GENERR; /** don't store values from conf files */ if (! (map->flags & NSCM_NONVOLATILE)) { DEBUGMSGT(("tlstmCertToTSNTable:save", "skipping RO/permanent/volatile row\n")); return SNMP_ERR_NOERROR; } hashType = se_find_label_in_slist("cert_hash_alg", map->hashType); if (NULL == hashType) { snmp_log(LOG_ERR, "skipping entry unknown hash type %d\n", map->hashType); return SNMP_ERR_GENERR; } mapType = se_find_label_in_slist("cert_map_type", map->mapType); if (TSNM_tlstmCertSpecified == map->mapType) data = (char*)map->data; snprintf(buf, sizeof(buf), "%s %d --%s %s --%s %s %d", MAP_MIB_CONFIG_TOKEN, map->priority, hashType, map->fingerprint, mapType, data ? data : "", row_status); DEBUGMSGTL(("tlstmCertToTSNTable:save", "saving '%s'\n", buf)); read_config_store(app_type, buf); return SNMP_ERR_NOERROR; }
static int _save_entry(certToTSN_entry *entry, void *app_type) { char buf[SNMP_MAXBUF_SMALL], *hashType, *mapType, *data = NULL; if (NULL == entry) return SNMP_ERR_GENERR; hashType = se_find_label_in_slist("cert_hash_alg", entry->hashType); if (NULL == hashType) { snmp_log(LOG_ERR, "skipping entry unknown hash type %d\n", entry->hashType); return SNMP_ERR_GENERR; } mapType = se_find_label_in_slist("cert_map_type", entry->mapType); if (TSNM_tlstmCertSpecified == entry->mapType) data = entry->data; snprintf(buf, sizeof(buf), "%s %ld --%s %s --%s %s %d", MAP_MIB_CONFIG_TOKEN, entry->tlstmCertToTSNID, hashType, entry->fingerprint, mapType, data ? data : "", entry->rowStatus); DEBUGMSGTL(("tlstmCertToTSNTable:save", "saving '%s'\n", buf)); read_config_store(app_type, buf); return SNMP_ERR_NOERROR; }
/** intended to be called as a callback during persistent save operations. * See the netsnmp_save_all_data_callback for where this is typically used. */ int netsnmp_save_all_data(netsnmp_data_list *head, const char *type, const char *token, Netsnmp_Save_List_Data * data_list_save_ptr) { char buf[SNMP_MAXBUF], *cp; for (; head; head = head->next) { if (head->name) { /* save begining of line */ snprintf(buf, sizeof(buf), "%s ", token); cp = buf + strlen(buf); cp = read_config_save_octet_string(cp, (u_char*)head->name, strlen(head->name)); *cp++ = ' '; /* call registered function to save the rest */ if (!(data_list_save_ptr)(cp, sizeof(buf) - strlen(buf), head->data)) { read_config_store(type, buf); } } } return SNMP_ERR_NOERROR; }
void vacm_save_auth_access(struct vacm_accessEntry *access_entry, const char *token, const char *type, int authtype) { char line[4096]; char *cptr; memset(line, 0, sizeof(line)); snprintf(line, sizeof(line), "%s%s %d %d %d %d %d ", token, "AuthAccess", access_entry->status, access_entry->storageType, access_entry->securityModel, access_entry->securityLevel, access_entry->contextMatch); line[ sizeof(line)-1 ] = 0; cptr = &line[strlen(line)]; /* the NULL */ cptr = read_config_save_octet_string(cptr, (u_char *) access_entry->groupName + 1, access_entry->groupName[0] + 1); *cptr++ = ' '; cptr = read_config_save_octet_string(cptr, (u_char *) access_entry->contextPrefix + 1, access_entry->contextPrefix[0] + 1); snprintf(cptr, sizeof(line)-(cptr-line), " %d ", authtype); while ( *cptr ) cptr++; *cptr++ = ' '; cptr = read_config_save_octet_string(cptr, (u_char *)access_entry->views[authtype], strlen(access_entry->views[authtype]) + 1); read_config_store(type, line); }
/* * vacm_save_view(): saves a view entry to the persistent cache */ void vacm_save_view(struct vacm_viewEntry *view, const char *token, const char *type) { char line[4096]; char *cptr; memset(line, 0, sizeof(line)); snprintf(line, sizeof(line), "%s%s %d %d %d ", token, "View", view->viewStatus, view->viewStorageType, view->viewType); line[ sizeof(line)-1 ] = 0; cptr = &line[strlen(line)]; /* the NULL */ cptr = read_config_save_octet_string(cptr, (u_char *) view->viewName + 1, view->viewName[0]); *cptr++ = ' '; cptr = read_config_save_objid(cptr, view->viewSubtree+1, view->viewSubtreeLen-1); *cptr++ = ' '; cptr = read_config_save_octet_string(cptr, (u_char *) view->viewMask, view->viewMaskLen); read_config_store(type, line); }
/** stores data in a starsh tree to peristent storage. This function can be called to save all data in a stash tree to Net-SNMP's percent storage. Make sure you register a parsing function with the read_config system to re-incorperate your saved data into future trees. @param root the top of the stash to store. @param tokenname the file token name to save in (passing "snmpd" will save things into snmpd.conf). @param dumpfn A function which can dump the data stored at a particular node into a char buffer. @param curoid must be a pointer to a OID array of length MAX_OID_LEN. @param curoid_len must be 0 for the top level call. */ void netsnmp_oid_stash_store(netsnmp_oid_stash_node *root, const char *tokenname, NetSNMPStashDump *dumpfn, oid *curoid, size_t curoid_len) { char buf[SNMP_MAXBUF]; netsnmp_oid_stash_node *tmpp; char *cp; char *appname = netsnmp_ds_get_string(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_APPTYPE); int i; if (!tokenname || !root || !curoid || !dumpfn) return; for (i = 0; i < (int)root->children_size; i++) { if (root->children[i]) { for (tmpp = root->children[i]; tmpp; tmpp = tmpp->next_sibling) { curoid[curoid_len] = tmpp->value; if (tmpp->thedata) { snprintf(buf, sizeof(buf), "%s ", tokenname); cp = read_config_save_objid(buf+strlen(buf), curoid, curoid_len+1); *cp++ = ' '; *cp = '\0'; if ((*dumpfn)(cp, sizeof(buf) - strlen(buf), tmpp->thedata, tmpp)) read_config_store(appname, buf); } netsnmp_oid_stash_store(tmpp, tokenname, dumpfn, curoid, curoid_len+1); } } } }
static int _save_debug_stat(netsnmp_token_descr *tb, void *type) { char buf[256]; snprintf(buf, sizeof(buf), "debug_hits %s %d", tb->token_name, tb->enabled); read_config_store((char *) type, buf); return SNMP_ERR_NOERROR; }
/* * vacm_save_group(): saves a group entry to the persistent cache */ void vacm_save_group (struct vacm_groupEntry *group_entry, const char *token, const char *type) { char line[4096]; char *cptr; memset (line, 0, sizeof (line)); snprintf (line, sizeof (line), "%s%s %d %d %d ", token, "Group", group_entry->status, group_entry->storageType, group_entry->securityModel); line[sizeof (line) - 1] = 0; cptr = &line[strlen (line)]; /* the NULL */ cptr = read_config_save_octet_string (cptr, (u_char *) group_entry->securityName + 1, group_entry->securityName[0] + 1); *cptr++ = ' '; cptr = read_config_save_octet_string (cptr, (u_char *) group_entry->groupName, strlen (group_entry->groupName) + 1); read_config_store (type, line); }
static int _save_maps(int majorID, int minorID, void *serverarg, void *clientarg) { char sep[] = "\n##############################################################"; char buf[] = "#\n" "# certificate secName mapping persistent data\n" "#"; char *type = netsnmp_ds_get_string(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_APPTYPE); netsnmp_container *maps = netsnmp_cert_map_container(); netsnmp_tdata_row *row; netsnmp_iterator *tbl_itr, *map_itr; netsnmp_cert_map *map; certToTSN_entry *entry; if ((NULL == maps) || ((CONTAINER_SIZE(maps) == 0) && (CONTAINER_SIZE(_table->container) == 0))) return SNMPERR_SUCCESS; read_config_store((char *) type, sep); read_config_store((char *) type, buf); /* * save active rows from maps */ if (NULL != maps) { map_itr = CONTAINER_ITERATOR(maps); if (NULL == map_itr) { DEBUGMSGTL(("tlstmCertToTSNTable:save", "cant get map iterator\n")); map = NULL; } else map = ITERATOR_FIRST(map_itr); for( ; map; map = ITERATOR_NEXT(map_itr)) { /** don't store config rows */ if (map->flags & NSCM_FROM_CONFIG) continue; _save_map(map, RS_ACTIVE, type); } } ITERATOR_RELEASE(map_itr); /* * save inactive rows from mib */ tbl_itr = CONTAINER_ITERATOR(_table->container); if (NULL == tbl_itr) DEBUGMSGTL(("tlstmCertToTSNTable:save", "cant get table iterator\n")); else { row = ITERATOR_FIRST(tbl_itr); for( ; row; row = ITERATOR_NEXT(tbl_itr)) { entry = row->data; /* * skip all active rows (should be in maps and thus saved * above) and volatile rows. */ if ((entry->rowStatus == RS_ACTIVE) || (entry->storageType != ST_NONVOLATILE)) continue; _save_entry(entry, type); } ITERATOR_RELEASE(tbl_itr); } read_config_store((char *) type, sep); read_config_store((char *) type, "\n"); /* * never fails */ return SNMPERR_SUCCESS; }
void read_app_config_store(const char *line) { read_config_store(ds_get_string(DS_LIBRARY_ID, DS_LIB_APPTYPE), line); }