dovecot-2.0: auth: Added auth-master socket that's allowed to do...

dovecot at dovecot.org dovecot at dovecot.org
Mon Aug 17 19:55:36 EEST 2009


details:   http://hg.dovecot.org/dovecot-2.0/rev/7f9fcd00a819
changeset: 9803:7f9fcd00a819
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Aug 17 12:54:54 2009 -0400
description:
auth: Added auth-master socket that's allowed to do REQUEST commands.

diffstat:

3 files changed, 31 insertions(+), 20 deletions(-)
src/auth/auth-master-connection.c |   35 +++++++++++++++++++----------------
src/auth/auth-master-connection.h |    3 ++-
src/auth/main.c                   |   13 ++++++++++---

diffs (130 lines):

diff -r fc0022950bad -r 7f9fcd00a819 src/auth/auth-master-connection.c
--- a/src/auth/auth-master-connection.c	Mon Aug 17 12:52:22 2009 -0400
+++ b/src/auth/auth-master-connection.c	Mon Aug 17 12:54:54 2009 -0400
@@ -264,7 +264,7 @@ master_input_list(struct auth_master_con
 	while (userdb != NULL && userdb->userdb->iface->iterate_init == NULL)
 		userdb = userdb->next;
 	if (userdb == NULL) {
-		i_error("Trying to iterate users, but userdbs don't suppor it");
+		i_error("Trying to iterate users, but userdbs don't support it");
 		str = t_strdup_printf("DONE\t%u\tfail", id);
 		(void)o_stream_send_str(conn->output, str);
 		return TRUE;
@@ -288,22 +288,24 @@ auth_master_input_line(struct auth_maste
 	if (conn->auth->set->debug)
 		i_info("master in: %s", line);
 
-	if (strncmp(line, "REQUEST\t", 8) == 0)
-		return master_input_request(conn, line + 8);
-	else if (strncmp(line, "USER\t", 5) == 0)
+	if (strncmp(line, "USER\t", 5) == 0)
 		return master_input_user(conn, line + 5);
-	else if (strncmp(line, "LIST\t", 5) == 0)
+	if (strncmp(line, "LIST\t", 5) == 0)
 		return master_input_list(conn, line + 5);
-	else if (strncmp(line, "CPID\t", 5) == 0) {
-		i_error("Authentication client trying to connect to "
-			"master socket");
-		return FALSE;
-	} else {
-		/* ignore unknown command */
-		i_error("BUG: Unknown command in master socket: %s",
-			str_sanitize(line, 80));
-		return FALSE;
-	}
+
+	if (!conn->userdb_only) {
+		if (strncmp(line, "REQUEST\t", 8) == 0)
+			return master_input_request(conn, line + 8);
+		if (strncmp(line, "CPID\t", 5) == 0) {
+			i_error("Authentication client trying to connect to "
+				"master socket");
+			return FALSE;
+		}
+	}
+
+	i_error("BUG: Unknown command in master socket: %s",
+		str_sanitize(line, 80));
+	return FALSE;
 }
 
 static void master_input(struct auth_master_connection *conn)
@@ -372,7 +374,7 @@ static int master_output(struct auth_mas
 }
 
 struct auth_master_connection *
-auth_master_connection_create(struct auth *auth, int fd)
+auth_master_connection_create(struct auth *auth, int fd, bool userdb_only)
 {
 	struct auth_master_connection *conn;
 	const char *line;
@@ -385,6 +387,7 @@ auth_master_connection_create(struct aut
 	conn->output = o_stream_create_fd(fd, (size_t)-1, FALSE);
 	o_stream_set_flush_callback(conn->output, master_output, conn);
 	conn->io = io_add(fd, IO_READ, master_input, conn);
+	conn->userdb_only = userdb_only;
 
 	line = t_strdup_printf("VERSION\t%u\t%u\nSPID\t%s\n",
 			       AUTH_MASTER_PROTOCOL_MAJOR_VERSION,
diff -r fc0022950bad -r 7f9fcd00a819 src/auth/auth-master-connection.h
--- a/src/auth/auth-master-connection.h	Mon Aug 17 12:52:22 2009 -0400
+++ b/src/auth/auth-master-connection.h	Mon Aug 17 12:54:54 2009 -0400
@@ -14,13 +14,14 @@ struct auth_master_connection {
 
 	unsigned int version_received:1;
 	unsigned int destroyed:1;
+	unsigned int userdb_only:1;
 };
 ARRAY_DEFINE_TYPE(auth_master_connections, struct auth_master_connection *);
 
 extern ARRAY_TYPE(auth_master_connections) auth_master_connections;
 
 struct auth_master_connection *
-auth_master_connection_create(struct auth *auth, int fd);
+auth_master_connection_create(struct auth *auth, int fd, bool userdb_only);
 void auth_master_connection_destroy(struct auth_master_connection **conn);
 
 void auth_master_connection_ref(struct auth_master_connection *conn);
diff -r fc0022950bad -r 7f9fcd00a819 src/auth/main.c
--- a/src/auth/main.c	Mon Aug 17 12:52:22 2009 -0400
+++ b/src/auth/main.c	Mon Aug 17 12:54:54 2009 -0400
@@ -28,7 +28,8 @@ enum auth_socket_type {
 enum auth_socket_type {
 	AUTH_SOCKET_UNKNOWN = 0,
 	AUTH_SOCKET_CLIENT,
-	AUTH_SOCKET_MASTER
+	AUTH_SOCKET_MASTER,
+	AUTH_SOCKET_USERDB
 };
 
 bool worker = FALSE, shutdown_request = FALSE;
@@ -86,7 +87,8 @@ static void main_init(void)
 		   auth process */
 		master_service_set_client_limit(master_service, 1);
 	} else if (getenv("MASTER_AUTH_FD") != NULL) {
-		(void)auth_master_connection_create(auth, MASTER_AUTH_FD);
+		(void)auth_master_connection_create(auth, MASTER_AUTH_FD,
+						    FALSE);
 	}
 }
 
@@ -141,13 +143,18 @@ static void client_connected(const struc
 		suffix = strrchr(sa.sun_path, '-');
 		if (strcmp(suffix, "master") == 0)
 			*type = AUTH_SOCKET_MASTER;
+		else if (strcmp(suffix, "userdb") == 0)
+			*type = AUTH_SOCKET_USERDB;
 		else
 			*type = AUTH_SOCKET_CLIENT;
 	}
 
 	switch (*type) {
 	case AUTH_SOCKET_MASTER:
-		(void)auth_master_connection_create(auth, conn->fd);
+		(void)auth_master_connection_create(auth, conn->fd, FALSE);
+		break;
+	case AUTH_SOCKET_USERDB:
+		(void)auth_master_connection_create(auth, conn->fd, TRUE);
 		break;
 	case AUTH_SOCKET_CLIENT:
 		(void)auth_client_connection_create(auth, conn->fd);


More information about the dovecot-cvs mailing list