The FreeRADIUS server $Id: a4e7f8c94e8038b7627bcf52356b7ed15955c1d7 $
Loading...
Searching...
No Matches
value.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/** Boxed value structures and functions to manipulate them
19 *
20 * @file src/lib/util/value.h
21 *
22 * @copyright 2015-2018 Arran Cudbard-Bell (a.cudbardb@freeradius.org)
23 */
24RCSIDH(value_h, "$Id: fe85a3826260c01802964bed0d7b4ce501363695 $")
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30#define FR_MAX_STRING_LEN 254U /* RFC2138: string 0-253 octets */
31
33
34#ifdef __cplusplus
35}
36#endif
37
38#include <freeradius-devel/build.h>
39#include <freeradius-devel/util/dcursor.h>
40#include <freeradius-devel/missing.h>
41#include <freeradius-devel/util/dbuff.h>
42#include <freeradius-devel/util/debug.h>
43#include <freeradius-devel/util/dict.h>
44#include <freeradius-devel/util/dlist.h>
45#include <freeradius-devel/util/inet.h>
46#include <freeradius-devel/util/log.h>
47#include <freeradius-devel/util/strerror.h>
48#include <freeradius-devel/util/table.h>
49#include <freeradius-devel/util/time.h>
50#include <freeradius-devel/util/token.h>
51#include <freeradius-devel/util/types.h>
52
53#ifdef __cplusplus
54extern "C" {
55#endif
56
57/*
58 * Allow public and private versions of the same structures
59 *
60 * Coverity reports every write that initialises a value box as a write
61 * to a const field. Coverity builds define `__COVERITY__`, so Coverity
62 * analyses the private version. The compiler still enforces the public
63 * version outside `value.c`.
64 */
65#ifdef _CONST
66# error _CONST can only be defined in the local header
67#endif
68#if !defined(_VALUE_PRIVATE) && !defined(__COVERITY__)
69# define _CONST const
70#else
71# define _CONST
72#endif
73
74extern size_t const fr_value_box_field_sizes[];
75
76extern size_t const fr_value_box_offsets[];
77
84
92
94
95#ifndef NDEBUG
96# define FR_VALUE_BOX_MAGIC RADIUSD_MAGIC_NUMBER
97#endif
98
99/** @name List and cursor type definitions
100 */
101FR_DLIST_TYPES(fr_value_box_list)
102FR_DLIST_TYPEDEFS(fr_value_box_list, fr_value_box_list_t, fr_value_box_entry_t)
103FR_DCURSOR_DLIST_TYPES(fr_value_box_dcursor, fr_value_box_list, fr_value_box_t)
104/** @{ */
105
106typedef union {
107 /*
108 * Variable length values
109 */
110 struct {
111 union {
112 char const * _CONST strvalue; //!< Pointer to UTF-8 string.
113 uint8_t const * _CONST octets; //!< Pointer to binary string.
114 void * _CONST ptr; //!< generic pointer.
115 };
116 size_t length; //!< Only these types are variable length.
117 };
118
119 struct {
120 void * _CONST cursor; //!< cursors
121 char const * _CONST name; //!< name of the current cursor
122 };
123
124 /*
125 * Fixed length values
126 */
127 fr_ipaddr_t ip; //!< IPv4/6 address/prefix.
128
129 fr_ifid_t ifid; //!< IPv6 interface ID.
130 fr_ethernet_t ether; //!< Ethernet (MAC) address.
131
132 bool boolean; //!< A truth value.
133
134 uint8_t uint8; //!< 8bit unsigned integer.
135 uint16_t uint16; //!< 16bit unsigned integer.
136 uint32_t uint32; //!< 32bit unsigned integer.
137 uint64_t uint64; //!< 64bit unsigned integer.
138 uint128_t uint128; //!< 128bit unsigned integer.
139
140 int8_t int8; //!< 8bit signed integer.
141 int16_t int16; //!< 16bit signed integer.
142 int32_t int32; //!< 32bit signed integer.
143 int64_t int64; //!< 64bit signed integer;
144
145 float float32; //!< Single precision float.
146 double float64; //!< Double precision float.
147
148 fr_unix_time_t date; //!< Date internal format in nanoseconds
149
150 /*
151 * System specific - Used for runtime configuration only.
152 */
153 size_t size; //!< System specific file/memory size.
154 fr_time_delta_t time_delta; //!< a delta time in nanoseconds
155
156 fr_dict_attr_t const *da; //!< dictionary reference
157
158 fr_value_box_list_t children; //!< for groups
160
161/** Escaping that's been applied to a value box
162 *
163 * This should be a unique value for each dialect being escaped. If the value is 0,
164 * then the box is not escaped. If the escaped value matches the escaped value of
165 * the function performing the escaping then it should not be re-escaped.
166 */
167typedef uintptr_t fr_value_box_safe_for_t;
168
169/*
170 * The default value of "completely unsafe" is zero. That way any initialization routines will default
171 * to marking the data as unsafe.
172 *
173 * The only data which should be marked as being completely safe is data taken from the configuration
174 * files which are managed by the administrator. Data create by end users (e.g. passwords) should always
175 * be marked as unsafe.
176 */
177#define FR_VALUE_BOX_SAFE_FOR_NONE ((uintptr_t) 0)
178#define FR_VALUE_BOX_SAFE_FOR_ANY (~((uintptr_t) 0))
179
180/** The safety of a value
181 *
182 * Which consumer the value has been escaped for, and whether the value is a secret.
183 * The struct also travels on its own, as the accumulator when the safety of several
184 * boxes is merged into one result.
185 */
186typedef struct {
187 fr_value_box_safe_for_t safe_for; //!< A unique value to indicate if that value box is safe
188 ///< for consumption by a particular module for a particular
189 ///< purpose. e.g. LDAP, SQL, etc.
190 ///< Usually set by the xlat framework on behalf of an xlat
191 ///< escaping function, and checked by a #fr_value_box_escape_t
192 ///< to see if it needs to operate.
193 unsigned int secret : 1; //!< Same as #fr_dict_attr_flags_t secret
195
196/** Union containing all data types supported by the server
197 *
198 * This union contains all data types that can be represented by fr_pair_ts. It may also be used in other parts
199 * of the server where values of different types need to be stored.
200 *
201 * fr_type_t should be an enumeration of the values in this union.
202 *
203 * Don't change the order of the fields below without checking that the output of radsize doesn't change.
204 *
205 * The first few fields (before safety) are reused in the #fr_pair_t. This allows structural
206 * data types to have vp->vp_type, and to also use / set the various flags defined below. Do NOT
207 * change the order of the fields!
208 */
210 /** Type and flags should appear together for packing efficiency
211 */
212 fr_type_t _CONST type; //!< Type of this value-box, at the start, see pair.h
213
214#ifndef NDEBUG
215 uint64_t magic; //!< Value to verify that the structure was allocated or initialised properly.
216#endif
217 /*
218 * The value-box code adds "file" and "line" for NDEBUG, but the #fr_pair_t needs the fields only
219 * when using WITH_VERIFY_PTR. Since the fields overlap, ensure that these fields exist when the
220 * #fr_pair_t needs them, too.
221 */
222#if defined(WITH_VERIFY_PTR) || !defined(NDEBUG)
223 char const *file; //!< File where the box was allocated or initialised.
224 int line; //!< Line where the box was allocated or initialised.
225 unsigned int verified : 1; //!< whether this value has been verified
226#endif
227
228 unsigned int tainted : 1; //!< i.e. did it come from an untrusted source
229 unsigned int immutable : 1; //!< once set, the value cannot be changed
230 unsigned int talloced : 1; //!< Talloced, not stack or text allocated.
231
232 unsigned int edit : 1; //!< to control foreach / edits
233
234 fr_value_box_safety_t _CONST safety; //!< Safety of the value, see #fr_value_box_safety_t.
235
236 /*
237 * The fields before this point overlap with #fr_pair_t, so that we can get efficiency in memory
238 * packing.
239 */
240
241 fr_value_box_entry_t entry; //!< Doubly linked list entry.
242
243 fr_dict_attr_t const *enumv; //!< Enumeration values.
244
245 fr_value_box_datum_t datum; //!< The value held by the value box. Should appear
246 ///< last for packing efficiency.
247};
248
249/** @name List and cursor function definitions
250 */
251FR_DLIST_FUNCS(fr_value_box_list, fr_value_box_t, entry)
252
253#define fr_value_box_list_foreach(_list_head, _iter) fr_dlist_foreach(fr_value_box_list_dlist_head(_list_head), fr_value_box_t, _iter)
254
255FR_DCURSOR_FUNCS(fr_value_box_dcursor, fr_value_box_list, fr_value_box_t)
256/** @} */
257
258/** Actions to perform when we process a box in a list
259 *
260 */
261typedef enum : uint8_t {
262 FR_VALUE_BOX_LIST_NONE = 0x00, //!< Do nothing to processed boxes.
263 FR_VALUE_BOX_LIST_REMOVE = 0x01, //!< Remove the box from the input list.
264 FR_VALUE_BOX_LIST_FREE_BOX = (0x02 | FR_VALUE_BOX_LIST_REMOVE), //!< Free each processed box.
265 FR_VALUE_BOX_LIST_FREE_BOX_VALUE = 0x04, //!< Explicitly free any value buffers associated
266 ///< with a box.
269
270#define vb_should_free(_action) ((_action & FR_VALUE_BOX_LIST_FREE_BOX) == FR_VALUE_BOX_LIST_FREE_BOX)
271#define vb_should_free_value(_action) ((_action & FR_VALUE_BOX_LIST_FREE_BOX_VALUE) == FR_VALUE_BOX_LIST_FREE_BOX_VALUE)
272#define vb_should_remove(_action) ((_action & FR_VALUE_BOX_LIST_REMOVE) == FR_VALUE_BOX_LIST_REMOVE)
273
274#ifndef NDEBUG
275#define VALUE_BOX_NDEBUG_INITIALISER .file = __FILE__, .line = __LINE__, .magic = FR_VALUE_BOX_MAGIC
276#else
277#define VALUE_BOX_NDEBUG_INITIALISER
278#endif
279
280/** @name Field accessors for #fr_value_box_t
281 *
282 * Use these instead of accessing fields directly to make refactoring
283 * easier in future.
284 *
285 * @{
286 */
287#define vb_strvalue datum.strvalue
288#define vb_octets datum.octets
289#define vb_void datum.ptr
290#define vb_group datum.children
291#define vb_attr datum.da
292
293#define vb_ip datum.ip
294#define vb_ipv4addr datum.ip.addr.v4.s_addr
295#define vb_ipv6addr datum.ip.addr.v6.s6_addr
296
297#define vb_ifid datum.ifid.addr
298#define vb_ether datum.ether.addr
299
300#define vb_bool datum.boolean
301#define vb_uint8 datum.uint8
302#define vb_uint16 datum.uint16
303#define vb_uint32 datum.uint32
304#define vb_uint64 datum.uint64
305#define vb_uint128 datum.uint128
306
307#define vb_int8 datum.int8
308#define vb_int16 datum.int16
309#define vb_int32 datum.int32
310#define vb_int64 datum.int64
311
312#define vb_float32 datum.float32
313#define vb_float64 datum.float64
314
315#define vb_date datum.date
316
317#define vb_size datum.size
318#define vb_timeval datum.timeval
319#define vb_time_delta datum.time_delta
320
321#define vb_length datum.length
322#define vb_safefor safety.safe_for
323#define vb_secret safety.secret
324
325#define vb_cursor datum.cursor
326#define vb_cursor_name datum.name
327/** @} */
328
329/** @name Argument boxing macros
330 *
331 * These macros allow C types to be passed to functions which take
332 * boxed arguments, without needing to declare a fr_value_box_t
333 * explicitly on the stack.
334 *
335 * @{
336 */
337#define _fr_box_with_len(_type, _field, _val, _len) &(fr_value_box_t){ .type = _type, _field = _val, .vb_length = _len, VALUE_BOX_NDEBUG_INITIALISER }
338
339#define fr_box_strvalue(_val) _fr_box_with_len(FR_TYPE_STRING, .vb_strvalue, _val, strlen(_val))
340#define fr_box_strvalue_len(_val, _len) _fr_box_with_len(FR_TYPE_STRING, .vb_strvalue, _val, _len)
341
342#define fr_box_octets(_val, _len) _fr_box_with_len(FR_TYPE_OCTETS, .vb_octets, _val, _len)
343#define fr_box_strvalue_buffer(_val) _fr_box_with_len(FR_TYPE_STRING, .vb_strvalue, _val, talloc_strlen(_val))
344#define fr_box_octets_buffer(_val) _fr_box_with_len(FR_TYPE_OCTETS, .vb_octets, _val, talloc_array_length(_val))
345
346#define _fr_box(_type, _field, _val) (&(fr_value_box_t){ .type = _type, _field = (_val), VALUE_BOX_NDEBUG_INITIALISER })
347
348#define fr_box_ipaddr(_val) _fr_box((((_val).af == AF_INET) ? \
349 (((_val).prefix == 32) ? FR_TYPE_IPV4_ADDR : \
350 FR_TYPE_IPV4_PREFIX) : \
351 (((_val).prefix == 128) ? FR_TYPE_IPV6_ADDR : \
352 FR_TYPE_IPV6_PREFIX)), \
353 .vb_ip, _val)
354#define fr_box_ipv4addr(_val) _fr_box(FR_TYPE_IPV4_ADDR, .vb_ip, _val)
355#define fr_box_ipv4prefix(_val) _fr_box(FR_TYPE_IPV4_PREFIX, .vb_ip, _val)
356#define fr_box_ipv6addr(_val) _fr_box(FR_TYPE_IPV6_ADDR, .vb_ip, _val)
357#define fr_box_ipv6prefix(_val) _fr_box(FR_TYPE_IPV6_PREFIX, .vb_ip, _val)
358
359#define fr_box_ifid(_val) _fr_box(FR_TYPE_IFID, .vb_ifid, _val)
360#define fr_box_ether(_val) &(fr_value_box_t){ .type = FR_TYPE_ETHERNET, .vb_ether = { _val[0], _val[1], _val[2], _val[3], _val[4], _val[5] } }
361
362#define fr_box_bool(_val) _fr_box(FR_TYPE_BOOL, .vb_bool, _val)
363
364#define fr_box_uint8(_val) _fr_box(FR_TYPE_UINT8, .vb_uint8, _val)
365#define fr_box_uint16(_val) _fr_box(FR_TYPE_UINT16, .vb_uint16, _val)
366#define fr_box_uint32(_val) _fr_box(FR_TYPE_UINT32, .vb_uint32, _val)
367#define fr_box_uint64(_val) _fr_box(FR_TYPE_UINT64, .vb_uint64, _val)
368#define fr_box_uint128(_val) _fr_box(FR_TYPE_UINT128, .vb_uint128, _val)
369
370#define fr_box_int8(_val) _fr_box(FR_TYPE_INT8, .vb_int8, _val)
371#define fr_box_int16(_val) _fr_box(FR_TYPE_INT16, .vb_int16, _val)
372#define fr_box_int32(_val) _fr_box(FR_TYPE_INT32, .vb_int32, _val)
373#define fr_box_int64(_val) _fr_box(FR_TYPE_INT64, .vb_int64, _val)
374
375#define fr_box_float32(_val) _fr_box(FR_TYPE_FLOAT32, .vb_float32, _val)
376#define fr_box_float64(_val) _fr_box(FR_TYPE_FLOAT64, .vb_float64, _val)
377
378#define fr_box_date(_val) _fr_box(FR_TYPE_DATE, .vb_date, _val)
379
380#define fr_box_time(_val) _fr_box(FR_TYPE_DATE, .vb_date, fr_time_to_unix_time(_val))
381
382#define fr_box_size(_val) _fr_box(FR_TYPE_SIZE, .vb_size, _val)
383
384#define _fr_box_with_da(_type, _field, _val, _da) (&(fr_value_box_t){ .type = _type, _field = (_val), .enumv = (_da) })
385
386#define fr_box_time_delta_with_res(_val, _res) _fr_box_with_da(FR_TYPE_TIME_DELTA, \
387 .vb_time_delta, \
388 (_val), \
389 (&(fr_dict_attr_t){ \
390 .name = NULL, \
391 .type = FR_TYPE_TIME_DELTA, \
392 .flags = { \
393 .type_size = _res \
394 } \
395 }))
396
397#define fr_box_time_delta(_val) fr_box_time_delta_with_res((_val), FR_TIME_RES_SEC)
398
399#define fr_box_time_delta_sec(_val) fr_box_time_delta_with_res((_val), FR_TIME_RES_SEC)
400
401#define fr_box_time_delta_msec(_val) fr_box_time_delta_with_res((_val), FR_TIME_RES_MSEC)
402
403#define fr_box_time_delta_nsec(_val) fr_box_time_delta_with_res((_val), FR_TIME_RES_NSEC)
404
405#define fr_box_time_delta_usec(_val) fr_box_time_delta_with_res((_val), FR_TIME_RES_USEC)
406
407/** Create an ephemeral box
408 *
409 * @note This likely shouldn't be used for variable width integers like 'int'
410 * as it obscures the underlying type.
411 *
412 * @param[in] _val to box.
413 */
414#define fr_box(_val) _Generic((_val), \
415 fr_ipaddr_t * : fr_box_ipaddr, \
416 fr_ipaddr_t const * : fr_box_ipaddr, \
417 fr_ethernet_t * : fr_box_ether, \
418 fr_ethernet_t const * : fr_box_ether, \
419 bool : fr_box_bool, \
420 int8_t : fr_box_int8, \
421 int16_t : fr_box_int16, \
422 int32_t : fr_box_int32, \
423 int64_t : fr_box_int16, \
424 uint8_t : fr_box_uint8, \
425 uint16_t : fr_box_uint16, \
426 uint32_t : fr_box_uint32, \
427 uint64_t : fr_box_uint64, \
428 size_t : fr_box_size, \
429 float : fr_box_float32, \
430 double : fr_box_float64 \
431)(_val)
432
433/** Create an ephemeral boxed value with a variable length
434 *
435 * @param[in] _val C variable to assign value from.
436 * @param[in] _len of C variable.
437 */
438#define fr_box_len( _val, _len) \
439_Generic((_val), \
440 char * : fr_box_strvalue_len, \
441 char const * : fr_box_strvalue_len, \
442 uint8_t * : fr_box_octets, \
443 uint8_t const * : fr_box_octets \
444)(_val, _len)
445
446/** @} */
447
448/** @name Type checking macros
449 *
450 * Convenience macros for checking if a box is a
451 * specific type.
452 *
453 * @{
454 */
455#define fr_box_is_null(_x) fr_type_is_null((_x)->type)
456#define fr_box_is_string(_x) fr_type_is_string((_x)->type)
457#define fr_box_is_octets(_x) fr_type_is_octets((_x)->type)
458#define fr_box_is_ipv4addr(_x) fr_type_is_ipv4addr((_x)->type)
459#define fr_box_is_ipv4prefix(_x) fr_type_is_ipv4prefix((_x)->type)
460#define fr_box_is_ipv6addr(_x) fr_type_is_ipv6addr((_x)->type)
461#define fr_box_is_ipv6prefix(_x) fr_type_is_ipv6prefix((_x)->type)
462#define fr_box_is_ifid(_x) fr_type_is_ifid((_x)->type)
463#define fr_box_is_combo_ipaddr(_x) fr_type_is_combo_ipaddr((_x)->type)
464#define fr_box_is_combo_ipprefix(_x) fr_type_is_combo_ipprefix((_x)->type)
465#define fr_box_is_ethernet(_x) fr_type_is_ethernet((_x)->type)
466#define fr_box_is_bool(_x) fr_type_is_bool((_x)->type)
467#define fr_box_is_uint8(_x) fr_type_is_uint8((_x)->type)
468#define fr_box_is_uint16(_x) fr_type_is_uint16((_x)->type)
469#define fr_box_is_uint32(_x) fr_type_is_uint32((_x)->type)
470#define fr_box_is_uint64(_x) fr_type_is_uint64((_x)->type)
471#define fr_box_is_int8(_x) fr_type_is_int8((_x)->type)
472#define fr_box_is_int16(_x) fr_type_is_int16((_x)->type)
473#define fr_box_is_int32(_x) fr_type_is_int32((_x)->type)
474#define fr_box_is_int64(_x) fr_type_is_int64((_x)->type)
475#define fr_box_is_float32(_x) fr_type_is_float32((_x)->type)
476#define fr_box_is_float64(_x) fr_type_is_float64((_x)->type)
477#define fr_box_is_date(_x) fr_type_is_date((_x)->type)
478#define fr_box_is_time_delta(_x) fr_type_is_time_delta((_x)->type)
479#define fr_box_is_size(_x) fr_type_is_size((_x)->type)
480#define fr_box_is_tlv(_x) fr_type_is_tlv((_x)->type)
481#define fr_box_is_struct(_x) fr_type_is_struct((_x)->type)
482#define fr_box_is_vsa(_x) fr_type_is_vsa((_x)->type)
483#define fr_box_is_vendor(_x) fr_type_is_vendor((_x)->type)
484#define fr_box_is_group(_x) fr_type_is_group((_x)->type)
485#define fr_box_is_value_box(_x) fr_type_is_value_box((_x)->type)
486#define fr_box_is_void(_x) fr_type_is_void((_x)->type)
487
488#define fr_box_is_integer_except_bool(_x) fr_type_is_integer_except_bool((_x)->type)
489#define fr_box_is_integer(_x) fr_type_is_integer((_x)->type)
490#define fr_box_is_numeric(_x) fr_type_is_numeric((_x)->type)
491
492#define fr_box_is_ip(_x) fr_type_is_ip((_x)->type)
493
494#define fr_box_is_fixed_size(_x) fr_type_is_fixed_size((_x)->type)
495#define fr_box_is_variable_size(_x) fr_type_is_variable_size((_x)->type)
496#define fr_box_is_value(_x) fr_type_is_value((_x)->type)
497#define fr_box_is_quoted(_x) fr_type_is_quoted((_x)->type)
498
499#define fr_box_is_structural_except_vsa(_x) fr_type_is_structural_except_vsa((_x)->type)
500#define fr_box_is_structural(_x) fr_type_is_structural((_x)->type)
501#define fr_box_is_non_value(_x) fr_type_is_non_value((_x)->type)
502/** @} */
503
504/** @name Parsing rules for various types of string
505 *
506 * @{
507 */
508extern fr_sbuff_parse_rules_t const value_parse_rules_bareword_unquoted;
509extern fr_sbuff_parse_rules_t const value_parse_rules_double_unquoted;
510extern fr_sbuff_parse_rules_t const value_parse_rules_single_unquoted;
511extern fr_sbuff_parse_rules_t const value_parse_rules_solidus_unquoted;
512extern fr_sbuff_parse_rules_t const value_parse_rules_backtick_unquoted;
513extern fr_sbuff_parse_rules_t const *value_parse_rules_unquoted[T_TOKEN_LAST];
514extern fr_sbuff_parse_rules_t const *value_parse_rules_unquoted_char[SBUFF_CHAR_CLASS];
515
516extern fr_sbuff_parse_rules_t const value_parse_rules_bareword_quoted;
517extern fr_sbuff_parse_rules_t const value_parse_rules_double_quoted;
518extern fr_sbuff_parse_rules_t const value_parse_rules_single_quoted;
519extern fr_sbuff_parse_rules_t const value_parse_rules_solidus_quoted;
520extern fr_sbuff_parse_rules_t const value_parse_rules_backtick_quoted;
521extern fr_sbuff_parse_rules_t const *value_parse_rules_quoted[T_TOKEN_LAST];
522extern fr_sbuff_parse_rules_t const *value_parse_rules_quoted_char[SBUFF_CHAR_CLASS];
523
524extern fr_sbuff_parse_rules_t const value_parse_rules_double_3quoted;
525extern fr_sbuff_parse_rules_t const value_parse_rules_single_3quoted;
526extern fr_sbuff_parse_rules_t const value_parse_rules_solidus_3quoted;
527extern fr_sbuff_parse_rules_t const value_parse_rules_backtick_3quoted;
528extern fr_sbuff_parse_rules_t const *value_parse_rules_3quoted[T_TOKEN_LAST];
529/** @} */
530
531/** @name Allocation and initialisation functions
532 *
533 * These macros and inline functions simplify working
534 * with lists of value boxes.
535 *
536 * @{
537 */
538/** A static initialiser for stack/globally allocated boxes
539 *
540 * We can only safely initialise a null box, as many other type need special initialisation
541 */
542#define FR_VALUE_BOX_INITIALISER_NULL(_vb) \
543 { \
544 .type = FR_TYPE_NULL, \
545 .entry = { \
546 .entry = FR_DLIST_ENTRY_INITIALISER((_vb).entry.entry) \
547 }, \
548 VALUE_BOX_NDEBUG_INITIALISER \
549 }
550
551/** A static initialiser for stack/globally allocated boxes
552 *
553 */
554#define FR_VALUE_BOX_INITIALISER(_vb, _type, _field, _val) \
555 { \
556 .type = _type, \
557 .datum = { \
558 _field = _val, \
559 }, \
560 .entry = { \
561 .entry = FR_DLIST_ENTRY_INITIALISER((_vb).entry.entry) \
562 }, \
563 VALUE_BOX_NDEBUG_INITIALISER \
564 }
565
566static inline CC_HINT(nonnull(1), always_inline)
568{
569 /*
570 * Outside `value.c`, `fr_value_box_t` has `_CONST` fields, so the
571 * compiler rejects an assignment to `*vb`. `memcpy()` writes the
572 * fields instead.
573 */
574 memcpy((void *) vb, &(fr_value_box_t){
575 .type = type,
576 .enumv = enumv,
577 .tainted = tainted,
578 .safety = { .secret = enumv && enumv->flags.secret },
579 /* don't set the immutable flag. The caller has to do it once he's finished editing the values */
580 }, sizeof(*vb));
581 fr_value_box_list_entry_init(vb);
582
583 /*
584 * The majority of types are fine to initialise to
585 * all zeros, the following are the exceptions.
586 */
587 switch (type) {
589 fr_value_box_list_init(&vb->vb_group);
590 break;
591
593 case FR_TYPE_COMBO_IP_ADDR: /* Default to the smaller type */
594 vb->vb_ip.af = AF_INET;
595 vb->vb_ip.prefix = 32;
596 break;
597
599 case FR_TYPE_COMBO_IP_PREFIX: /* Default to the samaller type */
600 vb->vb_ip.af = AF_INET;
601 break;
602
604 vb->vb_ip.af = AF_INET6;
605 vb->vb_ip.prefix = 128;
606 break;
607
609 vb->vb_ip.af = AF_INET6;
610 break;
611
612 default:
613 break;
614 }
615
616#ifndef NDEBUG
617 vb->magic = FR_VALUE_BOX_MAGIC;
618 vb->file = file;
619 vb->line = line;
620#endif
621}
622
623/** Initialise a fr_value_box_t
624 *
625 * The value should be set later with one of the fr_value_box_* functions.
626 *
627 * @param[in] _vb to initialise.
628 * @param[in] _type to set.
629 * @param[in] _enumv Enumeration values.
630 * @param[in] _tainted Whether data will come from an untrusted source.
631 *
632 * @hidecallergraph
633 */
634#define fr_value_box_init(_vb, _type, _enumv, _tainted) _fr_value_box_init(NDEBUG_LOCATION_EXP _vb, _type, _enumv, _tainted)
635
636/** Initialise an empty/null box that will be filled later
637 *
638 * @param[in] _vb to initialise.
639 */
640#define fr_value_box_init_null(_vb) _fr_value_box_init(NDEBUG_LOCATION_EXP _vb, FR_TYPE_NULL, NULL, false)
641
642static inline CC_HINT(always_inline)
644{
645 fr_value_box_t *vb;
646
647 vb = talloc(ctx, fr_value_box_t);
648 if (unlikely(!vb)) return NULL;
649
651 vb->talloced = 1;
652
653 return vb;
654}
655
656/** Allocate a value box of a specific type
657 *
658 * Allocates memory for the box, and sets the length of the value
659 * for fixed length types.
660 *
661 * @param[in] _ctx to allocate the value_box in.
662 * @param[in] _type of value.
663 * @param[in] _enumv Enumeration values.
664 * @return
665 * - A new fr_value_box_t.
666 * - NULL on error.
667 */
668#define fr_value_box_alloc(_ctx, _type, _enumv) _fr_value_box_alloc(NDEBUG_LOCATION_EXP _ctx, _type, _enumv)
669
670/** Allocate a value box for later use with a value assignment function
671 *
672 * @param[in] _ctx to allocate the value_box in.
673 * @return
674 * - A new fr_value_box_t.
675 * - NULL on error.
676 *
677 * @hidecallergraph
678 */
679#define fr_value_box_alloc_null(_ctx) _fr_value_box_alloc(NDEBUG_LOCATION_EXP _ctx, FR_TYPE_NULL, NULL)
680
681/** @} */
682
683/** @name Escape functions
684 *
685 * Apply a transformation to a value box or list of value boxes.
686 *
687 * @{
688 */
689
690 /** Escape a value box
691 *
692 * @note On failure the function reports the reason with fr_strerror_printf() or
693 * fr_strerror_const().
694 *
695 * @param[in] vb to escape.
696 * @param[in] uctx user context to pass to the escape function.
697 * @return
698 * - 1 if the value was escaped and the function set safe_for itself.
699 * - 0 if the value was escaped and the caller sets safe_for.
700 * - -1 on failure, with the reason in fr_strerror.
701 */
702typedef int (*fr_value_box_escape_func_t)(fr_value_box_t *vb, void *uctx);
703
709
710int fr_value_box_escape_in_place(fr_value_box_t *vb, fr_value_box_escape_t const *escape, void *uctx)
711 CC_HINT(nonnull(1,2));
712int fr_value_box_list_escape_in_place(fr_value_box_list_t *list, fr_value_box_escape_t const *escape, void *uctx)
713 CC_HINT(nonnull(1,2));
714
716 CC_HINT(nonnull);
717
718int fr_value_box_escape_erules(fr_value_box_t *vb, void *uctx) CC_HINT(nonnull);
719
720int fr_value_box_escape_in_place_func(TALLOC_CTX *ctx, fr_value_box_t *vb, fr_sbuff_escape_func_t escape)
721 CC_HINT(nonnull);
722
723/** @} */
724
725/** @name Convenience functions
726 *
727 * These macros and inline functions simplify working
728 * with lists of value boxes.
729 *
730 * @{
731 */
732/** Determines whether a list contains the number of boxes required
733 *
734 * @param[in] list of value boxes.
735 * @param[in] min The number of boxes required to return true.
736 * @return
737 * - true if the list has at least min boxes.
738 * - false if the list has fewer than min boxes.
739 */
740static inline CC_HINT(nonnull)
741bool fr_value_box_list_len_min(fr_value_box_list_t const *list, unsigned int min)
742{
743 unsigned int i = fr_value_box_list_num_elements(list);
744
745 return (i >= min);
746}
747/** @} */
748
749/** @name Box to box copying
750 *
751 * @{
752 */
754 CC_HINT(nonnull(1));
755
757 CC_HINT(nonnull(1));
758
759int fr_value_box_copy(TALLOC_CTX *ctx, fr_value_box_t *dst, const fr_value_box_t *src)
760 CC_HINT(nonnull(2,3)) CC_HINT(warn_unused_result);
761
762void fr_value_box_copy_shallow(TALLOC_CTX *ctx, fr_value_box_t *dst,
763 const fr_value_box_t *src)
764 CC_HINT(nonnull(2,3));
765
766int fr_value_box_steal(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_value_box_t *src)
767 CC_HINT(nonnull(2,3));
768
769/** Copy an existing box, allocating a new box to hold its contents
770 *
771 * @param[in] ctx to allocate new box in.
772 * @param[in] src box to copy.
773 */
774static inline CC_HINT(nonnull(2))
776{
778 if (unlikely(!vb)) return NULL;
779
780 if ((unlikely(fr_value_box_copy(vb, vb, src) < 0))) {
781 talloc_free(vb);
782 return NULL;
783 }
784
785 return vb;
786}
787/** @} */
788
789/** @name Value box assignment functions
790 *
791 * These functions allow C values to be assigned to value boxes.
792 * They will work with uninitialised/stack allocated memory.
793 *
794 * @{
795 */
796
797/** Return a pointer to the "raw" value from a value-box.
798 *
799 * This has "const" input and "unconst" output because sometimes it's used
800 * to copy out of, and sometimes in to, a value-box. We rely on the caller to know
801 * the correct uses of it.
802 */
803static inline CC_HINT(always_inline)
808
809/** Copy the value of a value box to a field in a C struct
810 *
811 * This is useful when interacting with 3rd party libraries, and doing configuration parsing
812 * as it allows us to use standard parsing and casting functions and then emit the result
813 * as a C value.
814 *
815 * The field pointed to by out must be of the same type as we use to represent the value boxe's
816 * value in its datum union, or at least the same size.
817 *
818 * No checks are done to ensure this is the case, so if you get this wrong it'll lead to silent
819 * memory corruption.
820 *
821 * @param[out] out Field in struct to write variable to.
822 * @param[in] vb to copy value from.
823 * @return
824 * - 0 on success.
825 * - -1 on failure.
826 */
827static inline CC_HINT(always_inline)
829{
830 size_t len;
831
832 len = fr_value_box_field_sizes[vb->type];
833 if (len == 0) {
834 fr_strerror_printf("Type %s not supported for conversion to C type", fr_type_to_str(vb->type));
835 return -1;
836 }
837
838 memcpy(out, ((uint8_t const *)vb) + fr_value_box_offsets[vb->type], len);
839
840 return 0;
841}
842
843/** Copy a C value value to a value box.
844 *
845 * This is useful when interacting with 3rd party libraries, and doing configuration parsing
846 * as it allows us to use standard parsing and casting functions and then emit the result
847 * as a C value.
848 *
849 * The field pointed to by in must be of the same type as we use to represent the value boxe's
850 * value in its datum union, or at least the same size.
851 *
852 * No checks are done to ensure this is the case, so if you get this wrong it'll lead to silent
853 * memory corruption.
854 *
855 * @param[in] vb destination value box, MUST already be initialized
856 * @param[out] in C variable to read from
857 * @return
858 * - 0 on success.
859 * - -1 on failure.
860 */
861static inline CC_HINT(always_inline)
863{
864 size_t len;
865
866 len = fr_value_box_field_sizes[vb->type];
867 if (len == 0) {
868 fr_strerror_printf("Type %s not supported for conversion to C type", fr_type_to_str(vb->type));
869 return -1;
870 }
871
872 memcpy(((uint8_t *)vb) + fr_value_box_offsets[vb->type], in, len);
873
874 return 0;
875}
876
877
878/** Box an ethernet value (6 bytes, network byte order)
879 *
880 * @param[in] dst Where to copy the ethernet address to.
881 * @param[in] enumv Enumeration values.
882 * @param[in] src The ethernet address.
883 * @param[in] tainted Whether data will come from an untrusted source.
884 * @return 0 (always successful).
885 */
886static inline CC_HINT(nonnull(1,3), always_inline) \
888 fr_ethernet_t const *src, bool tainted)
889{
890 fr_value_box_init(dst, FR_TYPE_ETHERNET, enumv, tainted);
891 memcpy(dst->vb_ether, src, sizeof(dst->vb_ether));
892 return 0;
893}
894
895#define DEF_BOXING_FUNC(_ctype, _field, _type) \
896static inline CC_HINT(nonnull(1), always_inline) \
897int fr_value_box_##_field(fr_value_box_t *dst, fr_dict_attr_t const *enumv, \
898 _ctype const value, bool tainted) { \
899 fr_value_box_init(dst, _type, enumv, tainted); \
900 dst->vb_##_field = value; \
901 return 0; \
902}
903
904DEF_BOXING_FUNC(bool, bool, FR_TYPE_BOOL)
905
909DEF_BOXING_FUNC(uint64_t, uint64, FR_TYPE_UINT64)
910
911DEF_BOXING_FUNC(int8_t, int8, FR_TYPE_INT8)
912DEF_BOXING_FUNC(int16_t, int16, FR_TYPE_INT16)
913DEF_BOXING_FUNC(int32_t, int32, FR_TYPE_INT32)
914DEF_BOXING_FUNC(int64_t, int64, FR_TYPE_INT64)
915
916DEF_BOXING_FUNC(float, float32, FR_TYPE_FLOAT32)
918
920
921/** Automagically fill in a box, determining the value type from the type of the C variable
922 *
923 * Simplify boxing for simple C types using the _Generic macro to emit code that
924 * fills in the value box based on the type of _var provided.
925 *
926 * @note Will not set the box value to tainted. You should do this manually if required.
927 *
928 * @note Will not work for all box types. Will default to the 'simpler' box type, if the mapping
929 * between C type and box type is ambiguous.
930 *
931 * @param[in] _box to assign value to.
932 * @param[in] _var C variable to assign value from.
933 * @param[in] _tainted Whether the value came from an untrusted source.
934 */
935#define fr_value_box(_box, _var, _tainted) \
936_Generic((_var), \
937 fr_ipaddr_t * : fr_value_box_ipaddr, \
938 fr_ipaddr_t const * : fr_value_box_ipaddr, \
939 fr_ethernet_t * : fr_value_box_ethernet_addr, \
940 fr_ethernet_t const * : fr_value_box_ethernet_addr, \
941 bool : fr_value_box_bool, \
942 uint8_t : fr_value_box_uint8, \
943 uint16_t : fr_value_box_uint16, \
944 uint32_t : fr_value_box_uint32, \
945 uint64_t : fr_value_box_uint64, \
946 int8_t : fr_value_box_int8, \
947 int16_t : fr_value_box_int16, \
948 int32_t : fr_value_box_int32, \
949 int64_t : fr_value_box_int64, \
950 float : fr_value_box_float32, \
951 double : fr_value_box_float64 \
952)(_box, NULL, _var, _tainted)
953
954/** Automagically fill in a box, for types with length
955 *
956 * @param[in] _ctx to allocate value in.
957 * @param[in] _box to assign value to.
958 * @param[in] _var C variable to assign value from.
959 * @param[in] _len of C variable.
960 * @param[in] _tainted Whether the value came from an untrusted source.
961 */
962#define fr_value_box_len(_ctx, _box, _var, _len, _tainted) \
963_Generic((_var), \
964 char * : fr_value_box_bstrndup, \
965 char const * : fr_value_box_bstrndup, \
966 uint8_t * : fr_value_box_memdup, \
967 uint8_t const * : fr_value_box_memdup \
968)(_ctx, _box, NULL, _var, _len, _tainted)
969
970/** Unbox an ethernet value (6 bytes, network byte order)
971 *
972 * @param[in] dst Where to copy the ethernet address to.
973 * @param[in] src Where to copy the ethernet address from.
974 * @return
975 * - 0 on success.
976 * - -1 on type mismatch.
977 */
978static inline CC_HINT(nonnull)
980{
981 if (unlikely(src->type != FR_TYPE_ETHERNET)) { \
982 fr_strerror_printf("Unboxing failed. Needed type %s, had type %s",
984 fr_type_to_str(src->type));
985 return -1; \
986 }
987 memcpy(dst, src->vb_ether, sizeof(src->vb_ether)); /* Must be src, dst is a pointer */
988 return 0;
989}
990
991#define DEF_UNBOXING_FUNC(_ctype, _field, _type) \
992static inline CC_HINT(nonnull) \
993int fr_value_unbox_##_field(_ctype *var, fr_value_box_t const *src) { \
994 if (unlikely(src->type != _type)) { \
995 fr_strerror_printf("Unboxing failed. Needed type %s, had type %s", \
996 fr_type_to_str(_type), \
997 fr_type_to_str(src->type)); \
998 return -1; \
999 } \
1000 *var = src->vb_##_field; \
1001 return 0; \
1002}
1003
1007DEF_UNBOXING_FUNC(uint64_t, uint64, FR_TYPE_UINT64)
1008
1009DEF_UNBOXING_FUNC(int8_t, int8, FR_TYPE_INT8)
1010DEF_UNBOXING_FUNC(int16_t, int16, FR_TYPE_INT16)
1011DEF_UNBOXING_FUNC(int32_t, int32, FR_TYPE_INT32)
1012DEF_UNBOXING_FUNC(int64_t, int64, FR_TYPE_INT64)
1013
1014DEF_UNBOXING_FUNC(float, float32, FR_TYPE_FLOAT32)
1016
1018
1019/** Unbox simple types performing type checks
1020 *
1021 * @param[out] _var to write to.
1022 * @param[in] _box to unbox.
1023 */
1024#define fr_value_unbox_shallow(_var, _box) \
1025_Generic((_var), \
1026 uint8_t * : fr_value_unbox_uint8, \
1027 uint16_t * : fr_value_unbox_uint16, \
1028 uint32_t * : fr_value_unbox_uint32, \
1029 uint64_t * : fr_value_unbox_uint64, \
1030 int8_t * : fr_value_unbox_int8, \
1031 int16_t * : fr_value_unbox_int16, \
1032 int32_t * : fr_value_unbox_int32, \
1033 int64_t * : fr_value_unbox_int64, \
1034 float * : fr_value_unbox_float32, \
1035 double * : fr_value_unbox_float64 \
1036)(_var, _box)
1037
1038/** @} */
1039
1040/*
1041 * Comparison
1042 */
1044 CC_HINT(nonnull);
1045
1047 CC_HINT(nonnull);
1048
1049/*
1050 * Conversion
1051 */
1052fr_sbuff_err_t fr_value_str_unescape(size_t *len, fr_sbuff_t *out, fr_sbuff_t *in, size_t max, char quote)
1053 CC_HINT(nonnull(2,3)) CC_HINT(warn_unused_result);
1054
1056 CC_HINT(nonnull(2,3)) CC_HINT(warn_unused_result);
1057
1058static inline fr_sbuff_err_t fr_value_str_aunescape(TALLOC_CTX *ctx, char **out, size_t *len, fr_sbuff_t *in, size_t max, char quote)
1060
1061static inline fr_sbuff_err_t fr_value_substr_aunescape(TALLOC_CTX *ctx, char **out, size_t *len, fr_sbuff_t *in, size_t max, char quote)
1063
1065 CC_HINT(nonnull);
1066
1068 CC_HINT(nonnull);
1069
1071#define FR_VALUE_BOX_TO_NETWORK_RETURN(_dbuff, _value) FR_DBUFF_RETURN(fr_value_box_to_network, _dbuff, _value)
1072
1073int fr_value_box_to_key(uint8_t **out, size_t *outlen, fr_value_box_t const *value)
1074 CC_HINT(nonnull);
1075
1076/** Special value to indicate fr_value_box_from_network experienced a general error
1077 */
1078#define FR_VALUE_BOX_NET_ERROR SSIZE_MIN
1079
1080/** Special value to indicate fr_value_box_from_network hit an out of memory error
1081 */
1082#define FR_VALUE_BOX_NET_OOM (FR_VALUE_BOX_NET_ERROR + 1)
1083
1084/** Special value to ensure other encoding/decoding errors don't overlap
1085 */
1086#define FR_VALUE_BOX_NET_MAX (FR_VALUE_BOX_NET_OOM + 1)
1087
1088ssize_t fr_value_box_from_network(TALLOC_CTX *ctx,
1089 fr_value_box_t *dst, fr_type_t type, fr_dict_attr_t const *enumv,
1090 fr_dbuff_t *dbuff, size_t len, bool tainted)
1091 CC_HINT(nonnull(2,5));
1092
1094 int prefix_len, uint8_t const *data, size_t data_len, bool fixed, bool tainted)
1095 CC_HINT(nonnull(1,5));
1096
1097ssize_t fr_value_box_from_memory(TALLOC_CTX *ctx,
1098 fr_value_box_t *dst, fr_type_t type, fr_dict_attr_t const *enumv,
1099 void const *src, size_t len)
1100 CC_HINT(nonnull(2,5));
1101
1102int fr_value_box_cast(TALLOC_CTX *ctx, fr_value_box_t *dst,
1103 fr_type_t dst_type, fr_dict_attr_t const *dst_enumv,
1104 fr_value_box_t const *src)
1105 CC_HINT(warn_unused_result,nonnull(2,5));
1106
1107int fr_value_box_cast_in_place(TALLOC_CTX *ctx, fr_value_box_t *vb,
1108 fr_type_t dst_type, fr_dict_attr_t const *dst_enumv)
1109 CC_HINT(warn_unused_result,nonnull(1));
1110
1111uint64_t fr_value_box_as_uint64(fr_value_box_t const *src)
1112 CC_HINT(warn_unused_result,nonnull);
1113
1115 CC_HINT(nonnull(1));
1116
1118 fr_ipaddr_t const *ipaddr, bool tainted)
1119 CC_HINT(nonnull(1,3));
1120
1122 CC_HINT(nonnull);
1123
1124#define fr_value_box_mark_safe_for(_box, _safe_for) _fr_value_box_mark_safe_for(_box, (fr_value_box_safe_for_t)_safe_for)
1126 CC_HINT(nonnull);
1127
1129 CC_HINT(nonnull);
1130
1131#define fr_value_box_is_safe_for(_box, _safe_for) (((_box)->vb_safefor == (fr_value_box_safe_for_t)_safe_for) || ((_box)->vb_safefor == FR_VALUE_BOX_SAFE_FOR_ANY))
1132#define fr_value_box_is_safe_for_only(_box, _safe_for) ((_box)->vb_safefor == (fr_value_box_safe_for_t)_safe_for)
1133
1134void fr_value_box_list_mark_safe_for(fr_value_box_list_t *list, fr_value_box_safe_for_t safe_for);
1135
1139void fr_value_box_safety_set(fr_value_box_t *box, fr_value_box_safety_t const *safety) CC_HINT(nonnull);
1140void fr_value_box_list_safety_merge(fr_value_box_t *out, fr_value_box_list_t const *list) CC_HINT(nonnull);
1141
1142static inline CC_HINT(nonnull, always_inline)
1144{
1145 return box->vb_secret;
1146}
1147
1148static inline CC_HINT(nonnull)
1150{
1151 fr_value_box_t const *vb = NULL;
1152
1153 if (box->vb_secret) return true;
1154 if (box->type == FR_TYPE_GROUP) {
1155 while ((vb = fr_value_box_list_next(&box->vb_group, vb))) {
1156 if (fr_value_box_contains_secret(vb)) return true;
1157 }
1158 }
1159 return false;
1160}
1161
1162void fr_value_box_set_secret(fr_value_box_t *box, bool secret) CC_HINT(nonnull);
1163
1164/** Decide if we need an enum prefix.
1165 *
1166 * We don't print the prefix in fr_value_box_print(), even though that function is the inverse of
1167 * fr_value_box_from_str(). If we always add the prefix there, then lots of code needs to be updated to
1168 * suppress printing the prefix. e.g. When using %{Service-Type} in a filename, or %{Acct-Status-Type} in an
1169 * SQL query, etc.
1170 *
1171 * Instead, the various unlang / debug routines add the prefix manually. This way ends up being less
1172 * complicated, and has fewer cornrer cases than the "right" way of doing it.
1173 *
1174 * Note that we don't return the enum name for booleans. Those are printed as "true / false", or "yes / no"
1175 * without the "::" prefix.
1176 */
1177static inline CC_HINT(nonnull, always_inline)
1179{
1180 if (fr_type_is_leaf(box->type) && (box->type != FR_TYPE_STRING) &&
1181 box->enumv && box->enumv->flags.has_value &&
1182 ((box->type != FR_TYPE_BOOL) || da_is_bit_field(box->enumv))) {
1183 return fr_dict_enum_name_by_value(box->enumv, box);
1184 }
1185
1186 return NULL;
1187}
1188
1189
1190/** @name Assign and manipulate binary-unsafe C strings
1191 *
1192 * @{
1193 */
1194int fr_value_box_strdup(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_dict_attr_t const *enumv,
1195 char const *src, bool tainted)
1196 CC_HINT(nonnull(2,4));
1197
1198int fr_value_box_strtrim(TALLOC_CTX *ctx, fr_value_box_t *vb)
1199 CC_HINT(nonnull(1));
1200
1201int fr_value_box_vasprintf(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_dict_attr_t const *enumv, bool tainted,
1202 char const *fmt, va_list ap)
1203 CC_HINT(nonnull(2,5), format(printf,5,0));
1204
1205int fr_value_box_asprintf(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_dict_attr_t const *enumv, bool tainted,
1206 char const *fmt, ...)
1207 CC_HINT(format(printf,5,6), nonnull(2,5));
1208
1210 char const *src, bool tainted)
1211 CC_HINT(nonnull(1,3));
1212
1214 CC_HINT(nonnull);
1215
1216int fr_value_box_bstrndup_replace(TALLOC_CTX *ctx, fr_value_box_t *vb, char const *src, ssize_t len)
1217 CC_HINT(nonnull(2,3));
1218/** @} */
1219
1220/** @name Assign and manipulate binary-safe strings
1221 *
1222 * @{
1223 */
1224int fr_value_box_bstr_alloc(TALLOC_CTX *ctx, char **out, fr_value_box_t *dst, fr_dict_attr_t const *enumv,
1225 size_t len, bool tainted)
1226 CC_HINT(nonnull(3));
1227
1228int fr_value_box_bstr_realloc(TALLOC_CTX *ctx, char **out, fr_value_box_t *dst, size_t len)
1229 CC_HINT(nonnull(3));
1230
1231int fr_value_box_bstrndup(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_dict_attr_t const *enumv,
1232 char const *src, size_t len, bool tainted)
1233 CC_HINT(nonnull(2)); /* src may be NULL if len == 0 */
1234
1235int fr_value_box_bstrndup_dbuff(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_dict_attr_t const *enumv,
1236 fr_dbuff_t *dbuff, size_t len, bool tainted)
1237 CC_HINT(nonnull(2,4));
1238
1239int fr_value_box_bstrdup_buffer(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_dict_attr_t const *enumv,
1240 char const *src, bool tainted)
1241 CC_HINT(nonnull(2,4));
1242
1244 char const *src, size_t len, bool tainted)
1245 CC_HINT(nonnull(1,3));
1246
1247int fr_value_box_bstrdup_buffer_shallow(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_dict_attr_t const *enumv,
1248 char const *src, bool tainted)
1249 CC_HINT(nonnull(2,4));
1250
1251/** @} */
1252
1253/** @name Assign and manipulate octets strings
1254 *
1255 * @{
1256 */
1257int fr_value_box_mem_alloc(TALLOC_CTX *ctx, uint8_t **out, fr_value_box_t *dst, fr_dict_attr_t const *enumv,
1258 size_t len, bool tainted)
1259 CC_HINT(nonnull(3));
1260
1261int fr_value_box_mem_realloc(TALLOC_CTX *ctx, uint8_t **out, fr_value_box_t *dst, size_t len)
1262 CC_HINT(nonnull(3));
1263
1264int fr_value_box_memdup(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_dict_attr_t const *enumv,
1265 uint8_t const *src, size_t len, bool tainted)
1266 CC_HINT(nonnull(2)); /* src may be NULL if len == 0 */
1267
1268int fr_value_box_memdup_dbuff(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_dict_attr_t const *enumv,
1269 fr_dbuff_t *dbuff, size_t len, bool tainted)
1270 CC_HINT(nonnull(2,4));
1271
1272int fr_value_box_memdup_buffer(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_dict_attr_t const *enumv,
1273 uint8_t const *src, bool tainted)
1274 CC_HINT(nonnull(2,4));
1275
1277 uint8_t const *src, size_t len, bool tainted)
1278 CC_HINT(nonnull(1,3));
1279
1280void fr_value_box_memdup_buffer_shallow(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_dict_attr_t const *enumv,
1281 uint8_t const *src, bool tainted)
1282 CC_HINT(nonnull(2,4));
1283
1284/** @} */
1285
1287 CC_HINT(nonnull);
1288
1289
1290
1291void fr_value_box_set_cursor_shallow(fr_value_box_t *dst, fr_type_t type, void *ptr, char const *name) CC_HINT(nonnull);
1292
1293#define fr_value_box_get_cursor(_dst) talloc_get_type_abort((_dst)->vb_cursor, fr_dcursor_t)
1294
1295void fr_value_box_set_void_shallow(fr_value_box_t *dst, void const *ptr);
1296
1298
1299/** @name Parsing
1300 *
1301 * @{
1302 */
1304 fr_type_t dst_type, fr_dict_attr_t const *dst_enumv,
1305 fr_sbuff_t *in, fr_sbuff_parse_rules_t const *rules)
1306 CC_HINT(nonnull(2,5));
1307
1308fr_slen_t fr_value_box_from_str(TALLOC_CTX *ctx, fr_value_box_t *dst,
1309 fr_type_t dst_type, fr_dict_attr_t const *dst_enumv,
1310 char const *in, size_t inlen,
1311 fr_sbuff_unescape_rules_t const *erules)
1312 CC_HINT(nonnull(2,5));
1313/** @} */
1314
1315/** @name Work with lists of boxed values
1316 *
1317 * @{
1318 */
1319ssize_t fr_value_box_list_concat_as_string(fr_value_box_safety_t *safety, fr_sbuff_t *sbuff, fr_value_box_list_t *list,
1320 char const *sep, size_t sep_len, fr_sbuff_escape_rules_t const *e_rules,
1321 fr_value_box_list_action_t proc_action, fr_value_box_safe_for_t safe_for, bool flatten)
1322 CC_HINT(nonnull(2,3));
1323
1324ssize_t fr_value_box_list_concat_as_octets(fr_value_box_safety_t *safety, fr_dbuff_t *dbuff, fr_value_box_list_t *list,
1325 uint8_t const *sep, size_t sep_len,
1326 fr_value_box_list_action_t proc_action, bool flatten)
1327 CC_HINT(nonnull(2,3));
1328
1329int fr_value_box_list_concat_in_place(TALLOC_CTX *ctx,
1330 fr_value_box_t *out, fr_value_box_list_t *list, fr_type_t type,
1331 fr_value_box_list_action_t proc_action, bool flatten,
1332 size_t max_size)
1333 CC_HINT(nonnull(2,3));
1334
1335void fr_value_box_flatten(TALLOC_CTX *ctx, fr_value_box_list_t *list, bool steal, bool free)
1336 CC_HINT(nonnull(2));
1337
1338char *fr_value_box_list_aprint(TALLOC_CTX *ctx, fr_value_box_list_t const *list, char const *delim,
1339 fr_sbuff_escape_rules_t const *e_rules)
1340 CC_HINT(nonnull(2));
1341
1342char *fr_value_box_list_aprint_secure(TALLOC_CTX *ctx, fr_value_box_list_t const *list, char const *delim,
1343 fr_sbuff_escape_rules_t const *e_rules)
1344 CC_HINT(nonnull(2));
1345
1346int fr_value_box_list_acopy(TALLOC_CTX *ctx, fr_value_box_list_t *out, fr_value_box_list_t const *in)
1347 CC_HINT(nonnull(2,3));
1348
1349bool fr_value_box_list_tainted(fr_value_box_list_t const *head)
1350 CC_HINT(nonnull(1));
1351/** @} */
1352
1353/** @name Print the value of a value box as a string
1354 *
1355 * @{
1356 */
1358 CC_HINT(nonnull(1,2));
1359
1361 CC_HINT(nonnull);
1362
1363static inline CC_HINT(nonnull(2,3))
1364 fr_slen_t fr_value_box_aprint(TALLOC_CTX *ctx, char **out,
1365 fr_value_box_t const *data, fr_sbuff_escape_rules_t const *e_rules)
1367
1368static inline CC_HINT(nonnull(2,3))
1370 fr_value_box_t const *data, fr_token_t quote)
1372
1373/** @} */
1374/** @name Hashing
1375 *
1376 * @{
1377 */
1379
1380/** @} */
1381
1382#if defined(WITH_VERIFY_PTR) || !defined(NDEBUG)
1383void fr_value_box_verify(char const *file, int line, fr_value_box_t const *vb)
1384 CC_HINT(nonnull(3));
1385void fr_value_box_list_verify(char const *file, int line, fr_value_box_list_t const *list)
1386 CC_HINT(nonnull(3));
1387
1388# define VALUE_BOX_VERIFY(_x) fr_value_box_verify(__FILE__, __LINE__, _x)
1389# define VALUE_BOX_LIST_VERIFY(_x) fr_value_box_list_verify(__FILE__, __LINE__, _x)
1390#else
1391/*
1392 * Even if were building without WITH_VERIFY_PTR
1393 * the pointer must not be NULL when these various macros are used
1394 * so we can add some sneaky asserts.
1395 */
1396# define VALUE_BOX_VERIFY(_x) fr_assert(_x)
1397# define VALUE_BOX_LIST_VERIFY(_x) fr_assert(_x)
1398# define VALUE_BOX_VERIFY(_x) fr_assert(_x)
1399# define VALUE_BOX_LIST_VERIFY(_x) fr_assert(_x)
1400#endif
1401
1402/** @name Debug functions
1403 *
1404 * @{
1405 */
1406void fr_value_box_list_debug(FILE *fp, fr_value_box_list_t const *head);
1407void fr_value_box_debug(FILE *fp, fr_value_box_t const *vb);
1408/** @} */
1409
1410#undef _CONST
1411
1412#ifdef __cplusplus
1413}
1414#endif
int const char * file
Definition acutest.h:855
static int const char * fmt
Definition acutest.h:638
void int line
Definition acutest.h:810
#define UNCONST(_type, _ptr)
Remove const qualification from a pointer.
Definition build.h:203
#define RCSIDH(h, id)
Definition build.h:604
#define unlikely(_x)
Definition build.h:486
#define NDEBUG_LOCATION_VALS
Definition build.h:362
#define NDEBUG_LOCATION_ARGS
Pass caller information to the function.
Definition build.h:361
fr_cmp_ret_t
Result of an ordering comparison.
Definition build.h:113
static size_t min(size_t x, size_t y)
Definition dbuff.c:66
#define FR_DCURSOR_DLIST_TYPES(_name, _list_name, _element_type)
Define type specific wrapper structs for dcursors.
Definition dcursor.h:876
#define FR_DCURSOR_FUNCS(_name, _list_name, _element_type)
Define type specific wrapper functions for dcursors.
Definition dcursor.h:893
#define da_is_bit_field(_da)
Definition dict.h:171
char const * fr_dict_enum_name_by_value(fr_dict_attr_t const *da, fr_value_box_t const *value)
Lookup the name of an enum value in a fr_dict_attr_t.
Definition dict_util.c:3765
Test enumeration values.
Definition dict_test.h:92
#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_TYPEDEFS(_name, _head, _entry)
Define friendly names for type specific dlist head and entry structures.
Definition dlist.h:1160
free(array)
talloc_free(hp)
Struct to represent an ethernet address.
Definition inet.h:45
Struct to represent an interface id.
Definition inet.h:54
IPv4/6 prefix.
unsigned short uint16_t
#define SBUFF_CHAR_CLASS
fr_type_t
@ FR_TYPE_FLOAT32
Single precision floating point.
@ FR_TYPE_IPV4_ADDR
32 Bit IPv4 Address.
@ FR_TYPE_INT8
8 Bit signed integer.
@ FR_TYPE_ETHERNET
48 Bit Mac-Address.
@ FR_TYPE_IPV6_PREFIX
IPv6 Prefix.
@ FR_TYPE_STRING
String of printable characters.
@ FR_TYPE_UINT16
16 Bit unsigned integer.
@ FR_TYPE_INT64
64 Bit signed integer.
@ FR_TYPE_INT16
16 Bit signed integer.
@ FR_TYPE_DATE
Unix time stamp, always has value >2^31.
@ FR_TYPE_COMBO_IP_PREFIX
IPv4 or IPv6 address prefix depending on length.
@ FR_TYPE_UINT8
8 Bit unsigned integer.
@ FR_TYPE_UINT32
32 Bit unsigned integer.
@ FR_TYPE_INT32
32 Bit signed integer.
@ FR_TYPE_UINT64
64 Bit unsigned integer.
@ FR_TYPE_IPV6_ADDR
128 Bit IPv6 Address.
@ FR_TYPE_IPV4_PREFIX
IPv4 Prefix.
@ FR_TYPE_BOOL
A truth value.
@ FR_TYPE_COMBO_IP_ADDR
IPv4 or IPv6 address depending on length.
@ FR_TYPE_GROUP
A grouping of other attributes.
@ FR_TYPE_FLOAT64
Double precision floating point.
unsigned int uint32_t
long int ssize_t
unsigned char bool
fr_sbuff_err_t
unsigned char uint8_t
ssize_t fr_slen_t
static char * secret
static char const * name
#define SBUFF_OUT_TALLOC_FUNC_ERR_LEN_DEF(_func, _in, _max,...)
#define SBUFF_OUT_TALLOC_FUNC_NO_LEN_DEF(_func,...)
Set of parsing rules for *unescape_until functions.
PRIVATE void float64()
fr_aka_sim_id_type_t type
A time delta, a difference in time measured in nanoseconds.
Definition time.h:80
"Unix" time.
Definition time.h:95
enum fr_token fr_token_t
#define T_TOKEN_LAST
Definition token.h:127
static fr_slen_t head
Definition xlat.h:410
#define fr_strerror_printf(_fmt,...)
Log to thread local error buffer.
Definition strerror.h:64
#define FR_TYPE_STRUCTURAL
Definition types.h:316
#define fr_type_is_leaf(_x)
Definition types.h:393
static char const * fr_type_to_str(fr_type_t type)
Return a static string containing the type name.
Definition types.h:454
fr_value_box_list_action_t
Actions to perform when we process a box in a list.
Definition value.h:261
@ FR_VALUE_BOX_LIST_NONE
Do nothing to processed boxes.
Definition value.h:262
@ FR_VALUE_BOX_LIST_REMOVE
Remove the box from the input list.
Definition value.h:263
@ FR_VALUE_BOX_LIST_FREE
Definition value.h:267
@ FR_VALUE_BOX_LIST_FREE_BOX_VALUE
Explicitly free any value buffers associated with a box.
Definition value.h:265
@ FR_VALUE_BOX_LIST_FREE_BOX
Free each processed box.
Definition value.h:264
int fr_value_box_bstrndup_replace(TALLOC_CTX *ctx, fr_value_box_t *vb, char const *src, ssize_t len))
Free the existing buffer (if talloced) associated with the valuebox, and replace it with a copy of a ...
Definition value.c:4848
fr_cmp_ret_t fr_value_box_cmp(fr_value_box_t const *a, fr_value_box_t const *b)
Compare two values.
Definition value.c:770
size_t const fr_value_box_field_sizes[]
How many bytes wide each of the value data fields are.
Definition value.c:162
size_t fr_value_box_network_length(fr_value_box_t const *value)
Get the size of the value held by the fr_value_box_t.
Definition value.c:1431
int fr_value_box_vasprintf(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_dict_attr_t const *enumv, bool tainted, char const *fmt, va_list ap)
void fr_value_box_set_void_shallow(fr_value_box_t *dst, void const *ptr)
Assign a void pointer to a box.
Definition value.c:5324
int(* fr_value_box_escape_func_t)(fr_value_box_t *vb, void *uctx)
Escape a value box.
Definition value.h:702
fr_ifid_t ifid
IPv6 interface ID.
Definition value.h:129
fr_sbuff_unescape_rules_t const fr_value_unescape_single
Definition value.c:301
ssize_t fr_value_box_list_concat_as_octets(fr_value_box_safety_t *safety, fr_dbuff_t *dbuff, fr_value_box_list_t *list, uint8_t const *sep, size_t sep_len, fr_value_box_list_action_t proc_action, bool flatten))
Concatenate a list of value boxes together.
Definition value.c:6632
uint16_t uint16
16bit unsigned integer.
Definition value.h:135
#define DEF_UNBOXING_FUNC(_ctype, _field, _type)
Definition value.h:991
static fr_sbuff_err_t char size_t fr_sbuff_t * in
Definition value.h:1061
uint32_t fr_value_box_hash(fr_value_box_t const *vb)
Hash the contents of a value box.
Definition value.c:7259
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:828
char * fr_value_box_list_aprint_secure(TALLOC_CTX *ctx, fr_value_box_list_t const *list, char const *delim, fr_sbuff_escape_rules_t const *e_rules))
Concatenate the string representations of a list of value boxes together hiding "secret" values.
Definition value.c:7208
int fr_value_box_escape_in_place(fr_value_box_t *vb, fr_value_box_escape_t const *escape, void *uctx))
Escape a single value box in place.
Definition value.c:6911
int8_t int8
8bit signed integer.
Definition value.h:140
fr_value_box_safe_for_t safe_for
A unique value to indicate if that value box is safe for consumption by a particular module for a par...
Definition value.h:187
fr_sbuff_escape_rules_t const fr_value_escape_double
Definition value.c:366
fr_sbuff_parse_rules_t const value_parse_rules_single_3quoted
Definition value.c:594
static fr_slen_t fr_value_box_aprint(TALLOC_CTX *ctx, char **out, fr_value_box_t const *data, fr_sbuff_escape_rules_t const *e_rules) 1(fr_value_box_print
static bool fr_value_box_is_secret(fr_value_box_t const *box)
Definition value.h:1143
fr_sbuff_escape_rules_t const fr_value_escape_backtick
Definition value.c:433
int fr_value_box_escape_erules(fr_value_box_t *vb, void *uctx)
Escape a value-box in place using the supplied fr_sbuff_escape_rules_t in uctx.
Definition value.c:7087
static fr_sbuff_err_t fr_value_str_aunescape(TALLOC_CTX *ctx, char **out, size_t *len, fr_sbuff_t *in, size_t max, char quote) static inline fr_sbuff_err_t fr_value_substr_aunescape(TALLOC_CTX *ctx
#define DEF_BOXING_FUNC(_ctype, _field, _type)
Definition value.h:895
fr_sbuff_escape_rules_t const fr_value_escape_secret
Escape secret fields by simply mashing all data to '.
Definition value.c:395
static fr_sbuff_err_t char size_t fr_sbuff_t size_t max
Definition value.h:1061
int fr_value_box_list_concat_in_place(TALLOC_CTX *ctx, fr_value_box_t *out, fr_value_box_list_t *list, fr_type_t type, fr_value_box_list_action_t proc_action, bool flatten, size_t max_size))
Concatenate a list of value boxes.
Definition value.c:6732
fr_sbuff_parse_rules_t const value_parse_rules_double_unquoted
Definition value.c:498
size_t size
System specific file/memory size.
Definition value.h:153
fr_sbuff_parse_rules_t const value_parse_rules_solidus_quoted
Definition value.c:573
static fr_slen_t data
Definition value.h:1366
int fr_value_box_cast(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_type_t dst_type, fr_dict_attr_t const *dst_enumv, fr_value_box_t const *src))
Convert one type of fr_value_box_t to another.
Definition value.c:4015
fr_sbuff_escape_rules_t const fr_value_escape_unprintables
Definition value.c:469
static bool fr_value_box_contains_secret(fr_value_box_t const *box)
Definition value.h:1149
unsigned int secret
Same as fr_dict_attr_flags_t secret.
Definition value.h:193
fr_value_box_list_t children
for groups
Definition value.h:158
int fr_value_box_copy(TALLOC_CTX *ctx, fr_value_box_t *dst, const fr_value_box_t *src))
Copy value data verbatim duplicating any buffers.
Definition value.c:4465
int fr_value_box_bstrndup_dbuff(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_dict_attr_t const *enumv, fr_dbuff_t *dbuff, size_t len, bool tainted))
Definition value.c:4977
int fr_value_box_asprintf(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_dict_attr_t const *enumv, bool tainted, char const *fmt,...)
int fr_value_box_strdup(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_dict_attr_t const *enumv, char const *src, bool tainted))
Copy a nul terminated string to a fr_value_box_t.
Definition value.c:4702
static bool fr_value_box_list_len_min(fr_value_box_list_t const *list, unsigned int min)
Determines whether a list contains the number of boxes required.
Definition value.h:741
fr_type_t _CONST type
Type and flags should appear together for packing efficiency.
Definition value.h:212
fr_sbuff_parse_rules_t const * value_parse_rules_quoted[T_TOKEN_LAST]
Parse rules for quoted strings.
Definition value.c:620
static fr_value_box_t * fr_value_box_acopy(TALLOC_CTX *ctx, fr_value_box_t const *src)
Copy an existing box, allocating a new box to hold its contents.
Definition value.h:775
fr_dict_attr_t const * da
dictionary reference
Definition value.h:156
static uint8_t * fr_value_box_raw(fr_value_box_t const *vb, fr_type_t type)
Return a pointer to the "raw" value from a value-box.
Definition value.h:804
fr_sbuff_escape_rules_t const fr_value_escape_solidus
Definition value.c:412
float float32
Single precision float.
Definition value.h:145
fr_sbuff_unescape_rules_t const * fr_value_unescape_by_quote[T_TOKEN_LAST]
Definition value.c:352
fr_value_box_safety_t _CONST safety
Safety of the value, see fr_value_box_safety_t.
Definition value.h:234
size_t const fr_value_box_offsets[]
Where the value starts in the fr_value_box_t.
Definition value.c:204
#define FR_VALUE_BOX_MAGIC
Definition value.h:96
int fr_value_box_mem_alloc(TALLOC_CTX *ctx, uint8_t **out, fr_value_box_t *dst, fr_dict_attr_t const *enumv, size_t len, bool tainted))
Pre-allocate an octets buffer for filling by the caller.
Definition value.c:5100
fr_sbuff_parse_rules_t const value_parse_rules_bareword_unquoted
Default formatting rules.
Definition value.c:494
int fr_value_box_escape_in_place_func(TALLOC_CTX *ctx, fr_value_box_t *vb, fr_sbuff_escape_func_t escape)
Escape a value box in place using an sbuff escape function.
Definition value.c:7107
int fr_value_box_strtrim(TALLOC_CTX *ctx, fr_value_box_t *vb))
Trim the length of the string buffer to match the length of the C string.
Definition value.c:4728
int fr_value_box_ipaddr(fr_value_box_t *dst, fr_dict_attr_t const *enumv, fr_ipaddr_t const *ipaddr, bool tainted))
Assign a fr_value_box_t value from an fr_ipaddr_t.
Definition value.c:4349
fr_sbuff_parse_rules_t const value_parse_rules_single_unquoted
Definition value.c:502
int fr_value_box_cmp_op(fr_token_t op, fr_value_box_t const *a, fr_value_box_t const *b)
Compare two attributes using an operator.
Definition value.c:1017
unsigned int immutable
once set, the value cannot be changed
Definition value.h:229
static fr_sbuff_err_t char size_t fr_sbuff_t size_t char quote int fr_value_box_hton(fr_value_box_t *dst, fr_value_box_t const *src)
Performs byte order reversal for types that need it.
Definition value.c:1330
int fr_value_box_memdup_dbuff(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_dict_attr_t const *enumv, fr_dbuff_t *dbuff, size_t len, bool tainted))
Definition value.c:5219
fr_unix_time_t date
Date internal format in nanoseconds.
Definition value.h:148
fr_sbuff_parse_rules_t const * value_parse_rules_unquoted_char[SBUFF_CHAR_CLASS]
Definition value.c:530
static fr_sbuff_err_t char ** out
Definition value.h:1061
uint64_t magic
Value to verify that the structure was allocated or initialised properly.
Definition value.h:215
fr_ipaddr_t ip
IPv4/6 address/prefix.
Definition value.h:127
fr_sbuff_parse_rules_t const value_parse_rules_single_quoted
Definition value.c:567
int32_t int32
32bit signed integer.
Definition value.h:142
int fr_value_box_mem_realloc(TALLOC_CTX *ctx, uint8_t **out, fr_value_box_t *dst, size_t len))
Change the length of a buffer already allocated to a value box.
Definition value.c:5133
static fr_sbuff_err_t char size_t * len
Definition value.h:1061
void fr_value_box_memdup_shallow(fr_value_box_t *dst, fr_dict_attr_t const *enumv, uint8_t const *src, size_t len, bool tainted))
Assign a buffer to a box, but don't copy it.
Definition value.c:5278
ssize_t fr_value_box_list_concat_as_string(fr_value_box_safety_t *safety, fr_sbuff_t *sbuff, fr_value_box_list_t *list, char const *sep, size_t sep_len, fr_sbuff_escape_rules_t const *e_rules, fr_value_box_list_action_t proc_action, fr_value_box_safe_for_t safe_for, bool flatten))
Concatenate a list of value boxes together.
Definition value.c:6515
char const * file
File where the box was allocated or initialised.
Definition value.h:223
void fr_value_box_increment(fr_value_box_t *vb)
Increment a boxed value.
Definition value.c:5370
void fr_value_box_set_attr(fr_value_box_t *dst, fr_dict_attr_t const *da)
Definition value.c:5356
int fr_value_box_memdup(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_dict_attr_t const *enumv, uint8_t const *src, size_t len, bool tainted))
Copy a buffer to a fr_value_box_t.
Definition value.c:5194
void fr_value_box_set_cursor_shallow(fr_value_box_t *dst, fr_type_t type, void *ptr, char const *name)
Definition value.c:5309
fr_sbuff_unescape_rules_t const fr_value_unescape_backtick
Definition value.c:333
void fr_value_box_set_secret(fr_value_box_t *box, bool secret)
Mark a box as holding a secret, or not.
Definition value.c:7577
void fr_value_box_list_verify(char const *file, int line, fr_value_box_list_t const *list))
Definition value.c:7439
fr_value_box_safe_for_t safe_for
Definition value.h:706
fr_sbuff_parse_rules_t const * value_parse_rules_3quoted[T_TOKEN_LAST]
Definition value.c:636
void fr_value_box_flatten(TALLOC_CTX *ctx, fr_value_box_list_t *list, bool steal, bool free))
Removes a single layer of nesting, moving all children into the parent list.
Definition value.c:7133
void fr_value_box_strdup_shallow_replace(fr_value_box_t *vb, char const *src, ssize_t len)
Free the existing buffer (if talloced) associated with the valuebox, and replace it with a new one.
Definition value.c:4828
void fr_value_box_safety_set(fr_value_box_t *box, fr_value_box_safety_t const *safety)
Replace the safety of a box.
Definition value.c:7566
fr_sbuff_unescape_rules_t const fr_value_unescape_double
Definition value.c:282
void _fr_value_box_mark_safe_for(fr_value_box_t *box, fr_value_box_safe_for_t safe_for)
Mark a value-box as "safe", of a particular type.
Definition value.c:7448
void fr_value_box_clear_value(fr_value_box_t *data))
Clear/free any existing value.
Definition value.c:4400
ssize_t fr_value_box_from_network(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_type_t type, fr_dict_attr_t const *enumv, fr_dbuff_t *dbuff, size_t len, bool tainted))
Decode a fr_value_box_t from serialized binary data.
Definition value.c:1942
static int fr_value_box_memcpy_in(fr_value_box_t *vb, void const *in)
Copy a C value value to a value box.
Definition value.h:862
ssize_t fr_value_box_print_quoted(fr_sbuff_t *out, fr_value_box_t const *data, fr_token_t quote)
Print one boxed value to a string with quotes (where needed)
Definition value.c:6472
bool boolean
A truth value.
Definition value.h:132
fr_sbuff_parse_rules_t const value_parse_rules_double_3quoted
Definition value.c:588
static always_inline void _fr_value_box_init(NDEBUG_LOCATION_ARGS fr_value_box_t *vb, fr_type_t type, fr_dict_attr_t const *enumv, bool tainted)
Definition value.h:567
int line
Line where the box was allocated or initialised.
Definition value.h:224
static char const * fr_value_box_enum_name(fr_value_box_t const *box)
Decide if we need an enum prefix.
Definition value.h:1178
bool fr_value_box_list_tainted(fr_value_box_list_t const *head))
Check to see if any list members (or their children) are tainted.
Definition value.c:7324
void fr_value_box_safety_copy_changed(fr_value_box_t *out, fr_value_box_t const *in)
Copy the safety values from one box to another.
Definition value.c:7510
fr_dict_attr_t const * enumv
Enumeration values.
Definition value.h:243
bool fr_value_box_is_truthy(fr_value_box_t const *box))
Check truthiness of values.
Definition value.c:7627
void fr_value_box_verify(char const *file, int line, fr_value_box_t const *vb))
Validation function to check that a fr_value_box_t is correctly initialised.
Definition value.c:7343
uintptr_t fr_value_box_safe_for_t
Escaping that's been applied to a value box.
Definition value.h:167
#define _CONST
Definition value.h:69
void fr_value_box_list_mark_safe_for(fr_value_box_list_t *list, fr_value_box_safe_for_t safe_for)
Set the escaped flag for all value boxes in a list.
Definition value.c:7479
int fr_value_unbox_ipaddr(fr_ipaddr_t *dst, fr_value_box_t *src)
Unbox an IP address performing a type check.
Definition value.c:4381
fr_slen_t fr_value_box_from_str(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_type_t dst_type, fr_dict_attr_t const *dst_enumv, char const *in, size_t inlen, fr_sbuff_unescape_rules_t const *erules))
Definition value.c:6195
int fr_value_box_cast_in_place(TALLOC_CTX *ctx, fr_value_box_t *vb, fr_type_t dst_type, fr_dict_attr_t const *dst_enumv))
Convert one type of fr_value_box_t to another in place.
Definition value.c:4265
int fr_value_box_escape_in_place_erules(TALLOC_CTX *ctx, fr_value_box_t *vb, fr_sbuff_escape_rules_t const *erules)
Escape a value-box in place using sbuff escaping rules, and mark it safe-for.
Definition value.c:7021
fr_sbuff_parse_rules_t const value_parse_rules_bareword_quoted
Definition value.c:538
void fr_value_box_safety_merge(fr_value_box_t *out, fr_value_box_t const *in)
Merge safety results.
Definition value.c:7555
fr_sbuff_parse_rules_t const value_parse_rules_backtick_3quoted
Definition value.c:606
fr_sbuff_escape_rules_t const fr_value_escape_single
Definition value.c:402
fr_value_box_entry_t entry
Doubly linked list entry.
Definition value.h:241
int fr_value_box_list_escape_in_place(fr_value_box_list_t *list, fr_value_box_escape_t const *escape, void *uctx))
Escape a list of value boxes in place.
Definition value.c:6967
fr_ethernet_t ether
Ethernet (MAC) address.
Definition value.h:130
void fr_value_box_list_debug(FILE *fp, fr_value_box_list_t const *head)
Print a list of value boxes as info messages.
Definition value.c:7687
fr_sbuff_parse_rules_t const * value_parse_rules_quoted_char[SBUFF_CHAR_CLASS]
Definition value.c:628
fr_sbuff_parse_rules_t const value_parse_rules_solidus_unquoted
Definition value.c:506
uint64_t fr_value_box_as_uint64(fr_value_box_t const *src)
Return a uint64_t from a fr_value_box_t.
Definition value.c:4315
fr_sbuff_parse_rules_t const value_parse_rules_backtick_quoted
Definition value.c:579
fr_value_box_datum_t datum
The value held by the value box.
Definition value.h:245
fr_sbuff_parse_rules_t const * value_parse_rules_unquoted[T_TOKEN_LAST]
Parse rules for non-quoted strings.
Definition value.c:522
unsigned int talloced
Talloced, not stack or text allocated.
Definition value.h:230
double float64
Double precision float.
Definition value.h:146
int nonnull(2, 5))
#define fr_value_box_alloc_null(_ctx)
Allocate a value box for later use with a value assignment function.
Definition value.h:679
uint64_t uint64
64bit unsigned integer.
Definition value.h:137
void fr_value_box_strdup_shallow(fr_value_box_t *dst, fr_dict_attr_t const *enumv, char const *src, bool tainted))
Assign a buffer containing a nul terminated string to a box, but don't copy it.
Definition value.c:4812
int fr_value_box_bstrdup_buffer(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_dict_attr_t const *enumv, char const *src, bool tainted))
Copy a nul terminated talloced buffer to a fr_value_box_t.
Definition value.c:5016
int fr_value_box_bstrdup_buffer_shallow(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_dict_attr_t const *enumv, char const *src, bool tainted))
Assign a talloced buffer containing a nul terminated string to a box, but don't copy it.
Definition value.c:5061
static fr_slen_t static e_rules fr_slen_t fr_value_box_aprint_quoted(TALLOC_CTX *ctx, char **out, fr_value_box_t const *data, fr_token_t quote) 1(fr_value_box_print_quoted
void fr_value_box_safety_copy(fr_value_box_t *out, fr_value_box_t const *in)
Copy the safety values from one box to another.
Definition value.c:7497
unsigned int tainted
i.e. did it come from an untrusted source
Definition value.h:228
fr_sbuff_parse_rules_t const value_parse_rules_backtick_unquoted
Definition value.c:510
fr_sbuff_parse_rules_t const value_parse_rules_double_quoted
Definition value.c:561
void fr_value_box_memdup_buffer_shallow(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_dict_attr_t const *enumv, uint8_t const *src, bool tainted))
Assign a talloced buffer to a box, but don't copy it.
Definition value.c:5296
fr_sbuff_parse_rules_t const value_parse_rules_solidus_3quoted
Definition value.c:600
uint32_t uint32
32bit unsigned integer.
Definition value.h:136
int fr_value_box_bstr_realloc(TALLOC_CTX *ctx, char **out, fr_value_box_t *dst, size_t len))
Change the length of a buffer already allocated to a value box.
Definition value.c:4912
unsigned int edit
to control foreach / edits
Definition value.h:232
fr_sbuff_err_t fr_value_str_unescape(size_t *len, fr_sbuff_t *out, fr_sbuff_t *in, size_t max, char quote))
Convert a string value with escape sequences into its binary form.
Definition value.c:1232
uint128_t uint128
128bit unsigned integer.
Definition value.h:138
int fr_value_box_to_key(uint8_t **out, size_t *outlen, fr_value_box_t const *value)
Get a key from a value box.
Definition value.c:2534
fr_value_box_escape_func_t func
Definition value.h:705
void fr_value_box_bstrndup_shallow(fr_value_box_t *dst, fr_dict_attr_t const *enumv, char const *src, size_t len, bool tainted))
Assign a string to to a fr_value_box_t.
Definition value.c:5040
int16_t int16
16bit signed integer.
Definition value.h:141
ssize_t fr_value_box_from_memory(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_type_t type, fr_dict_attr_t const *enumv, void const *src, size_t len))
Decode a fr_value_box_t from a C type in memory.
Definition value.c:2467
int fr_value_box_bstrndup(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_dict_attr_t const *enumv, char const *src, size_t len, bool tainted))
Copy a string to to a fr_value_box_t.
Definition value.c:4953
ssize_t fr_value_box_to_network(fr_dbuff_t *dbuff, fr_value_box_t const *value)
Encode a single value box, serializing its contents in generic network format.
Definition value.c:1534
void fr_value_box_list_safety_merge(fr_value_box_t *out, fr_value_box_list_t const *list)
Set the safety of out to the most restrictive safety of any leaf box in a list.
Definition value.c:7610
unsigned int verified
whether this value has been verified
Definition value.h:225
void fr_value_box_copy_shallow(TALLOC_CTX *ctx, fr_value_box_t *dst, const fr_value_box_t *src))
Perform a shallow copy of a value_box.
Definition value.c:4591
static always_inline int fr_value_box_ethernet_addr(fr_value_box_t *dst, fr_dict_attr_t const *enumv, fr_ethernet_t const *src, bool tainted)
Definition value.h:887
fr_sbuff_unescape_rules_t const * fr_value_unescape_by_char[SBUFF_CHAR_CLASS]
Definition value.c:359
void fr_value_box_debug(FILE *fp, fr_value_box_t const *vb)
Print the value of a box as info messages.
Definition value.c:7734
fr_slen_t fr_value_box_from_substr(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_type_t dst_type, fr_dict_attr_t const *dst_enumv, fr_sbuff_t *in, fr_sbuff_parse_rules_t const *rules))
Convert string value to a fr_value_box_t type.
Definition value.c:5523
char * fr_value_box_list_aprint(TALLOC_CTX *ctx, fr_value_box_list_t const *list, char const *delim, fr_sbuff_escape_rules_t const *e_rules))
Concatenate the string representations of a list of value boxes together.
Definition value.c:7158
static fr_value_box_t * _fr_value_box_alloc(NDEBUG_LOCATION_ARGS TALLOC_CTX *ctx, fr_type_t type, fr_dict_attr_t const *enumv)
Definition value.h:643
static int fr_value_unbox_ethernet_addr(fr_ethernet_t *dst, fr_value_box_t *src)
Unbox an ethernet value (6 bytes, network byte order)
Definition value.h:979
fr_sbuff_unescape_rules_t const fr_value_unescape_solidus
Definition value.c:312
#define fr_value_box_init(_vb, _type, _enumv, _tainted)
Initialise a fr_value_box_t.
Definition value.h:634
void fr_value_box_clear(fr_value_box_t *data))
Clear/free any existing value and metadata.
Definition value.c:4448
fr_sbuff_escape_rules_t const * fr_value_escape_by_quote[T_TOKEN_LAST]
Definition value.c:455
ssize_t fr_value_box_ipaddr_from_network(fr_value_box_t *dst, fr_type_t type, fr_dict_attr_t const *enumv, int prefix_len, uint8_t const *data, size_t data_len, bool fixed, bool tainted))
Decode a fr_value_box_t of type IP address / prefix.
Definition value.c:2346
void fr_value_box_mark_unsafe(fr_value_box_t *box)
Mark a value-box as "unsafe".
Definition value.c:7467
uint8_t uint8
8bit unsigned integer.
Definition value.h:134
int fr_value_box_memdup_buffer(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_dict_attr_t const *enumv, uint8_t const *src, bool tainted))
Copy a talloced buffer to a fr_value_box_t.
Definition value.c:5256
int format(printf, 5, 0))
fr_sbuff_err_t fr_value_substr_unescape(size_t *len, fr_sbuff_t *out, fr_sbuff_t *in, size_t max, char quote))
Convert a string value with escape sequences into its binary form.
Definition value.c:1300
int fr_value_box_list_acopy(TALLOC_CTX *ctx, fr_value_box_list_t *out, fr_value_box_list_t const *in))
Do a full copy of a list of value boxes.
Definition value.c:7296
fr_sbuff_escape_rules_t const * fr_value_escape_by_char[SBUFF_CHAR_CLASS]
Definition value.c:462
ssize_t fr_value_box_print(fr_sbuff_t *out, fr_value_box_t const *data, fr_sbuff_escape_rules_t const *e_rules))
Print one boxed value to a string.
Definition value.c:6232
int fr_value_box_bstr_alloc(TALLOC_CTX *ctx, char **out, fr_value_box_t *dst, fr_dict_attr_t const *enumv, size_t len, bool tainted))
Alloc and assign an empty \0 terminated string to a fr_value_box_t.
Definition value.c:4879
fr_time_delta_t time_delta
a delta time in nanoseconds
Definition value.h:154
int64_t int64
64bit signed integer;
Definition value.h:143
int fr_value_box_steal(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_value_box_t *src))
Copy value data verbatim moving any buffers to the specified context.
Definition value.c:4627
The safety of a value.
Definition value.h:186
Union containing all data types supported by the server.
Definition value.h:209