From: Alan T. DeKok Date: Sun, 22 Oct 2023 15:46:19 +0000 (-0400) Subject: allow removal of attributes by index X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3ebd2ea2ecdb03127e8f3d85e0dafc3daffb3033;p=thirdparty%2Ffreeradius-server.git allow removal of attributes by index 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. --- diff --git a/src/lib/unlang/edit.c b/src/lib/unlang/edit.c index c9ed89b00ca..fba9e2dfc59 100644 --- a/src/lib/unlang/edit.c +++ b/src/lib/unlang/edit.c @@ -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 index 00000000000..bf2a9875622 --- /dev/null +++ b/src/tests/keywords/edit-remove-index @@ -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