r16537: Fix for bug #3858, all files in a directory not
authorJeremy Allison <jra@samba.org>
Mon, 26 Jun 2006 23:36:03 +0000 (23:36 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 16:18:57 +0000 (11:18 -0500)
being deleted when hide unreadable set to true.

Here's the scoop.

This one is really interesting. The pattern of deleting a directory is to do a
findfirst to get the first part of the list, then for each name returned it
does a open/set delete on close/close -> thus deleting the file. Then it does a
findnext with the last file name THAT IT JUST DELETED ! Now we can handle this
in the findnext in the case where hide unreadable is set to false as we look
back in our cache of names and just seek to the right point. The bug is
actually fixed in the first hunk of this patch - the one that removes the
is_visible_file() check after SearchDir returns false. We don't actually need
it and in this case it's causing the delete to be aborted because it can't find
the name (doh ! it was just deleted). We don't need it as SearchDir is only
ever called from findnext, and findnext should only ever be returning names we
gave it.

The rest of the patch are the debugs I used to find
the problem but they're generically useful.

Phew - that one took a while to track down.....

Jerry, please merge for 3.0.23 final.

Jeremy.
(This used to be commit cd048cb775f0a8525fc19aa463db07c477521f5b)

source3/smbd/dir.c

index 27a4182c22066e1292b563399bbeef9af1bceee3..5ba9e1ed57558d6c94920bc4b02d57fa59a02f9b 100644 (file)
@@ -636,12 +636,7 @@ BOOL dptr_SearchDir(struct dptr_struct *dptr, const char *name, long *poffset, S
                return False;
        }
 
-       if (SearchDir(dptr->dir_hnd, name, poffset)) {
-               if (is_visible_file(dptr->conn, dptr->path, name, pst, True)) {
-                       return True;
-               }
-       }
-       return False;
+       return SearchDir(dptr->dir_hnd, name, poffset);
 }
 
 /****************************************************************************
@@ -854,6 +849,8 @@ static BOOL user_can_read_file(connection_struct *conn, char *name, SMB_STRUCT_S
 
        /* If we can't stat it does not show it */
        if (!VALID_STAT(*pst) && (SMB_VFS_STAT(conn, name, pst) != 0)) {
+               DEBUG(10,("user_can_read_file: SMB_VFS_STAT failed for file %s with error %s\n",
+                       name, strerror(errno) ));
                return False;
        }
 
@@ -992,6 +989,7 @@ BOOL is_visible_file(connection_struct *conn, const char *dir_path, const char *
 
        /* If it's a vetoed file, pretend it doesn't even exist */
        if (use_veto && IS_VETO_PATH(conn, name)) {
+               DEBUG(10,("is_visible_file: file %s is vetoed.\n", name ));
                return False;
        }
 
@@ -1003,16 +1001,19 @@ BOOL is_visible_file(connection_struct *conn, const char *dir_path, const char *
                }
                /* Honour _hide unreadable_ option */
                if (hide_unreadable && !user_can_read_file(conn, entry, pst)) {
+                       DEBUG(10,("is_visible_file: file %s is unreadable.\n", entry ));
                        SAFE_FREE(entry);
                        return False;
                }
                /* Honour _hide unwriteable_ option */
                if (hide_unwriteable && !user_can_write_file(conn, entry, pst)) {
+                       DEBUG(10,("is_visible_file: file %s is unwritable.\n", entry ));
                        SAFE_FREE(entry);
                        return False;
                }
                /* Honour _hide_special_ option */
                if (hide_special && file_is_special(conn, entry, pst)) {
+                       DEBUG(10,("is_visible_file: file %s is special.\n", entry ));
                        SAFE_FREE(entry);
                        return False;
                }