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
,
624 const struct vfs_open_how
*how
)
627 struct timespec ts1
,ts2
;
630 clock_gettime_mono(&ts1
);
631 result
= SMB_VFS_NEXT_OPENAT(handle
,
636 clock_gettime_mono(&ts2
);
637 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
639 if (timediff
> audit_timeout
) {
640 smb_time_audit_log_fsp("openat", timediff
, fsp
);
646 static NTSTATUS
smb_time_audit_create_file(vfs_handle_struct
*handle
,
647 struct smb_request
*req
,
648 struct files_struct
*dirfsp
,
649 struct smb_filename
*fname
,
650 uint32_t access_mask
,
651 uint32_t share_access
,
652 uint32_t create_disposition
,
653 uint32_t create_options
,
654 uint32_t file_attributes
,
655 uint32_t oplock_request
,
656 const struct smb2_lease
*lease
,
657 uint64_t allocation_size
,
658 uint32_t private_flags
,
659 struct security_descriptor
*sd
,
660 struct ea_list
*ea_list
,
661 files_struct
**result_fsp
,
663 const struct smb2_create_blobs
*in_context_blobs
,
664 struct smb2_create_blobs
*out_context_blobs
)
667 struct timespec ts1
,ts2
;
670 clock_gettime_mono(&ts1
);
671 result
= SMB_VFS_NEXT_CREATE_FILE(
676 access_mask
, /* access_mask */
677 share_access
, /* share_access */
678 create_disposition
, /* create_disposition*/
679 create_options
, /* create_options */
680 file_attributes
, /* file_attributes */
681 oplock_request
, /* oplock_request */
683 allocation_size
, /* allocation_size */
686 ea_list
, /* ea_list */
687 result_fsp
, /* result */
689 in_context_blobs
, out_context_blobs
); /* create context */
690 clock_gettime_mono(&ts2
);
691 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
693 if (timediff
> audit_timeout
) {
695 * can't use result_fsp this time, may have
696 * invalid content causing smbd crash
698 smb_time_audit_log_smb_fname("create_file", timediff
,
705 static int smb_time_audit_close(vfs_handle_struct
*handle
, files_struct
*fsp
)
708 struct timespec ts1
,ts2
;
711 clock_gettime_mono(&ts1
);
712 result
= SMB_VFS_NEXT_CLOSE(handle
, fsp
);
713 clock_gettime_mono(&ts2
);
714 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
716 if (timediff
> audit_timeout
) {
717 smb_time_audit_log_fsp("close", timediff
, fsp
);
723 static ssize_t
smb_time_audit_pread(vfs_handle_struct
*handle
,
725 void *data
, size_t n
, off_t offset
)
728 struct timespec ts1
,ts2
;
731 clock_gettime_mono(&ts1
);
732 result
= SMB_VFS_NEXT_PREAD(handle
, fsp
, data
, n
, offset
);
733 clock_gettime_mono(&ts2
);
734 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
736 if (timediff
> audit_timeout
) {
737 smb_time_audit_log_fsp("pread", timediff
, fsp
);
743 struct smb_time_audit_pread_state
{
744 struct files_struct
*fsp
;
746 struct vfs_aio_state vfs_aio_state
;
749 static void smb_time_audit_pread_done(struct tevent_req
*subreq
);
751 static struct tevent_req
*smb_time_audit_pread_send(
752 struct vfs_handle_struct
*handle
, TALLOC_CTX
*mem_ctx
,
753 struct tevent_context
*ev
, struct files_struct
*fsp
,
754 void *data
, size_t n
, off_t offset
)
756 struct tevent_req
*req
, *subreq
;
757 struct smb_time_audit_pread_state
*state
;
759 req
= tevent_req_create(mem_ctx
, &state
,
760 struct smb_time_audit_pread_state
);
766 subreq
= SMB_VFS_NEXT_PREAD_SEND(state
, ev
, handle
, fsp
, data
,
768 if (tevent_req_nomem(subreq
, req
)) {
769 return tevent_req_post(req
, ev
);
771 tevent_req_set_callback(subreq
, smb_time_audit_pread_done
, req
);
775 static void smb_time_audit_pread_done(struct tevent_req
*subreq
)
777 struct tevent_req
*req
= tevent_req_callback_data(
778 subreq
, struct tevent_req
);
779 struct smb_time_audit_pread_state
*state
= tevent_req_data(
780 req
, struct smb_time_audit_pread_state
);
782 state
->ret
= SMB_VFS_PREAD_RECV(subreq
, &state
->vfs_aio_state
);
784 tevent_req_done(req
);
787 static ssize_t
smb_time_audit_pread_recv(struct tevent_req
*req
,
788 struct vfs_aio_state
*vfs_aio_state
)
790 struct smb_time_audit_pread_state
*state
= tevent_req_data(
791 req
, struct smb_time_audit_pread_state
);
794 timediff
= state
->vfs_aio_state
.duration
* 1.0e-9;
796 if (timediff
> audit_timeout
) {
797 smb_time_audit_log_fsp("async pread", timediff
, state
->fsp
);
800 if (tevent_req_is_unix_error(req
, &vfs_aio_state
->error
)) {
803 *vfs_aio_state
= state
->vfs_aio_state
;
807 static ssize_t
smb_time_audit_pwrite(vfs_handle_struct
*handle
,
809 const void *data
, size_t n
,
813 struct timespec ts1
,ts2
;
816 clock_gettime_mono(&ts1
);
817 result
= SMB_VFS_NEXT_PWRITE(handle
, fsp
, data
, n
, offset
);
818 clock_gettime_mono(&ts2
);
819 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
821 if (timediff
> audit_timeout
) {
822 smb_time_audit_log_fsp("pwrite", timediff
, fsp
);
828 struct smb_time_audit_pwrite_state
{
829 struct files_struct
*fsp
;
831 struct vfs_aio_state vfs_aio_state
;
834 static void smb_time_audit_pwrite_done(struct tevent_req
*subreq
);
836 static struct tevent_req
*smb_time_audit_pwrite_send(
837 struct vfs_handle_struct
*handle
, TALLOC_CTX
*mem_ctx
,
838 struct tevent_context
*ev
, struct files_struct
*fsp
,
839 const void *data
, size_t n
, off_t offset
)
841 struct tevent_req
*req
, *subreq
;
842 struct smb_time_audit_pwrite_state
*state
;
844 req
= tevent_req_create(mem_ctx
, &state
,
845 struct smb_time_audit_pwrite_state
);
851 subreq
= SMB_VFS_NEXT_PWRITE_SEND(state
, ev
, handle
, fsp
, data
,
853 if (tevent_req_nomem(subreq
, req
)) {
854 return tevent_req_post(req
, ev
);
856 tevent_req_set_callback(subreq
, smb_time_audit_pwrite_done
, req
);
860 static void smb_time_audit_pwrite_done(struct tevent_req
*subreq
)
862 struct tevent_req
*req
= tevent_req_callback_data(
863 subreq
, struct tevent_req
);
864 struct smb_time_audit_pwrite_state
*state
= tevent_req_data(
865 req
, struct smb_time_audit_pwrite_state
);
867 state
->ret
= SMB_VFS_PWRITE_RECV(subreq
, &state
->vfs_aio_state
);
869 tevent_req_done(req
);
872 static ssize_t
smb_time_audit_pwrite_recv(struct tevent_req
*req
,
873 struct vfs_aio_state
*vfs_aio_state
)
875 struct smb_time_audit_pwrite_state
*state
= tevent_req_data(
876 req
, struct smb_time_audit_pwrite_state
);
879 timediff
= state
->vfs_aio_state
.duration
* 1.0e-9;
881 if (timediff
> audit_timeout
) {
882 smb_time_audit_log_fsp("async pwrite", timediff
, state
->fsp
);
885 if (tevent_req_is_unix_error(req
, &vfs_aio_state
->error
)) {
888 *vfs_aio_state
= state
->vfs_aio_state
;
892 static off_t
smb_time_audit_lseek(vfs_handle_struct
*handle
,
894 off_t offset
, int whence
)
897 struct timespec ts1
,ts2
;
900 clock_gettime_mono(&ts1
);
901 result
= SMB_VFS_NEXT_LSEEK(handle
, fsp
, offset
, whence
);
902 clock_gettime_mono(&ts2
);
903 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
905 if (timediff
> audit_timeout
) {
906 smb_time_audit_log_fsp("lseek", timediff
, fsp
);
912 static ssize_t
smb_time_audit_sendfile(vfs_handle_struct
*handle
, int tofd
,
913 files_struct
*fromfsp
,
914 const DATA_BLOB
*hdr
, off_t offset
,
918 struct timespec ts1
,ts2
;
921 clock_gettime_mono(&ts1
);
922 result
= SMB_VFS_NEXT_SENDFILE(handle
, tofd
, fromfsp
, hdr
, offset
, n
);
923 clock_gettime_mono(&ts2
);
924 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
926 if (timediff
> audit_timeout
) {
927 smb_time_audit_log_fsp("sendfile", timediff
, fromfsp
);
933 static ssize_t
smb_time_audit_recvfile(vfs_handle_struct
*handle
, int fromfd
,
939 struct timespec ts1
,ts2
;
942 clock_gettime_mono(&ts1
);
943 result
= SMB_VFS_NEXT_RECVFILE(handle
, fromfd
, tofsp
, offset
, n
);
944 clock_gettime_mono(&ts2
);
945 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
947 if (timediff
> audit_timeout
) {
948 smb_time_audit_log_fsp("recvfile", timediff
, tofsp
);
954 static int smb_time_audit_renameat(vfs_handle_struct
*handle
,
955 files_struct
*srcfsp
,
956 const struct smb_filename
*oldname
,
957 files_struct
*dstfsp
,
958 const struct smb_filename
*newname
)
961 struct timespec ts1
,ts2
;
963 struct smb_filename
*new_full_fname
= NULL
;
965 new_full_fname
= full_path_from_dirfsp_atname(talloc_tos(),
968 if (new_full_fname
== NULL
) {
972 clock_gettime_mono(&ts1
);
973 result
= SMB_VFS_NEXT_RENAMEAT(handle
,
978 clock_gettime_mono(&ts2
);
979 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
981 if (timediff
> audit_timeout
) {
982 smb_time_audit_log_smb_fname("renameat",
987 TALLOC_FREE(new_full_fname
);
991 struct smb_time_audit_fsync_state
{
992 struct files_struct
*fsp
;
994 struct vfs_aio_state vfs_aio_state
;
997 static void smb_time_audit_fsync_done(struct tevent_req
*subreq
);
999 static struct tevent_req
*smb_time_audit_fsync_send(
1000 struct vfs_handle_struct
*handle
, TALLOC_CTX
*mem_ctx
,
1001 struct tevent_context
*ev
, struct files_struct
*fsp
)
1003 struct tevent_req
*req
, *subreq
;
1004 struct smb_time_audit_fsync_state
*state
;
1006 req
= tevent_req_create(mem_ctx
, &state
,
1007 struct smb_time_audit_fsync_state
);
1013 subreq
= SMB_VFS_NEXT_FSYNC_SEND(state
, ev
, handle
, fsp
);
1014 if (tevent_req_nomem(subreq
, req
)) {
1015 return tevent_req_post(req
, ev
);
1017 tevent_req_set_callback(subreq
, smb_time_audit_fsync_done
, req
);
1021 static void smb_time_audit_fsync_done(struct tevent_req
*subreq
)
1023 struct tevent_req
*req
= tevent_req_callback_data(
1024 subreq
, struct tevent_req
);
1025 struct smb_time_audit_fsync_state
*state
= tevent_req_data(
1026 req
, struct smb_time_audit_fsync_state
);
1028 state
->ret
= SMB_VFS_FSYNC_RECV(subreq
, &state
->vfs_aio_state
);
1029 TALLOC_FREE(subreq
);
1030 tevent_req_done(req
);
1033 static int smb_time_audit_fsync_recv(struct tevent_req
*req
,
1034 struct vfs_aio_state
*vfs_aio_state
)
1036 struct smb_time_audit_fsync_state
*state
= tevent_req_data(
1037 req
, struct smb_time_audit_fsync_state
);
1040 timediff
= state
->vfs_aio_state
.duration
* 1.0e-9;
1042 if (timediff
> audit_timeout
) {
1043 smb_time_audit_log_fsp("async fsync", timediff
, state
->fsp
);
1046 if (tevent_req_is_unix_error(req
, &vfs_aio_state
->error
)) {
1049 *vfs_aio_state
= state
->vfs_aio_state
;
1053 static int smb_time_audit_stat(vfs_handle_struct
*handle
,
1054 struct smb_filename
*fname
)
1057 struct timespec ts1
,ts2
;
1060 clock_gettime_mono(&ts1
);
1061 result
= SMB_VFS_NEXT_STAT(handle
, fname
);
1062 clock_gettime_mono(&ts2
);
1063 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1065 if (timediff
> audit_timeout
) {
1066 smb_time_audit_log_smb_fname("stat", timediff
, fname
);
1072 static int smb_time_audit_fstat(vfs_handle_struct
*handle
, files_struct
*fsp
,
1073 SMB_STRUCT_STAT
*sbuf
)
1076 struct timespec ts1
,ts2
;
1079 clock_gettime_mono(&ts1
);
1080 result
= SMB_VFS_NEXT_FSTAT(handle
, fsp
, sbuf
);
1081 clock_gettime_mono(&ts2
);
1082 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1084 if (timediff
> audit_timeout
) {
1085 smb_time_audit_log_fsp("fstat", timediff
, fsp
);
1091 static int smb_time_audit_lstat(vfs_handle_struct
*handle
,
1092 struct smb_filename
*path
)
1095 struct timespec ts1
,ts2
;
1098 clock_gettime_mono(&ts1
);
1099 result
= SMB_VFS_NEXT_LSTAT(handle
, path
);
1100 clock_gettime_mono(&ts2
);
1101 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1103 if (timediff
> audit_timeout
) {
1104 smb_time_audit_log_smb_fname("lstat", timediff
, path
);
1110 static int smb_time_audit_fstatat(
1111 struct vfs_handle_struct
*handle
,
1112 const struct files_struct
*dirfsp
,
1113 const struct smb_filename
*smb_fname
,
1114 SMB_STRUCT_STAT
*sbuf
,
1118 struct timespec ts1
,ts2
;
1121 clock_gettime_mono(&ts1
);
1122 result
= SMB_VFS_NEXT_FSTATAT(handle
, dirfsp
, smb_fname
, sbuf
, flags
);
1123 clock_gettime_mono(&ts2
);
1124 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1126 if (timediff
> audit_timeout
) {
1127 smb_time_audit_log_smb_fname("fstatat", timediff
, smb_fname
);
1133 static uint64_t smb_time_audit_get_alloc_size(vfs_handle_struct
*handle
,
1135 const SMB_STRUCT_STAT
*sbuf
)
1138 struct timespec ts1
,ts2
;
1141 clock_gettime_mono(&ts1
);
1142 result
= SMB_VFS_NEXT_GET_ALLOC_SIZE(handle
, fsp
, sbuf
);
1143 clock_gettime_mono(&ts2
);
1144 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1146 if (timediff
> audit_timeout
) {
1147 smb_time_audit_log_fsp("get_alloc_size", timediff
, fsp
);
1153 static int smb_time_audit_unlinkat(vfs_handle_struct
*handle
,
1154 struct files_struct
*dirfsp
,
1155 const struct smb_filename
*path
,
1158 struct smb_filename
*full_fname
= NULL
;
1160 struct timespec ts1
,ts2
;
1163 full_fname
= full_path_from_dirfsp_atname(talloc_tos(),
1166 if (full_fname
== NULL
) {
1170 clock_gettime_mono(&ts1
);
1171 result
= SMB_VFS_NEXT_UNLINKAT(handle
,
1175 clock_gettime_mono(&ts2
);
1176 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1178 if (timediff
> audit_timeout
) {
1179 smb_time_audit_log_smb_fname("unlinkat", timediff
, full_fname
);
1182 TALLOC_FREE(full_fname
);
1186 static int smb_time_audit_fchmod(vfs_handle_struct
*handle
, files_struct
*fsp
,
1190 struct timespec ts1
,ts2
;
1193 clock_gettime_mono(&ts1
);
1194 result
= SMB_VFS_NEXT_FCHMOD(handle
, fsp
, mode
);
1195 clock_gettime_mono(&ts2
);
1196 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1198 if (timediff
> audit_timeout
) {
1199 smb_time_audit_log_fsp("fchmod", timediff
, fsp
);
1205 static int smb_time_audit_fchown(vfs_handle_struct
*handle
, files_struct
*fsp
,
1206 uid_t uid
, gid_t gid
)
1209 struct timespec ts1
,ts2
;
1212 clock_gettime_mono(&ts1
);
1213 result
= SMB_VFS_NEXT_FCHOWN(handle
, fsp
, uid
, gid
);
1214 clock_gettime_mono(&ts2
);
1215 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1217 if (timediff
> audit_timeout
) {
1218 smb_time_audit_log_fsp("fchown", timediff
, fsp
);
1224 static int smb_time_audit_lchown(vfs_handle_struct
*handle
,
1225 const struct smb_filename
*smb_fname
,
1230 struct timespec ts1
,ts2
;
1233 clock_gettime_mono(&ts1
);
1234 result
= SMB_VFS_NEXT_LCHOWN(handle
, smb_fname
, uid
, gid
);
1235 clock_gettime_mono(&ts2
);
1236 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1238 if (timediff
> audit_timeout
) {
1239 smb_time_audit_log_fname("lchown",
1241 smb_fname
->base_name
);
1247 static int smb_time_audit_chdir(vfs_handle_struct
*handle
,
1248 const struct smb_filename
*smb_fname
)
1251 struct timespec ts1
,ts2
;
1254 clock_gettime_mono(&ts1
);
1255 result
= SMB_VFS_NEXT_CHDIR(handle
, smb_fname
);
1256 clock_gettime_mono(&ts2
);
1257 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1259 if (timediff
> audit_timeout
) {
1260 smb_time_audit_log_fname("chdir",
1262 smb_fname
->base_name
);
1268 static struct smb_filename
*smb_time_audit_getwd(vfs_handle_struct
*handle
,
1269 TALLOC_CTX
*mem_ctx
)
1271 struct smb_filename
*result
;
1272 struct timespec ts1
,ts2
;
1275 clock_gettime_mono(&ts1
);
1276 result
= SMB_VFS_NEXT_GETWD(handle
, mem_ctx
);
1277 clock_gettime_mono(&ts2
);
1278 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1280 if (timediff
> audit_timeout
) {
1281 smb_time_audit_log("getwd", timediff
);
1287 static int smb_time_audit_fntimes(vfs_handle_struct
*handle
,
1289 struct smb_file_time
*ft
)
1292 struct timespec ts1
,ts2
;
1295 clock_gettime_mono(&ts1
);
1296 result
= SMB_VFS_NEXT_FNTIMES(handle
, fsp
, ft
);
1297 clock_gettime_mono(&ts2
);
1298 timediff
= nsec_time_diff(&ts2
, &ts1
) * 1.0e-9;
1300 if (timediff
> audit_timeout
) {
1301 smb_time_audit_log_fsp("fntimes", timediff
, fsp
);
1307 static int smb_time_audit_ftruncate(vfs_handle_struct
*handle
,
1312 struct timespec ts1
,ts2
;
1315 clock_gettime_mono(&ts1
);
1316 result
= SMB_VFS_NEXT_FTRUNCATE(handle
, fsp
, len
);
1317 clock_gettime_mono(&ts2
);
1318 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1320 if (timediff
> audit_timeout
) {
1321 smb_time_audit_log_fsp("ftruncate", timediff
, fsp
);
1327 static int smb_time_audit_fallocate(vfs_handle_struct
*handle
,
1334 int saved_errno
= 0;
1335 struct timespec ts1
,ts2
;
1338 clock_gettime_mono(&ts1
);
1339 result
= SMB_VFS_NEXT_FALLOCATE(handle
, fsp
, mode
, offset
, len
);
1341 saved_errno
= errno
;
1343 clock_gettime_mono(&ts2
);
1344 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1346 if (timediff
> audit_timeout
) {
1347 smb_time_audit_log_fsp("fallocate", timediff
, fsp
);
1350 errno
= saved_errno
;
1355 static bool smb_time_audit_lock(vfs_handle_struct
*handle
, files_struct
*fsp
,
1356 int op
, off_t offset
, off_t count
,
1360 struct timespec ts1
,ts2
;
1363 clock_gettime_mono(&ts1
);
1364 result
= SMB_VFS_NEXT_LOCK(handle
, fsp
, op
, offset
, count
, type
);
1365 clock_gettime_mono(&ts2
);
1366 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1368 if (timediff
> audit_timeout
) {
1369 smb_time_audit_log_fsp("lock", timediff
, fsp
);
1375 static int smb_time_audit_filesystem_sharemode(struct vfs_handle_struct
*handle
,
1376 struct files_struct
*fsp
,
1377 uint32_t share_access
,
1378 uint32_t access_mask
)
1381 struct timespec ts1
,ts2
;
1384 clock_gettime_mono(&ts1
);
1385 result
= SMB_VFS_NEXT_FILESYSTEM_SHAREMODE(handle
,
1389 clock_gettime_mono(&ts2
);
1390 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1392 if (timediff
> audit_timeout
) {
1393 smb_time_audit_log_fsp("filesystem_sharemode", timediff
, fsp
);
1399 static int smb_time_audit_fcntl(struct vfs_handle_struct
*handle
,
1400 struct files_struct
*fsp
,
1401 int cmd
, va_list cmd_arg
)
1404 va_list dup_cmd_arg
;
1406 struct timespec ts1
,ts2
;
1409 va_copy(dup_cmd_arg
, cmd_arg
);
1410 arg
= va_arg(dup_cmd_arg
, void *);
1411 clock_gettime_mono(&ts1
);
1412 result
= SMB_VFS_NEXT_FCNTL(handle
, fsp
, cmd
, arg
);
1413 clock_gettime_mono(&ts2
);
1414 va_end(dup_cmd_arg
);
1416 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1417 if (timediff
> audit_timeout
) {
1418 smb_time_audit_log_fsp("fcntl", timediff
, fsp
);
1424 static int smb_time_audit_linux_setlease(vfs_handle_struct
*handle
,
1429 struct timespec ts1
,ts2
;
1432 clock_gettime_mono(&ts1
);
1433 result
= SMB_VFS_NEXT_LINUX_SETLEASE(handle
, fsp
, leasetype
);
1434 clock_gettime_mono(&ts2
);
1435 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1437 if (timediff
> audit_timeout
) {
1438 smb_time_audit_log_fsp("linux_setlease", timediff
, fsp
);
1444 static bool smb_time_audit_getlock(vfs_handle_struct
*handle
,
1446 off_t
*poffset
, off_t
*pcount
,
1447 int *ptype
, pid_t
*ppid
)
1450 struct timespec ts1
,ts2
;
1453 clock_gettime_mono(&ts1
);
1454 result
= SMB_VFS_NEXT_GETLOCK(handle
, fsp
, poffset
, pcount
, ptype
,
1456 clock_gettime_mono(&ts2
);
1457 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1459 if (timediff
> audit_timeout
) {
1460 smb_time_audit_log_fsp("getlock", timediff
, fsp
);
1466 static int smb_time_audit_symlinkat(vfs_handle_struct
*handle
,
1467 const struct smb_filename
*link_contents
,
1468 struct files_struct
*dirfsp
,
1469 const struct smb_filename
*new_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_SYMLINKAT(handle
,
1489 clock_gettime_mono(&ts2
);
1490 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1492 if (timediff
> audit_timeout
) {
1493 smb_time_audit_log_fname("symlinkat", timediff
,
1494 full_fname
->base_name
);
1497 TALLOC_FREE(full_fname
);
1501 static int smb_time_audit_readlinkat(vfs_handle_struct
*handle
,
1502 const struct files_struct
*dirfsp
,
1503 const struct smb_filename
*smb_fname
,
1507 struct smb_filename
*full_fname
= NULL
;
1509 struct timespec ts1
,ts2
;
1512 full_fname
= full_path_from_dirfsp_atname(talloc_tos(),
1515 if (full_fname
== NULL
) {
1520 clock_gettime_mono(&ts1
);
1521 result
= SMB_VFS_NEXT_READLINKAT(handle
,
1526 clock_gettime_mono(&ts2
);
1527 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1529 if (timediff
> audit_timeout
) {
1530 smb_time_audit_log_fname("readlinkat", timediff
,
1531 full_fname
->base_name
);
1534 TALLOC_FREE(full_fname
);
1538 static int smb_time_audit_linkat(vfs_handle_struct
*handle
,
1539 files_struct
*srcfsp
,
1540 const struct smb_filename
*old_smb_fname
,
1541 files_struct
*dstfsp
,
1542 const struct smb_filename
*new_smb_fname
,
1545 struct smb_filename
*new_full_fname
= NULL
;
1547 struct timespec ts1
,ts2
;
1550 new_full_fname
= full_path_from_dirfsp_atname(talloc_tos(),
1553 if (new_full_fname
== NULL
) {
1558 clock_gettime_mono(&ts1
);
1559 result
= SMB_VFS_NEXT_LINKAT(handle
,
1565 clock_gettime_mono(&ts2
);
1566 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1568 if (timediff
> audit_timeout
) {
1569 smb_time_audit_log_fname("linkat", timediff
,
1570 new_full_fname
->base_name
);
1573 TALLOC_FREE(new_full_fname
);
1577 static int smb_time_audit_mknodat(vfs_handle_struct
*handle
,
1578 files_struct
*dirfsp
,
1579 const struct smb_filename
*smb_fname
,
1583 struct smb_filename
*full_fname
= NULL
;
1585 struct timespec ts1
,ts2
;
1588 full_fname
= full_path_from_dirfsp_atname(talloc_tos(),
1591 if (full_fname
== NULL
) {
1596 clock_gettime_mono(&ts1
);
1597 result
= SMB_VFS_NEXT_MKNODAT(handle
,
1602 clock_gettime_mono(&ts2
);
1603 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1605 if (timediff
> audit_timeout
) {
1606 smb_time_audit_log_smb_fname("mknodat", timediff
, full_fname
);
1609 TALLOC_FREE(full_fname
);
1613 static struct smb_filename
*smb_time_audit_realpath(vfs_handle_struct
*handle
,
1615 const struct smb_filename
*smb_fname
)
1617 struct smb_filename
*result_fname
;
1618 struct timespec ts1
,ts2
;
1621 clock_gettime_mono(&ts1
);
1622 result_fname
= SMB_VFS_NEXT_REALPATH(handle
, ctx
, smb_fname
);
1623 clock_gettime_mono(&ts2
);
1624 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1626 if (timediff
> audit_timeout
) {
1627 smb_time_audit_log_fname("realpath", timediff
,
1628 smb_fname
->base_name
);
1631 return result_fname
;
1634 static int smb_time_audit_fchflags(vfs_handle_struct
*handle
,
1635 struct files_struct
*fsp
,
1639 struct timespec ts1
,ts2
;
1642 clock_gettime_mono(&ts1
);
1643 result
= SMB_VFS_NEXT_FCHFLAGS(handle
, fsp
, flags
);
1644 clock_gettime_mono(&ts2
);
1645 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1647 if (timediff
> audit_timeout
) {
1648 smb_time_audit_log_smb_fname("chflags",
1656 static struct file_id
smb_time_audit_file_id_create(struct vfs_handle_struct
*handle
,
1657 const SMB_STRUCT_STAT
*sbuf
)
1659 struct file_id id_zero
;
1660 struct file_id result
;
1661 struct timespec ts1
,ts2
;
1664 ZERO_STRUCT(id_zero
);
1666 clock_gettime_mono(&ts1
);
1667 result
= SMB_VFS_NEXT_FILE_ID_CREATE(handle
, sbuf
);
1668 clock_gettime_mono(&ts2
);
1669 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1671 if (timediff
> audit_timeout
) {
1672 smb_time_audit_log("file_id_create", timediff
);
1678 static uint64_t smb_time_audit_fs_file_id(struct vfs_handle_struct
*handle
,
1679 const SMB_STRUCT_STAT
*sbuf
)
1682 struct timespec ts1
,ts2
;
1685 clock_gettime_mono(&ts1
);
1686 result
= SMB_VFS_NEXT_FS_FILE_ID(handle
, sbuf
);
1687 clock_gettime_mono(&ts2
);
1688 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1690 if (timediff
> audit_timeout
) {
1691 smb_time_audit_log("fs_file_id", timediff
);
1697 static NTSTATUS
smb_time_audit_fstreaminfo(vfs_handle_struct
*handle
,
1698 struct files_struct
*fsp
,
1699 TALLOC_CTX
*mem_ctx
,
1700 unsigned int *pnum_streams
,
1701 struct stream_struct
**pstreams
)
1704 struct timespec ts1
,ts2
;
1707 clock_gettime_mono(&ts1
);
1708 result
= SMB_VFS_NEXT_FSTREAMINFO(handle
, fsp
, mem_ctx
,
1709 pnum_streams
, pstreams
);
1710 clock_gettime_mono(&ts2
);
1711 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1713 if (timediff
> audit_timeout
) {
1714 smb_time_audit_log_fsp("fstreaminfo", timediff
, fsp
);
1720 static NTSTATUS
smb_time_audit_get_real_filename_at(
1721 struct vfs_handle_struct
*handle
,
1722 struct files_struct
*dirfsp
,
1724 TALLOC_CTX
*mem_ctx
,
1728 struct timespec ts1
,ts2
;
1731 clock_gettime_mono(&ts1
);
1732 result
= SMB_VFS_NEXT_GET_REAL_FILENAME_AT(
1733 handle
, dirfsp
, name
, mem_ctx
, found_name
);
1734 clock_gettime_mono(&ts2
);
1735 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1737 if (timediff
> audit_timeout
) {
1738 smb_time_audit_log_fname("get_real_filename_at",
1740 fsp_str_dbg(dirfsp
));
1746 static const char *smb_time_audit_connectpath(vfs_handle_struct
*handle
,
1747 const struct smb_filename
*smb_fname
)
1750 struct timespec ts1
,ts2
;
1753 clock_gettime_mono(&ts1
);
1754 result
= SMB_VFS_NEXT_CONNECTPATH(handle
, smb_fname
);
1755 clock_gettime_mono(&ts2
);
1756 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1758 if (timediff
> audit_timeout
) {
1759 smb_time_audit_log_fname("connectpath", timediff
,
1760 smb_fname
->base_name
);
1766 static NTSTATUS
smb_time_audit_brl_lock_windows(struct vfs_handle_struct
*handle
,
1767 struct byte_range_lock
*br_lck
,
1768 struct lock_struct
*plock
)
1771 struct timespec ts1
,ts2
;
1774 clock_gettime_mono(&ts1
);
1775 result
= SMB_VFS_NEXT_BRL_LOCK_WINDOWS(handle
, br_lck
, plock
);
1776 clock_gettime_mono(&ts2
);
1777 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1779 if (timediff
> audit_timeout
) {
1780 smb_time_audit_log_fsp("brl_lock_windows", timediff
,
1787 static bool smb_time_audit_brl_unlock_windows(struct vfs_handle_struct
*handle
,
1788 struct byte_range_lock
*br_lck
,
1789 const struct lock_struct
*plock
)
1792 struct timespec ts1
,ts2
;
1795 clock_gettime_mono(&ts1
);
1796 result
= SMB_VFS_NEXT_BRL_UNLOCK_WINDOWS(handle
, br_lck
, plock
);
1797 clock_gettime_mono(&ts2
);
1798 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1800 if (timediff
> audit_timeout
) {
1801 smb_time_audit_log_fsp("brl_unlock_windows", timediff
,
1808 static bool smb_time_audit_strict_lock_check(struct vfs_handle_struct
*handle
,
1809 struct files_struct
*fsp
,
1810 struct lock_struct
*plock
)
1813 struct timespec ts1
,ts2
;
1816 clock_gettime_mono(&ts1
);
1817 result
= SMB_VFS_NEXT_STRICT_LOCK_CHECK(handle
, fsp
, plock
);
1818 clock_gettime_mono(&ts2
);
1819 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1821 if (timediff
> audit_timeout
) {
1822 smb_time_audit_log_fsp("strict_lock_check", timediff
, fsp
);
1828 static NTSTATUS
smb_time_audit_translate_name(struct vfs_handle_struct
*handle
,
1830 enum vfs_translate_direction direction
,
1831 TALLOC_CTX
*mem_ctx
,
1835 struct timespec ts1
,ts2
;
1838 clock_gettime_mono(&ts1
);
1839 result
= SMB_VFS_NEXT_TRANSLATE_NAME(handle
, name
, direction
, mem_ctx
,
1841 clock_gettime_mono(&ts2
);
1842 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1844 if (timediff
> audit_timeout
) {
1845 smb_time_audit_log_fname("translate_name", timediff
, name
);
1851 static NTSTATUS
smb_time_audit_parent_pathname(struct vfs_handle_struct
*handle
,
1852 TALLOC_CTX
*mem_ctx
,
1853 const struct smb_filename
*smb_fname_in
,
1854 struct smb_filename
**parent_dir_out
,
1855 struct smb_filename
**atname_out
)
1858 struct timespec ts1
,ts2
;
1861 clock_gettime_mono(&ts1
);
1862 result
= SMB_VFS_NEXT_PARENT_PATHNAME(handle
,
1867 clock_gettime_mono(&ts2
);
1868 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1870 if (timediff
> audit_timeout
) {
1871 smb_time_audit_log_fname("parent_pathname",
1873 smb_fname_in
->base_name
);
1879 static NTSTATUS
smb_time_audit_fsctl(struct vfs_handle_struct
*handle
,
1880 struct files_struct
*fsp
,
1884 const uint8_t *_in_data
,
1886 uint8_t **_out_data
,
1887 uint32_t max_out_len
,
1891 struct timespec ts1
,ts2
;
1894 clock_gettime_mono(&ts1
);
1895 result
= SMB_VFS_NEXT_FSCTL(handle
,
1905 clock_gettime_mono(&ts2
);
1906 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1908 if (timediff
> audit_timeout
) {
1909 smb_time_audit_log_fsp("fsctl", timediff
, fsp
);
1915 struct smb_time_audit_get_dos_attributes_state
{
1916 struct vfs_aio_state aio_state
;
1917 files_struct
*dir_fsp
;
1918 const struct smb_filename
*smb_fname
;
1922 static void smb_time_audit_get_dos_attributes_done(struct tevent_req
*subreq
);
1924 static struct tevent_req
*smb_time_audit_get_dos_attributes_send(
1925 TALLOC_CTX
*mem_ctx
,
1926 struct tevent_context
*ev
,
1927 struct vfs_handle_struct
*handle
,
1928 files_struct
*dir_fsp
,
1929 struct smb_filename
*smb_fname
)
1931 struct tevent_req
*req
= NULL
;
1932 struct smb_time_audit_get_dos_attributes_state
*state
= NULL
;
1933 struct tevent_req
*subreq
= NULL
;
1935 req
= tevent_req_create(mem_ctx
, &state
,
1936 struct smb_time_audit_get_dos_attributes_state
);
1940 *state
= (struct smb_time_audit_get_dos_attributes_state
) {
1942 .smb_fname
= smb_fname
,
1945 subreq
= SMB_VFS_NEXT_GET_DOS_ATTRIBUTES_SEND(mem_ctx
,
1950 if (tevent_req_nomem(subreq
, req
)) {
1951 return tevent_req_post(req
, ev
);
1953 tevent_req_set_callback(subreq
,
1954 smb_time_audit_get_dos_attributes_done
,
1960 static void smb_time_audit_get_dos_attributes_done(struct tevent_req
*subreq
)
1962 struct tevent_req
*req
=
1963 tevent_req_callback_data(subreq
,
1965 struct smb_time_audit_get_dos_attributes_state
*state
=
1966 tevent_req_data(req
,
1967 struct smb_time_audit_get_dos_attributes_state
);
1970 status
= SMB_VFS_NEXT_GET_DOS_ATTRIBUTES_RECV(subreq
,
1973 TALLOC_FREE(subreq
);
1974 if (tevent_req_nterror(req
, status
)) {
1978 tevent_req_done(req
);
1982 static NTSTATUS
smb_time_audit_get_dos_attributes_recv(struct tevent_req
*req
,
1983 struct vfs_aio_state
*aio_state
,
1986 struct smb_time_audit_get_dos_attributes_state
*state
=
1987 tevent_req_data(req
,
1988 struct smb_time_audit_get_dos_attributes_state
);
1992 timediff
= state
->aio_state
.duration
* 1.0e-9;
1994 if (timediff
> audit_timeout
) {
1995 smb_time_audit_log_at("async get_dos_attributes",
2001 if (tevent_req_is_nterror(req
, &status
)) {
2002 tevent_req_received(req
);
2006 *aio_state
= state
->aio_state
;
2007 *dosmode
= state
->dosmode
;
2008 tevent_req_received(req
);
2009 return NT_STATUS_OK
;
2012 static NTSTATUS
smb_time_fget_dos_attributes(struct vfs_handle_struct
*handle
,
2013 struct files_struct
*fsp
,
2017 struct timespec ts1
,ts2
;
2020 clock_gettime_mono(&ts1
);
2021 result
= SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle
,
2024 clock_gettime_mono(&ts2
);
2025 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
2027 if (timediff
> audit_timeout
) {
2028 smb_time_audit_log_fsp("fget_dos_attributes", timediff
, fsp
);
2034 static NTSTATUS
smb_time_fset_dos_attributes(struct vfs_handle_struct
*handle
,
2035 struct files_struct
*fsp
,
2039 struct timespec ts1
,ts2
;
2042 clock_gettime_mono(&ts1
);
2043 result
= SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle
,
2046 clock_gettime_mono(&ts2
);
2047 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
2049 if (timediff
> audit_timeout
) {
2050 smb_time_audit_log_fsp("fset_dos_attributes", timediff
, fsp
);
2056 struct time_audit_offload_read_state
{
2057 struct vfs_handle_struct
*handle
;
2058 struct timespec ts_send
;
2061 DATA_BLOB token_blob
;
2064 static void smb_time_audit_offload_read_done(struct tevent_req
*subreq
);
2066 static struct tevent_req
*smb_time_audit_offload_read_send(
2067 TALLOC_CTX
*mem_ctx
,
2068 struct tevent_context
*ev
,
2069 struct vfs_handle_struct
*handle
,
2070 struct files_struct
*fsp
,
2076 struct tevent_req
*req
= NULL
;
2077 struct tevent_req
*subreq
= NULL
;
2078 struct time_audit_offload_read_state
*state
= NULL
;
2080 req
= tevent_req_create(mem_ctx
, &state
,
2081 struct time_audit_offload_read_state
);
2085 state
->handle
= handle
;
2086 clock_gettime_mono(&state
->ts_send
);
2088 subreq
= SMB_VFS_NEXT_OFFLOAD_READ_SEND(mem_ctx
, ev
,
2092 if (tevent_req_nomem(subreq
, req
)) {
2093 return tevent_req_post(req
, ev
);
2096 tevent_req_set_callback(subreq
, smb_time_audit_offload_read_done
, req
);
2100 static void smb_time_audit_offload_read_done(struct tevent_req
*subreq
)
2102 struct tevent_req
*req
= tevent_req_callback_data(
2103 subreq
, struct tevent_req
);
2104 struct time_audit_offload_read_state
*state
= tevent_req_data(
2105 req
, struct time_audit_offload_read_state
);
2108 status
= SMB_VFS_NEXT_OFFLOAD_READ_RECV(subreq
,
2113 &state
->token_blob
);
2114 TALLOC_FREE(subreq
);
2115 if (tevent_req_nterror(req
, status
)) {
2118 tevent_req_done(req
);
2121 static NTSTATUS
smb_time_audit_offload_read_recv(
2122 struct tevent_req
*req
,
2123 struct vfs_handle_struct
*handle
,
2124 TALLOC_CTX
*mem_ctx
,
2127 DATA_BLOB
*token_blob
)
2129 struct time_audit_offload_read_state
*state
= tevent_req_data(
2130 req
, struct time_audit_offload_read_state
);
2131 struct timespec ts_recv
;
2135 clock_gettime_mono(&ts_recv
);
2136 timediff
= nsec_time_diff(&ts_recv
, &state
->ts_send
) * 1.0e-9;
2137 if (timediff
> audit_timeout
) {
2138 smb_time_audit_log("offload_read", timediff
);
2141 if (tevent_req_is_nterror(req
, &status
)) {
2142 tevent_req_received(req
);
2146 *flags
= state
->flags
;
2147 *xferlen
= state
->xferlen
;
2148 token_blob
->length
= state
->token_blob
.length
;
2149 token_blob
->data
= talloc_move(mem_ctx
, &state
->token_blob
.data
);
2151 tevent_req_received(req
);
2152 return NT_STATUS_OK
;
2155 struct time_audit_offload_write_state
{
2156 struct timespec ts_send
;
2157 struct vfs_handle_struct
*handle
;
2160 static void smb_time_audit_offload_write_done(struct tevent_req
*subreq
);
2162 static struct tevent_req
*smb_time_audit_offload_write_send(struct vfs_handle_struct
*handle
,
2163 TALLOC_CTX
*mem_ctx
,
2164 struct tevent_context
*ev
,
2167 off_t transfer_offset
,
2168 struct files_struct
*dest_fsp
,
2172 struct tevent_req
*req
;
2173 struct tevent_req
*subreq
;
2174 struct time_audit_offload_write_state
*state
;
2176 req
= tevent_req_create(mem_ctx
, &state
,
2177 struct time_audit_offload_write_state
);
2182 state
->handle
= handle
;
2183 clock_gettime_mono(&state
->ts_send
);
2184 subreq
= SMB_VFS_NEXT_OFFLOAD_WRITE_SEND(handle
, state
, ev
,
2185 fsctl
, token
, transfer_offset
,
2186 dest_fsp
, dest_off
, num
);
2187 if (tevent_req_nomem(subreq
, req
)) {
2188 return tevent_req_post(req
, ev
);
2191 tevent_req_set_callback(subreq
, smb_time_audit_offload_write_done
, req
);
2195 static void smb_time_audit_offload_write_done(struct tevent_req
*subreq
)
2197 struct tevent_req
*req
= tevent_req_callback_data(
2198 subreq
, struct tevent_req
);
2199 struct time_audit_offload_write_state
*state
= tevent_req_data(
2200 req
, struct time_audit_offload_write_state
);
2203 status
= SMB_VFS_NEXT_OFFLOAD_WRITE_RECV(state
->handle
,
2206 TALLOC_FREE(subreq
);
2207 if (tevent_req_nterror(req
, status
)) {
2210 tevent_req_done(req
);
2213 static NTSTATUS
smb_time_audit_offload_write_recv(struct vfs_handle_struct
*handle
,
2214 struct tevent_req
*req
,
2217 struct time_audit_offload_write_state
*state
= tevent_req_data(
2218 req
, struct time_audit_offload_write_state
);
2219 struct timespec ts_recv
;
2223 clock_gettime_mono(&ts_recv
);
2224 timediff
= nsec_time_diff(&ts_recv
, &state
->ts_send
)*1.0e-9;
2225 if (timediff
> audit_timeout
) {
2226 smb_time_audit_log("offload_write", timediff
);
2229 *copied
= state
->copied
;
2230 if (tevent_req_is_nterror(req
, &status
)) {
2231 tevent_req_received(req
);
2235 tevent_req_received(req
);
2236 return NT_STATUS_OK
;
2239 static NTSTATUS
smb_time_audit_fget_compression(vfs_handle_struct
*handle
,
2240 TALLOC_CTX
*mem_ctx
,
2241 struct files_struct
*fsp
,
2242 uint16_t *_compression_fmt
)
2245 struct timespec ts1
,ts2
;
2248 clock_gettime_mono(&ts1
);
2249 result
= SMB_VFS_NEXT_FGET_COMPRESSION(handle
, mem_ctx
, fsp
,
2251 clock_gettime_mono(&ts2
);
2252 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
2254 if (timediff
> audit_timeout
) {
2255 smb_time_audit_log_fsp("get_compression",
2262 static NTSTATUS
smb_time_audit_set_compression(vfs_handle_struct
*handle
,
2263 TALLOC_CTX
*mem_ctx
,
2264 struct files_struct
*fsp
,
2265 uint16_t compression_fmt
)
2268 struct timespec ts1
,ts2
;
2271 clock_gettime_mono(&ts1
);
2272 result
= SMB_VFS_NEXT_SET_COMPRESSION(handle
, mem_ctx
, fsp
,
2274 clock_gettime_mono(&ts2
);
2275 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
2277 if (timediff
> audit_timeout
) {
2278 smb_time_audit_log_fsp("set_compression", timediff
, fsp
);
2284 static NTSTATUS
smb_time_audit_freaddir_attr(struct vfs_handle_struct
*handle
,
2285 struct files_struct
*fsp
,
2286 TALLOC_CTX
*mem_ctx
,
2287 struct readdir_attr_data
**pattr_data
)
2290 struct timespec ts1
, ts2
;
2293 clock_gettime_mono(&ts1
);
2294 status
= SMB_VFS_NEXT_FREADDIR_ATTR(handle
, fsp
, mem_ctx
, pattr_data
);
2295 clock_gettime_mono(&ts2
);
2296 timediff
= nsec_time_diff(&ts2
, &ts1
) * 1.0e-9;
2298 if (timediff
> audit_timeout
) {
2299 smb_time_audit_log_fsp("freaddir_attr", timediff
, fsp
);
2305 static NTSTATUS
smb_time_audit_fget_nt_acl(vfs_handle_struct
*handle
,
2307 uint32_t security_info
,
2308 TALLOC_CTX
*mem_ctx
,
2309 struct security_descriptor
**ppdesc
)
2312 struct timespec ts1
,ts2
;
2315 clock_gettime_mono(&ts1
);
2316 result
= SMB_VFS_NEXT_FGET_NT_ACL(handle
, fsp
, security_info
,
2318 clock_gettime_mono(&ts2
);
2319 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
2321 if (timediff
> audit_timeout
) {
2322 smb_time_audit_log_fsp("fget_nt_acl", timediff
, fsp
);
2328 static NTSTATUS
smb_time_audit_fset_nt_acl(vfs_handle_struct
*handle
,
2330 uint32_t security_info_sent
,
2331 const struct security_descriptor
*psd
)
2334 struct timespec ts1
,ts2
;
2337 clock_gettime_mono(&ts1
);
2338 result
= SMB_VFS_NEXT_FSET_NT_ACL(handle
, fsp
, security_info_sent
,
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_fsp("fset_nt_acl", timediff
, fsp
);
2350 static NTSTATUS
smb_time_audit_audit_file(struct vfs_handle_struct
*handle
,
2351 struct smb_filename
*smb_fname
,
2352 struct security_acl
*sacl
,
2353 uint32_t access_requested
,
2354 uint32_t access_denied
)
2357 struct timespec ts1
,ts2
;
2360 clock_gettime_mono(&ts1
);
2361 result
= SMB_VFS_NEXT_AUDIT_FILE(handle
,
2366 clock_gettime_mono(&ts2
);
2367 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
2369 if (timediff
> audit_timeout
) {
2370 smb_time_audit_log_fname("audit_file",
2372 smb_fname
->base_name
);
2378 static SMB_ACL_T
smb_time_audit_sys_acl_get_fd(vfs_handle_struct
*handle
,
2380 SMB_ACL_TYPE_T type
,
2381 TALLOC_CTX
*mem_ctx
)
2384 struct timespec ts1
,ts2
;
2387 clock_gettime_mono(&ts1
);
2388 result
= SMB_VFS_NEXT_SYS_ACL_GET_FD(handle
, fsp
, type
, mem_ctx
);
2389 clock_gettime_mono(&ts2
);
2390 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
2392 if (timediff
> audit_timeout
) {
2393 smb_time_audit_log_fsp("sys_acl_get_fd", timediff
, fsp
);
2399 static int smb_time_audit_sys_acl_blob_get_fd(vfs_handle_struct
*handle
,
2401 TALLOC_CTX
*mem_ctx
,
2402 char **blob_description
,
2406 struct timespec ts1
,ts2
;
2409 clock_gettime_mono(&ts1
);
2410 result
= SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle
, fsp
, mem_ctx
, blob_description
, blob
);
2411 clock_gettime_mono(&ts2
);
2412 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
2414 if (timediff
> audit_timeout
) {
2415 smb_time_audit_log("sys_acl_blob_get_fd", timediff
);
2421 static int smb_time_audit_sys_acl_set_fd(vfs_handle_struct
*handle
,
2423 SMB_ACL_TYPE_T type
,
2427 struct timespec ts1
,ts2
;
2430 clock_gettime_mono(&ts1
);
2431 result
= SMB_VFS_NEXT_SYS_ACL_SET_FD(handle
, fsp
, type
, theacl
);
2432 clock_gettime_mono(&ts2
);
2433 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
2435 if (timediff
> audit_timeout
) {
2436 smb_time_audit_log_fsp("sys_acl_set_fd", timediff
, fsp
);
2442 static int smb_time_audit_sys_acl_delete_def_fd(vfs_handle_struct
*handle
,
2446 struct timespec ts1
,ts2
;
2449 clock_gettime_mono(&ts1
);
2450 result
= SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FD(handle
, fsp
);
2451 clock_gettime_mono(&ts2
);
2452 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
2454 if (timediff
> audit_timeout
) {
2455 smb_time_audit_log_fsp("sys_acl_delete_def_fd", timediff
, fsp
);
2461 struct smb_time_audit_getxattrat_state
{
2462 struct vfs_aio_state aio_state
;
2463 files_struct
*dir_fsp
;
2464 const struct smb_filename
*smb_fname
;
2465 const char *xattr_name
;
2467 uint8_t *xattr_value
;
2470 static void smb_time_audit_getxattrat_done(struct tevent_req
*subreq
);
2472 static struct tevent_req
*smb_time_audit_getxattrat_send(
2473 TALLOC_CTX
*mem_ctx
,
2474 struct tevent_context
*ev
,
2475 struct vfs_handle_struct
*handle
,
2476 files_struct
*dir_fsp
,
2477 const struct smb_filename
*smb_fname
,
2478 const char *xattr_name
,
2481 struct tevent_req
*req
= NULL
;
2482 struct tevent_req
*subreq
= NULL
;
2483 struct smb_time_audit_getxattrat_state
*state
= NULL
;
2485 req
= tevent_req_create(mem_ctx
, &state
,
2486 struct smb_time_audit_getxattrat_state
);
2490 *state
= (struct smb_time_audit_getxattrat_state
) {
2492 .smb_fname
= smb_fname
,
2493 .xattr_name
= xattr_name
,
2496 subreq
= SMB_VFS_NEXT_GETXATTRAT_SEND(state
,
2503 if (tevent_req_nomem(subreq
, req
)) {
2504 return tevent_req_post(req
, ev
);
2506 tevent_req_set_callback(subreq
, smb_time_audit_getxattrat_done
, req
);
2511 static void smb_time_audit_getxattrat_done(struct tevent_req
*subreq
)
2513 struct tevent_req
*req
= tevent_req_callback_data(
2514 subreq
, struct tevent_req
);
2515 struct smb_time_audit_getxattrat_state
*state
= tevent_req_data(
2516 req
, struct smb_time_audit_getxattrat_state
);
2518 state
->xattr_size
= SMB_VFS_NEXT_GETXATTRAT_RECV(subreq
,
2521 &state
->xattr_value
);
2522 TALLOC_FREE(subreq
);
2523 if (state
->xattr_size
== -1) {
2524 tevent_req_error(req
, state
->aio_state
.error
);
2528 tevent_req_done(req
);
2531 static ssize_t
smb_time_audit_getxattrat_recv(struct tevent_req
*req
,
2532 struct vfs_aio_state
*aio_state
,
2533 TALLOC_CTX
*mem_ctx
,
2534 uint8_t **xattr_value
)
2536 struct smb_time_audit_getxattrat_state
*state
= tevent_req_data(
2537 req
, struct smb_time_audit_getxattrat_state
);
2541 timediff
= state
->aio_state
.duration
* 1.0e-9;
2543 if (timediff
> audit_timeout
) {
2544 smb_time_audit_log_at("async getxattrat",
2550 if (tevent_req_is_unix_error(req
, &aio_state
->error
)) {
2551 tevent_req_received(req
);
2555 *aio_state
= state
->aio_state
;
2556 xattr_size
= state
->xattr_size
;
2557 if (xattr_value
!= NULL
) {
2558 *xattr_value
= talloc_move(mem_ctx
, &state
->xattr_value
);
2561 tevent_req_received(req
);
2565 static ssize_t
smb_time_audit_fgetxattr(struct vfs_handle_struct
*handle
,
2566 struct files_struct
*fsp
,
2567 const char *name
, void *value
,
2571 struct timespec ts1
,ts2
;
2574 clock_gettime_mono(&ts1
);
2575 result
= SMB_VFS_NEXT_FGETXATTR(handle
, fsp
, name
, value
, size
);
2576 clock_gettime_mono(&ts2
);
2577 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
2579 if (timediff
> audit_timeout
) {
2580 smb_time_audit_log_fsp("fgetxattr", timediff
, fsp
);
2586 static ssize_t
smb_time_audit_flistxattr(struct vfs_handle_struct
*handle
,
2587 struct files_struct
*fsp
, char *list
,
2591 struct timespec ts1
,ts2
;
2594 clock_gettime_mono(&ts1
);
2595 result
= SMB_VFS_NEXT_FLISTXATTR(handle
, fsp
, list
, size
);
2596 clock_gettime_mono(&ts2
);
2597 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
2599 if (timediff
> audit_timeout
) {
2600 smb_time_audit_log_fsp("flistxattr", timediff
, fsp
);
2606 static int smb_time_audit_fremovexattr(struct vfs_handle_struct
*handle
,
2607 struct files_struct
*fsp
,
2611 struct timespec ts1
,ts2
;
2614 clock_gettime_mono(&ts1
);
2615 result
= SMB_VFS_NEXT_FREMOVEXATTR(handle
, fsp
, name
);
2616 clock_gettime_mono(&ts2
);
2617 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
2619 if (timediff
> audit_timeout
) {
2620 smb_time_audit_log_fsp("fremovexattr", timediff
, fsp
);
2626 static int smb_time_audit_fsetxattr(struct vfs_handle_struct
*handle
,
2627 struct files_struct
*fsp
, const char *name
,
2628 const void *value
, size_t size
, int flags
)
2631 struct timespec ts1
,ts2
;
2634 clock_gettime_mono(&ts1
);
2635 result
= SMB_VFS_NEXT_FSETXATTR(handle
, fsp
, name
, value
, size
, flags
);
2636 clock_gettime_mono(&ts2
);
2637 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
2639 if (timediff
> audit_timeout
) {
2640 smb_time_audit_log_fsp("fsetxattr", timediff
, fsp
);
2646 static bool smb_time_audit_aio_force(struct vfs_handle_struct
*handle
,
2647 struct files_struct
*fsp
)
2650 struct timespec ts1
,ts2
;
2653 clock_gettime_mono(&ts1
);
2654 result
= SMB_VFS_NEXT_AIO_FORCE(handle
, fsp
);
2655 clock_gettime_mono(&ts2
);
2656 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
2658 if (timediff
> audit_timeout
) {
2659 smb_time_audit_log_fsp("aio_force", timediff
, fsp
);
2665 static NTSTATUS
smb_time_audit_durable_cookie(struct vfs_handle_struct
*handle
,
2666 struct files_struct
*fsp
,
2667 TALLOC_CTX
*mem_ctx
,
2671 struct timespec ts1
,ts2
;
2674 clock_gettime_mono(&ts1
);
2675 result
= SMB_VFS_NEXT_DURABLE_COOKIE(handle
, fsp
, mem_ctx
, cookie
);
2676 clock_gettime_mono(&ts2
);
2677 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
2679 if (timediff
> audit_timeout
) {
2680 smb_time_audit_log_fsp("durable_cookie", timediff
, fsp
);
2686 static NTSTATUS
smb_time_audit_durable_disconnect(struct vfs_handle_struct
*handle
,
2687 struct files_struct
*fsp
,
2688 const DATA_BLOB old_cookie
,
2689 TALLOC_CTX
*mem_ctx
,
2690 DATA_BLOB
*new_cookie
)
2693 struct timespec ts1
,ts2
;
2696 clock_gettime_mono(&ts1
);
2697 result
= SMB_VFS_NEXT_DURABLE_DISCONNECT(handle
, fsp
, old_cookie
,
2698 mem_ctx
, new_cookie
);
2699 clock_gettime_mono(&ts2
);
2700 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
2702 if (timediff
> audit_timeout
) {
2703 smb_time_audit_log_fsp("durable_disconnect", timediff
, fsp
);
2709 static NTSTATUS
smb_time_audit_durable_reconnect(struct vfs_handle_struct
*handle
,
2710 struct smb_request
*smb1req
,
2711 struct smbXsrv_open
*op
,
2712 const DATA_BLOB old_cookie
,
2713 TALLOC_CTX
*mem_ctx
,
2714 struct files_struct
**fsp
,
2715 DATA_BLOB
*new_cookie
)
2718 struct timespec ts1
,ts2
;
2721 clock_gettime_mono(&ts1
);
2722 result
= SMB_VFS_NEXT_DURABLE_RECONNECT(handle
, smb1req
, op
, old_cookie
,
2723 mem_ctx
, fsp
, new_cookie
);
2724 clock_gettime_mono(&ts2
);
2725 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
2727 if (timediff
> audit_timeout
) {
2728 smb_time_audit_log("durable_reconnect", timediff
);
2734 /* VFS operations */
2736 static struct vfs_fn_pointers vfs_time_audit_fns
= {
2737 .connect_fn
= smb_time_audit_connect
,
2738 .disconnect_fn
= smb_time_audit_disconnect
,
2739 .disk_free_fn
= smb_time_audit_disk_free
,
2740 .get_quota_fn
= smb_time_audit_get_quota
,
2741 .set_quota_fn
= smb_time_audit_set_quota
,
2742 .get_shadow_copy_data_fn
= smb_time_audit_get_shadow_copy_data
,
2743 .statvfs_fn
= smb_time_audit_statvfs
,
2744 .fs_capabilities_fn
= smb_time_audit_fs_capabilities
,
2745 .get_dfs_referrals_fn
= smb_time_audit_get_dfs_referrals
,
2746 .create_dfs_pathat_fn
= smb_time_audit_create_dfs_pathat
,
2747 .read_dfs_pathat_fn
= smb_time_audit_read_dfs_pathat
,
2748 .fdopendir_fn
= smb_time_audit_fdopendir
,
2749 .readdir_fn
= smb_time_audit_readdir
,
2750 .seekdir_fn
= smb_time_audit_seekdir
,
2751 .telldir_fn
= smb_time_audit_telldir
,
2752 .rewind_dir_fn
= smb_time_audit_rewinddir
,
2753 .mkdirat_fn
= smb_time_audit_mkdirat
,
2754 .closedir_fn
= smb_time_audit_closedir
,
2755 .openat_fn
= smb_time_audit_openat
,
2756 .create_file_fn
= smb_time_audit_create_file
,
2757 .close_fn
= smb_time_audit_close
,
2758 .pread_fn
= smb_time_audit_pread
,
2759 .pread_send_fn
= smb_time_audit_pread_send
,
2760 .pread_recv_fn
= smb_time_audit_pread_recv
,
2761 .pwrite_fn
= smb_time_audit_pwrite
,
2762 .pwrite_send_fn
= smb_time_audit_pwrite_send
,
2763 .pwrite_recv_fn
= smb_time_audit_pwrite_recv
,
2764 .lseek_fn
= smb_time_audit_lseek
,
2765 .sendfile_fn
= smb_time_audit_sendfile
,
2766 .recvfile_fn
= smb_time_audit_recvfile
,
2767 .renameat_fn
= smb_time_audit_renameat
,
2768 .fsync_send_fn
= smb_time_audit_fsync_send
,
2769 .fsync_recv_fn
= smb_time_audit_fsync_recv
,
2770 .stat_fn
= smb_time_audit_stat
,
2771 .fstat_fn
= smb_time_audit_fstat
,
2772 .lstat_fn
= smb_time_audit_lstat
,
2773 .fstatat_fn
= smb_time_audit_fstatat
,
2774 .get_alloc_size_fn
= smb_time_audit_get_alloc_size
,
2775 .unlinkat_fn
= smb_time_audit_unlinkat
,
2776 .fchmod_fn
= smb_time_audit_fchmod
,
2777 .fchown_fn
= smb_time_audit_fchown
,
2778 .lchown_fn
= smb_time_audit_lchown
,
2779 .chdir_fn
= smb_time_audit_chdir
,
2780 .getwd_fn
= smb_time_audit_getwd
,
2781 .fntimes_fn
= smb_time_audit_fntimes
,
2782 .ftruncate_fn
= smb_time_audit_ftruncate
,
2783 .fallocate_fn
= smb_time_audit_fallocate
,
2784 .lock_fn
= smb_time_audit_lock
,
2785 .filesystem_sharemode_fn
= smb_time_audit_filesystem_sharemode
,
2786 .fcntl_fn
= smb_time_audit_fcntl
,
2787 .linux_setlease_fn
= smb_time_audit_linux_setlease
,
2788 .getlock_fn
= smb_time_audit_getlock
,
2789 .symlinkat_fn
= smb_time_audit_symlinkat
,
2790 .readlinkat_fn
= smb_time_audit_readlinkat
,
2791 .linkat_fn
= smb_time_audit_linkat
,
2792 .mknodat_fn
= smb_time_audit_mknodat
,
2793 .realpath_fn
= smb_time_audit_realpath
,
2794 .fchflags_fn
= smb_time_audit_fchflags
,
2795 .file_id_create_fn
= smb_time_audit_file_id_create
,
2796 .fs_file_id_fn
= smb_time_audit_fs_file_id
,
2797 .offload_read_send_fn
= smb_time_audit_offload_read_send
,
2798 .offload_read_recv_fn
= smb_time_audit_offload_read_recv
,
2799 .offload_write_send_fn
= smb_time_audit_offload_write_send
,
2800 .offload_write_recv_fn
= smb_time_audit_offload_write_recv
,
2801 .fget_compression_fn
= smb_time_audit_fget_compression
,
2802 .set_compression_fn
= smb_time_audit_set_compression
,
2803 .snap_check_path_fn
= smb_time_audit_snap_check_path
,
2804 .snap_create_fn
= smb_time_audit_snap_create
,
2805 .snap_delete_fn
= smb_time_audit_snap_delete
,
2806 .fstreaminfo_fn
= smb_time_audit_fstreaminfo
,
2807 .get_real_filename_at_fn
= smb_time_audit_get_real_filename_at
,
2808 .connectpath_fn
= smb_time_audit_connectpath
,
2809 .brl_lock_windows_fn
= smb_time_audit_brl_lock_windows
,
2810 .brl_unlock_windows_fn
= smb_time_audit_brl_unlock_windows
,
2811 .strict_lock_check_fn
= smb_time_audit_strict_lock_check
,
2812 .translate_name_fn
= smb_time_audit_translate_name
,
2813 .parent_pathname_fn
= smb_time_audit_parent_pathname
,
2814 .fsctl_fn
= smb_time_audit_fsctl
,
2815 .get_dos_attributes_send_fn
= smb_time_audit_get_dos_attributes_send
,
2816 .get_dos_attributes_recv_fn
= smb_time_audit_get_dos_attributes_recv
,
2817 .fget_dos_attributes_fn
= smb_time_fget_dos_attributes
,
2818 .fset_dos_attributes_fn
= smb_time_fset_dos_attributes
,
2819 .fget_nt_acl_fn
= smb_time_audit_fget_nt_acl
,
2820 .fset_nt_acl_fn
= smb_time_audit_fset_nt_acl
,
2821 .audit_file_fn
= smb_time_audit_audit_file
,
2822 .sys_acl_get_fd_fn
= smb_time_audit_sys_acl_get_fd
,
2823 .sys_acl_blob_get_fd_fn
= smb_time_audit_sys_acl_blob_get_fd
,
2824 .sys_acl_set_fd_fn
= smb_time_audit_sys_acl_set_fd
,
2825 .sys_acl_delete_def_fd_fn
= smb_time_audit_sys_acl_delete_def_fd
,
2826 .getxattrat_send_fn
= smb_time_audit_getxattrat_send
,
2827 .getxattrat_recv_fn
= smb_time_audit_getxattrat_recv
,
2828 .fgetxattr_fn
= smb_time_audit_fgetxattr
,
2829 .flistxattr_fn
= smb_time_audit_flistxattr
,
2830 .fremovexattr_fn
= smb_time_audit_fremovexattr
,
2831 .fsetxattr_fn
= smb_time_audit_fsetxattr
,
2832 .aio_force_fn
= smb_time_audit_aio_force
,
2833 .durable_cookie_fn
= smb_time_audit_durable_cookie
,
2834 .durable_disconnect_fn
= smb_time_audit_durable_disconnect
,
2835 .durable_reconnect_fn
= smb_time_audit_durable_reconnect
,
2836 .freaddir_attr_fn
= smb_time_audit_freaddir_attr
,
2841 NTSTATUS
vfs_time_audit_init(TALLOC_CTX
*ctx
)
2843 smb_vfs_assert_all_fns(&vfs_time_audit_fns
, "time_audit");
2845 audit_timeout
= (double)lp_parm_int(-1, "time_audit", "timeout",
2847 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION
, "time_audit",
2848 &vfs_time_audit_fns
);