[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor/release-0.3.2] Always set bridge-distribution-request on bridges' descriptors.
commit 613b18f0afd865b0fc5daf8d17da241396100dcd
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date: Mon Oct 23 10:52:42 2017 -0400
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.
---
src/or/config.c | 43 ++++++++++++++++++++++++++++++++++++++++---
src/or/router.c | 10 +++++++---
2 files changed, 47 insertions(+), 6 deletions(-)
diff --git a/src/or/config.c b/src/or/config.c
index 1bdfdf484..7f45bb2cb 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 780d0444f..553264efa 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);
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits