aboutsummaryrefslogtreecommitdiff
path: root/src/or/control.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/or/control.c')
-rw-r--r--src/or/control.c71
1 files changed, 32 insertions, 39 deletions
diff --git a/src/or/control.c b/src/or/control.c
index 545e767fd..a3c65d64f 100644
--- a/src/or/control.c
+++ b/src/or/control.c
@@ -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,17 +1145,17 @@ 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,
- "Unable to allocate address for '%s' in MapAddress msg",
- safe_str(line));
+ warn(LD_CONTROL,
+ "Unable to allocate address for '%s' in MapAddress msg",
+ safe_str(line));
} else {
size_t anslen = strlen(address)+strlen(to)+8;
char *ans = tor_malloc(anslen);
@@ -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,8 +1896,8 @@ 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",
- (char*)smartlist_get(args,i));
+ info(LD_CONTROL, "Skipping unknown option %s",
+ (char*)smartlist_get(args,i));
}
}
SMARTLIST_FOREACH(args, char *, cp, tor_free(cp));
@@ -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)",
- conn->s);
+ 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,8 +2164,8 @@ 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.",
- control_cmd_to_string(command_type));
+ 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);
goto again;
@@ -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;
}