s3:smbd: smbd_[un]lock_socket() while accessing the socket to the client
authorStefan Metzmacher <metze@samba.org>
Thu, 18 Mar 2010 08:23:48 +0000 (09:23 +0100)
committerMichael Adam <obnox@samba.org>
Fri, 26 Mar 2010 11:43:04 +0000 (12:43 +0100)
metze
(cherry picked from commit 977aa660f452d8ebc8f3a2f4bfbf0dda0bc230a2)

source3/smbd/process.c

index 9c3f57166cfefc4ee9cc19b0522b5aa53b1778fa..4bcce1b72a7b0f1a80666036b90678a3065cc0d0 100644 (file)
@@ -51,6 +51,12 @@ bool srv_send_smb(int fd, char *buffer,
        size_t nwritten=0;
        ssize_t ret;
        char *buf_out = buffer;
+       bool ok;
+
+       ok = smbd_lock_socket(smbd_server_conn);
+       if (!ok) {
+               exit_server_cleanly("failed to lock socket");
+       }
 
        if (do_signing) {
                /* Sign the outgoing packet if required. */
@@ -84,6 +90,12 @@ bool srv_send_smb(int fd, char *buffer,
        srv_free_enc_buffer(buf_out);
 out:
        SMB_PERFCOUNT_END(pcd);
+
+       ok = smbd_unlock_socket(smbd_server_conn);
+       if (!ok) {
+               exit_server_cleanly("failed to unlock socket");
+       }
+
        return true;
 }
 
@@ -1889,14 +1901,25 @@ static void smbd_server_connection_read_handler(struct smbd_server_connection *c
        NTSTATUS status;
        uint32_t seqnum;
 
-       /* TODO: make this completely nonblocking */
+       bool ok;
 
+       ok = smbd_lock_socket(conn);
+       if (!ok) {
+               exit_server_cleanly("failed to lock socket");
+       }
+
+       /* TODO: make this completely nonblocking */
        status = receive_smb_talloc(mem_ctx, smbd_server_fd(),
                                    (char **)(void *)&inbuf,
                                    0, /* timeout */
                                    &unread_bytes,
                                    &encrypted,
                                    &inbuf_len, &seqnum);
+       ok = smbd_unlock_socket(conn);
+       if (!ok) {
+               exit_server_cleanly("failed to unlock");
+       }
+
        if (NT_STATUS_EQUAL(status, NT_STATUS_RETRY)) {
                goto process;
        }