From: Timo Sirainen Date: Fri, 30 Dec 2011 10:33:06 +0000 (+0200) Subject: Use master_service_connection.name for determining listener type. X-Git-Tag: 2.1.rc2~22 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=faec0abfd648c647030027e86de2ce8911df683b;p=thirdparty%2Fdovecot%2Fcore.git Use master_service_connection.name for determining listener type. --- diff --git a/src/auth/main.c b/src/auth/main.c index b492a8fb2d..0ed58a4ea1 100644 --- a/src/auth/main.c +++ b/src/auth/main.c @@ -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: diff --git a/src/director/main.c b/src/director/main.c index 3db1ef03d7..d5908d4a2f 100644 --- a/src/director/main.c +++ b/src/director/main.c @@ -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) { diff --git a/src/ipc/main.c b/src/ipc/main.c index 6d1d166812..621c0d1fdf 100644 --- a/src/ipc/main.c +++ b/src/ipc/main.c @@ -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);