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