summaryrefslogtreecommitdiff
path: root/source4/torture/smb2
diff options
context:
space:
mode:
Diffstat (limited to 'source4/torture/smb2')
-rw-r--r--source4/torture/smb2/config.mk2
-rw-r--r--source4/torture/smb2/connect.c9
-rw-r--r--source4/torture/smb2/dir.c94
-rw-r--r--source4/torture/smb2/maxwrite.c126
-rw-r--r--source4/torture/smb2/smb2.c2
5 files changed, 230 insertions, 3 deletions
diff --git a/source4/torture/smb2/config.mk b/source4/torture/smb2/config.mk
index 6403f231f5..b24c1642a1 100644
--- a/source4/torture/smb2/config.mk
+++ b/source4/torture/smb2/config.mk
@@ -8,6 +8,8 @@ PRIVATE_PROTO_HEADER = \
proto.h
OBJ_FILES = \
connect.o \
+ dir.o \
+ maxwrite.o \
scan.o \
util.o \
getinfo.o \
diff --git a/source4/torture/smb2/connect.c b/source4/torture/smb2/connect.c
index 9f36e4d707..bb6ba0c39d 100644
--- a/source4/torture/smb2/connect.c
+++ b/source4/torture/smb2/connect.c
@@ -75,7 +75,7 @@ static NTSTATUS torture_smb2_write(struct smb2_tree *tree, struct smb2_handle ha
int i;
if (lp_parm_bool(-1, "torture", "dangerous", False)) {
- data = data_blob_talloc(tree, NULL, 160000);
+ data = data_blob_talloc(tree, NULL, 16000000);
} else if (lp_parm_bool(-1, "target", "samba4", False)) {
data = data_blob_talloc(tree, NULL, UINT16_MAX);
} else {
@@ -90,6 +90,8 @@ static NTSTATUS torture_smb2_write(struct smb2_tree *tree, struct smb2_handle ha
w.in.offset = 0;
w.in.data = data;
+ printf("writing %d bytes\n", data.length);
+
status = smb2_write(tree, &w);
if (!NT_STATUS_IS_OK(status)) {
printf("write failed - %s\n", nt_errstr(status));
@@ -120,6 +122,8 @@ static NTSTATUS torture_smb2_write(struct smb2_tree *tree, struct smb2_handle ha
r.in.length = data.length;
r.in.offset = 0;
+ printf("reading %d bytes\n", data.length);
+
status = smb2_read(tree, tree, &r);
if (!NT_STATUS_IS_OK(status)) {
printf("read failed - %s\n", nt_errstr(status));
@@ -139,8 +143,7 @@ static NTSTATUS torture_smb2_write(struct smb2_tree *tree, struct smb2_handle ha
/*
send a create
*/
-static struct smb2_handle torture_smb2_create(struct smb2_tree *tree,
- const char *fname)
+struct smb2_handle torture_smb2_create(struct smb2_tree *tree, const char *fname)
{
struct smb2_create io;
NTSTATUS status;
diff --git a/source4/torture/smb2/dir.c b/source4/torture/smb2/dir.c
new file mode 100644
index 0000000000..c30adb1e41
--- /dev/null
+++ b/source4/torture/smb2/dir.c
@@ -0,0 +1,94 @@
+/*
+ Unix SMB/CIFS implementation.
+
+ SMB2 dir list test suite
+
+ Copyright (C) Andrew Tridgell 2005
+
+ 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 2 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, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include "includes.h"
+#include "libcli/smb2/smb2.h"
+#include "libcli/smb2/smb2_calls.h"
+
+#include "torture/torture.h"
+#include "torture/smb2/proto.h"
+
+/*
+ test find continue
+*/
+static BOOL torture_smb2_find_dir(struct smb2_tree *tree)
+{
+ struct smb2_handle handle;
+ NTSTATUS status;
+ int i;
+ struct smb2_find f;
+ BOOL ret = True;
+ union smb_search_data *d;
+ uint_t count;
+
+ status = smb2_util_roothandle(tree, &handle);
+ if (!NT_STATUS_IS_OK(status)) {
+ return False;
+ }
+
+ ZERO_STRUCT(f);
+ f.in.file.handle = handle;
+ f.in.pattern = "*";
+ f.in.continue_flags = SMB2_CONTINUE_FLAG_SINGLE;
+ f.in.max_response_size = 0x100;
+ f.in.level = SMB2_FIND_BOTH_DIRECTORY_INFO;
+
+ do {
+ status = smb2_find_level(tree, tree, &f, &count, &d);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("SMB2_FIND_ID_BOTH_DIRECTORY_INFO failed - %s\n", nt_errstr(status));
+ break;
+ }
+
+ printf("Got %d files\n", count);
+ for (i=0;i<count;i++) {
+ printf("\t'%s'\n",
+ d[i].both_directory_info.name.s);
+ }
+ f.in.continue_flags = 0;
+ f.in.max_response_size = 4096;
+ } while (count != 0);
+
+
+ return ret;
+}
+
+
+/*
+ basic testing of directory listing with continue
+*/
+BOOL torture_smb2_dir(struct torture_context *torture)
+{
+ TALLOC_CTX *mem_ctx = talloc_new(NULL);
+ struct smb2_tree *tree;
+ BOOL ret = True;
+
+ if (!torture_smb2_connection(mem_ctx, &tree)) {
+ return False;
+ }
+
+ ret &= torture_smb2_find_dir(tree);
+
+ talloc_free(mem_ctx);
+
+ return ret;
+}
diff --git a/source4/torture/smb2/maxwrite.c b/source4/torture/smb2/maxwrite.c
new file mode 100644
index 0000000000..b9ca46437d
--- /dev/null
+++ b/source4/torture/smb2/maxwrite.c
@@ -0,0 +1,126 @@
+/*
+ Unix SMB/CIFS implementation.
+
+ test suite for SMB2 write operations
+
+ Copyright (C) Andrew Tridgell 2006
+
+ 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 2 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, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#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"
+
+/*
+ test writing
+*/
+static NTSTATUS torture_smb2_write(TALLOC_CTX *mem_ctx,
+ struct smb2_tree *tree, struct smb2_handle handle)
+{
+ struct smb2_write w;
+ struct smb2_read r;
+ NTSTATUS status;
+ int i, len;
+ int max = 10000000;
+ int min = 1;
+
+ while (max > min) {
+ TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
+
+
+ len = 1+(min+max)/2;
+
+ ZERO_STRUCT(w);
+ w.in.file.handle = handle;
+ w.in.offset = 0;
+ w.in.data = data_blob_talloc(tmp_ctx, NULL, len);
+
+ for (i=0;i<len;i++) {
+ w.in.data.data[i] = i % 256;
+ }
+
+ printf("trying to write %d bytes (min=%d max=%d)\n",
+ len, min, max);
+
+ status = smb2_write(tree, &w);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("write failed - %s\n", nt_errstr(status));
+ max = len-1;
+ talloc_free(tree);
+ if (!torture_smb2_connection(mem_ctx, &tree)) {
+ printf("failed to reconnect\n");
+ return NT_STATUS_NET_WRITE_FAULT;
+ }
+ handle = torture_smb2_create(tree, "test9.dat");
+ continue;
+ } else {
+ min = len;
+ }
+
+
+ ZERO_STRUCT(r);
+ r.in.file.handle = handle;
+ r.in.length = len;
+ r.in.offset = 0;
+
+ printf("reading %d bytes\n", len);
+
+ status = smb2_read(tree, tmp_ctx, &r);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("read failed - %s\n", nt_errstr(status));
+ } else if (w.in.data.length != r.out.data.length ||
+ memcmp(w.in.data.data, r.out.data.data, len) != 0) {
+ printf("read data mismatch\n");
+ }
+
+ talloc_free(tmp_ctx);
+ }
+
+ printf("converged: len=%d\n", max);
+
+ return status;
+}
+
+
+
+/*
+ basic testing of SMB2 connection calls
+*/
+BOOL torture_smb2_maxwrite(struct torture_context *torture)
+{
+ TALLOC_CTX *mem_ctx = talloc_new(NULL);
+ struct smb2_tree *tree;
+ struct smb2_handle h1;
+ NTSTATUS status;
+
+ if (!torture_smb2_connection(mem_ctx, &tree)) {
+ return False;
+ }
+
+ h1 = torture_smb2_create(tree, "test9.dat");
+ status = torture_smb2_write(mem_ctx, tree, h1);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("Write failed - %s\n", nt_errstr(status));
+ return False;
+ }
+
+ talloc_free(mem_ctx);
+
+ return True;
+}
diff --git a/source4/torture/smb2/smb2.c b/source4/torture/smb2/smb2.c
index 7417de851d..cb0401b5d6 100644
--- a/source4/torture/smb2/smb2.c
+++ b/source4/torture/smb2/smb2.c
@@ -37,6 +37,8 @@ NTSTATUS torture_smb2_init(void)
register_torture_op("SMB2-FIND", torture_smb2_find);
register_torture_op("SMB2-LOCK", torture_smb2_lock);
register_torture_op("SMB2-NOTIFY", torture_smb2_notify);
+ register_torture_op("SMB2-MAXWRITE", torture_smb2_maxwrite);
+ register_torture_op("SMB2-DIR", torture_smb2_dir);
return NT_STATUS_OK;
}