From: Ralph Boehme Date: Fri, 15 May 2020 13:25:07 +0000 (+0200) Subject: smbd: move fstat from create_internal_dirfsp() to open_internal_dirfsp() X-Git-Tag: ldb-2.2.0~434 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9557489478900c074d51bcb99f8b4be9920a0bf7;p=thirdparty%2Fsamba.git smbd: move fstat from create_internal_dirfsp() to open_internal_dirfsp() The original idea of doing the fstat in create_internal_dirfsp() was to return from the function with a valid file_id and that requires valid stat info. However, as dirfsp->fh->fd will still be -1 at this point vfs_stat_fsp() will fallback to path-based stat() which must be avoided. Signed-off-by: Ralph Boehme Reviewed-by: Jeremy Allison --- diff --git a/source3/smbd/files.c b/source3/smbd/files.c index bc064fce8c7..a1aa7e1183e 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -194,21 +194,6 @@ NTSTATUS create_internal_dirfsp(connection_struct *conn, return status; } - if (!VALID_STAT(fsp->fsp_name->st)) { - status = vfs_stat_fsp(fsp); - if (!NT_STATUS_IS_OK(status)) { - return status; - } - } - - if (!S_ISDIR(fsp->fsp_name->st.st_ex_mode)) { - DBG_ERR("%s is not a directory!\n", - smb_fname_str_dbg(smb_dname)); - file_free(NULL, fsp); - return NT_STATUS_NOT_A_DIRECTORY; - } - - fsp->file_id = vfs_file_id_from_sbuf(conn, &fsp->fsp_name->st); fsp->access_mask = FILE_LIST_DIRECTORY; fsp->fsp_flags.is_directory = true; @@ -226,6 +211,7 @@ NTSTATUS open_internal_dirfsp(connection_struct *conn, { struct files_struct *fsp = NULL; NTSTATUS status; + int ret; status = create_internal_dirfsp(conn, smb_dname, &fsp); if (!NT_STATUS_IS_OK(status)) { @@ -244,6 +230,19 @@ NTSTATUS open_internal_dirfsp(connection_struct *conn, return status; } + ret = SMB_VFS_FSTAT(fsp, &fsp->fsp_name->st); + if (ret != 0) { + return map_nt_error_from_unix(errno); + } + + if (!S_ISDIR(fsp->fsp_name->st.st_ex_mode)) { + DBG_ERR("%s is not a directory!\n", + smb_fname_str_dbg(smb_dname)); + file_free(NULL, fsp); + return NT_STATUS_NOT_A_DIRECTORY; + } + + fsp->file_id = vfs_file_id_from_sbuf(conn, &fsp->fsp_name->st); *_fsp = fsp; return NT_STATUS_OK;