From 15371d801cf7668b57bf3eb20f29afb6489bb027 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 30 Oct 2019 15:12:01 -0400 Subject: [PATCH 1/2] Mark more torrc options as FILENAME rather than as STRING. This will help us reimplement warn_about_relative_paths(). FILENAME options currently are the same as STRINGs in most respects, except for the type reported to the controller. In this commit, I'm picking the options to change based on: * the current contents of warn_about_relative_paths() * options that end with "File". --- src/app/config/config.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/app/config/config.c b/src/app/config/config.c index 2f40dd2bb9..cda2440963 100644 --- a/src/app/config/config.c +++ b/src/app/config/config.c @@ -382,7 +382,7 @@ static const config_var_t option_vars_[] = { V(UnixSocksGroupWritable, BOOL, "0"), V(CookieAuthentication, BOOL, "0"), V(CookieAuthFileGroupReadable, BOOL, "0"), - V(CookieAuthFile, STRING, NULL), + V(CookieAuthFile, FILENAME, NULL), V(CountPrivateBandwidth, BOOL, "0"), VAR("DataDirectory", FILENAME, DataDirectory_option, NULL), V(DataDirectoryGroupReadable, BOOL, "0"), @@ -452,7 +452,7 @@ static const config_var_t option_vars_[] = { V(ExtendAllowPrivateAddresses, BOOL, "0"), V(ExitRelay, AUTOBOOL, "auto"), VPORT(ExtORPort), - V(ExtORPortCookieAuthFile, STRING, NULL), + V(ExtORPortCookieAuthFile, FILENAME, NULL), V(ExtORPortCookieAuthFileGroupReadable, BOOL, "0"), V(ExtraInfoStatistics, BOOL, "1"), V(ExtendByEd25519ID, AUTOBOOL, "auto"), @@ -590,7 +590,7 @@ static const config_var_t option_vars_[] = { V(PathsNeededToBuildCircuits, DOUBLE, "-1"), V(PerConnBWBurst, MEMUNIT, "0"), V(PerConnBWRate, MEMUNIT, "0"), - V(PidFile, STRING, NULL), + V(PidFile, FILENAME, NULL), V(TestingTorNetwork, BOOL, "0"), V(TestingMinExitFlagThreshold, MEMUNIT, "0"), V(TestingMinFastFlagThreshold, MEMUNIT, "0"), @@ -635,7 +635,7 @@ static const config_var_t option_vars_[] = { V(ServerDNSAllowNonRFC953Hostnames, BOOL,"0"), V(ServerDNSDetectHijacking, BOOL, "1"), V(ServerDNSRandomizeCase, BOOL, "1"), - V(ServerDNSResolvConfFile, STRING, NULL), + V(ServerDNSResolvConfFile, FILENAME, NULL), V(ServerDNSSearchDomains, BOOL, "0"), V(ServerDNSTestAddresses, CSV, "www.google.com,www.mit.edu,www.yahoo.com,www.slashdot.org"), From 14831ea0ab7afbcdb1c0d91242f924d99ed4fcac Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 30 Oct 2019 15:32:12 -0400 Subject: [PATCH 2/2] Use FILENAME to determine which options to check for relative paths This is part of ticket 32344. --- changes/ticket32339_relative | 4 ++++ src/app/config/config.c | 31 +++++++++++++------------------ 2 files changed, 17 insertions(+), 18 deletions(-) create mode 100644 changes/ticket32339_relative diff --git a/changes/ticket32339_relative b/changes/ticket32339_relative new file mode 100644 index 0000000000..83af9f031b --- /dev/null +++ b/changes/ticket32339_relative @@ -0,0 +1,4 @@ + o Code simplification and refactoring: + - Instead of keeping a list of configuration options to check for + relative paths, check all the options whose type is "FILENAME". + Solves part of ticket 32339. diff --git a/src/app/config/config.c b/src/app/config/config.c index cda2440963..275ac9e762 100644 --- a/src/app/config/config.c +++ b/src/app/config/config.c @@ -3324,25 +3324,20 @@ warn_about_relative_paths(or_options_t *options) { tor_assert(options); int n = 0; + const config_mgr_t *mgr = get_options_mgr(); - n += warn_if_option_path_is_relative("CookieAuthFile", - options->CookieAuthFile); - n += warn_if_option_path_is_relative("ExtORPortCookieAuthFile", - options->ExtORPortCookieAuthFile); - n += warn_if_option_path_is_relative("DirPortFrontPage", - options->DirPortFrontPage); - n += warn_if_option_path_is_relative("V3BandwidthsFile", - options->V3BandwidthsFile); - n += warn_if_option_path_is_relative("ControlPortWriteToFile", - options->ControlPortWriteToFile); - n += warn_if_option_path_is_relative("GeoIPFile",options->GeoIPFile); - n += warn_if_option_path_is_relative("GeoIPv6File",options->GeoIPv6File); - n += warn_if_option_path_is_relative("Log",options->DebugLogFile); - n += warn_if_option_path_is_relative("AccelDir",options->AccelDir); - n += warn_if_option_path_is_relative("DataDirectory",options->DataDirectory); - n += warn_if_option_path_is_relative("PidFile",options->PidFile); - n += warn_if_option_path_is_relative("ClientOnionAuthDir", - options->ClientOnionAuthDir); + smartlist_t *vars = config_mgr_list_vars(mgr); + SMARTLIST_FOREACH_BEGIN(vars, const config_var_t *, cv) { + config_line_t *line; + if (cv->member.type != CONFIG_TYPE_FILENAME) + continue; + const char *name = cv->member.name; + line = config_get_assigned_option(mgr, options, name, 0); + if (line) + n += warn_if_option_path_is_relative(name, line->value); + config_free_lines(line); + } SMARTLIST_FOREACH_END(cv); + smartlist_free(vars); for (config_line_t *hs_line = options->RendConfigLines; hs_line; hs_line = hs_line->next) {