Pass fsp to dptr_CloseDir(). Cope with setting the fd if we're closing an fd that...
[samba.git] / source3 / smbd / dir.c
index 69c5d7534a6b2f1d131d57dde01c647a6049f38a..f81206e0ecfeebde899a2d1c0a3c1779570f403d 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "includes.h"
 #include "smbd/globals.h"
+#include "libcli/security/security.h"
 
 /*
    This module implements directory related functions for Samba.
@@ -121,7 +122,8 @@ bool init_dptrs(struct smbd_server_connection *sconn)
                return true;
        }
 
-       sconn->smb1.searches.dptr_bmap = bitmap_allocate(MAX_DIRECTORY_HANDLES);
+       sconn->smb1.searches.dptr_bmap = bitmap_talloc(
+               sconn, MAX_DIRECTORY_HANDLES);
 
        if (sconn->smb1.searches.dptr_bmap == NULL) {
                return false;
@@ -259,7 +261,7 @@ static void dptr_close_internal(struct dptr_struct *dptr)
         * biased by one with respect to the bitmap.
         */
 
-       if(bitmap_query(sconn->smb1.searches.dptr_bmap, dptr->dnum - 1) != true) {
+       if (!bitmap_query(sconn->smb1.searches.dptr_bmap, dptr->dnum - 1)) {
                DEBUG(0,("dptr_close_internal : Error - closing dnum = %d and bitmap not set !\n",
                        dptr->dnum ));
        }
@@ -552,12 +554,16 @@ NTSTATUS dptr_create(connection_struct *conn, const char *path, bool old_handle,
  Wrapper functions to access the lower level directory handles.
 ****************************************************************************/
 
-int dptr_CloseDir(struct dptr_struct *dptr)
+void dptr_CloseDir(files_struct *fsp)
 {
-       struct smbd_server_connection *sconn = dptr->conn->sconn;
-       DLIST_REMOVE(sconn->smb1.searches.dirptrs, dptr);
-       TALLOC_FREE(dptr->dir_hnd);
-       return 0;
+       if (fsp->dptr) {
+               if (fsp->fh->fd == dirfd(fsp->dptr->dir_hnd->dir)) {
+                       /* The call below closes the underlying fd. */
+                       fsp->fh->fd = -1;
+               }
+               dptr_close_internal(fsp->dptr);
+               fsp->dptr = NULL;
+       }
 }
 
 void dptr_SeekDir(struct dptr_struct *dptr, long offset)
@@ -981,7 +987,7 @@ bool smbd_dirptr_get_entry(TALLOC_CTX *ctx,
 
                        fileid = vfs_file_id_from_sbuf(conn,
                                                       &smb_fname.st);
-                       get_file_infos(fileid, NULL, &write_time_ts);
+                       get_file_infos(fileid, 0, NULL, &write_time_ts);
                        if (!null_timespec(write_time_ts)) {
                                update_stat_ex_mtime(&smb_fname.st,
                                                     write_time_ts);