dovecot-2.0: auth: Changed how auth deinitilization works.
dovecot at dovecot.org
dovecot at dovecot.org
Tue Jun 8 21:34:19 EEST 2010
details: http://hg.dovecot.org/dovecot-2.0/rev/190a5278e58b
changeset: 11498:190a5278e58b
user: Timo Sirainen <tss at iki.fi>
date: Tue Jun 08 19:34:14 2010 +0100
description:
auth: Changed how auth deinitilization works.
diffstat:
src/auth/auth-client-connection.c | 18 +++++++--
src/auth/auth-master-connection.c | 22 -----------
src/auth/auth-request-handler.c | 55 +++++++--------------------
src/auth/auth-request-handler.h | 3 +-
src/auth/auth-request.c | 30 ++++++---------
src/auth/auth-request.h | 1 -
src/auth/auth.c | 21 ++++++----
src/auth/auth.h | 7 +---
src/auth/main.c | 24 +++++------
src/auth/passdb.c | 7 +++
src/auth/userdb.c | 7 +++
11 files changed, 81 insertions(+), 114 deletions(-)
diffs (truncated from 514 to 300 lines):
diff -r 94f78f415811 -r 190a5278e58b src/auth/auth-client-connection.c
--- a/src/auth/auth-client-connection.c Tue Jun 08 18:47:24 2010 +0100
+++ b/src/auth/auth-client-connection.c Tue Jun 08 19:34:14 2010 +0100
@@ -319,7 +319,9 @@
return conn;
}
-void auth_client_connection_destroy(struct auth_client_connection **_conn)
+static void
+auth_client_connection_destroy_full(struct auth_client_connection **_conn,
+ bool abort_requests)
{
struct auth_client_connection *conn = *_conn;
struct auth_client_connection *const *clients;
@@ -347,13 +349,21 @@
net_disconnect(conn->fd);
conn->fd = -1;
- if (conn->request_handler != NULL)
- auth_request_handler_destroy(&conn->request_handler);
+ if (conn->request_handler != NULL) {
+ if (abort_requests)
+ auth_request_handler_abort_requests(conn->request_handler);
+ auth_request_handler_unref(&conn->request_handler);
+ }
master_service_client_connection_destroyed(master_service);
auth_client_connection_unref(&conn);
}
+void auth_client_connection_destroy(struct auth_client_connection **_conn)
+{
+ auth_client_connection_destroy_full(_conn, TRUE);
+}
+
static void auth_client_connection_unref(struct auth_client_connection **_conn)
{
struct auth_client_connection *conn = *_conn;
@@ -394,6 +404,6 @@
clients = array_get_modifiable(&auth_client_connections, &count);
for (i = count; i > 0; i--)
- auth_client_connection_destroy(&clients[i-1]);
+ auth_client_connection_destroy_full(&clients[i-1], FALSE);
array_free(&auth_client_connections);
}
diff -r 94f78f415811 -r 190a5278e58b src/auth/auth-master-connection.c
--- a/src/auth/auth-master-connection.c Tue Jun 08 18:47:24 2010 +0100
+++ b/src/auth/auth-master-connection.c Tue Jun 08 19:34:14 2010 +0100
@@ -3,7 +3,6 @@
#include "auth-common.h"
#include "array.h"
#include "hash.h"
-#include "llist.h"
#include "str.h"
#include "strescape.h"
#include "str-sanitize.h"
@@ -27,12 +26,6 @@
#define MAX_INBUF_SIZE 1024
#define MAX_OUTBUF_SIZE (1024*50)
-struct auth_request_list {
- struct auth_request_list *prev, *next;
-
- struct auth_request *auth_request;
-};
-
struct master_userdb_request {
struct auth_master_connection *conn;
unsigned int id;
@@ -123,7 +116,6 @@
const char **error_r)
{
struct auth_request *auth_request;
- struct auth_request_list *request_list;
const char *const *list, *name, *arg;
unsigned int id;
@@ -140,11 +132,6 @@
auth_request->master = conn;
auth_master_connection_ref(conn);
- request_list = p_new(auth_request->pool, struct auth_request_list, 1);
- request_list->auth_request = auth_request;
- DLLIST_PREPEND(&conn->requests, request_list);
- auth_request->context = request_list;
-
if (!auth_request_set_username(auth_request, list[1], error_r)) {
*request_r = auth_request;
return 0;
@@ -165,7 +152,6 @@
if (auth_request->service == NULL) {
i_error("BUG: Master sent %s request without service", cmd);
- DLLIST_REMOVE(&conn->requests, request_list);
auth_request_unref(&auth_request);
auth_master_connection_unref(&conn);
return -1;
@@ -181,7 +167,6 @@
struct auth_request *auth_request)
{
struct auth_master_connection *conn = auth_request->master;
- struct auth_request_list *list = auth_request->context;
struct auth_stream_reply *reply = auth_request->userdb_reply;
string_t *str;
const char *value;
@@ -214,7 +199,6 @@
str_append_c(str, '\n');
(void)o_stream_send(conn->output, str_data(str), str_len(str));
- DLLIST_REMOVE(&conn->requests, list);
auth_request_unref(&auth_request);
auth_master_connection_unref(&conn);
}
@@ -247,7 +231,6 @@
struct auth_request *auth_request)
{
struct auth_master_connection *conn = auth_request->master;
- struct auth_request_list *list = auth_request->context;
struct auth_stream_reply *reply = auth_request->extra_fields;
string_t *str;
@@ -276,7 +259,6 @@
str_append_c(str, '\n');
(void)o_stream_send(conn->output, str_data(str), str_len(str));
- DLLIST_REMOVE(&conn->requests, list);
auth_request_unref(&auth_request);
auth_master_connection_unref(&conn);
}
@@ -532,7 +514,6 @@
{
struct auth_master_connection *conn = *_conn;
struct auth_master_connection *const *masters;
- struct auth_request_list *list;
unsigned int idx;
*_conn = NULL;
@@ -540,9 +521,6 @@
return;
conn->destroyed = TRUE;
- for (list = conn->requests; list != NULL; list = list->next)
- list->auth_request->destroyed = TRUE;
-
array_foreach(&auth_master_connections, masters) {
if (*masters == conn) {
idx = array_foreach_idx(&auth_master_connections,
diff -r 94f78f415811 -r 190a5278e58b src/auth/auth-request-handler.c
--- a/src/auth/auth-request-handler.c Tue Jun 08 18:47:24 2010 +0100
+++ b/src/auth/auth-request-handler.c Tue Jun 08 19:34:14 2010 +0100
@@ -29,8 +29,6 @@
void *context;
auth_request_callback_t *master_callback;
-
- unsigned int destroyed:1;
};
static ARRAY_DEFINE(auth_failures_arr, struct auth_request *);
@@ -59,36 +57,7 @@
return handler;
}
-static void auth_request_handler_unref(struct auth_request_handler **_handler)
-{
- struct auth_request_handler *handler = *_handler;
- struct hash_iterate_context *iter;
- void *key, *value;
-
- *_handler = NULL;
- i_assert(handler->refcount > 0);
- if (--handler->refcount > 0)
- return;
-
- iter = hash_table_iterate_init(handler->requests);
- while (hash_table_iterate(iter, &key, &value)) {
- struct auth_request *auth_request = value;
-
- auth_request->destroyed = TRUE;
- auth_request_unref(&auth_request);
- }
- hash_table_iterate_deinit(&iter);
- hash_table_clear(handler->requests, TRUE);
-
- /* notify parent that we're done with all requests */
- handler->callback(NULL, handler->context);
-
- hash_table_destroy(&handler->requests);
- pool_unref(&handler->pool);
-}
-
-static void
-auth_request_handler_destroy_requests(struct auth_request_handler *handler)
+void auth_request_handler_abort_requests(struct auth_request_handler *handler)
{
struct hash_iterate_context *iter;
void *key, *value;
@@ -97,22 +66,29 @@
while (hash_table_iterate(iter, &key, &value)) {
struct auth_request *auth_request = value;
- auth_request->destroyed = TRUE;
+ auth_request_unref(&auth_request);
}
hash_table_iterate_deinit(&iter);
+ hash_table_clear(handler->requests, TRUE);
}
-void auth_request_handler_destroy(struct auth_request_handler **_handler)
+void auth_request_handler_unref(struct auth_request_handler **_handler)
{
struct auth_request_handler *handler = *_handler;
*_handler = NULL;
- i_assert(!handler->destroyed);
+ i_assert(handler->refcount > 0);
+ if (--handler->refcount > 0)
+ return;
- handler->destroyed = TRUE;
- auth_request_handler_destroy_requests(handler);
- auth_request_handler_unref(&handler);
+ i_assert(hash_table_count(handler->requests) == 0);
+
+ /* notify parent that we're done with all requests */
+ handler->callback(NULL, handler->context);
+
+ hash_table_destroy(&handler->requests);
+ pool_unref(&handler->pool);
}
void auth_request_handler_set(struct auth_request_handler *handler,
@@ -198,8 +174,7 @@
auth_request_handler_remove(handler, request);
if (request->no_failure_delay) {
- /* passdb specifically requested not to delay the
- reply. */
+ /* passdb specifically requested not to delay the reply. */
handler->callback(reply, handler->context);
auth_request_unref(&request);
return;
diff -r 94f78f415811 -r 190a5278e58b src/auth/auth-request-handler.h
--- a/src/auth/auth-request-handler.h Tue Jun 08 18:47:24 2010 +0100
+++ b/src/auth/auth-request-handler.h Tue Jun 08 19:34:14 2010 +0100
@@ -29,7 +29,8 @@
(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);
void auth_request_handler_set(struct auth_request_handler *handler,
unsigned int connect_uid,
diff -r 94f78f415811 -r 190a5278e58b src/auth/auth-request.c
--- a/src/auth/auth-request.c Tue Jun 08 18:47:24 2010 +0100
+++ b/src/auth/auth-request.c Tue Jun 08 19:34:14 2010 +0100
@@ -389,13 +389,6 @@
strlen(request->passdb_password));
}
- if (request->destroyed) {
- /* the passdb may have been freed already. this request won't
- be sent anywhere anyway, so just fail it immediately. */
- *result = PASSDB_RESULT_INTERNAL_FAILURE;
- return TRUE;
- }
-
if (request->passdb->set->deny &&
*result != PASSDB_RESULT_USER_UNKNOWN) {
/* deny passdb. we can get through this step only if the
@@ -559,9 +552,14 @@
auth_request_set_state(request, AUTH_REQUEST_STATE_PASSDB);
request->credentials_scheme = NULL;
- if (passdb->blocking)
+ if (passdb->iface.verify_plain == NULL) {
+ /* we're deinitializing and just want to get rid of this
+ request */
+ auth_request_verify_plain_callback(
+ PASSDB_RESULT_INTERNAL_FAILURE, request);
+ } else if (passdb->blocking) {
passdb_blocking_verify_plain(request);
- else {
+ } else if (passdb->iface.verify_plain != NULL) {
passdb->iface.verify_plain(request, password,
auth_request_verify_plain_callback);
}
@@ -741,14 +739,6 @@
{
struct userdb_module *userdb = request->userdb->userdb;
- if (request->destroyed) {
- /* the userdb may have been freed already. this request won't
- be sent anywhere anyway, so just fail it immediately. */
- request->private_callback.
- userdb(USERDB_RESULT_INTERNAL_FAILURE, request);
More information about the dovecot-cvs
mailing list