1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-08 21:18:16 +03:00

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

Lease variant of the reopen1a test which tests the
relevance of the client guid.

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
This commit is contained in:
Michael Adam 2016-03-15 10:02:14 +01:00 committed by Jeremy Allison
parent 7b557617e4
commit 3e90abe670
2 changed files with 171 additions and 0 deletions

View File

@ -193,6 +193,7 @@
^samba3.smb2.notify.rec
^samba3.smb2.durable-open.delete_on_close2
^samba3.smb2.durable-v2-open.app-instance
^samba3.smb2.durable-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

View File

@ -567,6 +567,175 @@ 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_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 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 = 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.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 = h;
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 = h;
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;
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
* In this case, a durable reconnect attempt with the
* correct client_guid yields a different error code.
*/
ZERO_STRUCT(io);
io.in.fname = fname;
io.in.durable_handle = h;
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 = h;
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); /* no dh response context... */
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)
@ -2589,6 +2758,7 @@ struct torture_suite *torture_smb2_durable_open_init(void)
torture_suite_add_1smb2_test(suite, "open-lease", test_durable_open_open_lease);
torture_suite_add_1smb2_test(suite, "reopen1", test_durable_open_reopen1);
torture_suite_add_1smb2_test(suite, "reopen1a", test_durable_open_reopen1a);
torture_suite_add_1smb2_test(suite, "reopen1a-lease", test_durable_open_reopen1a_lease);
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);