From a4e6250442bb7a4ba93cfdb373212da5493faa33 Mon Sep 17 00:00:00 2001 From: Richard Sharpe Date: Sun, 20 Mar 2016 12:51:32 -0700 Subject: [PATCH] s3: vfs: Add VFS functions for setting and getting DOS attributes. This will make it easier to support those systems and file systems that can store DOS attributes. It should retain the original functionality if VFS functions providing these things are not provided. Signed-off-by: Richard Sharpe Signed-off-by: Jeremy Allison --- examples/VFS/skel_opaque.c | 34 ++++++++++++ examples/VFS/skel_transparent.c | 42 ++++++++++++++ source3/include/vfs.h | 29 ++++++++++ source3/include/vfs_macros.h | 18 ++++++ source3/modules/vfs_default.c | 32 +++++++++++ source3/modules/vfs_full_audit.c | 94 ++++++++++++++++++++++++++++++++ source3/smbd/proto.h | 7 +++ source3/smbd/vfs.c | 32 +++++++++++ 8 files changed, 288 insertions(+) diff --git a/examples/VFS/skel_opaque.c b/examples/VFS/skel_opaque.c index 67c387d83df..81ce1848898 100644 --- a/examples/VFS/skel_opaque.c +++ b/examples/VFS/skel_opaque.c @@ -672,6 +672,34 @@ static NTSTATUS skel_readdir_attr(struct vfs_handle_struct *handle, return NT_STATUS_NOT_IMPLEMENTED; } +static NTSTATUS skel_get_dos_attributes(struct vfs_handle_struct *handle, + struct smb_filename *smb_fname, + uint32_t *dosmode) +{ + return NT_STATUS_NOT_IMPLEMENTED; +} + +static NTSTATUS skel_fget_dos_attributes(struct vfs_handle_struct *handle, + struct files_struct *fsp, + uint32_t *dosmode) +{ + return NT_STATUS_NOT_IMPLEMENTED; +} + +static NTSTATUS skel_set_dos_attributes(struct vfs_handle_struct *handle, + const struct smb_filename *smb_fname, + uint32_t dosmode) +{ + return NT_STATUS_NOT_IMPLEMENTED; +} + +static NTSTATUS skel_fset_dos_attributes(struct vfs_handle_struct *handle, + struct files_struct *fsp, + uint32_t dosmode) +{ + return NT_STATUS_NOT_IMPLEMENTED; +} + static NTSTATUS skel_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp, uint32_t security_info, TALLOC_CTX *mem_ctx, @@ -941,6 +969,12 @@ struct vfs_fn_pointers skel_opaque_fns = { .fsctl_fn = skel_fsctl, .readdir_attr_fn = skel_readdir_attr, + /* DOS attributes. */ + .get_dos_attributes_fn = skel_get_dos_attributes, + .fget_dos_attributes_fn = skel_fget_dos_attributes, + .set_dos_attributes_fn = skel_set_dos_attributes, + .fset_dos_attributes_fn = skel_fset_dos_attributes, + /* NT ACL operations. */ .fget_nt_acl_fn = skel_fget_nt_acl, diff --git a/examples/VFS/skel_transparent.c b/examples/VFS/skel_transparent.c index 9fc943819d6..418ee24f97e 100644 --- a/examples/VFS/skel_transparent.c +++ b/examples/VFS/skel_transparent.c @@ -801,6 +801,42 @@ static NTSTATUS skel_readdir_attr(struct vfs_handle_struct *handle, return SMB_VFS_NEXT_READDIR_ATTR(handle, fname, mem_ctx, pattr_data); } +static NTSTATUS skel_get_dos_attributes(struct vfs_handle_struct *handle, + struct smb_filename *smb_fname, + uint32_t *dosmode) +{ + return SMB_VFS_NEXT_GET_DOS_ATTRIBUTES(handle, + smb_fname, + dosmode); +} + +static NTSTATUS skel_fget_dos_attributes(struct vfs_handle_struct *handle, + struct files_struct *fsp, + uint32_t *dosmode) +{ + return SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle, + fsp, + dosmode); +} + +static NTSTATUS skel_set_dos_attributes(struct vfs_handle_struct *handle, + const struct smb_filename *smb_fname, + uint32_t dosmode) +{ + return SMB_VFS_NEXT_SET_DOS_ATTRIBUTES(handle, + smb_fname, + dosmode); +} + +static NTSTATUS skel_fset_dos_attributes(struct vfs_handle_struct *handle, + struct files_struct *fsp, + uint32_t dosmode) +{ + return SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle, + fsp, + dosmode); +} + static NTSTATUS skel_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp, uint32_t security_info, TALLOC_CTX *mem_ctx, @@ -1056,6 +1092,12 @@ struct vfs_fn_pointers skel_transparent_fns = { .fsctl_fn = skel_fsctl, .readdir_attr_fn = skel_readdir_attr, + /* DOS attributes. */ + .get_dos_attributes_fn = skel_get_dos_attributes, + .fget_dos_attributes_fn = skel_fget_dos_attributes, + .set_dos_attributes_fn = skel_set_dos_attributes, + .fset_dos_attributes_fn = skel_fset_dos_attributes, + /* NT ACL operations. */ .fget_nt_acl_fn = skel_fget_nt_acl, diff --git a/source3/include/vfs.h b/source3/include/vfs.h index 3a86c627f81..6ab9a7e36b2 100644 --- a/source3/include/vfs.h +++ b/source3/include/vfs.h @@ -191,6 +191,7 @@ /* Version 35 - Change streaminfo from const char *, to const struct smb_filename * */ /* Version 35 - Add uint32_t flags to struct smb_filename */ +/* Version 35 - Add get/set/fget/fset dos attribute functions. */ #define SMB_VFS_INTERFACE_VERSION 35 @@ -785,6 +786,22 @@ struct vfs_fn_pointers { uint32_t max_out_len, uint32_t *out_len); + NTSTATUS (*get_dos_attributes_fn)(struct vfs_handle_struct *handle, + struct smb_filename *smb_fname, + uint32_t *dosmode); + + NTSTATUS (*fget_dos_attributes_fn)(struct vfs_handle_struct *handle, + struct files_struct *fsp, + uint32_t *dosmode); + + NTSTATUS (*set_dos_attributes_fn)(struct vfs_handle_struct *handle, + const struct smb_filename *smb_fname, + uint32_t dosmode); + + NTSTATUS (*fset_dos_attributes_fn)(struct vfs_handle_struct *hande, + struct files_struct *fsp, + uint32_t dosmode); + /* NT ACL operations. */ NTSTATUS (*fget_nt_acl_fn)(struct vfs_handle_struct *handle, @@ -1205,6 +1222,18 @@ NTSTATUS smb_vfs_call_fsctl(struct vfs_handle_struct *handle, uint8_t **_out_data, uint32_t max_out_len, uint32_t *out_len); +NTSTATUS smb_vfs_call_get_dos_attributes(struct vfs_handle_struct *handle, + struct smb_filename *smb_fname, + uint32_t *dosmode); +NTSTATUS smb_vfs_call_fget_dos_attributes(struct vfs_handle_struct *handle, + struct files_struct *fsp, + uint32_t *dosmode); +NTSTATUS smb_vfs_call_set_dos_attributes(struct vfs_handle_struct *handle, + const struct smb_filename *smb_fname, + uint32_t dosmode); +NTSTATUS smb_vfs_call_fset_dos_attributes(struct vfs_handle_struct *handle, + struct files_struct *fsp, + uint32_t dosmode); struct tevent_req *smb_vfs_call_copy_chunk_send(struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx, struct tevent_context *ev, diff --git a/source3/include/vfs_macros.h b/source3/include/vfs_macros.h index 6059c2ab1a6..c3c9a1716e9 100644 --- a/source3/include/vfs_macros.h +++ b/source3/include/vfs_macros.h @@ -397,6 +397,24 @@ #define SMB_VFS_NEXT_FSCTL(handle, fsp, ctx, function, req_flags, in_data, in_len, out_data, max_out_len, out_len) \ smb_vfs_call_fsctl((handle)->next, (fsp), (ctx), (function), (req_flags), (in_data), (in_len), (out_data), (max_out_len), (out_len)) +#define SMB_VFS_GET_DOS_ATTRIBUTES(conn, smb_fname, attributes) \ + smb_vfs_call_get_dos_attributes((conn)->vfs_handles, (smb_fname), (attributes)) +#define SMB_VFS_NEXT_GET_DOS_ATTRIBUTES(handle, smb_fname, attributes) \ + smb_vfs_call_get_dos_attributes((handle)->next, (smb_fname), (attributes)) +#define SMB_VFS_FGET_DOS_ATTRIBUTES(conn, fsp, attributes) \ + smb_vfs_call_fget_dos_attributes((conn)->vfs_handles, (fsp), (attributes)) +#define SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle, fsp, attributes) \ + smb_vfs_call_fget_dos_attributes((handle)->next, (fsp), (attributes)) + +#define SMB_VFS_SET_DOS_ATTRIBUTES(conn, smb_fname, attributes) \ + smb_vfs_call_set_dos_attributes((conn)->vfs_handles, (smb_fname), (attributes)) +#define SMB_VFS_NEXT_SET_DOS_ATTRIBUTES(handle, smb_fname, attributes) \ + smb_vfs_call_set_dos_attributes((handle)->next, (smb_fname), (attributes)) +#define SMB_VFS_FSET_DOS_ATTRIBUTES(conn, fsp, attributes) \ + smb_vfs_call_fset_dos_attributes((conn)->vfs_handles, (fsp), (attributes)) +#define SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle, fsp, attributes) \ + smb_vfs_call_fset_dos_attributes((handle)->next, (fsp), (attributes)) + #define SMB_VFS_COPY_CHUNK_SEND(conn, mem_ctx, ev, src_fsp, src_off, dest_fsp, dest_off, num) \ smb_vfs_call_copy_chunk_send((conn)->vfs_handles, (mem_ctx), (ev), (src_fsp), (src_off), (dest_fsp), (dest_off), (num)) #define SMB_VFS_NEXT_COPY_CHUNK_SEND(handle, mem_ctx, ev, src_fsp, src_off, dest_fsp, dest_off, num) \ diff --git a/source3/modules/vfs_default.c b/source3/modules/vfs_default.c index 41e443e6ca6..8ee163506b4 100644 --- a/source3/modules/vfs_default.c +++ b/source3/modules/vfs_default.c @@ -1427,6 +1427,34 @@ static NTSTATUS vfswrap_fsctl(struct vfs_handle_struct *handle, return NT_STATUS_NOT_SUPPORTED; } +static NTSTATUS vfswrap_get_dos_attributes(struct vfs_handle_struct *handle, + struct smb_filename *smb_fname, + uint32_t *dosmode) +{ + return get_ea_dos_attribute(handle->conn, smb_fname, dosmode); +} + +static NTSTATUS vfswrap_fget_dos_attributes(struct vfs_handle_struct *handle, + struct files_struct *fsp, + uint32_t *dosmode) +{ + return get_ea_dos_attribute(handle->conn, fsp->fsp_name, dosmode); +} + +static NTSTATUS vfswrap_set_dos_attributes(struct vfs_handle_struct *handle, + const struct smb_filename *smb_fname, + uint32_t dosmode) +{ + return set_ea_dos_attribute(handle->conn, smb_fname, dosmode); +} + +static NTSTATUS vfswrap_fset_dos_attributes(struct vfs_handle_struct *handle, + struct files_struct *fsp, + uint32_t dosmode) +{ + return set_ea_dos_attribute(handle->conn, fsp->fsp_name, dosmode); +} + struct vfs_cc_state { off_t copied; uint8_t *buf; @@ -2649,6 +2677,10 @@ static struct vfs_fn_pointers vfs_default_fns = { .strict_unlock_fn = vfswrap_strict_unlock, .translate_name_fn = vfswrap_translate_name, .fsctl_fn = vfswrap_fsctl, + .set_dos_attributes_fn = vfswrap_set_dos_attributes, + .fset_dos_attributes_fn = vfswrap_fset_dos_attributes, + .get_dos_attributes_fn = vfswrap_get_dos_attributes, + .fget_dos_attributes_fn = vfswrap_fget_dos_attributes, .copy_chunk_send_fn = vfswrap_copy_chunk_send, .copy_chunk_recv_fn = vfswrap_copy_chunk_recv, .get_compression_fn = vfswrap_get_compression, diff --git a/source3/modules/vfs_full_audit.c b/source3/modules/vfs_full_audit.c index 691b1e14deb..79c57e8a1b1 100644 --- a/source3/modules/vfs_full_audit.c +++ b/source3/modules/vfs_full_audit.c @@ -175,6 +175,12 @@ typedef enum _vfs_op_type { SMB_VFS_OP_SET_COMPRESSION, SMB_VFS_OP_READDIR_ATTR, + /* DOS attribute operations. */ + SMB_VFS_OP_GET_DOS_ATTRIBUTES, + SMB_VFS_OP_FGET_DOS_ATTRIBUTES, + SMB_VFS_OP_SET_DOS_ATTRIBUTES, + SMB_VFS_OP_FSET_DOS_ATTRIBUTES, + /* NT ACL operations. */ SMB_VFS_OP_FGET_NT_ACL, @@ -301,6 +307,10 @@ static struct { { SMB_VFS_OP_GET_COMPRESSION, "get_compression" }, { SMB_VFS_OP_SET_COMPRESSION, "set_compression" }, { SMB_VFS_OP_READDIR_ATTR, "readdir_attr" }, + { SMB_VFS_OP_GET_DOS_ATTRIBUTES, "get_dos_attributes" }, + { SMB_VFS_OP_FGET_DOS_ATTRIBUTES, "fget_dos_attributes" }, + { SMB_VFS_OP_SET_DOS_ATTRIBUTES, "set_dos_attributes" }, + { SMB_VFS_OP_FSET_DOS_ATTRIBUTES, "fset_dos_attributes" }, { SMB_VFS_OP_FGET_NT_ACL, "fget_nt_acl" }, { SMB_VFS_OP_GET_NT_ACL, "get_nt_acl" }, { SMB_VFS_OP_FSET_NT_ACL, "fset_nt_acl" }, @@ -1895,6 +1905,86 @@ static NTSTATUS smb_full_audit_readdir_attr(struct vfs_handle_struct *handle, return status; } +static NTSTATUS smb_full_audit_get_dos_attributes( + struct vfs_handle_struct *handle, + struct smb_filename *smb_fname, + uint32_t *dosmode) +{ + NTSTATUS status; + + status = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES(handle, + smb_fname, + dosmode); + + do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES, + NT_STATUS_IS_OK(status), + handle, + "%s", + smb_fname_str_do_log(smb_fname)); + + return status; +} + +static NTSTATUS smb_full_audit_fget_dos_attributes( + struct vfs_handle_struct *handle, + struct files_struct *fsp, + uint32_t *dosmode) +{ + NTSTATUS status; + + status = SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle, + fsp, + dosmode); + + do_log(SMB_VFS_OP_FGET_DOS_ATTRIBUTES, + NT_STATUS_IS_OK(status), + handle, + "%s", + fsp_str_do_log(fsp)); + + return status; +} + +static NTSTATUS smb_full_audit_set_dos_attributes( + struct vfs_handle_struct *handle, + const struct smb_filename *smb_fname, + uint32_t dosmode) +{ + NTSTATUS status; + + status = SMB_VFS_NEXT_SET_DOS_ATTRIBUTES(handle, + smb_fname, + dosmode); + + do_log(SMB_VFS_OP_SET_DOS_ATTRIBUTES, + NT_STATUS_IS_OK(status), + handle, + "%s", + smb_fname_str_do_log(smb_fname)); + + return status; +} + +static NTSTATUS smb_full_audit_fset_dos_attributes( + struct vfs_handle_struct *handle, + struct files_struct *fsp, + uint32_t dosmode) +{ + NTSTATUS status; + + status = SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle, + fsp, + dosmode); + + do_log(SMB_VFS_OP_FSET_DOS_ATTRIBUTES, + NT_STATUS_IS_OK(status), + handle, + "%s", + fsp_str_do_log(fsp)); + + return status; +} + static NTSTATUS smb_full_audit_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp, uint32_t security_info, TALLOC_CTX *mem_ctx, @@ -2314,6 +2404,10 @@ static struct vfs_fn_pointers vfs_full_audit_fns = { .get_compression_fn = smb_full_audit_get_compression, .set_compression_fn = smb_full_audit_set_compression, .readdir_attr_fn = smb_full_audit_readdir_attr, + .get_dos_attributes_fn = smb_full_audit_get_dos_attributes, + .fget_dos_attributes_fn = smb_full_audit_fget_dos_attributes, + .set_dos_attributes_fn = smb_full_audit_set_dos_attributes, + .fset_dos_attributes_fn = smb_full_audit_fset_dos_attributes, .fget_nt_acl_fn = smb_full_audit_fget_nt_acl, .get_nt_acl_fn = smb_full_audit_get_nt_acl, .fset_nt_acl_fn = smb_full_audit_fset_nt_acl, diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h index 4be65211d43..8e8cbc34ca3 100644 --- a/source3/smbd/proto.h +++ b/source3/smbd/proto.h @@ -278,6 +278,13 @@ bool set_sticky_write_time_path(struct file_id fileid, struct timespec mtime); bool set_sticky_write_time_fsp(struct files_struct *fsp, struct timespec mtime); +NTSTATUS get_ea_dos_attribute(connection_struct *conn, + struct smb_filename *smb_fname, + uint32_t *pattr); +NTSTATUS set_ea_dos_attribute(connection_struct *conn, + const struct smb_filename *smb_fname, + uint32_t dosmode); + NTSTATUS set_create_timespec_ea(connection_struct *conn, const struct smb_filename *smb_fname, struct timespec create_time); diff --git a/source3/smbd/vfs.c b/source3/smbd/vfs.c index b58becc360c..efed2683a6a 100644 --- a/source3/smbd/vfs.c +++ b/source3/smbd/vfs.c @@ -2202,6 +2202,38 @@ NTSTATUS smb_vfs_call_fsctl(struct vfs_handle_struct *handle, out_len); } +NTSTATUS smb_vfs_call_get_dos_attributes(struct vfs_handle_struct *handle, + struct smb_filename *smb_fname, + uint32_t *dosmode) +{ + VFS_FIND(get_dos_attributes); + return handle->fns->get_dos_attributes_fn(handle, smb_fname, dosmode); +} + +NTSTATUS smb_vfs_call_fget_dos_attributes(struct vfs_handle_struct *handle, + struct files_struct *fsp, + uint32_t *dosmode) +{ + VFS_FIND(fget_dos_attributes); + return handle->fns->fget_dos_attributes_fn(handle, fsp, dosmode); +} + +NTSTATUS smb_vfs_call_set_dos_attributes(struct vfs_handle_struct *handle, + const struct smb_filename *smb_fname, + uint32_t dosmode) +{ + VFS_FIND(set_dos_attributes); + return handle->fns->set_dos_attributes_fn(handle, smb_fname, dosmode); +} + +NTSTATUS smb_vfs_call_fset_dos_attributes(struct vfs_handle_struct *handle, + struct files_struct *fsp, + uint32_t dosmode) +{ + VFS_FIND(set_dos_attributes); + return handle->fns->fset_dos_attributes_fn(handle, fsp, dosmode); +} + struct tevent_req *smb_vfs_call_copy_chunk_send(struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx, struct tevent_context *ev, -- 2.34.1