The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
map.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: 5b298157a12515b834e38c79886f4aa298e0bfb8 $
19 *
20 * @brief map and unlang integration.
21 * @brief Unlang "map" keyword evaluation.
22 *
23 * @ingroup AVP
24 *
25 * @copyright 2018 The FreeRADIUS server project
26 * @copyright 2018 Arran Cudbard-Bell (a.cudbardb@freeradius.org)
27 */
28RCSID("$Id: 5b298157a12515b834e38c79886f4aa298e0bfb8 $")
29
30#include <freeradius-devel/server/base.h>
31#include <freeradius-devel/server/map.h>
32#include <freeradius-devel/unlang/tmpl.h>
33#include <freeradius-devel/unlang/map.h>
34
35#include "map_priv.h"
36
37typedef enum {
38 UNLANG_UPDATE_MAP_INIT = 0, //!< Start processing a map.
39 UNLANG_UPDATE_MAP_EXPANDED_LHS, //!< Expand the LHS xlat or exec (if needed).
40 UNLANG_UPDATE_MAP_EXPANDED_RHS //!< Expand the RHS xlat or exec (if needed).
42
43/** State of an update block
44 *
45 */
46typedef struct {
47 fr_dcursor_t maps; //!< Cursor of maps to evaluate.
48
49 fr_dlist_head_t vlm_head; //!< Head of list of VP List Mod.
50
51 fr_value_box_list_t lhs_result; //!< Result of expanding the LHS
52 fr_value_box_list_t rhs_result; //!< Result of expanding the RHS.
53
54 unlang_update_state_t state; //!< What we're currently doing.
56
57/** State of a map block
58 *
59 */
60typedef struct {
61 fr_value_box_list_t src_result; //!< Result of expanding the map source.
62
63 /** @name Resumption and signalling
64 * @{
65 */
66 void *rctx; //!< for resume / signal
67 map_proc_func_t resume; //!< resumption handler
68 unlang_map_signal_t signal; //!< for signal handlers
69 fr_signal_t sigmask; //!< Signals to block.
70
71 /** @} */
73
74/** Wrapper to create a map_ctx_t as a compound literal
75 *
76 * @param[in] _mod_inst of the module being called.
77 * @param[in] _map_inst of the map being called.
78 * @param[in] _rctx Resume ctx (if any).
79 */
80#define MAP_CTX(_mod_inst, _map_inst, _rctx) &(map_ctx_t){ .moi = _mod_inst, .mpi = _map_inst, .rctx = _rctx }
81
82/** Apply a list of modifications on one or more fr_pair_t lists.
83 *
84 * @param[in] request The current request.
85 * @param[out] p_result The rcode indicating what the result
86 * of the operation was.
87 * @return
88 * - UNLANG_ACTION_CALCULATE_RESULT changes were applied.
89 * - UNLANG_ACTION_PUSHED_CHILD async execution of an expansion is required.
90 */
92{
93 unlang_stack_t *stack = request->stack;
94 unlang_stack_frame_t *frame = &stack->frame[stack->depth];
95 unlang_frame_state_update_t *update_state = frame->state;
96 vp_list_mod_t const *vlm = NULL;
97
98 /*
99 * No modifications...
100 */
101 if (fr_dlist_empty(&update_state->vlm_head)) {
102 RDEBUG2("Nothing to update");
103 goto done;
104 }
105
106 /*
107 * Apply the list of modifications. This should not fail
108 * except on memory allocation error.
109 */
110 while ((vlm = fr_dlist_next(&update_state->vlm_head, vlm))) {
111 int ret;
112
113 ret = map_list_mod_apply(request, vlm);
114 if (!fr_cond_assert(ret == 0)) {
115 TALLOC_FREE(frame->state);
116
117 return UNLANG_ACTION_FAIL;
118 }
119 }
120
121done:
123}
124
125/** Create a list of modifications to apply to one or more fr_pair_t lists
126 *
127 * @param[out] p_result The rcode indicating what the result
128 * of the operation was.
129 * @param[in] request The current request.
130 * @param[in] frame Current stack frame.
131 * @return
132 * - UNLANG_ACTION_CALCULATE_RESULT changes were applied.
133 * - UNLANG_ACTION_PUSHED_CHILD async execution of an expansion is required.
134 */
136{
137 unlang_frame_state_update_t *update_state = talloc_get_type_abort(frame->state, unlang_frame_state_update_t);
138 map_t *map;
139
140 /*
141 * Iterate over the maps producing a set of modifications to apply.
142 */
143 for (map = fr_dcursor_current(&update_state->maps);
144 map;
145 map = fr_dcursor_next(&update_state->maps)) {
146 repeatable_set(frame); /* Call us again when done */
147
148 switch (update_state->state) {
151
152 fr_assert(fr_value_box_list_empty(&update_state->lhs_result)); /* Should have been consumed */
153 fr_assert(fr_value_box_list_empty(&update_state->rhs_result)); /* Should have been consumed */
154
155 switch (map->lhs->type) {
156 default:
157 break;
158
159 case TMPL_TYPE_EXEC:
160 if (unlang_tmpl_push(update_state, NULL, &update_state->lhs_result,
161 request, map->lhs,
162 NULL) < 0) {
164 }
166
167 case TMPL_TYPE_XLAT:
168 if (unlang_xlat_push(update_state, NULL, &update_state->lhs_result,
169 request, tmpl_xlat(map->lhs), false) < 0) {
171 }
173
175 case TMPL_TYPE_REGEX:
179 fr_assert(0);
180 error:
181 TALLOC_FREE(frame->state);
182 repeatable_clear(frame);
183 return UNLANG_ACTION_FAIL;
184 }
186
188 /*
189 * map_to_list_mod() already concatenates the LHS, so we don't need to do it here.
190 */
191 if (!map->rhs) goto next;
192
194
195 switch (map->rhs->type) {
196 default:
197 break;
198
199 case TMPL_TYPE_EXEC:
200 if (unlang_tmpl_push(update_state, NULL, &update_state->rhs_result,
201 request, map->rhs, NULL) < 0) {
203 }
205
206 case TMPL_TYPE_XLAT:
207 if (unlang_xlat_push(update_state, NULL, &update_state->rhs_result,
208 request, tmpl_xlat(map->rhs), false) < 0) {
210 }
212
213 case TMPL_TYPE_REGEX:
218 fr_assert(0);
219 goto error;
220 }
222
224 {
225 vp_list_mod_t *new_mod;
226 /*
227 * Concat the top level results together
228 */
229 if (!fr_value_box_list_empty(&update_state->rhs_result) &&
231 fr_value_box_list_head(&update_state->rhs_result), &update_state->rhs_result, FR_TYPE_STRING,
233 SIZE_MAX) < 0)) {
234 RPEDEBUG("Failed concatenating RHS expansion results");
235 goto error;
236 }
237
238 if (map_to_list_mod(update_state, &new_mod,
239 request, map,
240 &update_state->lhs_result, &update_state->rhs_result) < 0) goto error;
241 if (new_mod) fr_dlist_insert_tail(&update_state->vlm_head, new_mod);
242
243 fr_value_box_list_talloc_free(&update_state->rhs_result);
244 }
245
246 next:
247 update_state->state = UNLANG_UPDATE_MAP_INIT;
248 fr_value_box_list_talloc_free(&update_state->lhs_result);
249
250 break;
251 }
252 }
253
254 return list_mod_apply(p_result, request);
255}
256
257
258/** Execute an update block
259 *
260 * Update blocks execute in two phases, first there's an evaluation phase where
261 * each input map is evaluated, outputting one or more modification maps. The modification
262 * maps detail a change that should be made to a list in the current request.
263 * The request is not modified during this phase.
264 *
265 * The second phase applies those modification maps to the current request.
266 * This re-enables the atomic functionality of update blocks provided in v2.x.x.
267 * If one map fails in the evaluation phase, no more maps are processed, and the current
268 * result is discarded.
269 */
271{
274 unlang_frame_state_update_t *update_state;
275
276 /*
277 * Initialise the frame state
278 */
279 MEM(frame->state = update_state = talloc_zero_pooled_object(request->stack, unlang_frame_state_update_t,
280 (sizeof(map_t) +
281 (sizeof(tmpl_t) * 2) + 128),
282 g->num_children)); /* 128 is for string buffers */
283
284 fr_dcursor_init(&update_state->maps, &gext->map.head);
285 fr_value_box_list_init(&update_state->lhs_result);
286 fr_value_box_list_init(&update_state->rhs_result);
287 fr_dlist_init(&update_state->vlm_head, vp_list_mod_t, entry);
288
289 /*
290 * Call list_mod_create
291 */
293 return list_mod_create(p_result, request, frame);
294}
295
297#ifdef WITH_VERIFY_PTR
299#else
301#endif
302 )
303{
304 unlang_frame_state_map_proc_t *state = talloc_get_type_abort(frame->state, unlang_frame_state_map_proc_t);
305 unlang_frame_state_map_proc_t *map_proc_state = talloc_get_type_abort(frame->state, unlang_frame_state_map_proc_t);
306 map_proc_func_t resume;
307 unlang_group_t *g = unlang_generic_to_group(frame->instruction);
311
312#ifdef WITH_VERIFY_PTR
313 VALUE_BOX_LIST_VERIFY(&map_proc_state->src_result);
314#endif
315 resume = state->resume;
316 state->resume = NULL;
317
318 /*
319 * Call any map resume function
320 */
321 if (resume) ua = resume(p_result, MAP_CTX(inst->proc->mod_inst, inst->data, state->rctx),
322 request, &map_proc_state->src_result, inst->maps);
323 return ua;
324}
325
326/** Yield a request back to the interpreter from within a module
327 *
328 * This passes control of the request back to the unlang interpreter, setting
329 * callbacks to execute when the request is 'signalled' asynchronously, or whatever
330 * timer or I/O event the module was waiting for occurs.
331 *
332 * @note The module function which calls #unlang_module_yield should return control
333 * of the C stack to the unlang interpreter immediately after calling #unlang_module_yield.
334 * A common pattern is to use ``return unlang_module_yield(...)``.
335 *
336 * @param[in] request The current request.
337 * @param[in] resume Called on unlang_interpret_mark_runnable().
338 * @param[in] signal Called on unlang_action().
339 * @param[in] sigmask Set of signals to block.
340 * @param[in] rctx to pass to the callbacks.
341 * @return
342 * - UNLANG_ACTION_YIELD.
343 */
345 map_proc_func_t resume, unlang_map_signal_t signal, fr_signal_t sigmask, void *rctx)
346{
347 unlang_stack_t *stack = request->stack;
348 unlang_stack_frame_t *frame = &stack->frame[stack->depth];
349 unlang_frame_state_map_proc_t *state = talloc_get_type_abort(frame->state, unlang_frame_state_map_proc_t);
350
351 REQUEST_VERIFY(request); /* Check the yielded request is sane */
352
353 state->rctx = rctx;
354 state->resume = resume;
355 state->signal = signal;
356 state->sigmask = sigmask;
357
358 /*
359 * We set the repeatable flag here,
360 * so that the resume function is always
361 * called going back up the stack.
362 */
364
365 return UNLANG_ACTION_YIELD;
366}
367
369{
372
374 unlang_frame_state_map_proc_t *map_proc_state = talloc_get_type_abort(frame->state, unlang_frame_state_map_proc_t);
375
376 RDEBUG2("MAP %s \"%pM\"", inst->proc->name, &map_proc_state->src_result);
377
378 VALUE_BOX_LIST_VERIFY(&map_proc_state->src_result);
380
381 return inst->proc->evaluate(p_result, MAP_CTX(inst->proc->mod_inst, inst->data, NULL),
382 request, &map_proc_state->src_result, inst->maps);
383}
384
386{
390 unlang_frame_state_map_proc_t *map_proc_state = talloc_get_type_abort(frame->state, unlang_frame_state_map_proc_t);
391
392 /*
393 * Initialise the frame state
394 */
395 repeatable_set(frame);
396
397 fr_value_box_list_init(&map_proc_state->src_result);
398 /*
399 * Set this BEFORE doing anything else, as we will be
400 * called again after unlang_xlat_push() returns.
401 */
402 frame->process = map_proc_apply;
403
404 /*
405 * Expand the map source
406 */
407 if (inst->src) switch (inst->src->type) {
408 default:
409 {
410 fr_value_box_t *src_result = NULL;
411 if (tmpl_aexpand(frame->state, &src_result,
412 request, inst->src, NULL, NULL) < 0) {
413 REDEBUG("Failed expanding map src");
414 error:
416 }
417 fr_value_box_list_insert_head(&map_proc_state->src_result, src_result);
418 break;
419 }
420 case TMPL_TYPE_EXEC:
421 if (unlang_tmpl_push(map_proc_state, NULL, &map_proc_state->src_result,
422 request, inst->src, NULL) < 0) {
424 }
426
427 case TMPL_TYPE_XLAT:
428 if (unlang_xlat_push(map_proc_state, NULL, &map_proc_state->src_result,
429 request, tmpl_xlat(inst->src), false) < 0) {
431 }
433
434
435 case TMPL_TYPE_REGEX:
440 fr_assert(0);
441 goto error;
442 }
443
444 return map_proc_apply(p_result, request, frame);
445}
446
447static int edit_section_alloc(CONF_SECTION *parent, CONF_SECTION **child, char const *name1, fr_token_t op)
448{
449 CONF_SECTION *cs;
450
451 cs = cf_section_alloc(parent, parent, name1, NULL);
452 if (!cs) return -1;
453
455
456 if (child) *child = cs;
457
458 return 0;
459}
460
461static int edit_pair_alloc(CONF_SECTION *cs, CONF_PAIR *original, char const *attr, fr_token_t op, char const *value, fr_token_t list_op)
462{
463 CONF_PAIR *cp;
464 fr_token_t rhs_quote;
465
466 if (original) {
467 rhs_quote = cf_pair_value_quote(original);
468 } else {
469 rhs_quote = T_BARE_WORD;
470 }
471
472 cp = cf_pair_alloc(cs, attr, value, op, T_BARE_WORD, rhs_quote);
473 if (!cp) return -1;
474
475 if (!original) return 0;
476
477 cf_filename_set(cp, cf_filename(original));
478 cf_lineno_set(cp, cf_lineno(original));
479
480 if (fr_debug_lvl >= 3) {
481 if (list_op == T_INVALID) {
482 cf_log_err(original, "%s %s %s --> %s %s %s",
483 cf_pair_attr(original), fr_tokens[cf_pair_operator(original)], cf_pair_value(original),
484 attr, fr_tokens[op], value);
485 } else {
486 if (*attr == '&') attr++;
487 cf_log_err(original, "%s %s %s --> %s %s { %s %s %s }",
488 cf_pair_attr(original), fr_tokens[cf_pair_operator(original)], cf_pair_value(original),
489 cf_section_name1(cs), fr_tokens[list_op], attr, fr_tokens[op], value);
490 }
491 } else if (fr_debug_lvl >= 2) {
492 if (list_op == T_INVALID) {
493 cf_log_err(original, "--> %s %s %s",
494 attr, fr_tokens[op], value);
495 } else {
496 cf_log_err(original, "--> %s %s { %s %s %s }",
497 cf_section_name1(cs), fr_tokens[list_op], attr, fr_tokens[op], value);
498 }
499 }
500
501 return 0;
502}
503
504/*
505 * Convert "update" to "edit" using evil spells and sorcery.
506 */
508{
509 char const *name2 = cf_section_name2(cs);
510 CONF_ITEM *ci;
511 CONF_SECTION *group;
513 char list_buffer[32];
514 char value_buffer[256];
515 char attr_buffer[256];
516 char const *list;
517
519
520 /*
521 * Wrap it all in a group, no matter what. Because of
522 * limitations in the cf_pair_alloc() API.
523 */
524 group = cf_section_alloc(g->cs, g->cs, "group", NULL);
525 if (!group) return NULL;
526
527 (void) cf_item_remove(g->cs, group); /* was added at the end */
528 cf_item_insert_after(g->cs, cs, group);
529
530 /*
531 * Hoist this out of the loop, and make sure it never has a '&' prefix.
532 */
533 if (name2) {
534 if (*name2 == '&') name2++;
535 snprintf(list_buffer, sizeof(list_buffer), "%s", name2);
536 } else {
537 snprintf(list_buffer, sizeof(list_buffer), "%s", tmpl_list_name(unlang_ctx->rules->attr.list_def, "<INVALID>"));
538
539 }
540
541 /*
542 * Loop over the entries, rewriting them.
543 */
544 for (ci = cf_item_next(cs, NULL);
545 ci != NULL;
546 ci = cf_item_next(cs, ci)) {
547 CONF_PAIR *cp;
548 CONF_SECTION *child;
549 int rcode;
550 fr_token_t op;
551 char const *attr, *value, *end;
552
553 if (cf_item_is_section(ci)) {
554 cf_log_err(ci, "Cannot specify subsections for 'update'");
555 return NULL;
556 }
557
558 if (!cf_item_is_pair(ci)) continue;
559
560 cp = cf_item_to_pair(ci);
561
562 attr = cf_pair_attr(cp);
563 value = cf_pair_value(cp);
564 op = cf_pair_operator(cp);
565
566 fr_assert(attr);
568
569 list = list_buffer;
570
571 if (*attr == '&') attr++;
572
573 end = strchr(attr, '.');
574 if (!end) end = attr + strlen(attr);
575
576 /*
577 * Separate out the various possibilities for the "name", which could be a list, an
578 * attribute name, or a list followed by an attribute name.
579 *
580 * Note that even if we have "update request { ....}", the v3 parser allowed the contents
581 * of the "update" section to still specify parent / lists. Which makes parsing it all
582 * annoying.
583 *
584 * The good news is that all we care about is whether or not there's a parent / list ref.
585 * We don't care what that ref is.
586 */
587 {
589
590 /*
591 * Allow for a "parent" or "outer" reference. There may be multiple
592 * "parent.parent", so we keep processing them until we get a list reference.
593 */
595
596 /*
597 * Catch one more case where the behavior is different.
598 *
599 * &request += &config[*]
600 */
601 if ((cf_pair_value_quote(cp) == T_BARE_WORD) && (*value == '&') &&
602 (strchr(value, '.') == NULL) && (strchr(value, '[') != NULL)) {
603 char const *p = strchr(value, '[');
604
605 cf_log_err(cp, "Cannot do array assignments for lists. Just use '%s %s %.*s'",
606 list, fr_tokens[op], (int) (p - value), value);
607 return NULL;
608 }
609
610 goto attr_is_list;
611
612 /*
613 * Doesn't have a parent ref, maybe it's a list ref?
614 */
615 } else if (tmpl_attr_list_from_substr(&tmpl_list, &FR_SBUFF_IN(attr, (end - attr))) > 0) {
616 char *p;
617
618 attr_is_list:
619 snprintf(attr_buffer, sizeof(attr_buffer), "%s", attr);
620 list = attr_buffer;
621 attr = NULL;
622
623 p = strchr(attr_buffer, '.');
624 if (p) {
625 *(p++) = '\0';
626 attr = p;
627 }
628 }
629 }
630
631 switch (op) {
632 /*
633 * FOO !* ANY
634 *
635 * The RHS doesn't matter, so we ignore it.
636 */
637 case T_OP_CMP_FALSE:
638 if (!attr) {
639 /*
640 * Set list to empty value.
641 */
642 rcode = edit_section_alloc(group, NULL, list, T_OP_SET);
643
644 } else {
645 if (strchr(attr, '[') == NULL) {
646 snprintf(value_buffer, sizeof(value_buffer), "%s[*]", attr);
647 } else {
648 snprintf(value_buffer, sizeof(value_buffer), "%s", attr);
649 }
650
651 rcode = edit_pair_alloc(group, cp, list, T_OP_SUB_EQ, value_buffer, T_INVALID);
652 }
653 break;
654
655 case T_OP_SET:
656 /*
657 * Must be a list-to-list operation
658 */
659 if (!attr) {
660 list_op:
661 rcode = edit_pair_alloc(group, cp, list, op, value, T_INVALID);
662 break;
663 }
664 goto pair_op;
665
666 case T_OP_EQ:
667 /*
668 * Allow &list = "foo"
669 */
670 if (!attr) {
671 if (!value) {
672 cf_log_err(cp, "Missing value");
673 return NULL;
674 }
675
676 rcode = edit_pair_alloc(group, cp, list, op, value, T_INVALID);
677 break;
678 }
679
680 pair_op:
681 fr_assert(*attr != '&');
682 if (snprintf(value_buffer, sizeof(value_buffer), "%s.%s", list, attr) < 0) {
683 cf_log_err(cp, "RHS of update too long to convert to edit automatically");
684 return NULL;
685 }
686
687 rcode = edit_pair_alloc(group, cp, value_buffer, op, value, T_INVALID);
688 break;
689
690 case T_OP_ADD_EQ:
691 case T_OP_PREPEND:
692 if (!attr) goto list_op;
693
694 rcode = edit_section_alloc(group, &child, list, op);
695 if (rcode < 0) break;
696
697 rcode = edit_pair_alloc(child, cp, attr, T_OP_EQ, value, op);
698 break;
699
700 /*
701 * Remove matching attributes
702 */
703 case T_OP_SUB_EQ:
704 op = T_OP_CMP_EQ;
705
706 filter:
707 if (!attr) {
708 cf_log_err(cp, "Invalid operator for list assignment");
709 return NULL;
710 }
711
712 rcode = edit_section_alloc(group, &child, list, T_OP_SUB_EQ);
713 if (rcode < 0) break;
714
715 if (strchr(attr, '[') != 0) {
716 cf_log_err(cp, "Cannot do filtering with array indexes");
717 return NULL;
718 }
719
720 rcode = edit_pair_alloc(child, cp, attr, op, value, T_OP_SUB_EQ);
721 break;
722
723 /*
724 * Keep matching attributes, i.e. remove non-matching ones.
725 */
726 case T_OP_CMP_EQ:
727 op = T_OP_NE;
728 goto filter;
729
730 case T_OP_NE:
731 op = T_OP_CMP_EQ;
732 goto filter;
733
734 case T_OP_LT:
735 op = T_OP_GE;
736 goto filter;
737
738 case T_OP_LE:
739 op = T_OP_GT;
740 goto filter;
741
742 case T_OP_GT:
743 op = T_OP_LE;
744 goto filter;
745
746 case T_OP_GE:
747 op = T_OP_LT;
748 goto filter;
749
750 default:
751 cf_log_err(cp, "Unsupported operator - cannot auto-convert to edit section");
752 return NULL;
753 }
754
755 if (rcode < 0) {
756 cf_log_err(cp, "Failed converting entry");
757 return NULL;
758 }
759 }
760
761 return UNLANG_IGNORE;
762}
763
765{
767 int rcode;
768
770 unlang_map_t *gext;
771
772 unlang_t *c;
773 char const *name2 = cf_section_name2(cs);
774
775 tmpl_rules_t t_rules;
776
777 if (main_config_migrate_option_get("forbid_update")) {
778 cf_log_err(cs, "The use of 'update' sections is forbidden by the server configuration");
779 return NULL;
780 }
781
782 /*
783 * If we're migrating "update" sections to edit, then go
784 * do that now.
785 */
786 if (main_config_migrate_option_get("rewrite_update")) {
788 }
789
790 /*
791 * We allow unknown attributes here.
792 */
793 t_rules = *(unlang_ctx->rules);
794 t_rules.attr.allow_unknown = true;
795 t_rules.attr.allow_wildcard = true;
796 RULES_VERIFY(&t_rules);
797
799 if (!g) return NULL;
800
801 gext = unlang_group_to_map(g);
802
803 /*
804 * This looks at cs->name2 to determine which list to update
805 */
806 map_list_init(&gext->map);
807 rcode = map_afrom_cs(gext, &gext->map, cs, &t_rules, &t_rules, unlang_fixup_update, NULL, 128);
808 if (rcode < 0) return NULL; /* message already printed */
809 if (map_list_empty(&gext->map)) {
810 cf_log_err(cs, "'update' sections cannot be empty");
811 error:
812 talloc_free(g);
813 return NULL;
814 }
815
817 if (name2) {
818 c->name = name2;
819 c->debug_name = talloc_typed_asprintf(c, "update %s", name2);
820 } else {
821 c->name = "update";
822 c->debug_name = c->name;
823 }
824
825 if (!pass2_fixup_update(g, unlang_ctx->rules)) goto error;
826
827 return c;
828}
829
831{
833
834 /*
835 * map <module-name> <arg>
836 */
837 if (gext->vpt) {
838 char quote;
839 size_t quoted_len;
840 char *quoted_str;
841
842 switch (cf_section_argv_quote(g->cs, 0)) {
844 quote = '"';
845 break;
846
848 quote = '\'';
849 break;
850
852 quote = '`';
853 break;
854
855 default:
856 quote = '\0';
857 break;
858 }
859
860 quoted_len = fr_snprint_len(gext->vpt->name, gext->vpt->len, quote);
861 quoted_str = talloc_array(g, char, quoted_len);
862 fr_snprint(quoted_str, quoted_len, gext->vpt->name, gext->vpt->len, quote);
863
864 g->self.name = talloc_typed_asprintf(g, "map %s %s", cf_section_name2(g->cs), quoted_str);
865 g->self.debug_name = g->self.name;
866 talloc_free(quoted_str);
867
868 return 0;
869 }
870
871 g->self.name = talloc_typed_asprintf(g, "map %s", cf_section_name2(g->cs));
872 g->self.debug_name = g->self.name;
873
874 return 0;
875}
876
877/** Validate and fixup a map that's part of an map section.
878 *
879 * @param map to validate.
880 * @param ctx data to pass to fixup function (currently unused).
881 * @return 0 if valid else -1.
882 */
883static int fixup_map_cb(map_t *map, UNUSED void *ctx)
884{
885 switch (map->lhs->type) {
886 case TMPL_TYPE_ATTR:
888 case TMPL_TYPE_XLAT:
889 break;
890
891 default:
892 cf_log_err(map->ci, "Left side of map must be an attribute "
893 "or an xlat (that expands to an attribute), not a %s",
894 tmpl_type_to_str(map->lhs->type));
895 return -1;
896 }
897
898 switch (map->rhs->type) {
901 case TMPL_TYPE_DATA:
902 case TMPL_TYPE_XLAT:
903 case TMPL_TYPE_ATTR:
904 case TMPL_TYPE_EXEC:
905 break;
906
907 default:
908 cf_log_err(map->ci, "Right side of map must be an attribute, literal, xlat or exec, got type %s",
909 tmpl_type_to_str(map->rhs->type));
910 return -1;
911 }
912
913 if (!fr_assignment_op[map->op] && !fr_comparison_op[map->op]) {
914 cf_log_err(map->ci, "Invalid operator \"%s\" in map section. "
915 "Only assignment or filter operators are allowed",
916 fr_table_str_by_value(fr_tokens_table, map->op, "<INVALID>"));
917 return -1;
918 }
919
920 return 0;
921}
922
924{
926 int rcode;
927
929 unlang_map_t *gext;
930
931 unlang_t *c;
932 CONF_SECTION *modules;
933 char const *tmpl_str;
934
935 tmpl_t *vpt = NULL;
936
937 map_proc_t *proc;
938 map_proc_inst_t *proc_inst;
939
940 char const *name2 = cf_section_name2(cs);
941
942 tmpl_rules_t t_rules;
943
944 /*
945 * The RHS is NOT resolved in the context of the LHS.
946 */
947 t_rules = *(unlang_ctx->rules);
948 t_rules.attr.disallow_rhs_resolve = true;
949 RULES_VERIFY(&t_rules);
950
951 modules = cf_section_find(cf_root(cs), "modules", NULL);
952 if (!modules) {
953 cf_log_err(cs, "'map' sections require a 'modules' section");
954 return NULL;
955 }
956
957 proc = map_proc_find(name2);
958 if (!proc) {
959 cf_log_err(cs, "Failed to find map processor '%s'", name2);
960 return NULL;
961 }
963
965 if (!g) return NULL;
966
967 gext = unlang_group_to_map(g);
968
969 /*
970 * If there's a third string, it's the map src.
971 *
972 * Convert it into a template.
973 */
974 tmpl_str = cf_section_argv(cs, 0); /* AFTER name1, name2 */
975 if (tmpl_str) {
977
979
980 /*
981 * Try to parse the template.
982 */
983 (void) tmpl_afrom_substr(gext, &vpt,
984 &FR_SBUFF_IN(tmpl_str, talloc_array_length(tmpl_str) - 1),
985 type,
986 NULL,
987 &t_rules);
988 if (!vpt) {
989 cf_log_perr(cs, "Failed parsing map");
990 error:
991 talloc_free(g);
992 return NULL;
993 }
994
995 /*
996 * Limit the allowed template types.
997 */
998 switch (vpt->type) {
1000 case TMPL_TYPE_ATTR:
1002 case TMPL_TYPE_XLAT:
1004 case TMPL_TYPE_EXEC:
1006 case TMPL_TYPE_DATA:
1007 break;
1008
1009 default:
1011 cf_log_err(cs, "Invalid third argument for map");
1012 return NULL;
1013 }
1014 }
1015
1016 /*
1017 * This looks at cs->name2 to determine which list to update
1018 */
1019 map_list_init(&gext->map);
1020 rcode = map_afrom_cs(gext, &gext->map, cs, unlang_ctx->rules, &t_rules, fixup_map_cb, NULL, 256);
1021 if (rcode < 0) return NULL; /* message already printed */
1022 if (map_list_empty(&gext->map)) {
1023 cf_log_err(cs, "'map' sections cannot be empty");
1024 goto error;
1025 }
1026
1027
1028 /*
1029 * Call the map's instantiation function to validate
1030 * the map and perform any caching required.
1031 */
1032 proc_inst = map_proc_instantiate(gext, proc, cs, vpt, &gext->map);
1033 if (!proc_inst) {
1034 cf_log_err(cs, "Failed instantiating map function '%s'", name2);
1035 goto error;
1036 }
1038
1039 gext->vpt = vpt;
1040 gext->proc_inst = proc_inst;
1041
1043
1044 /*
1045 * Cache the module in the unlang_group_t struct.
1046 *
1047 * Ensure that the module has a "map" entry in its module
1048 * header? Or ensure that the map is registered in the
1049 * "bootstrap" phase, so that it's always available here.
1050 */
1051 if (!pass2_fixup_map_rhs(g, unlang_ctx->rules)) goto error;
1052
1053 return c;
1054}
1055
1056
1058{
1060 .name = "update",
1061 .type = UNLANG_TYPE_UPDATE,
1063
1064 .compile = unlang_compile_update,
1065 .interpret = unlang_update_state_init,
1066
1067 .unlang_size = sizeof(unlang_map_t),
1068 .unlang_name = "unlang_map_t",
1069 });
1070
1072 .name = "map",
1073 .type = UNLANG_TYPE_MAP,
1075
1076 .compile = unlang_compile_map,
1077 .interpret = unlang_map_state_init,
1078
1079 .unlang_size = sizeof(unlang_map_t),
1080 .unlang_name = "unlang_map_t",
1081
1082 .frame_state_size = sizeof(unlang_frame_state_map_proc_t),
1083 .frame_state_type = "unlang_frame_state_map_proc_t",
1084 });
1085}
unlang_action_t
Returned by unlang_op_t calls, determine the next action of the interpreter.
Definition action.h:35
@ UNLANG_ACTION_PUSHED_CHILD
unlang_t pushed a new child onto the stack, execute it instead of continuing.
Definition action.h:39
@ UNLANG_ACTION_STOP_PROCESSING
Break out of processing the current request (unwind).
Definition action.h:42
@ UNLANG_ACTION_FAIL
Encountered an unexpected error.
Definition action.h:36
@ UNLANG_ACTION_CALCULATE_RESULT
Calculate a new section rlm_rcode_t value.
Definition action.h:37
@ UNLANG_ACTION_YIELD
Temporarily pause execution until an event occurs.
Definition action.h:41
#define RCSID(id)
Definition build.h:485
#define FALL_THROUGH
clang 10 doesn't recognised the FALL-THROUGH comment anymore
Definition build.h:324
#define UNUSED
Definition build.h:317
#define RULES_VERIFY(_cs, _rules)
Definition cf_file.c:177
Common header for all CONF_* types.
Definition cf_priv.h:49
Configuration AVP similar to a fr_pair_t.
Definition cf_priv.h:70
A section grouping multiple CONF_PAIR.
Definition cf_priv.h:101
bool cf_item_is_pair(CONF_ITEM const *ci)
Determine if CONF_ITEM is a CONF_PAIR.
Definition cf_util.c:631
fr_token_t cf_section_argv_quote(CONF_SECTION const *cs, int argc)
Return the quoting for one of the variadic arguments.
Definition cf_util.c:1259
char const * cf_section_name2(CONF_SECTION const *cs)
Return the second identifier of a CONF_SECTION.
Definition cf_util.c:1184
CONF_PAIR * cf_pair_alloc(CONF_SECTION *parent, char const *attr, char const *value, fr_token_t op, fr_token_t lhs_quote, fr_token_t rhs_quote)
Allocate a CONF_PAIR.
Definition cf_util.c:1278
char const * cf_section_name1(CONF_SECTION const *cs)
Return the second identifier of a CONF_SECTION.
Definition cf_util.c:1170
CONF_SECTION * cf_section_find(CONF_SECTION const *cs, char const *name1, char const *name2)
Find a CONF_SECTION with name1 and optionally name2.
Definition cf_util.c:1027
CONF_SECTION * cf_item_to_section(CONF_ITEM const *ci)
Cast a CONF_ITEM to a CONF_SECTION.
Definition cf_util.c:683
void cf_section_add_name2_quote(CONF_SECTION *cs, fr_token_t token)
Set the quoting of the name2 identifier.
Definition cf_util.c:1241
fr_token_t cf_pair_operator(CONF_PAIR const *pair)
Return the operator of a pair.
Definition cf_util.c:1607
fr_token_t cf_pair_value_quote(CONF_PAIR const *pair)
Return the value (rhs) quoting of a pair.
Definition cf_util.c:1637
bool cf_item_is_section(CONF_ITEM const *ci)
Determine if CONF_ITEM is a CONF_SECTION.
Definition cf_util.c:617
char const * cf_section_argv(CONF_SECTION const *cs, int argc)
Return variadic argument at the specified index.
Definition cf_util.c:1212
CONF_PAIR * cf_item_to_pair(CONF_ITEM const *ci)
Cast a CONF_ITEM to a CONF_PAIR.
Definition cf_util.c:663
char const * cf_pair_value(CONF_PAIR const *pair)
Return the value of a CONF_PAIR.
Definition cf_util.c:1593
char const * cf_pair_attr(CONF_PAIR const *pair)
Return the attr of a CONF_PAIR.
Definition cf_util.c:1577
#define cf_log_err(_cf, _fmt,...)
Definition cf_util.h:289
#define cf_lineno(_cf)
Definition cf_util.h:104
#define cf_item_insert_after(_parent, _prev, _child)
Definition cf_util.h:86
#define cf_lineno_set(_ci, _lineno)
Definition cf_util.h:131
#define cf_root(_cf)
Definition cf_util.h:98
#define cf_item_remove(_parent, _child)
Definition cf_util.h:89
#define cf_item_next(_parent, _curr)
Definition cf_util.h:92
#define cf_log_perr(_cf, _fmt,...)
Definition cf_util.h:296
#define cf_section_alloc(_ctx, _parent, _name1, _name2)
Definition cf_util.h:140
#define cf_filename_set(_ci, _filename)
Definition cf_util.h:128
#define cf_filename(_cf)
Definition cf_util.h:107
bool pass2_fixup_map_rhs(unlang_group_t *g, tmpl_rules_t const *rules)
Definition compile.c:223
unlang_group_t * unlang_group_allocate(unlang_t *parent, CONF_SECTION *cs, unlang_type_t type)
Definition compile.c:456
bool pass2_fixup_update(unlang_group_t *g, tmpl_rules_t const *rules)
Definition compile.c:196
static void * fr_dcursor_next(fr_dcursor_t *cursor)
Advanced the cursor to the next item.
Definition dcursor.h:290
#define fr_dcursor_init(_cursor, _head)
Initialise a cursor.
Definition dcursor.h:710
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 MEM(x)
Definition debug.h:36
Test enumeration values.
Definition dict_test.h:92
#define fr_dlist_init(_head, _type, _field)
Initialise the head structure of a doubly linked list.
Definition dlist.h:260
static bool fr_dlist_empty(fr_dlist_head_t const *list_head)
Check whether a list has any items.
Definition dlist.h:501
static int fr_dlist_insert_tail(fr_dlist_head_t *list_head, void *ptr)
Insert an item into the tail of a list.
Definition dlist.h:378
static void * fr_dlist_next(fr_dlist_head_t const *list_head, void const *ptr)
Get the next item in a list.
Definition dlist.h:555
Head of a doubly linked list.
Definition dlist.h:51
#define RPEDEBUG(fmt,...)
Definition log.h:376
int map_afrom_cs(TALLOC_CTX *ctx, map_list_t *out, CONF_SECTION *cs, tmpl_rules_t const *lhs_rules, tmpl_rules_t const *rhs_rules, map_validate_t validate, void *uctx, unsigned int max)
Convert a config section into an attribute map.
Definition map.c:1131
static TALLOC_CTX * unlang_ctx
Definition base.c:71
void unlang_register(unlang_op_t *op)
Register an operation with the interpreter.
Definition base.c:56
map_proc_func_t resume
resumption handler
Definition map.c:67
unlang_action_t unlang_map_yield(request_t *request, map_proc_func_t resume, unlang_map_signal_t signal, fr_signal_t sigmask, void *rctx)
Yield a request back to the interpreter from within a module.
Definition map.c:344
static int fixup_map_cb(map_t *map, UNUSED void *ctx)
Validate and fixup a map that's part of an map section.
Definition map.c:883
fr_value_box_list_t lhs_result
Result of expanding the LHS.
Definition map.c:51
static unlang_t * unlang_compile_map(unlang_t *parent, unlang_compile_ctx_t *unlang_ctx, CONF_ITEM const *ci)
Definition map.c:923
fr_signal_t sigmask
Signals to block.
Definition map.c:69
static unlang_t * compile_update_to_edit(unlang_t *parent, unlang_compile_ctx_t *unlang_ctx, CONF_SECTION *cs)
Definition map.c:507
unlang_update_state_t state
What we're currently doing.
Definition map.c:54
static unlang_action_t list_mod_apply(unlang_result_t *p_result, request_t *request)
Apply a list of modifications on one or more fr_pair_t lists.
Definition map.c:91
static int compile_map_name(unlang_group_t *g)
Definition map.c:830
static unlang_action_t unlang_update_state_init(unlang_result_t *p_result, request_t *request, unlang_stack_frame_t *frame)
Execute an update block.
Definition map.c:270
static int edit_pair_alloc(CONF_SECTION *cs, CONF_PAIR *original, char const *attr, fr_token_t op, char const *value, fr_token_t list_op)
Definition map.c:461
void unlang_map_init(void)
Definition map.c:1057
static unlang_action_t list_mod_create(unlang_result_t *p_result, request_t *request, unlang_stack_frame_t *frame)
Create a list of modifications to apply to one or more fr_pair_t lists.
Definition map.c:135
static unlang_action_t map_proc_resume(unlang_result_t *p_result, request_t *request, UNUSED unlang_stack_frame_t *frame)
Definition map.c:296
fr_dlist_head_t vlm_head
Head of list of VP List Mod.
Definition map.c:49
void * rctx
for resume / signal
Definition map.c:66
static unlang_action_t map_proc_apply(unlang_result_t *p_result, request_t *request, unlang_stack_frame_t *frame)
Definition map.c:368
static int edit_section_alloc(CONF_SECTION *parent, CONF_SECTION **child, char const *name1, fr_token_t op)
Definition map.c:447
unlang_update_state_t
map and unlang integration.
Definition map.c:37
@ UNLANG_UPDATE_MAP_EXPANDED_RHS
Expand the RHS xlat or exec (if needed).
Definition map.c:40
@ UNLANG_UPDATE_MAP_INIT
Start processing a map.
Definition map.c:38
@ UNLANG_UPDATE_MAP_EXPANDED_LHS
Expand the LHS xlat or exec (if needed).
Definition map.c:39
static unlang_action_t unlang_map_state_init(unlang_result_t *p_result, request_t *request, unlang_stack_frame_t *frame)
Definition map.c:385
fr_dcursor_t maps
Cursor of maps to evaluate.
Definition map.c:47
static unlang_t * unlang_compile_update(unlang_t *parent, unlang_compile_ctx_t *unlang_ctx, CONF_ITEM const *ci)
Definition map.c:764
fr_value_box_list_t rhs_result
Result of expanding the RHS.
Definition map.c:52
unlang_map_signal_t signal
for signal handlers
Definition map.c:68
#define MAP_CTX(_mod_inst, _map_inst, _rctx)
Wrapper to create a map_ctx_t as a compound literal.
Definition map.c:80
fr_value_box_list_t src_result
Result of expanding the map source.
Definition map.c:61
State of a map block.
Definition map.c:60
State of an update block.
Definition map.c:46
talloc_free(reap)
int fr_debug_lvl
Definition log.c:40
static char * stack[MAX_STACK]
Definition radmin.c:159
bool main_config_migrate_option_get(char const *name)
map_proc_inst_t * proc_inst
Definition map_priv.h:35
static unlang_map_t * unlang_group_to_map(unlang_group_t *g)
Cast a group structure to the map keyword extension.
Definition map_priv.h:41
map_list_t map
Head of the map list.
Definition map_priv.h:34
tmpl_t * vpt
Definition map_priv.h:33
map_proc_t * map_proc_find(char const *name)
Find a map processor by name.
Definition map_proc.c:81
map_proc_inst_t * map_proc_instantiate(TALLOC_CTX *ctx, map_proc_t const *proc, CONF_SECTION *cs, tmpl_t const *src, map_list_t const *maps)
Create a new map proc instance.
Definition map_proc.c:204
fr_value_box_safe_for_t map_proc_literals_safe_for(map_proc_t const *proc)
Definition map_proc.c:69
unlang_action_t(* map_proc_func_t)(unlang_result_t *p_result, map_ctx_t const *mpctx, request_t *request, fr_value_box_list_t *result, map_list_t const *maps)
Function to evaluate the src string and map the result to server attributes.
Definition map_proc.h:71
Map processor registration.
Map processor instance.
@ FR_TYPE_STRING
String of printable characters.
int unlang_fixup_update(map_t *map, void *ctx)
Validate and fixup a map that's part of an update section.
Definition compile.c:360
size_t fr_snprint(char *out, size_t outlen, char const *in, ssize_t inlen, char quote)
Escape any non printable or non-UTF8 characters in the input string.
Definition print.c:227
size_t fr_snprint_len(char const *in, ssize_t inlen, char quote)
Find the length of the buffer required to fully escape a string with fr_prints.
Definition print.c:409
#define fr_assert(_expr)
Definition rad_assert.h:38
static bool done
Definition radclient.c:81
#define REDEBUG(fmt,...)
Definition radclient.h:52
#define RDEBUG2(fmt,...)
Definition radclient.h:54
#define RETURN_UNLANG_FAIL
Definition rcode.h:59
#define RETURN_UNLANG_NOOP
Definition rcode.h:65
#define REQUEST_VERIFY(_x)
Definition request.h:305
#define FR_SBUFF_IN(_start, _len_or_end)
int map_list_mod_apply(request_t *request, vp_list_mod_t const *vlm)
Apply the output of map_to_list_mod to a request.
Definition map_async.c:914
int map_to_list_mod(TALLOC_CTX *ctx, vp_list_mod_t **out, request_t *request, map_t const *map, fr_value_box_list_t *lhs_result, fr_value_box_list_t *rhs_result)
Evaluate a map creating a new map with TMPL_TYPE_ATTR LHS and TMPL_TYPE_DATA RHS.
Definition map_async.c:248
A list modification.
Definition map.h:99
static char const * tmpl_type_to_str(tmpl_type_t type)
Return a static string containing the type name.
Definition tmpl.h:634
fr_table_num_sorted_t const tmpl_request_ref_table[]
Map keywords to tmpl_request_ref_t values.
fr_value_box_safe_for_t literals_safe_for
safe_for value assigned to literal values in xlats, execs, and data.
Definition tmpl.h:347
#define tmpl_xlat(_tmpl)
Definition tmpl.h:930
static fr_dict_attr_t const * tmpl_list(tmpl_t const *vpt)
Definition tmpl.h:904
@ TMPL_TYPE_REGEX_UNCOMPILED
Regex where compilation is possible but hasn't been performed yet.
Definition tmpl.h:158
@ TMPL_TYPE_ATTR_UNRESOLVED
An attribute reference that we couldn't resolve but looked valid.
Definition tmpl.h:185
@ TMPL_TYPE_ATTR
Reference to one or more attributes.
Definition tmpl.h:142
@ TMPL_TYPE_XLAT
Pre-parsed xlat expansion.
Definition tmpl.h:146
@ TMPL_TYPE_EXEC
Callout to an external script or program.
Definition tmpl.h:150
@ TMPL_TYPE_REGEX_XLAT_UNRESOLVED
A regular expression with unresolved xlat functions or attribute references.
Definition tmpl.h:197
@ TMPL_TYPE_DATA
Value in native boxed format.
Definition tmpl.h:138
@ TMPL_TYPE_REGEX
Compiled (and possibly JIT'd) regular expression.
Definition tmpl.h:154
@ TMPL_TYPE_DATA_UNRESOLVED
Unparsed literal string.
Definition tmpl.h:179
@ TMPL_TYPE_XLAT_UNRESOLVED
A xlat expansion with unresolved xlat functions or attribute references.
Definition tmpl.h:193
@ TMPL_TYPE_REGEX_XLAT
A regex containing xlat expansions.
Definition tmpl.h:162
@ TMPL_TYPE_EXEC_UNRESOLVED
An exec with unresolved xlat function or attribute references.
Definition tmpl.h:189
ssize_t tmpl_afrom_substr(TALLOC_CTX *ctx, tmpl_t **out, fr_sbuff_t *in, fr_token_t quote, fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules))
Convert an arbitrary string into a tmpl_t.
static fr_slen_t vpt
Definition tmpl.h:1269
tmpl_attr_rules_t attr
Rules/data for parsing attribute references.
Definition tmpl.h:335
static char const * tmpl_list_name(fr_dict_attr_t const *list, char const *def)
Return the name of a tmpl list or def if list not provided.
Definition tmpl.h:915
@ REQUEST_UNKNOWN
Unknown request.
Definition tmpl.h:97
#define tmpl_aexpand(_ctx, _out, _request, _vpt, _escape, _escape_ctx)
Expand a tmpl to a C type, allocing a new buffer to hold the string.
Definition tmpl.h:1062
fr_slen_t tmpl_attr_list_from_substr(fr_dict_attr_t const **da_p, fr_sbuff_t *in)
Parse one a single list reference.
Optional arguments passed to vp_tmpl functions.
Definition tmpl.h:332
fr_signal_t
Signals that can be generated/processed by request signal handlers.
Definition signal.h:38
PUBLIC int snprintf(char *string, size_t length, char *format, va_alist)
Definition snprintf.c:689
eap_aka_sim_process_conf_t * inst
fr_aka_sim_id_type_t type
eap_type_t type
The preferred EAP-Type of this instance of the EAP-SIM/AKA/AKA' state machine.
Value pair map.
Definition map.h:77
fr_token_t op
The operator that controls insertion of the dst attribute.
Definition map.h:82
tmpl_t * lhs
Typically describes the attribute to add, modify or compare.
Definition map.h:78
tmpl_t * rhs
Typically describes a literal value or a src attribute to copy or compare.
Definition map.h:79
CONF_ITEM * ci
Config item that the map was created from.
Definition map.h:85
uint8_t disallow_rhs_resolve
map RHS is NOT immediately resolved in the context of the LHS.
Definition tmpl.h:320
uint8_t allow_wildcard
Allow the special case of .
Definition tmpl.h:309
uint8_t allow_unknown
Allow unknown attributes i.e.
Definition tmpl.h:301
#define fr_table_str_by_value(_table, _number, _def)
Convert an integer to a string.
Definition table.h:772
#define fr_table_value_by_substr(_table, _name, _name_len, _def)
Convert a partial string to a value using an ordered or sorted table.
Definition table.h:693
char * talloc_typed_asprintf(TALLOC_CTX *ctx, char const *fmt,...)
Call talloc vasprintf, setting the type on the new chunk correctly.
Definition talloc.c:514
#define talloc_zero_pooled_object(_ctx, _type, _num_subobjects, _total_subobjects_size)
Definition talloc.h:177
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)
Push a tmpl onto the stack for evaluation.
Definition tmpl.c:273
const bool fr_assignment_op[T_TOKEN_LAST]
Definition token.c:169
fr_table_num_ordered_t const fr_tokens_table[]
Definition token.c:34
char const * fr_tokens[T_TOKEN_LAST]
Definition token.c:79
const bool fr_comparison_op[T_TOKEN_LAST]
Definition token.c:199
enum fr_token fr_token_t
@ T_OP_SUB_EQ
Definition token.h:70
@ T_INVALID
Definition token.h:39
@ T_SINGLE_QUOTED_STRING
Definition token.h:122
@ T_BARE_WORD
Definition token.h:120
@ T_OP_EQ
Definition token.h:83
@ T_BACK_QUOTED_STRING
Definition token.h:123
@ T_OP_SET
Definition token.h:84
@ T_OP_NE
Definition token.h:97
@ T_OP_ADD_EQ
Definition token.h:69
@ T_OP_CMP_FALSE
Definition token.h:105
@ T_DOUBLE_QUOTED_STRING
Definition token.h:121
@ T_OP_CMP_EQ
Definition token.h:106
@ T_OP_LE
Definition token.h:100
@ T_OP_GE
Definition token.h:98
@ T_OP_GT
Definition token.h:99
@ T_OP_LT
Definition token.h:101
@ T_OP_PREPEND
Definition token.h:85
void(* unlang_map_signal_t)(map_ctx_t const *mpctx, request_t *request, fr_signal_t action)
A callback when the request gets a fr_signal_t.
Definition map.h:43
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:283
CONF_SECTION * cs
static void repeatable_clear(unlang_stack_frame_t *frame)
char const * debug_name
Printed in log messages when the node is executed.
void * state
Stack frame specialisations.
static unlang_t * unlang_group_to_generic(unlang_group_t const *p)
#define UNLANG_IGNORE
static unlang_group_t * unlang_generic_to_group(unlang_t const *p)
char const * name
Unknown...
@ UNLANG_TYPE_UPDATE
Update block.
Definition unlang_priv.h:57
@ UNLANG_TYPE_MAP
Mapping section (like UNLANG_TYPE_UPDATE, but uses values from a map_proc_t call).
Definition unlang_priv.h:64
static void frame_repeat(unlang_stack_frame_t *frame, unlang_process_t process)
Mark the current stack frame up for repeat, and set a new process function.
unlang_t const * instruction
The unlang node we're evaluating.
@ UNLANG_OP_FLAG_DEBUG_BRACES
Print debug braces.
@ UNLANG_OP_FLAG_RCODE_SET
Set request->rcode to the result of this operation.
static void repeatable_set(unlang_stack_frame_t *frame)
unlang_process_t process
function to call for interpreting this stack frame
Generic representation of a grouping.
An unlang operation.
A node in a graph of unlang_op_t (s) that we execute.
Our interpreter stack, as distinct from the C stack.
An unlang stack associated with a request.
static fr_slen_t parent
Definition pair.h:839
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:5949
@ FR_VALUE_BOX_LIST_FREE
Definition value.h:237
#define VALUE_BOX_LIST_VERIFY(_x)
Definition value.h:1319