From: Jeremy Allison Date: Wed, 18 Feb 2015 19:51:53 +0000 (-0800) Subject: s4: smbtorture: leases - show stat opens grant leases and can be broken. X-Git-Tag: samba-4.2.0rc5~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=22578e83789e247dacd90036a40cf78b53f9ab39;p=thirdparty%2Fsamba.git 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 Reviewed-by: Ralph Böhme Autobuild-User(master): Jeremy Allison Autobuild-Date(master): Thu Feb 19 23:10:43 CET 2015 on sn-devel-104 (cherry picked from commit 75dff778c5f13c008419cf292d2ea73cf3a33d7b) --- diff --git a/source4/torture/smb2/lease.c b/source4/torture/smb2/lease.c index c1b6420bd7f..4b435a13a62 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);