]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Use master_service_connection.name for determining listener type.
authorTimo Sirainen <tss@iki.fi>
Fri, 30 Dec 2011 10:33:06 +0000 (12:33 +0200)
committerTimo Sirainen <tss@iki.fi>
Fri, 30 Dec 2011 10:33:06 +0000 (12:33 +0200)
src/auth/main.c
src/director/main.c
src/ipc/main.c

index b492a8fb2de61eeaf708678e0b7a2f6dcf97b039..0ed58a4ea1cee4cbdff9eecfbcb3180cc07b00a1 100644 (file)
@@ -96,21 +96,9 @@ static const char *const *read_global_settings(void)
 }
 
 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 @@ static void listeners_init(void)
                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 @@ static void client_connected(struct master_service_connection *conn)
        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:
index 3db1ef03d7745efcaf36155d84292f5ca6c404b7..d5908d4a2fd63e76ef3c0062166226a2a9dcf13a 100644 (file)
@@ -41,7 +41,7 @@ static int director_client_connected(int fd, const struct ip_addr *ip)
 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 @@ static void client_connected(struct master_service_connection *conn)
                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 @@ static void client_connected(struct master_service_connection *conn)
           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) {
index 6d1d166812cb4213eb0a29153f87e3e8a4babcc3..621c0d1fdfe1d07bff9b0f0c25f37cf0b26d4b1b 100644 (file)
@@ -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);