]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
allow passing type to "unknown from OID string"
authorAlan T. DeKok <aland@freeradius.org>
Mon, 11 Nov 2024 12:09:57 +0000 (07:09 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 11 Nov 2024 15:46:17 +0000 (10:46 -0500)
src/lib/util/dict.h
src/lib/util/dict_unknown.c
src/lib/util/pair_legacy.c

index e3abfe76d6e502508670307f6abdd8126b8baae6..e486df87ee04cdde0c2a9642c2f60b85501dd629 100644 (file)
@@ -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);
index 108e5a8f1bcb7a906694df303dd541cadc6cf25f..7e08ca1e6ba6387d05b0fa0e5f6870522760e7d6 100644 (file)
@@ -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;
                        }
index d8a43765859c8ad3dfc7aacacd26f1981fb66f0d..41791460162c65a375258a28589bd34af9976559 100644 (file)
@@ -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) {