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