]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
move to protocol::enum for subrequest
authorAlan T. DeKok <aland@freeradius.org>
Thu, 5 Sep 2024 23:56:18 +0000 (19:56 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Thu, 5 Sep 2024 23:56:18 +0000 (19:56 -0400)
because 'foo.bar' is an attribute reference when there's no "&",
so we can't use "dhcpv4.Discover"

src/lib/server/cf_file.c
src/lib/unlang/compile.c

index 82a05820086bd6ff98a47ab8b91631746d3eb2a2..01ee69f9883c7eb7bfe282baf12bbdc80eb81879 100644 (file)
@@ -1797,11 +1797,6 @@ static CONF_ITEM *process_subrequest(cf_stack_t *stack)
                return NULL;
        }
 
-       if (token != T_BARE_WORD) {
-               ERROR("%s[%d]: The first argument to 'subrequest' must be a name or an attribute reference",
-                     frame->filename, frame->lineno);
-               return NULL;
-       }
        mod = buff[1];
 
         /*
index 0883c64657f0362f5b6702a996aeaeffff8c1974..c3f6c0306a6cb9d26bf7582be15fcab1b4033713 100644 (file)
@@ -3958,7 +3958,7 @@ static unlang_t *compile_subrequest(unlang_t *parent, unlang_compile_t *unlang_c
 
        char                            *namespace = NULL;
        char const                      *packet_name = NULL;
-       char                            *p;
+       char                            *p = NULL;
 
        tmpl_t                          *vpt = NULL, *src_vpt = NULL, *dst_vpt = NULL;
 
@@ -4001,8 +4001,11 @@ static unlang_t *compile_subrequest(unlang_t *parent, unlang_compile_t *unlang_c
 
        /*
         *      If !tmpl_require_enum_prefix, '&' means "attribute reference".
+        *
+        *      Or, bare word means "attribute reference".
         */
-       if (name2[0] == '&') {
+       if ((name2[0] == '&') ||
+           (tmpl_require_enum_prefix && ((p = strchr(name2, ':')) == NULL))) {
                size_t slen;
 
                slen = tmpl_afrom_attr_substr(parent, NULL, &vpt,
@@ -4034,6 +4037,37 @@ static unlang_t *compile_subrequest(unlang_t *parent, unlang_compile_t *unlang_c
                goto get_packet_type;
        }
 
+       /*
+        *      subrequest foo::bar { ... }
+        *
+        *      Change to dictionary "foo", packet type "bar".
+        */
+       if (p) {
+               if (p[1] != ':') {
+                       cf_log_err(cs, "Invalid syntax in namespace::enum");
+                       return NULL;
+               }
+
+               MEM(namespace = talloc_strdup(parent, name2)); /* get a modifiable copy */
+
+               p = namespace + (p - name2);
+               *p = '\0';
+               p += 2;
+               packet_name = p;
+
+               dict = fr_dict_by_protocol_name(namespace);
+               if (!dict) {
+                       dict_ref = fr_dict_autoload_talloc(NULL, &dict, namespace);
+                       if (!dict_ref) {
+                               cf_log_err(cs, "Unknown namespace '%s'", namespace);
+                               talloc_free(namespace);
+                               return NULL;
+                       }
+               }
+
+               goto get_packet_type;
+       }
+
        /*
         *      subrequest foo { ... }
         *
@@ -4044,7 +4078,7 @@ static unlang_t *compile_subrequest(unlang_t *parent, unlang_compile_t *unlang_c
                dict = unlang_ctx->rules->attr.dict_def;
                packet_name = name2;
 
-       } else {
+       } else if (!tmpl_require_enum_prefix) {
                /*
                 *      subrequest foo.bar { ... }
                 *
@@ -4065,6 +4099,17 @@ static unlang_t *compile_subrequest(unlang_t *parent, unlang_compile_t *unlang_c
                                return NULL;
                        }
                }
+
+               WARN("Deprecated syntax 'subrequest %s ...'", name2);
+               WARN(" please switch to 'subrequest %s::%s ...", namespace, packet_name);
+
+       } else {
+               /*
+                *      We have tmpl_require_enum prefix, so bare word foo.bar is "attribute foo,
+                *      sub-attribute bar"
+                */
+               dict = unlang_ctx->rules->attr.dict_def;
+               packet_name = name2;
        }
 
        /*