Skip to content

Commit 8ec7091

Browse files
committed
Add '-S' and overrides
1 parent b878aa9 commit 8ec7091

3 files changed

Lines changed: 92 additions & 76 deletions

File tree

src/bin/radiusd.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -411,13 +411,11 @@ int main(int argc, char *argv[])
411411
break;
412412

413413
case 'S': /* Migration support */
414-
#if 0
415-
if (main_config_parse_option(optarg) < 0) {
416-
fprintf(stderr, "%s: Unknown configuration option '%s'\n",
417-
program, optarg);
414+
if (main_config_save_override(optarg) < 0) {
415+
fprintf(stderr, "%s: Failed saving configuration option '%s' - %s\n",
416+
program, optarg, fr_strerror());
418417
EXIT_WITH_FAILURE;
419418
}
420-
#endif
421419
break;
422420

423421
case 't': /* no child threads */
@@ -1104,6 +1102,15 @@ do { \
11041102
main_config_exclusive_proc_done(main_config);
11051103

11061104
cleanup:
1105+
/*
1106+
* If we're told to just exit without cleaning up memory,
1107+
* then do so.
1108+
*/
1109+
if (config && config->talloc_skip_cleanup) {
1110+
fr_atexit_global_disarm_all();
1111+
exit(ret);
1112+
}
1113+
11071114
/*
11081115
* This may not have been done earlier if we're
11091116
* exiting due to a startup error.

src/lib/server/main_config.c

Lines changed: 54 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -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

6260
fr_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

149168
static 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

src/lib/server/main_config.h

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,15 @@ struct main_config_s {
5858
bool spawn_workers; //!< Should the server spawn threads.
5959
char const *pid_file; //!< Path to write out PID file.
6060

61-
fr_worker_config_t worker; //!< Worker thread configuration.
62-
63-
bool drop_requests; //!< Administratively disable request processing.
64-
bool suppress_secrets; //!< suppress secrets (or not)
61+
bool write_pid; //!< write the PID file
6562

6663
char const *log_dir;
6764
char const *local_state_dir;
6865

69-
bool reverse_lookups;
70-
bool hostname_lookups;
66+
bool reverse_lookups; //!< do IP -> host lookups. Don't set this!
67+
bool hostname_lookups; //!< do hostname -> IP lookups
68+
bool drop_requests; //!< Administratively disable request processing.
69+
bool suppress_secrets; //!< suppress secrets (or not)
7170

7271
char const *radacct_dir;
7372
char const *lib_dir;
@@ -78,7 +77,6 @@ struct main_config_s {
7877
char const *prefix;
7978

8079
char const *log_dest;
81-
8280
char const *log_file;
8381
bool do_colourise;
8482
bool log_line_number; //!< Log src file/line the message was generated on.
@@ -90,8 +88,7 @@ struct main_config_s {
9088
int32_t syslog_facility;
9189

9290
char const *dict_dir; //!< Where to load dictionaries from.
93-
94-
bool write_pid; //!< write the PID file
91+
fr_dict_t *dict; //!< Main dictionary.
9592

9693
#ifdef HAVE_SETUID
9794
uid_t server_uid; //!< UID we're running as.
@@ -105,6 +102,9 @@ struct main_config_s {
105102
char const *chdir; //!< where to chdir() to when we start.
106103
bool chdir_is_set;
107104

105+
/*
106+
* OpenSSL configuration
107+
*/
108108
#ifdef ENABLE_OPENSSL_VERSION_CHECK
109109
char const *allow_vulnerable_openssl; //!< The CVE number of the last security issue acknowledged.
110110
#endif
@@ -120,51 +120,53 @@ struct main_config_s {
120120
///< in the async ctx pool.
121121
#endif
122122

123-
fr_dict_t *dict; //!< Main dictionary.
124-
125-
126123
/*
127124
* Debugging options
128125
*/
126+
uint32_t debug_level; //!< The base log level for the server.
127+
128+
bool talloc_memory_report; //!< Print a memory report on what's left unfreed.
129+
//!< Can only be used when the server is running in single
130+
//!< threaded mode.
131+
132+
bool talloc_skip_cleanup; //!< skip talloc cleanups at exit
133+
129134
bool allow_core_dumps; //!< Whether the server is allowed to drop a core when
130135
//!< receiving a fatal signal.
131136

132137
char const *panic_action; //!< Command to execute if the server receives a fatal
133138
//!< signal.
134139

135-
uint32_t debug_level; //!< The base log level for the server.
136-
137-
bool talloc_memory_report; //!< Print a memory report on what's left unfreed.
138-
//!< Can only be used when the server is running in single
139-
//!< threaded mode.
140140

141+
/*
142+
* Multiple processing sharing configs
143+
*/
141144
bool allow_multiple_procs; //!< Allow multiple instances of radiusd to run with the
142145
///< same config file.
143146

144147
int multi_proc_sem_id; //!< Semaphore we use to prevent multiple processes running.
145148
char *multi_proc_sem_path; //!< Semaphore path.
146149

150+
/*
151+
* Internal scheduler configuration
152+
*/
147153
uint32_t max_networks; //!< for the scheduler
148154
uint32_t max_workers; //!< for the scheduler
149155
fr_time_delta_t stats_interval; //!< for the scheduler
150156

157+
fr_worker_config_t worker; //!< Worker thread configuration.
158+
151159
#ifndef NDEBUG
152160
uint32_t ins_max; //!< max instruction count
153161
bool ins_countup; //!< count up to "max"
154162
#endif
155-
156-
/*
157-
* Migration tools
158-
*/
159163
};
160164

161165
void main_config_name_set_default(main_config_t *config, char const *name, bool overwrite_config);
162166
void main_config_confdir_set(main_config_t *config, char const *path);
163167
void main_config_dict_dir_set(main_config_t *config, char const *path);
164168

165-
int main_config_parse_option(char const *value); /* flat / nested migration */
166-
167-
bool main_config_migrate_option_get(char const *name);
169+
int main_config_save_override(char const *value);
168170

169171
void main_config_exclusive_proc_done(main_config_t const *config);
170172
int main_config_exclusive_proc_child(main_config_t const *config);

0 commit comments

Comments
 (0)