[dovecot-cvs] dovecot/src/auth auth-master-connection.c, 1.46, 1.47 auth-master-connection.h, 1.13, 1.14 auth-request-handler.c, 1.22, 1.23 auth.c, 1.32, 1.33 db-ldap.h, 1.28, 1.29 main.c, 1.58, 1.59 userdb-ldap.c, 1.44, 1.45

tss at dovecot.org tss at dovecot.org
Fri Jan 19 15:19:37 UTC 2007


Update of /var/lib/cvs/dovecot/src/auth
In directory talvi:/tmp/cvs-serv27386

Modified Files:
	auth-master-connection.c auth-master-connection.h 
	auth-request-handler.c auth.c db-ldap.h main.c userdb-ldap.c 
Log Message:
Several fixes to handling deinitialization without crashing.



Index: auth-master-connection.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/auth-master-connection.c,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -d -r1.46 -r1.47
--- auth-master-connection.c	15 Dec 2006 18:38:08 -0000	1.46
+++ auth-master-connection.c	19 Jan 2007 15:19:32 -0000	1.47
@@ -229,6 +229,7 @@
 
 	conn = i_new(struct auth_master_connection, 1);
 	conn->listener = listener;
+	conn->refcount = 1;
 	conn->fd = fd;
 	conn->input = i_stream_create_file(fd, default_pool,
 					   MAX_INBUF_SIZE, FALSE);
@@ -267,14 +268,15 @@
 	conn->destroyed = TRUE;
 
 	if (conn->input != NULL)
-		i_stream_destroy(&conn->input);
+		i_stream_close(conn->input);
 	if (conn->output != NULL)
-		o_stream_destroy(&conn->output);
+		o_stream_close(conn->output);
 	if (conn->io != NULL)
 		io_remove(&conn->io);
 	if (conn->fd != -1) {
 		if (close(conn->fd) < 0)
 			i_error("close(): %m");
+		conn->fd = -1;
 	}
 
 	conns = array_get(&conn->listener->masters, &count);
@@ -286,6 +288,31 @@
 	}
 	if (!standalone && auth_master_listeners_masters_left() == 0)
 		io_loop_stop(ioloop);
-       
+
+	auth_master_connection_unref(&conn);
+}
+
+void auth_master_connection_ref(struct auth_master_connection *conn)
+{
+	i_assert(conn->refcount > 0);
+
+	conn->refcount++;
+}
+
+void auth_master_connection_unref(struct auth_master_connection **_conn)
+{
+	struct auth_master_connection *conn = *_conn;
+
+	*_conn = NULL;
+	i_assert(conn->refcount > 0);
+
+	if (--conn->refcount > 0)
+		return;
+
+	if (conn->input != NULL)
+		i_stream_unref(&conn->input);
+	if (conn->output != NULL)
+		o_stream_unref(&conn->output);
+
 	i_free(conn);
 }

Index: auth-master-connection.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/auth-master-connection.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- auth-master-connection.h	14 Jan 2006 18:47:20 -0000	1.13
+++ auth-master-connection.h	19 Jan 2007 15:19:32 -0000	1.14
@@ -3,6 +3,7 @@
 
 struct auth_master_connection {
 	struct auth_master_listener *listener;
+	int refcount;
 
 	int fd;
 	struct istream *input;
@@ -17,6 +18,9 @@
 auth_master_connection_create(struct auth_master_listener *listener, int fd);
 void auth_master_connection_destroy(struct auth_master_connection **conn);
 
+void auth_master_connection_ref(struct auth_master_connection *conn);
+void auth_master_connection_unref(struct auth_master_connection **conn);
+
 void auth_master_connection_send_handshake(struct auth_master_connection *conn);
 void auth_master_connections_send_handshake(void);
 

Index: auth-request-handler.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/auth-request-handler.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- auth-request-handler.c	16 Jan 2007 13:18:23 -0000	1.22
+++ auth-request-handler.c	19 Jan 2007 15:19:32 -0000	1.23
@@ -8,6 +8,7 @@
 #include "str.h"
 #include "str-sanitize.h"
 #include "auth-request.h"
+#include "auth-master-connection.h"
 #include "auth-request-handler.h"
 
 #include <stdlib.h>
@@ -427,6 +428,7 @@
 	}
 	handler->master_callback(str_c(str), request->master);
 
