From: Alan T. DeKok Date: Thu, 17 Nov 2022 18:07:13 +0000 (-0500) Subject: allow attr names in update to have list references X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1eb5a1c2b593165604b700951f6ddb00799d08f4;p=thirdparty%2Ffreeradius-server.git allow attr names in update to have list references because "update request" just changes the default list, it doesn't require that list be used. --- diff --git a/src/lib/unlang/compile.c b/src/lib/unlang/compile.c index 1b00c573a05..85d8a626c39 100644 --- a/src/lib/unlang/compile.c +++ b/src/lib/unlang/compile.c @@ -1360,9 +1360,11 @@ static unlang_t *compile_update_to_edit(unlang_t *parent, unlang_compile_t *unla * Hoist this out of the loop, and make sure it always has a '&' prefix. */ if (name2) { - snprintf(list_buffer, sizeof(list_buffer), "&%s", name2); - list = list_buffer; + snprintf(list_buffer, sizeof(list_buffer), "&%s", name2); + } else { + snprintf(list_buffer, sizeof(list_buffer), "&%s", fr_table_str_by_value(pair_list_table, unlang_ctx->rules->attr.list_def, "???")); } + list = list_buffer; /* * Loop over the entries, rewriting them. @@ -1392,13 +1394,14 @@ static unlang_t *compile_update_to_edit(unlang_t *parent, unlang_compile_t *unla */ if (*attr == '&') attr++; + list = list_buffer; + /* - * Parse the LHS attribute reference for request ref and pair list ref. - * - * All of the other tmpl functions do full parsing into tmpls, which we don't want. We - * just want to know how long the prefix is. + * Separate out the various possibilities for the + * "name", which could be a list, an attribute + * name, or a list followed by an attribute name. */ - if (!name2) { + { char const *p, *q; p = attr; @@ -1434,15 +1437,12 @@ static unlang_t *compile_update_to_edit(unlang_t *parent, unlang_compile_t *unla } /* - * Move the list to a separate buffer. + * Separate the list reference from the attribute reference. */ if (p > (attr + 1)) { snprintf(ref_buffer, sizeof(ref_buffer), "&%.*s", (int) (p - attr) - 1, attr); list = ref_buffer; - /* - * Move the attribute name to a separate buffer. - */ if (*p) { attr = p; @@ -1450,16 +1450,13 @@ static unlang_t *compile_update_to_edit(unlang_t *parent, unlang_compile_t *unla attr = NULL; } - } else if (p) { + } else if (!p) { /* - * There is no list reference, so print out the default one. + * No trailing attribute name, the entire thing is a list + * + * @todo - handle &control[*] */ - snprintf(ref_buffer, sizeof(ref_buffer), "&%s", fr_table_str_by_value(pair_list_table, unlang_ctx->rules->attr.list_def, "???")); - list = ref_buffer; - - } else { - snprintf(ref_buffer, sizeof(ref_buffer), "&%s", attr); - list = ref_buffer; + list = cf_pair_attr(cp); attr = NULL; } } diff --git a/src/tests/keywords/all.mk b/src/tests/keywords/all.mk index d04b5f96340..25d31605673 100644 --- a/src/tests/keywords/all.mk +++ b/src/tests/keywords/all.mk @@ -42,9 +42,9 @@ test.keywords.help: TEST_KEYWORDS_HELP += test.keywords.${1} # # All of the "update" tests which should also be run with "-S rewrite_update=yes" # -KEYWORD_UPDATE_TESTS := update-attr-ref-null update-error-3 update-group-error update-filter update-list-error update-list-null-rhs update-null-value-assign update-remove-index update-exec +KEYWORD_UPDATE_TESTS := update-attr-ref-null update-error-3 update-group-error update-filter update-list-error update-null-value-assign update-remove-index update-exec -KEYWORD_UPDATE_REWRITE_TESTS := update-all update-array update-delete update-remove-any update-group update-hex update-remove-value update-index update-remove-list update-prepend unknown-update update-error update-error-2 update-exec-error +KEYWORD_UPDATE_REWRITE_TESTS := update-all update-array update-delete update-remove-any update-group update-hex update-remove-value update-index update-remove-list update-prepend unknown-update update-error update-error-2 update-exec-error update-list-null-rhs # # Migration support. Some of the tests don't run under the new diff --git a/src/tests/keywords/update-attr-ref-null b/src/tests/keywords/update-attr-ref-null index 3df91574800..599ae69d3b0 100644 --- a/src/tests/keywords/update-attr-ref-null +++ b/src/tests/keywords/update-attr-ref-null @@ -7,11 +7,6 @@ update request { &Tmp-String-0 += 'foo' &Tmp-String-0 += 'bar' &Tmp-String-1 += 'baz' - - # - # @fixme - EDIT - There's already a list! WTF is going on here? - # this should be forbidden! - # &control !* ANY }