From: Jeremy Allison Date: Thu, 27 Jan 2022 17:49:45 +0000 (-0800) Subject: s3: smbd: Plumb in POSIX lock requests through SMB2 lock calls if done on a POSIX... X-Git-Tag: tevent-0.12.0~804 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f68fffa85d1de992384a210bb0b9261cda3fb168;p=thirdparty%2Fsamba.git s3: smbd: Plumb in POSIX lock requests through SMB2 lock calls if done on a POSIX handle. Currently not allowed. Note there is currently no way to create a POSIX file handle in SMB2 so this code can't be accessed. This will remain so until client and server code are ready to turn on SMB2 POSIX extensions and the tests are in place. Signed-off-by: Jeremy Allison Reviewed-by: Andreas Schneider --- diff --git a/source3/smbd/smb2_lock.c b/source3/smbd/smb2_lock.c index 8d4b8b2e853..48593af4790 100644 --- a/source3/smbd/smb2_lock.c +++ b/source3/smbd/smb2_lock.c @@ -381,6 +381,7 @@ static struct tevent_req *smbd_smb2_lock_send(TALLOC_CTX *mem_ctx, for (i=0; iposix_flags & FSP_POSIX_FLAGS_OPEN); switch (in_locks[i].flags) { case SMB2_LOCK_FLAG_SHARED: @@ -426,7 +427,25 @@ static struct tevent_req *smbd_smb2_lock_send(TALLOC_CTX *mem_ctx, locks[i].offset = in_locks[i].offset; locks[i].count = in_locks[i].length; + if (posix_handle) { + locks[i].lock_flav = POSIX_LOCK; + } else { + locks[i].lock_flav = WINDOWS_LOCK; + } + if (in_locks[i].flags & SMB2_LOCK_FLAG_EXCLUSIVE) { + if (posix_handle && fsp->fsp_flags.can_write == false) { + /* + * Can't get a write lock on a posix + * read-only handle. + */ + DBG_INFO("POSIX write lock requested " + "on read-only handle for file %s\n", + fsp_str_dbg(fsp)); + tevent_req_nterror(req, + NT_STATUS_INVALID_HANDLE); + return tevent_req_post(req, ev); + } locks[i].brltype = WRITE_LOCK; } else if (in_locks[i].flags & SMB2_LOCK_FLAG_SHARED) { locks[i].brltype = READ_LOCK;