diff options
author | teor <teor@torproject.org> | 2019-10-31 00:28:05 +1000 |
---|---|---|
committer | teor <teor@torproject.org> | 2019-11-04 13:10:00 +1000 |
commit | d3c8486724ad29c732bbae591f11b0597641a446 (patch) | |
tree | 542f5791879a7942bd0092d725dab1dc5a8705f8 | |
parent | 85e50954d85e0372d2f4e854e651817389b4ece9 (diff) | |
download | tor-d3c8486724ad29c732bbae591f11b0597641a446.tar.gz tor-d3c8486724ad29c732bbae591f11b0597641a446.zip |
relay: Disable relay config when the module is disabled
This commit:
* disables the ORPort, DirPort, DirCache, and BridgeRelay options,
* sets ClientOnly 1,
* disables relay_config.c and relay/transport_config.c,
* disables test_rebind.sh, and
* modifies the expected results for test_parseconf.sh,
when the relay module is disabled.
Part of 32213.
20 files changed, 144 insertions, 16 deletions
diff --git a/src/core/include.am b/src/core/include.am index eda929df4a..a69914619e 100644 --- a/src/core/include.am +++ b/src/core/include.am @@ -143,13 +143,11 @@ LIBTOR_APP_A_SOURCES = \ src/feature/relay/dns.c \ src/feature/relay/ext_orport.c \ src/feature/relay/onion_queue.c \ - src/feature/relay/relay_config.c \ src/feature/relay/relay_periodic.c \ src/feature/relay/relay_sys.c \ src/feature/relay/router.c \ src/feature/relay/routerkeys.c \ src/feature/relay/selftest.c \ - src/feature/relay/transport_config.c \ src/feature/rend/rendcache.c \ src/feature/rend/rendclient.c \ src/feature/rend/rendcommon.c \ @@ -173,11 +171,13 @@ endif LIBTOR_APP_TESTING_A_SOURCES = $(LIBTOR_APP_A_SOURCES) # The Relay module. -MODULE_RELAY_SOURCES = \ - src/feature/relay/routermode.c +MODULE_RELAY_SOURCES = \ + src/feature/relay/routermode.c \ + src/feature/relay/relay_config.c \ + src/feature/relay/transport_config.c # The Directory Authority module. -MODULE_DIRAUTH_SOURCES = \ +MODULE_DIRAUTH_SOURCES = \ src/feature/dirauth/authmode.c \ src/feature/dirauth/bridgeauth.c \ src/feature/dirauth/bwauth.c \ diff --git a/src/feature/relay/relay_config.h b/src/feature/relay/relay_config.h index 13ab0fe7f2..5f08fc3e0f 100644 --- a/src/feature/relay/relay_config.h +++ b/src/feature/relay/relay_config.h @@ -12,12 +12,19 @@ #ifndef TOR_FEATURE_RELAY_RELAY_CONFIG_H #define TOR_FEATURE_RELAY_RELAY_CONFIG_H +typedef struct or_options_t or_options_t; + +#ifdef HAVE_MODULE_RELAY + #include "lib/cc/torint.h" #include "lib/testsupport/testsupport.h" -typedef struct or_options_t or_options_t; typedef struct smartlist_t smartlist_t; +int options_validate_relay_mode(const or_options_t *old_options, + or_options_t *options, + char **msg); + MOCK_DECL(const char*, get_dirportfrontpage, (void)); void relay_config_free_all(void); @@ -58,10 +65,6 @@ int options_validate_relay_accounting(const or_options_t *old_options, or_options_t *options, char **msg); -int options_validate_relay_mode(const or_options_t *old_options, - or_options_t *options, - char **msg); - int options_validate_relay_testing(const or_options_t *old_options, or_options_t *options, char **msg); @@ -70,6 +73,7 @@ int options_act_relay(const or_options_t *old_options); int options_act_relay_accounting(const or_options_t *old_options); int options_act_relay_bandwidth(const or_options_t *old_options); int options_act_bridge_stats(const or_options_t *old_options); + int options_act_relay_stats(const or_options_t *old_options, bool *print_notice_out); void options_act_relay_stats_msg(void); @@ -86,4 +90,99 @@ STATIC int have_enough_mem_for_dircache(const or_options_t *options, #endif +#else + +#include "lib/cc/compat_compiler.h" + +/** When tor is compiled with the relay module disabled, it can't be + * configured as a relay or bridge. + * + * Always sets ClientOnly to 1. + * + * Returns -1 and sets msg to a newly allocated string, if ORPort, DirPort, + * DirCache, or BridgeRelay are set in options. Otherwise returns 0. */ +static inline int +options_validate_relay_mode(const or_options_t *old_options, + or_options_t *options, + char **msg) +{ + (void)old_options; + + /* Only check the primary options for now, #29211 will disable more + * options. These ORPort and DirPort checks are too strict, and will + * reject valid configs that disable ports, like "ORPort 0". */ + if (options->DirCache || + options->BridgeRelay || + options->ORPort_lines || + options->DirPort_lines) { + /* REJECT() this configuration */ + *msg = tor_strdup("This tor was built with relay mode disabled. " + "It can not be configured with an ORPort, a DirPort, " + "DirCache 1, or BridgeRelay 1."); + return -1; + } + + /* 31851 / 29211: Set this option the correct way */ + options->ClientOnly = 1; + + return 0; +} + +#define get_dirportfrontpage() \ + (NULL) +#define relay_config_free_all() \ + STMT_BEGIN STMT_END + +#define get_effective_bwrate(options) \ + (((void)(options)),0) +#define get_effective_bwburst(options) \ + (((void)(options)),0) + +#define warn_nonlocal_ext_orports(ports, portname) \ + (((void)(ports)),((void)(portname))) + +#define parse_ports_relay(options, msg, ports_out, have_low_ports_out) \ + (((void)(options)),((void)(msg)),((void)(ports_out)), \ + ((void)(have_low_ports_out)),0) +#define update_port_set_relay(options, ports) \ + (((void)(options)),((void)(ports))) + +#define options_validate_relay_os(old_options, options, msg) \ + (((void)(old_options)),((void)(options)),((void)(msg)),0) +#define options_validate_relay_info(old_options, options, msg) \ + (((void)(old_options)),((void)(options)),((void)(msg)),0) +#define options_validate_publish_server(old_options, options, msg) \ + (((void)(old_options)),((void)(options)),((void)(msg)),0) +#define options_validate_relay_padding(old_options, options, msg) \ + (((void)(old_options)),((void)(options)),((void)(msg)),0) +#define options_validate_relay_bandwidth(old_options, options, msg) \ + (((void)(old_options)),((void)(options)),((void)(msg)),0) +#define options_validate_relay_accounting(old_options, options, msg) \ + (((void)(old_options)),((void)(options)),((void)(msg)),0) +#define options_validate_relay_testing(old_options, options, msg) \ + (((void)(old_options)),((void)(options)),((void)(msg)),0) + +#define options_act_relay(old_options) \ + (((void)(old_options)),0) +#define options_act_relay_accounting(old_options) \ + (((void)(old_options)),0) +#define options_act_relay_bandwidth(old_options) \ + (((void)(old_options)),0) +#define options_act_bridge_stats(old_options) \ + (((void)(old_options)),0) + +#define options_act_relay_stats(old_options, print_notice_out) \ + (((void)(old_options)),((void)(print_notice_out)),0) +#define options_act_relay_stats_msg() \ + STMT_BEGIN STMT_END + +#define options_act_relay_desc(old_options) \ + (((void)(old_options)),0) +#define options_act_relay_dos(old_options) \ + (((void)(old_options)),0) +#define options_act_relay_dir(old_options) \ + (((void)(old_options)),0) + +#endif + #endif /* !defined(TOR_FEATURE_RELAY_RELAY_CONFIG_H) */ diff --git a/src/feature/relay/transport_config.h b/src/feature/relay/transport_config.h index fe3747f665..c23eee03c3 100644 --- a/src/feature/relay/transport_config.h +++ b/src/feature/relay/transport_config.h @@ -12,6 +12,8 @@ #ifndef TOR_FEATURE_RELAY_TRANSPORT_CONFIG_H #define TOR_FEATURE_RELAY_TRANSPORT_CONFIG_H +#ifdef HAVE_MODULE_RELAY + #include "lib/testsupport/testsupport.h" typedef struct or_options_t or_options_t; @@ -34,4 +36,20 @@ STATIC smartlist_t *get_options_from_transport_options_line( #endif +#else + +#define get_transport_bindaddr_from_config(transport) \ + (((void)(transport)),NULL) + +/* 31851: called from client/transports.c, but only from server code */ +#define get_options_for_server_transport(transport) \ + (((void)(transport)),NULL) + +#define options_validate_server_transport(old_options, options, msg) \ + (((void)(old_options)),((void)(options)),((void)(msg)),0) +#define options_act_server_transport(old_options) \ + (((void)(old_options)),0) + +#endif + #endif /* !defined(TOR_FEATURE_RELAY_TRANSPORT_CONFIG_H) */ diff --git a/src/test/conf_examples/badnick_1/error_no_dirauth_relay b/src/test/conf_examples/badnick_1/error_no_dirauth_relay new file mode 100644 index 0000000000..9f9c0fd8f3 --- /dev/null +++ b/src/test/conf_examples/badnick_1/error_no_dirauth_relay @@ -0,0 +1 @@ +This tor was built with relay mode disabled. diff --git a/src/test/conf_examples/badnick_2/error_no_dirauth_relay b/src/test/conf_examples/badnick_2/error_no_dirauth_relay new file mode 100644 index 0000000000..9f9c0fd8f3 --- /dev/null +++ b/src/test/conf_examples/badnick_2/error_no_dirauth_relay @@ -0,0 +1 @@ +This tor was built with relay mode disabled. diff --git a/src/test/conf_examples/contactinfo_notutf8/error_no_dirauth_relay b/src/test/conf_examples/contactinfo_notutf8/error_no_dirauth_relay new file mode 100644 index 0000000000..9f9c0fd8f3 --- /dev/null +++ b/src/test/conf_examples/contactinfo_notutf8/error_no_dirauth_relay @@ -0,0 +1 @@ +This tor was built with relay mode disabled. diff --git a/src/test/conf_examples/example_1/error_no_dirauth_relay b/src/test/conf_examples/example_1/error_no_dirauth_relay new file mode 100644 index 0000000000..9f9c0fd8f3 --- /dev/null +++ b/src/test/conf_examples/example_1/error_no_dirauth_relay @@ -0,0 +1 @@ +This tor was built with relay mode disabled. diff --git a/src/test/conf_examples/example_3/error_no_dirauth_relay b/src/test/conf_examples/example_3/error_no_dirauth_relay new file mode 100644 index 0000000000..9f9c0fd8f3 --- /dev/null +++ b/src/test/conf_examples/example_3/error_no_dirauth_relay @@ -0,0 +1 @@ +This tor was built with relay mode disabled. diff --git a/src/test/conf_examples/include_1/error_no_dirauth_relay b/src/test/conf_examples/include_1/error_no_dirauth_relay new file mode 100644 index 0000000000..9f9c0fd8f3 --- /dev/null +++ b/src/test/conf_examples/include_1/error_no_dirauth_relay @@ -0,0 +1 @@ +This tor was built with relay mode disabled. diff --git a/src/test/conf_examples/include_bug_31408/error_no_dirauth_relay b/src/test/conf_examples/include_bug_31408/error_no_dirauth_relay new file mode 100644 index 0000000000..9f9c0fd8f3 --- /dev/null +++ b/src/test/conf_examples/include_bug_31408/error_no_dirauth_relay @@ -0,0 +1 @@ +This tor was built with relay mode disabled. diff --git a/src/test/conf_examples/large_1/error_no_dirauth_relay b/src/test/conf_examples/large_1/error_no_dirauth_relay new file mode 100644 index 0000000000..9f9c0fd8f3 --- /dev/null +++ b/src/test/conf_examples/large_1/error_no_dirauth_relay @@ -0,0 +1 @@ +This tor was built with relay mode disabled. diff --git a/src/test/conf_examples/ops_1/error_no_dirauth_relay b/src/test/conf_examples/ops_1/error_no_dirauth_relay new file mode 100644 index 0000000000..9f9c0fd8f3 --- /dev/null +++ b/src/test/conf_examples/ops_1/error_no_dirauth_relay @@ -0,0 +1 @@ +This tor was built with relay mode disabled. diff --git a/src/test/conf_examples/ops_1/expected_no_dirauth_relay b/src/test/conf_examples/ops_1/expected_no_dirauth_relay deleted file mode 100644 index 2bb9bfa132..0000000000 --- a/src/test/conf_examples/ops_1/expected_no_dirauth_relay +++ /dev/null @@ -1 +0,0 @@ -ORPort 1000 diff --git a/src/test/conf_examples/ops_3/error_no_dirauth_relay b/src/test/conf_examples/ops_3/error_no_dirauth_relay new file mode 100644 index 0000000000..9f9c0fd8f3 --- /dev/null +++ b/src/test/conf_examples/ops_3/error_no_dirauth_relay @@ -0,0 +1 @@ +This tor was built with relay mode disabled. diff --git a/src/test/conf_examples/ops_3/expected_no_dirauth_relay b/src/test/conf_examples/ops_3/expected_no_dirauth_relay deleted file mode 100644 index 93dea50eeb..0000000000 --- a/src/test/conf_examples/ops_3/expected_no_dirauth_relay +++ /dev/null @@ -1,2 +0,0 @@ -ORPort 9999 -ORPort 1000 diff --git a/src/test/conf_examples/ops_4/error_no_dirauth_relay b/src/test/conf_examples/ops_4/error_no_dirauth_relay new file mode 100644 index 0000000000..9f9c0fd8f3 --- /dev/null +++ b/src/test/conf_examples/ops_4/error_no_dirauth_relay @@ -0,0 +1 @@ +This tor was built with relay mode disabled. diff --git a/src/test/conf_examples/ops_4/expected_no_dirauth_relay b/src/test/conf_examples/ops_4/expected_no_dirauth_relay deleted file mode 100644 index 56b3a5b71f..0000000000 --- a/src/test/conf_examples/ops_4/expected_no_dirauth_relay +++ /dev/null @@ -1 +0,0 @@ -ORPort 9099 diff --git a/src/test/conf_examples/ops_5/error_no_dirauth_relay b/src/test/conf_examples/ops_5/error_no_dirauth_relay new file mode 100644 index 0000000000..9f9c0fd8f3 --- /dev/null +++ b/src/test/conf_examples/ops_5/error_no_dirauth_relay @@ -0,0 +1 @@ +This tor was built with relay mode disabled. diff --git a/src/test/conf_examples/ops_5/expected_no_dirauth_relay b/src/test/conf_examples/ops_5/expected_no_dirauth_relay deleted file mode 100644 index 834a785090..0000000000 --- a/src/test/conf_examples/ops_5/expected_no_dirauth_relay +++ /dev/null @@ -1,2 +0,0 @@ -ORPort 9000 -ORPort 9099 diff --git a/src/test/test_rebind.sh b/src/test/test_rebind.sh index d6d9d86668..62c9283fc9 100755 --- a/src/test/test_rebind.sh +++ b/src/test/test_rebind.sh @@ -12,6 +12,11 @@ if test "$UNAME_OS" = 'CYGWIN' || \ fi fi +if "${TESTING_TOR_BINARY}" --list-modules | grep -q "relay: no"; then + echo "This test requires the relay module. Skipping." >&2 + exit 77 +fi + tmpdir= clean () { if [ -n "$tmpdir" ] && [ -d "$tmpdir" ]; then |