]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: Simplify open_file()
authorVolker Lendecke <vl@samba.org>
Tue, 5 Sep 2023 12:59:29 +0000 (14:59 +0200)
committerRalph Boehme <slow@samba.org>
Thu, 5 Oct 2023 12:58:33 +0000 (12:58 +0000)
Simplify an if-condition:

We have to return NT_STATUS_OBJECT_NAME_INVALID even if we're not
creating. In fact, we probably should not end up in open_file() if
we're open a Windows file with a wildcard.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/smbd/open.c

index 2fbc7db979eeb417870a2bea1b5b29ef8868f172..973e656d1285815084098a6372b5b4516eeddc29 100644 (file)
@@ -1387,7 +1387,6 @@ static NTSTATUS open_file(struct smb_request *req,
        }
 
        if (open_fd) {
-               const char *wild;
                int ret;
 
 #if defined(O_NONBLOCK) && defined(S_ISFIFO)
@@ -1402,19 +1401,22 @@ static NTSTATUS open_file(struct smb_request *req,
                }
 #endif
 
-               /* Don't create files with Microsoft wildcard characters. */
-               if (fsp_is_alternate_stream(fsp)) {
+               if (!posix_open) {
+                       const char *wild = smb_fname->base_name;
                        /*
-                        * wildcard characters are allowed in stream names
-                        * only test the basefilename
+                        * Don't open files with Microsoft wildcard characters.
                         */
-                       wild = fsp->base_fsp->fsp_name->base_name;
-               } else {
-                       wild = smb_fname->base_name;
-               }
-               if ((local_flags & O_CREAT) && !file_existed && !posix_open &&
-                   ms_has_wild(wild))  {
-                       return NT_STATUS_OBJECT_NAME_INVALID;
+                       if (fsp_is_alternate_stream(fsp)) {
+                               /*
+                                * wildcard characters are allowed in stream
+                                * names only test the basefilename
+                                */
+                               wild = fsp->base_fsp->fsp_name->base_name;
+                       }
+
+                       if (ms_has_wild(wild)) {
+                               return NT_STATUS_OBJECT_NAME_INVALID;
+                       }
                }
 
                /* Can we access this file ? */