]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
login: Tell auth process to free aborted auth requests.
authorTimo Sirainen <tss@iki.fi>
Thu, 20 May 2010 11:17:30 +0000 (13:17 +0200)
committerTimo Sirainen <tss@iki.fi>
Thu, 20 May 2010 11:17:30 +0000 (13:17 +0200)
--HG--
branch : HEAD

src/auth/auth-client-connection.c
src/auth/auth-request-handler.c
src/auth/auth-request-handler.h
src/lib-auth/auth-client-request.c
src/lib-auth/auth-client.h
src/login-common/sasl-server.c

index 3790cfff7b0281ee6b1df3643c598edcb9906b31..ee47eda19ec631f8d820bf9b1bf58edb1dd5805b 100644 (file)
@@ -165,6 +165,20 @@ static const char *cont_line_hide_pass(const char *line)
        return t_strconcat(t_strdup_until(line, p), PASSWORD_HIDDEN_STR, NULL);
 }
 
+static bool
+auth_client_cancel(struct auth_client_connection *conn, const char *line)
+{
+       unsigned int client_id;
+
+       if (str_to_uint(line, &client_id) < 0) {
+               i_error("BUG: Authentication client sent broken CANCEL");
+               return FALSE;
+       }
+
+       auth_request_handler_cancel_request(conn->request_handler, client_id);
+       return TRUE;
+}
+
 static bool
 auth_client_handle_line(struct auth_client_connection *conn, const char *line)
 {
@@ -186,6 +200,11 @@ auth_client_handle_line(struct auth_client_connection *conn, const char *line)
                return auth_request_handler_auth_continue(conn->request_handler,
                                                          line + 5);
        }
+       if (strncmp(line, "CANCEL\t", 7) == 0) {
+               if (conn->auth->set->debug)
+                       i_debug("client in: %s", line);
+               return auth_client_cancel(conn, line + 7);
+       }
 
        i_error("BUG: Authentication client sent unknown command: %s",
                str_sanitize(line, 80));
index 09266e516b2811de8aec080475c5cc1f5bfce9c1..99bb7e9a82b89038fbdf0876c30571b7875a1193 100644 (file)
@@ -587,6 +587,16 @@ bool auth_request_handler_master_request(struct auth_request_handler *handler,
        return TRUE;
 }
 
+void auth_request_handler_cancel_request(struct auth_request_handler *handler,
+                                        unsigned int client_id)
+{
+       struct auth_request *request;
+
+       request = hash_table_lookup(handler->requests, POINTER_CAST(client_id));
+       if (request != NULL)
+               auth_request_handler_remove(handler, request);
+}
+
 void auth_request_handler_flush_failures(bool flush_all)
 {
        struct auth_request **auth_requests, *auth_request;
index 4bea9a5b899b333ab0074141b7d51aa5f1454ebf..02f75e6425eafe1f643bfb82ae2dc5f4bb725980 100644 (file)
@@ -37,6 +37,8 @@ bool auth_request_handler_master_request(struct auth_request_handler *handler,
                                         struct auth_master_connection *master,
                                         unsigned int id,
                                         unsigned int client_id);
+void auth_request_handler_cancel_request(struct auth_request_handler *handler,
+                                        unsigned int client_id);
 
 void auth_request_handler_flush_failures(bool flush_all);
 
index 582bd3d6341812ea8f9f2e0e546273e7818b3cd2..cfdd5e772ea32fa391b4ba5ddb79496ebceefeb6 100644 (file)
@@ -115,9 +115,13 @@ void auth_client_request_continue(struct auth_client_request *request,
 void auth_client_request_abort(struct auth_client_request **_request)
 {
        struct auth_client_request *request = *_request;
+       const char *str = t_strdup_printf("CANCEL\t%u\n", request->id);
 
        *_request = NULL;
 
+       if (o_stream_send_str(request->conn->output, str) < 0)
+               i_error("Error sending request to auth server: %m");
+
        request->callback(request, AUTH_REQUEST_STATUS_FAIL, NULL, NULL,
                          request->context);
        request->callback = NULL;
@@ -176,3 +180,11 @@ void auth_client_request_server_input(struct auth_client_request *request,
        if (status != AUTH_REQUEST_STATUS_CONTINUE)
                pool_unref(&request->pool);
 }
+
+void auth_client_send_cancel(struct auth_client *client, unsigned int id)
+{
+       const char *str = t_strdup_printf("CANCEL\t%u\n", id);
+
+       if (o_stream_send_str(client->conn->output, str) < 0)
+               i_error("Error sending request to auth server: %m");
+}
index fc376b2e0007071530025933fff30eacbdabc740..af555c02885f3921a9e24f4675d9e26723672d76 100644 (file)
@@ -91,4 +91,7 @@ auth_client_request_get_server_pid(struct auth_client_request *request);
 /* Return cookie of the server that handled this request. */
 const char *auth_client_request_get_cookie(struct auth_client_request *request);
 
+/* Tell auth process to drop specified request from memory */
+void auth_client_send_cancel(struct auth_client *client, unsigned int id);
+
 #endif
index 2c4c49a23f816db7fba052c45b1fd449bf10df29..456a97dfc6aa77123bc4e4536ce5b8d262e419aa 100644 (file)
@@ -139,6 +139,15 @@ static void master_send_request(struct anvil_request *anvil_request)
                            master_auth_callback, client, &client->master_tag);
 }
 
+static void master_abort_request(struct anvil_request *anvil_request)
+{
+       const char *cookie;
+
+       cookie = binary_to_hex(anvil_request->cookie,
+                              sizeof(anvil_request->cookie));
+       auth_client_send_cancel(auth_client, anvil_request->auth_id);
+}
+
 static void anvil_lookup_callback(const char *reply, void *context)
 {
        struct anvil_request *req = context;
@@ -155,6 +164,7 @@ static void anvil_lookup_callback(const char *reply, void *context)
                                         set->mail_max_userip_connections);
                call_client_callback(client, SASL_SERVER_REPLY_MASTER_FAILED,
                                     errmsg, NULL);
+               master_abort_request(req);
        }
        i_free(req);
 }