]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s4:torture: Convert samba4.base.tcon test to smb2
authorDavid Mulder <dmulder@suse.com>
Mon, 6 Jan 2020 16:43:19 +0000 (09:43 -0700)
committerJeremy Allison <jra@samba.org>
Tue, 28 Apr 2020 18:09:39 +0000 (18:09 +0000)
Signed-off-by: David Mulder <dmulder@suse.com>
Reviewed-by: Noel Power <noel.power@suse.com>
Reviewed-by: Jeremy Allison <jra@samba.org>
(cherry picked from commit eb167bc43dbe196ef5b3bfd24160c72c74113dea)

selftest/skip
selftest/todo_smb2_tests_to_port.list
source3/selftest/tests.py
source4/torture/smb2/smb2.c
source4/torture/smb2/tcon.c [new file with mode: 0644]
source4/torture/smb2/wscript_build

index 440c7cea6b7df8e0752ab83315abcbec93a06149..08862781946d9e5853f2ec50d59fb0ba9aee89d5 100644 (file)
@@ -159,3 +159,4 @@ bench # don't run benchmarks in our selftest
 ^samba4.rpc.unixinfo # This contains a server-side getpwuid call which hangs the server when nss_winbindd is in use
 ^samba.tests.dcerpc.unix  # This contains a server-side getpwuid call which hangs the server when nss_winbindd is in use
 ^samba4.smb2.mangle.*\(ad_dc_ntvfs\)$ # Ignore ad_dc_ntvfs since this is a new test
+^samba4.smb2.tcon.*\(ad_dc_ntvfs\)$ # Ignore ad_dc_ntvfs since this is a new test
index 595329ed7bb48da04371559cd2333d24b7f1e5f4..def79e16bff28f0a5a5681169764f6885bd1fe83 100644 (file)
@@ -55,10 +55,8 @@ samba3.base.samba3error(ad_dc_smb1)
 samba3.base.samba3error(nt4_dc_smb1)
 samba3.base.secleak(ad_dc_smb1)
 samba3.base.secleak(nt4_dc_smb1)
-samba3.base.tcon(ad_dc_smb1)
 samba3.base.tcondev(ad_dc_smb1)
 samba3.base.tcondev(nt4_dc_smb1)
-samba3.base.tcon(nt4_dc_smb1)
 samba3.base.trans2(ad_dc_smb1)
 samba3.base.trans2(nt4_dc_smb1)
 samba3.base.unlink(ad_dc_smb1)
index d36ee6c6ebb2050dd53937db68b1632ae7781542..dafa93b5784578fb212cf8fac567493ed32f484a 100755 (executable)
@@ -826,7 +826,7 @@ for t in tests:
                   "raw.write",]) :
         plansmbtorture4testsuite(t, "nt4_dc_smb1", '//$SERVER_IP/tmp -U$USERNAME%$PASSWORD')
         plansmbtorture4testsuite(t, "ad_dc_smb1", '//$SERVER/tmp -U$USERNAME%$PASSWORD')
-    elif t == "base.mangle":
+    elif t in ["base.mangle", "base.tcon"]:
         plansmbtorture4testsuite(t, "nt4_dc_smb1_done", '//$SERVER_IP/tmp -U$USERNAME%$PASSWORD')
         plansmbtorture4testsuite(t, "ad_dc_smb1_done", '//$SERVER/tmp -U$USERNAME%$PASSWORD')
     else:
index 85bced0bb3ca42207dc1144e49b95126f2325763..dffada3454edf65d8cc0d8e245aa4d66daa6191b 100644 (file)
@@ -205,6 +205,7 @@ NTSTATUS torture_smb2_init(TALLOC_CTX *ctx)
        torture_suite_add_suite(suite, torture_smb2_readwrite_init(suite));
        torture_suite_add_1smb2_test(suite, "maximum_allowed", torture_smb2_maximum_allowed);
        torture_suite_add_1smb2_test(suite, "mangle", torture_smb2_mangle);
+       torture_suite_add_1smb2_test(suite, "tcon", run_tcon_test);
 
        torture_suite_add_suite(suite, torture_smb2_charset(suite));
        suite->description = talloc_strdup(suite, "SMB2-specific tests");
