summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2017-10-23 10:52:42 -0400
committerNick Mathewson <nickm@torproject.org>2017-10-24 19:26:24 -0400
commit613b18f0afd865b0fc5daf8d17da241396100dcd (patch)
treec45626e051ec669c6212eb976b616cb07d608681
parent3581f93d273dfd9fbc56de907b7e3b77575614e1 (diff)
downloadtor-613b18f0afd865b0fc5daf8d17da241396100dcd.tar.gz
tor-613b18f0afd865b0fc5daf8d17da241396100dcd.zip
Always set bridge-distribution-request on bridges' descriptors.
Also, warn the user if the BridgeDistribution option is unrecognized, and reject the value if it is invalid.
-rw-r--r--src/or/config.c43
-rw-r--r--src/or/router.c10
2 files changed, 47 insertions, 6 deletions
diff --git a/src/or/config.c b/src/or/config.c
index 1bdfdf4846..7f45bb2cba 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -654,7 +654,7 @@ static int parse_ports(or_options_t *options, int validate_only,
static int check_server_ports(const smartlist_t *ports,
const or_options_t *options,
int *num_low_ports_out);
-
+static int check_bridge_distribution_setting(const char *bd);
static int validate_data_directory(or_options_t *options);
static int write_configuration_file(const char *fname,
const or_options_t *options);
@@ -3347,10 +3347,16 @@ options_validate(or_options_t *old_options, or_options_t *options,
options->DirPort_set = 0;
}
- if (options->BridgeDistribution && !options->BridgeRelay) {
- REJECT("You have set BridgeDistribution, yet you didn't set BridgeRelay!");
+ if (options->BridgeDistribution) {
+ if (!options->BridgeRelay) {
+ REJECT("You set BridgeDistribution, but you didn't set BridgeRelay!");
+ }
+ if (check_bridge_distribution_setting(options->BridgeDistribution) < 0) {
+ REJECT("Invalid BridgeDistribution value.");
+ }
}
+
if (options->MinUptimeHidServDirectoryV2 < 0) {
log_warn(LD_CONFIG, "MinUptimeHidServDirectoryV2 option must be at "
"least 0 seconds. Changing to 0.");
@@ -6344,6 +6350,37 @@ warn_client_dns_cache(const char *option, int disabling)
"to your destination.");
}
+/** Warn if <b>bd</b> is an unrecognized bridge distribution setting;
+ * return -1 if it is invalid. */
+static int
+check_bridge_distribution_setting(const char *bd)
+{
+ if (bd == NULL)
+ return 0;
+
+ const char *RECOGNIZED[] = {
+ "none", "any", "https", "email", "moat", "hyphae"
+ };
+ unsigned i;
+ for (i = 0; i < ARRAY_LENGTH(RECOGNIZED); ++i) {
+ if (!strcmp(bd, RECOGNIZED[i]))
+ return 0;
+ }
+
+ const char *cp = bd;
+ // Method = (KeywordChar | "_") +
+ while (TOR_ISALNUM(*cp) || *cp == '-' || *cp == '_')
+ ++cp;
+
+ if (*cp == 0) {
+ log_warn(LD_CONFIG, "Unrecognized BridgeDistribution value %s. I'll "
+ "assume you know what you are doing...", escaped(bd));
+ return 0; // we reached the end of the string; all is well
+ } else {
+ return -1; // we found a bad character in the string.
+ }
+}
+
/**
* Parse port configuration for a single port type.
*
diff --git a/src/or/router.c b/src/or/router.c
index 780d0444f3..553264efa8 100644
--- a/src/or/router.c
+++ b/src/or/router.c
@@ -2867,9 +2867,13 @@ router_dump_router_to_string(routerinfo_t *router,
smartlist_add_asprintf(chunks, "contact %s\n", ci);
}
- if (options->BridgeRelay && options->BridgeDistribution &&
- strlen(options->BridgeDistribution)) {
- const char *bd = options->BridgeDistribution;
+ if (options->BridgeRelay) {
+ const char *bd;
+ if (options->BridgeDistribution && strlen(options->BridgeDistribution)) {
+ bd = options->BridgeDistribution;
+ } else {
+ bd = "any";
+ }
if (strchr(bd, '\n') || strchr(bd, '\r'))
bd = escaped(bd);
smartlist_add_asprintf(chunks, "bridge-distribution-request %s\n", bd);