From: Jeremy Allison Date: Tue, 8 Feb 2011 23:05:00 +0000 (-0800) Subject: Pass fsp to dptr_CloseDir(). Cope with setting the fd if we're closing an fd that... X-Git-Tag: tevent-0.9.11~868 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=224fc03cb56b0d76f6ad7f18dd0528d6b0e57fb1;p=thirdparty%2Fsamba.git Pass fsp to dptr_CloseDir(). Cope with setting the fd if we're closing an fd that opendir knows about. --- diff --git a/source3/include/proto.h b/source3/include/proto.h index 77a7a4055a0..00e9de4c137 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -4548,7 +4548,7 @@ void dptr_closepath(struct smbd_server_connection *sconn, char *path,uint16 spid); NTSTATUS dptr_create(connection_struct *conn, const char *path, bool old_handle, bool expect_close,uint16 spid, const char *wcard, bool wcard_has_wild, uint32 attr, struct dptr_struct **dptr_ret); -int dptr_CloseDir(struct dptr_struct *dptr); +void dptr_CloseDir(files_struct *fsp); void dptr_SeekDir(struct dptr_struct *dptr, long offset); long dptr_TellDir(struct dptr_struct *dptr); bool dptr_has_wild(struct dptr_struct *dptr); diff --git a/source3/smbd/close.c b/source3/smbd/close.c index 25ed9a3c4db..d5a824f868f 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 7c9d6e262e0..f81206e0ecf 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 ded3d344c55..a9a12eaa0b2 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 9a7738ab762..b10446c3f10 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) {