smbd: add a directory argument to safe_symlink_target_path()
authorRalph Boehme <slow@samba.org>
Tue, 2 Jan 2024 12:25:25 +0000 (13:25 +0100)
committerJule Anger <janger@samba.org>
Mon, 29 Jan 2024 10:45:17 +0000 (10:45 +0000)
Existing caller passes NULL, no change in behaviour. Prepares for
replacing symlink_target_below_conn() in open.c.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=15549

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
(cherry picked from commit fc80c72d658a41fe4d93b24b793b52c91b350175)

source3/include/proto.h
source3/smbd/filename.c

index 5e1e807b1adc5b2a123d55923418ccc0bd3492ed..7df3c7a8e01ad6f6cfe536d97707b185f4fee3f2 100644 (file)
@@ -720,6 +720,7 @@ struct smb_filename *synthetic_smb_fname(TALLOC_CTX *mem_ctx,
                                         uint32_t flags);
 NTSTATUS safe_symlink_target_path(TALLOC_CTX *mem_ctx,
                                  const char *connectpath,
+                                 const char *dir,
                                  const char *target,
                                  size_t unparsed,
                                  char **_relative);
index 606959d0805f5c3e22172269dd8c76d52740ec6b..1e07abacea68cfc843b19dcc6a49443bfc6f19b5 100644 (file)
@@ -945,6 +945,7 @@ static char *symlink_target_path(
 
 NTSTATUS safe_symlink_target_path(TALLOC_CTX *mem_ctx,
                                  const char *connectpath,
+                                 const char *dir,
                                  const char *target,
                                  size_t unparsed,
                                  char **_relative)
@@ -960,10 +961,21 @@ NTSTATUS safe_symlink_target_path(TALLOC_CTX *mem_ctx,
 
        if (target[0] == '/') {
                abs_target = talloc_strdup(mem_ctx, target);
-       } else {
+       } else if (dir == NULL) {
+               abs_target = talloc_asprintf(mem_ctx,
+                                            "%s/%s",
+                                            connectpath,
+                                            target);
+       } else if (dir[0] == '/') {
                abs_target = talloc_asprintf(mem_ctx,
                                             "%s/%s",
+                                            dir,
+                                            target);
+       } else {
+               abs_target = talloc_asprintf(mem_ctx,
+                                            "%s/%s/%s",
                                             connectpath,
+                                            dir,
                                             target);
        }
        if (abs_target == NULL) {
@@ -1491,6 +1503,7 @@ next:
 
        status = safe_symlink_target_path(mem_ctx,
                                          conn->connectpath,
+                                         NULL,
                                          target,
                                          unparsed,
                                          &safe_target);