From 09c54655f1fb87b6522d2fdbc6d8b5f50d362840 Mon Sep 17 00:00:00 2001 From: rl1987 Date: Sun, 22 Mar 2015 20:07:59 +0200 Subject: [PATCH] Complain if relative paths are used in configuration When we validate torrc options, print warning(s) when relative path(s) been found. --- changes/bug14018 | 4 +++ src/or/config.c | 64 +++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 changes/bug14018 diff --git a/changes/bug14018 b/changes/bug14018 new file mode 100644 index 0000000000..165e0427f5 --- /dev/null +++ b/changes/bug14018 @@ -0,0 +1,4 @@ + o Minor features: + - Complain (i.e. print a warning) whenever we find a relative + file path being used as torrc option. Resolves issue 14018. + diff --git a/src/or/config.c b/src/or/config.c index 8d15d0df2f..c44753194e 100644 --- a/src/or/config.c +++ b/src/or/config.c @@ -2563,6 +2563,62 @@ options_validate_cb(void *old_options, void *options, void *default_options, from_setconf, msg); } +#define REJECT(arg) \ + STMT_BEGIN *msg = tor_strdup(arg); return -1; STMT_END +#define COMPLAIN(args...) \ + STMT_BEGIN log_warn(LD_CONFIG, args); STMT_END + +/** Log a warning message iff filepath is not absolute. + * Warning message must contain option name option and + * an absolute path that filepath will resolve to. + * + * In case filepath is absolute, do nothing. + */ +static void +warn_if_option_path_is_relative(const char *option, + char *filepath) +{ + if (filepath &&path_is_relative(filepath)) + COMPLAIN("Path for %s (%s) is relative and will resolve to %s." + " Is this what you wanted?",option,filepath, + make_path_absolute(filepath)); +} + +/** Scan options for occurances of relative file/directory + * path and log a warning whenever it is found. + */ +static void +warn_about_relative_paths(or_options_t *options) +{ + tor_assert(options); + + warn_if_option_path_is_relative("CookieAuthFile", + options->CookieAuthFile); + warn_if_option_path_is_relative("ExtORPortCookieAuthFile", + options->ExtORPortCookieAuthFile); + warn_if_option_path_is_relative("DirPortFrontPage", + options->DirPortFrontPage); + warn_if_option_path_is_relative("PortForwardingHelper", + options->PortForwardingHelper); + warn_if_option_path_is_relative("V3BandwidthsFile", + options->V3BandwidthsFile); + warn_if_option_path_is_relative("ControlPortWriteToFile", + options->ControlPortWriteToFile); + warn_if_option_path_is_relative("GeoIPFile",options->GeoIPFile); + warn_if_option_path_is_relative("GeoIPv6File",options->GeoIPv6File); + warn_if_option_path_is_relative("Log",options->DebugLogFile); + warn_if_option_path_is_relative("AccelDir",options->AccelDir); + warn_if_option_path_is_relative("Log",options->DebugLogFile); + warn_if_option_path_is_relative("DataDirectory",options->DataDirectory); + warn_if_option_path_is_relative("PidFile",options->PidFile); + + for (config_line_t *hs_line = options->RendConfigLines; hs_line; + hs_line = hs_line->next) { + if (!strcasecmp(hs_line->key, "HiddenServiceDir")) + warn_if_option_path_is_relative("HiddenServiceDir",hs_line->value); + } +} + /** Return 0 if every setting in options is reasonable, is a * permissible transition from old_options, and none of the * testing-only settings differ from default_options unless in @@ -2584,13 +2640,12 @@ options_validate(or_options_t *old_options, or_options_t *options, config_line_t *cl; const char *uname = get_uname(); int n_ports=0; -#define REJECT(arg) \ - STMT_BEGIN *msg = tor_strdup(arg); return -1; STMT_END -#define COMPLAIN(arg) STMT_BEGIN log_warn(LD_CONFIG, arg); STMT_END tor_assert(msg); *msg = NULL; + warn_about_relative_paths(options); + if (server_mode(options) && (!strcmpstart(uname, "Windows 95") || !strcmpstart(uname, "Windows 98") || @@ -3741,9 +3796,10 @@ options_validate(or_options_t *old_options, or_options_t *options, "combination."); return 0; +} + #undef REJECT #undef COMPLAIN -} /* Given the value that the user has set for MaxMemInQueues, compute the * actual maximum value. We clip this value if it's too low, and autodetect