dovecot-2.0: *-login: Get auth connection cookie earlier so its ...

dovecot at dovecot.org dovecot at dovecot.org
Thu Dec 10 03:19:09 EET 2009


details:   http://hg.dovecot.org/dovecot-2.0/rev/32e77c570529
changeset: 10448:32e77c570529
user:      Timo Sirainen <tss at iki.fi>
date:      Wed Dec 09 20:19:03 2009 -0500
description:
*-login: Get auth connection cookie earlier so its lookup can't fail.

diffstat:

4 files changed, 18 insertions(+), 18 deletions(-)
src/lib-auth/auth-client-request.c |    5 +++++
src/lib-auth/auth-client.c         |    7 -------
src/lib-auth/auth-client.h         |    3 ++-
src/login-common/sasl-server.c     |   21 +++++++++++----------

diffs (107 lines):

diff -r 3ac17da0d723 -r 32e77c570529 src/lib-auth/auth-client-request.c
--- a/src/lib-auth/auth-client-request.c	Wed Dec 09 20:11:08 2009 -0500
+++ b/src/lib-auth/auth-client-request.c	Wed Dec 09 20:19:03 2009 -0500
@@ -134,6 +134,11 @@ auth_client_request_get_server_pid(struc
 	return request->conn->server_pid;
 }
 
+const char *auth_client_request_get_cookie(struct auth_client_request *request)
+{
+	return request->conn->cookie;
+}
+
 bool auth_client_request_is_aborted(struct auth_client_request *request)
 {
 	return request->callback == NULL;
diff -r 3ac17da0d723 -r 32e77c570529 src/lib-auth/auth-client.c
--- a/src/lib-auth/auth-client.c	Wed Dec 09 20:11:08 2009 -0500
+++ b/src/lib-auth/auth-client.c	Wed Dec 09 20:19:03 2009 -0500
@@ -74,10 +74,3 @@ void auth_client_get_connect_id(struct a
 	*server_pid_r = client->conn->server_pid;
 	*connect_uid_r = client->conn->connect_uid;
 }
-
-const char *auth_client_get_cookie(struct auth_client *client)
-{
-	i_assert(auth_client_is_connected(client));
-
-	return client->conn->cookie;
-}
diff -r 3ac17da0d723 -r 32e77c570529 src/lib-auth/auth-client.h
--- a/src/lib-auth/auth-client.h	Wed Dec 09 20:11:08 2009 -0500
+++ b/src/lib-auth/auth-client.h	Wed Dec 09 20:19:03 2009 -0500
@@ -68,7 +68,6 @@ void auth_client_get_connect_id(struct a
 void auth_client_get_connect_id(struct auth_client *client,
 				unsigned int *server_pid_r,
 				unsigned int *connect_uid_r);
-const char *auth_client_get_cookie(struct auth_client *client);
 
 /* Create a new authentication request. callback is called whenever something
    happens for the request. */
@@ -87,5 +86,7 @@ unsigned int auth_client_request_get_id(
 /* Return the PID of the server that handled this request. */
 unsigned int
 auth_client_request_get_server_pid(struct auth_client_request *request);
+/* Return cookie of the server that handled this request. */
+const char *auth_client_request_get_cookie(struct auth_client_request *request);
 
 #endif
diff -r 3ac17da0d723 -r 32e77c570529 src/login-common/sasl-server.c
--- a/src/login-common/sasl-server.c	Wed Dec 09 20:11:08 2009 -0500
+++ b/src/login-common/sasl-server.c	Wed Dec 09 20:19:03 2009 -0500
@@ -26,6 +26,7 @@ struct anvil_request {
 struct anvil_request {
 	struct client *client;
 	unsigned int auth_pid, auth_id;
+	unsigned char cookie[MASTER_AUTH_COOKIE_SIZE];
 };
 
 const struct auth_mech_desc *
@@ -109,11 +110,8 @@ static void master_send_request(struct a
 	struct client *client = anvil_request->client;
 	struct master_auth_request req;
 	const unsigned char *data;
-	const char *cookie;
 	size_t size;
 	buffer_t *buf;
-
-	buf = buffer_create_dynamic(pool_datastack_create(), 256);
 
 	memset(&req, 0, sizeof(req));
 	req.auth_pid = anvil_request->auth_pid;
@@ -121,12 +119,9 @@ static void master_send_request(struct a
 	req.local_ip = client->local_ip;
 	req.remote_ip = client->ip;
 	req.client_pid = getpid();
-
-	cookie = auth_client_get_cookie(auth_client);
-	if (hex_to_binary(cookie, buf) == 0 && buf->used == sizeof(req.cookie))
-		memcpy(req.cookie, buf->data, sizeof(req.cookie));
-
-	buffer_set_used_size(buf, 0);
+	memcpy(req.cookie, anvil_request->cookie, sizeof(req.cookie));
+
+	buf = buffer_create_dynamic(pool_datastack_create(), 256);
 	buffer_append(buf, client->master_data_prefix,
 		      client->master_data_prefix_len);
 
@@ -159,12 +154,18 @@ anvil_check_too_many_connections(struct 
 				 struct auth_client_request *request)
 {
 	struct anvil_request *req;
-	const char *query;
+	const char *query, *cookie;
+	buffer_t buf;
 
 	req = i_new(struct anvil_request, 1);
 	req->client = client;
 	req->auth_pid = auth_client_request_get_server_pid(request);
 	req->auth_id = auth_client_request_get_id(request);
+
+	buffer_create_data(&buf, req->cookie, sizeof(req->cookie));
+	cookie = auth_client_request_get_cookie(request);
+	if (strlen(cookie) == MASTER_AUTH_COOKIE_SIZE*2)
+		(void)hex_to_binary(cookie, &buf);
 
 	if (client->virtual_user == NULL ||
 	    client->set->mail_max_userip_connections == 0) {


More information about the dovecot-cvs mailing list