]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
login processes: Auth code cleanups. Custom IMAP auth errors now have [ALERT] prefix.
authorTimo Sirainen <tss@iki.fi>
Fri, 10 Jul 2009 00:49:34 +0000 (20:49 -0400)
committerTimo Sirainen <tss@iki.fi>
Fri, 10 Jul 2009 00:49:34 +0000 (20:49 -0400)
This should make them visible in more clients.

--HG--
branch : HEAD

src/imap-login/client-authenticate.c
src/imap-login/client.c
src/login-common/sasl-server.c
src/login-common/sasl-server.h
src/pop3-login/client-authenticate.c
src/pop3-login/client.c

index 9b25eb6dbc2f49ee085c1f5a95e7b28c3aef815a..f04f9f9f98aaa025891766189aeec0bd25ab1001 100644 (file)
@@ -67,10 +67,9 @@ static void client_auth_input(struct imap_client *client)
        if (line == NULL)
                return;
 
-       if (strcmp(line, "*") == 0) {
-               sasl_server_auth_client_error(&client->common,
-                                             "Authentication aborted");
-       } else {
+       if (strcmp(line, "*") == 0)
+               sasl_server_auth_abort(&client->common);
+       else {
                client_set_auth_waiting(client);
                auth_client_request_continue(client->common.auth_request, line);
                io_remove(&client->io);
@@ -223,7 +222,7 @@ static bool client_handle_args(struct imap_client *client,
                   allowed to log in. Shouldn't probably happen. */
                reply = t_str_new(128);
                if (reason != NULL)
-                       str_printfa(reply, "NO %s", reason);
+                       str_printfa(reply, "NO [ALERT] %s", reason);
                else if (temp) {
                        str_append(reply, "NO ["IMAP_RESP_CODE_UNAVAILABLE"] "
                                   AUTH_TEMP_FAILED_MSG);
@@ -255,7 +254,7 @@ static void sasl_callback(struct client *_client, enum sasl_server_reply reply,
        bool nodelay;
 
        i_assert(!client->destroyed ||
-                reply == SASL_SERVER_REPLY_CLIENT_ERROR ||
+                reply == SASL_SERVER_REPLY_AUTH_ABORTED ||
                 reply == SASL_SERVER_REPLY_MASTER_FAILED);
 
        switch (reply) {
@@ -269,7 +268,7 @@ static void sasl_callback(struct client *_client, enum sasl_server_reply reply,
                client_destroy_success(client, "Login");
                break;
        case SASL_SERVER_REPLY_AUTH_FAILED:
-       case SASL_SERVER_REPLY_CLIENT_ERROR:
+       case SASL_SERVER_REPLY_AUTH_ABORTED:
                if (client->to_auth_waiting != NULL)
                        timeout_remove(&client->to_auth_waiting);
                if (args != NULL) {
@@ -277,9 +276,12 @@ static void sasl_callback(struct client *_client, enum sasl_server_reply reply,
                                break;
                }
 
-               msg = reply == SASL_SERVER_REPLY_AUTH_FAILED ? "NO " : "BAD ";
-               msg = t_strconcat(msg, data != NULL ? data :
-                                 IMAP_AUTH_FAILED_MSG, NULL);
+               if (reply == SASL_SERVER_REPLY_AUTH_ABORTED)
+                       msg = "BAD Authentication aborted by client.";
+               else if (data == NULL)
+                       msg = "NO "IMAP_AUTH_FAILED_MSG;
+               else
+                       msg = t_strconcat("NO [ALERT] ", data, NULL);
                client_send_tagline(client, msg);
 
                if (!client->destroyed)
index 1edd135f13e614849341eebff9453a1f2815c022..0aebede1004d8dda1bb1314a2340e3387c23bd63 100644 (file)
@@ -583,7 +583,7 @@ void client_destroy(struct imap_client *client, const char *reason)
                                          client->common.master_tag);
        } else if (client->common.auth_request != NULL) {
                i_assert(client->common.authenticating);
-               sasl_server_auth_client_error(&client->common, NULL);
+               sasl_server_auth_abort(&client->common);
        } else {
                i_assert(!client->common.authenticating);
        }
index bed8f46ad1b69dc0efa0030404f9929fff53f7a7..bd98bd76a4e92c59dfb627dee0cf7be225111380 100644 (file)
@@ -273,7 +273,7 @@ void sasl_server_auth_failed(struct client *client, const char *reason)
        sasl_server_auth_cancel(client, reason, SASL_SERVER_REPLY_AUTH_FAILED);
 }
 
-void sasl_server_auth_client_error(struct client *client, const char *reason)
+void sasl_server_auth_abort(struct client *client)
 {
-       sasl_server_auth_cancel(client, reason, SASL_SERVER_REPLY_CLIENT_ERROR);
+       sasl_server_auth_cancel(client, NULL, SASL_SERVER_REPLY_AUTH_ABORTED);
 }
index 3999d463d03a2fcbe1104a73bb702d6c75f5a9b8..99214894aa4d41ae3201048574e02fadb1b914bf 100644 (file)
@@ -6,7 +6,7 @@ struct client;
 enum sasl_server_reply {
        SASL_SERVER_REPLY_SUCCESS,
        SASL_SERVER_REPLY_AUTH_FAILED,
-       SASL_SERVER_REPLY_CLIENT_ERROR,
+       SASL_SERVER_REPLY_AUTH_ABORTED,
        SASL_SERVER_REPLY_MASTER_FAILED,
        SASL_SERVER_REPLY_CONTINUE
 };
@@ -20,6 +20,6 @@ void sasl_server_auth_begin(struct client *client,
                            const char *initial_resp_base64,
                            sasl_server_callback_t *callback);
 void sasl_server_auth_failed(struct client *client, const char *reason);
-void sasl_server_auth_client_error(struct client *client, const char *reason);
+void sasl_server_auth_abort(struct client *client);
 
 #endif
index 5f283167029e3500adcad9239c449a45456bc0a3..f8b4a2980c281573a802b9344224e0b51426163e 100644 (file)
@@ -73,10 +73,9 @@ static void client_auth_input(struct pop3_client *client)
        if (line == NULL)
                return;
 
-       if (strcmp(line, "*") == 0) {
-               sasl_server_auth_client_error(&client->common,
-                                             "Authentication aborted");
-       } else {
+       if (strcmp(line, "*") == 0)
+               sasl_server_auth_abort(&client->common);
+       else {
                auth_client_request_continue(client->common.auth_request, line);
                io_remove(&client->io);
 
@@ -217,7 +216,7 @@ static void sasl_callback(struct client *_client, enum sasl_server_reply reply,
        bool nodelay;
 
        i_assert(!client->destroyed ||
-                reply == SASL_SERVER_REPLY_CLIENT_ERROR ||
+                reply == SASL_SERVER_REPLY_AUTH_ABORTED ||
                 reply == SASL_SERVER_REPLY_MASTER_FAILED);
 
        switch (reply) {
@@ -230,14 +229,18 @@ static void sasl_callback(struct client *_client, enum sasl_server_reply reply,
                client_destroy_success(client, "Login");
                break;
        case SASL_SERVER_REPLY_AUTH_FAILED:
-       case SASL_SERVER_REPLY_CLIENT_ERROR:
+       case SASL_SERVER_REPLY_AUTH_ABORTED:
                if (args != NULL) {
                        if (client_handle_args(client, args, FALSE, &nodelay))
                                break;
                }
 
-               msg = t_strconcat("-ERR ", data != NULL ?
-                                 data : AUTH_FAILED_MSG, NULL);
+               if (reply == SASL_SERVER_REPLY_AUTH_ABORTED)
+                       msg = "-ERR Authentication aborted by client.";
+               else if (data == NULL)
+                       msg = "-ERR "AUTH_FAILED_MSG;
+               else
+                       msg = t_strconcat("-ERR ", data, NULL);
                client_send_line(client, msg);
 
                if (!client->destroyed)
index 30e26ca39efb068e9f9d3acfdebaf8be5d729df0..5c1922b1d4a55c2ef590bcac6185c4df7977cb8a 100644 (file)
@@ -384,7 +384,7 @@ void client_destroy(struct pop3_client *client, const char *reason)
                                          client->common.master_tag);
        } else if (client->common.auth_request != NULL) {
                i_assert(client->common.authenticating);
-               sasl_server_auth_client_error(&client->common, NULL);
+               sasl_server_auth_abort(&client->common);
        } else {
                i_assert(!client->common.authenticating);
        }