diff --git a/source4/torture/smb2/tcon.c b/source4/torture/smb2/tcon.c
new file mode 100644 (file)
index 0000000..1e658af
--- /dev/null
@@ -0,0 +1,146 @@
+/*
+   Unix SMB/CIFS implementation.
+   SMB torture tester
+   Copyright (C) Andrew Tridgell 1997-2003
+   Copyright (C) Jelmer Vernooij 2006
+   Copyright (C) David Mulder 2020
+
+   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 "libcli/smb2/smb2.h"
+#include "libcli/smb2/smb2_calls.h"
+#include "torture/smbtorture.h"
+#include "torture/smb2/proto.h"
+#include "libcli/smb/smbXcli_base.h"
+#include "torture/util.h"
+#include "system/filesys.h"
+#include "system/time.h"
+#include "libcli/resolve/resolve.h"
+#include "lib/events/events.h"
+#include "param/param.h"
+
+static void smb2cli_session_set_id(struct smbXcli_session *session,
+                                  uint64_t session_id)
+{
+       smb2cli_session_set_id_and_flags(session, session_id,
+                                        smb2cli_session_get_flags(session));
+}
+
+/**
+  this checks to see if a secondary tconx can use open files from an
+  earlier tconx
+ */
+bool run_tcon_test(struct torture_context *tctx, struct smb2_tree *tree)
+{
+       const char *fname = "tcontest.tmp";
+       struct smb2_handle fnum1;
+       uint32_t cnum1, cnum2, cnum3;
+       uint64_t sessid1, sessid2;
+       uint8_t buf[4];
+       bool ret = true;
+       struct smb2_tree *tree1 = NULL;
+       const char *host = torture_setting_string(tctx, "host", NULL);
+       struct smb2_create io = {0};
+       NTSTATUS status;
+       bool ok;
+
+       if (smb2_deltree(tree, fname) == -1) {
+               torture_comment(tctx, "unlink of %s failed\n", fname);
+       }
+
+       io.in.fname = fname;
+       io.in.desired_access = SEC_FILE_READ_DATA | SEC_FILE_WRITE_DATA;
+       io.in.create_disposition = NTCREATEX_DISP_CREATE;
+       io.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
+                            NTCREATEX_SHARE_ACCESS_WRITE |
+                            NTCREATEX_SHARE_ACCESS_DELETE;
+       status = smb2_create(tree, tree, &io);
+       if (NT_STATUS_IS_ERR(status)) {
+               torture_result(tctx, TORTURE_FAIL, "open of %s failed (%s)\n", fname, nt_errstr(status));
+               return false;
+       }
+       fnum1 = io.out.file.handle;
+
+       cnum1 = smb2cli_tcon_current_id(tree->smbXcli);
+       sessid1 = smb2cli_session_current_id(tree->session->smbXcli);
+
+       memset(buf, 0, 4); /* init buf so valgrind won't complain */
+       status = smb2_util_write(tree, fnum1, buf, 130, 4);
+       if (NT_STATUS_IS_ERR(status)) {
+               torture_result(tctx, TORTURE_FAIL, "initial write failed (%s)\n", nt_errstr(status));
+               return false;
+       }
+
+       ok = torture_smb2_tree_connect(tctx, tree->session, tctx, &tree1);
+       if (!ok) {
+               torture_result(tctx, TORTURE_FAIL, "%s refused 2nd tree connect\n", host);
+               return false;
+       }
+
+       cnum2 = smb2cli_tcon_current_id(tree1->smbXcli);
+       cnum3 = MAX(cnum1, cnum2) + 1; /* any invalid number */
+       sessid2 = smb2cli_session_current_id(tree1->session->smbXcli) + 1;
+
+       /* try a write with the wrong tid */
+       smb2cli_tcon_set_id(tree1->smbXcli, cnum2);
+
+       status = smb2_util_write(tree1, fnum1, buf, 130, 4);
+       if (NT_STATUS_IS_OK(status)) {
+               torture_result(tctx, TORTURE_FAIL, "* server allows write with wrong TID\n");
+               ret = false;
+       } else {
+               torture_comment(tctx, "server fails write with wrong TID : %s\n", nt_errstr(status));
+       }
+
+
+       /* try a write with an invalid tid */
+       smb2cli_tcon_set_id(tree1->smbXcli, cnum3);
+
+       status = smb2_util_write(tree1, fnum1, buf, 130, 4);
+       if (NT_STATUS_IS_OK(status)) {
+               torture_result(tctx, TORTURE_FAIL, "* server allows write with invalid TID\n");
+               ret = false;
+       } else {
+               torture_comment(tctx, "server fails write with invalid TID : %s\n", nt_errstr(status));
+       }
+
+       /* try a write with an invalid session id */
+       smb2cli_session_set_id(tree1->session->smbXcli, sessid2);
+       smb2cli_tcon_set_id(tree1->smbXcli, cnum1);
+
+       status = smb2_util_write(tree1, fnum1, buf, 130, 4);
+       if (NT_STATUS_IS_OK(status)) {
+               torture_result(tctx, TORTURE_FAIL, "* server allows write with invalid VUID\n");
+               ret = false;
+       } else {
+               torture_comment(tctx, "server fails write with invalid VUID : %s\n", nt_errstr(status));
+       }
+
+       smb2cli_session_set_id(tree1->session->smbXcli, sessid1);
+       smb2cli_tcon_set_id(tree1->smbXcli, cnum1);
+
+       status = smb2_util_close(tree1, fnum1);
+       if (NT_STATUS_IS_ERR(status)) {
+               torture_result(tctx, TORTURE_FAIL, "close failed (%s)\n", nt_errstr(status));
+               return false;
+       }
+
+       smb2cli_tcon_set_id(tree1->smbXcli, cnum2);
+
+       smb2_util_unlink(tree1, fname);
+
+       return ret;
+}
index 14d1ce151bc1a2255907f0ec69bdbfaeeb6eb8fe..aa83ea342960f1c5ee270affd55f0ca50787cb2b 100644 (file)
@@ -40,6 +40,7 @@ bld.SAMBA_MODULE('TORTURE_SMB2',
         smb2.c
         streams.c
         samba3misc.c
+        tcon.c
         timestamps.c
         util.c
         ''',