Multi-protocol attribute dictionary API. More...
#include <freeradius-devel/libradius.h>
Go to the source code of this file.
Data Structures | |
struct | attr_flags |
Values of the encryption flags. More... | |
struct | dict_attr |
Dictionary attribute. More... | |
struct | dict_enum |
Value of an enumerated attribute. More... | |
struct | dict_vendor |
Private enterprise. More... | |
Macros | |
#define | FR_DICT_ATTR_MAX_NAME_LEN (128) |
#define | FR_DICT_ATTR_SIZE (sizeof(fr_dict_attr_t) + FR_DICT_ATTR_MAX_NAME_LEN) |
Maximum dictionary attribute size. More... | |
#define | FR_DICT_ENUM_MAX_NAME_LEN (128) |
#define | FR_DICT_MAX_TLV_STACK (FR_DICT_TLV_NEST_MAX + 5) |
Maximum TLV stack size. More... | |
#define | FR_DICT_TLV_NEST_MAX (24) |
Maximum level of TLV nesting allowed. More... | |
#define | FR_DICT_VENDOR_MAX_NAME_LEN (128) |
#define | VERIFY_DA(_x) fr_assert(_x) |
Typedefs | |
typedef struct attr_flags | fr_dict_attr_flags_t |
Values of the encryption flags. More... | |
typedef struct dict_attr | fr_dict_attr_t |
typedef struct dict_enum | fr_dict_enum_t |
Value of an enumerated attribute. More... | |
typedef struct fr_dict | fr_dict_t |
typedef struct dict_vendor | fr_dict_vendor_t |
Private enterprise. More... | |
Functions | |
size_t | dict_print_attr_oid (char *buffer, size_t outlen, fr_dict_attr_t const *ancestor, fr_dict_attr_t const *da) |
Build the tlv_stack for the specified DA and encode the path in OID form. More... | |
int | fr_dict_attr_add (fr_dict_t *dict, fr_dict_attr_t const *parent, char const *name, int attr, PW_TYPE type, fr_dict_attr_flags_t flags) |
Add an attribute to the dictionary. More... | |
fr_dict_attr_t const * | fr_dict_attr_by_name (fr_dict_t *dict, char const *attr) |
Locate a fr_dict_attr_t by its name. More... | |
fr_dict_attr_t const * | fr_dict_attr_by_name_substr (fr_dict_t *dict, char const **name) |
Look up a dictionary attribute by a name embedded in another string. More... | |
fr_dict_attr_t const * | fr_dict_attr_by_num (fr_dict_t *dict, unsigned int vendor, unsigned int attr) |
Lookup a fr_dict_attr_t by its vendor and attribute numbers. More... | |
ssize_t | fr_dict_attr_by_oid (fr_dict_t *dict, fr_dict_attr_t const **parent, unsigned int *vendor, unsigned int *attr, char const *oid) |
Get the leaf attribute of an OID string. More... | |
fr_dict_attr_t const * | fr_dict_attr_by_type (fr_dict_t *dict, unsigned int vendor, unsigned int attr, PW_TYPE type) |
Lookup a attribute by its its vendor and attribute numbers and data type. More... | |
fr_dict_attr_t const * | fr_dict_attr_child_by_da (fr_dict_attr_t const *parent, fr_dict_attr_t const *child) |
Check if a child attribute exists in a parent using a pointer (da) More... | |
fr_dict_attr_t const * | fr_dict_attr_child_by_num (fr_dict_attr_t const *parent, unsigned int attr) |
Check if a child attribute exists in a parent using an attribute number. More... | |
int | fr_dict_enum_add (fr_dict_t *dict, char const *attr, char const *alias, int value) |
fr_dict_enum_t * | fr_dict_enum_by_da (fr_dict_t *dict, fr_dict_attr_t const *da, int value) |
Lookup the structure representing an enum value in a fr_dict_attr_t. More... | |
fr_dict_enum_t * | fr_dict_enum_by_name (fr_dict_t *dict, fr_dict_attr_t const *da, char const *val) |
char const * | fr_dict_enum_name_by_da (fr_dict_t *dict, fr_dict_attr_t const *da, int value) |
Lookup the name of an enum value in a fr_dict_attr_t. More... | |
int | fr_dict_init (TALLOC_CTX *ctx, fr_dict_t **out, char const *dir, char const *fn, char const *name) |
(re)initialize a protocol dictionary More... | |
int | fr_dict_oid_component (unsigned int *out, char const **oid) |
Process a single OID component. More... | |
fr_dict_attr_t const * | fr_dict_parent_common (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. More... | |
int | fr_dict_parse_str (fr_dict_t *dict, char *buf, fr_dict_attr_t const *parent, unsigned int vendor) |
void | fr_dict_print (fr_dict_attr_t const *da, int depth) |
int | fr_dict_read (fr_dict_t *dict, char const *dir, char const *filename) |
fr_dict_attr_t const * | fr_dict_root (fr_dict_t const *dict) |
Return the root attribute of a dictionary. More... | |
int | fr_dict_str_to_argv (char *str, char **argv, int max_argc) |
fr_dict_attr_t const * | fr_dict_unknown_add (fr_dict_t *dict, fr_dict_attr_t const *old) |
Converts an unknown to a known by adding it to the internal dictionaries. More... | |
fr_dict_attr_t * | fr_dict_unknown_afrom_fields (TALLOC_CTX *ctx, fr_dict_attr_t const *parent, unsigned int vendor, unsigned int attr) CC_HINT(nonnull) |
Allocates an unknown attribute. More... | |
fr_dict_attr_t const * | fr_dict_unknown_afrom_oid (TALLOC_CTX *ctx, fr_dict_t *dict, fr_dict_attr_t const *parent, char const *name) |
Create a fr_dict_attr_t from an ASCII attribute and value. More... | |
void | fr_dict_unknown_free (fr_dict_attr_t const **da) |
Free dynamically allocated (unknown attributes) More... | |
int | fr_dict_unknown_from_fields (fr_dict_attr_t *da, fr_dict_attr_t const *parent, unsigned int vendor, unsigned int attr) CC_HINT(nonnull) |
Initialises an unknown attribute. More... | |
int | fr_dict_unknown_from_oid (fr_dict_t *dict, fr_dict_attr_t *vendor_da, fr_dict_attr_t *da, fr_dict_attr_t const *parent, char const *name) |
Initialise a fr_dict_attr_t from an ASCII attribute and value. More... | |
int | fr_dict_unknown_from_suboid (fr_dict_t *dict, fr_dict_attr_t *vendor_da, fr_dict_attr_t *da, fr_dict_attr_t const *parent, char const **name) |
Create a dictionary attribute by name embedded in another string. More... | |
int | fr_dict_unknown_vendor_afrom_num (TALLOC_CTX *ctx, fr_dict_attr_t const **out, fr_dict_attr_t const *parent, unsigned int vendor) |
Build an unknown vendor, parented by a VSA or EVS attribute. More... | |
int | fr_dict_valid_name (char const *name) |
int | fr_dict_vendor_add (fr_dict_t *dict, char const *name, unsigned int value) |
Add a vendor to the dictionary. More... | |
int | fr_dict_vendor_by_name (fr_dict_t *dict, char const *name) |
Look up a vendor by its name. More... | |
fr_dict_vendor_t const * | fr_dict_vendor_by_num (fr_dict_t *dict, int vendor) |
Look up a vendor by its PEN. More... | |
void | fr_dict_verify (char const *file, int line, fr_dict_attr_t const *da) |
Variables | |
const size_t | dict_attr_sizes [PW_TYPE_MAX][2] |
Map data types to min / max data sizes. More... | |
const FR_NAME_NUMBER | dict_attr_types [] |
Map data types to names representing those types. More... | |
const int | fr_dict_attr_allowed_chars [256] |
fr_dict_t * | fr_dict_internal |
Internal server dictionary. More... | |
Multi-protocol attribute dictionary API.
Definition in file dict.h.
struct attr_flags |
Data Fields | ||
---|---|---|
__unnamed__ |
Data Fields | ||
---|---|---|
unsigned int | array: 1 | Pack multiples into 1 attr. |
unsigned int | compare: 1 | has a paircompare registered |
unsigned int | concat: 1 | concatenate multiple instances |
enum attr_flags | encrypt | |
unsigned int | has_tag: 1 | Tagged attribute. |
unsigned int | has_value: 1 | Has a value. |
unsigned virtual | int: 1 | for dynamic expansion |
unsigned int | internal: 1 | Internal attribute, should not be received in protocol packets, should not be encoded. |
unsigned int | is_pointer: 1 | data is a pointer |
unsigned int | is_root: 1 | Is root of a dictionary. |
unsigned int | is_unknown: 1 | Attribute number or vendor is unknown. |
uint8_t | length | length of the attribute |
uint8_t | type_size | for TLV2, size of the type |
struct dict_attr |
Data Fields | ||
---|---|---|
unsigned int | attr | Attribute number. |
fr_dict_attr_t const ** | children | Children of this attribute. |
unsigned int | depth | Depth of nesting for this attribute. |
fr_dict_attr_flags_t | flags | Flags. |
char | name[1] | Attribute name. |
fr_dict_attr_t const * | next | Next child in bin. |
fr_dict_attr_t const * | parent | Immediate parent of this attribute. |
PW_TYPE | type | Value type. |
unsigned int | vendor | Vendor that defines this attribute. |
struct dict_enum |
Data Fields | ||
---|---|---|
fr_dict_attr_t const * | da | Dictionary attribute enum is associated with. |
char | name[1] | Enum name. |
int | value | Enum value. |
struct dict_vendor |
#define FR_DICT_ATTR_SIZE (sizeof(fr_dict_attr_t) + FR_DICT_ATTR_MAX_NAME_LEN) |
#define FR_DICT_MAX_TLV_STACK (FR_DICT_TLV_NEST_MAX + 5) |
#define FR_DICT_TLV_NEST_MAX (24) |
typedef struct attr_flags fr_dict_attr_flags_t |
Values of the encryption flags.
typedef struct dict_attr fr_dict_attr_t |
typedef struct dict_enum fr_dict_enum_t |
Value of an enumerated attribute.
typedef struct dict_vendor fr_dict_vendor_t |
Private enterprise.
size_t dict_print_attr_oid | ( | char * | buffer, |
size_t | outlen, | ||
fr_dict_attr_t const * | ancestor, | ||
fr_dict_attr_t const * | da | ||
) |
Build the tlv_stack for the specified DA and encode the path in OID form.
[out] | buffer | Where to write the OID. |
[in] | outlen | Length of the output buffer. |
[in] | ancestor | If not NULL, only print OID portion between ancestor and da. |
[in] | da | to print OID string for. |
Definition at line 2525 of file dict.c.
int fr_dict_attr_add | ( | fr_dict_t * | dict, |
fr_dict_attr_t const * | parent, | ||
char const * | name, | ||
int | attr, | ||
PW_TYPE | type, | ||
fr_dict_attr_flags_t | flags | ||
) |
Add an attribute to the dictionary.
[in] | dict | of protocol context we're operating in. If NULL the internal dictionary will be used. |
[in] | parent | to add attribute under. |
[in] | name | of the attribute. |
[in] | attr | number. |
[in] | type | of attribute. |
[in] | flags | to set in the attribute. |
Definition at line 582 of file dict.c.
fr_dict_attr_t const* fr_dict_attr_by_name | ( | fr_dict_t * | dict, |
char const * | name | ||
) |
Locate a fr_dict_attr_t by its name.
[in] | dict | of protocol context we're operating in. If NULL the internal dictionary will be used. |
[in] | name | of the attribute to locate. |
Definition at line 3493 of file dict.c.
fr_dict_attr_t const* fr_dict_attr_by_name_substr | ( | fr_dict_t * | dict, |
char const ** | name | ||
) |
Look up a dictionary attribute by a name embedded in another string.
Find the first invalid attribute name char in the string pointed to by name.
Copy the characters between the start of the name string and the first none dict_attr_allowed_char to a buffer and perform a dictionary lookup using that value.
If the attribute exists, advance the pointer pointed to by name to the first none dict_attr_allowed_char char, and return the DA.
If the attribute does not exist, don't advance the pointer and return NULL.
[in] | dict | of protocol context we're operating in. If NULL the internal dictionary will be used. |
[in,out] | name | string start. |
Definition at line 3445 of file dict.c.
fr_dict_attr_t const* fr_dict_attr_by_num | ( | fr_dict_t * | dict, |
unsigned int | vendor, | ||
unsigned int | attr | ||
) |
Lookup a fr_dict_attr_t by its vendor and attribute numbers.
[in] | dict | of protocol context we're operating in. If NULL the internal dictionary will be used. |
[in] | vendor | number of the attribute. |
[in] | attr | number of the attribute. |
Definition at line 3519 of file dict.c.
ssize_t fr_dict_attr_by_oid | ( | fr_dict_t * | dict, |
fr_dict_attr_t const ** | parent, | ||
unsigned int * | vendor, | ||
unsigned int * | attr, | ||
char const * | oid | ||
) |
Get the leaf attribute of an OID string.
[in] | dict | of protocol context we're operating in. If NULL the internal dictionary will be used. |
[out] | attr | Number we parsed. |
[in,out] | vendor | number of attribute. |
[in,out] | parent | attribute (or root of dictionary). Will be updated to the parent directly beneath the leaf. |
[in] | oid | string to parse. |
Definition at line 3263 of file dict.c.
fr_dict_attr_t const* fr_dict_attr_by_type | ( | fr_dict_t * | dict, |
unsigned int | vendor, | ||
unsigned int | attr, | ||
PW_TYPE | type | ||
) |
Lookup a attribute by its its vendor and attribute numbers and data type.
[in] | dict | of protocol context we're operating in. If NULL the internal dictionary will be used. |
[in] | vendor | number of the attribute. |
[in] | attr | number of the attribute. |
[in] | type | Variant of attribute to lookup. |
Definition at line 3549 of file dict.c.
|
inline |
|
inline |
Check if a child attribute exists in a parent using an attribute number.
parent | to check for child in. |
attr | number to look for. |
Definition at line 3611 of file dict.c.
int fr_dict_enum_add | ( | fr_dict_t * | dict, |
char const * | attr, | ||
char const * | alias, | ||
int | value | ||
) |
fr_dict_enum_t* fr_dict_enum_by_da | ( | fr_dict_t * | dict, |
fr_dict_attr_t const * | da, | ||
int | value | ||
) |
Lookup the structure representing an enum value in a fr_dict_attr_t.
[in] | dict | of protocol context we're operating in. If NULL the internal dictionary will be used. |
[in] | da | to search in. |
[in] | value | number to search for. |
Definition at line 3654 of file dict.c.
fr_dict_enum_t* fr_dict_enum_by_name | ( | fr_dict_t * | dict, |
fr_dict_attr_t const * | da, | ||
char const * | val | ||
) |
char const* fr_dict_enum_name_by_da | ( | fr_dict_t * | dict, |
fr_dict_attr_t const * | da, | ||
int | value | ||
) |
Lookup the name of an enum value in a fr_dict_attr_t.
[in] | dict | of protocol context we're operating in. If NULL the internal dictionary will be used. |
[in] | da | to search in. |
[in] | value | number to search for. |
Definition at line 3688 of file dict.c.
int fr_dict_init | ( | TALLOC_CTX * | ctx, |
fr_dict_t ** | out, | ||
char const * | dir, | ||
char const * | fn, | ||
char const * | name | ||
) |
(re)initialize a protocol dictionary
Initialize the directory, then fix the attr member of all attributes.
First dictionary initialised will be set as the default internal dictionary.
[in] | ctx | to allocate the dictionary from. |
[out] | out | Where to write a pointer to the new dictionary. Will free existing dictionary if files have changed and *out is not NULL. |
[in] | dir | to read dictionary files from. |
[in] | fn | file name to read. |
[in] | name | to use for the root attributes. |
Definition at line 2148 of file dict.c.
int fr_dict_oid_component | ( | unsigned int * | out, |
char const ** | oid | ||
) |
fr_dict_attr_t const* fr_dict_parent_common | ( | 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.
a | first TLV attribute. |
b | second TLV attribute. |
is_ancestor | Enforce a->b relationship (a is parent or ancestor of b). |
Definition at line 3174 of file dict.c.
int fr_dict_parse_str | ( | fr_dict_t * | dict, |
char * | buf, | ||
fr_dict_attr_t const * | parent, | ||
unsigned int | vendor | ||
) |
void fr_dict_print | ( | fr_dict_attr_t const * | da, |
int | depth | ||
) |
int fr_dict_read | ( | fr_dict_t * | dict, |
char const * | dir, | ||
char const * | filename | ||
) |
fr_dict_attr_t const* fr_dict_root | ( | fr_dict_t const * | dict | ) |
int fr_dict_str_to_argv | ( | char * | str, |
char ** | argv, | ||
int | max_argc | ||
) |
fr_dict_attr_t const* fr_dict_unknown_add | ( | fr_dict_t * | dict, |
fr_dict_attr_t const * | old | ||
) |
Converts an unknown to a known by adding it to the internal dictionaries.
Does not free old fr_dict_attr_t, that is left up to the caller.
[in] | dict | of protocol context we're operating in. If NULL the internal dictionary will be used. |
[in] | old | unknown attribute to add. |
Definition at line 2384 of file dict.c.
fr_dict_attr_t* fr_dict_unknown_afrom_fields | ( | TALLOC_CTX * | ctx, |
fr_dict_attr_t const * | parent, | ||
unsigned int | vendor, | ||
unsigned int | attr | ||
) |
Allocates an unknown attribute.
Initialises an unknown attribute.
[in] | ctx | to allocate DA in. |
[in] | parent | of the unknown attribute (may also be unknown). |
[in] | attr | number. |
[in] | vendor | number. |
Definition at line 2613 of file dict.c.
fr_dict_attr_t const* fr_dict_unknown_afrom_oid | ( | TALLOC_CTX * | ctx, |
fr_dict_t * | dict, | ||
fr_dict_attr_t const * | parent, | ||
char const * | name | ||
) |
Create a fr_dict_attr_t from an ASCII attribute and value.
Where the attribute name is in the form:
Initialises an unknown attribute.
[in] | dict | of protocol context we're operating in. If NULL the internal dictionary will be used. |
[in] | ctx | to alloc new attribute in. |
[in] | parent | Attribute to use as the root for resolving OIDs in. Usually the root of a protocol dictionary. |
[in] | name | of attribute. |
Definition at line 2957 of file dict.c.
void fr_dict_unknown_free | ( | fr_dict_attr_t const ** | da | ) |
int fr_dict_unknown_from_fields | ( | fr_dict_attr_t * | da, |
fr_dict_attr_t const * | parent, | ||
unsigned int | vendor, | ||
unsigned int | attr | ||
) |
Initialises an unknown attribute.
Initialises a dict attr for an unknown attribute/vendor/type without adding it to dictionary pools/hashes.
Unknown attributes are used to transparently pass undecodeable attributes when we proxy requests.
[in,out] | da | struct to initialise, must be at least FR_DICT_ATTR_SIZE bytes. |
[in] | parent | of the unknown attribute (may also be unknown). |
[in] | attr | number. |
[in] | vendor | number. |
Definition at line 2571 of file dict.c.
int fr_dict_unknown_from_oid | ( | fr_dict_t * | dict, |
fr_dict_attr_t * | vendor_da, | ||
fr_dict_attr_t * | da, | ||
fr_dict_attr_t const * | parent, | ||
char const * | name | ||
) |
Initialise a fr_dict_attr_t from an ASCII attribute and value.
Where the attribute name is in the form:
Initialises an unknown attribute.
[in] | dict | of protocol context we're operating in. If NULL the internal dictionary will be used. |
[in] | vendor_da | to initialise. |
[in] | da | to initialise. |
[in] | parent | of the unknown attribute (may also be unknown). |
[in] | name | of attribute. |
Definition at line 2705 of file dict.c.
int fr_dict_unknown_from_suboid | ( | fr_dict_t * | dict, |
fr_dict_attr_t * | vendor_da, | ||
fr_dict_attr_t * | da, | ||
fr_dict_attr_t const * | parent, | ||
char const ** | name | ||
) |
Create a dictionary attribute by name embedded in another string.
Find the first invalid attribute name char in the string pointed to by name.
Copy the characters between the start of the name string and the first none dict_attr_allowed_char to a buffer and initialise da as an unknown attribute.
[in] | dict | of protocol context we're operating in. If NULL the internal dictionary will be used. |
[out] | vendor_da | will be filled in if a vendor is found. |
[out] | da | will be filled in with the da at the end of the OID chain. |
[in] | parent | Attribute to use as the root for resolving OIDs in. Usually the root of a protocol dictionary. |
[in,out] | name | string start. |
Definition at line 3034 of file dict.c.
int fr_dict_unknown_vendor_afrom_num | ( | TALLOC_CTX * | ctx, |
fr_dict_attr_t const ** | out, | ||
fr_dict_attr_t const * | parent, | ||
unsigned int | vendor | ||
) |
Build an unknown vendor, parented by a VSA or EVS attribute.
This allows us to complete the path back to the dictionary root in the case of unknown attributes with unknown vendors.
[in] | ctx | to allocate the vendor attribute in. |
[out] | out | Where to write point to new unknown dict attr representing the unknown vendor. |
[in] | parent | of the vendor attribute, either an EVS or VSA attribute. |
[in] | vendor | id. |
Definition at line 2459 of file dict.c.
int fr_dict_valid_name | ( | char const * | name | ) |
int fr_dict_vendor_add | ( | fr_dict_t * | dict, |
char const * | name, | ||
unsigned int | num | ||
) |
Add a vendor to the dictionary.
Inserts a vendor entry into the vendor hash table. This must be done before adding attributes under a VSA.
[in] | dict | of protocol context we're operating in. If NULL the internal dictionary will be used. |
[in] | name | of the vendor. |
[in] | num | Vendor's Private Enterprise Number. |
Definition at line 399 of file dict.c.
int fr_dict_vendor_by_name | ( | fr_dict_t * | dict, |
char const * | name | ||
) |
Look up a vendor by its name.
[in] | dict | of protocol context we're operating in. If NULL the internal dictionary will be used. |
[in] | name | to search for. |
Definition at line 3386 of file dict.c.
fr_dict_vendor_t const* fr_dict_vendor_by_num | ( | fr_dict_t * | dict, |
int | vendorpec | ||
) |
Look up a vendor by its PEN.
[in] | dict | of protocol context we're operating in. If NULL the internal dictionary will be used. |
[in] | vendorpec | to search for. |
Definition at line 3412 of file dict.c.
void fr_dict_verify | ( | char const * | file, |
int | line, | ||
fr_dict_attr_t const * | da | ||
) |
const size_t dict_attr_sizes[PW_TYPE_MAX][2] |
const FR_NAME_NUMBER dict_attr_types[] |