s3:smbd: Fix converity warning with _smb_setlen_large()
[metze/samba/wip.git] / source3 / smbd / process.c
index 7de26f1388d433627eab54bf1ea8cac745780bd4..936b5351de7cf6b917677c8d618cca9085355841 100644 (file)
@@ -32,7 +32,7 @@
 #include "passdb.h"
 #include "auth.h"
 #include "messages.h"
-#include "lib/messages_ctdbd.h"
+#include "lib/messages_ctdb.h"
 #include "smbprofile.h"
 #include "rpc_server/spoolss/srv_spoolss_nt.h"
 #include "libsmb/libsmb.h"
@@ -41,8 +41,9 @@
 #include "../libcli/security/security_token.h"
 #include "lib/id_cache.h"
 #include "lib/util/sys_rw_data.h"
-#include "serverid.h"
 #include "system/threads.h"
+#include "lib/pthreadpool/pthreadpool_tevent.h"
+#include "util_event.h"
 
 /* Internal message queue for deferred opens. */
 struct pending_message_list {
@@ -163,15 +164,9 @@ static bool smbd_unlock_socket_internal(struct smbXsrv_connection *xconn)
 
 #ifdef HAVE_ROBUST_MUTEXES
        if (xconn->smb1.echo_handler.socket_mutex != NULL) {
-               int ret = EINTR;
-
-               while (ret == EINTR) {
-                       ret = pthread_mutex_unlock(
-                               xconn->smb1.echo_handler.socket_mutex);
-                       if (ret == 0) {
-                               break;
-                       }
-               }
+               int ret;
+               ret = pthread_mutex_unlock(
+                       xconn->smb1.echo_handler.socket_mutex);
                if (ret != 0) {
                        DEBUG(1, ("pthread_mutex_unlock failed: %s\n",
                                  strerror(ret)));
@@ -279,10 +274,10 @@ out:
  Setup the word count and byte count for a smb message.
 ********************************************************************/
 
-int srv_set_message(char *buf,
-                        int num_words,
-                        int num_bytes,
-                        bool zero)
+size_t srv_set_message(char *buf,
+                      size_t num_words,
+                      size_t num_bytes,
+                      bool zero)
 {
        if (zero && (num_words || num_bytes)) {
                memset(buf + smb_size,'\0',num_words*2 + num_bytes);
@@ -1855,12 +1850,13 @@ void smb_request_done(struct smb_request *req)
 
                next->vuid = SVAL(req->outbuf, smb_uid);
                next->tid  = SVAL(req->outbuf, smb_tid);
-               status = smb1srv_tcon_lookup(req->xconn, req->tid,
+               status = smb1srv_tcon_lookup(req->xconn, next->tid,
                                             now, &tcon);
+
                if (NT_STATUS_IS_OK(status)) {
-                       req->conn = tcon->compat;
+                       next->conn = tcon->compat;
                } else {
-                       req->conn = NULL;
+                       next->conn = NULL;
                }
                next->chain_fsp = req->chain_fsp;
                next->inbuf = req->inbuf;
@@ -1973,7 +1969,8 @@ static void process_smb(struct smbXsrv_connection *xconn,
                        size_t pdulen = nread - NBT_HDR_SIZE;
                        smbd_smb2_process_negprot(xconn, 0, inpdu, pdulen);
                        return;
-               } else if (nread >= smb_size && valid_smb_header(inbuf)
+               }
+               if (nread >= smb_size && valid_smb_header(inbuf)
                                && CVAL(inbuf, smb_com) != 0x72) {
                        /* This is a non-negprot SMB1 packet.
                           Disable SMB2 from now on. */
@@ -2775,7 +2772,7 @@ static NTSTATUS smbd_register_ips(struct smbXsrv_connection *xconn,
        struct ctdbd_connection *cconn;
        int ret;
 
-       cconn = messaging_ctdbd_connection();
+       cconn = messaging_ctdb_connection();
        if (cconn == NULL) {
                return NT_STATUS_NO_MEMORY;
        }
@@ -3411,6 +3408,7 @@ bool fork_echo_handler(struct smbXsrv_connection *xconn)
                                  nt_errstr(status)));
                        exit(1);
                }
+               initialize_password_db(true, xconn->ev_ctx);
                smbd_echo_loop(xconn, listener_pipe[1]);
                exit(0);
        }
@@ -3931,6 +3929,12 @@ void smbd_process(struct tevent_context *ev_ctx,
        sconn->ev_ctx = ev_ctx;
        sconn->msg_ctx = msg_ctx;
 
+       ret = pthreadpool_tevent_init(sconn, lp_aio_max_threads(),
+                                     &sconn->pool);
+       if (ret != 0) {
+               exit_server("pthreadpool_tevent_init() failed.");
+       }
+
        if (lp_server_max_protocol() >= PROTOCOL_SMB2_02) {
                /*
                 * We're not making the decision here,
@@ -3945,14 +3949,6 @@ void smbd_process(struct tevent_context *ev_ctx,
        if (!interactive) {
                smbd_setup_sig_term_handler(sconn);
                smbd_setup_sig_hup_handler(sconn);
-
-               if (!serverid_register(messaging_server_id(msg_ctx),
-                                      FLAG_MSG_GENERAL|FLAG_MSG_SMBD
-                                      |FLAG_MSG_DBWRAP
-                                      |FLAG_MSG_PRINT_GENERAL)) {
-                       exit_server_cleanly("Could not register myself in "
-                                           "serverid.tdb");
-               }
        }
 
        status = smbd_add_connection(client, sock_fd, &xconn);