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

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             : 
       4             :    SMB2 setinfo individual test suite
       5             : 
       6             :    Copyright (C) Ralph Boehme 2016
       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/time.h"
      24             : #include "libcli/smb2/smb2.h"
      25             : #include "libcli/smb2/smb2_calls.h"
      26             : 
      27             : #include "torture/torture.h"
      28             : #include "torture/smb2/proto.h"
      29             : 
      30             : /*
      31             :   test dosmode and hidden files
      32             : */
      33           2 : bool torture_smb2_dosmode(struct torture_context *tctx)
      34             : {
      35           2 :         bool ret = true;
      36           0 :         NTSTATUS status;
      37           2 :         struct smb2_tree *tree = NULL;
      38           2 :         const char *dname = "torture_dosmode";
      39           2 :         const char *fname = "torture_dosmode\\file";
      40           2 :         const char *hidefile = "torture_dosmode\\hidefile";
      41           2 :         const char *dotfile = "torture_dosmode\\.dotfile";
      42           2 :         struct smb2_handle h1 = {{0}};
      43           0 :         struct smb2_create io;
      44           0 :         union smb_setfileinfo sfinfo;
      45           0 :         union smb_fileinfo finfo2;
      46             : 
      47           2 :         torture_comment(tctx, "Checking dosmode with \"hide files\" "
      48             :                         "and \"hide dot files\"\n");
      49             : 
      50           2 :         if (!torture_smb2_connection(tctx, &tree)) {
      51           0 :                 return false;
      52             :         }
      53             : 
      54           2 :         smb2_deltree(tree, dname);
      55             : 
      56           2 :         status = torture_smb2_testdir(tree, dname, &h1);
      57           2 :         torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
      58             :                                         "torture_smb2_testdir failed");
      59             : 
      60           2 :         ZERO_STRUCT(io);
      61           2 :         io.in.desired_access = SEC_FLAG_MAXIMUM_ALLOWED;
      62           2 :         io.in.file_attributes   = FILE_ATTRIBUTE_NORMAL;
      63           2 :         io.in.create_disposition = NTCREATEX_DISP_CREATE;
      64           2 :         io.in.create_options = 0;
      65           2 :         io.in.fname = fname;
      66             : 
      67           2 :         status = smb2_create(tree, tctx, &io);
      68           2 :         torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
      69             :                                         "smb2_create failed");
      70             : 
      71           2 :         ZERO_STRUCT(sfinfo);
      72           2 :         sfinfo.basic_info.in.attrib = FILE_ATTRIBUTE_HIDDEN;
      73           2 :         sfinfo.generic.level = RAW_SFILEINFO_BASIC_INFORMATION;
      74           2 :         sfinfo.generic.in.file.handle = io.out.file.handle;
      75           2 :         status = smb2_setinfo_file(tree, &sfinfo);
      76           2 :         torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
      77             :                                         "smb2_setinfo_filefailed");
      78             : 
      79           2 :         ZERO_STRUCT(finfo2);
      80           2 :         finfo2.generic.level = RAW_FILEINFO_BASIC_INFORMATION;
      81           2 :         finfo2.generic.in.file.handle = io.out.file.handle;
      82           2 :         status = smb2_getinfo_file(tree, tctx, &finfo2);
      83           2 :         torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
      84             :                                         "smb2_getinfo_file failed");
      85           2 :         torture_assert_int_equal_goto(tctx, finfo2.all_info2.out.attrib & FILE_ATTRIBUTE_HIDDEN,
      86             :                                       FILE_ATTRIBUTE_HIDDEN, ret, done,
      87             :                                       "FILE_ATTRIBUTE_HIDDEN is not set");
      88             : 
      89           2 :         smb2_util_close(tree, io.out.file.handle);
      90             : 
      91             :         /* This must fail with attribute mismatch */
      92           2 :         ZERO_STRUCT(io);
      93           2 :         io.in.desired_access = SEC_FLAG_MAXIMUM_ALLOWED;
      94           2 :         io.in.file_attributes   = FILE_ATTRIBUTE_NORMAL;
      95           2 :         io.in.create_disposition = NTCREATEX_DISP_OVERWRITE_IF;
      96           2 :         io.in.create_options = 0;
      97           2 :         io.in.fname = fname;
      98             : 
      99           2 :         status = smb2_create(tree, tctx, &io);
     100           2 :         torture_assert_ntstatus_equal_goto(tctx, status, NT_STATUS_ACCESS_DENIED,
     101             :                                            ret, done,"smb2_create failed");
     102             : 
     103             :         /* Create a file in "hide files" */
     104           2 :         ZERO_STRUCT(io);
     105           2 :         io.in.desired_access = SEC_FLAG_MAXIMUM_ALLOWED;
     106           2 :         io.in.file_attributes   = FILE_ATTRIBUTE_NORMAL;
     107           2 :         io.in.create_disposition = NTCREATEX_DISP_CREATE;
     108           2 :         io.in.create_options = 0;
     109           2 :         io.in.fname = hidefile;
     110             : 
     111           2 :         status = smb2_create(tree, tctx, &io);
     112           2 :         torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
     113             :                                         "smb2_create failed");
     114             : 
     115           2 :         ZERO_STRUCT(finfo2);
     116           2 :         finfo2.generic.level = RAW_FILEINFO_BASIC_INFORMATION;
     117           2 :         finfo2.generic.in.file.handle = io.out.file.handle;
     118           2 :         status = smb2_getinfo_file(tree, tctx, &finfo2);
     119           2 :         torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
     120             :                                         "smb2_getinfo_file failed");
     121           2 :         torture_assert_int_equal_goto(tctx, finfo2.all_info2.out.attrib & FILE_ATTRIBUTE_HIDDEN,
     122             :                                       FILE_ATTRIBUTE_HIDDEN, ret, done,
     123             :                                       "FILE_ATTRIBUTE_HIDDEN is not set");
     124             : 
     125           2 :         smb2_util_close(tree, io.out.file.handle);
     126             : 
     127             :         /* Overwrite a file in "hide files", should pass */
     128           2 :         ZERO_STRUCT(io);
     129           2 :         io.in.desired_access = SEC_FLAG_MAXIMUM_ALLOWED;
     130           2 :         io.in.file_attributes   = FILE_ATTRIBUTE_NORMAL;
     131           2 :         io.in.create_disposition = NTCREATEX_DISP_OVERWRITE_IF;
     132           2 :         io.in.create_options = 0;
     133           2 :         io.in.fname = hidefile;
     134             : 
     135           2 :         status = smb2_create(tree, tctx, &io);
     136           2 :         torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
     137             :                                         "smb2_create failed");
     138           2 :         smb2_util_close(tree, io.out.file.handle);
     139             : 
     140             :         /* Create a "hide dot files" */
     141           2 :         ZERO_STRUCT(io);
     142           2 :         io.in.desired_access = SEC_FLAG_MAXIMUM_ALLOWED;
     143           2 :         io.in.file_attributes   = FILE_ATTRIBUTE_NORMAL;
     144           2 :         io.in.create_disposition = NTCREATEX_DISP_CREATE;
     145           2 :         io.in.create_options = 0;
     146           2 :         io.in.fname = dotfile;
     147             : 
     148           2 :         status = smb2_create(tree, tctx, &io);
     149           2 :         torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
     150             :                                         "smb2_create failed");
     151             : 
     152           2 :         ZERO_STRUCT(finfo2);
     153           2 :         finfo2.generic.level = RAW_FILEINFO_BASIC_INFORMATION;
     154           2 :         finfo2.generic.in.file.handle = io.out.file.handle;
     155           2 :         status = smb2_getinfo_file(tree, tctx, &finfo2);
     156           2 :         torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
     157             :                                         "smb2_getinfo_file failed");
     158           2 :         torture_assert_int_equal_goto(tctx, finfo2.all_info2.out.attrib & FILE_ATTRIBUTE_HIDDEN,
     159             :                                       FILE_ATTRIBUTE_HIDDEN, ret, done,
     160             :                                       "FILE_ATTRIBUTE_HIDDEN is not set");
     161             : 
     162           2 :         smb2_util_close(tree, io.out.file.handle);
     163             : 
     164             :         /* Overwrite a "hide dot files", should pass */
     165           2 :         ZERO_STRUCT(io);
     166           2 :         io.in.desired_access = SEC_FLAG_MAXIMUM_ALLOWED;
     167           2 :         io.in.file_attributes   = FILE_ATTRIBUTE_NORMAL;
     168           2 :         io.in.create_disposition = NTCREATEX_DISP_OVERWRITE_IF;
     169           2 :         io.in.create_options = 0;
     170           2 :         io.in.fname = dotfile;
     171             : 
     172           2 :         status = smb2_create(tree, tctx, &io);
     173           2 :         torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
     174             :                                         "smb2_create failed");
     175           2 :         smb2_util_close(tree, io.out.file.handle);
     176             : 
     177           2 : done:
     178           2 :         if (!smb2_util_handle_empty(h1)) {
     179           2 :                 smb2_util_close(tree, h1);
     180             :         }
     181           2 :         smb2_deltree(tree, dname);
     182           2 :         return ret;
     183             : }
     184             : 
     185           2 : bool torture_smb2_async_dosmode(struct torture_context *tctx)
     186             : {
     187           2 :         bool ret = true;
     188           0 :         NTSTATUS status;
     189           2 :         struct smb2_tree *tree = NULL;
     190           2 :         const char *dname = "torture_dosmode";
     191           2 :         const char *fname = "torture_dosmode\\file";
     192           2 :         struct smb2_handle h = {{0}};
     193           0 :         struct smb2_create io;
     194           0 :         union smb_setfileinfo sfinfo;
     195           0 :         struct smb2_find f;
     196           0 :         union smb_search_data *d;
     197           0 :         unsigned int count;
     198             : 
     199           2 :         if (!torture_smb2_connection(tctx, &tree)) {
     200           0 :                 return false;
     201             :         }
     202             : 
     203           2 :         smb2_deltree(tree, dname);
     204             : 
     205           2 :         status = torture_smb2_testdir(tree, dname, &h);
     206           2 :         torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
     207             :                                         "torture_smb2_testdir failed");
     208             : 
     209           2 :         ZERO_STRUCT(io);
     210           2 :         io.in.desired_access = SEC_FLAG_MAXIMUM_ALLOWED;
     211           2 :         io.in.file_attributes   = FILE_ATTRIBUTE_NORMAL;
     212           2 :         io.in.create_disposition = NTCREATEX_DISP_CREATE;
     213           2 :         io.in.create_options = 0;
     214           2 :         io.in.fname = fname;
     215             : 
     216           2 :         status = smb2_create(tree, tctx, &io);
     217           2 :         torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
     218             :                                         "smb2_create failed");
     219             : 
     220           2 :         ZERO_STRUCT(sfinfo);
     221           2 :         sfinfo.basic_info.in.attrib = FILE_ATTRIBUTE_HIDDEN;
     222           2 :         sfinfo.generic.level = RAW_SFILEINFO_BASIC_INFORMATION;
     223           2 :         sfinfo.generic.in.file.handle = io.out.file.handle;
     224           2 :         status = smb2_setinfo_file(tree, &sfinfo);
     225           2 :         torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
     226             :                                         "smb2_setinfo_filefailed");
     227             : 
     228           2 :         smb2_util_close(tree, io.out.file.handle);
     229             : 
     230           2 :         ZERO_STRUCT(f);
     231           2 :         f.in.file.handle        = h;
     232           2 :         f.in.pattern            = "file";
     233           2 :         f.in.continue_flags     = SMB2_CONTINUE_FLAG_RESTART;
     234           2 :         f.in.max_response_size  = 0x1000;
     235           2 :         f.in.level              = SMB2_FIND_BOTH_DIRECTORY_INFO;
     236             : 
     237           2 :         status = smb2_find_level(tree, tree, &f, &count, &d);
     238           2 :         torture_assert_ntstatus_ok_goto(tctx, status, ret, done, "");
     239             : 
     240           2 :         smb2_util_close(tree, h);
     241           2 :         ZERO_STRUCT(h);
     242             : 
     243           2 :         torture_assert_goto(tctx,
     244             :                             d->both_directory_info.attrib & FILE_ATTRIBUTE_HIDDEN,
     245             :                             ret, done,
     246             :                             "FILE_ATTRIBUTE_HIDDEN is not set\n");
     247             : 
     248           2 : done:
     249           2 :         if (!smb2_util_handle_empty(h)) {
     250           0 :                 smb2_util_close(tree, h);
     251             :         }
     252           2 :         smb2_deltree(tree, dname);
     253           2 :         return ret;
     254             : }

Generated by: LCOV version 1.14