smbd:close: only remove kernel share modes if they had been taken at open
authorMichael Adam <obnox@samba.org>
Sun, 15 May 2016 21:24:08 +0000 (23:24 +0200)
committerChristian Ambach <ambi@samba.org>
Thu, 19 May 2016 00:34:36 +0000 (02:34 +0200)
This avoids errors due to 'not implemented' for SMB_VFS_KERNEL_FLOCK
on some file systems like glusterfs (with the vfs module). The only
other code path where SMB_VFS_KERNEL_FLOCK is called, is already protected.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=11919

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Christian Ambach <ambi@samba.org>
Autobuild-User(master): Christian Ambach <ambi@samba.org>
Autobuild-Date(master): Thu May 19 02:34:36 CEST 2016 on sn-devel-144

source3/smbd/close.c
source3/smbd/open.c

index 0302c67ce845e06481e0813fc68f5a69ef960249..9d1f1a98afefd17ed02daeb28be297fae702ebf8 100644 (file)
@@ -250,7 +250,6 @@ static NTSTATUS close_remove_share_mode(files_struct *fsp,
        const struct security_token *del_nt_token = NULL;
        bool got_tokens = false;
        bool normal_close;
-       int ret_flock;
 
        /* Ensure any pending write time updates are done. */
        if (fsp->update_write_time_event) {
@@ -474,12 +473,16 @@ static NTSTATUS close_remove_share_mode(files_struct *fsp,
                pop_sec_ctx();
        }
 
-       /* remove filesystem sharemodes */
-       ret_flock = SMB_VFS_KERNEL_FLOCK(fsp, 0, 0);
-       if (ret_flock == -1) {
-               DEBUG(2, ("close_remove_share_mode: removing kernel flock for "
-                                       "%s failed: %s\n", fsp_str_dbg(fsp),
-                                       strerror(errno)));
+       if (fsp->kernel_share_modes_taken) {
+               int ret_flock;
+
+               /* remove filesystem sharemodes */
+               ret_flock = SMB_VFS_KERNEL_FLOCK(fsp, 0, 0);
+               if (ret_flock == -1) {
+                       DEBUG(2, ("close_remove_share_mode: removing kernel "
+                                 "flock for %s failed: %s\n",
+                                 fsp_str_dbg(fsp), strerror(errno)));
+               }
        }
 
        if (!del_share_mode(lck, fsp)) {
index d111254b9cb8e58a843818493e16f5e4a5591c66..af1c1de89e8410485b417887709b5b5e8a24557f 100644 (file)
@@ -3102,6 +3102,8 @@ static NTSTATUS open_file_ntcreate(connection_struct *conn,
 
                        return NT_STATUS_SHARING_VIOLATION;
                }
+
+               fsp->kernel_share_modes_taken = true;
        }
 
        /*