[dovecot-cvs] dovecot/src/auth auth-cache.c, 1.16, 1.17 auth-cache.h, 1.5, 1.6 auth-client-connection.c, 1.39, 1.40 auth-client-connection.h, 1.10, 1.11 auth-master-connection.c, 1.39, 1.40 auth-master-connection.h, 1.12, 1.13 auth-master-listener.c, 1.4, 1.5 auth-master-listener.h, 1.2, 1.3 auth-module.c, 1.3, 1.4 auth-module.h, 1.1, 1.2 auth-request-handler.c, 1.10, 1.11 auth-request-handler.h, 1.6, 1.7 auth-request.c, 1.43, 1.44 auth-request.h, 1.21, 1.22 auth-worker-client.c, 1.20, 1.21 auth-worker-client.h, 1.2, 1.3 auth-worker-server.c, 1.6, 1.7 auth.c, 1.23, 1.24 auth.h, 1.16, 1.17 db-ldap.c, 1.36, 1.37 db-ldap.h, 1.19, 1.20 db-passwd-file.c, 1.17, 1.18 db-passwd-file.h, 1.8, 1.9 db-sql.c, 1.3, 1.4 db-sql.h, 1.2, 1.3 main.c, 1.52, 1.53 mech-gssapi.c, 1.3, 1.4 passdb-cache.c, 1.15, 1.16 passdb-checkpassword.c, 1.12, 1.13 passdb-ldap.c, 1.40, 1.41 passdb-pam.c, 1.33, 1.34 passdb-passwd-file.c, 1.23, 1.24 passdb-sql.c, 1.24, 1.25 passdb.c, 1.40, 1.41 password-scheme.c, 1.19, 1.20 userdb-ldap.c, 1.38, 1.39 userdb-passwd-file.c, 1.18, 1.19 userdb-sql.c, 1.12, 1.13 userdb.c, 1.24, 1.25

cras at dovecot.org cras at dovecot.org
Sat Jan 14 20:47:27 EET 2006


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

Modified Files:
	auth-cache.c auth-cache.h auth-client-connection.c 
	auth-client-connection.h auth-master-connection.c 
	auth-master-connection.h auth-master-listener.c 
	auth-master-listener.h auth-module.c auth-module.h 
	auth-request-handler.c auth-request-handler.h auth-request.c 
	auth-request.h auth-worker-client.c auth-worker-client.h 
	auth-worker-server.c auth.c auth.h db-ldap.c db-ldap.h 
	db-passwd-file.c db-passwd-file.h db-sql.c db-sql.h main.c 
	mech-gssapi.c passdb-cache.c passdb-checkpassword.c 
	passdb-ldap.c passdb-pam.c passdb-passwd-file.c passdb-sql.c 
	passdb.c password-scheme.c userdb-ldap.c userdb-passwd-file.c 
	userdb-sql.c userdb.c 
Log Message:
deinit, unref, destroy, close, free, etc. functions now take a pointer to
their data pointer, and set it to NULL. This makes double-frees less likely
to cause security holes.



Index: auth-cache.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/auth-cache.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- auth-cache.c	13 Jan 2006 20:25:57 -0000	1.16
+++ auth-cache.c	14 Jan 2006 18:47:20 -0000	1.17
@@ -52,7 +52,7 @@
 			}
 		}
 	}
-	return str_free_without_data(str);
+	return str_free_without_data(&str);
 }
 
 static void
@@ -133,8 +133,11 @@
 	return cache;
 }
 
-void auth_cache_free(struct auth_cache *cache)
+void auth_cache_free(struct auth_cache **_cache)
 {
+	struct auth_cache *cache = *_cache;
+
+	*_cache = NULL;
 	lib_signals_unset_handler(SIGHUP, sig_auth_cache_clear, cache);
 	lib_signals_unset_handler(SIGUSR2, sig_auth_cache_stats, cache);
 

Index: auth-cache.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/auth-cache.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- auth-cache.h	13 Jan 2006 20:25:57 -0000	1.5
+++ auth-cache.h	14 Jan 2006 18:47:20 -0000	1.6
@@ -12,7 +12,7 @@
    bytes to use for cache (it's not fully exact). ttl_secs specifies time to
    live for cache record, requests older than that are not used. */
 struct auth_cache *auth_cache_new(size_t max_size, unsigned int ttl_secs);
-void auth_cache_free(struct auth_cache *cache);
+void auth_cache_free(struct auth_cache **cache);
 
 /* Clear the cache. */
 void auth_cache_clear(struct auth_cache *cache);

Index: auth-client-connection.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/auth-client-connection.c,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -d -r1.39 -r1.40
--- auth-client-connection.c	13 Jan 2006 20:25:57 -0000	1.39
+++ auth-client-connection.c	14 Jan 2006 18:47:20 -0000	1.40
@@ -18,7 +18,7 @@
 
 #define OUTBUF_THROTTLE_SIZE (1024*50)
 
-static void auth_client_connection_unref(struct auth_client_connection *conn);
+static void auth_client_connection_unref(struct auth_client_connection **_conn);
 
 static void auth_client_input(void *context);
 static void auth_client_send(struct auth_client_connection *conn,
@@ -47,10 +47,8 @@
 	    OUTBUF_THROTTLE_SIZE) {
 		/* stop reading new requests until client has read the pending
 		   replies. */
-		if (conn->io != NULL) {
-			io_remove(conn->io);
-			conn->io = NULL;
-		}
+		if (conn->io != NULL)
+			io_remove(&conn->io);
 	}
 	va_end(args);
 	t_pop();
@@ -62,7 +60,7 @@
 
 	if (reply == NULL) {
 		/* handler destroyed */
-		auth_client_connection_unref(conn);
+		auth_client_connection_unref(&conn);
 		return;
 	}
 
@@ -89,7 +87,7 @@
 		   see if the old connection is still there. */
 		i_assert(old != conn);
 		if (i_stream_read(old->input) == -1) {
-                        auth_client_connection_destroy(old);
+                        auth_client_connection_destroy(&old);
 			old = NULL;
 		}
 	}
@@ -118,7 +116,7 @@
 	struct auth_client_connection *conn = context;
 
 	if (o_stream_flush(conn->output) < 0) {
-		auth_client_connection_destroy(conn);
+		auth_client_connection_destroy(&conn);
 		return 1;
 	}
 
@@ -160,13 +158,13 @@
 		return;
 	case -1:
 		/* disconnected */
-		auth_client_connection_destroy(conn);
+		auth_client_connection_destroy(&conn);
 		return;
 	case -2:
 		/* buffer full */
 		i_error("BUG: Auth client %u sent us more than %d bytes",
 			conn->pid, (int)AUTH_CLIENT_MAX_LINE_LENGTH);
-		auth_client_connection_destroy(conn);
+		auth_client_connection_destroy(&conn);
 		return;
 	}
 
