From 7fca428cfb99d9da2b6a8dedb4ddc27c1347e334 Mon Sep 17 00:00:00 2001 From: Ralph Boehme Date: Thu, 30 Apr 2020 17:46:31 +0200 Subject: [PATCH] smbd: call canonicalize_snapshot_path() on link target paths from client Prepares for having canonicalize_snapshot_path() strip any @GMT token from link targets. In the future VFS modules won't be doing @GMT token stripping, so we have to do it here. Signed-off-by: Ralph Boehme Reviewed-by: Jeremy Allison --- source3/smbd/trans2.c | 14 +++++++++++++- source3/torture/cmd_vfs.c | 21 ++++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/source3/smbd/trans2.c b/source3/smbd/trans2.c index 96087e6b456..fa77cb4c6e0 100644 --- a/source3/smbd/trans2.c +++ b/source3/smbd/trans2.c @@ -6982,7 +6982,9 @@ static NTSTATUS smb_set_file_unix_link(connection_struct *conn, const struct smb_filename *new_smb_fname) { char *link_target = NULL; + struct smb_filename target_fname; TALLOC_CTX *ctx = talloc_tos(); + NTSTATUS status; int ret; /* Set a symbolic link. */ @@ -7003,11 +7005,21 @@ static NTSTATUS smb_set_file_unix_link(connection_struct *conn, return NT_STATUS_INVALID_PARAMETER; } + target_fname = (struct smb_filename) { + .base_name = link_target, + }; + + /* Removes @GMT tokens if any */ + status = canonicalize_snapshot_path(&target_fname, 0); + if (!NT_STATUS_IS_OK(status)) { + return status; + } + DEBUG(10,("smb_set_file_unix_link: SMB_SET_FILE_UNIX_LINK doing symlink %s -> %s\n", new_smb_fname->base_name, link_target )); ret = SMB_VFS_SYMLINKAT(conn, - link_target, + target_fname.base_name, conn->cwd_fsp, new_smb_fname); if (ret != 0) { diff --git a/source3/torture/cmd_vfs.c b/source3/torture/cmd_vfs.c index 52e0e647469..e33c8863883 100644 --- a/source3/torture/cmd_vfs.c +++ b/source3/torture/cmd_vfs.c @@ -1145,7 +1145,10 @@ static NTSTATUS cmd_lock(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, c static NTSTATUS cmd_symlink(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv) { int ret; + char *target = NULL; + struct smb_filename target_fname; struct smb_filename *new_smb_fname = NULL; + NTSTATUS status; if (argc != 3) { printf("Usage: symlink \n"); @@ -1158,8 +1161,24 @@ static NTSTATUS cmd_symlink(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc if (new_smb_fname == NULL) { return NT_STATUS_NO_MEMORY; } + + target = talloc_strdup(mem_ctx, argv[1]); + if (target == NULL) { + return NT_STATUS_NO_MEMORY; + } + + target_fname = (struct smb_filename) { + .base_name = target, + }; + + /* Removes @GMT tokens if any */ + status = canonicalize_snapshot_path(&target_fname, 0); + if (!NT_STATUS_IS_OK(status)) { + return status; + } + ret = SMB_VFS_SYMLINKAT(vfs->conn, - argv[1], + target_fname.base_name, vfs->conn->cwd_fsp, new_smb_fname); if (ret == -1) {