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