]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: use open_pathref_fsp() in filename_convert_internal()
authorRalph Boehme <slow@samba.org>
Sat, 13 Jun 2020 17:16:39 +0000 (19:16 +0200)
committerRalph Boehme <slow@samba.org>
Wed, 16 Dec 2020 09:08:31 +0000 (09:08 +0000)
Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/smbd/filename.c

index a89f3047bac88b67db947f1db07ac272ea3d55a2..937fc3c0f6330464b04959268090828a2d6d8f63 100644 (file)
@@ -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;
 }