From 50e1861381f4f04d8c0430d6e32ec53d59118be9 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 30 Apr 2012 16:40:14 +0200 Subject: s4:torture: add smb2.session.reconnect2 test This uses just one transport connection and demonstrates the implicit logoff of the previous session. metze --- source4/torture/smb2/session.c | 64 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) (limited to 'source4/torture/smb2') diff --git a/source4/torture/smb2/session.c b/source4/torture/smb2/session.c index 296c7251d6..516f1649bc 100644 --- a/source4/torture/smb2/session.c +++ b/source4/torture/smb2/session.c @@ -137,6 +137,69 @@ done: return ret; } +/** + * basic test for doing a session reconnect on one connection + */ +bool test_session_reconnect2(struct torture_context *tctx, struct smb2_tree *tree) +{ + NTSTATUS status; + TALLOC_CTX *mem_ctx = talloc_new(tctx); + char fname[256]; + struct smb2_handle _h1; + struct smb2_handle *h1 = NULL; + struct smb2_create io1; + uint64_t previous_session_id; + bool ret = true; + struct smb2_session *session2; + union smb_fileinfo qfinfo; + + /* Add some random component to the file name. */ + snprintf(fname, 256, "session_reconnect_%s.dat", + generate_random_str(tctx, 8)); + + smb2_util_unlink(tree, fname); + + smb2_oplock_create_share(&io1, fname, + smb2_util_share_access(""), + smb2_util_oplock_level("b")); + io1.in.create_options |= NTCREATEX_OPTIONS_DELETE_ON_CLOSE; + + status = smb2_create(tree, mem_ctx, &io1); + CHECK_STATUS(status, NT_STATUS_OK); + _h1 = io1.out.file.handle; + h1 = &_h1; + CHECK_CREATED(&io1, CREATED, FILE_ATTRIBUTE_ARCHIVE); + CHECK_VAL(io1.out.oplock_level, smb2_util_oplock_level("b")); + + /* disconnect, reconnect and then do durable reopen */ + previous_session_id = smb2cli_session_current_id(tree->session->smbXcli); + + torture_assert(tctx, torture_smb2_session_setup(tctx, tree->session->transport, + previous_session_id, tctx, &session2), + "session reconnect (on the same connection) failed"); + + /* try to access the file via the old handle */ + + ZERO_STRUCT(qfinfo); + qfinfo.generic.level = RAW_FILEINFO_POSITION_INFORMATION; + qfinfo.generic.in.file.handle = _h1; + status = smb2_getinfo_file(tree, mem_ctx, &qfinfo); + CHECK_STATUS(status, NT_STATUS_USER_SESSION_DELETED); + h1 = NULL; + +done: + if (h1 != NULL) { + smb2_util_close(tree, *h1); + } + + talloc_free(tree); + talloc_free(session2); + + talloc_free(mem_ctx); + + return ret; +} + bool test_session_reauth1(struct torture_context *tctx, struct smb2_tree *tree) { NTSTATUS status; @@ -734,6 +797,7 @@ struct torture_suite *torture_smb2_session_init(void) torture_suite_create(talloc_autofree_context(), "session"); torture_suite_add_1smb2_test(suite, "reconnect1", test_session_reconnect1); + torture_suite_add_1smb2_test(suite, "reconnect2", test_session_reconnect2); torture_suite_add_1smb2_test(suite, "reauth1", test_session_reauth1); torture_suite_add_1smb2_test(suite, "reauth2", test_session_reauth2); torture_suite_add_1smb2_test(suite, "reauth3", test_session_reauth3); -- cgit