From: Ralph Boehme Date: Mon, 2 May 2022 14:29:49 +0000 (+0200) Subject: smbd: optimize and streamline smbd_smb2_close() X-Git-Tag: talloc-2.3.4~295 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1808e5c133474eabc9d3cf91c2a92ec4d92d9fdd;p=thirdparty%2Fsamba.git smbd: optimize and streamline smbd_smb2_close() Signed-off-by: Ralph Boehme Reviewed-by: Jeremy Allison --- diff --git a/source3/smbd/smb2_close.c b/source3/smbd/smb2_close.c index b842c721eff..cb494a3a4d9 100644 --- a/source3/smbd/smb2_close.c +++ b/source3/smbd/smb2_close.c @@ -159,24 +159,9 @@ static void setup_close_full_information(connection_struct *conn, struct timespec *out_change_ts, uint16_t *out_flags, uint64_t *out_allocation_size, - uint64_t *out_end_of_file, - uint32_t *out_file_attributes) + uint64_t *out_end_of_file) { - NTSTATUS status; - - status = openat_pathref_fsp(conn->cwd_fsp, smb_fname); - if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND) && - (smb_fname->flags & SMB_FILENAME_POSIX_PATH) && - S_ISLNK(smb_fname->st.st_ex_mode)) - { - status = NT_STATUS_OK; - } - if (!NT_STATUS_IS_OK(status)) { - return; - } - *out_flags = SMB2_CLOSE_FLAGS_FULL_INFORMATION; - *out_file_attributes = fdos_mode(smb_fname->fsp); *out_last_write_ts = smb_fname->st.st_ex_mtime; *out_last_access_ts = smb_fname->st.st_ex_atime; *out_creation_ts = get_create_timespec(conn, NULL, smb_fname); @@ -188,7 +173,7 @@ static void setup_close_full_information(connection_struct *conn, dos_filetime_timespec(out_last_access_ts); dos_filetime_timespec(out_change_ts); } - if (!(*out_file_attributes & FILE_ATTRIBUTE_DIRECTORY)) { + if (!S_ISDIR(smb_fname->st.st_ex_mode)) { *out_end_of_file = get_file_size_stat(&smb_fname->st); } @@ -212,10 +197,6 @@ static NTSTATUS smbd_smb2_close(struct smbd_smb2_request *req, connection_struct *conn = req->tcon->compat; struct files_struct *fsp = *_fsp; struct smb_filename *smb_fname = NULL; - uint64_t allocation_size = 0; - uint64_t file_size = 0; - uint32_t dos_attrs = 0; - uint16_t flags = 0; *out_creation_ts = (struct timespec){0, SAMBA_UTIME_OMIT}; *out_last_access_ts = (struct timespec){0, SAMBA_UTIME_OMIT}; @@ -235,33 +216,12 @@ static NTSTATUS smbd_smb2_close(struct smbd_smb2_request *req, return NT_STATUS_NO_MEMORY; } - smb_fname = cp_smb_filename(talloc_tos(), fsp->fsp_name); - if (smb_fname == NULL) { - return NT_STATUS_NO_MEMORY; - } - - if ((in_flags & SMB2_CLOSE_FLAGS_FULL_INFORMATION) && - (fsp->fsp_flags.initial_delete_on_close || - fsp->fsp_flags.delete_on_close)) - { - /* - * We might be deleting the file. Ensure we - * return valid data from before the file got - * removed. - */ - setup_close_full_information(conn, - smb_fname, - out_creation_ts, - out_last_access_ts, - out_last_write_ts, - out_change_ts, - &flags, - &allocation_size, - &file_size, - &dos_attrs); + if (in_flags & SMB2_CLOSE_FLAGS_FULL_INFORMATION) { + *out_file_attributes = fdos_mode(fsp); + fsp->fsp_flags.fstat_before_close = true; } - status = close_file_free(smbreq, &fsp, NORMAL_CLOSE); + status = close_file_smb(smbreq, fsp, NORMAL_CLOSE); if (!NT_STATUS_IS_OK(status)) { DEBUG(5,("smbd_smb2_close: close_file[%s]: %s\n", smb_fname_str_dbg(smb_fname), nt_errstr(status))); @@ -270,22 +230,18 @@ static NTSTATUS smbd_smb2_close(struct smbd_smb2_request *req, if (in_flags & SMB2_CLOSE_FLAGS_FULL_INFORMATION) { setup_close_full_information(conn, - smb_fname, + fsp->fsp_name, out_creation_ts, out_last_access_ts, out_last_write_ts, out_change_ts, - &flags, - &allocation_size, - &file_size, - &dos_attrs); + out_flags, + out_allocation_size, + out_end_of_file); } - *out_flags = flags; - *out_allocation_size = allocation_size; - *out_end_of_file = file_size; - *out_file_attributes = dos_attrs; - + file_free(smbreq, fsp); + *_fsp = fsp = NULL; return NT_STATUS_OK; }