]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
*-login: Use login_proxy.event for logging
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Thu, 9 Apr 2020 20:24:36 +0000 (23:24 +0300)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Fri, 24 Apr 2020 08:02:40 +0000 (08:02 +0000)
This way there's no need to have the "proxy: " or "proxy(user): " prefix.
This also standardizes it to always be "proxy(user): ".

src/imap-login/imap-proxy.c
src/login-common/client-common-auth.c
src/login-common/client-common.c
src/login-common/login-proxy.c
src/pop3-login/pop3-proxy.c
src/submission-login/submission-proxy.c

index 3ff25c725d9298d76cfcb83b3040220e7f1d8744..fc9e3062c580e1730247e5001200e22e284384ec 100644 (file)
@@ -80,8 +80,8 @@ static int proxy_write_starttls(struct imap_client *client, string_t *str)
        if ((ssl_flags & PROXY_SSL_FLAG_STARTTLS) != 0) {
                if (client->proxy_backend_capability != NULL &&
                    !str_array_icase_find(t_strsplit(client->proxy_backend_capability, " "), "STARTTLS")) {
-                       e_error(client->common.event,
-                               "proxy: Remote doesn't support STARTTLS");
+                       e_error(login_proxy_get_event(client->common.login_proxy),
+                               "Remote doesn't support STARTTLS");
                        return -1;
                }
                str_append(str, "S STARTTLS\r\n");
@@ -120,8 +120,8 @@ static int proxy_write_login(struct imap_client *client, string_t *str)
                /* logging in normally - use LOGIN command */
                if (client->proxy_logindisabled &&
                    login_proxy_get_ssl_flags(client->common.login_proxy) == 0) {
-                       e_error(client->common.event,
-                               "proxy: Remote advertised LOGINDISABLED and SSL/TLS not enabled");
+                       e_error(login_proxy_get_event(client->common.login_proxy),
+                               "Remote advertised LOGINDISABLED and SSL/TLS not enabled");
                        return -1;
                }
                str_append(str, "L LOGIN ");
@@ -150,8 +150,8 @@ static int proxy_write_login(struct imap_client *client, string_t *str)
        if (client->proxy_sasl_ir) {
                if (dsasl_client_output(client->common.proxy_sasl_client,
                                        &output, &len, &error) < 0) {
-                       e_error(client->common.event,
-                               "proxy: SASL mechanism %s init failed: %s",
+                       e_error(login_proxy_get_event(client->common.login_proxy),
+                               "SASL mechanism %s init failed: %s",
                                mech_name, error);
                        return -1;
                }
@@ -175,8 +175,8 @@ static int proxy_input_banner(struct imap_client *client,
        int ret;
 
        if (!str_begins(line, "* OK ")) {
-               e_error(client->common.event,
-                       "proxy: Remote returned invalid banner: %s",
+               e_error(login_proxy_get_event(client->common.login_proxy),
+                       "Remote returned invalid banner: %s",
                        str_sanitize(line, 160));
                return -1;
        }
@@ -283,8 +283,8 @@ int imap_proxy_parse_line(struct client *client, const char *line)
                str = t_str_new(128);
                if (line[1] != ' ' ||
                    base64_decode(line+2, strlen(line+2), NULL, str) < 0) {
-                       e_error(client->event,
-                               "proxy: Server sent invalid base64 data in AUTHENTICATE response");
+                       e_error(login_proxy_get_event(client->login_proxy),
+                               "Server sent invalid base64 data in AUTHENTICATE response");
                        client_proxy_failed(client, TRUE);
                        return -1;
                }
@@ -295,8 +295,8 @@ int imap_proxy_parse_line(struct client *client, const char *line)
                                                  &data, &data_len, &error);
                }
                if (ret < 0) {
-                       e_error(client->event,
-                               "proxy: Server sent invalid authentication data: %s",
+                       e_error(login_proxy_get_event(client->login_proxy),
+                               "Server sent invalid authentication data: %s",
                                error);
                        client_proxy_failed(client, TRUE);
                        return -1;
@@ -316,8 +316,8 @@ int imap_proxy_parse_line(struct client *client, const char *line)
 
                if (!str_begins(line, "S OK ")) {
                        /* STARTTLS failed */
-                       e_error(client->event,
-                               "proxy: Remote STARTTLS failed: %s",
+                       e_error(login_proxy_get_event(client->login_proxy),
+                               "Remote STARTTLS failed: %s",
                                str_sanitize(line + 5, 160));
                        client_proxy_failed(client, TRUE);
                        return -1;
@@ -434,8 +434,8 @@ int imap_proxy_parse_line(struct client *client, const char *line)
                return 0;
        } else {
                /* tagged reply, shouldn't happen. */
-               e_error(client->event,
-                       "proxy: Unexpected input, ignoring: %s",
+               e_error(login_proxy_get_event(client->login_proxy),
+                       "Unexpected input, ignoring: %s",
                        str_sanitize(line, 160));
                return 0;
        }
index 50d3cfca1071fa5613cb0a5e5ed43c0f49bf1c92..67af7e57cb94add5ce2ab79e180e0d87fe9f516a 100644 (file)
@@ -274,8 +274,9 @@ void client_proxy_finish_destroy_client(struct client *client)
        if (client->proxy_master_user != NULL)
                str_printfa(str, " (master %s)", client->proxy_master_user);
 
+       e_info(login_proxy_get_event(client->login_proxy), "%s", str_c(str));
        login_proxy_detach(client->login_proxy);
-       client_destroy_success(client, str_c(str));
+       client_destroy_success(client, NULL);
 }
 
 static void client_proxy_error(struct client *client, const char *text)
@@ -292,8 +293,7 @@ void client_proxy_log_failure(struct client *client, const char *line)
 {
        string_t *str = t_str_new(128);
 
-       str_printfa(str, "proxy(%s): Login failed to %s:%u",
-                   client->virtual_user,
+       str_printfa(str, "Login failed to %s:%u",
                    login_proxy_get_host(client->login_proxy),
                    login_proxy_get_port(client->login_proxy));
        if (strcmp(client->virtual_user, client->proxy_user) != 0) {
@@ -305,7 +305,7 @@ void client_proxy_log_failure(struct client *client, const char *line)
                str_printfa(str, " (master %s)", client->proxy_master_user);
        str_append(str, ": ");
        str_append(str, line);
-       e_info(client->event, "%s", str_c(str));
+       e_info(login_proxy_get_event(client->login_proxy), "%s", str_c(str));
 }
 
 void client_proxy_failed(struct client *client, bool send_line)
@@ -353,13 +353,15 @@ static void proxy_input(struct client *client)
 
        switch (i_stream_read(input)) {
        case -2:
-               e_error(client->event, "proxy: Remote input buffer full");
+               e_error(login_proxy_get_event(client->login_proxy),
+                       "Remote input buffer full");
                client_proxy_failed(client, TRUE);
                return;
        case -1:
                line = i_stream_next_line(input);
                duration = ioloop_time - client->created;
-               e_error(client->event, "proxy: Remote %s:%u disconnected: %s "
+               e_error(login_proxy_get_event(client->login_proxy),
+                       "Remote %s:%u disconnected: %s "
                        "(state=%s, duration=%us)%s",
                        login_proxy_get_host(client->login_proxy),
                        login_proxy_get_port(client->login_proxy),
@@ -383,23 +385,23 @@ static void proxy_input(struct client *client)
 }
 
 static bool
-proxy_check_start(struct client *client, const struct client_auth_reply *reply,
+proxy_check_start(struct client *client, struct event *event,
+                 const struct client_auth_reply *reply,
                  const struct dsasl_client_mech **sasl_mech_r)
 {
        if (reply->password == NULL) {
-               e_error(client->event, "proxy: password not given");
+               e_error(event, "password not given");
                return FALSE;
        }
        if (reply->host == NULL || *reply->host == '\0') {
-               e_error(client->event, "proxy: host not given");
+               e_error(event, "host not given");
                return FALSE;
        }
 
        if (reply->proxy_mech != NULL) {
                *sasl_mech_r = dsasl_client_mech_find(reply->proxy_mech);
                if (*sasl_mech_r == NULL) {
-                       e_error(client->event,
-                               "proxy: Unsupported SASL mechanism %s",
+                       e_error(event, "Unsupported SASL mechanism %s",
                                reply->proxy_mech);
                        return FALSE;
                }
@@ -410,7 +412,7 @@ proxy_check_start(struct client *client, const struct client_auth_reply *reply,
 
        if (login_proxy_is_ourself(client, reply->host, reply->port,
                                   reply->destuser)) {
-               e_error(client->event, "Proxying loops to itself");
+               e_error(event, "Proxying loops to itself");
                return FALSE;
        }
        return TRUE;
@@ -434,7 +436,7 @@ static int proxy_start(struct client *client,
        event_set_append_log_prefix(event, t_strdup_printf(
                "proxy(%s): ", client->virtual_user));
 
-       if (!proxy_check_start(client, reply, &sasl_mech)) {
+       if (!proxy_check_start(client, event, reply, &sasl_mech)) {
                client_proxy_error(client, PROXY_FAILURE_MSG);
                event_unref(&event);
                return -1;
index 8b9ccb017000fea06e15154610f1652864201068..d96dba8256219e1304a308912a002224a8561d7c 100644 (file)
@@ -107,12 +107,13 @@ 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(
-                       "proxy: Logging in to %s:%u timed out "
+                       "Logging in to %s:%u 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(client->event, "%s", destroy_reason);
+               e_error(login_proxy_get_event(client->login_proxy),
+                       "%s", destroy_reason);
        } else {
                user_reason = "Disconnected for inactivity.";
                destroy_reason = "Disconnected: Inactivity";
index c8fcb09813996d21ac66652869a22ee8afdcbe7d..828629c1c46f76b8878bff3d8418bc35048083d0 100644 (file)
@@ -181,7 +181,6 @@ proxy_log_connect_error(struct login_proxy *proxy)
        struct ip_addr local_ip;
        in_port_t local_port;
 
-       str_printfa(str, "proxy(%s): ", proxy->client->virtual_user);
        if (!proxy->connected) {
                str_printfa(str, "connect(%s, %u) failed: %m",
                            net_ip2addr(&proxy->ip), proxy->port);
@@ -205,7 +204,7 @@ proxy_log_connect_error(struct login_proxy *proxy)
        }
 
        str_append_c(str, ')');
-       e_error(proxy->client->event, "%s", str_c(str));
+       e_error(proxy->event, "%s", str_c(str));
 }
 
 static void proxy_reconnect_timeout(struct login_proxy *proxy)
@@ -285,10 +284,9 @@ static int login_proxy_connect(struct login_proxy *proxy)
 
        if (proxy->ip.family == 0 &&
            net_addr2ip(proxy->host, &proxy->ip) < 0) {
-               e_error(proxy->client->event,
-                       "proxy(%s): BUG: host %s is not an IP "
-                       "(auth should have changed it)",
-                       proxy->client->virtual_user, proxy->host);
+               e_error(proxy->event,
+                       "BUG: host %s is not an IP (auth should have changed it)",
+                       proxy->host);
                return -1;
        }
 
@@ -301,9 +299,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->client->event,
-                       "proxy(%s): Host %s:%u is down",
-                       proxy->client->virtual_user,
+               e_error(proxy->event, "Host %s:%u is down",
                        net_ip2addr(&proxy->ip), proxy->port);
                return -1;
        }
@@ -333,16 +329,13 @@ int login_proxy_new(struct client *client, struct event *event,
        i_assert(client->login_proxy == NULL);
 
        if (set->host == NULL || *set->host == '\0') {
-               e_error(client->event,
-                       "proxy(%s): host not given", client->virtual_user);
+               e_error(event, "host not given");
                event_unref(&event);
                return -1;
        }
 
        if (client->proxy_ttl <= 1) {
-               e_error(client->event,
-                       "proxy(%s): TTL reached zero - "
-                       "proxies appear to be looping?", client->virtual_user);
+               e_error(event, "TTL reached zero - proxies appear to be looping?");
                event_unref(&event);
                return -1;
        }
@@ -505,8 +498,7 @@ login_proxy_free_full(struct login_proxy **_proxy, const char *reason,
                        delay_ms = login_proxy_delay_disconnect(proxy);
 
                ipstr = net_ip2addr(&proxy->client->ip);
-               e_info(proxy->client->event, "proxy(%s): disconnecting %s%s%s",
-                      proxy->client->virtual_user,
+               e_info(proxy->event, "disconnecting %s%s%s",
                       ipstr != NULL ? ipstr : "",
                       reason == NULL ? "" : t_strdup_printf(" (%s)", reason),
                       delay_ms == 0 ? "" : t_strdup_printf(" - disconnecting client in %ums", delay_ms));
@@ -707,8 +699,8 @@ int login_proxy_starttls(struct login_proxy *proxy)
 
        io_remove(&proxy->server_io);
        if (ssl_iostream_client_context_cache_get(&ssl_set, &ssl_ctx, &error) < 0) {
-               e_error(proxy->client->event,
-                       "proxy: Failed to create SSL client context: %s", error);
+               e_error(proxy->event, "Failed to create SSL client context: %s",
+                       error);
                return -1;
        }
 
@@ -717,8 +709,8 @@ int login_proxy_starttls(struct login_proxy *proxy)
                                        &proxy->server_output,
                                        &proxy->server_ssl_iostream,
                                        &error) < 0) {
-               e_error(proxy->client->event,
-                       "proxy: Failed to create SSL client to %s:%u: %s",
+               e_error(proxy->event,
+                       "Failed to create SSL client to %s:%u: %s",
                        net_ip2addr(&proxy->ip), proxy->port, error);
                ssl_iostream_context_unref(&ssl_ctx);
                return -1;
@@ -726,8 +718,8 @@ int login_proxy_starttls(struct login_proxy *proxy)
        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->client->event,
-                       "proxy: Failed to start SSL handshake to %s:%u: %s",
+               e_error(proxy->event,
+                       "Failed to start SSL handshake to %s:%u: %s",
                        net_ip2addr(&proxy->ip), proxy->port,
                        ssl_iostream_get_last_error(proxy->server_ssl_iostream));
                return -1;
index 61a1ea756fcf8edb479d562ffddf0da985a131bc..44db29e771264f2b51c3a45ad378209152b9473f 100644 (file)
@@ -87,8 +87,8 @@ static int proxy_send_login(struct pop3_client *client, struct ostream *output)
        str_printfa(str, "AUTH %s ", mech_name);
        if (dsasl_client_output(client->common.proxy_sasl_client,
                                &sasl_output, &len, &error) < 0) {
-               e_error(client->common.event,
-                       "proxy: SASL mechanism %s init failed: %s",
+               e_error(login_proxy_get_event(client->common.login_proxy),
+                       "SASL mechanism %s init failed: %s",
                        mech_name, error);
                return -1;
        }
@@ -117,7 +117,8 @@ pop3_proxy_continue_sasl_auth(struct client *client, struct ostream *output,
 
        str = t_str_new(128);
        if (base64_decode(line, strlen(line), NULL, str) < 0) {
-               e_error(client->event, "proxy: Server sent invalid base64 data in AUTH response");
+               e_error(login_proxy_get_event(client->login_proxy),
+                       "Server sent invalid base64 data in AUTH response");
                return -1;
        }
        ret = dsasl_client_input(client->proxy_sasl_client,
@@ -127,9 +128,8 @@ pop3_proxy_continue_sasl_auth(struct client *client, struct ostream *output,
                                          &data, &data_len, &error);
        }
        if (ret < 0) {
-               e_error(client->event,
-                       "proxy: Server sent invalid authentication data: %s",
-                       error);
+               e_error(login_proxy_get_event(client->login_proxy),
+                       "Server sent invalid authentication data: %s", error);
                return -1;
        }
        i_assert(ret == 0);
@@ -155,8 +155,8 @@ int pop3_proxy_parse_line(struct client *client, const char *line)
        case POP3_PROXY_BANNER:
                /* this is a banner */
                if (!str_begins(line, "+OK")) {
-                       e_error(client->event,
-                               "proxy: Remote returned invalid banner: %s",
+                       e_error(login_proxy_get_event(client->login_proxy),
+                               "Remote returned invalid banner: %s",
                                str_sanitize(line, 160));
                        client_proxy_failed(client, TRUE);
                        return -1;
@@ -177,7 +177,8 @@ int pop3_proxy_parse_line(struct client *client, const char *line)
                return 0;
        case POP3_PROXY_STARTTLS:
                if (!str_begins(line, "+OK")) {
-                       e_error(client->event, "proxy: Remote STLS failed: %s",
+                       e_error(login_proxy_get_event(client->login_proxy),
+                               "Remote STLS failed: %s",
                                str_sanitize(line, 160));
                        client_proxy_failed(client, TRUE);
                        return -1;
@@ -195,8 +196,8 @@ int pop3_proxy_parse_line(struct client *client, const char *line)
                return 1;
        case POP3_PROXY_XCLIENT:
                if (!str_begins(line, "+OK")) {
-                       e_error(client->event,
-                               "proxy: Remote XCLIENT failed: %s",
+                       e_error(login_proxy_get_event(client->login_proxy),
+                               "Remote XCLIENT failed: %s",
                                str_sanitize(line, 160));
                        client_proxy_failed(client, TRUE);
                        return -1;
index 266769059069bf3817b6e3f0645005a8d97baebb..cc44a4b6c547b3ebb8ce2791e723511554aad9a8 100644 (file)
@@ -101,7 +101,7 @@ proxy_send_login(struct submission_client *client, struct ostream *output)
        if ((client->proxy_capability & SMTP_CAPABILITY_AUTH) == 0) {
                /* Prevent sending credentials to a server that has login
                   disabled; i.e., due to the lack of TLS */
-               e_error(client->common.event, "proxy: "
+               e_error(login_proxy_get_event(client->common.login_proxy),
                        "Server has disabled authentication (TLS required?)");
                return -1;
        }
@@ -127,8 +127,8 @@ proxy_send_login(struct submission_client *client, struct ostream *output)
        str_printfa(str, "AUTH %s ", mech_name);
        if (dsasl_client_output(client->common.proxy_sasl_client,
                                &sasl_output, &len, &error) < 0) {
-               e_error(client->common.event,
-                       "proxy: SASL mechanism %s init failed: %s",
+               e_error(login_proxy_get_event(client->common.login_proxy),
+                       "SASL mechanism %s init failed: %s",
                        mech_name, error);
                return -1;
        }
@@ -158,7 +158,7 @@ submission_proxy_continue_sasl_auth(struct client *client, struct ostream *outpu
 
        str = t_str_new(128);
        if (base64_decode(line, strlen(line), NULL, str) < 0) {
-               e_error(client->event, "proxy: "
+               e_error(login_proxy_get_event(client->login_proxy),
                        "Server sent invalid base64 data in AUTH response");
                return -1;
        }
@@ -169,9 +169,8 @@ submission_proxy_continue_sasl_auth(struct client *client, struct ostream *outpu
                                          &data, &data_len, &error);
        }
        if (ret < 0) {
-               e_error(client->event,
-                       "proxy: Server sent invalid authentication data: %s",
-                       error);
+               e_error(login_proxy_get_event(client->login_proxy),
+                       "Server sent invalid authentication data: %s", error);
                return -1;
        }
        i_assert(ret == 0);
@@ -256,8 +255,8 @@ int submission_proxy_parse_line(struct client *client, const char *line)
        }
        if (subm_client->proxy_reply_status != 0 &&
            subm_client->proxy_reply_status != status) {
-               e_error(client->event,
-                       "proxy: Remote returned inconsistent SMTP reply: %s "
+               e_error(login_proxy_get_event(client->login_proxy),
+                       "Remote returned inconsistent SMTP reply: %s "
                        "(status != %u)", str_sanitize(line, 160),
                        subm_client->proxy_reply_status);
                client_proxy_failed(client, TRUE);
@@ -275,8 +274,8 @@ int submission_proxy_parse_line(struct client *client, const char *line)
        case SUBMISSION_PROXY_BANNER:
                /* this is a banner */
                if (invalid_line || status != 220) {
-                       e_error(client->event,
-                               "proxy: Remote returned invalid banner: %s",
+                       e_error(login_proxy_get_event(client->login_proxy),
+                               "Remote returned invalid banner: %s",
                                str_sanitize(line, 160));
                        client_proxy_failed(client, TRUE);
                        return -1;
@@ -291,8 +290,8 @@ int submission_proxy_parse_line(struct client *client, const char *line)
        case SUBMISSION_PROXY_EHLO:
        case SUBMISSION_PROXY_TLS_EHLO:
                if (invalid_line || (status / 100) != 2) {
-                       e_error(client->event,
-                               "proxy: Remote returned invalid EHLO line: %s",
+                       e_error(login_proxy_get_event(client->login_proxy),
+                               "Remote returned invalid EHLO line: %s",
                                str_sanitize(line, 160));
                        client_proxy_failed(client, TRUE);
                        return -1;
@@ -335,7 +334,7 @@ int submission_proxy_parse_line(struct client *client, const char *line)
                } else {
                        if ((subm_client->proxy_capability &
                             SMTP_CAPABILITY_STARTTLS) == 0) {
-                               e_error(client->event, "proxy: "
+                               e_error(login_proxy_get_event(client->login_proxy),
                                        "Remote doesn't support STARTTLS");
                                return -1;
                        }
@@ -345,8 +344,8 @@ int submission_proxy_parse_line(struct client *client, const char *line)
                return 0;
        case SUBMISSION_PROXY_STARTTLS:
                if (invalid_line || status != 220) {
-                       e_error(client->event,
-                               "proxy: Remote STARTTLS failed: %s",
+                       e_error(login_proxy_get_event(client->login_proxy),
+                               "Remote STARTTLS failed: %s",
                                str_sanitize(line, 160));
                        client_proxy_failed(client, TRUE);
                        return -1;
@@ -368,8 +367,8 @@ int submission_proxy_parse_line(struct client *client, const char *line)
                return 0;
        case SUBMISSION_PROXY_XCLIENT:
                if (invalid_line || (status / 100) != 2) {
-                       e_error(client->event,
-                               "proxy: Remote XCLIENT failed: %s",
+                       e_error(login_proxy_get_event(client->login_proxy),
+                               "Remote XCLIENT failed: %s",
                                str_sanitize(line, 160));
                        client_proxy_failed(client, TRUE);
                        return -1;