The branch, master has been updated
       via  4db886db066 s3: smbd: Naming consistency. Change all uses of struct 
smb_Dir * variables to be dir_hnd.
       via  3d95064ceba s3: smbd: Naming consistency. Change all uses of struct 
smb_Dir * variables to be dir_hnd.
       via  a5b876f3dbd s3: smbd: Naming consistency. Change all uses of struct 
smb_Dir * variables to be dir_hnd.
       via  ec072f1a971 s3: smbd: Naming consistency. Change all uses of struct 
smb_Dir * variables to be dir_hnd.
       via  cc4ac86b950 s3: smbd: Naming consistency. Change all uses of struct 
smb_Dir * variables to be dir_hnd.
       via  8ad519c4089 s3: smbd: Naming consistency. Change all uses of struct 
smb_Dir * variables to be dir_hnd.
       via  8e65157edf4 s3: smbd: Naming consistency. Change all uses of struct 
smb_Dir * variables to be dir_hnd.
       via  79eae9e38ac s3: smbd: Naming consistency. Change all uses of struct 
smb_Dir * variables to be dir_hnd.
       via  eb5fa8ac846 s3: smbd: Use a separate simple destructor for the 
OpenDir() codepath.
       via  d1441089722 s3: smbd: Move the setting of the destructor of struct 
smb_Dir * up two levels.
       via  41c94b8b1f0 s3: smbd: OpenDir() is merely a wrapper around 
open_dir_safely().
      from  9d2fd082498 netcmd: Better error message for backup with no RID pool

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 4db886db066c53386aaa16a415c081bd50193af9
Author: Jeremy Allison <[email protected]>
Date:   Wed Jul 17 09:55:58 2019 -0700

    s3: smbd: Naming consistency. Change all uses of struct smb_Dir * variables 
to be dir_hnd.
    
    Fixes SearchDir(). No logic changes.
    
    Signed-off-by: Jeremy Allison <[email protected]>
    Reviewed-by: Andreas Schneider <[email protected]>
    
    Autobuild-User(master): Andreas Schneider <[email protected]>
    Autobuild-Date(master): Wed Jul 24 08:57:05 UTC 2019 on sn-devel-184

commit 3d95064ceba82a43f6edd5c4b250a22461986480
Author: Jeremy Allison <[email protected]>
Date:   Wed Jul 17 09:53:40 2019 -0700

    s3: smbd: Naming consistency. Change all uses of struct smb_Dir * variables 
to be dir_hnd.
    
    Fixes TellDir(). No logic changes.
    
    Signed-off-by: Jeremy Allison <[email protected]>
    Reviewed-by: Andreas Schneider <[email protected]>

commit a5b876f3dbdd2dc17407ec08340b5d192b374098
Author: Jeremy Allison <[email protected]>
Date:   Wed Jul 17 09:52:41 2019 -0700

    s3: smbd: Naming consistency. Change all uses of struct smb_Dir * variables 
to be dir_hnd.
    
    Fixes RewindDir(). No logic changes.
    
    Signed-off-by: Jeremy Allison <[email protected]>
    Reviewed-by: Andreas Schneider <[email protected]>

commit ec072f1a971faba9c140bae0f7792e5fc154189f
Author: Jeremy Allison <[email protected]>
Date:   Wed Jul 17 09:51:07 2019 -0700

    s3: smbd: Naming consistency. Change all uses of struct smb_Dir * variables 
to be dir_hnd.
    
    Fixes ReadDirName(). No logic changes.
    
    Signed-off-by: Jeremy Allison <[email protected]>
    Reviewed-by: Andreas Schneider <[email protected]>

commit cc4ac86b950f443b4dd23ca997d872549c80a484
Author: Jeremy Allison <[email protected]>
Date:   Wed Jul 17 09:47:31 2019 -0700

    s3: smbd: Naming consistency. Change all uses of struct smb_Dir * variables 
to be dir_hnd.
    
    Fixes OpenDir_fsp(). No logic changes.
    
    Signed-off-by: Jeremy Allison <[email protected]>
    Reviewed-by: Andreas Schneider <[email protected]>

commit 8ad519c4089df71a9fc9191cead68e4eabf844f1
Author: Jeremy Allison <[email protected]>
Date:   Wed Jul 17 09:44:56 2019 -0700

    s3: smbd: Naming consistency. Change all uses of struct smb_Dir * variables 
