Reporting broken symlinks to clients
Christof Schmitt
christof.schmitt at us.ibm.com
Thu Jun 13 17:22:38 MDT 2013
I got asked if it would make sense to report broken symlinks to
Windows clients. With the current code, the stat() call in
smbd_dirptr_lanman2_mode_fn fails on the broken symlink and it is not
reported in the directory listing to the client. This could be changed
without too much effort, like this hack:
--- a/source3/smbd/trans2.c
+++ b/source3/smbd/trans2.c
@@ -1553,11 +1553,22 @@ static bool
smbd_dirptr_lanman2_mode_fn(TALLOC_CTX *ctx,
SMB_VFS_STAT(state->conn, smb_fname) != 0) {
/* Needed to show the msdfs symlinks as
* directories */
+ int stat_errno = errno;
ms_dfs_link = check_msdfs_link(state->conn,
smb_fname->base_name,
&smb_fname->st);
- if (!ms_dfs_link) {
+ if (!ms_dfs_link && stat_errno == ENOENT) {
+ /* Invalid link target, try to get lstat() data to show
+ * a dummy file */
+ if (SMB_VFS_LSTAT(state->conn, smb_fname) != 0) {
+ DEBUG(5,("smbd_dirptr_lanman2_mode_fn: "
+ "Couldn't stat and lstat [%s] (%s)\n",
+ smb_fname_str_dbg(smb_fname),
+ strerror(errno)));
+ return false;
+ }
+ } else if (!ms_dfs_link) {
DEBUG(5,("smbd_dirptr_lanman2_mode_fn: "
"Couldn't stat [%s] (%s)\n",
smb_fname_str_dbg(smb_fname),
This could be useful in environments where the same directory is
accessible to Windows clients and to Linux/Unix systems. When a
broken symlink is created, the Windows clients would at least be able
to see that there is a file.
Comments?
--
Christof Schmitt || IBM || SONAS System Development || Tucson, AZ
christof.schmitt at us.ibm.com || +1-520-799-2469 (T/L: 321-2469)
More information about the samba-technical
mailing list