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_fname(const char *syscallname
, double elapsed
,
95 if (getcwd(cwd
, sizeof(cwd
)) == NULL
) {
96 snprintf(cwd
, sizeof(cwd
), "<getcwd() error %d>", errno
);
99 msg
= talloc_asprintf(talloc_tos(),
100 "cwd = \"%s\", filename = \"%s\"",
103 msg
= talloc_asprintf(talloc_tos(),
104 "cwd = \"%s\", filename = <NULL>",
107 smb_time_audit_log_msg(syscallname
, elapsed
, msg
);
111 static void smb_time_audit_log_smb_fname(const char *syscallname
, double elapsed
,
112 const struct smb_filename
*smb_fname
)
114 if (smb_fname
!= NULL
) {
115 smb_time_audit_log_fname(syscallname
, elapsed
,
116 smb_fname
->base_name
);
118 smb_time_audit_log_fname(syscallname
, elapsed
,
119 "smb_fname = <NULL>");
123 static int smb_time_audit_connect(vfs_handle_struct
*handle
,
124 const char *svc
, const char *user
)
127 struct timespec ts1
,ts2
;
134 clock_gettime_mono(&ts1
);
135 result
= SMB_VFS_NEXT_CONNECT(handle
, svc
, user
);
136 clock_gettime_mono(&ts2
);
137 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
138 if (timediff
> audit_timeout
) {
139 smb_time_audit_log_msg("connect", timediff
, user
);
144 static void smb_time_audit_disconnect(vfs_handle_struct
*handle
)
146 struct timespec ts1
,ts2
;
149 clock_gettime_mono(&ts1
);
150 SMB_VFS_NEXT_DISCONNECT(handle
);
151 clock_gettime_mono(&ts2
);
152 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
154 if (timediff
> audit_timeout
) {
155 smb_time_audit_log("disconnect", timediff
);
159 static uint64_t smb_time_audit_disk_free(vfs_handle_struct
*handle
,
161 bool small_query
, uint64_t *bsize
,
162 uint64_t *dfree
, uint64_t *dsize
)
165 struct timespec ts1
,ts2
;
168 clock_gettime_mono(&ts1
);
169 result
= SMB_VFS_NEXT_DISK_FREE(handle
, path
, small_query
, bsize
,
171 clock_gettime_mono(&ts2
);
172 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
174 /* Don't have a reasonable notion of failure here */
175 if (timediff
> audit_timeout
) {
176 smb_time_audit_log_fname("disk_free", timediff
, path
);
182 static int smb_time_audit_get_quota(struct vfs_handle_struct
*handle
,
183 enum SMB_QUOTA_TYPE qtype
, unid_t id
,
187 struct timespec ts1
,ts2
;
190 clock_gettime_mono(&ts1
);
191 result
= SMB_VFS_NEXT_GET_QUOTA(handle
, qtype
, id
, qt
);
192 clock_gettime_mono(&ts2
);
193 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
195 if (timediff
> audit_timeout
) {
196 smb_time_audit_log("get_quota", timediff
);
201 static int smb_time_audit_set_quota(struct vfs_handle_struct
*handle
,
202 enum SMB_QUOTA_TYPE qtype
, unid_t id
,
206 struct timespec ts1
,ts2
;
209 clock_gettime_mono(&ts1
);
210 result
= SMB_VFS_NEXT_SET_QUOTA(handle
, qtype
, id
, qt
);
211 clock_gettime_mono(&ts2
);
212 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
214 if (timediff
> audit_timeout
) {
215 smb_time_audit_log("set_quota", timediff
);
221 static int smb_time_audit_get_shadow_copy_data(struct vfs_handle_struct
*handle
,
222 struct files_struct
*fsp
,
223 struct shadow_copy_data
*shadow_copy_data
,
227 struct timespec ts1
,ts2
;
230 clock_gettime_mono(&ts1
);
231 result
= SMB_VFS_NEXT_GET_SHADOW_COPY_DATA(handle
, fsp
,
232 shadow_copy_data
, labels
);
233 clock_gettime_mono(&ts2
);
234 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
236 if (timediff
> audit_timeout
) {
237 smb_time_audit_log_fsp("get_shadow_copy_data", timediff
, fsp
);
243 static int smb_time_audit_statvfs(struct vfs_handle_struct
*handle
,
245 struct vfs_statvfs_struct
*statbuf
)
248 struct timespec ts1
,ts2
;
251 clock_gettime_mono(&ts1
);
252 result
= SMB_VFS_NEXT_STATVFS(handle
, path
, statbuf
);
253 clock_gettime_mono(&ts2
);
254 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
256 if (timediff
> audit_timeout
) {
257 smb_time_audit_log_fname("statvfs", timediff
, path
);
263 static uint32_t smb_time_audit_fs_capabilities(struct vfs_handle_struct
*handle
,
264 enum timestamp_set_resolution
*p_ts_res
)
267 struct timespec ts1
,ts2
;
270 clock_gettime_mono(&ts1
);
271 result
= SMB_VFS_NEXT_FS_CAPABILITIES(handle
, p_ts_res
);
272 clock_gettime_mono(&ts2
);
273 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
275 if (timediff
> audit_timeout
) {
276 smb_time_audit_log("fs_capabilities", timediff
);
282 static DIR *smb_time_audit_opendir(vfs_handle_struct
*handle
,
284 const char *mask
, uint32 attr
)
287 struct timespec ts1
,ts2
;
290 clock_gettime_mono(&ts1
);
291 result
= SMB_VFS_NEXT_OPENDIR(handle
, fname
, mask
, attr
);
292 clock_gettime_mono(&ts2
);
293 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
295 if (timediff
> audit_timeout
) {
296 smb_time_audit_log_fname("opendir", timediff
, fname
);
302 static DIR *smb_time_audit_fdopendir(vfs_handle_struct
*handle
,
304 const char *mask
, uint32 attr
)
307 struct timespec ts1
,ts2
;
310 clock_gettime_mono(&ts1
);
311 result
= SMB_VFS_NEXT_FDOPENDIR(handle
, fsp
, mask
, attr
);
312 clock_gettime_mono(&ts2
);
313 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
315 if (timediff
> audit_timeout
) {
316 smb_time_audit_log_fsp("fdopendir", timediff
, fsp
);
322 static struct dirent
*smb_time_audit_readdir(vfs_handle_struct
*handle
,
324 SMB_STRUCT_STAT
*sbuf
)
326 struct dirent
*result
;
327 struct timespec ts1
,ts2
;
330 clock_gettime_mono(&ts1
);
331 result
= SMB_VFS_NEXT_READDIR(handle
, dirp
, sbuf
);
332 clock_gettime_mono(&ts2
);
333 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
335 if (timediff
> audit_timeout
) {
336 smb_time_audit_log("readdir", timediff
);
342 static void smb_time_audit_seekdir(vfs_handle_struct
*handle
,
343 DIR *dirp
, long offset
)
345 struct timespec ts1
,ts2
;
348 clock_gettime_mono(&ts1
);
349 SMB_VFS_NEXT_SEEKDIR(handle
, dirp
, offset
);
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("seekdir", timediff
);
359 static long smb_time_audit_telldir(vfs_handle_struct
*handle
,
363 struct timespec ts1
,ts2
;
366 clock_gettime_mono(&ts1
);
367 result
= SMB_VFS_NEXT_TELLDIR(handle
, dirp
);
368 clock_gettime_mono(&ts2
);
369 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
371 if (timediff
> audit_timeout
) {
372 smb_time_audit_log("telldir", timediff
);
378 static void smb_time_audit_rewinddir(vfs_handle_struct
*handle
,
381 struct timespec ts1
,ts2
;
384 clock_gettime_mono(&ts1
);
385 SMB_VFS_NEXT_REWINDDIR(handle
, dirp
);
386 clock_gettime_mono(&ts2
);
387 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
389 if (timediff
> audit_timeout
) {
390 smb_time_audit_log("rewinddir", timediff
);
395 static int smb_time_audit_mkdir(vfs_handle_struct
*handle
,
396 const char *path
, mode_t mode
)
399 struct timespec ts1
,ts2
;
402 clock_gettime_mono(&ts1
);
403 result
= SMB_VFS_NEXT_MKDIR(handle
, path
, mode
);
404 clock_gettime_mono(&ts2
);
405 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
407 if (timediff
> audit_timeout
) {
408 smb_time_audit_log_fname("mkdir", timediff
, path
);
414 static int smb_time_audit_rmdir(vfs_handle_struct
*handle
,
418 struct timespec ts1
,ts2
;
421 clock_gettime_mono(&ts1
);
422 result
= SMB_VFS_NEXT_RMDIR(handle
, path
);
423 clock_gettime_mono(&ts2
);
424 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
426 if (timediff
> audit_timeout
) {
427 smb_time_audit_log_fname("rmdir", timediff
, path
);
433 static int smb_time_audit_closedir(vfs_handle_struct
*handle
,
437 struct timespec ts1
,ts2
;
440 clock_gettime_mono(&ts1
);
441 result
= SMB_VFS_NEXT_CLOSEDIR(handle
, dirp
);
442 clock_gettime_mono(&ts2
);
443 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
445 if (timediff
> audit_timeout
) {
446 smb_time_audit_log("closedir", timediff
);
452 static void smb_time_audit_init_search_op(vfs_handle_struct
*handle
,
455 struct timespec ts1
,ts2
;
458 clock_gettime_mono(&ts1
);
459 SMB_VFS_NEXT_INIT_SEARCH_OP(handle
, dirp
);
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("init_search_op", timediff
);
468 static int smb_time_audit_open(vfs_handle_struct
*handle
,
469 struct smb_filename
*fname
,
471 int flags
, mode_t mode
)
474 struct timespec ts1
,ts2
;
477 clock_gettime_mono(&ts1
);
478 result
= SMB_VFS_NEXT_OPEN(handle
, fname
, fsp
, flags
, mode
);
479 clock_gettime_mono(&ts2
);
480 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
482 if (timediff
> audit_timeout
) {
483 smb_time_audit_log_fsp("open", timediff
, fsp
);
489 static NTSTATUS
smb_time_audit_create_file(vfs_handle_struct
*handle
,
490 struct smb_request
*req
,
491 uint16_t root_dir_fid
,
492 struct smb_filename
*fname
,
493 uint32_t access_mask
,
494 uint32_t share_access
,
495 uint32_t create_disposition
,
496 uint32_t create_options
,
497 uint32_t file_attributes
,
498 uint32_t oplock_request
,
499 uint64_t allocation_size
,
500 uint32_t private_flags
,
501 struct security_descriptor
*sd
,
502 struct ea_list
*ea_list
,
503 files_struct
**result_fsp
,
507 struct timespec ts1
,ts2
;
510 clock_gettime_mono(&ts1
);
511 result
= SMB_VFS_NEXT_CREATE_FILE(
514 root_dir_fid
, /* root_dir_fid */
516 access_mask
, /* access_mask */
517 share_access
, /* share_access */
518 create_disposition
, /* create_disposition*/
519 create_options
, /* create_options */
520 file_attributes
, /* file_attributes */
521 oplock_request
, /* oplock_request */
522 allocation_size
, /* allocation_size */
525 ea_list
, /* ea_list */
526 result_fsp
, /* result */
528 clock_gettime_mono(&ts2
);
529 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
531 if (timediff
> audit_timeout
) {
533 * can't use result_fsp this time, may have
534 * invalid content causing smbd crash
536 smb_time_audit_log_smb_fname("create_file", timediff
,
543 static int smb_time_audit_close(vfs_handle_struct
*handle
, files_struct
*fsp
)
546 struct timespec ts1
,ts2
;
549 clock_gettime_mono(&ts1
);
550 result
= SMB_VFS_NEXT_CLOSE(handle
, fsp
);
551 clock_gettime_mono(&ts2
);
552 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
554 if (timediff
> audit_timeout
) {
555 smb_time_audit_log_fsp("close", timediff
, fsp
);
561 static ssize_t
smb_time_audit_read(vfs_handle_struct
*handle
,
562 files_struct
*fsp
, void *data
, size_t n
)
565 struct timespec ts1
,ts2
;
568 clock_gettime_mono(&ts1
);
569 result
= SMB_VFS_NEXT_READ(handle
, fsp
, data
, n
);
570 clock_gettime_mono(&ts2
);
571 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
573 if (timediff
> audit_timeout
) {
574 smb_time_audit_log_fsp("read", timediff
, fsp
);
580 static ssize_t
smb_time_audit_pread(vfs_handle_struct
*handle
,
582 void *data
, size_t n
, off_t offset
)
585 struct timespec ts1
,ts2
;
588 clock_gettime_mono(&ts1
);
589 result
= SMB_VFS_NEXT_PREAD(handle
, fsp
, data
, n
, offset
);
590 clock_gettime_mono(&ts2
);
591 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
593 if (timediff
> audit_timeout
) {
594 smb_time_audit_log_fsp("pread", timediff
, fsp
);
600 struct smb_time_audit_pread_state
{
601 struct files_struct
*fsp
;
607 static void smb_time_audit_pread_done(struct tevent_req
*subreq
);
609 static struct tevent_req
*smb_time_audit_pread_send(
610 struct vfs_handle_struct
*handle
, TALLOC_CTX
*mem_ctx
,
611 struct tevent_context
*ev
, struct files_struct
*fsp
,
612 void *data
, size_t n
, off_t offset
)
614 struct tevent_req
*req
, *subreq
;
615 struct smb_time_audit_pread_state
*state
;
617 req
= tevent_req_create(mem_ctx
, &state
,
618 struct smb_time_audit_pread_state
);
622 clock_gettime_mono(&state
->ts1
);
625 subreq
= SMB_VFS_NEXT_PREAD_SEND(state
, ev
, handle
, fsp
, data
,
627 if (tevent_req_nomem(subreq
, req
)) {
628 return tevent_req_post(req
, ev
);
630 tevent_req_set_callback(subreq
, smb_time_audit_pread_done
, req
);
634 static void smb_time_audit_pread_done(struct tevent_req
*subreq
)
636 struct tevent_req
*req
= tevent_req_callback_data(
637 subreq
, struct tevent_req
);
638 struct smb_time_audit_pread_state
*state
= tevent_req_data(
639 req
, struct smb_time_audit_pread_state
);
641 state
->ret
= SMB_VFS_PREAD_RECV(subreq
, &state
->err
);
643 tevent_req_done(req
);
646 static ssize_t
smb_time_audit_pread_recv(struct tevent_req
*req
, int *err
)
648 struct smb_time_audit_pread_state
*state
= tevent_req_data(
649 req
, struct smb_time_audit_pread_state
);
653 clock_gettime_mono(&ts2
);
654 timediff
= nsec_time_diff(&ts2
,&state
->ts1
)*1.0e-9;
656 if (timediff
> audit_timeout
) {
657 smb_time_audit_log_fsp("pread", timediff
, state
->fsp
);
660 if (tevent_req_is_unix_error(req
, err
)) {
667 static ssize_t
smb_time_audit_write(vfs_handle_struct
*handle
,
669 const void *data
, size_t n
)
672 struct timespec ts1
,ts2
;
675 clock_gettime_mono(&ts1
);
676 result
= SMB_VFS_NEXT_WRITE(handle
, fsp
, data
, n
);
677 clock_gettime_mono(&ts2
);
678 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
680 if (timediff
> audit_timeout
) {
681 smb_time_audit_log_fsp("write", timediff
, fsp
);
687 static ssize_t
smb_time_audit_pwrite(vfs_handle_struct
*handle
,
689 const void *data
, size_t n
,
693 struct timespec ts1
,ts2
;
696 clock_gettime_mono(&ts1
);
697 result
= SMB_VFS_NEXT_PWRITE(handle
, fsp
, data
, n
, offset
);
698 clock_gettime_mono(&ts2
);
699 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
701 if (timediff
> audit_timeout
) {
702 smb_time_audit_log_fsp("pwrite", timediff
, fsp
);
708 struct smb_time_audit_pwrite_state
{
709 struct files_struct
*fsp
;
715 static void smb_time_audit_pwrite_done(struct tevent_req
*subreq
);
717 static struct tevent_req
*smb_time_audit_pwrite_send(
718 struct vfs_handle_struct
*handle
, TALLOC_CTX
*mem_ctx
,
719 struct tevent_context
*ev
, struct files_struct
*fsp
,
720 const void *data
, size_t n
, off_t offset
)
722 struct tevent_req
*req
, *subreq
;
723 struct smb_time_audit_pwrite_state
*state
;
725 req
= tevent_req_create(mem_ctx
, &state
,
726 struct smb_time_audit_pwrite_state
);
730 clock_gettime_mono(&state
->ts1
);
733 subreq
= SMB_VFS_NEXT_PWRITE_SEND(state
, ev
, handle
, fsp
, data
,
735 if (tevent_req_nomem(subreq
, req
)) {
736 return tevent_req_post(req
, ev
);
738 tevent_req_set_callback(subreq
, smb_time_audit_pwrite_done
, req
);
742 static void smb_time_audit_pwrite_done(struct tevent_req
*subreq
)
744 struct tevent_req
*req
= tevent_req_callback_data(
745 subreq
, struct tevent_req
);
746 struct smb_time_audit_pwrite_state
*state
= tevent_req_data(
747 req
, struct smb_time_audit_pwrite_state
);
749 state
->ret
= SMB_VFS_PWRITE_RECV(subreq
, &state
->err
);
751 tevent_req_done(req
);
754 static ssize_t
smb_time_audit_pwrite_recv(struct tevent_req
*req
, int *err
)
756 struct smb_time_audit_pwrite_state
*state
= tevent_req_data(
757 req
, struct smb_time_audit_pwrite_state
);
761 clock_gettime_mono(&ts2
);
762 timediff
= nsec_time_diff(&ts2
,&state
->ts1
)*1.0e-9;
764 if (timediff
> audit_timeout
) {
765 smb_time_audit_log_fsp("pwrite", timediff
, state
->fsp
);
768 if (tevent_req_is_unix_error(req
, err
)) {
775 static off_t
smb_time_audit_lseek(vfs_handle_struct
*handle
,
777 off_t offset
, int whence
)
780 struct timespec ts1
,ts2
;
783 clock_gettime_mono(&ts1
);
784 result
= SMB_VFS_NEXT_LSEEK(handle
, fsp
, offset
, whence
);
785 clock_gettime_mono(&ts2
);
786 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
788 if (timediff
> audit_timeout
) {
789 smb_time_audit_log_fsp("lseek", timediff
, fsp
);
795 static ssize_t
smb_time_audit_sendfile(vfs_handle_struct
*handle
, int tofd
,
796 files_struct
*fromfsp
,
797 const DATA_BLOB
*hdr
, off_t offset
,
801 struct timespec ts1
,ts2
;
804 clock_gettime_mono(&ts1
);
805 result
= SMB_VFS_NEXT_SENDFILE(handle
, tofd
, fromfsp
, hdr
, offset
, n
);
806 clock_gettime_mono(&ts2
);
807 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
809 if (timediff
> audit_timeout
) {
810 smb_time_audit_log_fsp("sendfile", timediff
, fromfsp
);
816 static ssize_t
smb_time_audit_recvfile(vfs_handle_struct
*handle
, int fromfd
,
822 struct timespec ts1
,ts2
;
825 clock_gettime_mono(&ts1
);
826 result
= SMB_VFS_NEXT_RECVFILE(handle
, fromfd
, tofsp
, offset
, n
);
827 clock_gettime_mono(&ts2
);
828 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
830 if (timediff
> audit_timeout
) {
831 smb_time_audit_log_fsp("recvfile", timediff
, tofsp
);
837 static int smb_time_audit_rename(vfs_handle_struct
*handle
,
838 const struct smb_filename
*oldname
,
839 const struct smb_filename
*newname
)
842 struct timespec ts1
,ts2
;
845 clock_gettime_mono(&ts1
);
846 result
= SMB_VFS_NEXT_RENAME(handle
, oldname
, newname
);
847 clock_gettime_mono(&ts2
);
848 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
850 if (timediff
> audit_timeout
) {
851 smb_time_audit_log_smb_fname("rename", timediff
, newname
);
857 static int smb_time_audit_fsync(vfs_handle_struct
*handle
, files_struct
*fsp
)
860 struct timespec ts1
,ts2
;
863 clock_gettime_mono(&ts1
);
864 result
= SMB_VFS_NEXT_FSYNC(handle
, fsp
);
865 clock_gettime_mono(&ts2
);
866 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
868 if (timediff
> audit_timeout
) {
869 smb_time_audit_log_fsp("fsync", timediff
, fsp
);
875 struct smb_time_audit_fsync_state
{
876 struct files_struct
*fsp
;
882 static void smb_time_audit_fsync_done(struct tevent_req
*subreq
);
884 static struct tevent_req
*smb_time_audit_fsync_send(
885 struct vfs_handle_struct
*handle
, TALLOC_CTX
*mem_ctx
,
886 struct tevent_context
*ev
, struct files_struct
*fsp
)
888 struct tevent_req
*req
, *subreq
;
889 struct smb_time_audit_fsync_state
*state
;
891 req
= tevent_req_create(mem_ctx
, &state
,
892 struct smb_time_audit_fsync_state
);
896 clock_gettime_mono(&state
->ts1
);
899 subreq
= SMB_VFS_NEXT_FSYNC_SEND(state
, ev
, handle
, fsp
);
900 if (tevent_req_nomem(subreq
, req
)) {
901 return tevent_req_post(req
, ev
);
903 tevent_req_set_callback(subreq
, smb_time_audit_fsync_done
, req
);
907 static void smb_time_audit_fsync_done(struct tevent_req
*subreq
)
909 struct tevent_req
*req
= tevent_req_callback_data(
910 subreq
, struct tevent_req
);
911 struct smb_time_audit_fsync_state
*state
= tevent_req_data(
912 req
, struct smb_time_audit_fsync_state
);
914 state
->ret
= SMB_VFS_FSYNC_RECV(subreq
, &state
->err
);
916 tevent_req_done(req
);
919 static int smb_time_audit_fsync_recv(struct tevent_req
*req
, int *err
)
921 struct smb_time_audit_fsync_state
*state
= tevent_req_data(
922 req
, struct smb_time_audit_fsync_state
);
926 clock_gettime_mono(&ts2
);
927 timediff
= nsec_time_diff(&ts2
,&state
->ts1
)*1.0e-9;
929 if (timediff
> audit_timeout
) {
930 smb_time_audit_log_fsp("fsync", timediff
, state
->fsp
);
933 if (tevent_req_is_unix_error(req
, err
)) {
940 static int smb_time_audit_stat(vfs_handle_struct
*handle
,
941 struct smb_filename
*fname
)
944 struct timespec ts1
,ts2
;
947 clock_gettime_mono(&ts1
);
948 result
= SMB_VFS_NEXT_STAT(handle
, fname
);
949 clock_gettime_mono(&ts2
);
950 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
952 if (timediff
> audit_timeout
) {
953 smb_time_audit_log_smb_fname("stat", timediff
, fname
);
959 static int smb_time_audit_fstat(vfs_handle_struct
*handle
, files_struct
*fsp
,
960 SMB_STRUCT_STAT
*sbuf
)
963 struct timespec ts1
,ts2
;
966 clock_gettime_mono(&ts1
);
967 result
= SMB_VFS_NEXT_FSTAT(handle
, fsp
, sbuf
);
968 clock_gettime_mono(&ts2
);
969 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
971 if (timediff
> audit_timeout
) {
972 smb_time_audit_log_fsp("fstat", timediff
, fsp
);
978 static int smb_time_audit_lstat(vfs_handle_struct
*handle
,
979 struct smb_filename
*path
)
982 struct timespec ts1
,ts2
;
985 clock_gettime_mono(&ts1
);
986 result
= SMB_VFS_NEXT_LSTAT(handle
, path
);
987 clock_gettime_mono(&ts2
);
988 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
990 if (timediff
> audit_timeout
) {
991 smb_time_audit_log_smb_fname("lstat", timediff
, path
);
997 static uint64_t smb_time_audit_get_alloc_size(vfs_handle_struct
*handle
,
999 const SMB_STRUCT_STAT
*sbuf
)
1002 struct timespec ts1
,ts2
;
1005 clock_gettime_mono(&ts1
);
1006 result
= SMB_VFS_NEXT_GET_ALLOC_SIZE(handle
, fsp
, sbuf
);
1007 clock_gettime_mono(&ts2
);
1008 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1010 if (timediff
> audit_timeout
) {
1011 smb_time_audit_log_fsp("get_alloc_size", timediff
, fsp
);
1017 static int smb_time_audit_unlink(vfs_handle_struct
*handle
,
1018 const struct smb_filename
*path
)
1021 struct timespec ts1
,ts2
;
1024 clock_gettime_mono(&ts1
);
1025 result
= SMB_VFS_NEXT_UNLINK(handle
, path
);
1026 clock_gettime_mono(&ts2
);
1027 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1029 if (timediff
> audit_timeout
) {
1030 smb_time_audit_log_smb_fname("unlink", timediff
, path
);
1036 static int smb_time_audit_chmod(vfs_handle_struct
*handle
,
1037 const char *path
, mode_t mode
)
1040 struct timespec ts1
,ts2
;
1043 clock_gettime_mono(&ts1
);
1044 result
= SMB_VFS_NEXT_CHMOD(handle
, path
, mode
);
1045 clock_gettime_mono(&ts2
);
1046 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1048 if (timediff
> audit_timeout
) {
1049 smb_time_audit_log_fname("chmod", timediff
, path
);
1055 static int smb_time_audit_fchmod(vfs_handle_struct
*handle
, files_struct
*fsp
,
1059 struct timespec ts1
,ts2
;
1062 clock_gettime_mono(&ts1
);
1063 result
= SMB_VFS_NEXT_FCHMOD(handle
, fsp
, mode
);
1064 clock_gettime_mono(&ts2
);
1065 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1067 if (timediff
> audit_timeout
) {
1068 smb_time_audit_log_fsp("fchmod", timediff
, fsp
);
1074 static int smb_time_audit_chown(vfs_handle_struct
*handle
,
1075 const char *path
, uid_t uid
, gid_t gid
)
1078 struct timespec ts1
,ts2
;
1081 clock_gettime_mono(&ts1
);
1082 result
= SMB_VFS_NEXT_CHOWN(handle
, path
, uid
, gid
);
1083 clock_gettime_mono(&ts2
);
1084 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1086 if (timediff
> audit_timeout
) {
1087 smb_time_audit_log_fname("chown", timediff
, path
);
1093 static int smb_time_audit_fchown(vfs_handle_struct
*handle
, files_struct
*fsp
,
1094 uid_t uid
, gid_t gid
)
1097 struct timespec ts1
,ts2
;
1100 clock_gettime_mono(&ts1
);
1101 result
= SMB_VFS_NEXT_FCHOWN(handle
, fsp
, uid
, gid
);
1102 clock_gettime_mono(&ts2
);
1103 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1105 if (timediff
> audit_timeout
) {
1106 smb_time_audit_log_fsp("fchown", timediff
, fsp
);
1112 static int smb_time_audit_lchown(vfs_handle_struct
*handle
,
1113 const char *path
, uid_t uid
, gid_t gid
)
1116 struct timespec ts1
,ts2
;
1119 clock_gettime_mono(&ts1
);
1120 result
= SMB_VFS_NEXT_LCHOWN(handle
, path
, uid
, gid
);
1121 clock_gettime_mono(&ts2
);
1122 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1124 if (timediff
> audit_timeout
) {
1125 smb_time_audit_log_fname("lchown", timediff
, path
);
1131 static int smb_time_audit_chdir(vfs_handle_struct
*handle
, const char *path
)
1134 struct timespec ts1
,ts2
;
1137 clock_gettime_mono(&ts1
);
1138 result
= SMB_VFS_NEXT_CHDIR(handle
, path
);
1139 clock_gettime_mono(&ts2
);
1140 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1142 if (timediff
> audit_timeout
) {
1143 smb_time_audit_log_fname("chdir", timediff
, path
);
1149 static char *smb_time_audit_getwd(vfs_handle_struct
*handle
)
1152 struct timespec ts1
,ts2
;
1155 clock_gettime_mono(&ts1
);
1156 result
= SMB_VFS_NEXT_GETWD(handle
);
1157 clock_gettime_mono(&ts2
);
1158 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1160 if (timediff
> audit_timeout
) {
1161 smb_time_audit_log("getwd", timediff
);
1167 static int smb_time_audit_ntimes(vfs_handle_struct
*handle
,
1168 const struct smb_filename
*path
,
1169 struct smb_file_time
*ft
)
1172 struct timespec ts1
,ts2
;
1175 clock_gettime_mono(&ts1
);
1176 result
= SMB_VFS_NEXT_NTIMES(handle
, path
, ft
);
1177 clock_gettime_mono(&ts2
);
1178 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1180 if (timediff
> audit_timeout
) {
1181 smb_time_audit_log_smb_fname("ntimes", timediff
, path
);
1187 static int smb_time_audit_ftruncate(vfs_handle_struct
*handle
,
1192 struct timespec ts1
,ts2
;
1195 clock_gettime_mono(&ts1
);
1196 result
= SMB_VFS_NEXT_FTRUNCATE(handle
, fsp
, len
);
1197 clock_gettime_mono(&ts2
);
1198 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1200 if (timediff
> audit_timeout
) {
1201 smb_time_audit_log_fsp("ftruncate", timediff
, fsp
);
1207 static int smb_time_audit_fallocate(vfs_handle_struct
*handle
,
1209 enum vfs_fallocate_mode mode
,
1214 int saved_errno
= 0;
1215 struct timespec ts1
,ts2
;
1218 clock_gettime_mono(&ts1
);
1219 result
= SMB_VFS_NEXT_FALLOCATE(handle
, fsp
, mode
, offset
, len
);
1221 saved_errno
= errno
;
1223 clock_gettime_mono(&ts2
);
1224 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1226 if (timediff
> audit_timeout
) {
1227 smb_time_audit_log_fsp("fallocate", timediff
, fsp
);
1230 errno
= saved_errno
;
1235 static bool smb_time_audit_lock(vfs_handle_struct
*handle
, files_struct
*fsp
,
1236 int op
, off_t offset
, off_t count
,
1240 struct timespec ts1
,ts2
;
1243 clock_gettime_mono(&ts1
);
1244 result
= SMB_VFS_NEXT_LOCK(handle
, fsp
, op
, offset
, count
, type
);
1245 clock_gettime_mono(&ts2
);
1246 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1248 if (timediff
> audit_timeout
) {
1249 smb_time_audit_log_fsp("lock", timediff
, fsp
);
1255 static int smb_time_audit_kernel_flock(struct vfs_handle_struct
*handle
,
1256 struct files_struct
*fsp
,
1257 uint32 share_mode
, uint32 access_mask
)
1260 struct timespec ts1
,ts2
;
1263 clock_gettime_mono(&ts1
);
1264 result
= SMB_VFS_NEXT_KERNEL_FLOCK(handle
, fsp
, share_mode
,
1266 clock_gettime_mono(&ts2
);
1267 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1269 if (timediff
> audit_timeout
) {
1270 smb_time_audit_log_fsp("kernel_flock", timediff
, fsp
);
1276 static int smb_time_audit_linux_setlease(vfs_handle_struct
*handle
,
1281 struct timespec ts1
,ts2
;
1284 clock_gettime_mono(&ts1
);
1285 result
= SMB_VFS_NEXT_LINUX_SETLEASE(handle
, fsp
, leasetype
);
1286 clock_gettime_mono(&ts2
);
1287 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1289 if (timediff
> audit_timeout
) {
1290 smb_time_audit_log_fsp("linux_setlease", timediff
, fsp
);
1296 static bool smb_time_audit_getlock(vfs_handle_struct
*handle
,
1298 off_t
*poffset
, off_t
*pcount
,
1299 int *ptype
, pid_t
*ppid
)
1302 struct timespec ts1
,ts2
;
1305 clock_gettime_mono(&ts1
);
1306 result
= SMB_VFS_NEXT_GETLOCK(handle
, fsp
, poffset
, pcount
, ptype
,
1308 clock_gettime_mono(&ts2
);
1309 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1311 if (timediff
> audit_timeout
) {
1312 smb_time_audit_log_fsp("getlock", timediff
, fsp
);
1318 static int smb_time_audit_symlink(vfs_handle_struct
*handle
,
1319 const char *oldpath
, const char *newpath
)
1322 struct timespec ts1
,ts2
;
1325 clock_gettime_mono(&ts1
);
1326 result
= SMB_VFS_NEXT_SYMLINK(handle
, oldpath
, newpath
);
1327 clock_gettime_mono(&ts2
);
1328 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1330 if (timediff
> audit_timeout
) {
1331 smb_time_audit_log_fname("symlink", timediff
, newpath
);
1337 static int smb_time_audit_readlink(vfs_handle_struct
*handle
,
1338 const char *path
, char *buf
, size_t bufsiz
)
1341 struct timespec ts1
,ts2
;
1344 clock_gettime_mono(&ts1
);
1345 result
= SMB_VFS_NEXT_READLINK(handle
, path
, buf
, bufsiz
);
1346 clock_gettime_mono(&ts2
);
1347 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1349 if (timediff
> audit_timeout
) {
1350 smb_time_audit_log_fname("readlink", timediff
, path
);
1356 static int smb_time_audit_link(vfs_handle_struct
*handle
,
1357 const char *oldpath
, const char *newpath
)
1360 struct timespec ts1
,ts2
;
1363 clock_gettime_mono(&ts1
);
1364 result
= SMB_VFS_NEXT_LINK(handle
, oldpath
, newpath
);
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_fname("link", timediff
, newpath
);
1375 static int smb_time_audit_mknod(vfs_handle_struct
*handle
,
1376 const char *pathname
, mode_t mode
,
1380 struct timespec ts1
,ts2
;
1383 clock_gettime_mono(&ts1
);
1384 result
= SMB_VFS_NEXT_MKNOD(handle
, pathname
, mode
, dev
);
1385 clock_gettime_mono(&ts2
);
1386 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1388 if (timediff
> audit_timeout
) {
1389 smb_time_audit_log_fname("mknod", timediff
, pathname
);
1395 static char *smb_time_audit_realpath(vfs_handle_struct
*handle
,
1399 struct timespec ts1
,ts2
;
1402 clock_gettime_mono(&ts1
);
1403 result
= SMB_VFS_NEXT_REALPATH(handle
, path
);
1404 clock_gettime_mono(&ts2
);
1405 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1407 if (timediff
> audit_timeout
) {
1408 smb_time_audit_log_fname("realpath", timediff
, path
);
1414 static NTSTATUS
smb_time_audit_notify_watch(struct vfs_handle_struct
*handle
,
1415 struct sys_notify_context
*ctx
,
1418 uint32_t *subdir_filter
,
1419 void (*callback
)(struct sys_notify_context
*ctx
,
1421 struct notify_event
*ev
),
1422 void *private_data
, void *handle_p
)
1425 struct timespec ts1
,ts2
;
1428 clock_gettime_mono(&ts1
);
1429 result
= SMB_VFS_NEXT_NOTIFY_WATCH(handle
, ctx
, path
,
1430 filter
, subdir_filter
, callback
,
1431 private_data
, handle_p
);
1432 clock_gettime_mono(&ts2
);
1433 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1435 if (timediff
> audit_timeout
) {
1436 smb_time_audit_log_fname("notify_watch", timediff
, path
);
1442 static int smb_time_audit_chflags(vfs_handle_struct
*handle
,
1443 const char *path
, unsigned int flags
)
1446 struct timespec ts1
,ts2
;
1449 clock_gettime_mono(&ts1
);
1450 result
= SMB_VFS_NEXT_CHFLAGS(handle
, path
, flags
);
1451 clock_gettime_mono(&ts2
);
1452 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1454 if (timediff
> audit_timeout
) {
1455 smb_time_audit_log_fname("chflags", timediff
, path
);
1461 static struct file_id
smb_time_audit_file_id_create(struct vfs_handle_struct
*handle
,
1462 const SMB_STRUCT_STAT
*sbuf
)
1464 struct file_id id_zero
;
1465 struct file_id result
;
1466 struct timespec ts1
,ts2
;
1469 ZERO_STRUCT(id_zero
);
1471 clock_gettime_mono(&ts1
);
1472 result
= SMB_VFS_NEXT_FILE_ID_CREATE(handle
, sbuf
);
1473 clock_gettime_mono(&ts2
);
1474 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1476 if (timediff
> audit_timeout
) {
1477 smb_time_audit_log("file_id_create", timediff
);
1483 static NTSTATUS
smb_time_audit_streaminfo(vfs_handle_struct
*handle
,
1484 struct files_struct
*fsp
,
1486 TALLOC_CTX
*mem_ctx
,
1487 unsigned int *pnum_streams
,
1488 struct stream_struct
**pstreams
)
1491 struct timespec ts1
,ts2
;
1494 clock_gettime_mono(&ts1
);
1495 result
= SMB_VFS_NEXT_STREAMINFO(handle
, fsp
, fname
, mem_ctx
,
1496 pnum_streams
, pstreams
);
1497 clock_gettime_mono(&ts2
);
1498 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1500 if (timediff
> audit_timeout
) {
1501 smb_time_audit_log_fsp("streaminfo", timediff
, fsp
);
1507 static int smb_time_audit_get_real_filename(struct vfs_handle_struct
*handle
,
1510 TALLOC_CTX
*mem_ctx
,
1514 struct timespec ts1
,ts2
;
1517 clock_gettime_mono(&ts1
);
1518 result
= SMB_VFS_NEXT_GET_REAL_FILENAME(handle
, path
, name
, mem_ctx
,
1520 clock_gettime_mono(&ts2
);
1521 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1523 if (timediff
> audit_timeout
) {
1524 smb_time_audit_log_fname("get_real_filename", timediff
, path
);
1530 static const char *smb_time_audit_connectpath(vfs_handle_struct
*handle
,
1534 struct timespec ts1
,ts2
;
1537 clock_gettime_mono(&ts1
);
1538 result
= SMB_VFS_NEXT_CONNECTPATH(handle
, fname
);
1539 clock_gettime_mono(&ts2
);
1540 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1542 if (timediff
> audit_timeout
) {
1543 smb_time_audit_log_fname("connectpath", timediff
, fname
);
1549 static NTSTATUS
smb_time_audit_brl_lock_windows(struct vfs_handle_struct
*handle
,
1550 struct byte_range_lock
*br_lck
,
1551 struct lock_struct
*plock
,
1553 struct blocking_lock_record
*blr
)
1556 struct timespec ts1
,ts2
;
1559 clock_gettime_mono(&ts1
);
1560 result
= SMB_VFS_NEXT_BRL_LOCK_WINDOWS(handle
, br_lck
, plock
,
1561 blocking_lock
, blr
);
1562 clock_gettime_mono(&ts2
);
1563 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1565 if (timediff
> audit_timeout
) {
1566 smb_time_audit_log_fsp("brl_lock_windows", timediff
,
1573 static bool smb_time_audit_brl_unlock_windows(struct vfs_handle_struct
*handle
,
1574 struct messaging_context
*msg_ctx
,
1575 struct byte_range_lock
*br_lck
,
1576 const struct lock_struct
*plock
)
1579 struct timespec ts1
,ts2
;
1582 clock_gettime_mono(&ts1
);
1583 result
= SMB_VFS_NEXT_BRL_UNLOCK_WINDOWS(handle
, msg_ctx
, br_lck
,
1585 clock_gettime_mono(&ts2
);
1586 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1588 if (timediff
> audit_timeout
) {
1589 smb_time_audit_log_fsp("brl_unlock_windows", timediff
,
1596 static bool smb_time_audit_brl_cancel_windows(struct vfs_handle_struct
*handle
,
1597 struct byte_range_lock
*br_lck
,
1598 struct lock_struct
*plock
,
1599 struct blocking_lock_record
*blr
)
1602 struct timespec ts1
,ts2
;
1605 clock_gettime_mono(&ts1
);
1606 result
= SMB_VFS_NEXT_BRL_CANCEL_WINDOWS(handle
, br_lck
, plock
, blr
);
1607 clock_gettime_mono(&ts2
);
1608 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1610 if (timediff
> audit_timeout
) {
1611 smb_time_audit_log_fsp("brl_cancel_windows", timediff
,
1618 static bool smb_time_audit_strict_lock(struct vfs_handle_struct
*handle
,
1619 struct files_struct
*fsp
,
1620 struct lock_struct
*plock
)
1623 struct timespec ts1
,ts2
;
1626 clock_gettime_mono(&ts1
);
1627 result
= SMB_VFS_NEXT_STRICT_LOCK(handle
, fsp
, plock
);
1628 clock_gettime_mono(&ts2
);
1629 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1631 if (timediff
> audit_timeout
) {
1632 smb_time_audit_log_fsp("strict_lock", timediff
, fsp
);
1638 static void smb_time_audit_strict_unlock(struct vfs_handle_struct
*handle
,
1639 struct files_struct
*fsp
,
1640 struct lock_struct
*plock
)
1642 struct timespec ts1
,ts2
;
1645 clock_gettime_mono(&ts1
);
1646 SMB_VFS_NEXT_STRICT_UNLOCK(handle
, fsp
, plock
);
1647 clock_gettime_mono(&ts2
);
1648 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1650 if (timediff
> audit_timeout
) {
1651 smb_time_audit_log_fsp("strict_unlock", timediff
, fsp
);
1655 static NTSTATUS
smb_time_audit_translate_name(struct vfs_handle_struct
*handle
,
1657 enum vfs_translate_direction direction
,
1658 TALLOC_CTX
*mem_ctx
,
1662 struct timespec ts1
,ts2
;
1665 clock_gettime_mono(&ts1
);
1666 result
= SMB_VFS_NEXT_TRANSLATE_NAME(handle
, name
, direction
, mem_ctx
,
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_fname("translate_name", timediff
, name
);
1678 struct time_audit_cc_state
{
1679 struct timespec ts_send
;
1680 struct vfs_handle_struct
*handle
;
1683 static void smb_time_audit_copy_chunk_done(struct tevent_req
*subreq
);
1685 static struct tevent_req
*smb_time_audit_copy_chunk_send(struct vfs_handle_struct
*handle
,
1686 TALLOC_CTX
*mem_ctx
,
1687 struct tevent_context
*ev
,
1688 struct files_struct
*src_fsp
,
1690 struct files_struct
*dest_fsp
,
1694 struct tevent_req
*req
;
1695 struct tevent_req
*subreq
;
1696 struct time_audit_cc_state
*cc_state
;
1698 req
= tevent_req_create(mem_ctx
, &cc_state
, struct time_audit_cc_state
);
1703 cc_state
->handle
= handle
;
1704 clock_gettime_mono(&cc_state
->ts_send
);
1705 subreq
= SMB_VFS_NEXT_COPY_CHUNK_SEND(handle
, cc_state
, ev
,
1707 dest_fsp
, dest_off
, num
);
1708 if (tevent_req_nomem(subreq
, req
)) {
1709 return tevent_req_post(req
, ev
);
1712 tevent_req_set_callback(subreq
, smb_time_audit_copy_chunk_done
, req
);
1716 static void smb_time_audit_copy_chunk_done(struct tevent_req
*subreq
)
1718 struct tevent_req
*req
= tevent_req_callback_data(
1719 subreq
, struct tevent_req
);
1720 struct time_audit_cc_state
*cc_state
1721 = tevent_req_data(req
, struct time_audit_cc_state
);
1724 status
= SMB_VFS_NEXT_COPY_CHUNK_RECV(cc_state
->handle
,
1727 TALLOC_FREE(subreq
);
1728 if (tevent_req_nterror(req
, status
)) {
1731 tevent_req_done(req
);
1734 static NTSTATUS
smb_time_audit_copy_chunk_recv(struct vfs_handle_struct
*handle
,
1735 struct tevent_req
*req
,
1738 struct time_audit_cc_state
*cc_state
1739 = tevent_req_data(req
, struct time_audit_cc_state
);
1740 struct timespec ts_recv
;
1744 clock_gettime_mono(&ts_recv
);
1745 timediff
= nsec_time_diff(&ts_recv
, &cc_state
->ts_send
)*1.0e-9;
1746 if (timediff
> audit_timeout
) {
1747 smb_time_audit_log("copy_chunk", timediff
);
1750 *copied
= cc_state
->copied
;
1751 if (tevent_req_is_nterror(req
, &status
)) {
1752 tevent_req_received(req
);
1756 tevent_req_received(req
);
1757 return NT_STATUS_OK
;
1760 static NTSTATUS
smb_time_audit_fget_nt_acl(vfs_handle_struct
*handle
,
1762 uint32 security_info
,
1763 TALLOC_CTX
*mem_ctx
,
1764 struct security_descriptor
**ppdesc
)
1767 struct timespec ts1
,ts2
;
1770 clock_gettime_mono(&ts1
);
1771 result
= SMB_VFS_NEXT_FGET_NT_ACL(handle
, fsp
, security_info
,
1773 clock_gettime_mono(&ts2
);
1774 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1776 if (timediff
> audit_timeout
) {
1777 smb_time_audit_log_fsp("fget_nt_acl", timediff
, fsp
);
1783 static NTSTATUS
smb_time_audit_get_nt_acl(vfs_handle_struct
*handle
,
1785 uint32 security_info
,
1786 TALLOC_CTX
*mem_ctx
,
1787 struct security_descriptor
**ppdesc
)
1790 struct timespec ts1
,ts2
;
1793 clock_gettime_mono(&ts1
);
1794 result
= SMB_VFS_NEXT_GET_NT_ACL(handle
, name
, security_info
,
1796 clock_gettime_mono(&ts2
);
1797 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1799 if (timediff
> audit_timeout
) {
1800 smb_time_audit_log_fname("get_nt_acl", timediff
, name
);
1806 static NTSTATUS
smb_time_audit_fset_nt_acl(vfs_handle_struct
*handle
,
1808 uint32 security_info_sent
,
1809 const struct security_descriptor
*psd
)
1812 struct timespec ts1
,ts2
;
1815 clock_gettime_mono(&ts1
);
1816 result
= SMB_VFS_NEXT_FSET_NT_ACL(handle
, fsp
, security_info_sent
,
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("fset_nt_acl", timediff
, fsp
);
1828 static int smb_time_audit_chmod_acl(vfs_handle_struct
*handle
,
1829 const char *path
, mode_t mode
)
1832 struct timespec ts1
,ts2
;
1835 clock_gettime_mono(&ts1
);
1836 result
= SMB_VFS_NEXT_CHMOD_ACL(handle
, path
, mode
);
1837 clock_gettime_mono(&ts2
);
1838 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1840 if (timediff
> audit_timeout
) {
1841 smb_time_audit_log_fname("chmod_acl", timediff
, path
);
1847 static int smb_time_audit_fchmod_acl(vfs_handle_struct
*handle
,
1848 files_struct
*fsp
, mode_t mode
)
1851 struct timespec ts1
,ts2
;
1854 clock_gettime_mono(&ts1
);
1855 result
= SMB_VFS_NEXT_FCHMOD_ACL(handle
, fsp
, mode
);
1856 clock_gettime_mono(&ts2
);
1857 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1859 if (timediff
> audit_timeout
) {
1860 smb_time_audit_log_fsp("fchmod_acl", timediff
, fsp
);
1866 static SMB_ACL_T
smb_time_audit_sys_acl_get_file(vfs_handle_struct
*handle
,
1868 SMB_ACL_TYPE_T type
,
1869 TALLOC_CTX
*mem_ctx
)
1872 struct timespec ts1
,ts2
;
1875 clock_gettime_mono(&ts1
);
1876 result
= SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle
, path_p
, type
, mem_ctx
);
1877 clock_gettime_mono(&ts2
);
1878 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1880 if (timediff
> audit_timeout
) {
1881 smb_time_audit_log_fname("sys_acl_get_file", timediff
, path_p
);
1887 static SMB_ACL_T
smb_time_audit_sys_acl_get_fd(vfs_handle_struct
*handle
,
1889 TALLOC_CTX
*mem_ctx
)
1892 struct timespec ts1
,ts2
;
1895 clock_gettime_mono(&ts1
);
1896 result
= SMB_VFS_NEXT_SYS_ACL_GET_FD(handle
, fsp
, mem_ctx
);
1897 clock_gettime_mono(&ts2
);
1898 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1900 if (timediff
> audit_timeout
) {
1901 smb_time_audit_log_fsp("sys_acl_get_fd", timediff
, fsp
);
1908 static int smb_time_audit_sys_acl_blob_get_file(vfs_handle_struct
*handle
,
1910 TALLOC_CTX
*mem_ctx
,
1911 char **blob_description
,
1915 struct timespec ts1
,ts2
;
1918 clock_gettime_mono(&ts1
);
1919 result
= SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FILE(handle
, path_p
, mem_ctx
, blob_description
, blob
);
1920 clock_gettime_mono(&ts2
);
1921 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1923 if (timediff
> audit_timeout
) {
1924 smb_time_audit_log("sys_acl_blob_get_file", timediff
);
1930 static int smb_time_audit_sys_acl_blob_get_fd(vfs_handle_struct
*handle
,
1932 TALLOC_CTX
*mem_ctx
,
1933 char **blob_description
,
1937 struct timespec ts1
,ts2
;
1940 clock_gettime_mono(&ts1
);
1941 result
= SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle
, fsp
, mem_ctx
, blob_description
, blob
);
1942 clock_gettime_mono(&ts2
);
1943 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1945 if (timediff
> audit_timeout
) {
1946 smb_time_audit_log("sys_acl_blob_get_fd", timediff
);
1952 static int smb_time_audit_sys_acl_set_file(vfs_handle_struct
*handle
,
1954 SMB_ACL_TYPE_T acltype
,
1958 struct timespec ts1
,ts2
;
1961 clock_gettime_mono(&ts1
);
1962 result
= SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle
, name
, acltype
,
1964 clock_gettime_mono(&ts2
);
1965 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1967 if (timediff
> audit_timeout
) {
1968 smb_time_audit_log_fname("sys_acl_set_file", timediff
, name
);
1974 static int smb_time_audit_sys_acl_set_fd(vfs_handle_struct
*handle
,
1979 struct timespec ts1
,ts2
;
1982 clock_gettime_mono(&ts1
);
1983 result
= SMB_VFS_NEXT_SYS_ACL_SET_FD(handle
, fsp
, theacl
);
1984 clock_gettime_mono(&ts2
);
1985 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
1987 if (timediff
> audit_timeout
) {
1988 smb_time_audit_log_fsp("sys_acl_set_fd", timediff
, fsp
);
1994 static int smb_time_audit_sys_acl_delete_def_file(vfs_handle_struct
*handle
,
1998 struct timespec ts1
,ts2
;
2001 clock_gettime_mono(&ts1
);
2002 result
= SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle
, path
);
2003 clock_gettime_mono(&ts2
);
2004 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
2006 if (timediff
> audit_timeout
) {
2007 smb_time_audit_log_fname("sys_acl_delete_def_file", timediff
, path
);
2013 static ssize_t
smb_time_audit_getxattr(struct vfs_handle_struct
*handle
,
2014 const char *path
, const char *name
,
2015 void *value
, size_t size
)
2018 struct timespec ts1
,ts2
;
2021 clock_gettime_mono(&ts1
);
2022 result
= SMB_VFS_NEXT_GETXATTR(handle
, path
, name
, value
, size
);
2023 clock_gettime_mono(&ts2
);
2024 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
2026 if (timediff
> audit_timeout
) {
2027 smb_time_audit_log_fname("getxattr", timediff
, path
);
2033 static ssize_t
smb_time_audit_fgetxattr(struct vfs_handle_struct
*handle
,
2034 struct files_struct
*fsp
,
2035 const char *name
, void *value
,
2039 struct timespec ts1
,ts2
;
2042 clock_gettime_mono(&ts1
);
2043 result
= SMB_VFS_NEXT_FGETXATTR(handle
, fsp
, name
, value
, size
);
2044 clock_gettime_mono(&ts2
);
2045 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
2047 if (timediff
> audit_timeout
) {
2048 smb_time_audit_log_fsp("fgetxattr", timediff
, fsp
);
2054 static ssize_t
smb_time_audit_listxattr(struct vfs_handle_struct
*handle
,
2055 const char *path
, char *list
,
2059 struct timespec ts1
,ts2
;
2062 clock_gettime_mono(&ts1
);
2063 result
= SMB_VFS_NEXT_LISTXATTR(handle
, path
, list
, size
);
2064 clock_gettime_mono(&ts2
);
2065 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
2067 if (timediff
> audit_timeout
) {
2068 smb_time_audit_log_fname("listxattr", timediff
, path
);
2074 static ssize_t
smb_time_audit_flistxattr(struct vfs_handle_struct
*handle
,
2075 struct files_struct
*fsp
, char *list
,
2079 struct timespec ts1
,ts2
;
2082 clock_gettime_mono(&ts1
);
2083 result
= SMB_VFS_NEXT_FLISTXATTR(handle
, fsp
, list
, size
);
2084 clock_gettime_mono(&ts2
);
2085 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
2087 if (timediff
> audit_timeout
) {
2088 smb_time_audit_log_fsp("flistxattr", timediff
, fsp
);
2094 static int smb_time_audit_removexattr(struct vfs_handle_struct
*handle
,
2095 const char *path
, const char *name
)
2098 struct timespec ts1
,ts2
;
2101 clock_gettime_mono(&ts1
);
2102 result
= SMB_VFS_NEXT_REMOVEXATTR(handle
, path
, name
);
2103 clock_gettime_mono(&ts2
);
2104 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
2106 if (timediff
> audit_timeout
) {
2107 smb_time_audit_log_fname("removexattr", timediff
, path
);
2113 static int smb_time_audit_fremovexattr(struct vfs_handle_struct
*handle
,
2114 struct files_struct
*fsp
,
2118 struct timespec ts1
,ts2
;
2121 clock_gettime_mono(&ts1
);
2122 result
= SMB_VFS_NEXT_FREMOVEXATTR(handle
, fsp
, name
);
2123 clock_gettime_mono(&ts2
);
2124 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
2126 if (timediff
> audit_timeout
) {
2127 smb_time_audit_log_fsp("fremovexattr", timediff
, fsp
);
2133 static int smb_time_audit_setxattr(struct vfs_handle_struct
*handle
,
2134 const char *path
, const char *name
,
2135 const void *value
, size_t size
,
2139 struct timespec ts1
,ts2
;
2142 clock_gettime_mono(&ts1
);
2143 result
= SMB_VFS_NEXT_SETXATTR(handle
, path
, name
, value
, size
,
2145 clock_gettime_mono(&ts2
);
2146 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
2148 if (timediff
> audit_timeout
) {
2149 smb_time_audit_log_fname("setxattr", timediff
, path
);
2155 static int smb_time_audit_fsetxattr(struct vfs_handle_struct
*handle
,
2156 struct files_struct
*fsp
, const char *name
,
2157 const void *value
, size_t size
, int flags
)
2160 struct timespec ts1
,ts2
;
2163 clock_gettime_mono(&ts1
);
2164 result
= SMB_VFS_NEXT_FSETXATTR(handle
, fsp
, name
, value
, size
, flags
);
2165 clock_gettime_mono(&ts2
);
2166 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
2168 if (timediff
> audit_timeout
) {
2169 smb_time_audit_log_fsp("fsetxattr", timediff
, fsp
);
2175 static bool smb_time_audit_aio_force(struct vfs_handle_struct
*handle
,
2176 struct files_struct
*fsp
)
2179 struct timespec ts1
,ts2
;
2182 clock_gettime_mono(&ts1
);
2183 result
= SMB_VFS_NEXT_AIO_FORCE(handle
, fsp
);
2184 clock_gettime_mono(&ts2
);
2185 timediff
= nsec_time_diff(&ts2
,&ts1
)*1.0e-9;
2187 if (timediff
> audit_timeout
) {
2188 smb_time_audit_log_fsp("aio_force", timediff
, fsp
);
2196 /* VFS operations */
2198 static struct vfs_fn_pointers vfs_time_audit_fns
= {
2199 .connect_fn
= smb_time_audit_connect
,
2200 .disconnect_fn
= smb_time_audit_disconnect
,
2201 .disk_free_fn
= smb_time_audit_disk_free
,
2202 .get_quota_fn
= smb_time_audit_get_quota
,
2203 .set_quota_fn
= smb_time_audit_set_quota
,
2204 .get_shadow_copy_data_fn
= smb_time_audit_get_shadow_copy_data
,
2205 .statvfs_fn
= smb_time_audit_statvfs
,
2206 .fs_capabilities_fn
= smb_time_audit_fs_capabilities
,
2207 .opendir_fn
= smb_time_audit_opendir
,
2208 .fdopendir_fn
= smb_time_audit_fdopendir
,
2209 .readdir_fn
= smb_time_audit_readdir
,
2210 .seekdir_fn
= smb_time_audit_seekdir
,
2211 .telldir_fn
= smb_time_audit_telldir
,
2212 .rewind_dir_fn
= smb_time_audit_rewinddir
,
2213 .mkdir_fn
= smb_time_audit_mkdir
,
2214 .rmdir_fn
= smb_time_audit_rmdir
,
2215 .closedir_fn
= smb_time_audit_closedir
,
2216 .init_search_op_fn
= smb_time_audit_init_search_op
,
2217 .open_fn
= smb_time_audit_open
,
2218 .create_file_fn
= smb_time_audit_create_file
,
2219 .close_fn
= smb_time_audit_close
,
2220 .read_fn
= smb_time_audit_read
,
2221 .pread_fn
= smb_time_audit_pread
,
2222 .pread_send_fn
= smb_time_audit_pread_send
,
2223 .pread_recv_fn
= smb_time_audit_pread_recv
,
2224 .write_fn
= smb_time_audit_write
,
2225 .pwrite_fn
= smb_time_audit_pwrite
,
2226 .pwrite_send_fn
= smb_time_audit_pwrite_send
,
2227 .pwrite_recv_fn
= smb_time_audit_pwrite_recv
,
2228 .lseek_fn
= smb_time_audit_lseek
,
2229 .sendfile_fn
= smb_time_audit_sendfile
,
2230 .recvfile_fn
= smb_time_audit_recvfile
,
2231 .rename_fn
= smb_time_audit_rename
,
2232 .fsync_fn
= smb_time_audit_fsync
,
2233 .fsync_send_fn
= smb_time_audit_fsync_send
,
2234 .fsync_recv_fn
= smb_time_audit_fsync_recv
,
2235 .stat_fn
= smb_time_audit_stat
,
2236 .fstat_fn
= smb_time_audit_fstat
,
2237 .lstat_fn
= smb_time_audit_lstat
,
2238 .get_alloc_size_fn
= smb_time_audit_get_alloc_size
,
2239 .unlink_fn
= smb_time_audit_unlink
,
2240 .chmod_fn
= smb_time_audit_chmod
,
2241 .fchmod_fn
= smb_time_audit_fchmod
,
2242 .chown_fn
= smb_time_audit_chown
,
2243 .fchown_fn
= smb_time_audit_fchown
,
2244 .lchown_fn
= smb_time_audit_lchown
,
2245 .chdir_fn
= smb_time_audit_chdir
,
2246 .getwd_fn
= smb_time_audit_getwd
,
2247 .ntimes_fn
= smb_time_audit_ntimes
,
2248 .ftruncate_fn
= smb_time_audit_ftruncate
,
2249 .fallocate_fn
= smb_time_audit_fallocate
,
2250 .lock_fn
= smb_time_audit_lock
,
2251 .kernel_flock_fn
= smb_time_audit_kernel_flock
,
2252 .linux_setlease_fn
= smb_time_audit_linux_setlease
,
2253 .getlock_fn
= smb_time_audit_getlock
,
2254 .symlink_fn
= smb_time_audit_symlink
,
2255 .readlink_fn
= smb_time_audit_readlink
,
2256 .link_fn
= smb_time_audit_link
,
2257 .mknod_fn
= smb_time_audit_mknod
,
2258 .realpath_fn
= smb_time_audit_realpath
,
2259 .notify_watch_fn
= smb_time_audit_notify_watch
,
2260 .chflags_fn
= smb_time_audit_chflags
,
2261 .file_id_create_fn
= smb_time_audit_file_id_create
,
2262 .streaminfo_fn
= smb_time_audit_streaminfo
,
2263 .get_real_filename_fn
= smb_time_audit_get_real_filename
,
2264 .connectpath_fn
= smb_time_audit_connectpath
,
2265 .brl_lock_windows_fn
= smb_time_audit_brl_lock_windows
,
2266 .brl_unlock_windows_fn
= smb_time_audit_brl_unlock_windows
,
2267 .brl_cancel_windows_fn
= smb_time_audit_brl_cancel_windows
,
2268 .strict_lock_fn
= smb_time_audit_strict_lock
,
2269 .strict_unlock_fn
= smb_time_audit_strict_unlock
,
2270 .translate_name_fn
= smb_time_audit_translate_name
,
2271 .copy_chunk_send_fn
= smb_time_audit_copy_chunk_send
,
2272 .copy_chunk_recv_fn
= smb_time_audit_copy_chunk_recv
,
2273 .fget_nt_acl_fn
= smb_time_audit_fget_nt_acl
,
2274 .get_nt_acl_fn
= smb_time_audit_get_nt_acl
,
2275 .fset_nt_acl_fn
= smb_time_audit_fset_nt_acl
,
2276 .chmod_acl_fn
= smb_time_audit_chmod_acl
,
2277 .fchmod_acl_fn
= smb_time_audit_fchmod_acl
,
2278 .sys_acl_get_file_fn
= smb_time_audit_sys_acl_get_file
,
2279 .sys_acl_get_fd_fn
= smb_time_audit_sys_acl_get_fd
,
2280 .sys_acl_blob_get_file_fn
= smb_time_audit_sys_acl_blob_get_file
,
2281 .sys_acl_blob_get_fd_fn
= smb_time_audit_sys_acl_blob_get_fd
,
2282 .sys_acl_set_file_fn
= smb_time_audit_sys_acl_set_file
,
2283 .sys_acl_set_fd_fn
= smb_time_audit_sys_acl_set_fd
,
2284 .sys_acl_delete_def_file_fn
= smb_time_audit_sys_acl_delete_def_file
,
2285 .getxattr_fn
= smb_time_audit_getxattr
,
2286 .fgetxattr_fn
= smb_time_audit_fgetxattr
,
2287 .listxattr_fn
= smb_time_audit_listxattr
,
2288 .flistxattr_fn
= smb_time_audit_flistxattr
,
2289 .removexattr_fn
= smb_time_audit_removexattr
,
2290 .fremovexattr_fn
= smb_time_audit_fremovexattr
,
2291 .setxattr_fn
= smb_time_audit_setxattr
,
2292 .fsetxattr_fn
= smb_time_audit_fsetxattr
,
2293 .aio_force_fn
= smb_time_audit_aio_force
,
2297 NTSTATUS
vfs_time_audit_init(void);
2298 NTSTATUS
vfs_time_audit_init(void)
2300 audit_timeout
= (double)lp_parm_int(-1, "time_audit", "timeout",
2302 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION
, "time_audit",
2303 &vfs_time_audit_fns
);