]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
arguments to "case" MUST be static data
authorAlan T. DeKok <aland@freeradius.org>
Tue, 6 Apr 2021 14:44:35 +0000 (10:44 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 6 Apr 2021 14:45:48 +0000 (10:45 -0400)
in preparation for moving to rbtrees / hashes / patricia tries
for "case" statement values

src/lib/unlang/compile.c
src/tests/keywords/switch
src/tests/keywords/switch-attr-cast [deleted file]
src/tests/keywords/switch-attr-cmp [deleted file]
src/tests/keywords/switch-case-error [new file with mode: 0644]
src/tests/keywords/switch-value-error

index 52d8b36267ed7bdfdf00c494c24c6e7537725a96..c03d54375da920f0e04ae431a064757bc6dca3be 100644 (file)
@@ -2107,42 +2107,20 @@ static unlang_t *compile_case(unlang_t *parent, unlang_compile_t *unlang_ctx, CO
                        return NULL;
                }
 
-               if (tmpl_is_attr_unresolved(vpt)) {
-                       if (!pass2_fixup_tmpl(parent, cf_section_to_item(cs), &vpt)) {
-                               talloc_free(vpt);
-                               return NULL;
-                       }
-               }
-
                switch_g = unlang_generic_to_group(parent);
                switch_gext = unlang_group_to_switch(switch_g);
                fr_assert(switch_gext->vpt != NULL);
 
                /*
-                *      Do type-specific checks on the case statement
-                */
-               if (tmpl_is_list(vpt)) {
-                       cf_log_perr(cs, "Cannot use list for target of 'case' statement");
-                       talloc_free(vpt);
-                       return NULL;
-               }
-
-               if (tmpl_contains_regex(vpt)) {
-                       cf_log_err(cs, "Cannot use regular expression for target of 'case' statement");
-                       talloc_free(vpt);
-                       return NULL;
-               }
-
-               /*
-                *      This "case" statement is unresolved.  Try to
-                *      resolve it to the data type of the parent
-                *      "switch" tmpl.
+                *      This "case" statement is unresolved.  Try to
+                *      resolve it to the data type of the parent
+                *      "switch" tmpl.
                 */
                if (tmpl_is_unresolved(vpt)) {
                        fr_type_t cast_type = switch_gext->vpt->cast;
                        fr_dict_attr_t const *da = NULL;
 
-                       if (tmpl_is_attr(switch_gext->vpt)) da = tmpl_da(switch_gext->vpt);
+                       if (tmpl_is_attr(switch_gext->vpt)) da = tmpl_da(switch_gext->vpt);
 
                        if (fr_type_is_null(cast_type) && da) cast_type = da->type;
 
@@ -2153,26 +2131,10 @@ static unlang_t *compile_case(unlang_t *parent, unlang_compile_t *unlang_ctx, CO
                        }
                }
 
-               /*
-                *      Compile and sanity check xlat
-                *      expansions.
-                */
-               if (tmpl_is_xlat_unresolved(vpt)) {
-                       /*
-                        *      Don't expand xlat's into an
-                        *      attribute of a different type.
-                        */
-                       if (!pass2_fixup_tmpl(parent, cf_section_to_item(cs), &vpt)) {
-                               talloc_free(vpt);
-                               return NULL;
-                       }
-               }
-
-               if (tmpl_is_exec(vpt)) {
-                       if (!pass2_fixup_tmpl(parent, cf_section_to_item(cs), &vpt)) {
-                               talloc_free(vpt);
-                               return NULL;
-                       }
+               if (!tmpl_is_data(vpt)) {
+                       talloc_free(vpt);
+                       cf_log_err(cs, "arguments to 'case' statements MUST be static data.");
+                       return NULL;
                }
        } /* else it's a default 'case' statement */
 
index d50e2f636ee86327604dab35ca48546932959011..5932accf85ca874466287b27d8477202df10b228 100644 (file)
@@ -9,7 +9,7 @@ switch &User-Name {
                }
        }
 
-       case {
+       default {
                update reply {
                        &Filter-Id := "default"
                }
diff --git a/src/tests/keywords/switch-attr-cast b/src/tests/keywords/switch-attr-cast
deleted file mode 100644 (file)
index 7b6f383..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-#
-#  PRE: switch switch-attr-cmp
-#
-
-update request {
-       &Service-Type := Login-User
-       &Filter-Id := "Login-User"
-}
-
-switch &Service-Type {
-       case "%{expr: 1 + 2}" {
-               test_fail
-       }
-
-       #
-       #  The Filter-Id will get printed to a string,
-       #  have the string parsed as a Service-Type attr,
-       #  and then that compared to the input Service-Type
-       #
-       case &Filter-Id {
-               success
-       }
-
-       default {
-               test_fail
-       }
-
-}
diff --git a/src/tests/keywords/switch-attr-cmp b/src/tests/keywords/switch-attr-cmp
deleted file mode 100644 (file)
index 1c1bf0d..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-#
-#  PRE: switch
-#
-update request {
-       &Tmp-String-0 := &User-Name
-}
-
-#
-#  A switch statement where we compare two attributes
-#
-switch &User-Name {
-       case &Tmp-String-0 {
-               success
-       }
-
-       case "bob" {
-               test_fail
-       }
-
-       case "doug" {
-               test_fail
-       }
-
-       default {
-               test_fail
-       }
-
-}
diff --git a/src/tests/keywords/switch-case-error b/src/tests/keywords/switch-case-error
new file mode 100644 (file)
index 0000000..c62dceb
--- /dev/null
@@ -0,0 +1,17 @@
+switch &User-Name {
+       case "%{Filter-Id}" {   # ERROR
+               success
+       }
+
+       case "doug" {
+               update reply {
+                       &Filter-Id := "doug"
+               }
+       }
+
+       default {
+               update reply {
+                       &Filter-Id := "default"
+               }
+       }
+}
index e3cf1094f1064aeb58abb3b051c27c641824d69e..bb1fcfd37e273bc21827bc4306794428a2966561 100644 (file)
@@ -2,10 +2,6 @@
 #  PRE: switch
 #
 switch &Service-Type {
-       case "%{expr: 1 + 2}" {
-               test_fail
-       }
-
        case Login-User {
                test_fail
        }