Do this by fd if possible.
****************************************************************************/
-static void change_file_owner_to_parent(connection_struct *conn,
- struct smb_filename *smb_fname_parent,
- files_struct *fsp)
+static void change_file_owner_to_parent_fsp(struct files_struct *parent_fsp,
+ struct files_struct *fsp)
{
int ret;
- ret = SMB_VFS_STAT(conn, smb_fname_parent);
+ ret = SMB_VFS_FSTAT(parent_fsp, &parent_fsp->fsp_name->st);
if (ret == -1) {
- DEBUG(0,("change_file_owner_to_parent: failed to stat parent "
- "directory %s. Error was %s\n",
- smb_fname_str_dbg(smb_fname_parent),
- strerror(errno)));
- return;
+ DBG_ERR("failed to stat parent "
+ "directory %s. Error was %s\n",
+ fsp_str_dbg(parent_fsp),
+ strerror(errno));
+ return;
}
- if (smb_fname_parent->st.st_ex_uid == fsp->fsp_name->st.st_ex_uid) {
+ if (parent_fsp->fsp_name->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",
+ DBG_DEBUG("file %s is already owned by uid %u\n",
fsp_str_dbg(fsp),
- (int)fsp->fsp_name->st.st_ex_uid ));
- return;
+ (unsigned int)fsp->fsp_name->st.st_ex_uid);
+ return;
}
become_root();
- ret = SMB_VFS_FCHOWN(fsp, smb_fname_parent->st.st_ex_uid, (gid_t)-1);
+ ret = SMB_VFS_FCHOWN(fsp,
+ parent_fsp->fsp_name->st.st_ex_uid,
+ (gid_t)-1);
unbecome_root();
if (ret == -1) {
- DEBUG(0,("change_file_owner_to_parent: failed to fchown "
- "file %s to parent directory uid %u. Error "
- "was %s\n", fsp_str_dbg(fsp),
- (unsigned int)smb_fname_parent->st.st_ex_uid,
- strerror(errno) ));
+ DBG_ERR("failed to fchown "
+ "file %s to parent directory uid %u. Error "
+ "was %s\n",
+ fsp_str_dbg(fsp),
+ (unsigned int)parent_fsp->fsp_name->st.st_ex_uid,
+ strerror(errno));
} else {
- DEBUG(10,("change_file_owner_to_parent: changed new file %s to "
- "parent directory uid %u.\n", fsp_str_dbg(fsp),
- (unsigned int)smb_fname_parent->st.st_ex_uid));
+ DBG_DEBUG("changed new file %s to "
+ "parent directory uid %u.\n",
+ fsp_str_dbg(fsp),
+ (unsigned int)parent_fsp->fsp_name->st.st_ex_uid);
/* Ensure the uid entry is updated. */
- fsp->fsp_name->st.st_ex_uid = smb_fname_parent->st.st_ex_uid;
+ fsp->fsp_name->st.st_ex_uid =
+ parent_fsp->fsp_name->st.st_ex_uid;
}
}
/* Change the owner if required. */
if (lp_inherit_owner(SNUM(conn)) != INHERIT_OWNER_NO) {
- change_file_owner_to_parent(conn,
- parent_dir,
+ change_file_owner_to_parent_fsp(parent_dir->fsp,
fsp);
need_re_stat = true;
}