s3: VFS: xattr_tdb. Allow unlinkat to cope with dangling symlinks.
[bbaumbach/samba-autobuild/.git] / source3 / modules / vfs_xattr_tdb.c
index daa99b2cc3e03268aec7a66a09d6667fef4d4965..42c570b54b3e9f3542fc61d3f031b82415ab8ccd 100644 (file)
@@ -520,6 +520,16 @@ static int xattr_tdb_unlinkat(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) {
                goto out;