s3/vfs: remove now unused is_offline/set_offline VFS functions
[samba.git] / source3 / modules / vfs_full_audit.c
1 /* 
2  * Auditing VFS module for samba.  Log selected file operations to syslog
3  * facility.
4  *
5  * Copyright (C) Tim Potter, 1999-2000
6  * Copyright (C) Alexander Bokovoy, 2002
7  * Copyright (C) John H Terpstra, 2003
8  * Copyright (C) Stefan (metze) Metzmacher, 2003
9  * Copyright (C) Volker Lendecke, 2004
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 3 of the License, or
14  * (at your option) any later version.
15  *  
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *  
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, see <http://www.gnu.org/licenses/>.
23  */
24
25 /*
26  * This module implements parseable logging for all Samba VFS operations.
27  *
28  * You use it as follows:
29  *
30  * [tmp]
31  * path = /tmp
32  * vfs objects = full_audit
33  * full_audit:prefix = %u|%I
34  * full_audit:success = open opendir
35  * full_audit:failure = all
36  *
37  * vfs op can be "all" which means log all operations.
38  * vfs op can be "none" which means no logging.
39  *
40  * This leads to syslog entries of the form:
41  * smbd_audit: nobody|192.168.234.1|opendir|ok|.
42  * smbd_audit: nobody|192.168.234.1|open|fail (File not found)|r|x.txt
43  *
44  * where "nobody" is the connected username and "192.168.234.1" is the
45  * client's IP address. 
46  *
47  * Options:
48  *
49  * prefix: A macro expansion template prepended to the syslog entry.
50  *
51  * success: A list of VFS operations for which a successful completion should
52  * be logged. Defaults to no logging at all. The special operation "all" logs
53  * - you guessed it - everything.
54  *
55  * failure: A list of VFS operations for which failure to complete should be
56  * logged. Defaults to logging everything.
57  */
58
59
60 #include "includes.h"
61 #include "system/filesys.h"
62 #include "system/syslog.h"
63 #include "smbd/smbd.h"
64 #include "../librpc/gen_ndr/ndr_netlogon.h"
65 #include "auth.h"
66 #include "ntioctl.h"
67 #include "lib/param/loadparm.h"
68 #include "lib/util/bitmap.h"
69 #include "lib/util/tevent_unix.h"
70 #include "libcli/security/sddl.h"
71 #include "passdb/machine_sid.h"
72
73 static int vfs_full_audit_debug_level = DBGC_VFS;
74
75 struct vfs_full_audit_private_data {
76         struct bitmap *success_ops;
77         struct bitmap *failure_ops;
78         int syslog_facility;
79         int syslog_priority;
80         bool log_secdesc;
81         bool do_syslog;
82 };
83
84 #undef DBGC_CLASS
85 #define DBGC_CLASS vfs_full_audit_debug_level
86
87 typedef enum _vfs_op_type {
88         SMB_VFS_OP_NOOP = -1,
89
90         /* Disk operations */
91
92         SMB_VFS_OP_CONNECT = 0,
93         SMB_VFS_OP_DISCONNECT,
94         SMB_VFS_OP_DISK_FREE,
95         SMB_VFS_OP_GET_QUOTA,
96         SMB_VFS_OP_SET_QUOTA,
97         SMB_VFS_OP_GET_SHADOW_COPY_DATA,
98         SMB_VFS_OP_STATVFS,
99         SMB_VFS_OP_FS_CAPABILITIES,
100         SMB_VFS_OP_GET_DFS_REFERRALS,
101
102         /* Directory operations */
103
104         SMB_VFS_OP_OPENDIR,
105         SMB_VFS_OP_FDOPENDIR,
106         SMB_VFS_OP_READDIR,
107         SMB_VFS_OP_SEEKDIR,
108         SMB_VFS_OP_TELLDIR,
109         SMB_VFS_OP_REWINDDIR,
110         SMB_VFS_OP_MKDIR,
111         SMB_VFS_OP_RMDIR,
112         SMB_VFS_OP_CLOSEDIR,
113         SMB_VFS_OP_INIT_SEARCH_OP,
114
115         /* File operations */
116
117         SMB_VFS_OP_OPEN,
118         SMB_VFS_OP_CREATE_FILE,
119         SMB_VFS_OP_CLOSE,
120         SMB_VFS_OP_READ,
121         SMB_VFS_OP_PREAD,
122         SMB_VFS_OP_PREAD_SEND,
123         SMB_VFS_OP_PREAD_RECV,
124         SMB_VFS_OP_WRITE,
125         SMB_VFS_OP_PWRITE,
126         SMB_VFS_OP_PWRITE_SEND,
127         SMB_VFS_OP_PWRITE_RECV,
128         SMB_VFS_OP_LSEEK,
129         SMB_VFS_OP_SENDFILE,
130         SMB_VFS_OP_RECVFILE,
131         SMB_VFS_OP_RENAME,
132         SMB_VFS_OP_FSYNC,
133         SMB_VFS_OP_FSYNC_SEND,
134         SMB_VFS_OP_FSYNC_RECV,
135         SMB_VFS_OP_STAT,
136         SMB_VFS_OP_FSTAT,
137         SMB_VFS_OP_LSTAT,
138         SMB_VFS_OP_GET_ALLOC_SIZE,
139         SMB_VFS_OP_UNLINK,
140         SMB_VFS_OP_CHMOD,
141         SMB_VFS_OP_FCHMOD,
142         SMB_VFS_OP_CHOWN,
143         SMB_VFS_OP_FCHOWN,
144         SMB_VFS_OP_LCHOWN,
145         SMB_VFS_OP_CHDIR,
146         SMB_VFS_OP_GETWD,
147         SMB_VFS_OP_NTIMES,
148         SMB_VFS_OP_FTRUNCATE,
149         SMB_VFS_OP_FALLOCATE,
150         SMB_VFS_OP_LOCK,
151         SMB_VFS_OP_KERNEL_FLOCK,
152         SMB_VFS_OP_LINUX_SETLEASE,
153         SMB_VFS_OP_GETLOCK,
154         SMB_VFS_OP_SYMLINK,
155         SMB_VFS_OP_READLINK,
156         SMB_VFS_OP_LINK,
157         SMB_VFS_OP_MKNOD,
158         SMB_VFS_OP_REALPATH,
159         SMB_VFS_OP_CHFLAGS,
160         SMB_VFS_OP_FILE_ID_CREATE,
161         SMB_VFS_OP_STREAMINFO,
162         SMB_VFS_OP_GET_REAL_FILENAME,
163         SMB_VFS_OP_CONNECTPATH,
164         SMB_VFS_OP_BRL_LOCK_WINDOWS,
165         SMB_VFS_OP_BRL_UNLOCK_WINDOWS,
166         SMB_VFS_OP_BRL_CANCEL_WINDOWS,
167         SMB_VFS_OP_STRICT_LOCK,
168         SMB_VFS_OP_STRICT_UNLOCK,
169         SMB_VFS_OP_TRANSLATE_NAME,
170         SMB_VFS_OP_FSCTL,
171         SMB_VFS_OP_COPY_CHUNK_SEND,
172         SMB_VFS_OP_COPY_CHUNK_RECV,
173         SMB_VFS_OP_GET_COMPRESSION,
174         SMB_VFS_OP_SET_COMPRESSION,
175         SMB_VFS_OP_SNAP_CHECK_PATH,
176         SMB_VFS_OP_SNAP_CREATE,
177         SMB_VFS_OP_SNAP_DELETE,
178
179         /* DOS attribute operations. */
180         SMB_VFS_OP_GET_DOS_ATTRIBUTES,
181         SMB_VFS_OP_FGET_DOS_ATTRIBUTES,
182         SMB_VFS_OP_SET_DOS_ATTRIBUTES,
183         SMB_VFS_OP_FSET_DOS_ATTRIBUTES,
184
185         /* NT ACL operations. */
186
187         SMB_VFS_OP_FGET_NT_ACL,
188         SMB_VFS_OP_GET_NT_ACL,
189         SMB_VFS_OP_FSET_NT_ACL,
190         SMB_VFS_OP_AUDIT_FILE,
191
192         /* POSIX ACL operations. */
193
194         SMB_VFS_OP_CHMOD_ACL,
195         SMB_VFS_OP_FCHMOD_ACL,
196
197         SMB_VFS_OP_SYS_ACL_GET_FILE,
198         SMB_VFS_OP_SYS_ACL_GET_FD,
199         SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE,
200         SMB_VFS_OP_SYS_ACL_BLOB_GET_FD,
201         SMB_VFS_OP_SYS_ACL_SET_FILE,
202         SMB_VFS_OP_SYS_ACL_SET_FD,
203         SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE,
204
205         /* EA operations. */
206         SMB_VFS_OP_GETXATTR,
207         SMB_VFS_OP_FGETXATTR,
208         SMB_VFS_OP_LISTXATTR,
209         SMB_VFS_OP_FLISTXATTR,
210         SMB_VFS_OP_REMOVEXATTR,
211         SMB_VFS_OP_FREMOVEXATTR,
212         SMB_VFS_OP_SETXATTR,
213         SMB_VFS_OP_FSETXATTR,
214
215         /* aio operations */
216         SMB_VFS_OP_AIO_FORCE,
217
218         /* offline operations */
219         SMB_VFS_OP_IS_OFFLINE,
220         SMB_VFS_OP_SET_OFFLINE,
221
222         /* Durable handle operations. */
223         SMB_VFS_OP_DURABLE_COOKIE,
224         SMB_VFS_OP_DURABLE_DISCONNECT,
225         SMB_VFS_OP_DURABLE_RECONNECT,
226
227         SMB_VFS_OP_READDIR_ATTR,
228
229         /* This should always be last enum value */
230
231         SMB_VFS_OP_LAST
232 } vfs_op_type;
233
234 /* The following array *must* be in the same order as defined in vfs_op_type */
235
236 static struct {
237         vfs_op_type type;
238         const char *name;
239 } vfs_op_names[] = {
240         { SMB_VFS_OP_CONNECT,   "connect" },
241         { SMB_VFS_OP_DISCONNECT,        "disconnect" },
242         { SMB_VFS_OP_DISK_FREE, "disk_free" },
243         { SMB_VFS_OP_GET_QUOTA, "get_quota" },
244         { SMB_VFS_OP_SET_QUOTA, "set_quota" },
245         { SMB_VFS_OP_GET_SHADOW_COPY_DATA,      "get_shadow_copy_data" },
246         { SMB_VFS_OP_STATVFS,   "statvfs" },
247         { SMB_VFS_OP_FS_CAPABILITIES,   "fs_capabilities" },
248         { SMB_VFS_OP_GET_DFS_REFERRALS, "get_dfs_referrals" },
249         { SMB_VFS_OP_OPENDIR,   "opendir" },
250         { SMB_VFS_OP_FDOPENDIR, "fdopendir" },
251         { SMB_VFS_OP_READDIR,   "readdir" },
252         { SMB_VFS_OP_SEEKDIR,   "seekdir" },
253         { SMB_VFS_OP_TELLDIR,   "telldir" },
254         { SMB_VFS_OP_REWINDDIR, "rewinddir" },
255         { SMB_VFS_OP_MKDIR,     "mkdir" },
256         { SMB_VFS_OP_RMDIR,     "rmdir" },
257         { SMB_VFS_OP_CLOSEDIR,  "closedir" },
258         { SMB_VFS_OP_INIT_SEARCH_OP, "init_search_op" },
259         { SMB_VFS_OP_OPEN,      "open" },
260         { SMB_VFS_OP_CREATE_FILE, "create_file" },
261         { SMB_VFS_OP_CLOSE,     "close" },
262         { SMB_VFS_OP_READ,      "read" },
263         { SMB_VFS_OP_PREAD,     "pread" },
264         { SMB_VFS_OP_PREAD_SEND,        "pread_send" },
265         { SMB_VFS_OP_PREAD_RECV,        "pread_recv" },
266         { SMB_VFS_OP_WRITE,     "write" },
267         { SMB_VFS_OP_PWRITE,    "pwrite" },
268         { SMB_VFS_OP_PWRITE_SEND,       "pwrite_send" },
269         { SMB_VFS_OP_PWRITE_RECV,       "pwrite_recv" },
270         { SMB_VFS_OP_LSEEK,     "lseek" },
271         { SMB_VFS_OP_SENDFILE,  "sendfile" },
272         { SMB_VFS_OP_RECVFILE,  "recvfile" },
273         { SMB_VFS_OP_RENAME,    "rename" },
274         { SMB_VFS_OP_FSYNC,     "fsync" },
275         { SMB_VFS_OP_FSYNC_SEND,        "fsync_send" },
276         { SMB_VFS_OP_FSYNC_RECV,        "fsync_recv" },
277         { SMB_VFS_OP_STAT,      "stat" },
278         { SMB_VFS_OP_FSTAT,     "fstat" },
279         { SMB_VFS_OP_LSTAT,     "lstat" },
280         { SMB_VFS_OP_GET_ALLOC_SIZE,    "get_alloc_size" },
281         { SMB_VFS_OP_UNLINK,    "unlink" },
282         { SMB_VFS_OP_CHMOD,     "chmod" },
283         { SMB_VFS_OP_FCHMOD,    "fchmod" },
284         { SMB_VFS_OP_CHOWN,     "chown" },
285         { SMB_VFS_OP_FCHOWN,    "fchown" },
286         { SMB_VFS_OP_LCHOWN,    "lchown" },
287         { SMB_VFS_OP_CHDIR,     "chdir" },
288         { SMB_VFS_OP_GETWD,     "getwd" },
289         { SMB_VFS_OP_NTIMES,    "ntimes" },
290         { SMB_VFS_OP_FTRUNCATE, "ftruncate" },
291         { SMB_VFS_OP_FALLOCATE,"fallocate" },
292         { SMB_VFS_OP_LOCK,      "lock" },
293         { SMB_VFS_OP_KERNEL_FLOCK,      "kernel_flock" },
294         { SMB_VFS_OP_LINUX_SETLEASE, "linux_setlease" },
295         { SMB_VFS_OP_GETLOCK,   "getlock" },
296         { SMB_VFS_OP_SYMLINK,   "symlink" },
297         { SMB_VFS_OP_READLINK,  "readlink" },
298         { SMB_VFS_OP_LINK,      "link" },
299         { SMB_VFS_OP_MKNOD,     "mknod" },
300         { SMB_VFS_OP_REALPATH,  "realpath" },
301         { SMB_VFS_OP_CHFLAGS,   "chflags" },
302         { SMB_VFS_OP_FILE_ID_CREATE,    "file_id_create" },
303         { SMB_VFS_OP_STREAMINFO,        "streaminfo" },
304         { SMB_VFS_OP_GET_REAL_FILENAME, "get_real_filename" },
305         { SMB_VFS_OP_CONNECTPATH,       "connectpath" },
306         { SMB_VFS_OP_BRL_LOCK_WINDOWS,  "brl_lock_windows" },
307         { SMB_VFS_OP_BRL_UNLOCK_WINDOWS, "brl_unlock_windows" },
308         { SMB_VFS_OP_BRL_CANCEL_WINDOWS, "brl_cancel_windows" },
309         { SMB_VFS_OP_STRICT_LOCK, "strict_lock" },
310         { SMB_VFS_OP_STRICT_UNLOCK, "strict_unlock" },
311         { SMB_VFS_OP_TRANSLATE_NAME,    "translate_name" },
312         { SMB_VFS_OP_FSCTL,             "fsctl" },
313         { SMB_VFS_OP_COPY_CHUNK_SEND,   "copy_chunk_send" },
314         { SMB_VFS_OP_COPY_CHUNK_RECV,   "copy_chunk_recv" },
315         { SMB_VFS_OP_GET_COMPRESSION,   "get_compression" },
316         { SMB_VFS_OP_SET_COMPRESSION,   "set_compression" },
317         { SMB_VFS_OP_SNAP_CHECK_PATH, "snap_check_path" },
318         { SMB_VFS_OP_SNAP_CREATE, "snap_create" },
319         { SMB_VFS_OP_SNAP_DELETE, "snap_delete" },
320         { SMB_VFS_OP_GET_DOS_ATTRIBUTES, "get_dos_attributes" },
321         { SMB_VFS_OP_FGET_DOS_ATTRIBUTES, "fget_dos_attributes" },
322         { SMB_VFS_OP_SET_DOS_ATTRIBUTES, "set_dos_attributes" },
323         { SMB_VFS_OP_FSET_DOS_ATTRIBUTES, "fset_dos_attributes" },
324         { SMB_VFS_OP_FGET_NT_ACL,       "fget_nt_acl" },
325         { SMB_VFS_OP_GET_NT_ACL,        "get_nt_acl" },
326         { SMB_VFS_OP_FSET_NT_ACL,       "fset_nt_acl" },
327         { SMB_VFS_OP_AUDIT_FILE,        "audit_file" },
328         { SMB_VFS_OP_CHMOD_ACL, "chmod_acl" },
329         { SMB_VFS_OP_FCHMOD_ACL,        "fchmod_acl" },
330         { SMB_VFS_OP_SYS_ACL_GET_FILE,  "sys_acl_get_file" },
331         { SMB_VFS_OP_SYS_ACL_GET_FD,    "sys_acl_get_fd" },
332         { SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE,     "sys_acl_blob_get_file" },
333         { SMB_VFS_OP_SYS_ACL_BLOB_GET_FD,       "sys_acl_blob_get_fd" },
334         { SMB_VFS_OP_SYS_ACL_SET_FILE,  "sys_acl_set_file" },
335         { SMB_VFS_OP_SYS_ACL_SET_FD,    "sys_acl_set_fd" },
336         { SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE,   "sys_acl_delete_def_file" },
337         { SMB_VFS_OP_GETXATTR,  "getxattr" },
338         { SMB_VFS_OP_FGETXATTR, "fgetxattr" },
339         { SMB_VFS_OP_LISTXATTR, "listxattr" },
340         { SMB_VFS_OP_FLISTXATTR,        "flistxattr" },
341         { SMB_VFS_OP_REMOVEXATTR,       "removexattr" },
342         { SMB_VFS_OP_FREMOVEXATTR,      "fremovexattr" },
343         { SMB_VFS_OP_SETXATTR,  "setxattr" },
344         { SMB_VFS_OP_FSETXATTR, "fsetxattr" },
345         { SMB_VFS_OP_AIO_FORCE, "aio_force" },
346         { SMB_VFS_OP_IS_OFFLINE, "is_offline" },
347         { SMB_VFS_OP_SET_OFFLINE, "set_offline" },
348         { SMB_VFS_OP_DURABLE_COOKIE, "durable_cookie" },
349         { SMB_VFS_OP_DURABLE_DISCONNECT, "durable_disconnect" },
350         { SMB_VFS_OP_DURABLE_RECONNECT, "durable_reconnect" },
351         { SMB_VFS_OP_READDIR_ATTR,      "readdir_attr" },
352         { SMB_VFS_OP_LAST, NULL }
353 };
354
355 static int audit_syslog_facility(vfs_handle_struct *handle)
356 {
357         static const struct enum_list enum_log_facilities[] = {
358                 { LOG_USER, "USER" },
359                 { LOG_LOCAL0, "LOCAL0" },
360                 { LOG_LOCAL1, "LOCAL1" },
361                 { LOG_LOCAL2, "LOCAL2" },
362                 { LOG_LOCAL3, "LOCAL3" },
363                 { LOG_LOCAL4, "LOCAL4" },
364                 { LOG_LOCAL5, "LOCAL5" },
365                 { LOG_LOCAL6, "LOCAL6" },
366                 { LOG_LOCAL7, "LOCAL7" },
367                 { -1, NULL}
368         };
369
370         int facility;
371
372         facility = lp_parm_enum(SNUM(handle->conn), "full_audit", "facility", enum_log_facilities, LOG_USER);
373
374         return facility;
375 }
376
377 static int audit_syslog_priority(vfs_handle_struct *handle)
378 {
379         static const struct enum_list enum_log_priorities[] = {
380                 { LOG_EMERG, "EMERG" },
381                 { LOG_ALERT, "ALERT" },
382                 { LOG_CRIT, "CRIT" },
383                 { LOG_ERR, "ERR" },
384                 { LOG_WARNING, "WARNING" },
385                 { LOG_NOTICE, "NOTICE" },
386                 { LOG_INFO, "INFO" },
387                 { LOG_DEBUG, "DEBUG" },
388                 { -1, NULL}
389         };
390
391         int priority;
392
393         priority = lp_parm_enum(SNUM(handle->conn), "full_audit", "priority",
394                                 enum_log_priorities, LOG_NOTICE);
395         if (priority == -1) {
396                 priority = LOG_WARNING;
397         }
398
399         return priority;
400 }
401
402 static char *audit_prefix(TALLOC_CTX *ctx, connection_struct *conn)
403 {
404         char *prefix = NULL;
405         char *result;
406
407         prefix = talloc_strdup(ctx,
408                         lp_parm_const_string(SNUM(conn), "full_audit",
409                                              "prefix", "%u|%I"));
410         if (!prefix) {
411                 return NULL;
412         }
413         result = talloc_sub_advanced(ctx,
414                         lp_servicename(talloc_tos(), SNUM(conn)),
415                         conn->session_info->unix_info->unix_name,
416                         conn->connectpath,
417                         conn->session_info->unix_token->gid,
418                         conn->session_info->unix_info->sanitized_username,
419                         conn->session_info->info->domain_name,
420                         prefix);
421         TALLOC_FREE(prefix);
422         return result;
423 }
424
425 static bool log_success(struct vfs_full_audit_private_data *pd, vfs_op_type op)
426 {
427         if (pd->success_ops == NULL) {
428                 return True;
429         }
430
431         return bitmap_query(pd->success_ops, op);
432 }
433
434 static bool log_failure(struct vfs_full_audit_private_data *pd, vfs_op_type op)
435 {
436         if (pd->failure_ops == NULL)
437                 return True;
438
439         return bitmap_query(pd->failure_ops, op);
440 }
441
442 static struct bitmap *init_bitmap(TALLOC_CTX *mem_ctx, const char **ops)
443 {
444         struct bitmap *bm;
445
446         if (ops == NULL) {
447                 return NULL;
448         }
449
450         bm = bitmap_talloc(mem_ctx, SMB_VFS_OP_LAST);
451         if (bm == NULL) {
452                 DEBUG(0, ("Could not alloc bitmap -- "
453                           "defaulting to logging everything\n"));
454                 return NULL;
455         }
456
457         for (; *ops != NULL; ops += 1) {
458                 int i;
459                 bool neg = false;
460                 const char *op;
461
462                 if (strequal(*ops, "all")) {
463                         for (i=0; i<SMB_VFS_OP_LAST; i++) {
464                                 bitmap_set(bm, i);
465                         }
466                         continue;
467                 }
468
469                 if (strequal(*ops, "none")) {
470                         break;
471                 }
472
473                 op = ops[0];
474                 if (op[0] == '!') {
475                         neg = true;
476                         op += 1;
477                 }
478
479                 for (i=0; i<SMB_VFS_OP_LAST; i++) {
480                         if ((vfs_op_names[i].name == NULL)
481                          || (vfs_op_names[i].type != i)) {
482                                 smb_panic("vfs_full_audit.c: name table not "
483                                           "in sync with vfs_op_type enums\n");
484                         }
485                         if (strequal(op, vfs_op_names[i].name)) {
486                                 if (neg) {
487                                         bitmap_clear(bm, i);
488                                 } else {
489                                         bitmap_set(bm, i);
490                                 }
491                                 break;
492                         }
493                 }
494                 if (i == SMB_VFS_OP_LAST) {
495                         DEBUG(0, ("Could not find opname %s, logging all\n",
496                                   *ops));
497                         TALLOC_FREE(bm);
498                         return NULL;
499                 }
500         }
501         return bm;
502 }
503
504 static const char *audit_opname(vfs_op_type op)
505 {
506         if (op >= SMB_VFS_OP_LAST)
507                 return "INVALID VFS OP";
508         return vfs_op_names[op].name;
509 }
510
511 static TALLOC_CTX *tmp_do_log_ctx;
512 /*
513  * Get us a temporary talloc context usable just for DEBUG arguments
514  */
515 static TALLOC_CTX *do_log_ctx(void)
516 {
517         if (tmp_do_log_ctx == NULL) {
518                 tmp_do_log_ctx = talloc_named_const(NULL, 0, "do_log_ctx");
519         }
520         return tmp_do_log_ctx;
521 }
522
523 static void do_log(vfs_op_type op, bool success, vfs_handle_struct *handle,
524                    const char *format, ...)
525 {
526         struct vfs_full_audit_private_data *pd;
527         fstring err_msg;
528         char *audit_pre = NULL;
529         va_list ap;
530         char *op_msg = NULL;
531
532         SMB_VFS_HANDLE_GET_DATA(handle, pd,
533                                 struct vfs_full_audit_private_data,
534                                 return;);
535
536         if (success && (!log_success(pd, op)))
537                 goto out;
538
539         if (!success && (!log_failure(pd, op)))
540                 goto out;
541
542         if (success)
543                 fstrcpy(err_msg, "ok");
544         else
545                 fstr_sprintf(err_msg, "fail (%s)", strerror(errno));
546
547         va_start(ap, format);
548         op_msg = talloc_vasprintf(talloc_tos(), format, ap);
549         va_end(ap);
550
551         if (!op_msg) {
552                 goto out;
553         }
554
555         audit_pre = audit_prefix(talloc_tos(), handle->conn);
556
557         if (pd->do_syslog) {
558                 int priority;
559
560                 /*
561                  * Specify the facility to interoperate with other syslog
562                  * callers (smbd for example).
563                  */
564                 priority = pd->syslog_priority | pd->syslog_facility;
565
566                 syslog(priority, "%s|%s|%s|%s\n",
567                        audit_pre ? audit_pre : "",
568                        audit_opname(op), err_msg, op_msg);
569         } else {
570                 DEBUG(1, ("%s|%s|%s|%s\n",
571                           audit_pre ? audit_pre : "",
572                           audit_opname(op), err_msg, op_msg));
573         }
574  out:
575         TALLOC_FREE(audit_pre);
576         TALLOC_FREE(op_msg);
577         TALLOC_FREE(tmp_do_log_ctx);
578 }
579
580 /**
581  * Return a string using the do_log_ctx()
582  */
583 static const char *smb_fname_str_do_log(const struct smb_filename *smb_fname)
584 {
585         char *fname = NULL;
586         NTSTATUS status;
587
588         if (smb_fname == NULL) {
589                 return "";
590         }
591         status = get_full_smb_filename(do_log_ctx(), smb_fname, &fname);
592         if (!NT_STATUS_IS_OK(status)) {
593                 return "";
594         }
595         return fname;
596 }
597
598 /**
599  * Return an fsp debug string using the do_log_ctx()
600  */
601 static const char *fsp_str_do_log(const struct files_struct *fsp)
602 {
603         return smb_fname_str_do_log(fsp->fsp_name);
604 }
605
606 /* Implementation of vfs_ops.  Pass everything on to the default
607    operation but log event first. */
608
609 static int smb_full_audit_connect(vfs_handle_struct *handle,
610                          const char *svc, const char *user)
611 {
612         int result;
613         struct vfs_full_audit_private_data *pd = NULL;
614
615         result = SMB_VFS_NEXT_CONNECT(handle, svc, user);
616         if (result < 0) {
617                 return result;
618         }
619
620         pd = talloc_zero(handle, struct vfs_full_audit_private_data);
621         if (!pd) {
622                 SMB_VFS_NEXT_DISCONNECT(handle);
623                 return -1;
624         }
625
626         pd->syslog_facility = audit_syslog_facility(handle);
627         if (pd->syslog_facility == -1) {
628                 DEBUG(1, ("%s: Unknown facility %s\n", __func__,
629                           lp_parm_const_string(SNUM(handle->conn),
630                                                "full_audit", "facility",
631                                                "USER")));
632                 SMB_VFS_NEXT_DISCONNECT(handle);
633                 return -1;
634         }
635
636         pd->syslog_priority = audit_syslog_priority(handle);
637
638         pd->log_secdesc = lp_parm_bool(SNUM(handle->conn),
639                                        "full_audit", "log_secdesc", false);
640
641         pd->do_syslog = lp_parm_bool(SNUM(handle->conn),
642                                      "full_audit", "syslog", true);
643
644 #ifdef WITH_SYSLOG
645         if (pd->do_syslog) {
646                 openlog("smbd_audit", 0, pd->syslog_facility);
647         }
648 #endif
649
650         pd->success_ops = init_bitmap(
651                 pd, lp_parm_string_list(SNUM(handle->conn), "full_audit",
652                                         "success", NULL));
653         pd->failure_ops = init_bitmap(
654                 pd, lp_parm_string_list(SNUM(handle->conn), "full_audit",
655                                         "failure", NULL));
656
657         /* Store the private data. */
658         SMB_VFS_HANDLE_SET_DATA(handle, pd, NULL,
659                                 struct vfs_full_audit_private_data, return -1);
660
661         do_log(SMB_VFS_OP_CONNECT, True, handle,
662                "%s", svc);
663
664         return 0;
665 }
666
667 static void smb_full_audit_disconnect(vfs_handle_struct *handle)
668 {
669         SMB_VFS_NEXT_DISCONNECT(handle);
670
671         do_log(SMB_VFS_OP_DISCONNECT, True, handle,
672                "%s", lp_servicename(talloc_tos(), SNUM(handle->conn)));
673
674         /* The bitmaps will be disconnected when the private
675            data is deleted. */
676 }
677
678 static uint64_t smb_full_audit_disk_free(vfs_handle_struct *handle,
679                                     const char *path, uint64_t *bsize,
680                                     uint64_t *dfree, uint64_t *dsize)
681 {
682         uint64_t result;
683
684         result = SMB_VFS_NEXT_DISK_FREE(handle, path, bsize, dfree, dsize);
685
686         /* Don't have a reasonable notion of failure here */
687
688         do_log(SMB_VFS_OP_DISK_FREE, True, handle, "%s", path);
689
690         return result;
691 }
692
693 static int smb_full_audit_get_quota(struct vfs_handle_struct *handle,
694                                     const char *path, enum SMB_QUOTA_TYPE qtype,
695                                     unid_t id, SMB_DISK_QUOTA *qt)
696 {
697         int result;
698
699         result = SMB_VFS_NEXT_GET_QUOTA(handle, path, qtype, id, qt);
700
701         do_log(SMB_VFS_OP_GET_QUOTA, (result >= 0), handle, "%s", path);
702
703         return result;
704 }
705
706 static int smb_full_audit_set_quota(struct vfs_handle_struct *handle,
707                            enum SMB_QUOTA_TYPE qtype, unid_t id,
708                            SMB_DISK_QUOTA *qt)
709 {
710         int result;
711
712         result = SMB_VFS_NEXT_SET_QUOTA(handle, qtype, id, qt);
713
714         do_log(SMB_VFS_OP_SET_QUOTA, (result >= 0), handle, "");
715
716         return result;
717 }
718
719 static int smb_full_audit_get_shadow_copy_data(struct vfs_handle_struct *handle,
720                                 struct files_struct *fsp,
721                                 struct shadow_copy_data *shadow_copy_data,
722                                 bool labels)
723 {
724         int result;
725
726         result = SMB_VFS_NEXT_GET_SHADOW_COPY_DATA(handle, fsp, shadow_copy_data, labels);
727
728         do_log(SMB_VFS_OP_GET_SHADOW_COPY_DATA, (result >= 0), handle, "");
729
730         return result;
731 }
732
733 static int smb_full_audit_statvfs(struct vfs_handle_struct *handle,
734                                 const char *path,
735                                 struct vfs_statvfs_struct *statbuf)
736 {
737         int result;
738
739         result = SMB_VFS_NEXT_STATVFS(handle, path, statbuf);
740
741         do_log(SMB_VFS_OP_STATVFS, (result >= 0), handle, "");
742
743         return result;
744 }
745
746 static uint32_t smb_full_audit_fs_capabilities(struct vfs_handle_struct *handle, enum timestamp_set_resolution *p_ts_res)
747 {
748         int result;
749
750         result = SMB_VFS_NEXT_FS_CAPABILITIES(handle, p_ts_res);
751
752         do_log(SMB_VFS_OP_FS_CAPABILITIES, true, handle, "");
753
754         return result;
755 }
756
757 static NTSTATUS smb_full_audit_get_dfs_referrals(
758                                 struct vfs_handle_struct *handle,
759                                 struct dfs_GetDFSReferral *r)
760 {
761         NTSTATUS status;
762
763         status = SMB_VFS_NEXT_GET_DFS_REFERRALS(handle, r);
764
765         do_log(SMB_VFS_OP_GET_DFS_REFERRALS, NT_STATUS_IS_OK(status),
766                handle, "");
767
768         return status;
769 }
770
771 static NTSTATUS smb_full_audit_snap_check_path(struct vfs_handle_struct *handle,
772                                                TALLOC_CTX *mem_ctx,
773                                                const char *service_path,
774                                                char **base_volume)
775 {
776         NTSTATUS status;
777
778         status = SMB_VFS_NEXT_SNAP_CHECK_PATH(handle, mem_ctx, service_path,
779                                               base_volume);
780         do_log(SMB_VFS_OP_SNAP_CHECK_PATH, NT_STATUS_IS_OK(status),
781                handle, "");
782
783         return status;
784 }
785
786 static NTSTATUS smb_full_audit_snap_create(struct vfs_handle_struct *handle,
787                                            TALLOC_CTX *mem_ctx,
788                                            const char *base_volume,
789                                            time_t *tstamp,
790                                            bool rw,
791                                            char **base_path,
792                                            char **snap_path)
793 {
794         NTSTATUS status;
795
796         status = SMB_VFS_NEXT_SNAP_CREATE(handle, mem_ctx, base_volume, tstamp,
797                                           rw, base_path, snap_path);
798         do_log(SMB_VFS_OP_SNAP_CREATE, NT_STATUS_IS_OK(status), handle, "");
799
800         return status;
801 }
802
803 static NTSTATUS smb_full_audit_snap_delete(struct vfs_handle_struct *handle,
804                                            TALLOC_CTX *mem_ctx,
805                                            char *base_path,
806                                            char *snap_path)
807 {
808         NTSTATUS status;
809
810         status = SMB_VFS_NEXT_SNAP_DELETE(handle, mem_ctx, base_path,
811                                           snap_path);
812         do_log(SMB_VFS_OP_SNAP_DELETE, NT_STATUS_IS_OK(status), handle, "");
813
814         return status;
815 }
816
817 static DIR *smb_full_audit_opendir(vfs_handle_struct *handle,
818                         const struct smb_filename *smb_fname,
819                         const char *mask,
820                         uint32_t attr)
821 {
822         DIR *result;
823
824         result = SMB_VFS_NEXT_OPENDIR(handle, smb_fname, mask, attr);
825
826         do_log(SMB_VFS_OP_OPENDIR, (result != NULL), handle, "%s",
827                 smb_fname->base_name);
828
829         return result;
830 }
831
832 static DIR *smb_full_audit_fdopendir(vfs_handle_struct *handle,
833                           files_struct *fsp, const char *mask, uint32_t attr)
834 {
835         DIR *result;
836
837         result = SMB_VFS_NEXT_FDOPENDIR(handle, fsp, mask, attr);
838
839         do_log(SMB_VFS_OP_FDOPENDIR, (result != NULL), handle, "%s",
840                         fsp_str_do_log(fsp));
841
842         return result;
843 }
844
845 static struct dirent *smb_full_audit_readdir(vfs_handle_struct *handle,
846                                     DIR *dirp, SMB_STRUCT_STAT *sbuf)
847 {
848         struct dirent *result;
849
850         result = SMB_VFS_NEXT_READDIR(handle, dirp, sbuf);
851
852         /* This operation has no reasonable error condition
853          * (End of dir is also failure), so always succeed.
854          */
855         do_log(SMB_VFS_OP_READDIR, True, handle, "");
856
857         return result;
858 }
859
860 static void smb_full_audit_seekdir(vfs_handle_struct *handle,
861                         DIR *dirp, long offset)
862 {
863         SMB_VFS_NEXT_SEEKDIR(handle, dirp, offset);
864
865         do_log(SMB_VFS_OP_SEEKDIR, True, handle, "");
866 }
867
868 static long smb_full_audit_telldir(vfs_handle_struct *handle,
869                         DIR *dirp)
870 {
871         long result;
872
873         result = SMB_VFS_NEXT_TELLDIR(handle, dirp);
874
875         do_log(SMB_VFS_OP_TELLDIR, True, handle, "");
876
877         return result;
878 }
879
880 static void smb_full_audit_rewinddir(vfs_handle_struct *handle,
881                         DIR *dirp)
882 {
883         SMB_VFS_NEXT_REWINDDIR(handle, dirp);
884
885         do_log(SMB_VFS_OP_REWINDDIR, True, handle, "");
886 }
887
888 static int smb_full_audit_mkdir(vfs_handle_struct *handle,
889                        const struct smb_filename *smb_fname, mode_t mode)
890 {
891         int result;
892         
893         result = SMB_VFS_NEXT_MKDIR(handle, smb_fname, mode);
894         
895         do_log(SMB_VFS_OP_MKDIR, (result >= 0), handle, "%s",
896                 smb_fname->base_name);
897
898         return result;
899 }
900
901 static int smb_full_audit_rmdir(vfs_handle_struct *handle,
902                        const struct smb_filename *smb_fname)
903 {
904         int result;
905         
906         result = SMB_VFS_NEXT_RMDIR(handle, smb_fname);
907
908         do_log(SMB_VFS_OP_RMDIR, (result >= 0), handle, "%s",
909                 smb_fname->base_name);
910
911         return result;
912 }
913
914 static int smb_full_audit_closedir(vfs_handle_struct *handle,
915                           DIR *dirp)
916 {
917         int result;
918
919         result = SMB_VFS_NEXT_CLOSEDIR(handle, dirp);
920         
921         do_log(SMB_VFS_OP_CLOSEDIR, (result >= 0), handle, "");
922
923         return result;
924 }
925
926 static void smb_full_audit_init_search_op(vfs_handle_struct *handle,
927                         DIR *dirp)
928 {
929         SMB_VFS_NEXT_INIT_SEARCH_OP(handle, dirp);
930
931         do_log(SMB_VFS_OP_INIT_SEARCH_OP, True, handle, "");
932 }
933
934 static int smb_full_audit_open(vfs_handle_struct *handle,
935                                struct smb_filename *smb_fname,
936                                files_struct *fsp, int flags, mode_t mode)
937 {
938         int result;
939         
940         result = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
941
942         do_log(SMB_VFS_OP_OPEN, (result >= 0), handle, "%s|%s",
943                ((flags & O_WRONLY) || (flags & O_RDWR))?"w":"r",
944                smb_fname_str_do_log(smb_fname));
945
946         return result;
947 }
948
949 static NTSTATUS smb_full_audit_create_file(vfs_handle_struct *handle,
950                                       struct smb_request *req,
951                                       uint16_t root_dir_fid,
952                                       struct smb_filename *smb_fname,
953                                       uint32_t access_mask,
954                                       uint32_t share_access,
955                                       uint32_t create_disposition,
956                                       uint32_t create_options,
957                                       uint32_t file_attributes,
958                                       uint32_t oplock_request,
959                                       struct smb2_lease *lease,
960                                       uint64_t allocation_size,
961                                       uint32_t private_flags,
962                                       struct security_descriptor *sd,
963                                       struct ea_list *ea_list,
964                                       files_struct **result_fsp,
965                                       int *pinfo,
966                                       const struct smb2_create_blobs *in_context_blobs,
967                                       struct smb2_create_blobs *out_context_blobs)
968 {
969         NTSTATUS result;
970         const char* str_create_disposition;
971
972         switch (create_disposition) {
973         case FILE_SUPERSEDE:
974                 str_create_disposition = "supersede";
975                 break;
976         case FILE_OVERWRITE_IF:
977                 str_create_disposition = "overwrite_if";
978                 break;
979         case FILE_OPEN:
980                 str_create_disposition = "open";
981                 break;
982         case FILE_OVERWRITE:
983                 str_create_disposition = "overwrite";
984                 break;
985         case FILE_CREATE:
986                 str_create_disposition = "create";
987                 break;
988         case FILE_OPEN_IF:
989                 str_create_disposition = "open_if";
990                 break;
991         default:
992                 str_create_disposition = "unknown";
993         }
994
995         result = SMB_VFS_NEXT_CREATE_FILE(
996                 handle,                                 /* handle */
997                 req,                                    /* req */
998                 root_dir_fid,                           /* root_dir_fid */
999                 smb_fname,                              /* fname */
1000                 access_mask,                            /* access_mask */
1001                 share_access,                           /* share_access */
1002                 create_disposition,                     /* create_disposition*/
1003                 create_options,                         /* create_options */
1004                 file_attributes,                        /* file_attributes */
1005                 oplock_request,                         /* oplock_request */
1006                 lease,                                  /* lease */
1007                 allocation_size,                        /* allocation_size */
1008                 private_flags,
1009                 sd,                                     /* sd */
1010                 ea_list,                                /* ea_list */
1011                 result_fsp,                             /* result */
1012                 pinfo,                                  /* pinfo */
1013                 in_context_blobs, out_context_blobs);   /* create context */
1014
1015         do_log(SMB_VFS_OP_CREATE_FILE, (NT_STATUS_IS_OK(result)), handle,
1016                "0x%x|%s|%s|%s", access_mask,
1017                create_options & FILE_DIRECTORY_FILE ? "dir" : "file",
1018                str_create_disposition, smb_fname_str_do_log(smb_fname));
1019
1020         return result;
1021 }
1022
1023 static int smb_full_audit_close(vfs_handle_struct *handle, files_struct *fsp)
1024 {
1025         int result;
1026         
1027         result = SMB_VFS_NEXT_CLOSE(handle, fsp);
1028
1029         do_log(SMB_VFS_OP_CLOSE, (result >= 0), handle, "%s",
1030                fsp_str_do_log(fsp));
1031
1032         return result;
1033 }
1034
1035 static ssize_t smb_full_audit_read(vfs_handle_struct *handle, files_struct *fsp,
1036                           void *data, size_t n)
1037 {
1038         ssize_t result;
1039
1040         result = SMB_VFS_NEXT_READ(handle, fsp, data, n);
1041
1042         do_log(SMB_VFS_OP_READ, (result >= 0), handle, "%s",
1043                fsp_str_do_log(fsp));
1044
1045         return result;
1046 }
1047
1048 static ssize_t smb_full_audit_pread(vfs_handle_struct *handle, files_struct *fsp,
1049                            void *data, size_t n, off_t offset)
1050 {
1051         ssize_t result;
1052
1053         result = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
1054
1055         do_log(SMB_VFS_OP_PREAD, (result >= 0), handle, "%s",
1056                fsp_str_do_log(fsp));
1057
1058         return result;
1059 }
1060
1061 struct smb_full_audit_pread_state {
1062         vfs_handle_struct *handle;
1063         files_struct *fsp;
1064         ssize_t ret;
1065         struct vfs_aio_state vfs_aio_state;
1066 };
1067
1068 static void smb_full_audit_pread_done(struct tevent_req *subreq);
1069
1070 static struct tevent_req *smb_full_audit_pread_send(
1071         struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1072         struct tevent_context *ev, struct files_struct *fsp,
1073         void *data, size_t n, off_t offset)
1074 {
1075         struct tevent_req *req, *subreq;
1076         struct smb_full_audit_pread_state *state;
1077
1078         req = tevent_req_create(mem_ctx, &state,
1079                                 struct smb_full_audit_pread_state);
1080         if (req == NULL) {
1081                 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
1082                        fsp_str_do_log(fsp));
1083                 return NULL;
1084         }
1085         state->handle = handle;
1086         state->fsp = fsp;
1087
1088         subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
1089                                          n, offset);
1090         if (tevent_req_nomem(subreq, req)) {
1091                 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
1092                        fsp_str_do_log(fsp));
1093                 return tevent_req_post(req, ev);
1094         }
1095         tevent_req_set_callback(subreq, smb_full_audit_pread_done, req);
1096
1097         do_log(SMB_VFS_OP_PREAD_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1098         return req;
1099 }
1100
1101 static void smb_full_audit_pread_done(struct tevent_req *subreq)
1102 {
1103         struct tevent_req *req = tevent_req_callback_data(
1104                 subreq, struct tevent_req);
1105         struct smb_full_audit_pread_state *state = tevent_req_data(
1106                 req, struct smb_full_audit_pread_state);
1107
1108         state->ret = SMB_VFS_PREAD_RECV(subreq, &state->vfs_aio_state);
1109         TALLOC_FREE(subreq);
1110         tevent_req_done(req);
1111 }
1112
1113 static ssize_t smb_full_audit_pread_recv(struct tevent_req *req,
1114                                          struct vfs_aio_state *vfs_aio_state)
1115 {
1116         struct smb_full_audit_pread_state *state = tevent_req_data(
1117                 req, struct smb_full_audit_pread_state);
1118
1119         if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1120                 do_log(SMB_VFS_OP_PREAD_RECV, false, state->handle, "%s",
1121                        fsp_str_do_log(state->fsp));
1122                 return -1;
1123         }
1124
1125         do_log(SMB_VFS_OP_PREAD_RECV, (state->ret >= 0), state->handle, "%s",
1126                fsp_str_do_log(state->fsp));
1127
1128         *vfs_aio_state = state->vfs_aio_state;
1129         return state->ret;
1130 }
1131
1132 static ssize_t smb_full_audit_write(vfs_handle_struct *handle, files_struct *fsp,
1133                            const void *data, size_t n)
1134 {
1135         ssize_t result;
1136
1137         result = SMB_VFS_NEXT_WRITE(handle, fsp, data, n);
1138
1139         do_log(SMB_VFS_OP_WRITE, (result >= 0), handle, "%s",
1140                fsp_str_do_log(fsp));
1141
1142         return result;
1143 }
1144
1145 static ssize_t smb_full_audit_pwrite(vfs_handle_struct *handle, files_struct *fsp,
1146                             const void *data, size_t n,
1147                             off_t offset)
1148 {
1149         ssize_t result;
1150
1151         result = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
1152
1153         do_log(SMB_VFS_OP_PWRITE, (result >= 0), handle, "%s",
1154                fsp_str_do_log(fsp));
1155
1156         return result;
1157 }
1158
1159 struct smb_full_audit_pwrite_state {
1160         vfs_handle_struct *handle;
1161         files_struct *fsp;
1162         ssize_t ret;
1163         struct vfs_aio_state vfs_aio_state;
1164 };
1165
1166 static void smb_full_audit_pwrite_done(struct tevent_req *subreq);
1167
1168 static struct tevent_req *smb_full_audit_pwrite_send(
1169         struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1170         struct tevent_context *ev, struct files_struct *fsp,
1171         const void *data, size_t n, off_t offset)
1172 {
1173         struct tevent_req *req, *subreq;
1174         struct smb_full_audit_pwrite_state *state;
1175
1176         req = tevent_req_create(mem_ctx, &state,
1177                                 struct smb_full_audit_pwrite_state);
1178         if (req == NULL) {
1179                 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1180                        fsp_str_do_log(fsp));
1181                 return NULL;
1182         }
1183         state->handle = handle;
1184         state->fsp = fsp;
1185
1186         subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
1187                                          n, offset);
1188         if (tevent_req_nomem(subreq, req)) {
1189                 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1190                        fsp_str_do_log(fsp));
1191                 return tevent_req_post(req, ev);
1192         }
1193         tevent_req_set_callback(subreq, smb_full_audit_pwrite_done, req);
1194
1195         do_log(SMB_VFS_OP_PWRITE_SEND, true, handle, "%s",
1196                fsp_str_do_log(fsp));
1197         return req;
1198 }
1199
1200 static void smb_full_audit_pwrite_done(struct tevent_req *subreq)
1201 {
1202         struct tevent_req *req = tevent_req_callback_data(
1203                 subreq, struct tevent_req);
1204         struct smb_full_audit_pwrite_state *state = tevent_req_data(
1205                 req, struct smb_full_audit_pwrite_state);
1206
1207         state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->vfs_aio_state);
1208         TALLOC_FREE(subreq);
1209         tevent_req_done(req);
1210 }
1211
1212 static ssize_t smb_full_audit_pwrite_recv(struct tevent_req *req,
1213                                           struct vfs_aio_state *vfs_aio_state)
1214 {
1215         struct smb_full_audit_pwrite_state *state = tevent_req_data(
1216                 req, struct smb_full_audit_pwrite_state);
1217
1218         if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1219                 do_log(SMB_VFS_OP_PWRITE_RECV, false, state->handle, "%s",
1220                        fsp_str_do_log(state->fsp));
1221                 return -1;
1222         }
1223
1224         do_log(SMB_VFS_OP_PWRITE_RECV, (state->ret >= 0), state->handle, "%s",
1225                fsp_str_do_log(state->fsp));
1226
1227         *vfs_aio_state = state->vfs_aio_state;
1228         return state->ret;
1229 }
1230
1231 static off_t smb_full_audit_lseek(vfs_handle_struct *handle, files_struct *fsp,
1232                              off_t offset, int whence)
1233 {
1234         ssize_t result;
1235
1236         result = SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence);
1237
1238         do_log(SMB_VFS_OP_LSEEK, (result != (ssize_t)-1), handle,
1239                "%s", fsp_str_do_log(fsp));
1240
1241         return result;
1242 }
1243
1244 static ssize_t smb_full_audit_sendfile(vfs_handle_struct *handle, int tofd,
1245                               files_struct *fromfsp,
1246                               const DATA_BLOB *hdr, off_t offset,
1247                               size_t n)
1248 {
1249         ssize_t result;
1250
1251         result = SMB_VFS_NEXT_SENDFILE(handle, tofd, fromfsp, hdr, offset, n);
1252
1253         do_log(SMB_VFS_OP_SENDFILE, (result >= 0), handle,
1254                "%s", fsp_str_do_log(fromfsp));
1255
1256         return result;
1257 }
1258
1259 static ssize_t smb_full_audit_recvfile(vfs_handle_struct *handle, int fromfd,
1260                       files_struct *tofsp,
1261                               off_t offset,
1262                               size_t n)
1263 {
1264         ssize_t result;
1265
1266         result = SMB_VFS_NEXT_RECVFILE(handle, fromfd, tofsp, offset, n);
1267
1268         do_log(SMB_VFS_OP_RECVFILE, (result >= 0), handle,
1269                "%s", fsp_str_do_log(tofsp));
1270
1271         return result;
1272 }
1273
1274 static int smb_full_audit_rename(vfs_handle_struct *handle,
1275                                  const struct smb_filename *smb_fname_src,
1276                                  const struct smb_filename *smb_fname_dst)
1277 {
1278         int result;
1279         
1280         result = SMB_VFS_NEXT_RENAME(handle, smb_fname_src, smb_fname_dst);
1281
1282         do_log(SMB_VFS_OP_RENAME, (result >= 0), handle, "%s|%s",
1283                smb_fname_str_do_log(smb_fname_src),
1284                smb_fname_str_do_log(smb_fname_dst));
1285
1286         return result;    
1287 }
1288
1289 static int smb_full_audit_fsync(vfs_handle_struct *handle, files_struct *fsp)
1290 {
1291         int result;
1292         
1293         result = SMB_VFS_NEXT_FSYNC(handle, fsp);
1294
1295         do_log(SMB_VFS_OP_FSYNC, (result >= 0), handle, "%s",
1296                fsp_str_do_log(fsp));
1297
1298         return result;    
1299 }
1300
1301 struct smb_full_audit_fsync_state {
1302         vfs_handle_struct *handle;
1303         files_struct *fsp;
1304         int ret;
1305         struct vfs_aio_state vfs_aio_state;
1306 };
1307
1308 static void smb_full_audit_fsync_done(struct tevent_req *subreq);
1309
1310 static struct tevent_req *smb_full_audit_fsync_send(
1311         struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1312         struct tevent_context *ev, struct files_struct *fsp)
1313 {
1314         struct tevent_req *req, *subreq;
1315         struct smb_full_audit_fsync_state *state;
1316
1317         req = tevent_req_create(mem_ctx, &state,
1318                                 struct smb_full_audit_fsync_state);
1319         if (req == NULL) {
1320                 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1321                        fsp_str_do_log(fsp));
1322                 return NULL;
1323         }
1324         state->handle = handle;
1325         state->fsp = fsp;
1326
1327         subreq = SMB_VFS_NEXT_FSYNC_SEND(state, ev, handle, fsp);
1328         if (tevent_req_nomem(subreq, req)) {
1329                 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1330                        fsp_str_do_log(fsp));
1331                 return tevent_req_post(req, ev);
1332         }
1333         tevent_req_set_callback(subreq, smb_full_audit_fsync_done, req);
1334
1335         do_log(SMB_VFS_OP_FSYNC_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1336         return req;
1337 }
1338
1339 static void smb_full_audit_fsync_done(struct tevent_req *subreq)
1340 {
1341         struct tevent_req *req = tevent_req_callback_data(
1342                 subreq, struct tevent_req);
1343         struct smb_full_audit_fsync_state *state = tevent_req_data(
1344                 req, struct smb_full_audit_fsync_state);
1345
1346         state->ret = SMB_VFS_FSYNC_RECV(subreq, &state->vfs_aio_state);
1347         TALLOC_FREE(subreq);
1348         tevent_req_done(req);
1349 }
1350
1351 static int smb_full_audit_fsync_recv(struct tevent_req *req,
1352                                      struct vfs_aio_state *vfs_aio_state)
1353 {
1354         struct smb_full_audit_fsync_state *state = tevent_req_data(
1355                 req, struct smb_full_audit_fsync_state);
1356
1357         if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1358                 do_log(SMB_VFS_OP_FSYNC_RECV, false, state->handle, "%s",
1359                        fsp_str_do_log(state->fsp));
1360                 return -1;
1361         }
1362
1363         do_log(SMB_VFS_OP_FSYNC_RECV, (state->ret >= 0), state->handle, "%s",
1364                fsp_str_do_log(state->fsp));
1365
1366         *vfs_aio_state = state->vfs_aio_state;
1367         return state->ret;
1368 }
1369
1370 static int smb_full_audit_stat(vfs_handle_struct *handle,
1371                                struct smb_filename *smb_fname)
1372 {
1373         int result;
1374         
1375         result = SMB_VFS_NEXT_STAT(handle, smb_fname);
1376
1377         do_log(SMB_VFS_OP_STAT, (result >= 0), handle, "%s",
1378                smb_fname_str_do_log(smb_fname));
1379
1380         return result;    
1381 }
1382
1383 static int smb_full_audit_fstat(vfs_handle_struct *handle, files_struct *fsp,
1384                        SMB_STRUCT_STAT *sbuf)
1385 {
1386         int result;
1387         
1388         result = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1389
1390         do_log(SMB_VFS_OP_FSTAT, (result >= 0), handle, "%s",
1391                fsp_str_do_log(fsp));
1392
1393         return result;
1394 }
1395
1396 static int smb_full_audit_lstat(vfs_handle_struct *handle,
1397                                 struct smb_filename *smb_fname)
1398 {
1399         int result;
1400         
1401         result = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
1402
1403         do_log(SMB_VFS_OP_LSTAT, (result >= 0), handle, "%s",
1404                smb_fname_str_do_log(smb_fname));
1405
1406         return result;    
1407 }
1408
1409 static uint64_t smb_full_audit_get_alloc_size(vfs_handle_struct *handle,
1410                        files_struct *fsp, const SMB_STRUCT_STAT *sbuf)
1411 {
1412         uint64_t result;
1413
1414         result = SMB_VFS_NEXT_GET_ALLOC_SIZE(handle, fsp, sbuf);
1415
1416         do_log(SMB_VFS_OP_GET_ALLOC_SIZE, (result != (uint64_t)-1), handle,
1417                         "%llu", result);
1418
1419         return result;
1420 }
1421
1422 static int smb_full_audit_unlink(vfs_handle_struct *handle,
1423                                  const struct smb_filename *smb_fname)
1424 {
1425         int result;
1426         
1427         result = SMB_VFS_NEXT_UNLINK(handle, smb_fname);
1428
1429         do_log(SMB_VFS_OP_UNLINK, (result >= 0), handle, "%s",
1430                smb_fname_str_do_log(smb_fname));
1431
1432         return result;
1433 }
1434
1435 static int smb_full_audit_chmod(vfs_handle_struct *handle,
1436                                 const struct smb_filename *smb_fname,
1437                                 mode_t mode)
1438 {
1439         int result;
1440
1441         result = SMB_VFS_NEXT_CHMOD(handle, smb_fname, mode);
1442
1443         do_log(SMB_VFS_OP_CHMOD, (result >= 0), handle, "%s|%o",
1444                 smb_fname->base_name,
1445                 mode);
1446
1447         return result;
1448 }
1449
1450 static int smb_full_audit_fchmod(vfs_handle_struct *handle, files_struct *fsp,
1451                         mode_t mode)
1452 {
1453         int result;
1454         
1455         result = SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1456
1457         do_log(SMB_VFS_OP_FCHMOD, (result >= 0), handle,
1458                "%s|%o", fsp_str_do_log(fsp), mode);
1459
1460         return result;
1461 }
1462
1463 static int smb_full_audit_chown(vfs_handle_struct *handle,
1464                         const struct smb_filename *smb_fname,
1465                         uid_t uid,
1466                         gid_t gid)
1467 {
1468         int result;
1469
1470         result = SMB_VFS_NEXT_CHOWN(handle, smb_fname, uid, gid);
1471
1472         do_log(SMB_VFS_OP_CHOWN, (result >= 0), handle, "%s|%ld|%ld",
1473                smb_fname->base_name, (long int)uid, (long int)gid);
1474
1475         return result;
1476 }
1477
1478 static int smb_full_audit_fchown(vfs_handle_struct *handle, files_struct *fsp,
1479                         uid_t uid, gid_t gid)
1480 {
1481         int result;
1482
1483         result = SMB_VFS_NEXT_FCHOWN(handle, fsp, uid, gid);
1484
1485         do_log(SMB_VFS_OP_FCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1486                fsp_str_do_log(fsp), (long int)uid, (long int)gid);
1487
1488         return result;
1489 }
1490
1491 static int smb_full_audit_lchown(vfs_handle_struct *handle,
1492                         const struct smb_filename *smb_fname,
1493                         uid_t uid,
1494                         gid_t gid)
1495 {
1496         int result;
1497
1498         result = SMB_VFS_NEXT_LCHOWN(handle, smb_fname, uid, gid);
1499
1500         do_log(SMB_VFS_OP_LCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1501                smb_fname->base_name, (long int)uid, (long int)gid);
1502
1503         return result;
1504 }
1505
1506 static int smb_full_audit_chdir(vfs_handle_struct *handle,
1507                        const char *path)
1508 {
1509         int result;
1510
1511         result = SMB_VFS_NEXT_CHDIR(handle, path);
1512
1513         do_log(SMB_VFS_OP_CHDIR, (result >= 0), handle, "chdir|%s", path);
1514
1515         return result;
1516 }
1517
1518 static char *smb_full_audit_getwd(vfs_handle_struct *handle)
1519 {
1520         char *result;
1521
1522         result = SMB_VFS_NEXT_GETWD(handle);
1523         
1524         do_log(SMB_VFS_OP_GETWD, (result != NULL), handle, "%s",
1525                 result == NULL? "" : result);
1526
1527         return result;
1528 }
1529
1530 static int smb_full_audit_ntimes(vfs_handle_struct *handle,
1531                                  const struct smb_filename *smb_fname,
1532                                  struct smb_file_time *ft)
1533 {
1534         int result;
1535
1536         result = SMB_VFS_NEXT_NTIMES(handle, smb_fname, ft);
1537
1538         do_log(SMB_VFS_OP_NTIMES, (result >= 0), handle, "%s",
1539                smb_fname_str_do_log(smb_fname));
1540
1541         return result;
1542 }
1543
1544 static int smb_full_audit_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
1545                            off_t len)
1546 {
1547         int result;
1548
1549         result = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1550
1551         do_log(SMB_VFS_OP_FTRUNCATE, (result >= 0), handle,
1552                "%s", fsp_str_do_log(fsp));
1553
1554         return result;
1555 }
1556
1557 static int smb_full_audit_fallocate(vfs_handle_struct *handle, files_struct *fsp,
1558                            uint32_t mode,
1559                            off_t offset,
1560                            off_t len)
1561 {
1562         int result;
1563
1564         result = SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
1565
1566         do_log(SMB_VFS_OP_FALLOCATE, (result >= 0), handle,
1567                "%s", fsp_str_do_log(fsp));
1568
1569         return result;
1570 }
1571
1572 static bool smb_full_audit_lock(vfs_handle_struct *handle, files_struct *fsp,
1573                        int op, off_t offset, off_t count, int type)
1574 {
1575         bool result;
1576
1577         result = SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type);
1578
1579         do_log(SMB_VFS_OP_LOCK, result, handle, "%s", fsp_str_do_log(fsp));
1580
1581         return result;
1582 }
1583
1584 static int smb_full_audit_kernel_flock(struct vfs_handle_struct *handle,
1585                                        struct files_struct *fsp,
1586                                        uint32_t share_mode, uint32_t access_mask)
1587 {
1588         int result;
1589
1590         result = SMB_VFS_NEXT_KERNEL_FLOCK(handle, fsp, share_mode, access_mask);
1591
1592         do_log(SMB_VFS_OP_KERNEL_FLOCK, (result >= 0), handle, "%s",
1593                fsp_str_do_log(fsp));
1594
1595         return result;
1596 }
1597
1598 static int smb_full_audit_linux_setlease(vfs_handle_struct *handle, files_struct *fsp,
1599                                  int leasetype)
1600 {
1601         int result;
1602
1603         result = SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
1604
1605         do_log(SMB_VFS_OP_LINUX_SETLEASE, (result >= 0), handle, "%s",
1606                fsp_str_do_log(fsp));
1607
1608         return result;
1609 }
1610
1611 static bool smb_full_audit_getlock(vfs_handle_struct *handle, files_struct *fsp,
1612                        off_t *poffset, off_t *pcount, int *ptype, pid_t *ppid)
1613 {
1614         bool result;
1615
1616         result = SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype, ppid);
1617
1618         do_log(SMB_VFS_OP_GETLOCK, result, handle, "%s", fsp_str_do_log(fsp));
1619
1620         return result;
1621 }
1622
1623 static int smb_full_audit_symlink(vfs_handle_struct *handle,
1624                          const char *oldpath, const char *newpath)
1625 {
1626         int result;
1627
1628         result = SMB_VFS_NEXT_SYMLINK(handle, oldpath, newpath);
1629
1630         do_log(SMB_VFS_OP_SYMLINK, (result >= 0), handle,
1631                "%s|%s", oldpath, newpath);
1632
1633         return result;
1634 }
1635
1636 static int smb_full_audit_readlink(vfs_handle_struct *handle,
1637                           const char *path, char *buf, size_t bufsiz)
1638 {
1639         int result;
1640
1641         result = SMB_VFS_NEXT_READLINK(handle, path, buf, bufsiz);
1642
1643         do_log(SMB_VFS_OP_READLINK, (result >= 0), handle, "%s", path);
1644
1645         return result;
1646 }
1647
1648 static int smb_full_audit_link(vfs_handle_struct *handle,
1649                       const char *oldpath, const char *newpath)
1650 {
1651         int result;
1652
1653         result = SMB_VFS_NEXT_LINK(handle, oldpath, newpath);
1654
1655         do_log(SMB_VFS_OP_LINK, (result >= 0), handle,
1656                "%s|%s", oldpath, newpath);
1657
1658         return result;
1659 }
1660
1661 static int smb_full_audit_mknod(vfs_handle_struct *handle,
1662                        const char *pathname, mode_t mode, SMB_DEV_T dev)
1663 {
1664         int result;
1665
1666         result = SMB_VFS_NEXT_MKNOD(handle, pathname, mode, dev);
1667
1668         do_log(SMB_VFS_OP_MKNOD, (result >= 0), handle, "%s", pathname);
1669
1670         return result;
1671 }
1672
1673 static char *smb_full_audit_realpath(vfs_handle_struct *handle,
1674                             const char *path)
1675 {
1676         char *result;
1677
1678         result = SMB_VFS_NEXT_REALPATH(handle, path);
1679
1680         do_log(SMB_VFS_OP_REALPATH, (result != NULL), handle, "%s", path);
1681
1682         return result;
1683 }
1684
1685 static int smb_full_audit_chflags(vfs_handle_struct *handle,
1686                             const char *path, unsigned int flags)
1687 {
1688         int result;
1689
1690         result = SMB_VFS_NEXT_CHFLAGS(handle, path, flags);
1691
1692         do_log(SMB_VFS_OP_CHFLAGS, (result != 0), handle, "%s", path);
1693
1694         return result;
1695 }
1696
1697 static struct file_id smb_full_audit_file_id_create(struct vfs_handle_struct *handle,
1698                                                     const SMB_STRUCT_STAT *sbuf)
1699 {
1700         struct file_id id_zero;
1701         struct file_id result;
1702
1703         ZERO_STRUCT(id_zero);
1704
1705         result = SMB_VFS_NEXT_FILE_ID_CREATE(handle, sbuf);
1706
1707         do_log(SMB_VFS_OP_FILE_ID_CREATE,
1708                !file_id_equal(&id_zero, &result),
1709                handle, "%s", file_id_string_tos(&result));
1710
1711         return result;
1712 }
1713
1714 static NTSTATUS smb_full_audit_streaminfo(vfs_handle_struct *handle,
1715                                           struct files_struct *fsp,
1716                                           const struct smb_filename *smb_fname,
1717                                           TALLOC_CTX *mem_ctx,
1718                                           unsigned int *pnum_streams,
1719                                           struct stream_struct **pstreams)
1720 {
1721         NTSTATUS result;
1722
1723         result = SMB_VFS_NEXT_STREAMINFO(handle, fsp, smb_fname, mem_ctx,
1724                                          pnum_streams, pstreams);
1725
1726         do_log(SMB_VFS_OP_STREAMINFO, NT_STATUS_IS_OK(result), handle,
1727                "%s", smb_fname->base_name);
1728
1729         return result;
1730 }
1731
1732 static int smb_full_audit_get_real_filename(struct vfs_handle_struct *handle,
1733                                             const char *path,
1734                                             const char *name,
1735                                             TALLOC_CTX *mem_ctx,
1736                                             char **found_name)
1737 {
1738         int result;
1739
1740         result = SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name, mem_ctx,
1741                                                 found_name);
1742
1743         do_log(SMB_VFS_OP_GET_REAL_FILENAME, (result == 0), handle,
1744                "%s/%s->%s", path, name, (result == 0) ? "" : *found_name);
1745
1746         return result;
1747 }
1748
1749 static const char *smb_full_audit_connectpath(vfs_handle_struct *handle,
1750                                               const char *fname)
1751 {
1752         const char *result;
1753
1754         result = SMB_VFS_NEXT_CONNECTPATH(handle, fname);
1755
1756         do_log(SMB_VFS_OP_CONNECTPATH, result != NULL, handle,
1757                "%s", fname);
1758
1759         return result;
1760 }
1761
1762 static NTSTATUS smb_full_audit_brl_lock_windows(struct vfs_handle_struct *handle,
1763                                                 struct byte_range_lock *br_lck,
1764                                                 struct lock_struct *plock,
1765                                                 bool blocking_lock)
1766 {
1767         NTSTATUS result;
1768
1769         result = SMB_VFS_NEXT_BRL_LOCK_WINDOWS(handle, br_lck, plock,
1770                                                blocking_lock);
1771
1772         do_log(SMB_VFS_OP_BRL_LOCK_WINDOWS, NT_STATUS_IS_OK(result), handle,
1773             "%s:%llu-%llu. type=%d. blocking=%d",
1774                fsp_str_do_log(brl_fsp(br_lck)),
1775             plock->start, plock->size, plock->lock_type, blocking_lock);
1776
1777         return result;
1778 }
1779
1780 static bool smb_full_audit_brl_unlock_windows(struct vfs_handle_struct *handle,
1781                                               struct messaging_context *msg_ctx,
1782                                               struct byte_range_lock *br_lck,
1783                                               const struct lock_struct *plock)
1784 {
1785         bool result;
1786
1787         result = SMB_VFS_NEXT_BRL_UNLOCK_WINDOWS(handle, msg_ctx, br_lck,
1788             plock);
1789
1790         do_log(SMB_VFS_OP_BRL_UNLOCK_WINDOWS, (result == 0), handle,
1791                "%s:%llu-%llu:%d", fsp_str_do_log(brl_fsp(br_lck)),
1792                plock->start,
1793             plock->size, plock->lock_type);
1794
1795         return result;
1796 }
1797
1798 static bool smb_full_audit_brl_cancel_windows(struct vfs_handle_struct *handle,
1799                                               struct byte_range_lock *br_lck,
1800                                               struct lock_struct *plock)
1801 {
1802         bool result;
1803
1804         result = SMB_VFS_NEXT_BRL_CANCEL_WINDOWS(handle, br_lck, plock);
1805
1806         do_log(SMB_VFS_OP_BRL_CANCEL_WINDOWS, (result == 0), handle,
1807                "%s:%llu-%llu:%d", fsp_str_do_log(brl_fsp(br_lck)),
1808                plock->start,
1809             plock->size, plock->lock_type);
1810
1811         return result;
1812 }
1813
1814 static bool smb_full_audit_strict_lock(struct vfs_handle_struct *handle,
1815                                        struct files_struct *fsp,
1816                                        struct lock_struct *plock)
1817 {
1818         bool result;
1819
1820         result = SMB_VFS_NEXT_STRICT_LOCK(handle, fsp, plock);
1821
1822         do_log(SMB_VFS_OP_STRICT_LOCK, result, handle,
1823             "%s:%llu-%llu:%d", fsp_str_do_log(fsp), plock->start,
1824             plock->size, plock->lock_type);
1825
1826         return result;
1827 }
1828
1829 static void smb_full_audit_strict_unlock(struct vfs_handle_struct *handle,
1830                                          struct files_struct *fsp,
1831                                          struct lock_struct *plock)
1832 {
1833         SMB_VFS_NEXT_STRICT_UNLOCK(handle, fsp, plock);
1834
1835         do_log(SMB_VFS_OP_STRICT_UNLOCK, true, handle,
1836             "%s:%llu-%llu:%d", fsp_str_do_log(fsp), plock->start,
1837             plock->size, plock->lock_type);
1838 }
1839
1840 static NTSTATUS smb_full_audit_translate_name(struct vfs_handle_struct *handle,
1841                                               const char *name,
1842                                               enum vfs_translate_direction direction,
1843                                               TALLOC_CTX *mem_ctx,
1844                                               char **mapped_name)
1845 {
1846         NTSTATUS result;
1847
1848         result = SMB_VFS_NEXT_TRANSLATE_NAME(handle, name, direction, mem_ctx,
1849                                              mapped_name);
1850
1851         do_log(SMB_VFS_OP_TRANSLATE_NAME, NT_STATUS_IS_OK(result), handle, "");
1852
1853         return result;
1854 }
1855
1856 static NTSTATUS smb_full_audit_fsctl(struct vfs_handle_struct *handle,
1857                                 struct files_struct *fsp,
1858                                 TALLOC_CTX *ctx,
1859                                 uint32_t function,
1860                                 uint16_t req_flags,
1861                                 const uint8_t *_in_data,
1862                                 uint32_t in_len,
1863                                 uint8_t **_out_data,
1864                                 uint32_t max_out_len,
1865                                 uint32_t *out_len)
1866 {
1867         NTSTATUS result;
1868
1869         result = SMB_VFS_NEXT_FSCTL(handle,
1870                                 fsp,
1871                                 ctx,
1872                                 function,
1873                                 req_flags,
1874                                 _in_data,
1875                                 in_len,
1876                                 _out_data,
1877                                 max_out_len,
1878                                 out_len);
1879
1880         do_log(SMB_VFS_OP_FSCTL, NT_STATUS_IS_OK(result), handle, "");
1881
1882         return result;
1883 }
1884
1885 static struct tevent_req *smb_full_audit_copy_chunk_send(struct vfs_handle_struct *handle,
1886                                                          TALLOC_CTX *mem_ctx,
1887                                                          struct tevent_context *ev,
1888                                                          struct files_struct *src_fsp,
1889                                                          off_t src_off,
1890                                                          struct files_struct *dest_fsp,
1891                                                          off_t dest_off,
1892                                                          off_t num)
1893 {
1894         struct tevent_req *req;
1895
1896         req = SMB_VFS_NEXT_COPY_CHUNK_SEND(handle, mem_ctx, ev, src_fsp,
1897                                            src_off, dest_fsp, dest_off, num);
1898
1899         do_log(SMB_VFS_OP_COPY_CHUNK_SEND, req, handle, "");
1900
1901         return req;
1902 }
1903
1904 static NTSTATUS smb_full_audit_copy_chunk_recv(struct vfs_handle_struct *handle,
1905                                                struct tevent_req *req,
1906                                                off_t *copied)
1907 {
1908         NTSTATUS result;
1909
1910         result = SMB_VFS_NEXT_COPY_CHUNK_RECV(handle, req, copied);
1911
1912         do_log(SMB_VFS_OP_COPY_CHUNK_RECV, NT_STATUS_IS_OK(result), handle, "");
1913
1914         return result;
1915 }
1916
1917 static NTSTATUS smb_full_audit_get_compression(vfs_handle_struct *handle,
1918                                                TALLOC_CTX *mem_ctx,
1919                                                struct files_struct *fsp,
1920                                                struct smb_filename *smb_fname,
1921                                                uint16_t *_compression_fmt)
1922 {
1923         NTSTATUS result;
1924
1925         result = SMB_VFS_NEXT_GET_COMPRESSION(handle, mem_ctx, fsp, smb_fname,
1926                                               _compression_fmt);
1927
1928         do_log(SMB_VFS_OP_GET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
1929                "%s",
1930                (fsp ? fsp_str_do_log(fsp) : smb_fname_str_do_log(smb_fname)));
1931
1932         return result;
1933 }
1934
1935 static NTSTATUS smb_full_audit_set_compression(vfs_handle_struct *handle,
1936                                                TALLOC_CTX *mem_ctx,
1937                                                struct files_struct *fsp,
1938                                                uint16_t compression_fmt)
1939 {
1940         NTSTATUS result;
1941
1942         result = SMB_VFS_NEXT_SET_COMPRESSION(handle, mem_ctx, fsp,
1943                                               compression_fmt);
1944
1945         do_log(SMB_VFS_OP_SET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
1946                "%s", fsp_str_do_log(fsp));
1947
1948         return result;
1949 }
1950
1951 static NTSTATUS smb_full_audit_readdir_attr(struct vfs_handle_struct *handle,
1952                                             const struct smb_filename *fname,
1953                                             TALLOC_CTX *mem_ctx,
1954                                             struct readdir_attr_data **pattr_data)
1955 {
1956         NTSTATUS status;
1957
1958         status = SMB_VFS_NEXT_READDIR_ATTR(handle, fname, mem_ctx, pattr_data);
1959
1960         do_log(SMB_VFS_OP_READDIR_ATTR, NT_STATUS_IS_OK(status), handle, "%s",
1961                smb_fname_str_do_log(fname));
1962
1963         return status;
1964 }
1965
1966 static NTSTATUS smb_full_audit_get_dos_attributes(
1967                                 struct vfs_handle_struct *handle,
1968                                 struct smb_filename *smb_fname,
1969                                 uint32_t *dosmode)
1970 {
1971         NTSTATUS status;
1972
1973         status = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES(handle,
1974                                 smb_fname,
1975                                 dosmode);
1976
1977         do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES,
1978                 NT_STATUS_IS_OK(status),
1979                 handle,
1980                 "%s",
1981                 smb_fname_str_do_log(smb_fname));
1982
1983         return status;
1984 }
1985
1986 static NTSTATUS smb_full_audit_fget_dos_attributes(
1987                                 struct vfs_handle_struct *handle,
1988                                 struct files_struct *fsp,
1989                                 uint32_t *dosmode)
1990 {
1991         NTSTATUS status;
1992
1993         status = SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle,
1994                                 fsp,
1995                                 dosmode);
1996
1997         do_log(SMB_VFS_OP_FGET_DOS_ATTRIBUTES,
1998                 NT_STATUS_IS_OK(status),
1999                 handle,
2000                 "%s",
2001                 fsp_str_do_log(fsp));
2002
2003         return status;
2004 }
2005
2006 static NTSTATUS smb_full_audit_set_dos_attributes(
2007                                 struct vfs_handle_struct *handle,
2008                                 const struct smb_filename *smb_fname,
2009                                 uint32_t dosmode)
2010 {
2011         NTSTATUS status;
2012
2013         status = SMB_VFS_NEXT_SET_DOS_ATTRIBUTES(handle,
2014                                 smb_fname,
2015                                 dosmode);
2016
2017         do_log(SMB_VFS_OP_SET_DOS_ATTRIBUTES,
2018                 NT_STATUS_IS_OK(status),
2019                 handle,
2020                 "%s",
2021                 smb_fname_str_do_log(smb_fname));
2022
2023         return status;
2024 }
2025
2026 static NTSTATUS smb_full_audit_fset_dos_attributes(
2027                                 struct vfs_handle_struct *handle,
2028                                 struct files_struct *fsp,
2029                                 uint32_t dosmode)
2030 {
2031         NTSTATUS status;
2032
2033         status = SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle,
2034                                 fsp,
2035                                 dosmode);
2036
2037         do_log(SMB_VFS_OP_FSET_DOS_ATTRIBUTES,
2038                 NT_STATUS_IS_OK(status),
2039                 handle,
2040                 "%s",
2041                 fsp_str_do_log(fsp));
2042
2043         return status;
2044 }
2045
2046 static NTSTATUS smb_full_audit_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
2047                                            uint32_t security_info,
2048                                            TALLOC_CTX *mem_ctx,
2049                                            struct security_descriptor **ppdesc)
2050 {
2051         NTSTATUS result;
2052
2053         result = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
2054                                           mem_ctx, ppdesc);
2055
2056         do_log(SMB_VFS_OP_FGET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2057                "%s", fsp_str_do_log(fsp));
2058
2059         return result;
2060 }
2061
2062 static NTSTATUS smb_full_audit_get_nt_acl(vfs_handle_struct *handle,
2063                                           const struct smb_filename *smb_fname,
2064                                           uint32_t security_info,
2065                                           TALLOC_CTX *mem_ctx,
2066                                           struct security_descriptor **ppdesc)
2067 {
2068         NTSTATUS result;
2069
2070         result = SMB_VFS_NEXT_GET_NT_ACL(handle, smb_fname, security_info,
2071                                          mem_ctx, ppdesc);
2072
2073         do_log(SMB_VFS_OP_GET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2074                "%s", smb_fname_str_do_log(smb_fname));
2075
2076         return result;
2077 }
2078
2079 static NTSTATUS smb_full_audit_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
2080                               uint32_t security_info_sent,
2081                               const struct security_descriptor *psd)
2082 {
2083         struct vfs_full_audit_private_data *pd;
2084         NTSTATUS result;
2085         char *sd = NULL;
2086
2087         SMB_VFS_HANDLE_GET_DATA(handle, pd,
2088                                 struct vfs_full_audit_private_data,
2089                                 return NT_STATUS_INTERNAL_ERROR);
2090
2091         if (pd->log_secdesc) {
2092                 sd = sddl_encode(talloc_tos(), psd, get_global_sam_sid());
2093         }
2094
2095         result = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
2096
2097         do_log(SMB_VFS_OP_FSET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2098                "%s [%s]", fsp_str_do_log(fsp), sd ? sd : "");
2099
2100         TALLOC_FREE(sd);
2101
2102         return result;
2103 }
2104
2105 static NTSTATUS smb_full_audit_audit_file(struct vfs_handle_struct *handle,
2106                                 struct smb_filename *file,
2107                                 struct security_acl *sacl,
2108                                 uint32_t access_requested,
2109                                 uint32_t access_denied)
2110 {
2111         NTSTATUS result;
2112
2113         result = SMB_VFS_NEXT_AUDIT_FILE(handle,
2114                                         file,
2115                                         sacl,
2116                                         access_requested,
2117                                         access_denied);
2118
2119         do_log(SMB_VFS_OP_AUDIT_FILE, NT_STATUS_IS_OK(result), handle,
2120                         "%s", smb_fname_str_do_log(file));
2121
2122         return result;
2123 }
2124
2125 static int smb_full_audit_chmod_acl(vfs_handle_struct *handle,
2126                                 const struct smb_filename *smb_fname,
2127                                 mode_t mode)
2128 {
2129         int result;
2130         
2131         result = SMB_VFS_NEXT_CHMOD_ACL(handle, smb_fname, mode);
2132
2133         do_log(SMB_VFS_OP_CHMOD_ACL, (result >= 0), handle,
2134                "%s|%o", smb_fname->base_name, mode);
2135
2136         return result;
2137 }
2138
2139 static int smb_full_audit_fchmod_acl(vfs_handle_struct *handle, files_struct *fsp,
2140                                      mode_t mode)
2141 {
2142         int result;
2143         
2144         result = SMB_VFS_NEXT_FCHMOD_ACL(handle, fsp, mode);
2145
2146         do_log(SMB_VFS_OP_FCHMOD_ACL, (result >= 0), handle,
2147                "%s|%o", fsp_str_do_log(fsp), mode);
2148
2149         return result;
2150 }
2151
2152 static SMB_ACL_T smb_full_audit_sys_acl_get_file(vfs_handle_struct *handle,
2153                                         const char *path_p,
2154                                                  SMB_ACL_TYPE_T type,
2155                                                  TALLOC_CTX *mem_ctx)
2156 {
2157         SMB_ACL_T result;
2158
2159         result = SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, path_p, type, mem_ctx);
2160
2161         do_log(SMB_VFS_OP_SYS_ACL_GET_FILE, (result != NULL), handle,
2162                "%s", path_p);
2163
2164         return result;
2165 }
2166
2167 static SMB_ACL_T smb_full_audit_sys_acl_get_fd(vfs_handle_struct *handle,
2168                                                files_struct *fsp, TALLOC_CTX *mem_ctx)
2169 {
2170         SMB_ACL_T result;
2171
2172         result = SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp, mem_ctx);
2173
2174         do_log(SMB_VFS_OP_SYS_ACL_GET_FD, (result != NULL), handle,
2175                "%s", fsp_str_do_log(fsp));
2176
2177         return result;
2178 }
2179
2180 static int smb_full_audit_sys_acl_blob_get_file(vfs_handle_struct *handle,
2181                                                 const char *path_p,
2182                                                 TALLOC_CTX *mem_ctx,
2183                                                 char **blob_description,
2184                                                 DATA_BLOB *blob)
2185 {
2186         int result;
2187
2188         result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FILE(handle, path_p, mem_ctx, blob_description, blob);
2189
2190         do_log(SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE, (result >= 0), handle,
2191                "%s", path_p);
2192
2193         return result;
2194 }
2195
2196 static int smb_full_audit_sys_acl_blob_get_fd(vfs_handle_struct *handle,
2197                                               files_struct *fsp,
2198                                               TALLOC_CTX *mem_ctx,
2199                                               char **blob_description,
2200                                               DATA_BLOB *blob)
2201 {
2202         int result;
2203
2204         result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle, fsp, mem_ctx, blob_description, blob);
2205
2206         do_log(SMB_VFS_OP_SYS_ACL_BLOB_GET_FD, (result >= 0), handle,
2207                "%s", fsp_str_do_log(fsp));
2208
2209         return result;
2210 }
2211
2212 static int smb_full_audit_sys_acl_set_file(vfs_handle_struct *handle,
2213
2214                                   const char *name, SMB_ACL_TYPE_T acltype,
2215                                   SMB_ACL_T theacl)
2216 {
2217         int result;
2218
2219         result = SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, name, acltype,
2220                                                theacl);
2221
2222         do_log(SMB_VFS_OP_SYS_ACL_SET_FILE, (result >= 0), handle,
2223                "%s", name);
2224
2225         return result;
2226 }
2227
2228 static int smb_full_audit_sys_acl_set_fd(vfs_handle_struct *handle, files_struct *fsp,
2229                                 SMB_ACL_T theacl)
2230 {
2231         int result;
2232
2233         result = SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, theacl);
2234
2235         do_log(SMB_VFS_OP_SYS_ACL_SET_FD, (result >= 0), handle,
2236                "%s", fsp_str_do_log(fsp));
2237
2238         return result;
2239 }
2240
2241 static int smb_full_audit_sys_acl_delete_def_file(vfs_handle_struct *handle,
2242
2243                                          const char *path)
2244 {
2245         int result;
2246
2247         result = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, path);
2248
2249         do_log(SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE, (result >= 0), handle,
2250                "%s", path);
2251
2252         return result;
2253 }
2254
2255 static ssize_t smb_full_audit_getxattr(struct vfs_handle_struct *handle,
2256                               const char *path,
2257                               const char *name, void *value, size_t size)
2258 {
2259         ssize_t result;
2260
2261         result = SMB_VFS_NEXT_GETXATTR(handle, path, name, value, size);
2262
2263         do_log(SMB_VFS_OP_GETXATTR, (result >= 0), handle,
2264                "%s|%s", path, name);
2265
2266         return result;
2267 }
2268
2269 static ssize_t smb_full_audit_fgetxattr(struct vfs_handle_struct *handle,
2270                                struct files_struct *fsp,
2271                                const char *name, void *value, size_t size)
2272 {
2273         ssize_t result;
2274
2275         result = SMB_VFS_NEXT_FGETXATTR(handle, fsp, name, value, size);
2276
2277         do_log(SMB_VFS_OP_FGETXATTR, (result >= 0), handle,
2278                "%s|%s", fsp_str_do_log(fsp), name);
2279
2280         return result;
2281 }
2282
2283 static ssize_t smb_full_audit_listxattr(struct vfs_handle_struct *handle,
2284                                const char *path, char *list, size_t size)
2285 {
2286         ssize_t result;
2287
2288         result = SMB_VFS_NEXT_LISTXATTR(handle, path, list, size);
2289
2290         do_log(SMB_VFS_OP_LISTXATTR, (result >= 0), handle, "%s", path);
2291
2292         return result;
2293 }
2294
2295 static ssize_t smb_full_audit_flistxattr(struct vfs_handle_struct *handle,
2296                                 struct files_struct *fsp, char *list,
2297                                 size_t size)
2298 {
2299         ssize_t result;
2300
2301         result = SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
2302
2303         do_log(SMB_VFS_OP_FLISTXATTR, (result >= 0), handle,
2304                "%s", fsp_str_do_log(fsp));
2305
2306         return result;
2307 }
2308
2309 static int smb_full_audit_removexattr(struct vfs_handle_struct *handle,
2310                              const char *path,
2311                              const char *name)
2312 {
2313         int result;
2314
2315         result = SMB_VFS_NEXT_REMOVEXATTR(handle, path, name);
2316
2317         do_log(SMB_VFS_OP_REMOVEXATTR, (result >= 0), handle,
2318                "%s|%s", path, name);
2319
2320         return result;
2321 }
2322
2323 static int smb_full_audit_fremovexattr(struct vfs_handle_struct *handle,
2324                               struct files_struct *fsp,
2325                               const char *name)
2326 {
2327         int result;
2328
2329         result = SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, name);
2330
2331         do_log(SMB_VFS_OP_FREMOVEXATTR, (result >= 0), handle,
2332                "%s|%s", fsp_str_do_log(fsp), name);
2333
2334         return result;
2335 }
2336
2337 static int smb_full_audit_setxattr(struct vfs_handle_struct *handle,
2338                           const char *path,
2339                           const char *name, const void *value, size_t size,
2340                           int flags)
2341 {
2342         int result;
2343
2344         result = SMB_VFS_NEXT_SETXATTR(handle, path, name, value, size,
2345                                        flags);
2346
2347         do_log(SMB_VFS_OP_SETXATTR, (result >= 0), handle,
2348                "%s|%s", path, name);
2349
2350         return result;
2351 }
2352
2353 static int smb_full_audit_fsetxattr(struct vfs_handle_struct *handle,
2354                            struct files_struct *fsp, const char *name,
2355                            const void *value, size_t size, int flags)
2356 {
2357         int result;
2358
2359         result = SMB_VFS_NEXT_FSETXATTR(handle, fsp, name, value, size, flags);
2360
2361         do_log(SMB_VFS_OP_FSETXATTR, (result >= 0), handle,
2362                "%s|%s", fsp_str_do_log(fsp), name);
2363
2364         return result;
2365 }
2366
2367 static bool smb_full_audit_aio_force(struct vfs_handle_struct *handle,
2368                                      struct files_struct *fsp)
2369 {
2370         bool result;
2371
2372         result = SMB_VFS_NEXT_AIO_FORCE(handle, fsp);
2373         do_log(SMB_VFS_OP_AIO_FORCE, result, handle,
2374                 "%s", fsp_str_do_log(fsp));
2375
2376         return result;
2377 }
2378
2379 static NTSTATUS smb_full_audit_durable_cookie(struct vfs_handle_struct *handle,
2380                                 struct files_struct *fsp,
2381                                 TALLOC_CTX *mem_ctx,
2382                                 DATA_BLOB *cookie)
2383 {
2384         NTSTATUS result;
2385
2386         result = SMB_VFS_NEXT_DURABLE_COOKIE(handle,
2387                                         fsp,
2388                                         mem_ctx,
2389                                         cookie);
2390
2391         do_log(SMB_VFS_OP_DURABLE_COOKIE, NT_STATUS_IS_OK(result), handle,
2392                         "%s", fsp_str_do_log(fsp));
2393
2394         return result;
2395 }
2396
2397 static NTSTATUS smb_full_audit_durable_disconnect(
2398                                 struct vfs_handle_struct *handle,
2399                                 struct files_struct *fsp,
2400                                 const DATA_BLOB old_cookie,
2401                                 TALLOC_CTX *mem_ctx,
2402                                 DATA_BLOB *new_cookie)
2403 {
2404         NTSTATUS result;
2405
2406         result = SMB_VFS_NEXT_DURABLE_DISCONNECT(handle,
2407                                         fsp,
2408                                         old_cookie,
2409                                         mem_ctx,
2410                                         new_cookie);
2411
2412         do_log(SMB_VFS_OP_DURABLE_DISCONNECT, NT_STATUS_IS_OK(result), handle,
2413                         "%s", fsp_str_do_log(fsp));
2414
2415         return result;
2416 }
2417
2418 static NTSTATUS smb_full_audit_durable_reconnect(
2419                                 struct vfs_handle_struct *handle,
2420                                 struct smb_request *smb1req,
2421                                 struct smbXsrv_open *op,
2422                                 const DATA_BLOB old_cookie,
2423                                 TALLOC_CTX *mem_ctx,
2424                                 struct files_struct **fsp,
2425                                 DATA_BLOB *new_cookie)
2426 {
2427         NTSTATUS result;
2428
2429         result = SMB_VFS_NEXT_DURABLE_RECONNECT(handle,
2430                                         smb1req,
2431                                         op,
2432                                         old_cookie,
2433                                         mem_ctx,
2434                                         fsp,
2435                                         new_cookie);
2436
2437         do_log(SMB_VFS_OP_DURABLE_RECONNECT,
2438                         NT_STATUS_IS_OK(result),
2439                         handle,
2440                         "");
2441
2442         return result;
2443 }
2444
2445 static struct vfs_fn_pointers vfs_full_audit_fns = {
2446
2447         /* Disk operations */
2448
2449         .connect_fn = smb_full_audit_connect,
2450         .disconnect_fn = smb_full_audit_disconnect,
2451         .disk_free_fn = smb_full_audit_disk_free,
2452         .get_quota_fn = smb_full_audit_get_quota,
2453         .set_quota_fn = smb_full_audit_set_quota,
2454         .get_shadow_copy_data_fn = smb_full_audit_get_shadow_copy_data,
2455         .statvfs_fn = smb_full_audit_statvfs,
2456         .fs_capabilities_fn = smb_full_audit_fs_capabilities,
2457         .get_dfs_referrals_fn = smb_full_audit_get_dfs_referrals,
2458         .opendir_fn = smb_full_audit_opendir,
2459         .fdopendir_fn = smb_full_audit_fdopendir,
2460         .readdir_fn = smb_full_audit_readdir,
2461         .seekdir_fn = smb_full_audit_seekdir,
2462         .telldir_fn = smb_full_audit_telldir,
2463         .rewind_dir_fn = smb_full_audit_rewinddir,
2464         .mkdir_fn = smb_full_audit_mkdir,
2465         .rmdir_fn = smb_full_audit_rmdir,
2466         .closedir_fn = smb_full_audit_closedir,
2467         .init_search_op_fn = smb_full_audit_init_search_op,
2468         .open_fn = smb_full_audit_open,
2469         .create_file_fn = smb_full_audit_create_file,
2470         .close_fn = smb_full_audit_close,
2471         .read_fn = smb_full_audit_read,
2472         .pread_fn = smb_full_audit_pread,
2473         .pread_send_fn = smb_full_audit_pread_send,
2474         .pread_recv_fn = smb_full_audit_pread_recv,
2475         .write_fn = smb_full_audit_write,
2476         .pwrite_fn = smb_full_audit_pwrite,
2477         .pwrite_send_fn = smb_full_audit_pwrite_send,
2478         .pwrite_recv_fn = smb_full_audit_pwrite_recv,
2479         .lseek_fn = smb_full_audit_lseek,
2480         .sendfile_fn = smb_full_audit_sendfile,
2481         .recvfile_fn = smb_full_audit_recvfile,
2482         .rename_fn = smb_full_audit_rename,
2483         .fsync_fn = smb_full_audit_fsync,
2484         .fsync_send_fn = smb_full_audit_fsync_send,
2485         .fsync_recv_fn = smb_full_audit_fsync_recv,
2486         .stat_fn = smb_full_audit_stat,
2487         .fstat_fn = smb_full_audit_fstat,
2488         .lstat_fn = smb_full_audit_lstat,
2489         .get_alloc_size_fn = smb_full_audit_get_alloc_size,
2490         .unlink_fn = smb_full_audit_unlink,
2491         .chmod_fn = smb_full_audit_chmod,
2492         .fchmod_fn = smb_full_audit_fchmod,
2493         .chown_fn = smb_full_audit_chown,
2494         .fchown_fn = smb_full_audit_fchown,
2495         .lchown_fn = smb_full_audit_lchown,
2496         .chdir_fn = smb_full_audit_chdir,
2497         .getwd_fn = smb_full_audit_getwd,
2498         .ntimes_fn = smb_full_audit_ntimes,
2499         .ftruncate_fn = smb_full_audit_ftruncate,
2500         .fallocate_fn = smb_full_audit_fallocate,
2501         .lock_fn = smb_full_audit_lock,
2502         .kernel_flock_fn = smb_full_audit_kernel_flock,
2503         .linux_setlease_fn = smb_full_audit_linux_setlease,
2504         .getlock_fn = smb_full_audit_getlock,
2505         .symlink_fn = smb_full_audit_symlink,
2506         .readlink_fn = smb_full_audit_readlink,
2507         .link_fn = smb_full_audit_link,
2508         .mknod_fn = smb_full_audit_mknod,
2509         .realpath_fn = smb_full_audit_realpath,
2510         .chflags_fn = smb_full_audit_chflags,
2511         .file_id_create_fn = smb_full_audit_file_id_create,
2512         .copy_chunk_send_fn = smb_full_audit_copy_chunk_send,
2513         .copy_chunk_recv_fn = smb_full_audit_copy_chunk_recv,
2514         .get_compression_fn = smb_full_audit_get_compression,
2515         .set_compression_fn = smb_full_audit_set_compression,
2516         .snap_check_path_fn =  smb_full_audit_snap_check_path,
2517         .snap_create_fn = smb_full_audit_snap_create,
2518         .snap_delete_fn = smb_full_audit_snap_delete,
2519         .streaminfo_fn = smb_full_audit_streaminfo,
2520         .get_real_filename_fn = smb_full_audit_get_real_filename,
2521         .connectpath_fn = smb_full_audit_connectpath,
2522         .brl_lock_windows_fn = smb_full_audit_brl_lock_windows,
2523         .brl_unlock_windows_fn = smb_full_audit_brl_unlock_windows,
2524         .brl_cancel_windows_fn = smb_full_audit_brl_cancel_windows,
2525         .strict_lock_fn = smb_full_audit_strict_lock,
2526         .strict_unlock_fn = smb_full_audit_strict_unlock,
2527         .translate_name_fn = smb_full_audit_translate_name,
2528         .fsctl_fn = smb_full_audit_fsctl,
2529         .get_dos_attributes_fn = smb_full_audit_get_dos_attributes,
2530         .fget_dos_attributes_fn = smb_full_audit_fget_dos_attributes,
2531         .set_dos_attributes_fn = smb_full_audit_set_dos_attributes,
2532         .fset_dos_attributes_fn = smb_full_audit_fset_dos_attributes,
2533         .fget_nt_acl_fn = smb_full_audit_fget_nt_acl,
2534         .get_nt_acl_fn = smb_full_audit_get_nt_acl,
2535         .fset_nt_acl_fn = smb_full_audit_fset_nt_acl,
2536         .audit_file_fn = smb_full_audit_audit_file,
2537         .chmod_acl_fn = smb_full_audit_chmod_acl,
2538         .fchmod_acl_fn = smb_full_audit_fchmod_acl,
2539         .sys_acl_get_file_fn = smb_full_audit_sys_acl_get_file,
2540         .sys_acl_get_fd_fn = smb_full_audit_sys_acl_get_fd,
2541         .sys_acl_blob_get_file_fn = smb_full_audit_sys_acl_blob_get_file,
2542         .sys_acl_blob_get_fd_fn = smb_full_audit_sys_acl_blob_get_fd,
2543         .sys_acl_set_file_fn = smb_full_audit_sys_acl_set_file,
2544         .sys_acl_set_fd_fn = smb_full_audit_sys_acl_set_fd,
2545         .sys_acl_delete_def_file_fn = smb_full_audit_sys_acl_delete_def_file,
2546         .getxattr_fn = smb_full_audit_getxattr,
2547         .fgetxattr_fn = smb_full_audit_fgetxattr,
2548         .listxattr_fn = smb_full_audit_listxattr,
2549         .flistxattr_fn = smb_full_audit_flistxattr,
2550         .removexattr_fn = smb_full_audit_removexattr,
2551         .fremovexattr_fn = smb_full_audit_fremovexattr,
2552         .setxattr_fn = smb_full_audit_setxattr,
2553         .fsetxattr_fn = smb_full_audit_fsetxattr,
2554         .aio_force_fn = smb_full_audit_aio_force,
2555         .durable_cookie_fn = smb_full_audit_durable_cookie,
2556         .durable_disconnect_fn = smb_full_audit_durable_disconnect,
2557         .durable_reconnect_fn = smb_full_audit_durable_reconnect,
2558         .readdir_attr_fn = smb_full_audit_readdir_attr
2559
2560 };
2561
2562 static_decl_vfs;
2563 NTSTATUS vfs_full_audit_init(void)
2564 {
2565         NTSTATUS ret;
2566
2567         smb_vfs_assert_all_fns(&vfs_full_audit_fns, "full_audit");
2568
2569         ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "full_audit",
2570                                &vfs_full_audit_fns);
2571
2572         if (!NT_STATUS_IS_OK(ret))
2573                 return ret;
2574
2575         vfs_full_audit_debug_level = debug_add_class("full_audit");
2576         if (vfs_full_audit_debug_level == -1) {
2577                 vfs_full_audit_debug_level = DBGC_VFS;
2578                 DEBUG(0, ("vfs_full_audit: Couldn't register custom debugging "
2579                           "class!\n"));
2580         } else {
2581                 DEBUG(10, ("vfs_full_audit: Debug class number of "
2582                            "'full_audit': %d\n", vfs_full_audit_debug_level));
2583         }
2584         
2585         return ret;
2586 }