From d8cd54962b158527e61e82a79eb49ee6da12c5a4 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Wed, 25 Sep 2013 18:31:10 +0200 Subject: s4:torture:smb2: add a durable-open.reopen-lease-v2 test like durable-open.reopen2-lease but with v2 lease requets Signed-off-by: Michael Adam Reviewed-by: Jeremy Allison Reviewed-by: Stefan Metzmacher --- source4/torture/smb2/durable_open.c | 238 ++++++++++++++++++++++++++++++++++++ 1 file changed, 238 insertions(+) (limited to 'source4/torture/smb2') diff --git a/source4/torture/smb2/durable_open.c b/source4/torture/smb2/durable_open.c index 56ecc6576c..42cf302bf4 100644 --- a/source4/torture/smb2/durable_open.c +++ b/source4/torture/smb2/durable_open.c @@ -718,6 +718,243 @@ done: return ret; } +/** + * lease v2 variant of reopen2 + * basic test for doing a durable open + * tcp disconnect, reconnect, do a durable reopen (succeeds) + */ +static bool test_durable_open_reopen2_lease_v2(struct torture_context *tctx, + struct smb2_tree *tree) +{ + NTSTATUS status; + TALLOC_CTX *mem_ctx = talloc_new(tctx); + char fname[256]; + struct smb2_handle _h; + struct smb2_handle *h = NULL; + struct smb2_create io; + struct smb2_lease ls; + uint64_t lease_key; + bool ret = true; + struct smbcli_options options; + uint32_t caps; + + caps = smb2cli_conn_server_capabilities(tree->session->transport->conn); + if (!(caps & SMB2_CAP_LEASING)) { + torture_skip(tctx, "leases are not supported"); + } + + options = tree->session->transport->options; + + /* Choose a random name in case the state is left a little funky. */ + snprintf(fname, 256, "durable_open_reopen2_%s.dat", + generate_random_str(tctx, 8)); + + smb2_util_unlink(tree, fname); + + lease_key = random(); + smb2_lease_v2_create(&io, &ls, false /* dir */, fname, + lease_key, 0, /* parent lease key */ + smb2_util_lease_state("RWH"), 0 /* lease epoch */); + io.in.durable_open = true; + + status = smb2_create(tree, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OK); + _h = io.out.file.handle; + h = &_h; + CHECK_CREATED(&io, CREATED, FILE_ATTRIBUTE_ARCHIVE); + + CHECK_VAL(io.out.durable_open, true); + CHECK_VAL(io.out.oplock_level, SMB2_OPLOCK_LEVEL_LEASE); + CHECK_VAL(io.out.lease_response_v2.lease_key.data[0], lease_key); + CHECK_VAL(io.out.lease_response_v2.lease_key.data[1], ~lease_key); + CHECK_VAL(io.out.lease_response_v2.lease_state, + smb2_util_lease_state("RWH")); + CHECK_VAL(io.out.lease_response_v2.lease_flags, 0); + CHECK_VAL(io.out.lease_response_v2.lease_duration, 0); + + /* disconnect, reconnect and then do durable reopen */ + TALLOC_FREE(tree); + + if (!torture_smb2_connection_ext(tctx, 0, &options, &tree)) { + torture_warning(tctx, "couldn't reconnect, bailing\n"); + ret = false; + goto done; + } + + /* a few failure tests: */ + + /* + * several attempts without lease attached: + * all fail with NT_STATUS_OBJECT_NAME_NOT_FOUND + * irrespective of file name provided + */ + + ZERO_STRUCT(io); + io.in.fname = ""; + io.in.durable_handle = h; + status = smb2_create(tree, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND); + + ZERO_STRUCT(io); + io.in.fname = "__non_existing_fname__"; + io.in.durable_handle = h; + status = smb2_create(tree, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND); + + ZERO_STRUCT(io); + io.in.fname = fname; + io.in.durable_handle = h; + status = smb2_create(tree, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND); + + /* + * attempt with lease provided, but + * with a changed lease key. => fails + */ + ZERO_STRUCT(io); + io.in.fname = fname; + io.in.durable_open = false; + io.in.durable_handle = h; + io.in.lease_request_v2 = &ls; + io.in.oplock_level = SMB2_OPLOCK_LEVEL_LEASE; + /* a wrong lease key lets the request fail */ + ls.lease_key.data[0]++; + + status = smb2_create(tree, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND); + + /* restore the correct lease key */ + ls.lease_key.data[0]--; + + /* + * this last failing attempt is almost correct: + * only problem is: we use the wrong filename... + * Note that this gives INVALID_PARAMETER. + * This is different from oplocks! + */ + ZERO_STRUCT(io); + io.in.fname = "__non_existing_fname__"; + io.in.durable_open = false; + io.in.durable_handle = h; + io.in.lease_request_v2 = &ls; + io.in.oplock_level = SMB2_OPLOCK_LEVEL_LEASE; + + status = smb2_create(tree, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER); + + /* + * Now for a succeeding reconnect: + */ + + ZERO_STRUCT(io); + io.in.fname = fname; + io.in.durable_open = false; + io.in.durable_handle = h; + io.in.lease_request_v2 = &ls; + io.in.oplock_level = SMB2_OPLOCK_LEVEL_LEASE; + + /* the requested lease state is irrelevant */ + ls.lease_state = smb2_util_lease_state(""); + + h = NULL; + + status = smb2_create(tree, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OK); + + CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE); + CHECK_VAL(io.out.durable_open, false); + CHECK_VAL(io.out.durable_open_v2, false); /* no dh2q response blob */ + CHECK_VAL(io.out.persistent_open, false); + CHECK_VAL(io.out.oplock_level, SMB2_OPLOCK_LEVEL_LEASE); + CHECK_VAL(io.out.lease_response_v2.lease_key.data[0], lease_key); + CHECK_VAL(io.out.lease_response_v2.lease_key.data[1], ~lease_key); + CHECK_VAL(io.out.lease_response_v2.lease_state, + smb2_util_lease_state("RWH")); + CHECK_VAL(io.out.lease_response_v2.lease_flags, 0); + CHECK_VAL(io.out.lease_response_v2.lease_duration, 0); + _h = io.out.file.handle; + h = &_h; + + /* disconnect one more time */ + TALLOC_FREE(tree); + + if (!torture_smb2_connection_ext(tctx, 0, &options, &tree)) { + torture_warning(tctx, "couldn't reconnect, bailing\n"); + ret = false; + goto done; + } + + /* + * demonstrate that various parameters are ignored + * in the reconnect + */ + + ZERO_STRUCT(io); + /* + * These are completely ignored by the server + */ + io.in.security_flags = 0x78; + io.in.oplock_level = 0x78; + io.in.impersonation_level = 0x12345678; + io.in.create_flags = 0x12345678; + io.in.reserved = 0x12345678; + io.in.desired_access = 0x12345678; + io.in.file_attributes = 0x12345678; + io.in.share_access = 0x12345678; + io.in.create_disposition = 0x12345678; + io.in.create_options = 0x12345678; + + /* + * only these are checked: + * - io.in.fname + * - io.in.durable_handle, + * - io.in.lease_request->lease_key + */ + + io.in.fname = fname; + io.in.durable_open_v2 = false; + io.in.durable_handle_v2 = h; + io.in.lease_request_v2 = &ls; + + /* the requested lease state is irrelevant */ + ls.lease_state = smb2_util_lease_state(""); + + h = NULL; + + status = smb2_create(tree, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OK); + + CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE); + CHECK_VAL(io.out.durable_open, false); + CHECK_VAL(io.out.durable_open_v2, false); /* no dh2q response blob */ + CHECK_VAL(io.out.persistent_open, false); + CHECK_VAL(io.out.oplock_level, SMB2_OPLOCK_LEVEL_LEASE); + CHECK_VAL(io.out.lease_response_v2.lease_key.data[0], lease_key); + CHECK_VAL(io.out.lease_response_v2.lease_key.data[1], ~lease_key); + CHECK_VAL(io.out.lease_response_v2.lease_state, + smb2_util_lease_state("RWH")); + CHECK_VAL(io.out.lease_response_v2.lease_flags, 0); + CHECK_VAL(io.out.lease_response_v2.lease_duration, 0); + + _h = io.out.file.handle; + h = &_h; + +done: + if (tree != NULL) { + if (h != NULL) { + smb2_util_close(tree, *h); + } + + smb2_util_unlink(tree, fname); + + talloc_free(tree); + } + + talloc_free(mem_ctx); + + return ret; +} + /** * basic test for doing a durable open * tcp disconnect, reconnect with a session reconnect and @@ -2128,6 +2365,7 @@ struct torture_suite *torture_smb2_durable_open_init(void) torture_suite_add_1smb2_test(suite, "reopen1", test_durable_open_reopen1); torture_suite_add_1smb2_test(suite, "reopen2", test_durable_open_reopen2); torture_suite_add_1smb2_test(suite, "reopen2-lease", test_durable_open_reopen2_lease); + torture_suite_add_1smb2_test(suite, "reopen2-lease-v2", test_durable_open_reopen2_lease_v2); torture_suite_add_1smb2_test(suite, "reopen2a", test_durable_open_reopen2a); torture_suite_add_1smb2_test(suite, "reopen3", test_durable_open_reopen3); torture_suite_add_1smb2_test(suite, "reopen4", test_durable_open_reopen4); -- cgit