From 9a5a1fe148cd82cd00d2ee913ec1ae90b9fb24e0 Mon Sep 17 00:00:00 2001 From: Ralph Boehme Date: Sat, 13 Jun 2020 19:16:39 +0200 Subject: [PATCH] smbd: use open_pathref_fsp() in filename_convert_internal() Signed-off-by: Ralph Boehme Reviewed-by: Jeremy Allison --- source3/smbd/filename.c | 45 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/source3/smbd/filename.c b/source3/smbd/filename.c index a89f3047bac..937fc3c0f63 100644 --- a/source3/smbd/filename.c +++ b/source3/smbd/filename.c @@ -1918,6 +1918,7 @@ static NTSTATUS filename_convert_internal(TALLOC_CTX *ctx, struct smb_filename **_smb_fname) { struct smb_filename *smb_fname = NULL; + bool has_wild; NTSTATUS status; *_smb_fname = NULL; @@ -1985,6 +1986,50 @@ static NTSTATUS filename_convert_internal(TALLOC_CTX *ctx, return status; } + has_wild = ms_has_wild(name_in); + if (has_wild) { + DBG_DEBUG("[%s] contains wildcard, skipping pathref fsp\n", + name_in); + *_smb_fname = smb_fname; + return NT_STATUS_OK; + } + + if (!VALID_STAT(smb_fname->st)) { + DBG_DEBUG("[%s] does not exist, skipping pathref fsp\n", + smb_fname_str_dbg(smb_fname)); + *_smb_fname = smb_fname; + return NT_STATUS_OK; + } + + status = openat_pathref_fsp(conn->cwd_fsp, smb_fname); + if (NT_STATUS_EQUAL(status, NT_STATUS_STOPPED_ON_SYMLINK)) { + /* + * Don't leak NT_STATUS_STOPPED_ON_SYMLINK into the callers: + * it's a special SMB2 error that needs an extended SMB2 error + * response. We don't support that for SMB2 and it doesn't exist + * at all in SMB1. + * + * So we deal with symlinks here as we do in + * SMB_VFS_CREATE_FILE(): return success for POSIX clients with + * the notable difference that there will be no fsp in + * smb_fname->fsp. + * + * For Windows (non POSIX) clients fail with + * NT_STATUS_OBJECT_NAME_NOT_FOUND. + */ + if (ucf_flags & UCF_POSIX_PATHNAMES) { + status = NT_STATUS_OK; + } else { + status = NT_STATUS_OBJECT_NAME_NOT_FOUND; + } + } + if (!NT_STATUS_IS_OK(status)) { + DBG_ERR("open_pathref_fsp [%s] failed: %s\n", + smb_fname_str_dbg(smb_fname), + nt_errstr(status)); + return status; + } + *_smb_fname = smb_fname; return status; } -- 2.47.3