19
19
static const char* s_p_saved_filename;
21
/* File local functions */
22
static void handle_config_setting(struct mystr* p_setting_str,
23
struct mystr* p_value_str,
21
26
/* Tables mapping setting names to runtime variables */
22
27
/* Boolean settings */
23
28
static struct parseconf_bool_setting
101
106
{ "implicit_ssl", &tunable_implicit_ssl },
102
107
{ "sandbox", &tunable_sandbox },
103
108
{ "require_ssl_reuse", &tunable_require_ssl_reuse },
104
{ "isolate", &tunable_isolate },
105
{ "isolate_network", &tunable_isolate_network },
106
{ "ftp_enable", &tunable_ftp_enable },
107
{ "http_enable", &tunable_http_enable },
221
222
struct vsf_sysutil_statbuf* p_statbuf = 0;
222
223
retval = vsf_sysutil_stat(p_filename, &p_statbuf);
223
/* Security: check current user owns the config file. These are sanity
224
* checks for the admin, and are NOT designed to be checks safe from
224
/* Security: check current user owns the config file. This is a sanity
225
* check for the admin, and is NOT designed to be a check safe from
225
226
* race conditions.
227
228
if (vsf_sysutil_retval_is_error(retval) ||
228
vsf_sysutil_statbuf_get_uid(p_statbuf) != vsf_sysutil_getuid() ||
229
!vsf_sysutil_statbuf_is_regfile(p_statbuf))
229
vsf_sysutil_statbuf_get_uid(p_statbuf) != vsf_sysutil_getuid())
231
die("config file not owned by correct user, or not a file");
231
die("config file not owned by correct user");
233
233
vsf_sysutil_free(p_statbuf);
243
vsf_parseconf_load_setting(str_getbuf(&config_setting_str), errs_fatal);
243
/* Split into name=value pair */
244
str_split_char(&config_setting_str, &config_value_str, '=');
245
handle_config_setting(&config_setting_str, &config_value_str, errs_fatal);
245
247
str_free(&config_file_str);
246
248
str_free(&config_setting_str);
247
249
str_free(&config_value_str);
251
vsf_parseconf_load_setting(const char* p_setting, int errs_fatal)
253
handle_config_setting(struct mystr* p_setting_str, struct mystr* p_value_str,
253
static struct mystr s_setting_str;
254
static struct mystr s_value_str;
255
while (vsf_sysutil_isspace(*p_setting))
259
str_alloc_text(&s_setting_str, p_setting);
260
str_split_char(&s_setting_str, &s_value_str, '=');
261
256
/* Is it a string setting? */
263
258
const struct parseconf_str_setting* p_str_setting = parseconf_str_array;
264
259
while (p_str_setting->p_setting_name != 0)
266
if (str_equal_text(&s_setting_str, p_str_setting->p_setting_name))
261
if (str_equal_text(p_setting_str, p_str_setting->p_setting_name))
269
264
const char** p_curr_setting = p_str_setting->p_variable;
270
265
if (*p_curr_setting)
272
vsf_sysutil_free((char*) *p_curr_setting);
267
vsf_sysutil_free((char*)*p_curr_setting);
274
if (str_isempty(&s_value_str))
269
if (str_isempty(p_value_str))
276
271
*p_curr_setting = 0;
280
*p_curr_setting = str_strdup(&s_value_str);
275
*p_curr_setting = str_strdup(p_value_str);
287
if (str_isempty(&s_value_str))
282
if (str_isempty(p_value_str))
291
die2("missing value in config file for: ", str_getbuf(&s_setting_str));
286
die2("missing value in config file for: ", str_getbuf(p_setting_str));
300
295
const struct parseconf_bool_setting* p_bool_setting = parseconf_bool_array;
301
296
while (p_bool_setting->p_setting_name != 0)
303
if (str_equal_text(&s_setting_str, p_bool_setting->p_setting_name))
298
if (str_equal_text(p_setting_str, p_bool_setting->p_setting_name))
306
str_upper(&s_value_str);
307
if (str_equal_text(&s_value_str, "YES") ||
308
str_equal_text(&s_value_str, "TRUE") ||
309
str_equal_text(&s_value_str, "1"))
301
str_upper(p_value_str);
302
if (str_equal_text(p_value_str, "YES") ||
303
str_equal_text(p_value_str, "TRUE") ||
304
str_equal_text(p_value_str, "1"))
311
306
*(p_bool_setting->p_variable) = 1;
313
else if (str_equal_text(&s_value_str, "NO") ||
314
str_equal_text(&s_value_str, "FALSE") ||
315
str_equal_text(&s_value_str, "0"))
308
else if (str_equal_text(p_value_str, "NO") ||
309
str_equal_text(p_value_str, "FALSE") ||
310
str_equal_text(p_value_str, "0"))
317
312
*(p_bool_setting->p_variable) = 0;
319
314
else if (errs_fatal)
321
316
die2("bad bool value in config file for: ",
322
str_getbuf(&s_setting_str));
317
str_getbuf(p_setting_str));
331
326
const struct parseconf_uint_setting* p_uint_setting = parseconf_uint_array;
332
327
while (p_uint_setting->p_setting_name != 0)
334
if (str_equal_text(&s_setting_str, p_uint_setting->p_setting_name))
329
if (str_equal_text(p_setting_str, p_uint_setting->p_setting_name))
337
332
/* If the value starts with 0, assume it's an octal value */
338
if (!str_isempty(&s_value_str) &&
339
str_get_char_at(&s_value_str, 0) == '0')
333
if (!str_isempty(p_value_str) &&
334
str_get_char_at(p_value_str, 0) == '0')
341
*(p_uint_setting->p_variable) = str_octal_to_uint(&s_value_str);
336
*(p_uint_setting->p_variable) = str_octal_to_uint(p_value_str);
345
*(p_uint_setting->p_variable) = str_atoi(&s_value_str);
340
*(p_uint_setting->p_variable) = str_atoi(p_value_str);