]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-master: Added extensible master_auth_request_full() call.
authorTimo Sirainen <tss@iki.fi>
Tue, 17 Nov 2015 15:11:05 +0000 (17:11 +0200)
committerTimo Sirainen <tss@iki.fi>
Tue, 17 Nov 2015 15:11:05 +0000 (17:11 +0200)
Only the API was changed, no changes to functionality.

src/lib-master/master-auth.c
src/lib-master/master-auth.h
src/login-common/sasl-server.c

index 1e1b3dd93b5ff5ca47b90d237f2c520ae20d0d1b..6ff640e0769630c4e8d6e98ed414046c8a02e669 100644 (file)
@@ -148,11 +148,10 @@ static void master_auth_connection_timeout(struct master_auth_connection *conn)
        master_auth_connection_deinit(&conn);
 }
 
-void master_auth_request(struct master_auth *auth, int fd,
-                        const struct master_auth_request *request,
-                        const unsigned char *data,
-                        master_auth_callback_t *callback,
-                        void *context, unsigned int *tag_r)
+void master_auth_request_full(struct master_auth *auth,
+                             const struct master_auth_request_params *params,
+                             master_auth_callback_t *callback, void *context,
+                             unsigned int *tag_r)
 {
         struct master_auth_connection *conn;
        struct master_auth_request req;
@@ -160,27 +159,27 @@ void master_auth_request(struct master_auth *auth, int fd,
        struct stat st;
        ssize_t ret;
 
-       i_assert(request->client_pid != 0);
-       i_assert(request->auth_pid != 0);
+       i_assert(params->request.client_pid != 0);
+       i_assert(params->request.auth_pid != 0);
 
        conn = i_new(struct master_auth_connection, 1);
        conn->auth = auth;
        conn->callback = callback;
        conn->context = context;
 
-       req = *request;
+       req = params->request;
        req.tag = ++auth->tag_counter;
        if (req.tag == 0)
                req.tag = ++auth->tag_counter;
 
-       if (fstat(fd, &st) < 0)
+       if (fstat(params->client_fd, &st) < 0)
                i_fatal("fstat(auth dest fd) failed: %m");
        req.ino = st.st_ino;
 
        buf = buffer_create_dynamic(pool_datastack_create(),
                                    sizeof(req) + req.data_size);
        buffer_append(buf, &req, sizeof(req));
-       buffer_append(buf, data, req.data_size);
+       buffer_append(buf, params->data, req.data_size);
 
        conn->fd = net_connect_unix_with_retries(auth->path,
                                                 SOCKET_CONNECT_RETRY_MSECS);
@@ -192,10 +191,11 @@ void master_auth_request(struct master_auth *auth, int fd,
                return;
        }
 
-       ret = fd_send(conn->fd, fd, buf->data, buf->used);
-       if (ret < 0)
-               i_error("fd_send(%s, %d) failed: %m", auth->path, fd);
-       else if ((size_t)ret != buf->used) {
+       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,
+                       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);
                ret = -1;
@@ -215,6 +215,22 @@ void master_auth_request(struct master_auth *auth, int fd,
        *tag_r = req.tag;
 }
 
+void master_auth_request(struct master_auth *auth, int fd,
+                        const struct master_auth_request *request,
+                        const unsigned char *data,
+                        master_auth_callback_t *callback,
+                        void *context, unsigned int *tag_r)
+{
+       struct master_auth_request_params params;
+
+       memset(&params, 0, sizeof(params));
+       params.client_fd = fd;
+       params.request = *request;
+       params.data = data;
+
+       master_auth_request_full(auth, &params, callback, context, tag_r);
+}
+
 void master_auth_request_abort(struct master_auth *auth, unsigned int tag)
 {
         struct master_auth_connection *conn;
index fbf7538f320d521a03951584dbb380b0d5afb2ef..395976aa496115ee814a15258518eaa9f57faa8c 100644 (file)
@@ -66,6 +66,18 @@ struct master_auth_reply {
        pid_t mail_pid;
 };
 
+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;
+
+       /* Authentication request that is sent to post-login process.
+          tag is ignored. */
+       struct master_auth_request request;
+       /* Client input of size request.data_size */
+       const unsigned char *data;
+};
+
 /* reply=NULL if the auth lookup was cancelled due to some error */
 typedef void master_auth_callback_t(const struct master_auth_reply *reply,
                                    void *context);
@@ -74,10 +86,13 @@ struct master_auth *
 master_auth_init(struct master_service *service, const char *path);
 void master_auth_deinit(struct master_auth **auth);
 
-/* Send an authentication request. The fd contains the file descriptor to
-   transfer, or -1 if no fd is wanted to be transferred. Returns tag which can
-   be used to abort the request (ie. ignore the reply from master).
-   request->tag is ignored. */
+/* Send an authentication request. Returns tag which can be used to abort the
+   request (ie. ignore the reply from master). */
+void master_auth_request_full(struct master_auth *auth,
+                             const struct master_auth_request_params *params,
+                             master_auth_callback_t *callback, void *context,
+                             unsigned int *tag_r);
+/* For backwards compatibility: */
 void master_auth_request(struct master_auth *auth, int fd,
                         const struct master_auth_request *request,
                         const unsigned char *data,
index 9f3c530f16cc67283eebb69e1171023f2774f344..3a6e0d25d7496d956abed13ec4cd7b386def433f 100644 (file)
@@ -121,6 +121,7 @@ master_auth_callback(const struct master_auth_reply *reply, void *context)
 static void master_send_request(struct anvil_request *anvil_request)
 {
        struct client *client = anvil_request->client;
+       struct master_auth_request_params params;
        struct master_auth_request req;
        const unsigned char *data;
        size_t size;
@@ -151,8 +152,13 @@ static void master_send_request(struct anvil_request *anvil_request)
 
        client->auth_finished = ioloop_time;
        client->master_auth_id = req.auth_id;
-       master_auth_request(master_auth, client->fd, &req, buf->data,
-                           master_auth_callback, client, &client->master_tag);
+
+       memset(&params, 0, sizeof(params));
+       params.client_fd = client->fd;
+       params.request = req;
+       params.data = buf->data;
+       master_auth_request_full(master_auth, &params, master_auth_callback,
+                                client, &client->master_tag);
 }
 
 static void ATTR_NULL(1)