]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
auth: Don't assert-crash if a request still succeeds after its client connection...
authorTimo Sirainen <tss@iki.fi>
Thu, 30 Sep 2010 16:49:17 +0000 (17:49 +0100)
committerTimo Sirainen <tss@iki.fi>
Thu, 30 Sep 2010 16:49:17 +0000 (17:49 +0100)
src/auth/auth-client-connection.c
src/auth/auth-request-handler.c
src/auth/auth-request-handler.h

index 6ac0b56918be140187707e2486620c3f07d21bf4..0fd46697fba8869e03298cb55f438b879b43b303 100644 (file)
@@ -352,7 +352,7 @@ auth_client_connection_destroy_full(struct auth_client_connection **_conn,
        if (conn->request_handler != NULL) {
                if (abort_requests)
                        auth_request_handler_abort_requests(conn->request_handler);
-               auth_request_handler_unref(&conn->request_handler);
+               auth_request_handler_destroy(&conn->request_handler);
        }
 
         master_service_client_connection_destroyed(master_service);
index c3d5cb0b7ca61d24d8b448df951933b9d5c769a7..1354970b8e5332b270df81d1651f1c357dd3b0a0 100644 (file)
@@ -29,6 +29,8 @@ struct auth_request_handler {
        void *context;
 
        auth_request_callback_t *master_callback;
+
+       unsigned int destroyed:1;
 };
 
 static ARRAY_DEFINE(auth_failures_arr, struct auth_request *);
@@ -103,6 +105,18 @@ void auth_request_handler_unref(struct auth_request_handler **_handler)
        pool_unref(&handler->pool);
 }
 
+void auth_request_handler_destroy(struct auth_request_handler **_handler)
+{
+       struct auth_request_handler *handler = *_handler;
+
+       *_handler = NULL;
+
+       i_assert(!handler->destroyed);
+
+       handler->destroyed = TRUE;
+       auth_request_handler_unref(&handler);
+}
+
 void auth_request_handler_set(struct auth_request_handler *handler,
                              unsigned int connect_uid,
                              unsigned int client_pid)
@@ -225,6 +239,13 @@ void auth_request_handler_reply(struct auth_request *request,
        struct auth_stream_reply *reply;
        string_t *str;
 
+       if (handler->destroyed) {
+               /* the client connection was already closed. we can't do
+                  anything but abort this request */
+               request->internal_failure = TRUE;
+               result = AUTH_CLIENT_RESULT_FAILURE;
+       }
+
        reply = auth_stream_reply_init(pool_datastack_create());
        switch (result) {
        case AUTH_CLIENT_RESULT_CONTINUE:
@@ -365,10 +386,12 @@ bool auth_request_handler_auth_begin(struct auth_request_handler *handler,
        unsigned int id;
        buffer_t *buf;
 
+       i_assert(!handler->destroyed);
+
        /* <id> <mechanism> [...] */
        list = t_strsplit(args, "\t");
        if (list[0] == NULL || list[1] == NULL ||
-\v          str_to_uint(list[0], &id) < 0) {
+           str_to_uint(list[0], &id) < 0) {
                i_error("BUG: Authentication client %u "
                        "sent broken AUTH request", handler->client_pid);
                return FALSE;
index e9bc847fa6660175da7d4a0b35ffcbbd2d785901..2d751efb1f85bbfb646349e2ae4b15a93d9c9d76 100644 (file)
@@ -29,6 +29,7 @@ auth_request_handler_create(auth_request_callback_t *callback, void *context,
                (auth_request_callback_t *)callback, context, \
                master_callback)
 #endif
+void auth_request_handler_destroy(struct auth_request_handler **handler);
 void auth_request_handler_unref(struct auth_request_handler **handler);
 void auth_request_handler_abort_requests(struct auth_request_handler *handler);