24 RCSID(
"$Id: 32532812ba65083d58940e709365825e61dbe292 $")
26 #include <freeradius-devel/util/talloc.h>
27 #include <freeradius-devel/util/file.h>
97 common->
filename = talloc_strdup(common, filename);
128 char const *attr,
size_t attr_len,
129 char const *
name,
size_t name_len,
130 char const *
value,
size_t value_len,
178 fixup->
value, talloc_array_length(fixup->
value) - 1,
190 if (ret < 0)
return -1;
221 .ref = talloc_strdup(fixup, ref),
235 fr_assert((ref[0] ==
'.') && (ref[1] ==
'.'));
252 while (*q && (*q !=
'.')) {
253 *(p++) = tolower((
int) *(q++));
255 if ((
size_t) (p - protocol) >=
sizeof(protocol)) {
301 if (*
name !=
'.')
goto invalid;
335 if (fixup->
ref[0] !=
'.') {
358 fr_strerror_printf(
"References MUST NOT refer to an ATTRIBUTE which also has 'ref=...' at %s[%d]",
385 char const *ref,
size_t ref_len)
422 char const *ref = fixup->
ref;
428 root = fixup->
da->parent;
431 while (ref[0] ==
'.') {
435 if (root->flags.is_root) {
462 if (da->depth < fixup->
da->depth) {
475 fr_strerror_printf(
"References MUST NOT refer to an ATTRIBUTE which itself has a 'ref=...' at %s[%d]",
520 if (copied < 0)
return -1;
554 cloned->attr = fixup->
da->attr;
555 cloned->parent = fixup->
parent;
556 cloned->depth = cloned->parent->depth + 1;
599 if (fctx->
pool)
return 0;
606 if (!fctx->
pool)
return -1;
617 #define APPLY_FIXUP(_fctx, _list, _func, _type) \
620 while ((_fixup = fr_dlist_head(&(_fctx)->_list))) { \
621 if (_func(_fctx, _fixup) < 0) return -1; \
622 fr_dlist_remove(&(_fctx)->_list, _fixup); \
623 talloc_free(_fixup); \
640 TALLOC_FREE(fctx->
pool);
fr_dict_attr_t const * fr_dict_attr_by_oid(fr_dict_attr_err_t *err, fr_dict_attr_t const *parent, char const *oid))
Resolve an attribute using an OID string.
int fr_dict_enum_add_name(fr_dict_attr_t *da, char const *name, fr_value_box_t const *value, bool coerce, bool replace)
Add a value name.
fr_dict_attr_t * fr_dict_attr_unconst(fr_dict_attr_t const *da)
Coerce to non-const.
int fr_dict_walk(fr_dict_attr_t const *da, fr_dict_walk_t callback, void *uctx)
int fr_dict_protocol_afrom_file(fr_dict_t **out, char const *proto_name, char const *proto_dir, char const *dependent)
(Re)-initialize a protocol dictionary
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_by_da(fr_dict_attr_t const *da)
Attempt to locate the protocol dictionary containing an attribute.
fr_dict_t * fr_dict_unconst(fr_dict_t const *dict)
Coerce to non-const.
@ FR_DICT_ATTR_EXT_ENUMV
Enumeration values.
#define fr_dict_attr_is_key_field(_da)
static void * fr_dict_attr_ext(fr_dict_attr_t const *da, fr_dict_attr_ext_t ext)
fr_hash_table_t * name_by_value
Lookup a name by value.
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_hash_table_t * value_by_name
Lookup an enumeration value by name.
Attribute extension - Holds enumeration values.
static int dict_attr_ref_set(fr_dict_attr_t const *da, fr_dict_attr_t const *ref)
static fr_hash_table_t * dict_attr_namespace(fr_dict_attr_t const *da)
Return the namespace hash table associated with the attribute.
static fr_dict_attr_t const ** dict_attr_children(fr_dict_attr_t const *da)
fr_dict_attr_t * da
FR_TYPE_GROUP to fix.
dict_fixup_common_t common
Common fields.
int dict_fixup_apply(dict_fixup_ctx_t *fctx)
Apply all outstanding fixes to a set of dictionaries.
char * ref
the target attribute to clone
char * attribute
we couldn't find (and will need to resolve later).
static int dict_fixup_clone_apply(UNUSED dict_fixup_ctx_t *fctx, dict_fixup_clone_t *fixup)
Clone one are of a tree into another.
char * value
Raw enum value.
int dict_fixup_group(dict_fixup_ctx_t *fctx, char const *filename, int line, fr_dict_attr_t *da, char const *ref)
Resolve a group reference.
int dict_fixup_enumv(dict_fixup_ctx_t *fctx, char const *filename, int line, char const *attr, size_t attr_len, char const *name, size_t name_len, char const *value, size_t value_len, fr_dict_attr_t const *parent)
Add an enumeration value to an attribute which has not yet been defined.
static fr_dict_attr_t const * dict_protocol_reference(fr_dict_t **dict_def, char const *ref, char const *filename, int line)
dict_fixup_common_t common
Common fields.
int dict_fixup_init(TALLOC_CTX *ctx, dict_fixup_ctx_t *fctx)
Initialise a fixup ctx.
fr_dict_attr_t * parent
parent where we add the clone
fr_dlist_t entry
Entry in linked list of fctx.
char * filename
where the line being fixed up.
fr_dict_attr_t const * parent
Parent attribute to resolve the 'attribute' string in.
static int _dict_attr_fixup_hash_tables(fr_dict_attr_t const *da, UNUSED void *uctx)
Fixup all hash tables in the dictionary so they're suitable for threaded access.
static int dict_fixup_common(char const *filename, int line, fr_dlist_head_t *fixup_list, dict_fixup_common_t *common)
Initialise common fields in fixup struct, and add it to a fixup list.
dict_fixup_common_t common
Common fields.
fr_hash_table_t * hash
We need to finalise.
static int dict_fixup_group_apply(UNUSED dict_fixup_ctx_t *fctx, dict_fixup_group_t *fixup)
Resolve a group reference.
char * ref
the reference name
static int dict_fixup_enumv_apply(UNUSED dict_fixup_ctx_t *fctx, dict_fixup_enumv_t *fixup)
Add a previously defined enumeration value to an existing attribute.
#define APPLY_FIXUP(_fctx, _list, _func, _type)
char * name
Raw enum name.
void dict_hash_tables_finalise(fr_dict_t *dict)
Walk a dictionary finalising the hash tables in all attributes with a distinct namespace.
fr_dict_attr_t * da
FR_TYPE_TLV to clone.
dict_fixup_common_t common
Common fields.
int dict_fixup_clone(dict_fixup_ctx_t *fctx, char const *filename, int line, fr_dict_attr_t *parent, fr_dict_attr_t *da, char const *ref, size_t ref_len)
Clone one area of a tree into another.
Clone operation from one tree node to another.
Common fields for every fixup structure.
Add an enumeration value to an attribute that wasn't defined at the time the value was parsed.
Resolve a group reference.
Dictionary attribute namespaces need their hash tables finalised.
Functions to finalise and fixup dictionaries.
fr_dlist_head_t group
Group references to resolve.
fr_dlist_head_t clone
Clone operation to apply.
fr_dlist_head_t enumv
Raw enumeration values to add.
TALLOC_CTX * pool
Temporary pool for fixups, reduces holes.
fr_slen_t dict_by_protocol_substr(fr_dict_attr_err_t *err, fr_dict_t **out, fr_sbuff_t *name, fr_dict_t const *dict_def)
fr_dict_attr_t * dict_attr_acopy(TALLOC_CTX *ctx, fr_dict_attr_t const *in, char const *new_name)
Copy a an existing attribute.
#define DICT_FIXUP_POOL_SIZE
int dict_attr_add_to_namespace(fr_dict_attr_t const *parent, fr_dict_attr_t *da)
Add an attribute to the name table for an attribute.
int dict_attr_child_add(fr_dict_attr_t *parent, fr_dict_attr_t *child)
Add a child to a parent.
int dict_attr_acopy_children(fr_dict_t *dict, fr_dict_attr_t *dst, fr_dict_attr_t const *src)
Copy the children of an existing attribute.
int dict_attr_acopy_enumv(fr_dict_attr_t *dst, fr_dict_attr_t const *src)
Copy the VALUEs of an existing attribute, by casting them.
static int fr_dlist_insert_tail(fr_dlist_head_t *list_head, void *ptr)
Insert an item into the tail of a list.
#define fr_dlist_talloc_init(_head, _type, _field)
Initialise the head structure of a doubly linked list.
Head of a doubly linked list.
Entry in a doubly linked list.
char const * fr_cwd_strip(char const *filename)
Intended to be used in logging functions to make output more readable.
bool fr_hash_table_insert(fr_hash_table_t *ht, void const *data)
Insert data into a hash table.
void fr_hash_table_fill(fr_hash_table_t *ht)
Ensure all buckets are filled.
@ FR_TYPE_TLV
Contains nested attributes.
static unsigned int hash(char const *username, unsigned int tablesize)
#define FR_SBUFF_IN(_start, _len_or_end)
fr_aka_sim_id_type_t type
char * talloc_bstrndup(TALLOC_CTX *ctx, char const *in, size_t inlen)
Binary safe strndup function.
#define fr_strerror_printf(_fmt,...)
Log to thread local error buffer.
#define fr_strerror_printf_push(_fmt,...)
Add a message to an existing stack of messages at the tail.
#define fr_strerror_const(_msg)
#define fr_type_is_non_leaf(_x)
static char const * fr_type_to_str(fr_type_t type)
Return a static string containing the type name.
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)
void fr_value_box_clear(fr_value_box_t *data)
Clear/free any existing value and metadata.
#define fr_box_strvalue_buffer(_val)
#define FR_VALUE_BOX_INITIALISER_NULL(_vb)
A static initialiser for stack/globally allocated boxes.