summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2006-05-22 17:42:14 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:08:27 -0500
commit20532d7c495d75e35453ce22c383fe24925e8f00 (patch)
tree602d487ed3fff0e069b558c19b7c4aa167e85d56
parenta2f463bb3a66393f3934b465e73caab191277c6d (diff)
downloadsamba-20532d7c495d75e35453ce22c383fe24925e8f00.tar.gz
samba-20532d7c495d75e35453ce22c383fe24925e8f00.tar.bz2
samba-20532d7c495d75e35453ce22c383fe24925e8f00.zip
r15816: add SMB2-LOCK torture test, which demonstrates what possible valid and invalid
requests you can do with it metze (This used to be commit adef1372c118b6c116dfa976d0277be677118fd0)
-rw-r--r--source4/torture/smb2/config.mk3
-rw-r--r--source4/torture/smb2/lock.c215
-rw-r--r--source4/torture/torture.c1
3 files changed, 218 insertions, 1 deletions
diff --git a/source4/torture/smb2/config.mk b/source4/torture/smb2/config.mk
index 6095b3951d..d53b9895d1 100644
--- a/source4/torture/smb2/config.mk
+++ b/source4/torture/smb2/config.mk
@@ -10,7 +10,8 @@ OBJ_FILES = \
util.o \
getinfo.o \
setinfo.o \
- find.o
+ find.o \
+ lock.o
PUBLIC_DEPENDENCIES = \
LIBCLI_SMB2 POPT_CREDENTIALS
# End SUBSYSTEM TORTURE_SMB2
diff --git a/source4/torture/smb2/lock.c b/source4/torture/smb2/lock.c
new file mode 100644
index 0000000000..0bc90e126d
--- /dev/null
+++ b/source4/torture/smb2/lock.c
@@ -0,0 +1,215 @@
+/*
+ Unix SMB/CIFS implementation.
+
+ SMB2 lock test suite
+
+ Copyright (C) Stefan Metzmacher
+
+ 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"
+
+#define CHECK_STATUS(status, correct) do { \
+ if (!NT_STATUS_EQUAL(status, correct)) { \
+ printf("(%s) Incorrect status %s - should be %s\n", \
+ __location__, nt_errstr(status), nt_errstr(correct)); \
+ ret = False; \
+ goto done; \
+ }} while (0)
+
+#define CHECK_VALUE(v, correct) do { \
+ if ((v) != (correct)) { \
+ printf("(%s) Incorrect value %s=%d - should be %d\n", \
+ __location__, #v, v, correct); \
+ ret = False; \
+ goto done; \
+ }} while (0)
+
+static BOOL test_valid_request(TALLOC_CTX *mem_ctx, struct smb2_tree *tree)
+{
+ BOOL ret = True;
+ NTSTATUS status;
+ struct smb2_handle h;
+ uint8_t buf[200];
+ struct smb2_lock lck;
+
+ ZERO_STRUCT(buf);
+
+ status = torture_smb2_testfile(tree, "lock1.txt", &h);
+ CHECK_STATUS(status, NT_STATUS_OK);
+
+ status = smb2_util_write(tree, h, buf, 0, ARRAY_SIZE(buf));
+ CHECK_STATUS(status, NT_STATUS_OK);
+
+ lck.in.unknown1 = 0x0000;
+ lck.in.unknown2 = 0x00000000;
+ lck.in.file.handle = h;
+ lck.in.offset = 0x0000000000000000;
+ lck.in.count = 0x0000000000000000;
+ lck.in.unknown5 = 0x0000000000000000;
+ lck.in.flags = 0x00000000;
+ status = smb2_lock(tree, &lck);
+ CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER);
+
+ lck.in.unknown1 = 0x0001;
+ lck.in.unknown2 = 0x00000000;
+ lck.in.file.handle = h;
+ lck.in.offset = 0;
+ lck.in.count = 0;
+ lck.in.unknown5 = 0x00000000;
+ lck.in.flags = SMB2_LOCK_FLAG_NONE;
+ status = smb2_lock(tree, &lck);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ CHECK_VALUE(lck.out.unknown1, 0);
+
+ lck.in.file.handle.data[0] +=1;
+ status = smb2_lock(tree, &lck);
+ CHECK_STATUS(status, NT_STATUS_NOT_FOUND);
+ lck.in.file.handle.data[0] -=1;
+
+ lck.in.unknown1 = 0x0001;
+ lck.in.unknown2 = 0xFFFFFFFF;
+ lck.in.file.handle = h;
+ lck.in.offset = UINT64_MAX;
+ lck.in.count = UINT64_MAX;
+ lck.in.unknown5 = 0x00000000;
+ lck.in.flags = SMB2_LOCK_FLAG_EXCLUSIV;
+ status = smb2_lock(tree, &lck);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ CHECK_VALUE(lck.out.unknown1, 0);
+
+ status = smb2_lock(tree, &lck);
+ CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
+
+ status = smb2_lock(tree, &lck);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ CHECK_VALUE(lck.out.unknown1, 0);
+
+ status = smb2_lock(tree, &lck);
+ CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
+
+ status = smb2_lock(tree, &lck);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ CHECK_VALUE(lck.out.unknown1, 0);
+
+ lck.in.unknown1 = 0x0001;
+ lck.in.unknown2 = 0x12345678;
+ lck.in.file.handle = h;
+ lck.in.offset = UINT32_MAX;
+ lck.in.count = UINT32_MAX;
+ lck.in.unknown5 = 0x87654321;
+ lck.in.flags = SMB2_LOCK_FLAG_EXCLUSIV;
+ status = smb2_lock(tree, &lck);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ CHECK_VALUE(lck.out.unknown1, 0);
+
+ status = smb2_lock(tree, &lck);
+ CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
+
+ status = smb2_lock(tree, &lck);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ CHECK_VALUE(lck.out.unknown1, 0);
+
+ status = smb2_lock(tree, &lck);
+ CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED);
+
+ status = smb2_lock(tree, &lck);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ CHECK_VALUE(lck.out.unknown1, 0);
+
+ lck.in.flags = 0x00000000;
+ status = smb2_lock(tree, &lck);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ CHECK_VALUE(lck.out.unknown1, 0);
+
+ status = smb2_lock(tree, &lck);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ CHECK_VALUE(lck.out.unknown1, 0);
+
+ lck.in.flags = 0x00000001;
+ status = smb2_lock(tree, &lck);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ CHECK_VALUE(lck.out.unknown1, 0);
+
+ status = smb2_lock(tree, &lck);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ CHECK_VALUE(lck.out.unknown1, 0);
+
+ lck.in.unknown1 = 0x0001;
+ lck.in.unknown2 = 0x87654321;
+ lck.in.file.handle = h;
+ lck.in.offset = 0x00000000FFFFFFFF;
+ lck.in.count = 0x00000000FFFFFFFF;
+ lck.in.unknown5 = 0x12345678;
+ lck.in.flags = SMB2_LOCK_FLAG_UNLOCK;
+ status = smb2_lock(tree, &lck);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ CHECK_VALUE(lck.out.unknown1, 0);
+
+ lck.in.unknown1 = 0x0001;
+ lck.in.unknown2 = 0x12345678;
+ lck.in.file.handle = h;
+ lck.in.offset = 0x00000000FFFFFFFF;
+ lck.in.count = 0x00000000FFFFFFFF;
+ lck.in.unknown5 = 0x00000000;
+ lck.in.flags = SMB2_LOCK_FLAG_UNLOCK;
+ status = smb2_lock(tree, &lck);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ CHECK_VALUE(lck.out.unknown1, 0);
+
+ status = smb2_lock(tree, &lck);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ CHECK_VALUE(lck.out.unknown1, 0);
+ status = smb2_lock(tree, &lck);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ CHECK_VALUE(lck.out.unknown1, 0);
+ status = smb2_lock(tree, &lck);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ CHECK_VALUE(lck.out.unknown1, 0);
+ status = smb2_lock(tree, &lck);
+ CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
+ status = smb2_lock(tree, &lck);
+ CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
+ status = smb2_lock(tree, &lck);
+ CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
+
+done:
+ return ret;
+}
+
+/* basic testing of SMB2 locking
+*/
+BOOL torture_smb2_lock(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 &= test_valid_request(mem_ctx, tree);
+
+ talloc_free(mem_ctx);
+
+ return ret;
+}
diff --git a/source4/torture/torture.c b/source4/torture/torture.c
index 689de7c5f8..706bb43e2a 100644
--- a/source4/torture/torture.c
+++ b/source4/torture/torture.c
@@ -624,6 +624,7 @@ static struct {
{"SMB2-GETINFO", torture_smb2_getinfo, 0},
{"SMB2-SETINFO", torture_smb2_setinfo, 0},
{"SMB2-FIND", torture_smb2_find, 0},
+ {"SMB2-LOCK", torture_smb2_lock, 0},
/* RAP tests */
{"RAP-BASIC", torture_rap_basic, 0},