s3: VFS: streams_depot. Allow unlinkat to cope with dangling symlinks.
authorJeremy Allison <jra@samba.org>
Mon, 25 Oct 2021 19:01:58 +0000 (12:01 -0700)
committerRalph Boehme <slow@samba.org>
Fri, 29 Oct 2021 14:02:34 +0000 (14:02 +0000)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14879

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/modules/vfs_streams_depot.c

index 973edeeda24c2a9aea8de78766bc071cc8bfff3b..ae73ba965a55caa13d3e847e7f705ffad24fad0a 100644 (file)
@@ -823,6 +823,16 @@ static int streams_depot_unlink_internal(vfs_handle_struct *handle,
                ret = SMB_VFS_NEXT_LSTAT(handle, full_fname);
        } else {
                ret = SMB_VFS_NEXT_STAT(handle, full_fname);
+               if (ret == -1 && (errno == ENOENT || errno == ELOOP)) {
+                       if (VALID_STAT(smb_fname->st) &&
+                                       S_ISLNK(smb_fname->st.st_ex_mode)) {
+                               /*
+                                * Original name was a link - Could be
+                                * trying to remove a dangling symlink.
+                                */
+                               ret = SMB_VFS_NEXT_LSTAT(handle, full_fname);
+                       }
+               }
        }
        if (ret == -1) {
                TALLOC_FREE(full_fname);