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: ff85decee21f19b48cc1aab11a56a37c578cd55b $
19 *
20 * @brief map / template functions
21 * @file src/lib/server/map.c
22 *
23 * @ingroup AVP
24 *
25 * @copyright 2013 The FreeRADIUS server project
26 * @copyright 2013 Alan DeKok (aland@freeradius.org)
27 */
28
29RCSID("$Id: ff85decee21f19b48cc1aab11a56a37c578cd55b $")
30
31#include <freeradius-devel/server/exec.h>
32#include <freeradius-devel/server/exec_legacy.h>
33#include <freeradius-devel/server/map.h>
34#include <freeradius-devel/server/paircmp.h>
35#include <freeradius-devel/server/tmpl_dcursor.h>
36
37#include <freeradius-devel/unlang/interpret.h>
38
39#include <freeradius-devel/util/base16.h>
40#include <freeradius-devel/util/pair_legacy.h>
41
42#include <freeradius-devel/protocol/radius/rfc2865.h>
43#include <freeradius-devel/protocol/freeradius/freeradius.internal.h>
44
45
47 { L("\""), T_DOUBLE_QUOTED_STRING }, /* Don't re-order, backslash throws off ordering */
48 { L("'"), T_SINGLE_QUOTED_STRING },
49 { L("/"), T_SOLIDUS_QUOTED_STRING },
50 { L("`"), T_BACK_QUOTED_STRING }
51};
53
54
55#ifdef DEBUG_MAP
56static void map_dump(request_t *request, map_t const *map)
57{
58 RDEBUG2(">>> MAP TYPES LHS: %s, RHS: %s",
59 tmpl_type_to_str(map->lhs->type),
60 tmpl_type_to_str(map->rhs->type));
61
62 if (map->rhs) {
63 RDEBUG2(">>> MAP NAMES %s %s", map->lhs->name, map->rhs->name);
64 }
65}
66#endif
67
68static inline map_t *map_alloc(TALLOC_CTX *ctx, map_t *parent)
69{
70 map_t *map;
71
72 if (parent) {
73 map = talloc_zero(parent, map_t);
74 } else {
75 map = talloc_zero(ctx, map_t);
76 }
77 map->parent = parent;
78
79 map_list_init(&map->child);
80 return map;
81}
82
83/** Convert CONFIG_PAIR (which may contain refs) to map_t.
84 *
85 * Treats the left operand as an attribute reference
86 * @verbatim<request>.<list>.<attribute>@endverbatim
87 *
88 * Treatment of left operand depends on quotation, barewords are treated as
89 * attribute references, double quoted values are treated as expandable strings,
90 * single quoted values are treated as literal strings.
91 *
92 * Return must be freed with talloc_free
93 *
94 * @param[in] ctx for talloc.
95 * @param[in] out Where to write the pointer to the new #map_t.
96 * @param[in] parent the parent map
97 * @param[in] cp to convert to map.
98 * @param[in] lhs_rules rules for parsing LHS attribute references.
99 * @param[in] input_rhs_rules rules for parsing RHS attribute references.
100 * @param[in] edit treat the map as an edit
101 * @return
102 * - #map_t if successful.
103 * - NULL on error.
104 */
105int map_afrom_cp(TALLOC_CTX *ctx, map_t **out, map_t *parent, CONF_PAIR *cp,
106 tmpl_rules_t const *lhs_rules, tmpl_rules_t const *input_rhs_rules, bool edit)
107{
108 map_t *map;
109 char const *attr, *value, *marker_subject;
110 char *unescaped_value = NULL;
111 fr_sbuff_parse_rules_t const *p_rules;
112 ssize_t slen;
113 fr_token_t quote;
114 fr_dict_attr_t const *da;
115 tmpl_rules_t my_rhs_rules = {};
116 tmpl_rules_t const *rhs_rules = input_rhs_rules;
117 TALLOC_CTX *child_ctx = NULL;
118
119 *out = NULL;
120
121 if (!cp) return -1;
122
123 MEM(map = map_alloc(ctx, parent));
124 map->op = cf_pair_operator(cp);
125 map->ci = cf_pair_to_item(cp);
126
127 attr = cf_pair_attr(cp);
128 value = cf_pair_value(cp);
129 if (!value) {
130 cf_log_err(cp, "Missing attribute value");
131 goto error;
132 }
133
134 /*
135 * Allow for the RHS rules to be taken from the LHS rules.
136 */
137 if (!rhs_rules) rhs_rules = lhs_rules;
138
139 MEM(child_ctx = talloc(map, uint8_t));
140
141 /*
142 * LHS may be an expansion (that expands to an attribute reference)
143 * or an attribute reference. Quoting determines which it is.
144 */
145 quote = cf_pair_attr_quote(cp);
146 switch (quote) {
149 slen = tmpl_afrom_substr(ctx, &map->lhs,
150 &FR_SBUFF_IN(attr, talloc_array_length(attr) - 1),
151 quote,
152 value_parse_rules_unquoted[quote], /* We're not searching for quotes */
153 lhs_rules);
154 if (slen <= 0) {
155 char *spaces, *text;
156
157 marker_subject = attr;
158 marker:
159 fr_canonicalize_error(ctx, &spaces, &text, slen, marker_subject);
160 cf_log_err(cp, "%s", text);
161 cf_log_perr(cp, "%s^", spaces);
162
164 talloc_free(text);
165 goto error;
166 }
167 break;
168
169 default:
170 slen = tmpl_afrom_attr_str(ctx, NULL, &map->lhs, attr, lhs_rules);
171 if (slen <= 0) {
172 cf_log_err(cp, "Failed parsing attribute reference %s - %s", attr, fr_strerror());
173 marker_subject = attr;
174 goto marker;
175 }
176
178 cf_log_perr(cp, "Failed creating attribute %s", map->lhs->name);
179 goto error;
180 }
181
183
184 /*
185 * The caller wants the RHS attributes to be
186 * parsed in the context of the LHS, but only if
187 * the LHS attribute was a group / structural attribute.
188 */
189 if (!input_rhs_rules) {
190 tmpl_rules_child_init(child_ctx, &my_rhs_rules, lhs_rules, map->lhs);
191 } else {
192 my_rhs_rules = *input_rhs_rules;
193 }
194 rhs_rules = &my_rhs_rules;
195
196 if (edit) {
197 if ((map->op != T_OP_RSHIFT_EQ) && (map->op != T_OP_LSHIFT_EQ)) {
198 my_rhs_rules.enumv = tmpl_attr_tail_da(map->lhs);
199 }
200 } else {
201 /*
202 * If we parsed an attribute on the LHS, and the RHS looks like an enumerated
203 * value, then set the enumv.
204 */
205 if (!rhs_rules->enumv && tmpl_is_attr(map->lhs) &&
206 (value[0] == ':') && value[1] == ':') {
207 my_rhs_rules.enumv = tmpl_attr_tail_da(map->lhs);
208 }
209 }
210 break;
211 }
212
213 /*
214 * RHS might be an attribute reference.
215 */
216 quote = cf_pair_value_quote(cp);
217 p_rules = value_parse_rules_unquoted[quote]; /* We're not searching for quotes */
218 if (quote == T_DOUBLE_QUOTED_STRING || quote == T_BACK_QUOTED_STRING) {
219 slen = fr_sbuff_out_aunescape_until(child_ctx, &unescaped_value,
220 &FR_SBUFF_IN(value, talloc_array_length(value) - 1), SIZE_MAX, p_rules->terminals, p_rules->escapes);
221 if (slen < 0) {
222 marker_subject = value;
223 goto marker;
224 }
225 value = unescaped_value;
226 p_rules = NULL;
227
228 } else if (edit && (quote == T_HASH)) {
229 fr_slen_t slent;
231
232 /*
233 * Not a bare word, it's marked up as a complex expression.
234 *
235 * See cf_file.c, parse_input() and the use of T_HASH when doing alloc_pair,
236 * in order to see what magic is going on here.
237 */
238 slen = talloc_array_length(value) - 1;
239
240 MEM(map->rhs = tmpl_alloc(map, TMPL_TYPE_XLAT, T_BARE_WORD, value, slen));
241
242 /*
243 * Tokenize the expression.
244 */
245 slent = xlat_tokenize_expression(map->rhs, &head, &FR_SBUFF_IN(value, slen), p_rules, rhs_rules);
246 if (slent <= 0) {
247 slen = slent + 1;
248 marker_subject = value;
249 goto marker;
250 }
251
252 tmpl_set_xlat(map->rhs, head);
253 goto verify;
254
255 } else if ((map->op == T_OP_CMP_TRUE) || (map->op == T_OP_CMP_FALSE)) {
256 /*
257 * These operators require a hard-coded string on the RHS.
258 */
259 if (strcmp(value, "ANY") != 0) {
260 fr_strerror_printf("Invalid value for %s", fr_tokens[map->op]);
261 goto error;
262 }
263
264 (void) tmpl_afrom_value_box(map, &map->rhs, fr_box_strvalue("ANY"), false);
265 goto verify;
266
267 } else {
268 slen = talloc_array_length(value) - 1;
269 }
270
271 /*
272 * If we're assigning to a structural attribute, AND the
273 * RHS side is a string, THEN don't parse the RHS as a
274 * "group". The edit code will take the string, create
275 * pairs, and work on that.
276 */
277 if (edit && (rhs_rules == &my_rhs_rules) && my_rhs_rules.enumv && fr_type_is_structural(my_rhs_rules.enumv->type) &&
278 ((quote == T_DOUBLE_QUOTED_STRING) || (quote == T_BACK_QUOTED_STRING) || (quote == T_SINGLE_QUOTED_STRING))) {
279 my_rhs_rules.enumv = NULL;
280 }
281
282 slen = tmpl_afrom_substr(map, &map->rhs,
283 &FR_SBUFF_IN(value, slen),
284 quote,
285 p_rules,
286 rhs_rules);
287 if (slen < 0) {
288 marker_subject = value;
289 goto marker;
290 }
291
292 if (!map->rhs) {
293 cf_log_perr(cp, "Failed parsing RHS");
294 goto error;
295 }
296
297 if (tmpl_is_attr(map->rhs) && (tmpl_attr_unknown_add(map->rhs) < 0)) {
298 cf_log_perr(cp, "Failed creating attribute %s", map->rhs->name);
299 goto error;
300 }
301
302 /*
303 * We cannot assign a count to an attribute. That must
304 * be done in an xlat.
305 */
306 if (tmpl_is_attr(map->rhs) &&
307 (tmpl_attr_tail_num(map->rhs) == NUM_COUNT)) {
308 cf_log_err(cp, "Cannot assign from a count");
309 goto error;
310 }
311
312 /*
313 * If we can resolve the RHS in the context of the LHS,
314 * and are allowed to do so, then do that now.
315 *
316 * The "map" keyword uses the RHS not as the value which
317 * is assigned to the LHS. Instead, it is a pointer to
318 * the value. As such, we cannot immediately resolve the
319 * RHS in the context of the LHS.
320 *
321 * The edit code allows string assignments to lists, and
322 * will interpret the string as a sequence of edit
323 * operations. So we skip casting strings to lists.
324 *
325 * @todo - that could arguably be done immediately here,
326 * and the RHS could be parsed and created as a child
327 * map. That would allow for more compile-time sanity
328 * checks.
329 */
330 if (tmpl_is_attr(map->lhs) && tmpl_is_data(map->rhs) &&
331 (!input_rhs_rules || !input_rhs_rules->attr.disallow_rhs_resolve) &&
333 fr_type_t cast_type;
334
335 if ((map->op != T_OP_RSHIFT_EQ) && (map->op != T_OP_LSHIFT_EQ)) {
336 da = tmpl_attr_tail_da(map->lhs);
337 cast_type = da->type;
338 } else {
339 da = NULL;
340 cast_type = FR_TYPE_UINT32;
341 }
342
343 if (tmpl_cast_in_place(map->rhs, cast_type, da) < 0) {
344 cf_log_err(cp, "Invalid assignment - %s", fr_strerror());
345 goto error;
346 }
347 }
348
349verify:
350 MAP_VERIFY(map);
351 TALLOC_FREE(child_ctx);
352
353 *out = map;
354
355 return 0;
356
357error:
358 TALLOC_FREE(child_ctx);
359 talloc_free(map);
360 return -1;
361}
362
364 { L("!*"), T_OP_CMP_FALSE },
365 { L("!="), T_OP_NE },
366 { L("!~"), T_OP_REG_NE },
367 { L("+="), T_OP_ADD_EQ },
368 { L("-="), T_OP_SUB_EQ },
369 { L(":="), T_OP_SET },
370 { L("<"), T_OP_LT },
371 { L("<="), T_OP_LE },
372 { L("="), T_OP_EQ },
373 { L("=*"), T_OP_CMP_TRUE },
374 { L("=="), T_OP_CMP_EQ },
375 { L("=~"), T_OP_REG_EQ },
376 { L(">"), T_OP_GT },
377 { L(">="), T_OP_GE }
378};
380
381fr_sbuff_parse_rules_t const map_parse_rules_bareword_quoted = {
382 .escapes = &(fr_sbuff_unescape_rules_t){
383 .chr = '\\',
384 /*
385 * Allow barewords to contain whitespace
386 * if they're escaped.
387 */
388 .subs = {
389 ['\t'] = '\t',
390 ['\n'] = '\n',
391 [' '] = ' '
392 },
393 .do_hex = false,
394 .do_oct = false
395 },
396
397 /*
398 * We want to stop on _any_ terminal character, even if
399 * the token itself isn't valid here. Doing so means
400 * that we don't have the parser accept things like:
401 *
402 * User-Name,,,,=bob===
403 */
404 .terminals = &FR_SBUFF_TERMS(
405 L("\t"),
406 L("\n"),
407 L(" "),
408 L("!*"),
409 L("!="),
410 L("!~"),
411 L("+="),
412 L(","),
413 L("-="),
414 L(":="),
415 L("<"),
416 L("<="),
417 L("=*"),
418 L("=="),
419 L("=~"),
420 L(">"),
421 L(">="),
422 )
423};
424
432
433/** Parse sbuff into (which may contain refs) to map_t.
434 *
435 * This function uses the legacy operator meanings. The maps created here
436 * should only be used with radius_legacy_map_cmp() and
437 * radius_legacy_map_apply()
438 *
439 * The left operand MUST be an attribute reference
440 * @verbatim<request>.<list>.<attribute>@endverbatim
441 *
442 * The op_table should be #cond_cmp_op_table for check items, and
443 * #map_assignment_op_table for reply items.
444 *
445 * Return must be freed with talloc_free
446 *
447 * @param[in] ctx for talloc.
448 * @param[in] out Where to write the pointer to the new #map_t.
449 * @param[in,out] parent_p the parent map, updated for relative maps
450 * @param[in] in the data to parse for creating the map.
451 * @param[in] op_table for lhs OP rhs
452 * @param[in] op_table_len length of op_table
453 * @param[in] lhs_rules rules for parsing LHS attribute references.
454 * @param[in] rhs_rules rules for parsing RHS attribute references.
455 * @param[in] p_rules a list of terminals which will stop string
456 * parsing.
457 * @return
458 * - >0 on success.
459 * - <=0 on error.
460 */
461ssize_t map_afrom_substr(TALLOC_CTX *ctx, map_t **out, map_t **parent_p, fr_sbuff_t *in,
462 fr_table_num_sorted_t const *op_table, size_t op_table_len,
463 tmpl_rules_t const *lhs_rules, tmpl_rules_t const *rhs_rules,
464 fr_sbuff_parse_rules_t const *p_rules)
465{
466 ssize_t slen;
467 fr_token_t token;
468 map_t *map;
469 fr_sbuff_t our_in = FR_SBUFF(in);
470 fr_sbuff_marker_t m_lhs, m_rhs, m_op;
471 fr_sbuff_term_t const *tt = p_rules ? p_rules->terminals : NULL;
472 map_t *parent;
473 fr_dict_attr_t const *enumv;
474 tmpl_rules_t our_rhs_rules;
475
476 if (parent_p) {
477 parent = *parent_p;
478 } else {
479 parent = NULL;
480 }
481
482 *out = NULL;
483 MEM(map = map_alloc(ctx, NULL));
484
485 (void)fr_sbuff_adv_past_whitespace(&our_in, SIZE_MAX, tt);
486
487 fr_sbuff_marker(&m_lhs, &our_in);
489 switch (token) {
490 default:
491 fr_strerror_const("Expected attribute reference, not string");
492 goto error;
493
494 case T_BARE_WORD:
495 {
496 tmpl_rules_t our_lhs_rules;
497
498 our_lhs_rules = *lhs_rules;
499
500 /*
501 * Bare words on the LHS are always attributes.
502 *
503 * It doesn't make sense to allow "5 = 4". Or, "5 = NAS-Port".
504 *
505 * The conditions do allow "5 == NAS-Port", but
506 * they use a different parser for that.
507 */
508
509 /*
510 * Absolute references are from the root.
511 */
512 if (!fr_sbuff_next_if_char(&our_in, '.')) {
513 parent = NULL;
514
515 lhs_root:
516 slen = tmpl_afrom_attr_substr(map, NULL, &map->lhs, &our_in,
517 &map_parse_rules_bareword_quoted, &our_lhs_rules);
518 break;
519 }
520
521 /*
522 * Allow for ".foo" to refer to the current
523 * parents list. Allow for "..foo" to refer to
524 * the grandparent list.
525 */
526
527 /*
528 * Relative references must have a parent.
529 */
530 if (!parent) {
531 fr_strerror_const("Unexpected location for relative attribute - no parent attribute exists");
532 goto error;
533 }
534
535 /*
536 * Multiple '.' means "go to our parents parent".
537 */
538 while (fr_sbuff_next_if_char(&our_in, '.')) {
539 if (!parent) {
540 fr_strerror_const("Too many '.' in relative reference");
541 goto error;
542 }
543 parent = parent->parent;
544 }
545
546 if (!parent) goto lhs_root;
547
548 /*
549 * Start looking in the correct parent, not in whatever we were handed.
550 */
552 our_lhs_rules.attr.namespace = tmpl_attr_tail_da(parent->lhs);
553
554 slen = tmpl_afrom_attr_substr(map, NULL, &map->lhs, &our_in,
555 &map_parse_rules_bareword_quoted, &our_lhs_rules);
556 break;
557 }
558 }
559
560 if (!map->lhs) {
561 error:
562 slen = 0;
563
564 error_adj:
565 talloc_free(map);
566 FR_SBUFF_ERROR_RETURN(&our_in);
567 }
569
570 (void)fr_sbuff_adv_past_whitespace(&our_in, SIZE_MAX, tt);
571 fr_sbuff_marker(&m_op, &our_in);
572
573 /*
574 * Parse operator.
575 */
576 fr_sbuff_out_by_longest_prefix(&slen, &map->op, op_table, &our_in, T_INVALID);
577 if (map->op == T_INVALID) {
578 fr_strerror_const("Invalid operator");
579 goto error_adj;
580 }
581
582 /*
583 * Validate operators for check items.
584 *
585 * We can have comparison operators for reply items, as the rlm_attr_filter module
586 * uses that.
587 *
588 * However, we can't do comparisons on structural entries, except for existence checks.
589 */
590 if (!parent_p && tmpl_attr_tail_da_is_structural(map->lhs)) {
591 if (fr_comparison_op[map->op] && (map->op != T_OP_CMP_TRUE) && (map->op != T_OP_CMP_FALSE)) {
592 fr_sbuff_set(&our_in, &m_op);
593 fr_strerror_const("Comparison operators cannot be used inside of structural data types");
594 goto error;
595 }
596 }
597
598 (void)fr_sbuff_adv_past_whitespace(&our_in, SIZE_MAX, tt);
599
600 /*
601 * Copy LHS code above, except parsing in RHS, with some
602 * minor modifications.
603 */
604 fr_sbuff_marker(&m_rhs, &our_in);
605
606 /*
607 * If the LHS is a structural attribute, then (for now),
608 * the RHS can only be {}. This limitation should only
609 * be temporary, as we should really recurse to create
610 * child maps. And then the child maps should not have
611 * '.' as prefixes, and should require that the LHS can
612 * only be an attribute, etc. Not trivial, so we'll just
613 * skip all that for now.
614 */
615 switch (tmpl_attr_tail_da(map->lhs)->type) {
617 if ((map->op == T_OP_REG_EQ) || (map->op == T_OP_REG_NE)) {
618 fr_sbuff_set(&our_in, &m_op);
619 fr_assert(0);
620 fr_strerror_const("Regular expressions cannot be used for structural attributes");
621 goto error;
622 }
623
624 /*
625 * To match Vendor-Specific =* ANY
626 *
627 * Which is a damned hack.
628 */
629 if ((map->op == T_OP_CMP_TRUE) || (map->op == T_OP_CMP_FALSE)) goto parse_rhs;
630
631 if (fr_comparison_op[map->op]) {
632 fr_sbuff_set(&our_in, &m_op);
633 fr_strerror_const("Comparison operators cannot be used for structural attributes");
634 goto error;
635 }
636
637 /*
638 * radius_legacy_map_cmp() and radius_legacy_map_apply() both support structural
639 * attributes with RHS strings. And this function is only called from
640 * users_file.c. The consumers of the users file only call the radius legacy map
641 * functions.
642 */
643 if (!fr_sbuff_next_if_char(&our_in, '{')) {
644 goto parse_rhs;
645 }
646
647 fr_sbuff_adv_past_whitespace(&our_in, SIZE_MAX, tt);
648
649 /*
650 * Peek at the next character. If it's '}', stop.
651 */
652 if (!fr_sbuff_next_if_char(&our_in, '}')) {
653 fr_sbuff_set(&our_in, &m_rhs);
654 fr_strerror_const("Unexpected text before '}'");
655 goto error;
656 }
657
658 /*
659 * @todo - call ourselves recursively, with a special flag saying '.' is no
660 * longer necessary. And that we need to stop on '}'
661 */
662
663 /*
664 * Create an empty RHS.
665 */
667 (void) fr_value_box_strdup(map->rhs, tmpl_value(map->rhs), NULL, "", false);
668 goto check_for_child;
669
670 default:
671 break;
672 }
673
674parse_rhs:
675 /*
676 * These operators require a hard-coded string on the
677 * RHS. And we don't care about enums.
678 */
679 if ((map->op == T_OP_CMP_TRUE) || (map->op == T_OP_CMP_FALSE)) {
680 if (fr_sbuff_adv_past_str_literal(&our_in, "ANY") <= 0) {
681 fr_strerror_printf("Invalid value for %s", fr_tokens[map->op]);
682 goto error;
683 }
684
685 (void) tmpl_afrom_value_box(map, &map->rhs, fr_box_strvalue("ANY"), false);
686
687 goto check_for_child;
688 }
689
690 enumv = tmpl_attr_tail_da(map->lhs);
691
692 /*
693 * LHS is a structural type. The RHS is either empty (create empty LHS), or it's a string
694 * containing a list of attributes to create.
695 */
696 if (fr_type_is_leaf(enumv->type)) {
697 our_rhs_rules = *rhs_rules;
698 our_rhs_rules.enumv = enumv;
699 rhs_rules = &our_rhs_rules;
700 }
701
703 switch (token) {
708 slen = tmpl_afrom_substr(map, &map->rhs, &our_in, token,
709 value_parse_rules_quoted[token], rhs_rules);
710 break;
711
712 default:
713 if (rhs_rules->attr.bare_word_enum && rhs_rules->enumv) {
714 fr_value_box_t *vb;
715
716 MEM(vb = fr_value_box_alloc(map, rhs_rules->enumv->type, rhs_rules->enumv));
717
718 if (!p_rules) p_rules = &value_parse_rules_bareword_quoted;
719
720 /*
721 * It MUST be the given data type, and it MAY be an enum name.
722 */
723 slen = fr_value_box_from_substr(map, vb, rhs_rules->enumv->type, rhs_rules->enumv,
724 &our_in, p_rules);
725 if (slen < 0) goto error;
726
727 if (tmpl_afrom_value_box(map, &map->rhs, vb, true) < 0) {
728 goto error;
729 }
730
731 } else {
732 if (!p_rules) p_rules = &value_parse_rules_bareword_quoted;
733
734 /*
735 * Use the RHS termination rules ONLY for bare
736 * words. For quoted strings we already know how
737 * to terminate the input string.
738 */
739 slen = tmpl_afrom_substr(map, &map->rhs, &our_in, token, p_rules, rhs_rules);
740 }
741 break;
742 }
743 if (!map->rhs) goto error_adj;
744
745 /*
746 * Check for, and skip, the trailing quote if we had a leading quote.
747 */
748 if (token != T_BARE_WORD) {
749 if (!fr_sbuff_next_if_char(&our_in, fr_token_quote[token])) {
750 fr_strerror_const("Unexpected end of quoted string");
751 goto error;
752 }
753
754 /*
755 * The tmpl code does NOT return tmpl_type_data
756 * for string data without xlat. Instead, it
757 * creates TMPL_TYPE_DATA_UNRESOLVED.
758 */
759 if (tmpl_resolve(map->rhs, NULL) < 0) {
760 fr_sbuff_set(&our_in, &m_rhs); /* Marker points to RHS */
761 goto error;
762 }
763 } else if (tmpl_is_attr(map->lhs) && (tmpl_is_data_unresolved(map->rhs) || tmpl_is_data(map->rhs))) {
764 /*
765 * If the operator is "true" or "false", just
766 * cast the RHS to string, as no one will care
767 * about it.
768 */
769 if ((map->op != T_OP_CMP_TRUE) && (map->op != T_OP_CMP_FALSE)) {
770 fr_dict_attr_t const *da = tmpl_attr_tail_da(map->lhs);
771
772 if (tmpl_cast_in_place(map->rhs, da->type, da) < 0) {
773 fr_sbuff_set(&our_in, &m_rhs); /* Marker points to RHS */
774 goto error;
775 }
776 } else {
777 if (tmpl_cast_in_place(map->rhs, FR_TYPE_STRING, NULL) < 0) {
778 fr_sbuff_set(&our_in, &m_rhs); /* Marker points to RHS */
779 goto error;
780 }
781 }
782 }
783
784 if (tmpl_contains_regex(map->lhs)) {
785 fr_sbuff_set(&our_in, &m_lhs);
786 fr_strerror_const("Unexpected regular expression");
787 goto error;
788 }
789
790 if ((map->op == T_OP_REG_EQ) || (map->op == T_OP_REG_NE)) {
791 if (!tmpl_contains_regex(map->rhs)) {
792 fr_sbuff_set(&our_in, &m_rhs);
793 fr_strerror_const("Expected regular expression after regex operator");
794 goto error;
795 }
796 } else {
797 if (tmpl_contains_regex(map->rhs)) {
798 fr_sbuff_set(&our_in, &m_rhs);
799 fr_strerror_const("Unexpected regular expression");
800 goto error;
801 }
802 }
803
804check_for_child:
805 /*
806 * Add this map to to the parents list. Note that the caller
807 * will have to check for this, but checking if map->parent
808 * exists.
809 */
810 if (parent) {
811 (void) talloc_steal(parent, map);
812 map->parent = parent;
813 map_list_insert_tail(&parent->child, map);
814 }
815
816 if (parent_p) {
818 *parent_p = map;
819 } else {
820 *parent_p = parent;
821 }
822 }
823
824 /*
825 * Xlat expansions are cast to strings for structural data types.
826 */
829 }
830
831 MAP_VERIFY(map);
832 *out = map;
833
834 FR_SBUFF_SET_RETURN(in, &our_in);
835}
836
837static int _map_afrom_cs(TALLOC_CTX *ctx, map_list_t *out, map_t *parent, CONF_SECTION *cs,
838 tmpl_rules_t const *lhs_rules, tmpl_rules_t const *rhs_rules,
839 map_validate_t validate, void *uctx,
840 unsigned int max, bool update, bool edit)
841{
842 CONF_ITEM *ci;
843 CONF_PAIR *cp;
844
845 unsigned int total = 0;
846 map_t *map;
847 TALLOC_CTX *parent_ctx;
848
849 tmpl_rules_t our_lhs_rules = *lhs_rules; /* Mutable copy of the destination */
850 TALLOC_CTX *tmp_ctx = NULL; /* Temporary context for request lists */
851 tmpl_rules_t child_rhs_rules = *rhs_rules;
852 tmpl_rules_t const *our_rhs_rules;
853
854 /*
855 * The first map has ctx as the parent context.
856 * The rest have the previous map as the parent context.
857 */
858 parent_ctx = ctx;
859
860 ci = cf_section_to_item(cs);
861
862 /*
863 * Check the "update" section for destination lists.
864 */
865 if (update) {
866 fr_slen_t slen;
867 char const *p;
868
869 p = cf_section_name2(cs);
870 if (!p) goto do_children;
871
872 if (our_lhs_rules.attr.list_presence == TMPL_ATTR_LIST_FORBID) {
873 cf_log_err(ci, "Invalid \"update\" section - list references are not allowed here");
874 return -1;
875 }
876
877 MEM(tmp_ctx = talloc_init_const("tmp"));
878
879 slen = tmpl_request_ref_list_afrom_substr(ctx, NULL, &our_lhs_rules.attr.request_def,
880 &FR_SBUFF_IN(p, strlen(p)));
881 if (slen < 0) {
882 cf_log_err(ci, "Invalid reference - %s", fr_strerror());
883 talloc_free(tmp_ctx);
884 return -1;
885 }
886 p += slen;
887
888 slen = tmpl_attr_list_from_substr(&our_lhs_rules.attr.list_def, &FR_SBUFF_IN(p, strlen(p)));
889 if (slen == 0) {
890 cf_log_err(ci, "Unknown list reference \"%s\"", p);
891 talloc_free(tmp_ctx);
892 return -1;
893 }
894 }
895
896do_children:
897 for (ci = cf_item_next(cs, NULL);
898 ci != NULL;
899 ci = cf_item_next(cs, ci)) {
900 tmpl_rules_t child_lhs_rules = our_lhs_rules;
901
902 /*
903 * Disallow list references on the LHS of child lists for edit sections.
904 */
905 if (edit) child_lhs_rules.attr.list_presence = TMPL_ATTR_LIST_FORBID;
906
907 if (total++ == max) {
908 cf_log_err(ci, "Map size exceeded");
909 error:
910 /*
911 * Free in reverse as successive entries have their
912 * prececessors as talloc parent contexts
913 */
914 talloc_free(tmp_ctx);
915 map_list_talloc_reverse_free(out);
916 return -1;
917 }
918
919 /*
920 * If we have a subsection, AND the name2 is an
921 * assignment operator, THEN we allow sub-maps.
922 */
923 if (cf_item_is_section(ci)) {
924 CONF_SECTION *subcs;
925 fr_token_t token;
926 ssize_t slen;
927 map_list_t child_list;
928
929 map_list_init(&child_list);
930 subcs = cf_item_to_section(ci);
931 token = cf_section_name2_quote(subcs);
932
933 if (token == T_INVALID) {
934 cf_log_err(ci, "Section '%s { ... }' is missing the '=' operator", cf_section_name1(subcs));
935 goto error;
936 }
937
938 if (!fr_assignment_op[token]) {
939 cf_log_err(ci, "Invalid operator '%s'", fr_tokens[token]);
940 goto error;
941 }
942
943 MEM(map = map_alloc(parent_ctx, parent));
944 map->op = token;
945 map->ci = ci;
946
947 /*
948 * The LHS MUST be an attribute name.
949 * map_afrom_cp() allows for dynamic
950 * names, but for simplicity we forbid
951 * them for now. Once the functionality
952 * is tested and used, we can allow that.
953 */
954 slen = tmpl_afrom_attr_str(ctx, NULL, &map->lhs, cf_section_name1(subcs), &our_lhs_rules);
955 if (slen <= 0) {
956 cf_log_err(ci, "Failed parsing attribute reference for list %s - %s",
957 cf_section_name1(subcs), fr_strerror());
958 talloc_free(map);
959 goto error; /* re-do "goto marker" stuff to print out spaces ? */
960 }
961
962 /*
963 * The LHS MUST be an attribute reference
964 * for now.
965 */
966 if (!tmpl_is_attr(map->lhs)) {
967 cf_log_err(ci, "Left side of group '%s' is NOT an attribute reference",
968 map->lhs->name);
969 talloc_free(map);
970 goto error; /* re-do "goto marker" stuff to print out spaces ? */
971 }
972
973 if (tmpl_attr_tail_da(map->lhs)->flags.is_unknown) {
974 cf_log_err(ci, "Unknown attribute '%s'", map->lhs->name);
975 talloc_free(map);
976 goto error; /* re-do "goto marker" stuff to print out spaces ? */
977 }
978
979 /*
980 * The leaf reference of the outer section
981 * is used as the parsing context of the
982 * inner section.
983 */
984 child_lhs_rules.attr.namespace = tmpl_attr_tail_da(map->lhs);
985
986 /*
987 * Groups MAY change dictionaries. If so, then swap the dictionary and the parent.
988 */
989 if (child_lhs_rules.attr.namespace->type == FR_TYPE_GROUP) {
990 fr_dict_attr_t const *ref;
991 fr_dict_t const *dict, *internal;
992
993 ref = fr_dict_attr_ref(child_lhs_rules.attr.namespace);
994 dict = fr_dict_by_da(ref);
995 internal = fr_dict_internal();
996
997 if (dict != internal) {
998 if (dict != child_lhs_rules.attr.dict_def) {
999 child_lhs_rules.attr.dict_def = dict;
1000 child_lhs_rules.attr.namespace = ref;
1001 }
1002 } else {
1003 /*
1004 * We're internal: don't use it, and instead rely on dict_def.
1005 */
1006 child_lhs_rules.attr.namespace = NULL;
1007 }
1008 }
1009
1010 if (fr_type_is_structural(tmpl_attr_tail_da(map->lhs)->type)) {
1011 /*
1012 * This prints out any relevant error
1013 * messages. We MAY want to print out
1014 * additional ones, but that might get
1015 * complex and confusing.
1016 *
1017 * We call out internal _map_afrom_cs()
1018 * function, in order to pass in the
1019 * correct parent map.
1020 */
1021 if (_map_afrom_cs(map, &child_list, map, cf_item_to_section(ci),
1022 &child_lhs_rules, rhs_rules, validate, uctx, max, false, edit) < 0) {
1023 fail:
1024 map_list_talloc_free(&child_list);
1025 talloc_free(map);
1026 goto error;
1027 }
1028 map_list_move(&map->child, &child_list);
1029 } else {
1031
1032 /*
1033 * &foo := { a, b, c }
1034 *
1035 * @todo - maybe lhs_rules? But definitely not child_lhs_rules.
1036 *
1037 * @todo - this code is taken from compile_edit_section(), we might want
1038 * to just move that code here, for fewer special cases.
1039 */
1040 if (map_list_afrom_cs(map, &child_list, cf_item_to_section(ci), rhs_rules, NULL, NULL, max) < 0) {
1041 goto fail;
1042 }
1043
1044 if ((map->op != T_OP_SET) && !map_list_num_elements(&child_list)) {
1045 cf_log_err(cs, "Cannot use operator '%s' for assigning empty list to '%s' data type.",
1046 fr_tokens[map->op], fr_type_to_str(tmpl_attr_tail_da(map->lhs)->type));
1047 goto fail;
1048 }
1049
1050 map_list_move(&map->child, &child_list);
1051 }
1052
1053 MAP_VERIFY(map);
1054 goto next;
1055 }
1056
1057 if (!cf_item_is_pair(ci)) {
1058 cf_log_err(ci, "Entry is not in \"attribute = value\" format");
1059 goto error;
1060 }
1061
1062 cp = cf_item_to_pair(ci);
1063 fr_assert(cp != NULL);
1064
1065 /*
1066 * Over-ride RHS rules for
1067 *
1068 * &reply += {
1069 * &User-Name = &User-Name
1070 * }
1071 *
1072 * Which looks stupid. Instead we require
1073 *
1074 * &reply += {
1075 * &User-Name = &request.User-Name
1076 * }
1077 *
1078 * On the other hand, any xlats on the RHS don't use the full path. :( And we still need
1079 * to allow relative attribute references via ".foo", when updating structures.
1080 */
1081 our_rhs_rules = rhs_rules;
1082 if (edit && (rhs_rules->attr.list_def != child_lhs_rules.attr.list_def)) {
1083 char const *value = cf_pair_value(cp);
1084
1085 if (value && (*value == '&')) {
1086 child_rhs_rules.attr.list_presence = TMPL_ATTR_LIST_REQUIRE;
1087 our_rhs_rules = &child_rhs_rules;
1088 }
1089 }
1090
1091 if (map_afrom_cp(parent_ctx, &map, parent, cp, &child_lhs_rules, our_rhs_rules, edit) < 0) {
1092 fr_assert(0);
1093 cf_log_err(ci, "Failed creating map from '%s = %s'",
1094 cf_pair_attr(cp), cf_pair_value(cp));
1095 goto error;
1096 }
1097
1098 MAP_VERIFY(map);
1099
1100 /*
1101 * Check the types in the map are valid
1102 */
1103 if (validate && (validate(map, uctx) < 0)) goto error;
1104
1105 next:
1106 parent_ctx = map;
1107 map_list_insert_tail(out, map);
1108 }
1109
1110 talloc_free(tmp_ctx);
1111 return 0;
1112
1113}
1114
1115/** Convert a config section into an attribute map.
1116 *
1117 * For "update" sections, Uses 'name2' of section to set default request and lists.
1118 *
1119 * @param[in] ctx for talloc.
1120 * @param[out] out Where to store the allocated map.
1121 * @param[in] cs the update section
1122 * @param[in] lhs_rules rules for parsing LHS attribute references.
1123 * @param[in] rhs_rules rules for parsing RHS attribute references.
1124 * @param[in] validate map using this callback (may be NULL).
1125 * @param[in] uctx to pass to callback.
1126 * @param[in] max number of mappings to process.
1127 * @return
1128 * - 0 on success.
1129 * - -1 on failure.
1130 */
1131int map_afrom_cs(TALLOC_CTX *ctx, map_list_t *out, CONF_SECTION *cs,
1132 tmpl_rules_t const *lhs_rules, tmpl_rules_t const *rhs_rules,
1133 map_validate_t validate, void *uctx,
1134 unsigned int max)
1135{
1136 bool update;
1137 char const *name2;
1138 map_t *parent = NULL;
1139
1140 name2 = cf_section_name1(cs);
1141 update = (name2 && (strcmp(name2, "update") == 0));
1142
1143 if (ctx) parent = talloc_get_type(ctx, map_t);
1144
1145 return _map_afrom_cs(ctx, out, parent, cs, lhs_rules, rhs_rules, validate, uctx, max, update, false);
1146}
1147
1148/** Convert a config section into an attribute map for editing
1149 *
1150 * @param[in] ctx for talloc.
1151 * @param[out] out Where to store the allocated map.
1152 * @param[in] cs the update section
1153 * @param[in] lhs_rules rules for parsing LHS attribute references.
1154 * @param[in] rhs_rules rules for parsing RHS attribute references.
1155 * @param[in] validate map using this callback (may be NULL).
1156 * @param[in] uctx to pass to callback.
1157 * @param[in] max number of mappings to process.
1158 * @return
1159 * - 0 on success.
1160 * - -1 on failure.
1161 */
1162int map_afrom_cs_edit(TALLOC_CTX *ctx, map_list_t *out, CONF_SECTION *cs,
1163 tmpl_rules_t const *lhs_rules, tmpl_rules_t const *rhs_rules,
1164 map_validate_t validate, void *uctx,
1165 unsigned int max)
1166{
1167 map_t *parent = NULL;
1168
1169 if (ctx) parent = talloc_get_type(ctx, map_t);
1170
1171 return _map_afrom_cs(ctx, out, parent, cs, lhs_rules, rhs_rules, validate, uctx, max, false, true);
1172}
1173
1174/** Convert CONFIG_PAIR (which may contain refs) to map_t.
1175 *
1176 * Treats the CONFIG_PAIR name as a value.
1177 *
1178 * Treatment of left operand depends on quotation, barewords are treated as
1179 * attribute , double quoted values are treated as expandable strings,
1180 * single quoted values are treated as literal strings.
1181 *
1182 * Return must be freed with talloc_free
1183 *
1184 * @param[in] ctx for talloc.
1185 * @param[in] out Where to write the pointer to the new #map_t.
1186 * @param[in] parent the parent map
1187 * @param[in] cp to convert to map.
1188 * @param[in] t_rules rules for parsing name
1189 * @return
1190 * - #map_t if successful.
1191 * - NULL on error.
1192 */
1193static int map_value_afrom_cp(TALLOC_CTX *ctx, map_t **out, map_t *parent, CONF_PAIR *cp,
1194 tmpl_rules_t const *t_rules)
1195{
1196 map_t *map;
1197 char const *attr, *marker_subject;
1198 ssize_t slen;
1200
1201 *out = NULL;
1202
1203 if (!cp) return -1;
1204
1205 MEM(map = map_alloc(ctx, parent));
1206 map->op = T_OP_EQ; /* @todo - should probably be T_INVALID */
1207 map->ci = cf_pair_to_item(cp);
1208
1209 attr = cf_pair_attr(cp);
1210
1211 /*
1212 * LHS may be an expansion (that expands to an attribute reference)
1213 * or an attribute reference. Quoting determines which it is.
1214 */
1216 switch (type) {
1220 slen = tmpl_afrom_substr(ctx, &map->lhs,
1221 &FR_SBUFF_IN(attr, talloc_array_length(attr) - 1),
1222 type,
1223 value_parse_rules_unquoted[type], /* We're not searching for quotes */
1224 t_rules);
1225 if (slen <= 0) {
1226 char *spaces, *text;
1227
1228 marker:
1229 marker_subject = attr;
1230 fr_canonicalize_error(ctx, &spaces, &text, slen, marker_subject);
1231 cf_log_err(cp, "%s", text);
1232 cf_log_perr(cp, "%s^", spaces);
1233
1235 talloc_free(text);
1236 goto error;
1237 }
1238 break;
1239
1241 fr_strerror_const("Invalid location for regular expression");
1242 slen = 0;
1243 goto marker;
1244
1245 default:
1246 /*
1247 * Let the tmpl code determine if it's an attribute reference or else is a raw value.
1248 */
1249 slen = tmpl_afrom_substr(ctx, &map->lhs, &FR_SBUFF_IN(attr, talloc_array_length(attr) - 1), T_BARE_WORD, NULL, t_rules);
1250 if (slen <= 0) goto marker;
1251
1252 if (tmpl_is_attr(map->lhs) && (tmpl_attr_unknown_add(map->lhs) < 0)) {
1253 fr_strerror_printf("Failed defining attribute %s", map->lhs->name);
1254 goto error;
1255 }
1256 break;
1257 }
1258
1259 MAP_VERIFY(map);
1260
1261 *out = map;
1262
1263 return 0;
1264
1265error:
1266 talloc_free(map);
1267 return -1;
1268}
1269
1270/*
1271 * Where the RHS are all values.
1272 */
1273static int _map_list_afrom_cs(TALLOC_CTX *ctx, map_list_t *out, map_t *parent, CONF_SECTION *cs,
1274 tmpl_rules_t const *t_rules,
1275 map_validate_t validate, void *uctx,
1276 unsigned int max)
1277{
1278 CONF_ITEM *ci;
1279 CONF_PAIR *cp;
1280
1281 unsigned int total = 0;
1282 map_t *map;
1283 TALLOC_CTX *parent_ctx;
1284
1285 /*
1286 * The first map has ctx as the parent context.
1287 * The rest have the previous map as the parent context.
1288 */
1289 parent_ctx = ctx;
1290
1291 for (ci = cf_item_next(cs, NULL);
1292 ci != NULL;
1293 ci = cf_item_next(cs, ci)) {
1294 if (total++ == max) {
1295 cf_log_err(ci, "Map size exceeded");
1296 error:
1297 /*
1298 * Free in reverse as successive entries have their
1299 * prececessors as talloc parent contexts
1300 */
1301 map_list_talloc_reverse_free(out);
1302 return -1;
1303 }
1304
1305 if (cf_item_is_section(ci)) {
1306 cf_log_err(ci, "Cannot create sub-lists");
1307 goto error;
1308 }
1309
1310 cp = cf_item_to_pair(ci);
1311 fr_assert(cp != NULL);
1312
1313 if (map_value_afrom_cp(parent_ctx, &map, parent, cp, t_rules) < 0) {
1314 fr_assert(0);
1315 cf_log_err(ci, "Failed creating map from '%s'", cf_pair_attr(cp));
1316 goto error;
1317 }
1318
1319 MAP_VERIFY(map);
1320
1321 /*
1322 * Check the types in the map are valid
1323 */
1324 if (validate && (validate(map, uctx) < 0)) goto error;
1325
1326 parent_ctx = map;
1327 map_list_insert_tail(out, map);
1328 }
1329
1330 return 0;
1331
1332}
1333
1334/** Convert a config section into a list of { a, b, c, d, ... }
1335 *
1336 * @param[in] ctx for talloc.
1337 * @param[out] out Where to store the allocated map.
1338 * @param[in] cs the update section
1339 * @param[in] t_rules rules for parsing the data.
1340 * @param[in] validate map using this callback (may be NULL).
1341 * @param[in] uctx to pass to callback.
1342 * @param[in] max number of mappings to process.
1343 * @return
1344 * - 0 on success.
1345 * - -1 on failure.
1346 */
1347int map_list_afrom_cs(TALLOC_CTX *ctx, map_list_t *out, CONF_SECTION *cs,
1348 tmpl_rules_t const *t_rules,
1349 map_validate_t validate, void *uctx,
1350 unsigned int max)
1351{
1352 map_t *parent = NULL;
1353
1354 if (ctx) parent = talloc_get_type(ctx, map_t);
1355
1356 return _map_list_afrom_cs(ctx, out, parent, cs, t_rules, validate, uctx, max);
1357}
1358
1359/** Convert a value box to a map
1360 *
1361 * This is mainly used in IO modules, where another function is used to convert
1362 * between the foreign value type and internal values, and the destination
1363 * attribute is provided as a string.
1364 *
1365 * @param[in] ctx for talloc
1366 * @param[out] out Where to store the head of the map.
1367 * @param[in] lhs of the operation
1368 * @param[in] lhs_quote type of the LHS string
1369 * @param[in] lhs_rules rules that control parsing of the LHS string.
1370 * @param[in] op the operation to perform
1371 * @param[in] rhs of the operation
1372 * @param[in] steal_rhs_buffs Whether we attempt to save allocs by stealing the buffers
1373 * from the rhs #fr_value_box_t.
1374 * @return
1375 * - #map_t if successful.
1376 * - NULL on error.
1377 */
1378int map_afrom_value_box(TALLOC_CTX *ctx, map_t **out,
1379 char const *lhs, fr_token_t lhs_quote, tmpl_rules_t const *lhs_rules,
1380 fr_token_t op,
1381 fr_value_box_t *rhs, bool steal_rhs_buffs)
1382{
1383 ssize_t slen;
1384 map_t *map;
1385
1386 map = map_alloc(ctx, NULL);
1387
1388 slen = tmpl_afrom_substr(map, &map->lhs,
1389 &FR_SBUFF_IN(lhs, strlen(lhs)),
1390 lhs_quote,
1391 NULL,
1392 lhs_rules);
1393 if (slen < 0) {
1394 error:
1395 talloc_free(map);
1396 return -1;
1397 }
1398
1399 map->op = op;
1400
1401 if (tmpl_afrom_value_box(map, &map->rhs, rhs, steal_rhs_buffs) < 0) goto error;
1402
1403 MAP_VERIFY(map);
1404 *out = map;
1405
1406 return 0;
1407}
1408
1409/** Convert a value pair string to valuepair map
1410 *
1411 * Takes a valuepair string with list and request qualifiers and converts it into a
1412 * #map_t.
1413 *
1414 * Attribute string is in the format (where @verbatim <qu> @endverbatim is a quotation char ['"]):
1415 @verbatim
1416 [<list>.][<qu>]<attribute>[<qu>] <op> [<qu>]<value>[<qu>]
1417 @endverbatim
1418 *
1419 * @param[in] ctx where to allocate the map.
1420 * @param[out] out Where to write the new map.
1421 * @param[in] vp_str string to parse.
1422 * @param[in] lhs_rules rules for parsing LHS attribute references.
1423 * @param[in] rhs_rules rules for parsing RHS attribute references.
1424 * @return
1425 * - 0 on success.
1426 * - < 0 on error.
1427 */
1428int map_afrom_attr_str(TALLOC_CTX *ctx, map_t **out, char const *vp_str,
1429 tmpl_rules_t const *lhs_rules, tmpl_rules_t const *rhs_rules)
1430{
1431 fr_sbuff_t sbuff = FR_SBUFF_IN(vp_str, strlen(vp_str));
1432
1434 lhs_rules, rhs_rules, NULL) < 0) {
1435 return -1;
1436 }
1437
1438 if (!fr_cond_assert(*out != NULL)) return -1;
1439
1440 if (!tmpl_is_attr((*out)->lhs)) {
1441 TALLOC_FREE(*out);
1442 fr_strerror_const("Left operand must be an attribute");
1443 return -1;
1444 }
1445
1446 return 0;
1447}
1448
1449/** Convert a fr_pair_t into a map
1450 *
1451 * @param[in] ctx where to allocate the map.
1452 * @param[out] out Where to write the new map (must be freed with talloc_free()).
1453 * @param[in] vp to convert.
1454 * @param[in] rules to insert attributes into.
1455 * @return
1456 * - 0 on success.
1457 * - -1 on failure.
1458 */
1459int map_afrom_vp(TALLOC_CTX *ctx, map_t **out, fr_pair_t *vp, tmpl_rules_t const *rules)
1460{
1461 char buffer[256];
1462 fr_sbuff_t buffer_sbuff = FR_SBUFF_OUT(buffer, sizeof(buffer));
1463
1464 map_t *map;
1465
1466 map = map_alloc(ctx, NULL);
1467 if (!map) {
1468 oom:
1469 fr_strerror_const("Out of memory");
1470 return -1;
1471 }
1472
1473 /*
1474 * Allocate the LHS
1475 */
1476 map->lhs = tmpl_alloc(map, TMPL_TYPE_ATTR, T_BARE_WORD, NULL, 0);
1477 if (!map->lhs) goto oom;
1478
1480
1481 tmpl_attr_set_request_ref(map->lhs, rules->attr.request_def);
1482 tmpl_attr_set_list(map->lhs, rules->attr.list_def);
1483
1484 tmpl_print(&buffer_sbuff, map->lhs, NULL);
1485 tmpl_set_name(map->lhs, T_BARE_WORD, fr_sbuff_start(&buffer_sbuff), -1);
1486
1487 /*
1488 * Allocate the RHS
1489 */
1490 map->rhs = tmpl_alloc(map, TMPL_TYPE_DATA, T_BARE_WORD, NULL, -1);
1491 if (!map->lhs) goto oom;
1492
1493 switch (vp->vp_type) {
1494 case FR_TYPE_QUOTED:
1495 tmpl_set_name_printf(map->rhs, T_DOUBLE_QUOTED_STRING, "%pV", &vp->data);
1496 break;
1497
1498 default:
1499 tmpl_set_name_printf(map->rhs, T_BARE_WORD, "%pV", &vp->data);
1500 break;
1501 }
1502
1503 fr_value_box_copy(map->rhs, tmpl_value(map->rhs), &vp->data);
1504
1505 *out = map;
1506
1507 return 0;
1508}
1509
1510/** Process map which has exec as a src
1511 *
1512 * Evaluate maps which specify exec as a src. This may be used by various sorts of update sections, and so
1513 * has been broken out into it's own function.
1514 *
1515 * @param[in,out] ctx to allocate new #fr_pair_t (s) in.
1516 * @param[out] out Where to write the #fr_pair_t (s).
1517 * @param[in] request structure (used only for talloc).
1518 * @param[in] map the map. The LHS (dst) must be #TMPL_TYPE_ATTR.
1519 * The RHS (src) must be #TMPL_TYPE_EXEC.
1520 * @return
1521 * - 0 on success.
1522 * - -1 on failure.
1523 */
1524static int map_exec_to_vp(TALLOC_CTX *ctx, fr_pair_list_t *out, request_t *request, map_t const *map)
1525{
1526 int result;
1527 fr_pair_t *vp;
1528 fr_pair_list_t *input_pairs = NULL;
1529 char answer[1024];
1530
1532
1533 MAP_VERIFY(map);
1534
1535 fr_assert(map->rhs); /* Quite clang scan */
1536 fr_assert(tmpl_is_exec(map->rhs));
1537 fr_assert(tmpl_is_attr(map->lhs));
1538
1539 if (fr_type_is_structural(tmpl_attr_tail_da(map->lhs)->type)) {
1540 REDEBUG("Cannot assign `exec` output to structural attribute %s", map->lhs->name);
1541 return -1;
1542 }
1543
1544 /*
1545 * We always put the request pairs into the environment
1546 */
1547 input_pairs = tmpl_list_head(request, request_attr_request);
1548
1549 /*
1550 * Automagically switch output type depending on our destination
1551 * @todo - If dst is a list, then we create attributes from the output of the program
1552 * if dst is an attribute, then we create an attribute of that type and then
1553 * call fr_pair_value_from_str on the output of the script.
1554 */
1555 result = radius_exec_program_legacy(answer, sizeof(answer),
1556 request, map->rhs->name, input_pairs ? input_pairs : NULL,
1558 if (result != 0) {
1559 REDEBUG("Exec failed with code (%i)", result);
1560 return -1;
1561 }
1562
1563 /*
1564 * @todo - we completely ignore the operator here :( Arguably the caller should be calling ONLY
1565 * the legacy pair move functions with the results of this function.
1566 */
1568 vp->op = map->op;
1569 if (fr_pair_value_from_str(vp, answer, strlen(answer), &fr_value_unescape_single, false) < 0) {
1570 RPEDEBUG("Failed parsing exec output");
1571 talloc_free(&vp);
1572 return -2;
1573 }
1575
1576 return 0;
1577}
1578
1579/** Convert a map to a #fr_pair_t
1580 *
1581 * @param[in,out] ctx to allocate #fr_pair_t (s) in.
1582 * @param[out] out Where to write the #fr_pair_t (s), which may be NULL if not found
1583 * @param[in] request The current request.
1584 * @param[in] map the map. The LHS (dst) has to be #TMPL_TYPE_ATTR.
1585 * @param[in] uctx unused.
1586 * @return
1587 * - 0 on success.
1588 * - -1 on failure.
1589 */
1590int map_to_vp(TALLOC_CTX *ctx, fr_pair_list_t *out, request_t *request, map_t const *map, UNUSED void *uctx)
1591{
1592 int rcode = 0;
1593 fr_pair_t *n = NULL;
1594 fr_pair_list_t found;
1595 request_t *context = request;
1596 ssize_t slen;
1597 char *str;
1598
1599 fr_pair_list_init(&found);
1601
1602 MAP_VERIFY(map);
1603 if (!fr_cond_assert(map->lhs != NULL)) return -1;
1604
1605 fr_assert(tmpl_is_attr(map->lhs));
1606
1607 /*
1608 * If there's no RHS, then it MUST be an attribute, and
1609 * it MUST be structural. And it MAY have children.
1610 */
1611 if (!map->rhs) {
1612 map_t *child;
1613
1614 if (!tmpl_is_attr(map->lhs)) return -1;
1615
1616 switch (tmpl_attr_tail_da(map->lhs)->type) {
1617 case FR_TYPE_STRUCTURAL:
1618 break;
1619
1620 default:
1621 return -1;
1622 }
1623
1624 /*
1625 * Create the parent attribute, and
1626 * recurse to generate the children into
1627 * vp->vp_group
1628 */
1630 n->op = map->op;
1631
1632 for (child = map_list_next(&map->child, NULL);
1633 child != NULL;
1634 child = map_list_next(&map->child, child)) {
1635 fr_pair_list_t list;
1636
1637 /*
1638 * map_to_vp() frees "out", so we need to
1639 * work around that by creating a
1640 * temporary list.
1641 */
1642 fr_pair_list_init(&list);
1643 if (map_to_vp(n, &list, request, child, NULL) < 0) {
1644 talloc_free(n);
1645 return -1;
1646 }
1647
1648 fr_pair_list_append(&n->vp_group, &list);
1649 }
1650
1652 return 0;
1653 }
1654
1655 /*
1656 * List to list found, this is a special case because we don't need
1657 * to allocate any attributes, just finding the current list, and change
1658 * the op.
1659 */
1662 fr_pair_list_t *from = NULL;
1663
1664 if (tmpl_request_ptr(&context, tmpl_request(map->rhs)) == 0) {
1665 from = tmpl_list_head(context, tmpl_list(map->rhs));
1666 }
1667 if (!from) return 0;
1668
1669 if (fr_pair_list_copy(ctx, &found, from) < 0) return -1;
1670
1671 /*
1672 * List to list copy is empty if the src list has no attributes.
1673 */
1674 if (fr_pair_list_empty(&found)) return 0;
1675
1676 fr_pair_list_foreach(&found, vp) {
1677 vp->op = T_OP_ADD_EQ;
1678 }
1679
1680 fr_pair_list_append(out, &found);
1681
1682 return 0;
1683 }
1684
1685 /*
1686 * And parse the RHS
1687 */
1688 switch (map->rhs->type) {
1689 case TMPL_TYPE_XLAT:
1690 fr_assert(tmpl_is_attr(map->lhs));
1691 fr_assert(tmpl_attr_tail_da(map->lhs)); /* We need to know which attribute to create */
1692 fr_assert(tmpl_xlat(map->rhs) != NULL);
1693
1695
1696 /*
1697 * We do the debug printing because xlat_aeval_compiled
1698 * doesn't have access to the original string. It's been
1699 * mangled during the parsing to an internal data structure
1700 */
1701 RDEBUG2("EXPAND %s", map->rhs->name);
1702 RINDENT();
1703
1704 str = NULL;
1705 slen = xlat_aeval_compiled(request, &str, request, tmpl_xlat(map->rhs), NULL, NULL);
1706 REXDENT();
1707
1708 if (slen < 0) {
1709 rcode = slen;
1710 goto error;
1711 }
1712
1713 RDEBUG2("--> %s", str);
1714
1715 rcode = fr_pair_value_from_str(n, str, strlen(str), NULL, false);
1716 talloc_free(str);
1717 if (rcode < 0) {
1718 goto error;
1719 }
1720
1721 n->op = map->op;
1723 break;
1724
1726 fr_assert(tmpl_is_attr(map->lhs));
1727 fr_assert(tmpl_attr_tail_da(map->lhs)); /* We need to know which attribute to create */
1728
1730
1731 if (fr_pair_value_from_str(n, map->rhs->name, strlen(map->rhs->name), NULL, false) < 0) {
1732 rcode = 0;
1733 goto error;
1734 }
1735 n->op = map->op;
1737 break;
1738
1739 case TMPL_TYPE_ATTR:
1740 {
1741 fr_pair_t *vp;
1742 fr_dcursor_t from;
1743
1745
1746 /*
1747 * @todo should log error, and return -1 for v3.1 (causes update to fail)
1748 */
1749 if (tmpl_copy_pairs(ctx, &found, request, map->rhs) < 0) return 0;
1750
1751 vp = fr_pair_dcursor_init(&from, &found);
1752
1753 /*
1754 * Src/Dst attributes don't match, convert src attributes
1755 * to match dst.
1756 */
1757 if (tmpl_is_attr(map->lhs) && tmpl_attr_tail_da_is_leaf(map->lhs) &&
1758 (tmpl_attr_tail_da(map->rhs)->type != tmpl_attr_tail_da(map->lhs)->type)) {
1759 for (; vp; vp = fr_dcursor_current(&from)) {
1761
1762 if (fr_value_box_cast(n, &n->data,
1763 tmpl_attr_tail_da(map->lhs)->type, tmpl_attr_tail_da(map->lhs), &vp->data) < 0) {
1764 RPEDEBUG("Attribute conversion failed");
1765 fr_pair_list_free(&found);
1766 talloc_free(n);
1767 return -1;
1768 }
1769 vp = fr_dcursor_remove(&from); /* advances cursor */
1770 talloc_free(vp);
1771
1772 fr_assert((n->vp_type != FR_TYPE_STRING) || (n->vp_strvalue != NULL));
1773
1774 n->op = map->op;
1776 }
1777
1778 return 0;
1779 }
1780
1781 /*
1782 * Otherwise we just need to fixup the attribute types
1783 * and operators
1784 */
1785 for (; vp; vp = fr_dcursor_next(&from)) {
1787 vp->op = map->op;
1788 }
1789 fr_pair_list_append(out, &found);
1790 }
1791 break;
1792
1793 case TMPL_TYPE_DATA:
1795 fr_assert(tmpl_is_attr(map->lhs));
1796
1798
1799 if (tmpl_attr_tail_da(map->lhs)->type == tmpl_value_type(map->rhs)) {
1800 if (fr_value_box_copy(n, &n->data, tmpl_value(map->rhs)) < 0) {
1801 rcode = -1;
1802 goto error;
1803 }
1804
1805 } else if (fr_value_box_cast(n, &n->data, n->vp_type, n->da, tmpl_value(map->rhs)) < 0) {
1806 RPEDEBUG("Implicit cast failed");
1807 rcode = -1;
1808 goto error;
1809 }
1810 n->op = map->op;
1812
1813 MAP_VERIFY(map);
1814 break;
1815
1816 /*
1817 * This essentially does the same as rlm_exec xlat, except it's non-configurable.
1818 * It's only really here as a convenience for people who expect the contents of
1819 * backticks to be executed in a shell.
1820 *
1821 * exec string is xlat expanded and arguments are shell escaped.
1822 */
1823 case TMPL_TYPE_EXEC:
1824 return map_exec_to_vp(ctx, out, request, map);
1825
1826 default:
1827 fr_assert(0); /* Should have been caught at parse time */
1828
1829 error:
1830 talloc_free(n);
1831 return rcode;
1832 }
1833
1834 return 0;
1835}
1836
1837#define DEBUG_OVERWRITE(_old, _new) \
1838do {\
1839 if (RDEBUG_ENABLED3) {\
1840 char *our_old; \
1841 char *our_new; \
1842 fr_pair_aprint_value_quoted(request, &our_old, _old, T_DOUBLE_QUOTED_STRING); \
1843 fr_pair_aprint_value_quoted(request, &our_new, _new, T_DOUBLE_QUOTED_STRING); \
1844 RINDENT(); \
1845 RDEBUG3("--> overwriting %s with %s", our_old, our_new); \
1846 REXDENT(); \
1847 talloc_free(our_old); \
1848 talloc_free(our_new); \
1849 } \
1850} while (0)
1851
1852/** Convert #map_t to #fr_pair_t (s) and add them to a #request_t.
1853 *
1854 * Takes a single #map_t, resolves request and list identifiers
1855 * to pointers in the current request, then attempts to retrieve module
1856 * specific value(s) using callback, and adds the resulting values to the
1857 * correct request/list.
1858 *
1859 * @param request The current request.
1860 * @param map specifying destination attribute and location and src identifier.
1861 * @param func to retrieve module specific values and convert them to
1862 * #fr_pair_t.
1863 * @param ctx to be passed to func.
1864 * @return
1865 * - -1 if the operation failed.
1866 * - -2 in the source attribute wasn't valid.
1867 * - 0 on success.
1868 */
1869int map_to_request(request_t *request, map_t const *map, radius_map_getvalue_t func, void *ctx)
1870{
1871 int rcode = 0;
1872 fr_pair_t *dst;
1873 fr_pair_list_t *list, src_list;
1874 request_t *context, *tmp_ctx = NULL;
1875 TALLOC_CTX *parent;
1876 fr_dcursor_t dst_list;
1877
1878 bool found = false;
1879
1880 map_t exp_map;
1881 tmpl_t *exp_lhs;
1882 fr_dict_attr_t const *list_ref;
1883
1884 tmpl_dcursor_ctx_t cc = {};
1885
1886 fr_pair_list_init(&src_list);
1887 MAP_VERIFY(map);
1888 fr_assert(map->lhs != NULL);
1889 fr_assert(map->rhs != NULL);
1890
1891 /*
1892 * This function is called only when creating attributes. It cannot be called for conditions.
1893 */
1894 if (fr_comparison_op[map->op]) {
1895 REDEBUG("Invalid operator in %s %s ...", map->lhs->name, fr_tokens[map->op]);
1896 return -1;
1897 }
1898
1899 tmp_ctx = talloc_pool(request, 1024);
1900
1901 /*
1902 * Preprocessing of the LHS of the map.
1903 */
1904 switch (map->lhs->type) {
1905 /*
1906 * Already in the correct form.
1907 */
1908 case TMPL_TYPE_ATTR:
1909 break;
1910
1911 /*
1912 * Everything else gets expanded, then re-parsed as an attribute reference.
1913 *
1914 * This allows the syntax like:
1915 * - "Attr-%{number}" := "value"
1916 */
1917 case TMPL_TYPE_XLAT:
1918 case TMPL_TYPE_EXEC:
1919 {
1920 char *attr_str;
1921 ssize_t slen;
1922
1923 slen = tmpl_aexpand(request, &attr_str, request, map->lhs, NULL, NULL);
1924 if (slen <= 0) {
1925 RPEDEBUG("Left side expansion failed");
1926 fr_assert(!attr_str);
1927 rcode = -1;
1928 goto finish;
1929 }
1930
1931 slen = tmpl_afrom_attr_str(tmp_ctx, NULL, &exp_lhs, attr_str,
1932 &(tmpl_rules_t){
1933 .attr = {
1934 .dict_def = request->local_dict,
1935 .list_def = request_attr_request,
1936 }
1937 });
1938 if (slen <= 0) {
1939 RPEDEBUG("Left side expansion result \"%s\" is not an attribute reference", attr_str);
1940 talloc_free(attr_str);
1941 rcode = -1;
1942 goto finish;
1943 }
1944 fr_assert(tmpl_is_attr(exp_lhs));
1945
1946 memcpy(&exp_map, map, sizeof(exp_map));
1947 exp_map.lhs = exp_lhs;
1948 map = &exp_map;
1949 }
1950 break;
1951
1952 default:
1953 fr_assert(0);
1954 break;
1955 }
1956
1957
1958 /*
1959 * Sanity check inputs. We can have a list or attribute
1960 * as a destination.
1961 */
1962 if (!tmpl_is_attr(map->lhs)) {
1963 REDEBUG("Left side \"%.*s\" of map should be an attr or list but is an %s",
1964 (int)map->lhs->len, map->lhs->name,
1965 tmpl_type_to_str(map->lhs->type));
1966 rcode = -2;
1967 goto finish;
1968 }
1969
1970 context = request;
1971 if (tmpl_request_ptr(&context, tmpl_request(map->lhs)) < 0) {
1972 RPEDEBUG("Mapping \"%.*s\" -> \"%.*s\" cannot be performed due to error in left side of map",
1973 (int)map->rhs->len, map->rhs->name, (int)map->lhs->len, map->lhs->name);
1974 rcode = -2;
1975 goto finish;
1976 }
1977
1978 list_ref = tmpl_list(map->lhs);
1979 list = tmpl_list_head(context, list_ref);
1980 if (!list) {
1981 REDEBUG("Mapping \"%.*s\" -> \"%.*s\" cannot be performed due to to invalid list qualifier \"%s\" in left side of map",
1982 (int)map->rhs->len, map->rhs->name, (int)map->lhs->len, map->lhs->name,
1983 tmpl_list_name(list_ref, "<INVALID>"));
1984 rcode = -2;
1985 goto finish;
1986 }
1987
1990
1991 /*
1992 * The callback should either return -1 to signify operations error,
1993 * -2 when it can't find the attribute or list being referenced, or
1994 * 0 to signify success. It may return "success", but still have no
1995 * VPs to work with.
1996 */
1997 rcode = func(parent, &src_list, request, map, ctx);
1998 if (rcode < 0) {
1999 fr_assert(fr_pair_list_empty(&src_list));
2000 goto finish;
2001 }
2002 if (fr_pair_list_empty(&src_list)) {
2003 RDEBUG2("%.*s skipped: No values available", (int)map->lhs->len, map->lhs->name);
2004 goto finish;
2005 }
2006
2007 /*
2008 * Print the VPs
2009 */
2010#ifndef WITH_VERIFY_PTR
2011 if (RDEBUG_ENABLED)
2012#endif
2013 {
2014 fr_pair_list_foreach(&src_list, vp) {
2015 PAIR_VERIFY(vp);
2016
2017 if (RDEBUG_ENABLED) map_debug_log(request, map, vp);
2018 }
2019 }
2020
2021 /*
2022 * The destination is a list (which is a completely different set of operations)
2023 */
2024 if (tmpl_is_list(map->lhs)) {
2025 switch (map->op) {
2026 case T_OP_CMP_FALSE:
2027 /* We don't need the src VPs (should just be 'ANY') */
2028 fr_assert(fr_pair_list_empty(&src_list));
2029
2030 /* Clear the entire dst list */
2031 fr_pair_list_free(list);
2032 goto finish;
2033
2034 case T_OP_SET:
2035 if (tmpl_is_list(map->rhs)) {
2036 fr_pair_list_free(list);
2037 fr_pair_list_append(list, &src_list);
2038 fr_pair_list_init(&src_list);
2039 } else {
2041
2042 case T_OP_EQ:
2043 fr_assert(tmpl_is_exec(map->rhs));
2045
2046 case T_OP_ADD_EQ:
2047 fr_pair_list_move_op(list, &src_list, T_OP_ADD_EQ);
2048 }
2049 goto update;
2050
2051 case T_OP_PREPEND:
2052 fr_pair_list_move_op(list, &src_list, T_OP_PREPEND);
2053 goto update;
2054
2055 default:
2056 fr_pair_list_free(&src_list);
2057 rcode = -1;
2058 goto finish;
2059 }
2060 }
2061
2062 /*
2063 * Find the destination attribute. We leave with either
2064 * the dst_list and vp pointing to the attribute or the VP
2065 * being NULL (no attribute at that index).
2066 */
2067 dst = tmpl_dcursor_init(NULL, tmp_ctx, &cc, &dst_list, request, map->lhs);
2068 /*
2069 * The destination is an attribute
2070 */
2071 switch (map->op) {
2072 default:
2073 break;
2074 /*
2075 * !* - Remove all attributes which match dst in the specified list.
2076 * This doesn't use attributes returned by the func(), and immediately frees them.
2077 */
2078 case T_OP_CMP_FALSE:
2079 /* We don't need the src VPs (should just be 'ANY') */
2080 fr_assert(fr_pair_list_empty(&src_list));
2081 if (!dst) goto finish;
2082
2083 /*
2084 * Wildcard: delete all of the matching ones
2085 */
2086 if (tmpl_attr_tail_num(map->lhs) == NUM_UNSPEC) {
2087 fr_pair_delete_by_child_num(list, tmpl_attr_tail_da(map->lhs)->parent, tmpl_attr_tail_da(map->lhs)->attr);
2088 dst = NULL;
2089 /*
2090 * We've found the Nth one. Delete it, and only it.
2091 */
2092 } else {
2093 dst = fr_dcursor_remove(&dst_list);
2094 talloc_free(dst);
2095 }
2096
2097 /*
2098 * Check that the User-Name and User-Password
2099 * caches point to the correct attribute.
2100 */
2101 goto update;
2102
2103 /*
2104 * -= - Delete attributes in the dst list which match any of the
2105 * src_list attributes.
2106 *
2107 * This operation has two modes:
2108 * - If tmpl_attr_tail_num(map->lhs) > 0, we check each of the src_list attributes against
2109 * the dst attribute, to see if any of their values match.
2110 * - If tmpl_attr_tail_num(map->lhs) == NUM_UNSPEC, we compare all instances of the dst attribute
2111 * against each of the src_list attributes.
2112 */
2113 case T_OP_SUB_EQ:
2114 /* We didn't find any attributes earlier */
2115 if (!dst) {
2116 fr_pair_list_free(&src_list);
2117 goto finish;
2118 }
2119
2120 /*
2121 * Instance specific[n] delete
2122 */
2123 if (tmpl_attr_tail_num(map->lhs) != NUM_UNSPEC) {
2124 fr_pair_list_foreach(&src_list, vp) {
2125 vp->op = T_OP_CMP_EQ;
2126 rcode = paircmp_pairs(request, vp, dst);
2127 if (rcode == 0) {
2128 dst = fr_dcursor_remove(&dst_list);
2129 talloc_free(dst);
2130 found = true;
2131 }
2132 }
2133 rcode = 0;
2134 fr_pair_list_free(&src_list);
2135 if (!found) goto finish;
2136 goto update;
2137 }
2138
2139 /*
2140 * All instances[*] delete
2141 */
2142 for (dst = fr_dcursor_current(&dst_list);
2143 dst;
2145 fr_pair_list_foreach(&src_list, vp) {
2146 vp->op = T_OP_CMP_EQ;
2147 rcode = paircmp_pairs(request, vp, dst);
2148 if (rcode == 0) {
2149 dst = fr_dcursor_remove(&dst_list);
2150 talloc_free(dst);
2151 found = true;
2152 }
2153 }
2154 }
2155 rcode = 0;
2156 fr_pair_list_free(&src_list);
2157 if (!found) goto finish;
2158 goto update;
2159 }
2160
2161 switch (map->op) {
2162 /*
2163 * = - Set only if not already set
2164 */
2165 case T_OP_EQ:
2166 {
2167 tmpl_attr_extent_t *extent = NULL;
2168 fr_dlist_head_t leaf;
2169 fr_dlist_head_t interior;
2170 fr_pair_t *src_vp;
2171
2172 if (dst) {
2173 RDEBUG3("Refusing to overwrite (use :=)");
2174 fr_pair_list_free(&src_list);
2175 goto finish;
2176 }
2177
2179 fr_dlist_talloc_init(&interior, tmpl_attr_extent_t, entry);
2180
2181 /*
2182 * Find out what we need to build and build it
2183 */
2184 if ((tmpl_extents_find(tmp_ctx, &leaf, &interior, request, map->lhs) < 0) ||
2185 (tmpl_extents_build_to_leaf_parent(&leaf, &interior, map->lhs) < 0)) {
2186 fr_dlist_talloc_free(&leaf);
2187 fr_dlist_talloc_free(&interior);
2188 rcode = -1;
2189 goto finish;
2190 }
2191
2192 /*
2193 * Need to copy src to all dsts
2194 */
2195 src_vp = fr_pair_list_head(&src_list);
2196 if (!src_vp) {
2197 fr_dlist_talloc_free(&leaf);
2198 rcode = -1;
2199 goto finish;
2200 }
2201
2202 if (fr_dlist_num_elements(&leaf) > 1) {
2203 while ((extent = fr_dlist_tail(&leaf))) {
2204 fr_pair_append(extent->list, fr_pair_copy(extent->list_ctx, src_vp));
2206 }
2207 } else {
2208 extent = fr_dlist_head(&leaf);
2209 fr_pair_append(extent->list, fr_pair_copy(extent->list_ctx, src_vp));
2211 }
2212
2213 /* Free any we didn't insert */
2214 fr_pair_list_free(&src_list);
2215 fr_assert(fr_dlist_num_elements(&interior) == 0);
2216 fr_assert(fr_dlist_num_elements(&leaf) == 0);
2217 }
2218 break;
2219
2220 /*
2221 * := - Overwrite existing attribute with last src_list attribute
2222 */
2223 case T_OP_SET:
2224 {
2225 tmpl_attr_extent_t *extent = NULL;
2226 fr_dlist_head_t leaf;
2227 fr_dlist_head_t interior;
2228 fr_pair_t *src_vp;
2229
2230 src_vp = fr_pair_list_tail(&src_list);
2231
2232 if (dst) {
2233 DEBUG_OVERWRITE(dst, src_vp);
2234
2235 fr_pair_reinit_from_da(NULL, dst, src_vp->da);
2236 fr_pair_value_copy(dst, src_vp);
2237
2238 goto op_set_done;
2239 }
2240
2242 fr_dlist_talloc_init(&interior, tmpl_attr_extent_t, entry);
2243
2244 /*
2245 * Find out what we need to build and build it
2246 */
2247 if ((tmpl_extents_find(tmp_ctx, &leaf, &interior, request, map->lhs) < 0) ||
2248 (tmpl_extents_build_to_leaf_parent(&leaf, &interior, map->lhs) < 0)) {
2249 op_set_error:
2250 fr_dlist_talloc_free(&leaf);
2251 fr_dlist_talloc_free(&interior);
2252 rcode = -1;
2253 goto finish;
2254 }
2255
2256 if (fr_dlist_num_elements(&leaf) > 1) {
2257 ERROR("Not yet supported");
2258
2259 goto op_set_error;
2260 } else {
2261 extent = fr_dlist_head(&leaf);
2262 fr_pair_append(extent->list, fr_pair_copy(extent->list_ctx, src_vp));
2263 }
2264
2265 fr_assert(fr_dlist_num_elements(&interior) == 0);
2266 fr_dlist_talloc_free(&leaf);
2267
2268 op_set_done:
2269 /* Free any we didn't insert */
2270 fr_pair_list_free(&src_list);
2271 }
2272 break;
2273
2274 /*
2275 * ^= - Prepend src_list attributes to the destination
2276 */
2277 case T_OP_PREPEND:
2278 fr_pair_list_prepend(list, &src_list);
2279 fr_pair_list_free(&src_list);
2280 break;
2281
2282 /*
2283 * += - Add all src_list attributes to the destination
2284 */
2285 case T_OP_ADD_EQ:
2286 {
2287 tmpl_attr_extent_t *extent = NULL;
2288 fr_dlist_head_t leaf;
2289 fr_dlist_head_t interior;
2290
2292 fr_dlist_talloc_init(&interior, tmpl_attr_extent_t, entry);
2293
2294 /*
2295 * Find out what we need to build and build it
2296 */
2297 if ((tmpl_extents_find(tmp_ctx, &leaf, &interior, request, map->lhs) < 0) ||
2298 (tmpl_extents_build_to_leaf_parent(&leaf, &interior, map->lhs) < 0)) {
2299 fr_dlist_talloc_free(&leaf);
2300 fr_dlist_talloc_free(&interior);
2301 rcode = -1;
2302 goto finish;
2303 }
2304
2305 if (fr_dlist_num_elements(&leaf) > 1) {
2306 while ((extent = fr_dlist_tail(&leaf))) {
2307 (void) fr_pair_list_copy(extent->list_ctx, extent->list, &src_list);
2309 }
2310 /* Free all the src vps */
2311 fr_pair_list_free(&src_list);
2312 } else {
2313 extent = fr_dlist_head(&leaf);
2314 (void) fr_pair_list_copy(extent->list_ctx, extent->list, &src_list);
2316 }
2317
2318 fr_pair_list_free(&src_list);
2319 fr_assert(fr_dlist_num_elements(&interior) == 0);
2320 fr_assert(fr_dlist_num_elements(&leaf) == 0);
2321 }
2322 break;
2323
2324 /*
2325 * Filter operators
2326 */
2327 case T_OP_NE:
2328 case T_OP_CMP_EQ:
2329 case T_OP_GE:
2330 case T_OP_GT:
2331 case T_OP_LE:
2332 case T_OP_LT:
2333 {
2334 fr_pair_t *a;
2335
2338
2339 fr_dcursor_head(&dst_list);
2340
2341 fr_pair_list_foreach(&src_list, b) {
2342 for (a = fr_dcursor_current(&dst_list);
2343 a;
2344 a = fr_dcursor_next(&dst_list)) {
2345 int8_t cmp;
2346
2347 cmp = fr_pair_cmp_by_da(a, b); /* attribute and tag match */
2348 if (cmp > 0) break;
2349 else if (cmp < 0) continue;
2350
2351 cmp = (fr_value_box_cmp_op(map->op, &a->data, &b->data) == 0);
2352 if (cmp != 0) {
2353 a = fr_dcursor_remove(&dst_list);
2354 talloc_free(a);
2355 }
2356 }
2357 if (!a) break; /* end of the list */
2358 }
2359 fr_pair_list_free(&src_list);
2360 }
2361 break;
2362
2363 default:
2364 fr_assert(0); /* Should have been caught be the caller */
2365 rcode = -1;
2366 goto finish;
2367 }
2368
2369update:
2370 fr_assert(fr_pair_list_empty(&src_list));
2371
2372finish:
2373 tmpl_dcursor_clear(&cc);
2374 talloc_free(tmp_ctx);
2375 return rcode;
2376}
2377
2378/** Print a map to a string
2379 *
2380 * @param[out] out Buffer to write string to.
2381 * @param[in] map to print.
2382 * @return
2383 * - The number of bytes written to the out buffer.
2384 * - A number >= outlen if truncation has occurred.
2385 */
2387{
2388 fr_sbuff_t our_out = FR_SBUFF(out);
2389
2390 MAP_VERIFY(map);
2391
2392 /*
2393 * Print the lhs
2394 */
2395 if (tmpl_rules_cast(map->lhs)) {
2396 FR_SBUFF_IN_SPRINTF_RETURN(&our_out, "<%s>",
2398 }
2399 FR_SBUFF_RETURN(tmpl_print_quoted, &our_out, map->lhs);
2400
2401 /*
2402 * Print separators and operator
2403 */
2404 FR_SBUFF_IN_CHAR_RETURN(&our_out, ' ');
2406 FR_SBUFF_IN_CHAR_RETURN(&our_out, ' ');
2407
2408 /*
2409 * The RHS doesn't matter for many operators
2410 */
2411 if ((map->op == T_OP_CMP_TRUE) || (map->op == T_OP_CMP_FALSE)) {
2412 FR_SBUFF_IN_STRCPY_RETURN(&our_out, "ANY");
2413 FR_SBUFF_SET_RETURN(out, &our_out);
2414 }
2415
2416 /*
2417 * If there's no child and no RHS then the
2418 * map was invalid.
2419 */
2420 if (map_list_empty(&map->child) && !fr_cond_assert(map->rhs != NULL)) {
2421 fr_sbuff_terminate(out);
2422 return 0;
2423 }
2424
2425 if (tmpl_rules_cast(map->rhs)) {
2426 FR_SBUFF_IN_SPRINTF_RETURN(&our_out, "<%s>",
2428 }
2429
2430 /*
2431 * Print the RHS.
2432 */
2433 FR_SBUFF_RETURN(tmpl_print_quoted, &our_out, map->rhs);
2434
2435 FR_SBUFF_SET_RETURN(out, &our_out);
2436}
2437
2438/*
2439 * Debug print a map / VP
2440 */
2441void map_debug_log(request_t *request, map_t const *map, fr_pair_t const *vp)
2442{
2443 char *rhs = NULL, *value = NULL;
2444 char buffer[256];
2445
2446 MAP_VERIFY(map);
2447 if (!fr_cond_assert(map->lhs != NULL)) return;
2448 if (!fr_cond_assert(map->rhs != NULL)) return;
2449
2450 fr_assert(vp);
2451
2452 switch (map->rhs->type) {
2453 /*
2454 * Just print the value being assigned
2455 */
2456 default:
2458 fr_pair_aprint_value_quoted(request, &rhs, vp, map->rhs->quote);
2459 break;
2460
2461 case TMPL_TYPE_XLAT:
2462 fr_pair_aprint_value_quoted(request, &rhs, vp, map->rhs->quote);
2463 break;
2464
2465 case TMPL_TYPE_DATA:
2466 fr_pair_aprint_value_quoted(request, &rhs, vp, map->rhs->quote);
2467 break;
2468
2469 case TMPL_TYPE_ATTR:
2470 {
2471 fr_token_t quote;
2472
2473 switch (vp->vp_type) {
2474 case FR_TYPE_QUOTED:
2475 quote = T_DOUBLE_QUOTED_STRING;
2476 break;
2477 default:
2478 quote = T_BARE_WORD;
2479 break;
2480 }
2481
2482 /*
2483 * Not appropriate to use map->rhs->quote here, as that's the quoting
2484 * around the attr ref. The attribute value has no quoting, so we choose
2485 * the quoting based on the data type.
2486 */
2487 fr_pair_aprint_value_quoted(request, &value, vp, quote);
2488 tmpl_print(&FR_SBUFF_OUT(buffer, sizeof(buffer)), map->rhs, NULL);
2489 rhs = talloc_typed_asprintf(request, "%s -> %s", buffer, value);
2490 }
2491 break;
2492 }
2493
2494 switch (map->lhs->type) {
2495 case TMPL_TYPE_ATTR:
2496 tmpl_print(&FR_SBUFF_OUT(buffer, sizeof(buffer)), map->lhs, NULL);
2497 RDEBUG2("%s %s %s", buffer, fr_table_str_by_value(fr_tokens_table, vp ? vp->op : map->op, "<INVALID>"), rhs);
2498 break;
2499
2500 default:
2501 break;
2502 }
2503
2504 /*
2505 * Must be LIFO free order so we don't leak pool memory
2506 */
2507 talloc_free(rhs);
2509}
2510
2511/** Convert a fr_pair_t into a map
2512 *
2513 * @param[in] ctx where to allocate the map.
2514 * @param[out] out Where to write the new map (must be freed with talloc_free()).
2515 * @param[in,out] parent_p the parent map, updated for relative maps
2516 * @param[in] request the request
2517 * @param[in] lhs of map
2518 * @param[in] op_str operator for map
2519 * @param[in] rhs of map
2520 * @param[in] lhs_rules for parsing the LHS
2521 * @param[in] rhs_rules for parsing the RHS
2522 * @param[in] bare_word_only RHS is bare words, and nothing else.
2523 * @return
2524 * - 0 on success.
2525 * - -1 on failure.
2526 */
2527int map_afrom_fields(TALLOC_CTX *ctx, map_t **out, map_t **parent_p, request_t *request,
2528 char const *lhs, char const *op_str, char const *rhs,
2529 tmpl_rules_t const *lhs_rules, tmpl_rules_t const *rhs_rules, bool bare_word_only)
2530{
2531 ssize_t slen;
2532 fr_token_t quote, op;
2533 map_t *map;
2534 map_t *parent = *parent_p;
2535 tmpl_rules_t my_rules;
2536
2538 if (op == T_INVALID) {
2539 fr_strerror_printf("Invalid operator '%s'", op_str);
2540 return -1;
2541 }
2542
2543 /*
2544 * Reply items can be expanded. Check items cannot be,
2545 * unless the operator is a comparison operator.
2546 */
2547 if (!bare_word_only) {
2548 if (!fr_assignment_op[op]) {
2549 fr_assert(0);
2550 fr_strerror_printf("Invalid operator '%s' for assignment in reply item", op_str);
2551 return -1;
2552 }
2553
2554 } else if (!fr_assignment_op[op] && !fr_comparison_op[op]) {
2555 if (!fr_assignment_op[op]) {
2556 fr_strerror_printf("Invalid operator '%s' for check item", op_str);
2557 return -1;
2558 }
2559 }
2560
2561 my_rules = *lhs_rules;
2562 lhs_rules = &my_rules;
2563
2564 /*
2565 * We're only called from SQL. If the default list is request, then we only use that for
2566 * comparisons. We rewrite assignments to use the control list.
2567 *
2568 * @todo - as we expand the use of this function, perhaps add another argument which controls
2569 * this flag. But this function already has parameter overload :(
2570 */
2571 if (fr_assignment_op[op] && (lhs_rules->attr.list_def == request_attr_request)) {
2573 }
2574
2575 /*
2576 * One '.' means "the current parent".
2577 */
2578 if (*lhs == '.') {
2579 if (!parent) {
2580 no_parent:
2581 fr_strerror_const("Unexpected location for relative attribute - no parent attribute exists");
2582 return -1;
2583 }
2584 lhs++;
2585
2586 /*
2587 * Multiple '.' means "go to our parents parent".
2588 */
2589 while (*lhs == '.') {
2590 if (!parent) goto no_parent;
2591
2592 parent = parent->parent;
2593 lhs++;
2594 }
2595
2596 /*
2597 * Child elements can only be "=".
2598 */
2599 if (parent) {
2600 if (fr_comparison_op[op]) {
2601 fr_strerror_const("Comparison operators cannot be used inside of structural data types");
2602 return -1;
2603 }
2604
2605 if (op != T_OP_EQ) {
2606 fr_strerror_const("Invalid operator inside of structural data type - must be '='");
2607 return -1;
2608 }
2609 }
2610 }
2611
2612 MEM(map = map_alloc(ctx, parent));
2613 map->op = op;
2614
2615 /*
2616 * Start looking in the correct parent, not in whatever we were handed.
2617 */
2618 if (parent) {
2620 my_rules.attr.namespace = tmpl_attr_tail_da(parent->lhs);
2621
2622 slen = tmpl_afrom_attr_substr(map, NULL, &map->lhs, &FR_SBUFF_IN(lhs, strlen(lhs)),
2624 } else {
2625 /*
2626 * There's no '.', so this
2627 * attribute MUST come from the
2628 * root of the dictionary tree.
2629 */
2630 parent = NULL;
2631
2632 /*
2633 * Allocate the LHS, which must be an attribute.
2634 *
2635 * @todo - track relative attributes, which begin with a '.'
2636 */
2637 slen = tmpl_afrom_attr_str(ctx, NULL, &map->lhs, lhs, lhs_rules);
2638 }
2639 if (slen <= 0) {
2640 error:
2641 talloc_free(map);
2642 return -1;
2643 }
2644
2645 if (tmpl_attr_tail_is_unknown(map->lhs) && tmpl_attr_unknown_add(map->lhs) < 0) {
2646 fr_strerror_printf("Failed creating attribute %s", map->lhs->name);
2647 goto error;
2648 }
2649
2650 my_rules = *rhs_rules;
2651 my_rules.at_runtime = true;
2652 my_rules.xlat.runtime_el = unlang_interpret_event_list(request);
2653 my_rules.enumv = tmpl_attr_tail_da(map->lhs);
2654
2655 /*
2656 * LHS is a structureal type. The RHS is either empty (create empty LHS), or it's a string
2657 * containing a list of attributes to create.
2658 */
2659 if (!fr_type_is_leaf(my_rules.enumv->type)) {
2660 my_rules.enumv = NULL;
2661 }
2662
2663 /*
2664 * Try to figure out what we should do with the RHS.
2665 */
2666 if ((map->op == T_OP_CMP_TRUE) || (map->op == T_OP_CMP_FALSE)) {
2667 /*
2668 * These operators require a hard-coded string on the RHS.
2669 */
2670 if (strcmp(rhs, "ANY") != 0) {
2671 fr_strerror_printf("Invalid value %s for operator %s", rhs, fr_tokens[map->op]);
2672 goto error;
2673 }
2674
2675 if (tmpl_afrom_value_box(map, &map->rhs, fr_box_strvalue("ANY"), false) < 0) goto error;
2676
2677 } else if (bare_word_only) {
2678 fr_value_box_t *vb;
2679
2680 /*
2681 * No value, or no enum, parse it as a bare-word string.
2682 */
2683 if (!rhs[0] || !my_rules.enumv) goto do_bare_word;
2684
2685 MEM(vb = fr_value_box_alloc(map, my_rules.enumv->type, my_rules.enumv));
2686
2687 /*
2688 * It MUST be the given data type.
2689 */
2690 slen = fr_value_box_from_str(map, vb, my_rules.enumv->type, my_rules.enumv,
2691 rhs, strlen(rhs), NULL);
2692 if (slen <= 0) goto error;
2693
2694 if (tmpl_afrom_value_box(map, &map->rhs, vb, true) < 0) {
2695 goto error;
2696 }
2697
2698 } else if (rhs[0] == '"') {
2699 /*
2700 * We've been asked to expand the RHS. Passwords like
2701 *
2702 * "%{Calling-Station-ID}"
2703 *
2704 * might not do what you want.
2705 */
2706 quote = T_DOUBLE_QUOTED_STRING;
2707 goto parse_quoted;
2708
2709 } else if (rhs[0] == '\'') {
2710 size_t len;
2711
2712 quote = T_SINGLE_QUOTED_STRING;
2713
2714 parse_quoted:
2715 len = strlen(rhs + 1);
2716 if (len == 1) {
2717 if (rhs[1] != rhs[0]) {
2718 fr_strerror_const("Invalid string on right side");
2719 return -1;
2720 }
2721
2722 rhs = "";
2723 goto alloc_empty;
2724 }
2725
2726 slen = tmpl_afrom_substr(map, &map->rhs, &FR_SBUFF_IN(rhs + 1, len - 1),
2727 quote, value_parse_rules_quoted[quote], &my_rules);
2728 if (slen < 0) {
2729 REDEBUG3("Failed parsing right-hand side as quoted string.");
2730 fail_rhs:
2731 fr_strerror_printf("Failed parsing right-hand side: %s", fr_strerror());
2732 goto error;
2733 }
2734
2735 if (slen == 0) {
2736 rhs = "";
2737 goto alloc_empty;
2738 }
2739
2740 /*
2741 * Ignore any extra data after the string.
2742 *
2743 * @todo - this should likely be a parse error: we didn't parse the entire string!
2744 */
2745
2746 } else if (rhs[0] == '&') {
2747 /*
2748 * No enums here.
2749 */
2751
2752 parse_as_attr:
2753 my_rules.enumv = NULL;
2754
2755 slen = tmpl_afrom_attr_str(map, NULL, &map->rhs, rhs, &my_rules);
2756 if (slen <= 0) {
2757 REDEBUG3("Failed parsing right-hand side as attribute.");
2758 goto fail_rhs;
2759 }
2760
2761 } else if (!rhs[0] || !my_rules.enumv || (my_rules.enumv->type == FR_TYPE_STRING)) {
2762 do_bare_word:
2763 quote = T_BARE_WORD;
2764
2765 if (tmpl_attr_tail_da_is_structural(map->lhs) && !*rhs) goto done;
2766
2767 alloc_empty:
2768 MEM(map->rhs = tmpl_alloc(map, TMPL_TYPE_DATA, quote, rhs, strlen(rhs)));
2769
2770 /*
2771 * Create it when we have
2772 *
2773 * my-struct = ""
2774 */
2775 (void) fr_value_box_strdup(map->rhs, tmpl_value(map->rhs), NULL, rhs, false);
2776
2777 } else {
2778 /*
2779 * Parse it as the given data type.
2780 */
2781 slen = tmpl_afrom_substr(map, &map->rhs, &FR_SBUFF_IN(rhs, strlen(rhs)),
2783 if (slen <= 0) {
2784 goto parse_as_attr;
2785 }
2786
2787 /*
2788 * Xlat expansions are cast to strings for structural data types.
2789 */
2790 if (tmpl_attr_tail_da_is_structural(map->lhs) && (tmpl_is_xlat(map->rhs))) {
2792 }
2793 }
2794
2795 if (tmpl_needs_resolving(map->rhs)) {
2796 tmpl_res_rules_t tr_rules = (tmpl_res_rules_t) {
2797 .dict_def = lhs_rules->attr.dict_def,
2798 .enumv = tmpl_attr_tail_da(map->lhs)
2799 };
2800
2802
2803 if (tmpl_resolve(map->rhs, &tr_rules) < 0) {
2804 REDEBUG3("Failed resolving right-hand side.");
2805 goto fail_rhs;
2806 }
2807 }
2808
2809 /*
2810 * @todo - check that the entire string was parsed.
2811 */
2812
2813done:
2814 /*
2815 * If the tail is a leaf, we don't change parent.
2816 * Otherwise the structural attribute is the new parent.
2817 */
2818 if (tmpl_attr_tail_da_is_leaf(map->lhs)) {
2819 *parent_p = parent;
2820 } else {
2821 *parent_p = map;
2822 }
2823
2824 MAP_VERIFY(map);
2825
2826 if (parent) map_list_insert_tail(&parent->child, map);
2827 *out = map;
2828
2829 return 0;
2830}
static int const char char buffer[256]
Definition acutest.h:576
int n
Definition acutest.h:577
static int context
Definition radmin.c:71
#define RCSID(id)
Definition build.h:485
#define L(_str)
Helper for initialising arrays of string literals.
Definition build.h:209
#define FALL_THROUGH
clang 10 doesn't recognised the FALL-THROUGH comment anymore
Definition build.h:324
#define UNUSED
Definition build.h:317
#define NUM_ELEMENTS(_t)
Definition build.h:339
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_pair_attr_quote(CONF_PAIR const *pair)
Return the value (lhs) quoting of a pair.
Definition cf_util.c:1622
char const * cf_section_name2(CONF_SECTION const *cs)
Return the second identifier of a CONF_SECTION.
Definition cf_util.c:1184
CONF_ITEM * cf_section_to_item(CONF_SECTION const *cs)
Cast a CONF_SECTION to a CONF_ITEM.
Definition cf_util.c:737
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_item_to_section(CONF_ITEM const *ci)
Cast a CONF_ITEM to a CONF_SECTION.
Definition cf_util.c:683
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
CONF_PAIR * cf_item_to_pair(CONF_ITEM const *ci)
Cast a CONF_ITEM to a CONF_PAIR.
Definition cf_util.c:663
fr_token_t cf_section_name2_quote(CONF_SECTION const *cs)
Return the quoting of the name2 identifier.
Definition cf_util.c:1229
char const * cf_pair_value(CONF_PAIR const *pair)
Return the value of a CONF_PAIR.
Definition cf_util.c:1593
CONF_ITEM * cf_pair_to_item(CONF_PAIR const *cp)
Cast a CONF_PAIR to a CONF_ITEM.
Definition cf_util.c:721
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_item_next(_parent, _curr)
Definition cf_util.h:92
#define cf_log_perr(_cf, _fmt,...)
Definition cf_util.h:296
static void * fr_dcursor_next(fr_dcursor_t *cursor)
Advanced the cursor to the next item.
Definition dcursor.h:290
static void * fr_dcursor_filter_next(fr_dcursor_t *cursor, fr_dcursor_eval_t eval, void const *uctx)
Return the next item, skipping the current item, that satisfies an evaluation function.
Definition dcursor.h:547
static void * fr_dcursor_remove(fr_dcursor_t *cursor)
Remove the current item.
Definition dcursor.h:482
static void * fr_dcursor_current(fr_dcursor_t *cursor)
Return the item the cursor current points to.
Definition dcursor.h:339
static void * fr_dcursor_head(fr_dcursor_t *cursor)
Rewind cursor to the start of the list.
Definition dcursor.h:234
#define fr_cond_assert(_x)
Calls panic_action ifndef NDEBUG, else logs error and evaluates to value of _x.
Definition debug.h:139
#define MEM(x)
Definition debug.h:36
static char const * spaces
Definition dependency.c:370
#define ERROR(fmt,...)
Definition dhcpclient.c:41
fr_dict_t const * fr_dict_by_da(fr_dict_attr_t const *da)
Attempt to locate the protocol dictionary containing an attribute.
Definition dict_util.c:2609
fr_dict_t const * fr_dict_internal(void)
Definition dict_util.c:4654
static fr_slen_t in
Definition dict.h:840
static fr_dict_attr_t const * fr_dict_attr_ref(fr_dict_attr_t const *da)
Return the reference associated with a group type attribute.
Definition dict_ext.h:184
Test enumeration values.
Definition dict_test.h:92
static void * fr_dlist_head(fr_dlist_head_t const *list_head)
Return the HEAD item of a list or NULL if the list is empty.
Definition dlist.h:486
static void fr_dlist_talloc_free_head(fr_dlist_head_t *list_head)
Free the first item in the list.
Definition dlist.h:854
static void fr_dlist_talloc_free(fr_dlist_head_t *head)
Free all items in a doubly linked list (with talloc)
Definition dlist.h:908
static unsigned int fr_dlist_num_elements(fr_dlist_head_t const *head)
Return the number of elements in the dlist.
Definition dlist.h:939
static void fr_dlist_talloc_free_tail(fr_dlist_head_t *list_head)
Free the last item in the list.
Definition dlist.h:863
static void * fr_dlist_tail(fr_dlist_head_t const *list_head)
Return the TAIL item of a list or NULL if the list is empty.
Definition dlist.h:531
#define fr_dlist_talloc_init(_head, _type, _field)
Initialise the head structure of a doubly linked list.
Definition dlist.h:275
Head of a doubly linked list.
Definition dlist.h:51
#define EXEC_TIMEOUT
Default wait time for exec calls (in seconds).
Definition exec.h:32
int radius_exec_program_legacy(char *out, size_t outlen, request_t *request, char const *cmd, fr_pair_list_t *input_pairs, bool exec_wait, bool shell_escape, fr_time_delta_t timeout)
Execute a program.
fr_event_list_t * unlang_interpret_event_list(request_t *request)
Get the event list for the current interpreter.
Definition interpret.c:1757
#define REXDENT()
Exdent (unindent) R* messages by one level.
Definition log.h:443
#define RDEBUG3(fmt,...)
Definition log.h:343
#define REDEBUG3(fmt,...)
Definition log.h:373
#define RPEDEBUG(fmt,...)
Definition log.h:376
#define RINDENT()
Indent R* messages by one level.
Definition log.h:430
static int _map_afrom_cs(TALLOC_CTX *ctx, map_list_t *out, map_t *parent, CONF_SECTION *cs, tmpl_rules_t const *lhs_rules, tmpl_rules_t const *rhs_rules, map_validate_t validate, void *uctx, unsigned int max, bool update, bool edit)
Definition map.c:837
static int map_value_afrom_cp(TALLOC_CTX *ctx, map_t **out, map_t *parent, CONF_PAIR *cp, tmpl_rules_t const *t_rules)
Convert CONFIG_PAIR (which may contain refs) to map_t.
Definition map.c:1193
int map_afrom_fields(TALLOC_CTX *ctx, map_t **out, map_t **parent_p, request_t *request, char const *lhs, char const *op_str, char const *rhs, tmpl_rules_t const *lhs_rules, tmpl_rules_t const *rhs_rules, bool bare_word_only)
Convert a fr_pair_t into a map.
Definition map.c:2527
#define DEBUG_OVERWRITE(_old, _new)
Definition map.c:1837
int map_to_vp(TALLOC_CTX *ctx, fr_pair_list_t *out, request_t *request, map_t const *map, UNUSED void *uctx)
Convert a map to a fr_pair_t.
Definition map.c:1590
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:1162
fr_table_num_sorted_t const map_assignment_op_table[]
Definition map.c:363
fr_sbuff_parse_rules_t const map_parse_rules_bareword_quoted
Definition map.c:381
ssize_t map_afrom_substr(TALLOC_CTX *ctx, map_t **out, map_t **parent_p, fr_sbuff_t *in, fr_table_num_sorted_t const *op_table, size_t op_table_len, tmpl_rules_t const *lhs_rules, tmpl_rules_t const *rhs_rules, fr_sbuff_parse_rules_t const *p_rules)
Parse sbuff into (which may contain refs) to map_t.
Definition map.c:461
static map_t * map_alloc(TALLOC_CTX *ctx, map_t *parent)
Definition map.c:68
static int _map_list_afrom_cs(TALLOC_CTX *ctx, map_list_t *out, map_t *parent, CONF_SECTION *cs, tmpl_rules_t const *t_rules, map_validate_t validate, void *uctx, unsigned int max)
Definition map.c:1273
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:105
static fr_table_num_sorted_t const cond_quote_table[]
Definition map.c:46
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
int map_afrom_value_box(TALLOC_CTX *ctx, map_t **out, char const *lhs, fr_token_t lhs_quote, tmpl_rules_t const *lhs_rules, fr_token_t op, fr_value_box_t *rhs, bool steal_rhs_buffs)
Convert a value box to a map.
Definition map.c:1378
int map_afrom_vp(TALLOC_CTX *ctx, map_t **out, fr_pair_t *vp, tmpl_rules_t const *rules)
Convert a fr_pair_t into a map.
Definition map.c:1459
int map_to_request(request_t *request, map_t const *map, radius_map_getvalue_t func, void *ctx)
Convert map_t to fr_pair_t (s) and add them to a request_t.
Definition map.c:1869
static int map_exec_to_vp(TALLOC_CTX *ctx, fr_pair_list_t *out, request_t *request, map_t const *map)
Process map which has exec as a src.
Definition map.c:1524
static size_t cond_quote_table_len
Definition map.c:52
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:1347
int map_afrom_attr_str(TALLOC_CTX *ctx, map_t **out, char const *vp_str, tmpl_rules_t const *lhs_rules, tmpl_rules_t const *rhs_rules)
Convert a value pair string to valuepair map.
Definition map.c:1428
ssize_t map_print(fr_sbuff_t *out, map_t const *map)
Print a map to a string.
Definition map.c:2386
size_t map_assignment_op_table_len
Definition map.c:379
fr_sbuff_parse_rules_t const * map_parse_rules_quoted[T_TOKEN_LAST]
Definition map.c:425
void map_debug_log(request_t *request, map_t const *map, fr_pair_t const *vp)
Definition map.c:2441
talloc_free(reap)
void fr_canonicalize_error(TALLOC_CTX *ctx, char **sp, char **text, ssize_t slen, char const *fmt)
Canonicalize error strings, removing tabs, and generate spaces for error marker.
Definition log.c:87
#define MAP_VERIFY(_x)
Definition map.h:108
int(* radius_map_getvalue_t)(TALLOC_CTX *ctx, fr_pair_list_t *out, request_t *request, map_t const *map, void *uctx)
Definition map.h:117
int(* map_validate_t)(map_t *map, void *ctx)
Definition map.h:116
fr_type_t
@ FR_TYPE_STRING
String of printable characters.
@ FR_TYPE_UINT32
32 Bit unsigned integer.
@ FR_TYPE_GROUP
A grouping of other attributes.
long int ssize_t
unsigned char uint8_t
ssize_t fr_slen_t
fr_slen_t tmpl_print(fr_sbuff_t *out, tmpl_t const *vpt, fr_sbuff_escape_rules_t const *e_rules)
bool fr_pair_matches_da(void const *item, void const *uctx)
Evaluation function for matching if vp matches a given da.
Definition pair.c:3393
int fr_pair_list_copy(TALLOC_CTX *ctx, fr_pair_list_t *to, fr_pair_list_t const *from)
Duplicate a list of pairs.
Definition pair.c:2329
int fr_pair_value_from_str(fr_pair_t *vp, char const *value, size_t inlen, fr_sbuff_unescape_rules_t const *uerules, UNUSED bool tainted)
Convert string value to native attribute value.
Definition pair.c:2599
int fr_pair_append(fr_pair_list_t *list, fr_pair_t *to_add)
Add a VP to the end of the list.
Definition pair.c:1351
fr_pair_t * fr_pair_afrom_da(TALLOC_CTX *ctx, fr_dict_attr_t const *da)
Dynamically allocate a new attribute and assign a fr_dict_attr_t.
Definition pair.c:287
void fr_pair_list_init(fr_pair_list_t *list)
Initialise a pair list header.
Definition pair.c:46
int fr_pair_delete_by_child_num(fr_pair_list_t *list, fr_dict_attr_t const *parent, unsigned int attr)
Delete matching pairs from the specified list.
Definition pair.c:1814
int fr_pair_value_copy(fr_pair_t *dst, fr_pair_t *src)
Copy the value from one pair to another.
Definition pair.c:2573
int fr_pair_reinit_from_da(fr_pair_list_t *list, fr_pair_t *vp, fr_dict_attr_t const *da)
Re-initialise an attribute with a different da.
Definition pair.c:318
fr_pair_t * fr_pair_copy(TALLOC_CTX *ctx, fr_pair_t const *vp)
Copy a single valuepair.
Definition pair.c:493
int8_t fr_pair_cmp_by_da(void const *a, void const *b)
Order attributes by their da, and tag.
Definition pair.c:1850
void fr_pair_list_move_op(fr_pair_list_t *to, fr_pair_list_t *from, fr_token_t op)
Move pairs from source list to destination list respecting operator.
int paircmp_pairs(UNUSED request_t *request, fr_pair_t const *check, fr_pair_t *vp)
Compares check and vp by value.
Definition paircmp.c:53
#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 RDEBUG_ENABLED()
Definition radclient.h:49
fr_dict_attr_t const * request_attr_request
Definition request.c:43
fr_dict_attr_t const * request_attr_control
Definition request.c:45
bool fr_sbuff_next_if_char(fr_sbuff_t *sbuff, char c)
Return true if the current char matches, and if it does, advance.
Definition sbuff.c:2090
#define fr_sbuff_start(_sbuff_or_marker)
#define fr_sbuff_out_by_longest_prefix(_match_len, _out, _table, _sbuff, _def)
#define fr_sbuff_adv_past_str_literal(_sbuff, _needle)
#define FR_SBUFF_IN_CHAR_RETURN(_sbuff,...)
#define fr_sbuff_set(_dst, _src)
#define FR_SBUFF_IN(_start, _len_or_end)
#define fr_sbuff_adv_past_whitespace(_sbuff, _len, _tt)
#define FR_SBUFF_TERMS(...)
Initialise a terminal structure with a list of sorted strings.
Definition sbuff.h:192
#define FR_SBUFF_RETURN(_func, _sbuff,...)
#define FR_SBUFF_ERROR_RETURN(_sbuff_or_marker)
#define FR_SBUFF_SET_RETURN(_dst, _src)
#define FR_SBUFF_IN_SPRINTF_RETURN(...)
#define FR_SBUFF(_sbuff_or_marker)
#define FR_SBUFF_OUT(_start, _len_or_end)
#define FR_SBUFF_IN_STRCPY_RETURN(...)
Set of terminal elements.
Set of parsing rules for *unescape_until functions.
static int16_t tmpl_attr_tail_num(tmpl_t const *vpt)
Return the last attribute reference's attribute number.
Definition tmpl.h:885
void tmpl_attr_set_list(tmpl_t *vpt, fr_dict_attr_t const *list)
static char const * tmpl_type_to_str(tmpl_type_t type)
Return a static string containing the type name.
Definition tmpl.h:634
#define tmpl_is_xlat(vpt)
Definition tmpl.h:210
void tmpl_set_name_printf(tmpl_t *vpt, fr_token_t quote, char const *fmt,...))
Set the name on a pre-initialised tmpl.
void tmpl_set_xlat(tmpl_t *vpt, xlat_exp_head_t *xlat)
Change the default dictionary in the tmpl's resolution rules.
void tmpl_attr_set_request_ref(tmpl_t *vpt, FR_DLIST_HEAD(tmpl_request_list) const *request_def)
Set the request for an attribute ref.
int tmpl_resolve(tmpl_t *vpt, tmpl_res_rules_t const *tr_rules))
Attempt to resolve functions and attributes in xlats and attribute references.
#define tmpl_value(_tmpl)
Definition tmpl.h:937
TALLOC_CTX * list_ctx
Where to allocate new attributes if building out from the current extents of the tree.
Definition tmpl.h:610
int tmpl_afrom_value_box(TALLOC_CTX *ctx, tmpl_t **out, fr_value_box_t *data, bool steal)
Create a tmpl_t from a fr_value_box_t.
tmpl_t * tmpl_alloc(TALLOC_CTX *ctx, tmpl_type_t type, fr_token_t quote, char const *name, ssize_t len)
Create a new heap allocated tmpl_t.
int tmpl_attr_unknown_add(tmpl_t *vpt)
Add an unknown fr_dict_attr_t specified by a tmpl_t to the main dictionary.
static bool tmpl_attr_tail_is_unknown(tmpl_t const *vpt)
Return true if the last attribute reference is "unknown".
Definition tmpl.h:742
#define tmpl_contains_regex(vpt)
Definition tmpl.h:226
int tmpl_extents_build_to_leaf_parent(fr_dlist_head_t *leaf, fr_dlist_head_t *interior, tmpl_t const *vpt)
Allocate interior pairs.
#define tmpl_is_attr(vpt)
Definition tmpl.h:208
#define tmpl_is_exec(vpt)
Definition tmpl.h:211
fr_dict_attr_t const * enumv
Enumeration attribute used to resolve enum values.
Definition tmpl.h:338
void tmpl_rules_child_init(TALLOC_CTX *ctx, tmpl_rules_t *out, tmpl_rules_t const *parent, tmpl_t *vpt)
Initialize a set of rules from a parent set of rules, and a parsed tmpl_t.
#define tmpl_xlat(_tmpl)
Definition tmpl.h:930
static fr_dict_attr_t const * tmpl_list(tmpl_t const *vpt)
Definition tmpl.h:904
int tmpl_extents_find(TALLOC_CTX *ctx, fr_dlist_head_t *leaf, fr_dlist_head_t *interior, request_t *request, tmpl_t const *vpt))
Determines points where the reference list extends beyond the current pair tree.
#define tmpl_rules_cast(_tmpl)
Definition tmpl.h:942
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.
void tmpl_set_name(tmpl_t *vpt, fr_token_t quote, char const *name, ssize_t len)
Set the name on a pre-initialised tmpl.
@ 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
static bool tmpl_attr_tail_da_is_leaf(tmpl_t const *vpt)
Return true if the the last attribute reference is a leaf attribute.
Definition tmpl.h:817
#define NUM_COUNT
Definition tmpl.h:392
#define tmpl_contains_attr(vpt)
Definition tmpl.h:225
static bool tmpl_attr_tail_da_is_structural(tmpl_t const *vpt)
Return true if the the last attribute reference is a structural attribute.
Definition tmpl.h:835
int tmpl_copy_pairs(TALLOC_CTX *ctx, fr_pair_list_t *out, request_t *request, tmpl_t const *vpt))
Copy pairs matching a tmpl_t in the current request_t.
Definition tmpl_eval.c:677
fr_pair_list_t * tmpl_list_head(request_t *request, fr_dict_attr_t const *list)
Resolve attribute fr_pair_list_t value to an attribute list.
Definition tmpl_eval.c:70
TALLOC_CTX * tmpl_list_ctx(request_t *request, fr_dict_attr_t const *list)
Return the correct TALLOC_CTX to alloc fr_pair_t in, for a list.
Definition tmpl_eval.c:110
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 e_rules fr_slen_t tmpl_print_quoted(fr_sbuff_t *out, tmpl_t const *vpt)
Print a tmpl_t to a string with quotes.
tmpl_xlat_rules_t xlat
Rules/data for parsing xlats.
Definition tmpl.h:336
bool at_runtime
Produce an ephemeral/runtime tmpl.
Definition tmpl.h:344
static bool tmpl_is_list(tmpl_t const *vpt)
Definition tmpl.h:920
ssize_t tmpl_afrom_attr_substr(TALLOC_CTX *ctx, tmpl_attr_error_t *err, tmpl_t **out, fr_sbuff_t *name, fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules))
Parse a string into a TMPL_TYPE_ATTR_* type tmpl_t.
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...
#define tmpl_is_data(vpt)
Definition tmpl.h:206
fr_dict_t const * dict_def
Alternative default dictionary to use if vpt->rules->dict_def is NULL.
Definition tmpl.h:365
#define NUM_UNSPEC
Definition tmpl.h:390
fr_slen_t tmpl_request_ref_list_afrom_substr(TALLOC_CTX *ctx, tmpl_attr_error_t *err, FR_DLIST_HEAD(tmpl_request_list) _CONST **out, fr_sbuff_t *in)
#define tmpl_value_type(_tmpl)
Definition tmpl.h:939
int tmpl_request_ptr(request_t **request, FR_DLIST_HEAD(tmpl_request_list) const *rql)
Resolve a tmpl_request_ref_t to a request_t.
Definition tmpl_eval.c:163
#define tmpl_is_data_unresolved(vpt)
Definition tmpl.h:217
tmpl_attr_rules_t attr
Rules/data for parsing attribute references.
Definition tmpl.h:335
fr_pair_list_t * list
List that we tried to evaluate ar in and failed.
Definition tmpl.h:612
static fr_dict_attr_t const * tmpl_attr_tail_da(tmpl_t const *vpt)
Return the last attribute reference da.
Definition tmpl.h:801
@ TMPL_ATTR_LIST_REQUIRE
Attribute refs are required to have a list.
Definition tmpl.h:264
@ TMPL_ATTR_LIST_FORBID
Attribute refs are forbidden from having a list.
Definition tmpl.h:263
int tmpl_attr_set_leaf_da(tmpl_t *vpt, fr_dict_attr_t const *da)
Replace the leaf attribute only.
struct tmpl_res_rules_s tmpl_res_rules_t
Definition tmpl.h:237
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
#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.
fr_event_list_t * runtime_el
The eventlist to use for runtime instantiation of xlats.
Definition tmpl.h:324
#define tmpl_needs_resolving(vpt)
Definition tmpl.h:223
int tmpl_cast_set(tmpl_t *vpt, fr_type_t type)
Set a cast for a tmpl.
Describes the current extents of a pair tree in relation to the tree described by a tmpl_t.
Definition tmpl.h:601
Similar to tmpl_rules_t, but used to specify parameters that may change during subsequent resolution ...
Definition tmpl.h:364
Optional arguments passed to vp_tmpl functions.
Definition tmpl.h:332
fr_aka_sim_id_type_t type
fr_pair_t * vp
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
uint8_t disallow_rhs_resolve
map RHS is NOT immediately resolved in the context of the LHS.
Definition tmpl.h:320
tmpl_attr_list_presence_t list_presence
Whether the attribute reference can have a list, forbid it, or require it.
Definition tmpl.h:298
fr_dict_attr_t const * list_def
Default list to use with unqualified attribute reference.
Definition tmpl.h:295
uint8_t bare_word_enum
for v3 compatibility.
Definition tmpl.h:318
fr_dict_t const * dict_def
Default dictionary to use with unqualified attribute references.
Definition tmpl.h:273
Stores an attribute, a value and various bits of other data.
Definition pair.h:68
fr_dict_attr_t const *_CONST da
Dictionary attribute defines the attribute number, vendor and type of the pair.
Definition pair.h:69
#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:514
static TALLOC_CTX * talloc_init_const(char const *name)
Allocate a top level chunk with a constant name.
Definition talloc.h:112
static fr_time_delta_t fr_time_delta_from_sec(int64_t sec)
Definition time.h:590
void tmpl_dcursor_clear(tmpl_dcursor_ctx_t *cc)
Clear any temporary state allocations.
#define tmpl_dcursor_init(_err, _ctx, _cc, _cursor, _request, _vpt)
Maintains state between cursor calls.
const bool fr_assignment_op[T_TOKEN_LAST]
Definition token.c:169
char const * fr_token_name(int token)
Definition token.c:512
fr_table_num_ordered_t const fr_tokens_table[]
Definition token.c:34
const char fr_token_quote[T_TOKEN_LAST]
Convert tokens back to a quoting character.
Definition token.c:157
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_OP_CMP_TRUE
Definition token.h:104
@ T_BARE_WORD
Definition token.h:120
@ T_OP_EQ
Definition token.h:83
@ T_BACK_QUOTED_STRING
Definition token.h:123
@ T_HASH
Definition token.h:119
@ 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_OP_LSHIFT_EQ
Definition token.h:77
@ T_OP_RSHIFT_EQ
Definition token.h:76
@ T_OP_REG_EQ
Definition token.h:102
@ 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_SOLIDUS_QUOTED_STRING
Definition token.h:124
@ T_OP_LT
Definition token.h:101
@ T_OP_REG_NE
Definition token.h:103
@ T_OP_PREPEND
Definition token.h:85
#define T_TOKEN_LAST
Definition token.h:129
static fr_slen_t head
Definition xlat.h:419
ssize_t xlat_aeval_compiled(TALLOC_CTX *ctx, char **out, request_t *request, xlat_exp_head_t const *head, xlat_escape_legacy_t escape, void const *escape_ctx))
Definition xlat_eval.c:1804
fr_slen_t xlat_tokenize_expression(TALLOC_CTX *ctx, xlat_exp_head_t **head, fr_sbuff_t *in, fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules))
Definition xlat_expr.c:3120
bool fr_pair_list_empty(fr_pair_list_t const *list)
Is a valuepair list empty.
#define PAIR_VERIFY(_x)
Definition pair.h:191
void fr_pair_list_sort(fr_pair_list_t *list, fr_cmp_t cmp)
Sort a doubly linked list of fr_pair_ts using merge sort.
fr_pair_t * fr_pair_list_tail(fr_pair_list_t const *list)
Get the tail of a valuepair list.
Definition pair_inline.c:55
#define fr_pair_list_foreach(_list_head, _iter)
Iterate over the contents of a fr_pair_list_t.
Definition pair.h:261
void fr_pair_list_free(fr_pair_list_t *list)
Free memory used by a valuepair list.
void fr_pair_list_append(fr_pair_list_t *dst, fr_pair_list_t *src)
Appends a list of fr_pair_t from a temporary list to a destination list.
void fr_pair_list_prepend(fr_pair_list_t *dst, fr_pair_list_t *src)
Move a list of fr_pair_t from a temporary list to the head of a destination list.
static fr_slen_t fr_pair_aprint_value_quoted(TALLOC_CTX *ctx, char **out, fr_pair_t const *vp, fr_token_t quote) 1(fr_pair_print_value_quoted
#define fr_pair_dcursor_init(_cursor, _list)
Initialises a special dcursor with callbacks that will maintain the attr sublists correctly.
Definition pair.h:591
fr_pair_t * fr_pair_list_head(fr_pair_list_t const *list)
Get the head of a valuepair list.
Definition pair_inline.c:42
static fr_slen_t parent
Definition pair.h:845
char const * fr_strerror(void)
Get the last library error.
Definition strerror.c:553
#define fr_strerror_printf(_fmt,...)
Log to thread local error buffer.
Definition strerror.h:64
#define fr_strerror_const(_msg)
Definition strerror.h:223
#define FR_TYPE_QUOTED
Definition types.h:308
#define fr_type_is_structural(_x)
Definition types.h:388
#define FR_TYPE_STRUCTURAL
Definition types.h:312
#define fr_type_is_leaf(_x)
Definition types.h:389
static char const * fr_type_to_str(fr_type_t type)
Return a static string containing the type name.
Definition types.h:450
fr_sbuff_parse_rules_t const value_parse_rules_solidus_quoted
Definition value.c:558
int fr_value_box_cast(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_type_t dst_type, fr_dict_attr_t const *dst_enumv, fr_value_box_t const *src)
Convert one type of fr_value_box_t to another.
Definition value.c:3574
fr_sbuff_parse_rules_t const * value_parse_rules_quoted[T_TOKEN_LAST]
Parse rules for quoted strings.
Definition value.c:605
int fr_value_box_copy(TALLOC_CTX *ctx, fr_value_box_t *dst, const fr_value_box_t *src)
Copy value data verbatim duplicating any buffers.
Definition value.c:3962
int fr_value_box_cmp_op(fr_token_t op, fr_value_box_t const *a, fr_value_box_t const *b)
Compare two attributes using an operator.
Definition value.c:975
fr_sbuff_parse_rules_t const value_parse_rules_single_quoted
Definition value.c:552
ssize_t fr_value_box_from_str(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_type_t dst_type, fr_dict_attr_t const *dst_enumv, char const *in, size_t inlen, fr_sbuff_unescape_rules_t const *erules)
Definition value.c:5459
int fr_value_box_strdup(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_dict_attr_t const *enumv, char const *src, bool tainted)
Copy a nul terminated string to a fr_value_box_t.
Definition value.c:4158
fr_sbuff_parse_rules_t const value_parse_rules_bareword_quoted
Definition value.c:523
fr_sbuff_parse_rules_t const value_parse_rules_backtick_quoted
Definition value.c:564
fr_sbuff_parse_rules_t const * value_parse_rules_unquoted[T_TOKEN_LAST]
Parse rules for non-quoted strings.
Definition value.c:507
fr_sbuff_unescape_rules_t fr_value_unescape_single
Definition value.c:284
fr_sbuff_parse_rules_t const value_parse_rules_double_quoted
Definition value.c:546
ssize_t fr_value_box_from_substr(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_type_t dst_type, fr_dict_attr_t const *dst_enumv, fr_sbuff_t *in, fr_sbuff_parse_rules_t const *rules)
Convert string value to a fr_value_box_t type.
Definition value.c:4899
#define fr_value_box_alloc(_ctx, _type, _enumv)
Allocate a value box of a specific type.
Definition value.h:640
#define fr_box_strvalue(_val)
Definition value.h:304
static size_t char ** out
Definition value.h:1020