From: Alan T. DeKok Date: Mon, 3 Apr 2023 17:00:53 +0000 (-0400) Subject: update code and add tests to allow a group on the RHS of edits X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c4d6502368dbf817a8f8092ab5e54fb08289c858;p=thirdparty%2Ffreeradius-server.git update code and add tests to allow a group on the RHS of edits --- diff --git a/src/lib/server/cf_file.c b/src/lib/server/cf_file.c index 8e82d24fb5..1bfeb5814a 100644 --- a/src/lib/server/cf_file.c +++ b/src/lib/server/cf_file.c @@ -2401,7 +2401,7 @@ check_for_eol: * allow it everywhere. */ if (*ptr == '{') { - if (!parent->allow_unlang) { + if (!parent->allow_unlang && !frame->require_edits) { ERROR("%s[%d]: Parse error: Invalid location for grouped attribute", frame->filename, frame->lineno); return -1; diff --git a/src/lib/unlang/edit.c b/src/lib/unlang/edit.c index 7a05b0c526..2c672eb32e 100644 --- a/src/lib/unlang/edit.c +++ b/src/lib/unlang/edit.c @@ -432,12 +432,35 @@ apply_list: } RDEBUG2("}"); - rcode = fr_edit_list_apply_list_assignment(current->el, current->lhs.vp, map->op, children, copy_vps); - if (rcode < 0) RPERROR("Failed performing list %s operation", fr_tokens[map->op]); + if (current->el) { + rcode = fr_edit_list_apply_list_assignment(current->el, current->lhs.vp, map->op, children, copy_vps); + if (rcode < 0) RPERROR("Failed performing list %s operation", fr_tokens[map->op]); + + } else { + fr_assert(map->op == T_OP_EQ); + + if (copy_vps) { + fr_assert(children != ¤t->rhs.pair_list); + fr_assert(fr_pair_list_empty(¤t->rhs.pair_list)); + + if (fr_pair_list_copy(current->lhs.vp, ¤t->rhs.pair_list, children) < 0) { + rcode = 01; + goto done; + } + children = ¤t->rhs.pair_list; + } else { + copy_vps = true; /* the */ + } + + fr_pair_list_append(¤t->lhs.vp->vp_group, children); + PAIR_VERIFY(current->lhs.vp); + rcode = 0; + } /* * If the child list wasn't copied, then we just created it, and we need to free it. */ +done: if (!copy_vps) fr_pair_list_free(children); return rcode; } diff --git a/src/tests/keywords/edit-rhs-group b/src/tests/keywords/edit-rhs-group new file mode 100644 index 0000000000..2334fe2f2f --- /dev/null +++ b/src/tests/keywords/edit-rhs-group @@ -0,0 +1,12 @@ +# +# PRE: edit-list +# +&request += { + &Tmp-Group-0 = {} +} + +if (!&request.Tmp-Group-0) { + test_fail +} + +success