diff options
author | Nick Mathewson <nickm@torproject.org> | 2004-11-30 03:44:10 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2004-11-30 03:44:10 +0000 |
commit | c8abe1907dfaa0f2a5038e63ab57a2e641b519f7 (patch) | |
tree | 7324a18b0cf73bf46657b854287a03e6f03f3820 /src | |
parent | ebab451eedf543ab2f9545fe80f43c0fefbe7862 (diff) | |
download | tor-c8abe1907dfaa0f2a5038e63ab57a2e641b519f7.tar.gz tor-c8abe1907dfaa0f2a5038e63ab57a2e641b519f7.zip |
Rename parse_address to parse_extended_hostname (since we have other kinds of addresses); make its output an enum; support HEXDIGEST.exit hostnames.
svn:r3029
Diffstat (limited to 'src')
-rw-r--r-- | src/or/connection_edge.c | 37 | ||||
-rw-r--r-- | src/or/or.h | 5 | ||||
-rw-r--r-- | src/or/test.c | 6 |
3 files changed, 31 insertions, 17 deletions
diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c index e92b9f0968..0995afe27a 100644 --- a/src/or/connection_edge.c +++ b/src/or/connection_edge.c @@ -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; } diff --git a/src/or/or.h b/src/or/or.h index 47eec972ad..11062f10c4 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -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 ***************************/ diff --git a/src/or/test.c b/src/or/test.c index 557c80f878..55a36d925c 100644 --- a/src/or/test.c +++ b/src/or/test.c @@ -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); |