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)
committerJule Anger <janger@samba.org>
Thu, 2 Dec 2021 10:33:13 +0000 (10:33 +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>
(cherry picked from commit 295d7d026babe3cd5123d0f53adcb16868907f05)
(backported from commit 7a4173809a87350bc3580240232978042ec2ceca)
[pfilipen@redhat.com: code in 4.15 uses different variable name]

source3/modules/vfs_streams_depot.c

index a5e02d5a0698bfcd642bf4f4b436648273c16134..dd6376e5fd06e052fbef8770845cda95b4be1122 100644 (file)
@@ -739,6 +739,16 @@ static int streams_depot_unlink_internal(vfs_handle_struct *handle,
                ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname_base);
        } else {
                ret = SMB_VFS_NEXT_STAT(handle, smb_fname_base);
+               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, smb_fname_base);
+                       }
+               }
        }
 
        if (ret == -1) {