relay: Simplify some relay_config code

Part of 32213.
This commit is contained in:
teor 2019-10-31 12:19:56 +10:00
parent d3c8486724
commit 4d9a5c77f8

View File

@ -242,6 +242,7 @@ parse_ports_relay(or_options_t *options,
{ {
int retval = -1; int retval = -1;
smartlist_t *ports = smartlist_new(); smartlist_t *ports = smartlist_new();
int n_low_ports = 0;
if (BUG(!options)) if (BUG(!options))
goto err; goto err;
@ -255,7 +256,11 @@ parse_ports_relay(or_options_t *options,
if (BUG(!have_low_ports_out)) if (BUG(!have_low_ports_out))
goto err; goto err;
if (! options->ClientOnly) { if (options->ClientOnly) {
retval = 0;
goto err;
}
if (parse_port_config(ports, if (parse_port_config(ports,
options->ORPort_lines, options->ORPort_lines,
"OR", CONN_TYPE_OR_LISTENER, "OR", CONN_TYPE_OR_LISTENER,
@ -280,15 +285,11 @@ parse_ports_relay(or_options_t *options,
*msg = tor_strdup("Invalid DirPort configuration"); *msg = tor_strdup("Invalid DirPort configuration");
goto err; goto err;
} }
}
int n_low_ports = 0;
if (check_server_ports(ports, options, &n_low_ports) < 0) { if (check_server_ports(ports, options, &n_low_ports) < 0) {
*msg = tor_strdup("Misconfigured server ports"); *msg = tor_strdup("Misconfigured server ports");
goto err; goto err;
} }
if (*have_low_ports_out < 0)
*have_low_ports_out = (n_low_ports > 0);
smartlist_add_all(ports_out, ports); smartlist_add_all(ports_out, ports);
smartlist_free(ports); smartlist_free(ports);
@ -296,6 +297,8 @@ parse_ports_relay(or_options_t *options,
retval = 0; retval = 0;
err: err:
if (*have_low_ports_out < 0)
*have_low_ports_out = (n_low_ports > 0);
if (ports) { if (ports) {
SMARTLIST_FOREACH(ports, port_cfg_t *, p, port_cfg_free(p)); SMARTLIST_FOREACH(ports, port_cfg_t *, p, port_cfg_free(p));
smartlist_free(ports); smartlist_free(ports);
@ -314,6 +317,9 @@ update_port_set_relay(or_options_t *options,
if (BUG(!ports)) if (BUG(!ports))
return; return;
if (options->ClientOnly)
return;
/* Update the relay *Port_set options. The !! here is to force a boolean /* Update the relay *Port_set options. The !! here is to force a boolean
* out of an integer. */ * out of an integer. */
options->ORPort_set = options->ORPort_set =
@ -343,12 +349,14 @@ options_validate_relay_os(const or_options_t *old_options,
if (BUG(!msg)) if (BUG(!msg))
return -1; return -1;
if (!server_mode(options))
return 0;
const char *uname = get_uname(); const char *uname = get_uname();
if (server_mode(options) && if (!strcmpstart(uname, "Windows 95") ||
(!strcmpstart(uname, "Windows 95") ||
!strcmpstart(uname, "Windows 98") || !strcmpstart(uname, "Windows 98") ||
!strcmpstart(uname, "Windows Me"))) { !strcmpstart(uname, "Windows Me")) {
log_warn(LD_CONFIG, "Tor is running as a server, but you are " log_warn(LD_CONFIG, "Tor is running as a server, but you are "
"running %s; this probably won't work. See " "running %s; this probably won't work. See "
"https://www.torproject.org/docs/faq.html#BestOSForRelay " "https://www.torproject.org/docs/faq.html#BestOSForRelay "
@ -572,19 +580,22 @@ options_validate_relay_padding(const or_options_t *old_options,
if (BUG(!msg)) if (BUG(!msg))
return -1; return -1;
if (server_mode(options) && options->ConnectionPadding != -1) { if (!server_mode(options))
return 0;
if (options->ConnectionPadding != -1) {
REJECT("Relays must use 'auto' for the ConnectionPadding setting."); REJECT("Relays must use 'auto' for the ConnectionPadding setting.");
} }
if (server_mode(options) && options->ReducedConnectionPadding != 0) { if (options->ReducedConnectionPadding != 0) {
REJECT("Relays cannot set ReducedConnectionPadding. "); REJECT("Relays cannot set ReducedConnectionPadding. ");
} }
if (server_mode(options) && options->CircuitPadding == 0) { if (options->CircuitPadding == 0) {
REJECT("Relays cannot set CircuitPadding to 0. "); REJECT("Relays cannot set CircuitPadding to 0. ");
} }
if (server_mode(options) && options->ReducedCircuitPadding == 1) { if (options->ReducedCircuitPadding == 1) {
REJECT("Relays cannot set ReducedCircuitPadding. "); REJECT("Relays cannot set ReducedCircuitPadding. ");
} }
@ -1408,6 +1419,9 @@ options_act_relay_dir(const or_options_t *old_options)
const or_options_t *options = get_options(); const or_options_t *options = get_options();
if (!public_server_mode(options))
return 0;
/* Load the webpage we're going to serve every time someone asks for '/' on /* Load the webpage we're going to serve every time someone asks for '/' on
our DirPort. */ our DirPort. */
tor_free(global_dirfrontpagecontents); tor_free(global_dirfrontpagecontents);