]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
auth: Use the new listener type field to distinguish the various listener types.
authorStephan Bosch <stephan.bosch@open-xchange.com>
Fri, 18 Nov 2022 20:09:33 +0000 (21:09 +0100)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Sun, 11 Dec 2022 21:58:50 +0000 (21:58 +0000)
src/auth/auth-settings.c
src/auth/main.c

index aa8224aa4828b51f1fe16c4f04e75dd83c9b2d78..ca840f3ec192b2955ad33c5f8219531ecc0322a6 100644 (file)
@@ -19,36 +19,42 @@ static bool auth_userdb_settings_check(void *_set, pool_t pool, const char **err
 static struct file_listener_settings auth_unix_listeners_array[] = {
        {
                .path = "login/login",
+               .type = "login",
                .mode = 0666,
                .user = "",
                .group = "",
        },
        {
                .path = "token-login/tokenlogin",
+               .type = "token-login",
                .mode = 0666,
                .user = "",
                .group = "",
        },
        {
                .path = "auth-login",
+               .type = "login",
                .mode = 0600,
                .user = "$default_internal_user",
                .group = "",
        },
        {
                .path = "auth-client",
+               .type = "auth",
                .mode = 0600,
                .user = "$default_internal_user",
                .group = "",
        },
        {
                .path = "auth-userdb",
+               .type = "userdb",
                .mode = 0666,
                .user = "$default_internal_user",
                .group = "",
        },
        {
                .path = "auth-master",
+               .type = "master",
                .mode = 0600,
                .user = "",
                .group = "",
index d572ecd3d7dfcb87ea6a015b565d63f013e5de97..42f0599a11349efe98fc5ecf18bf5a7647f9ddb5 100644 (file)
 
 enum auth_socket_type {
        AUTH_SOCKET_UNKNOWN = 0,
-       AUTH_SOCKET_CLIENT,
-       AUTH_SOCKET_LOGIN_CLIENT,
+       AUTH_SOCKET_AUTH,
+       AUTH_SOCKET_LOGIN,
        AUTH_SOCKET_MASTER,
        AUTH_SOCKET_USERDB,
        AUTH_SOCKET_TOKEN,
-       AUTH_SOCKET_TOKEN_LOGIN
+       AUTH_SOCKET_TOKEN_LOGIN,
 };
 
 struct auth_socket_listener {
-       enum auth_socket_type type;
        struct stat st;
        char *path;
 };
 
+static const char *const auth_socket_type_names[] = {
+       [AUTH_SOCKET_UNKNOWN]       = "",
+       [AUTH_SOCKET_AUTH]          = "auth",
+       [AUTH_SOCKET_LOGIN]         = "login",
+       [AUTH_SOCKET_MASTER]        = "master",
+       [AUTH_SOCKET_USERDB]        = "userdb",
+       [AUTH_SOCKET_TOKEN]         = "token",
+       [AUTH_SOCKET_TOKEN_LOGIN]   = "token-login",
+};
+
 bool worker = FALSE, worker_restart_request = FALSE;
 time_t process_start_time;
 struct auth_penalty *auth_penalty;
@@ -97,35 +106,20 @@ static const char *const *read_global_settings(void)
        return services;
 }
 
-static enum auth_socket_type
-auth_socket_type_get(const char *path)
+static enum auth_socket_type auth_socket_type_get(const char *typename)
 {
-       const char *name, *suffix;
-
-       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 if (strcmp(suffix, "token") == 0)
-               return AUTH_SOCKET_TOKEN;
-       else if (strcmp(suffix, "tokenlogin") == 0)
+       unsigned int i;
+
+       for (i = 0; i < N_ELEMENTS(auth_socket_type_names); i++) {
+               if (null_strcmp(typename, auth_socket_type_names[i]) == 0)
+                       return (enum auth_socket_type)i;
+       }
+
+       /* Deprecated name suffixes */
+       if (strcmp(typename, "tokenlogin") == 0)
                return AUTH_SOCKET_TOKEN_LOGIN;
-       else
-               return AUTH_SOCKET_CLIENT;
+
+       return AUTH_SOCKET_AUTH;
 }
 
 static void listeners_init(void)
@@ -143,14 +137,11 @@ static void listeners_init(void)
                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 */
+                       /* not a unix socket */
                } 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);
-                       }
+                       if (stat(path, &l->st) < 0)
+                               i_error("stat(%s) failed: %m", path);
                }
        }
 }
@@ -324,16 +315,15 @@ static void client_connected(struct master_service_connection *conn)
 {
        struct auth_socket_listener *l;
        struct auth *auth;
+       const char *type;
 
        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);
+       if (l->path == NULL)
                l->path = i_strdup(conn->name);
-       }
+
+       type = master_service_connection_get_type(conn);
        auth = auth_default_service();
-       switch (l->type) {
+       switch (auth_socket_type_get(type)) {
        case AUTH_SOCKET_MASTER:
                (void)auth_master_connection_create(auth, conn->fd,
                                                    l->path, NULL, FALSE);
@@ -342,10 +332,10 @@ static void client_connected(struct master_service_connection *conn)
                (void)auth_master_connection_create(auth, conn->fd,
                                                    l->path, &l->st, TRUE);
                break;
-       case AUTH_SOCKET_LOGIN_CLIENT:
+       case AUTH_SOCKET_LOGIN:
                auth_client_connection_create(auth, conn->fd, TRUE, FALSE);
                break;
-       case AUTH_SOCKET_CLIENT:
+       case AUTH_SOCKET_AUTH:
                auth_client_connection_create(auth, conn->fd, FALSE, FALSE);
                break;
        case AUTH_SOCKET_TOKEN_LOGIN: