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