@@ -184,7 +182,7 @@
 				i_error("Authentication client "
 					"not compatible with this server "
 					"(mixed old and new binaries?)");
-				auth_client_connection_destroy(conn);
+				auth_client_connection_destroy(&conn);
 				return;
 			}
 			conn->version_received = TRUE;
@@ -193,7 +191,7 @@
 
 		if (strncmp(line, "CPID\t", 5) == 0) {
 			if (!auth_client_input_cpid(conn, line + 5)) {
-				auth_client_connection_destroy(conn);
+				auth_client_connection_destroy(&conn);
 				return;
 			}
 		}
@@ -207,11 +205,11 @@
 		t_pop();
 
 		if (!ret) {
-			auth_client_connection_destroy(conn);
+			auth_client_connection_destroy(&conn);
 			break;
 		}
 	}
-	auth_client_connection_unref(conn);
+	auth_client_connection_unref(&conn);
 }
 
 struct auth_client_connection *
@@ -250,19 +248,19 @@
 	iov[1].iov_base = str_data(str);
 	iov[1].iov_len = str_len(str);
 
-	if (o_stream_sendv(conn->output, iov, 2) < 0) {
-		auth_client_connection_destroy(conn);
-		conn = NULL;
-	}
+	if (o_stream_sendv(conn->output, iov, 2) < 0)
+		auth_client_connection_destroy(&conn);
 
 	return conn;
 }
 
-void auth_client_connection_destroy(struct auth_client_connection *conn)
+void auth_client_connection_destroy(struct auth_client_connection **_conn)
 {
+        struct auth_client_connection *conn = *_conn;
 	struct auth_client_connection *const *clients;
 	unsigned int i, count;
 
+	*_conn = NULL;
 	if (conn->fd == -1)
 		return;
 
@@ -277,27 +275,28 @@
 	i_stream_close(conn->input);
 	o_stream_close(conn->output);
 
-	if (conn->io != NULL) {
-		io_remove(conn->io);
-		conn->io = NULL;
-	}
+	if (conn->io != NULL)
+		io_remove(&conn->io);
 
 	net_disconnect(conn->fd);
 	conn->fd = -1;
 
 	if (conn->request_handler != NULL)
-		auth_request_handler_unref(conn->request_handler);
+		auth_request_handler_unref(&conn->request_handler);
 
-        auth_client_connection_unref(conn);
+        auth_client_connection_unref(&conn);
 }
 
-static void auth_client_connection_unref(struct auth_client_connection *conn)
+static void auth_client_connection_unref(struct auth_client_connection **_conn)
 {
+        struct auth_client_connection *conn = *_conn;
+
+	*_conn = NULL;
 	if (--conn->refcount > 0)
 		return;
 
-	i_stream_unref(conn->input);
-	o_stream_unref(conn->output);
+	i_stream_unref(&conn->input);
+	o_stream_unref(&conn->output);
 	i_free(conn);
 }
 
@@ -339,8 +338,6 @@
 
 void auth_client_connections_deinit(struct auth_master_listener *listener)
 {
-	if (listener->to_clients != NULL) {
-		timeout_remove(listener->to_clients);
-		listener->to_clients = NULL;
-	}
+	if (listener->to_clients != NULL)
+		timeout_remove(&listener->to_clients);
 }

Index: auth-client-connection.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/auth-client-connection.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- auth-client-connection.h	19 Apr 2005 13:11:12 -0000	1.10
+++ auth-client-connection.h	14 Jan 2006 18:47:20 -0000	1.11
@@ -20,7 +20,7 @@
 
 struct auth_client_connection *
 auth_client_connection_create(struct auth_master_listener *listener, int fd);
-void auth_client_connection_destroy(struct auth_client_connection *conn);
+void auth_client_connection_destroy(struct auth_client_connection **conn);
 
 struct auth_client_connection *
 auth_client_connection_lookup(struct auth_master_listener *listener,

Index: auth-master-connection.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/auth-master-connection.c,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -d -r1.39 -r1.40
--- auth-master-connection.c	13 Jan 2006 20:25:57 -0000	1.39
+++ auth-master-connection.c	14 Jan 2006 18:47:20 -0000	1.40
@@ -97,7 +97,7 @@
 		i_info("master out: %s", str_c(str));
 
 	(void)o_stream_send(conn->output, str_data(str), str_len(str));
-	auth_request_unref(auth_request);
+	auth_request_unref(&auth_request);
 }
 
 static bool
@@ -133,7 +133,7 @@
 
 	if (auth_request->service == NULL) {
 		i_error("BUG: Master sent USER request without service");
-		auth_request_unref(auth_request);
+		auth_request_unref(&auth_request);
 		return FALSE;
 	}
 
@@ -158,13 +158,13 @@
 		return;
 	case -1:
 		/* disconnected */
-                auth_master_connection_destroy(conn);
+                auth_master_connection_destroy(&conn);
 		return;
 	case -2:
 		/* buffer full */
 		i_error("BUG: Master sent us more than %d bytes",
 			(int)MAX_INBUF_SIZE);
-                auth_master_connection_destroy(conn);
+                auth_master_connection_destroy(&conn);
 		return;
 	}
 
@@ -179,7 +179,7 @@
 		    AUTH_MASTER_PROTOCOL_MAJOR_VERSION) {
 			i_error("Master not compatible with this server "
 				"(mixed old and new binaries?)");
-			auth_master_connection_destroy(conn);
+			auth_master_connection_destroy(&conn);
 			return;
 		}
 		conn->version_received = TRUE;
@@ -203,7 +203,7 @@
 		t_pop();
 
 		if (!ret) {
-			auth_master_connection_destroy(conn);
+			auth_master_connection_destroy(&conn);
 			return;
 		}
 	}
@@ -216,7 +216,7 @@
 
 	if ((ret = o_stream_flush(conn->output)) < 0) {
 		/* transmit error, probably master died */
-		auth_master_connection_destroy(conn);
+		auth_master_connection_destroy(&conn);
 		return 1;
 	}
 
@@ -260,11 +260,13 @@
 	(void)o_stream_send_str(conn->output, line);
 }
 
