int read_objid(//input, output, out_len) char *input, oid *output, int *out_len) /* number of subid's in "output" */ { struct snmp_mib_tree *root = Mib; oid *op = output; int i; if (*input == '.') input++; else { root = find_rfc1066_mib(root); for (i = 0; i < sizeof (RFC1066_MIB)/sizeof(oid); i++) { if ((*out_len)-- > 0) *output++ = RFC1066_MIB[i]; else { #ifdef STDERR_OUTPUT fprintf(stderr, WIDE("object identifier too long\n")); #endif return (0); } } } if (root == NULL) { //extern int mib_TxtToOid(char *Buf, oid **OidP, int *LenP); oid *tmp; if (!mib_TxtToOid(input, &tmp, out_len)) { #ifdef STDERR_OUTPUT fprintf(stderr, WIDE("Mib not initialized. Exiting.\n")); #endif return(0); } memcpy((char *)output, (char *)tmp, (*out_len * sizeof(oid))); free((char *)tmp); return (1); } if ((*out_len = parse_subtree(root, input, output, out_len)) == 0) return (0); *out_len += output - op; return (1); }
static int parse_subtree(struct snmp_mib_tree *subtree, char *input, oid *output, int *out_len) { char buf[128], *to = buf; u_int subid = 0; struct snmp_mib_tree *tp; /* * No empty strings. Can happen if there is a trailing '.' or two '.'s * in a row, i.e. "..". */ if ((*input == '\0') || (*input == '.')) return (0); if (xisdigit(*input)) { /* * Read the number, then try to find it in the subtree. */ while (xisdigit(*input)) { subid *= 10; subid += *input++ - '0'; } for (tp = subtree; tp; tp = tp->next_peer) { if (tp->subid == subid) goto found; } tp = NULL; } else { /* * Read the name into a buffer. */ while ((*input != '\0') && (*input != '.')) { *to++ = *input++; } *to = '\0'; /* * Find the name in the subtree; */ for (tp = subtree; tp; tp = tp->next_peer) { if (lc_cmp(tp->label, buf) == 0) { subid = tp->subid; goto found; } } /* * If we didn't find the entry, punt... */ if (tp == NULL) { snmplib_debug(0, "sub-identifier not found: %s\n", buf); return (0); } } found: if (subid > (u_int) MAX_SUBID) { snmplib_debug(0, "sub-identifier too large: %s\n", buf); return (0); } if ((*out_len)-- <= 0) { snmplib_debug(0, "object identifier too long\n"); return (0); } *output++ = subid; if (*input != '.') return (1); if ((*out_len = parse_subtree(tp ? tp->child_list : NULL, ++input, output, out_len)) == 0) return (0); return (++*out_len); }
static int parse_subtree(//subtree, input, output, out_len) struct snmp_mib_tree *subtree, char *input, oid *output, int *out_len) /* number of subid's */ { char buf[128], *to = buf; u_int subid = 0; struct snmp_mib_tree *tp; /* * No empty strings. Can happen if there is a trailing '.' or two '.'s * in a row, i.e. "..". */ if ((*input == '\0') || (*input == '.')) return (0); if (isdigit(*input)) { /* * Read the number, then try to find it in the subtree. */ while (isdigit(*input)) { subid *= 10; subid += *input++ - '0'; } for (tp = subtree; tp; tp = tp->next_peer) { if (tp->subid == subid) goto found; } tp = NULL; } else { /* * Read the name into a buffer. */ while ((*input != '\0') && (*input != '.')) { *to++ = *input++; } *to = '\0'; /* * Find the name in the subtree; */ for (tp = subtree; tp; tp = tp->next_peer) { if (lc_cmp(tp->label, buf) == 0) { subid = tp->subid; goto found; } } /* * If we didn't find the entry, punt... */ if (tp == NULL) { #ifdef STDERR_OUTPUT fprintf(stderr, WIDE("sub-identifier not found: %s\n"), buf); #endif return (0); } } found: //cpg26dec2006 src\snmplib\mib.c(808): Warning! W124: Comparison result always 0 if(subid > (u_int)MAX_SUBID){ { #ifdef STDERR_OUTPUT fprintf(stderr, WIDE("sub-identifier too large: %s\n"), buf); #endif return (0); } } if ((*out_len)-- <= 0){ #ifdef STDERR_OUTPUT fprintf(stderr, WIDE("object identifier too long\n")); #endif return (0); } *output++ = subid; if (*input != '.') return (1); if ((*out_len = parse_subtree(tp ? tp->child_list : NULL, ++input, output, out_len)) == 0) return (0); return (++*out_len); }