]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: Remove "local_flags" from open_file()
authorVolker Lendecke <vl@samba.org>
Tue, 5 Sep 2023 13:27:46 +0000 (15:27 +0200)
committerRalph Boehme <slow@samba.org>
Thu, 5 Oct 2023 12:58:33 +0000 (12:58 +0000)
This needs close review. I could not see where we were actually
referencing the original flags in a way that would not be available in
local_flags. The reason for this patch is that I want to pass in
vfs_open_how into open_file(), and the distinction between flags and
local_flags made this significantly harder to understand for me.

The only place where we really used both versions is the DBG_NOTICE in
the last hunk, and this will come back in the next patch.

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

index 6e18844bb16ac26bd63126440e6a262b8e6ad472..614e0f93068f7f81518afc69244c39b7b7867c01 100644 (file)
@@ -1315,7 +1315,6 @@ static NTSTATUS open_file(struct smb_request *req,
        connection_struct *conn = fsp->conn;
        struct smb_filename *smb_fname = fsp->fsp_name;
        NTSTATUS status = NT_STATUS_OK;
-       int local_flags = flags;
        bool file_existed = VALID_STAT(fsp->fsp_name->st);
        const uint32_t need_fd_mask =
                FILE_READ_DATA |
@@ -1350,7 +1349,7 @@ static NTSTATUS open_file(struct smb_request *req,
        if (((flags & O_ACCMODE) == O_RDONLY) && (flags & O_TRUNC)) {
                DBG_DEBUG("truncate requested on read-only open for file %s\n",
                          smb_fname_str_dbg(smb_fname));
-               local_flags = (flags & ~O_ACCMODE) | O_RDWR;
+               flags = (flags & ~O_ACCMODE) | O_RDWR;
        }
 
        /* Check permissions */
@@ -1378,7 +1377,7 @@ static NTSTATUS open_file(struct smb_request *req,
                 * O_CREAT doesn't create the file if we have write
                 * access into the directory.
                 */
-               local_flags &= ~(O_CREAT | O_EXCL);
+               flags &= ~(O_CREAT | O_EXCL);
        }
 
        if ((open_access_mask & need_fd_mask) || creating ||
@@ -1397,7 +1396,7 @@ static NTSTATUS open_file(struct smb_request *req,
                 */
 
                if (file_existed && S_ISFIFO(smb_fname->st.st_ex_mode)) {
-                       local_flags |= O_NONBLOCK;
+                       flags |= O_NONBLOCK;
                }
 #endif
 
@@ -1456,7 +1455,7 @@ static NTSTATUS open_file(struct smb_request *req,
                        }
 
                        if (!file_existed) {
-                               if (!(local_flags & O_CREAT)) {
+                               if (!(flags & O_CREAT)) {
                                        /* File didn't exist and no O_CREAT. */
                                        return NT_STATUS_OBJECT_NAME_NOT_FOUND;
                                }
@@ -1483,7 +1482,7 @@ static NTSTATUS open_file(struct smb_request *req,
                 */
                {
                        struct vfs_open_how how = {
-                               .flags = local_flags & ~O_TRUNC,
+                               .flags = flags & ~O_TRUNC,
                                .mode = unx_mode,
                        };
                        status = reopen_from_fsp(dirfsp,
@@ -1503,13 +1502,14 @@ static NTSTATUS open_file(struct smb_request *req,
                        status = NT_STATUS_OBJECT_NAME_NOT_FOUND;
                }
                if (!NT_STATUS_IS_OK(status)) {
-                       DEBUG(3,("Error opening file %s (%s) (local_flags=%d) "
-                                "(flags=%d)\n", smb_fname_str_dbg(smb_fname),
-                                nt_errstr(status),local_flags,flags));
+                       DBG_NOTICE("Error opening file %s (%s) (flags=%d)\n",
+                                  smb_fname_str_dbg(smb_fname),
+                                  nt_errstr(status),
+                                  flags);
                        return status;
                }
 
-               if (local_flags & O_NONBLOCK) {
+               if (flags & O_NONBLOCK) {
                        /*
                         * GPFS can return ETIMEDOUT for pread on
                         * nonblocking file descriptors when files