]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Log clearly with "auth failed, # attempts" if user gets disconnected before
authorTimo Sirainen <tss@iki.fi>
Wed, 26 Mar 2008 19:30:15 +0000 (21:30 +0200)
committerTimo Sirainen <tss@iki.fi>
Wed, 26 Mar 2008 19:30:15 +0000 (21:30 +0200)
logging in.

--HG--
branch : HEAD

src/imap-login/client-authenticate.c
src/imap-login/client.c
src/imap-login/client.h
src/imap-login/imap-proxy.c
src/pop3-login/client-authenticate.c
src/pop3-login/client.c
src/pop3-login/client.h
src/pop3-login/pop3-proxy.c

index f1a458b01e74baacc9eab5f7dffa41c31950dda5..461c2b59bd376aed0e229696731893a4ad2910dd 100644 (file)
@@ -156,7 +156,7 @@ static bool client_handle_args(struct imap_client *client,
                }
                client_send_tagline(client, str_c(reply));
                if (!nologin) {
-                       client_destroy(client, "Login with referral");
+                       client_destroy_success(client, "Login with referral");
                        return TRUE;
                }
        } else if (nologin || proxy_self) {
@@ -209,7 +209,7 @@ static void sasl_callback(struct client *_client, enum sasl_server_reply reply,
                }
 
                client_send_tagline(client, "OK Logged in.");
-               client_destroy(client, "Login");
+               client_destroy_success(client, "Login");
                break;
        case SASL_SERVER_REPLY_AUTH_FAILED:
        case SASL_SERVER_REPLY_CLIENT_ERROR:
@@ -234,7 +234,9 @@ static void sasl_callback(struct client *_client, enum sasl_server_reply reply,
                else {
                        client_send_tagline(client,
                                            t_strconcat("NO ", data, NULL));
-                       client_destroy(client, data);
+                       /* authentication itself succeeded, we just hit some
+                          internal failure. */
+                       client_destroy_success(client, data);
                }
                break;
        case SASL_SERVER_REPLY_CONTINUE:
index e0dd63894db0628d4b003df9b0669c6bfa9803ee..3bf830c5851c9175ca26047517c26f972fc68052 100644 (file)
@@ -211,9 +211,7 @@ static int cmd_logout(struct imap_client *client)
                client_destroy(client, "Aborted login "
                        "(tried to use disabled plaintext authentication)");
        } else {
-               client_destroy(client, t_strdup_printf(
-                       "Aborted login (%u authentication attempts)",
-                       client->common.auth_attempts));
+               client_destroy(client, "Aborted login");
        }
        return 1;
 }
@@ -284,8 +282,8 @@ static bool client_handle_input(struct imap_client *client)
                if (fatal) {
                        client_send_line(client, t_strconcat("* BYE ",
                                                             msg, NULL));
-                       client_destroy(client, t_strconcat("Disconnected: ",
-                                                          msg, NULL));
+                       client_destroy(client,
+                               t_strconcat("Disconnected: ", msg, NULL));
                        return FALSE;
                }
 
@@ -311,8 +309,8 @@ static bool client_handle_input(struct imap_client *client)
                if (++client->bad_counter >= CLIENT_MAX_BAD_COMMANDS) {
                        client_send_line(client,
                                "* BYE Too many invalid IMAP commands.");
-                       client_destroy(client, "Disconnected: "
-                                      "Too many invalid commands");
+                       client_destroy(client,
+                               "Disconnected: Too many invalid commands");
                        return FALSE;
                }  
                client_send_tagline(client,
@@ -486,6 +484,10 @@ void client_destroy(struct imap_client *client, const char *reason)
                return;
        client->destroyed = TRUE;
 
+       if (!client->login_success && reason != NULL) {
+               reason = t_strdup_printf("%s (auth failed, %u attempts)",
+                                        reason, client->common.auth_attempts);
+       }
        if (reason != NULL)
                client_syslog(&client->common, reason);
 
@@ -543,6 +545,12 @@ void client_destroy(struct imap_client *client, const char *reason)
        main_unref();
 }
 
