aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2005-12-08 23:58:23 +0000
committerNick Mathewson <nickm@torproject.org>2005-12-08 23:58:23 +0000
commitd57029ffe8ebd6e4aa830c58b568c4fda0bad56c (patch)
tree35218e84dde86a12254d637c024ae01640459c99
parent029d2befc15a72c83c131f5a021e1f4cc823f2a6 (diff)
downloadtor-d57029ffe8ebd6e4aa830c58b568c4fda0bad56c.tar
tor-d57029ffe8ebd6e4aa830c58b568c4fda0bad56c.tar.gz
Make code to handle "private" alias work when assume_action is set.
svn:r5542
-rw-r--r--src/or/config.c24
1 files changed, 15 insertions, 9 deletions
diff --git a/src/or/config.c b/src/or/config.c
index c664026b9..31a279c58 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -2774,7 +2774,7 @@ options_append_default_exit_policy(addr_policy_t **policy)
}
static int
-config_expand_exit_policy_aliases(smartlist_t *entries)
+config_expand_exit_policy_aliases(smartlist_t *entries, int assume_action)
{
static const char *prefixes[] = {
"0.0.0.0/8", "169.254.0.0/16",
@@ -2786,15 +2786,22 @@ config_expand_exit_policy_aliases(smartlist_t *entries)
for (i = 0; i < smartlist_len(entries); ++i) {
char *v = smartlist_get(entries, i);
const char *cp, *ports;
- int accept;
+ const char *action;
int prefix_idx;
- accept = !strcasecmpstart(v, "accept");
- if (!accept && strcasecmpstart(v, "reject")) {
+ if (!strcasecmpstart(v, "accept")) {
+ action = "accept ";
+ cp = v+strlen("accept");
+ } else if (!strcasecmpstart(v, "reject")) {
+ action = "reject ";
+ cp = v+strlen("reject");
+ } else if (assume_action >= 0) {
+ action = "";
+ cp = v;
+ } else {
warn(LD_CONFIG,"Policy '%s' didn't start with accept or reject.", v);
tor_free(pre);
return -1;
}
- cp = v+strlen("accept"); /* Yes, they're the same length. */
cp = eat_whitespace(cp);
if (strcmpstart(cp, "private"))
continue; /* No need to expand. */
@@ -2809,9 +2816,8 @@ config_expand_exit_policy_aliases(smartlist_t *entries)
for (prefix_idx = 0; prefixes[prefix_idx]; ++prefix_idx) {
size_t replacement_len = 16+strlen(prefixes[prefix_idx])+strlen(ports);
char *replacement = tor_malloc(replacement_len);
- tor_snprintf(replacement, replacement_len, "%s %s%s",
- accept?"accept":"reject", prefixes[prefix_idx],
- ports);
+ tor_snprintf(replacement, replacement_len, "%s%s%s",
+ action, prefixes[prefix_idx], ports);
smartlist_insert(entries, i++, replacement);
}
tor_free(v);
@@ -2851,7 +2857,7 @@ config_parse_addr_policy(config_line_t *cfg,
entries = smartlist_create();
for (; cfg; cfg = cfg->next) {
smartlist_split_string(entries, cfg->value, ",", SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
- if (config_expand_exit_policy_aliases(entries)<0) {
+ if (config_expand_exit_policy_aliases(entries,assume_action)<0) {
r = -1;
continue;
}