summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoger Dingledine <arma@torproject.org>2004-11-09 07:05:53 +0000
committerRoger Dingledine <arma@torproject.org>2004-11-09 07:05:53 +0000
commit6521c2ce51b3b808dd8ef5c47dc9995acce149e5 (patch)
tree4957b0a02b4e397c146f9b2f4c462acf8fb02b54
parent48a0b6c476dee067685a66a955cdffc8a37ea9d3 (diff)
downloadtor-6521c2ce51b3b808dd8ef5c47dc9995acce149e5.tar.gz
tor-6521c2ce51b3b808dd8ef5c47dc9995acce149e5.zip
Stop using the wrong DataDirectory when we're validating.
Also validate/normalize the DataDirectory better. svn:r2732
-rw-r--r--src/or/config.c57
-rw-r--r--src/or/control.c2
-rw-r--r--src/or/dirserv.c4
-rw-r--r--src/or/hibernate.c4
-rw-r--r--src/or/main.c10
-rw-r--r--src/or/or.h1
-rw-r--r--src/or/router.c11
-rw-r--r--src/or/routerlist.c45
8 files changed, 67 insertions, 67 deletions
diff --git a/src/or/config.c b/src/or/config.c
index 7d405b63e6..cfa6970939 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -243,10 +243,9 @@ options_act(void) {
/*XXX in options_validate, we should check if this is going to fail */
/* Ensure data directory is private; create if possible. */
- if (get_data_directory() &&
- check_private_dir(get_data_directory(), 1) != 0) {
+ if (check_private_dir(options->DataDirectory, 1) != 0) {
log_fn(LOG_ERR, "Couldn't access/create private data directory %s",
- get_data_directory());
+ options->DataDirectory);
return -1;
}
@@ -268,7 +267,7 @@ options_act(void) {
/* Start backgrounding the process, if requested. */
if (options->RunAsDaemon) {
- start_daemon(get_data_directory());
+ start_daemon(options->DataDirectory);
}
/* Finish backgrounding the process */
@@ -1844,43 +1843,47 @@ parse_dir_server_line(const char *line, int validate_only)
return r;
}
-/** Return the place where we are currently configured to store and read all
- * of our persistant data. */
-const char *
-get_data_directory(void)
-{
- return get_options()->DataDirectory;
-}
-
static int
-validate_data_directory(or_options_t *options) {
- const char *d = options->DataDirectory;
-
- if (!options->DataDirectory) {
+normalize_data_directory(or_options_t *options) {
#ifdef MS_WINDOWS
- char *p;
- p = tor_malloc(MAX_PATH);
- strlcpy(p,get_windows_conf_root(),MAX_PATH);
- options->DataDirectory = p;
- return p;
+ char *p;
+ if (options->DataDirectory)
+ return 0; /* all set */
+ p = tor_malloc(MAX_PATH);
+ strlcpy(p,get_windows_conf_root(),MAX_PATH);
+ options->DataDirectory = p;
+ return 0;
#else
+ const char *d = options->DataDirectory;
+ if(!d)
d = "~/.tor";
- }
-#endif
- if (d && strncmp(d,"~/",2) == 0) {
+ if (strncmp(d,"~/",2) == 0) {
char *fn = expand_filename(d);
if (!fn) {
- log_fn(LOG_ERR,"Failed to expand filename '%s'. Exiting.", d);
- exit(1);
+ log_fn(LOG_ERR,"Failed to expand filename '%s'.", d);
+ return -1;
}
tor_free(options->DataDirectory);
options->DataDirectory = fn;
}
-
return 0;
+#endif
+}
+
+static int
+validate_data_directory(or_options_t *options) {
+ if(normalize_data_directory(options) < 0)
+ return -1;
+ tor_assert(options->DataDirectory);
+ if (strlen(options->DataDirectory) > (512-128)) {
+ log_fn(LOG_ERR, "DataDirectory is too long.");
+ return -1;
+ }
+ return 0;
}
+
/*
Local Variables:
mode:c
diff --git a/src/or/control.c b/src/or/control.c
index 57ef6f484e..0a428e9612 100644
--- a/src/or/control.c
+++ b/src/or/control.c
@@ -577,7 +577,7 @@ init_cookie_authentication(void)
/* XXXX009 NM add config option to disable this. */
tor_snprintf(fname, sizeof(fname), "%s/control_auth_cookie",
- get_data_directory());
+ get_options()->DataDirectory);
crypto_rand(authentication_cookie, AUTHENTICATION_COOKIE_LEN);
authentication_cookie_is_set = 1;
if (write_bytes_to_file(fname, authentication_cookie,
diff --git a/src/or/dirserv.c b/src/or/dirserv.c
index cfe0a46611..2e6508b056 100644
--- a/src/or/dirserv.c
+++ b/src/or/dirserv.c
@@ -711,8 +711,8 @@ void dirserv_set_cached_directory(const char *directory, time_t when)
log_fn(LOG_WARN,"Error compressing cached directory");
}
cached_directory_published = when;
- if(get_data_directory()) {
- tor_snprintf(filename,sizeof(filename),"%s/cached-directory", get_data_directory());
+ if(get_options()->DataDirectory) {
+ tor_snprintf(filename,sizeof(filename),"%s/cached-directory", get_options()->DataDirectory);
if(write_str_to_file(filename,cached_directory,0) < 0) {
log_fn(LOG_WARN, "Couldn't write cached directory to disk. Ignoring.");
}
diff --git a/src/or/hibernate.c b/src/or/hibernate.c
index abe662c81a..c01d1c32c1 100644
--- a/src/or/hibernate.c
+++ b/src/or/hibernate.c
@@ -328,7 +328,7 @@ record_bandwidth_usage(time_t now)
(unsigned long)n_seconds_active_in_interval,
(unsigned long)expected_bandwidth_usage);
tor_snprintf(fname, sizeof(fname), "%s/bw_accounting",
- get_data_directory());
+ get_options()->DataDirectory);
return write_str_to_file(fname, buf, 0);
}
@@ -347,7 +347,7 @@ read_bandwidth_usage(void)
int ok;
tor_snprintf(fname, sizeof(fname), "%s/bw_accounting",
- get_data_directory());
+ get_options()->DataDirectory);
if (!(s = read_file_to_str(fname, 0))) {
return 0;
}
diff --git a/src/or/main.c b/src/or/main.c
index 3af6adb99b..7125b8c5ad 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -692,6 +692,7 @@ static int prepare_for_poll(void) {
* retry all connections, re-upload all descriptors, and so on. */
static int do_hup(void) {
char keydir[512];
+ or_options_t *options = get_options();
log_fn(LOG_NOTICE,"Received sighup. Reloading config.");
has_completed_circuit=0;
@@ -702,11 +703,12 @@ static int do_hup(void) {
log_fn(LOG_ERR,"Reading config failed--see warnings above. For usage, try -h.");
return -1;
}
+ options = get_options();
/*XXX this should move to options_act, but only once it's been
* removed from init_keys() */
- if(authdir_mode(get_options())) {
+ if(authdir_mode(options)) {
/* reload the approved-routers file */
- tor_snprintf(keydir,sizeof(keydir),"%s/approved-routers", get_data_directory());
+ tor_snprintf(keydir,sizeof(keydir),"%s/approved-routers", options->DataDirectory);
log_fn(LOG_INFO,"Reloading approved fingerprints from %s...",keydir);
if(dirserv_parse_fingerprint_file(keydir) < 0) {
log_fn(LOG_WARN, "Error reloading fingerprints. Continuing with old list.");
@@ -714,14 +716,14 @@ static int do_hup(void) {
}
/* Fetch a new directory. Even authdirservers do this. */
directory_get_from_dirserver(DIR_PURPOSE_FETCH_DIR, NULL, 0);
- if(server_mode(get_options())) {
+ if(server_mode(options)) {
/* Restart cpuworker and dnsworker processes, so they get up-to-date
* configuration options. */
cpuworkers_rotate();
dnsworkers_rotate();
/* Rebuild fresh descriptor as needed. */
router_rebuild_descriptor();
- tor_snprintf(keydir,sizeof(keydir),"%s/router.desc", get_data_directory());
+ tor_snprintf(keydir,sizeof(keydir),"%s/router.desc", options->DataDirectory);
log_fn(LOG_INFO,"Dumping descriptor to %s...",keydir);
if (write_str_to_file(keydir, router_get_my_descriptor(), 0)) {
return -1;
diff --git a/src/or/or.h b/src/or/or.h
index fafc1e5461..b363a46acc 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -1105,7 +1105,6 @@ int config_init_logs(or_options_t *options);
void config_parse_exit_policy(struct config_line_t *cfg,
struct exit_policy_t **dest);
void exit_policy_free(struct exit_policy_t *p);
-const char *get_data_directory(void);
int config_option_is_recognized(const char *key);
struct config_line_t *config_get_assigned_option(or_options_t *options,
const char *key);
diff --git a/src/or/router.c b/src/or/router.c
index 7530c34e77..c47080e562 100644
--- a/src/or/router.c
+++ b/src/or/router.c
@@ -103,9 +103,9 @@ void rotate_onion_key(void)
char fname_prev[512];
crypto_pk_env_t *prkey;
tor_snprintf(fname,sizeof(fname),
- "%s/keys/secret_onion_key",get_data_directory());
+ "%s/keys/secret_onion_key",get_options()->DataDirectory);
tor_snprintf(fname_prev,sizeof(fname_prev),
- "%s/keys/secret_onion_key.old",get_data_directory());
+ "%s/keys/secret_onion_key.old",get_options()->DataDirectory);
if (!(prkey = crypto_new_pk_env())) {
log(LOG_ERR, "Error creating crypto environment.");
goto error;
@@ -258,12 +258,7 @@ int init_keys(void) {
return 0;
}
/* Make sure DataDirectory exists, and is private. */
- datadir = get_data_directory();
- tor_assert(datadir);
- if (strlen(datadir) > (512-128)) {
- log_fn(LOG_ERR, "DataDirectory is too long.");
- return -1;
- }
+ datadir = options->DataDirectory;
if (check_private_dir(datadir, 1)) {
return -1;
}
diff --git a/src/or/routerlist.c b/src/or/routerlist.c
index 2c4b044f8e..ac62b4528d 100644
--- a/src/or/routerlist.c
+++ b/src/or/routerlist.c
@@ -48,30 +48,31 @@ int router_reload_router_list(void)
char filename[512];
int is_recent;
struct stat st;
- if (get_data_directory()) {
- char *s;
- tor_snprintf(filename,sizeof(filename),"%s/cached-directory", get_data_directory());
- if (stat(filename, &st)) {
- log_fn(LOG_WARN, "Unable to check status for '%s': %s", filename,
- strerror(errno));
- return 0;
+ char *s;
+ tor_assert(get_options()->DataDirectory);
+
+ tor_snprintf(filename,sizeof(filename),"%s/cached-directory",
+ get_options()->DataDirectory);
+ if (stat(filename, &st)) {
+ log_fn(LOG_WARN, "Unable to check status for '%s': %s", filename,
+ strerror(errno));
+ return 0;
+ }
+ s = read_file_to_str(filename,0);
+ if (s) {
+ tor_strstrip(s,"\r"); /* XXXX This is a bug workaround for win32. */
+ log_fn(LOG_INFO, "Loading cached directory from %s", filename);
+ is_recent = st.st_mtime > time(NULL) - 60*15;
+ if (router_load_routerlist_from_directory(s, NULL, is_recent) < 0) {
+ log_fn(LOG_WARN, "Cached directory '%s' was unparseable; ignoring.", filename);
}
- s = read_file_to_str(filename,0);
- if (s) {
- tor_strstrip(s,"\r"); /* XXXX This is a bug workaround for win32. */
- log_fn(LOG_INFO, "Loading cached directory from %s", filename);
- is_recent = st.st_mtime > time(NULL) - 60*15;
- if (router_load_routerlist_from_directory(s, NULL, is_recent) < 0) {
- log_fn(LOG_WARN, "Cached directory '%s' was unparseable; ignoring.", filename);
- }
- if(routerlist &&
- ((routerlist->published_on > time(NULL) - OLD_MIN_ONION_KEY_LIFETIME/2)
- || is_recent)) {
- /* XXX use new onion key lifetime when 0.0.8 servers are obsolete */
- directory_has_arrived(st.st_mtime); /* do things we've been waiting to do */
- }
- tor_free(s);
+ if(routerlist &&
+ ((routerlist->published_on > time(NULL) - OLD_MIN_ONION_KEY_LIFETIME/2)
+ || is_recent)) {
+ /* XXX use new onion key lifetime when 0.0.8 servers are obsolete */
+ directory_has_arrived(st.st_mtime); /* do things we've been waiting to do */
}
+ tor_free(s);
}
return 0;
}