From: Alan T. DeKok Date: Thu, 26 May 2022 18:37:50 +0000 (-0400) Subject: xlat_instantiate_ephemeral() will now call xlat_resolve() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=45570f4647c097e7b5258d8b29c306814e0afcbf;p=thirdparty%2Ffreeradius-server.git xlat_instantiate_ephemeral() will now call xlat_resolve() if needed --- diff --git a/src/lib/unlang/xlat_expr.c b/src/lib/unlang/xlat_expr.c index c18a454e661..bb6f2690954 100644 --- a/src/lib/unlang/xlat_expr.c +++ b/src/lib/unlang/xlat_expr.c @@ -1581,21 +1581,10 @@ ssize_t xlat_tokenize_ephemeral_expression(TALLOC_CTX *ctx, xlat_exp_head_t **ou return slen; } - /* - * Ensure that everything is resolved otherwise we have - * no idea what to do. - */ - if (head->flags.needs_resolving && - (xlat_resolve(head, &(xlat_res_rules_t){ .allow_unresolved = false }) < 0)) { - talloc_free(head); - return -1; - } - /* * Create ephemeral instance data for the xlat */ if (xlat_instantiate_ephemeral(head, el) < 0) { - fr_strerror_const("Failed performing ephemeral instantiation for xlat"); talloc_free(head); return 0; } diff --git a/src/lib/unlang/xlat_inst.c b/src/lib/unlang/xlat_inst.c index 816a2724f27..730db550822 100644 --- a/src/lib/unlang/xlat_inst.c +++ b/src/lib/unlang/xlat_inst.c @@ -331,6 +331,15 @@ int xlat_instantiate_ephemeral(xlat_exp_head_t *head, fr_event_list_t *el) { int ret; + /* + * The caller MAY resolve it, or may not. If the caller + * hasn't resolved it, then we can't allow any unresolved + * functions or attributes. + */ + if (head->flags.needs_resolving) { + if (xlat_resolve(head, &(xlat_res_rules_t){ .allow_unresolved = false }) < 0) return -1; + } + if (head->instantiated) return 0; ret = xlat_eval_walk(head, _xlat_instantiate_ephemeral_walker, XLAT_INVALID, el); diff --git a/src/tests/unit/xlat/cond_base.txt b/src/tests/unit/xlat/cond_base.txt index b796c8b78f0..dc0c2f39653 100644 --- a/src/tests/unit/xlat/cond_base.txt +++ b/src/tests/unit/xlat/cond_base.txt @@ -34,7 +34,7 @@ match ERROR offset 4: Unexpected text after enum value. Expected operator # @todo - this is an error somehow? # xlat_purify (Service-Type == 000-111) -match ERROR offset 1: No IPv6 component separator: Failed resolving attribute in expansion: Service-Type +match ERROR offset 0: No IPv6 component separator: Failed resolving attribute in expansion: Service-Type #match (&Service-Type == (0 - 111)) xlat_purify (ok FOO handled) @@ -230,7 +230,7 @@ match (&Event-Timestamp == "January 1, 2012 %{Request[0].User-Name}") # @todo - can't parse years? # xlat_purify &Event-Timestamp == 'January 1, 2012' -match ERROR offset 1: Invalid year string +match ERROR offset 0: Invalid year string #match (&Event-Timestamp == 'Jan 1 2012 00:00:00 EST') # literals are parsed when the conditions are parsed @@ -242,7 +242,7 @@ match ERROR offset 10: Failed parsing string as type 'uint32' # string the RHS is. # xlat_purify &NAS-Port == X -match ERROR offset 1: Failed parsing string as type 'uint32' +match ERROR offset 0: Failed parsing string as type 'uint32' #match ERROR offset 13: Failed parsing string as type 'uint32' # @@ -582,12 +582,12 @@ 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 # xlat_purify request.Foo == 'request.Foo' -match ERROR offset 1: Invalid attribute reference, missing '&' prefix: Failed resolving attribute in expansion: request.Foo +match ERROR offset 0: Invalid attribute reference, missing '&' prefix: Failed resolving attribute in expansion: request.Foo 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 -# . is a valid dictionarxy name attribute, so we can't error out in pass1 +# . is a valid dictionary name attribute, so we can't error out in pass1 xlat_purify ¬-a-packet.User-Name == ¬-a-packet.User-Name match ERROR offset 1: Attribute 'not' not found. Searched in: RADIUS, internal: Unresolved attributes are not allowed here