Revert "source3/smbd"
authorStefan Metzmacher <metze@samba.org>
Thu, 10 May 2012 16:40:56 +0000 (18:40 +0200)
committerStefan Metzmacher <metze@samba.org>
Thu, 10 May 2012 16:40:56 +0000 (18:40 +0200)
This reverts commit 53ad9d4726deef7c94b6062a19d6057453ddabf9.

26 files changed:
source3/include/smb.h
source3/lib/serverid.c
source3/lib/util.c
source3/locking/locking.c
source3/locking/share_mode_lock.c
source3/smbd/close.c
source3/smbd/files.c
source3/smbd/globals.h
source3/smbd/open.c
source3/smbd/password.c
source3/smbd/smb2_break.c
source3/smbd/smb2_close.c
source3/smbd/smb2_create.c
source3/smbd/smb2_find.c
source3/smbd/smb2_flush.c
source3/smbd/smb2_getinfo.c
source3/smbd/smb2_ioctl.c
source3/smbd/smb2_lock.c
source3/smbd/smb2_negprot.c
source3/smbd/smb2_notify.c
source3/smbd/smb2_read.c
source3/smbd/smb2_server.c
source3/smbd/smb2_sesssetup.c
source3/smbd/smb2_setinfo.c
source3/smbd/smb2_tcon.c
source3/smbd/smb2_write.c

index 147a063e40da4ed0c4bcc150fb04b2fbb0cf56db..529803ce0cf15fdb2b3f6c1d84c4cd5095bd10fa 100644 (file)
@@ -223,7 +223,6 @@ struct print_file_data {
 typedef struct files_struct {
        struct files_struct *next, *prev;
        int fnum;
-       struct smbXsrv_open0 *smbXsrv;
        struct connection_struct *conn;
        struct fd_handle *fh;
        unsigned int num_smb_operations;
@@ -1229,8 +1228,6 @@ typedef struct user_struct {
        struct auth_session_info *session_info;
 
        struct gensec_security *gensec_security;
-
-       struct smbXsrv_session0 *session;
 } user_struct;
 
 /*
index 5e9125c18defecdafc23f0da8676a027f4b96b4c..48d5b4251a18d842ca2d14c20d5457c4bbdc15a0 100644 (file)
@@ -294,8 +294,8 @@ bool serverids_exist(const struct server_id *ids, int num_ids, bool *results)
 
 #ifdef HAVE_CTDB_CONTROL_CHECK_SRVIDS_DECL
        if (lp_clustering()) {
-//             return ctdb_serverids_exist(messaging_ctdbd_connection(),
-//                                         ids, num_ids, results);
+               return ctdb_serverids_exist(messaging_ctdbd_connection(),
+                                           ids, num_ids, results);
        }
 #endif
        if (!processes_exist(ids, num_ids, results)) {
@@ -319,18 +319,6 @@ bool serverids_exist(const struct server_id *ids, int num_ids, bool *results)
                if (!results[i]) {
                        continue;
                }
-#if 0
-       typedef [public] struct {
-               hyper pid;
-               uint32 task_id;
-               uint32 vnn;
-               hyper unique_id;
-       } server_id;
-#endif
-               if (ids[i].unique_id == UINT64_MAX) {
-                       // bug #8760 :-)
-                       continue;
-               }
 
                serverid_fill_key(&ids[i], &key);
                tdbkey = make_tdb_data((uint8_t *)&key, sizeof(key));
index 7ab98040101b12d39b473872d5da7fec90cab430..7913ce9ee7815d6f0a32dd6fd436c5d55b6bfe85 100644 (file)
@@ -724,28 +724,10 @@ bool processes_exist(const struct server_id *pids, int num_pids,
        num_remote_pids = 0;
 
        for (i=0; i<num_pids; i++) {
-               results[i] = false;
-
                if (procid_is_me(&pids[i])) {
                        results[i] = true;
                        continue;
                }
-#if 0
-       typedef [public] struct {
-               hyper pid;
-               uint32 task_id;
-               uint32 vnn;
-               hyper unique_id;
-       } server_id;
-#endif
-               if (pids[i].pid == UINT64_MAX &&
-                   pids[i].task_id == UINT32_MAX &&
-                   pids[i].vnn == UINT32_MAX &&
-                   pids[i].unique_id == UINT64_MAX) {
-                       // bug #8760 :-) :-) ok
-                       results[i] = true;
-                       continue;
-               }
                if (procid_is_local(&pids[i])) {
                        results[i] = ((kill(pids[i].pid,0) == 0) ||
                                      (errno != ESRCH));
index d90e8c679b1cfc2d2bea9e7f4b5a3aafce9e4060..b9afd2392c46f973581e4d930cf8316837179b7c 100644 (file)
@@ -669,23 +669,6 @@ static void fill_deferred_open_entry(struct share_mode_entry *e,
 static void add_share_mode_entry(struct share_mode_data *d,
                                 const struct share_mode_entry *entry)
 {
-       uint32_t i = 0;
-
-       while (i < d->num_share_modes) {
-               struct share_mode_entry *e = &d->share_modes[i];
-               if (e->pid.pid == UINT64_MAX &&
-                   e->pid.task_id == UINT32_MAX &&
-                   e->pid.vnn == UINT32_MAX &&
-                   e->pid.unique_id == UINT64_MAX) {
-                       *e = d->share_modes[d->num_share_modes-1];
-                       d->num_share_modes -= 1;
-                       d->modified = True;
-                       continue;
-               }
-
-               i += 1;
-       }
-
        ADD_TO_ARRAY(d, struct share_mode_entry, *entry,
                     &d->share_modes, &d->num_share_modes);
        d->modified = True;
@@ -764,7 +747,6 @@ static struct share_mode_entry *find_share_mode_entry(struct share_mode_data *d,
 bool del_share_mode(struct share_mode_lock *lck, files_struct *fsp)
 {
        struct share_mode_entry entry, *e;
-       uint32_t i = 0;
 
        /* Don't care about the pid owner being correct here - just a search. */
        fill_share_mode_entry(&entry, fsp, (uid_t)-1, 0, NO_OPLOCK);
@@ -776,22 +758,6 @@ bool del_share_mode(struct share_mode_lock *lck, files_struct *fsp)
        *e = lck->data->share_modes[lck->data->num_share_modes-1];
        lck->data->num_share_modes -= 1;
        lck->data->modified = True;
-
-       while (i < lck->data->num_share_modes) {
-               e = &lck->data->share_modes[i];
-
-               if (e->pid.pid == UINT64_MAX &&
-                   e->pid.task_id == UINT32_MAX &&
-                   e->pid.vnn == UINT32_MAX &&
-                   e->pid.unique_id == UINT64_MAX) {
-                       *e = lck->data->share_modes[lck->data->num_share_modes-1];
-                       lck->data->num_share_modes -= 1;
-                       continue;
-               }
-
-               i += 1;
-       }
-
        return True;
 }
 
index ed19c32b9c063c6e6a0a10a6a99b7ba437fd8a7e..de8cc3ce8bde1824030c36a1aeffdc204237880c 100644 (file)
@@ -147,26 +147,7 @@ static struct share_mode_data *parse_share_modes(TALLOC_CTX *mem_ctx,
                DEBUG(10, ("parse_share_modes:\n"));
                NDR_PRINT_DEBUG(share_mode_data, d);
        }
-#if 0
-       typedef [public] struct {
-               hyper pid;
-               uint32 task_id;
-               uint32 vnn;
-               hyper unique_id;
-       } server_id;
-#endif
-       if (d->num_share_modes == 1) {
-               struct share_mode_entry *e = &d->share_modes[0];
-
-               if (e->pid.pid == UINT64_MAX &&
-                   e->pid.task_id == UINT32_MAX &&
-                   e->pid.vnn == UINT32_MAX &&
-                   e->pid.unique_id == UINT64_MAX) {
-                       return d;
-               }
-       }
 
-//return d;
        /*
         * Ensure that each entry has a real process attached.
         */
@@ -202,16 +183,6 @@ static struct share_mode_data *parse_share_modes(TALLOC_CTX *mem_ctx,
                        d->modified = True;
                        continue;
                }
-               if (e->pid.pid == UINT64_MAX &&
-                   e->pid.task_id == UINT32_MAX &&
-                   e->pid.vnn == UINT32_MAX &&
-                   e->pid.unique_id == UINT64_MAX) {
-                       *e = d->share_modes[d->num_share_modes-1];
-                       d->num_share_modes -= 1;
-                       d->modified = True;
-                       continue;
-               }
-
                i += 1;
        }
        TALLOC_FREE(pid_exists);
index 08acd508af74e66811de5bb172af2cdcd4fc70e0..c87b1a000be41b4d022d6732390147e46e2182b6 100644 (file)
@@ -679,71 +679,6 @@ static NTSTATUS close_normal_file(struct smb_request *req, files_struct *fsp,
                        status, map_nt_error_from_unix(ret));
        }
 
