1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-18 06:04:06 +03:00

s4: torture. Add smb2.lease.rename_wait test to reproduce regression in delay rename for lease break code.

Passes against Windows 10. Add to knownfail, the
next commit will fix this.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14679
CI: https://gitlab.com/samba-team/samba/-/merge_requests/1875

Back-ported from 8d9a0b8d57713781c72440c7e91746b5d89e6f6a.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
This commit is contained in:
Jeremy Allison 2021-03-30 15:05:47 -07:00 committed by Karolin Seeger
parent e85d111f54
commit f5bb7a5501
2 changed files with 146 additions and 0 deletions

View File

@ -0,0 +1 @@
^samba3.smb2.lease.rename_wait\(nt4_dc\)

View File

@ -3722,6 +3722,148 @@ static bool test_lease_timeout(struct torture_context *tctx,
return ret;
}
static bool test_lease_rename_wait(struct torture_context *tctx,
struct smb2_tree *tree)
{
TALLOC_CTX *mem_ctx = talloc_new(tctx);
struct smb2_create io;
struct smb2_lease ls1;
struct smb2_lease ls2;
struct smb2_lease ls3;
struct smb2_handle h1 = {{0}};
struct smb2_handle h2 = {{0}};
struct smb2_handle h3 = {{0}};
union smb_setfileinfo sinfo;
NTSTATUS status;
const char *fname_src = "lease_rename_src.dat";
const char *fname_dst = "lease_rename_dst.dat";
bool ret = true;
struct smb2_lease_break_ack ack = {};
struct smb2_request *rename_req = NULL;
uint32_t caps;
unsigned int i;
caps = smb2cli_conn_server_capabilities(tree->session->transport->conn);
if (!(caps & SMB2_CAP_LEASING)) {
torture_skip(tctx, "leases are not supported");
}
smb2_util_unlink(tree, fname_src);
smb2_util_unlink(tree, fname_dst);
/* Short timeout for fails. */
tree->session->transport->options.request_timeout = 15;
/* Grab a RH lease. */
smb2_lease_create(&io,
&ls1,
false,
fname_src,
LEASE1,
smb2_util_lease_state("RH"));
status = smb2_create(tree, mem_ctx, &io);
CHECK_STATUS(status, NT_STATUS_OK);
CHECK_CREATED(&io, CREATED, FILE_ATTRIBUTE_ARCHIVE);
CHECK_LEASE(&io, "RH", true, LEASE1, 0);
h1 = io.out.file.handle;
/* Second open with a RH lease. */
smb2_lease_create(&io,
&ls2,
false,
fname_src,
LEASE2,
smb2_util_lease_state("RH"));
io.in.create_disposition = NTCREATEX_DISP_OPEN;
io.in.desired_access = GENERIC_READ_ACCESS;
status = smb2_create(tree, mem_ctx, &io);
CHECK_STATUS(status, NT_STATUS_OK);
CHECK_CREATED(&io, EXISTED, FILE_ATTRIBUTE_ARCHIVE);
CHECK_LEASE(&io, "RH", true, LEASE2, 0);
h2 = io.out.file.handle;
/*
* Don't ack a lease break.
*/
tree->session->transport->lease.handler = torture_lease_handler;
tree->session->transport->lease.private_data = tree;
torture_reset_lease_break_info(tctx, &lease_break_info);
lease_break_info.lease_skip_ack = true;
/* Break with a rename. */
ZERO_STRUCT(sinfo);
sinfo.rename_information.level = RAW_SFILEINFO_RENAME_INFORMATION;
sinfo.rename_information.in.file.handle = h1;
sinfo.rename_information.in.overwrite = true;
sinfo.rename_information.in.new_name = fname_dst;
rename_req = smb2_setinfo_file_send(tree, &sinfo);
torture_assert(tctx,
rename_req != NULL,
"smb2_setinfo_file_send");
torture_assert(tctx,
rename_req->state == SMB2_REQUEST_RECV,
"rename pending");
/* Try and open the destination with a RH lease. */
smb2_lease_create(&io,
&ls3,
false,
fname_dst,
LEASE3,
smb2_util_lease_state("RH"));
/* We want to open, not create. */
io.in.create_disposition = NTCREATEX_DISP_OPEN;
io.in.desired_access = GENERIC_READ_ACCESS;
status = smb2_create(tree, mem_ctx, &io);
CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
/*
* The smb2_create() I/O should have picked up the break request
* caused by the pending rename.
*/
/* Copy the break request. */
ack.in.lease.lease_key =
lease_break_info.lease_break.current_lease.lease_key;
ack.in.lease.lease_state =
lease_break_info.lease_break.new_lease_state;
/*
* Give the server 3 more chances to have renamed
* the file. Better than doing a sleep.
*/
for (i = 0; i < 3; i++) {
status = smb2_create(tree, mem_ctx, &io);
CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
}
/* Ack the break. The server is now free to rename. */
status = smb2_lease_break_ack(tree, &ack);
CHECK_STATUS(status, NT_STATUS_OK);
/* Get the rename reply. */
status = smb2_setinfo_recv(rename_req);
CHECK_STATUS(status, NT_STATUS_OK);
/* The target should now exist. */
status = smb2_create(tree, mem_ctx, &io);
CHECK_STATUS(status, NT_STATUS_OK);
h3 = io.out.file.handle;
done:
smb2_util_close(tree, h1);
smb2_util_close(tree, h2);
smb2_util_close(tree, h3);
smb2_util_unlink(tree, fname_src);
smb2_util_unlink(tree, fname_dst);
talloc_free(mem_ctx);
return ret;
}
static bool test_lease_v2_rename(struct torture_context *tctx,
struct smb2_tree *tree)
{
@ -4192,6 +4334,9 @@ struct torture_suite *torture_smb2_lease_init(TALLOC_CTX *ctx)
torture_suite_add_1smb2_test(suite, "dynamic_share", test_lease_dynamic_share);
torture_suite_add_1smb2_test(suite, "timeout", test_lease_timeout);
torture_suite_add_1smb2_test(suite, "unlink", test_lease_unlink);
torture_suite_add_1smb2_test(suite, "rename_wait",
test_lease_rename_wait);
suite->description = talloc_strdup(suite, "SMB2-LEASE tests");