[SCM] Samba Shared Repository - branch v4-2-test updated

Karolin Seeger kseeger at samba.org
Sun Feb 22 08:42:07 MST 2015


The branch, v4-2-test has been updated
       via  bba7796 s3: smbd: SMB2 close. If a file has delete on close, store the return info before deleting.
       via  381e601 s3: smbd: SMB2 close. Call utility function setup_close_full_information()
       via  66acf5b s3: smbd: SMB2 close. Add utility function setup_close_full_information()
       via  22578e8 s4: smbtorture: leases - show stat opens grant leases and can be broken.
       via  6eadda1 s3: smbd: leases - losen paranoia check. Stat opens can grant leases.
       via  8b7e8ee s3: smbd: leases - new torture test shows stat opens can get leases.
      from  8409939 samba-tool: Create NIS enabled users and unixHomeDirectory attribute

https://git.samba.org/?p=samba.git;a=shortlog;h=v4-2-test


- Log -----------------------------------------------------------------
commit bba7796a7326a4b4fafcf3b36fe4a2c44eb42a8d
Author: Jeremy Allison <jra at samba.org>
Date:   Thu Feb 19 18:50:45 2015 -0800

    s3: smbd: SMB2 close. If a file has delete on close, store the return info before deleting.
    
    If we delete the file on close, the stat after the close
    will fail so we fail to return the attributes requested.
    
    Bug 11104 - SMB2/SMB3 close response does not include attributes when requested.
    
    https://bugzilla.samba.org/show_bug.cgi?id=11104
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Steve French <sfrench at samba.org>
    
    Autobuild-User(master): Jeremy Allison <jra at samba.org>
    Autobuild-Date(master): Fri Feb 20 20:54:18 CET 2015 on sn-devel-104
    
    (cherry picked from commit a6008b2de7b2974073f38a1df88aacc27d3c6f57)
    
    Autobuild-User(v4-2-test): Karolin Seeger <kseeger at samba.org>
    Autobuild-Date(v4-2-test): Sun Feb 22 16:41:21 CET 2015 on sn-devel-104

commit 381e60190262d9d293de8f707b6f2d23e1418879
Author: Jeremy Allison <jra at samba.org>
Date:   Thu Feb 19 18:49:03 2015 -0800

    s3: smbd: SMB2 close. Call utility function setup_close_full_information()
    
    Replaces existing inline code.
    
    Bug 11104 - SMB2/SMB3 close response does not include attributes when requested.
    
    https://bugzilla.samba.org/show_bug.cgi?id=11104
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Steve French <sfrench at samba.org>
    (cherry picked from commit 4a8c6988e349a4f714f3052ebf3f96f801d3c11f)

commit 66acf5bc704033070ba2074d0c6519ea9e44a70e
Author: Jeremy Allison <jra at samba.org>
Date:   Thu Feb 19 18:46:55 2015 -0800

    s3: smbd: SMB2 close. Add utility function setup_close_full_information()
    
    Not yet used.
    
    Bug 11104 - SMB2/SMB3 close response does not include attributes when requested.
    
    https://bugzilla.samba.org/show_bug.cgi?id=11104
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Steve French <sfrench at samba.org>
    (cherry picked from commit 2ccfdf760e4adcf25d59c629c9d6d6b31a10a9f1)

commit 22578e83789e247dacd90036a40cf78b53f9ab39
Author: Jeremy Allison <jra at samba.org>
Date:   Wed Feb 18 11:51:53 2015 -0800

    s4: smbtorture: leases - show stat opens grant leases and can be broken.
    
    https://bugzilla.samba.org/show_bug.cgi?id=11102
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Ralph Böhme <slow at samba.org>
    
    Autobuild-User(master): Jeremy Allison <jra at samba.org>
    Autobuild-Date(master): Thu Feb 19 23:10:43 CET 2015 on sn-devel-104
    
    (cherry picked from commit 75dff778c5f13c008419cf292d2ea73cf3a33d7b)

commit 6eadda106e9ba7de535575bb2a0c874d0345f347
Author: Jeremy Allison <jra at samba.org>
Date:   Wed Feb 18 11:49:27 2015 -0800

    s3: smbd: leases - losen paranoia check. Stat opens can grant leases.
    
    https://bugzilla.samba.org/show_bug.cgi?id=11102
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Ralph Böhme <slow at samba.org>
    (cherry picked from commit cec2a38e971ac83260f3a9a5c4ac7095f8d23d65)

