]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: Only create an artificial dirfsp when necessary
authorVolker Lendecke <vl@samba.org>
Fri, 8 Apr 2022 11:10:15 +0000 (13:10 +0200)
committerRalph Boehme <slow@samba.org>
Thu, 28 Apr 2022 13:12:33 +0000 (13:12 +0000)
parent_pathref() is expensive, and we should avoid it if possible.

Not effective at this point, we always pass in NULL, but will be used
soon.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/smbd/open.c

index 6a5addfaae473e5c0f1af2a68679f9f1abad7500..bee6cab6d426b768cc17f1d18b9813c2ab80a08f 100644 (file)
@@ -5908,18 +5908,36 @@ static NTSTATUS create_file_unixpath(connection_struct *conn,
                fsp_set_base_fsp(fsp, base_fsp);
        }
 
-       /*
-        * Get a pathref on the parent. We can re-use this
-        * for multiple calls to check parent ACLs etc. to
-        * avoid pathname calls.
-        */
-       status = parent_pathref(talloc_tos(),
-                               conn->cwd_fsp,
-                               smb_fname,
-                               &parent_dir_fname,
-                               &smb_fname_atname);
-       if (!NT_STATUS_IS_OK(status)) {
-               goto fail;
+       if (dirfsp != NULL) {
+               status = SMB_VFS_PARENT_PATHNAME(
+                       conn,
+                       talloc_tos(),
+                       smb_fname,
+                       &parent_dir_fname,
+                       &smb_fname_atname);
+               if (!NT_STATUS_IS_OK(status)) {
+                       goto fail;
+               }
+       } else {
+               /*
+                * Get a pathref on the parent. We can re-use this for
+                * multiple calls to check parent ACLs etc. to avoid
+                * pathname calls.
+                */
+               status = parent_pathref(talloc_tos(),
+                                       conn->cwd_fsp,
+                                       smb_fname,
+                                       &parent_dir_fname,
+                                       &smb_fname_atname);
+               if (!NT_STATUS_IS_OK(status)) {
+                       goto fail;
+               }
+
+               dirfsp = parent_dir_fname->fsp;
+               status = fsp_set_smb_fname(dirfsp, parent_dir_fname);
+               if (!NT_STATUS_IS_OK(status)) {
+                       goto fail;
+               }
        }
 
        /*
@@ -5954,7 +5972,7 @@ static NTSTATUS create_file_unixpath(connection_struct *conn,
                                        create_disposition,
                                        create_options,
                                        file_attributes,
-                                       parent_dir_fname,
+                                       dirfsp->fsp_name,
                                        smb_fname_atname,
                                        &info,
                                        fsp);
@@ -5979,7 +5997,7 @@ static NTSTATUS create_file_unixpath(connection_struct *conn,
                                            oplock_request,
                                            lease,
                                            private_flags,
-                                           parent_dir_fname,
+                                           dirfsp->fsp_name,
                                            smb_fname_atname,
                                            &info,
                                            fsp);
@@ -6010,7 +6028,7 @@ static NTSTATUS create_file_unixpath(connection_struct *conn,
                                                create_disposition,
                                                create_options,
                                                file_attributes,
-                                               parent_dir_fname,
+                                               dirfsp->fsp_name,
                                                smb_fname_atname,
                                                &info,
                                                fsp);
@@ -6094,8 +6112,7 @@ static NTSTATUS create_file_unixpath(connection_struct *conn,
                        }
                } else if (lp_inherit_acls(SNUM(conn))) {
                        /* Inherit from parent. Errors here are not fatal. */
-                       status = inherit_new_acl(
-                               parent_dir_fname->fsp, fsp);
+                       status = inherit_new_acl(dirfsp, fsp);
                        if (!NT_STATUS_IS_OK(status)) {
                                DEBUG(10,("inherit_new_acl: failed for %s with %s\n",
                                        fsp_str_dbg(fsp),