From cd4df6ae43286138072b1fdd11b3eec4c47d13fc Mon Sep 17 00:00:00 2001 From: Ralph Boehme Date: Tue, 2 Jan 2024 13:25:25 +0100 Subject: [PATCH] smbd: add a directory argument to safe_symlink_target_path() 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 Reviewed-by: Volker Lendecke (cherry picked from commit fc80c72d658a41fe4d93b24b793b52c91b350175) --- source3/include/proto.h | 1 + source3/smbd/filename.c | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/source3/include/proto.h b/source3/include/proto.h index 13240033bf1..15c5839caf8 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -721,6 +721,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); diff --git a/source3/smbd/filename.c b/source3/smbd/filename.c index 45fb90381e2..55a49e0ba93 100644 --- a/source3/smbd/filename.c +++ b/source3/smbd/filename.c @@ -944,6 +944,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) @@ -959,10 +960,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) { @@ -1473,6 +1485,7 @@ next: status = safe_symlink_target_path(mem_ctx, conn->connectpath, + NULL, target, unparsed, &safe_target); -- 2.11.4.GIT