]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
produce warnings and errors for attributes which have leading '&'
authorAlan T. DeKok <aland@freeradius.org>
Thu, 6 Mar 2025 14:25:19 +0000 (09:25 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Thu, 6 Mar 2025 16:39:08 +0000 (11:39 -0500)
If we're in the new config and -C, produce a warning.

If the migration flag says to forbid '&', then we produce an
error.

src/lib/server/cf_parse.c

index f21fc8a50a74b8ef2b5e54554f5ab5802e1dba5b..de85876c9784b660d40a216943378d3525054ac1 100644 (file)
@@ -34,6 +34,7 @@ RCSID("$Id$")
 #include <freeradius-devel/server/log.h>
 #include <freeradius-devel/server/tmpl.h>
 #include <freeradius-devel/server/virtual_servers.h>
+#include <freeradius-devel/server/main_config.h>
 #include <freeradius-devel/util/debug.h>
 #include <freeradius-devel/util/inet.h>
 #include <freeradius-devel/util/misc.h>
@@ -46,6 +47,11 @@ static char const parse_spaces[] = "
 #define PAIR_SPACE(_cs) ((_cs->depth + 1) * 2)
 #define SECTION_SPACE(_cs) (_cs->depth * 2)
 
+/*
+ *     For migration.
+ */
+extern bool tmpl_require_enum_prefix;
+
 void cf_pair_debug_log(CONF_SECTION const *cs, CONF_PAIR *cp, conf_parser_t const *rule)
 {
        char const      *value;
@@ -1202,10 +1208,12 @@ static int cf_parse_tmpl_pass2(UNUSED CONF_SECTION *cs, tmpl_t **out, CONF_PAIR
                return -1;
        }
 
-       if (attribute && !tmpl_is_attr(vpt)) {
-               cf_log_err(cp, "Expected attr got %s",
-                          tmpl_type_to_str(vpt->type));
-               return -1;
+       if (attribute) {
+               if (!tmpl_is_attr(vpt)) {
+                       cf_log_err(cp, "Expected attr got %s",
+                                  tmpl_type_to_str(vpt->type));
+                       return -1;
+               }
        }
 
        switch (vpt->type) {
@@ -1227,6 +1235,20 @@ static int cf_parse_tmpl_pass2(UNUSED CONF_SECTION *cs, tmpl_t **out, CONF_PAIR
                break;
 
        case TMPL_TYPE_ATTR:
+               if (!check_config) break;
+
+               if (vpt->name[0] != '&') break;
+
+               if (main_config_migrate_option_get("call_env_forbid_ampersand")) {
+                       cf_log_err(cp, "Please remove '&' from the attribute name");
+                       return -1;
+               }
+
+               if (tmpl_require_enum_prefix)  {
+                       cf_log_warn(cp, "Please remove '&' from the attribute name");
+               }
+               break;
+
        case TMPL_TYPE_DATA:
        case TMPL_TYPE_EXEC:
        case TMPL_TYPE_EXEC_UNRESOLVED: