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