From: Alan T. DeKok Date: Sat, 17 Aug 2024 12:55:42 +0000 (-0400) Subject: add "require_enum_prefix" migration flag X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=da410bd1698ffce69486a94558d61bc13bac9dbc;p=thirdparty%2Ffreeradius-server.git add "require_enum_prefix" migration flag in preparation for moving to ::enum-name everywhere, which then lets us drop the "&" prefix for attribute names --- diff --git a/src/lib/server/base.c b/src/lib/server/base.c index 21c31a3b5a7..c2bc5573993 100644 --- a/src/lib/server/base.c +++ b/src/lib/server/base.c @@ -32,6 +32,8 @@ RCSID("$Id$") #include #include +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; } diff --git a/src/lib/server/main_config.c b/src/lib/server/main_config.c index bda0592a635..e4c55dac887 100644 --- a/src/lib/server/main_config.c +++ b/src/lib/server/main_config.c @@ -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); diff --git a/src/lib/server/main_config.h b/src/lib/server/main_config.h index 365c7951fa8..be5dd37608b 100644 --- a/src/lib/server/main_config.h +++ b/src/lib/server/main_config.h @@ -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); diff --git a/src/lib/server/map.c b/src/lib/server/map.c index a723e416a10..7842d6b9dca 100644 --- a/src/lib/server/map.c +++ b/src/lib/server/map.c @@ -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, diff --git a/src/lib/server/tmpl_tokenize.c b/src/lib/server/tmpl_tokenize.c index 7add1c3d07a..5411ddaf2c7 100644 --- a/src/lib/server/tmpl_tokenize.c +++ b/src/lib/server/tmpl_tokenize.c @@ -41,6 +41,13 @@ RCSID("$Id$") #include +/* + * 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); + } diff --git a/src/tests/keywords/radius.conf b/src/tests/keywords/radius.conf index e834e691e8b..03257d3617b 100644 --- a/src/tests/keywords/radius.conf +++ b/src/tests/keywords/radius.conf @@ -1,3 +1,7 @@ +migrate { + require_enum_prefix = yes +} + modules { $INCLUDE ${raddb}/mods-enabled/always