From: Ralph Boehme Date: Thu, 2 Apr 2020 15:28:32 +0000 (+0200) Subject: smbd: move files_struct.can_write to a bitfield X-Git-Tag: ldb-2.2.0~992 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b95c62bc90cef5cbb5525c92788eca9641944268;p=thirdparty%2Fsamba.git smbd: move files_struct.can_write to a bitfield Signed-off-by: Ralph Boehme Reviewed-by: Jeremy Allison --- diff --git a/source3/include/smb_macros.h b/source3/include/smb_macros.h index 1c81bd1b9d2..702be07aacd 100644 --- a/source3/include/smb_macros.h +++ b/source3/include/smb_macros.h @@ -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) || \ diff --git a/source3/include/vfs.h b/source3/include/vfs.h index 13f0fb6d660..d270dcbd92a 100644 --- a/source3/include/vfs.h +++ b/source3/include/vfs.h @@ -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; diff --git a/source3/locking/posix.c b/source3/locking/posix.c index e74f48636ec..e7d773a6f66 100644 --- a/source3/locking/posix.c +++ b/source3/locking/posix.c @@ -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. diff --git a/source3/modules/vfs_shadow_copy2.c b/source3/modules/vfs_shadow_copy2.c index 3666b2af2b4..c4881c6d53e 100644 --- a/source3/modules/vfs_shadow_copy2.c +++ b/source3/modules/vfs_shadow_copy2.c @@ -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; diff --git a/source3/modules/vfs_syncops.c b/source3/modules/vfs_syncops.c index a863fbc0676..f375c359d6f 100644 --- a/source3/modules/vfs_syncops.c +++ b/source3/modules/vfs_syncops.c @@ -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); diff --git a/source3/printing/printspoolss.c b/source3/printing/printspoolss.c index a2942fbdf3f..fbf4054b192 100644 --- a/source3/printing/printspoolss.c +++ b/source3/printing/printspoolss.c @@ -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; diff --git a/source3/smbd/durable.c b/source3/smbd/durable.c index 94607a70464..54283a7bef1 100644 --- a/source3/smbd/durable.c +++ b/source3/smbd/durable.c @@ -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; diff --git a/source3/smbd/fileio.c b/source3/smbd/fileio.c index f516b95d609..2300f5a209f 100644 --- a/source3/smbd/fileio.c +++ b/source3/smbd/fileio.c @@ -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; } diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 1573c946105..78df1fad6f4 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -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; diff --git a/source3/smbd/nttrans.c b/source3/smbd/nttrans.c index 001dbe2a79d..38493d58c02 100644 --- a/source3/smbd/nttrans.c +++ b/source3/smbd/nttrans.c @@ -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 { diff --git a/source3/smbd/open.c b/source3/smbd/open.c index ffc818cc63a..4e0b3752371 100644 --- a/source3/smbd/open.c +++ b/source3/smbd/open.c @@ -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; /* diff --git a/source3/smbd/pysmbd.c b/source3/smbd/pysmbd.c index e0cf7e081bd..224619b6014 100644 --- a/source3/smbd/pysmbd.c +++ b/source3/smbd/pysmbd.c @@ -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; diff --git a/source3/smbd/server_exit.c b/source3/smbd/server_exit.c index 23debc5f5cc..f361aaf0bb7 100644 --- a/source3/smbd/server_exit.c +++ b/source3/smbd/server_exit.c @@ -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)) { diff --git a/source3/smbd/trans2.c b/source3/smbd/trans2.c index 8a33533ced4..a4cf666d76f 100644 --- a/source3/smbd/trans2.c +++ b/source3/smbd/trans2.c @@ -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; diff --git a/source3/torture/cmd_vfs.c b/source3/torture/cmd_vfs.c index bea66ee2c71..4ad65dc31ba 100644 --- a/source3/torture/cmd_vfs.c +++ b/source3/torture/cmd_vfs.c @@ -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;