mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2025-02-25 15:10:48 +01:00
Implement the various get_foodir_*() functions.
This commit is contained in:
parent
a9806af261
commit
a57bcffcc7
9 changed files with 135 additions and 96 deletions
|
@ -7984,53 +7984,56 @@ init_libevent(const or_options_t *options)
|
||||||
suppress_libevent_log_msg(NULL);
|
suppress_libevent_log_msg(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Return a newly allocated string holding a filename relative to the data
|
/** Return a newly allocated string holding a filename relative to the
|
||||||
* directory. If <b>sub1</b> is present, it is the first path component after
|
* directory in <b>options</b> specified by <b>roottype</b>.
|
||||||
|
* If <b>sub1</b> is present, it is the first path component after
|
||||||
* the data directory. If <b>sub2</b> is also present, it is the second path
|
* the data directory. If <b>sub2</b> is also present, it is the second path
|
||||||
* component after the data directory. If <b>suffix</b> is present, it
|
* component after the data directory. If <b>suffix</b> is present, it
|
||||||
* is appended to the filename.
|
* is appended to the filename.
|
||||||
*
|
*
|
||||||
* Examples:
|
* Note: Consider using macros in config.h that wrap this function;
|
||||||
* get_datadir_fname2_suffix("a", NULL, NULL) -> $DATADIR/a
|
* you should probably never need to call it as-is.
|
||||||
* get_datadir_fname2_suffix("a", NULL, ".tmp") -> $DATADIR/a.tmp
|
|
||||||
* get_datadir_fname2_suffix("a", "b", ".tmp") -> $DATADIR/a/b/.tmp
|
|
||||||
* get_datadir_fname2_suffix("a", "b", NULL) -> $DATADIR/a/b
|
|
||||||
*
|
|
||||||
* Note: Consider using the get_datadir_fname* macros in or.h.
|
|
||||||
*/
|
*/
|
||||||
MOCK_IMPL(char *,
|
MOCK_IMPL(char *,
|
||||||
options_get_datadir_fname2_suffix,(const or_options_t *options,
|
options_get_dir_fname2_suffix,(const or_options_t *options,
|
||||||
|
directory_root_t roottype,
|
||||||
const char *sub1, const char *sub2,
|
const char *sub1, const char *sub2,
|
||||||
const char *suffix))
|
const char *suffix))
|
||||||
{
|
{
|
||||||
char *fname = NULL;
|
|
||||||
size_t len;
|
|
||||||
tor_assert(options);
|
tor_assert(options);
|
||||||
tor_assert(options->DataDirectory);
|
|
||||||
tor_assert(sub1 || !sub2); /* If sub2 is present, sub1 must be present. */
|
const char *rootdir = NULL;
|
||||||
len = strlen(options->DataDirectory);
|
switch (roottype) {
|
||||||
if (sub1) {
|
case DIRROOT_DATADIR:
|
||||||
len += strlen(sub1)+1;
|
rootdir = options->DataDirectory;
|
||||||
if (sub2)
|
break;
|
||||||
len += strlen(sub2)+1;
|
case DIRROOT_CACHEDIR:
|
||||||
|
rootdir = options->CacheDirectory;
|
||||||
|
break;
|
||||||
|
case DIRROOT_KEYDIR:
|
||||||
|
rootdir = options->KeyDirectory;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
tor_assert_unreached();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if (suffix)
|
tor_assert(rootdir);
|
||||||
len += strlen(suffix);
|
|
||||||
len++;
|
if (!suffix)
|
||||||
fname = tor_malloc(len);
|
suffix = "";
|
||||||
if (sub1) {
|
|
||||||
if (sub2) {
|
char *fname = NULL;
|
||||||
tor_snprintf(fname, len, "%s"PATH_SEPARATOR"%s"PATH_SEPARATOR"%s",
|
|
||||||
options->DataDirectory, sub1, sub2);
|
if (sub1 == NULL) {
|
||||||
|
tor_asprintf(&fname, "%s%s", rootdir, suffix);
|
||||||
|
tor_assert(!sub2); /* If sub2 is present, sub1 must be present. */
|
||||||
|
} else if (sub2 == NULL) {
|
||||||
|
tor_asprintf(&fname, "%s"PATH_SEPARATOR"%s%s", rootdir, sub1, suffix);
|
||||||
} else {
|
} else {
|
||||||
tor_snprintf(fname, len, "%s"PATH_SEPARATOR"%s",
|
tor_asprintf(&fname, "%s"PATH_SEPARATOR"%s"PATH_SEPARATOR"%s%s",
|
||||||
options->DataDirectory, sub1);
|
rootdir, sub1, sub2, suffix);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
strlcpy(fname, options->DataDirectory, len);
|
|
||||||
}
|
|
||||||
if (suffix)
|
|
||||||
strlcat(fname, suffix, len);
|
|
||||||
return fname;
|
return fname;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,45 +58,72 @@ config_line_t *option_get_assignment(const or_options_t *options,
|
||||||
const char *key);
|
const char *key);
|
||||||
int options_save_current(void);
|
int options_save_current(void);
|
||||||
const char *get_torrc_fname(int defaults_fname);
|
const char *get_torrc_fname(int defaults_fname);
|
||||||
|
typedef enum {
|
||||||
|
DIRROOT_DATADIR,
|
||||||
|
DIRROOT_CACHEDIR,
|
||||||
|
DIRROOT_KEYDIR
|
||||||
|
} directory_root_t;
|
||||||
|
|
||||||
MOCK_DECL(char *,
|
MOCK_DECL(char *,
|
||||||
options_get_datadir_fname2_suffix,
|
options_get_dir_fname2_suffix,
|
||||||
(const or_options_t *options,
|
(const or_options_t *options,
|
||||||
|
directory_root_t roottype,
|
||||||
const char *sub1, const char *sub2,
|
const char *sub1, const char *sub2,
|
||||||
const char *suffix));
|
const char *suffix));
|
||||||
#define get_datadir_fname2_suffix(sub1, sub2, suffix) \
|
|
||||||
options_get_datadir_fname2_suffix(get_options(), (sub1), (sub2), (suffix))
|
|
||||||
/** Return a newly allocated string containing datadir/sub1. See
|
|
||||||
* get_datadir_fname2_suffix. */
|
|
||||||
#define get_datadir_fname(sub1) get_datadir_fname2_suffix((sub1), NULL, NULL)
|
|
||||||
/** Return a newly allocated string containing datadir/sub1/sub2. See
|
|
||||||
* get_datadir_fname2_suffix. */
|
|
||||||
#define get_datadir_fname2(sub1,sub2) \
|
|
||||||
get_datadir_fname2_suffix((sub1), (sub2), NULL)
|
|
||||||
/** Return a newly allocated string containing datadir/sub1suffix. See
|
|
||||||
* get_datadir_fname2_suffix. */
|
|
||||||
#define get_datadir_fname_suffix(sub1, suffix) \
|
|
||||||
get_datadir_fname2_suffix((sub1), NULL, (suffix))
|
|
||||||
|
|
||||||
/** Return a newly allocated string containing datadir/sub1 relative to
|
/* These macros wrap options_get_dir_fname2_suffix to provide a more
|
||||||
* opts. See get_datadir_fname2_suffix. */
|
* convenient API for finding filenames that Tor uses inside its storage
|
||||||
|
* They are named according to a pattern:
|
||||||
|
* (options_)?get_(cache|key|data)dir_fname(2)?(_suffix)?
|
||||||
|
*
|
||||||
|
* Macros that begin with options_ take an options argument; the others
|
||||||
|
* work with respect to the global options.
|
||||||
|
*
|
||||||
|
* Each macro works relative to the data directory, the key directory,
|
||||||
|
* or the cache directory, as determined by which one is mentioned.
|
||||||
|
*
|
||||||
|
* Macro variants with "2" in their name take two path components; others
|
||||||
|
* take one.
|
||||||
|
*
|
||||||
|
* Macro variants with "_suffix" at the end take an additional suffix
|
||||||
|
* that gets appended to the end of the file
|
||||||
|
*/
|
||||||
|
#define options_get_datadir_fname2_suffix(options, sub1, sub2, suffix) \
|
||||||
|
options_get_dir_fname2_suffix((options), DIRROOT_DATADIR, \
|
||||||
|
(sub1), (sub2), (suffix))
|
||||||
|
#define options_get_cachedir_fname2_suffix(options, sub1, sub2, suffix) \
|
||||||
|
options_get_dir_fname2_suffix((options), DIRROOT_CACHEDIR, \
|
||||||
|
(sub1), (sub2), (suffix))
|
||||||
|
#define options_get_keydir_fname2_suffix(options, sub1, sub2, suffix) \
|
||||||
|
options_get_dir_fname2_suffix((options), DIRROOT_KEYDIR, \
|
||||||
|
(sub1), (sub2), (suffix))
|
||||||
|
|
||||||
#define options_get_datadir_fname(opts,sub1) \
|
#define options_get_datadir_fname(opts,sub1) \
|
||||||
options_get_datadir_fname2_suffix((opts),(sub1), NULL, NULL)
|
options_get_datadir_fname2_suffix((opts),(sub1), NULL, NULL)
|
||||||
/** Return a newly allocated string containing datadir/sub1/sub2 relative to
|
|
||||||
* opts. See get_datadir_fname2_suffix. */
|
|
||||||
#define options_get_datadir_fname2(opts,sub1,sub2) \
|
#define options_get_datadir_fname2(opts,sub1,sub2) \
|
||||||
options_get_datadir_fname2_suffix((opts),(sub1), (sub2), NULL)
|
options_get_datadir_fname2_suffix((opts),(sub1), (sub2), NULL)
|
||||||
|
|
||||||
/** DOCDOC */
|
#define get_datadir_fname2_suffix(sub1, sub2, suffix) \
|
||||||
#define get_keydir_fname(sub1) \
|
options_get_datadir_fname2_suffix(get_options(), (sub1), (sub2), (suffix))
|
||||||
get_datadir_fname2("keys", (sub1))
|
#define get_datadir_fname(sub1) \
|
||||||
#define options_get_keydir_fname(options, sub1) \
|
get_datadir_fname2_suffix((sub1), NULL, NULL)
|
||||||
options_get_datadir_fname2((options), "keys", (sub1))
|
#define get_datadir_fname2(sub1,sub2) \
|
||||||
#define get_keydir_fname_suffix(sub1, suffix) \
|
get_datadir_fname2_suffix((sub1), (sub2), NULL)
|
||||||
get_datadir_fname2_suffix("keys", (sub1), (suffix))
|
#define get_datadir_fname_suffix(sub1, suffix) \
|
||||||
|
get_datadir_fname2_suffix((sub1), NULL, (suffix))
|
||||||
|
|
||||||
#define get_cachedir_fname(sub1) get_datadir_fname((sub1))
|
/** DOCDOC */
|
||||||
|
#define options_get_keydir_fname(options, sub1) \
|
||||||
|
options_get_keydir_fname2_suffix((options), (sub1), NULL, NULL)
|
||||||
|
#define get_keydir_fname_suffix(sub1, suffix) \
|
||||||
|
options_get_keydir_fname2_suffix(get_options(), (sub1), NULL, suffix)
|
||||||
|
#define get_keydir_fname(sub1) \
|
||||||
|
options_get_keydir_fname2_suffix(get_options(), (sub1), NULL, NULL)
|
||||||
|
|
||||||
|
#define get_cachedir_fname(sub1) \
|
||||||
|
options_get_cachedir_fname2_suffix(get_options(), (sub1), NULL, NULL)
|
||||||
#define get_cachedir_fname_suffix(sub1, suffix) \
|
#define get_cachedir_fname_suffix(sub1, suffix) \
|
||||||
get_datadir_fname_suffix((sub1), (suffix))
|
options_get_cachedir_fname2_suffix(get_options(), (sub1), NULL, (suffix))
|
||||||
|
|
||||||
int using_default_dir_authorities(const or_options_t *options);
|
int using_default_dir_authorities(const or_options_t *options);
|
||||||
|
|
||||||
|
|
|
@ -31,8 +31,8 @@ test_conscache_simple_usage(void *arg)
|
||||||
|
|
||||||
/* Make a temporary datadir for these tests */
|
/* Make a temporary datadir for these tests */
|
||||||
char *ddir_fname = tor_strdup(get_fname_rnd("datadir_cache"));
|
char *ddir_fname = tor_strdup(get_fname_rnd("datadir_cache"));
|
||||||
tor_free(get_options_mutable()->DataDirectory);
|
tor_free(get_options_mutable()->CacheDirectory);
|
||||||
get_options_mutable()->DataDirectory = tor_strdup(ddir_fname);
|
get_options_mutable()->CacheDirectory = tor_strdup(ddir_fname);
|
||||||
check_private_dir(ddir_fname, CPD_CREATE, NULL);
|
check_private_dir(ddir_fname, CPD_CREATE, NULL);
|
||||||
consensus_cache_t *cache = consensus_cache_open("cons", 128);
|
consensus_cache_t *cache = consensus_cache_open("cons", 128);
|
||||||
|
|
||||||
|
@ -124,8 +124,8 @@ test_conscache_cleanup(void *arg)
|
||||||
|
|
||||||
/* Make a temporary datadir for these tests */
|
/* Make a temporary datadir for these tests */
|
||||||
char *ddir_fname = tor_strdup(get_fname_rnd("datadir_cache"));
|
char *ddir_fname = tor_strdup(get_fname_rnd("datadir_cache"));
|
||||||
tor_free(get_options_mutable()->DataDirectory);
|
tor_free(get_options_mutable()->CacheDirectory);
|
||||||
get_options_mutable()->DataDirectory = tor_strdup(ddir_fname);
|
get_options_mutable()->CacheDirectory = tor_strdup(ddir_fname);
|
||||||
check_private_dir(ddir_fname, CPD_CREATE, NULL);
|
check_private_dir(ddir_fname, CPD_CREATE, NULL);
|
||||||
consensus_cache_t *cache = consensus_cache_open("cons", 128);
|
consensus_cache_t *cache = consensus_cache_open("cons", 128);
|
||||||
|
|
||||||
|
@ -267,8 +267,8 @@ test_conscache_filter(void *arg)
|
||||||
|
|
||||||
/* Make a temporary datadir for these tests */
|
/* Make a temporary datadir for these tests */
|
||||||
char *ddir_fname = tor_strdup(get_fname_rnd("datadir_cache"));
|
char *ddir_fname = tor_strdup(get_fname_rnd("datadir_cache"));
|
||||||
tor_free(get_options_mutable()->DataDirectory);
|
tor_free(get_options_mutable()->CacheDirectory);
|
||||||
get_options_mutable()->DataDirectory = tor_strdup(ddir_fname);
|
get_options_mutable()->CacheDirectory = tor_strdup(ddir_fname);
|
||||||
check_private_dir(ddir_fname, CPD_CREATE, NULL);
|
check_private_dir(ddir_fname, CPD_CREATE, NULL);
|
||||||
consensus_cache_t *cache = consensus_cache_open("cons", 128);
|
consensus_cache_t *cache = consensus_cache_open("cons", 128);
|
||||||
|
|
||||||
|
|
|
@ -24,8 +24,8 @@ consdiffmgr_test_setup(const struct testcase_t *arg)
|
||||||
{
|
{
|
||||||
(void)arg;
|
(void)arg;
|
||||||
char *ddir_fname = tor_strdup(get_fname_rnd("datadir_cdm"));
|
char *ddir_fname = tor_strdup(get_fname_rnd("datadir_cdm"));
|
||||||
tor_free(get_options_mutable()->DataDirectory);
|
tor_free(get_options_mutable()->CacheDirectory);
|
||||||
get_options_mutable()->DataDirectory = ddir_fname; // now owns the pointer.
|
get_options_mutable()->CacheDirectory = ddir_fname; // now owns the pointer.
|
||||||
check_private_dir(ddir_fname, CPD_CREATE, NULL);
|
check_private_dir(ddir_fname, CPD_CREATE, NULL);
|
||||||
|
|
||||||
consdiff_cfg_t consdiff_cfg = { 300 };
|
consdiff_cfg_t consdiff_cfg = { 300 };
|
||||||
|
@ -215,8 +215,8 @@ test_consdiffmgr_init_failure(void *arg)
|
||||||
/* As in ...test_setup, but do not create the datadir. The missing directory
|
/* As in ...test_setup, but do not create the datadir. The missing directory
|
||||||
* will cause a failure. */
|
* will cause a failure. */
|
||||||
char *ddir_fname = tor_strdup(get_fname_rnd("datadir_cdm"));
|
char *ddir_fname = tor_strdup(get_fname_rnd("datadir_cdm"));
|
||||||
tor_free(get_options_mutable()->DataDirectory);
|
tor_free(get_options_mutable()->CacheDirectory);
|
||||||
get_options_mutable()->DataDirectory = ddir_fname; // now owns the pointer.
|
get_options_mutable()->CacheDirectory = ddir_fname; // now owns the pointer.
|
||||||
|
|
||||||
consdiff_cfg_t consdiff_cfg = { 7200, 300 };
|
consdiff_cfg_t consdiff_cfg = { 7200, 300 };
|
||||||
|
|
||||||
|
|
|
@ -4874,9 +4874,11 @@ mock_check_private_dir(const char *dirname, cpd_check_t check,
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
mock_get_datadir_fname(const or_options_t *options,
|
mock_get_datadir_fname(const or_options_t *options,
|
||||||
|
directory_root_t roottype,
|
||||||
const char *sub1, const char *sub2,
|
const char *sub1, const char *sub2,
|
||||||
const char *suffix)
|
const char *suffix)
|
||||||
{
|
{
|
||||||
|
(void) roottype;
|
||||||
char *rv = NULL;
|
char *rv = NULL;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -5033,7 +5035,7 @@ test_dir_dump_unparseable_descriptors(void *data)
|
||||||
mock_options->MaxUnparseableDescSizeToLog = 1536;
|
mock_options->MaxUnparseableDescSizeToLog = 1536;
|
||||||
MOCK(get_options, mock_get_options);
|
MOCK(get_options, mock_get_options);
|
||||||
MOCK(check_private_dir, mock_check_private_dir);
|
MOCK(check_private_dir, mock_check_private_dir);
|
||||||
MOCK(options_get_datadir_fname2_suffix,
|
MOCK(options_get_dir_fname2_suffix,
|
||||||
mock_get_datadir_fname);
|
mock_get_datadir_fname);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -5551,7 +5553,7 @@ test_dir_dump_unparseable_descriptors(void *data)
|
||||||
mock_unlink_reset();
|
mock_unlink_reset();
|
||||||
UNMOCK(write_str_to_file);
|
UNMOCK(write_str_to_file);
|
||||||
mock_write_str_to_file_reset();
|
mock_write_str_to_file_reset();
|
||||||
UNMOCK(options_get_datadir_fname2_suffix);
|
UNMOCK(options_get_dir_fname2_suffix);
|
||||||
UNMOCK(check_private_dir);
|
UNMOCK(check_private_dir);
|
||||||
UNMOCK(get_options);
|
UNMOCK(get_options);
|
||||||
tor_free(mock_options);
|
tor_free(mock_options);
|
||||||
|
|
|
@ -469,6 +469,7 @@ init_mock_options(void)
|
||||||
memset(mock_options, 0, sizeof(or_options_t));
|
memset(mock_options, 0, sizeof(or_options_t));
|
||||||
mock_options->TestingTorNetwork = 1;
|
mock_options->TestingTorNetwork = 1;
|
||||||
mock_options->DataDirectory = tor_strdup(get_fname_rnd("datadir_tmp"));
|
mock_options->DataDirectory = tor_strdup(get_fname_rnd("datadir_tmp"));
|
||||||
|
mock_options->CacheDirectory = tor_strdup(mock_options->DataDirectory);
|
||||||
check_private_dir(mock_options->DataDirectory, CPD_CREATE, NULL);
|
check_private_dir(mock_options->DataDirectory, CPD_CREATE, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,12 +69,12 @@ test_md_cache(void *data)
|
||||||
time3 = time(NULL) - 15*24*60*60;
|
time3 = time(NULL) - 15*24*60*60;
|
||||||
|
|
||||||
/* Possibly, turn this into a test setup/cleanup pair */
|
/* Possibly, turn this into a test setup/cleanup pair */
|
||||||
tor_free(options->DataDirectory);
|
tor_free(options->CacheDirectory);
|
||||||
options->DataDirectory = tor_strdup(get_fname("md_datadir_test"));
|
options->CacheDirectory = tor_strdup(get_fname("md_datadir_test"));
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
tt_int_op(0, OP_EQ, mkdir(options->DataDirectory));
|
tt_int_op(0, OP_EQ, mkdir(options->CacheDirectory));
|
||||||
#else
|
#else
|
||||||
tt_int_op(0, OP_EQ, mkdir(options->DataDirectory, 0700));
|
tt_int_op(0, OP_EQ, mkdir(options->CacheDirectory, 0700));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
tt_assert(!strcmpstart(test_md3_noannotation, "onion-key"));
|
tt_assert(!strcmpstart(test_md3_noannotation, "onion-key"));
|
||||||
|
@ -152,7 +152,7 @@ test_md_cache(void *data)
|
||||||
strlen(test_md3_noannotation));
|
strlen(test_md3_noannotation));
|
||||||
|
|
||||||
tor_asprintf(&fn, "%s"PATH_SEPARATOR"cached-microdescs.new",
|
tor_asprintf(&fn, "%s"PATH_SEPARATOR"cached-microdescs.new",
|
||||||
options->DataDirectory);
|
options->CacheDirectory);
|
||||||
s = read_file_to_str(fn, RFTS_BIN, NULL);
|
s = read_file_to_str(fn, RFTS_BIN, NULL);
|
||||||
tt_assert(s);
|
tt_assert(s);
|
||||||
tt_mem_op(md1->body, OP_EQ, s + md1->off, md1->bodylen);
|
tt_mem_op(md1->body, OP_EQ, s + md1->off, md1->bodylen);
|
||||||
|
@ -180,7 +180,7 @@ test_md_cache(void *data)
|
||||||
|
|
||||||
/* read the cache. */
|
/* read the cache. */
|
||||||
tor_asprintf(&fn, "%s"PATH_SEPARATOR"cached-microdescs",
|
tor_asprintf(&fn, "%s"PATH_SEPARATOR"cached-microdescs",
|
||||||
options->DataDirectory);
|
options->CacheDirectory);
|
||||||
s = read_file_to_str(fn, RFTS_BIN, NULL);
|
s = read_file_to_str(fn, RFTS_BIN, NULL);
|
||||||
tt_mem_op(md1->body, OP_EQ, s + md1->off, strlen(test_md1));
|
tt_mem_op(md1->body, OP_EQ, s + md1->off, strlen(test_md1));
|
||||||
tt_mem_op(md2->body, OP_EQ, s + md2->off, strlen(test_md2));
|
tt_mem_op(md2->body, OP_EQ, s + md2->off, strlen(test_md2));
|
||||||
|
@ -234,7 +234,7 @@ test_md_cache(void *data)
|
||||||
|
|
||||||
done:
|
done:
|
||||||
if (options)
|
if (options)
|
||||||
tor_free(options->DataDirectory);
|
tor_free(options->CacheDirectory);
|
||||||
microdesc_free_all();
|
microdesc_free_all();
|
||||||
|
|
||||||
smartlist_free(added);
|
smartlist_free(added);
|
||||||
|
@ -266,17 +266,17 @@ test_md_cache_broken(void *data)
|
||||||
|
|
||||||
options = get_options_mutable();
|
options = get_options_mutable();
|
||||||
tt_assert(options);
|
tt_assert(options);
|
||||||
tor_free(options->DataDirectory);
|
tor_free(options->CacheDirectory);
|
||||||
options->DataDirectory = tor_strdup(get_fname("md_datadir_test2"));
|
options->CacheDirectory = tor_strdup(get_fname("md_datadir_test2"));
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
tt_int_op(0, OP_EQ, mkdir(options->DataDirectory));
|
tt_int_op(0, OP_EQ, mkdir(options->CacheDirectory));
|
||||||
#else
|
#else
|
||||||
tt_int_op(0, OP_EQ, mkdir(options->DataDirectory, 0700));
|
tt_int_op(0, OP_EQ, mkdir(options->CacheDirectory, 0700));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
tor_asprintf(&fn, "%s"PATH_SEPARATOR"cached-microdescs",
|
tor_asprintf(&fn, "%s"PATH_SEPARATOR"cached-microdescs",
|
||||||
options->DataDirectory);
|
options->CacheDirectory);
|
||||||
|
|
||||||
write_str_to_file(fn, truncated_md, 1);
|
write_str_to_file(fn, truncated_md, 1);
|
||||||
|
|
||||||
|
@ -285,7 +285,7 @@ test_md_cache_broken(void *data)
|
||||||
|
|
||||||
done:
|
done:
|
||||||
if (options)
|
if (options)
|
||||||
tor_free(options->DataDirectory);
|
tor_free(options->CacheDirectory);
|
||||||
tor_free(fn);
|
tor_free(fn);
|
||||||
microdesc_free_all();
|
microdesc_free_all();
|
||||||
}
|
}
|
||||||
|
@ -754,8 +754,8 @@ test_md_reject_cache(void *arg)
|
||||||
or_options_t *options = get_options_mutable();
|
or_options_t *options = get_options_mutable();
|
||||||
char buf[DIGEST256_LEN];
|
char buf[DIGEST256_LEN];
|
||||||
|
|
||||||
tor_free(options->DataDirectory);
|
tor_free(options->CacheDirectory);
|
||||||
options->DataDirectory = tor_strdup(get_fname("md_datadir_test_rej"));
|
options->CacheDirectory = tor_strdup(get_fname("md_datadir_test_rej"));
|
||||||
mock_rgsbd_val_a = tor_malloc_zero(sizeof(routerstatus_t));
|
mock_rgsbd_val_a = tor_malloc_zero(sizeof(routerstatus_t));
|
||||||
mock_rgsbd_val_b = tor_malloc_zero(sizeof(routerstatus_t));
|
mock_rgsbd_val_b = tor_malloc_zero(sizeof(routerstatus_t));
|
||||||
mock_ns_val = tor_malloc_zero(sizeof(networkstatus_t));
|
mock_ns_val = tor_malloc_zero(sizeof(networkstatus_t));
|
||||||
|
@ -765,9 +765,9 @@ test_md_reject_cache(void *arg)
|
||||||
mock_ns_val->flavor = FLAV_MICRODESC;
|
mock_ns_val->flavor = FLAV_MICRODESC;
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
tt_int_op(0, OP_EQ, mkdir(options->DataDirectory));
|
tt_int_op(0, OP_EQ, mkdir(options->CacheDirectory));
|
||||||
#else
|
#else
|
||||||
tt_int_op(0, OP_EQ, mkdir(options->DataDirectory, 0700));
|
tt_int_op(0, OP_EQ, mkdir(options->CacheDirectory, 0700));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
MOCK(router_get_mutable_consensus_status_by_descriptor_digest,
|
MOCK(router_get_mutable_consensus_status_by_descriptor_digest,
|
||||||
|
@ -802,7 +802,7 @@ test_md_reject_cache(void *arg)
|
||||||
done:
|
done:
|
||||||
UNMOCK(networkstatus_get_latest_consensus_by_flavor);
|
UNMOCK(networkstatus_get_latest_consensus_by_flavor);
|
||||||
UNMOCK(router_get_mutable_consensus_status_by_descriptor_digest);
|
UNMOCK(router_get_mutable_consensus_status_by_descriptor_digest);
|
||||||
tor_free(options->DataDirectory);
|
tor_free(options->CacheDirectory);
|
||||||
microdesc_free_all();
|
microdesc_free_all();
|
||||||
smartlist_free(added);
|
smartlist_free(added);
|
||||||
SMARTLIST_FOREACH(wanted, char *, cp, tor_free(cp));
|
SMARTLIST_FOREACH(wanted, char *, cp, tor_free(cp));
|
||||||
|
|
|
@ -421,6 +421,7 @@ test_routerkeys_ed_keys_init_all(void *arg)
|
||||||
{
|
{
|
||||||
(void)arg;
|
(void)arg;
|
||||||
char *dir = tor_strdup(get_fname("test_ed_keys_init_all"));
|
char *dir = tor_strdup(get_fname("test_ed_keys_init_all"));
|
||||||
|
char *keydir = tor_strdup(get_fname("test_ed_keys_init_all/KEYS"));
|
||||||
or_options_t *options = tor_malloc_zero(sizeof(or_options_t));
|
or_options_t *options = tor_malloc_zero(sizeof(or_options_t));
|
||||||
time_t now = time(NULL);
|
time_t now = time(NULL);
|
||||||
ed25519_public_key_t id;
|
ed25519_public_key_t id;
|
||||||
|
@ -445,13 +446,14 @@ test_routerkeys_ed_keys_init_all(void *arg)
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
mkdir(dir);
|
mkdir(dir);
|
||||||
mkdir(get_fname("test_ed_keys_init_all/keys"));
|
mkdir(keydir);
|
||||||
#else
|
#else
|
||||||
mkdir(dir, 0700);
|
mkdir(dir, 0700);
|
||||||
mkdir(get_fname("test_ed_keys_init_all/keys"), 0700);
|
mkdir(keydir, 0700);
|
||||||
#endif /* defined(_WIN32) */
|
#endif /* defined(_WIN32) */
|
||||||
|
|
||||||
options->DataDirectory = dir;
|
options->DataDirectory = dir;
|
||||||
|
options->KeyDirectory = keydir;
|
||||||
|
|
||||||
tt_int_op(1, OP_EQ, load_ed_keys(options, now));
|
tt_int_op(1, OP_EQ, load_ed_keys(options, now));
|
||||||
tt_int_op(0, OP_EQ, generate_ed_link_cert(options, now, 0));
|
tt_int_op(0, OP_EQ, generate_ed_link_cert(options, now, 0));
|
||||||
|
@ -521,7 +523,7 @@ test_routerkeys_ed_keys_init_all(void *arg)
|
||||||
|
|
||||||
/* Demonstrate that we can start up with no secret identity key */
|
/* Demonstrate that we can start up with no secret identity key */
|
||||||
routerkeys_free_all();
|
routerkeys_free_all();
|
||||||
unlink(get_fname("test_ed_keys_init_all/keys/"
|
unlink(get_fname("test_ed_keys_init_all/KEYS/"
|
||||||
"ed25519_master_id_secret_key"));
|
"ed25519_master_id_secret_key"));
|
||||||
tt_int_op(1, OP_EQ, load_ed_keys(options, now));
|
tt_int_op(1, OP_EQ, load_ed_keys(options, now));
|
||||||
tt_int_op(0, OP_EQ, generate_ed_link_cert(options, now, 0));
|
tt_int_op(0, OP_EQ, generate_ed_link_cert(options, now, 0));
|
||||||
|
@ -542,6 +544,7 @@ test_routerkeys_ed_keys_init_all(void *arg)
|
||||||
|
|
||||||
done:
|
done:
|
||||||
tor_free(dir);
|
tor_free(dir);
|
||||||
|
tor_free(keydir);
|
||||||
tor_free(options);
|
tor_free(options);
|
||||||
tor_cert_free(link_cert);
|
tor_cert_free(link_cert);
|
||||||
routerkeys_free_all();
|
routerkeys_free_all();
|
||||||
|
|
|
@ -293,6 +293,9 @@ main(int c, const char **v)
|
||||||
setup_directory();
|
setup_directory();
|
||||||
options_init(options);
|
options_init(options);
|
||||||
options->DataDirectory = tor_strdup(temp_dir);
|
options->DataDirectory = tor_strdup(temp_dir);
|
||||||
|
tor_asprintf(&options->KeyDirectory, "%s"PATH_SEPARATOR"keys",
|
||||||
|
options->DataDirectory);
|
||||||
|
options->CacheDirectory = tor_strdup(temp_dir);
|
||||||
options->EntryStatistics = 1;
|
options->EntryStatistics = 1;
|
||||||
if (set_options(options, &errmsg) < 0) {
|
if (set_options(options, &errmsg) < 0) {
|
||||||
printf("Failed to set initial options: %s\n", errmsg);
|
printf("Failed to set initial options: %s\n", errmsg);
|
||||||
|
|
Loading…
Add table
Reference in a new issue