smbd: use fsp_get_pathref_fd() for *at related directory handles
authorRalph Boehme <slow@samba.org>
Sat, 17 Oct 2020 15:01:47 +0000 (17:01 +0200)
committerRalph Boehme <slow@samba.org>
Wed, 16 Dec 2020 09:08:30 +0000 (09:08 +0000)
Obviously correct to use fsp_get_pathref_fd() here.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/modules/vfs_ceph.c
source3/modules/vfs_default.c
source3/modules/vfs_fruit.c
source3/modules/vfs_glusterfs.c
source3/modules/vfs_streams_depot.c
source3/modules/vfs_streams_xattr.c
source3/modules/vfs_virusfilter.c
source3/smbd/vfs.c

index 661b4ca387d67ccf294fd8da75a7c7cdb49b6659..9133949c84ab175afa5ea9cc6e8f632f05106b65 100644 (file)
@@ -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);
index 5f86b6e780f7d50d111a3769ea520f3caf420d75..926ee51475c4dce20796b45b375104bc1d4c3ac7 100644 (file)
@@ -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;
index 902ce0e9b15abf3733b661c316ec797e60de54ae..dae9db5d423323e08ebcedbdebce78834eb6e128 100644 (file)
@@ -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,
index 27ee71ca6ec571ac3eba8919db7ef4aad50f44ae..1d636471812c1e3f6d2b18868fc03bd2ea1a7f05 100644 (file)
@@ -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) {
index bd2ad48656d332d8171c22ed11f1577f5279af45..da14a0d98a59c9fb40b3bd0076657f505292d8a3 100644 (file)
@@ -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(),
index 70e26f5f92964997b7d732fd8cf2d64e6c4d4088..1d3f3ca14a74f2c1b7216c6ca576c6efe7e9fd0c 100644 (file)
@@ -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);
index fed1723a782541feab3210fa977a66bfc38e4662..c952b9bddb226809006612c3eaf90b037dc0b1a6 100644 (file)
@@ -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);
index b4a265e346d71b62550b5be91e6d13553bfc5d15..cd7212d0e9be08cd854c1ddbd87bf1b196e90934 100644 (file)
@@ -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