From: Sachin Prabhu Date: Mon, 11 Mar 2019 20:05:02 +0000 (+0000) Subject: s4-torture: Add lease break retry tests - test1 X-Git-Url: http://git.samba.org/samba.git/?p=ambi%2Fsamba-autobuild%2F.git;a=commitdiff_plain;h=311c024b4cc8507515db82f9e12ea638759657ae s4-torture: Add lease break retry tests - test1 Test to check if lease breaks are sent by the server as expected. Signed-off-by: Guenther Deschner Signed-off-by: Sachin Prabhu Reviewed-by: Jeremy Allison --- diff --git a/source4/torture/smb2/multichannel.c b/source4/torture/smb2/multichannel.c index 58f8687b618..229ea005fd1 100644 --- a/source4/torture/smb2/multichannel.c +++ b/source4/torture/smb2/multichannel.c @@ -34,6 +34,7 @@ #include "lib/param/param.h" #include "lib/events/events.h" #include "oplock_break_handler.h" +#include "lease_break_handler.h" #include "torture/smb2/block.h" #define BASEDIR "multichanneltestdir" @@ -864,6 +865,213 @@ done: return ret; } +static const uint64_t LEASE1F1 = 0xBADC0FFEE0DDF00Dull; +static const uint64_t LEASE1F2 = 0xBADC0FFEE0DDD00Dull; +static const uint64_t LEASE1F3 = 0xDADC0FFEE0DDD00Dull; +static const uint64_t LEASE2F1 = 0xDEADBEEFFEEDBEADull; +static const uint64_t LEASE2F2 = 0xDAD0FFEDD00DF00Dull; +static const uint64_t LEASE2F3 = 0xBAD0FFEDD00DF00Dull; + +/* + * Lease Break Test 1: + * Test to check if lease breaks are sent by the server as expected. + * open file1 in session 2A + * open file2 in session 2B + * open file3 in session 2C + * open file1 in session 1 + * lease break sent + * open file2 in session 1 + * lease break sent + * open file3 in session 1 + * lease break sent + */ +static bool test_multichannel_lease_break_test1(struct torture_context *tctx, + struct smb2_tree *tree1) +{ + const char *host = torture_setting_string(tctx, "host", NULL); + const char *share = torture_setting_string(tctx, "share", NULL); + struct cli_credentials *credentials = popt_get_cmdline_credentials(); + NTSTATUS status; + TALLOC_CTX *mem_ctx = talloc_new(tctx); + struct smb2_handle _h; + struct smb2_handle *h = NULL; + struct smb2_handle h_client1_file1 = {{0}}; + struct smb2_handle h_client1_file2 = {{0}}; + struct smb2_handle h_client1_file3 = {{0}}; + struct smb2_handle h_client2_file1 = {{0}}; + struct smb2_handle h_client2_file2 = {{0}}; + struct smb2_handle h_client2_file3 = {{0}}; + struct smb2_create io1, io2, io3; + bool ret = true; + const char *fname1 = BASEDIR "\\lease_break_test1.dat"; + const char *fname2 = BASEDIR "\\lease_break_test2.dat"; + const char *fname3 = BASEDIR "\\lease_break_test3.dat"; + struct smb2_tree *tree2A = NULL; + struct smb2_tree *tree2B = NULL; + struct smb2_tree *tree2C = NULL; + struct smb2_transport *transport1 = tree1->session->transport; + struct smbcli_options transport2_options; + struct smb2_session *session1 = tree1->session; + uint16_t local_port = 0; + struct smb2_lease ls1; + struct smb2_lease ls2; + struct smb2_lease ls3; + + if (!test_multichannel_initial_checks(tctx, tree1)) { + return true; + } + + torture_comment(tctx, "Lease break retry: Test1\n"); + + torture_reset_lease_break_info(tctx, &lease_break_info); + + transport1->lease.handler = torture_lease_handler; + transport1->lease.private_data = tree1; + torture_comment(tctx, "transport1 [%p]\n", transport1); + local_port = torture_get_local_port_from_transport(transport1); + torture_comment(tctx, "transport1 uses tcp port: %d\n", local_port); + + status = torture_smb2_testdir(tree1, BASEDIR, &_h); + CHECK_STATUS(status, NT_STATUS_OK); + smb2_util_close(tree1, _h); + smb2_util_unlink(tree1, fname1); + smb2_util_unlink(tree1, fname2); + smb2_util_unlink(tree1, fname3); + CHECK_VAL(lease_break_info.count, 0); + + smb2_lease_create(&io1, &ls1, false, fname1, LEASE2F1, + smb2_util_lease_state("RHW")); + test_multichannel_init_smb_create(&io1); + + smb2_lease_create(&io2, &ls2, false, fname2, LEASE2F2, + smb2_util_lease_state("RHW")); + test_multichannel_init_smb_create(&io2); + + smb2_lease_create(&io3, &ls3, false, fname3, LEASE2F3, + smb2_util_lease_state("RHW")); + test_multichannel_init_smb_create(&io3); + + transport2_options = transport1->options; + + ret = test_multichannel_create_channels(tctx, host, share, + credentials, + &transport2_options, + &tree2A, &tree2B, &tree2C); + torture_assert(tctx, ret, "Could not create channels.\n"); + + /* 2a opens file1 */ + torture_comment(tctx, "client2 opens fname1 via session 2A\n"); + status = smb2_create(tree2A, mem_ctx, &io1); + CHECK_STATUS(status, NT_STATUS_OK); + h_client2_file1 = io1.out.file.handle; + CHECK_CREATED(&io1, CREATED, FILE_ATTRIBUTE_ARCHIVE); + CHECK_LEASE(&io1, "RHW", true, LEASE2F1, 0); + CHECK_VAL(lease_break_info.count, 0); + + /* 2b opens file2 */ + torture_comment(tctx, "client2 opens fname2 via session 2B\n"); + status = smb2_create(tree2B, mem_ctx, &io2); + CHECK_STATUS(status, NT_STATUS_OK); + h_client2_file2 = io2.out.file.handle; + CHECK_CREATED(&io2, CREATED, FILE_ATTRIBUTE_ARCHIVE); + CHECK_LEASE(&io2, "RHW", true, LEASE2F2, 0); + CHECK_VAL(lease_break_info.count, 0); + + /* 2c opens file3 */ + torture_comment(tctx, "client2 opens fname3 via session 2C\n"); + smb2_lease_create(&io3, &ls3, false, fname3, LEASE2F3, + smb2_util_lease_state("RHW")); + status = smb2_create(tree2C, mem_ctx, &io3); + CHECK_STATUS(status, NT_STATUS_OK); + h_client2_file3 = io3.out.file.handle; + CHECK_CREATED(&io3, CREATED, FILE_ATTRIBUTE_ARCHIVE); + CHECK_LEASE(&io3, "RHW", true, LEASE2F3, 0); + CHECK_VAL(lease_break_info.count, 0); + + /* 1 opens file1 - lease break? */ + torture_comment(tctx, "client1 opens fname1 via session 1\n"); + smb2_lease_create(&io1, &ls1, false, fname1, LEASE1F1, + smb2_util_lease_state("RHW")); + status = smb2_create(tree1, mem_ctx, &io1); + CHECK_STATUS(status, NT_STATUS_OK); + h_client1_file1 = io1.out.file.handle; + CHECK_CREATED(&io1, EXISTED, FILE_ATTRIBUTE_ARCHIVE); + CHECK_LEASE(&io1, "RH", true, LEASE1F1, 0); + CHECK_BREAK_INFO("RHW", "RH", LEASE2F1); + CHECK_VAL(lease_break_info.count, 1); + + torture_reset_lease_break_info(tctx, &lease_break_info); + + /* 1 opens file2 - lease break? */ + torture_comment(tctx, "client1 opens fname2 via session 1\n"); + smb2_lease_create(&io2, &ls2, false, fname2, LEASE1F2, + smb2_util_lease_state("RHW")); + status = smb2_create(tree1, mem_ctx, &io2); + CHECK_STATUS(status, NT_STATUS_OK); + h_client1_file2 = io2.out.file.handle; + CHECK_CREATED(&io2, EXISTED, FILE_ATTRIBUTE_ARCHIVE); + CHECK_LEASE(&io2, "RH", true, LEASE1F2, 0); + CHECK_BREAK_INFO("RHW", "RH", LEASE2F2); + CHECK_VAL(lease_break_info.count, 1); + + torture_reset_lease_break_info(tctx, &lease_break_info); + + /* 1 opens file3 - lease break? */ + torture_comment(tctx, "client1 opens fname3 via session 1\n"); + smb2_lease_create(&io3, &ls3, false, fname3, LEASE1F3, + smb2_util_lease_state("RHW")); + status = smb2_create(tree1, mem_ctx, &io3); + CHECK_STATUS(status, NT_STATUS_OK); + h_client1_file3 = io3.out.file.handle; + CHECK_CREATED(&io3, EXISTED, FILE_ATTRIBUTE_ARCHIVE); + CHECK_LEASE(&io3, "RH", true, LEASE1F3, 0); + CHECK_BREAK_INFO("RHW", "RH", LEASE2F3); + CHECK_VAL(lease_break_info.count, 1); + + /* cleanup everything */ + torture_reset_lease_break_info(tctx, &lease_break_info); + + smb2_util_close(tree1, h_client1_file1); + smb2_util_close(tree1, h_client1_file2); + smb2_util_close(tree1, h_client1_file3); + smb2_util_close(tree2A, h_client2_file1); + smb2_util_close(tree2A, h_client2_file2); + smb2_util_close(tree2A, h_client2_file3); + + smb2_util_unlink(tree1, fname1); + smb2_util_unlink(tree1, fname2); + smb2_util_unlink(tree1, fname3); + CHECK_VAL(lease_break_info.count, 0); + test_multichannel_free_channels(tree2A, tree2B, tree2C); + tree2A = tree2B = tree2C = NULL; +done: + tree1->session = session1; + + smb2_util_close(tree1, h_client1_file1); + smb2_util_close(tree1, h_client1_file2); + smb2_util_close(tree1, h_client1_file3); + if (tree2A != NULL) { + smb2_util_close(tree2A, h_client2_file1); + smb2_util_close(tree2A, h_client2_file2); + smb2_util_close(tree2A, h_client2_file3); + } + + if (h != NULL) { + smb2_util_close(tree1, *h); + } + + smb2_util_unlink(tree1, fname1); + smb2_util_unlink(tree1, fname2); + smb2_util_unlink(tree1, fname3); + smb2_deltree(tree1, BASEDIR); + + test_multichannel_free_channels(tree2A, tree2B, tree2C); + talloc_free(tree1); + talloc_free(mem_ctx); + + return ret; +} + struct torture_suite *torture_smb2_multichannel_init(TALLOC_CTX *ctx) { struct torture_suite *suite = torture_suite_create(ctx, "multichannel"); @@ -871,9 +1079,12 @@ struct torture_suite *torture_smb2_multichannel_init(TALLOC_CTX *ctx) "generic"); struct torture_suite *suite_oplocks = torture_suite_create(ctx, "oplocks"); + struct torture_suite *suite_leases = torture_suite_create(ctx, + "leases"); torture_suite_add_suite(suite, suite_generic); torture_suite_add_suite(suite, suite_oplocks); + torture_suite_add_suite(suite, suite_leases); torture_suite_add_1smb2_test(suite, "interface_info", test_multichannel_interface_info); @@ -881,6 +1092,8 @@ struct torture_suite *torture_smb2_multichannel_init(TALLOC_CTX *ctx) test_multichannel_oplock_break_test1); torture_suite_add_1smb2_test(suite_oplocks, "test2", test_multichannel_oplock_break_test2); + torture_suite_add_1smb2_test(suite_leases, "test1", + test_multichannel_lease_break_test1); suite->description = talloc_strdup(suite, "SMB2 Multichannel tests");