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: 1fa38219d68c784f5fc55c6cea0ddbf71428be2e $
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: 1fa38219d68c784f5fc55c6cea0ddbf71428be2e $")
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 /*
1011 * This prints out any relevant error
1012 * messages. We MAY want to print out
1013 * additional ones, but that might get
1014 * complex and confusing.
1015 *
1016 * We call out internal _map_afrom_cs()
1017 * function, in order to pass in the
1018 * correct parent map.
1019 */
1020 if (_map_afrom_cs(map, &child_list, map, cf_item_to_section(ci),
1021 &child_lhs_rules, rhs_rules, validate, uctx, max, false, edit) < 0) {
1022 map_list_talloc_free(&child_list);
1023 talloc_free(map);
1024 goto error;
1025 }
1026 map_list_move(&map->child, &child_list);
1027
1028 MAP_VERIFY(map);
1029 goto next;
1030 }
1031
1032 if (!cf_item_is_pair(ci)) {
1033 cf_log_err(ci, "Entry is not in \"attribute = value\" format");
1034 goto error;
1035 }
1036
1037 cp = cf_item_to_pair(ci);
1038 fr_assert(cp != NULL);
1039
1040 /*
1041 * Over-ride RHS rules for
1042 *
1043 * &reply += {
1044 * &User-Name = &User-Name
1045 * }
1046 *
1047 * Which looks stupid. Instead we require
1048 *
1049 * &reply += {
1050 * &User-Name = &request.User-Name
1051 * }
1052 *
1053 * On the other hand, any xlats on the RHS don't use the full path. :( And we still need
1054 * to allow relative attribute references via ".foo", when updating structures.
1055 */
1056 our_rhs_rules = rhs_rules;
1057 if (edit && (rhs_rules->attr.list_def != child_lhs_rules.attr.list_def)) {
1058 char const *value = cf_pair_value(cp);
1059
1060 if (value && (*value == '&')) {
1061 child_rhs_rules.attr.list_presence = TMPL_ATTR_LIST_REQUIRE;
1062 our_rhs_rules = &child_rhs_rules;
1063 }
1064 }
1065
1066 if (map_afrom_cp(parent_ctx, &map, parent, cp, &child_lhs_rules, our_rhs_rules, edit) < 0) {
1067 cf_log_err(ci, "Failed creating map from '%s = %s'",
1068 cf_pair_attr(cp), cf_pair_value(cp));
1069 goto error;
1070 }
1071
1072 MAP_VERIFY(map);
1073
1074 /*
1075 * Check the types in the map are valid
1076 */
1077 if (validate && (validate(map, uctx) < 0)) goto error;
1078
1079 next:
1080 parent_ctx = map;
1081 map_list_insert_tail(out, map);
1082 }
1083
1084 talloc_free(tmp_ctx);
1085 return 0;
1086
1087}
1088
1089/** Convert a config section into an attribute map.
1090 *
1091 * For "update" sections, Uses 'name2' of section to set default request and lists.
1092 *
1093 * @param[in] ctx for talloc.
1094 * @param[out] out Where to store the allocated map.
1095 * @param[in] cs the update section
1096 * @param[in] lhs_rules rules for parsing LHS attribute references.
1097 * @param[in] rhs_rules rules for parsing RHS attribute references.
1098 * @param[in] validate map using this callback (may be NULL).
1099 * @param[in] uctx to pass to callback.
1100 * @param[in] max number of mappings to process.
1101 * @return
1102 * - 0 on success.
1103 * - -1 on failure.
1104 */
1105int map_afrom_cs(TALLOC_CTX *ctx, map_list_t *out, CONF_SECTION *cs,
1106 tmpl_rules_t const *lhs_rules, tmpl_rules_t const *rhs_rules,
1107 map_validate_t validate, void *uctx,
1108 unsigned int max)
1109{
1110 bool update;
1111 char const *name2;
1112 map_t *parent = NULL;
1113
1114 name2 = cf_section_name1(cs);
1115 update = (name2 && (strcmp(name2, "update") == 0));
1116
1117 if (ctx) parent = talloc_get_type(ctx, map_t);
1118
1119 return _map_afrom_cs(ctx, out, parent, cs, lhs_rules, rhs_rules, validate, uctx, max, update, false);
1120}
1121
1122/** Convert a config section into an attribute map for editing
1123 *
1124 * @param[in] ctx for talloc.
1125 * @param[out] out Where to store the allocated map.
1126 * @param[in] cs the update section
1127 * @param[in] lhs_rules rules for parsing LHS attribute references.
1128 * @param[in] rhs_rules rules for parsing RHS attribute references.
1129 * @param[in] validate map using this callback (may be NULL).
1130 * @param[in] uctx to pass to callback.
1131 * @param[in] max number of mappings to process.
1132 * @return
1133 * - 0 on success.
1134 * - -1 on failure.
1135 */
1136int map_afrom_cs_edit(TALLOC_CTX *ctx, map_list_t *out, CONF_SECTION *cs,
1137 tmpl_rules_t const *lhs_rules, tmpl_rules_t const *rhs_rules,
1138 map_validate_t validate, void *uctx,
1139 unsigned int max)
1140{
1141 map_t *parent = NULL;
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, false, true);
1146}
1147
1148/** Convert CONFIG_PAIR (which may contain refs) to map_t.
1149 *
1150 * Treats the CONFIG_PAIR name as a value.
1151 *
1152 * Treatment of left operand depends on quotation, barewords are treated as
1153 * attribute , double quoted values are treated as expandable strings,
1154 * single quoted values are treated as literal strings.
1155 *
1156 * Return must be freed with talloc_free
1157 *
1158 * @param[in] ctx for talloc.
1159 * @param[in] out Where to write the pointer to the new #map_t.
1160 * @param[in] parent the parent map
1161 * @param[in] cp to convert to map.
1162 * @param[in] t_rules rules for parsing name
1163 * @return
1164 * - #map_t if successful.
1165 * - NULL on error.
1166 */
1167static int map_value_afrom_cp(TALLOC_CTX *ctx, map_t **out, map_t *parent, CONF_PAIR *cp,
1168 tmpl_rules_t const *t_rules)
1169{
1170 map_t *map;
1171 char const *attr, *marker_subject;
1172 ssize_t slen;
1174
1175 *out = NULL;
1176
1177 if (!cp) return -1;
1178
1179 MEM(map = map_alloc(ctx, parent));
1180 map->op = T_OP_EQ; /* @todo - should probably be T_INVALID */
1181 map->ci = cf_pair_to_item(cp);
1182
1183 attr = cf_pair_attr(cp);
1184
1185 /*
1186 * LHS may be an expansion (that expands to an attribute reference)
1187 * or an attribute reference. Quoting determines which it is.
1188 */
1190 switch (type) {
1194 slen = tmpl_afrom_substr(ctx, &map->lhs,
1195 &FR_SBUFF_IN(attr, talloc_array_length(attr) - 1),
1196 type,
1197 value_parse_rules_unquoted[type], /* We're not searching for quotes */
1198 t_rules);
1199 if (slen <= 0) {
1200 char *spaces, *text;
1201
1202 marker:
1203 marker_subject = attr;
1204 fr_canonicalize_error(ctx, &spaces, &text, slen, marker_subject);
1205 cf_log_err(cp, "%s", text);
1206 cf_log_perr(cp, "%s^", spaces);
1207
1209 talloc_free(text);
1210 goto error;
1211 }
1212 break;
1213
1215 fr_strerror_const("Invalid location for regular expression");
1216 slen = 0;
1217 goto marker;
1218
1219 default:
1220 /*
1221 * Let the tmpl code determine if it's an attribute reference or else is a raw value.
1222 */
1223 slen = tmpl_afrom_substr(ctx, &map->lhs, &FR_SBUFF_IN(attr, talloc_array_length(attr) - 1), T_BARE_WORD, NULL, t_rules);
1224 if (slen <= 0) goto marker;
1225
1226 if (tmpl_is_attr(map->lhs) && (tmpl_attr_unknown_add(map->lhs) < 0)) {
1227 fr_strerror_printf("Failed defining attribute %s", map->lhs->name);
1228 goto error;
1229 }
1230 break;
1231 }
1232
1233 MAP_VERIFY(map);
1234
1235 *out = map;
1236
1237 return 0;
1238
1239error:
1240 talloc_free(map);
1241 return -1;
1242}
1243
1244/*
1245 * Where the RHS are all values.
1246 */
1247static int _map_list_afrom_cs(TALLOC_CTX *ctx, map_list_t *out, map_t *parent, CONF_SECTION *cs,
1248 tmpl_rules_t const *t_rules,
1249 map_validate_t validate, void *uctx,
1250 unsigned int max)
1251{
1252 CONF_ITEM *ci;
1253 CONF_PAIR *cp;
1254
1255 unsigned int total = 0;
1256 map_t *map;
1257 TALLOC_CTX *parent_ctx;
1258
1259 /*
1260 * The first map has ctx as the parent context.
1261 * The rest have the previous map as the parent context.
1262 */
1263 parent_ctx = ctx;
1264
1265 for (ci = cf_item_next(cs, NULL);
1266 ci != NULL;
1267 ci = cf_item_next(cs, ci)) {
1268 if (total++ == max) {
1269 cf_log_err(ci, "Map size exceeded");
1270 error:
1271 /*
1272 * Free in reverse as successive entries have their
1273 * prececessors as talloc parent contexts
1274 */
1275 map_list_talloc_reverse_free(out);
1276 return -1;
1277 }
1278
1279 if (cf_item_is_section(ci)) {
1280 cf_log_err(ci, "Cannot create sub-lists");
1281 goto error;
1282 }
1283
1284 cp = cf_item_to_pair(ci);
1285 fr_assert(cp != NULL);
1286
1287 if (map_value_afrom_cp(parent_ctx, &map, parent, cp, t_rules) < 0) {
1288 cf_log_err(ci, "Failed creating map from '%s'", cf_pair_attr(cp));
1289 goto error;
1290 }
1291
1292 MAP_VERIFY(map);
1293
1294 /*
1295 * Check the types in the map are valid
1296 */
1297 if (validate && (validate(map, uctx) < 0)) goto error;
1298
1299 parent_ctx = map;
1300 map_list_insert_tail(out, map);
1301 }
1302
1303 return 0;
1304
1305}
1306
1307/** Convert a config section into a list of { a, b, c, d, ... }
1308 *
1309 * @param[in] ctx for talloc.
1310 * @param[out] out Where to store the allocated map.
1311 * @param[in] cs the update section
1312 * @param[in] t_rules rules for parsing the data.
1313 * @param[in] validate map using this callback (may be NULL).
1314 * @param[in] uctx to pass to callback.
1315 * @param[in] max number of mappings to process.
1316 * @return
1317 * - 0 on success.
1318 * - -1 on failure.
1319 */
1320int map_list_afrom_cs(TALLOC_CTX *ctx, map_list_t *out, CONF_SECTION *cs,
1321 tmpl_rules_t const *t_rules,
1322 map_validate_t validate, void *uctx,
1323 unsigned int max)
1324{
1325 map_t *parent = NULL;
1326
1327 if (ctx) parent = talloc_get_type(ctx, map_t);
1328
1329 return _map_list_afrom_cs(ctx, out, parent, cs, t_rules, validate, uctx, max);
1330}
1331
1332/** Convert a value box to a map
1333 *
1334 * This is mainly used in IO modules, where another function is used to convert
1335 * between the foreign value type and internal values, and the destination
1336 * attribute is provided as a string.
1337 *
1338 * @param[in] ctx for talloc
1339 * @param[out] out Where to store the head of the map.
1340 * @param[in] lhs of the operation
1341 * @param[in] lhs_quote type of the LHS string
1342 * @param[in] lhs_rules rules that control parsing of the LHS string.
1343 * @param[in] op the operation to perform
1344 * @param[in] rhs of the operation
1345 * @param[in] steal_rhs_buffs Whether we attempt to save allocs by stealing the buffers
1346 * from the rhs #fr_value_box_t.
1347 * @return
1348 * - #map_t if successful.
1349 * - NULL on error.
1350 */
1351int map_afrom_value_box(TALLOC_CTX *ctx, map_t **out,
1352 char const *lhs, fr_token_t lhs_quote, tmpl_rules_t const *lhs_rules,
1353 fr_token_t op,
1354 fr_value_box_t *rhs, bool steal_rhs_buffs)
1355{
1356 ssize_t slen;
1357 map_t *map;
1358
1359 map = map_alloc(ctx, NULL);
1360
1361 slen = tmpl_afrom_substr(map, &map->lhs,
1362 &FR_SBUFF_IN(lhs, strlen(lhs)),
1363 lhs_quote,
1364 NULL,
1365 lhs_rules);
1366 if (slen < 0) {
1367 error:
1368 talloc_free(map);
1369 return -1;
1370 }
1371
1372 map->op = op;
1373
1374 if (tmpl_afrom_value_box(map, &map->rhs, rhs, steal_rhs_buffs) < 0) goto error;
1375
1376 MAP_VERIFY(map);
1377 *out = map;
1378
1379 return 0;
1380}
1381
1382/** Convert a value pair string to valuepair map
1383 *
1384 * Takes a valuepair string with list and request qualifiers and converts it into a
1385 * #map_t.
1386 *
1387 * Attribute string is in the format (where @verbatim <qu> @endverbatim is a quotation char ['"]):
1388 @verbatim
1389 [<list>.][<qu>]<attribute>[<qu>] <op> [<qu>]<value>[<qu>]
1390 @endverbatim
1391 *
1392 * @param[in] ctx where to allocate the map.
1393 * @param[out] out Where to write the new map.
1394 * @param[in] vp_str string to parse.
1395 * @param[in] lhs_rules rules for parsing LHS attribute references.
1396 * @param[in] rhs_rules rules for parsing RHS attribute references.
1397 * @return
1398 * - 0 on success.
1399 * - < 0 on error.
1400 */
1401int map_afrom_attr_str(TALLOC_CTX *ctx, map_t **out, char const *vp_str,
1402 tmpl_rules_t const *lhs_rules, tmpl_rules_t const *rhs_rules)
1403{
1404 fr_sbuff_t sbuff = FR_SBUFF_IN(vp_str, strlen(vp_str));
1405
1407 lhs_rules, rhs_rules, NULL) < 0) {
1408 return -1;
1409 }
1410
1411 if (!fr_cond_assert(*out != NULL)) return -1;
1412
1413 if (!tmpl_is_attr((*out)->lhs)) {
1414 TALLOC_FREE(*out);
1415 fr_strerror_const("Left operand must be an attribute");
1416 return -1;
1417 }
1418
1419 return 0;
1420}
1421
1422/** Convert a fr_pair_t into a map
1423 *
1424 * @param[in] ctx where to allocate the map.
1425 * @param[out] out Where to write the new map (must be freed with talloc_free()).
1426 * @param[in] vp to convert.
1427 * @param[in] rules to insert attributes into.
1428 * @return
1429 * - 0 on success.
1430 * - -1 on failure.
1431 */
1432int map_afrom_vp(TALLOC_CTX *ctx, map_t **out, fr_pair_t *vp, tmpl_rules_t const *rules)
1433{
1434 char buffer[256];
1435 fr_sbuff_t buffer_sbuff = FR_SBUFF_OUT(buffer, sizeof(buffer));
1436
1437 map_t *map;
1438
1439 map = map_alloc(ctx, NULL);
1440 if (!map) {
1441 oom:
1442 fr_strerror_const("Out of memory");
1443 return -1;
1444 }
1445
1446 /*
1447 * Allocate the LHS
1448 */
1449 map->lhs = tmpl_alloc(map, TMPL_TYPE_ATTR, T_BARE_WORD, NULL, 0);
1450 if (!map->lhs) goto oom;
1451
1453
1454 tmpl_attr_set_request_ref(map->lhs, rules->attr.request_def);
1455 tmpl_attr_set_list(map->lhs, rules->attr.list_def);
1456
1457 tmpl_print(&buffer_sbuff, map->lhs, NULL);
1458 tmpl_set_name(map->lhs, T_BARE_WORD, fr_sbuff_start(&buffer_sbuff), -1);
1459
1460 /*
1461 * Allocate the RHS
1462 */
1463 map->rhs = tmpl_alloc(map, TMPL_TYPE_DATA, T_BARE_WORD, NULL, -1);
1464 if (!map->lhs) goto oom;
1465
1466 switch (vp->vp_type) {
1467 case FR_TYPE_QUOTED:
1468 tmpl_set_name_printf(map->rhs, T_DOUBLE_QUOTED_STRING, "%pV", &vp->data);
1469 break;
1470
1471 default:
1472 tmpl_set_name_printf(map->rhs, T_BARE_WORD, "%pV", &vp->data);
1473 break;
1474 }
1475
1476 fr_value_box_copy(map->rhs, tmpl_value(map->rhs), &vp->data);
1477
1478 *out = map;
1479
1480 return 0;
1481}
1482
1483/** Process map which has exec as a src
1484 *
1485 * Evaluate maps which specify exec as a src. This may be used by various sorts of update sections, and so
1486 * has been broken out into it's own function.
1487 *
1488 * @param[in,out] ctx to allocate new #fr_pair_t (s) in.
1489 * @param[out] out Where to write the #fr_pair_t (s).
1490 * @param[in] request structure (used only for talloc).
1491 * @param[in] map the map. The LHS (dst) must be #TMPL_TYPE_ATTR.
1492 * The RHS (src) must be #TMPL_TYPE_EXEC.
1493 * @return
1494 * - 0 on success.
1495 * - -1 on failure.
1496 */
1497static int map_exec_to_vp(TALLOC_CTX *ctx, fr_pair_list_t *out, request_t *request, map_t const *map)
1498{
1499 int result;
1500 fr_pair_t *vp;
1501 fr_pair_list_t *input_pairs = NULL;
1502 char answer[1024];
1503
1505
1506 MAP_VERIFY(map);
1507
1508 fr_assert(map->rhs); /* Quite clang scan */
1509 fr_assert(tmpl_is_exec(map->rhs));
1510 fr_assert(tmpl_is_attr(map->lhs));
1511
1512 if (fr_type_is_structural(tmpl_attr_tail_da(map->lhs)->type)) {
1513 REDEBUG("Cannot assign `exec` output to structural attribute %s", map->lhs->name);
1514 return -1;
1515 }
1516
1517 /*
1518 * We always put the request pairs into the environment
1519 */
1520 input_pairs = tmpl_list_head(request, request_attr_request);
1521
1522 /*
1523 * Automagically switch output type depending on our destination
1524 * @todo - If dst is a list, then we create attributes from the output of the program
1525 * if dst is an attribute, then we create an attribute of that type and then
1526 * call fr_pair_value_from_str on the output of the script.
1527 */
1528 result = radius_exec_program_legacy(answer, sizeof(answer),
1529 request, map->rhs->name, input_pairs ? input_pairs : NULL,
1531 if (result != 0) {
1532 REDEBUG("Exec failed with code (%i)", result);
1533 return -1;
1534 }
1535
1536 /*
1537 * @todo - we completely ignore the operator here :( Arguably the caller should be calling ONLY
1538 * the legacy pair move functions with the results of this function.
1539 */
1541 vp->op = map->op;
1542 if (fr_pair_value_from_str(vp, answer, strlen(answer), &fr_value_unescape_single, false) < 0) {
1543 RPEDEBUG("Failed parsing exec output");
1544 talloc_free(&vp);
1545 return -2;
1546 }
1548
1549 return 0;
1550}
1551
1552/** Convert a map to a #fr_pair_t
1553 *
1554 * @param[in,out] ctx to allocate #fr_pair_t (s) in.
1555 * @param[out] out Where to write the #fr_pair_t (s), which may be NULL if not found
1556 * @param[in] request The current request.
1557 * @param[in] map the map. The LHS (dst) has to be #TMPL_TYPE_ATTR.
1558 * @param[in] uctx unused.
1559 * @return
1560 * - 0 on success.
1561 * - -1 on failure.
1562 */
1563int map_to_vp(TALLOC_CTX *ctx, fr_pair_list_t *out, request_t *request, map_t const *map, UNUSED void *uctx)
1564{
1565 int rcode = 0;
1566 fr_pair_t *n = NULL;
1567 fr_pair_list_t found;
1568 request_t *context = request;
1569 ssize_t slen;
1570 char *str;
1571
1572 fr_pair_list_init(&found);
1574
1575 MAP_VERIFY(map);
1576 if (!fr_cond_assert(map->lhs != NULL)) return -1;
1577
1578 fr_assert(tmpl_is_attr(map->lhs));
1579
1580 /*
1581 * If there's no RHS, then it MUST be an attribute, and
1582 * it MUST be structural. And it MAY have children.
1583 */
1584 if (!map->rhs) {
1585 map_t *child;
1586
1587 if (!tmpl_is_attr(map->lhs)) return -1;
1588
1589 switch (tmpl_attr_tail_da(map->lhs)->type) {
1590 case FR_TYPE_STRUCTURAL:
1591 break;
1592
1593 default:
1594 return -1;
1595 }
1596
1597 /*
1598 * Create the parent attribute, and
1599 * recurse to generate the children into
1600 * vp->vp_group
1601 */
1603 n->op = map->op;
1604
1605 for (child = map_list_next(&map->child, NULL);
1606 child != NULL;
1607 child = map_list_next(&map->child, child)) {
1608 fr_pair_list_t list;
1609
1610 /*
1611 * map_to_vp() frees "out", so we need to
1612 * work around that by creating a
1613 * temporary list.
1614 */
1615 fr_pair_list_init(&list);
1616 if (map_to_vp(n, &list, request, child, NULL) < 0) {
1617 talloc_free(n);
1618 return -1;
1619 }
1620
1621 fr_pair_list_append(&n->vp_group, &list);
1622 }
1623
1625 return 0;
1626 }
1627
1628 /*
1629 * List to list found, this is a special case because we don't need
1630 * to allocate any attributes, just finding the current list, and change
1631 * the op.
1632 */
1635 fr_pair_list_t *from = NULL;
1636
1637 if (tmpl_request_ptr(&context, tmpl_request(map->rhs)) == 0) {
1638 from = tmpl_list_head(context, tmpl_list(map->rhs));
1639 }
1640 if (!from) return 0;
1641
1642 if (fr_pair_list_copy(ctx, &found, from) < 0) return -1;
1643
1644 /*
1645 * List to list copy is empty if the src list has no attributes.
1646 */
1647 if (fr_pair_list_empty(&found)) return 0;
1648
1649 fr_pair_list_foreach(&found, vp) {
1650 vp->op = T_OP_ADD_EQ;
1651 }
1652
1653 fr_pair_list_append(out, &found);
1654
1655 return 0;
1656 }
1657
1658 /*
1659 * And parse the RHS
1660 */
1661 switch (map->rhs->type) {
1662 case TMPL_TYPE_XLAT:
1663 fr_assert(tmpl_is_attr(map->lhs));
1664 fr_assert(tmpl_attr_tail_da(map->lhs)); /* We need to know which attribute to create */
1665 fr_assert(tmpl_xlat(map->rhs) != NULL);
1666
1668
1669 /*
1670 * We do the debug printing because xlat_aeval_compiled
1671 * doesn't have access to the original string. It's been
1672 * mangled during the parsing to an internal data structure
1673 */
1674 RDEBUG2("EXPAND %s", map->rhs->name);
1675 RINDENT();
1676
1677 str = NULL;
1678 slen = xlat_aeval_compiled(request, &str, request, tmpl_xlat(map->rhs), NULL, NULL);
1679 REXDENT();
1680
1681 if (slen < 0) {
1682 rcode = slen;
1683 goto error;
1684 }
1685
1686 RDEBUG2("--> %s", str);
1687
1688 rcode = fr_pair_value_from_str(n, str, strlen(str), NULL, false);
1689 talloc_free(str);
1690 if (rcode < 0) {
1691 goto error;
1692 }
1693
1694 n->op = map->op;
1696 break;
1697
1699 fr_assert(tmpl_is_attr(map->lhs));
1700 fr_assert(tmpl_attr_tail_da(map->lhs)); /* We need to know which attribute to create */
1701
1703
1704 if (fr_pair_value_from_str(n, map->rhs->name, strlen(map->rhs->name), NULL, false) < 0) {
1705 rcode = 0;
1706 goto error;
1707 }
1708 n->op = map->op;
1710 break;
1711
1712 case TMPL_TYPE_ATTR:
1713 {
1714 fr_pair_t *vp;
1715 fr_dcursor_t from;
1716
1718
1719 /*
1720 * @todo should log error, and return -1 for v3.1 (causes update to fail)
1721 */
1722 if (tmpl_copy_pairs(ctx, &found, request, map->rhs) < 0) return 0;
1723
1724 vp = fr_pair_dcursor_init(&from, &found);
1725
1726 /*
1727 * Src/Dst attributes don't match, convert src attributes
1728 * to match dst.
1729 */
1730 if (tmpl_is_attr(map->lhs) && tmpl_attr_tail_da_is_leaf(map->lhs) &&
1731 (tmpl_attr_tail_da(map->rhs)->type != tmpl_attr_tail_da(map->lhs)->type)) {
1732 for (; vp; vp = fr_dcursor_current(&from)) {
1734
1735 if (fr_value_box_cast(n, &n->data,
1736 tmpl_attr_tail_da(map->lhs)->type, tmpl_attr_tail_da(map->lhs), &vp->data) < 0) {
1737 RPEDEBUG("Attribute conversion failed");
1738 fr_pair_list_free(&found);
1739 talloc_free(n);
1740 return -1;
1741 }
1742 vp = fr_dcursor_remove(&from); /* advances cursor */
1743 talloc_free(vp);
1744
1745 fr_assert((n->vp_type != FR_TYPE_STRING) || (n->vp_strvalue != NULL));
1746
1747 n->op = map->op;
1749 }
1750
1751 return 0;
1752 }
1753
1754 /*
1755 * Otherwise we just need to fixup the attribute types
1756 * and operators
1757 */
1758 for (; vp; vp = fr_dcursor_next(&from)) {
1760 vp->op = map->op;
1761 }
1762 fr_pair_list_append(out, &found);
1763 }
1764 break;
1765
1766 case TMPL_TYPE_DATA:
1768 fr_assert(tmpl_is_attr(map->lhs));
1769
1771
1772 if (tmpl_attr_tail_da(map->lhs)->type == tmpl_value_type(map->rhs)) {
1773 if (fr_value_box_copy(n, &n->data, tmpl_value(map->rhs)) < 0) {
1774 rcode = -1;
1775 goto error;
1776 }
1777
1778 } else if (fr_value_box_cast(n, &n->data, n->vp_type, n->da, tmpl_value(map->rhs)) < 0) {
1779 RPEDEBUG("Implicit cast failed");
1780 rcode = -1;
1781 goto error;
1782 }
1783 n->op = map->op;
1785
1786 MAP_VERIFY(map);
1787 break;
1788
1789 /*
1790 * This essentially does the same as rlm_exec xlat, except it's non-configurable.
1791 * It's only really here as a convenience for people who expect the contents of
1792 * backticks to be executed in a shell.
1793 *
1794 * exec string is xlat expanded and arguments are shell escaped.
1795 */
1796 case TMPL_TYPE_EXEC:
1797 return map_exec_to_vp(ctx, out, request, map);
1798
1799 default:
1800 fr_assert(0); /* Should have been caught at parse time */
1801
1802 error:
1803 talloc_free(n);
1804 return rcode;
1805 }
1806
1807 return 0;
1808}
1809
1810#define DEBUG_OVERWRITE(_old, _new) \
1811do {\
1812 if (RDEBUG_ENABLED3) {\
1813 char *our_old; \
1814 char *our_new; \
1815 fr_pair_aprint_value_quoted(request, &our_old, _old, T_DOUBLE_QUOTED_STRING); \
1816 fr_pair_aprint_value_quoted(request, &our_new, _new, T_DOUBLE_QUOTED_STRING); \
1817 RINDENT(); \
1818 RDEBUG3("--> overwriting %s with %s", our_old, our_new); \
1819 REXDENT(); \
1820 talloc_free(our_old); \
1821 talloc_free(our_new); \
1822 } \
1823} while (0)
1824
1825/** Convert #map_t to #fr_pair_t (s) and add them to a #request_t.
1826 *
1827 * Takes a single #map_t, resolves request and list identifiers
1828 * to pointers in the current request, then attempts to retrieve module
1829 * specific value(s) using callback, and adds the resulting values to the
1830 * correct request/list.
1831 *
1832 * @param request The current request.
1833 * @param map specifying destination attribute and location and src identifier.
1834 * @param func to retrieve module specific values and convert them to
1835 * #fr_pair_t.
1836 * @param ctx to be passed to func.
1837 * @return
1838 * - -1 if the operation failed.
1839 * - -2 in the source attribute wasn't valid.
1840 * - 0 on success.
1841 */
1842int map_to_request(request_t *request, map_t const *map, radius_map_getvalue_t func, void *ctx)
1843{
1844 int rcode = 0;
1845 fr_pair_t *dst;
1846 fr_pair_list_t *list, src_list;
1847 request_t *context, *tmp_ctx = NULL;
1848 TALLOC_CTX *parent;
1849 fr_dcursor_t dst_list;
1850
1851 bool found = false;
1852
1853 map_t exp_map;
1854 tmpl_t *exp_lhs;
1855 fr_dict_attr_t const *list_ref;
1856
1857 tmpl_dcursor_ctx_t cc = {};
1858
1859 fr_pair_list_init(&src_list);
1860 MAP_VERIFY(map);
1861 fr_assert(map->lhs != NULL);
1862 fr_assert(map->rhs != NULL);
1863
1864 /*
1865 * This function is called only when creating attributes. It cannot be called for conditions.
1866 */
1867 if (fr_comparison_op[map->op]) {
1868 REDEBUG("Invalid operator in %s %s ...", map->lhs->name, fr_tokens[map->op]);
1869 return -1;
1870 }
1871
1872 tmp_ctx = talloc_pool(request, 1024);
1873
1874 /*
1875 * Preprocessing of the LHS of the map.
1876 */
1877 switch (map->lhs->type) {
1878 /*
1879 * Already in the correct form.
1880 */
1881 case TMPL_TYPE_ATTR:
1882 break;
1883
1884 /*
1885 * Everything else gets expanded, then re-parsed as an attribute reference.
1886 *
1887 * This allows the syntax like:
1888 * - "Attr-%{number}" := "value"
1889 */
1890 case TMPL_TYPE_XLAT:
1891 case TMPL_TYPE_EXEC:
1892 {
1893 char *attr_str;
1894 ssize_t slen;
1895
1896 slen = tmpl_aexpand(request, &attr_str, request, map->lhs, NULL, NULL);
1897 if (slen <= 0) {
1898 RPEDEBUG("Left side expansion failed");
1899 fr_assert(!attr_str);
1900 rcode = -1;
1901 goto finish;
1902 }
1903
1904 slen = tmpl_afrom_attr_str(tmp_ctx, NULL, &exp_lhs, attr_str,
1905 &(tmpl_rules_t){
1906 .attr = {
1907 .dict_def = request->local_dict,
1908 .list_def = request_attr_request,
1909 }
1910 });
1911 if (slen <= 0) {
1912 RPEDEBUG("Left side expansion result \"%s\" is not an attribute reference", attr_str);
1913 talloc_free(attr_str);
1914 rcode = -1;
1915 goto finish;
1916 }
1917 fr_assert(tmpl_is_attr(exp_lhs));
1918
1919 memcpy(&exp_map, map, sizeof(exp_map));
1920 exp_map.lhs = exp_lhs;
1921 map = &exp_map;
1922 }
1923 break;
1924
1925 default:
1926 fr_assert(0);
1927 break;
1928 }
1929
1930
1931 /*
1932 * Sanity check inputs. We can have a list or attribute
1933 * as a destination.
1934 */
1935 if (!tmpl_is_attr(map->lhs)) {
1936 REDEBUG("Left side \"%.*s\" of map should be an attr or list but is an %s",
1937 (int)map->lhs->len, map->lhs->name,
1938 tmpl_type_to_str(map->lhs->type));
1939 rcode = -2;
1940 goto finish;
1941 }
1942
1943 context = request;
1944 if (tmpl_request_ptr(&context, tmpl_request(map->lhs)) < 0) {
1945 RPEDEBUG("Mapping \"%.*s\" -> \"%.*s\" cannot be performed due to error in left side of map",
1946 (int)map->rhs->len, map->rhs->name, (int)map->lhs->len, map->lhs->name);
1947 rcode = -2;
1948 goto finish;
1949 }
1950
1951 list_ref = tmpl_list(map->lhs);
1952 list = tmpl_list_head(context, list_ref);
1953 if (!list) {
1954 REDEBUG("Mapping \"%.*s\" -> \"%.*s\" cannot be performed due to to invalid list qualifier \"%s\" in left side of map",
1955 (int)map->rhs->len, map->rhs->name, (int)map->lhs->len, map->lhs->name,
1956 tmpl_list_name(list_ref, "<INVALID>"));
1957 rcode = -2;
1958 goto finish;
1959 }
1960
1963
1964 /*
1965 * The callback should either return -1 to signify operations error,
1966 * -2 when it can't find the attribute or list being referenced, or
1967 * 0 to signify success. It may return "success", but still have no
1968 * VPs to work with.
1969 */
1970 rcode = func(parent, &src_list, request, map, ctx);
1971 if (rcode < 0) {
1972 fr_assert(fr_pair_list_empty(&src_list));
1973 goto finish;
1974 }
1975 if (fr_pair_list_empty(&src_list)) {
1976 RDEBUG2("%.*s skipped: No values available", (int)map->lhs->len, map->lhs->name);
1977 goto finish;
1978 }
1979
1980 /*
1981 * Print the VPs
1982 */
1983#ifndef WITH_VERIFY_PTR
1984 if (RDEBUG_ENABLED)
1985#endif
1986 {
1987 fr_pair_list_foreach(&src_list, vp) {
1988 PAIR_VERIFY(vp);
1989
1990 if (RDEBUG_ENABLED) map_debug_log(request, map, vp);
1991 }
1992 }
1993
1994 /*
1995 * The destination is a list (which is a completely different set of operations)
1996 */
1997 if (tmpl_is_list(map->lhs)) {
1998 switch (map->op) {
1999 case T_OP_CMP_FALSE:
2000 /* We don't need the src VPs (should just be 'ANY') */
2001 fr_assert(fr_pair_list_empty(&src_list));
2002
2003 /* Clear the entire dst list */
2004 fr_pair_list_free(list);
2005 goto finish;
2006
2007 case T_OP_SET:
2008 if (tmpl_is_list(map->rhs)) {
2009 fr_pair_list_free(list);
2010 fr_pair_list_append(list, &src_list);
2011 fr_pair_list_init(&src_list);
2012 } else {
2014
2015 case T_OP_EQ:
2016 fr_assert(tmpl_is_exec(map->rhs));
2018
2019 case T_OP_ADD_EQ:
2020 fr_pair_list_move_op(list, &src_list, T_OP_ADD_EQ);
2021 }
2022 goto update;
2023
2024 case T_OP_PREPEND:
2025 fr_pair_list_move_op(list, &src_list, T_OP_PREPEND);
2026 goto update;
2027
2028 default:
2029 fr_pair_list_free(&src_list);
2030 rcode = -1;
2031 goto finish;
2032 }
2033 }
2034
2035 /*
2036 * Find the destination attribute. We leave with either
2037 * the dst_list and vp pointing to the attribute or the VP
2038 * being NULL (no attribute at that index).
2039 */
2040 dst = tmpl_dcursor_init(NULL, tmp_ctx, &cc, &dst_list, request, map->lhs);
2041 /*
2042 * The destination is an attribute
2043 */
2044 switch (map->op) {
2045 default:
2046 break;
2047 /*
2048 * !* - Remove all attributes which match dst in the specified list.
2049 * This doesn't use attributes returned by the func(), and immediately frees them.
2050 */
2051 case T_OP_CMP_FALSE:
2052 /* We don't need the src VPs (should just be 'ANY') */
2053 fr_assert(fr_pair_list_empty(&src_list));
2054 if (!dst) goto finish;
2055
2056 /*
2057 * Wildcard: delete all of the matching ones
2058 */
2059 if (tmpl_attr_tail_num(map->lhs) == NUM_UNSPEC) {
2060 fr_pair_delete_by_child_num(list, tmpl_attr_tail_da(map->lhs)->parent, tmpl_attr_tail_da(map->lhs)->attr);
2061 dst = NULL;
2062 /*
2063 * We've found the Nth one. Delete it, and only it.
2064 */
2065 } else {
2066 dst = fr_dcursor_remove(&dst_list);
2067 talloc_free(dst);
2068 }
2069
2070 /*
2071 * Check that the User-Name and User-Password
2072 * caches point to the correct attribute.
2073 */
2074 goto update;
2075
2076 /*
2077 * -= - Delete attributes in the dst list which match any of the
2078 * src_list attributes.
2079 *
2080 * This operation has two modes:
2081 * - If tmpl_attr_tail_num(map->lhs) > 0, we check each of the src_list attributes against
2082 * the dst attribute, to see if any of their values match.
2083 * - If tmpl_attr_tail_num(map->lhs) == NUM_UNSPEC, we compare all instances of the dst attribute
2084 * against each of the src_list attributes.
2085 */
2086 case T_OP_SUB_EQ:
2087 /* We didn't find any attributes earlier */
2088 if (!dst) {
2089 fr_pair_list_free(&src_list);
2090 goto finish;
2091 }
2092
2093 /*
2094 * Instance specific[n] delete
2095 */
2096 if (tmpl_attr_tail_num(map->lhs) != NUM_UNSPEC) {
2097 fr_pair_list_foreach(&src_list, vp) {
2098 vp->op = T_OP_CMP_EQ;
2099 rcode = paircmp_pairs(request, vp, dst);
2100 if (rcode == 0) {
2101 dst = fr_dcursor_remove(&dst_list);
2102 talloc_free(&dst);
2103 found = true;
2104 }
2105 }
2106 rcode = 0;
2107 fr_pair_list_free(&src_list);
2108 if (!found) goto finish;
2109 goto update;
2110 }
2111
2112 /*
2113 * All instances[*] delete
2114 */
2115 for (dst = fr_dcursor_current(&dst_list);
2116 dst;
2118 fr_pair_list_foreach(&src_list, vp) {
2119 vp->op = T_OP_CMP_EQ;
2120 rcode = paircmp_pairs(request, vp, dst);
2121 if (rcode == 0) {
2122 dst = fr_dcursor_remove(&dst_list);
2123 talloc_free(&dst);
2124 found = true;
2125 }
2126 }
2127 }
2128 rcode = 0;
2129 fr_pair_list_free(&src_list);
2130 if (!found) goto finish;
2131 goto update;
2132 }
2133
2134 switch (map->op) {
2135 /*
2136 * = - Set only if not already set
2137 */
2138 case T_OP_EQ:
2139 {
2140 tmpl_attr_extent_t *extent = NULL;
2141 fr_dlist_head_t leaf;
2142 fr_dlist_head_t interior;
2143 fr_pair_t *src_vp;
2144
2145 if (dst) {
2146 RDEBUG3("Refusing to overwrite (use :=)");
2147 fr_pair_list_free(&src_list);
2148 goto finish;
2149 }
2150
2152 fr_dlist_talloc_init(&interior, tmpl_attr_extent_t, entry);
2153
2154 /*
2155 * Find out what we need to build and build it
2156 */
2157 if ((tmpl_extents_find(tmp_ctx, &leaf, &interior, request, map->lhs) < 0) ||
2158 (tmpl_extents_build_to_leaf_parent(&leaf, &interior, map->lhs) < 0)) {
2159 fr_dlist_talloc_free(&leaf);
2160 fr_dlist_talloc_free(&interior);
2161 rcode = -1;
2162 goto finish;
2163 }
2164
2165 /*
2166 * Need to copy src to all dsts
2167 */
2168 src_vp = fr_pair_list_head(&src_list);
2169 if (!src_vp) {
2170 fr_dlist_talloc_free(&leaf);
2171 rcode = -1;
2172 goto finish;
2173 }
2174
2175 if (fr_dlist_num_elements(&leaf) > 1) {
2176 while ((extent = fr_dlist_tail(&leaf))) {
2177 fr_pair_append(extent->list, fr_pair_copy(extent->list_ctx, src_vp));
2179 }
2180 } else {
2181 extent = fr_dlist_head(&leaf);
2182 fr_pair_append(extent->list, fr_pair_copy(extent->list_ctx, src_vp));
2184 }
2185
2186 /* Free any we didn't insert */
2187 fr_pair_list_free(&src_list);
2188 fr_assert(fr_dlist_num_elements(&interior) == 0);
2189 fr_assert(fr_dlist_num_elements(&leaf) == 0);
2190 }
2191 break;
2192
2193 /*
2194 * := - Overwrite existing attribute with last src_list attribute
2195 */
2196 case T_OP_SET:
2197 {
2198 tmpl_attr_extent_t *extent = NULL;
2199 fr_dlist_head_t leaf;
2200 fr_dlist_head_t interior;
2201 fr_pair_t *src_vp;
2202
2203 src_vp = fr_pair_list_tail(&src_list);
2204
2205 if (dst) {
2206 DEBUG_OVERWRITE(dst, src_vp);
2207
2208 fr_pair_reinit_from_da(NULL, dst, src_vp->da);
2209 fr_pair_value_copy(dst, src_vp);
2210
2211 goto op_set_done;
2212 }
2213
2215 fr_dlist_talloc_init(&interior, tmpl_attr_extent_t, entry);
2216
2217 /*
2218 * Find out what we need to build and build it
2219 */
2220 if ((tmpl_extents_find(tmp_ctx, &leaf, &interior, request, map->lhs) < 0) ||
2221 (tmpl_extents_build_to_leaf_parent(&leaf, &interior, map->lhs) < 0)) {
2222 op_set_error:
2223 fr_dlist_talloc_free(&leaf);
2224 fr_dlist_talloc_free(&interior);
2225 rcode = -1;
2226 goto finish;
2227 }
2228
2229 if (fr_dlist_num_elements(&leaf) > 1) {
2230 ERROR("Not yet supported");
2231
2232 goto op_set_error;
2233 } else {
2234 extent = fr_dlist_head(&leaf);
2235 fr_pair_append(extent->list, fr_pair_copy(extent->list_ctx, src_vp));
2236 }
2237
2238 fr_assert(fr_dlist_num_elements(&interior) == 0);
2239 fr_dlist_talloc_free(&leaf);
2240
2241 op_set_done:
2242 /* Free any we didn't insert */
2243 fr_pair_list_free(&src_list);
2244 }
2245 break;
2246
2247 /*
2248 * ^= - Prepend src_list attributes to the destination
2249 */
2250 case T_OP_PREPEND:
2251 fr_pair_list_prepend(list, &src_list);
2252 fr_pair_list_free(&src_list);
2253 break;
2254
2255 /*
2256 * += - Add all src_list attributes to the destination
2257 */
2258 case T_OP_ADD_EQ:
2259 {
2260 tmpl_attr_extent_t *extent = NULL;
2261 fr_dlist_head_t leaf;
2262 fr_dlist_head_t interior;
2263
2265 fr_dlist_talloc_init(&interior, tmpl_attr_extent_t, entry);
2266
2267 /*
2268 * Find out what we need to build and build it
2269 */
2270 if ((tmpl_extents_find(tmp_ctx, &leaf, &interior, request, map->lhs) < 0) ||
2271 (tmpl_extents_build_to_leaf_parent(&leaf, &interior, map->lhs) < 0)) {
2272 fr_dlist_talloc_free(&leaf);
2273 fr_dlist_talloc_free(&interior);
2274 rcode = -1;
2275 goto finish;
2276 }
2277
2278 if (fr_dlist_num_elements(&leaf) > 1) {
2279 while ((extent = fr_dlist_tail(&leaf))) {
2280 (void) fr_pair_list_copy(extent->list_ctx, extent->list, &src_list);
2282 }
2283 /* Free all the src vps */
2284 fr_pair_list_free(&src_list);
2285 } else {
2286 extent = fr_dlist_head(&leaf);
2287 (void) fr_pair_list_copy(extent->list_ctx, extent->list, &src_list);
2289 }
2290
2291 fr_pair_list_free(&src_list);
2292 fr_assert(fr_dlist_num_elements(&interior) == 0);
2293 fr_assert(fr_dlist_num_elements(&leaf) == 0);
2294 }
2295 break;
2296
2297 /*
2298 * Filter operators
2299 */
2300 case T_OP_NE:
2301 case T_OP_CMP_EQ:
2302 case T_OP_GE:
2303 case T_OP_GT:
2304 case T_OP_LE:
2305 case T_OP_LT:
2306 {
2307 fr_pair_t *a;
2308
2311
2312 fr_dcursor_head(&dst_list);
2313
2314 fr_pair_list_foreach(&src_list, b) {
2315 for (a = fr_dcursor_current(&dst_list);
2316 a;
2317 a = fr_dcursor_next(&dst_list)) {
2318 int8_t cmp;
2319
2320 cmp = fr_pair_cmp_by_da(a, b); /* attribute and tag match */
2321 if (cmp > 0) break;
2322 else if (cmp < 0) continue;
2323
2324 cmp = (fr_value_box_cmp_op(map->op, &a->data, &b->data) == 0);
2325 if (cmp != 0) {
2326 a = fr_dcursor_remove(&dst_list);
2327 talloc_free(a);
2328 }
2329 }
2330 if (!a) break; /* end of the list */
2331 }
2332 fr_pair_list_free(&src_list);
2333 }
2334 break;
2335
2336 default:
2337 fr_assert(0); /* Should have been caught be the caller */
2338 rcode = -1;
2339 goto finish;
2340 }
2341
2342update:
2343 fr_assert(fr_pair_list_empty(&src_list));
2344
2345finish:
2346 tmpl_dcursor_clear(&cc);
2347 talloc_free(tmp_ctx);
2348 return rcode;
2349}
2350
2351/** Print a map to a string
2352 *
2353 * @param[out] out Buffer to write string to.
2354 * @param[in] map to print.
2355 * @return
2356 * - The number of bytes written to the out buffer.
2357 * - A number >= outlen if truncation has occurred.
2358 */
2360{
2361 fr_sbuff_t our_out = FR_SBUFF(out);
2362
2363 MAP_VERIFY(map);
2364
2365 /*
2366 * Print the lhs
2367 */
2368 if (tmpl_rules_cast(map->lhs)) {
2369 FR_SBUFF_IN_SPRINTF_RETURN(&our_out, "<%s>",
2371 }
2372 FR_SBUFF_RETURN(tmpl_print_quoted, &our_out, map->lhs);
2373
2374 /*
2375 * Print separators and operator
2376 */
2377 FR_SBUFF_IN_CHAR_RETURN(&our_out, ' ');
2379 FR_SBUFF_IN_CHAR_RETURN(&our_out, ' ');
2380
2381 /*
2382 * The RHS doesn't matter for many operators
2383 */
2384 if ((map->op == T_OP_CMP_TRUE) || (map->op == T_OP_CMP_FALSE)) {
2385 FR_SBUFF_IN_STRCPY_RETURN(&our_out, "ANY");
2386 FR_SBUFF_SET_RETURN(out, &our_out);
2387 }
2388
2389 /*
2390 * If there's no child and no RHS then the
2391 * map was invalid.
2392 */
2393 if (map_list_empty(&map->child) && !fr_cond_assert(map->rhs != NULL)) {
2394 fr_sbuff_terminate(out);
2395 return 0;
2396 }
2397
2398 if (tmpl_rules_cast(map->rhs)) {
2399 FR_SBUFF_IN_SPRINTF_RETURN(&our_out, "<%s>",
2401 }
2402
2403 /*
2404 * Print the RHS.
2405 */
2406 FR_SBUFF_RETURN(tmpl_print_quoted, &our_out, map->rhs);
2407
2408 FR_SBUFF_SET_RETURN(out, &our_out);
2409}
2410
2411/*
2412 * Debug print a map / VP
2413 */
2414void map_debug_log(request_t *request, map_t const *map, fr_pair_t const *vp)
2415{
2416 char *rhs = NULL, *value = NULL;
2417 char buffer[256];
2418
2419 MAP_VERIFY(map);
2420 if (!fr_cond_assert(map->lhs != NULL)) return;
2421 if (!fr_cond_assert(map->rhs != NULL)) return;
2422
2423 fr_assert(vp);
2424
2425 switch (map->rhs->type) {
2426 /*
2427 * Just print the value being assigned
2428 */
2429 default:
2431 fr_pair_aprint_value_quoted(request, &rhs, vp, map->rhs->quote);
2432 break;
2433
2434 case TMPL_TYPE_XLAT:
2435 fr_pair_aprint_value_quoted(request, &rhs, vp, map->rhs->quote);
2436 break;
2437
2438 case TMPL_TYPE_DATA:
2439 fr_pair_aprint_value_quoted(request, &rhs, vp, map->rhs->quote);
2440 break;
2441
2442 case TMPL_TYPE_ATTR:
2443 {
2444 fr_token_t quote;
2445
2446 switch (vp->vp_type) {
2447 case FR_TYPE_QUOTED:
2448 quote = T_DOUBLE_QUOTED_STRING;
2449 break;
2450 default:
2451 quote = T_BARE_WORD;
2452 break;
2453 }
2454
2455 /*
2456 * Not appropriate to use map->rhs->quote here, as that's the quoting
2457 * around the attr ref. The attribute value has no quoting, so we choose
2458 * the quoting based on the data type.
2459 */
2460 fr_pair_aprint_value_quoted(request, &value, vp, quote);
2461 tmpl_print(&FR_SBUFF_OUT(buffer, sizeof(buffer)), map->rhs, NULL);
2462 rhs = talloc_typed_asprintf(request, "%s -> %s", buffer, value);
2463 }
2464 break;
2465 }
2466
2467 switch (map->lhs->type) {
2468 case TMPL_TYPE_ATTR:
2469 tmpl_print(&FR_SBUFF_OUT(buffer, sizeof(buffer)), map->lhs, NULL);
2470 RDEBUG2("%s %s %s", buffer, fr_table_str_by_value(fr_tokens_table, vp ? vp->op : map->op, "<INVALID>"), rhs);
2471 break;
2472
2473 default:
2474 break;
2475 }
2476
2477 /*
2478 * Must be LIFO free order so we don't leak pool memory
2479 */
2480 talloc_free(rhs);
2482}
2483
2484/** Convert a fr_pair_t into a map
2485 *
2486 * @param[in] ctx where to allocate the map.
2487 * @param[out] out Where to write the new map (must be freed with talloc_free()).
2488 * @param[in,out] parent_p the parent map, updated for relative maps
2489 * @param[in] request the request
2490 * @param[in] lhs of map
2491 * @param[in] op_str operator for map
2492 * @param[in] rhs of map
2493 * @param[in] lhs_rules for parsing the LHS
2494 * @param[in] rhs_rules for parsing the RHS
2495 * @param[in] bare_word_only RHS is bare words, and nothing else.
2496 * @return
2497 * - 0 on success.
2498 * - -1 on failure.
2499 */
2500int map_afrom_fields(TALLOC_CTX *ctx, map_t **out, map_t **parent_p, request_t *request,
2501 char const *lhs, char const *op_str, char const *rhs,
2502 tmpl_rules_t const *lhs_rules, tmpl_rules_t const *rhs_rules, bool bare_word_only)
2503{
2504 ssize_t slen;
2505 fr_token_t quote, op;
2506 map_t *map;
2507 map_t *parent = *parent_p;
2508 tmpl_rules_t my_rules;
2509
2511 if (op == T_INVALID) {
2512 fr_strerror_printf("Invalid operator '%s'", op_str);
2513 return -1;
2514 }
2515
2516 /*
2517 * Reply items can be expanded. Check items cannot be,
2518 * unless the operator is a comparison operator.
2519 */
2520 if (!bare_word_only) {
2521 if (!fr_assignment_op[op]) {
2522 fr_assert(0);
2523 fr_strerror_printf("Invalid operator '%s' for assignment in reply item", op_str);
2524 return -1;
2525 }
2526
2527 } else if (!fr_assignment_op[op] && !fr_comparison_op[op]) {
2528 if (!fr_assignment_op[op]) {
2529 fr_strerror_printf("Invalid operator '%s' for check item", op_str);
2530 return -1;
2531 }
2532 }
2533
2534 my_rules = *lhs_rules;
2535 lhs_rules = &my_rules;
2536
2537 /*
2538 * We're only called from SQL. If the default list is request, then we only use that for
2539 * comparisons. We rewrite assignments to use the control list.
2540 *
2541 * @todo - as we expand the use of this function, perhaps add another argument which controls
2542 * this flag. But this function already has parameter overload :(
2543 */
2544 if (fr_assignment_op[op] && (lhs_rules->attr.list_def == request_attr_request)) {
2546 }
2547
2548 /*
2549 * One '.' means "the current parent".
2550 */
2551 if (*lhs == '.') {
2552 if (!parent) {
2553 no_parent:
2554 fr_strerror_const("Unexpected location for relative attribute - no parent attribute exists");
2555 return -1;
2556 }
2557 lhs++;
2558
2559 /*
2560 * Multiple '.' means "go to our parents parent".
2561 */
2562 while (*lhs == '.') {
2563 if (!parent) goto no_parent;
2564
2565 parent = parent->parent;
2566 lhs++;
2567 }
2568
2569 /*
2570 * Child elements can only be "=".
2571 */
2572 if (parent) {
2573 if (fr_comparison_op[op]) {
2574 fr_strerror_const("Comparison operators cannot be used inside of structural data types");
2575 return -1;
2576 }
2577
2578 if (op != T_OP_EQ) {
2579 fr_strerror_const("Invalid operator inside of structural data type - must be '='");
2580 return -1;
2581 }
2582 }
2583 }
2584
2585 MEM(map = map_alloc(ctx, parent));
2586 map->op = op;
2587
2588 /*
2589 * Start looking in the correct parent, not in whatever we were handed.
2590 */
2591 if (parent) {
2593 my_rules.attr.namespace = tmpl_attr_tail_da(parent->lhs);
2594
2595 slen = tmpl_afrom_attr_substr(map, NULL, &map->lhs, &FR_SBUFF_IN(lhs, strlen(lhs)),
2597 } else {
2598 /*
2599 * There's no '.', so this
2600 * attribute MUST come from the
2601 * root of the dictionary tree.
2602 */
2603 parent = NULL;
2604
2605 /*
2606 * Allocate the LHS, which must be an attribute.
2607 *
2608 * @todo - track relative attributes, which begin with a '.'
2609 */
2610 slen = tmpl_afrom_attr_str(ctx, NULL, &map->lhs, lhs, lhs_rules);
2611 }
2612 if (slen <= 0) {
2613 error:
2614 talloc_free(map);
2615 return -1;
2616 }
2617
2618 if (tmpl_attr_tail_is_unknown(map->lhs) && tmpl_attr_unknown_add(map->lhs) < 0) {
2619 fr_strerror_printf("Failed creating attribute %s", map->lhs->name);
2620 goto error;
2621 }
2622
2623 my_rules = *rhs_rules;
2624 my_rules.at_runtime = true;
2625 my_rules.xlat.runtime_el = unlang_interpret_event_list(request);
2626 my_rules.enumv = tmpl_attr_tail_da(map->lhs);
2627
2628 /*
2629 * LHS is a structureal type. The RHS is either empty (create empty LHS), or it's a string
2630 * containing a list of attributes to create.
2631 */
2632 if (!fr_type_is_leaf(my_rules.enumv->type)) {
2633 my_rules.enumv = NULL;
2634 }
2635
2636 /*
2637 * Try to figure out what we should do with the RHS.
2638 */
2639 if ((map->op == T_OP_CMP_TRUE) || (map->op == T_OP_CMP_FALSE)) {
2640 /*
2641 * These operators require a hard-coded string on the RHS.
2642 */
2643 if (strcmp(rhs, "ANY") != 0) {
2644 fr_strerror_printf("Invalid value %s for operator %s", rhs, fr_tokens[map->op]);
2645 goto error;
2646 }
2647
2648 if (tmpl_afrom_value_box(map, &map->rhs, fr_box_strvalue("ANY"), false) < 0) goto error;
2649
2650 } else if (bare_word_only) {
2651 fr_value_box_t *vb;
2652
2653 /*
2654 * No value, or no enum, parse it as a bare-word string.
2655 */
2656 if (!rhs[0] || !my_rules.enumv) goto do_bare_word;
2657
2658 MEM(vb = fr_value_box_alloc(map, my_rules.enumv->type, my_rules.enumv));
2659
2660 /*
2661 * It MUST be the given data type.
2662 */
2663 slen = fr_value_box_from_str(map, vb, my_rules.enumv->type, my_rules.enumv,
2664 rhs, strlen(rhs), NULL);
2665 if (slen <= 0) goto error;
2666
2667 if (tmpl_afrom_value_box(map, &map->rhs, vb, true) < 0) {
2668 goto error;
2669 }
2670
2671 } else if (rhs[0] == '"') {
2672 /*
2673 * We've been asked to expand the RHS. Passwords like
2674 *
2675 * "%{Calling-Station-ID}"
2676 *
2677 * might not do what you want.
2678 */
2679 quote = T_DOUBLE_QUOTED_STRING;
2680 goto parse_quoted;
2681
2682 } else if (rhs[0] == '\'') {
2683 size_t len;
2684
2685 quote = T_SINGLE_QUOTED_STRING;
2686
2687 parse_quoted:
2688 len = strlen(rhs + 1);
2689 if (len == 1) {
2690 if (rhs[1] != rhs[0]) {
2691 fr_strerror_const("Invalid string on right side");
2692 return -1;
2693 }
2694
2695 rhs = "";
2696 goto alloc_empty;
2697 }
2698
2699 slen = tmpl_afrom_substr(map, &map->rhs, &FR_SBUFF_IN(rhs + 1, len - 1),
2700 quote, value_parse_rules_quoted[quote], &my_rules);
2701 if (slen < 0) {
2702 REDEBUG3("Failed parsing right-hand side as quoted string.");
2703 fail_rhs:
2704 fr_strerror_printf("Failed parsing right-hand side: %s", fr_strerror());
2705 goto error;
2706 }
2707
2708 if (slen == 0) {
2709 rhs = "";
2710 goto alloc_empty;
2711 }
2712
2713 /*
2714 * Ignore any extra data after the string.
2715 *
2716 * @todo - this should likely be a parse error: we didn't parse the entire string!
2717 */
2718
2719 } else if (rhs[0] == '&') {
2720 /*
2721 * No enums here.
2722 */
2724
2725 parse_as_attr:
2726 my_rules.enumv = NULL;
2727
2728 slen = tmpl_afrom_attr_str(map, NULL, &map->rhs, rhs, &my_rules);
2729 if (slen <= 0) {
2730 REDEBUG3("Failed parsing right-hand side as attribute.");
2731 goto fail_rhs;
2732 }
2733
2734 } else if (!rhs[0] || !my_rules.enumv || (my_rules.enumv->type == FR_TYPE_STRING)) {
2735 do_bare_word:
2736 quote = T_BARE_WORD;
2737
2738 if (tmpl_attr_tail_da_is_structural(map->lhs) && !*rhs) goto done;
2739
2740 alloc_empty:
2741 MEM(map->rhs = tmpl_alloc(map, TMPL_TYPE_DATA, quote, rhs, strlen(rhs)));
2742
2743 /*
2744 * Create it when we have
2745 *
2746 * my-struct = ""
2747 */
2748 (void) fr_value_box_strdup(map->rhs, tmpl_value(map->rhs), NULL, rhs, false);
2749
2750 } else {
2751 /*
2752 * Parse it as the given data type.
2753 */
2754 slen = tmpl_afrom_substr(map, &map->rhs, &FR_SBUFF_IN(rhs, strlen(rhs)),
2756 if (slen <= 0) {
2757 goto parse_as_attr;
2758 }
2759
2760 /*
2761 * Xlat expansions are cast to strings for structural data types.
2762 */
2763 if (tmpl_attr_tail_da_is_structural(map->lhs) && (tmpl_is_xlat(map->rhs))) {
2765 }
2766 }
2767
2768 if (tmpl_needs_resolving(map->rhs)) {
2769 tmpl_res_rules_t tr_rules = (tmpl_res_rules_t) {
2770 .dict_def = lhs_rules->attr.dict_def,
2771 .enumv = tmpl_attr_tail_da(map->lhs)
2772 };
2773
2775
2776 if (tmpl_resolve(map->rhs, &tr_rules) < 0) {
2777 REDEBUG3("Failed resolving right-hand side.");
2778 goto fail_rhs;
2779 }
2780 }
2781
2782 /*
2783 * @todo - check that the entire string was parsed.
2784 */
2785
2786done:
2787 /*
2788 * If the tail is a leaf, we don't change parent.
2789 * Otherwise the structural attribute is the new parent.
2790 */
2791 if (tmpl_attr_tail_da_is_leaf(map->lhs)) {
2792 *parent_p = parent;
2793 } else {
2794 *parent_p = map;
2795 }
2796
2797 MAP_VERIFY(map);
2798
2799 if (parent) map_list_insert_tail(&parent->child, map);
2800 *out = map;
2801
2802 return 0;
2803}
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:288
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:545
static void * fr_dcursor_remove(fr_dcursor_t *cursor)
Remove the current item.
Definition dcursor.h:480
static void * fr_dcursor_current(fr_dcursor_t *cursor)
Return the item the cursor current points to.
Definition dcursor.h:337
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:2608
fr_dict_t const * fr_dict_internal(void)
Definition dict_util.c:4612
static fr_slen_t in
Definition dict.h:833
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:1822
#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:1167
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:2500
#define DEBUG_OVERWRITE(_old, _new)
Definition map.c:1810
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:1563
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:1136
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:1247
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:1105
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:1351
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:1432
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:1842
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:1497
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:1320
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:1401
ssize_t map_print(fr_sbuff_t *out, map_t const *map)
Print a map to a string.
Definition map.c:2359
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:2414
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:3385
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:2321
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:2591
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:1347
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:285
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:1810
int fr_pair_value_copy(fr_pair_t *dst, fr_pair_t *src)
Copy the value from one pair to another.
Definition pair.c:2565
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:316
fr_pair_t * fr_pair_copy(TALLOC_CTX *ctx, fr_pair_t const *vp)
Copy a single valuepair.
Definition pair.c:491
int8_t fr_pair_cmp_by_da(void const *a, void const *b)
Order attributes by their da, and tag.
Definition pair.c:1846
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:788
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:488
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:167
char const * fr_token_name(int token)
Definition token.c:510
fr_table_num_ordered_t const fr_tokens_table[]
Definition token.c:32
const char fr_token_quote[T_TOKEN_LAST]
Convert tokens back to a quoting character.
Definition token.c:155
char const * fr_tokens[T_TOKEN_LAST]
Definition token.c:77
const bool fr_comparison_op[T_TOKEN_LAST]
Definition token.c:197
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:416
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:1725
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:3030
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:292
#define fr_type_is_structural(_x)
Definition types.h:371
#define FR_TYPE_STRUCTURAL
Definition types.h:296
#define fr_type_is_leaf(_x)
Definition types.h:372
static char const * fr_type_to_str(fr_type_t type)
Return a static string containing the type name.
Definition types.h:433
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:3963
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:5450
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:4161
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:4890
#define fr_value_box_alloc(_ctx, _type, _enumv)
Allocate a value box of a specific type.
Definition value.h:632
#define fr_box_strvalue(_val)
Definition value.h:296
static size_t char ** out
Definition value.h:1012