ee8dbbcff2c88847b852b6d8f1db660994aeea17
[bbaumbach/samba-autobuild/.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
114         /* File operations */
115
116         SMB_VFS_OP_OPEN,
117         SMB_VFS_OP_CREATE_FILE,
118         SMB_VFS_OP_CLOSE,
119         SMB_VFS_OP_READ,
120         SMB_VFS_OP_PREAD,
121         SMB_VFS_OP_PREAD_SEND,
122         SMB_VFS_OP_PREAD_RECV,
123         SMB_VFS_OP_WRITE,
124         SMB_VFS_OP_PWRITE,
125         SMB_VFS_OP_PWRITE_SEND,
126         SMB_VFS_OP_PWRITE_RECV,
127         SMB_VFS_OP_LSEEK,
128         SMB_VFS_OP_SENDFILE,
129         SMB_VFS_OP_RECVFILE,
130         SMB_VFS_OP_RENAME,
131         SMB_VFS_OP_FSYNC,
132         SMB_VFS_OP_FSYNC_SEND,
133         SMB_VFS_OP_FSYNC_RECV,
134         SMB_VFS_OP_STAT,
135         SMB_VFS_OP_FSTAT,
136         SMB_VFS_OP_LSTAT,
137         SMB_VFS_OP_GET_ALLOC_SIZE,
138         SMB_VFS_OP_UNLINK,
139         SMB_VFS_OP_CHMOD,
140         SMB_VFS_OP_FCHMOD,
141         SMB_VFS_OP_CHOWN,
142         SMB_VFS_OP_FCHOWN,
143         SMB_VFS_OP_LCHOWN,
144         SMB_VFS_OP_CHDIR,
145         SMB_VFS_OP_GETWD,
146         SMB_VFS_OP_NTIMES,
147         SMB_VFS_OP_FTRUNCATE,
148         SMB_VFS_OP_FALLOCATE,
149         SMB_VFS_OP_LOCK,
150         SMB_VFS_OP_KERNEL_FLOCK,
151         SMB_VFS_OP_LINUX_SETLEASE,
152         SMB_VFS_OP_GETLOCK,
153         SMB_VFS_OP_SYMLINK,
154         SMB_VFS_OP_READLINK,
155         SMB_VFS_OP_LINK,
156         SMB_VFS_OP_MKNOD,
157         SMB_VFS_OP_REALPATH,
158         SMB_VFS_OP_CHFLAGS,
159         SMB_VFS_OP_FILE_ID_CREATE,
160         SMB_VFS_OP_STREAMINFO,
161         SMB_VFS_OP_GET_REAL_FILENAME,
162         SMB_VFS_OP_CONNECTPATH,
163         SMB_VFS_OP_BRL_LOCK_WINDOWS,
164         SMB_VFS_OP_BRL_UNLOCK_WINDOWS,
165         SMB_VFS_OP_BRL_CANCEL_WINDOWS,
166         SMB_VFS_OP_STRICT_LOCK_CHECK,
167         SMB_VFS_OP_TRANSLATE_NAME,
168         SMB_VFS_OP_FSCTL,
169         SMB_VFS_OP_OFFLOAD_READ_SEND,
170         SMB_VFS_OP_OFFLOAD_READ_RECV,
171         SMB_VFS_OP_OFFLOAD_WRITE_SEND,
172         SMB_VFS_OP_OFFLOAD_WRITE_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_OPEN,      "open" },
259         { SMB_VFS_OP_CREATE_FILE, "create_file" },
260         { SMB_VFS_OP_CLOSE,     "close" },
261         { SMB_VFS_OP_READ,      "read" },
262         { SMB_VFS_OP_PREAD,     "pread" },
263         { SMB_VFS_OP_PREAD_SEND,        "pread_send" },
264         { SMB_VFS_OP_PREAD_RECV,        "pread_recv" },
265         { SMB_VFS_OP_WRITE,     "write" },
266         { SMB_VFS_OP_PWRITE,    "pwrite" },
267         { SMB_VFS_OP_PWRITE_SEND,       "pwrite_send" },
268         { SMB_VFS_OP_PWRITE_RECV,       "pwrite_recv" },
269         { SMB_VFS_OP_LSEEK,     "lseek" },
270         { SMB_VFS_OP_SENDFILE,  "sendfile" },
271         { SMB_VFS_OP_RECVFILE,  "recvfile" },
272         { SMB_VFS_OP_RENAME,    "rename" },
273         { SMB_VFS_OP_FSYNC,     "fsync" },
274         { SMB_VFS_OP_FSYNC_SEND,        "fsync_send" },
275         { SMB_VFS_OP_FSYNC_RECV,        "fsync_recv" },
276         { SMB_VFS_OP_STAT,      "stat" },
277         { SMB_VFS_OP_FSTAT,     "fstat" },
278         { SMB_VFS_OP_LSTAT,     "lstat" },
279         { SMB_VFS_OP_GET_ALLOC_SIZE,    "get_alloc_size" },
280         { SMB_VFS_OP_UNLINK,    "unlink" },
281         { SMB_VFS_OP_CHMOD,     "chmod" },
282         { SMB_VFS_OP_FCHMOD,    "fchmod" },
283         { SMB_VFS_OP_CHOWN,     "chown" },
284         { SMB_VFS_OP_FCHOWN,    "fchown" },
285         { SMB_VFS_OP_LCHOWN,    "lchown" },
286         { SMB_VFS_OP_CHDIR,     "chdir" },
287         { SMB_VFS_OP_GETWD,     "getwd" },
288         { SMB_VFS_OP_NTIMES,    "ntimes" },
289         { SMB_VFS_OP_FTRUNCATE, "ftruncate" },
290         { SMB_VFS_OP_FALLOCATE,"fallocate" },
291         { SMB_VFS_OP_LOCK,      "lock" },
292         { SMB_VFS_OP_KERNEL_FLOCK,      "kernel_flock" },
293         { SMB_VFS_OP_LINUX_SETLEASE, "linux_setlease" },
294         { SMB_VFS_OP_GETLOCK,   "getlock" },
295         { SMB_VFS_OP_SYMLINK,   "symlink" },
296         { SMB_VFS_OP_READLINK,  "readlink" },
297         { SMB_VFS_OP_LINK,      "link" },
298         { SMB_VFS_OP_MKNOD,     "mknod" },
299         { SMB_VFS_OP_REALPATH,  "realpath" },
300         { SMB_VFS_OP_CHFLAGS,   "chflags" },
301         { SMB_VFS_OP_FILE_ID_CREATE,    "file_id_create" },
302         { SMB_VFS_OP_STREAMINFO,        "streaminfo" },
303         { SMB_VFS_OP_GET_REAL_FILENAME, "get_real_filename" },
304         { SMB_VFS_OP_CONNECTPATH,       "connectpath" },
305         { SMB_VFS_OP_BRL_LOCK_WINDOWS,  "brl_lock_windows" },
306         { SMB_VFS_OP_BRL_UNLOCK_WINDOWS, "brl_unlock_windows" },
307         { SMB_VFS_OP_BRL_CANCEL_WINDOWS, "brl_cancel_windows" },
308         { SMB_VFS_OP_STRICT_LOCK_CHECK, "strict_lock_check" },
309         { SMB_VFS_OP_TRANSLATE_NAME,    "translate_name" },
310         { SMB_VFS_OP_FSCTL,             "fsctl" },
311         { SMB_VFS_OP_OFFLOAD_READ_SEND, "offload_read_send" },
312         { SMB_VFS_OP_OFFLOAD_READ_RECV, "offload_read_recv" },
313         { SMB_VFS_OP_OFFLOAD_WRITE_SEND,        "offload_write_send" },
314         { SMB_VFS_OP_OFFLOAD_WRITE_RECV,        "offload_write_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, ...) PRINTF_ATTRIBUTE(4, 5);
525
526 static void do_log(vfs_op_type op, bool success, vfs_handle_struct *handle,
527                    const char *format, ...)
528 {
529         struct vfs_full_audit_private_data *pd;
530         fstring err_msg;
531         char *audit_pre = NULL;
532         va_list ap;
533         char *op_msg = NULL;
534
535         SMB_VFS_HANDLE_GET_DATA(handle, pd,
536                                 struct vfs_full_audit_private_data,
537                                 return;);
538
539         if (success && (!log_success(pd, op)))
540                 goto out;
541
542         if (!success && (!log_failure(pd, op)))
543                 goto out;
544
545         if (success)
546                 fstrcpy(err_msg, "ok");
547         else
548                 fstr_sprintf(err_msg, "fail (%s)", strerror(errno));
549
550         va_start(ap, format);
551         op_msg = talloc_vasprintf(talloc_tos(), format, ap);
552         va_end(ap);
553
554         if (!op_msg) {
555                 goto out;
556         }
557
558         audit_pre = audit_prefix(talloc_tos(), handle->conn);
559
560         if (pd->do_syslog) {
561                 int priority;
562
563                 /*
564                  * Specify the facility to interoperate with other syslog
565                  * callers (smbd for example).
566                  */
567                 priority = pd->syslog_priority | pd->syslog_facility;
568
569                 syslog(priority, "%s|%s|%s|%s\n",
570                        audit_pre ? audit_pre : "",
571                        audit_opname(op), err_msg, op_msg);
572         } else {
573                 DEBUG(1, ("%s|%s|%s|%s\n",
574                           audit_pre ? audit_pre : "",
575                           audit_opname(op), err_msg, op_msg));
576         }
577  out:
578         TALLOC_FREE(audit_pre);
579         TALLOC_FREE(op_msg);
580         TALLOC_FREE(tmp_do_log_ctx);
581 }
582
583 /**
584  * Return a string using the do_log_ctx()
585  */
586 static const char *smb_fname_str_do_log(const struct smb_filename *smb_fname)
587 {
588         char *fname = NULL;
589         NTSTATUS status;
590
591         if (smb_fname == NULL) {
592                 return "";
593         }
594         status = get_full_smb_filename(do_log_ctx(), smb_fname, &fname);
595         if (!NT_STATUS_IS_OK(status)) {
596                 return "";
597         }
598         return fname;
599 }
600
601 /**
602  * Return an fsp debug string using the do_log_ctx()
603  */
604 static const char *fsp_str_do_log(const struct files_struct *fsp)
605 {
606         return smb_fname_str_do_log(fsp->fsp_name);
607 }
608
609 /* Implementation of vfs_ops.  Pass everything on to the default
610    operation but log event first. */
611
612 static int smb_full_audit_connect(vfs_handle_struct *handle,
613                          const char *svc, const char *user)
614 {
615         int result;
616         struct vfs_full_audit_private_data *pd = NULL;
617
618         result = SMB_VFS_NEXT_CONNECT(handle, svc, user);
619         if (result < 0) {
620                 return result;
621         }
622
623         pd = talloc_zero(handle, struct vfs_full_audit_private_data);
624         if (!pd) {
625                 SMB_VFS_NEXT_DISCONNECT(handle);
626                 return -1;
627         }
628
629         pd->syslog_facility = audit_syslog_facility(handle);
630         if (pd->syslog_facility == -1) {
631                 DEBUG(1, ("%s: Unknown facility %s\n", __func__,
632                           lp_parm_const_string(SNUM(handle->conn),
633                                                "full_audit", "facility",
634                                                "USER")));
635                 SMB_VFS_NEXT_DISCONNECT(handle);
636                 return -1;
637         }
638
639         pd->syslog_priority = audit_syslog_priority(handle);
640
641         pd->log_secdesc = lp_parm_bool(SNUM(handle->conn),
642                                        "full_audit", "log_secdesc", false);
643
644         pd->do_syslog = lp_parm_bool(SNUM(handle->conn),
645                                      "full_audit", "syslog", true);
646
647 #ifdef WITH_SYSLOG
648         if (pd->do_syslog) {
649                 openlog("smbd_audit", 0, pd->syslog_facility);
650         }
651 #endif
652
653         pd->success_ops = init_bitmap(
654                 pd, lp_parm_string_list(SNUM(handle->conn), "full_audit",
655                                         "success", NULL));
656         pd->failure_ops = init_bitmap(
657                 pd, lp_parm_string_list(SNUM(handle->conn), "full_audit",
658                                         "failure", NULL));
659
660         /* Store the private data. */
661         SMB_VFS_HANDLE_SET_DATA(handle, pd, NULL,
662                                 struct vfs_full_audit_private_data, return -1);
663
664         do_log(SMB_VFS_OP_CONNECT, True, handle,
665                "%s", svc);
666
667         return 0;
668 }
669
670 static void smb_full_audit_disconnect(vfs_handle_struct *handle)
671 {
672         SMB_VFS_NEXT_DISCONNECT(handle);
673
674         do_log(SMB_VFS_OP_DISCONNECT, True, handle,
675                "%s", lp_servicename(talloc_tos(), SNUM(handle->conn)));
676
677         /* The bitmaps will be disconnected when the private
678            data is deleted. */
679 }
680
681 static uint64_t smb_full_audit_disk_free(vfs_handle_struct *handle,
682                                 const struct smb_filename *smb_fname,
683                                 uint64_t *bsize,
684                                 uint64_t *dfree,
685                                 uint64_t *dsize)
686 {
687         uint64_t result;
688
689         result = SMB_VFS_NEXT_DISK_FREE(handle, smb_fname, bsize, dfree, dsize);
690
691         /* Don't have a reasonable notion of failure here */
692
693         do_log(SMB_VFS_OP_DISK_FREE, True, handle, "%s", smb_fname->base_name);
694
695         return result;
696 }
697
698 static int smb_full_audit_get_quota(struct vfs_handle_struct *handle,
699                                 const struct smb_filename *smb_fname,
700                                 enum SMB_QUOTA_TYPE qtype,
701                                 unid_t id,
702                                 SMB_DISK_QUOTA *qt)
703 {
704         int result;
705
706         result = SMB_VFS_NEXT_GET_QUOTA(handle, smb_fname, qtype, id, qt);
707
708         do_log(SMB_VFS_OP_GET_QUOTA, (result >= 0), handle, "%s",
709                         smb_fname->base_name);
710
711         return result;
712 }
713
714 static int smb_full_audit_set_quota(struct vfs_handle_struct *handle,
715                            enum SMB_QUOTA_TYPE qtype, unid_t id,
716                            SMB_DISK_QUOTA *qt)
717 {
718         int result;
719
720         result = SMB_VFS_NEXT_SET_QUOTA(handle, qtype, id, qt);
721
722         do_log(SMB_VFS_OP_SET_QUOTA, (result >= 0), handle, "");
723
724         return result;
725 }
726
727 static int smb_full_audit_get_shadow_copy_data(struct vfs_handle_struct *handle,
728                                 struct files_struct *fsp,
729                                 struct shadow_copy_data *shadow_copy_data,
730                                 bool labels)
731 {
732         int result;
733
734         result = SMB_VFS_NEXT_GET_SHADOW_COPY_DATA(handle, fsp, shadow_copy_data, labels);
735
736         do_log(SMB_VFS_OP_GET_SHADOW_COPY_DATA, (result >= 0), handle, "");
737
738         return result;
739 }
740
741 static int smb_full_audit_statvfs(struct vfs_handle_struct *handle,
742                                 const struct smb_filename *smb_fname,
743                                 struct vfs_statvfs_struct *statbuf)
744 {
745         int result;
746
747         result = SMB_VFS_NEXT_STATVFS(handle, smb_fname, statbuf);
748
749         do_log(SMB_VFS_OP_STATVFS, (result >= 0), handle, "");
750
751         return result;
752 }
753
754 static uint32_t smb_full_audit_fs_capabilities(struct vfs_handle_struct *handle, enum timestamp_set_resolution *p_ts_res)
755 {
756         int result;
757
758         result = SMB_VFS_NEXT_FS_CAPABILITIES(handle, p_ts_res);
759
760         do_log(SMB_VFS_OP_FS_CAPABILITIES, true, handle, "");
761
762         return result;
763 }
764
765 static NTSTATUS smb_full_audit_get_dfs_referrals(
766                                 struct vfs_handle_struct *handle,
767                                 struct dfs_GetDFSReferral *r)
768 {
769         NTSTATUS status;
770
771         status = SMB_VFS_NEXT_GET_DFS_REFERRALS(handle, r);
772
773         do_log(SMB_VFS_OP_GET_DFS_REFERRALS, NT_STATUS_IS_OK(status),
774                handle, "");
775
776         return status;
777 }
778
779 static NTSTATUS smb_full_audit_snap_check_path(struct vfs_handle_struct *handle,
780                                                TALLOC_CTX *mem_ctx,
781                                                const char *service_path,
782                                                char **base_volume)
783 {
784         NTSTATUS status;
785
786         status = SMB_VFS_NEXT_SNAP_CHECK_PATH(handle, mem_ctx, service_path,
787                                               base_volume);
788         do_log(SMB_VFS_OP_SNAP_CHECK_PATH, NT_STATUS_IS_OK(status),
789                handle, "");
790
791         return status;
792 }
793
794 static NTSTATUS smb_full_audit_snap_create(struct vfs_handle_struct *handle,
795                                            TALLOC_CTX *mem_ctx,
796                                            const char *base_volume,
797                                            time_t *tstamp,
798                                            bool rw,
799                                            char **base_path,
800                                            char **snap_path)
801 {
802         NTSTATUS status;
803
804         status = SMB_VFS_NEXT_SNAP_CREATE(handle, mem_ctx, base_volume, tstamp,
805                                           rw, base_path, snap_path);
806         do_log(SMB_VFS_OP_SNAP_CREATE, NT_STATUS_IS_OK(status), handle, "");
807
808         return status;
809 }
810
811 static NTSTATUS smb_full_audit_snap_delete(struct vfs_handle_struct *handle,
812                                            TALLOC_CTX *mem_ctx,
813                                            char *base_path,
814                                            char *snap_path)
815 {
816         NTSTATUS status;
817
818         status = SMB_VFS_NEXT_SNAP_DELETE(handle, mem_ctx, base_path,
819                                           snap_path);
820         do_log(SMB_VFS_OP_SNAP_DELETE, NT_STATUS_IS_OK(status), handle, "");
821
822         return status;
823 }
824
825 static DIR *smb_full_audit_opendir(vfs_handle_struct *handle,
826                         const struct smb_filename *smb_fname,
827                         const char *mask,
828                         uint32_t attr)
829 {
830         DIR *result;
831
832         result = SMB_VFS_NEXT_OPENDIR(handle, smb_fname, mask, attr);
833
834         do_log(SMB_VFS_OP_OPENDIR, (result != NULL), handle, "%s",
835                 smb_fname->base_name);
836
837         return result;
838 }
839
840 static DIR *smb_full_audit_fdopendir(vfs_handle_struct *handle,
841                           files_struct *fsp, const char *mask, uint32_t attr)
842 {
843         DIR *result;
844
845         result = SMB_VFS_NEXT_FDOPENDIR(handle, fsp, mask, attr);
846
847         do_log(SMB_VFS_OP_FDOPENDIR, (result != NULL), handle, "%s",
848                         fsp_str_do_log(fsp));
849
850         return result;
851 }
852
853 static struct dirent *smb_full_audit_readdir(vfs_handle_struct *handle,
854                                     DIR *dirp, SMB_STRUCT_STAT *sbuf)
855 {
856         struct dirent *result;
857
858         result = SMB_VFS_NEXT_READDIR(handle, dirp, sbuf);
859
860         /* This operation has no reasonable error condition
861          * (End of dir is also failure), so always succeed.
862          */
863         do_log(SMB_VFS_OP_READDIR, True, handle, "");
864
865         return result;
866 }
867
868 static void smb_full_audit_seekdir(vfs_handle_struct *handle,
869                         DIR *dirp, long offset)
870 {
871         SMB_VFS_NEXT_SEEKDIR(handle, dirp, offset);
872
873         do_log(SMB_VFS_OP_SEEKDIR, True, handle, "");
874 }
875
876 static long smb_full_audit_telldir(vfs_handle_struct *handle,
877                         DIR *dirp)
878 {
879         long result;
880
881         result = SMB_VFS_NEXT_TELLDIR(handle, dirp);
882
883         do_log(SMB_VFS_OP_TELLDIR, True, handle, "");
884
885         return result;
886 }
887
888 static void smb_full_audit_rewinddir(vfs_handle_struct *handle,
889                         DIR *dirp)
890 {
891         SMB_VFS_NEXT_REWINDDIR(handle, dirp);
892
893         do_log(SMB_VFS_OP_REWINDDIR, True, handle, "");
894 }
895
896 static int smb_full_audit_mkdir(vfs_handle_struct *handle,
897                        const struct smb_filename *smb_fname, mode_t mode)
898 {
899         int result;
900         
901         result = SMB_VFS_NEXT_MKDIR(handle, smb_fname, mode);
902         
903         do_log(SMB_VFS_OP_MKDIR, (result >= 0), handle, "%s",
904                 smb_fname->base_name);
905
906         return result;
907 }
908
909 static int smb_full_audit_rmdir(vfs_handle_struct *handle,
910                        const struct smb_filename *smb_fname)
911 {
912         int result;
913         
914         result = SMB_VFS_NEXT_RMDIR(handle, smb_fname);
915
916         do_log(SMB_VFS_OP_RMDIR, (result >= 0), handle, "%s",
917                 smb_fname->base_name);
918
919         return result;
920 }
921
922 static int smb_full_audit_closedir(vfs_handle_struct *handle,
923                           DIR *dirp)
924 {
925         int result;
926
927         result = SMB_VFS_NEXT_CLOSEDIR(handle, dirp);
928         
929         do_log(SMB_VFS_OP_CLOSEDIR, (result >= 0), handle, "");
930
931         return result;
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_pread(vfs_handle_struct *handle, files_struct *fsp,
1036                            void *data, size_t n, off_t offset)
1037 {
1038         ssize_t result;
1039
1040         result = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
1041
1042         do_log(SMB_VFS_OP_PREAD, (result >= 0), handle, "%s",
1043                fsp_str_do_log(fsp));
1044
1045         return result;
1046 }
1047
1048 struct smb_full_audit_pread_state {
1049         vfs_handle_struct *handle;
1050         files_struct *fsp;
1051         ssize_t ret;
1052         struct vfs_aio_state vfs_aio_state;
1053 };
1054
1055 static void smb_full_audit_pread_done(struct tevent_req *subreq);
1056
1057 static struct tevent_req *smb_full_audit_pread_send(
1058         struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1059         struct tevent_context *ev, struct files_struct *fsp,
1060         void *data, size_t n, off_t offset)
1061 {
1062         struct tevent_req *req, *subreq;
1063         struct smb_full_audit_pread_state *state;
1064
1065         req = tevent_req_create(mem_ctx, &state,
1066                                 struct smb_full_audit_pread_state);
1067         if (req == NULL) {
1068                 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
1069                        fsp_str_do_log(fsp));
1070                 return NULL;
1071         }
1072         state->handle = handle;
1073         state->fsp = fsp;
1074
1075         subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
1076                                          n, offset);
1077         if (tevent_req_nomem(subreq, req)) {
1078                 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
1079                        fsp_str_do_log(fsp));
1080                 return tevent_req_post(req, ev);
1081         }
1082         tevent_req_set_callback(subreq, smb_full_audit_pread_done, req);
1083
1084         do_log(SMB_VFS_OP_PREAD_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1085         return req;
1086 }
1087
1088 static void smb_full_audit_pread_done(struct tevent_req *subreq)
1089 {
1090         struct tevent_req *req = tevent_req_callback_data(
1091                 subreq, struct tevent_req);
1092         struct smb_full_audit_pread_state *state = tevent_req_data(
1093                 req, struct smb_full_audit_pread_state);
1094
1095         state->ret = SMB_VFS_PREAD_RECV(subreq, &state->vfs_aio_state);
1096         TALLOC_FREE(subreq);
1097         tevent_req_done(req);
1098 }
1099
1100 static ssize_t smb_full_audit_pread_recv(struct tevent_req *req,
1101                                          struct vfs_aio_state *vfs_aio_state)
1102 {
1103         struct smb_full_audit_pread_state *state = tevent_req_data(
1104                 req, struct smb_full_audit_pread_state);
1105
1106         if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1107                 do_log(SMB_VFS_OP_PREAD_RECV, false, state->handle, "%s",
1108                        fsp_str_do_log(state->fsp));
1109                 return -1;
1110         }
1111
1112         do_log(SMB_VFS_OP_PREAD_RECV, (state->ret >= 0), state->handle, "%s",
1113                fsp_str_do_log(state->fsp));
1114
1115         *vfs_aio_state = state->vfs_aio_state;
1116         return state->ret;
1117 }
1118
1119 static ssize_t smb_full_audit_pwrite(vfs_handle_struct *handle, files_struct *fsp,
1120                             const void *data, size_t n,
1121                             off_t offset)
1122 {
1123         ssize_t result;
1124
1125         result = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
1126
1127         do_log(SMB_VFS_OP_PWRITE, (result >= 0), handle, "%s",
1128                fsp_str_do_log(fsp));
1129
1130         return result;
1131 }
1132
1133 struct smb_full_audit_pwrite_state {
1134         vfs_handle_struct *handle;
1135         files_struct *fsp;
1136         ssize_t ret;
1137         struct vfs_aio_state vfs_aio_state;
1138 };
1139
1140 static void smb_full_audit_pwrite_done(struct tevent_req *subreq);
1141
1142 static struct tevent_req *smb_full_audit_pwrite_send(
1143         struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1144         struct tevent_context *ev, struct files_struct *fsp,
1145         const void *data, size_t n, off_t offset)
1146 {
1147         struct tevent_req *req, *subreq;
1148         struct smb_full_audit_pwrite_state *state;
1149
1150         req = tevent_req_create(mem_ctx, &state,
1151                                 struct smb_full_audit_pwrite_state);
1152         if (req == NULL) {
1153                 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1154                        fsp_str_do_log(fsp));
1155                 return NULL;
1156         }
1157         state->handle = handle;
1158         state->fsp = fsp;
1159
1160         subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
1161                                          n, offset);
1162         if (tevent_req_nomem(subreq, req)) {
1163                 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1164                        fsp_str_do_log(fsp));
1165                 return tevent_req_post(req, ev);
1166         }
1167         tevent_req_set_callback(subreq, smb_full_audit_pwrite_done, req);
1168
1169         do_log(SMB_VFS_OP_PWRITE_SEND, true, handle, "%s",
1170                fsp_str_do_log(fsp));
1171         return req;
1172 }
1173
1174 static void smb_full_audit_pwrite_done(struct tevent_req *subreq)
1175 {
1176         struct tevent_req *req = tevent_req_callback_data(
1177                 subreq, struct tevent_req);
1178         struct smb_full_audit_pwrite_state *state = tevent_req_data(
1179                 req, struct smb_full_audit_pwrite_state);
1180
1181         state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->vfs_aio_state);
1182         TALLOC_FREE(subreq);
1183         tevent_req_done(req);
1184 }
1185
1186 static ssize_t smb_full_audit_pwrite_recv(struct tevent_req *req,
1187                                           struct vfs_aio_state *vfs_aio_state)
1188 {
1189         struct smb_full_audit_pwrite_state *state = tevent_req_data(
1190                 req, struct smb_full_audit_pwrite_state);
1191
1192         if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1193                 do_log(SMB_VFS_OP_PWRITE_RECV, false, state->handle, "%s",
1194                        fsp_str_do_log(state->fsp));
1195                 return -1;
1196         }
1197
1198         do_log(SMB_VFS_OP_PWRITE_RECV, (state->ret >= 0), state->handle, "%s",
1199                fsp_str_do_log(state->fsp));
1200
1201         *vfs_aio_state = state->vfs_aio_state;
1202         return state->ret;
1203 }
1204
1205 static off_t smb_full_audit_lseek(vfs_handle_struct *handle, files_struct *fsp,
1206                              off_t offset, int whence)
1207 {
1208         ssize_t result;
1209
1210         result = SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence);
1211
1212         do_log(SMB_VFS_OP_LSEEK, (result != (ssize_t)-1), handle,
1213                "%s", fsp_str_do_log(fsp));
1214
1215         return result;
1216 }
1217
1218 static ssize_t smb_full_audit_sendfile(vfs_handle_struct *handle, int tofd,
1219                               files_struct *fromfsp,
1220                               const DATA_BLOB *hdr, off_t offset,
1221                               size_t n)
1222 {
1223         ssize_t result;
1224
1225         result = SMB_VFS_NEXT_SENDFILE(handle, tofd, fromfsp, hdr, offset, n);
1226
1227         do_log(SMB_VFS_OP_SENDFILE, (result >= 0), handle,
1228                "%s", fsp_str_do_log(fromfsp));
1229
1230         return result;
1231 }
1232
1233 static ssize_t smb_full_audit_recvfile(vfs_handle_struct *handle, int fromfd,
1234                       files_struct *tofsp,
1235                               off_t offset,
1236                               size_t n)
1237 {
1238         ssize_t result;
1239
1240         result = SMB_VFS_NEXT_RECVFILE(handle, fromfd, tofsp, offset, n);
1241
1242         do_log(SMB_VFS_OP_RECVFILE, (result >= 0), handle,
1243                "%s", fsp_str_do_log(tofsp));
1244
1245         return result;
1246 }
1247
1248 static int smb_full_audit_rename(vfs_handle_struct *handle,
1249                                  const struct smb_filename *smb_fname_src,
1250                                  const struct smb_filename *smb_fname_dst)
1251 {
1252         int result;
1253         
1254         result = SMB_VFS_NEXT_RENAME(handle, smb_fname_src, smb_fname_dst);
1255
1256         do_log(SMB_VFS_OP_RENAME, (result >= 0), handle, "%s|%s",
1257                smb_fname_str_do_log(smb_fname_src),
1258                smb_fname_str_do_log(smb_fname_dst));
1259
1260         return result;    
1261 }
1262
1263 struct smb_full_audit_fsync_state {
1264         vfs_handle_struct *handle;
1265         files_struct *fsp;
1266         int ret;
1267         struct vfs_aio_state vfs_aio_state;
1268 };
1269
1270 static void smb_full_audit_fsync_done(struct tevent_req *subreq);
1271
1272 static struct tevent_req *smb_full_audit_fsync_send(
1273         struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1274         struct tevent_context *ev, struct files_struct *fsp)
1275 {
1276         struct tevent_req *req, *subreq;
1277         struct smb_full_audit_fsync_state *state;
1278
1279         req = tevent_req_create(mem_ctx, &state,
1280                                 struct smb_full_audit_fsync_state);
1281         if (req == NULL) {
1282                 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1283                        fsp_str_do_log(fsp));
1284                 return NULL;
1285         }
1286         state->handle = handle;
1287         state->fsp = fsp;
1288
1289         subreq = SMB_VFS_NEXT_FSYNC_SEND(state, ev, handle, fsp);
1290         if (tevent_req_nomem(subreq, req)) {
1291                 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1292                        fsp_str_do_log(fsp));
1293                 return tevent_req_post(req, ev);
1294         }
1295         tevent_req_set_callback(subreq, smb_full_audit_fsync_done, req);
1296
1297         do_log(SMB_VFS_OP_FSYNC_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1298         return req;
1299 }
1300
1301 static void smb_full_audit_fsync_done(struct tevent_req *subreq)
1302 {
1303         struct tevent_req *req = tevent_req_callback_data(
1304                 subreq, struct tevent_req);
1305         struct smb_full_audit_fsync_state *state = tevent_req_data(
1306                 req, struct smb_full_audit_fsync_state);
1307
1308         state->ret = SMB_VFS_FSYNC_RECV(subreq, &state->vfs_aio_state);
1309         TALLOC_FREE(subreq);
1310         tevent_req_done(req);
1311 }
1312
1313 static int smb_full_audit_fsync_recv(struct tevent_req *req,
1314                                      struct vfs_aio_state *vfs_aio_state)
1315 {
1316         struct smb_full_audit_fsync_state *state = tevent_req_data(
1317                 req, struct smb_full_audit_fsync_state);
1318
1319         if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1320                 do_log(SMB_VFS_OP_FSYNC_RECV, false, state->handle, "%s",
1321                        fsp_str_do_log(state->fsp));
1322                 return -1;
1323         }
1324
1325         do_log(SMB_VFS_OP_FSYNC_RECV, (state->ret >= 0), state->handle, "%s",
1326                fsp_str_do_log(state->fsp));
1327
1328         *vfs_aio_state = state->vfs_aio_state;
1329         return state->ret;
1330 }
1331
1332 static int smb_full_audit_stat(vfs_handle_struct *handle,
1333                                struct smb_filename *smb_fname)
1334 {
1335         int result;
1336         
1337         result = SMB_VFS_NEXT_STAT(handle, smb_fname);
1338
1339         do_log(SMB_VFS_OP_STAT, (result >= 0), handle, "%s",
1340                smb_fname_str_do_log(smb_fname));
1341
1342         return result;    
1343 }
1344
1345 static int smb_full_audit_fstat(vfs_handle_struct *handle, files_struct *fsp,
1346                        SMB_STRUCT_STAT *sbuf)
1347 {
1348         int result;
1349         
1350         result = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1351
1352         do_log(SMB_VFS_OP_FSTAT, (result >= 0), handle, "%s",
1353                fsp_str_do_log(fsp));
1354
1355         return result;
1356 }
1357
1358 static int smb_full_audit_lstat(vfs_handle_struct *handle,
1359                                 struct smb_filename *smb_fname)
1360 {
1361         int result;
1362         
1363         result = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
1364
1365         do_log(SMB_VFS_OP_LSTAT, (result >= 0), handle, "%s",
1366                smb_fname_str_do_log(smb_fname));
1367
1368         return result;    
1369 }
1370
1371 static uint64_t smb_full_audit_get_alloc_size(vfs_handle_struct *handle,
1372                        files_struct *fsp, const SMB_STRUCT_STAT *sbuf)
1373 {
1374         uint64_t result;
1375
1376         result = SMB_VFS_NEXT_GET_ALLOC_SIZE(handle, fsp, sbuf);
1377
1378         do_log(SMB_VFS_OP_GET_ALLOC_SIZE, (result != (uint64_t)-1), handle,
1379                         "%llu", (unsigned long long)result);
1380
1381         return result;
1382 }
1383
1384 static int smb_full_audit_unlink(vfs_handle_struct *handle,
1385                                  const struct smb_filename *smb_fname)
1386 {
1387         int result;
1388         
1389         result = SMB_VFS_NEXT_UNLINK(handle, smb_fname);
1390
1391         do_log(SMB_VFS_OP_UNLINK, (result >= 0), handle, "%s",
1392                smb_fname_str_do_log(smb_fname));
1393
1394         return result;
1395 }
1396
1397 static int smb_full_audit_chmod(vfs_handle_struct *handle,
1398                                 const struct smb_filename *smb_fname,
1399                                 mode_t mode)
1400 {
1401         int result;
1402
1403         result = SMB_VFS_NEXT_CHMOD(handle, smb_fname, mode);
1404
1405         do_log(SMB_VFS_OP_CHMOD, (result >= 0), handle, "%s|%o",
1406                 smb_fname->base_name,
1407                 mode);
1408
1409         return result;
1410 }
1411
1412 static int smb_full_audit_fchmod(vfs_handle_struct *handle, files_struct *fsp,
1413                         mode_t mode)
1414 {
1415         int result;
1416         
1417         result = SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1418
1419         do_log(SMB_VFS_OP_FCHMOD, (result >= 0), handle,
1420                "%s|%o", fsp_str_do_log(fsp), mode);
1421
1422         return result;
1423 }
1424
1425 static int smb_full_audit_chown(vfs_handle_struct *handle,
1426                         const struct smb_filename *smb_fname,
1427                         uid_t uid,
1428                         gid_t gid)
1429 {
1430         int result;
1431
1432         result = SMB_VFS_NEXT_CHOWN(handle, smb_fname, uid, gid);
1433
1434         do_log(SMB_VFS_OP_CHOWN, (result >= 0), handle, "%s|%ld|%ld",
1435                smb_fname->base_name, (long int)uid, (long int)gid);
1436
1437         return result;
1438 }
1439
1440 static int smb_full_audit_fchown(vfs_handle_struct *handle, files_struct *fsp,
1441                         uid_t uid, gid_t gid)
1442 {
1443         int result;
1444
1445         result = SMB_VFS_NEXT_FCHOWN(handle, fsp, uid, gid);
1446
1447         do_log(SMB_VFS_OP_FCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1448                fsp_str_do_log(fsp), (long int)uid, (long int)gid);
1449
1450         return result;
1451 }
1452
1453 static int smb_full_audit_lchown(vfs_handle_struct *handle,
1454                         const struct smb_filename *smb_fname,
1455                         uid_t uid,
1456                         gid_t gid)
1457 {
1458         int result;
1459
1460         result = SMB_VFS_NEXT_LCHOWN(handle, smb_fname, uid, gid);
1461
1462         do_log(SMB_VFS_OP_LCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1463                smb_fname->base_name, (long int)uid, (long int)gid);
1464
1465         return result;
1466 }
1467
1468 static int smb_full_audit_chdir(vfs_handle_struct *handle,
1469                         const struct smb_filename *smb_fname)
1470 {
1471         int result;
1472
1473         result = SMB_VFS_NEXT_CHDIR(handle, smb_fname);
1474
1475         do_log(SMB_VFS_OP_CHDIR, (result >= 0), handle, "chdir|%s",
1476                 smb_fname->base_name);
1477
1478         return result;
1479 }
1480
1481 static struct smb_filename *smb_full_audit_getwd(vfs_handle_struct *handle,
1482                                 TALLOC_CTX *ctx)
1483 {
1484         struct smb_filename *result;
1485
1486         result = SMB_VFS_NEXT_GETWD(handle, ctx);
1487         
1488         do_log(SMB_VFS_OP_GETWD, (result != NULL), handle, "%s",
1489                 result == NULL? "" : result->base_name);
1490
1491         return result;
1492 }
1493
1494 static int smb_full_audit_ntimes(vfs_handle_struct *handle,
1495                                  const struct smb_filename *smb_fname,
1496                                  struct smb_file_time *ft)
1497 {
1498         int result;
1499
1500         result = SMB_VFS_NEXT_NTIMES(handle, smb_fname, ft);
1501
1502         do_log(SMB_VFS_OP_NTIMES, (result >= 0), handle, "%s",
1503                smb_fname_str_do_log(smb_fname));
1504
1505         return result;
1506 }
1507
1508 static int smb_full_audit_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
1509                            off_t len)
1510 {
1511         int result;
1512
1513         result = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1514
1515         do_log(SMB_VFS_OP_FTRUNCATE, (result >= 0), handle,
1516                "%s", fsp_str_do_log(fsp));
1517
1518         return result;
1519 }
1520
1521 static int smb_full_audit_fallocate(vfs_handle_struct *handle, files_struct *fsp,
1522                            uint32_t mode,
1523                            off_t offset,
1524                            off_t len)
1525 {
1526         int result;
1527
1528         result = SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
1529
1530         do_log(SMB_VFS_OP_FALLOCATE, (result >= 0), handle,
1531                "%s", fsp_str_do_log(fsp));
1532
1533         return result;
1534 }
1535
1536 static bool smb_full_audit_lock(vfs_handle_struct *handle, files_struct *fsp,
1537                        int op, off_t offset, off_t count, int type)
1538 {
1539         bool result;
1540
1541         result = SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type);
1542
1543         do_log(SMB_VFS_OP_LOCK, result, handle, "%s", fsp_str_do_log(fsp));
1544
1545         return result;
1546 }
1547
1548 static int smb_full_audit_kernel_flock(struct vfs_handle_struct *handle,
1549                                        struct files_struct *fsp,
1550                                        uint32_t share_mode, uint32_t access_mask)
1551 {
1552         int result;
1553
1554         result = SMB_VFS_NEXT_KERNEL_FLOCK(handle, fsp, share_mode, access_mask);
1555
1556         do_log(SMB_VFS_OP_KERNEL_FLOCK, (result >= 0), handle, "%s",
1557                fsp_str_do_log(fsp));
1558
1559         return result;
1560 }
1561
1562 static int smb_full_audit_linux_setlease(vfs_handle_struct *handle, files_struct *fsp,
1563                                  int leasetype)
1564 {
1565         int result;
1566
1567         result = SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
1568
1569         do_log(SMB_VFS_OP_LINUX_SETLEASE, (result >= 0), handle, "%s",
1570                fsp_str_do_log(fsp));
1571
1572         return result;
1573 }
1574
1575 static bool smb_full_audit_getlock(vfs_handle_struct *handle, files_struct *fsp,
1576                        off_t *poffset, off_t *pcount, int *ptype, pid_t *ppid)
1577 {
1578         bool result;
1579
1580         result = SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype, ppid);
1581
1582         do_log(SMB_VFS_OP_GETLOCK, result, handle, "%s", fsp_str_do_log(fsp));
1583
1584         return result;
1585 }
1586
1587 static int smb_full_audit_symlink(vfs_handle_struct *handle,
1588                         const char *link_contents,
1589                         const struct smb_filename *new_smb_fname)
1590 {
1591         int result;
1592
1593         result = SMB_VFS_NEXT_SYMLINK(handle, link_contents, new_smb_fname);
1594
1595         do_log(SMB_VFS_OP_SYMLINK, (result >= 0), handle,
1596                "%s|%s", link_contents, new_smb_fname->base_name);
1597
1598         return result;
1599 }
1600
1601 static int smb_full_audit_readlink(vfs_handle_struct *handle,
1602                         const struct smb_filename *smb_fname,
1603                         char *buf,
1604                         size_t bufsiz)
1605 {
1606         int result;
1607
1608         result = SMB_VFS_NEXT_READLINK(handle, smb_fname, buf, bufsiz);
1609
1610         do_log(SMB_VFS_OP_READLINK, (result >= 0), handle, "%s",
1611                         smb_fname->base_name);
1612
1613         return result;
1614 }
1615
1616 static int smb_full_audit_link(vfs_handle_struct *handle,
1617                         const struct smb_filename *old_smb_fname,
1618                         const struct smb_filename *new_smb_fname)
1619 {
1620         int result;
1621
1622         result = SMB_VFS_NEXT_LINK(handle, old_smb_fname, new_smb_fname);
1623
1624         do_log(SMB_VFS_OP_LINK, (result >= 0), handle,
1625                "%s|%s", old_smb_fname->base_name, new_smb_fname->base_name);
1626
1627         return result;
1628 }
1629
1630 static int smb_full_audit_mknod(vfs_handle_struct *handle,
1631                         const struct smb_filename *smb_fname,
1632                         mode_t mode,
1633                         SMB_DEV_T dev)
1634 {
1635         int result;
1636
1637         result = SMB_VFS_NEXT_MKNOD(handle, smb_fname, mode, dev);
1638
1639         do_log(SMB_VFS_OP_MKNOD, (result >= 0), handle, "%s",
1640                 smb_fname->base_name);
1641
1642         return result;
1643 }
1644
1645 static struct smb_filename *smb_full_audit_realpath(vfs_handle_struct *handle,
1646                                 TALLOC_CTX *ctx,
1647                                 const struct smb_filename *smb_fname)
1648 {
1649         struct smb_filename *result_fname = NULL;
1650
1651         result_fname = SMB_VFS_NEXT_REALPATH(handle, ctx, smb_fname);
1652
1653         do_log(SMB_VFS_OP_REALPATH, (result_fname != NULL), handle, "%s",
1654                         smb_fname->base_name);
1655
1656         return result_fname;
1657 }
1658
1659 static int smb_full_audit_chflags(vfs_handle_struct *handle,
1660                         const struct smb_filename *smb_fname,
1661                         unsigned int flags)
1662 {
1663         int result;
1664
1665         result = SMB_VFS_NEXT_CHFLAGS(handle, smb_fname, flags);
1666
1667         do_log(SMB_VFS_OP_CHFLAGS, (result != 0), handle, "%s",
1668                 smb_fname->base_name);
1669
1670         return result;
1671 }
1672
1673 static struct file_id smb_full_audit_file_id_create(struct vfs_handle_struct *handle,
1674                                                     const SMB_STRUCT_STAT *sbuf)
1675 {
1676         struct file_id id_zero;
1677         struct file_id result;
1678
1679         ZERO_STRUCT(id_zero);
1680
1681         result = SMB_VFS_NEXT_FILE_ID_CREATE(handle, sbuf);
1682
1683         do_log(SMB_VFS_OP_FILE_ID_CREATE,
1684                !file_id_equal(&id_zero, &result),
1685                handle, "%s", file_id_string_tos(&result));
1686
1687         return result;
1688 }
1689
1690 static NTSTATUS smb_full_audit_streaminfo(vfs_handle_struct *handle,
1691                                           struct files_struct *fsp,
1692                                           const struct smb_filename *smb_fname,
1693                                           TALLOC_CTX *mem_ctx,
1694                                           unsigned int *pnum_streams,
1695                                           struct stream_struct **pstreams)
1696 {
1697         NTSTATUS result;
1698
1699         result = SMB_VFS_NEXT_STREAMINFO(handle, fsp, smb_fname, mem_ctx,
1700                                          pnum_streams, pstreams);
1701
1702         do_log(SMB_VFS_OP_STREAMINFO, NT_STATUS_IS_OK(result), handle,
1703                "%s", smb_fname->base_name);
1704
1705         return result;
1706 }
1707
1708 static int smb_full_audit_get_real_filename(struct vfs_handle_struct *handle,
1709                                             const char *path,
1710                                             const char *name,
1711                                             TALLOC_CTX *mem_ctx,
1712                                             char **found_name)
1713 {
1714         int result;
1715
1716         result = SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name, mem_ctx,
1717                                                 found_name);
1718
1719         do_log(SMB_VFS_OP_GET_REAL_FILENAME, (result == 0), handle,
1720                "%s/%s->%s", path, name, (result == 0) ? "" : *found_name);
1721
1722         return result;
1723 }
1724
1725 static const char *smb_full_audit_connectpath(vfs_handle_struct *handle,
1726                                         const struct smb_filename *smb_fname)
1727 {
1728         const char *result;
1729
1730         result = SMB_VFS_NEXT_CONNECTPATH(handle, smb_fname);
1731
1732         do_log(SMB_VFS_OP_CONNECTPATH, result != NULL, handle,
1733                "%s", smb_fname->base_name);
1734
1735         return result;
1736 }
1737
1738 static NTSTATUS smb_full_audit_brl_lock_windows(struct vfs_handle_struct *handle,
1739                                                 struct byte_range_lock *br_lck,
1740                                                 struct lock_struct *plock,
1741                                                 bool blocking_lock)
1742 {
1743         NTSTATUS result;
1744
1745         result = SMB_VFS_NEXT_BRL_LOCK_WINDOWS(handle, br_lck, plock,
1746                                                blocking_lock);
1747
1748         do_log(SMB_VFS_OP_BRL_LOCK_WINDOWS, NT_STATUS_IS_OK(result), handle,
1749             "%s:%llu-%llu. type=%d. blocking=%d",
1750                fsp_str_do_log(brl_fsp(br_lck)),
1751                (unsigned long long)plock->start,
1752                (unsigned long long)plock->size,
1753                plock->lock_type,
1754                blocking_lock);
1755
1756         return result;
1757 }
1758
1759 static bool smb_full_audit_brl_unlock_windows(struct vfs_handle_struct *handle,
1760                                               struct messaging_context *msg_ctx,
1761                                               struct byte_range_lock *br_lck,
1762                                               const struct lock_struct *plock)
1763 {
1764         bool result;
1765
1766         result = SMB_VFS_NEXT_BRL_UNLOCK_WINDOWS(handle, msg_ctx, br_lck,
1767             plock);
1768
1769         do_log(SMB_VFS_OP_BRL_UNLOCK_WINDOWS, (result == 0), handle,
1770                "%s:%llu-%llu:%d", fsp_str_do_log(brl_fsp(br_lck)),
1771                (unsigned long long)plock->start,
1772                (unsigned long long)plock->size,
1773                plock->lock_type);
1774
1775         return result;
1776 }
1777
1778 static bool smb_full_audit_brl_cancel_windows(struct vfs_handle_struct *handle,
1779                                               struct byte_range_lock *br_lck,
1780                                               struct lock_struct *plock)
1781 {
1782         bool result;
1783
1784         result = SMB_VFS_NEXT_BRL_CANCEL_WINDOWS(handle, br_lck, plock);
1785
1786         do_log(SMB_VFS_OP_BRL_CANCEL_WINDOWS, (result == 0), handle,
1787                "%s:%llu-%llu:%d", fsp_str_do_log(brl_fsp(br_lck)),
1788                (unsigned long long)plock->start,
1789                (unsigned long long)plock->size,
1790                plock->lock_type);
1791
1792         return result;
1793 }
1794
1795 static bool smb_full_audit_strict_lock_check(struct vfs_handle_struct *handle,
1796                                              struct files_struct *fsp,
1797                                              struct lock_struct *plock)
1798 {
1799         bool result;
1800
1801         result = SMB_VFS_NEXT_STRICT_LOCK_CHECK(handle, fsp, plock);
1802
1803         do_log(SMB_VFS_OP_STRICT_LOCK_CHECK, result, handle,
1804                "%s:%llu-%llu:%d", fsp_str_do_log(fsp),
1805                (unsigned long long)plock->start,
1806                (unsigned long long)plock->size,
1807                plock->lock_type);
1808
1809         return result;
1810 }
1811
1812 static NTSTATUS smb_full_audit_translate_name(struct vfs_handle_struct *handle,
1813                                               const char *name,
1814                                               enum vfs_translate_direction direction,
1815                                               TALLOC_CTX *mem_ctx,
1816                                               char **mapped_name)
1817 {
1818         NTSTATUS result;
1819
1820         result = SMB_VFS_NEXT_TRANSLATE_NAME(handle, name, direction, mem_ctx,
1821                                              mapped_name);
1822
1823         do_log(SMB_VFS_OP_TRANSLATE_NAME, NT_STATUS_IS_OK(result), handle, "");
1824
1825         return result;
1826 }
1827
1828 static NTSTATUS smb_full_audit_fsctl(struct vfs_handle_struct *handle,
1829                                 struct files_struct *fsp,
1830                                 TALLOC_CTX *ctx,
1831                                 uint32_t function,
1832                                 uint16_t req_flags,
1833                                 const uint8_t *_in_data,
1834                                 uint32_t in_len,
1835                                 uint8_t **_out_data,
1836                                 uint32_t max_out_len,
1837                                 uint32_t *out_len)
1838 {
1839         NTSTATUS result;
1840
1841         result = SMB_VFS_NEXT_FSCTL(handle,
1842                                 fsp,
1843                                 ctx,
1844                                 function,
1845                                 req_flags,
1846                                 _in_data,
1847                                 in_len,
1848                                 _out_data,
1849                                 max_out_len,
1850                                 out_len);
1851
1852         do_log(SMB_VFS_OP_FSCTL, NT_STATUS_IS_OK(result), handle, "");
1853
1854         return result;
1855 }
1856
1857 static struct tevent_req *smb_full_audit_offload_read_send(
1858         TALLOC_CTX *mem_ctx,
1859         struct tevent_context *ev,
1860         struct vfs_handle_struct *handle,
1861         struct files_struct *fsp,
1862         uint32_t fsctl,
1863         uint32_t ttl,
1864         off_t offset,
1865         size_t to_copy)
1866 {
1867         struct tevent_req *req = NULL;
1868
1869         req = SMB_VFS_NEXT_OFFLOAD_READ_SEND(mem_ctx, ev, handle, fsp,
1870                                              fsctl, ttl, offset, to_copy);
1871
1872         do_log(SMB_VFS_OP_OFFLOAD_READ_SEND, req, handle, "");
1873
1874         return req;
1875 }
1876
1877 static NTSTATUS smb_full_audit_offload_read_recv(
1878         struct tevent_req *req,
1879         struct vfs_handle_struct *handle,
1880         TALLOC_CTX *mem_ctx,
1881         DATA_BLOB *_token_blob)
1882 {
1883         NTSTATUS status;
1884
1885         status = SMB_VFS_NEXT_OFFLOAD_READ_RECV(req, handle, mem_ctx,
1886                                                 _token_blob);
1887
1888         do_log(SMB_VFS_OP_OFFLOAD_READ_RECV, NT_STATUS_IS_OK(status), handle, "");
1889
1890         return status;
1891 }
1892
1893 static struct tevent_req *smb_full_audit_offload_write_send(struct vfs_handle_struct *handle,
1894                                                          TALLOC_CTX *mem_ctx,
1895                                                          struct tevent_context *ev,
1896                                                          uint32_t fsctl,
1897                                                          DATA_BLOB *token,
1898                                                          off_t transfer_offset,
1899                                                          struct files_struct *dest_fsp,
1900                                                          off_t dest_off,
1901                                                             off_t num)
1902 {
1903         struct tevent_req *req;
1904
1905         req = SMB_VFS_NEXT_OFFLOAD_WRITE_SEND(handle, mem_ctx, ev,
1906                                            fsctl, token, transfer_offset,
1907                                            dest_fsp, dest_off, num);
1908
1909         do_log(SMB_VFS_OP_OFFLOAD_WRITE_SEND, req, handle, "");
1910
1911         return req;
1912 }
1913
1914 static NTSTATUS smb_full_audit_offload_write_recv(struct vfs_handle_struct *handle,
1915                                                struct tevent_req *req,
1916                                                off_t *copied)
1917 {
1918         NTSTATUS result;
1919
1920         result = SMB_VFS_NEXT_OFFLOAD_WRITE_RECV(handle, req, copied);
1921
1922         do_log(SMB_VFS_OP_OFFLOAD_WRITE_RECV, NT_STATUS_IS_OK(result), handle, "");
1923
1924         return result;
1925 }
1926
1927 static NTSTATUS smb_full_audit_get_compression(vfs_handle_struct *handle,
1928                                                TALLOC_CTX *mem_ctx,
1929                                                struct files_struct *fsp,
1930                                                struct smb_filename *smb_fname,
1931                                                uint16_t *_compression_fmt)
1932 {
1933         NTSTATUS result;
1934
1935         result = SMB_VFS_NEXT_GET_COMPRESSION(handle, mem_ctx, fsp, smb_fname,
1936                                               _compression_fmt);
1937
1938         do_log(SMB_VFS_OP_GET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
1939                "%s",
1940                (fsp ? fsp_str_do_log(fsp) : smb_fname_str_do_log(smb_fname)));
1941
1942         return result;
1943 }
1944
1945 static NTSTATUS smb_full_audit_set_compression(vfs_handle_struct *handle,
1946                                                TALLOC_CTX *mem_ctx,
1947                                                struct files_struct *fsp,
1948                                                uint16_t compression_fmt)
1949 {
1950         NTSTATUS result;
1951
1952         result = SMB_VFS_NEXT_SET_COMPRESSION(handle, mem_ctx, fsp,
1953                                               compression_fmt);
1954
1955         do_log(SMB_VFS_OP_SET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
1956                "%s", fsp_str_do_log(fsp));
1957
1958         return result;
1959 }
1960
1961 static NTSTATUS smb_full_audit_readdir_attr(struct vfs_handle_struct *handle,
1962                                             const struct smb_filename *fname,
1963                                             TALLOC_CTX *mem_ctx,
1964                                             struct readdir_attr_data **pattr_data)
1965 {
1966         NTSTATUS status;
1967
1968         status = SMB_VFS_NEXT_READDIR_ATTR(handle, fname, mem_ctx, pattr_data);
1969
1970         do_log(SMB_VFS_OP_READDIR_ATTR, NT_STATUS_IS_OK(status), handle, "%s",
1971                smb_fname_str_do_log(fname));
1972
1973         return status;
1974 }
1975
1976 static NTSTATUS smb_full_audit_get_dos_attributes(
1977                                 struct vfs_handle_struct *handle,
1978                                 struct smb_filename *smb_fname,
1979                                 uint32_t *dosmode)
1980 {
1981         NTSTATUS status;
1982
1983         status = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES(handle,
1984                                 smb_fname,
1985                                 dosmode);
1986
1987         do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES,
1988                 NT_STATUS_IS_OK(status),
1989                 handle,
1990                 "%s",
1991                 smb_fname_str_do_log(smb_fname));
1992
1993         return status;
1994 }
1995
1996 static NTSTATUS smb_full_audit_fget_dos_attributes(
1997                                 struct vfs_handle_struct *handle,
1998                                 struct files_struct *fsp,
1999                                 uint32_t *dosmode)
2000 {
2001         NTSTATUS status;
2002
2003         status = SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle,
2004                                 fsp,
2005                                 dosmode);
2006
2007         do_log(SMB_VFS_OP_FGET_DOS_ATTRIBUTES,
2008                 NT_STATUS_IS_OK(status),
2009                 handle,
2010                 "%s",
2011                 fsp_str_do_log(fsp));
2012
2013         return status;
2014 }
2015
2016 static NTSTATUS smb_full_audit_set_dos_attributes(
2017                                 struct vfs_handle_struct *handle,
2018                                 const struct smb_filename *smb_fname,
2019                                 uint32_t dosmode)
2020 {
2021         NTSTATUS status;
2022
2023         status = SMB_VFS_NEXT_SET_DOS_ATTRIBUTES(handle,
2024                                 smb_fname,
2025                                 dosmode);
2026
2027         do_log(SMB_VFS_OP_SET_DOS_ATTRIBUTES,
2028                 NT_STATUS_IS_OK(status),
2029                 handle,
2030                 "%s",
2031                 smb_fname_str_do_log(smb_fname));
2032
2033         return status;
2034 }
2035
2036 static NTSTATUS smb_full_audit_fset_dos_attributes(
2037                                 struct vfs_handle_struct *handle,
2038                                 struct files_struct *fsp,
2039                                 uint32_t dosmode)
2040 {
2041         NTSTATUS status;
2042
2043         status = SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle,
2044                                 fsp,
2045                                 dosmode);
2046
2047         do_log(SMB_VFS_OP_FSET_DOS_ATTRIBUTES,
2048                 NT_STATUS_IS_OK(status),
2049                 handle,
2050                 "%s",
2051                 fsp_str_do_log(fsp));
2052
2053         return status;
2054 }
2055
2056 static NTSTATUS smb_full_audit_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
2057                                            uint32_t security_info,
2058                                            TALLOC_CTX *mem_ctx,
2059                                            struct security_descriptor **ppdesc)
2060 {
2061         NTSTATUS result;
2062
2063         result = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
2064                                           mem_ctx, ppdesc);
2065
2066         do_log(SMB_VFS_OP_FGET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2067                "%s", fsp_str_do_log(fsp));
2068
2069         return result;
2070 }
2071
2072 static NTSTATUS smb_full_audit_get_nt_acl(vfs_handle_struct *handle,
2073                                           const struct smb_filename *smb_fname,
2074                                           uint32_t security_info,
2075                                           TALLOC_CTX *mem_ctx,
2076                                           struct security_descriptor **ppdesc)
2077 {
2078         NTSTATUS result;
2079
2080         result = SMB_VFS_NEXT_GET_NT_ACL(handle, smb_fname, security_info,
2081                                          mem_ctx, ppdesc);
2082
2083         do_log(SMB_VFS_OP_GET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2084                "%s", smb_fname_str_do_log(smb_fname));
2085
2086         return result;
2087 }
2088
2089 static NTSTATUS smb_full_audit_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
2090                               uint32_t security_info_sent,
2091                               const struct security_descriptor *psd)
2092 {
2093         struct vfs_full_audit_private_data *pd;
2094         NTSTATUS result;
2095         char *sd = NULL;
2096
2097         SMB_VFS_HANDLE_GET_DATA(handle, pd,
2098                                 struct vfs_full_audit_private_data,
2099                                 return NT_STATUS_INTERNAL_ERROR);
2100
2101         if (pd->log_secdesc) {
2102                 sd = sddl_encode(talloc_tos(), psd, get_global_sam_sid());
2103         }
2104
2105         result = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
2106
2107         do_log(SMB_VFS_OP_FSET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2108                "%s [%s]", fsp_str_do_log(fsp), sd ? sd : "");
2109
2110         TALLOC_FREE(sd);
2111
2112         return result;
2113 }
2114
2115 static NTSTATUS smb_full_audit_audit_file(struct vfs_handle_struct *handle,
2116                                 struct smb_filename *file,
2117                                 struct security_acl *sacl,
2118                                 uint32_t access_requested,
2119                                 uint32_t access_denied)
2120 {
2121         NTSTATUS result;
2122
2123         result = SMB_VFS_NEXT_AUDIT_FILE(handle,
2124                                         file,
2125                                         sacl,
2126                                         access_requested,
2127                                         access_denied);
2128
2129         do_log(SMB_VFS_OP_AUDIT_FILE, NT_STATUS_IS_OK(result), handle,
2130                         "%s", smb_fname_str_do_log(file));
2131
2132         return result;
2133 }
2134
2135 static int smb_full_audit_chmod_acl(vfs_handle_struct *handle,
2136                                 const struct smb_filename *smb_fname,
2137                                 mode_t mode)
2138 {
2139         int result;
2140         
2141         result = SMB_VFS_NEXT_CHMOD_ACL(handle, smb_fname, mode);
2142
2143         do_log(SMB_VFS_OP_CHMOD_ACL, (result >= 0), handle,
2144                "%s|%o", smb_fname->base_name, mode);
2145
2146         return result;
2147 }
2148
2149 static int smb_full_audit_fchmod_acl(vfs_handle_struct *handle, files_struct *fsp,
2150                                      mode_t mode)
2151 {
2152         int result;
2153         
2154         result = SMB_VFS_NEXT_FCHMOD_ACL(handle, fsp, mode);
2155
2156         do_log(SMB_VFS_OP_FCHMOD_ACL, (result >= 0), handle,
2157                "%s|%o", fsp_str_do_log(fsp), mode);
2158
2159         return result;
2160 }
2161
2162 static SMB_ACL_T smb_full_audit_sys_acl_get_file(vfs_handle_struct *handle,
2163                                 const struct smb_filename *smb_fname,
2164                                 SMB_ACL_TYPE_T type,
2165                                 TALLOC_CTX *mem_ctx)
2166 {
2167         SMB_ACL_T result;
2168
2169         result = SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, smb_fname,
2170                                 type, mem_ctx);
2171
2172         do_log(SMB_VFS_OP_SYS_ACL_GET_FILE, (result != NULL), handle,
2173                "%s", smb_fname->base_name);
2174
2175         return result;
2176 }
2177
2178 static SMB_ACL_T smb_full_audit_sys_acl_get_fd(vfs_handle_struct *handle,
2179                                                files_struct *fsp, TALLOC_CTX *mem_ctx)
2180 {
2181         SMB_ACL_T result;
2182
2183         result = SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp, mem_ctx);
2184
2185         do_log(SMB_VFS_OP_SYS_ACL_GET_FD, (result != NULL), handle,
2186                "%s", fsp_str_do_log(fsp));
2187
2188         return result;
2189 }
2190
2191 static int smb_full_audit_sys_acl_blob_get_file(vfs_handle_struct *handle,
2192                                 const struct smb_filename *smb_fname,
2193                                 TALLOC_CTX *mem_ctx,
2194                                 char **blob_description,
2195                                 DATA_BLOB *blob)
2196 {
2197         int result;
2198
2199         result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FILE(handle, smb_fname,
2200                         mem_ctx, blob_description, blob);
2201
2202         do_log(SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE, (result >= 0), handle,
2203                "%s", smb_fname->base_name);
2204
2205         return result;
2206 }
2207
2208 static int smb_full_audit_sys_acl_blob_get_fd(vfs_handle_struct *handle,
2209                                               files_struct *fsp,
2210                                               TALLOC_CTX *mem_ctx,
2211                                               char **blob_description,
2212                                               DATA_BLOB *blob)
2213 {
2214         int result;
2215
2216         result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle, fsp, mem_ctx, blob_description, blob);
2217
2218         do_log(SMB_VFS_OP_SYS_ACL_BLOB_GET_FD, (result >= 0), handle,
2219                "%s", fsp_str_do_log(fsp));
2220
2221         return result;
2222 }
2223
2224 static int smb_full_audit_sys_acl_set_file(vfs_handle_struct *handle,
2225                                 const struct smb_filename *smb_fname,
2226                                 SMB_ACL_TYPE_T acltype,
2227                                 SMB_ACL_T theacl)
2228 {
2229         int result;
2230
2231         result = SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, smb_fname, acltype,
2232                                                theacl);
2233
2234         do_log(SMB_VFS_OP_SYS_ACL_SET_FILE, (result >= 0), handle,
2235                "%s", smb_fname->base_name);
2236
2237         return result;
2238 }
2239
2240 static int smb_full_audit_sys_acl_set_fd(vfs_handle_struct *handle, files_struct *fsp,
2241                                 SMB_ACL_T theacl)
2242 {
2243         int result;
2244
2245         result = SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, theacl);
2246
2247         do_log(SMB_VFS_OP_SYS_ACL_SET_FD, (result >= 0), handle,
2248                "%s", fsp_str_do_log(fsp));
2249
2250         return result;
2251 }
2252
2253 static int smb_full_audit_sys_acl_delete_def_file(vfs_handle_struct *handle,
2254                                 const struct smb_filename *smb_fname)
2255 {
2256         int result;
2257
2258         result = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, smb_fname);
2259
2260         do_log(SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE, (result >= 0), handle,
2261                "%s", smb_fname->base_name);
2262
2263         return result;
2264 }
2265
2266 static ssize_t smb_full_audit_getxattr(struct vfs_handle_struct *handle,
2267                               const struct smb_filename *smb_fname,
2268                               const char *name, void *value, size_t size)
2269 {
2270         ssize_t result;
2271
2272         result = SMB_VFS_NEXT_GETXATTR(handle, smb_fname, name, value, size);
2273
2274         do_log(SMB_VFS_OP_GETXATTR, (result >= 0), handle,
2275                "%s|%s", smb_fname->base_name, name);
2276
2277         return result;
2278 }
2279
2280 static ssize_t smb_full_audit_fgetxattr(struct vfs_handle_struct *handle,
2281                                struct files_struct *fsp,
2282                                const char *name, void *value, size_t size)
2283 {
2284         ssize_t result;
2285
2286         result = SMB_VFS_NEXT_FGETXATTR(handle, fsp, name, value, size);
2287
2288         do_log(SMB_VFS_OP_FGETXATTR, (result >= 0), handle,
2289                "%s|%s", fsp_str_do_log(fsp), name);
2290
2291         return result;
2292 }
2293
2294 static ssize_t smb_full_audit_listxattr(struct vfs_handle_struct *handle,
2295                                 const struct smb_filename *smb_fname,
2296                                 char *list,
2297                                 size_t size)
2298 {
2299         ssize_t result;
2300
2301         result = SMB_VFS_NEXT_LISTXATTR(handle, smb_fname, list, size);
2302
2303         do_log(SMB_VFS_OP_LISTXATTR, (result >= 0), handle, "%s",
2304                         smb_fname->base_name);
2305
2306         return result;
2307 }
2308
2309 static ssize_t smb_full_audit_flistxattr(struct vfs_handle_struct *handle,
2310                                 struct files_struct *fsp, char *list,
2311                                 size_t size)
2312 {
2313         ssize_t result;
2314
2315         result = SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
2316
2317         do_log(SMB_VFS_OP_FLISTXATTR, (result >= 0), handle,
2318                "%s", fsp_str_do_log(fsp));
2319
2320         return result;
2321 }
2322
2323 static int smb_full_audit_removexattr(struct vfs_handle_struct *handle,
2324                              const struct smb_filename *smb_fname,
2325                              const char *name)
2326 {
2327         int result;
2328
2329         result = SMB_VFS_NEXT_REMOVEXATTR(handle, smb_fname, name);
2330
2331         do_log(SMB_VFS_OP_REMOVEXATTR, (result >= 0), handle,
2332                "%s|%s", smb_fname->base_name, name);
2333
2334         return result;
2335 }
2336
2337 static int smb_full_audit_fremovexattr(struct vfs_handle_struct *handle,
2338                               struct files_struct *fsp,
2339                               const char *name)
2340 {
2341         int result;
2342
2343         result = SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, name);
2344
2345         do_log(SMB_VFS_OP_FREMOVEXATTR, (result >= 0), handle,
2346                "%s|%s", fsp_str_do_log(fsp), name);
2347
2348         return result;
2349 }
2350
2351 static int smb_full_audit_setxattr(struct vfs_handle_struct *handle,
2352                           const struct smb_filename *smb_fname,
2353                           const char *name, const void *value, size_t size,
2354                           int flags)
2355 {
2356         int result;
2357
2358         result = SMB_VFS_NEXT_SETXATTR(handle, smb_fname, name, value, size,
2359                                        flags);
2360
2361         do_log(SMB_VFS_OP_SETXATTR, (result >= 0), handle,
2362                "%s|%s", smb_fname->base_name, name);
2363
2364         return result;
2365 }
2366
2367 static int smb_full_audit_fsetxattr(struct vfs_handle_struct *handle,
2368                            struct files_struct *fsp, const char *name,
2369                            const void *value, size_t size, int flags)
2370 {
2371         int result;
2372
2373         result = SMB_VFS_NEXT_FSETXATTR(handle, fsp, name, value, size, flags);
2374
2375         do_log(SMB_VFS_OP_FSETXATTR, (result >= 0), handle,
2376                "%s|%s", fsp_str_do_log(fsp), name);
2377
2378         return result;
2379 }
2380
2381 static bool smb_full_audit_aio_force(struct vfs_handle_struct *handle,
2382                                      struct files_struct *fsp)
2383 {
2384         bool result;
2385
2386         result = SMB_VFS_NEXT_AIO_FORCE(handle, fsp);
2387         do_log(SMB_VFS_OP_AIO_FORCE, result, handle,
2388                 "%s", fsp_str_do_log(fsp));
2389
2390         return result;
2391 }
2392
2393 static NTSTATUS smb_full_audit_durable_cookie(struct vfs_handle_struct *handle,
2394                                 struct files_struct *fsp,
2395                                 TALLOC_CTX *mem_ctx,
2396                                 DATA_BLOB *cookie)
2397 {
2398         NTSTATUS result;
2399
2400         result = SMB_VFS_NEXT_DURABLE_COOKIE(handle,
2401                                         fsp,
2402                                         mem_ctx,
2403                                         cookie);
2404
2405         do_log(SMB_VFS_OP_DURABLE_COOKIE, NT_STATUS_IS_OK(result), handle,
2406                         "%s", fsp_str_do_log(fsp));
2407
2408         return result;
2409 }
2410
2411 static NTSTATUS smb_full_audit_durable_disconnect(
2412                                 struct vfs_handle_struct *handle,
2413                                 struct files_struct *fsp,
2414                                 const DATA_BLOB old_cookie,
2415                                 TALLOC_CTX *mem_ctx,
2416                                 DATA_BLOB *new_cookie)
2417 {
2418         NTSTATUS result;
2419
2420         result = SMB_VFS_NEXT_DURABLE_DISCONNECT(handle,
2421                                         fsp,
2422                                         old_cookie,
2423                                         mem_ctx,
2424                                         new_cookie);
2425
2426         do_log(SMB_VFS_OP_DURABLE_DISCONNECT, NT_STATUS_IS_OK(result), handle,
2427                         "%s", fsp_str_do_log(fsp));
2428
2429         return result;
2430 }
2431
2432 static NTSTATUS smb_full_audit_durable_reconnect(
2433                                 struct vfs_handle_struct *handle,
2434                                 struct smb_request *smb1req,
2435                                 struct smbXsrv_open *op,
2436                                 const DATA_BLOB old_cookie,
2437                                 TALLOC_CTX *mem_ctx,
2438                                 struct files_struct **fsp,
2439                                 DATA_BLOB *new_cookie)
2440 {
2441         NTSTATUS result;
2442
2443         result = SMB_VFS_NEXT_DURABLE_RECONNECT(handle,
2444                                         smb1req,
2445                                         op,
2446                                         old_cookie,
2447                                         mem_ctx,
2448                                         fsp,
2449                                         new_cookie);
2450
2451         do_log(SMB_VFS_OP_DURABLE_RECONNECT,
2452                         NT_STATUS_IS_OK(result),
2453                         handle,
2454                         "");
2455
2456         return result;
2457 }
2458
2459 static struct vfs_fn_pointers vfs_full_audit_fns = {
2460
2461         /* Disk operations */
2462
2463         .connect_fn = smb_full_audit_connect,
2464         .disconnect_fn = smb_full_audit_disconnect,
2465         .disk_free_fn = smb_full_audit_disk_free,
2466         .get_quota_fn = smb_full_audit_get_quota,
2467         .set_quota_fn = smb_full_audit_set_quota,
2468         .get_shadow_copy_data_fn = smb_full_audit_get_shadow_copy_data,
2469         .statvfs_fn = smb_full_audit_statvfs,
2470         .fs_capabilities_fn = smb_full_audit_fs_capabilities,
2471         .get_dfs_referrals_fn = smb_full_audit_get_dfs_referrals,
2472         .opendir_fn = smb_full_audit_opendir,
2473         .fdopendir_fn = smb_full_audit_fdopendir,
2474         .readdir_fn = smb_full_audit_readdir,
2475         .seekdir_fn = smb_full_audit_seekdir,
2476         .telldir_fn = smb_full_audit_telldir,
2477         .rewind_dir_fn = smb_full_audit_rewinddir,
2478         .mkdir_fn = smb_full_audit_mkdir,
2479         .rmdir_fn = smb_full_audit_rmdir,
2480         .closedir_fn = smb_full_audit_closedir,
2481         .open_fn = smb_full_audit_open,
2482         .create_file_fn = smb_full_audit_create_file,
2483         .close_fn = smb_full_audit_close,
2484         .pread_fn = smb_full_audit_pread,
2485         .pread_send_fn = smb_full_audit_pread_send,
2486         .pread_recv_fn = smb_full_audit_pread_recv,
2487         .pwrite_fn = smb_full_audit_pwrite,
2488         .pwrite_send_fn = smb_full_audit_pwrite_send,
2489         .pwrite_recv_fn = smb_full_audit_pwrite_recv,
2490         .lseek_fn = smb_full_audit_lseek,
2491         .sendfile_fn = smb_full_audit_sendfile,
2492         .recvfile_fn = smb_full_audit_recvfile,
2493         .rename_fn = smb_full_audit_rename,
2494         .fsync_send_fn = smb_full_audit_fsync_send,
2495         .fsync_recv_fn = smb_full_audit_fsync_recv,
2496         .stat_fn = smb_full_audit_stat,
2497         .fstat_fn = smb_full_audit_fstat,
2498         .lstat_fn = smb_full_audit_lstat,
2499         .get_alloc_size_fn = smb_full_audit_get_alloc_size,
2500         .unlink_fn = smb_full_audit_unlink,
2501         .chmod_fn = smb_full_audit_chmod,
2502         .fchmod_fn = smb_full_audit_fchmod,
2503         .chown_fn = smb_full_audit_chown,
2504         .fchown_fn = smb_full_audit_fchown,
2505         .lchown_fn = smb_full_audit_lchown,
2506         .chdir_fn = smb_full_audit_chdir,
2507         .getwd_fn = smb_full_audit_getwd,
2508         .ntimes_fn = smb_full_audit_ntimes,
2509         .ftruncate_fn = smb_full_audit_ftruncate,
2510         .fallocate_fn = smb_full_audit_fallocate,
2511         .lock_fn = smb_full_audit_lock,
2512         .kernel_flock_fn = smb_full_audit_kernel_flock,
2513         .linux_setlease_fn = smb_full_audit_linux_setlease,
2514         .getlock_fn = smb_full_audit_getlock,
2515         .symlink_fn = smb_full_audit_symlink,
2516         .readlink_fn = smb_full_audit_readlink,
2517         .link_fn = smb_full_audit_link,
2518         .mknod_fn = smb_full_audit_mknod,
2519         .realpath_fn = smb_full_audit_realpath,
2520         .chflags_fn = smb_full_audit_chflags,
2521         .file_id_create_fn = smb_full_audit_file_id_create,
2522         .offload_read_send_fn = smb_full_audit_offload_read_send,
2523         .offload_read_recv_fn = smb_full_audit_offload_read_recv,
2524         .offload_write_send_fn = smb_full_audit_offload_write_send,
2525         .offload_write_recv_fn = smb_full_audit_offload_write_recv,
2526         .get_compression_fn = smb_full_audit_get_compression,
2527         .set_compression_fn = smb_full_audit_set_compression,
2528         .snap_check_path_fn =  smb_full_audit_snap_check_path,
2529         .snap_create_fn = smb_full_audit_snap_create,
2530         .snap_delete_fn = smb_full_audit_snap_delete,
2531         .streaminfo_fn = smb_full_audit_streaminfo,
2532         .get_real_filename_fn = smb_full_audit_get_real_filename,
2533         .connectpath_fn = smb_full_audit_connectpath,
2534         .brl_lock_windows_fn = smb_full_audit_brl_lock_windows,
2535         .brl_unlock_windows_fn = smb_full_audit_brl_unlock_windows,
2536         .brl_cancel_windows_fn = smb_full_audit_brl_cancel_windows,
2537         .strict_lock_check_fn = smb_full_audit_strict_lock_check,
2538         .translate_name_fn = smb_full_audit_translate_name,
2539         .fsctl_fn = smb_full_audit_fsctl,
2540         .get_dos_attributes_fn = smb_full_audit_get_dos_attributes,
2541         .fget_dos_attributes_fn = smb_full_audit_fget_dos_attributes,
2542         .set_dos_attributes_fn = smb_full_audit_set_dos_attributes,
2543         .fset_dos_attributes_fn = smb_full_audit_fset_dos_attributes,
2544         .fget_nt_acl_fn = smb_full_audit_fget_nt_acl,
2545         .get_nt_acl_fn = smb_full_audit_get_nt_acl,
2546         .fset_nt_acl_fn = smb_full_audit_fset_nt_acl,
2547         .audit_file_fn = smb_full_audit_audit_file,
2548         .chmod_acl_fn = smb_full_audit_chmod_acl,
2549         .fchmod_acl_fn = smb_full_audit_fchmod_acl,
2550         .sys_acl_get_file_fn = smb_full_audit_sys_acl_get_file,
2551         .sys_acl_get_fd_fn = smb_full_audit_sys_acl_get_fd,
2552         .sys_acl_blob_get_file_fn = smb_full_audit_sys_acl_blob_get_file,
2553         .sys_acl_blob_get_fd_fn = smb_full_audit_sys_acl_blob_get_fd,
2554         .sys_acl_set_file_fn = smb_full_audit_sys_acl_set_file,
2555         .sys_acl_set_fd_fn = smb_full_audit_sys_acl_set_fd,
2556         .sys_acl_delete_def_file_fn = smb_full_audit_sys_acl_delete_def_file,
2557         .getxattr_fn = smb_full_audit_getxattr,
2558         .fgetxattr_fn = smb_full_audit_fgetxattr,
2559         .listxattr_fn = smb_full_audit_listxattr,
2560         .flistxattr_fn = smb_full_audit_flistxattr,
2561         .removexattr_fn = smb_full_audit_removexattr,
2562         .fremovexattr_fn = smb_full_audit_fremovexattr,
2563         .setxattr_fn = smb_full_audit_setxattr,
2564         .fsetxattr_fn = smb_full_audit_fsetxattr,
2565         .aio_force_fn = smb_full_audit_aio_force,
2566         .durable_cookie_fn = smb_full_audit_durable_cookie,
2567         .durable_disconnect_fn = smb_full_audit_durable_disconnect,
2568         .durable_reconnect_fn = smb_full_audit_durable_reconnect,
2569         .readdir_attr_fn = smb_full_audit_readdir_attr
2570
2571 };
2572
2573 static_decl_vfs;
2574 NTSTATUS vfs_full_audit_init(TALLOC_CTX *ctx)
2575 {
2576         NTSTATUS ret;
2577
2578         smb_vfs_assert_all_fns(&vfs_full_audit_fns, "full_audit");
2579
2580         ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "full_audit",
2581                                &vfs_full_audit_fns);
2582
2583         if (!NT_STATUS_IS_OK(ret))
2584                 return ret;
2585
2586         vfs_full_audit_debug_level = debug_add_class("full_audit");
2587         if (vfs_full_audit_debug_level == -1) {
2588                 vfs_full_audit_debug_level = DBGC_VFS;
2589                 DEBUG(0, ("vfs_full_audit: Couldn't register custom debugging "
2590                           "class!\n"));
2591         } else {
2592                 DEBUG(10, ("vfs_full_audit: Debug class number of "
2593                            "'full_audit': %d\n", vfs_full_audit_debug_level));
2594         }
2595         
2596         return ret;
2597 }