s4:torture: Add smb2.oplock test batch9a and raw.oplock test batch9a
authorJeremy Allison <jra@samba.org>
Wed, 5 Nov 2014 18:12:20 +0000 (10:12 -0800)
committerJeremy Allison <jra@samba.org>
Fri, 7 Nov 2014 19:13:09 +0000 (20:13 +0100)
Shows attribute(stat) access open can create a file,
and subsequent attribute(stat) opens don't break oplocks.

Can be extended to explore more varients.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
selftest/knownfail
source4/torture/raw/oplock.c
source4/torture/smb2/oplock.c

index 6cca3dd62d6733848613625306dfb90ee2266995..1c4f446129abb5fda04644528d5614a3f07d3c7e 100644 (file)
 ^samba4.smb2.oplock.batch1\(.*\)$ # samba 4 oplocks are a mess
 ^samba4.smb2.oplock.batch6\(.*\)$ # samba 4 oplocks are a mess
 ^samba4.smb2.oplock.batch9\(.*\)$ # samba 4 oplocks are a mess
+^samba4.smb2.oplock.batch9a\(.*\)$ # samba 4 oplocks are a mess
 ^samba4.smb2.oplock.batch10\(.*\)$ # samba 4 oplocks are a mess
 ^samba4.smb2.oplock.batch20\(.*\)$ # samba 4 oplocks are a mess
 ^samba4.smb2.oplock.batch26\(.*\)$
index a4f6a0555ef345ff3387a70b4a5a871c0c1b51fb..1d7522f541946cc57fa010c8b00b634d6c29e083 100644 (file)
@@ -1873,6 +1873,126 @@ done:
        return ret;
 }
 
