]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
allow for "export in dictionary form, too"
authorAlan T. DeKok <aland@freeradius.org>
Fri, 14 May 2021 14:48:56 +0000 (10:48 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Fri, 14 May 2021 14:48:56 +0000 (10:48 -0400)
in preparation for some horrific scripts which will let us
convert v3 names to v4

src/bin/radict.c

index 544deae62a3d3a96d6a63488f76e6955490720df..2523985209a7d196c15c6d754912b234c08cfcc8 100644 (file)
@@ -179,7 +179,7 @@ static void da_print_info_td(fr_dict_t const *dict, fr_dict_attr_t const *da)
        }
 }
 
-static void _fr_dict_export(fr_dict_t const *dict, uint64_t *count, uintptr_t *low, uintptr_t *high, fr_dict_attr_t const *da, unsigned int lvl)
+static void _raddict_export(fr_dict_t const *dict, uint64_t *count, uintptr_t *low, uintptr_t *high, fr_dict_attr_t const *da, unsigned int lvl)
 {
        unsigned int            i;
        size_t                  len;
@@ -213,18 +213,18 @@ static void _fr_dict_export(fr_dict_t const *dict, uint64_t *count, uintptr_t *l
        len = talloc_array_length(children);
        for (i = 0; i < len; i++) {
                for (p = children[i]; p; p = p->next) {
-                       _fr_dict_export(dict, count, low, high, p, lvl + 1);
+                       _raddict_export(dict, count, low, high, p, lvl + 1);
                }
        }
 }
 
-static void fr_dict_export(uint64_t *count, uintptr_t *low, uintptr_t *high, fr_dict_t *dict)
+static void raddict_export(uint64_t *count, uintptr_t *low, uintptr_t *high, fr_dict_t *dict)
 {
        if (count) *count = 0;
        if (low) *low = UINTPTR_MAX;
        if (high) *high = 0;
 
-       _fr_dict_export(dict, count, low, high, fr_dict_root(dict), 0);
+       _raddict_export(dict, count, low, high, fr_dict_root(dict), 0);
 }
 
 /**
@@ -238,6 +238,8 @@ int main(int argc, char *argv[])
        int                     ret = 0;
        bool                    found = false;
        bool                    export = false;
+       bool                    file_export = false;
+       char const              *protocol;
 
        TALLOC_CTX              *autofree;
        fr_dict_gctx_t const    *our_dict_gctx = NULL;
@@ -260,7 +262,11 @@ int main(int argc, char *argv[])
 
        fr_debug_lvl = 1;
 
-       while ((c = getopt(argc, argv, "ED:Vxh")) != -1) switch (c) {
+       while ((c = getopt(argc, argv, "fED:p:Vxh")) != -1) switch (c) {
+               case 'f':
+                       file_export = true;
+                       break;
+
                case 'E':
                        export = true;
                        break;
@@ -269,6 +275,10 @@ int main(int argc, char *argv[])
                        dict_dir = optarg;
                        break;
 
+               case 'p':
+                       protocol = optarg;
+                       break;
+
                case 'V':
                        print_values = true;
                        break;
@@ -323,6 +333,16 @@ int main(int argc, char *argv[])
                goto finish;
        }
 
+       if (file_export) {
+               fr_dict_t       **dict_p = dicts;
+
+               do {
+                       if (protocol && (strcasecmp(fr_dict_root(*dict_p)->name, protocol) == 0)) {
+                               fr_dict_export(*dict_p);
+                       }
+               } while (++dict_p < dict_end);
+       }
+
        if (export) {
                fr_dict_t       **dict_p = dicts;
 
@@ -331,7 +351,7 @@ int main(int argc, char *argv[])
                        uintptr_t       high;
                        uintptr_t       low;
 
-                       fr_dict_export(&count, &low, &high, *dict_p);
+                       raddict_export(&count, &low, &high, *dict_p);
                        DEBUG2("Attribute count %" PRIu64, count);
                        DEBUG2("Memory allocd %zu (bytes)", talloc_total_size(*dict_p));
                        DEBUG2("Memory spread %zu (bytes)", (size_t) (high - low));