-       if (fsp->smbXsrv->global->durable && close_type == SHUTDOWN_CLOSE) {
-               struct share_mode_lock *lck;
-
-               lck = get_existing_share_mode_lock(talloc_tos(), fsp->file_id);
-               if (lck != NULL && lck->data->num_share_modes == 1) {
-                       lck->data->share_modes[0].pid.pid = UINT64_MAX;
-                       lck->data->share_modes[0].pid.task_id = UINT32_MAX;
-                       lck->data->share_modes[0].pid.vnn = UINT32_MAX;
-                       lck->data->share_modes[0].pid.unique_id = UINT64_MAX; //todo place NTTIME expire timer here
-                       lck->data->modified = true;
-#if 0
-               } else if (lck != NULL) {
-                       uint32_t i;
-
-                       for (i=0; i < lck->data->num_share_modes; i++) {
-                               struct share_mode_entry *e = &lck->data->share_modes[i];
-                               char msg[MSG_SMB_SHARE_MODE_ENTRY_SIZE];
-
-                               if (procid_is_me(&e->pid)) {
-                                       continue;
-                               }
-
-                               share_mode_entry_to_message(msg, e);
-
-                               messaging_send_buf(fsp->conn->sconn->msg_ctx,
-                                                  e->pid,
-                                                  MSG_SMB_BREAK_RESPONSE,
-                                                  (uint8 *)msg,
-                                                  MSG_SMB_SHARE_MODE_ENTRY_SIZE);
-                       }
-               }
-#endif
-
-                       tmp = close_filestruct(fsp);
-                       status = ntstatus_keeperror(status, tmp);
-
-                       if (fsp->oplock_type == LEVEL_II_OPLOCK) {
-                               level_II_oplocks_open--;
-                       } else if (EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type)) {
-                               exclusive_oplocks_open--;
-                       }
-
-                       SMB_ASSERT(exclusive_oplocks_open>=0);
-                       SMB_ASSERT(level_II_oplocks_open>=0);
-
-                       TALLOC_FREE(lck);
-
-                       tmp = fd_close(fsp);
-                       status = ntstatus_keeperror(status, tmp);
-                       file_free(req, fsp);
-                       return status;
-               }
-
-               TALLOC_FREE(lck);
-
-#if 0
-               TALLOC_FREE(lck);
-
-               tmp = fd_close(fsp);
-               status = ntstatus_keeperror(status, tmp);
-               file_free(req, fsp);
-               return status;
-#endif
-       }
-
        /*
         * If we're flushing on a close we can get a write
         * error here, we must remember this.
index 6e73e2fbb36f3ad862795f1b9d63fc18489d767b..8a9f0555308021769eca0cedd132d57cd892c8fa 100644 (file)
@@ -25,6 +25,8 @@
 #include <ccan/hash/hash.h>
 #include "lib/util/bitmap.h"
 
+#define VALID_FNUM(fnum)   (((fnum) >= 0) && ((fnum) < real_max_open_files))
+
 #define FILE_HANDLE_OFFSET 0x1000
 
 /****************************************************************************
@@ -37,7 +39,6 @@ static unsigned long get_gen_count(struct smbd_server_connection *sconn)
        if (sconn->file_gen_counter == 0) {
                sconn->file_gen_counter += 1;
        }
-
        return sconn->file_gen_counter;
 }
 
@@ -49,10 +50,30 @@ NTSTATUS file_new(struct smb_request *req, connection_struct *conn,
                  files_struct **result)
 {
        struct smbd_server_connection *sconn = conn->sconn;
+       int i;
        files_struct *fsp;
        NTSTATUS status;
-       struct smbXsrv_open *op;
-       NTTIME now = 0;
+
+       /* we want to give out file handles differently on each new
+          connection because of a common bug in MS clients where they try to
+          reuse a file descriptor from an earlier smb connection. This code
+          increases the chance that the errant client will get an error rather
+          than causing corruption */
+       if (sconn->first_file == 0) {
+               sconn->first_file = (getpid() ^ (int)time(NULL));
+               sconn->first_file %= sconn->real_max_open_files;
+       }
+
+       /* TODO: Port the id-tree implementation from Samba4 */
+
+       i = bitmap_find(sconn->file_bmap, sconn->first_file);
+       if (i == -1) {
+               DEBUG(0,("ERROR! Out of file structures\n"));
+               /* TODO: We have to unconditionally return a DOS error here,
+                * W2k3 even returns ERRDOS/ERRnofids for ntcreate&x with
+                * NTSTATUS negotiated */
+               return NT_STATUS_TOO_MANY_OPENED_FILES;
+       }
 
        /*
         * Make a child of the connection_struct as an fsp can't exist
@@ -81,27 +102,12 @@ NTSTATUS file_new(struct smb_request *req, connection_struct *conn,
        fsp->fh->gen_id = get_gen_count(sconn);
        GetTimeOfDay(&fsp->open_time);
 
-       if (sconn->conn) {
-               status = smbXsrv_open_create(sconn->conn, now, &op);
-               if (!NT_STATUS_IS_OK(status)) {
-                       TALLOC_FREE(fsp);
-                       return status;
-               }
-               fsp->smbXsrv = op;
-               op->fsp = fsp;
-               fsp->fnum = op->local_id;
-       } else {
-               /*
-                * hack for printer driver upload
-                */
-/*             if (sconn->files_used > 0) {
-                       TALLOC_FREE(fsp);
-                       return NT_STATUS_INSUFFICIENT_RESOURCES;
-               }
-*/             fsp->fnum = -1;
-       }
+       sconn->first_file = (i+1) % (sconn->real_max_open_files);
+
+       bitmap_set(sconn->file_bmap, i);
 
-       //talloc_set_destructor(fsp, smbd_fsp_destructor);
+       fsp->fnum = i + FILE_HANDLE_OFFSET;
+       SMB_ASSERT(fsp->fnum < 65536);
 
        /*
         * Create an smb_filename with "" for the base_name.  There are very
@@ -118,8 +124,8 @@ NTSTATUS file_new(struct smb_request *req, connection_struct *conn,
        DLIST_ADD(sconn->files, fsp);
        sconn->num_files += 1;
 
-       DEBUG(5,("allocated file structure, fnum = %d (%u used)\n",
-                fsp->fnum, (unsigned int)sconn->num_files));
+       DEBUG(5,("allocated file structure %d, fnum = %d (%u used)\n",
+                i, fsp->fnum, (unsigned int)sconn->num_files));
 
        if (req != NULL) {
                req->chain_fsp = fsp;
@@ -148,12 +154,7 @@ void file_close_conn(connection_struct *conn)
 
        for (fsp=conn->sconn->files; fsp; fsp=next) {
                next = fsp->next;
-               if (fsp->conn != conn) {
-                       continue;
-               }
-               if (conn->sconn->using_smb2 && fsp->smbXsrv->global->durable) {
-                       close_file(NULL, fsp, NORMAL_CLOSE);
-               } else {
+               if (fsp->conn == conn) {
                        close_file(NULL, fsp, SHUTDOWN_CLOSE);
                }
        }
@@ -207,6 +208,11 @@ bool file_init(struct smbd_server_connection *sconn)
 
        SMB_ASSERT(sconn->real_max_open_files > 100);
 
+       sconn->file_bmap = bitmap_talloc(sconn, sconn->real_max_open_files);
+
+       if (!sconn->file_bmap) {
+               return false;
+       }
        return true;
 }
 
@@ -450,8 +456,7 @@ void file_free(struct smb_request *req, files_struct *fsp)
        /* Ensure this event will never fire. */
        TALLOC_FREE(fsp->update_write_time_event);
 
-       TALLOC_FREE(fsp->smbXsrv);
-
+       bitmap_clear(sconn->file_bmap, fsp->fnum - FILE_HANDLE_OFFSET);
        DEBUG(5,("freed files structure %d (%u used)\n",
                 fsp->fnum, (unsigned int)sconn->num_files));
 
