From: Noel Power Date: Fri, 7 May 2021 23:11:46 +0000 (-0700) Subject: VFS: Add SMB_VFS_FSTREAMINFO X-Git-Tag: tevent-0.11.0~930 X-Git-Url: http://git.samba.org/?a=commitdiff_plain;h=64af0aeb23ded0917d972701577a18d30fc9df61;p=samba.git VFS: Add SMB_VFS_FSTREAMINFO Signed-off-by: Noel Power Reviewed-by: Jeremy Allison --- diff --git a/examples/VFS/skel_opaque.c b/examples/VFS/skel_opaque.c index 56d2e42d160..ce3672c752f 100644 --- a/examples/VFS/skel_opaque.c +++ b/examples/VFS/skel_opaque.c @@ -638,6 +638,15 @@ static NTSTATUS skel_streaminfo(struct vfs_handle_struct *handle, return NT_STATUS_NOT_IMPLEMENTED; } +static NTSTATUS skel_fstreaminfo(struct vfs_handle_struct *handle, + struct files_struct *fsp, + TALLOC_CTX *mem_ctx, + unsigned int *num_streams, + struct stream_struct **streams) +{ + return NT_STATUS_NOT_IMPLEMENTED; +} + static int skel_get_real_filename(struct vfs_handle_struct *handle, const struct smb_filename *path, const char *name, @@ -1058,6 +1067,7 @@ static struct vfs_fn_pointers skel_opaque_fns = { .set_compression_fn = skel_set_compression, .streaminfo_fn = skel_streaminfo, + .fstreaminfo_fn = skel_fstreaminfo, .get_real_filename_fn = skel_get_real_filename, .connectpath_fn = skel_connectpath, .brl_lock_windows_fn = skel_brl_lock_windows, diff --git a/examples/VFS/skel_transparent.c b/examples/VFS/skel_transparent.c index c5bcc5314d8..02b3c75969f 100644 --- a/examples/VFS/skel_transparent.c +++ b/examples/VFS/skel_transparent.c @@ -855,6 +855,19 @@ static NTSTATUS skel_streaminfo(struct vfs_handle_struct *handle, streams); } +static NTSTATUS skel_fstreaminfo(struct vfs_handle_struct *handle, + struct files_struct *fsp, + TALLOC_CTX *mem_ctx, + unsigned int *num_streams, + struct stream_struct **streams) +{ + return SMB_VFS_NEXT_FSTREAMINFO(handle, + fsp, + mem_ctx, + num_streams, + streams); +} + static int skel_get_real_filename(struct vfs_handle_struct *handle, const struct smb_filename *path, const char *name, @@ -1364,6 +1377,7 @@ static struct vfs_fn_pointers skel_transparent_fns = { .set_compression_fn = skel_set_compression, .streaminfo_fn = skel_streaminfo, + .fstreaminfo_fn = skel_fstreaminfo, .get_real_filename_fn = skel_get_real_filename, .connectpath_fn = skel_connectpath, .brl_lock_windows_fn = skel_brl_lock_windows, diff --git a/source3/include/vfs.h b/source3/include/vfs.h index eaa816d8bec..dfba1cf7608 100644 --- a/source3/include/vfs.h +++ b/source3/include/vfs.h @@ -349,6 +349,7 @@ * Version 45 - Remove SMB_VFS_CHMOD * Version 45 - Add SMB_VFS_FNTIMES * Version 45 - Remove SMB_VFS_NTIMES + * Version 45 - ADD SMB_VFS_FSTREAMINFO */ #define SMB_VFS_INTERFACE_VERSION 45 @@ -1119,6 +1120,12 @@ struct vfs_fn_pointers { unsigned int *num_streams, struct stream_struct **streams); + NTSTATUS (*fstreaminfo_fn)(struct vfs_handle_struct *handle, + struct files_struct *fsp, + TALLOC_CTX *mem_ctx, + unsigned int *num_streams, + struct stream_struct **streams); + int (*get_real_filename_fn)(struct vfs_handle_struct *handle, const struct smb_filename *path, const char *name, @@ -1592,6 +1599,11 @@ NTSTATUS smb_vfs_call_streaminfo(struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx, unsigned int *num_streams, struct stream_struct **streams); +NTSTATUS smb_vfs_call_fstreaminfo(struct vfs_handle_struct *handle, + struct files_struct *fsp, + TALLOC_CTX *mem_ctx, + unsigned int *num_streams, + struct stream_struct **streams); int smb_vfs_call_get_real_filename(struct vfs_handle_struct *handle, const struct smb_filename *path, const char *name, @@ -2053,6 +2065,11 @@ NTSTATUS vfs_not_implemented_streaminfo(struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx, unsigned int *num_streams, struct stream_struct **streams); +NTSTATUS vfs_not_implemented_fstreaminfo(struct vfs_handle_struct *handle, + struct files_struct *fsp, + TALLOC_CTX *mem_ctx, + unsigned int *num_streams, + struct stream_struct **streams); int vfs_not_implemented_get_real_filename(struct vfs_handle_struct *handle, const struct smb_filename *path, const char *name, diff --git a/source3/include/vfs_macros.h b/source3/include/vfs_macros.h index 40ff68aedab..3769593c2e4 100644 --- a/source3/include/vfs_macros.h +++ b/source3/include/vfs_macros.h @@ -353,6 +353,11 @@ #define SMB_VFS_NEXT_STREAMINFO(handle, fsp, smb_fname, mem_ctx, num_streams, streams) \ smb_vfs_call_streaminfo((handle)->next, (fsp), (smb_fname), (mem_ctx), (num_streams), (streams)) +#define SMB_VFS_FSTREAMINFO(fsp, mem_ctx, num_streams, streams) \ + smb_vfs_call_fstreaminfo((fsp)->conn->vfs_handles, (fsp), (mem_ctx), (num_streams), (streams)) +#define SMB_VFS_NEXT_FSTREAMINFO(handle, fsp, mem_ctx, num_streams, streams) \ + smb_vfs_call_fstreaminfo(handle->next, (fsp), (mem_ctx), (num_streams), (streams)) + #define SMB_VFS_GET_REAL_FILENAME(conn, path, name, mem_ctx, found_name) \ smb_vfs_call_get_real_filename((conn)->vfs_handles, (path), (name), (mem_ctx), (found_name)) #define SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name, mem_ctx, found_name) \ diff --git a/source3/modules/vfs_default.c b/source3/modules/vfs_default.c index 1bb927f5a47..a5fee959dc8 100644 --- a/source3/modules/vfs_default.c +++ b/source3/modules/vfs_default.c @@ -3081,6 +3081,57 @@ static NTSTATUS vfswrap_streaminfo(vfs_handle_struct *handle, return NT_STATUS_OK; } +static NTSTATUS vfswrap_fstreaminfo(vfs_handle_struct *handle, + struct files_struct *fsp, + TALLOC_CTX *mem_ctx, + unsigned int *pnum_streams, + struct stream_struct **pstreams) +{ + struct stream_struct *tmp_streams = NULL; + unsigned int num_streams = *pnum_streams; + struct stream_struct *streams = *pstreams; + NTSTATUS status; + + if (fsp->fsp_flags.is_directory) { + /* + * No default streams on directories + */ + goto done; + } + status = vfs_stat_fsp(fsp); + if (!NT_STATUS_IS_OK(status)) { + return status; + } + + if (num_streams + 1 < 1) { + /* Integer wrap. */ + return NT_STATUS_INVALID_PARAMETER; + } + + tmp_streams = talloc_realloc(mem_ctx, + streams, + struct stream_struct, + num_streams + 1); + if (tmp_streams == NULL) { + return NT_STATUS_NO_MEMORY; + } + tmp_streams[num_streams].name = talloc_strdup(tmp_streams, "::$DATA"); + if (tmp_streams[num_streams].name == NULL) { + return NT_STATUS_NO_MEMORY; + } + tmp_streams[num_streams].size = fsp->fsp_name->st.st_ex_size; + tmp_streams[num_streams].alloc_size = SMB_VFS_GET_ALLOC_SIZE( + handle->conn, + fsp, + &fsp->fsp_name->st); + num_streams += 1; + + *pnum_streams = num_streams; + *pstreams = tmp_streams; + done: + return NT_STATUS_OK; +} + static int vfswrap_get_real_filename(struct vfs_handle_struct *handle, const struct smb_filename *path, const char *name, @@ -3828,6 +3879,7 @@ static struct vfs_fn_pointers vfs_default_fns = { .file_id_create_fn = vfswrap_file_id_create, .fs_file_id_fn = vfswrap_fs_file_id, .streaminfo_fn = vfswrap_streaminfo, + .fstreaminfo_fn = vfswrap_fstreaminfo, .get_real_filename_fn = vfswrap_get_real_filename, .connectpath_fn = vfswrap_connectpath, .brl_lock_windows_fn = vfswrap_brl_lock_windows, diff --git a/source3/modules/vfs_full_audit.c b/source3/modules/vfs_full_audit.c index 060fecfba40..f52a519e68d 100644 --- a/source3/modules/vfs_full_audit.c +++ b/source3/modules/vfs_full_audit.c @@ -164,6 +164,7 @@ typedef enum _vfs_op_type { SMB_VFS_OP_FILE_ID_CREATE, SMB_VFS_OP_FS_FILE_ID, SMB_VFS_OP_STREAMINFO, + SMB_VFS_OP_FSTREAMINFO, SMB_VFS_OP_GET_REAL_FILENAME, SMB_VFS_OP_CONNECTPATH, SMB_VFS_OP_BRL_LOCK_WINDOWS, @@ -303,6 +304,7 @@ static struct { { SMB_VFS_OP_FILE_ID_CREATE, "file_id_create" }, { SMB_VFS_OP_FS_FILE_ID, "fs_file_id" }, { SMB_VFS_OP_STREAMINFO, "streaminfo" }, + { SMB_VFS_OP_FSTREAMINFO, "fstreaminfo" }, { SMB_VFS_OP_GET_REAL_FILENAME, "get_real_filename" }, { SMB_VFS_OP_CONNECTPATH, "connectpath" }, { SMB_VFS_OP_BRL_LOCK_WINDOWS, "brl_lock_windows" }, @@ -2005,7 +2007,6 @@ static uint64_t smb_full_audit_fs_file_id(struct vfs_handle_struct *handle, return result; } - static NTSTATUS smb_full_audit_streaminfo(vfs_handle_struct *handle, struct files_struct *fsp, const struct smb_filename *smb_fname, @@ -2027,6 +2028,26 @@ static NTSTATUS smb_full_audit_streaminfo(vfs_handle_struct *handle, return result; } +static NTSTATUS smb_full_audit_fstreaminfo(vfs_handle_struct *handle, + struct files_struct *fsp, + TALLOC_CTX *mem_ctx, + unsigned int *pnum_streams, + struct stream_struct **pstreams) +{ + NTSTATUS result; + + result = SMB_VFS_NEXT_FSTREAMINFO(handle, fsp, mem_ctx, + pnum_streams, pstreams); + + do_log(SMB_VFS_OP_FSTREAMINFO, + NT_STATUS_IS_OK(result), + handle, + "%s", + smb_fname_str_do_log(handle->conn, fsp->fsp_name)); + + return result; +} + static int smb_full_audit_get_real_filename(struct vfs_handle_struct *handle, const struct smb_filename *path, const char *name, @@ -2982,6 +3003,7 @@ static struct vfs_fn_pointers vfs_full_audit_fns = { .snap_create_fn = smb_full_audit_snap_create, .snap_delete_fn = smb_full_audit_snap_delete, .streaminfo_fn = smb_full_audit_streaminfo, + .fstreaminfo_fn = smb_full_audit_fstreaminfo, .get_real_filename_fn = smb_full_audit_get_real_filename, .connectpath_fn = smb_full_audit_connectpath, .brl_lock_windows_fn = smb_full_audit_brl_lock_windows, diff --git a/source3/modules/vfs_not_implemented.c b/source3/modules/vfs_not_implemented.c index 1b76427dc75..230ae35ca05 100644 --- a/source3/modules/vfs_not_implemented.c +++ b/source3/modules/vfs_not_implemented.c @@ -640,6 +640,15 @@ NTSTATUS vfs_not_implemented_streaminfo(struct vfs_handle_struct *handle, return NT_STATUS_NOT_IMPLEMENTED; } +NTSTATUS vfs_not_implemented_fstreaminfo(struct vfs_handle_struct *handle, + struct files_struct *fsp, + TALLOC_CTX *mem_ctx, + unsigned int *num_streams, + struct stream_struct **streams) +{ + return NT_STATUS_NOT_IMPLEMENTED; +} + int vfs_not_implemented_get_real_filename(struct vfs_handle_struct *handle, const struct smb_filename *path, const char *name, @@ -1062,6 +1071,7 @@ static struct vfs_fn_pointers vfs_not_implemented_fns = { .set_compression_fn = vfs_not_implemented_set_compression, .streaminfo_fn = vfs_not_implemented_streaminfo, + .fstreaminfo_fn = vfs_not_implemented_fstreaminfo, .get_real_filename_fn = vfs_not_implemented_get_real_filename, .connectpath_fn = vfs_not_implemented_connectpath, .brl_lock_windows_fn = vfs_not_implemented_brl_lock_windows, diff --git a/source3/modules/vfs_time_audit.c b/source3/modules/vfs_time_audit.c index 5b08ce94935..c2bf905a152 100644 --- a/source3/modules/vfs_time_audit.c +++ b/source3/modules/vfs_time_audit.c @@ -1669,6 +1669,29 @@ static NTSTATUS smb_time_audit_streaminfo(vfs_handle_struct *handle, return result; } +static NTSTATUS smb_time_audit_fstreaminfo(vfs_handle_struct *handle, + struct files_struct *fsp, + TALLOC_CTX *mem_ctx, + unsigned int *pnum_streams, + struct stream_struct **pstreams) +{ + NTSTATUS result; + struct timespec ts1,ts2; + double timediff; + + clock_gettime_mono(&ts1); + result = SMB_VFS_NEXT_FSTREAMINFO(handle, fsp, mem_ctx, + pnum_streams, pstreams); + clock_gettime_mono(&ts2); + timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9; + + if (timediff > audit_timeout) { + smb_time_audit_log_fsp("fstreaminfo", timediff, fsp); + } + + return result; +} + static int smb_time_audit_get_real_filename(struct vfs_handle_struct *handle, const struct smb_filename *path, const char *name, @@ -2817,6 +2840,7 @@ static struct vfs_fn_pointers vfs_time_audit_fns = { .snap_create_fn = smb_time_audit_snap_create, .snap_delete_fn = smb_time_audit_snap_delete, .streaminfo_fn = smb_time_audit_streaminfo, + .fstreaminfo_fn = smb_time_audit_fstreaminfo, .get_real_filename_fn = smb_time_audit_get_real_filename, .connectpath_fn = smb_time_audit_connectpath, .brl_lock_windows_fn = smb_time_audit_brl_lock_windows, diff --git a/source3/smbd/vfs.c b/source3/smbd/vfs.c index d081a8935bf..9104db06690 100644 --- a/source3/smbd/vfs.c +++ b/source3/smbd/vfs.c @@ -2399,6 +2399,17 @@ NTSTATUS smb_vfs_call_streaminfo(struct vfs_handle_struct *handle, num_streams, streams); } +NTSTATUS smb_vfs_call_fstreaminfo(struct vfs_handle_struct *handle, + struct files_struct *fsp, + TALLOC_CTX *mem_ctx, + unsigned int *num_streams, + struct stream_struct **streams) +{ + VFS_FIND(fstreaminfo); + return handle->fns->fstreaminfo_fn(handle, fsp, mem_ctx, + num_streams, streams); +} + int smb_vfs_call_get_real_filename(struct vfs_handle_struct *handle, const struct smb_filename *path, const char *name,