From: Ralph Boehme Date: Fri, 18 Oct 2024 15:19:34 +0000 (+0200) Subject: smbtorture: add test smb2.dirleases.leases X-Git-Tag: tdb-1.4.13~681 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9695cda30fc165d9afe33f770c37d862af8a0ca0;p=thirdparty%2Fsamba.git smbtorture: add test smb2.dirleases.leases 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. Signed-off-by: Ralph Boehme Reviewed-by: Stefan Metzmacher --- diff --git a/source4/torture/smb2/lease.c b/source4/torture/smb2/lease.c index c5b72765803..5a87fbb10c1 100644 --- a/source4/torture/smb2/lease.c +++ b/source4/torture/smb2/lease.c @@ -1489,6 +1489,104 @@ static bool test_lease_v2_request_parent(struct torture_context *tctx, 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. + */ +static bool test_dirlease_leases(struct torture_context *tctx, + struct smb2_tree *tree) +{ + TALLOC_CTX *mem_ctx = talloc_new(tctx); + struct smb2_create io; + struct smb2_lease ls; + struct smb2_handle h1 = {}; + NTSTATUS status; + const char *dname = "test_dirlease_leases_dir"; + bool ret = true; + uint32_t caps; + + 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); + + torture_reset_lease_break_info(tctx, &lease_break_info); + + /* Request "RWH" -> grant "RH" */ + + ZERO_STRUCT(io); + smb2_lease_v2_create_share(&io, &ls, true, dname, + smb2_util_share_access("RWD"), + LEASE1, NULL, + smb2_util_lease_state("RWH"), + 0x11); + + status = smb2_create(tree, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OK); + h1 = io.out.file.handle; + CHECK_LEASE_V2(&io, "RH", true, LEASE1, + 0, 0, ++ls.lease_epoch); + smb2_util_close(tree, h1); + + /* Request "RW" -> grant "R" */ + + ZERO_STRUCT(io); + smb2_lease_v2_create_share(&io, &ls, true, dname, + smb2_util_share_access("RWD"), + LEASE1, NULL, + smb2_util_lease_state("RW"), + 0x11); + + status = smb2_create(tree, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OK); + h1 = io.out.file.handle; + CHECK_LEASE_V2(&io, "R", true, LEASE1, + 0, 0, ++ls.lease_epoch); + smb2_util_close(tree, h1); + + /* Request "RH" -> grant "RH" */ + + ZERO_STRUCT(io); + smb2_lease_v2_create_share(&io, &ls, true, dname, + smb2_util_share_access("RWD"), + LEASE1, NULL, + smb2_util_lease_state("RH"), + 0x11); + + status = smb2_create(tree, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OK); + h1 = io.out.file.handle; + CHECK_LEASE_V2(&io, "RH", true, LEASE1, + 0, 0, ++ls.lease_epoch); + smb2_util_close(tree, h1); + + /* Request "R" -> grant "R" */ + + ZERO_STRUCT(io); + smb2_lease_v2_create_share(&io, &ls, true, dname, + smb2_util_share_access("RWD"), + LEASE1, NULL, + smb2_util_lease_state("R"), + 0x11); + + status = smb2_create(tree, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OK); + h1 = io.out.file.handle; + CHECK_LEASE_V2(&io, "R", true, LEASE1, + 0, 0, ++ls.lease_epoch); + smb2_util_close(tree, h1); + +done: + smb2_util_close(tree, h1); + smb2_deltree(tree, dname); + + talloc_free(mem_ctx); + + return ret; +} + static bool test_lease_break_twice(struct torture_context *tctx, struct smb2_tree *tree) { @@ -5534,5 +5632,6 @@ 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_1smb2_test(suite, "v2_request", test_lease_v2_request); + torture_suite_add_1smb2_test(suite, "leases", test_dirlease_leases); return suite; }