s3: vfs: Add VFS functions for setting and getting DOS attributes.
authorRichard Sharpe <rsharpe@samba.org>
Sun, 20 Mar 2016 19:51:32 +0000 (12:51 -0700)
committerJeremy Allison <jra@samba.org>
Sun, 27 Mar 2016 03:57:17 +0000 (05:57 +0200)
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 <rsharpe@samba.org>
Signed-off-by: Jeremy Allison <jra@samba.org>
examples/VFS/skel_opaque.c
examples/VFS/skel_transparent.c
source3/include/vfs.h
source3/include/vfs_macros.h
source3/modules/vfs_default.c
source3/modules/vfs_full_audit.c
source3/smbd/proto.h
source3/smbd/vfs.c

index 67c387d83dfd50015d4856ad08ea84685e18878b..81ce1848898ee9efb7f6e454969458b871b811fc 100644 (file)
@@ -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,
index 9fc943819d6b7e937c1797ea9b4308614ebf86e8..418ee24f97eca18cdd39804ba47c3bff805e9e3b 100644 (file)
@@ -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,
index 3a86c627f8144825642e5e74c2f59d48423a5d59..6ab9a7e36b2bb39b9c14be4a4ffca47352f054c9 100644 (file)
 /* 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,
index 6059c2ab1a600ed6136ac89e8bfceaa35cd4a854..c3c9a1716e926611a4b5ea15e724e10144a2407f 100644 (file)
 #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) \
index 41e443e6ca67553beb80be5b737678d25ad0028b..8ee163506b46c0b710d001a40d8fbfa06bf62365 100644 (file)
@@ -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,
index 691b1e14deb070e44a78794a1d76bebbaf250349..79c57e8a1b1d22ed6ce1f8131762d854d8603edd 100644 (file)
@@ -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,
index 4be65211d435bcb3cfbe903c1080ec88f8a12b4d..8e8cbc34ca32a9fafa3d19f17ddc31fcdb7c8775 100644 (file)
@@ -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);
index b58becc360c03ae809327a5f117548b6d7bb82bb..efed2683a6ab992e01212017a0361cc91a2809af 100644 (file)
@@ -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,