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