Mercurial > dovecot > core-2.2
diff src/lib-master/master-login-auth.c @ 12405:e72ab743b8df
lib-master: Don't wait for handshake before sending auth-master request.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Tue, 09 Nov 2010 19:48:47 +0000 |
parents | 9f179255b796 |
children | aec1f1614028 |
line wrap: on
line diff
--- a/src/lib-master/master-login-auth.c Tue Nov 09 18:36:37 2010 +0000 +++ b/src/lib-master/master-login-auth.c Tue Nov 09 19:48:47 2010 +0000 @@ -31,6 +31,8 @@ master_login_auth_request_callback_t *callback; void *context; + + unsigned int aborted:1; }; struct master_login_auth { @@ -56,7 +58,7 @@ }; static void master_login_auth_set_timeout(struct master_login_auth *auth); -static void master_login_auth_send_all_requests(struct master_login_auth *auth); +static void master_login_auth_check_spids(struct master_login_auth *auth); struct master_login_auth *master_login_auth_init(const char *auth_socket_path) { @@ -195,6 +197,12 @@ return NULL; } master_login_auth_request_remove(auth, request); + if (request->aborted) { + request->callback(NULL, MASTER_AUTH_ERRMSG_INTERNAL_FAILURE, + request->context); + i_free(request); + return NULL; + } return request; } @@ -325,7 +333,7 @@ return; } auth->spid_received = TRUE; - master_login_auth_send_all_requests(auth); + master_login_auth_check_spids(auth); } auth->refcount++; @@ -367,19 +375,38 @@ return 0; } +static bool +auth_request_check_spid(struct master_login_auth *auth, + struct master_login_auth_request *req) +{ + if (auth->auth_server_pid != req->auth_pid && auth->spid_received) { + /* auth server was restarted. don't even attempt a login. */ + i_warning("Auth server restarted (pid %u -> %u), aborting auth", + (unsigned int)req->auth_pid, + (unsigned int)auth->auth_server_pid); + return FALSE; + } + return TRUE; +} + +static void master_login_auth_check_spids(struct master_login_auth *auth) +{ + struct master_login_auth_request *req, *next; + + for (req = auth->request_head; req != NULL; req = next) { + next = req->next; + if (!auth_request_check_spid(auth, req)) + req->aborted = TRUE; + } +} + static void master_login_auth_send_request(struct master_login_auth *auth, struct master_login_auth_request *req) { string_t *str; - i_assert(auth->spid_received); - - if (auth->auth_server_pid != req->auth_pid) { - /* auth server was restarted. don't even attempt a login. */ - i_warning("Auth server restarted (pid %u -> %u), aborting auth", - (unsigned int)req->auth_pid, - (unsigned int)auth->auth_server_pid); + if (!auth_request_check_spid(auth, req)) { master_login_auth_request_remove(auth, req); req->callback(NULL, MASTER_AUTH_ERRMSG_INTERNAL_FAILURE, req->context); @@ -395,16 +422,6 @@ o_stream_send(auth->output, str_data(str), str_len(str)); } -static void master_login_auth_send_all_requests(struct master_login_auth *auth) -{ - struct master_login_auth_request *req, *next; - - for (req = auth->request_head; req != NULL; req = next) { - next = req->next; - master_login_auth_send_request(auth, req); - } -} - void master_login_auth_request(struct master_login_auth *auth, const struct master_auth_request *req, master_login_auth_request_callback_t *callback, @@ -447,8 +464,7 @@ if (auth->to == NULL) master_login_auth_set_timeout(auth); - if (auth->spid_received) - master_login_auth_send_request(auth, login_req); + master_login_auth_send_request(auth, login_req); } unsigned int master_login_auth_request_count(struct master_login_auth *auth)