s3-auth Remove unused global_machine_account_needs_changing
[mat/samba.git] / source3 / smbd / process.c
index 465f429747098633a99860e6dccea10d05838ed7..80b0c1d79b67a632a9b52077c5096be933ec3e0a 100644 (file)
@@ -41,8 +41,6 @@
 #include "lib/id_cache.h"
 #include "serverid.h"
 
-extern bool global_machine_password_needs_changing;
-
 /* Internal message queue for deferred opens. */
 struct pending_message_list {
        struct pending_message_list *next, *prev;
@@ -516,6 +514,9 @@ static bool init_smb_request(struct smb_request *req,
                             size_t unread_bytes, bool encrypted,
                             uint32_t seqnum)
 {
+       struct smbXsrv_tcon *tcon;
+       NTSTATUS status;
+       NTTIME now;
        size_t req_size = smb_len(inbuf) + 4;
 
        /* Ensure we have at least smb_size bytes. */
@@ -526,6 +527,7 @@ static bool init_smb_request(struct smb_request *req,
        }
 
        req->request_time = timeval_current();
+       now = timeval_to_nttime(&req->request_time);
 
        req->cmd    = CVAL(inbuf, smb_com);
        req->flags2 = SVAL(inbuf, smb_flg2);
@@ -541,7 +543,12 @@ static bool init_smb_request(struct smb_request *req,
        req->unread_bytes = unread_bytes;
        req->encrypted = encrypted;
        req->sconn = sconn;
-       req->conn = conn_find(sconn,req->tid);
+       status = smb1srv_tcon_lookup(sconn->conn, req->tid, now, &tcon);
+       if (NT_STATUS_IS_OK(status)) {
+               req->conn = tcon->compat;
+       } else {
+               req->conn = NULL;
+       }
        req->chain_fsp = NULL;
        req->smb2req = NULL;
        req->priv_paths = NULL;
@@ -709,15 +716,14 @@ void remove_deferred_open_message_smb(struct smbd_server_connection *sconn,
  schedule it for immediate processing.
 ****************************************************************************/
 
-void schedule_deferred_open_message_smb(struct smbd_server_connection *sconn,
+bool schedule_deferred_open_message_smb(struct smbd_server_connection *sconn,
                                        uint64_t mid)
 {
        struct pending_message_list *pml;
        int i = 0;
 
        if (sconn->using_smb2) {
-               schedule_deferred_open_message_smb2(sconn, mid);
-               return;
+               return schedule_deferred_open_message_smb2(sconn, mid);
        }
 
        for (pml = sconn->deferred_open_queue; pml; pml = pml->next) {
@@ -759,13 +765,15 @@ void schedule_deferred_open_message_smb(struct smbd_server_connection *sconn,
                        TALLOC_FREE(pml->te);
                        pml->te = te;
                        DLIST_PROMOTE(sconn->deferred_open_queue, pml);
-                       return;
+                       return true;
                }
        }
 
        DEBUG(10,("schedule_deferred_open_message_smb: failed to "
                "find message mid %llu\n",
                (unsigned long long)mid ));
+
+       return false;
 }
 
 /****************************************************************************
@@ -1361,6 +1369,9 @@ static connection_struct *switch_message(uint8 type, struct smb_request *req)
        uint64_t session_tag;
        connection_struct *conn = NULL;
        struct smbd_server_connection *sconn = req->sconn;
+       NTTIME now = timeval_to_nttime(&req->request_time);
+       struct smbXsrv_session *session = NULL;
+       NTSTATUS status;
 
        errno = 0;
 
@@ -1394,18 +1405,42 @@ static connection_struct *switch_message(uint8 type, struct smb_request *req)
         * JRA.
         */
 
+       /*
+        * lookup an existing session
+        *
+        * Note: for now we only check for NT_STATUS_NETWORK_SESSION_EXPIRED
+        * here, the main check is still in change_to_user()
+        */
+       status = smb1srv_session_lookup(sconn->conn,
+                                       session_tag,
+                                       now,
+                                       &session);
+       if (NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_SESSION_EXPIRED)) {
+               switch (type) {
+               case SMBsesssetupX:
+                       status = NT_STATUS_OK;
+                       break;
+               default:
+                       DEBUG(1,("Error: session %llu is expired, mid=%llu.\n",
+                                (unsigned long long)session_tag,
+                                (unsigned long long)req->mid));
+                       reply_nterror(req, NT_STATUS_NETWORK_SESSION_EXPIRED);
+                       return conn;
+               }
+       }
+
        if (session_tag != sconn->smb1.sessions.last_session_tag) {
                struct user_struct *vuser = NULL;
 
                sconn->smb1.sessions.last_session_tag = session_tag;
-               if(session_tag != UID_FIELD_INVALID) {
-                       vuser = get_valid_user_struct(sconn, session_tag);
-                       if (vuser) {
-                               set_current_user_info(
-                                       vuser->session_info->unix_info->sanitized_username,
-                                       vuser->session_info->unix_info->unix_name,
-                                       vuser->session_info->info->domain_name);
-                       }
+               if (session) {
+                       vuser = session->compat;
+               }
+               if (vuser) {
+                       set_current_user_info(
+                               vuser->session_info->unix_info->sanitized_username,
+                               vuser->session_info->unix_info->unix_name,
+                               vuser->session_info->info->domain_name);
                }
        }
 
@@ -1643,10 +1678,18 @@ void smb_request_done(struct smb_request *req)
 
        while ((next_index < num_reqs) && (IVAL(req->outbuf, smb_rcls) == 0)) {
                struct smb_request *next = reqs[next_index];
+               struct smbXsrv_tcon *tcon;
+               NTTIME now = timeval_to_nttime(&req->request_time);
 
                next->vuid = SVAL(req->outbuf, smb_uid);
                next->tid  = SVAL(req->outbuf, smb_tid);
-               next->conn = conn_find(req->sconn, req->tid);
+               status = smb1srv_tcon_lookup(req->sconn->conn, req->tid,
+                                            now, &tcon);
+               if (NT_STATUS_IS_OK(status)) {
+                       req->conn = tcon->compat;
+               } else {
+                       req->conn = NULL;
+               }
                next->chain_fsp = req->chain_fsp;
                next->inbuf = (uint8_t *)req->inbuf;
 
@@ -2536,9 +2579,6 @@ static bool housekeeping_fn(const struct timeval *now, void *private_data)
        /* check if we need to reload services */
        check_reload(sconn, time_mono(NULL));
 
-       /* Change machine password if neccessary. */
-       attempt_machine_password_change();
-
         /*
         * Force a log file check.
         */
@@ -3157,9 +3197,38 @@ static void smbd_id_cache_kill(struct messaging_context *msg_ctx,
 NTSTATUS smbXsrv_connection_init_tables(struct smbXsrv_connection *conn,
                                        enum protocol_types protocol)
 {
+       NTSTATUS status;
+
        set_Protocol(protocol);
        conn->protocol = protocol;
 
+       if (protocol >= PROTOCOL_SMB2_02) {
+               status = smb2srv_session_table_init(conn);
+               if (!NT_STATUS_IS_OK(status)) {
+                       return status;
+               }
+
+               status = smb2srv_open_table_init(conn);
+               if (!NT_STATUS_IS_OK(status)) {
+                       return status;
+               }
+       } else {
+               status = smb1srv_session_table_init(conn);
+               if (!NT_STATUS_IS_OK(status)) {
+                       return status;
+               }
+
+               status = smb1srv_tcon_table_init(conn);
+               if (!NT_STATUS_IS_OK(status)) {
+                       return status;
+               }
+
+               status = smb1srv_open_table_init(conn);
+               if (!NT_STATUS_IS_OK(status)) {
+                       return status;
+               }
+       }
+
        return NT_STATUS_OK;
 }
 
@@ -3172,6 +3241,11 @@ static void smbd_tevent_trace_callback(enum tevent_trace_point point,
 
        switch (point) {
        case TEVENT_TRACE_BEFORE_WAIT:
+               /*
+                * This just removes compiler warning
+                * without profile support
+                */
+               conn->smbd_idle_profstamp = 0;
                START_PROFILE_STAMP(smbd_idle, conn->smbd_idle_profstamp);
                break;
        case TEVENT_TRACE_AFTER_WAIT:
@@ -3492,10 +3566,7 @@ void smbd_process(struct tevent_context *ev_ctx,
        sconn->smb1.sessions.done_sesssetup = false;
        sconn->smb1.sessions.max_send = BUFFER_SIZE;
        sconn->smb1.sessions.last_session_tag = UID_FIELD_INVALID;
-       /* this holds info on user ids that are already validated for this VC */
-       sconn->smb1.sessions.next_vuid = VUID_OFFSET;
 
-       conn_init(sconn);
        if (!init_dptrs(sconn)) {
                exit_server("init_dptrs() failed");
        }