From: Alan T. DeKok Date: Thu, 13 Jul 2023 16:12:16 +0000 (-0400) Subject: add -S pair_legacy_nested=true X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a72047520de4236cd8506e03982120738625535a;p=thirdparty%2Ffreeradius-server.git add -S pair_legacy_nested=true 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. --- diff --git a/src/lib/util/pair.c b/src/lib/util/pair.c index 1bad0bc823a..27867ebab40 100644 --- a/src/lib/util/pair.c +++ b/src/lib/util/pair.c @@ -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; diff --git a/src/tests/keywords/all.mk b/src/tests/keywords/all.mk index 68ff6355709..8845f95e5fe 100644 --- a/src/tests/keywords/all.mk +++ b/src/tests/keywords/all.mk @@ -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