Skip to content

Commit

Permalink
nfs4_acls: Call chown_if_needed function to remove duplicate code
Browse files Browse the repository at this point in the history
Signed-off-by: Christof Schmitt <[email protected]>
Reviewed-by: Volker Lendecke <[email protected]>
  • Loading branch information
chs authored and vlendec committed Dec 2, 2022
1 parent eeb8a66 commit bfb4b36
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 42 deletions.
43 changes: 2 additions & 41 deletions source3/modules/nfs4_acls.c
Original file line number Diff line number Diff line change
Expand Up @@ -978,8 +978,6 @@ NTSTATUS smb_set_nt_acl_nfs4(vfs_handle_struct *handle, files_struct *fsp,
bool result, is_directory;

bool set_acl_as_root = false;
uid_t newUID = (uid_t)-1;
gid_t newGID = (gid_t)-1;
int saved_errno;
NTSTATUS status;
TALLOC_CTX *frame = talloc_stackframe();
Expand Down Expand Up @@ -1019,49 +1017,12 @@ NTSTATUS smb_set_nt_acl_nfs4(vfs_handle_struct *handle, files_struct *fsp,
is_directory = S_ISDIR(fsp->fsp_name->st.st_ex_mode);

if (pparams->do_chown) {
/* chown logic is a copy/paste from posix_acl.c:set_nt_acl */

uid_t old_uid = fsp->fsp_name->st.st_ex_uid;
gid_t old_gid = fsp->fsp_name->st.st_ex_gid;
status = unpack_nt_owners(fsp->conn, &newUID, &newGID,
security_info_sent, psd);
status = chown_if_needed(fsp, security_info_sent, psd,
&set_acl_as_root);
if (!NT_STATUS_IS_OK(status)) {
DEBUG(8, ("unpack_nt_owners failed"));
TALLOC_FREE(frame);
return status;
}
if (((newUID != (uid_t)-1) && (old_uid != newUID)) ||
((newGID != (gid_t)-1) && (old_gid != newGID)))
{
status = try_chown(fsp, newUID, newGID);
if (!NT_STATUS_IS_OK(status)) {
DEBUG(3,("chown %s, %u, %u failed. Error = "
"%s.\n", fsp_str_dbg(fsp),
(unsigned int)newUID,
(unsigned int)newGID,
nt_errstr(status)));
TALLOC_FREE(frame);
return status;
}

DEBUG(10,("chown %s, %u, %u succeeded.\n",
fsp_str_dbg(fsp), (unsigned int)newUID,
(unsigned int)newGID));

/*
* Owner change, need to update stat info.
*/
status = vfs_stat_fsp(fsp);
if (!NT_STATUS_IS_OK(status)) {
TALLOC_FREE(frame);
return status;
}

/* If we successfully chowned, we know we must
* be able to set the acl, so do it as root.
*/
set_acl_as_root = true;
}
}

if (!(security_info_sent & SECINFO_DACL) || psd->dacl ==NULL) {
Expand Down
2 changes: 1 addition & 1 deletion source3/smbd/posix_acls.c
Original file line number Diff line number Diff line change
Expand Up @@ -3618,7 +3618,7 @@ NTSTATUS set_nt_acl(files_struct *fsp, uint32_t security_info_sent, const struct
* If we successfully chowned, we know we must be able to set
* the acl, so do it as root (set_acl_as_root).
*/
status = check_chown(fsp, security_info_sent, psd, &set_acl_as_root);
status = chown_if_needed(fsp, security_info_sent, psd, &set_acl_as_root);
if (!NT_STATUS_IS_OK(status)) {
return status;
}
Expand Down

0 comments on commit bfb4b36

Please sign in to comment.