]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
add -S pair_legacy_nested=true
authorAlan T. DeKok <aland@freeradius.org>
Thu, 13 Jul 2023 16:12:16 +0000 (12:12 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Thu, 13 Jul 2023 17:30:32 +0000 (13:30 -0400)
and set it for keyword tests.

Except for map-xlat-struct, which calls fr_pair_afrom_da_depth_nested()
with a struct that has a "key" field.

update pair.c to correctly create and auto-populate the key field,
and create the child struct correctly.

map-xlat-struct fails because the output now contains a key field,
and is nested.  But that is easy enough to fix when we move over
to fully nested.

src/lib/util/pair.c
src/tests/keywords/all.mk

index 1bad0bc823a625f849ca1df8e3cfd2df699a50a5..27867ebab4041ce9bda42fbc552fd31e989d1bd3 100644 (file)
@@ -461,7 +461,7 @@ fr_pair_t *fr_pair_afrom_child_num(TALLOC_CTX *ctx, fr_dict_attr_t const *parent
  */
 fr_pair_t *fr_pair_afrom_da_depth_nested(TALLOC_CTX *ctx, fr_pair_list_t *list, fr_dict_attr_t const *da, int start)
 {
-       fr_pair_t               *vp;
+       fr_pair_t               *vp, *key_vp = NULL;
        unsigned int            i;
        TALLOC_CTX              *cur_ctx;
        fr_dict_attr_t const    *find;          /* DA currently being looked for */
@@ -475,6 +475,12 @@ fr_pair_t *fr_pair_afrom_da_depth_nested(TALLOC_CTX *ctx, fr_pair_list_t *list,
        for (i = start; i <= da->depth; i++) {
                find = da_stack.da[i];
 
+               if (key_vp) {
+                       fr_assert(find->type == FR_TYPE_STRUCT);
+                       key_vp->vp_uint32 = find->attr;
+                       key_vp = NULL;
+               }
+
                vp = fr_pair_find_by_da(cur_list, NULL, find);
                if (!vp || (vp->da == da)) {
                        if  (fr_pair_append_by_da(cur_ctx, &vp, cur_list, find) < 0) return NULL;
@@ -482,6 +488,16 @@ fr_pair_t *fr_pair_afrom_da_depth_nested(TALLOC_CTX *ctx, fr_pair_list_t *list,
 
                if (find == da) return vp;
 
+               /*
+                *      Create the key field, but do _not_ put the child struct into it.  Instead, the child
+                *      struct goes appended into this struct.  However, we _do_ automatically set the value
+                *      of the key field, depending on the number of the child structure.
+                */
+               if (fr_dict_attr_is_key_field(find)) {
+                       key_vp = vp;
+                       continue;
+               }
+
                fr_assert(fr_type_is_structural(vp->da->type));
 
                cur_ctx = vp;
index 68ff635570918991269d4413f43438de9754c81e..8845f95e5fef94e75c358859c4394f6fac340e18 100644 (file)
@@ -73,6 +73,9 @@ KEYWORD_UPDATE_REWRITE_TESTS := update-all update-array update-delete update-rem
 # Tests which can use new conditions, but which can't use tmpl_tokenize_all_nested=yes
 KEYWORD_UPDATE_TMPL_TESTS      := foreach-regex xlat-dhcpv4
 
+# Tests which can't use pair_legacy_nested=yes
+KEYWORD_PAIR_LEGACY_TESTS      := map-xlat-struct
+
 #
 #  Migration support.  Some of the tests don't run under the new
 #  conditions, so we don't run them under the new conditions.
@@ -88,8 +91,10 @@ $(OUTPUT)/${1}: NEW_COND=-S use_new_conditions=yes -S rewrite_update=yes
 
 else ifneq "$(findstring ${1}, $(KEYWORD_UPDATE_TMPL_TESTS))" ""
 $(OUTPUT)/${1}: NEW_COND=-S use_new_conditions=yes -S forbid_update=yes
-else
+else ifneq "$(findstring ${1}, $(KEYWORD_PAIR_LEGACY_TESTS))" ""
 $(OUTPUT)/${1}: NEW_COND=-S use_new_conditions=yes -S forbid_update=yes -S tmpl_tokenize_all_nested=yes
+else
+$(OUTPUT)/${1}: NEW_COND=-S use_new_conditions=yes -S forbid_update=yes -S tmpl_tokenize_all_nested=yes -S pair_legacy_nested=true
 
 ifeq "${1}" "mschap"
 $(OUTPUT)/${1}: $(BUILD_DIR)/lib/rlm_mschap.la