From: Ralph Boehme Date: Sat, 29 Jun 2019 12:08:04 +0000 (+0200) Subject: s3:vfs: add SMB_VFS_FS_FILE_ID() X-Git-Tag: ldb-2.0.5~102 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=71996fef09f28fba39637acb86a51b5e0c1da36b;p=thirdparty%2Fsamba.git s3:vfs: add SMB_VFS_FS_FILE_ID() Not yet used, that comes next. Signed-off-by: Ralph Boehme Reviewed-by: Jeremy Allison --- diff --git a/examples/VFS/skel_opaque.c b/examples/VFS/skel_opaque.c index 6628bffe3eb..4e4475a11e8 100644 --- a/examples/VFS/skel_opaque.c +++ b/examples/VFS/skel_opaque.c @@ -513,6 +513,13 @@ static struct file_id skel_file_id_create(vfs_handle_struct *handle, return id; } +static uint64_t skel_fs_file_id(vfs_handle_struct *handle, + const SMB_STRUCT_STAT *sbuf) +{ + errno = ENOSYS; + return 0; +} + struct skel_offload_read_state { bool dummy; }; @@ -1084,6 +1091,7 @@ static struct vfs_fn_pointers skel_opaque_fns = { .realpath_fn = skel_realpath, .chflags_fn = skel_chflags, .file_id_create_fn = skel_file_id_create, + .fs_file_id_fn = skel_fs_file_id, .offload_read_send_fn = skel_offload_read_send, .offload_read_recv_fn = skel_offload_read_recv, .offload_write_send_fn = skel_offload_write_send, diff --git a/examples/VFS/skel_transparent.c b/examples/VFS/skel_transparent.c index 9b5f336042e..ac2665ef07b 100644 --- a/examples/VFS/skel_transparent.c +++ b/examples/VFS/skel_transparent.c @@ -600,6 +600,12 @@ static struct file_id skel_file_id_create(vfs_handle_struct *handle, return SMB_VFS_NEXT_FILE_ID_CREATE(handle, sbuf); } +static uint64_t skel_fs_file_id(vfs_handle_struct *handle, + const SMB_STRUCT_STAT *sbuf) +{ + return SMB_VFS_NEXT_FS_FILE_ID(handle, sbuf); +} + struct skel_offload_read_state { struct vfs_handle_struct *handle; DATA_BLOB token; @@ -1348,6 +1354,7 @@ static struct vfs_fn_pointers skel_transparent_fns = { .realpath_fn = skel_realpath, .chflags_fn = skel_chflags, .file_id_create_fn = skel_file_id_create, + .fs_file_id_fn = skel_fs_file_id, .offload_read_send_fn = skel_offload_read_send, .offload_read_recv_fn = skel_offload_read_recv, .offload_write_send_fn = skel_offload_write_send, diff --git a/source3/include/vfs.h b/source3/include/vfs.h index 33c54c884cd..56f4b9dd1f8 100644 --- a/source3/include/vfs.h +++ b/source3/include/vfs.h @@ -265,6 +265,7 @@ /* Version 41 - convert struct stat_ex.st_ex_calculated_birthtime to flags */ /* Version 41 - add st_ex_itime to struct stat_ex */ /* Version 41 - add st_ex_file_id to struct stat_ex */ +/* Version 41 - add SMB_VFS_FS_FILE_ID */ #define SMB_VFS_INTERFACE_VERSION 41 @@ -800,6 +801,8 @@ struct vfs_fn_pointers { unsigned int flags); struct file_id (*file_id_create_fn)(struct vfs_handle_struct *handle, const SMB_STRUCT_STAT *sbuf); + uint64_t (*fs_file_id_fn)(struct vfs_handle_struct *handle, + const SMB_STRUCT_STAT *sbuf); struct tevent_req *(*offload_read_send_fn)(TALLOC_CTX *mem_ctx, struct tevent_context *ev, struct vfs_handle_struct *handle, @@ -1327,6 +1330,8 @@ int smb_vfs_call_chflags(struct vfs_handle_struct *handle, unsigned int flags); struct file_id smb_vfs_call_file_id_create(struct vfs_handle_struct *handle, const SMB_STRUCT_STAT *sbuf); +uint64_t smb_vfs_call_fs_file_id(struct vfs_handle_struct *handle, + const SMB_STRUCT_STAT *sbuf); NTSTATUS smb_vfs_call_streaminfo(struct vfs_handle_struct *handle, struct files_struct *fsp, const struct smb_filename *smb_fname, @@ -1751,6 +1756,8 @@ int vfs_not_implemented_chflags(vfs_handle_struct *handle, uint flags); struct file_id vfs_not_implemented_file_id_create(vfs_handle_struct *handle, const SMB_STRUCT_STAT *sbuf); +uint64_t vfs_not_implemented_fs_file_id(vfs_handle_struct *handle, + const SMB_STRUCT_STAT *sbuf); struct tevent_req *vfs_not_implemented_offload_read_send( TALLOC_CTX *mem_ctx, struct tevent_context *ev, diff --git a/source3/include/vfs_macros.h b/source3/include/vfs_macros.h index e867810f30f..c4fa0fe022e 100644 --- a/source3/include/vfs_macros.h +++ b/source3/include/vfs_macros.h @@ -331,6 +331,11 @@ #define SMB_VFS_NEXT_FILE_ID_CREATE(handle, sbuf) \ smb_vfs_call_file_id_create((handle)->next, (sbuf)) +#define SMB_VFS_FS_FILE_ID(conn, sbuf) \ + smb_vfs_call_fs_file_id((conn)->vfs_handles, (sbuf)) +#define SMB_VFS_NEXT_FS_FILE_ID(handle, sbuf) \ + smb_vfs_call_fs_file_id((handle)->next, (sbuf)) + #define SMB_VFS_STREAMINFO(conn, fsp, smb_fname, mem_ctx, num_streams, streams) \ smb_vfs_call_streaminfo((conn)->vfs_handles, (fsp), (smb_fname), (mem_ctx), (num_streams), (streams)) #define SMB_VFS_NEXT_STREAMINFO(handle, fsp, smb_fname, mem_ctx, num_streams, streams) \ diff --git a/source3/modules/vfs_full_audit.c b/source3/modules/vfs_full_audit.c index 8c4dc44dc5d..b20bca0a528 100644 --- a/source3/modules/vfs_full_audit.c +++ b/source3/modules/vfs_full_audit.c @@ -158,6 +158,7 @@ typedef enum _vfs_op_type { SMB_VFS_OP_REALPATH, SMB_VFS_OP_CHFLAGS, SMB_VFS_OP_FILE_ID_CREATE, + SMB_VFS_OP_FS_FILE_ID, SMB_VFS_OP_STREAMINFO, SMB_VFS_OP_GET_REAL_FILENAME, SMB_VFS_OP_CONNECTPATH, @@ -300,6 +301,7 @@ static struct { { SMB_VFS_OP_REALPATH, "realpath" }, { SMB_VFS_OP_CHFLAGS, "chflags" }, { 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_GET_REAL_FILENAME, "get_real_filename" }, { SMB_VFS_OP_CONNECTPATH, "connectpath" }, @@ -1820,6 +1822,20 @@ static struct file_id smb_full_audit_file_id_create(struct vfs_handle_struct *ha return result; } +static uint64_t smb_full_audit_fs_file_id(struct vfs_handle_struct *handle, + const SMB_STRUCT_STAT *sbuf) +{ + uint64_t result; + + result = SMB_VFS_NEXT_FS_FILE_ID(handle, sbuf); + + do_log(SMB_VFS_OP_FS_FILE_ID, + result != 0, + handle, "%" PRIu64, result); + + return result; +} + static NTSTATUS smb_full_audit_streaminfo(vfs_handle_struct *handle, struct files_struct *fsp, const struct smb_filename *smb_fname, @@ -2864,6 +2880,7 @@ static struct vfs_fn_pointers vfs_full_audit_fns = { .realpath_fn = smb_full_audit_realpath, .chflags_fn = smb_full_audit_chflags, .file_id_create_fn = smb_full_audit_file_id_create, + .fs_file_id_fn = smb_full_audit_fs_file_id, .offload_read_send_fn = smb_full_audit_offload_read_send, .offload_read_recv_fn = smb_full_audit_offload_read_recv, .offload_write_send_fn = smb_full_audit_offload_write_send, diff --git a/source3/modules/vfs_not_implemented.c b/source3/modules/vfs_not_implemented.c index d3aca899067..aa7068ed073 100644 --- a/source3/modules/vfs_not_implemented.c +++ b/source3/modules/vfs_not_implemented.c @@ -511,6 +511,13 @@ struct file_id vfs_not_implemented_file_id_create(vfs_handle_struct *handle, return id; } +uint64_t vfs_not_implemented_fs_file_id(vfs_handle_struct *handle, + const SMB_STRUCT_STAT *sbuf) +{ + errno = ENOSYS; + return 0; +} + struct vfs_not_implemented_offload_read_state { bool dummy; }; @@ -1088,6 +1095,7 @@ static struct vfs_fn_pointers vfs_not_implemented_fns = { .realpath_fn = vfs_not_implemented_realpath, .chflags_fn = vfs_not_implemented_chflags, .file_id_create_fn = vfs_not_implemented_file_id_create, + .fs_file_id_fn = vfs_not_implemented_fs_file_id, .offload_read_send_fn = vfs_not_implemented_offload_read_send, .offload_read_recv_fn = vfs_not_implemented_offload_read_recv, .offload_write_send_fn = vfs_not_implemented_offload_write_send, diff --git a/source3/modules/vfs_time_audit.c b/source3/modules/vfs_time_audit.c index 96847a4fde9..8e1c794c037 100644 --- a/source3/modules/vfs_time_audit.c +++ b/source3/modules/vfs_time_audit.c @@ -1520,6 +1520,25 @@ static struct file_id smb_time_audit_file_id_create(struct vfs_handle_struct *ha return result; } +static uint64_t smb_time_audit_fs_file_id(struct vfs_handle_struct *handle, + const SMB_STRUCT_STAT *sbuf) +{ + uint64_t result; + struct timespec ts1,ts2; + double timediff; + + clock_gettime_mono(&ts1); + result = SMB_VFS_NEXT_FS_FILE_ID(handle, sbuf); + clock_gettime_mono(&ts2); + timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9; + + if (timediff > audit_timeout) { + smb_time_audit_log("fs_file_id", timediff); + } + + return result; +} + static NTSTATUS smb_time_audit_streaminfo(vfs_handle_struct *handle, struct files_struct *fsp, const struct smb_filename *smb_fname, @@ -2824,6 +2843,7 @@ static struct vfs_fn_pointers vfs_time_audit_fns = { .realpath_fn = smb_time_audit_realpath, .chflags_fn = smb_time_audit_chflags, .file_id_create_fn = smb_time_audit_file_id_create, + .fs_file_id_fn = smb_time_audit_fs_file_id, .offload_read_send_fn = smb_time_audit_offload_read_send, .offload_read_recv_fn = smb_time_audit_offload_read_recv, .offload_write_send_fn = smb_time_audit_offload_write_send, diff --git a/source3/smbd/vfs.c b/source3/smbd/vfs.c index d3bb9c5d63f..51a4aeb0f22 100644 --- a/source3/smbd/vfs.c +++ b/source3/smbd/vfs.c @@ -2237,6 +2237,13 @@ struct file_id smb_vfs_call_file_id_create(struct vfs_handle_struct *handle, return handle->fns->file_id_create_fn(handle, sbuf); } +uint64_t smb_vfs_call_fs_file_id(struct vfs_handle_struct *handle, + const SMB_STRUCT_STAT *sbuf) +{ + VFS_FIND(fs_file_id); + return handle->fns->fs_file_id_fn(handle, sbuf); +} + NTSTATUS smb_vfs_call_streaminfo(struct vfs_handle_struct *handle, struct files_struct *fsp, const struct smb_filename *smb_fname,