]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: prepare for replacing SMB_VFS_READLINKAT() with SMB_VFS_STATX() in the future
authorRalph Boehme <slow@samba.org>
Thu, 9 Apr 2020 13:42:59 +0000 (15:42 +0200)
committerRalph Boehme <slow@samba.org>
Thu, 21 May 2020 05:23:29 +0000 (05:23 +0000)
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 <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/smbd/open.c

index c28016da37098700d6d383095639d5fd32af9715..d59b797e97a621dc4c7c84b384b923482f8142a1 100644 (file)
@@ -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;
        }