The FreeRADIUS server $Id: a4e7f8c94e8038b7627bcf52356b7ed15955c1d7 $
Loading...
Searching...
No Matches
tmpl.h
Go to the documentation of this file.
1#pragma once
2/*
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
16 */
17
18/**
19 * $Id: b7632679595218f826f6fc8ab0b2df5247f4a2f8 $
20 *
21 * @file lib/server/tmpl.h
22 * @brief Structures and prototypes for templates
23 *
24 * These functions are used to work with #tmpl_t structs.
25 *
26 * #tmpl_t (VPTs) specify either a data source, or a data sink.
27 *
28 * Examples of sources are #TMPL_TYPE_XLAT_UNRESOLVED, #TMPL_TYPE_EXEC and #TMPL_TYPE_ATTR.
29 * Examples of sinks are #TMPL_TYPE_ATTR.
30 *
31 * VPTs are used to gather values or attributes for evaluation, or copying, and to specify
32 * where values or #fr_pair_t should be copied to.
33 *
34 * To create new #tmpl_t use one of the tmpl_*from_* functions. These parse
35 * strings into VPTs. The main parsing function is #tmpl_afrom_substr, which can produce
36 * most types of VPTs. It uses the type of quoting (passed as an #fr_token_t) to determine
37 * what type of VPT to parse the string as. For example a #T_DOUBLE_QUOTED_STRING will
38 * produce either a #TMPL_TYPE_XLAT_UNRESOLVED or a #TMPL_TYPE_DATA_UNRESOLVED (depending if the string
39 * contained a non-literal expansion).
40 *
41 * @see tmpl_afrom_substr
42 * @see tmpl_afrom_attr_str
43 *
44 * In the case of #TMPL_TYPE_ATTR, there are special cursor overlay
45 * functions which can be used to iterate over only the #fr_pair_t that match a
46 * tmpl_t in a given list.
47 *
48 * @see tmpl_dcursor_init
49 * @see tmpl_cursor_next
50 *
51 * Or for simplicity, there are functions which wrap the cursor functions, to copy or
52 * return the #fr_pair_t that match the VPT.
53 *
54 * @see tmpl_copy_pairs
55 * @see tmpl_find_vp
56 *
57 * If you just need the string value of whatever the VPT refers to, the tmpl_*expand
58 * functions may be used. These functions evaluate the VPT, execing, and xlat expanding
59 * as necessary. In the case of #TMPL_TYPE_ATTR, and #FR_TYPE_STRING or #FR_TYPE_OCTETS
60 * #tmpl_expand will return a pointer to the raw #fr_pair_t buffer. This can be very
61 * useful when using the #CONF_FLAG_TMPL type in #conf_parser_t structs, as it allows the
62 * user to determine whether they want the module to sanitise the value using presentation
63 * format specific #xlat_escape_legacy_t function, or to operate on the raw value.
64 *
65 * @see tmpl_expand
66 * @see tmpl_aexpand
67 *
68 * @copyright 2014-2015 The FreeRADIUS server project
69 */
70RCSIDH(tmpl_h, "$Id: b7632679595218f826f6fc8ab0b2df5247f4a2f8 $")
71
72#ifdef __cplusplus
73extern "C" {
74#endif
75
76#include <freeradius-devel/util/table.h>
77#include <freeradius-devel/util/dlist.h>
78#include <freeradius-devel/util/value.h>
79
80#include <freeradius-devel/server/tmpl_escape.h>
81
82/** The maximum number of request references allowed
83 *
84 */
85#define TMPL_MAX_REQUEST_REF_NESTING 10
86
87/** The maximum number of nested calls between the tmpl, xlat, and expression parsers.
88 *
89 * The parsers can call each other recursively, which means that we need to limit the
90 * nesting depth. If we don't do this, then we can blow out the local C stack.
91 */
92#define TMPL_MAX_NESTING 128
93
95extern size_t pair_list_table_len;
96
97typedef enum requests_ref_e : uint8_t {
98 REQUEST_CURRENT = 0, //!< The current request (default).
99 REQUEST_OUTER, //!< #request_t containing the outer layer of the EAP
100 //!< conversation. Usually the RADIUS request sent
101 //!< by the NAS.
102
103 REQUEST_PARENT, //!< Parent (whatever it is).
104 REQUEST_UNKNOWN //!< Unknown request.
106
108extern size_t tmpl_request_ref_table_len;
109
110/** Base data type is an attribute reference
111 *
112 */
113#define TMPL_FLAG_ATTR 0x01000000
114
115/** Base data type is an xlat expansion
116 *
117 */
118#define TMPL_FLAG_XLAT 0x02000000
119
120/** Is a type of regular expression
121 *
122 */
123#define TMPL_FLAG_REGEX 0x04000000
124
125/** Needs resolution
126 *
127 */
128#define TMPL_FLAG_UNRESOLVED 0x08000000
129
130/** Types of #tmpl_t
131 *
132 * Types may be compound types made up of multiple other types.
133 *
134 * Types which are used as part of compound types are:
135 * - XLAT_TYPE_XLAT - #tmpl_t contains xlat expansion.
136 * - XLAT_TYPE_UNRESOLVED - #tmpl_t contains unresolved elements such as xlat functions or other expansions.
137 */
138typedef enum tmpl_type_e : uint32_t {
139 /** Uninitialised
140 */
142
143 /** Value in native boxed format
144 */
146
147 /** Reference to one or more attributes
148 */
150
151 /** Pre-parsed xlat expansion
152 */
154
155 /** Callout to an external script or program
156 */
158
159 /** Compiled (and possibly JIT'd) regular expression
160 */
162
163 /** Regex where compilation is possible but hasn't been performed yet
164 */
166
167 /** A regex containing xlat expansions. Cannot be pre-compiled
168 */
170
171 /** @name unresolved types
172 *
173 * These are tmpls which could not immediately be transformed into
174 * their "resolved" form due to missing references or because
175 * additional parsing is required.
176 *
177 * @{
178 */
179
180 /** Unparsed literal string
181 *
182 * May be an intermediary phase where the tmpl is created as a
183 * temporary structure during parsing. The value here MUST be raw
184 * data, and cannot be anything else.
185 */
187
188 /** An attribute reference that we couldn't resolve but looked valid
189 *
190 * May be resolvable later once more attributes are defined.
191 */
193
194 /** An exec with unresolved xlat function or attribute references
195 */
197
198 /** A xlat expansion with unresolved xlat functions or attribute references
199 */
201
202 /** A regular expression with unresolved xlat functions or attribute references
203 */
205
206 TMPL_TYPE_MAX //!< Marker for the last tmpl type.
208
209/** Helpers to verify the type of #tmpl_t
210 */
211#define tmpl_is_uninitialised(vpt) ((vpt)->type == TMPL_TYPE_UNINITIALISED)
212
213#define tmpl_is_data(vpt) ((vpt)->type == TMPL_TYPE_DATA)
214
215#define tmpl_is_attr(vpt) ((vpt)->type == TMPL_TYPE_ATTR)
216
217#define tmpl_is_xlat(vpt) ((vpt)->type == TMPL_TYPE_XLAT)
218#define tmpl_is_exec(vpt) ((vpt)->type == TMPL_TYPE_EXEC)
219
220#define tmpl_is_regex(vpt) ((vpt)->type == TMPL_TYPE_REGEX)
221#define tmpl_is_regex_uncompiled(vpt) ((vpt)->type == TMPL_TYPE_REGEX_UNCOMPILED)
222#define tmpl_is_regex_xlat(vpt) ((vpt)->type == TMPL_TYPE_REGEX_XLAT)
223
224#define tmpl_is_data_unresolved(vpt) ((vpt)->type == TMPL_TYPE_DATA_UNRESOLVED)
225#define tmpl_is_exec_unresolved(vpt) ((vpt)->type == TMPL_TYPE_EXEC_UNRESOLVED)
226#define tmpl_is_attr_unresolved(vpt) ((vpt)->type == TMPL_TYPE_ATTR_UNRESOLVED)
227#define tmpl_is_xlat_unresolved(vpt) ((vpt)->type == TMPL_TYPE_XLAT_UNRESOLVED)
228#define tmpl_is_regex_xlat_unresolved(vpt) ((vpt)->type == TMPL_TYPE_REGEX_XLAT_UNRESOLVED)
229
230#define tmpl_needs_resolving(vpt) (((vpt)->type & TMPL_FLAG_UNRESOLVED) != 0)
231#define tmpl_contains_data(vpt) (((vpt)->type & TMPL_TYPE_DATA) != 0)
232#define tmpl_contains_attr(vpt) (((vpt)->type & TMPL_FLAG_ATTR) != 0)
233#define tmpl_contains_regex(vpt) (((vpt)->type & TMPL_FLAG_REGEX) != 0)
234#define tmpl_contains_xlat(vpt) (((vpt)->type & TMPL_FLAG_XLAT) != 0)
235
236
238extern size_t tmpl_type_table_len;
239
243typedef struct tmpl_literal_rules_s tmpl_literal_rules_t;
245typedef struct tmpl_s tmpl_t;
246
247#include <freeradius-devel/unlang/xlat.h>
248#include <freeradius-devel/unlang/xlat_ctx.h>
249#include <freeradius-devel/util/packet.h>
250#include <freeradius-devel/util/proto.h>
251#include <freeradius-devel/util/regex.h>
252
253/*
254 * Allow public and private versions of the same structures
255 */
256#ifdef _CONST
257# error _CONST can only be defined in the local header
258#endif
259#ifndef _TMPL_PRIVATE
260# define _CONST const
261#else
262# define _CONST
263#endif
264
265/** Specify whether attribute references can have a list (or parent) reference
266 *
267 */
268typedef enum : uint8_t {
269 TMPL_ATTR_LIST_ALLOW = 0, //!< Attribute refs are allowed to have a list
270 TMPL_ATTR_LIST_FORBID, //!< Attribute refs are forbidden from having a list
271 TMPL_ATTR_LIST_REQUIRE //!< Attribute refs are required to have a list.
273
274/** Define entry and head types for tmpl request references
275 *
276 */
277FR_DLIST_TYPES(tmpl_request_list)
278
280 fr_dict_t const *dict_def; //!< Default dictionary to use
281 ///< with unqualified attribute references.
282
283 fr_dict_attr_t const *namespace; //!< Point in dictionary tree to resume parsing
284 ///< from. If this is provided then dict_def
285 ///< request_def and list_def will be ignored
286 ///< and the presence of any of those qualifiers
287 ///< will be treated as an error.
288
289 FR_DLIST_HEAD(tmpl_request_list) _CONST *request_def; //!< Default request to use with
290 ///< unqualified attribute references.
291 ///< If NULL the request is assumed to
292 ///< but the current request.
293 ///< Usually this will be one of
294 ///< - tmpl_request_def_current
295 ///< - tmpl_request_def_outer
296 ///< - tmpl_request_def_parent
297 ///< If a custom list needs to be
298 ///< used it should be allocated on
299 ///< the stack and a pointer to it
300 ///< placed here.
301
302 fr_dict_attr_t const *list_def; //!< Default list to use with unqualified
303 ///< attribute reference.
304
305 tmpl_attr_list_presence_t list_presence; //!< Whether the attribute reference can
306 ///< have a list, forbid it, or require it.
307
308 CONF_ITEM *ci; //!< for migration support and various warnings
309
310 unsigned int allow_unknown : 1; //!< Allow unknown attributes i.e. attributes
311 ///< defined by OID string.
312
313 unsigned int allow_unresolved : 1; //!< Allow attributes that look valid but were
314 ///< not found in the dictionaries.
315 ///< This should be used as part of a multi-pass
316 ///< approach to parsing.
317
318 unsigned int allow_wildcard : 1; //!< Allow the special case of .[*] representing
319 ///< all children of a structural attribute.
320
321 unsigned int allow_foreign : 1; //!< Allow arguments not found in dict_def.
322
323 unsigned int allow_oid : 1; //!< allow numerical OIDs.
324
325 unsigned int disallow_filters : 1; //!< disallow filters.
326
327 unsigned int xlat : 1 ; //!< for %{User-Name}
328
329 unsigned int bare_word_enum : 1; //!< for v3 compatibility.
330
331 unsigned int disallow_rhs_resolve : 1; //!< map RHS is NOT immediately resolved in the context of the LHS.
332};
333
335 fr_event_list_t *runtime_el; //!< The eventlist to use for runtime instantiation
336 ///< of xlats.
337 bool new_functions; //!< new function syntax
338};
339
340/** Optional arguments passed to vp_tmpl functions
341 *
342 */
344 tmpl_rules_t const *parent; //!< for parent / child relationships
345
346 tmpl_attr_rules_t attr; //!< Rules/data for parsing attribute references.
347 tmpl_xlat_rules_t xlat; //!< Rules/data for parsing xlats.
348
349 fr_dict_attr_t const *enumv; //!< Enumeration attribute used to resolve enum values.
350
351 fr_type_t cast; //!< Whether there was an explicit cast.
352 ///< Used to determine if barewords or other values
353 ///< should be converted to an internal data type.
354
355 unsigned int depth; //!< to catch nested calls.
356
357 bool at_runtime; //!< Produce an ephemeral/runtime tmpl.
358 ///< Instantiated xlats are not added to the global
359 ///< trees, regexes are not JIT'd.
360 fr_value_box_safe_for_t literals_safe_for; //!< safe_for value assigned to literal values in
361 ///< xlats, execs, and data.
362 tmpl_escape_t escape; //!< How escaping should be handled during evaluation.
363};
364
365/** Copy parse rules for a nested parse, and increment the depth field.
366 *
367 * The `parent` field points at a parent with different rules. A
368 * nested parse does not the rules, so it does not change the parent.
369 *
370 * @param[out] _out rules to use for the nested parse.
371 * @param[in] _in rules of the parse which is already running.
372 */
373#define tmpl_rules_copy_depth(_out, _in) \
374do { \
375 *(_out) = *(_in); \
376 (_out)->depth++; \
377} while (0)
378
379/** Similar to tmpl_rules_t, but used to specify parameters that may change during subsequent resolution passes
380 *
381 * When a tmpl is parsed initially the rules are stored in the #tmpl_t.
382 *
383 * During subsequent resolution phases where unresolved attributes are resolved to dictionary
384 * attributes the initial #tmpl_rules_t is used to control resolution.
385 *
386 * In some instances however (primarily policies), some rules may need change between initial
387 * parsing and subsequent resolution phases.
388 *
389 * This structure holds rules which may override the tmpl_rules_s during subsequent resolution passes.
390 */
392 fr_dict_t const *dict_def; //!< Alternative default dictionary to use if
393 ///< vpt->rules->dict_def is NULL.
394 //!< Will be written to vpt->rules->dict_def
395 ///< if used.
396
397 bool force_dict_def; //!< Use supplied dict_def even if original
398 ///< vpt->rules->dict_def was not NULL.
399
400 fr_dict_attr_t const *enumv; //!< for resolving T_BARE_WORD
401};
402
403typedef enum : uint8_t {
404 TMPL_ATTR_TYPE_NORMAL = 0, //!< Normal, resolved, attribute ref.
405 TMPL_ATTR_TYPE_UNSPEC, //!< No attribute was specified as this level
406 ///< only a filter.
407 TMPL_ATTR_TYPE_UNKNOWN, //!< We have an attribute number but
408 ///< it doesn't match anything in the
409 ///< dictionary, or isn't a child of
410 ///< the previous ref. May be resolved
411 ///< later.
412 TMPL_ATTR_TYPE_UNRESOLVED //!< We have a name, but nothing else
413 ///< to identify the attribute.
414 ///< may be resolved later.
416
417#define NUM_UNSPEC INT16_MIN
418#define NUM_ALL (INT16_MIN + 1)
419#define NUM_COUNT (INT16_MIN + 2)
420#define NUM_LAST (INT16_MIN + 3)
421
422/** Define entry and head types for attribute reference lists
423 *
424 */
425FR_DLIST_TYPES(tmpl_attr_list)
426
427/** Different types of filter that can be applied to an attribute reference
428 *
429 */
430typedef enum : uint8_t {
431 TMPL_ATTR_FILTER_TYPE_NONE = 0, //!< No filter present.
432 TMPL_ATTR_FILTER_TYPE_INDEX, //!< Filter is an index type.
433 TMPL_ATTR_FILTER_TYPE_CONDITION, //!< Filter is a condition
434 TMPL_ATTR_FILTER_TYPE_TMPL, //!< Filter is a tmpl
435 TMPL_ATTR_FILTER_TYPE_EXPR, //!< Filter is an expression
437
438typedef struct {
439 tmpl_attr_filter_type_t _CONST type; //!< Type of filter this is.
440 int16_t _CONST num; //!< For array references.
441
442 /*
443 * These are "union" because they are disjoint. The "num" field is arguably disjoint, too, but
444 * there is currently a lot of code in tmpl_tokenize.c which directly references ar->ar_num
445 * without checking the type.
446 */
447 union {
448 xlat_exp_head_t _CONST *cond; //!< xlat condition
449 tmpl_t _CONST *tmpl; //!< tmpl
450 xlat_exp_head_t _CONST *expr; //!< xlat expression
451 };
453
454/** An element in a list of nested attribute references
455 *
456 */
457typedef struct {
458 FR_DLIST_ENTRY(tmpl_attr_list) _CONST entry; //!< Entry in the doubly linked list
459 ///< of attribute references.
460
461 fr_dict_attr_t const * _CONST da; //!< Resolved dictionary attribute.
462
463 union {
464 struct {
465 fr_dict_attr_t * _CONST da; //!< Unknown dictionary attribute.
466 } unknown;
467
468 struct {
469 char * _CONST name; //!< Undefined reference type.
470 fr_dict_attr_t const * _CONST namespace; //!< Namespace we should be trying
471 ///< to resolve this attribute in.
472 } unresolved;
473 };
474
475 fr_dict_attr_t const * _CONST parent; //!< The parent we used when trying to
476 ///< resolve the attribute originally.
477 ///< Should point to the referenced
478 ///< attribute.
479
480 unsigned int _CONST resolve_only : 1; //!< This reference and those before it
481 ///< in the list can only be used for
482 ///< resolution, not building out trees.
483 unsigned int _CONST is_raw : 1; /// is a raw reference
484
485 tmpl_attr_type_t _CONST type; //!< Type of attribute reference.
486
487 tmpl_attr_filter_t _CONST filter; //!< Filter associated with the attribute reference.
489
490/** Define manipulation functions for the attribute reference list
491 *
492 */
493FR_DLIST_FUNCS(tmpl_attr_list, tmpl_attr_t, entry)
494
495/** An element in a list of request references
496 *
497 */
498typedef struct {
499 FR_DLIST_ENTRY(tmpl_request_list) _CONST entry; //!< Entry in the doubly linked list
500 ///< of request references.
501
504
505/** Define manipulation functions for the attribute reference list
506 *
507 */
508FR_DLIST_FUNCS(tmpl_request_list, tmpl_request_t, entry)
509
510/** How many additional headers to allocate in a pool for a tmpl_t
511 *
512 */
513#define TMPL_POOL_DEF_HEADERS 4
514
515/** How many additional bytes to allocate in a pool for a tmpl_t
516 *
517 */
518#define TMPL_POOL_DEF_LEN (sizeof(tmpl_t) + 64 + sizeof(tmpl_attr_t) + sizeof(tmpl_request_t))
519
520/** @name Field accessors for attribute references
521 *
522 * @{
523 */
524#define ar_type type
525#define ar_depth depth
526#define ar_da da
527#define ar_parent parent
528#define ar_unknown unknown.da
529#define ar_unresolved unresolved.name
530#define ar_unresolved_namespace unresolved.namespace
531
532#define ar_is_normal(_ar) ((_ar)->ar_type == TMPL_ATTR_TYPE_NORMAL)
533#define ar_is_unspecified(_ar) ((_ar)->ar_type == TMPL_ATTR_TYPE_UNSPEC)
534#define ar_is_unknown(_ar) ((_ar)->ar_type == TMPL_ATTR_TYPE_UNKNOWN)
535#define ar_is_unresolved(_ar) ((_ar)->ar_type == TMPL_ATTR_TYPE_UNRESOLVED)
536#define ar_is_raw(_ar) ((_ar)->is_raw)
537
538#define ar_num filter.num
539#define ar_cond filter.cond
540#define ar_tmpl filter.tmpl
541#define ar_expr filter.expr
542#define ar_filter_type filter.type
543
544#define ar_filter_is_none(_ar) ((_ar)->ar_filter_type == TMPL_ATTR_FILTER_TYPE_NONE)
545#define ar_filter_is_num(_ar) ((_ar)->ar_filter_type == TMPL_ATTR_FILTER_TYPE_INDEX)
546#define ar_filter_is_cond(_ar) ((_ar)->ar_filter_type == TMPL_ATTR_FILTER_TYPE_CONDITION)
547#define ar_filter_is_tmpl(_ar) ((_ar)->ar_filter_type == TMPL_ATTR_FILTER_TYPE_TMPL)
548#define ar_filter_is_expr(_ar) ((_ar)->ar_filter_type == TMPL_ATTR_FILTER_TYPE_EXPR)
549/** @} */
550
551/** A source or sink of value data.
552 *
553 * Is used as both the RHS and LHS of a map (both update, and conditional types)
554 *
555 * @section update_maps Use in update map_t
556 * When used on the LHS it describes an attribute to create and should be one of these types:
557 * - #TMPL_TYPE_ATTR
558 *
559 * When used on the RHS it describes the value to assign to the attribute being created and
560 * should be one of these types:
561 * - #TMPL_TYPE_DATA_UNRESOLVED
562 * - #TMPL_TYPE_XLAT_UNRESOLVED
563 * - #TMPL_TYPE_ATTR
564 * - #TMPL_TYPE_EXEC
565 * - #TMPL_TYPE_DATA
566 * - #TMPL_TYPE_XLAT (pre-parsed xlat)
567 *
568 * @section conditional_maps Use in conditional map_t
569 * When used as part of a condition it may be any of the RHS side types, as well as:
570 * - #TMPL_TYPE_REGEX (pre-parsed regex)
571 *
572 * @see map_t
573 */
574struct tmpl_s {
575 tmpl_type_t _CONST type; //!< What type of value tmpl refers to.
576
577 char const * _CONST name; //!< Raw string used to create the template.
578 ///< this string will have any escape sequences left intact.
579 size_t _CONST len; //!< Length of the raw string used to create the template.
580 fr_token_t _CONST quote; //!< What type of quoting was around the raw string.
581
582 union {
583 char *unescaped; //!< Unescaped form of the name, used for TMPL_TYPE_DATA_UNRESOLVED
584 ///< and TMPL_TYPE_REGEX_UNCOMPILED.
585
586 _CONST struct {
587 FR_DLIST_HEAD(tmpl_request_list) rr; //!< Request to search or insert in.
588 FR_DLIST_HEAD(tmpl_attr_list) ar; //!< Head of the attribute reference list.
589 } attribute;
590
591 /*
592 * Attribute value. Typically used as the RHS of an update map.
593 */
594 fr_value_box_t literal; //!< Value data.
595
596 struct {
597 union {
598 _CONST struct {
599 xlat_exp_head_t *ex; //!< pre-parsed xlat expansion
600 ///< and expansion.
601 } xlat;
602#ifdef HAVE_REGEX
603 _CONST struct {
604 char *src; //!< Original unescaped source string.
605 regex_t *ex; //!< pre-parsed regex_t
606 bool subcaptures; //!< Whether the regex was compiled with
607 ///< subcaptures.
608 } reg;
609#endif
610 };
611 fr_regex_flags_t reg_flags; //!< Flags for regular expressions.
612 ///< Used by:
613 ///< - TMPL_TYPE_REGEX_XLAT
614 ///< - TMPL_TYPE_REGEX_UNCOMPILED
615 ///< - TMPL_TYPE_REGEX
616 ///< - TMPL_TYPE_REGEX_XLAT_UNRESOLVED
617 };
619
620 tmpl_rules_t _CONST rules; //!< The rules that were used when creating the tmpl.
621 ///< These are useful for multiple resolution passes as
622 ///< they ensure the correct parsing rules are applied.
623};
624
625/** Describes the current extents of a pair tree in relation to the tree described by a tmpl_t
626 *
627 */
628typedef struct {
629 fr_dlist_t entry; //!< Entry in the dlist of extents
630
631 tmpl_attr_t const *ar; //!< Attribute representing the ar
632 ///< after the deepest node that was found
633 ///< in the existing pair tree when evaluating
634 ///< this path. If this is NULL, then all ars
635 ///< were evaluated.
636
637 TALLOC_CTX *list_ctx; //!< Where to allocate new attributes if building
638 ///< out from the current extents of the tree.
639 fr_pair_list_t *list; //!< List that we tried to evaluate ar in and failed.
640 ///< Or if ar is NULL, the list that represents the
641 ///< deepest grouping or TLV attribute the chain of
642 ///< ars referenced.
644
645/** Convenience macro for printing a meaningful assert message when we get a bad tmpl type
646 */
647#define tmpl_assert_type(_cond) \
648 fr_assert_msg(_cond, "Unexpected tmpl type '%s'", \
649 tmpl_type_to_str(vpt->type))
650
651
652/** @name Functions for printing and parsing tmpl type names
653 *
654 * @{
655 */
656/** Return a static string containing the type name
657 *
658 * @param[in] type to return name for.
659 * @return name of the type
660 */
661static inline char const *tmpl_type_to_str(tmpl_type_t type)
662{
663 return fr_table_str_by_value(tmpl_type_table, type, "<INVALID>");
664}
665
666/** Return the constant value representing a type
667 *
668 * @param[in] type to return the constant value for.
669 * @return The constant type value or TMPL_TYPE_UNINITIALISED if no type matches.
670 */
671static inline tmpl_type_t tmpl_type_from_str(char const *type)
672{
674
675 return (tmpl_type_t)tmpl_type;
676}
677/** @} */
678
679/** @name Field accessors for #TMPL_TYPE_ATTR, #TMPL_TYPE_ATTR_UNRESOLVED
680 *
681 * @{
682 */
683 #define tmpl_attr(_tmpl) &(_tmpl)->data.attribute.ar
684
685static inline FR_DLIST_HEAD(tmpl_request_list) const *tmpl_request(tmpl_t const *vpt)
686{
689
690 return &vpt->data.attribute.rr;
691}
692
693/** The number of request references contained within a tmpl
694 *
695 */
696static inline size_t tmpl_request_ref_count(tmpl_t const *vpt)
697{
700
701 return tmpl_request_list_num_elements(&vpt->data.attribute.rr);
702}
703
704/** Return true if the tmpl_attr is one of the list types
705 *
706 * @hidecallergraph
707*/
708static inline bool tmpl_attr_is_list_attr(tmpl_attr_t const *ar)
709{
710 if (!ar || !ar_is_normal(ar)) return false;
711
712 return request_attr_is_list(ar->ar_da);
713}
714
715/** Return true if the head attribute reference is a list reference
716 *
717 * @hidecallergraph
718 */
719static inline bool tmpl_attr_head_is_list(tmpl_t const *vpt)
720{
721 tmpl_attr_t *ar;
722
724
725 ar = tmpl_attr_list_head(tmpl_attr(vpt));
726 if (unlikely(!ar)) return false;
727
728 return tmpl_attr_is_list_attr(ar);
729}
730
731/** Return true if the last attribute reference is "normal"
732 *
733 * @hidecallergraph
734 */
735static inline bool tmpl_attr_tail_is_normal(tmpl_t const *vpt)
736{
737 tmpl_attr_t *ar;
738
740
741 ar = tmpl_attr_list_tail(tmpl_attr(vpt));
742 if (unlikely(!ar)) return false;
743
744 return ar_is_normal(ar);
745}
746
747/** Return true if the last attribute reference is "unspecified"
748 *
749 * @hidecallergraph
750 */
751static inline bool tmpl_attr_tail_is_unspecified(tmpl_t const *vpt)
752{
753 tmpl_attr_t *ar;
754
756
757 ar = tmpl_attr_list_tail(tmpl_attr(vpt));
758 if (unlikely(!ar)) return false;
759
760 return ar_is_unspecified(ar);
761}
762
763/** Return true if the last attribute reference is "unknown"
764 *
765 * @hidecallergraph
766 */
767static inline bool tmpl_attr_tail_is_unknown(tmpl_t const *vpt)
768{
769 tmpl_attr_t *ar;
770
772
773 ar = tmpl_attr_list_tail(tmpl_attr(vpt));
774 if (unlikely(!ar)) return false;
775
776 return ar_is_unknown(ar);
777}
778
779/** Return true if the last attribute reference is "unresolved"
780 *
781 * @hidecallergraph
782 */
783static inline bool tmpl_attr_tail_is_unresolved(tmpl_t const *vpt)
784{
785 tmpl_attr_t *ar;
786
788
789 ar = tmpl_attr_list_tail(tmpl_attr(vpt));
790 if (unlikely(!ar)) return false;
791
792 return ar_is_unresolved(ar);
793}
794
795/** Return true if the last attribute reference is "raw"
796 *
797 * @hidecallergraph
798 */
799static inline bool tmpl_attr_tail_is_raw(tmpl_t const *vpt)
800{
801 tmpl_attr_t *ar;
802
804
805 ar = tmpl_attr_list_tail(tmpl_attr(vpt));
806 if (unlikely(!ar)) return false;
807
808 return ar_is_raw(ar);
809}
810
811/** Return the last attribute reference
812 *
813 * @hidecallergraph
814 */
815static inline tmpl_attr_t const *tmpl_attr_tail(tmpl_t const *vpt)
816{
818
819 return tmpl_attr_list_tail(tmpl_attr(vpt));
820}
821
822/** Return the last attribute reference da
823 *
824 * @hidecallergraph
825 */
826static inline fr_dict_attr_t const *tmpl_attr_tail_da(tmpl_t const *vpt)
827{
828 tmpl_attr_t *ar;
829
831
832 ar = tmpl_attr_list_tail(tmpl_attr(vpt));
833 if (!ar) return NULL;
834
835 return ar->ar_da;
836}
837
838/** Return true if the last attribute reference is a leaf attribute
839 *
840 * @hidecallergraph
841 */
842static inline bool tmpl_attr_tail_da_is_leaf(tmpl_t const *vpt)
843{
844 tmpl_attr_t *ar;
845
847
848 ar = tmpl_attr_list_tail(tmpl_attr(vpt));
849 if (!ar) return false;
850
852
853 return fr_type_is_leaf(ar->ar_da->type);
854}
855
856/** Return true if the last attribute reference is a structural attribute
857 *
858 * @hidecallergraph
859 */
861{
862 tmpl_attr_t *ar;
863
865
866 ar = tmpl_attr_list_tail(tmpl_attr(vpt));
867 if (!ar) return false;
868
870
871 return fr_type_is_structural(ar->ar_da->type);
872}
873
874/** Return the last attribute reference unknown da
875 *
876 * @hidecallergraph
877 */
879{
880 tmpl_attr_t *ar;
881
883
884 ar = tmpl_attr_list_tail(tmpl_attr(vpt));
885 if (!ar) return NULL;
886
887 return ar->ar_unknown;
888}
889
890/** Return the last attribute reference unresolved da
891 *
892 * @hidecallergraph
893 */
894static inline char const *tmpl_attr_tail_unresolved(tmpl_t const *vpt)
895{
896 tmpl_attr_t *ar;
897
899
900 ar = tmpl_attr_list_tail(tmpl_attr(vpt));
901 if (!ar) return NULL;
902
903 return ar->ar_unresolved;
904}
905
906/** Return the last attribute reference's attribute number
907 *
908 * @hidecallergraph
909 */
910static inline int16_t tmpl_attr_tail_num(tmpl_t const *vpt)
911{
914
915 return tmpl_attr_list_tail(tmpl_attr(vpt))->ar_num;
916}
917
918/** The number of attribute references contained within a tmpl
919 *
920 */
921static inline size_t tmpl_attr_num_elements(tmpl_t const *vpt)
922{
925
926 return tmpl_attr_list_num_elements(tmpl_attr(vpt));
927}
928
929static inline fr_dict_attr_t const *tmpl_list(tmpl_t const *vpt)
930{
931 if (!tmpl_attr_head_is_list(vpt)) return NULL;
932
933 return tmpl_attr_list_head(tmpl_attr(vpt))->ar_da;
934}
935/** @} */
936
937/** Return the name of a tmpl list or def if list not provided
938 *
939*/
940static inline char const *tmpl_list_name(fr_dict_attr_t const *list, char const *def)
941{
942 return (list ? list->name : def);
943}
944
945static inline bool tmpl_is_list(tmpl_t const *vpt)
946{
947 if (!tmpl_is_attr(vpt)) return false;
949}
950
951/** @name Field accessors for #TMPL_TYPE_XLAT
952 *
953 * @{
954 */
955#define tmpl_xlat(_tmpl) (_tmpl)->data.xlat.ex
956/** @} */
957
958/** @name Field accessors for #TMPL_TYPE_DATA
959 *
960 * @{
961 */
962#define tmpl_value(_tmpl) (&(_tmpl)->data.literal)
963#define tmpl_value_length(_tmpl) (_tmpl)->data.literal.vb_length
964#define tmpl_value_type(_tmpl) (_tmpl)->data.literal.type
965#define tmpl_value_enumv(_tmpl) (_tmpl)->data.literal.enumv
966
967#define tmpl_rules_cast(_tmpl) (_tmpl)->rules.cast
968#define tmpl_rules_enumv(_tmpl) (_tmpl)->rules.enumv
969
970fr_type_t tmpl_data_type(tmpl_t const *vpt) CC_HINT(nonnull);
971
972/** @} */
973
974/** @name Field accessors for #TMPL_TYPE_REGEX and #TMPL_TYPE_REGEX_XLAT_UNRESOLVED
975 *
976 * @{
977 */
978#ifdef HAVE_REGEX
979# define tmpl_regex(_tmpl) (_tmpl)->data.reg.ex //!< #TMPL_TYPE_REGEX only.
980# define tmpl_regex_flags(_tmpl) (&(_tmpl)->data.reg_flags)
981#endif
982/** @} */
983
984#ifndef WITH_VERIFY_PTR
985# define TMPL_ATTR_VERIFY(_vpt)
986# define TMPL_VERIFY(_vpt)
987#else
988# define TMPL_ATTR_VERIFY(_vpt) tmpl_attr_verify(__FILE__, __LINE__, _vpt)
989# define TMPL_VERIFY(_vpt) tmpl_verify(__FILE__, __LINE__, _vpt)
990void tmpl_attr_verify(char const *file, int line, tmpl_t const *vpt);
991void tmpl_verify(char const *file, int line, tmpl_t const *vpt);
992#endif
993
994/** Determine the correct context and list head
995 *
996 * Used in conjunction with the fr_dcursor functions to determine the correct list
997 * and TALLOC_CTX for inserting fr_pair_ts.
998 *
999 * Example:
1000 @code{.c}
1001 TALLOC_CTX *ctx;
1002 fr_pair_list_t *head;
1003 fr_value_box_t value;
1004
1005 tmpl_pair_list_and_ctx(ctx, head, request, CURRENT_REQUEST, request_attr_request);
1006 if (!list) return -1; // error
1007
1008 value.strvalue = talloc_strdup(NULL, "my new username");
1009 value.length = talloc_strlen(value.strvalue);
1010 @endcode
1011 *
1012 * @param _ctx new #fr_pair_t s should be allocated in for the specified list.
1013 * @param _head of the #fr_pair_t list.
1014 * @param _request The current request.
1015 * @param _ref to resolve.
1016 * @param _list to resolve.
1017 */
1018#define tmpl_pair_list_and_ctx(_ctx, _head, _request, _ref, _list) \
1019do {\
1020 request_t *_rctx = _request; \
1021 if ((tmpl_request_ptr(&_rctx, _ref) < 0) || \
1022 !(_head = tmpl_list_head(_rctx, _list)) || \
1023 !(_ctx = tmpl_list_ctx(_rctx, _list))) {\
1024 _ctx = NULL; \
1025 _head = NULL; \
1026 }\
1027} while (0)
1028
1029typedef enum : uint8_t {
1030 TMPL_ATTR_ERROR_NONE = 0, //!< No error.
1031 TMPL_ATTR_ERROR_EMPTY, //!< Attribute ref contains no data.
1032 TMPL_ATTR_ERROR_BAD_PREFIX, //!< Missing '&' or has '&' when it shouldn't.
1033 TMPL_ATTR_ERROR_LIST_NOT_ALLOWED, //!< List qualifier is not allowed here.
1034 TMPL_ATTR_ERROR_LIST_MISSING, //!< List qualifier is required, but missing.
1035 TMPL_ATTR_ERROR_UNKNOWN_NOT_ALLOWED, //!< Attribute specified as OID, could not be
1036 ///< found in the dictionaries, and is disallowed
1037 ///< because 'allow_unknown' in tmpl_rules_t
1038 ///< is false.
1039 TMPL_ATTR_ERROR_UNRESOLVED_NOT_ALLOWED, //!< Attribute couldn't be found in the dictionaries.
1040 TMPL_ATTR_ERROR_UNQUALIFIED_NOT_ALLOWED, //!< Attribute must be qualified to be used here.
1041 TMPL_ATTR_ERROR_INVALID_NAME, //!< Attribute ref length is zero, or longer than
1042 ///< the maximum.
1043 TMPL_ATTR_ERROR_INTERNAL_NOT_ALLOWED, //!< Attribute resolved to an internal attribute
1044 ///< which is disallowed.
1045 TMPL_ATTR_ERROR_FOREIGN_NOT_ALLOWED, //!< Attribute resolved in a dictionary different
1046 ///< to the one specified.
1047 TMPL_ATTR_ERROR_FILTER_NOT_ALLOWED, //!< Filters disallowed by rules.
1048 TMPL_ATTR_ERROR_INVALID_ARRAY_INDEX, //!< Invalid array index.
1050 TMPL_ATTR_ERROR_NESTING_TOO_DEEP, //!< Too many levels of nesting.
1051 TMPL_ATTR_ERROR_INVALID_REQUEST_REF, //!< invalid request reference
1052 TMPL_ATTR_ERROR_MISSING_TERMINATOR, //!< Unexpected text found after attribute reference
1053 TMPL_ATTR_ERROR_BAD_CAST, //!< Specified cast was invalid.
1054 TMPL_ATTR_ERROR_INVALID_OID //!< OIDs are not allowed
1056
1057/** Map ptr type to a boxed type
1058 *
1059 */
1060#define FR_TYPE_FROM_PTR(_ptr) \
1061 _Generic((_ptr), \
1062 char **: FR_TYPE_STRING, \
1063 char const **: FR_TYPE_STRING, \
1064 uint8_t **: FR_TYPE_OCTETS, \
1065 uint8_t const **: FR_TYPE_OCTETS, \
1066 uint8_t *: FR_TYPE_UINT8, \
1067 uint16_t *: FR_TYPE_UINT16, \
1068 uint32_t *: FR_TYPE_UINT32, \
1069 uint64_t *: FR_TYPE_UINT64, \
1070 fr_value_box_t **: FR_TYPE_VALUE_BOX, \
1071 fr_value_box_t const **: FR_TYPE_VALUE_BOX)
1072
1073/** Expand a tmpl to a C type, using existing storage to hold variably sized types
1074 *
1075 * Expands a template using the _out ptr to determinate the cast type.
1076 *
1077 * @see _tmpl_to_type
1078 */
1079#define tmpl_expand(_out, _buff, _buff_len, _request, _vpt) \
1080 _tmpl_to_type((void *)(_out), (uint8_t *)_buff, _buff_len, \
1081 _request, _vpt, FR_TYPE_FROM_PTR(_out))
1082
1083/** Expand a tmpl to a C type, allocing a new buffer to hold the string
1084 *
1085 * Expands a template using the _out ptr to determinate the cast type.
1086 *
1087 * @see _tmpl_to_atype
1088 */
1089#define tmpl_aexpand(_ctx, _out, _request, _vpt, _escape, _escape_ctx) \
1090 _tmpl_to_atype(_ctx, (void *)(_out), _request, _vpt, _escape, _escape_ctx, FR_TYPE_FROM_PTR(_out))
1091
1092/** Expand a tmpl to a C type, allocing a new buffer to hold the string
1093 *
1094 * Takes an explicit type which must match the ctype pointed to by out.
1095 *
1096 * @see _tmpl_to_atype
1097 */
1098#define tmpl_aexpand_type(_ctx, _out, _type, _request, _vpt) \
1099 _tmpl_to_atype(_ctx, (void *)(_out), _request, _vpt, NULL, NULL, _type)
1100
1101void tmpl_debug(FILE *fp, tmpl_t const *vpt) CC_HINT(nonnull);
1102
1104
1106
1107TALLOC_CTX *tmpl_list_ctx(request_t *request, fr_dict_attr_t const *list);
1108
1110
1111tmpl_t *tmpl_init_printf(tmpl_t *vpt, tmpl_type_t type, fr_token_t quote, char const *fmt, ...) CC_HINT(nonnull(1,4)) CC_HINT(format (printf, 4, 5));
1112
1114 char const *name, ssize_t len,
1115 tmpl_rules_t const *t_rules) CC_HINT(nonnull(1,4));
1116
1118 char const *name, ssize_t len,
1119 tmpl_rules_t const *t_rules) CC_HINT(nonnull(1,4));
1120
1121tmpl_t *tmpl_alloc(TALLOC_CTX *ctx, tmpl_type_t type, fr_token_t quote, char const *name, ssize_t len);
1122
1123/** @name Parse request qualifiers
1124 *
1125 * @{
1126 */
1127/** Static default request ref list for the current request
1128 *
1129 * Passed as request_def in tmpl_attr_rules_t.
1130 */
1131extern FR_DLIST_HEAD(tmpl_request_list) tmpl_request_def_current;
1132
1133/** Static default request ref list for the outer request
1134 *
1135 * Passed as request_def in tmpl_attr_rules_t.
1136 */
1137extern FR_DLIST_HEAD(tmpl_request_list) tmpl_request_def_outer;
1138
1139/** Static default request ref list for the parent request
1140 *
1141 * Passed as request_def in tmpl_attr_rules_t.
1142 */
1143extern FR_DLIST_HEAD(tmpl_request_list) tmpl_request_def_parent;
1144
1145int tmpl_request_ptr(request_t **request, FR_DLIST_HEAD(tmpl_request_list) const *rql) CC_HINT(nonnull);
1146
1147void tmpl_request_ref_list_debug(FR_DLIST_HEAD(tmpl_request_list) const *rql);
1148
1149fr_cmp_ret_t tmpl_request_ref_list_cmp(FR_DLIST_HEAD(tmpl_request_list) const *a,
1150 FR_DLIST_HEAD(tmpl_request_list) const *b);
1151
1152/** Returns true if the specified qualifier list points to the current request
1153 *
1154 * @param[in] _list to check.
1155 * @return
1156 * - true if the list only contains a current request qualifier.
1157 * - false otherwise.
1158 */
1159#define tmpl_request_ref_is_current(_list) (tmpl_request_ref_list_cmp(_list, &tmpl_request_def_current) == 0)
1160
1161/** Returns true if the specified qualifier list points to the parent request
1162 *
1163 * @param[in] _list to check.
1164 * @return
1165 * - true if the list only contains a parent request qualifier.
1166 * - false otherwise.
1167 */
1168#define tmpl_request_ref_is_parent(_list) (tmpl_request_ref_list_cmp(_list, &tmpl_request_def_parent) == 0)
1169
1170/** Returns true if the specified qualifier list points to the outer request
1171 *
1172 * @param[in] _list to check.
1173 * @return
1174 * - true if the list only contains a outer request qualifier.
1175 * - false otherwise.
1176 */
1177#define tmpl_request_ref_is_outer(_list) (tmpl_request_ref_list_cmp(_list, &tmpl_request_def_outer) == 0)
1178
1179
1181 FR_DLIST_HEAD(tmpl_request_list) _CONST **out,
1182 fr_sbuff_t *in);
1183/** @} */
1184
1185void tmpl_set_name_printf(tmpl_t *vpt, fr_token_t quote, char const *fmt, ...) CC_HINT(nonnull(1,3)) CC_HINT(format(printf, 3, 4));
1186
1187void tmpl_set_name_shallow(tmpl_t *vpt, fr_token_t quote, char const *name, ssize_t len) CC_HINT(nonnull);
1188
1189void tmpl_set_name(tmpl_t *vpt, fr_token_t quote, char const *name, ssize_t len) CC_HINT(nonnull);
1190
1191void tmpl_set_dict_def(tmpl_t *vpt, fr_dict_t const *dict) CC_HINT(nonnull);
1192
1193void tmpl_set_escape(tmpl_t *vpt, tmpl_escape_t const *escape) CC_HINT(nonnull);
1194
1195void tmpl_set_xlat(tmpl_t *vpt, xlat_exp_head_t *xlat) CC_HINT(nonnull);
1196
1197int tmpl_afrom_value_box(TALLOC_CTX *ctx, tmpl_t **out, fr_value_box_t *data, bool steal) CC_HINT(nonnull);
1198
1199void tmpl_attr_ref_debug(FILE *fp, const tmpl_attr_t *ar, unsigned int idx) CC_HINT(nonnull);
1200
1201void tmpl_attr_ref_list_debug(FILE *fp, FR_DLIST_HEAD(tmpl_attr_list) const *ar_head) CC_HINT(nonnull);
1202
1203void tmpl_attr_debug(FILE *fp, tmpl_t const *vpt) CC_HINT(nonnull);
1204
1205int tmpl_attr_copy(tmpl_t *dst, tmpl_t const *src) CC_HINT(nonnull);
1206
1207int tmpl_attr_rebase(tmpl_t *vpt, tmpl_t const *parent) CC_HINT(nonnull);
1208//int tmpl_attr_rebase(tmpl_t *dst, tmpl_t const *src) CC_HINT(nonnull);
1209
1210int tmpl_attr_set_da(tmpl_t *vpt, fr_dict_attr_t const *da) CC_HINT(nonnull);
1211
1212int tmpl_attr_set_leaf_da(tmpl_t *vpt, fr_dict_attr_t const *da) CC_HINT(nonnull);
1213
1214void tmpl_attr_rewrite_leaf_num(tmpl_t *vpt, int16_t num) CC_HINT(nonnull);
1215
1216void tmpl_attr_set_list(tmpl_t *vpt, fr_dict_attr_t const *list) CC_HINT(nonnull);
1217
1218int tmpl_attr_afrom_list(TALLOC_CTX *ctx, tmpl_t **out, tmpl_t const *list,
1219 fr_dict_attr_t const *da) CC_HINT(nonnull);
1220
1221/** @name Produce a #tmpl_t from a string or substring
1222 *
1223 * @{
1224 */
1227 fr_sbuff_parse_rules_t const *p_rules,
1228 tmpl_rules_t const *t_rules) CC_HINT(nonnull(3,4));
1229
1230fr_slen_t tmpl_afrom_attr_str(TALLOC_CTX *ctx, tmpl_attr_error_t *err,
1231 tmpl_t **out, char const *name,
1232 tmpl_rules_t const *rules) CC_HINT(nonnull (3, 4));
1233
1234ssize_t tmpl_afrom_substr(TALLOC_CTX *ctx, tmpl_t **out,
1235 fr_sbuff_t *in,
1236 fr_token_t quote,
1237 fr_sbuff_parse_rules_t const *p_rules,
1238 tmpl_rules_t const *t_rules) CC_HINT(nonnull(2,3));
1239
1241 fr_token_t quote,
1242 tmpl_rules_t const *t_rules, bool allow_enum,
1243 fr_sbuff_parse_rules_t const *p_rules) CC_HINT(nonnull(2,3,5));
1244
1245tmpl_t *tmpl_copy(TALLOC_CTX *ctx, tmpl_t const *in) CC_HINT(nonnull);
1246
1247ssize_t tmpl_cast_from_substr(tmpl_rules_t *t_rules, fr_sbuff_t *in) CC_HINT(nonnull(2)); /* Parses cast string */
1248
1249int tmpl_cast_set(tmpl_t *vpt, fr_type_t type) CC_HINT(nonnull); /* Sets cast type */
1250
1252{
1253 return vpt->rules.cast;
1254}
1255
1256#ifdef HAVE_REGEX
1257ssize_t tmpl_regex_flags_substr(tmpl_t *vpt, fr_sbuff_t *in,
1258 fr_sbuff_term_t const *terminals) CC_HINT(nonnull(1,2));
1259#endif
1260/** @} */
1261
1262/** @name Change a #tmpl_t type, usually by casting or resolving a reference
1263 * @{
1264 */
1265int tmpl_cast_in_place(tmpl_t *vpt, fr_type_t type, fr_dict_attr_t const *enumv) CC_HINT(nonnull(1));
1266
1267int tmpl_resolve(tmpl_t *vpt, tmpl_res_rules_t const *tr_rules) CC_HINT(nonnull(1));
1268
1269void tmpl_unresolve(tmpl_t *vpt) CC_HINT(nonnull);
1270
1272
1274 fr_type_t type, fr_dict_attr_flags_t const *flags) CC_HINT(nonnull(1));
1275
1276#ifdef HAVE_REGEX
1277ssize_t tmpl_regex_compile(tmpl_t *vpt, bool subcaptures) CC_HINT(nonnull);
1278#endif
1279/** @} */
1280
1281/** @name Print the contents of a #tmpl_t
1282 * @{
1283 */
1284fr_slen_t tmpl_request_ref_list_print(fr_sbuff_t *out, FR_DLIST_HEAD(tmpl_request_list) const *rql)
1285 CC_HINT(nonnull(1,2));
1286
1287static inline fr_slen_t tmpl_request_ref_list_aprint(TALLOC_CTX *ctx, char **out, FR_DLIST_HEAD(tmpl_request_list) const *rql)
1289
1291
1292static inline fr_slen_t tmpl_attr_aprint(TALLOC_CTX *ctx, char **out, tmpl_t const *vpt)
1294
1296 fr_sbuff_escape_rules_t const *e_rules) CC_HINT(nonnull(1,2));
1297
1298static inline fr_slen_t tmpl_aprint(TALLOC_CTX *ctx, char **out, tmpl_t const *vpt,
1299 fr_sbuff_escape_rules_t const *e_rules)
1301
1303
1304static inline fr_slen_t tmpl_aprint_quoted(TALLOC_CTX *ctx, char **out, tmpl_t const *vpt)
1306/** @} */
1307
1308/** @name Expand the tmpl, returning one or more values
1309 * @{
1310 */
1312
1314 uint8_t *buff, size_t outlen,
1316 tmpl_t const *vpt,
1317 fr_type_t dst_type)
1318 CC_HINT(nonnull (1, 4, 5));
1319
1320ssize_t _tmpl_to_atype(TALLOC_CTX *ctx, void *out,
1322 tmpl_t const *vpt,
1323 xlat_escape_legacy_t escape, void const *escape_ctx,
1324 fr_type_t dst_type)
1325 CC_HINT(nonnull (2, 3, 4));
1326
1327int tmpl_copy_pairs(TALLOC_CTX *ctx, fr_pair_list_t *out,
1328 request_t *request, tmpl_t const *vpt) CC_HINT(nonnull(2,3,4));
1329
1330int tmpl_copy_pair_children(TALLOC_CTX *ctx, fr_pair_list_t *out,
1331 request_t *request, tmpl_t const *vpt) CC_HINT(nonnull(2,3,4));
1332
1333int tmpl_find_vp(fr_pair_t **out, request_t *request, tmpl_t const *vpt) CC_HINT(nonnull(2,3));
1334
1336
1337int pair_append_by_tmpl_parent(TALLOC_CTX *ctx, fr_pair_t **out, fr_pair_list_t *list,
1338 tmpl_t const *vpt, bool skip_list) CC_HINT(nonnull(1,3,4));
1339
1340int tmpl_extents_find(TALLOC_CTX *ctx,
1341 fr_dlist_head_t *leaf, fr_dlist_head_t *interior,
1342 request_t *request, tmpl_t const *vpt) CC_HINT(nonnull(5));
1343
1345 tmpl_t const *vpt) CC_HINT(nonnull);
1346
1347void tmpl_extents_debug(FILE *fp, fr_dlist_head_t *head) CC_HINT(nonnull);
1348
1349int tmpl_eval_pair(TALLOC_CTX *ctx, fr_value_box_list_t *out, request_t *request, tmpl_t const *vpt);
1350
1351int tmpl_eval(TALLOC_CTX *ctx, fr_value_box_list_t *out, request_t *request, tmpl_t const *vpt);
1352
1353int tmpl_eval_cast_in_place(fr_value_box_list_t *out, request_t *request, tmpl_t const *vpt);
1354/** @} */
1355
1356ssize_t tmpl_preparse(char const **out, size_t *outlen, char const *in, size_t inlen,
1357 fr_token_t *type) CC_HINT(nonnull(1,2,3,5));
1358
1359bool tmpl_async_required(tmpl_t const *vpt) CC_HINT(nonnull);
1360
1361int tmpl_value_list_insert_tail(fr_value_box_list_t *list, fr_value_box_t *vb, tmpl_t const *vpt) CC_HINT(nonnull);
1362
1363void tmpl_rules_child_init(TALLOC_CTX *ctx, tmpl_rules_t *out, tmpl_rules_t const *parent, tmpl_t *vpt) CC_HINT(nonnull);
1364
1365void tmpl_rules_debug(tmpl_rules_t const *rules) CC_HINT(nonnull);
1366
1367bool tmpl_rules_depth_exceeded(tmpl_rules_t const *t_rules) CC_HINT(nonnull);
1368
1369int tmpl_global_init(void);
1370
1371#undef _CONST
1372
1373#ifdef __cplusplus
1374}
1375#endif
static int const char * fmt
Definition acutest.h:638
void int line
Definition acutest.h:810
static uint8_t request[4]
#define RCSIDH(h, id)
Definition build.h:604
#define unlikely(_x)
Definition build.h:486
fr_cmp_ret_t
Result of an ordering comparison.
Definition build.h:113
Common header for all CONF_* types.
Definition cf_priv.h:54
Values of the encryption flags.
#define FR_DLIST_TYPES(_name)
Define type specific wrapper structs for dlists.
Definition dlist.h:1150
#define FR_DLIST_FUNCS(_name, _element_type, _element_entry)
Define type specific wrapper functions for dlists.
Definition dlist.h:1173
#define FR_DLIST_HEAD(_name)
Expands to the type name used for the head wrapper structure.
Definition dlist.h:1143
Head of a doubly linked list.
Definition dlist.h:51
Entry in a doubly linked list.
Definition dlist.h:41
static tmpl_res_rules_t tr_rules
Definition fuzzer_tmpl.c:53
Stores all information relating to an event list.
Definition event.c:375
size_t(* xlat_escape_legacy_t)(request_t *request, char *out, size_t outlen, char const *in, void *arg)
fr_type_t
unsigned int uint32_t
long int ssize_t
unsigned char uint8_t
ssize_t fr_slen_t
#define fr_assert(_expr)
Definition rad_assert.h:37
static bool request_attr_is_list(fr_dict_attr_t const *da)
Definition request.h:363
static char const * name
#define SBUFF_OUT_TALLOC_FUNC_NO_LEN_DEF(_func,...)
Set of terminal elements.
int tmpl_find_vp(fr_pair_t **out, request_t *request, tmpl_t const *vpt))
Returns the first VP matching a tmpl_t.
Definition tmpl_eval.c:777
void tmpl_request_ref_list_debug(FR_DLIST_HEAD(tmpl_request_list) const *rql)
Dump a request list to stderr.
static tmpl_attr_t const * tmpl_attr_tail(tmpl_t const *vpt)
Return the last attribute reference.
Definition tmpl.h:815
static int16_t tmpl_attr_tail_num(tmpl_t const *vpt)
Return the last attribute reference's attribute number.
Definition tmpl.h:910
void tmpl_attr_set_list(tmpl_t *vpt, fr_dict_attr_t const *list)
#define ar_is_unspecified(_ar)
Definition tmpl.h:533
static char const * tmpl_type_to_str(tmpl_type_t type)
Return a static string containing the type name.
Definition tmpl.h:661
void tmpl_unresolve(tmpl_t *vpt)
Reset the tmpl, leaving only the name in place.
#define tmpl_is_attr_unresolved(vpt)
Definition tmpl.h:226
enum requests_ref_e tmpl_request_ref_t
void tmpl_set_name_printf(tmpl_t *vpt, fr_token_t quote, char const *fmt,...))
Set the name on a pre-initialised tmpl.
static bool tmpl_attr_tail_is_unspecified(tmpl_t const *vpt)
Return true if the last attribute reference is "unspecified".
Definition tmpl.h:751
void tmpl_set_xlat(tmpl_t *vpt, xlat_exp_head_t *xlat)
Change the default dictionary in the tmpl's resolution rules.
int tmpl_attr_set_da(tmpl_t *vpt, fr_dict_attr_t const *da)
Replace the current attribute reference.
fr_packet_t * tmpl_packet_ptr(request_t *request, fr_dict_attr_t const *list)
Resolve a list to the fr_packet_t holding the HEAD pointer for a fr_pair_t list.
Definition tmpl_eval.c:140
unsigned int depth
to catch nested calls.
Definition tmpl.h:355
tmpl_escape_t escape
How escaping should be handled during evaluation.
Definition tmpl.h:362
static bool tmpl_attr_tail_is_normal(tmpl_t const *vpt)
Return true if the last attribute reference is "normal".
Definition tmpl.h:735
fr_slen_t tmpl_afrom_value_substr(TALLOC_CTX *ctx, tmpl_t **out, fr_sbuff_t *in, fr_token_t quote, tmpl_rules_t const *t_rules, bool allow_enum, fr_sbuff_parse_rules_t const *p_rules))
Create TMPL_TYPE_DATA from a string.
tmpl_t * tmpl_init(tmpl_t *vpt, tmpl_type_t type, fr_token_t quote, char const *name, ssize_t len, tmpl_rules_t const *t_rules))
Initialise a tmpl using a literal string to create the name.
int tmpl_resolve(tmpl_t *vpt, tmpl_res_rules_t const *tr_rules))
Attempt to resolve functions and attributes in xlats and attribute references.
static fr_slen_t tmpl_aprint_quoted(TALLOC_CTX *ctx, char **out, tmpl_t const *vpt) 1(tmpl_print_quoted
TALLOC_CTX * list_ctx
Where to allocate new attributes if building out from the current extents of the tree.
Definition tmpl.h:637
fr_cmp_ret_t tmpl_request_ref_list_cmp(FR_DLIST_HEAD(tmpl_request_list) const *a, FR_DLIST_HEAD(tmpl_request_list) const *b)
Compare a list of request qualifiers.
fr_table_num_sorted_t const tmpl_request_ref_table[]
Map keywords to tmpl_request_ref_t values.
#define TMPL_FLAG_ATTR
Base data type is an attribute reference.
Definition tmpl.h:113
void tmpl_attr_debug(FILE *fp, tmpl_t const *vpt)
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.
#define ar_is_unknown(_ar)
Definition tmpl.h:534
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:767
int tmpl_extents_build_to_leaf_parent(fr_dlist_head_t *leaf, fr_dlist_head_t *interior, tmpl_t const *vpt)
Allocate interior pairs.
static tmpl_type_t tmpl_type_from_str(char const *type)
Return the constant value representing a type.
Definition tmpl.h:671
fr_value_box_safe_for_t literals_safe_for
safe_for value assigned to literal values in xlats, execs, and data.
Definition tmpl.h:360
void tmpl_set_escape(tmpl_t *vpt, tmpl_escape_t const *escape)
Set escape parameters for the tmpl output.
void tmpl_attr_ref_debug(FILE *fp, const tmpl_attr_t *ar, unsigned int idx)
#define TMPL_FLAG_UNRESOLVED
Needs resolution.
Definition tmpl.h:128
#define ar_is_raw(_ar)
Definition tmpl.h:536
size_t pair_list_table_len
#define tmpl_is_attr(vpt)
Definition tmpl.h:215
bool tmpl_async_required(tmpl_t const *vpt)
Return whether or not async is required for this tmpl.
fr_dict_attr_t const * enumv
Enumeration attribute used to resolve enum values.
Definition tmpl.h:349
tmpl_rules_t const * parent
for parent / child relationships
Definition tmpl.h:344
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.
static fr_slen_t tmpl_aprint(TALLOC_CTX *ctx, char **out, tmpl_t const *vpt, fr_sbuff_escape_rules_t const *e_rules) 1(tmpl_print
static fr_dict_attr_t const * tmpl_list(tmpl_t const *vpt)
Definition tmpl.h:929
int16_t _CONST num
For array references.
Definition tmpl.h:440
tmpl_attr_list_presence_t
Specify whether attribute references can have a list (or parent) reference.
Definition tmpl.h:268
@ TMPL_ATTR_LIST_REQUIRE
Attribute refs are required to have a list.
Definition tmpl.h:271
@ TMPL_ATTR_LIST_ALLOW
Attribute refs are allowed to have a list.
Definition tmpl.h:269
@ TMPL_ATTR_LIST_FORBID
Attribute refs are forbidden from having a list.
Definition tmpl.h:270
static bool tmpl_attr_is_list_attr(tmpl_attr_t const *ar)
Return true if the tmpl_attr is one of the list types.
Definition tmpl.h:708
void tmpl_attr_ref_list_debug(FILE *fp, FR_DLIST_HEAD(tmpl_attr_list) const *ar_head)
tmpl_attr_filter_type_t
Define entry and head types for attribute reference lists.
Definition tmpl.h:430
@ TMPL_ATTR_FILTER_TYPE_TMPL
Filter is a tmpl.
Definition tmpl.h:434
@ TMPL_ATTR_FILTER_TYPE_INDEX
Filter is an index type.
Definition tmpl.h:432
@ TMPL_ATTR_FILTER_TYPE_CONDITION
Filter is a condition.
Definition tmpl.h:433
@ TMPL_ATTR_FILTER_TYPE_NONE
No filter present.
Definition tmpl.h:431
@ TMPL_ATTR_FILTER_TYPE_EXPR
Filter is an expression.
Definition tmpl.h:435
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.
static fr_slen_t tmpl_request_ref_list_aprint(TALLOC_CTX *ctx, char **out, FR_DLIST_HEAD(tmpl_request_list) const *rql) 1(tmpl_request_ref_list_print
static fr_slen_t vpt ssize_t tmpl_print(fr_sbuff_t *out, tmpl_t const *vpt, fr_sbuff_escape_rules_t const *e_rules))
Print a tmpl_t to a string.
int tmpl_eval_cast_in_place(fr_value_box_list_t *out, request_t *request, tmpl_t const *vpt)
Casts a value or list of values according to the tmpl.
Definition tmpl_eval.c:1235
void tmpl_set_name(tmpl_t *vpt, fr_token_t quote, char const *name, ssize_t len)
Set the name on a pre-initialised tmpl.
int tmpl_attr_afrom_list(TALLOC_CTX *ctx, tmpl_t **out, tmpl_t const *list, fr_dict_attr_t const *da)
Create a new tmpl from a list tmpl and a da.
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:842
#define tmpl_assert_type(_cond)
Convenience macro for printing a meaningful assert message when we get a bad tmpl type.
Definition tmpl.h:647
#define tmpl_contains_attr(vpt)
Definition tmpl.h:232
int tmpl_eval(TALLOC_CTX *ctx, fr_value_box_list_t *out, request_t *request, tmpl_t const *vpt)
Gets the value of a tmpl.
Definition tmpl_eval.c:1104
tmpl_t * tmpl_copy(TALLOC_CTX *ctx, tmpl_t const *in)
Copy a tmpl.
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:860
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
ssize_t _tmpl_to_atype(TALLOC_CTX *ctx, void *out, request_t *request, tmpl_t const *vpt, xlat_escape_legacy_t escape, void const *escape_ctx, fr_type_t dst_type))
Expand a template to a string, allocing a new buffer to hold the string.
Definition tmpl_eval.c:463
#define TMPL_FLAG_REGEX
Is a type of regular expression.
Definition tmpl.h:123
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
static size_t tmpl_request_ref_count(tmpl_t const *vpt)
The number of request references contained within a tmpl.
Definition tmpl.h:696
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.
tmpl_rules_t _CONST rules
The rules that were used when creating the tmpl.
Definition tmpl.h:620
tmpl_attr_error_t
Definition tmpl.h:1029
@ TMPL_ATTR_ERROR_INVALID_ARRAY_INDEX
Invalid array index.
Definition tmpl.h:1048
@ TMPL_ATTR_ERROR_LIST_NOT_ALLOWED
List qualifier is not allowed here.
Definition tmpl.h:1033
@ TMPL_ATTR_ERROR_INTERNAL_NOT_ALLOWED
Attribute resolved to an internal attribute which is disallowed.
Definition tmpl.h:1043
@ TMPL_ATTR_ERROR_UNRESOLVED_NOT_ALLOWED
Attribute couldn't be found in the dictionaries.
Definition tmpl.h:1039
@ TMPL_ATTR_ERROR_INVALID_FILTER
Invalid filter.
Definition tmpl.h:1049
@ TMPL_ATTR_ERROR_BAD_CAST
Specified cast was invalid.
Definition tmpl.h:1053
@ TMPL_ATTR_ERROR_INVALID_NAME
Attribute ref length is zero, or longer than the maximum.
Definition tmpl.h:1041
@ TMPL_ATTR_ERROR_UNQUALIFIED_NOT_ALLOWED
Attribute must be qualified to be used here.
Definition tmpl.h:1040
@ TMPL_ATTR_ERROR_MISSING_TERMINATOR
Unexpected text found after attribute reference.
Definition tmpl.h:1052
@ TMPL_ATTR_ERROR_INVALID_REQUEST_REF
invalid request reference
Definition tmpl.h:1051
@ TMPL_ATTR_ERROR_LIST_MISSING
List qualifier is required, but missing.
Definition tmpl.h:1034
@ TMPL_ATTR_ERROR_NONE
No error.
Definition tmpl.h:1030
@ TMPL_ATTR_ERROR_FOREIGN_NOT_ALLOWED
Attribute resolved in a dictionary different to the one specified.
Definition tmpl.h:1045
@ TMPL_ATTR_ERROR_INVALID_OID
OIDs are not allowed.
Definition tmpl.h:1054
@ TMPL_ATTR_ERROR_UNKNOWN_NOT_ALLOWED
Attribute specified as OID, could not be found in the dictionaries, and is disallowed because 'allow_...
Definition tmpl.h:1035
@ TMPL_ATTR_ERROR_FILTER_NOT_ALLOWED
Filters disallowed by rules.
Definition tmpl.h:1047
@ TMPL_ATTR_ERROR_EMPTY
Attribute ref contains no data.
Definition tmpl.h:1031
@ TMPL_ATTR_ERROR_NESTING_TOO_DEEP
Too many levels of nesting.
Definition tmpl.h:1050
@ TMPL_ATTR_ERROR_BAD_PREFIX
Missing '&' or has '&' when it shouldn't.
Definition tmpl.h:1032
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.
fr_dlist_t entry
Entry in the dlist of extents.
Definition tmpl.h:629
fr_type_t tmpl_data_type(tmpl_t const *vpt)
Definition tmpl_eval.c:1343
int tmpl_global_init(void)
Definition tmpl_eval.c:1384
tmpl_xlat_rules_t xlat
Rules/data for parsing xlats.
Definition tmpl.h:347
static char const * tmpl_attr_tail_unresolved(tmpl_t const *vpt)
Return the last attribute reference unresolved da.
Definition tmpl.h:894
bool at_runtime
Produce an ephemeral/runtime tmpl.
Definition tmpl.h:357
static bool tmpl_is_list(tmpl_t const *vpt)
Definition tmpl.h:945
bool new_functions
new function syntax
Definition tmpl.h:337
int tmpl_eval_pair(TALLOC_CTX *ctx, fr_value_box_list_t *out, request_t *request, tmpl_t const *vpt)
Gets the value of a real or virtual attribute.
Definition tmpl_eval.c:954
requests_ref_e
Definition tmpl.h:97
@ REQUEST_OUTER
request_t containing the outer layer of the EAP conversation.
Definition tmpl.h:99
@ REQUEST_PARENT
Parent (whatever it is).
Definition tmpl.h:103
@ REQUEST_UNKNOWN
Unknown request.
Definition tmpl.h:104
@ REQUEST_CURRENT
The current request (default).
Definition tmpl.h:98
tmpl_attr_type_t
Definition tmpl.h:403
@ TMPL_ATTR_TYPE_UNSPEC
No attribute was specified as this level only a filter.
Definition tmpl.h:405
@ TMPL_ATTR_TYPE_NORMAL
Normal, resolved, attribute ref.
Definition tmpl.h:404
@ TMPL_ATTR_TYPE_UNKNOWN
We have an attribute number but it doesn't match anything in the dictionary, or isn't a child of the ...
Definition tmpl.h:407
@ TMPL_ATTR_TYPE_UNRESOLVED
We have a name, but nothing else to identify the attribute.
Definition tmpl.h:412
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...
bool force_dict_def
Use supplied dict_def even if original vpt->rules->dict_def was not NULL.
Definition tmpl.h:397
void tmpl_set_name_shallow(tmpl_t *vpt, fr_token_t quote, char const *name, ssize_t len)
Set the name on a pre-initialised tmpl.
static fr_slen_t vpt
Definition tmpl.h:1300
fr_dict_t const * dict_def
Alternative default dictionary to use if vpt->rules->dict_def is NULL.
Definition tmpl.h:392
static bool tmpl_attr_tail_is_unresolved(tmpl_t const *vpt)
Return true if the last attribute reference is "unresolved".
Definition tmpl.h:783
tmpl_type_t _CONST type
What type of value tmpl refers to.
Definition tmpl.h:575
#define _CONST
Definition tmpl.h:260
ssize_t tmpl_preparse(char const **out, size_t *outlen, char const *in, size_t inlen, fr_token_t *type))
Preparse a string in preparation for passing it to tmpl_afrom_substr()
static size_t tmpl_attr_num_elements(tmpl_t const *vpt)
The number of attribute references contained within a tmpl.
Definition tmpl.h:921
int tmpl_attr_rebase(tmpl_t *vpt, tmpl_t const *parent)
Rewrite an attribute reference, filling in missing references.
fr_slen_t tmpl_request_ref_list_afrom_substr(TALLOC_CTX *ctx, tmpl_attr_error_t *err, FR_DLIST_HEAD(tmpl_request_list) _CONST **out, fr_sbuff_t *in)
fr_table_num_ordered_t const pair_list_table[]
void tmpl_debug(FILE *fp, tmpl_t const *vpt)
#define tmpl_attr(_tmpl)
Definition tmpl.h:683
void tmpl_attr_rewrite_leaf_num(tmpl_t *vpt, int16_t num)
Rewrite the leaf's instance number.
static fr_slen_t tmpl_attr_aprint(TALLOC_CTX *ctx, char **out, tmpl_t const *vpt) 1(tmpl_attr_print
static fr_type_t tmpl_cast_get(tmpl_t *vpt)
Definition tmpl.h:1251
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
char const *_CONST name
Raw string used to create the template.
Definition tmpl.h:577
fr_type_t cast
Whether there was an explicit cast.
Definition tmpl.h:351
void tmpl_extents_debug(FILE *fp, fr_dlist_head_t *head)
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.
void tmpl_rules_debug(tmpl_rules_t const *rules)
tmpl_type_e
Types of tmpl_t.
Definition tmpl.h:138
@ TMPL_TYPE_REGEX_UNCOMPILED
Regex where compilation is possible but hasn't been performed yet.
Definition tmpl.h:165
@ TMPL_TYPE_MAX
Marker for the last tmpl type.
Definition tmpl.h:206
@ TMPL_TYPE_ATTR_UNRESOLVED
An attribute reference that we couldn't resolve but looked valid.
Definition tmpl.h:192
@ 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_REGEX_XLAT_UNRESOLVED
A regular expression with unresolved xlat functions or attribute references.
Definition tmpl.h:204
@ TMPL_TYPE_DATA
Value in native boxed format.
Definition tmpl.h:145
@ TMPL_TYPE_REGEX
Compiled (and possibly JIT'd) regular expression.
Definition tmpl.h:161
@ TMPL_TYPE_DATA_UNRESOLVED
Unparsed literal string.
Definition tmpl.h:186
@ TMPL_TYPE_XLAT_UNRESOLVED
A xlat expansion with unresolved xlat functions or attribute references.
Definition tmpl.h:200
@ TMPL_TYPE_REGEX_XLAT
A regex containing xlat expansions.
Definition tmpl.h:169
@ TMPL_TYPE_EXEC_UNRESOLVED
An exec with unresolved xlat function or attribute references.
Definition tmpl.h:196
@ TMPL_TYPE_UNINITIALISED
Uninitialised.
Definition tmpl.h:141
int tmpl_attr_copy(tmpl_t *dst, tmpl_t const *src)
Copy a list of attribute and request references from one tmpl to another.
fr_pair_list_t * list
List that we tried to evaluate ar in and failed.
Definition tmpl.h:639
ssize_t _tmpl_to_type(void *out, uint8_t *buff, size_t outlen, request_t *request, tmpl_t const *vpt, fr_type_t dst_type))
Expand a tmpl_t to a string writing the result to a buffer.
Definition tmpl_eval.c:276
tmpl_t * tmpl_init_printf(tmpl_t *vpt, tmpl_type_t type, fr_token_t quote, char const *fmt,...))
Initialise a tmpl using a format string to create the name.
static fr_dict_attr_t const * tmpl_attr_tail_da(tmpl_t const *vpt)
Return the last attribute reference da.
Definition tmpl.h:826
#define ar_is_unresolved(_ar)
Definition tmpl.h:535
static bool tmpl_attr_head_is_list(tmpl_t const *vpt)
Return true if the head attribute reference is a list reference.
Definition tmpl.h:719
enum tmpl_type_e tmpl_type_t
Types of tmpl_t.
size_t tmpl_type_table_len
struct tmpl_literal_rules_s tmpl_literal_rules_t
Definition tmpl.h:243
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.
#define ar_is_normal(_ar)
Definition tmpl.h:532
int tmpl_attr_set_leaf_da(tmpl_t *vpt, fr_dict_attr_t const *da)
Replace the leaf attribute only.
static fr_dict_attr_t const * tmpl_attr_tail_unknown(tmpl_t const *vpt)
Return the last attribute reference unknown da.
Definition tmpl.h:878
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:940
static bool tmpl_attr_tail_is_raw(tmpl_t const *vpt)
Return true if the last attribute reference is "raw".
Definition tmpl.h:799
fr_slen_t tmpl_request_ref_list_print(fr_sbuff_t *out, FR_DLIST_HEAD(tmpl_request_list) const *rql))
int tmpl_find_or_add_vp(fr_pair_t **out, request_t *request, tmpl_t const *vpt)
Returns the first VP matching a tmpl_t, or if no VPs match, creates a new one.
Definition tmpl_eval.c:806
int tmpl_value_list_insert_tail(fr_value_box_list_t *list, fr_value_box_t *vb, tmpl_t const *vpt)
Insert a value-box to a list, with casting.
Definition tmpl_eval.c:929
static fr_slen_t rql ssize_t tmpl_attr_print(fr_sbuff_t *out, tmpl_t const *vpt)
Print an attribute or list tmpl_t to a string.
void tmpl_set_dict_def(tmpl_t *vpt, fr_dict_t const *dict)
Change the default dictionary in the tmpl's resolution rules.
int tmpl_attr_tail_unresolved_add(fr_dict_t *dict, tmpl_t *vpt, fr_type_t type, fr_dict_attr_flags_t const *flags))
Add an unresolved fr_dict_attr_t specified by a tmpl_t to the main dictionary.
int tmpl_copy_pair_children(TALLOC_CTX *ctx, fr_pair_list_t *out, request_t *request, tmpl_t const *vpt))
Copy children of pairs matching a tmpl_t in the current request_t.
Definition tmpl_eval.c:729
fr_dict_attr_t const * enumv
for resolving T_BARE_WORD
Definition tmpl.h:400
size_t _CONST len
Length of the raw string used to create the template.
Definition tmpl.h:579
ssize_t tmpl_cast_from_substr(tmpl_rules_t *t_rules, fr_sbuff_t *in))
Parse a cast specifier.
int pair_append_by_tmpl_parent(TALLOC_CTX *ctx, fr_pair_t **out, fr_pair_list_t *list, tmpl_t const *vpt, bool skip_list))
Allocate and insert a leaf vp from a tmpl_t, building the parent vps if needed.
Definition tmpl_eval.c:863
#define TMPL_FLAG_XLAT
Base data type is an xlat expansion.
Definition tmpl.h:118
tmpl_attr_t const * ar
Attribute representing the ar after the deepest node that was found in the existing pair tree when ev...
Definition tmpl.h:631
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
union tmpl_s::@109 data
fr_table_num_ordered_t const tmpl_type_table[]
Map tmpl_type_t values to descriptive strings.
int tmpl_cast_set(tmpl_t *vpt, fr_type_t type)
Set a cast for a tmpl.
fr_token_t _CONST quote
What type of quoting was around the raw string.
Definition tmpl.h:580
tmpl_t * tmpl_init_shallow(tmpl_t *vpt, tmpl_type_t type, fr_token_t quote, char const *name, ssize_t len, tmpl_rules_t const *t_rules))
Initialise a tmpl without copying the input name string.
fr_type_t tmpl_expanded_type(tmpl_t const *vpt)
Return the native data type of the expression.
Definition tmpl_eval.c:203
tmpl_attr_filter_type_t _CONST type
Type of filter this is.
Definition tmpl.h:439
size_t tmpl_request_ref_table_len
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
A source or sink of value data.
Definition tmpl.h:574
static char buff[sizeof("18446744073709551615")+3]
Definition size_tests.c:37
fr_aka_sim_id_type_t type
Define entry and head types for tmpl request references.
Definition tmpl.h:279
unsigned int allow_unknown
Allow unknown attributes i.e.
Definition tmpl.h:310
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 allow_wildcard
Allow the special case of .
Definition tmpl.h:318
CONF_ITEM * ci
for migration support and various warnings
Definition tmpl.h:308
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
FR_DLIST_HEAD(tmpl_request_list) _CONST *request_def
< Point in dictionary tree to resume parsing from.
unsigned int disallow_filters
disallow filters.
Definition tmpl.h:325
unsigned int allow_oid
allow numerical OIDs.
Definition tmpl.h:323
unsigned int xlat
for %{User-Name}
Definition tmpl.h:327
unsigned int bare_word_enum
for v3 compatibility.
Definition tmpl.h:329
unsigned int allow_foreign
Allow arguments not found in dict_def.
Definition tmpl.h:321
unsigned int allow_unresolved
Allow attributes that look valid but were not found in the dictionaries.
Definition tmpl.h:313
An element in a list of nested attribute references.
Definition tmpl.h:457
unsigned int _CONST resolve_only
This reference and those before it.
Definition tmpl.h:480
unsigned int _CONST is_raw
Definition tmpl.h:483
fr_dict_attr_t const *_CONST da
Resolved dictionary attribute.
Definition tmpl.h:461
fr_dict_attr_t const *_CONST parent
The parent we used when trying to resolve the attribute originally.
Definition tmpl.h:475
FR_DLIST_ENTRY(tmpl_attr_list) _CONST entry
Entry in the doubly linked list of attribute references.
tmpl_attr_filter_t _CONST filter
Filter associated with the attribute reference.
Definition tmpl.h:487
tmpl_attr_type_t _CONST type
is a raw reference
Definition tmpl.h:485
Define manipulation functions for the attribute reference list.
Definition tmpl.h:498
FR_DLIST_ENTRY(tmpl_request_list) _CONST entry
Entry in the doubly linked list of request references.
tmpl_request_ref_t _CONST request
Definition tmpl.h:502
Stores an attribute, a value and various bits of other data.
Definition pair.h:68
#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 an arbitrarily ordered array of name to num mappings.
Definition table.h:57
An element in a lexicographically sorted array of name to num mappings.
Definition table.h:49
Escaping rules for tmpls.
Definition tmpl_escape.h:80
enum fr_token fr_token_t
static fr_slen_t head
Definition xlat.h:410
static fr_slen_t parent
Definition pair.h:864
#define fr_type_is_structural(_x)
Definition types.h:392
#define fr_type_is_leaf(_x)
Definition types.h:393
static fr_sbuff_err_t char size_t fr_sbuff_t * in
Definition value.h:1061
static fr_slen_t data
Definition value.h:1366
static fr_sbuff_err_t char ** out
Definition value.h:1061
static fr_sbuff_err_t char size_t * len
Definition value.h:1061
uintptr_t fr_value_box_safe_for_t
Escaping that's been applied to a value box.
Definition value.h:167
int nonnull(2, 5))
int format(printf, 5, 0))