diff options
author | Nick Mathewson <nickm@torproject.org> | 2006-11-14 00:06:45 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2006-11-14 00:06:45 +0000 |
commit | 0f6402f17b9d4017aec608b10cb031512c543bc5 (patch) | |
tree | 1efa5847002b0156d9aaed773be1f2f0b802de1a /src | |
parent | 1913cb915ee3f91f18dfcefeb8202380ed4cfcbc (diff) | |
download | tor-0f6402f17b9d4017aec608b10cb031512c543bc5.tar.gz tor-0f6402f17b9d4017aec608b10cb031512c543bc5.zip |
r9309@totoro: nickm | 2006-11-13 19:05:41 -0500
Whitespace fixes, and clean up code from last natd patch.
svn:r8947
Diffstat (limited to 'src')
-rw-r--r-- | src/or/config.c | 7 | ||||
-rw-r--r-- | src/or/connection_edge.c | 30 | ||||
-rw-r--r-- | src/or/main.c | 3 | ||||
-rw-r--r-- | src/or/routerparse.c | 3 |
4 files changed, 27 insertions, 16 deletions
diff --git a/src/or/config.c b/src/or/config.c index 6dfb40dafc..36e829bc71 100644 --- a/src/or/config.c +++ b/src/or/config.c @@ -2100,18 +2100,19 @@ options_validate(or_options_t *old_options, or_options_t *options, int is_socks = i==0; int is_trans = i==1; config_line_t *line, *opt, *old; - const char *tp = is_socks ? "SOCKS proxy" : - is_trans ? "transparent proxy" - : "natd proxy"; + const char *tp; if (is_socks) { opt = options->SocksListenAddress; old = old_options ? old_options->SocksListenAddress : NULL; + tp = "SOCKS proxy"; } else if (is_trans) { opt = options->TransListenAddress; old = old_options ? old_options->TransListenAddress : NULL; + tp = "transparent proxy"; } else { opt = options->NatdListenAddress; old = old_options ? old_options->NatdListenAddress : NULL; + tp = "natd proxy"; } for (line = opt; line; line = line->next) { diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c index bb86b1cf1c..55dd17197d 100644 --- a/src/or/connection_edge.c +++ b/src/or/connection_edge.c @@ -1479,7 +1479,8 @@ connection_ap_process_transparent(edge_connection_t *conn) if (connection_ap_get_original_destination(conn, socks) < 0) { log_warn(LD_APP,"Fetching original destination failed. Closing."); - connection_mark_unattached_ap(conn, END_STREAM_REASON_CANT_FETCH_ORIG_DEST); + connection_mark_unattached_ap(conn, + END_STREAM_REASON_CANT_FETCH_ORIG_DEST); return -1; } /* we have the original destination */ @@ -1509,7 +1510,7 @@ connection_ap_process_natd(edge_connection_t *conn) { char tmp_buf[36], *tbuf, *daddr; size_t tlen = 30; - int err; + int err, port_ok; socks_request_t *socks; or_options_t *options = get_options(); @@ -1532,27 +1533,34 @@ connection_ap_process_natd(edge_connection_t *conn) return -1; } - if (strncmp(tmp_buf, "[DEST ", 6)) { - log_warn(LD_APP,"Natd handshake failed. Closing. tmp_buf = '%s'", tmp_buf); + if (strcmpstart(tmp_buf, "[DEST ")) { + log_warn(LD_APP,"Natd handshake was ill-formed; closing. The client " + "said: '%s'", + escaped(tmp_buf)); connection_mark_unattached_ap(conn, END_STREAM_REASON_INVALID_NATD_DEST); return -1; } - tbuf = &tmp_buf[0] + 6; - daddr = tbuf; - while (tbuf[0] != '\0' && tbuf[0] != ' ') + daddr = tbuf = &tmp_buf[0] + 6; /* after end of "[DEST " */ + while (*tbuf != '\0' && *tbuf != ' ') tbuf++; - tbuf[0] = '\0'; + *tbuf = '\0'; tbuf++; /* pretend that a socks handshake completed so we don't try to * send a socks reply down a natd conn */ + strlcpy(socks->address, daddr, sizeof(socks->address)); + socks->port = (uint16_t) tor_parse_long(tbuf, 10, 1, 65535, &port_ok, NULL); + if (!port_ok) { + log_warn(LD_APP,"Natd handshake failed; port '%s' is ill-formed or out " + "of range.", escaped(tbuf)); + connection_mark_unattached_ap(conn, END_STREAM_REASON_INVALID_NATD_DEST); + return -1; + } + socks->command = SOCKS_COMMAND_CONNECT; socks->has_finished = 1; - strlcpy(socks->address, daddr, sizeof(socks->address)); - socks->port = atoi(tbuf); - control_event_stream_status(conn, STREAM_EVENT_NEW, 0); if (options->LeaveStreamsUnattached) { diff --git a/src/or/main.c b/src/or/main.c index c8b3ef2327..9f4084b187 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -1333,7 +1333,8 @@ extern uint64_t buf_total_used; extern uint64_t buf_total_alloc; extern uint64_t rephist_total_alloc; extern uint32_t rephist_total_num; -void dump_distinct_digests_xx(int severity); // xxxx0124 remove +// xxxx0124 remove +void dump_distinct_digests_xx(int severity); /** * Write current memory usage information to the log. diff --git a/src/or/routerparse.c b/src/or/routerparse.c index 5bf519e2a8..671788cae3 100644 --- a/src/or/routerparse.c +++ b/src/or/routerparse.c @@ -703,7 +703,8 @@ void dump_distinct_digests_xx(int severity); static digestmap_t *verified_digests_tmp = NULL; // XXXX0124 remove me. // remove me too. void -dump_distinct_digests_xx(int severity) { +dump_distinct_digests_xx(int severity) +{ if (!verified_digests_tmp) verified_digests_tmp = digestmap_new(); log(severity, LD_GENERAL, "%d *distinct* router digests verified", |