24RCSID(
"$Id: 0590afce569f2f003724b739cff75b3c9756ad91 $")
26#include <freeradius-devel/radius/defs.h>
27#include <freeradius-devel/util/conf.h>
28#include <freeradius-devel/util/dict_fixup_priv.h>
29#include <freeradius-devel/util/file.h>
30#include <freeradius-devel/util/rand.h>
31#include <freeradius-devel/util/syserror.h>
39#define DICT_MAX_ARGV (8)
45#define DICT_MAX_STACK (32)
52typedef enum CC_HINT(flag_enum) {
61#define NEST_ANY (NEST_TOP | NEST_PROTOCOL | NEST_VENDOR | NEST_ATTRIBUTE)
105 char const *dir_name,
char const *filename,
106 char const *src_file,
int src_line);
109#define CURRENT_FRAME(_dctx) (&(_dctx)->stack[(_dctx)->stack_depth])
110#define CURRENT_DA(_dctx) (CURRENT_FRAME(_dctx)->da)
117#define ASSERT_CURRENT_NEST(_dctx, _nest) fr_assert_msg(CURRENT_FRAME(_dctx)->nest == (_nest), "Expected frame type %s, got %s", \
118 fr_table_str_by_value(dict_nest_table, (_nest), "<INVALID>"), fr_table_str_by_value(dict_nest_table, CURRENT_FRAME(_dctx)->nest, "<INVALID>"))
204 if (frame->
finalise(dctx) < 0)
return NULL;
221 if ((frame->
nest & nest) != 0) {
243 if (argc >= max_argc)
break;
253 while ((*str ==
' ') ||
277 int unsigned ret = 0;
279 char const *tab =
"0123456789";
281 if ((str[0] ==
'0') &&
282 ((str[1] ==
'x') || (str[1] ==
'X'))) {
283 tab =
"0123456789abcdef";
292 if (*str ==
'.')
break;
294 c = memchr(tab, tolower((
uint8_t)*str), base);
295 if (!c)
return false;
297 if (ret >= (UINT_MAX / base))
return false;
324 char const *filename,
int line)
330 .type_size =
dict->proto->default_type_size,
331 .length =
dict->proto->default_type_length,
366 if (
strlcpy(name_buff, name_in,
sizeof(name_buff)) >=
sizeof(name_buff)) {
375 p = strchr(
name,
'[');
381 q = strchr(p + 1,
']');
401 if ((length == 0) || (length > UINT16_MAX)) {
409 if (strcmp(
name,
"octets") == 0) {
412 }
else if (strcmp(
name,
"string") == 0) {
415 }
else if (strcmp(
name,
"struct") == 0) {
418 }
else if (strcmp(
name,
"union") == 0) {
421 }
else if (strcmp(
name,
"bit") == 0) {
423 fr_strerror_const(
"Bit fields can only be defined as a MEMBER of data type 'struct'");
427 (*da_p)->flags.extra = 1;
432 }
else if (length <= 8) {
434 }
else if (length <= 16) {
436 }
else if (length <= 32) {
438 }
else if (length <= 56) {
452 (*da_p)->flags.flag_byte_offset = length;
460 (*da_p)->flags.is_known_width =
true;
461 (*da_p)->flags.length = length;
474 if (dctx->
dict->proto->attr.type_parse &&
475 !dctx->
dict->proto->attr.type_parse(&
type, da_p,
name)) {
520#define FLAG_FUNC(_name) \
521static int dict_flag_##_name(fr_dict_attr_t **da_p, UNUSED char const *value, UNUSED fr_dict_flag_parser_rule_t const *rules)\
523 (*da_p)->flags._name = 1; \
534 switch ((*da_p)->type) {
554 (*da_p)->flags.is_known_width = 0;
594 if (!(*da_p)->flags.internal) {
599 (*da_p)->flags.allow_flat =
true;
614 fr_strerror_const(
"Attributes defining a 'key' field cannot specify a key reference");
619 fr_strerror_const(
"The 'key' flag can only be used for attributes of type 'uint8', 'uint16', or 'uint32'");
623 if (da->flags.extra) {
648 fr_strerror_printf(
"Invalid reference for 'key=...'. Parent %s does not have a child attribute named %s",
649 da->parent->name,
value);
653 if (da->parent != key->parent) {
654 fr_strerror_printf(
"Invalid reference for 'key=...'. Reference %s does not share a common parent",
660 fr_strerror_printf(
"Invalid reference for 'key=...'. Reference %s is not a 'key' field",
688 if (strcmp(
value,
"uint8") == 0) {
689 da->flags.is_known_width =
true;
693 }
else if (strcmp(
value,
"uint16") == 0) {
694 da->flags.is_known_width =
true;
702 da->flags.type_size = 0;
718 fr_strerror_const(
"The 'offset' flag can only be used in combination with 'length=uint8' or 'length=uint16'");
722 offset = atoi(
value);
723 if ((offset <= 0) || (offset > 255)) {
727 da->flags.type_size = offset;
743 fr_strerror_const(
"The 'precision' flag can only be used with data types 'date' or 'time'");
752 da->flags.flag_time_res = precision;
761 if (da->flags.extra) {
781 da->flags.secret = 1;
784 fr_strerror_const(
"The 'secret' flag can only be used with data types 'string' or 'octets'");
802 fr_strerror_const(
"The 'subtype' flag can only be used with data types 'date' or 'time'");
821 da->flags.length = 2;
825 da->flags.is_unsigned =
true;
826 da->flags.length = 2;
831 da->flags.length = 4;
835 da->flags.is_unsigned =
true;
836 da->flags.length = 4;
841 da->flags.length = 8;
845 da->flags.is_unsigned =
true;
846 da->flags.length = 8;
875static
int dict_option_split(
char **key,
char **
value,
char **next,
char *p)
884 for (q = p + 1; *q && (*q !=
'=') && (*q !=
','); q++) {
895 if (!*q || (*q ==
',')) {
921 {
L(
"array"), { .func = dict_flag_array } },
923 {
L(
"counter"), { .func = dict_flag_counter } },
926 {
L(
"internal"), { .func = dict_flag_internal } },
934 {
L(
"unsafe"), { .func = dict_flag_unsafe } },
936 static size_t dict_common_flags_len =
NUM_ELEMENTS(dict_common_flags);
938 char *p, *next = NULL;
945 for (p =
name; p && *p !=
'\0' ; p = next) {
949 if (dict_option_split(&key, &
value, &next, p) < 0)
return -1;
955 if (!((dctx->
dict->proto->attr.flags.table &&
956 fr_dict_attr_flag_to_parser(&parser, dctx->
dict->proto->attr.flags.table,
957 dctx->
dict->proto->attr.flags.table_len, key, NULL)) ||
958 fr_dict_attr_flag_to_parser(&parser, dict_common_flags, dict_common_flags_len, key, NULL))) {
991static inline CC_HINT(always_inline)
1098 if (!da->parent)
return 1;
1106 if (!dup_name && !dup_num)
return 1;
1108 found = dup_name ? dup_name : dup_num;
1127 if ((da->type == found->type) &&
1136 fr_strerror_printf(
"Duplicate attribute name '%s' in namespace '%s'. Originally defined %s[%d]",
1141 fr_strerror_printf(
"Duplicate attribute number %u in parent '%s'. Originally defined %s[%d]",
1160 if (da->flags.is_known_width) {
1162 fr_strerror_printf(
"MEMBERs of %s struct[%u] do not exactly fill the fixed-size structure",
1163 da->name, da->flags.length);
1205 char const *type_name,
char *flag_name,
1215 if (strncmp(
name,
"Attr-", 5) == 0) {
1239 da->dict = dctx->
dict;
1251 memcpy(&da->flags, base_flags,
sizeof(da->flags));
1253 if (
unlikely(strcmp(type_name,
"auto") == 0)) {
1255 char const *p, *end;
1257 if (!flag_name || !(p = strstr(flag_name,
"clone="))) {
1258 fr_strerror_const(
"Data type of 'auto' is missing the required flag 'clone=...'");
1263 for (end = p; *end !=
'\0'; end++) {
1264 if (*end ==
',')
break;
1269 fr_strerror_const(
"Data type 'auto' requires that the 'clone=...' reference points to an attribute which already exists");
1317 bool required =
true;
1320 int src_line = dctx->
line;
1322 char const *filename;
1329 if ((argv[0][8] !=
'\0') && ((argv[0][8] !=
'-') || (argv[0][9] !=
'\0'))) {
1340 required = (argv[0][8] !=
'-');
1346 if (strncmp(pattern,
"${dictdir}/", 11) == 0) {
1402 bool continuation =
false;
1411 if ((strlen(p) < 3) ||
1415 (p[3] && (p[3] !=
','))) {
1421 type = (int)(p[0] -
'0');
1422 length = (int)(p[2] -
'0');
1429 if ((length != 0) && (length != 1) && (length != 2)) {
1441 if ((p[4] !=
'c') ||
1447 continuation =
true;
1449 if ((
type != 1) || (length != 1)) {
1457 *pcontinuation = continuation;
1482 if (strncmp(argv[0],
"Attr-", 5) == 0) {
1487 if (strchr(argv[0],
'.') != NULL) {
1488 fr_strerror_const(
"ALIAS names must be in the local context, and cannot contain '.'");
1513 if (argv[1][0] ==
'@') {
1517 }
else if (argv[1][0] ==
'.') {
1518 if (argv[1][1] ==
'.') {
1519 fr_strerror_const(
"An ALIAS reference cannot use '..' to go back up to another parent");
1524 fr_strerror_const(
"An ALIAS reference must use a leading '.' when referring to attributes with the same parent");
1552 bool set_relative_attr;
1561 if ((argc < 3) || (argc > 4)) {
1566#ifdef STATIC_ANALYZER
1567 if (!dctx->
dict)
return -1;
1575 if (argv[1][0] !=
'.') {
1579 if (!frame)
return -1;
1587 if (strchr(argv[1],
'.') == 0) {
1595 if (slen <= 0)
return -1;
1604 set_relative_attr = (
strcasecmp(argv[2],
"tlv") == 0);
1608 fr_strerror_printf(
"No parent attribute reference was set for partial OID %s", argv[1]);
1615 if (slen <= 0)
return -1;
1617 set_relative_attr =
false;
1626 fr_strerror_printf(
"Member %s of ATTRIBUTE %s type 'struct' MUST use the \"MEMBER\" keyword",
1675 box.vb_uint32 = attr;
1685 (argc > 3) ? argv[3] : NULL, base_flags) < 0) {
1690 fr_strerror_const(
"Bit fields can only be defined as a MEMBER of data type 'struct'");
1698 fr_strerror_const(
"ATTRIBUTEs of type 'union' can only be defined as a MEMBER of data type 'struct'");
1705 if (key && (
parent->flags.is_known_width)) {
1706 if (!da->flags.is_known_width) {
1707 da->flags.is_known_width = 1;
1708 da->flags.length =
parent->flags.length;
1710 }
else if (da->flags.length !=
parent->flags.length) {
1711 fr_strerror_printf(
"Invalid length %u for struct, the parent union %s has a different length %u",
1717#ifdef WITH_DICTIONARY_WARNINGS
1722 if (!vendor && (attr < 256) &&
1723 !strstr(fn,
"rfc") && !strstr(fn,
"illegal")) {
1724 fprintf(stderr,
"WARNING: Illegal attribute %s in %s\n",
1766 if (
parent->flags.is_root) dctx->
dict->vsa_parent = attr;
1833 if (!
fr_cond_assert_msg(frame,
"Context stack doesn't have an attribute or dictionary "
1834 "root to begin searching from %s[%d]", dctx->
filename, dctx->
line) ||
1847 fr_strerror_printf(
"BEGIN %s is not resolvable in current context '%s'", argv[0], frame->
da->name);
1905 fr_strerror_printf(
"BEGIN-PROTOCOL cannot be used inside of any other BEGIN/END block. Previous definition is at %s[%d]",
1919 found->loading =
true;
1959 if (strncmp(argv[1],
"parent=", 7) != 0) {
1973 "Attribute '%s' should be 'vsa' but is '%s'", p,
1980 }
else if (dctx->
dict->vsa_parent) {
1991 }
else if (dctx->
dict->string_based) {
1992 vsa_da = dctx->
dict->root;
1995 fr_strerror_printf(
"BEGIN-VENDOR is forbidden for protocol %s - it has no ATTRIBUTE of type 'vsa'",
1996 dctx->
dict->root->name);
2002 fr_strerror_printf(
"Nested BEGIN-VENDOR is forbidden. Previous definition is at %s[%d]",
2051 if ((argc < 2) || (argc > 3)) {
2065 fr_strerror_printf(
"Member %s of parent %s type 'struct' MUST use the \"MEMBER\" keyword",
2071 fr_strerror_printf(
"Parent attribute %s is of type 'union', and cannot use DEFINE for children",
2082 (argc > 2) ? argv[2] : NULL, base_flags) < 0) {
2102 fr_strerror_const(
"Bit fields can only be defined as a MEMBER of data type 'struct'");
2106#ifdef STATIC_ANALYZER
2107 if (!dctx->
dict)
goto error;
2114 da->flags.name_only =
true;
2212 if (argc == 0)
return 0;
2227 if (da != current) {
2228 fr_strerror_printf(
"END %s does not match previous BEGIN %s", argv[0], current->name);
2254 if (found != dctx->
dict) {
2256 argv[0], dctx->
dict->root->name);
2268 fr_strerror_printf(
"END-PROTOCOL %s does not match previous BEGIN-PROTOCOL %s", argv[0],
2347 if (strncmp(argv[0],
"Attr-", 5) == 0) {
2352#ifdef STATIC_ANALYZER
2353 if (!dctx->
dict)
goto error;
2361 if (
unlikely(da == NULL))
return -1;
2363 da->dict = dctx->
dict;
2368 memcpy(&da->flags, base_flags,
sizeof(da->flags));
2370 da->flags.name_only =
true;
2371 da->flags.internal =
true;
2373 flags.is_enum =
true;
2386 fr_strerror_const(
"Bit fields can only be defined as a MEMBER of a data type 'struct'");
2450 if (strcmp(p,
"internal") == 0) {
2468 if ((argc < 2) || (argc > 3)) {
2474 fr_strerror_printf(
"MEMBER can only be used for ATTRIBUTEs of type 'struct', not for data type %s",
2484 fr_strerror_printf(
"Cannot add MEMBER to 'struct' %s after a variable sized member %s",
2499 (argc > 2) ? argv[2] : NULL, base_flags) < 0) {
2503#ifdef STATIC_ANALYZER
2504 if (!dctx->
dict)
goto error;
2536 da->flags.flag_byte_offset = (da->flags.length + previous->flags.flag_byte_offset) & 0x07;
2539 if (previous->flags.flag_byte_offset != 0) {
2575 fr_strerror_printf(
"'struct' %s has a 'length' field %s, and cannot end with a TLV %s",
2653 if (!da->flags.is_known_width) {
2659 fr_strerror_printf(
"'struct' %s has fixed size %u, but member %s is of unknown size",
2695 fr_strerror_printf(
"'struct' %s has fixed size %u, but member %s overflows that length",
2754 enum_len = strlen(argv[1]);
2786 fr_strerror_printf(
"Invalid VALUE name '%s' for attribute '%s' - the name cannot be an integer", argv[1], da->name);
2802 argv[0], strlen(argv[0]),
2803 argv[1], strlen(argv[1]),
2804 argv[2], strlen(argv[2]),
parent) < 0) {
2815 fr_strerror_printf(
"Cannot define VALUE for attribute '%s' of data type '%s'", da->name,
2826 argv[2], strlen(argv[2]),
2851 bool continuation =
false;
2859 if ((argc < 2) || (argc > 3)) {
2892 mutable->type =
type;
2893 mutable->length = length;
2894 mutable->continuation = continuation;
2962 char *p, *next = NULL;
2964 for (p = options; *p !=
'\0'; p = next) {
2968 if (dict_option_split(&key, &
value, &next, p) < 0)
return -1;
2975 fr_strerror_printf(
"Missing value for PROTOCOL option '%s', write '%s=<value>'", key, key);
2988 if (strcmp(
value,
"string") == 0) {
3011 if (size.vb_size == 0) {
3013 "expected a size greater than zero",
value);
3022 if (strcmp(
value,
"lib") != 0) {
3043 unsigned int required_value;
3044 char const *required_name;
3051 fr_strerror_const(
"PROTOCOL definitions cannot occur inside of any other BEGIN/END block");
3058 if ((argc < 2) || (argc > 3)) {
3059 fr_strerror_const(
"Missing arguments after PROTOCOL. Expected PROTOCOL <name> <number>");
3084 if (required_value && (required_value !=
value)) {
3093 if (required_name && (
strcasecmp(required_name, argv[0]) != 0)) {
3094 fr_strerror_printf(
"Invalid value '%u' for PROTOCOL '%s' - that value is already used by '%s'",
3095 value, argv[0], required_name);
3107#ifdef STATIC_ANALYZER
3108 if (!
dict->root)
return -1;
3118#ifdef STATIC_ANALYZER
3119 if (!
dict->root || !
dict->root->name || !argv[0])
return -1;
3124 dict->root->name, argv[0],
dict->root->attr);
3134 fr_strerror_printf(
"Conflicting flags for PROTOCOL \"%s\" (current %d versus new %u)",
3145 fr_strerror_printf(
"Cannot set PROTOCOL option 'pool', PROTOCOL '%s' is already defined. "
3146 "Move 'pool' to the first PROTOCOL line for '%s'",
3147 dict->root->name,
dict->root->name);
3158 if (!
dict)
return -1;
3183 mutable->flags.type_size = opts.
type_size;
3184 mutable->flags.length = 1;
3219 char const *src_file,
int src_line)
3250 *filename_out =
file->filename;
3270 char const *src_file,
int src_line)
3278 if (!
file)
return false;
3280 if (!src_file)
return true;
3283 if (!src->src_file)
return true;
3284 if (src->src_line != src_line)
continue;
3285 if (strcmp(src->src_file, src_file) == 0)
return true;
3295 if (!
dict)
return false;
3378 char const *dir,
char const *filename,
3379 char const *src_file,
int src_line)
3399 char filename_buf[256];
3404 struct stat statbuf;
3425 if (FR_DIR_IS_RELATIVE(filename)) {
3434 if ((strlen(dir) + 2 + strlen(filename)) >
sizeof(filename_buf)) {
3443 for (q = dir; *q !=
'\0'; q++) {
3453 if (slash)
continue;
3459 if (!slash) *(p++) =
'/';
3462 filename = filename_buf;
3474 fr_strerror_printf(
"ERROR - we have a recursive $INCLUDE or load of file %s", filename);
3479 if ((fp = fopen(filename,
"r")) == NULL) {
3483 fr_strerror_printf(
"Error reading dictionary: %s[%d]: Couldn't open dictionary '%s': %s",
3493 if (fstat(fileno(fp), &statbuf) < 0) {
3501 if (!S_ISREG(statbuf.st_mode)) {
3513 "Refusing to start due to insecure configuration", filename);
3519 old_line = dctx->
line;
3533 while (fgets(buf,
sizeof(buf), fp) != NULL) {
3534 bool do_begin =
false;
3536 char **argv_p = argv;
3561 p = strchr(buf,
'#');
3565 if (argc == 0)
continue;
3571 if ((strcmp(argv[0],
"BEGIN") == 0) ||
3572 (fr_dict_keyword(&parser, keywords,
NUM_ELEMENTS(keywords), argv_p[0], NULL))) {
3599 if (fr_dict_keyword(&parser, keywords,
NUM_ELEMENTS(keywords), argv_p[0], NULL)) {
3607 if (do_begin && !parser->
begin) {
3611 if (
unlikely(parser->
parse(dctx, argv_p + 1 , argc - 1, &base_flags) < 0))
goto error;
3616 if (do_begin &&
unlikely(parser->
begin(dctx) < 0))
goto error;
3683 if (frame->
finalise(dctx) < 0)
goto error;
3699 char const *dir_name,
char const *filename,
3700 char const *src_file,
int src_line)
3705 memset(&dctx, 0,
sizeof(dctx));
3745 char *dict_path = NULL;
3753 fr_strerror_const(
"fr_dict_global_ctx_init() must be called before loading dictionary files");
3787 TALLOC_FREE(dict_path);
3854 box.vb_uint8 = p->
value;
3881 char *dict_dir = NULL;
3888 fr_strerror_const(
"fr_dict_global_ctx_init() must be called before loading dictionary files");
3893 fr_strerror_const(
"Internal dictionary must be initialised before loading protocol dictionaries");
3924 dict->loaded =
true;
3956 fr_strerror_printf(
"Dictionary \"%s\" missing \"BEGIN-PROTOCOL %s\" declaration", dict_dir, proto_name);
3963 dict->loaded =
true;
3964 if (
dict->proto &&
dict->proto->init) {
3965 if (
dict->proto->init() < 0)
goto error;
3967 dict->loading =
false;
3969 dict->dir = talloc_steal(
dict, dict_dir);
3993 fr_strerror_printf(
"fr_dict_global_ctx_init() must be called before loading dictionary files");
4001 if (!
dict)
return NULL;
4027 if (!dir) dir =
dict->dir;
4034 if (!
dict->vendors_by_name) {
4035 fr_strerror_printf(
"%s: Must initialise dictionary before calling fr_dict_read()", __FUNCTION__);
4067 memset(&dctx, 0,
sizeof(dctx));
4088 argv[1],
dict->root->name);
4093 }
else if (
strcasecmp(argv[0],
"ATTRIBUTE") == 0) {
4099 argv + 1, argc - 1, &base_flags);
4101 }
else if (
strcasecmp(argv[0],
"DEFINE") == 0) {
4107 argv + 1, argc - 1, &base_flags);
4109 }
else if (
strcasecmp(argv[0],
"VENDOR") == 0) {
4117 if (ret < 0)
goto error;
4141 fr_strerror_const(
"fr_dict_global_ctx_init() must be called before loading dictionary files");
4146 fr_strerror_const(
"Internal dictionary must be initialised before loading test dictionaries");
4153 if (!
dict)
return -1;
4174 dict->loaded =
true;
4175 dict->loading =
false;
static int const char char buffer[256]
strcpy(log_entry->msg, buffer)
#define UNCONST(_type, _ptr)
Remove const qualification from a pointer.
#define L(_str)
Helper for initialising arrays of string literals.
#define fr_cond_assert(_x)
Calls panic_action ifndef NDEBUG, else logs error and evaluates to value of _x.
#define FR_FAULT_LOG(_fmt,...)
#define fr_cond_assert_msg(_x, _fmt,...)
Calls panic_action ifndef NDEBUG, else logs error and evaluates to value of _x.
int fr_dict_attr_add_initialised(fr_dict_attr_t *da)
A variant of fr_dict_attr_t that allows a pre-allocated, populated fr_dict_attr_t to be added.
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.
char const * name
Vendor name.
unsigned int is_root
Is root of a dictionary.
char const char const * dependent
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.
int fr_dict_protocol_reference(fr_dict_attr_t const **da_p, fr_dict_attr_t const *root, fr_sbuff_t *in)
Resolve a reference string to a dictionary attribute.
fr_dict_attr_t const * fr_dict_attr_by_name(fr_dict_attr_err_t *err, fr_dict_attr_t const *parent, char const *attr))
Locate a fr_dict_attr_t by its name.
fr_dict_attr_t * fr_dict_attr_unconst(fr_dict_attr_t const *da)
Coerce to non-const.
@ FLAG_LENGTH_UINT8
string / octets type is prefixed by uint8 of length
@ FLAG_LENGTH_UINT16
string / octets type is prefixed by uint16 of length
@ FLAG_KEY_FIELD
this is a key field for a subsequent struct
@ FLAG_BIT_FIELD
bit field inside of a struct
fr_slen_t fr_dict_attr_by_oid_legacy(fr_dict_attr_t const **parent, unsigned int *attr, char const *oid)
Get the leaf attribute of an OID string.
fr_dict_attr_t const * fr_dict_root(fr_dict_t const *dict)
Return the root attribute of a dictionary.
fr_dict_flag_parse_func_t func
Custom parsing function to convert a flag value string to a C type value.
unsigned int internal
Internal attribute, should not be received in protocol packets, should not be encoded.
#define da_is_bit_field(_da)
uint32_t pen
Private enterprise number.
#define da_is_length_field(_da)
char const * fr_dict_attr_filename(fr_dict_attr_t const *da)
Resolve an attribute's location file id to the filename.
char const * fr_dict_global_ctx_dir(void)
@ FR_DICT_ATTR_EXT_ENUMV
Enumeration values.
@ FR_DICT_ATTR_EXT_REF
Attribute references another attribute and/or dictionary.
@ FR_DICT_ATTR_EXT_KEY
UNION attribute references a key.
fr_dict_vendor_t const * fr_dict_vendor_by_name(fr_dict_t const *dict, char const *name)
Look up a vendor by its name.
bool needs_value
This parsing flag must have a value. Else we error.
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.
fr_dict_vendor_t const * fr_dict_vendor_by_num(fr_dict_t const *dict, uint32_t vendor_pen)
Look up a vendor by its PEN.
fr_slen_t fr_dict_enum_name_from_substr(fr_sbuff_t *out, fr_sbuff_err_t *err, fr_sbuff_t *in, fr_sbuff_term_t const *tt)
Extract an enumeration name from a string.
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.
#define fr_dict_attr_is_key_field(_da)
static int8_t fr_dict_attr_cmp_fields(const fr_dict_attr_t *a, const fr_dict_attr_t *b)
Compare two dictionary attributes by their contents.
Values of the encryption flags.
Protocol specific custom flag definitnion.
#define fr_dict_attr_ref_type(_type)
fr_dict_attr_ref_type_t type
The state of the reference.
static void * fr_dict_attr_ext(fr_dict_attr_t const *da, fr_dict_attr_ext_t ext)
#define fr_dict_attr_ref_is_unresolved(_type)
@ FR_DICT_ATTR_REF_ENUM
The attribute is an enumeration value.
@ FR_DICT_ATTR_REF_KEY
it is a UNION which has a ref to a key, and children.
@ FR_DICT_ATTR_REF_ALIAS
The attribute is an alias for another attribute.
@ FR_DICT_ATTR_REF_CLONE
The attribute is a "copy" of another attribute.
Attribute extension - Holds a reference to an attribute in another dictionary.
static int dict_attr_ref_set(fr_dict_attr_t const *da, fr_dict_attr_t const *ref, fr_dict_attr_ref_type_t type)
static int dict_attr_ref_aunresolved(fr_dict_attr_t **da_p, char const *ref, fr_dict_attr_ref_type_t type)
static void * dict_attr_ext_alloc(fr_dict_attr_t **da_p, fr_dict_attr_ext_t ext)
Allocate an attribute extension.
int dict_fixup_apply(dict_fixup_ctx_t *fctx)
Apply all outstanding fixes to a set of dictionaries.
int dict_fixup_enumv_enqueue(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.
int dict_fixup_alias_enqueue(dict_fixup_ctx_t *fctx, char const *filename, int line, fr_dict_attr_t *alias_parent, char const *alias, fr_dict_attr_t *ref_parent, char const *ref)
Resolve a group reference.
int dict_fixup_clone_enqueue(dict_fixup_ctx_t *fctx, fr_dict_attr_t *da, char const *ref)
Clone one area of a tree into another.
int dict_fixup_clone_enum_enqueue(dict_fixup_ctx_t *fctx, fr_dict_attr_t *da, char const *ref)
Clone enumeration values from one attribute to another.
int dict_fixup_vsa_enqueue(dict_fixup_ctx_t *fctx, fr_dict_attr_t *da)
Push a fixup for a VSA.
int dict_fixup_clone(fr_dict_attr_t **dst_p, fr_dict_attr_t const *src)
Clone a dictionary attribute from a ref.
int dict_fixup_group_enqueue(dict_fixup_ctx_t *fctx, fr_dict_attr_t *da, char const *ref)
Resolve a group reference.
int dict_fixup_init(dict_fixup_ctx_t *fctx)
Initialise a fixup ctx.
TALLOC_CTX * pool
Temporary pool for fixups, reduces holes.
void dict_attr_location_init(fr_dict_t *dict, fr_dict_attr_t *da, char const *filename, int line)
Set where the dictionary attribute was defined.
char const * src_file
File which did the $INCLUDE.
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.
#define dict_attr_alloc(_ctx, _parent, _name, _attr, _type, _args)
#define INTERNAL_IF_NULL(_dict, _ret)
Set the internal dictionary if none was provided.
int src_line
Line of the $INCLUDE in src_file.
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_child_by_num(fr_dict_attr_t const *parent, unsigned int attr)
Internal version of fr_dict_attr_child_by_num.
fr_dict_t * dict_by_protocol_num(unsigned int num)
Internal version of fr_dict_by_protocol_num.
int dict_attr_child_add(fr_dict_attr_t *parent, fr_dict_attr_t *child)
Add a child to a parent.
fr_dict_filename_t * dict_filename_intern(fr_dict_t *dict, char const *filename)
Return the table entry for a filename, creating the entry if the filename is not in the table.
int dict_vendor_add(fr_dict_t *dict, char const *name, unsigned int num)
Add a vendor to the dictionary.
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_num_init(fr_dict_attr_t *da, unsigned int num)
Set the attribute number (if any)
int dict_attr_num_init_name_only(fr_dict_attr_t *da)
Set the attribute number (if any)
int dict_dlopen(fr_dict_t *dict, char const *name)
fr_dict_t * dict_by_protocol_name(char const *name)
Internal version of fr_dict_by_protocol_name.
fr_dict_t * dict_alloc(TALLOC_CTX *ctx, size_t pool_size)
Allocate a new dictionary.
int dict_attr_alias_add(fr_dict_attr_t const *parent, char const *alias, fr_dict_attr_t const *ref, bool from_public)
Add an alias to an existing attribute.
fr_dict_t * internal
Magic internal dictionary.
fr_dict_attr_t * dict_attr_alloc_null(TALLOC_CTX *ctx, fr_dict_protocol_t const *dict)
Partial initialisation functions.
int dict_dependent_add(fr_dict_t *dict, char const *dependent)
Record a new dependency on a dictionary.
char * filename
Name of the file the dictionary was loaded from.
#define dict_attr_alloc_root(_ctx, _dict, _name, _attr, _args)
int dict_protocol_add(fr_dict_t *dict)
Add a protocol to the global protocol table.
fr_dict_gctx_t * dict_gctx
Top level structure containing global dictionary state.
bool perm_check
Whether we should check dictionary file permissions as they're loaded.
Optional arguments for initialising/allocating attributes.
One load or $INCLUDE of a dictionary file.
Entry in the table of files associated with this dictionary.
fr_dict_keyword_finalise_t finalise
function to call when popping
bool fr_dict_filename_loaded(fr_dict_t const *dict, char const *dir, char const *filename)
static int dict_flag_flat(fr_dict_attr_t **da_p, UNUSED char const *value, UNUSED fr_dict_flag_parser_rule_t const *rule)
"flat"
static fr_table_num_sorted_t const dict_nest_table[]
static int dict_read_process_include(dict_tokenize_ctx_t *dctx, char **argv, int argc, char const *dir)
dict_nest_t nest
for manual vs automatic begin / end things
static int dict_read_process_common(dict_tokenize_ctx_t *dctx, fr_dict_attr_t **da_p, fr_dict_attr_t const *parent, char const *name, char const *type_name, char *flag_name, fr_dict_attr_flags_t const *base_flags)
static int dict_process_type_field(dict_tokenize_ctx_t *dctx, char const *name_in, fr_dict_attr_t **da_p)
static int dict_read_process_attribute(dict_tokenize_ctx_t *dctx, char **argv, int argc, fr_dict_attr_flags_t *base_flags)
int member_num
structure member numbers
static int dict_filename_add(char **filename_out, fr_dict_t *dict, char const *filename, char const *src_file, int src_line)
Record a dictionary file we've loaded.
static int dict_read_process_alias(dict_tokenize_ctx_t *dctx, char **argv, int argc, UNUSED fr_dict_attr_flags_t *base_flags)
static int _dict_from_file(dict_tokenize_ctx_t *dctx, char const *dir_name, char const *filename, char const *src_file, int src_line)
fr_dict_section_begin_t begin
Can have a BEGIN prefix.
static int dict_attr_allow_dup(fr_dict_attr_t const *da)
Check if this definition is a duplicate, and if it is, whether we should skip it error out.
int fr_dict_parse_str(fr_dict_t *dict, char const *input, fr_dict_attr_t const *parent)
size_t pool_size
Pool size in bytes, from pool=<size>. 0 selects DICT_POOL_SIZE.
static int dict_finalise(dict_tokenize_ctx_t *dctx)
static int dict_read_process_member(dict_tokenize_ctx_t *dctx, char **argv, int argc, fr_dict_attr_flags_t *base_flags)
fr_dict_t * fr_dict_alloc(char const *proto_name, unsigned int proto_number)
static int dict_flag_ref(fr_dict_attr_t **da_p, char const *value, UNUSED fr_dict_flag_parser_rule_t const *rule)
static int dict_flag_precision(fr_dict_attr_t **da_p, char const *value, UNUSED fr_dict_flag_parser_rule_t const *rule)
static fr_table_num_ordered_t const dict_proto_table[]
The main protocols that we care about.
static int dict_read_process_end(dict_tokenize_ctx_t *dctx, char **argv, int argc, fr_dict_attr_flags_t *base_flags)
int stack_depth
points to the last used stack frame
ssize_t struct_size
size of the struct.
static bool dict_read_sscanf_i(unsigned int *pvalue, char const *str)
static int dict_read_process_end_protocol(dict_tokenize_ctx_t *dctx, char **argv, int argc, fr_dict_attr_flags_t *base_flags)
int fr_dict_afrom_file(fr_dict_t **out, char const *dir, char const *filename)
Load one dictionary file.
fr_dict_attr_t const * struct_is_closed
no more members are allowed
unsigned int type_size
Size in octets of the 'type' field, from format=<n>.
char * filename
current filename
int(* fr_dict_keyword_parse_t)(dict_tokenize_ctx_t *dctx, char **argv, int argc, fr_dict_attr_flags_t *base_flags)
Keyword parser.
static int dict_read_process_vendor(dict_tokenize_ctx_t *dctx, char **argv, int argc, UNUSED fr_dict_attr_flags_t *base_flags)
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
int(* fr_dict_section_begin_t)(dict_tokenize_ctx_t *dctx)
Pushes a new frame onto the top of the stack based on the current frame.
int fr_dict_str_to_argv(char *str, char **argv, int max_argc)
static int dict_read_process_define(dict_tokenize_ctx_t *dctx, char **argv, int argc, fr_dict_attr_flags_t *base_flags)
static size_t const dict_nest_table_len
static int dict_read_parse_format(char const *format, int *ptype, int *plength, bool *pcontinuation)
static int dict_read_process_begin_vendor(dict_tokenize_ctx_t *dctx, char **argv, int argc, UNUSED fr_dict_attr_flags_t *base_flags)
#define ASSERT_CURRENT_NEST(_dctx, _nest)
static dict_tokenize_frame_t const * dict_dctx_unwind_until(dict_tokenize_ctx_t *dctx, dict_nest_t nest)
Unwind the stack until it points to a particular type of stack frame.
static int dict_from_file(fr_dict_t *dict, char const *dir_name, char const *filename, char const *src_file, int src_line)
fr_dict_attr_t const * da
the da we care about
dict_protocol_opt_t
Options that can appear in the last field of a PROTOCOL line.
@ DICT_PROTOCOL_OPT_FORMAT
format=<n> or format=string.
@ DICT_PROTOCOL_OPT_VERIFY
verify=lib.
@ DICT_PROTOCOL_OPT_INVALID
Returned by the dict_protocol_opt_table lookup for an unknown name.
@ DICT_PROTOCOL_OPT_POOL
pool=<size>.
fr_dict_attr_t * value_attr
Cache of last attribute to speed up value processing.
static int dict_read_process_protocol(dict_tokenize_ctx_t *dctx, char **argv, int argc, UNUSED fr_dict_attr_flags_t *base_flag)
Register the specified dictionary as a protocol dictionary.
bool string_based
true for format=string.
static int dict_read_process_end_vendor(dict_tokenize_ctx_t *dctx, char **argv, int argc, fr_dict_attr_flags_t *base_flags)
#define FLAG_FUNC(_name)
Define a flag setting function, which sets one bit in a fr_dict_attr_flags_t.
static int dict_root_set(fr_dict_t *dict, char const *name, unsigned int proto_number, char const *filename, int line)
Set a new root dictionary attribute.
static dict_tokenize_frame_t const * dict_dctx_pop(dict_tokenize_ctx_t *dctx)
Pop the current stack frame.
static fr_table_num_sorted_t const dict_protocol_opt_table[]
char * filename
name of the file where we read this entry
static int dict_set_value_attr(dict_tokenize_ctx_t *dctx, fr_dict_attr_t *da)
static int dict_read_process_enum(dict_tokenize_ctx_t *dctx, char **argv, int argc, fr_dict_attr_flags_t *base_flags)
static int dict_struct_finalise(dict_tokenize_ctx_t *dctx)
static int dict_flag_offset(fr_dict_attr_t **da_p, char const *value, UNUSED fr_dict_flag_parser_rule_t const *rule)
static int dict_read_process_begin_protocol(dict_tokenize_ctx_t *dctx, char **argv, int argc, UNUSED fr_dict_attr_flags_t *base_flags)
static int dict_flag_key(fr_dict_attr_t **da_p, char const *value, UNUSED fr_dict_flag_parser_rule_t const *rule)
fr_dict_t * dict
Protocol dictionary we're inserting attributes into.
static int dict_begin_protocol(NDEBUG_UNUSED dict_tokenize_ctx_t *dctx)
Process an inline BEGIN PROTOCOL block.
static int dict_flag_clone(fr_dict_attr_t **da_p, char const *value, UNUSED fr_dict_flag_parser_rule_t const *rules)
dict_tokenize_frame_t stack[DICT_MAX_STACK]
stack of attributes to track
int line
line number where we read this entry
static int dict_flag_enum(fr_dict_attr_t **da_p, char const *value, UNUSED fr_dict_flag_parser_rule_t const *rule)
static dict_tokenize_frame_t const * dict_dctx_unwind(dict_tokenize_ctx_t *dctx)
static int dict_process_flag_field(dict_tokenize_ctx_t *dctx, char *name, fr_dict_attr_t **da_p)
#define CURRENT_DA(_dctx)
#define DICT_MAX_ARGV
Maximum number of arguments.
static int dict_read_process_value(dict_tokenize_ctx_t *dctx, char **argv, int argc, UNUSED fr_dict_attr_flags_t *base_flags)
Process a value alias.
static dict_tokenize_frame_t const * dict_dctx_find_frame(dict_tokenize_ctx_t *dctx, dict_nest_t nest)
static size_t const dict_proto_table_len
fr_dict_keyword_parser_t value
Value to return from lookup.
static int dict_flag_length(fr_dict_attr_t **da_p, char const *value, UNUSED fr_dict_flag_parser_rule_t const *rule)
static int dict_protocol_opts_parse(dict_protocol_opts_t *opts, char *options)
Parse the comma-separated options of a PROTOCOL line.
bool require_dl
true for verify=lib. A missing protocol library then fails the load.
static bool dict_filename_loaded(fr_dict_t const *dict, char const *filename, char const *src_file, int src_line)
See if we have already loaded the file,.
int fr_dict_read(fr_dict_t *dict, char const *dir, char const *filename)
Read supplementary attribute definitions into an existing dictionary.
#define DICT_MAX_STACK
Maximum stack size.
static size_t dict_protocol_opt_table_len
static int dict_flag_subtype(fr_dict_attr_t **da_p, char const *value, UNUSED fr_dict_flag_parser_rule_t const *rule)
static int dict_read_process_begin(dict_tokenize_ctx_t *dctx, char **argv, int argc, UNUSED fr_dict_attr_flags_t *base_flags)
int fr_dict_internal_afrom_file(fr_dict_t **out, char const *dict_subdir, char const *dependent)
(Re-)Initialize the special internal dictionary
static int dict_dctx_push(dict_tokenize_ctx_t *dctx, fr_dict_attr_t const *da, dict_nest_t nest)
static int dict_read_process_flags(UNUSED dict_tokenize_ctx_t *dctx, char **argv, int argc, fr_dict_attr_flags_t *base_flags)
static int dict_attr_add_or_fixup(dict_fixup_ctx_t *fixup, fr_dict_attr_t **da_p)
Add an attribute to the dictionary, or add it to a list of attributes to clone later.
int(* fr_dict_keyword_finalise_t)(dict_tokenize_ctx_t *dctx)
#define CURRENT_FRAME(_dctx)
static void dict_attr_location_set(dict_tokenize_ctx_t *dctx, fr_dict_attr_t *da)
fr_dict_attr_t const * relative_attr
for ".82" instead of "1.2.3.82". only for parents of type "tlv"
static int dict_flag_secret(fr_dict_attr_t **da_p, UNUSED char const *value, UNUSED fr_dict_flag_parser_rule_t const *rule)
fr_table_elem_name_t name
Name of the keyword, e.g. "ATTRIBUTE".
fr_dict_keyword_parse_t parse
Function to parse the keyword with.
void dict_dctx_debug(dict_tokenize_ctx_t *dctx)
dict_nest_t
This represents explicit BEGIN/END frames pushed onto the stack.
@ NEST_TOP
top of the stack
@ NEST_VENDOR
BEGIN-VENDOR.
@ NEST_PROTOCOL
BEGIN-PROTOCOL.
@ NEST_ATTRIBUTE
BEGIN foo.
Settings parsed from the options of a PROTOCOL line.
Parser context for dict_from_file.
#define fr_dlist_foreach(_list_head, _type, _iter)
Iterate over the contents of a list.
static int fr_dlist_insert_tail(fr_dlist_head_t *list_head, void *ptr)
Insert an item into the tail of a list.
int fr_hash_table_find(void **found, fr_hash_table_t *ht, void const *data)
Find data in a hash table.
int fr_globdir_iter_init(char const **filename, char const *dir, char const *pattern, fr_globdir_iter_t *iter)
Initialize an iterator over filenames.
int fr_globdir_iter_next(char const **filename, fr_globdir_iter_t *iter)
Get the next filename.
char const * fr_cwd_strip(char const *filename)
Intended to be used in logging functions to make output more readable.
int fr_globdir_iter_free(fr_globdir_iter_t *iter)
@ FR_TYPE_TIME_DELTA
A period of time measured in nanoseconds.
@ FR_TYPE_TLV
Contains nested attributes.
@ FR_TYPE_STRING
String of printable characters.
@ FR_TYPE_NULL
Invalid (uninitialised) attribute type.
@ FR_TYPE_UINT16
16 Bit unsigned integer.
@ FR_TYPE_INT64
64 Bit signed integer.
@ FR_TYPE_INT16
16 Bit signed integer.
@ FR_TYPE_DATE
Unix time stamp, always has value >2^31.
@ FR_TYPE_UINT8
8 Bit unsigned integer.
@ FR_TYPE_UINT32
32 Bit unsigned integer.
@ FR_TYPE_STRUCT
like TLV, but without T or L, and fixed-width children
@ FR_TYPE_INT32
32 Bit signed integer.
@ FR_TYPE_VENDOR
Attribute that represents a vendor in the attribute tree.
@ FR_TYPE_UINT64
64 Bit unsigned integer.
@ FR_TYPE_BOOL
A truth value.
@ FR_TYPE_SIZE
Unsigned integer capable of representing any memory address on the local system.
@ FR_TYPE_VSA
Vendor-Specific, for RADIUS attribute 26.
@ FR_TYPE_OCTETS
Raw octets.
@ FR_TYPE_GROUP
A grouping of other attributes.
int strncasecmp(char *s1, char *s2, int n)
int strcasecmp(char *s1, char *s2)
size_t fr_sbuff_adv_past_allowed(fr_sbuff_t *sbuff, size_t len, bool const allowed[static SBUFF_CHAR_CLASS], fr_sbuff_term_t const *tt)
Wind position past characters in the allowed set.
bool const sbuff_char_class_int[SBUFF_CHAR_CLASS]
#define FR_SBUFF_IN(_start, _len_or_end)
#define FR_SBUFF_IN_STR(_start)
PUBLIC int snprintf(char *string, size_t length, char *format, va_alist)
fr_aka_sim_id_type_t type
size_t strlcpy(char *dst, char const *src, size_t siz)
char const * fr_syserror(int num)
Guaranteed to be thread-safe version of strerror.
char const * str
Literal string.
#define fr_table_value_by_str(_table, _name, _def)
Convert a string to a value using a sorted or ordered table.
#define fr_table_str_by_value(_table, _number, _def)
Convert an integer to a string.
#define TABLE_TYPE_NAME_FUNC_RPTR(_func, _our_table_type, _our_name, _our_def_type, _our_out_type)
Create a type-specific name-to-value function.
static void const * table_sorted_value_by_str(void const *table, size_t table_len, size_t element_size, char const *name)
Convert a string to a value using a lexicographically sorted table.
fr_table_elem_name_t name
An element in an arbitrarily ordered array of name to num mappings.
An element in a lexicographically sorted array of name to num mappings.
char * talloc_typed_asprintf(TALLOC_CTX *ctx, char const *fmt,...)
Call talloc vasprintf, setting the type on the new chunk correctly.
#define talloc_strdup(_ctx, _str)
fr_table_num_ordered_t const fr_time_precision_table[]
#define FR_DICTIONARY_FILE
void fr_strerror_clear(void)
Clears all pending messages from the talloc pools.
#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_push(_msg)
#define fr_strerror_printf_push_head(_fmt,...)
Add a message to an existing stack of messages at the head.
#define fr_strerror_const(_msg)
fr_table_num_ordered_t const fr_type_table[]
Map data types to names representing those types.
@ FR_TYPE_UNION
A union of limited children.
@ FR_TYPE_ATTR
A contains an attribute reference.
#define fr_type_is_structural(_x)
#define fr_type_is_null(_x)
#define fr_type_is_tlv(_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.
static fr_type_t fr_type_from_str(char const *type)
Return the constant value representing a type.
fr_slen_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)
int fr_value_box_cast_in_place(TALLOC_CTX *ctx, fr_value_box_t *vb, fr_type_t dst_type, fr_dict_attr_t const *dst_enumv)
Convert one type of fr_value_box_t to another in place.
void fr_value_box_clear(fr_value_box_t *data)
Clear/free any existing value and metadata.
#define FR_VALUE_BOX_INITIALISER_NULL(_vb)
A static initialiser for stack/globally allocated boxes.
static fr_sbuff_err_t char ** out
static fr_sbuff_err_t char size_t * len
#define fr_value_box_init(_vb, _type, _enumv, _tainted)
Initialise a fr_value_box_t.
int format(printf, 5, 0))