-void auth_master_connection_destroy(struct auth_master_connection *conn)
+void auth_master_connection_destroy(struct auth_master_connection **_conn)
 {
+        struct auth_master_connection *conn = *_conn;
         struct auth_master_connection *const *conns;
 	unsigned int i, count;
 
+	*_conn = NULL;
 	if (conn->destroyed)
 		return;
 	conn->destroyed = TRUE;
@@ -274,11 +276,11 @@
 			i_error("close(): %m");
 	}
 	if (conn->input != NULL)
-		i_stream_unref(conn->input);
+		i_stream_unref(&conn->input);
 	if (conn->output != NULL)
-		o_stream_unref(conn->output);
+		o_stream_unref(&conn->output);
 	if (conn->io != NULL)
-		io_remove(conn->io);
+		io_remove(&conn->io);
 
 	conns = array_get(&conn->listener->masters, &count);
 	for (i = 0; i < count; i++) {

Index: auth-master-connection.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/auth-master-connection.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- auth-master-connection.h	19 Apr 2005 13:11:12 -0000	1.12
+++ auth-master-connection.h	14 Jan 2006 18:47:20 -0000	1.13
@@ -15,7 +15,7 @@
 
 struct auth_master_connection *
 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_destroy(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-master-listener.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/auth-master-listener.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- auth-master-listener.c	13 Jan 2006 20:25:57 -0000	1.4
+++ auth-master-listener.c	14 Jan 2006 18:47:20 -0000	1.5
@@ -51,18 +51,21 @@
 	}
 
 	net_disconnect(socket->fd);
-	io_remove(socket->io);
+	io_remove(&socket->io);
 	i_free(socket);
 }
 
-void auth_master_listener_destroy(struct auth_master_listener *listener)
+void auth_master_listener_destroy(struct auth_master_listener **_listener)
 {
+        struct auth_master_listener *listener = *_listener;
 	struct auth_master_listener *const *listeners;
-	struct auth_master_listener_socket *const *sockets;
-	struct auth_master_connection *const *masters;
-	struct auth_client_connection *const *clients;
+	struct auth_master_listener_socket **sockets;
+	struct auth_master_connection **masters;
+	struct auth_client_connection **clients;
 	unsigned int i, count;
 
+	*_listener = NULL;
+
 	listeners = array_get(&master_listeners, &count);
 	for (i = 0; i < count; i++) {
 		if (listeners[i] == listener) {
@@ -71,17 +74,17 @@
 		}
 	}
 
-	sockets = array_get(&listener->sockets, &count);
+	sockets = array_get_modifyable(&listener->sockets, &count);
 	for (i = count; i > 0; i--)
 		auth_master_listener_socket_free(sockets[i-1]);
 
-	masters = array_get(&listener->masters, &count);
+	masters = array_get_modifyable(&listener->masters, &count);
 	for (i = count; i > 0; i--)
-		auth_master_connection_destroy(masters[i-1]);
+		auth_master_connection_destroy(&masters[i-1]);
 
-	clients = array_get(&listener->clients, &count);
+	clients = array_get_modifyable(&listener->clients, &count);
 	for (i = count; i > 0; i--)
-		auth_client_connection_destroy(clients[i-1]);
+		auth_client_connection_destroy(&clients[i-1]);
 
         auth_client_connections_deinit(listener);
 	array_free(&listener->sockets);
@@ -174,11 +177,11 @@
 
 void auth_master_listeners_deinit(void)
 {
-        struct auth_master_listener *const *listeners;
+        struct auth_master_listener **listeners;
 	unsigned int i, count;
 
-	listeners = array_get(&master_listeners, &count);
+	listeners = array_get_modifyable(&master_listeners, &count);
 	for (i = count; i > 0; i--)
-		auth_master_listener_destroy(listeners[i-1]);
+		auth_master_listener_destroy(&listeners[i-1]);
 	array_free(&master_listeners);
 }

Index: auth-master-listener.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/auth-master-listener.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- auth-master-listener.h	13 Jan 2006 20:25:57 -0000	1.2
+++ auth-master-listener.h	14 Jan 2006 18:47:20 -0000	1.3
@@ -18,7 +18,7 @@
 };
 
 struct auth_master_listener *auth_master_listener_create(struct auth *auth);
-void auth_master_listener_destroy(struct auth_master_listener *listener);
+void auth_master_listener_destroy(struct auth_master_listener **listener);
 
 void auth_master_listener_add(struct auth_master_listener *listener,
 			      int fd, const char *path,

Index: auth-module.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/auth-module.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- auth-module.c	30 May 2003 01:07:31 -0000	1.3
+++ auth-module.c	14 Jan 2006 18:47:20 -0000	1.4
@@ -73,10 +73,12 @@
 	return module;
 }
 
-void auth_module_close(struct auth_module *module)
+void auth_module_close(struct auth_module **_module)
 {
+        struct auth_module *module = *_module;
 	struct auth_module **pos;
 
+	*_module = NULL;
 	if (--module->refcount > 0)
 		return;
 

Index: auth-module.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/auth-module.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- auth-module.h	11 Feb 2003 18:01:39 -0000	1.1
+++ auth-module.h	14 Jan 2006 18:47:20 -0000	1.2
@@ -2,7 +2,7 @@
 #define __AUTH_MODULE_H
 
 struct auth_module *auth_module_open(const char *name);
-void auth_module_close(struct auth_module *module);
+void auth_module_close(struct auth_module **module);
 
 void *auth_module_sym(struct auth_module *module, const char *name);
 

Index: auth-request-handler.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/auth-request-handler.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- auth-request-handler.c	13 Jan 2006 20:25:57 -0000	1.10
+++ auth-request-handler.c	14 Jan 2006 18:47:20 -0000	1.11
@@ -50,11 +50,13 @@
 	return handler;
 }
 
-void auth_request_handler_unref(struct auth_request_handler *handler)
+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;
@@ -83,7 +85,7 @@
 					struct auth_request *request)
 {
 	hash_remove(handler->requests, POINTER_CAST(request->id));
-	auth_request_unref(request);
+	auth_request_unref(&request);
 }
 
 void auth_request_handler_check_timeouts(struct auth_request_handler *handler)
@@ -200,7 +202,7 @@
 			/* passdb specifically requested not to delay the
 			   reply. */
 			handler->callback(str_c(str), handler->context);
-			auth_request_unref(request);
+			auth_request_unref(&request);
 		} else {
 			/* failure. don't announce it immediately to avoid
 			   a) timing attacks, b) flooding */
@@ -213,7 +215,7 @@
 	}
 	/* NOTE: request may be destroyed now */
 
