]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
allow operations on list which has some immutable values
authorAlan T. DeKok <aland@freeradius.org>
Mon, 21 Aug 2023 00:48:00 +0000 (20:48 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 21 Aug 2023 00:48:00 +0000 (20:48 -0400)
src/lib/unlang/edit.c
src/tests/keywords/immutable

index d833c347d00b873350c79503615fff966c3f8ac3..c3f6a357112538120b681c2b617c7b8706680aec 100644 (file)
@@ -357,7 +357,7 @@ static int apply_edits_to_list(request_t *request, unlang_frame_state_edit_t *st
                 */
                RDEBUG2("%s %s %s", current->lhs.vpt->name, fr_tokens[T_OP_SUB_EQ], current->rhs.vpt->name);
 
-               while (vp) {
+               for ( ; vp != NULL; vp = next) {
                        fr_pair_list_t *list;
 
                        next = fr_dcursor_next(&cursor);
@@ -365,12 +365,12 @@ static int apply_edits_to_list(request_t *request, unlang_frame_state_edit_t *st
                        list = fr_pair_parent_list(vp);
                        fr_assert(list != NULL);
 
+                       if (fr_pair_immutable(vp)) continue;
+
                        if (fr_edit_list_pair_delete(current->el, list, vp) < 0) {
                                tmpl_dcursor_clear(&cc);
                                return -1;
                        }
-
-                       vp = next;
                }
 
                tmpl_dcursor_clear(&cc);
@@ -1336,7 +1336,13 @@ static int check_lhs(request_t *request, unlang_frame_state_edit_t *state, edit_
                // &control := ...
        }
 
-       if (fr_pair_immutable(vp)) {
+       /*
+        *      We forbid operations on immutable leaf attributes.
+        *
+        *      If a list contains an immutable attribute, then we can still operate on the list, but instead
+        *      we look at each VP we're operating on.
+        */
+       if (fr_type_is_leaf(vp->vp_type) && vp->vp_immutable) {
                RWDEBUG("Cannot modify immutable value for %s", current->lhs.vpt->name);
                return -1;
        }
index bd21f1071a7ee925da0765ff03b5073045fe9fde..c926c04e14e9e85280ef57e9da64224534de5909 100644 (file)
@@ -52,4 +52,26 @@ if !(&Tmp-Integer-0 == 1814) {
        test_fail
 }
 
+#
+#  Add a non-immutable NAS-Port
+#
+&request += {
+       &NAS-Port = 6809
+}
+
+debug_request
+
+if !(&NAS-Port[1] == 6809) {
+       test_fail
+}
+
+&request -= &NAS-Port[*]
+if !(&NAS-Port == 1813) {
+       test_fail
+}
+
+if (&NAS-Port[#] != 1) {
+       test_fail
+}
+
 success