6ceeb2e2e46006301db4bc2572f6e07a5e7f9678
[kai/samba.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
32 #undef DBGC_CLASS
33 #define DBGC_CLASS DBGC_VFS
34
35 static double audit_timeout;
36
37 static void smb_time_audit_log(const char *syscallname, double elapsed)
38 {
39         DEBUG(0, ("WARNING: System call \"%s\" took unexpectedly long "
40                   "(%.2f seconds) -- Validate that file and storage "
41                   "subsystems are operating normally\n", syscallname,
42                   elapsed));
43 }
44
45 static int smb_time_audit_connect(vfs_handle_struct *handle,
46                                   const char *svc, const char *user)
47 {
48         int result;
49         struct timespec ts1,ts2;
50         double timediff;
51
52         if (!handle) {
53                 return -1;
54         }
55
56         clock_gettime_mono(&ts1);
57         result = SMB_VFS_NEXT_CONNECT(handle, svc, user);
58         clock_gettime_mono(&ts2);
59         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
60         if (timediff > audit_timeout) {
61                 smb_time_audit_log("connect", timediff);
62         }
63         return result;
64 }
65
66 static void smb_time_audit_disconnect(vfs_handle_struct *handle)
67 {
68         struct timespec ts1,ts2;
69         double timediff;
70
71         clock_gettime_mono(&ts1);
72         SMB_VFS_NEXT_DISCONNECT(handle);
73         clock_gettime_mono(&ts2);
74         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
75
76         if (timediff > audit_timeout) {
77                 smb_time_audit_log("disconnect", timediff);
78         }
79
80         return;
81 }
82
83 static uint64_t smb_time_audit_disk_free(vfs_handle_struct *handle,
84                                          const char *path,
85                                          bool small_query, uint64_t *bsize,
86                                          uint64_t *dfree, uint64_t *dsize)
87 {
88         uint64_t result;
89         struct timespec ts1,ts2;
90         double timediff;
91
92         clock_gettime_mono(&ts1);
93         result = SMB_VFS_NEXT_DISK_FREE(handle, path, small_query, bsize,
94                                         dfree, dsize);
95         clock_gettime_mono(&ts2);
96         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
97
98         /* Don't have a reasonable notion of failure here */
99         if (timediff > audit_timeout) {
100                 smb_time_audit_log("disk_free", timediff);
101         }
102
103         return result;
104 }
105
106 static int smb_time_audit_get_quota(struct vfs_handle_struct *handle,
107                                     enum SMB_QUOTA_TYPE qtype, unid_t id,
108                                     SMB_DISK_QUOTA *qt)
109 {
110         int result;
111         struct timespec ts1,ts2;
112         double timediff;
113
114         clock_gettime_mono(&ts1);
115         result = SMB_VFS_NEXT_GET_QUOTA(handle, qtype, id, qt);
116         clock_gettime_mono(&ts2);
117         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
118
119         if (timediff > audit_timeout) {
120                 smb_time_audit_log("get_quota", timediff);
121         }
122         return result;
123 }
124
125 static int smb_time_audit_set_quota(struct vfs_handle_struct *handle,
126                                     enum SMB_QUOTA_TYPE qtype, unid_t id,
127                                     SMB_DISK_QUOTA *qt)
128 {
129         int result;
130         struct timespec ts1,ts2;
131         double timediff;
132
133         clock_gettime_mono(&ts1);
134         result = SMB_VFS_NEXT_SET_QUOTA(handle, qtype, id, qt);
135         clock_gettime_mono(&ts2);
136         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
137
138         if (timediff > audit_timeout) {
139                 smb_time_audit_log("set_quota", timediff);
140         }
141
142         return result;
143 }
144
145 static int smb_time_audit_get_shadow_copy_data(struct vfs_handle_struct *handle,
146                                                struct files_struct *fsp,
147                                                SHADOW_COPY_DATA *shadow_copy_data,
148                                                bool labels)
149 {
150         int result;
151         struct timespec ts1,ts2;
152         double timediff;
153
154         clock_gettime_mono(&ts1);
155         result = SMB_VFS_NEXT_GET_SHADOW_COPY_DATA(handle, fsp,
156                                                    shadow_copy_data, labels);
157         clock_gettime_mono(&ts2);
158         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
159
160         if (timediff > audit_timeout) {
161                 smb_time_audit_log("get_shadow_copy_data", timediff);
162         }
163
164         return result;
165 }
166
167 static int smb_time_audit_statvfs(struct vfs_handle_struct *handle,
168                                   const char *path,
169                                   struct vfs_statvfs_struct *statbuf)
170 {
171         int result;
172         struct timespec ts1,ts2;
173         double timediff;
174
175         clock_gettime_mono(&ts1);
176         result = SMB_VFS_NEXT_STATVFS(handle, path, statbuf);
177         clock_gettime_mono(&ts2);
178         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
179
180         if (timediff > audit_timeout) {
181                 smb_time_audit_log("statvfs", timediff);
182         }
183
184         return result;
185 }
186
187 static uint32_t smb_time_audit_fs_capabilities(struct vfs_handle_struct *handle,
188                                                enum timestamp_set_resolution *p_ts_res)
189 {
190         uint32_t result;
191         struct timespec ts1,ts2;
192         double timediff;
193
194         clock_gettime_mono(&ts1);
195         result = SMB_VFS_NEXT_FS_CAPABILITIES(handle, p_ts_res);
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("fs_capabilities", timediff);
201         }
202
203         return result;
204 }
205
206 static SMB_STRUCT_DIR *smb_time_audit_opendir(vfs_handle_struct *handle,
207                                               const char *fname,
208                                               const char *mask, uint32 attr)
209 {
210         SMB_STRUCT_DIR *result;
211         struct timespec ts1,ts2;
212         double timediff;
213
214         clock_gettime_mono(&ts1);
215         result = SMB_VFS_NEXT_OPENDIR(handle, fname, mask, attr);
216         clock_gettime_mono(&ts2);
217         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
218
219         if (timediff > audit_timeout) {
220                 smb_time_audit_log("opendir", timediff);
221         }
222
223         return result;
224 }
225
226 static SMB_STRUCT_DIR *smb_time_audit_fdopendir(vfs_handle_struct *handle,
227                                               files_struct *fsp,
228                                               const char *mask, uint32 attr)
229 {
230         SMB_STRUCT_DIR *result;
231         struct timespec ts1,ts2;
232         double timediff;
233
234         clock_gettime_mono(&ts1);
235         result = SMB_VFS_NEXT_FDOPENDIR(handle, fsp, mask, attr);
236         clock_gettime_mono(&ts2);
237         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
238
239         if (timediff > audit_timeout) {
240                 smb_time_audit_log("fdopendir", timediff);
241         }
242
243         return result;
244 }
245
246 static SMB_STRUCT_DIRENT *smb_time_audit_readdir(vfs_handle_struct *handle,
247                                                  SMB_STRUCT_DIR *dirp,
248                                                  SMB_STRUCT_STAT *sbuf)
249 {
250         SMB_STRUCT_DIRENT *result;
251         struct timespec ts1,ts2;
252         double timediff;
253
254         clock_gettime_mono(&ts1);
255         result = SMB_VFS_NEXT_READDIR(handle, dirp, sbuf);
256         clock_gettime_mono(&ts2);
257         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
258
259         if (timediff > audit_timeout) {
260                 smb_time_audit_log("readdir", timediff);
261         }
262
263         return result;
264 }
265
266 static void smb_time_audit_seekdir(vfs_handle_struct *handle,
267                                    SMB_STRUCT_DIR *dirp, long offset)
268 {
269         struct timespec ts1,ts2;
270         double timediff;
271
272         clock_gettime_mono(&ts1);
273         SMB_VFS_NEXT_SEEKDIR(handle, dirp, offset);
274         clock_gettime_mono(&ts2);
275         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
276
277         if (timediff > audit_timeout) {
278                 smb_time_audit_log("seekdir", timediff);
279         }
280
281         return;
282 }
283
284 static long smb_time_audit_telldir(vfs_handle_struct *handle,
285                                    SMB_STRUCT_DIR *dirp)
286 {
287         long result;
288         struct timespec ts1,ts2;
289         double timediff;
290
291         clock_gettime_mono(&ts1);
292         result = SMB_VFS_NEXT_TELLDIR(handle, dirp);
293         clock_gettime_mono(&ts2);
294         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
295
296         if (timediff > audit_timeout) {
297                 smb_time_audit_log("telldir", timediff);
298         }
299
300         return result;
301 }
302
303 static void smb_time_audit_rewinddir(vfs_handle_struct *handle,
304                                      SMB_STRUCT_DIR *dirp)
305 {
306         struct timespec ts1,ts2;
307         double timediff;
308
309         clock_gettime_mono(&ts1);
310         SMB_VFS_NEXT_REWINDDIR(handle, dirp);
311         clock_gettime_mono(&ts2);
312         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
313
314         if (timediff > audit_timeout) {
315                 smb_time_audit_log("rewinddir", timediff);
316         }
317
318         return;
319 }
320
321 static int smb_time_audit_mkdir(vfs_handle_struct *handle,
322                                 const char *path, mode_t mode)
323 {
324         int result;
325         struct timespec ts1,ts2;
326         double timediff;
327
328         clock_gettime_mono(&ts1);
329         result = SMB_VFS_NEXT_MKDIR(handle, path, mode);
330         clock_gettime_mono(&ts2);
331         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
332
333         if (timediff > audit_timeout) {
334                 smb_time_audit_log("mkdir", timediff);
335         }
336
337         return result;
338 }
339
340 static int smb_time_audit_rmdir(vfs_handle_struct *handle,
341                                 const char *path)
342 {
343         int result;
344         struct timespec ts1,ts2;
345         double timediff;
346
347         clock_gettime_mono(&ts1);
348         result = SMB_VFS_NEXT_RMDIR(handle, path);
349         clock_gettime_mono(&ts2);
350         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
351
352         if (timediff > audit_timeout) {
353                 smb_time_audit_log("rmdir", timediff);
354         }
355
356         return result;
357 }
358
359 static int smb_time_audit_closedir(vfs_handle_struct *handle,
360                                    SMB_STRUCT_DIR *dirp)
361 {
362         int result;
363         struct timespec ts1,ts2;
364         double timediff;
365
366         clock_gettime_mono(&ts1);
367         result = SMB_VFS_NEXT_CLOSEDIR(handle, dirp);
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("closedir", timediff);
373         }
374
375         return result;
376 }
377
378 static void smb_time_audit_init_search_op(vfs_handle_struct *handle,
379                                           SMB_STRUCT_DIR *dirp)
380 {
381         struct timespec ts1,ts2;
382         double timediff;
383
384         clock_gettime_mono(&ts1);
385         SMB_VFS_NEXT_INIT_SEARCH_OP(handle, dirp);
386         clock_gettime_mono(&ts2);
387         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
388
389         if (timediff > audit_timeout) {
390                 smb_time_audit_log("init_search_op", timediff);
391         }
392         return;
393 }
394
395 static int smb_time_audit_open(vfs_handle_struct *handle,
396                                struct smb_filename *fname,
397                                files_struct *fsp,
398                                int flags, mode_t mode)
399 {
400         int result;
401         struct timespec ts1,ts2;
402         double timediff;
403
404         clock_gettime_mono(&ts1);
405         result = SMB_VFS_NEXT_OPEN(handle, fname, fsp, flags, mode);
406         clock_gettime_mono(&ts2);
407         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
408
409         if (timediff > audit_timeout) {
410                 smb_time_audit_log("open", timediff);
411         }
412
413         return result;
414 }
415
416 static NTSTATUS smb_time_audit_create_file(vfs_handle_struct *handle,
417                                            struct smb_request *req,
418                                            uint16_t root_dir_fid,
419                                            struct smb_filename *fname,
420                                            uint32_t access_mask,
421                                            uint32_t share_access,
422                                            uint32_t create_disposition,
423                                            uint32_t create_options,
424                                            uint32_t file_attributes,
425                                            uint32_t oplock_request,
426                                            uint64_t allocation_size,
427                                            uint32_t private_flags,
428                                            struct security_descriptor *sd,
429                                            struct ea_list *ea_list,
430                                            files_struct **result_fsp,
431                                            int *pinfo)
432 {
433         NTSTATUS result;
434         struct timespec ts1,ts2;
435         double timediff;
436
437         clock_gettime_mono(&ts1);
438         result = SMB_VFS_NEXT_CREATE_FILE(
439                 handle,                                 /* handle */
440                 req,                                    /* req */
441                 root_dir_fid,                           /* root_dir_fid */
442                 fname,                                  /* fname */
443                 access_mask,                            /* access_mask */
444                 share_access,                           /* share_access */
445                 create_disposition,                     /* create_disposition*/
446                 create_options,                         /* create_options */
447                 file_attributes,                        /* file_attributes */
448                 oplock_request,                         /* oplock_request */
449                 allocation_size,                        /* allocation_size */
450                 private_flags,
451                 sd,                                     /* sd */
452                 ea_list,                                /* ea_list */
453                 result_fsp,                             /* result */
454                 pinfo);
455         clock_gettime_mono(&ts2);
456         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
457
458         if (timediff > audit_timeout) {
459                 smb_time_audit_log("create_file", timediff);
460         }
461
462         return result;
463 }
464
465 static int smb_time_audit_close(vfs_handle_struct *handle, files_struct *fsp)
466 {
467         int result;
468         struct timespec ts1,ts2;
469         double timediff;
470
471         clock_gettime_mono(&ts1);
472         result = SMB_VFS_NEXT_CLOSE(handle, fsp);
473         clock_gettime_mono(&ts2);
474         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
475
476         if (timediff > audit_timeout) {
477                 smb_time_audit_log("close", timediff);
478         }
479
480         return result;
481 }
482
483 static ssize_t smb_time_audit_read(vfs_handle_struct *handle,
484                                    files_struct *fsp, void *data, size_t n)
485 {
486         ssize_t result;
487         struct timespec ts1,ts2;
488         double timediff;
489
490         clock_gettime_mono(&ts1);
491         result = SMB_VFS_NEXT_READ(handle, fsp, data, n);
492         clock_gettime_mono(&ts2);
493         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
494
495         if (timediff > audit_timeout) {
496                 smb_time_audit_log("read", timediff);
497         }
498
499         return result;
500 }
501
502 static ssize_t smb_time_audit_pread(vfs_handle_struct *handle,
503                                     files_struct *fsp,
504                                     void *data, size_t n, SMB_OFF_T offset)
505 {
506         ssize_t result;
507         struct timespec ts1,ts2;
508         double timediff;
509
510         clock_gettime_mono(&ts1);
511         result = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
512         clock_gettime_mono(&ts2);
513         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
514
515         if (timediff > audit_timeout) {
516                 smb_time_audit_log("pread", timediff);
517         }
518
519         return result;
520 }
521
522 static ssize_t smb_time_audit_write(vfs_handle_struct *handle,
523                                     files_struct *fsp,
524                                     const void *data, size_t n)
525 {
526         ssize_t result;
527         struct timespec ts1,ts2;
528         double timediff;
529
530         clock_gettime_mono(&ts1);
531         result = SMB_VFS_NEXT_WRITE(handle, fsp, data, n);
532         clock_gettime_mono(&ts2);
533         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
534
535         if (timediff > audit_timeout) {
536                 smb_time_audit_log("write", timediff);
537         }
538
539         return result;
540 }
541
542 static ssize_t smb_time_audit_pwrite(vfs_handle_struct *handle,
543                                      files_struct *fsp,
544                                      const void *data, size_t n,
545                                      SMB_OFF_T offset)
546 {
547         ssize_t result;
548         struct timespec ts1,ts2;
549         double timediff;
550
551         clock_gettime_mono(&ts1);
552         result = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
553         clock_gettime_mono(&ts2);
554         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
555
556         if (timediff > audit_timeout) {
557                 smb_time_audit_log("pwrite", timediff);
558         }
559
560         return result;
561 }
562
563 static SMB_OFF_T smb_time_audit_lseek(vfs_handle_struct *handle,
564                                       files_struct *fsp,
565                                       SMB_OFF_T offset, int whence)
566 {
567         ssize_t result;
568         struct timespec ts1,ts2;
569         double timediff;
570
571         clock_gettime_mono(&ts1);
572         result = SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence);
573         clock_gettime_mono(&ts2);
574         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
575
576         if (timediff > audit_timeout) {
577                 smb_time_audit_log("lseek", timediff);
578         }
579
580         return result;
581 }
582
583 static ssize_t smb_time_audit_sendfile(vfs_handle_struct *handle, int tofd,
584                                        files_struct *fromfsp,
585                                        const DATA_BLOB *hdr, SMB_OFF_T offset,
586                                        size_t n)
587 {
588         ssize_t result;
589         struct timespec ts1,ts2;
590         double timediff;
591
592         clock_gettime_mono(&ts1);
593         result = SMB_VFS_NEXT_SENDFILE(handle, tofd, fromfsp, hdr, offset, n);
594         clock_gettime_mono(&ts2);
595         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
596
597         if (timediff > audit_timeout) {
598                 smb_time_audit_log("sendfile", timediff);
599         }
600
601         return result;
602 }
603
604 static ssize_t smb_time_audit_recvfile(vfs_handle_struct *handle, int fromfd,
605                                        files_struct *tofsp,
606                                        SMB_OFF_T offset,
607                                        size_t n)
608 {
609         ssize_t result;
610         struct timespec ts1,ts2;
611         double timediff;
612
613         clock_gettime_mono(&ts1);
614         result = SMB_VFS_NEXT_RECVFILE(handle, fromfd, tofsp, offset, n);
615         clock_gettime_mono(&ts2);
616         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
617
618         if (timediff > audit_timeout) {
619                 smb_time_audit_log("recvfile", timediff);
620         }
621
622         return result;
623 }
624
625 static int smb_time_audit_rename(vfs_handle_struct *handle,
626                                  const struct smb_filename *oldname,
627                                  const struct smb_filename *newname)
628 {
629         int result;
630         struct timespec ts1,ts2;
631         double timediff;
632
633         clock_gettime_mono(&ts1);
634         result = SMB_VFS_NEXT_RENAME(handle, oldname, newname);
635         clock_gettime_mono(&ts2);
636         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
637
638         if (timediff > audit_timeout) {
639                 smb_time_audit_log("rename", timediff);
640         }
641
642         return result;
643 }
644
645 static int smb_time_audit_fsync(vfs_handle_struct *handle, files_struct *fsp)
646 {
647         int result;
648         struct timespec ts1,ts2;
649         double timediff;
650
651         clock_gettime_mono(&ts1);
652         result = SMB_VFS_NEXT_FSYNC(handle, fsp);
653         clock_gettime_mono(&ts2);
654         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
655
656         if (timediff > audit_timeout) {
657                 smb_time_audit_log("fsync", timediff);
658         }
659
660         return result;
661 }
662
663 static int smb_time_audit_stat(vfs_handle_struct *handle,
664                                struct smb_filename *fname)
665 {
666         int result;
667         struct timespec ts1,ts2;
668         double timediff;
669
670         clock_gettime_mono(&ts1);
671         result = SMB_VFS_NEXT_STAT(handle, fname);
672         clock_gettime_mono(&ts2);
673         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
674
675         if (timediff > audit_timeout) {
676                 smb_time_audit_log("stat", timediff);
677         }
678
679         return result;
680 }
681
682 static int smb_time_audit_fstat(vfs_handle_struct *handle, files_struct *fsp,
683                                 SMB_STRUCT_STAT *sbuf)
684 {
685         int result;
686         struct timespec ts1,ts2;
687         double timediff;
688
689         clock_gettime_mono(&ts1);
690         result = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
691         clock_gettime_mono(&ts2);
692         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
693
694         if (timediff > audit_timeout) {
695                 smb_time_audit_log("fstat", timediff);
696         }
697
698         return result;
699 }
700
701 static int smb_time_audit_lstat(vfs_handle_struct *handle,
702                                 struct smb_filename *path)
703 {
704         int result;
705         struct timespec ts1,ts2;
706         double timediff;
707
708         clock_gettime_mono(&ts1);
709         result = SMB_VFS_NEXT_LSTAT(handle, path);
710         clock_gettime_mono(&ts2);
711         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
712
713         if (timediff > audit_timeout) {
714                 smb_time_audit_log("lstat", timediff);
715         }
716
717         return result;
718 }
719
720 static uint64_t smb_time_audit_get_alloc_size(vfs_handle_struct *handle,
721                                               files_struct *fsp,
722                                               const SMB_STRUCT_STAT *sbuf)
723 {
724         int result;
725         struct timespec ts1,ts2;
726         double timediff;
727
728         clock_gettime_mono(&ts1);
729         result = SMB_VFS_NEXT_GET_ALLOC_SIZE(handle, fsp, sbuf);
730         clock_gettime_mono(&ts2);
731         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
732
733         if (timediff > audit_timeout) {
734                 smb_time_audit_log("get_alloc_size", timediff);
735         }
736
737         return result;
738 }
739
740 static int smb_time_audit_unlink(vfs_handle_struct *handle,
741                                  const struct smb_filename *path)
742 {
743         int result;
744         struct timespec ts1,ts2;
745         double timediff;
746
747         clock_gettime_mono(&ts1);
748         result = SMB_VFS_NEXT_UNLINK(handle, path);
749         clock_gettime_mono(&ts2);
750         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
751
752         if (timediff > audit_timeout) {
753                 smb_time_audit_log("unlink", timediff);
754         }
755
756         return result;
757 }
758
759 static int smb_time_audit_chmod(vfs_handle_struct *handle,
760                                 const char *path, mode_t mode)
761 {
762         int result;
763         struct timespec ts1,ts2;
764         double timediff;
765
766         clock_gettime_mono(&ts1);
767         result = SMB_VFS_NEXT_CHMOD(handle, path, mode);
768         clock_gettime_mono(&ts2);
769         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
770
771         if (timediff > audit_timeout) {
772                 smb_time_audit_log("chmod", timediff);
773         }
774
775         return result;
776 }
777
778 static int smb_time_audit_fchmod(vfs_handle_struct *handle, files_struct *fsp,
779                                  mode_t mode)
780 {
781         int result;
782         struct timespec ts1,ts2;
783         double timediff;
784
785         clock_gettime_mono(&ts1);
786         result = SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
787         clock_gettime_mono(&ts2);
788         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
789
790         if (timediff > audit_timeout) {
791                 smb_time_audit_log("fchmod", timediff);
792         }
793
794         return result;
795 }
796
797 static int smb_time_audit_chown(vfs_handle_struct *handle,
798                                 const char *path, uid_t uid, gid_t gid)
799 {
800         int result;
801         struct timespec ts1,ts2;
802         double timediff;
803
804         clock_gettime_mono(&ts1);
805         result = SMB_VFS_NEXT_CHOWN(handle, path, uid, gid);
806         clock_gettime_mono(&ts2);
807         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
808
809         if (timediff > audit_timeout) {
810                 smb_time_audit_log("chown", timediff);
811         }
812
813         return result;
814 }
815
816 static int smb_time_audit_fchown(vfs_handle_struct *handle, files_struct *fsp,
817                                  uid_t uid, gid_t gid)
818 {
819         int result;
820         struct timespec ts1,ts2;
821         double timediff;
822
823         clock_gettime_mono(&ts1);
824         result = SMB_VFS_NEXT_FCHOWN(handle, fsp, uid, gid);
825         clock_gettime_mono(&ts2);
826         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
827
828         if (timediff > audit_timeout) {
829                 smb_time_audit_log("fchown", timediff);
830         }
831
832         return result;
833 }
834
835 static int smb_time_audit_lchown(vfs_handle_struct *handle,
836                                  const char *path, uid_t uid, gid_t gid)
837 {
838         int result;
839         struct timespec ts1,ts2;
840         double timediff;
841
842         clock_gettime_mono(&ts1);
843         result = SMB_VFS_NEXT_LCHOWN(handle, path, uid, gid);
844         clock_gettime_mono(&ts2);
845         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
846
847         if (timediff > audit_timeout) {
848                 smb_time_audit_log("lchown", timediff);
849         }
850
851         return result;
852 }
853
854 static int smb_time_audit_chdir(vfs_handle_struct *handle, const char *path)
855 {
856         int result;
857         struct timespec ts1,ts2;
858         double timediff;
859
860         clock_gettime_mono(&ts1);
861         result = SMB_VFS_NEXT_CHDIR(handle, path);
862         clock_gettime_mono(&ts2);
863         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
864
865         if (timediff > audit_timeout) {
866                 smb_time_audit_log("chdir", timediff);
867         }
868
869         return result;
870 }
871
872 static char *smb_time_audit_getwd(vfs_handle_struct *handle, char *path)
873 {
874         char *result;
875         struct timespec ts1,ts2;
876         double timediff;
877
878         clock_gettime_mono(&ts1);
879         result = SMB_VFS_NEXT_GETWD(handle, path);
880         clock_gettime_mono(&ts2);
881         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
882
883         if (timediff > audit_timeout) {
884                 smb_time_audit_log("getwd", timediff);
885         }
886
887         return result;
888 }
889
890 static int smb_time_audit_ntimes(vfs_handle_struct *handle,
891                                  const struct smb_filename *path,
892                                  struct smb_file_time *ft)
893 {
894         int result;
895         struct timespec ts1,ts2;
896         double timediff;
897
898         clock_gettime_mono(&ts1);
899         result = SMB_VFS_NEXT_NTIMES(handle, path, ft);
900         clock_gettime_mono(&ts2);
901         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
902
903         if (timediff > audit_timeout) {
904                 smb_time_audit_log("ntimes", timediff);
905         }
906
907         return result;
908 }
909
910 static int smb_time_audit_ftruncate(vfs_handle_struct *handle,
911                                     files_struct *fsp,
912                                     SMB_OFF_T len)
913 {
914         int result;
915         struct timespec ts1,ts2;
916         double timediff;
917
918         clock_gettime_mono(&ts1);
919         result = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
920         clock_gettime_mono(&ts2);
921         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
922
923         if (timediff > audit_timeout) {
924                 smb_time_audit_log("ftruncate", timediff);
925         }
926
927         return result;
928 }
929
930 static int smb_time_audit_fallocate(vfs_handle_struct *handle,
931                                     files_struct *fsp,
932                                     enum vfs_fallocate_mode mode,
933                                     SMB_OFF_T offset,
934                                     SMB_OFF_T len)
935 {
936         int result;
937         struct timespec ts1,ts2;
938         double timediff;
939
940         clock_gettime_mono(&ts1);
941         result = SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
942         clock_gettime_mono(&ts2);
943         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
944
945         if (timediff > audit_timeout) {
946                 smb_time_audit_log("fallocate", timediff);
947         }
948
949         return result;
950 }
951
952 static bool smb_time_audit_lock(vfs_handle_struct *handle, files_struct *fsp,
953                                 int op, SMB_OFF_T offset, SMB_OFF_T count,
954                                 int type)
955 {
956         bool result;
957         struct timespec ts1,ts2;
958         double timediff;
959
960         clock_gettime_mono(&ts1);
961         result = SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type);
962         clock_gettime_mono(&ts2);
963         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
964
965         if (timediff > audit_timeout) {
966                 smb_time_audit_log("lock", timediff);
967         }
968
969         return result;
970 }
971
972 static int smb_time_audit_kernel_flock(struct vfs_handle_struct *handle,
973                                        struct files_struct *fsp,
974                                        uint32 share_mode, uint32 access_mask)
975 {
976         int result;
977         struct timespec ts1,ts2;
978         double timediff;
979
980         clock_gettime_mono(&ts1);
981         result = SMB_VFS_NEXT_KERNEL_FLOCK(handle, fsp, share_mode,
982                                            access_mask);
983         clock_gettime_mono(&ts2);
984         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
985
986         if (timediff > audit_timeout) {
987                 smb_time_audit_log("kernel_flock", timediff);
988         }
989
990         return result;
991 }
992
993 static int smb_time_audit_linux_setlease(vfs_handle_struct *handle,
994                                          files_struct *fsp,
995                                          int leasetype)
996 {
997         int result;
998         struct timespec ts1,ts2;
999         double timediff;
1000
1001         clock_gettime_mono(&ts1);
1002         result = SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
1003         clock_gettime_mono(&ts2);
1004         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1005
1006         if (timediff > audit_timeout) {
1007                 smb_time_audit_log("linux_setlease", timediff);
1008         }
1009
1010         return result;
1011 }
1012
1013 static bool smb_time_audit_getlock(vfs_handle_struct *handle,
1014                                    files_struct *fsp,
1015                                    SMB_OFF_T *poffset, SMB_OFF_T *pcount,
1016                                    int *ptype, pid_t *ppid)
1017 {
1018         bool result;
1019         struct timespec ts1,ts2;
1020         double timediff;
1021
1022         clock_gettime_mono(&ts1);
1023         result = SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype,
1024                                       ppid);
1025         clock_gettime_mono(&ts2);
1026         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1027
1028         if (timediff > audit_timeout) {
1029                 smb_time_audit_log("getlock", timediff);
1030         }
1031
1032         return result;
1033 }
1034
1035 static int smb_time_audit_symlink(vfs_handle_struct *handle,
1036                                   const char *oldpath, const char *newpath)
1037 {
1038         int result;
1039         struct timespec ts1,ts2;
1040         double timediff;
1041
1042         clock_gettime_mono(&ts1);
1043         result = SMB_VFS_NEXT_SYMLINK(handle, oldpath, newpath);
1044         clock_gettime_mono(&ts2);
1045         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1046
1047         if (timediff > audit_timeout) {
1048                 smb_time_audit_log("symlink", timediff);
1049         }
1050
1051         return result;
1052 }
1053
1054 static int smb_time_audit_readlink(vfs_handle_struct *handle,
1055                           const char *path, char *buf, size_t bufsiz)
1056 {
1057         int result;
1058         struct timespec ts1,ts2;
1059         double timediff;
1060
1061         clock_gettime_mono(&ts1);
1062         result = SMB_VFS_NEXT_READLINK(handle, path, buf, bufsiz);
1063         clock_gettime_mono(&ts2);
1064         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1065
1066         if (timediff > audit_timeout) {
1067                 smb_time_audit_log("readlink", timediff);
1068         }
1069
1070         return result;
1071 }
1072
1073 static int smb_time_audit_link(vfs_handle_struct *handle,
1074                                const char *oldpath, const char *newpath)
1075 {
1076         int result;
1077         struct timespec ts1,ts2;
1078         double timediff;
1079
1080         clock_gettime_mono(&ts1);
1081         result = SMB_VFS_NEXT_LINK(handle, oldpath, newpath);
1082         clock_gettime_mono(&ts2);
1083         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1084
1085         if (timediff > audit_timeout) {
1086                 smb_time_audit_log("link", timediff);
1087         }
1088
1089         return result;
1090 }
1091
1092 static int smb_time_audit_mknod(vfs_handle_struct *handle,
1093                                 const char *pathname, mode_t mode,
1094                                 SMB_DEV_T dev)
1095 {
1096         int result;
1097         struct timespec ts1,ts2;
1098         double timediff;
1099
1100         clock_gettime_mono(&ts1);
1101         result = SMB_VFS_NEXT_MKNOD(handle, pathname, mode, dev);
1102         clock_gettime_mono(&ts2);
1103         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1104
1105         if (timediff > audit_timeout) {
1106                 smb_time_audit_log("mknod", timediff);
1107         }
1108
1109         return result;
1110 }
1111
1112 static char *smb_time_audit_realpath(vfs_handle_struct *handle,
1113                                      const char *path)
1114 {
1115         char *result;
1116         struct timespec ts1,ts2;
1117         double timediff;
1118
1119         clock_gettime_mono(&ts1);
1120         result = SMB_VFS_NEXT_REALPATH(handle, path);
1121         clock_gettime_mono(&ts2);
1122         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1123
1124         if (timediff > audit_timeout) {
1125                 smb_time_audit_log("realpath", timediff);
1126         }
1127
1128         return result;
1129 }
1130
1131 static NTSTATUS smb_time_audit_notify_watch(struct vfs_handle_struct *handle,
1132                         struct sys_notify_context *ctx,
1133                         struct notify_entry *e,
1134                         void (*callback)(struct sys_notify_context *ctx,
1135                                         void *private_data,
1136                                         struct notify_event *ev),
1137                         void *private_data, void *handle_p)
1138 {
1139         NTSTATUS result;
1140         struct timespec ts1,ts2;
1141         double timediff;
1142
1143         clock_gettime_mono(&ts1);
1144         result = SMB_VFS_NEXT_NOTIFY_WATCH(handle, ctx, e, callback,
1145                                            private_data, handle_p);
1146         clock_gettime_mono(&ts2);
1147         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1148
1149         if (timediff > audit_timeout) {
1150                 smb_time_audit_log("notify_watch", timediff);
1151         }
1152
1153         return result;
1154 }
1155
1156 static int smb_time_audit_chflags(vfs_handle_struct *handle,
1157                                   const char *path, unsigned int flags)
1158 {
1159         int result;
1160         struct timespec ts1,ts2;
1161         double timediff;
1162
1163         clock_gettime_mono(&ts1);
1164         result = SMB_VFS_NEXT_CHFLAGS(handle, path, flags);
1165         clock_gettime_mono(&ts2);
1166         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1167
1168         if (timediff > audit_timeout) {
1169                 smb_time_audit_log("chflags", timediff);
1170         }
1171
1172         return result;
1173 }
1174
1175 static struct file_id smb_time_audit_file_id_create(struct vfs_handle_struct *handle,
1176                                                     const SMB_STRUCT_STAT *sbuf)
1177 {
1178         struct file_id id_zero;
1179         struct file_id result;
1180         struct timespec ts1,ts2;
1181         double timediff;
1182
1183         ZERO_STRUCT(id_zero);
1184
1185         clock_gettime_mono(&ts1);
1186         result = SMB_VFS_NEXT_FILE_ID_CREATE(handle, sbuf);
1187         clock_gettime_mono(&ts2);
1188         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1189
1190         if (timediff > audit_timeout) {
1191                 smb_time_audit_log("file_id_create", timediff);
1192         }
1193
1194         return result;
1195 }
1196
1197 static NTSTATUS smb_time_audit_streaminfo(vfs_handle_struct *handle,
1198                                           struct files_struct *fsp,
1199                                           const char *fname,
1200                                           TALLOC_CTX *mem_ctx,
1201                                           unsigned int *pnum_streams,
1202                                           struct stream_struct **pstreams)
1203 {
1204         NTSTATUS result;
1205         struct timespec ts1,ts2;
1206         double timediff;
1207
1208         clock_gettime_mono(&ts1);
1209         result = SMB_VFS_NEXT_STREAMINFO(handle, fsp, fname, mem_ctx,
1210                                          pnum_streams, pstreams);
1211         clock_gettime_mono(&ts2);
1212         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1213
1214         if (timediff > audit_timeout) {
1215                 smb_time_audit_log("streaminfo", timediff);
1216         }
1217
1218         return result;
1219 }
1220
1221 static int smb_time_audit_get_real_filename(struct vfs_handle_struct *handle,
1222                                             const char *path,
1223                                             const char *name,
1224                                             TALLOC_CTX *mem_ctx,
1225                                             char **found_name)
1226 {
1227         int result;
1228         struct timespec ts1,ts2;
1229         double timediff;
1230
1231         clock_gettime_mono(&ts1);
1232         result = SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name, mem_ctx,
1233                                                 found_name);
1234         clock_gettime_mono(&ts2);
1235         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1236
1237         if (timediff > audit_timeout) {
1238                 smb_time_audit_log("get_real_filename", timediff);
1239         }
1240
1241         return result;
1242 }
1243
1244 static const char *smb_time_audit_connectpath(vfs_handle_struct *handle,
1245                                               const char *fname)
1246 {
1247         const char *result;
1248         struct timespec ts1,ts2;
1249         double timediff;
1250
1251         clock_gettime_mono(&ts1);
1252         result = SMB_VFS_NEXT_CONNECTPATH(handle, fname);
1253         clock_gettime_mono(&ts2);
1254         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1255
1256         if (timediff > audit_timeout) {
1257                 smb_time_audit_log("connectpath", timediff);
1258         }
1259
1260         return result;
1261 }
1262
1263 static NTSTATUS smb_time_audit_brl_lock_windows(struct vfs_handle_struct *handle,
1264                                                 struct byte_range_lock *br_lck,
1265                                                 struct lock_struct *plock,
1266                                                 bool blocking_lock,
1267                                                 struct blocking_lock_record *blr)
1268 {
1269         NTSTATUS result;
1270         struct timespec ts1,ts2;
1271         double timediff;
1272
1273         clock_gettime_mono(&ts1);
1274         result = SMB_VFS_NEXT_BRL_LOCK_WINDOWS(handle, br_lck, plock,
1275                                                blocking_lock, blr);
1276         clock_gettime_mono(&ts2);
1277         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1278
1279         if (timediff > audit_timeout) {
1280                 smb_time_audit_log("brl_lock_windows", timediff);
1281         }
1282
1283         return result;
1284 }
1285
1286 static bool smb_time_audit_brl_unlock_windows(struct vfs_handle_struct *handle,
1287                                               struct messaging_context *msg_ctx,
1288                                               struct byte_range_lock *br_lck,
1289                                               const struct lock_struct *plock)
1290 {
1291         bool result;
1292         struct timespec ts1,ts2;
1293         double timediff;
1294
1295         clock_gettime_mono(&ts1);
1296         result = SMB_VFS_NEXT_BRL_UNLOCK_WINDOWS(handle, msg_ctx, br_lck,
1297                                                  plock);
1298         clock_gettime_mono(&ts2);
1299         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1300
1301         if (timediff > audit_timeout) {
1302                 smb_time_audit_log("brl_unlock_windows", timediff);
1303         }
1304
1305         return result;
1306 }
1307
1308 static bool smb_time_audit_brl_cancel_windows(struct vfs_handle_struct *handle,
1309                                               struct byte_range_lock *br_lck,
1310                                               struct lock_struct *plock,
1311                                               struct blocking_lock_record *blr)
1312 {
1313         bool result;
1314         struct timespec ts1,ts2;
1315         double timediff;
1316
1317         clock_gettime_mono(&ts1);
1318         result = SMB_VFS_NEXT_BRL_CANCEL_WINDOWS(handle, br_lck, plock, blr);
1319         clock_gettime_mono(&ts2);
1320         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1321
1322         if (timediff > audit_timeout) {
1323                 smb_time_audit_log("brl_cancel_windows", timediff);
1324         }
1325
1326         return result;
1327 }
1328
1329 static bool smb_time_audit_strict_lock(struct vfs_handle_struct *handle,
1330                                        struct files_struct *fsp,
1331                                        struct lock_struct *plock)
1332 {
1333         bool result;
1334         struct timespec ts1,ts2;
1335         double timediff;
1336
1337         clock_gettime_mono(&ts1);
1338         result = SMB_VFS_NEXT_STRICT_LOCK(handle, fsp, plock);
1339         clock_gettime_mono(&ts2);
1340         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1341
1342         if (timediff > audit_timeout) {
1343                 smb_time_audit_log("strict_lock", timediff);
1344         }
1345
1346         return result;
1347 }
1348
1349 static void smb_time_audit_strict_unlock(struct vfs_handle_struct *handle,
1350                                          struct files_struct *fsp,
1351                                          struct lock_struct *plock)
1352 {
1353         struct timespec ts1,ts2;
1354         double timediff;
1355
1356         clock_gettime_mono(&ts1);
1357         SMB_VFS_NEXT_STRICT_UNLOCK(handle, fsp, plock);
1358         clock_gettime_mono(&ts2);
1359         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1360
1361         if (timediff > audit_timeout) {
1362                 smb_time_audit_log("strict_unlock", timediff);
1363         }
1364
1365         return;
1366 }
1367
1368 static NTSTATUS smb_time_audit_translate_name(struct vfs_handle_struct *handle,
1369                                               const char *name,
1370                                               enum vfs_translate_direction direction,
1371                                               TALLOC_CTX *mem_ctx,
1372                                               char **mapped_name)
1373 {
1374         NTSTATUS result;
1375         struct timespec ts1,ts2;
1376         double timediff;
1377
1378         clock_gettime_mono(&ts1);
1379         result = SMB_VFS_NEXT_TRANSLATE_NAME(handle, name, direction, mem_ctx,
1380                                              mapped_name);
1381         clock_gettime_mono(&ts2);
1382         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1383
1384         if (timediff > audit_timeout) {
1385                 smb_time_audit_log("translate_name", timediff);
1386         }
1387
1388         return result;
1389 }
1390
1391 static NTSTATUS smb_time_audit_fget_nt_acl(vfs_handle_struct *handle,
1392                                            files_struct *fsp,
1393                                            uint32 security_info,
1394                                            struct security_descriptor **ppdesc)
1395 {
1396         NTSTATUS result;
1397         struct timespec ts1,ts2;
1398         double timediff;
1399
1400         clock_gettime_mono(&ts1);
1401         result = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info, ppdesc);
1402         clock_gettime_mono(&ts2);
1403         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1404
1405         if (timediff > audit_timeout) {
1406                 smb_time_audit_log("fget_nt_acl", timediff);
1407         }
1408
1409         return result;
1410 }
1411
1412 static NTSTATUS smb_time_audit_get_nt_acl(vfs_handle_struct *handle,
1413                                           const char *name,
1414                                           uint32 security_info,
1415                                           struct security_descriptor **ppdesc)
1416 {
1417         NTSTATUS result;
1418         struct timespec ts1,ts2;
1419         double timediff;
1420
1421         clock_gettime_mono(&ts1);
1422         result = SMB_VFS_NEXT_GET_NT_ACL(handle, name, security_info, ppdesc);
1423         clock_gettime_mono(&ts2);
1424         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1425
1426         if (timediff > audit_timeout) {
1427                 smb_time_audit_log("get_nt_acl", timediff);
1428         }
1429
1430         return result;
1431 }
1432
1433 static NTSTATUS smb_time_audit_fset_nt_acl(vfs_handle_struct *handle,
1434                                            files_struct *fsp,
1435                                            uint32 security_info_sent,
1436                                            const struct security_descriptor *psd)
1437 {
1438         NTSTATUS result;
1439         struct timespec ts1,ts2;
1440         double timediff;
1441
1442         clock_gettime_mono(&ts1);
1443         result = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent,
1444                                           psd);
1445         clock_gettime_mono(&ts2);
1446         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1447
1448         if (timediff > audit_timeout) {
1449                 smb_time_audit_log("fset_nt_acl", timediff);
1450         }
1451
1452         return result;
1453 }
1454
1455 static int smb_time_audit_chmod_acl(vfs_handle_struct *handle,
1456                                     const char *path, mode_t mode)
1457 {
1458         int result;
1459         struct timespec ts1,ts2;
1460         double timediff;
1461
1462         clock_gettime_mono(&ts1);
1463         result = SMB_VFS_NEXT_CHMOD_ACL(handle, path, mode);
1464         clock_gettime_mono(&ts2);
1465         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1466
1467         if (timediff > audit_timeout) {
1468                 smb_time_audit_log("chmod_acl", timediff);
1469         }
1470
1471         return result;
1472 }
1473
1474 static int smb_time_audit_fchmod_acl(vfs_handle_struct *handle,
1475                                      files_struct *fsp, mode_t mode)
1476 {
1477         int result;
1478         struct timespec ts1,ts2;
1479         double timediff;
1480
1481         clock_gettime_mono(&ts1);
1482         result = SMB_VFS_NEXT_FCHMOD_ACL(handle, fsp, mode);
1483         clock_gettime_mono(&ts2);
1484         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1485
1486         if (timediff > audit_timeout) {
1487                 smb_time_audit_log("fchmod_acl", timediff);
1488         }
1489
1490         return result;
1491 }
1492
1493 static int smb_time_audit_sys_acl_get_entry(vfs_handle_struct *handle,
1494                                             SMB_ACL_T theacl, int entry_id,
1495                                             SMB_ACL_ENTRY_T *entry_p)
1496 {
1497         int result;
1498         struct timespec ts1,ts2;
1499         double timediff;
1500
1501         clock_gettime_mono(&ts1);
1502         result = SMB_VFS_NEXT_SYS_ACL_GET_ENTRY(handle, theacl, entry_id,
1503                                                 entry_p);
1504         clock_gettime_mono(&ts2);
1505         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1506
1507         if (timediff > audit_timeout) {
1508                 smb_time_audit_log("sys_acl_get_entry", timediff);
1509         }
1510
1511         return result;
1512 }
1513
1514 static int smb_time_audit_sys_acl_get_tag_type(vfs_handle_struct *handle,
1515                                                SMB_ACL_ENTRY_T entry_d,
1516                                                SMB_ACL_TAG_T *tag_type_p)
1517 {
1518         int result;
1519         struct timespec ts1,ts2;
1520         double timediff;
1521
1522         clock_gettime_mono(&ts1);
1523         result = SMB_VFS_NEXT_SYS_ACL_GET_TAG_TYPE(handle, entry_d,
1524                                                    tag_type_p);
1525         clock_gettime_mono(&ts2);
1526         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1527
1528         if (timediff > audit_timeout) {
1529                 smb_time_audit_log("sys_acl_get_tag_type", timediff);
1530         }
1531
1532         return result;
1533 }
1534
1535 static int smb_time_audit_sys_acl_get_permset(vfs_handle_struct *handle,
1536                                               SMB_ACL_ENTRY_T entry_d,
1537                                               SMB_ACL_PERMSET_T *permset_p)
1538 {
1539         int result;
1540         struct timespec ts1,ts2;
1541         double timediff;
1542
1543         clock_gettime_mono(&ts1);
1544         result = SMB_VFS_NEXT_SYS_ACL_GET_PERMSET(handle, entry_d,
1545                                                   permset_p);
1546         clock_gettime_mono(&ts2);
1547         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1548
1549         if (timediff > audit_timeout) {
1550                 smb_time_audit_log("sys_acl_get_permset", timediff);
1551         }
1552
1553         return result;
1554 }
1555
1556 static void * smb_time_audit_sys_acl_get_qualifier(vfs_handle_struct *handle,
1557                                                    SMB_ACL_ENTRY_T entry_d)
1558 {
1559         void *result;
1560         struct timespec ts1,ts2;
1561         double timediff;
1562
1563         clock_gettime_mono(&ts1);
1564         result = SMB_VFS_NEXT_SYS_ACL_GET_QUALIFIER(handle, entry_d);
1565         clock_gettime_mono(&ts2);
1566         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1567
1568         if (timediff > audit_timeout) {
1569                 smb_time_audit_log("sys_acl_get_qualifier", timediff);
1570         }
1571
1572         return result;
1573 }
1574
1575 static SMB_ACL_T smb_time_audit_sys_acl_get_file(vfs_handle_struct *handle,
1576                                                  const char *path_p,
1577                                                  SMB_ACL_TYPE_T type)
1578 {
1579         SMB_ACL_T result;
1580         struct timespec ts1,ts2;
1581         double timediff;
1582
1583         clock_gettime_mono(&ts1);
1584         result = SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, path_p, type);
1585         clock_gettime_mono(&ts2);
1586         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1587
1588         if (timediff > audit_timeout) {
1589                 smb_time_audit_log("sys_acl_get_file", timediff);
1590         }
1591
1592         return result;
1593 }
1594
1595 static SMB_ACL_T smb_time_audit_sys_acl_get_fd(vfs_handle_struct *handle,
1596                                                files_struct *fsp)
1597 {
1598         SMB_ACL_T result;
1599         struct timespec ts1,ts2;
1600         double timediff;
1601
1602         clock_gettime_mono(&ts1);
1603         result = SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp);
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("sys_acl_get_fd", timediff);
1609         }
1610
1611         return result;
1612 }
1613
1614 static int smb_time_audit_sys_acl_clear_perms(vfs_handle_struct *handle,
1615                                               SMB_ACL_PERMSET_T permset)
1616 {
1617         int result;
1618         struct timespec ts1,ts2;
1619         double timediff;
1620
1621         clock_gettime_mono(&ts1);
1622         result = SMB_VFS_NEXT_SYS_ACL_CLEAR_PERMS(handle, permset);
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("sys_acl_clear_perms", timediff);
1628         }
1629
1630         return result;
1631 }
1632
1633 static int smb_time_audit_sys_acl_add_perm(vfs_handle_struct *handle,
1634                                            SMB_ACL_PERMSET_T permset,
1635                                            SMB_ACL_PERM_T perm)
1636 {
1637         int result;
1638         struct timespec ts1,ts2;
1639         double timediff;
1640
1641         clock_gettime_mono(&ts1);
1642         result = SMB_VFS_NEXT_SYS_ACL_ADD_PERM(handle, permset, perm);
1643         clock_gettime_mono(&ts2);
1644         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1645
1646         if (timediff > audit_timeout) {
1647                 smb_time_audit_log("sys_acl_add_perm", timediff);
1648         }
1649
1650         return result;
1651 }
1652
1653 static char * smb_time_audit_sys_acl_to_text(vfs_handle_struct *handle,
1654                                              SMB_ACL_T theacl,
1655                                              ssize_t *plen)
1656 {
1657         char * result;
1658         struct timespec ts1,ts2;
1659         double timediff;
1660
1661         clock_gettime_mono(&ts1);
1662         result = SMB_VFS_NEXT_SYS_ACL_TO_TEXT(handle, theacl, plen);
1663         clock_gettime_mono(&ts2);
1664         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1665
1666         if (timediff > audit_timeout) {
1667                 smb_time_audit_log("sys_acl_to_text", timediff);
1668         }
1669
1670         return result;
1671 }
1672
1673 static SMB_ACL_T smb_time_audit_sys_acl_init(vfs_handle_struct *handle,
1674                                              int count)
1675 {
1676         SMB_ACL_T result;
1677         struct timespec ts1,ts2;
1678         double timediff;
1679
1680         clock_gettime_mono(&ts1);
1681         result = SMB_VFS_NEXT_SYS_ACL_INIT(handle, count);
1682         clock_gettime_mono(&ts2);
1683         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1684
1685         if (timediff > audit_timeout) {
1686                 smb_time_audit_log("sys_acl_init", timediff);
1687         }
1688
1689         return result;
1690 }
1691
1692 static int smb_time_audit_sys_acl_create_entry(vfs_handle_struct *handle,
1693                                                SMB_ACL_T *pacl,
1694                                                SMB_ACL_ENTRY_T *pentry)
1695 {
1696         int result;
1697         struct timespec ts1,ts2;
1698         double timediff;
1699
1700         clock_gettime_mono(&ts1);
1701         result = SMB_VFS_NEXT_SYS_ACL_CREATE_ENTRY(handle, pacl, pentry);
1702         clock_gettime_mono(&ts2);
1703         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1704
1705         if (timediff > audit_timeout) {
1706                 smb_time_audit_log("sys_acl_create_entry", timediff);
1707         }
1708
1709         return result;
1710 }
1711
1712 static int smb_time_audit_sys_acl_set_tag_type(vfs_handle_struct *handle,
1713                                                SMB_ACL_ENTRY_T entry,
1714                                                SMB_ACL_TAG_T tagtype)
1715 {
1716         int result;
1717         struct timespec ts1,ts2;
1718         double timediff;
1719
1720         clock_gettime_mono(&ts1);
1721         result = SMB_VFS_NEXT_SYS_ACL_SET_TAG_TYPE(handle, entry,
1722                                                    tagtype);
1723         clock_gettime_mono(&ts2);
1724         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1725
1726         if (timediff > audit_timeout) {
1727                 smb_time_audit_log("sys_acl_set_tag_type", timediff);
1728         }
1729
1730         return result;
1731 }
1732
1733 static int smb_time_audit_sys_acl_set_qualifier(vfs_handle_struct *handle,
1734                                                 SMB_ACL_ENTRY_T entry,
1735                                                 void *qual)
1736 {
1737         int result;
1738         struct timespec ts1,ts2;
1739         double timediff;
1740
1741         clock_gettime_mono(&ts1);
1742         result = SMB_VFS_NEXT_SYS_ACL_SET_QUALIFIER(handle, entry, qual);
1743         clock_gettime_mono(&ts2);
1744         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1745
1746         if (timediff > audit_timeout) {
1747                 smb_time_audit_log("sys_acl_set_qualifier", timediff);
1748         }
1749
1750         return result;
1751 }
1752
1753 static int smb_time_audit_sys_acl_set_permset(vfs_handle_struct *handle,
1754                                               SMB_ACL_ENTRY_T entry,
1755                                               SMB_ACL_PERMSET_T permset)
1756 {
1757         int result;
1758         struct timespec ts1,ts2;
1759         double timediff;
1760
1761         clock_gettime_mono(&ts1);
1762         result = SMB_VFS_NEXT_SYS_ACL_SET_PERMSET(handle, entry, permset);
1763         clock_gettime_mono(&ts2);
1764         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1765
1766         if (timediff > audit_timeout) {
1767                 smb_time_audit_log("sys_acl_set_permset", timediff);
1768         }
1769
1770         return result;
1771 }
1772
1773 static int smb_time_audit_sys_acl_valid(vfs_handle_struct *handle,
1774                                         SMB_ACL_T theacl)
1775 {
1776         int result;
1777         struct timespec ts1,ts2;
1778         double timediff;
1779
1780         clock_gettime_mono(&ts1);
1781         result = SMB_VFS_NEXT_SYS_ACL_VALID(handle, theacl);
1782         clock_gettime_mono(&ts2);
1783         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1784
1785         if (timediff > audit_timeout) {
1786                 smb_time_audit_log("sys_acl_valid", timediff);
1787         }
1788
1789         return result;
1790 }
1791
1792 static int smb_time_audit_sys_acl_set_file(vfs_handle_struct *handle,
1793                                            const char *name,
1794                                            SMB_ACL_TYPE_T acltype,
1795                                            SMB_ACL_T theacl)
1796 {
1797         int result;
1798         struct timespec ts1,ts2;
1799         double timediff;
1800
1801         clock_gettime_mono(&ts1);
1802         result = SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, name, acltype,
1803                                                theacl);
1804         clock_gettime_mono(&ts2);
1805         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1806
1807         if (timediff > audit_timeout) {
1808                 smb_time_audit_log("sys_acl_set_file", timediff);
1809         }
1810
1811         return result;
1812 }
1813
1814 static int smb_time_audit_sys_acl_set_fd(vfs_handle_struct *handle,
1815                                          files_struct *fsp,
1816                                          SMB_ACL_T theacl)
1817 {
1818         int result;
1819         struct timespec ts1,ts2;
1820         double timediff;
1821
1822         clock_gettime_mono(&ts1);
1823         result = SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, theacl);
1824         clock_gettime_mono(&ts2);
1825         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1826
1827         if (timediff > audit_timeout) {
1828                 smb_time_audit_log("sys_acl_set_fd", timediff);
1829         }
1830
1831         return result;
1832 }
1833
1834 static int smb_time_audit_sys_acl_delete_def_file(vfs_handle_struct *handle,
1835                                                   const char *path)
1836 {
1837         int result;
1838         struct timespec ts1,ts2;
1839         double timediff;
1840
1841         clock_gettime_mono(&ts1);
1842         result = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, path);
1843         clock_gettime_mono(&ts2);
1844         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1845
1846         if (timediff > audit_timeout) {
1847                 smb_time_audit_log("sys_acl_delete_def_file", timediff);
1848         }
1849
1850         return result;
1851 }
1852
1853 static int smb_time_audit_sys_acl_get_perm(vfs_handle_struct *handle,
1854                                            SMB_ACL_PERMSET_T permset,
1855                                            SMB_ACL_PERM_T perm)
1856 {
1857         int result;
1858         struct timespec ts1,ts2;
1859         double timediff;
1860
1861         clock_gettime_mono(&ts1);
1862         result = SMB_VFS_NEXT_SYS_ACL_GET_PERM(handle, permset, perm);
1863         clock_gettime_mono(&ts2);
1864         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1865
1866         if (timediff > audit_timeout) {
1867                 smb_time_audit_log("sys_acl_get_perm", timediff);
1868         }
1869
1870         return result;
1871 }
1872
1873 static int smb_time_audit_sys_acl_free_text(vfs_handle_struct *handle,
1874                                             char *text)
1875 {
1876         int result;
1877         struct timespec ts1,ts2;
1878         double timediff;
1879
1880         clock_gettime_mono(&ts1);
1881         result = SMB_VFS_NEXT_SYS_ACL_FREE_TEXT(handle, text);
1882         clock_gettime_mono(&ts2);
1883         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1884
1885         if (timediff > audit_timeout) {
1886                 smb_time_audit_log("sys_acl_free_text", timediff);
1887         }
1888
1889         return result;
1890 }
1891
1892 static int smb_time_audit_sys_acl_free_acl(vfs_handle_struct *handle,
1893                                            SMB_ACL_T posix_acl)
1894 {
1895         int result;
1896         struct timespec ts1,ts2;
1897         double timediff;
1898
1899         clock_gettime_mono(&ts1);
1900         result = SMB_VFS_NEXT_SYS_ACL_FREE_ACL(handle, posix_acl);
1901         clock_gettime_mono(&ts2);
1902         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1903
1904         if (timediff > audit_timeout) {
1905                 smb_time_audit_log("sys_acl_free_acl", timediff);
1906         }
1907
1908         return result;
1909 }
1910
1911 static int smb_time_audit_sys_acl_free_qualifier(vfs_handle_struct *handle,
1912                                                  void *qualifier,
1913                                                  SMB_ACL_TAG_T tagtype)
1914 {
1915         int result;
1916         struct timespec ts1,ts2;
1917         double timediff;
1918
1919         clock_gettime_mono(&ts1);
1920         result = SMB_VFS_NEXT_SYS_ACL_FREE_QUALIFIER(handle, qualifier,
1921                                                      tagtype);
1922         clock_gettime_mono(&ts2);
1923         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1924
1925         if (timediff > audit_timeout) {
1926                 smb_time_audit_log("sys_acl_free_qualifier", timediff);
1927         }
1928
1929         return result;
1930 }
1931
1932 static ssize_t smb_time_audit_getxattr(struct vfs_handle_struct *handle,
1933                                        const char *path, const char *name,
1934                                        void *value, size_t size)
1935 {
1936         ssize_t result;
1937         struct timespec ts1,ts2;
1938         double timediff;
1939
1940         clock_gettime_mono(&ts1);
1941         result = SMB_VFS_NEXT_GETXATTR(handle, path, name, value, size);
1942         clock_gettime_mono(&ts2);
1943         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1944
1945         if (timediff > audit_timeout) {
1946                 smb_time_audit_log("getxattr", timediff);
1947         }
1948
1949         return result;
1950 }
1951
1952 static ssize_t smb_time_audit_lgetxattr(struct vfs_handle_struct *handle,
1953                                         const char *path, const char *name,
1954                                         void *value, size_t size)
1955 {
1956         ssize_t result;
1957         struct timespec ts1,ts2;
1958         double timediff;
1959
1960         clock_gettime_mono(&ts1);
1961         result = SMB_VFS_NEXT_LGETXATTR(handle, path, name, value, size);
1962         clock_gettime_mono(&ts2);
1963         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1964
1965         if (timediff > audit_timeout) {
1966                 smb_time_audit_log("lgetxattr", timediff);
1967         }
1968
1969         return result;
1970 }
1971
1972 static ssize_t smb_time_audit_fgetxattr(struct vfs_handle_struct *handle,
1973                                         struct files_struct *fsp,
1974                                         const char *name, void *value,
1975                                         size_t size)
1976 {
1977         ssize_t result;
1978         struct timespec ts1,ts2;
1979         double timediff;
1980
1981         clock_gettime_mono(&ts1);
1982         result = SMB_VFS_NEXT_FGETXATTR(handle, fsp, name, value, size);
1983         clock_gettime_mono(&ts2);
1984         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
1985
1986         if (timediff > audit_timeout) {
1987                 smb_time_audit_log("fgetxattr", timediff);
1988         }
1989
1990         return result;
1991 }
1992
1993 static ssize_t smb_time_audit_listxattr(struct vfs_handle_struct *handle,
1994                                         const char *path, char *list,
1995                                         size_t size)
1996 {
1997         ssize_t result;
1998         struct timespec ts1,ts2;
1999         double timediff;
2000
2001         clock_gettime_mono(&ts1);
2002         result = SMB_VFS_NEXT_LISTXATTR(handle, path, list, size);
2003         clock_gettime_mono(&ts2);
2004         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2005
2006         if (timediff > audit_timeout) {
2007                 smb_time_audit_log("listxattr", timediff);
2008         }
2009
2010         return result;
2011 }
2012
2013 static ssize_t smb_time_audit_llistxattr(struct vfs_handle_struct *handle,
2014                                          const char *path, char *list,
2015                                          size_t size)
2016 {
2017         ssize_t result;
2018         struct timespec ts1,ts2;
2019         double timediff;
2020
2021         clock_gettime_mono(&ts1);
2022         result = SMB_VFS_NEXT_LLISTXATTR(handle, path, list, size);
2023         clock_gettime_mono(&ts2);
2024         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2025
2026         if (timediff > audit_timeout) {
2027                 smb_time_audit_log("llistxattr", timediff);
2028         }
2029
2030         return result;
2031 }
2032
2033 static ssize_t smb_time_audit_flistxattr(struct vfs_handle_struct *handle,
2034                                          struct files_struct *fsp, char *list,
2035                                          size_t size)
2036 {
2037         ssize_t result;
2038         struct timespec ts1,ts2;
2039         double timediff;
2040
2041         clock_gettime_mono(&ts1);
2042         result = SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
2043         clock_gettime_mono(&ts2);
2044         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2045
2046         if (timediff > audit_timeout) {
2047                 smb_time_audit_log("flistxattr", timediff);
2048         }
2049
2050         return result;
2051 }
2052
2053 static int smb_time_audit_removexattr(struct vfs_handle_struct *handle,
2054                                       const char *path, const char *name)
2055 {
2056         int result;
2057         struct timespec ts1,ts2;
2058         double timediff;
2059
2060         clock_gettime_mono(&ts1);
2061         result = SMB_VFS_NEXT_REMOVEXATTR(handle, path, name);
2062         clock_gettime_mono(&ts2);
2063         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2064
2065         if (timediff > audit_timeout) {
2066                 smb_time_audit_log("removexattr", timediff);
2067         }
2068
2069         return result;
2070 }
2071
2072 static int smb_time_audit_lremovexattr(struct vfs_handle_struct *handle,
2073                                        const char *path, const char *name)
2074 {
2075         int result;
2076         struct timespec ts1,ts2;
2077         double timediff;
2078
2079         clock_gettime_mono(&ts1);
2080         result = SMB_VFS_NEXT_LREMOVEXATTR(handle, path, name);
2081         clock_gettime_mono(&ts2);
2082         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2083
2084         if (timediff > audit_timeout) {
2085                 smb_time_audit_log("lremovexattr", timediff);
2086         }
2087
2088         return result;
2089 }
2090
2091 static int smb_time_audit_fremovexattr(struct vfs_handle_struct *handle,
2092                                        struct files_struct *fsp,
2093                                        const char *name)
2094 {
2095         int result;
2096         struct timespec ts1,ts2;
2097         double timediff;
2098
2099         clock_gettime_mono(&ts1);
2100         result = SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, name);
2101         clock_gettime_mono(&ts2);
2102         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2103
2104         if (timediff > audit_timeout) {
2105                 smb_time_audit_log("fremovexattr", timediff);
2106         }
2107
2108         return result;
2109 }
2110
2111 static int smb_time_audit_setxattr(struct vfs_handle_struct *handle,
2112                                    const char *path, const char *name,
2113                                    const void *value, size_t size,
2114                                    int flags)
2115 {
2116         int result;
2117         struct timespec ts1,ts2;
2118         double timediff;
2119
2120         clock_gettime_mono(&ts1);
2121         result = SMB_VFS_NEXT_SETXATTR(handle, path, name, value, size,
2122                                        flags);
2123         clock_gettime_mono(&ts2);
2124         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2125
2126         if (timediff > audit_timeout) {
2127                 smb_time_audit_log("setxattr", timediff);
2128         }
2129
2130         return result;
2131 }
2132
2133 static int smb_time_audit_lsetxattr(struct vfs_handle_struct *handle,
2134                                     const char *path, const char *name,
2135                                     const void *value, size_t size,
2136                                     int flags)
2137 {
2138         int result;
2139         struct timespec ts1,ts2;
2140         double timediff;
2141
2142         clock_gettime_mono(&ts1);
2143         result = SMB_VFS_NEXT_LSETXATTR(handle, path, name, value, size,
2144                                         flags);
2145         clock_gettime_mono(&ts2);
2146         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2147
2148         if (timediff > audit_timeout) {
2149                 smb_time_audit_log("lsetxattr", timediff);
2150         }
2151
2152         return result;
2153 }
2154
2155 static int smb_time_audit_fsetxattr(struct vfs_handle_struct *handle,
2156                                     struct files_struct *fsp, const char *name,
2157                                     const void *value, size_t size, int flags)
2158 {
2159         int result;
2160         struct timespec ts1,ts2;
2161         double timediff;
2162
2163         clock_gettime_mono(&ts1);
2164         result = SMB_VFS_NEXT_FSETXATTR(handle, fsp, name, value, size, flags);
2165         clock_gettime_mono(&ts2);
2166         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2167
2168         if (timediff > audit_timeout) {
2169                 smb_time_audit_log("fsetxattr", timediff);
2170         }
2171
2172         return result;
2173 }
2174
2175 static int smb_time_audit_aio_read(struct vfs_handle_struct *handle,
2176                                    struct files_struct *fsp,
2177                                    SMB_STRUCT_AIOCB *aiocb)
2178 {
2179         int result;
2180         struct timespec ts1,ts2;
2181         double timediff;
2182
2183         clock_gettime_mono(&ts1);
2184         result = SMB_VFS_NEXT_AIO_READ(handle, fsp, aiocb);
2185         clock_gettime_mono(&ts2);
2186         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2187
2188         if (timediff > audit_timeout) {
2189                 smb_time_audit_log("aio_read", timediff);
2190         }
2191
2192         return result;
2193 }
2194
2195 static int smb_time_audit_aio_write(struct vfs_handle_struct *handle,
2196                                     struct files_struct *fsp,
2197                                     SMB_STRUCT_AIOCB *aiocb)
2198 {
2199         int result;
2200         struct timespec ts1,ts2;
2201         double timediff;
2202
2203         clock_gettime_mono(&ts1);
2204         result = SMB_VFS_NEXT_AIO_WRITE(handle, fsp, aiocb);
2205         clock_gettime_mono(&ts2);
2206         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2207
2208         if (timediff > audit_timeout) {
2209                 smb_time_audit_log("aio_write", timediff);
2210         }
2211
2212         return result;
2213 }
2214
2215 static ssize_t smb_time_audit_aio_return(struct vfs_handle_struct *handle,
2216                                          struct files_struct *fsp,
2217                                          SMB_STRUCT_AIOCB *aiocb)
2218 {
2219         int result;
2220         struct timespec ts1,ts2;
2221         double timediff;
2222
2223         clock_gettime_mono(&ts1);
2224         result = SMB_VFS_NEXT_AIO_RETURN(handle, fsp, aiocb);
2225         clock_gettime_mono(&ts2);
2226         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2227
2228         if (timediff > audit_timeout) {
2229                 smb_time_audit_log("aio_return", timediff);
2230         }
2231
2232         return result;
2233 }
2234
2235 static int smb_time_audit_aio_cancel(struct vfs_handle_struct *handle,
2236                                      struct files_struct *fsp,
2237                                      SMB_STRUCT_AIOCB *aiocb)
2238 {
2239         int result;
2240         struct timespec ts1,ts2;
2241         double timediff;
2242
2243         clock_gettime_mono(&ts1);
2244         result = SMB_VFS_NEXT_AIO_CANCEL(handle, fsp, aiocb);
2245         clock_gettime_mono(&ts2);
2246         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2247
2248         if (timediff > audit_timeout) {
2249                 smb_time_audit_log("aio_cancel", timediff);
2250         }
2251
2252         return result;
2253 }
2254
2255 static int smb_time_audit_aio_error(struct vfs_handle_struct *handle,
2256                                     struct files_struct *fsp,
2257                                     SMB_STRUCT_AIOCB *aiocb)
2258 {
2259         int result;
2260         struct timespec ts1,ts2;
2261         double timediff;
2262
2263         clock_gettime_mono(&ts1);
2264         result = SMB_VFS_NEXT_AIO_ERROR(handle, fsp, aiocb);
2265         clock_gettime_mono(&ts2);
2266         timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
2267
2268         if (timediff > audit_timeout) {
2269                 smb_time_audit_log("aio_error", timediff);
2270         }
2271
2272         return result;
2273 }
2274
2275 static int smb_time_audit_aio_fsync(struct vfs_handle_struct *handle,
2276                                     struct files_struct *fsp, int op,
2277                                     SMB_STRUCT_AIOCB *aiocb)
2278 {
2279         int result;
2280         struct timespec ts1,ts2;
2281         double timediff;
2282
2283         clock_gettime_mono(&ts1);
2284         result = SMB_VFS_NEXT_AIO_FSYNC(handle, fsp, op, aiocb);
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("aio_fsync", timediff);
2290         }
2291
2292         return result;
2293 }
2294
2295 static int smb_time_audit_aio_suspend(struct vfs_handle_struct *handle,
2296                                       struct files_struct *fsp,
2297                                       const SMB_STRUCT_AIOCB * const aiocb[],
2298                                       int n, const struct timespec *ts)
2299 {
2300         int result;
2301         struct timespec ts1,ts2;
2302         double timediff;
2303
2304         clock_gettime_mono(&ts1);
2305         result = SMB_VFS_NEXT_AIO_SUSPEND(handle, fsp, aiocb, n, ts);
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("aio_suspend", timediff);
2311         }
2312
2313         return result;
2314 }
2315
2316 static bool smb_time_audit_aio_force(struct vfs_handle_struct *handle,
2317                                      struct files_struct *fsp)
2318 {
2319         bool result;
2320         struct timespec ts1,ts2;
2321         double timediff;
2322
2323         clock_gettime_mono(&ts1);
2324         result = SMB_VFS_NEXT_AIO_FORCE(handle, fsp);
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("aio_force", timediff);
2330         }
2331
2332         return result;
2333 }
2334
2335
2336
2337 /* VFS operations */
2338
2339 static struct vfs_fn_pointers vfs_time_audit_fns = {
2340         .connect_fn = smb_time_audit_connect,
2341         .disconnect = smb_time_audit_disconnect,
2342         .disk_free = smb_time_audit_disk_free,
2343         .get_quota = smb_time_audit_get_quota,
2344         .set_quota = smb_time_audit_set_quota,
2345         .get_shadow_copy_data = smb_time_audit_get_shadow_copy_data,
2346         .statvfs = smb_time_audit_statvfs,
2347         .fs_capabilities = smb_time_audit_fs_capabilities,
2348         .opendir = smb_time_audit_opendir,
2349         .fdopendir = smb_time_audit_fdopendir,
2350         .readdir = smb_time_audit_readdir,
2351         .seekdir = smb_time_audit_seekdir,
2352         .telldir = smb_time_audit_telldir,
2353         .rewind_dir = smb_time_audit_rewinddir,
2354         .mkdir = smb_time_audit_mkdir,
2355         .rmdir = smb_time_audit_rmdir,
2356         .closedir = smb_time_audit_closedir,
2357         .init_search_op = smb_time_audit_init_search_op,
2358         .open = smb_time_audit_open,
2359         .create_file = smb_time_audit_create_file,
2360         .close_fn = smb_time_audit_close,
2361         .vfs_read = smb_time_audit_read,
2362         .pread = smb_time_audit_pread,
2363         .write = smb_time_audit_write,
2364         .pwrite = smb_time_audit_pwrite,
2365         .lseek = smb_time_audit_lseek,
2366         .sendfile = smb_time_audit_sendfile,
2367         .recvfile = smb_time_audit_recvfile,
2368         .rename = smb_time_audit_rename,
2369         .fsync = smb_time_audit_fsync,
2370         .stat = smb_time_audit_stat,
2371         .fstat = smb_time_audit_fstat,
2372         .lstat = smb_time_audit_lstat,
2373         .get_alloc_size = smb_time_audit_get_alloc_size,
2374         .unlink = smb_time_audit_unlink,
2375         .chmod = smb_time_audit_chmod,
2376         .fchmod = smb_time_audit_fchmod,
2377         .chown = smb_time_audit_chown,
2378         .fchown = smb_time_audit_fchown,
2379         .lchown = smb_time_audit_lchown,
2380         .chdir = smb_time_audit_chdir,
2381         .getwd = smb_time_audit_getwd,
2382         .ntimes = smb_time_audit_ntimes,
2383         .ftruncate = smb_time_audit_ftruncate,
2384         .fallocate = smb_time_audit_fallocate,
2385         .lock = smb_time_audit_lock,
2386         .kernel_flock = smb_time_audit_kernel_flock,
2387         .linux_setlease = smb_time_audit_linux_setlease,
2388         .getlock = smb_time_audit_getlock,
2389         .symlink = smb_time_audit_symlink,
2390         .vfs_readlink = smb_time_audit_readlink,
2391         .link = smb_time_audit_link,
2392         .mknod = smb_time_audit_mknod,
2393         .realpath = smb_time_audit_realpath,
2394         .notify_watch = smb_time_audit_notify_watch,
2395         .chflags = smb_time_audit_chflags,
2396         .file_id_create = smb_time_audit_file_id_create,
2397         .streaminfo = smb_time_audit_streaminfo,
2398         .get_real_filename = smb_time_audit_get_real_filename,
2399         .connectpath = smb_time_audit_connectpath,
2400         .brl_lock_windows = smb_time_audit_brl_lock_windows,
2401         .brl_unlock_windows = smb_time_audit_brl_unlock_windows,
2402         .brl_cancel_windows = smb_time_audit_brl_cancel_windows,
2403         .strict_lock = smb_time_audit_strict_lock,
2404         .strict_unlock = smb_time_audit_strict_unlock,
2405         .translate_name = smb_time_audit_translate_name,
2406         .fget_nt_acl = smb_time_audit_fget_nt_acl,
2407         .get_nt_acl = smb_time_audit_get_nt_acl,
2408         .fset_nt_acl = smb_time_audit_fset_nt_acl,
2409         .chmod_acl = smb_time_audit_chmod_acl,
2410         .fchmod_acl = smb_time_audit_fchmod_acl,
2411         .sys_acl_get_entry = smb_time_audit_sys_acl_get_entry,
2412         .sys_acl_get_tag_type = smb_time_audit_sys_acl_get_tag_type,
2413         .sys_acl_get_permset = smb_time_audit_sys_acl_get_permset,
2414         .sys_acl_get_qualifier = smb_time_audit_sys_acl_get_qualifier,
2415         .sys_acl_get_file = smb_time_audit_sys_acl_get_file,
2416         .sys_acl_get_fd = smb_time_audit_sys_acl_get_fd,
2417         .sys_acl_clear_perms = smb_time_audit_sys_acl_clear_perms,
2418         .sys_acl_add_perm = smb_time_audit_sys_acl_add_perm,
2419         .sys_acl_to_text = smb_time_audit_sys_acl_to_text,
2420         .sys_acl_init = smb_time_audit_sys_acl_init,
2421         .sys_acl_create_entry = smb_time_audit_sys_acl_create_entry,
2422         .sys_acl_set_tag_type = smb_time_audit_sys_acl_set_tag_type,
2423         .sys_acl_set_qualifier = smb_time_audit_sys_acl_set_qualifier,
2424         .sys_acl_set_permset = smb_time_audit_sys_acl_set_permset,
2425         .sys_acl_valid = smb_time_audit_sys_acl_valid,
2426         .sys_acl_set_file = smb_time_audit_sys_acl_set_file,
2427         .sys_acl_set_fd = smb_time_audit_sys_acl_set_fd,
2428         .sys_acl_delete_def_file = smb_time_audit_sys_acl_delete_def_file,
2429         .sys_acl_get_perm = smb_time_audit_sys_acl_get_perm,
2430         .sys_acl_free_text = smb_time_audit_sys_acl_free_text,
2431         .sys_acl_free_acl = smb_time_audit_sys_acl_free_acl,
2432         .sys_acl_free_qualifier = smb_time_audit_sys_acl_free_qualifier,
2433         .getxattr = smb_time_audit_getxattr,
2434         .lgetxattr = smb_time_audit_lgetxattr,
2435         .fgetxattr = smb_time_audit_fgetxattr,
2436         .listxattr = smb_time_audit_listxattr,
2437         .llistxattr = smb_time_audit_llistxattr,
2438         .flistxattr = smb_time_audit_flistxattr,
2439         .removexattr = smb_time_audit_removexattr,
2440         .lremovexattr = smb_time_audit_lremovexattr,
2441         .fremovexattr = smb_time_audit_fremovexattr,
2442         .setxattr = smb_time_audit_setxattr,
2443         .lsetxattr = smb_time_audit_lsetxattr,
2444         .fsetxattr = smb_time_audit_fsetxattr,
2445         .aio_read = smb_time_audit_aio_read,
2446         .aio_write = smb_time_audit_aio_write,
2447         .aio_return_fn = smb_time_audit_aio_return,
2448         .aio_cancel = smb_time_audit_aio_cancel,
2449         .aio_error_fn = smb_time_audit_aio_error,
2450         .aio_fsync = smb_time_audit_aio_fsync,
2451         .aio_suspend = smb_time_audit_aio_suspend,
2452         .aio_force = smb_time_audit_aio_force,
2453 };
2454
2455
2456 NTSTATUS vfs_time_audit_init(void);
2457 NTSTATUS vfs_time_audit_init(void)
2458 {
2459         audit_timeout = (double)lp_parm_int(-1, "time_audit", "timeout",
2460                                             10000) / 1000.0;
2461         return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "time_audit",
2462                                 &vfs_time_audit_fns);
2463 }