]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
login-proxy: Add ip:port to log prefix and remove them from log messages
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Thu, 9 Apr 2020 21:27:40 +0000 (00:27 +0300)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Fri, 24 Apr 2020 08:02:40 +0000 (08:02 +0000)
src/login-common/client-common-auth.c
src/login-common/client-common.c
src/login-common/login-proxy.c

index 4b6bd39c98d21eb933b38020c49d650f0beb2257..197d982227d1879561971feac17d03ce5069de0f 100644 (file)
@@ -262,13 +262,13 @@ void client_proxy_finish_destroy_client(struct client *client)
                return;
        }
 
-       str_printfa(str, "started proxying to %s:%u",
-                   login_proxy_get_host(client->login_proxy),
-                   login_proxy_get_port(client->login_proxy));
+       /* Include hostname in the log message in case it's different from the
+          IP address in the prefix. */
+       str_printfa(str, "started proxying to %s",
+                   login_proxy_get_host(client->login_proxy));
        if (strcmp(client->virtual_user, client->proxy_user) != 0) {
                /* remote username is different, log it */
-               str_append_c(str, '/');
-               str_append(str, client->proxy_user);
+               str_printfa(str, " as user %s", client->proxy_user);
        }
        if (client->proxy_master_user != NULL)
                str_printfa(str, " (master %s)", client->proxy_master_user);
@@ -292,13 +292,10 @@ void client_proxy_log_failure(struct client *client, const char *line)
 {
        string_t *str = t_str_new(128);
 
-       str_printfa(str, "Login failed to %s:%u",
-                   login_proxy_get_host(client->login_proxy),
-                   login_proxy_get_port(client->login_proxy));
+       str_printfa(str, "Login failed");
        if (strcmp(client->virtual_user, client->proxy_user) != 0) {
                /* remote username is different, log it */
-               str_append_c(str, '/');
-               str_append(str, client->proxy_user);
+               str_printfa(str, " as user %s", client->proxy_user);
        }
        if (client->proxy_master_user != NULL)
                str_printfa(str, " (master %s)", client->proxy_master_user);
@@ -361,10 +358,8 @@ static void proxy_input(struct client *client)
                line = i_stream_next_line(input);
                duration = ioloop_time - client->created;
                e_error(login_proxy_get_event(client->login_proxy),
-                       "Disconnected by server %s:%u: %s "
+                       "Disconnected by server: %s "
                        "(state=%s, duration=%us)%s",
-                       login_proxy_get_host(client->login_proxy),
-                       login_proxy_get_port(client->login_proxy),
                        io_stream_get_disconnect_reason(input, NULL),
                        client_proxy_get_state(client), duration,
                        line == NULL ? "" : t_strdup_printf(
@@ -475,6 +470,11 @@ static int proxy_start(struct client *client,
        proxy_set.notify_refresh_secs = reply->proxy_refresh_secs;
        proxy_set.ssl_flags = reply->ssl_flags;
 
+       /* Include destination ip:port also in the log prefix */
+       event_set_append_log_prefix(event, t_strdup_printf(
+               "proxy(%s,%s:%u): ", client->virtual_user,
+               net_ip2addr(&proxy_set.ip), proxy_set.port));
+
        if (login_proxy_new(client, event, &proxy_set, proxy_input) < 0) {
                event_unref(&event);
                client_proxy_error(client, PROXY_FAILURE_MSG);
index 807fe27249aeb2cdaa13efb0ba1137424d32b66b..e96661ec8dedd7af26b4fb8eae1257631bbc314b 100644 (file)
@@ -107,10 +107,8 @@ static void client_idle_disconnect_timeout(struct client *client)
                secs = ioloop_time - client->created;
                user_reason = "Timeout while finishing login.";
                destroy_reason = t_strdup_printf(
-                       "Logging in to %s:%u timed out "
+                       "Logging in timed out "
                        "(state=%s, duration=%us)",
-                       login_proxy_get_host(client->login_proxy),
-                       login_proxy_get_port(client->login_proxy),
                        client_proxy_get_state(client), secs);
                e_error(login_proxy_get_event(client->login_proxy),
                        "%s", destroy_reason);
index edff91321bc785fa3d2821bc97a67b3e8647e705..082c0ebd2476a5d7a1f226a3d0aff6cb8a56bc37 100644 (file)
@@ -183,8 +183,7 @@ proxy_log_connect_error(struct login_proxy *proxy)
                str_printfa(str, "connect(%s, %u) failed: %m",
                            net_ip2addr(&proxy->ip), proxy->port);
        } else {
-               str_printfa(str, "Login for %s:%u timed out in state=%s",
-                           net_ip2addr(&proxy->ip), proxy->port,
+               str_printfa(str, "Login timed out in state=%s",
                            client_proxy_get_state(proxy->client));
        }
        str_printfa(str, " (after %u secs",
@@ -289,8 +288,7 @@ static int login_proxy_connect(struct login_proxy *proxy)
            rec->last_failure.tv_sec - rec->last_success.tv_sec > PROXY_IMMEDIATE_FAILURE_SECS &&
            rec->num_waiting_connections > 1) {
                /* the server is down. fail immediately */
-               e_error(proxy->event, "Host %s:%u is down",
-                       net_ip2addr(&proxy->ip), proxy->port);
+               e_error(proxy->event, "Host is down");
                return -1;
        }
 
@@ -463,7 +461,6 @@ login_proxy_free_full(struct login_proxy **_proxy, const char *reason,
 {
        struct login_proxy *proxy = *_proxy;
        struct client *client = proxy->client;
-       const char *ipstr;
        unsigned int delay_ms = 0;
 
        *_proxy = NULL;
@@ -483,9 +480,7 @@ login_proxy_free_full(struct login_proxy **_proxy, const char *reason,
                if ((flags & LOGIN_PROXY_FREE_FLAG_DELAYED) != 0)
                        delay_ms = login_proxy_delay_disconnect(proxy);
 
-               ipstr = net_ip2addr(&proxy->client->ip);
-               e_info(proxy->event, "disconnecting %s (%s)%s",
-                      ipstr != NULL ? ipstr : "", reason,
+               e_info(proxy->event, "disconnecting (%s)%s", reason,
                       delay_ms == 0 ? "" : t_strdup_printf(" - disconnecting client in %ums", delay_ms));
 
                i_assert(detached_login_proxies_count > 0);
@@ -686,18 +681,14 @@ int login_proxy_starttls(struct login_proxy *proxy)
                                        &proxy->server_output,
                                        &proxy->server_ssl_iostream,
                                        &error) < 0) {
-               e_error(proxy->event,
-                       "Failed to create SSL client to %s:%u: %s",
-                       net_ip2addr(&proxy->ip), proxy->port, error);
+               e_error(proxy->event, "Failed to create SSL client: %s", error);
                ssl_iostream_context_unref(&ssl_ctx);
                return -1;
        }
        ssl_iostream_context_unref(&ssl_ctx);
        if (ssl_iostream_handshake(proxy->server_ssl_iostream) < 0) {
                error = ssl_iostream_get_last_error(proxy->server_ssl_iostream);
-               e_error(proxy->event,
-                       "Failed to start SSL handshake to %s:%u: %s",
-                       net_ip2addr(&proxy->ip), proxy->port,
+               e_error(proxy->event, "Failed to start SSL handshake: %s",
                        ssl_iostream_get_last_error(proxy->server_ssl_iostream));
                return -1;
        }