@@ -45,8 +45,6 @@ RCSID("$Id$")
4545
4646#include <freeradius-devel/unlang/xlat_func.h>
4747
48-
49-
5048#ifdef HAVE_SYSLOG_H
5149# include <syslog.h>
5250#endif
@@ -61,6 +59,27 @@ extern fr_log_t debug_log;
6159
6260fr_log_t debug_log = { .fd = -1 , .dst = L_DST_NULL };
6361
62+ /*
63+ * Configuration file overrides
64+ */
65+ FR_DLIST_TYPES (fr_override_list )
66+ typedef FR_DLIST_HEAD (fr_override_list ) fr_override_list_t ;
67+ FR_DLIST_TYPEDEFS (fr_override_list , fr_override_list_t , fr_override_entry_t )
68+
69+ static fr_override_list_t override ;
70+
71+ typedef struct {
72+ char * name ; //!< must not be 'const'
73+ char * value ;
74+ FR_DLIST_ENTRY (fr_override_list ) entry ;
75+ } fr_override_t ;
76+
77+ FR_DLIST_FUNCS (fr_override_list , fr_override_t , entry )
78+
79+ #define fr_override_list_foreach (_list_head , _iter ) \
80+ for (fr_override_t *JOIN(_next,_iter), *_iter = fr_override_list_head(_list_head); JOIN(_next,_iter) = fr_override_list_next(_list_head, _iter), _iter != NULL; _iter = JOIN(_next,_iter))
81+
82+
6483/**********************************************************************
6584 *
6685 * We need to figure out where the logs go, before doing anything
@@ -148,11 +167,11 @@ static const conf_parser_t log_config[] = {
148167
149168static const conf_parser_t resources [] = {
150169 /*
151- * Don't set a default here. It's set in the code, below. This means that
152- * the config item will *not* get printed out in debug mode, so that no one knows
153- * it exists.
170+ * Don't set defaults here. They're set in the command line. This means
171+ * that the config item will *not* get printed out in debug mode, so that no one knows it exists.
154172 */
155- { FR_CONF_OFFSET_FLAGS ("talloc_memory_report" , CONF_FLAG_HIDDEN , main_config_t , talloc_memory_report ) }, /* DO NOT SET DEFAULT */
173+ { FR_CONF_OFFSET_FLAGS ("talloc_memory_report" , CONF_FLAG_HIDDEN , main_config_t , talloc_memory_report ) }, /* DO NOT SET DEFAULT */
174+ { FR_CONF_OFFSET_FLAGS ("talloc_skip_cleanup" , CONF_FLAG_HIDDEN , main_config_t , talloc_skip_cleanup ) }, /* DO NOT SET DEFAULT */
156175 CONF_PARSER_TERMINATOR
157176};
158177
@@ -997,6 +1016,8 @@ main_config_t *main_config_alloc(TALLOC_CTX *ctx)
9971016
9981017 main_config = config ;
9991018
1019+ fr_override_list_init (& override );
1020+
10001021 return config ;
10011022}
10021023
@@ -1213,6 +1234,17 @@ int main_config_init(main_config_t *config)
12131234 } /* loop over pairs in ENV */
12141235 } /* there's an ENV subsection */
12151236
1237+ /*
1238+ * Now that we've read the configuration files, override the values.
1239+ */
1240+ fr_override_list_foreach (& override , ov ) {
1241+ if (cf_pair_replace_or_add (cs , ov -> name , ov -> value ) < 0 ) {
1242+ fprintf (stderr , "%s: Error: Cannot update configuration item '%s' - %s.\n" ,
1243+ config -> name , ov -> name , fr_strerror ());
1244+ goto failure ;
1245+ }
1246+ }
1247+
12161248 /*
12171249 * Parse log section of main config.
12181250 */
@@ -1450,62 +1482,37 @@ void main_config_hup(main_config_t *config)
14501482 INFO ("HUP - NYI in version 4" ); /* Not yet implemented in v4 */
14511483}
14521484
1453- #if 0
1454- static fr_table_num_ordered_t config_arg_table [] = {
1455- };
1456- static size_t config_arg_table_len = NUM_ELEMENTS (config_arg_table );
1457-
14581485/*
14591486 * Migration function that allows for command-line over-ride of
14601487 * data structures which need to be initialized before the
14611488 * configuration files are loaded.
14621489 *
14631490 * This should really only be temporary, until we get rid of flat vs nested.
14641491 */
1465- int main_config_parse_option (char const * value )
1492+ int main_config_save_override (char const * str )
14661493{
1467- fr_value_box_t box ;
1468- size_t offset ;
1469- char const * p ;
1470- bool * out ;
1494+ char * p ;
1495+ fr_override_t * ov ;
14711496
1472- p = strchr (value , '=' );
1473- if (!p ) return -1 ;
1497+ MEM (ov = talloc_zero (main_config , fr_override_t ));
14741498
1475- offset = fr_table_value_by_substr (config_arg_table , value , p - value , 0 );
1476- if (offset ) {
1477- out = (bool * ) (((uintptr_t ) main_config ) + offset );
1499+ MEM (ov -> name = talloc_strdup (ov , str ));
14781500
1479- } else {
1501+ p = strchr (ov -> name , '=' );
1502+ if (!p ) {
1503+ talloc_free (ov );
1504+ fr_strerror_const ("Missing '='" );
14801505 return -1 ;
14811506 }
14821507
1483- p += 1 ;
1484-
1485- fr_value_box_init (& box , FR_TYPE_BOOL , NULL , false);
1486- if (fr_value_box_from_str (NULL , & box , FR_TYPE_BOOL , NULL ,
1487- p , strlen (p ), NULL ) < 0 ) {
1488- fr_perror ("Invalid boolean \"%s\"" , p );
1489- fr_exit (1 );
1508+ * p ++ = '\0' ;
1509+ if (!* p ) {
1510+ talloc_free (ov );
1511+ fr_strerror_const ("Missing value after '='" );
1512+ return -1 ;
14901513 }
1514+ ov -> value = p ;
14911515
1492- * out = box .vb_bool ;
1493-
1516+ fr_override_list_insert_tail (& override , ov );
14941517 return 0 ;
14951518}
1496-
1497- /*
1498- * Allow other pieces of the code to examine the migration options.
1499- */
1500- bool main_config_migrate_option_get (char const * name )
1501- {
1502- size_t offset ;
1503-
1504- if (!main_config ) return false;
1505-
1506- offset = fr_table_value_by_substr (config_arg_table , name , strlen (name ), 0 );
1507- if (!offset ) return false;
1508-
1509- return * (bool * ) (((uintptr_t ) main_config ) + offset );
1510- }
1511- #endif
0 commit comments