From: Ralph Boehme Date: Tue, 2 Jan 2024 12:25:25 +0000 (+0100) Subject: smbd: add a directory argument to safe_symlink_target_path() X-Git-Tag: talloc-2.4.2~61 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=fc80c72d658a41fe4d93b24b793b52c91b350175;p=thirdparty%2Fsamba.git 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 --- diff --git a/source3/include/proto.h b/source3/include/proto.h index a22c7abf587..e9e13f67173 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -706,6 +706,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 a3392ef986f..f80f67c1291 100644 --- a/source3/smbd/filename.c +++ b/source3/smbd/filename.c @@ -661,6 +661,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) @@ -676,10 +677,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) { @@ -1192,6 +1204,7 @@ next: status = safe_symlink_target_path(mem_ctx, conn->connectpath, + NULL, target, symlink_err->unparsed, &safe_target);