28 #define _DICT_PRIVATE 1
30 #include <freeradius-devel/protocol/base.h>
31 #include <freeradius-devel/util/dict.h>
32 #include <freeradius-devel/util/dict_ext_priv.h>
33 #include <freeradius-devel/util/dl.h>
34 #include <freeradius-devel/util/hash.h>
35 #include <freeradius-devel/util/value.h>
37 #define DICT_POOL_SIZE (1024 * 1024 * 2)
38 #define DICT_FIXUP_POOL_SIZE (1024)
45 #define INTERNAL_IF_NULL(_dict, _ret) \
48 _dict = dict_gctx ? dict_gctx->internal : NULL; \
49 if (unlikely(!(_dict))) { \
50 fr_strerror_const("No dictionaries available for attribute resolution"); \
211 #define dict_attr_init(_da_p, _parent, _name, _attr, _type, _args) \
212 _dict_attr_init(__FILE__, __LINE__, _da_p, _parent, _name, _attr, _type, _args)
216 char const *
name,
unsigned int attr,
219 #define dict_attr_init_name_only(_da_p, _parent, _name, _type, _args) \
220 _dict_attr_init_name_only(__FILE__, __LINE__, _da_p, _parent, _name, _type, _args)
227 #define dict_attr_alloc_root(_ctx, _dict, _name, _attr, _args) \
228 _dict_attr_alloc_root(__FILE__, __LINE__, _ctx, _dict, _name, _attr, _args)
232 char const *
name,
int attr,
235 #define dict_attr_alloc(_ctx, _parent, _name, _attr, _type, _args) \
236 _dict_attr_alloc(__FILE__, __LINE__, _ctx, _parent, _name, _attr, _type, (_args))
240 char const *
name,
int attr,
fr_dict_attr_err_t
Errors returned by attribute lookup functions.
Values of the encryption flags.
Protocol-specific callbacks in libfreeradius-PROTOCOL.
char * dict_dir_default
The default location for loading dictionaries if one wasn't provided.
fr_hash_table_t * protocol_by_name
Hash containing names of all the registered protocols.
fr_dlist_t entry
Entry in the list of filenames.
fr_hash_table_t * vendors_by_name
Lookup vendor by name.
fr_hash_table_t * vendors_by_num
Lookup vendor by PEN.
fr_dict_t * dict_by_da(fr_dict_attr_t const *da)
Internal version of fr_dict_by_da.
bool in_protocol_by_num
Whether the dictionary has been inserted into the protocol_by_num table.
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)
int dict_attr_enum_add_name(fr_dict_attr_t *da, char const *name, fr_value_box_t const *value, bool coerce, bool replace, fr_dict_attr_t const *child_struct)
int dict_attr_type_init(fr_dict_attr_t **da_p, fr_type_t type)
Initialise type specific fields within the dictionary attribute.
int dict_attr_parent_init(fr_dict_attr_t **da_p, fr_dict_attr_t const *parent)
Initialise fields which depend on a parent attribute.
fr_dlist_head_t filenames
Files that this dictionary was loaded from.
fr_dict_attr_t * _dict_attr_alloc(char const *filename, int line, TALLOC_CTX *ctx, fr_dict_attr_t const *parent, char const *name, int attr, fr_type_t type, dict_attr_args_t const *args))
Allocate a dictionary attribute on the heap.
fr_dict_gctx_t * gctx
Global dictionary context this dictionary was allocated in.
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.
fr_hash_table_t * protocol_by_num
Hash containing numbers of all the registered protocols.
bool dict_attr_can_have_children(fr_dict_attr_t const *da)
See if a fr_dict_attr_t can have children.
fr_dict_attr_t * root
Root attribute of this dictionary.
void dict_attr_location_init(fr_dict_attr_t *da, char const *filename, int line)
Set where the dictionary attribute was defined.
fr_dict_t * dict_by_protocol_num(unsigned int num)
Internal version of fr_dict_by_protocol_num.
bool string_based
TACACS, etc.
bool in_protocol_by_name
Whether the dictionary has been inserted into the protocol_by_name hash.
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.
fr_dict_attr_t * _dict_attr_alloc_root(char const *filename, int line, TALLOC_CTX *ctx, fr_dict_t const *dict, char const *name, int attr, dict_attr_args_t const *args))
Allocate a dictionary root attribute on the heap.
bool read_only
If true, disallow modifications.
fr_dict_attr_flags_t const * flags
Any flags to assign to the attribute.
fr_dict_t * dict_by_protocol_name(char const *name)
Internal version of fr_dict_by_protocol_name.
int dict_attr_child_add(fr_dict_attr_t *parent, fr_dict_attr_t *child)
Add a child to a parent.
int dict_dependent_remove(fr_dict_t *dict, char const *dependent)
Decrement ref count for a dependent in a dictionary.
fr_dict_t * dict_alloc(TALLOC_CTX *ctx)
Allocate a new dictionary.
int dict_vendor_add(fr_dict_t *dict, char const *name, unsigned int num)
Add a vendor to the dictionary.
fr_dict_protocol_t const * proto
protocol-specific validation functions
fr_rb_tree_t * dependents
Which files are using this dictionary.
dl_loader_t * dict_loader
for protocol validation
int dict_attr_alias_add(fr_dict_attr_t const *parent, char const *alias, fr_dict_attr_t const *ref)
Add an alias to an existing attribute.
int dict_attr_finalise(fr_dict_attr_t **da_p, char const *name)
Set remaining fields in a dictionary attribute before insertion.
int _dict_attr_init_name_only(char const *filename, int line, fr_dict_attr_t **da_p, fr_dict_attr_t const *parent, char const *name, fr_type_t type, dict_attr_args_t const *args))
Initialise fields in a dictionary attribute structure.
fr_dict_attr_t * dict_attr_child_by_num(fr_dict_attr_t const *parent, unsigned int attr)
Internal version of fr_dict_attr_child_by_num.
char const * dependent
File holding the reference.
bool dict_attr_flags_valid(fr_dict_attr_t *da))
Validate a set of flags.
int dict_attr_num_init(fr_dict_attr_t *da, unsigned int num)
Set the attribute number (if any)
bool dict_attr_valid(fr_dict_attr_t *da)
Validate a new attribute definition.
int dict_attr_num_init_name_only(fr_dict_attr_t *da)
Set the attribute number (if any)
unsigned int vsa_parent
varies with different protocols.
int dict_dlopen(fr_dict_t *dict, char const *name)
bool loading
from fr_dict_protocol_afrom_file();
fr_dict_t const * next
for attribute overloading
fr_dict_attr_t const * attr_protocol_encapsulation
fr_hash_table_t * autoref
other dictionaries that we loaded via references
bool loaded
from fr_dict_protocol_afrom_file();
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.
fr_dict_attr_t ** fixups
Attributes that need fixing up.
TALLOC_CTX * pool
Talloc memory pool to reduce allocs.
bool free_at_exit
This gctx will be freed on exit.
int dict_dependent_add(fr_dict_t *dict, char const *dependent)
Record a new dependency on a dictionary.
fr_dict_attr_t * dict_attr_alloc_null(TALLOC_CTX *ctx, fr_dict_protocol_t const *dict)
Partial initialisation functions.
char * filename
Name of the file the dictionary was loaded on.
fr_dict_attr_t const * ref
This attribute is a reference to another attribute.
int dict_protocol_add(fr_dict_t *dict)
Add a protocol to the global protocol table.
bool dict_has_dependents(fr_dict_t *dict)
Check if a dictionary still has dependents.
fr_dict_gctx_t * dict_gctx
Top level structure containing global dictionary state.
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.
bool perm_check
Whether we should check dictionary file permissions as they're loaded.
int _dict_attr_init(char const *filename, int line, fr_dict_attr_t **da_p, fr_dict_attr_t const *parent, char const *name, unsigned int attr, fr_type_t type, dict_attr_args_t const *args))
Initialise fields in a dictionary attribute structure.
fr_dict_attr_t * dict_attr_by_name(fr_dict_attr_err_t *err, fr_dict_attr_t const *parent, char const *name)
int count
How many references are held by this file.
Optional arguments for initialising/allocating attributes.
Entry recording dictionary reference holders by file.
Entry in the filename list of files associated with this dictionary.
Vendors and attribute names.
Head of a doubly linked list.
Entry in a doubly linked list.
The main red black tree structure.
fr_aka_sim_id_type_t type
static size_t char ** out