+void client_destroy_success(struct imap_client *client, const char *reason)
+{
+       client->login_success = TRUE;
+       client_destroy(client, reason);
+}
+
 void client_destroy_internal_failure(struct imap_client *client)
 {
        client_send_line(client, "* BYE Internal login failure. "
index 73e6d0f856655799220c3295749010ff99bafa48..26e3c33ed834b4022e488325c1108d8522c065da 100644 (file)
@@ -24,6 +24,7 @@ struct imap_client {
 
        const char *cmd_tag, *cmd_name;
 
+       unsigned int login_success:1;
        unsigned int cmd_finished:1;
        unsigned int proxy_login_sent:1;
        unsigned int skip_line:1;
@@ -33,6 +34,7 @@ struct imap_client {
 };
 
 void client_destroy(struct imap_client *client, const char *reason);
+void client_destroy_success(struct imap_client *client, const char *reason);
 void client_destroy_internal_failure(struct imap_client *client);
 
 void client_send_line(struct imap_client *client, const char *line);
index 79bd3d3be0aa5d3c01cd036d5c69899b39adf19b..e6b0b63fa76ef11d550865ca552f86cd3d59ca18 100644 (file)
@@ -63,7 +63,7 @@ static int proxy_input_line(struct imap_client *client,
                client->input = NULL;
                client->output = NULL;
                client->common.fd = -1;
-               client_destroy(client, msg);
+               client_destroy_success(client, msg);
                return -1;
        } else if (strncmp(line, "P ", 2) == 0) {
                /* If the backend server isn't Dovecot, the error message may
@@ -117,7 +117,7 @@ static void proxy_input(struct istream *input, struct ostream *output,
 
                /* failed for some reason, probably server disconnected */
                client_send_line(client, "* BYE Temporary login failure.");
-               client_destroy(client, NULL);
+               client_destroy_success(client, NULL);
                return;
        }
 
@@ -132,7 +132,7 @@ static void proxy_input(struct istream *input, struct ostream *output,
                return;
        case -1:
                /* disconnected */
-               client_destroy(client, "Proxy: Remote disconnected");
+               client_destroy_success(client, "Proxy: Remote disconnected");
                return;
        }
 
index f3f3cd653a1eb185279ca715e43d1a98f6fde163..3fc2bd93c87f28ed080da140f52f39f6e9098490 100644 (file)
@@ -170,7 +170,7 @@ static void sasl_callback(struct client *_client, enum sasl_server_reply reply,
                }
 
                client_send_line(client, "+OK Logged in.");
-               client_destroy(client, "Login");
+               client_destroy_success(client, "Login");
                break;
        case SASL_SERVER_REPLY_AUTH_FAILED:
        case SASL_SERVER_REPLY_CLIENT_ERROR:
@@ -197,7 +197,7 @@ static void sasl_callback(struct client *_client, enum sasl_server_reply reply,
                else {
                        client_send_line(client,
                                t_strconcat("-ERR [IN-USE] ", data, NULL));
-                       client_destroy(client, data);
+                       client_destroy_success(client, data);
                }
                break;
        case SASL_SERVER_REPLY_CONTINUE:
index 0fc529e342bc1f48e27e21ea5b6ccde224c8caaf..a2ad08e218c26a689888e2493136ab49e3f6db5f 100644 (file)
@@ -150,9 +150,7 @@ static bool cmd_quit(struct pop3_client *client)
                client_destroy(client, "Aborted login "
                        "(tried to use disabled plaintext authentication)");
        } else {
-               client_destroy(client, t_strdup_printf(
-                       "Aborted login (%u authentication attempts)",
-                       client->common.auth_attempts));
+               client_destroy(client, "Aborted login");
        }
        return TRUE;
 }
@@ -341,12 +339,22 @@ struct client *client_create(int fd, bool ssl, const struct ip_addr *local_ip,
        return &client->common;
 }
 
+void client_destroy_success(struct pop3_client *client, const char *reason)
+{
+       client->login_success = TRUE;
+       client_destroy(client, reason);
+}
+
 void client_destroy(struct pop3_client *client, const char *reason)
 {
        if (client->destroyed)
                return;
        client->destroyed = TRUE;
 
+       if (!client->login_success && reason != NULL) {
+               reason = t_strdup_printf("%s (auth failed, %u attempts)",
+                                        reason, client->common.auth_attempts);
+       }
        if (reason != NULL)
                client_syslog(&client->common, reason);
 
index d688af62e97ba4a0e99ecc8275dad6ababe267cf..34815fab465faa6989ce7d412bc6eb4b465ce739 100644 (file)
@@ -28,12 +28,14 @@ struct pop3_client {
        char *apop_challenge;
        struct auth_connect_id auth_id;
 
+       unsigned int login_success:1;
        unsigned int authenticating:1;
        unsigned int auth_connected:1;
        unsigned int destroyed:1;
 };
 
 void client_destroy(struct pop3_client *client, const char *reason);
+void client_destroy_success(struct pop3_client *client, const char *reason);
 void client_destroy_internal_failure(struct pop3_client *client);
 
 void client_send_line(struct pop3_client *client, const char *line);
index 80cffcbe945ce84a428937af6bffe421d467f8cc..8ca9dcba0669deb0de7b240cf3a93c1a45694b07 100644 (file)
@@ -32,7 +32,7 @@ static void proxy_input(struct istream *input, struct ostream *output,
                /* failed for some reason, probably server disconnected */
                client_send_line(client,
                                 "-ERR [IN-USE] Temporary login failure.");
-               client_destroy(client, NULL);
+               client_destroy_success(client, NULL);
                return;
        }
 
@@ -47,7 +47,7 @@ static void proxy_input(struct istream *input, struct ostream *output,
                return;
        case -1:
                /* disconnected */
-               client_destroy(client, "Proxy: Remote disconnected");
+               client_destroy_success(client, "Proxy: Remote disconnected");
                return;
        }
 
@@ -114,7 +114,7 @@ static void proxy_input(struct istream *input, struct ostream *output,
                client->input = NULL;
                client->output = NULL;
                client->common.fd = -1;
-               client_destroy(client, msg);
+               client_destroy_success(client, msg);
                return;
        }