7116796cc4668275ab196302061f548168b93570
[nivanova/samba-autobuild/.git] / source3 / modules / vfs_time_audit.c
1 /*
2  * Time auditing VFS module for samba.  Log time taken for VFS call to syslog
3  * facility.
4  *
5  * Copyright (C) Abhidnya Chirmule <achirmul@in.ibm.com> 2009
6  *
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.
11  *
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.
16  *
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/>.
19  */
20
21 /*
22  * This module implements logging for time taken for all Samba VFS operations.
23  *
24  * vfs objects = time_audit
25  */
26
27
28 #include "includes.h"
29 #include "smbd/smbd.h"
30 #include "ntioctl.h"
31 #include "lib/util/tevent_unix.h"
32 #include "lib/util/tevent_ntstatus.h"
33
34 #undef DBGC_CLASS
35 #define DBGC_CLASS DBGC_VFS
36
37 static double audit_timeout;
38
39 static void smb_time_audit_log_msg(const char *syscallname, double elapsed,
40                                     const char *msg)
41 {
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) ? " " : ""));
47 }
48
49 static void smb_time_audit_log(const char *syscallname, double elapsed)
50 {
51         smb_time_audit_log_msg(syscallname, elapsed, NULL);
52 }
53
54 static void smb_time_audit_log_fsp(const char *syscallname, double elapsed,
55                                    const struct files_struct *fsp)
56 {
57         char *base_name = NULL;
58         char *connectpath = NULL;
59         char *msg = NULL;
60
61         if (fsp == NULL) {
62                 smb_time_audit_log(syscallname, elapsed);
63                 return;
64         }
65         if (fsp->conn)
66                 connectpath = fsp->conn->connectpath;
67         if (fsp->fsp_name)
68                 base_name = fsp->fsp_name->base_name;
69
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\", "
75                                       "base_name = <NULL>",
76                                       connectpath);
77         } else if (connectpath == NULL && base_name != NULL) {
78                 msg = talloc_asprintf(talloc_tos(), "connectpath = <NULL>, "
79                                       "base_name = \"%s\"",
80                                       base_name);
81         } else { /* connectpath == NULL && base_name == NULL */
82                 msg = talloc_asprintf(talloc_tos(), "connectpath = <NULL>, "
83                                       "base_name = <NULL>");
84         }
85         smb_time_audit_log_msg(syscallname, elapsed, msg);
86         TALLOC_FREE(msg);
87 }
88
89 static void smb_time_audit_log_fname(const char *syscallname, double elapsed,
90                                     const char *fname)
91 {
92         char cwd[PATH_MAX];
93         char *msg = NULL;
94
95         if (getcwd(cwd, sizeof(cwd)) == NULL) {
96                 snprintf(cwd, sizeof(cwd), "<getcwd() error %d>", errno);
97         }
98         if (fname != NULL) {
99                 msg = talloc_asprintf(talloc_tos(),
100                                       "cwd = \"%s\", filename = \"%s\"",
101                                       cwd, fname);
102         } else {
103                 msg = talloc_asprintf(talloc_tos(),
104                                       "cwd = \"%s\", filename = <NULL>",
105                                       cwd);
106         }
107         smb_time_audit_log_msg(syscallname, elapsed, msg);
108         TALLOC_FREE(msg);
109 }
110
111 static void smb_time_audit_log_smb_fname(const char *syscallname, double elapsed,
112                                        const struct smb_filename *smb_fname)
113 {
114         if (smb_fname != NULL) {
115                 smb_time_audit_log_fname(syscallname, elapsed,
116                                          smb_fname->base_name);
117         } else {
118                 smb_time_audit_log_fname(syscallname, elapsed,
119                                          "smb_fname = <NULL>");
120         }
121 }
122
123 static int smb_time_audit_connect(vfs_handle_struct *handle,
124                                   const char *svc, const char *user)
125 {
126         int result;
127         struct timespec ts1,ts2;
128         double timediff;
129
130         if (!handle) {
131                 return -1;
132         }
133
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);
140         }
141         return result;
142 }
143
144 static void smb_time_audit_disconnect(vfs_handle_struct *handle)
145 {
146         struct timespec ts1,ts2;
147         double timediff;
148
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;
153
154         if (timediff > audit_timeout) {
155                 smb_time_audit_log("disconnect", timediff);
156         }
157 }
158
159 static uint64_t smb_time_audit_disk_free(vfs_handle_struct *handle,
160                                         const struct smb_filename *smb_fname,
161                                         uint64_t *bsize,
162                                         uint64_t *dfree,
163                                         uint64_t *dsize)
164 {
165         uint64_t result;
166         struct timespec ts1,ts2;
167         double timediff;
168
169         clock_gettime_mono(&ts1);
170         result = SMB_VFS_NEXT_DISK_FREE(handle, smb_fname, bsize, dfree, dsize);
171         clock_gettime_mono(&ts2);
172         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
173
174         /* Don't have a reasonable notion of failure here */
175         if (timediff > audit_timeout) {
176                 smb_time_audit_log_fname("disk_free",
177                                 timediff,
178                                 smb_fname->base_name);
179         }
180
181         return result;
182 }
183
184 static int smb_time_audit_get_quota(struct vfs_handle_struct *handle,
185                                         const struct smb_filename *smb_fname,
186                                         enum SMB_QUOTA_TYPE qtype,
187                                         unid_t id,
188                                         SMB_DISK_QUOTA *qt)
189 {
190         int result;
191         struct timespec ts1,ts2;
192         double timediff;
193
194         clock_gettime_mono(&ts1);
195         result = SMB_VFS_NEXT_GET_QUOTA(handle, smb_fname, qtype, id, qt);
196         clock_gettime_mono(&ts2);
197         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
198
199         if (timediff > audit_timeout) {
200                 smb_time_audit_log_fname("get_quota",
201                                 timediff,
202                                 smb_fname->base_name);
203         }
204         return result;
205 }
206
207 static int smb_time_audit_set_quota(struct vfs_handle_struct *handle,
208                                     enum SMB_QUOTA_TYPE qtype, unid_t id,
209                                     SMB_DISK_QUOTA *qt)
210 {
211         int result;
212         struct timespec ts1,ts2;
213         double timediff;
214
215         clock_gettime_mono(&ts1);
216         result = SMB_VFS_NEXT_SET_QUOTA(handle, qtype, id, qt);
217         clock_gettime_mono(&ts2);
218         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
219
220         if (timediff > audit_timeout) {
221                 smb_time_audit_log("set_quota", timediff);
222         }
223
224         return result;
225 }
226
227 static int smb_time_audit_get_shadow_copy_data(struct vfs_handle_struct *handle,
228                                                struct files_struct *fsp,
229                                                struct shadow_copy_data *shadow_copy_data,
230                                                bool labels)
231 {
232         int result;
233         struct timespec ts1,ts2;
234         double timediff;
235
236         clock_gettime_mono(&ts1);
237         result = SMB_VFS_NEXT_GET_SHADOW_COPY_DATA(handle, fsp,
238                                                    shadow_copy_data, labels);
239         clock_gettime_mono(&ts2);
240         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
241
242         if (timediff > audit_timeout) {
243                 smb_time_audit_log_fsp("get_shadow_copy_data", timediff, fsp);
244         }
245
246         return result;
247 }
248
249 static int smb_time_audit_statvfs(struct vfs_handle_struct *handle,
250                                   const struct smb_filename *smb_fname,
251                                   struct vfs_statvfs_struct *statbuf)
252 {
253         int result;
254         struct timespec ts1,ts2;
255         double timediff;
256
257         clock_gettime_mono(&ts1);
258         result = SMB_VFS_NEXT_STATVFS(handle, smb_fname, statbuf);
259         clock_gettime_mono(&ts2);
260         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
261
262         if (timediff > audit_timeout) {
263                 smb_time_audit_log_fname("statvfs", timediff,
264                         smb_fname->base_name);
265         }
266
267         return result;
268 }
269
270 static uint32_t smb_time_audit_fs_capabilities(struct vfs_handle_struct *handle,
271                                                enum timestamp_set_resolution *p_ts_res)
272 {
273         uint32_t result;
274         struct timespec ts1,ts2;
275         double timediff;
276
277         clock_gettime_mono(&ts1);
278         result = SMB_VFS_NEXT_FS_CAPABILITIES(handle, p_ts_res);
279         clock_gettime_mono(&ts2);
280         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
281
282         if (timediff > audit_timeout) {
283                 smb_time_audit_log("fs_capabilities", timediff);
284         }
285
286         return result;
287 }
288
289 static NTSTATUS smb_time_audit_get_dfs_referrals(
290                         struct vfs_handle_struct *handle,
291                         struct dfs_GetDFSReferral *r)
292 {
293         NTSTATUS result;
294         struct timespec ts1,ts2;
295         double timediff;
296
297         clock_gettime_mono(&ts1);
298         result = SMB_VFS_NEXT_GET_DFS_REFERRALS(handle, r);
299         clock_gettime_mono(&ts2);
300         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
301
302         if (timediff > audit_timeout) {
303                 smb_time_audit_log("get_dfs_referrals(", timediff);
304         }
305
306         return result;
307 }
308
309 static NTSTATUS smb_time_audit_snap_check_path(struct vfs_handle_struct *handle,
310                                                TALLOC_CTX *mem_ctx,
311                                                const char *service_path,
312                                                char **base_volume)
313 {
314         NTSTATUS status;
315         struct timespec ts1,ts2;
316         double timediff;
317
318         clock_gettime_mono(&ts1);
319         status = SMB_VFS_NEXT_SNAP_CHECK_PATH(handle, mem_ctx, service_path,
320                                               base_volume);
321         clock_gettime_mono(&ts2);
322         timediff = nsec_time_diff(&ts2, &ts1) * 1.0e-9;
323
324         if (timediff > audit_timeout) {
325                 smb_time_audit_log("snap_check_path", timediff);
326         }
327
328         return status;
329 }
330
331 static NTSTATUS smb_time_audit_snap_create(struct vfs_handle_struct *handle,
332                                            TALLOC_CTX *mem_ctx,
333                                            const char *base_volume,
334                                            time_t *tstamp,
335                                            bool rw,
336                                            char **base_path,
337                                            char **snap_path)
338 {
339         NTSTATUS status;
340         struct timespec ts1,ts2;
341         double timediff;
342
343         clock_gettime_mono(&ts1);
344         status = SMB_VFS_NEXT_SNAP_CREATE(handle, mem_ctx, base_volume, tstamp,
345                                           rw, base_path, snap_path);
346         clock_gettime_mono(&ts2);
347         timediff = nsec_time_diff(&ts2 ,&ts1) * 1.0e-9;
348
349         if (timediff > audit_timeout) {
350                 smb_time_audit_log("snap_create", timediff);
351         }
352
353         return status;
354 }
355
356 static NTSTATUS smb_time_audit_snap_delete(struct vfs_handle_struct *handle,
357                                            TALLOC_CTX *mem_ctx,
358                                            char *base_path,
359                                            char *snap_path)
360 {
361         NTSTATUS status;
362         struct timespec ts1,ts2;
363         double timediff;
364
365         clock_gettime_mono(&ts1);
366         status = SMB_VFS_NEXT_SNAP_DELETE(handle, mem_ctx, base_path,
367                                           snap_path);
368         clock_gettime_mono(&ts2);
369         timediff = nsec_time_diff(&ts2, &ts1) * 1.0e-9;
370
371         if (timediff > audit_timeout) {
372                 smb_time_audit_log("snap_delete", timediff);
373         }
374
375         return status;
376 }
377
378 static DIR *smb_time_audit_opendir(vfs_handle_struct *handle,
379                                    const struct smb_filename *smb_fname,
380                                    const char *mask, uint32_t attr)
381 {
382         DIR *result;
383         struct timespec ts1,ts2;
384         double timediff;
385
386         clock_gettime_mono(&ts1);
387         result = SMB_VFS_NEXT_OPENDIR(handle, smb_fname, mask, attr);
388         clock_gettime_mono(&ts2);
389         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
390
391         if (timediff > audit_timeout) {
392                 smb_time_audit_log_smb_fname("opendir", timediff, smb_fname);
393         }
394
395         return result;
396 }
397
398 static DIR *smb_time_audit_fdopendir(vfs_handle_struct *handle,
399                                               files_struct *fsp,
400                                               const char *mask, uint32_t attr)
401 {
402         DIR *result;
403         struct timespec ts1,ts2;
404         double timediff;
405
406         clock_gettime_mono(&ts1);
407         result = SMB_VFS_NEXT_FDOPENDIR(handle, fsp, mask, attr);
408         clock_gettime_mono(&ts2);
409         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
410
411         if (timediff > audit_timeout) {
412                 smb_time_audit_log_fsp("fdopendir", timediff, fsp);
413         }
414
415         return result;
416 }
417
418 static struct dirent *smb_time_audit_readdir(vfs_handle_struct *handle,
419                                                  DIR *dirp,
420                                                  SMB_STRUCT_STAT *sbuf)
421 {
422         struct dirent *result;
423         struct timespec ts1,ts2;
424         double timediff;
425
426         clock_gettime_mono(&ts1);
427         result = SMB_VFS_NEXT_READDIR(handle, dirp, sbuf);
428         clock_gettime_mono(&ts2);
429         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
430
431         if (timediff > audit_timeout) {
432                 smb_time_audit_log("readdir", timediff);
433         }
434
435         return result;
436 }
437
438 static void smb_time_audit_seekdir(vfs_handle_struct *handle,
439                                    DIR *dirp, long offset)
440 {
441         struct timespec ts1,ts2;
442         double timediff;
443
444         clock_gettime_mono(&ts1);
445         SMB_VFS_NEXT_SEEKDIR(handle, dirp, offset);
446         clock_gettime_mono(&ts2);
447         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
448
449         if (timediff > audit_timeout) {
450                 smb_time_audit_log("seekdir", timediff);
451         }
452
453 }
454
455 static long smb_time_audit_telldir(vfs_handle_struct *handle,
456                                    DIR *dirp)
457 {
458         long result;
459         struct timespec ts1,ts2;
460         double timediff;
461
462         clock_gettime_mono(&ts1);
463         result = SMB_VFS_NEXT_TELLDIR(handle, dirp);
464         clock_gettime_mono(&ts2);
465         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
466
467         if (timediff > audit_timeout) {
468                 smb_time_audit_log("telldir", timediff);
469         }
470
471         return result;
472 }
473
474 static void smb_time_audit_rewinddir(vfs_handle_struct *handle,
475                                      DIR *dirp)
476 {
477         struct timespec ts1,ts2;
478         double timediff;
479
480         clock_gettime_mono(&ts1);
481         SMB_VFS_NEXT_REWINDDIR(handle, dirp);
482         clock_gettime_mono(&ts2);
483         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
484
485         if (timediff > audit_timeout) {
486                 smb_time_audit_log("rewinddir", timediff);
487         }
488
489 }
490
491 static int smb_time_audit_mkdir(vfs_handle_struct *handle,
492                                 const struct smb_filename *smb_fname,
493                                 mode_t mode)
494 {
495         int result;
496         struct timespec ts1,ts2;
497         double timediff;
498
499         clock_gettime_mono(&ts1);
500         result = SMB_VFS_NEXT_MKDIR(handle, smb_fname, mode);
501         clock_gettime_mono(&ts2);
502         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
503
504         if (timediff > audit_timeout) {
505                 smb_time_audit_log_smb_fname("mkdir",
506                         timediff,
507                         smb_fname);
508         }
509
510         return result;
511 }
512
513 static int smb_time_audit_rmdir(vfs_handle_struct *handle,
514                                 const struct smb_filename *smb_fname)
515 {
516         int result;
517         struct timespec ts1,ts2;
518         double timediff;
519
520         clock_gettime_mono(&ts1);
521         result = SMB_VFS_NEXT_RMDIR(handle, smb_fname);
522         clock_gettime_mono(&ts2);
523         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
524
525         if (timediff > audit_timeout) {
526                 smb_time_audit_log_smb_fname("rmdir",
527                         timediff,
528                         smb_fname);
529         }
530
531         return result;
532 }
533
534 static int smb_time_audit_closedir(vfs_handle_struct *handle,
535                                    DIR *dirp)
536 {
537         int result;
538         struct timespec ts1,ts2;
539         double timediff;
540
541         clock_gettime_mono(&ts1);
542         result = SMB_VFS_NEXT_CLOSEDIR(handle, dirp);
543         clock_gettime_mono(&ts2);
544         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
545
546         if (timediff > audit_timeout) {
547                 smb_time_audit_log("closedir", timediff);
548         }
549
550         return result;
551 }
552
553 static void smb_time_audit_init_search_op(vfs_handle_struct *handle,
554                                           DIR *dirp)
555 {
556         struct timespec ts1,ts2;
557         double timediff;
558
559         clock_gettime_mono(&ts1);
560         SMB_VFS_NEXT_INIT_SEARCH_OP(handle, dirp);
561         clock_gettime_mono(&ts2);
562         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
563
564         if (timediff > audit_timeout) {
565                 smb_time_audit_log("init_search_op", timediff);
566         }
567 }
568
569 static int smb_time_audit_open(vfs_handle_struct *handle,
570                                struct smb_filename *fname,
571                                files_struct *fsp,
572                                int flags, mode_t mode)
573 {
574         int result;
575         struct timespec ts1,ts2;
576         double timediff;
577
578         clock_gettime_mono(&ts1);
579         result = SMB_VFS_NEXT_OPEN(handle, fname, fsp, flags, mode);
580         clock_gettime_mono(&ts2);
581         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
582
583         if (timediff > audit_timeout) {
584                 smb_time_audit_log_fsp("open", timediff, fsp);
585         }
586
587         return result;
588 }
589
590 static NTSTATUS smb_time_audit_create_file(vfs_handle_struct *handle,
591                                            struct smb_request *req,
592                                            uint16_t root_dir_fid,
593                                            struct smb_filename *fname,
594                                            uint32_t access_mask,
595                                            uint32_t share_access,
596                                            uint32_t create_disposition,
597                                            uint32_t create_options,
598                                            uint32_t file_attributes,
599                                            uint32_t oplock_request,
600                                            struct smb2_lease *lease,
601                                            uint64_t allocation_size,
602                                            uint32_t private_flags,
603                                            struct security_descriptor *sd,
604                                            struct ea_list *ea_list,
605                                            files_struct **result_fsp,
606                                            int *pinfo,
607                                            const struct smb2_create_blobs *in_context_blobs,
608                                            struct smb2_create_blobs *out_context_blobs)
609 {
610         NTSTATUS result;
611         struct timespec ts1,ts2;
612         double timediff;
613
614         clock_gettime_mono(&ts1);
615         result = SMB_VFS_NEXT_CREATE_FILE(
616                 handle,                                 /* handle */
617                 req,                                    /* req */
618                 root_dir_fid,                           /* root_dir_fid */
619                 fname,                                  /* fname */
620                 access_mask,                            /* access_mask */
621                 share_access,                           /* share_access */
622                 create_disposition,                     /* create_disposition*/
623                 create_options,                         /* create_options */
624                 file_attributes,                        /* file_attributes */
625                 oplock_request,                         /* oplock_request */
626                 lease,                                  /* lease */
627                 allocation_size,                        /* allocation_size */
628                 private_flags,
629                 sd,                                     /* sd */
630                 ea_list,                                /* ea_list */
631                 result_fsp,                             /* result */
632                 pinfo,
633                 in_context_blobs, out_context_blobs);   /* create context */
634         clock_gettime_mono(&ts2);
635         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
636
637         if (timediff > audit_timeout) {
638                 /*
639                  * can't use result_fsp this time, may have
640                  * invalid content causing smbd crash
641                  */
642                 smb_time_audit_log_smb_fname("create_file", timediff,
643                                            fname);
644         }
645
646         return result;
647 }
648
649 static int smb_time_audit_close(vfs_handle_struct *handle, files_struct *fsp)
650 {
651         int result;
652         struct timespec ts1,ts2;
653         double timediff;
654
655         clock_gettime_mono(&ts1);
656         result = SMB_VFS_NEXT_CLOSE(handle, fsp);
657         clock_gettime_mono(&ts2);
658         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
659
660         if (timediff > audit_timeout) {
661                 smb_time_audit_log_fsp("close", timediff, fsp);
662         }
663
664         return result;
665 }
666
667 static ssize_t smb_time_audit_read(vfs_handle_struct *handle,
668                                    files_struct *fsp, void *data, size_t n)
669 {
670         ssize_t result;
671         struct timespec ts1,ts2;
672         double timediff;
673
674         clock_gettime_mono(&ts1);
675         result = SMB_VFS_NEXT_READ(handle, fsp, data, n);
676         clock_gettime_mono(&ts2);
677         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
678
679         if (timediff > audit_timeout) {
680                 smb_time_audit_log_fsp("read", timediff, fsp);
681         }
682
683         return result;
684 }
685
686 static ssize_t smb_time_audit_pread(vfs_handle_struct *handle,
687                                     files_struct *fsp,
688                                     void *data, size_t n, off_t offset)
689 {
690         ssize_t result;
691         struct timespec ts1,ts2;
692         double timediff;
693
694         clock_gettime_mono(&ts1);
695         result = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
696         clock_gettime_mono(&ts2);
697         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
698
699         if (timediff > audit_timeout) {
700                 smb_time_audit_log_fsp("pread", timediff, fsp);
701         }
702
703         return result;
704 }
705
706 struct smb_time_audit_pread_state {
707         struct files_struct *fsp;
708         ssize_t ret;
709         struct vfs_aio_state vfs_aio_state;
710 };
711
712 static void smb_time_audit_pread_done(struct tevent_req *subreq);
713
714 static struct tevent_req *smb_time_audit_pread_send(
715         struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
716         struct tevent_context *ev, struct files_struct *fsp,
717         void *data, size_t n, off_t offset)
718 {
719         struct tevent_req *req, *subreq;
720         struct smb_time_audit_pread_state *state;
721
722         req = tevent_req_create(mem_ctx, &state,
723                                 struct smb_time_audit_pread_state);
724         if (req == NULL) {
725                 return NULL;
726         }
727         state->fsp = fsp;
728
729         subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
730                                          n, offset);
731         if (tevent_req_nomem(subreq, req)) {
732                 return tevent_req_post(req, ev);
733         }
734         tevent_req_set_callback(subreq, smb_time_audit_pread_done, req);
735         return req;
736 }
737
738 static void smb_time_audit_pread_done(struct tevent_req *subreq)
739 {
740         struct tevent_req *req = tevent_req_callback_data(
741                 subreq, struct tevent_req);
742         struct smb_time_audit_pread_state *state = tevent_req_data(
743                 req, struct smb_time_audit_pread_state);
744
745         state->ret = SMB_VFS_PREAD_RECV(subreq, &state->vfs_aio_state);
746         TALLOC_FREE(subreq);
747         tevent_req_done(req);
748 }
749
750 static ssize_t smb_time_audit_pread_recv(struct tevent_req *req,
751                                          struct vfs_aio_state *vfs_aio_state)
752 {
753         struct smb_time_audit_pread_state *state = tevent_req_data(
754                 req, struct smb_time_audit_pread_state);
755         double timediff;
756
757         timediff = state->vfs_aio_state.duration * 1.0e-9;
758
759         if (timediff > audit_timeout) {
760                 smb_time_audit_log_fsp("async pread", timediff, state->fsp);
761         }
762
763         if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
764                 return -1;
765         }
766         *vfs_aio_state = state->vfs_aio_state;
767         return state->ret;
768 }
769
770 static ssize_t smb_time_audit_write(vfs_handle_struct *handle,
771                                     files_struct *fsp,
772                                     const void *data, size_t n)
773 {
774         ssize_t result;
775         struct timespec ts1,ts2;
776         double timediff;
777
778         clock_gettime_mono(&ts1);
779         result = SMB_VFS_NEXT_WRITE(handle, fsp, data, n);
780         clock_gettime_mono(&ts2);
781         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
782
783         if (timediff > audit_timeout) {
784                 smb_time_audit_log_fsp("write", timediff, fsp);
785         }
786
787         return result;
788 }
789
790 static ssize_t smb_time_audit_pwrite(vfs_handle_struct *handle,
791                                      files_struct *fsp,
792                                      const void *data, size_t n,
793                                      off_t offset)
794 {
795         ssize_t result;
796         struct timespec ts1,ts2;
797         double timediff;
798
799         clock_gettime_mono(&ts1);
800         result = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
801         clock_gettime_mono(&ts2);
802         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
803
804         if (timediff > audit_timeout) {
805                 smb_time_audit_log_fsp("pwrite", timediff, fsp);
806         }
807
808         return result;
809 }
810
811 struct smb_time_audit_pwrite_state {
812         struct files_struct *fsp;
813         ssize_t ret;
814         struct vfs_aio_state vfs_aio_state;
815 };
816
817 static void smb_time_audit_pwrite_done(struct tevent_req *subreq);
818
819 static struct tevent_req *smb_time_audit_pwrite_send(
820         struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
821         struct tevent_context *ev, struct files_struct *fsp,
822         const void *data, size_t n, off_t offset)
823 {
824         struct tevent_req *req, *subreq;
825         struct smb_time_audit_pwrite_state *state;
826
827         req = tevent_req_create(mem_ctx, &state,
828                                 struct smb_time_audit_pwrite_state);
829         if (req == NULL) {
830                 return NULL;
831         }
832         state->fsp = fsp;
833
834         subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
835                                          n, offset);
836         if (tevent_req_nomem(subreq, req)) {
837                 return tevent_req_post(req, ev);
838         }
839         tevent_req_set_callback(subreq, smb_time_audit_pwrite_done, req);
840         return req;
841 }
842
843 static void smb_time_audit_pwrite_done(struct tevent_req *subreq)
844 {
845         struct tevent_req *req = tevent_req_callback_data(
846                 subreq, struct tevent_req);
847         struct smb_time_audit_pwrite_state *state = tevent_req_data(
848                 req, struct smb_time_audit_pwrite_state);
849
850         state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->vfs_aio_state);
851         TALLOC_FREE(subreq);
852         tevent_req_done(req);
853 }
854
855 static ssize_t smb_time_audit_pwrite_recv(struct tevent_req *req,
856                                           struct vfs_aio_state *vfs_aio_state)
857 {
858         struct smb_time_audit_pwrite_state *state = tevent_req_data(
859                 req, struct smb_time_audit_pwrite_state);
860         double timediff;
861
862         timediff = state->vfs_aio_state.duration * 1.0e-9;
863
864         if (timediff > audit_timeout) {
865                 smb_time_audit_log_fsp("async pwrite", timediff, state->fsp);
866         }
867
868         if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
869                 return -1;
870         }
871         *vfs_aio_state = state->vfs_aio_state;
872         return state->ret;
873 }
874
875 static off_t smb_time_audit_lseek(vfs_handle_struct *handle,
876                                       files_struct *fsp,
877                                       off_t offset, int whence)
878 {
879         off_t result;
880         struct timespec ts1,ts2;
881         double timediff;
882
883         clock_gettime_mono(&ts1);
884         result = SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence);
885         clock_gettime_mono(&ts2);
886         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
887
888         if (timediff > audit_timeout) {
889                 smb_time_audit_log_fsp("lseek", timediff, fsp);
890         }
891
892         return result;
893 }
894
895 static ssize_t smb_time_audit_sendfile(vfs_handle_struct *handle, int tofd,
896                                        files_struct *fromfsp,
897                                        const DATA_BLOB *hdr, off_t offset,
898                                        size_t n)
899 {
900         ssize_t result;
901         struct timespec ts1,ts2;
902         double timediff;
903
904         clock_gettime_mono(&ts1);
905         result = SMB_VFS_NEXT_SENDFILE(handle, tofd, fromfsp, hdr, offset, n);
906         clock_gettime_mono(&ts2);
907         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
908
909         if (timediff > audit_timeout) {
910                 smb_time_audit_log_fsp("sendfile", timediff, fromfsp);
911         }
912
913         return result;
914 }
915
916 static ssize_t smb_time_audit_recvfile(vfs_handle_struct *handle, int fromfd,
917                                        files_struct *tofsp,
918                                        off_t offset,
919                                        size_t n)
920 {
921         ssize_t result;
922         struct timespec ts1,ts2;
923         double timediff;
924
925         clock_gettime_mono(&ts1);
926         result = SMB_VFS_NEXT_RECVFILE(handle, fromfd, tofsp, offset, n);
927         clock_gettime_mono(&ts2);
928         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
929
930         if (timediff > audit_timeout) {
931                 smb_time_audit_log_fsp("recvfile", timediff, tofsp);
932         }
933
934         return result;
935 }
936
937 static int smb_time_audit_rename(vfs_handle_struct *handle,
938                                  const struct smb_filename *oldname,
939                                  const struct smb_filename *newname)
940 {
941         int result;
942         struct timespec ts1,ts2;
943         double timediff;
944
945         clock_gettime_mono(&ts1);
946         result = SMB_VFS_NEXT_RENAME(handle, oldname, newname);
947         clock_gettime_mono(&ts2);
948         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
949
950         if (timediff > audit_timeout) {
951                 smb_time_audit_log_smb_fname("rename", timediff, newname);
952         }
953
954         return result;
955 }
956
957 static int smb_time_audit_fsync(vfs_handle_struct *handle, files_struct *fsp)
958 {
959         int result;
960         struct timespec ts1,ts2;
961         double timediff;
962
963         clock_gettime_mono(&ts1);
964         result = SMB_VFS_NEXT_FSYNC(handle, fsp);
965         clock_gettime_mono(&ts2);
966         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
967
968         if (timediff > audit_timeout) {
969                 smb_time_audit_log_fsp("fsync", timediff, fsp);
970         }
971
972         return result;
973 }
974
975 struct smb_time_audit_fsync_state {
976         struct files_struct *fsp;
977         int ret;
978         struct vfs_aio_state vfs_aio_state;
979 };
980
981 static void smb_time_audit_fsync_done(struct tevent_req *subreq);
982
983 static struct tevent_req *smb_time_audit_fsync_send(
984         struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
985         struct tevent_context *ev, struct files_struct *fsp)
986 {
987         struct tevent_req *req, *subreq;
988         struct smb_time_audit_fsync_state *state;
989
990         req = tevent_req_create(mem_ctx, &state,
991                                 struct smb_time_audit_fsync_state);
992         if (req == NULL) {
993                 return NULL;
994         }
995         state->fsp = fsp;
996
997         subreq = SMB_VFS_NEXT_FSYNC_SEND(state, ev, handle, fsp);
998         if (tevent_req_nomem(subreq, req)) {
999                 return tevent_req_post(req, ev);
1000         }
1001         tevent_req_set_callback(subreq, smb_time_audit_fsync_done, req);
1002         return req;
1003 }
1004
1005 static void smb_time_audit_fsync_done(struct tevent_req *subreq)
1006 {
1007         struct tevent_req *req = tevent_req_callback_data(
1008                 subreq, struct tevent_req);
1009         struct smb_time_audit_fsync_state *state = tevent_req_data(
1010                 req, struct smb_time_audit_fsync_state);
1011
1012         state->ret = SMB_VFS_FSYNC_RECV(subreq, &state->vfs_aio_state);
1013         TALLOC_FREE(subreq);
1014         tevent_req_done(req);
1015 }
1016
1017 static int smb_time_audit_fsync_recv(struct tevent_req *req,
1018                                      struct vfs_aio_state *vfs_aio_state)
1019 {
1020         struct smb_time_audit_fsync_state *state = tevent_req_data(
1021                 req, struct smb_time_audit_fsync_state);
1022         double timediff;
1023
1024         timediff = state->vfs_aio_state.duration * 1.0e-9;
1025
1026         if (timediff > audit_timeout) {
1027                 smb_time_audit_log_fsp("async fsync", timediff, state->fsp);
1028         }
1029
1030         if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1031                 return -1;
1032         }
1033         *vfs_aio_state = state->vfs_aio_state;
1034         return state->ret;
1035 }
1036
1037 static int smb_time_audit_stat(vfs_handle_struct *handle,
1038                                struct smb_filename *fname)
1039 {
1040         int result;
1041         struct timespec ts1,ts2;
1042         double timediff;
1043
1044         clock_gettime_mono(&ts1);
1045         result = SMB_VFS_NEXT_STAT(handle, fname);
1046         clock_gettime_mono(&ts2);
1047         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1048
1049         if (timediff > audit_timeout) {
1050                 smb_time_audit_log_smb_fname("stat", timediff, fname);
1051         }
1052
1053         return result;
1054 }
1055
1056 static int smb_time_audit_fstat(vfs_handle_struct *handle, files_struct *fsp,
1057                                 SMB_STRUCT_STAT *sbuf)
1058 {
1059         int result;
1060         struct timespec ts1,ts2;
1061         double timediff;
1062
1063         clock_gettime_mono(&ts1);
1064         result = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1065         clock_gettime_mono(&ts2);
1066         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1067
1068         if (timediff > audit_timeout) {
1069                 smb_time_audit_log_fsp("fstat", timediff, fsp);
1070         }
1071
1072         return result;
1073 }
1074
1075 static int smb_time_audit_lstat(vfs_handle_struct *handle,
1076                                 struct smb_filename *path)
1077 {
1078         int result;
1079         struct timespec ts1,ts2;
1080         double timediff;
1081
1082         clock_gettime_mono(&ts1);
1083         result = SMB_VFS_NEXT_LSTAT(handle, path);
1084         clock_gettime_mono(&ts2);
1085         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1086
1087         if (timediff > audit_timeout) {
1088                 smb_time_audit_log_smb_fname("lstat", timediff, path);
1089         }
1090
1091         return result;
1092 }
1093
1094 static uint64_t smb_time_audit_get_alloc_size(vfs_handle_struct *handle,
1095                                               files_struct *fsp,
1096                                               const SMB_STRUCT_STAT *sbuf)
1097 {
1098         uint64_t result;
1099         struct timespec ts1,ts2;
1100         double timediff;
1101
1102         clock_gettime_mono(&ts1);
1103         result = SMB_VFS_NEXT_GET_ALLOC_SIZE(handle, fsp, sbuf);
1104         clock_gettime_mono(&ts2);
1105         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1106
1107         if (timediff > audit_timeout) {
1108                 smb_time_audit_log_fsp("get_alloc_size", timediff, fsp);
1109         }
1110
1111         return result;
1112 }
1113
1114 static int smb_time_audit_unlink(vfs_handle_struct *handle,
1115                                  const struct smb_filename *path)
1116 {
1117         int result;
1118         struct timespec ts1,ts2;
1119         double timediff;
1120
1121         clock_gettime_mono(&ts1);
1122         result = SMB_VFS_NEXT_UNLINK(handle, path);
1123         clock_gettime_mono(&ts2);
1124         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1125
1126         if (timediff > audit_timeout) {
1127                 smb_time_audit_log_smb_fname("unlink", timediff, path);
1128         }
1129
1130         return result;
1131 }
1132
1133 static int smb_time_audit_chmod(vfs_handle_struct *handle,
1134                         const struct smb_filename *smb_fname,
1135                         mode_t mode)
1136 {
1137         int result;
1138         struct timespec ts1,ts2;
1139         double timediff;
1140
1141         clock_gettime_mono(&ts1);
1142         result = SMB_VFS_NEXT_CHMOD(handle, smb_fname, mode);
1143         clock_gettime_mono(&ts2);
1144         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1145
1146         if (timediff > audit_timeout) {
1147                 smb_time_audit_log_fname("chmod",
1148                         timediff,
1149                         smb_fname->base_name);
1150         }
1151
1152         return result;
1153 }
1154
1155 static int smb_time_audit_fchmod(vfs_handle_struct *handle, files_struct *fsp,
1156                                  mode_t mode)
1157 {
1158         int result;
1159         struct timespec ts1,ts2;
1160         double timediff;
1161
1162         clock_gettime_mono(&ts1);
1163         result = SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1164         clock_gettime_mono(&ts2);
1165         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1166
1167         if (timediff > audit_timeout) {
1168                 smb_time_audit_log_fsp("fchmod", timediff, fsp);
1169         }
1170
1171         return result;
1172 }
1173
1174 static int smb_time_audit_chown(vfs_handle_struct *handle,
1175                         const struct smb_filename *smb_fname,
1176                         uid_t uid,
1177                         gid_t gid)
1178 {
1179         int result;
1180         struct timespec ts1,ts2;
1181         double timediff;
1182
1183         clock_gettime_mono(&ts1);
1184         result = SMB_VFS_NEXT_CHOWN(handle, smb_fname, uid, gid);
1185         clock_gettime_mono(&ts2);
1186         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1187
1188         if (timediff > audit_timeout) {
1189                 smb_time_audit_log_fname("chown",
1190                         timediff,
1191                         smb_fname->base_name);
1192         }
1193
1194         return result;
1195 }
1196
1197 static int smb_time_audit_fchown(vfs_handle_struct *handle, files_struct *fsp,
1198                                  uid_t uid, gid_t gid)
1199 {
1200         int result;
1201         struct timespec ts1,ts2;
1202         double timediff;
1203
1204         clock_gettime_mono(&ts1);
1205         result = SMB_VFS_NEXT_FCHOWN(handle, fsp, uid, gid);
1206         clock_gettime_mono(&ts2);
1207         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1208
1209         if (timediff > audit_timeout) {
1210                 smb_time_audit_log_fsp("fchown", timediff, fsp);
1211         }
1212
1213         return result;
1214 }
1215
1216 static int smb_time_audit_lchown(vfs_handle_struct *handle,
1217                         const struct smb_filename *smb_fname,
1218                         uid_t uid,
1219                         gid_t gid)
1220 {
1221         int result;
1222         struct timespec ts1,ts2;
1223         double timediff;
1224
1225         clock_gettime_mono(&ts1);
1226         result = SMB_VFS_NEXT_LCHOWN(handle, smb_fname, uid, gid);
1227         clock_gettime_mono(&ts2);
1228         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1229
1230         if (timediff > audit_timeout) {
1231                 smb_time_audit_log_fname("lchown",
1232                         timediff,
1233                         smb_fname->base_name);
1234         }
1235
1236         return result;
1237 }
1238
1239 static int smb_time_audit_chdir(vfs_handle_struct *handle,
1240                         const struct smb_filename *smb_fname)
1241 {
1242         int result;
1243         struct timespec ts1,ts2;
1244         double timediff;
1245
1246         clock_gettime_mono(&ts1);
1247         result = SMB_VFS_NEXT_CHDIR(handle, smb_fname);
1248         clock_gettime_mono(&ts2);
1249         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1250
1251         if (timediff > audit_timeout) {
1252                 smb_time_audit_log_fname("chdir",
1253                         timediff,
1254                         smb_fname->base_name);
1255         }
1256
1257         return result;
1258 }
1259
1260 static struct smb_filename *smb_time_audit_getwd(vfs_handle_struct *handle,
1261                                         TALLOC_CTX *mem_ctx)
1262 {
1263         struct smb_filename *result;
1264         struct timespec ts1,ts2;
1265         double timediff;
1266
1267         clock_gettime_mono(&ts1);
1268         result = SMB_VFS_NEXT_GETWD(handle, mem_ctx);
1269         clock_gettime_mono(&ts2);
1270         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1271
1272         if (timediff > audit_timeout) {
1273                 smb_time_audit_log("getwd", timediff);
1274         }
1275
1276         return result;
1277 }
1278
1279 static int smb_time_audit_ntimes(vfs_handle_struct *handle,
1280                                  const struct smb_filename *path,
1281                                  struct smb_file_time *ft)
1282 {
1283         int result;
1284         struct timespec ts1,ts2;
1285         double timediff;
1286
1287         clock_gettime_mono(&ts1);
1288         result = SMB_VFS_NEXT_NTIMES(handle, path, ft);
1289         clock_gettime_mono(&ts2);
1290         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1291
1292         if (timediff > audit_timeout) {
1293                 smb_time_audit_log_smb_fname("ntimes", timediff, path);
1294         }
1295
1296         return result;
1297 }
1298
1299 static int smb_time_audit_ftruncate(vfs_handle_struct *handle,
1300                                     files_struct *fsp,
1301                                     off_t len)
1302 {
1303         int result;
1304         struct timespec ts1,ts2;
1305         double timediff;
1306
1307         clock_gettime_mono(&ts1);
1308         result = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1309         clock_gettime_mono(&ts2);
1310         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1311
1312         if (timediff > audit_timeout) {
1313                 smb_time_audit_log_fsp("ftruncate", timediff, fsp);
1314         }
1315
1316         return result;
1317 }
1318
1319 static int smb_time_audit_fallocate(vfs_handle_struct *handle,
1320                                     files_struct *fsp,
1321                                     uint32_t mode,
1322                                     off_t offset,
1323                                     off_t len)
1324 {
1325         int result;
1326         int saved_errno = 0;
1327         struct timespec ts1,ts2;
1328         double timediff;
1329
1330         clock_gettime_mono(&ts1);
1331         result = SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
1332         if (result == -1) {
1333                 saved_errno = errno;
1334         }
1335         clock_gettime_mono(&ts2);
1336         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1337
1338         if (timediff > audit_timeout) {
1339                 smb_time_audit_log_fsp("fallocate", timediff, fsp);
1340         }
1341         if (result == -1) {
1342                 errno = saved_errno;
1343         }
1344         return result;
1345 }
1346
1347 static bool smb_time_audit_lock(vfs_handle_struct *handle, files_struct *fsp,
1348                                 int op, off_t offset, off_t count,
1349                                 int type)
1350 {
1351         bool result;
1352         struct timespec ts1,ts2;
1353         double timediff;
1354
1355         clock_gettime_mono(&ts1);
1356         result = SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type);
1357         clock_gettime_mono(&ts2);
1358         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1359
1360         if (timediff > audit_timeout) {
1361                 smb_time_audit_log_fsp("lock", timediff, fsp);
1362         }
1363
1364         return result;
1365 }
1366
1367 static int smb_time_audit_kernel_flock(struct vfs_handle_struct *handle,
1368                                        struct files_struct *fsp,
1369                                        uint32_t share_mode, uint32_t access_mask)
1370 {
1371         int result;
1372         struct timespec ts1,ts2;
1373         double timediff;
1374
1375         clock_gettime_mono(&ts1);
1376         result = SMB_VFS_NEXT_KERNEL_FLOCK(handle, fsp, share_mode,
1377                                            access_mask);
1378         clock_gettime_mono(&ts2);
1379         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1380
1381         if (timediff > audit_timeout) {
1382                 smb_time_audit_log_fsp("kernel_flock", timediff, fsp);
1383         }
1384
1385         return result;
1386 }
1387
1388 static int smb_time_audit_linux_setlease(vfs_handle_struct *handle,
1389                                          files_struct *fsp,
1390                                          int leasetype)
1391 {
1392         int result;
1393         struct timespec ts1,ts2;
1394         double timediff;
1395
1396         clock_gettime_mono(&ts1);
1397         result = SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
1398         clock_gettime_mono(&ts2);
1399         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1400
1401         if (timediff > audit_timeout) {
1402                 smb_time_audit_log_fsp("linux_setlease", timediff, fsp);
1403         }
1404
1405         return result;
1406 }
1407
1408 static bool smb_time_audit_getlock(vfs_handle_struct *handle,
1409                                    files_struct *fsp,
1410                                    off_t *poffset, off_t *pcount,
1411                                    int *ptype, pid_t *ppid)
1412 {
1413         bool result;
1414         struct timespec ts1,ts2;
1415         double timediff;
1416
1417         clock_gettime_mono(&ts1);
1418         result = SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype,
1419                                       ppid);
1420         clock_gettime_mono(&ts2);
1421         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1422
1423         if (timediff > audit_timeout) {
1424                 smb_time_audit_log_fsp("getlock", timediff, fsp);
1425         }
1426
1427         return result;
1428 }
1429
1430 static int smb_time_audit_symlink(vfs_handle_struct *handle,
1431                                 const char *link_contents,
1432                                 const struct smb_filename *new_smb_fname)
1433 {
1434         int result;
1435         struct timespec ts1,ts2;
1436         double timediff;
1437
1438         clock_gettime_mono(&ts1);
1439         result = SMB_VFS_NEXT_SYMLINK(handle, link_contents, new_smb_fname);
1440         clock_gettime_mono(&ts2);
1441         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1442
1443         if (timediff > audit_timeout) {
1444                 smb_time_audit_log_fname("symlink", timediff,
1445                         new_smb_fname->base_name);
1446         }
1447
1448         return result;
1449 }
1450
1451 static int smb_time_audit_readlink(vfs_handle_struct *handle,
1452                                 const struct smb_filename *smb_fname,
1453                                 char *buf,
1454                                 size_t bufsiz)
1455 {
1456         int result;
1457         struct timespec ts1,ts2;
1458         double timediff;
1459
1460         clock_gettime_mono(&ts1);
1461         result = SMB_VFS_NEXT_READLINK(handle, smb_fname,
1462                                 buf, bufsiz);
1463         clock_gettime_mono(&ts2);
1464         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1465
1466         if (timediff > audit_timeout) {
1467                 smb_time_audit_log_fname("readlink", timediff,
1468                                 smb_fname->base_name);
1469         }
1470
1471         return result;
1472 }
1473
1474 static int smb_time_audit_link(vfs_handle_struct *handle,
1475                                 const struct smb_filename *old_smb_fname,
1476                                 const struct smb_filename *new_smb_fname)
1477 {
1478         int result;
1479         struct timespec ts1,ts2;
1480         double timediff;
1481
1482         clock_gettime_mono(&ts1);
1483         result = SMB_VFS_NEXT_LINK(handle, old_smb_fname, new_smb_fname);
1484         clock_gettime_mono(&ts2);
1485         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1486
1487         if (timediff > audit_timeout) {
1488                 smb_time_audit_log_fname("link", timediff,
1489                         new_smb_fname->base_name);
1490         }
1491
1492         return result;
1493 }
1494
1495 static int smb_time_audit_mknod(vfs_handle_struct *handle,
1496                                 const struct smb_filename *smb_fname,
1497                                 mode_t mode,
1498                                 SMB_DEV_T dev)
1499 {
1500         int result;
1501         struct timespec ts1,ts2;
1502         double timediff;
1503
1504         clock_gettime_mono(&ts1);
1505         result = SMB_VFS_NEXT_MKNOD(handle, smb_fname, mode, dev);
1506         clock_gettime_mono(&ts2);
1507         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1508
1509         if (timediff > audit_timeout) {
1510                 smb_time_audit_log_smb_fname("mknod", timediff, smb_fname);
1511         }
1512
1513         return result;
1514 }
1515
1516 static struct smb_filename *smb_time_audit_realpath(vfs_handle_struct *handle,
1517                                 TALLOC_CTX *ctx,
1518                                 const struct smb_filename *smb_fname)
1519 {
1520         struct smb_filename *result_fname;
1521         struct timespec ts1,ts2;
1522         double timediff;
1523
1524         clock_gettime_mono(&ts1);
1525         result_fname = SMB_VFS_NEXT_REALPATH(handle, ctx, smb_fname);
1526         clock_gettime_mono(&ts2);
1527         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1528
1529         if (timediff > audit_timeout) {
1530                 smb_time_audit_log_fname("realpath", timediff,
1531                                 smb_fname->base_name);
1532         }
1533
1534         return result_fname;
1535 }
1536
1537 static int smb_time_audit_chflags(vfs_handle_struct *handle,
1538                                 const struct smb_filename *smb_fname,
1539                                 unsigned int flags)
1540 {
1541         int result;
1542         struct timespec ts1,ts2;
1543         double timediff;
1544
1545         clock_gettime_mono(&ts1);
1546         result = SMB_VFS_NEXT_CHFLAGS(handle, smb_fname, flags);
1547         clock_gettime_mono(&ts2);
1548         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1549
1550         if (timediff > audit_timeout) {
1551                 smb_time_audit_log_smb_fname("chflags", timediff, smb_fname);
1552         }
1553
1554         return result;
1555 }
1556
1557 static struct file_id smb_time_audit_file_id_create(struct vfs_handle_struct *handle,
1558                                                     const SMB_STRUCT_STAT *sbuf)
1559 {
1560         struct file_id id_zero;
1561         struct file_id result;
1562         struct timespec ts1,ts2;
1563         double timediff;
1564
1565         ZERO_STRUCT(id_zero);
1566
1567         clock_gettime_mono(&ts1);
1568         result = SMB_VFS_NEXT_FILE_ID_CREATE(handle, sbuf);
1569         clock_gettime_mono(&ts2);
1570         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1571
1572         if (timediff > audit_timeout) {
1573                 smb_time_audit_log("file_id_create", timediff);
1574         }
1575
1576         return result;
1577 }
1578
1579 static NTSTATUS smb_time_audit_streaminfo(vfs_handle_struct *handle,
1580                                           struct files_struct *fsp,
1581                                           const struct smb_filename *smb_fname,
1582                                           TALLOC_CTX *mem_ctx,
1583                                           unsigned int *pnum_streams,
1584                                           struct stream_struct **pstreams)
1585 {
1586         NTSTATUS result;
1587         struct timespec ts1,ts2;
1588         double timediff;
1589
1590         clock_gettime_mono(&ts1);
1591         result = SMB_VFS_NEXT_STREAMINFO(handle, fsp, smb_fname, mem_ctx,
1592                                          pnum_streams, pstreams);
1593         clock_gettime_mono(&ts2);
1594         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1595
1596         if (timediff > audit_timeout) {
1597                 smb_time_audit_log_fsp("streaminfo", timediff, fsp);
1598         }
1599
1600         return result;
1601 }
1602
1603 static int smb_time_audit_get_real_filename(struct vfs_handle_struct *handle,
1604                                             const char *path,
1605                                             const char *name,
1606                                             TALLOC_CTX *mem_ctx,
1607                                             char **found_name)
1608 {
1609         int result;
1610         struct timespec ts1,ts2;
1611         double timediff;
1612
1613         clock_gettime_mono(&ts1);
1614         result = SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name, mem_ctx,
1615                                                 found_name);
1616         clock_gettime_mono(&ts2);
1617         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1618
1619         if (timediff > audit_timeout) {
1620                 smb_time_audit_log_fname("get_real_filename", timediff, path);
1621         }
1622
1623         return result;
1624 }
1625
1626 static const char *smb_time_audit_connectpath(vfs_handle_struct *handle,
1627                                         const struct smb_filename *smb_fname)
1628 {
1629         const char *result;
1630         struct timespec ts1,ts2;
1631         double timediff;
1632
1633         clock_gettime_mono(&ts1);
1634         result = SMB_VFS_NEXT_CONNECTPATH(handle, smb_fname);
1635         clock_gettime_mono(&ts2);
1636         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1637
1638         if (timediff > audit_timeout) {
1639                 smb_time_audit_log_fname("connectpath", timediff,
1640                         smb_fname->base_name);
1641         }
1642
1643         return result;
1644 }
1645
1646 static NTSTATUS smb_time_audit_brl_lock_windows(struct vfs_handle_struct *handle,
1647                                                 struct byte_range_lock *br_lck,
1648                                                 struct lock_struct *plock,
1649                                                 bool blocking_lock)
1650 {
1651         NTSTATUS result;
1652         struct timespec ts1,ts2;
1653         double timediff;
1654
1655         clock_gettime_mono(&ts1);
1656         result = SMB_VFS_NEXT_BRL_LOCK_WINDOWS(handle, br_lck, plock,
1657                                                blocking_lock);
1658         clock_gettime_mono(&ts2);
1659         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1660
1661         if (timediff > audit_timeout) {
1662                 smb_time_audit_log_fsp("brl_lock_windows", timediff,
1663                                        brl_fsp(br_lck));
1664         }
1665
1666         return result;
1667 }
1668
1669 static bool smb_time_audit_brl_unlock_windows(struct vfs_handle_struct *handle,
1670                                               struct messaging_context *msg_ctx,
1671                                               struct byte_range_lock *br_lck,
1672                                               const struct lock_struct *plock)
1673 {
1674         bool result;
1675         struct timespec ts1,ts2;
1676         double timediff;
1677
1678         clock_gettime_mono(&ts1);
1679         result = SMB_VFS_NEXT_BRL_UNLOCK_WINDOWS(handle, msg_ctx, br_lck,
1680                                                  plock);
1681         clock_gettime_mono(&ts2);
1682         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1683
1684         if (timediff > audit_timeout) {
1685                 smb_time_audit_log_fsp("brl_unlock_windows", timediff,
1686                                        brl_fsp(br_lck));
1687         }
1688
1689         return result;
1690 }
1691
1692 static bool smb_time_audit_brl_cancel_windows(struct vfs_handle_struct *handle,
1693                                               struct byte_range_lock *br_lck,
1694                                               struct lock_struct *plock)
1695 {
1696         bool result;
1697         struct timespec ts1,ts2;
1698         double timediff;
1699
1700         clock_gettime_mono(&ts1);
1701         result = SMB_VFS_NEXT_BRL_CANCEL_WINDOWS(handle, br_lck, plock);
1702         clock_gettime_mono(&ts2);
1703         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1704
1705         if (timediff > audit_timeout) {
1706                 smb_time_audit_log_fsp("brl_cancel_windows", timediff,
1707                                        brl_fsp(br_lck));
1708         }
1709
1710         return result;
1711 }
1712
1713 static bool smb_time_audit_strict_lock_check(struct vfs_handle_struct *handle,
1714                                              struct files_struct *fsp,
1715                                              struct lock_struct *plock)
1716 {
1717         bool result;
1718         struct timespec ts1,ts2;
1719         double timediff;
1720
1721         clock_gettime_mono(&ts1);
1722         result = SMB_VFS_NEXT_STRICT_LOCK_CHECK(handle, fsp, plock);
1723         clock_gettime_mono(&ts2);
1724         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1725
1726         if (timediff > audit_timeout) {
1727                 smb_time_audit_log_fsp("strict_lock_check", timediff, fsp);
1728         }
1729
1730         return result;
1731 }
1732
1733 static NTSTATUS smb_time_audit_translate_name(struct vfs_handle_struct *handle,
1734                                               const char *name,
1735                                               enum vfs_translate_direction direction,
1736                                               TALLOC_CTX *mem_ctx,
1737                                               char **mapped_name)
1738 {
1739         NTSTATUS result;
1740         struct timespec ts1,ts2;
1741         double timediff;
1742
1743         clock_gettime_mono(&ts1);
1744         result = SMB_VFS_NEXT_TRANSLATE_NAME(handle, name, direction, mem_ctx,
1745                                              mapped_name);
1746         clock_gettime_mono(&ts2);
1747         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1748
1749         if (timediff > audit_timeout) {
1750                 smb_time_audit_log_fname("translate_name", timediff, name);
1751         }
1752
1753         return result;
1754 }
1755
1756 static NTSTATUS smb_time_audit_fsctl(struct vfs_handle_struct *handle,
1757                                 struct files_struct *fsp,
1758                                 TALLOC_CTX *ctx,
1759                                 uint32_t function,
1760                                 uint16_t req_flags,
1761                                 const uint8_t *_in_data,
1762                                 uint32_t in_len,
1763                                 uint8_t **_out_data,
1764                                 uint32_t max_out_len,
1765                                 uint32_t *out_len)
1766 {
1767         NTSTATUS result;
1768         struct timespec ts1,ts2;
1769         double timediff;
1770
1771         clock_gettime_mono(&ts1);
1772         result = SMB_VFS_NEXT_FSCTL(handle,
1773                                 fsp,
1774                                 ctx,
1775                                 function,
1776                                 req_flags,
1777                                 _in_data,
1778                                 in_len,
1779                                 _out_data,
1780                                 max_out_len,
1781                                 out_len);
1782         clock_gettime_mono(&ts2);
1783         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1784
1785         if (timediff > audit_timeout) {
1786                 smb_time_audit_log_fsp("fsctl", timediff, fsp);
1787         }
1788
1789         return result;
1790 }
1791
1792 static NTSTATUS smb_time_get_dos_attributes(struct vfs_handle_struct *handle,
1793                                         struct smb_filename *smb_fname,
1794                                         uint32_t *dosmode)
1795 {
1796         NTSTATUS result;
1797         struct timespec ts1,ts2;
1798         double timediff;
1799
1800         clock_gettime_mono(&ts1);
1801         result = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES(handle,
1802                                 smb_fname,
1803                                 dosmode);
1804         clock_gettime_mono(&ts2);
1805         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1806
1807         if (timediff > audit_timeout) {
1808                 smb_time_audit_log_fname("get_dos_attributes",
1809                                 timediff,
1810                                 smb_fname->base_name);
1811         }
1812
1813         return result;
1814 }
1815
1816 static NTSTATUS smb_time_fget_dos_attributes(struct vfs_handle_struct *handle,
1817                                         struct files_struct *fsp,
1818                                         uint32_t *dosmode)
1819 {
1820         NTSTATUS result;
1821         struct timespec ts1,ts2;
1822         double timediff;
1823
1824         clock_gettime_mono(&ts1);
1825         result = SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle,
1826                                 fsp,
1827                                 dosmode);
1828         clock_gettime_mono(&ts2);
1829         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1830
1831         if (timediff > audit_timeout) {
1832                 smb_time_audit_log_fsp("fget_dos_attributes", timediff, fsp);
1833         }
1834
1835         return result;
1836 }
1837
1838 static NTSTATUS smb_time_set_dos_attributes(struct vfs_handle_struct *handle,
1839                                         const struct smb_filename *smb_fname,
1840                                         uint32_t dosmode)
1841 {
1842         NTSTATUS result;
1843         struct timespec ts1,ts2;
1844         double timediff;
1845
1846         clock_gettime_mono(&ts1);
1847         result = SMB_VFS_NEXT_SET_DOS_ATTRIBUTES(handle,
1848                                 smb_fname,
1849                                 dosmode);
1850         clock_gettime_mono(&ts2);
1851         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1852
1853         if (timediff > audit_timeout) {
1854                 smb_time_audit_log_fname("set_dos_attributes",
1855                                 timediff,
1856                                 smb_fname->base_name);
1857         }
1858
1859         return result;
1860 }
1861
1862 static NTSTATUS smb_time_fset_dos_attributes(struct vfs_handle_struct *handle,
1863                                         struct files_struct *fsp,
1864                                         uint32_t dosmode)
1865 {
1866         NTSTATUS result;
1867         struct timespec ts1,ts2;
1868         double timediff;
1869
1870         clock_gettime_mono(&ts1);
1871         result = SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle,
1872                                 fsp,
1873                                 dosmode);
1874         clock_gettime_mono(&ts2);
1875         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1876
1877         if (timediff > audit_timeout) {
1878                 smb_time_audit_log_fsp("fset_dos_attributes", timediff, fsp);
1879         }
1880
1881         return result;
1882 }
1883
1884 struct time_audit_offload_read_state {
1885         struct vfs_handle_struct *handle;
1886         struct timespec ts_send;
1887         DATA_BLOB token_blob;
1888 };
1889
1890 static void smb_time_audit_offload_read_done(struct tevent_req *subreq);
1891
1892 static struct tevent_req *smb_time_audit_offload_read_send(
1893         TALLOC_CTX *mem_ctx,
1894         struct tevent_context *ev,
1895         struct vfs_handle_struct *handle,
1896         struct files_struct *fsp,
1897         uint32_t fsctl,
1898         uint32_t ttl,
1899         off_t offset,
1900         size_t to_copy)
1901 {
1902         struct tevent_req *req = NULL;
1903         struct tevent_req *subreq = NULL;
1904         struct time_audit_offload_read_state *state = NULL;
1905
1906         req = tevent_req_create(mem_ctx, &state,
1907                                 struct time_audit_offload_read_state);
1908         if (req == NULL) {
1909                 return NULL;
1910         }
1911         state->handle = handle;
1912         clock_gettime_mono(&state->ts_send);
1913
1914         subreq = SMB_VFS_NEXT_OFFLOAD_READ_SEND(mem_ctx, ev,
1915                                                 handle, fsp,
1916                                                 fsctl, ttl,
1917                                                 offset, to_copy);
1918         if (tevent_req_nomem(subreq, req)) {
1919                 return tevent_req_post(req, ev);
1920         }
1921
1922         tevent_req_set_callback(subreq, smb_time_audit_offload_read_done, req);
1923         return req;
1924 }
1925
1926 static void smb_time_audit_offload_read_done(struct tevent_req *subreq)
1927 {
1928         struct tevent_req *req = tevent_req_callback_data(
1929                 subreq, struct tevent_req);
1930         struct time_audit_offload_read_state *state = tevent_req_data(
1931                 req, struct time_audit_offload_read_state);
1932         NTSTATUS status;
1933
1934         status = SMB_VFS_NEXT_OFFLOAD_READ_RECV(subreq,
1935                                                 state->handle,
1936                                                 state,
1937                                                 &state->token_blob);
1938         TALLOC_FREE(subreq);
1939         if (tevent_req_nterror(req, status)) {
1940                 return;
1941         }
1942         tevent_req_done(req);
1943 }
1944
1945 static NTSTATUS smb_time_audit_offload_read_recv(
1946         struct tevent_req *req,
1947         struct vfs_handle_struct *handle,
1948         TALLOC_CTX *mem_ctx,
1949         DATA_BLOB *_token_blob)
1950 {
1951         struct time_audit_offload_read_state *state = tevent_req_data(
1952                 req, struct time_audit_offload_read_state);
1953         struct timespec ts_recv;
1954         double timediff;
1955         DATA_BLOB token_blob;
1956         NTSTATUS status;
1957
1958         clock_gettime_mono(&ts_recv);
1959         timediff = nsec_time_diff(&ts_recv, &state->ts_send) * 1.0e-9;
1960         if (timediff > audit_timeout) {
1961                 smb_time_audit_log("offload_read", timediff);
1962         }
1963
1964         if (tevent_req_is_nterror(req, &status)) {
1965                 tevent_req_received(req);
1966                 return status;
1967         }
1968
1969         token_blob = data_blob_talloc(mem_ctx,
1970                                       state->token_blob.data,
1971                                       state->token_blob.length);
1972         if (token_blob.data == NULL) {
1973                 tevent_req_received(req);
1974                 return NT_STATUS_NO_MEMORY;
1975         }
1976
1977         tevent_req_received(req);
1978         return NT_STATUS_OK;
1979 }
1980
1981 struct time_audit_offload_write_state {
1982         struct timespec ts_send;
1983         struct vfs_handle_struct *handle;
1984         off_t copied;
1985 };
1986 static void smb_time_audit_offload_write_done(struct tevent_req *subreq);
1987
1988 static struct tevent_req *smb_time_audit_offload_write_send(struct vfs_handle_struct *handle,
1989                                                          TALLOC_CTX *mem_ctx,
1990                                                          struct tevent_context *ev,
1991                                                          uint32_t fsctl,
1992                                                          DATA_BLOB *token,
1993                                                          off_t transfer_offset,
1994                                                          struct files_struct *dest_fsp,
1995                                                          off_t dest_off,
1996                                                          off_t num)
1997 {
1998         struct tevent_req *req;
1999         struct tevent_req *subreq;
2000         struct time_audit_offload_write_state *state;
2001
2002         req = tevent_req_create(mem_ctx, &state,
2003                                 struct time_audit_offload_write_state);
2004         if (req == NULL) {
2005                 return NULL;
2006         }
2007
2008         state->handle = handle;
2009         clock_gettime_mono(&state->ts_send);
2010         subreq = SMB_VFS_NEXT_OFFLOAD_WRITE_SEND(handle, state, ev,
2011                                               fsctl, token, transfer_offset,
2012                                               dest_fsp, dest_off, num);
2013         if (tevent_req_nomem(subreq, req)) {
2014                 return tevent_req_post(req, ev);
2015         }
2016
2017         tevent_req_set_callback(subreq, smb_time_audit_offload_write_done, req);
2018         return req;
2019 }
2020
2021 static void smb_time_audit_offload_write_done(struct tevent_req *subreq)
2022 {
2023         struct tevent_req *req = tevent_req_callback_data(
2024                 subreq, struct tevent_req);
2025         struct time_audit_offload_write_state *state = tevent_req_data(
2026                 req, struct time_audit_offload_write_state);
2027         NTSTATUS status;
2028
2029         status = SMB_VFS_NEXT_OFFLOAD_WRITE_RECV(state->handle,
2030                                               subreq,
2031                                               &state->copied);
2032         TALLOC_FREE(subreq);
2033         if (tevent_req_nterror(req, status)) {
2034                 return;
2035         }
2036         tevent_req_done(req);
2037 }
2038
2039 static NTSTATUS smb_time_audit_offload_write_recv(struct vfs_handle_struct *handle,
2040                                                struct tevent_req *req,
2041                                                off_t *copied)
2042 {
2043         struct time_audit_offload_write_state *state = tevent_req_data(
2044                 req, struct time_audit_offload_write_state);
2045         struct timespec ts_recv;
2046         double timediff;
2047         NTSTATUS status;
2048
2049         clock_gettime_mono(&ts_recv);
2050         timediff = nsec_time_diff(&ts_recv, &state->ts_send)*1.0e-9;
2051         if (timediff > audit_timeout) {
2052                 smb_time_audit_log("offload_write", timediff);
2053         }
2054
2055         *copied = state->copied;
2056         if (tevent_req_is_nterror(req, &status)) {
2057                 tevent_req_received(req);
2058                 return status;
2059         }
2060
2061         tevent_req_received(req);
2062         return NT_STATUS_OK;
2063 }
2064
2065 static NTSTATUS smb_time_audit_get_compression(vfs_handle_struct *handle,
2066                                                TALLOC_CTX *mem_ctx,
2067                                                struct files_struct *fsp,
2068                                                struct smb_filename *smb_fname,
2069                                                uint16_t *_compression_fmt)
2070 {
2071         NTSTATUS result;
2072         struct timespec ts1,ts2;
2073         double timediff;
2074
2075         clock_gettime_mono(&ts1);
2076         result = SMB_VFS_NEXT_GET_COMPRESSION(handle, mem_ctx, fsp, smb_fname,
2077                                               _compression_fmt);
2078         clock_gettime_mono(&ts2);
2079         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2080
2081         if (timediff > audit_timeout) {
2082                 if (fsp !=  NULL) {
2083                         smb_time_audit_log_fsp("get_compression",
2084                                                timediff, fsp);
2085                 } else {
2086                         smb_time_audit_log_smb_fname("get_compression",
2087                                                      timediff, smb_fname);
2088                 }
2089         }
2090
2091         return result;
2092 }
2093
2094 static NTSTATUS smb_time_audit_set_compression(vfs_handle_struct *handle,
2095                                                TALLOC_CTX *mem_ctx,
2096                                                struct files_struct *fsp,
2097                                                uint16_t compression_fmt)
2098 {
2099         NTSTATUS result;
2100         struct timespec ts1,ts2;
2101         double timediff;
2102
2103         clock_gettime_mono(&ts1);
2104         result = SMB_VFS_NEXT_SET_COMPRESSION(handle, mem_ctx, fsp,
2105                                               compression_fmt);
2106         clock_gettime_mono(&ts2);
2107         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2108
2109         if (timediff > audit_timeout) {
2110                 smb_time_audit_log_fsp("set_compression", timediff, fsp);
2111         }
2112
2113         return result;
2114 }
2115
2116 static NTSTATUS smb_time_audit_readdir_attr(struct vfs_handle_struct *handle,
2117                                             const struct smb_filename *fname,
2118                                             TALLOC_CTX *mem_ctx,
2119                                             struct readdir_attr_data **pattr_data)
2120 {
2121         NTSTATUS status;
2122         struct timespec ts1,ts2;
2123         double timediff;
2124
2125         clock_gettime_mono(&ts1);
2126         status = SMB_VFS_NEXT_READDIR_ATTR(handle, fname, mem_ctx, pattr_data);
2127         clock_gettime_mono(&ts2);
2128         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2129
2130         if (timediff > audit_timeout) {
2131                 smb_time_audit_log_smb_fname("readdir_attr", timediff, fname);
2132         }
2133
2134         return status;
2135 }
2136
2137 static NTSTATUS smb_time_audit_fget_nt_acl(vfs_handle_struct *handle,
2138                                            files_struct *fsp,
2139                                            uint32_t security_info,
2140                                            TALLOC_CTX *mem_ctx,
2141                                            struct security_descriptor **ppdesc)
2142 {
2143         NTSTATUS result;
2144         struct timespec ts1,ts2;
2145         double timediff;
2146
2147         clock_gettime_mono(&ts1);
2148         result = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
2149                                           mem_ctx, ppdesc);
2150         clock_gettime_mono(&ts2);
2151         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2152
2153         if (timediff > audit_timeout) {
2154                 smb_time_audit_log_fsp("fget_nt_acl", timediff, fsp);
2155         }
2156
2157         return result;
2158 }
2159
2160 static NTSTATUS smb_time_audit_get_nt_acl(vfs_handle_struct *handle,
2161                                           const struct smb_filename *smb_fname,
2162                                           uint32_t security_info,
2163                                           TALLOC_CTX *mem_ctx,
2164                                           struct security_descriptor **ppdesc)
2165 {
2166         NTSTATUS result;
2167         struct timespec ts1,ts2;
2168         double timediff;
2169
2170         clock_gettime_mono(&ts1);
2171         result = SMB_VFS_NEXT_GET_NT_ACL(handle, smb_fname, security_info,
2172                                          mem_ctx, ppdesc);
2173         clock_gettime_mono(&ts2);
2174         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2175
2176         if (timediff > audit_timeout) {
2177                 smb_time_audit_log_fname("get_nt_acl",
2178                         timediff,
2179                         smb_fname->base_name);
2180         }
2181
2182         return result;
2183 }
2184
2185 static NTSTATUS smb_time_audit_fset_nt_acl(vfs_handle_struct *handle,
2186                                            files_struct *fsp,
2187                                            uint32_t security_info_sent,
2188                                            const struct security_descriptor *psd)
2189 {
2190         NTSTATUS result;
2191         struct timespec ts1,ts2;
2192         double timediff;
2193
2194         clock_gettime_mono(&ts1);
2195         result = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent,
2196                                           psd);
2197         clock_gettime_mono(&ts2);
2198         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2199
2200         if (timediff > audit_timeout) {
2201                 smb_time_audit_log_fsp("fset_nt_acl", timediff, fsp);
2202         }
2203
2204         return result;
2205 }
2206
2207 static NTSTATUS smb_time_audit_audit_file(struct vfs_handle_struct *handle,
2208                                 struct smb_filename *smb_fname,
2209                                 struct security_acl *sacl,
2210                                 uint32_t access_requested,
2211                                 uint32_t access_denied)
2212 {
2213         NTSTATUS result;
2214         struct timespec ts1,ts2;
2215         double timediff;
2216
2217         clock_gettime_mono(&ts1);
2218         result = SMB_VFS_NEXT_AUDIT_FILE(handle,
2219                                         smb_fname,
2220                                         sacl,
2221                                         access_requested,
2222                                         access_denied);
2223         clock_gettime_mono(&ts2);
2224         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2225
2226         if (timediff > audit_timeout) {
2227                 smb_time_audit_log_fname("audit_file",
2228                         timediff,
2229                         smb_fname->base_name);
2230         }
2231
2232         return result;
2233 }
2234
2235
2236
2237 static int smb_time_audit_chmod_acl(vfs_handle_struct *handle,
2238                         const struct smb_filename *smb_fname,
2239                         mode_t mode)
2240 {
2241         int result;
2242         struct timespec ts1,ts2;
2243         double timediff;
2244
2245         clock_gettime_mono(&ts1);
2246         result = SMB_VFS_NEXT_CHMOD_ACL(handle, smb_fname, mode);
2247         clock_gettime_mono(&ts2);
2248         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2249
2250         if (timediff > audit_timeout) {
2251                 smb_time_audit_log_fname("chmod_acl",
2252                         timediff,
2253                         smb_fname->base_name);
2254         }
2255
2256         return result;
2257 }
2258
2259 static int smb_time_audit_fchmod_acl(vfs_handle_struct *handle,
2260                                      files_struct *fsp, mode_t mode)
2261 {
2262         int result;
2263         struct timespec ts1,ts2;
2264         double timediff;
2265
2266         clock_gettime_mono(&ts1);
2267         result = SMB_VFS_NEXT_FCHMOD_ACL(handle, fsp, mode);
2268         clock_gettime_mono(&ts2);
2269         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2270
2271         if (timediff > audit_timeout) {
2272                 smb_time_audit_log_fsp("fchmod_acl", timediff, fsp);
2273         }
2274
2275         return result;
2276 }
2277
2278 static SMB_ACL_T smb_time_audit_sys_acl_get_file(vfs_handle_struct *handle,
2279                                         const struct smb_filename *smb_fname,
2280                                         SMB_ACL_TYPE_T type,
2281                                         TALLOC_CTX *mem_ctx)
2282 {
2283         SMB_ACL_T result;
2284         struct timespec ts1,ts2;
2285         double timediff;
2286
2287         clock_gettime_mono(&ts1);
2288         result = SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, smb_fname,
2289                                 type, mem_ctx);
2290         clock_gettime_mono(&ts2);
2291         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2292
2293         if (timediff > audit_timeout) {
2294                 smb_time_audit_log_fname("sys_acl_get_file", timediff,
2295                         smb_fname->base_name);
2296         }
2297
2298         return result;
2299 }
2300
2301 static SMB_ACL_T smb_time_audit_sys_acl_get_fd(vfs_handle_struct *handle,
2302                                                files_struct *fsp,
2303                                                TALLOC_CTX *mem_ctx)
2304 {
2305         SMB_ACL_T result;
2306         struct timespec ts1,ts2;
2307         double timediff;
2308
2309         clock_gettime_mono(&ts1);
2310         result = SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp, mem_ctx);
2311         clock_gettime_mono(&ts2);
2312         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2313
2314         if (timediff > audit_timeout) {
2315                 smb_time_audit_log_fsp("sys_acl_get_fd", timediff, fsp);
2316         }
2317
2318         return result;
2319 }
2320
2321
2322 static int smb_time_audit_sys_acl_blob_get_file(vfs_handle_struct *handle,
2323                                 const struct smb_filename *smb_fname,
2324                                 TALLOC_CTX *mem_ctx,
2325                                 char **blob_description,
2326                                 DATA_BLOB *blob)
2327 {
2328         int result;
2329         struct timespec ts1,ts2;
2330         double timediff;
2331
2332         clock_gettime_mono(&ts1);
2333         result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FILE(handle, smb_fname,
2334                                 mem_ctx, blob_description, blob);
2335         clock_gettime_mono(&ts2);
2336         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2337
2338         if (timediff > audit_timeout) {
2339                 smb_time_audit_log("sys_acl_blob_get_file", timediff);
2340         }
2341
2342         return result;
2343 }
2344
2345 static int smb_time_audit_sys_acl_blob_get_fd(vfs_handle_struct *handle,
2346                                               files_struct *fsp,
2347                                               TALLOC_CTX *mem_ctx, 
2348                                               char **blob_description,
2349                                               DATA_BLOB *blob)
2350 {
2351         int result;
2352         struct timespec ts1,ts2;
2353         double timediff;
2354
2355         clock_gettime_mono(&ts1);
2356         result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle, fsp, mem_ctx, blob_description, blob);
2357         clock_gettime_mono(&ts2);
2358         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2359
2360         if (timediff > audit_timeout) {
2361                 smb_time_audit_log("sys_acl_blob_get_fd", timediff);
2362         }
2363
2364         return result;
2365 }
2366
2367 static int smb_time_audit_sys_acl_set_file(vfs_handle_struct *handle,
2368                                            const struct smb_filename *smb_fname,
2369                                            SMB_ACL_TYPE_T acltype,
2370                                            SMB_ACL_T theacl)
2371 {
2372         int result;
2373         struct timespec ts1,ts2;
2374         double timediff;
2375
2376         clock_gettime_mono(&ts1);
2377         result = SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, smb_fname, acltype,
2378                                                theacl);
2379         clock_gettime_mono(&ts2);
2380         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2381
2382         if (timediff > audit_timeout) {
2383                 smb_time_audit_log_fname("sys_acl_set_file", timediff,
2384                         smb_fname->base_name);
2385         }
2386
2387         return result;
2388 }
2389
2390 static int smb_time_audit_sys_acl_set_fd(vfs_handle_struct *handle,
2391                                          files_struct *fsp,
2392                                          SMB_ACL_T theacl)
2393 {
2394         int result;
2395         struct timespec ts1,ts2;
2396         double timediff;
2397
2398         clock_gettime_mono(&ts1);
2399         result = SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, theacl);
2400         clock_gettime_mono(&ts2);
2401         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2402
2403         if (timediff > audit_timeout) {
2404                 smb_time_audit_log_fsp("sys_acl_set_fd", timediff, fsp);
2405         }
2406
2407         return result;
2408 }
2409
2410 static int smb_time_audit_sys_acl_delete_def_file(vfs_handle_struct *handle,
2411                                 const struct smb_filename *smb_fname)
2412 {
2413         int result;
2414         struct timespec ts1,ts2;
2415         double timediff;
2416
2417         clock_gettime_mono(&ts1);
2418         result = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, smb_fname);
2419         clock_gettime_mono(&ts2);
2420         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2421
2422         if (timediff > audit_timeout) {
2423                 smb_time_audit_log_fname("sys_acl_delete_def_file", timediff,
2424                         smb_fname->base_name);
2425         }
2426
2427         return result;
2428 }
2429
2430 static ssize_t smb_time_audit_getxattr(struct vfs_handle_struct *handle,
2431                                 const struct smb_filename *smb_fname,
2432                                 const char *name,
2433                                 void *value,
2434                                 size_t size)
2435 {
2436         ssize_t result;
2437         struct timespec ts1,ts2;
2438         double timediff;
2439
2440         clock_gettime_mono(&ts1);
2441         result = SMB_VFS_NEXT_GETXATTR(handle, smb_fname, name, value, size);
2442         clock_gettime_mono(&ts2);
2443         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2444
2445         if (timediff > audit_timeout) {
2446                 smb_time_audit_log_fname("getxattr", timediff,
2447                         smb_fname->base_name);
2448         }
2449
2450         return result;
2451 }
2452
2453 static ssize_t smb_time_audit_fgetxattr(struct vfs_handle_struct *handle,
2454                                         struct files_struct *fsp,
2455                                         const char *name, void *value,
2456                                         size_t size)
2457 {
2458         ssize_t result;
2459         struct timespec ts1,ts2;
2460         double timediff;
2461
2462         clock_gettime_mono(&ts1);
2463         result = SMB_VFS_NEXT_FGETXATTR(handle, fsp, name, value, size);
2464         clock_gettime_mono(&ts2);
2465         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2466
2467         if (timediff > audit_timeout) {
2468                 smb_time_audit_log_fsp("fgetxattr", timediff, fsp);
2469         }
2470
2471         return result;
2472 }
2473
2474 static ssize_t smb_time_audit_listxattr(struct vfs_handle_struct *handle,
2475                                         const struct smb_filename *smb_fname,
2476                                         char *list,
2477                                         size_t size)
2478 {
2479         ssize_t result;
2480         struct timespec ts1,ts2;
2481         double timediff;
2482
2483         clock_gettime_mono(&ts1);
2484         result = SMB_VFS_NEXT_LISTXATTR(handle, smb_fname, list, size);
2485         clock_gettime_mono(&ts2);
2486         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2487
2488         if (timediff > audit_timeout) {
2489                 smb_time_audit_log_fname("listxattr", timediff,
2490                                 smb_fname->base_name);
2491         }
2492
2493         return result;
2494 }
2495
2496 static ssize_t smb_time_audit_flistxattr(struct vfs_handle_struct *handle,
2497                                          struct files_struct *fsp, char *list,
2498                                          size_t size)
2499 {
2500         ssize_t result;
2501         struct timespec ts1,ts2;
2502         double timediff;
2503
2504         clock_gettime_mono(&ts1);
2505         result = SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
2506         clock_gettime_mono(&ts2);
2507         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2508
2509         if (timediff > audit_timeout) {
2510                 smb_time_audit_log_fsp("flistxattr", timediff, fsp);
2511         }
2512
2513         return result;
2514 }
2515
2516 static int smb_time_audit_removexattr(struct vfs_handle_struct *handle,
2517                                 const struct smb_filename *smb_fname,
2518                                 const char *name)
2519 {
2520         int result;
2521         struct timespec ts1,ts2;
2522         double timediff;
2523
2524         clock_gettime_mono(&ts1);
2525         result = SMB_VFS_NEXT_REMOVEXATTR(handle, smb_fname, name);
2526         clock_gettime_mono(&ts2);
2527         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2528
2529         if (timediff > audit_timeout) {
2530                 smb_time_audit_log_fname("removexattr", timediff,
2531                         smb_fname->base_name);
2532         }
2533
2534         return result;
2535 }
2536
2537 static int smb_time_audit_fremovexattr(struct vfs_handle_struct *handle,
2538                                        struct files_struct *fsp,
2539                                        const char *name)
2540 {
2541         int result;
2542         struct timespec ts1,ts2;
2543         double timediff;
2544
2545         clock_gettime_mono(&ts1);
2546         result = SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, name);
2547         clock_gettime_mono(&ts2);
2548         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2549
2550         if (timediff > audit_timeout) {
2551                 smb_time_audit_log_fsp("fremovexattr", timediff, fsp);
2552         }
2553
2554         return result;
2555 }
2556
2557 static int smb_time_audit_setxattr(struct vfs_handle_struct *handle,
2558                                 const struct smb_filename *smb_fname,
2559                                 const char *name,
2560                                 const void *value,
2561                                 size_t size,
2562                                 int flags)
2563 {
2564         int result;
2565         struct timespec ts1,ts2;
2566         double timediff;
2567
2568         clock_gettime_mono(&ts1);
2569         result = SMB_VFS_NEXT_SETXATTR(handle, smb_fname, name, value, size,
2570                                        flags);
2571         clock_gettime_mono(&ts2);
2572         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2573
2574         if (timediff > audit_timeout) {
2575                 smb_time_audit_log_fname("setxattr", timediff,
2576                                 smb_fname->base_name);
2577         }
2578
2579         return result;
2580 }
2581
2582 static int smb_time_audit_fsetxattr(struct vfs_handle_struct *handle,
2583                                     struct files_struct *fsp, const char *name,
2584                                     const void *value, size_t size, int flags)
2585 {
2586         int result;
2587         struct timespec ts1,ts2;
2588         double timediff;
2589
2590         clock_gettime_mono(&ts1);
2591         result = SMB_VFS_NEXT_FSETXATTR(handle, fsp, name, value, size, flags);
2592         clock_gettime_mono(&ts2);
2593         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2594
2595         if (timediff > audit_timeout) {
2596                 smb_time_audit_log_fsp("fsetxattr", timediff, fsp);
2597         }
2598
2599         return result;
2600 }
2601
2602 static bool smb_time_audit_aio_force(struct vfs_handle_struct *handle,
2603                                      struct files_struct *fsp)
2604 {
2605         bool result;
2606         struct timespec ts1,ts2;
2607         double timediff;
2608
2609         clock_gettime_mono(&ts1);
2610         result = SMB_VFS_NEXT_AIO_FORCE(handle, fsp);
2611         clock_gettime_mono(&ts2);
2612         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2613
2614         if (timediff > audit_timeout) {
2615                 smb_time_audit_log_fsp("aio_force", timediff, fsp);
2616         }
2617
2618         return result;
2619 }
2620
2621 static NTSTATUS smb_time_audit_durable_cookie(struct vfs_handle_struct *handle,
2622                                               struct files_struct *fsp,
2623                                               TALLOC_CTX *mem_ctx,
2624                                               DATA_BLOB *cookie)
2625 {
2626         NTSTATUS result;
2627         struct timespec ts1,ts2;
2628         double timediff;
2629
2630         clock_gettime_mono(&ts1);
2631         result = SMB_VFS_NEXT_DURABLE_COOKIE(handle, fsp, mem_ctx, cookie);
2632         clock_gettime_mono(&ts2);
2633         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2634
2635         if (timediff > audit_timeout) {
2636                 smb_time_audit_log_fsp("durable_cookie", timediff, fsp);
2637         }
2638
2639         return result;
2640 }
2641
2642 static NTSTATUS smb_time_audit_durable_disconnect(struct vfs_handle_struct *handle,
2643                                                   struct files_struct *fsp,
2644                                                   const DATA_BLOB old_cookie,
2645                                                   TALLOC_CTX *mem_ctx,
2646                                                   DATA_BLOB *new_cookie)
2647 {
2648         NTSTATUS result;
2649         struct timespec ts1,ts2;
2650         double timediff;
2651
2652         clock_gettime_mono(&ts1);
2653         result = SMB_VFS_NEXT_DURABLE_DISCONNECT(handle, fsp, old_cookie,
2654                                                  mem_ctx, new_cookie);
2655         clock_gettime_mono(&ts2);
2656         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2657
2658         if (timediff > audit_timeout) {
2659                 smb_time_audit_log_fsp("durable_disconnect", timediff, fsp);
2660         }
2661
2662         return result;
2663 }
2664
2665 static NTSTATUS smb_time_audit_durable_reconnect(struct vfs_handle_struct *handle,
2666                                                  struct smb_request *smb1req,
2667                                                  struct smbXsrv_open *op,
2668                                                  const DATA_BLOB old_cookie,
2669                                                  TALLOC_CTX *mem_ctx,
2670                                                  struct files_struct **fsp,
2671                                                  DATA_BLOB *new_cookie)
2672 {
2673         NTSTATUS result;
2674         struct timespec ts1,ts2;
2675         double timediff;
2676
2677         clock_gettime_mono(&ts1);
2678         result = SMB_VFS_NEXT_DURABLE_RECONNECT(handle, smb1req, op, old_cookie,
2679                                                 mem_ctx, fsp, new_cookie);
2680         clock_gettime_mono(&ts2);
2681         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2682
2683         if (timediff > audit_timeout) {
2684                 smb_time_audit_log("durable_reconnect", timediff);
2685         }
2686
2687         return result;
2688 }
2689
2690 /* VFS operations */
2691
2692 static struct vfs_fn_pointers vfs_time_audit_fns = {
2693         .connect_fn = smb_time_audit_connect,
2694         .disconnect_fn = smb_time_audit_disconnect,
2695         .disk_free_fn = smb_time_audit_disk_free,
2696         .get_quota_fn = smb_time_audit_get_quota,
2697         .set_quota_fn = smb_time_audit_set_quota,
2698         .get_shadow_copy_data_fn = smb_time_audit_get_shadow_copy_data,
2699         .statvfs_fn = smb_time_audit_statvfs,
2700         .fs_capabilities_fn = smb_time_audit_fs_capabilities,
2701         .get_dfs_referrals_fn = smb_time_audit_get_dfs_referrals,
2702         .opendir_fn = smb_time_audit_opendir,
2703         .fdopendir_fn = smb_time_audit_fdopendir,
2704         .readdir_fn = smb_time_audit_readdir,
2705         .seekdir_fn = smb_time_audit_seekdir,
2706         .telldir_fn = smb_time_audit_telldir,
2707         .rewind_dir_fn = smb_time_audit_rewinddir,
2708         .mkdir_fn = smb_time_audit_mkdir,
2709         .rmdir_fn = smb_time_audit_rmdir,
2710         .closedir_fn = smb_time_audit_closedir,
2711         .init_search_op_fn = smb_time_audit_init_search_op,
2712         .open_fn = smb_time_audit_open,
2713         .create_file_fn = smb_time_audit_create_file,
2714         .close_fn = smb_time_audit_close,
2715         .read_fn = smb_time_audit_read,
2716         .pread_fn = smb_time_audit_pread,
2717         .pread_send_fn = smb_time_audit_pread_send,
2718         .pread_recv_fn = smb_time_audit_pread_recv,
2719         .write_fn = smb_time_audit_write,
2720         .pwrite_fn = smb_time_audit_pwrite,
2721         .pwrite_send_fn = smb_time_audit_pwrite_send,
2722         .pwrite_recv_fn = smb_time_audit_pwrite_recv,
2723         .lseek_fn = smb_time_audit_lseek,
2724         .sendfile_fn = smb_time_audit_sendfile,
2725         .recvfile_fn = smb_time_audit_recvfile,
2726         .rename_fn = smb_time_audit_rename,
2727         .fsync_fn = smb_time_audit_fsync,
2728         .fsync_send_fn = smb_time_audit_fsync_send,
2729         .fsync_recv_fn = smb_time_audit_fsync_recv,
2730         .stat_fn = smb_time_audit_stat,
2731         .fstat_fn = smb_time_audit_fstat,
2732         .lstat_fn = smb_time_audit_lstat,
2733         .get_alloc_size_fn = smb_time_audit_get_alloc_size,
2734         .unlink_fn = smb_time_audit_unlink,
2735         .chmod_fn = smb_time_audit_chmod,
2736         .fchmod_fn = smb_time_audit_fchmod,
2737         .chown_fn = smb_time_audit_chown,
2738         .fchown_fn = smb_time_audit_fchown,
2739         .lchown_fn = smb_time_audit_lchown,
2740         .chdir_fn = smb_time_audit_chdir,
2741         .getwd_fn = smb_time_audit_getwd,
2742         .ntimes_fn = smb_time_audit_ntimes,
2743         .ftruncate_fn = smb_time_audit_ftruncate,
2744         .fallocate_fn = smb_time_audit_fallocate,
2745         .lock_fn = smb_time_audit_lock,
2746         .kernel_flock_fn = smb_time_audit_kernel_flock,
2747         .linux_setlease_fn = smb_time_audit_linux_setlease,
2748         .getlock_fn = smb_time_audit_getlock,
2749         .symlink_fn = smb_time_audit_symlink,
2750         .readlink_fn = smb_time_audit_readlink,
2751         .link_fn = smb_time_audit_link,
2752         .mknod_fn = smb_time_audit_mknod,
2753         .realpath_fn = smb_time_audit_realpath,
2754         .chflags_fn = smb_time_audit_chflags,
2755         .file_id_create_fn = smb_time_audit_file_id_create,
2756         .offload_read_send_fn = smb_time_audit_offload_read_send,
2757         .offload_read_recv_fn = smb_time_audit_offload_read_recv,
2758         .offload_write_send_fn = smb_time_audit_offload_write_send,
2759         .offload_write_recv_fn = smb_time_audit_offload_write_recv,
2760         .get_compression_fn = smb_time_audit_get_compression,
2761         .set_compression_fn = smb_time_audit_set_compression,
2762         .snap_check_path_fn = smb_time_audit_snap_check_path,
2763         .snap_create_fn = smb_time_audit_snap_create,
2764         .snap_delete_fn = smb_time_audit_snap_delete,
2765         .streaminfo_fn = smb_time_audit_streaminfo,
2766         .get_real_filename_fn = smb_time_audit_get_real_filename,
2767         .connectpath_fn = smb_time_audit_connectpath,
2768         .brl_lock_windows_fn = smb_time_audit_brl_lock_windows,
2769         .brl_unlock_windows_fn = smb_time_audit_brl_unlock_windows,
2770         .brl_cancel_windows_fn = smb_time_audit_brl_cancel_windows,
2771         .strict_lock_check_fn = smb_time_audit_strict_lock_check,
2772         .translate_name_fn = smb_time_audit_translate_name,
2773         .fsctl_fn = smb_time_audit_fsctl,
2774         .get_dos_attributes_fn = smb_time_get_dos_attributes,
2775         .fget_dos_attributes_fn = smb_time_fget_dos_attributes,
2776         .set_dos_attributes_fn = smb_time_set_dos_attributes,
2777         .fset_dos_attributes_fn = smb_time_fset_dos_attributes,
2778         .fget_nt_acl_fn = smb_time_audit_fget_nt_acl,
2779         .get_nt_acl_fn = smb_time_audit_get_nt_acl,
2780         .fset_nt_acl_fn = smb_time_audit_fset_nt_acl,
2781         .audit_file_fn = smb_time_audit_audit_file,
2782         .chmod_acl_fn = smb_time_audit_chmod_acl,
2783         .fchmod_acl_fn = smb_time_audit_fchmod_acl,
2784         .sys_acl_get_file_fn = smb_time_audit_sys_acl_get_file,
2785         .sys_acl_get_fd_fn = smb_time_audit_sys_acl_get_fd,
2786         .sys_acl_blob_get_file_fn = smb_time_audit_sys_acl_blob_get_file,
2787         .sys_acl_blob_get_fd_fn = smb_time_audit_sys_acl_blob_get_fd,
2788         .sys_acl_set_file_fn = smb_time_audit_sys_acl_set_file,
2789         .sys_acl_set_fd_fn = smb_time_audit_sys_acl_set_fd,
2790         .sys_acl_delete_def_file_fn = smb_time_audit_sys_acl_delete_def_file,
2791         .getxattr_fn = smb_time_audit_getxattr,
2792         .fgetxattr_fn = smb_time_audit_fgetxattr,
2793         .listxattr_fn = smb_time_audit_listxattr,
2794         .flistxattr_fn = smb_time_audit_flistxattr,
2795         .removexattr_fn = smb_time_audit_removexattr,
2796         .fremovexattr_fn = smb_time_audit_fremovexattr,
2797         .setxattr_fn = smb_time_audit_setxattr,
2798         .fsetxattr_fn = smb_time_audit_fsetxattr,
2799         .aio_force_fn = smb_time_audit_aio_force,
2800         .durable_cookie_fn = smb_time_audit_durable_cookie,
2801         .durable_disconnect_fn = smb_time_audit_durable_disconnect,
2802         .durable_reconnect_fn = smb_time_audit_durable_reconnect,
2803         .readdir_attr_fn = smb_time_audit_readdir_attr,
2804 };
2805
2806
2807 NTSTATUS vfs_time_audit_init(TALLOC_CTX *);
2808 NTSTATUS vfs_time_audit_init(TALLOC_CTX *ctx)
2809 {
2810         smb_vfs_assert_all_fns(&vfs_time_audit_fns, "time_audit");
2811
2812         audit_timeout = (double)lp_parm_int(-1, "time_audit", "timeout",
2813                                             10000) / 1000.0;
2814         return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "time_audit",
2815                                 &vfs_time_audit_fns);
2816 }