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;
372 struct smb_filename *full_fname = NULL;
374 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
377 if (full_fname == NULL) {
378 return NT_STATUS_NO_MEMORY;
381 clock_gettime_mono(&ts1);
382 result = SMB_VFS_NEXT_READ_DFS_PATHAT(handle,
388 clock_gettime_mono(&ts2);
389 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
391 if (timediff > audit_timeout) {
392 smb_time_audit_log_smb_fname("read_dfs_pathat",
397 TALLOC_FREE(full_fname);
401 static NTSTATUS smb_time_audit_snap_check_path(struct vfs_handle_struct *handle,
403 const char *service_path,
407 struct timespec ts1,ts2;
410 clock_gettime_mono(&ts1);
411 status = SMB_VFS_NEXT_SNAP_CHECK_PATH(handle, mem_ctx, service_path,
413 clock_gettime_mono(&ts2);
414 timediff = nsec_time_diff(&ts2, &ts1) * 1.0e-9;
416 if (timediff > audit_timeout) {
417 smb_time_audit_log("snap_check_path", timediff);
423 static NTSTATUS smb_time_audit_snap_create(struct vfs_handle_struct *handle,
425 const char *base_volume,
432 struct timespec ts1,ts2;
435 clock_gettime_mono(&ts1);
436 status = SMB_VFS_NEXT_SNAP_CREATE(handle, mem_ctx, base_volume, tstamp,
437 rw, base_path, snap_path);
438 clock_gettime_mono(&ts2);
439 timediff = nsec_time_diff(&ts2 ,&ts1) * 1.0e-9;
441 if (timediff > audit_timeout) {
442 smb_time_audit_log("snap_create", timediff);
448 static NTSTATUS smb_time_audit_snap_delete(struct vfs_handle_struct *handle,
454 struct timespec ts1,ts2;
457 clock_gettime_mono(&ts1);
458 status = SMB_VFS_NEXT_SNAP_DELETE(handle, mem_ctx, base_path,
460 clock_gettime_mono(&ts2);
461 timediff = nsec_time_diff(&ts2, &ts1) * 1.0e-9;
463 if (timediff > audit_timeout) {
464 smb_time_audit_log("snap_delete", timediff);
470 static DIR *smb_time_audit_fdopendir(vfs_handle_struct *handle,
472 const char *mask, uint32_t attr)
475 struct timespec ts1,ts2;
478 clock_gettime_mono(&ts1);
479 result = SMB_VFS_NEXT_FDOPENDIR(handle, fsp, mask, attr);
480 clock_gettime_mono(&ts2);
481 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
483 if (timediff > audit_timeout) {
484 smb_time_audit_log_fsp("fdopendir", timediff, fsp);
490 static struct dirent *smb_time_audit_readdir(vfs_handle_struct *handle,
491 struct files_struct *dirfsp,
493 SMB_STRUCT_STAT *sbuf)
495 struct dirent *result;
496 struct timespec ts1,ts2;
499 clock_gettime_mono(&ts1);
500 result = SMB_VFS_NEXT_READDIR(handle, dirfsp, dirp, sbuf);
501 clock_gettime_mono(&ts2);
502 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
504 if (timediff > audit_timeout) {
505 smb_time_audit_log("readdir", timediff);
511 static void smb_time_audit_seekdir(vfs_handle_struct *handle,
512 DIR *dirp, long offset)
514 struct timespec ts1,ts2;
517 clock_gettime_mono(&ts1);
518 SMB_VFS_NEXT_SEEKDIR(handle, dirp, offset);
519 clock_gettime_mono(&ts2);
520 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
522 if (timediff > audit_timeout) {
523 smb_time_audit_log("seekdir", timediff);
528 static long smb_time_audit_telldir(vfs_handle_struct *handle,
532 struct timespec ts1,ts2;
535 clock_gettime_mono(&ts1);
536 result = SMB_VFS_NEXT_TELLDIR(handle, dirp);
537 clock_gettime_mono(&ts2);
538 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
540 if (timediff > audit_timeout) {
541 smb_time_audit_log("telldir", timediff);
547 static void smb_time_audit_rewinddir(vfs_handle_struct *handle,
550 struct timespec ts1,ts2;
553 clock_gettime_mono(&ts1);
554 SMB_VFS_NEXT_REWINDDIR(handle, dirp);
555 clock_gettime_mono(&ts2);
556 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
558 if (timediff > audit_timeout) {
559 smb_time_audit_log("rewinddir", timediff);
564 static int smb_time_audit_mkdirat(vfs_handle_struct *handle,
565 struct files_struct *dirfsp,
566 const struct smb_filename *smb_fname,
569 struct smb_filename *full_fname = NULL;
571 struct timespec ts1,ts2;
574 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
577 if (full_fname == NULL) {
582 clock_gettime_mono(&ts1);
583 result = SMB_VFS_NEXT_MKDIRAT(handle,
587 clock_gettime_mono(&ts2);
588 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
590 if (timediff > audit_timeout) {
591 smb_time_audit_log_smb_fname("mkdirat",
596 TALLOC_FREE(full_fname);
601 static int smb_time_audit_closedir(vfs_handle_struct *handle,
605 struct timespec ts1,ts2;
608 clock_gettime_mono(&ts1);
609 result = SMB_VFS_NEXT_CLOSEDIR(handle, dirp);
610 clock_gettime_mono(&ts2);
611 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
613 if (timediff > audit_timeout) {
614 smb_time_audit_log("closedir", timediff);
620 static int smb_time_audit_openat(vfs_handle_struct *handle,
621 const struct files_struct *dirfsp,
622 const struct smb_filename *smb_fname,
623 struct files_struct *fsp,
628 struct timespec ts1,ts2;
631 clock_gettime_mono(&ts1);
632 result = SMB_VFS_NEXT_OPENAT(handle,
638 clock_gettime_mono(&ts2);
639 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
641 if (timediff > audit_timeout) {
642 smb_time_audit_log_fsp("openat", timediff, fsp);
648 static NTSTATUS smb_time_audit_create_file(vfs_handle_struct *handle,
649 struct smb_request *req,
650 struct files_struct *dirfsp,
651 struct smb_filename *fname,
652 uint32_t access_mask,
653 uint32_t share_access,
654 uint32_t create_disposition,
655 uint32_t create_options,
656 uint32_t file_attributes,
657 uint32_t oplock_request,
658 const struct smb2_lease *lease,
659 uint64_t allocation_size,
660 uint32_t private_flags,
661 struct security_descriptor *sd,
662 struct ea_list *ea_list,
663 files_struct **result_fsp,
665 const struct smb2_create_blobs *in_context_blobs,
666 struct smb2_create_blobs *out_context_blobs)
669 struct timespec ts1,ts2;
672 clock_gettime_mono(&ts1);
673 result = SMB_VFS_NEXT_CREATE_FILE(
678 access_mask, /* access_mask */
679 share_access, /* share_access */
680 create_disposition, /* create_disposition*/
681 create_options, /* create_options */
682 file_attributes, /* file_attributes */
683 oplock_request, /* oplock_request */
685 allocation_size, /* allocation_size */
688 ea_list, /* ea_list */
689 result_fsp, /* result */
691 in_context_blobs, out_context_blobs); /* create context */
692 clock_gettime_mono(&ts2);
693 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
695 if (timediff > audit_timeout) {
697 * can't use result_fsp this time, may have
698 * invalid content causing smbd crash
700 smb_time_audit_log_smb_fname("create_file", timediff,
707 static int smb_time_audit_close(vfs_handle_struct *handle, files_struct *fsp)
710 struct timespec ts1,ts2;
713 clock_gettime_mono(&ts1);
714 result = SMB_VFS_NEXT_CLOSE(handle, fsp);
715 clock_gettime_mono(&ts2);
716 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
718 if (timediff > audit_timeout) {
719 smb_time_audit_log_fsp("close", timediff, fsp);
725 static ssize_t smb_time_audit_pread(vfs_handle_struct *handle,
727 void *data, size_t n, off_t offset)
730 struct timespec ts1,ts2;
733 clock_gettime_mono(&ts1);
734 result = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
735 clock_gettime_mono(&ts2);
736 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
738 if (timediff > audit_timeout) {
739 smb_time_audit_log_fsp("pread", timediff, fsp);
745 struct smb_time_audit_pread_state {
746 struct files_struct *fsp;
748 struct vfs_aio_state vfs_aio_state;
751 static void smb_time_audit_pread_done(struct tevent_req *subreq);
753 static struct tevent_req *smb_time_audit_pread_send(
754 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
755 struct tevent_context *ev, struct files_struct *fsp,
756 void *data, size_t n, off_t offset)
758 struct tevent_req *req, *subreq;
759 struct smb_time_audit_pread_state *state;
761 req = tevent_req_create(mem_ctx, &state,
762 struct smb_time_audit_pread_state);
768 subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
770 if (tevent_req_nomem(subreq, req)) {
771 return tevent_req_post(req, ev);
773 tevent_req_set_callback(subreq, smb_time_audit_pread_done, req);
777 static void smb_time_audit_pread_done(struct tevent_req *subreq)
779 struct tevent_req *req = tevent_req_callback_data(
780 subreq, struct tevent_req);
781 struct smb_time_audit_pread_state *state = tevent_req_data(
782 req, struct smb_time_audit_pread_state);
784 state->ret = SMB_VFS_PREAD_RECV(subreq, &state->vfs_aio_state);
786 tevent_req_done(req);
789 static ssize_t smb_time_audit_pread_recv(struct tevent_req *req,
790 struct vfs_aio_state *vfs_aio_state)
792 struct smb_time_audit_pread_state *state = tevent_req_data(
793 req, struct smb_time_audit_pread_state);
796 timediff = state->vfs_aio_state.duration * 1.0e-9;
798 if (timediff > audit_timeout) {
799 smb_time_audit_log_fsp("async pread", timediff, state->fsp);
802 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
805 *vfs_aio_state = state->vfs_aio_state;
809 static ssize_t smb_time_audit_pwrite(vfs_handle_struct *handle,
811 const void *data, size_t n,
815 struct timespec ts1,ts2;
818 clock_gettime_mono(&ts1);
819 result = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
820 clock_gettime_mono(&ts2);
821 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
823 if (timediff > audit_timeout) {
824 smb_time_audit_log_fsp("pwrite", timediff, fsp);
830 struct smb_time_audit_pwrite_state {
831 struct files_struct *fsp;
833 struct vfs_aio_state vfs_aio_state;
836 static void smb_time_audit_pwrite_done(struct tevent_req *subreq);
838 static struct tevent_req *smb_time_audit_pwrite_send(
839 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
840 struct tevent_context *ev, struct files_struct *fsp,
841 const void *data, size_t n, off_t offset)
843 struct tevent_req *req, *subreq;
844 struct smb_time_audit_pwrite_state *state;
846 req = tevent_req_create(mem_ctx, &state,
847 struct smb_time_audit_pwrite_state);
853 subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
855 if (tevent_req_nomem(subreq, req)) {
856 return tevent_req_post(req, ev);
858 tevent_req_set_callback(subreq, smb_time_audit_pwrite_done, req);
862 static void smb_time_audit_pwrite_done(struct tevent_req *subreq)
864 struct tevent_req *req = tevent_req_callback_data(
865 subreq, struct tevent_req);
866 struct smb_time_audit_pwrite_state *state = tevent_req_data(
867 req, struct smb_time_audit_pwrite_state);
869 state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->vfs_aio_state);
871 tevent_req_done(req);
874 static ssize_t smb_time_audit_pwrite_recv(struct tevent_req *req,
875 struct vfs_aio_state *vfs_aio_state)
877 struct smb_time_audit_pwrite_state *state = tevent_req_data(
878 req, struct smb_time_audit_pwrite_state);
881 timediff = state->vfs_aio_state.duration * 1.0e-9;
883 if (timediff > audit_timeout) {
884 smb_time_audit_log_fsp("async pwrite", timediff, state->fsp);
887 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
890 *vfs_aio_state = state->vfs_aio_state;
894 static off_t smb_time_audit_lseek(vfs_handle_struct *handle,
896 off_t offset, int whence)
899 struct timespec ts1,ts2;
902 clock_gettime_mono(&ts1);
903 result = SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence);
904 clock_gettime_mono(&ts2);
905 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
907 if (timediff > audit_timeout) {
908 smb_time_audit_log_fsp("lseek", timediff, fsp);
914 static ssize_t smb_time_audit_sendfile(vfs_handle_struct *handle, int tofd,
915 files_struct *fromfsp,
916 const DATA_BLOB *hdr, off_t offset,
920 struct timespec ts1,ts2;
923 clock_gettime_mono(&ts1);
924 result = SMB_VFS_NEXT_SENDFILE(handle, tofd, fromfsp, hdr, offset, n);
925 clock_gettime_mono(&ts2);
926 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
928 if (timediff > audit_timeout) {
929 smb_time_audit_log_fsp("sendfile", timediff, fromfsp);
935 static ssize_t smb_time_audit_recvfile(vfs_handle_struct *handle, int fromfd,
941 struct timespec ts1,ts2;
944 clock_gettime_mono(&ts1);
945 result = SMB_VFS_NEXT_RECVFILE(handle, fromfd, tofsp, offset, n);
946 clock_gettime_mono(&ts2);
947 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
949 if (timediff > audit_timeout) {
950 smb_time_audit_log_fsp("recvfile", timediff, tofsp);
956 static int smb_time_audit_renameat(vfs_handle_struct *handle,
957 files_struct *srcfsp,
958 const struct smb_filename *oldname,
959 files_struct *dstfsp,
960 const struct smb_filename *newname)
963 struct timespec ts1,ts2;
965 struct smb_filename *new_full_fname = NULL;
967 new_full_fname = full_path_from_dirfsp_atname(talloc_tos(),
970 if (new_full_fname == NULL) {
974 clock_gettime_mono(&ts1);
975 result = SMB_VFS_NEXT_RENAMEAT(handle,
980 clock_gettime_mono(&ts2);
981 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
983 if (timediff > audit_timeout) {
984 smb_time_audit_log_smb_fname("renameat",
989 TALLOC_FREE(new_full_fname);
993 struct smb_time_audit_fsync_state {
994 struct files_struct *fsp;
996 struct vfs_aio_state vfs_aio_state;
999 static void smb_time_audit_fsync_done(struct tevent_req *subreq);
1001 static struct tevent_req *smb_time_audit_fsync_send(
1002 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1003 struct tevent_context *ev, struct files_struct *fsp)
1005 struct tevent_req *req, *subreq;
1006 struct smb_time_audit_fsync_state *state;
1008 req = tevent_req_create(mem_ctx, &state,
1009 struct smb_time_audit_fsync_state);
1015 subreq = SMB_VFS_NEXT_FSYNC_SEND(state, ev, handle, fsp);
1016 if (tevent_req_nomem(subreq, req)) {
1017 return tevent_req_post(req, ev);
1019 tevent_req_set_callback(subreq, smb_time_audit_fsync_done, req);
1023 static void smb_time_audit_fsync_done(struct tevent_req *subreq)
1025 struct tevent_req *req = tevent_req_callback_data(
1026 subreq, struct tevent_req);
1027 struct smb_time_audit_fsync_state *state = tevent_req_data(
1028 req, struct smb_time_audit_fsync_state);
1030 state->ret = SMB_VFS_FSYNC_RECV(subreq, &state->vfs_aio_state);
1031 TALLOC_FREE(subreq);
1032 tevent_req_done(req);
1035 static int smb_time_audit_fsync_recv(struct tevent_req *req,
1036 struct vfs_aio_state *vfs_aio_state)
1038 struct smb_time_audit_fsync_state *state = tevent_req_data(
1039 req, struct smb_time_audit_fsync_state);
1042 timediff = state->vfs_aio_state.duration * 1.0e-9;
1044 if (timediff > audit_timeout) {
1045 smb_time_audit_log_fsp("async fsync", timediff, state->fsp);
1048 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1051 *vfs_aio_state = state->vfs_aio_state;
1055 static int smb_time_audit_stat(vfs_handle_struct *handle,
1056 struct smb_filename *fname)
1059 struct timespec ts1,ts2;
1062 clock_gettime_mono(&ts1);
1063 result = SMB_VFS_NEXT_STAT(handle, fname);
1064 clock_gettime_mono(&ts2);
1065 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1067 if (timediff > audit_timeout) {
1068 smb_time_audit_log_smb_fname("stat", timediff, fname);
1074 static int smb_time_audit_fstat(vfs_handle_struct *handle, files_struct *fsp,
1075 SMB_STRUCT_STAT *sbuf)
1078 struct timespec ts1,ts2;
1081 clock_gettime_mono(&ts1);
1082 result = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1083 clock_gettime_mono(&ts2);
1084 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1086 if (timediff > audit_timeout) {
1087 smb_time_audit_log_fsp("fstat", timediff, fsp);
1093 static int smb_time_audit_lstat(vfs_handle_struct *handle,
1094 struct smb_filename *path)
1097 struct timespec ts1,ts2;
1100 clock_gettime_mono(&ts1);
1101 result = SMB_VFS_NEXT_LSTAT(handle, path);
1102 clock_gettime_mono(&ts2);
1103 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1105 if (timediff > audit_timeout) {
1106 smb_time_audit_log_smb_fname("lstat", timediff, path);
1112 static int smb_time_audit_fstatat(
1113 struct vfs_handle_struct *handle,
1114 const struct files_struct *dirfsp,
1115 const struct smb_filename *smb_fname,
1116 SMB_STRUCT_STAT *sbuf,
1120 struct timespec ts1,ts2;
1123 clock_gettime_mono(&ts1);
1124 result = SMB_VFS_NEXT_FSTATAT(handle, dirfsp, smb_fname, sbuf, flags);
1125 clock_gettime_mono(&ts2);
1126 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1128 if (timediff > audit_timeout) {
1129 smb_time_audit_log_smb_fname("fstatat", timediff, smb_fname);
1135 static uint64_t smb_time_audit_get_alloc_size(vfs_handle_struct *handle,
1137 const SMB_STRUCT_STAT *sbuf)
1140 struct timespec ts1,ts2;
1143 clock_gettime_mono(&ts1);
1144 result = SMB_VFS_NEXT_GET_ALLOC_SIZE(handle, fsp, sbuf);
1145 clock_gettime_mono(&ts2);
1146 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1148 if (timediff > audit_timeout) {
1149 smb_time_audit_log_fsp("get_alloc_size", timediff, fsp);
1155 static int smb_time_audit_unlinkat(vfs_handle_struct *handle,
1156 struct files_struct *dirfsp,
1157 const struct smb_filename *path,
1160 struct smb_filename *full_fname = NULL;
1162 struct timespec ts1,ts2;
1165 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1168 if (full_fname == NULL) {
1172 clock_gettime_mono(&ts1);
1173 result = SMB_VFS_NEXT_UNLINKAT(handle,
1177 clock_gettime_mono(&ts2);
1178 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1180 if (timediff > audit_timeout) {
1181 smb_time_audit_log_smb_fname("unlinkat", timediff, full_fname);
1184 TALLOC_FREE(full_fname);
1188 static int smb_time_audit_fchmod(vfs_handle_struct *handle, files_struct *fsp,
1192 struct timespec ts1,ts2;
1195 clock_gettime_mono(&ts1);
1196 result = SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1197 clock_gettime_mono(&ts2);
1198 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1200 if (timediff > audit_timeout) {
1201 smb_time_audit_log_fsp("fchmod", timediff, fsp);
1207 static int smb_time_audit_fchown(vfs_handle_struct *handle, files_struct *fsp,
1208 uid_t uid, gid_t gid)
1211 struct timespec ts1,ts2;
1214 clock_gettime_mono(&ts1);
1215 result = SMB_VFS_NEXT_FCHOWN(handle, fsp, uid, gid);
1216 clock_gettime_mono(&ts2);
1217 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1219 if (timediff > audit_timeout) {
1220 smb_time_audit_log_fsp("fchown", timediff, fsp);
1226 static int smb_time_audit_lchown(vfs_handle_struct *handle,
1227 const struct smb_filename *smb_fname,
1232 struct timespec ts1,ts2;
1235 clock_gettime_mono(&ts1);
1236 result = SMB_VFS_NEXT_LCHOWN(handle, smb_fname, uid, gid);
1237 clock_gettime_mono(&ts2);
1238 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1240 if (timediff > audit_timeout) {
1241 smb_time_audit_log_fname("lchown",
1243 smb_fname->base_name);
1249 static int smb_time_audit_chdir(vfs_handle_struct *handle,
1250 const struct smb_filename *smb_fname)
1253 struct timespec ts1,ts2;
1256 clock_gettime_mono(&ts1);
1257 result = SMB_VFS_NEXT_CHDIR(handle, smb_fname);
1258 clock_gettime_mono(&ts2);
1259 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1261 if (timediff > audit_timeout) {
1262 smb_time_audit_log_fname("chdir",
1264 smb_fname->base_name);
1270 static struct smb_filename *smb_time_audit_getwd(vfs_handle_struct *handle,
1271 TALLOC_CTX *mem_ctx)
1273 struct smb_filename *result;
1274 struct timespec ts1,ts2;
1277 clock_gettime_mono(&ts1);
1278 result = SMB_VFS_NEXT_GETWD(handle, mem_ctx);
1279 clock_gettime_mono(&ts2);
1280 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1282 if (timediff > audit_timeout) {
1283 smb_time_audit_log("getwd", timediff);
1289 static int smb_time_audit_fntimes(vfs_handle_struct *handle,
1291 struct smb_file_time *ft)
1294 struct timespec ts1,ts2;
1297 clock_gettime_mono(&ts1);
1298 result = SMB_VFS_NEXT_FNTIMES(handle, fsp, ft);
1299 clock_gettime_mono(&ts2);
1300 timediff = nsec_time_diff(&ts2, &ts1) * 1.0e-9;
1302 if (timediff > audit_timeout) {
1303 smb_time_audit_log_fsp("fntimes", timediff, fsp);
1309 static int smb_time_audit_ftruncate(vfs_handle_struct *handle,
1314 struct timespec ts1,ts2;
1317 clock_gettime_mono(&ts1);
1318 result = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1319 clock_gettime_mono(&ts2);
1320 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1322 if (timediff > audit_timeout) {
1323 smb_time_audit_log_fsp("ftruncate", timediff, fsp);
1329 static int smb_time_audit_fallocate(vfs_handle_struct *handle,
1336 int saved_errno = 0;
1337 struct timespec ts1,ts2;
1340 clock_gettime_mono(&ts1);
1341 result = SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
1343 saved_errno = errno;
1345 clock_gettime_mono(&ts2);
1346 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1348 if (timediff > audit_timeout) {
1349 smb_time_audit_log_fsp("fallocate", timediff, fsp);
1352 errno = saved_errno;
1357 static bool smb_time_audit_lock(vfs_handle_struct *handle, files_struct *fsp,
1358 int op, off_t offset, off_t count,
1362 struct timespec ts1,ts2;
1365 clock_gettime_mono(&ts1);
1366 result = SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type);
1367 clock_gettime_mono(&ts2);
1368 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1370 if (timediff > audit_timeout) {
1371 smb_time_audit_log_fsp("lock", timediff, fsp);
1377 static int smb_time_audit_filesystem_sharemode(struct vfs_handle_struct *handle,
1378 struct files_struct *fsp,
1379 uint32_t share_access,
1380 uint32_t access_mask)
1383 struct timespec ts1,ts2;
1386 clock_gettime_mono(&ts1);
1387 result = SMB_VFS_NEXT_FILESYSTEM_SHAREMODE(handle,
1391 clock_gettime_mono(&ts2);
1392 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1394 if (timediff > audit_timeout) {
1395 smb_time_audit_log_fsp("filesystem_sharemode", timediff, fsp);
1401 static int smb_time_audit_fcntl(struct vfs_handle_struct *handle,
1402 struct files_struct *fsp,
1403 int cmd, va_list cmd_arg)
1406 va_list dup_cmd_arg;
1408 struct timespec ts1,ts2;
1411 va_copy(dup_cmd_arg, cmd_arg);
1412 arg = va_arg(dup_cmd_arg, void *);
1413 clock_gettime_mono(&ts1);
1414 result = SMB_VFS_NEXT_FCNTL(handle, fsp, cmd, arg);
1415 clock_gettime_mono(&ts2);
1416 va_end(dup_cmd_arg);
1418 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1419 if (timediff > audit_timeout) {
1420 smb_time_audit_log_fsp("fcntl", timediff, fsp);
1426 static int smb_time_audit_linux_setlease(vfs_handle_struct *handle,
1431 struct timespec ts1,ts2;
1434 clock_gettime_mono(&ts1);
1435 result = SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
1436 clock_gettime_mono(&ts2);
1437 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1439 if (timediff > audit_timeout) {
1440 smb_time_audit_log_fsp("linux_setlease", timediff, fsp);
1446 static bool smb_time_audit_getlock(vfs_handle_struct *handle,
1448 off_t *poffset, off_t *pcount,
1449 int *ptype, pid_t *ppid)
1452 struct timespec ts1,ts2;
1455 clock_gettime_mono(&ts1);
1456 result = SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype,
1458 clock_gettime_mono(&ts2);
1459 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1461 if (timediff > audit_timeout) {
1462 smb_time_audit_log_fsp("getlock", timediff, fsp);
1468 static int smb_time_audit_symlinkat(vfs_handle_struct *handle,
1469 const struct smb_filename *link_contents,
1470 struct files_struct *dirfsp,
1471 const struct smb_filename *new_smb_fname)
1473 struct smb_filename *full_fname = NULL;
1475 struct timespec ts1,ts2;
1478 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1481 if (full_fname == NULL) {
1486 clock_gettime_mono(&ts1);
1487 result = SMB_VFS_NEXT_SYMLINKAT(handle,
1491 clock_gettime_mono(&ts2);
1492 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1494 if (timediff > audit_timeout) {
1495 smb_time_audit_log_fname("symlinkat", timediff,
1496 full_fname->base_name);
1499 TALLOC_FREE(full_fname);
1503 static int smb_time_audit_readlinkat(vfs_handle_struct *handle,
1504 const struct files_struct *dirfsp,
1505 const struct smb_filename *smb_fname,
1509 struct smb_filename *full_fname = NULL;
1511 struct timespec ts1,ts2;
1514 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1517 if (full_fname == NULL) {
1522 clock_gettime_mono(&ts1);
1523 result = SMB_VFS_NEXT_READLINKAT(handle,
1528 clock_gettime_mono(&ts2);
1529 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1531 if (timediff > audit_timeout) {
1532 smb_time_audit_log_fname("readlinkat", timediff,
1533 full_fname->base_name);
1536 TALLOC_FREE(full_fname);
1540 static int smb_time_audit_linkat(vfs_handle_struct *handle,
1541 files_struct *srcfsp,
1542 const struct smb_filename *old_smb_fname,
1543 files_struct *dstfsp,
1544 const struct smb_filename *new_smb_fname,
1547 struct smb_filename *new_full_fname = NULL;
1549 struct timespec ts1,ts2;
1552 new_full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1555 if (new_full_fname == NULL) {
1560 clock_gettime_mono(&ts1);
1561 result = SMB_VFS_NEXT_LINKAT(handle,
1567 clock_gettime_mono(&ts2);
1568 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1570 if (timediff > audit_timeout) {
1571 smb_time_audit_log_fname("linkat", timediff,
1572 new_full_fname->base_name);
1575 TALLOC_FREE(new_full_fname);
1579 static int smb_time_audit_mknodat(vfs_handle_struct *handle,
1580 files_struct *dirfsp,
1581 const struct smb_filename *smb_fname,
1585 struct smb_filename *full_fname = NULL;
1587 struct timespec ts1,ts2;
1590 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1593 if (full_fname == NULL) {
1598 clock_gettime_mono(&ts1);
1599 result = SMB_VFS_NEXT_MKNODAT(handle,
1604 clock_gettime_mono(&ts2);
1605 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1607 if (timediff > audit_timeout) {
1608 smb_time_audit_log_smb_fname("mknodat", timediff, full_fname);
1611 TALLOC_FREE(full_fname);
1615 static struct smb_filename *smb_time_audit_realpath(vfs_handle_struct *handle,
1617 const struct smb_filename *smb_fname)
1619 struct smb_filename *result_fname;
1620 struct timespec ts1,ts2;
1623 clock_gettime_mono(&ts1);
1624 result_fname = SMB_VFS_NEXT_REALPATH(handle, ctx, smb_fname);
1625 clock_gettime_mono(&ts2);
1626 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1628 if (timediff > audit_timeout) {
1629 smb_time_audit_log_fname("realpath", timediff,
1630 smb_fname->base_name);
1633 return result_fname;
1636 static int smb_time_audit_fchflags(vfs_handle_struct *handle,
1637 struct files_struct *fsp,
1641 struct timespec ts1,ts2;
1644 clock_gettime_mono(&ts1);
1645 result = SMB_VFS_NEXT_FCHFLAGS(handle, fsp, flags);
1646 clock_gettime_mono(&ts2);
1647 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1649 if (timediff > audit_timeout) {
1650 smb_time_audit_log_smb_fname("chflags",
1658 static struct file_id smb_time_audit_file_id_create(struct vfs_handle_struct *handle,
1659 const SMB_STRUCT_STAT *sbuf)
1661 struct file_id id_zero;
1662 struct file_id result;
1663 struct timespec ts1,ts2;
1666 ZERO_STRUCT(id_zero);
1668 clock_gettime_mono(&ts1);
1669 result = SMB_VFS_NEXT_FILE_ID_CREATE(handle, sbuf);
1670 clock_gettime_mono(&ts2);
1671 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1673 if (timediff > audit_timeout) {
1674 smb_time_audit_log("file_id_create", timediff);
1680 static uint64_t smb_time_audit_fs_file_id(struct vfs_handle_struct *handle,
1681 const SMB_STRUCT_STAT *sbuf)
1684 struct timespec ts1,ts2;
1687 clock_gettime_mono(&ts1);
1688 result = SMB_VFS_NEXT_FS_FILE_ID(handle, sbuf);
1689 clock_gettime_mono(&ts2);
1690 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1692 if (timediff > audit_timeout) {
1693 smb_time_audit_log("fs_file_id", timediff);
1699 static NTSTATUS smb_time_audit_fstreaminfo(vfs_handle_struct *handle,
1700 struct files_struct *fsp,
1701 TALLOC_CTX *mem_ctx,
1702 unsigned int *pnum_streams,
1703 struct stream_struct **pstreams)
1706 struct timespec ts1,ts2;
1709 clock_gettime_mono(&ts1);
1710 result = SMB_VFS_NEXT_FSTREAMINFO(handle, fsp, mem_ctx,
1711 pnum_streams, pstreams);
1712 clock_gettime_mono(&ts2);
1713 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1715 if (timediff > audit_timeout) {
1716 smb_time_audit_log_fsp("fstreaminfo", timediff, fsp);
1722 static NTSTATUS smb_time_audit_get_real_filename_at(
1723 struct vfs_handle_struct *handle,
1724 struct files_struct *dirfsp,
1726 TALLOC_CTX *mem_ctx,
1730 struct timespec ts1,ts2;
1733 clock_gettime_mono(&ts1);
1734 result = SMB_VFS_NEXT_GET_REAL_FILENAME_AT(
1735 handle, dirfsp, name, mem_ctx, found_name);
1736 clock_gettime_mono(&ts2);
1737 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1739 if (timediff > audit_timeout) {
1740 smb_time_audit_log_fname("get_real_filename_at",
1742 fsp_str_dbg(dirfsp));
1748 static const char *smb_time_audit_connectpath(vfs_handle_struct *handle,
1749 const struct smb_filename *smb_fname)
1752 struct timespec ts1,ts2;
1755 clock_gettime_mono(&ts1);
1756 result = SMB_VFS_NEXT_CONNECTPATH(handle, smb_fname);
1757 clock_gettime_mono(&ts2);
1758 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1760 if (timediff > audit_timeout) {
1761 smb_time_audit_log_fname("connectpath", timediff,
1762 smb_fname->base_name);
1768 static NTSTATUS smb_time_audit_brl_lock_windows(struct vfs_handle_struct *handle,
1769 struct byte_range_lock *br_lck,
1770 struct lock_struct *plock)
1773 struct timespec ts1,ts2;
1776 clock_gettime_mono(&ts1);
1777 result = SMB_VFS_NEXT_BRL_LOCK_WINDOWS(handle, br_lck, plock);
1778 clock_gettime_mono(&ts2);
1779 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1781 if (timediff > audit_timeout) {
1782 smb_time_audit_log_fsp("brl_lock_windows", timediff,
1789 static bool smb_time_audit_brl_unlock_windows(struct vfs_handle_struct *handle,
1790 struct byte_range_lock *br_lck,
1791 const struct lock_struct *plock)
1794 struct timespec ts1,ts2;
1797 clock_gettime_mono(&ts1);
1798 result = SMB_VFS_NEXT_BRL_UNLOCK_WINDOWS(handle, br_lck, plock);
1799 clock_gettime_mono(&ts2);
1800 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1802 if (timediff > audit_timeout) {
1803 smb_time_audit_log_fsp("brl_unlock_windows", timediff,
1810 static bool smb_time_audit_strict_lock_check(struct vfs_handle_struct *handle,
1811 struct files_struct *fsp,
1812 struct lock_struct *plock)
1815 struct timespec ts1,ts2;
1818 clock_gettime_mono(&ts1);
1819 result = SMB_VFS_NEXT_STRICT_LOCK_CHECK(handle, fsp, plock);
1820 clock_gettime_mono(&ts2);
1821 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1823 if (timediff > audit_timeout) {
1824 smb_time_audit_log_fsp("strict_lock_check", timediff, fsp);
1830 static NTSTATUS smb_time_audit_translate_name(struct vfs_handle_struct *handle,
1832 enum vfs_translate_direction direction,
1833 TALLOC_CTX *mem_ctx,
1837 struct timespec ts1,ts2;
1840 clock_gettime_mono(&ts1);
1841 result = SMB_VFS_NEXT_TRANSLATE_NAME(handle, name, direction, mem_ctx,
1843 clock_gettime_mono(&ts2);
1844 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1846 if (timediff > audit_timeout) {
1847 smb_time_audit_log_fname("translate_name", timediff, name);
1853 static NTSTATUS smb_time_audit_parent_pathname(struct vfs_handle_struct *handle,
1854 TALLOC_CTX *mem_ctx,
1855 const struct smb_filename *smb_fname_in,
1856 struct smb_filename **parent_dir_out,
1857 struct smb_filename **atname_out)
1860 struct timespec ts1,ts2;
1863 clock_gettime_mono(&ts1);
1864 result = SMB_VFS_NEXT_PARENT_PATHNAME(handle,
1869 clock_gettime_mono(&ts2);
1870 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1872 if (timediff > audit_timeout) {
1873 smb_time_audit_log_fname("parent_pathname",
1875 smb_fname_in->base_name);
1881 static NTSTATUS smb_time_audit_fsctl(struct vfs_handle_struct *handle,
1882 struct files_struct *fsp,
1886 const uint8_t *_in_data,
1888 uint8_t **_out_data,
1889 uint32_t max_out_len,
1893 struct timespec ts1,ts2;
1896 clock_gettime_mono(&ts1);
1897 result = SMB_VFS_NEXT_FSCTL(handle,
1907 clock_gettime_mono(&ts2);
1908 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1910 if (timediff > audit_timeout) {
1911 smb_time_audit_log_fsp("fsctl", timediff, fsp);
1917 struct smb_time_audit_get_dos_attributes_state {
1918 struct vfs_aio_state aio_state;
1919 files_struct *dir_fsp;
1920 const struct smb_filename *smb_fname;
1924 static void smb_time_audit_get_dos_attributes_done(struct tevent_req *subreq);
1926 static struct tevent_req *smb_time_audit_get_dos_attributes_send(
1927 TALLOC_CTX *mem_ctx,
1928 struct tevent_context *ev,
1929 struct vfs_handle_struct *handle,
1930 files_struct *dir_fsp,
1931 struct smb_filename *smb_fname)
1933 struct tevent_req *req = NULL;
1934 struct smb_time_audit_get_dos_attributes_state *state = NULL;
1935 struct tevent_req *subreq = NULL;
1937 req = tevent_req_create(mem_ctx, &state,
1938 struct smb_time_audit_get_dos_attributes_state);
1942 *state = (struct smb_time_audit_get_dos_attributes_state) {
1944 .smb_fname = smb_fname,
1947 subreq = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES_SEND(mem_ctx,
1952 if (tevent_req_nomem(subreq, req)) {
1953 return tevent_req_post(req, ev);
1955 tevent_req_set_callback(subreq,
1956 smb_time_audit_get_dos_attributes_done,
1962 static void smb_time_audit_get_dos_attributes_done(struct tevent_req *subreq)
1964 struct tevent_req *req =
1965 tevent_req_callback_data(subreq,
1967 struct smb_time_audit_get_dos_attributes_state *state =
1968 tevent_req_data(req,
1969 struct smb_time_audit_get_dos_attributes_state);
1972 status = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES_RECV(subreq,
1975 TALLOC_FREE(subreq);
1976 if (tevent_req_nterror(req, status)) {
1980 tevent_req_done(req);
1984 static NTSTATUS smb_time_audit_get_dos_attributes_recv(struct tevent_req *req,
1985 struct vfs_aio_state *aio_state,
1988 struct smb_time_audit_get_dos_attributes_state *state =
1989 tevent_req_data(req,
1990 struct smb_time_audit_get_dos_attributes_state);
1994 timediff = state->aio_state.duration * 1.0e-9;
1996 if (timediff > audit_timeout) {
1997 smb_time_audit_log_at("async get_dos_attributes",
2003 if (tevent_req_is_nterror(req, &status)) {
2004 tevent_req_received(req);
2008 *aio_state = state->aio_state;
2009 *dosmode = state->dosmode;
2010 tevent_req_received(req);
2011 return NT_STATUS_OK;
2014 static NTSTATUS smb_time_fget_dos_attributes(struct vfs_handle_struct *handle,
2015 struct files_struct *fsp,
2019 struct timespec ts1,ts2;
2022 clock_gettime_mono(&ts1);
2023 result = SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle,
2026 clock_gettime_mono(&ts2);
2027 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2029 if (timediff > audit_timeout) {
2030 smb_time_audit_log_fsp("fget_dos_attributes", timediff, fsp);
2036 static NTSTATUS smb_time_fset_dos_attributes(struct vfs_handle_struct *handle,
2037 struct files_struct *fsp,
2041 struct timespec ts1,ts2;
2044 clock_gettime_mono(&ts1);
2045 result = SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle,
2048 clock_gettime_mono(&ts2);
2049 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2051 if (timediff > audit_timeout) {
2052 smb_time_audit_log_fsp("fset_dos_attributes", timediff, fsp);
2058 struct time_audit_offload_read_state {
2059 struct vfs_handle_struct *handle;
2060 struct timespec ts_send;
2063 DATA_BLOB token_blob;
2066 static void smb_time_audit_offload_read_done(struct tevent_req *subreq);
2068 static struct tevent_req *smb_time_audit_offload_read_send(
2069 TALLOC_CTX *mem_ctx,
2070 struct tevent_context *ev,
2071 struct vfs_handle_struct *handle,
2072 struct files_struct *fsp,
2078 struct tevent_req *req = NULL;
2079 struct tevent_req *subreq = NULL;
2080 struct time_audit_offload_read_state *state = NULL;
2082 req = tevent_req_create(mem_ctx, &state,
2083 struct time_audit_offload_read_state);
2087 state->handle = handle;
2088 clock_gettime_mono(&state->ts_send);
2090 subreq = SMB_VFS_NEXT_OFFLOAD_READ_SEND(mem_ctx, ev,
2094 if (tevent_req_nomem(subreq, req)) {
2095 return tevent_req_post(req, ev);
2098 tevent_req_set_callback(subreq, smb_time_audit_offload_read_done, req);
2102 static void smb_time_audit_offload_read_done(struct tevent_req *subreq)
2104 struct tevent_req *req = tevent_req_callback_data(
2105 subreq, struct tevent_req);
2106 struct time_audit_offload_read_state *state = tevent_req_data(
2107 req, struct time_audit_offload_read_state);
2110 status = SMB_VFS_NEXT_OFFLOAD_READ_RECV(subreq,
2115 &state->token_blob);
2116 TALLOC_FREE(subreq);
2117 if (tevent_req_nterror(req, status)) {
2120 tevent_req_done(req);
2123 static NTSTATUS smb_time_audit_offload_read_recv(
2124 struct tevent_req *req,
2125 struct vfs_handle_struct *handle,
2126 TALLOC_CTX *mem_ctx,
2129 DATA_BLOB *token_blob)
2131 struct time_audit_offload_read_state *state = tevent_req_data(
2132 req, struct time_audit_offload_read_state);
2133 struct timespec ts_recv;
2137 clock_gettime_mono(&ts_recv);
2138 timediff = nsec_time_diff(&ts_recv, &state->ts_send) * 1.0e-9;
2139 if (timediff > audit_timeout) {
2140 smb_time_audit_log("offload_read", timediff);
2143 if (tevent_req_is_nterror(req, &status)) {
2144 tevent_req_received(req);
2148 *flags = state->flags;
2149 *xferlen = state->xferlen;
2150 token_blob->length = state->token_blob.length;
2151 token_blob->data = talloc_move(mem_ctx, &state->token_blob.data);
2153 tevent_req_received(req);
2154 return NT_STATUS_OK;
2157 struct time_audit_offload_write_state {
2158 struct timespec ts_send;
2159 struct vfs_handle_struct *handle;
2162 static void smb_time_audit_offload_write_done(struct tevent_req *subreq);
2164 static struct tevent_req *smb_time_audit_offload_write_send(struct vfs_handle_struct *handle,
2165 TALLOC_CTX *mem_ctx,
2166 struct tevent_context *ev,
2169 off_t transfer_offset,
2170 struct files_struct *dest_fsp,
2174 struct tevent_req *req;
2175 struct tevent_req *subreq;
2176 struct time_audit_offload_write_state *state;
2178 req = tevent_req_create(mem_ctx, &state,
2179 struct time_audit_offload_write_state);
2184 state->handle = handle;
2185 clock_gettime_mono(&state->ts_send);
2186 subreq = SMB_VFS_NEXT_OFFLOAD_WRITE_SEND(handle, state, ev,
2187 fsctl, token, transfer_offset,
2188 dest_fsp, dest_off, num);
2189 if (tevent_req_nomem(subreq, req)) {
2190 return tevent_req_post(req, ev);
2193 tevent_req_set_callback(subreq, smb_time_audit_offload_write_done, req);
2197 static void smb_time_audit_offload_write_done(struct tevent_req *subreq)
2199 struct tevent_req *req = tevent_req_callback_data(
2200 subreq, struct tevent_req);
2201 struct time_audit_offload_write_state *state = tevent_req_data(
2202 req, struct time_audit_offload_write_state);
2205 status = SMB_VFS_NEXT_OFFLOAD_WRITE_RECV(state->handle,
2208 TALLOC_FREE(subreq);
2209 if (tevent_req_nterror(req, status)) {
2212 tevent_req_done(req);
2215 static NTSTATUS smb_time_audit_offload_write_recv(struct vfs_handle_struct *handle,
2216 struct tevent_req *req,
2219 struct time_audit_offload_write_state *state = tevent_req_data(
2220 req, struct time_audit_offload_write_state);
2221 struct timespec ts_recv;
2225 clock_gettime_mono(&ts_recv);
2226 timediff = nsec_time_diff(&ts_recv, &state->ts_send)*1.0e-9;
2227 if (timediff > audit_timeout) {
2228 smb_time_audit_log("offload_write", timediff);
2231 *copied = state->copied;
2232 if (tevent_req_is_nterror(req, &status)) {
2233 tevent_req_received(req);
2237 tevent_req_received(req);
2238 return NT_STATUS_OK;
2241 static NTSTATUS smb_time_audit_fget_compression(vfs_handle_struct *handle,
2242 TALLOC_CTX *mem_ctx,
2243 struct files_struct *fsp,
2244 uint16_t *_compression_fmt)
2247 struct timespec ts1,ts2;
2250 clock_gettime_mono(&ts1);
2251 result = SMB_VFS_NEXT_FGET_COMPRESSION(handle, mem_ctx, fsp,
2253 clock_gettime_mono(&ts2);
2254 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2256 if (timediff > audit_timeout) {
2257 smb_time_audit_log_fsp("get_compression",
2264 static NTSTATUS smb_time_audit_set_compression(vfs_handle_struct *handle,
2265 TALLOC_CTX *mem_ctx,
2266 struct files_struct *fsp,
2267 uint16_t compression_fmt)
2270 struct timespec ts1,ts2;
2273 clock_gettime_mono(&ts1);
2274 result = SMB_VFS_NEXT_SET_COMPRESSION(handle, mem_ctx, fsp,
2276 clock_gettime_mono(&ts2);
2277 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2279 if (timediff > audit_timeout) {
2280 smb_time_audit_log_fsp("set_compression", timediff, fsp);
2286 static NTSTATUS smb_time_audit_freaddir_attr(struct vfs_handle_struct *handle,
2287 struct files_struct *fsp,
2288 TALLOC_CTX *mem_ctx,
2289 struct readdir_attr_data **pattr_data)
2292 struct timespec ts1, ts2;
2295 clock_gettime_mono(&ts1);
2296 status = SMB_VFS_NEXT_FREADDIR_ATTR(handle, fsp, mem_ctx, pattr_data);
2297 clock_gettime_mono(&ts2);
2298 timediff = nsec_time_diff(&ts2, &ts1) * 1.0e-9;
2300 if (timediff > audit_timeout) {
2301 smb_time_audit_log_fsp("freaddir_attr", timediff, fsp);
2307 static NTSTATUS smb_time_audit_fget_nt_acl(vfs_handle_struct *handle,
2309 uint32_t security_info,
2310 TALLOC_CTX *mem_ctx,
2311 struct security_descriptor **ppdesc)
2314 struct timespec ts1,ts2;
2317 clock_gettime_mono(&ts1);
2318 result = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
2320 clock_gettime_mono(&ts2);
2321 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2323 if (timediff > audit_timeout) {
2324 smb_time_audit_log_fsp("fget_nt_acl", timediff, fsp);
2330 static NTSTATUS smb_time_audit_fset_nt_acl(vfs_handle_struct *handle,
2332 uint32_t security_info_sent,
2333 const struct security_descriptor *psd)
2336 struct timespec ts1,ts2;
2339 clock_gettime_mono(&ts1);
2340 result = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent,
2342 clock_gettime_mono(&ts2);
2343 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2345 if (timediff > audit_timeout) {
2346 smb_time_audit_log_fsp("fset_nt_acl", timediff, fsp);
2352 static NTSTATUS smb_time_audit_audit_file(struct vfs_handle_struct *handle,
2353 struct smb_filename *smb_fname,
2354 struct security_acl *sacl,
2355 uint32_t access_requested,
2356 uint32_t access_denied)
2359 struct timespec ts1,ts2;
2362 clock_gettime_mono(&ts1);
2363 result = SMB_VFS_NEXT_AUDIT_FILE(handle,
2368 clock_gettime_mono(&ts2);
2369 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2371 if (timediff > audit_timeout) {
2372 smb_time_audit_log_fname("audit_file",
2374 smb_fname->base_name);
2380 static SMB_ACL_T smb_time_audit_sys_acl_get_fd(vfs_handle_struct *handle,
2382 SMB_ACL_TYPE_T type,
2383 TALLOC_CTX *mem_ctx)
2386 struct timespec ts1,ts2;
2389 clock_gettime_mono(&ts1);
2390 result = SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp, type, mem_ctx);
2391 clock_gettime_mono(&ts2);
2392 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2394 if (timediff > audit_timeout) {
2395 smb_time_audit_log_fsp("sys_acl_get_fd", timediff, fsp);
2401 static int smb_time_audit_sys_acl_blob_get_fd(vfs_handle_struct *handle,
2403 TALLOC_CTX *mem_ctx,
2404 char **blob_description,
2408 struct timespec ts1,ts2;
2411 clock_gettime_mono(&ts1);
2412 result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle, fsp, mem_ctx, blob_description, blob);
2413 clock_gettime_mono(&ts2);
2414 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2416 if (timediff > audit_timeout) {
2417 smb_time_audit_log("sys_acl_blob_get_fd", timediff);
2423 static int smb_time_audit_sys_acl_set_fd(vfs_handle_struct *handle,
2425 SMB_ACL_TYPE_T type,
2429 struct timespec ts1,ts2;
2432 clock_gettime_mono(&ts1);
2433 result = SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, type, theacl);
2434 clock_gettime_mono(&ts2);
2435 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2437 if (timediff > audit_timeout) {
2438 smb_time_audit_log_fsp("sys_acl_set_fd", timediff, fsp);
2444 static int smb_time_audit_sys_acl_delete_def_fd(vfs_handle_struct *handle,
2448 struct timespec ts1,ts2;
2451 clock_gettime_mono(&ts1);
2452 result = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FD(handle, fsp);
2453 clock_gettime_mono(&ts2);
2454 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2456 if (timediff > audit_timeout) {
2457 smb_time_audit_log_fsp("sys_acl_delete_def_fd", timediff, fsp);
2463 struct smb_time_audit_getxattrat_state {
2464 struct vfs_aio_state aio_state;
2465 files_struct *dir_fsp;
2466 const struct smb_filename *smb_fname;
2467 const char *xattr_name;
2469 uint8_t *xattr_value;
2472 static void smb_time_audit_getxattrat_done(struct tevent_req *subreq);
2474 static struct tevent_req *smb_time_audit_getxattrat_send(
2475 TALLOC_CTX *mem_ctx,
2476 struct tevent_context *ev,
2477 struct vfs_handle_struct *handle,
2478 files_struct *dir_fsp,
2479 const struct smb_filename *smb_fname,
2480 const char *xattr_name,
2483 struct tevent_req *req = NULL;
2484 struct tevent_req *subreq = NULL;
2485 struct smb_time_audit_getxattrat_state *state = NULL;
2487 req = tevent_req_create(mem_ctx, &state,
2488 struct smb_time_audit_getxattrat_state);
2492 *state = (struct smb_time_audit_getxattrat_state) {
2494 .smb_fname = smb_fname,
2495 .xattr_name = xattr_name,
2498 subreq = SMB_VFS_NEXT_GETXATTRAT_SEND(state,
2505 if (tevent_req_nomem(subreq, req)) {
2506 return tevent_req_post(req, ev);
2508 tevent_req_set_callback(subreq, smb_time_audit_getxattrat_done, req);
2513 static void smb_time_audit_getxattrat_done(struct tevent_req *subreq)
2515 struct tevent_req *req = tevent_req_callback_data(
2516 subreq, struct tevent_req);
2517 struct smb_time_audit_getxattrat_state *state = tevent_req_data(
2518 req, struct smb_time_audit_getxattrat_state);
2520 state->xattr_size = SMB_VFS_NEXT_GETXATTRAT_RECV(subreq,
2523 &state->xattr_value);
2524 TALLOC_FREE(subreq);
2525 if (state->xattr_size == -1) {
2526 tevent_req_error(req, state->aio_state.error);
2530 tevent_req_done(req);
2533 static ssize_t smb_time_audit_getxattrat_recv(struct tevent_req *req,
2534 struct vfs_aio_state *aio_state,
2535 TALLOC_CTX *mem_ctx,
2536 uint8_t **xattr_value)
2538 struct smb_time_audit_getxattrat_state *state = tevent_req_data(
2539 req, struct smb_time_audit_getxattrat_state);
2543 timediff = state->aio_state.duration * 1.0e-9;
2545 if (timediff > audit_timeout) {
2546 smb_time_audit_log_at("async getxattrat",
2552 if (tevent_req_is_unix_error(req, &aio_state->error)) {
2553 tevent_req_received(req);
2557 *aio_state = state->aio_state;
2558 xattr_size = state->xattr_size;
2559 if (xattr_value != NULL) {
2560 *xattr_value = talloc_move(mem_ctx, &state->xattr_value);
2563 tevent_req_received(req);
2567 static ssize_t smb_time_audit_fgetxattr(struct vfs_handle_struct *handle,
2568 struct files_struct *fsp,
2569 const char *name, void *value,
2573 struct timespec ts1,ts2;
2576 clock_gettime_mono(&ts1);
2577 result = SMB_VFS_NEXT_FGETXATTR(handle, fsp, name, value, size);
2578 clock_gettime_mono(&ts2);
2579 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2581 if (timediff > audit_timeout) {
2582 smb_time_audit_log_fsp("fgetxattr", timediff, fsp);
2588 static ssize_t smb_time_audit_flistxattr(struct vfs_handle_struct *handle,
2589 struct files_struct *fsp, char *list,
2593 struct timespec ts1,ts2;
2596 clock_gettime_mono(&ts1);
2597 result = SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
2598 clock_gettime_mono(&ts2);
2599 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2601 if (timediff > audit_timeout) {
2602 smb_time_audit_log_fsp("flistxattr", timediff, fsp);
2608 static int smb_time_audit_fremovexattr(struct vfs_handle_struct *handle,
2609 struct files_struct *fsp,
2613 struct timespec ts1,ts2;
2616 clock_gettime_mono(&ts1);
2617 result = SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, name);
2618 clock_gettime_mono(&ts2);
2619 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2621 if (timediff > audit_timeout) {
2622 smb_time_audit_log_fsp("fremovexattr", timediff, fsp);
2628 static int smb_time_audit_fsetxattr(struct vfs_handle_struct *handle,
2629 struct files_struct *fsp, const char *name,
2630 const void *value, size_t size, int flags)
2633 struct timespec ts1,ts2;
2636 clock_gettime_mono(&ts1);
2637 result = SMB_VFS_NEXT_FSETXATTR(handle, fsp, name, value, size, flags);
2638 clock_gettime_mono(&ts2);
2639 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2641 if (timediff > audit_timeout) {
2642 smb_time_audit_log_fsp("fsetxattr", timediff, fsp);
2648 static bool smb_time_audit_aio_force(struct vfs_handle_struct *handle,
2649 struct files_struct *fsp)
2652 struct timespec ts1,ts2;
2655 clock_gettime_mono(&ts1);
2656 result = SMB_VFS_NEXT_AIO_FORCE(handle, fsp);
2657 clock_gettime_mono(&ts2);
2658 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2660 if (timediff > audit_timeout) {
2661 smb_time_audit_log_fsp("aio_force", timediff, fsp);
2667 static NTSTATUS smb_time_audit_durable_cookie(struct vfs_handle_struct *handle,
2668 struct files_struct *fsp,
2669 TALLOC_CTX *mem_ctx,
2673 struct timespec ts1,ts2;
2676 clock_gettime_mono(&ts1);
2677 result = SMB_VFS_NEXT_DURABLE_COOKIE(handle, fsp, mem_ctx, cookie);
2678 clock_gettime_mono(&ts2);
2679 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2681 if (timediff > audit_timeout) {
2682 smb_time_audit_log_fsp("durable_cookie", timediff, fsp);
2688 static NTSTATUS smb_time_audit_durable_disconnect(struct vfs_handle_struct *handle,
2689 struct files_struct *fsp,
2690 const DATA_BLOB old_cookie,
2691 TALLOC_CTX *mem_ctx,
2692 DATA_BLOB *new_cookie)
2695 struct timespec ts1,ts2;
2698 clock_gettime_mono(&ts1);
2699 result = SMB_VFS_NEXT_DURABLE_DISCONNECT(handle, fsp, old_cookie,
2700 mem_ctx, new_cookie);
2701 clock_gettime_mono(&ts2);
2702 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2704 if (timediff > audit_timeout) {
2705 smb_time_audit_log_fsp("durable_disconnect", timediff, fsp);
2711 static NTSTATUS smb_time_audit_durable_reconnect(struct vfs_handle_struct *handle,
2712 struct smb_request *smb1req,
2713 struct smbXsrv_open *op,
2714 const DATA_BLOB old_cookie,
2715 TALLOC_CTX *mem_ctx,
2716 struct files_struct **fsp,
2717 DATA_BLOB *new_cookie)
2720 struct timespec ts1,ts2;
2723 clock_gettime_mono(&ts1);
2724 result = SMB_VFS_NEXT_DURABLE_RECONNECT(handle, smb1req, op, old_cookie,
2725 mem_ctx, fsp, new_cookie);
2726 clock_gettime_mono(&ts2);
2727 timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2729 if (timediff > audit_timeout) {
2730 smb_time_audit_log("durable_reconnect", timediff);
2736 /* VFS operations */
2738 static struct vfs_fn_pointers vfs_time_audit_fns = {
2739 .connect_fn = smb_time_audit_connect,
2740 .disconnect_fn = smb_time_audit_disconnect,
2741 .disk_free_fn = smb_time_audit_disk_free,
2742 .get_quota_fn = smb_time_audit_get_quota,
2743 .set_quota_fn = smb_time_audit_set_quota,
2744 .get_shadow_copy_data_fn = smb_time_audit_get_shadow_copy_data,
2745 .statvfs_fn = smb_time_audit_statvfs,
2746 .fs_capabilities_fn = smb_time_audit_fs_capabilities,
2747 .get_dfs_referrals_fn = smb_time_audit_get_dfs_referrals,
2748 .create_dfs_pathat_fn = smb_time_audit_create_dfs_pathat,
2749 .read_dfs_pathat_fn = smb_time_audit_read_dfs_pathat,
2750 .fdopendir_fn = smb_time_audit_fdopendir,
2751 .readdir_fn = smb_time_audit_readdir,
2752 .seekdir_fn = smb_time_audit_seekdir,
2753 .telldir_fn = smb_time_audit_telldir,
2754 .rewind_dir_fn = smb_time_audit_rewinddir,
2755 .mkdirat_fn = smb_time_audit_mkdirat,
2756 .closedir_fn = smb_time_audit_closedir,
2757 .openat_fn = smb_time_audit_openat,
2758 .create_file_fn = smb_time_audit_create_file,
2759 .close_fn = smb_time_audit_close,
2760 .pread_fn = smb_time_audit_pread,
2761 .pread_send_fn = smb_time_audit_pread_send,
2762 .pread_recv_fn = smb_time_audit_pread_recv,
2763 .pwrite_fn = smb_time_audit_pwrite,
2764 .pwrite_send_fn = smb_time_audit_pwrite_send,
2765 .pwrite_recv_fn = smb_time_audit_pwrite_recv,
2766 .lseek_fn = smb_time_audit_lseek,
2767 .sendfile_fn = smb_time_audit_sendfile,
2768 .recvfile_fn = smb_time_audit_recvfile,
2769 .renameat_fn = smb_time_audit_renameat,
2770 .fsync_send_fn = smb_time_audit_fsync_send,
2771 .fsync_recv_fn = smb_time_audit_fsync_recv,
2772 .stat_fn = smb_time_audit_stat,
2773 .fstat_fn = smb_time_audit_fstat,
2774 .lstat_fn = smb_time_audit_lstat,
2775 .fstatat_fn = smb_time_audit_fstatat,
2776 .get_alloc_size_fn = smb_time_audit_get_alloc_size,
2777 .unlinkat_fn = smb_time_audit_unlinkat,
2778 .fchmod_fn = smb_time_audit_fchmod,
2779 .fchown_fn = smb_time_audit_fchown,
2780 .lchown_fn = smb_time_audit_lchown,
2781 .chdir_fn = smb_time_audit_chdir,
2782 .getwd_fn = smb_time_audit_getwd,
2783 .fntimes_fn = smb_time_audit_fntimes,
2784 .ftruncate_fn = smb_time_audit_ftruncate,
2785 .fallocate_fn = smb_time_audit_fallocate,
2786 .lock_fn = smb_time_audit_lock,
2787 .filesystem_sharemode_fn = smb_time_audit_filesystem_sharemode,
2788 .fcntl_fn = smb_time_audit_fcntl,
2789 .linux_setlease_fn = smb_time_audit_linux_setlease,
2790 .getlock_fn = smb_time_audit_getlock,
2791 .symlinkat_fn = smb_time_audit_symlinkat,
2792 .readlinkat_fn = smb_time_audit_readlinkat,
2793 .linkat_fn = smb_time_audit_linkat,
2794 .mknodat_fn = smb_time_audit_mknodat,
2795 .realpath_fn = smb_time_audit_realpath,
2796 .fchflags_fn = smb_time_audit_fchflags,
2797 .file_id_create_fn = smb_time_audit_file_id_create,
2798 .fs_file_id_fn = smb_time_audit_fs_file_id,
2799 .offload_read_send_fn = smb_time_audit_offload_read_send,
2800 .offload_read_recv_fn = smb_time_audit_offload_read_recv,
2801 .offload_write_send_fn = smb_time_audit_offload_write_send,
2802 .offload_write_recv_fn = smb_time_audit_offload_write_recv,
2803 .fget_compression_fn = smb_time_audit_fget_compression,
2804 .set_compression_fn = smb_time_audit_set_compression,
2805 .snap_check_path_fn = smb_time_audit_snap_check_path,
2806 .snap_create_fn = smb_time_audit_snap_create,
2807 .snap_delete_fn = smb_time_audit_snap_delete,
2808 .fstreaminfo_fn = smb_time_audit_fstreaminfo,
2809 .get_real_filename_at_fn = smb_time_audit_get_real_filename_at,
2810 .connectpath_fn = smb_time_audit_connectpath,
2811 .brl_lock_windows_fn = smb_time_audit_brl_lock_windows,
2812 .brl_unlock_windows_fn = smb_time_audit_brl_unlock_windows,
2813 .strict_lock_check_fn = smb_time_audit_strict_lock_check,
2814 .translate_name_fn = smb_time_audit_translate_name,
2815 .parent_pathname_fn = smb_time_audit_parent_pathname,
2816 .fsctl_fn = smb_time_audit_fsctl,
2817 .get_dos_attributes_send_fn = smb_time_audit_get_dos_attributes_send,
2818 .get_dos_attributes_recv_fn = smb_time_audit_get_dos_attributes_recv,
2819 .fget_dos_attributes_fn = smb_time_fget_dos_attributes,
2820 .fset_dos_attributes_fn = smb_time_fset_dos_attributes,
2821 .fget_nt_acl_fn = smb_time_audit_fget_nt_acl,
2822 .fset_nt_acl_fn = smb_time_audit_fset_nt_acl,
2823 .audit_file_fn = smb_time_audit_audit_file,
2824 .sys_acl_get_fd_fn = smb_time_audit_sys_acl_get_fd,
2825 .sys_acl_blob_get_fd_fn = smb_time_audit_sys_acl_blob_get_fd,
2826 .sys_acl_set_fd_fn = smb_time_audit_sys_acl_set_fd,
2827 .sys_acl_delete_def_fd_fn = smb_time_audit_sys_acl_delete_def_fd,
2828 .getxattrat_send_fn = smb_time_audit_getxattrat_send,
2829 .getxattrat_recv_fn = smb_time_audit_getxattrat_recv,
2830 .fgetxattr_fn = smb_time_audit_fgetxattr,
2831 .flistxattr_fn = smb_time_audit_flistxattr,
2832 .fremovexattr_fn = smb_time_audit_fremovexattr,
2833 .fsetxattr_fn = smb_time_audit_fsetxattr,
2834 .aio_force_fn = smb_time_audit_aio_force,
2835 .durable_cookie_fn = smb_time_audit_durable_cookie,
2836 .durable_disconnect_fn = smb_time_audit_durable_disconnect,
2837 .durable_reconnect_fn = smb_time_audit_durable_reconnect,
2838 .freaddir_attr_fn = smb_time_audit_freaddir_attr,
2843 NTSTATUS vfs_time_audit_init(TALLOC_CTX *ctx)
2845 smb_vfs_assert_all_fns(&vfs_time_audit_fns, "time_audit");
2847 audit_timeout = (double)lp_parm_int(-1, "time_audit", "timeout",
2849 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "time_audit",
2850 &vfs_time_audit_fns);