The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
cf_parse.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: d631245b2231ee07e6f0596d0838022e70122d61 $
19 * @file cf_parse.c
20 * @brief Convert internal format configuration values into native C types.
21 *
22 * @copyright 2017 Arran Cudbard-Bell (a.cudbardb@freeradius.org)
23 * @copyright 2000,2006 The FreeRADIUS server project
24 * @copyright 2000 Miquel van Smoorenburg (miquels@cistron.nl)
25 * @copyright 2000 Alan DeKok (aland@freeradius.org)
26 */
27RCSID("$Id: d631245b2231ee07e6f0596d0838022e70122d61 $")
28
29#include <string.h>
30#include <sys/errno.h>
31#include <sys/fcntl.h>
32
33#include <freeradius-devel/server/cf_file.h>
34#include <freeradius-devel/server/cf_parse.h>
35#include <freeradius-devel/server/cf_priv.h>
36#include <freeradius-devel/server/log.h>
37#include <freeradius-devel/server/tmpl.h>
38#include <freeradius-devel/server/virtual_servers.h>
39#include <freeradius-devel/server/main_config.h>
40#include <freeradius-devel/util/debug.h>
41#include <freeradius-devel/util/inet.h>
42#include <freeradius-devel/util/misc.h>
43#include <freeradius-devel/util/perm.h>
44#include <freeradius-devel/util/syserror.h>
45
47static char const parse_spaces[] = " ";
48
49#define PAIR_SPACE(_cs) ((_cs->depth + 1) * 2)
50#define SECTION_SPACE(_cs) (_cs->depth * 2)
51
52void cf_pair_debug_log(CONF_SECTION const *cs, CONF_PAIR *cp, conf_parser_t const *rule)
53{
54 char const *value;
55 char *tmp = NULL;
56 char const *quote = "";
57 bool secret = (rule && (rule->flags & CONF_FLAG_SECRET));
59
60 if (cp->printed) return;
61
62 /*
63 * tmpls are special, they just need to get printed as string
64 */
65 if (!rule || (rule->flags & CONF_FLAG_TMPL)) {
67 } else {
68 type = rule->type;
69 }
70
71 if (secret && (fr_debug_lvl < L_DBG_LVL_3)) {
72 cf_log_debug(cs, "%.*s%s = <<< secret >>>", PAIR_SPACE(cs), parse_spaces, cp->attr);
73 return;
74 }
75
76 /*
77 * Print the strings with the correct quotation character and escaping.
78 */
80 value = tmp = fr_asprint(NULL, cp->value, talloc_array_length(cp->value) - 1, fr_token_quote[cp->rhs_quote]);
81
82 } else {
83 value = cf_pair_value(cp);
84 }
85
87 switch (cf_pair_value_quote(cp)) {
88 default:
89 break;
90
92 quote = "\"";
93 break;
94
96 quote = "'";
97 break;
98
100 quote = "`";
101 break;
102
104 quote = "/";
105 break;
106 }
107 }
108
109 cf_log_debug(cs, "%.*s%s = %s%s%s", PAIR_SPACE(cs), parse_spaces, cp->attr, quote, value, quote);
110
111 talloc_free(tmp);
112
113 cp->printed = true;
114}
115
116/** Parses a #CONF_PAIR into a boxed value
117 *
118 * @copybrief cf_pair_value
119 * @see cf_pair_value
120 *
121 * @param[in] ctx to allocate any dynamic buffers in.
122 * @param[out] out Where to write the parsed value.
123 * @param[in] cp to parse.
124 * @param[in] rule to parse to. May contain flags.
125 * @return
126 * - 0 on success.
127 * - -1 on failure.
128 */
129int cf_pair_to_value_box(TALLOC_CTX *ctx, fr_value_box_t *out, CONF_PAIR *cp, conf_parser_t const *rule)
130{
131 if (fr_value_box_from_str(ctx, out, rule->type, NULL, cp->value, talloc_array_length(cp->value) - 1, NULL) < 0) {
132 cf_log_perr(cp, "Invalid value \"%s\" for config item %s",
133 cp->value, cp->attr);
134
135 return -1;
136 }
137
138 /*
139 * Strings can be file paths...
140 */
141 if (fr_type_is_string(rule->type)) {
142 if (fr_rule_file_socket(rule)) {
143 /*
144 * Attempt to actually connect to the socket.
145 * There's no real standard behaviour across
146 * operating systems for this.
147 *
148 * This also implies fr_rule_file_exists.
149 */
150 if (fr_rule_file_readable(rule) || fr_rule_file_writable(rule)) {
152 cf_log_perr(cp, "File check failed");
153 return -1;
154 }
155 /*
156 * Otherwise just passively check if the socket
157 * exists.
158 */
159 } else if (fr_rule_file_exists(rule)) {
161 cf_log_perr(cp, "File check failed");
162 return -1;
163 }
164 /*
165 * ...and if there's no existence requirement
166 * just check that it's a unix socket.
167 */
168 } else {
170 default:
171 /* ok */
172 break;
173
175 cf_log_perr(cp, "File check failed");
176 return -1;
177 }
178 }
179 }
180 /*
181 * If there's out AND it's an input file, check
182 * that we can read it. This check allows errors
183 * to be caught as early as possible, during
184 * server startup.
185 */
186 else if (fr_rule_file_readable(rule) && (cf_file_check(cp, true) < 0)) {
187 error:
189 return -1;
190 }
191 else if (fr_rule_file_exists(rule) && (cf_file_check(cp, false) < 0)) goto error;
192 }
193
195
196 return 0;
197}
198
199/** Parses a #CONF_PAIR into a C data type
200 *
201 * @copybrief cf_pair_value
202 * @see cf_pair_value
203 *
204 * @param[in] ctx to allocate any dynamic buffers in.
205 * @param[out] out Where to write the parsed value.
206 * @param[in] base address of the structure out points into.
207 * May be NULL in the case of manual parsing.
208 * @param[in] ci to parse.
209 * @param[in] rule to parse to. May contain flags.
210 * @return
211 * - 0 on success.
212 * - -1 on failure.
213 */
214int cf_pair_parse_value(TALLOC_CTX *ctx, void *out, UNUSED void *base, CONF_ITEM *ci, conf_parser_t const *rule)
215{
216 int ret = 0;
217 bool cant_be_empty, tmpl;
218
219 ssize_t slen;
220
221 CONF_PAIR *cp = cf_item_to_pair(ci);
222
223 cant_be_empty = fr_rule_not_empty(rule);
224 tmpl = fr_rule_is_tmpl(rule);
225
226 fr_assert(cp);
227 fr_assert(!fr_rule_is_attribute(rule) || tmpl); /* Attribute flag only valid for templates */
228
229 if (fr_rule_required(rule)) cant_be_empty = true; /* May want to review this in the future... */
230
231 /*
232 * Everything except templates must have a base type.
233 */
234 if (!rule->type && !tmpl) {
235 cf_log_err(cp, "Configuration pair \"%s\" must have a data type", cp->attr);
236 return -1;
237 }
238
239 /*
240 * Catch crazy errors.
241 */
242 if (!cp->value) {
243 cf_log_err(cp, "Configuration pair \"%s\" must have a value", cp->attr);
244 return -1;
245 }
246
247 /*
248 * Check for zero length strings
249 */
250 if ((cp->value[0] == '\0') && cant_be_empty) {
251 cf_log_err(cp, "Configuration pair \"%s\" must not be empty (zero length)", cp->attr);
252 if (!fr_rule_required(rule)) cf_log_err(cp, "Comment item to silence this message");
253 error:
254 ret = -1;
255 return ret;
256 }
257
258 if (tmpl) {
259 tmpl_t *vpt;
260 static tmpl_rules_t rules = {
261 .attr = {
262 .allow_unknown = true,
263 .allow_unresolved = true,
264 .allow_foreign = true,
265 },
266 .literals_safe_for = FR_VALUE_BOX_SAFE_FOR_ANY,
267 };
268 fr_sbuff_t sbuff = FR_SBUFF_IN(cp->value, strlen(cp->value));
269
271
272 /*
273 * Bare words are magical sometimes.
274 */
275 if (cp->rhs_quote == T_BARE_WORD) {
276 /*
277 * Attributes are parsed as attributes.
278 */
279 if (fr_rule_is_attribute(rule)) {
280 slen = tmpl_afrom_attr_substr(cp, NULL, &vpt, &sbuff, NULL, &rules);
281 if (slen < 0) goto tmpl_error;
282
283 fr_assert(vpt);
284
285 *(tmpl_t **)out = vpt;
286 goto finish;
287 }
288
289 /*
290 * @todo - otherwise bare words are NOT parsed as attributes, they're parsed as
291 * bare words, ala v3.
292 */
293
294 } else if (fr_rule_is_attribute(rule)) {
295 cf_log_err(cp, "Unexpected quoted string. An attribute name is required here.");
296 goto error;
297 }
298
299 slen = tmpl_afrom_substr(cp, &vpt, &sbuff, cp->rhs_quote,
301 &rules);
302 if (slen < 0) {
303 tmpl_error:
304 cf_canonicalize_error(cp, slen, fr_strerror(), cp->value);
305 goto error;
306 }
307 fr_assert(vpt);
308
309 /*
310 * The caller told us what data type was expected. If we do have data, then try to cast
311 * it to the requested type.
312 */
313 if ((rule->type != FR_TYPE_VOID) && tmpl_contains_data(vpt)) {
314 slen = 0; // for errors
315
317 tmpl_cast_set(vpt, rule->type);
318
319 if (tmpl_resolve(vpt, NULL) < 0) goto tmpl_error;
320
321 } else if (rule->type != tmpl_value_type(vpt)) {
323
324 if (tmpl_cast_in_place(vpt, rule->type, NULL) < 0) goto tmpl_error;
325 }
326 }
327
328 *(tmpl_t **)out = vpt;
329 goto finish;
330 }
331
332 /*
333 * Parse as a boxed value out of sheer laziness...
334 *
335 * Then we get all the internal types for free, and only need to add
336 * one set of printing and parsing functions for new types...
337 */
338 {
340
341 if (cf_pair_to_value_box(ctx, &vb, cf_item_to_pair(ci), rule) < 0) goto error;
342
343 if (fr_value_box_memcpy_out(out, &vb) < 0) {
344 cf_log_perr(cp, "Failed unboxing parsed configuration item value");
346 goto error;
347 }
348 }
349
350finish:
351
352 return ret;
353}
354
355/** Allocate a pair using the dflt value and quotation
356 *
357 * The pair created by this function should fed to #cf_pair_parse for parsing.
358 *
359 * @param[out] out Where to write the CONF_PAIR we created with the default value.
360 * @param[in] parent being populated.
361 * @param[in] cs to parent the CONF_PAIR from.
362 * @param[in] rule to use to create the default.
363 * @return
364 * - 0 on success.
365 * - -1 on failure.
366 */
367static int cf_pair_default(CONF_PAIR **out, void *parent, CONF_SECTION *cs, conf_parser_t const *rule)
368
369{
370 int lineno = 0;
371 char const *expanded;
372 CONF_PAIR *cp;
373 char buffer[8192];
374 fr_token_t dflt_quote = rule->quote;
375
376 fr_assert(rule->dflt || rule->dflt_func);
377
378 if (fr_rule_required(rule)) {
379 cf_log_err(cs, "Configuration pair \"%s\" must have a value", rule->name1);
380 return -1;
381 }
382
383 /*
384 * If no default quote was set, determine it from the type
385 */
386 if (dflt_quote == T_INVALID) {
387 if (fr_type_is_quoted(rule->type)) {
388 dflt_quote = T_DOUBLE_QUOTED_STRING;
389 } else {
390 dflt_quote = T_BARE_WORD;
391 }
392 }
393
394 /*
395 * Use the dynamic default function if set
396 */
397 if (rule->dflt_func) {
398 if (rule->dflt_func(out, parent, cs, dflt_quote, rule) < 0) {
399 cf_log_perr(cs, "Failed producing default for \"%s\"", rule->name1);
400 return -1;
401 }
402
403 return 0;
404 }
405
406 expanded = cf_expand_variables("<internal>", lineno, cs, buffer, sizeof(buffer), rule->dflt, -1, NULL);
407 if (!expanded) {
408 cf_log_err(cs, "Failed expanding variable %s", rule->name1);
409 return -1;
410 }
411
412 cp = cf_pair_alloc(cs, rule->name1, expanded, T_OP_EQ, T_BARE_WORD, dflt_quote);
413 if (!cp) return -1;
414
415 /*
416 * Set the ret to indicate we used a default value
417 */
418 *out = cp;
419
420 return 1;
421}
422
423static int cf_pair_unescape(CONF_PAIR *cp, conf_parser_t const *rule)
424{
425 char const *p;
426 char *str, *unescaped, *q;
427
428 if (!cp->value) return 0;
429
430 if (cp->rhs_quote != T_DOUBLE_QUOTED_STRING) return 0;
431
432 if (!(rule->flags & CONF_FLAG_TMPL)) {
433 if (rule->type != FR_TYPE_STRING) return 0;
434 }
435
436 if (strchr(cp->value, '\\') == NULL) return 0;
437
438 str = talloc_strdup(cp, cp->value);
439 if (!str) return -1;
440
441 p = cp->value;
442 q = str;
443 while (*p) {
444 unsigned int x;
445
446 if (*p != '\\') {
447 *(q++) = *(p++);
448 continue;
449 }
450
451 p++;
452 switch (*p) {
453 case 'r':
454 *q++ = '\r';
455 break;
456 case 'n':
457 *q++ = '\n';
458 break;
459 case 't':
460 *q++ = '\t';
461 break;
462
463 default:
464 if (*p >= '0' && *p <= '9' &&
465 sscanf(p, "%3o", &x) == 1) {
466 if (!x) {
467 cf_log_err(cp, "Cannot have embedded zeros in value for %s", cp->attr);
468 return -1;
469 }
470
471 *q++ = x;
472 p += 2;
473 } else {
474 *q++ = *p;
475 }
476 break;
477 }
478 p++;
479 }
480 *q = '\0';
481
482 unescaped = talloc_typed_strdup(cp, str); /* no embedded NUL */
483 if (!unescaped) return -1;
484
485 talloc_free(str);
486
487 /*
488 * Replace the old value with the new one.
489 */
491 cp->value = unescaped;
492
493 return 0;
494}
495
496/** Parses a #CONF_PAIR into a C data type, with a default value.
497 *
498 * @param[in] ctx To allocate arrays and values in.
499 * @param[out] out Where to write the result.
500 * Must not be NULL unless rule->runc is provided.
501 * @param[in] base address of the structure out points into.
502 * May be NULL in the case of manual parsing.
503 * @param[in] cs to search for matching #CONF_PAIR in.
504 * @param[in] rule to parse #CONF_PAIR with.
505 * @return
506 * - 1 if default value was used, or if there was no CONF_PAIR or dflt.
507 * - 0 on success.
508 * - -1 on error.
509 * - -2 if deprecated.
510 */
511static int CC_HINT(nonnull(4,5)) cf_pair_parse_internal(TALLOC_CTX *ctx, void *out, void *base,
512 CONF_SECTION *cs, conf_parser_t const *rule)
513{
514 bool required, deprecated;
515 size_t count = 0;
516 CONF_PAIR *cp = NULL, *dflt_cp = NULL;
517
518#ifndef NDEBUG
519 char const *dflt = rule->dflt;
520 fr_token_t dflt_quote = rule->quote;
521#endif
522 cf_parse_t func = rule->func ? rule->func : cf_pair_parse_value;
523
524 fr_assert(!fr_rule_is_tmpl(rule) || !dflt || (dflt_quote != T_INVALID)); /* We ALWAYS need a quoting type for templates */
525
526 /*
527 * Functions don't necessarily *need* to write
528 * anywhere, so their data pointer can be NULL.
529 */
530 if (!out) {
531 if (!rule->func) {
532 cf_log_err(cs, "Rule doesn't specify output destination");
533 return -1;
534 }
535 }
536
537 required = fr_rule_required(rule);
538 deprecated = fr_rule_deprecated(rule);
539
540 /*
541 * If the item is multi-valued we allocate an array
542 * to hold the multiple values.
543 */
544 if (fr_rule_multi(rule)) {
545 void **array;
546 size_t i = 0;
547
548 /*
549 * Easier than re-allocing
550 */
551 count = cf_pair_count(cs, rule->name1);
552
553 /*
554 * Multivalued, but there's no value, create a
555 * default pair.
556 */
557 if (!count) {
558 if (deprecated) return 0;
559
560 if (!fr_rule_dflt(rule)) {
561 if (required) {
562 need_value:
563 cf_log_err(cs, "Configuration item \"%s\" must have a value", rule->name1);
564 return -1;
565 }
566 return 1;
567 }
568
569 if (cf_pair_default(&dflt_cp, base, cs, rule) < 0) return -1;
570 count = cf_pair_count(cs, rule->name1); /* Dynamic functions can add multiple defaults */
571 if (!count) {
572 if (fr_rule_not_empty(rule)) {
573 cf_log_err(cs, "Configuration item \"%s\" cannot be empty", rule->name1);
574 return -1;
575 }
576 return 0;
577 }
578 }
579
580 if (deprecated) {
581 /*
582 * Emit the deprecated warning in the
583 * context of the first pair.
584 */
585 cp = cf_pair_find(cs, rule->name1);
586 fr_assert(cp);
587
588 deprecated:
589 cf_log_err(cp, "Configuration pair \"%s\" is deprecated", cp->attr);
590 return -2;
591 }
592
593 /*
594 * No output, so don't bother allocing the array
595 */
596 if (!out) {
597 array = NULL;
598
599 /*
600 * Tmpl is outside normal range
601 */
602 } else if (fr_rule_is_tmpl(rule)) {
603 MEM(array = (void **)talloc_zero_array(ctx, tmpl_t *, count));
604
605 /*
606 * Allocate an array of values.
607 *
608 * We don't NULL terminate. Consumer must use
609 * talloc_array_length().
610 */
611 } else {
612 array = fr_type_array_alloc(ctx, rule->type, count);
613 if (unlikely(array == NULL)) {
614 cf_log_perr(cp, "Failed allocating value array");
615 return -1;
616 }
617 }
618
619 while ((cp = cf_pair_find_next(cs, cp, rule->name1))) {
620 int ret;
621 void *entry;
622 TALLOC_CTX *value_ctx = array;
623
624 /*
625 * Figure out where to write the output
626 */
627 if (!array) {
628 entry = NULL;
629 } else if ((rule->type == FR_TYPE_VOID) || (rule->flags & CONF_FLAG_TMPL)) {
630 entry = &array[i++];
631 } else {
632 entry = ((uint8_t *) array) + (i++ * fr_value_box_field_sizes[rule->type]);
633 }
634
635 if (cf_pair_unescape(cp, rule) < 0) return -1;
636
637 /*
638 * Switch between custom parsing function
639 * and the standard value parsing function.
640 */
641 cf_pair_debug_log(cs, cp, rule);
642
643 if (cf_pair_is_parsed(cp)) continue;
644 ret = func(value_ctx, entry, base, cf_pair_to_item(cp), rule);
645 if (ret < 0) {
646 talloc_free(array);
647 return -1;
648 }
650 }
651 if (array) *(void **)out = array;
652 /*
653 * Single valued config item gets written to
654 * the data pointer directly.
655 */
656 } else {
657 CONF_PAIR *next;
658 int ret;
659
660 cp = cf_pair_find(cs, rule->name1);
661 if (!cp) {
662 if (deprecated) return 0;
663
664 if (!fr_rule_dflt(rule)) {
665 if (required) goto need_value;
666 return 1;
667 }
668
669 if (cf_pair_default(&dflt_cp, base, cs, rule) < 0) return -1;
670 cp = dflt_cp;
671 if (!cp) {
672 if (fr_rule_not_empty(rule)) {
673 cf_log_err(cs, "Configuration item \"%s\" cannot be empty", rule->name1);
674 return -1;
675 }
676
677 return 0;
678 }
679 } else {
680 if (cf_pair_unescape(cp, rule) < 0) return -1;
681 }
682
683 next = cf_pair_find_next(cs, cp, rule->name1);
684 if (next) {
685 cf_log_err(cf_pair_to_item(next), "Invalid duplicate configuration item '%s'", rule->name1);
686 return -1;
687 }
688 if (deprecated) goto deprecated;
689
690 cf_pair_debug_log(cs, cp, rule);
691
692 if (cf_pair_is_parsed(cp)) return 0;
693 ret = func(ctx, out, base, cf_pair_to_item(cp), rule);
694 if (ret < 0) return -1;
696 }
697
698 return 0;
699}
700
701/** Parses a #CONF_PAIR into a C data type, with a default value.
702 *
703 * Takes fields from a #conf_parser_t struct and uses them to parse the string value
704 * of a #CONF_PAIR into a C data type matching the type argument.
705 *
706 * The format of the types are the same as #fr_value_box_t types.
707 *
708 * @note The dflt value will only be used if no matching #CONF_PAIR is found. Empty strings will not
709 * result in the dflt value being used.
710 *
711 * **fr_type_t to data type mappings**
712 * | fr_type_t | Data type | Dynamically allocated |
713 * | ----------------------- | ------------------ | ---------------------- |
714 * | FR_TYPE_BOOL | ``bool`` | No |
715 * | FR_TYPE_UINT32 | ``uint32_t`` | No |
716 * | FR_TYPE_UINT16 | ``uint16_t`` | No |
717 * | FR_TYPE_UINT64 | ``uint64_t`` | No |
718 * | FR_TYPE_INT32 | ``int32_t`` | No |
719 * | FR_TYPE_STRING | ``char const *`` | Yes |
720 * | FR_TYPE_IPV4_ADDR | ``fr_ipaddr_t`` | No |
721 * | FR_TYPE_IPV4_PREFIX | ``fr_ipaddr_t`` | No |
722 * | FR_TYPE_IPV6_ADDR | ``fr_ipaddr_t`` | No |
723 * | FR_TYPE_IPV6_PREFIX | ``fr_ipaddr_t`` | No |
724 * | FR_TYPE_COMBO_IP_ADDR | ``fr_ipaddr_t`` | No |
725 * | FR_TYPE_COMBO_IP_PREFIX | ``fr_ipaddr_t`` | No |
726 * | FR_TYPE_TIME_DELTA | ``fr_time_delta_t``| No |
727 *
728 * @param[in] ctx To allocate arrays and values in.
729 * @param[in] cs to search for matching #CONF_PAIR in.
730 * @param[in] name of #CONF_PAIR to search for.
731 * @param[in] type Data type to parse #CONF_PAIR value as.
732 * Should be one of the following ``data`` types,
733 * and one or more of the following ``flag`` types or'd together:
734
735 * - ``data`` #FR_TYPE_BOOL - @copybrief FR_TYPE_BOOL
736 * - ``data`` #FR_TYPE_UINT32 - @copybrief FR_TYPE_UINT32
737 * - ``data`` #FR_TYPE_UINT16 - @copybrief FR_TYPE_UINT16
738 * - ``data`` #FR_TYPE_UINT64 - @copybrief FR_TYPE_UINT64
739 * - ``data`` #FR_TYPE_INT32 - @copybrief FR_TYPE_INT32
740 * - ``data`` #FR_TYPE_STRING - @copybrief FR_TYPE_STRING
741 * - ``data`` #FR_TYPE_IPV4_ADDR - @copybrief FR_TYPE_IPV4_ADDR (IPv4 address with prefix 32).
742 * - ``data`` #FR_TYPE_IPV4_PREFIX - @copybrief FR_TYPE_IPV4_PREFIX (IPv4 address with variable prefix).
743 * - ``data`` #FR_TYPE_IPV6_ADDR - @copybrief FR_TYPE_IPV6_ADDR (IPv6 address with prefix 128).
744 * - ``data`` #FR_TYPE_IPV6_PREFIX - @copybrief FR_TYPE_IPV6_PREFIX (IPv6 address with variable prefix).
745 * - ``data`` #FR_TYPE_COMBO_IP_ADDR - @copybrief FR_TYPE_COMBO_IP_ADDR (IPv4/IPv6 address with
746 * prefix 32/128).
747 * - ``data`` #FR_TYPE_COMBO_IP_PREFIX - @copybrief FR_TYPE_COMBO_IP_PREFIX (IPv4/IPv6 address with
748 * variable prefix).
749 * - ``data`` #FR_TYPE_TIME_DELTA - @copybrief FR_TYPE_TIME_DELTA
750 * - ``flag`` #CONF_FLAG_TMPL - @copybrief CONF_FLAG_TMPL
751 * Feeds the value into #tmpl_afrom_substr. Value can be
752 * obtained when processing requests, with #tmpl_expand or #tmpl_aexpand.
753 * - ``flag`` #FR_TYPE_DEPRECATED - @copybrief FR_TYPE_DEPRECATED
754 * - ``flag`` #CONF_FLAG_REQUIRED - @copybrief CONF_FLAG_REQUIRED
755 * - ``flag`` #CONF_FLAG_ATTRIBUTE - @copybrief CONF_FLAG_ATTRIBUTE
756 * - ``flag`` #CONF_FLAG_SECRET - @copybrief CONF_FLAG_SECRET
757 * - ``flag`` #CONF_FLAG_FILE_READABLE - @copybrief CONF_FLAG_FILE_READABLE
758 * - ``flag`` #CONF_FLAG_FILE_WRITABLE - @copybrief CONF_FLAG_FILE_WRITABLE
759 * - ``flag`` #CONF_FLAG_NOT_EMPTY - @copybrief CONF_FLAG_NOT_EMPTY
760 * - ``flag`` #CONF_FLAG_MULTI - @copybrief CONF_FLAG_MULTI
761 * - ``flag`` #CONF_FLAG_IS_SET - @copybrief CONF_FLAG_IS_SET
762 * @param[out] data Pointer to a global variable, or pointer to a field in the struct being populated with values.
763 * @param[in] dflt value to use, if no #CONF_PAIR is found.
764 * @param[in] dflt_quote around the dflt value.
765 * @return
766 * - 1 if default value was used, or if there was no CONF_PAIR or dflt.
767 * - 0 on success.
768 * - -1 on error.
769 * - -2 if deprecated.
770 */
771int cf_pair_parse(TALLOC_CTX *ctx, CONF_SECTION *cs, char const *name,
772 unsigned int type, void *data, char const *dflt, fr_token_t dflt_quote)
773{
774 conf_parser_t rule = {
775 .name1 = name,
776 .type = type,
777 .dflt = dflt,
778 .quote = dflt_quote
779 };
780
781 return cf_pair_parse_internal(ctx, data, NULL, cs, &rule);
782}
783
784/** Pre-allocate a config section structure to allow defaults to be set
785 *
786 * @param cs The parent subsection.
787 * @param base pointer or variable.
788 * @param rule that may have defaults in this config section.
789 * @return
790 * - 0 on success.
791 * - -1 on failure.
792 */
793static int cf_section_parse_init(CONF_SECTION *cs, void *base, conf_parser_t const *rule)
794{
795 CONF_PAIR *cp;
796
797 /*
798 * This rule refers to a named subsection
799 */
800 if ((rule->flags & CONF_FLAG_SUBSECTION)) {
801 char const *name2 = NULL;
802 CONF_SECTION *subcs;
803
804 /*
805 * Optional MUST be listed before required ones
806 */
807 if ((rule->flags & CONF_FLAG_OPTIONAL) != 0) {
808 return 0;
809 }
810
811 subcs = cf_section_find(cs, rule->name1, rule->name2);
812
813 /*
814 * Set the is_set field for the subsection.
815 */
816 if (rule->flags & CONF_FLAG_IS_SET) {
817 bool *is_set;
818
819 is_set = rule->data ? rule->is_set_ptr : ((uint8_t *)base) + rule->is_set_offset;
820 if (is_set) *is_set = (subcs != NULL);
821 }
822
823 /*
824 * It exists, we don't have to do anything else.
825 */
826 if (subcs) return 0;
827
828 /*
829 * If there is no subsection, either complain,
830 * allow it, or create it with default values.
831 */
832 if (rule->flags & CONF_FLAG_REQUIRED) {
833 cf_log_err(cs, "Missing %s {} subsection", rule->name1);
834 return -1;
835 }
836
837 /*
838 * It's OK for this to be missing. Don't
839 * initialize it.
840 */
841 if ((rule->flags & CONF_FLAG_OK_MISSING) != 0) return 0;
842
843 /*
844 * If there's no subsection in the
845 * config, BUT the conf_parser_t wants one,
846 * then create an empty one. This is so
847 * that we can track the strings,
848 * etc. allocated in the subsection.
849 */
850 if (DEBUG_ENABLED4) cf_log_debug(cs, "Allocating fake section \"%s\"", rule->name1);
851
852 /*
853 * If name1 is CF_IDENT_ANY, then don't
854 * alloc the section as we have no idea
855 * what it should be called.
856 */
857 if (rule->name1 == CF_IDENT_ANY) return 0;
858
859 /*
860 * Don't specify name2 if it's CF_IDENT_ANY
861 */
862 if (rule->name2 != CF_IDENT_ANY) name2 = rule->name2;
863 subcs = cf_section_alloc(cs, cs, rule->name1, name2);
864 if (!subcs) return -1;
865
866 return 0;
867 }
868
869 /*
870 * This rule refers to another conf_parse_t which is included in-line in
871 * this section.
872 */
873 if ((rule->flags & CONF_FLAG_REF) != 0) {
874 conf_parser_t const *rule_p;
875 uint8_t *sub_base = base;
876
877 fr_assert(rule->subcs != NULL);
878
879 sub_base += rule->offset;
880
881 for (rule_p = rule->subcs; rule_p->name1; rule_p++) {
882 int ret = cf_section_parse_init(cs, sub_base, rule_p);
883 if (ret < 0) return ret;
884 }
885 return 0;
886 }
887
888 /*
889 * Don't re-initialize data which was already parsed.
890 */
891 cp = cf_pair_find(cs, rule->name1);
892 if (cp && cp->parsed) return 0;
893
894 if ((rule->type != FR_TYPE_STRING) &&
895 (!(rule->flags & CONF_FLAG_FILE_READABLE)) &&
896 (!(rule->flags & CONF_FLAG_FILE_WRITABLE))) {
897 return 0;
898 }
899
900 if (rule->data) {
901 *(char **) rule->data = NULL;
902 } else if (base) {
903 *(char **) (((char *)base) + rule->offset) = NULL;
904 } else {
905 return 0;
906 }
907
908 return 0;
909}
910
912{
913 cf_item_foreach(&cs->item, ci) {
914 /*
915 * Don't recurse on sections. We can only safely
916 * check conf pairs at the same level as the
917 * section that was just parsed.
918 */
919 if (ci->type == CONF_ITEM_SECTION) continue;
920 if (ci->type == CONF_ITEM_PAIR) {
921 CONF_PAIR *cp;
922
923 cp = cf_item_to_pair(ci);
924 if (cp->parsed || cp->referenced || (ci->lineno < 0)) continue;
925
926 WARN("%s[%d]: The item '%s' is defined, but is unused by the configuration",
927 ci->filename, ci->lineno,
928 cp->attr);
929 }
930
931 /*
932 * Skip everything else.
933 */
934 }
935}
936
937/** Parse a subsection
938 *
939 * @note Turns out using nested structures (instead of pointers) for subsections, was actually
940 * a pretty bad design decision, and will need to be fixed at some future point.
941 * For now we have a horrible hack where only multi-subsections get an array of structures
942 * of the appropriate size.
943 *
944 * @param[in] ctx to allocate any additional structures under.
945 * @param[out] out pointer to a struct/pointer to fill with data.
946 * @param[in] base address of the structure out points into.
947 * May be NULL in the case of manual parsing.
948 * @param[in] cs to parse.
949 * @param[in] rule to parse the subcs with.
950 * @return
951 * - 0 on success.
952 * - -1 on general error.
953 * - -2 if a deprecated #CONF_ITEM was found.
954 */
955static int cf_subsection_parse(TALLOC_CTX *ctx, void *out, void *base, CONF_SECTION *cs, conf_parser_t const *rule)
956{
957 CONF_SECTION *subcs = NULL;
958 int count = 0, i = 0, ret;
959
960 size_t subcs_size = rule->subcs_size;
961 conf_parser_t const *rules = rule->subcs;
962
963 uint8_t **array = NULL;
964
966
967 subcs = cf_section_find(cs, rule->name1, rule->name2);
968 if (!subcs) return 0;
969
970 /*
971 * Handle the single subsection case (which is simple)
972 */
973 if (!(rule->flags & CONF_FLAG_MULTI)) {
974 uint8_t *buff = NULL;
975
976 if (DEBUG_ENABLED4) cf_log_debug(cs, "Evaluating rules for %s section. Output %p",
977 cf_section_name1(subcs), out);
978
979 /*
980 * Add any rules, so the func can just call cf_section_parse
981 * if it wants to continue after doing its stuff.
982 */
983 if (cf_section_rules_push(subcs, rules) < 0) return -1;
984 if (rule->func) return rule->func(ctx, out, base, cf_section_to_item(subcs), rule);
985
986 /*
987 * FIXME: We shouldn't allow nested structures like this.
988 * Each subsection struct should be allocated separately so
989 * we have a clean talloc hierarchy.
990 */
991 if (!subcs_size) return cf_section_parse(ctx, out, subcs);
992
993 if (out) {
994 MEM(buff = talloc_zero_array(ctx, uint8_t, subcs_size));
995 if (rule->subcs_type) talloc_set_name_const(buff, rule->subcs_type);
996 }
997
998 ret = cf_section_parse(buff, buff, subcs);
999 if (ret < 0) {
1001 return ret;
1002 }
1003
1004 if (out) *((uint8_t **)out) = buff;
1005
1006 return 0;
1007 }
1008
1009 fr_assert(subcs_size);
1010
1011 /*
1012 * Handle the multi subsection case (which is harder)
1013 */
1014 subcs = NULL;
1015 while ((subcs = cf_section_find_next(cs, subcs, rule->name1, rule->name2))) count++;
1016
1017 /*
1018 * Allocate an array to hold the subsections
1019 */
1020 if (out) {
1021 MEM(array = talloc_zero_array(ctx, uint8_t *, count));
1022 if (rule->subcs_type) talloc_set_name(array, "%s *", rule->subcs_type);
1023 }
1024 /*
1025 * Start parsing...
1026 *
1027 * Note, we allocate each subsection structure individually
1028 * so that they can be used as talloc contexts and we can
1029 * keep the talloc hierarchy clean.
1030 */
1031 subcs = NULL;
1032 while ((subcs = cf_section_find_next(cs, subcs, rule->name1, rule->name2))) {
1033 uint8_t *buff = NULL;
1034
1035 if (DEBUG_ENABLED4) cf_log_debug(cs, "Evaluating rules for %s[%i] section. Output %p",
1036 cf_section_name1(subcs),
1037 i, out);
1038
1039 if (array) {
1040 MEM(buff = talloc_zero_array(array, uint8_t, subcs_size));
1041 if (rule->subcs_type) talloc_set_name_const(buff, rule->subcs_type);
1042 array[i++] = buff;
1043 }
1044
1045 /*
1046 * Add any rules, so the func can just call cf_section_parse
1047 * if it wants to continue after doing its stuff.
1048 */
1049 if (cf_section_rules_push(subcs, rules) < 0) {
1050 talloc_free(array);
1051 return -1;
1052 }
1053 if (rule->func) {
1054 ret = rule->func(ctx, buff, base, cf_section_to_item(subcs), rule);
1055 if (ret < 0) {
1056 talloc_free(array);
1057 return ret;
1058 }
1059 continue;
1060 }
1061
1062 ret = cf_section_parse(buff, buff, subcs);
1063 if (ret < 0) {
1064 talloc_free(array);
1065 return ret;
1066 }
1067 }
1068
1069 if (out) *((uint8_t ***)out) = array;
1070
1071 return 0;
1072}
1073
1074static int cf_section_parse_rule(TALLOC_CTX *ctx, void *base, CONF_SECTION *cs, conf_parser_t const *rule)
1075{
1076 int ret;
1077 bool *is_set = NULL;
1078 void *data = NULL;
1079
1080 /*
1081 * Ignore ON_READ parse rules if there's no subsequent
1082 * parse functions.
1083 */
1084 if (!rule->func && rule->on_read) return 0;
1085
1086 /*
1087 * Pre-allocate the config structure to hold default values
1088 */
1089 if (cf_section_parse_init(cs, base, rule) < 0) return -1;
1090
1091 if (rule->data) {
1092 data = rule->data; /* prefer this. */
1093 } else if (base) {
1094 data = ((uint8_t *)base) + rule->offset;
1095 }
1096
1097 /*
1098 * Handle subsections specially
1099 */
1100 if (rule->flags & CONF_FLAG_SUBSECTION) {
1101 return cf_subsection_parse(ctx, data, base, cs, rule);
1102 }
1103
1104 /*
1105 * Ignore this rule if it's a reference, as the
1106 * rules it points to have been pushed by the
1107 * above function.
1108 */
1109 if ((rule->flags & CONF_FLAG_REF) != 0) {
1110 conf_parser_t const *rule_p;
1111 uint8_t *sub_base = base;
1112
1113 fr_assert(rule->subcs != NULL);
1114
1115 sub_base += rule->offset;
1116
1117 for (rule_p = rule->subcs; rule_p->name1; rule_p++) {
1118 if (rule_p->flags & CONF_FLAG_DEPRECATED) continue; /* Skip deprecated */
1119
1120 ret = cf_section_parse_rule(ctx, sub_base, cs, rule_p);
1121 if (ret < 0) return ret;
1122 }
1123
1124 /*
1125 * Ensure we have a proper terminator, type so we catch
1126 * missing terminators reliably
1127 */
1128 fr_cond_assert(rule_p->type == conf_term.type);
1129
1130 return 0;
1131 }
1132
1133 /*
1134 * Else it's a CONF_PAIR
1135 */
1136
1137 /*
1138 * Pair either needs an output destination or
1139 * there needs to be a function associated with
1140 * it.
1141 */
1142 if (!data && !rule->func) {
1143 cf_log_err(cs, "Rule doesn't specify output destination");
1144 return -1;
1145 }
1146
1147 /*
1148 * Get pointer to where we need to write out
1149 * whether the pointer was set.
1150 */
1151 if (rule->flags & CONF_FLAG_IS_SET) {
1152 is_set = rule->data ? rule->is_set_ptr : ((uint8_t *)base) + rule->is_set_offset;
1153 }
1154
1155 /*
1156 * Parse the pair we found, or a default value.
1157 */
1158 ret = cf_pair_parse_internal(ctx, data, base, cs, rule);
1159 switch (ret) {
1160 case 1: /* Used default (or not present) */
1161 if (is_set) *is_set = false;
1162 ret = 0;
1163 break;
1164
1165 case 0: /* OK */
1166 if (is_set) *is_set = true;
1167 break;
1168
1169 case -1: /* Parse error */
1170 break;
1171
1172 case -2: /* Deprecated CONF ITEM */
1173 if (((rule + 1)->offset && ((rule + 1)->offset == rule->offset)) ||
1174 ((rule + 1)->data && ((rule + 1)->data == rule->data))) {
1175 cf_log_err(cs, "Replace \"%s\" with \"%s\"", rule->name1,
1176 (rule + 1)->name1);
1177 }
1178 break;
1179 }
1180
1181 return ret;
1182}
1183
1184/** Parse a configuration section into user-supplied variables
1185 *
1186 * @param[in] ctx to allocate any strings, or additional structures in.
1187 * Usually the same as base, unless base is a nested struct.
1188 * @param[out] base pointer to a struct to fill with data.
1189 * @param[in] cs to parse.
1190 * @return
1191 * - 0 on success.
1192 * - -1 on general error.
1193 * - -2 if a deprecated #CONF_ITEM was found.
1194 */
1195int cf_section_parse(TALLOC_CTX *ctx, void *base, CONF_SECTION *cs)
1196{
1197 CONF_DATA const *rule_cd = NULL;
1198
1199 if (!cs->name2) {
1200 cf_log_debug(cs, "%.*s%s {", SECTION_SPACE(cs), parse_spaces, cs->name1);
1201 } else {
1202 cf_log_debug(cs, "%.*s%s %s {", SECTION_SPACE(cs), parse_spaces, cs->name1, cs->name2);
1203 }
1204
1205 /*
1206 * Loop over all the child rules of the section
1207 */
1208 while ((rule_cd = cf_data_find_next(cs, rule_cd, conf_parser_t, CF_IDENT_ANY))) {
1209 int ret;
1210 conf_parser_t *rule;
1211
1212 rule = cf_data_value(rule_cd);
1213
1214 ret = cf_section_parse_rule(ctx, base, cs, rule);
1215 if (ret < 0) return ret;
1216 }
1217
1218 cs->base = base;
1219
1220 /*
1221 * Warn about items in the configuration which weren't
1222 * checked during parsing.
1223 */
1225
1226 cf_log_debug(cs, "%.*s}", SECTION_SPACE(cs), parse_spaces);
1227
1228 return 0;
1229}
1230
1231/*
1232 * Pass2 fixups on tmpl_t
1233 *
1234 * We don't have (or need yet) cf_pair_parse_pass2(), so we just
1235 * do it for tmpls.
1236 */
1238 bool attribute, fr_dict_t const *dict_def)
1239{
1240 tmpl_t *vpt = *out;
1241
1242 fr_assert(vpt); /* We need something to resolve */
1243
1244 if (tmpl_resolve(vpt, &(tmpl_res_rules_t){ .dict_def = dict_def, .force_dict_def = (dict_def != NULL)}) < 0) {
1245 cf_log_perr(cp, "Failed processing configuration item '%s'", cp->attr);
1246 return -1;
1247 }
1248
1249 if (attribute) {
1250 if (!tmpl_is_attr(vpt)) {
1251 cf_log_err(cp, "Expected attr got %s",
1252 tmpl_type_to_str(vpt->type));
1253 return -1;
1254 }
1255 }
1256
1257 switch (vpt->type) {
1258 /*
1259 * All attributes should have been defined by this point.
1260 */
1262 cf_log_err(cp, "Unknown attribute '%s'", tmpl_attr_tail_unresolved(vpt));
1263 return -1;
1264
1266 /*
1267 * Try to realize the underlying type, if at all possible.
1268 */
1269 if (!attribute && type && (tmpl_cast_in_place(vpt, type, NULL) < 0)) {
1270 cf_log_perr(cp, "Failed processing configuration item '%s'", cp->attr);
1271 return -1;
1272 }
1273 break;
1274
1275 case TMPL_TYPE_ATTR:
1276 if (!check_config) break;
1277
1278 if (vpt->name[0] != '&') break;
1279
1280 if (main_config_migrate_option_get("call_env_forbid_ampersand")) {
1281 cf_log_err(cp, "Please remove '&' from the attribute name");
1282 return -1;
1283 }
1284 cf_log_warn(cp, "Please remove '&' from the attribute name");
1285 break;
1286
1287 case TMPL_TYPE_DATA:
1288 case TMPL_TYPE_EXEC:
1290 case TMPL_TYPE_XLAT:
1292 break;
1293
1295 case TMPL_TYPE_REGEX:
1299 case TMPL_TYPE_MAX:
1300 fr_assert(0);
1301 /* Don't add default */
1302 }
1303
1304 return 0;
1305}
1306
1307/** Fixup xlat expansions and attributes
1308 *
1309 * @param[out] base start of structure to write #tmpl_t s to.
1310 * @param[in] cs CONF_SECTION to fixup.
1311 * @return
1312 * - 0 on success.
1313 * - -1 on failure (parse errors etc...).
1314 */
1316{
1317 CONF_DATA const *rule_cd = NULL;
1318
1319 while ((rule_cd = cf_data_find_next(cs, rule_cd, conf_parser_t, CF_IDENT_ANY))) {
1320 bool attribute, multi, is_tmpl, is_xlat;
1321 CONF_PAIR *cp;
1322 conf_parser_t *rule = cf_data_value(rule_cd);
1323 void *data;
1324 fr_type_t type = rule->type;
1325 conf_parser_flags_t flags = rule->flags;
1326 fr_dict_t const *dict = NULL;
1327
1328 is_tmpl = (flags & CONF_FLAG_TMPL);
1329 is_xlat = (flags & CONF_FLAG_XLAT);
1330 attribute = (flags & CONF_FLAG_ATTRIBUTE);
1331 multi = (flags & CONF_FLAG_MULTI);
1332
1333 /*
1334 * It's a section, recurse!
1335 */
1336 if (flags & CONF_FLAG_SUBSECTION) {
1337 uint8_t *subcs_base;
1338 CONF_SECTION *subcs = cf_section_find(cs, rule->name1, rule->name2);
1339
1340 /*
1341 * Select base by whether this is a nested struct,
1342 * or a pointer to another struct.
1343 */
1344 if (!base) {
1345 subcs_base = NULL;
1346 } else if (multi) {
1347 size_t j, len;
1348 uint8_t **array;
1349
1350 array = *(uint8_t ***)(((uint8_t *)base) + rule->offset);
1351 len = talloc_array_length(array);
1352
1353 for (j = 0; j < len; j++) if (cf_section_parse_pass2(array[j], subcs) < 0) return -1;
1354 continue;
1355 } else {
1356 subcs_base = (uint8_t *)base + rule->offset;
1357 }
1358
1359 if (cf_section_parse_pass2(subcs_base, subcs) < 0) return -1;
1360
1361 continue;
1362 }
1363
1364 /*
1365 * Find the CONF_PAIR, may still not exist if there was
1366 * no default set for the conf_parser_t.
1367 */
1368 cp = cf_pair_find(cs, rule->name1);
1369 if (!cp) continue;
1370
1371 /*
1372 * Figure out which data we need to fix.
1373 */
1374 data = rule->data; /* prefer this. */
1375 if (!data && base) data = ((char *)base) + rule->offset;
1376 if (!data) continue;
1377
1378 /*
1379 * Non-xlat expansions shouldn't have xlat!
1380 *
1381 * Except other libraries like libkafka may be the ones
1382 * doing the actual expansion, so we don't _know_
1383 * if the xlatlike value is destined for use in FreeRADIUS
1384 * or not, so we can't definitely determine if this is an
1385 * error.
1386 *
1387 * Code left in place to warn other people off re-adding
1388 * this check in future.
1389 */
1390#if 0
1391 if (!is_xlat && !is_tmpl) {
1392 /*
1393 * Ignore %{... in shared secrets.
1394 * They're never dynamically expanded.
1395 */
1396 if ((rule->flags & CONF_FLAG_SECRET) != 0) continue;
1397
1398 if (strstr(cp->value, "%{") != NULL) {
1399 cf_log_err(cp, "Found dynamic expansion in string which "
1400 "will not be dynamically expanded");
1401 return -1;
1402 }
1403 continue;
1404 }
1405#endif
1406
1407 /*
1408 * Search for dictionary data somewhere in the virtual
1409 * server.
1410 */
1412
1413 /*
1414 * Parse (and throw away) the xlat string (for validation).
1415 *
1416 * FIXME: All of these should be converted from CONF_FLAG_XLAT
1417 * to CONF_FLAG_TMPL.
1418 */
1419 if (is_xlat) {
1420 ssize_t slen;
1421 xlat_exp_head_t *xlat;
1422
1423 redo:
1424 xlat = NULL;
1425
1426 /*
1427 * xlat expansions should be parseable.
1428 */
1429 slen = xlat_tokenize(cs, &xlat,
1430 &FR_SBUFF_IN(cp->value, talloc_array_length(cp->value) - 1), NULL,
1431 &(tmpl_rules_t) {
1432 .attr = {
1433 .dict_def = dict,
1434 .list_def = request_attr_request,
1435 .allow_unknown = false,
1436 .allow_unresolved = false,
1437 .allow_foreign = (dict == NULL)
1438 },
1439 });
1440 if (slen < 0) {
1441 char *spaces, *text;
1442
1443 fr_canonicalize_error(cs, &spaces, &text, slen, cp->value);
1444
1445 cf_log_err(cp, "Failed parsing expansion string:");
1446 cf_log_err(cp, "%s", text);
1447 cf_log_perr(cp, "%s^", spaces);
1448
1450 talloc_free(text);
1451 talloc_free(xlat);
1452 return -1;
1453 }
1454
1455 talloc_free(xlat);
1456
1457 /*
1458 * If the "multi" flag is set, check all of them.
1459 */
1460 if (multi) {
1461 cp = cf_pair_find_next(cs, cp, cp->attr);
1462 if (cp) goto redo;
1463 }
1464 continue;
1465
1466 /*
1467 * Parse the pair into a template
1468 */
1469 } else if (is_tmpl && !multi) {
1470 if (cf_parse_tmpl_pass2(cs, (tmpl_t **)data, cp, type, attribute, dict) < 0) {
1471 return -1;
1472 }
1473
1474 } else if (is_tmpl) {
1475 size_t i;
1476 char const *name = cp->attr;
1477 tmpl_t **array = *(tmpl_t ***) data;
1478
1479 for (i = 0; i < talloc_array_length(array); i++, cp = cf_pair_find_next(cs, cp, name)) {
1480 if (!cp) break;
1481
1482 if (cf_parse_tmpl_pass2(cs, &array[i], cp, type, attribute, dict) < 0) {
1483 return -1;
1484 }
1485 }
1486 }
1487 }
1488
1489 return 0;
1490}
1491
1492
1493/** Add a single rule to a #CONF_SECTION
1494 *
1495 * @param[in] cs to add rules to.
1496 * @param[in] rule to add.
1497 * @param[in] filename where the rule was pushed.
1498 * @param[in] lineno where the rule was pushed.
1499 * @return
1500 * - 0 on success.
1501 * - -1 if the rules added conflict.
1502 */
1503int _cf_section_rule_push(CONF_SECTION *cs, conf_parser_t const *rule, char const *filename, int lineno)
1504{
1505 char const *name1, *name2;
1506
1507 if (!cs || !rule) return 0;
1508
1509 name1 = rule->name1 == CF_IDENT_ANY ? "__any__" : rule->name1;
1510 name2 = rule->name2 == CF_IDENT_ANY ? "__any__" : rule->name2;
1511
1512 if (DEBUG_ENABLED4) {
1513 cf_log_debug(cs, "Pushed parse rule to %s section: %s %s",
1514 cf_section_name1(cs),
1515 name1, rule->flags & CONF_FLAG_SUBSECTION ? "{}": "");
1516 }
1517
1518 /*
1519 * Qualifying with name prevents duplicate rules being added
1520 *
1521 * Fixme maybe?.. Can't have a section and pair with the same name.
1522 */
1523 if (!_cf_data_add_static(CF_TO_ITEM(cs), rule, "conf_parser_t", name1, filename, lineno)) {
1524 CONF_DATA const *cd;
1525 conf_parser_t *old;
1526
1527 cd = cf_data_find(CF_TO_ITEM(cs), conf_parser_t, name1);
1528 old = cf_data_value(cd);
1529 fr_assert(old != NULL);
1530
1531 /*
1532 * Shut up about duplicates.
1533 */
1534 if (memcmp(rule, old, sizeof(*rule)) == 0) {
1535 return 0;
1536 }
1537
1538 /*
1539 * Remove any ON_READ callbacks, and add the new
1540 * rule in its place.
1541 */
1542 if (old->on_read) {
1543 CONF_DATA *cd1;
1544
1545 /*
1546 * Over-write the rule in place.
1547 *
1548 * We'd like to call cf_item_remove(), but
1549 * that apparently doesn't work for
1550 * CONF_DATA. We don't need to
1551 * free/alloc one, so re-using this is
1552 * fine.
1553 */
1554 memcpy(&cd1, &cd, sizeof(cd1));
1555 cd1->data = rule;
1556 cd1->item.filename = filename;
1557 cd1->item.lineno = lineno;
1558 return 0;
1559 }
1560
1561 /*
1562 * If we have a duplicate sub-section, just
1563 * recurse and add the new sub-rules to the
1564 * existing sub-section.
1565 */
1566 if (rule->flags & CONF_FLAG_SUBSECTION) {
1567 CONF_SECTION *subcs;
1568
1569 subcs = cf_section_find(cs, name1, name2);
1570 if (!subcs) {
1571 cf_log_err(cs, "Failed finding '%s' subsection", name1);
1572 cf_item_debug(cs);
1573 return -1;
1574 }
1575
1576 /*
1577 * The old rules were delayed until we pushed a matching subsection which is actually used.
1578 */
1579 if ((old->flags & CONF_FLAG_OPTIONAL) != 0) {
1580 if (cf_section_rules_push(subcs, old->subcs) < 0) return -1;
1581 }
1582
1583 return cf_section_rules_push(subcs, rule->subcs);
1584 }
1585
1586 cf_log_err(cs, "Data of type %s with name \"%s\" already exists. "
1587 "Existing data added %s[%i]", "conf_parser_t",
1588 name1, cd->item.filename, cd->item.lineno);
1589
1590 cf_item_debug(cs);
1591 return -1;
1592 }
1593
1594 return 0;
1595}
1596
1597/** Add an array of parse rules to a #CONF_SECTION
1598 *
1599 * @param[in] cs to add rules to.
1600 * @param[in] rules to add. Last element should have NULL name field.
1601 * @param[in] filename where the rule was pushed.
1602 * @param[in] lineno where the rule was pushed.
1603 * @return
1604 * - 0 on success.
1605 * - -1 on failure.
1606 */
1607int _cf_section_rules_push(CONF_SECTION *cs, conf_parser_t const *rules, char const *filename, int lineno)
1608{
1609 conf_parser_t const *rule_p;
1610
1611 if (!cs || !rules) return 0;
1612
1613 for (rule_p = rules; rule_p->name1; rule_p++) {
1614 if (rule_p->flags & CONF_FLAG_DEPRECATED) continue; /* Skip deprecated */
1615 if (_cf_section_rule_push(cs, rule_p, filename, lineno) < 0) return -1;
1616 }
1617
1618 /*
1619 * Ensure we have a proper terminator, type so we catch
1620 * missing terminators reliably
1621 */
1622 fr_cond_assert(rule_p->type == conf_term.type);
1623
1624 return 0;
1625}
1626
1627/** Generic function for parsing conf pair values as int
1628 *
1629 * @note This should be used for enum types as c99 6.4.4.3 states that the enumeration
1630 * constants are of type int.
1631 *
1632 */
1633int cf_table_parse_int(UNUSED TALLOC_CTX *ctx, void *out, UNUSED void *parent,
1634 CONF_ITEM *ci, conf_parser_t const *rule)
1635{
1636 int num;
1637 cf_table_parse_ctx_t const *parse_ctx = rule->uctx;
1638
1639 if (cf_pair_in_table(&num, parse_ctx->table, *parse_ctx->len, cf_item_to_pair(ci)) < 0) return -1;
1640
1641 *((int *)out) = num;
1642
1643 return 0;
1644}
1645
1646/** Generic function for parsing conf pair values as int32_t (FR_TYPE_INT32)
1647 *
1648 */
1649int cf_table_parse_int32(UNUSED TALLOC_CTX *ctx, void *out, UNUSED void *parent,
1650 CONF_ITEM *ci, conf_parser_t const *rule)
1651{
1652 int32_t num;
1653 cf_table_parse_ctx_t const *parse_ctx = rule->uctx;
1654
1655 if (cf_pair_in_table(&num, parse_ctx->table, *parse_ctx->len, cf_item_to_pair(ci)) < 0) return -1;
1656
1657 *((int32_t *)out) = num;
1658
1659 return 0;
1660}
1661
1662/** Generic function for parsing conf pair values as int32_t (FR_TYPE_UINT32)
1663 *
1664 */
1665int cf_table_parse_uint32(UNUSED TALLOC_CTX *ctx, void *out, UNUSED void *parent,
1666 CONF_ITEM *ci, conf_parser_t const *rule)
1667{
1668 int32_t num;
1669 cf_table_parse_ctx_t const *parse_ctx = rule->uctx;
1670
1671 if (cf_pair_in_table(&num, parse_ctx->table, *parse_ctx->len, cf_item_to_pair(ci)) < 0) return -1;
1672 if (num < 0) {
1673 cf_log_err(ci, "Resolved value must be a positive integer, got %i", num);
1674 return -1;
1675 }
1676 *((uint32_t *)out) = (uint32_t)num;
1677
1678 return 0;
1679}
1680
1681/** Generic function for resolving UID strings to uid_t values
1682 *
1683 * Type should be FR_TYPE_VOID, struct field should be a uid_t.
1684 */
1685int cf_parse_uid(TALLOC_CTX *ctx, void *out, UNUSED void *parent,
1686 CONF_ITEM *ci, UNUSED conf_parser_t const *rule)
1687{
1688 if (fr_perm_uid_from_str(ctx, (uid_t *)out, cf_pair_value(cf_item_to_pair(ci))) < 0) {
1689 cf_log_perr(ci, "Failed resolving UID");
1690 return -1;
1691 }
1692
1693 return 0;
1694}
1695
1696/** Generic function for resolving GID strings to uid_t values
1697 *
1698 * Type should be FR_TYPE_VOID, struct field should be a gid_t.
1699 */
1700int cf_parse_gid(TALLOC_CTX *ctx, void *out, UNUSED void *parent,
1701 CONF_ITEM *ci, UNUSED conf_parser_t const *rule)
1702{
1703 if (fr_perm_gid_from_str(ctx, (gid_t *)out, cf_pair_value(cf_item_to_pair(ci))) < 0) {
1704 cf_log_perr(ci, "Failed resolving GID");
1705 return -1;
1706 }
1707
1708 return 0;
1709}
1710
1711/** Generic function for resolving permissions to a mode-t
1712 *
1713 * Type should be FR_TYPE_VOID, struct field should be a gid_t.
1714 */
1715int cf_parse_permissions(UNUSED TALLOC_CTX *ctx, void *out, UNUSED void *parent,
1716 CONF_ITEM *ci, UNUSED conf_parser_t const *rule)
1717{
1718 mode_t mode;
1719 char const *name = cf_pair_value(cf_item_to_pair(ci));
1720
1721 if (fr_perm_mode_from_str(&mode, name) < 0) {
1722 cf_log_perr(ci, "Invalid permissions string");
1723 return -1;
1724 }
1725
1726 *(mode_t *) out = mode;
1727
1728 return 0;
1729}
1730
1731/** NULL callback for sections
1732 *
1733 * This callback exists only as a place-holder to ensure that the
1734 * nested on_read functions are called. The conf file routines won't
1735 * recurse into every conf_parser_t section to check if there's an
1736 * "on_read" callback. So this place-holder is a signal to do that.
1737 *
1738 * @param[in] ctx to allocate data in.
1739 * @param[out] out Unused
1740 * @param[in] parent Base structure address.
1741 * @param[in] ci #CONF_SECTION containing the current section.
1742 * @param[in] rule unused.
1743 * @return
1744 * - 0 on success.
1745 * - -1 on failure.
1746 */
1747int cf_null_on_read(UNUSED TALLOC_CTX *ctx, UNUSED void *out, UNUSED void *parent,
1748 UNUSED CONF_ITEM *ci, UNUSED conf_parser_t const *rule)
1749{
1750 return 0;
1751}
static int const char char buffer[256]
Definition acutest.h:576
#define RCSID(id)
Definition build.h:485
#define unlikely(_x)
Definition build.h:383
#define UNUSED
Definition build.h:317
bool check_config
Definition cf_file.c:66
char const * cf_expand_variables(char const *cf, int lineno, CONF_SECTION *outer_cs, char *output, size_t outsize, char const *input, ssize_t inlen, bool *soft_fail)
Definition cf_file.c:188
cf_file_check_err_t cf_file_check_unix_perm(char const *filename, UNUSED void *uctx)
Check if file exists, and is a socket.
Definition cf_file.c:811
cf_file_check_err_t cf_file_check(CONF_PAIR *cp, bool check_perms)
Do some checks on the file as an "input" file.
Definition cf_file.c:907
cf_file_check_err_t cf_file_check_effective(char const *filename, cf_file_check_err_t(*cb)(char const *filename, void *uctx), void *uctx)
Perform an operation with the effect/group set to conf_check_gid and conf_check_uid.
Definition cf_file.c:686
cf_file_check_err_t cf_file_check_unix_connect(char const *filename, UNUSED void *uctx)
Check if we can connect to a unix socket.
Definition cf_file.c:738
@ CF_FILE_NO_UNIX_SOCKET
File is not a unix socket.
Definition cf_file.h:49
int cf_table_parse_uint32(UNUSED TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
Generic function for parsing conf pair values as int32_t (FR_TYPE_UINT32)
Definition cf_parse.c:1665
int cf_section_parse(TALLOC_CTX *ctx, void *base, CONF_SECTION *cs)
Parse a configuration section into user-supplied variables.
Definition cf_parse.c:1195
int cf_table_parse_int32(UNUSED TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
Generic function for parsing conf pair values as int32_t (FR_TYPE_INT32)
Definition cf_parse.c:1649
static int cf_pair_default(CONF_PAIR **out, void *parent, CONF_SECTION *cs, conf_parser_t const *rule)
Allocate a pair using the dflt value and quotation.
Definition cf_parse.c:367
#define PAIR_SPACE(_cs)
Definition cf_parse.c:49
static char const parse_spaces[]
Definition cf_parse.c:47
int cf_table_parse_int(UNUSED TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
Generic function for parsing conf pair values as int.
Definition cf_parse.c:1633
int cf_pair_parse_value(TALLOC_CTX *ctx, void *out, UNUSED void *base, CONF_ITEM *ci, conf_parser_t const *rule)
Parses a CONF_PAIR into a C data type.
Definition cf_parse.c:214
static int cf_pair_unescape(CONF_PAIR *cp, conf_parser_t const *rule)
Definition cf_parse.c:423
static void cf_section_parse_warn(CONF_SECTION *cs)
Definition cf_parse.c:911
static conf_parser_t conf_term
Definition cf_parse.c:46
int cf_parse_gid(TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, UNUSED conf_parser_t const *rule)
Generic function for resolving GID strings to uid_t values.
Definition cf_parse.c:1700
int cf_pair_parse(TALLOC_CTX *ctx, CONF_SECTION *cs, char const *name, unsigned int type, void *data, char const *dflt, fr_token_t dflt_quote)
Parses a CONF_PAIR into a C data type, with a default value.
Definition cf_parse.c:771
void cf_pair_debug_log(CONF_SECTION const *cs, CONF_PAIR *cp, conf_parser_t const *rule)
Definition cf_parse.c:52
int cf_null_on_read(UNUSED TALLOC_CTX *ctx, UNUSED void *out, UNUSED void *parent, UNUSED CONF_ITEM *ci, UNUSED conf_parser_t const *rule)
NULL callback for sections.
Definition cf_parse.c:1747
static int cf_pair_parse_internal(TALLOC_CTX *ctx, void *out, void *base, CONF_SECTION *cs, conf_parser_t const *rule)
Parses a CONF_PAIR into a C data type, with a default value.
Definition cf_parse.c:511
int cf_parse_permissions(UNUSED TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, UNUSED conf_parser_t const *rule)
Generic function for resolving permissions to a mode-t.
Definition cf_parse.c:1715
int cf_section_parse_pass2(void *base, CONF_SECTION *cs)
Fixup xlat expansions and attributes.
Definition cf_parse.c:1315
static int cf_section_parse_init(CONF_SECTION *cs, void *base, conf_parser_t const *rule)
Pre-allocate a config section structure to allow defaults to be set.
Definition cf_parse.c:793
int _cf_section_rule_push(CONF_SECTION *cs, conf_parser_t const *rule, char const *filename, int lineno)
Add a single rule to a CONF_SECTION.
Definition cf_parse.c:1503
#define SECTION_SPACE(_cs)
Definition cf_parse.c:50
int _cf_section_rules_push(CONF_SECTION *cs, conf_parser_t const *rules, char const *filename, int lineno)
Add an array of parse rules to a CONF_SECTION.
Definition cf_parse.c:1607
int cf_pair_to_value_box(TALLOC_CTX *ctx, fr_value_box_t *out, CONF_PAIR *cp, conf_parser_t const *rule)
Parses a CONF_PAIR into a boxed value.
Definition cf_parse.c:129
static int cf_subsection_parse(TALLOC_CTX *ctx, void *out, void *base, CONF_SECTION *cs, conf_parser_t const *rule)
Parse a subsection.
Definition cf_parse.c:955
int cf_parse_uid(TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, UNUSED conf_parser_t const *rule)
Generic function for resolving UID strings to uid_t values.
Definition cf_parse.c:1685
static int cf_parse_tmpl_pass2(UNUSED CONF_SECTION *cs, tmpl_t **out, CONF_PAIR *cp, fr_type_t type, bool attribute, fr_dict_t const *dict_def)
Definition cf_parse.c:1237
static int cf_section_parse_rule(TALLOC_CTX *ctx, void *base, CONF_SECTION *cs, conf_parser_t const *rule)
Definition cf_parse.c:1074
#define CONF_PARSER_TERMINATOR
Definition cf_parse.h:662
cf_parse_t func
Override default parsing behaviour for the specified type with a custom parsing function.
Definition cf_parse.h:616
#define fr_rule_file_writable(_rule)
Definition cf_parse.h:481
void const * uctx
User data accessible by the cf_parse_t func.
Definition cf_parse.h:622
void * data
Pointer to a static variable to write the parsed value to.
Definition cf_parse.h:613
#define fr_rule_file_readable(_rule)
Definition cf_parse.h:479
#define fr_rule_file_socket(_rule)
Definition cf_parse.h:483
#define fr_rule_dflt(_rule)
Definition cf_parse.h:495
conf_parser_flags_t flags
Flags which control parsing behaviour.
Definition cf_parse.h:605
#define fr_rule_not_empty(_rule)
Definition cf_parse.h:489
fr_type_t type
An fr_type_t value, controls the output type.
Definition cf_parse.h:603
size_t offset
Relative offset of field or structure to write the parsed value to.
Definition cf_parse.h:607
#define fr_rule_multi(_rule)
Definition cf_parse.h:487
char const * name2
Second identifier for CONF_SECTION.
Definition cf_parse.h:601
fr_token_t quote
Quoting around the default value. Only used for templates.
Definition cf_parse.h:654
fr_table_num_sorted_t const * table
Definition cf_parse.h:658
#define fr_rule_file_exists(_rule)
Definition cf_parse.h:485
#define fr_rule_deprecated(_rule)
Definition cf_parse.h:473
int(* cf_parse_t)(TALLOC_CTX *ctx, void *out, void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
Callback for performing custom parsing of a CONF_SECTION or CONF_PAIR.
Definition cf_parse.h:556
#define cf_section_rules_push(_cs, _rule)
Definition cf_parse.h:694
#define fr_rule_is_tmpl(_rule)
Definition cf_parse.h:501
char const * name1
Name of the CONF_ITEM to parse.
Definition cf_parse.h:600
#define fr_rule_is_attribute(_rule)
Definition cf_parse.h:497
cf_parse_t on_read
Function to call as the item is being read, just after it has been allocated and initialized.
Definition cf_parse.h:619
#define fr_rule_required(_rule)
Definition cf_parse.h:475
conf_parser_flags_t
Definition cf_parse.h:426
@ CONF_FLAG_REQUIRED
Error out if no matching CONF_PAIR is found, and no dflt value is set.
Definition cf_parse.h:434
@ CONF_FLAG_MULTI
CONF_PAIR can have multiple copies.
Definition cf_parse.h:451
@ CONF_FLAG_REF
reference another conf_parser_t inline in this one
Definition cf_parse.h:462
@ CONF_FLAG_SECRET
Only print value if debug level >= 3.
Definition cf_parse.h:438
@ CONF_FLAG_IS_SET
Write whether this config item was left as the default to is_set_offset or is_set_ptr.
Definition cf_parse.h:456
@ CONF_FLAG_ATTRIBUTE
Value must resolve to attribute in dict (deprecated, use CONF_FLAG_TMPL).
Definition cf_parse.h:436
@ CONF_FLAG_DEPRECATED
If a matching CONF_PAIR is found, error out with a deprecated message.
Definition cf_parse.h:432
@ CONF_FLAG_XLAT
string will be dynamically expanded.
Definition cf_parse.h:448
@ CONF_FLAG_OPTIONAL
subsection is pushed only if a non-optional matching one is pushed
Definition cf_parse.h:463
@ CONF_FLAG_FILE_READABLE
File matching value must exist, and must be readable.
Definition cf_parse.h:440
@ CONF_FLAG_OK_MISSING
OK if it's missing.
Definition cf_parse.h:459
@ CONF_FLAG_SUBSECTION
Instead of putting the information into a configuration structure, the configuration file routines MA...
Definition cf_parse.h:428
@ CONF_FLAG_TMPL
CONF_PAIR should be parsed as a template.
Definition cf_parse.h:449
@ CONF_FLAG_FILE_WRITABLE
File matching value must exist, and must be writable.
Definition cf_parse.h:442
Defines a CONF_PAIR to C data type mapping.
Definition cf_parse.h:599
bool printed
Was this item printed already in debug mode?
Definition cf_priv.h:82
CONF_ITEM item
Common set of fields.
Definition cf_priv.h:102
void * base
Definition cf_priv.h:113
char const * name2
Second name token. Given foo bar {} would be bar.
Definition cf_priv.h:105
char const * attr
Attribute name.
Definition cf_priv.h:73
fr_token_t rhs_quote
Value Quoting style T_(DOUBLE|SINGLE|BACK)_QUOTE_STRING or T_BARE_WORD.
Definition cf_priv.h:78
char const * value
Attribute value.
Definition cf_priv.h:74
#define cf_item_foreach(_ci, _iter)
Iterate over the contents of a list.
Definition cf_priv.h:150
char const * name1
First name token. Given foo bar {} would be foo.
Definition cf_priv.h:104
void const * data
User data.
Definition cf_priv.h:131
char const * filename
The file the config item was parsed from.
Definition cf_priv.h:64
@ CONF_ITEM_PAIR
Definition cf_priv.h:41
@ CONF_ITEM_SECTION
Definition cf_priv.h:42
bool referenced
Was this item referenced in the config?
Definition cf_priv.h:83
CONF_ITEM item
Common set of fields.
Definition cf_priv.h:126
bool parsed
Was this item used during parsing?
Definition cf_priv.h:81
int lineno
The line number the config item began on.
Definition cf_priv.h:63
Internal data that is associated with a configuration section.
Definition cf_priv.h:125
Common header for all CONF_* types.
Definition cf_priv.h:49
Configuration AVP similar to a fr_pair_t.
Definition cf_priv.h:70
A section grouping multiple CONF_PAIR.
Definition cf_priv.h:101
CONF_PAIR * cf_pair_find_next(CONF_SECTION const *cs, CONF_PAIR const *prev, char const *attr)
Find a pair with a name matching attr, after specified pair.
Definition cf_util.c:1452
unsigned int cf_pair_count(CONF_SECTION const *cs, char const *attr)
Count the number of times an attribute occurs in a parent section.
Definition cf_util.c:1519
int cf_pair_in_table(int32_t *out, fr_table_num_sorted_t const *table, size_t table_len, CONF_PAIR *cp)
Check to see if the CONF_PAIR value is present in the specified table.
Definition cf_util.c:1965
void * cf_data_value(CONF_DATA const *cd)
Return the user assigned value of CONF_DATA.
Definition cf_util.c:1762
CONF_ITEM * cf_section_to_item(CONF_SECTION const *cs)
Cast a CONF_SECTION to a CONF_ITEM.
Definition cf_util.c:737
CONF_PAIR * cf_pair_alloc(CONF_SECTION *parent, char const *attr, char const *value, fr_token_t op, fr_token_t lhs_quote, fr_token_t rhs_quote)
Allocate a CONF_PAIR.
Definition cf_util.c:1278
void cf_pair_mark_parsed(CONF_PAIR *cp)
Mark a pair as parsed.
Definition cf_util.c:1375
char const * cf_section_name1(CONF_SECTION const *cs)
Return the second identifier of a CONF_SECTION.
Definition cf_util.c:1170
CONF_SECTION * cf_section_find(CONF_SECTION const *cs, char const *name1, char const *name2)
Find a CONF_SECTION with name1 and optionally name2.
Definition cf_util.c:1027
CONF_PAIR * cf_pair_find(CONF_SECTION const *cs, char const *attr)
Search for a CONF_PAIR with a specific name.
Definition cf_util.c:1438
CONF_DATA const * _cf_data_add_static(CONF_ITEM *ci, void const *data, char const *type, char const *name, char const *filename, int lineno)
Add non-talloced user data to a config section.
Definition cf_util.c:1827
bool cf_pair_is_parsed(CONF_PAIR *cp)
Return whether a pair has already been parsed.
Definition cf_util.c:1387
fr_token_t cf_pair_value_quote(CONF_PAIR const *pair)
Return the value (rhs) quoting of a pair.
Definition cf_util.c:1637
CONF_PAIR * cf_item_to_pair(CONF_ITEM const *ci)
Cast a CONF_ITEM to a CONF_PAIR.
Definition cf_util.c:663
CONF_SECTION * cf_section_find_next(CONF_SECTION const *cs, CONF_SECTION const *prev, char const *name1, char const *name2)
Return the next matching section.
Definition cf_util.c:1048
char const * cf_pair_value(CONF_PAIR const *pair)
Return the value of a CONF_PAIR.
Definition cf_util.c:1593
CONF_ITEM * cf_pair_to_item(CONF_PAIR const *cp)
Cast a CONF_PAIR to a CONF_ITEM.
Definition cf_util.c:721
#define cf_log_err(_cf, _fmt,...)
Definition cf_util.h:289
#define cf_data_find(_cf, _type, _name)
Definition cf_util.h:244
#define cf_canonicalize_error(_ci, _slen, _msg, _str)
Definition cf_util.h:367
#define cf_log_perr(_cf, _fmt,...)
Definition cf_util.h:296
#define cf_section_alloc(_ctx, _parent, _name1, _name2)
Definition cf_util.h:140
#define CF_TO_ITEM(_cf)
Auto cast from the input type to CONF_ITEM (which is the base type)
Definition cf_util.h:65
#define cf_log_warn(_cf, _fmt,...)
Definition cf_util.h:290
#define cf_log_debug(_cf, _fmt,...)
Definition cf_util.h:292
#define cf_data_find_next(_cf, _prev, _type, _name)
Definition cf_util.h:247
#define cf_item_debug(_cf)
Definition cf_util.h:361
#define CF_IDENT_ANY
Definition cf_util.h:78
#define fr_cond_assert(_x)
Calls panic_action ifndef NDEBUG, else logs error and evaluates to value of _x.
Definition debug.h:131
#define MEM(x)
Definition debug.h:36
static char const * spaces
Definition dependency.c:360
Test enumeration values.
Definition dict_test.h:92
#define DEBUG_ENABLED4
True if global debug level 1-3 messages are enabled.
Definition log.h:260
talloc_free(reap)
int fr_debug_lvl
Definition log.c:40
void fr_canonicalize_error(TALLOC_CTX *ctx, char **sp, char **text, ssize_t slen, char const *fmt)
Canonicalize error strings, removing tabs, and generate spaces for error marker.
Definition log.c:87
@ L_DBG_LVL_3
3rd highest priority debug messages (-xxx | -Xx).
Definition log.h:72
bool main_config_migrate_option_get(char const *name)
fr_type_t
@ FR_TYPE_STRING
String of printable characters.
@ FR_TYPE_VOID
User data.
unsigned int uint32_t
long int ssize_t
unsigned char uint8_t
unsigned int mode_t
int fr_perm_mode_from_str(mode_t *out, char const *str)
Definition perm.c:62
int fr_perm_uid_from_str(TALLOC_CTX *ctx, uid_t *out, char const *name)
Resolve a user name to a GID.
Definition perm.c:451
int fr_perm_gid_from_str(TALLOC_CTX *ctx, gid_t *out, char const *name)
Resolve a group name to a GID.
Definition perm.c:473
char * fr_asprint(TALLOC_CTX *ctx, char const *in, ssize_t inlen, char quote)
Escape string that may contain binary data, and write it to a new buffer.
Definition print.c:428
#define fr_assert(_expr)
Definition rad_assert.h:38
static char * secret
#define WARN(fmt,...)
Definition radclient.h:47
fr_dict_attr_t const * request_attr_request
Definition request.c:43
static char const * name
#define FR_SBUFF_IN(_start, _len_or_end)
static char const * tmpl_type_to_str(tmpl_type_t type)
Return a static string containing the type name.
Definition tmpl.h:634
#define tmpl_contains_data(vpt)
Definition tmpl.h:224
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_is_attr(vpt)
Definition tmpl.h:208
@ TMPL_TYPE_REGEX_UNCOMPILED
Regex where compilation is possible but hasn't been performed yet.
Definition tmpl.h:158
@ TMPL_TYPE_MAX
Marker for the last tmpl type.
Definition tmpl.h:199
@ TMPL_TYPE_ATTR_UNRESOLVED
An attribute reference that we couldn't resolve but looked valid.
Definition tmpl.h:185
@ TMPL_TYPE_ATTR
Reference to one or more attributes.
Definition tmpl.h:142
@ TMPL_TYPE_XLAT
Pre-parsed xlat expansion.
Definition tmpl.h:146
@ TMPL_TYPE_EXEC
Callout to an external script or program.
Definition tmpl.h:150
@ TMPL_TYPE_REGEX_XLAT_UNRESOLVED
A regular expression with unresolved xlat functions or attribute references.
Definition tmpl.h:197
@ TMPL_TYPE_DATA
Value in native boxed format.
Definition tmpl.h:138
@ TMPL_TYPE_REGEX
Compiled (and possibly JIT'd) regular expression.
Definition tmpl.h:154
@ TMPL_TYPE_DATA_UNRESOLVED
Unparsed literal string.
Definition tmpl.h:179
@ TMPL_TYPE_XLAT_UNRESOLVED
A xlat expansion with unresolved xlat functions or attribute references.
Definition tmpl.h:193
@ TMPL_TYPE_REGEX_XLAT
A regex containing xlat expansions.
Definition tmpl.h:162
@ TMPL_TYPE_EXEC_UNRESOLVED
An exec with unresolved xlat function or attribute references.
Definition tmpl.h:189
@ TMPL_TYPE_UNINITIALISED
Uninitialised.
Definition tmpl.h:134
ssize_t tmpl_afrom_substr(TALLOC_CTX *ctx, tmpl_t **out, fr_sbuff_t *in, fr_token_t quote, fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules))
Convert an arbitrary string into a tmpl_t.
static char const * tmpl_attr_tail_unresolved(tmpl_t const *vpt)
Return the last attribute reference unresolved da.
Definition tmpl.h:869
ssize_t tmpl_afrom_attr_substr(TALLOC_CTX *ctx, tmpl_attr_error_t *err, tmpl_t **out, fr_sbuff_t *name, fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules))
Parse a string into a TMPL_TYPE_ATTR_* type tmpl_t.
int tmpl_cast_in_place(tmpl_t *vpt, fr_type_t type, fr_dict_attr_t const *enumv))
Convert tmpl_t of type TMPL_TYPE_DATA_UNRESOLVED or TMPL_TYPE_DATA to TMPL_TYPE_DATA of type specifie...
#define tmpl_is_data(vpt)
Definition tmpl.h:206
static fr_slen_t vpt
Definition tmpl.h:1269
#define tmpl_value_type(_tmpl)
Definition tmpl.h:939
#define tmpl_is_data_unresolved(vpt)
Definition tmpl.h:217
tmpl_attr_rules_t attr
Rules/data for parsing attribute references.
Definition tmpl.h:335
int tmpl_cast_set(tmpl_t *vpt, fr_type_t type)
Set a cast for a tmpl.
Similar to tmpl_rules_t, but used to specify parameters that may change during subsequent resolution ...
Definition tmpl.h:364
Optional arguments passed to vp_tmpl functions.
Definition tmpl.h:332
static char buff[sizeof("18446744073709551615")+3]
Definition size_tests.c:41
return count
Definition module.c:155
fr_aka_sim_id_type_t type
fr_dict_attr_t const * list_def
Default list to use with unqualified attribute reference.
Definition tmpl.h:295
uint8_t allow_unknown
Allow unknown attributes i.e.
Definition tmpl.h:301
char * talloc_typed_strdup(TALLOC_CTX *ctx, char const *p)
Call talloc_strdup, setting the type on the new chunk correctly.
Definition talloc.c:467
static int talloc_const_free(void const *ptr)
Free const'd memory.
Definition talloc.h:229
const char fr_token_quote[T_TOKEN_LAST]
Convert tokens back to a quoting character.
Definition token.c:157
enum fr_token fr_token_t
@ T_INVALID
Definition token.h:39
@ T_SINGLE_QUOTED_STRING
Definition token.h:122
@ T_BARE_WORD
Definition token.h:120
@ T_OP_EQ
Definition token.h:83
@ T_BACK_QUOTED_STRING
Definition token.h:123
@ T_DOUBLE_QUOTED_STRING
Definition token.h:121
@ T_SOLIDUS_QUOTED_STRING
Definition token.h:124
fr_slen_t xlat_tokenize(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)
Tokenize an xlat expansion.
static fr_slen_t parent
Definition pair.h:841
char const * fr_strerror(void)
Get the last library error.
Definition strerror.c:553
void ** fr_type_array_alloc(TALLOC_CTX *ctx, fr_type_t type, size_t count)
Allocate an array of a given type.
Definition types.c:641
#define fr_type_is_string(_x)
Definition types.h:346
#define fr_type_is_quoted(_x)
Definition types.h:387
size_t const fr_value_box_field_sizes[]
How many bytes wide each of the value data fields are.
Definition value.c:152
ssize_t fr_value_box_from_str(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_type_t dst_type, fr_dict_attr_t const *dst_enumv, char const *in, size_t inlen, fr_sbuff_unescape_rules_t const *erules)
Definition value.c:5754
void fr_value_box_clear_value(fr_value_box_t *data)
Clear/free any existing value.
Definition value.c:4093
fr_sbuff_parse_rules_t const * value_parse_rules_unquoted[T_TOKEN_LAST]
Parse rules for non-quoted strings.
Definition value.c:514
void fr_value_box_clear(fr_value_box_t *data)
Clear/free any existing value and metadata.
Definition value.c:4139
static int fr_value_box_memcpy_out(void *out, fr_value_box_t const *vb)
Copy the value of a value box to a field in a C struct.
Definition value.h:790
#define fr_value_box_mark_safe_for(_box, _safe_for)
Definition value.h:1074
static fr_slen_t data
Definition value.h:1291
int nonnull(2, 5))
static size_t char ** out
Definition value.h:1023
#define FR_VALUE_BOX_SAFE_FOR_ANY
Definition value.h:173
fr_dict_t const * virtual_server_dict_by_child_ci(CONF_ITEM const *ci)
Return the namespace for a given virtual server specified by a CONF_ITEM within the virtual server.