[SCM] Samba Shared Repository - branch v3-6-test updated

Karolin Seeger kseeger at samba.org
Sun Jun 17 12:57:52 MDT 2012


The branch, v3-6-test has been updated
       via  fc42ea0 s3:smbd: use fsp_persistent_id() as persistent_file_id part for SMB2 (bug #8995)
       via  cb5a0b1 s3:smbd: add a fsp_persistent_id() function
       via  8c11594 s3:smbd: try to make fsp->fh->gen_id as globally unique as possible
       via  a411223 Revert "s3:smbd: set req->smb2req->compat_chain_fsp in file_fsp()"
       via  9980779 s3:smb2_ioctl: make use of file_fsp_smb2()
       via  f3049c6 s3:smb2_lock: make use of file_fsp_smb2()
       via  b7da435 s3:smb2_write: make use of file_fsp_smb2()
       via  770ea1c s3:smb2_read: make use of file_fsp_smb2()
       via  742dd9d s3:smb2_notify: make use of file_fsp_smb2()
       via  d4b4cc3 3:smb2_setinfo: make use of file_fsp_smb2()
       via  e49840f s3:smb2_getinfo: make use of file_fsp_smb2()
       via  45d6159 s3:smb2_find: make use of file_fsp_smb2()
       via  416bb94 s3:smb2_break: make use of file_fsp_smb2()
       via  feed8c0 s3:smb2_close: make use of file_fsp_smb2()
       via  3ade960 s3:smb2_flush: make use of file_fsp_smb2()
       via  6334f80 s3:smbd: add file_fsp_smb2()
       via  46d293d s3:smb2_write: pass fsp->fnum to init_strict_lock_struct()
       via  0afc959 s3:smb2_read: pass fsp->fnum to init_strict_lock_struct()
       via  c47b3ff s3:smb2_lock: use fsp->fnum as locking context
       via  09dde2e s3:smb2_lock: use smb2req->compat_chain_fsp instead of looking it up again
       via  6ed9df5 s3:smbd: set req->smb2req->compat_chain_fsp in file_fsp()
      from  0ace3ca Part 2 of fix for bug #8998 - Notify code can miss a ChDir.

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v3-6-test


- Log -----------------------------------------------------------------
commit fc42ea02c7af66ddf5af61d444fdfe5e348d05e2
Author: Stefan Metzmacher <metze at samba.org>
Date:   Wed Jun 13 12:13:01 2012 +0200

    s3:smbd: use fsp_persistent_id() as persistent_file_id part for SMB2 (bug #8995)
    
    It seems to be important to have unique persistent file ids,
    because windows clients seem to index files by server_guid + persistent_file_id.
    Which may break, if we just have a 16-bit range per connection
    and the client connects multiple times.
    
    Based on code from Ira Cooper. Use fsp->fh->gen_id as the persistent
    fileid in SMB2.
    
    metze
    
    Autobuild-User(master): Stefan Metzmacher <metze at samba.org>
    Autobuild-Date(master): Thu Jun 14 22:04:13 CEST 2012 on sn-devel-104
    
    Signed-off-by: Jeremy Allison <jra at samba.org>

commit cb5a0b1bc311667818ab45bb1837dc67a241a379
Author: Stefan Metzmacher <metze at samba.org>
Date:   Thu Jun 14 10:32:43 2012 +0200

    s3:smbd: add a fsp_persistent_id() function
    
    This calculates a 64-bit value that most likely uniquely identifies
    the files_struct globally to the server.
    
    * 32-bit random gen_id
    * 16-bit truncated open_time
    * 16-bit fnum (valatile_id)
    
    Based on code from Ira Cooper. Use fsp->fh->gen_id as the persistent
    fileid in SMB2.
    
    Pair-Programmed-With: Michael Adam <obnox at samba.org>
    
    metze
    
    Signed-off-by: Jeremy Allison <jra at samba.org>

commit 8c1159461a0c5a948cd04cdf969e54e1fa83387e
Author: Stefan Metzmacher <metze at samba.org>
Date:   Wed Jun 13 12:11:51 2012 +0200

    s3:smbd: try to make fsp->fh->gen_id as globally unique as possible
    
    This makes sure the value is never 0, it's between 1 and UINT32_MAX.
    
    While fsp->fh->gen_id is 'unsigned long' currently (which might by 8 bytes),
    there's some oplock code which truncates it to uint32_t (using IVAL()).
    
    Which means we could reuse fsp->fh->gen_id as persistent file id
    until we have a final fix, which uses database.
    
    See bug #8995 for more details.
    
    Based on code from Ira Cooper. Ensure fsp->fh->gen_id starts from
    a random point. We will use this as the SMB2 persistent_id.
    
    metze
    
    Signed-off-by: Jeremy Allison <jra at samba.org>

commit a41122337cb72fdc3f16d77396a3e68bf53c1c03
Author: Stefan Metzmacher <metze at samba.org>
Date:   Sat Jun 9 11:11:26 2012 +0200

    Revert "s3:smbd: set req->smb2req->compat_chain_fsp in file_fsp()"
    
    This reverts commit c2716a7d5ccf78f9716b703c22e6cf4d4f179656.
    
    This is not needed anymore, as we have file_fsp_smb2() now.
    
    metze
    
    Autobuild-User(master): Stefan Metzmacher <metze at samba.org>
    Autobuild-Date(master): Sun Jun 10 18:04:21 CEST 2012 on sn-devel-104
    
    Signed-off-by: Jeremy Allison <jra at samba.org>

commit 99807792d743b7f258f0d433689b6231b260bddf
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Jun 15 13:42:27 2012 -0700

    s3:smb2_ioctl: make use of file_fsp_smb2()
    
    metze
    
    Signed-off-by: Jeremy Allison <jra at samba.org>

commit f3049c6cafc252a19db84636765674300ff4162b
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Jun 8 11:57:21 2012 +0200

    s3:smb2_lock: make use of file_fsp_smb2()
    
    metze
    
    Signed-off-by: Jeremy Allison <jra at samba.org>

commit b7da435b7ca4e15265442674c876afa9f53c9d51
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Jun 15 13:31:59 2012 -0700

    s3:smb2_write: make use of file_fsp_smb2()
    
    metze
    
    Signed-off-by: Jeremy Allison <jra at samba.org>

commit 770ea1c18f35c169ce4267f335a7ecca0cda3f40
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Jun 15 13:29:24 2012 -0700

    s3:smb2_read: make use of file_fsp_smb2()
    
    metze
    
    Signed-off-by: Jeremy Allison <jra at samba.org>

commit 742dd9dd2bb176bfe08ceac932ef68f1c182ffe9
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Jun 15 13:27:55 2012 -0700

    s3:smb2_notify: make use of file_fsp_smb2()
    
    metze
    
    Signed-off-by: Jeremy Allison <jra at samba.org>

commit d4b4cc33e04fe29dc98603db11173b5ca04b33d7
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Jun 15 13:25:11 2012 -0700

    3:smb2_setinfo: make use of file_fsp_smb2()
    
    metze
    
    Signed-off-by: Jeremy Allison <jra at samba.org>

commit e49840fc8b78d8e08ce7e662d0f760d2ee6efff0
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Jun 15 13:23:47 2012 -0700

    s3:smb2_getinfo: make use of file_fsp_smb2()
    
    metze
    
    Signed-off-by: Jeremy Allison <jra at samba.org>

commit 45d61598c626c7e7099361e6a02e2aa3eade5d08
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Jun 8 10:42:43 2012 +0200

    s3:smb2_find: make use of file_fsp_smb2()
    
    metze
    
    Signed-off-by: Jeremy Allison <jra at samba.org>

commit 416bb94b7b6b393eef89b4cdf5d2050ed80383e5
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Jun 8 10:36:24 2012 +0200

    s3:smb2_break: make use of file_fsp_smb2()
    
    metze
    
    Signed-off-by: Jeremy Allison <jra at samba.org>

commit feed8c0ea1523b2267aa1b30fbcb009333f21b3e
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Jun 15 13:15:27 2012 -0700

    s3:smb2_close: make use of file_fsp_smb2()
    
    metze
    Signed-off-by: Jeremy Allison <jra at samba.org>

commit 3ade9604f92dc48d2ac12ff14b4ee0504e3fdf4a
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Jun 15 12:55:52 2012 -0700

    s3:smb2_flush: make use of file_fsp_smb2()
    
    metze
    Signed-off-by: Jeremy Allison <jra at samba.org>

commit 6334f807d21a54d8da0f3f9531b3f49e921e072d
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Jun 8 10:11:57 2012 +0200

    s3:smbd: add file_fsp_smb2()
    
    metze
    
    Signed-off-by: Jeremy Allison <jra at samba.org>

commit 46d293d03a895d82bfbf2b6b0c6af797acc39d0e
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Jun 8 11:19:00 2012 +0200

    s3:smb2_write: pass fsp->fnum to init_strict_lock_struct()
    
    fsp->fnum is the same as in_file_id_volatile.
    
    When we start to support durable handles we should pass
    in_file_id_persistent.
    
    metze
    
    Autobuild-User(master): Stefan Metzmacher <metze at samba.org>
    Autobuild-Date(master): Sat Jun  9 18:50:32 CEST 2012 on sn-devel-104
    
    Signed-off-by: Jeremy Allison <jra at samba.org>

commit 0afc9592774b0084a0c5d3191e91570f124447fa
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Jun 8 11:19:00 2012 +0200

    s3:smb2_read: pass fsp->fnum to init_strict_lock_struct()
    
    fsp->fnum is the same as in_file_id_volatile.
    
    When we start to support durable handles we should pass
    in_file_id_persistent.
    
    metze
    
    Signed-off-by: Jeremy Allison <jra at samba.org>

commit c47b3ff25fcc62be3bc96ecf797990e61f5d08ef
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Jun 8 11:19:00 2012 +0200

    s3:smb2_lock: use fsp->fnum as locking context
    
    fsp->fnum is the same as in_file_id_volatile.
    
    When we start to support durable handles we should pass
    in_file_id_persistent.
    
    metze
    
    Signed-off-by: Jeremy Allison <jra at samba.org>

commit 09dde2e60ee78a60a7521f2225fed7d8a74620d0
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Jun 8 12:05:56 2012 +0200

    s3:smb2_lock: use smb2req->compat_chain_fsp instead of looking it up again
    
    metze
    
    Signed-off-by: Jeremy Allison <jra at samba.org>

commit 6ed9df52ec81a8bca884d452adec92f89fdfe2cd
Author: Stefan Metzmacher <metze at samba.org>
Date:   Sat Jun 9 11:09:25 2012 +0200

    s3:smbd: set req->smb2req->compat_chain_fsp in file_fsp()
    
    metze
    
    Signed-off-by: Jeremy Allison <jra at samba.org>

-----------------------------------------------------------------------

Summary of changes:
 source3/smbd/files.c        |   89 ++++++++++++++++++++++++++++++++++++++++++-
 source3/smbd/proto.h        |    4 ++
 source3/smbd/smb2_break.c   |   48 +++++++----------------
 source3/smbd/smb2_close.c   |   28 ++++----------
 source3/smbd/smb2_create.c  |    2 +-
 source3/smbd/smb2_find.c    |   35 ++++------------
 source3/smbd/smb2_flush.c   |   35 ++++------------
 source3/smbd/smb2_getinfo.c |   41 ++++++--------------
 source3/smbd/smb2_ioctl.c   |   46 ++++++++--------------
 source3/smbd/smb2_lock.c    |   51 +++++++------------------
 source3/smbd/smb2_notify.c  |   35 ++++------------
 source3/smbd/smb2_read.c    |   44 ++++++---------------
 source3/smbd/smb2_setinfo.c |   41 ++++++--------------
 source3/smbd/smb2_write.c   |   37 +++++-------------
 14 files changed, 220 insertions(+), 316 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source3/smbd/files.c b/source3/smbd/files.c
index bdf85db..58c24a8 100644
--- a/source3/smbd/files.c
+++ b/source3/smbd/files.c
@@ -28,12 +28,26 @@
 #define FILE_HANDLE_OFFSET 0x1000
 
 /****************************************************************************
- Return a unique number identifying this fsp over the life of this pid.
+ Return a unique number identifying this fsp over the life of this pid,
+ and try to make it as globally unique as possible.
+ See bug #8995 for the details.
 ****************************************************************************/
 
 static unsigned long get_gen_count(struct smbd_server_connection *sconn)
 {
+	/*
+	 * While fsp->fh->gen_id is 'unsigned long' currently
+	 * (which might by 8 bytes),
+	 * there's some oplock code which truncates it to
+	 * uint32_t(using IVAL()).
+	 */
+	if (sconn->file_gen_counter == 0) {
+		sconn->file_gen_counter = generate_random();
+	}
 	sconn->file_gen_counter += 1;
+	if (sconn->file_gen_counter >= UINT32_MAX) {
+		sconn->file_gen_counter = 0;
+	}
 	if (sconn->file_gen_counter == 0) {
 		sconn->file_gen_counter += 1;
 	}
@@ -284,6 +298,10 @@ files_struct *file_find_dif(struct smbd_server_connection *sconn,
 	int count=0;
 	files_struct *fsp;
 
+	if (gen_id == 0) {
+		return NULL;
+	}
+
 	for (fsp=sconn->files; fsp; fsp=fsp->next,count++) {
 		/* We can have a fsp->fh->fd == -1 here as it could be a stat open. */
 		if (file_id_equal(&fsp->file_id, &id) &&
@@ -548,6 +566,75 @@ files_struct *file_fsp(struct smb_request *req, uint16 fid)
 	return fsp;
 }
 
+uint64_t fsp_persistent_id(const struct files_struct *fsp)
+{
+	uint64_t persistent_id;
+
+	/*
+	 * This calculates a number that is most likely
+	 * globally unique. In future we will have a database
+	 * to make it completely unique.
+	 *
+	 * 32-bit random gen_id
+	 * 16-bit truncated open_time
+	 * 16-bit fnum (valatile_id)
+	 */
+	persistent_id = fsp->fh->gen_id & UINT32_MAX;
+	persistent_id <<= 16;
+	persistent_id &= 0x0000FFFFFFFF0000LLU;
+	persistent_id |= fsp->open_time.tv_usec & UINT16_MAX;
+	persistent_id <<= 16;
+	persistent_id &= 0xFFFFFFFFFFFF0000LLU;
+	persistent_id |= fsp->fnum & UINT16_MAX;
+
+	return persistent_id;
+}
+
+struct files_struct *file_fsp_smb2(struct smbd_smb2_request *smb2req,
+				   uint64_t persistent_id,
+				   uint64_t volatile_id)
+{
+	struct files_struct *fsp;
+	uint64_t fsp_persistent;
+
+	if (smb2req->compat_chain_fsp != NULL) {
+		return smb2req->compat_chain_fsp;
+	}
+
+	if (volatile_id > UINT16_MAX) {
+		return NULL;
+	}
+
+	fsp = file_fnum(smb2req->sconn, (uint16_t)volatile_id);
+	if (fsp == NULL) {
+		return NULL;
+	}
+	fsp_persistent = fsp_persistent_id(fsp);
+
+	if (persistent_id != fsp_persistent) {
+		return NULL;
+	}
+
+	if (smb2req->tcon == NULL) {
+		return NULL;
+	}
+
+	if (smb2req->tcon->compat_conn != fsp->conn) {
+		return NULL;
+	}
+
+	if (smb2req->session == NULL) {
+		return NULL;
+	}
+
+	if (smb2req->session->vuid != fsp->vuid) {
+		return NULL;
+	}
+
+	smb2req->compat_chain_fsp = fsp;
+	return fsp;
+}
+
 /****************************************************************************
  Duplicate the file handle part for a DOS or FCB open.
 ****************************************************************************/
diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h
index e9f4624..d75138b 100644
--- a/source3/smbd/proto.h
+++ b/source3/smbd/proto.h
@@ -373,6 +373,10 @@ bool file_find_subpath(files_struct *dir_fsp);
 void file_sync_all(connection_struct *conn);
 void file_free(struct smb_request *req, files_struct *fsp);
 files_struct *file_fsp(struct smb_request *req, uint16 fid);
+uint64_t fsp_persistent_id(const struct files_struct *fsp);
+struct files_struct *file_fsp_smb2(struct smbd_smb2_request *smb2req,
+				   uint64_t persistent_id,
+				   uint64_t volatile_id);
 NTSTATUS dup_file_fsp(struct smb_request *req, files_struct *from,
 		      uint32 access_mask, uint32 share_access,
 		      uint32 create_options, files_struct *to);
diff --git a/source3/smbd/smb2_break.c b/source3/smbd/smb2_break.c
index ce583ac..4957a88 100644
--- a/source3/smbd/smb2_break.c
+++ b/source3/smbd/smb2_break.c
@@ -28,8 +28,8 @@
 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_volatile);
+						      struct files_struct *in_fsp,
+						      uint8_t in_oplock_level);
 static NTSTATUS smbd_smb2_oplock_break_recv(struct tevent_req *req,
 					    uint8_t *out_oplock_level);
 
@@ -42,6 +42,7 @@ NTSTATUS smbd_smb2_request_process_break(struct smbd_smb2_request *req)
 	uint8_t in_oplock_level;
 	uint64_t in_file_id_persistent;
 	uint64_t in_file_id_volatile;
+	struct files_struct *in_fsp;
 	struct tevent_req *subreq;
 
 	status = smbd_smb2_request_verify_sizes(req, 0x18);
@@ -62,17 +63,13 @@ 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) {
+	in_fsp = file_fsp_smb2(req, in_file_id_persistent, in_file_id_volatile);
+	if (in_fsp == NULL) {
 		return smbd_smb2_request_error(req, NT_STATUS_FILE_CLOSED);
 	}
 
-	subreq = smbd_smb2_oplock_break_send(req,
-					     req->sconn->smb2.event_ctx,
-					     req,
-					     in_oplock_level,
-					     in_file_id_volatile);
+	subreq = smbd_smb2_oplock_break_send(req, req->sconn->smb2.event_ctx,
+					     req, in_fsp, in_oplock_level);
 	if (subreq == NULL) {
 		return smbd_smb2_request_error(req, NT_STATUS_NO_MEMORY);
 	}
@@ -148,14 +145,12 @@ struct smbd_smb2_oplock_break_state {
 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_volatile)
+						      struct files_struct *fsp,
+						      uint8_t in_oplock_level)
 {
 	struct tevent_req *req;
 	struct smbd_smb2_oplock_break_state *state;
 	struct smb_request *smbreq;
-	connection_struct *conn = smb2req->tcon->compat_conn;
-	files_struct *fsp = NULL;
 	int oplocklevel = map_smb2_oplock_levels_to_samba(in_oplock_level);
 	bool break_to_none = (oplocklevel == NO_OPLOCK);
 	bool result;
@@ -168,30 +163,16 @@ static struct tevent_req *smbd_smb2_oplock_break_send(TALLOC_CTX *mem_ctx,
 	state->smb2req = smb2req;
 	state->out_oplock_level = SMB2_OPLOCK_LEVEL_NONE;
 
-	DEBUG(10,("smbd_smb2_oplock_break_send: file_id[0x%016llX] "
-		"samba level %d\n",
-		(unsigned long long)in_file_id_volatile,
-		oplocklevel));
+	DEBUG(10,("smbd_smb2_oplock_break_send: %s - fnum[%d] "
+		  "samba level %d\n",
+		  fsp_str_dbg(fsp), fsp->fnum,
+		  oplocklevel));
 
 	smbreq = smbd_smb2_fake_smb_request(smb2req);
 	if (tevent_req_nomem(smbreq, req)) {
 		return tevent_req_post(req, ev);
 	}
 
-	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 (conn != fsp->conn) {
-		tevent_req_nterror(req, NT_STATUS_FILE_CLOSED);
-		return tevent_req_post(req, ev);
-	}
-	if (smb2req->session->vuid != fsp->vuid) {
-		tevent_req_nterror(req, NT_STATUS_FILE_CLOSED);
-		return tevent_req_post(req, ev);
-	}
-
 	DEBUG(5,("smbd_smb2_oplock_break_send: got SMB2 oplock break (%u) from client "
 		"for file %s fnum = %d\n",
 		(unsigned int)in_oplock_level,
@@ -256,6 +237,7 @@ void send_break_message_smb2(files_struct *fsp, int level)
 				SMB2_OPLOCK_LEVEL_II :
 				SMB2_OPLOCK_LEVEL_NONE;
 	NTSTATUS status;
+	uint64_t fsp_persistent = fsp_persistent_id(fsp);
 
 	DEBUG(10,("send_break_message_smb2: sending oplock break "
 		"for file %s, fnum = %d, smb2 level %u\n",
@@ -264,7 +246,7 @@ 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->fnum,
+					fsp_persistent,
 					(uint64_t)fsp->fnum,
 					smb2_oplock_level);
 	if (!NT_STATUS_IS_OK(status)) {
diff --git a/source3/smbd/smb2_close.c b/source3/smbd/smb2_close.c
index ffe08cc..9459503 100644
--- a/source3/smbd/smb2_close.c
+++ b/source3/smbd/smb2_close.c
@@ -24,8 +24,8 @@
 #include "../libcli/smb/smb_common.h"
 
 static NTSTATUS smbd_smb2_close(struct smbd_smb2_request *req,
+				struct files_struct *fsp,
 				uint16_t in_flags,
-				uint64_t in_file_id_volatile,
 				DATA_BLOB *outbody);
 
 NTSTATUS smbd_smb2_request_process_close(struct smbd_smb2_request *req)
@@ -37,6 +37,7 @@ NTSTATUS smbd_smb2_request_process_close(struct smbd_smb2_request *req)
 	uint16_t in_flags;
 	uint64_t in_file_id_persistent;
 	uint64_t in_file_id_volatile;
+	struct files_struct *in_fsp;
 	NTSTATUS status;
 
 	status = smbd_smb2_request_verify_sizes(req, 0x18);
@@ -54,15 +55,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) {
+	in_fsp = file_fsp_smb2(req, in_file_id_persistent, in_file_id_volatile);
+	if (in_fsp == NULL) {
 		return smbd_smb2_request_error(req, NT_STATUS_FILE_CLOSED);
 	}
 
 	status = smbd_smb2_close(req,
+				in_fsp,
 				in_flags,
-				in_file_id_volatile,
 				&outbody);
 	if (!NT_STATUS_IS_OK(status)) {
 		return smbd_smb2_request_error(req, status);
@@ -73,14 +73,13 @@ NTSTATUS smbd_smb2_request_process_close(struct smbd_smb2_request *req)
 }
 
 static NTSTATUS smbd_smb2_close(struct smbd_smb2_request *req,
+				struct files_struct *fsp,
 				uint16_t in_flags,
-				uint64_t in_file_id_volatile,
 				DATA_BLOB *outbody)
 {
 	NTSTATUS status;
 	struct smb_request *smbreq;
 	connection_struct *conn = req->tcon->compat_conn;
-	files_struct *fsp;
 	struct smb_filename *smb_fname = NULL;
 	struct timespec mdate_ts, adate_ts, cdate_ts, create_date_ts;
 	uint64_t allocation_size = 0;
@@ -94,25 +93,14 @@ static NTSTATUS smbd_smb2_close(struct smbd_smb2_request *req,
 	ZERO_STRUCT(mdate_ts);
 	ZERO_STRUCT(cdate_ts);
 
-	DEBUG(10,("smbd_smb2_close: file_id[0x%016llX]\n",
-		  (unsigned long long)in_file_id_volatile));
+	DEBUG(10,("smbd_smb2_close: %s - fnum[%d]\n",
+		  fsp_str_dbg(fsp), fsp->fnum));
 
 	smbreq = smbd_smb2_fake_smb_request(req);
 	if (smbreq == NULL) {
 		return NT_STATUS_NO_MEMORY;
 	}
 
-	fsp = file_fsp(smbreq, (uint16_t)in_file_id_volatile);
-	if (fsp == NULL) {
-		return NT_STATUS_FILE_CLOSED;
-	}
-	if (conn != fsp->conn) {
-		return NT_STATUS_FILE_CLOSED;
-	}
-	if (req->session->vuid != fsp->vuid) {
-		return NT_STATUS_FILE_CLOSED;
-	}
-
 	posix_open = fsp->posix_open;
 	status = copy_smb_filename(talloc_tos(),
 				fsp->fsp_name,
diff --git a/source3/smbd/smb2_create.c b/source3/smbd/smb2_create.c
index a98422c..c6e3fc3 100644
--- a/source3/smbd/smb2_create.c
+++ b/source3/smbd/smb2_create.c
@@ -827,7 +827,7 @@ static struct tevent_req *smbd_smb2_create_send(TALLOC_CTX *mem_ctx,
 	if (state->out_file_attributes == 0) {
 		state->out_file_attributes = FILE_ATTRIBUTE_NORMAL;
 	}
-	state->out_file_id_persistent = result->fnum;
+	state->out_file_id_persistent = fsp_persistent_id(result);
 	state->out_file_id_volatile = result->fnum;
 	state->out_context_blobs = out_context_blobs;
 
diff --git a/source3/smbd/smb2_find.c b/source3/smbd/smb2_find.c
index 3dcc768..59e5b66 100644
--- a/source3/smbd/smb2_find.c
+++ b/source3/smbd/smb2_find.c
@@ -28,10 +28,10 @@
 static struct tevent_req *smbd_smb2_find_send(TALLOC_CTX *mem_ctx,
 					      struct tevent_context *ev,
 					      struct smbd_smb2_request *smb2req,
+					      struct files_struct *in_fsp,
 					      uint8_t in_file_info_class,
 					      uint8_t in_flags,
 					      uint32_t in_file_index,
-					      uint64_t in_file_id_volatile,
 					      uint32_t in_output_buffer_length,
 					      const char *in_file_name);
 static NTSTATUS smbd_smb2_find_recv(struct tevent_req *req,
@@ -49,6 +49,7 @@ NTSTATUS smbd_smb2_request_process_find(struct smbd_smb2_request *req)
 	uint32_t in_file_index;
 	uint64_t in_file_id_persistent;
 	uint64_t in_file_id_volatile;
+	struct files_struct *in_fsp;
 	uint16_t in_file_name_offset;
 	uint16_t in_file_name_length;
 	DATA_BLOB in_file_name_buffer;
@@ -115,19 +116,16 @@ 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) {
+	in_fsp = file_fsp_smb2(req, in_file_id_persistent, in_file_id_volatile);
+	if (in_fsp == NULL) {
 		return smbd_smb2_request_error(req, NT_STATUS_FILE_CLOSED);
 	}
 
-	subreq = smbd_smb2_find_send(req,
-				     req->sconn->smb2.event_ctx,
-				     req,
+	subreq = smbd_smb2_find_send(req, req->sconn->smb2.event_ctx,
+				     req, in_fsp,
 				     in_file_info_class,
 				     in_flags,
 				     in_file_index,
-				     in_file_id_volatile,
 				     in_output_buffer_length,
 				     in_file_name_string);
 	if (subreq == NULL) {
@@ -207,10 +205,10 @@ struct smbd_smb2_find_state {
 static struct tevent_req *smbd_smb2_find_send(TALLOC_CTX *mem_ctx,
 					      struct tevent_context *ev,
 					      struct smbd_smb2_request *smb2req,
+					      struct files_struct *fsp,
 					      uint8_t in_file_info_class,
 					      uint8_t in_flags,
 					      uint32_t in_file_index,
-					      uint64_t in_file_id_volatile,
 					      uint32_t in_output_buffer_length,
 					      const char *in_file_name)
 {
@@ -218,7 +216,6 @@ static struct tevent_req *smbd_smb2_find_send(TALLOC_CTX *mem_ctx,
 	struct smbd_smb2_find_state *state;
 	struct smb_request *smbreq;
 	connection_struct *conn = smb2req->tcon->compat_conn;
-	files_struct *fsp;
 	NTSTATUS status;
 	NTSTATUS empty_status;
 	uint32_t info_level;
@@ -241,28 +238,14 @@ static struct tevent_req *smbd_smb2_find_send(TALLOC_CTX *mem_ctx,
 	state->smb2req = smb2req;
 	state->out_output_buffer = data_blob_null;
 
-	DEBUG(10,("smbd_smb2_find_send: file_id[0x%016llX]\n",
-		  (unsigned long long)in_file_id_volatile));
+	DEBUG(10,("smbd_smb2_find_send: %s - fnum[%d]\n",
+		  fsp_str_dbg(fsp), fsp->fnum));
 
 	smbreq = smbd_smb2_fake_smb_request(smb2req);
 	if (tevent_req_nomem(smbreq, req)) {
 		return tevent_req_post(req, ev);
 	}
 
-	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 (conn != fsp->conn) {
-		tevent_req_nterror(req, NT_STATUS_FILE_CLOSED);
-		return tevent_req_post(req, ev);
-	}
-	if (smb2req->session->vuid != fsp->vuid) {
-		tevent_req_nterror(req, NT_STATUS_FILE_CLOSED);
-		return tevent_req_post(req, ev);
-	}
-
 	if (!fsp->is_directory) {
 		tevent_req_nterror(req, NT_STATUS_NOT_SUPPORTED);
 		return tevent_req_post(req, ev);
diff --git a/source3/smbd/smb2_flush.c b/source3/smbd/smb2_flush.c
index 5f3c42a..d24cb86 100644
--- a/source3/smbd/smb2_flush.c
+++ b/source3/smbd/smb2_flush.c
@@ -27,7 +27,7 @@
 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_volatile);
+					       struct files_struct *fsp);
 static NTSTATUS smbd_smb2_flush_recv(struct tevent_req *req);
 
 static void smbd_smb2_request_flush_done(struct tevent_req *subreq);
@@ -38,6 +38,7 @@ NTSTATUS smbd_smb2_request_process_flush(struct smbd_smb2_request *req)
 	int i = req->current_idx;
 	uint64_t in_file_id_persistent;
 	uint64_t in_file_id_volatile;
+	struct files_struct *in_fsp;
 	struct tevent_req *subreq;
 
 	status = smbd_smb2_request_verify_sizes(req, 0x18);
@@ -49,16 +50,13 @@ 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) {
+	in_fsp = file_fsp_smb2(req, in_file_id_persistent, in_file_id_volatile);
+	if (in_fsp == NULL) {
 		return smbd_smb2_request_error(req, NT_STATUS_FILE_CLOSED);
 	}
 
-	subreq = smbd_smb2_flush_send(req,
-				      req->sconn->smb2.event_ctx,
-				      req,
-				      in_file_id_volatile);
+	subreq = smbd_smb2_flush_send(req, req->sconn->smb2.event_ctx,
+				      req, in_fsp);
 	if (subreq == NULL) {
 		return smbd_smb2_request_error(req, NT_STATUS_NO_MEMORY);
 	}
@@ -116,13 +114,12 @@ 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_volatile)
+					       struct files_struct *fsp)
 {
 	struct tevent_req *req;
 	struct smbd_smb2_flush_state *state;
 	NTSTATUS status;
 	struct smb_request *smbreq;
-	files_struct *fsp;
 


-- 
Samba Shared Repository


More information about the samba-cvs mailing list