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