From 7278c549ea7ea4a83ff164a9f9bf335fa4d11dd8 Mon Sep 17 00:00:00 2001 From: Zach Loafman Date: Thu, 26 Mar 2009 09:32:50 -0700 Subject: Reorganize old persistent_handles test into durable_open.c, turn it into a suite instead of a solo test (in anticipation of more tests). --- source4/torture/smb2/config.mk | 2 +- source4/torture/smb2/durable_open.c | 194 ++++++++++++++++++++++++++++++ source4/torture/smb2/persistent_handles.c | 183 ---------------------------- source4/torture/smb2/smb2.c | 2 +- 4 files changed, 196 insertions(+), 185 deletions(-) create mode 100644 source4/torture/smb2/durable_open.c delete mode 100644 source4/torture/smb2/persistent_handles.c (limited to 'source4/torture/smb2') diff --git a/source4/torture/smb2/config.mk b/source4/torture/smb2/config.mk index e0fc29f278..91ba9fcf0c 100644 --- a/source4/torture/smb2/config.mk +++ b/source4/torture/smb2/config.mk @@ -20,7 +20,7 @@ TORTURE_SMB2_OBJ_FILES = $(addprefix $(torturesrcdir)/smb2/, \ lock.o \ notify.o \ smb2.o \ - persistent_handles.o \ + durable_open.o \ oplocks.o \ create.o \ read.o) diff --git a/source4/torture/smb2/durable_open.c b/source4/torture/smb2/durable_open.c new file mode 100644 index 0000000000..3cf6e85de3 --- /dev/null +++ b/source4/torture/smb2/durable_open.c @@ -0,0 +1,194 @@ +/* + Unix SMB/CIFS implementation. + + test suite for SMB2 durable opens + + Copyright (C) Stefan Metzmacher 2008 + + 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 "librpc/gen_ndr/security.h" +#include "libcli/smb2/smb2.h" +#include "libcli/smb2/smb2_calls.h" +#include "torture/torture.h" +#include "torture/smb2/proto.h" + +#define CHECK_VAL(v, correct) do { \ + if ((v) != (correct)) { \ + torture_result(tctx, TORTURE_FAIL, "(%s): wrong value for %s got 0x%x - should be 0x%x\n", \ + __location__, #v, (int)v, (int)correct); \ + ret = false; \ + }} while (0) + +#define CHECK_STATUS(status, correct) do { \ + if (!NT_STATUS_EQUAL(status, correct)) { \ + torture_result(tctx, TORTURE_FAIL, __location__": Incorrect status %s - should be %s", \ + nt_errstr(status), nt_errstr(correct)); \ + ret = false; \ + goto done; \ + }} while (0) + +/* + basic testing of SMB2 durable opens + regarding the position information on the handle +*/ +bool test_durable_open_file_position(struct torture_context *tctx, + struct smb2_tree *tree1, + struct smb2_tree *tree2) +{ + TALLOC_CTX *mem_ctx = talloc_new(tctx); + struct smb2_handle h1, h2; + struct smb2_create io1, io2; + NTSTATUS status; + const char *fname = "durable_opens.dat"; + DATA_BLOB b; + union smb_fileinfo qfinfo; + union smb_setfileinfo sfinfo; + bool ret = true; + uint64_t pos; + + smb2_util_unlink(tree1, fname); + + ZERO_STRUCT(io1); + io1.in.security_flags = 0x00; + io1.in.oplock_level = SMB2_OPLOCK_LEVEL_BATCH; + io1.in.impersonation_level = NTCREATEX_IMPERSONATION_IMPERSONATION; + io1.in.create_flags = 0x00000000; + io1.in.reserved = 0x00000000; + io1.in.desired_access = SEC_RIGHTS_FILE_ALL; + io1.in.file_attributes = FILE_ATTRIBUTE_NORMAL; + io1.in.share_access = NTCREATEX_SHARE_ACCESS_READ | + NTCREATEX_SHARE_ACCESS_WRITE | + NTCREATEX_SHARE_ACCESS_DELETE; + io1.in.create_disposition = NTCREATEX_DISP_OPEN_IF; + io1.in.create_options = NTCREATEX_OPTIONS_SEQUENTIAL_ONLY | + NTCREATEX_OPTIONS_ASYNC_ALERT | + NTCREATEX_OPTIONS_NON_DIRECTORY_FILE | + 0x00200000; + io1.in.fname = fname; + + b = data_blob_talloc(mem_ctx, NULL, 16); + SBVAL(b.data, 0, 0); + SBVAL(b.data, 8, 0); + + status = smb2_create_blob_add(tree1, &io1.in.blobs, + SMB2_CREATE_TAG_DHNQ, + b); + CHECK_STATUS(status, NT_STATUS_OK); + + status = smb2_create(tree1, mem_ctx, &io1); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VAL(io1.out.oplock_level, SMB2_OPLOCK_LEVEL_BATCH); + /*CHECK_VAL(io1.out.reserved, 0);*/ + CHECK_VAL(io1.out.create_action, NTCREATEX_ACTION_CREATED); + CHECK_VAL(io1.out.alloc_size, 0); + CHECK_VAL(io1.out.size, 0); + CHECK_VAL(io1.out.file_attr, FILE_ATTRIBUTE_ARCHIVE); + CHECK_VAL(io1.out.reserved2, 0); + + /* TODO: check extra blob content */ + + h1 = io1.out.file.handle; + + ZERO_STRUCT(qfinfo); + qfinfo.generic.level = RAW_FILEINFO_POSITION_INFORMATION; + qfinfo.generic.in.file.handle = h1; + status = smb2_getinfo_file(tree1, mem_ctx, &qfinfo); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VAL(qfinfo.position_information.out.position, 0); + pos = qfinfo.position_information.out.position; + torture_comment(tctx, "position: %llu\n", + (unsigned long long)pos); + + ZERO_STRUCT(sfinfo); + sfinfo.generic.level = RAW_SFILEINFO_POSITION_INFORMATION; + sfinfo.generic.in.file.handle = h1; + sfinfo.position_information.in.position = 0x1000; + status = smb2_setinfo_file(tree1, &sfinfo); + CHECK_STATUS(status, NT_STATUS_OK); + + ZERO_STRUCT(qfinfo); + qfinfo.generic.level = RAW_FILEINFO_POSITION_INFORMATION; + qfinfo.generic.in.file.handle = h1; + status = smb2_getinfo_file(tree1, mem_ctx, &qfinfo); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VAL(qfinfo.position_information.out.position, 0x1000); + pos = qfinfo.position_information.out.position; + torture_comment(tctx, "position: %llu\n", + (unsigned long long)pos); + + talloc_free(tree1); + tree1 = NULL; + + ZERO_STRUCT(qfinfo); + qfinfo.generic.level = RAW_FILEINFO_POSITION_INFORMATION; + qfinfo.generic.in.file.handle = h1; + status = smb2_getinfo_file(tree2, mem_ctx, &qfinfo); + CHECK_STATUS(status, NT_STATUS_FILE_CLOSED); + + ZERO_STRUCT(io2); + io2.in.fname = fname; + + b = data_blob_talloc(tctx, NULL, 16); + SBVAL(b.data, 0, h1.data[0]); + SBVAL(b.data, 8, h1.data[1]); + + status = smb2_create_blob_add(tree2, &io2.in.blobs, + SMB2_CREATE_TAG_DHNC, + b); + CHECK_STATUS(status, NT_STATUS_OK); + + status = smb2_create(tree2, mem_ctx, &io2); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VAL(io2.out.oplock_level, SMB2_OPLOCK_LEVEL_BATCH); + CHECK_VAL(io2.out.reserved, 0x00); + CHECK_VAL(io2.out.create_action, NTCREATEX_ACTION_EXISTED); + CHECK_VAL(io2.out.alloc_size, 0); + CHECK_VAL(io2.out.size, 0); + CHECK_VAL(io2.out.file_attr, FILE_ATTRIBUTE_ARCHIVE); + CHECK_VAL(io2.out.reserved2, 0); + + h2 = io2.out.file.handle; + + ZERO_STRUCT(qfinfo); + qfinfo.generic.level = RAW_FILEINFO_POSITION_INFORMATION; + qfinfo.generic.in.file.handle = h2; + status = smb2_getinfo_file(tree2, mem_ctx, &qfinfo); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VAL(qfinfo.position_information.out.position, 0x1000); + pos = qfinfo.position_information.out.position; + torture_comment(tctx, "position: %llu\n", + (unsigned long long)pos); + + smb2_util_close(tree2, h2); + + talloc_free(mem_ctx); + + smb2_util_unlink(tree2, fname); +done: + return ret; +} + +struct torture_suite *torture_smb2_durable_open_init(void) +{ + struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), + "DURABLE-OPEN"); + + torture_suite_add_2smb2_test(suite, "FILE-POSITION", + test_durable_open_file_position); + + suite->description = talloc_strdup(suite, "SMB2-DURABLE-OPEN tests"); +} diff --git a/source4/torture/smb2/persistent_handles.c b/source4/torture/smb2/persistent_handles.c deleted file mode 100644 index 05c5dbbe85..0000000000 --- a/source4/torture/smb2/persistent_handles.c +++ /dev/null @@ -1,183 +0,0 @@ -/* - Unix SMB/CIFS implementation. - - test suite for SMB2 persistent file handles - - Copyright (C) Stefan Metzmacher 2008 - - 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 "librpc/gen_ndr/security.h" -#include "libcli/smb2/smb2.h" -#include "libcli/smb2/smb2_calls.h" -#include "torture/torture.h" -#include "torture/smb2/proto.h" - -#define CHECK_VAL(v, correct) do { \ - if ((v) != (correct)) { \ - torture_result(tctx, TORTURE_FAIL, "(%s): wrong value for %s got 0x%x - should be 0x%x\n", \ - __location__, #v, (int)v, (int)correct); \ - ret = false; \ - }} while (0) - -#define CHECK_STATUS(status, correct) do { \ - if (!NT_STATUS_EQUAL(status, correct)) { \ - torture_result(tctx, TORTURE_FAIL, __location__": Incorrect status %s - should be %s", \ - nt_errstr(status), nt_errstr(correct)); \ - ret = false; \ - goto done; \ - }} while (0) - -/* - basic testing of SMB2 persistent file handles - regarding the position information on the handle -*/ -bool torture_smb2_persistent_handles1(struct torture_context *tctx, - struct smb2_tree *tree1, - struct smb2_tree *tree2) -{ - TALLOC_CTX *mem_ctx = talloc_new(tctx); - struct smb2_handle h1, h2; - struct smb2_create io1, io2; - NTSTATUS status; - const char *fname = "persistent_handles.dat"; - DATA_BLOB b; - union smb_fileinfo qfinfo; - union smb_setfileinfo sfinfo; - bool ret = true; - uint64_t pos; - - smb2_util_unlink(tree1, fname); - - ZERO_STRUCT(io1); - io1.in.security_flags = 0x00; - io1.in.oplock_level = SMB2_OPLOCK_LEVEL_BATCH; - io1.in.impersonation_level = NTCREATEX_IMPERSONATION_IMPERSONATION; - io1.in.create_flags = 0x00000000; - io1.in.reserved = 0x00000000; - io1.in.desired_access = SEC_RIGHTS_FILE_ALL; - io1.in.file_attributes = FILE_ATTRIBUTE_NORMAL; - io1.in.share_access = NTCREATEX_SHARE_ACCESS_READ | - NTCREATEX_SHARE_ACCESS_WRITE | - NTCREATEX_SHARE_ACCESS_DELETE; - io1.in.create_disposition = NTCREATEX_DISP_OPEN_IF; - io1.in.create_options = NTCREATEX_OPTIONS_SEQUENTIAL_ONLY | - NTCREATEX_OPTIONS_ASYNC_ALERT | - NTCREATEX_OPTIONS_NON_DIRECTORY_FILE | - 0x00200000; - io1.in.fname = fname; - - b = data_blob_talloc(mem_ctx, NULL, 16); - SBVAL(b.data, 0, 0); - SBVAL(b.data, 8, 0); - - status = smb2_create_blob_add(tree1, &io1.in.blobs, - SMB2_CREATE_TAG_DHNQ, - b); - CHECK_STATUS(status, NT_STATUS_OK); - - status = smb2_create(tree1, mem_ctx, &io1); - CHECK_STATUS(status, NT_STATUS_OK); - CHECK_VAL(io1.out.oplock_level, SMB2_OPLOCK_LEVEL_BATCH); - /*CHECK_VAL(io1.out.reserved, 0);*/ - CHECK_VAL(io1.out.create_action, NTCREATEX_ACTION_CREATED); - CHECK_VAL(io1.out.alloc_size, 0); - CHECK_VAL(io1.out.size, 0); - CHECK_VAL(io1.out.file_attr, FILE_ATTRIBUTE_ARCHIVE); - CHECK_VAL(io1.out.reserved2, 0); - - /* TODO: check extra blob content */ - - h1 = io1.out.file.handle; - - ZERO_STRUCT(qfinfo); - qfinfo.generic.level = RAW_FILEINFO_POSITION_INFORMATION; - qfinfo.generic.in.file.handle = h1; - status = smb2_getinfo_file(tree1, mem_ctx, &qfinfo); - CHECK_STATUS(status, NT_STATUS_OK); - CHECK_VAL(qfinfo.position_information.out.position, 0); - pos = qfinfo.position_information.out.position; - torture_comment(tctx, "position: %llu\n", - (unsigned long long)pos); - - ZERO_STRUCT(sfinfo); - sfinfo.generic.level = RAW_SFILEINFO_POSITION_INFORMATION; - sfinfo.generic.in.file.handle = h1; - sfinfo.position_information.in.position = 0x1000; - status = smb2_setinfo_file(tree1, &sfinfo); - CHECK_STATUS(status, NT_STATUS_OK); - - ZERO_STRUCT(qfinfo); - qfinfo.generic.level = RAW_FILEINFO_POSITION_INFORMATION; - qfinfo.generic.in.file.handle = h1; - status = smb2_getinfo_file(tree1, mem_ctx, &qfinfo); - CHECK_STATUS(status, NT_STATUS_OK); - CHECK_VAL(qfinfo.position_information.out.position, 0x1000); - pos = qfinfo.position_information.out.position; - torture_comment(tctx, "position: %llu\n", - (unsigned long long)pos); - - talloc_free(tree1); - tree1 = NULL; - - ZERO_STRUCT(qfinfo); - qfinfo.generic.level = RAW_FILEINFO_POSITION_INFORMATION; - qfinfo.generic.in.file.handle = h1; - status = smb2_getinfo_file(tree2, mem_ctx, &qfinfo); - CHECK_STATUS(status, NT_STATUS_FILE_CLOSED); - - ZERO_STRUCT(io2); - io2.in.fname = fname; - - b = data_blob_talloc(tctx, NULL, 16); - SBVAL(b.data, 0, h1.data[0]); - SBVAL(b.data, 8, h1.data[1]); - - status = smb2_create_blob_add(tree2, &io2.in.blobs, - SMB2_CREATE_TAG_DHNC, - b); - CHECK_STATUS(status, NT_STATUS_OK); - - status = smb2_create(tree2, mem_ctx, &io2); - CHECK_STATUS(status, NT_STATUS_OK); - CHECK_VAL(io2.out.oplock_level, SMB2_OPLOCK_LEVEL_BATCH); - CHECK_VAL(io2.out.reserved, 0x00); - CHECK_VAL(io2.out.create_action, NTCREATEX_ACTION_EXISTED); - CHECK_VAL(io2.out.alloc_size, 0); - CHECK_VAL(io2.out.size, 0); - CHECK_VAL(io2.out.file_attr, FILE_ATTRIBUTE_ARCHIVE); - CHECK_VAL(io2.out.reserved2, 0); - - h2 = io2.out.file.handle; - - ZERO_STRUCT(qfinfo); - qfinfo.generic.level = RAW_FILEINFO_POSITION_INFORMATION; - qfinfo.generic.in.file.handle = h2; - status = smb2_getinfo_file(tree2, mem_ctx, &qfinfo); - CHECK_STATUS(status, NT_STATUS_OK); - CHECK_VAL(qfinfo.position_information.out.position, 0x1000); - pos = qfinfo.position_information.out.position; - torture_comment(tctx, "position: %llu\n", - (unsigned long long)pos); - - smb2_util_close(tree2, h2); - - talloc_free(mem_ctx); - - smb2_util_unlink(tree2, fname); -done: - return ret; -} diff --git a/source4/torture/smb2/smb2.c b/source4/torture/smb2/smb2.c index 9418650de4..3b2e752295 100644 --- a/source4/torture/smb2/smb2.c +++ b/source4/torture/smb2/smb2.c @@ -139,7 +139,7 @@ NTSTATUS torture_smb2_init(void) torture_suite_add_suite(suite, torture_smb2_read_init()); torture_suite_add_suite(suite, torture_smb2_create_init()); torture_suite_add_simple_test(suite, "NOTIFY", torture_smb2_notify); - torture_suite_add_2smb2_test(suite, "PERSISTENT-HANDLES1", torture_smb2_persistent_handles1); + torture_suite_add_suite(suite, torture_smb2_durable_open_init()); torture_suite_add_1smb2_test(suite, "OPLOCK-BATCH1", torture_smb2_oplock_batch1); suite->description = talloc_strdup(suite, "SMB2-specific tests"); -- cgit