smbd: Factor out full_path_from_dirfsp_at_basename()
authorVolker Lendecke <vl@samba.org>
Thu, 22 Jun 2023 12:46:01 +0000 (14:46 +0200)
committerVolker Lendecke <vl@samba.org>
Fri, 30 Jun 2023 10:42:36 +0000 (10:42 +0000)
Will use this logic in the next patch

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

index f71796b57ae9c38c564c9160c68ee6c956ecd578..bf6797514e35dd50568db66de32ab7dcd3b38f1e 100644 (file)
@@ -726,6 +726,9 @@ NTSTATUS filename_convert_dirfsp(
        NTTIME twrp,
        struct files_struct **pdirfsp,
        struct smb_filename **psmb_name_rel);
+char *full_path_from_dirfsp_at_basename(TALLOC_CTX *mem_ctx,
+                                       const struct files_struct *dirfsp,
+                                       const char *at_base_name);
 struct smb_filename *full_path_from_dirfsp_atname(
        TALLOC_CTX *mem_ctx,
        const struct files_struct *dirfsp,
index 8079ea46e1a9309ada6eece296a4776b5e4a1858..7f97daef1fd591d1c6942fe21e2fc480f55456d1 100644 (file)
@@ -1483,27 +1483,39 @@ next:
        goto next;
 }
 
-/*
- * Build the full path from a dirfsp and dirfsp relative name
- */
-struct smb_filename *full_path_from_dirfsp_atname(
-       TALLOC_CTX *mem_ctx,
-       const struct files_struct *dirfsp,
-       const struct smb_filename *atname)
+char *full_path_from_dirfsp_at_basename(TALLOC_CTX *mem_ctx,
+                                       const struct files_struct *dirfsp,
+                                       const char *at_base_name)
 {
-       struct smb_filename *fname = NULL;
        char *path = NULL;
 
        if (dirfsp == dirfsp->conn->cwd_fsp ||
-           ISDOT(dirfsp->fsp_name->base_name) ||
-           atname->base_name[0] == '/')
-       {
-               path = talloc_strdup(mem_ctx, atname->base_name);
+           ISDOT(dirfsp->fsp_name->base_name) || at_base_name[0] == '/') {
+               path = talloc_strdup(mem_ctx, at_base_name);
        } else {
-               path = talloc_asprintf(mem_ctx, "%s/%s",
+               path = talloc_asprintf(mem_ctx,
+                                      "%s/%s",
                                       dirfsp->fsp_name->base_name,
-                                      atname->base_name);
+                                      at_base_name);
        }
+
+       return path;
+}
+
+/*
+ * Build the full path from a dirfsp and dirfsp relative name
+ */
+struct smb_filename *
+full_path_from_dirfsp_atname(TALLOC_CTX *mem_ctx,
+                            const struct files_struct *dirfsp,
+                            const struct smb_filename *atname)
+{
+       struct smb_filename *fname = NULL;
+       char *path = NULL;
+
+       path = full_path_from_dirfsp_at_basename(mem_ctx,
+                                                dirfsp,
+                                                atname->base_name);
        if (path == NULL) {
                return NULL;
        }