From: Nick Mathewson Date: Fri, 16 Jul 2004 19:43:58 +0000 (+0000) Subject: Look in .torrc if no CONFDIR "torrc" is found. X-Git-Tag: tor-0.0.8pre1~72 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0b3357d57382d93aee1abfc5d6f57de918794953;p=thirdparty%2Ftor.git Look in .torrc if no CONFDIR "torrc" is found. svn:r2048 --- diff --git a/doc/TODO b/doc/TODO index c321fa483a..b84785e596 100644 --- a/doc/TODO +++ b/doc/TODO @@ -39,7 +39,7 @@ NICK milestone 1: o Adjust tor o Change torrc.sample D Change packages (not till 0.0.8 packages!) -NICK - Look in ~/.tor/ if no */etc/torrc is found? + o Look in ~/.torrc if no */etc/torrc is found. NICK - Possible to get autoconf to easily install things into ~/.tor? o Contact info, pgp fingerprint, comments in router desc. o Add a ContactInfo line to torrc, which gets published in diff --git a/src/or/config.c b/src/or/config.c index 2941174a69..f8e69687a9 100644 --- a/src/or/config.c +++ b/src/or/config.c @@ -607,10 +607,20 @@ int getconfig(int argc, char **argv, or_options_t *options) { i++; } if(i < argc-1) { /* we found one */ - fname = argv[i+1]; + fname = tor_strdup(argv[i+1]); using_default_torrc = 0; - } else { /* didn't find one, try CONFDIR */ - fname = CONFDIR "/torrc"; + } else if (file_status(CONFDIR "/torrc")==FN_FILE) { + /* didn't find one, try CONFDIR */ + fname = tor_strdup(CONFDIR "/torrc"); + using_default_torrc = 1; + } else { + char *fn = expand_filename("~/.torrc"); + if (file_status(fn)==FN_FILE) { + fname = fn; + } else { + tor_free(fn); + fname = tor_strdup(CONFDIR "/torrc"); + } using_default_torrc = 1; } log(LOG_DEBUG,"Opening config file '%s'",fname); @@ -619,13 +629,17 @@ int getconfig(int argc, char **argv, or_options_t *options) { if(!cf) { if(using_default_torrc == 1) { log(LOG_NOTICE, "Configuration file '%s' not present, using reasonable defaults.",fname); - if(config_assign_defaults(options) < 0) + tor_free(fname); + if(config_assign_defaults(options) < 0) { return -1; + } } else { log(LOG_WARN, "Unable to open configuration file '%s'.",fname); + tor_free(fname); return -1; } } else { /* it opened successfully. use it. */ + tor_free(fname); cl = config_get_lines(cf); if(!cl) return -1; if(config_assign(options,cl) < 0) @@ -925,27 +939,15 @@ void exit_policy_free(struct exit_policy_t *p) { const char *get_data_directory(or_options_t *options) { const char *d; - char buf[1024]; - const char *home; - size_t n; if (options->DataDirectory) d = options->DataDirectory; else d = "~/.tor"; - if (!strncmp(d,"~/",2)) { - home = getenv("HOME"); - if (!home) { - log_fn(LOG_ERR, "Couldn't find $HOME environment variable for data directory %s", d); - exit(1); - } - n = snprintf(buf,1020,"%s/%s",home,d+2); - if (n>=1020) { - log_fn(LOG_ERR, "Overlong data directory name."); - exit(1); - } + if (strncmp(d,"~/",2)==0) { + char *fn = expand_filename(d); tor_free(options->DataDirectory); - options->DataDirectory = tor_strdup(buf); + options->DataDirectory = fn; } return options->DataDirectory; }