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