]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
allow setting of options via the command line for migration
authorAlan T. DeKok <aland@freeradius.org>
Sun, 21 Aug 2022 13:45:27 +0000 (09:45 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 22 Aug 2022 00:34:09 +0000 (20:34 -0400)
We need to have the variables set before parsing the configuration
files, so their configuration can't go into the files.

src/bin/radiusd.c
src/bin/unit_test_module.c
src/lib/server/main_config.c
src/lib/server/main_config.h

index c2dd55cb4023f1e01c25f94b8df43322e0e6c2c8..aefac34013b735398be66921b2bd75318dac6e4f 100644 (file)
@@ -354,7 +354,7 @@ int main(int argc, char *argv[])
        }
 
        /*  Process the options.  */
-       while ((c = getopt(argc, argv, "Cd:D:e:fhi:l:Mmn:p:PrstTvxX")) != -1) switch (c) {
+       while ((c = getopt(argc, argv, "Cd:D:e:fhi:l:Mmn:p:PrsS:tTvxX")) != -1) switch (c) {
                case 'C':
                        check_config = true;
                        config->spawn_workers = false;
@@ -425,6 +425,14 @@ int main(int argc, char *argv[])
                        config->daemonize = false;
                        break;
 
+               case 'S':       /* Migration support */
+                       if (main_config_parse_option(optarg) < 0) {
+                               fprintf(stderr, "%s: Unknown configuration option '%s'\n",
+                                       config->name, optarg);
+                               EXIT_WITH_FAILURE;
+                       }
+                       break;
+
                case 't':       /* no child threads */
                        config->spawn_workers = false;
                        break;
index 6d1dddcd2d5767cd009a5ad4d5d93e5d8a8f6001..a9d8c59e5b60ae2e24bb0bd71300d2d4d6529b35 100644 (file)
@@ -636,7 +636,7 @@ int main(int argc, char *argv[])
        default_log.print_level = true;
 
        /*  Process the options.  */
-       while ((c = getopt(argc, argv, "c:d:D:f:hi:mMn:o:O:p:r:xXz")) != -1) {
+       while ((c = getopt(argc, argv, "c:d:D:f:hi:mMn:o:O:p:r:S:xXz")) != -1) {
                switch (c) {
                        case 'c':
                                count = atoi(optarg);
@@ -691,6 +691,14 @@ int main(int argc, char *argv[])
                                receipt_file = optarg;
                                break;
 
+                       case 'S': /* Migration support */
+                               if (main_config_parse_option(optarg) < 0) {
+                                       fprintf(stderr, "%s: Unknown configuration option '%s'\n",
+                                               config->name, optarg);
+                                       fr_exit_now(EXIT_FAILURE);
+                               }
+                               break;
+
                        case 'X':
                                fr_debug_lvl += 2;
                                default_log.print_level = true;
index 0dfba227bb39b47cbb75ebb7401092b2cda496b4..c48a2c7f016295b82feb655f1a18d444ba4dcc19 100644 (file)
@@ -174,6 +174,9 @@ static const CONF_PARSER thread_config[] = {
        CONF_PARSER_TERMINATOR
 };
 
+/*
+ *     Migration configuration.
+ */
 static const CONF_PARSER migrate_config[] = {
        { FR_CONF_OFFSET("unflatten_after_decode", FR_TYPE_BOOL | FR_TYPE_HIDDEN, main_config_t, unflatten_after_decode) },
        { FR_CONF_OFFSET("unflatten_before_encode", FR_TYPE_BOOL | FR_TYPE_HIDDEN, main_config_t, unflatten_before_encode) },
@@ -1420,3 +1423,43 @@ void main_config_hup(main_config_t *config)
 
        INFO("HUP - NYI in version 4"); /* Not yet implemented in v4 */
 }
+
+static fr_table_num_ordered_t config_arg_table[] = {
+       { L("parse_new_conditions"),     offsetof(main_config_t, parse_new_conditions) },
+       { L("use_new_conditions"),       offsetof(main_config_t, use_new_conditions) },
+       { L("tmpl_tokenize_all_nested"), offsetof(main_config_t, tmpl_tokenize_all_nested) },
+};
+static size_t config_arg_table_len = NUM_ELEMENTS(config_arg_table);
+
+/*
+ *     Migration function that allows for command-line over-ride of
+ *     data structures which need to be initialized before the
+ *     configuration files are loaded.
+ *
+ *     This should really only be temporary, until we get rid of flat vs nested.
+ */
+int main_config_parse_option(char const *value)
+{
+       fr_value_box_t box;
+       size_t offset;
+       char const *p;
+
+       p = strchr(value, '=');
+       if (!p) return -1;
+
+       offset = fr_table_value_by_substr(config_arg_table, value, p - value, 0);
+       if (!offset) return -1;
+
+       p += 1;
+
+       fr_value_box_init(&box, FR_TYPE_BOOL, NULL, false);
+       if (fr_value_box_from_str(NULL, &box, FR_TYPE_BOOL, NULL,
+                                 p, strlen(p), NULL, false) < 0) {
+               fr_perror("Invalid boolean \"%s\"", p);
+               fr_exit(1);
+       }
+
+       *(bool *) (((uintptr_t) main_config) + offset) = box.vb_bool;
+
+       return 0;
+}
index 8a8af7cd3795a9925ff13677d0231e0f30ab53c8..28cbf0179f5fc6961799dc037176f2e943c94f22 100644 (file)
@@ -165,6 +165,8 @@ void                        main_config_name_set_default(main_config_t *config, char const *name, boo
 void                   main_config_raddb_dir_set(main_config_t *config, char const *path);
 void                   main_config_dict_dir_set(main_config_t *config, char const *path);
 
+int                    main_config_parse_option(char const *value); /* flat / nested migration */
+
 void                   main_config_exclusive_proc_done(main_config_t  const *config);
 int                    main_config_exclusive_proc_child(main_config_t const *config);
 int                    main_config_exclusive_proc(main_config_t *config);