pairparsevalue should return 0 or -1 like pretty much every other function int the...
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 28 May 2014 16:03:05 +0000 (17:03 +0100)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 28 May 2014 16:03:33 +0000 (17:03 +0100)
src/include/libradius.h
src/lib/valuepair.c
src/main/evaluate.c
src/main/map.c
src/main/valuepair.c
src/modules/rlm_cache/rlm_cache.c
src/modules/rlm_ldap/attrmap.c
src/modules/rlm_perl/rlm_perl.c
src/modules/rlm_rest/rest.c
src/modules/rlm_sql/sql.c

index 8d7d531..5d13425 100644 (file)
@@ -614,7 +614,7 @@ void                pairfilter(TALLOC_CTX *ctx, VALUE_PAIR **to, VALUE_PAIR **from,
                           unsigned int attr, unsigned int vendor, int8_t tag);
 VALUE_PAIR     *pairmake_ip(TALLOC_CTX *ctx, char const *value,
                             DICT_ATTR *ipv4, DICT_ATTR *ipv6, DICT_ATTR *ipv4_prefix, DICT_ATTR *ipv6_prefix);
-bool           pairparsevalue(VALUE_PAIR *vp, char const *value, size_t len);
+int            pairparsevalue(VALUE_PAIR *vp, char const *value, size_t len);
 VALUE_PAIR     *pairmake(TALLOC_CTX *ctx, VALUE_PAIR **vps, char const *attribute, char const *value, FR_TOKEN op);
 int            pairmark_xlat(VALUE_PAIR *vp, char const *value);
 FR_TOKEN       pairread(char const **ptr, VALUE_PAIR_RAW *raw);
index c3b1fd8..3810a24 100644 (file)
@@ -1203,14 +1203,14 @@ static char const *hextab = "0123456789abcdef";
  *       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);
 
        /*
@@ -1335,7 +1335,7 @@ bool pairparsevalue(VALUE_PAIR *vp, char const *value, size_t inlen)
                 */
                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;
@@ -1343,7 +1343,7 @@ bool pairparsevalue(VALUE_PAIR *vp, char const *value, size_t inlen)
                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;
@@ -1356,7 +1356,7 @@ bool pairparsevalue(VALUE_PAIR *vp, char const *value, size_t inlen)
 
                if (ascend_parse_filter(vp, value, len) < 0 ) {
                        /* Allow ascend_parse_filter's strerror to bubble up */
-                       return false;
+                       return -1;
                }
                goto finish;
 #else
@@ -1375,7 +1375,7 @@ bool pairparsevalue(VALUE_PAIR *vp, char const *value, size_t inlen)
 
                if ((len < 2) || (len & 0x01) || (strncasecmp(value, "0x", 2) != 0)) {
                        fr_strerror_printf("Invalid TLV specification");
-                       return false;
+                       return -1;
                }
                len -= 2;
 
@@ -1383,11 +1383,11 @@ bool pairparsevalue(VALUE_PAIR *vp, char const *value, size_t inlen)
                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;
@@ -1405,7 +1405,7 @@ bool pairparsevalue(VALUE_PAIR *vp, char const *value, size_t inlen)
        if (inlen > 0) {
                if (len >= sizeof(buffer)) {
                        fr_strerror_printf("Temporary buffer too small");
-                       return false;
+                       return -1;
                }
 
                memcpy(buffer, value, inlen);
@@ -1445,7 +1445,7 @@ bool pairparsevalue(VALUE_PAIR *vp, char const *value, size_t 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));
@@ -1457,7 +1457,7 @@ bool pairparsevalue(VALUE_PAIR *vp, char const *value, size_t inlen)
 
                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;
@@ -1477,7 +1477,7 @@ bool pairparsevalue(VALUE_PAIR *vp, char const *value, size_t inlen)
                if (!*p) {
                        if (vp->vp_integer > 255) {
                                fr_strerror_printf("Byte value \"%s\" is larger than 255", value);
-                               return false;
+                               return -1;
                        }
                        break;
                }
