s4/torture: add a test for dosmode and hidden files
authorRalph Boehme <slow@samba.org>
Thu, 23 Jun 2016 17:13:05 +0000 (19:13 +0200)
committerRalph Boehme <slow@samba.org>
Sat, 25 Jun 2016 16:47:17 +0000 (18:47 +0200)
Bug: https://bugzilla.samba.org/show_bug.cgi?id=11992

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
selftest/target/Samba3.pm
source3/selftest/tests.py
source4/selftest/tests.py
source4/torture/smb2/dosmode.c [new file with mode: 0644]
source4/torture/smb2/smb2.c
source4/torture/smb2/wscript_build

index 3f6fd1e866ca7c6c72a3ce40c103db8ccc976ee0..2ac953d89a8c48a9c053db5675b455a4f38668e0 100755 (executable)
@@ -555,6 +555,13 @@ sub setup_simpleserver($$)
         vfs objects = aio_fork
         read only = no
         vfs_aio_fork:erratic_testing_mode=yes
+
+[dosmode]
+       path = $prefix_abs/share
+       vfs objects =
+       store dos attributes = yes
+       hide files = /hidefile/
+       hide dot files = yes
 ";
 
        my $vars = $self->provision($path,
index cc635cdccd7c2b18f6843d4b5b1d0a80431894b5..371ec2abd3f55f23f3ec10266c77cd20d844144c 100755 (executable)
@@ -408,6 +408,8 @@ for t in tests:
     elif t == "smb2.notify":
         plansmbtorture4testsuite(t, "nt4_dc", '//$SERVER_IP/tmp -U$USERNAME%$PASSWORD --signing=required')
         plansmbtorture4testsuite(t, "ad_dc", '//$SERVER/tmp -U$USERNAME%$PASSWORD --signing=required')
+    elif t == "smb2.dosmode":
+        plansmbtorture4testsuite(t, "simpleserver", '//$SERVER/dosmode -U$USERNAME%$PASSWORD')
     else:
         plansmbtorture4testsuite(t, "nt4_dc", '//$SERVER_IP/tmp -U$USERNAME%$PASSWORD')
         plansmbtorture4testsuite(t, "ad_dc", '//$SERVER/tmp -U$USERNAME%$PASSWORD')
index 844b93c52d9c4006a4db1b697c1ff4f1f366c980..7372072a4b6deae0db593435b858c0f9574d9656 100755 (executable)
@@ -300,8 +300,9 @@ for t in nbt_tests:
 # Tests against the NTVFS POSIX backend
 ntvfsargs = ["--option=torture:sharedelay=100000", "--option=torture:oplocktimeout=3", "--option=torture:writetimeupdatedelay=500000"]
 
-# smb2.change_notify_disabled must only run against env fileserver-notify-disabled
-smb2 = filter(lambda x: "smb2.change_notify_disabled" not in x, smbtorture4_testsuites("smb2."))
+# Filter smb2 tests that should not run against ad_dc_ntvfs
+smb2_s3only = ["smb2.change_notify_disabled", "smb2.dosmode"]
+smb2 = [x for x in smbtorture4_testsuites("smb2.") if x not in smb2_s3only]
 
 #The QFILEINFO-IPC test needs to be on ipc$
 raw = filter(lambda x: "raw.qfileinfo.ipc" not in x, smbtorture4_testsuites("raw."))
diff --git a/source4/torture/smb2/dosmode.c b/source4/torture/smb2/dosmode.c
new file mode 100644 (file)
index 0000000..7808ca6
--- /dev/null
@@ -0,0 +1,183 @@
+/*
+   Unix SMB/CIFS implementation.
+
+   SMB2 setinfo individual test suite
+
+   Copyright (C) Ralph Boehme 2016
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "includes.h"
+#include "system/time.h"
+#include "libcli/smb2/smb2.h"
+#include "libcli/smb2/smb2_calls.h"
+
+#include "torture/torture.h"
+#include "torture/smb2/proto.h"
+
+/*
+  test dosmode and hidden files
+*/
+bool torture_smb2_dosmode(struct torture_context *tctx)
+{
+       bool ret = true;
+       NTSTATUS status;
+       struct smb2_tree *tree = NULL;
+       const char *dname = "torture_dosmode";
+       const char *fname = "torture_dosmode\\file";
+       const char *hidefile = "torture_dosmode\\hidefile";
+       const char *dotfile = "torture_dosmode\\.dotfile";
+       struct smb2_handle h1 = {{0}};
+       struct smb2_create io;
+       union smb_setfileinfo sfinfo;
+       union smb_fileinfo finfo2;
+
+       torture_comment(tctx, "Checking dosmode with \"hide files\" "
+                       "and \"hide dot files\"\n");
+
+       if (!torture_smb2_connection(tctx, &tree)) {
+               return false;
+       }
+
+       smb2_deltree(tree, dname);
+
+       status = torture_smb2_testdir(tree, dname, &h1);
+       torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
+                                       "torture_smb2_testdir failed");
+
+       ZERO_STRUCT(io);
+       io.in.desired_access = SEC_FLAG_MAXIMUM_ALLOWED;
+       io.in.file_attributes   = FILE_ATTRIBUTE_NORMAL;
+       io.in.create_disposition = NTCREATEX_DISP_CREATE;
+       io.in.create_options = 0;
+       io.in.fname = fname;
+
+       status = smb2_create(tree, tctx, &io);
+       torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
+                                       "smb2_create failed");
+
+       ZERO_STRUCT(sfinfo);
+       sfinfo.basic_info.in.attrib = FILE_ATTRIBUTE_HIDDEN;
+       sfinfo.generic.level = RAW_SFILEINFO_BASIC_INFORMATION;
+       sfinfo.generic.in.file.handle = io.out.file.handle;
+       status = smb2_setinfo_file(tree, &sfinfo);
+       torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
+                                       "smb2_setinfo_filefailed");
+
+       ZERO_STRUCT(finfo2);
+       finfo2.generic.level = RAW_FILEINFO_BASIC_INFORMATION;
+       finfo2.generic.in.file.handle = io.out.file.handle;
+       status = smb2_getinfo_file(tree, tctx, &finfo2);
+       torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
+                                       "smb2_getinfo_file failed");
+       torture_assert_int_equal_goto(tctx, finfo2.all_info2.out.attrib & FILE_ATTRIBUTE_HIDDEN,
+                                     FILE_ATTRIBUTE_HIDDEN, ret, done,
+                                     "FILE_ATTRIBUTE_HIDDEN is not set");
+
+       smb2_util_close(tree, io.out.file.handle);
+
+       /* This must fail with attribute mismatch */
+       ZERO_STRUCT(io);
+       io.in.desired_access = SEC_FLAG_MAXIMUM_ALLOWED;
+       io.in.file_attributes   = FILE_ATTRIBUTE_NORMAL;
+       io.in.create_disposition = NTCREATEX_DISP_OVERWRITE_IF;
+       io.in.create_options = 0;
+       io.in.fname = fname;
+
+       status = smb2_create(tree, tctx, &io);
+       torture_assert_ntstatus_equal_goto(tctx, status, NT_STATUS_ACCESS_DENIED,
+                                          ret, done,"smb2_create failed");
+
+       /* Create a file in "hide files" */
+       ZERO_STRUCT(io);
+       io.in.desired_access = SEC_FLAG_MAXIMUM_ALLOWED;
+       io.in.file_attributes   = FILE_ATTRIBUTE_NORMAL;
+       io.in.create_disposition = NTCREATEX_DISP_CREATE;
+       io.in.create_options = 0;
+       io.in.fname = hidefile;
+
+       status = smb2_create(tree, tctx, &io);
+       torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
+                                       "smb2_create failed");
+
+       ZERO_STRUCT(finfo2);
+       finfo2.generic.level = RAW_FILEINFO_BASIC_INFORMATION;
+       finfo2.generic.in.file.handle = io.out.file.handle;
+       status = smb2_getinfo_file(tree, tctx, &finfo2);
+       torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
+                                       "smb2_getinfo_file failed");
+       torture_assert_int_equal_goto(tctx, finfo2.all_info2.out.attrib & FILE_ATTRIBUTE_HIDDEN,
+                                     FILE_ATTRIBUTE_HIDDEN, ret, done,
+                                     "FILE_ATTRIBUTE_HIDDEN is not set");
+
+       smb2_util_close(tree, io.out.file.handle);
+
+       /* Overwrite a file in "hide files", should pass */
+       ZERO_STRUCT(io);
+       io.in.desired_access = SEC_FLAG_MAXIMUM_ALLOWED;
+       io.in.file_attributes   = FILE_ATTRIBUTE_NORMAL;
+       io.in.create_disposition = NTCREATEX_DISP_OVERWRITE_IF;
+       io.in.create_options = 0;
+       io.in.fname = hidefile;
+
+       status = smb2_create(tree, tctx, &io);
+       torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
+                                       "smb2_create failed");
+       smb2_util_close(tree, io.out.file.handle);
+
+       /* Create a "hide dot files" */
+       ZERO_STRUCT(io);
+       io.in.desired_access = SEC_FLAG_MAXIMUM_ALLOWED;
+       io.in.file_attributes   = FILE_ATTRIBUTE_NORMAL;
+       io.in.create_disposition = NTCREATEX_DISP_CREATE;
+       io.in.create_options = 0;
+       io.in.fname = dotfile;
+
+       status = smb2_create(tree, tctx, &io);
+       torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
+                                       "smb2_create failed");
+
+       ZERO_STRUCT(finfo2);
+       finfo2.generic.level = RAW_FILEINFO_BASIC_INFORMATION;
+       finfo2.generic.in.file.handle = io.out.file.handle;
+       status = smb2_getinfo_file(tree, tctx, &finfo2);
+       torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
+                                       "smb2_getinfo_file failed");
+       torture_assert_int_equal_goto(tctx, finfo2.all_info2.out.attrib & FILE_ATTRIBUTE_HIDDEN,
+                                     FILE_ATTRIBUTE_HIDDEN, ret, done,
+                                     "FILE_ATTRIBUTE_HIDDEN is not set");
+
+       smb2_util_close(tree, io.out.file.handle);
+
+       /* Overwrite a "hide dot files", should pass */
+       ZERO_STRUCT(io);
+       io.in.desired_access = SEC_FLAG_MAXIMUM_ALLOWED;
+       io.in.file_attributes   = FILE_ATTRIBUTE_NORMAL;
+       io.in.create_disposition = NTCREATEX_DISP_OVERWRITE_IF;
+       io.in.create_options = 0;
+       io.in.fname = dotfile;
+
+       status = smb2_create(tree, tctx, &io);
+       torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
+                                       "smb2_create failed");
+       smb2_util_close(tree, io.out.file.handle);
+
+done:
+       if (!smb2_util_handle_empty(h1)) {
+               smb2_util_close(tree, h1);
+       }
+       smb2_deltree(tree, dname);
+       return ret;
+}
index 90029c7ea43009fae0707136e2e57d4073bb689c..be632cccca5ad5a7cfe25f8ea68e88d4f8124204 100644 (file)
@@ -170,6 +170,7 @@ NTSTATUS torture_smb2_init(void)
        torture_suite_add_1smb2_test(suite, "hold-oplock", test_smb2_hold_oplock);
        torture_suite_add_suite(suite, torture_smb2_session_init());
        torture_suite_add_suite(suite, torture_smb2_replay_init());
+       torture_suite_add_simple_test(suite, "dosmode", torture_smb2_dosmode);
 
        torture_suite_add_suite(suite, torture_smb2_doc_init());
 
index 1c593efcc76278133b9d5dbf525da04d210f1d19..f404356fc3e2c75f61ec6250da9830d4a0b18954 100644 (file)
@@ -4,7 +4,7 @@ bld.SAMBA_MODULE('TORTURE_SMB2',
        source='''connect.c scan.c util.c getinfo.c setinfo.c lock.c notify.c
        smb2.c durable_open.c durable_v2_open.c oplock.c dir.c lease.c create.c
        acls.c read.c compound.c streams.c ioctl.c rename.c
-       session.c delete-on-close.c replay.c notify_disabled.c''',
+       session.c delete-on-close.c replay.c notify_disabled.c dosmode.c''',
        subsystem='smbtorture',
        deps='LIBCLI_SMB2 POPT_CREDENTIALS torture NDR_IOCTL',
        internal_module=True,