From: Ralph Boehme Date: Wed, 4 Mar 2020 09:54:18 +0000 (+0100) Subject: smbd: use helper variables in open_file() X-Git-Tag: ldb-2.2.0~901 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fff86ad49a1b50c8d74ede4a66a90add1d338d76;p=thirdparty%2Fsamba.git smbd: use helper variables in open_file() Simplify an if expression by using helper variables, no change in behaviour. Signed-off-by: Ralph Boehme --- diff --git a/source3/smbd/open.c b/source3/smbd/open.c index b2d0455ba43..16c24383b23 100644 --- a/source3/smbd/open.c +++ b/source3/smbd/open.c @@ -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