-        auth_request_handler_unref(handler);
+        auth_request_handler_unref(&handler);
 
 	t_pop();
 }
@@ -293,7 +295,7 @@
 		i_error("BUG: Authentication client %u "
 			"didn't specify service in request",
 			handler->client_pid);
-		auth_request_unref(request);
+		auth_request_unref(&request);
 		return FALSE;
 	}
 
@@ -396,8 +398,8 @@
 	}
 	handler->master_callback(str_c(str), request->master);
 
-	auth_request_unref(request);
-        auth_request_handler_unref(handler);
+	auth_request_unref(&request);
+        auth_request_handler_unref(&handler);
 }
 
 void auth_request_handler_master_request(struct auth_request_handler *handler,
@@ -455,7 +457,7 @@
 		i_assert(auth_request[i]->state == AUTH_REQUEST_STATE_FINISHED);
 		auth_request[i]->callback(auth_request[i],
 					  AUTH_CLIENT_RESULT_FAILURE, NULL, 0);
-		auth_request_unref(auth_request[i]);
+		auth_request_unref(&auth_request[i]);
 	}
 	buffer_set_used_size(auth_failures_buf, 0);
 }
@@ -474,5 +476,5 @@
 void auth_request_handler_deinit(void)
 {
 	buffer_free(auth_failures_buf);
-	timeout_remove(to_auth_failures);
+	timeout_remove(&to_auth_failures);
 }

Index: auth-request-handler.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/auth-request-handler.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- auth-request-handler.h	13 Jan 2006 20:25:57 -0000	1.6
+++ auth-request-handler.h	14 Jan 2006 18:47:20 -0000	1.7
@@ -10,7 +10,7 @@
 auth_request_handler_create(struct auth *auth,
 			    auth_request_callback_t *callback, void *context,
 			    auth_request_callback_t *master_callback);
-void auth_request_handler_unref(struct auth_request_handler *handler);
+void auth_request_handler_unref(struct auth_request_handler **handler);
 
 void auth_request_handler_set(struct auth_request_handler *handler,
 			      unsigned int connect_uid,

Index: auth-request.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/auth-request.c,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -d -r1.43 -r1.44
--- auth-request.c	13 Jan 2006 20:25:57 -0000	1.43
+++ auth-request.c	14 Jan 2006 18:47:20 -0000	1.44
@@ -87,17 +87,19 @@
 	request->refcount++;
 }
 
-bool auth_request_unref(struct auth_request *request)
+void auth_request_unref(struct auth_request **_request)
 {
+	struct auth_request *request = *_request;
+
+	*_request = NULL;
 	i_assert(request->refcount > 0);
 	if (--request->refcount > 0)
-		return TRUE;
+		return;
 
 	if (request->mech != NULL)
 		request->mech->auth_free(request);
 	else
 		pool_unref(request->pool);
-	return FALSE;
 }
 
 void auth_request_export(struct auth_request *request, string_t *str)
@@ -317,7 +319,7 @@
 		request->private_callback.verify_plain(result, request);
 		safe_memset(request->mech_password, 0,
 			    strlen(request->mech_password));
-		auth_request_unref(request);
+		auth_request_unref(&request);
 	}
 }
 

Index: auth-request.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/auth-request.h,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- auth-request.h	13 Jan 2006 20:25:57 -0000	1.21
+++ auth-request.h	14 Jan 2006 18:47:20 -0000	1.22
@@ -69,7 +69,7 @@
 		 mech_callback_t *callback, void *context);
 struct auth_request *auth_request_new_dummy(struct auth *auth);
 void auth_request_ref(struct auth_request *request);
-bool auth_request_unref(struct auth_request *request);
+void auth_request_unref(struct auth_request **request);
 
 void auth_request_success(struct auth_request *request,
 			  const void *data, size_t data_size);

Index: auth-worker-client.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/auth-worker-client.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- auth-worker-client.c	13 Jan 2006 20:25:57 -0000	1.20
+++ auth-worker-client.c	14 Jan 2006 18:47:20 -0000	1.21
@@ -36,10 +36,8 @@
 	    OUTBUF_THROTTLE_SIZE) {
 		/* stop reading new requests until client has read the pending
 		   replies. */
-		if (client->io != NULL) {
-			io_remove(client->io);
-			client->io = NULL;
-		}
+		if (client->io != NULL)
+			io_remove(&client->io);
 	}
 }
 
@@ -101,9 +99,9 @@
 	str_append_c(str, '\n');
 	o_stream_send(client->output, str_data(str), str_len(str));
 
-	auth_request_unref(request);
+	auth_request_unref(&request);
 	auth_worker_client_check_throttle(client);
-	auth_worker_client_unref(client);
+	auth_worker_client_unref(&client);
 }
 
 static void
@@ -133,7 +131,7 @@
 
 	if (auth_request->user == NULL || auth_request->service == NULL) {
 		i_error("BUG: PASSV had missing parameters");
-		auth_request_unref(auth_request);
+		auth_request_unref(&auth_request);
 		return;
 	}
 
@@ -141,7 +139,7 @@
 		auth_request->passdb = auth_request->passdb->next;
 		if (auth_request->passdb == NULL) {
 			i_error("BUG: PASSV had invalid passdb num");
-			auth_request_unref(auth_request);
+			auth_request_unref(&auth_request);
 			return;
 		}
 	}
@@ -175,9 +173,9 @@
 	str_append_c(str, '\n');
 	o_stream_send(client->output, str_data(str), str_len(str));
 
-	auth_request_unref(request);
+	auth_request_unref(&request);
 	auth_worker_client_check_throttle(client);
-	auth_worker_client_unref(client);
+	auth_worker_client_unref(&client);
 }
 
 static void
@@ -209,7 +207,7 @@
 
 	if (auth_request->user == NULL || auth_request->service == NULL) {
 		i_error("BUG: PASSL had missing parameters");
-		auth_request_unref(auth_request);
+		auth_request_unref(&auth_request);
 		return;
 	}
 
@@ -217,7 +215,7 @@
 		auth_request->passdb = auth_request->passdb->next;
 		if (auth_request->passdb == NULL) {
 			i_error("BUG: PASSL had invalid passdb num");
-			auth_request_unref(auth_request);
+			auth_request_unref(&auth_request);
 			return;
 		}
 	}
@@ -241,9 +239,9 @@
 
 	o_stream_send(client->output, str_data(str), str_len(str));
 
-	auth_request_unref(auth_request);
+	auth_request_unref(&auth_request);
 	auth_worker_client_check_throttle(client);
