From: Alan T. DeKok Date: Mon, 11 Nov 2024 12:09:57 +0000 (-0500) Subject: allow passing type to "unknown from OID string" X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a4a1cf85d3453b99b50c57b356db2d26d088b154;p=thirdparty%2Ffreeradius-server.git allow passing type to "unknown from OID string" --- diff --git a/src/lib/util/dict.h b/src/lib/util/dict.h index e3abfe76d6e..e486df87ee0 100644 --- a/src/lib/util/dict.h +++ b/src/lib/util/dict.h @@ -571,7 +571,7 @@ fr_dict_attr_t *fr_dict_attr_unknown_raw_afrom_da(TALLOC_CTX *ctx, fr_dict_attr fr_slen_t fr_dict_attr_unknown_afrom_oid_substr(TALLOC_CTX *ctx, fr_dict_attr_t const **out, fr_dict_attr_t const *parent, - fr_sbuff_t *in) + fr_sbuff_t *in, fr_type_t type) CC_HINT(nonnull(2,3,4)); int fr_dict_attr_unknown_parent_to_known(fr_dict_attr_t *da, fr_dict_attr_t const *parent); diff --git a/src/lib/util/dict_unknown.c b/src/lib/util/dict_unknown.c index 108e5a8f1bc..7e08ca1e6ba 100644 --- a/src/lib/util/dict_unknown.c +++ b/src/lib/util/dict_unknown.c @@ -347,7 +347,8 @@ fr_dict_attr_t *fr_dict_attr_unknown_raw_afrom_da(TALLOC_CTX *ctx, fr_dict_attr_ * dictionary attributes. * @param[in] parent Attribute to use as the root for resolving OIDs in. * Usually the root of a protocol dictionary. - * @param[in] in of attribute. + * @param[in] in OID string to parse + * @param[in] type data type of the unknown attribute * @return * - The number of bytes parsed on success. * - <= 0 on failure. Negative offset indicates parse error position. @@ -355,7 +356,7 @@ fr_dict_attr_t *fr_dict_attr_unknown_raw_afrom_da(TALLOC_CTX *ctx, fr_dict_attr_ fr_slen_t fr_dict_attr_unknown_afrom_oid_substr(TALLOC_CTX *ctx, fr_dict_attr_t const **out, fr_dict_attr_t const *parent, - fr_sbuff_t *in) + fr_sbuff_t *in, fr_type_t type) { fr_sbuff_t our_in = FR_SBUFF(in); fr_dict_attr_t const *our_parent = parent; @@ -445,7 +446,7 @@ fr_slen_t fr_dict_attr_unknown_afrom_oid_substr(TALLOC_CTX *ctx, fr_type_to_str(our_parent->type)); goto error; } - if (dict_attr_init(&n, our_parent, NULL, num, FR_TYPE_OCTETS, + if (dict_attr_init(&n, our_parent, NULL, num, type, &(dict_attr_args_t){ .flags = &flags }) < 0) goto error; break; } diff --git a/src/lib/util/pair_legacy.c b/src/lib/util/pair_legacy.c index d8a43765859..41791460162 100644 --- a/src/lib/util/pair_legacy.c +++ b/src/lib/util/pair_legacy.c @@ -289,48 +289,49 @@ redo: slen = fr_dict_oid_component(&err, &da, relative->da, &our_in, &bareword_terminals); if (err == FR_DICT_ATTR_NOTFOUND) { if (raw) { - if (fr_sbuff_is_digit(&our_in)) { - slen = fr_dict_attr_unknown_afrom_oid_substr(NULL, &da_unknown, relative->da, &our_in); - if (slen < 0) return fr_sbuff_error(&our_in) + slen; + /* + * We looked up raw.FOO, and FOO wasn't found. The component must be a number. + */ + if (!fr_sbuff_is_digit(&our_in)) goto notfound; - fr_assert(da_unknown); + slen = fr_dict_attr_unknown_afrom_oid_substr(NULL, &da_unknown, relative->da, &our_in, FR_TYPE_OCTETS); + if (slen < 0) return fr_sbuff_error(&our_in) + slen; - /* - * Append from the root list, starting at the root depth. - */ - vp = fr_pair_afrom_da_depth_nested(root->ctx, root->list, da_unknown, - root->da->depth); - fr_dict_attr_unknown_free(&da_unknown); + fr_assert(da_unknown); - if (!vp) return fr_sbuff_error(&our_in); + /* + * Append from the root list, starting at the root depth. + */ + vp = fr_pair_afrom_da_depth_nested(root->ctx, root->list, da_unknown, + root->da->depth); + fr_dict_attr_unknown_free(&da_unknown); - PAIR_VERIFY(vp); + if (!vp) return fr_sbuff_error(&our_in); - /* - * The above function MAY have jumped ahead a few levels. Ensure - * that the relative structure is set correctly for the parent, - * but only if the parent changed. - */ - if (relative->da != vp->da->parent) { - fr_pair_t *parent_vp; + PAIR_VERIFY(vp); - parent_vp = fr_pair_parent(vp); - fr_assert(parent_vp); + /* + * The above function MAY have jumped ahead a few levels. Ensure + * that the relative structure is set correctly for the parent, + * but only if the parent changed. + */ + if (relative->da != vp->da->parent) { + fr_pair_t *parent_vp; - relative->ctx = parent_vp; - relative->da = parent_vp->da; - relative->list = &parent_vp->vp_group; - } + parent_vp = fr_pair_parent(vp); + fr_assert(parent_vp); - /* - * Update the new relative information for the current VP, which - * may be structural, or a key field. - */ - fr_assert(!fr_sbuff_is_char(&our_in, '.')); /* be sure the loop exits */ - goto update_relative; + relative->ctx = parent_vp; + relative->da = parent_vp->da; + relative->list = &parent_vp->vp_group; } - goto notfound; + /* + * Update the new relative information for the current VP, which + * may be structural, or a key field. + */ + fr_assert(!fr_sbuff_is_char(&our_in, '.')); /* be sure the loop exits */ + goto update_relative; } if (internal) {