Bug 2019461

Summary: Directory containing dangling symlinks cannot be deleted.
Product: Red Hat Enterprise Linux 8 Reporter: Bijesh Thekkepat <bthekkep>
Component: sambaAssignee: Pavel Filipensky <pfilipen>
Status: CLOSED ERRATA QA Contact: Denis Karpelevich <dkarpele>
Severity: high Docs Contact:
Priority: unspecified    
Version: 8.0CC: aboscatt, asn, dkarpele, gdeschner, jarrpa, pfilipen, sgoveas, tscherf
Target Milestone: rcKeywords: Triaged, ZStream
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: samba-4.15.2-1.el8 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 2026717 (view as bug list) Environment:
Last Closed: 2022-05-10 15:27:35 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 2026717    

Description Bijesh Thekkepat 2021-11-02 15:37:32 UTC
Description of problem:

Dangling/dead symlinks cannot be detected by samba and folder containing Dangling/dead symlinks cannot be deleted.


Version-Release number of selected component (if applicable):

[root@smb ~]# cat /etc/redhat-release
Red Hat Enterprise Linux release 8.4 (Ootpa)


[root@smb ~]# rpm -qa samba*
samba-client-4.13.3-4.el8_4.x86_64
samba-common-tools-4.13.3-4.el8_4.x86_64
samba-winbind-4.13.3-4.el8_4.x86_64
samba-libs-4.13.3-4.el8_4.x86_64
samba-winbind-modules-4.13.3-4.el8_4.x86_64
samba-common-libs-4.13.3-4.el8_4.x86_64
samba-common-4.13.3-4.el8_4.noarch
samba-client-libs-4.13.3-4.el8_4.x86_64
samba-winbind-clients-4.13.3-4.el8_4.x86_64
samba-4.13.3-4.el8_4.x86_64

How reproducible:

====
[root@smb ~]# cat /etc/redhat-release
Red Hat Enterprise Linux release 8.4 (Ootpa)


[root@smb ~]# rpm -qa samba*
samba-client-4.13.3-4.el8_4.x86_64
samba-common-tools-4.13.3-4.el8_4.x86_64
samba-winbind-4.13.3-4.el8_4.x86_64
samba-libs-4.13.3-4.el8_4.x86_64
samba-winbind-modules-4.13.3-4.el8_4.x86_64
samba-common-libs-4.13.3-4.el8_4.x86_64
samba-common-4.13.3-4.el8_4.noarch
samba-client-libs-4.13.3-4.el8_4.x86_64
samba-winbind-clients-4.13.3-4.el8_4.x86_64
samba-4.13.3-4.el8_4.x86_64
====

#####################
[IDM1\bijeshtesting@smb smbtest]$ pwd
/home/IDM1/bijeshtesting/smbtest


[IDM1\bijeshtesting@smb smbtest]$ touch testfile
[IDM1\bijeshtesting@smb smbtest]$ echo "test" > testfile
[IDM1\bijeshtesting@smb smbtest]$ cat testfile
test
[IDM1\bijeshtesting@smb smbtest]$ ls -la
total 4
drwxrwsr-x 2 IDM1\bijeshtesting IDM1\domain users  22 Oct 20 02:18 .
drwxr-sr-x 6 IDM1\bijeshtesting IDM1\domain users 176 Oct 20 01:50 ..
-rw-r--r-- 1 IDM1\bijeshtesting IDM1\domain users   5 Oct 20 02:18 testfile


[IDM1\bijeshtesting@smb smbtest]$ ln -s testfile testfilelink  <----------------------------- created symbolic link

[IDM1\bijeshtesting@smb smbtest]$ ls -la
total 4
drwxrwsr-x 2 IDM1\bijeshtesting IDM1\domain users  42 Oct 20 02:19 .
drwxr-sr-x 6 IDM1\bijeshtesting IDM1\domain users 176 Oct 20 01:50 ..
-rw-r--r-- 1 IDM1\bijeshtesting IDM1\domain users   5 Oct 20 02:18 testfile
lrwxrwxrwx 1 IDM1\bijeshtesting IDM1\domain users   8 Oct 20 02:19 testfilelink -> testfile



[root@smb testshare]# smbclient -U bijeshtesting.global //smb.idm.local/testshare  <----------------------------- When connected to smbclient samba is able to detect both files as expected.
Enter bijeshtesting.global's password:
Try "help" to get a list of possible commands.
smb: \> cd smbtest\
smb: \smbtest\> ls
  .                                   D        0  Wed Oct 20 02:19:36 2021
  ..                                  D        0  Wed Oct 20 01:50:04 2021
  testfile                            N        5  Wed Oct 20 02:18:20 2021
  testfilelink                        N        5  Wed Oct 20 02:18:20 2021

