2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 * @brief String expansion ("translation"). Implements %Attribute -> value
23 * @copyright 2000,2006 The FreeRADIUS server project
24 * @copyright 2000 Alan DeKok <aland@ox.org>
29 #include <freeradius-devel/radiusd.h>
30 #include <freeradius-devel/parser.h>
31 #include <freeradius-devel/rad_assert.h>
32 #include <freeradius-devel/base64.h>
35 typedef struct xlat_t {
36 char name[MAX_STRING_LEN]; //!< Name of the xlat expansion.
37 int length; //!< Length of name.
38 void *instance; //!< Module instance passed to xlat and escape functions.
39 RAD_XLAT_FUNC func; //!< xlat function.
40 RADIUS_ESCAPE_STRING escape; //!< Escape function to apply to dynamic input to func.
41 bool internal; //!< If true, cannot be redefined.
45 XLAT_LITERAL, //!< Literal string
46 XLAT_PERCENT, //!< Literal string with %v
47 XLAT_MODULE, //!< xlat module
48 XLAT_VIRTUAL, //!< virtual attribute
49 XLAT_ATTRIBUTE, //!< xlat attribute
51 XLAT_REGEX, //!< regex reference
53 XLAT_ALTERNATE //!< xlat conditional syntax :-
57 char const *fmt; //!< The format string.
58 size_t len; //!< Length of the format string.
60 xlat_state_t type; //!< type of this expansion.
61 xlat_exp_t *next; //!< Next in the list.
63 xlat_exp_t *child; //!< Nested expansion.
64 xlat_exp_t *alternate; //!< Alternative expansion if this one expanded to a zero length string.
66 value_pair_tmpl_t attr; //!< An attribute template.
67 xlat_t const *xlat; //!< The xlat expansion to expand format with.
70 typedef struct xlat_out {
71 char const *out; //!< Output data.
72 size_t len; //!< Length of the output string.
75 static rbtree_t *xlat_root = NULL;
78 static char const * const xlat_foreach_names[] = {"Foreach-Variable-0",
91 #if REQUEST_MAX_REGEX > 8
92 #error Please fix the following line
94 static int xlat_inst[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 }; /* up to 8 for regex */
96 char const *radiusd_short_version = RADIUSD_VERSION_STRING;
98 /** Print length of its RHS.
101 static ssize_t xlat_strlen(UNUSED void *instance, UNUSED REQUEST *request,
102 char const *fmt, char *out, size_t outlen)
104 snprintf(out, outlen, "%u", (unsigned int) strlen(fmt));
108 /** Print the size of the attribute in bytes.
111 static ssize_t xlat_length(UNUSED void *instance, UNUSED REQUEST *request,
112 char const *fmt, char *out, size_t outlen)
115 while (isspace((int) *fmt)) fmt++;
117 if ((radius_get_vp(&vp, request, fmt) < 0) || !vp) {
122 snprintf(out, outlen, "%zu", vp->length);
126 /** Print data as integer, not as VALUE.
129 static ssize_t xlat_integer(UNUSED void *instance, REQUEST *request,
130 char const *fmt, char *out, size_t outlen)
134 uint64_t int64 = 0; /* Needs to be initialised to zero */
135 uint32_t int32 = 0; /* Needs to be initialised to zero */
137 while (isspace((int) *fmt)) fmt++;
139 if ((radius_get_vp(&vp, request, fmt) < 0) || !vp) {
144 switch (vp->da->type) {
147 if (vp->length > 8) {
151 if (vp->length > 4) {
152 memcpy(&int64, vp->vp_octets, vp->length);
153 return snprintf(out, outlen, "%" PRIu64, htonll(int64));
156 memcpy(&int32, vp->vp_octets, vp->length);
157 return snprintf(out, outlen, "%i", htonl(int32));
159 case PW_TYPE_INTEGER64:
160 return snprintf(out, outlen, "%" PRIu64, vp->vp_integer64);
163 * IP addresses are treated specially, as parsing functions assume the value
164 * is bigendian and will convert it for us.
166 case PW_TYPE_IPV4_ADDR:
167 return snprintf(out, outlen, "%u", htonl(vp->vp_ipaddr));
169 case PW_TYPE_IPV4_PREFIX:
170 return snprintf(out, outlen, "%u", htonl((*(uint32_t *)(vp->vp_ipv4prefix + 2))));
172 case PW_TYPE_INTEGER:
174 return snprintf(out, outlen, "%u", vp->vp_integer);
176 return snprintf(out, outlen, "%u", (unsigned int) vp->vp_byte);
178 return snprintf(out, outlen, "%u", (unsigned int) vp->vp_short);
181 * Ethernet is weird... It's network related, so we assume to it should be
184 case PW_TYPE_ETHERNET:
185 memcpy(&int64, &vp->vp_ether, vp->length);
186 return snprintf(out, outlen, "%" PRIu64, htonll(int64));
189 return snprintf(out, outlen, "%i", vp->vp_signed);
191 case PW_TYPE_IPV6_ADDR:
192 return fr_prints_uint128(out, outlen, ntohlll(*(uint128_t const *) &vp->vp_ipv6addr));
194 case PW_TYPE_IPV6_PREFIX:
195 return fr_prints_uint128(out, outlen, ntohlll(*(uint128_t const *) &(vp->vp_ipv6prefix[2])));
201 REDEBUG("Type '%s' of length %zu cannot be converted to integer",
202 fr_int2str(dict_attr_types, vp->da->type, "???"), vp->length);
208 /** Print data as hex, not as VALUE.
211 static ssize_t xlat_hex(UNUSED void *instance, REQUEST *request,
212 char const *fmt, char *out, size_t outlen)
220 while (isspace((int) *fmt)) fmt++;
222 if ((radius_get_vp(&vp, request, fmt) < 0) || !vp) {
227 ret = rad_vp2data(&p, vp);
234 * Don't truncate the data.
236 if ((ret < 0 ) || (outlen < (len * 2))) {
241 for (i = 0; i < len; i++) {
242 snprintf(out + 2*i, 3, "%02x", p[i]);
248 /** Return the tag of an attribute reference
251 static ssize_t xlat_tag(UNUSED void *instance, REQUEST *request,
252 char const *fmt, char *out, size_t outlen)
256 while (isspace((int) *fmt)) fmt++;
258 if ((radius_get_vp(&vp, request, fmt) < 0) || !vp) {
263 if (!vp->da->flags.has_tag || !TAG_VALID(vp->tag)) {
268 return snprintf(out, outlen, "%u", vp->tag);
271 /** Print out attribute info
273 * Prints out all instances of a current attribute, or all attributes in a list.
275 * At higher debugging levels, also prints out alternative decodings of the same
276 * value. This is helpful to determine types for unknown attributes of long
277 * passed vendors, or just crazy/broken NAS.
279 * It's also useful for exposing issues in the packet decoding functions, as in
280 * some cases they get fed random garbage data.
282 * This expands to a zero length string.
284 static ssize_t xlat_debug_attr(UNUSED void *instance, REQUEST *request, char const *fmt,
285 char *out, UNUSED size_t outlen)
287 VALUE_PAIR *vp, **vps;
292 value_pair_tmpl_t vpt;
294 if (!RDEBUG_ENABLED2) {
299 while (isspace((int) *fmt)) fmt++;
301 if (tmpl_from_attr_str(&vpt, fmt, REQUEST_CURRENT, PAIR_LIST_REQUEST) <= 0) {
302 RDEBUG("%s", fr_strerror());
307 if (radius_request(¤t, vpt.tmpl_request) < 0) return -2;
309 vps = radius_list(current, vpt.tmpl_list);
314 RIDEBUG("Attributes matching \"%s\"", fmt);
315 vp = fr_cursor_init(&cursor, vps);
318 vp = fr_cursor_next_by_da(&cursor, vpt.tmpl_da, TAG_ANY);
321 DICT_ATTR *dac = NULL;
324 vp_prints_value(buffer, sizeof(buffer), vp, '\'');
326 if (vp->da->flags.has_tag) {
327 RIDEBUG2("\t%s:%s:%i %s %s",
328 fr_int2str(pair_lists, vpt.tmpl_list, "<INVALID>"),
331 fr_int2str(fr_tokens, vp->op, "<INVALID>"),
334 RIDEBUG2("\t%s:%s %s %s",
335 fr_int2str(pair_lists, vpt.tmpl_list, "<INVALID>"),
337 fr_int2str(fr_tokens, vp->op, "<INVALID>"),
341 if (!RDEBUG_ENABLED3) {
345 if (vp->da->vendor) {
346 dv = dict_vendorbyvalue(vp->da->vendor);
347 RDEBUG3("\t\tvendor : %i (%s)", vp->da->vendor, dv ? dv->name : "unknown");
349 RDEBUG3("\t\ttype : %s", fr_int2str(dict_attr_types, vp->da->type, "<INVALID>"));
350 RDEBUG3("\t\tlength : %zu", vp->length);
352 dac = talloc_memdup(request, vp->da, sizeof(DICT_ATTR));
354 talloc_set_type(dac, DICT_ATTR);
360 vp = fr_cursor_next_by_da(&cursor, vpt.tmpl_da, TAG_ANY);
362 vp = fr_cursor_next(&cursor);
370 /** Prints the current module processing the request
373 static ssize_t xlat_module(UNUSED void *instance, REQUEST *request,
374 UNUSED char const *fmt, char *out, size_t outlen)
376 strlcpy(out, request->module, outlen);
382 /** Implements the Foreach-Variable-X
386 static ssize_t xlat_foreach(void *instance, REQUEST *request,
387 UNUSED char const *fmt, char *out, size_t outlen)
393 * See modcall, "FOREACH" for how this works.
395 pvp = (VALUE_PAIR **) request_data_reference(request, radius_get_vp, *(int*) instance);
401 len = vp_prints_value(out, outlen, *pvp, 0);
402 if (is_truncated(len, outlen)) {
403 RDEBUG("Insufficient buffer space to write foreach value");
411 /** Print data as string, if possible.
413 * If attribute "Foo" is defined as "octets" it will normally
414 * be printed as 0x0a0a0a. The xlat "%{string:Foo}" will instead
417 static ssize_t xlat_string(UNUSED void *instance, REQUEST *request,
418 char const *fmt, char *out, size_t outlen)
425 while (isspace((int) *fmt)) fmt++;
433 if ((radius_get_vp(&vp, request, fmt) < 0) || !vp) goto nothing;
435 ret = rad_vp2data(&p, vp);
440 switch (vp->da->type) {
442 len = fr_print_string((char const *) p, vp->length, out, outlen, '\0');
446 len = strlcpy(out, vp->vp_strvalue, outlen);
450 len = fr_print_string((char const *) p, ret, out, outlen, '\0');
457 /** xlat expand string attribute value
460 static ssize_t xlat_xlat(UNUSED void *instance, REQUEST *request,
461 char const *fmt, char *out, size_t outlen)
465 while (isspace((int) *fmt)) fmt++;
473 if ((radius_get_vp(&vp, request, fmt) < 0) || !vp) goto nothing;
475 return radius_xlat(out, outlen, request, vp->vp_strvalue, NULL, NULL);
478 /** Dynamically change the debugging level for the current request
482 static ssize_t xlat_debug(UNUSED void *instance, REQUEST *request,
483 char const *fmt, char *out, size_t outlen)
488 * Expand to previous (or current) level
490 snprintf(out, outlen, "%d", request->log.lvl & RAD_REQUEST_OPTION_DEBUG4);
493 * Assume we just want to get the current value and NOT set it to 0
500 request->log.lvl = RAD_REQUEST_OPTION_NONE;
501 request->log.func = NULL;
503 if (level > 4) level = 4;
505 request->log.lvl = level;
506 request->log.func = vradlog_request;
514 * Compare two xlat_t structs, based ONLY on the module name.
516 static int xlat_cmp(void const *one, void const *two)
518 xlat_t const *a = one;
519 xlat_t const *b = two;
521 if (a->length != b->length) {
522 return a->length - b->length;
525 return memcmp(a->name, b->name, a->length);
530 * find the appropriate registered xlat function.
532 static xlat_t *xlat_find(char const *name)
536 strlcpy(my_xlat.name, name, sizeof(my_xlat.name));
537 my_xlat.length = strlen(my_xlat.name);
539 return rbtree_finddata(xlat_root, &my_xlat);
543 /** Register an xlat function.
545 * @param[in] name xlat name.
546 * @param[in] func xlat function to be called.
547 * @param[in] escape function to sanitize any sub expansions passed to the xlat function.
548 * @param[in] instance of module that's registering the xlat function.
549 * @return 0 on success, -1 on failure
551 int xlat_register(char const *name, RAD_XLAT_FUNC func, RADIUS_ESCAPE_STRING escape, void *instance)
557 if (!name || !*name) {
558 DEBUG("xlat_register: Invalid xlat name");
563 * First time around, build up the tree...
565 * FIXME: This code should be hoisted out of this function,
566 * and into a global "initialization". But it isn't critical...
573 xlat_root = rbtree_create(NULL, xlat_cmp, free, 0);
575 DEBUG("xlat_register: Failed to create tree");
580 for (i = 0; xlat_foreach_names[i] != NULL; i++) {
581 xlat_register(xlat_foreach_names[i],
582 xlat_foreach, NULL, &xlat_inst[i]);
583 c = xlat_find(xlat_foreach_names[i]);
584 rad_assert(c != NULL);
589 #define XLAT_REGISTER(_x) xlat_register(STRINGIFY(_x), xlat_ ## _x, NULL, NULL); \
590 c = xlat_find(STRINGIFY(_x)); \
591 rad_assert(c != NULL); \
594 XLAT_REGISTER(integer);
595 XLAT_REGISTER(strlen);
596 XLAT_REGISTER(length);
599 XLAT_REGISTER(string);
601 XLAT_REGISTER(module);
602 XLAT_REGISTER(debug_attr);
604 xlat_register("debug", xlat_debug, NULL, &xlat_inst[0]);
605 c = xlat_find("debug");
606 rad_assert(c != NULL);
611 * If it already exists, replace the instance.
613 strlcpy(my_xlat.name, name, sizeof(my_xlat.name));
614 my_xlat.length = strlen(my_xlat.name);
615 c = rbtree_finddata(xlat_root, &my_xlat);
618 DEBUG("xlat_register: Cannot re-define internal xlat");
624 c->instance = instance;
629 * Doesn't exist. Create it.
631 c = rad_malloc(sizeof(*c));
632 memset(c, 0, sizeof(*c));
636 strlcpy(c->name, name, sizeof(c->name));
637 c->length = strlen(c->name);
638 c->instance = instance;
640 node = rbtree_insert_node(xlat_root, c);
649 /** Unregister an xlat function
651 * We can only have one function to call per name, so the passing of "func"
652 * here is extraneous.
654 * @param[in] name xlat to unregister.
655 * @param[in] func unused.
656 * @param[in] instance data.
658 void xlat_unregister(char const *name, UNUSED RAD_XLAT_FUNC func, void *instance)
665 strlcpy(my_xlat.name, name, sizeof(my_xlat.name));
666 my_xlat.length = strlen(my_xlat.name);
668 c = rbtree_finddata(xlat_root, &my_xlat);
671 if (c->instance != instance) return;
673 rbtree_deletebydata(xlat_root, c);
677 /** Crappy temporary function to add attribute ref support to xlats
679 * This needs to die, and hopefully will die, when xlat functions accept
680 * xlat node structures.
682 * Provides either a pointer to a buffer which contains the value of the reference VALUE_PAIR
683 * in an architecture independent format. Or a pointer to the start of the fmt string.
685 * The pointer is only guaranteed to be valid between calls to xlat_fmt_to_ref,
686 * and so long as the source VALUE_PAIR is not freed.
688 * @param out where to write a pointer to the buffer to the data the xlat function needs to work on.
689 * @param request current request.
691 * @returns the length of the data or -1 on error.
693 ssize_t xlat_fmt_to_ref(uint8_t const **out, REQUEST *request, char const *fmt)
697 while (isspace((int) *fmt)) fmt++;
700 if ((radius_get_vp(&vp, request, fmt) < 0) || !vp) {
705 return rad_vp2data(out, vp);
708 *out = (uint8_t const *)fmt;
712 /** De-register all xlat functions, used mainly for debugging.
717 rbtree_free(xlat_root);
722 #define XLAT_DEBUG DEBUG3
724 #define XLAT_DEBUG(...)
727 static ssize_t xlat_tokenize_expansion(TALLOC_CTX *ctx, char *fmt, xlat_exp_t **head,
729 static ssize_t xlat_tokenize_literal(TALLOC_CTX *ctx, char *fmt, xlat_exp_t **head,
730 int brace, char const **error);
731 static size_t xlat_process(char **out, REQUEST *request, xlat_exp_t const * const head,
732 RADIUS_ESCAPE_STRING escape, void *escape_ctx);
734 static ssize_t xlat_tokenize_alternation(TALLOC_CTX *ctx, char *fmt, xlat_exp_t **head,
741 rad_assert(fmt[0] == '%');
742 rad_assert(fmt[1] == '{');
743 rad_assert(fmt[2] == '%');
744 rad_assert(fmt[3] == '{');
746 XLAT_DEBUG("ALTERNATE <-- %s", fmt);
748 node = talloc_zero(ctx, xlat_exp_t);
749 node->type = XLAT_ALTERNATE;
752 slen = xlat_tokenize_expansion(node, p, &node->child, error);
755 return slen - (p - fmt);
761 *error = "Expected ':' after first expansion";
768 *error = "Expected '-' after ':'";
774 * Allow the RHS to be empty as a special case.
778 * Hack up an empty string.
780 node->alternate = talloc_zero(node, xlat_exp_t);
781 node->alternate->type = XLAT_LITERAL;
782 node->alternate->fmt = talloc_typed_strdup(node->alternate, "");
786 slen = xlat_tokenize_literal(node, p, &node->alternate, true, error);
789 return slen - (p - fmt);
792 if (!node->alternate) {
794 *error = "Empty expansion is invalid";
804 static ssize_t xlat_tokenize_expansion(TALLOC_CTX *ctx, char *fmt, xlat_exp_t **head,
809 char const *attrname;
812 rad_assert(fmt[0] == '%');
813 rad_assert(fmt[1] == '{');
818 if ((fmt[2] == '%') && (fmt[3] == '{')) {
819 return xlat_tokenize_alternation(ctx, fmt, head, error);
822 XLAT_DEBUG("EXPANSION <-- %s", fmt);
823 node = talloc_zero(ctx, xlat_exp_t);
824 attrname = node->fmt = fmt + 2;
829 * Handle regex's specially.
831 if (isdigit((int) fmt[2]) && (fmt[3] == '}')) {
834 *error = "Invalid regex reference";
838 XLAT_DEBUG("REGEX <-- %s", fmt);
840 node->attr.tmpl_num = fmt[2] - '0'; /* ASCII */
842 node->type = XLAT_REGEX;
846 #endif /* HAVE_REGEX */
851 * %{Tunnel-Password:1}
852 * %{Tunnel-Password:1[#]}
853 * %{request:Attr-Name}
854 * %{request:Tunnel-Password:1}
855 * %{request:Tunnel-Password:1[#]}
859 for (p = fmt + 2; *p != '\0'; p++) {
860 if (*p == ':') break;
862 if (isspace((int) *p)) break;
864 if (*p == '[') break;
866 if (*p == '}') break;
869 if (*p != ':') p = NULL;
872 * Might be a module name reference.
880 node->xlat = xlat_find(node->fmt);
882 node->type = XLAT_MODULE;
884 XLAT_DEBUG("MOD <-- %s ... %s", node->fmt, p + 1);
886 slen = xlat_tokenize_literal(node, p + 1, &node->child, true, error);
889 return slen - (p - fmt);
894 rad_assert(node->next == NULL);
899 * Modules can have '}' in their RHS, so we
900 * didn't check for that until now.
902 * As of now, node->fmt MUST be a reference to an
903 * attribute, however complicated. So it MUST have a closing brace.
905 brace = strchr(p + 1, '}');
906 if (!brace) goto no_brace;
912 * %{Tunnel-Password:1}
913 * %{request:Tunnel-Password:1}
915 * <sigh> The syntax is fairly poor.
917 XLAT_DEBUG("Looking for list in '%s'", attrname);
920 * Not a module. Has to be an attribute
923 * As of v3, we've removed %{request: ..>} as
924 * internally registered xlats.
927 node->attr.tmpl_request = radius_request_name(&attrname, REQUEST_CURRENT);
928 rad_assert(node->attr.tmpl_request != REQUEST_UNKNOWN);
930 node->attr.tmpl_list = radius_list_name(&attrname, PAIR_LIST_REQUEST);
931 if (node->attr.tmpl_list == PAIR_LIST_UNKNOWN) {
933 *error = "Unknown module";
938 * Check for a trailing tag.
940 p = strchr(attrname, ':');
944 brace = strchr(attrname, '}');
948 *error = "No matching closing brace";
949 return -1; /* second character of format string */
953 node->attr.tmpl_request = REQUEST_CURRENT;
954 node->attr.tmpl_list = PAIR_LIST_REQUEST;
959 XLAT_DEBUG("Looking for attribute name in %s", attrname);
962 * Allow for an array reference. They come AFTER the
963 * tag, if the tag exists. Otherwise, they come after
964 * the attribute name.
967 q = strchr(p + 1, '[');
969 q = strchr(attrname, '[');
971 if (q) *(q++) = '\0';
975 *error = "Empty expression is invalid";
976 return -(attrname - fmt);
980 * It's either an attribute name, or a Tunnel-Password:TAG
981 * with the ':' already set to NULL.
983 node->attr.tmpl_da = dict_attrbyname(attrname);
984 if (!node->attr.tmpl_da) {
986 * Foreach. Maybe other stuff, too.
988 node->xlat = xlat_find(attrname);
990 node->type = XLAT_VIRTUAL;
991 node->fmt = attrname;
993 XLAT_DEBUG("VIRTUAL <-- %s", node->fmt);
995 rad_assert(node->next == NULL);
1001 *error = "Unknown attribute";
1002 return -(attrname - fmt);
1012 if (!node->attr.tmpl_da->flags.has_tag) {
1014 *error = "Attribute cannot have a tag";
1018 tag = strtoul(p + 1, &end, 10);
1021 if (tag == ULONG_MAX) {
1023 *error = "Invalid tag value";
1027 node->attr.tmpl_tag = tag;
1032 *error = "Unexpected text after tag";
1037 node->attr.tmpl_tag = TAG_ANY;
1042 * Check for array reference
1050 node->attr.tmpl_num = NUM_COUNT;
1053 } else if (*p == '*') {
1054 node->attr.tmpl_num = NUM_ALL;
1057 } else if (isdigit((int) *p)) {
1058 num = strtoul(p, &end, 10);
1061 *error = "Invalid array index";
1065 node->attr.tmpl_num = num;
1069 *error = "Invalid array index";
1075 *error = "Expected ']'";
1082 *error = "Unexpected text after array reference";
1086 node->attr.tmpl_num = NUM_ANY;
1089 rad_assert(!p || (p == brace));
1091 node->type = XLAT_ATTRIBUTE;
1095 rad_assert(node->next == NULL);
1100 static ssize_t xlat_tokenize_literal(TALLOC_CTX *ctx, char *fmt, xlat_exp_t **head,
1101 int brace, char const **error)
1106 if (!*fmt) return 0;
1108 XLAT_DEBUG("LITERAL <-- %s", fmt);
1110 node = talloc_zero(ctx, xlat_exp_t);
1113 node->type = XLAT_LITERAL;
1120 * Convert \n to it's literal representation.
1122 if (p[0] == '\\') switch (p[1]) {
1137 if (!p[0] || !p[1]) {
1139 *error = "Hex expansion requires two hex digits";
1143 if (!fr_hex2bin((uint8_t *) q, 1, p, 2)) {
1145 *error = "Invalid hex characters";
1150 * Don't let people shoot themselves in the foot.
1151 * \x00 is forbidden.
1155 *error = "Cannot add zero byte to printable string";
1172 * Process the expansion.
1174 if ((p[0] == '%') && (p[1] == '{')) {
1177 XLAT_DEBUG("LITERAL <-- %s", node->fmt);
1179 slen = xlat_tokenize_expansion(node, p, &node->next, error);
1182 return slen - (p - fmt);
1184 *p = '\0'; /* end the literal */
1187 rad_assert(node->next != NULL);
1190 * Short-circuit the recursive call.
1191 * This saves another function call and
1192 * memory allocation.
1197 * "foo %{User-Name} bar"
1199 * EXPANSION User-Name
1202 slen = xlat_tokenize_literal(node->next, p, &(node->next->next), brace, error);
1203 rad_assert(slen != 0);
1206 return slen - (p - fmt);
1210 break; /* stop processing the string */
1214 * Check for valid single-character expansions.
1220 if (!p[1] || !strchr("%dlmtDGHISTYv", p[1])) {
1222 *error = "Invalid variable expansion";
1227 next = talloc_zero(node, xlat_exp_t);
1231 next->fmt = talloc_typed_strdup(next, "%");
1233 XLAT_DEBUG("LITERAL <-- %s", next->fmt);
1234 next->type = XLAT_LITERAL;
1239 XLAT_DEBUG("PERCENT <-- %c", *next->fmt);
1240 next->type = XLAT_PERCENT;
1252 slen = xlat_tokenize_literal(node->next, p, &(node->next->next), brace, error);
1253 rad_assert(slen != 0);
1256 return slen - (p - fmt);
1260 break; /* stop processing the string */
1264 * If required, eat the brace.
1266 if (brace && (*p == '}')) {
1277 * Squash zero-width literals
1279 if (node->len > 0) {
1282 *head = talloc_steal(ctx, node->next);
1290 static char const xlat_tabs[] = " ";
1292 static void xlat_tokenize_debug(xlat_exp_t const *node, int lvl)
1294 rad_assert(node != NULL);
1296 if (lvl >= (int) sizeof(xlat_tabs)) lvl = sizeof(xlat_tabs);
1299 switch (node->type) {
1301 DEBUG("%.*sliteral --> %s", lvl, xlat_tabs, node->fmt);
1305 DEBUG("%.*spercent --> %c", lvl, xlat_tabs, node->fmt[0]);
1308 case XLAT_ATTRIBUTE:
1309 rad_assert(node->attr.tmpl_da != NULL);
1310 DEBUG("%.*sattribute --> %s", lvl, xlat_tabs, node->attr.tmpl_da->name);
1311 rad_assert(node->child == NULL);
1312 if ((node->attr.tmpl_tag != TAG_ANY) || (node->attr.tmpl_num != NUM_ANY)) {
1313 DEBUG("%.*s{", lvl, xlat_tabs);
1315 DEBUG("%.*sref %d", lvl + 1, xlat_tabs, node->attr.tmpl_request);
1316 DEBUG("%.*slist %d", lvl + 1, xlat_tabs, node->attr.tmpl_list);
1318 if (node->attr.tmpl_tag != TAG_ANY) {
1319 DEBUG("%.*stag %d", lvl + 1, xlat_tabs, node->attr.tmpl_tag);
1321 if (node->attr.tmpl_num != NUM_ANY) {
1322 if (node->attr.tmpl_num == NUM_COUNT) {
1323 DEBUG("%.*s[#]", lvl + 1, xlat_tabs);
1324 } else if (node->attr.tmpl_num == NUM_ALL) {
1325 DEBUG("%.*s[*]", lvl + 1, xlat_tabs);
1327 DEBUG("%.*s[%d]", lvl + 1, xlat_tabs, node->attr.tmpl_num);
1331 DEBUG("%.*s}", lvl, xlat_tabs);
1336 rad_assert(node->fmt != NULL);
1337 DEBUG("%.*svirtual --> %s", lvl, xlat_tabs, node->fmt);
1341 rad_assert(node->xlat != NULL);
1342 DEBUG("%.*sxlat --> %s", lvl, xlat_tabs, node->xlat->name);
1344 DEBUG("%.*s{", lvl, xlat_tabs);
1345 xlat_tokenize_debug(node->child, lvl + 1);
1346 DEBUG("%.*s}", lvl, xlat_tabs);
1352 DEBUG("%.*sregex-var --> %d", lvl, xlat_tabs, node->attr.tmpl_num);
1356 case XLAT_ALTERNATE:
1357 DEBUG("%.*sif {", lvl, xlat_tabs);
1358 xlat_tokenize_debug(node->child, lvl + 1);
1359 DEBUG("%.*s}", lvl, xlat_tabs);
1360 DEBUG("%.*selse {", lvl, xlat_tabs);
1361 xlat_tokenize_debug(node->alternate, lvl + 1);
1362 DEBUG("%.*s}", lvl, xlat_tabs);
1369 size_t xlat_sprint(char *buffer, size_t bufsize, xlat_exp_t const *node)
1380 end = buffer + bufsize;
1383 switch (node->type) {
1385 strlcpy(p, node->fmt, end - p);
1391 p[1] = node->fmt[0];
1395 case XLAT_ATTRIBUTE:
1399 if (node->attr.tmpl_request != REQUEST_CURRENT) {
1400 strlcpy(p, fr_int2str(request_refs, node->attr.tmpl_request, "??"), end - p);
1405 if ((node->attr.tmpl_request != REQUEST_CURRENT) ||
1406 (node->attr.tmpl_list != PAIR_LIST_REQUEST)) {
1407 strlcpy(p, fr_int2str(pair_lists, node->attr.tmpl_list, "??"), end - p);
1412 strlcpy(p, node->attr.tmpl_da->name, end - p);
1415 if (node->attr.tmpl_tag != TAG_ANY) {
1417 snprintf(p, end - p, "%u", node->attr.tmpl_tag);
1421 if (node->attr.tmpl_num != NUM_ANY) {
1423 switch (node->attr.tmpl_num) {
1433 snprintf(p, end - p, "%i", node->attr.tmpl_num);
1442 snprintf(p, end - p, "%%{%i}", node->attr.tmpl_num);
1449 strlcpy(p, node->fmt, end - p);
1457 strlcpy(p, node->xlat->name, end - p);
1460 rad_assert(node->child != NULL);
1461 len = xlat_sprint(p, end - p, node->child);
1466 case XLAT_ALTERNATE:
1470 len = xlat_sprint(p, end - p, node->child);
1476 len = xlat_sprint(p, end - p, node->alternate);
1484 if (p == end) break;
1494 ssize_t xlat_tokenize(TALLOC_CTX *ctx, char *fmt, xlat_exp_t **head,
1497 return xlat_tokenize_literal(ctx, fmt, head, false, error);
1501 /** Tokenize an xlat expansion
1503 * @param[in] request the input request. Memory will be attached here.
1504 * @param[in] fmt the format string to expand
1505 * @param[out] head the head of the xlat list / tree structure.
1507 static ssize_t xlat_tokenize_request(REQUEST *request, char const *fmt, xlat_exp_t **head)
1516 * Copy the original format string to a buffer so that
1517 * the later functions can mangle it in-place, which is
1520 tokens = talloc_typed_strdup(request, fmt);
1521 if (!tokens) return -1;
1523 slen = xlat_tokenize_literal(request, tokens, head, false, &error);
1526 * Zero length expansion, return a zero length node.
1529 *head = talloc_zero(request, xlat_exp_t);
1533 * Output something like:
1536 * " ^ error was here"
1539 talloc_free(tokens);
1540 rad_assert(error != NULL);
1542 REMARKER(fmt, -slen, error);
1546 if (*head && (debug_flag > 2)) {
1548 DEBUG("Parsed xlat tree:");
1549 xlat_tokenize_debug(*head, 0);
1553 * All of the nodes point to offsets in the "tokens"
1554 * string. Let's ensure that free'ing head will free
1557 (void) talloc_steal(*head, tokens);
1563 static char *xlat_getvp(TALLOC_CTX *ctx, REQUEST *request, pair_lists_t list, DICT_ATTR const *da,
1564 int8_t tag, int num, bool return_null)
1566 VALUE_PAIR *vp, *vps = NULL, *myvp = NULL;
1567 RADIUS_PACKET *packet = NULL;
1572 * Arg. Too much abstraction is annoying.
1576 if (return_null) return NULL;
1577 return vp_aprint_type(ctx, da->type);
1579 case PAIR_LIST_CONTROL:
1580 vps = request->config_items;
1583 case PAIR_LIST_REQUEST:
1584 packet = request->packet;
1585 if (packet) vps = packet->vps;
1588 case PAIR_LIST_REPLY:
1589 packet = request->reply;
1590 if (packet) vps = packet->vps;
1594 case PAIR_LIST_PROXY_REQUEST:
1595 packet = request->proxy;
1596 if (packet) vps = packet->vps;
1599 case PAIR_LIST_PROXY_REPLY:
1600 packet = request->proxy_reply;
1601 if (packet) vps = packet->vps;
1608 if (request->coa) packet = request->coa->packet;
1609 if (packet) vps = packet->vps;
1612 case PAIR_LIST_COA_REPLY:
1613 case PAIR_LIST_DM_REPLY:
1614 if (request->coa) packet = request->coa->reply;
1615 if (packet) vps = packet->vps;
1622 * Now we have the list, check to see if we have an attribute in
1623 * the request, if we do, it takes precedence over the virtual
1626 * This allows users to manipulate virtual attributes as if they
1629 vp = pairfind(vps, da->attr, da->vendor, tag);
1630 if (vp) goto do_print;
1633 * We didn't find the VP in a list. It MIGHT be a
1634 * virtual one, in which case we do lots more checks
1635 * below. However, if we're looking for a normal
1636 * attribute, it must exist, and therefore not finding it
1637 * means we return NULL.
1639 if (!da->flags.virtual) return NULL;
1642 * Some non-packet expansions
1646 break; /* ignore them */
1648 case PW_CLIENT_SHORTNAME:
1649 if (num == NUM_COUNT) goto count;
1650 if (request->client && request->client->shortname) {
1651 return talloc_typed_strdup(ctx, request->client->shortname);
1653 return talloc_typed_strdup(ctx, "<UNKNOWN-CLIENT>");
1655 case PW_REQUEST_PROCESSING_STAGE:
1656 if (num == NUM_COUNT) goto count;
1657 if (request->component) {
1658 return talloc_typed_strdup(ctx, request->component);
1660 return talloc_typed_strdup(ctx, "server_core");
1662 case PW_VIRTUAL_SERVER:
1663 if (num == NUM_COUNT) goto count;
1664 if (!request->server) return NULL;
1665 return talloc_typed_strdup(ctx, request->server);
1667 case PW_MODULE_RETURN_CODE:
1668 if (num == NUM_COUNT) goto count;
1669 if (!request->rcode) return NULL;
1670 return talloc_typed_strdup(ctx, fr_int2str(modreturn_table, request->rcode, ""));
1674 * All of the attributes must now refer to a packet.
1675 * If there's no packet, we can't print any attribute
1679 if (return_null) return NULL;
1680 return vp_aprint_type(ctx, da->type);
1688 case PW_PACKET_TYPE:
1689 dv = dict_valbyattr(PW_PACKET_TYPE, 0, packet->code);
1690 if (dv) return talloc_typed_strdup(ctx, dv->name);
1691 return talloc_typed_asprintf(ctx, "%d", packet->code);
1693 case PW_RESPONSE_PACKET_TYPE:
1698 if (request->proxy_reply && (!request->reply || !request->reply->code)) {
1699 code = request->proxy_reply->code;
1702 if (request->reply) {
1703 code = request->reply->code;
1706 return talloc_typed_strdup(ctx, fr_packet_codes[code]);
1710 * Virtual attributes which require a temporary VALUE_PAIR
1711 * to be allocated. We can't use stack allocated memory
1712 * because of the talloc checks sprinkled throughout the
1713 * various VP functions.
1715 case PW_PACKET_AUTHENTICATION_VECTOR:
1716 myvp = pairalloc(ctx, da);
1717 pairmemcpy(myvp, packet->vector, sizeof(packet->vector));
1721 case PW_CLIENT_IP_ADDRESS:
1722 case PW_PACKET_SRC_IP_ADDRESS:
1723 if (packet->src_ipaddr.af == AF_INET) {
1724 myvp = pairalloc(ctx, da);
1725 myvp->vp_ipaddr = packet->src_ipaddr.ipaddr.ip4addr.s_addr;
1730 case PW_PACKET_DST_IP_ADDRESS:
1731 if (packet->dst_ipaddr.af == AF_INET) {
1732 myvp = pairalloc(ctx, da);
1733 myvp->vp_ipaddr = packet->dst_ipaddr.ipaddr.ip4addr.s_addr;
1738 case PW_PACKET_SRC_IPV6_ADDRESS:
1739 if (packet->src_ipaddr.af == AF_INET6) {
1740 myvp = pairalloc(ctx, da);
1741 memcpy(&myvp->vp_ipv6addr,
1742 &packet->src_ipaddr.ipaddr.ip6addr,
1743 sizeof(packet->src_ipaddr.ipaddr.ip6addr));
1748 case PW_PACKET_DST_IPV6_ADDRESS:
1749 if (packet->dst_ipaddr.af == AF_INET6) {
1750 myvp = pairalloc(ctx, da);
1751 memcpy(&myvp->vp_ipv6addr,
1752 &packet->dst_ipaddr.ipaddr.ip6addr,
1753 sizeof(packet->dst_ipaddr.ipaddr.ip6addr));
1758 case PW_PACKET_SRC_PORT:
1759 myvp = pairalloc(ctx, da);
1760 myvp->vp_integer = packet->src_port;
1764 case PW_PACKET_DST_PORT:
1765 myvp = pairalloc(ctx, da);
1766 myvp->vp_integer = packet->dst_port;
1772 * Fake various operations for virtual attributes.
1775 if (num != NUM_ANY) switch (num) {
1777 * [n] is NULL (we only have [0])
1782 * [*] means only one.
1788 * [#] means 1 (as there's only one)
1792 ret = talloc_strdup(ctx, "1");
1796 * [0] is fine (get the first instance)
1806 * We want the N'th VP.
1808 if (num != NUM_ANY) {
1814 * Return a count of the VPs.
1817 fr_cursor_init(&cursor, &vp);
1818 while (fr_cursor_next_by_da(&cursor, da, tag) != NULL) {
1821 return talloc_typed_asprintf(ctx, "%d", count);
1824 * Ugly, but working.
1830 (void) fr_cursor_init(&cursor, &vp);
1831 vp = fr_cursor_next_by_da(&cursor, da, tag);
1832 if (!vp) return NULL;
1834 p = vp_aprint_value(ctx, vp, '"');
1835 if (!p) return NULL;
1836 while ((vp = fr_cursor_next_by_da(&cursor, da, tag)) != NULL) {
1837 q = vp_aprint_value(ctx, vp, '"');
1838 if (!q) return NULL;
1839 p = talloc_strdup_append(p, ",");
1840 p = talloc_strdup_append(p, q);
1847 fr_cursor_init(&cursor, &vp);
1848 while ((vp = fr_cursor_next_by_da(&cursor, da, tag)) != NULL) {
1849 if (count++ == num) break;
1856 if (return_null) return NULL;
1857 return vp_aprint_type(ctx, da->type);
1861 ret = vp_aprint_value(ctx, vp, '"');
1869 static const char xlat_spaces[] = " ";
1872 static char *xlat_aprint(TALLOC_CTX *ctx, REQUEST *request, xlat_exp_t const * const node,
1873 RADIUS_ESCAPE_STRING escape, void *escape_ctx, int lvl)
1876 char *str = NULL, *child;
1879 XLAT_DEBUG("%.*sxlat aprint %d", lvl, xlat_spaces, node->type);
1881 switch (node->type) {
1883 * Don't escape this.
1886 XLAT_DEBUG("xlat_aprint LITERAL");
1887 return talloc_typed_strdup(ctx, node->fmt);
1890 * Do a one-character expansion.
1896 size_t freespace = 256;
1900 XLAT_DEBUG("xlat_aprint PERCENT");
1902 str = talloc_array(ctx, char, freespace); /* @todo do better allocation */
1905 when = request->timestamp;
1906 if (request->packet) {
1907 when = request->packet->timestamp.tv_sec;
1916 case 'd': /* request day */
1917 (void) localtime_r(&when, &ts);
1918 strftime(str, freespace, "%d", &ts);
1921 case 'l': /* request timestamp */
1922 snprintf(str, freespace, "%lu",
1923 (unsigned long) when);
1926 case 'm': /* request month */
1927 (void) localtime_r(&when, &ts);
1928 strftime(str, freespace, "%m", &ts);
1931 case 'n': /* Request Number*/
1932 snprintf(str, freespace, "%u", request->number);
1935 case 't': /* request timestamp */
1936 CTIME_R(&when, str, freespace);
1937 nl = strchr(str, '\n');
1941 case 'D': /* request date */
1942 (void) localtime_r(&when, &ts);
1943 strftime(str, freespace, "%Y%m%d", &ts);
1946 case 'G': /* request minute */
1947 (void) localtime_r(&when, &ts);
1948 strftime(str, freespace, "%M", &ts);
1951 case 'H': /* request hour */
1952 (void) localtime_r(&when, &ts);
1953 strftime(str, freespace, "%H", &ts);
1956 case 'I': /* Request ID */
1957 if (request->packet) {
1958 snprintf(str, freespace, "%i", request->packet->id);
1962 case 'S': /* request timestamp in SQL format*/
1963 (void) localtime_r(&when, &ts);
1964 strftime(str, freespace, "%Y-%m-%d %H:%M:%S", &ts);
1967 case 'T': /* request timestamp */
1968 (void) localtime_r(&when, &ts);
1969 strftime(str, freespace, "%Y-%m-%d-%H.%M.%S.000000", &ts);
1972 case 'Y': /* request year */
1973 (void) localtime_r(&when, &ts);
1974 strftime(str, freespace, "%Y", &ts);
1977 case 'v': /* Version of code */
1978 snprintf(str, freespace, "%s", radiusd_short_version);
1988 case XLAT_ATTRIBUTE:
1989 XLAT_DEBUG("xlat_aprint ATTRIBUTE");
1991 if (radius_request(&ref, node->attr.tmpl_request) < 0) {
1996 * Some attributes are virtual <sigh>
1998 str = xlat_getvp(ctx, ref, node->attr.tmpl_list, node->attr.tmpl_da, node->attr.tmpl_tag, node->attr.tmpl_num, true);
2000 XLAT_DEBUG("EXPAND attr %s", node->attr.tmpl_da->name);
2001 XLAT_DEBUG(" ---> %s", str);
2006 XLAT_DEBUG("xlat_aprint VIRTUAL");
2007 str = talloc_array(ctx, char, 2048); /* FIXME: have the module call talloc_typed_asprintf */
2008 rcode = node->xlat->func(node->xlat->instance, request, NULL, str, 2048);
2016 XLAT_DEBUG("xlat_aprint MODULE");
2017 if (xlat_process(&child, request, node->child, node->xlat->escape, node->xlat->instance) == 0) {
2021 XLAT_DEBUG("%.*sEXPAND mod %s %s", lvl, xlat_spaces, node->fmt, node->child->fmt);
2022 XLAT_DEBUG("%.*s ---> %s", lvl, xlat_spaces, child);
2024 str = talloc_array(ctx, char, 2048); /* FIXME: have the module call talloc_typed_asprintf */
2025 *str = '\0'; /* Be sure the string is NULL terminated, we now only free on error */
2027 rcode = node->xlat->func(node->xlat->instance, request, child, str, 2048);
2037 XLAT_DEBUG("xlat_aprint REGEX");
2038 child = request_data_reference(request, request,
2039 REQUEST_DATA_REGEX | node->attr.tmpl_num);
2040 if (!child) return NULL;
2042 str = talloc_typed_strdup(ctx, child);
2046 case XLAT_ALTERNATE:
2047 XLAT_DEBUG("xlat_aprint ALTERNATE");
2048 rad_assert(node->child != NULL);
2049 rad_assert(node->alternate != NULL);
2051 str = xlat_aprint(ctx, request, node->child, escape, escape_ctx, lvl);
2054 str = xlat_aprint(ctx, request, node->alternate, escape, escape_ctx, lvl);
2060 * Escape the non-literals we found above.
2062 if (str && escape) {
2065 escaped = talloc_array(ctx, char, 2048); /* FIXME: do something intelligent */
2066 escape(request, escaped, 2038, str, escape_ctx);
2075 static size_t xlat_process(char **out, REQUEST *request, xlat_exp_t const * const head,
2076 RADIUS_ESCAPE_STRING escape, void *escape_ctx)
2080 char **array, *answer;
2081 xlat_exp_t const *node;
2086 * There are no nodes to process, so the result is a zero
2090 *out = talloc_zero_array(request, char, 1);
2095 * Hack for speed. If it's one expansion, just allocate
2096 * that and return, instead of allocating an intermediary
2101 * Pass the MAIN escape function. Recursive
2102 * calls will call node-specific escape
2105 answer = xlat_aprint(request, request, head, escape, escape_ctx, 0);
2107 *out = talloc_zero_array(request, char, 1);
2111 return strlen(answer);
2114 list = 0; /* FIXME: calculate this once */
2115 for (node = head; node != NULL; node = node->next) {
2119 array = talloc_array(request, char *, list);
2120 if (!array) return -1;
2122 for (node = head, i = 0; node != NULL; node = node->next, i++) {
2123 array[i] = xlat_aprint(array, request, node, escape, escape_ctx, 0); /* may be NULL */
2127 for (i = 0; i < list; i++) {
2128 if (array[i]) total += strlen(array[i]); /* FIXME: calculate strlen once */
2133 *out = talloc_zero_array(request, char, 1);
2137 answer = talloc_array(request, char, total + 1);
2140 for (i = 0; i < list; i++) {
2144 len = strlen(array[i]);
2145 memcpy(answer + total, array[i], len);
2149 answer[total] = '\0';
2150 talloc_free(array); /* and child entries */
2157 /** Replace %whatever in a string.
2159 * See 'doc/variables.txt' for more information.
2161 * @param[out] out Where to write pointer to output buffer.
2162 * @param[in] outlen Size of out.
2163 * @param[in] request current request.
2164 * @param[in] node the xlat structure to expand
2165 * @param[in] escape function to escape final value e.g. SQL quoting.
2166 * @param[in] escape_ctx pointer to pass to escape function.
2167 * @return length of string written @bug should really have -1 for failure
2169 static ssize_t xlat_expand_struct(char **out, size_t outlen, REQUEST *request, xlat_exp_t const *node,
2170 RADIUS_ESCAPE_STRING escape, void *escape_ctx)
2175 rad_assert(node != NULL);
2177 len = xlat_process(&buff, request, node, escape, escape_ctx);
2178 if ((len < 0) || !buff) {
2179 rad_assert(buff == NULL);
2180 if (*out) *out[0] = '\0';
2187 strlcpy(*out, buff, outlen);
2191 return strlen(*out);
2194 static ssize_t xlat_expand(char **out, size_t outlen, REQUEST *request, char const *fmt,
2195 RADIUS_ESCAPE_STRING escape, void *escape_ctx) CC_HINT(nonnull (1, 3, 4));
2197 /** Replace %whatever in a string.
2199 * See 'doc/variables.txt' for more information.
2201 * @param[out] out Where to write pointer to output buffer.
2202 * @param[in] outlen Size of out.
2203 * @param[in] request current request.
2204 * @param[in] fmt string to expand.
2205 * @param[in] escape function to escape final value e.g. SQL quoting.
2206 * @param[in] escape_ctx pointer to pass to escape function.
2207 * @return length of string written @bug should really have -1 for failure
2209 static ssize_t CC_HINT(nonnull (1, 3, 4)) xlat_expand(char **out, size_t outlen, REQUEST *request, char const *fmt,
2210 RADIUS_ESCAPE_STRING escape, void *escape_ctx)
2216 * Give better errors than the old code.
2218 len = xlat_tokenize_request(request, fmt, &node);
2223 *out = talloc_zero_array(request, char, 1);
2229 if (*out) *out[0] = '\0';
2233 len = xlat_expand_struct(out, outlen, request, node, escape, escape_ctx);
2236 RDEBUG2("EXPAND %s", fmt);
2237 RDEBUG2(" --> %s", *out);
2243 * Try to convert an xlat to a tmpl for efficiency
2245 value_pair_tmpl_t *radius_xlat2tmpl(TALLOC_CTX *ctx, xlat_exp_t *node)
2247 value_pair_tmpl_t *vpt;
2249 if (node->next || (node->type != XLAT_ATTRIBUTE)) return NULL;
2252 * @todo it should be possible to emulate the concat and count operations in the
2255 if ((node->attr.tmpl_num == NUM_COUNT) || (node->attr.tmpl_num == NUM_ALL)) return NULL;
2257 vpt = tmpl_alloc(ctx, TMPL_TYPE_ATTR, node->fmt, -1);
2258 if (!vpt) return NULL;
2259 vpt->tmpl_request = node->attr.tmpl_request;
2260 vpt->tmpl_list = node->attr.tmpl_list;
2261 vpt->tmpl_da = node->attr.tmpl_da;
2262 vpt->tmpl_num = node->attr.tmpl_num;
2263 vpt->tmpl_tag = node->attr.tmpl_tag;
2270 ssize_t radius_xlat(char *out, size_t outlen, REQUEST *request, char const *fmt, RADIUS_ESCAPE_STRING escape, void *ctx)
2272 return xlat_expand(&out, outlen, request, fmt, escape, ctx);
2275 ssize_t radius_axlat(char **out, REQUEST *request, char const *fmt, RADIUS_ESCAPE_STRING escape, void *ctx)
2277 return xlat_expand(out, 0, request, fmt, escape, ctx);
2280 ssize_t radius_axlat_struct(char **out, REQUEST *request, xlat_exp_t const *xlat, RADIUS_ESCAPE_STRING escape, void *ctx)
2282 return xlat_expand_struct(out, 0, request, xlat, escape, ctx);