From 15303ee19bce519d18758e7e6cb3aa8a539bab42 Mon Sep 17 00:00:00 2001 From: Ralph Boehme Date: Thu, 9 Apr 2020 15:42:59 +0200 Subject: [PATCH] smbd: prepare for replacing SMB_VFS_READLINKAT() with SMB_VFS_STATX() in the future Add a large comment inside process_symlink_open() explaining why we need to call SMB_VFS_READLINKAT(). As we don't make use of the returned name and just rely on SMB_VFS_REALPATH() doing its job, remove target_fname Signed-off-by: Ralph Boehme Reviewed-by: Jeremy Allison --- source3/smbd/open.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/source3/smbd/open.c b/source3/smbd/open.c index c28016da370..d59b797e97a 100644 --- a/source3/smbd/open.c +++ b/source3/smbd/open.c @@ -481,7 +481,6 @@ static int process_symlink_open(struct connection_struct *conn, { int fd = -1; char *link_target = NULL; - struct smb_filename target_fname = {0}; int link_len = -1; struct smb_filename *oldwd_fname = NULL; size_t rootdir_len = 0; @@ -506,7 +505,19 @@ static int process_symlink_open(struct connection_struct *conn, goto out; } - /* Read the link target. */ + /* + * Read the link target. We do this just to verify that smb_fname indeed + * points at a symbolic link and return the SMB_VFS_READLINKAT() errno + * and failure in case smb_fname is NOT a symlink. + * + * The caller needs this piece of information to distinguish two cases + * where open() fails with errno=ENOTDIR, cf the comment in + * non_widelink_open(). + * + * We rely on SMB_VFS_REALPATH() to resolve the path including the + * symlink. Once we have SMB_VFS_STATX() or something similar in our VFS + * we may want to use that instead of SMB_VFS_READLINKAT(). + */ link_len = SMB_VFS_READLINKAT(conn, conn->cwd_fsp, smb_fname, @@ -516,15 +527,8 @@ static int process_symlink_open(struct connection_struct *conn, goto out; } - /* Ensure it's at least null terminated. */ - link_target[link_len] = '\0'; - target_fname = (struct smb_filename) { - .base_name = link_target, - .twrp = smb_fname->twrp, - }; - /* Convert to an absolute path. */ - resolved_fname = SMB_VFS_REALPATH(conn, talloc_tos(), &target_fname); + resolved_fname = SMB_VFS_REALPATH(conn, talloc_tos(), smb_fname); if (resolved_fname == NULL) { goto out; }