2 * Time auditing VFS module for samba. Log time taken for VFS call to syslog
5 * Copyright (C) Abhidnya Chirmule <achirmul@in.ibm.com> 2009
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, see <http://www.gnu.org/licenses/>.
22 * This module implements logging for time taken for all Samba VFS operations.
24 * vfs objects = time_audit
29 #include "smbd/smbd.h"
31 #include "lib/util/tevent_unix.h"
32 #include "lib/util/tevent_ntstatus.h"
35 #define DBGC_CLASS DBGC_VFS
37 static double audit_timeout;
39 static void smb_time_audit_log_msg(const char *syscallname, double elapsed,
42 DEBUG(0, ("WARNING: VFS call \"%s\" took unexpectedly long "
43 "(%.2f seconds) %s%s-- Validate that file and storage "
44 "subsystems are operating normally\n", syscallname,
45 elapsed, (msg != NULL) ? msg : "",
46 (msg != NULL) ? " " : ""));
49 static void smb_time_audit_log(const char *syscallname, double elapsed)
51 smb_time_audit_log_msg(syscallname, elapsed, NULL);
54 static void smb_time_audit_log_fsp(const char *syscallname, double elapsed,
55 const struct files_struct *fsp)
57 char *base_name = NULL;
58 char *connectpath = NULL;
62 smb_time_audit_log(syscallname, elapsed);
66 connectpath = fsp->conn->connectpath;
68 base_name = fsp->fsp_name->base_name;
70 if (connectpath != NULL && base_name != NULL) {
71 msg = talloc_asprintf(talloc_tos(), "filename = \"%s/%s\"",
72 connectpath, base_name);
73 } else if (connectpath != NULL && base_name == NULL) {
74 msg = talloc_asprintf(talloc_tos(), "connectpath = \"%s\", "
77 } else if (connectpath == NULL && base_name != NULL) {
78 msg = talloc_asprintf(talloc_tos(), "connectpath = <NULL>, "
81 } else { /* connectpath == NULL && base_name == NULL */
82 msg = talloc_asprintf(talloc_tos(), "connectpath = <NULL>, "
83 "base_name = <NULL>");
85 smb_time_audit_log_msg(syscallname, elapsed, msg);
89 static void smb_time_audit_log_at(const char *syscallname,
91 const struct files_struct *dir_fsp,
92 const struct smb_filename *smb_fname)
96 msg = talloc_asprintf(talloc_tos(),
97 "filename = \"%s/%s/%s\"",
98 dir_fsp->conn->connectpath,
99 dir_fsp->fsp_name->base_name,
100 smb_fname->base_name);
102 smb_time_audit_log_msg(syscallname, elapsed, msg);
106 static void smb_time_audit_log_fname(const char *syscallname, double elapsed,
112 if (getcwd(cwd, sizeof(cwd)) == NULL) {
113 snprintf(cwd, sizeof(cwd), "<getcwd() error %d>", errno);
116 msg = talloc_asprintf(talloc_tos(),
117 "cwd = \"%s\", filename = \"%s\"",
120 msg = talloc_asprintf(talloc_tos(),
121 "cwd = \"%s\", filename = <NULL>",
124 smb_time_audit_log_msg(syscallname, elapsed, msg);
128 static void smb_time_audit_log_smb_fname(const char *syscallname, double elapsed,
129 const struct smb_filename *smb_fname)
131 if (smb_fname != NULL) {
132 smb_time_audit_log_fname(syscallname, elapsed,
133 smb_fname->base_name);
135 smb_time_audit_log_fname(syscallname, elapsed,
136 "smb_fname = <NULL>");
140 static int smb_time_audit_connect(vfs_handle_struct *handle,
141 const char *svc, const char *user)
144 struct timespec ts1,ts2;
151 clock_gettime_mono(&ts1);
152 result = SMB_VFS_NEXT_CONNECT(handle, svc, user);
153 clock_gettime_mono(&ts2);
154 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
155 if (timediff > audit_timeout) {
156 smb_time_audit_log_msg("connect", timediff, user);
161 static void smb_time_audit_disconnect(vfs_handle_struct *handle)
163 struct timespec ts1,ts2;
166 clock_gettime_mono(&ts1);
167 SMB_VFS_NEXT_DISCONNECT(handle);
168 clock_gettime_mono(&ts2);
169 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
171 if (timediff > audit_timeout) {
172 smb_time_audit_log("disconnect", timediff);
176 static uint64_t smb_time_audit_disk_free(vfs_handle_struct *handle,
177 const struct smb_filename *smb_fname,
183 struct timespec ts1,ts2;
186 clock_gettime_mono(&ts1);
187 result = SMB_VFS_NEXT_DISK_FREE(handle, smb_fname, bsize, dfree, dsize);
188 clock_gettime_mono(&ts2);
189 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
191 /* Don't have a reasonable notion of failure here */
192 if (timediff > audit_timeout) {
193 smb_time_audit_log_fname("disk_free",
195 smb_fname->base_name);
201 static int smb_time_audit_get_quota(struct vfs_handle_struct *handle,
202 const struct smb_filename *smb_fname,
203 enum SMB_QUOTA_TYPE qtype,
208 struct timespec ts1,ts2;
211 clock_gettime_mono(&ts1);
212 result = SMB_VFS_NEXT_GET_QUOTA(handle, smb_fname, qtype, id, qt);
213 clock_gettime_mono(&ts2);
214 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
216 if (timediff > audit_timeout) {
217 smb_time_audit_log_fname("get_quota",
219 smb_fname->base_name);
224 static int smb_time_audit_set_quota(struct vfs_handle_struct *handle,
225 enum SMB_QUOTA_TYPE qtype, unid_t id,
229 struct timespec ts1,ts2;
232 clock_gettime_mono(&ts1);
233 result = SMB_VFS_NEXT_SET_QUOTA(handle, qtype, id, qt);
234 clock_gettime_mono(&ts2);
235 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
237 if (timediff > audit_timeout) {
238 smb_time_audit_log("set_quota", timediff);
244 static int smb_time_audit_get_shadow_copy_data(struct vfs_handle_struct *handle,
245 struct files_struct *fsp,
246 struct shadow_copy_data *shadow_copy_data,
250 struct timespec ts1,ts2;
253 clock_gettime_mono(&ts1);
254 result = SMB_VFS_NEXT_GET_SHADOW_COPY_DATA(handle, fsp,
255 shadow_copy_data, labels);
256 clock_gettime_mono(&ts2);
257 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
259 if (timediff > audit_timeout) {
260 smb_time_audit_log_fsp("get_shadow_copy_data", timediff, fsp);
266 static int smb_time_audit_statvfs(struct vfs_handle_struct *handle,
267 const struct smb_filename *smb_fname,
268 struct vfs_statvfs_struct *statbuf)
271 struct timespec ts1,ts2;
274 clock_gettime_mono(&ts1);
275 result = SMB_VFS_NEXT_STATVFS(handle, smb_fname, statbuf);
276 clock_gettime_mono(&ts2);
277 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
279 if (timediff > audit_timeout) {
280 smb_time_audit_log_fname("statvfs", timediff,
281 smb_fname->base_name);
287 static uint32_t smb_time_audit_fs_capabilities(struct vfs_handle_struct *handle,
288 enum timestamp_set_resolution *p_ts_res)
291 struct timespec ts1,ts2;
294 clock_gettime_mono(&ts1);
295 result = SMB_VFS_NEXT_FS_CAPABILITIES(handle, p_ts_res);
296 clock_gettime_mono(&ts2);
297 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
299 if (timediff > audit_timeout) {
300 smb_time_audit_log("fs_capabilities", timediff);
306 static NTSTATUS smb_time_audit_get_dfs_referrals(
307 struct vfs_handle_struct *handle,
308 struct dfs_GetDFSReferral *r)
311 struct timespec ts1,ts2;
314 clock_gettime_mono(&ts1);
315 result = SMB_VFS_NEXT_GET_DFS_REFERRALS(handle, r);
316 clock_gettime_mono(&ts2);
317 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
319 if (timediff > audit_timeout) {
320 smb_time_audit_log("get_dfs_referrals", timediff);
326 static NTSTATUS smb_time_audit_create_dfs_pathat(struct vfs_handle_struct *handle,
327 struct files_struct *dirfsp,
328 const struct smb_filename *smb_fname,
329 const struct referral *reflist,
330 size_t referral_count)
333 struct timespec ts1,ts2;
335 struct smb_filename *full_fname = NULL;
337 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
340 if (full_fname == NULL) {
341 return NT_STATUS_NO_MEMORY;
344 clock_gettime_mono(&ts1);
345 result = SMB_VFS_NEXT_CREATE_DFS_PATHAT(handle,
350 clock_gettime_mono(&ts2);
351 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
353 if (timediff > audit_timeout) {
354 smb_time_audit_log_smb_fname("create_dfs_pathat",
358 TALLOC_FREE(full_fname);
362 static NTSTATUS smb_time_audit_read_dfs_pathat(struct vfs_handle_struct *handle,
364 struct files_struct *dirfsp,
365 struct smb_filename *smb_fname,
366 struct referral **ppreflist,
367 size_t *preferral_count)
370 struct timespec ts1,ts2;
373 clock_gettime_mono(&ts1);
374 result = SMB_VFS_NEXT_READ_DFS_PATHAT(handle,
380 clock_gettime_mono(&ts2);
381 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
383 if (timediff > audit_timeout) {
384 smb_time_audit_log("read_dfs_pathat", timediff);
390 static NTSTATUS smb_time_audit_snap_check_path(struct vfs_handle_struct *handle,
392 const char *service_path,
396 struct timespec ts1,ts2;
399 clock_gettime_mono(&ts1);
400 status = SMB_VFS_NEXT_SNAP_CHECK_PATH(handle, mem_ctx, service_path,
402 clock_gettime_mono(&ts2);
403 timediff = nsec_time_diff(&ts2, &ts1) * 1.0e-9;
405 if (timediff > audit_timeout) {
406 smb_time_audit_log("snap_check_path", timediff);
412 static NTSTATUS smb_time_audit_snap_create(struct vfs_handle_struct *handle,
414 const char *base_volume,
421 struct timespec ts1,ts2;
424 clock_gettime_mono(&ts1);
425 status = SMB_VFS_NEXT_SNAP_CREATE(handle, mem_ctx, base_volume, tstamp,
426 rw, base_path, snap_path);
427 clock_gettime_mono(&ts2);
428 timediff = nsec_time_diff(&ts2 ,&ts1) * 1.0e-9;
430 if (timediff > audit_timeout) {
431 smb_time_audit_log("snap_create", timediff);
437 static NTSTATUS smb_time_audit_snap_delete(struct vfs_handle_struct *handle,
443 struct timespec ts1,ts2;
446 clock_gettime_mono(&ts1);
447 status = SMB_VFS_NEXT_SNAP_DELETE(handle, mem_ctx, base_path,
449 clock_gettime_mono(&ts2);
450 timediff = nsec_time_diff(&ts2, &ts1) * 1.0e-9;
452 if (timediff > audit_timeout) {
453 smb_time_audit_log("snap_delete", timediff);
459 static DIR *smb_time_audit_fdopendir(vfs_handle_struct *handle,
461 const char *mask, uint32_t attr)
464 struct timespec ts1,ts2;
467 clock_gettime_mono(&ts1);
468 result = SMB_VFS_NEXT_FDOPENDIR(handle, fsp, mask, attr);
469 clock_gettime_mono(&ts2);
470 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
472 if (timediff > audit_timeout) {
473 smb_time_audit_log_fsp("fdopendir", timediff, fsp);
479 static struct dirent *smb_time_audit_readdir(vfs_handle_struct *handle,
480 struct files_struct *dirfsp,
482 SMB_STRUCT_STAT *sbuf)
484 struct dirent *result;
485 struct timespec ts1,ts2;
488 clock_gettime_mono(&ts1);
489 result = SMB_VFS_NEXT_READDIR(handle, dirfsp, dirp, sbuf);
490 clock_gettime_mono(&ts2);
491 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
493 if (timediff > audit_timeout) {
494 smb_time_audit_log("readdir", timediff);
500 static void smb_time_audit_seekdir(vfs_handle_struct *handle,
501 DIR *dirp, long offset)
503 struct timespec ts1,ts2;
506 clock_gettime_mono(&ts1);
507 SMB_VFS_NEXT_SEEKDIR(handle, dirp, offset);
508 clock_gettime_mono(&ts2);
509 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
511 if (timediff > audit_timeout) {
512 smb_time_audit_log("seekdir", timediff);
517 static long smb_time_audit_telldir(vfs_handle_struct *handle,
521 struct timespec ts1,ts2;
524 clock_gettime_mono(&ts1);
525 result = SMB_VFS_NEXT_TELLDIR(handle, dirp);
526 clock_gettime_mono(&ts2);
527 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
529 if (timediff > audit_timeout) {
530 smb_time_audit_log("telldir", timediff);
536 static void smb_time_audit_rewinddir(vfs_handle_struct *handle,
539 struct timespec ts1,ts2;
542 clock_gettime_mono(&ts1);
543 SMB_VFS_NEXT_REWINDDIR(handle, dirp);
544 clock_gettime_mono(&ts2);
545 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
547 if (timediff > audit_timeout) {
548 smb_time_audit_log("rewinddir", timediff);
553 static int smb_time_audit_mkdirat(vfs_handle_struct *handle,
554 struct files_struct *dirfsp,
555 const struct smb_filename *smb_fname,
558 struct smb_filename *full_fname = NULL;
560 struct timespec ts1,ts2;
563 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
566 if (full_fname == NULL) {
571 clock_gettime_mono(&ts1);
572 result = SMB_VFS_NEXT_MKDIRAT(handle,
576 clock_gettime_mono(&ts2);
577 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
579 if (timediff > audit_timeout) {
580 smb_time_audit_log_smb_fname("mkdirat",
585 TALLOC_FREE(full_fname);
590 static int smb_time_audit_closedir(vfs_handle_struct *handle,
594 struct timespec ts1,ts2;
597 clock_gettime_mono(&ts1);
598 result = SMB_VFS_NEXT_CLOSEDIR(handle, dirp);
599 clock_gettime_mono(&ts2);
600 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
602 if (timediff > audit_timeout) {
603 smb_time_audit_log("closedir", timediff);
609 static int smb_time_audit_openat(vfs_handle_struct *handle,
610 const struct files_struct *dirfsp,
611 const struct smb_filename *smb_fname,
612 struct files_struct *fsp,
617 struct timespec ts1,ts2;
620 clock_gettime_mono(&ts1);
621 result = SMB_VFS_NEXT_OPENAT(handle,
627 clock_gettime_mono(&ts2);
628 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
630 if (timediff > audit_timeout) {
631 smb_time_audit_log_fsp("openat", timediff, fsp);
637 static NTSTATUS smb_time_audit_create_file(vfs_handle_struct *handle,
638 struct smb_request *req,
639 struct smb_filename *fname,
640 uint32_t access_mask,
641 uint32_t share_access,
642 uint32_t create_disposition,
643 uint32_t create_options,
644 uint32_t file_attributes,
645 uint32_t oplock_request,
646 const struct smb2_lease *lease,
647 uint64_t allocation_size,
648 uint32_t private_flags,
649 struct security_descriptor *sd,
650 struct ea_list *ea_list,
651 files_struct **result_fsp,
653 const struct smb2_create_blobs *in_context_blobs,
654 struct smb2_create_blobs *out_context_blobs)
657 struct timespec ts1,ts2;
660 clock_gettime_mono(&ts1);
661 result = SMB_VFS_NEXT_CREATE_FILE(
665 access_mask, /* access_mask */
666 share_access, /* share_access */
667 create_disposition, /* create_disposition*/
668 create_options, /* create_options */
669 file_attributes, /* file_attributes */
670 oplock_request, /* oplock_request */
672 allocation_size, /* allocation_size */
675 ea_list, /* ea_list */
676 result_fsp, /* result */
678 in_context_blobs, out_context_blobs); /* create context */
679 clock_gettime_mono(&ts2);
680 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
682 if (timediff > audit_timeout) {
684 * can't use result_fsp this time, may have
685 * invalid content causing smbd crash
687 smb_time_audit_log_smb_fname("create_file", timediff,
694 static int smb_time_audit_close(vfs_handle_struct *handle, files_struct *fsp)
697 struct timespec ts1,ts2;
700 clock_gettime_mono(&ts1);
701 result = SMB_VFS_NEXT_CLOSE(handle, fsp);
702 clock_gettime_mono(&ts2);
703 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
705 if (timediff > audit_timeout) {
706 smb_time_audit_log_fsp("close", timediff, fsp);
712 static ssize_t smb_time_audit_pread(vfs_handle_struct *handle,
714 void *data, size_t n, off_t offset)
717 struct timespec ts1,ts2;
720 clock_gettime_mono(&ts1);
721 result = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
722 clock_gettime_mono(&ts2);
723 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
725 if (timediff > audit_timeout) {
726 smb_time_audit_log_fsp("pread", timediff, fsp);
732 struct smb_time_audit_pread_state {
733 struct files_struct *fsp;
735 struct vfs_aio_state vfs_aio_state;
738 static void smb_time_audit_pread_done(struct tevent_req *subreq);
740 static struct tevent_req *smb_time_audit_pread_send(
741 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
742 struct tevent_context *ev, struct files_struct *fsp,
743 void *data, size_t n, off_t offset)
745 struct tevent_req *req, *subreq;
746 struct smb_time_audit_pread_state *state;
748 req = tevent_req_create(mem_ctx, &state,
749 struct smb_time_audit_pread_state);
755 subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
757 if (tevent_req_nomem(subreq, req)) {
758 return tevent_req_post(req, ev);
760 tevent_req_set_callback(subreq, smb_time_audit_pread_done, req);
764 static void smb_time_audit_pread_done(struct tevent_req *subreq)
766 struct tevent_req *req = tevent_req_callback_data(
767 subreq, struct tevent_req);
768 struct smb_time_audit_pread_state *state = tevent_req_data(
769 req, struct smb_time_audit_pread_state);
771 state->ret = SMB_VFS_PREAD_RECV(subreq, &state->vfs_aio_state);
773 tevent_req_done(req);
776 static ssize_t smb_time_audit_pread_recv(struct tevent_req *req,
777 struct vfs_aio_state *vfs_aio_state)
779 struct smb_time_audit_pread_state *state = tevent_req_data(
780 req, struct smb_time_audit_pread_state);
783 timediff = state->vfs_aio_state.duration * 1.0e-9;
785 if (timediff > audit_timeout) {
786 smb_time_audit_log_fsp("async pread", timediff, state->fsp);
789 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
792 *vfs_aio_state = state->vfs_aio_state;
796 static ssize_t smb_time_audit_pwrite(vfs_handle_struct *handle,
798 const void *data, size_t n,
802 struct timespec ts1,ts2;
805 clock_gettime_mono(&ts1);
806 result = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
807 clock_gettime_mono(&ts2);
808 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
810 if (timediff > audit_timeout) {
811 smb_time_audit_log_fsp("pwrite", timediff, fsp);
817 struct smb_time_audit_pwrite_state {
818 struct files_struct *fsp;
820 struct vfs_aio_state vfs_aio_state;
823 static void smb_time_audit_pwrite_done(struct tevent_req *subreq);
825 static struct tevent_req *smb_time_audit_pwrite_send(
826 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
827 struct tevent_context *ev, struct files_struct *fsp,
828 const void *data, size_t n, off_t offset)
830 struct tevent_req *req, *subreq;
831 struct smb_time_audit_pwrite_state *state;
833 req = tevent_req_create(mem_ctx, &state,
834 struct smb_time_audit_pwrite_state);
840 subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
842 if (tevent_req_nomem(subreq, req)) {
843 return tevent_req_post(req, ev);
845 tevent_req_set_callback(subreq, smb_time_audit_pwrite_done, req);
849 static void smb_time_audit_pwrite_done(struct tevent_req *subreq)
851 struct tevent_req *req = tevent_req_callback_data(
852 subreq, struct tevent_req);
853 struct smb_time_audit_pwrite_state *state = tevent_req_data(
854 req, struct smb_time_audit_pwrite_state);
856 state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->vfs_aio_state);
858 tevent_req_done(req);
861 static ssize_t smb_time_audit_pwrite_recv(struct tevent_req *req,
862 struct vfs_aio_state *vfs_aio_state)
864 struct smb_time_audit_pwrite_state *state = tevent_req_data(
865 req, struct smb_time_audit_pwrite_state);
868 timediff = state->vfs_aio_state.duration * 1.0e-9;
870 if (timediff > audit_timeout) {
871 smb_time_audit_log_fsp("async pwrite", timediff, state->fsp);
874 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
877 *vfs_aio_state = state->vfs_aio_state;
881 static off_t smb_time_audit_lseek(vfs_handle_struct *handle,
883 off_t offset, int whence)
886 struct timespec ts1,ts2;
889 clock_gettime_mono(&ts1);
890 result = SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence);
891 clock_gettime_mono(&ts2);
892 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
894 if (timediff > audit_timeout) {
895 smb_time_audit_log_fsp("lseek", timediff, fsp);
901 static ssize_t smb_time_audit_sendfile(vfs_handle_struct *handle, int tofd,
902 files_struct *fromfsp,
903 const DATA_BLOB *hdr, off_t offset,
907 struct timespec ts1,ts2;
910 clock_gettime_mono(&ts1);
911 result = SMB_VFS_NEXT_SENDFILE(handle, tofd, fromfsp, hdr, offset, n);
912 clock_gettime_mono(&ts2);
913 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
915 if (timediff > audit_timeout) {
916 smb_time_audit_log_fsp("sendfile", timediff, fromfsp);
922 static ssize_t smb_time_audit_recvfile(vfs_handle_struct *handle, int fromfd,
928 struct timespec ts1,ts2;
931 clock_gettime_mono(&ts1);
932 result = SMB_VFS_NEXT_RECVFILE(handle, fromfd, tofsp, offset, n);
933 clock_gettime_mono(&ts2);
934 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
936 if (timediff > audit_timeout) {
937 smb_time_audit_log_fsp("recvfile", timediff, tofsp);
943 static int smb_time_audit_renameat(vfs_handle_struct *handle,
944 files_struct *srcfsp,
945 const struct smb_filename *oldname,
946 files_struct *dstfsp,
947 const struct smb_filename *newname)
950 struct timespec ts1,ts2;
952 struct smb_filename *new_full_fname = NULL;
954 new_full_fname = full_path_from_dirfsp_atname(talloc_tos(),
957 if (new_full_fname == NULL) {
961 clock_gettime_mono(&ts1);
962 result = SMB_VFS_NEXT_RENAMEAT(handle,
967 clock_gettime_mono(&ts2);
968 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
970 if (timediff > audit_timeout) {
971 smb_time_audit_log_smb_fname("renameat",
976 TALLOC_FREE(new_full_fname);
980 struct smb_time_audit_fsync_state {
981 struct files_struct *fsp;
983 struct vfs_aio_state vfs_aio_state;
986 static void smb_time_audit_fsync_done(struct tevent_req *subreq);
988 static struct tevent_req *smb_time_audit_fsync_send(
989 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
990 struct tevent_context *ev, struct files_struct *fsp)
992 struct tevent_req *req, *subreq;
993 struct smb_time_audit_fsync_state *state;
995 req = tevent_req_create(mem_ctx, &state,
996 struct smb_time_audit_fsync_state);
1002 subreq = SMB_VFS_NEXT_FSYNC_SEND(state, ev, handle, fsp);
1003 if (tevent_req_nomem(subreq, req)) {
1004 return tevent_req_post(req, ev);
1006 tevent_req_set_callback(subreq, smb_time_audit_fsync_done, req);
1010 static void smb_time_audit_fsync_done(struct tevent_req *subreq)
1012 struct tevent_req *req = tevent_req_callback_data(
1013 subreq, struct tevent_req);
1014 struct smb_time_audit_fsync_state *state = tevent_req_data(
1015 req, struct smb_time_audit_fsync_state);
1017 state->ret = SMB_VFS_FSYNC_RECV(subreq, &state->vfs_aio_state);
1018 TALLOC_FREE(subreq);
1019 tevent_req_done(req);
1022 static int smb_time_audit_fsync_recv(struct tevent_req *req,
1023 struct vfs_aio_state *vfs_aio_state)
1025 struct smb_time_audit_fsync_state *state = tevent_req_data(
1026 req, struct smb_time_audit_fsync_state);
1029 timediff = state->vfs_aio_state.duration * 1.0e-9;
1031 if (timediff > audit_timeout) {
1032 smb_time_audit_log_fsp("async fsync", timediff, state->fsp);
1035 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1038 *vfs_aio_state = state->vfs_aio_state;
1042 static int smb_time_audit_stat(vfs_handle_struct *handle,
1043 struct smb_filename *fname)
1046 struct timespec ts1,ts2;
1049 clock_gettime_mono(&ts1);
1050 result = SMB_VFS_NEXT_STAT(handle, fname);
1051 clock_gettime_mono(&ts2);
1052 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1054 if (timediff > audit_timeout) {
1055 smb_time_audit_log_smb_fname("stat", timediff, fname);
1061 static int smb_time_audit_fstat(vfs_handle_struct *handle, files_struct *fsp,
1062 SMB_STRUCT_STAT *sbuf)
1065 struct timespec ts1,ts2;
1068 clock_gettime_mono(&ts1);
1069 result = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1070 clock_gettime_mono(&ts2);
1071 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1073 if (timediff > audit_timeout) {
1074 smb_time_audit_log_fsp("fstat", timediff, fsp);
1080 static int smb_time_audit_lstat(vfs_handle_struct *handle,
1081 struct smb_filename *path)
1084 struct timespec ts1,ts2;
1087 clock_gettime_mono(&ts1);
1088 result = SMB_VFS_NEXT_LSTAT(handle, path);
1089 clock_gettime_mono(&ts2);
1090 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1092 if (timediff > audit_timeout) {
1093 smb_time_audit_log_smb_fname("lstat", timediff, path);
1099 static uint64_t smb_time_audit_get_alloc_size(vfs_handle_struct *handle,
1101 const SMB_STRUCT_STAT *sbuf)
1104 struct timespec ts1,ts2;
1107 clock_gettime_mono(&ts1);
1108 result = SMB_VFS_NEXT_GET_ALLOC_SIZE(handle, fsp, sbuf);
1109 clock_gettime_mono(&ts2);
1110 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1112 if (timediff > audit_timeout) {
1113 smb_time_audit_log_fsp("get_alloc_size", timediff, fsp);
1119 static int smb_time_audit_unlinkat(vfs_handle_struct *handle,
1120 struct files_struct *dirfsp,
1121 const struct smb_filename *path,
1124 struct smb_filename *full_fname = NULL;
1126 struct timespec ts1,ts2;
1129 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1132 if (full_fname == NULL) {
1136 clock_gettime_mono(&ts1);
1137 result = SMB_VFS_NEXT_UNLINKAT(handle,
1141 clock_gettime_mono(&ts2);
1142 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1144 if (timediff > audit_timeout) {
1145 smb_time_audit_log_smb_fname("unlinkat", timediff, full_fname);
1148 TALLOC_FREE(full_fname);
1152 static int smb_time_audit_fchmod(vfs_handle_struct *handle, files_struct *fsp,
1156 struct timespec ts1,ts2;
1159 clock_gettime_mono(&ts1);
1160 result = SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1161 clock_gettime_mono(&ts2);
1162 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1164 if (timediff > audit_timeout) {
1165 smb_time_audit_log_fsp("fchmod", timediff, fsp);
1171 static int smb_time_audit_fchown(vfs_handle_struct *handle, files_struct *fsp,
1172 uid_t uid, gid_t gid)
1175 struct timespec ts1,ts2;
1178 clock_gettime_mono(&ts1);
1179 result = SMB_VFS_NEXT_FCHOWN(handle, fsp, uid, gid);
1180 clock_gettime_mono(&ts2);
1181 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1183 if (timediff > audit_timeout) {
1184 smb_time_audit_log_fsp("fchown", timediff, fsp);
1190 static int smb_time_audit_lchown(vfs_handle_struct *handle,
1191 const struct smb_filename *smb_fname,
1196 struct timespec ts1,ts2;
1199 clock_gettime_mono(&ts1);
1200 result = SMB_VFS_NEXT_LCHOWN(handle, smb_fname, uid, gid);
1201 clock_gettime_mono(&ts2);
1202 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1204 if (timediff > audit_timeout) {
1205 smb_time_audit_log_fname("lchown",
1207 smb_fname->base_name);
1213 static int smb_time_audit_chdir(vfs_handle_struct *handle,
1214 const struct smb_filename *smb_fname)
1217 struct timespec ts1,ts2;
1220 clock_gettime_mono(&ts1);
1221 result = SMB_VFS_NEXT_CHDIR(handle, smb_fname);
1222 clock_gettime_mono(&ts2);
1223 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1225 if (timediff > audit_timeout) {
1226 smb_time_audit_log_fname("chdir",
1228 smb_fname->base_name);
1234 static struct smb_filename *smb_time_audit_getwd(vfs_handle_struct *handle,
1235 TALLOC_CTX *mem_ctx)
1237 struct smb_filename *result;
1238 struct timespec ts1,ts2;
1241 clock_gettime_mono(&ts1);
1242 result = SMB_VFS_NEXT_GETWD(handle, mem_ctx);
1243 clock_gettime_mono(&ts2);
1244 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1246 if (timediff > audit_timeout) {
1247 smb_time_audit_log("getwd", timediff);
1253 static int smb_time_audit_fntimes(vfs_handle_struct *handle,
1255 struct smb_file_time *ft)
1258 struct timespec ts1,ts2;
1261 clock_gettime_mono(&ts1);
1262 result = SMB_VFS_NEXT_FNTIMES(handle, fsp, ft);
1263 clock_gettime_mono(&ts2);
1264 timediff = nsec_time_diff(&ts2, &ts1) * 1.0e-9;
1266 if (timediff > audit_timeout) {
1267 smb_time_audit_log_fsp("fntimes", timediff, fsp);
1273 static int smb_time_audit_ftruncate(vfs_handle_struct *handle,
1278 struct timespec ts1,ts2;
1281 clock_gettime_mono(&ts1);
1282 result = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1283 clock_gettime_mono(&ts2);
1284 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1286 if (timediff > audit_timeout) {
1287 smb_time_audit_log_fsp("ftruncate", timediff, fsp);
1293 static int smb_time_audit_fallocate(vfs_handle_struct *handle,
1300 int saved_errno = 0;
1301 struct timespec ts1,ts2;
1304 clock_gettime_mono(&ts1);
1305 result = SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
1307 saved_errno = errno;
1309 clock_gettime_mono(&ts2);
1310 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1312 if (timediff > audit_timeout) {
1313 smb_time_audit_log_fsp("fallocate", timediff, fsp);
1316 errno = saved_errno;
1321 static bool smb_time_audit_lock(vfs_handle_struct *handle, files_struct *fsp,
1322 int op, off_t offset, off_t count,
1326 struct timespec ts1,ts2;
1329 clock_gettime_mono(&ts1);
1330 result = SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type);
1331 clock_gettime_mono(&ts2);
1332 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1334 if (timediff > audit_timeout) {
1335 smb_time_audit_log_fsp("lock", timediff, fsp);
1341 static int smb_time_audit_kernel_flock(struct vfs_handle_struct *handle,
1342 struct files_struct *fsp,
1343 uint32_t share_access,
1344 uint32_t access_mask)
1347 struct timespec ts1,ts2;
1350 clock_gettime_mono(&ts1);
1351 result = SMB_VFS_NEXT_KERNEL_FLOCK(handle, fsp, share_access,
1353 clock_gettime_mono(&ts2);
1354 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1356 if (timediff > audit_timeout) {
1357 smb_time_audit_log_fsp("kernel_flock", timediff, fsp);
1363 static int smb_time_audit_fcntl(struct vfs_handle_struct *handle,
1364 struct files_struct *fsp,
1365 int cmd, va_list cmd_arg)
1368 va_list dup_cmd_arg;
1370 struct timespec ts1,ts2;
1373 va_copy(dup_cmd_arg, cmd_arg);
1374 arg = va_arg(dup_cmd_arg, void *);
1375 clock_gettime_mono(&ts1);
1376 result = SMB_VFS_NEXT_FCNTL(handle, fsp, cmd, arg);
1377 clock_gettime_mono(&ts2);
1378 va_end(dup_cmd_arg);
1380 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1381 if (timediff > audit_timeout) {
1382 smb_time_audit_log_fsp("kernel_flock", timediff, fsp);
1388 static int smb_time_audit_linux_setlease(vfs_handle_struct *handle,
1393 struct timespec ts1,ts2;
1396 clock_gettime_mono(&ts1);
1397 result = SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
1398 clock_gettime_mono(&ts2);
1399 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1401 if (timediff > audit_timeout) {
1402 smb_time_audit_log_fsp("linux_setlease", timediff, fsp);
1408 static bool smb_time_audit_getlock(vfs_handle_struct *handle,
1410 off_t *poffset, off_t *pcount,
1411 int *ptype, pid_t *ppid)
1414 struct timespec ts1,ts2;
1417 clock_gettime_mono(&ts1);
1418 result = SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype,
1420 clock_gettime_mono(&ts2);
1421 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1423 if (timediff > audit_timeout) {
1424 smb_time_audit_log_fsp("getlock", timediff, fsp);
1430 static int smb_time_audit_symlinkat(vfs_handle_struct *handle,
1431 const struct smb_filename *link_contents,
1432 struct files_struct *dirfsp,
1433 const struct smb_filename *new_smb_fname)
1435 struct smb_filename *full_fname = NULL;
1437 struct timespec ts1,ts2;
1440 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1443 if (full_fname == NULL) {
1448 clock_gettime_mono(&ts1);
1449 result = SMB_VFS_NEXT_SYMLINKAT(handle,
1453 clock_gettime_mono(&ts2);
1454 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1456 if (timediff > audit_timeout) {
1457 smb_time_audit_log_fname("symlinkat", timediff,
1458 full_fname->base_name);
1461 TALLOC_FREE(full_fname);
1465 static int smb_time_audit_readlinkat(vfs_handle_struct *handle,
1466 const struct files_struct *dirfsp,
1467 const struct smb_filename *smb_fname,
1471 struct smb_filename *full_fname = NULL;
1473 struct timespec ts1,ts2;
1476 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1479 if (full_fname == NULL) {
1484 clock_gettime_mono(&ts1);
1485 result = SMB_VFS_NEXT_READLINKAT(handle,
1490 clock_gettime_mono(&ts2);
1491 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1493 if (timediff > audit_timeout) {
1494 smb_time_audit_log_fname("readlinkat", timediff,
1495 full_fname->base_name);
1498 TALLOC_FREE(full_fname);
1502 static int smb_time_audit_linkat(vfs_handle_struct *handle,
1503 files_struct *srcfsp,
1504 const struct smb_filename *old_smb_fname,
1505 files_struct *dstfsp,
1506 const struct smb_filename *new_smb_fname,
1509 struct smb_filename *new_full_fname = NULL;
1511 struct timespec ts1,ts2;
1514 new_full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1517 if (new_full_fname == NULL) {
1522 clock_gettime_mono(&ts1);
1523 result = SMB_VFS_NEXT_LINKAT(handle,
1529 clock_gettime_mono(&ts2);
1530 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1532 if (timediff > audit_timeout) {
1533 smb_time_audit_log_fname("linkat", timediff,
1534 new_full_fname->base_name);
1537 TALLOC_FREE(new_full_fname);
1541 static int smb_time_audit_mknodat(vfs_handle_struct *handle,
1542 files_struct *dirfsp,
1543 const struct smb_filename *smb_fname,
1547 struct smb_filename *full_fname = NULL;
1549 struct timespec ts1,ts2;
1552 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1555 if (full_fname == NULL) {
1560 clock_gettime_mono(&ts1);
1561 result = SMB_VFS_NEXT_MKNODAT(handle,
1566 clock_gettime_mono(&ts2);
1567 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1569 if (timediff > audit_timeout) {
1570 smb_time_audit_log_smb_fname("mknodat", timediff, full_fname);
1573 TALLOC_FREE(full_fname);
1577 static struct smb_filename *smb_time_audit_realpath(vfs_handle_struct *handle,
1579 const struct smb_filename *smb_fname)
1581 struct smb_filename *result_fname;
1582 struct timespec ts1,ts2;
1585 clock_gettime_mono(&ts1);
1586 result_fname = SMB_VFS_NEXT_REALPATH(handle, ctx, smb_fname);
1587 clock_gettime_mono(&ts2);
1588 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1590 if (timediff > audit_timeout) {
1591 smb_time_audit_log_fname("realpath", timediff,
1592 smb_fname->base_name);
1595 return result_fname;
1598 static int smb_time_audit_chflags(vfs_handle_struct *handle,
1599 const struct smb_filename *smb_fname,
1603 struct timespec ts1,ts2;
1606 clock_gettime_mono(&ts1);
1607 result = SMB_VFS_NEXT_CHFLAGS(handle, smb_fname, flags);
1608 clock_gettime_mono(&ts2);
1609 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1611 if (timediff > audit_timeout) {
1612 smb_time_audit_log_smb_fname("chflags", timediff, smb_fname);
1618 static int smb_time_audit_fchflags(vfs_handle_struct *handle,
1619 struct files_struct *fsp,
1623 struct timespec ts1,ts2;
1626 clock_gettime_mono(&ts1);
1627 result = SMB_VFS_NEXT_FCHFLAGS(handle, fsp, flags);
1628 clock_gettime_mono(&ts2);
1629 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1631 if (timediff > audit_timeout) {
1632 smb_time_audit_log_smb_fname("chflags",
1640 static struct file_id smb_time_audit_file_id_create(struct vfs_handle_struct *handle,
1641 const SMB_STRUCT_STAT *sbuf)
1643 struct file_id id_zero;
1644 struct file_id result;
1645 struct timespec ts1,ts2;
1648 ZERO_STRUCT(id_zero);
1650 clock_gettime_mono(&ts1);
1651 result = SMB_VFS_NEXT_FILE_ID_CREATE(handle, sbuf);
1652 clock_gettime_mono(&ts2);
1653 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1655 if (timediff > audit_timeout) {
1656 smb_time_audit_log("file_id_create", timediff);
1662 static uint64_t smb_time_audit_fs_file_id(struct vfs_handle_struct *handle,
1663 const SMB_STRUCT_STAT *sbuf)
1666 struct timespec ts1,ts2;
1669 clock_gettime_mono(&ts1);
1670 result = SMB_VFS_NEXT_FS_FILE_ID(handle, sbuf);
1671 clock_gettime_mono(&ts2);
1672 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1674 if (timediff > audit_timeout) {
1675 smb_time_audit_log("fs_file_id", timediff);
1681 static NTSTATUS smb_time_audit_fstreaminfo(vfs_handle_struct *handle,
1682 struct files_struct *fsp,
1683 TALLOC_CTX *mem_ctx,
1684 unsigned int *pnum_streams,
1685 struct stream_struct **pstreams)
1688 struct timespec ts1,ts2;
1691 clock_gettime_mono(&ts1);
1692 result = SMB_VFS_NEXT_FSTREAMINFO(handle, fsp, mem_ctx,
1693 pnum_streams, pstreams);
1694 clock_gettime_mono(&ts2);
1695 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1697 if (timediff > audit_timeout) {
1698 smb_time_audit_log_fsp("fstreaminfo", timediff, fsp);
1704 static int smb_time_audit_get_real_filename(struct vfs_handle_struct *handle,
1705 const struct smb_filename *path,
1707 TALLOC_CTX *mem_ctx,
1711 struct timespec ts1,ts2;
1714 clock_gettime_mono(&ts1);
1715 result = SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name, mem_ctx,
1717 clock_gettime_mono(&ts2);
1718 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1720 if (timediff > audit_timeout) {
1721 smb_time_audit_log_fname("get_real_filename",
1722 timediff, path->base_name);
1728 static const char *smb_time_audit_connectpath(vfs_handle_struct *handle,
1729 const struct smb_filename *smb_fname)
1732 struct timespec ts1,ts2;
1735 clock_gettime_mono(&ts1);
1736 result = SMB_VFS_NEXT_CONNECTPATH(handle, smb_fname);
1737 clock_gettime_mono(&ts2);
1738 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1740 if (timediff > audit_timeout) {
1741 smb_time_audit_log_fname("connectpath", timediff,
1742 smb_fname->base_name);
1748 static NTSTATUS smb_time_audit_brl_lock_windows(struct vfs_handle_struct *handle,
1749 struct byte_range_lock *br_lck,
1750 struct lock_struct *plock)
1753 struct timespec ts1,ts2;
1756 clock_gettime_mono(&ts1);
1757 result = SMB_VFS_NEXT_BRL_LOCK_WINDOWS(handle, br_lck, plock);
1758 clock_gettime_mono(&ts2);
1759 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1761 if (timediff > audit_timeout) {
1762 smb_time_audit_log_fsp("brl_lock_windows", timediff,
1769 static bool smb_time_audit_brl_unlock_windows(struct vfs_handle_struct *handle,
1770 struct byte_range_lock *br_lck,
1771 const struct lock_struct *plock)
1774 struct timespec ts1,ts2;
1777 clock_gettime_mono(&ts1);
1778 result = SMB_VFS_NEXT_BRL_UNLOCK_WINDOWS(handle, br_lck, plock);
1779 clock_gettime_mono(&ts2);
1780 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1782 if (timediff > audit_timeout) {
1783 smb_time_audit_log_fsp("brl_unlock_windows", timediff,
1790 static bool smb_time_audit_strict_lock_check(struct vfs_handle_struct *handle,
1791 struct files_struct *fsp,
1792 struct lock_struct *plock)
1795 struct timespec ts1,ts2;
1798 clock_gettime_mono(&ts1);
1799 result = SMB_VFS_NEXT_STRICT_LOCK_CHECK(handle, fsp, plock);
1800 clock_gettime_mono(&ts2);
1801 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1803 if (timediff > audit_timeout) {
1804 smb_time_audit_log_fsp("strict_lock_check", timediff, fsp);
1810 static NTSTATUS smb_time_audit_translate_name(struct vfs_handle_struct *handle,
1812 enum vfs_translate_direction direction,
1813 TALLOC_CTX *mem_ctx,
1817 struct timespec ts1,ts2;
1820 clock_gettime_mono(&ts1);
1821 result = SMB_VFS_NEXT_TRANSLATE_NAME(handle, name, direction, mem_ctx,
1823 clock_gettime_mono(&ts2);
1824 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1826 if (timediff > audit_timeout) {
1827 smb_time_audit_log_fname("translate_name", timediff, name);
1833 static NTSTATUS smb_time_audit_parent_pathname(struct vfs_handle_struct *handle,
1834 TALLOC_CTX *mem_ctx,
1835 const struct smb_filename *smb_fname_in,
1836 struct smb_filename **parent_dir_out,
1837 struct smb_filename **atname_out)
1840 struct timespec ts1,ts2;
1843 clock_gettime_mono(&ts1);
1844 result = SMB_VFS_NEXT_PARENT_PATHNAME(handle,
1849 clock_gettime_mono(&ts2);
1850 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1852 if (timediff > audit_timeout) {
1853 smb_time_audit_log_fname("parent_pathname",
1855 smb_fname_in->base_name);
1861 static NTSTATUS smb_time_audit_fsctl(struct vfs_handle_struct *handle,
1862 struct files_struct *fsp,
1866 const uint8_t *_in_data,
1868 uint8_t **_out_data,
1869 uint32_t max_out_len,
1873 struct timespec ts1,ts2;
1876 clock_gettime_mono(&ts1);
1877 result = SMB_VFS_NEXT_FSCTL(handle,
1887 clock_gettime_mono(&ts2);
1888 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1890 if (timediff > audit_timeout) {
1891 smb_time_audit_log_fsp("fsctl", timediff, fsp);
1897 struct smb_time_audit_get_dos_attributes_state {
1898 struct vfs_aio_state aio_state;
1899 files_struct *dir_fsp;
1900 const struct smb_filename *smb_fname;
1904 static void smb_time_audit_get_dos_attributes_done(struct tevent_req *subreq);
1906 static struct tevent_req *smb_time_audit_get_dos_attributes_send(
1907 TALLOC_CTX *mem_ctx,
1908 struct tevent_context *ev,
1909 struct vfs_handle_struct *handle,
1910 files_struct *dir_fsp,
1911 struct smb_filename *smb_fname)
1913 struct tevent_req *req = NULL;
1914 struct smb_time_audit_get_dos_attributes_state *state = NULL;
1915 struct tevent_req *subreq = NULL;
1917 req = tevent_req_create(mem_ctx, &state,
1918 struct smb_time_audit_get_dos_attributes_state);
1922 *state = (struct smb_time_audit_get_dos_attributes_state) {
1924 .smb_fname = smb_fname,
1927 subreq = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES_SEND(mem_ctx,
1932 if (tevent_req_nomem(subreq, req)) {
1933 return tevent_req_post(req, ev);
1935 tevent_req_set_callback(subreq,
1936 smb_time_audit_get_dos_attributes_done,
1942 static void smb_time_audit_get_dos_attributes_done(struct tevent_req *subreq)
1944 struct tevent_req *req =
1945 tevent_req_callback_data(subreq,
1947 struct smb_time_audit_get_dos_attributes_state *state =
1948 tevent_req_data(req,
1949 struct smb_time_audit_get_dos_attributes_state);
1952 status = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES_RECV(subreq,
1955 TALLOC_FREE(subreq);
1956 if (tevent_req_nterror(req, status)) {
1960 tevent_req_done(req);
1964 static NTSTATUS smb_time_audit_get_dos_attributes_recv(struct tevent_req *req,
1965 struct vfs_aio_state *aio_state,
1968 struct smb_time_audit_get_dos_attributes_state *state =
1969 tevent_req_data(req,
1970 struct smb_time_audit_get_dos_attributes_state);
1974 timediff = state->aio_state.duration * 1.0e-9;
1976 if (timediff > audit_timeout) {
1977 smb_time_audit_log_at("async get_dos_attributes",
1983 if (tevent_req_is_nterror(req, &status)) {
1984 tevent_req_received(req);
1988 *aio_state = state->aio_state;
1989 *dosmode = state->dosmode;
1990 tevent_req_received(req);
1991 return NT_STATUS_OK;
1994 static NTSTATUS smb_time_fget_dos_attributes(struct vfs_handle_struct *handle,
1995 struct files_struct *fsp,
1999 struct timespec ts1,ts2;
2002 clock_gettime_mono(&ts1);
2003 result = SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle,
2006 clock_gettime_mono(&ts2);
2007 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2009 if (timediff > audit_timeout) {
2010 smb_time_audit_log_fsp("fget_dos_attributes", timediff, fsp);
2016 static NTSTATUS smb_time_fset_dos_attributes(struct vfs_handle_struct *handle,
2017 struct files_struct *fsp,
2021 struct timespec ts1,ts2;
2024 clock_gettime_mono(&ts1);
2025 result = SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle,
2028 clock_gettime_mono(&ts2);
2029 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2031 if (timediff > audit_timeout) {
2032 smb_time_audit_log_fsp("fset_dos_attributes", timediff, fsp);
2038 struct time_audit_offload_read_state {
2039 struct vfs_handle_struct *handle;
2040 struct timespec ts_send;
2041 DATA_BLOB token_blob;
2044 static void smb_time_audit_offload_read_done(struct tevent_req *subreq);
2046 static struct tevent_req *smb_time_audit_offload_read_send(
2047 TALLOC_CTX *mem_ctx,
2048 struct tevent_context *ev,
2049 struct vfs_handle_struct *handle,
2050 struct files_struct *fsp,
2056 struct tevent_req *req = NULL;
2057 struct tevent_req *subreq = NULL;
2058 struct time_audit_offload_read_state *state = NULL;
2060 req = tevent_req_create(mem_ctx, &state,
2061 struct time_audit_offload_read_state);
2065 state->handle = handle;
2066 clock_gettime_mono(&state->ts_send);
2068 subreq = SMB_VFS_NEXT_OFFLOAD_READ_SEND(mem_ctx, ev,
2072 if (tevent_req_nomem(subreq, req)) {
2073 return tevent_req_post(req, ev);
2076 tevent_req_set_callback(subreq, smb_time_audit_offload_read_done, req);
2080 static void smb_time_audit_offload_read_done(struct tevent_req *subreq)
2082 struct tevent_req *req = tevent_req_callback_data(
2083 subreq, struct tevent_req);
2084 struct time_audit_offload_read_state *state = tevent_req_data(
2085 req, struct time_audit_offload_read_state);
2088 status = SMB_VFS_NEXT_OFFLOAD_READ_RECV(subreq,
2091 &state->token_blob);
2092 TALLOC_FREE(subreq);
2093 if (tevent_req_nterror(req, status)) {
2096 tevent_req_done(req);
2099 static NTSTATUS smb_time_audit_offload_read_recv(
2100 struct tevent_req *req,
2101 struct vfs_handle_struct *handle,
2102 TALLOC_CTX *mem_ctx,
2103 DATA_BLOB *token_blob)
2105 struct time_audit_offload_read_state *state = tevent_req_data(
2106 req, struct time_audit_offload_read_state);
2107 struct timespec ts_recv;
2111 clock_gettime_mono(&ts_recv);
2112 timediff = nsec_time_diff(&ts_recv, &state->ts_send) * 1.0e-9;
2113 if (timediff > audit_timeout) {
2114 smb_time_audit_log("offload_read", timediff);
2117 if (tevent_req_is_nterror(req, &status)) {
2118 tevent_req_received(req);
2122 token_blob->length = state->token_blob.length;
2123 token_blob->data = talloc_move(mem_ctx, &state->token_blob.data);
2125 tevent_req_received(req);
2126 return NT_STATUS_OK;
2129 struct time_audit_offload_write_state {
2130 struct timespec ts_send;
2131 struct vfs_handle_struct *handle;
2134 static void smb_time_audit_offload_write_done(struct tevent_req *subreq);
2136 static struct tevent_req *smb_time_audit_offload_write_send(struct vfs_handle_struct *handle,
2137 TALLOC_CTX *mem_ctx,
2138 struct tevent_context *ev,
2141 off_t transfer_offset,
2142 struct files_struct *dest_fsp,
2146 struct tevent_req *req;
2147 struct tevent_req *subreq;
2148 struct time_audit_offload_write_state *state;
2150 req = tevent_req_create(mem_ctx, &state,
2151 struct time_audit_offload_write_state);
2156 state->handle = handle;
2157 clock_gettime_mono(&state->ts_send);
2158 subreq = SMB_VFS_NEXT_OFFLOAD_WRITE_SEND(handle, state, ev,
2159 fsctl, token, transfer_offset,
2160 dest_fsp, dest_off, num);
2161 if (tevent_req_nomem(subreq, req)) {
2162 return tevent_req_post(req, ev);
2165 tevent_req_set_callback(subreq, smb_time_audit_offload_write_done, req);
2169 static void smb_time_audit_offload_write_done(struct tevent_req *subreq)
2171 struct tevent_req *req = tevent_req_callback_data(
2172 subreq, struct tevent_req);
2173 struct time_audit_offload_write_state *state = tevent_req_data(
2174 req, struct time_audit_offload_write_state);
2177 status = SMB_VFS_NEXT_OFFLOAD_WRITE_RECV(state->handle,
2180 TALLOC_FREE(subreq);
2181 if (tevent_req_nterror(req, status)) {
2184 tevent_req_done(req);
2187 static NTSTATUS smb_time_audit_offload_write_recv(struct vfs_handle_struct *handle,
2188 struct tevent_req *req,
2191 struct time_audit_offload_write_state *state = tevent_req_data(
2192 req, struct time_audit_offload_write_state);
2193 struct timespec ts_recv;
2197 clock_gettime_mono(&ts_recv);
2198 timediff = nsec_time_diff(&ts_recv, &state->ts_send)*1.0e-9;
2199 if (timediff > audit_timeout) {
2200 smb_time_audit_log("offload_write", timediff);
2203 *copied = state->copied;
2204 if (tevent_req_is_nterror(req, &status)) {
2205 tevent_req_received(req);
2209 tevent_req_received(req);
2210 return NT_STATUS_OK;
2213 static NTSTATUS smb_time_audit_fget_compression(vfs_handle_struct *handle,
2214 TALLOC_CTX *mem_ctx,
2215 struct files_struct *fsp,
2216 uint16_t *_compression_fmt)
2219 struct timespec ts1,ts2;
2222 clock_gettime_mono(&ts1);
2223 result = SMB_VFS_NEXT_FGET_COMPRESSION(handle, mem_ctx, fsp,
2225 clock_gettime_mono(&ts2);
2226 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2228 if (timediff > audit_timeout) {
2229 smb_time_audit_log_fsp("get_compression",
2236 static NTSTATUS smb_time_audit_set_compression(vfs_handle_struct *handle,
2237 TALLOC_CTX *mem_ctx,
2238 struct files_struct *fsp,
2239 uint16_t compression_fmt)
2242 struct timespec ts1,ts2;
2245 clock_gettime_mono(&ts1);
2246 result = SMB_VFS_NEXT_SET_COMPRESSION(handle, mem_ctx, fsp,
2248 clock_gettime_mono(&ts2);
2249 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2251 if (timediff > audit_timeout) {
2252 smb_time_audit_log_fsp("set_compression", timediff, fsp);
2258 static NTSTATUS smb_time_audit_freaddir_attr(struct vfs_handle_struct *handle,
2259 struct files_struct *fsp,
2260 TALLOC_CTX *mem_ctx,
2261 struct readdir_attr_data **pattr_data)
2264 struct timespec ts1, ts2;
2267 clock_gettime_mono(&ts1);
2268 status = SMB_VFS_NEXT_FREADDIR_ATTR(handle, fsp, mem_ctx, pattr_data);
2269 clock_gettime_mono(&ts2);
2270 timediff = nsec_time_diff(&ts2, &ts1) * 1.0e-9;
2272 if (timediff > audit_timeout) {
2273 smb_time_audit_log_fsp("freaddir_attr", timediff, fsp);
2279 static NTSTATUS smb_time_audit_fget_nt_acl(vfs_handle_struct *handle,
2281 uint32_t security_info,
2282 TALLOC_CTX *mem_ctx,
2283 struct security_descriptor **ppdesc)
2286 struct timespec ts1,ts2;
2289 clock_gettime_mono(&ts1);
2290 result = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
2292 clock_gettime_mono(&ts2);
2293 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2295 if (timediff > audit_timeout) {
2296 smb_time_audit_log_fsp("fget_nt_acl", timediff, fsp);
2302 static NTSTATUS smb_time_audit_fset_nt_acl(vfs_handle_struct *handle,
2304 uint32_t security_info_sent,
2305 const struct security_descriptor *psd)
2308 struct timespec ts1,ts2;
2311 clock_gettime_mono(&ts1);
2312 result = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent,
2314 clock_gettime_mono(&ts2);
2315 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2317 if (timediff > audit_timeout) {
2318 smb_time_audit_log_fsp("fset_nt_acl", timediff, fsp);
2324 static NTSTATUS smb_time_audit_audit_file(struct vfs_handle_struct *handle,
2325 struct smb_filename *smb_fname,
2326 struct security_acl *sacl,
2327 uint32_t access_requested,
2328 uint32_t access_denied)
2331 struct timespec ts1,ts2;
2334 clock_gettime_mono(&ts1);
2335 result = SMB_VFS_NEXT_AUDIT_FILE(handle,
2340 clock_gettime_mono(&ts2);
2341 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2343 if (timediff > audit_timeout) {
2344 smb_time_audit_log_fname("audit_file",
2346 smb_fname->base_name);
2352 static SMB_ACL_T smb_time_audit_sys_acl_get_fd(vfs_handle_struct *handle,
2354 SMB_ACL_TYPE_T type,
2355 TALLOC_CTX *mem_ctx)
2358 struct timespec ts1,ts2;
2361 clock_gettime_mono(&ts1);
2362 result = SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp, type, mem_ctx);
2363 clock_gettime_mono(&ts2);
2364 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2366 if (timediff > audit_timeout) {
2367 smb_time_audit_log_fsp("sys_acl_get_fd", timediff, fsp);
2373 static int smb_time_audit_sys_acl_blob_get_fd(vfs_handle_struct *handle,
2375 TALLOC_CTX *mem_ctx,
2376 char **blob_description,
2380 struct timespec ts1,ts2;
2383 clock_gettime_mono(&ts1);
2384 result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle, fsp, mem_ctx, blob_description, blob);
2385 clock_gettime_mono(&ts2);
2386 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2388 if (timediff > audit_timeout) {
2389 smb_time_audit_log("sys_acl_blob_get_fd", timediff);
2395 static int smb_time_audit_sys_acl_set_fd(vfs_handle_struct *handle,
2397 SMB_ACL_TYPE_T type,
2401 struct timespec ts1,ts2;
2404 clock_gettime_mono(&ts1);
2405 result = SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, type, theacl);
2406 clock_gettime_mono(&ts2);
2407 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2409 if (timediff > audit_timeout) {
2410 smb_time_audit_log_fsp("sys_acl_set_fd", timediff, fsp);
2416 static int smb_time_audit_sys_acl_delete_def_fd(vfs_handle_struct *handle,
2420 struct timespec ts1,ts2;
2423 clock_gettime_mono(&ts1);
2424 result = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FD(handle, fsp);
2425 clock_gettime_mono(&ts2);
2426 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2428 if (timediff > audit_timeout) {
2429 smb_time_audit_log_fsp("sys_acl_delete_def_fd", timediff, fsp);
2435 static ssize_t smb_time_audit_getxattr(struct vfs_handle_struct *handle,
2436 const struct smb_filename *smb_fname,
2442 struct timespec ts1,ts2;
2445 clock_gettime_mono(&ts1);
2446 result = SMB_VFS_NEXT_GETXATTR(handle, smb_fname, name, value, size);
2447 clock_gettime_mono(&ts2);
2448 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2450 if (timediff > audit_timeout) {
2451 smb_time_audit_log_fname("getxattr", timediff,
2452 smb_fname->base_name);
2458 struct smb_time_audit_getxattrat_state {
2459 struct vfs_aio_state aio_state;
2460 files_struct *dir_fsp;
2461 const struct smb_filename *smb_fname;
2462 const char *xattr_name;
2464 uint8_t *xattr_value;
2467 static void smb_time_audit_getxattrat_done(struct tevent_req *subreq);
2469 static struct tevent_req *smb_time_audit_getxattrat_send(
2470 TALLOC_CTX *mem_ctx,
2471 struct tevent_context *ev,
2472 struct vfs_handle_struct *handle,
2473 files_struct *dir_fsp,
2474 const struct smb_filename *smb_fname,
2475 const char *xattr_name,
2478 struct tevent_req *req = NULL;
2479 struct tevent_req *subreq = NULL;
2480 struct smb_time_audit_getxattrat_state *state = NULL;
2482 req = tevent_req_create(mem_ctx, &state,
2483 struct smb_time_audit_getxattrat_state);
2487 *state = (struct smb_time_audit_getxattrat_state) {
2489 .smb_fname = smb_fname,
2490 .xattr_name = xattr_name,
2493 subreq = SMB_VFS_NEXT_GETXATTRAT_SEND(state,
2500 if (tevent_req_nomem(subreq, req)) {
2501 return tevent_req_post(req, ev);
2503 tevent_req_set_callback(subreq, smb_time_audit_getxattrat_done, req);
2508 static void smb_time_audit_getxattrat_done(struct tevent_req *subreq)
2510 struct tevent_req *req = tevent_req_callback_data(
2511 subreq, struct tevent_req);
2512 struct smb_time_audit_getxattrat_state *state = tevent_req_data(
2513 req, struct smb_time_audit_getxattrat_state);
2515 state->xattr_size = SMB_VFS_NEXT_GETXATTRAT_RECV(subreq,
2518 &state->xattr_value);
2519 TALLOC_FREE(subreq);
2520 if (state->xattr_size == -1) {
2521 tevent_req_error(req, state->aio_state.error);
2525 tevent_req_done(req);
2528 static ssize_t smb_time_audit_getxattrat_recv(struct tevent_req *req,
2529 struct vfs_aio_state *aio_state,
2530 TALLOC_CTX *mem_ctx,
2531 uint8_t **xattr_value)
2533 struct smb_time_audit_getxattrat_state *state = tevent_req_data(
2534 req, struct smb_time_audit_getxattrat_state);
2538 timediff = state->aio_state.duration * 1.0e-9;
2540 if (timediff > audit_timeout) {
2541 smb_time_audit_log_at("async getxattrat",
2547 if (tevent_req_is_unix_error(req, &aio_state->error)) {
2548 tevent_req_received(req);
2552 *aio_state = state->aio_state;
2553 xattr_size = state->xattr_size;
2554 if (xattr_value != NULL) {
2555 *xattr_value = talloc_move(mem_ctx, &state->xattr_value);
2558 tevent_req_received(req);
2562 static ssize_t smb_time_audit_fgetxattr(struct vfs_handle_struct *handle,
2563 struct files_struct *fsp,
2564 const char *name, void *value,
2568 struct timespec ts1,ts2;
2571 clock_gettime_mono(&ts1);
2572 result = SMB_VFS_NEXT_FGETXATTR(handle, fsp, name, value, size);
2573 clock_gettime_mono(&ts2);
2574 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2576 if (timediff > audit_timeout) {
2577 smb_time_audit_log_fsp("fgetxattr", timediff, fsp);
2583 static ssize_t smb_time_audit_flistxattr(struct vfs_handle_struct *handle,
2584 struct files_struct *fsp, char *list,
2588 struct timespec ts1,ts2;
2591 clock_gettime_mono(&ts1);
2592 result = SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
2593 clock_gettime_mono(&ts2);
2594 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2596 if (timediff > audit_timeout) {
2597 smb_time_audit_log_fsp("flistxattr", timediff, fsp);
2603 static int smb_time_audit_fremovexattr(struct vfs_handle_struct *handle,
2604 struct files_struct *fsp,
2608 struct timespec ts1,ts2;
2611 clock_gettime_mono(&ts1);
2612 result = SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, name);
2613 clock_gettime_mono(&ts2);
2614 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2616 if (timediff > audit_timeout) {
2617 smb_time_audit_log_fsp("fremovexattr", timediff, fsp);
2623 static int smb_time_audit_fsetxattr(struct vfs_handle_struct *handle,
2624 struct files_struct *fsp, const char *name,
2625 const void *value, size_t size, int flags)
2628 struct timespec ts1,ts2;
2631 clock_gettime_mono(&ts1);
2632 result = SMB_VFS_NEXT_FSETXATTR(handle, fsp, name, value, size, flags);
2633 clock_gettime_mono(&ts2);
2634 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2636 if (timediff > audit_timeout) {
2637 smb_time_audit_log_fsp("fsetxattr", timediff, fsp);
2643 static bool smb_time_audit_aio_force(struct vfs_handle_struct *handle,
2644 struct files_struct *fsp)
2647 struct timespec ts1,ts2;
2650 clock_gettime_mono(&ts1);
2651 result = SMB_VFS_NEXT_AIO_FORCE(handle, fsp);
2652 clock_gettime_mono(&ts2);
2653 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2655 if (timediff > audit_timeout) {
2656 smb_time_audit_log_fsp("aio_force", timediff, fsp);
2662 static NTSTATUS smb_time_audit_durable_cookie(struct vfs_handle_struct *handle,
2663 struct files_struct *fsp,
2664 TALLOC_CTX *mem_ctx,
2668 struct timespec ts1,ts2;
2671 clock_gettime_mono(&ts1);
2672 result = SMB_VFS_NEXT_DURABLE_COOKIE(handle, fsp, mem_ctx, cookie);
2673 clock_gettime_mono(&ts2);
2674 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2676 if (timediff > audit_timeout) {
2677 smb_time_audit_log_fsp("durable_cookie", timediff, fsp);
2683 static NTSTATUS smb_time_audit_durable_disconnect(struct vfs_handle_struct *handle,
2684 struct files_struct *fsp,
2685 const DATA_BLOB old_cookie,
2686 TALLOC_CTX *mem_ctx,
2687 DATA_BLOB *new_cookie)
2690 struct timespec ts1,ts2;
2693 clock_gettime_mono(&ts1);
2694 result = SMB_VFS_NEXT_DURABLE_DISCONNECT(handle, fsp, old_cookie,
2695 mem_ctx, new_cookie);
2696 clock_gettime_mono(&ts2);
2697 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2699 if (timediff > audit_timeout) {
2700 smb_time_audit_log_fsp("durable_disconnect", timediff, fsp);
2706 static NTSTATUS smb_time_audit_durable_reconnect(struct vfs_handle_struct *handle,
2707 struct smb_request *smb1req,
2708 struct smbXsrv_open *op,
2709 const DATA_BLOB old_cookie,
2710 TALLOC_CTX *mem_ctx,
2711 struct files_struct **fsp,
2712 DATA_BLOB *new_cookie)
2715 struct timespec ts1,ts2;
2718 clock_gettime_mono(&ts1);
2719 result = SMB_VFS_NEXT_DURABLE_RECONNECT(handle, smb1req, op, old_cookie,
2720 mem_ctx, fsp, new_cookie);
2721 clock_gettime_mono(&ts2);
2722 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2724 if (timediff > audit_timeout) {
2725 smb_time_audit_log("durable_reconnect", timediff);
2731 /* VFS operations */
2733 static struct vfs_fn_pointers vfs_time_audit_fns = {
2734 .connect_fn = smb_time_audit_connect,
2735 .disconnect_fn = smb_time_audit_disconnect,
2736 .disk_free_fn = smb_time_audit_disk_free,
2737 .get_quota_fn = smb_time_audit_get_quota,
2738 .set_quota_fn = smb_time_audit_set_quota,
2739 .get_shadow_copy_data_fn = smb_time_audit_get_shadow_copy_data,
2740 .statvfs_fn = smb_time_audit_statvfs,
2741 .fs_capabilities_fn = smb_time_audit_fs_capabilities,
2742 .get_dfs_referrals_fn = smb_time_audit_get_dfs_referrals,
2743 .create_dfs_pathat_fn = smb_time_audit_create_dfs_pathat,
2744 .read_dfs_pathat_fn = smb_time_audit_read_dfs_pathat,
2745 .fdopendir_fn = smb_time_audit_fdopendir,
2746 .readdir_fn = smb_time_audit_readdir,
2747 .seekdir_fn = smb_time_audit_seekdir,
2748 .telldir_fn = smb_time_audit_telldir,
2749 .rewind_dir_fn = smb_time_audit_rewinddir,
2750 .mkdirat_fn = smb_time_audit_mkdirat,
2751 .closedir_fn = smb_time_audit_closedir,
2752 .openat_fn = smb_time_audit_openat,
2753 .create_file_fn = smb_time_audit_create_file,
2754 .close_fn = smb_time_audit_close,
2755 .pread_fn = smb_time_audit_pread,
2756 .pread_send_fn = smb_time_audit_pread_send,
2757 .pread_recv_fn = smb_time_audit_pread_recv,
2758 .pwrite_fn = smb_time_audit_pwrite,
2759 .pwrite_send_fn = smb_time_audit_pwrite_send,
2760 .pwrite_recv_fn = smb_time_audit_pwrite_recv,
2761 .lseek_fn = smb_time_audit_lseek,
2762 .sendfile_fn = smb_time_audit_sendfile,
2763 .recvfile_fn = smb_time_audit_recvfile,
2764 .renameat_fn = smb_time_audit_renameat,
2765 .fsync_send_fn = smb_time_audit_fsync_send,
2766 .fsync_recv_fn = smb_time_audit_fsync_recv,
2767 .stat_fn = smb_time_audit_stat,
2768 .fstat_fn = smb_time_audit_fstat,
2769 .lstat_fn = smb_time_audit_lstat,
2770 .get_alloc_size_fn = smb_time_audit_get_alloc_size,
2771 .unlinkat_fn = smb_time_audit_unlinkat,
2772 .fchmod_fn = smb_time_audit_fchmod,
2773 .fchown_fn = smb_time_audit_fchown,
2774 .lchown_fn = smb_time_audit_lchown,
2775 .chdir_fn = smb_time_audit_chdir,
2776 .getwd_fn = smb_time_audit_getwd,
2777 .fntimes_fn = smb_time_audit_fntimes,
2778 .ftruncate_fn = smb_time_audit_ftruncate,
2779 .fallocate_fn = smb_time_audit_fallocate,
2780 .lock_fn = smb_time_audit_lock,
2781 .kernel_flock_fn = smb_time_audit_kernel_flock,
2782 .fcntl_fn = smb_time_audit_fcntl,
2783 .linux_setlease_fn = smb_time_audit_linux_setlease,
2784 .getlock_fn = smb_time_audit_getlock,
2785 .symlinkat_fn = smb_time_audit_symlinkat,
2786 .readlinkat_fn = smb_time_audit_readlinkat,
2787 .linkat_fn = smb_time_audit_linkat,
2788 .mknodat_fn = smb_time_audit_mknodat,
2789 .realpath_fn = smb_time_audit_realpath,
2790 .chflags_fn = smb_time_audit_chflags,
2791 .fchflags_fn = smb_time_audit_fchflags,
2792 .file_id_create_fn = smb_time_audit_file_id_create,
2793 .fs_file_id_fn = smb_time_audit_fs_file_id,
2794 .offload_read_send_fn = smb_time_audit_offload_read_send,
2795 .offload_read_recv_fn = smb_time_audit_offload_read_recv,
2796 .offload_write_send_fn = smb_time_audit_offload_write_send,
2797 .offload_write_recv_fn = smb_time_audit_offload_write_recv,
2798 .fget_compression_fn = smb_time_audit_fget_compression,
2799 .set_compression_fn = smb_time_audit_set_compression,
2800 .snap_check_path_fn = smb_time_audit_snap_check_path,
2801 .snap_create_fn = smb_time_audit_snap_create,
2802 .snap_delete_fn = smb_time_audit_snap_delete,
2803 .fstreaminfo_fn = smb_time_audit_fstreaminfo,
2804 .get_real_filename_fn = smb_time_audit_get_real_filename,
2805 .connectpath_fn = smb_time_audit_connectpath,
2806 .brl_lock_windows_fn = smb_time_audit_brl_lock_windows,
2807 .brl_unlock_windows_fn = smb_time_audit_brl_unlock_windows,
2808 .strict_lock_check_fn = smb_time_audit_strict_lock_check,
2809 .translate_name_fn = smb_time_audit_translate_name,
2810 .parent_pathname_fn = smb_time_audit_parent_pathname,
2811 .fsctl_fn = smb_time_audit_fsctl,
2812 .get_dos_attributes_send_fn = smb_time_audit_get_dos_attributes_send,
2813 .get_dos_attributes_recv_fn = smb_time_audit_get_dos_attributes_recv,
2814 .fget_dos_attributes_fn = smb_time_fget_dos_attributes,
2815 .fset_dos_attributes_fn = smb_time_fset_dos_attributes,
2816 .fget_nt_acl_fn = smb_time_audit_fget_nt_acl,
2817 .fset_nt_acl_fn = smb_time_audit_fset_nt_acl,
2818 .audit_file_fn = smb_time_audit_audit_file,
2819 .sys_acl_get_fd_fn = smb_time_audit_sys_acl_get_fd,
2820 .sys_acl_blob_get_fd_fn = smb_time_audit_sys_acl_blob_get_fd,
2821 .sys_acl_set_fd_fn = smb_time_audit_sys_acl_set_fd,
2822 .sys_acl_delete_def_fd_fn = smb_time_audit_sys_acl_delete_def_fd,
2823 .getxattr_fn = smb_time_audit_getxattr,
2824 .getxattrat_send_fn = smb_time_audit_getxattrat_send,
2825 .getxattrat_recv_fn = smb_time_audit_getxattrat_recv,
2826 .fgetxattr_fn = smb_time_audit_fgetxattr,
2827 .flistxattr_fn = smb_time_audit_flistxattr,
2828 .fremovexattr_fn = smb_time_audit_fremovexattr,
2829 .fsetxattr_fn = smb_time_audit_fsetxattr,
2830 .aio_force_fn = smb_time_audit_aio_force,
2831 .durable_cookie_fn = smb_time_audit_durable_cookie,
2832 .durable_disconnect_fn = smb_time_audit_durable_disconnect,
2833 .durable_reconnect_fn = smb_time_audit_durable_reconnect,
2834 .freaddir_attr_fn = smb_time_audit_freaddir_attr,
2839 NTSTATUS vfs_time_audit_init(TALLOC_CTX *ctx)
2841 smb_vfs_assert_all_fns(&vfs_time_audit_fns, "time_audit");
2843 audit_timeout = (double)lp_parm_int(-1, "time_audit", "timeout",
2845 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "time_audit",
2846 &vfs_time_audit_fns);