]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: Simplify create_file_unixpath()
authorVolker Lendecke <vl@samba.org>
Wed, 24 Jun 2026 15:42:40 +0000 (17:42 +0200)
committerAnoop C S <anoopcs@samba.org>
Fri, 26 Jun 2026 10:41:34 +0000 (10:41 +0000)
We don't need to call vfs_stat() before openat_pathref_fsp() to check
whether a file exists. openat_pathref_fsp() is well doing that on its
own.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Anoop C S <anoopcs@samba.org>
source3/smbd/open.c

index bcd1aef0b2307cf4dbc131f5aea126217f6ed350..1a90d6e633bdce7cee37669d3a8d492c9bf3f476 100644 (file)
@@ -6253,7 +6253,6 @@ static NTSTATUS create_file_unixpath(connection_struct *conn,
        files_struct *fsp = NULL;
        bool free_fsp_on_error = false;
        NTSTATUS status;
-       int ret;
        struct smb_filename *parent_dir_fname = NULL;
        struct smb_filename *smb_fname_atname = NULL;
 
@@ -6437,23 +6436,19 @@ static NTSTATUS create_file_unixpath(connection_struct *conn,
                 * if the basefile exists we want a handle so we can fstat() it.
                 */
 
-               ret = vfs_stat(conn, smb_fname_base);
-               if (ret == -1 && errno != ENOENT) {
-                       status = map_nt_error_from_unix(errno);
+               status = openat_pathref_fsp(conn->cwd_fsp, smb_fname_base);
+
+               if (!NT_STATUS_IS_OK(status) &&
+                   !NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND))
+               {
+                       DBG_ERR("openat_pathref_fsp [%s] failed: %s\n",
+                               smb_fname_str_dbg(smb_fname_base),
+                               nt_errstr(status));
                        TALLOC_FREE(smb_fname_base);
                        goto fail;
                }
-               if (ret == 0) {
-                       status = openat_pathref_fsp(conn->cwd_fsp,
-                                                   smb_fname_base);
-                       if (!NT_STATUS_IS_OK(status)) {
-                               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 (NT_STATUS_IS_OK(status)) {
                        /*
                         * https://bugzilla.samba.org/show_bug.cgi?id=10229
                         * We need to check if the requested access mask