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