From bc908ea3f2eb2284b625bc257264235cad0a7951 Mon Sep 17 00:00:00 2001 From: Ralph Boehme Date: Sat, 17 Oct 2020 17:01:47 +0200 Subject: [PATCH] smbd: use fsp_get_pathref_fd() for *at related directory handles Obviously correct to use fsp_get_pathref_fd() here. Signed-off-by: Ralph Boehme Reviewed-by: Jeremy Allison --- source3/modules/vfs_ceph.c | 2 +- source3/modules/vfs_default.c | 29 ++++++++++++++++------------- source3/modules/vfs_fruit.c | 2 +- source3/modules/vfs_glusterfs.c | 2 +- source3/modules/vfs_streams_depot.c | 2 +- source3/modules/vfs_streams_xattr.c | 2 +- source3/modules/vfs_virusfilter.c | 2 +- source3/smbd/vfs.c | 2 +- 8 files changed, 23 insertions(+), 20 deletions(-) diff --git a/source3/modules/vfs_ceph.c b/source3/modules/vfs_ceph.c index 661b4ca387d..9133949c84a 100644 --- a/source3/modules/vfs_ceph.c +++ b/source3/modules/vfs_ceph.c @@ -412,7 +412,7 @@ static int cephwrap_openat(struct vfs_handle_struct *handle, /* * cephfs API doesn't have ceph_openat(), so for now assert this. */ - SMB_ASSERT(dirfsp->fh->fd == AT_FDCWD); + SMB_ASSERT(fsp_get_pathref_fd(dirfsp) == AT_FDCWD); DBG_DEBUG("[CEPH] openat(%p, %s, %p, %d, %d)\n", handle, smb_fname_str_dbg(smb_fname), fsp, flags, mode); diff --git a/source3/modules/vfs_default.c b/source3/modules/vfs_default.c index 5f86b6e780f..926ee51475c 100644 --- a/source3/modules/vfs_default.c +++ b/source3/modules/vfs_default.c @@ -667,7 +667,7 @@ static int vfswrap_mkdirat(vfs_handle_struct *handle, TALLOC_FREE(parent); - result = mkdirat(dirfsp->fh->fd, smb_fname->base_name, mode); + result = mkdirat(fsp_get_pathref_fd(dirfsp), smb_fname->base_name, mode); END_PROFILE(syscall_mkdirat); return result; @@ -702,7 +702,10 @@ static int vfswrap_openat(vfs_handle_struct *handle, goto out; } - result = openat(dirfsp->fh->fd, smb_fname->base_name, flags, mode); + result = openat(fsp_get_pathref_fd(dirfsp), + smb_fname->base_name, + flags, + mode); out: END_PROFILE(syscall_openat); @@ -1230,9 +1233,9 @@ static int vfswrap_renameat(vfs_handle_struct *handle, goto out; } - result = renameat(srcfsp->fh->fd, + result = renameat(fsp_get_pathref_fd(srcfsp), smb_fname_src->base_name, - dstfsp->fh->fd, + fsp_get_pathref_fd(dstfsp), smb_fname_dst->base_name); out: @@ -1264,7 +1267,7 @@ static int vfswrap_fstat(vfs_handle_struct *handle, files_struct *fsp, SMB_STRUC int result; START_PROFILE(syscall_fstat); - result = sys_fstat(fsp->fh->fd, + result = sys_fstat(fsp_get_pathref_fd(fsp), sbuf, lp_fake_directory_create_times(SNUM(handle->conn))); END_PROFILE(syscall_fstat); return result; @@ -2396,7 +2399,7 @@ static int vfswrap_unlinkat(vfs_handle_struct *handle, errno = ENOENT; goto out; } - result = unlinkat(dirfsp->fh->fd, + result = unlinkat(fsp_get_pathref_fd(dirfsp), smb_fname->base_name, flags); @@ -2874,7 +2877,7 @@ static int vfswrap_symlinkat(vfs_handle_struct *handle, START_PROFILE(syscall_symlinkat); result = symlinkat(link_target->base_name, - dirfsp->fh->fd, + fsp_get_pathref_fd(dirfsp), new_smb_fname->base_name); END_PROFILE(syscall_symlinkat); return result; @@ -2890,7 +2893,7 @@ static int vfswrap_readlinkat(vfs_handle_struct *handle, START_PROFILE(syscall_readlinkat); - result = readlinkat(dirfsp->fh->fd, + result = readlinkat(fsp_get_pathref_fd(dirfsp), smb_fname->base_name, buf, bufsiz); @@ -2910,9 +2913,9 @@ static int vfswrap_linkat(vfs_handle_struct *handle, START_PROFILE(syscall_linkat); - result = linkat(srcfsp->fh->fd, + result = linkat(fsp_get_pathref_fd(srcfsp), old_smb_fname->base_name, - dstfsp->fh->fd, + fsp_get_pathref_fd(dstfsp), new_smb_fname->base_name, flags); @@ -2930,7 +2933,7 @@ static int vfswrap_mknodat(vfs_handle_struct *handle, START_PROFILE(syscall_mknodat); - result = sys_mknodat(dirfsp->fh->fd, + result = sys_mknodat(fsp_get_pathref_fd(dirfsp), smb_fname->base_name, mode, dev); @@ -3304,7 +3307,7 @@ static struct tevent_req *vfswrap_getxattrat_send( SMBPROFILE_BYTES_ASYNC_START(syscall_asys_getxattrat, profile_p, state->profile_bytes, 0); - if (dir_fsp->fh->fd == -1) { + if (fsp_get_pathref_fd(dir_fsp) == -1) { DBG_ERR("Need a valid directory fd\n"); tevent_req_error(req, EINVAL); return tevent_req_post(req, ev); @@ -3442,7 +3445,7 @@ static void vfswrap_getxattrat_do_async(void *private_data) goto end_profile; } - ret = fchdir(state->dir_fsp->fh->fd); + ret = fchdir(fsp_get_pathref_fd(state->dir_fsp)); if (ret == -1) { state->xattr_size = -1; state->vfs_aio_state.error = errno; diff --git a/source3/modules/vfs_fruit.c b/source3/modules/vfs_fruit.c index 902ce0e9b15..dae9db5d423 100644 --- a/source3/modules/vfs_fruit.c +++ b/source3/modules/vfs_fruit.c @@ -1536,7 +1536,7 @@ static int fruit_open_rsrc_xattr(vfs_handle_struct *handle, /* * As there's no attropenat() this is only going to work with AT_FDCWD. */ - SMB_ASSERT(dirfsp->fh->fd == AT_FDCWD); + SMB_ASSERT(fsp_get_pathref_fd(dirfsp) == AT_FDCWD); fd = attropen(smb_fname->base_name, AFPRESOURCE_EA_NETATALK, diff --git a/source3/modules/vfs_glusterfs.c b/source3/modules/vfs_glusterfs.c index 27ee71ca6ec..1d636471812 100644 --- a/source3/modules/vfs_glusterfs.c +++ b/source3/modules/vfs_glusterfs.c @@ -737,7 +737,7 @@ static int vfs_gluster_openat(struct vfs_handle_struct *handle, /* * Looks like glfs API doesn't have openat(). */ - SMB_ASSERT(dirfsp->fh->fd == AT_FDCWD); + SMB_ASSERT(fsp_get_pathref_fd(dirfsp) == AT_FDCWD); p_tmp = VFS_ADD_FSP_EXTENSION(handle, fsp, glfs_fd_t *, NULL); if (p_tmp == NULL) { diff --git a/source3/modules/vfs_streams_depot.c b/source3/modules/vfs_streams_depot.c index bd2ad48656d..da14a0d98a5 100644 --- a/source3/modules/vfs_streams_depot.c +++ b/source3/modules/vfs_streams_depot.c @@ -639,7 +639,7 @@ static int streams_depot_openat(struct vfs_handle_struct *handle, /* * For now assert this so the below SMB_VFS_STAT() is ok. */ - SMB_ASSERT(dirfsp->fh->fd == AT_FDCWD); + SMB_ASSERT(fsp_get_pathref_fd(dirfsp) == AT_FDCWD); /* Ensure the base file still exists. */ smb_fname_base = synthetic_smb_fname(talloc_tos(), diff --git a/source3/modules/vfs_streams_xattr.c b/source3/modules/vfs_streams_xattr.c index 70e26f5f929..1d3f3ca14a7 100644 --- a/source3/modules/vfs_streams_xattr.c +++ b/source3/modules/vfs_streams_xattr.c @@ -393,7 +393,7 @@ static int streams_xattr_openat(struct vfs_handle_struct *handle, /* * For now assert this, so the below SMB_VFS_SETXATTR() works. */ - SMB_ASSERT(dirfsp->fh->fd == AT_FDCWD); + SMB_ASSERT(fsp_get_pathref_fd(dirfsp) == AT_FDCWD); status = streams_xattr_get_name(handle, talloc_tos(), smb_fname->stream_name, &xattr_name); diff --git a/source3/modules/vfs_virusfilter.c b/source3/modules/vfs_virusfilter.c index fed1723a782..c952b9bddb2 100644 --- a/source3/modules/vfs_virusfilter.c +++ b/source3/modules/vfs_virusfilter.c @@ -1171,7 +1171,7 @@ static int virusfilter_vfs_openat(struct vfs_handle_struct *handle, /* * For now assert this, so SMB_VFS_NEXT_STAT() below works. */ - SMB_ASSERT(dirfsp->fh->fd == AT_FDCWD); + SMB_ASSERT(fsp_get_pathref_fd(dirfsp) == AT_FDCWD); SMB_VFS_HANDLE_GET_DATA(handle, config, struct virusfilter_config, return -1); diff --git a/source3/smbd/vfs.c b/source3/smbd/vfs.c index b4a265e346d..cd7212d0e9b 100644 --- a/source3/smbd/vfs.c +++ b/source3/smbd/vfs.c @@ -895,7 +895,7 @@ int vfs_ChDir(connection_struct *conn, const struct smb_filename *smb_fname) * conn->cwd_fsp->fh->fd = AT_FDCWD * on success! */ - if (conn->cwd_fsp->fh->fd != AT_FDCWD) { + if (fsp_get_pathref_fd(conn->cwd_fsp) != AT_FDCWD) { /* * This should never happen and * we might change this to -- 2.34.1