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