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