Bug 13637 - Directory browse with smbc_readdir() does not show broken symlinks
Summary: Directory browse with smbc_readdir() does not show broken symlinks
Alias: None
Product: Samba 4.1 and newer
Classification: Unclassified
Component: libsmbclient (show other bugs)
Version: 4.8.5
Hardware: All All
: P5 normal (vote)
Target Milestone: ---
Assignee: Samba QA Contact
QA Contact: Samba QA Contact
Depends on:
Reported: 2018-10-01 09:04 UTC by Michal Malý
Modified: 2018-10-01 20:48 UTC (History)
0 users

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Michal Malý 2018-10-01 09:04:26 UTC

this behavior of smbc_readdir() had me puzzled for a while this morning. Suppose I have a directory containing a "file.dat" and a "file.lnk" which is a symlink pointing to "file.dat". When I open the directory with "smbc_opendir()" and iterate through its content with "smbc_readdir()" I will get both the "file.dat" and "file.lnk". Now if I remove the "file.dat" but leave the - now broken - symlink, smbc_readdir() will not show me the "file.lnk" file.

This becomes a problem when a user tries to delete a directory containing such entries. If the deleting function happens to delete the symlink target before the actual symlink, "smbc_rmdir()" will return ENOTEMPTY and the directory becomes undeletable through Samba.

I can reproduce this behavior with a CentOS 7 server running Samba 4.7.1 and libsmbclient from Samba 4.8.5 used though KDE's KIO Samba plugin on a client running Arch Linux.

Steps to reproduce (run on server):
1) touch file.dat
2) ln -s file.dat file.lnk
3) rm file.dat

4) Walk through the directory on client.
Comment 1 Jeremy Allison 2018-10-01 18:23:16 UTC
Unfortunately this is by design. Clients using SMB windows access methods see symlinks as real files, and if they are broken they cannot access them.

If you want to see symlinks as symlinks, you need to access the filesystem using the POSIX extensions. At that point you can manipulate and destroy them.

You'll need to fix the broken symlinks before non-posix access can remove them.
Comment 2 Michal Malý 2018-10-01 20:37:17 UTC
Okay, thanks for clearing this up. It is my understanding that I currently can’t enable POSIX extensions if my client is libsmbclient-based?
Comment 3 Jeremy Allison 2018-10-01 20:48:02 UTC
Yes, I don't think we expose the cli_posix_XXX() function calls we have to libsmbclient code. We could do so, by allowing the caller to specify they want POSIX semantics but we don't currently have that code.