From: Jeremy Allison Date: Mon, 7 Jun 2021 20:10:30 +0000 (-0700) Subject: s3: smbd: Make open_file() fail early for an existing directory we are trying to... X-Git-Tag: tevent-0.11.0~642 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f1ca59b81b20b17827c1ce5425f7da0e45a002af;p=thirdparty%2Fsamba.git s3: smbd: Make open_file() fail early for an existing directory we are trying to open. Makes sure we keep the pathref fd open for the NT_FILE_IS_A_DIRECTORY case. Signed-off-by: Jeremy Allison Signed-off-by: Noel Power Reviewed-by: Ralph Boehme --- diff --git a/source3/smbd/open.c b/source3/smbd/open.c index ab89ee78884..ed180efa1e3 100644 --- a/source3/smbd/open.c +++ b/source3/smbd/open.c @@ -1310,6 +1310,14 @@ static NTSTATUS open_file(files_struct *fsp, bool truncating = (flags & O_TRUNC); bool open_fd = false; + /* + * Catch early an attempt to open an existing + * directory as a file. + */ + if (file_existed && S_ISDIR(fsp->fsp_name->st.st_ex_mode)) { + return NT_STATUS_FILE_IS_A_DIRECTORY; + } + /* Check permissions */ /*