LCOV - code coverage report
Current view: top level - source4/torture/raw - mkdir.c (source / functions) Hit Total Coverage
Test: coverage report for master 2f515e9b Lines: 77 79 97.5 %
Date: 2024-04-21 15:09:00 Functions: 2 2 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             :    
       6             :    This program is free software; you can redistribute it and/or modify
       7             :    it under the terms of the GNU General Public License as published by
       8             :    the Free Software Foundation; either version 3 of the License, or
       9             :    (at your option) any later version.
      10             :    
      11             :    This program is distributed in the hope that it will be useful,
      12             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14             :    GNU General Public License for more details.
      15             :    
      16             :    You should have received a copy of the GNU General Public License
      17             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      18             : */
      19             : 
      20             : #include "includes.h"
      21             : #include "libcli/raw/libcliraw.h"
      22             : #include "libcli/libcli.h"
      23             : #include "torture/util.h"
      24             : #include "torture/raw/proto.h"
      25             : 
      26             : #define BASEDIR "\\mkdirtest"
      27             : 
      28             : #define CHECK_STATUS(status, correct) do { \
      29             :         if (!NT_STATUS_EQUAL(status, correct)) { \
      30             :                 printf("(%s) Incorrect status %s - should be %s\n", \
      31             :                        __location__, nt_errstr(status), nt_errstr(correct)); \
      32             :                 ret = false; \
      33             :                 goto done; \
      34             :         }} while (0)
      35             : 
      36             : /*
      37             :   test mkdir ops
      38             : */
      39           6 : static bool test_mkdir(struct smbcli_state *cli, struct torture_context *tctx)
      40             : {
      41           1 :         union smb_mkdir md;
      42           1 :         struct smb_rmdir rd;
      43           6 :         const char *path = BASEDIR "\\mkdir.dir";
      44           1 :         NTSTATUS status;
      45           6 :         bool ret = true;
      46             : 
      47           6 :         torture_assert(tctx, torture_setup_dir(cli, BASEDIR), "Failed to setup up test directory: " BASEDIR);
      48             : 
      49             :         /* 
      50             :            basic mkdir
      51             :         */
      52           6 :         md.mkdir.level = RAW_MKDIR_MKDIR;
      53           6 :         md.mkdir.in.path = path;
      54             : 
      55           6 :         status = smb_raw_mkdir(cli->tree, &md);
      56           6 :         CHECK_STATUS(status, NT_STATUS_OK);
      57             : 
      58           6 :         printf("Testing mkdir collision\n");
      59             : 
      60             :         /* 2nd create */
      61           6 :         status = smb_raw_mkdir(cli->tree, &md);
      62           6 :         CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_COLLISION);
      63             : 
      64             :         /* basic rmdir */
      65           6 :         rd.in.path = path;
      66           6 :         status = smb_raw_rmdir(cli->tree, &rd);
      67           6 :         CHECK_STATUS(status, NT_STATUS_OK);
      68             : 
      69           6 :         status = smb_raw_rmdir(cli->tree, &rd);
      70           6 :         CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
      71             : 
      72           6 :         printf("Testing mkdir collision with file\n");
      73             : 
      74             :         /* name collision with a file */
      75           6 :         smbcli_close(cli->tree, create_complex_file(cli, tctx, path));
      76           6 :         status = smb_raw_mkdir(cli->tree, &md);
      77           6 :         CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_COLLISION);
      78             : 
      79           6 :         printf("Testing rmdir with file\n");
      80             : 
      81             :         /* delete a file with rmdir */
      82           6 :         status = smb_raw_rmdir(cli->tree, &rd);
      83           6 :         CHECK_STATUS(status, NT_STATUS_NOT_A_DIRECTORY);
      84             : 
      85           6 :         smbcli_unlink(cli->tree, path);
      86             : 
      87           6 :         printf("Testing invalid dir\n");
      88             : 
      89             :         /* create an invalid dir */
      90           6 :         md.mkdir.in.path = "..\\..\\..";
      91           6 :         status = smb_raw_mkdir(cli->tree, &md);
      92           6 :         CHECK_STATUS(status, NT_STATUS_OBJECT_PATH_SYNTAX_BAD);
      93             :         
      94           6 :         printf("Testing t2mkdir\n");
      95             : 
      96             :         /* try a t2mkdir - need to work out why this fails! */
      97           6 :         md.t2mkdir.level = RAW_MKDIR_T2MKDIR;
      98           6 :         md.t2mkdir.in.path = path;
      99           6 :         md.t2mkdir.in.num_eas = 0;      
     100           6 :         status = smb_raw_mkdir(cli->tree, &md);
     101           6 :         CHECK_STATUS(status, NT_STATUS_OK);
     102             : 
     103           6 :         status = smb_raw_rmdir(cli->tree, &rd);
     104           6 :         CHECK_STATUS(status, NT_STATUS_OK);
     105             : 
     106           6 :         printf("Testing t2mkdir bad path\n");
     107           6 :         md.t2mkdir.in.path = talloc_asprintf(tctx, "%s\\bad_path\\bad_path",
     108             :                                              BASEDIR);
     109           6 :         status = smb_raw_mkdir(cli->tree, &md);
     110           6 :         CHECK_STATUS(status, NT_STATUS_OBJECT_PATH_NOT_FOUND);
     111             : 
     112           6 :         printf("Testing t2mkdir with EAs\n");
     113             : 
     114             :         /* with EAs */
     115           6 :         md.t2mkdir.level = RAW_MKDIR_T2MKDIR;
     116           6 :         md.t2mkdir.in.path = path;
     117           6 :         md.t2mkdir.in.num_eas = 3;
     118           6 :         md.t2mkdir.in.eas = talloc_array(tctx, struct ea_struct, md.t2mkdir.in.num_eas);
     119           6 :         md.t2mkdir.in.eas[0].flags = 0;
     120           6 :         md.t2mkdir.in.eas[0].name.s = "EAONE";
     121           6 :         md.t2mkdir.in.eas[0].value = data_blob_talloc(tctx, "blah", 4);
     122           6 :         md.t2mkdir.in.eas[1].flags = 0;
     123           6 :         md.t2mkdir.in.eas[1].name.s = "EA TWO";
     124           6 :         md.t2mkdir.in.eas[1].value = data_blob_talloc(tctx, "foo bar", 7);
     125           6 :         md.t2mkdir.in.eas[2].flags = 0;
     126           6 :         md.t2mkdir.in.eas[2].name.s = "EATHREE";
     127           6 :         md.t2mkdir.in.eas[2].value = data_blob_talloc(tctx, "xx1", 3);
     128           6 :         status = smb_raw_mkdir(cli->tree, &md);
     129             : 
     130           6 :         if (torture_setting_bool(tctx, "samba3", false)
     131           5 :             && NT_STATUS_EQUAL(status, NT_STATUS_EAS_NOT_SUPPORTED)) {
     132           0 :                 d_printf("EAS not supported -- not treating as fatal\n");
     133             :         }
     134             :         else {
     135             :                 /*
     136             :                  * In Samba3, don't see this error as fatal
     137             :                  */
     138           6 :                 CHECK_STATUS(status, NT_STATUS_OK);
     139             : 
     140           6 :                 status = torture_check_ea(cli, path, "EAONE", "blah");
     141           6 :                 CHECK_STATUS(status, NT_STATUS_OK);
     142           6 :                 status = torture_check_ea(cli, path, "EA TWO", "foo bar");
     143           6 :                 CHECK_STATUS(status, NT_STATUS_OK);
     144           6 :                 status = torture_check_ea(cli, path, "EATHREE", "xx1");
     145           6 :                 CHECK_STATUS(status, NT_STATUS_OK);
     146             : 
     147           6 :                 status = smb_raw_rmdir(cli->tree, &rd);
     148           6 :                 CHECK_STATUS(status, NT_STATUS_OK);
     149             :         }
     150             : 
     151           6 : done:
     152           6 :         smb_raw_exit(cli->session);
     153           6 :         smbcli_deltree(cli->tree, BASEDIR);
     154           6 :         return ret;
     155             : }
     156             : 
     157             : 
     158             : /* 
     159             :    basic testing of all RAW_MKDIR_* calls 
     160             : */
     161           6 : bool torture_raw_mkdir(struct torture_context *torture, 
     162             :                        struct smbcli_state *cli)
     163             : {
     164           6 :         bool ret = true;
     165             : 
     166           6 :         if (!test_mkdir(cli, torture)) {
     167           0 :                 ret = false;
     168             :         }
     169             : 
     170           6 :         return ret;
     171             : }

Generated by: LCOV version 1.14