s3: smbd: Remove vfs_chown_fsp().
authorJeremy Allison <jra@samba.org>
Tue, 8 Oct 2019 20:46:02 +0000 (13:46 -0700)
committerJeremy Allison <jra@samba.org>
Tue, 15 Oct 2019 18:46:37 +0000 (18:46 +0000)
No longer used. This gets rid of another case
where we were playing directory changing games
that are eliminated by just using a file handle.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Ralph Böhme <slow@samba.org>
source3/smbd/proto.h
source3/smbd/vfs.c

index e9d04474df656795db383f6e1e94838c0f1bdb6e..dd6993a60f0992881278a000b04405b9c5ac44b6 100644 (file)
@@ -1247,7 +1247,6 @@ int vfs_stat_smb_basename(struct connection_struct *conn,
                        const struct smb_filename *smb_fname_in,
                        SMB_STRUCT_STAT *psbuf);
 NTSTATUS vfs_stat_fsp(files_struct *fsp);
-NTSTATUS vfs_chown_fsp(files_struct *fsp, uid_t uid, gid_t gid);
 NTSTATUS vfs_streaminfo(connection_struct *conn,
                        struct files_struct *fsp,
                        const struct smb_filename *smb_fname,
index 34923b62ab42982c0f99bc0e8f8da92aea89c989..588580314e82ff860bca498e4d59909eabaeb127 100644 (file)
@@ -2050,127 +2050,6 @@ int smb_vfs_call_lchown(struct vfs_handle_struct *handle,
        return handle->fns->lchown_fn(handle, smb_fname, uid, gid);
 }
 
-NTSTATUS vfs_chown_fsp(files_struct *fsp, uid_t uid, gid_t gid)
-{
-       int ret;
-       bool as_root = false;
-       NTSTATUS status;
-
-       if (fsp->fh->fd != -1) {
-               /* Try fchown. */
-               ret = SMB_VFS_FCHOWN(fsp, uid, gid);
-               if (ret == 0) {
-                       return NT_STATUS_OK;
-               }
-               if (ret == -1 && errno != ENOSYS) {
-                       return map_nt_error_from_unix(errno);
-               }
-       }
-
-       as_root = (geteuid() == 0);
-
-       if (as_root) {
-               /*
-                * We are being asked to chown as root. Make
-                * sure we chdir() into the path to pin it,
-                * and always act using lchown to ensure we
-                * don't deref any symbolic links.
-                */
-               char *parent_dir = NULL;
-               const char *final_component = NULL;
-               struct smb_filename *local_smb_fname = NULL;
-               struct smb_filename parent_dir_fname = {0};
-               struct smb_filename *saved_dir_fname = NULL;
-
-               saved_dir_fname = vfs_GetWd(talloc_tos(),fsp->conn);
-               if (!saved_dir_fname) {
-                       status = map_nt_error_from_unix(errno);
-                       DEBUG(0,("vfs_chown_fsp: failed to get "
-                               "current working directory. Error was %s\n",
-                               strerror(errno)));
-                       return status;
-               }
-
-               if (!parent_dirname(talloc_tos(),
-                               fsp->fsp_name->base_name,
-                               &parent_dir,
-                               &final_component)) {
-                       return NT_STATUS_NO_MEMORY;
-               }
-
-               parent_dir_fname = (struct smb_filename) {
-                       .base_name = parent_dir,
-                       .flags = fsp->fsp_name->flags
-               };
-
-               /* cd into the parent dir to pin it. */
-               ret = vfs_ChDir(fsp->conn, &parent_dir_fname);
-               if (ret == -1) {
-                       return map_nt_error_from_unix(errno);
-               }
-
-               local_smb_fname = synthetic_smb_fname(talloc_tos(),
-                                       final_component,
-                                       NULL,
-                                       NULL,
-                                       fsp->fsp_name->flags);
-               if (local_smb_fname == NULL) {
-                       status = NT_STATUS_NO_MEMORY;
-                       goto out;
-               }
-
-               /* Must use lstat here. */
-               ret = SMB_VFS_LSTAT(fsp->conn, local_smb_fname);
-               if (ret == -1) {
-                       status = map_nt_error_from_unix(errno);
-                       goto out;
-               }
-
-               /* Ensure it matches the fsp stat. */
-               if (!check_same_stat(&local_smb_fname->st,
-                               &fsp->fsp_name->st)) {
-                        status = NT_STATUS_ACCESS_DENIED;
-                       goto out;
-                }
-
-               ret = SMB_VFS_LCHOWN(fsp->conn,
-                       local_smb_fname,
-                       uid, gid);
-
-               if (ret == 0) {
-                       status = NT_STATUS_OK;
-               } else {
-                       status = map_nt_error_from_unix(errno);
-               }
-
-  out:
-
-               vfs_ChDir(fsp->conn, saved_dir_fname);
-               TALLOC_FREE(local_smb_fname);
-               TALLOC_FREE(saved_dir_fname);
-               TALLOC_FREE(parent_dir);
-
-               return status;
-       }
-
-       if (fsp->posix_flags & FSP_POSIX_FLAGS_OPEN) {
-               ret = SMB_VFS_LCHOWN(fsp->conn,
-                       fsp->fsp_name,
-                       uid, gid);
-       } else {
-               ret = SMB_VFS_CHOWN(fsp->conn,
-                       fsp->fsp_name,
-                       uid, gid);
-       }
-
-       if (ret == 0) {
-               status = NT_STATUS_OK;
-       } else {
-               status = map_nt_error_from_unix(errno);
-       }
-       return status;
-}
-
 int smb_vfs_call_chdir(struct vfs_handle_struct *handle,
                        const struct smb_filename *smb_fname)
 {