]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
allow attr names in update to have list references
authorAlan T. DeKok <aland@freeradius.org>
Thu, 17 Nov 2022 18:07:13 +0000 (13:07 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Thu, 17 Nov 2022 20:49:43 +0000 (15:49 -0500)
because "update request" just changes the default list, it doesn't
require that list be used.

src/lib/unlang/compile.c
src/tests/keywords/all.mk
src/tests/keywords/update-attr-ref-null

index 1b00c573a055fcebe1c35acb5a85c01154834a71..85d8a626c39e78dec43121e4941018fcf3876504 100644 (file)
@@ -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;
                        }
                }
index d04b5f9634045c3cccb997df929a7af1ba13e445..25d31605673b6fe820b04958b86abf576829df20 100644 (file)
@@ -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
index 3df91574800de36553d2d827be45c656ffe28f31..599ae69d3b010539da2c1e9e5138495e50086743 100644 (file)
@@ -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
 }