The branch, v4-0-test has been updated via 30e04ae3a02596de03d06874ff5dfc0ddc3bf902 (commit) via 02bfe20fd3ef2981945b3eb38f0bf012ef0cb91e (commit) via d70afbb0673184ed067e5f1c7608536025a3cca7 (commit) via 66c0f331a231ea8897bd8f83658c86b1d2c85d62 (commit) via fbfbd74e65b1f3e185f08a538bdd50ba7c6ce9bf (commit) via e0a0d8e36acd735b587cd7870625af52c5dc3431 (commit) via 874924a85a862e38b7d1a6199276e998cf3697d8 (commit) from d40804777edf41889bd461f63f7a07cc1cc60e27 (commit)
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v4-0-test - Log ----------------------------------------------------------------- commit 30e04ae3a02596de03d06874ff5dfc0ddc3bf902 Author: Stefan Metzmacher <[EMAIL PROTECTED]> Date: Wed Apr 16 10:11:44 2008 +0200 torture/smb2: add SMB2-PERSISTENT-HANDLES1 test This demonstrates that the file seek position is still available on reconnected persistent handles. metze commit 02bfe20fd3ef2981945b3eb38f0bf012ef0cb91e Author: Stefan Metzmacher <[EMAIL PROTECTED]> Date: Thu Apr 17 02:38:13 2008 +0200 selftest: ignore failures in the SMB2-PERSISTENT-HANDLES1 test metze commit d70afbb0673184ed067e5f1c7608536025a3cca7 Author: Stefan Metzmacher <[EMAIL PROTECTED]> Date: Wed Apr 16 15:16:56 2008 +0200 torture/smb2: add torture_suite_add_2smb2_test() helper function metze commit 66c0f331a231ea8897bd8f83658c86b1d2c85d62 Author: Stefan Metzmacher <[EMAIL PROTECTED]> Date: Wed Apr 16 15:15:57 2008 +0200 torture/smb2: fix whitespaces metze commit fbfbd74e65b1f3e185f08a538bdd50ba7c6ce9bf Author: Stefan Metzmacher <[EMAIL PROTECTED]> Date: Wed Apr 16 19:26:52 2008 +0200 smb_server/smb2: initialize new create.in.blobs element untill it'll be supported metze commit e0a0d8e36acd735b587cd7870625af52c5dc3431 Author: Stefan Metzmacher <[EMAIL PROTECTED]> Date: Wed Apr 16 10:03:08 2008 +0200 libcli/smb2: make it possible to pass additional extra blobs in smb2_create() This also fixes the alignment from 8 to 4 byte bounderies. metze commit 874924a85a862e38b7d1a6199276e998cf3697d8 Author: Stefan Metzmacher <[EMAIL PROTECTED]> Date: Wed Apr 16 10:05:53 2008 +0200 libcli/smb2: also offer the SMB2 dialect that what used in longhorn beta3 With this smbtorture works against longhorn beta3 again, hopefully it still works with new versions... metze ----------------------------------------------------------------------- Summary of changes: source/libcli/raw/interfaces.h | 8 ++ source/libcli/smb2/connect.c | 7 +- source/libcli/smb2/create.c | 94 +++++++++++++---- source/samba4-knownfail | 1 + source/smb_server/smb2/fileio.c | 1 + source/torture/smb2/config.mk | 3 +- source/torture/smb2/persistent_handles.c | 162 ++++++++++++++++++++++++++++++ source/torture/smb2/smb2.c | 62 +++++++++++- 8 files changed, 308 insertions(+), 30 deletions(-) create mode 100644 source/torture/smb2/persistent_handles.c Changeset truncated at 500 lines: diff --git a/source/libcli/raw/interfaces.h b/source/libcli/raw/interfaces.h index 61441b2..cf5a3aa 100644 --- a/source/libcli/raw/interfaces.h +++ b/source/libcli/raw/interfaces.h @@ -1587,6 +1587,14 @@ union smb_open { /* optional list of extended attributes */ struct smb_ea_list eas; + + struct smb2_create_blobs { + uint32_t num_blobs; + struct smb2_create_blob { + const char *tag; + DATA_BLOB data; + } *blobs; + } blobs; } in; struct { union smb_handle file; diff --git a/source/libcli/smb2/connect.c b/source/libcli/smb2/connect.c index d68b85a..59d4e6e 100644 --- a/source/libcli/smb2/connect.c +++ b/source/libcli/smb2/connect.c @@ -121,7 +121,7 @@ static void continue_socket(struct composite_context *creq) struct smbcli_socket *sock; struct smb2_transport *transport; struct smb2_request *req; - uint16_t dialects[1]; + uint16_t dialects[2]; c->status = smbcli_sock_connect_recv(creq, state, &sock); if (!composite_is_ok(c)) return; @@ -130,11 +130,12 @@ static void continue_socket(struct composite_context *creq) if (composite_nomem(transport, c)) return; ZERO_STRUCT(state->negprot); - state->negprot.in.dialect_count = 1; + state->negprot.in.dialect_count = 2; state->negprot.in.security_mode = 0; state->negprot.in.capabilities = 0; unix_to_nt_time(&state->negprot.in.start_time, time(NULL)); - dialects[0] = SMB2_DIALECT_REVISION; + dialects[0] = 0; + dialects[1] = SMB2_DIALECT_REVISION; state->negprot.in.dialects = dialects; req = smb2_negprot_send(transport, &state->negprot); diff --git a/source/libcli/smb2/create.c b/source/libcli/smb2/create.c index 999c10a..6ac32a4 100644 --- a/source/libcli/smb2/create.c +++ b/source/libcli/smb2/create.c @@ -28,30 +28,59 @@ /* add a blob to a smb2_create attribute blob */ -NTSTATUS smb2_create_blob_add(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, - const char *tag, - DATA_BLOB add, bool last) +static NTSTATUS smb2_create_blob_push_one(TALLOC_CTX *mem_ctx, DATA_BLOB *buffer, + const struct smb2_create_blob *blob, + bool last) { - uint32_t ofs = blob->length; - size_t tag_length = strlen(tag); - uint8_t pad = smb2_padding_size(add.length+tag_length, 8); - if (!data_blob_realloc(mem_ctx, blob, - blob->length + 0x14 + tag_length + add.length + pad)) + uint32_t ofs = buffer->length; + size_t tag_length = strlen(blob->tag); + uint8_t pad = smb2_padding_size(blob->data.length+tag_length, 4); + + if (!data_blob_realloc(mem_ctx, buffer, + buffer->length + 0x14 + tag_length + blob->data.length + pad)) return NT_STATUS_NO_MEMORY; - + if (last) { - SIVAL(blob->data, ofs+0x00, 0); + SIVAL(buffer->data, ofs+0x00, 0); } else { - SIVAL(blob->data, ofs+0x00, 0x14 + tag_length + add.length + pad); + SIVAL(buffer->data, ofs+0x00, 0x14 + tag_length + blob->data.length + pad); } - SSVAL(blob->data, ofs+0x04, 0x10); /* offset of tag */ - SIVAL(blob->data, ofs+0x06, tag_length); /* tag length */ - SSVAL(blob->data, ofs+0x0A, 0x14 + tag_length); /* offset of data */ - SIVAL(blob->data, ofs+0x0C, add.length); - memcpy(blob->data+ofs+0x10, tag, tag_length); - SIVAL(blob->data, ofs+0x10+tag_length, 0); /* pad? */ - memcpy(blob->data+ofs+0x14+tag_length, add.data, add.length); - memset(blob->data+ofs+0x14+tag_length+add.length, 0, pad); + SSVAL(buffer->data, ofs+0x04, 0x10); /* offset of tag */ + SIVAL(buffer->data, ofs+0x06, tag_length); /* tag length */ + SSVAL(buffer->data, ofs+0x0A, 0x14 + tag_length); /* offset of data */ + SIVAL(buffer->data, ofs+0x0C, blob->data.length); + memcpy(buffer->data+ofs+0x10, blob->tag, tag_length); + SIVAL(buffer->data, ofs+0x10+tag_length, 0); /* pad? */ + memcpy(buffer->data+ofs+0x14+tag_length, blob->data.data, blob->data.length); + memset(buffer->data+ofs+0x14+tag_length+blob->data.length, 0, pad); + + return NT_STATUS_OK; +} + +NTSTATUS smb2_create_blob_add(TALLOC_CTX *mem_ctx, struct smb2_create_blobs *b, + const char *tag, DATA_BLOB data) +{ + struct smb2_create_blob *array; + + array = talloc_realloc(mem_ctx, b->blobs, + struct smb2_create_blob, + b->num_blobs + 1); + NT_STATUS_HAVE_NO_MEMORY(array); + b->blobs = array; + + b->blobs[b->num_blobs].tag = talloc_strdup(b->blobs, tag); + NT_STATUS_HAVE_NO_MEMORY(b->blobs[b->num_blobs].tag); + + if (data.data) { + b->blobs[b->num_blobs].data = data_blob_talloc(b->blobs, + data.data, + data.length); + NT_STATUS_HAVE_NO_MEMORY(b->blobs[b->num_blobs].data.data); + } else { + b->blobs[b->num_blobs].data = data_blob(NULL, 0); + } + + b->num_blobs += 1; return NT_STATUS_OK; } @@ -64,6 +93,7 @@ struct smb2_request *smb2_create_send(struct smb2_tree *tree, struct smb2_create struct smb2_request *req; NTSTATUS status; DATA_BLOB blob = data_blob(NULL, 0); + uint32_t i; req = smb2_request_init_tree(tree, SMB2_OP_CREATE, 0x38, true, 0); if (req == NULL) return NULL; @@ -89,7 +119,8 @@ struct smb2_request *smb2_create_send(struct smb2_tree *tree, struct smb2_create DATA_BLOB b = data_blob_talloc(req, NULL, ea_list_size_chained(io->in.eas.num_eas, io->in.eas.eas)); ea_put_list_chained(b.data, io->in.eas.num_eas, io->in.eas.eas); - status = smb2_create_blob_add(req, &blob, SMB2_CREATE_TAG_EXTA, b, false); + status = smb2_create_blob_add(req, &io->in.blobs, + SMB2_CREATE_TAG_EXTA, b); if (!NT_STATUS_IS_OK(status)) { talloc_free(req); return NULL; @@ -99,13 +130,30 @@ struct smb2_request *smb2_create_send(struct smb2_tree *tree, struct smb2_create /* an empty MxAc tag seems to be used to ask the server to return the maximum access mask allowed on the file */ - status = smb2_create_blob_add(req, &blob, SMB2_CREATE_TAG_MXAC, - data_blob(NULL, 0), true); - + status = smb2_create_blob_add(req, &io->in.blobs, + SMB2_CREATE_TAG_MXAC, data_blob(NULL, 0)); if (!NT_STATUS_IS_OK(status)) { talloc_free(req); return NULL; } + + for (i=0; i < io->in.blobs.num_blobs; i++) { + bool last = false; + const struct smb2_create_blob *c; + + if ((i + 1) == io->in.blobs.num_blobs) { + last = true; + } + + c = &io->in.blobs.blobs[i]; + status = smb2_create_blob_push_one(req, &blob, + c, last); + if (!NT_STATUS_IS_OK(status)) { + talloc_free(req); + return NULL; + } + } + status = smb2_push_o32s32_blob(&req->out, 0x30, blob); if (!NT_STATUS_IS_OK(status)) { talloc_free(req); diff --git a/source/samba4-knownfail b/source/samba4-knownfail index 496af31..e7d2980 100644 --- a/source/samba4-knownfail +++ b/source/samba4-knownfail @@ -33,3 +33,4 @@ rpc.netlogon.*.GetTrustPasswords base.charset.*.Testing partial surrogate .*net.api.delshare.* # DelShare isn't implemented yet rap.*netservergetinfo +smb2.persistent.handles1 diff --git a/source/smb_server/smb2/fileio.c b/source/smb_server/smb2/fileio.c index 8f8b4e7..af1a413 100644 --- a/source/smb_server/smb2/fileio.c +++ b/source/smb_server/smb2/fileio.c @@ -79,6 +79,7 @@ void smb2srv_create_recv(struct smb2srv_request *req) SMB2SRV_CHECK(smb2_pull_o32s32_blob(&req->in, io, req->in.body+0x30, &blob)); /* TODO: parse the blob */ ZERO_STRUCT(io->smb2.in.eas); + ZERO_STRUCT(io->smb2.in.blobs); /* the VFS backend does not yet handle NULL filenames */ if (io->smb2.in.fname == NULL) { diff --git a/source/torture/smb2/config.mk b/source/torture/smb2/config.mk index 379632f..12d5edb 100644 --- a/source/torture/smb2/config.mk +++ b/source/torture/smb2/config.mk @@ -20,5 +20,6 @@ TORTURE_SMB2_OBJ_FILES = $(addprefix torture/smb2/, \ find.o \ lock.o \ notify.o \ - smb2.o) + smb2.o \ + persistent_handles.o) diff --git a/source/torture/smb2/persistent_handles.c b/source/torture/smb2/persistent_handles.c new file mode 100644 index 0000000..d08714d --- /dev/null +++ b/source/torture/smb2/persistent_handles.c @@ -0,0 +1,162 @@ +/* + 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 <http://www.gnu.org/licenses/>. +*/ + +#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" +#include "param/param.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 io; + NTSTATUS status; + const char *fname = "persistent_handles.dat"; + DATA_BLOB b; + union smb_fileinfo qfinfo; + union smb_setfileinfo sfinfo; + bool ret = true; + + ZERO_STRUCT(io); + io.in.security_flags = 0x00; + io.in.oplock_level = SMB2_OPLOCK_LEVEL_BATCH; + io.in.impersonation_level = NTCREATEX_IMPERSONATION_IMPERSONATION; + io.in.create_flags = 0x00000000; + io.in.reserved = 0x00000000; + io.in.desired_access = SEC_RIGHTS_FILE_READ; + io.in.file_attributes = 0x00000000; + io.in.share_access = NTCREATEX_SHARE_ACCESS_READ | + NTCREATEX_SHARE_ACCESS_DELETE; + io.in.create_disposition = NTCREATEX_DISP_OPEN_IF; + io.in.create_options = NTCREATEX_OPTIONS_SEQUENTIAL_ONLY | + NTCREATEX_OPTIONS_ASYNC_ALERT | + NTCREATEX_OPTIONS_NON_DIRECTORY_FILE | + 0x00200000; + io.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, &io.in.blobs, + SMB2_CREATE_TAG_DHNQ, + b); + CHECK_STATUS(status, NT_STATUS_OK); + + status = smb2_create(tree1, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OK); + + h1 = io.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); + printf("position: %llu\n", + (unsigned long long)qfinfo.position_information.out.position); + + 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); + printf("position: %llu\n", + (unsigned long long)qfinfo.position_information.out.position); + + 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(io); + io.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, &io.in.blobs, + SMB2_CREATE_TAG_DHNC, + b); + CHECK_STATUS(status, NT_STATUS_OK); + if (!NT_STATUS_IS_OK(status)) { + printf("create1 failed - %s\n", nt_errstr(status)); + return false; + } + + status = smb2_create(tree2, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OK); + + h2 = io.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); + printf("position: %llu\n", + (unsigned long long)qfinfo.position_information.out.position); + + talloc_free(mem_ctx); + +done: + return ret; +} diff --git a/source/torture/smb2/smb2.c b/source/torture/smb2/smb2.c index d076112..80b2d25 100644 --- a/source/torture/smb2/smb2.c +++ b/source/torture/smb2/smb2.c @@ -47,9 +47,9 @@ static bool wrap_simple_1smb2_test(struct torture_context *torture_ctx, } struct torture_test *torture_suite_add_1smb2_test(struct torture_suite *suite, - const char *name, - bool (*run) (struct torture_context *, - struct smb2_tree *)) + const char *name, + bool (*run)(struct torture_context *, + struct smb2_tree *)) { struct torture_test *test; struct torture_tcase *tcase; @@ -69,6 +69,61 @@ struct torture_test *torture_suite_add_1smb2_test(struct torture_suite *suite, return test; } + +static bool wrap_simple_2smb2_test(struct torture_context *torture_ctx, + struct torture_tcase *tcase, + struct torture_test *test) +{ + bool (*fn) (struct torture_context *, struct smb2_tree *, struct smb2_tree *); + bool ret; + + struct smb2_tree *tree1; + struct smb2_tree *tree2; + TALLOC_CTX *mem_ctx = talloc_new(torture_ctx); + + if (!torture_smb2_connection(torture_ctx, &tree1) || + !torture_smb2_connection(torture_ctx, &tree2)) { + return false; + } + + talloc_steal(mem_ctx, tree1); + talloc_steal(mem_ctx, tree2); + + fn = test->fn; + + ret = fn(torture_ctx, tree1, tree2); + + /* the test may already closed some of the connections */ + talloc_free(mem_ctx); + + return ret; +} + + +_PUBLIC_ struct torture_test *torture_suite_add_2smb2_test(struct torture_suite *suite, + const char *name, + bool (*run)(struct torture_context *, + struct smb2_tree *, + struct smb2_tree *)) +{ + struct torture_test *test; + struct torture_tcase *tcase; + + tcase = torture_suite_add_tcase(suite, name); + + test = talloc(tcase, struct torture_test); + + test->name = talloc_strdup(test, name); + test->description = NULL; + test->run = wrap_simple_2smb2_test; + test->fn = run; + test->dangerous = false; + + DLIST_ADD_END(tcase->tests, test, struct torture_test *); + + return test; +} + NTSTATUS torture_smb2_init(void) { struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "SMB2"); @@ -82,6 +137,7 @@ NTSTATUS torture_smb2_init(void) torture_suite_add_simple_test(suite, "FIND", torture_smb2_find); torture_suite_add_suite(suite, torture_smb2_lock_init()); torture_suite_add_simple_test(suite, "NOTIFY", torture_smb2_notify); + torture_suite_add_2smb2_test(suite, "PERSISTENT-HANDLES1", torture_smb2_persistent_handles1); suite->description = talloc_strdup(suite, "SMB2-specific tests"); -- Samba Shared Repository