commit 8b7e8eeb6ddeb3b5f3908fc5def8ee453cd06fc6
Author: Jeremy Allison <jra at samba.org>
Date:   Wed Feb 18 11:48:31 2015 -0800

    s3: smbd: leases - new torture test shows stat opens can get leases.
    
    Can also issue breaks on these leases.
    
    https://bugzilla.samba.org/show_bug.cgi?id=11102
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Ralph Böhme <slow at samba.org>
    (cherry picked from commit 2d3db5e7930af9dd2a70727b2f2828bd73a1ec3b)

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

Summary of changes:
 source3/smbd/files.c         |  3 +-
 source3/smbd/open.c          | 11 ++---
 source3/smbd/smb2_close.c    | 99 ++++++++++++++++++++++++++++++++------------
 source4/torture/smb2/lease.c | 79 +++++++++++++++++++++++++++++++++++
 4 files changed, 158 insertions(+), 34 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source3/smbd/files.c b/source3/smbd/files.c
index 1ad601a..f8a5a8f 100644
--- a/source3/smbd/files.c
+++ b/source3/smbd/files.c
@@ -322,7 +322,8 @@ files_struct *file_find_dif(struct smbd_server_connection *sconn,
 			}
 			/* Paranoia check. */
 			if ((fsp->fh->fd == -1) &&
-			    (fsp->oplock_type != NO_OPLOCK)) {
+			    (fsp->oplock_type != NO_OPLOCK &&
+			     fsp->oplock_type != LEASE_OPLOCK)) {
 				DEBUG(0,("file_find_dif: file %s file_id = "
 					 "%s, gen = %u oplock_type = %u is a "
 					 "stat open with oplock type !\n",
diff --git a/source3/smbd/open.c b/source3/smbd/open.c
index 06770e0..773b146 100644
--- a/source3/smbd/open.c
+++ b/source3/smbd/open.c
@@ -3099,7 +3099,8 @@ static NTSTATUS open_file_ntcreate(connection_struct *conn,
 
 	if (file_existed) {
 		/*
-		 * stat opens on existing files don't get oplocks or leases.
+		 * stat opens on existing files don't get oplocks.
+		 * They can get leases.
 		 *
 		 * Note that we check for stat open on the *open_access_mask*,
 		 * i.e. the access mask we actually used to do the open,
@@ -3108,12 +3109,8 @@ static NTSTATUS open_file_ntcreate(connection_struct *conn,
 		 * FILE_OVERWRITE and FILE_OVERWRITE_IF add in O_TRUNC,
 		 * which adds FILE_WRITE_DATA to open_access_mask.
 		 */
-		if (is_stat_open(open_access_mask)) {
-			if (lease) {
-				lease->lease_state = SMB2_LEASE_NONE;
-			} else {
-				oplock_request = NO_OPLOCK;
-			}
+		if (is_stat_open(open_access_mask) && lease == NULL) {
+			oplock_request = NO_OPLOCK;
 		}
 	}
 
diff --git a/source3/smbd/smb2_close.c b/source3/smbd/smb2_close.c
index 0e1475d..ed53e1b 100644
--- a/source3/smbd/smb2_close.c
+++ b/source3/smbd/smb2_close.c
@@ -149,6 +149,48 @@ static void smbd_smb2_request_close_done(struct tevent_req *subreq)
 	}
 }
 
+static void setup_close_full_information(connection_struct *conn,
+				struct smb_filename *smb_fname,
+				bool posix_open,
+				struct timespec *out_creation_ts,
+				struct timespec *out_last_access_ts,
+				struct timespec *out_last_write_ts,
+				struct timespec *out_change_ts,
+				uint16_t *out_flags,
+				uint64_t *out_allocation_size,
+				uint64_t *out_end_of_file,
+				uint32_t *out_file_attributes)
+{
+	int ret;
+	if (posix_open) {
+		ret = SMB_VFS_LSTAT(conn, smb_fname);
+	} else {
+		ret = SMB_VFS_STAT(conn, smb_fname);
+	}
+	if (ret != 0) {
+		return;
+	}
+
+	*out_flags = SMB2_CLOSE_FLAGS_FULL_INFORMATION;
+	*out_file_attributes = dos_mode(conn, smb_fname);
+	*out_last_write_ts = smb_fname->st.st_ex_mtime;
+	*out_last_access_ts = smb_fname->st.st_ex_atime;
+	*out_creation_ts = get_create_timespec(conn, NULL, smb_fname);
+	*out_change_ts = get_change_timespec(conn, NULL, smb_fname);
+
+	if (lp_dos_filetime_resolution(SNUM(conn))) {
+		dos_filetime_timespec(out_creation_ts);
+		dos_filetime_timespec(out_last_write_ts);
+		dos_filetime_timespec(out_last_access_ts);
+		dos_filetime_timespec(out_change_ts);
+	}
+	if (!(*out_file_attributes & FILE_ATTRIBUTE_DIRECTORY)) {
+		*out_end_of_file = get_file_size_stat(&smb_fname->st);
+	}
+
+	*out_allocation_size = SMB_VFS_GET_ALLOC_SIZE(conn, NULL, &smb_fname->st);
+}
+
 static NTSTATUS smbd_smb2_close(struct smbd_smb2_request *req,
 				struct files_struct *fsp,
 				uint16_t in_flags,
@@ -195,6 +237,26 @@ static NTSTATUS smbd_smb2_close(struct smbd_smb2_request *req,
 		return NT_STATUS_NO_MEMORY;
 	}
 
+	if ((in_flags & SMB2_CLOSE_FLAGS_FULL_INFORMATION) &&
+	    (fsp->initial_delete_on_close || fsp->delete_on_close)) {
+		/*
+		 * We might be deleting the file. Ensure we
+		 * return valid data from before the file got
+		 * removed.
+		 */
+		setup_close_full_information(conn,
+				smb_fname,
+				posix_open,
+				out_creation_ts,
+				out_last_access_ts,
+				out_last_write_ts,
+				out_change_ts,
+				&flags,
+				&allocation_size,
+				&file_size,
+				&dos_attrs);
+	}
+
 	status = close_file(smbreq, fsp, NORMAL_CLOSE);
 	if (!NT_STATUS_IS_OK(status)) {
 		DEBUG(5,("smbd_smb2_close: close_file[%s]: %s\n",
@@ -203,32 +265,17 @@ static NTSTATUS smbd_smb2_close(struct smbd_smb2_request *req,
 	}
 
 	if (in_flags & SMB2_CLOSE_FLAGS_FULL_INFORMATION) {
-		int ret;
-		if (posix_open) {
-			ret = SMB_VFS_LSTAT(conn, smb_fname);
-		} else {
-			ret = SMB_VFS_STAT(conn, smb_fname);
-		}
-		if (ret == 0) {
-			flags = SMB2_CLOSE_FLAGS_FULL_INFORMATION;
-			dos_attrs = dos_mode(conn, smb_fname);
-			*out_last_write_ts = smb_fname->st.st_ex_mtime;
-			*out_last_access_ts = smb_fname->st.st_ex_atime;
-			*out_creation_ts = get_create_timespec(conn, NULL, smb_fname);
-			*out_change_ts = get_change_timespec(conn, NULL, smb_fname);
-
-			if (lp_dos_filetime_resolution(SNUM(conn))) {
-				dos_filetime_timespec(out_creation_ts);
-				dos_filetime_timespec(out_last_write_ts);
-				dos_filetime_timespec(out_last_access_ts);
-				dos_filetime_timespec(out_change_ts);
-			}
-			if (!(dos_attrs & FILE_ATTRIBUTE_DIRECTORY)) {
-				file_size = get_file_size_stat(&smb_fname->st);
-			}
-
-			allocation_size = SMB_VFS_GET_ALLOC_SIZE(conn, NULL, &smb_fname->st);
-		}
+		setup_close_full_information(conn,
+				smb_fname,
+				posix_open,
+				out_creation_ts,
+				out_last_access_ts,
+				out_last_write_ts,
+				out_change_ts,
+				&flags,
+				&allocation_size,
+				&file_size,
+				&dos_attrs);
 	}
 
 	*out_flags = flags;
diff --git a/source4/torture/smb2/lease.c b/source4/torture/smb2/lease.c
index c1b6420..4b435a1 100644
--- a/source4/torture/smb2/lease.c
+++ b/source4/torture/smb2/lease.c
@@ -27,6 +27,7 @@
 #include "torture/smb2/proto.h"
 #include "torture/util.h"
 #include "libcli/smb/smbXcli_base.h"
+#include "libcli/security/security.h"
 #include "lib/param/param.h"
 
 #define CHECK_VAL(v, correct) do { \
@@ -912,6 +913,83 @@ done:
 	return ret;
 }
 
+static bool test_lease_statopen(struct torture_context *tctx,
+				   struct smb2_tree *tree)
+{
+	TALLOC_CTX *mem_ctx = talloc_new(tctx);
+	struct smb2_create io;
+	struct smb2_lease ls;
+	struct smb2_handle h1, h2;
+	NTSTATUS status;
+	const char *fname = "lease_statopen.dat";
+	bool ret = true;
+	uint32_t caps;
+
+	caps = smb2cli_conn_server_capabilities(
+		tree->session->transport->conn);
+	if (!(caps & SMB2_CAP_LEASING)) {
+		torture_skip(tctx, "leases are not supported");
+	}
+
+	smb2_util_unlink(tree, fname);
+
+	/* Create file. */
+	smb2_lease_create(&io, &ls, false, fname, LEASE1,
+			  smb2_util_lease_state("RWH"));
+	status = smb2_create(tree, mem_ctx, &io);
+	CHECK_STATUS(status, NT_STATUS_OK);
+	h1 = io.out.file.handle;
+	CHECK_CREATED(&io, CREATED, FILE_ATTRIBUTE_ARCHIVE);
+	CHECK_LEASE(&io, "RWH", true, LEASE1, 0);
+	smb2_util_close(tree, h1);
+
+	/* Stat open file with RWH lease. */
+	smb2_lease_create_share(&io, &ls, false, fname, 0, LEASE1,
+			  smb2_util_lease_state("RWH"));
+	io.in.desired_access = FILE_READ_ATTRIBUTES;
+	status = smb2_create(tree, mem_ctx, &io);
+	CHECK_STATUS(status, NT_STATUS_OK);
+	h2 = io.out.file.handle;
+	CHECK_LEASE(&io, "RWH", true, LEASE1, 0);
+
+	ZERO_STRUCT(break_info);
+
+	tree->session->transport->lease.handler	= torture_lease_handler;
+	tree->session->transport->lease.private_data = tree;
+
+	/* Ensure non-stat open doesn't break and gets same lease
+	   state as existing stat open. */
+	smb2_lease_create(&io, &ls, false, fname, LEASE1,
+			  smb2_util_lease_state(""));
+	status = smb2_create(tree, mem_ctx, &io);
+	CHECK_STATUS(status, NT_STATUS_OK);
+	h1 = io.out.file.handle;
+	CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE);
+	CHECK_LEASE(&io, "RWH", true, LEASE1, 0);
+
+	CHECK_NO_BREAK(tctx);
+	smb2_util_close(tree, h1);
+
+	/* Open with conflicting lease. stat open should break down to RH */
+	smb2_lease_create(&io, &ls, false, fname, LEASE2,
+			  smb2_util_lease_state("RWH"));
+	status = smb2_create(tree, mem_ctx, &io);
+	CHECK_STATUS(status, NT_STATUS_OK);
+	h1 = io.out.file.handle;
+	CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE);
+	CHECK_LEASE(&io, "RH", true, LEASE2, 0);
+
+	CHECK_BREAK_INFO("RWH", "RH", LEASE1);
+
+done:
+	smb2_util_close(tree, h2);
+	smb2_util_close(tree, h1);
+	smb2_util_unlink(tree, fname);
+	talloc_free(mem_ctx);
+	return ret;
+}
+
+
 static void torture_oplock_break_callback(struct smb2_request *req)
 {
 	NTSTATUS status;
@@ -3814,6 +3892,7 @@ struct torture_suite *torture_smb2_lease_init(void)
 				     test_lease_break_twice);
 	torture_suite_add_1smb2_test(suite, "nobreakself",
 				     test_lease_nobreakself);
+	torture_suite_add_1smb2_test(suite, "statopen", test_lease_statopen);
 	torture_suite_add_1smb2_test(suite, "upgrade", test_lease_upgrade);
 	torture_suite_add_1smb2_test(suite, "upgrade2", test_lease_upgrade2);
 	torture_suite_add_1smb2_test(suite, "upgrade3", test_lease_upgrade3);


-- 
Samba Shared Repository


More information about the samba-cvs mailing list