24RCSID(
"$Id: a4f6db8b9fe66a0c5816aa821e8e5d8573bd18ed $")
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/proto.h>
30#include <freeradius-devel/util/regex.h>
32#include <freeradius-devel/protocol/radius/rfc2865.h>
33#include <freeradius-devel/protocol/freeradius/freeradius.internal.h>
105 fr_sbuff_parse_rules_t
const *rules;
130 return slen - (quote != 0);
140 return slen + ((quote != 0) << 1);
223 bool raw, was_unknown;
224 bool was_relative =
false;
264 fr_strerror_const(
"Attribute comparisons can only be used when the destination list is empty");
271#define CLEAN_DA_STACK do { if (was_unknown) { \
272 for (i = 1; i < da_stack.depth; i++) { \
273 fr_dict_attr_unknown_free(&da_stack.da[i]); \
300 append = !was_relative;
301 was_relative =
false;
321 }
else if (relative->
da->flags.is_root) {
322 fr_strerror_const(
"The '.Attribute' syntax cannot be used at the root of a dictionary");
329 fr_strerror_printf(
"The '.Attribute' syntax cannot be used with parent %s of data type 'group'",
345 if (relative->
da->flags.is_unknown) {
354 if (raw && relative->
da->flags.internal) {
362 fr_sbuff_marker(&lhs_m, &our_in);
378 if (!components)
goto done;
380 fr_sbuff_marker(&op_m, &our_in);
410 fr_strerror_printf(
"The '.Attribute' syntax cannot be used along with the '%s' operator",
433 static const bool invalid[
UINT8_MAX + 1] = {
434 [
'!'] =
true, [
'#'] =
true, [
'$'] =
true, [
'*'] =
true,
435 [
'+'] =
true, [
'-'] =
true, [
'/'] =
true, [
'<'] =
true,
436 [
'='] =
true, [
'>'] =
true, [
'?'] =
true, [
'|'] =
true,
440 if (c && invalid[c]) {
468 fr_sbuff_marker(&rhs_m, &our_in);
498 fr_sbuff_marker(&rhs_m, &our_in);
518 for (i = 1; i <= components; i++, da_stack.
depth++) {
532 fr_sbuff_marker(&lhs_m, &our_in);
564 if ((relative->
da->dict == relative->
internal) && relative->
dict) {
575 fr_strerror_printf(
"Internal attribute '%s' of data type '%s' cannot contain protocol attributes",
634 da_stack.
da[da_stack.
depth - 1]->name);
643 fr_strerror_printf(
"Cannot create 'raw' children in attribute %s of data type 'group'",
644 da_stack.
da[da_stack.
depth - 1]->name);
659 if (i < components) {
678 unknown_type = raw_type;
682 if (!da_unknown)
goto error;
702 if (da->parent !=
parent) {
711 diff = da->depth - ref->depth;
726 for (j = da_stack.
depth + diff; j >= da_stack.
depth; j--) {
731 for (j = da_stack.
depth; j <= da_stack.
depth + diff; j++) {
738 da_stack.
depth += diff;
767 if (i < components) {
779 fr_strerror_printf(
"Please remove the reference to key field '%s' from the input string",
788 }
else if (raw && !da->flags.is_unknown) {
803 fr_strerror_printf(
"Cannot create raw attribute %s which changes data type from %s to %s",
810 if (!da_unknown)
goto error;
816 da_stack.
da[da_stack.
depth] = da;
822 if (da_stack.
depth <= 1) {
827 if (da_stack.
depth <= components) {
849 da_stack.
da[da_stack.
depth - 1]->name);
856 if (components == 1) append = (op !=
T_OP_EQ);
863 if ((relative->
da->flags.allow_flat) && (da_stack.
depth > 2)) {
864 da_stack.
da[1] = da_stack.
da[da_stack.
depth - 1];
874 for (i = 1; i < da_stack.
depth; i++) {
896 if (!
vp->
da->flags.internal)
break;
899 if (
vp && (
vp->
da->attr > da->attr)) {
915 my.list = &
vp->vp_group;
927 if (
vp)
goto update_relative;
942 my.list = &
vp->vp_group;
985 my.end_of_list =
true;
997 if (slen < 0)
goto error;
1012 if (slen <= 0)
goto error;
1106 relative->
list = &
vp->vp_group;
1123 if (remaining > 20) remaining = 20;
1169 .allow_compare =
true,
1173 while (fgets(buf,
sizeof(buf), fp) != NULL) {
1178 if ((buf[0] ==
'\n') || (buf[0] ==
'\r')) {
1189 if (buf[0] ==
'#')
continue;
1210#ifdef WITH_VERIFY_PTR
1211 fr_pair_list_verify(__FILE__, __LINE__, ctx, &tmp_list,
true);
1291 if (!found)
goto do_add;
1300 if (!found)
goto do_add;
#define L(_str)
Helper for initialising arrays of string literals.
fr_dict_t const * fr_dict_by_da(fr_dict_attr_t const *da)
Attempt to locate the protocol dictionary containing an attribute.
fr_dict_attr_t const * fr_dict_attr_common_parent(fr_dict_attr_t const *a, fr_dict_attr_t const *b, bool is_ancestor)
Find a common ancestor that two TLV type attributes share.
static fr_dict_attr_t * fr_dict_attr_unknown_afrom_oid(TALLOC_CTX *ctx, fr_dict_attr_t const *parent, fr_sbuff_t *in, fr_type_t type)
bool const fr_dict_attr_allowed_chars[UINT8_MAX+1]
Characters allowed in a single dictionary attribute name.
fr_dict_attr_t * fr_dict_attr_unknown_alloc(TALLOC_CTX *ctx, fr_dict_attr_t const *da, fr_type_t type))
Allocate an unknown DA.
fr_dict_attr_t const * fr_dict_root(fr_dict_t const *dict)
Return the root attribute of a dictionary.
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.
#define FR_DICT_MAX_TLV_STACK
Maximum TLV stack size.
fr_dict_attr_err_t
Errors returned by attribute lookup functions.
@ FR_DICT_ATTR_OK
No error.
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.
void fr_bio_shutdown & my
@ 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.
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_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(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.
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.
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_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.
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
fr_pair_t * vp[FR_DICT_MAX_TLV_STACK]
which VP we have created or found
static ssize_t fr_pair_value_from_substr(fr_pair_t *vp, fr_sbuff_t *in, UNUSED bool tainted)
fr_dict_attr_t const * da[FR_DICT_MAX_TLV_STACK]
parent for parsing
static fr_table_num_sorted_t const pair_comparison_op_table[]
static fr_sbuff_term_t const bareword_terminals
static ssize_t pair_assignment_op_table_len
Our version of a DA stack.
bool allow_zeros
allow '\0' as end of attribute
struct fr_pair_parse_s fr_pair_parse_t
bool end_of_list
do we expect an end of list '}' character?
fr_pair_list_t * list
list where output is placed
fr_dict_t const * internal
a cached pointer to the internal dictionary
fr_dict_t const * dict
the protocol dictionary we use
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_current(_sbuff_or_marker)
#define fr_sbuff_char(_sbuff_or_marker, _eob)
#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_SET_RETURN(_dst, _src)
#define fr_sbuff_is_digit(_sbuff_or_marker)
#define FR_SBUFF_IN_STR(_start)
#define fr_sbuff_error(_sbuff_or_marker)
#define FR_SBUFF(_sbuff_or_marker)
#define fr_sbuff_adv_past_blank(_sbuff, _len, _tt)
#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.
char const * fr_tokens[T_TOKEN_LAST]
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.
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.
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.
fr_pair_t * fr_pair_list_prev(fr_pair_list_t const *list, fr_pair_t const *item))
Get the previous item in a valuepair list before a specific entry.
fr_pair_t * fr_pair_list_head(fr_pair_list_t const *list)
Get the head of a valuepair 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.
#define FR_TYPE_STRUCTURAL_EXCEPT_GROUP
#define fr_type_is_structural(_x)
#define fr_type_is_leaf(_x)
static char const * fr_type_to_str(fr_type_t type)
Return a static string containing the type name.
fr_sbuff_parse_rules_t const value_parse_rules_single_quoted
fr_sbuff_parse_rules_t const value_parse_rules_double_quoted
ssize_t fr_value_box_from_substr(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_type_t dst_type, fr_dict_attr_t const *dst_enumv, fr_sbuff_t *in, fr_sbuff_parse_rules_t const *rules)
Convert string value to a fr_value_box_t type.
static size_t char ** out