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