8374272 blocks of size 1024. 3469108 blocks available
smb: \smbtest\> exit


[IDM1\bijeshtesting@smb smbtest]$ rm -rf testfile     <----------------------------- Deleted original file
[IDM1\bijeshtesting@smb smbtest]$ ls -la
total 0
drwxrwsr-x 2 IDM1\bijeshtesting IDM1\domain users  26 Oct 20 02:20 .
drwxr-sr-x 6 IDM1\bijeshtesting IDM1\domain users 176 Oct 20 01:50 ..
lrwxrwxrwx 1 IDM1\bijeshtesting IDM1\domain users   8 Oct 20 02:19 testfilelink -> testfile   <----------------------------- Since original file is deleted the symlink breaks. From server we can see Red colour highligted for the link  [Attached link.png]
[IDM1\bijeshtesting@smb smbtest]$ cat testfilelink
cat: testfilelink: No such file or directory
[IDM1\bijeshtesting@smb smbtest]$ cat testfile
cat: testfile: No such file or directory


1]
[root@smb testshare]# smbclient -U bijeshtesting.global //smb.idm.local/testshare  <----------------------------- smbclient is not able to detect both the files.
Enter bijeshtesting.global's password:
Try "help" to get a list of possible commands.
smb: \> cd smbtest\
smb: \smbtest\> ls
  .                                   D        0  Wed Oct 20 02:20:45 2021
  ..                                  D        0  Wed Oct 20 01:50:04 2021

8374272 blocks of size 1024. 3468380 blocks available
smb: \smbtest\> exit


Logs shows

=======
[2021/10/20 02:23:03.901018,  5, pid=38661, effective(1101347, 1100513), real(1101347, 0)] ../../source3/smbd/trans2.c:1808(smbd_dirptr_lanman2_mode_fn)
  smbd_dirptr_lanman2_mode_fn: Couldn't stat [smbtest/testfilelink] (No such file or directory)
=======

smb: \smbtest\> cd ..

2]
smb: \> rmdir smbtest\                                                   <----------------------------- When tried to delete the directory "smbtest" it fails with NT_STATUS_DIRECTORY_NOT_EMPTY error.
NT_STATUS_DIRECTORY_NOT_EMPTY removing remote directory file \smbtest\

Logs shows

=======
[2021/10/20 02:24:23.853803, 10, pid=38661, effective(1101347, 1100513), real(1101347, 0)] ../../source3/smbd/dir.c:1796(can_delete_directory_fsp)
  got name testfilelink - can't delete
=======

3]
The same issue happens when share is accessed from Windows explorer. The samba share is not able to detect the dead link and if we goto parent folder and try and delete the folder containing the dead link, we cannot remove it as samba see the folder as not being empty.
#####################



Detailed Samba debugging logs attached for 1] ls.txt and 2] rmdir.txt 3] Share not showing dead link file.png , Trying to delete parent folder.png , Parent folder not getting deleted.png, link.png



Below is my current smb.conf , I have tried with few options as below but it did not help.

==========
[IDM1\bijeshtesting@smb smbtest]$ cat /etc/samba/smb.conf
[global]
workgroup = IDM1
realm = GSSLAB1.IDM.GLOBAL
security = ads
idmap config * : backend = autorid
idmap config * : range = 100000-19999999
idmap config * : rangesize = 1000000
template homedir = /home/%D/%U
template shell = /bin/bash
winbind use default domain = false
winbind offline logon = true
log file = /var/log/samba/log.%m
max log size = 0
log level = 10
allow insecure wide links = yes   <------------------
unix extensions = no     <------------------
debug pid = true


[testshare]
comment = My Samba share
path = /home/IDM1/bijeshtesting/
read only = no
guest ok = no
valid users = +"IDM1\domain users"
write list = +"IDM1\domain users"
follow symlinks = yes   <------------------
wide links = yes        <------------------
==========


Steps to Reproduce:

As above

Actual results:

Folder containing Dangling/dead symlinks cannot be deleted.

Expected results:

Folder containing Dangling/dead symlinks should be deleted.

Additional info:

Samba sme expert Pavel Filipensky from Redhat was able to provide me below info

---
The fix was already coded by Jeremy Allison: https://bugzilla.samba.org/show_bug.cgi?id=14879. I was already able to verify that with 'delete veto files = yes' it will be possible to delete dir with dangling symlinks.

We will backport the fix to RHEL once it is ready. 
---

@Pavel Thank you..

Comment 14 errata-xmlrpc 2022-05-10 15:27:35 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (Moderate: samba security, bug fix, and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHSA-2022:2074