]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Rename parse_address to parse_extended_hostname (since we have other kinds of address...
authorNick Mathewson <nickm@torproject.org>
Tue, 30 Nov 2004 03:44:10 +0000 (03:44 +0000)
committerNick Mathewson <nickm@torproject.org>
Tue, 30 Nov 2004 03:44:10 +0000 (03:44 +0000)
svn:r3029

src/or/connection_edge.c
src/or/or.h
src/or/test.c

index e92b9f0968b15cc092f9f40b8e27f1f08a2a7b74..0995afe27ac19a63123deb0dfbe08a3439f15bb3 100644 (file)
@@ -353,7 +353,7 @@ void connection_ap_attach_pending(void)
 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 @@ static int connection_ap_handshake_process_socks(connection_t *conn) {
   /* 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 @@ set_exit_redirects(smartlist_t *lst)
 }
 
 /** 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 @@ int parse_address(char *address) {
     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 @@ int parse_address(char *address) {
     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 47eec972ada9d9b984b146822f3189bb379a22fe..11062f10c4cb9327a27e5a424ff41f8e270e108c 100644 (file)
@@ -1236,7 +1236,10 @@ int client_dns_incr_failures(const char *address);
 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 557c80f878350222e4f5b2556817a022fa4842f3..55a36d925c42a95a6b5e00582641e32ae0a2ea44 100644 (file)
@@ -1228,9 +1228,9 @@ test_rend_fns(void)
   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);