to be dir_hnd.
    
    Fixes OpenDir_internal(). No logic changes.
    
    Signed-off-by: Jeremy Allison <[email protected]>
    Reviewed-by: Andreas Schneider <[email protected]>

commit 8e65157edf4fe5a9e7c4abdd6c0f2a8d5b8c43b2
Author: Jeremy Allison <[email protected]>
Date:   Wed Jul 17 09:42:45 2019 -0700

    s3: smbd: Naming consistency. Change all uses of struct smb_Dir * variables 
to be dir_hnd.
    
    Fixes DirCacheAdd(). No logic changes.
    
    Signed-off-by: Jeremy Allison <[email protected]>
    Reviewed-by: Andreas Schneider <[email protected]>

commit 79eae9e38ac2ef967671b43fc2eb76d8b195eee8
Author: Jeremy Allison <[email protected]>
Date:   Wed Jul 17 09:40:04 2019 -0700

    s3: smbd: Naming consistency. Change all uses of struct smb_Dir * variables 
to be dir_hnd.
    
    Fixes smb_Dir_destructor(). No logic changes.
    
    Signed-off-by: Jeremy Allison <[email protected]>
    Reviewed-by: Andreas Schneider <[email protected]>

commit eb5fa8ac8465e621c95da1f03b68da8aae73f6b0
Author: Jeremy Allison <[email protected]>
Date:   Wed Jul 17 09:31:46 2019 -0700

    s3: smbd: Use a separate simple destructor for the OpenDir() codepath.
    
    This will help greatly in understanding the code changes later.
    
    Signed-off-by: Jeremy Allison <[email protected]>
    Reviewed-by: Andreas Schneider <[email protected]>

commit d1441089722b7985df417494f6542e6560e99330
Author: Jeremy Allison <[email protected]>
Date:   Wed Jul 17 09:11:25 2019 -0700

    s3: smbd: Move the setting of the destructor of struct smb_Dir * up two 
levels.
    
    Previously, open_dir_safely() called OpenDir_internal() which
    set the destructor.
    
    Move setting the destructor into the callers of open_dir_safely()
    as this will allow us to have different destructors for handle-based
    calls.
    
    The reason this is important is that I have a follow up patchset
    that depends on this which makes all client directory enumerations
    handle-based, calling OpenDir_fsp() only, and so the destructor there
    will take care of the fsp back pointer.
    
    Trying to keep a common destructor for handle-based and non-handle
    based calls broke my brain when trying to separate the handle-based
    calls from the non-handle based ones in my later patchset.
    
    NB. The change in OpenDir_fsp() isn't a logic change as instead
    of doing an early return from a function that sets the destructor,
    we now fallthrough to setting the destructor then return, which
    is identical.
    
    Eventually the whole codepath using the fallback for non-handle
    opens inside dptr_create() will go away and this simplifies the
    code immensely. Some short term pain for long-term gain :-).
    
    Added doxygen documentation as requested.
    
    Signed-off-by: Jeremy Allison <[email protected]>
    Reviewed-by: Andreas Schneider <[email protected]>

commit 41c94b8b1f0ba312711b5b6c2ba2f27c696b445b
Author: Jeremy Allison <[email protected]>
Date:   Wed Jul 17 08:56:49 2019 -0700

    s3: smbd: OpenDir() is merely a wrapper around open_dir_safely().
    
    Preparatory work.
    
    Separate these out internal to source3/smbd/dir.c so I can
    give the internal and external uses separate destructor functions
    to allow all client requested directory enumeration to move to handle
    based functions.
    
    Signed-off-by: Jeremy Allison <[email protected]>
    Reviewed-by: Andreas Schneider <[email protected]>

-----------------------------------------------------------------------

Summary of changes:
 source3/smbd/dir.c   | 235 +++++++++++++++++++++++++++++++++------------------
 source3/smbd/proto.h |   4 +-
 2 files changed, 154 insertions(+), 85 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source3/smbd/dir.c b/source3/smbd/dir.c
index 2c59cb898ec..7a845e9a2d0 100644
--- a/source3/smbd/dir.c
+++ b/source3/smbd/dir.c
@@ -83,7 +83,14 @@ static struct smb_Dir *OpenDir_fsp(TALLOC_CTX *mem_ctx, 
connection_struct *conn,
                        const char *mask,
                        uint32_t attr);
 
