s3:smbd: move sconn->smb1.echo_handler.* to xconn->smb1.echo_handler.*
authorStefan Metzmacher <metze@samba.org>
Fri, 23 May 2014 07:26:26 +0000 (09:26 +0200)
committerMichael Adam <obnox@samba.org>
Wed, 6 Aug 2014 07:51:11 +0000 (09:51 +0200)
This prepares the structures for multi-channel support.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
source3/smbd/globals.h
source3/smbd/msdfs.c
source3/smbd/process.c
source3/smbd/reply.c
source3/smbd/trans2.c

index 63bd731719faa5389484f1d53105fca87df4536c..ba90d47aeadb6e099ca06376f17acb12a6afb760 100644 (file)
@@ -115,7 +115,6 @@ DATA_BLOB negprot_spnego(TALLOC_CTX *ctx, struct smbd_server_connection *sconn);
 
 void smbd_lock_socket(struct smbd_server_connection *sconn);
 void smbd_unlock_socket(struct smbd_server_connection *sconn);
-void smbd_echo_init(struct smbd_server_connection *sconn);
 
 NTSTATUS smbd_do_locking(struct smb_request *req,
                         files_struct *fsp,
@@ -354,6 +353,38 @@ struct smbXsrv_connection {
        } transport;
 
        struct {
+               struct {
+                       /*
+                        * fd for the fcntl lock and process shared
+                        * robust mutex to coordinate access to the
+                        * client socket. When the system supports
+                        * process shared robust mutexes, those are
+                        * used. If not, then the fcntl lock will be
+                        * used.
+                        */
+                       int socket_lock_fd;
+#ifdef HAVE_ROBUST_MUTEXES
+                       pthread_mutex_t *socket_mutex;
+#endif
+
+                       /*
+                        * fd for the trusted pipe from
+                        * echo handler child
+                        */
+                       int trusted_fd;
+
+                       /*
+                        * fde for the trusted_fd
+                        */
+                       struct tevent_fd *trusted_fde;
+
+                       /*
+                        * Reference count for the fcntl lock to
+                        * allow recursive locks.
+                        */
+                       int ref_count;
+               } echo_handler;
+
                struct {
                        bool encrypted_passwords;
                        bool spnego;
@@ -725,39 +756,6 @@ struct smbd_server_connection {
        } oplocks;
 
        struct {
-               struct {
-
-                       /*
-                        * fd for the fcntl lock and process shared
-                        * robust mutex to coordinate access to the
-                        * client socket. When the system supports
-                        * process shared robust mutexes, those are
-                        * used. If not, then the fcntl lock will be
-                        * used.
-                        */
-                       int socket_lock_fd;
-#ifdef HAVE_ROBUST_MUTEXES
-                       pthread_mutex_t *socket_mutex;
-#endif
-
-                       /*
-                        * fd for the trusted pipe from
-                        * echo handler child
-                        */
-                       int trusted_fd;
-
-                       /*
-                        * fde for the trusted_fd
-                        */
-                       struct tevent_fd *trusted_fde;
-
-                       /*
-                        * Reference count for the fcntl lock to
-                        * allow recursive locks.
-                        */
-                       int ref_count;
-               } echo_handler;
-
                struct {
                        uint16_t client_major;
                        uint16_t client_minor;
index 5b38d586c97472d89efe4ec11af5617a2f89b5d8..bbf353d615c81a255796afc590e4471e37bf237c 100644 (file)
@@ -246,7 +246,6 @@ static NTSTATUS create_conn_struct_as_root(TALLOC_CTX *ctx,
 
        sconn->ev_ctx = ev;
        sconn->msg_ctx = msg;
-       smbd_echo_init(sconn);
 
        conn = conn_new(sconn);
        if (conn == NULL) {
index 188d619e7db8599856230edc34ecf339637dd371..daf19476e534fbfda09f2019a139f5feacb31405 100644 (file)
@@ -62,23 +62,23 @@ static struct pending_message_list *get_deferred_open_message_smb(
        struct smbd_server_connection *sconn, uint64_t mid);
 static bool smb_splice_chain(uint8_t **poutbuf, const uint8_t *andx_buf);
 
-void smbd_echo_init(struct smbd_server_connection *sconn)
+static void smbd_echo_init(struct smbXsrv_connection *xconn)
 {
-       sconn->smb1.echo_handler.trusted_fd = -1;
-       sconn->smb1.echo_handler.socket_lock_fd = -1;
+       xconn->smb1.echo_handler.trusted_fd = -1;
+       xconn->smb1.echo_handler.socket_lock_fd = -1;
 #ifdef HAVE_ROBUST_MUTEXES
-       sconn->smb1.echo_handler.socket_mutex = NULL;
+       xconn->smb1.echo_handler.socket_mutex = NULL;
 #endif
 }
 
-static bool smbd_echo_active(struct smbd_server_connection *sconn)
+static bool smbd_echo_active(struct smbXsrv_connection *xconn)
 {
-       if (sconn->smb1.echo_handler.socket_lock_fd != -1) {
+       if (xconn->smb1.echo_handler.socket_lock_fd != -1) {
                return true;
        }
 
 #ifdef HAVE_ROBUST_MUTEXES
-       if (sconn->smb1.echo_handler.socket_mutex != NULL) {
+       if (xconn->smb1.echo_handler.socket_mutex != NULL) {
                return true;
        }
 #endif
@@ -88,25 +88,27 @@ static bool smbd_echo_active(struct smbd_server_connection *sconn)
 
 static bool smbd_lock_socket_internal(struct smbd_server_connection *sconn)
 {
-       if (!smbd_echo_active(sconn)) {
+       struct smbXsrv_connection *xconn = sconn->conn;
+
+       if (!smbd_echo_active(xconn)) {
                return true;
        }
 
-       sconn->smb1.echo_handler.ref_count++;
+       xconn->smb1.echo_handler.ref_count++;
 
-       if (sconn->smb1.echo_handler.ref_count > 1) {
+       if (xconn->smb1.echo_handler.ref_count > 1) {
                return true;
        }
 
        DEBUG(10,("pid[%d] wait for socket lock\n", (int)getpid()));
 
 #ifdef HAVE_ROBUST_MUTEXES
-       if (sconn->smb1.echo_handler.socket_mutex != NULL) {
+       if (xconn->smb1.echo_handler.socket_mutex != NULL) {
                int ret = EINTR;
 
                while (ret == EINTR) {
                        ret = pthread_mutex_lock(
-                               sconn->smb1.echo_handler.socket_mutex);
+                               xconn->smb1.echo_handler.socket_mutex);
                        if (ret == 0) {
                                break;
                        }
@@ -119,12 +121,12 @@ static bool smbd_lock_socket_internal(struct smbd_server_connection *sconn)
        }
 #endif
 
-       if (sconn->smb1.echo_handler.socket_lock_fd != -1) {
+       if (xconn->smb1.echo_handler.socket_lock_fd != -1) {
                bool ok;
 
                do {
                        ok = fcntl_lock(
-                               sconn->smb1.echo_handler.socket_lock_fd,
+                               xconn->smb1.echo_handler.socket_lock_fd,
                                F_SETLKW, 0, 0, F_WRLCK);
                } while (!ok && (errno == EINTR));
 
@@ -148,23 +150,25 @@ void smbd_lock_socket(struct smbd_server_connection *sconn)
 
 static bool smbd_unlock_socket_internal(struct smbd_server_connection *sconn)
 {
-       if (!smbd_echo_active(sconn)) {
+       struct smbXsrv_connection *xconn = sconn->conn;
+
+       if (!smbd_echo_active(xconn)) {
                return true;
        }
 
-       sconn->smb1.echo_handler.ref_count--;
+       xconn->smb1.echo_handler.ref_count--;
 
-       if (sconn->smb1.echo_handler.ref_count > 0) {
+       if (xconn->smb1.echo_handler.ref_count > 0) {
                return true;
        }
 
 #ifdef HAVE_ROBUST_MUTEXES
-       if (sconn->smb1.echo_handler.socket_mutex != NULL) {
+       if (xconn->smb1.echo_handler.socket_mutex != NULL) {
                int ret = EINTR;
 
                while (ret == EINTR) {
                        ret = pthread_mutex_unlock(
-                               sconn->smb1.echo_handler.socket_mutex);
+                               xconn->smb1.echo_handler.socket_mutex);
                        if (ret == 0) {
                                break;
                        }
@@ -177,12 +181,12 @@ static bool smbd_unlock_socket_internal(struct smbd_server_connection *sconn)
        }
 #endif
 
-       if (sconn->smb1.echo_handler.socket_lock_fd != -1) {
+       if (xconn->smb1.echo_handler.socket_lock_fd != -1) {
                bool ok;
 
                do {
                        ok = fcntl_lock(
-                               sconn->smb1.echo_handler.socket_lock_fd,
+                               xconn->smb1.echo_handler.socket_lock_fd,
                                F_SETLKW, 0, 0, F_UNLCK);
                } while (!ok && (errno == EINTR));
 
@@ -498,7 +502,7 @@ static NTSTATUS receive_smb_raw_talloc(TALLOC_CTX *mem_ctx,
            (smb_len_large(lenbuf) > /* Could be a UNIX large writeX. */
                (min_recv_size + STANDARD_WRITE_AND_X_HEADER_SIZE)) &&
            !srv_is_signing_active(xconn) &&
-           sconn->smb1.echo_handler.trusted_fde == NULL) {
+           xconn->smb1.echo_handler.trusted_fde == NULL) {
 
                return receive_smb_raw_talloc_partial_read(
                        mem_ctx, lenbuf, sconn, sock, buffer, timeout,
@@ -2457,13 +2461,13 @@ static void smbd_server_connection_read_handler(
        bool from_client = false;
 
        if (async_echo) {
-               if (fd_is_readable(sconn->smb1.echo_handler.trusted_fd)) {
+               if (fd_is_readable(xconn->smb1.echo_handler.trusted_fd)) {
                        /*
                         * This is the super-ugly hack to prefer the packets
                         * forwarded by the echo handler over the ones by the
                         * client directly
                         */
-                       fd = sconn->smb1.echo_handler.trusted_fd;
+                       fd = xconn->smb1.echo_handler.trusted_fd;
                }
        }
 
@@ -2548,8 +2552,8 @@ static void smbd_server_echo_handler(struct tevent_context *ev,
                /*
                 * we're not supposed to do any io
                 */
-               TEVENT_FD_NOT_READABLE(conn->smb1.echo_handler.trusted_fde);
-               TEVENT_FD_NOT_WRITEABLE(conn->smb1.echo_handler.trusted_fde);
+               TEVENT_FD_NOT_READABLE(xconn->smb1.echo_handler.trusted_fde);
+               TEVENT_FD_NOT_WRITEABLE(xconn->smb1.echo_handler.trusted_fde);
                return;
        }
 
@@ -2559,7 +2563,7 @@ static void smbd_server_echo_handler(struct tevent_context *ev,
        }
        if (flags & TEVENT_FD_READ) {
                smbd_server_connection_read_handler(
-                       conn, conn->smb1.echo_handler.trusted_fd);
+                       conn, xconn->smb1.echo_handler.trusted_fd);
                return;
        }
 }
@@ -3199,6 +3203,7 @@ static void smbd_echo_got_packet(struct tevent_req *req)
  */
 bool fork_echo_handler(struct smbd_server_connection *sconn)
 {
+       struct smbXsrv_connection *xconn = sconn->conn;
        int listener_pipe[2];
        int res;
        pid_t child;
@@ -3216,9 +3221,9 @@ bool fork_echo_handler(struct smbd_server_connection *sconn)
        if (use_mutex) {
                pthread_mutexattr_t a;
 
-               sconn->smb1.echo_handler.socket_mutex =
+               xconn->smb1.echo_handler.socket_mutex =
                        anonymous_shared_allocate(sizeof(pthread_mutex_t));
-               if (sconn->smb1.echo_handler.socket_mutex == NULL) {
+               if (xconn->smb1.echo_handler.socket_mutex == NULL) {
                        DEBUG(1, ("Could not create mutex shared memory: %s\n",
                                  strerror(errno)));
                        goto fail;
@@ -3251,7 +3256,7 @@ bool fork_echo_handler(struct smbd_server_connection *sconn)
                        pthread_mutexattr_destroy(&a);
                        goto fail;
                }
-               res = pthread_mutex_init(sconn->smb1.echo_handler.socket_mutex,
+               res = pthread_mutex_init(xconn->smb1.echo_handler.socket_mutex,
                                         &a);
                pthread_mutexattr_destroy(&a);
                if (res != 0) {
@@ -3263,9 +3268,9 @@ bool fork_echo_handler(struct smbd_server_connection *sconn)
 #endif
 
        if (!use_mutex) {
-               sconn->smb1.echo_handler.socket_lock_fd =
+               xconn->smb1.echo_handler.socket_lock_fd =
                        create_unlink_tmp(lp_lock_directory());
-               if (sconn->smb1.echo_handler.socket_lock_fd == -1) {
+               if (xconn->smb1.echo_handler.socket_lock_fd == -1) {
                        DEBUG(1, ("Could not create lock fd: %s\n",
                                  strerror(errno)));
                        goto fail;
@@ -3292,7 +3297,7 @@ bool fork_echo_handler(struct smbd_server_connection *sconn)
        }
        close(listener_pipe[1]);
        listener_pipe[1] = -1;
-       sconn->smb1.echo_handler.trusted_fd = listener_pipe[0];
+       xconn->smb1.echo_handler.trusted_fd = listener_pipe[0];
 
        DEBUG(10,("fork_echo_handler: main[%d] echo_child[%d]\n", (int)getpid(), (int)child));
 
@@ -3300,13 +3305,13 @@ bool fork_echo_handler(struct smbd_server_connection *sconn)
         * Without smb signing this is the same as the normal smbd
         * listener. This needs to change once signing comes in.
         */
-       sconn->smb1.echo_handler.trusted_fde = tevent_add_fd(sconn->ev_ctx,
+       xconn->smb1.echo_handler.trusted_fde = tevent_add_fd(sconn->ev_ctx,
                                        sconn,
-                                       sconn->smb1.echo_handler.trusted_fd,
+                                       xconn->smb1.echo_handler.trusted_fd,
                                        TEVENT_FD_READ,
                                        smbd_server_echo_handler,
                                        sconn);
-       if (sconn->smb1.echo_handler.trusted_fde == NULL) {
+       if (xconn->smb1.echo_handler.trusted_fde == NULL) {
                DEBUG(1, ("event_add_fd failed\n"));
                goto fail;
        }
@@ -3320,17 +3325,16 @@ fail:
        if (listener_pipe[1] != -1) {
                close(listener_pipe[1]);
        }
-       if (sconn->smb1.echo_handler.socket_lock_fd != -1) {
-               close(sconn->smb1.echo_handler.socket_lock_fd);
+       if (xconn->smb1.echo_handler.socket_lock_fd != -1) {
+               close(xconn->smb1.echo_handler.socket_lock_fd);
        }
-
 #ifdef HAVE_ROBUST_MUTEXES
-       if (sconn->smb1.echo_handler.socket_mutex != NULL) {
-               pthread_mutex_destroy(sconn->smb1.echo_handler.socket_mutex);
-               anonymous_shared_free(sconn->smb1.echo_handler.socket_mutex);
+       if (xconn->smb1.echo_handler.socket_mutex != NULL) {
+               pthread_mutex_destroy(xconn->smb1.echo_handler.socket_mutex);
+               anonymous_shared_free(xconn->smb1.echo_handler.socket_mutex);
        }
 #endif
-       smbd_echo_init(sconn);
+       smbd_echo_init(xconn);
 
        return false;
 }
@@ -3559,6 +3563,7 @@ void smbd_process(struct tevent_context *ev_ctx,
        conn->ev_ctx = ev_ctx;
        conn->msg_ctx = msg_ctx;
        conn->transport.sock = sock_fd;
+       smbd_echo_init(conn);
 
        sconn = talloc_zero(conn, struct smbd_server_connection);
        if (!sconn) {
@@ -3575,7 +3580,6 @@ void smbd_process(struct tevent_context *ev_ctx,
 
        sconn->ev_ctx = ev_ctx;
        sconn->msg_ctx = msg_ctx;
-       smbd_echo_init(sconn);
 
        if (!interactive) {
                smbd_setup_sig_term_handler(sconn);
index d41f4adbdfe39fb6544f043578958920d7e24358..9f9683cce0f3578ba5e6de5e16663b281d3b43f9 100644 (file)
@@ -3344,7 +3344,7 @@ void reply_readbraw(struct smb_request *req)
                return;
        }
 
-       if (sconn->smb1.echo_handler.trusted_fde) {
+       if (xconn->smb1.echo_handler.trusted_fde) {
                DEBUG(2,("SMBreadbraw rejected with NOT_SUPPORTED because of "
                         "'async smb echo handler = yes'\n"));
                reply_readbraw_error(sconn);
@@ -4162,7 +4162,7 @@ void reply_writebraw(struct smb_request *req)
                return;
        }
 
-       if (req->sconn->smb1.echo_handler.trusted_fde) {
+       if (xconn->smb1.echo_handler.trusted_fde) {
                DEBUG(2,("SMBwritebraw rejected with NOT_SUPPORTED because of "
                         "'async smb echo handler = yes'\n"));
                reply_nterror(req, NT_STATUS_NOT_SUPPORTED);
index d00a6db6ee1265b675180c10c1546b4390e2e8e6..ca0ef738f7d9a7de6ea448880ffe24c983fe0bb7 100644 (file)
@@ -3709,6 +3709,7 @@ static void call_trans2setfsinfo(connection_struct *conn,
                                 unsigned int max_data_bytes)
 {
        struct smbd_server_connection *sconn = req->sconn;
+       struct smbXsrv_connection *xconn = sconn->conn;
        char *pdata = *ppdata;
        char *params = *pparams;
        uint16 info_level;
@@ -3819,7 +3820,7 @@ static void call_trans2setfsinfo(connection_struct *conn,
                                        return;
                                }
 
-                               if (req->sconn->smb1.echo_handler.trusted_fde) {
+                               if (xconn->smb1.echo_handler.trusted_fde) {
                                        DEBUG( 2,("call_trans2setfsinfo: "
                                                "request transport encryption disabled"
                                                "with 'fork echo handler = yes'\n"));