-	auth_worker_client_unref(client);
+	auth_worker_client_unref(&client);
 }
 
 static void
@@ -262,7 +260,7 @@
 
 	if (auth_request->user == NULL || auth_request->service == NULL) {
 		i_error("BUG: USER had missing parameters");
-		auth_request_unref(auth_request);
+		auth_request_unref(&auth_request);
 		return;
 	}
 
@@ -270,7 +268,7 @@
 		auth_request->userdb = auth_request->userdb->next;
 		if (auth_request->userdb == NULL) {
 			i_error("BUG: USER had invalid userdb num");
-			auth_request_unref(auth_request);
+			auth_request_unref(&auth_request);
 			return;
 		}
 	}
@@ -313,13 +311,13 @@
 		return;
 	case -1:
 		/* disconnected */
-		auth_worker_client_destroy(client);
+		auth_worker_client_destroy(&client);
 		return;
 	case -2:
 		/* buffer full */
 		i_error("BUG: Auth worker server sent us more than %d bytes",
 			(int)AUTH_WORKER_MAX_LINE_LENGTH);
-		auth_worker_client_destroy(client);
+		auth_worker_client_destroy(&client);
 		return;
 	}
 
@@ -332,11 +330,11 @@
 		t_pop();
 
 		if (!ret) {
-			auth_worker_client_destroy(client);
+			auth_worker_client_destroy(&client);
 			break;
 		}
 	}
-	auth_worker_client_unref(client);
+	auth_worker_client_unref(&client);
 }
 
 static int auth_worker_output(void *context)
@@ -344,7 +342,7 @@
 	struct auth_worker_client *client = context;
 
 	if (o_stream_flush(client->output) < 0) {
-		auth_worker_client_destroy(client);
+		auth_worker_client_destroy(&client);
 		return 1;
 	}
 
@@ -362,7 +360,7 @@
 	struct auth_worker_client *client = context;
 
 	if (client->last_request + AUTH_WORKER_MAX_IDLE <= ioloop_time)
-                auth_worker_client_destroy(client);
+                auth_worker_client_destroy(&client);
 }
 
 struct auth_worker_client *
@@ -389,20 +387,21 @@
 	return client;
 }
 
-void auth_worker_client_destroy(struct auth_worker_client *client)
+void auth_worker_client_destroy(struct auth_worker_client **_client)
 {
+	struct auth_worker_client *client = *_client;
+
+	*_client = NULL;
 	if (client->fd == -1)
 		return;
 
-	timeout_remove(client->to);
+	timeout_remove(&client->to);
 
 	i_stream_close(client->input);
 	o_stream_close(client->output);
 
-	if (client->io != NULL) {
-		io_remove(client->io);
-		client->io = NULL;
-	}
+	if (client->io != NULL)
+		io_remove(&client->io);
 
 	net_disconnect(client->fd);
 	client->fd = -1;
@@ -410,15 +409,19 @@
 	io_loop_stop(ioloop);
 }
 
-void auth_worker_client_unref(struct auth_worker_client *client)
+void auth_worker_client_unref(struct auth_worker_client **_client)
 {
-	if (--client->refcount > 0)
+	struct auth_worker_client *client = *_client;
+
+	if (--client->refcount > 0) {
+		*_client = NULL;
 		return;
+	}
 
 	if (client->fd != -1)
-		auth_worker_client_destroy(client);
+		auth_worker_client_destroy(_client);
 
-	i_stream_unref(client->input);
-	o_stream_unref(client->output);
+	i_stream_unref(&client->input);
+	o_stream_unref(&client->output);
 	i_free(client);
 }

Index: auth-worker-client.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/auth-worker-client.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- auth-worker-client.h	8 Jun 2005 13:37:17 -0000	1.2
+++ auth-worker-client.h	14 Jan 2006 18:47:20 -0000	1.3
@@ -4,7 +4,7 @@
 #define AUTH_WORKER_MAX_LINE_LENGTH 1024
 
 struct auth_worker_client *auth_worker_client_create(struct auth *auth, int fd);
-void auth_worker_client_destroy(struct auth_worker_client *client);
-void auth_worker_client_unref(struct auth_worker_client *client);
+void auth_worker_client_destroy(struct auth_worker_client **client);
+void auth_worker_client_unref(struct auth_worker_client **client);
 
 #endif

Index: auth-worker-server.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/auth-worker-server.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- auth-worker-server.c	14 Aug 2005 20:34:33 -0000	1.6
+++ auth-worker-server.c	14 Jan 2006 18:47:20 -0000	1.7
@@ -121,7 +121,7 @@
 	for (i = 0; i < size; i++) {
 		if (request[i].id != 0) {
 			request[i].callback(request[i].auth_request, reply);
-			auth_request_unref(request[i].auth_request);
+			auth_request_unref(&request[i].auth_request);
 		}
 	}
 
@@ -129,9 +129,9 @@
 		i_error("close(auth worker) failed: %m");
 
 	buffer_free(conn->requests);
-	io_remove(conn->io);
-	i_stream_unref(conn->input);
-	o_stream_unref(conn->output);
+	io_remove(&conn->io);
+	i_stream_unref(&conn->input);
+	o_stream_unref(&conn->output);
 	i_free(conn);
 }
 
@@ -189,7 +189,7 @@
 				       const char *line)
 {
 	request->callback(request->auth_request, line);
-	auth_request_unref(request->auth_request);
+	auth_request_unref(&request->auth_request);
 
 	/* mark the record empty so it can be used for future requests */
 	memset(request, 0, sizeof(*request));
@@ -378,6 +378,6 @@
 	buffer_free(connections);
 	connections = NULL;
 
-	timeout_remove(to);
+	timeout_remove(&to);
 	i_free(worker_socket_path);
 }

Index: auth.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/auth.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- auth.c	13 Jan 2006 20:25:57 -0000	1.23
+++ auth.c	14 Jan 2006 18:47:20 -0000	1.24
@@ -228,11 +228,14 @@
 		getenv("SSL_USERNAME_FROM_CERT") != NULL;
 }
 
