]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
allow removal of attributes by index
authorAlan T. DeKok <aland@freeradius.org>
Sun, 22 Oct 2023 15:46:19 +0000 (11:46 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Sun, 22 Oct 2023 15:46:19 +0000 (11:46 -0400)
this is the start of porting update-remove-index, which currently
doesn't work for a host of reasons.

We should probably remove the syntax of &list -= &attr, as it is
now duplicative, and we don't like that.

src/lib/unlang/edit.c
src/tests/keywords/edit-remove-index [new file with mode: 0644]

index c9ed89b00caa3c13daa40fd8f781318108c2c91a..fba9e2dfc59fd853ba9699ae377997b6dc45119f 100644 (file)
@@ -867,7 +867,7 @@ static int check_rhs(request_t *request, unlang_frame_state_edit_t *state, edit_
         *
         *      The we just apply the assignment to the LHS, over-writing it's value.
         */
-       if ((map->op == T_OP_SET) && (tmpl_attr_tail_num(current->lhs.vpt) == NUM_UNSPEC)) {
+       if ((map->op == T_OP_SET) && ((tmpl_attr_tail_num(current->lhs.vpt) == NUM_UNSPEC) || !current->map->rhs)) {
                tmpl_dcursor_ctx_t cc;
                fr_dcursor_t cursor;
                bool first = fr_type_is_structural(tmpl_attr_tail_da(current->lhs.vpt)->type);
@@ -1313,7 +1313,8 @@ static int check_lhs(request_t *request, unlang_frame_state_edit_t *state, edit_
                 *
                 *      because foo[3] is a single leaf value, not a list.
                 */
-               if (!map->rhs && fr_type_is_leaf(tmpl_attr_tail_da(current->lhs.vpt)->type)) {
+               if (!map->rhs && fr_type_is_leaf(tmpl_attr_tail_da(current->lhs.vpt)->type) &&
+                   (map_list_num_elements(&map->child) > 0)) {
                        RWDEBUG("Cannot set one entry to multiple values for %s", current->lhs.vpt->name);
                        return -1;
                }
diff --git a/src/tests/keywords/edit-remove-index b/src/tests/keywords/edit-remove-index
new file mode 100644 (file)
index 0000000..bf2a987
--- /dev/null
@@ -0,0 +1,27 @@
+#
+#  PRE: if edit
+#
+&request += {
+       &Tmp-IP-Address-0 = 192.0.2.1
+       &Tmp-IP-Address-0 = 192.0.2.2
+}
+
+#
+#  Delete only the second one
+#
+&request.Tmp-IP-Address-0[1] := {}
+
+#
+#  Attribute 'Tmp-IP-Address[1]' not found.
+#
+#&request -= &Tmp-IP-Address[1]
+
+if (&Tmp-IP-Address-0[#] != 1) {
+       test_fail
+}
+
+if !(&Tmp-IP-Address-0[0] == 192.0.2.1) {
+       test_fail
+}
+
+success