From 4d06aa1550bbc980a983e881a5f1394fb6f87c1b Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 10 Aug 2022 08:48:25 +0000 Subject: [PATCH] s3:smbd: call grant_fsp_lease() after set_share_mode() This means we don't have to call remove_lease_if_stale() if set_share_mode() fails. It's easier to cleanup the share mode entry. And it makes the code flow easier to the following changes. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125 Signed-off-by: Stefan Metzmacher Reviewed-by: Jeremy Allison --- source3/smbd/open.c | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/source3/smbd/open.c b/source3/smbd/open.c index b111174a0e3..596fa55eeed 100644 --- a/source3/smbd/open.c +++ b/source3/smbd/open.c @@ -4171,16 +4171,8 @@ static NTSTATUS open_file_ntcreate(connection_struct *conn, if (oplock_type == LEASE_OPLOCK) { lease_key = &lease->lease_key; - status = grant_fsp_lease(fsp, lck, lease, granted_lease); - if (!NT_STATUS_IS_OK(status)) { - TALLOC_FREE(lck); - fd_close(fsp); - return status; - } - fsp->oplock_type = oplock_type; - DBG_DEBUG("lease_state=%d\n", fsp->lease->lease.lease_state); } else if (oplock_type != NO_OPLOCK) { fsp->oplock_type = oplock_type; @@ -4206,22 +4198,23 @@ static NTSTATUS open_file_ntcreate(connection_struct *conn, share_access, access_mask); if (!ok) { - if (fsp->oplock_type == LEASE_OPLOCK) { - status = remove_lease_if_stale( - lck, - fsp_client_guid(fsp), - &fsp->lease->lease.lease_key); - if (!NT_STATUS_IS_OK(status)) { - DBG_WARNING("remove_lease_if_stale " - "failed: %s\n", - nt_errstr(status)); - } - } TALLOC_FREE(lck); fd_close(fsp); return NT_STATUS_NO_MEMORY; } + if (oplock_type == LEASE_OPLOCK) { + status = grant_fsp_lease(fsp, lck, lease, granted_lease); + if (!NT_STATUS_IS_OK(status)) { + del_share_mode(lck, fsp); + TALLOC_FREE(lck); + fd_close(fsp); + return status; + } + + DBG_DEBUG("lease_state=%d\n", fsp->lease->lease.lease_state); + } + /* Should we atomically (to the client at least) truncate ? */ if ((!new_file_created) && (flags2 & O_TRUNC) &&