From b14dd975c754be30d247591190bec5db3f305245 Mon Sep 17 00:00:00 2001 From: Ralph Boehme Date: Mon, 9 Sep 2019 07:57:34 +0200 Subject: s3: replace fsp_stat() with vfs_stat_fsp() Both functions do the same, they differ just in the type of the returned result. BUG: https://bugzilla.samba.org/show_bug.cgi?id=14121 Signed-off-by: Ralph Boehme Reviewed-by: Stefan Metzmacher (cherry picked from commit ab03394969f8a4c748aea7d0d8ed37f9ced6cc30) --- source3/modules/vfs_dirsort.c | 13 ++++++++----- source3/smbd/fileio.c | 17 ----------------- source3/smbd/proto.h | 1 - source3/smbd/reply.c | 23 +++++++++++++++-------- 4 files changed, 23 insertions(+), 31 deletions(-) diff --git a/source3/modules/vfs_dirsort.c b/source3/modules/vfs_dirsort.c index c23f6f0152d..c6b5ea41c93 100644 --- a/source3/modules/vfs_dirsort.c +++ b/source3/modules/vfs_dirsort.c @@ -44,19 +44,22 @@ static bool get_sorted_dir_mtime(vfs_handle_struct *handle, { int ret; struct timespec mtime; + NTSTATUS status; if (data->fsp) { - ret = fsp_stat(data->fsp); + status = vfs_stat_fsp(data->fsp); + if (!NT_STATUS_IS_OK(status)) { + return false; + } mtime = data->fsp->fsp_name->st.st_ex_mtime; } else { ret = SMB_VFS_STAT(handle->conn, data->smb_fname); + if (ret == -1) { + return false; + } mtime = data->smb_fname->st.st_ex_mtime; } - if (ret == -1) { - return false; - } - *ret_mtime = mtime; return true; diff --git a/source3/smbd/fileio.c b/source3/smbd/fileio.c index a00b368f92b..067ce5a9ad4 100644 --- a/source3/smbd/fileio.c +++ b/source3/smbd/fileio.c @@ -1068,20 +1068,3 @@ NTSTATUS sync_file(connection_struct *conn, files_struct *fsp, bool write_throug } return NT_STATUS_OK; } - -/************************************************************ - Perform a stat whether a valid fd or not. -************************************************************/ - -int fsp_stat(files_struct *fsp) -{ - if (fsp->fh->fd == -1) { - if (fsp->posix_flags & FSP_POSIX_FLAGS_OPEN) { - return SMB_VFS_LSTAT(fsp->conn, fsp->fsp_name); - } else { - return SMB_VFS_STAT(fsp->conn, fsp->fsp_name); - } - } else { - return SMB_VFS_FSTAT(fsp, &fsp->fsp_name->st); - } -} diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h index cd1ec9a1f9e..10ffaf6e480 100644 --- a/source3/smbd/proto.h +++ b/source3/smbd/proto.h @@ -342,7 +342,6 @@ void delete_write_cache(files_struct *fsp); void set_filelen_write_cache(files_struct *fsp, off_t file_size); ssize_t flush_write_cache(files_struct *fsp, enum flush_reason_enum reason); NTSTATUS sync_file(connection_struct *conn, files_struct *fsp, bool write_through); -int fsp_stat(files_struct *fsp); /* The following definitions come from smbd/filename.c */ diff --git a/source3/smbd/reply.c b/source3/smbd/reply.c index dec67a10cae..35d1ae772d5 100644 --- a/source3/smbd/reply.c +++ b/source3/smbd/reply.c @@ -3662,6 +3662,7 @@ void reply_readbraw(struct smb_request *req) files_struct *fsp; struct lock_struct lock; off_t size = 0; + NTSTATUS status; START_PROFILE(SMBreadbraw); @@ -3759,7 +3760,8 @@ void reply_readbraw(struct smb_request *req) return; } - if (fsp_stat(fsp) == 0) { + status = vfs_stat_fsp(fsp); + if (NT_STATUS_IS_OK(status)) { size = fsp->fsp_name->st.st_ex_size; } @@ -4090,6 +4092,7 @@ static void send_file_readX(connection_struct *conn, struct smb_request *req, ssize_t nread = -1; struct lock_struct lock; int saved_errno = 0; + NTSTATUS status; init_strict_lock_struct(fsp, (uint64_t)req->smbpid, (uint64_t)startpos, (uint64_t)smb_maxcnt, READ_LOCK, @@ -4114,8 +4117,9 @@ static void send_file_readX(connection_struct *conn, struct smb_request *req, uint8_t headerbuf[smb_size + 12 * 2 + 1 /* padding byte */]; DATA_BLOB header; - if(fsp_stat(fsp) == -1) { - reply_nterror(req, map_nt_error_from_unix(errno)); + status = vfs_stat_fsp(fsp); + if (!NT_STATUS_IS_OK(status)) { + reply_nterror(req, status); goto out; } @@ -5323,6 +5327,7 @@ void reply_lseek(struct smb_request *req) off_t res= -1; int mode,umode; files_struct *fsp; + NTSTATUS status; START_PROFILE(SMBlseek); @@ -5367,9 +5372,9 @@ void reply_lseek(struct smb_request *req) if(errno == EINVAL) { off_t current_pos = startpos; - if(fsp_stat(fsp) == -1) { - reply_nterror(req, - map_nt_error_from_unix(errno)); + status = vfs_stat_fsp(fsp); + if (!NT_STATUS_IS_OK(status)) { + reply_nterror(req, status); END_PROFILE(SMBlseek); return; } @@ -8739,6 +8744,7 @@ void reply_getattrE(struct smb_request *req) int mode; files_struct *fsp; struct timespec create_ts; + NTSTATUS status; START_PROFILE(SMBgetattrE); @@ -8757,8 +8763,9 @@ void reply_getattrE(struct smb_request *req) } /* Do an fstat on this file */ - if(fsp_stat(fsp)) { - reply_nterror(req, map_nt_error_from_unix(errno)); + status = vfs_stat_fsp(fsp); + if (!NT_STATUS_IS_OK(status)) { + reply_nterror(req, status); END_PROFILE(SMBgetattrE); return; } -- cgit v1.2.1