]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Extract ARGS from SMETHOD line and attach them to transport.
authorGeorge Kadianakis <desnacked@riseup.net>
Mon, 1 Jul 2013 13:45:21 +0000 (16:45 +0300)
committerNick Mathewson <nickm@torproject.org>
Thu, 18 Jul 2013 12:43:52 +0000 (08:43 -0400)
src/or/transports.c
src/or/transports.h

index cfec70340c36a3f9f11fd04dcfeda0932a41a4a1..d1c34b5854ae5ae6544218dbf58da451025c2f9d 100644 (file)
@@ -137,7 +137,8 @@ static smartlist_t *transport_list = NULL;
     SOCKS version <b>socks_ver</b>. */
 static transport_t *
 transport_new(const tor_addr_t *addr, uint16_t port,
-              const char *name, int socks_ver)
+              const char *name, int socks_ver,
+              const char *extra_info_args)
 {
   transport_t *t = tor_malloc_zero(sizeof(transport_t));
 
@@ -145,6 +146,8 @@ transport_new(const tor_addr_t *addr, uint16_t port,
   t->port = port;
   t->name = tor_strdup(name);
   t->socks_version = socks_ver;
+  if (extra_info_args)
+    t->extra_info_args = tor_strdup(extra_info_args);
 
   return t;
 }
@@ -157,6 +160,7 @@ transport_free(transport_t *transport)
     return;
 
   tor_free(transport->name);
+  tor_free(transport->extra_info_args);
   tor_free(transport);
 }
 
@@ -324,7 +328,7 @@ int
 transport_add_from_config(const tor_addr_t *addr, uint16_t port,
                           const char *name, int socks_ver)
 {
-  transport_t *t = transport_new(addr, port, name, socks_ver);
+  transport_t *t = transport_new(addr, port, name, socks_ver, NULL);
 
   int r = transport_add(t);
 
@@ -941,7 +945,7 @@ parse_smethod_line(const char *line, managed_proxy_t *mp)
   smartlist_t *items = NULL;
 
   char *method_name=NULL;
-
+  char *args_string=NULL;
   char *addrport=NULL;
   tor_addr_t tor_addr;
   char *address=NULL;
@@ -958,6 +962,9 @@ parse_smethod_line(const char *line, managed_proxy_t *mp)
     goto err;
   }
 
+  /* Example of legit SMETHOD line:
+     SMETHOD obfs2 0.0.0.0:25612 ARGS:secret=supersekrit,key=superkey */
+
   tor_assert(!strcmp(smartlist_get(items,0),PROTO_SMETHOD));
 
   method_name = smartlist_get(items,1);
@@ -985,7 +992,19 @@ parse_smethod_line(const char *line, managed_proxy_t *mp)
     goto err;
   }
 
-  transport = transport_new(&tor_addr, port, method_name, PROXY_NONE);
+  if (smartlist_len(items) > 3) {
+    /* Seems like there are also some [options] in the SMETHOD line.
+       Let's see if we can parse them. */
+    char *options_string = smartlist_get(items, 3);
+    log_debug(LD_CONFIG, "Got options_string: %s", options_string);
+    if (!strcmpstart(options_string, "ARGS:")) {
+      args_string = options_string+strlen("ARGS:");
+      log_debug(LD_CONFIG, "Got ARGS: %s", args_string);
+    }
+  }
+
+  transport = transport_new(&tor_addr, port, method_name,
+                            PROXY_NONE, args_string);
   if (!transport)
     goto err;
 
@@ -1077,7 +1096,7 @@ parse_cmethod_line(const char *line, managed_proxy_t *mp)
     goto err;
   }
 
-  transport = transport_new(&tor_addr, port, method_name, socks_ver);
+  transport = transport_new(&tor_addr, port, method_name, socks_ver, NULL);
   if (!transport)
     goto err;
 
index cc3e018d6d8b8bea23ec66baf1413f1da948da95..525d48ab2226c13bf7087fd1829457bca356bed9 100644 (file)
@@ -25,6 +25,9 @@ typedef struct transport_t {
   /** Boolean: We are re-parsing our transport list, and we are going to remove
    * this one if we don't find it in the list of configured transports. */
   unsigned marked_for_removal : 1;
+  /** Arguments for this transport that must be written to the
+      extra-info descriptor. */
+  char *extra_info_args;
 } transport_t;
 
 void mark_transport_list(void);