@@ -1497,7 +1497,7 @@ bool pairparsevalue(VALUE_PAIR *vp, char const *value, size_t inlen)
                if (!*p) {
                        if (vp->vp_integer > 65535) {
                                fr_strerror_printf("Byte value \"%s\" is larger than 65535", value);
-                               return false;
+                               return -1;
                        }
                        break;
                }
@@ -1524,7 +1524,7 @@ bool pairparsevalue(VALUE_PAIR *vp, char const *value, size_t inlen)
                 */
                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;
        }
@@ -1540,7 +1540,7 @@ bool pairparsevalue(VALUE_PAIR *vp, char const *value, size_t inlen)
                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;
@@ -1560,7 +1560,7 @@ bool pairparsevalue(VALUE_PAIR *vp, char const *value, size_t inlen)
                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;
@@ -1572,7 +1572,7 @@ bool pairparsevalue(VALUE_PAIR *vp, char const *value, size_t inlen)
        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;
@@ -1584,7 +1584,7 @@ bool pairparsevalue(VALUE_PAIR *vp, char const *value, size_t inlen)
                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 */
@@ -1600,7 +1600,7 @@ bool pairparsevalue(VALUE_PAIR *vp, char const *value, size_t inlen)
                p = strchr(value, '/');
                if (!p || ((p - value) >= 256)) {
                        fr_strerror_printf("invalid IPv6 prefix string \"%s\"", value);
-                       return false;
+                       return -1;
                }
 
                /*
@@ -1611,13 +1611,13 @@ bool pairparsevalue(VALUE_PAIR *vp, char const *value, size_t inlen)
 
                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;
 
@@ -1647,7 +1647,7 @@ bool pairparsevalue(VALUE_PAIR *vp, char const *value, size_t inlen)
 
                        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;
@@ -1658,7 +1658,7 @@ bool pairparsevalue(VALUE_PAIR *vp, char const *value, size_t inlen)
                 */
                if ((size_t)(p - value) >= sizeof(buffer)) {
                        fr_strerror_printf("invalid IPv4 prefix string \"%s\"", value);
-                       return false;
+                       return -1;
                }
 
                /*
@@ -1669,13 +1669,13 @@ bool pairparsevalue(VALUE_PAIR *vp, char const *value, size_t inlen)
 
                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;
 
@@ -1724,7 +1724,7 @@ bool pairparsevalue(VALUE_PAIR *vp, char const *value, size_t inlen)
                        }
                        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++;
@@ -1751,7 +1751,7 @@ bool pairparsevalue(VALUE_PAIR *vp, char const *value, size_t inlen)
                        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 */
@@ -1762,12 +1762,12 @@ bool pairparsevalue(VALUE_PAIR *vp, char const *value, size_t inlen)
                                             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;
@@ -1789,12 +1789,12 @@ bool pairparsevalue(VALUE_PAIR *vp, char const *value, size_t inlen)
                 */
        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
@@ -1848,7 +1848,7 @@ VALUE_PAIR *pairmake_ip(TALLOC_CTX *ctx, char const *value, DICT_ATTR *ipv4, DIC
 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;
        }
@@ -2096,7 +2096,7 @@ VALUE_PAIR *pairmake(TALLOC_CTX *ctx, VALUE_PAIR **vps,
         *      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;
        }
index 251f96d..763d0ef 100644 (file)
@@ -337,7 +337,7 @@ static VALUE_PAIR *get_cast_vp(REQUEST *request, value_pair_tmpl_t const *vpt, D
                return NULL;
        }
 
