]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
allow modification of leaf attributes in "foreach"
authorAlan T. DeKok <aland@freeradius.org>
Fri, 30 Aug 2024 18:26:28 +0000 (14:26 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Fri, 30 Aug 2024 18:31:20 +0000 (14:31 -0400)
src/lib/unlang/foreach.c
src/tests/keywords/foreach-modify [new file with mode: 0644]

index 91c004ea44cdfa96b70963b9e48550910f089ad2..623a63bab6ea8a8f3a8033ee778caa0d171fb1f8 100644 (file)
@@ -135,6 +135,14 @@ static unlang_action_t unlang_foreach_next(rlm_rcode_t *p_result, request_t *req
 
        if (is_stack_unwinding_to_break(request->stack)) return UNLANG_ACTION_CALCULATE_RESULT;
 
+       vp = fr_dcursor_current(&state->cursor);
+       fr_assert(vp != NULL);
+
+       if (!fr_type_is_structural(vp->vp_type) && (vp->vp_type == state->key->vp_type)) {
+               fr_value_box_clear_value(&vp->data);
+               (void) fr_value_box_copy(vp, &vp->data, &state->key->data);
+       }       
+
 next:
        vp = fr_dcursor_next(&state->cursor);
        if (!vp) {
diff --git a/src/tests/keywords/foreach-modify b/src/tests/keywords/foreach-modify
new file mode 100644 (file)
index 0000000..1115dc5
--- /dev/null
@@ -0,0 +1,27 @@
+#
+#  PRE: foreach
+#
+
+&Tmp-Integer-0 := { 1, 3, 5, 11 }
+
+foreach uint32 self (&Tmp-Integer-0) {
+       &self += 19
+}
+
+if (&Tmp-Integer-0[0] != 20) {
+       test_fail
+}
+
+if (&Tmp-Integer-0[1] != 22) {
+       test_fail
+}
+
+if (&Tmp-Integer-0[2] != 24) {
+       test_fail
+}
+
+if (&Tmp-Integer-0[3] != 30) {
+       test_fail
+}
+
+success