]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
update code and add tests to allow a group on the RHS of edits
authorAlan T. DeKok <aland@freeradius.org>
Mon, 3 Apr 2023 17:00:53 +0000 (13:00 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 3 Apr 2023 19:14:02 +0000 (15:14 -0400)
src/lib/server/cf_file.c
src/lib/unlang/edit.c
src/tests/keywords/edit-rhs-group [new file with mode: 0644]

index 8e82d24fb5822cdbc84f527001d5105bad9ffa80..1bfeb5814a637b0dc9b6b7a87cec5f1da45edcb1 100644 (file)
@@ -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;
index 7a05b0c526438dd526496000d856d8afbaa3effc..2c672eb32e0368103b225ce5fc6485b7d1a7c125 100644 (file)
@@ -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 != &current->rhs.pair_list);
+                       fr_assert(fr_pair_list_empty(&current->rhs.pair_list));
+
+                       if (fr_pair_list_copy(current->lhs.vp, &current->rhs.pair_list, children) < 0) {
+                               rcode = 01;
+                               goto done;
+                       }
+                       children = &current->rhs.pair_list;
+               } else {
+                       copy_vps = true; /* the  */
+               }
+
+               fr_pair_list_append(&current->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 (file)
index 0000000..2334fe2
--- /dev/null
@@ -0,0 +1,12 @@
+#
+#  PRE: edit-list
+#
+&request += {
+       &Tmp-Group-0 = {}
+}
+
+if (!&request.Tmp-Group-0) {
+       test_fail
+}
+
+success