From 97b1694ebc188f30cef7b73d006a8ade34d7b0ee Mon Sep 17 00:00:00 2001 From: Ralph Boehme Date: Sat, 22 Mar 2025 16:57:13 +0100 Subject: [PATCH 1/2] smbtorture: add test smb2.dirlease.oplocks Verifies server correctly ignores oplock on directories and only grants leases. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15836 Signed-off-by: Ralph Boehme Reviewed-by: Stefan Metzmacher (cherry picked from commit 9ecaa4095643729bf5f9c93316d577b603190449) --- selftest/knownfail.d/samba3.smb2.dirlease | 1 + source4/torture/smb2/lease.c | 58 +++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 selftest/knownfail.d/samba3.smb2.dirlease diff --git a/selftest/knownfail.d/samba3.smb2.dirlease b/selftest/knownfail.d/samba3.smb2.dirlease new file mode 100644 index 000000000000..0aa9d23a57a0 --- /dev/null +++ b/selftest/knownfail.d/samba3.smb2.dirlease @@ -0,0 +1 @@ +^samba3.smb2.dirlease.oplocks\(fileserver\) diff --git a/source4/torture/smb2/lease.c b/source4/torture/smb2/lease.c index 6966f97ccb49..60d5f81ae80f 100644 --- a/source4/torture/smb2/lease.c +++ b/source4/torture/smb2/lease.c @@ -1492,6 +1492,63 @@ static bool test_lease_v2_request_parent(struct torture_context *tctx, return ret; } +static bool test_dirlease_oplocks(struct torture_context *tctx, + struct smb2_tree *tree) +{ + const char *dname = "test_dirlease_leases_dir"; + struct smb2_create c; + struct smb2_handle h = {}; + uint16_t levels[] = { + SMB2_OPLOCK_LEVEL_NONE, + SMB2_OPLOCK_LEVEL_II, + SMB2_OPLOCK_LEVEL_EXCLUSIVE, + SMB2_OPLOCK_LEVEL_BATCH + }; + uint32_t caps; + int i; + 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"); + torture_assert_goto(tctx, caps & SMB2_CAP_DIRECTORY_LEASING, ret, done, + "SMB3 Directory Leases are not supported\n"); + + smb2_deltree(tree, dname); + + for (i = 0; i < sizeof(levels); i++) { + c = (struct smb2_create) { + .in.oplock_level = levels[i], + .in.desired_access = SEC_RIGHTS_DIR_READ, + .in.create_options = NTCREATEX_OPTIONS_DIRECTORY, + .in.file_attributes = FILE_ATTRIBUTE_DIRECTORY, + .in.share_access = NTCREATEX_SHARE_ACCESS_MASK, + .in.create_disposition = NTCREATEX_DISP_OPEN_IF, + .in.fname = dname, + }; + + status = smb2_create(tree, tree, &c); + torture_assert_ntstatus_ok_goto(tctx, status, ret, done, + "smb2_create failed\n"); + h = c.out.file.handle; + status = smb2_util_close(tree, h); + torture_assert_ntstatus_ok_goto(tctx, status, ret, done, + "smb2_util_close failed\n"); + + torture_assert_int_equal_goto( + tctx, + c.out.oplock_level, + SMB2_OPLOCK_LEVEL_NONE, + ret, done, "bad level"); + } + +done: + smb2_util_close(tree, h); + smb2_deltree(tree, dname); + + return ret; +} + /* * Checks server accepts "RWH", "RH" and "R" lease request and grants at most * (lease_request & "RH"), so no "W", but "R" without "H" if requested. @@ -7558,6 +7615,7 @@ struct torture_suite *torture_smb2_dirlease_init(TALLOC_CTX *ctx) torture_suite_add_1smb2_test(suite, "v2_request_parent", test_lease_v2_request_parent); torture_suite_add_2smb2_test(suite, "v2_request", test_lease_v2_request); + torture_suite_add_1smb2_test(suite, "oplocks", test_dirlease_oplocks); torture_suite_add_1smb2_test(suite, "leases", test_dirlease_leases); torture_suite_add_2smb2_test(suite, "seteof", test_dirlease_seteof); torture_suite_add_2smb2_test(suite, "setdos", test_dirlease_setdos); -- 2.49.0 From f95aa27e091ade5bad90abc948f728cc852603c5 Mon Sep 17 00:00:00 2001 From: Ralph Boehme Date: Sat, 22 Mar 2025 16:59:07 +0100 Subject: [PATCH 2/2] smbd: fix handling of directory leases and oplock levels MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BUG: https://bugzilla.samba.org/show_bug.cgi?id=15836 Signed-off-by: Ralph Boehme Reviewed-by: Stefan Metzmacher Autobuild-User(master): Ralph Böhme Autobuild-Date(master): Fri Mar 28 07:53:25 UTC 2025 on atb-devel-224 (cherry picked from commit 4b3f45e13f9c11920924c034a457ea2cb8e15e18) --- selftest/knownfail.d/samba3.smb2.dirlease | 1 - source3/smbd/open.c | 7 +++++++ 2 files changed, 7 insertions(+), 1 deletion(-) delete mode 100644 selftest/knownfail.d/samba3.smb2.dirlease diff --git a/selftest/knownfail.d/samba3.smb2.dirlease b/selftest/knownfail.d/samba3.smb2.dirlease deleted file mode 100644 index 0aa9d23a57a0..000000000000 --- a/selftest/knownfail.d/samba3.smb2.dirlease +++ /dev/null @@ -1 +0,0 @@ -^samba3.smb2.dirlease.oplocks\(fileserver\) diff --git a/source3/smbd/open.c b/source3/smbd/open.c index 771734f6203c..540dc7a0c60f 100644 --- a/source3/smbd/open.c +++ b/source3/smbd/open.c @@ -5191,6 +5191,13 @@ static NTSTATUS open_directory(connection_struct *conn, keep_locked = true; } + if ((oplock_request != NO_OPLOCK) && (oplock_request != LEASE_OPLOCK)) { + /* + * No oplocks on directories, only leases + */ + oplock_request = NO_OPLOCK; + } + lck_state = (struct open_ntcreate_lock_state) { .fsp = fsp, .object_type = "directory", -- 2.49.0