diff options
Diffstat (limited to 'source4/torture/smb2/lock.c')
-rw-r--r-- | source4/torture/smb2/lock.c | 118 |
1 files changed, 107 insertions, 11 deletions
diff --git a/source4/torture/smb2/lock.c b/source4/torture/smb2/lock.c index ac642a7d0b..a932145db9 100644 --- a/source4/torture/smb2/lock.c +++ b/source4/torture/smb2/lock.c @@ -27,6 +27,8 @@ #include "torture/torture.h" #include "torture/smb2/proto.h" +#include "librpc/gen_ndr/ndr_security.h" + #define CHECK_STATUS(status, correct) do { \ if (!NT_STATUS_EQUAL(status, correct)) { \ printf("(%s) Incorrect status %s - should be %s\n", \ @@ -43,7 +45,7 @@ goto done; \ }} while (0) -static BOOL test_valid_request(TALLOC_CTX *mem_ctx, struct smb2_tree *tree) +static BOOL test_valid_request(struct torture_context *torture, struct smb2_tree *tree) { BOOL ret = True; NTSTATUS status; @@ -195,21 +197,115 @@ done: return ret; } -/* basic testing of SMB2 locking -*/ -BOOL torture_smb2_lock(struct torture_context *torture) +static BOOL test_block_write(struct torture_context *torture, struct smb2_tree *tree) { - TALLOC_CTX *mem_ctx = talloc_new(NULL); - struct smb2_tree *tree; BOOL ret = True; + NTSTATUS status; + struct smb2_handle h1, h2; + uint8_t buf[200]; + struct smb2_lock lck; + struct smb2_create cr; + struct smb2_write wr; + const char *fname = "lock2.txt"; + + ZERO_STRUCT(buf); + + status = torture_smb2_testfile(tree, fname, &h1); + CHECK_STATUS(status, NT_STATUS_OK); + + status = smb2_util_write(tree, h1, buf, 0, ARRAY_SIZE(buf)); + CHECK_STATUS(status, NT_STATUS_OK); + + lck.in.unknown1 = 0x0001; + lck.in.unknown2 = 0x00000000; + lck.in.file.handle = h1; + lck.in.offset = 0; + lck.in.count = ARRAY_SIZE(buf)/2; + 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); + + lck.in.unknown1 = 0x0001; + lck.in.unknown2 = 0x00000000; + lck.in.file.handle = h1; + lck.in.offset = ARRAY_SIZE(buf)/2; + lck.in.count = ARRAY_SIZE(buf)/2; + 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); + + ZERO_STRUCT(cr); + cr.in.oplock_flags = 0; + cr.in.access_mask = SEC_RIGHTS_FILE_ALL; + cr.in.file_attr = FILE_ATTRIBUTE_NORMAL; + cr.in.open_disposition = NTCREATEX_DISP_OPEN_IF; + cr.in.share_access = + NTCREATEX_SHARE_ACCESS_DELETE| + NTCREATEX_SHARE_ACCESS_READ| + NTCREATEX_SHARE_ACCESS_WRITE; + cr.in.create_options = 0; + cr.in.fname = fname; + + status = smb2_create(tree, tree, &cr); + CHECK_STATUS(status, NT_STATUS_OK); + + h2 = cr.out.file.handle; + + + ZERO_STRUCT(wr); + wr.in.file.handle = h1; + wr.in.offset = ARRAY_SIZE(buf)/2; + wr.in.data = data_blob_const(buf, ARRAY_SIZE(buf)/2); + + status = smb2_write(tree, &wr); + CHECK_STATUS(status, NT_STATUS_OK); + + ZERO_STRUCT(wr); + wr.in.file.handle = h2; + wr.in.offset = ARRAY_SIZE(buf)/2; + wr.in.data = data_blob_const(buf, ARRAY_SIZE(buf)/2); - if (!torture_smb2_connection(mem_ctx, &tree)) { - return False; - } + status = smb2_write(tree, &wr); + CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT); + + lck.in.unknown1 = 0x0001; + lck.in.unknown2 = 0x00000000; + lck.in.file.handle = h1; + lck.in.offset = ARRAY_SIZE(buf)/2; + lck.in.count = ARRAY_SIZE(buf)/2; + 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); - ret &= test_valid_request(mem_ctx, tree); + ZERO_STRUCT(wr); + wr.in.file.handle = h2; + wr.in.offset = ARRAY_SIZE(buf)/2; + wr.in.data = data_blob_const(buf, ARRAY_SIZE(buf)/2); - talloc_free(mem_ctx); + status = smb2_write(tree, &wr); + CHECK_STATUS(status, NT_STATUS_OK); +done: return ret; } + +/* basic testing of SMB2 locking +*/ +struct torture_suite *torture_smb2_lock_init(void) +{ + struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "LOCK"); + + torture_suite_add_1smb2_test(suite, "VALID-REQUEST", test_valid_request); + torture_suite_add_1smb2_test(suite, "BLOCK-WRITE", test_block_write); + + suite->description = talloc_strdup(suite, "SMB2-LOCK tests"); + + return suite; +} + |