[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] r8452: Debug client-side reverse dns code. (in tor/trunk: . contrib src/or)
Author: nickm
Date: 2006-09-21 20:44:07 -0400 (Thu, 21 Sep 2006)
New Revision: 8452
Modified:
tor/trunk/
tor/trunk/contrib/tor-resolve.py
tor/trunk/src/or/circuituse.c
tor/trunk/src/or/connection_edge.c
tor/trunk/src/or/control.c
tor/trunk/src/or/dns.c
tor/trunk/src/or/relay.c
Log:
r8895@Kushana: nickm | 2006-09-21 20:05:11 -0400
Debug client-side reverse dns code.
Property changes on: tor/trunk
___________________________________________________________________
svk:merge ticket from /tor/branches/eventdns [r8895] on c95137ef-5f19-0410-b913-86e773d04f59
Modified: tor/trunk/contrib/tor-resolve.py
===================================================================
--- tor/trunk/contrib/tor-resolve.py 2006-09-22 00:43:55 UTC (rev 8451)
+++ tor/trunk/contrib/tor-resolve.py 2006-09-22 00:44:07 UTC (rev 8452)
@@ -36,7 +36,9 @@
version = 5
rsv = 0
port = 0
- reqheader = struct.pack("!BBBBB",version, command, rsv, atype, len(hostname))
+ reqheader = struct.pack("!BBBB",version, command, rsv, atype)
+ if atype == 0x03:
+ reqheader += struct.pack("!B", len(hostname))
portstr = struct.pack("!H",port)
return "%s%s%s"%(reqheader,hostname,portstr)
@@ -62,8 +64,11 @@
# not really the right way to format IPv6
return "IPv6: %s"%(":".join([hex(ord(c)) for c in addr]))
else:
- nul = r.index('\0',4)
- return r[4:nul]
+ hlen, = struct.unpack("!B", r[4])
+ expected_len = 5 + hlen + 2
+ if len(r) < expected_len:
+ return None
+ return r[5:-2]
def socks5ResolvePTRRequest(hostname):
return socks5ResolveRequest(socket.inet_aton(hostname),
@@ -105,7 +110,6 @@
if socksver == 5:
s.send(socks5Hello())
socks5ParseHello(s.recv(2))
- print len(fmt(hostname)), len(hostname)
s.send(fmt(hostname))
answer = s.recv(6)
result = parse(answer)
@@ -127,7 +131,7 @@
sys.exit(0)
socksver = 4
reverse = 0
- while sys.argv[1] == '-':
+ while sys.argv[1][0] == '-':
if sys.argv[1] in ("-4", "-5"):
socksver = int(sys.argv[1][1])
del sys.argv[1]
@@ -138,7 +142,7 @@
break
if len(sys.argv) >= 4:
- print "Syntax: resolve.py [-4|-5] hostname [sockshost:socksport]"
+ print "Syntax: resolve.py [-x] [-4|-5] hostname [sockshost:socksport]"
sys.exit(0)
if len(sys.argv) == 3:
sh,sp = parseHostAndPort(sys.argv[2])
Modified: tor/trunk/src/or/circuituse.c
===================================================================
--- tor/trunk/src/or/circuituse.c 2006-09-22 00:43:55 UTC (rev 8451)
+++ tor/trunk/src/or/circuituse.c 2006-09-22 00:44:07 UTC (rev 8452)
@@ -947,7 +947,8 @@
tor_assert(conn);
tor_assert(circp);
tor_assert(conn->_base.state == AP_CONN_STATE_CIRCUIT_WAIT);
- is_resolve = conn->socks_request->command == SOCKS_COMMAND_RESOLVE;
+ is_resolve = (conn->socks_request->command == SOCKS_COMMAND_RESOLVE ||
+ conn->socks_request->command == SOCKS_COMMAND_RESOLVE_PTR);
need_uptime = smartlist_string_num_isin(get_options()->LongLivedPorts,
conn->socks_request->port);
Modified: tor/trunk/src/or/connection_edge.c
===================================================================
--- tor/trunk/src/or/connection_edge.c 2006-09-22 00:43:55 UTC (rev 8451)
+++ tor/trunk/src/or/connection_edge.c 2006-09-22 00:44:07 UTC (rev 8452)
@@ -1120,7 +1120,7 @@
return -1;
}
- if (socks->command == SOCKS_COMMAND_RESOLVE) { // resolve_ptr XXXX NM
+ if (socks->command == SOCKS_COMMAND_RESOLVE) {
uint32_t answer;
struct in_addr in;
/* Reply to resolves immediately if we can. */
@@ -1141,7 +1141,7 @@
return 0;
}
rep_hist_note_used_resolve(time(NULL)); /* help predict this next time */
- } else { /* socks->command == SOCKS_COMMAND_CONNECT */
+ } else if (socks->command == SOCKS_COMMAND_CONNECT) {
if (socks->port == 0) {
log_notice(LD_APP,"Application asked to connect to port 0. Refusing.");
connection_mark_unattached_ap(conn, END_STREAM_REASON_TORPROTOCOL);
@@ -1166,6 +1166,12 @@
/* help predict this next time */
rep_hist_note_used_port(socks->port, time(NULL));
+ } else if (socks->command == SOCKS_COMMAND_RESOLVE_PTR) {
+ // XXXX NM Do anything here?
+
+ rep_hist_note_used_resolve(time(NULL)); /* help predict this next time */
+ } else {
+ tor_fragile_assert();
}
conn->_base.state = AP_CONN_STATE_CIRCUIT_WAIT;
if ((circ &&
@@ -1701,10 +1707,10 @@
buf[1] = SOCKS5_SUCCEEDED;
buf[2] = 0; /* reserved */
buf[3] = 0x03; /* Domainname address type */
- memcpy(buf+4, answer, answer_len); /* address */
- buf[4+answer_len] = '\0';
- set_uint16(buf+4+answer_len+1, 0); /* port == 0. */
- replylen = 4+answer_len+1+2;
+ buf[4] = (char)answer_len;
+ memcpy(buf+5, answer, answer_len); /* address */
+ set_uint16(buf+5+answer_len, 0); /* port == 0. */
+ replylen = 5+answer_len+2;
} else {
buf[1] = SOCKS5_HOST_UNREACHABLE;
memset(buf+2, 0, 8);
Modified: tor/trunk/src/or/control.c
===================================================================
--- tor/trunk/src/or/control.c 2006-09-22 00:43:55 UTC (rev 8451)
+++ tor/trunk/src/or/control.c 2006-09-22 00:44:07 UTC (rev 8452)
@@ -1435,7 +1435,8 @@
case AP_CONN_STATE_CONTROLLER_WAIT:
case AP_CONN_STATE_CIRCUIT_WAIT:
if (conn->socks_request &&
- conn->socks_request->command == SOCKS_COMMAND_RESOLVE)
+ (conn->socks_request->command == SOCKS_COMMAND_RESOLVE ||
+ conn->socks_request->command == SOCKS_COMMAND_RESOLVE_PTR))
state = "NEWRESOLVE";
else
state = "NEW";
Modified: tor/trunk/src/or/dns.c
===================================================================
Modified: tor/trunk/src/or/relay.c
===================================================================
--- tor/trunk/src/or/relay.c 2006-09-22 00:43:55 UTC (rev 8451)
+++ tor/trunk/src/or/relay.c 2006-09-22 00:44:07 UTC (rev 8452)
@@ -865,7 +865,8 @@
"Dropping.");
return 0;
}
- tor_assert(conn->socks_request->command == SOCKS_COMMAND_RESOLVE);
+ tor_assert(conn->socks_request->command == SOCKS_COMMAND_RESOLVE ||
+ conn->socks_request->command == SOCKS_COMMAND_RESOLVE_PTR);
answer_len = cell->payload[RELAY_HEADER_SIZE+1];
if (rh->length < 2 || answer_len+2>rh->length) {
log_warn(LD_PROTOCOL, "Dropping malformed 'resolved' cell");