Skip to content

Commit

Permalink
lib-imap-client: centralize authentication failed error logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Josef 'Jeff' Sipek authored and sirainen committed Feb 17, 2017
1 parent 992657a commit 934dc5b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
26 changes: 14 additions & 12 deletions src/lib-imap-client/imapc-connection.c
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down
1 change: 0 additions & 1 deletion src/lib-storage/index/imapc/imapc-storage.c
Expand Up @@ -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) {
Expand Down

0 comments on commit 934dc5b

Please sign in to comment.