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