]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
handle key fields in unflatten
authorAlan T. DeKok <aland@freeradius.org>
Mon, 21 Aug 2023 15:17:18 +0000 (11:17 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 21 Aug 2023 15:17:18 +0000 (11:17 -0400)
src/lib/util/pair.c

index 664ccba325f3b67fa496347f0e4699c95da573cc..63c46457ccb0bf9d94ceadefbe4e60685fff624c 100644 (file)
@@ -3399,7 +3399,15 @@ static fr_pair_t *pair_alloc_parent(fr_pair_t *in, fr_pair_t *item, fr_dict_attr
 
        /*
         *      We should never be called with a leaf da.
+        *
+        *      If we're asked to create children of a keyed
+        *      structure, just create the children in the parent.
         */
+       if (!fr_type_is_structural(da->type)) {
+               fr_assert(fr_dict_attr_is_key_field(da));
+               da = da->parent;
+       }
+
        fr_assert(fr_type_is_structural(da->type));
 
        /*
@@ -3475,7 +3483,8 @@ static int pair_reparent_struct(fr_pair_t *parent, fr_pair_t *item, fr_pair_t *i
        for (vp = fr_pair_list_head(&in->vp_group); vp; vp = next) {
                next = fr_pair_list_next(&in->vp_group, vp);
 
-               fr_assert((vp->da->parent == parent->da) || (parent->vp_type == FR_TYPE_GROUP) || (parent->vp_type == FR_TYPE_VENDOR));
+               fr_assert((vp->da->parent == parent->da) || (parent->vp_type == FR_TYPE_GROUP) || (parent->vp_type == FR_TYPE_VENDOR) ||
+                         (fr_dict_attr_is_key_field(vp->da->parent) && vp->da->parent->parent == parent->da));
 
                /*
                 *      If we need a new parent, allocate it.
@@ -3645,6 +3654,12 @@ int fr_pair_unflatten(fr_pair_t *in)
                        continue;
                }
 
+               /*
+                *      Sub-structures are put into their parent.
+                */
+               if (fr_dict_attr_is_key_field(vp->da->parent) &&
+                   fr_pair_parent(vp) == in) continue;
+
                /*
                 *      Allocate or find the parent attribute.
                 *