[or-cvs] Make code to handle "private" alias work when assume_action...

Nick Mathewson nickm at seul.org
Thu Dec 8 23:58:25 UTC 2005


Update of /home/or/cvsroot/tor/src/or
In directory moria:/tmp/cvs-serv8474/src/or

Modified Files:
	config.c 
Log Message:
Make code to handle "private" alias work when assume_action is set.

Index: config.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/config.c,v
retrieving revision 1.453
retrieving revision 1.454
diff -u -d -r1.453 -r1.454
--- config.c	8 Dec 2005 19:58:14 -0000	1.453
+++ config.c	8 Dec 2005 23:58:23 -0000	1.454
@@ -2774,7 +2774,7 @@
 }
 
 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 @@
   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 @@
     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 @@
   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;
     }



More information about the tor-commits mailing list