-static void DirCacheAdd(struct smb_Dir *dirp, const char *name, long offset);
+static void DirCacheAdd(struct smb_Dir *dir_hnd, const char *name, long 
offset);
+
+static struct smb_Dir *open_dir_safely(TALLOC_CTX *ctx,
+                                       connection_struct *conn,
+                                       const struct smb_filename *smb_dname,
+                                       const char *wcard,
+                                       uint32_t attr);
+static int smb_Dir_destructor(struct smb_Dir *dir_hnd);
 
 #define INVALID_DPTR_KEY (-3)
 
@@ -334,7 +341,11 @@ static struct smb_Dir 
*open_dir_with_privilege(connection_struct *conn,
                goto out;
        }
 
-       dir_hnd = OpenDir(NULL, conn, smb_fname_cwd, wcard, attr);
+       dir_hnd = open_dir_safely(NULL, conn, smb_fname_cwd, wcard, attr);
+
+       if (dir_hnd != NULL) {
+               talloc_set_destructor(dir_hnd, smb_Dir_destructor);
+       }
 
   out:
 
@@ -431,12 +442,18 @@ NTSTATUS dptr_create(connection_struct *conn,
                                                wcard,
                                                attr);
                } else {
-                       dir_hnd = OpenDir(NULL,
+                       dir_hnd = open_dir_safely(NULL,
                                        conn,
                                        smb_dname_cp,
                                        wcard,
                                        attr);
+                       if (dir_hnd != NULL) {
+                               talloc_set_destructor(dir_hnd,
+                                       smb_Dir_destructor);
+                       }
                }
+
+
                TALLOC_FREE(smb_dname_cp);
        }
 
@@ -1495,22 +1512,23 @@ bool is_visible_file(connection_struct *conn, const 
char *dir_path,
        return ret;
 }
 
