loadparm: make the source3/ lp_ functions take an explicit TALLOC_CTX *.
[obnox/samba/samba-obnox.git] / source3 / smbd / process.c
index 1cff64a3001009b0f9f1ea2229381452e7bbc922..adb773d74972760836a46e46625bdfc971a73da5 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;
@@ -718,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) {
@@ -768,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;
 }
 
 /****************************************************************************
@@ -1370,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;
 
@@ -1403,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);
                }
        }
 
@@ -2553,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.
         */
@@ -3184,6 +3207,11 @@ NTSTATUS smbXsrv_connection_init_tables(struct smbXsrv_connection *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)) {
@@ -3194,6 +3222,11 @@ NTSTATUS smbXsrv_connection_init_tables(struct smbXsrv_connection *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;
@@ -3423,16 +3456,17 @@ void smbd_process(struct tevent_context *ev_ctx,
                exit_server("Could not open account policy tdb.\n");
        }
 
-       if (*lp_rootdir()) {
-               if (chroot(lp_rootdir()) != 0) {
-                       DEBUG(0,("Failed to change root to %s\n", lp_rootdir()));
+       if (*lp_rootdir(talloc_tos())) {
+               if (chroot(lp_rootdir(talloc_tos())) != 0) {
+                       DEBUG(0,("Failed to change root to %s\n",
+                                lp_rootdir(talloc_tos())));
                        exit_server("Failed to chroot()");
                }
                if (chdir("/") == -1) {
-                       DEBUG(0,("Failed to chdir to / on chroot to %s\n", lp_rootdir()));
+                       DEBUG(0,("Failed to chdir to / on chroot to %s\n", lp_rootdir(talloc_tos())));
                        exit_server("Failed to chroot()");
                }
-               DEBUG(0,("Changed root to %s\n", lp_rootdir()));
+               DEBUG(0,("Changed root to %s\n", lp_rootdir(talloc_tos())));
        }
 
        if (!srv_init_signing(sconn)) {