-void auth_deinit(struct auth *auth)
+void auth_deinit(struct auth **_auth)
 {
+        struct auth *auth = *_auth;
 	struct auth_passdb *passdb;
 	struct auth_userdb *userdb;
 
+	*_auth = NULL;
+
 	passdb_cache_deinit();
 	for (passdb = auth->passdbs; passdb != NULL; passdb = passdb->next)
 		passdb_deinit(passdb);

Index: auth.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/auth.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- auth.h	13 Jan 2006 20:25:57 -0000	1.16
+++ auth.h	14 Jan 2006 18:47:20 -0000	1.17
@@ -51,6 +51,6 @@
 
 struct auth *auth_preinit(void);
 void auth_init(struct auth *auth);
-void auth_deinit(struct auth *auth);
+void auth_deinit(struct auth **auth);
 
 #endif

Index: db-ldap.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/db-ldap.c,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -d -r1.36 -r1.37
--- db-ldap.c	13 Jan 2006 20:25:57 -0000	1.36
+++ db-ldap.c	14 Jan 2006 18:47:20 -0000	1.37
@@ -298,10 +298,8 @@
 
 	conn->connected = FALSE;
 
-	if (conn->io != NULL) {
-		io_remove(conn->io);
-		conn->io = NULL;
-	}
+	if (conn->io != NULL)
+		io_remove(&conn->io);
 
 	if (conn->ld != NULL) {
 		ldap_unbind(conn->ld);
@@ -453,10 +451,12 @@
 	return conn;
 }
 
-void db_ldap_unref(struct ldap_connection *conn)
+void db_ldap_unref(struct ldap_connection **_conn)
 {
+        struct ldap_connection *conn = *_conn;
 	struct ldap_connection **p;
 
+	*_conn = NULL;
 	i_assert(conn->refcount >= 0);
 	if (--conn->refcount > 0)
 		return;

Index: db-ldap.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/db-ldap.h,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- db-ldap.h	13 Jan 2006 20:25:57 -0000	1.19
+++ db-ldap.h	14 Jan 2006 18:47:20 -0000	1.20
@@ -73,7 +73,7 @@
 		       const char *const default_attr_map[]);
 
 struct ldap_connection *db_ldap_init(const char *config_path);
-void db_ldap_unref(struct ldap_connection *conn);
+void db_ldap_unref(struct ldap_connection **conn);
 
 bool db_ldap_connect(struct ldap_connection *conn);
 

Index: db-passwd-file.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/db-passwd-file.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- db-passwd-file.c	13 Jan 2006 20:25:57 -0000	1.17
+++ db-passwd-file.c	14 Jan 2006 18:47:20 -0000	1.18
@@ -182,7 +182,7 @@
 		}
 		t_pop();
 	}
-	i_stream_unref(input);
+	i_stream_unref(&input);
 	return TRUE;
 }
 
@@ -312,12 +312,14 @@
 	return db;
 }
 
-void db_passwd_file_unref(struct db_passwd_file *db)
+void db_passwd_file_unref(struct db_passwd_file **_db)
 {
+        struct db_passwd_file *db = *_db;
         struct db_passwd_file **p;
 	struct hash_iterate_context *iter;
 	void *key, *value;
 
+	*_db = NULL;
 	i_assert(db->refcount >= 0);
 	if (--db->refcount > 0)
 		return;

Index: db-passwd-file.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/db-passwd-file.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- db-passwd-file.h	13 Jan 2006 20:25:57 -0000	1.8
+++ db-passwd-file.h	14 Jan 2006 18:47:20 -0000	1.9
@@ -43,6 +43,6 @@
 db_passwd_file_lookup(struct db_passwd_file *db, struct auth_request *request);
 
 struct db_passwd_file *db_passwd_file_parse(const char *path, bool userdb);
-void db_passwd_file_unref(struct db_passwd_file *db);
+void db_passwd_file_unref(struct db_passwd_file **db);
 
 #endif

Index: db-sql.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/db-sql.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- db-sql.c	12 Jul 2005 12:58:47 -0000	1.3
+++ db-sql.c	14 Jan 2006 18:47:20 -0000	1.4
@@ -88,12 +88,15 @@
 	return conn;
 }
 
-void db_sql_unref(struct sql_connection *conn)
+void db_sql_unref(struct sql_connection **_conn)
 {
+        struct sql_connection *conn = *_conn;
+
+	*_conn = NULL;
 	if (--conn->refcount > 0)
 		return;
 
-	sql_deinit(conn->db);
+	sql_deinit(&conn->db);
 	pool_unref(conn->pool);
 }
 

Index: db-sql.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/db-sql.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- db-sql.h	9 Jun 2005 18:44:46 -0000	1.2
+++ db-sql.h	14 Jan 2006 18:47:20 -0000	1.3
@@ -23,6 +23,6 @@
 };
 
 struct sql_connection *db_sql_init(const char *config_path);
-void db_sql_unref(struct sql_connection *conn);
+void db_sql_unref(struct sql_connection **conn);
 
 #endif

Index: main.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/main.c,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -d -r1.52 -r1.53
--- main.c	13 Jan 2006 20:25:57 -0000	1.52
+++ main.c	14 Jan 2006 18:47:20 -0000	1.53
@@ -263,10 +263,10 @@
 
 static void main_deinit(void)
 {
-	auth_deinit(auth);
+	auth_deinit(&auth);
 
 	if (worker_client != NULL)
-		auth_worker_client_unref(worker_client);
+		auth_worker_client_unref(&worker_client);
 	else
 		auth_request_handler_flush_failures();
 
@@ -309,7 +309,7 @@
         io_loop_run(ioloop);
 	main_deinit();
 
-	io_loop_destroy(ioloop);
+	io_loop_destroy(&ioloop);
 	lib_deinit();
 
         return 0;

Index: mech-gssapi.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/mech-gssapi.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- mech-gssapi.c	28 Dec 2005 17:15:43 -0000	1.3
+++ mech-gssapi.c	14 Jan 2006 18:47:20 -0000	1.4
@@ -115,7 +115,7 @@
 				       GSS_C_NT_HOSTBASED_SERVICE,
 				       &gss_principal);
 
-	str_free(principal_name);
+	str_free(&principal_name);
 
 	if (GSS_ERROR(major_status)) {
 		auth_request_log_gss_error(request, major_status,

Index: passdb-cache.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/passdb-cache.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- passdb-cache.c	13 Jan 2006 20:25:57 -0000	1.15
+++ passdb-cache.c	14 Jan 2006 18:47:20 -0000	1.16
@@ -144,5 +144,5 @@
 void passdb_cache_deinit(void)
 {
 	if (passdb_cache != NULL)
-		auth_cache_free(passdb_cache);
+		auth_cache_free(&passdb_cache);
 }

Index: passdb-checkpassword.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/passdb-checkpassword.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- passdb-checkpassword.c	6 Dec 2005 15:08:32 -0000	1.12
+++ passdb-checkpassword.c	14 Jan 2006 18:47:20 -0000	1.13
@@ -46,13 +46,11 @@
 			i_error("checkpassword: close() failed: %m");
 		request->fd_in = -1;
 	}
-	if (request->io_in != NULL) {
-		io_remove(request->io_in);
-		request->io_in = NULL;
-	}
+	if (request->io_in != NULL)
+		io_remove(&request->io_in);
 
 	if (request->io_out != NULL)
-		io_remove(request->io_out);
+		io_remove(&request->io_out);
 	if (request->fd_out != -1) {
 		if (close(request->fd_out) < 0)
 			i_error("checkpassword: close() failed: %m");
@@ -75,16 +73,13 @@
 					 str_c(request->input_buf));
 	}
 
