From 9c2ba9436d1abe66c493a512702101f631946cdf Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 14 Apr 2011 12:49:58 -0700 Subject: Optimization for change_file_owner_to_parent() and change_dir_owner_to_parent() Don't do the chown if the owner is already correct. --- source3/smbd/open.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/source3/smbd/open.c b/source3/smbd/open.c index 66b14ff076..04353a1d56 100644 --- a/source3/smbd/open.c +++ b/source3/smbd/open.c @@ -214,6 +214,17 @@ void change_file_owner_to_parent(connection_struct *conn, "directory %s. Error was %s\n", smb_fname_str_dbg(smb_fname_parent), strerror(errno))); + TALLOC_FREE(smb_fname_parent); + return; + } + + if (smb_fname_parent->st.st_ex_uid == fsp->fsp_name->st.st_ex_uid) { + /* Already this uid - no need to change. */ + DEBUG(10,("change_file_owner_to_parent: file %s " + "is already owned by uid %d\n", + fsp_str_dbg(fsp), + (int)fsp->fsp_name->st.st_ex_uid )); + TALLOC_FREE(smb_fname_parent); return; } @@ -314,6 +325,16 @@ NTSTATUS change_dir_owner_to_parent(connection_struct *conn, goto chdir; } + if (smb_fname_parent->st.st_ex_uid == smb_fname_cwd->st.st_ex_uid) { + /* Already this uid - no need to change. */ + DEBUG(10,("change_dir_owner_to_parent: directory %s " + "is already owned by uid %d\n", + fname, + (int)smb_fname_cwd->st.st_ex_uid )); + status = NT_STATUS_OK; + goto chdir; + } + become_root(); ret = SMB_VFS_CHOWN(conn, ".", smb_fname_parent->st.st_ex_uid, (gid_t)-1); -- cgit