From 224fc03cb56b0d76f6ad7f18dd0528d6b0e57fb1 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 8 Feb 2011 15:05:00 -0800 Subject: Pass fsp to dptr_CloseDir(). Cope with setting the fd if we're closing an fd that opendir knows about. --- source3/smbd/close.c | 4 ---- source3/smbd/dir.c | 12 +++++++++--- source3/smbd/open.c | 3 +++ source3/smbd/smb2_find.c | 5 +---- 4 files changed, 13 insertions(+), 11 deletions(-) (limited to 'source3/smbd') diff --git a/source3/smbd/close.c b/source3/smbd/close.c index 25ed9a3c4d..d5a824f868 100644 --- a/source3/smbd/close.c +++ b/source3/smbd/close.c @@ -1061,10 +1061,6 @@ static NTSTATUS close_directory(struct smb_request *req, files_struct *fsp, strerror(errno))); } - if (fsp->dptr) { - dptr_CloseDir(fsp->dptr); - } - /* * Do the code common to files and directories. */ diff --git a/source3/smbd/dir.c b/source3/smbd/dir.c index 7c9d6e262e..f81206e0ec 100644 --- a/source3/smbd/dir.c +++ b/source3/smbd/dir.c @@ -554,10 +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) { - dptr_close_internal(dptr); - 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) diff --git a/source3/smbd/open.c b/source3/smbd/open.c index ded3d344c5..a9a12eaa0b 100644 --- a/source3/smbd/open.c +++ b/source3/smbd/open.c @@ -168,6 +168,9 @@ NTSTATUS fd_close(files_struct *fsp) { int ret; + if (fsp->dptr) { + dptr_CloseDir(fsp); + } if (fsp->fh->fd == -1) { return NT_STATUS_OK; /* What we used to call a stat open. */ } diff --git a/source3/smbd/smb2_find.c b/source3/smbd/smb2_find.c index 9a7738ab76..b10446c3f1 100644 --- a/source3/smbd/smb2_find.c +++ b/source3/smbd/smb2_find.c @@ -317,10 +317,7 @@ static struct tevent_req *smbd_smb2_find_send(TALLOC_CTX *mem_ctx, } if (in_flags & SMB2_CONTINUE_FLAG_REOPEN) { - if (fsp->dptr) { - dptr_CloseDir(fsp->dptr); - fsp->dptr = NULL; - } + dptr_CloseDir(fsp); } if (fsp->dptr == NULL) { -- cgit