Mercurial > dovecot > core-2.2
changeset 12473:fe8e82b5bff9
auth: Assume inet_listeners are auth client listeners if they exist.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Fri, 26 Nov 2010 17:31:00 +0000 |
parents | 3abefa63b8e7 |
children | e9b90ff13910 |
files | src/auth/main.c |
diffstat | 1 files changed, 39 insertions(+), 28 deletions(-) [+] |
line wrap: on
line diff
--- a/src/auth/main.c Fri Nov 26 17:27:44 2010 +0000 +++ b/src/auth/main.c Fri Nov 26 17:31:00 2010 +0000 @@ -201,40 +201,51 @@ (void)auth_worker_client_create(auth_find_service(NULL), conn->fd); } +static enum auth_socket_type +auth_socket_type_get(int listen_fd) +{ + 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. */ + return AUTH_SOCKET_CLIENT; + } + + name = strrchr(path, '/'); + if (name == NULL) + name = path; + else + name++; + + suffix = strrchr(name, '-'); + if (suffix == NULL) + suffix = name; + else + suffix++; + + if (strcmp(suffix, "login") == 0) + return AUTH_SOCKET_LOGIN_CLIENT; + else if (strcmp(suffix, "master") == 0) + return AUTH_SOCKET_MASTER; + else if (strcmp(suffix, "userdb") == 0) + return AUTH_SOCKET_USERDB; + else + return AUTH_SOCKET_CLIENT; +} + static void client_connected(struct master_service_connection *conn) { enum auth_socket_type *type; - const char *path, *name, *suffix; struct auth *auth; type = array_idx_modifiable(&listen_fd_types, conn->listen_fd); - if (*type == AUTH_SOCKET_UNKNOWN) { - /* figure out if this is a server or network socket by - checking the socket path name. */ - 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++; - - suffix = strrchr(name, '-'); - if (suffix == NULL) - suffix = name; - else - suffix++; - - if (strcmp(suffix, "login") == 0) - *type = AUTH_SOCKET_LOGIN_CLIENT; - else if (strcmp(suffix, "master") == 0) - *type = AUTH_SOCKET_MASTER; - else if (strcmp(suffix, "userdb") == 0) - *type = AUTH_SOCKET_USERDB; - else - *type = AUTH_SOCKET_CLIENT; - } + if (*type == AUTH_SOCKET_UNKNOWN) + *type = auth_socket_type_get(conn->listen_fd); auth = auth_find_service(NULL); switch (*type) {