~ubuntu-branches/ubuntu/utopic/vsftpd/utopic-proposed

« back to all changes in this revision

Viewing changes to parseconf.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2009-05-03 17:49:00 UTC
  • mto: (2.4.1 sid) (1.5.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 15.
  • Revision ID: james.westby@ubuntu.com-20090503174900-0osuifgr8jknvu5e
Tags: upstream-2.1.1~pre1
ImportĀ upstreamĀ versionĀ 2.1.1~pre1

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
static const char* s_p_saved_filename;
20
20
 
 
21
/* File local functions */
 
22
static void handle_config_setting(struct mystr* p_setting_str,
 
23
                                  struct mystr* p_value_str,
 
24
                                  int errs_fatal);
 
25
 
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 },
108
109
  { 0, 0 }
109
110
};
110
111
 
209
210
  {
210
211
    if (errs_fatal)
211
212
    {
212
 
      die2("cannot read config file: ", p_filename);
 
213
      die2("cannot open config file:", p_filename);
213
214
    }
214
215
    else
215
216
    {
220
221
  {
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.
226
227
     */
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())
230
230
    {
231
 
      die("config file not owned by correct user, or not a file");
 
231
      die("config file not owned by correct user");
232
232
    }
233
233
    vsf_sysutil_free(p_statbuf);
234
234
  }
240
240
    {
241
241
      continue;
242
242
    }
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);
244
246
  }
245
247
  str_free(&config_file_str);
246
248
  str_free(&config_setting_str);
247
249
  str_free(&config_value_str);
248
250
}
249
251
 
250
 
void
251
 
vsf_parseconf_load_setting(const char* p_setting, int errs_fatal)
 
252
static void
 
253
handle_config_setting(struct mystr* p_setting_str, struct mystr* p_value_str,
 
254
                      int errs_fatal)
252
255
{
253
 
  static struct mystr s_setting_str;
254
 
  static struct mystr s_value_str;
255
 
  while (vsf_sysutil_isspace(*p_setting))
256
 
  {
257
 
    p_setting++;
258
 
  }
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? */
262
257
  {
263
258
    const struct parseconf_str_setting* p_str_setting = parseconf_str_array;
264
259
    while (p_str_setting->p_setting_name != 0)
265
260
    {
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))
267
262
      {
268
263
        /* Got it */
269
264
        const char** p_curr_setting = p_str_setting->p_variable;
270
265
        if (*p_curr_setting)
271
266
        {
272
 
          vsf_sysutil_free((char*) *p_curr_setting);
 
267
          vsf_sysutil_free((char*)*p_curr_setting);
273
268
        }
274
 
        if (str_isempty(&s_value_str))
 
269
        if (str_isempty(p_value_str))
275
270
        {
276
271
          *p_curr_setting = 0;
277
272
        }
278
273
        else
279
274
        {
280
 
          *p_curr_setting = str_strdup(&s_value_str);
 
275
          *p_curr_setting = str_strdup(p_value_str);
281
276
        }
282
277
        return;
283
278
      }
284
279
      p_str_setting++;
285
280
    }
286
281
  }
287
 
  if (str_isempty(&s_value_str))
 
282
  if (str_isempty(p_value_str))
288
283
  {
289
284
    if (errs_fatal)
290
285
    {
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));
292
287
    }
293
288
    else
294
289
    {
300
295
    const struct parseconf_bool_setting* p_bool_setting = parseconf_bool_array;
301
296
    while (p_bool_setting->p_setting_name != 0)
302
297
    {
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))
304
299
      {
305
300
        /* Got it */
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"))
310
305
        {
311
306
          *(p_bool_setting->p_variable) = 1;
312
307
        }
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"))
316
311
        {
317
312
          *(p_bool_setting->p_variable) = 0;
318
313
        }
319
314
        else if (errs_fatal)
320
315
        {
321
316
          die2("bad bool value in config file for: ",
322
 
               str_getbuf(&s_setting_str));
 
317
               str_getbuf(p_setting_str));
323
318
        }
324
319
        return;
325
320
      }
331
326
    const struct parseconf_uint_setting* p_uint_setting = parseconf_uint_array;
332
327
    while (p_uint_setting->p_setting_name != 0)
333
328
    {
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))
335
330
      {
336
331
        /* Got it */
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')
340
335
        {
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);
342
337
        }
343
338
        else
344
339
        {
345
 
          *(p_uint_setting->p_variable) = str_atoi(&s_value_str);
 
340
          *(p_uint_setting->p_variable) = str_atoi(p_value_str);
346
341
        }
347
342
        return;
348
343
      }
351
346
  }
352
347
  if (errs_fatal)
353
348
  {
354
 
    die2("unrecognised variable in config file: ", str_getbuf(&s_setting_str));
 
349
    die2("unrecognised variable in config file: ", str_getbuf(p_setting_str));
355
350
  }
356
351
}