LCOV - code coverage report
Current view: top level - source4/torture/smb2 - rename.c (source / functions) Hit Total Coverage
Test: coverage report for master 6248eab5 Lines: 718 802 89.5 %
Date: 2021-08-25 13:27:56 Functions: 23 23 100.0 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             : 
       4             :    SMB2 rename test suite
       5             : 
       6             :    Copyright (C) Christian Ambach 2012
       7             : 
       8             :    This program is free software; you can redistribute it and/or modify
       9             :    it under the terms of the GNU General Public License as published by
      10             :    the Free Software Foundation; either version 3 of the License, or
      11             :    (at your option) any later version.
      12             : 
      13             :    This program is distributed in the hope that it will be useful,
      14             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      15             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      16             :    GNU General Public License for more details.
      17             : 
      18             :    You should have received a copy of the GNU General Public License
      19             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      20             : */
      21             : 
      22             : #include "includes.h"
      23             : #include "libcli/smb2/smb2.h"
      24             : #include "libcli/smb2/smb2_calls.h"
      25             : #include <tevent.h>
      26             : #include "lib/util/tevent_ntstatus.h"
      27             : 
      28             : #include "torture/torture.h"
      29             : #include "torture/smb2/proto.h"
      30             : 
      31             : #include "librpc/gen_ndr/security.h"
      32             : 
      33             : #define CHECK_STATUS(status, correct) do { \
      34             :         if (!NT_STATUS_EQUAL(status, correct)) { \
      35             :                 torture_result(torture, TORTURE_FAIL, \
      36             :                        "(%s) Incorrect status %s - should be %s\n", \
      37             :                        __location__, nt_errstr(status), nt_errstr(correct)); \
      38             :                 ret = false; \
      39             :                 goto done; \
      40             :         }} while (0)
      41             : 
      42             : #define BASEDIR "test_rename"
      43             : 
      44             : /*
      45             :  * basic testing of rename: open file with DELETE access
      46             :  * this should pass
      47             :  */
      48             : 
      49           4 : static bool torture_smb2_rename_simple(struct torture_context *torture,
      50             :                 struct smb2_tree *tree1)
      51             : {
      52           4 :         bool ret = true;
      53             :         NTSTATUS status;
      54             :         union smb_open io;
      55             :         union smb_close cl;
      56             :         union smb_setfileinfo sinfo;
      57             :         union smb_fileinfo fi;
      58             :         struct smb2_handle h1;
      59             : 
      60           4 :         ZERO_STRUCT(h1);
      61             : 
      62           4 :         smb2_deltree(tree1, BASEDIR);
      63           4 :         smb2_util_rmdir(tree1, BASEDIR);
      64             : 
      65           4 :         torture_comment(torture, "Creating base directory\n");
      66             : 
      67           4 :         smb2_util_mkdir(tree1, BASEDIR);
      68             : 
      69             : 
      70           4 :         torture_comment(torture, "Creating test file\n");
      71             : 
      72           4 :         ZERO_STRUCT(io.smb2);
      73           4 :         io.generic.level = RAW_OPEN_SMB2;
      74           4 :         io.smb2.in.create_flags = 0;
      75           4 :         io.smb2.in.desired_access = SEC_FILE_ALL|SEC_STD_DELETE;
      76           4 :         io.smb2.in.create_options = NTCREATEX_OPTIONS_NON_DIRECTORY_FILE;
      77           4 :         io.smb2.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
      78           4 :         io.smb2.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
      79             :                 NTCREATEX_SHARE_ACCESS_WRITE | NTCREATEX_SHARE_ACCESS_DELETE;
      80           4 :         io.smb2.in.alloc_size = 0;
      81           4 :         io.smb2.in.create_disposition = NTCREATEX_DISP_CREATE;
      82           4 :         io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
      83           4 :         io.smb2.in.security_flags = 0;
      84           4 :         io.smb2.in.fname = BASEDIR "\\file.txt";
      85             : 
      86           4 :         status = smb2_create(tree1, torture, &(io.smb2));
      87           4 :         CHECK_STATUS(status, NT_STATUS_OK);
      88           4 :         h1 = io.smb2.out.file.handle;
      89             : 
      90           4 :         torture_comment(torture, "Renaming test file\n");
      91             : 
      92           4 :         ZERO_STRUCT(sinfo);
      93           4 :         sinfo.rename_information.level = RAW_SFILEINFO_RENAME_INFORMATION;
      94           4 :         sinfo.rename_information.in.file.handle = io.smb2.out.file.handle;
      95           4 :         sinfo.rename_information.in.overwrite = 0;
      96           4 :         sinfo.rename_information.in.root_fid = 0;
      97           4 :         sinfo.rename_information.in.new_name =
      98             :                 BASEDIR "\\newname.txt";
      99           4 :         status = smb2_setinfo_file(tree1, &sinfo);
     100           4 :         CHECK_STATUS(status, NT_STATUS_OK);
     101             : 
     102           4 :         torture_comment(torture, "Checking for new filename\n");
     103             : 
     104           4 :         ZERO_STRUCT(fi);
     105           4 :         fi.generic.level = RAW_FILEINFO_SMB2_ALL_INFORMATION;
     106           4 :         fi.generic.in.file.handle = h1;
     107           4 :         status = smb2_getinfo_file(tree1, torture, &fi);
     108           4 :         CHECK_STATUS(status, NT_STATUS_OK);
     109             : 
     110             : 
     111           4 :         torture_comment(torture, "Closing test file\n");
     112             : 
     113           4 :         ZERO_STRUCT(cl.smb2);
     114           4 :         cl.smb2.level = RAW_CLOSE_SMB2;
     115           4 :         cl.smb2.in.file.handle = h1;
     116           4 :         status = smb2_close(tree1, &(cl.smb2));
     117           4 :         CHECK_STATUS(status, NT_STATUS_OK);
     118             : 
     119           4 :         ZERO_STRUCT(h1);
     120             : 
     121           4 : done:
     122             : 
     123           4 :         torture_comment(torture, "Cleaning up\n");
     124             : 
     125           4 :         if (h1.data[0] || h1.data[1]) {
     126           0 :                 ZERO_STRUCT(cl.smb2);
     127           0 :                 cl.smb2.level = RAW_CLOSE_SMB2;
     128           0 :                 cl.smb2.in.file.handle = h1;
     129           0 :                 status = smb2_close(tree1, &(cl.smb2));
     130             :         }
     131           4 :         smb2_deltree(tree1, BASEDIR);
     132           4 :         return ret;
     133             : }
     134             : 
     135             : /*
     136             :  * basic testing of rename, this time do not request DELETE access
     137             :  * for the file, this should fail
     138             :  */
     139             : 
     140           4 : static bool torture_smb2_rename_simple2(struct torture_context *torture,
     141             :                 struct smb2_tree *tree1)
     142             : {
     143           4 :         bool ret = true;
     144             :         NTSTATUS status;
     145             :         union smb_open io;
     146             :         union smb_close cl;
     147             :         union smb_setfileinfo sinfo;
     148             :         struct smb2_handle h1;
     149             : 
     150           4 :         ZERO_STRUCT(h1);
     151             : 
     152           4 :         smb2_deltree(tree1, BASEDIR);
     153           4 :         smb2_util_rmdir(tree1, BASEDIR);
     154             : 
     155           4 :         torture_comment(torture, "Creating base directory\n");
     156             : 
     157           4 :         smb2_util_mkdir(tree1, BASEDIR);
     158             : 
     159             : 
     160           4 :         torture_comment(torture, "Creating test file\n");
     161             : 
     162           4 :         ZERO_STRUCT(io.smb2);
     163           4 :         io.generic.level = RAW_OPEN_SMB2;
     164           4 :         io.smb2.in.create_flags = 0;
     165           4 :         io.smb2.in.desired_access = SEC_FILE_ALL;
     166           4 :         io.smb2.in.create_options = NTCREATEX_OPTIONS_NON_DIRECTORY_FILE;
     167           4 :         io.smb2.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
     168           4 :         io.smb2.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
     169             :                 NTCREATEX_SHARE_ACCESS_WRITE | NTCREATEX_SHARE_ACCESS_DELETE;
     170           4 :         io.smb2.in.alloc_size = 0;
     171           4 :         io.smb2.in.create_disposition = NTCREATEX_DISP_CREATE;
     172           4 :         io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
     173           4 :         io.smb2.in.security_flags = 0;
     174           4 :         io.smb2.in.fname = BASEDIR "\\file.txt";
     175             : 
     176           4 :         status = smb2_create(tree1, torture, &(io.smb2));
     177           4 :         CHECK_STATUS(status, NT_STATUS_OK);
     178           4 :         h1 = io.smb2.out.file.handle;
     179             : 
     180           4 :         torture_comment(torture, "Renaming test file\n");
     181             : 
     182           4 :         ZERO_STRUCT(sinfo);
     183           4 :         sinfo.rename_information.level = RAW_SFILEINFO_RENAME_INFORMATION;
     184           4 :         sinfo.rename_information.in.file.handle = io.smb2.out.file.handle;
     185           4 :         sinfo.rename_information.in.overwrite = 0;
     186           4 :         sinfo.rename_information.in.root_fid = 0;
     187           4 :         sinfo.rename_information.in.new_name =
     188             :                 BASEDIR "\\newname.txt";
     189           4 :         status = smb2_setinfo_file(tree1, &sinfo);
     190           4 :         CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
     191             : 
     192           0 :         torture_comment(torture, "Closing test file\n");
     193             : 
     194           0 :         ZERO_STRUCT(cl.smb2);
     195           0 :         cl.smb2.level = RAW_CLOSE_SMB2;
     196           0 :         cl.smb2.in.file.handle = h1;
     197           0 :         status = smb2_close(tree1, &(cl.smb2));
     198           0 :         CHECK_STATUS(status, NT_STATUS_OK);
     199             : 
     200           0 :         ZERO_STRUCT(h1);
     201             : 
     202           4 : done:
     203             : 
     204           4 :         torture_comment(torture, "Cleaning up\n");
     205             : 
     206           4 :         if (h1.data[0] || h1.data[1]) {
     207           4 :                 ZERO_STRUCT(cl.smb2);
     208           4 :                 cl.smb2.level = RAW_CLOSE_SMB2;
     209           4 :                 cl.smb2.in.file.handle = h1;
     210           4 :                 status = smb2_close(tree1, &(cl.smb2));
     211             :         }
     212           4 :         smb2_deltree(tree1, BASEDIR);
     213           4 :         return ret;
     214             : }
     215             : 
     216             : 
     217             : /*
     218             :  * testing of rename with no sharing allowed on file
     219             :  * this should work
     220             :  */
     221             : 
     222           4 : static bool torture_smb2_rename_no_sharemode(struct torture_context *torture,
     223             :                 struct smb2_tree *tree1)
     224             : {
     225           4 :         bool ret = true;
     226             :         NTSTATUS status;
     227             :         union smb_open io;
     228             :         union smb_close cl;
     229             :         union smb_setfileinfo sinfo;
     230             :         union smb_fileinfo fi;
     231             :         struct smb2_handle h1;
     232             : 
     233           4 :         ZERO_STRUCT(h1);
     234             : 
     235           4 :         smb2_deltree(tree1, BASEDIR);
     236           4 :         smb2_util_rmdir(tree1, BASEDIR);
     237             : 
     238           4 :         torture_comment(torture, "Creating base directory\n");
     239             : 
     240           4 :         smb2_util_mkdir(tree1, BASEDIR);
     241             : 
     242             : 
     243           4 :         torture_comment(torture, "Creating test file\n");
     244             : 
     245           4 :         ZERO_STRUCT(io.smb2);
     246           4 :         io.generic.level = RAW_OPEN_SMB2;
     247           4 :         io.smb2.in.create_flags = 0;
     248           4 :         io.smb2.in.desired_access = 0x0017019f;
     249           4 :         io.smb2.in.create_options = NTCREATEX_OPTIONS_NON_DIRECTORY_FILE;
     250           4 :         io.smb2.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
     251           4 :         io.smb2.in.share_access = 0;
     252           4 :         io.smb2.in.alloc_size = 0;
     253           4 :         io.smb2.in.create_disposition = NTCREATEX_DISP_CREATE;
     254           4 :         io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
     255           4 :         io.smb2.in.security_flags = 0;
     256           4 :         io.smb2.in.fname = BASEDIR "\\file.txt";
     257             : 
     258           4 :         status = smb2_create(tree1, torture, &(io.smb2));
     259           4 :         CHECK_STATUS(status, NT_STATUS_OK);
     260           4 :         h1 = io.smb2.out.file.handle;
     261             : 
     262           4 :         torture_comment(torture, "Renaming test file\n");
     263             : 
     264           4 :         ZERO_STRUCT(sinfo);
     265           4 :         sinfo.rename_information.level = RAW_SFILEINFO_RENAME_INFORMATION;
     266           4 :         sinfo.rename_information.in.file.handle = io.smb2.out.file.handle;
     267           4 :         sinfo.rename_information.in.overwrite = 0;
     268           4 :         sinfo.rename_information.in.root_fid = 0;
     269           4 :         sinfo.rename_information.in.new_name =
     270             :                 BASEDIR "\\newname.txt";
     271           4 :         status = smb2_setinfo_file(tree1, &sinfo);
     272           4 :         CHECK_STATUS(status, NT_STATUS_OK);
     273             : 
     274           4 :         torture_comment(torture, "Checking for new filename\n");
     275             : 
     276           4 :         ZERO_STRUCT(fi);
     277           4 :         fi.generic.level = RAW_FILEINFO_SMB2_ALL_INFORMATION;
     278           4 :         fi.generic.in.file.handle = h1;
     279           4 :         status = smb2_getinfo_file(tree1, torture, &fi);
     280           4 :         CHECK_STATUS(status, NT_STATUS_OK);
     281             : 
     282             : 
     283           4 :         torture_comment(torture, "Closing test file\n");
     284             : 
     285           4 :         ZERO_STRUCT(cl.smb2);
     286           4 :         cl.smb2.level = RAW_CLOSE_SMB2;
     287           4 :         cl.smb2.in.file.handle = h1;
     288           4 :         status = smb2_close(tree1, &(cl.smb2));
     289           4 :         CHECK_STATUS(status, NT_STATUS_OK);
     290             : 
     291           4 :         ZERO_STRUCT(h1);
     292             : 
     293           4 : done:
     294             : 
     295           4 :         torture_comment(torture, "Cleaning up\n");
     296             : 
     297           4 :         if (h1.data[0] || h1.data[1]) {
     298           0 :                 ZERO_STRUCT(cl.smb2);
     299           0 :                 cl.smb2.level = RAW_CLOSE_SMB2;
     300           0 :                 cl.smb2.in.file.handle = h1;
     301           0 :                 status = smb2_close(tree1, &(cl.smb2));
     302             :         }
     303           4 :         smb2_deltree(tree1, BASEDIR);
     304           4 :         return ret;
     305             : }
     306             : 
     307             : /*
     308             :  * testing of rename when opening parent dir with delete access and delete
     309             :  * sharing allowed
     310             :  * should result in sharing violation
     311             :  */
     312             : 
     313           4 : static bool torture_smb2_rename_with_delete_access(struct torture_context *torture,
     314             :                 struct smb2_tree *tree1)
     315             : {
     316           4 :         bool ret = true;
     317             :         NTSTATUS status;
     318             :         union smb_open io;
     319             :         union smb_close cl;
     320             :         union smb_setfileinfo sinfo;
     321             :         struct smb2_handle fh, dh;
     322             : 
     323           4 :         ZERO_STRUCT(fh);
     324           4 :         ZERO_STRUCT(dh);
     325             : 
     326           4 :         smb2_deltree(tree1, BASEDIR);
     327           4 :         smb2_util_rmdir(tree1, BASEDIR);
     328             : 
     329           4 :         torture_comment(torture, "Creating base directory\n");
     330             : 
     331           4 :         smb2_util_mkdir(tree1, BASEDIR);
     332             : 
     333           4 :         torture_comment(torture, "Opening parent directory\n");
     334             : 
     335           4 :         ZERO_STRUCT(io.smb2);
     336           4 :         io.generic.level = RAW_OPEN_SMB2;
     337           4 :         io.smb2.in.create_flags = 0;
     338           4 :         io.smb2.in.desired_access = SEC_STD_SYNCHRONIZE | SEC_STD_WRITE_DAC |
     339             :                 SEC_STD_READ_CONTROL | SEC_STD_DELETE | SEC_FILE_WRITE_ATTRIBUTE |
     340             :                 SEC_FILE_READ_ATTRIBUTE | SEC_FILE_EXECUTE | SEC_FILE_WRITE_EA |
     341             :                 SEC_FILE_READ_EA | SEC_FILE_APPEND_DATA | SEC_FILE_READ_DATA |
     342             :                 SEC_FILE_WRITE_DATA;
     343           4 :         io.smb2.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
     344           4 :         io.smb2.in.file_attributes = FILE_ATTRIBUTE_DIRECTORY;
     345           4 :         io.smb2.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
     346             :                 NTCREATEX_SHARE_ACCESS_WRITE | NTCREATEX_SHARE_ACCESS_DELETE;
     347           4 :         io.smb2.in.alloc_size = 0;
     348           4 :         io.smb2.in.create_disposition = NTCREATEX_DISP_OPEN;
     349           4 :         io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
     350           4 :         io.smb2.in.security_flags = 0;
     351           4 :         io.smb2.in.fname = BASEDIR;
     352             : 
     353           4 :         status = smb2_create(tree1, torture, &(io.smb2));
     354           4 :         CHECK_STATUS(status, NT_STATUS_OK);
     355           4 :         dh = io.smb2.out.file.handle;
     356             : 
     357             : 
     358           4 :         torture_comment(torture, "Creating test file\n");
     359             : 
     360           4 :         ZERO_STRUCT(io.smb2);
     361           4 :         io.generic.level = RAW_OPEN_SMB2;
     362           4 :         io.smb2.in.create_flags = 0;
     363           4 :         io.smb2.in.desired_access = SEC_STD_SYNCHRONIZE | SEC_STD_WRITE_DAC |
     364             :                 SEC_STD_READ_CONTROL | SEC_STD_DELETE | SEC_FILE_WRITE_ATTRIBUTE |
     365             :                 SEC_FILE_READ_ATTRIBUTE | SEC_FILE_WRITE_EA | SEC_FILE_READ_EA |
     366             :                 SEC_FILE_APPEND_DATA | SEC_FILE_READ_DATA | SEC_FILE_WRITE_DATA;
     367           4 :         io.smb2.in.create_options = NTCREATEX_OPTIONS_NON_DIRECTORY_FILE;
     368           4 :         io.smb2.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
     369           4 :         io.smb2.in.share_access = 0;
     370           4 :         io.smb2.in.alloc_size = 0;
     371           4 :         io.smb2.in.create_disposition = NTCREATEX_DISP_CREATE;
     372           4 :         io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
     373           4 :         io.smb2.in.security_flags = 0;
     374           4 :         io.smb2.in.fname = BASEDIR "\\file.txt";
     375             : 
     376           4 :         status = smb2_create(tree1, torture, &(io.smb2));
     377           4 :         CHECK_STATUS(status, NT_STATUS_OK);
     378           4 :         fh = io.smb2.out.file.handle;
     379             : 
     380           4 :         torture_comment(torture, "Renaming test file\n");
     381             : 
     382           4 :         ZERO_STRUCT(sinfo);
     383           4 :         sinfo.rename_information.level = RAW_SFILEINFO_RENAME_INFORMATION;
     384           4 :         sinfo.rename_information.in.file.handle = fh;
     385           4 :         sinfo.rename_information.in.overwrite = 0;
     386           4 :         sinfo.rename_information.in.root_fid = 0;
     387           4 :         sinfo.rename_information.in.new_name =
     388             :                 BASEDIR "\\newname.txt";
     389           4 :         status = smb2_setinfo_file(tree1, &sinfo);
     390           4 :         CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION);
     391             : 
     392           4 :         torture_comment(torture, "Closing test file\n");
     393             : 
     394           4 :         ZERO_STRUCT(cl.smb2);
     395           4 :         cl.smb2.level = RAW_CLOSE_SMB2;
     396           4 :         cl.smb2.in.file.handle = fh;
     397           4 :         status = smb2_close(tree1, &(cl.smb2));
     398           4 :         CHECK_STATUS(status, NT_STATUS_OK);
     399             : 
     400           4 :         ZERO_STRUCT(fh);
     401             : 
     402           4 :         torture_comment(torture, "Closing directory\n");
     403             : 
     404           4 :         ZERO_STRUCT(cl.smb2);
     405           4 :         cl.smb2.level = RAW_CLOSE_SMB2;
     406           4 :         cl.smb2.in.file.handle = dh;
     407           4 :         status = smb2_close(tree1, &(cl.smb2));
     408           4 :         CHECK_STATUS(status, NT_STATUS_OK);
     409             : 
     410           4 :         ZERO_STRUCT(dh);
     411             : 
     412             : 
     413           4 : done:
     414             : 
     415           4 :         torture_comment(torture, "Cleaning up\n");
     416             : 
     417           4 :         if (fh.data[0] || fh.data[1]) {
     418           0 :                 ZERO_STRUCT(cl.smb2);
     419           0 :                 cl.smb2.level = RAW_CLOSE_SMB2;
     420           0 :                 cl.smb2.in.file.handle = fh;
     421           0 :                 status = smb2_close(tree1, &(cl.smb2));
     422             :         }
     423           4 :         if (dh.data[0] || dh.data[1]) {
     424           0 :                 ZERO_STRUCT(cl.smb2);
     425           0 :                 cl.smb2.level = RAW_CLOSE_SMB2;
     426           0 :                 cl.smb2.in.file.handle = dh;
     427           0 :                 status = smb2_close(tree1, &(cl.smb2));
     428             :         }
     429             : 
     430           4 :         smb2_deltree(tree1, BASEDIR);
     431           4 :         return ret;
     432             : }
     433             : 
     434             : 
     435             : /*
     436             :  * testing of rename with delete access on parent dir
     437             :  * this is a variation of the test above: parent dir is opened
     438             :  * without share_delete, so rename must fail
     439             :  */
     440             : 
     441           4 : static bool torture_smb2_rename_with_delete_access2(struct torture_context *torture,
     442             :                 struct smb2_tree *tree1)
     443             : {
     444           4 :         bool ret = true;
     445             :         NTSTATUS status;
     446             :         union smb_open io;
     447             :         union smb_close cl;
     448             :         union smb_setfileinfo sinfo;
     449             :         struct smb2_handle fh, dh;
     450             : 
     451           4 :         ZERO_STRUCT(fh);
     452           4 :         ZERO_STRUCT(dh);
     453             : 
     454           4 :         smb2_deltree(tree1, BASEDIR);
     455           4 :         smb2_util_rmdir(tree1, BASEDIR);
     456             : 
     457           4 :         torture_comment(torture, "Creating base directory\n");
     458             : 
     459           4 :         smb2_util_mkdir(tree1, BASEDIR);
     460             : 
     461           4 :         torture_comment(torture, "Opening parent directory\n");
     462             : 
     463           4 :         ZERO_STRUCT(io.smb2);
     464           4 :         io.generic.level = RAW_OPEN_SMB2;
     465           4 :         io.smb2.in.create_flags = 0;
     466           4 :         io.smb2.in.desired_access = SEC_STD_SYNCHRONIZE | SEC_STD_WRITE_DAC |
     467             :                 SEC_STD_READ_CONTROL | SEC_STD_DELETE | SEC_FILE_WRITE_ATTRIBUTE |
     468             :                 SEC_FILE_READ_ATTRIBUTE | SEC_FILE_EXECUTE | SEC_FILE_WRITE_EA |
     469             :                 SEC_FILE_READ_EA | SEC_FILE_APPEND_DATA | SEC_FILE_READ_DATA |
     470             :                 SEC_FILE_WRITE_DATA;
     471           4 :         io.smb2.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
     472           4 :         io.smb2.in.file_attributes = FILE_ATTRIBUTE_DIRECTORY;
     473           4 :         io.smb2.in.share_access = 0;
     474           4 :         io.smb2.in.alloc_size = 0;
     475           4 :         io.smb2.in.create_disposition = NTCREATEX_DISP_OPEN;
     476           4 :         io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
     477           4 :         io.smb2.in.security_flags = 0;
     478           4 :         io.smb2.in.fname = BASEDIR;
     479             : 
     480           4 :         status = smb2_create(tree1, torture, &(io.smb2));
     481           4 :         CHECK_STATUS(status, NT_STATUS_OK);
     482           4 :         dh = io.smb2.out.file.handle;
     483             : 
     484             : 
     485           4 :         torture_comment(torture, "Creating test file\n");
     486             : 
     487           4 :         ZERO_STRUCT(io.smb2);
     488           4 :         io.generic.level = RAW_OPEN_SMB2;
     489           4 :         io.smb2.in.create_flags = 0;
     490           4 :         io.smb2.in.desired_access = SEC_STD_SYNCHRONIZE | SEC_STD_WRITE_DAC |
     491             :                 SEC_STD_READ_CONTROL | SEC_STD_DELETE | SEC_FILE_WRITE_ATTRIBUTE |
     492             :                 SEC_FILE_READ_ATTRIBUTE | SEC_FILE_WRITE_EA | SEC_FILE_READ_EA |
     493             :                 SEC_FILE_APPEND_DATA | SEC_FILE_READ_DATA | SEC_FILE_WRITE_DATA;
     494           4 :         io.smb2.in.create_options = NTCREATEX_OPTIONS_NON_DIRECTORY_FILE;
     495           4 :         io.smb2.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
     496           4 :         io.smb2.in.share_access = 0;
     497           4 :         io.smb2.in.alloc_size = 0;
     498           4 :         io.smb2.in.create_disposition = NTCREATEX_DISP_CREATE;
     499           4 :         io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
     500           4 :         io.smb2.in.security_flags = 0;
     501           4 :         io.smb2.in.fname = BASEDIR "\\file.txt";
     502             : 
     503           4 :         status = smb2_create(tree1, torture, &(io.smb2));
     504           4 :         CHECK_STATUS(status, NT_STATUS_OK);
     505           4 :         fh = io.smb2.out.file.handle;
     506             : 
     507           4 :         torture_comment(torture, "Renaming test file\n");
     508             : 
     509           4 :         ZERO_STRUCT(sinfo);
     510           4 :         sinfo.rename_information.level = RAW_SFILEINFO_RENAME_INFORMATION;
     511           4 :         sinfo.rename_information.in.file.handle = fh;
     512           4 :         sinfo.rename_information.in.overwrite = 0;
     513           4 :         sinfo.rename_information.in.root_fid = 0;
     514           4 :         sinfo.rename_information.in.new_name =
     515             :                 BASEDIR "\\newname.txt";
     516           4 :         status = smb2_setinfo_file(tree1, &sinfo);
     517           4 :         CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION);
     518             : 
     519           4 :         torture_comment(torture, "Closing test file\n");
     520             : 
     521           4 :         ZERO_STRUCT(cl.smb2);
     522           4 :         cl.smb2.level = RAW_CLOSE_SMB2;
     523           4 :         cl.smb2.in.file.handle = fh;
     524           4 :         status = smb2_close(tree1, &(cl.smb2));
     525           4 :         CHECK_STATUS(status, NT_STATUS_OK);
     526             : 
     527           4 :         ZERO_STRUCT(fh);
     528             : 
     529           4 :         torture_comment(torture, "Closing directory\n");
     530             : 
     531           4 :         ZERO_STRUCT(cl.smb2);
     532           4 :         cl.smb2.level = RAW_CLOSE_SMB2;
     533           4 :         cl.smb2.in.file.handle = dh;
     534           4 :         status = smb2_close(tree1, &(cl.smb2));
     535           4 :         CHECK_STATUS(status, NT_STATUS_OK);
     536             : 
     537           4 :         ZERO_STRUCT(dh);
     538             : 
     539             : 
     540           4 : done:
     541             : 
     542           4 :         torture_comment(torture, "Cleaning up\n");
     543             : 
     544           4 :         if (fh.data[0] || fh.data[1]) {
     545           0 :                 ZERO_STRUCT(cl.smb2);
     546           0 :                 cl.smb2.level = RAW_CLOSE_SMB2;
     547           0 :                 cl.smb2.in.file.handle = fh;
     548           0 :                 status = smb2_close(tree1, &(cl.smb2));
     549             :         }
     550           4 :         if (dh.data[0] || dh.data[1]) {
     551           0 :                 ZERO_STRUCT(cl.smb2);
     552           0 :                 cl.smb2.level = RAW_CLOSE_SMB2;
     553           0 :                 cl.smb2.in.file.handle = dh;
     554           0 :                 status = smb2_close(tree1, &(cl.smb2));
     555             :         }
     556             : 
     557           4 :         smb2_deltree(tree1, BASEDIR);
     558           4 :         return ret;
     559             : }
     560             : 
     561             : /*
     562             :  * testing of rename when opening parent dir with no delete access and delete
     563             :  * sharing allowed
     564             :  * this should pass
     565             :  */
     566             : 
     567           4 : static bool torture_smb2_rename_no_delete_access(struct torture_context *torture,
     568             :                 struct smb2_tree *tree1)
     569             : {
     570           4 :         bool ret = true;
     571             :         NTSTATUS status;
     572             :         union smb_open io;
     573             :         union smb_close cl;
     574             :         union smb_setfileinfo sinfo;
     575             :         union smb_fileinfo fi;
     576             :         struct smb2_handle fh, dh;
     577             : 
     578           4 :         ZERO_STRUCT(fh);
     579           4 :         ZERO_STRUCT(dh);
     580             : 
     581           4 :         smb2_deltree(tree1, BASEDIR);
     582           4 :         smb2_util_rmdir(tree1, BASEDIR);
     583             : 
     584           4 :         torture_comment(torture, "Creating base directory\n");
     585             : 
     586           4 :         smb2_util_mkdir(tree1, BASEDIR);
     587             : 
     588           4 :         torture_comment(torture, "Opening parent directory\n");
     589             : 
     590           4 :         ZERO_STRUCT(io.smb2);
     591           4 :         io.generic.level = RAW_OPEN_SMB2;
     592           4 :         io.smb2.in.create_flags = 0;
     593           4 :         io.smb2.in.desired_access = SEC_STD_SYNCHRONIZE | SEC_STD_WRITE_DAC |
     594             :                 SEC_STD_READ_CONTROL | SEC_FILE_WRITE_ATTRIBUTE |
     595             :                 SEC_FILE_READ_ATTRIBUTE | SEC_FILE_EXECUTE | SEC_FILE_WRITE_EA |
     596             :                 SEC_FILE_READ_EA | SEC_FILE_APPEND_DATA | SEC_FILE_READ_DATA |
     597             :                 SEC_FILE_WRITE_DATA;
     598           4 :         io.smb2.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
     599           4 :         io.smb2.in.file_attributes = FILE_ATTRIBUTE_DIRECTORY;
     600           4 :         io.smb2.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
     601             :                 NTCREATEX_SHARE_ACCESS_WRITE | NTCREATEX_SHARE_ACCESS_DELETE;
     602           4 :         io.smb2.in.alloc_size = 0;
     603           4 :         io.smb2.in.create_disposition = NTCREATEX_DISP_OPEN;
     604           4 :         io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
     605           4 :         io.smb2.in.security_flags = 0;
     606           4 :         io.smb2.in.fname = BASEDIR;
     607             : 
     608           4 :         status = smb2_create(tree1, torture, &(io.smb2));
     609           4 :         CHECK_STATUS(status, NT_STATUS_OK);
     610           4 :         dh = io.smb2.out.file.handle;
     611             : 
     612             : 
     613           4 :         torture_comment(torture, "Creating test file\n");
     614             : 
     615           4 :         ZERO_STRUCT(io.smb2);
     616           4 :         io.generic.level = RAW_OPEN_SMB2;
     617           4 :         io.smb2.in.create_flags = 0;
     618           4 :         io.smb2.in.desired_access = SEC_STD_SYNCHRONIZE | SEC_STD_WRITE_DAC |
     619             :                 SEC_STD_READ_CONTROL | SEC_STD_DELETE | SEC_FILE_WRITE_ATTRIBUTE |
     620             :                 SEC_FILE_READ_ATTRIBUTE | SEC_FILE_WRITE_EA | SEC_FILE_READ_EA |
     621             :                 SEC_FILE_APPEND_DATA | SEC_FILE_READ_DATA | SEC_FILE_WRITE_DATA;
     622           4 :         io.smb2.in.create_options = NTCREATEX_OPTIONS_NON_DIRECTORY_FILE;
     623           4 :         io.smb2.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
     624           4 :         io.smb2.in.share_access = 0;
     625           4 :         io.smb2.in.alloc_size = 0;
     626           4 :         io.smb2.in.create_disposition = NTCREATEX_DISP_CREATE;
     627           4 :         io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
     628           4 :         io.smb2.in.security_flags = 0;
     629           4 :         io.smb2.in.fname = BASEDIR "\\file.txt";
     630             : 
     631           4 :         status = smb2_create(tree1, torture, &(io.smb2));
     632           4 :         CHECK_STATUS(status, NT_STATUS_OK);
     633           4 :         fh = io.smb2.out.file.handle;
     634             : 
     635           4 :         torture_comment(torture, "Renaming test file\n");
     636             : 
     637           4 :         ZERO_STRUCT(sinfo);
     638           4 :         sinfo.rename_information.level = RAW_SFILEINFO_RENAME_INFORMATION;
     639           4 :         sinfo.rename_information.in.file.handle = fh;
     640           4 :         sinfo.rename_information.in.overwrite = 0;
     641           4 :         sinfo.rename_information.in.root_fid = 0;
     642           4 :         sinfo.rename_information.in.new_name =
     643             :                 BASEDIR "\\newname.txt";
     644           4 :         status = smb2_setinfo_file(tree1, &sinfo);
     645           4 :         CHECK_STATUS(status, NT_STATUS_OK);
     646             : 
     647           4 :         torture_comment(torture, "Checking for new filename\n");
     648             : 
     649           4 :         ZERO_STRUCT(fi);
     650           4 :         fi.generic.level = RAW_FILEINFO_SMB2_ALL_INFORMATION;
     651           4 :         fi.generic.in.file.handle = fh;
     652           4 :         status = smb2_getinfo_file(tree1, torture, &fi);
     653           4 :         CHECK_STATUS(status, NT_STATUS_OK);
     654             : 
     655             : 
     656           4 :         torture_comment(torture, "Closing test file\n");
     657             : 
     658           4 :         ZERO_STRUCT(cl.smb2);
     659           4 :         cl.smb2.level = RAW_CLOSE_SMB2;
     660           4 :         cl.smb2.in.file.handle = fh;
     661           4 :         status = smb2_close(tree1, &(cl.smb2));
     662           4 :         CHECK_STATUS(status, NT_STATUS_OK);
     663             : 
     664           4 :         ZERO_STRUCT(fh);
     665             : 
     666           4 :         torture_comment(torture, "Closing directory\n");
     667             : 
     668           4 :         ZERO_STRUCT(cl.smb2);
     669           4 :         cl.smb2.level = RAW_CLOSE_SMB2;
     670           4 :         cl.smb2.in.file.handle = dh;
     671           4 :         status = smb2_close(tree1, &(cl.smb2));
     672           4 :         CHECK_STATUS(status, NT_STATUS_OK);
     673             : 
     674           4 :         ZERO_STRUCT(dh);
     675             : 
     676             : 
     677           4 : done:
     678             : 
     679           4 :         torture_comment(torture, "Cleaning up\n");
     680             : 
     681           4 :         if (fh.data[0] || fh.data[1]) {
     682           0 :                 ZERO_STRUCT(cl.smb2);
     683           0 :                 cl.smb2.level = RAW_CLOSE_SMB2;
     684           0 :                 cl.smb2.in.file.handle = fh;
     685           0 :                 status = smb2_close(tree1, &(cl.smb2));
     686             :         }
     687           4 :         if (dh.data[0] || dh.data[1]) {
     688           0 :                 ZERO_STRUCT(cl.smb2);
     689           0 :                 cl.smb2.level = RAW_CLOSE_SMB2;
     690           0 :                 cl.smb2.in.file.handle = dh;
     691           0 :                 status = smb2_close(tree1, &(cl.smb2));
     692             :         }
     693             : 
     694           4 :         smb2_deltree(tree1, BASEDIR);
     695           4 :         return ret;
     696             : }
     697             : 
     698             : 
     699             : /*
     700             :  * testing of rename with no delete access on parent dir
     701             :  * this is the negative case of the test above: parent dir is opened
     702             :  * without share_delete, so rename must fail
     703             :  */
     704             : 
     705           4 : static bool torture_smb2_rename_no_delete_access2(struct torture_context *torture,
     706             :                 struct smb2_tree *tree1)
     707             : {
     708           4 :         bool ret = true;
     709             :         NTSTATUS status;
     710             :         union smb_open io;
     711             :         union smb_close cl;
     712             :         union smb_setfileinfo sinfo;
     713             :         struct smb2_handle fh, dh;
     714             : 
     715           4 :         ZERO_STRUCT(fh);
     716           4 :         ZERO_STRUCT(dh);
     717             : 
     718           4 :         smb2_deltree(tree1, BASEDIR);
     719           4 :         smb2_util_rmdir(tree1, BASEDIR);
     720             : 
     721           4 :         torture_comment(torture, "Creating base directory\n");
     722             : 
     723           4 :         smb2_util_mkdir(tree1, BASEDIR);
     724             : 
     725           4 :         torture_comment(torture, "Opening parent directory\n");
     726             : 
     727           4 :         ZERO_STRUCT(io.smb2);
     728           4 :         io.generic.level = RAW_OPEN_SMB2;
     729           4 :         io.smb2.in.create_flags = 0;
     730           4 :         io.smb2.in.desired_access = SEC_STD_SYNCHRONIZE | SEC_STD_WRITE_DAC |
     731             :                 SEC_STD_READ_CONTROL | SEC_FILE_WRITE_ATTRIBUTE |
     732             :                 SEC_FILE_READ_ATTRIBUTE | SEC_FILE_EXECUTE | SEC_FILE_WRITE_EA |
     733             :                 SEC_FILE_READ_EA | SEC_FILE_APPEND_DATA | SEC_FILE_READ_DATA |
     734             :                 SEC_FILE_WRITE_DATA;
     735           4 :         io.smb2.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
     736           4 :         io.smb2.in.file_attributes = FILE_ATTRIBUTE_DIRECTORY;
     737           4 :         io.smb2.in.share_access = 0;
     738           4 :         io.smb2.in.alloc_size = 0;
     739           4 :         io.smb2.in.create_disposition = NTCREATEX_DISP_OPEN;
     740           4 :         io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
     741           4 :         io.smb2.in.security_flags = 0;
     742           4 :         io.smb2.in.fname = BASEDIR;
     743             : 
     744           4 :         status = smb2_create(tree1, torture, &(io.smb2));
     745           4 :         CHECK_STATUS(status, NT_STATUS_OK);
     746           4 :         dh = io.smb2.out.file.handle;
     747             : 
     748             : 
     749           4 :         torture_comment(torture, "Creating test file\n");
     750             : 
     751           4 :         ZERO_STRUCT(io.smb2);
     752           4 :         io.generic.level = RAW_OPEN_SMB2;
     753           4 :         io.smb2.in.create_flags = 0;
     754           4 :         io.smb2.in.desired_access = SEC_STD_SYNCHRONIZE | SEC_STD_WRITE_DAC |
     755             :                 SEC_STD_READ_CONTROL | SEC_STD_DELETE | SEC_FILE_WRITE_ATTRIBUTE |
     756             :                 SEC_FILE_READ_ATTRIBUTE | SEC_FILE_WRITE_EA | SEC_FILE_READ_EA |
     757             :                 SEC_FILE_APPEND_DATA | SEC_FILE_READ_DATA | SEC_FILE_WRITE_DATA;
     758           4 :         io.smb2.in.create_options = NTCREATEX_OPTIONS_NON_DIRECTORY_FILE;
     759           4 :         io.smb2.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
     760           4 :         io.smb2.in.share_access = 0;
     761           4 :         io.smb2.in.alloc_size = 0;
     762           4 :         io.smb2.in.create_disposition = NTCREATEX_DISP_CREATE;
     763           4 :         io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
     764           4 :         io.smb2.in.security_flags = 0;
     765           4 :         io.smb2.in.fname = BASEDIR "\\file.txt";
     766             : 
     767           4 :         status = smb2_create(tree1, torture, &(io.smb2));
     768           4 :         CHECK_STATUS(status, NT_STATUS_OK);
     769           4 :         fh = io.smb2.out.file.handle;
     770             : 
     771           4 :         torture_comment(torture, "Renaming test file\n");
     772             : 
     773           4 :         ZERO_STRUCT(sinfo);
     774           4 :         sinfo.rename_information.level = RAW_SFILEINFO_RENAME_INFORMATION;
     775           4 :         sinfo.rename_information.in.file.handle = fh;
     776           4 :         sinfo.rename_information.in.overwrite = 0;
     777           4 :         sinfo.rename_information.in.root_fid = 0;
     778           4 :         sinfo.rename_information.in.new_name =
     779             :                 BASEDIR "\\newname.txt";
     780           4 :         status = smb2_setinfo_file(tree1, &sinfo);
     781           4 :         CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION);
     782             : 
     783           0 :         torture_comment(torture, "Closing test file\n");
     784             : 
     785           0 :         ZERO_STRUCT(cl.smb2);
     786           0 :         cl.smb2.level = RAW_CLOSE_SMB2;
     787           0 :         cl.smb2.in.file.handle = fh;
     788           0 :         status = smb2_close(tree1, &(cl.smb2));
     789           0 :         CHECK_STATUS(status, NT_STATUS_OK);
     790             : 
     791           0 :         ZERO_STRUCT(fh);
     792             : 
     793           0 :         torture_comment(torture, "Closing directory\n");
     794             : 
     795           0 :         ZERO_STRUCT(cl.smb2);
     796           0 :         cl.smb2.level = RAW_CLOSE_SMB2;
     797           0 :         cl.smb2.in.file.handle = dh;
     798           0 :         status = smb2_close(tree1, &(cl.smb2));
     799           0 :         CHECK_STATUS(status, NT_STATUS_OK);
     800             : 
     801           0 :         ZERO_STRUCT(dh);
     802             : 
     803             : 
     804           4 : done:
     805             : 
     806           4 :         torture_comment(torture, "Cleaning up\n");
     807             : 
     808           4 :         if (fh.data[0] || fh.data[1]) {
     809           4 :                 ZERO_STRUCT(cl.smb2);
     810           4 :                 cl.smb2.level = RAW_CLOSE_SMB2;
     811           4 :                 cl.smb2.in.file.handle = fh;
     812           4 :                 status = smb2_close(tree1, &(cl.smb2));
     813             :         }
     814           4 :         if (dh.data[0] || dh.data[1]) {
     815           4 :                 ZERO_STRUCT(cl.smb2);
     816           4 :                 cl.smb2.level = RAW_CLOSE_SMB2;
     817           4 :                 cl.smb2.in.file.handle = dh;
     818           4 :                 status = smb2_close(tree1, &(cl.smb2));
     819             :         }
     820             : 
     821           4 :         smb2_deltree(tree1, BASEDIR);
     822           4 :         return ret;
     823             : }
     824             : 
     825             : /*
     826             :  * this is a replay of how Word 2010 saves a file
     827             :  * this should pass
     828             :  */
     829             : 
     830           4 : static bool torture_smb2_rename_msword(struct torture_context *torture,
     831             :                 struct smb2_tree *tree1)
     832             : {
     833           4 :         bool ret = true;
     834             :         NTSTATUS status;
     835             :         union smb_open io;
     836             :         union smb_close cl;
     837             :         union smb_setfileinfo sinfo;
     838             :         union smb_fileinfo fi;
     839             :         struct smb2_handle fh, dh;
     840             : 
     841           4 :         ZERO_STRUCT(fh);
     842           4 :         ZERO_STRUCT(dh);
     843             : 
     844           4 :         smb2_deltree(tree1, BASEDIR);
     845           4 :         smb2_util_rmdir(tree1, BASEDIR);
     846             : 
     847           4 :         torture_comment(torture, "Creating base directory\n");
     848             : 
     849           4 :         smb2_util_mkdir(tree1, BASEDIR);
     850             : 
     851           4 :         torture_comment(torture, "Creating test file\n");
     852             : 
     853           4 :         ZERO_STRUCT(io.smb2);
     854           4 :         io.generic.level = RAW_OPEN_SMB2;
     855           4 :         io.smb2.in.create_flags = 0;
     856           4 :         io.smb2.in.desired_access = 0x0017019f;
     857           4 :         io.smb2.in.create_options = 0x60;
     858           4 :         io.smb2.in.file_attributes = 0;
     859           4 :         io.smb2.in.share_access = 0;
     860           4 :         io.smb2.in.alloc_size = 0;
     861           4 :         io.smb2.in.create_disposition = NTCREATEX_DISP_CREATE;
     862           4 :         io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
     863           4 :         io.smb2.in.security_flags = 0;
     864           4 :         io.smb2.in.fname = BASEDIR "\\file.txt";
     865             : 
     866           4 :         status = smb2_create(tree1, torture, &(io.smb2));
     867           4 :         CHECK_STATUS(status, NT_STATUS_OK);
     868           4 :         fh = io.smb2.out.file.handle;
     869             : 
     870           4 :         torture_comment(torture, "Opening parent directory\n");
     871             : 
     872           4 :         ZERO_STRUCT(io.smb2);
     873           4 :         io.generic.level = RAW_OPEN_SMB2;
     874           4 :         io.smb2.in.create_flags = 0;
     875           4 :         io.smb2.in.desired_access = 0x00100080;
     876           4 :         io.smb2.in.create_options = 0x00800021;
     877           4 :         io.smb2.in.file_attributes = 0;
     878           4 :         io.smb2.in.share_access = 0;
     879           4 :         io.smb2.in.alloc_size = 0;
     880           4 :         io.smb2.in.create_disposition = NTCREATEX_DISP_OPEN;
     881           4 :         io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
     882           4 :         io.smb2.in.security_flags = 0;
     883           4 :         io.smb2.in.fname = BASEDIR;
     884             : 
     885           4 :         status = smb2_create(tree1, torture, &(io.smb2));
     886           4 :         CHECK_STATUS(status, NT_STATUS_OK);
     887           4 :         dh = io.smb2.out.file.handle;
     888             : 
     889           4 :         torture_comment(torture, "Renaming test file\n");
     890             : 
     891           4 :         ZERO_STRUCT(sinfo);
     892           4 :         sinfo.rename_information.level = RAW_SFILEINFO_RENAME_INFORMATION;
     893           4 :         sinfo.rename_information.in.file.handle = fh;
     894           4 :         sinfo.rename_information.in.overwrite = 0;
     895           4 :         sinfo.rename_information.in.root_fid = 0;
     896           4 :         sinfo.rename_information.in.new_name =
     897             :                 BASEDIR "\\newname.txt";
     898           4 :         status = smb2_setinfo_file(tree1, &sinfo);
     899           4 :         CHECK_STATUS(status, NT_STATUS_OK);
     900             : 
     901           4 :         torture_comment(torture, "Checking for new filename\n");
     902             : 
     903           4 :         ZERO_STRUCT(fi);
     904           4 :         fi.generic.level = RAW_FILEINFO_SMB2_ALL_INFORMATION;
     905           4 :         fi.generic.in.file.handle = fh;
     906           4 :         status = smb2_getinfo_file(tree1, torture, &fi);
     907           4 :         CHECK_STATUS(status, NT_STATUS_OK);
     908             : 
     909             : 
     910           4 :         torture_comment(torture, "Closing test file\n");
     911             : 
     912           4 :         ZERO_STRUCT(cl.smb2);
     913           4 :         cl.smb2.level = RAW_CLOSE_SMB2;
     914           4 :         cl.smb2.in.file.handle = fh;
     915           4 :         status = smb2_close(tree1, &(cl.smb2));
     916           4 :         CHECK_STATUS(status, NT_STATUS_OK);
     917             : 
     918           4 :         ZERO_STRUCT(fh);
     919             : 
     920           4 :         torture_comment(torture, "Closing directory\n");
     921             : 
     922           4 :         ZERO_STRUCT(cl.smb2);
     923           4 :         cl.smb2.level = RAW_CLOSE_SMB2;
     924           4 :         cl.smb2.in.file.handle = dh;
     925           4 :         status = smb2_close(tree1, &(cl.smb2));
     926           4 :         CHECK_STATUS(status, NT_STATUS_OK);
     927             : 
     928           4 :         ZERO_STRUCT(dh);
     929             : 
     930             : 
     931           4 : done:
     932             : 
     933           4 :         torture_comment(torture, "Cleaning up\n");
     934             : 
     935           4 :         if (fh.data[0] || fh.data[1]) {
     936           0 :                 ZERO_STRUCT(cl.smb2);
     937           0 :                 cl.smb2.level = RAW_CLOSE_SMB2;
     938           0 :                 cl.smb2.in.file.handle = fh;
     939           0 :                 status = smb2_close(tree1, &(cl.smb2));
     940             :         }
     941           4 :         if (dh.data[0] || dh.data[1]) {
     942           0 :                 ZERO_STRUCT(cl.smb2);
     943           0 :                 cl.smb2.level = RAW_CLOSE_SMB2;
     944           0 :                 cl.smb2.in.file.handle = dh;
     945           0 :                 status = smb2_close(tree1, &(cl.smb2));
     946             :         }
     947             : 
     948           4 :         smb2_deltree(tree1, BASEDIR);
     949           4 :         return ret;
     950             : }
     951             : 
     952           4 : static bool torture_smb2_rename_dir_openfile(struct torture_context *torture,
     953             :                                              struct smb2_tree *tree1)
     954             : {
     955           4 :         bool ret = true;
     956             :         NTSTATUS status;
     957             :         union smb_open io;
     958             :         union smb_close cl;
     959             :         union smb_setfileinfo sinfo;
     960             :         struct smb2_handle d1, h1;
     961             : 
     962           4 :         ZERO_STRUCT(d1);
     963           4 :         ZERO_STRUCT(h1);
     964             : 
     965           4 :         smb2_deltree(tree1, BASEDIR);
     966           4 :         smb2_util_rmdir(tree1, BASEDIR);
     967             : 
     968           4 :         torture_comment(torture, "Creating base directory\n");
     969             : 
     970           4 :         ZERO_STRUCT(io.smb2);
     971           4 :         io.generic.level = RAW_OPEN_SMB2;
     972           4 :         io.smb2.in.create_flags = 0;
     973           4 :         io.smb2.in.desired_access = 0x0017019f;
     974           4 :         io.smb2.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
     975           4 :         io.smb2.in.file_attributes = FILE_ATTRIBUTE_DIRECTORY;
     976           4 :         io.smb2.in.share_access = 0;
     977           4 :         io.smb2.in.alloc_size = 0;
     978           4 :         io.smb2.in.create_disposition = NTCREATEX_DISP_CREATE;
     979           4 :         io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
     980           4 :         io.smb2.in.security_flags = 0;
     981           4 :         io.smb2.in.fname = BASEDIR;
     982             : 
     983           4 :         status = smb2_create(tree1, torture, &(io.smb2));
     984           4 :         CHECK_STATUS(status, NT_STATUS_OK);
     985           4 :         d1 = io.smb2.out.file.handle;
     986             : 
     987           4 :         torture_comment(torture, "Creating test file\n");
     988             : 
     989           4 :         ZERO_STRUCT(io.smb2);
     990           4 :         io.generic.level = RAW_OPEN_SMB2;
     991           4 :         io.smb2.in.create_flags = 0;
     992           4 :         io.smb2.in.desired_access = 0x0017019f;
     993           4 :         io.smb2.in.create_options = NTCREATEX_OPTIONS_NON_DIRECTORY_FILE;
     994           4 :         io.smb2.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
     995           4 :         io.smb2.in.share_access = 0;
     996           4 :         io.smb2.in.alloc_size = 0;
     997           4 :         io.smb2.in.create_disposition = NTCREATEX_DISP_CREATE;
     998           4 :         io.smb2.in.impersonation_level = SMB2_IMPERSONATION_ANONYMOUS;
     999           4 :         io.smb2.in.security_flags = 0;
    1000           4 :         io.smb2.in.fname = BASEDIR "\\file.txt";
    1001             : 
    1002           4 :         status = smb2_create(tree1, torture, &(io.smb2));
    1003           4 :         CHECK_STATUS(status, NT_STATUS_OK);
    1004           4 :         h1 = io.smb2.out.file.handle;
    1005             : 
    1006           4 :         torture_comment(torture, "Renaming directory\n");
    1007             : 
    1008           4 :         ZERO_STRUCT(sinfo);
    1009           4 :         sinfo.rename_information.level = RAW_SFILEINFO_RENAME_INFORMATION;
    1010           4 :         sinfo.rename_information.in.file.handle = d1;
    1011           4 :         sinfo.rename_information.in.overwrite = 0;
    1012           4 :         sinfo.rename_information.in.root_fid = 0;
    1013           4 :         sinfo.rename_information.in.new_name =
    1014             :                 BASEDIR "-new";
    1015           4 :         status = smb2_setinfo_file(tree1, &sinfo);
    1016           4 :         CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
    1017             : 
    1018           4 :         torture_comment(torture, "Closing directory\n");
    1019             : 
    1020           4 :         ZERO_STRUCT(cl.smb2);
    1021           4 :         cl.smb2.level = RAW_CLOSE_SMB2;
    1022           4 :         cl.smb2.in.file.handle = d1;
    1023           4 :         status = smb2_close(tree1, &(cl.smb2));
    1024           4 :         CHECK_STATUS(status, NT_STATUS_OK);
    1025           4 :         ZERO_STRUCT(d1);
    1026             : 
    1027           4 :         torture_comment(torture, "Closing test file\n");
    1028             : 
    1029           4 :         cl.smb2.in.file.handle = h1;
    1030           4 :         status = smb2_close(tree1, &(cl.smb2));
    1031           4 :         CHECK_STATUS(status, NT_STATUS_OK);
    1032           4 :         ZERO_STRUCT(h1);
    1033             : 
    1034           4 : done:
    1035             : 
    1036           4 :         torture_comment(torture, "Cleaning up\n");
    1037             : 
    1038           4 :         if (h1.data[0] || h1.data[1]) {
    1039           0 :                 ZERO_STRUCT(cl.smb2);
    1040           0 :                 cl.smb2.level = RAW_CLOSE_SMB2;
    1041           0 :                 cl.smb2.in.file.handle = h1;
    1042           0 :                 status = smb2_close(tree1, &(cl.smb2));
    1043             :         }
    1044           4 :         smb2_deltree(tree1, BASEDIR);
    1045           4 :         return ret;
    1046             : }
    1047             : 
    1048             : struct rename_one_dir_cycle_state {
    1049             :         struct tevent_context *ev;
    1050             :         struct smb2_tree *tree;
    1051             :         struct smb2_handle file;
    1052             :         const char *base_name;
    1053             :         char *new_name;
    1054             :         unsigned *rename_counter;
    1055             : 
    1056             :         unsigned current;
    1057             :         unsigned max;
    1058             :         union smb_setfileinfo sinfo;
    1059             : };
    1060             : 
    1061             : static void rename_one_dir_cycle_done(struct smb2_request *subreq);
    1062             : 
    1063          12 : static struct tevent_req *rename_one_dir_cycle_send(TALLOC_CTX *mem_ctx,
    1064             :                                                     struct tevent_context *ev,
    1065             :                                                     struct smb2_tree *tree,
    1066             :                                                     struct smb2_handle file,
    1067             :                                                     unsigned max_renames,
    1068             :                                                     const char *base_name,
    1069             :                                                     unsigned *rename_counter)
    1070             : {
    1071             :         struct tevent_req *req;
    1072             :         struct rename_one_dir_cycle_state *state;
    1073             :         struct smb2_request *subreq;
    1074             : 
    1075          12 :         req = tevent_req_create(mem_ctx, &state,
    1076             :                                 struct rename_one_dir_cycle_state);
    1077          12 :         if (req == NULL) {
    1078           0 :                 return NULL;
    1079             :         }
    1080          12 :         state->ev = ev;
    1081          12 :         state->tree = tree;
    1082          12 :         state->file = file;
    1083          12 :         state->base_name = base_name;
    1084          12 :         state->rename_counter = rename_counter;
    1085          12 :         state->current = 0;
    1086          12 :         state->max = max_renames;
    1087             : 
    1088          12 :         ZERO_STRUCT(state->sinfo);
    1089          12 :         state->sinfo.rename_information.level =
    1090             :                 RAW_SFILEINFO_RENAME_INFORMATION;
    1091          12 :         state->sinfo.rename_information.in.file.handle = state->file;
    1092          12 :         state->sinfo.rename_information.in.overwrite = 0;
    1093          12 :         state->sinfo.rename_information.in.root_fid = 0;
    1094             : 
    1095          24 :         state->new_name = talloc_asprintf(
    1096          24 :                 state, "%s-%u", state->base_name, state->current);
    1097          12 :         if (tevent_req_nomem(state->new_name, req)) {
    1098           0 :                 return tevent_req_post(req, ev);
    1099             :         }
    1100          12 :         state->sinfo.rename_information.in.new_name = state->new_name;
    1101             : 
    1102          12 :         subreq = smb2_setinfo_file_send(state->tree, &state->sinfo);
    1103          12 :         if (tevent_req_nomem(subreq, req)) {
    1104           0 :                 return tevent_req_post(req, ev);
    1105             :         }
    1106          12 :         subreq->async.fn = rename_one_dir_cycle_done;
    1107          12 :         subreq->async.private_data = req;
    1108          12 :         return req;
    1109             : }
    1110             : 
    1111         120 : static void rename_one_dir_cycle_done(struct smb2_request *subreq)
    1112             : {
    1113         120 :         struct tevent_req *req = talloc_get_type_abort(
    1114             :                 subreq->async.private_data, struct tevent_req);
    1115         120 :         struct rename_one_dir_cycle_state *state = tevent_req_data(
    1116             :                 req, struct rename_one_dir_cycle_state);
    1117             :         NTSTATUS status;
    1118             : 
    1119         120 :         status = smb2_setinfo_recv(subreq);
    1120         120 :         if (tevent_req_nterror(req, status)) {
    1121          12 :                 return;
    1122             :         }
    1123         120 :         TALLOC_FREE(state->new_name);
    1124             : 
    1125         120 :         *state->rename_counter += 1;
    1126             : 
    1127         120 :         state->current += 1;
    1128         120 :         if (state->current >= state->max) {
    1129          12 :                 tevent_req_done(req);
    1130          12 :                 return;
    1131             :         }
    1132             : 
    1133         108 :         ZERO_STRUCT(state->sinfo);
    1134         108 :         state->sinfo.rename_information.level =
    1135             :                 RAW_SFILEINFO_RENAME_INFORMATION;
    1136         108 :         state->sinfo.rename_information.in.file.handle = state->file;
    1137         108 :         state->sinfo.rename_information.in.overwrite = 0;
    1138         108 :         state->sinfo.rename_information.in.root_fid = 0;
    1139             : 
    1140         108 :         state->new_name = talloc_asprintf(
    1141             :                 state, "%s-%u", state->base_name, state->current);
    1142         108 :         if (tevent_req_nomem(state->new_name, req)) {
    1143           0 :                 return;
    1144             :         }
    1145         108 :         state->sinfo.rename_information.in.new_name = state->new_name;
    1146             : 
    1147         108 :         subreq = smb2_setinfo_file_send(state->tree, &state->sinfo);
    1148         108 :         if (tevent_req_nomem(subreq, req)) {
    1149           0 :                 return;
    1150             :         }
    1151         108 :         subreq->async.fn = rename_one_dir_cycle_done;
    1152         108 :         subreq->async.private_data = req;
    1153             : }
    1154             : 
    1155          12 : static NTSTATUS rename_one_dir_cycle_recv(struct tevent_req *req)
    1156             : {
    1157          12 :         return tevent_req_simple_recv_ntstatus(req);
    1158             : }
    1159             : 
    1160             : struct rename_dir_bench_state {
    1161             :         struct tevent_context *ev;
    1162             :         struct smb2_tree *tree;
    1163             :         const char *base_name;
    1164             :         unsigned max_renames;
    1165             :         unsigned *rename_counter;
    1166             : 
    1167             :         struct smb2_create io;
    1168             :         union smb_setfileinfo sinfo;
    1169             :         struct smb2_close cl;
    1170             : 
    1171             :         struct smb2_handle file;
    1172             : };
    1173             : 
    1174             : static void rename_dir_bench_opened(struct smb2_request *subreq);
    1175             : static void rename_dir_bench_renamed(struct tevent_req *subreq);
    1176             : static void rename_dir_bench_set_doc(struct smb2_request *subreq);
    1177             : static void rename_dir_bench_closed(struct smb2_request *subreq);
    1178             : 
    1179          12 : static struct tevent_req *rename_dir_bench_send(TALLOC_CTX *mem_ctx,
    1180             :                                                 struct tevent_context *ev,
    1181             :                                                 struct smb2_tree *tree,
    1182             :                                                 const char *base_name,
    1183             :                                                 unsigned max_renames,
    1184             :                                                 unsigned *rename_counter)
    1185             : {
    1186             :         struct tevent_req *req;
    1187             :         struct rename_dir_bench_state *state;
    1188             :         struct smb2_request *subreq;
    1189             : 
    1190          12 :         req = tevent_req_create(mem_ctx, &state,
    1191             :                                 struct rename_dir_bench_state);
    1192          12 :         if (req == NULL) {
    1193           0 :                 return NULL;
    1194             :         }
    1195          12 :         state->ev = ev;
    1196          12 :         state->tree = tree;
    1197          12 :         state->base_name = base_name;
    1198          12 :         state->max_renames = max_renames;
    1199          12 :         state->rename_counter = rename_counter;
    1200             : 
    1201          12 :         ZERO_STRUCT(state->io);
    1202          12 :         state->io.in.desired_access = SEC_FLAG_MAXIMUM_ALLOWED;
    1203          12 :         state->io.in.share_access =
    1204             :                 NTCREATEX_SHARE_ACCESS_READ|
    1205             :                 NTCREATEX_SHARE_ACCESS_WRITE;
    1206          12 :         state->io.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
    1207          12 :         state->io.in.file_attributes = FILE_ATTRIBUTE_DIRECTORY;
    1208          12 :         state->io.in.create_disposition = NTCREATEX_DISP_OPEN_IF;
    1209          12 :         state->io.in.fname = state->base_name;
    1210             : 
    1211          12 :         subreq = smb2_create_send(state->tree, &state->io);
    1212          12 :         if (tevent_req_nomem(subreq, req)) {
    1213           0 :                 return tevent_req_post(req, ev);
    1214             :         }
    1215          12 :         subreq->async.fn = rename_dir_bench_opened;
    1216          12 :         subreq->async.private_data = req;
    1217          12 :         return req;
    1218             : }
    1219             : 
    1220          12 : static void rename_dir_bench_opened(struct smb2_request *subreq)
    1221             : {
    1222          12 :         struct tevent_req *req = talloc_get_type_abort(
    1223             :                 subreq->async.private_data, struct tevent_req);
    1224          12 :         struct rename_dir_bench_state *state = tevent_req_data(
    1225             :                 req, struct rename_dir_bench_state);
    1226             :         struct smb2_create *io;
    1227             :         struct tevent_req *subreq2;
    1228             :         NTSTATUS status;
    1229             : 
    1230          12 :         io = talloc(state, struct smb2_create);
    1231          12 :         if (tevent_req_nomem(io, req)) {
    1232           0 :                 return;
    1233             :         }
    1234             : 
    1235          12 :         status = smb2_create_recv(subreq, io, io);
    1236          12 :         if (tevent_req_nterror(req, status)) {
    1237           0 :                 return;
    1238             :         }
    1239          12 :         state->file = io->out.file.handle;
    1240          12 :         TALLOC_FREE(io);
    1241             : 
    1242          12 :         subreq2 = rename_one_dir_cycle_send(
    1243             :                 state, state->ev, state->tree, state->file,
    1244             :                 state->max_renames, state->base_name,
    1245             :                 state->rename_counter);
    1246          12 :         if (tevent_req_nomem(subreq2, req)) {
    1247           0 :                 return;
    1248             :         }
    1249          12 :         tevent_req_set_callback(subreq2, rename_dir_bench_renamed, req);
    1250             : }
    1251             : 
    1252          12 : static void rename_dir_bench_renamed(struct tevent_req *subreq)
    1253             : {
    1254          12 :         struct tevent_req *req = tevent_req_callback_data(
    1255             :                 subreq, struct tevent_req);
    1256          12 :         struct rename_dir_bench_state *state = tevent_req_data(
    1257             :                 req, struct rename_dir_bench_state);
    1258             :         struct smb2_request *subreq2;
    1259             :         NTSTATUS status;
    1260             : 
    1261          12 :         status = rename_one_dir_cycle_recv(subreq);
    1262          12 :         TALLOC_FREE(subreq);
    1263          12 :         if (tevent_req_nterror(req, status)) {
    1264           0 :                 return;
    1265             :         }
    1266             : 
    1267          12 :         ZERO_STRUCT(state->sinfo);
    1268          12 :         state->sinfo.disposition_info.level =
    1269             :                 RAW_SFILEINFO_DISPOSITION_INFORMATION;
    1270          12 :         state->sinfo.disposition_info.in.file.handle = state->file;
    1271          12 :         state->sinfo.disposition_info.in.delete_on_close = true;
    1272             : 
    1273          12 :         subreq2 = smb2_setinfo_file_send(state->tree, &state->sinfo);
    1274          12 :         if (tevent_req_nomem(subreq2, req)) {
    1275           0 :                 return;
    1276             :         }
    1277          12 :         subreq2->async.fn = rename_dir_bench_set_doc;
    1278          12 :         subreq2->async.private_data = req;
    1279             : }
    1280             : 
    1281          12 : static void rename_dir_bench_set_doc(struct smb2_request *subreq)
    1282             : {
    1283          12 :         struct tevent_req *req = talloc_get_type_abort(
    1284             :                 subreq->async.private_data, struct tevent_req);
    1285          12 :         struct rename_dir_bench_state *state = tevent_req_data(
    1286             :                 req, struct rename_dir_bench_state);
    1287             :         NTSTATUS status;
    1288             : 
    1289          12 :         status = smb2_setinfo_recv(subreq);
    1290          12 :         if (tevent_req_nterror(req, status)) {
    1291           0 :                 return;
    1292             :         }
    1293             : 
    1294          12 :         ZERO_STRUCT(state->cl);
    1295          12 :         state->cl.in.file.handle = state->file;
    1296             : 
    1297          12 :         subreq = smb2_close_send(state->tree, &state->cl);
    1298          12 :         if (tevent_req_nomem(subreq, req)) {
    1299           0 :                 return;
    1300             :         }
    1301          12 :         subreq->async.fn = rename_dir_bench_closed;
    1302          12 :         subreq->async.private_data = req;
    1303             : }
    1304             : 
    1305          12 : static void rename_dir_bench_closed(struct smb2_request *subreq)
    1306             : {
    1307          12 :         struct tevent_req *req = talloc_get_type_abort(
    1308             :                 subreq->async.private_data, struct tevent_req);
    1309             :         struct smb2_close cl;
    1310             :         NTSTATUS status;
    1311             : 
    1312          12 :         status = smb2_close_recv(subreq, &cl);
    1313          12 :         if (tevent_req_nterror(req, status)) {
    1314           0 :                 return;
    1315             :         }
    1316          12 :         tevent_req_done(req);
    1317             : }
    1318             : 
    1319          12 : static NTSTATUS rename_dir_bench_recv(struct tevent_req *req)
    1320             : {
    1321          12 :         return tevent_req_simple_recv_ntstatus(req);
    1322             : }
    1323             : 
    1324             : struct rename_dirs_bench_state {
    1325             :         unsigned num_reqs;
    1326             :         unsigned num_done;
    1327             : };
    1328             : 
    1329             : static void rename_dirs_bench_done(struct tevent_req *subreq);
    1330             : 
    1331           4 : static struct tevent_req *rename_dirs_bench_send(TALLOC_CTX *mem_ctx,
    1332             :                                                  struct tevent_context *ev,
    1333             :                                                  struct smb2_tree *tree,
    1334             :                                                  const char *base_name,
    1335             :                                                  unsigned num_parallel,
    1336             :                                                  unsigned max_renames,
    1337             :                                                  unsigned *rename_counter)
    1338             : {
    1339             :         struct tevent_req *req;
    1340             :         struct rename_dirs_bench_state *state;
    1341             :         unsigned i;
    1342             : 
    1343           4 :         req = tevent_req_create(mem_ctx, &state,
    1344             :                                 struct rename_dirs_bench_state);
    1345           4 :         if (req == NULL) {
    1346           0 :                 return NULL;
    1347             :         }
    1348           4 :         state->num_reqs = num_parallel;
    1349           4 :         state->num_done = 0;
    1350             : 
    1351          16 :         for (i=0; i<num_parallel; i++) {
    1352             :                 struct tevent_req *subreq;
    1353             :                 char *sub_base;
    1354             : 
    1355          12 :                 sub_base = talloc_asprintf(state, "%s-%u", base_name, i);
    1356          12 :                 if (tevent_req_nomem(sub_base, req)) {
    1357           0 :                         return tevent_req_post(req, ev);
    1358             :                 }
    1359             : 
    1360          12 :                 subreq = rename_dir_bench_send(state, ev, tree, sub_base,
    1361             :                                                max_renames, rename_counter);
    1362          12 :                 if (tevent_req_nomem(subreq, req)) {
    1363           0 :                         return tevent_req_post(req, ev);
    1364             :                 }
    1365          12 :                 tevent_req_set_callback(subreq, rename_dirs_bench_done, req);
    1366             :         }
    1367           4 :         return req;
    1368             : }
    1369             : 
    1370          12 : static void rename_dirs_bench_done(struct tevent_req *subreq)
    1371             : {
    1372          12 :         struct tevent_req *req = tevent_req_callback_data(
    1373             :                 subreq, struct tevent_req);
    1374          12 :         struct rename_dirs_bench_state *state = tevent_req_data(
    1375             :                 req, struct rename_dirs_bench_state);
    1376             :         NTSTATUS status;
    1377             : 
    1378          12 :         status = rename_dir_bench_recv(subreq);
    1379          12 :         TALLOC_FREE(subreq);
    1380          12 :         if (tevent_req_nterror(req, status)) {
    1381           0 :                 return;
    1382             :         }
    1383             : 
    1384          12 :         state->num_done += 1;
    1385          12 :         if (state->num_done >= state->num_reqs) {
    1386           4 :                 tevent_req_done(req);
    1387             :         }
    1388             : }
    1389             : 
    1390           4 : static NTSTATUS rename_dirs_bench_recv(struct tevent_req *req)
    1391             : {
    1392           4 :         return tevent_req_simple_recv_ntstatus(req);
    1393             : }
    1394             : 
    1395           4 : static bool torture_smb2_rename_dir_bench(struct torture_context *tctx,
    1396             :                                           struct smb2_tree *tree)
    1397             : {
    1398             :         struct tevent_req *req;
    1399             :         NTSTATUS status;
    1400           4 :         unsigned counter = 0;
    1401             :         bool ret;
    1402             : 
    1403           4 :         req = rename_dirs_bench_send(tctx, tctx->ev, tree, "dir", 3, 10,
    1404             :                                      &counter);
    1405           4 :         torture_assert(tctx, req != NULL, "rename_dirs_bench_send failed");
    1406             : 
    1407           4 :         ret = tevent_req_poll(req, tctx->ev);
    1408           4 :         torture_assert(tctx, ret, "tevent_req_poll failed");
    1409             : 
    1410           4 :         status = rename_dirs_bench_recv(req);
    1411           4 :         torture_comment(tctx, "rename_dirs_bench returned %s\n",
    1412             :                         nt_errstr(status));
    1413           4 :         TALLOC_FREE(req);
    1414           4 :         torture_assert_ntstatus_ok(tctx, status, "bench failed");
    1415           4 :         return true;
    1416             : }
    1417             : 
    1418             : 
    1419             : /*
    1420             :    basic testing of SMB2 rename
    1421             :  */
    1422        2353 : struct torture_suite *torture_smb2_rename_init(TALLOC_CTX *ctx)
    1423             : {
    1424        2353 :         struct torture_suite *suite =
    1425             :                 torture_suite_create(ctx, "rename");
    1426             : 
    1427        2353 :         torture_suite_add_1smb2_test(suite, "simple",
    1428             :                 torture_smb2_rename_simple);
    1429             : 
    1430        2353 :         torture_suite_add_1smb2_test(suite, "simple_nodelete",
    1431             :                 torture_smb2_rename_simple2);
    1432             : 
    1433        2353 :         torture_suite_add_1smb2_test(suite, "no_sharing",
    1434             :                 torture_smb2_rename_no_sharemode);
    1435             : 
    1436        2353 :         torture_suite_add_1smb2_test(suite,
    1437             :                 "share_delete_and_delete_access",
    1438             :                 torture_smb2_rename_with_delete_access);
    1439             : 
    1440        2353 :         torture_suite_add_1smb2_test(suite,
    1441             :                 "no_share_delete_but_delete_access",
    1442             :                 torture_smb2_rename_with_delete_access2);
    1443             : 
    1444        2353 :         torture_suite_add_1smb2_test(suite,
    1445             :                 "share_delete_no_delete_access",
    1446             :                 torture_smb2_rename_no_delete_access);
    1447             : 
    1448        2353 :         torture_suite_add_1smb2_test(suite,
    1449             :                 "no_share_delete_no_delete_access",
    1450             :                 torture_smb2_rename_no_delete_access2);
    1451             : 
    1452        2353 :         torture_suite_add_1smb2_test(suite,
    1453             :                 "msword",
    1454             :                 torture_smb2_rename_msword);
    1455             : 
    1456        2353 :         torture_suite_add_1smb2_test(
    1457             :                 suite, "rename_dir_openfile",
    1458             :                 torture_smb2_rename_dir_openfile);
    1459             : 
    1460        2353 :         torture_suite_add_1smb2_test(suite,
    1461             :                 "rename_dir_bench",
    1462             :                 torture_smb2_rename_dir_bench);
    1463             : 
    1464        2353 :         suite->description = talloc_strdup(suite, "smb2.rename tests");
    1465             : 
    1466        2353 :         return suite;
    1467             : }

Generated by: LCOV version 1.13