+static bool test_raw_oplock_batch9a(struct torture_context *tctx, struct smbcli_state *cli1, struct smbcli_state *cli2)
+{
+       const char *fname = BASEDIR "\\test_batch9a.dat";
+       NTSTATUS status;
+       bool ret = true;
+       union smb_open io;
+       uint16_t fnum=0, fnum2=0;
+       char c = 0;
+
+       if (!torture_setup_dir(cli1, BASEDIR)) {
+               return false;
+       }
+
+       /* cleanup */
+       smbcli_unlink(cli1->tree, fname);
+
+       smbcli_oplock_handler(cli1->transport, oplock_handler_ack_to_given, cli1->tree);
+
+       /*
+         base ntcreatex parms
+       */
+       io.generic.level = RAW_OPEN_NTCREATEX;
+       io.ntcreatex.in.root_fid.fnum = 0;
+       io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
+       io.ntcreatex.in.alloc_size = 0;
+       io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
+       io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
+       io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN_IF;
+       io.ntcreatex.in.create_options = 0;
+       io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
+       io.ntcreatex.in.security_flags = 0;
+       io.ntcreatex.in.fname = fname;
+
+       torture_comment(tctx, "BATCH9: open with attributes only can create file\n");
+
+       io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED |
+               NTCREATEX_FLAGS_REQUEST_OPLOCK |
+               NTCREATEX_FLAGS_REQUEST_BATCH_OPLOCK;
+       io.ntcreatex.in.access_mask = SEC_FILE_READ_ATTRIBUTE|SEC_FILE_WRITE_ATTRIBUTE|SEC_STD_SYNCHRONIZE;
+       status = smb_raw_open(cli1->tree, tctx, &io);
+       CHECK_STATUS(tctx, status, NT_STATUS_OK);
+       fnum = io.ntcreatex.out.file.fnum;
+       CHECK_VAL(io.ntcreatex.out.create_action, FILE_WAS_CREATED);
+       CHECK_VAL(io.ntcreatex.out.oplock_level, BATCH_OPLOCK_RETURN);
+
+       torture_comment(tctx, "Subsequent attributes open should not break\n");
+
+       ZERO_STRUCT(break_info);
+       smbcli_oplock_handler(cli1->transport, oplock_handler_ack_to_given, cli1->tree);
+
+       status = smb_raw_open(cli2->tree, tctx, &io);
+       CHECK_STATUS(tctx, status, NT_STATUS_OK);
+       fnum2 = io.ntcreatex.out.file.fnum;
+       torture_wait_for_oplock_break(tctx);
+       CHECK_VAL(break_info.count, 0);
+       CHECK_VAL(io.ntcreatex.out.create_action, FILE_WAS_OPENED);
+       CHECK_VAL(io.ntcreatex.out.oplock_level, NO_OPLOCK_RETURN);
+       smbcli_close(cli2->tree, fnum2);
+
+       torture_comment(tctx, "Subsequent normal open should break oplock on attribute only open to level II\n");
+
+       ZERO_STRUCT(break_info);
+       smbcli_oplock_handler(cli1->transport, oplock_handler_ack_to_given, cli1->tree);
+
+       io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED |
+               NTCREATEX_FLAGS_REQUEST_OPLOCK |
+               NTCREATEX_FLAGS_REQUEST_BATCH_OPLOCK;
+       io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
+       io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
+       status = smb_raw_open(cli2->tree, tctx, &io);
+       CHECK_STATUS(tctx, status, NT_STATUS_OK);
+       fnum2 = io.ntcreatex.out.file.fnum;
+       torture_wait_for_oplock_break(tctx);
+       CHECK_VAL(break_info.count, 1);
+       CHECK_VAL(break_info.fnum, fnum);
+       CHECK_VAL(break_info.failures, 0);
+       CHECK_VAL(break_info.level, OPLOCK_BREAK_TO_LEVEL_II);
+       CHECK_VAL(io.ntcreatex.out.oplock_level, LEVEL_II_OPLOCK_RETURN);
+       smbcli_close(cli2->tree, fnum2);
+
+       torture_comment(tctx, "third oplocked open should grant level2 without break\n");
+       ZERO_STRUCT(break_info);
+       smbcli_oplock_handler(cli1->transport, oplock_handler_ack_to_given, cli1->tree);
+       smbcli_oplock_handler(cli2->transport, oplock_handler_ack_to_given, cli2->tree);
+       io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED |
+               NTCREATEX_FLAGS_REQUEST_OPLOCK |
+               NTCREATEX_FLAGS_REQUEST_BATCH_OPLOCK;
+       io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
+       io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
+       status = smb_raw_open(cli2->tree, tctx, &io);
+       CHECK_STATUS(tctx, status, NT_STATUS_OK);
+       fnum2 = io.ntcreatex.out.file.fnum;
+       torture_wait_for_oplock_break(tctx);
+       CHECK_VAL(break_info.count, 0);
+       CHECK_VAL(break_info.failures, 0);
+       CHECK_VAL(io.ntcreatex.out.oplock_level, LEVEL_II_OPLOCK_RETURN);
+
+       ZERO_STRUCT(break_info);
+
+       torture_comment(tctx, "write should trigger a break to none on both\n");
+       smbcli_write(cli2->tree, fnum2, 0, &c, 0, 1);
+
+       /* We expect two breaks */
+       torture_wait_for_oplock_break(tctx);
+       torture_wait_for_oplock_break(tctx);
+
+       CHECK_VAL(break_info.count, 2);
+       CHECK_VAL(break_info.level, 0);
+       CHECK_VAL(break_info.failures, 0);
+
+       smbcli_close(cli1->tree, fnum);
+       smbcli_close(cli2->tree, fnum2);
+
+done:
+       smb_raw_exit(cli1->session);
+       smb_raw_exit(cli2->session);
+       smbcli_deltree(cli1->tree, BASEDIR);
+       return ret;
+}
+
 static bool test_raw_oplock_batch10(struct torture_context *tctx, struct smbcli_state *cli1, struct smbcli_state *cli2)
 {
        const char *fname = BASEDIR "\\test_batch10.dat";
@@ -4311,6 +4431,7 @@ struct torture_suite *torture_raw_oplock(TALLOC_CTX *mem_ctx)
        torture_suite_add_2smb_test(suite, "batch7", test_raw_oplock_batch7);
        torture_suite_add_2smb_test(suite, "batch8", test_raw_oplock_batch8);
        torture_suite_add_2smb_test(suite, "batch9", test_raw_oplock_batch9);
+       torture_suite_add_2smb_test(suite, "batch9a", test_raw_oplock_batch9a);
        torture_suite_add_2smb_test(suite, "batch10", test_raw_oplock_batch10);
        torture_suite_add_2smb_test(suite, "batch11", test_raw_oplock_batch11);
        torture_suite_add_2smb_test(suite, "batch12", test_raw_oplock_batch12);
index d2a2832bffa821e0705b8c2659a1f82c4ea74323..be1c5eb0f5af5e88d3fa2544f4e40253d15c1724 100644 (file)
@@ -1611,6 +1611,133 @@ static bool test_smb2_oplock_batch9(struct torture_context *tctx,
        return ret;
 }
 
+static bool test_smb2_oplock_batch9a(struct torture_context *tctx,
+                                    struct smb2_tree *tree1,
+                                    struct smb2_tree *tree2)
+{
+       const char *fname = BASEDIR "\\test_batch9a.dat";
+       NTSTATUS status;
+       bool ret = true;
+       union smb_open io;
+       struct smb2_handle h, h1, h2, h3;
+       char c = 0;
+
+       status = torture_smb2_testdir(tree1, BASEDIR, &h);
+       torture_assert_ntstatus_ok(tctx, status, "Error creating directory");
+
+       /* cleanup */
+       smb2_util_unlink(tree1, fname);
+
+       tree1->session->transport->oplock.handler = torture_oplock_handler;
+       tree1->session->transport->oplock.private_data = tree1;
+
+       /*
+         base ntcreatex parms
+       */
+       ZERO_STRUCT(io.smb2);
+       io.generic.level = RAW_OPEN_SMB2;
+       io.smb2.in.desired_access = SEC_RIGHTS_FILE_ALL;
+       io.smb2.in.alloc_size = 0;
+       io.smb2.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
+       io.smb2.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
+       io.smb2.in.create_disposition = NTCREATEX_DISP_OPEN_IF;
+       io.smb2.in.create_options = 0;
+       io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
+       io.smb2.in.security_flags = 0;
+       io.smb2.in.fname = fname;
+
+       torture_comment(tctx, "BATCH9: open with attributes only can create "
+                       "file\n");
+
+       io.smb2.in.create_flags = NTCREATEX_FLAGS_EXTENDED;
+       io.smb2.in.oplock_level = SMB2_OPLOCK_LEVEL_BATCH;
+       io.smb2.in.desired_access = SEC_FILE_READ_ATTRIBUTE |
+                               SEC_FILE_WRITE_ATTRIBUTE |
+                               SEC_STD_SYNCHRONIZE;
+       status = smb2_create(tree1, tctx, &(io.smb2));
+       torture_assert_ntstatus_ok(tctx, status, "Error creating the file");
+       h1 = io.smb2.out.file.handle;
+       CHECK_VAL(io.smb2.out.create_action, FILE_WAS_CREATED);
+       CHECK_VAL(io.smb2.out.oplock_level, SMB2_OPLOCK_LEVEL_BATCH);
+
+       torture_comment(tctx, "Subsequent attributes open should not break\n");
+
+       ZERO_STRUCT(break_info);
+
+       status = smb2_create(tree2, tctx, &(io.smb2));
+       torture_assert_ntstatus_ok(tctx, status, "Incorrect status");
+       h3 = io.smb2.out.file.handle;
+       torture_wait_for_oplock_break(tctx);
+       CHECK_VAL(break_info.count, 0);
+       CHECK_VAL(io.smb2.out.create_action, FILE_WAS_OPENED);
+       CHECK_VAL(io.smb2.out.oplock_level, SMB2_OPLOCK_LEVEL_NONE);
+       smb2_util_close(tree2, h3);
+
+       torture_comment(tctx, "Subsequent normal open should break oplock on "
+                       "attribute only open to level II\n");
+
+       ZERO_STRUCT(break_info);
+
+       io.smb2.in.create_flags = NTCREATEX_FLAGS_EXTENDED;
+       io.smb2.in.oplock_level = SMB2_OPLOCK_LEVEL_BATCH;
+       io.smb2.in.desired_access = SEC_RIGHTS_FILE_ALL;
+       io.smb2.in.create_disposition = NTCREATEX_DISP_OPEN;
+       status = smb2_create(tree2, tctx, &(io.smb2));
+       torture_assert_ntstatus_ok(tctx, status, "Incorrect status");
+       h2 = io.smb2.out.file.handle;
+       torture_wait_for_oplock_break(tctx);
+       CHECK_VAL(break_info.count, 1);
+       CHECK_VAL(break_info.handle.data[0], h1.data[0]);
+       CHECK_VAL(break_info.failures, 0);
+       CHECK_VAL(break_info.level, SMB2_OPLOCK_LEVEL_II);
+       CHECK_VAL(io.smb2.out.oplock_level, SMB2_OPLOCK_LEVEL_II);
+       smb2_util_close(tree2, h2);
+
+       torture_comment(tctx, "third oplocked open should grant level2 without "
+                       "break\n");
+       ZERO_STRUCT(break_info);
+
+       tree2->session->transport->oplock.handler = torture_oplock_handler;
+       tree2->session->transport->oplock.private_data = tree2;
+
+       io.smb2.in.create_flags = NTCREATEX_FLAGS_EXTENDED;
+       io.smb2.in.oplock_level = SMB2_OPLOCK_LEVEL_BATCH;
+       io.smb2.in.desired_access = SEC_RIGHTS_FILE_ALL;
+       io.smb2.in.create_disposition = NTCREATEX_DISP_OPEN;
+       status = smb2_create(tree2, tctx, &(io.smb2));
+       torture_assert_ntstatus_ok(tctx, status, "Incorrect status");
+       h2 = io.smb2.out.file.handle;
+       torture_wait_for_oplock_break(tctx);
+       CHECK_VAL(break_info.count, 0);
+       CHECK_VAL(break_info.failures, 0);
+       CHECK_VAL(io.smb2.out.oplock_level, SMB2_OPLOCK_LEVEL_II);
+
+       ZERO_STRUCT(break_info);
+
+       torture_comment(tctx, "write should trigger a break to none on both\n");
+       tree1->session->transport->oplock.handler =
+           torture_oplock_handler_level2_to_none;
+       tree2->session->transport->oplock.handler =
+           torture_oplock_handler_level2_to_none;
+       smb2_util_write(tree2, h2, &c, 0, 1);
+
+       /* We expect two breaks */
+       torture_wait_for_oplock_break(tctx);
+       torture_wait_for_oplock_break(tctx);
+
+       CHECK_VAL(break_info.count, 2);
+       CHECK_VAL(break_info.level, 0);
+       CHECK_VAL(break_info.failures, 0);
+
+       smb2_util_close(tree1, h1);
+       smb2_util_close(tree2, h2);
+       smb2_util_close(tree1, h);
+
+       smb2_deltree(tree1, BASEDIR);
+       return ret;
+}
+
+
 static bool test_smb2_oplock_batch10(struct torture_context *tctx,
                                     struct smb2_tree *tree1,
                                     struct smb2_tree *tree2)
@@ -3836,6 +3963,7 @@ struct torture_suite *torture_smb2_oplocks_init(void)
        torture_suite_add_2smb2_test(suite, "batch7", test_smb2_oplock_batch7);
        torture_suite_add_2smb2_test(suite, "batch8", test_smb2_oplock_batch8);
        torture_suite_add_2smb2_test(suite, "batch9", test_smb2_oplock_batch9);
+       torture_suite_add_2smb2_test(suite, "batch9a", test_smb2_oplock_batch9a);
        torture_suite_add_2smb2_test(suite, "batch10", test_smb2_oplock_batch10);
        torture_suite_add_2smb2_test(suite, "batch11", test_smb2_oplock_batch11);
        torture_suite_add_2smb2_test(suite, "batch12", test_smb2_oplock_batch12);