]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3: smbd: Plumb in POSIX lock requests through SMB2 lock calls if done on a POSIX...
authorJeremy Allison <jra@samba.org>
Thu, 27 Jan 2022 17:49:45 +0000 (09:49 -0800)
committerAndreas Schneider <asn@cryptomilk.org>
Tue, 1 Feb 2022 16:30:37 +0000 (16:30 +0000)
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 <jra@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
source3/smbd/smb2_lock.c

index 8d4b8b2e853781d7764a7eb1574bd4f07fe34e67..48593af47905e2110b9618cc5cadcf3a0bbbe2f0 100644 (file)
@@ -381,6 +381,7 @@ static struct tevent_req *smbd_smb2_lock_send(TALLOC_CTX *mem_ctx,
 
        for (i=0; i<in_lock_count; i++) {
                bool invalid = false;
+               bool posix_handle =(fsp->posix_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;