24 RCSID(
"$Id: 4e86572f944f87e18c6b8bfcc0a3cb207a883f47 $")
26 #include <freeradius-devel/util/dict.h>
27 #include <freeradius-devel/util/pair.h>
28 #include <freeradius-devel/util/pair_legacy.h>
29 #include <freeradius-devel/util/misc.h>
30 #include <freeradius-devel/util/proto.h>
31 #include <freeradius-devel/util/regex.h>
33 #include <freeradius-devel/protocol/radius/rfc2865.h>
34 #include <freeradius-devel/protocol/freeradius/freeradius.internal.h>
106 fr_sbuff_parse_rules_t
const *rules;
129 if (slen < 0)
return slen - (quote != 0);
136 return slen + ((quote != 0) << 1);
155 bool was_relative =
false;
182 if (
internal == root->
da)
internal = NULL;
206 append = !was_relative;
207 was_relative =
false;
223 }
else if (!relative->
ctx || !relative->
da || !relative->
list) {
224 fr_strerror_const(
"The '.Attribute' syntax can only be used if the previous attribute is structural, and the line ends with ','");
233 fr_sbuff_marker(&lhs_m, &our_in);
273 fr_sbuff_marker(&rhs_m, &our_in);
289 fr_sbuff_marker(&m, &our_in);
304 fr_sbuff_marker(&rhs_m, &our_in);
363 if (relative->
da !=
vp->
da->parent) {
369 relative->
ctx = parent_vp;
370 relative->
da = parent_vp->
da;
371 relative->
list = &parent_vp->vp_group;
379 goto update_relative;
389 fr_sbuff_marker(&rhs_m, &our_in);
405 if (relative->
da->flags.is_root) {
415 if (i < components) {
447 fr_strerror_printf(
"Cannot create raw attribute %s which changes data type from %s to %s",
475 if (tail && (tail->
da->attr >= da->attr) && !da->flags.array) {
479 if (!parent_vp)
goto leaf;
484 if (!grand_vp)
goto leaf;
495 relative->
list = &
vp->vp_group;
512 switch (
vp->vp_type) {
519 relative->
list = &
vp->vp_group;
530 if (relative->
da ==
internal) {
533 relative->
list = &
vp->vp_group;
547 relative->
ctx = parent_vp;
549 relative->
list = &parent_vp->vp_group;
632 if (keep_going)
goto redo;
667 .allow_compare =
true,
671 while (fgets(buf,
sizeof(buf), fp) != NULL) {
676 if ((buf[0] ==
'\n') || (buf[0] ==
'\r')) {
687 if (buf[0] ==
'#')
continue;
785 if (!found)
goto do_add;
794 if (!found)
goto do_add;
#define L(_str)
Helper for initialising arrays of string literals.
bool const fr_dict_attr_allowed_chars[UINT8_MAX+1]
Characters that are allowed in dictionary attribute names.
fr_dict_attr_t const * fr_dict_root(fr_dict_t const *dict)
Return the root attribute of a dictionary.
void fr_dict_attr_unknown_free(fr_dict_attr_t const **da)
Free dynamically allocated (unknown attributes)
fr_dict_t const * fr_dict_by_da(fr_dict_attr_t const *da)
Attempt to locate the protocol dictionary containing an attribute.
fr_slen_t fr_dict_attr_unknown_afrom_oid_substr(TALLOC_CTX *ctx, fr_dict_attr_t const **out, fr_dict_attr_t const *parent, fr_sbuff_t *in, fr_type_t type))
Create a fr_dict_attr_t from an ASCII attribute and value.
fr_dict_attr_t * fr_dict_attr_unknown_raw_afrom_da(TALLOC_CTX *ctx, fr_dict_attr_t const *da))
Initialise an octets type attribute from a da.
fr_dict_t const * fr_dict_internal(void)
static bool fr_dict_attr_is_top_level(fr_dict_attr_t const *da)
Return true if this attribute is parented directly off the dictionary root.
fr_dict_attr_err_t
Errors returned by attribute lookup functions.
@ FR_DICT_ATTR_OK
No error.
@ FR_DICT_ATTR_NOTFOUND
Attribute couldn't be found.
fr_slen_t fr_dict_oid_component(fr_dict_attr_err_t *err, fr_dict_attr_t const **out, fr_dict_attr_t const *parent, fr_sbuff_t *in, fr_sbuff_term_t const *tt))
Parse an OID component, resolving it to a defined attribute.
#define fr_dict_attr_is_key_field(_da)
static fr_dict_attr_t const * fr_dict_attr_ref(fr_dict_attr_t const *da)
Return the reference associated with a group type attribute.
@ FR_TYPE_TLV
Contains nested attributes.
@ FR_TYPE_NULL
Invalid (uninitialised) attribute type.
@ FR_TYPE_STRUCT
like TLV, but without T or L, and fixed-width children
@ FR_TYPE_VENDOR
Attribute that represents a vendor in the attribute tree.
@ FR_TYPE_VSA
Vendor-Specific, for RADIUS attribute 26.
@ FR_TYPE_OCTETS
Raw octets.
@ FR_TYPE_GROUP
A grouping of other attributes.
fr_pair_t * fr_pair_find_by_da(fr_pair_list_t const *list, fr_pair_t const *prev, fr_dict_attr_t const *da)
Find the first pair with a matching da.
int fr_pair_append_by_da(TALLOC_CTX *ctx, fr_pair_t **out, fr_pair_list_t *list, fr_dict_attr_t const *da)
Alloc a new fr_pair_t (and append)
fr_pair_t * fr_pair_parent(fr_pair_t const *vp)
Return a pointer to the parent pair.
fr_pair_t * fr_pair_afrom_da(TALLOC_CTX *ctx, fr_dict_attr_t const *da)
Dynamically allocate a new attribute and assign a fr_dict_attr_t.
fr_pair_t * fr_pair_find_last_by_da(fr_pair_list_t const *list, fr_pair_t const *prev, fr_dict_attr_t const *da)
Find the last pair with a matching da.
int fr_pair_append(fr_pair_list_t *list, fr_pair_t *to_add)
Add a VP to the end of the list.
int fr_pair_delete_by_da(fr_pair_list_t *list, fr_dict_attr_t const *da)
Delete matching pairs from the specified list.
void fr_pair_list_init(fr_pair_list_t *list)
Initialise a pair list header.
int fr_pair_prepend(fr_pair_list_t *list, fr_pair_t *to_add)
Add a VP to the start of the list.
fr_pair_t * fr_pair_list_parent(fr_pair_list_t const *list)
Return a pointer to the parent pair which contains this list.
fr_pair_t * fr_pair_afrom_da_depth_nested(TALLOC_CTX *ctx, fr_pair_list_t *list, fr_dict_attr_t const *da, int start)
Create a pair (and all intermediate parents), and append it to the list.
static fr_sbuff_parse_rules_t const bareword_unquoted
static fr_table_num_sorted_t const pair_assignment_op_table[]
fr_slen_t fr_pair_list_afrom_substr(fr_pair_parse_t const *root, fr_pair_parse_t *relative, fr_sbuff_t *in)
Parse a fr_pair_list_t from a substring.
int fr_pair_list_afrom_file(TALLOC_CTX *ctx, fr_dict_t const *dict, fr_pair_list_t *out, FILE *fp, bool *pfiledone)
Read valuepairs from the fp up to End-Of-File.
void fr_pair_list_move_op(fr_pair_list_t *to, fr_pair_list_t *from, fr_token_t op)
Move pairs from source list to destination list respecting operator.
static size_t pair_comparison_op_table_len
static fr_table_num_sorted_t const pair_comparison_op_table[]
static fr_sbuff_term_t const bareword_terminals
static ssize_t fr_pair_value_from_substr(fr_pair_t *vp, fr_sbuff_t *in, bool tainted)
static ssize_t pair_assignment_op_table_len
struct fr_pair_parse_s fr_pair_parse_t
fr_pair_list_t * list
list where output is placed
bool allow_compare
allow comparison operators
fr_dict_attr_t const * da
root da to start parsing from
bool tainted
source is tainted
bool allow_crlf
allow CRLF, and treat like comma
char last_char
last character we read - ',', ' ', or 0 for EOF
size_t fr_sbuff_adv_past_allowed(fr_sbuff_t *sbuff, size_t len, bool const allowed[static UINT8_MAX+1], fr_sbuff_term_t const *tt)
Wind position past characters in the allowed set.
bool const sbuff_char_line_endings[UINT8_MAX+1]
bool fr_sbuff_next_if_char(fr_sbuff_t *sbuff, char c)
Return true if the current char matches, and if it does, advance.
#define fr_sbuff_out_by_longest_prefix(_match_len, _out, _table, _sbuff, _def)
#define fr_sbuff_is_str_literal(_sbuff, _str)
#define fr_sbuff_set(_dst, _src)
#define fr_sbuff_diff(_a, _b)
#define FR_SBUFF_IN(_start, _len_or_end)
#define fr_sbuff_adv_past_whitespace(_sbuff, _len, _tt)
#define fr_sbuff_current(_sbuff_or_marker)
#define FR_SBUFF_TERMS(...)
Initialise a terminal structure with a list of sorted strings.
#define fr_sbuff_extend(_sbuff_or_marker)
#define fr_sbuff_is_char(_sbuff_or_marker, _c)
#define fr_sbuff_is_digit(_sbuff_or_marker)
#define fr_sbuff_error(_sbuff_or_marker)
#define FR_SBUFF(_sbuff_or_marker)
#define fr_sbuff_advance(_sbuff_or_marker, _len)
#define fr_sbuff_remaining(_sbuff_or_marker)
Set of terminal elements.
Stores an attribute, a value and various bits of other data.
fr_dict_attr_t const *_CONST da
Dictionary attribute defines the attribute number, vendor and type of the pair.
An element in a lexicographically sorted array of name to num mappings.
fr_pair_t * fr_pair_list_head(fr_pair_list_t const *list)
Get the head of a valuepair list.
fr_pair_t * fr_pair_list_tail(fr_pair_list_t const *list)
Get the tail of a valuepair list.
fr_pair_t * fr_pair_remove(fr_pair_list_t *list, fr_pair_t *vp)
Remove fr_pair_t from a list without freeing.
bool fr_pair_list_empty(fr_pair_list_t const *list)
Is a valuepair list empty.
fr_pair_t * fr_pair_list_next(fr_pair_list_t const *list, fr_pair_t const *item))
Get the next item in a valuepair list after a specific entry.
void fr_pair_list_free(fr_pair_list_t *list)
Free memory used by a valuepair list.
void fr_pair_list_append(fr_pair_list_t *dst, fr_pair_list_t *src)
Appends a list of fr_pair_t from a temporary list to a destination list.
void fr_pair_list_prepend(fr_pair_list_t *dst, fr_pair_list_t *src)
Move a list of fr_pair_t from a temporary list to the head of a destination list.
#define fr_strerror_printf(_fmt,...)
Log to thread local error buffer.
#define fr_strerror_const(_msg)
fr_table_num_ordered_t const fr_type_table[]
Map data types to names representing those types.
static char const * fr_type_to_str(fr_type_t type)
Return a static string containing the type name.
#define fr_type_is_structural(_x)
#define fr_type_is_leaf(_x)
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.
fr_sbuff_parse_rules_t const value_parse_rules_single_quoted
FR_SBUFF_SET_RETURN(sbuff, &our_sbuff)
fr_sbuff_parse_rules_t const value_parse_rules_double_quoted
static size_t char ** out