LCOV - code coverage report
Current view: top level - source4/torture/smb2 - mkdir.c (source / functions) Hit Total Coverage
Test: coverage report for master 2f515e9b Lines: 33 34 97.1 %
Date: 2024-04-21 15:09:00 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             :    RAW_MKDIR_* and RAW_RMDIR_* individual test suite
       4             :    Copyright (C) Andrew Tridgell 2003
       5             :    Copyright (C) David Mulder 2020
       6             : 
       7             :    This program is free software; you can redistribute it and/or modify
       8             :    it under the terms of the GNU General Public License as published by
       9             :    the Free Software Foundation; either version 3 of the License, or
      10             :    (at your option) any later version.
      11             : 
      12             :    This program is distributed in the hope that it will be useful,
      13             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      14             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15             :    GNU General Public License for more details.
      16             : 
      17             :    You should have received a copy of the GNU General Public License
      18             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      19             : */
      20             : 
      21             : #include "includes.h"
      22             : #include "libcli/smb2/smb2.h"
      23             : #include "libcli/smb2/smb2_calls.h"
      24             : #include "torture/util.h"
      25             : #include "torture/smb2/proto.h"
      26             : #include "libcli/smb_composite/smb_composite.h"
      27             : 
      28             : #define BASEDIR "mkdirtest"
      29             : 
      30             : /*
      31             :   test mkdir ops
      32             : */
      33           4 : bool torture_smb2_mkdir(struct torture_context *tctx, struct smb2_tree *tree)
      34             : {
      35           4 :         struct smb2_handle h = {{0}};
      36           4 :         const char *path = BASEDIR "\\mkdir.dir";
      37           0 :         NTSTATUS status;
      38           4 :         bool ret = true;
      39             : 
      40           4 :         ret = smb2_util_setup_dir(tctx, tree, BASEDIR);
      41           4 :         torture_assert(tctx, ret, "Failed to setup up test directory: " BASEDIR);
      42             : 
      43             :         /*
      44             :            basic mkdir
      45             :         */
      46           4 :         status = smb2_util_mkdir(tree, path);
      47           4 :         torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
      48             :                                         "Incorrect status");
      49             : 
      50           4 :         torture_comment(tctx, "Testing mkdir collision\n");
      51             : 
      52             :         /* 2nd create */
      53           4 :         status = smb2_util_mkdir(tree, path);
      54           4 :         torture_assert_ntstatus_equal_goto(tctx, status,
      55             :                                            NT_STATUS_OBJECT_NAME_COLLISION,
      56             :                                            ret, done, "Incorrect status");
      57             : 
      58             :         /* basic rmdir */
      59           4 :         status = smb2_util_rmdir(tree, path);
      60           4 :         torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
      61             :                                         "Incorrect status");
      62             : 
      63           4 :         status = smb2_util_rmdir(tree, path);
      64           4 :         torture_assert_ntstatus_equal_goto(tctx, status,
      65             :                                            NT_STATUS_OBJECT_NAME_NOT_FOUND,
      66             :                                            ret, done, "Incorrect status");
      67             : 
      68           4 :         torture_comment(tctx, "Testing mkdir collision with file\n");
      69             : 
      70             :         /* name collision with a file */
      71           4 :         smb2_create_complex_file(tctx, tree, path, &h);
      72           4 :         smb2_util_close(tree, h);
      73           4 :         status = smb2_util_mkdir(tree, path);
      74           4 :         torture_assert_ntstatus_equal_goto(tctx, status,
      75             :                                            NT_STATUS_OBJECT_NAME_COLLISION,
      76             :                                            ret, done, "Incorrect status");
      77             : 
      78           4 :         torture_comment(tctx, "Testing rmdir with file\n");
      79             : 
      80             :         /* delete a file with rmdir */
      81           4 :         status = smb2_util_rmdir(tree, path);
      82           4 :         torture_assert_ntstatus_equal_goto(tctx, status,
      83             :                                            NT_STATUS_NOT_A_DIRECTORY,
      84             :                                            ret, done, "Incorrect status");
      85             : 
      86           4 :         smb2_util_unlink(tree, path);
      87             : 
      88           4 :         torture_comment(tctx, "Testing invalid dir\n");
      89             : 
      90             :         /* create an invalid dir */
      91           4 :         status = smb2_util_mkdir(tree, "..\\..\\..");
      92           4 :         torture_assert_ntstatus_equal_goto(tctx, status,
      93             :                                            NT_STATUS_OBJECT_PATH_SYNTAX_BAD,
      94             :                                            ret, done, "Incorrect status");
      95             : 
      96           4 :         torture_comment(tctx, "Testing t2mkdir bad path\n");
      97           4 :         status = smb2_util_mkdir(tree, BASEDIR "\\bad_path\\bad_path");
      98           4 :         torture_assert_ntstatus_equal_goto(tctx, status,
      99             :                                            NT_STATUS_OBJECT_PATH_NOT_FOUND,
     100             :                                            ret, done, "Incorrect status");
     101             : 
     102           4 : done:
     103           4 :         smb2_deltree(tree, BASEDIR);
     104           4 :         return ret;
     105             : }

Generated by: LCOV version 1.14