[or-cvs] Stop using the wrong DataDirectory when we"re validating.
Roger Dingledine
arma at seul.org
Tue Nov 9 07:05:55 UTC 2004
Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/home2/arma/work/onion/cvs/src/or
Modified Files:
config.c control.c dirserv.c hibernate.c main.c or.h router.c
routerlist.c
Log Message:
Stop using the wrong DataDirectory when we're validating.
Also validate/normalize the DataDirectory better.
Index: config.c
===================================================================
RCS file: /home/or/cvsroot/src/or/config.c,v
retrieving revision 1.227
retrieving revision 1.228
diff -u -d -r1.227 -r1.228
--- config.c 9 Nov 2004 06:40:32 -0000 1.227
+++ config.c 9 Nov 2004 07:05:53 -0000 1.228
@@ -243,10 +243,9 @@
/*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 @@
/* 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 @@
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
Index: control.c
===================================================================
RCS file: /home/or/cvsroot/src/or/control.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- control.c 9 Nov 2004 06:40:32 -0000 1.16
+++ control.c 9 Nov 2004 07:05:53 -0000 1.17
@@ -577,7 +577,7 @@
/* 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,
Index: dirserv.c
===================================================================
RCS file: /home/or/cvsroot/src/or/dirserv.c,v
retrieving revision 1.112
retrieving revision 1.113
diff -u -d -r1.112 -r1.113
--- dirserv.c 7 Nov 2004 01:33:06 -0000 1.112
+++ dirserv.c 9 Nov 2004 07:05:53 -0000 1.113
@@ -711,8 +711,8 @@
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.");
}
Index: hibernate.c
===================================================================
RCS file: /home/or/cvsroot/src/or/hibernate.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- hibernate.c 9 Nov 2004 02:12:41 -0000 1.11
+++ hibernate.c 9 Nov 2004 07:05:53 -0000 1.12
@@ -328,7 +328,7 @@
(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 @@
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;
}
Index: main.c
===================================================================
RCS file: /home/or/cvsroot/src/or/main.c,v
retrieving revision 1.359
retrieving revision 1.360
diff -u -d -r1.359 -r1.360
--- main.c 9 Nov 2004 04:28:17 -0000 1.359
+++ main.c 9 Nov 2004 07:05:53 -0000 1.360
@@ -692,6 +692,7 @@
* 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 @@
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 @@
}
/* 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;
Index: or.h
===================================================================
RCS file: /home/or/cvsroot/src/or/or.h,v
retrieving revision 1.468
retrieving revision 1.469
diff -u -d -r1.468 -r1.469
--- or.h 9 Nov 2004 06:40:32 -0000 1.468
+++ or.h 9 Nov 2004 07:05:53 -0000 1.469
@@ -1105,7 +1105,6 @@
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);
Index: router.c
===================================================================
RCS file: /home/or/cvsroot/src/or/router.c,v
retrieving revision 1.112
retrieving revision 1.113
diff -u -d -r1.112 -r1.113
--- router.c 7 Nov 2004 23:19:12 -0000 1.112
+++ router.c 9 Nov 2004 07:05:53 -0000 1.113
@@ -103,9 +103,9 @@
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 @@
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;
}
Index: routerlist.c
===================================================================
RCS file: /home/or/cvsroot/src/or/routerlist.c,v
retrieving revision 1.178
retrieving revision 1.179
diff -u -d -r1.178 -r1.179
--- routerlist.c 7 Nov 2004 01:33:06 -0000 1.178
+++ routerlist.c 9 Nov 2004 07:05:53 -0000 1.179
@@ -48,30 +48,31 @@
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;
}
More information about the tor-commits
mailing list