static void _parse_interface_config(const char *token, char *cptr) { netsnmp_conf_if_list *if_ptr, *if_new; char *name, *type, *speed, *ecp; char *st; name = strtok_r(cptr, " \t", &st); if (!name) { config_perror("Missing NAME parameter"); return; } type = strtok_r(NULL, " \t", &st); if (!type) { config_perror("Missing TYPE parameter"); return; } speed = strtok_r(NULL, " \t", &st); if (!speed) { config_perror("Missing SPEED parameter"); return; } if_ptr = conf_list; while (if_ptr) if (strcmp(if_ptr->name, name)) if_ptr = if_ptr->next; else break; if (if_ptr) config_pwarn("Duplicate interface specification"); if_new = SNMP_MALLOC_TYPEDEF(netsnmp_conf_if_list); if (!if_new) { config_perror("Out of memory"); return; } if_new->speed = strtoull(speed, &ecp, 0); if (*ecp) { config_perror("Bad SPEED value"); free(if_new); return; } if_new->type = strtol(type, &ecp, 0); if (*ecp || if_new->type < 0) { config_perror("Bad TYPE"); free(if_new); return; } if_new->name = strdup(name); if (!if_new->name) { config_perror("Out of memory"); free(if_new); return; } if_new->next = conf_list; conf_list = if_new; }
static void _parse_server_cert(const char *tok, char *line) { config_pwarn("serverCert is deprecated. Clients should use peerCert, servers should use localCert."); if (*line == '"') { char buf[SNMP_MAXBUF]; copy_nword(line, buf, sizeof(buf)); netsnmp_ds_set_string(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_X509_CLIENT_PUB, buf); } else netsnmp_ds_set_string(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_X509_SERVER_PUB, line); }
static void netsnmp_register_user_target(const char* token, char* cptr) { struct netsnmp_lookup_target *run = targets, *prev = NULL; size_t len = strlen(cptr) + 1; char* application = (char*)malloc(len); char* domain = (char*)malloc(len); char* target = (char*)malloc(len); int i = 0; { char* cp = copy_nword(cptr, application, len); cp = copy_nword(cp, domain, len); cp = copy_nword(cp, target, len); if (cp) config_pwarn("Trailing junk found"); } while (run && ((i = strcmp(run->application, application)) < 0 || (i == 0 && strcmp(run->domain, domain) < 0))) { prev = run; run = run->next; } if (run && i == 0 && strcmp(run->domain, domain) == 0) { if (run->userTarget != NULL) { config_perror("Default target already registered for this " "application-domain combination"); goto done; } } else { run = SNMP_MALLOC_STRUCT(netsnmp_lookup_target); run->application = strdup(application); run->domain = strdup(domain); run->target = NULL; if (prev) { run->next = prev->next; prev->next = run; } else { run->next = targets; targets = run; } } run->userTarget = strdup(target); done: free(target); free(domain); free(application); }
void snmpd_parse_config_informsink(const char *word, char *cptr) { char *st, *sp, *cp, *pp = NULL; if (!snmp_trapcommunity) snmp_trapcommunity = strdup("public"); sp = strtok_r(cptr, " \t\n", &st); cp = strtok_r(NULL, " \t\n", &st); if (cp) pp = strtok_r(NULL, " \t\n", &st); if (pp) config_pwarn("The separate port argument to informsink is deprecated"); if (create_v2_inform_session(sp, pp, cp ? cp : snmp_trapcommunity) == 0) { netsnmp_config_error("cannot create informsink: %s", cptr); } }
void snmpd_parse_config_trapsink(const char *token, char *cptr) { char tmpbuf[1024]; char *sp, *cp, *pp = NULL; char *st; if (!snmp_trapcommunity) snmp_trapcommunity = strdup("public"); sp = strtok_r(cptr, " \t\n", &st); cp = strtok_r(NULL, " \t\n", &st); if (cp) pp = strtok_r(NULL, " \t\n", &st); if (pp) config_pwarn("The separate port argument to trapsink is deprecated"); if (create_v1_trap_session(sp, pp, cp ? cp : snmp_trapcommunity) == 0) { snprintf(tmpbuf, sizeof(tmpbuf), "cannot create trapsink: %s", cptr); tmpbuf[sizeof(tmpbuf)-1] = '\0'; config_perror(tmpbuf); } }
/** @internal */ void netsnmp_config_parse_add_row(const char *token, char *line) { char buf[SNMP_MAXBUF_MEDIUM]; char tname[SNMP_MAXBUF_MEDIUM]; size_t buf_size; int rc; data_set_tables *tables; netsnmp_variable_list *vb; /* containing only types */ netsnmp_table_row *row; netsnmp_table_data_set_storage *dr; line = copy_nword(line, tname, SNMP_MAXBUF_MEDIUM); tables = (data_set_tables *) netsnmp_get_list_data(auto_tables, tname); if (!tables) { config_pwarn("Unknown table trying to add a row"); return; } /* * do the indexes first */ row = netsnmp_create_table_data_row(); for (vb = tables->table_set->table->indexes_template; vb; vb = vb->next_variable) { if (!line) { config_pwarn("missing an index value"); return; } DEBUGMSGTL(("table_set_add_row", "adding index of type %d\n", vb->type)); buf_size = SNMP_MAXBUF_MEDIUM; line = read_config_read_memory(vb->type, line, buf, &buf_size); netsnmp_table_row_add_index(row, vb->type, buf, buf_size); } /* * then do the data */ for (dr = tables->table_set->default_row; dr; dr = dr->next) { if (!line) { config_pwarn("missing a data value. " "All columns must be specified."); snmp_log(LOG_WARNING," can't find value for column %d\n", dr->column - 1); return; } buf_size = SNMP_MAXBUF_MEDIUM; line = read_config_read_memory(dr->type, line, buf, &buf_size); DEBUGMSGTL(("table_set_add_row", "adding data at column %d of type %d\n", dr->column, dr->type)); netsnmp_set_row_column(row, dr->column, dr->type, buf, buf_size); if (dr->writable) netsnmp_mark_row_column_writable(row, dr->column, 1); /* make writable */ } rc = netsnmp_table_data_add_row(tables->table_set->table, row); if (SNMPERR_SUCCESS != rc) { config_pwarn("error adding table row"); } }
/** @internal */ void netsnmp_config_parse_table_set(const char *token, char *line) { oid name[MAX_OID_LEN], table_name[MAX_OID_LEN]; size_t name_length = MAX_OID_LEN, table_name_length = MAX_OID_LEN; struct tree *tp, *indexnode; netsnmp_table_data_set *table_set; data_set_tables *tables; struct index_list *index; unsigned int mincol = 0xffffff, maxcol = 0; u_char type; char *pos; /* * instatiate a fake table based on MIB information */ DEBUGMSGTL(("9:table_set_add_table", "processing '%s'\n", line)); if (NULL != (pos = strchr(line,' '))) { config_pwarn("ignoring extra tokens on line"); snmp_log(LOG_WARNING," ignoring '%s'\n", pos); *pos = '\0'; } /* * check for duplicate table */ tables = (data_set_tables *) netsnmp_get_list_data(auto_tables, line); if (NULL != tables) { config_pwarn("duplicate table definition"); return; } /* * parse oid and find tree structure */ if (!snmp_parse_oid(line, table_name, &table_name_length)) { config_pwarn ("can't instatiate table since I can't parse the table name"); return; } if(NULL == (tp = get_tree(table_name, table_name_length, get_tree_head()))) { config_pwarn("can't instatiate table since " "I can't find mib information about it"); return; } if (NULL == (tp = tp->child_list) || NULL == tp->child_list) { config_pwarn("can't instatiate table since it doesn't appear to be " "a proper table (no children)"); return; } /* * check for augments indexes */ if (NULL != tp->augments) { if (!snmp_parse_oid(tp->augments, table_name, &table_name_length)) { config_pwarn("I can't parse the augment tabel name"); snmp_log(LOG_WARNING, " can't parse %s\n", tp->augments); return; } if(NULL == (tp = get_tree(table_name, table_name_length, get_tree_head()))) { config_pwarn("can't instatiate table since " "I can't find mib information about augment table"); snmp_log(LOG_WARNING, " table %s not found in tree\n", tp->augments); return; } table_set = netsnmp_create_table_data_set(line); /* * loop through indexes and add types */ for (index = tp->indexes; index; index = index->next) { if (!snmp_parse_oid(index->ilabel, name, &name_length) || (NULL == (indexnode = get_tree(name, name_length, get_tree_head())))) { config_pwarn("can't instatiate table since " "I don't know anything about one index"); snmp_log(LOG_WARNING, " index %s not found in tree\n", index->ilabel); return; /* xxx mem leak */ } type = mib_to_asn_type(indexnode->type); if (type == (u_char) - 1) { config_pwarn("unknown index type"); return; /* xxx mem leak */ } if (index->isimplied) /* if implied, mark it as such */ type |= ASN_PRIVATE; DEBUGMSGTL(("table_set_add_row", "adding default index of type %d\n", type)); netsnmp_table_dataset_add_index(table_set, type); } } else table_set = netsnmp_create_table_data_set(line); /* * loop through indexes and add types */ for (index = tp->indexes; index; index = index->next) { if (!snmp_parse_oid(index->ilabel, name, &name_length) || (NULL == (indexnode = get_tree(name, name_length, get_tree_head())))) { config_pwarn("can't instatiate table since " "I don't know anything about one index"); snmp_log(LOG_WARNING, " index %s not found in tree\n", index->ilabel); return; /* xxx mem leak */ } type = mib_to_asn_type(indexnode->type); if (type == (u_char) - 1) { config_pwarn("unknown index type"); return; /* xxx mem leak */ } if (index->isimplied) /* if implied, mark it as such */ type |= ASN_PRIVATE; DEBUGMSGTL(("table_set_add_row", "adding default index of type %d\n", type)); netsnmp_table_dataset_add_index(table_set, type); } /* * loop through children and add each column info */ for (tp = tp->child_list; tp; tp = tp->next_peer) { int canwrite = 0; type = mib_to_asn_type(tp->type); if (type == (u_char) - 1) { config_pwarn("unknown column type"); return; /* xxx mem leak */ } DEBUGMSGTL(("table_set_add_row", "adding column %s(%d) of type %d (access %d)\n", tp->label, tp->subid, type, tp->access)); switch (tp->access) { case MIB_ACCESS_CREATE: table_set->allow_creation = 1; case MIB_ACCESS_READWRITE: case MIB_ACCESS_WRITEONLY: canwrite = 1; case MIB_ACCESS_READONLY: DEBUGMSGTL(("table_set_add_row", "adding column %d of type %d\n", tp->subid, type)); netsnmp_table_set_add_default_row(table_set, tp->subid, type, canwrite, NULL, 0); mincol = SNMP_MIN(mincol, tp->subid); maxcol = SNMP_MAX(maxcol, tp->subid); break; case MIB_ACCESS_NOACCESS: case MIB_ACCESS_NOTIFY: break; default: config_pwarn("unknown column access type"); break; } } /* * register the table */ netsnmp_register_table_data_set(netsnmp_create_handler_registration (line, NULL, table_name, table_name_length, HANDLER_CAN_RWRITE), table_set, NULL); netsnmp_register_auto_data_table(table_set, NULL); }
static void _table_set_add_indexes(netsnmp_table_data_set *table_set, struct tree *tp) { oid name[MAX_OID_LEN]; size_t name_length = MAX_OID_LEN; struct index_list *index; struct tree *indexnode; u_char type; int fixed_len = 0; /* * loop through indexes and add types */ for (index = tp->indexes; index; index = index->next) { if (!snmp_parse_oid(index->ilabel, name, &name_length) || (NULL == (indexnode = get_tree(name, name_length, get_tree_head())))) { config_pwarn("can't instatiate table since " "I don't know anything about one index"); snmp_log(LOG_WARNING, " index %s not found in tree\n", index->ilabel); return; /* xxx mem leak */ } type = mib_to_asn_type(indexnode->type); if (type == (u_char) - 1) { config_pwarn("unknown index type"); return; /* xxx mem leak */ } /* * if implied, mark it as such. also mark fixed length * octet strings as implied (ie no length prefix) as well. * */ if ((TYPE_OCTETSTR == indexnode->type) && /* octet str */ (NULL != indexnode->ranges) && /* & has range */ (NULL == indexnode->ranges->next) && /* but only one */ (indexnode->ranges->high == /* & high==low */ indexnode->ranges->low)) { type |= ASN_PRIVATE; fixed_len = indexnode->ranges->high; } else if (index->isimplied) type |= ASN_PRIVATE; DEBUGMSGTL(("table_set_add_table", "adding default index of type %d\n", type)); netsnmp_table_dataset_add_index(table_set, type); /* * hack alert: for fixed lenght strings, save the * lenght for use during oid parsing. */ if (fixed_len) { /* * find last (just added) index */ netsnmp_variable_list *var = table_set->table->indexes_template; while (NULL != var->next_variable) var = var->next_variable; var->val_len = fixed_len; } } }
void disk_parse_config(char *token, char *cptr) { #if HAVE_GETMNTENT #if HAVE_SYS_MNTTAB_H struct mnttab mnttab; #else struct mntent *mntent; #endif FILE *mntfp; #else #if HAVE_FSTAB_H struct fstab *fstab; struct stat stat1, stat2; #endif #endif char tmpbuf[1024]; #if defined(HAVE_GETMNTENT) && !defined(HAVE_SETMNTENT) int i; #endif #if HAVE_FSTAB_H || HAVE_GETMNTENT if (numdisks == MAXDISKS) { config_perror("Too many disks specified."); sprintf(tmpbuf,"\tignoring: %s",cptr); config_perror(tmpbuf); } else { /* read disk path (eg, /1 or /usr) */ copy_word(cptr,disks[numdisks].path); cptr = skip_not_white(cptr); cptr = skip_white(cptr); /* read optional minimum disk usage spec */ if (cptr != NULL) { if (strchr(cptr, '%') == 0) { disks[numdisks].minimumspace = atoi(cptr); disks[numdisks].minpercent = -1; } else { disks[numdisks].minimumspace = -1; disks[numdisks].minpercent = atoi(cptr); } } else { disks[numdisks].minimumspace = DEFDISKMINIMUMSPACE; disks[numdisks].minpercent = -1; } /* find the device associated with the directory */ #if HAVE_GETMNTENT #if HAVE_SETMNTENT mntfp = setmntent(ETC_MNTTAB, "r"); disks[numdisks].device[0] = 0; while ((mntent = getmntent (mntfp))) if (strcmp (disks[numdisks].path, mntent->mnt_dir) == 0) { copy_word (mntent->mnt_fsname, disks[numdisks].device); DEBUGMSGTL(("ucd-snmp/disk", "Disk: %s\n",mntent->mnt_fsname)); break; } else { DEBUGMSGTL(("ucd-snmp/disk", " %s != %s\n", disks[numdisks].path, mntent->mnt_dir)); } endmntent(mntfp); if (disks[numdisks].device[0] != 0) { /* dummy clause for else below */ numdisks += 1; /* but inc numdisks here after test */ } #else /* getmentent but not setmntent */ mntfp = fopen (ETC_MNTTAB, "r"); while ((i = getmntent (mntfp, &mnttab)) == 0) if (strcmp (disks[numdisks].path, mnttab.mnt_mountp) == 0) break; else { DEBUGMSGTL(("ucd-snmp/disk", " %s != %s\n", disks[numdisks].path, mnttab.mnt_mountp)); } fclose (mntfp); if (i == 0) { copy_word (mnttab.mnt_special, disks[numdisks].device); numdisks += 1; } #endif /* HAVE_SETMNTENT */ #else #if HAVE_FSTAB_H stat(disks[numdisks].path,&stat1); setfsent(); if ((fstab = getfsfile(disks[numdisks].path))) { copy_word(fstab->fs_spec,disks[numdisks].device); numdisks += 1; } #endif #endif else { sprintf(tmpbuf, "Couldn't find device for disk %s", disks[numdisks].path); config_pwarn(tmpbuf); disks[numdisks].minimumspace = -1; disks[numdisks].minpercent = -1; disks[numdisks].path[0] = 0; } #if HAVE_FSTAB_H endfsent(); #endif } #else config_perror("'disk' checks not supported on this architecture."); #endif }
/* config_perror: prints a warning string associated with a file and line number of a .conf file and increments the error count. */ void config_perror(const char *string) { config_pwarn(string); config_errors++; }
/*******************************************************************-o-****** * read_config * * Parameters: * *filename * *line_handler * when * * Read <filename> and process each line in accordance with the list of * <line_handler> functions. * * * For each line in <filename>, search the list of <line_handler>'s * for an entry that matches the first token on the line. This comparison is * case insensitive. * * For each match, check that <when> is the designated time for the * <line_handler> function to be executed before processing the line. */ void read_config(const char *filename, struct config_line *line_handler, int when) { #ifdef CYGPKG_SNMPLIB_FILESYSTEM_SUPPORT FILE *ifile; char line[STRINGMAX], token[STRINGMAX], tmpbuf[STRINGMAX]; char *cptr; int i, done; struct config_line *lptr; linecount = 0; curfilename = filename; if ((ifile = fopen(filename, "r")) == NULL) { #ifdef ENOENT if (errno == ENOENT) { DEBUGMSGTL(("read_config", "%s: %s\n", filename, strerror(errno))); } else #endif /* ENOENT */ #ifdef EACCES if (errno == EACCES) { DEBUGMSGTL(("read_config", "%s: %s\n", filename, strerror(errno))); } else #endif /* EACCES */ #if defined(ENOENT) || defined(EACCES) { snmp_log_perror(filename); } #else /* defined(ENOENT) || defined(EACCES) */ snmp_log_perror(filename); #endif /* ENOENT */ return; } else { DEBUGMSGTL(("read_config", "Reading configuration %s\n", filename)); } while (fgets(line, sizeof(line), ifile) != NULL) { lptr = line_handler; linecount++; cptr = line; i = strlen(line)-1; if (line[i] == '\n') line[i] = 0; /* check blank line or # comment */ if ((cptr = skip_white(cptr))) { cptr = copy_word(cptr,token); if (cptr == NULL) { sprintf(tmpbuf,"Blank line following %s token.", token); config_perror(tmpbuf); } else { for(lptr = line_handler, done=0; lptr != NULL && !done; lptr = lptr->next) { if (!strcasecmp(token,lptr->config_token)) { if (when == EITHER_CONFIG || lptr->config_time == when) { DEBUGMSGTL(("read_config", "%s:%d Parsing: %s\n", filename, linecount, line)); (*(lptr->parse_line))(token,cptr); } done = 1; } } if (!done && when != PREMIB_CONFIG && !ds_get_boolean(DS_LIBRARY_ID, DS_LIB_NO_TOKEN_WARNINGS)) { sprintf(tmpbuf,"Unknown token: %s.", token); config_pwarn(tmpbuf); } } } } fclose(ifile); #endif return; } /* end read_config() */