@@ -494,24 +499,9 @@ void file_free(struct smb_request *req, files_struct *fsp)
 static struct files_struct *file_fnum(struct smbd_server_connection *sconn,
                                      uint16 fnum)
 {
-       NTSTATUS status;
-       struct smbXsrv_open *op;
-       NTTIME now = 0;
        files_struct *fsp;
        int count=0;
 
-       if (sconn->conn == NULL) {
-               return NULL;
-       }
-
-       status = smb1srv_open_lookup(&sconn->conn->open_table,
-                                    fnum, now, &op);
-       if (!NT_STATUS_IS_OK(status)) {
-               return NULL;
-       }
-
-       return op->fsp;
-
        for (fsp=sconn->files; fsp; fsp=fsp->next, count++) {
                if (fsp->fnum == fnum) {
                        if (count > 10) {
index af83c0a9a3eb2a10467513cc3f32b1b951937dfe..b3ddba3ffd3dee949a0ff5ebcd6b463d504209b3 100644 (file)
@@ -387,10 +387,12 @@ NTSTATUS smbXsrv_open_create(struct smbXsrv_connection *conn,
                                NTTIME now,
                                struct smbXsrv_open **_open);
 NTSTATUS smbXsrv_open_update(struct smbXsrv_open *_open);
+
 NTSTATUS smb1srv_open_table_init(struct smbXsrv_connection *conn);
 NTSTATUS smb1srv_open_lookup(struct smbXsrv_open_table *table,
                                uint16_t vuid, NTTIME now,
                                struct smbXsrv_open **_open);
+
 NTSTATUS smb2srv_open_table_init(struct smbXsrv_connection *conn);
 NTSTATUS smb2srv_open_lookup(struct smbXsrv_open_table *table,
                                uint64_t open_id, NTTIME now,
@@ -490,10 +492,8 @@ struct smbd_smb2_session {
        uint64_t vuid;
        struct gensec_security *gensec_security;
        struct auth_session_info *session_info;
-       //DATA_BLOB session_key;
-       //bool do_signing;
-
-       struct smbXsrv_session *smbXsrv;
+       DATA_BLOB session_key;
+       bool do_signing;
 
        user_struct *compat_vuser;
 
@@ -543,9 +543,11 @@ struct smbd_server_connection {
        size_t num_files;
        struct files_struct *files;
 
+       struct bitmap *file_bmap;
        int real_max_open_files;
        struct fsp_singleton_cache fsp_fi_cache;
        unsigned long file_gen_counter;
+       int first_file;
 
        struct pending_message_list *deferred_open_queue;
 
@@ -648,6 +650,14 @@ struct smbd_server_connection {
                struct tstream_context *stream;
                bool negprot_2ff;
                struct {
+                       /* an id tree used to allocate vuids */
+                       /* this holds info on session vuids that are already
+                        * validated for this VC */
+                       struct idr_context *idtree;
+
+                       /* this is the limit of vuid values for this connection */
+                       uint64_t limit;
+
                        struct smbd_smb2_session *list;
                } sessions;
                struct {
@@ -665,8 +675,6 @@ struct smbd_server_connection {
                bool supports_multicredit;
                struct bitmap *credits_bitmap;
                bool compound_related_in_progress;
-               DATA_BLOB serverguid;
-               uint32_t capabilities;
        } smb2;
 
        struct smbXsrv_connection *conn;
index 0d46650b89565804d8cfda478e39ef66ad106ab7..543a6619e9dec881e3f028cfb233cd4dc1971406 100644 (file)
@@ -821,10 +821,6 @@ static bool share_conflict(struct share_mode_entry *entry,
                  (unsigned int)entry->share_access,
                  (unsigned int)entry->private_options));
 
-       if (entry->pid.pid == UINT64_MAX) {
-               return false;
-       }
-
        DEBUG(10,("share_conflict: access_mask = 0x%x, share_access = 0x%x\n",
                  (unsigned int)access_mask, (unsigned int)share_access));
 
@@ -1169,11 +1165,6 @@ static bool delay_for_batch_oplocks(files_struct *fsp,
                return false;
        }
 
-       if (batch_entry->pid.pid == UINT64_MAX) {
-               /* TODO: clean up */
-               return false;
-       }
-
        /* Found a batch oplock */
        send_break_message(fsp, batch_entry, mid, oplock_request);
        return true;
@@ -1193,11 +1184,6 @@ static bool delay_for_exclusive_oplocks(files_struct *fsp,
                return false;
        }
 
-       if (ex_entry->pid.pid == UINT64_MAX) {
-               /* TODO: clean up */
-               return false;
-       }
-
        /* Found an exclusive or batch oplock */
 
        delay_it = is_delete_request(fsp) ?
index 42e4eb47991da17e3d78526f182bc6ef3fbcdc54..2a76d830b50018396ad917492feb5287cf62278f 100644 (file)
@@ -170,7 +170,6 @@ static void increment_next_vuid(uint16_t *vuid)
 int register_initial_vuid(struct smbd_server_connection *sconn)
 {
        user_struct *vuser;
-       NTSTATUS status;
 
        /* Limit allowed vuids to 16bits - VUID_OFFSET. */
        if (sconn->num_users >= 0xFFFF-VUID_OFFSET) {
@@ -205,12 +204,6 @@ int register_initial_vuid(struct smbd_server_connection *sconn)
        sconn->num_users++;
        DLIST_ADD(sconn->users, vuser);
 
-       status = smbXsrv_session_create(sconn->conn,
-                                       0, /* now */
-                                       &vuser->session);
-       DEBUG(0,("%s: smbXsrv_session_create() %s\n",
-               __location__, nt_errstr(status)));
-
        return vuser->vuid;
 }
 
index 79d8a3af1d0d2db521d6611196ab7e20369abf1a..310b24bb393343e55639adb13c798c2c58df5236 100644 (file)
@@ -29,7 +29,6 @@ static struct tevent_req *smbd_smb2_oplock_break_send(TALLOC_CTX *mem_ctx,
                                                      struct tevent_context *ev,
                                                      struct smbd_smb2_request *smb2req,
                                                      uint8_t in_oplock_level,
-                                                     uint64_t in_file_id_persistent,
                                                      uint64_t in_file_id_volatile);
 static NTSTATUS smbd_smb2_oplock_break_recv(struct tevent_req *req,
                                            uint8_t *out_oplock_level);
@@ -63,11 +62,16 @@ NTSTATUS smbd_smb2_request_process_break(struct smbd_smb2_request *req)
        in_file_id_persistent           = BVAL(inbody, 0x08);
        in_file_id_volatile             = BVAL(inbody, 0x10);
 
+       if (req->compat_chain_fsp) {
+               /* skip check */
+       } else if (in_file_id_persistent != in_file_id_volatile) {
+               return smbd_smb2_request_error(req, NT_STATUS_FILE_CLOSED);
+       }
+
        subreq = smbd_smb2_oplock_break_send(req,
                                             req->sconn->ev_ctx,
                                             req,
                                             in_oplock_level,
-                                            in_file_id_persistent,
                                             in_file_id_volatile);
        if (subreq == NULL) {
                return smbd_smb2_request_error(req, NT_STATUS_NO_MEMORY);
@@ -145,7 +149,6 @@ static struct tevent_req *smbd_smb2_oplock_break_send(TALLOC_CTX *mem_ctx,
                                                      struct tevent_context *ev,
                                                      struct smbd_smb2_request *smb2req,
                                                      uint8_t in_oplock_level,
-                                                     uint64_t in_file_id_persistent,
                                                      uint64_t in_file_id_volatile)
 {
        struct tevent_req *req;
@@ -180,12 +183,6 @@ static struct tevent_req *smbd_smb2_oplock_break_send(TALLOC_CTX *mem_ctx,
                tevent_req_nterror(req, NT_STATUS_FILE_CLOSED);
                return tevent_req_post(req, ev);
        }
-       if (smb2req->compat_chain_fsp) {
-               /* skip check */
-       } else if (in_file_id_persistent != fsp->smbXsrv->global->open_persistent_id) {
-               tevent_req_nterror(req, NT_STATUS_FILE_CLOSED);
-               return tevent_req_post(req, ev);
-       }
        if (conn != fsp->conn) {
                tevent_req_nterror(req, NT_STATUS_FILE_CLOSED);
                return tevent_req_post(req, ev);
@@ -267,8 +264,8 @@ void send_break_message_smb2(files_struct *fsp, int level)
                (unsigned int)smb2_oplock_level ));
 
        status = smbd_smb2_send_oplock_break(fsp->conn->sconn,
-                                       (uint64_t)fsp->smbXsrv->global->open_persistent_id,
-                                       (uint64_t)fsp->smbXsrv->global->open_volatile_id,
+                                       (uint64_t)fsp->fnum,
+                                       (uint64_t)fsp->fnum,
                                        smb2_oplock_level);
        if (!NT_STATUS_IS_OK(status)) {
                smbd_server_connection_terminate(fsp->conn->sconn,
index c3fb62ce9d675a67d4bd89f200825ff307dac80e..2cc8266fe171d87f85cf2490acbe7fd03825488f 100644 (file)
@@ -25,7 +25,6 @@
 
 static NTSTATUS smbd_smb2_close(struct smbd_smb2_request *req,
                                uint16_t in_flags,
-                               uint64_t in_file_id_persistent,
                                uint64_t in_file_id_volatile,
                                DATA_BLOB *outbody);
 
@@ -54,9 +53,14 @@ NTSTATUS smbd_smb2_request_process_close(struct smbd_smb2_request *req)
        in_file_id_persistent   = BVAL(inbody, 0x08);
        in_file_id_volatile     = BVAL(inbody, 0x10);
 
+       if (req->compat_chain_fsp) {
+               /* skip check */
+       } else if (in_file_id_persistent != in_file_id_volatile) {
+               return smbd_smb2_request_error(req, NT_STATUS_FILE_CLOSED);
+       }
+
        status = smbd_smb2_close(req,
                                in_flags,
-                               in_file_id_persistent,
                                in_file_id_volatile,
                                &outbody);
        if (!NT_STATUS_IS_OK(status)) {
@@ -68,7 +72,6 @@ NTSTATUS smbd_smb2_request_process_close(struct smbd_smb2_request *req)
 
 static NTSTATUS smbd_smb2_close(struct smbd_smb2_request *req,
                                uint16_t in_flags,
-                               uint64_t in_file_id_persistent,
                                uint64_t in_file_id_volatile,
                                DATA_BLOB *outbody)
 {
@@ -101,11 +104,6 @@ static NTSTATUS smbd_smb2_close(struct smbd_smb2_request *req,
        if (fsp == NULL) {
                return NT_STATUS_FILE_CLOSED;
        }
-       if (req->compat_chain_fsp) {
-               /* skip check */
-       } else if (in_file_id_persistent != fsp->smbXsrv->global->open_persistent_id) {
-               return NT_STATUS_FILE_CLOSED;
-       }
        if (conn != fsp->conn) {
                return NT_STATUS_FILE_CLOSED;
        }
index 95f8cd6b8ee3e0219edf7b3b820a6e3851c70009..35be32823143595c07d59c444973b13890d2febe 100644 (file)
 #include "smbd/globals.h"
 #include "../libcli/smb/smb_common.h"
 #include "../librpc/gen_ndr/ndr_security.h"
-#include "libcli/security/security.h"
 #include "../lib/util/tevent_ntstatus.h"
 #include "messages.h"
-#include "librpc/gen_ndr/open_files.h"
-#include "serverid.h"
 
 int map_smb2_oplock_levels_to_samba(uint8_t in_oplock_level)
 {
@@ -391,209 +388,6 @@ static void smbd_smb2_request_create_done(struct tevent_req *tsubreq)
        }
 }
 
-/*
- * TODO: needs to be moved - copied from source3/smbd/files.c
- */
-static unsigned long get_gen_count(struct smbd_server_connection *sconn)
-{
-       sconn->file_gen_counter += 1;
-       if (sconn->file_gen_counter == 0) {
-               sconn->file_gen_counter += 1;
-       }
-
-       return sconn->file_gen_counter;
-}
-
-static NTSTATUS new_durable_reconnect_fsp(struct smbXsrv_open *op,
-                                         struct connection_struct *conn,
-                                         struct smb_filename *smb_fname,
-                                         TALLOC_CTX *mem_ctx,
-                                         files_struct **_fsp)
-{
-       NTSTATUS status = NT_STATUS_NO_MEMORY;
-       files_struct *fsp = NULL;
-       TALLOC_CTX *frame = talloc_stackframe();
-       struct smbd_server_connection *sconn = op->connection->sconn;
-
-       fsp = talloc_zero(frame, struct files_struct);
-       if (fsp == NULL) {
-               goto fail;
-       }
-
-       /*
-        * This can't be a child of fsp because the file_handle can be ref'd
-        * when doing a dos/fcb open, which will then share the file_handle
-        * across multiple fsps.
-        */
-       fsp->fh = talloc_zero(frame, struct fd_handle);
-       if (fsp->fh == NULL) {
-               goto fail;
-       }
-
-       fsp->fh->ref_count = 1;
-       fsp->fh->fd = -1;
-       fsp->fh->gen_id = get_gen_count(sconn);
-
-       fsp->conn = conn;
-
-       status = fsp_set_smb_fname(fsp, smb_fname);
-       if (!NT_STATUS_IS_OK(status)) {
-               goto fail;
-       }
-
-
-
-       /* success */
-
-       talloc_steal(mem_ctx, fsp);
-       talloc_steal(mem_ctx, fsp->fh);
-       *_fsp = fsp;
-
-       status = NT_STATUS_OK;
-
-fail:
-       talloc_free(frame);
-       return status;
-}
-
-static NTSTATUS smb2_create_durable_reconnect(struct smbXsrv_open *op,
-                                             struct connection_struct *conn,
-                                             struct smb_request *smb1req,
-                                             struct smb_filename *smb_fname,
-                                             TALLOC_CTX *mem_ctx,
-                                             files_struct **_fsp,
-                                             int *info)
-{
-       struct share_mode_lock *sharemode_lock;
-       struct share_mode_entry *e;
-       files_struct *fsp = NULL;
-       NTSTATUS status;
-       bool ok;
-
-DEBUG(0, ("OBNOX - durable_reconnect enter: (%s:%s)\n", __location__, __FUNCTION__));
-
-       /* 1. check entry in locking.tdb */
-
-       sharemode_lock = get_existing_share_mode_lock(mem_ctx,
-                                       op->global->backend_file_id);
-       if (sharemode_lock == NULL) {
-               /* TODO: use/create other fetch func with better error code */
-DEBUG(0, ("OBNOX - durable_reconnect: share-mode lock not obtained from db (%s:%s)\n", __location__, __FUNCTION__));
-               return NT_STATUS_OBJECT_NAME_NOT_FOUND;
-       }
-
-       if (sharemode_lock->data->num_share_modes == 0) {
-               /* should not happen? internal error? */
-DEBUG(0, ("OBNOX - durable_reconnect: no share-mode entry (%s:%s)\n", __location__, __FUNCTION__));
-               return NT_STATUS_INTERNAL_DB_ERROR;
-       }
-
-       if (sharemode_lock->data->num_share_modes > 1) {
-               /*
-                * It can't be durable if there is more than one handle
-                * on the file.
-                */
-DEBUG(0, ("OBNOX - durable_reconnect: more than one share-mode entry - can't be durable (%s:%s)\n", __location__, __FUNCTION__));
-               return NT_STATUS_OBJECT_NAME_NOT_FOUND;
-       }
-
-       e = &sharemode_lock->data->share_modes[0];
-
-       if (e->pid.pid != UINT64_MAX && serverid_exists(&e->pid))  {
-               /*
-                * server still exists
-                * TODO: check whether session exists
-                *  (could have been a session_logoff())
-                */
-DEBUG(0, ("OBNOX - durable_reconnect: serverid exists - denying access to durable (%s:%s)\n", __location__, __FUNCTION__));
-               return NT_STATUS_OBJECT_NAME_NOT_FOUND;
-       }
-
-       /* 2. proceed with opening file */
-
-       /*
-        * circumstances seems ok, do the open
-        */
-       status = new_durable_reconnect_fsp(op, conn, smb_fname, conn, &fsp);
-       if (!NT_STATUS_IS_OK(status)) {
-DEBUG(0, ("OBNOX - durable_reconnect: failed to create new fsp: %s (%s:%s)\n", nt_errstr(status), __location__, __FUNCTION__));
-               return status;
-       }
-
-DEBUG(0, ("OBNOX - durable_reconnect: new fsp created (%s:%s)\n", __location__, __FUNCTION__));
-
-       fsp->fh->private_options = e->private_options;
-       fsp->file_id = op->global->backend_file_id;
-       fsp->initial_allocation_size = 0;//TODO
-       fsp->file_pid = smb1req->smbpid;
-       fsp->vuid = smb1req->vuid;//
-       fsp->open_time = e->time;
-       fsp->access_mask = e->access_mask;
-       fsp->share_access = e->share_access;
-       fsp->can_lock = true;//from->can_lock;
-       fsp->can_read = (fsp->access_mask & (FILE_READ_DATA)) ? True : False;
-       if (!CAN_WRITE(conn)) {
-               fsp->can_write = False;
-       } else {
-               fsp->can_write = (fsp->access_mask & (FILE_WRITE_DATA | FILE_APPEND_DATA)) ? True : False;
-       }
-       fsp->modified = false;//from->modified;
-       fsp->is_directory = false;//from->is_directory;
-       fsp->aio_write_behind = false;//from->aio_write_behind;
-
-       fsp->oplock_type = e->op_type;
-
-
-       sharemode_lock->data->modified = true;
-       e->pid = messaging_server_id(op->connection->sconn->msg_ctx);
-       e->op_mid = smb1req->mid;
-       e->share_file_id = fsp->fh->gen_id;
-
-DEBUG(0, ("OBNOX - durable_reconnect: before open file (%s:%s)\n", __location__, __FUNCTION__));
-
-
-       fsp->fh->fd = SMB_VFS_OPEN(conn,
-                                  smb_fname,
-                                  fsp,
-                                  e->flags | O_RDWR, /* TODO: parse open flags */
-                                  0 /* mode */);
-       if (fsp->fh->fd == -1) {
-               status = map_nt_error_from_unix(errno);
-DEBUG(0, ("OBNOX - durable_reconnect: failed to open file: %s (%s:%s)\n", nt_errstr(status), __location__, __FUNCTION__));
-               return status;
-       }
-
-       ok = set_file_oplock(fsp, e->op_type);
-
-       DLIST_ADD(conn->sconn->files, fsp);
-       conn->sconn->num_files += 1;
-
-       DEBUG(5,("allocated file structure, fnum = %d (%d used)\n",
-                fsp->fnum, (unsigned int)conn->sconn->num_files));
-
-       smb1req->chain_fsp = fsp;
-
-DEBUG(0, ("OBNOX - durable_reconnect: opened file (%s:%s)\n", __location__, __FUNCTION__));
-
-       /* - release the sharemode lock: this writes the changes */
-       talloc_free(sharemode_lock);
-
-
-       /* Q: do this in fsp creation? */
-       op->fsp = fsp;
-       fsp->smbXsrv = op;
-       *_fsp = fsp;
-
-       /*
-        * - return
-        *
-        * ... think about seek()
-        */
-
-       *info = FILE_WAS_OPENED;
-       return NT_STATUS_OK;
-}
-
 struct smbd_smb2_create_state {
        struct smbd_smb2_request *smb2req;
        struct smb_request *smb1req;
@@ -638,7 +432,6 @@ static struct tevent_req *smbd_smb2_create_send(TALLOC_CTX *mem_ctx,
        struct timespec write_time_ts;
        struct smb2_create_blobs out_context_blobs;
        int requested_oplock_level;
-       struct smbXsrv_open *op = NULL;
 
        ZERO_STRUCT(out_context_blobs);
 
@@ -725,12 +518,6 @@ static struct tevent_req *smbd_smb2_create_send(TALLOC_CTX *mem_ctx,
                uint64_t allocation_size = 0;
                struct smb2_create_blob *twrp = NULL;
                struct smb2_create_blob *qfid = NULL;
-               struct smb2_create_blob *dh2q = NULL;
-               struct smb2_create_blob *dh2c = NULL;
-               bool do_durable_reconnect = false;
-               bool persistent_requested = false;
-               bool persistent_granted = false;
-               uint32_t durable_v2_timeout = 0;
 
                exta = smb2_create_blob_find(&in_context_blobs,
                                             SMB2_CREATE_TAG_EXTA);
@@ -748,10 +535,6 @@ static struct tevent_req *smbd_smb2_create_send(TALLOC_CTX *mem_ctx,
                                             SMB2_CREATE_TAG_TWRP);
                qfid = smb2_create_blob_find(&in_context_blobs,
                                             SMB2_CREATE_TAG_QFID);
-               dh2q = smb2_create_blob_find(&in_context_blobs,
-                                            SMB2_CREATE_TAG_DH2Q);
-               dh2c = smb2_create_blob_find(&in_context_blobs,
-                                            SMB2_CREATE_TAG_DH2C);
 
                fname = talloc_strdup(state, in_name);
                if (tevent_req_nomem(fname, req)) {
@@ -823,108 +606,20 @@ static struct tevent_req *smbd_smb2_create_send(TALLOC_CTX *mem_ctx,
                                tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
                                return tevent_req_post(req, ev);
                        }
-
-
-                       /*
-                        * durable handle request is processed below.
-                        */
-               }
-
-               if (dh2q) {
-                       uint32_t dh2q_flags;
-
-                       if (dh2q->data.length != 32) {
-                               tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
-                               return tevent_req_post(req, ev);
-                       }
-
-                       /* TODO - sanity checks - other blobs */
-
-                       /*
-                        * durable handle v2 request processed below
-                        */
-
-                       durable_v2_timeout = SVAL(dh2q->data.data, 0);
-                       dh2q_flags = SVAL(dh2q->data.data, 4);
-                       persistent_requested = dh2q_flags & SMB2_DHANDLE_FLAG_PERSISTENT;
-
-                       persistent_granted = persistent_requested;
-
                        /*
-                        * TODO: extract create guid
+                        * we don't support durable handles yet
+                        * and have to ignore this
                         */
                }
 
                if (dhnc) {
-                       uint64_t persistent_id;
-
-DEBUG(0, ("OBNOX - dhnc found (%s:%s)\n", __location__, __FUNCTION__));
-
                        if (dhnc->data.length != 16) {
                                tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
                                return tevent_req_post(req, ev);
                        }
-
-                       persistent_id = BVAL(dhnc->data.data, 0);
-
-                       status = smb2srv_open_recreate(smb2req->sconn->conn,
-                                                      persistent_id,
-                                                      &op);
-                       if (!NT_STATUS_IS_OK(status)) {
-                               tevent_req_nterror(req, status);
-                               return tevent_req_post(req, ev);
-                       }
-
-                       /* TODO: needed? or is successful global_lookup enough?) */
-
-                       if (!op->global->durable) {
-                               talloc_free(op);
-                               tevent_req_nterror(req,
-                                       NT_STATUS_OBJECT_NAME_NOT_FOUND);
-                               return tevent_req_post(req, ev);
-                       }
-
-                       do_durable_reconnect = true;
-               }
-
-               if (dh2c) {
-                       uint64_t persistent_id;
-                       uint32_t dh2c_flags;
-
-DEBUG(0, ("OBNOX - dh2c found (%s:%s)\n", __location__, __FUNCTION__));
-
-                       if (dh2c->data.length != 36) {
-                               tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
-                               return tevent_req_post(req, ev);
-                       }
-
-                       persistent_id = BVAL(dh2c->data.data, 0);
-                       /*
-                        * TODO: extract and check create guid
-                        */
-                       dh2c_flags = SVAL(dh2c->data.data, 32);
-                       persistent_requested = dh2c_flags & SMB2_DHANDLE_FLAG_PERSISTENT;
-
-                       status = smb2srv_open_recreate(smb2req->sconn->conn,
-                                                      persistent_id,
-                                                      &op);
-                       if (!NT_STATUS_IS_OK(status)) {
-                               tevent_req_nterror(req, status);
-                               return tevent_req_post(req, ev);
-                       }
-
-                       if (!op->global->durable) {
-                               talloc_free(op);
-                               tevent_req_nterror(req,
-                                       NT_STATUS_OBJECT_NAME_NOT_FOUND);
-                               return tevent_req_post(req, ev);
-                       }
-
-                       if (persistent_requested && op->global->persistent) {
-                               persistent_granted = true;
-                       }
-
-                       do_durable_reconnect = true;
+                       /* we don't support durable handles yet */
+                       tevent_req_nterror(req, NT_STATUS_OBJECT_NAME_NOT_FOUND);
+                       return tevent_req_post(req, ev);
                }
 
                if (alsi) {
@@ -1003,8 +698,8 @@ DEBUG(0, ("OBNOX - dh2c found (%s:%s)\n", __location__, __FUNCTION__));
                                          smb1req->conn,
                                          smb1req->flags2 & FLAGS2_DFS_PATHNAMES,
                                          fname,
-                                         0,    /* unix_convert flags */
-                                         NULL, /* ppath_contains_wcards */
+                                         0,
+                                         NULL,
                                          &smb_fname);
                if (!NT_STATUS_IS_OK(status)) {
                        tevent_req_nterror(req, status);
@@ -1013,55 +708,30 @@ DEBUG(0, ("OBNOX - dh2c found (%s:%s)\n", __location__, __FUNCTION__));
 
                in_file_attributes &= ~FILE_FLAG_POSIX_SEMANTICS;
 
-               DEBUG(5, ("%s: open execution phase\n", __FUNCTION__));
-
-               /*
-                * For the backend file open procedure, there are
-                * two possible modes: durable_reconnect or not.
-                */
-               if (do_durable_reconnect) {
-                       status = smb2_create_durable_reconnect(op,
-                                                              smb1req->conn,
-                                                              smb1req,
-                                                              smb_fname,
-                                                              mem_ctx,
-                                                              &result,
-                                                              &info);
-
-DEBUG(0, ("OBNOX - durable_reconnect result: %s (%s:%s)\n", nt_errstr(status), __location__, __FUNCTION__));
-
-                       if (!NT_STATUS_IS_OK(status)) {
-                               tevent_req_nterror(req, status);
-                               return tevent_req_post(req, ev);
-                       }
-               } else {
-                       status = SMB_VFS_CREATE_FILE(smb1req->conn,
-                                                    smb1req,
-                                                    0, /* root_dir_fid */
-                                                    smb_fname,
-                                                    in_desired_access,
-                                                    in_share_access,
-                                                    in_create_disposition,
-                                                    in_create_options,
-                                                    in_file_attributes,
-                                                    map_smb2_oplock_levels_to_samba(requested_oplock_level),
-                                                    allocation_size,
-                                                    0, /* private_flags */
-                                                    sec_desc,
-                                                    ea_list,
-                                                    &result,
-                                                    &info);
-                       if (!NT_STATUS_IS_OK(status)) {
-                               if (open_was_deferred(smb1req->sconn, smb1req->mid)) {
-                                       return req;
-                               }
-                               tevent_req_nterror(req, status);
-                               return tevent_req_post(req, ev);
+               status = SMB_VFS_CREATE_FILE(smb1req->conn,
+                                            smb1req,
+                                            0, /* root_dir_fid */
+                                            smb_fname,
+                                            in_desired_access,
+                                            in_share_access,
+                                            in_create_disposition,
+                                            in_create_options,
+                                            in_file_attributes,
+                                            map_smb2_oplock_levels_to_samba(requested_oplock_level),
+                                            allocation_size,
+                                            0, /* private_flags */
+                                            sec_desc,
+                                            ea_list,
+                                            &result,
+                                            &info);
+               if (!NT_STATUS_IS_OK(status)) {
+                       if (open_was_deferred(smb1req->sconn, smb1req->mid)) {
+                               return req;
                        }
+                       tevent_req_nterror(req, status);
+                       return tevent_req_post(req, ev);
                }
 
-               DEBUG(5, ("%s: response construction phase\n", __FUNCTION__));
-
                if (mxac) {
                        NTTIME last_write_time;
 
@@ -1091,71 +761,6 @@ DEBUG(0, ("OBNOX - durable_reconnect result: %s (%s:%s)\n", nt_errstr(status), _
                        }
                }
 
-               /*
-                * windows creates a dhnc response blob upon dbnc request.
-                * this seems to contradict the documentation, though
-                * --> TODO:dochelp
-                */
-               if (dhnc || (dhnq && BATCH_OPLOCK_TYPE(result->oplock_type))) {
-                       uint8_t p[8];
-                       DATA_BLOB blob = data_blob_const(p, sizeof(p));
-
-DEBUG(0, ("OBNOX - constructing a dhnq response blob (%s: %s)\n", __location__, __FUNCTION__));
-
-                       result->smbXsrv->global->backend_file_id = result->file_id;
-                       result->smbXsrv->global->durable = true;
-
-                       status = smbXsrv_open_update(result->smbXsrv);
-                       if (!NT_STATUS_IS_OK(status)) {
-                               tevent_req_nterror(req, status);
-                               return tevent_req_post(req, ev);
-                       }
-
-                       ZERO_STRUCT(p); /* fill with zeroes */
-
-                       status = smb2_create_blob_add(state, &out_context_blobs,
-                                                     SMB2_CREATE_TAG_DHNQ,
-                                                     blob);
-
-                       if (!NT_STATUS_IS_OK(status)) {
-                               tevent_req_nterror(req, status);
-                               return tevent_req_post(req, ev);
-                       }
-               }
-
-               if (dh2c || (dh2q && BATCH_OPLOCK_TYPE(result->oplock_type))) {
-                       uint8_t p[8];
-                       DATA_BLOB blob = data_blob_const(p, sizeof(p));
-                       uint32_t durable_v2_response_flags = 0;
-
-DEBUG(0, ("OBNOX - constructing a dh2q response blob (%s: %s)\n", __location__, __FUNCTION__));
-
-                       if (persistent_granted) {
-                               durable_v2_response_flags |= SMB2_DHANDLE_FLAG_PERSISTENT;
-                       }
-
-                       SIVAL(p, 0, durable_v2_timeout);
-                       SIVAL(p, 4, durable_v2_response_flags);
-
-                       result->smbXsrv->global->backend_file_id = result->file_id;
-                       result->smbXsrv->global->durable = true;
-                       result->smbXsrv->global->persistent = persistent_granted;
-
-                       status = smbXsrv_open_update(result->smbXsrv);
-                       if (!NT_STATUS_IS_OK(status)) {
-                               tevent_req_nterror(req, status);
-                               return tevent_req_post(req, ev);
-                       }
-
-                       status = smb2_create_blob_add(state, &out_context_blobs,
-                                                     SMB2_CREATE_TAG_DH2Q,
-                                                     blob);
-                       if (!NT_STATUS_IS_OK(status)) {
-                               tevent_req_nterror(req, status);
-                               return tevent_req_post(req, ev);
-                       }
-               }
-
                if (qfid) {
                        uint8_t p[32];
                        uint64_t file_index = get_FileIndex(result->conn,
@@ -1222,9 +827,8 @@ DEBUG(0, ("OBNOX - constructing a dh2q response blob (%s: %s)\n", __location__,
        if (state->out_file_attributes == 0) {
                state->out_file_attributes = FILE_ATTRIBUTE_NORMAL;
        }
-
-       state->out_file_id_persistent = result->smbXsrv->global->open_persistent_id;
-       state->out_file_id_volatile = result->smbXsrv->global->open_volatile_id;
+       state->out_file_id_persistent = result->fnum;
+       state->out_file_id_volatile = result->fnum;
        state->out_context_blobs = out_context_blobs;
 
        tevent_req_done(req);
index 1854f3457db03302a39a01e2c7637f2cefb965e8..9c0d18b278fa7033e6ba33cf901742f85dab729b 100644 (file)
@@ -31,7 +31,6 @@ static struct tevent_req *smbd_smb2_find_send(TALLOC_CTX *mem_ctx,
                                              uint8_t in_file_info_class,
                                              uint8_t in_flags,
                                              uint32_t in_file_index,
-                                             uint64_t in_file_id_persistent,
                                              uint64_t in_file_id_volatile,
                                              uint32_t in_output_buffer_length,
                                              const char *in_file_name);
@@ -116,13 +115,18 @@ NTSTATUS smbd_smb2_request_process_find(struct smbd_smb2_request *req)
                return smbd_smb2_request_error(req, NT_STATUS_OBJECT_NAME_INVALID);
        }
 
+       if (req->compat_chain_fsp) {
+               /* skip check */
+       } else if (in_file_id_persistent != in_file_id_volatile) {
+               return smbd_smb2_request_error(req, NT_STATUS_FILE_CLOSED);
+       }
+
        subreq = smbd_smb2_find_send(req,
                                     req->sconn->ev_ctx,
                                     req,
                                     in_file_info_class,
                                     in_flags,
                                     in_file_index,
-                                    in_file_id_persistent,
                                     in_file_id_volatile,
                                     in_output_buffer_length,
                                     in_file_name_string);
@@ -202,7 +206,6 @@ static struct tevent_req *smbd_smb2_find_send(TALLOC_CTX *mem_ctx,
                                              uint8_t in_file_info_class,
                                              uint8_t in_flags,
                                              uint32_t in_file_index,
-                                             uint64_t in_file_id_persistent,
                                              uint64_t in_file_id_volatile,
                                              uint32_t in_output_buffer_length,
                                              const char *in_file_name)
@@ -247,12 +250,6 @@ static struct tevent_req *smbd_smb2_find_send(TALLOC_CTX *mem_ctx,
                tevent_req_nterror(req, NT_STATUS_FILE_CLOSED);
                return tevent_req_post(req, ev);
        }
-       if (smb2req->compat_chain_fsp) {
-               /* skip check */
-       } else if (in_file_id_persistent != fsp->smbXsrv->global->open_persistent_id) {
-               tevent_req_nterror(req, NT_STATUS_FILE_CLOSED);
-               return tevent_req_post(req, ev);
-       }
        if (conn != fsp->conn) {
                tevent_req_nterror(req, NT_STATUS_FILE_CLOSED);
                return tevent_req_post(req, ev);
index 66dd22a7edd0abe394c4454aa311ed5e20e0b03f..fecce45fb4e1c376d4278aa2fd01ac992b1a9118 100644 (file)
@@ -27,7 +27,6 @@
 static struct tevent_req *smbd_smb2_flush_send(TALLOC_CTX *mem_ctx,
                                               struct tevent_context *ev,
                                               struct smbd_smb2_request *smb2req,
-                                              uint64_t in_file_id_persistent,
                                               uint64_t in_file_id_volatile);
 static NTSTATUS smbd_smb2_flush_recv(struct tevent_req *req);
 
@@ -50,10 +49,15 @@ NTSTATUS smbd_smb2_request_process_flush(struct smbd_smb2_request *req)
        in_file_id_persistent   = BVAL(inbody, 0x08);
        in_file_id_volatile     = BVAL(inbody, 0x10);
 
+       if (req->compat_chain_fsp) {
+               /* skip check */
+       } else if (in_file_id_persistent != in_file_id_volatile) {
+               return smbd_smb2_request_error(req, NT_STATUS_FILE_CLOSED);
+       }
+
        subreq = smbd_smb2_flush_send(req,
                                      req->sconn->ev_ctx,
                                      req,
-                                     in_file_id_persistent,
                                      in_file_id_volatile);
        if (subreq == NULL) {
                return smbd_smb2_request_error(req, NT_STATUS_NO_MEMORY);
@@ -112,7 +116,6 @@ struct smbd_smb2_flush_state {
 static struct tevent_req *smbd_smb2_flush_send(TALLOC_CTX *mem_ctx,
                                               struct tevent_context *ev,
                                               struct smbd_smb2_request *smb2req,
-                                              uint64_t in_file_id_persistent,
                                               uint64_t in_file_id_volatile)
 {
        struct tevent_req *req;
@@ -146,12 +149,6 @@ static struct tevent_req *smbd_smb2_flush_send(TALLOC_CTX *mem_ctx,
                tevent_req_nterror(req, NT_STATUS_FILE_CLOSED);
                return tevent_req_post(req, ev);
        }
-       if (smb2req->compat_chain_fsp) {
-               /* skip check */
-       } else if (in_file_id_persistent != fsp->smbXsrv->global->open_persistent_id) {
-               tevent_req_nterror(req, NT_STATUS_FILE_CLOSED);
-               return tevent_req_post(req, ev);
-       }
        if (smbreq->conn != fsp->conn) {
                tevent_req_nterror(req, NT_STATUS_FILE_CLOSED);
                return tevent_req_post(req, ev);
index 16bd2897aaf997858f97412fef1d6e44f8ba7764..e8d918df388a3e44ee0db3b2d87a43622cbc91c3 100644 (file)
@@ -35,7 +35,6 @@ static struct tevent_req *smbd_smb2_getinfo_send(TALLOC_CTX *mem_ctx,
                                                 DATA_BLOB in_input_buffer,
                                                 uint32_t in_additional_information,
                                                 uint32_t in_flags,
-                                                uint64_t in_file_id_persistent,
                                                 uint64_t in_file_id_volatile);
 static NTSTATUS smbd_smb2_getinfo_recv(struct tevent_req *req,
                                       TALLOC_CTX *mem_ctx,
@@ -104,6 +103,12 @@ NTSTATUS smbd_smb2_request_process_getinfo(struct smbd_smb2_request *req)
                return smbd_smb2_request_error(req, status);
        }
 
+       if (req->compat_chain_fsp) {
+               /* skip check */
+       } else if (in_file_id_persistent != in_file_id_volatile) {
+               return smbd_smb2_request_error(req, NT_STATUS_FILE_CLOSED);
+       }
+
        subreq = smbd_smb2_getinfo_send(req,
                                        req->sconn->ev_ctx,
                                        req,
@@ -113,7 +118,6 @@ NTSTATUS smbd_smb2_request_process_getinfo(struct smbd_smb2_request *req)
                                        in_input_buffer,
                                        in_additional_information,
                                        in_flags,
-                                       in_file_id_persistent,
                                        in_file_id_volatile);
        if (subreq == NULL) {
                return smbd_smb2_request_error(req, NT_STATUS_NO_MEMORY);
@@ -238,7 +242,6 @@ static struct tevent_req *smbd_smb2_getinfo_send(TALLOC_CTX *mem_ctx,
                                                 DATA_BLOB in_input_buffer,
                                                 uint32_t in_additional_information,
                                                 uint32_t in_flags,
-                                                uint64_t in_file_id_persistent,
                                                 uint64_t in_file_id_volatile)
 {
        struct tevent_req *req;
@@ -270,12 +273,6 @@ static struct tevent_req *smbd_smb2_getinfo_send(TALLOC_CTX *mem_ctx,
                tevent_req_nterror(req, NT_STATUS_FILE_CLOSED);
                return tevent_req_post(req, ev);
        }
-       if (smb2req->compat_chain_fsp) {
-               /* skip check */
-       } else if (in_file_id_persistent != fsp->smbXsrv->global->open_persistent_id) {
-               tevent_req_nterror(req, NT_STATUS_FILE_CLOSED);
-               return tevent_req_post(req, ev);
-       }
        if (conn != fsp->conn) {
                tevent_req_nterror(req, NT_STATUS_FILE_CLOSED);
                return tevent_req_post(req, ev);
index 3592c74b495c50ef6bcd81e998f52771e60fefcc..9471e2f6caec13d6da8afaac48a2ace4dfd0d130 100644 (file)
@@ -30,7 +30,6 @@ static struct tevent_req *smbd_smb2_ioctl_send(TALLOC_CTX *mem_ctx,
                                               struct tevent_context *ev,
                                               struct smbd_smb2_request *smb2req,
                                               uint32_t in_ctl_code,
-                                              uint64_t in_file_id_persistent,
                                               uint64_t in_file_id_volatile,
                                               DATA_BLOB in_input,
                                               uint32_t in_max_output,
@@ -89,11 +88,19 @@ NTSTATUS smbd_smb2_request_process_ioctl(struct smbd_smb2_request *req)
        in_input_buffer.data = (uint8_t *)req->in.vector[i+2].iov_base;
        in_input_buffer.length = in_input_length;
 
+       if (req->compat_chain_fsp) {
+               /* skip check */
+       } else if (in_file_id_persistent == UINT64_MAX &&
+                  in_file_id_volatile == UINT64_MAX) {
+               /* without a handle */
+       } else if (in_file_id_persistent != in_file_id_volatile) {
+               return smbd_smb2_request_error(req, NT_STATUS_FILE_CLOSED);
+       }
+
        subreq = smbd_smb2_ioctl_send(req,
                                      req->sconn->ev_ctx,
                                      req,
                                      in_ctl_code,
-                                     in_file_id_persistent,
                                      in_file_id_volatile,
                                      in_input_buffer,
                                      in_max_output_length,
@@ -213,7 +220,6 @@ static struct tevent_req *smbd_smb2_ioctl_send(TALLOC_CTX *mem_ctx,
                                               struct tevent_context *ev,
                                               struct smbd_smb2_request *smb2req,
                                               uint32_t in_ctl_code,
-                                              uint64_t in_file_id_persistent,
                                               uint64_t in_file_id_volatile,
                                               DATA_BLOB in_input,
                                               uint32_t in_max_output,
@@ -247,19 +253,12 @@ static struct tevent_req *smbd_smb2_ioctl_send(TALLOC_CTX *mem_ctx,
        }
        state->smbreq = smbreq;
 
-       if (in_file_id_volatile != UINT64_MAX &&
-           in_file_id_persistent != UINT64_MAX) {
+       if (in_file_id_volatile != UINT64_MAX) {
                fsp = file_fsp(smbreq, (uint16_t)in_file_id_volatile);
                if (fsp == NULL) {
                        tevent_req_nterror(req, NT_STATUS_FILE_CLOSED);
                        return tevent_req_post(req, ev);
                }
-               if (smb2req->compat_chain_fsp) {
-                       /* skip check */
-               } else if (in_file_id_persistent != fsp->smbXsrv->global->open_persistent_id) {
-                       tevent_req_nterror(req, NT_STATUS_FILE_CLOSED);
-                       return tevent_req_post(req, ev);
-               }
                if (smbreq->conn != fsp->conn) {
                        tevent_req_nterror(req, NT_STATUS_FILE_CLOSED);
                        return tevent_req_post(req, ev);
index 1549fcf70851857fbbabbfc4ea1fd394c139cbdf..fdca266a2764f35153c286578a9e9e57fe0b5e55 100644 (file)
@@ -47,7 +47,6 @@ static struct tevent_req *smbd_smb2_lock_send(TALLOC_CTX *mem_ctx,
                                                 struct tevent_context *ev,
                                                 struct smbd_smb2_request *smb2req,
                                                 uint32_t in_smbpid,
-                                                uint64_t in_file_id_persistent,
                                                 uint64_t in_file_id_volatile,
                                                 uint16_t in_lock_count,
                                                 struct smbd_smb2_lock_element *in_locks);
@@ -91,6 +90,12 @@ NTSTATUS smbd_smb2_request_process_lock(struct smbd_smb2_request *req)
                return smbd_smb2_request_error(req, NT_STATUS_INVALID_PARAMETER);
        }
 
+       if (req->compat_chain_fsp) {
+               /* skip check */
+       } else if (in_file_id_persistent != in_file_id_volatile) {
+               return smbd_smb2_request_error(req, NT_STATUS_FILE_CLOSED);
+       }
+
        in_locks = talloc_array(req, struct smbd_smb2_lock_element,
                                in_lock_count);
        if (in_locks == NULL) {
@@ -120,7 +125,6 @@ NTSTATUS smbd_smb2_request_process_lock(struct smbd_smb2_request *req)
                                     req->sconn->ev_ctx,
                                     req,
                                     in_smbpid,
-                                    in_file_id_persistent,
                                     in_file_id_volatile,
                                     in_lock_count,
                                     in_locks);
@@ -204,7 +208,6 @@ static struct tevent_req *smbd_smb2_lock_send(TALLOC_CTX *mem_ctx,
                                                 struct tevent_context *ev,
                                                 struct smbd_smb2_request *smb2req,
                                                 uint32_t in_smbpid,
-                                                uint64_t in_file_id_persistent,
                                                 uint64_t in_file_id_volatile,
                                                 uint16_t in_lock_count,
                                                 struct smbd_smb2_lock_element *in_locks)
@@ -243,12 +246,6 @@ static struct tevent_req *smbd_smb2_lock_send(TALLOC_CTX *mem_ctx,
                tevent_req_nterror(req, NT_STATUS_FILE_CLOSED);
                return tevent_req_post(req, ev);
        }
-       if (smb2req->compat_chain_fsp) {
-               /* skip check */
-       } else if (in_file_id_persistent != fsp->smbXsrv->global->open_persistent_id) {
-               tevent_req_nterror(req, NT_STATUS_FILE_CLOSED);
-               return tevent_req_post(req, ev);
-       }
        if (conn != fsp->conn) {
                tevent_req_nterror(req, NT_STATUS_FILE_CLOSED);
                return tevent_req_post(req, ev);
index ee2ed50cca632e9b0cf766e83969f381fff1da4b..4793a30b4a50cc3559838ad2accb7b7fa9cc4444 100644 (file)
@@ -250,8 +250,6 @@ NTSTATUS smbd_smb2_request_process_negprot(struct smbd_smb2_request *req)
                capabilities |= SMB2_CAP_DFS;
        }
 
-       /* persistent */
-               capabilities += 0x10;
        /*
         * 0x10000 (65536) is the maximum allowed message size
         * for SMB 2.0
@@ -327,9 +325,5 @@ NTSTATUS smbd_smb2_request_process_negprot(struct smbd_smb2_request *req)
        req->sconn->smb2.max_read  = max_read;
        req->sconn->smb2.max_write = max_write;
 
-       req->sconn->smb2.serverguid = data_blob_talloc_zero(req->sconn, 16);
-       memcpy(req->sconn->smb2.serverguid.data, negprot_spnego_blob.data, 16);
-       req->sconn->smb2.capabilities = capabilities;
-
        return smbd_smb2_request_done(req, outbody, &outdyn);
 }
index aad37d352252eda7cce666fa9740ac66c505cc3f..3f5365c154b5f3aa21a3bb45e4f7fccf8e7fae0f 100644 (file)
@@ -38,7 +38,6 @@ static struct tevent_req *smbd_smb2_notify_send(TALLOC_CTX *mem_ctx,
                                                struct smbd_smb2_request *smb2req,
                                                uint16_t in_flags,
                                                uint32_t in_output_buffer_length,
-                                               uint64_t in_file_id_persistent,
                                                uint64_t in_file_id_volatile,
                                                uint64_t in_completion_filter);
 static NTSTATUS smbd_smb2_notify_recv(struct tevent_req *req,
@@ -85,12 +84,17 @@ NTSTATUS smbd_smb2_request_process_notify(struct smbd_smb2_request *req)
                return smbd_smb2_request_error(req, status);
        }
 
+       if (req->compat_chain_fsp) {
+               /* skip check */
+       } else if (in_file_id_persistent != in_file_id_volatile) {
+               return smbd_smb2_request_error(req, NT_STATUS_FILE_CLOSED);
+       }
+
        subreq = smbd_smb2_notify_send(req,
                                       req->sconn->ev_ctx,
                                       req,
                                       in_flags,
                                       in_output_buffer_length,
-                                      in_file_id_persistent,
                                       in_file_id_volatile,
                                       in_completion_filter);
        if (subreq == NULL) {
@@ -187,7 +191,6 @@ static struct tevent_req *smbd_smb2_notify_send(TALLOC_CTX *mem_ctx,
                                                struct smbd_smb2_request *smb2req,
                                                uint16_t in_flags,
                                                uint32_t in_output_buffer_length,
-                                               uint64_t in_file_id_persistent,
                                                uint64_t in_file_id_volatile,
                                                uint64_t in_completion_filter)
 {
@@ -225,12 +228,6 @@ static struct tevent_req *smbd_smb2_notify_send(TALLOC_CTX *mem_ctx,
                tevent_req_nterror(req, NT_STATUS_FILE_CLOSED);
                return tevent_req_post(req, ev);
        }
-       if (smb2req->compat_chain_fsp) {
-               /* skip check */
-       } else if (in_file_id_persistent != fsp->smbXsrv->global->open_persistent_id) {
-               tevent_req_nterror(req, NT_STATUS_FILE_CLOSED);
-               return tevent_req_post(req, ev);
-       }
        if (conn != fsp->conn) {
                tevent_req_nterror(req, NT_STATUS_FILE_CLOSED);
                return tevent_req_post(req, ev);
index a1582a89c0e2e6475e39164a477575b69d629581..53b0a9dc571f143e5ba275387a695e07283ef1df 100644 (file)
@@ -31,7 +31,6 @@ static struct tevent_req *smbd_smb2_read_send(TALLOC_CTX *mem_ctx,
                                              struct tevent_context *ev,
                                              struct smbd_smb2_request *smb2req,
                                              uint32_t in_smbpid,
-                                             uint64_t in_file_id_persistent,
                                              uint64_t in_file_id_volatile,
                                              uint32_t in_length,
                                              uint64_t in_offset,
@@ -86,11 +85,16 @@ NTSTATUS smbd_smb2_request_process_read(struct smbd_smb2_request *req)
                return smbd_smb2_request_error(req, status);
        }
 
+       if (req->compat_chain_fsp) {
+               /* skip check */
+       } else if (in_file_id_persistent != in_file_id_volatile) {
+               return smbd_smb2_request_error(req, NT_STATUS_FILE_CLOSED);
+       }
+
        subreq = smbd_smb2_read_send(req,
                                     req->sconn->ev_ctx,
                                     req,
                                     in_smbpid,
-                                    in_file_id_persistent,
                                     in_file_id_volatile,
                                     in_length,
                                     in_offset,
@@ -377,7 +381,6 @@ static struct tevent_req *smbd_smb2_read_send(TALLOC_CTX *mem_ctx,
                                              struct tevent_context *ev,
                                              struct smbd_smb2_request *smb2req,
                                              uint32_t in_smbpid,
-                                             uint64_t in_file_id_persistent,
                                              uint64_t in_file_id_volatile,
                                              uint32_t in_length,
                                              uint64_t in_offset,
@@ -420,12 +423,6 @@ static struct tevent_req *smbd_smb2_read_send(TALLOC_CTX *mem_ctx,
                tevent_req_nterror(req, NT_STATUS_FILE_CLOSED);
                return tevent_req_post(req, ev);
        }
-       if (smb2req->compat_chain_fsp) {
-               /* skip check */
-       } else if (in_file_id_persistent != fsp->smbXsrv->global->open_persistent_id) {
-               tevent_req_nterror(req, NT_STATUS_FILE_CLOSED);
-               return tevent_req_post(req, ev);
-       }
        if (conn != fsp->conn) {
                tevent_req_nterror(req, NT_STATUS_FILE_CLOSED);
                return tevent_req_post(req, ev);
index c168ea003f2d0defaad28a094f8e658cf706db84..5d30aa48900f46a152dd8736e60288819eba5a5e 100644 (file)
@@ -108,6 +108,11 @@ static NTSTATUS smbd_initialize_smb2(struct smbd_server_connection *sconn)
                return NT_STATUS_NO_MEMORY;
        }
 
+       sconn->smb2.sessions.idtree = idr_init(sconn);
+       if (sconn->smb2.sessions.idtree == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
+       sconn->smb2.sessions.limit = 0x0000FFFE;
        sconn->smb2.sessions.list = NULL;
        sconn->smb2.seqnum_low = 0;
        sconn->smb2.credits_granted = 0;
@@ -811,13 +816,9 @@ static NTSTATUS smb2_send_async_interim_response(const struct smbd_smb2_request
        /* Re-sign if needed. */
        if (nreq->do_signing) {
                NTSTATUS status;
-               struct smbXsrv_session *x = nreq->session->smbXsrv;
-               struct smbXsrv_connection *conn = x->connection;
-               DATA_BLOB signing_key = x->global->channels[0].signing_key;
-
-               status = smb2_signing_sign_pdu(signing_key,
-                                              conn->protocol,
-                                              &nreq->out.vector[i], 3);
+               status = smb2_signing_sign_pdu(nreq->session->session_key,
+                                       get_Protocol(),
+                                       &nreq->out.vector[i], 3);
                if (!NT_STATUS_IS_OK(status)) {
                        return status;
                }
@@ -1100,13 +1101,10 @@ static void smbd_smb2_request_pending_timer(struct tevent_context *ev,
 
        if (req->do_signing) {
                NTSTATUS status;
-               struct smbXsrv_session *x = req->session->smbXsrv;
-               struct smbXsrv_connection *conn = x->connection;
-               DATA_BLOB signing_key = x->global->channels[0].signing_key;
 
-               status = smb2_signing_sign_pdu(signing_key,
-                                              conn->protocol,
-                                              &state->vector[1], 2);
+               status = smb2_signing_sign_pdu(req->session->session_key,
+                                       get_Protocol(),
+                                       &state->vector[1], 2);
                if (!NT_STATUS_IS_OK(status)) {
                        smbd_server_connection_terminate(req->sconn,
                                                nt_errstr(status));
@@ -1249,10 +1247,8 @@ static NTSTATUS smbd_smb2_request_check_session(struct smbd_smb2_request *req)
        int i = req->current_idx;
        uint32_t in_flags;
        uint64_t in_session_id;
+       void *p;
        struct smbd_smb2_session *session;
-       struct smbXsrv_session *smbXsrv;
-       NTSTATUS status;
-       NTTIME now = 0;
 
        req->session = NULL;
        req->tcon = NULL;
@@ -1267,13 +1263,12 @@ static NTSTATUS smbd_smb2_request_check_session(struct smbd_smb2_request *req)
        }
 
        /* lookup an existing session */
-       status = smb2srv_session_lookup(&req->sconn->conn->session_table,
-                                       in_session_id, now,
-                                       &smbXsrv);
-       if (!NT_STATUS_IS_OK(status)) {
-               return status;
+       p = idr_find(req->sconn->smb2.sessions.idtree, in_session_id);
+       if (p == NULL) {
+               return NT_STATUS_USER_SESSION_DELETED;
        }
-       session = smbXsrv->smb2sess;
+       session = talloc_get_type_abort(p, struct smbd_smb2_session);
+
        if (!NT_STATUS_IS_OK(session->status)) {
                return NT_STATUS_ACCESS_DENIED;
        }
@@ -1393,7 +1388,6 @@ NTSTATUS smbd_smb2_request_dispatch(struct smbd_smb2_request *req)
        NTSTATUS session_status;
        uint32_t allowed_flags;
        NTSTATUS return_value;
-       struct smbXsrv_session *x = NULL;
 
        inhdr = (const uint8_t *)req->in.vector[i].iov_base;
 
@@ -1432,9 +1426,6 @@ NTSTATUS smbd_smb2_request_dispatch(struct smbd_smb2_request *req)
        if (opcode == SMB2_OP_CANCEL) {
                allowed_flags |= SMB2_HDR_FLAG_ASYNC;
        }
-       if (true /* TODO  - which OPs ? */) {
-               allowed_flags |= SMB2_HDR_FLAG_REPLAY_OPERATION;
-       }
        if ((flags & ~allowed_flags) != 0) {
                return smbd_smb2_request_error(req, NT_STATUS_INVALID_PARAMETER);
        }
@@ -1448,29 +1439,23 @@ NTSTATUS smbd_smb2_request_dispatch(struct smbd_smb2_request *req)
         * we defer the check of the session_status
         */
        session_status = smbd_smb2_request_check_session(req);
-       if (req->session) {
-               x = req->session->smbXsrv;
-       }
 
        req->do_signing = false;
        if (flags & SMB2_HDR_FLAG_SIGNED) {
-               struct smbXsrv_connection *conn = x->connection;
-               DATA_BLOB signing_key = x->global->channels[0].signing_key;
-
                if (!NT_STATUS_IS_OK(session_status)) {
                        return smbd_smb2_request_error(req, session_status);
                }
 
                req->do_signing = true;
-               status = smb2_signing_check_pdu(signing_key,
-                                               conn->protocol,
+               status = smb2_signing_check_pdu(req->session->session_key,
+                                               get_Protocol(),
                                                &req->in.vector[i], 3);
                if (!NT_STATUS_IS_OK(status)) {
                        return smbd_smb2_request_error(req, status);
                }
        } else if (opcode == SMB2_OP_CANCEL) {
                /* Cancel requests are allowed to skip the signing */
-       } else if (x && x->global->signing_required) {
+       } else if (req->session && req->session->do_signing) {
                return smbd_smb2_request_error(req, NT_STATUS_ACCESS_DENIED);
        }
 
@@ -1952,12 +1937,8 @@ static NTSTATUS smbd_smb2_request_reply(struct smbd_smb2_request *req)
 
        if (req->do_signing) {
                NTSTATUS status;
-               struct smbXsrv_session *x = req->session->smbXsrv;
-               struct smbXsrv_connection *conn = x->connection;
-               DATA_BLOB signing_key = x->global->channels[0].signing_key;
-
-               status = smb2_signing_sign_pdu(signing_key,
-                                              conn->protocol,
+               status = smb2_signing_sign_pdu(req->session->session_key,
+                                              get_Protocol(),
                                               &req->out.vector[i], 3);
                if (!NT_STATUS_IS_OK(status)) {
                        return status;
index 5ba81c449c7188cb0a9cb1df7012e6a8f7bd7fdc..9a750eea0d67db653eacb4926ee80abc3697d603 100644 (file)
@@ -129,6 +129,7 @@ static int smbd_smb2_session_destructor(struct smbd_smb2_session *session)
                talloc_free(session->tcons.list);
        }
 
+       idr_remove(session->sconn->smb2.sessions.idtree, session->vuid);
        DLIST_REMOVE(session->sconn->smb2.sessions.list, session);
        invalidate_vuid(session->sconn, session->vuid);
 
@@ -136,8 +137,6 @@ static int smbd_smb2_session_destructor(struct smbd_smb2_session *session)
        session->status = NT_STATUS_USER_SESSION_DELETED;
        session->sconn = NULL;
 
-       TALLOC_FREE(session->smbXsrv);
-
        return 0;
 }
 
@@ -148,15 +147,11 @@ static NTSTATUS smbd_smb2_auth_generic_return(struct smbd_smb2_session *session,
                                        uint16_t *out_session_flags,
                                        uint64_t *out_session_id)
 {
-       NTSTATUS status;
        bool guest = false;
-       uint8_t session_key[16];
-       struct smbXsrv_session *x = session->smbXsrv;
-       struct smbXsrv_connection *conn = x->connection;
 
        if ((in_security_mode & SMB2_NEGOTIATE_SIGNING_REQUIRED) ||
            lp_server_signing() == SMB_SIGNING_REQUIRED) {
-               x->global->signing_required = true;
+               session->do_signing = true;
        }
 
        if (security_session_user_level(session->session_info, NULL) < SECURITY_USER) {
@@ -164,68 +159,11 @@ static NTSTATUS smbd_smb2_auth_generic_return(struct smbd_smb2_session *session,
                *out_session_flags |= SMB2_SESSION_FLAG_IS_GUEST;
                *out_session_flags |= SMB2_SESSION_FLAG_IS_NULL;
                /* force no signing */
-               x->global->signing_required = false;
+               session->do_signing = false;
                guest = true;
        }
 
-       //session->session_key = session->session_info->session_key;
-
-       ZERO_STRUCT(session_key);
-       memcpy(session_key, session->session_info->session_key.data,
-              MIN(session->session_info->session_key.length, sizeof(session_key)));
-
-       x->global->signing_key = data_blob_talloc(x->global,
-                                                 session_key,
-                                                 sizeof(session_key));
-       if (x->global->signing_key.data == NULL) {
-               ZERO_STRUCT(session_key);
-               return NT_STATUS_NO_MEMORY;
-       }
-
-       if (conn->protocol >= PROTOCOL_SMB2_24) {
-#define _STRING_BLOB(x) data_blob_const((const uint8_t *)(x), sizeof(x))
-               const DATA_BLOB label = _STRING_BLOB("SMB2AESCMAC");
-               const DATA_BLOB context = _STRING_BLOB("SmbSign");
-#undef _STRING_BLOB
-
-               smb2_key_derivation(session_key, sizeof(session_key),
-                                   label.data, label.length,
-                                   context.data, context.length,
-                                   x->global->signing_key.data);
-       }
-
-       x->global->application_key = data_blob_dup_talloc(x->global,
-                                               x->global->signing_key);
-       if (x->global->application_key.data == NULL) {
-               ZERO_STRUCT(session_key);
-               return NT_STATUS_NO_MEMORY;
-       }
-
-       if (conn->protocol >= PROTOCOL_SMB2_24) {
-#define _STRING_BLOB(x) data_blob_const((const uint8_t *)(x), sizeof(x))
-               const DATA_BLOB label = _STRING_BLOB("SMB2APP");
-               const DATA_BLOB context = _STRING_BLOB("SmbRpc");
-#undef _STRING_BLOB
-
-               smb2_key_derivation(session_key, sizeof(session_key),
-                                   label.data, label.length,
-                                   context.data, context.length,
-                                   x->global->application_key.data);
-       }
-       ZERO_STRUCT(session_key);
-
-       x->global->channels[0].signing_key = data_blob_dup_talloc(x->global->channels,
-                                               x->global->signing_key);
-       if (x->global->channels[0].signing_key.data == NULL) {
-               return NT_STATUS_NO_MEMORY;
-       }
-
-       data_blob_clear_free(&session->session_info->session_key);
-       session->session_info->session_key = data_blob_dup_talloc(session->session_info,
-                                               x->global->application_key);
-       if (session->session_info->session_key.data == NULL) {
-               return NT_STATUS_NO_MEMORY;
-       }
+       session->session_key = session->session_info->session_key;
 
        session->compat_vuser = talloc_zero(session, user_struct);
        if (session->compat_vuser == NULL) {
@@ -259,17 +197,6 @@ static NTSTATUS smbd_smb2_auth_generic_return(struct smbd_smb2_session *session,
 
        reload_services(smb2req->sconn, conn_snum_used, true);
 
-       session->smbXsrv->status = NT_STATUS_OK;
-       session->smbXsrv->global->auth_session_info = session->session_info;
-
-       status = smbXsrv_session_update(session->smbXsrv);
-       if (!NT_STATUS_IS_OK(status)) {
-               DEBUG(0, ("smb2: Failed to update session for vuid=%d - %s\n",
-                       session->compat_vuser->vuid, nt_errstr(status)));
-               TALLOC_FREE(session);
-               return NT_STATUS_LOGON_FAILURE;
-       }
-
        session->status = NT_STATUS_OK;
 
        /*
@@ -361,63 +288,55 @@ static NTSTATUS smbd_smb2_session_setup(struct smbd_smb2_request *smb2req,
                                        DATA_BLOB *out_security_buffer,
                                        uint64_t *out_session_id)
 {
-       struct smbd_smb2_session *smb2sess;
-       struct smbXsrv_session *session;
-       NTSTATUS status;
-       NTTIME now = 0;
+       struct smbd_smb2_session *session;
 
        *out_session_flags = 0;
        *out_session_id = 0;
 
        if (in_session_id == 0) {
+               int id;
+
                /* create a new session */
-               smb2sess = talloc_zero(smb2req->sconn, struct smbd_smb2_session);
-               if (smb2sess == NULL) {
+               session = talloc_zero(smb2req->sconn, struct smbd_smb2_session);
+               if (session == NULL) {
                        return NT_STATUS_NO_MEMORY;
                }
-
-               status = smbXsrv_session_create(smb2req->sconn->conn,
-                                               now, &session);
-               if (!NT_STATUS_IS_OK(status)) {
-                       return status;
+               session->status = NT_STATUS_MORE_PROCESSING_REQUIRED;
+               id = idr_get_new_random(smb2req->sconn->smb2.sessions.idtree,
+                                       session,
+                                       smb2req->sconn->smb2.sessions.limit);
+               if (id == -1) {
+                       return NT_STATUS_INSUFFICIENT_RESOURCES;
                }
-               smb2sess->smbXsrv = session;
-               session->smb2sess = smb2sess;
-               talloc_set_destructor(smb2sess, smbd_smb2_session_destructor);
+               session->vuid = id;
 
-               smb2sess->status = NT_STATUS_MORE_PROCESSING_REQUIRED;
-               smb2sess->vuid = session->global->session_wire_id;
-
-               smb2sess->tcons.idtree = idr_init(smb2sess);
-               if (smb2sess->tcons.idtree == NULL) {
+               session->tcons.idtree = idr_init(session);
+               if (session->tcons.idtree == NULL) {
                        return NT_STATUS_NO_MEMORY;
                }
-               smb2sess->tcons.limit = 0x0000FFFE;
-               smb2sess->tcons.list = NULL;
+               session->tcons.limit = 0x0000FFFE;
+               session->tcons.list = NULL;
 
-               DLIST_ADD_END(smb2req->sconn->smb2.sessions.list, smb2sess,
+               DLIST_ADD_END(smb2req->sconn->smb2.sessions.list, session,
                              struct smbd_smb2_session *);
-               smb2sess->sconn = smb2req->sconn;
+               session->sconn = smb2req->sconn;
+               talloc_set_destructor(session, smbd_smb2_session_destructor);
        } else {
-               status = smb2srv_session_lookup(&smb2req->sconn->conn->session_table,
-                                               in_session_id, now,
-                                               &session);
-               if (NT_STATUS_IS_OK(status)) {
-                       return NT_STATUS_REQUEST_NOT_ACCEPTED;
-               }
-               if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
+               void *p;
 
-                       return status;
+               /* lookup an existing session */
+               p = idr_find(smb2req->sconn->smb2.sessions.idtree, in_session_id);
+               if (p == NULL) {
+                       return NT_STATUS_USER_SESSION_DELETED;
                }
-
-               smb2sess = session->smb2sess;
+               session = talloc_get_type_abort(p, struct smbd_smb2_session);
        }
 
-       if (NT_STATUS_IS_OK(smb2sess->status)) {
+       if (NT_STATUS_IS_OK(session->status)) {
                return NT_STATUS_REQUEST_NOT_ACCEPTED;
        }
 
-       return smbd_smb2_auth_generic(smb2sess,
+       return smbd_smb2_auth_generic(session,
                                      smb2req,
                                      in_security_mode,
                                      in_security_buffer,
index 0c9f905cf919fa9eb955b0164a942ff44d1db321..be506ccecf6d560e874a0e011e8b12a0ea4c7016 100644 (file)
@@ -33,7 +33,6 @@ static struct tevent_req *smbd_smb2_setinfo_send(TALLOC_CTX *mem_ctx,
                                                 uint8_t in_file_info_class,
                                                 DATA_BLOB in_input_buffer,
                                                 uint32_t in_additional_information,
-                                                uint64_t in_file_id_persistent,
                                                 uint64_t in_file_id_volatile);
 static NTSTATUS smbd_smb2_setinfo_recv(struct tevent_req *req);
 
@@ -92,6 +91,12 @@ NTSTATUS smbd_smb2_request_process_setinfo(struct smbd_smb2_request *req)
                return smbd_smb2_request_error(req, status);
        }
 
+       if (req->compat_chain_fsp) {
+               /* skip check */
+       } else if (in_file_id_persistent != in_file_id_volatile) {
+               return smbd_smb2_request_error(req, NT_STATUS_FILE_CLOSED);
+       }
+
        subreq = smbd_smb2_setinfo_send(req,
                                        req->sconn->ev_ctx,
                                        req,
@@ -99,7 +104,6 @@ NTSTATUS smbd_smb2_request_process_setinfo(struct smbd_smb2_request *req)
                                        in_file_info_class,
                                        in_input_buffer,
                                        in_additional_information,
-                                       in_file_id_persistent,
                                        in_file_id_volatile);
        if (subreq == NULL) {
                return smbd_smb2_request_error(req, NT_STATUS_NO_MEMORY);
@@ -161,7 +165,6 @@ static struct tevent_req *smbd_smb2_setinfo_send(TALLOC_CTX *mem_ctx,
                                                 uint8_t in_file_info_class,
                                                 DATA_BLOB in_input_buffer,
                                                 uint32_t in_additional_information,
-                                                uint64_t in_file_id_persistent,
                                                 uint64_t in_file_id_volatile)
 {
        struct tevent_req *req = NULL;
@@ -191,12 +194,6 @@ static struct tevent_req *smbd_smb2_setinfo_send(TALLOC_CTX *mem_ctx,
                tevent_req_nterror(req, NT_STATUS_FILE_CLOSED);
                return tevent_req_post(req, ev);
        }
-       if (smb2req->compat_chain_fsp) {
-               /* skip check */
-       } else if (in_file_id_persistent != fsp->smbXsrv->global->open_persistent_id) {
-               tevent_req_nterror(req, NT_STATUS_FILE_CLOSED);
-               return tevent_req_post(req, ev);
-       }
        if (conn != fsp->conn) {
                tevent_req_nterror(req, NT_STATUS_FILE_CLOSED);
                return tevent_req_post(req, ev);
index a364d670ccedeaa7a5d6c65c5bfdd8fd3d22f39e..5f75e5ebe186ccfa0b424b61282a32ee7959eab9 100644 (file)
@@ -275,10 +275,6 @@ static NTSTATUS smbd_smb2_tree_connect(struct smbd_smb2_request *req,
                *out_share_flags |= SMB2_SHAREFLAG_ACCESS_BASED_DIRECTORY_ENUM;
        }
 
-       /*announce CA + cluster */
-       *out_capabilities += 0x10;
-       *out_capabilities += 0x40;
-
        *out_maximal_access = tcon->compat_conn->share_access;
 
        *out_tree_id = tcon->tid;
index 43a48fbcc07acd60a80cd6e6f3ab5b509a7a232c..163672cdb112d17e6dd7a83742034c37347a2637 100644 (file)
@@ -29,7 +29,6 @@ static struct tevent_req *smbd_smb2_write_send(TALLOC_CTX *mem_ctx,
                                               struct tevent_context *ev,
                                               struct smbd_smb2_request *smb2req,
                                               uint32_t in_smbpid,
-                                              uint64_t in_file_id_persistent,
                                               uint64_t in_file_id_volatile,
                                               DATA_BLOB in_data,
                                               uint64_t in_offset,
@@ -94,11 +93,16 @@ NTSTATUS smbd_smb2_request_process_write(struct smbd_smb2_request *req)
                return smbd_smb2_request_error(req, status);
        }
 
+       if (req->compat_chain_fsp) {
+               /* skip check */
+       } else if (in_file_id_persistent != in_file_id_volatile) {
+               return smbd_smb2_request_error(req, NT_STATUS_FILE_CLOSED);
+       }
+
        subreq = smbd_smb2_write_send(req,
                                      req->sconn->ev_ctx,
                                      req,
                                      in_smbpid,
-                                     in_file_id_persistent,
                                      in_file_id_volatile,
                                      in_data_buffer,
                                      in_offset,
@@ -235,7 +239,6 @@ static struct tevent_req *smbd_smb2_write_send(TALLOC_CTX *mem_ctx,
                                               struct tevent_context *ev,
                                               struct smbd_smb2_request *smb2req,
                                               uint32_t in_smbpid,
-                                              uint64_t in_file_id_persistent,
                                               uint64_t in_file_id_volatile,
                                               DATA_BLOB in_data,
                                               uint64_t in_offset,
@@ -276,12 +279,6 @@ static struct tevent_req *smbd_smb2_write_send(TALLOC_CTX *mem_ctx,
                tevent_req_nterror(req, NT_STATUS_FILE_CLOSED);
                return tevent_req_post(req, ev);
        }
-       if (smb2req->compat_chain_fsp) {
-               /* skip check */
-       } else if (in_file_id_persistent != fsp->smbXsrv->global->open_persistent_id) {
-               tevent_req_nterror(req, NT_STATUS_FILE_CLOSED);
-               return tevent_req_post(req, ev);
-       }
        if (conn != fsp->conn) {
                tevent_req_nterror(req, NT_STATUS_FILE_CLOSED);
                return tevent_req_post(req, ev);