diff options
author | teor <teor2345@gmail.com> | 2014-10-19 17:48:07 +1100 |
---|---|---|
committer | teor <teor2345@gmail.com> | 2014-11-08 20:31:20 +1100 |
commit | fd7e9e9030cee9d8e863cea3f3f90226ae66fdfe (patch) | |
tree | a9ca33e658ff76b7a4bf4a7d5f9dd3a4936da575 /src/or/config.c | |
parent | ce7fd6e160e2e3acb824b29e29afe15cd5e7bf4f (diff) | |
download | tor-fd7e9e9030cee9d8e863cea3f3f90226ae66fdfe.tar.gz tor-fd7e9e9030cee9d8e863cea3f3f90226ae66fdfe.zip |
Stop failing when key files are zero-length
Instead, generate new keys, and overwrite the empty key files.
Adds FN_EMPTY to file_status_t and file_status.
Fixes bug 13111.
Related changes due to review of FN_FILE usage:
Stop generating a fresh .old RSA key file when the .old file is missing.
Avoid overwriting .old key files with empty key files.
Skip loading zero-length extra info store, router store, stats, state,
and key files.
Diffstat (limited to 'src/or/config.c')
-rw-r--r-- | src/or/config.c | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/src/or/config.c b/src/or/config.c index 3f31e876dd..3e7a73f612 100644 --- a/src/or/config.c +++ b/src/or/config.c @@ -4017,17 +4017,24 @@ find_torrc_filename(config_line_t *cmd_arg, if (*using_default_fname) { /* didn't find one, try CONFDIR */ const char *dflt = get_default_conf_file(defaults_file); - if (dflt && file_status(dflt) == FN_FILE) { + file_status_t st = file_status(dflt); + if (dflt && (st == FN_FILE || st == FN_EMPTY)) { fname = tor_strdup(dflt); } else { #ifndef _WIN32 char *fn = NULL; - if (!defaults_file) + if (!defaults_file) { fn = expand_filename("~/.torrc"); - if (fn && file_status(fn) == FN_FILE) { - fname = fn; + } + if (fn) { + file_status_t hmst = file_status(fn); + if (hmst == FN_FILE || hmst == FN_EMPTY) { + fname = fn; + } else { + tor_free(fn); + fname = tor_strdup(dflt); + } } else { - tor_free(fn); fname = tor_strdup(dflt); } #else @@ -4063,7 +4070,8 @@ load_torrc_from_disk(config_line_t *cmd_arg, int defaults_file) *fname_var = fname; /* Open config file */ - if (file_status(fname) != FN_FILE || + file_status_t st = file_status(fname); + if (!(st == FN_FILE || st == FN_EMPTY) || !(cf = read_file_to_str(fname,0,NULL))) { if (using_default_torrc == 1 || ignore_missing_torrc) { if (!defaults_file) @@ -6413,7 +6421,9 @@ write_configuration_file(const char *fname, const or_options_t *options) tor_assert(fname); switch (file_status(fname)) { + /* create backups of old config files, even if they're empty */ case FN_FILE: + case FN_EMPTY: old_val = read_file_to_str(fname, 0, NULL); if (!old_val || strcmpstart(old_val, GENERATED_FILE_PREFIX)) { rename_old = 1; |