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