summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2014-11-26 10:25:45 +0100
committerStefan Metzmacher <metze@samba.org>2014-11-27 16:45:06 +0100
commit6494597c0451944e2599736af116d6838e6aac4e (patch)
treeaf0e1444f9996561a71a9b25c1910e265f8721d5
parentb3a985ab6662cacb2ac399c667b48e03c0bd1bfe (diff)
downloadsamba-6494597c0451944e2599736af116d6838e6aac4e.tar.gz
s4:torture/smb2: smb2.lease.breaking5 test
This is like breaking4, but with an initial "R" lease instead of "RH". Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
-rw-r--r--source4/torture/smb2/lease.c120
1 files changed, 120 insertions, 0 deletions
diff --git a/source4/torture/smb2/lease.c b/source4/torture/smb2/lease.c
index dff8a11a89f..ff10d5c7595 100644
--- a/source4/torture/smb2/lease.c
+++ b/source4/torture/smb2/lease.c
@@ -2369,6 +2369,125 @@ done:
return ret;
}
+static bool test_lease_breaking5(struct torture_context *tctx,
+ struct smb2_tree *tree)
+{
+ TALLOC_CTX *mem_ctx = talloc_new(tctx);
+ struct smb2_create io1 = {};
+ struct smb2_create io2 = {};
+ struct smb2_create io3 = {};
+ struct smb2_lease ls1 = {};
+ struct smb2_lease ls1t = {};
+ struct smb2_handle h1 = {};
+ struct smb2_handle h2 = {};
+ struct smb2_handle h3 = {};
+ struct smb2_request *req2 = NULL;
+ struct torture_lease_break break_info_tmp = {};
+ struct smb2_lease_break_ack ack = {};
+ const char *fname = "lease_breaking5.dat";
+ bool ret = true;
+ NTSTATUS status;
+ 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);
+
+ tree->session->transport->lease.handler = torture_lease_handler;
+ tree->session->transport->lease.private_data = tree;
+ tree->session->transport->oplock.handler = torture_oplock_handler;
+ tree->session->transport->oplock.private_data = tree;
+
+ /*
+ * we defer acking the lease break.
+ */
+ ZERO_STRUCT(break_info);
+ break_info.lease_skip_ack = true;
+
+ smb2_lease_create_share(&io1, &ls1, false, fname,
+ smb2_util_share_access("RWD"),
+ LEASE1,
+ smb2_util_lease_state("R"));
+ status = smb2_create(tree, mem_ctx, &io1);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ h1 = io1.out.file.handle;
+ CHECK_CREATED(&io1, CREATED, FILE_ATTRIBUTE_ARCHIVE);
+ CHECK_LEASE(&io1, "R", true, LEASE1, 0);
+
+ CHECK_NO_BREAK(tctx);
+
+ /*
+ * a conflicting open is *not* blocked until we ack the
+ * lease break
+ */
+ smb2_oplock_create(&io2, fname, SMB2_OPLOCK_LEVEL_NONE);
+ io2.in.create_disposition = NTCREATEX_DISP_OVERWRITE;
+ req2 = smb2_create_send(tree, &io2);
+ torture_assert(tctx, req2 != NULL, "smb2_create_send");
+
+ /*
+ * We got a break from RH to NONE, we're supported to ack
+ * this downgrade
+ */
+ CHECK_BREAK_INFO("R", "", LEASE1);
+
+ break_info_tmp = break_info;
+ ZERO_STRUCT(break_info);
+ CHECK_NO_BREAK(tctx);
+
+ torture_assert(tctx, req2->state == SMB2_REQUEST_DONE, "req2 done");
+
+ status = smb2_create_recv(req2, tctx, &io2);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ h2 = io2.out.file.handle;
+ CHECK_CREATED(&io2, TRUNCATED, FILE_ATTRIBUTE_ARCHIVE);
+ CHECK_VAL(io2.out.oplock_level, SMB2_OPLOCK_LEVEL_NONE);
+
+ CHECK_NO_BREAK(tctx);
+
+ /*
+ * We now ask the server about the current lease state
+ * which should still be "RH", but with
+ * SMB2_LEASE_FLAG_BREAK_IN_PROGRESS.
+ */
+ smb2_lease_create_share(&io3, &ls1t, false, fname,
+ smb2_util_share_access("RWD"),
+ LEASE1,
+ smb2_util_lease_state(""));
+ status = smb2_create(tree, mem_ctx, &io3);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ h3 = io3.out.file.handle;
+ CHECK_CREATED(&io3, EXISTED, FILE_ATTRIBUTE_ARCHIVE);
+ CHECK_LEASE(&io3, "", true, LEASE1, 0);
+
+ /*
+ * We send an ack without without being asked.
+ */
+ CHECK_NO_BREAK(tctx);
+ break_info = break_info_tmp;
+ ack.in.lease.lease_key =
+ break_info.lease_break.current_lease.lease_key;
+ ack.in.lease.lease_state =
+ break_info.lease_break.new_lease_state;
+ ZERO_STRUCT(break_info);
+ status = smb2_lease_break_ack(tree, &ack);
+ CHECK_STATUS(status, NT_STATUS_UNSUCCESSFUL);
+
+ CHECK_NO_BREAK(tctx);
+
+done:
+ smb2_util_close(tree, h1);
+ smb2_util_close(tree, h2);
+ smb2_util_close(tree, h3);
+
+ smb2_util_unlink(tree, fname);
+ talloc_free(mem_ctx);
+ return ret;
+}
+
static bool test_lease_complex1(struct torture_context *tctx,
struct smb2_tree *tree1a)
{
@@ -2660,6 +2779,7 @@ struct torture_suite *torture_smb2_lease_init(void)
torture_suite_add_1smb2_test(suite, "breaking2", test_lease_breaking2);
torture_suite_add_1smb2_test(suite, "breaking3", test_lease_breaking3);
torture_suite_add_1smb2_test(suite, "breaking4", test_lease_breaking4);
+ torture_suite_add_1smb2_test(suite, "breaking5", test_lease_breaking5);
torture_suite_add_1smb2_test(suite, "complex1", test_lease_complex1);
torture_suite_add_1smb2_test(suite, "v2_request_parent",
test_lease_v2_request_parent);