-static int smb_Dir_destructor(struct smb_Dir *dirp)
+static int smb_Dir_destructor(struct smb_Dir *dir_hnd)
 {
-       if (dirp->dir != NULL) {
-               SMB_VFS_CLOSEDIR(dirp->conn,dirp->dir);
-               if (dirp->fsp != NULL) {
+       if (dir_hnd->dir != NULL) {
+               SMB_VFS_CLOSEDIR(dir_hnd->conn, dir_hnd->dir);
+               if (dir_hnd->fsp != NULL) {
                        /*
                         * The SMB_VFS_CLOSEDIR above
                         * closes the underlying fd inside
                         * dirp->fsp.
                         */
-                       dirp->fsp->fh->fd = -1;
-                       if (dirp->fsp->dptr != NULL) {
-                               SMB_ASSERT(dirp->fsp->dptr->dir_hnd == dirp);
-                               dirp->fsp->dptr->dir_hnd = NULL;
+                       dir_hnd->fsp->fh->fd = -1;
+                       if (dir_hnd->fsp->dptr != NULL) {
+                               SMB_ASSERT(dir_hnd->fsp->dptr->dir_hnd ==
+                                       dir_hnd);
+                               dir_hnd->fsp->dptr->dir_hnd = NULL;
                        }
-                       dirp->fsp = NULL;
+                       dir_hnd->fsp = NULL;
                }
        }
        return 0;
@@ -1526,22 +1544,22 @@ static struct smb_Dir *OpenDir_internal(TALLOC_CTX 
*mem_ctx,
                        const char *mask,
                        uint32_t attr)
 {
-       struct smb_Dir *dirp = talloc_zero(mem_ctx, struct smb_Dir);
+       struct smb_Dir *dir_hnd = talloc_zero(mem_ctx, struct smb_Dir);
 
-       if (!dirp) {
+       if (!dir_hnd) {
                return NULL;
        }
 
-       dirp->dir = SMB_VFS_OPENDIR(conn, smb_dname, mask, attr);
+       dir_hnd->dir = SMB_VFS_OPENDIR(conn, smb_dname, mask, attr);
 
-       if (!dirp->dir) {
+       if (!dir_hnd->dir) {
                DEBUG(5,("OpenDir: Can't open %s. %s\n",
                        smb_dname->base_name,
                        strerror(errno) ));
                goto fail;
        }
 
-       dirp->conn = conn;
+       dir_hnd->conn = conn;
 
        if (!conn->sconn->using_smb2) {
                /*
@@ -1550,21 +1568,47 @@ static struct smb_Dir *OpenDir_internal(TALLOC_CTX 
*mem_ctx,
                 * position (unless it's told to restart or close-and-reopen the
                 * listing).
                 */
-               dirp->name_cache_size = 
lp_directory_name_cache_size(SNUM(conn));
+               dir_hnd->name_cache_size =
+                       lp_directory_name_cache_size(SNUM(conn));
        }
 
-       talloc_set_destructor(dirp, smb_Dir_destructor);
-
-       return dirp;
+       return dir_hnd;
 
   fail:
-       TALLOC_FREE(dirp);
+       TALLOC_FREE(dir_hnd);
        return NULL;
 }
 
-/****************************************************************************
- Open a directory handle by pathname, ensuring it's under the share path.
-****************************************************************************/
+/**
+ * @brief Open a directory handle by pathname, ensuring it's under the share 
path.
+ *
+ * First stores the $cwd, then changes directory to the passed in pathname
+ * uses check_name() to ensure this is under the connection struct share path,
+ * then operates on a pathname of "." to ensure we're in the same place.
+ *
+ * The returned struct smb_Dir * should have a talloc destrctor added to
+ * ensure that when the struct is freed the internal POSIX DIR * pointer
+ * is closed.
+ *
+ * @code
+ *
+ * static int sample_smb_Dir_destructor(struct smb_Dir *dirp)
+ * {
+ *     SMB_VFS_CLOSEDIR(dirp->conn,dirp->dir);
+ * }
+ * ..
+ *     struct smb_Dir *dir_hnd = open_dir_safely(mem_ctx,
+ *                              conn,
+ *                              smb_dname,
+ *                              mask,
+ *                              attr);
+ *      if (dir_hnd == NULL) {
+ *              return NULL;
+ *      }
+ *      talloc_set_destructor(dir_hnd, smb_Dir_destructor);
+ * ..
+ * @endcode
+ */
 
 static struct smb_Dir *open_dir_safely(TALLOC_CTX *ctx,
                                        connection_struct *conn,
@@ -1621,6 +1665,7 @@ static struct smb_Dir *open_dir_safely(TALLOC_CTX *ctx,
        dir_hnd->dir_smb_fname = cp_smb_filename(dir_hnd, smb_dname);
        if (!dir_hnd->dir_smb_fname) {
                TALLOC_FREE(dir_hnd);
+               SMB_VFS_CLOSEDIR(conn, dir_hnd->dir);
                errno = ENOMEM;
        }
 
@@ -1631,16 +1676,33 @@ static struct smb_Dir *open_dir_safely(TALLOC_CTX *ctx,
        return dir_hnd;
 }
 
+/*
+ * Simple destructor for OpenDir() use. Don't need to
+ * care about fsp back pointer as we know we have never
+ * set it in the OpenDir() code path.
+ */
+
+static int smb_Dir_OpenDir_destructor(struct smb_Dir *dir_hnd)
+{
+       SMB_VFS_CLOSEDIR(dir_hnd->conn, dir_hnd->dir);
+       return 0;
+}
+
 struct smb_Dir *OpenDir(TALLOC_CTX *mem_ctx, connection_struct *conn,
                        const struct smb_filename *smb_dname,
                        const char *mask,
                        uint32_t attr)
 {
-       return open_dir_safely(mem_ctx,
+       struct smb_Dir *dir_hnd = open_dir_safely(mem_ctx,
                                conn,
                                smb_dname,
                                mask,
                                attr);
+       if (dir_hnd == NULL) {
+               return NULL;
+       }
+       talloc_set_destructor(dir_hnd, smb_Dir_OpenDir_destructor);
+       return dir_hnd;
 }
 
 /*******************************************************************
@@ -1652,9 +1714,9 @@ static struct smb_Dir *OpenDir_fsp(TALLOC_CTX *mem_ctx, 
connection_struct *conn,
                        const char *mask,
                        uint32_t attr)
 {
-       struct smb_Dir *dirp = talloc_zero(mem_ctx, struct smb_Dir);
+       struct smb_Dir *dir_hnd = talloc_zero(mem_ctx, struct smb_Dir);
 
-       if (!dirp) {
+       if (!dir_hnd) {
                goto fail;
        }
 
@@ -1668,7 +1730,7 @@ static struct smb_Dir *OpenDir_fsp(TALLOC_CTX *mem_ctx, 
connection_struct *conn,
                goto fail;
        }
 
-       dirp->conn = conn;
+       dir_hnd->conn = conn;
 
        if (!conn->sconn->using_smb2) {
                /*
@@ -1677,44 +1739,49 @@ static struct smb_Dir *OpenDir_fsp(TALLOC_CTX *mem_ctx, 
connection_struct *conn,
                 * position (unless it's told to restart or close-and-reopen the
                 * listing).
                 */
-               dirp->name_cache_size = 
lp_directory_name_cache_size(SNUM(conn));
+               dir_hnd->name_cache_size =
+                       lp_directory_name_cache_size(SNUM(conn));
        }
 
-       dirp->dir_smb_fname = cp_smb_filename(dirp, fsp->fsp_name);
-       if (!dirp->dir_smb_fname) {
+       dir_hnd->dir_smb_fname = cp_smb_filename(dir_hnd, fsp->fsp_name);
+       if (!dir_hnd->dir_smb_fname) {
                errno = ENOMEM;
                goto fail;
        }
 
-       dirp->dir = SMB_VFS_FDOPENDIR(fsp, mask, attr);
-       if (dirp->dir != NULL) {
-               dirp->fsp = fsp;
+       dir_hnd->dir = SMB_VFS_FDOPENDIR(fsp, mask, attr);
+       if (dir_hnd->dir != NULL) {
+               dir_hnd->fsp = fsp;
        } else {
                DEBUG(10,("OpenDir_fsp: SMB_VFS_FDOPENDIR on %s returned "
                        "NULL (%s)\n",
-                       dirp->dir_smb_fname->base_name,
+                       dir_hnd->dir_smb_fname->base_name,
                        strerror(errno)));
                if (errno != ENOSYS) {
                        goto fail;
                }
        }
 
-       if (dirp->dir == NULL) {
+       if (dir_hnd->dir == NULL) {
                /* FDOPENDIR is not supported. Use OPENDIR instead. */
-               TALLOC_FREE(dirp);
-               return open_dir_safely(mem_ctx,
+               TALLOC_FREE(dir_hnd);
+               dir_hnd = open_dir_safely(mem_ctx,
                                        conn,
                                        fsp->fsp_name,
                                        mask,
                                        attr);
+               if (dir_hnd == NULL) {
+                       errno = ENOMEM;
+                       goto fail;
+               }
        }
 
-       talloc_set_destructor(dirp, smb_Dir_destructor);
+       talloc_set_destructor(dir_hnd, smb_Dir_destructor);
 
-       return dirp;
+       return dir_hnd;
 
   fail:
-       TALLOC_FREE(dirp);
+       TALLOC_FREE(dir_hnd);
        return NULL;
 }
 
@@ -1725,38 +1792,38 @@ static struct smb_Dir *OpenDir_fsp(TALLOC_CTX *mem_ctx, 
connection_struct *conn,
  Don't check for veto or invisible files.
 ********************************************************************/
 
-const char *ReadDirName(struct smb_Dir *dirp, long *poffset,
+const char *ReadDirName(struct smb_Dir *dir_hnd, long *poffset,
                        SMB_STRUCT_STAT *sbuf, char **ptalloced)
 {
        const char *n;
        char *talloced = NULL;
-       connection_struct *conn = dirp->conn;
+       connection_struct *conn = dir_hnd->conn;
 
        /* Cheat to allow . and .. to be the first entries returned. */
        if (((*poffset == START_OF_DIRECTORY_OFFSET) ||
-            (*poffset == DOT_DOT_DIRECTORY_OFFSET)) && (dirp->file_number < 2))
+            (*poffset == DOT_DOT_DIRECTORY_OFFSET)) && (dir_hnd->file_number < 
2))
        {
-               if (dirp->file_number == 0) {
+               if (dir_hnd->file_number == 0) {
                        n = ".";
-                       *poffset = dirp->offset = START_OF_DIRECTORY_OFFSET;
+                       *poffset = dir_hnd->offset = START_OF_DIRECTORY_OFFSET;
                } else {
                        n = "..";
-                       *poffset = dirp->offset = DOT_DOT_DIRECTORY_OFFSET;
+                       *poffset = dir_hnd->offset = DOT_DOT_DIRECTORY_OFFSET;
                }
-               dirp->file_number++;
+               dir_hnd->file_number++;
                *ptalloced = NULL;
                return n;
        }
 
        if (*poffset == END_OF_DIRECTORY_OFFSET) {
-               *poffset = dirp->offset = END_OF_DIRECTORY_OFFSET;
+               *poffset = dir_hnd->offset = END_OF_DIRECTORY_OFFSET;
                return NULL;
        }
 
        /* A real offset, seek to it. */
-       SeekDir(dirp, *poffset);
+       SeekDir(dir_hnd, *poffset);
 
-       while ((n = vfs_readdirname(conn, dirp->dir, sbuf, &talloced))) {
+       while ((n = vfs_readdirname(conn, dir_hnd->dir, sbuf, &talloced))) {
                /* Ignore . and .. - we've already returned them. */
                if (*n == '.') {
                        if ((n[1] == '\0') || (n[1] == '.' && n[2] == '\0')) {
@@ -1764,12 +1831,12 @@ const char *ReadDirName(struct smb_Dir *dirp, long 
*poffset,
                                continue;
                        }
                }
-               *poffset = dirp->offset = SMB_VFS_TELLDIR(conn, dirp->dir);
+               *poffset = dir_hnd->offset = SMB_VFS_TELLDIR(conn, 
dir_hnd->dir);
                *ptalloced = talloced;
-               dirp->file_number++;
+               dir_hnd->file_number++;
                return n;
        }
-       *poffset = dirp->offset = END_OF_DIRECTORY_OFFSET;
+       *poffset = dir_hnd->offset = END_OF_DIRECTORY_OFFSET;
        *ptalloced = NULL;
        return NULL;
 }
@@ -1778,11 +1845,11 @@ const char *ReadDirName(struct smb_Dir *dirp, long 
*poffset,
  Rewind to the start.
 ********************************************************************/
 
-void RewindDir(struct smb_Dir *dirp, long *poffset)
+void RewindDir(struct smb_Dir *dir_hnd, long *poffset)
 {
-       SMB_VFS_REWINDDIR(dirp->conn, dirp->dir);
-       dirp->file_number = 0;
-       dirp->offset = START_OF_DIRECTORY_OFFSET;
+       SMB_VFS_REWINDDIR(dir_hnd->conn, dir_hnd->dir);
+       dir_hnd->file_number = 0;
+       dir_hnd->offset = START_OF_DIRECTORY_OFFSET;
        *poffset = START_OF_DIRECTORY_OFFSET;
 }
 
@@ -1823,37 +1890,38 @@ void SeekDir(struct smb_Dir *dirp, long offset)
  Tell a dir position.
 ********************************************************************/
 
-long TellDir(struct smb_Dir *dirp)
+long TellDir(struct smb_Dir *dir_hnd)
 {
-       return(dirp->offset);
+       return(dir_hnd->offset);
 }
 
 /*******************************************************************
  Add an entry into the dcache.
 ********************************************************************/
 
-static void DirCacheAdd(struct smb_Dir *dirp, const char *name, long offset)
+static void DirCacheAdd(struct smb_Dir *dir_hnd, const char *name, long offset)
 {
        struct name_cache_entry *e;
 
-       if (dirp->name_cache_size == 0) {
+       if (dir_hnd->name_cache_size == 0) {
                return;
        }
 
-       if (dirp->name_cache == NULL) {
-               dirp->name_cache = talloc_zero_array(
-                       dirp, struct name_cache_entry, dirp->name_cache_size);
+       if (dir_hnd->name_cache == NULL) {
+               dir_hnd->name_cache = talloc_zero_array(dir_hnd,
+                                               struct name_cache_entry,
+                                               dir_hnd->name_cache_size);
 
-               if (dirp->name_cache == NULL) {
+               if (dir_hnd->name_cache == NULL) {
                        return;
                }
        }
 
-       dirp->name_cache_index = (dirp->name_cache_index+1) %
-                                       dirp->name_cache_size;
-       e = &dirp->name_cache[dirp->name_cache_index];
+       dir_hnd->name_cache_index = (dir_hnd->name_cache_index+1) %
+                                       dir_hnd->name_cache_size;
+       e = &dir_hnd->name_cache[dir_hnd->name_cache_index];
        TALLOC_FREE(e->name);
-       e->name = talloc_strdup(dirp, name);
+       e->name = talloc_strdup(dir_hnd, name);
        e->offset = offset;
 }
 
@@ -1862,38 +1930,39 @@ static void DirCacheAdd(struct smb_Dir *dirp, const 
char *name, long offset)
  Don't check for veto or invisible files.
 ********************************************************************/
 
-bool SearchDir(struct smb_Dir *dirp, const char *name, long *poffset)
+bool SearchDir(struct smb_Dir *dir_hnd, const char *name, long *poffset)
 {
        int i;
        const char *entry = NULL;
        char *talloced = NULL;
-       connection_struct *conn = dirp->conn;
+       connection_struct *conn = dir_hnd->conn;
 
        /* Search back in the name cache. */
-       if (dirp->name_cache_size && dirp->name_cache) {
-               for (i = dirp->name_cache_index; i >= 0; i--) {
-                       struct name_cache_entry *e = &dirp->name_cache[i];
+       if (dir_hnd->name_cache_size && dir_hnd->name_cache) {
+               for (i = dir_hnd->name_cache_index; i >= 0; i--) {
+                       struct name_cache_entry *e = &dir_hnd->name_cache[i];
                        if (e->name && (conn->case_sensitive ? (strcmp(e->name, 
name) == 0) : strequal(e->name, name))) {
                                *poffset = e->offset;
-                               SeekDir(dirp, e->offset);
+                               SeekDir(dir_hnd, e->offset);
                                return True;
                        }
                }
-               for (i = dirp->name_cache_size - 1; i > dirp->name_cache_index; 
i--) {
-                       struct name_cache_entry *e = &dirp->name_cache[i];
+               for (i = dir_hnd->name_cache_size - 1;
+                               i > dir_hnd->name_cache_index; i--) {
+                       struct name_cache_entry *e = &dir_hnd->name_cache[i];
                        if (e->name && (conn->case_sensitive ? (strcmp(e->name, 
name) == 0) : strequal(e->name, name))) {
                                *poffset = e->offset;
-                               SeekDir(dirp, e->offset);
+                               SeekDir(dir_hnd, e->offset);
                                return True;
                        }
                }
        }
 
        /* Not found in the name cache. Rewind directory and start from 
scratch. */
-       SMB_VFS_REWINDDIR(conn, dirp->dir);
-       dirp->file_number = 0;
+       SMB_VFS_REWINDDIR(conn, dir_hnd->dir);
+       dir_hnd->file_number = 0;
        *poffset = START_OF_DIRECTORY_OFFSET;
-       while ((entry = ReadDirName(dirp, poffset, NULL, &talloced))) {
+       while ((entry = ReadDirName(dir_hnd, poffset, NULL, &talloced))) {
                if (conn->case_sensitive ? (strcmp(entry, name) == 0) : 
strequal(entry, name)) {
                        TALLOC_FREE(talloced);
                        return True;
diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h
index 4a47d394686..1bdf1b03760 100644
--- a/source3/smbd/proto.h
+++ b/source3/smbd/proto.h
@@ -230,9 +230,9 @@ struct smb_Dir *OpenDir(TALLOC_CTX *mem_ctx,
                        const struct smb_filename *smb_fname,
                        const char *mask,
                        uint32_t attr);
-const char *ReadDirName(struct smb_Dir *dirp, long *poffset,
+const char *ReadDirName(struct smb_Dir *dir_hnd, long *poffset,
                        SMB_STRUCT_STAT *sbuf, char **talloced);
-void RewindDir(struct smb_Dir *dirp, long *poffset);
+void RewindDir(struct smb_Dir *dir_hnd, long *poffset);
 void SeekDir(struct smb_Dir *dirp, long offset);
 long TellDir(struct smb_Dir *dirp);
 bool SearchDir(struct smb_Dir *dirp, const char *name, long *poffset);


-- 
Samba Shared Repository

Reply via email to