The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Macros | Functions | Variables
value.c File Reference

Boxed value structures and functions to manipulate them. More...

#include <freeradius-devel/util/value.h>
#include <freeradius-devel/util/atexit.h>
#include <freeradius-devel/util/base16.h>
#include <freeradius-devel/util/dcursor.h>
#include <freeradius-devel/util/size.h>
#include <freeradius-devel/util/time.h>
#include <math.h>
+ Include dependency graph for value.c:

Go to the source code of this file.

Macros

#define _VALUE_PRIVATE
 
#define CAST_IP_FIX_COMBO
 
#define COMPARE(_type)   return CMP(memcmp(&a->datum._type, &b->datum._type, sizeof(a->datum._type)), 0)
 
#define INFO_INDENT(_fmt, ...)   FR_FAULT_LOG("%*s"_fmt, depth * 2, " ", ## __VA_ARGS__)
 
#define network_max_size(_x)   (fr_value_box_network_sizes[_x][1])
 
#define network_min_size(_x)   (fr_value_box_network_sizes[_x][0])
 Sanity checks. More...
 
#define RETURN(_type)   return CMP(a->datum._type, b->datum._type)
 
#define SIGN_BIT_HIGH(_int, _len)   ((((uint64_t)1) << (((_len) << 3) - 1)) & (_int))
 
#define SIGN_PROMOTE(_int, _len)
 

Functions

static void _fr_value_box_debug (fr_value_box_t const *vb, int depth, int idx)
 
static void _fr_value_box_list_debug (fr_value_box_list_t const *head, int depth)
 
void _fr_value_box_mark_safe_for (fr_value_box_t *vb, fr_value_box_safe_for_t safe_for)
 Mark a value-box as "safe", of a particular type. More...
 
return fr_dbuff_set (dbuff, &our_dbuff)
 
int fr_regex_cmp_op (fr_token_t op, fr_value_box_t const *a, fr_value_box_t const *b)
 Compare two boxes using an operator. More...
 
 FR_SBUFF_SET_RETURN (sbuff, &our_sbuff)
 
int fr_value_box_asprintf (TALLOC_CTX *ctx, fr_value_box_t *dst, fr_dict_attr_t const *enumv, bool tainted, char const *fmt,...)
 Print a formatted string using our internal printf wrapper and assign it to a value box. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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)
 
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. More...
 
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. More...
 
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. More...
 
