mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-10 21:23:58 +01:00
Stop using the wrong DataDirectory when we're validating.
Also validate/normalize the DataDirectory better. svn:r2732
This commit is contained in:
parent
48a0b6c476
commit
6521c2ce51
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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.");
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user