From: Ralph Boehme Date: Sat, 3 Oct 2020 19:24:29 +0000 (+0200) Subject: smbd: use fsp_get_pathref_fd() when close()ing fds X-Git-Tag: samba-4.14.0rc1~415 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0208ca6946db7f800977d20cdda0ae7df03ae635;p=thirdparty%2Fsamba.git smbd: use fsp_get_pathref_fd() when close()ing fds Signed-off-by: Ralph Boehme Reviewed-by: Jeremy Allison --- diff --git a/source3/locking/posix.c b/source3/locking/posix.c index a233f74d593..536d8bf802b 100644 --- a/source3/locking/posix.c +++ b/source3/locking/posix.c @@ -521,10 +521,11 @@ static void add_fd_to_close_entry_fn( void *private_data) { struct add_fd_to_close_entry_state *state = private_data; + int fd = fsp_get_pathref_fd(state->fsp); TDB_DATA values[] = { value, - { .dptr = (uint8_t *)&(state->fsp->fh->fd), - .dsize = sizeof(state->fsp->fh->fd) }, + { .dptr = (uint8_t *)&fd, + .dsize = sizeof(fd) }, }; NTSTATUS status; @@ -593,7 +594,7 @@ int fd_close_posix(const struct files_struct *fsp) * open file description lock semantics which only removes * locks on the file descriptor we're closing. Just close. */ - return close(fsp->fh->fd); + return close(fsp_get_pathref_fd(fsp)); } if (get_lock_ref_count(fsp)) { @@ -626,7 +627,7 @@ int fd_close_posix(const struct files_struct *fsp) * Finally close the fd associated with this fsp. */ - return close(fsp->fh->fd); + return close(fsp_get_pathref_fd(fsp)); } /**************************************************************************** diff --git a/source3/modules/vfs_aio_fork.c b/source3/modules/vfs_aio_fork.c index f58d37ece13..772906fb771 100644 --- a/source3/modules/vfs_aio_fork.c +++ b/source3/modules/vfs_aio_fork.c @@ -419,8 +419,8 @@ static int aio_child_destructor(struct aio_child *child) static struct files_struct *close_fsp_fd(struct files_struct *fsp, void *private_data) { - if ((fsp->fh != NULL) && (fsp->fh->fd != -1)) { - close(fsp->fh->fd); + if ((fsp->fh != NULL) && (fsp_get_pathref_fd(fsp) != -1)) { + close(fsp_get_pathref_fd(fsp)); fsp_set_fd(fsp, -1); } return NULL; diff --git a/source3/modules/vfs_fruit.c b/source3/modules/vfs_fruit.c index 4da4c8b0ec6..902ce0e9b15 100644 --- a/source3/modules/vfs_fruit.c +++ b/source3/modules/vfs_fruit.c @@ -1669,7 +1669,7 @@ static int fruit_close_meta(vfs_handle_struct *handle, break; case FRUIT_META_NETATALK: - ret = close(fsp->fh->fd); + ret = close(fsp_get_pathref_fd(fsp)); fsp_set_fd(fsp, -1); break; @@ -1698,7 +1698,7 @@ static int fruit_close_rsrc(vfs_handle_struct *handle, break; case FRUIT_RSRC_XATTR: - ret = close(fsp->fh->fd); + ret = close(fsp_get_pathref_fd(fsp)); fsp_set_fd(fsp, -1); break; @@ -1716,7 +1716,7 @@ static int fruit_close(vfs_handle_struct *handle, int ret; int fd; - fd = fsp->fh->fd; + fd = fsp_get_pathref_fd(fsp); DBG_DEBUG("Path [%s] fd [%d]\n", smb_fname_str_dbg(fsp->fsp_name), fd); diff --git a/source3/modules/vfs_streams_xattr.c b/source3/modules/vfs_streams_xattr.c index f564efcb6e7..70e26f5f929 100644 --- a/source3/modules/vfs_streams_xattr.c +++ b/source3/modules/vfs_streams_xattr.c @@ -505,7 +505,7 @@ static int streams_xattr_close(vfs_handle_struct *handle, int ret; int fd; - fd = fsp->fh->fd; + fd = fsp_get_pathref_fd(fsp); DBG_DEBUG("streams_xattr_close called [%s] fd [%d]\n", smb_fname_str_dbg(fsp->fsp_name), fd); diff --git a/source3/smbd/open.c b/source3/smbd/open.c index e79877cc9c9..11f3112ad85 100644 --- a/source3/smbd/open.c +++ b/source3/smbd/open.c @@ -847,7 +847,7 @@ NTSTATUS fd_close(files_struct *fsp) if (fsp->dptr) { dptr_CloseDir(fsp); } - if (fsp->fh->fd == -1) { + if (fsp_get_pathref_fd(fsp) == -1) { /* * Either a directory where the dptr_CloseDir() already closed * the fd or a stat open.