smbd: Hand full_fname from openat_pathref_nostream()
authorVolker Lendecke <vl@samba.org>
Tue, 14 Jun 2022 15:05:09 +0000 (17:05 +0200)
committerRalph Boehme <slow@samba.org>
Mon, 25 Jul 2022 12:04:33 +0000 (12:04 +0000)
Rename it to openat_pathref_fullname(), it will be used for stream
open next

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

index 80420ea2e10155407a45928ba24d508d856a06e9..0adc84eba4275dcd7e6b3e3092a9e760be16f7ab 100644 (file)
@@ -440,12 +440,12 @@ static int smb_fname_fsp_destructor(struct smb_filename *smb_fname)
        return 0;
 }
 
-static NTSTATUS openat_pathref_nostream(
+static NTSTATUS openat_pathref_fullname(
        const struct files_struct *dirfsp,
+       struct smb_filename **full_fname,
        struct smb_filename *smb_fname)
 {
        struct connection_struct *conn = dirfsp->conn;
-       struct smb_filename *full_fname = NULL;
        struct files_struct *fsp = NULL;
        int open_flags = O_RDONLY;
        NTSTATUS status;
@@ -466,13 +466,7 @@ static NTSTATUS openat_pathref_nostream(
 
        fsp->fsp_flags.is_pathref = true;
 
-       full_fname = full_path_from_dirfsp_atname(fsp, dirfsp, smb_fname);
-       if (full_fname == NULL) {
-               status = NT_STATUS_NO_MEMORY;
-               goto fail;
-       }
-
-       status = fsp_attach_smb_fname(fsp, &full_fname);
+       status = fsp_attach_smb_fname(fsp, full_fname);
        if (!NT_STATUS_IS_OK(status)) {
                goto fail;
        }
@@ -551,6 +545,7 @@ NTSTATUS openat_pathref_fsp(const struct files_struct *dirfsp,
                            struct smb_filename *smb_fname)
 {
        connection_struct *conn = dirfsp->conn;
+       struct smb_filename *full_fname = NULL;
        struct smb_filename *base_fname = NULL;
        NTSTATUS status;
 
@@ -565,7 +560,23 @@ NTSTATUS openat_pathref_fsp(const struct files_struct *dirfsp,
 
        if (!(conn->fs_capabilities & FILE_NAMED_STREAMS) ||
            !is_named_stream(smb_fname)) {
-               status = openat_pathref_nostream(dirfsp, smb_fname);
+               /*
+                * openat_pathref_fullname() will make "full_fname" a
+                * talloc child of the smb_fname->fsp. Don't use
+                * talloc_tos() to allocate it to avoid making the
+                * talloc stackframe pool long-lived.
+                */
+               full_fname = full_path_from_dirfsp_atname(
+                       conn,
+                       dirfsp,
+                       smb_fname);
+               if (full_fname == NULL) {
+                       status = NT_STATUS_NO_MEMORY;
+                       goto fail;
+               }
+               status = openat_pathref_fullname(
+                       dirfsp, &full_fname, smb_fname);
+               TALLOC_FREE(full_fname);
                return status;
        }
 
@@ -577,7 +588,18 @@ NTSTATUS openat_pathref_fsp(const struct files_struct *dirfsp,
                return NT_STATUS_NO_MEMORY;
        }
 
-       status = openat_pathref_nostream(dirfsp, base_fname);
+       full_fname = full_path_from_dirfsp_atname(
+               conn,   /* no talloc_tos(), see comment above */
+               dirfsp,
+               base_fname);
+       if (full_fname == NULL) {
+               status = NT_STATUS_NO_MEMORY;
+               goto fail;
+       }
+
+       status = openat_pathref_fullname(
+               dirfsp, &full_fname, base_fname);
+       TALLOC_FREE(full_fname);
        if (!NT_STATUS_IS_OK(status)) {
                DBG_DEBUG("openat_pathref_nostream failed: %s\n",
                          nt_errstr(status));