smbd: move files_struct.can_write to a bitfield
authorRalph Boehme <slow@samba.org>
Thu, 2 Apr 2020 15:28:32 +0000 (17:28 +0200)
committerJeremy Allison <jra@samba.org>
Fri, 3 Apr 2020 19:05:44 +0000 (19:05 +0000)
Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
15 files changed:
source3/include/smb_macros.h
source3/include/vfs.h
source3/locking/posix.c
source3/modules/vfs_shadow_copy2.c
source3/modules/vfs_syncops.c
source3/printing/printspoolss.c
source3/smbd/durable.c
source3/smbd/fileio.c
source3/smbd/files.c
source3/smbd/nttrans.c
source3/smbd/open.c
source3/smbd/pysmbd.c
source3/smbd/server_exit.c
source3/smbd/trans2.c
source3/torture/cmd_vfs.c

index 1c81bd1b9d2b7be7862cfc034c362e11df832502..702be07aacd5afe804d80c6ac5df5aefada5c28c 100644 (file)
@@ -78,7 +78,7 @@
         (((fsp)->fsp_flags.can_read)))
 
 #define CHECK_WRITE(fsp) \
-       ((fsp)->can_write && \
+       ((fsp)->fsp_flags.can_write && \
         ((fsp)->fh->fd != -1))
 
 #define ERROR_WAS_LOCK_DENIED(status) (NT_STATUS_EQUAL((status), NT_STATUS_LOCK_NOT_GRANTED) || \
index 13f0fb6d660cdd5a7d1f4b80f147a2f3639fdf7d..d270dcbd92aca942c1141fddfbfe142065a70a2d 100644 (file)
@@ -364,6 +364,7 @@ typedef struct files_struct {
                bool write_time_forced : 1;
                bool can_lock : 1;
                bool can_read : 1;
+               bool can_write : 1;
        } fsp_flags;
 
        struct tevent_timer *update_write_time_event;
@@ -384,7 +385,6 @@ typedef struct files_struct {
        struct lock_struct last_lock_failure;
        int current_lock_count; /* Count the number of outstanding locks and pending locks. */
 
-       bool can_write;
        bool modified;
        bool is_directory;
        bool aio_write_behind;
index e74f48636ec0635abf8561ed8ec08c2ccdea898b..e7d773a6f667de317f70a2f012cd18236a1af362 100644 (file)
@@ -51,7 +51,7 @@ static struct db_context *posix_pending_close_db;
 
 static int map_posix_lock_type( files_struct *fsp, enum brl_type lock_type)
 {
-       if((lock_type == WRITE_LOCK) && !fsp->can_write) {
+       if ((lock_type == WRITE_LOCK) && !fsp->fsp_flags.can_write) {
                /*
                 * Many UNIX's cannot get a write lock on a file opened read-only.
                 * Win32 locking semantics allow this.
index 3666b2af2b43dc8392c177ec9756367783b45654..c4881c6d53e46cb141564459aa55ae89f989eff6 100644 (file)
@@ -2767,7 +2767,7 @@ static ssize_t shadow_copy2_pwrite(vfs_handle_struct *handle,
 
        nwritten = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
        if (nwritten == -1) {
-               if (errno == EBADF && fsp->can_write) {
+               if (errno == EBADF && fsp->fsp_flags.can_write) {
                        errno = EROFS;
                }
        }
@@ -2840,7 +2840,7 @@ static ssize_t shadow_copy2_pwrite_recv(struct tevent_req *req,
 
        if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
                if ((vfs_aio_state->error == EBADF) &&
-                   state->fsp->can_write)
+                   state->fsp->fsp_flags.can_write)
                {
                        vfs_aio_state->error = EROFS;
                        errno = EROFS;
index a863fbc0676a0c48d33493a5cdb297c1a50f5f2e..f375c359d6fdfbd649382d57a321d324743ee6dc 100644 (file)
@@ -280,7 +280,7 @@ static int syncops_close(vfs_handle_struct *handle, files_struct *fsp)
                                struct syncops_config_data,
                                return -1);
 
-       if (fsp->can_write && config->onclose) {
+       if (fsp->fsp_flags.can_write && config->onclose) {
                /* ideally we'd only do this if we have written some
                 data, but there is no flag for that in fsp yet. */
                fsync(fsp->fh->fd);
index a2942fbdf3f69e20dc8fff371d79168593ff8279..fbf4054b19249ceefe4deceb80e917991ecf7ffa 100644 (file)
@@ -231,7 +231,7 @@ NTSTATUS print_spool_open(files_struct *fsp,
        fsp->fsp_flags.can_lock = false;
        fsp->fsp_flags.can_read = false;
        fsp->access_mask = FILE_GENERIC_WRITE;
-       fsp->can_write = true;
+       fsp->fsp_flags.can_write = true;
        fsp->modified = false;
        fsp->oplock_type = NO_OPLOCK;
        fsp->sent_oplock_break = NO_BREAK_SENT;
index 94607a70464f7742b8e641ccce1224cc000dddec..54283a7bef11c7964aec68f3a40ac024e091ca31 100644 (file)
@@ -683,7 +683,7 @@ NTSTATUS vfs_default_durable_reconnect(struct connection_struct *conn,
        fsp->open_time = e.time;
        fsp->access_mask = e.access_mask;
        fsp->fsp_flags.can_read = ((fsp->access_mask & FILE_READ_DATA) != 0);
-       fsp->can_write = ((fsp->access_mask & (FILE_WRITE_DATA|FILE_APPEND_DATA)) != 0);
+       fsp->fsp_flags.can_write = ((fsp->access_mask & (FILE_WRITE_DATA|FILE_APPEND_DATA)) != 0);
        fsp->fnum = op->local_id;
        fsp_set_gen_id(fsp);
 
@@ -803,9 +803,9 @@ NTSTATUS vfs_default_durable_reconnect(struct connection_struct *conn,
        /*
         * TODO: properly calculate open flags
         */
-       if (fsp->can_write && fsp->fsp_flags.can_read) {
+       if (fsp->fsp_flags.can_write && fsp->fsp_flags.can_read) {
                flags = O_RDWR;
-       } else if (fsp->can_write) {
+       } else if (fsp->fsp_flags.can_write) {
                flags = O_WRONLY;
        } else if (fsp->fsp_flags.can_read) {
                flags = O_RDONLY;
index f516b95d6091c88d976339a40ee68ee830542c4a..2300f5a209f4660e7ba3c257a005ba55b8e0d356 100644 (file)
@@ -256,7 +256,7 @@ ssize_t write_file(struct smb_request *req,
                return t;
        }
 
-       if (!fsp->can_write) {
+       if (!fsp->fsp_flags.can_write) {
                errno = EPERM;
                return -1;
        }
index 1573c94610581469dab2977d3e7eaf9a8579beb9..78df1fad6f4f9c0a9396c5a64a97cef795f3e231 100644 (file)
@@ -790,7 +790,7 @@ NTSTATUS dup_file_fsp(
        to->oplock_type = from->oplock_type;
        to->fsp_flags.can_lock = from->fsp_flags.can_lock;
        to->fsp_flags.can_read = ((access_mask & FILE_READ_DATA) != 0);
-       to->can_write =
+       to->fsp_flags.can_write =
                CAN_WRITE(from->conn) &&
                ((access_mask & (FILE_WRITE_DATA | FILE_APPEND_DATA)) != 0);
        to->modified = from->modified;
index 001dbe2a79de983b195ca0d930d44e51c8d0b95d..38493d58c0280286f9499898f67d9b39517faee5 100644 (file)
@@ -725,7 +725,7 @@ void reply_ntcreate_and_X(struct smb_request *req)
                uint32_t perms = 0;
                p += 25;
                if (fsp->is_directory ||
-                   fsp->can_write ||
+                   fsp->fsp_flags.can_write ||
                    can_write_to_file(conn, smb_fname)) {
                        perms = FILE_GENERIC_ALL;
                } else {
@@ -1380,7 +1380,7 @@ static void call_nt_transact_create(connection_struct *conn,
                uint32_t perms = 0;
                p += 25;
                if (fsp->is_directory ||
-                   fsp->can_write ||
+                   fsp->fsp_flags.can_write ||
                    can_write_to_file(conn, smb_fname)) {
                        perms = FILE_GENERIC_ALL;
                } else {
index ffc818cc63acd6ae01cab4c3e8f8c4e5110680af..4e0b375237126a2f2f90536fe268d80ffa5030e0 100644 (file)
@@ -1431,7 +1431,7 @@ static NTSTATUS open_file(files_struct *fsp,
        fsp->file_pid = req ? req->smbpid : 0;
        fsp->fsp_flags.can_lock = true;
        fsp->fsp_flags.can_read = ((access_mask & FILE_READ_DATA) != 0);
-       fsp->can_write =
+       fsp->fsp_flags.can_write =
                CAN_WRITE(conn) &&
                ((access_mask & (FILE_WRITE_DATA | FILE_APPEND_DATA)) != 0);
        fsp->print_file = NULL;
@@ -1448,7 +1448,7 @@ static NTSTATUS open_file(files_struct *fsp,
                 conn->session_info->unix_info->unix_name,
                 smb_fname_str_dbg(smb_fname),
                 BOOLSTR(fsp->fsp_flags.can_read),
-                BOOLSTR(fsp->can_write),
+                BOOLSTR(fsp->fsp_flags.can_write),
                 conn->num_files_open));
 
        errno = 0;
@@ -4394,7 +4394,7 @@ static NTSTATUS open_directory(connection_struct *conn,
        fsp->file_pid = req ? req->smbpid : 0;
        fsp->fsp_flags.can_lock = false;
        fsp->fsp_flags.can_read = false;
-       fsp->can_write = False;
+       fsp->fsp_flags.can_write = false;
 
        fsp->fh->private_options = 0;
        /*
index e0cf7e081bd481aa4166ce3f1cc6a61a12fcb496..224619b601467db994d06dc9b1a44d3b94d8a80d 100644 (file)
@@ -195,7 +195,7 @@ static NTSTATUS init_files_struct(TALLOC_CTX *mem_ctx,
        fsp->file_pid = 0;
        fsp->fsp_flags.can_lock = true;
        fsp->fsp_flags.can_read = true;
-       fsp->can_write = True;
+       fsp->fsp_flags.can_write = true;
        fsp->print_file = NULL;
        fsp->modified = False;
        fsp->sent_oplock_break = NO_BREAK_SENT;
index 23debc5f5ccb52754d5cd3a7eb47bc2a92e58d7c..f361aaf0bb78411aef4bd2e1122f44b86caf28d6 100644 (file)
@@ -44,7 +44,7 @@ static struct files_struct *log_writeable_file_fn(
        bool *found = (bool *)private_data;
        char *path;
 
-       if (!fsp->can_write) {
+       if (!fsp->fsp_flags.can_write) {
                return NULL;
        }
        if (!(*found)) {
index 8a33533ced46d1a2037579ed3f5466e4de7e50ad..a4cf666d76fb420b5b16a51dcdd6ceda03ada78e 100644 (file)
@@ -7685,7 +7685,7 @@ static NTSTATUS smb_set_posix_lock(connection_struct *conn,
                        break;
                case POSIX_LOCK_TYPE_WRITE:
                        /* Return the right POSIX-mappable error code for files opened read-only. */
-                       if (!fsp->can_write) {
+                       if (!fsp->fsp_flags.can_write) {
                                return NT_STATUS_INVALID_HANDLE;
                        }
                        lock_type = WRITE_LOCK;
index bea66ee2c71709c66473314f896b821bb463c00e..4ad65dc31ba5c7f158ab34f066bc49f5083093cd 100644 (file)
@@ -424,8 +424,7 @@ static NTSTATUS cmd_open(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, c
        fsp->file_pid = 0;
        fsp->fsp_flags.can_lock = true;
        fsp->fsp_flags.can_read = true;
-       fsp->can_write =
-               CAN_WRITE(vfs->conn);
+       fsp->fsp_flags.can_write = CAN_WRITE(vfs->conn);
        fsp->print_file = NULL;
        fsp->modified = False;
        fsp->sent_oplock_break = NO_BREAK_SENT;
@@ -1653,7 +1652,7 @@ static NTSTATUS cmd_set_nt_acl(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int a
        fsp->file_pid = 0;
        fsp->fsp_flags.can_lock = true;
        fsp->fsp_flags.can_read = true;
-       fsp->can_write = True;
+       fsp->fsp_flags.can_write = true;
        fsp->print_file = NULL;
        fsp->modified = False;
        fsp->sent_oplock_break = NO_BREAK_SENT;