]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: replace a stat() with an fstat() in create_file_unixpath()
authorRalph Boehme <slow@samba.org>
Mon, 23 Nov 2020 06:46:42 +0000 (07:46 +0100)
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/open.c

index 47ee513e0a4686ca6eca4185a973ee1d5ed08d94..eef2e2faea9dc7a425dfbabcfc357c621ee950e0 100644 (file)
@@ -5576,10 +5576,37 @@ static NTSTATUS create_file_unixpath(connection_struct *conn,
                        goto fail;
                }
 
-               if (SMB_VFS_STAT(conn, smb_fname_base) == -1) {
-                       DEBUG(10, ("Unable to stat stream: %s\n",
-                                  smb_fname_str_dbg(smb_fname_base)));
-               } else {
+               /*
+                * We may be creating the basefile as part of creating the
+                * stream, so it's legal if the basefile doesn't exist at this
+                * point, the create_file_unixpath() below will create it. But
+                * if the basefile exists we want a handle so we can fstat() it.
+                */
+               status = openat_pathref_fsp(conn->cwd_fsp, smb_fname_base);
+               if (NT_STATUS_EQUAL(status, NT_STATUS_STOPPED_ON_SYMLINK)) {
+                       status = NT_STATUS_OBJECT_NAME_NOT_FOUND;
+               }
+               if (!NT_STATUS_IS_OK(status) &&
+                   !NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND))
+               {
+                       DBG_ERR("open_smb_fname_fsp [%s] failed: %s\n",
+                               smb_fname_str_dbg(smb_fname_base),
+                               nt_errstr(status));
+                       TALLOC_FREE(smb_fname_base);
+                       goto fail;
+               }
+
+               if (smb_fname_base->fsp != NULL) {
+                       int ret;
+
+                       ret = SMB_VFS_FSTAT(smb_fname_base->fsp,
+                                           &smb_fname_base->st);
+                       if (ret != 0) {
+                               DBG_DEBUG("Unable to stat stream [%s]: %s\n",
+                                         smb_fname_str_dbg(smb_fname_base),
+                                         strerror(errno));
+                       }
+
                        /*
                         * https://bugzilla.samba.org/show_bug.cgi?id=10229
                         * We need to check if the requested access mask