mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-24 12:23:32 +01:00
Migrate a few more files to domained logging
svn:r5285
This commit is contained in:
parent
edf5698474
commit
55f2ab9cc3
@ -57,6 +57,10 @@
|
||||
#define LD_CONFIG 3
|
||||
#define LD_FS 4
|
||||
#define LD_PROTOCOL 5
|
||||
#define LD_MM 6
|
||||
#define LD_HTTP 7
|
||||
#define LD_APP 8
|
||||
#define LD_CONTROL 9
|
||||
|
||||
typedef void (*log_callback)(int severity, int domain, const char *msg);
|
||||
|
||||
|
@ -12,6 +12,7 @@ const char buffers_c_id[] = "$Id$";
|
||||
* memory, file descriptors, or TLS connections.
|
||||
**/
|
||||
|
||||
#define NEW_LOG_INTERFACE
|
||||
#include "or.h"
|
||||
|
||||
#define SENTINELS
|
||||
@ -86,7 +87,7 @@ buf_normalize(buf_t *buf)
|
||||
} else {
|
||||
char *newmem, *oldmem;
|
||||
size_t sz = (buf->mem+buf->len)-buf->cur;
|
||||
log_fn(LOG_WARN, "Unexpected non-normalized buffer.");
|
||||
warn(LD_GENERAL, "Unexpected non-normalized buffer.");
|
||||
newmem = GUARDED_MEM(tor_malloc(ALLOC_LEN(buf->len)));
|
||||
SET_GUARDS(newmem, buf->len);
|
||||
memcpy(newmem, buf->cur, sz);
|
||||
@ -259,7 +260,7 @@ buf_ensure_capacity(buf_t *buf, size_t capacity)
|
||||
while (new_len < capacity)
|
||||
new_len *= 2;
|
||||
/* Resize the buffer. */
|
||||
log_fn(LOG_DEBUG,"Growing buffer from %d to %d bytes.",
|
||||
debug(LD_MM,"Growing buffer from %d to %d bytes.",
|
||||
(int)buf->len, (int)new_len);
|
||||
buf_resize(buf,new_len);
|
||||
return 0;
|
||||
@ -284,7 +285,7 @@ buf_shrink(buf_t *buf)
|
||||
if (new_len == buf->len)
|
||||
return;
|
||||
|
||||
log_fn(LOG_DEBUG,"Shrinking buffer from %d to %d bytes.",
|
||||
debug(LD_MM,"Shrinking buffer from %d to %d bytes.",
|
||||
(int)buf->len, (int)new_len);
|
||||
buf_resize(buf, new_len);
|
||||
}
|
||||
@ -404,7 +405,7 @@ read_to_buf_impl(int s, size_t at_most, buf_t *buf,
|
||||
}
|
||||
return 0; /* would block. */
|
||||
} else if (read_result == 0) {
|
||||
log_fn(LOG_DEBUG,"Encountered eof");
|
||||
debug(LD_NET,"Encountered eof");
|
||||
*reached_eof = 1;
|
||||
return 0;
|
||||
} else { /* we read some bytes */
|
||||
@ -412,7 +413,7 @@ read_to_buf_impl(int s, size_t at_most, buf_t *buf,
|
||||
buf_total_used += read_result;
|
||||
if (buf->datalen > buf->highwater)
|
||||
buf->highwater = buf->datalen;
|
||||
log_fn(LOG_DEBUG,"Read %d bytes. %d on inbuf.",read_result,
|
||||
debug(LD_NET,"Read %d bytes. %d on inbuf.",read_result,
|
||||
(int)buf->datalen);
|
||||
return read_result;
|
||||
}
|
||||
@ -478,7 +479,7 @@ read_to_buf_tls_impl(tor_tls_t *tls, size_t at_most, buf_t *buf, char *next)
|
||||
{
|
||||
int r;
|
||||
|
||||
log_fn(LOG_DEBUG,"before: %d on buf, %d pending, at_most %d.",
|
||||
debug(LD_NET,"before: %d on buf, %d pending, at_most %d.",
|
||||
(int)buf_datalen(buf), (int)tor_tls_get_pending_bytes(tls),
|
||||
(int)at_most);
|
||||
r = tor_tls_read(tls, next, at_most);
|
||||
@ -488,7 +489,7 @@ read_to_buf_tls_impl(tor_tls_t *tls, size_t at_most, buf_t *buf, char *next)
|
||||
buf_total_used += r;
|
||||
if (buf->datalen > buf->highwater)
|
||||
buf->highwater = buf->datalen;
|
||||
log_fn(LOG_DEBUG,"Read %d bytes. %d on inbuf; %d pending",r,
|
||||
debug(LD_NET,"Read %d bytes. %d on inbuf; %d pending",r,
|
||||
(int)buf->datalen,(int)tor_tls_get_pending_bytes(tls));
|
||||
return r;
|
||||
}
|
||||
@ -522,7 +523,7 @@ read_to_buf_tls(tor_tls_t *tls, size_t at_most, buf_t *buf)
|
||||
tor_assert(tls);
|
||||
assert_buf_ok(buf);
|
||||
|
||||
log_fn(LOG_DEBUG,"start: %d on buf, %d pending, at_most %d.",
|
||||
debug(LD_NET,"start: %d on buf, %d pending, at_most %d.",
|
||||
(int)buf_datalen(buf), (int)tor_tls_get_pending_bytes(tls),
|
||||
(int)at_most);
|
||||
|
||||
@ -572,7 +573,7 @@ flush_buf_impl(int s, buf_t *buf, size_t sz, size_t *buf_flushlen)
|
||||
if (!ERRNO_IS_EAGAIN(e)) { /* it's a real error */
|
||||
return -1;
|
||||
}
|
||||
log_fn(LOG_DEBUG,"write() would block, returning.");
|
||||
debug(LD_NET,"write() would block, returning.");
|
||||
return 0;
|
||||
} else {
|
||||
*buf_flushlen -= write_result;
|
||||
@ -610,7 +611,7 @@ flush_buf(int s, buf_t *buf, size_t *buf_flushlen)
|
||||
r = flush_buf_impl(s, buf, flushlen0, buf_flushlen);
|
||||
check();
|
||||
|
||||
log_fn(LOG_DEBUG,"%d: flushed %d bytes, %d ready to flush, %d remain.",
|
||||
debug(LD_NET,"%d: flushed %d bytes, %d ready to flush, %d remain.",
|
||||
s,r,(int)*buf_flushlen,(int)buf->datalen);
|
||||
if (r < 0 || (size_t)r < flushlen0)
|
||||
return r; /* Error, or can't flush any more now. */
|
||||
@ -620,7 +621,7 @@ flush_buf(int s, buf_t *buf, size_t *buf_flushlen)
|
||||
tor_assert(buf->cur == buf->mem);
|
||||
r = flush_buf_impl(s, buf, flushlen1, buf_flushlen);
|
||||
check();
|
||||
log_fn(LOG_DEBUG,"%d: flushed %d bytes, %d ready to flush, %d remain.",
|
||||
debug(LD_NET,"%d: flushed %d bytes, %d ready to flush, %d remain.",
|
||||
s,r,(int)*buf_flushlen,(int)buf->datalen);
|
||||
if (r<0)
|
||||
return r;
|
||||
@ -645,7 +646,7 @@ flush_buf_tls_impl(tor_tls_t *tls, buf_t *buf, size_t sz, size_t *buf_flushlen)
|
||||
}
|
||||
*buf_flushlen -= r;
|
||||
buf_remove_from_front(buf, r);
|
||||
log_fn(LOG_DEBUG,"flushed %d bytes, %d ready to flush, %d remain.",
|
||||
debug(LD_NET,"flushed %d bytes, %d ready to flush, %d remain.",
|
||||
r,(int)*buf_flushlen,(int)buf->datalen);
|
||||
return r;
|
||||
}
|
||||
@ -705,7 +706,7 @@ write_to_buf(const char *string, size_t string_len, buf_t *buf)
|
||||
assert_buf_ok(buf);
|
||||
|
||||
if (buf_ensure_capacity(buf, buf->datalen+string_len)) {
|
||||
log_fn(LOG_WARN, "buflen too small, can't hold %d bytes.", (int)(buf->datalen+string_len));
|
||||
warn(LD_MM, "buflen too small, can't hold %d bytes.", (int)(buf->datalen+string_len));
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -724,7 +725,7 @@ write_to_buf(const char *string, size_t string_len, buf_t *buf)
|
||||
}
|
||||
if (buf->datalen > buf->highwater)
|
||||
buf->highwater = buf->datalen;
|
||||
log_fn(LOG_DEBUG,"added %d bytes to buf (now %d total).",
|
||||
debug(LD_NET,"added %d bytes to buf (now %d total).",
|
||||
(int)string_len, (int)buf->datalen);
|
||||
check();
|
||||
return buf->datalen;
|
||||
@ -806,27 +807,27 @@ fetch_from_buf_http(buf_t *buf,
|
||||
buf_normalize(buf);
|
||||
|
||||
if (buf_nul_terminate(buf)<0) {
|
||||
log_fn(LOG_WARN,"Couldn't nul-terminate buffer");
|
||||
warn(LD_GENERAL,"Couldn't nul-terminate buffer");
|
||||
return -1;
|
||||
}
|
||||
headers = buf->cur;
|
||||
body = strstr(headers,"\r\n\r\n");
|
||||
if (!body) {
|
||||
log_fn(LOG_DEBUG,"headers not all here yet.");
|
||||
debug(LD_HTTP,"headers not all here yet.");
|
||||
return 0;
|
||||
}
|
||||
body += 4; /* Skip the the CRLFCRLF */
|
||||
headerlen = body-headers; /* includes the CRLFCRLF */
|
||||
bodylen = buf->datalen - headerlen;
|
||||
log_fn(LOG_DEBUG,"headerlen %d, bodylen %d.", (int)headerlen, (int)bodylen);
|
||||
debug(LD_HTTP,"headerlen %d, bodylen %d.", (int)headerlen, (int)bodylen);
|
||||
|
||||
if (max_headerlen <= headerlen) {
|
||||
log_fn(LOG_WARN,"headerlen %d larger than %d. Failing.", (int)headerlen,
|
||||
warn(LD_HTTP,"headerlen %d larger than %d. Failing.", (int)headerlen,
|
||||
(int)max_headerlen-1);
|
||||
return -1;
|
||||
}
|
||||
if (max_bodylen <= bodylen) {
|
||||
log_fn(LOG_WARN,"bodylen %d larger than %d. Failing.", (int)bodylen, (int)max_bodylen-1);
|
||||
warn(LD_HTTP,"bodylen %d larger than %d. Failing.", (int)bodylen, (int)max_bodylen-1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -836,21 +837,21 @@ fetch_from_buf_http(buf_t *buf,
|
||||
int i;
|
||||
i = atoi(p+strlen(CONTENT_LENGTH));
|
||||
if (i < 0) {
|
||||
log_fn(LOG_WARN, "Content-Length is less than zero; it looks like someone is trying to crash us.");
|
||||
warn(LD_PROTOCOL, "Content-Length is less than zero; it looks like someone is trying to crash us.");
|
||||
return -1;
|
||||
}
|
||||
contentlen = i;
|
||||
/* if content-length is malformed, then our body length is 0. fine. */
|
||||
log_fn(LOG_DEBUG,"Got a contentlen of %d.",(int)contentlen);
|
||||
debug(LD_HTTP,"Got a contentlen of %d.",(int)contentlen);
|
||||
if (bodylen < contentlen) {
|
||||
if (!force_complete) {
|
||||
log_fn(LOG_DEBUG,"body not all here yet.");
|
||||
debug(LD_HTTP,"body not all here yet.");
|
||||
return 0; /* not all there yet */
|
||||
}
|
||||
}
|
||||
if (bodylen > contentlen) {
|
||||
bodylen = contentlen;
|
||||
log_fn(LOG_DEBUG,"bodylen reduced to %d.",(int)bodylen);
|
||||
debug(LD_HTTP,"bodylen reduced to %d.",(int)bodylen);
|
||||
}
|
||||
}
|
||||
/* all happy. copy into the appropriate places, and return 1 */
|
||||
@ -917,7 +918,7 @@ fetch_from_buf_socks(buf_t *buf, socks_request_t *req)
|
||||
if (buf->datalen < 2u+nummethods)
|
||||
return 0;
|
||||
if (!nummethods || !memchr(buf->cur+2, 0, nummethods)) {
|
||||
log_fn(LOG_WARN,"socks5: offered methods don't include 'no auth'. Rejecting.");
|
||||
warn(LD_APP,"socks5: offered methods don't include 'no auth'. Rejecting.");
|
||||
req->replylen = 2; /* 2 bytes of response */
|
||||
req->reply[0] = 5;
|
||||
req->reply[1] = '\xFF'; /* reject all methods */
|
||||
@ -929,24 +930,24 @@ fetch_from_buf_socks(buf_t *buf, socks_request_t *req)
|
||||
req->reply[0] = 5; /* socks5 reply */
|
||||
req->reply[1] = SOCKS5_SUCCEEDED;
|
||||
req->socks_version = 5; /* remember that we've already negotiated auth */
|
||||
log_fn(LOG_DEBUG,"socks5: accepted method 0");
|
||||
debug(LD_APP,"socks5: accepted method 0");
|
||||
return 0;
|
||||
}
|
||||
/* we know the method; read in the request */
|
||||
log_fn(LOG_DEBUG,"socks5: checking request");
|
||||
debug(LD_APP,"socks5: checking request");
|
||||
if (buf->datalen < 8) /* basic info plus >=2 for addr plus 2 for port */
|
||||
return 0; /* not yet */
|
||||
req->command = (unsigned char) *(buf->cur+1);
|
||||
if (req->command != SOCKS_COMMAND_CONNECT &&
|
||||
req->command != SOCKS_COMMAND_RESOLVE) {
|
||||
/* not a connect or resolve? we don't support it. */
|
||||
log_fn(LOG_WARN,"socks5: command %d not recognized. Rejecting.",
|
||||
warn(LD_APP,"socks5: command %d not recognized. Rejecting.",
|
||||
req->command);
|
||||
return -1;
|
||||
}
|
||||
switch (*(buf->cur+3)) { /* address type */
|
||||
case 1: /* IPv4 address */
|
||||
log_fn(LOG_DEBUG,"socks5: ipv4 address type");
|
||||
debug(LD_APP,"socks5: ipv4 address type");
|
||||
if (buf->datalen < 10) /* ip/port there? */
|
||||
return 0; /* not yet */
|
||||
|
||||
@ -954,7 +955,7 @@ fetch_from_buf_socks(buf_t *buf, socks_request_t *req)
|
||||
in.s_addr = htonl(destip);
|
||||
tor_inet_ntoa(&in,tmpbuf,sizeof(tmpbuf));
|
||||
if (strlen(tmpbuf)+1 > MAX_SOCKS_ADDR_LEN) {
|
||||
log_fn(LOG_WARN,"socks5 IP takes %d bytes, which doesn't fit in %d. Rejecting.",
|
||||
warn(LD_APP,"socks5 IP takes %d bytes, which doesn't fit in %d. Rejecting.",
|
||||
(int)strlen(tmpbuf)+1,(int)MAX_SOCKS_ADDR_LEN);
|
||||
return -1;
|
||||
}
|
||||
@ -963,17 +964,17 @@ fetch_from_buf_socks(buf_t *buf, socks_request_t *req)
|
||||
buf_remove_from_front(buf, 10);
|
||||
if (!address_is_in_virtual_range(req->address) &&
|
||||
!have_warned_about_unsafe_socks) {
|
||||
log_fn(LOG_WARN,"Your application (using socks5 on port %d) is giving Tor only an IP address. Applications that do DNS resolves themselves may leak information. Consider using Socks4A (e.g. via privoxy or socat) instead. For more information, please see http://wiki.noreply.org/noreply/TheOnionRouter/TorFAQ#SOCKSAndDNS", req->port);
|
||||
warn(LD_APP,"Your application (using socks5 on port %d) is giving Tor only an IP address. Applications that do DNS resolves themselves may leak information. Consider using Socks4A (e.g. via privoxy or socat) instead. For more information, please see http://wiki.noreply.org/noreply/TheOnionRouter/TorFAQ#SOCKSAndDNS", req->port);
|
||||
// have_warned_about_unsafe_socks = 1; // (for now, warn every time)
|
||||
}
|
||||
return 1;
|
||||
case 3: /* fqdn */
|
||||
log_fn(LOG_DEBUG,"socks5: fqdn address type");
|
||||
debug(LD_APP,"socks5: fqdn address type");
|
||||
len = (unsigned char)*(buf->cur+4);
|
||||
if (buf->datalen < 7u+len) /* addr/port there? */
|
||||
return 0; /* not yet */
|
||||
if (len+1 > MAX_SOCKS_ADDR_LEN) {
|
||||
log_fn(LOG_WARN,"socks5 hostname is %d bytes, which doesn't fit in %d. Rejecting.",
|
||||
warn(LD_APP,"socks5 hostname is %d bytes, which doesn't fit in %d. Rejecting.",
|
||||
len+1,MAX_SOCKS_ADDR_LEN);
|
||||
return -1;
|
||||
}
|
||||
@ -983,7 +984,7 @@ fetch_from_buf_socks(buf_t *buf, socks_request_t *req)
|
||||
buf_remove_from_front(buf, 5+len+2);
|
||||
return 1;
|
||||
default: /* unsupported */
|
||||
log_fn(LOG_WARN,"socks5: unsupported address type %d. Rejecting.",*(buf->cur+3));
|
||||
warn(LD_APP,"socks5: unsupported address type %d. Rejecting.",*(buf->cur+3));
|
||||
return -1;
|
||||
}
|
||||
tor_assert(0);
|
||||
@ -999,7 +1000,7 @@ fetch_from_buf_socks(buf_t *buf, socks_request_t *req)
|
||||
if (req->command != SOCKS_COMMAND_CONNECT &&
|
||||
req->command != SOCKS_COMMAND_RESOLVE) {
|
||||
/* not a connect or resolve? we don't support it. */
|
||||
log_fn(LOG_WARN,"socks4: command %d not recognized. Rejecting.",
|
||||
warn(LD_APP,"socks4: command %d not recognized. Rejecting.",
|
||||
req->command);
|
||||
return -1;
|
||||
}
|
||||
@ -1007,26 +1008,26 @@ fetch_from_buf_socks(buf_t *buf, socks_request_t *req)
|
||||
req->port = ntohs(*(uint16_t*)(buf->cur+2));
|
||||
destip = ntohl(*(uint32_t*)(buf->mem+4));
|
||||
if ((!req->port && req->command!=SOCKS_COMMAND_RESOLVE) || !destip) {
|
||||
log_fn(LOG_WARN,"socks4: Port or DestIP is zero. Rejecting.");
|
||||
warn(LD_APP,"socks4: Port or DestIP is zero. Rejecting.");
|
||||
return -1;
|
||||
}
|
||||
if (destip >> 8) {
|
||||
log_fn(LOG_DEBUG,"socks4: destip not in form 0.0.0.x.");
|
||||
debug(LD_APP,"socks4: destip not in form 0.0.0.x.");
|
||||
in.s_addr = htonl(destip);
|
||||
tor_inet_ntoa(&in,tmpbuf,sizeof(tmpbuf));
|
||||
if (strlen(tmpbuf)+1 > MAX_SOCKS_ADDR_LEN) {
|
||||
log_fn(LOG_WARN,"socks4 addr (%d bytes) too long. Rejecting.",
|
||||
debug(LD_APP,"socks4 addr (%d bytes) too long. Rejecting.",
|
||||
(int)strlen(tmpbuf));
|
||||
return -1;
|
||||
}
|
||||
log_fn(LOG_DEBUG,"socks4: successfully read destip (%s)", safe_str(tmpbuf));
|
||||
debug(LD_APP,"socks4: successfully read destip (%s)", safe_str(tmpbuf));
|
||||
socks4_prot = socks4;
|
||||
}
|
||||
|
||||
next = memchr(buf->cur+SOCKS4_NETWORK_LEN, 0,
|
||||
buf->datalen-SOCKS4_NETWORK_LEN);
|
||||
if (!next) {
|
||||
log_fn(LOG_DEBUG,"socks4: Username not here yet.");
|
||||
debug(LD_APP,"socks4: Username not here yet.");
|
||||
return 0;
|
||||
}
|
||||
tor_assert(next < buf->cur+buf->datalen);
|
||||
@ -1035,27 +1036,27 @@ fetch_from_buf_socks(buf_t *buf, socks_request_t *req)
|
||||
if (socks4_prot != socks4a &&
|
||||
!address_is_in_virtual_range(tmpbuf) &&
|
||||
!have_warned_about_unsafe_socks) {
|
||||
log_fn(LOG_WARN,"Your application (using socks4 on port %d) is giving Tor only an IP address. Applications that do DNS resolves themselves may leak information. Consider using Socks4A (e.g. via privoxy or socat) instead.", req->port);
|
||||
warn(LD_APP,"Your application (using socks4 on port %d) is giving Tor only an IP address. Applications that do DNS resolves themselves may leak information. Consider using Socks4A (e.g. via privoxy or socat) instead.", req->port);
|
||||
// have_warned_about_unsafe_socks = 1; // (for now, warn every time)
|
||||
}
|
||||
if (socks4_prot == socks4a) {
|
||||
if (next+1 == buf->cur+buf->datalen) {
|
||||
log_fn(LOG_DEBUG,"socks4: No part of destaddr here yet.");
|
||||
debug(LD_APP,"socks4: No part of destaddr here yet.");
|
||||
return 0;
|
||||
}
|
||||
startaddr = next+1;
|
||||
next = memchr(startaddr, 0, buf->cur+buf->datalen-startaddr);
|
||||
if (!next) {
|
||||
log_fn(LOG_DEBUG,"socks4: Destaddr not all here yet.");
|
||||
debug(LD_APP,"socks4: Destaddr not all here yet.");
|
||||
return 0;
|
||||
}
|
||||
if (MAX_SOCKS_ADDR_LEN <= next-startaddr) {
|
||||
log_fn(LOG_WARN,"socks4: Destaddr too long. Rejecting.");
|
||||
warn(LD_APP,"socks4: Destaddr too long. Rejecting.");
|
||||
return -1;
|
||||
}
|
||||
tor_assert(next < buf->cur+buf->datalen);
|
||||
}
|
||||
log_fn(LOG_DEBUG,"socks4: Everything is here. Success.");
|
||||
debug(LD_APP,"socks4: Everything is here. Success.");
|
||||
strlcpy(req->address, startaddr ? startaddr : tmpbuf,
|
||||
sizeof(req->address));
|
||||
buf_remove_from_front(buf, next-buf->cur+1); /* next points to the final \0 on inbuf */
|
||||
@ -1089,7 +1090,7 @@ fetch_from_buf_socks(buf_t *buf, socks_request_t *req)
|
||||
req->replylen = strlen(req->reply)+1;
|
||||
/* fall through */
|
||||
default: /* version is not socks4 or socks5 */
|
||||
log_fn(LOG_WARN,"Socks version %d not recognized. (Tor is not an http proxy.)",
|
||||
warn(LD_APP,"Socks version %d not recognized. (Tor is not an http proxy.)",
|
||||
*(buf->cur));
|
||||
return -1;
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ const char control_c_id[] = "$Id$";
|
||||
* \brief Implementation for Tor's control-socket interface.
|
||||
**/
|
||||
|
||||
#define NEW_LOG_INTERFACE
|
||||
#include "or.h"
|
||||
|
||||
#define STATE_IS_OPEN(s) ((s) == CONTROL_CONN_STATE_OPEN_V0 || \
|
||||
@ -691,7 +692,7 @@ control_setconf_helper(connection_t *conn, uint32_t len, char *body,
|
||||
*outp = '\0';
|
||||
|
||||
if (config_get_lines(config, &lines) < 0) {
|
||||
log_fn(LOG_WARN,"Controller gave us config lines we can't parse.");
|
||||
warn(LD_CONTROL,"Controller gave us config lines we can't parse.");
|
||||
connection_write_str_to_buf("551 Couldn't parse configuration\r\n", conn);
|
||||
tor_free(config);
|
||||
return 0;
|
||||
@ -699,7 +700,7 @@ control_setconf_helper(connection_t *conn, uint32_t len, char *body,
|
||||
tor_free(config);
|
||||
} else {
|
||||
if (config_get_lines(body, &lines) < 0) {
|
||||
log_fn(LOG_WARN,"Controller gave us config lines we can't parse.");
|
||||
warn(LD_CONTROL,"Controller gave us config lines we can't parse.");
|
||||
send_control0_error(conn, ERR_SYNTAX, "Couldn't parse configuration");
|
||||
return 0;
|
||||
}
|
||||
@ -708,7 +709,7 @@ control_setconf_helper(connection_t *conn, uint32_t len, char *body,
|
||||
if ((r=options_trial_assign(lines, use_defaults, clear_first)) < 0) {
|
||||
int v0_err;
|
||||
const char *msg;
|
||||
log_fn(LOG_WARN,"Controller gave us config lines that didn't validate.");
|
||||
warn(LD_CONTROL,"Controller gave us config lines that didn't validate.");
|
||||
switch (r) {
|
||||
case -1:
|
||||
v0_err = ERR_UNRECOGNIZED_CONFIG_KEY;
|
||||
@ -1003,7 +1004,7 @@ handle_control_authenticate(connection_t *conn, uint32_t len, const char *body)
|
||||
char expected[S2K_SPECIFIER_LEN+DIGEST_LEN];
|
||||
char received[DIGEST_LEN];
|
||||
if (decode_hashed_password(expected, options->HashedControlPassword)<0) {
|
||||
log_fn(LOG_WARN,"Couldn't decode HashedControlPassword: invalid base16");
|
||||
warn(LD_CONTROL,"Couldn't decode HashedControlPassword: invalid base16");
|
||||
goto err;
|
||||
}
|
||||
secret_to_key(received,DIGEST_LEN,password,password_len,expected);
|
||||
@ -1028,7 +1029,7 @@ handle_control_authenticate(connection_t *conn, uint32_t len, const char *body)
|
||||
}
|
||||
return 0;
|
||||
ok:
|
||||
log_fn(LOG_INFO, "Authenticated control connection (%d)", conn->s);
|
||||
info(LD_CONTROL, "Authenticated control connection (%d)", conn->s);
|
||||
send_control_done(conn);
|
||||
if (STATE_IS_V0(conn->state))
|
||||
conn->state = CONTROL_CONN_STATE_OPEN_V0;
|
||||
@ -1144,15 +1145,15 @@ handle_control_mapaddress(connection_t *conn, uint32_t len, const char *body)
|
||||
const char *from = smartlist_get(elts,0);
|
||||
const char *to = smartlist_get(elts,1);
|
||||
if (!is_plausible_address(from)) {
|
||||
log_fn(LOG_WARN,"Skipping invalid argument '%s' in MapAddress msg",from);
|
||||
warn(LD_CONTROL,"Skipping invalid argument '%s' in MapAddress msg",from);
|
||||
} else if (!is_plausible_address(to)) {
|
||||
log_fn(LOG_WARN,"Skipping invalid argument '%s' in MapAddress msg",to);
|
||||
warn(LD_CONTROL,"Skipping invalid argument '%s' in MapAddress msg",to);
|
||||
} else if (!strcmp(from, ".") || !strcmp(from, "0.0.0.0")) {
|
||||
const char *address = addressmap_register_virtual_address(
|
||||
!strcmp(from,".") ? RESOLVED_TYPE_HOSTNAME : RESOLVED_TYPE_IPV4,
|
||||
tor_strdup(to));
|
||||
if (!address) {
|
||||
log_fn(LOG_WARN,
|
||||
warn(LD_CONTROL,
|
||||
"Unable to allocate address for '%s' in MapAddress msg",
|
||||
safe_str(line));
|
||||
} else {
|
||||
@ -1176,7 +1177,7 @@ handle_control_mapaddress(connection_t *conn, uint32_t len, const char *body)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log_fn(LOG_WARN, "Skipping MapAddress line with wrong number of items.");
|
||||
warn(LD_CONTROL, "Skipping MapAddress line with wrong number of items.");
|
||||
}
|
||||
SMARTLIST_FOREACH(elts, char *, cp, tor_free(cp));
|
||||
smartlist_clear(elts);
|
||||
@ -1326,7 +1327,7 @@ handle_getinfo_helper(const char *question, char **answer)
|
||||
case AP_CONN_STATE_OPEN:
|
||||
state = "SUCCEEDED"; break;
|
||||
default:
|
||||
log_fn(LOG_WARN, "Asked for stream in unknown state %d",
|
||||
warn(LD_GENERAL, "Asked for stream in unknown state %d",
|
||||
conns[i]->state);
|
||||
continue;
|
||||
}
|
||||
@ -1585,7 +1586,7 @@ handle_control_extendcircuit(connection_t *conn, uint32_t len,
|
||||
if (circ->state == CIRCUIT_STATE_OPEN) {
|
||||
circ->state = CIRCUIT_STATE_BUILDING;
|
||||
if (circuit_send_next_onion_skin(circ) < 0) {
|
||||
log_fn(LOG_INFO,"send_next_onion_skin failed; circuit marked for closing.");
|
||||
info(LD_CONTROL,"send_next_onion_skin failed; circuit marked for closing.");
|
||||
circuit_mark_for_close(circ);
|
||||
if (v0)
|
||||
send_control0_error(conn, ERR_INTERNAL, "couldn't send onion skin");
|
||||
@ -1895,7 +1896,7 @@ handle_control_closecircuit(connection_t *conn, uint32_t len,
|
||||
if (!strcasecmp(smartlist_get(args, i), "IfUnused"))
|
||||
safe = 1;
|
||||
else
|
||||
log_fn(LOG_INFO, "Skipping unknown option %s",
|
||||
info(LD_CONTROL, "Skipping unknown option %s",
|
||||
(char*)smartlist_get(args,i));
|
||||
}
|
||||
}
|
||||
@ -1924,7 +1925,7 @@ handle_control_fragments(connection_t *conn, uint16_t command_type,
|
||||
{
|
||||
if (command_type == CONTROL0_CMD_FRAGMENTHEADER) {
|
||||
if (conn->incoming_cmd) {
|
||||
log_fn(LOG_WARN, "Dropping incomplete fragmented command");
|
||||
warn(LD_CONTROL, "Dropping incomplete fragmented command");
|
||||
tor_free(conn->incoming_cmd);
|
||||
}
|
||||
if (body_len < 6) {
|
||||
@ -1976,7 +1977,7 @@ connection_control_reached_eof(connection_t *conn)
|
||||
tor_assert(conn);
|
||||
tor_assert(conn->type == CONN_TYPE_CONTROL);
|
||||
|
||||
log_fn(LOG_INFO,"Control connection reached EOF. Closing.");
|
||||
info(LD_CONTROL,"Control connection reached EOF. Closing.");
|
||||
connection_mark_for_close(conn);
|
||||
return 0;
|
||||
}
|
||||
@ -2049,10 +2050,6 @@ connection_control_process_inbuf_v1(connection_t *conn)
|
||||
&& !TOR_ISSPACE(conn->incoming_cmd[cmd_len]))
|
||||
++cmd_len;
|
||||
|
||||
/*
|
||||
log_fn(LOG_NOTICE, "READ A COMMAND FROM THE BUFFER: <%s> [%d]",
|
||||
conn->incoming_cmd, (int)cmd_len);
|
||||
*/
|
||||
data_len -= cmd_len;
|
||||
conn->incoming_cmd[cmd_len]='\0';
|
||||
args = conn->incoming_cmd+cmd_len+1;
|
||||
@ -2060,10 +2057,6 @@ connection_control_process_inbuf_v1(connection_t *conn)
|
||||
++args;
|
||||
--data_len;
|
||||
}
|
||||
/*
|
||||
log_fn(LOG_NOTICE, "COMMAND IS: <%s>", conn->incoming_cmd);
|
||||
log_fn(LOG_NOTICE, "ARGS ARE: <%s>", args);
|
||||
*/
|
||||
|
||||
if (!strcasecmp(conn->incoming_cmd, "QUIT")) {
|
||||
connection_write_str_to_buf("250 closing connection\r\n", conn);
|
||||
@ -2149,13 +2142,13 @@ connection_control_process_inbuf_v0(connection_t *conn)
|
||||
{
|
||||
case -2:
|
||||
tor_free(body);
|
||||
log_fn(LOG_INFO, "Detected v1 control protocol on connection (fd %d)",
|
||||
info(LD_CONTROL, "Detected v1 control protocol on connection (fd %d)",
|
||||
conn->s);
|
||||
conn->state = CONTROL_CONN_STATE_NEEDAUTH_V1;
|
||||
return connection_control_process_inbuf_v1(conn);
|
||||
case -1:
|
||||
tor_free(body);
|
||||
log_fn(LOG_WARN, "Error in control command. Failing.");
|
||||
warn(LD_CONTROL, "Error in control command. Failing.");
|
||||
return -1;
|
||||
case 0:
|
||||
/* Control command not all here yet. Wait. */
|
||||
@ -2171,7 +2164,7 @@ connection_control_process_inbuf_v0(connection_t *conn)
|
||||
* commands will be considered. */
|
||||
if (conn->state == CONTROL_CONN_STATE_NEEDAUTH_V0 &&
|
||||
command_type != CONTROL0_CMD_AUTHENTICATE) {
|
||||
log_fn(LOG_WARN, "Rejecting '%s' command; authentication needed.",
|
||||
info(LD_CONTROL, "Rejecting '%s' command; authentication needed.",
|
||||
control_cmd_to_string(command_type));
|
||||
send_control0_error(conn, ERR_UNAUTHORIZED, "Authentication required");
|
||||
tor_free(body);
|
||||
@ -2191,7 +2184,7 @@ connection_control_process_inbuf_v0(connection_t *conn)
|
||||
body = conn->incoming_cmd;
|
||||
conn->incoming_cmd = NULL;
|
||||
} else if (conn->incoming_cmd) {
|
||||
log_fn(LOG_WARN, "Dropping incomplete fragmented command");
|
||||
warn(LD_CONTROL, "Dropping incomplete fragmented command");
|
||||
tor_free(conn->incoming_cmd);
|
||||
}
|
||||
|
||||
@ -2259,17 +2252,17 @@ connection_control_process_inbuf_v0(connection_t *conn)
|
||||
case CONTROL0_CMD_CONFVALUE:
|
||||
case CONTROL0_CMD_EVENT:
|
||||
case CONTROL0_CMD_INFOVALUE:
|
||||
log_fn(LOG_WARN, "Received client-only '%s' command; ignoring.",
|
||||
warn(LD_CONTROL, "Received client-only '%s' command; ignoring.",
|
||||
control_cmd_to_string(command_type));
|
||||
send_control0_error(conn, ERR_UNRECOGNIZED_TYPE,
|
||||
"Command type only valid from server to tor client");
|
||||
break;
|
||||
case CONTROL0_CMD_FRAGMENTHEADER:
|
||||
case CONTROL0_CMD_FRAGMENT:
|
||||
log_fn(LOG_WARN, "Recieved command fragment out of order; ignoring.");
|
||||
warn(LD_CONTROL, "Recieved command fragment out of order; ignoring.");
|
||||
send_control0_error(conn, ERR_SYNTAX, "Bad fragmentation on command.");
|
||||
default:
|
||||
log_fn(LOG_WARN, "Received unrecognized command type %d; ignoring.",
|
||||
warn(LD_CONTROL, "Received unrecognized command type %d; ignoring.",
|
||||
(int)command_type);
|
||||
send_control0_error(conn, ERR_UNRECOGNIZED_TYPE,
|
||||
"Unrecognized command type");
|
||||
@ -2325,7 +2318,7 @@ control_event_circuit_status(circuit_t *circ, circuit_status_event_t tp)
|
||||
case CIRC_EVENT_FAILED: status = "FAILED"; break;
|
||||
case CIRC_EVENT_CLOSED: status = "CLOSED"; break;
|
||||
default:
|
||||
log_fn(LOG_WARN, "Unrecognized status code %d", (int)tp);
|
||||
warn(LD_GENERAL, "Unrecognized status code %d", (int)tp);
|
||||
return 0;
|
||||
}
|
||||
send_control1_event(EVENT_CIRCUIT_STATUS,
|
||||
@ -2396,7 +2389,7 @@ control_event_stream_status(connection_t *conn, stream_status_event_t tp)
|
||||
case STREAM_EVENT_NEW_RESOLVE: status = "NEWRESOLVE"; break;
|
||||
case STREAM_EVENT_FAILED_RETRIABLE: status = "DETACHED"; break;
|
||||
default:
|
||||
log_fn(LOG_WARN, "Unrecognized status code %d", (int)tp);
|
||||
warn(LD_GENERAL, "Unrecognized status code %d", (int)tp);
|
||||
return 0;
|
||||
}
|
||||
circ = circuit_get_by_edge_conn(conn);
|
||||
@ -2438,7 +2431,7 @@ control_event_or_conn_status(connection_t *conn,or_conn_status_event_t tp)
|
||||
case OR_CONN_EVENT_FAILED: status = "FAILED"; break;
|
||||
case OR_CONN_EVENT_CLOSED: status = "CLOSED"; break;
|
||||
default:
|
||||
log_fn(LOG_WARN, "Unrecognized status code %d", (int)tp);
|
||||
warn(LD_GENERAL, "Unrecognized status code %d", (int)tp);
|
||||
return 0;
|
||||
}
|
||||
send_control1_event(EVENT_OR_CONN_STATUS,
|
||||
@ -2490,7 +2483,7 @@ enable_control_logging(void)
|
||||
|
||||
/** We got a log message: tell any interested control connections. */
|
||||
void
|
||||
control_event_logmsg(int severity, const char *msg)
|
||||
control_event_logmsg(int severity, int domain, const char *msg)
|
||||
{
|
||||
int oldlog, event;
|
||||
|
||||
@ -2615,7 +2608,7 @@ init_cookie_authentication(int enabled)
|
||||
authentication_cookie_is_set = 1;
|
||||
if (write_bytes_to_file(fname, authentication_cookie,
|
||||
AUTHENTICATION_COOKIE_LEN, 1)) {
|
||||
log_fn(LOG_WARN,"Error writing authentication cookie.");
|
||||
warn(LD_FS,"Error writing authentication cookie.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -133,7 +133,9 @@
|
||||
|
||||
#include "../common/crypto.h"
|
||||
#include "../common/tortls.h"
|
||||
#ifndef NEW_LOG_INTERFACE
|
||||
#define OLD_LOG_INTERFACE
|
||||
#endif
|
||||
#include "../common/log.h"
|
||||
#include "../common/compat.h"
|
||||
#include "../common/container.h"
|
||||
@ -1718,7 +1720,7 @@ int control_event_circuit_status(circuit_t *circ, circuit_status_event_t e);
|
||||
int control_event_stream_status(connection_t *conn, stream_status_event_t e);
|
||||
int control_event_or_conn_status(connection_t *conn, or_conn_status_event_t e);
|
||||
int control_event_bandwidth_used(uint32_t n_read, uint32_t n_written);
|
||||
void control_event_logmsg(int severity, const char *msg);
|
||||
void control_event_logmsg(int severity, int domain, const char *msg);
|
||||
int control_event_descriptors_changed(smartlist_t *routers);
|
||||
int control_event_address_mapped(const char *from, const char *to,time_t expires);
|
||||
|
||||
|
@ -4,7 +4,6 @@
|
||||
|
||||
#include "orconfig.h"
|
||||
|
||||
#define OLD_LOG_INTERFACE
|
||||
#include "../common/compat.h"
|
||||
#include "../common/util.h"
|
||||
#include "../common/log.h"
|
||||
@ -42,7 +41,7 @@
|
||||
|
||||
#define RESPONSE_LEN 8
|
||||
#define log_sock_error(act, _s) \
|
||||
do { log_fn(LOG_ERR, "Error while %s: %s", act, \
|
||||
do { log_fn(LOG_ERR, LD_NET, "Error while %s: %s", act, \
|
||||
tor_socket_strerror(tor_socket_errno(_s))); } while (0)
|
||||
|
||||
/** Set *<b>out</b> to a newly allocated SOCKS4a resolve request with
|
||||
@ -83,20 +82,20 @@ parse_socks4a_resolve_response(const char *response, size_t len,
|
||||
tor_assert(addr_out);
|
||||
|
||||
if (len < RESPONSE_LEN) {
|
||||
log_fn(LOG_WARN,"Truncated socks response.");
|
||||
warn(LD_PROTOCOL,"Truncated socks response.");
|
||||
return -1;
|
||||
}
|
||||
if (((uint8_t)response[0])!=0) { /* version: 0 */
|
||||
log_fn(LOG_WARN,"Nonzero version in socks response: bad format.");
|
||||
warn(LD_PROTOCOL,"Nonzero version in socks response: bad format.");
|
||||
return -1;
|
||||
}
|
||||
status = (uint8_t)response[1];
|
||||
if (get_uint16(response+2)!=0) { /* port: 0 */
|
||||
log_fn(LOG_WARN,"Nonzero port in socks response: bad format.");
|
||||
warn(LD_PROTOCOL,"Nonzero port in socks response: bad format.");
|
||||
return -1;
|
||||
}
|
||||
if (status != 90) {
|
||||
log_fn(LOG_WARN,"Got status response '%d': socks request failed.", status);
|
||||
warn(LD_NET,"Got status response '%d': socks request failed.", status);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -137,7 +136,7 @@ do_resolve(const char *hostname, uint32_t sockshost, uint16_t socksport,
|
||||
}
|
||||
|
||||
if ((len = build_socks4a_resolve_request(&req, "", hostname))<0) {
|
||||
log_fn(LOG_ERR, "Error generating SOCKS request");
|
||||
err("Error generating SOCKS request");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -158,7 +157,7 @@ do_resolve(const char *hostname, uint32_t sockshost, uint16_t socksport,
|
||||
while (len < RESPONSE_LEN) {
|
||||
r = recv(s, response_buf+len, RESPONSE_LEN-len, 0);
|
||||
if (r==0) {
|
||||
log_fn(LOG_WARN,"EOF while reading SOCKS response");
|
||||
warn(LD_NET,"EOF while reading SOCKS response");
|
||||
return -1;
|
||||
}
|
||||
if (r<0) {
|
||||
@ -213,7 +212,7 @@ main(int argc, char **argv)
|
||||
add_stream_log(LOG_WARN, LOG_ERR, "<stderr>", stderr);
|
||||
}
|
||||
if (n_args == 1) {
|
||||
log_fn(LOG_DEBUG, "defaulting to localhost:9050");
|
||||
debug(LD_CONFIG, "defaulting to localhost:9050");
|
||||
sockshost = 0x7f000001u; /* localhost */
|
||||
socksport = 9050; /* 9050 */
|
||||
} else if (n_args == 2) {
|
||||
@ -222,7 +221,7 @@ main(int argc, char **argv)
|
||||
return 1;
|
||||
}
|
||||
if (socksport == 0) {
|
||||
log_fn(LOG_DEBUG, "defaulting to port 9050");
|
||||
debug(LD_CONFIG, "defaulting to port 9050");
|
||||
socksport = 9050;
|
||||
}
|
||||
} else {
|
||||
@ -237,7 +236,7 @@ main(int argc, char **argv)
|
||||
}
|
||||
|
||||
if (network_init()<0) {
|
||||
log_fn(LOG_ERR,"Error initializing network; exiting.");
|
||||
err("Error initializing network; exiting.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user