+	auth_master_connection_unref(&request->master);
 	auth_request_unref(&request);
         auth_request_handler_unref(&handler);
 }
@@ -469,7 +471,9 @@
 		request->context = handler;
 		request->master = master;
 
-		/* handler is referenced until userdb_callback is called. */
+		/* master and handler are referenced until userdb_callback i
+		   s called. */
+		auth_master_connection_ref(master);
 		handler->refcount++;
 		auth_request_lookup_user(request, userdb_callback);
 	}
@@ -505,6 +509,7 @@
 
 void auth_request_handler_deinit(void)
 {
+	auth_request_handler_flush_failures();
 	buffer_free(auth_failures_buf);
 	timeout_remove(&to_auth_failures);
 }

Index: auth.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/auth.c,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -d -r1.32 -r1.33
--- auth.c	8 Nov 2006 20:22:08 -0000	1.32
+++ auth.c	19 Jan 2007 15:19:32 -0000	1.33
@@ -280,7 +280,6 @@
 
 	*_auth = NULL;
 
-	passdb_cache_deinit();
 	for (passdb = auth->masterdbs; passdb != NULL; passdb = passdb->next)
 		passdb_deinit(passdb);
 	for (passdb = auth->passdbs; passdb != NULL; passdb = passdb->next)
@@ -288,5 +287,8 @@
 	for (userdb = auth->userdbs; userdb != NULL; userdb = userdb->next)
 		userdb_deinit(userdb);
 
+	auth_request_handler_deinit();
+	passdb_cache_deinit();
+
 	pool_unref(auth->pool);
 }

Index: db-ldap.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/db-ldap.h,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- db-ldap.h	7 Nov 2006 16:16:11 -0000	1.28
+++ db-ldap.h	19 Jan 2007 15:19:32 -0000	1.29
@@ -66,6 +66,7 @@
 
 	unsigned int connected:1;
 	unsigned int connecting:1;
+	unsigned int binding:1;
 	unsigned int retrying:1; /* just reconnected, resending requests */
 	unsigned int last_auth_bind:1;
 };

Index: main.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/main.c,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -d -r1.58 -r1.59
--- main.c	15 Dec 2006 16:55:29 -0000	1.58
+++ main.c	19 Jan 2007 15:19:32 -0000	1.59
@@ -283,7 +283,6 @@
 
         auth_worker_server_deinit();
 	auth_master_listeners_deinit();
-	auth_request_handler_deinit();
 	auth_deinit(&auth);
 	mech_deinit();
 

Index: userdb-ldap.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/userdb-ldap.c,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -d -r1.44 -r1.45
--- userdb-ldap.c	21 Dec 2006 16:01:15 -0000	1.44
+++ userdb-ldap.c	19 Jan 2007 15:19:32 -0000	1.45
@@ -142,12 +142,14 @@
 	enum userdb_result result = USERDB_RESULT_INTERNAL_FAILURE;
 	int ret;
 
-	ret = ldap_result2error(conn->ld, res, 0);
-	if (ret != LDAP_SUCCESS) {
-		auth_request_log_error(auth_request, "ldap",
-			"ldap_search() failed: %s", ldap_err2string(ret));
-		urequest->userdb_callback(result, NULL, auth_request);
-		return;
+	if (res != NULL) {
+		ret = ldap_result2error(conn->ld, res, 0);
+		if (ret != LDAP_SUCCESS) {
+			auth_request_log_error(auth_request, "ldap",
+					       "ldap_search() failed: %s", ldap_err2string(ret));
+			urequest->userdb_callback(result, NULL, auth_request);
+			return;
+		}
 	}
 
 	entry = res == NULL ? NULL : ldap_first_entry(conn->ld, res);



More information about the dovecot-cvs mailing list