LCOV - code coverage report
Current view: top level - source4/torture/basic - rename.c (source / functions) Hit Total Coverage
Test: coverage report for master 2b515b7d Lines: 24 25 96.0 %
Date: 2024-02-28 12:06:22 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /* 
       2             :    Unix SMB/CIFS implementation.
       3             : 
       4             :    rename testing
       5             : 
       6             :    Copyright (C) Andrew Tridgell 2003
       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/libcli.h"
      24             : #include "torture/util.h"
      25             : #include "torture/basic/proto.h"
      26             : 
      27             : /*
      28             :   Test rename on files open with share delete and no share delete.
      29             :  */
      30           6 : bool torture_test_rename(struct torture_context *tctx, 
      31             :                          struct smbcli_state *cli1)
      32             : {
      33           6 :         const char *fname = "\\test.txt";
      34           6 :         const char *fname1 = "\\test1.txt";
      35           0 :         int fnum1;
      36             : 
      37           6 :         smbcli_unlink(cli1->tree, fname);
      38           6 :         smbcli_unlink(cli1->tree, fname1);
      39           6 :         fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, 
      40             :                                       SEC_RIGHTS_FILE_READ, 
      41             :                                       FILE_ATTRIBUTE_NORMAL,
      42             :                                       NTCREATEX_SHARE_ACCESS_READ, 
      43             :                                       NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
      44             : 
      45           6 :         torture_assert(tctx, fnum1 != -1, talloc_asprintf(tctx, "First open failed - %s", 
      46             :                        smbcli_errstr(cli1->tree)));
      47             : 
      48           6 :         torture_assert(tctx, NT_STATUS_IS_ERR(smbcli_rename(cli1->tree, fname, fname1)), 
      49             :                                         "First rename succeeded - this should have failed !");
      50             : 
      51           6 :         torture_assert_ntstatus_ok(tctx, smbcli_close(cli1->tree, fnum1),
      52             :                 talloc_asprintf(tctx, "close - 1 failed (%s)", smbcli_errstr(cli1->tree)));
      53             : 
      54           6 :         smbcli_unlink(cli1->tree, fname);
      55           6 :         smbcli_unlink(cli1->tree, fname1);
      56           6 :         fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, 
      57             :                                       SEC_RIGHTS_FILE_READ, 
      58             :                                       FILE_ATTRIBUTE_NORMAL,
      59             :                                       NTCREATEX_SHARE_ACCESS_DELETE|NTCREATEX_SHARE_ACCESS_READ, 
      60             :                                       NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
      61             : 
      62           6 :         torture_assert(tctx, fnum1 != -1, talloc_asprintf(tctx, 
      63             :                                    "Second open failed - %s", smbcli_errstr(cli1->tree)));
      64             : 
      65           6 :         torture_assert_ntstatus_ok(tctx, smbcli_rename(cli1->tree, fname, fname1),
      66             :                 talloc_asprintf(tctx, 
      67             :                                 "Second rename failed - this should have succeeded - %s", 
      68             :                        smbcli_errstr(cli1->tree)));
      69             : 
      70           6 :         torture_assert_ntstatus_ok(tctx, smbcli_close(cli1->tree, fnum1),
      71             :                 talloc_asprintf(tctx, 
      72             :                 "close - 2 failed (%s)", smbcli_errstr(cli1->tree)));
      73             : 
      74           6 :         smbcli_unlink(cli1->tree, fname);
      75           6 :         smbcli_unlink(cli1->tree, fname1);
      76             : 
      77           6 :         fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, 
      78             :                                       SEC_STD_READ_CONTROL, 
      79             :                                       FILE_ATTRIBUTE_NORMAL,
      80             :                                       NTCREATEX_SHARE_ACCESS_NONE, 
      81             :                                       NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
      82             : 
      83           6 :         torture_assert(tctx, fnum1 != -1, talloc_asprintf(tctx, "Third open failed - %s", 
      84             :                         smbcli_errstr(cli1->tree)));
      85             : 
      86           6 :         torture_assert_ntstatus_ok(tctx, smbcli_rename(cli1->tree, fname, fname1),
      87             :                 talloc_asprintf(tctx, "Third rename failed - this should have succeeded - %s", 
      88             :                        smbcli_errstr(cli1->tree)));
      89             : 
      90           6 :         torture_assert_ntstatus_ok(tctx, smbcli_close(cli1->tree, fnum1), 
      91             :                 talloc_asprintf(tctx, "close - 3 failed (%s)", smbcli_errstr(cli1->tree)));
      92             : 
      93           6 :         smbcli_unlink(cli1->tree, fname);
      94           6 :         smbcli_unlink(cli1->tree, fname1);
      95             : 
      96           6 :         return true;
      97             : }
      98             : 

Generated by: LCOV version 1.14