The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
compile.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: 242ba0dcb58c6563c54c6b0cfa0974115584a43f $
19 *
20 * @file unlang/compile.c
21 * @brief Functions to convert configuration sections into unlang structures.
22 *
23 * @copyright 2006-2016 The FreeRADIUS server project
24 */
25RCSID("$Id: 242ba0dcb58c6563c54c6b0cfa0974115584a43f $")
26
27#include <freeradius-devel/protocol/freeradius/freeradius.internal.h>
28
29#include <freeradius-devel/server/virtual_servers.h>
30
31#include <freeradius-devel/server/cf_file.h>
32#include <freeradius-devel/server/main_config.h>
33#include <freeradius-devel/server/map_proc.h>
34#include <freeradius-devel/server/modpriv.h>
35
36
37#include <freeradius-devel/unlang/xlat_priv.h>
38
39#include "call_priv.h"
40#include "caller_priv.h"
41#include "condition_priv.h"
42#include "foreach_priv.h"
43#include "load_balance_priv.h"
44#include "map_priv.h"
45#include "module_priv.h"
46#include "parallel_priv.h"
47#include "subrequest_priv.h"
48#include "switch_priv.h"
49#include "edit_priv.h"
50#include "timeout_priv.h"
51#include "limit_priv.h"
52#include "transaction_priv.h"
53#include "try_priv.h"
54#include "mod_action.h"
55
56extern uint64_t unlang_number;
57
58/*
59 * Until we know how many instructions there are, we can't
60 * allocate an array. So we have to put the instructions into an
61 * RB tree.
62 */
65
66/* Here's where we recognize all of our keywords: first the rcodes, then the
67 * actions */
69 { L("..."), RLM_MODULE_NOT_SET },
70 { L("disallow"), RLM_MODULE_DISALLOW },
71 { L("fail"), RLM_MODULE_FAIL },
72 { L("handled"), RLM_MODULE_HANDLED },
73 { L("invalid"), RLM_MODULE_INVALID },
74 { L("noop"), RLM_MODULE_NOOP },
75 { L("notfound"), RLM_MODULE_NOTFOUND },
76 { L("ok"), RLM_MODULE_OK },
77 { L("reject"), RLM_MODULE_REJECT },
78 { L("timeout"), RLM_MODULE_TIMEOUT },
79 { L("updated"), RLM_MODULE_UPDATED }
80};
82
83#define UPDATE_CTX2 unlang_compile_ctx_copy(&unlang_ctx2, unlang_ctx)
84
85
86static char const unlang_spaces[] = " ";
87
88bool pass2_fixup_tmpl(UNUSED TALLOC_CTX *ctx, tmpl_t **vpt_p, CONF_ITEM const *ci, fr_dict_t const *dict)
89{
90 tmpl_t *vpt = *vpt_p;
91
93
94 /*
95 * We may now know the correct dictionary
96 * where we didn't before...
97 */
98 if (!vpt->rules.attr.dict_def) tmpl_set_dict_def(vpt, dict);
99
100 /*
101 * Fixup any other tmpl types
102 */
103 if (tmpl_resolve(vpt, &(tmpl_res_rules_t){ .dict_def = dict, .force_dict_def = (dict != NULL)}) < 0) {
104 cf_log_perr(ci, NULL);
105 return false;
106 }
107
108 return true;
109}
110
111/** Fixup ONE map (recursively)
112 *
113 * This function resolves most things. Most notable it CAN leave the
114 * RHS unresolved, for use in `map` sections.
115 */
117{
118 RULES_VERIFY(rules);
119
120 if (tmpl_is_data_unresolved(map->lhs)) {
121 if (!pass2_fixup_tmpl(map, &map->lhs, map->ci, rules->attr.dict_def)) {
122 return false;
123 }
124 }
125
126 /*
127 * Enforce parent-child relationships in nested maps.
128 */
129 if (parent) {
130 if ((map->op != T_OP_EQ) && (!map->parent || (map->parent->op != T_OP_SUB_EQ))) {
131 cf_log_err(map->ci, "Invalid operator \"%s\" in nested map section. "
132 "Only '=' is allowed",
133 fr_table_str_by_value(fr_tokens_table, map->op, "<INVALID>"));
134 return false;
135 }
136 }
137
138 if (map->rhs) {
139 if (tmpl_is_data_unresolved(map->rhs)) {
141
142 if (!pass2_fixup_tmpl(map, &map->rhs, map->ci, rules->attr.dict_def)) {
143 return false;
144 }
145 }
146 }
147
148 /*
149 * Sanity check sublists.
150 */
151 if (!map_list_empty(&map->child)) {
152 fr_dict_attr_t const *da;
153 map_t *child;
154
155 if (!tmpl_is_attr(map->lhs)) {
156 cf_log_err(map->ci, "Sublists can only be assigned to a known attribute");
157 return false;
158 }
159
160 da = tmpl_attr_tail_da(map->lhs);
161
162 /*
163 * Resolve all children.
164 */
165 for (child = map_list_next(&map->child, NULL);
166 child != NULL;
167 child = map_list_next(&map->child, child)) {
168 if (!pass2_fixup_map(child, rules, da)) {
169 return false;
170 }
171 }
172 }
173
174 return true;
175}
176
177/*
178 * Do all kinds of fixups and checks for update sections.
179 */
181{
183 map_t *map = NULL;
184
185 RULES_VERIFY(rules);
186
187 while ((map = map_list_next(&gext->map, map))) {
188 /*
189 * Mostly fixup the map, but maybe leave the RHS
190 * unresolved.
191 */
192 if (!pass2_fixup_map(map, rules, NULL)) return false;
193
194 /*
195 * Check allowed operators, and ensure that the
196 * RHS is resolved.
197 */
198 if (cf_item_is_pair(map->ci) && (unlang_fixup_update(map, NULL) < 0)) return false;
199 }
200
201 return true;
202}
203
204/*
205 * Compile the RHS of map sections to xlat_exp_t
206 */
208{
210 map_t *map = NULL;
211
212 RULES_VERIFY(rules);
213
214 /*
215 * Do most fixups on the maps. Leaving the RHS as
216 * unresolved, so that the `map` function can interpret
217 * the RHS as a reference to a json string, SQL column
218 * name, etc.
219 */
220 while ((map = map_list_next(&gext->map, map))) {
221 if (!pass2_fixup_map(map, rules, NULL)) return false;
222 }
223
224 /*
225 * Map sections don't need a VPT.
226 */
227 if (!gext->vpt) return true;
228
229 if (map_list_num_elements(&gext->map) == 0) return true;
230
231 return pass2_fixup_tmpl(map_list_head(&gext->map)->ci, &gext->vpt,
232 cf_section_to_item(g->cs), rules->attr.dict_def);
233}
234
235static void unlang_dump(unlang_t *c, int depth)
236{
238 map_t *map;
239 char buffer[1024];
240
241 switch (c->type) {
242 case UNLANG_TYPE_NULL:
244 case UNLANG_TYPE_MAX:
245 fr_assert(0);
246 break;
247
249 DEBUG("%.*s%s", depth, unlang_spaces, c->debug_name);
250 break;
251
253 {
255
256 DEBUG("%.*s%s", depth, unlang_spaces, m->mmc.mi->name);
257 }
258 break;
259
260 case UNLANG_TYPE_MAP:
261 {
262 unlang_map_t *gext;
263
264 DEBUG("%.*s%s {", depth, unlang_spaces, c->debug_name);
265
267 gext = unlang_group_to_map(g);
268 map = NULL;
269 while ((map = map_list_next(&gext->map, map))) {
270 map_print(&FR_SBUFF_OUT(buffer, sizeof(buffer)), map);
271 DEBUG("%.*s%s", depth + 1, unlang_spaces, buffer);
272 }
273
274 DEBUG("%.*s}", depth, unlang_spaces);
275 }
276 break;
277
278 case UNLANG_TYPE_EDIT:
279 {
280 unlang_edit_t *edit;
281
282 DEBUG("%.*s%s {", depth, unlang_spaces, c->debug_name);
283
284 edit = unlang_generic_to_edit(c);
285 map = NULL;
286 while ((map = map_list_next(&edit->maps, map))) {
287 if (!map->rhs) continue; /* @todo - fixme */
288
289 map_print(&FR_SBUFF_OUT(buffer, sizeof(buffer)), map);
290 DEBUG("%.*s%s", depth + 1, unlang_spaces, buffer);
291 }
292
293 DEBUG("%.*s}", depth, unlang_spaces);
294 }
295 break;
296
297 case UNLANG_TYPE_CALL:
299 case UNLANG_TYPE_CASE:
302 case UNLANG_TYPE_ELSE:
305 case UNLANG_TYPE_IF:
316 case UNLANG_TYPE_TRY:
317 case UNLANG_TYPE_CATCH: /* @todo - print out things we catch, too */
319
320 DEBUG("%.*s%s {", depth, unlang_spaces, c->debug_name);
321 unlang_list_foreach(&g->children, child) {
322 unlang_dump(child, depth + 1);
323 }
324 DEBUG("%.*s}", depth, unlang_spaces);
325 break;
326
331 case UNLANG_TYPE_TMPL:
332 case UNLANG_TYPE_XLAT:
333 DEBUG("%.*s%s", depth, unlang_spaces, c->debug_name);
334 break;
335 }
336}
337
338
339/** Validate and fixup a map that's part of an update section.
340 *
341 * @param map to validate.
342 * @param ctx data to pass to fixup function (currently unused).
343 * @return
344 * - 0 if valid.
345 * - -1 not valid.
346 */
347int unlang_fixup_update(map_t *map, void *ctx)
348{
349 CONF_PAIR *cp = cf_item_to_pair(map->ci);
350
351 if (!ctx) {
352 /*
353 * Fixup RHS attribute references to change NUM_UNSPEC to NUM_ALL.
354 *
355 * RHS may be NULL for T_OP_CMP_FALSE.
356 */
357 if (map->rhs) {
358 switch (map->rhs->type) {
359 case TMPL_TYPE_ATTR:
361 break;
362
363 default:
364 break;
365 }
366 }
367 }
368
369 /*
370 * Lots of sanity checks for insane people...
371 */
372
373 /*
374 * Depending on the attribute type, some operators are disallowed.
375 */
376 if (tmpl_is_attr(map->lhs)) {
377 /*
378 * What exactly were you expecting to happen here?
379 */
380 if (tmpl_attr_tail_da_is_leaf(map->lhs) &&
381 map->rhs && tmpl_is_list(map->rhs)) {
382 cf_log_err(map->ci, "Can't copy list into an attribute");
383 return -1;
384 }
385
386 if (!fr_assignment_op[map->op] && !fr_comparison_op[map->op] && !fr_binary_op[map->op]) {
387 cf_log_err(map->ci, "Invalid operator \"%s\" in update section. "
388 "Only assignment or filter operators are allowed",
389 fr_table_str_by_value(fr_tokens_table, map->op, "<INVALID>"));
390 return -1;
391 }
392
393 if (fr_comparison_op[map->op] && (map->op != T_OP_CMP_FALSE)) {
394 cf_log_warn(cp, "Please use the 'filter' keyword for attribute filtering");
395 }
396 }
397
398 /*
399 * If the map has a unary operator there's no further
400 * processing we need to, as RHS is unused.
401 */
402 if (map->op == T_OP_CMP_FALSE) return 0;
403
404 if (unlikely(!map->rhs)) {
405 cf_log_err(map->ci, "Missing rhs");
406 return -1;
407 }
408
409 if (!tmpl_is_data_unresolved(map->rhs)) return 0;
410
411 /*
412 * If LHS is an attribute, and RHS is a literal, we can
413 * preparse the information into a TMPL_TYPE_DATA.
414 *
415 * Unless it's a unary operator in which case we
416 * ignore map->rhs.
417 */
418 if (tmpl_is_attr(map->lhs) && tmpl_is_data_unresolved(map->rhs)) {
419 fr_type_t type = tmpl_attr_tail_da(map->lhs)->type;
420
421 /*
422 * @todo - allow passing octets to
423 * FR_TYPE_STRUCT, which can then decode them as
424 * data? That would be rather powerful.
425 */
427
428 /*
429 * It's a literal string, just copy it.
430 * Don't escape anything.
431 */
432 if (tmpl_cast_in_place(map->rhs, type, tmpl_attr_tail_da(map->lhs)) < 0) {
433 cf_log_perr(map->ci, "Cannot convert RHS value (%s) to LHS attribute type (%s)",
436 return -1;
437 }
438
439 return 0;
440 } /* else we can't precompile the data */
441
442 if (!tmpl_is_xlat(map->lhs)) {
443 fr_assert(0);
444 cf_log_err(map->ci, "Cannot determine what update action to perform");
445 return -1;
446 }
447
448 return 0;
449}
450
451
453{
455 unlang_t *c;
456 TALLOC_CTX *ctx;
457 unlang_op_t const *op = &unlang_ops[type];
458
459 ctx = parent;
460 if (!ctx) ctx = cs;
461
462 fr_assert(op->unlang_size > 0);
463
464 /*
465 * All the groups have a common header
466 */
467 g = (unlang_group_t *)_talloc_zero_pooled_object(ctx, op->unlang_size, op->unlang_name,
468 op->pool_headers, op->pool_len);
469 if (!g) return NULL;
470
471 g->cs = cs;
472
474 c->ci = CF_TO_ITEM(cs);
475
477
478 return g;
479}
480
481/** Update a compiled unlang_t with the default actions.
482 *
483 * Don't over-ride any actions which have been set.
484 */
486{
487 int i;
488
489 /*
490 * Note that we do NOT copy over the default retries, as
491 * that would result in every subsection doing it's own
492 * retries. That is not what we want. Instead, we want
493 * the retries to apply only to the _current_ section.
494 */
495
496 /*
497 * Set the default actions if they haven't already been
498 * set.
499 */
500 for (i = 0; i < RLM_MODULE_NUMCODES; i++) {
501 if (!c->actions.actions[i]) {
502 c->actions.actions[i] = unlang_ctx->actions.actions[i];
503 }
504 }
505}
506
507#define T(_x) [T_OP_ ## _x] = true
508
509static const bool edit_list_sub_op[T_TOKEN_LAST] = {
510 T(NE),
511 T(GE),
512 T(GT),
513 T(LE),
514 T(LT),
515 T(CMP_EQ),
516};
517
518/** Validate and fixup a map that's part of an edit section.
519 *
520 * @param map to validate.
521 * @param ctx data to pass to fixup function (currently unused).
522 * @return 0 if valid else -1.
523 *
524 * @todo - this is only called for CONF_PAIR maps, not for
525 * CONF_SECTION. So when we parse nested maps, there's no validation
526 * done of the CONF_SECTION. In order to fix this, we need to have
527 * map_afrom_cs() call the validation function for the CONF_SECTION
528 * *before* recursing.
529 */
530static int unlang_fixup_edit(map_t *map, void *ctx)
531{
532 CONF_PAIR *cp = cf_item_to_pair(map->ci);
533 fr_dict_attr_t const *da;
534 fr_dict_attr_t const *parent = NULL;
535 map_t *parent_map = ctx;
536
537 fr_assert(parent_map);
538#ifdef STATIC_ANALYZER
539 if (!parent_map) return -1;
540#endif
541
542 fr_assert(tmpl_is_attr(parent_map->lhs));
543
544 if (parent_map->op == T_OP_SUB_EQ) {
545 if (!edit_list_sub_op[map->op]) {
546 cf_log_err(cp, "Invalid operator '%s' for right-hand side list. It must be a comparison operator", fr_tokens[map->op]);
547 return -1;
548 }
549
550 } else if (map->op != T_OP_EQ) {
551 cf_log_err(cp, "Invalid operator '%s' for right-hand side list. It must be '='", fr_tokens[map->op]);
552 return -1;
553 }
554
555 /*
556 * map_afrom_cs() will build its tree recursively, and call us for each child map.
557 */
558 if (map->parent && (map->parent != parent_map)) parent_map = map->parent;
559
560 parent = tmpl_attr_tail_da(parent_map->lhs);
561
562 switch (map->lhs->type) {
563 case TMPL_TYPE_ATTR:
564 da = tmpl_attr_tail_da(map->lhs);
565 if (!da->flags.internal && parent && (parent->type != FR_TYPE_GROUP) &&
566 (da->parent != parent)) {
567 /* FIXME - Broken check, doesn't work for key attributes */
568 cf_log_err(cp, "Invalid location for %s - it is not a child of %s",
569 da->name, parent->name);
570 return -1;
571 }
572 break;
573
575 case TMPL_TYPE_XLAT:
576 break;
577
578 default:
579 cf_log_err(map->ci, "Left side of map must be an attribute "
580 "or an xlat (that expands to an attribute), not a %s",
581 tmpl_type_to_str(map->lhs->type));
582 return -1;
583 }
584
585 fr_assert(map->rhs);
586
587 switch (map->rhs->type) {
590 case TMPL_TYPE_XLAT:
591 case TMPL_TYPE_DATA:
592 case TMPL_TYPE_ATTR:
593 case TMPL_TYPE_EXEC:
594 break;
595
596 default:
597 cf_log_err(map->ci, "Right side of map must be an attribute, literal, xlat or exec, got type %s",
598 tmpl_type_to_str(map->rhs->type));
599 return -1;
600 }
601
602 return 0;
603}
604
605/** Compile one edit section.
606 */
608{
609 unlang_edit_t *edit;
611 map_t *map;
612 char const *name;
613 fr_token_t op;
614 ssize_t slen;
615 fr_dict_attr_t const *parent_da;
616 int num;
617
618 tmpl_rules_t t_rules;
619
621 if (name) {
622 cf_log_err(cs, "Unexpected name2 '%s' for editing list %s ", name, cf_section_name1(cs));
623 return NULL;
624 }
625
626 op = cf_section_name2_quote(cs);
627 if ((op == T_INVALID) || !fr_list_assignment_op[op]) {
628 cf_log_err(cs, "Invalid operator '%s' for editing list %s.", fr_tokens[op], cf_section_name1(cs));
629 return NULL;
630 }
631
632 if ((op == T_OP_CMP_TRUE) || (op == T_OP_CMP_FALSE)) {
633 cf_log_err(cs, "Invalid operator \"%s\".",
634 fr_table_str_by_value(fr_tokens_table, op, "<INVALID>"));
635 return NULL;
636 }
637
638 /*
639 * We allow unknown attributes here.
640 */
641 t_rules = *(unlang_ctx->rules);
642 t_rules.attr.allow_unknown = true;
643 RULES_VERIFY(&t_rules);
644
645 edit = talloc_zero(parent, unlang_edit_t);
646 if (!edit) return NULL;
647
648 c = out = unlang_edit_to_generic(edit);
650 c->name = cf_section_name1(cs);
651 c->debug_name = c->name;
652 c->ci = CF_TO_ITEM(cs);
653
654 map_list_init(&edit->maps);
655
656 /*
657 * Allocate the map and initialize it.
658 */
659 MEM(map = talloc_zero(edit, map_t));
660 map->op = op;
661 map->ci = cf_section_to_item(cs);
662 map_list_init(&map->child);
663
665
666 slen = tmpl_afrom_attr_str(map, NULL, &map->lhs, name, &t_rules);
667 if (slen <= 0) {
668 cf_log_err(cs, "Failed parsing list reference %s - %s", name, fr_strerror());
669 fail:
670 talloc_free(edit);
671 return NULL;
672 }
673
674 /*
675 * Can't assign to [*] or [#]
676 */
677 num = tmpl_attr_tail_num(map->lhs);
678 if ((num == NUM_ALL) || (num == NUM_COUNT)) {
679 cf_log_err(cs, "Invalid array reference in %s", name);
680 goto fail;
681 }
682
683 /*
684 * If the DA isn't structural, then it can't have children.
685 */
686 parent_da = tmpl_attr_tail_da(map->lhs);
687 if (fr_type_is_structural(parent_da->type)) {
688 map_t *child;
689
690 /*
691 * Reset the namespace to be this attribute. The tmpl tokenizer will take care of
692 * figuring out if this is a group, TLV, dictionary switch, etc.
693 */
694 t_rules.attr.namespace = parent_da;
695
696 if (map_afrom_cs_edit(map, &map->child, cs, &t_rules, &t_rules, unlang_fixup_edit, map, 256) < 0) {
697 goto fail;
698 }
699
700 /*
701 * As a set of fixups... we can't do array references in -=
702 */
703 if (map->op == T_OP_SUB_EQ) {
704 for (child = map_list_head(&map->child); child != NULL; child = map_list_next(&map->child, child)) {
705 if (!tmpl_is_attr(child->lhs)) continue;
706
707 if (tmpl_attr_tail_num(child->lhs) != NUM_UNSPEC) {
708 cf_log_err(child->ci, "Cannot use array references and values when deleting from a list");
709 goto fail;
710 }
711
712 /*
713 * The edit code doesn't do this correctly, so we just forbid it.
714 */
715 if ((tmpl_attr_num_elements(child->lhs) - tmpl_attr_num_elements(map->lhs)) > 1) {
716 cf_log_err(child->ci, "List deletion must operate directly on the final child");
717 goto fail;
718 }
719
720 /*
721 * We don't do list comparisons either.
722 */
723 if (fr_type_is_structural(tmpl_attr_tail_da(child->lhs)->type)) {
724 cf_log_err(child->ci, "List deletion cannot operate on lists");
725 goto fail;
726 }
727 }
728 }
729 } else {
730 /*
731 * foo := { a, b, c }
732 */
733 if (map_list_afrom_cs(map, &map->child, cs, &t_rules, NULL, NULL, 256) < 0) {
734 goto fail;
735 }
736
737 if ((map->op != T_OP_SET) && !map_list_num_elements(&map->child)) {
738 cf_log_err(cs, "Cannot use operator '%s' for assigning empty list to '%s' data type.",
739 fr_tokens[map->op], fr_type_to_str(parent_da->type));
740 goto fail;
741 }
742 }
743 /*
744 * Do basic sanity checks and resolving.
745 */
746 if (!pass2_fixup_map(map, unlang_ctx->rules, NULL)) goto fail;
747
748 /*
749 * Check operators, and ensure that the RHS has been
750 * resolved.
751 */
752// if (unlang_fixup_update(map, NULL) < 0) goto fail;
753
754 map_list_insert_tail(&edit->maps, map);
755
756 return out;
757}
758
759/** Compile one edit pair
760 *
761 */
763{
764 unlang_edit_t *edit;
765 unlang_t *c = NULL, *out = UNLANG_IGNORE;
766 map_t *map;
767 int num;
768
769 tmpl_rules_t t_rules;
770 fr_token_t op;
771
772 /*
773 * We allow unknown attributes here.
774 */
775 t_rules = *(unlang_ctx->rules);
776 t_rules.attr.allow_unknown = true;
777 fr_assert(t_rules.attr.ci == cf_pair_to_item(cp));
778 RULES_VERIFY(&t_rules);
779
780 edit = talloc_zero(parent, unlang_edit_t);
781 if (!edit) return NULL;
782
783 c = out = unlang_edit_to_generic(edit);
785 c->name = cf_pair_attr(cp);
786 c->debug_name = c->name;
787 c->ci = CF_TO_ITEM(cp);
788
789 map_list_init(&edit->maps);
790
791 op = cf_pair_operator(cp);
792 if ((op == T_OP_CMP_TRUE) || (op == T_OP_CMP_FALSE)) {
793 cf_log_err(cp, "Invalid operator \"%s\".",
794 fr_table_str_by_value(fr_tokens_table, op, "<INVALID>"));
795 fail:
796 talloc_free(edit);
797 return NULL;
798 }
799
800 /*
801 * Convert this particular map.
802 */
803 if (map_afrom_cp(edit, &map, map_list_tail(&edit->maps), cp, &t_rules, NULL, true) < 0) {
804 goto fail;
805 }
806
807 /*
808 * @todo - we still want to do fixups on the RHS?
809 */
810 if (tmpl_is_attr(map->lhs)) {
811 /*
812 * Can't assign to [*] or [#]
813 */
814 num = tmpl_attr_tail_num(map->lhs);
815 if ((num == NUM_ALL) || (num == NUM_COUNT)) {
816 cf_log_err(cp, "Invalid array reference in %s", map->lhs->name);
817 goto fail;
818 }
819
820 if ((map->op == T_OP_SUB_EQ) && fr_type_is_structural(tmpl_attr_tail_da(map->lhs)->type) &&
821 tmpl_is_attr(map->rhs) && tmpl_attr_tail_da(map->rhs)->flags.local) {
822 cf_log_err(cp, "Cannot delete local variable %s", map->rhs->name);
823 goto fail;
824 }
825 }
826
827 /*
828 * Do basic sanity checks and resolving.
829 */
830 if (!pass2_fixup_map(map, unlang_ctx->rules, NULL)) goto fail;
831
832 /*
833 * Check operators, and ensure that the RHS has been
834 * resolved.
835 */
836 if (unlang_fixup_update(map, c) < 0) goto fail;
837
838 map_list_insert_tail(&edit->maps, map);
839
840 return out;
841}
842
843/** Compile a variable definition.
844 *
845 * Definitions which are adjacent to one another are automatically merged
846 * into one larger variable definition.
847 */
849{
852 char const *attr, *value;
853 unlang_group_t *group;
854
856
857 /*
858 * Enforce locations for local variables.
859 */
860 switch (parent->type) {
861 case UNLANG_TYPE_CASE:
862 case UNLANG_TYPE_ELSE:
866 case UNLANG_TYPE_IF:
874 break;
875
876 default:
877 cf_log_err(cp, "Local variables cannot be used here");
878 return -1;
879 }
880
881 /*
882 * The variables exist in the parent block.
883 */
885 if (group->variables) {
886 var = group->variables;
887
888 } else {
889 group->variables = var = talloc_zero(parent, unlang_variable_t);
890 if (!var) return -1;
891
892 var->dict = fr_dict_protocol_alloc(unlang_ctx->rules->attr.dict_def);
893 if (!var->dict) {
894 group->variables = NULL;
895 talloc_free(var);
896 return -1;
897 }
898 var->root = fr_dict_root(var->dict);
899
900 var->max_attr = 1;
901
902 /*
903 * Initialize the new rules, and point them to the parent rules.
904 *
905 * Then replace the parse rules with our rules, and our dictionary.
906 */
907 *t_rules = *unlang_ctx->rules;
908 t_rules->parent = unlang_ctx->rules;
909
910 t_rules->attr.dict_def = var->dict;
911 t_rules->attr.namespace = NULL;
912
913 unlang_ctx->rules = t_rules;
914 }
915
916 attr = cf_pair_attr(cp); /* data type */
917 value = cf_pair_value(cp); /* variable name */
918
920 if (type == FR_TYPE_NULL) {
922 cf_log_err(cp, "Invalid data type '%s'", attr);
923 return -1;
924 }
925
926 /*
927 * Leaf and group are OK. TLV, Vendor, Struct, VSA, etc. are not.
928 */
929 if (!(fr_type_is_leaf(type) || (type == FR_TYPE_GROUP))) goto invalid_type;
930
931 return unlang_define_local_variable(cf_pair_to_item(cp), var, t_rules, type, value, NULL);
932}
933
934/*
935 * Compile action && rcode for later use.
936 */
938{
939 int action;
940 char const *attr, *value;
941
942 attr = cf_pair_attr(cp);
943 value = cf_pair_value(cp);
944 if (!value) return true;
945
946 if (!strcasecmp(value, "return"))
947 action = MOD_ACTION_RETURN;
948
949 else if (!strcasecmp(value, "break"))
950 action = MOD_ACTION_RETURN;
951
952 else if (!strcasecmp(value, "reject"))
953 action = MOD_ACTION_REJECT;
954
955 else if (!strcasecmp(value, "retry"))
956 action = MOD_ACTION_RETRY;
957
958 else if (strspn(value, "0123456789") == strlen(value)) {
959 if (strlen(value) > 2) {
960 invalid_action:
961 cf_log_err(cp, "Priorities MUST be between 1 and 64.");
962 return false;
963 }
964
965 action = MOD_PRIORITY(atoi(value));
966
967 if (!MOD_ACTION_VALID_SET(action)) goto invalid_action;
968
969 } else {
970 cf_log_err(cp, "Unknown action '%s'.\n",
971 value);
972 return false;
973 }
974
975 if (strcasecmp(attr, "default") != 0) {
976 int rcode;
977
978 rcode = fr_table_value_by_str(mod_rcode_table, attr, -1);
979 if (rcode < 0) {
980 cf_log_err(cp,
981 "Unknown module rcode '%s'.",
982 attr);
983 return false;
984 }
985 actions->actions[rcode] = action;
986
987 } else { /* set all unset values to the default */
988 int i;
989
990 for (i = 0; i < RLM_MODULE_NUMCODES; i++) {
991 if (!actions->actions[i]) actions->actions[i] = action;
992 }
993 }
994
995 return true;
996}
997
999{
1000 CONF_ITEM *csi;
1001 CONF_SECTION *cs;
1002
1003 cs = cf_item_to_section(ci);
1004 for (csi=cf_item_next(cs, NULL);
1005 csi != NULL;
1006 csi=cf_item_next(cs, csi)) {
1007 CONF_PAIR *cp;
1008 char const *name, *value;
1009
1010 if (cf_item_is_section(csi)) {
1011 cf_log_err(csi, "Invalid subsection in 'retry' configuration.");
1012 return false;
1013 }
1014
1015 if (!cf_item_is_pair(csi)) continue;
1016
1017 cp = cf_item_to_pair(csi);
1018 name = cf_pair_attr(cp);
1019 value = cf_pair_value(cp);
1020
1021 if (!value) {
1022 cf_log_err(csi, "Retry configuration must specify a value");
1023 return false;
1024 }
1025
1026#define CLAMP(_name, _field, _limit) do { \
1027 if (!fr_time_delta_ispos(actions->retry._field)) { \
1028 cf_log_err(csi, "Invalid value for '" STRINGIFY(_name) " = %s' - value must be positive", \
1029 value); \
1030 return false; \
1031 } \
1032 if (fr_time_delta_cmp(actions->retry._field, fr_time_delta_from_sec(_limit)) > 0) { \
1033 cf_log_err(csi, "Invalid value for '" STRINGIFY(_name) " = %s' - value must be less than " STRINGIFY(_limit) "s", \
1034 value); \
1035 return false; \
1036 } \
1037 } while (0)
1038
1039 /*
1040 * We don't use conf_parser_t here for various
1041 * magical reasons.
1042 */
1043 if (strcmp(name, "initial_rtx_time") == 0) {
1044 if (fr_time_delta_from_str(&actions->retry.irt, value, strlen(value), FR_TIME_RES_SEC) < 0) {
1045 error:
1046 cf_log_err(csi, "Failed parsing '%s = %s' - %s",
1047 name, value, fr_strerror());
1048 return false;
1049 }
1050 CLAMP(initial_rtx_time, irt, 2);
1051
1052 } else if (strcmp(name, "max_rtx_time") == 0) {
1053 if (fr_time_delta_from_str(&actions->retry.mrt, value, strlen(value), FR_TIME_RES_SEC) < 0) goto error;
1054
1055 CLAMP(max_rtx_time, mrt, 10);
1056
1057 } else if (strcmp(name, "max_rtx_count") == 0) {
1058 char *end;
1059 unsigned long v = strtoul(value, &end, 10);
1060
1061 if (*end || (end == value) || (v > 10)) {
1062 cf_log_err(csi, "Invalid value for 'max_rtx_count = %s' - value must be between 0 and 10",
1063 value);
1064 return false;
1065 }
1066
1067 actions->retry.mrc = v;
1068
1069 } else if (strcmp(name, "max_rtx_duration") == 0) {
1070 if (fr_time_delta_from_str(&actions->retry.mrd, value, strlen(value), FR_TIME_RES_SEC) < 0) goto error;
1071
1072 CLAMP(max_rtx_duration, mrd, 20);
1073
1074 } else {
1075 cf_log_err(csi, "Invalid item '%s' in 'retry' configuration.", name);
1076 return false;
1077 }
1078 }
1079
1080 return true;
1081}
1082
1083bool unlang_compile_actions(unlang_mod_actions_t *actions, CONF_SECTION *cs, bool module_retry)
1084{
1085 int i;
1086 bool disallow_retry_action = false;
1087 CONF_ITEM *csi;
1088
1089 /*
1090 * Over-ride the default return codes of the module.
1091 */
1092 for (csi=cf_item_next(cs, NULL);
1093 csi != NULL;
1094 csi=cf_item_next(cs, csi)) {
1095 char const *name;
1096 CONF_PAIR *cp;
1097
1098 if (cf_item_is_section(csi)) {
1099 CONF_SECTION *subcs = cf_item_to_section(csi);
1100
1101 name = cf_section_name1(subcs);
1102
1103 /*
1104 * Look for a "retry" section.
1105 */
1106 if (name && (strcmp(name, "retry") == 0) && !cf_section_name2(subcs)) {
1107 if (!compile_retry_section(actions, csi)) return false;
1108 continue;
1109 }
1110
1111 cf_log_err(csi, "Invalid subsection. Expected 'action = value'");
1112 return false;
1113 }
1114
1115 if (!cf_item_is_pair(csi)) continue;
1116
1117 cp = cf_item_to_pair(csi);
1118
1119 /*
1120 * Allow 'retry = path.to.retry.config'
1121 */
1122 name = cf_pair_attr(cp);
1123 if (strcmp(name, "retry") == 0) {
1124 CONF_ITEM *subci;
1125 char const *value = cf_pair_value(cp);
1126
1127 if (!value) {
1128 cf_log_err(csi, "Missing reference string");
1129 return false;
1130 }
1131
1133 if (!subci) {
1134 cf_log_perr(csi, "Failed finding reference '%s'", value);
1135 return false;
1136 }
1137
1138 if (!compile_retry_section(actions, subci)) return false;
1139 continue;
1140 }
1141
1142 if (!compile_action_pair(actions, cp)) {
1143 return false;
1144 }
1145 }
1146
1147 if (module_retry) {
1148 if (!fr_time_delta_ispos(actions->retry.irt)) {
1149 cf_log_err(cs, "initial_rtx_time MUST be non-zero for modules which support retries.");
1150 return false;
1151 }
1152 } else {
1153 if (fr_time_delta_ispos(actions->retry.irt)) {
1154 cf_log_err(cs, "initial_rtx_time MUST be zero, as only max_rtx_count and max_rtx_duration are used.");
1155 return false;
1156 }
1157
1158 if (!actions->retry.mrc && !fr_time_delta_ispos(actions->retry.mrd)) {
1159 disallow_retry_action = true;
1160 }
1161 }
1162
1163 /*
1164 * Sanity check that "fail = retry", we actually have a
1165 * retry section.
1166 */
1167 for (i = 0; i < RLM_MODULE_NUMCODES; i++) {
1168 if (actions->actions[i] != MOD_ACTION_RETRY) continue;
1169
1170 if (module_retry) {
1171 cf_log_err(cs, "Cannot use a '%s = retry' action for a module which has its own retries",
1172 fr_table_str_by_value(mod_rcode_table, i, "<INVALID>"));
1173 return false;
1174 }
1175
1176 if (disallow_retry_action) {
1177 cf_log_err(cs, "max_rtx_count and max_rtx_duration cannot both be zero when using '%s = retry'",
1178 fr_table_str_by_value(mod_rcode_table, i, "<INVALID>"));
1179 return false;
1180 }
1181
1182 if (!fr_time_delta_ispos(actions->retry.irt) &&
1183 !actions->retry.mrc &&
1184 !fr_time_delta_ispos(actions->retry.mrd)) {
1185 cf_log_err(cs, "Cannot use a '%s = retry' action without a 'retry { ... }' section.",
1186 fr_table_str_by_value(mod_rcode_table, i, "<INVALID>"));
1187 return false;
1188 }
1189 }
1190
1191 return true;
1192}
1193
1195{
1196 unlang_group_t *g;
1197 unlang_t *c;
1198
1199 /*
1200 * If we're compiling an empty section, then the
1201 * *interpreter* type is GROUP, even if the *debug names*
1202 * are something else.
1203 */
1205 if (!g) return NULL;
1206
1208 if (!cs) {
1209 c->name = unlang_ops[type].name;
1210 c->debug_name = c->name;
1211
1212 } else {
1213 char const *name2;
1214
1215 name2 = cf_section_name2(cs);
1216 if (!name2) {
1217 c->name = cf_section_name1(cs);
1218 c->debug_name = c->name;
1219 } else {
1220 c->name = name2;
1221 c->debug_name = talloc_typed_asprintf(c, "%s %s", cf_section_name1(cs), name2);
1222 }
1223 }
1224
1225 return c;
1226}
1227
1228
1230
1231/*
1232 * compile 'actions { ... }' inside of another group.
1233 */
1235{
1236 CONF_ITEM *ci, *next;
1237
1238 ci = cf_section_to_item(subcs);
1239
1240 next = cf_item_next(cs, ci);
1241 if (next && (cf_item_is_pair(next) || cf_item_is_section(next))) {
1242 cf_log_err(ci, "'actions' MUST be the last block in a section");
1243 return false;
1244 }
1245
1246 if (cf_section_name2(subcs) != NULL) {
1247 cf_log_err(ci, "Invalid name for 'actions' section");
1248 return false;
1249 }
1250
1251 /*
1252 * Over-riding the actions can be done in certain limited
1253 * situations. In other situations (e.g. "redundant",
1254 * "load-balance"), it doesn't make sense.
1255 *
1256 * Note that this limitation also applies to "retry"
1257 * timers. We can do retries of a "group". We cannot do
1258 * retries of "load-balance", as the "load-balance"
1259 * section already takes care of redundancy.
1260 *
1261 * We may need to loosen that limitation in the future.
1262 */
1263 switch (c->type) {
1264 case UNLANG_TYPE_CASE:
1265 case UNLANG_TYPE_CATCH:
1266 case UNLANG_TYPE_IF:
1267 case UNLANG_TYPE_ELSE:
1268 case UNLANG_TYPE_ELSIF:
1270 case UNLANG_TYPE_GROUP:
1271 case UNLANG_TYPE_LIMIT:
1272 case UNLANG_TYPE_SWITCH:
1275 break;
1276
1277 default:
1278 cf_log_err(ci, "'actions' MUST NOT be in a '%s' block", unlang_ops[c->type].name);
1279 return false;
1280 }
1281
1282 return unlang_compile_actions(&c->actions, subcs, false);
1283}
1284
1285
1287{
1288 CONF_ITEM *ci = NULL;
1289 unlang_t *c, *single;
1290 bool was_if = false;
1291 char const *skip_else = NULL;
1293 unlang_compile_ctx_t unlang_ctx2;
1294 tmpl_rules_t t_rules, t2_rules; /* yes, it does */
1295
1297
1298 /*
1299 * Create our own compilation context which can be edited
1300 * by a variable definition.
1301 */
1302 unlang_compile_ctx_copy(&unlang_ctx2, unlang_ctx_in);
1303 t2_rules = *(unlang_ctx_in->rules);
1304
1305 unlang_ctx = &unlang_ctx2;
1306 unlang_ctx2.rules = &t2_rules;
1307
1308 t_rules = *unlang_ctx_in->rules;
1309
1310 /*
1311 * Loop over the children of this group.
1312 */
1313 while ((ci = cf_item_next(g->cs, ci))) {
1314 if (cf_item_is_data(ci)) continue;
1315
1316 t_rules.attr.ci = ci;
1317 t2_rules.attr.ci = ci;
1318
1319 /*
1320 * Sections are keywords, or references to
1321 * modules with updated return codes.
1322 */
1323 if (cf_item_is_section(ci)) {
1324 char const *name = NULL;
1325 CONF_SECTION *subcs = cf_item_to_section(ci);
1326
1327 /*
1328 * Skip precompiled blocks. This is
1329 * mainly for policies.
1330 */
1331 if (cf_data_find(subcs, unlang_group_t, NULL)) continue;
1332
1333 /*
1334 * "actions" apply to the current group.
1335 * It's not a subgroup.
1336 */
1337 name = cf_section_name1(subcs);
1338
1339 /*
1340 * In-line attribute editing. Nothing else in the parse has list assignments, so this must be it.
1341 */
1343 single = compile_edit_section(c, unlang_ctx, subcs);
1344 if (!single) {
1345 fail:
1346 talloc_free(c);
1347 return NULL;
1348 }
1349
1350 goto add_child;
1351 }
1352
1353 if (strcmp(name, "actions") == 0) {
1354 if (!compile_action_subsection(c, g->cs, subcs)) goto fail;
1355 continue;
1356 }
1357
1358 /*
1359 * Special checks for "else" and "elsif".
1360 */
1361 if ((strcmp(name, "else") == 0) || (strcmp(name, "elsif") == 0)) {
1362 /*
1363 * We ran into one without a preceding "if" or "elsif".
1364 * That's not allowed.
1365 */
1366 if (!was_if) {
1367 cf_log_err(ci, "Invalid location for '%s'. There is no preceding "
1368 "'if' or 'elsif' statement", name);
1369 goto fail;
1370 }
1371
1372 /*
1373 * There was a previous "if" or "elsif" which was always taken.
1374 * So we skip this "elsif" or "else".
1375 */
1376 if (skip_else) {
1377 void *ptr;
1378
1379 /*
1380 * And manually free this.
1381 */
1382 ptr = cf_data_remove(subcs, xlat_exp_head_t, NULL);
1383 talloc_free(ptr);
1384
1386
1387 cf_log_debug_prefix(ci, "Skipping contents of '%s' due to previous "
1388 "'%s' always being taken.",
1389 name, skip_else);
1390 continue;
1391 }
1392 }
1393
1394 /*
1395 * Otherwise it's a real keyword.
1396 */
1397 single = compile_item(c, unlang_ctx, ci);
1398 if (!single) {
1399 cf_log_err(ci, "Failed to parse \"%s\" subsection", cf_section_name1(subcs));
1400 goto fail;
1401 }
1402
1403 goto add_child;
1404
1405 } else if (cf_item_is_pair(ci)) {
1406 CONF_PAIR *cp = cf_item_to_pair(ci);
1407
1408 /*
1409 * Variable definition.
1410 */
1411 if (cf_pair_operator(cp) == T_OP_CMP_TRUE) {
1412 if (compile_variable(c, unlang_ctx, cp, &t_rules) < 0) goto fail;
1413
1414 single = UNLANG_IGNORE;
1415 goto add_child;
1416 }
1417
1418 if (!cf_pair_value(cp)) {
1419 single = compile_item(c, unlang_ctx, ci);
1420 if (!single) {
1421 cf_log_err(ci, "Invalid keyword \"%s\".", cf_pair_attr(cp));
1422 goto fail;
1423 }
1424
1425 goto add_child;
1426 }
1427
1428 /*
1429 * What remains MUST be an edit pair. At this point, the state of the compiler
1430 * tells us what it is, and we don't really care if there's a leading '&'.
1431 */
1432 single = compile_edit_pair(c, unlang_ctx, cp);
1433 if (!single) goto fail;
1434
1435 goto add_child;
1436 } else {
1437 cf_log_err(ci, "Asked to compile unknown conf type");
1438 goto fail;
1439 }
1440
1441 add_child:
1442 if (single == UNLANG_IGNORE) continue;
1443
1444 /*
1445 * Do optimizations for "if" and "elsif"
1446 * conditions.
1447 */
1448 switch (single->type) {
1449 case UNLANG_TYPE_ELSIF:
1450 case UNLANG_TYPE_IF:
1451 was_if = true;
1452
1453 {
1454 unlang_group_t *f;
1455 unlang_cond_t *gext;
1456
1457 /*
1458 * Skip else, and/or omit things which will never be run.
1459 */
1460 f = unlang_generic_to_group(single);
1461 gext = unlang_group_to_cond(f);
1462
1463 if (gext->is_truthy) {
1464 if (gext->value) {
1465 skip_else = single->debug_name;
1466 } else {
1467 /*
1468 * If this came from compile_single, then it will already
1469 * have a number and be in the tree.
1470 */
1471 if (single->number) fr_rb_remove(unlang_instruction_tree, single);
1472
1473 /*
1474 * The condition never
1475 * matches, so we can
1476 * avoid putting it into
1477 * the unlang tree.
1478 */
1479 talloc_free(single);
1480 continue;
1481 }
1482 }
1483 }
1484 break;
1485
1486 default:
1487 was_if = false;
1488 skip_else = NULL;
1489 break;
1490 }
1491
1492 /*
1493 * unlang_group_t is grown by adding a unlang_t to the end
1494 */
1495 fr_assert(g == talloc_parent(single));
1497 unlang_list_insert_tail(&g->children, single);
1498 single->list = &g->children;
1499
1500 /*
1501 * If it's not possible to execute statement
1502 * after the current one, then just stop
1503 * processing the children.
1504 */
1505 if (g->self.closed) {
1506 cf_log_warn(ci, "Skipping remaining instructions due to '%s'",
1507 single->name);
1508 break;
1509 }
1510 }
1511
1512 return c;
1513}
1514
1515
1516/*
1517 * Generic "compile a section with more unlang inside of it".
1518 */
1520{
1521 unlang_group_t *g;
1522 unlang_t *c;
1523 char const *name1, *name2;
1524
1525 fr_assert(unlang_ctx->rules != NULL);
1526 fr_assert(unlang_ctx->rules->attr.list_def);
1527
1528 /*
1529 * We always create a group, even if the section is empty.
1530 */
1532 if (!g) return NULL;
1533
1535
1536 /*
1537 * Remember the name for printing, etc.
1538 */
1539 name1 = cf_section_name1(cs);
1540 name2 = cf_section_name2(cs);
1541 c->name = name1;
1542
1543 /*
1544 * Make sure to tell the user that we're running a
1545 * policy, and not anything else.
1546 */
1547 if (type == UNLANG_TYPE_POLICY) {
1548 MEM(c->debug_name = talloc_typed_asprintf(c, "policy %s", name1));
1549
1550 } else if (!name2) {
1551 c->debug_name = c->name;
1552
1553 } else {
1554 MEM(c->debug_name = talloc_typed_asprintf(c, "%s %s", name1, name2));
1555 }
1556
1558}
1559
1560
1562{
1563 CONF_PAIR *cp = cf_item_to_pair(ci);
1564 unlang_t *c;
1565 unlang_tmpl_t *ut;
1566 ssize_t slen;
1567 char const *p = cf_pair_attr(cp);
1568 tmpl_t *vpt;
1569
1570 MEM(ut = talloc_zero(parent, unlang_tmpl_t));
1571 c = unlang_tmpl_to_generic(ut);
1573 c->name = p;
1574 c->debug_name = c->name;
1575 c->ci = CF_TO_ITEM(cp);
1576
1577 RULES_VERIFY(unlang_ctx->rules);
1578 slen = tmpl_afrom_substr(ut, &vpt,
1579 &FR_SBUFF_IN(p, talloc_strlen(p)),
1581 NULL,
1582 unlang_ctx->rules);
1583 if (!vpt) {
1584 cf_canonicalize_error(cp, slen, "Failed parsing expansion", p);
1585 talloc_free(ut);
1586 return NULL;
1587 }
1588 ut->tmpl = vpt; /* const issues */
1589
1590 return c;
1591}
1592
1593/*
1594 * redundant, load-balance and parallel have limits on what can
1595 * go in them.
1596 */
1598{
1599 CONF_ITEM *ci;
1600
1601 for (ci=cf_item_next(cs, NULL);
1602 ci != NULL;
1603 ci=cf_item_next(cs, ci)) {
1604 /*
1605 * If we're a redundant, etc. group, then the
1606 * intention is to call modules, rather than
1607 * processing logic. These checks aren't
1608 * *strictly* necessary, but they keep the users
1609 * from doing crazy things.
1610 */
1611 if (cf_item_is_section(ci)) {
1612 CONF_SECTION *subcs = cf_item_to_section(ci);
1613 char const *name1 = cf_section_name1(subcs);
1614
1615 /*
1616 * Allow almost anything except "else"
1617 * statements. The normal processing
1618 * falls through from "if" to "else", and
1619 * we can't do that for redundant and
1620 * load-balance sections.
1621 */
1622 if ((strcmp(name1, "else") == 0) ||
1623 (strcmp(name1, "elsif") == 0)) {
1624 cf_log_err(ci, "%s sections cannot contain a \"%s\" statement",
1625 name, name1);
1626 return false;
1627 }
1628 continue;
1629 }
1630
1631 if (cf_item_is_pair(ci)) {
1632 CONF_PAIR *cp = cf_item_to_pair(ci);
1633
1634 if (cf_pair_operator(cp) == T_OP_CMP_TRUE) continue;
1635
1636 if (cf_pair_value(cp) != NULL) {
1637 cf_log_err(cp, "Unknown keyword '%s', or invalid location", cf_pair_attr(cp));
1638 return false;
1639 }
1640 }
1641 }
1642
1643 return true;
1644}
1645
1646
1648 CONF_SECTION *subcs,
1649 bool policy)
1650{
1651 unlang_compile_ctx_t unlang_ctx2;
1652 unlang_t *c;
1653
1655
1656 /*
1657 * module.c takes care of ensuring that this is:
1658 *
1659 * group foo { ...
1660 * load-balance foo { ...
1661 * redundant foo { ...
1662 * redundant-load-balance foo { ...
1663 *
1664 * We can just recurse to compile the section as
1665 * if it was found here.
1666 */
1667 if (cf_section_name2(subcs)) {
1668 if (policy) {
1669 cf_log_err(subcs, "Unexpected second name in policy");
1670 return NULL;
1671 }
1672
1673 c = compile_item(parent, &unlang_ctx2, cf_section_to_item(subcs));
1674
1675 } else {
1676 /*
1677 * We have:
1678 *
1679 * foo { ...
1680 *
1681 * So we compile it like it was:
1682 *
1683 * group foo { ...
1684 */
1685 c = unlang_compile_section(parent, &unlang_ctx2, subcs,
1687 }
1688 if (!c) return NULL;
1690
1691 /*
1692 * Return the compiled thing if we can.
1693 */
1694 if (!cf_item_is_section(ci)) return c;
1695
1696 /*
1697 * Else we have a reference to a policy, and that reference
1698 * over-rides the return codes for the policy!
1699 */
1700 if (!unlang_compile_actions(&c->actions, cf_item_to_section(ci), false)) {
1701 talloc_free(c);
1702 return NULL;
1703 }
1704
1705 return c;
1706}
1707
1708/** Load a named module from the virtual module list, or from the "policy" subsection.
1709 *
1710 * If it's "foo.method", look for "foo", and return "method" as the method
1711 * we wish to use, instead of the input component.
1712 *
1713 * @param[in] ci Configuration item to check
1714 * @param[in] real_name Complete name string e.g. foo.authorize.
1715 * @param[in] virtual_name Virtual module name e.g. foo.
1716 * @param[in] method_name Method override (may be NULL) or the method
1717 * name e.g. authorize.
1718 * @param[in] unlang_ctx Unlang context this call is being compiled in.
1719 * @param[out] policy whether or not this thing was a policy
1720 * @return the CONF_SECTION specifying the virtual module.
1721 */
1722static CONF_SECTION *virtual_module_find_cs(CONF_ITEM *ci, UNUSED char const *real_name, char const *virtual_name,
1723 char const *method_name, unlang_compile_ctx_t *unlang_ctx, bool *policy)
1724{
1725 CONF_SECTION *cs, *subcs, *conf_root;
1726 CONF_ITEM *loop;
1727 char buffer[256];
1728
1729 *policy = false;
1730 conf_root = cf_root(ci);
1731
1732 /*
1733 * Look for "foo" as a virtual server. If we find it,
1734 * AND there's no method name, we've found the right
1735 * thing.
1736 *
1737 * Found "foo". Load it as "foo", or "foo.method".
1738 *
1739 * Return it to the caller, with the updated method.
1740 */
1741 subcs = module_rlm_virtual_by_name(virtual_name);
1742 if (subcs) goto check_for_loop;
1743
1744 /*
1745 * Look for it in "policy".
1746 *
1747 * If there's no policy section, we can't do anything else.
1748 */
1749 cs = cf_section_find(conf_root, "policy", NULL);
1750 if (!cs) return NULL;
1751
1752 *policy = true;
1753
1754 /*
1755 * "foo.authorize" means "load policy 'foo.authorize' or 'foo'"
1756 * as method "authorize".
1757 *
1758 * And bail out if there's no policy "foo.authorize" or "foo".
1759 */
1760 if (method_name) {
1761 snprintf(buffer, sizeof(buffer), "%s.%s", virtual_name, method_name);
1762 subcs = cf_section_find(cs, buffer, NULL);
1763 if (!subcs) subcs = cf_section_find(cs, virtual_name, NULL);
1764 if (!subcs) return NULL;
1765
1766 goto check_for_loop;
1767 }
1768
1769 /*
1770 * "foo" means "look for foo.name1.name2" first, to allow
1771 * method overrides. If that's not found, look for
1772 * "foo.name1" and if that's not found just look for
1773 * a policy "foo".
1774 */
1775 if (unlang_ctx->section_name2) {
1776 snprintf(buffer, sizeof(buffer), "%s.%s.%s", virtual_name, unlang_ctx->section_name1, unlang_ctx->section_name2);
1777 subcs = cf_section_find(cs, buffer, NULL);
1778 } else {
1779 subcs = NULL;
1780 }
1781
1782 if (!subcs) {
1783 snprintf(buffer, sizeof(buffer), "%s.%s", virtual_name, unlang_ctx->section_name1);
1784 subcs = cf_section_find(cs, buffer, NULL);
1785 }
1786
1787 if (!subcs) subcs = cf_section_find(cs, virtual_name, NULL);
1788 if (!subcs) return NULL;
1789
1790check_for_loop:
1791 /*
1792 * Check that we're not creating a loop. We may
1793 * be compiling an "sql" module reference inside
1794 * of an "sql" policy. If so, we allow the
1795 * second "sql" to refer to the module.
1796 */
1797 for (loop = cf_parent(ci);
1798 loop && subcs;
1799 loop = cf_parent(loop)) {
1800 if (loop == cf_section_to_item(subcs)) {
1801 return NULL;
1802 }
1803 }
1804
1805 return subcs;
1806}
1807
1809{
1810 unlang_t *c;
1811 unlang_module_t *m;
1812 fr_slen_t slen;
1813
1814 MEM(m = talloc_zero(parent, unlang_module_t));
1815 slen = module_rlm_by_name_and_method(m, &m->mmc,
1816 unlang_ctx->vs,
1817 &(section_name_t){ .name1 = unlang_ctx->section_name1, .name2 = unlang_ctx->section_name2 },
1819 unlang_ctx->rules);
1820 if (slen < 0) {
1821 cf_log_perr(ci, "Failed compiling module call");
1822 talloc_free(m);
1823 return NULL;
1824 }
1825
1826 /*
1827 * We parsed a string, but we were told to ignore it. Don't do anything.
1828 */
1829 if (!m->mmc.rlm) return UNLANG_IGNORE;
1830
1831 if (m->mmc.rlm->common.dict &&
1832 !fr_dict_compatible(*m->mmc.rlm->common.dict, unlang_ctx->rules->attr.dict_def)) {
1833 cf_log_err(ci, "The '%s' module can only be used within a '%s' namespace.",
1834 m->mmc.rlm->common.name, fr_dict_root(*m->mmc.rlm->common.dict)->name);
1835 cf_log_err(ci, "Please use the 'subrequest' keyword to change namespaces");
1836 cf_log_err(ci, DOC_KEYWORD_REF(subrequest));
1837 talloc_free(m);
1838 return NULL;
1839 }
1840
1843 c->name = talloc_strdup(c, name);
1844 c->debug_name = c->name;
1845 c->ci = ci;
1846
1847 /*
1848 * Set the default actions for this module.
1849 */
1850 c->actions = m->mmc.mi->actions;
1851
1852 /*
1853 * Parse the method environment for this module / method
1854 */
1855 if (m->mmc.mmb.method_env) {
1857
1858 fr_assert_msg(method_env->inst_size, "Method environment for module %s, method %s %s declared, "
1859 "but no inst_size set",
1860 m->mmc.mi->name, unlang_ctx->section_name1, unlang_ctx->section_name2);
1861
1862 if (!unlang_ctx->rules) {
1863 cf_log_err(ci, "Failed compiling %s - no rules", m->mmc.mi->name);
1864 goto error;
1865 }
1867 unlang_ctx->rules, m->mmc.mi->conf,
1868 &(call_env_ctx_t){
1869 .type = CALL_ENV_CTX_TYPE_MODULE,
1870 .mi = m->mmc.mi,
1871 .asked = &m->mmc.asked
1872 });
1873 if (!m->call_env) {
1874 error:
1875 talloc_free(m);
1876 return NULL;
1877 }
1878 }
1879
1880 /*
1881 * If a module reference is a section, then the section
1882 * should contain action over-rides. We add those here.
1883 */
1884 if (cf_item_is_section(ci) &&
1886 (m->mmc.mi->exported->flags & MODULE_TYPE_RETRY) != 0)) goto error;
1887
1888 return c;
1889}
1890
1891extern int dict_attr_acopy_children(fr_dict_t *dict, fr_dict_attr_t *dst, fr_dict_attr_t const *src);
1892
1893#define name_to_op(name) fr_hash_table_find(unlang_op_table, &(unlang_op_t) { .name = name })
1894
1896 fr_dict_attr_t const *ref)
1897{
1898 fr_dict_attr_t const *da;
1899 fr_slen_t len;
1900 unlang_op_t const *op;
1901
1902 fr_dict_attr_flags_t flags = {
1903 .internal = true,
1904 .local = true,
1905 };
1906
1907 /*
1908 * No overlap with list names.
1909 */
1911 fail_list:
1912 cf_log_err(ci, "Local variable '%s' cannot be a list reference.", name);
1913 return -1;
1914 }
1915
1916 len = strlen(name);
1917 if (tmpl_attr_list_from_substr(&da, &FR_SBUFF_IN(name, len)) == len) goto fail_list;
1918
1919 /*
1920 * No keyword section names.
1921 */
1922 op = name_to_op(name);
1923 if (op) {
1924 cf_log_err(ci, "Local variable '%s' cannot be an unlang keyword.", name);
1925 return -1;
1926 }
1927
1928 /*
1929 * No protocol names.
1930 */
1931 if (fr_dict_by_protocol_name(name) != NULL) {
1932 cf_log_err(ci, "Local variable '%s' cannot be an existing protocol name.", name);
1933 return -1;
1934 }
1935
1936 /*
1937 * No overlap with attributes in the current dictionary. The lookup in var->root will also check
1938 * the current dictionary, so the check here is really only for better error messages.
1939 */
1940 if (t_rules && t_rules->parent && t_rules->parent->attr.dict_def) {
1941 da = fr_dict_attr_by_name(NULL, fr_dict_root(t_rules->parent->attr.dict_def), name);
1942 if (da) {
1943 cf_log_err(ci, "Local variable '%s' duplicates a dictionary attribute.", name);
1944 return -1;
1945 }
1946 }
1947
1948 /*
1949 * No data types.
1950 */
1952 cf_log_err(ci, "Invalid variable name '%s'.", name);
1953 return -1;
1954 }
1955
1956 /*
1957 * No dups of local variables.
1958 */
1959 da = fr_dict_attr_by_name(NULL, var->root, name);
1960 if (da) {
1961 cf_log_err(ci, "Duplicate variable name '%s'.", name);
1962 return -1;
1963 }
1964
1965 if (fr_dict_attr_add(var->dict, var->root, name, var->max_attr, type, &flags) < 0) {
1966 fail:
1967 cf_log_err(ci, "Failed adding variable '%s' - %s", name, fr_strerror());
1968 return -1;
1969 }
1970 da = fr_dict_attr_by_name(NULL, var->root, name);
1971 fr_assert(da != NULL);
1972
1973 /*
1974 * Copy the children over.
1975 */
1976 var->max_attr++;
1978 fr_fatal_assert(ref != NULL);
1979
1980 if (fr_dict_attr_acopy_local(da, ref) < 0) goto fail;
1981 }
1982
1983
1984 return 0;
1985}
1986
1987/*
1988 * Compile one unlang instruction
1989 */
1991{
1992 char const *name, *p;
1993 CONF_SECTION *cs, *subcs, *modules;
1994 unlang_compile_ctx_t unlang_ctx2;
1995 bool policy;
1996 unlang_t *c;
1997 unlang_op_t const *op;
1998
1999 if (cf_item_is_section(ci)) {
2000 cs = cf_item_to_section(ci);
2001 name = cf_section_name1(cs);
2002 op = name_to_op(name);
2003
2004 if (op) {
2005 /*
2006 * Forbid pair keywords as section names,
2007 * e.g. "break { ... }"
2008 */
2009 if ((op->flag & UNLANG_OP_FLAG_SINGLE_WORD) != 0) {
2010 cf_log_err(ci, "Syntax error after keyword '%s' - unexpected '{'", name);
2011 return NULL;
2012 }
2013
2014 c = op->compile(parent, unlang_ctx, ci);
2015 goto allocate_number;
2016 }
2017
2018 /* else it's something like sql { fail = 1 ...} */
2019 goto check_for_module;
2020
2021 } else if (cf_item_is_pair(ci)) {
2022
2023 /*
2024 * Else it's a module reference such as "sql", OR
2025 * one of the few bare keywords that we allow.
2026 */
2027 CONF_PAIR *cp = cf_item_to_pair(ci);
2028
2029 /*
2030 * We cannot have assignments or actions here.
2031 */
2032 if (cf_pair_value(cp) != NULL) {
2033 cf_log_err(ci, "Invalid assignment");
2034 return NULL;
2035 }
2036
2037 name = cf_pair_attr(cp);
2038 op = name_to_op(name);
2039
2040 if (op) {
2041 /*
2042 * Forbid section keywords as pair names, e.g. "switch = foo"
2043 */
2044 if ((op->flag & UNLANG_OP_FLAG_SINGLE_WORD) == 0) {
2045 cf_log_err(ci, "Syntax error after keyword '%s' - missing '{'", name);
2046 return NULL;
2047 }
2048
2049 c = op->compile(parent, unlang_ctx, ci);
2050 goto allocate_number;
2051 }
2052
2053 /*
2054 * In-place expansions.
2055 *
2056 * @todo - allow only function calls, not %{...}
2057 *
2058 * @todo don't create a tmpl. Instead, create an
2059 * xlat. This functionality is needed for the in-place language functions via
2060 *
2061 * language {{{
2062 * ...
2063 * }}}
2064 */
2065 if (name[0] == '%') {
2067 goto allocate_number;
2068 }
2069
2070 goto check_for_module;
2071
2072 } else {
2073 cf_log_err(ci, "Asked to compile unknown configuration item");
2074 return NULL; /* who knows what it is... */
2075 }
2076
2077check_for_module:
2078 /*
2079 * We now have a name. It can be one of two forms. A
2080 * bare module name, or a section named for the module,
2081 * with over-rides for the return codes.
2082 *
2083 * The name can refer to a real module, in the "modules"
2084 * section. In that case, the name will be either the
2085 * first or second name of the sub-section of "modules".
2086 *
2087 * Or, the name can refer to a policy, in the "policy"
2088 * section. In that case, the name will be first of the
2089 * sub-section of "policy".
2090 *
2091 * Or, the name can refer to a "module.method", in which
2092 * case we're calling a different method than normal for
2093 * this section.
2094 *
2095 * Or, the name can refer to a virtual module, in the
2096 * "modules" section. In that case, the name will be
2097 * name2 of the CONF_SECTION.
2098 *
2099 * We try these in sequence, from the bottom up. This is
2100 * so that virtual modules and things in "policy" can
2101 * over-ride calls to real modules.
2102 */
2103
2104
2105 /*
2106 * Try:
2107 *
2108 * policy { ... name { .. } .. }
2109 * policy { ... name.method { .. } .. }
2110 */
2111 p = strrchr(name, '.');
2112 if (!p) {
2113 subcs = virtual_module_find_cs(ci, name, name, NULL, unlang_ctx, &policy);
2114 } else {
2115 char buffer[256];
2116
2117 strlcpy(buffer, name, sizeof(buffer));
2118 buffer[p - name] = '\0';
2119
2120 subcs = virtual_module_find_cs(ci, name,
2121 buffer, buffer + (p - name) + 1, unlang_ctx, &policy);
2122 }
2123
2124 /*
2125 * We've found the thing which defines this "function".
2126 * It MUST be a sub-section.
2127 *
2128 * i.e. it refers to a a subsection in "policy".
2129 */
2130 if (subcs) {
2131 c = compile_function(parent, unlang_ctx, ci, subcs, policy);
2132 goto allocate_number;
2133 }
2134
2135 /*
2136 * Not a function. It must be a real module.
2137 */
2138 modules = cf_section_find(cf_root(ci), "modules", NULL);
2139 if (!modules) {
2140 cf_log_err(ci, "Failed compiling \"%s\" as a module or policy as no modules are enabled", name);
2141 cf_log_err(ci, "Please verify that modules { ... } section is present in the server configuration");
2142 return NULL;
2143 }
2144
2145 /*
2146 * Set the child compilation context BEFORE parsing the
2147 * module name and method. The lookup function will take
2148 * care of returning the appropriate component, name1,
2149 * name2, etc.
2150 */
2152 c = compile_module(parent, &unlang_ctx2, ci, name);
2153
2154allocate_number:
2155 if (!c) return NULL;
2156 if (c == UNLANG_IGNORE) return UNLANG_IGNORE;
2157
2158 /*
2159 * Some compilation paths already go through this path
2160 * and will have assigned a number.
2161 */
2162 if (c->number) return c;
2163
2164 c->number = unlang_number++;
2166
2168 cf_log_err(ci, "Instruction \"%s\" number %u has conflict with previous one.",
2169 c->debug_name, c->number);
2170 talloc_free(c);
2171 return NULL;
2172 }
2173
2174 return c;
2175}
2176
2177/** Compile an unlang section for a virtual server
2178 *
2179 * @param[in] vs Virtual server to compile section for.
2180 * @param[in] cs containing the unlang calls to compile.
2181 * @param[in] actions Actions to use for the unlang section.
2182 * @param[in] rules Rules to use for the unlang section.
2183 * @param[out] instruction Pointer to store the compiled unlang section.
2184 * @return
2185 * - 0 on success.
2186 * - -1 on error.
2187 */
2189 CONF_SECTION *cs, unlang_mod_actions_t const *actions, tmpl_rules_t const *rules, void **instruction)
2190{
2191 unlang_t *c;
2192 char const *name1, *name2;
2193 CONF_DATA const *cd;
2194
2195 /*
2196 * Don't compile it twice, and don't print out debug
2197 * messages twice.
2198 */
2199 cd = cf_data_find(cs, unlang_group_t, NULL);
2200 if (cd) {
2201 if (instruction) *instruction = cf_data_value(cd);
2202 return 1;
2203 }
2204
2205 /*
2206 * Ensure that all compile functions get valid rules.
2207 */
2208 if (!rules) {
2209 cf_log_err(cs, "Failed compiling section - no namespace rules passed");
2210 return -1;
2211 }
2212
2213 name1 = cf_section_name1(cs);
2214 name2 = cf_section_name2(cs);
2215
2216 if (!name2) name2 = "";
2217
2218 cf_log_debug(cs, "Compiling policies in - %s %s {...}", name1, name2);
2219
2220 c = unlang_compile_section(NULL,
2222 .vs = vs,
2223 .section_name1 = cf_section_name1(cs),
2224 .section_name2 = cf_section_name2(cs),
2225 .actions = *actions,
2226 .rules = rules
2227 },
2228 cs, UNLANG_TYPE_GROUP);
2229 if (!c) return -1;
2230
2232
2233 if (DEBUG_ENABLED4) unlang_dump(c, 2);
2234
2235 /*
2236 * Associate the unlang with the configuration section,
2237 * and free the unlang code when the configuration
2238 * section is freed.
2239 */
2240 cf_data_add(cs, c, NULL, true);
2242 if (instruction) *instruction = c;
2243
2244 return 0;
2245}
2246
2247
2248/** Check if name is an unlang keyword
2249 *
2250 * @param[in] name to check.
2251 * @return
2252 * - true if it is a keyword.
2253 * - false if it's not a keyword.
2254 */
2256{
2257 if (!name || !*name) return false;
2258
2259 return (name_to_op(name) != NULL);
2260}
2261
2262/*
2263 * These are really unlang_foo_t, but that's fine...
2264 */
2265static int8_t instruction_cmp(void const *one, void const *two)
2266{
2267 unlang_t const *a = one;
2268 unlang_t const *b = two;
2269
2270 return CMP(a->number, b->number);
2271}
2272
2273
2274void unlang_compile_init(TALLOC_CTX *ctx)
2275{
2277}
static int const char char buffer[256]
Definition acutest.h:576
#define RCSID(id)
Definition build.h:512
#define L(_str)
Helper for initialising arrays of string literals.
Definition build.h:228
#define CMP(_a, _b)
Same as CMP_PREFER_SMALLER use when you don't really care about ordering, you just want an ordering.
Definition build.h:113
#define unlikely(_x)
Definition build.h:407
#define UNUSED
Definition build.h:336
#define NUM_ELEMENTS(_t)
Definition build.h:358
static int invalid_type(fr_type_t type)
Definition calc.c:698
call_env_t * call_env_alloc(TALLOC_CTX *ctx, char const *name, call_env_method_t const *call_env_method, tmpl_rules_t const *t_rules, CONF_SECTION *cs, call_env_ctx_t const *cec)
Given a call_env_method, parse all call_env_pair_t in the context of a specific call to an xlat or mo...
Definition call_env.c:795
size_t inst_size
Size of per call env.
Definition call_env.h:245
CONF_ITEM * cf_reference_item(CONF_SECTION const *parent_cs, CONF_SECTION const *outer_cs, char const *ptr)
Definition cf_file.c:3852
Internal data that is associated with a configuration section.
Definition cf_priv.h:125
Common header for all CONF_* types.
Definition cf_priv.h:49
Configuration AVP similar to a fr_pair_t.
Definition cf_priv.h:72
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:633
fr_token_t cf_pair_attr_quote(CONF_PAIR const *pair)
Return the value (lhs) quoting of a pair.
Definition cf_util.c:1610
char const * cf_section_name2(CONF_SECTION const *cs)
Return the second identifier of a CONF_SECTION.
Definition cf_util.c:1187
void * cf_data_value(CONF_DATA const *cd)
Return the user assigned value of CONF_DATA.
Definition cf_util.c:1750
CONF_ITEM * cf_section_to_item(CONF_SECTION const *cs)
Cast a CONF_SECTION to a CONF_ITEM.
Definition cf_util.c:739
char const * cf_section_name1(CONF_SECTION const *cs)
Return the first identifier of a CONF_SECTION.
Definition cf_util.c:1173
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:1029
CONF_SECTION * cf_item_to_section(CONF_ITEM const *ci)
Cast a CONF_ITEM to a CONF_SECTION.
Definition cf_util.c:685
bool cf_item_is_data(CONF_ITEM const *ci)
Determine if CONF_ITEM is CONF_DATA.
Definition cf_util.c:647
fr_token_t cf_pair_operator(CONF_PAIR const *pair)
Return the operator of a pair.
Definition cf_util.c:1595
bool cf_item_is_section(CONF_ITEM const *ci)
Determine if CONF_ITEM is a CONF_SECTION.
Definition cf_util.c:619
CONF_PAIR * cf_item_to_pair(CONF_ITEM const *ci)
Cast a CONF_ITEM to a CONF_PAIR.
Definition cf_util.c:665
fr_token_t cf_section_name2_quote(CONF_SECTION const *cs)
Return the quoting of the name2 identifier.
Definition cf_util.c:1232
char const * cf_pair_value(CONF_PAIR const *pair)
Return the value of a CONF_PAIR.
Definition cf_util.c:1581
CONF_ITEM * cf_pair_to_item(CONF_PAIR const *cp)
Cast a CONF_PAIR to a CONF_ITEM.
Definition cf_util.c:723
char const * cf_pair_attr(CONF_PAIR const *pair)
Return the attr of a CONF_PAIR.
Definition cf_util.c:1565
#define cf_log_err(_cf, _fmt,...)
Definition cf_util.h:287
#define cf_data_add(_cf, _data, _name, _free)
Definition cf_util.h:253
#define cf_data_find(_cf, _type, _name)
Definition cf_util.h:242
#define cf_log_debug_prefix(_cf, _fmt,...)
Definition cf_util.h:304
#define cf_data_remove(_cf, _type, _name)
Remove an item from a parent by type and name.
Definition cf_util.h:265
#define cf_root(_cf)
Definition cf_util.h:95
#define cf_section_free_children(_x)
Definition cf_util.h:196
#define cf_parent(_cf)
Definition cf_util.h:98
#define cf_canonicalize_error(_ci, _slen, _msg, _str)
Definition cf_util.h:365
#define cf_item_next(_parent, _curr)
Definition cf_util.h:89
#define cf_log_perr(_cf, _fmt,...)
Definition cf_util.h:294
#define CF_TO_ITEM(_cf)
Auto cast from the input type to CONF_ITEM (which is the base type)
Definition cf_util.h:62
#define cf_log_warn(_cf, _fmt,...)
Definition cf_util.h:288
#define cf_log_debug(_cf, _fmt,...)
Definition cf_util.h:290
#define cf_item_mark_parsed(_cf)
Definition cf_util.h:133
unlang_t * unlang_compile_children(unlang_group_t *g, unlang_compile_ctx_t *unlang_ctx_in)
Definition compile.c:1286
static unlang_t * compile_module(unlang_t *parent, unlang_compile_ctx_t *unlang_ctx, CONF_ITEM *ci, char const *name)
Definition compile.c:1808
static unlang_t * compile_edit_pair(unlang_t *parent, unlang_compile_ctx_t *unlang_ctx, CONF_PAIR *cp)
Compile one edit pair.
Definition compile.c:762
bool unlang_compile_is_keyword(const char *name)
Check if name is an unlang keyword.
Definition compile.c:2255
void unlang_compile_init(TALLOC_CTX *ctx)
Definition compile.c:2274
static bool compile_action_pair(unlang_mod_actions_t *actions, CONF_PAIR *cp)
Definition compile.c:937
unlang_t * unlang_compile_section(unlang_t *parent, unlang_compile_ctx_t *unlang_ctx, CONF_SECTION *cs, unlang_type_t type)
Definition compile.c:1519
bool pass2_fixup_map_rhs(unlang_group_t *g, tmpl_rules_t const *rules)
Definition compile.c:207
bool pass2_fixup_tmpl(UNUSED TALLOC_CTX *ctx, tmpl_t **vpt_p, CONF_ITEM const *ci, fr_dict_t const *dict)
Definition compile.c:88
static unlang_t * compile_edit_section(unlang_t *parent, unlang_compile_ctx_t *unlang_ctx, CONF_SECTION *cs)
Compile one edit section.
Definition compile.c:607
bool unlang_compile_limit_subsection(CONF_SECTION *cs, char const *name)
Definition compile.c:1597
static void unlang_dump(unlang_t *c, int depth)
Definition compile.c:235
static int compile_variable(unlang_t *parent, unlang_compile_ctx_t *unlang_ctx, CONF_PAIR *cp, tmpl_rules_t *t_rules)
Compile a variable definition.
Definition compile.c:848
static char const unlang_spaces[]
Definition compile.c:86
bool unlang_compile_actions(unlang_mod_actions_t *actions, CONF_SECTION *cs, bool module_retry)
Definition compile.c:1083
#define UPDATE_CTX2
Definition compile.c:83
#define name_to_op(name)
Definition compile.c:1893
static int8_t instruction_cmp(void const *one, void const *two)
Definition compile.c:2265
int unlang_fixup_update(map_t *map, void *ctx)
Validate and fixup a map that's part of an update section.
Definition compile.c:347
static bool compile_retry_section(unlang_mod_actions_t *actions, CONF_ITEM *ci)
Definition compile.c:998
static CONF_SECTION * virtual_module_find_cs(CONF_ITEM *ci, UNUSED char const *real_name, char const *virtual_name, char const *method_name, unlang_compile_ctx_t *unlang_ctx, bool *policy)
Load a named module from the virtual module list, or from the "policy" subsection.
Definition compile.c:1722
static unlang_t * compile_item(unlang_t *parent, unlang_compile_ctx_t *unlang_ctx, CONF_ITEM *ci)
Definition compile.c:1990
uint64_t unlang_number
Definition interpret.c:54
static const bool edit_list_sub_op[T_TOKEN_LAST]
Definition compile.c:509
size_t mod_rcode_table_len
Definition compile.c:81
static unlang_t * compile_tmpl(unlang_t *parent, unlang_compile_ctx_t *unlang_ctx, CONF_ITEM *ci)
Definition compile.c:1561
static void compile_set_default_actions(unlang_t *c, unlang_compile_ctx_t *unlang_ctx)
Update a compiled unlang_t with the default actions.
Definition compile.c:485
unlang_t * unlang_compile_empty(unlang_t *parent, UNUSED unlang_compile_ctx_t *unlang_ctx, CONF_SECTION *cs, unlang_type_t type)
Definition compile.c:1194
unlang_group_t * unlang_group_allocate(unlang_t *parent, CONF_SECTION *cs, unlang_type_t type)
Definition compile.c:452
fr_rb_tree_t * unlang_instruction_tree
Definition compile.c:64
bool pass2_fixup_map(map_t *map, tmpl_rules_t const *rules, fr_dict_attr_t const *parent)
Fixup ONE map (recursively)
Definition compile.c:116
bool pass2_fixup_update(unlang_group_t *g, tmpl_rules_t const *rules)
Definition compile.c:180
static unlang_t * compile_function(unlang_t *parent, unlang_compile_ctx_t *unlang_ctx, CONF_ITEM *ci, CONF_SECTION *subcs, bool policy)
Definition compile.c:1647
int dict_attr_acopy_children(fr_dict_t *dict, fr_dict_attr_t *dst, fr_dict_attr_t const *src)
Copy the children of an existing attribute.
Definition dict_util.c:1191
fr_table_num_sorted_t const mod_rcode_table[]
Definition compile.c:68
static int unlang_fixup_edit(map_t *map, void *ctx)
Validate and fixup a map that's part of an edit section.
Definition compile.c:530
int unlang_compile(virtual_server_t const *vs, CONF_SECTION *cs, unlang_mod_actions_t const *actions, tmpl_rules_t const *rules, void **instruction)
Compile an unlang section for a virtual server.
Definition compile.c:2188
#define CLAMP(_name, _field, _limit)
#define T(_x)
Definition compile.c:507
int unlang_define_local_variable(CONF_ITEM *ci, unlang_variable_t *var, tmpl_rules_t *t_rules, fr_type_t type, char const *name, fr_dict_attr_t const *ref)
Definition compile.c:1895
static bool compile_action_subsection(unlang_t *c, CONF_SECTION *cs, CONF_SECTION *subcs)
Definition compile.c:1234
static unlang_cond_t * unlang_group_to_cond(unlang_group_t *g)
Cast a group structure to the cond keyword extension.
#define fr_assert_msg(_x, _msg,...)
Calls panic_action ifndef NDEBUG, else logs error and causes the server to exit immediately with code...
Definition debug.h:212
#define fr_fatal_assert(_x)
Calls panic_action ifndef NDEBUG, else logs error and causes the server to exit immediately with code...
Definition debug.h:169
#define MEM(x)
Definition debug.h:46
#define DEBUG(fmt,...)
Definition dhcpclient.c:38
int fr_dict_attr_acopy_local(fr_dict_attr_t const *dst, fr_dict_attr_t const *src)
Definition dict_util.c:1129
fr_dict_attr_t const * fr_dict_attr_by_name(fr_dict_attr_err_t *err, fr_dict_attr_t const *parent, char const *attr))
Locate a fr_dict_attr_t by its name.
Definition dict_util.c:3528
bool fr_dict_compatible(fr_dict_t const *dict1, fr_dict_t const *dict2)
See if two dictionaries have the same end parent.
Definition dict_util.c:2884
fr_dict_attr_t const * fr_dict_root(fr_dict_t const *dict)
Return the root attribute of a dictionary.
Definition dict_util.c:2665
unsigned int internal
Internal attribute, should not be received in protocol packets, should not be encoded.
Definition dict.h:88
fr_dict_t const * fr_dict_by_protocol_name(char const *name)
Lookup a protocol by its name.
Definition dict_util.c:2842
int fr_dict_attr_add(fr_dict_t *dict, fr_dict_attr_t const *parent, char const *name, unsigned int attr, fr_type_t type, fr_dict_attr_flags_t const *flags))
Add an attribute to the dictionary.
Definition dict_util.c:1967
fr_dict_t * fr_dict_protocol_alloc(fr_dict_t const *parent)
Allocate a new local dictionary.
Definition dict_util.c:4266
Values of the encryption flags.
Test enumeration values.
Definition dict_test.h:92
map_list_t maps
Head of the map list.
Definition edit_priv.h:33
static unlang_t * unlang_edit_to_generic(unlang_edit_t const *p)
Definition edit_priv.h:45
static unlang_edit_t * unlang_generic_to_edit(unlang_t const *p)
Cast a generic structure to the edit extension.
Definition edit_priv.h:39
talloc_free(hp)
#define DEBUG_ENABLED4
True if global debug level 1-4 messages are enabled.
Definition log.h:260
int map_afrom_cs_edit(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 for editing.
Definition map.c:1167
int map_afrom_cp(TALLOC_CTX *ctx, map_t **out, map_t *parent, CONF_PAIR *cp, tmpl_rules_t const *lhs_rules, tmpl_rules_t const *input_rhs_rules, bool edit)
Convert CONFIG_PAIR (which may contain refs) to map_t.
Definition map.c:110
int map_list_afrom_cs(TALLOC_CTX *ctx, map_list_t *out, CONF_SECTION *cs, tmpl_rules_t const *t_rules, map_validate_t validate, void *uctx, unsigned int max)
Convert a config section into a list of { a, b, c, d, ... }.
Definition map.c:1352
ssize_t map_print(fr_sbuff_t *out, map_t const *map)
Print a map to a string.
Definition map.c:2387
unlang_op_t unlang_ops[UNLANG_TYPE_MAX]
Different operations the interpreter can execute.
Definition base.c:31
static TALLOC_CTX * unlang_ctx
Definition base.c:71
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
fr_type_t
@ FR_TYPE_STRING
String of printable characters.
@ FR_TYPE_NULL
Invalid (uninitialised) attribute type.
@ FR_TYPE_GROUP
A grouping of other attributes.
long int ssize_t
ssize_t fr_slen_t
static uint8_t depth(fr_minmax_heap_index_t i)
Definition minmax_heap.c:83
int strcasecmp(char *s1, char *s2)
Definition missing.c:65
Unlang module actions.
@ MOD_ACTION_RETURN
stop processing the section, and return the rcode with unset priority
Definition mod_action.h:41
@ MOD_ACTION_REJECT
change the rcode to REJECT, with unset priority
Definition mod_action.h:40
@ MOD_ACTION_RETRY
retry the instruction, MUST also set a retry config
Definition mod_action.h:39
#define MOD_ACTION_VALID_SET(_x)
Definition mod_action.h:66
fr_retry_config_t retry
Definition mod_action.h:70
#define MOD_PRIORITY(_x)
Definition mod_action.h:34
unlang_mod_action_t actions[RLM_MODULE_NUMCODES]
Definition mod_action.h:69
Declarations for the unlang module interface.
static unlang_t * unlang_module_to_generic(unlang_module_t *p)
Definition module_priv.h:92
static unlang_module_t * unlang_generic_to_module(unlang_t const *p)
Definition module_priv.h:86
module_method_call_t mmc
Everything needed to call a module method.
Definition module_priv.h:38
unlang_t self
Common fields in all unlang_t tree nodes.
Definition module_priv.h:36
call_env_t const * call_env
The per call parsed call environment.
Definition module_priv.h:37
A call to a module method.
Definition module_priv.h:35
fr_slen_t module_rlm_by_name_and_method(TALLOC_CTX *ctx, module_method_call_t *mmc_out, virtual_server_t const *vs, section_name_t const *section, fr_sbuff_t *name, tmpl_rules_t const *t_rules)
Find an existing module instance and verify it implements the specified method.
Definition module_rlm.c:548
CONF_SECTION * module_rlm_virtual_by_name(char const *asked_name)
Definition module_rlm.c:792
module_instance_t * mi
The process modules also push module calls onto the stack for execution.
Definition module_rlm.h:63
module_t common
Common fields presented by all modules.
Definition module_rlm.h:39
module_method_binding_t mmb
Method we're calling.
Definition module_rlm.h:70
module_rlm_t const * rlm
Cached module_rlm_t.
Definition module_rlm.h:66
Declarations for the unlang "parallel" keyword.
#define fr_assert(_expr)
Definition rad_assert.h:37
void * fr_rb_remove(fr_rb_tree_t *tree, void const *data)
Remove an entry from the tree, without freeing the data.
Definition rb.c:695
bool fr_rb_insert(fr_rb_tree_t *tree, void const *data)
Insert data into a tree.
Definition rb.c:626
#define fr_rb_alloc(_ctx, _data_cmp, _data_free)
Allocs a red black tree.
Definition rb.h:221
The main red black tree structure.
Definition rb.h:71
@ RLM_MODULE_INVALID
The module considers the request invalid.
Definition rcode.h:51
@ 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_DISALLOW
Reject the request (user is locked out).
Definition rcode.h:52
@ RLM_MODULE_REJECT
Immediately reject the request.
Definition rcode.h:47
@ RLM_MODULE_TIMEOUT
Module (or section) timed out.
Definition rcode.h:56
@ RLM_MODULE_NOTFOUND
User not found.
Definition rcode.h:53
@ RLM_MODULE_UPDATED
OK (pairs modified).
Definition rcode.h:55
@ RLM_MODULE_NOT_SET
Error resolving rcode (should not be returned by modules).
Definition rcode.h:45
@ RLM_MODULE_NOOP
Module succeeded without doing anything.
Definition rcode.h:54
@ RLM_MODULE_NUMCODES
How many valid return codes there are.
Definition rcode.h:57
@ RLM_MODULE_HANDLED
The module handled the request, so stop.
Definition rcode.h:50
static const call_env_method_t method_env
Definition rlm_detail.c:474
static char const * name
#define FR_SBUFF_IN(_start, _len_or_end)
#define FR_SBUFF_IN_STR(_start)
#define FR_SBUFF_OUT(_start, _len_or_end)
Section name identifier.
Definition section.h:43
char const * name
Instance name e.g. user_database.
Definition module.h:357
@ MODULE_TYPE_RETRY
can handle retries
Definition module.h:51
module_flags_t flags
Flags that control how a module starts up and how a module is called.
Definition module.h:236
CONF_SECTION * conf
Module's instance configuration.
Definition module.h:351
unlang_mod_actions_t actions
default actions and retries.
Definition module.h:325
fr_dict_t const ** dict
required dictionary for this module.
Definition module.h:207
call_env_method_t const * method_env
Method specific call_env.
Definition module.h:178
module_t * exported
Public module structure.
Definition module.h:298
static int16_t tmpl_attr_tail_num(tmpl_t const *vpt)
Return the last attribute reference's attribute number.
Definition tmpl.h:885
#define TMPL_VERIFY(_vpt)
Definition tmpl.h:961
static char const * tmpl_type_to_str(tmpl_type_t type)
Return a static string containing the type name.
Definition tmpl.h:638
#define tmpl_is_xlat(vpt)
Definition tmpl.h:210
int tmpl_resolve(tmpl_t *vpt, tmpl_res_rules_t const *tr_rules))
Attempt to resolve functions and attributes in xlats and attribute references.
fr_table_num_sorted_t const tmpl_request_ref_table[]
Map keywords to tmpl_request_ref_t values.
#define tmpl_is_attr(vpt)
Definition tmpl.h:208
#define NUM_ALL
Definition tmpl.h:395
tmpl_rules_t const * parent
for parent / child relationships
Definition tmpl.h:337
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.
@ 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_DATA
Value in native boxed format.
Definition tmpl.h:138
@ 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
static bool tmpl_attr_tail_da_is_leaf(tmpl_t const *vpt)
Return true if the last attribute reference is a leaf attribute.
Definition tmpl.h:817
#define NUM_COUNT
Definition tmpl.h:396
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 bool tmpl_is_list(tmpl_t const *vpt)
Definition tmpl.h:920
int tmpl_cast_in_place(tmpl_t *vpt, fr_type_t type, fr_dict_attr_t const *enumv))
Convert tmpl_t of type TMPL_TYPE_DATA_UNRESOLVED or TMPL_TYPE_DATA to TMPL_TYPE_DATA of type specifie...
static fr_slen_t vpt
Definition tmpl.h:1269
#define NUM_UNSPEC
Definition tmpl.h:394
static size_t tmpl_attr_num_elements(tmpl_t const *vpt)
The number of attribute references contained within a tmpl.
Definition tmpl.h:896
void tmpl_attr_rewrite_leaf_num(tmpl_t *vpt, int16_t num)
Rewrite the leaf's instance number.
#define tmpl_is_data_unresolved(vpt)
Definition tmpl.h:217
tmpl_attr_rules_t attr
Rules/data for parsing attribute references.
Definition tmpl.h:339
static fr_dict_attr_t const * tmpl_attr_tail_da(tmpl_t const *vpt)
Return the last attribute reference da.
Definition tmpl.h:801
@ REQUEST_UNKNOWN
Unknown request.
Definition tmpl.h:97
#define tmpl_is_regex_xlat_unresolved(vpt)
Definition tmpl.h:221
void tmpl_set_dict_def(tmpl_t *vpt, fr_dict_t const *dict)
Change the default dictionary in the tmpl's resolution rules.
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.
Similar to tmpl_rules_t, but used to specify parameters that may change during subsequent resolution ...
Definition tmpl.h:368
Optional arguments passed to vp_tmpl functions.
Definition tmpl.h:336
PUBLIC int snprintf(char *string, size_t length, char *format, va_alist)
Definition snprintf.c:689
fr_aka_sim_id_type_t type
size_t strlcpy(char *dst, char const *src, size_t siz)
Definition strlcpy.c:34
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
map_list_t child
parent map, for nested ones
Definition map.h:89
map_t * parent
Definition map.h:88
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
unsigned int allow_unknown
Allow unknown attributes i.e.
Definition tmpl.h:303
CONF_ITEM * ci
for migration support and various warnings
Definition tmpl.h:301
fr_dict_t const * dict_def
Default dictionary to use with unqualified attribute references.
Definition tmpl.h:273
#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
char * talloc_typed_asprintf(TALLOC_CTX *ctx, char const *fmt,...)
Call talloc vasprintf, setting the type on the new chunk correctly.
Definition talloc.c:545
#define talloc_strdup(_ctx, _str)
Definition talloc.h:142
static size_t talloc_strlen(char const *s)
Returns the length of a talloc array containing a string.
Definition talloc.h:136
fr_slen_t fr_time_delta_from_str(fr_time_delta_t *out, char const *in, size_t inlen, fr_time_res_t hint)
Create fr_time_delta_t from a string.
Definition time.c:412
#define fr_time_delta_ispos(_a)
Definition time.h:290
@ FR_TIME_RES_SEC
Definition time.h:50
const bool fr_assignment_op[T_TOKEN_LAST]
Definition token.c:170
const bool fr_list_assignment_op[T_TOKEN_LAST]
Definition token.c:187
fr_table_num_ordered_t const fr_tokens_table[]
Definition token.c:33
char const * fr_tokens[T_TOKEN_LAST]
Definition token.c:80
const bool fr_comparison_op[T_TOKEN_LAST]
Definition token.c:200
const bool fr_binary_op[T_TOKEN_LAST]
Definition token.c:218
enum fr_token fr_token_t
@ T_OP_SUB_EQ
Definition token.h:68
@ T_INVALID
Definition token.h:37
@ T_OP_CMP_TRUE
Definition token.h:102
@ T_OP_EQ
Definition token.h:81
@ T_OP_SET
Definition token.h:82
@ T_OP_CMP_FALSE
Definition token.h:103
#define T_TOKEN_LAST
Definition token.h:127
Declarations for unlang transactions.
Declaration for unlang try.
#define RULES_VERIFY(_rules)
CONF_SECTION * cs
char const * debug_name
Printed in log messages when the node is executed.
unlang_mod_actions_t actions
Priorities, etc. for the various return codes.
tmpl_rules_t const * rules
unlang_t * parent
Previous node.
static void unlang_type_init(unlang_t *unlang, unlang_t *parent, unlang_type_t type)
fr_dict_attr_t const * root
the root of our dictionary
size_t pool_len
How much additional space to allocate for chunks.
static void unlang_compile_ctx_copy(unlang_compile_ctx_t *dst, unlang_compile_ctx_t const *src)
bool closed
whether or not this section is closed to new statements
static unlang_t * unlang_group_to_generic(unlang_group_t const *p)
#define unlang_list_foreach(_list_head, _iter)
char const * unlang_name
Talloc type name for the unlang_t.
#define UNLANG_IGNORE
static unlang_t * unlang_tmpl_to_generic(unlang_tmpl_t const *p)
CONF_ITEM * ci
used to generate this item
static unlang_group_t * unlang_generic_to_group(unlang_t const *p)
unsigned int number
unique node number
size_t unlang_size
Total length of the unlang_t + specialisation struct.
unlang_list_t children
char const * name
Unknown...
unlang_type_t
Types of unlang_t nodes.
Definition unlang_priv.h:47
@ UNLANG_TYPE_SWITCH
Switch section.
Definition unlang_priv.h:59
@ UNLANG_TYPE_TRANSACTION
transactions for editing lists
Definition unlang_priv.h:75
@ UNLANG_TYPE_FINALLY
run at the end of a virtual server.
Definition unlang_priv.h:78
@ UNLANG_TYPE_SUBREQUEST
create a child subrequest
Definition unlang_priv.h:67
@ UNLANG_TYPE_CONTINUE
Break statement (within a UNLANG_TYPE_FOREACH).
Definition unlang_priv.h:63
@ UNLANG_TYPE_ELSIF
!Condition && Condition.
Definition unlang_priv.h:58
@ UNLANG_TYPE_ELSE
!Condition.
Definition unlang_priv.h:57
@ UNLANG_TYPE_LOAD_BALANCE
Load balance section.
Definition unlang_priv.h:53
@ UNLANG_TYPE_DETACH
detach a child
Definition unlang_priv.h:70
@ UNLANG_TYPE_GROUP
Grouping section.
Definition unlang_priv.h:51
@ UNLANG_TYPE_POLICY
Policy section.
Definition unlang_priv.h:79
@ UNLANG_TYPE_TMPL
asynchronously expand a tmpl_t
Definition unlang_priv.h:81
@ UNLANG_TYPE_CASE
Case section (within a UNLANG_TYPE_SWITCH).
Definition unlang_priv.h:60
@ UNLANG_TYPE_LIMIT
limit number of requests in a section
Definition unlang_priv.h:74
@ UNLANG_TYPE_BREAK
Break statement (within a UNLANG_TYPE_FOREACH or UNLANG_TYPE_CASE).
Definition unlang_priv.h:62
@ UNLANG_TYPE_TRY
try / catch blocks
Definition unlang_priv.h:76
@ UNLANG_TYPE_CALL
call another virtual server
Definition unlang_priv.h:71
@ UNLANG_TYPE_RETURN
Return statement.
Definition unlang_priv.h:64
@ UNLANG_TYPE_REDUNDANT
exactly like group, but with different default return codes
Definition unlang_priv.h:52
@ UNLANG_TYPE_MAX
Definition unlang_priv.h:83
@ UNLANG_TYPE_IF
Condition.
Definition unlang_priv.h:56
@ UNLANG_TYPE_XLAT
Represents one level of an xlat expansion.
Definition unlang_priv.h:80
@ UNLANG_TYPE_NULL
unlang type not set.
Definition unlang_priv.h:48
@ UNLANG_TYPE_MAP
Mapping section (like #UNLANG_TYPE_UPDATE, but uses values from a map_proc_t call).
Definition unlang_priv.h:65
@ UNLANG_TYPE_CALLER
conditionally check parent dictionary type
Definition unlang_priv.h:72
@ UNLANG_TYPE_TIMEOUT
time-based timeouts.
Definition unlang_priv.h:73
@ UNLANG_TYPE_MODULE
Module method.
Definition unlang_priv.h:49
@ UNLANG_TYPE_REDUNDANT_LOAD_BALANCE
Redundant load balance section.
Definition unlang_priv.h:54
@ UNLANG_TYPE_CHILD_REQUEST
a frame at the top of a child's request stack used to signal the parent when the child is complete.
Definition unlang_priv.h:68
@ UNLANG_TYPE_CATCH
catch a previous try
Definition unlang_priv.h:77
@ UNLANG_TYPE_FUNCTION
Internal call to a function or submodule.
Definition unlang_priv.h:50
@ UNLANG_TYPE_EDIT
edit VPs in place. After 20 years!
Definition unlang_priv.h:82
@ UNLANG_TYPE_FOREACH
Foreach section.
Definition unlang_priv.h:61
@ UNLANG_TYPE_PARALLEL
execute statements in parallel
Definition unlang_priv.h:55
unsigned pool_headers
How much additional space to allocate for chunk headers.
unlang_compile_t compile
compile the keyword
unlang_variable_t * variables
rarely used, so we don't usually need it
#define debug_braces(_type)
char const * name
Name of the keyword.
int max_attr
1..N local attributes have been defined
fr_dict_t * dict
our dictionary
static void unlang_group_type_init(unlang_t *unlang, unlang_t *parent, unlang_type_t type)
tmpl_t const * tmpl
@ UNLANG_OP_FLAG_SINGLE_WORD
the operation is parsed and compiled as a single word
unlang_type_t type
The specialisation of this node.
unlang_op_flag_t flag
Interpreter flags for this operation.
unlang_list_t * list
so we have fewer run-time dereferences
Generic representation of a grouping.
An unlang operation.
A node in a graph of unlang_op_t (s) that we execute.
A naked xlat.
static fr_slen_t parent
Definition pair.h:858
fr_time_delta_t irt
Initial transmission time.
Definition retry.h:33
fr_time_delta_t mrt
Maximum retransmission time.
Definition retry.h:34
uint32_t mrc
Maximum retransmission count.
Definition retry.h:36
fr_time_delta_t mrd
Maximum retransmission duration.
Definition retry.h:35
char const * fr_strerror(void)
Get the last library error.
Definition strerror.c:553
fr_table_num_ordered_t const fr_type_table[]
Map data types to names representing those types.
Definition types.c:31
#define fr_type_is_structural(_x)
Definition types.h:392
#define fr_type_is_leaf(_x)
Definition types.h:393
static char const * fr_type_to_str(fr_type_t type)
Return a static string containing the type name.
Definition types.h:454
#define DOC_KEYWORD_REF(_x)
Definition version.h:89
static size_t char ** out
Definition value.h:1030