[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] Rename parse_address to parse_extended_hostname (since we h...



Update of /home/or/cvsroot/tor/src/or
In directory moria.mit.edu:/tmp/cvs-serv26310/src/or

Modified Files:
	connection_edge.c or.h test.c 
Log Message:
Rename parse_address to parse_extended_hostname (since we have other kinds of addresses); make its output an enum; support HEXDIGEST.exit hostnames.

Index: connection_edge.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/connection_edge.c,v
retrieving revision 1.246
retrieving revision 1.247
diff -u -d -r1.246 -r1.247
--- connection_edge.c	29 Nov 2004 22:25:30 -0000	1.246
+++ connection_edge.c	30 Nov 2004 03:44:08 -0000	1.247
@@ -353,7 +353,7 @@
 static int connection_ap_handshake_process_socks(connection_t *conn) {
   socks_request_t *socks;
   int sockshere;
-  int addresstype;
+  hostname_type_t addresstype;
 
   tor_assert(conn);
   tor_assert(conn->type == CONN_TYPE_AP);
@@ -402,20 +402,30 @@
   /* Parse the address provided by SOCKS.  Modify it in-place if it
    * specifies a hidden-service (.onion) or particular exit node (.exit).
    */
-  addresstype = parse_address(socks->address);
+  addresstype = parse_extended_hostname(socks->address);
 
-  if (addresstype == 1) {
+  if (addresstype == EXIT_HOSTNAME) {
     /* .exit -- modify conn to specify the exit node. */
     char *s = strrchr(socks->address,'.');
     if (!s || s[1] == '\0') {
       log_fn(LOG_WARN,"Malformed address '%s.exit'. Refusing.", socks->address);
       return -1;
     }
-    conn->chosen_exit_name = tor_strdup(s+1);
+    if (strlen(s+1) == HEX_DIGEST_LEN) {
+      conn->chosen_exit_name = tor_malloc(HEX_DIGEST_LEN+2);
+      *(conn->chosen_exit_name) = '$';
+      strlcpy(conn->chosen_exit_name+1, HEX_DIGEST_LEN+1, s+1);
+    } else {
+      conn->chosen_exit_name = tor_strdup(s+1);
+    }
     *s = 0;
+    if (!is_legal_nickname_or_hexdigest(conn->chosen_exit_name)) {
+      log_fn(LOG_WARN, "%s is not a legal exit node nickname; rejecting.");
+      return -1;
+    }
   }
 
-  if (addresstype != 2) {
+  if (addresstype != ONION_HOSTNAME) {
     /* not a hidden-service request (i.e. normal or .exit) */
     if (socks->command == SOCKS_COMMAND_CONNECT && socks->port == 0) {
       log_fn(LOG_WARN,"Application asked to connect to port 0. Refusing.");
@@ -1245,15 +1255,16 @@
 }
 
 /** If address is of the form "y.onion" with a well-formed handle y:
- *     Put a '\0' after y, lower-case it, and return 2.
+ *     Put a '\0' after y, lower-case it, and return ONION_HOSTNAME.
  *
  * If address is of the form "y.exit":
- *     Put a '\0' after y and return 1.
+ *     Put a '\0' after y and return EXIT_HOSTNAME.
  *
  * Otherwise:
- *     Return 0 and change nothing.
+ *     Return NORMAL_HOSTNAME and change nothing.
  */
-int parse_address(char *address) {
+hostname_type_t
+parse_extended_hostname(char *address) {
     char *s;
     char query[REND_SERVICE_ID_LEN+1];
 
@@ -1261,10 +1272,10 @@
     if (!s) return 0; /* no dot, thus normal */
     if (!strcasecmp(s+1,"exit")) {
       *s = 0; /* null-terminate it */
-      return 1; /* .exit */
+      return EXIT_HOSTNAME; /* .exit */
     }
     if (strcasecmp(s+1,"onion"))
-      return 0; /* neither .exit nor .onion, thus normal */
+      return NORMAL_HOSTNAME; /* neither .exit nor .onion, thus normal */
 
     /* so it is .onion */
     *s = 0; /* null-terminate it */
@@ -1273,11 +1284,11 @@
     tor_strlower(query);
     if (rend_valid_service_id(query)) {
       tor_strlower(address);
-      return 2; /* success */
+      return ONION_HOSTNAME; /* success */
     }
 failed:
     /* otherwise, return to previous state and return 0 */
     *s = '.';
-    return 0;
+    return NORMAL_HOSTNAME;
 }
 

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/or.h,v
retrieving revision 1.500
retrieving revision 1.501
diff -u -d -r1.500 -r1.501
--- or.h	29 Nov 2004 23:06:51 -0000	1.500
+++ or.h	30 Nov 2004 03:44:09 -0000	1.501
@@ -1236,7 +1236,10 @@
 void client_dns_set_entry(const char *address, uint32_t val);
 void client_dns_clean(void);
 void set_exit_redirects(smartlist_t *lst);
-int parse_address(char *address);
+typedef enum hostname_type_t {
+  NORMAL_HOSTNAME, ONION_HOSTNAME, EXIT_HOSTNAME
+} hostname_type_t;
+hostname_type_t parse_extended_hostname(char *address);
 
 /********************************* connection_or.c ***************************/
 

Index: test.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/test.c,v
retrieving revision 1.155
retrieving revision 1.156
diff -u -d -r1.155 -r1.156
--- test.c	29 Nov 2004 23:04:26 -0000	1.155
+++ test.c	30 Nov 2004 03:44:10 -0000	1.156
@@ -1228,9 +1228,9 @@
   test_streq(d2->intro_points[1], "crow");
   test_streq(d2->intro_points[2], "joel");
 
-  test_eq(0, parse_address(address1));
-  test_eq(2, parse_address(address2));
-  test_eq(1, parse_address(address3));
+  test_eq(NORMAL_HOSTNAME, parse_extended_hostname(address1));
+  test_eq(ONION_HOSTNAME, parse_extended_hostname(address2));
+  test_eq(EXIT_HOSTNAME, parse_extended_hostname(address3));
 
   rend_service_descriptor_free(d1);
   rend_service_descriptor_free(d2);