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