From d0b0591d8dcfc709f0daa99ff3adf389d911b1f0 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 18 Feb 2015 11:48:31 -0800 Subject: [PATCH 1/3] 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 --- source3/smbd/open.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) 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; } } -- 1.9.1 From cf1310f5d46975b568fb83c7f83372cbbcccea18 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 18 Feb 2015 11:49:27 -0800 Subject: [PATCH 2/3] 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 --- source3/smbd/files.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 19896a7..5b3741b 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", -- 1.9.1 From 35f877c4bca561c23f2b71fc20d63a287e194cd4 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 18 Feb 2015 11:51:53 -0800 Subject: [PATCH 3/3] 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 --- source4/torture/smb2/lease.c | 79 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) 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); -- 1.9.1