Esempio n. 1
0
/*
 * Read user input OID - one of following formats:
 * 1) 1.2.1.1.2.1.0 - that is if option numeric was given;
 * 2) string - in such case append .0 to the asn_oid subs;
 * 3) string.1 - no additional processing required in such case.
 */
static char *
snmptools_parse_stroid(struct snmp_toolinfo *snmptoolctx,
    struct snmp_object *obj, char *argv)
{
	char string[MAXSTR], *str;
	int32_t i = 0;
	struct asn_oid in_oid;

	str = argv;

	if (*str == '.')
		str++;

	while (isalpha(*str) || *str == '_' || (i != 0 && isdigit(*str))) {
		str++;
		i++;
	}

	if (i <= 0 || i >= MAXSTR)
		return (NULL);

	memset(&in_oid, 0, sizeof(struct asn_oid));
	if ((str = snmp_parse_suboid((argv + i), &in_oid)) == NULL) {
		warnx("Invalid OID - %s", argv);
		return (NULL);
	}

	strlcpy(string, argv, i + 1);
	if (snmp_lookup_oidall(snmptoolctx, obj, string) < 0) {
		warnx("No entry for %s in mapping lists", string);
		return (NULL);
	}

	/* If OID given on command line append it. */
	if (in_oid.len > 0)
		asn_append_oid(&(obj->val.var), &in_oid);
	else if (*str == '[') {
		if ((str = snmp_parse_index(snmptoolctx, str + 1, obj)) == NULL)
			return (NULL);
	} else if (obj->val.syntax > 0 && GET_PDUTYPE(snmptoolctx) ==
	    SNMP_PDU_GET) {
		if (snmp_suboid_append(&(obj->val.var), (asn_subid_t) 0) < 0)
			return (NULL);
	}

	return (str);
}
Esempio n. 2
0
static int
snmpwalk_parse_stroid(struct snmp_toolinfo *tool, struct snmp_object *obj, char *argv)
{
    char 		string[MAXSTR], *ptr;
    int 		i = 0;
    struct asn_oid  in_oid;

    ptr = argv;
    while (isalpha(*ptr)|| *ptr == '_' || (i != 0 \
                                           && isdigit(*ptr))) {
        ptr++;
        i++;
    }

    if (i <= 0 || i >= MAXSTR)
        return (-1);

    memset(&in_oid, 0, sizeof(struct asn_oid));
    if ((ptr = snmp_parse_suboid((argv + i), &in_oid)) == NULL) {
        return (-1);
    }

    strlcpy(string, argv, i + 1);

    if (snmp_lookup_oidall(tool, obj, string) < 0) {
        warnx("No entry for %s in mapping lists", string);
        return(-1);
    }

    /*
     * If suboid provided on command line - append it as well
     */

    if (in_oid.len > 0)
        asn_append_oid(&(obj->val.var), &in_oid);
    else if (*ptr == '[') {
        if ((ptr = snmp_parse_index(tool, ptr + 1, obj)) == NULL)
            return (-1);
    }

    if (*ptr != '\0') {
        warnx("Invalid character after OID %s", argv);
        return (-1);
    }
    return (1);
}