]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: Slightly simplify smbd_dirptr_get_entry()
authorVolker Lendecke <vl@samba.org>
Mon, 13 Nov 2023 09:25:58 +0000 (10:25 +0100)
committerVolker Lendecke <vl@samba.org>
Wed, 15 Nov 2023 05:10:35 +0000 (05:10 +0000)
Check for dirptr being toplevel just once.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/smbd/dir.c

index 5fe1aeb2641ff48cdb4bb4a54fd5a5b139c53e5a..f66ab0956f7125afd356a0d0ac50ca12f8528d7f 100644 (file)
@@ -526,7 +526,7 @@ bool smbd_dirptr_get_entry(TALLOC_CTX *ctx,
        struct smb_Dir *dir_hnd = dirptr->dir_hnd;
        struct smb_filename *dir_fname = dir_hnd->dir_smb_fname;
        bool posix = (dir_fname->flags & SMB_FILENAME_POSIX_PATH);
-       const char *dpath = dir_fname->base_name;
+       const bool toplevel = ISDOT(dir_fname->base_name);
        NTSTATUS status;
 
        *_smb_fname = NULL;
@@ -554,6 +554,7 @@ bool smbd_dirptr_get_entry(TALLOC_CTX *ctx,
                struct open_symlink_err *symlink_err = NULL;
                uint32_t mode = 0;
                bool get_dosmode = get_dosmode_in;
+               bool toplevel_dotdot;
                bool ok;
 
                dname = dptr_ReadDirName(ctx, dirptr);
@@ -586,11 +587,13 @@ bool smbd_dirptr_get_entry(TALLOC_CTX *ctx,
                        continue;
                }
 
+               toplevel_dotdot = toplevel && ISDOTDOT(dname);
+
                if (ISDOT(dname) || ISDOTDOT(dname)) {
 
                        const char *dotname = dname;
 
-                       if (ISDOTDOT(dname) && ISDOT(dpath)) {
+                       if (toplevel_dotdot) {
                                /*
                                 * Handle ".." in toplevel like "." to not
                                 * leak info from outside the share.
@@ -624,7 +627,7 @@ bool smbd_dirptr_get_entry(TALLOC_CTX *ctx,
                         * Don't leak INO/DEV/User SID/Group SID about
                         * the containing directory of the share.
                         */
-                       if (ISDOT(dpath) && ISDOTDOT(dname)) {
+                       if (toplevel_dotdot) {
                                /*
                                 * Ensure posix fileid and sids are hidden
                                 */