From: Alan T. DeKok Date: Thu, 7 Jul 2022 14:59:56 +0000 (-0400) Subject: call xlat_init() manually, before registering any xlats X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d7c252885394603f45a569725eca2128e04a46b4;p=thirdparty%2Ffreeradius-server.git call xlat_init() manually, before registering any xlats so that we don't need to check xlat_root every time we try to register an xlat --- diff --git a/src/lib/server/main_config.c b/src/lib/server/main_config.c index 84912ca2f0a..36b4b77bb7f 100644 --- a/src/lib/server/main_config.c +++ b/src/lib/server/main_config.c @@ -983,6 +983,11 @@ int main_config_init(main_config_t *config) char buffer[1024]; xlat_t *xlat; + /* + * Initialize the xlats before we load the configuration files, so that we can later call xlat_register(). + */ + xlat_init(); + if (stat(config->raddb_dir, &statbuf) < 0) { ERROR("Error checking raddb_dir \"%s\": %s", config->raddb_dir, fr_syserror(errno)); return -1; diff --git a/src/lib/unlang/xlat_builtin.c b/src/lib/unlang/xlat_builtin.c index 45efd54a276..ade0c843a97 100644 --- a/src/lib/unlang/xlat_builtin.c +++ b/src/lib/unlang/xlat_builtin.c @@ -173,7 +173,7 @@ xlat_t *xlat_register_module(TALLOC_CTX *ctx, module_inst_ctx_t const *mctx, xlat_t *c; module_inst_ctx_t *our_mctx = NULL; - if (!xlat_root) xlat_init(); + fr_assert(xlat_root); if (!*name) { ERROR("%s: Invalid xlat name", __FUNCTION__); diff --git a/src/tests/unit/xlat/cond_base.txt b/src/tests/unit/xlat/cond_base.txt index 97b20c00157..3c50b3a98ea 100644 --- a/src/tests/unit/xlat/cond_base.txt +++ b/src/tests/unit/xlat/cond_base.txt @@ -572,10 +572,13 @@ xlat_purify &User-Name[-1] == 'bob' match ERROR offset 11: Invalid array index '-1' (should be between 0-1000) # -# The attribute/xlat_purify parser does not fall back to bare words +# attributes MUST be prefixed with '&'. # xlat_purify request.Foo == 'request.Foo' -match ERROR offset 0: Failed resolving attribute in expansion: request.Foo +match true + +xlat_purify &request.Foo == 'request.Foo' +match ERROR offset 9: Attribute 'Foo' not found in namespace 'internal': Unresolved attributes are not allowed here xlat_purify ¬-a-list.User-Name == ¬-a-list.User-Name match ERROR offset 1: Attribute 'not' not found. Searched in: RADIUS, internal: Unresolved attributes are not allowed here @@ -761,4 +764,4 @@ match %{rcode:'handled'} count -match 314 +match 316