}
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)
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);
+ }
}
}
}
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:
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;
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);
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) {
#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);