-	if (auth_request_unref(request->request)) {
-		request->callback(result, request->request);
-	}
+	request->callback(result, request->request);
+	auth_request_unref(&request->request);
 
         checkpassword_request_close(request);
 
-	if (request->input_buf != NULL) {
-		str_free(request->input_buf);
-		request->input_buf = NULL;
-	}
+	if (request->input_buf != NULL)
+		str_free(&request->input_buf);
 
 	safe_memset(request->password, 0, strlen(request->password));
 	i_free(request->password);
@@ -136,10 +131,9 @@
 	/* FIXME: if we ever do some other kind of forking, this needs fixing */
 	while ((pid = waitpid(-1, &status, WNOHANG)) != 0) {
 		if (pid == -1) {
-			if (errno == ECHILD) {
-				timeout_remove(module->to_wait);
-				module->to_wait = NULL;
-			} else if (errno != EINTR)
+			if (errno == ECHILD)
+				timeout_remove(&module->to_wait);
+			else if (errno != EINTR)
 				i_error("waitpid() failed: %m");
 			return;
 		}
@@ -270,8 +264,7 @@
 		i_error("checkpassword: close() failed: %m");
         request->fd_out = -1;
 
-	io_remove(request->io_out);
-	request->io_out = NULL;
+	io_remove(&request->io_out);
 }
 
 static void
@@ -382,7 +375,7 @@
 	hash_destroy(module->clients);
 
 	if (module->to_wait != NULL)
-		timeout_remove(module->to_wait);
+		timeout_remove(&module->to_wait);
 }
 
 struct passdb_module_interface passdb_checkpassword = {

Index: passdb-ldap.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/passdb-ldap.c,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -d -r1.40 -r1.41
--- passdb-ldap.c	7 Jan 2006 01:25:05 -0000	1.40
+++ passdb-ldap.c	14 Jan 2006 18:47:20 -0000	1.41
@@ -95,9 +95,7 @@
 
 	passdb_result = PASSDB_RESULT_INTERNAL_FAILURE;
 
-	if (!auth_request_unref(auth_request)) {
-		/* Auth request is already aborted */
-	} else if (res != NULL) {
+	if (res != NULL) {
 		/* LDAP query returned something */
 		ret = ldap_result2error(conn->ld, res, 0);
 		if (ret != LDAP_SUCCESS) {
@@ -120,6 +118,7 @@
 	}
 
 	request->callback.verify_plain(passdb_result, auth_request);
+	auth_request_unref(&auth_request);
 	return NULL;
 }
 
@@ -164,6 +163,7 @@
 		passdb_handle_credentials(passdb_result, password, scheme,
 			ldap_request->callback.lookup_credentials,
 			auth_request);
+		auth_request_unref(&auth_request);
 		return;
 	}
 
@@ -171,6 +171,7 @@
 	if (password == NULL) {
 		ldap_request->callback.verify_plain(passdb_result,
 						    auth_request);
+		auth_request_unref(&auth_request);
 		return;
 	}
 
@@ -187,6 +188,7 @@
 	ldap_request->callback.verify_plain(ret > 0 ? PASSDB_RESULT_OK :
 					    PASSDB_RESULT_PASSWORD_MISMATCH,
 					    auth_request);
+	auth_request_unref(&auth_request);
 }
 
 static void
@@ -201,9 +203,7 @@
 
 	passdb_result = PASSDB_RESULT_INTERNAL_FAILURE;
 
-	if (!auth_request_unref(auth_request)) {
-		/* Auth request is already aborted */
-	} else if (res != NULL) {
+	if (res != NULL) {
 		ret = ldap_result2error(conn->ld, res, 0);
 		if (ret == LDAP_SUCCESS)
 			passdb_result = PASSDB_RESULT_OK;
@@ -217,6 +217,7 @@
 	}
 
 	passdb_ldap_request->callback.verify_plain(passdb_result, auth_request);
+        auth_request_unref(&auth_request);
 }
 
 static void authbind_start(struct ldap_connection *conn,
@@ -261,6 +262,7 @@
 	ldap_request->callback = handle_request_authbind;
 
         authbind_start(conn, ldap_request, ldap_get_dn(conn->ld, entry));
+	auth_request_unref(&auth_request);
 }
 
 static void ldap_lookup_pass(struct auth_request *auth_request,
@@ -428,7 +430,7 @@
 	struct ldap_passdb_module *module =
 		(struct ldap_passdb_module *)_module;
 
-	db_ldap_unref(module->conn);
+	db_ldap_unref(&module->conn);
 }
 
 struct passdb_module_interface passdb_ldap = {

Index: passdb-pam.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/passdb-pam.c,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -d -r1.33 -r1.34
--- passdb-pam.c	13 Jan 2006 20:25:57 -0000	1.33
+++ passdb-pam.c	14 Jan 2006 18:47:20 -0000	1.34
@@ -336,10 +336,10 @@
 				       "close(child input) failed: %m");
 	}
 
-	if (auth_request_unref(auth_request))
-		request->callback(result, auth_request);
+	request->callback(result, auth_request);
+	auth_request_unref(&auth_request);
 
-	io_remove(request->io);
+	io_remove(&request->io);
 	i_free(request);
 }
 
