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