* should be the length of the string or sub string to parse.
* @return true on success, else false.
*/
-bool pairparsevalue(VALUE_PAIR *vp, char const *value, size_t inlen)
+int pairparsevalue(VALUE_PAIR *vp, char const *value, size_t inlen)
{
char const *cs;
DICT_VALUE *dval;
size_t len;
char buffer[256];
- if (!value) return false;
+ if (!value) return -1;
VERIFY_VP(vp);
/*
*/
if ((len & 0x01) != 0) {
fr_strerror_printf("Length of Hex String is not even, got %zu bytes", vp->length);
- return false;
+ return -1;
}
vp->length = len >> 1;
if (fr_hex2bin(p, value + 2, len) != vp->length) {
talloc_free(p);
fr_strerror_printf("Invalid hex data");
- return false;
+ return -1;
}
vp->vp_octets = p;
if (ascend_parse_filter(vp, value, len) < 0 ) {
/* Allow ascend_parse_filter's strerror to bubble up */
- return false;
+ return -1;
}
goto finish;
#else
if ((len < 2) || (len & 0x01) || (strncasecmp(value, "0x", 2) != 0)) {
fr_strerror_printf("Invalid TLV specification");
- return false;
+ return -1;
}
len -= 2;
p = talloc_array(vp, uint8_t, vp->length);
if (!p) {
fr_strerror_printf("No memory");
- return false;
+ return -1;
}
if (fr_hex2bin(p, value + 2, len) != vp->length) {
fr_strerror_printf("Invalid hex data in TLV");
- return false;
+ return -1;
}
vp->vp_tlv = p;
if (inlen > 0) {
if (len >= sizeof(buffer)) {
fr_strerror_printf("Temporary buffer too small");
- return false;
+ return -1;
}
memcpy(buffer, value, inlen);
if ((p[1] != '3') || (p[2] != '2') || (p[3] != '\0')) {
fr_strerror_printf("Invalid IP address suffix \"%s\". Only '/32' permitted "
"for non-prefix types", p);
- return false;
+ return -1;
}
strlcpy(ipv4, value, sizeof(ipv4));
if (ip_hton(cs, AF_INET, &ipaddr) < 0) {
fr_strerror_printf("Failed to find IP address for %s", cs);
- return false;
+ return -1;
}
vp->vp_ipaddr = ipaddr.ipaddr.ip4addr.s_addr;
if (!*p) {
if (vp->vp_integer > 255) {
fr_strerror_printf("Byte value \"%s\" is larger than 255", value);
- return false;
+ return -1;
}
break;
}
if (!*p) {
if (vp->vp_integer > 65535) {
fr_strerror_printf("Byte value \"%s\" is larger than 65535", value);
- return false;
+ return -1;
}
break;
}
*/
if ((dval = dict_valbyname(vp->da->attr, vp->da->vendor, value)) == NULL) {
fr_strerror_printf("Unknown value '%s' for attribute '%s'", value, vp->da->name);
- return false;
+ return -1;
}
vp->vp_integer = dval->value;
}
if (sscanf(value, "%" PRIu64, &y) != 1) {
fr_strerror_printf("Invalid value '%s' for attribute '%s'",
value, vp->da->name);
- return false;
+ return -1;
}
vp->vp_integer64 = y;
vp->length = 8;
if (fr_get_time(value, &date) < 0) {
fr_strerror_printf("failed to parse time string "
"\"%s\"", value);
- return false;
+ return -1;
}
vp->vp_date = date;
case PW_TYPE_IFID:
if (ifid_aton(value, (void *) &vp->vp_ifid) == NULL) {
fr_strerror_printf("Failed to parse interface-id string \"%s\"", value);
- return false;
+ return -1;
}
vp->length = 8;
break;
if (ip_hton(value, AF_INET6, &ipaddr) < 0) {
fr_strerror_printf("failed to parse IPv6 address "
"string \"%s\": %s", value, fr_strerror());
- return false;
+ return -1;
}
vp->vp_ipv6addr = ipaddr.ipaddr.ip6addr;
vp->length = 16; /* length of IPv6 address */
p = strchr(value, '/');
if (!p || ((p - value) >= 256)) {
fr_strerror_printf("invalid IPv6 prefix string \"%s\"", value);
- return false;
+ return -1;
}
/*
if (inet_pton(AF_INET6, buffer, vp->vp_ipv6prefix + 2) <= 0) {
fr_strerror_printf("failed to parse IPv6 address string \"%s\"", value);
- return false;
+ return -1;
}
prefix = strtoul(p + 1, &eptr, 10);
if ((prefix > 128) || *eptr) {
fr_strerror_printf("failed to parse IPv6 address string \"%s\"", value);
- return false;
+ return -1;
}
vp->vp_ipv6prefix[1] = prefix;
if (inet_pton(AF_INET, value, vp->vp_ipv4prefix + 2) <= 0) {
fr_strerror_printf("failed to parse IPv4 address string \"%s\"", value);
- return false;
+ return -1;
}
vp->length = sizeof(vp->vp_ipv4prefix);
break;
*/
if ((size_t)(p - value) >= sizeof(buffer)) {
fr_strerror_printf("invalid IPv4 prefix string \"%s\"", value);
- return false;
+ return -1;
}
/*
if (inet_pton(AF_INET, buffer, vp->vp_ipv4prefix + 2) <= 0) {
fr_strerror_printf("failed to parse IPv4 address string \"%s\"", value);
- return false;
+ return -1;
}
prefix = strtoul(p + 1, &eptr, 10);
if ((prefix > 32) || *eptr) {
fr_strerror_printf("failed to parse IPv4 address string \"%s\"", value);
- return false;
+ return -1;
}
vp->vp_ipv4prefix[1] = prefix;
}
if (!c1 || !c2 || (vp_len >= sizeof(vp->vp_ether))) {
fr_strerror_printf("failed to parse Ethernet address \"%s\"", value);
- return false;
+ return -1;
}
vp->vp_ether[vp_len] = ((c1-hextab)<<4) + (c2-hextab);
vp_len++;
da = dict_attrbytype(vp->da->attr, vp->da->vendor, PW_TYPE_IPV6ADDR);
if (!da) {
fr_strerror_printf("Cannot find ipv6addr for %s", vp->da->name);
- return false;
+ return -1;
}
vp->length = 16; /* length of IPv6 address */
PW_TYPE_IPADDR);
if (!da) {
fr_strerror_printf("Cannot find ipaddr for %s", vp->da->name);
- return false;
+ return -1;
}
if (ip_hton(value, AF_INET, &ipaddr) < 0) {
fr_strerror_printf("Failed to find IPv4 address for %s", value);
- return false;
+ return -1;
}
vp->vp_ipaddr = ipaddr.ipaddr.ip4addr.s_addr;
*/
default:
fr_strerror_printf("unknown attribute type %d", vp->da->type);
- return false;
+ return -1;
}
finish:
vp->type = VT_DATA;
- return true;
+ return 0;
}
/** Use simple heuristics to create an VALUE_PAIR from an unknown address string
finish:
vp = pairalloc(ctx, da);
if (!vp) return NULL;
- if (!pairparsevalue(vp, value, 0)) {
+ if (pairparsevalue(vp, value, 0) < 0) {
talloc_free(vp);
return NULL;
}
* We probably want to fix pairparsevalue to accept
* octets as values for any attribute.
*/
- if (value && !pairparsevalue(vp, value, 0)) {
+ if (value && (pairparsevalue(vp, value, 0) < 0)) {
talloc_free(vp);
return NULL;
}
return NULL;
}
- if (!pairparsevalue(vp, str, 0)) {
+ if ((pairparsevalue(vp, str, 0) < 0)) {
talloc_free(str);
pairfree(&vp);
return NULL;
* Copy data from src to dst, where the attributes are of
* different type.
*/
-static bool do_cast_copy(VALUE_PAIR *dst, VALUE_PAIR const *src)
+static int do_cast_copy(VALUE_PAIR *dst, VALUE_PAIR const *src)
{
rad_assert(dst->da->type != src->da->type);
if (dst->da->type == PW_TYPE_STRING) {
dst->vp_strvalue = vp_aprint_value(dst, src);
dst->length = strlen(dst->vp_strvalue);
- return true;
+ return 0;
}
if (dst->da->type == PW_TYPE_OCTETS) {
} else {
pairmemcpy(dst, (uint8_t const *) &src->data, src->length);
}
- return true;
+ return 0;
}
if (src->da->type == PW_TYPE_STRING) {
/*
* For OUIs in the DB.
*/
- if ((array[0] != 0) || (array[1] != 0)) return false;
+ if ((array[0] != 0) || (array[1] != 0)) return -1;
memcpy(&dst->vp_ether, &array[2], 6);
dst->length = 6;
- return true;
+ return 0;
}
/*
if ((src->length < dict_attr_sizes[dst->da->type][0]) ||
(src->length > dict_attr_sizes[dst->da->type][1])) {
EVAL_DEBUG("Casted attribute is wrong size (%u)", (unsigned int) src->length);
- return false;
+ return -1;
}
if (src->da->type == PW_TYPE_OCTETS) {
}
dst->length = src->length;
- return true;
+ return 0;
}
/*
dst->length = src->length;
- return true;
+ return 0;
}
/*
* In a separate function for clarity
*/
- if (!do_cast_copy(lhs_vp, cast_vp)) {
+ if (do_cast_copy(lhs_vp, cast_vp) < 0) {
talloc_free(lhs_vp);
return false;
}
radius_find_compare(map->dst->vpt_da)) {
rhs_vp = pairalloc(request, map->dst->vpt_da);
rad_assert(rhs_vp != NULL);
- if (!pairparsevalue(rhs_vp, rhs, 0)) {
+ if (pairparsevalue(rhs_vp, rhs, 0) < 0) {
talloc_free(rhs);
EVAL_DEBUG("FAIL %d", __LINE__);
return -1;
*/
rhs_vp = pairalloc(request, map->dst->vpt_da);
rad_assert(rhs_vp != NULL);
- if (!pairparsevalue(rhs_vp, rhs, 0)) {
+ if (pairparsevalue(rhs_vp, rhs, 0) < 0) {
talloc_free(rhs);
pairfree(&rhs_vp);
EVAL_DEBUG("FAIL %d", __LINE__);