-       if (!pairparsevalue(vp, str, 0)) {
+       if ((pairparsevalue(vp, str, 0) < 0)) {
                talloc_free(str);
                pairfree(&vp);
                return NULL;
@@ -350,14 +350,14 @@ static VALUE_PAIR *get_cast_vp(REQUEST *request, value_pair_tmpl_t const *vpt, D
  *     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) {
@@ -366,7 +366,7 @@ static bool do_cast_copy(VALUE_PAIR *dst, VALUE_PAIR const *src)
                } else {
                        pairmemcpy(dst, (uint8_t const *) &src->data, src->length);
                }
-               return true;
+               return 0;
        }
 
        if (src->da->type == PW_TYPE_STRING) {
@@ -384,11 +384,11 @@ static bool do_cast_copy(VALUE_PAIR *dst, VALUE_PAIR const *src)
                /*
                 *      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;
        }
 
        /*
@@ -398,7 +398,7 @@ static bool do_cast_copy(VALUE_PAIR *dst, VALUE_PAIR const *src)
        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) {
@@ -428,7 +428,7 @@ static bool do_cast_copy(VALUE_PAIR *dst, VALUE_PAIR const *src)
                }
 
                dst->length = src->length;
-               return true;
+               return 0;
        }
 
        /*
@@ -452,7 +452,7 @@ static bool do_cast_copy(VALUE_PAIR *dst, VALUE_PAIR const *src)
 
        dst->length = src->length;
 
-       return true;
+       return 0;
 }
 
 
@@ -533,7 +533,7 @@ int radius_evaluate_map(REQUEST *request, UNUSED int modreturn, UNUSED int depth
                        /*
                         *      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;
                        }
@@ -670,7 +670,7 @@ int radius_evaluate_map(REQUEST *request, UNUSED int modreturn, UNUSED int depth
                            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;
@@ -690,7 +690,7 @@ int radius_evaluate_map(REQUEST *request, UNUSED int modreturn, UNUSED int depth
                 */
                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__);
index eec76dc..f4639ab 100644 (file)
@@ -879,7 +879,7 @@ bool radius_cast_tmpl(value_pair_tmpl_t *vpt, DICT_ATTR const *da)
        vp = pairalloc(vpt, da);
        if (!vp) return false;
 
-       if (!pairparsevalue(vp, vpt->name, 0)) {
+       if (pairparsevalue(vp, vpt->name, 0) < 0) {
                pairfree(&vp);
                return false;
        }
index 2f6e481..5be3e17 100644 (file)
@@ -616,7 +616,7 @@ int radius_xlat_do(REQUEST *request, VALUE_PAIR *vp)
        /*
         *      Parse the string into a new value.
         */
-       if (!pairparsevalue(vp, buffer, 0)){
+       if (pairparsevalue(vp, buffer, 0) < 0){
                return -2;
        }
 
@@ -1336,7 +1336,7 @@ int radius_mapexec(VALUE_PAIR **out, REQUEST *request, value_pair_map_t const *m
                vp = pairalloc(request, map->dst->vpt_da);
                if (!vp) return -1;
                vp->op = map->op;
-               if (!pairparsevalue(vp, answer, 0)) {
+               if (pairparsevalue(vp, answer, 0) < 0) {
                        pairfree(&vp);
                        return -2;
                }
@@ -1481,9 +1481,8 @@ int radius_map2vp(VALUE_PAIR **out, REQUEST *request, value_pair_map_t const *ma
 
                rcode = pairparsevalue(vp, str, 0);
                talloc_free(str);
-               if (!rcode) {
+               if (rcode < 0) {
                        pairfree(&vp);
-                       rcode = -1;
                        goto error;
                }
                break;
@@ -1499,15 +1498,14 @@ int radius_map2vp(VALUE_PAIR **out, REQUEST *request, value_pair_map_t const *ma
                }
                rcode = pairparsevalue(vp, str, 0);
                talloc_free(str);
-               if (!rcode) {
+               if (rcode < 0) {
                        pairfree(&vp);
-                       rcode = -1;
                        goto error;
                }
                break;
 
        case VPT_TYPE_LITERAL:
-               if (!pairparsevalue(vp, map->src->name, 0)) {
+               if (pairparsevalue(vp, map->src->name, 0) < 0) {
                        rcode = 0;
                        goto error;
                }
index d7f1c72..1f3c176 100644 (file)
@@ -510,7 +510,7 @@ static rlm_cache_entry_t *cache_add(rlm_cache_t *inst, REQUEST *request,
                        if (!vp) continue;
 
                        vp->op = map->op;
-                       if (!pairparsevalue(vp, buffer, 0)) {
+                       if (pairparsevalue(vp, buffer, 0) < 0) {
                                pairfree(&vp);
                                continue;
                        }
@@ -535,7 +535,7 @@ static rlm_cache_entry_t *cache_add(rlm_cache_t *inst, REQUEST *request,
                        if (!vp) continue;
 
                        vp->op = map->op;
-                       if (!pairparsevalue(vp, map->src->name, 0)) {
+                       if (pairparsevalue(vp, map->src->name, 0) < 0) {
                                pairfree(&vp);
                                continue;
                        }
@@ -642,7 +642,7 @@ static int cache_verify(rlm_cache_t *inst, value_pair_map_t **head)
 
                                ret = pairparsevalue(vp, map->src->name, 0);
                                talloc_free(vp);
-                               if (!ret) {
+                               if (ret < 0) {
                                        cf_log_err(map->ci, "%s", fr_strerror());
                                        return -1;
                                }
index 57ec056..c51dff7 100644 (file)
@@ -97,7 +97,7 @@ static int rlm_ldap_map_getvalue(VALUE_PAIR **out, REQUEST *request, value_pair_
                        vp = pairalloc(request, map->dst->vpt_da);
                        rad_assert(vp);
 
-                       if (!pairparsevalue(vp, self->values[i]->bv_val, self->values[i]->bv_len)) {
+                       if (pairparsevalue(vp, self->values[i]->bv_val, self->values[i]->bv_len) < 0) {
                                RDEBUG("Failed parsing value for \"%s\"", map->dst->vpt_da->name);
 
                                talloc_free(vp);
index a4429a7..fecc01c 100644 (file)
@@ -668,7 +668,7 @@ static int pairadd_sv(TALLOC_CTX *ctx, REQUEST *request, VALUE_PAIR **vps, char
                }
 
                if (vp->da->type != PW_TYPE_STRING) {
-                       if (!pairparsevalue(vp, val, 0)) goto fail;
+                       if (pairparsevalue(vp, val, 0) < 0) goto fail;
                } else {
                        pairstrncpy(vp, val, len);
                }
index 810a9dc..323ca9a 100644 (file)
@@ -1025,7 +1025,7 @@ static int rest_decode_post(UNUSED rlm_rest_t *instance, UNUSED rlm_rest_section
 
                ret = pairparsevalue(vp, expanded, 0);
                TALLOC_FREE(expanded);
-               if (!ret) {
+               if (ret < 0) {
                        RWDEBUG("Incompatible value assignment, skipping");
                        talloc_free(vp);
                        goto skip;
@@ -1114,7 +1114,7 @@ static VALUE_PAIR *json_pairmake_leaf(UNUSED rlm_rest_t *instance, UNUSED rlm_re
 
        ret = pairparsevalue(vp, to_parse, 0);
        talloc_free(expanded);
-       if (!ret) {
+       if (ret < 0) {
                RWDEBUG("Incompatible value assignment, skipping...");
                talloc_free(vp);
 
index 5316197..a64bd1e 100644 (file)
@@ -261,7 +261,7 @@ int sql_userparse(TALLOC_CTX *ctx, VALUE_PAIR **head, rlm_sql_row_t row)
                        return -1;
                }
        } else {
-               if (!pairparsevalue(vp, value, 0)) {
+               if (pairparsevalue(vp, value, 0) < 0) {
                        ERROR("rlm_sql: Error parsing value: %s", fr_strerror());
 
                        talloc_free(vp);