From dedb4f24af99c8ed5e601bdb30a8ed14de0aae54 Mon Sep 17 00:00:00 2001 From: David Mulder Date: Thu, 23 Jan 2020 07:26:53 -0700 Subject: [PATCH] s4:torture: Convert samba3.raw.mkdir test to smb2 Signed-off-by: David Mulder Reviewed-by: Noel Power Reviewed-by: Jeremy Allison (cherry picked from commit 888abcaf8ffbec45fc47520bd3f544e3aa6f58f2) Autobuild-User(master): Jeremy Allison Autobuild-Date(master): Tue Apr 28 19:46:32 UTC 2020 on sn-devel-184 --- selftest/skip | 1 + selftest/todo_smb2_tests_to_port.list | 2 - source3/selftest/tests.py | 2 +- source4/torture/smb2/mkdir.c | 105 ++++++++++++++++++++++++++ source4/torture/smb2/smb2.c | 1 + source4/torture/smb2/wscript_build | 1 + 6 files changed, 109 insertions(+), 3 deletions(-) create mode 100644 source4/torture/smb2/mkdir.c diff --git a/selftest/skip b/selftest/skip index 08862781946..d13cf7cd18b 100644 --- a/selftest/skip +++ b/selftest/skip @@ -160,3 +160,4 @@ bench # don't run benchmarks in our selftest ^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 +^samba4.smb2.mkdir.*\(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 def79e16bff..a9d7b8b48c5 100644 --- a/selftest/todo_smb2_tests_to_port.list +++ b/selftest/todo_smb2_tests_to_port.list @@ -100,8 +100,6 @@ samba3.raw.composite(nt4_dc_smb1) samba3.raw.eas(ad_dc_smb1) samba3.raw.eas(nt4_dc_smb1) samba3.raw.lock(nt4_dc_smb1) -samba3.raw.mkdir(ad_dc_smb1) -samba3.raw.mkdir(nt4_dc_smb1) samba3.raw.notify(nt4_dc_smb1) samba3.raw.open(ad_dc_smb1) samba3.raw.open(nt4_dc_smb1) diff --git a/source3/selftest/tests.py b/source3/selftest/tests.py index dafa93b5784..45b8dca56c2 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 in ["base.mangle", "base.tcon"]: + elif t in ["base.mangle", "base.tcon", "raw.mkdir"]: 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/mkdir.c b/source4/torture/smb2/mkdir.c new file mode 100644 index 00000000000..f797b5cef6f --- /dev/null +++ b/source4/torture/smb2/mkdir.c @@ -0,0 +1,105 @@ +/* + Unix SMB/CIFS implementation. + RAW_MKDIR_* and RAW_RMDIR_* individual test suite + Copyright (C) Andrew Tridgell 2003 + 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/util.h" +#include "torture/smb2/proto.h" +#include "libcli/smb_composite/smb_composite.h" + +#define BASEDIR "mkdirtest" + +/* + test mkdir ops +*/ +bool torture_smb2_mkdir(struct torture_context *tctx, struct smb2_tree *tree) +{ + struct smb2_handle h = {{0}}; + const char *path = BASEDIR "\\mkdir.dir"; + NTSTATUS status; + bool ret = true; + + ret = smb2_util_setup_dir(tctx, tree, BASEDIR); + torture_assert(tctx, ret, "Failed to setup up test directory: " BASEDIR); + + /* + basic mkdir + */ + status = smb2_util_mkdir(tree, path); + torture_assert_ntstatus_ok_goto(tctx, status, ret, done, + "Incorrect status"); + + torture_comment(tctx, "Testing mkdir collision\n"); + + /* 2nd create */ + status = smb2_util_mkdir(tree, path); + torture_assert_ntstatus_equal_goto(tctx, status, + NT_STATUS_OBJECT_NAME_COLLISION, + ret, done, "Incorrect status"); + + /* basic rmdir */ + status = smb2_util_rmdir(tree, path); + torture_assert_ntstatus_ok_goto(tctx, status, ret, done, + "Incorrect status"); + + status = smb2_util_rmdir(tree, path); + torture_assert_ntstatus_equal_goto(tctx, status, + NT_STATUS_OBJECT_NAME_NOT_FOUND, + ret, done, "Incorrect status"); + + torture_comment(tctx, "Testing mkdir collision with file\n"); + + /* name collision with a file */ + smb2_create_complex_file(tctx, tree, path, &h); + smb2_util_close(tree, h); + status = smb2_util_mkdir(tree, path); + torture_assert_ntstatus_equal_goto(tctx, status, + NT_STATUS_OBJECT_NAME_COLLISION, + ret, done, "Incorrect status"); + + torture_comment(tctx, "Testing rmdir with file\n"); + + /* delete a file with rmdir */ + status = smb2_util_rmdir(tree, path); + torture_assert_ntstatus_equal_goto(tctx, status, + NT_STATUS_NOT_A_DIRECTORY, + ret, done, "Incorrect status"); + + smb2_util_unlink(tree, path); + + torture_comment(tctx, "Testing invalid dir\n"); + + /* create an invalid dir */ + status = smb2_util_mkdir(tree, "..\\..\\.."); + torture_assert_ntstatus_equal_goto(tctx, status, + NT_STATUS_OBJECT_PATH_SYNTAX_BAD, + ret, done, "Incorrect status"); + + torture_comment(tctx, "Testing t2mkdir bad path\n"); + status = smb2_util_mkdir(tree, BASEDIR "\\bad_path\\bad_path"); + torture_assert_ntstatus_equal_goto(tctx, status, + NT_STATUS_OBJECT_PATH_NOT_FOUND, + ret, done, "Incorrect status"); + +done: + smb2_deltree(tree, BASEDIR); + return ret; +} diff --git a/source4/torture/smb2/smb2.c b/source4/torture/smb2/smb2.c index dffada3454e..0754d107e2d 100644 --- a/source4/torture/smb2/smb2.c +++ b/source4/torture/smb2/smb2.c @@ -206,6 +206,7 @@ NTSTATUS torture_smb2_init(TALLOC_CTX *ctx) 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_1smb2_test(suite, "mkdir", torture_smb2_mkdir); torture_suite_add_suite(suite, torture_smb2_charset(suite)); suite->description = talloc_strdup(suite, "SMB2-specific tests"); diff --git a/source4/torture/smb2/wscript_build b/source4/torture/smb2/wscript_build index aa83ea34296..940de12aeb2 100644 --- a/source4/torture/smb2/wscript_build +++ b/source4/torture/smb2/wscript_build @@ -24,6 +24,7 @@ bld.SAMBA_MODULE('TORTURE_SMB2', mangle.c maxfid.c maxwrite.c + mkdir.c multichannel.c oplock_break_handler.c notify.c