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"
34 #define DBGC_CLASS DBGC_VFS
36 static double audit_timeout
;
38 static void smb_time_audit_log_msg(const char *syscallname
, double elapsed
,
41 DEBUG(0, ("WARNING: VFS call \"%s\" took unexpectedly long "
42 "(%.2f seconds) %s%s-- Validate that file and storage "
43 "subsystems are operating normally\n", syscallname
,
44 elapsed
, (msg
!= NULL
) ? msg
: "",
45 (msg
!= NULL
) ? " " : ""));
48 static void smb_time_audit_log(const char *syscallname
, double elapsed
)
50 smb_time_audit_log_msg(syscallname
, elapsed
, NULL
);
53 static void smb_time_audit_log_fsp(const char *syscallname
, double elapsed
,
54 const struct files_struct
*fsp
)
56 char *base_name
= NULL
;
57 char *connectpath
= NULL
;
61 smb_time_audit_log(syscallname
, elapsed
);
65 connectpath
= fsp
->conn
->connectpath
;
67 base_name
= fsp
->fsp_name
->base_name
;
69 if (connectpath
!= NULL
&& base_name
!= NULL
) {
70 msg
= talloc_asprintf(talloc_tos(), "filename = \"%s/%s\"",
71 connectpath
, base_name
);
72 } else if (connectpath
!= NULL
&& base_name
== NULL
) {
73 msg
= talloc_asprintf(talloc_tos(), "connectpath = \"%s\", "
76 } else if (connectpath
== NULL
&& base_name
!= NULL
) {
77 msg
= talloc_asprintf(talloc_tos(), "connectpath = <NULL>, "
80 } else { /* connectpath == NULL && base_name == NULL */
81 msg
= talloc_asprintf(talloc_tos(), "connectpath = <NULL>, "
82 "base_name = <NULL>");
84 smb_time_audit_log_msg(syscallname
, elapsed
, msg
);
88 static void smb_time_audit_log_fname(const char *syscallname
, double elapsed
,
94 if (getcwd(cwd
, sizeof(cwd
)) == NULL
) {
95 snprintf(cwd
, sizeof(cwd
), "<getcwd() error %d>", errno
);
98 msg
= talloc_asprintf(talloc_tos(),
99 "cwd = \"%s\", filename = \"%s\"",
102 msg
= talloc_asprintf(talloc_tos(),
103 "cwd = \"%s\", filename = <NULL>",
106 smb_time_audit_log_msg(syscallname
, elapsed
, msg
);
110 static void smb_time_audit_log_smb_fname(const char *syscallname
, double elapsed
,
111 const struct smb_filename
*smb_fname
)
113 if (smb_fname
!= NULL
) {
114 smb_time_audit_log_fname(syscallname
, elapsed
,
115 smb_fname
->base_name
);
117 smb_time_audit_log_fname(syscallname
, elapsed
,
118 "smb_fname = <NULL>");
122 static int smb_time_audit_connect(vfs_handle_struct
*handle
,
123 const char *svc
, const char *user
)
126 struct timespec ts1
,ts2
;
133 clock_gettime_mono(&ts1
);
134 result
= SMB_VFS_NEXT_CONNECT(handle
, svc
, user
);
135 clock_gettime_mono(&ts2
);
136 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
137 if (timediff
> audit_timeout
) {
138 smb_time_audit_log_msg("connect", timediff
, user
);
143 static void smb_time_audit_disconnect(vfs_handle_struct
*handle
)
145 struct timespec ts1
,ts2
;
148 clock_gettime_mono(&ts1
);
149 SMB_VFS_NEXT_DISCONNECT(handle
);
150 clock_gettime_mono(&ts2
);
151 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
153 if (timediff
> audit_timeout
) {
154 smb_time_audit_log("disconnect", timediff
);
158 static uint64_t smb_time_audit_disk_free(vfs_handle_struct
*handle
,
160 bool small_query
, uint64_t *bsize
,
161 uint64_t *dfree
, uint64_t *dsize
)
164 struct timespec ts1
,ts2
;
167 clock_gettime_mono(&ts1
);
168 result
= SMB_VFS_NEXT_DISK_FREE(handle
, path
, small_query
, bsize
,
170 clock_gettime_mono(&ts2
);
171 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
173 /* Don't have a reasonable notion of failure here */
174 if (timediff
> audit_timeout
) {
175 smb_time_audit_log_fname("disk_free", timediff
, path
);
181 static int smb_time_audit_get_quota(struct vfs_handle_struct
*handle
,
182 enum SMB_QUOTA_TYPE qtype
, unid_t id
,
186 struct timespec ts1
,ts2
;
189 clock_gettime_mono(&ts1
);
190 result
= SMB_VFS_NEXT_GET_QUOTA(handle
, qtype
, id
, qt
);
191 clock_gettime_mono(&ts2
);
192 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
194 if (timediff
> audit_timeout
) {
195 smb_time_audit_log("get_quota", timediff
);
200 static int smb_time_audit_set_quota(struct vfs_handle_struct
*handle
,
201 enum SMB_QUOTA_TYPE qtype
, unid_t id
,
205 struct timespec ts1
,ts2
;
208 clock_gettime_mono(&ts1
);
209 result
= SMB_VFS_NEXT_SET_QUOTA(handle
, qtype
, id
, qt
);
210 clock_gettime_mono(&ts2
);
211 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
213 if (timediff
> audit_timeout
) {
214 smb_time_audit_log("set_quota", timediff
);
220 static int smb_time_audit_get_shadow_copy_data(struct vfs_handle_struct
*handle
,
221 struct files_struct
*fsp
,
222 struct shadow_copy_data
*shadow_copy_data
,
226 struct timespec ts1
,ts2
;
229 clock_gettime_mono(&ts1
);
230 result
= SMB_VFS_NEXT_GET_SHADOW_COPY_DATA(handle
, fsp
,
231 shadow_copy_data
, labels
);
232 clock_gettime_mono(&ts2
);
233 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
235 if (timediff
> audit_timeout
) {
236 smb_time_audit_log_fsp("get_shadow_copy_data", timediff
, fsp
);
242 static int smb_time_audit_statvfs(struct vfs_handle_struct
*handle
,
244 struct vfs_statvfs_struct
*statbuf
)
247 struct timespec ts1
,ts2
;
250 clock_gettime_mono(&ts1
);
251 result
= SMB_VFS_NEXT_STATVFS(handle
, path
, statbuf
);
252 clock_gettime_mono(&ts2
);
253 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
255 if (timediff
> audit_timeout
) {
256 smb_time_audit_log_fname("statvfs", timediff
, path
);
262 static uint32_t smb_time_audit_fs_capabilities(struct vfs_handle_struct
*handle
,
263 enum timestamp_set_resolution
*p_ts_res
)
266 struct timespec ts1
,ts2
;
269 clock_gettime_mono(&ts1
);
270 result
= SMB_VFS_NEXT_FS_CAPABILITIES(handle
, p_ts_res
);
271 clock_gettime_mono(&ts2
);
272 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
274 if (timediff
> audit_timeout
) {
275 smb_time_audit_log("fs_capabilities", timediff
);
281 static DIR *smb_time_audit_opendir(vfs_handle_struct
*handle
,
283 const char *mask
, uint32 attr
)
286 struct timespec ts1
,ts2
;
289 clock_gettime_mono(&ts1
);
290 result
= SMB_VFS_NEXT_OPENDIR(handle
, fname
, mask
, attr
);
291 clock_gettime_mono(&ts2
);
292 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
294 if (timediff
> audit_timeout
) {
295 smb_time_audit_log_fname("opendir", timediff
, fname
);
301 static DIR *smb_time_audit_fdopendir(vfs_handle_struct
*handle
,
303 const char *mask
, uint32 attr
)
306 struct timespec ts1
,ts2
;
309 clock_gettime_mono(&ts1
);
310 result
= SMB_VFS_NEXT_FDOPENDIR(handle
, fsp
, mask
, attr
);
311 clock_gettime_mono(&ts2
);
312 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
314 if (timediff
> audit_timeout
) {
315 smb_time_audit_log_fsp("fdopendir", timediff
, fsp
);
321 static struct dirent
*smb_time_audit_readdir(vfs_handle_struct
*handle
,
323 SMB_STRUCT_STAT
*sbuf
)
325 struct dirent
*result
;
326 struct timespec ts1
,ts2
;
329 clock_gettime_mono(&ts1
);
330 result
= SMB_VFS_NEXT_READDIR(handle
, dirp
, sbuf
);
331 clock_gettime_mono(&ts2
);
332 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
334 if (timediff
> audit_timeout
) {
335 smb_time_audit_log("readdir", timediff
);
341 static void smb_time_audit_seekdir(vfs_handle_struct
*handle
,
342 DIR *dirp
, long offset
)
344 struct timespec ts1
,ts2
;
347 clock_gettime_mono(&ts1
);
348 SMB_VFS_NEXT_SEEKDIR(handle
, dirp
, offset
);
349 clock_gettime_mono(&ts2
);
350 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
352 if (timediff
> audit_timeout
) {
353 smb_time_audit_log("seekdir", timediff
);
358 static long smb_time_audit_telldir(vfs_handle_struct
*handle
,
362 struct timespec ts1
,ts2
;
365 clock_gettime_mono(&ts1
);
366 result
= SMB_VFS_NEXT_TELLDIR(handle
, dirp
);
367 clock_gettime_mono(&ts2
);
368 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
370 if (timediff
> audit_timeout
) {
371 smb_time_audit_log("telldir", timediff
);
377 static void smb_time_audit_rewinddir(vfs_handle_struct
*handle
,
380 struct timespec ts1
,ts2
;
383 clock_gettime_mono(&ts1
);
384 SMB_VFS_NEXT_REWINDDIR(handle
, dirp
);
385 clock_gettime_mono(&ts2
);
386 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
388 if (timediff
> audit_timeout
) {
389 smb_time_audit_log("rewinddir", timediff
);
394 static int smb_time_audit_mkdir(vfs_handle_struct
*handle
,
395 const char *path
, mode_t mode
)
398 struct timespec ts1
,ts2
;
401 clock_gettime_mono(&ts1
);
402 result
= SMB_VFS_NEXT_MKDIR(handle
, path
, mode
);
403 clock_gettime_mono(&ts2
);
404 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
406 if (timediff
> audit_timeout
) {
407 smb_time_audit_log_fname("mkdir", timediff
, path
);
413 static int smb_time_audit_rmdir(vfs_handle_struct
*handle
,
417 struct timespec ts1
,ts2
;
420 clock_gettime_mono(&ts1
);
421 result
= SMB_VFS_NEXT_RMDIR(handle
, path
);
422 clock_gettime_mono(&ts2
);
423 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
425 if (timediff
> audit_timeout
) {
426 smb_time_audit_log_fname("rmdir", timediff
, path
);
432 static int smb_time_audit_closedir(vfs_handle_struct
*handle
,
436 struct timespec ts1
,ts2
;
439 clock_gettime_mono(&ts1
);
440 result
= SMB_VFS_NEXT_CLOSEDIR(handle
, dirp
);
441 clock_gettime_mono(&ts2
);
442 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
444 if (timediff
> audit_timeout
) {
445 smb_time_audit_log("closedir", timediff
);
451 static void smb_time_audit_init_search_op(vfs_handle_struct
*handle
,
454 struct timespec ts1
,ts2
;
457 clock_gettime_mono(&ts1
);
458 SMB_VFS_NEXT_INIT_SEARCH_OP(handle
, dirp
);
459 clock_gettime_mono(&ts2
);
460 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
462 if (timediff
> audit_timeout
) {
463 smb_time_audit_log("init_search_op", timediff
);
467 static int smb_time_audit_open(vfs_handle_struct
*handle
,
468 struct smb_filename
*fname
,
470 int flags
, mode_t mode
)
473 struct timespec ts1
,ts2
;
476 clock_gettime_mono(&ts1
);
477 result
= SMB_VFS_NEXT_OPEN(handle
, fname
, fsp
, flags
, mode
);
478 clock_gettime_mono(&ts2
);
479 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
481 if (timediff
> audit_timeout
) {
482 smb_time_audit_log_fsp("open", timediff
, fsp
);
488 static NTSTATUS
smb_time_audit_create_file(vfs_handle_struct
*handle
,
489 struct smb_request
*req
,
490 uint16_t root_dir_fid
,
491 struct smb_filename
*fname
,
492 uint32_t access_mask
,
493 uint32_t share_access
,
494 uint32_t create_disposition
,
495 uint32_t create_options
,
496 uint32_t file_attributes
,
497 uint32_t oplock_request
,
498 uint64_t allocation_size
,
499 uint32_t private_flags
,
500 struct security_descriptor
*sd
,
501 struct ea_list
*ea_list
,
502 files_struct
**result_fsp
,
506 struct timespec ts1
,ts2
;
509 clock_gettime_mono(&ts1
);
510 result
= SMB_VFS_NEXT_CREATE_FILE(
513 root_dir_fid
, /* root_dir_fid */
515 access_mask
, /* access_mask */
516 share_access
, /* share_access */
517 create_disposition
, /* create_disposition*/
518 create_options
, /* create_options */
519 file_attributes
, /* file_attributes */
520 oplock_request
, /* oplock_request */
521 allocation_size
, /* allocation_size */
524 ea_list
, /* ea_list */
525 result_fsp
, /* result */
527 clock_gettime_mono(&ts2
);
528 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
530 if (timediff
> audit_timeout
) {
532 * can't use result_fsp this time, may have
533 * invalid content causing smbd crash
535 smb_time_audit_log_smb_fname("create_file", timediff
,
542 static int smb_time_audit_close(vfs_handle_struct
*handle
, files_struct
*fsp
)
545 struct timespec ts1
,ts2
;
548 clock_gettime_mono(&ts1
);
549 result
= SMB_VFS_NEXT_CLOSE(handle
, fsp
);
550 clock_gettime_mono(&ts2
);
551 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
553 if (timediff
> audit_timeout
) {
554 smb_time_audit_log_fsp("close", timediff
, fsp
);
560 static ssize_t
smb_time_audit_read(vfs_handle_struct
*handle
,
561 files_struct
*fsp
, void *data
, size_t n
)
564 struct timespec ts1
,ts2
;
567 clock_gettime_mono(&ts1
);
568 result
= SMB_VFS_NEXT_READ(handle
, fsp
, data
, n
);
569 clock_gettime_mono(&ts2
);
570 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
572 if (timediff
> audit_timeout
) {
573 smb_time_audit_log_fsp("read", timediff
, fsp
);
579 static ssize_t
smb_time_audit_pread(vfs_handle_struct
*handle
,
581 void *data
, size_t n
, off_t offset
)
584 struct timespec ts1
,ts2
;
587 clock_gettime_mono(&ts1
);
588 result
= SMB_VFS_NEXT_PREAD(handle
, fsp
, data
, n
, offset
);
589 clock_gettime_mono(&ts2
);
590 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
592 if (timediff
> audit_timeout
) {
593 smb_time_audit_log_fsp("pread", timediff
, fsp
);
599 struct smb_time_audit_pread_state
{
600 struct files_struct
*fsp
;
606 static void smb_time_audit_pread_done(struct tevent_req
*subreq
);
608 static struct tevent_req
*smb_time_audit_pread_send(
609 struct vfs_handle_struct
*handle
, TALLOC_CTX
*mem_ctx
,
610 struct tevent_context
*ev
, struct files_struct
*fsp
,
611 void *data
, size_t n
, off_t offset
)
613 struct tevent_req
*req
, *subreq
;
614 struct smb_time_audit_pread_state
*state
;
616 req
= tevent_req_create(mem_ctx
, &state
,
617 struct smb_time_audit_pread_state
);
621 clock_gettime_mono(&state
->ts1
);
624 subreq
= SMB_VFS_NEXT_PREAD_SEND(state
, ev
, handle
, fsp
, data
,
626 if (tevent_req_nomem(subreq
, req
)) {
627 return tevent_req_post(req
, ev
);
629 tevent_req_set_callback(subreq
, smb_time_audit_pread_done
, req
);
633 static void smb_time_audit_pread_done(struct tevent_req
*subreq
)
635 struct tevent_req
*req
= tevent_req_callback_data(
636 subreq
, struct tevent_req
);
637 struct smb_time_audit_pread_state
*state
= tevent_req_data(
638 req
, struct smb_time_audit_pread_state
);
640 state
->ret
= SMB_VFS_PREAD_RECV(subreq
, &state
->err
);
642 tevent_req_done(req
);
645 static ssize_t
smb_time_audit_pread_recv(struct tevent_req
*req
, int *err
)
647 struct smb_time_audit_pread_state
*state
= tevent_req_data(
648 req
, struct smb_time_audit_pread_state
);
652 clock_gettime_mono(&ts2
);
653 timediff
= nsec_time_diff(&ts2
,&state
->ts1
)*1.0e-9;
655 if (timediff
> audit_timeout
) {
656 smb_time_audit_log_fsp("pread", timediff
, state
->fsp
);
659 if (tevent_req_is_unix_error(req
, err
)) {
666 static ssize_t
smb_time_audit_write(vfs_handle_struct
*handle
,
668 const void *data
, size_t n
)
671 struct timespec ts1
,ts2
;
674 clock_gettime_mono(&ts1
);
675 result
= SMB_VFS_NEXT_WRITE(handle
, fsp
, data
, n
);
676 clock_gettime_mono(&ts2
);
677 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
679 if (timediff
> audit_timeout
) {
680 smb_time_audit_log_fsp("write", timediff
, fsp
);
686 static ssize_t
smb_time_audit_pwrite(vfs_handle_struct
*handle
,
688 const void *data
, size_t n
,
692 struct timespec ts1
,ts2
;
695 clock_gettime_mono(&ts1
);
696 result
= SMB_VFS_NEXT_PWRITE(handle
, fsp
, data
, n
, offset
);
697 clock_gettime_mono(&ts2
);
698 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
700 if (timediff
> audit_timeout
) {
701 smb_time_audit_log_fsp("pwrite", timediff
, fsp
);
707 struct smb_time_audit_pwrite_state
{
708 struct files_struct
*fsp
;
714 static void smb_time_audit_pwrite_done(struct tevent_req
*subreq
);
716 static struct tevent_req
*smb_time_audit_pwrite_send(
717 struct vfs_handle_struct
*handle
, TALLOC_CTX
*mem_ctx
,
718 struct tevent_context
*ev
, struct files_struct
*fsp
,
719 const void *data
, size_t n
, off_t offset
)
721 struct tevent_req
*req
, *subreq
;
722 struct smb_time_audit_pwrite_state
*state
;
724 req
= tevent_req_create(mem_ctx
, &state
,
725 struct smb_time_audit_pwrite_state
);
729 clock_gettime_mono(&state
->ts1
);
732 subreq
= SMB_VFS_NEXT_PWRITE_SEND(state
, ev
, handle
, fsp
, data
,
734 if (tevent_req_nomem(subreq
, req
)) {
735 return tevent_req_post(req
, ev
);
737 tevent_req_set_callback(subreq
, smb_time_audit_pwrite_done
, req
);
741 static void smb_time_audit_pwrite_done(struct tevent_req
*subreq
)
743 struct tevent_req
*req
= tevent_req_callback_data(
744 subreq
, struct tevent_req
);
745 struct smb_time_audit_pwrite_state
*state
= tevent_req_data(
746 req
, struct smb_time_audit_pwrite_state
);
748 state
->ret
= SMB_VFS_PWRITE_RECV(subreq
, &state
->err
);
750 tevent_req_done(req
);
753 static ssize_t
smb_time_audit_pwrite_recv(struct tevent_req
*req
, int *err
)
755 struct smb_time_audit_pwrite_state
*state
= tevent_req_data(
756 req
, struct smb_time_audit_pwrite_state
);
760 clock_gettime_mono(&ts2
);
761 timediff
= nsec_time_diff(&ts2
,&state
->ts1
)*1.0e-9;
763 if (timediff
> audit_timeout
) {
764 smb_time_audit_log_fsp("pwrite", timediff
, state
->fsp
);
767 if (tevent_req_is_unix_error(req
, err
)) {
774 static off_t
smb_time_audit_lseek(vfs_handle_struct
*handle
,
776 off_t offset
, int whence
)
779 struct timespec ts1
,ts2
;
782 clock_gettime_mono(&ts1
);
783 result
= SMB_VFS_NEXT_LSEEK(handle
, fsp
, offset
, whence
);
784 clock_gettime_mono(&ts2
);
785 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
787 if (timediff
> audit_timeout
) {
788 smb_time_audit_log_fsp("lseek", timediff
, fsp
);
794 static ssize_t
smb_time_audit_sendfile(vfs_handle_struct
*handle
, int tofd
,
795 files_struct
*fromfsp
,
796 const DATA_BLOB
*hdr
, off_t offset
,
800 struct timespec ts1
,ts2
;
803 clock_gettime_mono(&ts1
);
804 result
= SMB_VFS_NEXT_SENDFILE(handle
, tofd
, fromfsp
, hdr
, offset
, n
);
805 clock_gettime_mono(&ts2
);
806 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
808 if (timediff
> audit_timeout
) {
809 smb_time_audit_log_fsp("sendfile", timediff
, fromfsp
);
815 static ssize_t
smb_time_audit_recvfile(vfs_handle_struct
*handle
, int fromfd
,
821 struct timespec ts1
,ts2
;
824 clock_gettime_mono(&ts1
);
825 result
= SMB_VFS_NEXT_RECVFILE(handle
, fromfd
, tofsp
, offset
, n
);
826 clock_gettime_mono(&ts2
);
827 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
829 if (timediff
> audit_timeout
) {
830 smb_time_audit_log_fsp("recvfile", timediff
, tofsp
);
836 static int smb_time_audit_rename(vfs_handle_struct
*handle
,
837 const struct smb_filename
*oldname
,
838 const struct smb_filename
*newname
)
841 struct timespec ts1
,ts2
;
844 clock_gettime_mono(&ts1
);
845 result
= SMB_VFS_NEXT_RENAME(handle
, oldname
, newname
);
846 clock_gettime_mono(&ts2
);
847 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
849 if (timediff
> audit_timeout
) {
850 smb_time_audit_log_smb_fname("rename", timediff
, newname
);
856 static int smb_time_audit_fsync(vfs_handle_struct
*handle
, files_struct
*fsp
)
859 struct timespec ts1
,ts2
;
862 clock_gettime_mono(&ts1
);
863 result
= SMB_VFS_NEXT_FSYNC(handle
, fsp
);
864 clock_gettime_mono(&ts2
);
865 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
867 if (timediff
> audit_timeout
) {
868 smb_time_audit_log_fsp("fsync", timediff
, fsp
);
874 struct smb_time_audit_fsync_state
{
875 struct files_struct
*fsp
;
881 static void smb_time_audit_fsync_done(struct tevent_req
*subreq
);
883 static struct tevent_req
*smb_time_audit_fsync_send(
884 struct vfs_handle_struct
*handle
, TALLOC_CTX
*mem_ctx
,
885 struct tevent_context
*ev
, struct files_struct
*fsp
)
887 struct tevent_req
*req
, *subreq
;
888 struct smb_time_audit_fsync_state
*state
;
890 req
= tevent_req_create(mem_ctx
, &state
,
891 struct smb_time_audit_fsync_state
);
895 clock_gettime_mono(&state
->ts1
);
898 subreq
= SMB_VFS_NEXT_FSYNC_SEND(state
, ev
, handle
, fsp
);
899 if (tevent_req_nomem(subreq
, req
)) {
900 return tevent_req_post(req
, ev
);
902 tevent_req_set_callback(subreq
, smb_time_audit_fsync_done
, req
);
906 static void smb_time_audit_fsync_done(struct tevent_req
*subreq
)
908 struct tevent_req
*req
= tevent_req_callback_data(
909 subreq
, struct tevent_req
);
910 struct smb_time_audit_fsync_state
*state
= tevent_req_data(
911 req
, struct smb_time_audit_fsync_state
);
913 state
->ret
= SMB_VFS_FSYNC_RECV(subreq
, &state
->err
);
915 tevent_req_done(req
);
918 static int smb_time_audit_fsync_recv(struct tevent_req
*req
, int *err
)
920 struct smb_time_audit_fsync_state
*state
= tevent_req_data(
921 req
, struct smb_time_audit_fsync_state
);
925 clock_gettime_mono(&ts2
);
926 timediff
= nsec_time_diff(&ts2
,&state
->ts1
)*1.0e-9;
928 if (timediff
> audit_timeout
) {
929 smb_time_audit_log_fsp("fsync", timediff
, state
->fsp
);
932 if (tevent_req_is_unix_error(req
, err
)) {
939 static int smb_time_audit_stat(vfs_handle_struct
*handle
,
940 struct smb_filename
*fname
)
943 struct timespec ts1
,ts2
;
946 clock_gettime_mono(&ts1
);
947 result
= SMB_VFS_NEXT_STAT(handle
, fname
);
948 clock_gettime_mono(&ts2
);
949 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
951 if (timediff
> audit_timeout
) {
952 smb_time_audit_log_smb_fname("stat", timediff
, fname
);
958 static int smb_time_audit_fstat(vfs_handle_struct
*handle
, files_struct
*fsp
,
959 SMB_STRUCT_STAT
*sbuf
)
962 struct timespec ts1
,ts2
;
965 clock_gettime_mono(&ts1
);
966 result
= SMB_VFS_NEXT_FSTAT(handle
, fsp
, sbuf
);
967 clock_gettime_mono(&ts2
);
968 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
970 if (timediff
> audit_timeout
) {
971 smb_time_audit_log_fsp("fstat", timediff
, fsp
);
977 static int smb_time_audit_lstat(vfs_handle_struct
*handle
,
978 struct smb_filename
*path
)
981 struct timespec ts1
,ts2
;
984 clock_gettime_mono(&ts1
);
985 result
= SMB_VFS_NEXT_LSTAT(handle
, path
);
986 clock_gettime_mono(&ts2
);
987 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
989 if (timediff
> audit_timeout
) {
990 smb_time_audit_log_smb_fname("lstat", timediff
, path
);
996 static uint64_t smb_time_audit_get_alloc_size(vfs_handle_struct
*handle
,
998 const SMB_STRUCT_STAT
*sbuf
)
1001 struct timespec ts1
,ts2
;
1004 clock_gettime_mono(&ts1
);
1005 result
= SMB_VFS_NEXT_GET_ALLOC_SIZE(handle
, fsp
, sbuf
);
1006 clock_gettime_mono(&ts2
);
1007 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1009 if (timediff
> audit_timeout
) {
1010 smb_time_audit_log_fsp("get_alloc_size", timediff
, fsp
);
1016 static int smb_time_audit_unlink(vfs_handle_struct
*handle
,
1017 const struct smb_filename
*path
)
1020 struct timespec ts1
,ts2
;
1023 clock_gettime_mono(&ts1
);
1024 result
= SMB_VFS_NEXT_UNLINK(handle
, path
);
1025 clock_gettime_mono(&ts2
);
1026 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1028 if (timediff
> audit_timeout
) {
1029 smb_time_audit_log_smb_fname("unlink", timediff
, path
);
1035 static int smb_time_audit_chmod(vfs_handle_struct
*handle
,
1036 const char *path
, mode_t mode
)
1039 struct timespec ts1
,ts2
;
1042 clock_gettime_mono(&ts1
);
1043 result
= SMB_VFS_NEXT_CHMOD(handle
, path
, mode
);
1044 clock_gettime_mono(&ts2
);
1045 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1047 if (timediff
> audit_timeout
) {
1048 smb_time_audit_log_fname("chmod", timediff
, path
);
1054 static int smb_time_audit_fchmod(vfs_handle_struct
*handle
, files_struct
*fsp
,
1058 struct timespec ts1
,ts2
;
1061 clock_gettime_mono(&ts1
);
1062 result
= SMB_VFS_NEXT_FCHMOD(handle
, fsp
, mode
);
1063 clock_gettime_mono(&ts2
);
1064 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1066 if (timediff
> audit_timeout
) {
1067 smb_time_audit_log_fsp("fchmod", timediff
, fsp
);
1073 static int smb_time_audit_chown(vfs_handle_struct
*handle
,
1074 const char *path
, uid_t uid
, gid_t gid
)
1077 struct timespec ts1
,ts2
;
1080 clock_gettime_mono(&ts1
);
1081 result
= SMB_VFS_NEXT_CHOWN(handle
, path
, uid
, gid
);
1082 clock_gettime_mono(&ts2
);
1083 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1085 if (timediff
> audit_timeout
) {
1086 smb_time_audit_log_fname("chown", timediff
, path
);
1092 static int smb_time_audit_fchown(vfs_handle_struct
*handle
, files_struct
*fsp
,
1093 uid_t uid
, gid_t gid
)
1096 struct timespec ts1
,ts2
;
1099 clock_gettime_mono(&ts1
);
1100 result
= SMB_VFS_NEXT_FCHOWN(handle
, fsp
, uid
, gid
);
1101 clock_gettime_mono(&ts2
);
1102 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1104 if (timediff
> audit_timeout
) {
1105 smb_time_audit_log_fsp("fchown", timediff
, fsp
);
1111 static int smb_time_audit_lchown(vfs_handle_struct
*handle
,
1112 const char *path
, uid_t uid
, gid_t gid
)
1115 struct timespec ts1
,ts2
;
1118 clock_gettime_mono(&ts1
);
1119 result
= SMB_VFS_NEXT_LCHOWN(handle
, path
, uid
, gid
);
1120 clock_gettime_mono(&ts2
);
1121 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1123 if (timediff
> audit_timeout
) {
1124 smb_time_audit_log_fname("lchown", timediff
, path
);
1130 static int smb_time_audit_chdir(vfs_handle_struct
*handle
, const char *path
)
1133 struct timespec ts1
,ts2
;
1136 clock_gettime_mono(&ts1
);
1137 result
= SMB_VFS_NEXT_CHDIR(handle
, path
);
1138 clock_gettime_mono(&ts2
);
1139 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1141 if (timediff
> audit_timeout
) {
1142 smb_time_audit_log_fname("chdir", timediff
, path
);
1148 static char *smb_time_audit_getwd(vfs_handle_struct
*handle
)
1151 struct timespec ts1
,ts2
;
1154 clock_gettime_mono(&ts1
);
1155 result
= SMB_VFS_NEXT_GETWD(handle
);
1156 clock_gettime_mono(&ts2
);
1157 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1159 if (timediff
> audit_timeout
) {
1160 smb_time_audit_log("getwd", timediff
);
1166 static int smb_time_audit_ntimes(vfs_handle_struct
*handle
,
1167 const struct smb_filename
*path
,
1168 struct smb_file_time
*ft
)
1171 struct timespec ts1
,ts2
;
1174 clock_gettime_mono(&ts1
);
1175 result
= SMB_VFS_NEXT_NTIMES(handle
, path
, ft
);
1176 clock_gettime_mono(&ts2
);
1177 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1179 if (timediff
> audit_timeout
) {
1180 smb_time_audit_log_smb_fname("ntimes", timediff
, path
);
1186 static int smb_time_audit_ftruncate(vfs_handle_struct
*handle
,
1191 struct timespec ts1
,ts2
;
1194 clock_gettime_mono(&ts1
);
1195 result
= SMB_VFS_NEXT_FTRUNCATE(handle
, fsp
, len
);
1196 clock_gettime_mono(&ts2
);
1197 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1199 if (timediff
> audit_timeout
) {
1200 smb_time_audit_log_fsp("ftruncate", timediff
, fsp
);
1206 static int smb_time_audit_fallocate(vfs_handle_struct
*handle
,
1208 enum vfs_fallocate_mode mode
,
1213 struct timespec ts1
,ts2
;
1216 clock_gettime_mono(&ts1
);
1217 result
= SMB_VFS_NEXT_FALLOCATE(handle
, fsp
, mode
, offset
, len
);
1218 clock_gettime_mono(&ts2
);
1219 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1221 if (timediff
> audit_timeout
) {
1222 smb_time_audit_log_fsp("fallocate", timediff
, fsp
);
1228 static bool smb_time_audit_lock(vfs_handle_struct
*handle
, files_struct
*fsp
,
1229 int op
, off_t offset
, off_t count
,
1233 struct timespec ts1
,ts2
;
1236 clock_gettime_mono(&ts1
);
1237 result
= SMB_VFS_NEXT_LOCK(handle
, fsp
, op
, offset
, count
, type
);
1238 clock_gettime_mono(&ts2
);
1239 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1241 if (timediff
> audit_timeout
) {
1242 smb_time_audit_log_fsp("lock", timediff
, fsp
);
1248 static int smb_time_audit_kernel_flock(struct vfs_handle_struct
*handle
,
1249 struct files_struct
*fsp
,
1250 uint32 share_mode
, uint32 access_mask
)
1253 struct timespec ts1
,ts2
;
1256 clock_gettime_mono(&ts1
);
1257 result
= SMB_VFS_NEXT_KERNEL_FLOCK(handle
, fsp
, share_mode
,
1259 clock_gettime_mono(&ts2
);
1260 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1262 if (timediff
> audit_timeout
) {
1263 smb_time_audit_log_fsp("kernel_flock", timediff
, fsp
);
1269 static int smb_time_audit_linux_setlease(vfs_handle_struct
*handle
,
1274 struct timespec ts1
,ts2
;
1277 clock_gettime_mono(&ts1
);
1278 result
= SMB_VFS_NEXT_LINUX_SETLEASE(handle
, fsp
, leasetype
);
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_fsp("linux_setlease", timediff
, fsp
);
1289 static bool smb_time_audit_getlock(vfs_handle_struct
*handle
,
1291 off_t
*poffset
, off_t
*pcount
,
1292 int *ptype
, pid_t
*ppid
)
1295 struct timespec ts1
,ts2
;
1298 clock_gettime_mono(&ts1
);
1299 result
= SMB_VFS_NEXT_GETLOCK(handle
, fsp
, poffset
, pcount
, ptype
,
1301 clock_gettime_mono(&ts2
);
1302 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1304 if (timediff
> audit_timeout
) {
1305 smb_time_audit_log_fsp("getlock", timediff
, fsp
);
1311 static int smb_time_audit_symlink(vfs_handle_struct
*handle
,
1312 const char *oldpath
, const char *newpath
)
1315 struct timespec ts1
,ts2
;
1318 clock_gettime_mono(&ts1
);
1319 result
= SMB_VFS_NEXT_SYMLINK(handle
, oldpath
, newpath
);
1320 clock_gettime_mono(&ts2
);
1321 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1323 if (timediff
> audit_timeout
) {
1324 smb_time_audit_log_fname("symlink", timediff
, newpath
);
1330 static int smb_time_audit_readlink(vfs_handle_struct
*handle
,
1331 const char *path
, char *buf
, size_t bufsiz
)
1334 struct timespec ts1
,ts2
;
1337 clock_gettime_mono(&ts1
);
1338 result
= SMB_VFS_NEXT_READLINK(handle
, path
, buf
, bufsiz
);
1339 clock_gettime_mono(&ts2
);
1340 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1342 if (timediff
> audit_timeout
) {
1343 smb_time_audit_log_fname("readlink", timediff
, path
);
1349 static int smb_time_audit_link(vfs_handle_struct
*handle
,
1350 const char *oldpath
, const char *newpath
)
1353 struct timespec ts1
,ts2
;
1356 clock_gettime_mono(&ts1
);
1357 result
= SMB_VFS_NEXT_LINK(handle
, oldpath
, newpath
);
1358 clock_gettime_mono(&ts2
);
1359 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1361 if (timediff
> audit_timeout
) {
1362 smb_time_audit_log_fname("link", timediff
, newpath
);
1368 static int smb_time_audit_mknod(vfs_handle_struct
*handle
,
1369 const char *pathname
, mode_t mode
,
1373 struct timespec ts1
,ts2
;
1376 clock_gettime_mono(&ts1
);
1377 result
= SMB_VFS_NEXT_MKNOD(handle
, pathname
, mode
, dev
);
1378 clock_gettime_mono(&ts2
);
1379 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1381 if (timediff
> audit_timeout
) {
1382 smb_time_audit_log_fname("mknod", timediff
, pathname
);
1388 static char *smb_time_audit_realpath(vfs_handle_struct
*handle
,
1392 struct timespec ts1
,ts2
;
1395 clock_gettime_mono(&ts1
);
1396 result
= SMB_VFS_NEXT_REALPATH(handle
, path
);
1397 clock_gettime_mono(&ts2
);
1398 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1400 if (timediff
> audit_timeout
) {
1401 smb_time_audit_log_fname("realpath", timediff
, path
);
1407 static NTSTATUS
smb_time_audit_notify_watch(struct vfs_handle_struct
*handle
,
1408 struct sys_notify_context
*ctx
,
1411 uint32_t *subdir_filter
,
1412 void (*callback
)(struct sys_notify_context
*ctx
,
1414 struct notify_event
*ev
),
1415 void *private_data
, void *handle_p
)
1418 struct timespec ts1
,ts2
;
1421 clock_gettime_mono(&ts1
);
1422 result
= SMB_VFS_NEXT_NOTIFY_WATCH(handle
, ctx
, path
,
1423 filter
, subdir_filter
, callback
,
1424 private_data
, handle_p
);
1425 clock_gettime_mono(&ts2
);
1426 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1428 if (timediff
> audit_timeout
) {
1429 smb_time_audit_log_fname("notify_watch", timediff
, path
);
1435 static int smb_time_audit_chflags(vfs_handle_struct
*handle
,
1436 const char *path
, unsigned int flags
)
1439 struct timespec ts1
,ts2
;
1442 clock_gettime_mono(&ts1
);
1443 result
= SMB_VFS_NEXT_CHFLAGS(handle
, path
, flags
);
1444 clock_gettime_mono(&ts2
);
1445 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1447 if (timediff
> audit_timeout
) {
1448 smb_time_audit_log_fname("chflags", timediff
, path
);
1454 static struct file_id
smb_time_audit_file_id_create(struct vfs_handle_struct
*handle
,
1455 const SMB_STRUCT_STAT
*sbuf
)
1457 struct file_id id_zero
;
1458 struct file_id result
;
1459 struct timespec ts1
,ts2
;
1462 ZERO_STRUCT(id_zero
);
1464 clock_gettime_mono(&ts1
);
1465 result
= SMB_VFS_NEXT_FILE_ID_CREATE(handle
, sbuf
);
1466 clock_gettime_mono(&ts2
);
1467 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1469 if (timediff
> audit_timeout
) {
1470 smb_time_audit_log("file_id_create", timediff
);
1476 static NTSTATUS
smb_time_audit_streaminfo(vfs_handle_struct
*handle
,
1477 struct files_struct
*fsp
,
1479 TALLOC_CTX
*mem_ctx
,
1480 unsigned int *pnum_streams
,
1481 struct stream_struct
**pstreams
)
1484 struct timespec ts1
,ts2
;
1487 clock_gettime_mono(&ts1
);
1488 result
= SMB_VFS_NEXT_STREAMINFO(handle
, fsp
, fname
, mem_ctx
,
1489 pnum_streams
, pstreams
);
1490 clock_gettime_mono(&ts2
);
1491 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1493 if (timediff
> audit_timeout
) {
1494 smb_time_audit_log_fsp("streaminfo", timediff
, fsp
);
1500 static int smb_time_audit_get_real_filename(struct vfs_handle_struct
*handle
,
1503 TALLOC_CTX
*mem_ctx
,
1507 struct timespec ts1
,ts2
;
1510 clock_gettime_mono(&ts1
);
1511 result
= SMB_VFS_NEXT_GET_REAL_FILENAME(handle
, path
, name
, mem_ctx
,
1513 clock_gettime_mono(&ts2
);
1514 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1516 if (timediff
> audit_timeout
) {
1517 smb_time_audit_log_fname("get_real_filename", timediff
, path
);
1523 static const char *smb_time_audit_connectpath(vfs_handle_struct
*handle
,
1527 struct timespec ts1
,ts2
;
1530 clock_gettime_mono(&ts1
);
1531 result
= SMB_VFS_NEXT_CONNECTPATH(handle
, fname
);
1532 clock_gettime_mono(&ts2
);
1533 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1535 if (timediff
> audit_timeout
) {
1536 smb_time_audit_log_fname("connectpath", timediff
, fname
);
1542 static NTSTATUS
smb_time_audit_brl_lock_windows(struct vfs_handle_struct
*handle
,
1543 struct byte_range_lock
*br_lck
,
1544 struct lock_struct
*plock
,
1546 struct blocking_lock_record
*blr
)
1549 struct timespec ts1
,ts2
;
1552 clock_gettime_mono(&ts1
);
1553 result
= SMB_VFS_NEXT_BRL_LOCK_WINDOWS(handle
, br_lck
, plock
,
1554 blocking_lock
, blr
);
1555 clock_gettime_mono(&ts2
);
1556 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1558 if (timediff
> audit_timeout
) {
1559 smb_time_audit_log_fsp("brl_lock_windows", timediff
,
1566 static bool smb_time_audit_brl_unlock_windows(struct vfs_handle_struct
*handle
,
1567 struct messaging_context
*msg_ctx
,
1568 struct byte_range_lock
*br_lck
,
1569 const struct lock_struct
*plock
)
1572 struct timespec ts1
,ts2
;
1575 clock_gettime_mono(&ts1
);
1576 result
= SMB_VFS_NEXT_BRL_UNLOCK_WINDOWS(handle
, msg_ctx
, br_lck
,
1578 clock_gettime_mono(&ts2
);
1579 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1581 if (timediff
> audit_timeout
) {
1582 smb_time_audit_log_fsp("brl_unlock_windows", timediff
,
1589 static bool smb_time_audit_brl_cancel_windows(struct vfs_handle_struct
*handle
,
1590 struct byte_range_lock
*br_lck
,
1591 struct lock_struct
*plock
,
1592 struct blocking_lock_record
*blr
)
1595 struct timespec ts1
,ts2
;
1598 clock_gettime_mono(&ts1
);
1599 result
= SMB_VFS_NEXT_BRL_CANCEL_WINDOWS(handle
, br_lck
, plock
, blr
);
1600 clock_gettime_mono(&ts2
);
1601 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1603 if (timediff
> audit_timeout
) {
1604 smb_time_audit_log_fsp("brl_cancel_windows", timediff
,
1611 static bool smb_time_audit_strict_lock(struct vfs_handle_struct
*handle
,
1612 struct files_struct
*fsp
,
1613 struct lock_struct
*plock
)
1616 struct timespec ts1
,ts2
;
1619 clock_gettime_mono(&ts1
);
1620 result
= SMB_VFS_NEXT_STRICT_LOCK(handle
, fsp
, plock
);
1621 clock_gettime_mono(&ts2
);
1622 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1624 if (timediff
> audit_timeout
) {
1625 smb_time_audit_log_fsp("strict_lock", timediff
, fsp
);
1631 static void smb_time_audit_strict_unlock(struct vfs_handle_struct
*handle
,
1632 struct files_struct
*fsp
,
1633 struct lock_struct
*plock
)
1635 struct timespec ts1
,ts2
;
1638 clock_gettime_mono(&ts1
);
1639 SMB_VFS_NEXT_STRICT_UNLOCK(handle
, fsp
, plock
);
1640 clock_gettime_mono(&ts2
);
1641 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1643 if (timediff
> audit_timeout
) {
1644 smb_time_audit_log_fsp("strict_unlock", timediff
, fsp
);
1648 static NTSTATUS
smb_time_audit_translate_name(struct vfs_handle_struct
*handle
,
1650 enum vfs_translate_direction direction
,
1651 TALLOC_CTX
*mem_ctx
,
1655 struct timespec ts1
,ts2
;
1658 clock_gettime_mono(&ts1
);
1659 result
= SMB_VFS_NEXT_TRANSLATE_NAME(handle
, name
, direction
, mem_ctx
,
1661 clock_gettime_mono(&ts2
);
1662 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1664 if (timediff
> audit_timeout
) {
1665 smb_time_audit_log_fname("translate_name", timediff
, name
);
1671 static NTSTATUS
smb_time_audit_fget_nt_acl(vfs_handle_struct
*handle
,
1673 uint32 security_info
,
1674 TALLOC_CTX
*mem_ctx
,
1675 struct security_descriptor
**ppdesc
)
1678 struct timespec ts1
,ts2
;
1681 clock_gettime_mono(&ts1
);
1682 result
= SMB_VFS_NEXT_FGET_NT_ACL(handle
, fsp
, security_info
,
1684 clock_gettime_mono(&ts2
);
1685 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1687 if (timediff
> audit_timeout
) {
1688 smb_time_audit_log_fsp("fget_nt_acl", timediff
, fsp
);
1694 static NTSTATUS
smb_time_audit_get_nt_acl(vfs_handle_struct
*handle
,
1696 uint32 security_info
,
1697 TALLOC_CTX
*mem_ctx
,
1698 struct security_descriptor
**ppdesc
)
1701 struct timespec ts1
,ts2
;
1704 clock_gettime_mono(&ts1
);
1705 result
= SMB_VFS_NEXT_GET_NT_ACL(handle
, name
, security_info
,
1707 clock_gettime_mono(&ts2
);
1708 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1710 if (timediff
> audit_timeout
) {
1711 smb_time_audit_log_fname("get_nt_acl", timediff
, name
);
1717 static NTSTATUS
smb_time_audit_fset_nt_acl(vfs_handle_struct
*handle
,
1719 uint32 security_info_sent
,
1720 const struct security_descriptor
*psd
)
1723 struct timespec ts1
,ts2
;
1726 clock_gettime_mono(&ts1
);
1727 result
= SMB_VFS_NEXT_FSET_NT_ACL(handle
, fsp
, security_info_sent
,
1729 clock_gettime_mono(&ts2
);
1730 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1732 if (timediff
> audit_timeout
) {
1733 smb_time_audit_log_fsp("fset_nt_acl", timediff
, fsp
);
1739 static int smb_time_audit_chmod_acl(vfs_handle_struct
*handle
,
1740 const char *path
, mode_t mode
)
1743 struct timespec ts1
,ts2
;
1746 clock_gettime_mono(&ts1
);
1747 result
= SMB_VFS_NEXT_CHMOD_ACL(handle
, path
, mode
);
1748 clock_gettime_mono(&ts2
);
1749 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1751 if (timediff
> audit_timeout
) {
1752 smb_time_audit_log_fname("chmod_acl", timediff
, path
);
1758 static int smb_time_audit_fchmod_acl(vfs_handle_struct
*handle
,
1759 files_struct
*fsp
, mode_t mode
)
1762 struct timespec ts1
,ts2
;
1765 clock_gettime_mono(&ts1
);
1766 result
= SMB_VFS_NEXT_FCHMOD_ACL(handle
, fsp
, mode
);
1767 clock_gettime_mono(&ts2
);
1768 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1770 if (timediff
> audit_timeout
) {
1771 smb_time_audit_log_fsp("fchmod_acl", timediff
, fsp
);
1777 static SMB_ACL_T
smb_time_audit_sys_acl_get_file(vfs_handle_struct
*handle
,
1779 SMB_ACL_TYPE_T type
,
1780 TALLOC_CTX
*mem_ctx
)
1783 struct timespec ts1
,ts2
;
1786 clock_gettime_mono(&ts1
);
1787 result
= SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle
, path_p
, type
, mem_ctx
);
1788 clock_gettime_mono(&ts2
);
1789 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1791 if (timediff
> audit_timeout
) {
1792 smb_time_audit_log_fname("sys_acl_get_file", timediff
, path_p
);
1798 static SMB_ACL_T
smb_time_audit_sys_acl_get_fd(vfs_handle_struct
*handle
,
1800 TALLOC_CTX
*mem_ctx
)
1803 struct timespec ts1
,ts2
;
1806 clock_gettime_mono(&ts1
);
1807 result
= SMB_VFS_NEXT_SYS_ACL_GET_FD(handle
, fsp
, mem_ctx
);
1808 clock_gettime_mono(&ts2
);
1809 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1811 if (timediff
> audit_timeout
) {
1812 smb_time_audit_log_fsp("sys_acl_get_fd", timediff
, fsp
);
1819 static int smb_time_audit_sys_acl_blob_get_file(vfs_handle_struct
*handle
,
1821 TALLOC_CTX
*mem_ctx
,
1822 char **blob_description
,
1826 struct timespec ts1
,ts2
;
1829 clock_gettime_mono(&ts1
);
1830 result
= SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FILE(handle
, path_p
, mem_ctx
, blob_description
, blob
);
1831 clock_gettime_mono(&ts2
);
1832 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1834 if (timediff
> audit_timeout
) {
1835 smb_time_audit_log("sys_acl_blob_get_file", timediff
);
1841 static int smb_time_audit_sys_acl_blob_get_fd(vfs_handle_struct
*handle
,
1843 TALLOC_CTX
*mem_ctx
,
1844 char **blob_description
,
1848 struct timespec ts1
,ts2
;
1851 clock_gettime_mono(&ts1
);
1852 result
= SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle
, fsp
, mem_ctx
, blob_description
, blob
);
1853 clock_gettime_mono(&ts2
);
1854 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1856 if (timediff
> audit_timeout
) {
1857 smb_time_audit_log("sys_acl_blob_get_fd", timediff
);
1863 static int smb_time_audit_sys_acl_set_file(vfs_handle_struct
*handle
,
1865 SMB_ACL_TYPE_T acltype
,
1869 struct timespec ts1
,ts2
;
1872 clock_gettime_mono(&ts1
);
1873 result
= SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle
, name
, acltype
,
1875 clock_gettime_mono(&ts2
);
1876 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1878 if (timediff
> audit_timeout
) {
1879 smb_time_audit_log_fname("sys_acl_set_file", timediff
, name
);
1885 static int smb_time_audit_sys_acl_set_fd(vfs_handle_struct
*handle
,
1890 struct timespec ts1
,ts2
;
1893 clock_gettime_mono(&ts1
);
1894 result
= SMB_VFS_NEXT_SYS_ACL_SET_FD(handle
, fsp
, theacl
);
1895 clock_gettime_mono(&ts2
);
1896 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1898 if (timediff
> audit_timeout
) {
1899 smb_time_audit_log_fsp("sys_acl_set_fd", timediff
, fsp
);
1905 static int smb_time_audit_sys_acl_delete_def_file(vfs_handle_struct
*handle
,
1909 struct timespec ts1
,ts2
;
1912 clock_gettime_mono(&ts1
);
1913 result
= SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle
, path
);
1914 clock_gettime_mono(&ts2
);
1915 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1917 if (timediff
> audit_timeout
) {
1918 smb_time_audit_log_fname("sys_acl_delete_def_file", timediff
, path
);
1924 static ssize_t
smb_time_audit_getxattr(struct vfs_handle_struct
*handle
,
1925 const char *path
, const char *name
,
1926 void *value
, size_t size
)
1929 struct timespec ts1
,ts2
;
1932 clock_gettime_mono(&ts1
);
1933 result
= SMB_VFS_NEXT_GETXATTR(handle
, path
, name
, value
, size
);
1934 clock_gettime_mono(&ts2
);
1935 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1937 if (timediff
> audit_timeout
) {
1938 smb_time_audit_log_fname("getxattr", timediff
, path
);
1944 static ssize_t
smb_time_audit_fgetxattr(struct vfs_handle_struct
*handle
,
1945 struct files_struct
*fsp
,
1946 const char *name
, void *value
,
1950 struct timespec ts1
,ts2
;
1953 clock_gettime_mono(&ts1
);
1954 result
= SMB_VFS_NEXT_FGETXATTR(handle
, fsp
, name
, value
, size
);
1955 clock_gettime_mono(&ts2
);
1956 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1958 if (timediff
> audit_timeout
) {
1959 smb_time_audit_log_fsp("fgetxattr", timediff
, fsp
);
1965 static ssize_t
smb_time_audit_listxattr(struct vfs_handle_struct
*handle
,
1966 const char *path
, char *list
,
1970 struct timespec ts1
,ts2
;
1973 clock_gettime_mono(&ts1
);
1974 result
= SMB_VFS_NEXT_LISTXATTR(handle
, path
, list
, size
);
1975 clock_gettime_mono(&ts2
);
1976 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1978 if (timediff
> audit_timeout
) {
1979 smb_time_audit_log_fname("listxattr", timediff
, path
);
1985 static ssize_t
smb_time_audit_flistxattr(struct vfs_handle_struct
*handle
,
1986 struct files_struct
*fsp
, char *list
,
1990 struct timespec ts1
,ts2
;
1993 clock_gettime_mono(&ts1
);
1994 result
= SMB_VFS_NEXT_FLISTXATTR(handle
, fsp
, list
, size
);
1995 clock_gettime_mono(&ts2
);
1996 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1998 if (timediff
> audit_timeout
) {
1999 smb_time_audit_log_fsp("flistxattr", timediff
, fsp
);
2005 static int smb_time_audit_removexattr(struct vfs_handle_struct
*handle
,
2006 const char *path
, const char *name
)
2009 struct timespec ts1
,ts2
;
2012 clock_gettime_mono(&ts1
);
2013 result
= SMB_VFS_NEXT_REMOVEXATTR(handle
, path
, name
);
2014 clock_gettime_mono(&ts2
);
2015 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
2017 if (timediff
> audit_timeout
) {
2018 smb_time_audit_log_fname("removexattr", timediff
, path
);
2024 static int smb_time_audit_fremovexattr(struct vfs_handle_struct
*handle
,
2025 struct files_struct
*fsp
,
2029 struct timespec ts1
,ts2
;
2032 clock_gettime_mono(&ts1
);
2033 result
= SMB_VFS_NEXT_FREMOVEXATTR(handle
, fsp
, name
);
2034 clock_gettime_mono(&ts2
);
2035 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
2037 if (timediff
> audit_timeout
) {
2038 smb_time_audit_log_fsp("fremovexattr", timediff
, fsp
);
2044 static int smb_time_audit_setxattr(struct vfs_handle_struct
*handle
,
2045 const char *path
, const char *name
,
2046 const void *value
, size_t size
,
2050 struct timespec ts1
,ts2
;
2053 clock_gettime_mono(&ts1
);
2054 result
= SMB_VFS_NEXT_SETXATTR(handle
, path
, name
, value
, size
,
2056 clock_gettime_mono(&ts2
);
2057 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
2059 if (timediff
> audit_timeout
) {
2060 smb_time_audit_log_fname("setxattr", timediff
, path
);
2066 static int smb_time_audit_fsetxattr(struct vfs_handle_struct
*handle
,
2067 struct files_struct
*fsp
, const char *name
,
2068 const void *value
, size_t size
, int flags
)
2071 struct timespec ts1
,ts2
;
2074 clock_gettime_mono(&ts1
);
2075 result
= SMB_VFS_NEXT_FSETXATTR(handle
, fsp
, name
, value
, size
, flags
);
2076 clock_gettime_mono(&ts2
);
2077 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
2079 if (timediff
> audit_timeout
) {
2080 smb_time_audit_log_fsp("fsetxattr", timediff
, fsp
);
2086 static bool smb_time_audit_aio_force(struct vfs_handle_struct
*handle
,
2087 struct files_struct
*fsp
)
2090 struct timespec ts1
,ts2
;
2093 clock_gettime_mono(&ts1
);
2094 result
= SMB_VFS_NEXT_AIO_FORCE(handle
, fsp
);
2095 clock_gettime_mono(&ts2
);
2096 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
2098 if (timediff
> audit_timeout
) {
2099 smb_time_audit_log_fsp("aio_force", timediff
, fsp
);
2107 /* VFS operations */
2109 static struct vfs_fn_pointers vfs_time_audit_fns
= {
2110 .connect_fn
= smb_time_audit_connect
,
2111 .disconnect_fn
= smb_time_audit_disconnect
,
2112 .disk_free_fn
= smb_time_audit_disk_free
,
2113 .get_quota_fn
= smb_time_audit_get_quota
,
2114 .set_quota_fn
= smb_time_audit_set_quota
,
2115 .get_shadow_copy_data_fn
= smb_time_audit_get_shadow_copy_data
,
2116 .statvfs_fn
= smb_time_audit_statvfs
,
2117 .fs_capabilities_fn
= smb_time_audit_fs_capabilities
,
2118 .opendir_fn
= smb_time_audit_opendir
,
2119 .fdopendir_fn
= smb_time_audit_fdopendir
,
2120 .readdir_fn
= smb_time_audit_readdir
,
2121 .seekdir_fn
= smb_time_audit_seekdir
,
2122 .telldir_fn
= smb_time_audit_telldir
,
2123 .rewind_dir_fn
= smb_time_audit_rewinddir
,
2124 .mkdir_fn
= smb_time_audit_mkdir
,
2125 .rmdir_fn
= smb_time_audit_rmdir
,
2126 .closedir_fn
= smb_time_audit_closedir
,
2127 .init_search_op_fn
= smb_time_audit_init_search_op
,
2128 .open_fn
= smb_time_audit_open
,
2129 .create_file_fn
= smb_time_audit_create_file
,
2130 .close_fn
= smb_time_audit_close
,
2131 .read_fn
= smb_time_audit_read
,
2132 .pread_fn
= smb_time_audit_pread
,
2133 .pread_send_fn
= smb_time_audit_pread_send
,
2134 .pread_recv_fn
= smb_time_audit_pread_recv
,
2135 .write_fn
= smb_time_audit_write
,
2136 .pwrite_fn
= smb_time_audit_pwrite
,
2137 .pwrite_send_fn
= smb_time_audit_pwrite_send
,
2138 .pwrite_recv_fn
= smb_time_audit_pwrite_recv
,
2139 .lseek_fn
= smb_time_audit_lseek
,
2140 .sendfile_fn
= smb_time_audit_sendfile
,
2141 .recvfile_fn
= smb_time_audit_recvfile
,
2142 .rename_fn
= smb_time_audit_rename
,
2143 .fsync_fn
= smb_time_audit_fsync
,
2144 .fsync_send_fn
= smb_time_audit_fsync_send
,
2145 .fsync_recv_fn
= smb_time_audit_fsync_recv
,
2146 .stat_fn
= smb_time_audit_stat
,
2147 .fstat_fn
= smb_time_audit_fstat
,
2148 .lstat_fn
= smb_time_audit_lstat
,
2149 .get_alloc_size_fn
= smb_time_audit_get_alloc_size
,
2150 .unlink_fn
= smb_time_audit_unlink
,
2151 .chmod_fn
= smb_time_audit_chmod
,
2152 .fchmod_fn
= smb_time_audit_fchmod
,
2153 .chown_fn
= smb_time_audit_chown
,
2154 .fchown_fn
= smb_time_audit_fchown
,
2155 .lchown_fn
= smb_time_audit_lchown
,
2156 .chdir_fn
= smb_time_audit_chdir
,
2157 .getwd_fn
= smb_time_audit_getwd
,
2158 .ntimes_fn
= smb_time_audit_ntimes
,
2159 .ftruncate_fn
= smb_time_audit_ftruncate
,
2160 .fallocate_fn
= smb_time_audit_fallocate
,
2161 .lock_fn
= smb_time_audit_lock
,
2162 .kernel_flock_fn
= smb_time_audit_kernel_flock
,
2163 .linux_setlease_fn
= smb_time_audit_linux_setlease
,
2164 .getlock_fn
= smb_time_audit_getlock
,
2165 .symlink_fn
= smb_time_audit_symlink
,
2166 .readlink_fn
= smb_time_audit_readlink
,
2167 .link_fn
= smb_time_audit_link
,
2168 .mknod_fn
= smb_time_audit_mknod
,
2169 .realpath_fn
= smb_time_audit_realpath
,
2170 .notify_watch_fn
= smb_time_audit_notify_watch
,
2171 .chflags_fn
= smb_time_audit_chflags
,
2172 .file_id_create_fn
= smb_time_audit_file_id_create
,
2173 .streaminfo_fn
= smb_time_audit_streaminfo
,
2174 .get_real_filename_fn
= smb_time_audit_get_real_filename
,
2175 .connectpath_fn
= smb_time_audit_connectpath
,
2176 .brl_lock_windows_fn
= smb_time_audit_brl_lock_windows
,
2177 .brl_unlock_windows_fn
= smb_time_audit_brl_unlock_windows
,
2178 .brl_cancel_windows_fn
= smb_time_audit_brl_cancel_windows
,
2179 .strict_lock_fn
= smb_time_audit_strict_lock
,
2180 .strict_unlock_fn
= smb_time_audit_strict_unlock
,
2181 .translate_name_fn
= smb_time_audit_translate_name
,
2182 .fget_nt_acl_fn
= smb_time_audit_fget_nt_acl
,
2183 .get_nt_acl_fn
= smb_time_audit_get_nt_acl
,
2184 .fset_nt_acl_fn
= smb_time_audit_fset_nt_acl
,
2185 .chmod_acl_fn
= smb_time_audit_chmod_acl
,
2186 .fchmod_acl_fn
= smb_time_audit_fchmod_acl
,
2187 .sys_acl_get_file_fn
= smb_time_audit_sys_acl_get_file
,
2188 .sys_acl_get_fd_fn
= smb_time_audit_sys_acl_get_fd
,
2189 .sys_acl_blob_get_file_fn
= smb_time_audit_sys_acl_blob_get_file
,
2190 .sys_acl_blob_get_fd_fn
= smb_time_audit_sys_acl_blob_get_fd
,
2191 .sys_acl_set_file_fn
= smb_time_audit_sys_acl_set_file
,
2192 .sys_acl_set_fd_fn
= smb_time_audit_sys_acl_set_fd
,
2193 .sys_acl_delete_def_file_fn
= smb_time_audit_sys_acl_delete_def_file
,
2194 .getxattr_fn
= smb_time_audit_getxattr
,
2195 .fgetxattr_fn
= smb_time_audit_fgetxattr
,
2196 .listxattr_fn
= smb_time_audit_listxattr
,
2197 .flistxattr_fn
= smb_time_audit_flistxattr
,
2198 .removexattr_fn
= smb_time_audit_removexattr
,
2199 .fremovexattr_fn
= smb_time_audit_fremovexattr
,
2200 .setxattr_fn
= smb_time_audit_setxattr
,
2201 .fsetxattr_fn
= smb_time_audit_fsetxattr
,
2202 .aio_force_fn
= smb_time_audit_aio_force
,
2206 NTSTATUS
vfs_time_audit_init(void);
2207 NTSTATUS
vfs_time_audit_init(void)
2209 audit_timeout
= (double)lp_parm_int(-1, "time_audit", "timeout",
2211 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION
, "time_audit",
2212 &vfs_time_audit_fns
);