From 34311553d7f3bbc91a86ad5fe51e3b46f3ba505b Mon Sep 17 00:00:00 2001 From: David Mulder Date: Mon, 6 Jan 2020 09:43:19 -0700 Subject: [PATCH] s4:torture: Convert samba4.base.tcon test to smb2 Signed-off-by: David Mulder Reviewed-by: Noel Power Reviewed-by: Jeremy Allison (cherry picked from commit eb167bc43dbe196ef5b3bfd24160c72c74113dea) --- selftest/skip | 1 + selftest/todo_smb2_tests_to_port.list | 2 - source3/selftest/tests.py | 2 +- source4/torture/smb2/smb2.c | 1 + source4/torture/smb2/tcon.c | 146 ++++++++++++++++++++++++++ source4/torture/smb2/wscript_build | 1 + 6 files changed, 150 insertions(+), 3 deletions(-) create mode 100644 source4/torture/smb2/tcon.c diff --git a/selftest/skip b/selftest/skip index 440c7cea6b7..08862781946 100644 --- a/selftest/skip +++ b/selftest/skip @@ -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 diff --git a/selftest/todo_smb2_tests_to_port.list b/selftest/todo_smb2_tests_to_port.list index 595329ed7bb..def79e16bff 100644 --- a/selftest/todo_smb2_tests_to_port.list +++ b/selftest/todo_smb2_tests_to_port.list @@ -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) diff --git a/source3/selftest/tests.py b/source3/selftest/tests.py index d36ee6c6ebb..dafa93b5784 100755 --- a/source3/selftest/tests.py +++ b/source3/selftest/tests.py @@ -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: diff --git a/source4/torture/smb2/smb2.c b/source4/torture/smb2/smb2.c index 85bced0bb3c..dffada3454e 100644 --- a/source4/torture/smb2/smb2.c +++ b/source4/torture/smb2/smb2.c @@ -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 index 00000000000..1e658af2c2d --- /dev/null +++ b/source4/torture/smb2/tcon.c @@ -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 . +*/ + +#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; +} diff --git a/source4/torture/smb2/wscript_build b/source4/torture/smb2/wscript_build index 14d1ce151bc..aa83ea34296 100644 --- a/source4/torture/smb2/wscript_build +++ b/source4/torture/smb2/wscript_build @@ -40,6 +40,7 @@ bld.SAMBA_MODULE('TORTURE_SMB2', smb2.c streams.c samba3misc.c + tcon.c timestamps.c util.c ''', -- 2.47.3