summaryrefslogtreecommitdiff
path: root/source4/torture/smb2/maxwrite.c
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2006-09-22 04:04:46 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:19:13 -0500
commit8c3b54f01dfc7275c7ff0ec194cd68ea072a8186 (patch)
tree6d34b821a0993372a937c553a723c0cf174917fa /source4/torture/smb2/maxwrite.c
parent4f913d91cb75377555d2858becde0f34ab7f6f49 (diff)
downloadsamba-8c3b54f01dfc7275c7ff0ec194cd68ea072a8186.tar.gz
samba-8c3b54f01dfc7275c7ff0ec194cd68ea072a8186.tar.bz2
samba-8c3b54f01dfc7275c7ff0ec194cd68ea072a8186.zip
r18808: added SMB2-MAXWRITE test and SMB2-DIR tests
expanded size of dangerous level for write in SMB2-CONNECT test (This used to be commit 355c6e78a91f4e934479829e722f873ca7e66baf)
Diffstat (limited to 'source4/torture/smb2/maxwrite.c')
-rw-r--r--source4/torture/smb2/maxwrite.c126
1 files changed, 126 insertions, 0 deletions
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;
+}