mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-10 21:23:58 +01:00
Raise the part of torrc mapaddress handling that knows wildcards
This patch extracts the inner part of config_register_addressmaps -- the part that knows about detecting wildcard addresses addresses -- and makes it into a new function. The new function is deliberately not moved or reindented, so that the diff is smaller. I need this to fix bug 6244.
This commit is contained in:
parent
91b52a259a
commit
959f850056
@ -4864,12 +4864,11 @@ config_register_addressmaps(const or_options_t *options)
|
|||||||
{
|
{
|
||||||
smartlist_t *elts;
|
smartlist_t *elts;
|
||||||
config_line_t *opt;
|
config_line_t *opt;
|
||||||
char *from, *to;
|
const char *from, *to, *msg;
|
||||||
|
|
||||||
addressmap_clear_configured();
|
addressmap_clear_configured();
|
||||||
elts = smartlist_new();
|
elts = smartlist_new();
|
||||||
for (opt = options->AddressMap; opt; opt = opt->next) {
|
for (opt = options->AddressMap; opt; opt = opt->next) {
|
||||||
int from_wildcard = 0, to_wildcard = 0;
|
|
||||||
smartlist_split_string(elts, opt->value, NULL,
|
smartlist_split_string(elts, opt->value, NULL,
|
||||||
SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 2);
|
SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 2);
|
||||||
if (smartlist_len(elts) < 2) {
|
if (smartlist_len(elts) < 2) {
|
||||||
@ -4887,11 +4886,39 @@ config_register_addressmaps(const or_options_t *options)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strcmp(to, "*") || !strcmp(from, "*")) {
|
if (addressmap_register_auto(from, to, 0, ADDRMAPSRC_TORRC, &msg) < 0) {
|
||||||
log_warn(LD_CONFIG,"MapAddress '%s' is unsupported - can't remap from "
|
log_warn(LD_CONFIG,"MapAddress '%s' failed: %s. Ignoring.", opt->value,
|
||||||
"or to *. Ignoring.",opt->value);
|
msg);
|
||||||
goto cleanup;
|
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' */
|
/* Detect asterisks in expressions of type: '*.example.com' */
|
||||||
if (!strncmp(from,"*.",2)) {
|
if (!strncmp(from,"*.",2)) {
|
||||||
from += 2;
|
from += 2;
|
||||||
@ -4903,30 +4930,20 @@ config_register_addressmaps(const or_options_t *options)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (to_wildcard && !from_wildcard) {
|
if (to_wildcard && !from_wildcard) {
|
||||||
log_warn(LD_CONFIG,
|
*msg = "can only use wildcard (i.e. '*.') if 'from' address "
|
||||||
"Skipping invalid argument '%s' to MapAddress: "
|
"uses wildcard also";
|
||||||
"can only use wildcard (i.e. '*.') if 'from' address "
|
return -1;
|
||||||
"uses wildcard also", opt->value);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (address_is_invalid_destination(to, 1)) {
|
if (address_is_invalid_destination(to, 1)) {
|
||||||
log_warn(LD_CONFIG,
|
*msg = "destination is invalid";
|
||||||
"Skipping invalid argument '%s' to MapAddress", opt->value);
|
return -1;
|
||||||
goto cleanup;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
addressmap_register(from, tor_strdup(to), 0, ADDRMAPSRC_TORRC,
|
addressmap_register(from, tor_strdup(to), expires, addrmap_source,
|
||||||
from_wildcard, to_wildcard);
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -96,6 +96,12 @@ or_options_t *options_new(void);
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
void config_register_addressmaps(const or_options_t *options);
|
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
|
#endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user