Commit e9586a65 authored by Michael Adam's avatar Michael Adam Committed by Jeremy Allison

torture:smb2: add durable-v2-open.reopen1a-lease

Lease variant of the reopen1a test which tests the
relevance of the client guid.
Signed-off-by: default avatarMichael Adam <obnox@samba.org>
Reviewed-by: default avatarJeremy Allison <jra@samba.org>

Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Tue Mar 22 03:47:02 CET 2016 on sn-devel-144
parent b853040d
......@@ -194,6 +194,7 @@
^samba3.smb2.durable-open.delete_on_close2
^samba3.smb2.durable-v2-open.app-instance
^samba3.smb2.durable-open.reopen1a-lease\(ad_dc\)$
^samba3.smb2.durable-v2-open.reopen1a-lease\(ad_dc\)$
^samba4.smb2.ioctl.req_resume_key\(ad_dc_ntvfs\) # not supported by s4 ntvfs server
^samba4.smb2.ioctl.copy_chunk_\w*\(ad_dc_ntvfs\) # not supported by s4 ntvfs server
^samba3.smb2.dir.one
......
......@@ -739,6 +739,188 @@ done:
return ret;
}
/**
* lease variant of reopen1a
*
* Basic test for doing a durable open and doing a session
* reconnect while the first session is still active and the
* handle is still open in the client.
* This closes the original session and a durable reconnect on
* the new session succeeds depending on the client guid:
*
* Durable reconnect on a session with a different client guid fails.
* Durable reconnect on a session with the original client guid succeeds.
*/
bool test_durable_v2_open_reopen1a_lease(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 GUID create_guid = GUID_random();
struct smb2_lease ls;
uint64_t lease_key;
bool ret = true;
struct smb2_tree *tree2 = NULL;
struct smb2_tree *tree3 = NULL;
uint64_t previous_session_id;
struct smbcli_options options;
struct GUID orig_client_guid;
options = tree->session->transport->options;
orig_client_guid = options.client_guid;
/* Choose a random name in case the state is left a little funky. */
snprintf(fname, 256, "durable_v2_open_reopen1a_lease_%s.dat",
generate_random_str(tctx, 8));
smb2_util_unlink(tree, fname);
lease_key = random();
smb2_lease_create(&io, &ls, false /* dir */, fname,
lease_key, smb2_util_lease_state("RWH"));
io.in.durable_open = false;
io.in.durable_open_v2 = true;
io.in.persistent_open = false;
io.in.create_guid = create_guid;
io.in.timeout = UINT32_MAX;
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, false);
CHECK_VAL(io.out.durable_open_v2, true);
CHECK_VAL(io.out.persistent_open, false);
CHECK_VAL(io.out.timeout, io.in.timeout);
CHECK_VAL(io.out.oplock_level, SMB2_OPLOCK_LEVEL_LEASE);
CHECK_VAL(io.out.lease_response.lease_key.data[0], lease_key);
CHECK_VAL(io.out.lease_response.lease_key.data[1], ~lease_key);
CHECK_VAL(io.out.lease_response.lease_state,
smb2_util_lease_state("RWH"));
CHECK_VAL(io.out.lease_response.lease_flags, 0);
CHECK_VAL(io.out.lease_response.lease_duration, 0);
previous_session_id = smb2cli_session_current_id(tree->session->smbXcli);
/*
* a session reconnect on a second tcp connection
* with a different client_guid does not allow
* the durable reconnect.
*/
options.client_guid = GUID_random();
ret = torture_smb2_connection_ext(tctx, previous_session_id,
&options, &tree2);
torture_assert_goto(tctx, ret, ret, done, "couldn't reconnect");
/*
* check that this has deleted the old session
*/
ZERO_STRUCT(io);
io.in.fname = fname;
io.in.durable_handle_v2 = h;
io.in.create_guid = create_guid;
io.in.lease_request = &ls;
status = smb2_create(tree, mem_ctx, &io);
CHECK_STATUS(status, NT_STATUS_USER_SESSION_DELETED);
TALLOC_FREE(tree);
/*
* but a durable reconnect on the new session with the wrong
* client guid fails
*/
ZERO_STRUCT(io);
io.in.fname = fname;
io.in.durable_handle_v2 = h;
io.in.create_guid = create_guid;
io.in.lease_request = &ls;
status = smb2_create(tree2, mem_ctx, &io);
CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
/*
* now a session reconnect on a second tcp connection
* with original client_guid allows the durable reconnect.
*/
options.client_guid = orig_client_guid;
//options.client_guid = GUID_random();
ret = torture_smb2_connection_ext(tctx, previous_session_id,
&options, &tree3);
torture_assert_goto(tctx, ret, ret, done, "couldn't reconnect");
/*
* check that this has deleted the old session
*/
ZERO_STRUCT(io);
io.in.fname = fname;
io.in.durable_handle_v2 = h;
io.in.create_guid = create_guid;
io.in.lease_request = &ls;
status = smb2_create(tree2, mem_ctx, &io);
CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
TALLOC_FREE(tree2);
/*
* but a durable reconnect on the new session succeeds:
*/
ZERO_STRUCT(io);
io.in.fname = fname;
io.in.durable_handle_v2 = h;
io.in.create_guid = create_guid;
io.in.lease_request = &ls;
status = smb2_create(tree3, 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.timeout, io.in.timeout);
CHECK_VAL(io.out.oplock_level, SMB2_OPLOCK_LEVEL_LEASE);
CHECK_VAL(io.out.lease_response.lease_key.data[0], lease_key);
CHECK_VAL(io.out.lease_response.lease_key.data[1], ~lease_key);
CHECK_VAL(io.out.lease_response.lease_state,
smb2_util_lease_state("RWH"));
CHECK_VAL(io.out.lease_response.lease_flags, 0);
CHECK_VAL(io.out.lease_response.lease_duration, 0);
_h = io.out.file.handle;
h = &_h;
done:
if (tree == NULL) {
tree = tree2;
}
if (tree == NULL) {
tree = tree3;
}
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, do a durable reopen (succeeds)
......@@ -1832,6 +2014,7 @@ struct torture_suite *torture_smb2_durable_v2_open_init(void)
torture_suite_add_1smb2_test(suite, "open-lease", test_durable_v2_open_lease);
torture_suite_add_1smb2_test(suite, "reopen1", test_durable_v2_open_reopen1);
torture_suite_add_1smb2_test(suite, "reopen1a", test_durable_v2_open_reopen1a);
torture_suite_add_1smb2_test(suite, "reopen1a-lease", test_durable_v2_open_reopen1a_lease);
torture_suite_add_1smb2_test(suite, "reopen2", test_durable_v2_open_reopen2);
torture_suite_add_1smb2_test(suite, "reopen2b", test_durable_v2_open_reopen2b);
torture_suite_add_1smb2_test(suite, "reopen2c", test_durable_v2_open_reopen2c);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment