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