s4: torture: Add new SMB2 lease test test_lease_duplicate_open().
authorJeremy Allison <jra@samba.org>
Thu, 17 Feb 2022 18:58:32 +0000 (10:58 -0800)
committerJule Anger <janger@samba.org>
Mon, 7 Mar 2022 13:04:15 +0000 (13:04 +0000)
Checks we return INVALID_PARAMETER when trying to open a
different file with a duplicate lease key on the same share.

Checked against Windows10. Currently fails against smbd
so add knownfail.d/smb2-lease-duplicateopen

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14737

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: David Mulder <dmulder@suse.com>
(cherry picked from commit ca3896b6f8bbcad68f042720feceedfa29ddbd83)

selftest/knownfail.d/smb2-lease-duplicateopen [new file with mode: 0644]
source4/torture/smb2/lease.c

diff --git a/selftest/knownfail.d/smb2-lease-duplicateopen b/selftest/knownfail.d/smb2-lease-duplicateopen
new file mode 100644 (file)
index 0000000..1336b02
--- /dev/null
@@ -0,0 +1 @@
+^samba3.smb2.lease.duplicate_open\(nt4_dc\)
index e7407453006af92ac220b71d636dad7eaa569504..8f2eaee469edc7cc8e2e554ba90632aa0842df03 100644 (file)
@@ -4345,6 +4345,74 @@ done:
        return ret;
 }
 
+static bool test_lease_duplicate_open(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 = {{0}};
+       struct smb2_handle h2 = {{0}};
+       NTSTATUS status;
+       const char *fname1 = "duplicate_open1.dat";
+       const char *fname2 = "duplicate_open2.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");
+       }
+
+       /* Ensure files don't exist. */
+       smb2_util_unlink(tree, fname1);
+       smb2_util_unlink(tree, fname2);
+
+       /* Create file1 - LEASE1 key. */
+       smb2_lease_create(&io, &ls, false, fname1, 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);
+
+       /* Leave file1 open and leased. */
+
+       /* Create file2 - no lease. */
+       smb2_lease_create(&io, NULL, false, fname2, 0,
+                         smb2_util_lease_state("RWH"));
+       status = smb2_create(tree, mem_ctx, &io);
+       CHECK_STATUS(status, NT_STATUS_OK);
+       h2 = io.out.file.handle;
+       CHECK_CREATED(&io, CREATED, FILE_ATTRIBUTE_ARCHIVE);
+       /* Close it. */
+       smb2_util_close(tree, h2);
+
+       /*
+        * Try and open file2 with the same LEASE1 key - this should fail with.
+        * INVALID_PARAMETER.
+        */
+       smb2_lease_create(&io, &ls, false, fname2, LEASE1,
+                         smb2_util_lease_state("RWH"));
+       status = smb2_create(tree, mem_ctx, &io);
+       CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER);
+       /*
+        * If we did open this is an error, but save off
+        * the handle so we close below.
+        */
+       h2 = io.out.file.handle;
+
+done:
+       smb2_util_close(tree, h2);
+       smb2_util_close(tree, h1);
+       smb2_util_unlink(tree, fname1);
+       smb2_util_unlink(tree, fname2);
+       talloc_free(mem_ctx);
+       return ret;
+}
+
 struct torture_suite *torture_smb2_lease_init(TALLOC_CTX *ctx)
 {
        struct torture_suite *suite =
@@ -4390,6 +4458,8 @@ struct torture_suite *torture_smb2_lease_init(TALLOC_CTX *ctx)
                                test_lease_rename_wait);
        torture_suite_add_1smb2_test(suite, "duplicate_create",
                                test_lease_duplicate_create);
+       torture_suite_add_1smb2_test(suite, "duplicate_open",
+                               test_lease_duplicate_open);
 
 
        suite->description = talloc_strdup(suite, "SMB2-LEASE tests");