]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-imap-client: centralize authentication failed error logging
authorJosef 'Jeff' Sipek <jeff.sipek@dovecot.fi>
Tue, 14 Feb 2017 13:58:10 +0000 (08:58 -0500)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 17 Feb 2017 09:32:32 +0000 (11:32 +0200)
src/lib-imap-client/imapc-connection.c
src/lib-storage/index/imapc/imapc-storage.c

index 6ba738968ff157c96d0a2491aba1a81dad754b52..67486566fb23801e8dd2bdcd5222a4a4d190a723 100644 (file)
@@ -141,6 +141,13 @@ static int imapc_connection_ssl_init(struct imapc_connection *conn);
 static void imapc_command_free(struct imapc_command *cmd);
 static void imapc_command_send_more(struct imapc_connection *conn);
 
+static void
+imapc_auth_failed(struct imapc_connection *conn,
+                 const char *error)
+{
+       i_error("imapc(%s): Authentication failed: %s", conn->name, error);
+}
+
 struct imapc_connection *
 imapc_connection_init(struct imapc_client *client)
 {
@@ -764,12 +771,9 @@ imapc_connection_auth_finish(struct imapc_connection *conn,
                             const struct imapc_command_reply *reply)
 {
        if (reply->state != IMAPC_COMMAND_STATE_OK) {
+               imapc_auth_failed(conn, reply->text_full);
                if (conn->login_callback != NULL)
                        imapc_login_callback(conn, reply);
-               else {
-                       i_error("imapc(%s): Authentication failed: %s",
-                               conn->name, reply->text_full);
-               }
                imapc_connection_disconnect(conn);
                return;
        }
@@ -832,15 +836,14 @@ imapc_connection_authenticate_cb(const struct imapc_command_reply *reply,
        buf = buffer_create_dynamic(pool_datastack_create(),
                                    MAX_BASE64_DECODED_SIZE(input_len));
        if (base64_decode(reply->text_full, input_len, NULL, buf) < 0) {
-               i_error("imapc(%s): Authentication failed: Server sent non-base64 input for AUTHENTICATE: %s",
-                       conn->name, reply->text_full);
+               imapc_auth_failed(conn,
+                                 t_strdup_printf("Server sent non-base64 input for AUTHENTICATE: %s",
+                                                 error));
        } else if (dsasl_client_input(conn->sasl_client, buf->data, buf->used, &error) < 0) {
-               i_error("imapc(%s): Authentication failed: %s",
-                       conn->name, error);
+               imapc_auth_failed(conn, error);
        } else if (dsasl_client_output(conn->sasl_client, &sasl_output,
                                       &sasl_output_len, &error) < 0) {
-               i_error("imapc(%s): Authentication failed: %s",
-                       conn->name, error);
+               imapc_auth_failed(conn, error);
        } else {
                string_t *imap_output =
                        t_str_new(MAX_BASE64_ENCODED_SIZE(sasl_output_len)+2);
@@ -912,8 +915,7 @@ static void imapc_connection_authenticate(struct imapc_connection *conn)
 
        if (set->sasl_mechanisms != NULL && set->sasl_mechanisms[0] != '\0') {
                if (imapc_connection_get_sasl_mech(conn, &sasl_mech, &error) < 0) {
-                       i_error("imapc(%s): Authentication failed: %s",
-                               conn->name, error);
+                       imapc_auth_failed(conn, error);
                        imapc_connection_disconnect(conn);
                        return;
                }
index 67bd5c50b8e0183d9a42cc3f46398716db9c3988..b916bc4440bb9c8ff78e4347dce4c5d414a2ff18 100644 (file)
@@ -230,7 +230,6 @@ imapc_storage_client_login(const struct imapc_command_reply *reply,
                return;
        }
 
-       i_error("imapc: Authentication failed: %s", reply->text_full);
        client->auth_failed = TRUE;
 
        if (client->_storage != NULL) {