]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: use helper variables in open_file()
authorRalph Boehme <slow@samba.org>
Wed, 4 Mar 2020 09:54:18 +0000 (10:54 +0100)
committerJeremy Allison <jra@samba.org>
Tue, 21 Apr 2020 18:37:39 +0000 (18:37 +0000)
Simplify an if expression by using helper variables, no change in behaviour.

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

index b2d0455ba43c4203303d042bc1e51684ecae3abc..16c24383b237001ca80189ce54b971f9ad8e411c 100644 (file)
@@ -1150,6 +1150,16 @@ static NTSTATUS open_file(files_struct *fsp,
        int accmode = (flags & O_ACCMODE);
        int local_flags = flags;
        bool file_existed = VALID_STAT(fsp->fsp_name->st);
+       uint32_t need_fd_mask =
+               FILE_READ_DATA |
+               FILE_WRITE_DATA |
+               FILE_APPEND_DATA |
+               FILE_EXECUTE |
+               WRITE_DAC_ACCESS |
+               WRITE_OWNER_ACCESS |
+               READ_CONTROL_ACCESS;
+       bool creating = !file_existed && (flags & O_CREAT);
+       bool truncating = (flags & O_TRUNC);
 
        fsp->fh->fd = -1;
        errno = EPERM;
@@ -1201,12 +1211,7 @@ static NTSTATUS open_file(files_struct *fsp,
                local_flags = (flags & ~O_ACCMODE)|O_RDWR;
        }
 
-       if ((open_access_mask & (FILE_READ_DATA|FILE_WRITE_DATA|
-                                FILE_APPEND_DATA|FILE_EXECUTE|
-                                WRITE_DAC_ACCESS|WRITE_OWNER_ACCESS|
-                                READ_CONTROL_ACCESS))||
-           (!file_existed && (local_flags & O_CREAT)) ||
-           ((local_flags & O_TRUNC) == O_TRUNC) ) {
+       if ((open_access_mask & need_fd_mask) || creating || truncating) {
                const char *wild;
                int ret;
 
@@ -1220,6 +1225,7 @@ static NTSTATUS open_file(files_struct *fsp,
                if (file_existed && S_ISFIFO(smb_fname->st.st_ex_mode)) {
                        local_flags &= ~O_TRUNC; /* Can't truncate a FIFO. */
                        local_flags |= O_NONBLOCK;
+                       truncating = false;
                }
 #endif