aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2012-08-17 12:39:31 -0400
committerNick Mathewson <nickm@torproject.org>2012-08-17 12:39:31 -0400
commiteec86939d13681b3b6560caf6c49ec1b55c2489b (patch)
tree4502387d1d472fc3d853bafce284664725ccb1a5 /src
parent1728801bbc42f45e561812d8655b7f46fc740ea8 (diff)
parente9172e51fb13cfe5d4c70a98809a45e05b528482 (diff)
downloadtor-eec86939d13681b3b6560caf6c49ec1b55c2489b.tar
tor-eec86939d13681b3b6560caf6c49ec1b55c2489b.tar.gz
Merge remote-tracking branch 'origin/maint-0.2.3'
Diffstat (limited to 'src')
-rw-r--r--src/or/config.c61
-rw-r--r--src/or/config.h6
-rw-r--r--src/or/control.c15
3 files changed, 57 insertions, 25 deletions
diff --git a/src/or/config.c b/src/or/config.c
index 87068b68f..372b8911f 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -4873,12 +4873,11 @@ config_register_addressmaps(const or_options_t *options)
{
smartlist_t *elts;
config_line_t *opt;
- char *from, *to;
+ const char *from, *to, *msg;
addressmap_clear_configured();
elts = smartlist_new();
for (opt = options->AddressMap; opt; opt = opt->next) {
- int from_wildcard = 0, to_wildcard = 0;
smartlist_split_string(elts, opt->value, NULL,
SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 2);
if (smartlist_len(elts) < 2) {
@@ -4896,11 +4895,39 @@ config_register_addressmaps(const or_options_t *options)
goto cleanup;
}
- if (!strcmp(to, "*") || !strcmp(from, "*")) {
- log_warn(LD_CONFIG,"MapAddress '%s' is unsupported - can't remap from "
- "or to *. Ignoring.",opt->value);
+ if (addressmap_register_auto(from, to, 0, ADDRMAPSRC_TORRC, &msg) < 0) {
+ log_warn(LD_CONFIG,"MapAddress '%s' failed: %s. Ignoring.", opt->value,
+ msg);
goto cleanup;
}
+
+ if (smartlist_len(elts) > 2)
+ log_warn(LD_CONFIG,"Ignoring extra arguments to MapAddress.");
+
+ cleanup:
+ SMARTLIST_FOREACH(elts, char*, cp, tor_free(cp));
+ smartlist_clear(elts);
+ }
+ smartlist_free(elts);
+}
+
+/** As addressmap_register(), but detect the wildcarded status of "from" and
+ * "to", and do not steal a reference to <b>to</b>. */
+/* XXXX024 move to connection_edge.c */
+int
+addressmap_register_auto(const char *from, const char *to,
+ time_t expires,
+ addressmap_entry_source_t addrmap_source,
+ const char **msg)
+{
+ int from_wildcard = 0, to_wildcard = 0;
+
+ *msg = "whoops, forgot the error message";
+ if (1) {
+ if (!strcmp(to, "*") || !strcmp(from, "*")) {
+ *msg = "can't remap from or to *";
+ return -1;
+ }
/* Detect asterisks in expressions of type: '*.example.com' */
if (!strncmp(from,"*.",2)) {
from += 2;
@@ -4912,30 +4939,20 @@ config_register_addressmaps(const or_options_t *options)
}
if (to_wildcard && !from_wildcard) {
- log_warn(LD_CONFIG,
- "Skipping invalid argument '%s' to MapAddress: "
- "can only use wildcard (i.e. '*.') if 'from' address "
- "uses wildcard also", opt->value);
- goto cleanup;
+ *msg = "can only use wildcard (i.e. '*.') if 'from' address "
+ "uses wildcard also";
+ return -1;
}
if (address_is_invalid_destination(to, 1)) {
- log_warn(LD_CONFIG,
- "Skipping invalid argument '%s' to MapAddress", opt->value);
- goto cleanup;
+ *msg = "destination is invalid";
+ return -1;
}
- addressmap_register(from, tor_strdup(to), 0, ADDRMAPSRC_TORRC,
+ addressmap_register(from, tor_strdup(to), expires, addrmap_source,
from_wildcard, to_wildcard);
-
- if (smartlist_len(elts) > 2)
- log_warn(LD_CONFIG,"Ignoring extra arguments to MapAddress.");
-
- cleanup:
- SMARTLIST_FOREACH(elts, char*, cp, tor_free(cp));
- smartlist_clear(elts);
}
- smartlist_free(elts);
+ return 0;
}
/**
diff --git a/src/or/config.h b/src/or/config.h
index ce7e31974..48f4e8630 100644
--- a/src/or/config.h
+++ b/src/or/config.h
@@ -96,6 +96,12 @@ or_options_t *options_new(void);
#endif
void config_register_addressmaps(const or_options_t *options);
+/* XXXX024 move to connection_edge.h */
+int addressmap_register_auto(const char *from, const char *to,
+ time_t expires,
+ addressmap_entry_source_t addrmap_source,
+ const char **msg);
+
#endif
diff --git a/src/or/control.c b/src/or/control.c
index 61a9f724e..4a0f8d70a 100644
--- a/src/or/control.c
+++ b/src/or/control.c
@@ -1380,9 +1380,18 @@ handle_control_mapaddress(control_connection_t *conn, uint32_t len,
smartlist_add_asprintf(reply, "250-%s=%s", address, to);
}
} else {
- addressmap_register(from, tor_strdup(to), 1,
- ADDRMAPSRC_CONTROLLER, 0, 0);
- smartlist_add_asprintf(reply, "250-%s", line);
+ const char *msg;
+ if (addressmap_register_auto(from, to, 1,
+ ADDRMAPSRC_CONTROLLER, &msg) < 0) {
+ smartlist_add_asprintf(reply,
+ "512-syntax error: invalid address mapping "
+ " '%s': %s", line, msg);
+ log_warn(LD_CONTROL,
+ "Skipping invalid argument '%s' in MapAddress msg: %s",
+ line, msg);
+ } else {
+ smartlist_add_asprintf(reply, "250-%s", line);
+ }
}
} else {
smartlist_add_asprintf(reply, "512-syntax error: mapping '%s' is "