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