]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
vfs: Simplify acl_common_remove_object()
authorVolker Lendecke <vl@samba.org>
Mon, 30 Dec 2024 19:28:39 +0000 (20:28 +0100)
committerJeremy Allison <jra@samba.org>
Thu, 23 Jan 2025 23:08:38 +0000 (23:08 +0000)
These days we have "dirfsp" available inside the unlinkat vfs
functions. There's no need to mess with the cwd.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/modules/vfs_acl_common.c

index f098b7f1e79277b1284236fd734d3282c816615d..5686c15c777100b86e194329c7aaeb7f65048aee 100644 (file)
@@ -1000,58 +1000,26 @@ static int acl_common_remove_object(vfs_handle_struct *handle,
                                        bool is_directory)
 {
        connection_struct *conn = handle->conn;
+       struct stat_ex st;
        struct file_id id;
        files_struct *fsp = NULL;
        int ret = 0;
-       struct smb_filename *full_fname = NULL;
-       struct smb_filename *local_fname = NULL;
-       struct smb_filename *parent_dir_fname = NULL;
-       int saved_errno = 0;
-       struct smb_filename *saved_dir_fname = NULL;
-       NTSTATUS status;
 
-       saved_dir_fname = vfs_GetWd(talloc_tos(),conn);
-       if (saved_dir_fname == NULL) {
-               saved_errno = errno;
-               goto out;
-       }
+       SMB_ASSERT(strchr_m(smb_fname->base_name, '/') == NULL);
 
-       full_fname = full_path_from_dirfsp_atname(talloc_tos(),
-                                                 dirfsp,
-                                                 smb_fname);
-       if (full_fname == NULL) {
-               goto out;
-       }
-
-       status = SMB_VFS_PARENT_PATHNAME(conn,
-                                        talloc_tos(),
-                                        full_fname,
-                                        &parent_dir_fname,
-                                        &local_fname);
-       if (!NT_STATUS_IS_OK(status)) {
-               saved_errno = map_errno_from_nt_status(status);
-               goto out;
-       }
-
-       DBG_DEBUG("removing %s %s\n", is_directory ? "directory" : "file",
-                 smb_fname_str_dbg(full_fname));
-
-       /* cd into the parent dir to pin it. */
-       ret = vfs_ChDir(conn, parent_dir_fname);
+       ret = SMB_VFS_FSTATAT(
+               conn, dirfsp, smb_fname, &st, AT_SYMLINK_NOFOLLOW);
        if (ret == -1) {
-               saved_errno = errno;
-               goto out;
+               return ret;
        }
 
-       /* Must use lstat here. */
-       ret = SMB_VFS_LSTAT(conn, local_fname);
-       if (ret == -1) {
-               saved_errno = errno;
-               goto out;
-       }
+       DBG_DEBUG("removing %s %s/%s\n",
+                 is_directory ? "directory" : "file",
+                 fsp_str_dbg(dirfsp),
+                 smb_fname_str_dbg(smb_fname));
 
        /* Ensure we have this file open with DELETE access. */
-       id = vfs_file_id_from_sbuf(conn, &local_fname->st);
+       id = vfs_file_id_from_sbuf(conn, &st);
        for (fsp = file_find_di_first(conn->sconn, id, true); fsp;
                     fsp = file_find_di_next(fsp, true)) {
                if (fsp->access_mask & DELETE_ACCESS &&
@@ -1065,11 +1033,11 @@ static int acl_common_remove_object(vfs_handle_struct *handle,
        }
 
        if (!fsp) {
-               DBG_DEBUG("%s %s not an open file\n",
+               DBG_DEBUG("%s %s/%s not an open file\n",
                          is_directory ? "directory" : "file",
-                         smb_fname_str_dbg(full_fname));
-               saved_errno = EACCES;
-               goto out;
+                         fsp_str_dbg(dirfsp),
+                         smb_fname_str_dbg(smb_fname));
+               return EACCES;
        }
 
        become_root();
@@ -1086,22 +1054,6 @@ static int acl_common_remove_object(vfs_handle_struct *handle,
        }
        unbecome_root();
 
-       if (ret == -1) {
-               saved_errno = errno;
-       }
-
-  out:
-
-       TALLOC_FREE(parent_dir_fname);
-       TALLOC_FREE(full_fname);
-
-       if (saved_dir_fname) {
-               vfs_ChDir(conn, saved_dir_fname);
-               TALLOC_FREE(saved_dir_fname);
-       }
-       if (saved_errno) {
-               errno = saved_errno;
-       }
        return ret;
 }