LCOV - code coverage report
Current view: top level - source4/torture/basic - unlink.c (source / functions) Hit Total Coverage
Test: coverage report for v4-17-test 1498b464 Lines: 33 33 100.0 %
Date: 2024-06-13 04:01:37 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /* 
       2             :    Unix SMB/CIFS implementation.
       3             : 
       4             :    unlink tester
       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 "system/filesys.h"
      24             : #include "libcli/libcli.h"
      25             : #include "torture/util.h"
      26             : #include "torture/basic/proto.h"
      27             : 
      28             : #define BASEDIR "\\unlinktest"
      29             : 
      30             : /*
      31             :   This test checks that 
      32             : 
      33             :   1) the server does not allow an unlink on a file that is open
      34             : */
      35           5 : bool torture_unlinktest(struct torture_context *tctx, struct smbcli_state *cli)
      36             : {
      37           5 :         const char *fname = BASEDIR "\\unlink.tst";
      38             :         int fnum;
      39           5 :         bool correct = true;
      40             :         union smb_open io;
      41             :         NTSTATUS status;
      42             : 
      43           5 :         torture_assert(tctx, torture_setup_dir(cli, BASEDIR), 
      44             :                                    talloc_asprintf(tctx, "Failed setting up %s", BASEDIR));
      45             : 
      46           5 :         cli->session->pid = 1;
      47             : 
      48           5 :         torture_comment(tctx, "Opening a file\n");
      49             : 
      50           5 :         fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
      51           5 :         torture_assert(tctx, fnum != -1, talloc_asprintf(tctx, "open of %s failed (%s)", fname, smbcli_errstr(cli->tree)));
      52             : 
      53           5 :         torture_comment(tctx, "Unlinking a open file\n");
      54             : 
      55           5 :         torture_assert(tctx, !NT_STATUS_IS_OK(smbcli_unlink(cli->tree, fname)),
      56             :                 "server allowed unlink on an open file");
      57             :         
      58           5 :         correct = check_error(__location__, cli, ERRDOS, ERRbadshare, 
      59           5 :                                       NT_STATUS_SHARING_VIOLATION);
      60             : 
      61           5 :         smbcli_close(cli->tree, fnum);
      62           5 :         smbcli_unlink(cli->tree, fname);
      63             : 
      64           5 :         torture_comment(tctx, "Testing unlink after ntcreatex with DELETE access\n");
      65             : 
      66           5 :         io.ntcreatex.level = RAW_OPEN_NTCREATEX;
      67           5 :         io.ntcreatex.in.root_fid.fnum = 0;
      68           5 :         io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
      69           5 :         io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_NON_DIRECTORY_FILE;
      70           5 :         io.ntcreatex.in.file_attr = 0;
      71           5 :         io.ntcreatex.in.alloc_size = 0;
      72           5 :         io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
      73           5 :         io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_IMPERSONATION;
      74           5 :         io.ntcreatex.in.security_flags = 0;
      75           5 :         io.ntcreatex.in.fname = fname;
      76           5 :         io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_DELETE;
      77           5 :         io.ntcreatex.in.access_mask  = SEC_RIGHTS_FILE_ALL;
      78             : 
      79           5 :         status = smb_raw_open(cli->tree, cli, &io);
      80           5 :         torture_assert_ntstatus_ok(tctx, status, talloc_asprintf(tctx, "failed to open %s", fname));
      81             : 
      82           5 :         torture_assert(tctx, !NT_STATUS_IS_OK(smbcli_unlink(cli->tree, fname)),
      83             :                 "server allowed unlink on an open file");
      84             : 
      85           5 :         correct = check_error(__location__, cli, ERRDOS, ERRbadshare, 
      86           5 :                                       NT_STATUS_SHARING_VIOLATION);
      87             : 
      88           5 :         return correct;
      89             : }
      90             : 
      91             : 

Generated by: LCOV version 1.13