From e1bb3d34d900730c71ceaf2a1fba23823342f94e Mon Sep 17 00:00:00 2001 From: Christof Schmitt Date: Fri, 28 Sep 2018 16:37:51 -0700 Subject: [PATCH 1/1] smbtorture: Add smb2.ioctl.zero_data Allow to manually issue the FSCTL_ZERO_DATA call and verify the state of the file in the file system. Signed-off-by: Christof Schmitt Reviewed-by: Andrew Bartlett --- selftest/skip | 2 ++ source4/torture/smb2/ioctl.c | 61 ++++++++++++++++++++++++++++++++++++ source4/torture/smb2/smb2.c | 2 ++ 3 files changed, 65 insertions(+) diff --git a/selftest/skip b/selftest/skip index d9e615146fb..1e7448acb9f 100644 --- a/selftest/skip +++ b/selftest/skip @@ -71,6 +71,7 @@ ^samba3.smb2.hold-sharemode # Not a test, but a way to block other clients for a test ^samba3.smb2.check-sharemode # Not a test, but a way to test sharemodes outside of Samba ^samba3.smb2.set-sparse-ioctl # For manual testing, needs additional parameters. +^samba3.smb2.zero-data-ioctl # For manual testing, needs additional parameters. ^samba3.smb2.durable-open-disconnect # Not a test, but a way to create a disconnected durable ^samba3.smb2.scan # No tests ^samba3.smb2.oplock.levelii501 # No test yet @@ -85,6 +86,7 @@ ^samba4.smb2.hold-sharemode # Not a test, but a way to block other clients for a test ^samba4.smb2.check-sharemode # Not a test, but a way to test sharemodes outside of Samba ^samba4.smb2.set-sparse-ioctl # For manual testing, needs additional parameters. +^samba4.smb2.zero-data-ioctl # For manual testing, needs additional parameters. ^samba4.raw.ping.pong # Needs second server to test ^samba4.rpc.samr.accessmask ^samba4.rpc.samr.passwords.*ncacn_np\(ad_dc_ntvfs\) # currently fails, possibly config issue diff --git a/source4/torture/smb2/ioctl.c b/source4/torture/smb2/ioctl.c index 39aedba7cc8..eed81d1f598 100644 --- a/source4/torture/smb2/ioctl.c +++ b/source4/torture/smb2/ioctl.c @@ -3894,6 +3894,67 @@ err_out: return status; } +bool test_ioctl_zero_data(struct torture_context *tctx) +{ + bool ret = true; + int offset, beyond_final_zero; + const char *filename; + NTSTATUS status; + struct smb2_create create = { }; + struct smb2_tree *tree = NULL; + + offset = torture_setting_int(tctx, "offset", -1); + + if (offset < 0) { + torture_fail(tctx, "Need to provide non-negative offset " + "through --option=torture:offset=NNN\n"); + return false; + } + + beyond_final_zero = torture_setting_int(tctx, "beyond_final_zero", + -1); + if (beyond_final_zero < 0) { + torture_fail(tctx, "Need to provide non-negative " + "'beyond final zero' through " + "--option=torture:beyond_final_zero=NNN\n"); + return false; + } + filename = torture_setting_string(tctx, "filename", NULL); + if (filename == NULL) { + torture_fail(tctx, "Need to provide filename through " + "--option=torture:filename=testfile\n"); + return false; + } + + if (!torture_smb2_connection(tctx, &tree)) { + torture_comment(tctx, "Initializing smb2 connection failed.\n"); + return false; + } + + create.in.desired_access = SEC_RIGHTS_DIR_ALL; + create.in.create_options = 0; + create.in.file_attributes = FILE_ATTRIBUTE_NORMAL; + create.in.share_access = NTCREATEX_SHARE_ACCESS_READ | + NTCREATEX_SHARE_ACCESS_WRITE | + NTCREATEX_SHARE_ACCESS_DELETE; + create.in.create_disposition = NTCREATEX_DISP_OPEN; + create.in.fname = filename; + + status = smb2_create(tree, tctx, &create); + torture_assert_ntstatus_ok_goto(tctx, status, ret, done, + "CREATE failed.\n"); + + status = test_ioctl_zdata_req(tctx, tctx, tree, + create.out.file.handle, + offset, + beyond_final_zero); + torture_assert_ntstatus_ok_goto(tctx, status, ret, done, + "FSCTL_ZERO_DATA failed.\n"); + +done: + return ret; +} + static bool test_ioctl_sparse_punch(struct torture_context *torture, struct smb2_tree *tree) { diff --git a/source4/torture/smb2/smb2.c b/source4/torture/smb2/smb2.c index 56df0ddaafe..f495c19d251 100644 --- a/source4/torture/smb2/smb2.c +++ b/source4/torture/smb2/smb2.c @@ -177,6 +177,8 @@ NTSTATUS torture_smb2_init(TALLOC_CTX *ctx) torture_suite_add_suite(suite, torture_smb2_ioctl_init(suite)); torture_suite_add_simple_test(suite, "set-sparse-ioctl", test_ioctl_set_sparse); + torture_suite_add_simple_test(suite, "zero-data-ioctl", + test_ioctl_zero_data); torture_suite_add_suite(suite, torture_smb2_rename_init(suite)); torture_suite_add_1smb2_test(suite, "bench-oplock", test_smb2_bench_oplock); torture_suite_add_suite(suite, torture_smb2_sharemode_init(suite)); -- 2.34.1