The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
xlat_eval.c
Go to the documentation of this file.
1/*
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.
6 *
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.
11 *
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
15 */
16
17/**
18 * $Id: 46fc7ff175ce662461725d26b68dfca119948e00 $
19 *
20 * @file xlat_eval.c
21 * @brief String expansion ("translation"). Evaluation of pre-parsed xlat expansions.
22 *
23 * @copyright 2018-2021 Arran Cudbard-Bell (a.cudbardb@freeradius.org)
24 * @copyright 2000,2006 The FreeRADIUS server project
25 * @copyright 2000 Alan DeKok (aland@freeradius.org)
26 */
27RCSID("$Id: 46fc7ff175ce662461725d26b68dfca119948e00 $")
28
29#include <freeradius-devel/server/base.h>
30#include <freeradius-devel/server/tmpl_dcursor.h>
31#include <freeradius-devel/server/rcode.h>
32#include <freeradius-devel/unlang/mod_action.h>
33#include <freeradius-devel/unlang/xlat_priv.h>
34
35static int instance_count = 0;
36
38
40 { .out = &dict_freeradius, .proto = "freeradius" },
42};
43
44fr_dict_attr_t const *attr_expr_bool_enum; /* xlat_expr.c */
45fr_dict_attr_t const *attr_cast_base; /* xlat_expr.c */
46
58
60 { .out = &attr_expr_bool_enum, .name = "Expr-Bool-Enum", .type = FR_TYPE_BOOL, .dict = &dict_freeradius },
61 { .out = &attr_cast_base, .name = "Cast-Base", .type = FR_TYPE_UINT8, .dict = &dict_freeradius },
62
63 { .out = &attr_cast_time_res_sec, .name = "Cast-Time-Res-Sec", .type = FR_TYPE_TIME_DELTA, .dict = &dict_freeradius },
64 { .out = &attr_cast_time_res_min, .name = "Cast-Time-Res-Min", .type = FR_TYPE_TIME_DELTA, .dict = &dict_freeradius },
65 { .out = &attr_cast_time_res_hour, .name = "Cast-Time-Res-Hour", .type = FR_TYPE_TIME_DELTA, .dict = &dict_freeradius },
66 { .out = &attr_cast_time_res_day, .name = "Cast-Time-Res-Day", .type = FR_TYPE_TIME_DELTA, .dict = &dict_freeradius },
67 { .out = &attr_cast_time_res_week, .name = "Cast-Time-Res-Week", .type = FR_TYPE_TIME_DELTA, .dict = &dict_freeradius },
68 { .out = &attr_cast_time_res_month, .name = "Cast-Time-Res-Month", .type = FR_TYPE_TIME_DELTA, .dict = &dict_freeradius },
69 { .out = &attr_cast_time_res_year, .name = "Cast-Time-Res-Year", .type = FR_TYPE_TIME_DELTA, .dict = &dict_freeradius },
70 { .out = &attr_cast_time_res_csec, .name = "Cast-Time-Res-Centi-Sec", .type = FR_TYPE_TIME_DELTA, .dict = &dict_freeradius },
71 { .out = &attr_cast_time_res_msec, .name = "Cast-Time-Res-Milli-Sec", .type = FR_TYPE_TIME_DELTA, .dict = &dict_freeradius },
72 { .out = &attr_cast_time_res_usec, .name = "Cast-Time-Res-Micro-Sec", .type = FR_TYPE_TIME_DELTA, .dict = &dict_freeradius },
73 { .out = &attr_cast_time_res_nsec, .name = "Cast-Time-Res-Nano-Sec", .type = FR_TYPE_TIME_DELTA, .dict = &dict_freeradius },
74
76};
77
79 { L("done"), XLAT_ACTION_DONE },
80 { L("fail"), XLAT_ACTION_FAIL },
81 { L("push-child"), XLAT_ACTION_PUSH_CHILD },
82 { L("yield"), XLAT_ACTION_YIELD }
83};
85
86/*
87 * This should be updated if fr_time_precision_table[] adds more time resolutions.
88 */
90 { L("microseconds"), &attr_cast_time_res_usec },
91 { L("us"), &attr_cast_time_res_usec },
92
93 { L("nanoseconds"), &attr_cast_time_res_nsec },
94 { L("ns"), &attr_cast_time_res_nsec },
95
96 { L("milliseconds"), &attr_cast_time_res_msec },
97 { L("ms"), &attr_cast_time_res_msec },
98
99 { L("centiseconds"), &attr_cast_time_res_csec },
100 { L("cs"), &attr_cast_time_res_csec },
101
102 { L("seconds"), &attr_cast_time_res_sec },
103 { L("s"), &attr_cast_time_res_sec },
104
105 { L("minutes"), &attr_cast_time_res_min },
106 { L("m"), &attr_cast_time_res_min },
107
108 { L("hours"), &attr_cast_time_res_hour },
109 { L("h"), &attr_cast_time_res_hour },
110
111 { L("days"), &attr_cast_time_res_day },
112 { L("d"), &attr_cast_time_res_day },
113
114 { L("weeks"), &attr_cast_time_res_week },
115 { L("w"), &attr_cast_time_res_week },
116
117 /*
118 * These use special values FR_TIME_DUR_MONTH and FR_TIME_DUR_YEAR
119 */
120 { L("months"), &attr_cast_time_res_month },
121 { L("M"), &attr_cast_time_res_month },
122
123 { L("years"), &attr_cast_time_res_year },
124 { L("y"), &attr_cast_time_res_year },
125
126};
128
129fr_dict_attr_t const *xlat_time_res_attr(char const *res)
130{
131 fr_dict_attr_t const **da_p;
132
134 if (!da_p) return NULL;
135
136 return *da_p;
137}
138
139static ssize_t xlat_eval_sync(TALLOC_CTX *ctx, char **out, request_t *request, xlat_exp_head_t const * const head,
140 xlat_escape_legacy_t escape, void const *escape_ctx);
141
142/** Reconstruct the original expansion string from an xlat tree
143 *
144 * @param[in] out sbuff to print result in.
145 * @param[in] node in the tree to start printing.
146 * @return
147 * - The original expansion string on success.
148 * - NULL on error.
149 */
151{
152 switch (node->type) {
153 case XLAT_BOX:
154 case XLAT_GROUP:
155 fr_assert(node->fmt != NULL);
156 return fr_sbuff_in_sprintf(out, "%pV", fr_box_strvalue_buffer(node->fmt));
157
158 case XLAT_ONE_LETTER:
159 fr_assert(node->fmt != NULL);
160 return fr_sbuff_in_sprintf(out, "%%%s", node->fmt);
161
162 case XLAT_TMPL:
163 fr_assert(node->fmt != NULL);
164
165 /*
166 * Just print the attribute name, or the nested xlat.
167 */
168 if (tmpl_is_attr(node->vpt) || (tmpl_is_xlat(node->vpt))) {
169 return fr_sbuff_in_strcpy(out, node->fmt);
170
171 } else {
172 return fr_sbuff_in_sprintf(out, "%%{%s}", node->fmt);
173 }
174
175#ifdef HAVE_REGEX
176 case XLAT_REGEX:
177 return fr_sbuff_in_sprintf(out, "%%{%u}", node->regex_index);
178#endif
179
180 case XLAT_FUNC:
181 {
182 bool first_done = false;
183 fr_sbuff_t our_out;
184 fr_slen_t slen;
185
186 /*
187 * No arguments, just print an empty function.
188 */
189 if (!xlat_exp_head(node->call.args)) return fr_sbuff_in_sprintf(out, "%%%s()", node->call.func->name);
190
191 our_out = FR_SBUFF(out);
192 FR_SBUFF_IN_SPRINTF_RETURN(&our_out, "%%%s(", node->call.func->name);
193
194 if (node->call.args) {
195 xlat_exp_foreach(node->call.args, arg) {
196 if (first_done && (node->call.func->args)) {
197 FR_SBUFF_IN_CHAR_RETURN(&our_out, ',');
198 }
199
200 slen = xlat_fmt_print(&our_out, arg);
201 if (slen < 0) return slen - fr_sbuff_used(&our_out);
202
203 first_done = true;
204 }
205 }
206
207 FR_SBUFF_IN_CHAR_RETURN(&our_out, ')');
208 return fr_sbuff_set(out, &our_out);
209 }
210
211 default:
212 return 0;
213 }
214}
215
216/** Output what we're currently expanding
217 *
218 * @param[in] request The current request.
219 * @param[in] node Being processed.
220 * @param[in] args from previous expansion.
221 * @param[in] line Unused
222 */
223static inline void xlat_debug_log_expansion(request_t *request, xlat_exp_t const *node, fr_value_box_list_t const *args, UNUSED int line)
224{
225 if (node->flags.constant) return;
226
227 if (!RDEBUG_ENABLED2) return;
228
229 /*
230 * Because it's difficult to keep track of what
231 * the function was actually called with,
232 * we print the concatenated arguments list as
233 * well as the original fmt string.
234 */
235 if ((node->type == XLAT_FUNC) && !xlat_is_literal(node->call.args)) {
236 fr_token_t token = node->call.func->token;
237
238 if ((token == T_INVALID) || (!fr_comparison_op[token] && !fr_binary_op[token])) {
239 RDEBUG2("| %%%s(%pM)", node->call.func->name, args);
240 } else {
241 fr_value_box_t *a, *b;
242
243 a = fr_value_box_list_head(args);
244 b = fr_value_box_list_next(args, a);
245
246 RDEBUG2("| (%pR %s %pR)", a, fr_tokens[node->call.func->token], b);
247
248#ifndef NDEBUG
249 if (a && b) {
250 a = fr_value_box_list_next(args, b);
251 if (a) {
252 RDEBUG2("| ... ??? %pR", a);
253 fr_assert(0);
254 }
255 }
256#endif
257
258 }
259 } else {
260 fr_sbuff_t *agg;
261
262 FR_SBUFF_TALLOC_THREAD_LOCAL(&agg, 1024, SIZE_MAX);
263
264 if (xlat_fmt_print(agg, node) < 0) {
265 RERROR("Failed printing expansion");
266 return;
267 }
268 RDEBUG2("| %s", fr_sbuff_start(agg)); /* print line number here for debugging */
269 }
270}
271
272/** Output the list result of an expansion
273 *
274 * @param[in] request The current request.
275 * @param[in] node which was expanded.
276 * @param[in] result of the expansion.
277 */
278static inline void xlat_debug_log_list_result(request_t *request, xlat_exp_t const *node, fr_value_box_list_t const *result)
279{
280 if (node->flags.constant) return;
281
282 if (!RDEBUG_ENABLED2) return;
283
284 RDEBUG2("| --> %pM", result);
285}
286
287/** Output the result of an expansion
288 *
289 * @param[in] request The current request.
290 * @param[in] node which was expanded.
291 * @param[in] result of the expansion.
292 */
293static inline void xlat_debug_log_result(request_t *request, xlat_exp_t const *node, fr_value_box_t const *result)
294{
295 if (node->flags.constant) return;
296
297 if (!RDEBUG_ENABLED2) return;
298
299 RDEBUG2("| --> %pR", result);
300}
301
302static int xlat_arg_stringify(request_t *request, xlat_arg_parser_t const *arg, xlat_exp_t const *node, fr_value_box_t *vb)
303{
304 int rcode;
305
306 if (vb->type == FR_TYPE_GROUP) {
307 fr_value_box_list_foreach(&vb->vb_group, child) {
308 if (xlat_arg_stringify(request, arg, NULL, child) < 0) return -1;
309 }
310
311 if (!node || (node->quote == T_BARE_WORD)) return 0;
312
313 fr_assert(node->type == XLAT_GROUP);
314
315 /*
316 * Empty lists are empty strings.
317 */
318 if (!fr_value_box_list_head(&vb->vb_group)) {
319 fr_value_box_entry_t entry;
320
321 entry = vb->entry;
322 fr_value_box_init(vb, FR_TYPE_STRING, NULL, false);
323 fr_value_box_strdup(vb, vb, NULL, "", false);
324 vb->entry = entry;
325
327 return 0;
328 }
329
330 /*
331 * Mash all of the child value-box to a string.
332 */
333 if (fr_value_box_list_concat_in_place(vb, vb, &vb->vb_group, FR_TYPE_STRING, FR_VALUE_BOX_LIST_FREE, true, SIZE_MAX) < 0) {
334 return -1;
335 }
336
337 /*
338 * Do NOT mark this as safe for anything. The inputs could have come from anywhere.
339 *
340 * The arg->safe_for value is set ONLY after the data has been escaped.
341 */
342 return 0;
343 }
344
345 if (fr_value_box_is_safe_for(vb, arg->safe_for) && !arg->always_escape) return 0;
346
347 rcode = arg->func(request, vb, arg->uctx);
348 if (rcode != 0) return rcode;
349
351 return 0;
352}
353
354/** Process an individual xlat argument value box group
355 *
356 * @param[in] ctx to allocate any additional buffers in
357 * @param[in,out] list of value boxes representing one argument
358 * @param[in] request currently being processed
359 * @param[in] name of the function being called
360 * @param[in] arg specification of current argument
361 * @param[in] node expansion for the current argument
362 * @param[in] arg_num number of current argument in the argument specifications
363 * @return
364 * - XLAT_ACTION_DONE on success.
365 * - XLAT_ACTION_FAIL on failure.
366 */
367static xlat_action_t xlat_process_arg_list(TALLOC_CTX *ctx, fr_value_box_list_t *list, request_t *request,
368 char const *name, xlat_arg_parser_t const *arg, xlat_exp_t const *node, unsigned int arg_num)
369{
370 fr_value_box_t *vb;
371 bool concat = false;
372 bool quoted = false;
374
375 /*
376 * The function does it's own escaping and concatenation.
377 */
378 if (arg->will_escape) {
380 return XLAT_ACTION_DONE;
381 }
382
383 /*
384 * See if we have to concatenate multiple value-boxes into one output string / whatever.
385 *
386 * If the input xlat is more complicated expression, it's going to be a function, e.g.
387 *
388 * 1+2 --> %op_add(1,2).
389 *
390 * And then we can't do escaping. Note that this is also the case for
391 *
392 * "foo" + User-Name --> %op_add("foo", User-Name)
393 *
394 * Arguably, we DO want to escape User-Name, but not Foo. Because "+" here is a special case. :(
395 */
396 if ((fr_dlist_num_elements(&node->group->dlist) == 1) && (xlat_exp_head(node->group)->quote != T_BARE_WORD)) {
397 quoted = concat = true;
399
400 } else {
401 concat = arg->concat;
402 type = arg->type;
403 }
404
405 /*
406 * No data - nothing to do.
407 */
408 if (fr_value_box_list_empty(list)) {
409 /*
410 * The expansion resulted in no data, BUT the admin wants a string. So we create an
411 * empty string.
412 *
413 * i.e. If attribute 'foo' doesn't exist, then we have:
414 *
415 * %{foo} --> nothing, because 'foo' doesn't exist
416 * "%{foo}" --> "", because we want a string, therefore the contents of the string are nothing.
417 *
418 * Also note that an empty string satisfies a required argument.
419 */
420 if (quoted) {
421 MEM(vb = fr_value_box_alloc(ctx, FR_TYPE_STRING, NULL));
422 fr_value_box_strdup(vb, vb, NULL, "", false);
423 fr_value_box_list_insert_tail(list, vb);
424
425 return XLAT_ACTION_DONE;
426 }
427
428 if (arg->required) {
429 REDEBUG("Function \"%s\" is missing required argument %u", name, arg_num);
430 return XLAT_ACTION_FAIL;
431 }
432
433 return XLAT_ACTION_DONE;
434 }
435
436 /*
437 * The function may be URI or SQL, which have different sub-types. So we call the function if it
438 * is NOT marked as "globally safe for SQL", but the called function may check the more specific
439 * flag "safe for MySQL". And then things which aren't safe for MySQL are escaped, and then
440 * marked as "safe for MySQL".
441 *
442 * If the escape function returns "0", then we set the safe_for value. If the escape function
443 * returns "1", then it has set the safe_for value.
444 */
445 if (arg->func) {
446 for (vb = fr_value_box_list_head(list);
447 vb != NULL;
448 vb = fr_value_box_list_next(list, vb)) {
449 if (xlat_arg_stringify(request, arg, node, vb) < 0) {
450 RPEDEBUG("Function \"%s\" failed escaping argument %u", name, arg_num);
451 return XLAT_ACTION_FAIL;
452 }
453 }
454 }
455
456 vb = fr_value_box_list_head(list);
457 fr_assert(node->type == XLAT_GROUP);
458
459 /*
460 * Concatenate child boxes, then cast to the desired type.
461 */
462 if (concat) {
463 if (fr_value_box_list_concat_in_place(ctx, vb, list, type, FR_VALUE_BOX_LIST_FREE, true, SIZE_MAX) < 0) {
464 RPEDEBUG("Function \"%s\" failed concatenating arguments to type %s", name, fr_type_to_str(type));
465 return XLAT_ACTION_FAIL;
466 }
467 fr_assert(fr_value_box_list_num_elements(list) == 1);
468
469 goto check_types;
470 }
471
472 /*
473 * Only a single child box is valid here. Check there is
474 * just one, cast to the correct type
475 */
476 if (arg->single) {
477 if (fr_value_box_list_num_elements(list) > 1) {
478 RPEDEBUG("Function \"%s\" was provided an incorrect number of values at argument %u, "
479 "expected %s got %u",
480 name, arg_num,
481 arg->required ? "1" : "0-1",
482 fr_value_box_list_num_elements(list));
483 return XLAT_ACTION_FAIL;
484 }
485
486 check_types:
487 if (!fr_type_is_leaf(arg->type)) goto check_non_leaf;
488
489 /*
490 * Cast to the correct type if necessary.
491 */
492 if (vb->type != arg->type) {
493 if (fr_value_box_cast_in_place(ctx, vb, arg->type, NULL) < 0) {
494 cast_error:
495 RPEDEBUG("Function \"%s\" failed to cast argument %u to type %s", name, arg_num, fr_type_to_str(arg->type));
496 return XLAT_ACTION_FAIL;
497 }
498 }
499
500 return XLAT_ACTION_DONE;
501 }
502
503 /*
504 * We're neither concatenating nor do we only expect a single value,
505 * cast all child values to the required type.
506 */
507 if (fr_type_is_leaf(arg->type)) {
508 do {
509 if (vb->type == arg->type) continue;
510 if (fr_value_box_cast_in_place(ctx, vb,
511 arg->type, NULL) < 0) goto cast_error;
512 } while ((vb = fr_value_box_list_next(list, vb)));
513
514 return XLAT_ACTION_DONE;
515 }
516
517check_non_leaf:
518 if (arg->type == FR_TYPE_VOID) return XLAT_ACTION_DONE;
519
520 /*
521 * We already have a pair cursor, the argument was an attribute reference.
522 * Check if the arg is required that it has at least one pair.
523 */
524 if (vb->type == FR_TYPE_PAIR_CURSOR) {
526 return XLAT_ACTION_DONE;
527 }
528
529 /*
530 * If the argument is a pair
531 */
532 fr_assert(vb->type != FR_TYPE_PAIR_CURSOR);
533
534 {
535 int err;
536 tmpl_t *vpt;
537
538 /*
539 * Cursor names have to be strings, which are completely safe.
540 */
541 if (vb->type != FR_TYPE_STRING) {
542 REDEBUG("Expected attribute reference as string, not %s", fr_type_to_str(vb->type));
543 return XLAT_ACTION_FAIL;
544 }
545
548 REDEBUG("Refusing to reference attribute from unsafe data");
549 return XLAT_ACTION_FAIL;
550 }
551
552 if (tmpl_afrom_attr_str(ctx, NULL, &vpt, vb->vb_strvalue,
553 &(tmpl_rules_t){
554 .attr = {
555 .dict_def = request->local_dict,
556 .list_def = request_attr_request,
557 .allow_wildcard = arg->allow_wildcard,
558 }
559 }) <= 0) {
560 RPEDEBUG("Failed parsing attribute reference");
561 return XLAT_ACTION_FAIL;
562 }
563
565
566 /*
567 * The cursor can return something, nothing (-1), or no list (-2) or no context (-3). Of
568 * these, only the last two are actually errors.
569 *
570 * "no matching pair" returns an empty cursor.
571 */
572 (void) tmpl_dcursor_value_box_init(&err, vb, vb, request, vpt);
573 if (err < -1) return XLAT_ACTION_FAIL;
574 if (arg->required && err == -1) return XLAT_ACTION_FAIL;
575 }
576
577#undef ESCAPE
578
579 return XLAT_ACTION_DONE;
580}
581
582
583/** Process list of boxed values provided as input to an xlat
584 *
585 * Ensures that the value boxes passed to an xlat function match the
586 * requirements listed in its "args", and escapes any tainted boxes
587 * using the specified escaping routine.
588 *
589 * @param[in] ctx in which to allocate any buffers.
590 * @param[in,out] list value boxes provided as input.
591 * List will be modified in accordance to rules
592 * provided in the args array.
593 * @param[in] request being processed.
594 * @param[in] node which is a function
595 */
596static inline CC_HINT(always_inline)
597xlat_action_t xlat_process_args(TALLOC_CTX *ctx, fr_value_box_list_t *list,
598 request_t *request, xlat_exp_t const *node)
599{
600 xlat_t const *func = node->call.func;
601 xlat_arg_parser_t const *arg_p = func->args;
602 xlat_exp_t *arg, *arg_next;
603 xlat_action_t xa;
604 fr_value_box_t *vb, *vb_next;
605
606 /*
607 * No args registered for this xlat
608 */
609 if (!func->args) return XLAT_ACTION_DONE;
610
611 /*
612 * Manage the arguments.
613 */
614 vb = fr_value_box_list_head(list);
615 arg = xlat_exp_head(node->call.args);
616
617 while (arg_p->type != FR_TYPE_NULL) {
618 /*
619 * Separate check to see if the group
620 * box is there. Check in
621 * xlat_process_arg_list verifies it
622 * has a value.
623 */
624 if (!vb) {
625 if (arg_p->required) {
626 missing:
627 REDEBUG("Function \"%s\" is missing required argument %u",
628 func->name, (unsigned int)((arg_p - func->args) + 1));
629 return XLAT_ACTION_FAIL;
630 }
631
632 /*
633 * The argument isn't required. Just omit it. xlat_func_args_set() enforces
634 * that optional arguments are at the end of the argument list.
635 */
636 return XLAT_ACTION_DONE;
637 }
638
639 /*
640 * Everything in the top level list should be
641 * groups
642 */
643 if (!fr_cond_assert(vb->type == FR_TYPE_GROUP)) return XLAT_ACTION_FAIL;
644
645 /*
646 * pre-advance, in case the vb is replaced
647 * during processing.
648 */
649 vb_next = fr_value_box_list_next(list, vb);
650 arg_next = xlat_exp_next(node->call.args, arg);
651
652 xa = xlat_process_arg_list(ctx, &vb->vb_group, request, func->name, arg_p, arg,
653 (unsigned int)((arg_p - func->args) + 1));
654 if (xa != XLAT_ACTION_DONE) return xa;
655
656 /*
657 * This argument doesn't exist. That might be OK, or it may be a fatal error.
658 */
659 if (fr_value_box_list_empty(&vb->vb_group)) {
660 /*
661 * Variadic rules deal with empty boxes differently...
662 */
663 switch (arg_p->variadic) {
665 fr_value_box_list_talloc_free_head(list);
666 goto do_next;
667
669 goto empty_ok;
670
672 break;
673 }
674
675 /*
676 * Empty groups for optional arguments are OK, we can just stop processing the list.
677 */
678 if (!arg_p->required) {
679 /*
680 * If the caller doesn't care about the type, then we leave the
681 * empty group there.
682 */
683 if (arg_p->type == FR_TYPE_VOID) goto do_next;
684
685 /*
686 * The caller does care about the type, and we don't have any
687 * matching data. Omit this argument, and all arguments after it.
688 *
689 * i.e. if the caller has 3 optional arguments, all
690 * FR_TYPE_UINT8, and the first one is missing, then we MUST
691 * either supply boxes all of FR_TYPE_UINT8, OR we supply nothing.
692 *
693 * We can't supply a box of any other type, because the caller
694 * has declared that it wants FR_TYPE_UINT8, and is naively
695 * accessing the box as vb_uint8, hoping that it's being passed
696 * the right thing.
697 */
698 fr_value_box_list_talloc_free_head(list);
699 break;
700 }
701
702 /*
703 * If the caller is expecting a particular type, then getting nothing is
704 * an error.
705 *
706 * If the caller manually checks the input type, then we can leave it as
707 * an empty group.
708 */
709 if (arg_p->type != FR_TYPE_VOID) goto missing;
710 }
711
712 empty_ok:
713 /*
714 * In some cases we replace the current argument with the head of the group.
715 *
716 * xlat_process_arg_list() has already done concatenations for us.
717 */
718 if (arg_p->single || arg_p->concat) {
719 fr_value_box_t *head = fr_value_box_list_pop_head(&vb->vb_group);
720
721 /*
722 * If we're meant to be smashing the argument
723 * to a single box, but the group was empty,
724 * add a null box instead so ordering is maintained
725 * for subsequent boxes.
726 */
727 if (!head) head = fr_value_box_alloc_null(ctx);
728 fr_value_box_list_replace(list, vb, head);
729 talloc_free(vb);
730 }
731
732 do_next:
733 if (arg_p->variadic) {
734 if (!vb_next) break;
735 } else {
736 arg_p++;
737 arg = arg_next;
738 }
739 vb = vb_next;
740 }
741
742 return XLAT_ACTION_DONE;
743}
744
745/** Validate that the return values from an xlat function match what it registered
746 *
747 * @param[in] request The current request.
748 * @param[in] func that was called.
749 * @param[in] returned the output list of the function.
750 * @param[in] pos current position in the output list.
751 * @return
752 * - true - If return values were correct.
753 * - false - If the return values were incorrect.
754 */
755static inline CC_HINT(nonnull(1,2,3))
756bool xlat_process_return(request_t *request, xlat_t const *func, fr_value_box_list_t const *returned, fr_value_box_t *pos)
757{
758 unsigned int count = 0;
759
760 /*
761 * Nothing to validate. We don't yet enforce that functions
762 * must return at least one instance of their type.
763 */
764 if (!pos || fr_type_is_void(func->return_type)) return true;
765
766 if (fr_type_is_null(func->return_type)) {
767 /* Dynamic expansion to get the right name */
768 REDEBUG("%s return type registered as %s, but %s expansion produced data",
769 func->name, func->name, fr_type_to_str(func->return_type));
770
771 /* We are not forgiving for debug builds */
772 fr_assert_fail("Treating invalid return type as fatal");
773
774 return false;
775 }
776
777 do {
778 if (pos->type != func->return_type) {
779 REDEBUG("%s returned invalid result type at index %u. Expected type %s, got type %s",
780 func->name, count, fr_type_to_str(func->return_type), fr_type_to_str(pos->type));
781
782 /* We are not forgiving for debug builds */
783 fr_assert_fail("Treating invalid return type as fatal");
784 }
785 fr_value_box_mark_safe_for(pos, func->return_safe_for); /* Always set this */
786 count++;
787 } while ((pos = fr_value_box_list_next(returned, pos)));
788
789 return true;
790}
791
792/** One letter expansions
793 *
794 * @param[in] ctx to allocate boxed value, and buffers in.
795 * @param[out] out Where to write the boxed value.
796 * @param[in] request The current request.
797 * @param[in] letter to expand.
798 * @return
799 * - #XLAT_ACTION_FAIL on memory allocation errors.
800 * - #XLAT_ACTION_DONE if we're done processing this node.
801 *
802 */
803static inline CC_HINT(always_inline)
804xlat_action_t xlat_eval_one_letter(TALLOC_CTX *ctx, fr_value_box_list_t *out,
805 request_t *request, char letter)
806{
807
808 char buffer[64];
809 struct tm ts;
810 time_t now;
812
813 now = fr_time_to_sec(request->packet->timestamp);
814
815 switch (letter) {
816 case '%':
818 if (fr_value_box_strdup(value, value, NULL, "%", false) < 0) {
820 return XLAT_ACTION_FAIL;
821 }
822 break;
823
824 /*
825 * RADIUS request values
826 */
827
828 case 'I': /* Request ID */
830 value->datum.uint32 = request->packet->id;
831 break;
832
833 case 'n': /* Request number */
835 value->datum.uint64 = request->number;
836 break;
837
838 case 's': /* First request in this sequence */
840 value->datum.uint64 = request->seq_start;
841 break;
842
843 /*
844 * Current time
845 */
846
847 case 'c': /* Current epoch time seconds */
848 /*
849 * @todo - leave this as FR_TYPE_DATE, but add an enumv which changes the scale to
850 * seconds?
851 */
853 value->datum.uint64 = (uint64_t)fr_time_to_sec(fr_time());
854 break;
855
856 case 'C': /* Current epoch time microsecond component */
857 /*
858 * @todo - we probably should remove this now that we have FR_TYPE_DATE with scaling.
859 */
861 value->datum.uint64 = (uint64_t)fr_time_to_usec(fr_time()) % 1000000;
862 break;
863
864 /*
865 * Time of the current request
866 */
867
868 case 'd': /* Request day */
869 if (!localtime_r(&now, &ts)) {
870 error:
871 REDEBUG("Failed converting packet timestamp to localtime: %s", fr_syserror(errno));
872 return XLAT_ACTION_FAIL;
873 }
874
876 value->datum.uint8 = ts.tm_mday;
877 break;
878
879 case 'D': /* Request date */
880 if (!localtime_r(&now, &ts)) goto error;
881
882 strftime(buffer, sizeof(buffer), "%Y%m%d", &ts);
883
885 if (fr_value_box_strdup(value, value, NULL, buffer, false) < 0) {
887 goto error;
888 }
889 break;
890
891 case 'e': /* Request second */
892 if (!localtime_r(&now, &ts)) goto error;
893
895 value->datum.uint8 = ts.tm_sec;
896 break;
897
898 case 'G': /* Request minute */
899 if (!localtime_r(&now, &ts)) goto error;
900
902 value->datum.uint8 = ts.tm_min;
903 break;
904
905 case 'H': /* Request hour */
906 if (!localtime_r(&now, &ts)) goto error;
907
909 value->datum.uint8 = ts.tm_hour;
910 break;
911
912 case 'l': /* Request timestamp as seconds since the epoch */
913 /*
914 * @todo - leave this as FR_TYPE_DATE, but add an enumv which changes the scale to
915 * seconds?
916 */
918 value->datum.uint64 = (uint64_t ) now;
919 break;
920
921 case 'm': /* Request month */
922 if (!localtime_r(&now, &ts)) goto error;
923
925 value->datum.uint8 = ts.tm_mon + 1;
926 break;
927
928 case 'M': /* Request time microsecond component */
929 /*
930 * @todo - we probably should remove this now that we have FR_TYPE_DATE with scaling.
931 */
933 value->datum.uint64 = (uint64_t)fr_time_to_usec(request->packet->timestamp) % 1000000;
934 break;
935
936 case 'S': /* Request timestamp in SQL format */
937 if (!localtime_r(&now, &ts)) goto error;
938
939 strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", &ts);
940
942 if (fr_value_box_strdup(value, value, NULL, buffer, false) < 0) goto error;
943 break;
944
945 case 't': /* Request timestamp in CTIME format */
946 {
947 char *p;
948
949 CTIME_R(&now, buffer, sizeof(buffer));
950 p = strchr(buffer, '\n');
951 if (p) *p = '\0';
952
954 if (fr_value_box_strdup(value, value, NULL, buffer, false) < 0) goto error;
955 }
956 break;
957
958 case 'T': /* Request timestamp in ISO format */
959 {
960 int len = 0;
961
962 if (!gmtime_r(&now, &ts)) goto error;
963
964 if (!(len = strftime(buffer, sizeof(buffer) - 1, "%Y-%m-%dT%H:%M:%S", &ts))) {
965 REDEBUG("Failed converting packet timestamp to gmtime: Buffer full");
966 return XLAT_ACTION_FAIL;
967 }
968 strcat(buffer, ".");
969 len++;
970 snprintf(buffer + len, sizeof(buffer) - len, "%03i",
971 (int) fr_time_to_msec(request->packet->timestamp) % 1000);
972
974 if (fr_value_box_strdup(value, value, NULL, buffer, false) < 0) goto error;
975 }
976 break;
977
978 case 'Y': /* Request year */
979 if (!localtime_r(&now, &ts)) goto error;
980
982
983 value->datum.uint16 = ts.tm_year + 1900;
984 break;
985
986 default:
987 fr_assert_fail("%%%c is not a valid one letter expansion", letter);
988 return XLAT_ACTION_FAIL;
989 }
990
991 fr_value_box_list_insert_tail(out, value);
992
993 return XLAT_ACTION_DONE;
994}
995
996typedef struct {
998 fr_value_box_list_t list;
1001
1003 xlat_ctx_t const *xctx,
1004 UNUSED request_t *request, UNUSED fr_value_box_list_t *in)
1005{
1006 xlat_exec_rctx_t *rctx = talloc_get_type_abort(xctx->rctx, xlat_exec_rctx_t);
1007
1008 if (rctx->status != 0) {
1009 fr_strerror_printf("Program failed with status %d", rctx->status);
1010 return XLAT_ACTION_FAIL;
1011 }
1012
1013#if 0
1014 /*
1015 * Comment this out until such time as we better track exceptions.
1016 *
1017 * Enabling this code causes some keyword tests to fail, specifically
1018 * xlat-alternation-with-func and if-regex-match-named.
1019 *
1020 * The regex tests are failing because the various regex_request_to_sub() functions are returning
1021 * errors when there is no previous regex, OR when the referenced regex match doesn't exist.
1022 * This should arguably be a success with NULL results.
1023 *
1024 * The alternation test is failing because a function is called with an argument that doesn't
1025 * exist, inside of an alternation. e.g. %{%foo(nope) || bar}. We arguably want the alternation
1026 * to catch this error, and run the alternate path "bar".
1027 *
1028 * However, doing that would involve more changes. Alternation could catch LHS errors of
1029 * XLAT_FAIL, and then run the RHS. Doing that would require it to manually expand each
1030 * argument, and catch the errors. Note that this is largely what Perl and Python do with their
1031 * logical "and" / "or" functions.
1032 *
1033 * For our use-case, we could perhaps have a variante of || which "catches" errors. One proposal
1034 * is to use a %catch(...) function, but that seems ugly. Pretty much everything would need to
1035 * be wrapped in %catch().
1036 *
1037 * Another option is to extend the || operator. e.g. %{foo(nope) ||? bar}. But that seems ugly,
1038 * too.
1039 *
1040 * Another option is to change the behavior so that failed xlats just result in empty
1041 * value-boxes. However, it then becomes difficult to distinguish the situations for
1042 * %sql("SELECT...") where the SELECT returns nothing, versus the SQL connection is down.
1043 */
1044 if (rctx->result.rcode != RLM_MODULE_OK) {
1045 fr_strerror_printf("Expansion failed with code %s",
1046 fr_table_str_by_value(rcode_table, rctx->result.rcode, "<INVALID>"));
1047 return XLAT_ACTION_FAIL;
1048 }
1049#endif
1050
1051 fr_value_box_list_move((fr_value_box_list_t *)out->dlist, &rctx->list);
1052
1053 return XLAT_ACTION_DONE;
1054}
1055
1056
1057/** Signal an xlat function
1058 *
1059 * @param[in] signal function to call.
1060 * @param[in] exp Xlat node that previously yielded.
1061 * @param[in] request The current request.
1062 * @param[in] rctx Opaque (to us), resume ctx provided by the xlat function
1063 * when it yielded.
1064 * @param[in] action What the request should do (the type of signal).
1065 */
1067 request_t *request, void *rctx, fr_signal_t action)
1068{
1070
1071 signal(XLAT_CTX(exp->call.inst, t->data, exp, t->mctx, NULL, rctx), request, action);
1072}
1073
1075 UNUSED xlat_ctx_t const *xctx,
1076 UNUSED request_t *request, UNUSED fr_value_box_list_t *in)
1077{
1078 return XLAT_ACTION_DONE;
1079}
1080
1081/** Call an xlat's resumption method
1082 *
1083 * @param[in] ctx to allocate value boxes in.
1084 * @param[out] out a list of #fr_value_box_t to append to.
1085 * @param[out] child to evaluate. If a child needs to be evaluated
1086 * by the caller, we return XLAT_ACTION_PUSH_CHILD
1087 * and place the child to be evaluated here.
1088 * Once evaluation is complete, the caller
1089 * should call us with the same #xlat_exp_t and the
1090 * result of the nested evaluation in result.
1091 * @param[in] request the current request.
1092 * @param[in] head of the list to evaluate
1093 * @param[in,out] in xlat node to evaluate. Advanced as we process
1094 * additional #xlat_exp_t.
1095 * @param[in] result Previously expanded arguments to this xlat function.
1096 * @param[in] resume function to call.
1097 * @param[in] rctx Opaque (to us), resume ctx provided by xlat function
1098 * when it yielded.
1099 */
1101 xlat_exp_head_t const **child,
1102 request_t *request, xlat_exp_head_t const *head, xlat_exp_t const **in,
1103 fr_value_box_list_t *result, xlat_func_t resume, void *rctx)
1104{
1105 xlat_action_t xa;
1106 xlat_exp_t const *node = *in;
1107
1108 /*
1109 * It's important that callbacks leave the result list
1110 * in a valid state, as it leads to all kinds of hard
1111 * to debug problems if they free or change elements
1112 * and don't remove them from the list.
1113 */
1114 VALUE_BOX_LIST_VERIFY(result);
1115
1116 if (node->type != XLAT_FUNC) {
1117 xa = resume(ctx, out, XLAT_CTX(NULL, NULL, NULL, NULL, NULL, rctx), request, result);
1118 } else {
1120 t = xlat_thread_instance_find(node);
1121 xa = resume(ctx, out, XLAT_CTX(node->call.inst->data, t->data, node, t->mctx, NULL, rctx), request, result);
1122 VALUE_BOX_LIST_VERIFY(result);
1123
1124 RDEBUG2("| %%%s(...)", node->call.func->name);
1125 }
1126
1127 switch (xa) {
1128 case XLAT_ACTION_YIELD:
1129 RDEBUG2("| (YIELD)");
1130 return xa;
1131
1132 case XLAT_ACTION_DONE:
1133 if (unlang_xlat_yield(request, xlat_null_resume, NULL, 0, NULL) != XLAT_ACTION_YIELD) return XLAT_ACTION_FAIL;
1134
1135 fr_dcursor_next(out); /* Wind to the start of this functions output */
1136 if ((node->type == XLAT_FUNC) && (node->call.func)) {
1137 RDEBUG2("| --> %pR", fr_dcursor_current(out));
1138 if (!xlat_process_return(request, node->call.func, (fr_value_box_list_t *)out->dlist,
1140 }
1141
1142 /*
1143 * It's easier if we get xlat_frame_eval to continue evaluating the frame.
1144 */
1145 *in = xlat_exp_next(head, *in); /* advance */
1146 return xlat_frame_eval(ctx, out, child, request, head, in);
1147
1150 case XLAT_ACTION_FAIL:
1151 break;
1152 }
1153
1154 return xa;
1155}
1156
1157/** Process the result of a previous nested expansion
1158 *
1159 * @param[in] ctx to allocate value boxes in.
1160 * @param[out] out a list of #fr_value_box_t to append to.
1161 * @param[out] child to evaluate. If a child needs to be evaluated
1162 * by the caller, we return XLAT_ACTION_PUSH_CHILD
1163 * and place the child to be evaluated here.
1164 * Once evaluation is complete, the caller
1165 * should call us with the same #xlat_exp_t and the
1166 * result of the nested evaluation in result.
1167 * @param[in] request the current request.
1168 * @param[in] head of the list to evaluate
1169 * @param[in,out] in xlat node to evaluate. Advanced as we process
1170 * additional #xlat_exp_t.
1171 * @param[in] env_data Expanded call env.
1172 * @param[in] result of a previous nested evaluation.
1173 */
1175 xlat_exp_head_t const **child,
1176 request_t *request, xlat_exp_head_t const *head, xlat_exp_t const **in,
1177 void *env_data, fr_value_box_list_t *result)
1178{
1179 xlat_exp_t const *node = *in;
1180
1181 fr_dcursor_tail(out); /* Needed for reentrant behaviour and debugging */
1182
1183 switch (node->type) {
1184 case XLAT_FUNC:
1185 {
1186 xlat_action_t xa;
1188
1189 t = xlat_thread_instance_find(node);
1190 fr_assert(t);
1191
1192 XLAT_DEBUG("** [%i] %s(func-async) - %%%s(%pM)",
1193 unlang_interpret_stack_depth(request), __FUNCTION__,
1194 node->fmt, result);
1195
1196 VALUE_BOX_LIST_VERIFY(result);
1197
1198 if (RDEBUG_ENABLED2) {
1199 REXDENT();
1200 xlat_debug_log_expansion(request, *in, result, __LINE__);
1201 RINDENT();
1202 }
1203
1204 xa = xlat_process_args(ctx, result, request, node);
1205 if (xa == XLAT_ACTION_FAIL) {
1206 return xa;
1207 }
1208
1209 VALUE_BOX_LIST_VERIFY(result);
1210 xa = node->call.func->func(ctx, out,
1211 XLAT_CTX(node->call.inst->data, t->data, node, t->mctx, env_data, NULL),
1212 request, result);
1213 VALUE_BOX_LIST_VERIFY(result);
1214
1215 switch (xa) {
1216 case XLAT_ACTION_FAIL:
1217 fr_value_box_list_talloc_free_head(result);
1218 return xa;
1219
1221 RDEBUG3("| -- CHILD");
1222 return xa;
1223
1225 RDEBUG3("| -- UNLANG");
1226 return xa;
1227
1228 case XLAT_ACTION_YIELD:
1229 RDEBUG3("| -- YIELD");
1230 return xa;
1231
1232 case XLAT_ACTION_DONE: /* Process the result */
1233 fr_value_box_list_talloc_free_head(result);
1235
1236 REXDENT();
1238 if (!xlat_process_return(request, node->call.func,
1239 (fr_value_box_list_t *)out->dlist,
1241 RINDENT();
1242 return XLAT_ACTION_FAIL;
1243 }
1244 RINDENT();
1245 break;
1246 }
1247 }
1248 break;
1249
1250 case XLAT_GROUP:
1251 {
1252 fr_value_box_t *arg;
1253
1254 /*
1255 * We'd like to do indent / exdent for groups, but that also involves fixing all of the
1256 * error paths. Which we won't do right now.
1257 */
1258 XLAT_DEBUG("** [%i] %s(child) - continuing %%{%s ...}", unlang_interpret_stack_depth(request), __FUNCTION__,
1259 node->fmt);
1260
1261 /*
1262 * Hoist %{...} to its results.
1263 *
1264 * There may be zero or more results.
1265 */
1266 if (node->hoist) {
1267 /*
1268 * Mash quoted strings, UNLESS they're in a function argument. In which case the argument parser
1269 * will do escaping.
1270 *
1271 * @todo - when pushing the xlat for expansion, also push the escaping rules. In which case we can do escaping here.
1272 */
1273 if ((node->quote != T_BARE_WORD) && !head->is_argv) {
1274 if (!fr_value_box_list_head(result)) {
1275 MEM(arg = fr_value_box_alloc(ctx, FR_TYPE_STRING, NULL));
1276 fr_value_box_strdup(arg, arg, NULL, "", false);
1277 fr_dcursor_insert(out, arg);
1278 break;
1279 }
1280
1281 /*
1282 * Mash all of the child value-box to a string.
1283 */
1284 arg = fr_value_box_list_head(result);
1285 fr_assert(arg != NULL);
1286
1287 if (fr_value_box_list_concat_in_place(arg, arg, result, FR_TYPE_STRING, FR_VALUE_BOX_LIST_FREE, true, SIZE_MAX) < 0) {
1288 return XLAT_ACTION_FAIL;
1289 }
1290 }
1291
1292 while ((arg = fr_value_box_list_pop_head(result)) != NULL) {
1293 talloc_steal(ctx, arg);
1294 fr_dcursor_insert(out, arg);
1295 }
1296 break;
1297 }
1298
1299 MEM(arg = fr_value_box_alloc(ctx, FR_TYPE_GROUP, NULL));
1300
1301 if (!fr_value_box_list_empty(result)) {
1302 VALUE_BOX_LIST_VERIFY(result);
1303 fr_value_box_list_move(&arg->vb_group, result);
1304 }
1305
1306 VALUE_BOX_VERIFY(arg);
1307
1308 fr_dcursor_insert(out, arg);
1309 }
1310 break;
1311
1312 case XLAT_TMPL:
1313 fr_assert(tmpl_is_exec(node->vpt));
1314
1315 if (tmpl_eval_cast_in_place(result, request, node->vpt) < 0) {
1316 fr_value_box_list_talloc_free(result);
1317 return XLAT_ACTION_FAIL;
1318 }
1319
1320 /*
1321 * First entry is the command to run. Subsequent entries are the options to pass to the
1322 * command.
1323 */
1324 fr_value_box_list_move((fr_value_box_list_t *)out->dlist, result);
1325 break;
1326
1327 default:
1328 fr_assert(0);
1329 return XLAT_ACTION_FAIL;
1330 }
1331
1332 /*
1333 * It's easier if we get xlat_frame_eval to continue evaluating the frame.
1334 */
1335 *in = xlat_exp_next(head, *in); /* advance */
1336 return xlat_frame_eval(ctx, out, child, request, head, in);
1337}
1338
1339/** Converts xlat nodes to value boxes
1340 *
1341 * Evaluates a single level of expansions.
1342 *
1343 * @param[in] ctx to allocate value boxes in.
1344 * @param[out] out a list of #fr_value_box_t to append to.
1345 * @param[out] child to evaluate. If a child needs to be evaluated
1346 * by the caller, we return XLAT_ACTION_PUSH_CHILD
1347 * and place the child to be evaluated here.
1348 * Once evaluation is complete, the caller
1349 * should call us with the same #xlat_exp_t and the
1350 * result of the nested evaluation in result.
1351 * @param[in] request the current request.
1352 * @param[in] head of the list to evaluate
1353 * @param[in,out] in xlat node to evaluate. Advanced as we process
1354 * additional #xlat_exp_t.
1355 * @return
1356 * - XLAT_ACTION_PUSH_CHILD if we need to evaluate a deeper level of nested.
1357 * child will be filled with the node that needs to be evaluated.
1358 * call #xlat_frame_eval_repeat on this node, once there are results
1359 * from the nested expansion.
1360 * - XLAT_ACTION_YIELD a resumption frame was pushed onto the stack by an
1361 * xlat function and we need to wait for the request to be resumed
1362 * before continuing.
1363 * - XLAT_ACTION_DONE we're done, pop the frame.
1364 * - XLAT_ACTION_FAIL an xlat module failed.
1365 */
1367 request_t *request, xlat_exp_head_t const *head, xlat_exp_t const **in)
1368{
1370 xlat_exp_t const *node;
1371 fr_value_box_list_t result; /* tmp list so debug works correctly */
1373
1374 fr_value_box_list_init(&result);
1375
1376 *child = NULL;
1377
1378 if (!*in) return XLAT_ACTION_DONE;
1379
1380 /*
1381 * An attribute reference which is a cursor just gets a
1382 * value-box of cursor returned. That is filled in
1383 * later.
1384 */
1385 if (unlikely(head && head->cursor)) {
1386 int err;
1387
1388 fr_assert((*in)->type == XLAT_TMPL);
1389
1391
1392 (void) tmpl_dcursor_value_box_init(&err, value, value, request, (*in)->vpt);
1393 if (err < -1) return XLAT_ACTION_FAIL;
1394
1396 goto finish;
1397 }
1398
1399 /*
1400 * An attribute reference which produces a box of type FR_TYPE_ATTR
1401 */
1402 if (unlikely(head && head->is_attr)) {
1403 fr_assert((*in)->type == XLAT_TMPL);
1404
1407
1409 goto finish;
1410 }
1411
1412 XLAT_DEBUG("** [%i] %s >> entered", unlang_interpret_stack_depth(request), __FUNCTION__);
1413
1414 for (node = *in; node; node = xlat_exp_next(head, node)) {
1415 *in = node; /* Update node in our caller */
1416 fr_dcursor_tail(out); /* Needed for debugging */
1417 VALUE_BOX_LIST_VERIFY((fr_value_box_list_t *)out->dlist);
1418
1419 fr_assert(fr_value_box_list_num_elements(&result) == 0); /* Should all have been moved */
1420
1421 switch (node->type) {
1422 case XLAT_BOX:
1423 XLAT_DEBUG("** [%i] %s(value_box) - %s", unlang_interpret_stack_depth(request), __FUNCTION__, node->fmt);
1424
1425 /*
1426 * Empty boxes are only allowed if
1427 * they're the only node in the expansion.
1428 *
1429 * If they're found anywhere else the xlat
1430 * parser has an error.
1431 */
1432 fr_assert(((node == *in) && !xlat_exp_next(head, node)) || (talloc_array_length(node->fmt) > 1));
1433
1434 /*
1435 * We unfortunately need to dup the buffer
1436 * because references aren't threadsafe.
1437 */
1439 if (unlikely(fr_value_box_copy(value, value, &node->data) < 0)) goto fail;
1441 continue;
1442
1443 case XLAT_ONE_LETTER:
1444 XLAT_DEBUG("** [%i] %s(one-letter) - %%%s", unlang_interpret_stack_depth(request), __FUNCTION__,
1445 node->fmt);
1446
1447 xlat_debug_log_expansion(request, node, NULL, __LINE__);
1448 if (xlat_eval_one_letter(ctx, &result, request, node->fmt[0]) == XLAT_ACTION_FAIL) {
1449 fail:
1450 fr_value_box_list_talloc_free(&result);
1451 xa = XLAT_ACTION_FAIL;
1452 goto finish;
1453 }
1454 xlat_debug_log_list_result(request, *in, &result);
1455 fr_value_box_list_move((fr_value_box_list_t *)out->dlist, &result);
1456 continue;
1457
1458 case XLAT_TMPL:
1459 /*
1460 * Everything should have been resolved.
1461 */
1462 fr_assert(!tmpl_needs_resolving(node->vpt));
1463
1464 if (tmpl_is_data(node->vpt)) {
1465 XLAT_DEBUG("** [%i] %s(value) - %s", unlang_interpret_stack_depth(request), __FUNCTION__,
1466 node->vpt->name);
1467
1468 MEM(value = fr_value_box_alloc(ctx, tmpl_value_type(node->vpt), NULL));
1469
1470 if (unlikely(fr_value_box_copy(value, value, tmpl_value(node->vpt)) < 0)) {
1472 goto fail;
1473 }; /* Also dups taint */
1474 fr_value_box_list_insert_tail(&result, value);
1475
1476 /*
1477 * Cast the results if necessary.
1478 */
1479 if (tmpl_eval_cast_in_place(&result, request, node->vpt) < 0) goto fail;
1480
1481 fr_value_box_list_move((fr_value_box_list_t *)out->dlist, &result);
1482 continue;
1483
1484 } else if (tmpl_is_attr(node->vpt)) {
1485 if (node->fmt[0] == '&') {
1486 XLAT_DEBUG("** [%i] %s(attribute) - %s", unlang_interpret_stack_depth(request), __FUNCTION__,
1487 node->fmt);
1488 } else {
1489 XLAT_DEBUG("** [%i] %s(attribute) - %%{%s}", unlang_interpret_stack_depth(request), __FUNCTION__,
1490 node->fmt);
1491 }
1492 xlat_debug_log_expansion(request, node, NULL, __LINE__);
1493
1494 if (tmpl_eval_pair(ctx, &result, request, node->vpt) < 0) goto fail;
1495
1496 } else if (tmpl_is_exec(node->vpt) || tmpl_is_xlat(node->vpt)) {
1497 xlat_exec_rctx_t *rctx;
1498
1499 /*
1500 * Allocate and initialize the output context, with value-boxes, exec status, etc.
1501 */
1502 MEM(rctx = talloc_zero(unlang_interpret_frame_talloc_ctx(request), xlat_exec_rctx_t));
1503 fr_value_box_list_init(&rctx->list);
1505
1506 xlat_debug_log_expansion(request, node, NULL, __LINE__);
1507
1508 if (unlang_xlat_yield(request, xlat_exec_resume, NULL, 0, rctx) != XLAT_ACTION_YIELD) goto fail;
1509
1510 if (unlang_tmpl_push(ctx, &rctx->result, &rctx->list, request, node->vpt,
1512 false, &rctx->status), UNLANG_SUB_FRAME) < 0) goto fail;
1513
1515 goto finish;
1516
1517 } else {
1518#ifdef NDEBUG
1519 xa = XLAT_ACTION_FAIL;
1520 goto finish;
1521#endif
1522
1523 /*
1524 * Either this should have been handled previously, or we need to write
1525 * code to deal with this case.
1526 */
1527 fr_assert(0);
1528 }
1529
1530 xlat_debug_log_list_result(request, node, &result);
1531 fr_value_box_list_move((fr_value_box_list_t *)out->dlist, &result);
1532 continue;
1533
1534 case XLAT_FUNC:
1535 XLAT_DEBUG("** [%i] %s(func) - %%%s(...)", unlang_interpret_stack_depth(request), __FUNCTION__,
1536 node->fmt);
1537
1538 /*
1539 * Hand back the child node to the caller
1540 * for evaluation.
1541 */
1542 if (xlat_exp_head(node->call.args)) {
1543 *child = node->call.args;
1545 goto finish;
1546 }
1547
1548 /*
1549 * If there's no children we can just
1550 * call the function directly.
1551 */
1552 xa = xlat_frame_eval_repeat(ctx, out, child, request, head, in, NULL, &result);
1553 if (xa != XLAT_ACTION_DONE || (!*in)) goto finish;
1554 continue;
1555
1556#ifdef HAVE_REGEX
1557 case XLAT_REGEX:
1558 XLAT_DEBUG("** [%i] %s(regex) - %%{%s}", unlang_interpret_stack_depth(request), __FUNCTION__,
1559 node->fmt);
1560
1561 xlat_debug_log_expansion(request, node, NULL, __LINE__);
1563 if (regex_request_to_sub(value, value, request, node->regex_index) < 0) {
1565 continue;
1566 }
1567
1568 xlat_debug_log_result(request, node, value);
1570 continue;
1571#endif
1572
1573 case XLAT_GROUP:
1574 XLAT_DEBUG("** [%i] %s(child) - %%{%s ...}", unlang_interpret_stack_depth(request), __FUNCTION__,
1575 node->fmt);
1576 if (!node->group) continue; /* empty group means we just keep going */
1577
1578 /*
1579 * Hand back the child node to the caller
1580 * for evaluation.
1581 */
1582 *child = node->group;
1584 goto finish;
1585
1586 /*
1587 * Should have been fixed up during pass2
1588 */
1589 case XLAT_INVALID:
1591 fr_assert(0);
1592 return XLAT_ACTION_FAIL;
1593 }
1594 }
1595
1596finish:
1597 VALUE_BOX_LIST_VERIFY((fr_value_box_list_t *)out->dlist);
1598 XLAT_DEBUG("** [%i] %s << %s", unlang_interpret_stack_depth(request),
1599 __FUNCTION__, fr_table_str_by_value(xlat_action_table, xa, "<INVALID>"));
1600
1601 return xa;
1602}
1603
1604static int xlat_sync_stringify(TALLOC_CTX *ctx, request_t *request, xlat_exp_head_t const *head, fr_value_box_list_t *list,
1605 xlat_escape_legacy_t escape, void const *escape_ctx)
1606{
1607 fr_value_box_t *vb, *box;
1608 xlat_exp_t *node;
1609 fr_value_box_safe_for_t safe_for_expected = escape ? (fr_value_box_safe_for_t) escape : FR_VALUE_BOX_SAFE_FOR_ANY;
1611
1612 vb = fr_value_box_list_head(list);
1613 if (!vb) return 0;
1614
1615 node = xlat_exp_head(head);
1616 fr_assert(node != NULL);
1617
1618 do {
1619 size_t len, real_len;
1620 char *escaped;
1621
1622 /*
1623 * Groups commonly are because of quoted strings.
1624 *
1625 * However, we sometimes have a group because of %{...}, in which case the result is just
1626 * a leaf value.
1627 */
1628 if ((node->type == XLAT_GROUP) && (vb->type == FR_TYPE_GROUP)) {
1629 fr_assert(node->quote != T_BARE_WORD);
1630
1631 if (xlat_sync_stringify(vb, request, node->group, &vb->vb_group, escape, escape_ctx) < 0) return -1;
1632
1633 /*
1634 * Replace the group wuth a fixed string.
1635 */
1636 MEM(box = fr_value_box_alloc_null(ctx));
1637
1638 if (fr_value_box_cast(box, box, FR_TYPE_STRING, NULL, vb) < 0) return -1;
1639
1640 /*
1641 * Remove the group, and replace it with the string.
1642 */
1643 fr_value_box_list_insert_before(list, vb, box);
1644 fr_value_box_list_remove(list, vb);
1645 talloc_free(vb);
1646 vb = box;
1647
1648 /*
1649 * It's now safe, so we don't need to do anything else.
1650 */
1651 fr_value_box_mark_safe_for(vb, safe_for_mark);
1652 goto next;
1653 }
1654
1655 if (!escape) goto next;
1656
1657 if (fr_value_box_is_safe_for(vb, safe_for_expected)) goto next;
1658
1659 /*
1660 * We cast EVERYTHING to a string and also escape everything.
1661 */
1662 if (fr_value_box_cast_in_place(vb, vb, FR_TYPE_STRING, NULL) < 0) {
1663 return -1;
1664 }
1665
1666 len = vb->vb_length * 3;
1667 MEM(escaped = talloc_array(vb, char, len + 1));
1668 real_len = escape(request, escaped, len, vb->vb_strvalue, UNCONST(void *, escape_ctx));
1669
1670 fr_value_box_strdup_shallow_replace(vb, escaped, real_len);
1671 fr_value_box_mark_safe_for(vb, safe_for_mark);
1672
1673 next:
1674 vb = fr_value_box_list_next(list, vb);
1675 node = xlat_exp_next(head, node);
1676
1677 } while (node && vb);
1678
1679 return 0;
1680}
1681
1682static ssize_t xlat_eval_sync(TALLOC_CTX *ctx, char **out, request_t *request, xlat_exp_head_t const * const head,
1683 xlat_escape_legacy_t escape, void const *escape_ctx)
1684{
1685 fr_value_box_list_t result;
1686 unlang_result_t unlang_result = UNLANG_RESULT_NOT_SET;
1687 TALLOC_CTX *pool = talloc_new(NULL);
1688 rlm_rcode_t rcode;
1689 char *str;
1690
1691 XLAT_DEBUG("xlat_eval_sync");
1692
1693 *out = NULL;
1694
1695 fr_value_box_list_init(&result);
1696
1697 /*
1698 * Use the unlang stack to evaluate the xlat.
1699 */
1700 if (unlang_xlat_push(pool, &unlang_result, &result, request, head, UNLANG_TOP_FRAME) < 0) {
1701 fail:
1702 talloc_free(pool);
1703 return -1;
1704 }
1705
1706 /*
1707 * Pure functions don't yield, and can therefore be
1708 * expanded in place. This check saves an expensive
1709 * bounce through a new synchronous interpreter.
1710 */
1711 if (!xlat_impure_func(head) && unlang_interpret_get(request)) {
1712 rcode = unlang_interpret(request, UNLANG_REQUEST_RUNNING);
1713 } else {
1715 }
1716
1717 switch (rcode) {
1718 default:
1719 if (XLAT_RESULT_SUCCESS(&unlang_result)) {
1720 break;
1721 }
1723
1724 case RLM_MODULE_REJECT:
1725 case RLM_MODULE_FAIL:
1726 goto fail;
1727 }
1728
1729 if (!fr_value_box_list_empty(&result)) {
1730 /*
1731 * Walk over the data recursively, escaping it, and converting quoted groups to strings.
1732 */
1733 if (xlat_sync_stringify(pool, request, head, &result, escape, escape_ctx) < 0) {
1734 goto fail;
1735 }
1736
1737 str = fr_value_box_list_aprint(ctx, &result, NULL, NULL);
1738 if (!str) goto fail;
1739 } else {
1740 str = talloc_typed_strdup(ctx, "");
1741 }
1742 talloc_free(pool); /* Memory should be in new ctx */
1743
1744 *out = str;
1745
1746 return talloc_array_length(str) - 1;
1747}
1748
1749/** Replace %whatever in a string.
1750 *
1751 * See 'doc/unlang/xlat.adoc' for more information.
1752 *
1753 * @param[in] ctx to allocate expansion buffers in.
1754 * @param[out] out Where to write pointer to output buffer.
1755 * @param[in] outlen Size of out.
1756 * @param[in] request current request.
1757 * @param[in] head the xlat structure to expand
1758 * @param[in] escape function to escape final value e.g. SQL quoting.
1759 * @param[in] escape_ctx pointer to pass to escape function.
1760 * @return length of string written @bug should really have -1 for failure.
1761 */
1762static ssize_t _xlat_eval_compiled(TALLOC_CTX *ctx, char **out, size_t outlen, request_t *request,
1763 xlat_exp_head_t const *head, xlat_escape_legacy_t escape, void const *escape_ctx)
1764{
1765 char *buff;
1766 ssize_t slen;
1767
1768 fr_assert(head != NULL);
1769
1770 slen = xlat_eval_sync(ctx, &buff, request, head, escape, escape_ctx);
1771 if (slen < 0) {
1772 fr_assert(buff == NULL);
1773 if (*out) **out = '\0';
1774 return slen;
1775 }
1776
1777 /*
1778 * If out doesn't point to an existing buffer
1779 * copy the pointer to our buffer over.
1780 */
1781 if (!*out) {
1782 *out = buff;
1783 return slen;
1784 }
1785
1786 if ((size_t)slen >= outlen) {
1787 fr_strerror_const("Insufficient output buffer space");
1788 return -1;
1789 }
1790
1791 /*
1792 * Otherwise copy the talloced buffer to the fixed one.
1793 */
1794 memcpy(*out, buff, slen);
1795 (*out)[slen] = '\0';
1797
1798 return slen;
1799}
1800
1801/** Replace %whatever in a string.
1802 *
1803 * See 'doc/unlang/xlat.adoc' for more information.
1804 *
1805 * @param[in] ctx to allocate expansion buffers in.
1806 * @param[out] out Where to write pointer to output buffer.
1807 * @param[in] outlen Size of out.
1808 * @param[in] request current request.
1809 * @param[in] fmt string to expand.
1810 * @param[in] escape function to escape final value e.g. SQL quoting.
1811 * @param[in] escape_ctx pointer to pass to escape function.
1812 * @return length of string written @bug should really have -1 for failure.
1813 */
1814static CC_HINT(nonnull (2, 4, 5))
1815ssize_t _xlat_eval(TALLOC_CTX *ctx, char **out, size_t outlen, request_t *request, char const *fmt,
1816 xlat_escape_legacy_t escape, void const *escape_ctx)
1817{
1818 ssize_t len;
1820
1821 RINDENT();
1822
1823 /*
1824 * Give better errors than the old code.
1825 */
1826 len = xlat_tokenize(ctx, &head,
1828 NULL,
1829 &(tmpl_rules_t){
1830 .attr = {
1831 .dict_def = request->local_dict,
1832 .list_def = request_attr_request,
1833 },
1834 .xlat = {
1835 .runtime_el = unlang_interpret_event_list(request),
1836 },
1837 .at_runtime = true,
1838 });
1839 if (len == 0) {
1840 if (*out) {
1841 **out = '\0';
1842 } else {
1843 *out = talloc_zero_array(ctx, char, 1);
1844 }
1845 REXDENT();
1846 return 0;
1847 }
1848
1849 if (len < 0) {
1850 REMARKER(fmt, -(len), "%s", fr_strerror());
1851 if (*out) **out = '\0';
1852 REXDENT();
1853 return -1;
1854 }
1855
1856 len = _xlat_eval_compiled(ctx, out, outlen, request, head, escape, escape_ctx);
1858
1859 REXDENT();
1860
1861 return len;
1862}
1863
1864ssize_t xlat_eval(char *out, size_t outlen, request_t *request,
1865 char const *fmt, xlat_escape_legacy_t escape, void const *escape_ctx)
1866{
1868
1869 return _xlat_eval(request, &out, outlen, request, fmt, escape, escape_ctx);
1870}
1871
1872ssize_t xlat_eval_compiled(char *out, size_t outlen, request_t *request,
1873 xlat_exp_head_t const *xlat, xlat_escape_legacy_t escape, void const *escape_ctx)
1874{
1876
1877 return _xlat_eval_compiled(request, &out, outlen, request, xlat, escape, escape_ctx);
1878}
1879
1880ssize_t xlat_aeval(TALLOC_CTX *ctx, char **out, request_t *request, char const *fmt,
1881 xlat_escape_legacy_t escape, void const *escape_ctx)
1882{
1884
1885 *out = NULL;
1886 return _xlat_eval(ctx, out, 0, request, fmt, escape, escape_ctx);
1887}
1888
1889ssize_t xlat_aeval_compiled(TALLOC_CTX *ctx, char **out, request_t *request,
1890 xlat_exp_head_t const *xlat, xlat_escape_legacy_t escape, void const *escape_ctx)
1891{
1893
1894 *out = NULL;
1895 return _xlat_eval_compiled(ctx, out, 0, request, xlat, escape, escape_ctx);
1896}
1897
1898
1899/** Turn am xlat list into an argv[] array, and nuke the input list.
1900 *
1901 * This is mostly for async use.
1902 */
1904{
1905 int i;
1906 xlat_exp_head_t **my_argv;
1907 size_t count;
1908
1909 if (head->flags.needs_resolving) {
1910 fr_strerror_printf("Cannot flatten expression with unresolved functions");
1911 return -1;
1912 }
1913
1914 count = 0;
1915 xlat_exp_foreach(head, node) {
1916 count++;
1917 }
1918
1919 MEM(my_argv = talloc_zero_array(ctx, xlat_exp_head_t *, count + 1));
1920 *argv = my_argv;
1921
1923
1924 i = 0;
1925 xlat_exp_foreach(head, node) {
1926 fr_assert(node->type == XLAT_GROUP);
1927 my_argv[i++] = talloc_steal(my_argv, node->group);
1928 }
1929
1930 fr_value_box_list_talloc_free((fr_value_box_list_t *)&head->dlist);
1931
1932 return count;
1933}
1934
1935/** Walk over all xlat nodes (depth first) in a xlat expansion, calling a callback
1936 *
1937 * @param[in] head to evaluate.
1938 * @param[in] walker callback to pass nodes to.
1939 * @param[in] type if > 0 a mask of types to call walker for.
1940 * @param[in] uctx to pass to walker.
1941 * @return
1942 * - 0 on success (walker always returned 0).
1943 * - <0 if walker returned <0.
1944 */
1946{
1947 int ret;
1948
1949 /*
1950 * Iterate over nodes at the same depth
1951 */
1952 xlat_exp_foreach(head, node) {
1953 switch (node->type){
1954 case XLAT_FUNC:
1955 /*
1956 * Evaluate the function's arguments
1957 * first, as they may get moved around
1958 * when the function is instantiated.
1959 */
1960 if (xlat_exp_head(node->call.args)) {
1961 ret = xlat_eval_walk(node->call.args, walker, type, uctx);
1962 if (ret < 0) return ret;
1963 }
1964
1965 if (!type || (type & XLAT_FUNC)) {
1966 ret = walker(node, uctx);
1967 if (ret < 0) return ret;
1968 }
1969 break;
1970
1972 if (xlat_exp_head(node->call.args)) {
1973 ret = xlat_eval_walk(node->call.args, walker, type, uctx);
1974 if (ret < 0) return ret;
1975 }
1976
1977 if (!type || (type & XLAT_FUNC_UNRESOLVED)) {
1978 ret = walker(node, uctx);
1979 if (ret < 0) return ret;
1980 }
1981 break;
1982
1983 case XLAT_GROUP:
1984 if (!type || (type & XLAT_GROUP)) {
1985 ret = walker(node, uctx);
1986 if (ret < 0) return ret;
1987 if (ret > 0) continue;
1988 }
1989
1990 /*
1991 * Evaluate the child.
1992 */
1993 ret = xlat_eval_walk(node->group, walker, type, uctx);
1994 if (ret < 0) return ret;
1995 break;
1996
1997 default:
1998 if (!type || (type & node->type)) {
1999 ret = walker(node, uctx);
2000 if (ret < 0) return ret;
2001 }
2002 break;
2003 }
2004 }
2005
2006 return 0;
2007}
2008
2010{
2012
2013 if (instance_count > 0) {
2015 return 0;
2016 }
2017
2019 PERROR("%s", __FUNCTION__);
2020 return -1;
2021 }
2022
2024 PERROR("%s", __FUNCTION__);
2026 return -1;
2027 }
2028
2030 return 0;
2031}
2032
2034{
2036
2037 if (--instance_count > 0) return;
2038
2040}
static int const char char buffer[256]
Definition acutest.h:578
va_list args
Definition acutest.h:772
static int const char * fmt
Definition acutest.h:575
int const char int line
Definition acutest.h:704
#define UNCONST(_type, _ptr)
Remove const qualification from a pointer.
Definition build.h:167
#define RCSID(id)
Definition build.h:487
#define L(_str)
Helper for initialising arrays of string literals.
Definition build.h:209
#define FALL_THROUGH
clang 10 doesn't recognised the FALL-THROUGH comment anymore
Definition build.h:324
#define unlikely(_x)
Definition build.h:383
#define UNUSED
Definition build.h:317
#define NUM_ELEMENTS(_t)
Definition build.h:339
static void * fr_dcursor_next(fr_dcursor_t *cursor)
Advanced the cursor to the next item.
Definition dcursor.h:290
static int fr_dcursor_append(fr_dcursor_t *cursor, void *v)
Insert a single item at the end of the list.
Definition dcursor.h:408
static void * fr_dcursor_tail(fr_dcursor_t *cursor)
Wind cursor to the tail item in the list.
Definition dcursor.h:260
static int fr_dcursor_insert(fr_dcursor_t *cursor, void *v)
Insert directly after the current item.
Definition dcursor.h:437
static void * fr_dcursor_current(fr_dcursor_t *cursor)
Return the item the cursor current points to.
Definition dcursor.h:339
#define fr_cond_assert(_x)
Calls panic_action ifndef NDEBUG, else logs error and evaluates to value of _x.
Definition debug.h:131
#define fr_assert_fail(_msg,...)
Calls panic_action ifndef NDEBUG, else logs error.
Definition debug.h:208
#define MEM(x)
Definition debug.h:36
#define fr_dict_autofree(_to_free)
Definition dict.h:917
static fr_slen_t err
Definition dict.h:884
fr_dict_attr_t const ** out
Where to write a pointer to the resolved fr_dict_attr_t.
Definition dict.h:294
fr_dict_t const ** out
Where to write a pointer to the loaded/resolved fr_dict_t.
Definition dict.h:307
int fr_dict_attr_autoload(fr_dict_attr_autoload_t const *to_load)
Process a dict_attr_autoload element to load/verify a dictionary attribute.
Definition dict_util.c:4402
#define fr_dict_autoload(_to_load)
Definition dict.h:914
#define DICT_AUTOLOAD_TERMINATOR
Definition dict.h:313
static fr_slen_t in
Definition dict.h:884
Specifies an attribute which must be present for the module to function.
Definition dict.h:293
Specifies a dictionary which must be loaded/loadable for the module to function.
Definition dict.h:306
Test enumeration values.
Definition dict_test.h:92
static unsigned int fr_dlist_num_elements(fr_dlist_head_t const *head)
Return the number of elements in the dlist.
Definition dlist.h:921
#define EXEC_TIMEOUT
Default wait time for exec calls (in seconds).
Definition exec.h:32
talloc_free(hp)
rlm_rcode_t unlang_interpret(request_t *request, bool running)
Run the interpreter for a current request.
Definition interpret.c:939
unlang_interpret_t * unlang_interpret_get(request_t *request)
Get the interpreter set for a request.
Definition interpret.c:2031
int unlang_interpret_stack_depth(request_t *request)
Return the depth of the request's stack.
Definition interpret.c:1541
TALLOC_CTX * unlang_interpret_frame_talloc_ctx(request_t *request)
Get a talloc_ctx which is valid only for this frame.
Definition interpret.c:1673
fr_event_list_t * unlang_interpret_event_list(request_t *request)
Get the event list for the current interpreter.
Definition interpret.c:2041
#define UNLANG_RESULT_NOT_SET
Definition interpret.h:139
#define UNLANG_SUB_FRAME
Definition interpret.h:37
rlm_rcode_t rcode
The current rcode, from executing the instruction or merging the result from a frame.
Definition interpret.h:134
#define UNLANG_TOP_FRAME
Definition interpret.h:36
#define UNLANG_REQUEST_RUNNING
Definition interpret.h:42
rlm_rcode_t unlang_interpret_synchronous(fr_event_list_t *el, request_t *request)
Execute an unlang section synchronously.
#define UNLANG_RESULT_RCODE(_x)
Definition interpret.h:140
#define PERROR(_fmt,...)
Definition log.h:228
#define REXDENT()
Exdent (unindent) R* messages by one level.
Definition log.h:455
#define RDEBUG3(fmt,...)
Definition log.h:355
#define RERROR(fmt,...)
Definition log.h:310
#define REMARKER(_str, _marker_idx, _marker,...)
Output string with error marker, showing where format error occurred.
Definition log.h:510
#define RPEDEBUG(fmt,...)
Definition log.h:388
#define RINDENT()
Indent R* messages by one level.
Definition log.h:442
FILE * fr_log_fp
Definition log.c:39
size_t(* xlat_escape_legacy_t)(request_t *request, char *out, size_t outlen, char const *in, void *arg)
fr_type_t
@ FR_TYPE_TIME_DELTA
A period of time measured in nanoseconds.
@ FR_TYPE_STRING
String of printable characters.
@ FR_TYPE_NULL
Invalid (uninitialised) attribute type.
@ FR_TYPE_UINT16
16 Bit unsigned integer.
@ FR_TYPE_UINT8
8 Bit unsigned integer.
@ FR_TYPE_UINT32
32 Bit unsigned integer.
@ FR_TYPE_UINT64
64 Bit unsigned integer.
@ FR_TYPE_VOID
User data.
@ FR_TYPE_BOOL
A truth value.
@ FR_TYPE_GROUP
A grouping of other attributes.
long int ssize_t
unsigned char bool
ssize_t fr_slen_t
struct tm * gmtime_r(time_t const *l_clock, struct tm *result)
Definition missing.c:201
struct tm * localtime_r(time_t const *l_clock, struct tm *result)
Definition missing.c:163
#define fr_assert(_expr)
Definition rad_assert.h:38
#define REDEBUG(fmt,...)
Definition radclient.h:52
#define RDEBUG_ENABLED2()
Definition radclient.h:50
#define RDEBUG2(fmt,...)
Definition radclient.h:54
fr_table_num_sorted_t const rcode_table[]
Definition rcode.c:35
rlm_rcode_t
Return codes indicating the result of the module call.
Definition rcode.h:44
@ RLM_MODULE_OK
The module is OK, continue.
Definition rcode.h:49
@ RLM_MODULE_FAIL
Module failed, don't reply.
Definition rcode.h:48
@ RLM_MODULE_REJECT
Immediately reject the request.
Definition rcode.h:47
fr_dict_attr_t const * request_attr_request
Definition request.c:43
static char const * name
ssize_t fr_sbuff_in_strcpy(fr_sbuff_t *sbuff, char const *str)
Copy bytes into the sbuff up to the first \0.
Definition sbuff.c:1459
ssize_t fr_sbuff_in_sprintf(fr_sbuff_t *sbuff, char const *fmt,...)
Print using a fmt string to an sbuff.
Definition sbuff.c:1592
#define fr_sbuff_start(_sbuff_or_marker)
#define FR_SBUFF_IN_CHAR_RETURN(_sbuff,...)
#define fr_sbuff_set(_dst, _src)
#define FR_SBUFF_IN_SPRINTF_RETURN(...)
#define FR_SBUFF_IN_STR(_start)
#define FR_SBUFF(_sbuff_or_marker)
#define fr_sbuff_used(_sbuff_or_marker)
#define FR_SBUFF_TALLOC_THREAD_LOCAL(_out, _init, _max)
#define tmpl_is_xlat(vpt)
Definition tmpl.h:210
#define tmpl_value(_tmpl)
Definition tmpl.h:937
#define tmpl_is_attr(vpt)
Definition tmpl.h:208
#define tmpl_is_exec(vpt)
Definition tmpl.h:211
ssize_t tmpl_afrom_attr_str(TALLOC_CTX *ctx, tmpl_attr_error_t *err, tmpl_t **out, char const *name, tmpl_rules_t const *rules))
Parse a string into a TMPL_TYPE_ATTR_* type tmpl_t.
int tmpl_eval_cast_in_place(fr_value_box_list_t *out, request_t *request, tmpl_t const *vpt)
Casts a value or list of values according to the tmpl.
Definition tmpl_eval.c:1231
int tmpl_eval_pair(TALLOC_CTX *ctx, fr_value_box_list_t *out, request_t *request, tmpl_t const *vpt)
Gets the value of a real or virtual attribute.
Definition tmpl_eval.c:953
#define tmpl_is_data(vpt)
Definition tmpl.h:206
static fr_slen_t vpt
Definition tmpl.h:1269
#define tmpl_value_type(_tmpl)
Definition tmpl.h:939
static fr_dict_attr_t const * tmpl_attr_tail_da(tmpl_t const *vpt)
Return the last attribute reference da.
Definition tmpl.h:801
#define tmpl_needs_resolving(vpt)
Definition tmpl.h:223
Optional arguments passed to vp_tmpl functions.
Definition tmpl.h:336
fr_signal_t
Signals that can be generated/processed by request signal handlers.
Definition signal.h:38
static char buff[sizeof("18446744073709551615")+3]
Definition size_tests.c:41
PUBLIC int snprintf(char *string, size_t length, char *format, va_alist)
Definition snprintf.c:689
return count
Definition module.c:155
fr_aka_sim_id_type_t type
#define fr_time()
Allow us to arbitrarily manipulate time.
Definition state_test.c:8
char const * fr_syserror(int num)
Guaranteed to be thread-safe version of strerror.
Definition syserror.c:243
#define fr_table_value_by_str(_table, _name, _def)
Convert a string to a value using a sorted or ordered table.
Definition table.h:653
#define fr_table_str_by_value(_table, _number, _def)
Convert an integer to a string.
Definition table.h:772
An element in a lexicographically sorted array of name to num mappings.
Definition table.h:49
An element in an arbitrarily ordered array of name to ptr mappings.
Definition table.h:73
char * talloc_typed_strdup(TALLOC_CTX *ctx, char const *p)
Call talloc_strdup, setting the type on the new chunk correctly.
Definition talloc.c:468
static int64_t fr_time_to_sec(fr_time_t when)
Convert an fr_time_t (internal time) to number of sec since the unix epoch (wallclock time)
Definition time.h:731
static int64_t fr_time_to_msec(fr_time_t when)
Convert an fr_time_t (internal time) to number of msec since the unix epoch (wallclock time)
Definition time.h:711
static fr_time_delta_t fr_time_delta_from_sec(int64_t sec)
Definition time.h:590
static int64_t fr_time_to_usec(fr_time_t when)
Convert an fr_time_t (internal time) to number of usec since the unix epoch (wallclock time)
Definition time.h:701
int unlang_tmpl_push(TALLOC_CTX *ctx, unlang_result_t *p_result, fr_value_box_list_t *out, request_t *request, tmpl_t const *tmpl, unlang_tmpl_args_t *args, bool top_frame)
Push a tmpl onto the stack for evaluation.
Definition tmpl.c:276
fr_pair_t * tmpl_dcursor_value_box_init(int *err, TALLOC_CTX *ctx, fr_value_box_t *vb, request_t *request, tmpl_t const *vpt)
Initialize a #tmpl_dcursor_t into a fr_value_box_t.
char const * fr_tokens[T_TOKEN_LAST]
Definition token.c:79
const bool fr_comparison_op[T_TOKEN_LAST]
Definition token.c:199
const bool fr_binary_op[T_TOKEN_LAST]
Definition token.c:217
enum fr_token fr_token_t
@ T_INVALID
Definition token.h:39
@ T_BARE_WORD
Definition token.h:120
#define TMPL_ARGS_EXEC(_env, _timeout, _stdout_on_error, _status_out)
Create a temporary argument structure for evaluating an exec type tmpl.
Definition tmpl.h:76
xlat_action_t unlang_xlat_yield(request_t *request, xlat_func_t resume, xlat_func_signal_t signal, fr_signal_t sigmask, void *rctx)
Yield a request back to the interpreter from within a module.
Definition xlat.c:544
int unlang_xlat_push(TALLOC_CTX *ctx, unlang_result_t *p_result, fr_value_box_list_t *out, request_t *request, xlat_exp_head_t const *xlat, bool top_frame)
Push a pre-compiled xlat onto the stack for evaluation.
Definition xlat.c:270
fr_type_t type
Type to cast argument to.
Definition xlat.h:155
void * data
Thread specific instance data.
Definition xlat.h:94
xlat_thread_inst_t * xlat_thread_instance_find(xlat_exp_t const *node)
Retrieve xlat/thread specific instance data.
Definition xlat_inst.c:405
bool xlat_is_literal(xlat_exp_head_t const *head)
Check to see if the expansion consists entirely of value-box elements.
void * uctx
Argument to pass to escape callback.
Definition xlat.h:159
bool xlat_impure_func(xlat_exp_head_t const *head)
xlat_escape_func_t func
Function to handle tainted values.
Definition xlat.h:156
fr_slen_t xlat_tokenize(TALLOC_CTX *ctx, xlat_exp_head_t **head, fr_sbuff_t *in, fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules)
Tokenize an xlat expansion.
unsigned int concat
Concat boxes together.
Definition xlat.h:147
@ XLAT_ARG_VARIADIC_EMPTY_KEEP
Empty argument groups are left alone, and either passed through as empty groups or null boxes.
Definition xlat.h:137
@ XLAT_ARG_VARIADIC_EMPTY_SQUASH
Empty argument groups are removed.
Definition xlat.h:136
@ XLAT_ARG_VARIADIC_DISABLED
Definition xlat.h:135
static fr_slen_t head
Definition xlat.h:420
xlat_arg_parser_variadic_t variadic
All additional boxes should be processed using this definition.
Definition xlat.h:153
#define XLAT_RESULT_SUCCESS(_p_result)
Definition xlat.h:500
void(* xlat_func_signal_t)(xlat_ctx_t const *xctx, request_t *request, fr_signal_t action)
A callback when the request gets a fr_signal_t.
Definition xlat.h:243
fr_value_box_safe_for_t safe_for
Escaped value to set for boxes processed by this escape function.
Definition xlat.h:157
xlat_action_t(* xlat_func_t)(TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_ctx_t const *xctx, request_t *request, fr_value_box_list_t *in)
xlat callback function
Definition xlat.h:232
unsigned int always_escape
Pass all arguments to escape function not just tainted ones.
Definition xlat.h:151
unsigned int required
Argument must be present, and non-empty.
Definition xlat.h:146
unsigned int single
Argument must only contain a single box.
Definition xlat.h:148
xlat_action_t
Definition xlat.h:37
@ XLAT_ACTION_FAIL
An xlat function failed.
Definition xlat.h:44
@ XLAT_ACTION_YIELD
An xlat function pushed a resume frame onto the stack.
Definition xlat.h:42
@ XLAT_ACTION_PUSH_UNLANG
An xlat function pushed an unlang frame onto the unlang stack.
Definition xlat.h:39
@ XLAT_ACTION_DONE
We're done evaluating this level of nesting.
Definition xlat.h:43
@ XLAT_ACTION_PUSH_CHILD
A deeper level of nesting needs to be evaluated.
Definition xlat.h:38
unsigned int will_escape
the function will do escaping and concatenation.
Definition xlat.h:150
unsigned int constant
xlat is just tmpl_attr_tail_data, or XLAT_BOX
Definition xlat.h:114
module_ctx_t const * mctx
A synthesised module calling ctx containing module global and thread instance data.
Definition xlat.h:96
Definition for a single argument consumend by an xlat function.
Definition xlat.h:145
Thread specific instance data for xlat expansion node.
Definition xlat.h:85
char const * fr_strerror(void)
Get the last library error.
Definition strerror.c:553
#define fr_strerror_printf(_fmt,...)
Log to thread local error buffer.
Definition strerror.h:64
#define fr_strerror_const(_msg)
Definition strerror.h:223
#define fr_type_is_void(_x)
Definition types.h:379
@ FR_TYPE_PAIR_CURSOR
cursor over a fr_pair_t
Definition types.h:91
#define fr_type_is_null(_x)
Definition types.h:348
#define fr_type_is_leaf(_x)
Definition types.h:394
static char const * fr_type_to_str(fr_type_t type)
Return a static string containing the type name.
Definition types.h:455
int fr_value_box_cast(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_type_t dst_type, fr_dict_attr_t const *dst_enumv, fr_value_box_t const *src)
Convert one type of fr_value_box_t to another.
Definition value.c:3961
char * fr_value_box_list_aprint(TALLOC_CTX *ctx, fr_value_box_list_t const *list, char const *delim, fr_sbuff_escape_rules_t const *e_rules)
Concatenate the string representations of a list of value boxes together.
Definition value.c:6881
int fr_value_box_copy(TALLOC_CTX *ctx, fr_value_box_t *dst, const fr_value_box_t *src)
Copy value data verbatim duplicating any buffers.
Definition value.c:4409
int fr_value_box_cast_in_place(TALLOC_CTX *ctx, fr_value_box_t *vb, fr_type_t dst_type, fr_dict_attr_t const *dst_enumv)
Convert one type of fr_value_box_t to another in place.
Definition value.c:4211
void fr_value_box_clear_value(fr_value_box_t *data)
Clear/free any existing value.
Definition value.c:4346
void fr_value_box_set_attr(fr_value_box_t *dst, fr_dict_attr_t const *da)
Definition value.c:5256
int fr_value_box_strdup(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_dict_attr_t const *enumv, char const *src, bool tainted)
Copy a nul terminated string to a fr_value_box_t.
Definition value.c:4634
void fr_value_box_strdup_shallow_replace(fr_value_box_t *vb, char const *src, ssize_t len)
Free the existing buffer (if talloced) associated with the valuebox, and replace it with a new one.
Definition value.c:4760
void fr_value_box_debug(FILE *fp, fr_value_box_t const *vb)
Print the value of a box as info messages.
Definition value.c:7391
int fr_value_box_list_concat_in_place(TALLOC_CTX *ctx, fr_value_box_t *out, fr_value_box_list_t *list, fr_type_t type, fr_value_box_list_action_t proc_action, bool flatten, size_t max_size)
Concatenate a list of value boxes.
Definition value.c:6612
@ FR_VALUE_BOX_LIST_FREE
Definition value.h:238
#define fr_value_box_alloc(_ctx, _type, _enumv)
Allocate a value box of a specific type.
Definition value.h:644
#define fr_value_box_mark_safe_for(_box, _safe_for)
Definition value.h:1087
#define fr_box_strvalue_buffer(_val)
Definition value.h:312
#define fr_value_box_is_safe_for(_box, _safe_for)
Definition value.h:1094
#define fr_value_box_get_cursor(_dst)
Definition value.h:1255
#define FR_VALUE_BOX_SAFE_FOR_NONE
Definition value.h:172
uintptr_t fr_value_box_safe_for_t
Escaping that's been applied to a value box.
Definition value.h:162
#define VALUE_BOX_VERIFY(_x)
Definition value.h:1364
#define VALUE_BOX_LIST_VERIFY(_x)
Definition value.h:1365
int nonnull(2, 5))
#define fr_value_box_alloc_null(_ctx)
Allocate a value box for later use with a value assignment function.
Definition value.h:655
#define fr_value_box_init(_vb, _type, _enumv, _tainted)
Initialise a fr_value_box_t.
Definition value.h:610
#define fr_value_box_list_foreach(_list_head, _iter)
Definition value.h:224
static size_t char ** out
Definition value.h:1024
#define FR_VALUE_BOX_SAFE_FOR_ANY
Definition value.h:173
void * rctx
Resume context.
Definition xlat_ctx.h:54
#define XLAT_CTX(_inst, _thread, _ex, _mctx, _env_data, _rctx)
Wrapper to create a xlat_ctx_t as a compound literal.
Definition xlat_ctx.h:95
An xlat calling ctx.
Definition xlat_ctx.h:49
ssize_t xlat_eval_compiled(char *out, size_t outlen, request_t *request, xlat_exp_head_t const *xlat, xlat_escape_legacy_t escape, void const *escape_ctx)
Definition xlat_eval.c:1872
static size_t xlat_time_precision_table_len
Definition xlat_eval.c:127
static fr_dict_attr_t const * attr_cast_time_res_week
Definition xlat_eval.c:51
unlang_result_t result
Definition xlat_eval.c:999
static fr_table_ptr_ordered_t const xlat_time_precision_table[]
Definition xlat_eval.c:89
static fr_slen_t xlat_fmt_print(fr_sbuff_t *out, xlat_exp_t const *node)
Reconstruct the original expansion string from an xlat tree.
Definition xlat_eval.c:150
static void xlat_debug_log_expansion(request_t *request, xlat_exp_t const *node, fr_value_box_list_t const *args, UNUSED int line)
Output what we're currently expanding.
Definition xlat_eval.c:223
xlat_action_t xlat_frame_eval_repeat(TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_exp_head_t const **child, request_t *request, xlat_exp_head_t const *head, xlat_exp_t const **in, void *env_data, fr_value_box_list_t *result)
Process the result of a previous nested expansion.
Definition xlat_eval.c:1174
void xlat_signal(xlat_func_signal_t signal, xlat_exp_t const *exp, request_t *request, void *rctx, fr_signal_t action)
Signal an xlat function.
Definition xlat_eval.c:1066
fr_dict_attr_t const * xlat_time_res_attr(char const *res)
Definition xlat_eval.c:129
static void xlat_debug_log_result(request_t *request, xlat_exp_t const *node, fr_value_box_t const *result)
Output the result of an expansion.
Definition xlat_eval.c:293
int xlat_eval_init(void)
Definition xlat_eval.c:2009
fr_table_num_sorted_t const xlat_action_table[]
Definition xlat_eval.c:78
xlat_action_t xlat_frame_eval_resume(TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_exp_head_t const **child, request_t *request, xlat_exp_head_t const *head, xlat_exp_t const **in, fr_value_box_list_t *result, xlat_func_t resume, void *rctx)
Call an xlat's resumption method.
Definition xlat_eval.c:1100
static fr_dict_attr_t const * attr_cast_time_res_year
Definition xlat_eval.c:53
static fr_dict_t const * dict_freeradius
Definition xlat_eval.c:37
static fr_dict_attr_t const * attr_cast_time_res_nsec
Definition xlat_eval.c:57
static xlat_action_t xlat_eval_one_letter(TALLOC_CTX *ctx, fr_value_box_list_t *out, request_t *request, char letter)
One letter expansions.
Definition xlat_eval.c:804
static fr_dict_attr_t const * attr_cast_time_res_month
Definition xlat_eval.c:52
static fr_dict_attr_t const * attr_cast_time_res_usec
Definition xlat_eval.c:56
fr_dict_attr_t const * attr_expr_bool_enum
Definition xlat_eval.c:44
static fr_dict_attr_t const * attr_cast_time_res_csec
Definition xlat_eval.c:54
size_t xlat_action_table_len
Definition xlat_eval.c:84
static ssize_t _xlat_eval(TALLOC_CTX *ctx, char **out, size_t outlen, request_t *request, char const *fmt, xlat_escape_legacy_t escape, void const *escape_ctx)
Replace whatever in a string.
Definition xlat_eval.c:1815
static xlat_action_t xlat_process_arg_list(TALLOC_CTX *ctx, fr_value_box_list_t *list, request_t *request, char const *name, xlat_arg_parser_t const *arg, xlat_exp_t const *node, unsigned int arg_num)
Process an individual xlat argument value box group.
Definition xlat_eval.c:367
static fr_dict_autoload_t xlat_eval_dict[]
Definition xlat_eval.c:39
static fr_dict_attr_t const * attr_cast_time_res_msec
Definition xlat_eval.c:55
fr_dict_attr_t const * attr_cast_base
Definition xlat_eval.c:45
fr_value_box_list_t list
Definition xlat_eval.c:998
ssize_t xlat_eval(char *out, size_t outlen, request_t *request, char const *fmt, xlat_escape_legacy_t escape, void const *escape_ctx)
Definition xlat_eval.c:1864
xlat_action_t xlat_frame_eval(TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_exp_head_t const **child, request_t *request, xlat_exp_head_t const *head, xlat_exp_t const **in)
Converts xlat nodes to value boxes.
Definition xlat_eval.c:1366
int xlat_flatten_to_argv(TALLOC_CTX *ctx, xlat_exp_head_t ***argv, xlat_exp_head_t *head)
Turn am xlat list into an argv[] array, and nuke the input list.
Definition xlat_eval.c:1903
static fr_dict_attr_autoload_t xlat_eval_dict_attr[]
Definition xlat_eval.c:59
static xlat_action_t xlat_process_args(TALLOC_CTX *ctx, fr_value_box_list_t *list, request_t *request, xlat_exp_t const *node)
Process list of boxed values provided as input to an xlat.
Definition xlat_eval.c:597
static bool xlat_process_return(request_t *request, xlat_t const *func, fr_value_box_list_t const *returned, fr_value_box_t *pos)
Validate that the return values from an xlat function match what it registered.
Definition xlat_eval.c:756
void xlat_eval_free(void)
Definition xlat_eval.c:2033
static int xlat_arg_stringify(request_t *request, xlat_arg_parser_t const *arg, xlat_exp_t const *node, fr_value_box_t *vb)
Definition xlat_eval.c:302
int xlat_eval_walk(xlat_exp_head_t *head, xlat_walker_t walker, xlat_type_t type, void *uctx)
Walk over all xlat nodes (depth first) in a xlat expansion, calling a callback.
Definition xlat_eval.c:1945
static fr_dict_attr_t const * attr_cast_time_res_sec
Definition xlat_eval.c:47
static xlat_action_t xlat_null_resume(UNUSED TALLOC_CTX *ctx, UNUSED fr_dcursor_t *out, UNUSED xlat_ctx_t const *xctx, UNUSED request_t *request, UNUSED fr_value_box_list_t *in)
Definition xlat_eval.c:1074
ssize_t xlat_aeval(TALLOC_CTX *ctx, char **out, request_t *request, char const *fmt, xlat_escape_legacy_t escape, void const *escape_ctx)
Definition xlat_eval.c:1880
static fr_dict_attr_t const * attr_cast_time_res_day
Definition xlat_eval.c:50
static ssize_t _xlat_eval_compiled(TALLOC_CTX *ctx, char **out, size_t outlen, request_t *request, xlat_exp_head_t const *head, xlat_escape_legacy_t escape, void const *escape_ctx)
Replace whatever in a string.
Definition xlat_eval.c:1762
ssize_t xlat_aeval_compiled(TALLOC_CTX *ctx, char **out, request_t *request, xlat_exp_head_t const *xlat, xlat_escape_legacy_t escape, void const *escape_ctx)
Definition xlat_eval.c:1889
static int xlat_sync_stringify(TALLOC_CTX *ctx, request_t *request, xlat_exp_head_t const *head, fr_value_box_list_t *list, xlat_escape_legacy_t escape, void const *escape_ctx)
Definition xlat_eval.c:1604
static void xlat_debug_log_list_result(request_t *request, xlat_exp_t const *node, fr_value_box_list_t const *result)
Output the list result of an expansion.
Definition xlat_eval.c:278
static fr_dict_attr_t const * attr_cast_time_res_min
Definition xlat_eval.c:48
static ssize_t xlat_eval_sync(TALLOC_CTX *ctx, char **out, request_t *request, xlat_exp_head_t const *const head, xlat_escape_legacy_t escape, void const *escape_ctx)
Definition xlat_eval.c:1682
static xlat_action_t xlat_exec_resume(UNUSED TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_ctx_t const *xctx, UNUSED request_t *request, UNUSED fr_value_box_list_t *in)
Definition xlat_eval.c:1002
static fr_dict_attr_t const * attr_cast_time_res_hour
Definition xlat_eval.c:49
static int instance_count
Definition xlat_eval.c:35
#define XLAT_DEBUG(...)
Definition xlat_expr.c:38
char const * name
Name of xlat function.
Definition xlat_priv.h:64
xlat_flags_t flags
Flags that control resolution and evaluation.
Definition xlat_priv.h:154
fr_type_t return_type
Function is guaranteed to return one or more boxes of this type.
Definition xlat_priv.h:101
static xlat_exp_t * xlat_exp_next(xlat_exp_head_t const *head, xlat_exp_t const *node)
Definition xlat_priv.h:247
xlat_func_t func
async xlat function (async unsafe).
Definition xlat_priv.h:65
int(* xlat_walker_t)(xlat_exp_t *exp, void *uctx)
Walker callback for xlat_walk()
Definition xlat_priv.h:268
fr_token_t quote
Type of quoting around XLAT_GROUP types.
Definition xlat_priv.h:152
xlat_type_t
Definition xlat_priv.h:106
@ XLAT_ONE_LETTER
Special "one-letter" expansion.
Definition xlat_priv.h:109
@ XLAT_BOX
fr_value_box_t
Definition xlat_priv.h:108
@ XLAT_TMPL
xlat attribute
Definition xlat_priv.h:112
@ XLAT_FUNC
xlat module
Definition xlat_priv.h:110
@ XLAT_GROUP
encapsulated string of xlats
Definition xlat_priv.h:116
@ XLAT_FUNC_UNRESOLVED
func needs resolution during pass2.
Definition xlat_priv.h:111
@ XLAT_INVALID
Bad expansion.
Definition xlat_priv.h:107
xlat_arg_parser_t const * args
Definition of args consumed.
Definition xlat_priv.h:94
char const *_CONST fmt
The original format string (a talloced buffer).
Definition xlat_priv.h:151
xlat_type_t _CONST type
type of this expansion.
Definition xlat_priv.h:155
fr_value_box_safe_for_t return_safe_for
Escaped value to set in output boxes.
Definition xlat_priv.h:100
#define xlat_exp_foreach(_list_head, _iter)
Iterate over the contents of a list, only one level.
Definition xlat_priv.h:223
static xlat_exp_t * xlat_exp_head(xlat_exp_head_t const *head)
Definition xlat_priv.h:210
An xlat expansion node.
Definition xlat_priv.h:148