diff --git a/source4/torture/smb2/oplock.c b/source4/torture/smb2/oplock.c index 2d74c5d..fd56daa 100644 --- a/source4/torture/smb2/oplock.c +++ b/source4/torture/smb2/oplock.c @@ -795,6 +795,98 @@ static bool test_smb2_oplock_exclusive6(struct torture_context *tctx, return ret; } +static bool test_smb2_oplock_exclusive7(struct torture_context *tctx, + struct smb2_tree *tree1, + struct smb2_tree *tree2) +{ + const char *fname1 = BASEDIR "\\test_exclusive7_1.dat"; + const char *fname2 = BASEDIR "\\test_exclusive7_2.dat"; + NTSTATUS status; + bool ret = true; + union smb_open io; + union smb_setfileinfo sinfo; + union smb_fileinfo ginfo; + struct smb2_handle h, h1; + + status = torture_smb2_testdir(tree1, BASEDIR, &h); + torture_assert_ntstatus_ok(tctx, status, "Error creating directory"); + + /* cleanup */ + smb2_util_unlink(tree1, fname1); + smb2_util_unlink(tree2, fname2); + + 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.desired_access = 0x130089; + 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.share_access = NTCREATEX_SHARE_ACCESS_READ | + NTCREATEX_SHARE_ACCESS_WRITE | + NTCREATEX_SHARE_ACCESS_DELETE; + io.smb2.in.create_disposition = NTCREATEX_DISP_OPEN_IF; + io.smb2.in.create_options = 0x200060; + io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS; + io.smb2.in.security_flags = 0; + io.smb2.in.fname = fname1; + io.smb2.in.durable_open = true; + + torture_comment(tctx, "EXCLUSIVE7: open a file with an exclusive " + "oplock (share mode: none)\n"); + ZERO_STRUCT(break_info); + io.smb2.in.create_flags = NTCREATEX_FLAGS_EXTENDED; + io.smb2.in.oplock_level = SMB2_OPLOCK_LEVEL_BATCH; + + status = smb2_create(tree1, tctx, &(io.smb2)); + torture_assert_ntstatus_ok(tctx, status, "Error opening the file"); + h1 = io.smb2.out.file.handle; + CHECK_VAL(io.smb2.out.oplock_level, SMB2_OPLOCK_LEVEL_BATCH); + + ZERO_STRUCT(ginfo); + ginfo.generic.in.file.handle = h1; + ginfo.generic.level = RAW_FILEINFO_SEC_DESC; + ginfo.query_secdesc.in.secinfo_flags = 5; + status = smb2_getinfo_file(tree1, tctx, &ginfo); + torture_assert_ntstatus_ok(tctx, status, "Error getting SD on the file"); + + ZERO_STRUCT(ginfo); + ginfo.generic.level = RAW_FILEINFO_STREAM_INFORMATION; + ginfo.generic.in.file.handle = h1; + status = smb2_getinfo_file(tree1, tctx, &ginfo); + torture_assert_ntstatus_ok(tctx, status, "Error getting STREAM_INFO on the file"); + + torture_comment(tctx, "rename should not generate a break but get " + "a sharing violation\n"); + ZERO_STRUCT(sinfo); + sinfo.rename_information.level = RAW_SFILEINFO_RENAME_INFORMATION_SMB2; + sinfo.rename_information.in.file.handle = h1; + sinfo.rename_information.in.overwrite = true; + sinfo.rename_information.in.root_fid = 0; + sinfo.rename_information.in.new_name = fname2; + status = smb2_setinfo_file(tree1, &sinfo); + + torture_comment(tctx, "trying rename while first file open\n"); + torture_assert_ntstatus_equal(tctx, status, NT_STATUS_SHARING_VIOLATION, + "Incorrect status"); + torture_wait_for_oplock_break(tctx); + CHECK_VAL(break_info.count, 0); + CHECK_VAL(break_info.failures, 0); + + smb2_util_close(tree1, h1); + smb2_util_close(tree1, h); + + smb2_deltree(tree1, BASEDIR); + return ret; +} + + static bool test_smb2_oplock_batch1(struct torture_context *tctx, struct smb2_tree *tree1, struct smb2_tree *tree2) @@ -3369,6 +3461,7 @@ struct torture_suite *torture_smb2_oplocks_init(void) torture_suite_add_2smb2_test(suite, "exclusive4", test_smb2_oplock_exclusive4); torture_suite_add_2smb2_test(suite, "exclusive5", test_smb2_oplock_exclusive5); torture_suite_add_2smb2_test(suite, "exclusive6", test_smb2_oplock_exclusive6); + torture_suite_add_2smb2_test(suite, "exclusive7", test_smb2_oplock_exclusive7); torture_suite_add_2smb2_test(suite, "batch1", test_smb2_oplock_batch1); torture_suite_add_2smb2_test(suite, "batch2", test_smb2_oplock_batch2); torture_suite_add_2smb2_test(suite, "batch3", test_smb2_oplock_batch3);