smbd: simplify handling of failing fstat() after unlinking file
authorRalph Boehme <slow@samba.org>
Mon, 5 Feb 2024 14:03:48 +0000 (15:03 +0100)
committerJule Anger <janger@samba.org>
Wed, 27 Mar 2024 14:52:15 +0000 (14:52 +0000)
close_remove_share_mode() already called vfs_stat_fsp(), so we can skip the
fstat() triggered in fd_close() by fsp->fsp_flags.fstat_before_close being true.

This avoids getting an EACCESS error when doing an fstat() on the removed file
which seems to happen with some FUSE filesystems.

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

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
(cherry picked from commit 6e6324cff29089a636823786183222a73fe7cb28)

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

index af5e78daa1005c6e68803f77ca9dc175bc927df3..e16cb2d34852e63d96ac03ee8e1706e5c61f5766 100644 (file)
@@ -603,6 +603,7 @@ static NTSTATUS close_remove_share_mode(files_struct *fsp,
         */
 
        fsp->fsp_flags.delete_on_close = false;
+       fsp->fsp_flags.fstat_before_close = false;
        lck_state.reset_delete_on_close = true;
 
  done:
index c3b279285105a821268571c6b767cb2dde02887f..45ac27c2fdfc35a68ced56df3e03e23b69cb6975 100644 (file)
@@ -952,20 +952,7 @@ NTSTATUS fd_close(files_struct *fsp)
        if (fsp->fsp_flags.fstat_before_close) {
                status = vfs_stat_fsp(fsp);
                if (!NT_STATUS_IS_OK(status)) {
-                       /*
-                        * If this is a stream and delete-on-close was set, the
-                        * backing object (an xattr from streams_xattr) might
-                        * already be deleted so fstat() fails with
-                        * NT_STATUS_NOT_FOUND. So if fsp refers to a stream we
-                        * ignore the error and only bail for normal files where
-                        * an fstat() should still work. NB. We cannot use
-                        * fsp_is_alternate_stream(fsp) for this as the base_fsp
-                        * has already been closed at this point and so the value
-                        * fsp_is_alternate_stream() checks for is already NULL.
-                        */
-                       if (fsp->fsp_name->stream_name == NULL) {
-                               return status;
-                       }
+                       return status;
                }
        }