From ba4acf05b24527e6de117c7f82324b6eab237717 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Sun, 26 Feb 2012 02:36:13 +0100 Subject: [PATCH] s4:torture:smb2: add durable_open.reopen2a - variant of reopen2 with session reconnect --- source4/torture/smb2/durable_open.c | 77 +++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/source4/torture/smb2/durable_open.c b/source4/torture/smb2/durable_open.c index 03e6c9066c4..6a3f52b3810 100644 --- a/source4/torture/smb2/durable_open.c +++ b/source4/torture/smb2/durable_open.c @@ -24,6 +24,7 @@ #include "libcli/smb2/smb2_calls.h" #include "torture/torture.h" #include "torture/smb2/proto.h" +#include "../libcli/smb/smbXcli_base.h" #define CHECK_VAL(v, correct) do { \ if ((v) != (correct)) { \ @@ -447,6 +448,81 @@ done: return ret; } +/** + * basic test for doing a durable open + * tcp disconnect, reconnect with a session reconnect and + * do a durable reopen (succeeds) + */ +bool test_durable_open_reopen2a(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 io1, io2; + uint64_t previous_session_id; + bool ret = true; + + /* 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); + + smb2_oplock_create_share(&io1, fname, + smb2_util_share_access(""), + smb2_util_oplock_level("b")); + io1.in.durable_open = true; + + status = smb2_create(tree, mem_ctx, &io1); + CHECK_STATUS(status, NT_STATUS_OK); + _h = io1.out.file.handle; + h = &_h; + CHECK_CREATED(&io1, CREATED, FILE_ATTRIBUTE_ARCHIVE); + CHECK_VAL(io1.out.durable_open, true); + 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); + talloc_free(tree); + tree = NULL; + + if (!torture_smb2_connection_ext(tctx, previous_session_id, &tree)) { + torture_warning(tctx, "couldn't reconnect, bailing\n"); + ret = false; + goto done; + } + + ZERO_STRUCT(io2); + io2.in.fname = fname; + io2.in.durable_handle = h; + h = NULL; + + status = smb2_create(tree, mem_ctx, &io2); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_CREATED(&io2, EXISTED, FILE_ATTRIBUTE_ARCHIVE); + CHECK_VAL(io2.out.durable_open, true); + CHECK_VAL(io2.out.oplock_level, smb2_util_oplock_level("b")); + _h = io2.out.file.handle; + h = &_h; + +done: + 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: * tdis, new tcon, try durable reopen (fails) @@ -1173,6 +1249,7 @@ struct torture_suite *torture_smb2_durable_open_init(void) torture_suite_add_1smb2_test(suite, "open2", test_durable_open_open2); 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, "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); torture_suite_add_2smb2_test(suite, "file-position", -- 2.34.1