]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
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)
committerVolker Lendecke <vl@samba.org>
Mon, 22 Jan 2024 10:53:29 +0000 (10:53 +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>
source3/include/proto.h
source3/smbd/filename.c

index a22c7abf587b846b771a4ef5ca627b18e17b2399..e9e13f671733cfcc5b945299712ac5e35a0af214 100644 (file)
@@ -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);
index a3392ef986fe4459d20740b7d7d50852e1c68b16..f80f67c12910d70025f02679b68adc149771de41 100644 (file)
@@ -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);