]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
add type names / values as enums to Cast-Base
authorAlan T. DeKok <aland@freeradius.org>
Mon, 17 Jan 2022 13:41:26 +0000 (08:41 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 17 Jan 2022 13:49:05 +0000 (08:49 -0500)
so that the types are in the dictionaries, which is nice.

src/lib/util/dict_tokenize.c

index 6e21dcb8384b3ebc8e1298927802bdea98a5c1bc..f4228729a7f3d4ea38f067533a9140bc43201dba 100644 (file)
@@ -2543,6 +2543,8 @@ int fr_dict_internal_afrom_file(fr_dict_t **out, char const *dict_subdir, char c
        size_t                  i;
        fr_dict_attr_flags_t    flags = { .internal = true };
        char                    *type_name;
+       fr_dict_attr_t          *cast_base;
+       fr_value_box_t          box;
 
        if (unlikely(!dict_gctx)) {
                fr_strerror_const("fr_dict_global_ctx_init() must be called before loading dictionary files");
@@ -2577,6 +2579,32 @@ int fr_dict_internal_afrom_file(fr_dict_t **out, char const *dict_subdir, char c
         */
        if (dict_root_set(dict, "internal", 0) < 0) goto error;
 
+       if (dict_path && dict_from_file(dict, dict_path, FR_DICTIONARY_FILE, NULL, 0) < 0) goto error;
+
+       TALLOC_FREE(dict_path);
+
+       dict_dependent_add(dict, dependent);
+
+       if (!dict_gctx->internal) {
+               dict_gctx->internal = dict;
+               dict_dependent_add(dict, "global");
+       }
+
+       /*
+        *      Try to load libfreeradius-internal, too.  If that
+        *      fails (i.e. fuzzers???), ignore it.
+        */
+       (void) dict_dlopen(dict, "internal");
+
+       cast_base = dict_attr_child_by_num(dict->root, FR_CAST_BASE);
+       if (!cast_base) {
+               fr_strerror_printf("Failed to find 'Cast-Base' in internal dictionary");
+               goto error;
+       }
+
+       fr_assert(cast_base->type == FR_TYPE_UINT8);
+       fr_value_box_init(&box, FR_TYPE_UINT8, NULL, false);
+
        /*
         *      Add cast attributes.  We do it this way,
         *      so cast attributes get added automatically for new types.
@@ -2616,25 +2644,17 @@ int fr_dict_internal_afrom_file(fr_dict_t **out, char const *dict_subdir, char c
                 *      Set up parenting for the attribute.
                 */
                if (dict_attr_child_add(dict->root, n) < 0) goto error;
-       }
-
-       if (dict_path && dict_from_file(dict, dict_path, FR_DICTIONARY_FILE, NULL, 0) < 0) goto error;
-
-       talloc_free(dict_path);
-
-       dict_dependent_add(dict, dependent);
 
-       if (!dict_gctx->internal) {
-               dict_gctx->internal = dict;
-               dict_dependent_add(dict, "global");
+               /*
+                *      Add the enum, too.
+                */
+               box.vb_uint8 = p->value;
+               if (dict_attr_enum_add_name(cast_base, p->name.str, &box, false, false, NULL) < 0) {
+                       fr_strerror_printf_push("Failed adding '%s' as a VALUE into internal dictionary", p->name.str);
+                       goto error;
+               }
        }
 
-       /*
-        *      Try to load libfreeradius-internal, too.  If that
-        *      fails (i.e. fuzzers???), ignore it.
-        */
-       (void) dict_dlopen(dict, "internal");
-
        *out = dict;
 
        return 0;