]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
add "require_enum_prefix" migration flag
authorAlan T. DeKok <aland@freeradius.org>
Sat, 17 Aug 2024 12:55:42 +0000 (08:55 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Sat, 17 Aug 2024 13:07:37 +0000 (09:07 -0400)
in preparation for moving to ::enum-name everywhere, which then
lets us drop the "&" prefix for attribute names

src/lib/server/base.c
src/lib/server/main_config.c
src/lib/server/main_config.h
src/lib/server/map.c
src/lib/server/tmpl_tokenize.c
src/tests/keywords/radius.conf

index 21c31a3b5a7902e5e8e52b6e1c200a530d380e22..c2bc55739935417f963211acf93674fb72913f28 100644 (file)
@@ -32,6 +32,8 @@ RCSID("$Id$")
 #include <freeradius-devel/server/packet.h>
 #include <freeradius-devel/unlang/xlat.h>
 
+extern bool tmpl_require_enum_prefix;
+
 /** Initialize src/lib/server/
  *
  *  This is just so that the callers don't need to call a million functions.
@@ -104,6 +106,8 @@ int server_init(CONF_SECTION *cs)
         */
        if (packet_global_init() < 0) return -1;
 
+       tmpl_require_enum_prefix = main_config_migrate_option_get("require_enum_prefix");
+
        return 0;
 }
 
index bda0592a6357d1f1274c337bf0802d43a9e63c42..e4c55dac887c764cab5c137a431e3d10f7b6497e 100644 (file)
@@ -190,6 +190,7 @@ static const conf_parser_t thread_config[] = {
 static const conf_parser_t migrate_config[] = {
        { FR_CONF_OFFSET_FLAGS("rewrite_update", CONF_FLAG_HIDDEN, main_config_t, rewrite_update) },
        { FR_CONF_OFFSET_FLAGS("forbid_update", CONF_FLAG_HIDDEN, main_config_t, forbid_update) },
+       { FR_CONF_OFFSET_FLAGS("require_enum_prefix", CONF_FLAG_HIDDEN, main_config_t, require_enum_prefix) },
 
        CONF_PARSER_TERMINATOR
 };
@@ -1503,6 +1504,7 @@ void main_config_hup(main_config_t *config)
 static fr_table_num_ordered_t config_arg_table[] = {
        { L("rewrite_update"),           offsetof(main_config_t, rewrite_update) },
        { L("forbid_update"),            offsetof(main_config_t, forbid_update) },
+       { L("require_enum_prefix"),      offsetof(main_config_t, require_enum_prefix) },
 };
 static size_t config_arg_table_len = NUM_ELEMENTS(config_arg_table);
 
index 365c7951fa8a822ab167f616f0009cf1e7cb55a3..be5dd37608b57f159641c00dce570c57dd355f7b 100644 (file)
@@ -161,6 +161,7 @@ struct main_config_s {
         */
        bool            rewrite_update;                 //!< rewrite "update" to be new edit sections
        bool            forbid_update;                  //!< forbid "update" sections
+       bool            require_enum_prefix;            //!< require "::" for enum parsing.  They're always printed with this
 };
 
 void                   main_config_name_set_default(main_config_t *config, char const *name, bool overwrite_config);
index a723e416a102f6cd6768d4b6ee3d7c2526dbf910..7842d6b9dca390b35ba430c2fdb89466d56c26e5 100644 (file)
@@ -262,7 +262,6 @@ int map_afrom_cp(TALLOC_CTX *ctx, map_t **out, map_t *parent, CONF_PAIR *cp,
                my_rhs_rules.enumv = NULL;
        }
 
-
        slen = tmpl_afrom_substr(map, &map->rhs,
                                 &FR_SBUFF_IN(value, slen),
                                 type,
index 7add1c3d07ac6034cf2137f943ccaa00d82ec806..5411ddaf2c7f90449a88eb877443d47e111c2d0c 100644 (file)
@@ -41,6 +41,13 @@ RCSID("$Id$")
 
 #include <ctype.h>
 
+/*
+ *     Migration flag for enum prefixes.
+ */
+extern bool tmpl_require_enum_prefix;
+
+bool tmpl_require_enum_prefix = false;
+
 /** Define a global variable for specifying a default request reference
  *
  * @param[in] _name    what the global variable should be called.
@@ -2948,11 +2955,18 @@ static ssize_t tmpl_afrom_enum(TALLOC_CTX *ctx, tmpl_t **out, fr_sbuff_t *in,
        fr_sbuff_parse_error_t  sberr;
        fr_sbuff_t      our_in = FR_SBUFF(in);
 
-       if (fr_sbuff_is_str_literal(&our_in, "::")) {
-               (void) fr_sbuff_advance(&our_in, 2);
+       /*
+        *      If there isn't a "::" prefix, then check for migration flags, and enum.
+        *
+        *      If we require an enum prefix, then the input can't be an enum, and we don't do any more
+        *      parsing.
+        *
+        *      Otherwise if there's no prefix and no enumv, we know this input can't be an enum name.
+        */
+       if (!fr_sbuff_adv_past_str_literal(&our_in, "::")) {
+               if (tmpl_require_enum_prefix) return 0;
 
-       } else if (!t_rules->enumv) {
-               return 0;
+               if (!t_rules->enumv) return 0;
        }
 
        vpt = tmpl_alloc_null(ctx);
@@ -5771,4 +5785,5 @@ void tmpl_rules_debug(tmpl_rules_t const *rules)
        FR_FAULT_LOG("\tenumv      = %s", rules->enumv ? rules->enumv->name : "");
        FR_FAULT_LOG("\tcast       = %s", fr_type_to_str(rules->cast));
        FR_FAULT_LOG("\tat_runtime = %u", rules->at_runtime);
+
 }
index e834e691e8b04cab020a9045a4ada44c1afbbc61..03257d3617beb094179a7a29f25e48fe1fee33b5 100644 (file)
@@ -1,3 +1,7 @@
+migrate {
+       require_enum_prefix = yes
+}
+
 modules {
        $INCLUDE ${raddb}/mods-enabled/always