mirror of
https://github.com/samba-team/samba.git
synced 2025-02-23 09:57:40 +03:00
smbd: move files_struct.can_write to a bitfield
Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
This commit is contained in:
parent
8b48969241
commit
b95c62bc90
@ -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) || \
|
||||
|
@ -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;
|
||||
|
@ -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.
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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 {
|
||||
|
@ -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;
|
||||
/*
|
||||
|
@ -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;
|
||||
|
@ -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)) {
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user