void parse_trapd_address(const char *token, char *cptr) { char buf[BUFSIZ]; cptr = copy_nword(cptr, buf, sizeof(buf)); if (default_port == ddefault_port) { default_port = strdup(buf); } else { strcat( buf, "," ); strcat( buf, default_port ); free(default_port); default_port = strdup(buf); } }
void snmpd_parse_config_trapsess(const char *word, char *cptr) { char *argv[MAX_ARGS], *cp = cptr, tmp[SPRINT_MAX_LEN]; int argn, arg; netsnmp_session session, *ss; /* * inform or trap? default to trap */ traptype = SNMP_MSG_TRAP2; /* * create the argv[] like array */ argv[0] = strdup("snmpd-trapsess"); /* bogus entry for getopt() */ for (argn = 1; cp && argn < MAX_ARGS; argn++) { cp = copy_nword(cp, tmp, SPRINT_MAX_LEN); argv[argn] = strdup(tmp); } arg = snmp_parse_args(argn, argv, &session, "C:", trapOptProc); ss = snmp_open(&session); for (; argn > 0; argn--) { free(argv[argn - 1]); } if (!ss) { config_perror ("snmpd: failed to parse this line or the remote trap receiver is down. Possible cause:"); snmp_sess_perror("snmpd: snmpd_parse_config_trapsess()", &session); return; } #ifndef DISABLE_SNMPV1 if (ss->version == SNMP_VERSION_1) { add_trap_session(ss, SNMP_MSG_TRAP, 0, SNMP_VERSION_1); } else { #endif add_trap_session(ss, traptype, (traptype == SNMP_MSG_INFORM), ss->version); #ifndef DISABLE_SNMPV1 } #endif }
void parse_trapd_address(const char *token, char *cptr) { char buf[BUFSIZ]; char *p; cptr = copy_nword(cptr, buf, sizeof(buf)); if (default_port == ddefault_port) { default_port = strdup(buf); } else { p = malloc(strlen(buf) + 1 + strlen(default_port) + 1); if (p) { strcat(p, buf); strcat(p, ","); strcat(p, default_port ); } free(default_port); default_port = p; } }
static void netsnmp_register_user_domain(const char* token, char* cptr) { struct netsnmp_lookup_domain *run = domains, *prev = NULL; size_t len = strlen(cptr) + 1; char* application = (char*)malloc(len); char** domain; { char* cp = copy_nword(cptr, application, len); domain = create_word_array(cp); } while (run != NULL && strcmp(run->application, application) < 0) { prev = run; run = run->next; } if (run && strcmp(run->application, application) == 0) { if (run->userDomain != NULL) { config_perror("Default transport already registered for this " "application"); destroy_word_array(domain); free(application); return; } } else { run = SNMP_MALLOC_STRUCT(netsnmp_lookup_domain); run->application = strdup(application); run->domain = NULL; if (prev) { run->next = prev->next; prev->next = run; } else { run->next = domains; domains = run; } } run->userDomain = domain; free(application); }
void regexp_procfix_parse_config(const char *token, char *cptr) { char tmpname[STRMAX]; struct myregexp_proc *procp; /* * don't allow two entries with the same name */ cptr = copy_nword(cptr, tmpname, sizeof(tmpname)); if ((procp = get_regexp_proc_by_name(tmpname)) == NULL) { config_perror("No proc entry registered for this proc name yet."); return; } if (strlen(cptr) > sizeof(procp->fixcmd)) { config_perror("fix command too long."); return; } strcpy(procp->fixcmd, cptr); }
void execfix_parse_config(const char *token, char *cptr) { char tmpname[STRMAX]; struct extensible *execp; /* * don't allow two entries with the same name */ cptr = copy_nword(cptr, tmpname, sizeof(tmpname)); if ((execp = get_exec_by_name(tmpname)) == NULL) { config_perror("No exec entry registered for this exec name yet."); return; } if (strlen(cptr) > sizeof(execp->fixcmd)) { config_perror("fix command too long."); return; } strlcpy(execp->fixcmd, cptr, sizeof(execp->fixcmd)); }
void extensible_parse_config(const char *token, char *cptr) { struct extensible *ptmp, **pp; char *tcptr; int scount; /* * allocate and clear memory structure */ ptmp = (struct extensible *) calloc(1, sizeof(struct extensible)); if (ptmp == NULL) return; /* XXX memory alloc error */ if (*cptr == '.') cptr++; if (isdigit(*cptr)) { /* * its a relocatable extensible mib */ config_perror("WARNING: This output format is not valid, and is only retained for backward compatibility - Please consider using the 'extend' directive instead" ); for (pp = &relocs, numrelocs++; *pp; pp = &((*pp)->next)); (*pp) = ptmp; pp = &relocs; scount = numrelocs; } else { /* * it goes in with the general extensible table */ for (pp = &extens, numextens++; *pp; pp = &((*pp)->next)); (*pp) = ptmp; pp = &extens; scount = numextens; } /* * the rest is pretty much handled the same */ if (!strncasecmp(token, "sh", 2)) ptmp->type = SHPROC; else ptmp->type = EXECPROC; if (isdigit(*cptr)) { ptmp->miblen = parse_miboid(cptr, ptmp->miboid); while (isdigit(*cptr) || *cptr == '.') cptr++; } /* * name */ cptr = skip_white(cptr); copy_nword(cptr, ptmp->name, sizeof(ptmp->name)); cptr = skip_not_white(cptr); cptr = skip_white(cptr); /* * command */ if (cptr == NULL) { config_perror("No command specified on line"); } else { /* * Support multi-element commands in shell configuration * lines, but truncate after the first command for 'exec' */ for (tcptr = cptr; *tcptr != 0 && *tcptr != '#'; tcptr++) if (*tcptr == ';' && ptmp->type == EXECPROC) break; sprintf(ptmp->command, "%.*s", (int) (tcptr - cptr), cptr); } #ifdef NETSNMP_EXECFIXCMD sprintf(ptmp->fixcmd, NETSNMP_EXECFIXCMD, ptmp->name); #endif if (ptmp->miblen > 0) { /* * For relocatable "exec" entries, * register the new (not-strictly-valid) MIB subtree... */ register_mib(token, (struct variable *) extensible_relocatable_variables, sizeof(struct variable2), sizeof(extensible_relocatable_variables) / sizeof(*extensible_relocatable_variables), ptmp->miboid, ptmp->miblen); /* * ... and ensure the entries are sorted by OID. * This isn't needed for entries in the main extTable (which * don't have MIB OIDs explicitly associated with them anyway) */ if (scount > 1 && pp != &extens) { int i; struct extensible **etmp = (struct extensible **) malloc(((sizeof(struct extensible *)) * scount)); if (etmp == NULL) return; /* XXX memory alloc error */ for (i = 0, ptmp = *pp; i < scount && ptmp != 0; i++, ptmp = ptmp->next) etmp[i] = ptmp; qsort(etmp, scount, sizeof(struct extensible *), pass_compare); *pp = (struct extensible *) etmp[0]; ptmp = (struct extensible *) etmp[0]; for (i = 0; i < scount - 1; i++) { ptmp->next = etmp[i + 1]; ptmp = ptmp->next; } ptmp->next = NULL; free(etmp); } } }
static void disk_parse_config(const char *token, char *cptr) { #if HAVE_FSTAB_H || HAVE_GETMNTENT || HAVE_STATFS char tmpbuf[1024]; char path[STRMAX]; int minpercent; int minspace; if (numdisks == maxdisks) { if (maxdisks == 0) { maxdisks = 50; disks = malloc(maxdisks * sizeof(struct diskpart)); if (!disks) { config_perror("malloc failed for new disk allocation."); sprintf(tmpbuf, "\tignoring: %s", cptr); tmpbuf[ sizeof(tmpbuf)-1 ] = 0; config_perror(tmpbuf); return; } memset(disks, 0, maxdisks * sizeof(struct diskpart)); } else { maxdisks *= 2; disks = realloc(disks, maxdisks * sizeof(struct diskpart)); if (!disks) { config_perror("malloc failed for new disk allocation."); sprintf(tmpbuf, "\tignoring: %s", cptr); tmpbuf[ sizeof(tmpbuf)-1 ] = 0; config_perror(tmpbuf); return; } memset(disks + maxdisks/2, 0, maxdisks/2 * sizeof(struct diskpart)); } } /* * read disk path (eg, /1 or /usr) */ copy_nword(cptr, path, sizeof(path)); cptr = skip_not_white(cptr); cptr = skip_white(cptr); /* * read optional minimum disk usage spec */ if(cptr != NULL) { if(strchr(cptr, '%') == 0) { minspace = atoi(cptr); minpercent = -1; } else { minspace = -1; minpercent = atoi(cptr); } } else { minspace = NETSNMP_DEFDISKMINIMUMSPACE; minpercent = -1; } /* * check if the disk already exists, if so then modify its * parameters. if it does not exist then add it */ add_device(path, find_device(path), minspace, minpercent, 1); #endif /* HAVE_FSTAB_H || HAVE_GETMNTENT || HAVE_STATFS */ }
int sh_count_procs(char *procname) { char line[STRMAX], *cptr, *cp; int ret = 0, fd; FILE *file; #ifndef NETSNMP_EXCACHETIME #endif struct extensible ex; int slow = strstr(PSCMD, "ax") != NULL; strcpy(ex.command, PSCMD); if ((fd = get_exec_output(&ex)) >= 0) { if ((file = fdopen(fd, "r")) == NULL) { setPerrorstatus("fdopen"); close(fd); return (-1); } while (fgets(line, sizeof(line), file) != NULL) { DEBUGMSGTL(("proc","misc2 Comparing wanted %s against %s\n", procname, line)); if (slow) { cptr = find_field(line, 5); cp = strrchr(cptr, '/'); if (cp) cptr = cp + 1; else if (*cptr == '-') cptr++; else if (*cptr == '[') { cptr++; cp = strchr(cptr, ']'); if (cp) *cp = 0; } copy_nword(cptr, line, sizeof(line)); cp = line + strlen(line) - 1; if (*cp == ':') *cp = 0; } else { if ((cptr = find_field(line, NETSNMP_LASTFIELD)) == NULL) continue; copy_nword(cptr, line, sizeof(line)); } DEBUGMSGTL(("proc","misc2 Comparing wanted %s against %s\n", procname, line)); if (!strcmp(line, procname)) ret++; } if (ftell(file) < 2) { #ifdef USING_UCD_SNMP_ERRORMIB_MODULE seterrorstatus("process list unreasonable short (mem?)", 2); #endif ret = -1; } fclose(file); wait_on_exec(&ex); } else { ret = -1; } return (ret); }
int get_exec_output(struct extensible *ex) { #if HAVE_EXECV int fd[2], i, cnt; char ctmp[STRMAX], *cptr1, *cptr2, argvs[STRMAX], **argv, **aptr; #ifdef EXCACHETIME char cachefile[STRMAX]; char cache[MAXCACHESIZE]; ssize_t cachebytes; long curtime; static char lastcmd[STRMAX]; int cfd; static int lastresult; int readcount; #endif #ifdef EXCACHETIME sprintf(cachefile, "%s/%s", get_persistent_directory(), CACHEFILE); curtime = time(NULL); if (curtime > (cachetime + EXCACHETIME) || strcmp(ex->command, lastcmd) != 0) { strcpy(lastcmd, ex->command); cachetime = curtime; #endif if (pipe(fd)) { setPerrorstatus("pipe"); #ifdef EXCACHETIME cachetime = 0; #endif return -1; } if ((ex->pid = fork()) == 0) { close(1); if (dup(fd[1]) != 1) { setPerrorstatus("dup"); return -1; } /* * write standard output and standard error to pipe. */ /* * close all other file descriptors. */ for (cnt = getdtablesize() - 1; cnt >= 2; --cnt) (void) close(cnt); (void) dup(1); /* stderr */ /* * set standard input to /dev/null */ close(0); (void) open("/dev/null", O_RDWR); for (cnt = 1, cptr1 = ex->command, cptr2 = argvs; cptr1 && *cptr1 != 0; cptr2++, cptr1++) { *cptr2 = *cptr1; if (*cptr1 == ' ') { *(cptr2++) = 0; if ((cptr1 = skip_white(cptr1)) == NULL) break; if (cptr1) { *cptr2 = *cptr1; if (*cptr1 != 0) cnt++; } } } *cptr2 = 0; *(cptr2 + 1) = 0; argv = (char **) malloc((cnt + 2) * sizeof(char *)); if (argv == NULL) return 0; /* memory alloc error */ aptr = argv; *(aptr++) = argvs; for (cptr2 = argvs, i = 1; i != cnt; cptr2++) if (*cptr2 == 0) { *(aptr++) = cptr2 + 1; i++; } while (*cptr2 != 0) cptr2++; *(aptr++) = NULL; copy_nword(ex->command, ctmp, sizeof(ctmp)); execv(ctmp, argv); perror(ctmp); exit(1); } else { close(fd[1]); if (ex->pid < 0) { close(fd[0]); setPerrorstatus("fork"); #ifdef EXCACHETIME cachetime = 0; #endif return -1; } #ifdef EXCACHETIME unlink(cachefile); /* * XXX Use SNMP_FILEMODE_CLOSED instead of 644? */ if ((cfd = open(cachefile, O_WRONLY | O_TRUNC | O_CREAT, 0644)) < 0) { setPerrorstatus(cachefile); cachetime = 0; return -1; } fcntl(fd[0], F_SETFL, O_NONBLOCK); /* don't block on reads */ #ifdef HAVE_USLEEP for (readcount = 0; readcount <= MAXREADCOUNT * 100 && (cachebytes = read(fd[0], (void *) cache, MAXCACHESIZE)); readcount++) { #else for (readcount = 0; readcount <= MAXREADCOUNT && (cachebytes = read(fd[0], (void *) cache, MAXCACHESIZE)); readcount++) { #endif if (cachebytes > 0) write(cfd, (void *) cache, cachebytes); else if (cachebytes == -1 && errno != EAGAIN) { setPerrorstatus("read"); break; } else #ifdef HAVE_USLEEP usleep(10000); /* sleeps for 0.01 sec */ #else sleep(1); #endif } close(cfd); close(fd[0]); /* * wait for the child to finish */ if (ex->pid > 0 && waitpid(ex->pid, &ex->result, 0) < 0) { setPerrorstatus("waitpid()"); cachetime = 0; return -1; } ex->pid = 0; ex->result = WEXITSTATUS(ex->result); lastresult = ex->result; #else /* !EXCACHETIME */ return (fd[0]); #endif } #ifdef EXCACHETIME } else {
void usm_parse_create_usmUser(const char *token, char *line) { char *cp; char buf[SNMP_MAXBUF_MEDIUM]; struct usmUser *newuser; u_char userKey[SNMP_MAXBUF_SMALL], *tmpp; size_t userKeyLen = SNMP_MAXBUF_SMALL; size_t privKeyLen = 0; size_t ret; int ret2; int testcase; newuser = usm_create_user(); /* * READ: Security Name */ cp = copy_nword(line, buf, sizeof(buf)); /* * might be a -e ENGINEID argument */ if (strcmp(buf, "-e") == 0) { size_t ebuf_len = 32, eout_len = 0; u_char *ebuf = (u_char *) malloc(ebuf_len); if (ebuf == NULL) { config_perror("malloc failure processing -e flag"); usm_free_user(newuser); return; } /* * Get the specified engineid from the line. */ cp = copy_nword(cp, buf, sizeof(buf)); if (!snmp_hex_to_binary(&ebuf, &ebuf_len, &eout_len, 1, buf)) { config_perror("invalid EngineID argument to -e"); usm_free_user(newuser); SNMP_FREE(ebuf); return; } newuser->engineID = ebuf; newuser->engineIDLen = eout_len; cp = copy_nword(cp, buf, sizeof(buf)); } else { newuser->engineID = snmpv3_generate_engineID(&ret); if (ret == 0) { usm_free_user(newuser); return; } newuser->engineIDLen = ret; } newuser->secName = strdup(buf); newuser->name = strdup(buf); if (!cp) goto add; /* no authentication or privacy type */ /* * READ: Authentication Type */ #ifndef NETSNMP_DISABLE_MD5 if (strncmp(cp, "MD5", 3) == 0) { memcpy(newuser->authProtocol, usmHMACMD5AuthProtocol, sizeof(usmHMACMD5AuthProtocol)); } else #endif if (strncmp(cp, "SHA", 3) == 0) { memcpy(newuser->authProtocol, usmHMACSHA1AuthProtocol, sizeof(usmHMACSHA1AuthProtocol)); } else { config_perror("Unknown authentication protocol"); usm_free_user(newuser); return; } cp = skip_token(cp); /* * READ: Authentication Pass Phrase or key */ if (!cp) { config_perror("no authentication pass phrase"); usm_free_user(newuser); return; } cp = copy_nword(cp, buf, sizeof(buf)); if (strcmp(buf,"-m") == 0) { /* a master key is specified */ cp = copy_nword(cp, buf, sizeof(buf)); ret = sizeof(userKey); tmpp = userKey; userKeyLen = 0; if (!snmp_hex_to_binary(&tmpp, &ret, &userKeyLen, 0, buf)) { config_perror("invalid key value argument to -m"); usm_free_user(newuser); return; } } else if (strcmp(buf,"-l") != 0) { /* a password is specified */ userKeyLen = sizeof(userKey); ret2 = generate_Ku(newuser->authProtocol, newuser->authProtocolLen, (u_char *) buf, strlen(buf), userKey, &userKeyLen); if (ret2 != SNMPERR_SUCCESS) { config_perror("could not generate the authentication key from the " "supplied pass phrase."); usm_free_user(newuser); return; } } /* * And turn it into a localized key */ ret2 = sc_get_properlength(newuser->authProtocol, newuser->authProtocolLen); if (ret2 <= 0) { config_perror("Could not get proper authentication protocol key length"); return; } newuser->authKey = (u_char *) malloc(ret2); if (strcmp(buf,"-l") == 0) { /* a local key is directly specified */ cp = copy_nword(cp, buf, sizeof(buf)); newuser->authKeyLen = 0; ret = ret2; if (!snmp_hex_to_binary(&newuser->authKey, &ret, &newuser->authKeyLen, 0, buf)) { config_perror("invalid key value argument to -l"); usm_free_user(newuser); return; } if (ret != newuser->authKeyLen) { config_perror("improper key length to -l"); usm_free_user(newuser); return; } } else { newuser->authKeyLen = ret2; ret2 = generate_kul(newuser->authProtocol, newuser->authProtocolLen, newuser->engineID, newuser->engineIDLen, userKey, userKeyLen, newuser->authKey, &newuser->authKeyLen); if (ret2 != SNMPERR_SUCCESS) { config_perror("could not generate localized authentication key " "(Kul) from the master key (Ku)."); usm_free_user(newuser); return; } } if (!cp) goto add; /* no privacy type (which is legal) */ /* * READ: Privacy Type */ testcase = 0; #ifndef NETSNMP_DISABLE_DES if (strncmp(cp, "DES", 3) == 0) { memcpy(newuser->privProtocol, usmDESPrivProtocol, sizeof(usmDESPrivProtocol)); testcase = 1; /* DES uses a 128 bit key, 64 bits of which is a salt */ privKeyLen = 16; } #endif #ifdef HAVE_AES if (strncmp(cp, "AES128", 6) == 0 || strncmp(cp, "AES", 3) == 0) { memcpy(newuser->privProtocol, usmAESPrivProtocol, sizeof(usmAESPrivProtocol)); testcase = 1; privKeyLen = 16; } #endif if (testcase == 0) { config_perror("Unknown privacy protocol"); usm_free_user(newuser); return; } cp = skip_token(cp); /* * READ: Encryption Pass Phrase or key */ if (!cp) { /* * assume the same as the authentication key */ memdup(&newuser->privKey, newuser->authKey, newuser->authKeyLen); newuser->privKeyLen = newuser->authKeyLen; } else { cp = copy_nword(cp, buf, sizeof(buf)); if (strcmp(buf,"-m") == 0) { /* a master key is specified */ cp = copy_nword(cp, buf, sizeof(buf)); ret = sizeof(userKey); tmpp = userKey; userKeyLen = 0; if (!snmp_hex_to_binary(&tmpp, &ret, &userKeyLen, 0, buf)) { config_perror("invalid key value argument to -m"); usm_free_user(newuser); return; } } else if (strcmp(buf,"-l") != 0) { /* a password is specified */ userKeyLen = sizeof(userKey); ret2 = generate_Ku(newuser->authProtocol, newuser->authProtocolLen, (u_char *) buf, strlen(buf), userKey, &userKeyLen); if (ret2 != SNMPERR_SUCCESS) { config_perror("could not generate the privacy key from the " "supplied pass phrase."); usm_free_user(newuser); return; } } /* * And turn it into a localized key */ ret2 = sc_get_properlength(newuser->authProtocol, newuser->authProtocolLen); if (ret2 < 0) { config_perror("could not get proper key length to use for the " "privacy algorithm."); usm_free_user(newuser); return; } newuser->privKey = (u_char *) malloc(ret2); if (strcmp(buf,"-l") == 0) { /* a local key is directly specified */ cp = copy_nword(cp, buf, sizeof(buf)); ret = ret2; newuser->privKeyLen = 0; if (!snmp_hex_to_binary(&newuser->privKey, &ret, &newuser->privKeyLen, 0, buf)) { config_perror("invalid key value argument to -l"); usm_free_user(newuser); return; } } else { newuser->privKeyLen = ret2; ret2 = generate_kul(newuser->authProtocol, newuser->authProtocolLen, newuser->engineID, newuser->engineIDLen, userKey, userKeyLen, newuser->privKey, &newuser->privKeyLen); if (ret2 != SNMPERR_SUCCESS) { config_perror("could not generate localized privacy key " "(Kul) from the master key (Ku)."); usm_free_user(newuser); return; } } } if ((newuser->privKeyLen >= privKeyLen) || (privKeyLen == 0)){ newuser->privKeyLen = privKeyLen; } else { /* The privKey length is smaller than required by privProtocol */ usm_free_user(newuser); return; } add: usm_add_user(newuser); DEBUGMSGTL(("usmUser", "created a new user %s at ", newuser->secName)); DEBUGMSGHEX(("usmUser", newuser->engineID, newuser->engineIDLen)); DEBUGMSG(("usmUser", "\n")); }
netsnmp_session * get_target_sessions(char *taglist, TargetFilterFunction * filterfunct, void *filterArg) { netsnmp_session *ret = NULL, thissess; struct targetAddrTable_struct *targaddrs; char buf[SPRINT_MAX_LEN]; char tags[MAX_TAGS][SPRINT_MAX_LEN], *cp; int numtags = 0, i; static struct targetParamTable_struct *param; DEBUGMSGTL(("target_sessions", "looking for: %s\n", taglist)); for (cp = taglist; cp && numtags < MAX_TAGS;) { cp = copy_nword(cp, tags[numtags], sizeof(tags[numtags])); DEBUGMSGTL(("target_sessions", " for: %d=%s\n", numtags, tags[numtags])); numtags++; } for (targaddrs = get_addrTable(); targaddrs; targaddrs = targaddrs->next) { /* * legal row? */ if (targaddrs->tDomain == NULL || targaddrs->tAddress == NULL || targaddrs->rowStatus != SNMP_ROW_ACTIVE) { DEBUGMSGTL(("target_sessions", " which is not ready yet\n")); continue; } if (netsnmp_tdomain_support (targaddrs->tDomain, targaddrs->tDomainLen, NULL, NULL) == 0) { snmp_log(LOG_ERR, "unsupported domain for target address table entry %s\n", targaddrs->name); } /* * check tag list to see if we match */ if (targaddrs->tagList) { /* * loop through tag list looking for requested tags */ for (cp = targaddrs->tagList; cp;) { cp = copy_nword(cp, buf, sizeof(buf)); for (i = 0; i < numtags; i++) { if (strcmp(buf, tags[i]) == 0) { /* * found a valid target table entry */ DEBUGMSGTL(("target_sessions", "found one: %s\n", tags[i])); if (targaddrs->params) { param = get_paramEntry(targaddrs->params); if (!param || param->rowStatus != SNMP_ROW_ACTIVE) { /* * parameter entry must exist and be active */ continue; } } else { /* * parameter entry must be specified */ continue; } /* * last chance for caller to opt-out. Call * filtering function */ if (filterfunct && (*(filterfunct)) (targaddrs, param, filterArg)) { continue; } if (targaddrs->storageType != ST_READONLY && targaddrs->sess && param->updateTime >= targaddrs->sessionCreationTime) { /* * parameters have changed, nuke the old session */ snmp_close(targaddrs->sess); targaddrs->sess = NULL; } /* * target session already exists? */ if (targaddrs->sess == NULL) { /* * create an appropriate snmp session and add * it to our return list */ netsnmp_transport *t = NULL; t = netsnmp_tdomain_transport_oid(targaddrs-> tDomain, targaddrs-> tDomainLen, targaddrs-> tAddress, targaddrs-> tAddressLen, 0); if (t == NULL) { DEBUGMSGTL(("target_sessions", "bad dest \"")); DEBUGMSGOID(("target_sessions", targaddrs->tDomain, targaddrs->tDomainLen)); DEBUGMSG(("target_sessions", "\", \"")); DEBUGMSGHEX(("target_sessions", targaddrs->tAddress, targaddrs->tAddressLen)); DEBUGMSG(("target_sessions", "\n")); continue; } else { char *dst_str = t->f_fmtaddr(t, NULL, 0); if (dst_str != NULL) { DEBUGMSGTL(("target_sessions", " to: %s\n", dst_str)); free(dst_str); } } memset(&thissess, 0, sizeof(thissess)); thissess.timeout = (targaddrs->timeout) * 1000; thissess.retries = targaddrs->retryCount; DEBUGMSGTL(("target_sessions", "timeout: %d -> %d\n", targaddrs->timeout, thissess.timeout)); if (param->mpModel == SNMP_VERSION_3 && param->secModel != 3) { snmp_log(LOG_ERR, "unsupported model/secmodel combo for target %s\n", targaddrs->name); /* * XXX: memleak */ netsnmp_transport_free(t); continue; } thissess.version = param->mpModel; if (param->mpModel == SNMP_VERSION_3) { thissess.securityName = param->secName; thissess.securityNameLen = strlen(thissess.securityName); thissess.securityLevel = param->secLevel; #if !defined(DISABLE_SNMPV1) || !defined(DISABLE_SNMPV2C) } else { thissess.community = (u_char *) strdup(param->secName); thissess.community_len = strlen((char *) thissess.community); #endif } targaddrs->sess = snmp_add(&thissess, t, NULL, NULL); targaddrs->sessionCreationTime = time(NULL); } if (targaddrs->sess) { if (ret) { targaddrs->sess->next = ret; } ret = targaddrs->sess; } else { snmp_sess_perror("target session", &thissess); } } } } } } return ret; }
netsnmp_session *get_target_sessions (char *taglist, TargetFilterFunction * filterfunct, void *filterArg) { netsnmp_session *ret = NULL, thissess; struct targetAddrTable_struct *targaddrs; char buf[SPRINT_MAX_LEN]; char tags[MAX_TAGS][SPRINT_MAX_LEN], *cp; int numtags = 0, i; #if defined(NETSNMP_TRANSPORT_DTLSUDP_DOMAIN) || defined(NETSNMP_TRANSPORT_TLSTCP_DOMAIN) int tls = 0; #endif static struct targetParamTable_struct *param; DEBUGMSGTL (("target_sessions", "looking for: %s\n", taglist)); for (cp = taglist; cp && numtags < MAX_TAGS;) { cp = copy_nword (cp, tags[numtags], sizeof (tags[numtags])); DEBUGMSGTL (("target_sessions", " for: %d=%s\n", numtags, tags[numtags])); numtags++; } for (targaddrs = get_addrTable (); targaddrs; targaddrs = targaddrs->next) { /* * legal row? */ if (targaddrs->tDomain == NULL || targaddrs->tAddress == NULL || targaddrs->rowStatus != SNMP_ROW_ACTIVE) { DEBUGMSGTL (("target_sessions", " which is not ready yet\n")); continue; } if (netsnmp_tdomain_support (targaddrs->tDomain, targaddrs->tDomainLen, NULL, NULL) == 0) { snmp_log (LOG_ERR, "unsupported domain for target address table entry %s\n", targaddrs->name); } /* * check tag list to see if we match */ if (targaddrs->tagList) { int matched = 0; /* * loop through tag list looking for requested tags */ for (cp = targaddrs->tagList; cp && !matched;) { cp = copy_nword (cp, buf, sizeof (buf)); for (i = 0; i < numtags && !matched; i++) { if (strcmp (buf, tags[i]) == 0) { /* * found a valid target table entry */ DEBUGMSGTL (("target_sessions", "found one: %s\n", tags[i])); if (targaddrs->params) { param = get_paramEntry (targaddrs->params); if (!param || param->rowStatus != SNMP_ROW_ACTIVE) { /* * parameter entry must exist and be active */ continue; } } else { /* * parameter entry must be specified */ continue; } /* * last chance for caller to opt-out. Call * filtering function */ if (filterfunct && (*(filterfunct)) (targaddrs, param, filterArg)) { continue; } /* * Only one notification per TargetAddrEntry, * rather than one per tag */ matched = 1; if (targaddrs->storageType != ST_READONLY && targaddrs->sess && param->updateTime >= targaddrs->sessionCreationTime) { /* * parameters have changed, nuke the old session */ snmp_close (targaddrs->sess); targaddrs->sess = NULL; } /* * target session already exists? */ if (targaddrs->sess == NULL) { /* * create an appropriate snmp session and add * it to our return list */ netsnmp_transport *t = NULL; t = netsnmp_tdomain_transport_oid (targaddrs->tDomain, targaddrs->tDomainLen, targaddrs->tAddress, targaddrs->tAddressLen, 0); if (t == NULL) { DEBUGMSGTL (("target_sessions", "bad dest \"")); DEBUGMSGOID (("target_sessions", targaddrs->tDomain, targaddrs->tDomainLen)); DEBUGMSG (("target_sessions", "\", \"")); DEBUGMSGHEX (("target_sessions", targaddrs->tAddress, targaddrs->tAddressLen)); DEBUGMSG (("target_sessions", "\n")); continue; } else { char *dst_str = t->f_fmtaddr (t, NULL, 0); if (dst_str != NULL) { DEBUGMSGTL (("target_sessions", " to: %s\n", dst_str)); free (dst_str); } } /* * if tDomain is tls related, check for tls config */ #ifdef NETSNMP_TRANSPORT_DTLSUDP_DOMAIN tls = snmp_oid_compare (targaddrs->tDomain, targaddrs->tDomainLen, netsnmpDTLSUDPDomain, netsnmpDTLSUDPDomain_len); #endif #ifdef NETSNMP_TRANSPORT_TLSTCP_DOMAIN if (tls) tls = snmp_oid_compare (targaddrs->tDomain, targaddrs->tDomainLen, netsnmpTLSTCPDomain, netsnmpTLSTCPDomain_len); #endif #if defined(NETSNMP_TRANSPORT_DTLSUDP_DOMAIN) || defined(NETSNMP_TRANSPORT_TLSTCP_DOMAIN) if (!tls) { netsnmp_cert *cert; char *server_id = NULL; DEBUGMSGTL (("target_sessions", " looking up our id: %s\n", targaddrs->params)); cert = netsnmp_cert_find (NS_CERT_IDENTITY, NS_CERTKEY_TARGET_PARAM, targaddrs->params); netsnmp_assert (t->f_config); if (cert) { DEBUGMSGTL (("target_sessions", " found fingerprint: %s\n", cert->fingerprint)); t->f_config (t, "localCert", cert->fingerprint); } DEBUGMSGTL (("target_sessions", " looking up their id: %s\n", targaddrs->name)); cert = netsnmp_cert_find (NS_CERT_REMOTE_PEER, NS_CERTKEY_TARGET_ADDR, targaddrs->name); if (cert) { DEBUGMSGTL (("target_sessions", " found fingerprint: %s\n", cert->fingerprint)); t->f_config (t, "peerCert", cert->fingerprint); } #ifndef NETSNMP_FEATURE_REMOVE_TLSTMADDR_GET_SERVERID server_id = netsnmp_tlstmAddr_get_serverId (targaddrs->name); #endif /* NETSNMP_FEATURE_REMOVE_TLSTMADDR_GET_SERVERID */ if (server_id) { DEBUGMSGTL (("target_sessions", " found serverId: %s\n", server_id)); t->f_config (t, "their_hostname", server_id); } } #endif memset (&thissess, 0, sizeof (thissess)); thissess.timeout = (targaddrs->timeout) * 1000; thissess.retries = targaddrs->retryCount; DEBUGMSGTL (("target_sessions", "timeout: %d -> %ld\n", targaddrs->timeout, thissess.timeout)); if (param->mpModel == SNMP_VERSION_3 && param->secModel != SNMP_SEC_MODEL_USM && param->secModel != SNMP_SEC_MODEL_TSM) { snmp_log (LOG_ERR, "unsupported mpModel/secModel combo %d/%d for target %s\n", param->mpModel, param->secModel, targaddrs->name); /* * XXX: memleak */ netsnmp_transport_free (t); continue; } thissess.paramName = strdup (param->paramName); thissess.version = param->mpModel; if (param->mpModel == SNMP_VERSION_3) { thissess.securityName = strdup (param->secName); thissess.securityNameLen = strlen (thissess.securityName); thissess.securityLevel = param->secLevel; thissess.securityModel = param->secModel; #if !defined(NETSNMP_DISABLE_SNMPV1) || !defined(NETSNMP_DISABLE_SNMPV2C) } else { thissess.community = (u_char *) strdup (param->secName); thissess.community_len = strlen ((char *) thissess.community); #endif } thissess.flags |= SNMP_FLAGS_DONT_PROBE; targaddrs->sess = snmp_add (&thissess, t, NULL, NULL); thissess.flags &= ~SNMP_FLAGS_DONT_PROBE; targaddrs->sessionCreationTime = time (NULL); } if (targaddrs->sess) { if (NULL == targaddrs->sess->paramName) targaddrs->sess->paramName = strdup (param->paramName); targaddrs->sess->next = ret; ret = targaddrs->sess; } else { snmp_sess_perror ("target session", &thissess); } } } } } } return ret; }
void snmptrapd_parse_traphandle(const char *token, char *line) { char buf[STRINGMAX]; oid obuf[MAX_OID_LEN]; size_t olen = MAX_OID_LEN; char *cptr, *cp; netsnmp_trapd_handler *traph; int flags = 0; char *format = NULL; memset( buf, 0, sizeof(buf)); memset(obuf, 0, sizeof(obuf)); cptr = copy_nword(line, buf, sizeof(buf)); if ( buf[0] == '-' && buf[1] == 'F' ) { cptr = copy_nword(cptr, buf, sizeof(buf)); format = strdup( buf ); cptr = copy_nword(cptr, buf, sizeof(buf)); } if ( !cptr ) { netsnmp_config_error("Missing traphandle command (%s)", buf); return; } DEBUGMSGTL(("read_config:traphandle", "registering handler for: ")); if (!strcmp(buf, "default")) { DEBUGMSG(("read_config:traphandle", "default")); traph = netsnmp_add_global_traphandler(NETSNMPTRAPD_DEFAULT_HANDLER, command_handler ); } else { cp = buf+strlen(buf)-1; if ( *cp == '*' ) { flags |= NETSNMP_TRAPHANDLER_FLAG_MATCH_TREE; *(cp--) = '\0'; if ( *cp == '.' ) { /* * Distinguish between 'oid.*' & 'oid*' */ flags |= NETSNMP_TRAPHANDLER_FLAG_STRICT_SUBTREE; *(cp--) = '\0'; } } if (!read_objid(buf, obuf, &olen)) { netsnmp_config_error("Bad trap OID in traphandle directive: %s", buf); return; } DEBUGMSGOID(("read_config:traphandle", obuf, olen)); traph = netsnmp_add_traphandler( command_handler, obuf, olen ); } DEBUGMSG(("read_config:traphandle", "\n")); if (traph) { traph->flags = flags; traph->authtypes = TRAP_AUTH_EXE; traph->token = strdup(cptr); if (format) traph->format = format; } }
do { \ ++__test_counter; \ if ((cond)) \ printf("ok %d\n", __test_counter); \ else { \ printf("not ok %d - %d: %s failed, ", \ __test_counter, __LINE__, #cond); \ printf on_error ; \ } \ } while (0) { /* A quoted string */ char input[] = "\"The red rose\""; char output[sizeof(input)] = ""; char* run = copy_nword(input, output, sizeof(output)); ASSERT2(strcmp(output, "The red rose") == 0, ("output = >%s<\n", output)); ASSERT1(run == NULL); } { /* Escaped quotes */ char input[] = "\\\"The red rose\\\""; char output[sizeof(input)] = ""; char* run = copy_nword(input, output, sizeof(output)); ASSERT2(strcmp(output, "\"The") == 0, ("output = >%s<\n", output)); ASSERT2(run == input + 6, ("run = input + %d\n", (int)(run - input))); run = copy_nword(run, output, sizeof(output)); ASSERT2(strcmp(output, "red") == 0, ("output = >%s<\n", output)); ASSERT2(run == input + 10, ("run = input + %d\n", (int)(run - input)));
void snmpd_parse_config_trapsess(const char *word, char *cptr) { char *argv[MAX_ARGS], *cp = cptr, tmp[SPRINT_MAX_LEN]; int argn, arg; netsnmp_session session, *ss; size_t len; /* * inform or trap? default to trap */ traptype = SNMP_MSG_TRAP2; /* * create the argv[] like array */ argv[0] = strdup("snmpd-trapsess"); /* bogus entry for getopt() */ for (argn = 1; cp && argn < MAX_ARGS; argn++) { cp = copy_nword(cp, tmp, SPRINT_MAX_LEN); argv[argn] = strdup(tmp); } arg = snmp_parse_args(argn, argv, &session, "C:", trapOptProc); ss = snmp_add(&session, netsnmp_transport_open_client("snmptrap", session.peername), NULL, NULL); for (; argn > 0; argn--) { free(argv[argn - 1]); } if (!ss) { config_perror ("snmpd: failed to parse this line or the remote trap receiver is down. Possible cause:"); snmp_sess_perror("snmpd: snmpd_parse_config_trapsess()", &session); return; } /* * If this is an SNMPv3 TRAP session, then the agent is * the authoritative engine, so set the engineID accordingly */ if (ss->version == SNMP_VERSION_3 && traptype != SNMP_MSG_INFORM && ss->securityEngineIDLen == 0) { len = snmpv3_get_engineID( tmp, sizeof(tmp)); memdup(&ss->securityEngineID, tmp, len); ss->securityEngineIDLen = len; } #ifndef NETSNMP_DISABLE_SNMPV1 if (ss->version == SNMP_VERSION_1) { add_trap_session(ss, SNMP_MSG_TRAP, 0, SNMP_VERSION_1); } else { #endif add_trap_session(ss, traptype, (traptype == SNMP_MSG_INFORM), ss->version); #ifndef NETSNMP_DISABLE_SNMPV1 } #endif }
void proxy_parse_config(const char *token, char *line) { /* * proxy args [base-oid] [remap-to-remote-oid] */ netsnmp_session session, *ss; struct simple_proxy *newp, **listpp; char args[MAX_ARGS][SPRINT_MAX_LEN], *argv[MAX_ARGS]; int argn, arg; char *cp; netsnmp_handler_registration *reg; context_string = NULL; DEBUGMSGTL(("proxy_config", "entering\n")); /* * create the argv[] like array */ strcpy(argv[0] = args[0], "snmpd-proxy"); /* bogus entry for getopt() */ for (argn = 1, cp = line; cp && argn < MAX_ARGS;) { argv[argn] = args[argn]; cp = copy_nword(cp, argv[argn], SPRINT_MAX_LEN); argn++; } for (arg = 0; arg < argn; arg++) { DEBUGMSGTL(("proxy_args", "final args: %d = %s\n", arg, argv[arg])); } DEBUGMSGTL(("proxy_config", "parsing args: %d\n", argn)); /* Call special parse_args that allows for no specified community string */ arg = snmp_parse_args(argn, argv, &session, "C:", proxyOptProc); /* reset this in case we modified it */ netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_IGNORE_NO_COMMUNITY, 0); if (arg < 0) { config_perror("failed to parse proxy args"); return; } DEBUGMSGTL(("proxy_config", "done parsing args\n")); if (arg >= argn) { config_perror("missing base oid"); return; } /* * usm_set_reportErrorOnUnknownID(0); * * hack, stupid v3 ASIs. */ /* * XXX: on a side note, we don't really need to be a reference * platform any more so the proper thing to do would be to fix * snmplib/snmpusm.c to pass in the pdu type to usm_process_incoming * so this isn't needed. */ ss = snmp_open(&session); /* * usm_set_reportErrorOnUnknownID(1); */ if (ss == NULL) { /* * diagnose snmp_open errors with the input netsnmp_session pointer */ snmp_sess_perror("snmpget", &session); SOCK_CLEANUP; return; } newp = (struct simple_proxy *) calloc(1, sizeof(struct simple_proxy)); newp->sess = ss; DEBUGMSGTL(("proxy_init", "name = %s\n", args[arg])); newp->name_len = MAX_OID_LEN; if (!snmp_parse_oid(args[arg++], newp->name, &newp->name_len)) { snmp_perror("proxy"); config_perror("illegal proxy oid specified\n"); return; } if (arg < argn) { DEBUGMSGTL(("proxy_init", "base = %s\n", args[arg])); newp->base_len = MAX_OID_LEN; if (!snmp_parse_oid(args[arg++], newp->base, &newp->base_len)) { snmp_perror("proxy"); config_perror("illegal variable name specified (base oid)\n"); return; } } if ( context_string ) newp->context = strdup(context_string); DEBUGMSGTL(("proxy_init", "registering at: ")); DEBUGMSGOID(("proxy_init", newp->name, newp->name_len)); DEBUGMSG(("proxy_init", "\n")); /* * add to our chain */ /* * must be sorted! */ listpp = &proxies; while (*listpp && snmp_oid_compare(newp->name, newp->name_len, (*listpp)->name, (*listpp)->name_len) > 0) { listpp = &((*listpp)->next); } /* * listpp should be next in line from us. */ if (*listpp) { /* * make our next in the link point to the current link */ newp->next = *listpp; } /* * replace current link with us */ *listpp = newp; reg = netsnmp_create_handler_registration("proxy", proxy_handler, newp->name, newp->name_len, HANDLER_CAN_RWRITE); reg->handler->myvoid = newp; if (context_string) reg->contextName = strdup(context_string); netsnmp_register_handler(reg); }
void parse_expression(const char *token, char *line) { char buf[ SPRINT_MAX_LEN]; char ename[EXP_STR1_LEN+1]; oid name_buf[MAX_OID_LEN]; size_t name_len; char *cp, *cp2; struct expExpression *entry; struct expObject *object; netsnmp_session *sess = NULL; int type=EXPVALTYPE_COUNTER; int i=1; DEBUGMSGTL(("disman:expr:conf", "Parsing expression config... ")); memset(buf, 0, sizeof(buf)); memset(ename, 0, sizeof(ename)); for (cp = copy_nword(line, buf, SPRINT_MAX_LEN); ; cp = copy_nword(cp, buf, SPRINT_MAX_LEN)) { if (buf[0] == '-' ) { switch (buf[1]) { case 't': /* type */ switch (buf[2]) { case 'c': type = EXPVALTYPE_COUNTER; break; case 'u': type = EXPVALTYPE_UNSIGNED; break; case 't': type = EXPVALTYPE_TIMETICKS; break; case 'i': type = EXPVALTYPE_INTEGER; break; case 'a': type = EXPVALTYPE_IPADDRESS; break; case 's': type = EXPVALTYPE_STRING; break; case 'o': type = EXPVALTYPE_OID; break; case 'C': type = EXPVALTYPE_COUNTER64; break; } break; case 'u': /* user */ cp = copy_nword(cp, buf, SPRINT_MAX_LEN); sess = netsnmp_iquery_user_session(buf); break; } } else { break; } } memcpy(ename, buf, sizeof(ename)); /* cp = copy_nword(line, ename, sizeof(ename)); */ entry = expExpression_createEntry( "snmpd.conf", ename, 1 ); if (!entry) return; cp2 = entry->expExpression; while (cp && *cp) { /* * Copy everything that can't possibly be a MIB * object name into the expression field... */ /* XXX - TODO - Handle string literals */ if (!isalpha(*cp)) { *cp2++ = *cp++; continue; } /* * ... and copy the defined functions across as well * XXX - TODO */ /* * Anything else is presumably a MIB object (or instance). * Create an entry in the expObjectTable, and insert a * corresponding parameter in the expression itself. */ name_len = MAX_OID_LEN; cp = copy_nword(cp, buf, SPRINT_MAX_LEN); snmp_parse_oid( buf, name_buf, &name_len ); object = expObject_createEntry( "snmpd.conf", ename, i, 1 ); memcpy( object->expObjectID, name_buf, name_len*sizeof(oid)); object->expObjectID_len = name_len; object->flags |= EXP_OBJ_FLAG_VALID | EXP_OBJ_FLAG_ACTIVE | EXP_OBJ_FLAG_OWILD; /* * The first such object can also be used as the * expExpressionPrefix */ if ( i == 1 ) { memcpy( entry->expPrefix, name_buf, name_len*sizeof(oid)); entry->expPrefix_len = name_len; object->flags |= EXP_OBJ_FLAG_PREFIX; } sprintf(cp2, "$%d", i++); while (*cp2) cp2++; /* Skip over this parameter */ } if (sess) entry->session = sess; else entry->session = netsnmp_query_get_default_session(); entry->expDeltaInterval = 10; entry->expValueType = type; entry->flags |= EXP_FLAG_VALID | EXP_FLAG_ACTIVE; expExpression_enable( entry ); DEBUGMSG(("disman:expr:conf", "(%s, %s)\n", ename, entry->expExpression)); }
void parse_setEvent( const char *token, char *line ) { char ename[MTE_STR1_LEN+1]; char buf[SPRINT_MAX_LEN]; oid name_buf[MAX_OID_LEN]; size_t name_buf_len; long value; int wild = 1; struct mteEvent *entry; char *cp; DEBUGMSGTL(("disman:event:conf", "Parsing setEvent config... ")); memset( ename, 0, sizeof(ename)); cp = copy_nword(line, ename, MTE_STR1_LEN); if (!cp || ename[0] == '\0') { config_perror("syntax error: no event name"); return; } if (cp && *cp=='-' && *(cp+1)=='I') { wild = 0; /* an instance assignment */ cp = skip_token( cp ); } /* * Parse the SET assignment in the form "OID = value" */ cp = copy_nword(cp, buf, SPRINT_MAX_LEN); if ( buf[0] == '\0' ) { config_perror("syntax error: no set OID"); return; } name_buf_len = MAX_OID_LEN; if (!snmp_parse_oid(buf, name_buf, &name_buf_len)) { snmp_log(LOG_ERR, "setEvent OID: %s\n", buf); config_perror("unknown set OID"); return; } if (cp && *cp == '=') { cp = skip_token( cp ); /* skip the '=' assignment character */ } value = strtol( cp, NULL, 0); /* * If the entry has parsed successfully, then create, * populate and activate the new event entry. */ entry = _find_typed_mteEvent_entry("snmpd.conf", ename, MTE_EVENT_SET); if (!entry) { return; } memcpy( entry->mteSetOID, name_buf, name_buf_len*sizeof(oid)); entry->mteSetOID_len = name_buf_len; entry->mteSetValue = value; if (wild) entry->flags |= MTE_SET_FLAG_OBJWILD; entry->mteEventActions |= MTE_EVENT_SET; entry->flags |= MTE_EVENT_FLAG_ENABLED | MTE_EVENT_FLAG_ACTIVE | MTE_EVENT_FLAG_FIXED | MTE_EVENT_FLAG_VALID; return; }
void parse_notificationEvent( const char *token, char *line ) { char ename[MTE_STR1_LEN+1]; char buf[SPRINT_MAX_LEN]; oid name_buf[MAX_OID_LEN]; size_t name_buf_len; struct mteEvent *entry; struct mteObject *object; int wild = 1; int idx = 0; char *cp; #ifndef NETSNMP_DISABLE_MIB_LOADING struct tree *tp; #endif struct varbind_list *var; DEBUGMSGTL(("disman:event:conf", "Parsing notificationEvent config\n")); /* * The event name could be used directly to index the mteObjectsTable. * But it's quite possible that the same name could also be used to * set up a mteTriggerTable entry (with trigger-specific objects). * * To avoid such a clash, we'll add a prefix ("_E"). */ memset(ename, 0, sizeof(ename)); ename[0] = '_'; ename[1] = 'E'; cp = copy_nword(line, ename+2, MTE_STR1_LEN-2); if (!cp || ename[2] == '\0') { config_perror("syntax error: no event name"); return; } /* * Parse the notification OID field ... */ cp = copy_nword(cp, buf, SPRINT_MAX_LEN); if ( buf[0] == '\0' ) { config_perror("syntax error: no notification OID"); return; } name_buf_len = MAX_OID_LEN; if (!snmp_parse_oid(buf, name_buf, &name_buf_len)) { snmp_log(LOG_ERR, "notificationEvent OID: %s\n", buf); config_perror("unknown notification OID"); return; } /* * ... and the relevant object/instances. */ if ( cp && *cp=='-' && *(cp+1)=='m' ) { #ifdef NETSNMP_DISABLE_MIB_LOADING config_perror("Can't use -m if MIB loading is disabled"); return; #else /* * Use the MIB definition to add the standard * notification payload to the mteObjectsTable. */ cp = skip_token( cp ); tp = get_tree( name_buf, name_buf_len, get_tree_head()); if (!tp) { config_perror("Can't locate notification payload info"); return; } for (var = tp->varbinds; var; var=var->next) { idx++; object = mteObjects_addOID( "snmpd.conf", ename, idx, var->vblabel, wild ); idx = object->mteOIndex; } #endif } while (cp) { if ( *cp == '-' ) { switch (*(cp+1)) { case 'm': config_perror("-m option must come first"); return; case 'i': /* exact instance */ case 'w': /* "not-wild" (backward compatability) */ wild = 0; break; case 'o': /* wildcarded object */ wild = 1; break; default: config_perror("unrecognised option"); return; } cp = skip_token( cp ); if (!cp) { config_perror("missing parameter"); return; } } idx++; cp = copy_nword(cp, buf, SPRINT_MAX_LEN); object = mteObjects_addOID( "snmpd.conf", ename, idx, buf, wild ); idx = object->mteOIndex; wild = 1; /* default to wildcarded objects */ } /* * If the entry has parsed successfully, then create, * populate and activate the new event entry. */ entry = _find_typed_mteEvent_entry("snmpd.conf", ename+2, MTE_EVENT_NOTIFICATION); if (!entry) { mteObjects_removeEntries( "snmpd.conf", ename ); return; } entry->mteNotification_len = name_buf_len; memcpy( entry->mteNotification, name_buf, name_buf_len*sizeof(oid)); memcpy( entry->mteNotifyOwner, "snmpd.conf", 10 ); memcpy( entry->mteNotifyObjects, ename, MTE_STR1_LEN ); entry->mteEventActions |= MTE_EVENT_NOTIFICATION; entry->flags |= MTE_EVENT_FLAG_ENABLED | MTE_EVENT_FLAG_ACTIVE | MTE_EVENT_FLAG_FIXED | MTE_EVENT_FLAG_VALID; return; }
void netsnmp_parse_override(const char *token, char *line) { char *cp; char buf[SNMP_MAXBUF], namebuf[SNMP_MAXBUF]; int readwrite = 0; oid oidbuf[MAX_OID_LEN]; size_t oidbuf_len = MAX_OID_LEN; int type; override_data *thedata; netsnmp_handler_registration *the_reg; cp = copy_nword(line, namebuf, sizeof(namebuf) - 1); if (strcmp(namebuf, "-rw") == 0) { readwrite = 1; cp = copy_nword(cp, namebuf, sizeof(namebuf) - 1); } if (!cp) { config_perror("no oid specified"); return; } if (!snmp_parse_oid(namebuf, oidbuf, &oidbuf_len)) { config_perror("illegal oid"); return; } cp = copy_nword(cp, buf, sizeof(buf) - 1); if (!cp && strcmp(buf, "null") != 0) { config_perror("no variable value specified"); return; } { struct { const char* key; int value; } const strings[] = { { "counter", ASN_COUNTER }, { "counter64", ASN_COUNTER64 }, { "integer", ASN_INTEGER }, { "ipaddress", ASN_IPADDRESS }, { "nsap", ASN_NSAP }, { "null", ASN_NULL }, { "object_id", ASN_OBJECT_ID }, { "octet_str", ASN_OCTET_STR }, { "opaque", ASN_OPAQUE }, #ifdef NETSNMP_WITH_OPAQUE_SPECIAL_TYPES { "opaque_counter64", ASN_OPAQUE_COUNTER64 }, { "opaque_double", ASN_OPAQUE_DOUBLE }, { "opaque_float", ASN_OPAQUE_FLOAT }, { "opaque_i64", ASN_OPAQUE_I64 }, { "opaque_u64", ASN_OPAQUE_U64 }, #endif { "timeticks", ASN_TIMETICKS }, { "uinteger", ASN_GAUGE }, { "unsigned", ASN_UNSIGNED }, { NULL, 0 } }, * run; for(run = strings; run->key && strcasecmp(run->key, buf) < 0; ++run); if(run->key && strcasecmp(run->key, buf) == 0) type = run->value; else { config_perror("unknown type specified"); return; } } if (cp) copy_nword(cp, buf, sizeof(buf) - 1); else buf[0] = 0; thedata = SNMP_MALLOC_TYPEDEF(override_data); if (!thedata) { config_perror("memory allocation failure"); return; } thedata->type = type; switch (type) { case ASN_INTEGER: MALLOC_OR_DIE(sizeof(long)); *((long *) thedata->value) = strtol(buf, NULL, 0); break; case ASN_COUNTER: case ASN_TIMETICKS: case ASN_UNSIGNED: MALLOC_OR_DIE(sizeof(u_long)); *((u_long *) thedata->value) = strtoul(buf, NULL, 0); break; case ASN_OCTET_STR: case ASN_BIT_STR: if (buf[0] == '0' && buf[1] == 'x') { /* * hex */ thedata->value_len = hex_to_binary2((u_char *)(buf + 2), strlen(buf) - 2, (char **) &thedata->value); } else { thedata->value = strdup(buf); thedata->value_len = strlen(buf); } break; case ASN_OBJECT_ID: read_config_read_objid(buf, (oid **) & thedata->value, &thedata->value_len); break; case ASN_NULL: thedata->value_len = 0; break; default: SNMP_FREE(thedata); config_perror("illegal/unsupported type specified"); return; } if (!thedata->value && thedata->type != ASN_NULL) { config_perror("memory allocation failure"); free(thedata); return; } the_reg = SNMP_MALLOC_TYPEDEF(netsnmp_handler_registration); if (!the_reg) { config_perror("memory allocation failure"); free(thedata); return; } the_reg->handlerName = strdup(namebuf); the_reg->priority = 255; the_reg->modes = (readwrite) ? HANDLER_CAN_RWRITE : HANDLER_CAN_RONLY; the_reg->handler = netsnmp_create_handler("override", override_handler); the_reg->rootoid = snmp_duplicate_objid(oidbuf, oidbuf_len); the_reg->rootoid_len = oidbuf_len; if (!the_reg->rootoid || !the_reg->handler || !the_reg->handlerName) { if (the_reg->handler) SNMP_FREE(the_reg->handler->handler_name); SNMP_FREE(the_reg->handler); SNMP_FREE(the_reg->handlerName); SNMP_FREE(the_reg); config_perror("memory allocation failure"); free(thedata); return; } the_reg->handler->myvoid = thedata; if (netsnmp_register_instance(the_reg)) { config_perror("oid registration failed within the agent"); SNMP_FREE(thedata->value); free(thedata); return; } }
void parse_notificationEvent(const char *token, char *line) { char name_buf[64]; char oid_name_buf[SPRINT_MAX_LEN]; oid oid_buf[MAX_OID_LEN]; size_t oid_buf_len = MAX_OID_LEN; int wild = 1; netsnmp_table_row *row; long tlong; char tc; /* get the owner */ const char *owner = "snmpd.conf"; /* get the name */ char *cp = copy_nword(line, name_buf, SPRINT_MAX_LEN); if (!cp || name_buf[0] == '\0') { config_perror("syntax error."); return; } for(row = table_set->table->first_row; row; row = row->next) { if (strcmp(row->indexes->val.string, owner) == 0 && strcmp(row->indexes->next_variable->val.string, name_buf) == 0) { config_perror("An eventd by that name has already been defined."); return; } } /* now, get all the trap oid */ cp = copy_nword(cp, oid_name_buf, SPRINT_MAX_LEN); if (oid_name_buf[0] == '\0') { config_perror("syntax error."); return; } if (!snmp_parse_oid(oid_name_buf, oid_buf, &oid_buf_len)) { snmp_log(LOG_ERR,"namebuf: %s\n",oid_name_buf); config_perror("unable to parse trap oid"); return; } /* * add to the mteEventNotificationtable to point to the * notification and the objects. */ row = netsnmp_create_table_data_row(); /* indexes */ netsnmp_table_row_add_index(row, ASN_OCTET_STR, owner, strlen(owner)); netsnmp_table_row_add_index(row, ASN_PRIV_IMPLIED_OCTET_STR, name_buf, strlen(name_buf)); /* columns */ netsnmp_set_row_column(row, COLUMN_MTEEVENTNOTIFICATION, ASN_OBJECT_ID, (char *) oid_buf, oid_buf_len * sizeof(oid)); netsnmp_set_row_column(row, COLUMN_MTEEVENTNOTIFICATIONOBJECTSOWNER, ASN_OCTET_STR, owner, strlen(owner)); netsnmp_set_row_column(row, COLUMN_MTEEVENTNOTIFICATIONOBJECTS, ASN_OCTET_STR, name_buf, strlen(name_buf)); netsnmp_table_data_add_row(mteEventNotif_table_set->table, row); /* * add to the mteEventTable to make it a notification to trigger * notification and the objects. */ row = netsnmp_create_table_data_row(); /* indexes */ netsnmp_table_row_add_index(row, ASN_OCTET_STR, owner, strlen(owner)); netsnmp_table_row_add_index(row, ASN_PRIV_IMPLIED_OCTET_STR, name_buf, strlen(name_buf)); /* columns */ tc = (u_char)0x80; netsnmp_set_row_column(row, COLUMN_MTEEVENTACTIONS, ASN_OCTET_STR, &tc, 1); tlong = MTETRIGGERENABLED_TRUE; netsnmp_set_row_column(row, COLUMN_MTEEVENTENABLED, ASN_INTEGER, (char *) &tlong, sizeof(tlong)); tlong = RS_ACTIVE; netsnmp_set_row_column(row, COLUMN_MTEEVENTENTRYSTATUS, ASN_INTEGER, (char *) &tlong, sizeof(tlong)); netsnmp_table_data_add_row(table_set->table, row); /* * now all the objects to put into the trap's object row */ while(cp) { cp = copy_nword(cp, oid_name_buf, SPRINT_MAX_LEN); if (strcmp(oid_name_buf, "-w") == 0) { wild = 0; continue; } oid_buf_len = MAX_OID_LEN; if (!snmp_parse_oid(oid_name_buf, oid_buf, &oid_buf_len)) { config_perror("unable to parse an object oid"); return; } mte_add_object_to_table("snmpd.conf", name_buf, oid_buf, oid_buf_len, wild); wild = 1; } }
/** @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"); } }
void parse_sched_periodic( const char *token, char *line ) { netsnmp_tdata_row *row; struct schedTable_entry *entry; char buf[24], tmpbuf[SPRINT_MAX_LEN]; long frequency; long value; size_t tmpint; oid variable[ MAX_OID_LEN], *var_ptr = variable; size_t var_len = MAX_OID_LEN; schedEntries++; sprintf(buf, "_conf%03d", schedEntries); DEBUGMSGTL(( "disman:schedule:conf", "periodic: %s %s\n", token, line)); /* * Parse the configure directive line */ line = copy_nword(line, tmpbuf, sizeof(tmpbuf)); frequency = netsnmp_string_time_to_secs(tmpbuf); if (frequency == -1) { config_perror("Illegal frequency specified"); return; } line = read_config_read_data(ASN_OBJECT_ID, line, &var_ptr, &var_len); if (var_len == 0) { config_perror("invalid specification for schedVariable"); return; } /* * Skip over optional assignment in "var = value" */ while (line && isspace((unsigned char)(*line))) line++; if (line && *line == '=' ) { line++; while (line && isspace((unsigned char)(*line))) { line++; } } line = read_config_read_data(ASN_INTEGER, line, &value, &tmpint); /* * Create an entry in the schedTable */ row = schedTable_createEntry( "snmpd.conf", buf ); if (!row || !row->data) { config_perror("create schedule entry failure"); return; } entry = (struct schedTable_entry *)row->data; entry->schedInterval = frequency; entry->schedValue = value; entry->schedVariable_len = var_len; memcpy(entry->schedVariable, variable, var_len*sizeof(oid)); entry->schedType = SCHED_TYPE_PERIODIC; entry->schedStorageType = ST_READONLY; /* or PERMANENT */ entry->flags = SCHEDULE_FLAG_ENABLED | SCHEDULE_FLAG_ACTIVE | SCHEDULE_FLAG_VALID; entry->session = netsnmp_query_get_default_session(); sched_nextTime( entry ); }
int get_exec_pipes(char *cmd, int *fdIn, int *fdOut, int *pid) { /* Alexander Prömel, [email protected] 08/24/2006 The following code, is tested on picotux rev. 1.01. I think, it will be better to put the named pipes, into /var/run or make it selectable via CONFIG file. If the pipe file already exist, the creation will fail. I put the pipes into /flash, the pipepath has to change in ucd-snmp/pass_persist.c too, if you change it here. */ #if HAVE_EXECV #ifdef __uClinux__ /* HAVE uClinux */ int in,out; char fifo_in_path[256]; char fifo_out_path[256]; pid_t tpid; if ((tpid = vfork()) == 0) { /*temp child*/ execve(cmd, NULL,NULL); perror(cmd); exit(1); } else { if(tpid > 0) { /*initialize workspace*/ snprintf(fifo_in_path, 256, "/flash/cp_%d", tpid); snprintf(fifo_out_path, 256, "/flash/pc_%d", tpid); in = mkfifo(fifo_in_path, S_IRWXU); /*Create Input Pipe, 700*/ if ( in ) { perror("parent: inpipe"); exit(0); } out = mkfifo(fifo_out_path, S_IRWXU); /*Create Output Pipe, 700*/ if ( out ) { perror("parent: outpipe"); exit(0); } in = open(fifo_in_path,O_RDONLY); /*open the Input Pipe read Only*/ if(in < 0) { perror("parent: input"); exit(0); } out = open(fifo_out_path,O_WRONLY); /*open the Output Pipe write Only*/ if(out < 0) { perror("parent: output"); exit(0); } *fdIn = in; /*read*/ *fdOut = out; /*write*/ *pid = tpid; return (1); /* We are returning 0 for error... */ } else { /*pid < 0*/ setPerrorstatus("vfork"); return 0; } } #else /*HAVE x86*/ int fd[2][2], i, cnt; char ctmp[STRMAX], *cptr1, *cptr2, argvs[STRMAX], **argv, **aptr; /* * Setup our pipes */ if (pipe(fd[0]) || pipe(fd[1])) { setPerrorstatus("pipe"); return 0; } if ((*pid = fork()) == 0) { /* First handle for the child */ close(0); if (dup(fd[0][0]) != 0) { setPerrorstatus("dup 0"); return 0; } close(1); if (dup(fd[1][1]) != 1) { setPerrorstatus("dup 1"); return 0; } /* * write standard output and standard error to pipe. */ /* * close all non-standard open file descriptors */ for (cnt = getdtablesize() - 1; cnt >= 2; --cnt) (void) close(cnt); (void) dup(1); /* stderr */ for (cnt = 1, cptr1 = cmd, cptr2 = argvs; *cptr1 != 0; cptr2++, cptr1++) { *cptr2 = *cptr1; if (*cptr1 == ' ') { *(cptr2++) = 0; if ((cptr1 = skip_white(cptr1)) == NULL) break; *cptr2 = *cptr1; if (*cptr1 != 0) cnt++; } } *cptr2 = 0; *(cptr2 + 1) = 0; argv = (char **) malloc((cnt + 2) * sizeof(char *)); if (argv == NULL) return 0; /* memory alloc error */ aptr = argv; *(aptr++) = argvs; for (cptr2 = argvs, i = 1; i != cnt; cptr2++) if (*cptr2 == 0) { *(aptr++) = cptr2 + 1; i++; } while (*cptr2 != 0) cptr2++; *(aptr++) = NULL; copy_nword(cmd, ctmp, sizeof(ctmp)); execv(ctmp, argv); perror(ctmp); exit(1); } else { close(fd[0][0]); close(fd[1][1]); if (*pid < 0) { close(fd[0][1]); close(fd[1][0]); setPerrorstatus("fork"); return 0; } *fdIn = fd[1][0]; *fdOut = fd[0][1]; return (1); /* We are returning 0 for error... */ } #endif /* uClinux or x86 */ #endif /* !HAVE_EXECV */ #if defined(WIN32) && !defined (mingw32) && !defined(HAVE_EXECV) /* MSVC (MinGW not working but should use this code). Cygwin already works as it has execv and fork */ /* Reference: MS tech note: 190351 */ HANDLE hInputWriteTmp, hInputRead, hInputWrite = NULL; HANDLE hOutputReadTmp, hOutputRead, hOutputWrite = NULL; HANDLE hErrorWrite; SECURITY_ATTRIBUTES sa; PROCESS_INFORMATION pi; STARTUPINFO si; sa.nLength= sizeof(SECURITY_ATTRIBUTES); sa.lpSecurityDescriptor = NULL; sa.bInheritHandle = TRUE; /* Child temporary output pipe with Inheritance on (sa.bInheritHandle is true) */ if (!CreatePipe(&hOutputReadTmp,&hOutputWrite,&sa,0)) { DEBUGMSGTL(("util_funcs", "get_exec_pipes CreatePipe ChildOut: %d\n", GetLastError())); return 0; } /* Child temporary input pipe with Inheritance on (sa.bInheritHandle is true) */ if (!CreatePipe(&hInputRead,&hInputWriteTmp,&sa,0)) { DEBUGMSGTL(("util_funcs", "get_exec_pipes CreatePipe ChildIn: %d\n", GetLastError())); return 0; } /* Copy the stdout handle to the stderr handle in case the child closes one of * its stdout handles. */ if (!DuplicateHandle(GetCurrentProcess(),hOutputWrite, GetCurrentProcess(), &hErrorWrite,0, TRUE,DUPLICATE_SAME_ACCESS)) { DEBUGMSGTL(("util_funcs", "get_exec_pipes DuplicateHandle: %d\n", GetLastError())); return 0; } /* Create new copies of the input and output handles but set bInheritHandle to * FALSE so the new handle can not be inherited. Otherwise the handles can not * be closed. */ if (!DuplicateHandle(GetCurrentProcess(), hOutputReadTmp, GetCurrentProcess(), &hOutputRead, 0, FALSE, DUPLICATE_SAME_ACCESS)) { DEBUGMSGTL(("util_funcs", "get_exec_pipes DupliateHandle ChildOut: %d\n", GetLastError())); CloseHandle(hErrorWrite); return 0; } if (!DuplicateHandle(GetCurrentProcess(),hInputWriteTmp, GetCurrentProcess(), &hInputWrite, 0, FALSE, DUPLICATE_SAME_ACCESS)) { DEBUGMSGTL(("util_funcs","get_exec_pipes DupliateHandle ChildIn: %d\n", GetLastError())); CloseHandle(hErrorWrite); CloseHandle(hOutputRead); return 0; } /* Close the temporary output and input handles */ if (!CloseHandle(hOutputReadTmp)) { DEBUGMSGTL(("util_funcs", "get_exec_pipes CloseHandle (hOutputReadTmp): %d\n", GetLastError())); CloseHandle(hErrorWrite); CloseHandle(hOutputRead); CloseHandle(hInputWrite); return 0; } if (!CloseHandle(hInputWriteTmp)) { DEBUGMSGTL(("util_funcs", "get_exec_pipes CloseHandle (hInputWriteTmp): %d\n", GetLastError())); CloseHandle(hErrorWrite); CloseHandle(hOutputRead); CloseHandle(hInputWrite); return 0; } /* Associates a C run-time file descriptor with an existing operating-system file handle. */ *fdIn = _open_osfhandle((long) hOutputRead, 0); *fdOut = _open_osfhandle((long) hInputWrite, 0); /* Set up STARTUPINFO for CreateProcess with the handles and have it hide the window * for the new process. */ ZeroMemory(&si,sizeof(STARTUPINFO)); si.cb = sizeof(STARTUPINFO); si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW; si.hStdOutput = hOutputWrite; si.hStdInput = hInputRead; si.hStdError = hErrorWrite; si.wShowWindow = SW_HIDE; /* Launch the process that you want to redirect. Example snmpd.conf pass_persist: * pass_persist .1.3.6.1.4.1.2021.255 c:/perl/bin/perl c:/temp/pass_persisttest */ if (!CreateProcess(NULL, cmd, NULL, NULL, TRUE, CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi)) { DEBUGMSGTL(("util_funcs","get_exec_pipes CreateProcess:'%s' %d\n",cmd, GetLastError())); CloseHandle(hErrorWrite); CloseHandle(hOutputRead); CloseHandle(hInputWrite); return 0; } DEBUGMSGTL(("util_funcs","child hProcess (stored in pid): %d\n",(int)pi.hProcess)); DEBUGMSGTL(("util_funcs","child dwProcessId (task manager): %d\n",(int)pi.dwProcessId)); /* Set global child process handle */ *pid = (int)pi.hProcess; /* Cleanup */ if (!CloseHandle(pi.hThread)) DEBUGMSGTL(("util_funcs","get_exec_pipes CloseHandle pi.hThread: %d\n",cmd)); /* Close pipe handles to make sure that no handles to the write end of the * output pipe are maintained in this process or else the pipe will * not close when the child process exits and any calls to ReadFile * will hang. */ if (!CloseHandle(hOutputWrite)){ DEBUGMSGTL(("util_funcs","get_exec_pipes CloseHandle hOutputWrite: %d\n",cmd, GetLastError())); return 0; } if (!CloseHandle(hInputRead)) { DEBUGMSGTL(("util_funcs","get_exec_pipes CloseHandle hInputRead: %d\n",cmd, GetLastError())); return 0; } if (!CloseHandle(hErrorWrite)) { DEBUGMSGTL(("util_funcs","get_exec_pipes CloseHandle hErrorWrite: %d\n",cmd, GetLastError())); return 0; } return 1; #endif /* WIN32 */ return 0; }
void regexp_proc_parse_config(const char *token, char *cptr) { char tmpname[STRMAX]; struct myregexp_proc **procp = ®exp_procwatch; const char *pcre_error; int pcre_error_offset; /* * don't allow two entries with the same name */ copy_nword(cptr, tmpname, sizeof(tmpname)); if (get_regexp_proc_by_name(tmpname) != NULL) { config_perror("Already have an entry for this process."); return; } /* * skip past used ones */ while (*procp != NULL) procp = &((*procp)->next); (*procp) = (struct myregexp_proc *) calloc(1, sizeof(struct myregexp_proc)); if (*procp == NULL) return; /* memory alloc error */ numprocs++; (*procp)->regexp = NULL; /* * not blank and not a comment */ copy_nword(cptr, (*procp)->name, sizeof((*procp)->name)); cptr = skip_not_white(cptr); if ((cptr = skip_white(cptr))) { (*procp)->max = atoi(cptr); cptr = skip_not_white(cptr); if ((cptr = skip_white(cptr))) { (*procp)->min = atoi(cptr); cptr = skip_not_white(cptr); if ((cptr = skip_white(cptr))) { DEBUGMSGTL(("ucd-snmp/regexp_proc", "Loading regex %s\n", cptr)); (*procp)->regexp = pcre_compile(cptr, 0, &pcre_error, &pcre_error_offset, NULL); if ((*procp)->regexp == NULL) { config_perror(pcre_error); } } } else (*procp)->min = 0; } else { /* Default to asssume that we require at least one * such process to be running, but no upper limit */ (*procp)->max = 0; (*procp)->min = 1; /* This frees "proc <procname> 0 0" to monitor * processes that should _not_ be running. */ } #ifdef NETSNMP_PROCFIXCMD sprintf((*procp)->fixcmd, NETSNMP_PROCFIXCMD, (*procp)->name); #endif DEBUGMSGTL(("ucd-snmp/regexp_proc", "Read: %s (%d) (%d)\n", (*procp)->name, (*procp)->max, (*procp)->min)); }
void vacm_create_simple(const char *token, char *confline, int parsetype, int viewtypes) { char line[SPRINT_MAX_LEN]; char community[COMMUNITY_MAX_LEN]; char theoid[SPRINT_MAX_LEN]; char viewname[SPRINT_MAX_LEN]; char *view_ptr = viewname; #if !defined(NETSNMP_DISABLE_SNMPV1) || !defined(NETSNMP_DISABLE_SNMPV2C) char addressname[SPRINT_MAX_LEN]; #endif const char *rw = "none"; char model[SPRINT_MAX_LEN]; char *cp, *tmp; char secname[SPRINT_MAX_LEN]; char grpname[SPRINT_MAX_LEN]; char authlevel[SPRINT_MAX_LEN]; char context[SPRINT_MAX_LEN]; int ctxprefix = 1; /* Default to matching all contexts */ static int commcount = 0; /* Conveniently, the community-based security model values can also be used as bit flags */ int commversion = SNMP_SEC_MODEL_SNMPv1 | SNMP_SEC_MODEL_SNMPv2c; /* * init */ strcpy(model, "any"); memset(context, 0, sizeof(context)); memset(secname, 0, sizeof(secname)); memset(grpname, 0, sizeof(grpname)); /* * community name or user name */ cp = copy_nword(confline, community, sizeof(community)); if (parsetype == VACM_CREATE_SIMPLE_V3) { /* * maybe security model type */ if (strcmp(community, "-s") == 0) { /* * -s model ... */ if (cp) cp = copy_nword(cp, model, sizeof(model)); if (!cp) { config_perror("illegal line"); return; } if (cp) cp = copy_nword(cp, community, sizeof(community)); } else { strcpy(model, "usm"); } /* * authentication level */ if (cp && *cp) cp = copy_nword(cp, authlevel, sizeof(authlevel)); else strcpy(authlevel, "auth"); DEBUGMSGTL((token, "setting auth level: \"%s\"\n", authlevel)); #if !defined(NETSNMP_DISABLE_SNMPV1) || !defined(NETSNMP_DISABLE_SNMPV2C) } else { if (strcmp(community, "-v") == 0) { /* * -v version ... */ if (cp) cp = copy_nword(cp, model, sizeof(model)); if (!cp) { config_perror("illegal line"); return; } if ( strcasecmp( model, "1" ) == 0 ) strcpy(model, "v1"); if ( strcasecmp( model, "v1" ) == 0 ) commversion = SNMP_SEC_MODEL_SNMPv1; if ( strcasecmp( model, "2c" ) == 0 ) strcpy(model, "v2c"); if ( strcasecmp( model, "v2c" ) == 0 ) commversion = SNMP_SEC_MODEL_SNMPv2c; if (cp) cp = copy_nword(cp, community, sizeof(community)); } /* * source address */ if (cp && *cp) { cp = copy_nword(cp, addressname, sizeof(addressname)); } else { strcpy(addressname, "default"); } /* * authlevel has to be noauth */ strcpy(authlevel, "noauth"); #endif /* support for community based SNMP */ } /* * oid they can touch */ if (cp && *cp) { if (strncmp(cp, "-V ", 3) == 0) { cp = skip_token(cp); cp = copy_nword(cp, viewname, sizeof(viewname)); view_ptr = NULL; } else { cp = copy_nword(cp, theoid, sizeof(theoid)); } } else { strcpy(theoid, ".1"); strcpy(viewname, "_all_"); view_ptr = NULL; } /* * optional, non-default context */ if (cp && *cp) { cp = copy_nword(cp, context, sizeof(context)); tmp = (context + strlen(context)-1); if (tmp && *tmp == '*') { *tmp = '\0'; ctxprefix = 1; } else { /* * If no context field is given, then we default to matching * all contexts (for compatability with previous releases). * But if a field context is specified (not ending with '*') * then this should be taken as an exact match. * Specifying a context field of "" will match the default * context (and *only* the default context). */ ctxprefix = 0; } } if (viewtypes & VACM_VIEW_WRITE_BIT) rw = viewname; commcount++; #if !defined(NETSNMP_DISABLE_SNMPV1) || !defined(NETSNMP_DISABLE_SNMPV2C) #ifdef NETSNMP_TRANSPORT_UDP_DOMAIN if (parsetype == VACM_CREATE_SIMPLE_COMIPV4 || parsetype == VACM_CREATE_SIMPLE_COM) { vacm_gen_com2sec(commcount, community, addressname, "com2sec", &netsnmp_udp_parse_security, secname, sizeof(secname), view_ptr, sizeof(viewname), commversion, context); } #endif #ifdef NETSNMP_TRANSPORT_UNIX_DOMAIN if (parsetype == VACM_CREATE_SIMPLE_COMUNIX || parsetype == VACM_CREATE_SIMPLE_COM) { if ( *context ) snprintf(line, sizeof(line), "-Cn %s %s %s '%s'", context, secname, addressname, community); else snprintf(line, sizeof(line), "%s %s '%s'", secname, addressname, community); line[ sizeof(line)-1 ] = 0; DEBUGMSGTL((token, "passing: %s %s\n", "com2secunix", line)); netsnmp_unix_parse_security("com2secunix", line); } #endif #ifdef NETSNMP_TRANSPORT_UDPIPV6_DOMAIN if (parsetype == VACM_CREATE_SIMPLE_COMIPV6 || parsetype == VACM_CREATE_SIMPLE_COM) { vacm_gen_com2sec(commcount, community, addressname, "com2sec6", &netsnmp_udp6_parse_security, secname, sizeof(secname), view_ptr, sizeof(viewname), commversion, context); } #endif #endif /* support for community based SNMP */ if (parsetype == VACM_CREATE_SIMPLE_V3) { /* support for SNMPv3 user names */ if (view_ptr) { sprintf(viewname,"viewUSM%d",commcount); } if ( strcmp( token, "authgroup" ) == 0 ) { strlcpy(grpname, community, sizeof(grpname)); } else { strlcpy(secname, community, sizeof(secname)); /* * sec->group mapping */ /* * group anonymousGroupNameNUM any anonymousSecNameNUM */ snprintf(grpname, sizeof(grpname), "grp%.28s", secname); for (tmp=grpname; *tmp; tmp++) if (!isalnum((unsigned char)(*tmp))) *tmp = '_'; snprintf(line, sizeof(line), "%s %s \"%s\"", grpname, model, secname); line[ sizeof(line)-1 ] = 0; DEBUGMSGTL((token, "passing: %s %s\n", "group", line)); vacm_parse_group("group", line); } } else { snprintf(grpname, sizeof(grpname), "grp%.28s", secname); for (tmp=grpname; *tmp; tmp++) if (!isalnum((unsigned char)(*tmp))) *tmp = '_'; } /* * view definition */ /* * view anonymousViewNUM included OID */ if (view_ptr) { snprintf(line, sizeof(line), "%s included %s", viewname, theoid); line[ sizeof(line)-1 ] = 0; DEBUGMSGTL((token, "passing: %s %s\n", "view", line)); vacm_parse_view("view", line); } /* * map everything together */ if ((viewtypes == VACM_VIEW_READ_BIT) || (viewtypes == (VACM_VIEW_READ_BIT | VACM_VIEW_WRITE_BIT))) { /* Use the simple line access command */ /* * access anonymousGroupNameNUM "" MODEL AUTHTYPE prefix anonymousViewNUM [none/anonymousViewNUM] [none/anonymousViewNUM] */ snprintf(line, sizeof(line), "%s %s %s %s %s %s %s %s", grpname, context[0] ? context : "\"\"", model, authlevel, (ctxprefix ? "prefix" : "exact"), viewname, rw, rw); line[ sizeof(line)-1 ] = 0; DEBUGMSGTL((token, "passing: %s %s\n", "access", line)); vacm_parse_access("access", line); } else { /* Use one setaccess line per access type */ /* * setaccess anonymousGroupNameNUM "" MODEL AUTHTYPE prefix viewname viewval */ int i; DEBUGMSGTL((token, " checking view levels for %x\n", viewtypes)); for(i = 0; i <= VACM_MAX_VIEWS; i++) { if (viewtypes & (1 << i)) { snprintf(line, sizeof(line), "%s %s %s %s %s %s %s", grpname, context[0] ? context : "\"\"", model, authlevel, (ctxprefix ? "prefix" : "exact"), se_find_label_in_slist(VACM_VIEW_ENUM_NAME, i), viewname); line[ sizeof(line)-1 ] = 0; DEBUGMSGTL((token, "passing: %s %s\n", "setaccess", line)); vacm_parse_setaccess("setaccess", line); } } } }