diff options
author | Alexander Færøy <ahf@torproject.org> | 2018-11-23 22:50:55 +0100 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2018-12-17 16:39:28 -0500 |
commit | e3ceaebba25127a1d4a3da16e9128ab52491c080 (patch) | |
tree | 4031572e1fe7ff60b4845641a4a3cdc385cbcaed /src/feature/client | |
parent | bfb94dd2ca8e04fb1fe8aba9ad48effbb8b70662 (diff) | |
download | tor-e3ceaebba25127a1d4a3da16e9128ab52491c080.tar.gz tor-e3ceaebba25127a1d4a3da16e9128ab52491c080.zip |
Add support for logging messages from pluggable transports.
This patch adds support for the "LOG" protocol message from a pluggable
transport. This allows pluggable transport developers to relay log
messages from their binary to Tor, which will both emit them as log
messages from the Tor process itself, but also pass them on via the
control port.
See: https://bugs.torproject.org/28180
See: https://bugs.torproject.org/28181
See: https://bugs.torproject.org/28182
Diffstat (limited to 'src/feature/client')
-rw-r--r-- | src/feature/client/transports.c | 42 | ||||
-rw-r--r-- | src/feature/client/transports.h | 1 |
2 files changed, 43 insertions, 0 deletions
diff --git a/src/feature/client/transports.c b/src/feature/client/transports.c index f0400b713d..dc76e9c245 100644 --- a/src/feature/client/transports.c +++ b/src/feature/client/transports.c @@ -128,6 +128,7 @@ static void parse_method_error(const char *line, int is_server_method); #define PROTO_SMETHODS_DONE "SMETHODS DONE" #define PROTO_PROXY_DONE "PROXY DONE" #define PROTO_PROXY_ERROR "PROXY-ERROR" +#define PROTO_LOG "LOG" /** The first and only supported - at the moment - configuration protocol version. */ @@ -909,6 +910,9 @@ handle_proxy_line(const char *line, managed_proxy_t *mp) parse_proxy_error(line); goto err; + } else if (!strcmpstart(line, PROTO_LOG)) { + parse_log_line(line); + return; } else if (!strcmpstart(line, SPAWN_ERROR_MESSAGE)) { /* managed proxy launch failed: parse error message to learn why. */ int retval, child_state, saved_errno; @@ -1146,6 +1150,44 @@ parse_proxy_error(const char *line) line+strlen(PROTO_PROXY_ERROR)+1); } +/** Parses a LOG <b>line</b> and emit log events accordingly. */ +STATIC void +parse_log_line(const char *line) +{ + smartlist_t *items = smartlist_new(); + + if (strlen(line) < (strlen(PROTO_LOG) + 1)) { + log_warn(LD_PT, "Managed proxy sent us a %s line " + "with missing arguments.", PROTO_LOG); + goto done; + } + + const char *arguments = line + strlen(PROTO_LOG) + 1; + + /* The format is 'LOG <transport> <message>'. We accept empty messages. */ + smartlist_split_string(items, arguments, NULL, + SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 2); + + if (smartlist_len(items) < 2) { + log_warn(LD_PT, "Managed proxy sent us a %s line " + "with too few arguments.", PROTO_LOG); + goto done; + } + + const char *transport_name = smartlist_get(items, 0); + const char *message = smartlist_get(items, 1); + + log_info(LD_PT, "Managed proxy transport \"%s\" says: %s", + transport_name, message); + + /* Emit control port event. */ + control_event_transport_log(transport_name, message); + + done: + SMARTLIST_FOREACH(items, char *, s, tor_free(s)); + smartlist_free(items); +} + /** Return a newly allocated string that tor should place in * TOR_PT_SERVER_TRANSPORT_OPTIONS while configuring the server * manged proxy in <b>mp</b>. Return NULL if no such options are found. */ diff --git a/src/feature/client/transports.h b/src/feature/client/transports.h index 59df637d81..fbb720aac6 100644 --- a/src/feature/client/transports.h +++ b/src/feature/client/transports.h @@ -128,6 +128,7 @@ STATIC int parse_version(const char *line, managed_proxy_t *mp); STATIC void parse_env_error(const char *line); STATIC void parse_proxy_error(const char *line); STATIC void handle_proxy_line(const char *line, managed_proxy_t *mp); +STATIC void parse_log_line(const char *line); STATIC char *get_transport_options_for_server_proxy(const managed_proxy_t *mp); STATIC void managed_proxy_destroy(managed_proxy_t *mp, |