diff options
author | Andrew Tridgell <tridge@samba.org> | 2008-05-21 22:12:20 +1000 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 2008-05-21 22:12:20 +1000 |
commit | 4d39976dddf2adf6a0d659050c3a21a6e0ff8ab2 (patch) | |
tree | ed2ef4b86ae4b1629d91a7605a262e64703e3859 /source4/torture | |
parent | af61219f365ae94f3c797b7450d0ea0e00ad0b11 (diff) | |
download | samba-4d39976dddf2adf6a0d659050c3a21a6e0ff8ab2.tar.gz samba-4d39976dddf2adf6a0d659050c3a21a6e0ff8ab2.tar.bz2 samba-4d39976dddf2adf6a0d659050c3a21a6e0ff8ab2.zip |
fixed SMB2 locking
- SMB2 locking is different in several ways from SMB locking. To fix
it properly we will need a new generic mapping structure for
locking, but for now do a best effort mapping
- added locking to gentest_smb2
(This used to be commit ea6d9cf602302adafe0f9d5f5f90a9b26d1ead6f)
Diffstat (limited to 'source4/torture')
-rw-r--r-- | source4/torture/gentest_smb2.c | 57 | ||||
-rw-r--r-- | source4/torture/smb2/lock.c | 148 |
2 files changed, 105 insertions, 100 deletions
diff --git a/source4/torture/gentest_smb2.c b/source4/torture/gentest_smb2.c index 9c4be90b3c..68e9e2c20b 100644 --- a/source4/torture/gentest_smb2.c +++ b/source4/torture/gentest_smb2.c @@ -530,13 +530,16 @@ static uint16_t gen_rename_flags(void) /* - return a lockingx lock mode + return a set of lock flags */ -static uint16_t gen_lock_mode(void) +static uint16_t gen_lock_flags(void) { if (gen_chance(5)) return gen_bits_mask(0xFFFF); if (gen_chance(20)) return gen_bits_mask(0x1F); - return gen_bits_mask(LOCKING_ANDX_SHARED_LOCK | LOCKING_ANDX_LARGE_FILES); + if (gen_chance(50)) return SMB2_LOCK_FLAG_UNLOCK; + return gen_bits_mask(SMB2_LOCK_FLAG_SHARED | + SMB2_LOCK_FLAG_EXCLUSIVE | + SMB2_LOCK_FLAG_FAIL_IMMEDIATELY); } /* @@ -1135,46 +1138,41 @@ static bool handler_write(int instance) return true; } -#if 0 /* generate lockingx operations */ static bool handler_lock(int instance) { - union smb_lock parm[NSERVERS]; + struct smb2_lock parm[NSERVERS]; NTSTATUS status[NSERVERS]; - int n, nlocks; + int n; - parm[0].lockx.level = RAW_LOCK_LOCKX; - parm[0].lockx.in.file.fnum = gen_fnum(instance); - parm[0].lockx.in.mode = gen_lock_mode(); - parm[0].lockx.in.timeout = gen_timeout(); - do { - /* make sure we don't accidentially generate an oplock - break ack - otherwise the server can just block forever */ - parm[0].lockx.in.ulock_cnt = gen_lock_count(); - parm[0].lockx.in.lock_cnt = gen_lock_count(); - nlocks = parm[0].lockx.in.ulock_cnt + parm[0].lockx.in.lock_cnt; - } while (nlocks == 0); - - if (nlocks > 0) { - parm[0].lockx.in.locks = talloc_array(current_op.mem_ctx, - struct smb_lock_entry, - nlocks); - for (n=0;n<nlocks;n++) { - parm[0].lockx.in.locks[n].pid = gen_pid(); - parm[0].lockx.in.locks[n].offset = gen_offset(); - parm[0].lockx.in.locks[n].count = gen_io_count(); - } + parm[0].level = RAW_LOCK_LOCKX; + parm[0].in.file.handle.data[0] = gen_fnum(instance); + parm[0].in.lock_count = gen_lock_count(); + parm[0].in.reserved = gen_bits_mask2(0, 0xFFFFFFFF); + + parm[0].in.locks = talloc_array(current_op.mem_ctx, + struct smb2_lock_element, + parm[0].in.lock_count); + for (n=0;n<parm[0].in.lock_count;n++) { + parm[0].in.locks[n].offset = gen_offset(); + parm[0].in.locks[n].length = gen_io_count(); + /* don't yet cope with async replies */ + parm[0].in.locks[n].flags = gen_lock_flags() | + SMB2_LOCK_FLAG_FAIL_IMMEDIATELY; + parm[0].in.locks[n].reserved = gen_bits_mask2(0x0, 0xFFFFFFFF); } GEN_COPY_PARM; - GEN_SET_FNUM(lockx.in.file.fnum); - GEN_CALL(smb_raw_lock(tree, &parm[i])); + GEN_SET_FNUM(in.file.handle); + GEN_CALL(smb2_lock(tree, &parm[i])); return true; } +#if 0 + /* generate a fileinfo query structure */ @@ -1583,6 +1581,7 @@ static struct { {"CLOSE", handler_close}, {"READ", handler_read}, {"WRITE", handler_write}, + {"LOCK", handler_lock}, }; diff --git a/source4/torture/smb2/lock.c b/source4/torture/smb2/lock.c index 3cf2e93ee0..e81647b497 100644 --- a/source4/torture/smb2/lock.c +++ b/source4/torture/smb2/lock.c @@ -51,6 +51,7 @@ static bool test_valid_request(struct torture_context *torture, struct smb2_tree struct smb2_handle h; uint8_t buf[200]; struct smb2_lock lck; + struct smb2_lock_element el[1]; ZERO_STRUCT(buf); @@ -60,117 +61,119 @@ static bool test_valid_request(struct torture_context *torture, struct smb2_tree 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.locks = el; + + lck.in.lock_count = 0x0000; + lck.in.reserved = 0x00000000; lck.in.file.handle = h; - lck.in.offset = 0x0000000000000000; - lck.in.count = 0x0000000000000000; - lck.in.unknown5 = 0x0000000000000000; - lck.in.flags = 0x00000000; + el[0].offset = 0x0000000000000000; + el[0].length = 0x0000000000000000; + el[0].reserved = 0x0000000000000000; + el[0].flags = 0x00000000; status = smb2_lock(tree, &lck); CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER); - lck.in.unknown1 = 0x0001; - lck.in.unknown2 = 0x00000000; + lck.in.lock_count = 0x0001; + lck.in.reserved = 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; + el[0].offset = 0; + el[0].length = 0; + el[0].reserved = 0x00000000; + el[0].flags = SMB2_LOCK_FLAG_NONE; status = smb2_lock(tree, &lck); CHECK_STATUS(status, NT_STATUS_OK); - CHECK_VALUE(lck.out.unknown1, 0); + CHECK_VALUE(lck.out.reserved, 0); lck.in.file.handle.data[0] +=1; status = smb2_lock(tree, &lck); CHECK_STATUS(status, NT_STATUS_FILE_CLOSED); lck.in.file.handle.data[0] -=1; - lck.in.unknown1 = 0x0001; - lck.in.unknown2 = 0xFFFFFFFF; + lck.in.lock_count = 0x0001; + lck.in.reserved = 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|SMB2_LOCK_FLAG_NO_PENDING; + el[0].offset = UINT64_MAX; + el[0].length = UINT64_MAX; + el[0].reserved = 0x00000000; + el[0].flags = SMB2_LOCK_FLAG_EXCLUSIVE|SMB2_LOCK_FLAG_FAIL_IMMEDIATELY; status = smb2_lock(tree, &lck); CHECK_STATUS(status, NT_STATUS_OK); - CHECK_VALUE(lck.out.unknown1, 0); + CHECK_VALUE(lck.out.reserved, 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); + CHECK_VALUE(lck.out.reserved, 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); + CHECK_VALUE(lck.out.reserved, 0); - lck.in.unknown1 = 0x0001; - lck.in.unknown2 = 0x12345678; + lck.in.lock_count = 0x0001; + lck.in.reserved = 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|SMB2_LOCK_FLAG_NO_PENDING; + el[0].offset = UINT32_MAX; + el[0].length = UINT32_MAX; + el[0].reserved = 0x87654321; + el[0].flags = SMB2_LOCK_FLAG_EXCLUSIVE|SMB2_LOCK_FLAG_FAIL_IMMEDIATELY; status = smb2_lock(tree, &lck); CHECK_STATUS(status, NT_STATUS_OK); - CHECK_VALUE(lck.out.unknown1, 0); + CHECK_VALUE(lck.out.reserved, 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); + CHECK_VALUE(lck.out.reserved, 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); + CHECK_VALUE(lck.out.reserved, 0); - lck.in.flags = 0x00000000; + el[0].flags = 0x00000000; status = smb2_lock(tree, &lck); CHECK_STATUS(status, NT_STATUS_OK); - CHECK_VALUE(lck.out.unknown1, 0); + CHECK_VALUE(lck.out.reserved, 0); status = smb2_lock(tree, &lck); CHECK_STATUS(status, NT_STATUS_OK); - CHECK_VALUE(lck.out.unknown1, 0); + CHECK_VALUE(lck.out.reserved, 0); - lck.in.flags = 0x00000001; + el[0].flags = 0x00000001; status = smb2_lock(tree, &lck); CHECK_STATUS(status, NT_STATUS_OK); - CHECK_VALUE(lck.out.unknown1, 0); + CHECK_VALUE(lck.out.reserved, 0); status = smb2_lock(tree, &lck); CHECK_STATUS(status, NT_STATUS_OK); - CHECK_VALUE(lck.out.unknown1, 0); + CHECK_VALUE(lck.out.reserved, 0); - lck.in.unknown1 = 0x0001; - lck.in.unknown2 = 0x87654321; + lck.in.lock_count = 0x0001; + lck.in.reserved = 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; + el[0].offset = 0x00000000FFFFFFFF; + el[0].length = 0x00000000FFFFFFFF; + el[0].reserved = 0x12345678; + el[0].flags = SMB2_LOCK_FLAG_UNLOCK; status = smb2_lock(tree, &lck); CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED); - lck.in.unknown1 = 0x0001; - lck.in.unknown2 = 0x12345678; + lck.in.lock_count = 0x0001; + lck.in.reserved = 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; + el[0].offset = 0x00000000FFFFFFFF; + el[0].length = 0x00000000FFFFFFFF; + el[0].reserved = 0x00000000; + el[0].flags = SMB2_LOCK_FLAG_UNLOCK; status = smb2_lock(tree, &lck); CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED); @@ -206,6 +209,9 @@ static bool test_lock_read_write(struct torture_context *torture, struct smb2_create cr; struct smb2_write wr; struct smb2_read rd; + struct smb2_lock_element el[1]; + + lck.in.locks = el; ZERO_STRUCT(buf); @@ -215,27 +221,27 @@ static bool test_lock_read_write(struct torture_context *torture, 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.lock_count = 0x0001; + lck.in.reserved = 0x00000000; lck.in.file.handle = h1; - lck.in.offset = 0; - lck.in.count = ARRAY_SIZE(buf)/2; - lck.in.unknown5 = 0x00000000; - lck.in.flags = s->lock_flags; + el[0].offset = 0; + el[0].length = ARRAY_SIZE(buf)/2; + el[0].reserved = 0x00000000; + el[0].flags = s->lock_flags; status = smb2_lock(tree, &lck); CHECK_STATUS(status, NT_STATUS_OK); - CHECK_VALUE(lck.out.unknown1, 0); + CHECK_VALUE(lck.out.reserved, 0); - lck.in.unknown1 = 0x0001; - lck.in.unknown2 = 0x00000000; + lck.in.lock_count = 0x0001; + lck.in.reserved = 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 = s->lock_flags; + el[0].offset = ARRAY_SIZE(buf)/2; + el[0].length = ARRAY_SIZE(buf)/2; + el[0].reserved = 0x00000000; + el[0].flags = s->lock_flags; status = smb2_lock(tree, &lck); CHECK_STATUS(status, NT_STATUS_OK); - CHECK_VALUE(lck.out.unknown1, 0); + CHECK_VALUE(lck.out.reserved, 0); ZERO_STRUCT(cr); cr.in.oplock_level = 0; @@ -286,16 +292,16 @@ static bool test_lock_read_write(struct torture_context *torture, status = smb2_read(tree, tree, &rd); CHECK_STATUS(status, s->read_h2_status); - lck.in.unknown1 = 0x0001; - lck.in.unknown2 = 0x00000000; + lck.in.lock_count = 0x0001; + lck.in.reserved = 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; + el[0].offset = ARRAY_SIZE(buf)/2; + el[0].length = ARRAY_SIZE(buf)/2; + el[0].reserved = 0x00000000; + el[0].flags = SMB2_LOCK_FLAG_UNLOCK; status = smb2_lock(tree, &lck); CHECK_STATUS(status, NT_STATUS_OK); - CHECK_VALUE(lck.out.unknown1, 0); + CHECK_VALUE(lck.out.reserved, 0); ZERO_STRUCT(wr); wr.in.file.handle = h2; @@ -349,7 +355,7 @@ static bool test_lock_rw_exclusiv(struct torture_context *torture, struct smb2_t { struct test_lock_read_write_state s = { .fname = "lock_rw_exclusiv.dat", - .lock_flags = SMB2_LOCK_FLAG_EXCLUSIV, + .lock_flags = SMB2_LOCK_FLAG_EXCLUSIVE, .write_h1_status = NT_STATUS_OK, .read_h1_status = NT_STATUS_OK, .write_h2_status = NT_STATUS_FILE_LOCK_CONFLICT, |