]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: Slightly simplify non_widelink_open()
authorVolker Lendecke <vl@samba.org>
Sat, 10 Sep 2022 08:36:11 +0000 (01:36 -0700)
committerJeremy Allison <jra@samba.org>
Sat, 17 Sep 2022 04:15:35 +0000 (04:15 +0000)
Avoid the "is_share_root" boolean: One special case less to take care
of further down and in callers: Sanitize the relative name so that it
can never contain a path separator

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

index 463f8809abcbeeb81608c2c0767272fdbb609b51..5dd43ee4c553811eed2ff5093241db451eeaf6f8 100644 (file)
@@ -694,7 +694,6 @@ static NTSTATUS non_widelink_open(const struct files_struct *dirfsp,
        struct smb_filename *oldwd_fname = NULL;
        struct smb_filename *parent_dir_fname = NULL;
        bool have_opath = false;
-       bool is_share_root = false;
        struct vfs_open_how how = *_how;
        int ret;
 
@@ -710,11 +709,19 @@ static NTSTATUS non_widelink_open(const struct files_struct *dirfsp,
                int cmp = strcmp(connpath, smb_fname->base_name);
 
                if (cmp == 0) {
-                       is_share_root = true;
+                       /*
+                        * We're on the share root, reflect this in
+                        * smb_fname
+                        */
+                       smb_fname->base_name = talloc_strdup(smb_fname, "");
+                       if (smb_fname->base_name == NULL) {
+                               status = NT_STATUS_NO_MEMORY;
+                               goto out;
+                       }
                }
        }
 
-       if (!is_share_root && (dirfsp == conn->cwd_fsp)) {
+       if (dirfsp == conn->cwd_fsp) {
                struct smb_filename *smb_fname_dot = NULL;
 
                status = SMB_VFS_PARENT_PATHNAME(fsp->conn,
@@ -769,10 +776,7 @@ static NTSTATUS non_widelink_open(const struct files_struct *dirfsp,
                smb_fname_rel = smb_fname;
        }
 
-       if (!is_share_root) {
-               char *slash = strchr_m(smb_fname_rel->base_name, '/');
-               SMB_ASSERT(slash == NULL);
-       }
+       SMB_ASSERT(strchr_m(smb_fname_rel->base_name, '/') == NULL);
 
        how.flags |= O_NOFOLLOW;