From dde84e5fd331705a20262664f2c11a3e9ba11941 Mon Sep 17 00:00:00 2001 From: Ralph Boehme Date: Thu, 24 Oct 2024 12:00:40 +0200 Subject: [PATCH] smbtorture: check parent leasekey is ignored unless SMB2_LEASE_FLAG_PARENT_LEASE_KEY_SET is set Signed-off-by: Ralph Boehme Reviewed-by: Stefan Metzmacher --- selftest/knownfail.d/samba3.smb2.lease | 1 + source4/torture/smb2/lease.c | 50 ++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 selftest/knownfail.d/samba3.smb2.lease diff --git a/selftest/knownfail.d/samba3.smb2.lease b/selftest/knownfail.d/samba3.smb2.lease new file mode 100644 index 00000000000..c3084dc5ad2 --- /dev/null +++ b/selftest/knownfail.d/samba3.smb2.lease @@ -0,0 +1 @@ +^samba3.smb2.lease.v2_flags_parentkey\(fileserver\) diff --git a/source4/torture/smb2/lease.c b/source4/torture/smb2/lease.c index dfac95b7506..9a841ecacfd 100644 --- a/source4/torture/smb2/lease.c +++ b/source4/torture/smb2/lease.c @@ -93,6 +93,9 @@ if (__flags & SMB2_LEASE_FLAG_PARENT_LEASE_KEY_SET) { \ CHECK_VAL((__io)->out.lease_response_v2.parent_lease_key.data[0], (__parent)); \ CHECK_VAL((__io)->out.lease_response_v2.parent_lease_key.data[1], ~(__parent)); \ + } else { \ + CHECK_VAL((__io)->out.lease_response_v2.parent_lease_key.data[0], 0); \ + CHECK_VAL((__io)->out.lease_response_v2.parent_lease_key.data[1], 0); \ } \ CHECK_VAL((__io)->out.lease_response_v2.lease_duration, 0); \ CHECK_VAL((__io)->out.lease_response_v2.lease_epoch, (__epoch)); \ @@ -1981,6 +1984,52 @@ done: return ret; } +/* + * Verify server ignores the parent leasekey if + * SMB2_LEASE_FLAG_PARENT_LEASE_KEY_SET is not set in the request. + */ +static bool test_lease_v2_flags_parentkey(struct torture_context *tctx, + struct smb2_tree *tree) +{ + struct smb2_create c = {}; + struct smb2_lease ls = {}; + struct smb2_handle h = {}; + const char *fname = "lease_v2_epoch1.dat"; + enum protocol_types protocol; + uint32_t caps; + NTSTATUS status; + bool ret = true; + + caps = smb2cli_conn_server_capabilities(tree->session->transport->conn); + torture_assert_goto(tctx, caps & SMB2_CAP_LEASING, ret, done, "leases are not supported"); + + protocol = smbXcli_conn_protocol(tree->session->transport->conn); + if (protocol < PROTOCOL_SMB3_00) { + torture_skip(tctx, "v2 leases are not supported"); + } + + smb2_util_unlink(tree, fname); + + smb2_lease_v2_create_share(&c, &ls, false, fname, + smb2_util_share_access("RWD"), + LEASE1, &LEASE1, + smb2_util_lease_state("RHW"), + 0x4711); + ls.lease_flags = 0; + + status = smb2_create(tree, tree, &c); + CHECK_STATUS(status, NT_STATUS_OK); + h = c.out.file.handle; + + CHECK_CREATED(&c, CREATED, FILE_ATTRIBUTE_ARCHIVE); + CHECK_LEASE_V2(&c, "RHW", true, LEASE1, 0, 0, ls.lease_epoch + 1); + +done: + smb2_util_close(tree, h); + smb2_util_unlink(tree, fname); + return ret; +} + static bool test_lease_v2_epoch1(struct torture_context *tctx, struct smb2_tree *tree) { @@ -5759,6 +5808,7 @@ struct torture_suite *torture_smb2_lease_init(TALLOC_CTX *ctx) torture_suite_add_2smb2_test(suite, "lock1", test_lease_lock1); torture_suite_add_1smb2_test(suite, "complex1", test_lease_complex1); torture_suite_add_1smb2_test(suite, "v2_flags_breaking", test_lease_v2_flags_breaking); + torture_suite_add_1smb2_test(suite, "v2_flags_parentkey", test_lease_v2_flags_parentkey); torture_suite_add_1smb2_test(suite, "v2_epoch1", test_lease_v2_epoch1); torture_suite_add_1smb2_test(suite, "v2_epoch2", test_lease_v2_epoch2); torture_suite_add_1smb2_test(suite, "v2_epoch3", test_lease_v2_epoch3); -- 2.11.4.GIT