]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-master: master_auth_request_full() now supports per-request path.
authorTimo Sirainen <tss@iki.fi>
Tue, 17 Nov 2015 15:23:31 +0000 (17:23 +0200)
committerTimo Sirainen <tss@iki.fi>
Tue, 17 Nov 2015 15:23:31 +0000 (17:23 +0200)
src/lib-master/master-auth.c
src/lib-master/master-auth.h

index 6ff640e0769630c4e8d6e98ed414046c8a02e669..3e50ef9b35a8bda377f13208a8a1f722556e0196 100644 (file)
@@ -18,6 +18,7 @@ struct master_auth_connection {
        struct master_auth *auth;
        unsigned int tag;
 
+       char *path;
        int fd;
        struct io *io;
        struct timeout *to;
@@ -33,7 +34,7 @@ struct master_auth {
        struct master_service *service;
        pool_t pool;
 
-       const char *path;
+       const char *default_path;
 
        unsigned int tag_counter;
        HASH_TABLE(void *, struct master_auth_connection *) connections;
@@ -49,7 +50,7 @@ master_auth_init(struct master_service *service, const char *path)
        auth = p_new(pool, struct master_auth, 1);
        auth->pool = pool;
        auth->service = service;
-       auth->path = p_strdup(pool, path);
+       auth->default_path = p_strdup(pool, path);
        hash_table_create_direct(&auth->connections, pool, 0);
        return auth;
 }
@@ -74,9 +75,10 @@ master_auth_connection_deinit(struct master_auth_connection **_conn)
                io_remove(&conn->io);
        if (conn->fd != -1) {
                if (close(conn->fd) < 0)
-                       i_fatal("close(%s) failed: %m", conn->auth->path);
+                       i_fatal("close(%s) failed: %m", conn->path);
                conn->fd = -1;
        }
+       i_free(conn->path);
        i_free(conn);
 }
 
@@ -110,11 +112,11 @@ static void master_auth_connection_input(struct master_auth_connection *conn)
                if (ret == 0 || errno == ECONNRESET) {
                        i_error("read(%s) failed: Remote closed connection "
                                "(destination service { process_limit } reached?)",
-                               conn->auth->path);
+                               conn->path);
                } else {
                        if (errno == EAGAIN)
                                return;
-                       i_error("read(%s) failed: %m", conn->auth->path);
+                       i_error("read(%s) failed: %m", conn->path);
                }
                master_auth_connection_deinit(&conn);
                return;
@@ -130,7 +132,7 @@ static void master_auth_connection_input(struct master_auth_connection *conn)
 
        if (conn->tag != reply->tag)
                i_error("master(%s): Received reply with unknown tag %u",
-                       conn->auth->path, reply->tag);
+                       conn->path, reply->tag);
        else if (conn->callback == NULL) {
                /* request aborted */
        } else {
@@ -143,7 +145,7 @@ static void master_auth_connection_input(struct master_auth_connection *conn)
 static void master_auth_connection_timeout(struct master_auth_connection *conn)
 {
        i_error("master(%s): Auth request timed out (received %u/%u bytes)",
-               conn->auth->path, conn->buf_pos,
+               conn->path, conn->buf_pos,
                (unsigned int)sizeof(conn->buf));
        master_auth_connection_deinit(&conn);
 }
@@ -166,6 +168,8 @@ void master_auth_request_full(struct master_auth *auth,
        conn->auth = auth;
        conn->callback = callback;
        conn->context = context;
+       conn->path = params->socket_path != NULL ?
+               i_strdup(params->socket_path) : i_strdup(auth->default_path);
 
        req = params->request;
        req.tag = ++auth->tag_counter;
@@ -181,11 +185,11 @@ void master_auth_request_full(struct master_auth *auth,
        buffer_append(buf, &req, sizeof(req));
        buffer_append(buf, params->data, req.data_size);
 
-       conn->fd = net_connect_unix_with_retries(auth->path,
+       conn->fd = net_connect_unix_with_retries(conn->path,
                                                 SOCKET_CONNECT_RETRY_MSECS);
        if (conn->fd == -1) {
                i_error("net_connect_unix(%s) failed: %m%s",
-                       auth->path, errno != EAGAIN ? "" :
+                       conn->path, errno != EAGAIN ? "" :
                        " - http://wiki2.dovecot.org/SocketUnavailable");
                master_auth_connection_deinit(&conn);
                return;
@@ -193,11 +197,11 @@ void master_auth_request_full(struct master_auth *auth,
 
        ret = fd_send(conn->fd, params->client_fd, buf->data, buf->used);
        if (ret < 0) {
-               i_error("fd_send(%s, %d) failed: %m", auth->path,
+               i_error("fd_send(%s, %d) failed: %m", conn->path,
                        params->client_fd);
        } else if ((size_t)ret != buf->used) {
                i_error("fd_send(%s) sent only %d of %d bytes",
-                       auth->path, (int)ret, (int)buf->used);
+                       conn->path, (int)ret, (int)buf->used);
                ret = -1;
        }
        if (ret < 0) {
index 395976aa496115ee814a15258518eaa9f57faa8c..91b63550a10e193406273ad1ee6bdbf3c5e43877 100644 (file)
@@ -70,6 +70,8 @@ struct master_auth_request_params {
        /* Client fd to transfer to post-login process or -1 if no fd is
           wanted to be transferred. */
        int client_fd;
+       /* Override master_auth->default_path if non-NULL */
+       const char *socket_path;
 
        /* Authentication request that is sent to post-login process.
           tag is ignored. */