dovecot-2.1: Use master_service_connection.name for determining ...

dovecot at dovecot.org dovecot at dovecot.org
Fri Dec 30 12:33:17 EET 2011


details:   http://hg.dovecot.org/dovecot-2.1/rev/5df67a23afb9
changeset: 13878:5df67a23afb9
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Dec 30 12:33:06 2011 +0200
description:
Use master_service_connection.name for determining listener type.

diffstat:

 src/auth/main.c     |  38 +++++++++++++++++++-------------------
 src/director/main.c |  17 ++++-------------
 src/ipc/main.c      |  22 ++++++++--------------
 3 files changed, 31 insertions(+), 46 deletions(-)

diffs (146 lines):

diff -r cdf2c63ece6a -r 5df67a23afb9 src/auth/main.c
--- a/src/auth/main.c	Fri Dec 30 12:31:58 2011 +0200
+++ b/src/auth/main.c	Fri Dec 30 12:33:06 2011 +0200
@@ -96,21 +96,9 @@
 }
 
 static enum auth_socket_type
-auth_socket_type_get(int listen_fd, const char **path_r)
+auth_socket_type_get(const char *path)
 {
-	const char *path, *name, *suffix;
-
-	/* figure out if this is a server or network socket by
-	   checking the socket path name. */
-	if (net_getunixname(listen_fd, &path) < 0) {
-		if (errno != ENOTSOCK)
-			i_fatal("getunixname(%d) failed: %m", listen_fd);
-		/* not UNIX socket. let's just assume it's an
-		   auth client. */
-		*path_r = NULL;
-		return AUTH_SOCKET_CLIENT;
-	}
-	*path_r = path;
+	const char *name, *suffix;
 
 	name = strrchr(path, '/');
 	if (name == NULL)
@@ -146,11 +134,17 @@
 		struct auth_socket_listener *l;
 
 		l = array_idx_modifiable(&listeners, fd);
-		l->type = auth_socket_type_get(fd, &path);
-		l->path = i_strdup(path);
-		if (l->type == AUTH_SOCKET_USERDB) {
-			if (stat(path, &l->st) < 0)
-				i_error("stat(%s) failed: %m", path);
+		if (net_getunixname(fd, &path) < 0) {
+			if (errno != ENOTSOCK)
+				i_fatal("getunixname(%d) failed: %m", fd);
+			/* not a unix socket, set its name and type lazily */
+		} else {
+			l->type = auth_socket_type_get(path);
+			l->path = i_strdup(path);
+			if (l->type == AUTH_SOCKET_USERDB) {
+				if (stat(path, &l->st) < 0)
+					i_error("stat(%s) failed: %m", path);
+			}
 		}
 	}
 }
@@ -311,6 +305,12 @@
 	struct auth *auth;
 
 	l = array_idx_modifiable(&listeners, conn->listen_fd);
+	if (l->type == AUTH_SOCKET_UNKNOWN) {
+		/* first connection from inet socket, figure out its type
+		   from the listener name */
+		l->type = auth_socket_type_get(conn->name);
+		l->path = i_strdup(conn->name);
+	}
 	auth = auth_find_service(NULL);
 	switch (l->type) {
 	case AUTH_SOCKET_MASTER:
diff -r cdf2c63ece6a -r 5df67a23afb9 src/director/main.c
--- a/src/director/main.c	Fri Dec 30 12:31:58 2011 +0200
+++ b/src/director/main.c	Fri Dec 30 12:33:06 2011 +0200
@@ -41,7 +41,7 @@
 static void client_connected(struct master_service_connection *conn)
 {
 	struct auth_connection *auth;
-	const char *path, *name, *socket_path;
+	const char *socket_path;
 	struct ip_addr ip;
 	unsigned int local_port, len;
 	bool userdb;
@@ -70,17 +70,8 @@
 		return;
 	}
 
-	if (net_getunixname(conn->listen_fd, &path) < 0)
-		i_fatal("getunixname(%d) failed: %m", conn->listen_fd);
-
-	name = strrchr(path, '/');
-	if (name == NULL)
-		name = path;
-	else
-		name++;
-
-	len = strlen(name);
-	if (len > 6 && strcmp(name + len - 6, "-admin") == 0) {
+	len = strlen(conn->name);
+	if (len > 6 && strcmp(conn->name + len - 6, "-admin") == 0) {
 		/* doveadm connection */
 		master_service_client_connection_accept(conn);
 		(void)doveadm_connection_init(director, conn->fd);
@@ -91,7 +82,7 @@
 	   b) login connection
 	   Both of them are handled exactly the same, except for which
 	   auth socket they connect to. */
-	userdb = len > 7 && strcmp(name + len - 7, "-userdb") == 0;
+	userdb = len > 7 && strcmp(conn->name + len - 7, "-userdb") == 0;
 	socket_path = userdb ? AUTH_USERDB_SOCKET_PATH : AUTH_SOCKET_PATH;
 	auth = auth_connection_init(socket_path);
 	if (auth_connection_connect(auth) == 0) {
diff -r cdf2c63ece6a -r 5df67a23afb9 src/ipc/main.c
--- a/src/ipc/main.c	Fri Dec 30 12:31:58 2011 +0200
+++ b/src/ipc/main.c	Fri Dec 30 12:33:06 2011 +0200
@@ -8,30 +8,24 @@
 #include "ipc-connection.h"
 #include "client.h"
 
-static bool ipc_socket_is_client(int listen_fd)
+static bool ipc_socket_is_client(const char *name)
 {
-	const char *path, *name;
+	unsigned int len;
 
-	if (net_getunixname(listen_fd, &path) < 0) {
-		if (errno != ENOTSOCK)
-			i_fatal("getunixname(%d) failed: %m", listen_fd);
-		/* not a UNIX socket. let's just assume it's a client. */
+	if (strcmp(name, "ipc") == 0)
 		return TRUE;
-	}
 
-	name = strrchr(path, '/');
-	if (name == NULL)
-		name = path;
-	else
-		name++;
-	return strcmp(name, "ipc") == 0;
+	len = strlen(name);
+	if (len > 7 && strcmp(name + len - 7, "-client") == 0)
+		return TRUE;
+	return FALSE;
 }
 
 static void client_connected(struct master_service_connection *conn)
 {
 	master_service_client_connection_accept(conn);
 
-	if (ipc_socket_is_client(conn->listen_fd))
+	if (ipc_socket_is_client(conn->name))
 		(void)client_create(conn->fd);
 	else
 		(void)ipc_connection_create(conn->listen_fd, conn->fd);


More information about the dovecot-cvs mailing list