]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
open.c: prefer capabilities over become_root
authorBjörn Jacke <bj@sernet.de>
Fri, 17 Jun 2022 05:27:38 +0000 (07:27 +0200)
committerBjoern Jacke <bjacke@samba.org>
Thu, 16 Nov 2023 21:38:38 +0000 (21:38 +0000)
Signed-off-by: Bjoern Jacke <bjacke@samba.org>
Reviewed-by: Christof Schmitt <cs@samba.org>
source3/smbd/open.c

index cb1e2adbf1e3b03a5e54edf23d6909ec85662da8..30d0d3ab7285dfa15afd603c0d2ff6edc890aab3 100644 (file)
@@ -1054,11 +1054,11 @@ static void change_file_owner_to_parent_fsp(struct files_struct *parent_fsp,
                 return;
        }
 
-       become_root();
+       set_effective_capability(DAC_OVERRIDE_CAPABILITY);
        ret = SMB_VFS_FCHOWN(fsp,
                             parent_fsp->fsp_name->st.st_ex_uid,
                             (gid_t)-1);
-       unbecome_root();
+       drop_effective_capability(DAC_OVERRIDE_CAPABILITY);
        if (ret == -1) {
                DBG_ERR("failed to fchown "
                        "file %s to parent directory uid %u. Error "
@@ -1091,11 +1091,11 @@ static NTSTATUS change_dir_owner_to_parent_fsp(struct files_struct *parent_fsp,
                return NT_STATUS_OK;
        }
 
-       become_root();
+       set_effective_capability(DAC_OVERRIDE_CAPABILITY);
        ret = SMB_VFS_FCHOWN(fsp,
                             parent_fsp->fsp_name->st.st_ex_uid,
                             (gid_t)-1);
-       unbecome_root();
+       drop_effective_capability(DAC_OVERRIDE_CAPABILITY);
        if (ret == -1) {
                status = map_nt_error_from_unix(errno);
                DBG_ERR("failed to chown "
@@ -5558,13 +5558,13 @@ static NTSTATUS inherit_new_acl(files_struct *dirfsp, files_struct *fsp)
 
        if (inherit_owner) {
                /* We need to be root to force this. */
-               become_root();
+               set_effective_capability(DAC_OVERRIDE_CAPABILITY);
        }
        status = SMB_VFS_FSET_NT_ACL(metadata_fsp(fsp),
                        security_info_sent,
                        psd);
        if (inherit_owner) {
-               unbecome_root();
+               drop_effective_capability(DAC_OVERRIDE_CAPABILITY);
        }
        TALLOC_FREE(frame);
        return status;