From: Volker Lendecke Date: Tue, 18 Jan 2022 20:14:13 +0000 (+0100) Subject: smbd: Pass "dirfsp" and "smb_fname" to fd_open_atomic() X-Git-Tag: tevent-0.12.0~762 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c2ac6a9cd7b1eceb3affc1319c52d79f751a6f45;p=thirdparty%2Fsamba.git smbd: Pass "dirfsp" and "smb_fname" to fd_open_atomic() Dereference fsp once instead of four times Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- diff --git a/source3/smbd/open.c b/source3/smbd/open.c index 6acc38c80f6..48d1faf2c6c 100644 --- a/source3/smbd/open.c +++ b/source3/smbd/open.c @@ -1057,7 +1057,9 @@ static NTSTATUS change_dir_owner_to_parent_fsp(struct files_struct *parent_fsp, file was created or not. ****************************************************************************/ -static NTSTATUS fd_open_atomic(files_struct *fsp, +static NTSTATUS fd_open_atomic(struct files_struct *dirfsp, + struct smb_filename *smb_fname, + files_struct *fsp, int flags, mode_t mode, bool *file_created) @@ -1071,7 +1073,7 @@ static NTSTATUS fd_open_atomic(files_struct *fsp, /* * We're not creating the file, just pass through. */ - status = fd_openat(fsp->conn->cwd_fsp, fsp->fsp_name, fsp, flags, mode); + status = fd_openat(dirfsp, smb_fname, fsp, flags, mode); *file_created = false; return status; } @@ -1080,7 +1082,7 @@ static NTSTATUS fd_open_atomic(files_struct *fsp, /* * Fail if already exists, just pass through. */ - status = fd_openat(fsp->conn->cwd_fsp, fsp->fsp_name, fsp, flags, mode); + status = fd_openat(dirfsp, smb_fname, fsp, flags, mode); /* * Here we've opened with O_CREAT|O_EXCL. If that went @@ -1120,7 +1122,7 @@ static NTSTATUS fd_open_atomic(files_struct *fsp, retry_status = NT_STATUS_OBJECT_NAME_COLLISION; } - status = fd_openat(fsp->conn->cwd_fsp, fsp->fsp_name, fsp, curr_flags, mode); + status = fd_openat(dirfsp, smb_fname, fsp, curr_flags, mode); if (NT_STATUS_IS_OK(status)) { *file_created = !file_existed; return NT_STATUS_OK; @@ -1139,7 +1141,7 @@ static NTSTATUS fd_open_atomic(files_struct *fsp, curr_flags = flags | O_EXCL; } - status = fd_openat(fsp->conn->cwd_fsp, fsp->fsp_name, fsp, curr_flags, mode); + status = fd_openat(dirfsp, smb_fname, fsp, curr_flags, mode); } *file_created = (NT_STATUS_IS_OK(status) && !file_existed); @@ -1242,10 +1244,13 @@ static NTSTATUS reopen_from_fsp(struct files_struct *fsp, fsp->fsp_flags.is_pathref = false; - status = fd_open_atomic(fsp, - flags, - mode, - p_file_created); + status = fd_open_atomic( + fsp->conn->cwd_fsp, + fsp->fsp_name, + fsp, + flags, + mode, + p_file_created); return status; }