From: Alan T. DeKok Date: Tue, 4 Jul 2023 19:14:37 +0000 (-0400) Subject: use pair_append_by_tmpl_parent() instead of fr_pair_afrom_da() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4ea5035acd640a668a0e61d15ad9a9c0cfa80443;p=thirdparty%2Ffreeradius-server.git use pair_append_by_tmpl_parent() instead of fr_pair_afrom_da() as the tmpl function finds or creates all of the pairs in the map. The mschap tests expected that to work: &request += { &Vendor-Specific.Microsoft.CHAP-Challenge = 0xe96e4fff2955c4f1 &Vendor-Specific.Microsoft.CHAP-Response = 0x000100000... } Would create: &request { CHAP-Challenge = ... CHAP-Response = ... } which was wrong --- diff --git a/src/lib/unlang/edit.c b/src/lib/unlang/edit.c index 2e226ec3db7..0fca5423f63 100644 --- a/src/lib/unlang/edit.c +++ b/src/lib/unlang/edit.c @@ -580,18 +580,23 @@ static int apply_edits_to_leaf(request_t *request, unlang_frame_state_edit_t *st * the appropriate place. */ if (current->temporary_pair_list) { - fr_dict_attr_t const *da = tmpl_attr_tail_da(current->lhs.vpt); fr_pair_list_t *list = ¤t->parent->rhs.pair_list; + fr_pair_t *vp; while (box) { - fr_pair_t *vp; + /* + * Create (or find) all intermediate attributes. The LHS map might have multiple + * attribute names in it. + * + * @todo - audit other uses of tmpl_attr_tail_da() and fr_pair_afrom_da() in this file. + */ + if (pair_append_by_tmpl_parent(current->parent->lhs.vp, &vp, list, current->lhs.vpt, true) < 0) { + RWDEBUG("Failed creating attribute %s", current->lhs.vpt->name); + return -1; + } - MEM(vp = fr_pair_afrom_da(current->parent->lhs.vp, da)); vp->op = map->op; if (fr_value_box_cast(vp, &vp->data, vp->da->type, vp->da, box) < 0) return -1; - if (fr_pair_append(list, vp) < 0) return -1; - -// RDEBUG2("%s %s %pV", current->lhs.vpt->name, fr_tokens[map->op], &vp->data); if (single) break; diff --git a/src/tests/keywords/all.mk b/src/tests/keywords/all.mk index 7ba440e24db..8160ec66aeb 100644 --- a/src/tests/keywords/all.mk +++ b/src/tests/keywords/all.mk @@ -71,7 +71,7 @@ KEYWORD_UPDATE_TESTS := update-attr-ref-null update-error-3 update-group-error u KEYWORD_UPDATE_REWRITE_TESTS := update-all update-array update-delete update-remove-any update-group update-hex update-remove-value update-index update-list-error update-remove-list update-prepend unknown-update update-error update-error-2 update-exec-error update-list-null-rhs update-exec # Tests which can use new conditions, but which can't use tmpl_tokenize_all_nested=yes -KEYWORD_UPDATE_TMPL_TESTS := foreach-regex mschap pairs xlat-dhcpv4 +KEYWORD_UPDATE_TMPL_TESTS := foreach-regex pairs xlat-dhcpv4 # # Migration support. Some of the tests don't run under the new