]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add support for FR_TYPE_ATTR xlat arguments
authorNick Porter <nick@portercomputing.co.uk>
Wed, 1 Oct 2025 11:04:46 +0000 (12:04 +0100)
committerNick Porter <nick@portercomputing.co.uk>
Wed, 1 Oct 2025 11:04:46 +0000 (12:04 +0100)
src/lib/unlang/xlat_eval.c
src/lib/unlang/xlat_priv.h
src/lib/unlang/xlat_tokenize.c

index b987fd95ff5a6e3c1301090b806b3d5316fcabf6..3b0a9ad17d65eedfcb13539edaefdc22561733b5 100644 (file)
@@ -1344,6 +1344,19 @@ xlat_action_t xlat_frame_eval(TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_exp_head_
                goto finish;
        }
 
+       /*
+        *      An attribute reference which produces a box of type FR_TYPE_ATTR
+        */
+       if (unlikely(head && head->is_attr)) {
+               fr_assert((*in)->type == XLAT_TMPL);
+
+               MEM(value = fr_value_box_alloc_null(ctx));
+               fr_value_box_set_attr(value, tmpl_attr_tail_da((*in)->vpt));
+
+               fr_dcursor_append(out, value);
+               goto finish;
+       }
+
        XLAT_DEBUG("** [%i] %s >> entered", unlang_interpret_stack_depth(request), __FUNCTION__);
 
        for (node = *in; node; node = xlat_exp_next(head, node)) {
index 9fca229d10dd70465e0f19ba47600852e4cce108..0426c505641c4fa3755c721cc13599e8e5bdca32 100644 (file)
@@ -191,6 +191,7 @@ struct xlat_exp_head_s {
        uint8_t                 instantiated : 1;  //!< temporary flag until we fix more things
        uint8_t                 is_argv : 1;    //!< this thing holds function arguments
        uint8_t                 cursor : 1;     //!< otherwise it's too hard to pass xlat_arg_parser_t to the evaluation function.
+       uint8_t                 is_attr : 1;    //!< the argument is an attribute reference
 
 #ifndef NDEBUG
        char const * _CONST     file;           //!< File where the xlat was allocated.
index 38df4ffb5f6cffd8c4c1947fd9f6ffe0b8679a02..6d80030277ab97031b18c092a3ef20e046cc7321 100644 (file)
@@ -292,6 +292,26 @@ static int xlat_validate_function_arg(xlat_arg_parser_t const *arg_p, xlat_exp_t
                return 0;
        }
 
+       /*
+        *      An attribute argument results in an FR_TYPE_ATTR box, rather than the value of the attribute
+        */
+       if (arg_p->type == FR_TYPE_ATTR) {
+               if (node->type != XLAT_TMPL) {
+                       fr_strerror_printf("Attribute must be a bare word, not %s", fr_type_to_str(node->data.type));
+                       return -1;
+               }
+
+               if (xlat_tmpl_normalize(node) < 0) return -1;
+
+               if (!tmpl_is_attr(node->vpt)) {
+                       fr_strerror_printf("Invalid argument - expected attribute reference");
+                       return -1;
+               }
+
+               arg->group->is_attr = true;
+               return 0;
+       }
+
        /*
         *      The argument is either ONE tmpl / value-box, OR is an
         *      xlat group which contains a double-quoted string.