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