@@ -352,10 +352,9 @@
 	/* FIXME: if we ever do some other kind of forking, this needs fixing */
 	while ((pid = waitpid(-1, &status, WNOHANG)) != 0) {
 		if (pid == -1) {
-			if (errno == ECHILD) {
-				timeout_remove(module->to_wait);
-				module->to_wait = NULL;
-			} else if (errno != EINTR)
+			if (errno == ECHILD)
+				timeout_remove(&module->to_wait);
+			else if (errno != EINTR)
 				i_error("waitpid() failed: %m");
 			return;
 		}
@@ -462,7 +461,7 @@
         struct pam_passdb_module *module = (struct pam_passdb_module *)_module;
 
 	if (module->to_wait != NULL)
-		timeout_remove(module->to_wait);
+		timeout_remove(&module->to_wait);
 }
 
 struct passdb_module_interface passdb_pam = {

Index: passdb-passwd-file.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/passdb-passwd-file.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- passdb-passwd-file.c	1 Jan 2006 17:04:29 -0000	1.23
+++ passdb-passwd-file.c	14 Jan 2006 18:47:20 -0000	1.24
@@ -109,7 +109,7 @@
 	struct passwd_file_passdb_module *module =
 		(struct passwd_file_passdb_module *)_module;
 
-	db_passwd_file_unref(module->pwf);
+	db_passwd_file_unref(&module->pwf);
 }
 
 struct passdb_module_interface passdb_passwd_file = {

Index: passdb-sql.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/passdb-sql.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- passdb-sql.c	28 Oct 2005 12:02:36 -0000	1.24
+++ passdb-sql.c	14 Jan 2006 18:47:20 -0000	1.25
@@ -100,12 +100,14 @@
 		passdb_handle_credentials(passdb_result, password, scheme,
 			sql_request->callback.lookup_credentials,
 			auth_request);
+		auth_request_unref(&auth_request);
 		return;
 	}
 
 	/* verify plain */
 	if (password == NULL) {
 		sql_request->callback.verify_plain(passdb_result, auth_request);
+		auth_request_unref(&auth_request);
 		return;
 	}
 
@@ -121,6 +123,7 @@
 	sql_request->callback.verify_plain(ret > 0 ? PASSDB_RESULT_OK :
 					   PASSDB_RESULT_PASSWORD_MISMATCH,
 					   auth_request);
+	auth_request_unref(&auth_request);
 }
 
 static void sql_lookup_pass(struct passdb_sql_request *sql_request)
@@ -138,6 +141,7 @@
 	auth_request_log_debug(sql_request->auth_request, "sql",
 			       "query: %s", str_c(query));
 
+	auth_request_ref(sql_request->auth_request);
 	sql_query(module->conn->db, str_c(query),
 		  sql_query_callback, sql_request);
 }
@@ -202,7 +206,7 @@
 	struct sql_passdb_module *module =
 		(struct sql_passdb_module *)_module;
 
-	db_sql_unref(module->conn);
+	db_sql_unref(&module->conn);
 }
 
 struct passdb_module_interface passdb_sql = {

Index: passdb.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/passdb.c,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -d -r1.40 -r1.41
--- passdb.c	30 Dec 2005 15:43:41 -0000	1.40
+++ passdb.c	14 Jan 2006 18:47:20 -0000	1.41
@@ -192,6 +192,6 @@
 		passdb->passdb->iface.deinit(passdb->passdb);
 #ifdef HAVE_MODULES
 	if (passdb->module != NULL)
-                auth_module_close(passdb->module);
+                auth_module_close(&passdb->module);
 #endif
 }

Index: password-scheme.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/password-scheme.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- password-scheme.c	13 Jan 2006 20:25:57 -0000	1.19
+++ password-scheme.c	14 Jan 2006 18:47:20 -0000	1.20
@@ -492,7 +492,7 @@
 void password_schemes_deinit(void)
 {
 #ifdef HAVE_MODULES
-	module_dir_unload(scheme_modules);
+	module_dir_unload(&scheme_modules);
 #endif
 
 	buffer_free(schemes_buf);

Index: userdb-ldap.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/userdb-ldap.c,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -d -r1.38 -r1.39
--- userdb-ldap.c	13 Jan 2006 20:25:57 -0000	1.38
+++ userdb-ldap.c	14 Jan 2006 18:47:20 -0000	1.39
@@ -164,6 +164,7 @@
 	}
 
 	urequest->userdb_callback(reply, auth_request);
+	auth_request_unref(&auth_request);
 }
 
 static void userdb_ldap_lookup(struct auth_request *auth_request,
@@ -178,6 +179,7 @@
 	struct userdb_ldap_request *request;
 	string_t *str;
 
+	auth_request_ref(auth_request);
 	request = p_new(auth_request->pool, struct userdb_ldap_request, 1);
 	request->request.callback = handle_request;
 	request->auth_request = auth_request;
@@ -235,7 +237,7 @@
 	struct ldap_userdb_module *module =
 		(struct ldap_userdb_module *)_module;
 
-	db_ldap_unref(module->conn);
+	db_ldap_unref(&module->conn);
 }
 
 struct userdb_module_interface userdb_ldap = {

Index: userdb-passwd-file.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/userdb-passwd-file.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- userdb-passwd-file.c	16 Oct 2005 14:34:39 -0000	1.18
+++ userdb-passwd-file.c	14 Jan 2006 18:47:20 -0000	1.19
@@ -66,7 +66,7 @@
 	struct passwd_file_userdb_module *module =
 		(struct passwd_file_userdb_module *)_module;
 
-	db_passwd_file_unref(module->pwf);
+	db_passwd_file_unref(&module->pwf);
 }
 
 struct userdb_module_interface userdb_passwd_file = {

Index: userdb-sql.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/userdb-sql.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- userdb-sql.c	16 Oct 2005 14:34:39 -0000	1.12
+++ userdb-sql.c	14 Jan 2006 18:47:20 -0000	1.13
@@ -95,6 +95,7 @@
 	}
 
 	sql_request->callback(reply, auth_request);
+	auth_request_unref(&auth_request);
 	i_free(sql_request);
 }
 
@@ -112,6 +113,7 @@
 		   auth_request_get_var_expand_table(auth_request,
 						     str_escape));
 
+	auth_request_ref(auth_request);
 	sql_request = i_new(struct userdb_sql_request, 1);
 	sql_request->callback = callback;
 	sql_request->auth_request = auth_request;
@@ -151,7 +153,7 @@
 	struct sql_userdb_module *module =
 		(struct sql_userdb_module *)_module;
 
-	db_sql_unref(module->conn);
+	db_sql_unref(&module->conn);
 }
 
 struct userdb_module_interface userdb_sql = {

Index: userdb.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/userdb.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- userdb.c	14 Dec 2005 17:45:06 -0000	1.24
+++ userdb.c	14 Jan 2006 18:47:20 -0000	1.25
@@ -150,6 +150,6 @@
 		userdb->userdb->iface->deinit(userdb->userdb);
 #ifdef HAVE_MODULES
 	if (userdb->module != NULL)
-                auth_module_close(userdb->module);
+                auth_module_close(&userdb->module);
 #endif
 }



More information about the dovecot-cvs mailing list