Added test_nttransrename() to test Metze's new code.
authorJeremy Allison <jra@samba.org>
Tue, 11 Mar 2008 22:27:08 +0000 (15:27 -0700)
committerJeremy Allison <jra@samba.org>
Tue, 11 Mar 2008 22:27:08 +0000 (15:27 -0700)
Jeremy.
(This used to be commit 4556fafede8691c6a12670695ff108e9e59aff98)

source4/torture/raw/oplock.c
source4/torture/raw/rename.c

index ab23ee78c01916afbdaf585515e3f02620979f9e..89f3607ecd7b2b0d2d049c686d6832dbc2c5d8bc 100644 (file)
@@ -2206,6 +2206,95 @@ done:
        return ret;
 }
 
+/****************************************************
+ Called from raw-rename - we need oplock handling for
+ this test so this is why it's in oplock.c, not rename.c
+****************************************************/
+
+bool test_nttransrename(struct torture_context *tctx, struct smbcli_state *cli1)
+{
+       const char *fname1 = BASEDIR "\\test_nttransrename_1.dat";
+       const char *fname2 = BASEDIR "\\test_nttransrename_2.dat";
+       NTSTATUS status;
+       bool ret = true;
+       union smb_open io;
+       union smb_fileinfo qfi;
+       union smb_rename rn;
+       uint16_t fnum=0;
+
+       if (!torture_setup_dir(cli1, BASEDIR)) {
+               return false;
+       }
+
+       /* cleanup */
+       smbcli_unlink(cli1->tree, fname1);
+       smbcli_unlink(cli1->tree, fname2);
+
+       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 = 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 = fname1;
+
+       torture_comment(tctx, "nttrans_rename: open a file with an exclusive oplock (share mode: none)\n");
+       ZERO_STRUCT(break_info);
+       io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED |
+               NTCREATEX_FLAGS_REQUEST_OPLOCK;
+       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.oplock_level, EXCLUSIVE_OPLOCK_RETURN);
+
+       torture_comment(tctx, "nttrans_rename should not trigger a break nor a share mode violation\n");
+       ZERO_STRUCT(rn);
+       rn.generic.level = RAW_RENAME_NTTRANS;
+       rn.nttrans.in.file.fnum = fnum;
+       rn.nttrans.in.flags     = 0;
+       rn.nttrans.in.new_name  = fname2+strlen(BASEDIR)+1;
+
+        status = smb_raw_rename(cli1->tree, &rn);
+
+       CHECK_STATUS(tctx, status, NT_STATUS_OK);
+       CHECK_VAL(break_info.count, 0);
+
+       /* Seems name is only updated on close. */
+       smbcli_close(cli1->tree, fnum);
+
+       /* Check if we can open with the new name. */
+       io.ntcreatex.in.fname = fname2;
+       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.oplock_level, EXCLUSIVE_OPLOCK_RETURN);
+
+       ZERO_STRUCT(qfi);
+       qfi.generic.level = RAW_FILEINFO_ALL_INFORMATION;
+       qfi.generic.in.file.fnum = fnum;
+
+       status = smb_raw_fileinfo(cli1->tree, tctx, &qfi);
+       CHECK_STATUS(tctx, status, NT_STATUS_OK);
+       CHECK_STRMATCH(qfi.all_info.out.fname.s, fname2);
+
+       smbcli_close(cli1->tree, fnum);
+
+done:
+       smb_raw_exit(cli1->session);
+       smbcli_deltree(cli1->tree, BASEDIR);
+       return ret;
+}
+
+
 static bool test_raw_oplock_batch20(struct torture_context *tctx, struct smbcli_state *cli1, struct smbcli_state *cli2)
 {
        const char *fname1 = BASEDIR "\\test_batch20_1.dat";
index 308bd7f8dc8783f67360cdda59adee949b80558c..9765c04101179ebbe5cb7223f184a13e7e671ca9 100644 (file)
@@ -435,6 +435,7 @@ done:
 }
 
 extern bool test_trans2rename(struct torture_context *tctx, struct smbcli_state *cli1, struct smbcli_state *cli2);
+extern bool test_nttransrename(struct torture_context *tctx, struct smbcli_state *cli1);
 
 /* 
    basic testing of rename calls
@@ -444,9 +445,10 @@ struct torture_suite *torture_raw_rename(TALLOC_CTX *mem_ctx)
        struct torture_suite *suite = torture_suite_create(mem_ctx, "RENAME");
 
        torture_suite_add_1smb_test(suite, "mv", test_mv);
-       /* test_trans2rename is actually in torture/raw/oplock.c to
+       /* test_trans2rename and test_nttransrename are actually in torture/raw/oplock.c to
           use the handlers and macros there. */
        torture_suite_add_2smb_test(suite, "trans2rename", test_trans2rename);
+       torture_suite_add_1smb_test(suite, "nttransrename", test_nttransrename);
        torture_suite_add_1smb_test(suite, "ntrename", test_ntrename);
 
        return suite;