static int fr_value_box_cast_integer_to_integer (UNUSED 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 any signed or unsigned integer type to any other signed or unsigned integer type. More...
 
static int fr_value_box_cast_to_bool (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 any supported type to a bool. More...
 
static int fr_value_box_cast_to_ethernet (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 any supported type to an ethernet address. More...
 
static int fr_value_box_cast_to_float (UNUSED 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 any value to a floating point value. More...
 
static int fr_value_box_cast_to_integer (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 any value to a signed or unsigned integer. More...
 
static int fr_value_box_cast_to_ipv4addr (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 any supported type to an IPv4 address. More...
 
static int fr_value_box_cast_to_ipv4prefix (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 any supported type to an IPv6 address. More...
 
static int fr_value_box_cast_to_ipv6addr (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 any supported type to an IPv6 address. More...
 
static int fr_value_box_cast_to_ipv6prefix (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 any supported type to an IPv6 address. More...
 
static int fr_value_box_cast_to_octets (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 any supported type to octets. More...
 
static int fr_value_box_cast_to_strvalue (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 any supported type to a string. More...
 
static int fr_value_box_cidr_cmp_op (fr_token_t op, int bytes, uint8_t a_net, uint8_t const *a, uint8_t b_net, uint8_t const *b)
 
void fr_value_box_clear (fr_value_box_t *data)
 Clear/free any existing value and metadata. More...
 
void fr_value_box_clear_value (fr_value_box_t *data)
 Clear/free any existing value. More...
 
int8_t fr_value_box_cmp (fr_value_box_t const *a, fr_value_box_t const *b)
 Compare two values. More...
 
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. More...
 
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. More...
 
static void fr_value_box_copy_meta (fr_value_box_t *dst, fr_value_box_t const *src)
 Copy flags and type data from one value box to another. More...
 
void fr_value_box_copy_shallow (TALLOC_CTX *ctx, fr_value_box_t *dst, fr_value_box_t const *src)
 Perform a shallow copy of a value_box. More...
 
void fr_value_box_debug (fr_value_box_t const *vb)
 Print the value of a box as info messages. More...
 
int fr_value_box_escape_in_place (fr_value_box_t *vb, fr_value_box_escape_t escape, fr_value_box_safe_for_t safe_for, void *uctx)
 Escape a single value box in place. More...
 
static int fr_value_box_fixed_size_from_octets (fr_value_box_t *dst, fr_type_t dst_type, fr_dict_attr_t const *dst_enumv, fr_value_box_t const *src)
 Convert octets to a fixed size value box value. More...
 
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. More...
 
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. More...
 
static fr_slen_t fr_value_box_from_numeric_substr (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 integer encoded as string to a fr_value_box_t type. More...
 
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)
 
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. More...
 
uint32_t fr_value_box_hash (fr_value_box_t const *vb)
 Hash the contents of a value box. More...
 
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. More...
 
void fr_value_box_increment (fr_value_box_t *vb)
 Increment a boxed value. More...
 
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. More...
 
bool fr_value_box_is_truthy (fr_value_box_t const *in)
 Check truthiness of values. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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, fr_value_box_safe_for_t safe_for, bool flatten)
 Concatenate a list of value boxes together. More...
 
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. More...
 
void fr_value_box_list_debug (fr_value_box_list_t const *head)
 Print a list of value boxes as info messages. More...
 
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 safe_for, void *uctx)
 Escape a list of value boxes in place. More...
 
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. More...
 
void fr_value_box_list_taint (fr_value_box_list_t *head)
 Taint every list member (and their children) More...
 
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. More...
 
void fr_value_box_list_untaint (fr_value_box_list_t *head)
 Untaint every list member (and their children) More...
 
void fr_value_box_list_verify (char const *file, int line, fr_value_box_list_t const *list)
 
void fr_value_box_mark_unsafe (fr_value_box_t *vb)
 Mark a value-box as "unsafe". More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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)
 
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. More...
 
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. More...
 
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. More...
 
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) More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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)
 Print a formatted string using our internal printf wrapper and assign it to a value box. More...
 
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. More...
 
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. More...
 
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. More...
 
int fr_value_unbox_ipaddr (fr_ipaddr_t *dst, fr_value_box_t *src)
 Unbox an IP address performing a type check. More...
 

Variables

size_t const fr_value_box_field_sizes []
 How many bytes wide each of the value data fields are. More...
 
static uint64_t const fr_value_box_integer_max []
 
static int64_t const fr_value_box_integer_min []
 
static size_t const fr_value_box_network_sizes [FR_TYPE_MAX+1][2]
 
size_t const fr_value_box_offsets []
 Where the value starts in the fr_value_box_t. More...
 
fr_sbuff_escape_rules_t fr_value_escape_backtick
 
fr_sbuff_escape_rules_tfr_value_escape_by_char [UINT8_MAX+1]
 
fr_sbuff_escape_rules_tfr_value_escape_by_quote [T_TOKEN_LAST]
 
fr_sbuff_escape_rules_t fr_value_escape_double
 
fr_sbuff_escape_rules_t fr_value_escape_secret
 Escape secret fields by simply mashing all data to '. More...
 
fr_sbuff_escape_rules_t fr_value_escape_single
 
fr_sbuff_escape_rules_t fr_value_escape_solidus
 
fr_sbuff_escape_rules_t fr_value_escape_unprintables
 
fr_sbuff_unescape_rules_t fr_value_unescape_backtick
 
fr_sbuff_unescape_rules_tfr_value_unescape_by_char [UINT8_MAX+1]
 
fr_sbuff_unescape_rules_tfr_value_unescape_by_quote [T_TOKEN_LAST]
 
fr_sbuff_unescape_rules_t fr_value_unescape_double
 
fr_sbuff_unescape_rules_t fr_value_unescape_single
 
fr_sbuff_unescape_rules_t fr_value_unescape_solidus
 
static uint8_t const v4_v6_map []
 v4 to v6 mapping prefix More...
 

Produce a #tmpl_t from a string or substring

fr_sbuff_parse_rules_t const * value_parse_rules_3quoted [T_TOKEN_LAST]
 
fr_sbuff_parse_rules_t const value_parse_rules_backtick_3quoted
 
fr_sbuff_parse_rules_t const value_parse_rules_backtick_quoted
 
fr_sbuff_parse_rules_t const value_parse_rules_backtick_unquoted
 
fr_sbuff_parse_rules_t const value_parse_rules_bareword_quoted
 
fr_sbuff_parse_rules_t const value_parse_rules_bareword_unquoted
 Default formatting rules. More...
 
fr_sbuff_parse_rules_t const value_parse_rules_double_3quoted
 
fr_sbuff_parse_rules_t const value_parse_rules_double_quoted
 
fr_sbuff_parse_rules_t const value_parse_rules_double_unquoted
 
fr_sbuff_parse_rules_t const * value_parse_rules_quoted [T_TOKEN_LAST]
 Parse rules for quoted strings. More...
 
fr_sbuff_parse_rules_t const * value_parse_rules_quoted_char [UINT8_MAX]
 
fr_sbuff_parse_rules_t const value_parse_rules_single_3quoted
 
fr_sbuff_parse_rules_t const value_parse_rules_single_quoted
 
fr_sbuff_parse_rules_t const value_parse_rules_single_unquoted
 
fr_sbuff_parse_rules_t const value_parse_rules_solidus_3quoted
 
fr_sbuff_parse_rules_t const value_parse_rules_solidus_quoted
 
fr_sbuff_parse_rules_t const value_parse_rules_solidus_unquoted
 
fr_sbuff_parse_rules_t const * value_parse_rules_unquoted [T_TOKEN_LAST]
 Parse rules for non-quoted strings. More...
 
fr_sbuff_parse_rules_t const * value_parse_rules_unquoted_char [UINT8_MAX]
 

Detailed Description

Boxed value structures and functions to manipulate them.

There are three notional data formats used in the server:

Definition in file value.c.

Macro Definition Documentation

◆ _VALUE_PRIVATE

#define _VALUE_PRIVATE

Definition at line 47 of file value.c.

◆ CAST_IP_FIX_COMBO

#define CAST_IP_FIX_COMBO
Value:
if (src->vb_ip.af == AF_INET) { \
src_type = FR_TYPE_IPV4_ADDR; \
} else if (src->vb_ip.af == AF_INET6) { \
src_type = FR_TYPE_IPV6_ADDR; \
} \
break; \
if (src->vb_ip.af == AF_INET) { \
src_type = FR_TYPE_IPV4_PREFIX; \
} else if (src->vb_ip.af == AF_INET6) { \
src_type = FR_TYPE_IPV6_PREFIX; \
} \
break
@ FR_TYPE_IPV4_ADDR
32 Bit IPv4 Address.
Definition: merged_model.c:86
@ FR_TYPE_IPV6_PREFIX
IPv6 Prefix.
Definition: merged_model.c:89
@ FR_TYPE_COMBO_IP_PREFIX
IPv4 or IPv6 address prefix depending on length.
Definition: merged_model.c:92
@ 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_COMBO_IP_ADDR
IPv4 or IPv6 address depending on length.
Definition: merged_model.c:91

Definition at line 2346 of file value.c.

◆ COMPARE

#define COMPARE (   _type)    return CMP(memcmp(&a->datum._type, &b->datum._type, sizeof(a->datum._type)), 0)

◆ INFO_INDENT

#define INFO_INDENT (   _fmt,
  ... 
)    FR_FAULT_LOG("%*s"_fmt, depth * 2, " ", ## __VA_ARGS__)

Definition at line 6360 of file value.c.

◆ network_max_size

#define network_max_size (   _x)    (fr_value_box_network_sizes[_x][1])

Definition at line 108 of file value.c.

◆ network_min_size

#define network_min_size (   _x)    (fr_value_box_network_sizes[_x][0])

Sanity checks.

There should never be an instance where these fail. How many bytes on-the-wire would a fr_value_box_t value consume

This is for the generic NETWORK format. For field sizes in the in-memory structure use fr_value_box_field_sizes.

Note
Don't use this array directly when determining the length that would be consumed by the on-the-wire representation. Use fr_value_box_network_length instead, as that deals with variable length attributes too.

Definition at line 107 of file value.c.

◆ RETURN

#define RETURN (   _type)    return CMP(a->datum._type, b->datum._type)

◆ SIGN_BIT_HIGH

#define SIGN_BIT_HIGH (   _int,
  _len 
)    ((((uint64_t)1) << (((_len) << 3) - 1)) & (_int))

◆ SIGN_PROMOTE

#define SIGN_PROMOTE (   _int,
  _len 
)
Value:
((_len) < sizeof(_int) ? \
(_int) | (~((__typeof__(_int))0)) << ((_len) << 3) : (_int))

Function Documentation

◆ _fr_value_box_debug()

static void _fr_value_box_debug ( fr_value_box_t const *  vb,
int  depth,
int  idx 
)
static

Definition at line 6381 of file value.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _fr_value_box_list_debug()

static void _fr_value_box_list_debug ( fr_value_box_list_t const *  head,
int  depth 
)
static

Definition at line 6363 of file value.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _fr_value_box_mark_safe_for()

void _fr_value_box_mark_safe_for ( fr_value_box_t vb,
fr_value_box_safe_for_t  safe_for 
)

Mark a value-box as "safe", of a particular type.

Definition at line 6292 of file value.c.

◆ fr_dbuff_set()

return fr_dbuff_set ( dbuff  ,
our_dbuff 
)

◆ fr_regex_cmp_op()

int fr_regex_cmp_op ( fr_token_t  op,
fr_value_box_t const *  a,
fr_value_box_t const *  b 
)

Compare two boxes using an operator.

Todo:
  • allow /foo/i on the RHS

However, this involves allocating intermediate sbuffs for the unescaped RHS, and all kinds of extra work. It's not overly hard, but it's something we wish to avoid for now.

Parameters
[in]opto use in comparison. MUST be T_OP_REG_EQ or T_OP_REG_NE
[in]aValue to compare, MUST be FR_TYPE_STRING
[in]buncompiled regex as FR_TYPE_STRING
Returns
  • 1 if true
  • 0 if false
  • -1 on failure.

Definition at line 1360 of file regex.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ FR_SBUFF_SET_RETURN()

FR_SBUFF_SET_RETURN ( sbuff  ,
our_sbuff 
)

◆ fr_value_box_asprintf()

int fr_value_box_asprintf ( TALLOC_CTX *  ctx,
fr_value_box_t dst,
fr_dict_attr_t const *  enumv,
bool  tainted,
char const *  fmt,
  ... 
)

Print a formatted string using our internal printf wrapper and assign it to a value box.

Parameters
[in]ctxto allocate any new buffers in.
[in]dstto assign new buffer to.
[in]enumvAliases for values.
[in]taintedWhether the value came from a trusted source.
[in]fmtThe printf format string to process.
[in]...Substitution arguments.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 4014 of file value.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_value_box_bstr_alloc()

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.

Parameters
[in]ctxto allocate any new buffers in.
[out]outif non-null where to write a pointer to the new buffer.
[in]dstto assign new buffer to.
[in]enumvAliases for values.
[in]lenof buffer to allocate.
[in]taintedWhether the value came from a trusted source.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 4071 of file value.c.

+ Here is the caller graph for this function:

◆ fr_value_box_bstr_append_buffer()

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.

Parameters
[in]ctxWhere to allocate any talloc buffers required.
[in]dstvalue box to append to.
[in]srcstring data to append.
[in]taintedWhether src is tainted.
Returns
  • 0 on success.
    • -1 on failure.

Definition at line 4337 of file value.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_value_box_bstr_realloc()

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.

Note
Do not use on an uninitialised box.
Parameters
[in]ctxto realloc buffer in.
[out]outif non-null where to write a pointer to the new buffer.
[in]dstto realloc buffer for.
[in]lento realloc to (don't include nul byte).
Returns
  • 0 on success.
    • -1 on failure.

Definition at line 4104 of file value.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_value_box_bstrdup_buffer()

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.

Copy a talloced nul terminated buffer, setting fields in the dst value box appropriately.

The buffer must be \0 terminated, or an error will be returned.

Parameters
[in]ctxto allocate any new buffers in.
[in]dstto assign new buffer to.
[in]enumvAliases for values.
[in]srca talloced nul terminated buffer.
[in]taintedWhether the value came from a trusted source.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 4208 of file value.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_value_box_bstrdup_buffer_shallow()

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.

Adds a reference to the src buffer so that it cannot be freed until the ctx is freed.

Parameters
[in]ctxto add reference from. If NULL no reference will be added.
[in]dstto assign string to.
[in]enumvAliases for values.
[in]srcto copy string from.
[in]taintedWhether the value came from a trusted source.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 4253 of file value.c.

+ Here is the caller graph for this function:

◆ fr_value_box_bstrn_append()

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.

Parameters
[in]ctxWhere to allocate any talloc buffers required.
[in]dstvalue box to append to.
[in]srcoctets data to append.
[in]lenlength of octets data.
[in]taintedWhether src is tainted.
Returns
  • 0 on success.
    • -1 on failure.

Definition at line 4284 of file value.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_value_box_bstrndup()

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.

Parameters
[in]ctxto allocate any new buffers in.
[in]dstto assign buffer to.
[in]enumvAliases for values.
[in]srca string. May be NULL only if len == 0.
[in]lenof src.
[in]taintedWhether the value came from a trusted source.

Definition at line 4148 of file value.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_value_box_bstrndup_dbuff()

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 at line 4172 of file value.c.

+ Here is the caller graph for this function:

◆ fr_value_box_bstrndup_shallow()

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.

Parameters
[in]dstto assign new buffer to.
[in]enumvAliases for values.
[in]srca string.
[in]lenof src.
[in]taintedWhether the value came from a trusted source.

Definition at line 4232 of file value.c.

+ Here is the caller graph for this function:

◆ fr_value_box_cast()

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.

This should be the canonical function used to convert between INTERNAL data formats.

If you want to convert from PRESENTATION format, use fr_value_box_from_substr.

Note
src and dst must not be the same box. We do not support casting in place.
Parameters
ctxto allocate buffers in (usually the same as dst)
dstWhere to write result of casting.
dst_typeto cast to.
dst_enumvAliases for values contained within this fr_value_box_t. If fr_value_box_t is passed to fr_value_box_aprint names will be printed instead of actual value.
srcInput data.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 3352 of file value.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_value_box_cast_in_place()

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.

This should be the canonical function used to convert between INTERNAL data formats.

If you want to convert from PRESENTATION format, use fr_value_box_from_substr.

Parameters
ctxto allocate buffers in (usually the same as dst)
vbto cast.
dst_typeto cast to.
dst_enumvAliases for values contained within this fr_value_box_t. If fr_value_box_t is passed to fr_value_box_aprint names will be printed instead of actual value.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 3572 of file value.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_value_box_cast_integer_to_integer()

static int fr_value_box_cast_integer_to_integer ( UNUSED 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 
)
inlinestatic

Convert any signed or unsigned integer type to any other signed or unsigned integer type.

Definition at line 2974 of file value.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_value_box_cast_to_bool()

static int fr_value_box_cast_to_bool ( 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 
)
inlinestatic

Convert any supported type to a bool.

Allowed input types are:

  • FR_TYPE_STRING ("yes", "true", "no", "false")
Parameters
ctxunused.
dstWhere to write result of casting.
dst_typeto cast to.
dst_enumvenumeration values.
srcInput data.

Definition at line 2885 of file value.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_value_box_cast_to_ethernet()

static int fr_value_box_cast_to_ethernet ( 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 
)
inlinestatic

Convert any supported type to an ethernet address.

Allowed input types are:

  • FR_TYPE_STRING ("00:11:22:33:44:55")
  • FR_TYPE_OCTETS (0x001122334455)
Parameters
ctxunused.
dstWhere to write result of casting.
dst_typeto cast to.
dst_enumvenumeration values.
srcInput data.

Definition at line 2825 of file value.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_value_box_cast_to_float()

static int fr_value_box_cast_to_float ( UNUSED 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 
)
inlinestatic

Convert any value to a floating point value.

Parameters
ctxunused.
dstWhere to write result of casting.
dst_typeto cast to.
dst_enumvenumeration values.
srcInput data.

Definition at line 3230 of file value.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_value_box_cast_to_integer()

static int fr_value_box_cast_to_integer ( 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 
)
inlinestatic

Convert any value to a signed or unsigned integer.

Parameters
ctxunused.
dstWhere to write result of casting.
dst_typeto cast to.
dst_enumvenumeration values.
srcInput data.

Definition at line 3129 of file value.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_value_box_cast_to_ipv4addr()

static int fr_value_box_cast_to_ipv4addr ( 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 
)
inlinestatic

Convert any supported type to an IPv4 address.

Allowed input types are:

  • FR_TYPE_IPV6_ADDR (with v4 prefix).
  • FR_TYPE_IPV4_PREFIX (with 32bit mask).
  • FR_TYPE_IPV6_PREFIX (with v4 prefix and 128bit mask).
  • FR_TYPE_OCTETS (of length 4).
  • FR_TYPE_UINT32
Parameters
ctxunused.
dstWhere to write result of casting.
dst_typeto cast to.
dst_enumvenumeration values.
srcInput data.

Definition at line 2378 of file value.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_value_box_cast_to_ipv4prefix()

static int fr_value_box_cast_to_ipv4prefix ( 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 
)
inlinestatic

Convert any supported type to an IPv6 address.

Allowed input types are:

  • FR_TYPE_IPV4_ADDR
  • FR_TYPE_IPV4_PREFIX (with 32bit mask).
  • FR_TYPE_IPV6_PREFIX (with 128bit mask).
  • FR_TYPE_OCTETS (of length 16).
Parameters
ctxunused.
dstWhere to write result of casting.
dst_typeto cast to.
dst_enumvenumeration values.
srcInput data.

Definition at line 2494 of file value.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_value_box_cast_to_ipv6addr()

static int fr_value_box_cast_to_ipv6addr ( 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 
)
inlinestatic

Convert any supported type to an IPv6 address.

Allowed input types are:

  • FR_TYPE_IPV4_ADDR
  • FR_TYPE_IPV4_PREFIX (with 32bit mask).
  • FR_TYPE_IPV6_PREFIX (with 128bit mask).
  • FR_TYPE_OCTETS (of length 16).
Parameters
ctxunused.
dstWhere to write result of casting.
dst_typeto cast to.
dst_enumvenumeration values.
srcInput data.

Definition at line 2610 of file value.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_value_box_cast_to_ipv6prefix()

static int fr_value_box_cast_to_ipv6prefix ( 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 
)
inlinestatic

Convert any supported type to an IPv6 address.

Allowed input types are:

  • FR_TYPE_IPV4_ADDR
  • FR_TYPE_IPV4_PREFIX (with 32bit mask).
  • FR_TYPE_IPV6_PREFIX (with 128bit mask).
  • FR_TYPE_OCTETS (of length 16).
Parameters
ctxunused.
dstWhere to write result of casting.
dst_typeto cast to.
dst_enumvenumeration values.
srcInput data.

Definition at line 2725 of file value.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_value_box_cast_to_octets()

static int fr_value_box_cast_to_octets ( 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 
)
inlinestatic

Convert any supported type to octets.

All non-structural types are allowed.

Parameters
ctxunused.
dstWhere to write result of casting.
dst_typeto cast to.
dst_enumvenumeration values.
srcInput data.

Definition at line 2256 of file value.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_value_box_cast_to_strvalue()

static int fr_value_box_cast_to_strvalue ( 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 
)
inlinestatic

Convert any supported type to a string.

All non-structural types are allowed.

Parameters
ctxunused.
dstWhere to write result of casting.
dst_typeto cast to.
dst_enumvenumeration values.
srcInput data.

Definition at line 2209 of file value.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_value_box_cidr_cmp_op()

static int fr_value_box_cidr_cmp_op ( fr_token_t  op,
int  bytes,
uint8_t  a_net,
uint8_t const *  a,
uint8_t  b_net,
uint8_t const *  b 
)
static

Definition at line 807 of file value.c.

+ Here is the caller graph for this function:

◆ fr_value_box_clear()

void fr_value_box_clear ( fr_value_box_t data)

Clear/free any existing value and metadata.

Note
Do not use on uninitialised memory.
Parameters
[in]datato clear.

Definition at line 3723 of file value.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_value_box_clear_value()

void fr_value_box_clear_value ( fr_value_box_t data)

Clear/free any existing value.

Note
Do not use on uninitialised memory.
Parameters
[in]datato clear.

Definition at line 3681 of file value.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_value_box_cmp()

int8_t fr_value_box_cmp ( fr_value_box_t const *  a,
fr_value_box_t const *  b 
)

Compare two values.

Parameters
[in]aValue to compare.
[in]bValue to compare.
Returns
  • -1 if a is less than b.
  • 0 if both are equal.
  • 1 if a is more than b.
  • < -1 on failure.

Definition at line 676 of file value.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_value_box_cmp_op()

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.

Parameters
[in]opto use in comparison.
[in]aValue to compare.
[in]bValue to compare.
Returns
  • 1 if true
  • 0 if false
  • -1 on failure.

Definition at line 929 of file value.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_value_box_copy()

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.

Note
Will free any exiting buffers associated with the dst fr_value_box_t.
Parameters
ctxTo allocate buffers in.
dstWhere to copy value_box to.
srcWhere to copy value_box from.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 3740 of file value.c.

+ Here is the call graph for this function:

◆ fr_value_box_copy_meta()

static void fr_value_box_copy_meta ( fr_value_box_t dst,
fr_value_box_t const *  src 
)
inlinestatic

Copy flags and type data from one value box to another.

Parameters
[in]dstto copy flags to
[in]srcof data.

Definition at line 638 of file value.c.

+ Here is the caller graph for this function:

◆ fr_value_box_copy_shallow()

void fr_value_box_copy_shallow ( TALLOC_CTX *  ctx,
fr_value_box_t dst,
fr_value_box_t const *  src 
)

Perform a shallow copy of a value_box.

Like fr_value_box_copy, but does not duplicate the buffers of the src value_box.

For FR_TYPE_STRING and FR_TYPE_OCTETS adds a reference from ctx so that the buffer cannot be freed until the ctx is freed.

Parameters
[in]ctxto add reference from. If NULL no reference will be added.
[in]dstto copy value to.
[in]srcto copy value from.

Definition at line 3834 of file value.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_value_box_debug()

void fr_value_box_debug ( fr_value_box_t const *  vb)

Print the value of a box as info messages.

Note
Call directly from the debugger

Definition at line 6403 of file value.c.

+ Here is the call graph for this function:

◆ fr_value_box_escape_in_place()

int fr_value_box_escape_in_place ( fr_value_box_t vb,
fr_value_box_escape_t  escape,
fr_value_box_safe_for_t  safe_for,
void *  uctx 
)

Escape a single value box in place.

Note
Applies recursively to the children of group boxes.
Parameters
[in]vbto escape.
[in]escapefunction to apply to the value box.
[in]safe_forthe escaped value to check value boxes again. box has an escaped value that matches, it will not be re-escaped.
[in]uctxuser context to pass to the escape function.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 5945 of file value.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_value_box_fixed_size_from_octets()

static int fr_value_box_fixed_size_from_octets ( fr_value_box_t dst,
fr_type_t  dst_type,
fr_dict_attr_t const *  dst_enumv,
fr_value_box_t const *  src 
)
static

Convert octets to a fixed size value box value.

All fixed size types are allowed.

Parameters
dstWhere to write result of casting.
dst_typeto cast to.
dst_enumvenumeration values.
srcInput data.

Definition at line 2147 of file value.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_value_box_flatten()

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.

Parameters
[in]ctxto reparent children in if steal is true.
[in]listto flatten.
[in]stealwhether to change the talloc ctx of children.
[in]freewhether to free any group boxes which have had their children removed.

Definition at line 6003 of file value.c.

+ Here is the call graph for this function:

◆ fr_value_box_from_network()

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.

The general deserialization rules are:

  • Octets are decoded in binary form (not hex).
  • Strings are decoded without the trailing \0 byte. Strings must consist only of valid UTF8 chars.
  • Integers are decoded big-endian.
  • Bools are decoded using one byte, with value 0x00 (false) or 0x01 (true).
  • Signed integers are decoded two's complement, with the MSB as the sign bit. Byte order is big-endian.
  • Network addresses are decoded big-endian.
  • IPv4 prefixes are decoded with 1 byte for the prefix, then 4 bytes of address.
  • IPv6 prefixes are decoded with 1 byte for the scope_id, 1 byte for the prefix, and 16 bytes of address.
  • Floats are decoded in IEEE-754 format with a big-endian byte order. We rely on the fact that the C standards require floats to be represented in IEEE-754 format in memory.
  • Dates are decoded as 32bit unsigned UNIX timestamps.

    All of the dictionary rules are respected. string/octets can have a fixed length, or can have an 8/16-bit "length" prefix. If the enumv is not an array, then the input # len MUST be the correct size (not too large or small), otherwise an error is returned.

    If the enumv is an array, then the input must have the minimum length, and the number of bytes decoded is capped at the maximum length allowed to be decoded. This behavior allows the caller to decode an array of values simply by calling this function in a loop.

Parameters
[in]ctxWhere to allocate any talloc buffers required.
[out]dstvalue_box to write the result to.
[in]typeto decode data to.
[in]enumvAliases for values.
[in]dbuffBinary data to decode.
[in]lenLength of data to decode. For fixed length types we only decode complete values.
[in]taintedWhether the value came from a trusted source.
Returns
  • >= 0 The number of bytes consumed.
  • <0 - The negative offset where the error occurred.
  • FR_VALUE_BOX_NET_OOM (negative value) - Out of memory.

Definition at line 1754 of file value.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_value_box_from_numeric_substr()

static fr_slen_t fr_value_box_from_numeric_substr ( 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 
)
inlinestatic

Convert integer encoded as string to a fr_value_box_t type.

Parameters
[out]dstwhere to write parsed value.
[in]dst_typetype of integer to convert string to.
[in]dst_enumvEnumeration values.
[in]inString to convert to integer.
[in]rulesfor parsing string.
[in]taintedWhether the value came from a trusted source.
Returns
  • >= 0 on success (number of bytes parsed).
  • < 0 on error (where the parse error occurred).

Definition at line 4701 of file value.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_value_box_from_str()

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 at line 5315 of file value.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_value_box_from_substr()

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.

Parameters
[in]ctxto alloc strings in.
[out]dstwhere to write parsed value.
[in,out]dst_typeof value data to create/dst_type of value created.
[in]dst_enumvfr_dict_attr_t with string names for uint32 values.
[in]insbuff to read data from.
[in]rulesunescape and termination rules.
[in]taintedWhether the value came from a trusted source.
Returns
  • >0 on success.
  • <= 0 on parse error.

Definition at line 4802 of file value.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_value_box_hash()

uint32_t fr_value_box_hash ( fr_value_box_t const *  vb)

Hash the contents of a value box.

Definition at line 6129 of file value.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_value_box_hton()

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.

Parameters
[in]dstWhere to write the result. May be the same as src.
[in]srcfr_value_box_t containing an uint32 value.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 1231 of file value.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_value_box_increment()

void fr_value_box_increment ( fr_value_box_t vb)

Increment a boxed value.

Implements safe integer overflow.

Parameters
[in]vbto increment.

Definition at line 4648 of file value.c.

+ Here is the caller graph for this function:

◆ fr_value_box_ipaddr()

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.

Automatically determines the type of the value box from the ipaddr address family and the length of the prefix field.

Parameters
[in]dstto assign ipaddr to.
[in]enumvAliases for values.
[in]ipaddrto copy address from.
[in]taintedWhether the value came from a trusted source.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 3630 of file value.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_value_box_is_truthy()

bool fr_value_box_is_truthy ( fr_value_box_t const *  in)

Check truthiness of values.

The casting rules for expressions / conditions are slightly
different than fr_value_box_cast().  Largely because that
function is used to parse configuration files, and parses "yes
/ no" and "true / false" strings, even if there's no
fr_dict_attr_t passed to it.

Definition at line 6326 of file value.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_value_box_list_acopy()

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.

Parameters
[in]ctxto allocate boxes in.
[out]outWhere to write the head of the new list.
[in]inboxes to copy.
Returns
  • A duplicate list of value boxes, allocated in the context of 'ctx'
  • NULL on error, or empty input list.

Definition at line 6158 of file value.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_value_box_list_aprint()

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.

Parameters
[in]ctxto allocate the buffer in.
[in]listof value boxes.
[in]delimto insert between value box values.
[in]e_rulesto control escaping of the concatenated elements.
Returns
  • NULL on error.
  • The concatenation of the string values of the value box list on success.

Definition at line 6028 of file value.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_value_box_list_aprint_secure()

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.

Parameters
[in]ctxto allocate the buffer in.
[in]listof value boxes.
[in]delimto insert between value box values.
[in]e_rulesto control escaping of the concatenated elements.
Returns
  • NULL on error.
  • The concatenation of the string values of the value box list on success.

Definition at line 6078 of file value.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_value_box_list_concat_as_octets()

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.

All boxes will be removed from the list.

Parameters
[out]taintedIf nonnull, will be set to true if any input boxes are tainted. bool pointed to must be initialised.
[out]secretIf nonnull, will be set to true if any input boxes are secret.
[out]dbuffto write the result of the concatenation to.
[in]listto concatenate.
[in]sepInsert a separator between the values.
[in]sep_lenLength of the separator.
[in]proc_actionWhat to do with the boxes in the list once they've been processed.
[in]flattenIf true and we encounter a FR_TYPE_GROUP, we concat the contents of its children together. If false, the contents will be cast to FR_TYPE_OCTETS.
Returns
  • >=0 the number of bytes written to the sbuff.
  • <0 how many additional bytes we would have needed to concat the next box.

Definition at line 5677 of file value.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_value_box_list_concat_as_string()

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,
fr_value_box_safe_for_t  safe_for,
bool  flatten 
)

Concatenate a list of value boxes together.

All boxes will be removed from the list.

Parameters
[out]taintedIf nonnull, will be set to true if any input boxes are tainted. bool pointed to must be initialised.
[out]secretIf nonnull, will be set to true if any input boxes are secret.
[out]sbuffto write the result of the concatenation to.
[in]listto concatenate.
[in]sepInsert a separator between the values.
[in]sep_lenLength of the separator.
[in]e_rulesTo apply to FR_TYPE_STRING types. Is not currently applied to any other box type.
[in]proc_actionWhat to do with the boxes in the list once they've been processed.
[in]safe_forif value has this safe_for value, don't apply the escape rules.
[in]flattenIf true and we encounter a FR_TYPE_GROUP, we concat the contents of its children together. If false, the contents will be cast to FR_TYPE_STRING.
Returns
  • >=0 the number of bytes written to the sbuff.
  • <0 how many additional bytes we would have needed to concat the next box.

Definition at line 5584 of file value.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_value_box_list_concat_in_place()

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.

Note
Will automatically cast all fr_value_box_t to type specified.
Parameters
[in]ctxto allocate new value buffer in.
[out]outWhere to write the resulting box.
[in]listto concatenate together.
[in]typeMay be FR_TYPE_STRING or FR_TYPE_OCTETS, no other types are supported.
[in]proc_actionWhat to do with the boxes in the list once they've been processed.
[in]flattenIf true and we encounter a FR_TYPE_GROUP, we concat the contents of its children together. If false, the contents will be cast to the given type.
[in]max_sizeof the value.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 5777 of file value.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_value_box_list_debug()

void fr_value_box_list_debug ( fr_value_box_list_t const *  head)

Print a list of value boxes as info messages.

Note
Call directly from the debugger

Definition at line 6376 of file value.c.

+ Here is the call graph for this function:

◆ fr_value_box_list_escape_in_place()

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  safe_for,
void *  uctx 
)

Escape a list of value boxes in place.

Note
Applies recursively to the children of group boxes.
on error, the list may be left in an inconsistent/partially escaped state.
Parameters
[in]listto escape.
[in]escapefunction to apply to the value box.
[in]safe_forthe escaped value to check value boxes again. box has an escaped value that matches, it will not be re-escaped.
[in]uctxuser context to pass to the escape function.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 5982 of file value.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_value_box_list_mark_safe_for()

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.

Note
Only operates on a single level.
Parameters
[in]listto operate on.
[in]safe_forvalue to set.

Definition at line 6313 of file value.c.

+ Here is the caller graph for this function:

◆ fr_value_box_list_taint()

void fr_value_box_list_taint ( fr_value_box_list_t *  head)

Taint every list member (and their children)

Parameters
[in]headof list.

Definition at line 6202 of file value.c.

◆ fr_value_box_list_tainted()

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.

Parameters
[in]headof list to check.
Returns
  • true if a list member is tainted.
  • false if no list members are tainted.

Definition at line 6186 of file value.c.

+ Here is the caller graph for this function:

◆ fr_value_box_list_untaint()

void fr_value_box_list_untaint ( fr_value_box_list_t *  head)

Untaint every list member (and their children)

Parameters
[in]headof list.

Definition at line 6216 of file value.c.

+ Here is the caller graph for this function:

◆ fr_value_box_list_verify()

void fr_value_box_list_verify ( char const *  file,
int  line,
fr_value_box_list_t const *  list 
)

Definition at line 6284 of file value.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_value_box_mark_unsafe()

void fr_value_box_mark_unsafe ( fr_value_box_t vb)

Mark a value-box as "unsafe".

This always succeeds, and there are no side effects.

Definition at line 6301 of file value.c.

◆ fr_value_box_mem_alloc()

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.

Note
Buffer will not be zeroed, as it's assumed the caller will be filling it.
Parameters
[in]ctxto allocate any new buffers in.
[out]outIf non-null will be filled with a pointer to the new buffer.
[in]dstto assign new buffer to.
[in]enumvAliases for values.
[in]lenof data in the buffer. If 0, a zero length talloc buffer will be alloced. dst->vb_octets will NOT be NULL. You should use the length field of the box to determine if any value is assigned.
[in]taintedWhether the value came from a trusted source.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 4371 of file value.c.

+ Here is the caller graph for this function:

◆ fr_value_box_mem_append()

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.

Parameters
[in]ctxWhere to allocate any talloc buffers required.
[in]dstvalue box to append to.
[in]srcoctets data to append.
[in]lenlength of octets data.
[in]taintedWhether src is tainted.
Returns
  • 0 on success.
    • -1 on failure.

Definition at line 4587 of file value.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_value_box_mem_append_buffer()

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.

Parameters
[in]ctxWhere to allocate any talloc buffers required.
[in]dstvalue box to append to.
[in]srcoctets data to append.
[in]taintedWhether src is tainted.
Returns
  • 0 on success.
    • -1 on failure.

Definition at line 4637 of file value.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_value_box_mem_realloc()

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.

Note
Do not use on an uninitialised box.
Parameters
[in]ctxto realloc buffer in.
[out]outif non-null where to write a pointer to the new buffer.
[in]dstto realloc buffer for.
[in]lento realloc to.
Returns
  • 0 on success.
    • -1 on failure.

Definition at line 4404 of file value.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_value_box_memdup()

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.

Copy a buffer containing binary data, setting fields in the dst value box appropriately.

Parameters
[in]ctxto allocate any new buffers in.
[in]dstto assign new buffer to.
[in]enumvAliases for values.
[in]srca buffer.
[in]lenof data in the buffer. If 0, a zero length talloc buffer will be alloced. dst->vb_octets will NOT be NULL. You should use the length field of the box to determine if any value is assigned.
[in]taintedWhether the value came from a trusted source.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 4468 of file value.c.

+ Here is the caller graph for this function:

◆ fr_value_box_memdup_buffer()

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.

Copy a buffer containing binary data, setting fields in the dst value box appropriately.

Parameters
[in]ctxto allocate any new buffers in.
[in]dstto assign new buffer to.
[in]enumvAliases for values.
[in]srca buffer.
[in]taintedWhether the value came from a trusted source.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 4526 of file value.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_value_box_memdup_buffer_shallow()

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.

Adds a reference to the src buffer so that it cannot be freed until the ctx is freed.

Parameters
[in]ctxto allocate any new buffers in.
[in]dstto assign buffer to.
[in]enumvAliases for values.
[in]srca talloced buffer.
[in]taintedWhether the value came from a trusted source.

Definition at line 4566 of file value.c.

+ Here is the caller graph for this function:

◆ fr_value_box_memdup_dbuff()

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 at line 4493 of file value.c.

+ Here is the caller graph for this function:

◆ fr_value_box_memdup_shallow()

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.

Adds a reference to the src buffer so that it cannot be freed until the ctx is freed.

Caller should set dst->taint = true, where the value was acquired from an untrusted source.

Note
Will free any exiting buffers associated with the value box.
Parameters
[in]dstto assign buffer to.
[in]enumvAliases for values.
[in]srca talloced buffer.
[in]lenof buffer.
[in]taintedWhether the value came from a trusted source.

Definition at line 4548 of file value.c.

+ Here is the caller graph for this function:

◆ fr_value_box_network_length()

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.

This is the length of the NETWORK presentation

Definition at line 1325 of file value.c.

+ Here is the caller graph for this function:

◆ fr_value_box_print()

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.

This function should primarily be used when a fr_value_box_t is being serialized in some non-standard way, i.e. as a value for a field in a database, in all other instances it's better to use fr_value_box_print_quoted.

Note
- this function does NOT respect tainting! The escaping rules are ONLY for escaping quotation characters, CR, LF, etc.
Parameters
[in]outWhere to write the printed string.
[in]dataValue box to print.
[in]e_rulesTo apply to FR_TYPE_STRING types, for escaping quotation characters only. Is not currently applied to any other box type.

Definition at line 5352 of file value.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_value_box_print_quoted()

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)

Parameters
[in]outWhere to write the printed string.
[in]dataValue box to print.
[in]quoteTo apply to FR_TYPE_STRING types. Is not currently applied to any other box type.

Definition at line 5540 of file value.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_value_box_steal()

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.

Parameters
[in]ctxto allocate any new buffers in.
[in]dstto copy value to.
[in]srcto copy value from.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 3858 of file value.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_value_box_strdup()

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.

Parameters
[in]ctxto allocate any new buffers in.
[in]dstto assign new buffer to.
[in]enumvAliases for values.
[in]srca nul terminated buffer.
[in]taintedWhether the value came from a trusted source.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 3927 of file value.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_value_box_strdup_shallow()

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.

Note
Input string will not be duplicated.
Parameters
[in]dstto assign string to.
[in]enumvAliases for values.
[in]srcto copy string from.
[in]taintedWhether the value came from a trusted source.

Definition at line 4036 of file value.c.

+ Here is the caller graph for this function:

◆ fr_value_box_strdup_shallow_replace()

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.

Note
Input string will not be duplicated.
Parameters
[in]vbto replace string in.
[in]srcto assign string from.
[in]lenof src.

Definition at line 4052 of file value.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_value_box_strtrim()

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.

Parameters
[in]ctxto re-alloc the buffer in.
[in,out]vbto trim.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 3953 of file value.c.

+ Here is the caller graph for this function:

◆ fr_value_box_to_key()

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.

Parameters
[in,out]out- set to a small buffer on input. If the callback has more data than is available here, the callback can update "out" to point elsewhere
[in,out]outlenThe number of bits available in the initial buffer. On output, the number of bits available in the key
[in]valuethe value box which contains the key
Returns
  • <0 on error
  • 0 on success

Definition at line 2084 of file value.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_value_box_to_network()

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.

The serialized form of fr_value_box_t may not match the requirements of your protocol completely. In cases where they do not, you should overload specific types in the function calling fr_value_box_to_network.

The general serialization rules are:

  • Octets are encoded in binary form (not hex).
  • Strings are encoded without the trailing \0 byte.
  • Integers are encoded big-endian.
  • Bools are encoded using one byte, with value 0x00 (false) or 0x01 (true).
  • Signed integers are encoded two's complement, with the MSB as the sign bit. Byte order is big-endian.
  • Network addresses are encoded big-endian.
  • IPv4 prefixes are encoded with 1 byte for the prefix, then 4 bytes of address.
  • IPv6 prefixes are encoded with 1 byte for the scope_id, 1 byte for the prefix, and 16 bytes of address.
  • Floats are encoded in IEEE-754 format with a big-endian byte order. We rely on the fact that the C standards require floats to be represented in IEEE-754 format in memory.
  • Dates are encoded as 16/32/64-bit unsigned UNIX timestamps.
  • time_deltas are encoded as 16/32/64-bit signed integers.

FR_TYPE_SIZE is not encodable, as it is system specific.

This function will not encode structural types (TLVs, VSAs etc...). These are usually specific to the protocol anyway.

All of the dictionary rules are respected. string/octets can have a fixed length (which is zero-padded if necessary), or can have an 8/16-bit "length" prefix.

Parameters
[out]dbuffWhere to write serialized data.
[in]valueto encode.
Returns
  • 0 no bytes were written.
  • >0 the number of bytes written to out.
  • <0 the number of bytes we'd need in dbuff to complete the operation.

Definition at line 1404 of file value.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_value_box_vasprintf()

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 
)

Print a formatted string using our internal printf wrapper and assign it to a value box.

Parameters
[in]ctxto allocate any new buffers in.
[in]dstto assign new buffer to.
[in]enumvAliases for values.
[in]fmtThe printf format string to process.
[in]taintedWhether the value came from a trusted source.
[in]apSubstitution arguments.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 3983 of file value.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_value_box_verify()

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 at line 6229 of file value.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_value_str_unescape()

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.

The quote character determines the escape sequences recognised.

  • Literal mode ("'" quote char) will unescape:
      - \\        - Literal backslash.
      - \<quote>  - The quotation char.
    
  • Expanded mode ('"' quote char) will also unescape:
      - \a        - Alert.
      - \b        - Backspace.
      - \e        - Escape character i.e. (\‍)
      - \r        - Carriage return.
      - \n        - Newline.
      - \t        - Tab.
      - \v        - Vertical tab
      - \<oct>    - An octal escape sequence.
      - \x<hex>   - A hex escape sequence.
    
  • Backtick mode ('‘’ quote char) identical to expanded mode.
  • Regex mode ('/') identical to expanded mode but two successive backslashes will be interpreted as an escape sequence, but not unescaped, so that they will be passed to the underlying regex library.
  • Verbatim mode ('\0' quote char) copies in to out verbatim.
Note
The resulting output may contain embedded \0s.
Unrecognised escape sequences will be copied verbatim.
In and out may point to the same underlying buffer.
Copying will stop early if an unescaped instance of the quoting char is found in the input buffer.
Parameters
[out]outWhere to write the unescaped string.
[in]inThe string to unescape.
[in]inlenLength of input string. Pass SIZE_MAX to copy all data in the input buffer.
[in]quoteCharacter around the string, determines unescaping mode.
Returns
  • 0 if input string was empty.
  • >0 the number of bytes written to out.

Definition at line 1128 of file value.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_value_substr_unescape()

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.

The quote character determines the escape sequences recognised.

  • Literal mode ("'" quote char) will unescape:
      - \\        - Literal backslash.
      - \<quote>  - The quotation char.
    
  • Expanded mode ('"' quote char) will also unescape:
      - \a        - Alert.
      - \b        - Backspace.
      - \e        - Escape character i.e. (\‍)
      - \r        - Carriage return.
      - \n        - Newline.
      - \t        - Tab.
      - \v        - Vertical tab
      - \<oct>    - An octal escape sequence.
      - \x<hex>   - A hex escape sequence.
    
  • Backtick mode ('‘’ quote char) identical to expanded mode.
  • Regex mode ('/') identical to expanded mode but two successive backslashes will be interpreted as an escape sequence, but not unescaped, so that they will be passed to the underlying regex library.
  • Verbatim mode ('\0' quote char) copies in to out verbatim.
Note
The resulting output may contain embedded \0s.
Unrecognised escape sequences will be copied verbatim.
In and out may point to the same underlying buffer.
Copying will stop early if an unescaped instance of the quoting char is found in the input buffer.
Parameters
[out]outWhere to write the unescaped string.
[in]inThe string to unescape.
[in]inlenLength of input string. Pass SIZE_MAX to copy all data in the input buffer.
[in]quoteCharacter around the string, determines unescaping mode.
Returns
  • 0 if input string was empty.
  • >0 the number of bytes written to out.

Definition at line 1201 of file value.c.

+ Here is the call graph for this function:

◆ fr_value_unbox_ipaddr()

int fr_value_unbox_ipaddr ( fr_ipaddr_t dst,
fr_value_box_t src 
)

Unbox an IP address performing a type check.

Parameters
[out]dstWhere to copy the IP address to.
[in]srcWhere to copy the IP address from.
Returns
  • 0 on success.
  • -1 on type mismatch.

Definition at line 3662 of file value.c.

+ Here is the call graph for this function:

Variable Documentation

◆ fr_value_box_field_sizes

size_t const fr_value_box_field_sizes[]

How many bytes wide each of the value data fields are.

This is useful when copying a value from a fr_value_box_t to a memory location passed as a void *.

Definition at line 149 of file value.c.

◆ fr_value_box_integer_max

uint64_t const fr_value_box_integer_max[]
static
Initial value:
= {
[FR_TYPE_BOOL] = true,
[FR_TYPE_UINT16] = UINT16_MAX,
[FR_TYPE_UINT32] = UINT32_MAX,
[FR_TYPE_UINT64] = UINT64_MAX,
[FR_TYPE_INT8] = INT8_MAX,
[FR_TYPE_INT16] = INT16_MAX,
[FR_TYPE_INT32] = INT32_MAX,
[FR_TYPE_INT64] = INT64_MAX,
[FR_TYPE_DATE] = UINT64_MAX,
[FR_TYPE_TIME_DELTA] = INT64_MAX,
[FR_TYPE_SIZE] = SIZE_MAX,
[FR_TYPE_MAX] = 0
}
@ FR_TYPE_TIME_DELTA
A period of time measured in nanoseconds.
Definition: merged_model.c:113
@ FR_TYPE_INT8
8 Bit signed integer.
Definition: merged_model.c:103
@ FR_TYPE_MAX
Number of defined data types.
Definition: merged_model.c:130
@ 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_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_BOOL
A truth value.
Definition: merged_model.c:95
@ FR_TYPE_SIZE
Unsigned integer capable of representing any memory address on the local system.
Definition: merged_model.c:115
#define UINT8_MAX
Definition: merged_model.c:32

Definition at line 226 of file value.c.

◆ fr_value_box_integer_min

int64_t const fr_value_box_integer_min[]
static
Initial value:
= {
[FR_TYPE_BOOL] = false,
[FR_TYPE_INT8] = INT8_MIN,
[FR_TYPE_INT16] = INT16_MIN,
[FR_TYPE_INT32] = INT32_MIN,
[FR_TYPE_INT64] = INT64_MIN,
[FR_TYPE_DATE] = 0,
[FR_TYPE_TIME_DELTA] = INT64_MIN,
[FR_TYPE_SIZE] = 0,
[FR_TYPE_MAX] = 0
}

Definition at line 246 of file value.c.

◆ fr_value_box_network_sizes

size_t const fr_value_box_network_sizes[FR_TYPE_MAX+1][2]
static

Definition at line 109 of file value.c.

◆ fr_value_box_offsets

size_t const fr_value_box_offsets[]

Where the value starts in the fr_value_box_t.

Definition at line 189 of file value.c.

◆ fr_value_escape_backtick

fr_sbuff_escape_rules_t fr_value_escape_backtick
Initial value:
= {
.name = "backtick",
.chr = '\\',
.subs = {
['%'] = '%',
['\\'] = '\\',
['`'] = '`',
['\a'] = 'a',
['\b'] = 'b',
['\n'] = 'n',
['\r'] = 'r',
['\t'] = 't',
['\v'] = 'v'
},
.esc = {
},
.do_utf8 = true,
.do_oct = true
}
#define SBUFF_CHAR_UNPRINTABLES_EXTENDED
#define SBUFF_CHAR_UNPRINTABLES_LOW

Definition at line 419 of file value.c.

◆ fr_value_escape_by_char

fr_sbuff_escape_rules_t* fr_value_escape_by_char[UINT8_MAX+1]
Initial value:
= {
}
fr_sbuff_escape_rules_t fr_value_escape_double
Definition: value.c:350
fr_sbuff_escape_rules_t fr_value_escape_single
Definition: value.c:388
fr_sbuff_escape_rules_t fr_value_escape_solidus
Definition: value.c:398
fr_sbuff_escape_rules_t fr_value_escape_backtick
Definition: value.c:419

Definition at line 448 of file value.c.

◆ fr_value_escape_by_quote

fr_sbuff_escape_rules_t* fr_value_escape_by_quote[T_TOKEN_LAST]
Initial value:

Definition at line 441 of file value.c.

◆ fr_value_escape_double

fr_sbuff_escape_rules_t fr_value_escape_double
Initial value:
= {
.name = "double",
.chr = '\\',
.subs = {
['"'] = '"',
['%'] = '%',
['\\'] = '\\',
['\a'] = 'a',
['\b'] = 'b',
['\n'] = 'n',
['\r'] = 'r',
['\t'] = 't',
['\v'] = 'v'
},
.esc = {
},
.do_utf8 = true,
.do_oct = true
}

Definition at line 350 of file value.c.

◆ fr_value_escape_secret

fr_sbuff_escape_rules_t fr_value_escape_secret
Initial value:
= {
.name = "secret",
.subs = {
[ 0 ... 255 ] = '.',
},
}

Escape secret fields by simply mashing all data to '.

'

The length of the secret still leaks, but that is likely fine. Fixing that is more work.

Definition at line 381 of file value.c.

◆ fr_value_escape_single

fr_sbuff_escape_rules_t fr_value_escape_single
Initial value:
= {
.name = "single",
.chr = '\\',
.subs = {
['\''] = '\'',
['\\'] = '\\'
},
.do_utf8 = true,
}

Definition at line 388 of file value.c.

◆ fr_value_escape_solidus

fr_sbuff_escape_rules_t fr_value_escape_solidus
Initial value:
= {
.name = "solidus",
.chr = '\\',
.subs = {
['%'] = '%',
['/'] = '/',
['\a'] = 'a',
['\b'] = 'b',
['\n'] = 'n',
['\r'] = 'r',
['\t'] = 't',
['\v'] = 'v'
},
.esc = {
},
.do_utf8 = true,
.do_oct = true
}

Definition at line 398 of file value.c.

◆ fr_value_escape_unprintables

fr_sbuff_escape_rules_t fr_value_escape_unprintables
Initial value:
= {
.name = "unprintables",
.chr = '\\',
.subs = {
['\\'] = '\\',
},
.esc = {
},
.do_utf8 = true,
.do_oct = true
}

Definition at line 455 of file value.c.

◆ fr_value_unescape_backtick

fr_sbuff_unescape_rules_t fr_value_unescape_backtick
Initial value:
= {
.name = "backtick",
.chr = '\\',
.subs = {
['%'] = '%',
['\\'] = '\\',
['`'] = '`',
['a'] = '\a',
['b'] = '\b',
['e'] = '\\',
['n'] = '\n',
['r'] = '\r',
['t'] = '\t',
['v'] = '\v'
},
.do_hex = true,
.do_oct = true
}

Definition at line 317 of file value.c.

◆ fr_value_unescape_by_char

fr_sbuff_unescape_rules_t* fr_value_unescape_by_char[UINT8_MAX+1]
Initial value:
= {
}
fr_sbuff_unescape_rules_t fr_value_unescape_solidus
Definition: value.c:296
fr_sbuff_unescape_rules_t fr_value_unescape_backtick
Definition: value.c:317
fr_sbuff_unescape_rules_t fr_value_unescape_single
Definition: value.c:285
fr_sbuff_unescape_rules_t fr_value_unescape_double
Definition: value.c:266

Definition at line 343 of file value.c.

◆ fr_value_unescape_by_quote

fr_sbuff_unescape_rules_t* fr_value_unescape_by_quote[T_TOKEN_LAST]

◆ fr_value_unescape_double

fr_sbuff_unescape_rules_t fr_value_unescape_double
Initial value:
= {
.name = "double",
.chr = '\\',
.subs = {
['"'] = '"',
['%'] = '%',
['\\'] = '\\',
['a'] = '\a',
['b'] = '\b',
['e'] = '\\',
['n'] = '\n',
['r'] = '\r',
['t'] = '\t',
['v'] = '\v'
},
.do_hex = true,
.do_oct = true
}

Definition at line 266 of file value.c.

◆ fr_value_unescape_single

fr_sbuff_unescape_rules_t fr_value_unescape_single
Initial value:
= {
.name = "single",
.chr = '\\',
.subs = {
['\''] = '\'',
['\\'] = '\\'
},
.do_hex = false,
.do_oct = false
}

Definition at line 285 of file value.c.

◆ fr_value_unescape_solidus

fr_sbuff_unescape_rules_t fr_value_unescape_solidus
Initial value:
= {
.name = "solidus",
.chr = '\\',
.subs = {
['%'] = '%',
['/'] = '/',
['a'] = '\a',
['b'] = '\b',
['e'] = '\\',
['n'] = '\n',
['r'] = '\r',
['t'] = '\t',
['v'] = '\v'
},
.skip = {
['\\'] = '\\'
},
.do_hex = true,
.do_oct = true
}

Definition at line 296 of file value.c.

◆ v4_v6_map

uint8_t const v4_v6_map[]
static
Initial value:
= { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xff, 0xff }

v4 to v6 mapping prefix

Part of the IPv6 range is allocated to represent IPv4 addresses.

Definition at line 2195 of file value.c.

◆ value_parse_rules_3quoted

fr_sbuff_parse_rules_t const* value_parse_rules_3quoted[T_TOKEN_LAST]
Initial value:
= {
}
@ T_BARE_WORD
Definition: token.h:120
fr_sbuff_parse_rules_t const value_parse_rules_single_3quoted
Definition: value.c:580
fr_sbuff_parse_rules_t const value_parse_rules_double_3quoted
Definition: value.c:574
fr_sbuff_parse_rules_t const value_parse_rules_bareword_quoted
Definition: value.c:524
fr_sbuff_parse_rules_t const value_parse_rules_backtick_3quoted
Definition: value.c:592
fr_sbuff_parse_rules_t const value_parse_rules_solidus_3quoted
Definition: value.c:586

Definition at line 622 of file value.c.

◆ value_parse_rules_backtick_3quoted

fr_sbuff_parse_rules_t const value_parse_rules_backtick_3quoted
Initial value:
= {
.terminals = &FR_SBUFF_TERMS(
L(""), L("\n"), L("\r"), L("```"))
}
#define L(_str)
Helper for initialising arrays of string literals.
Definition: build.h:207
#define FR_SBUFF_TERMS(...)
Initialise a terminal structure with a list of sorted strings.
Definition: sbuff.h:167

Definition at line 592 of file value.c.

◆ value_parse_rules_backtick_quoted

fr_sbuff_parse_rules_t const value_parse_rules_backtick_quoted
Initial value:
= {
.terminals = &FR_SBUFF_TERMS(
L(""), L("\n"), L("\r"), L("`"))
}

Definition at line 565 of file value.c.

◆ value_parse_rules_backtick_unquoted

fr_sbuff_parse_rules_t const value_parse_rules_backtick_unquoted
Initial value:
= {
}

Definition at line 496 of file value.c.

◆ value_parse_rules_bareword_quoted

fr_sbuff_parse_rules_t const value_parse_rules_bareword_quoted
Initial value:
= {
.chr = '\\',
.subs = {
['\t'] = '\t',
['\n'] = '\n',
[' '] = ' '
},
.do_hex = false,
.do_oct = false
},
.terminals = &FR_SBUFF_TERMS(
L(""),
L("\t"),
L("\n"),
L(" ")
)
}
Set of parsing rules for *unescape_until functions.
Definition: merged_model.c:163

Definition at line 524 of file value.c.

◆ value_parse_rules_bareword_unquoted

fr_sbuff_parse_rules_t const value_parse_rules_bareword_unquoted
Initial value:
= {
}

Default formatting rules.

Control token termination, escaping and how the tmpl is printed.

Definition at line 480 of file value.c.

◆ value_parse_rules_double_3quoted

fr_sbuff_parse_rules_t const value_parse_rules_double_3quoted
Initial value:
= {
.terminals = &FR_SBUFF_TERMS(
L(""), L("\n"), L("\r"), L("\"\"\""))
}

Definition at line 574 of file value.c.

◆ value_parse_rules_double_quoted

fr_sbuff_parse_rules_t const value_parse_rules_double_quoted
Initial value:
= {
.terminals = &FR_SBUFF_TERMS(
L(""), L("\n"), L("\r"), L("\""))
}

Definition at line 547 of file value.c.

◆ value_parse_rules_double_unquoted

fr_sbuff_parse_rules_t const value_parse_rules_double_unquoted
Initial value:
= {
}

Definition at line 484 of file value.c.

◆ value_parse_rules_quoted

fr_sbuff_parse_rules_t const* value_parse_rules_quoted[T_TOKEN_LAST]
Initial value:
= {
}
fr_sbuff_parse_rules_t const value_parse_rules_solidus_quoted
Definition: value.c:559
fr_sbuff_parse_rules_t const value_parse_rules_single_quoted
Definition: value.c:553
fr_sbuff_parse_rules_t const value_parse_rules_backtick_quoted
Definition: value.c:565
fr_sbuff_parse_rules_t const value_parse_rules_double_quoted
Definition: value.c:547

Parse rules for quoted strings.

These parse rules should be used for internal parsing functions that are working with configuration files.

They include appropriate quote terminals to force functions parsing quoted strings to return when they reach a quote character.

Definition at line 606 of file value.c.

◆ value_parse_rules_quoted_char

fr_sbuff_parse_rules_t const* value_parse_rules_quoted_char[UINT8_MAX]

◆ value_parse_rules_single_3quoted

fr_sbuff_parse_rules_t const value_parse_rules_single_3quoted
Initial value:
= {
.terminals = &FR_SBUFF_TERMS(
L(""), L("\n"), L("\r"), L("'''"))
}

Definition at line 580 of file value.c.

◆ value_parse_rules_single_quoted

fr_sbuff_parse_rules_t const value_parse_rules_single_quoted
Initial value:
= {
.terminals = &FR_SBUFF_TERMS(
L(""), L("\n"), L("\r"), L("'"))
}

Definition at line 553 of file value.c.

◆ value_parse_rules_single_unquoted

fr_sbuff_parse_rules_t const value_parse_rules_single_unquoted
Initial value:
= {
}

Definition at line 488 of file value.c.

◆ value_parse_rules_solidus_3quoted

fr_sbuff_parse_rules_t const value_parse_rules_solidus_3quoted
Initial value:
= {
.terminals = &FR_SBUFF_TERMS(
L(""), L("\n"), L("\r"), L("///"))
}

Definition at line 586 of file value.c.

◆ value_parse_rules_solidus_quoted

fr_sbuff_parse_rules_t const value_parse_rules_solidus_quoted
Initial value:
= {
.terminals = &FR_SBUFF_TERMS(
L(""), L("\n"), L("\r"), L("/"))
}

Definition at line 559 of file value.c.

◆ value_parse_rules_solidus_unquoted

fr_sbuff_parse_rules_t const value_parse_rules_solidus_unquoted
Initial value:
= {
}

Definition at line 492 of file value.c.

◆ value_parse_rules_unquoted

fr_sbuff_parse_rules_t const* value_parse_rules_unquoted[T_TOKEN_LAST]
Initial value:
= {
}
fr_sbuff_parse_rules_t const value_parse_rules_double_unquoted
Definition: value.c:484
fr_sbuff_parse_rules_t const value_parse_rules_bareword_unquoted
Default formatting rules.
Definition: value.c:480
fr_sbuff_parse_rules_t const value_parse_rules_single_unquoted
Definition: value.c:488
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_unquoted
Definition: value.c:496

Parse rules for non-quoted strings.

These parse rules should be used for processing escape sequences in data from external data sources like SQL databases and REST APIs.

They do not include terminals to stop parsing as it assumes the values are discrete, and not wrapped in quotes.

Definition at line 508 of file value.c.

◆ value_parse_rules_unquoted_char

fr_sbuff_parse_rules_t const* value_parse_rules_unquoted_char[UINT8_MAX]