* Parse a name into a MIB entry. * Lookup and print out the MIB entry if it exists. * Set a new value if requested. */
| 497 | * Set a new value if requested. |
| 498 | */ |
| 499 | static int |
| 500 | parse(const char *string, int lineno) |
| 501 | { |
| 502 | int len, i, j, save_errno; |
| 503 | const void *newval; |
| 504 | char *newvalstr = NULL; |
| 505 | void *newbuf; |
| 506 | size_t newsize = Bflag; |
| 507 | int mib[CTL_MAXNAME]; |
| 508 | char *cp, *bufp, *buf, fmt[BUFSIZ], line[BUFSIZ]; |
| 509 | u_int kind; |
| 510 | |
| 511 | if (lineno) |
| 512 | snprintf(line, sizeof(line), " at line %d", lineno); |
| 513 | else |
| 514 | line[0] = '\0'; |
| 515 | |
| 516 | /* |
| 517 | * Split the string into name and value. |
| 518 | * |
| 519 | * Either = or : may be used as the delimiter. |
| 520 | * Whitespace surrounding the delimiter is trimmed. |
| 521 | * Quotes around the value are stripped. |
| 522 | */ |
| 523 | cp = buf = strdup(string); |
| 524 | bufp = strsep(&cp, "=:"); |
| 525 | if (cp != NULL) { |
| 526 | /* Tflag just lists tunables, do not allow assignment */ |
| 527 | if (Tflag || Wflag) { |
| 528 | warnx("Can't set variables when using -T or -W"); |
| 529 | usage(); |
| 530 | } |
| 531 | /* Trim whitespace before the value. */ |
| 532 | while (isspace(*cp)) |
| 533 | cp++; |
| 534 | /* Strip a pair of " or ' if any. */ |
| 535 | switch (*cp) { |
| 536 | case '\"': |
| 537 | case '\'': |
| 538 | if (cp[strlen(cp) - 1] == *cp) |
| 539 | cp[strlen(cp) - 1] = '\0'; |
| 540 | cp++; |
| 541 | } |
| 542 | newvalstr = cp; |
| 543 | newsize = strlen(cp); |
| 544 | } |
| 545 | /* Trim whitespace after the name. */ |
| 546 | cp = bufp + strlen(bufp) - 1; |
| 547 | while (cp >= bufp && isspace((int)*cp)) { |
| 548 | *cp = '\0'; |
| 549 | cp--; |
| 550 | } |
| 551 | |
| 552 | /* |
| 553 | * Check the name is a useable oid. |
| 554 | */ |
| 555 | len = name2oid(bufp, mib); |
| 556 | if (len < 0) { |
no test coverage detected