s3: VFS: Change SMB_VFS_DISK_FREE to use const struct smb_filename * instead of const...
[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 char *path, enum SMB_QUOTA_TYPE qtype,
697                                     unid_t id, SMB_DISK_QUOTA *qt)
698 {
699         int result;
700
701         result = SMB_VFS_NEXT_GET_QUOTA(handle, path, qtype, id, qt);
702
703         do_log(SMB_VFS_OP_GET_QUOTA, (result >= 0), handle, "%s", path);
704
705         return result;
706 }
707
708 static int smb_full_audit_set_quota(struct vfs_handle_struct *handle,
709                            enum SMB_QUOTA_TYPE qtype, unid_t id,
710                            SMB_DISK_QUOTA *qt)
711 {
712         int result;
713
714         result = SMB_VFS_NEXT_SET_QUOTA(handle, qtype, id, qt);
715
716         do_log(SMB_VFS_OP_SET_QUOTA, (result >= 0), handle, "");
717
718         return result;
719 }
720
721 static int smb_full_audit_get_shadow_copy_data(struct vfs_handle_struct *handle,
722                                 struct files_struct *fsp,
723                                 struct shadow_copy_data *shadow_copy_data,
724                                 bool labels)
725 {
726         int result;
727
728         result = SMB_VFS_NEXT_GET_SHADOW_COPY_DATA(handle, fsp, shadow_copy_data, labels);
729
730         do_log(SMB_VFS_OP_GET_SHADOW_COPY_DATA, (result >= 0), handle, "");
731
732         return result;
733 }
734
735 static int smb_full_audit_statvfs(struct vfs_handle_struct *handle,
736                                 const char *path,
737                                 struct vfs_statvfs_struct *statbuf)
738 {
739         int result;
740
741         result = SMB_VFS_NEXT_STATVFS(handle, path, statbuf);
742
743         do_log(SMB_VFS_OP_STATVFS, (result >= 0), handle, "");
744
745         return result;
746 }
747
748 static uint32_t smb_full_audit_fs_capabilities(struct vfs_handle_struct *handle, enum timestamp_set_resolution *p_ts_res)
749 {
750         int result;
751
752         result = SMB_VFS_NEXT_FS_CAPABILITIES(handle, p_ts_res);
753
754         do_log(SMB_VFS_OP_FS_CAPABILITIES, true, handle, "");
755
756         return result;
757 }
758
759 static NTSTATUS smb_full_audit_get_dfs_referrals(
760                                 struct vfs_handle_struct *handle,
761                                 struct dfs_GetDFSReferral *r)
762 {
763         NTSTATUS status;
764
765         status = SMB_VFS_NEXT_GET_DFS_REFERRALS(handle, r);
766
767         do_log(SMB_VFS_OP_GET_DFS_REFERRALS, NT_STATUS_IS_OK(status),
768                handle, "");
769
770         return status;
771 }
772
773 static NTSTATUS smb_full_audit_snap_check_path(struct vfs_handle_struct *handle,
774                                                TALLOC_CTX *mem_ctx,
775                                                const char *service_path,
776                                                char **base_volume)
777 {
778         NTSTATUS status;
779
780         status = SMB_VFS_NEXT_SNAP_CHECK_PATH(handle, mem_ctx, service_path,
781                                               base_volume);
782         do_log(SMB_VFS_OP_SNAP_CHECK_PATH, NT_STATUS_IS_OK(status),
783                handle, "");
784
785         return status;
786 }
787
788 static NTSTATUS smb_full_audit_snap_create(struct vfs_handle_struct *handle,
789                                            TALLOC_CTX *mem_ctx,
790                                            const char *base_volume,
791                                            time_t *tstamp,
792                                            bool rw,
793                                            char **base_path,
794                                            char **snap_path)
795 {
796         NTSTATUS status;
797
798         status = SMB_VFS_NEXT_SNAP_CREATE(handle, mem_ctx, base_volume, tstamp,
799                                           rw, base_path, snap_path);
800         do_log(SMB_VFS_OP_SNAP_CREATE, NT_STATUS_IS_OK(status), handle, "");
801
802         return status;
803 }
804
805 static NTSTATUS smb_full_audit_snap_delete(struct vfs_handle_struct *handle,
806                                            TALLOC_CTX *mem_ctx,
807                                            char *base_path,
808                                            char *snap_path)
809 {
810         NTSTATUS status;
811
812         status = SMB_VFS_NEXT_SNAP_DELETE(handle, mem_ctx, base_path,
813                                           snap_path);
814         do_log(SMB_VFS_OP_SNAP_DELETE, NT_STATUS_IS_OK(status), handle, "");
815
816         return status;
817 }
818
819 static DIR *smb_full_audit_opendir(vfs_handle_struct *handle,
820                         const struct smb_filename *smb_fname,
821                         const char *mask,
822                         uint32_t attr)
823 {
824         DIR *result;
825
826         result = SMB_VFS_NEXT_OPENDIR(handle, smb_fname, mask, attr);
827
828         do_log(SMB_VFS_OP_OPENDIR, (result != NULL), handle, "%s",
829                 smb_fname->base_name);
830
831         return result;
832 }
833
834 static DIR *smb_full_audit_fdopendir(vfs_handle_struct *handle,
835                           files_struct *fsp, const char *mask, uint32_t attr)
836 {
837         DIR *result;
838
839         result = SMB_VFS_NEXT_FDOPENDIR(handle, fsp, mask, attr);
840
841         do_log(SMB_VFS_OP_FDOPENDIR, (result != NULL), handle, "%s",
842                         fsp_str_do_log(fsp));
843
844         return result;
845 }
846
847 static struct dirent *smb_full_audit_readdir(vfs_handle_struct *handle,
848                                     DIR *dirp, SMB_STRUCT_STAT *sbuf)
849 {
850         struct dirent *result;
851
852         result = SMB_VFS_NEXT_READDIR(handle, dirp, sbuf);
853
854         /* This operation has no reasonable error condition
855          * (End of dir is also failure), so always succeed.
856          */
857         do_log(SMB_VFS_OP_READDIR, True, handle, "");
858
859         return result;
860 }
861
862 static void smb_full_audit_seekdir(vfs_handle_struct *handle,
863                         DIR *dirp, long offset)
864 {
865         SMB_VFS_NEXT_SEEKDIR(handle, dirp, offset);
866
867         do_log(SMB_VFS_OP_SEEKDIR, True, handle, "");
868 }
869
870 static long smb_full_audit_telldir(vfs_handle_struct *handle,
871                         DIR *dirp)
872 {
873         long result;
874
875         result = SMB_VFS_NEXT_TELLDIR(handle, dirp);
876
877         do_log(SMB_VFS_OP_TELLDIR, True, handle, "");
878
879         return result;
880 }
881
882 static void smb_full_audit_rewinddir(vfs_handle_struct *handle,
883                         DIR *dirp)
884 {
885         SMB_VFS_NEXT_REWINDDIR(handle, dirp);
886
887         do_log(SMB_VFS_OP_REWINDDIR, True, handle, "");
888 }
889
890 static int smb_full_audit_mkdir(vfs_handle_struct *handle,
891                        const struct smb_filename *smb_fname, mode_t mode)
892 {
893         int result;
894         
895         result = SMB_VFS_NEXT_MKDIR(handle, smb_fname, mode);
896         
897         do_log(SMB_VFS_OP_MKDIR, (result >= 0), handle, "%s",
898                 smb_fname->base_name);
899
900         return result;
901 }
902
903 static int smb_full_audit_rmdir(vfs_handle_struct *handle,
904                        const struct smb_filename *smb_fname)
905 {
906         int result;
907         
908         result = SMB_VFS_NEXT_RMDIR(handle, smb_fname);
909
910         do_log(SMB_VFS_OP_RMDIR, (result >= 0), handle, "%s",
911                 smb_fname->base_name);
912
913         return result;
914 }
915
916 static int smb_full_audit_closedir(vfs_handle_struct *handle,
917                           DIR *dirp)
918 {
919         int result;
920
921         result = SMB_VFS_NEXT_CLOSEDIR(handle, dirp);
922         
923         do_log(SMB_VFS_OP_CLOSEDIR, (result >= 0), handle, "");
924
925         return result;
926 }
927
928 static void smb_full_audit_init_search_op(vfs_handle_struct *handle,
929                         DIR *dirp)
930 {
931         SMB_VFS_NEXT_INIT_SEARCH_OP(handle, dirp);
932
933         do_log(SMB_VFS_OP_INIT_SEARCH_OP, True, handle, "");
934 }
935
936 static int smb_full_audit_open(vfs_handle_struct *handle,
937                                struct smb_filename *smb_fname,
938                                files_struct *fsp, int flags, mode_t mode)
939 {
940         int result;
941         
942         result = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
943
944         do_log(SMB_VFS_OP_OPEN, (result >= 0), handle, "%s|%s",
945                ((flags & O_WRONLY) || (flags & O_RDWR))?"w":"r",
946                smb_fname_str_do_log(smb_fname));
947
948         return result;
949 }
950
951 static NTSTATUS smb_full_audit_create_file(vfs_handle_struct *handle,
952                                       struct smb_request *req,
953                                       uint16_t root_dir_fid,
954                                       struct smb_filename *smb_fname,
955                                       uint32_t access_mask,
956                                       uint32_t share_access,
957                                       uint32_t create_disposition,
958                                       uint32_t create_options,
959                                       uint32_t file_attributes,
960                                       uint32_t oplock_request,
961                                       struct smb2_lease *lease,
962                                       uint64_t allocation_size,
963                                       uint32_t private_flags,
964                                       struct security_descriptor *sd,
965                                       struct ea_list *ea_list,
966                                       files_struct **result_fsp,
967                                       int *pinfo,
968                                       const struct smb2_create_blobs *in_context_blobs,
969                                       struct smb2_create_blobs *out_context_blobs)
970 {
971         NTSTATUS result;
972         const char* str_create_disposition;
973
974         switch (create_disposition) {
975         case FILE_SUPERSEDE:
976                 str_create_disposition = "supersede";
977                 break;
978         case FILE_OVERWRITE_IF:
979                 str_create_disposition = "overwrite_if";
980                 break;
981         case FILE_OPEN:
982                 str_create_disposition = "open";
983                 break;
984         case FILE_OVERWRITE:
985                 str_create_disposition = "overwrite";
986                 break;
987         case FILE_CREATE:
988                 str_create_disposition = "create";
989                 break;
990         case FILE_OPEN_IF:
991                 str_create_disposition = "open_if";
992                 break;
993         default:
994                 str_create_disposition = "unknown";
995         }
996
997         result = SMB_VFS_NEXT_CREATE_FILE(
998                 handle,                                 /* handle */
999                 req,                                    /* req */
1000                 root_dir_fid,                           /* root_dir_fid */
1001                 smb_fname,                              /* fname */
1002                 access_mask,                            /* access_mask */
1003                 share_access,                           /* share_access */
1004                 create_disposition,                     /* create_disposition*/
1005                 create_options,                         /* create_options */
1006                 file_attributes,                        /* file_attributes */
1007                 oplock_request,                         /* oplock_request */
1008                 lease,                                  /* lease */
1009                 allocation_size,                        /* allocation_size */
1010                 private_flags,
1011                 sd,                                     /* sd */
1012                 ea_list,                                /* ea_list */
1013                 result_fsp,                             /* result */
1014                 pinfo,                                  /* pinfo */
1015                 in_context_blobs, out_context_blobs);   /* create context */
1016
1017         do_log(SMB_VFS_OP_CREATE_FILE, (NT_STATUS_IS_OK(result)), handle,
1018                "0x%x|%s|%s|%s", access_mask,
1019                create_options & FILE_DIRECTORY_FILE ? "dir" : "file",
1020                str_create_disposition, smb_fname_str_do_log(smb_fname));
1021
1022         return result;
1023 }
1024
1025 static int smb_full_audit_close(vfs_handle_struct *handle, files_struct *fsp)
1026 {
1027         int result;
1028         
1029         result = SMB_VFS_NEXT_CLOSE(handle, fsp);
1030
1031         do_log(SMB_VFS_OP_CLOSE, (result >= 0), handle, "%s",
1032                fsp_str_do_log(fsp));
1033
1034         return result;
1035 }
1036
1037 static ssize_t smb_full_audit_read(vfs_handle_struct *handle, files_struct *fsp,
1038                           void *data, size_t n)
1039 {
1040         ssize_t result;
1041
1042         result = SMB_VFS_NEXT_READ(handle, fsp, data, n);
1043
1044         do_log(SMB_VFS_OP_READ, (result >= 0), handle, "%s",
1045                fsp_str_do_log(fsp));
1046
1047         return result;
1048 }
1049
1050 static ssize_t smb_full_audit_pread(vfs_handle_struct *handle, files_struct *fsp,
1051                            void *data, size_t n, off_t offset)
1052 {
1053         ssize_t result;
1054
1055         result = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
1056
1057         do_log(SMB_VFS_OP_PREAD, (result >= 0), handle, "%s",
1058                fsp_str_do_log(fsp));
1059
1060         return result;
1061 }
1062
1063 struct smb_full_audit_pread_state {
1064         vfs_handle_struct *handle;
1065         files_struct *fsp;
1066         ssize_t ret;
1067         struct vfs_aio_state vfs_aio_state;
1068 };
1069
1070 static void smb_full_audit_pread_done(struct tevent_req *subreq);
1071
1072 static struct tevent_req *smb_full_audit_pread_send(
1073         struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1074         struct tevent_context *ev, struct files_struct *fsp,
1075         void *data, size_t n, off_t offset)
1076 {
1077         struct tevent_req *req, *subreq;
1078         struct smb_full_audit_pread_state *state;
1079
1080         req = tevent_req_create(mem_ctx, &state,
1081                                 struct smb_full_audit_pread_state);
1082         if (req == NULL) {
1083                 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
1084                        fsp_str_do_log(fsp));
1085                 return NULL;
1086         }
1087         state->handle = handle;
1088         state->fsp = fsp;
1089
1090         subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
1091                                          n, offset);
1092         if (tevent_req_nomem(subreq, req)) {
1093                 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
1094                        fsp_str_do_log(fsp));
1095                 return tevent_req_post(req, ev);
1096         }
1097         tevent_req_set_callback(subreq, smb_full_audit_pread_done, req);
1098
1099         do_log(SMB_VFS_OP_PREAD_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1100         return req;
1101 }
1102
1103 static void smb_full_audit_pread_done(struct tevent_req *subreq)
1104 {
1105         struct tevent_req *req = tevent_req_callback_data(
1106                 subreq, struct tevent_req);
1107         struct smb_full_audit_pread_state *state = tevent_req_data(
1108                 req, struct smb_full_audit_pread_state);
1109
1110         state->ret = SMB_VFS_PREAD_RECV(subreq, &state->vfs_aio_state);
1111         TALLOC_FREE(subreq);
1112         tevent_req_done(req);
1113 }
1114
1115 static ssize_t smb_full_audit_pread_recv(struct tevent_req *req,
1116                                          struct vfs_aio_state *vfs_aio_state)
1117 {
1118         struct smb_full_audit_pread_state *state = tevent_req_data(
1119                 req, struct smb_full_audit_pread_state);
1120
1121         if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1122                 do_log(SMB_VFS_OP_PREAD_RECV, false, state->handle, "%s",
1123                        fsp_str_do_log(state->fsp));
1124                 return -1;
1125         }
1126
1127         do_log(SMB_VFS_OP_PREAD_RECV, (state->ret >= 0), state->handle, "%s",
1128                fsp_str_do_log(state->fsp));
1129
1130         *vfs_aio_state = state->vfs_aio_state;
1131         return state->ret;
1132 }
1133
1134 static ssize_t smb_full_audit_write(vfs_handle_struct *handle, files_struct *fsp,
1135                            const void *data, size_t n)
1136 {
1137         ssize_t result;
1138
1139         result = SMB_VFS_NEXT_WRITE(handle, fsp, data, n);
1140
1141         do_log(SMB_VFS_OP_WRITE, (result >= 0), handle, "%s",
1142                fsp_str_do_log(fsp));
1143
1144         return result;
1145 }
1146
1147 static ssize_t smb_full_audit_pwrite(vfs_handle_struct *handle, files_struct *fsp,
1148                             const void *data, size_t n,
1149                             off_t offset)
1150 {
1151         ssize_t result;
1152
1153         result = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
1154
1155         do_log(SMB_VFS_OP_PWRITE, (result >= 0), handle, "%s",
1156                fsp_str_do_log(fsp));
1157
1158         return result;
1159 }
1160
1161 struct smb_full_audit_pwrite_state {
1162         vfs_handle_struct *handle;
1163         files_struct *fsp;
1164         ssize_t ret;
1165         struct vfs_aio_state vfs_aio_state;
1166 };
1167
1168 static void smb_full_audit_pwrite_done(struct tevent_req *subreq);
1169
1170 static struct tevent_req *smb_full_audit_pwrite_send(
1171         struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1172         struct tevent_context *ev, struct files_struct *fsp,
1173         const void *data, size_t n, off_t offset)
1174 {
1175         struct tevent_req *req, *subreq;
1176         struct smb_full_audit_pwrite_state *state;
1177
1178         req = tevent_req_create(mem_ctx, &state,
1179                                 struct smb_full_audit_pwrite_state);
1180         if (req == NULL) {
1181                 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1182                        fsp_str_do_log(fsp));
1183                 return NULL;
1184         }
1185         state->handle = handle;
1186         state->fsp = fsp;
1187
1188         subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
1189                                          n, offset);
1190         if (tevent_req_nomem(subreq, req)) {
1191                 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1192                        fsp_str_do_log(fsp));
1193                 return tevent_req_post(req, ev);
1194         }
1195         tevent_req_set_callback(subreq, smb_full_audit_pwrite_done, req);
1196
1197         do_log(SMB_VFS_OP_PWRITE_SEND, true, handle, "%s",
1198                fsp_str_do_log(fsp));
1199         return req;
1200 }
1201
1202 static void smb_full_audit_pwrite_done(struct tevent_req *subreq)
1203 {
1204         struct tevent_req *req = tevent_req_callback_data(
1205                 subreq, struct tevent_req);
1206         struct smb_full_audit_pwrite_state *state = tevent_req_data(
1207                 req, struct smb_full_audit_pwrite_state);
1208
1209         state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->vfs_aio_state);
1210         TALLOC_FREE(subreq);
1211         tevent_req_done(req);
1212 }
1213
1214 static ssize_t smb_full_audit_pwrite_recv(struct tevent_req *req,
1215                                           struct vfs_aio_state *vfs_aio_state)
1216 {
1217         struct smb_full_audit_pwrite_state *state = tevent_req_data(
1218                 req, struct smb_full_audit_pwrite_state);
1219
1220         if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1221                 do_log(SMB_VFS_OP_PWRITE_RECV, false, state->handle, "%s",
1222                        fsp_str_do_log(state->fsp));
1223                 return -1;
1224         }
1225
1226         do_log(SMB_VFS_OP_PWRITE_RECV, (state->ret >= 0), state->handle, "%s",
1227                fsp_str_do_log(state->fsp));
1228
1229         *vfs_aio_state = state->vfs_aio_state;
1230         return state->ret;
1231 }
1232
1233 static off_t smb_full_audit_lseek(vfs_handle_struct *handle, files_struct *fsp,
1234                              off_t offset, int whence)
1235 {
1236         ssize_t result;
1237
1238         result = SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence);
1239
1240         do_log(SMB_VFS_OP_LSEEK, (result != (ssize_t)-1), handle,
1241                "%s", fsp_str_do_log(fsp));
1242
1243         return result;
1244 }
1245
1246 static ssize_t smb_full_audit_sendfile(vfs_handle_struct *handle, int tofd,
1247                               files_struct *fromfsp,
1248                               const DATA_BLOB *hdr, off_t offset,
1249                               size_t n)
1250 {
1251         ssize_t result;
1252
1253         result = SMB_VFS_NEXT_SENDFILE(handle, tofd, fromfsp, hdr, offset, n);
1254
1255         do_log(SMB_VFS_OP_SENDFILE, (result >= 0), handle,
1256                "%s", fsp_str_do_log(fromfsp));
1257
1258         return result;
1259 }
1260
1261 static ssize_t smb_full_audit_recvfile(vfs_handle_struct *handle, int fromfd,
1262                       files_struct *tofsp,
1263                               off_t offset,
1264                               size_t n)
1265 {
1266         ssize_t result;
1267
1268         result = SMB_VFS_NEXT_RECVFILE(handle, fromfd, tofsp, offset, n);
1269
1270         do_log(SMB_VFS_OP_RECVFILE, (result >= 0), handle,
1271                "%s", fsp_str_do_log(tofsp));
1272
1273         return result;
1274 }
1275
1276 static int smb_full_audit_rename(vfs_handle_struct *handle,
1277                                  const struct smb_filename *smb_fname_src,
1278                                  const struct smb_filename *smb_fname_dst)
1279 {
1280         int result;
1281         
1282         result = SMB_VFS_NEXT_RENAME(handle, smb_fname_src, smb_fname_dst);
1283
1284         do_log(SMB_VFS_OP_RENAME, (result >= 0), handle, "%s|%s",
1285                smb_fname_str_do_log(smb_fname_src),
1286                smb_fname_str_do_log(smb_fname_dst));
1287
1288         return result;    
1289 }
1290
1291 static int smb_full_audit_fsync(vfs_handle_struct *handle, files_struct *fsp)
1292 {
1293         int result;
1294         
1295         result = SMB_VFS_NEXT_FSYNC(handle, fsp);
1296
1297         do_log(SMB_VFS_OP_FSYNC, (result >= 0), handle, "%s",
1298                fsp_str_do_log(fsp));
1299
1300         return result;    
1301 }
1302
1303 struct smb_full_audit_fsync_state {
1304         vfs_handle_struct *handle;
1305         files_struct *fsp;
1306         int ret;
1307         struct vfs_aio_state vfs_aio_state;
1308 };
1309
1310 static void smb_full_audit_fsync_done(struct tevent_req *subreq);
1311
1312 static struct tevent_req *smb_full_audit_fsync_send(
1313         struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1314         struct tevent_context *ev, struct files_struct *fsp)
1315 {
1316         struct tevent_req *req, *subreq;
1317         struct smb_full_audit_fsync_state *state;
1318
1319         req = tevent_req_create(mem_ctx, &state,
1320                                 struct smb_full_audit_fsync_state);
1321         if (req == NULL) {
1322                 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1323                        fsp_str_do_log(fsp));
1324                 return NULL;
1325         }
1326         state->handle = handle;
1327         state->fsp = fsp;
1328
1329         subreq = SMB_VFS_NEXT_FSYNC_SEND(state, ev, handle, fsp);
1330         if (tevent_req_nomem(subreq, req)) {
1331                 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1332                        fsp_str_do_log(fsp));
1333                 return tevent_req_post(req, ev);
1334         }
1335         tevent_req_set_callback(subreq, smb_full_audit_fsync_done, req);
1336
1337         do_log(SMB_VFS_OP_FSYNC_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1338         return req;
1339 }
1340
1341 static void smb_full_audit_fsync_done(struct tevent_req *subreq)
1342 {
1343         struct tevent_req *req = tevent_req_callback_data(
1344                 subreq, struct tevent_req);
1345         struct smb_full_audit_fsync_state *state = tevent_req_data(
1346                 req, struct smb_full_audit_fsync_state);
1347
1348         state->ret = SMB_VFS_FSYNC_RECV(subreq, &state->vfs_aio_state);
1349         TALLOC_FREE(subreq);
1350         tevent_req_done(req);
1351 }
1352
1353 static int smb_full_audit_fsync_recv(struct tevent_req *req,
1354                                      struct vfs_aio_state *vfs_aio_state)
1355 {
1356         struct smb_full_audit_fsync_state *state = tevent_req_data(
1357                 req, struct smb_full_audit_fsync_state);
1358
1359         if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1360                 do_log(SMB_VFS_OP_FSYNC_RECV, false, state->handle, "%s",
1361                        fsp_str_do_log(state->fsp));
1362                 return -1;
1363         }
1364
1365         do_log(SMB_VFS_OP_FSYNC_RECV, (state->ret >= 0), state->handle, "%s",
1366                fsp_str_do_log(state->fsp));
1367
1368         *vfs_aio_state = state->vfs_aio_state;
1369         return state->ret;
1370 }
1371
1372 static int smb_full_audit_stat(vfs_handle_struct *handle,
1373                                struct smb_filename *smb_fname)
1374 {
1375         int result;
1376         
1377         result = SMB_VFS_NEXT_STAT(handle, smb_fname);
1378
1379         do_log(SMB_VFS_OP_STAT, (result >= 0), handle, "%s",
1380                smb_fname_str_do_log(smb_fname));
1381
1382         return result;    
1383 }
1384
1385 static int smb_full_audit_fstat(vfs_handle_struct *handle, files_struct *fsp,
1386                        SMB_STRUCT_STAT *sbuf)
1387 {
1388         int result;
1389         
1390         result = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1391
1392         do_log(SMB_VFS_OP_FSTAT, (result >= 0), handle, "%s",
1393                fsp_str_do_log(fsp));
1394
1395         return result;
1396 }
1397
1398 static int smb_full_audit_lstat(vfs_handle_struct *handle,
1399                                 struct smb_filename *smb_fname)
1400 {
1401         int result;
1402         
1403         result = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
1404
1405         do_log(SMB_VFS_OP_LSTAT, (result >= 0), handle, "%s",
1406                smb_fname_str_do_log(smb_fname));
1407
1408         return result;    
1409 }
1410
1411 static uint64_t smb_full_audit_get_alloc_size(vfs_handle_struct *handle,
1412                        files_struct *fsp, const SMB_STRUCT_STAT *sbuf)
1413 {
1414         uint64_t result;
1415
1416         result = SMB_VFS_NEXT_GET_ALLOC_SIZE(handle, fsp, sbuf);
1417
1418         do_log(SMB_VFS_OP_GET_ALLOC_SIZE, (result != (uint64_t)-1), handle,
1419                         "%llu", result);
1420
1421         return result;
1422 }
1423
1424 static int smb_full_audit_unlink(vfs_handle_struct *handle,
1425                                  const struct smb_filename *smb_fname)
1426 {
1427         int result;
1428         
1429         result = SMB_VFS_NEXT_UNLINK(handle, smb_fname);
1430
1431         do_log(SMB_VFS_OP_UNLINK, (result >= 0), handle, "%s",
1432                smb_fname_str_do_log(smb_fname));
1433
1434         return result;
1435 }
1436
1437 static int smb_full_audit_chmod(vfs_handle_struct *handle,
1438                                 const struct smb_filename *smb_fname,
1439                                 mode_t mode)
1440 {
1441         int result;
1442
1443         result = SMB_VFS_NEXT_CHMOD(handle, smb_fname, mode);
1444
1445         do_log(SMB_VFS_OP_CHMOD, (result >= 0), handle, "%s|%o",
1446                 smb_fname->base_name,
1447                 mode);
1448
1449         return result;
1450 }
1451
1452 static int smb_full_audit_fchmod(vfs_handle_struct *handle, files_struct *fsp,
1453                         mode_t mode)
1454 {
1455         int result;
1456         
1457         result = SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1458
1459         do_log(SMB_VFS_OP_FCHMOD, (result >= 0), handle,
1460                "%s|%o", fsp_str_do_log(fsp), mode);
1461
1462         return result;
1463 }
1464
1465 static int smb_full_audit_chown(vfs_handle_struct *handle,
1466                         const struct smb_filename *smb_fname,
1467                         uid_t uid,
1468                         gid_t gid)
1469 {
1470         int result;
1471
1472         result = SMB_VFS_NEXT_CHOWN(handle, smb_fname, uid, gid);
1473
1474         do_log(SMB_VFS_OP_CHOWN, (result >= 0), handle, "%s|%ld|%ld",
1475                smb_fname->base_name, (long int)uid, (long int)gid);
1476
1477         return result;
1478 }
1479
1480 static int smb_full_audit_fchown(vfs_handle_struct *handle, files_struct *fsp,
1481                         uid_t uid, gid_t gid)
1482 {
1483         int result;
1484
1485         result = SMB_VFS_NEXT_FCHOWN(handle, fsp, uid, gid);
1486
1487         do_log(SMB_VFS_OP_FCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1488                fsp_str_do_log(fsp), (long int)uid, (long int)gid);
1489
1490         return result;
1491 }
1492
1493 static int smb_full_audit_lchown(vfs_handle_struct *handle,
1494                         const struct smb_filename *smb_fname,
1495                         uid_t uid,
1496                         gid_t gid)
1497 {
1498         int result;
1499
1500         result = SMB_VFS_NEXT_LCHOWN(handle, smb_fname, uid, gid);
1501
1502         do_log(SMB_VFS_OP_LCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1503                smb_fname->base_name, (long int)uid, (long int)gid);
1504
1505         return result;
1506 }
1507
1508 static int smb_full_audit_chdir(vfs_handle_struct *handle,
1509                        const char *path)
1510 {
1511         int result;
1512
1513         result = SMB_VFS_NEXT_CHDIR(handle, path);
1514
1515         do_log(SMB_VFS_OP_CHDIR, (result >= 0), handle, "chdir|%s", path);
1516
1517         return result;
1518 }
1519
1520 static char *smb_full_audit_getwd(vfs_handle_struct *handle)
1521 {
1522         char *result;
1523
1524         result = SMB_VFS_NEXT_GETWD(handle);
1525         
1526         do_log(SMB_VFS_OP_GETWD, (result != NULL), handle, "%s",
1527                 result == NULL? "" : result);
1528
1529         return result;
1530 }
1531
1532 static int smb_full_audit_ntimes(vfs_handle_struct *handle,
1533                                  const struct smb_filename *smb_fname,
1534                                  struct smb_file_time *ft)
1535 {
1536         int result;
1537
1538         result = SMB_VFS_NEXT_NTIMES(handle, smb_fname, ft);
1539
1540         do_log(SMB_VFS_OP_NTIMES, (result >= 0), handle, "%s",
1541                smb_fname_str_do_log(smb_fname));
1542
1543         return result;
1544 }
1545
1546 static int smb_full_audit_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
1547                            off_t len)
1548 {
1549         int result;
1550
1551         result = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1552
1553         do_log(SMB_VFS_OP_FTRUNCATE, (result >= 0), handle,
1554                "%s", fsp_str_do_log(fsp));
1555
1556         return result;
1557 }
1558
1559 static int smb_full_audit_fallocate(vfs_handle_struct *handle, files_struct *fsp,
1560                            uint32_t mode,
1561                            off_t offset,
1562                            off_t len)
1563 {
1564         int result;
1565
1566         result = SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
1567
1568         do_log(SMB_VFS_OP_FALLOCATE, (result >= 0), handle,
1569                "%s", fsp_str_do_log(fsp));
1570
1571         return result;
1572 }
1573
1574 static bool smb_full_audit_lock(vfs_handle_struct *handle, files_struct *fsp,
1575                        int op, off_t offset, off_t count, int type)
1576 {
1577         bool result;
1578
1579         result = SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type);
1580
1581         do_log(SMB_VFS_OP_LOCK, result, handle, "%s", fsp_str_do_log(fsp));
1582
1583         return result;
1584 }
1585
1586 static int smb_full_audit_kernel_flock(struct vfs_handle_struct *handle,
1587                                        struct files_struct *fsp,
1588                                        uint32_t share_mode, uint32_t access_mask)
1589 {
1590         int result;
1591
1592         result = SMB_VFS_NEXT_KERNEL_FLOCK(handle, fsp, share_mode, access_mask);
1593
1594         do_log(SMB_VFS_OP_KERNEL_FLOCK, (result >= 0), handle, "%s",
1595                fsp_str_do_log(fsp));
1596
1597         return result;
1598 }
1599
1600 static int smb_full_audit_linux_setlease(vfs_handle_struct *handle, files_struct *fsp,
1601                                  int leasetype)
1602 {
1603         int result;
1604
1605         result = SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
1606
1607         do_log(SMB_VFS_OP_LINUX_SETLEASE, (result >= 0), handle, "%s",
1608                fsp_str_do_log(fsp));
1609
1610         return result;
1611 }
1612
1613 static bool smb_full_audit_getlock(vfs_handle_struct *handle, files_struct *fsp,
1614                        off_t *poffset, off_t *pcount, int *ptype, pid_t *ppid)
1615 {
1616         bool result;
1617
1618         result = SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype, ppid);
1619
1620         do_log(SMB_VFS_OP_GETLOCK, result, handle, "%s", fsp_str_do_log(fsp));
1621
1622         return result;
1623 }
1624
1625 static int smb_full_audit_symlink(vfs_handle_struct *handle,
1626                          const char *oldpath, const char *newpath)
1627 {
1628         int result;
1629
1630         result = SMB_VFS_NEXT_SYMLINK(handle, oldpath, newpath);
1631
1632         do_log(SMB_VFS_OP_SYMLINK, (result >= 0), handle,
1633                "%s|%s", oldpath, newpath);
1634
1635         return result;
1636 }
1637
1638 static int smb_full_audit_readlink(vfs_handle_struct *handle,
1639                           const char *path, char *buf, size_t bufsiz)
1640 {
1641         int result;
1642
1643         result = SMB_VFS_NEXT_READLINK(handle, path, buf, bufsiz);
1644
1645         do_log(SMB_VFS_OP_READLINK, (result >= 0), handle, "%s", path);
1646
1647         return result;
1648 }
1649
1650 static int smb_full_audit_link(vfs_handle_struct *handle,
1651                       const char *oldpath, const char *newpath)
1652 {
1653         int result;
1654
1655         result = SMB_VFS_NEXT_LINK(handle, oldpath, newpath);
1656
1657         do_log(SMB_VFS_OP_LINK, (result >= 0), handle,
1658                "%s|%s", oldpath, newpath);
1659
1660         return result;
1661 }
1662
1663 static int smb_full_audit_mknod(vfs_handle_struct *handle,
1664                         const struct smb_filename *smb_fname,
1665                         mode_t mode,
1666                         SMB_DEV_T dev)
1667 {
1668         int result;
1669
1670         result = SMB_VFS_NEXT_MKNOD(handle, smb_fname, mode, dev);
1671
1672         do_log(SMB_VFS_OP_MKNOD, (result >= 0), handle, "%s",
1673                 smb_fname->base_name);
1674
1675         return result;
1676 }
1677
1678 static char *smb_full_audit_realpath(vfs_handle_struct *handle,
1679                             const char *path)
1680 {
1681         char *result;
1682
1683         result = SMB_VFS_NEXT_REALPATH(handle, path);
1684
1685         do_log(SMB_VFS_OP_REALPATH, (result != NULL), handle, "%s", path);
1686
1687         return result;
1688 }
1689
1690 static int smb_full_audit_chflags(vfs_handle_struct *handle,
1691                         const struct smb_filename *smb_fname,
1692                         unsigned int flags)
1693 {
1694         int result;
1695
1696         result = SMB_VFS_NEXT_CHFLAGS(handle, smb_fname, flags);
1697
1698         do_log(SMB_VFS_OP_CHFLAGS, (result != 0), handle, "%s",
1699                 smb_fname->base_name);
1700
1701         return result;
1702 }
1703
1704 static struct file_id smb_full_audit_file_id_create(struct vfs_handle_struct *handle,
1705                                                     const SMB_STRUCT_STAT *sbuf)
1706 {
1707         struct file_id id_zero;
1708         struct file_id result;
1709
1710         ZERO_STRUCT(id_zero);
1711
1712         result = SMB_VFS_NEXT_FILE_ID_CREATE(handle, sbuf);
1713
1714         do_log(SMB_VFS_OP_FILE_ID_CREATE,
1715                !file_id_equal(&id_zero, &result),
1716                handle, "%s", file_id_string_tos(&result));
1717
1718         return result;
1719 }
1720
1721 static NTSTATUS smb_full_audit_streaminfo(vfs_handle_struct *handle,
1722                                           struct files_struct *fsp,
1723                                           const struct smb_filename *smb_fname,
1724                                           TALLOC_CTX *mem_ctx,
1725                                           unsigned int *pnum_streams,
1726                                           struct stream_struct **pstreams)
1727 {
1728         NTSTATUS result;
1729
1730         result = SMB_VFS_NEXT_STREAMINFO(handle, fsp, smb_fname, mem_ctx,
1731                                          pnum_streams, pstreams);
1732
1733         do_log(SMB_VFS_OP_STREAMINFO, NT_STATUS_IS_OK(result), handle,
1734                "%s", smb_fname->base_name);
1735
1736         return result;
1737 }
1738
1739 static int smb_full_audit_get_real_filename(struct vfs_handle_struct *handle,
1740                                             const char *path,
1741                                             const char *name,
1742                                             TALLOC_CTX *mem_ctx,
1743                                             char **found_name)
1744 {
1745         int result;
1746
1747         result = SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name, mem_ctx,
1748                                                 found_name);
1749
1750         do_log(SMB_VFS_OP_GET_REAL_FILENAME, (result == 0), handle,
1751                "%s/%s->%s", path, name, (result == 0) ? "" : *found_name);
1752
1753         return result;
1754 }
1755
1756 static const char *smb_full_audit_connectpath(vfs_handle_struct *handle,
1757                                               const char *fname)
1758 {
1759         const char *result;
1760
1761         result = SMB_VFS_NEXT_CONNECTPATH(handle, fname);
1762
1763         do_log(SMB_VFS_OP_CONNECTPATH, result != NULL, handle,
1764                "%s", fname);
1765
1766         return result;
1767 }
1768
1769 static NTSTATUS smb_full_audit_brl_lock_windows(struct vfs_handle_struct *handle,
1770                                                 struct byte_range_lock *br_lck,
1771                                                 struct lock_struct *plock,
1772                                                 bool blocking_lock)
1773 {
1774         NTSTATUS result;
1775
1776         result = SMB_VFS_NEXT_BRL_LOCK_WINDOWS(handle, br_lck, plock,
1777                                                blocking_lock);
1778
1779         do_log(SMB_VFS_OP_BRL_LOCK_WINDOWS, NT_STATUS_IS_OK(result), handle,
1780             "%s:%llu-%llu. type=%d. blocking=%d",
1781                fsp_str_do_log(brl_fsp(br_lck)),
1782             plock->start, plock->size, plock->lock_type, blocking_lock);
1783
1784         return result;
1785 }
1786
1787 static bool smb_full_audit_brl_unlock_windows(struct vfs_handle_struct *handle,
1788                                               struct messaging_context *msg_ctx,
1789                                               struct byte_range_lock *br_lck,
1790                                               const struct lock_struct *plock)
1791 {
1792         bool result;
1793
1794         result = SMB_VFS_NEXT_BRL_UNLOCK_WINDOWS(handle, msg_ctx, br_lck,
1795             plock);
1796
1797         do_log(SMB_VFS_OP_BRL_UNLOCK_WINDOWS, (result == 0), handle,
1798                "%s:%llu-%llu:%d", fsp_str_do_log(brl_fsp(br_lck)),
1799                plock->start,
1800             plock->size, plock->lock_type);
1801
1802         return result;
1803 }
1804
1805 static bool smb_full_audit_brl_cancel_windows(struct vfs_handle_struct *handle,
1806                                               struct byte_range_lock *br_lck,
1807                                               struct lock_struct *plock)
1808 {
1809         bool result;
1810
1811         result = SMB_VFS_NEXT_BRL_CANCEL_WINDOWS(handle, br_lck, plock);
1812
1813         do_log(SMB_VFS_OP_BRL_CANCEL_WINDOWS, (result == 0), handle,
1814                "%s:%llu-%llu:%d", fsp_str_do_log(brl_fsp(br_lck)),
1815                plock->start,
1816             plock->size, plock->lock_type);
1817
1818         return result;
1819 }
1820
1821 static bool smb_full_audit_strict_lock(struct vfs_handle_struct *handle,
1822                                        struct files_struct *fsp,
1823                                        struct lock_struct *plock)
1824 {
1825         bool result;
1826
1827         result = SMB_VFS_NEXT_STRICT_LOCK(handle, fsp, plock);
1828
1829         do_log(SMB_VFS_OP_STRICT_LOCK, result, handle,
1830             "%s:%llu-%llu:%d", fsp_str_do_log(fsp), plock->start,
1831             plock->size, plock->lock_type);
1832
1833         return result;
1834 }
1835
1836 static void smb_full_audit_strict_unlock(struct vfs_handle_struct *handle,
1837                                          struct files_struct *fsp,
1838                                          struct lock_struct *plock)
1839 {
1840         SMB_VFS_NEXT_STRICT_UNLOCK(handle, fsp, plock);
1841
1842         do_log(SMB_VFS_OP_STRICT_UNLOCK, true, handle,
1843             "%s:%llu-%llu:%d", fsp_str_do_log(fsp), plock->start,
1844             plock->size, plock->lock_type);
1845 }
1846
1847 static NTSTATUS smb_full_audit_translate_name(struct vfs_handle_struct *handle,
1848                                               const char *name,
1849                                               enum vfs_translate_direction direction,
1850                                               TALLOC_CTX *mem_ctx,
1851                                               char **mapped_name)
1852 {
1853         NTSTATUS result;
1854
1855         result = SMB_VFS_NEXT_TRANSLATE_NAME(handle, name, direction, mem_ctx,
1856                                              mapped_name);
1857
1858         do_log(SMB_VFS_OP_TRANSLATE_NAME, NT_STATUS_IS_OK(result), handle, "");
1859
1860         return result;
1861 }
1862
1863 static NTSTATUS smb_full_audit_fsctl(struct vfs_handle_struct *handle,
1864                                 struct files_struct *fsp,
1865                                 TALLOC_CTX *ctx,
1866                                 uint32_t function,
1867                                 uint16_t req_flags,
1868                                 const uint8_t *_in_data,
1869                                 uint32_t in_len,
1870                                 uint8_t **_out_data,
1871                                 uint32_t max_out_len,
1872                                 uint32_t *out_len)
1873 {
1874         NTSTATUS result;
1875
1876         result = SMB_VFS_NEXT_FSCTL(handle,
1877                                 fsp,
1878                                 ctx,
1879                                 function,
1880                                 req_flags,
1881                                 _in_data,
1882                                 in_len,
1883                                 _out_data,
1884                                 max_out_len,
1885                                 out_len);
1886
1887         do_log(SMB_VFS_OP_FSCTL, NT_STATUS_IS_OK(result), handle, "");
1888
1889         return result;
1890 }
1891
1892 static struct tevent_req *smb_full_audit_copy_chunk_send(struct vfs_handle_struct *handle,
1893                                                          TALLOC_CTX *mem_ctx,
1894                                                          struct tevent_context *ev,
1895                                                          struct files_struct *src_fsp,
1896                                                          off_t src_off,
1897                                                          struct files_struct *dest_fsp,
1898                                                          off_t dest_off,
1899                                                          off_t num,
1900                                                          uint32_t flags)
1901 {
1902         struct tevent_req *req;
1903
1904         req = SMB_VFS_NEXT_COPY_CHUNK_SEND(handle, mem_ctx, ev, src_fsp,
1905                                            src_off, dest_fsp, dest_off, num,
1906                                            flags);
1907
1908         do_log(SMB_VFS_OP_COPY_CHUNK_SEND, req, handle, "");
1909
1910         return req;
1911 }
1912
1913 static NTSTATUS smb_full_audit_copy_chunk_recv(struct vfs_handle_struct *handle,
1914                                                struct tevent_req *req,
1915                                                off_t *copied)
1916 {
1917         NTSTATUS result;
1918
1919         result = SMB_VFS_NEXT_COPY_CHUNK_RECV(handle, req, copied);
1920
1921         do_log(SMB_VFS_OP_COPY_CHUNK_RECV, NT_STATUS_IS_OK(result), handle, "");
1922
1923         return result;
1924 }
1925
1926 static NTSTATUS smb_full_audit_get_compression(vfs_handle_struct *handle,
1927                                                TALLOC_CTX *mem_ctx,
1928                                                struct files_struct *fsp,
1929                                                struct smb_filename *smb_fname,
1930                                                uint16_t *_compression_fmt)
1931 {
1932         NTSTATUS result;
1933
1934         result = SMB_VFS_NEXT_GET_COMPRESSION(handle, mem_ctx, fsp, smb_fname,
1935                                               _compression_fmt);
1936
1937         do_log(SMB_VFS_OP_GET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
1938                "%s",
1939                (fsp ? fsp_str_do_log(fsp) : smb_fname_str_do_log(smb_fname)));
1940
1941         return result;
1942 }
1943
1944 static NTSTATUS smb_full_audit_set_compression(vfs_handle_struct *handle,
1945                                                TALLOC_CTX *mem_ctx,
1946                                                struct files_struct *fsp,
1947                                                uint16_t compression_fmt)
1948 {
1949         NTSTATUS result;
1950
1951         result = SMB_VFS_NEXT_SET_COMPRESSION(handle, mem_ctx, fsp,
1952                                               compression_fmt);
1953
1954         do_log(SMB_VFS_OP_SET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
1955                "%s", fsp_str_do_log(fsp));
1956
1957         return result;
1958 }
1959
1960 static NTSTATUS smb_full_audit_readdir_attr(struct vfs_handle_struct *handle,
1961                                             const struct smb_filename *fname,
1962                                             TALLOC_CTX *mem_ctx,
1963                                             struct readdir_attr_data **pattr_data)
1964 {
1965         NTSTATUS status;
1966
1967         status = SMB_VFS_NEXT_READDIR_ATTR(handle, fname, mem_ctx, pattr_data);
1968
1969         do_log(SMB_VFS_OP_READDIR_ATTR, NT_STATUS_IS_OK(status), handle, "%s",
1970                smb_fname_str_do_log(fname));
1971
1972         return status;
1973 }
1974
1975 static NTSTATUS smb_full_audit_get_dos_attributes(
1976                                 struct vfs_handle_struct *handle,
1977                                 struct smb_filename *smb_fname,
1978                                 uint32_t *dosmode)
1979 {
1980         NTSTATUS status;
1981
1982         status = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES(handle,
1983                                 smb_fname,
1984                                 dosmode);
1985
1986         do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES,
1987                 NT_STATUS_IS_OK(status),
1988                 handle,
1989                 "%s",
1990                 smb_fname_str_do_log(smb_fname));
1991
1992         return status;
1993 }
1994
1995 static NTSTATUS smb_full_audit_fget_dos_attributes(
1996                                 struct vfs_handle_struct *handle,
1997                                 struct files_struct *fsp,
1998                                 uint32_t *dosmode)
1999 {
2000         NTSTATUS status;
2001
2002         status = SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle,
2003                                 fsp,
2004                                 dosmode);
2005
2006         do_log(SMB_VFS_OP_FGET_DOS_ATTRIBUTES,
2007                 NT_STATUS_IS_OK(status),
2008                 handle,
2009                 "%s",
2010                 fsp_str_do_log(fsp));
2011
2012         return status;
2013 }
2014
2015 static NTSTATUS smb_full_audit_set_dos_attributes(
2016                                 struct vfs_handle_struct *handle,
2017                                 const struct smb_filename *smb_fname,
2018                                 uint32_t dosmode)
2019 {
2020         NTSTATUS status;
2021
2022         status = SMB_VFS_NEXT_SET_DOS_ATTRIBUTES(handle,
2023                                 smb_fname,
2024                                 dosmode);
2025
2026         do_log(SMB_VFS_OP_SET_DOS_ATTRIBUTES,
2027                 NT_STATUS_IS_OK(status),
2028                 handle,
2029                 "%s",
2030                 smb_fname_str_do_log(smb_fname));
2031
2032         return status;
2033 }
2034
2035 static NTSTATUS smb_full_audit_fset_dos_attributes(
2036                                 struct vfs_handle_struct *handle,
2037                                 struct files_struct *fsp,
2038                                 uint32_t dosmode)
2039 {
2040         NTSTATUS status;
2041
2042         status = SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle,
2043                                 fsp,
2044                                 dosmode);
2045
2046         do_log(SMB_VFS_OP_FSET_DOS_ATTRIBUTES,
2047                 NT_STATUS_IS_OK(status),
2048                 handle,
2049                 "%s",
2050                 fsp_str_do_log(fsp));
2051
2052         return status;
2053 }
2054
2055 static NTSTATUS smb_full_audit_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
2056                                            uint32_t security_info,
2057                                            TALLOC_CTX *mem_ctx,
2058                                            struct security_descriptor **ppdesc)
2059 {
2060         NTSTATUS result;
2061
2062         result = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
2063                                           mem_ctx, ppdesc);
2064
2065         do_log(SMB_VFS_OP_FGET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2066                "%s", fsp_str_do_log(fsp));
2067
2068         return result;
2069 }
2070
2071 static NTSTATUS smb_full_audit_get_nt_acl(vfs_handle_struct *handle,
2072                                           const struct smb_filename *smb_fname,
2073                                           uint32_t security_info,
2074                                           TALLOC_CTX *mem_ctx,
2075                                           struct security_descriptor **ppdesc)
2076 {
2077         NTSTATUS result;
2078
2079         result = SMB_VFS_NEXT_GET_NT_ACL(handle, smb_fname, security_info,
2080                                          mem_ctx, ppdesc);
2081
2082         do_log(SMB_VFS_OP_GET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2083                "%s", smb_fname_str_do_log(smb_fname));
2084
2085         return result;
2086 }
2087
2088 static NTSTATUS smb_full_audit_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
2089                               uint32_t security_info_sent,
2090                               const struct security_descriptor *psd)
2091 {
2092         struct vfs_full_audit_private_data *pd;
2093         NTSTATUS result;
2094         char *sd = NULL;
2095
2096         SMB_VFS_HANDLE_GET_DATA(handle, pd,
2097                                 struct vfs_full_audit_private_data,
2098                                 return NT_STATUS_INTERNAL_ERROR);
2099
2100         if (pd->log_secdesc) {
2101                 sd = sddl_encode(talloc_tos(), psd, get_global_sam_sid());
2102         }
2103
2104         result = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
2105
2106         do_log(SMB_VFS_OP_FSET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2107                "%s [%s]", fsp_str_do_log(fsp), sd ? sd : "");
2108
2109         TALLOC_FREE(sd);
2110
2111         return result;
2112 }
2113
2114 static NTSTATUS smb_full_audit_audit_file(struct vfs_handle_struct *handle,
2115                                 struct smb_filename *file,
2116                                 struct security_acl *sacl,
2117                                 uint32_t access_requested,
2118                                 uint32_t access_denied)
2119 {
2120         NTSTATUS result;
2121
2122         result = SMB_VFS_NEXT_AUDIT_FILE(handle,
2123                                         file,
2124                                         sacl,
2125                                         access_requested,
2126                                         access_denied);
2127
2128         do_log(SMB_VFS_OP_AUDIT_FILE, NT_STATUS_IS_OK(result), handle,
2129                         "%s", smb_fname_str_do_log(file));
2130
2131         return result;
2132 }
2133
2134 static int smb_full_audit_chmod_acl(vfs_handle_struct *handle,
2135                                 const struct smb_filename *smb_fname,
2136                                 mode_t mode)
2137 {
2138         int result;
2139         
2140         result = SMB_VFS_NEXT_CHMOD_ACL(handle, smb_fname, mode);
2141
2142         do_log(SMB_VFS_OP_CHMOD_ACL, (result >= 0), handle,
2143                "%s|%o", smb_fname->base_name, mode);
2144
2145         return result;
2146 }
2147
2148 static int smb_full_audit_fchmod_acl(vfs_handle_struct *handle, files_struct *fsp,
2149                                      mode_t mode)
2150 {
2151         int result;
2152         
2153         result = SMB_VFS_NEXT_FCHMOD_ACL(handle, fsp, mode);
2154
2155         do_log(SMB_VFS_OP_FCHMOD_ACL, (result >= 0), handle,
2156                "%s|%o", fsp_str_do_log(fsp), mode);
2157
2158         return result;
2159 }
2160
2161 static SMB_ACL_T smb_full_audit_sys_acl_get_file(vfs_handle_struct *handle,
2162                                 const struct smb_filename *smb_fname,
2163                                 SMB_ACL_TYPE_T type,
2164                                 TALLOC_CTX *mem_ctx)
2165 {
2166         SMB_ACL_T result;
2167
2168         result = SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, smb_fname,
2169                                 type, mem_ctx);
2170
2171         do_log(SMB_VFS_OP_SYS_ACL_GET_FILE, (result != NULL), handle,
2172                "%s", smb_fname->base_name);
2173
2174         return result;
2175 }
2176
2177 static SMB_ACL_T smb_full_audit_sys_acl_get_fd(vfs_handle_struct *handle,
2178                                                files_struct *fsp, TALLOC_CTX *mem_ctx)
2179 {
2180         SMB_ACL_T result;
2181
2182         result = SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp, mem_ctx);
2183
2184         do_log(SMB_VFS_OP_SYS_ACL_GET_FD, (result != NULL), handle,
2185                "%s", fsp_str_do_log(fsp));
2186
2187         return result;
2188 }
2189
2190 static int smb_full_audit_sys_acl_blob_get_file(vfs_handle_struct *handle,
2191                                 const struct smb_filename *smb_fname,
2192                                 TALLOC_CTX *mem_ctx,
2193                                 char **blob_description,
2194                                 DATA_BLOB *blob)
2195 {
2196         int result;
2197
2198         result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FILE(handle, smb_fname,
2199                         mem_ctx, blob_description, blob);
2200
2201         do_log(SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE, (result >= 0), handle,
2202                "%s", smb_fname->base_name);
2203
2204         return result;
2205 }
2206
2207 static int smb_full_audit_sys_acl_blob_get_fd(vfs_handle_struct *handle,
2208                                               files_struct *fsp,
2209                                               TALLOC_CTX *mem_ctx,
2210                                               char **blob_description,
2211                                               DATA_BLOB *blob)
2212 {
2213         int result;
2214
2215         result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle, fsp, mem_ctx, blob_description, blob);
2216
2217         do_log(SMB_VFS_OP_SYS_ACL_BLOB_GET_FD, (result >= 0), handle,
2218                "%s", fsp_str_do_log(fsp));
2219
2220         return result;
2221 }
2222
2223 static int smb_full_audit_sys_acl_set_file(vfs_handle_struct *handle,
2224                                 const struct smb_filename *smb_fname,
2225                                 SMB_ACL_TYPE_T acltype,
2226                                 SMB_ACL_T theacl)
2227 {
2228         int result;
2229
2230         result = SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, smb_fname, acltype,
2231                                                theacl);
2232
2233         do_log(SMB_VFS_OP_SYS_ACL_SET_FILE, (result >= 0), handle,
2234                "%s", smb_fname->base_name);
2235
2236         return result;
2237 }
2238
2239 static int smb_full_audit_sys_acl_set_fd(vfs_handle_struct *handle, files_struct *fsp,
2240                                 SMB_ACL_T theacl)
2241 {
2242         int result;
2243
2244         result = SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, theacl);
2245
2246         do_log(SMB_VFS_OP_SYS_ACL_SET_FD, (result >= 0), handle,
2247                "%s", fsp_str_do_log(fsp));
2248
2249         return result;
2250 }
2251
2252 static int smb_full_audit_sys_acl_delete_def_file(vfs_handle_struct *handle,
2253                                 const struct smb_filename *smb_fname)
2254 {
2255         int result;
2256
2257         result = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, smb_fname);
2258
2259         do_log(SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE, (result >= 0), handle,
2260                "%s", smb_fname->base_name);
2261
2262         return result;
2263 }
2264
2265 static ssize_t smb_full_audit_getxattr(struct vfs_handle_struct *handle,
2266                               const struct smb_filename *smb_fname,
2267                               const char *name, void *value, size_t size)
2268 {
2269         ssize_t result;
2270
2271         result = SMB_VFS_NEXT_GETXATTR(handle, smb_fname, name, value, size);
2272
2273         do_log(SMB_VFS_OP_GETXATTR, (result >= 0), handle,
2274                "%s|%s", smb_fname->base_name, name);
2275
2276         return result;
2277 }
2278
2279 static ssize_t smb_full_audit_fgetxattr(struct vfs_handle_struct *handle,
2280                                struct files_struct *fsp,
2281                                const char *name, void *value, size_t size)
2282 {
2283         ssize_t result;
2284
2285         result = SMB_VFS_NEXT_FGETXATTR(handle, fsp, name, value, size);
2286
2287         do_log(SMB_VFS_OP_FGETXATTR, (result >= 0), handle,
2288                "%s|%s", fsp_str_do_log(fsp), name);
2289
2290         return result;
2291 }
2292
2293 static ssize_t smb_full_audit_listxattr(struct vfs_handle_struct *handle,
2294                                 const struct smb_filename *smb_fname,
2295                                 char *list,
2296                                 size_t size)
2297 {
2298         ssize_t result;
2299
2300         result = SMB_VFS_NEXT_LISTXATTR(handle, smb_fname, list, size);
2301
2302         do_log(SMB_VFS_OP_LISTXATTR, (result >= 0), handle, "%s",
2303                         smb_fname->base_name);
2304
2305         return result;
2306 }
2307
2308 static ssize_t smb_full_audit_flistxattr(struct vfs_handle_struct *handle,
2309                                 struct files_struct *fsp, char *list,
2310                                 size_t size)
2311 {
2312         ssize_t result;
2313
2314         result = SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
2315
2316         do_log(SMB_VFS_OP_FLISTXATTR, (result >= 0), handle,
2317                "%s", fsp_str_do_log(fsp));
2318
2319         return result;
2320 }
2321
2322 static int smb_full_audit_removexattr(struct vfs_handle_struct *handle,
2323                              const struct smb_filename *smb_fname,
2324                              const char *name)
2325 {
2326         int result;
2327
2328         result = SMB_VFS_NEXT_REMOVEXATTR(handle, smb_fname, name);
2329
2330         do_log(SMB_VFS_OP_REMOVEXATTR, (result >= 0), handle,
2331                "%s|%s", smb_fname->base_name, name);
2332
2333         return result;
2334 }
2335
2336 static int smb_full_audit_fremovexattr(struct vfs_handle_struct *handle,
2337                               struct files_struct *fsp,
2338                               const char *name)
2339 {
2340         int result;
2341
2342         result = SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, name);
2343
2344         do_log(SMB_VFS_OP_FREMOVEXATTR, (result >= 0), handle,
2345                "%s|%s", fsp_str_do_log(fsp), name);
2346
2347         return result;
2348 }
2349
2350 static int smb_full_audit_setxattr(struct vfs_handle_struct *handle,
2351                           const struct smb_filename *smb_fname,
2352                           const char *name, const void *value, size_t size,
2353                           int flags)
2354 {
2355         int result;
2356
2357         result = SMB_VFS_NEXT_SETXATTR(handle, smb_fname, name, value, size,
2358                                        flags);
2359
2360         do_log(SMB_VFS_OP_SETXATTR, (result >= 0), handle,
2361                "%s|%s", smb_fname->base_name, name);
2362
2363         return result;
2364 }
2365
2366 static int smb_full_audit_fsetxattr(struct vfs_handle_struct *handle,
2367                            struct files_struct *fsp, const char *name,
2368                            const void *value, size_t size, int flags)
2369 {
2370         int result;
2371
2372         result = SMB_VFS_NEXT_FSETXATTR(handle, fsp, name, value, size, flags);
2373
2374         do_log(SMB_VFS_OP_FSETXATTR, (result >= 0), handle,
2375                "%s|%s", fsp_str_do_log(fsp), name);
2376
2377         return result;
2378 }
2379
2380 static bool smb_full_audit_aio_force(struct vfs_handle_struct *handle,
2381                                      struct files_struct *fsp)
2382 {
2383         bool result;
2384
2385         result = SMB_VFS_NEXT_AIO_FORCE(handle, fsp);
2386         do_log(SMB_VFS_OP_AIO_FORCE, result, handle,
2387                 "%s", fsp_str_do_log(fsp));
2388
2389         return result;
2390 }
2391
2392 static NTSTATUS smb_full_audit_durable_cookie(struct vfs_handle_struct *handle,
2393                                 struct files_struct *fsp,
2394                                 TALLOC_CTX *mem_ctx,
2395                                 DATA_BLOB *cookie)
2396 {
2397         NTSTATUS result;
2398
2399         result = SMB_VFS_NEXT_DURABLE_COOKIE(handle,
2400                                         fsp,
2401                                         mem_ctx,
2402                                         cookie);
2403
2404         do_log(SMB_VFS_OP_DURABLE_COOKIE, NT_STATUS_IS_OK(result), handle,
2405                         "%s", fsp_str_do_log(fsp));
2406
2407         return result;
2408 }
2409
2410 static NTSTATUS smb_full_audit_durable_disconnect(
2411                                 struct vfs_handle_struct *handle,
2412                                 struct files_struct *fsp,
2413                                 const DATA_BLOB old_cookie,
2414                                 TALLOC_CTX *mem_ctx,
2415                                 DATA_BLOB *new_cookie)
2416 {
2417         NTSTATUS result;
2418
2419         result = SMB_VFS_NEXT_DURABLE_DISCONNECT(handle,
2420                                         fsp,
2421                                         old_cookie,
2422                                         mem_ctx,
2423                                         new_cookie);
2424
2425         do_log(SMB_VFS_OP_DURABLE_DISCONNECT, NT_STATUS_IS_OK(result), handle,
2426                         "%s", fsp_str_do_log(fsp));
2427
2428         return result;
2429 }
2430
2431 static NTSTATUS smb_full_audit_durable_reconnect(
2432                                 struct vfs_handle_struct *handle,
2433                                 struct smb_request *smb1req,
2434                                 struct smbXsrv_open *op,
2435                                 const DATA_BLOB old_cookie,
2436                                 TALLOC_CTX *mem_ctx,
2437                                 struct files_struct **fsp,
2438                                 DATA_BLOB *new_cookie)
2439 {
2440         NTSTATUS result;
2441
2442         result = SMB_VFS_NEXT_DURABLE_RECONNECT(handle,
2443                                         smb1req,
2444                                         op,
2445                                         old_cookie,
2446                                         mem_ctx,
2447                                         fsp,
2448                                         new_cookie);
2449
2450         do_log(SMB_VFS_OP_DURABLE_RECONNECT,
2451                         NT_STATUS_IS_OK(result),
2452                         handle,
2453                         "");
2454
2455         return result;
2456 }
2457
2458 static struct vfs_fn_pointers vfs_full_audit_fns = {
2459
2460         /* Disk operations */
2461
2462         .connect_fn = smb_full_audit_connect,
2463         .disconnect_fn = smb_full_audit_disconnect,
2464         .disk_free_fn = smb_full_audit_disk_free,
2465         .get_quota_fn = smb_full_audit_get_quota,
2466         .set_quota_fn = smb_full_audit_set_quota,
2467         .get_shadow_copy_data_fn = smb_full_audit_get_shadow_copy_data,
2468         .statvfs_fn = smb_full_audit_statvfs,
2469         .fs_capabilities_fn = smb_full_audit_fs_capabilities,
2470         .get_dfs_referrals_fn = smb_full_audit_get_dfs_referrals,
2471         .opendir_fn = smb_full_audit_opendir,
2472         .fdopendir_fn = smb_full_audit_fdopendir,
2473         .readdir_fn = smb_full_audit_readdir,
2474         .seekdir_fn = smb_full_audit_seekdir,
2475         .telldir_fn = smb_full_audit_telldir,
2476         .rewind_dir_fn = smb_full_audit_rewinddir,
2477         .mkdir_fn = smb_full_audit_mkdir,
2478         .rmdir_fn = smb_full_audit_rmdir,
2479         .closedir_fn = smb_full_audit_closedir,
2480         .init_search_op_fn = smb_full_audit_init_search_op,
2481         .open_fn = smb_full_audit_open,
2482         .create_file_fn = smb_full_audit_create_file,
2483         .close_fn = smb_full_audit_close,
2484         .read_fn = smb_full_audit_read,
2485         .pread_fn = smb_full_audit_pread,
2486         .pread_send_fn = smb_full_audit_pread_send,
2487         .pread_recv_fn = smb_full_audit_pread_recv,
2488         .write_fn = smb_full_audit_write,
2489         .pwrite_fn = smb_full_audit_pwrite,
2490         .pwrite_send_fn = smb_full_audit_pwrite_send,
2491         .pwrite_recv_fn = smb_full_audit_pwrite_recv,
2492         .lseek_fn = smb_full_audit_lseek,
2493         .sendfile_fn = smb_full_audit_sendfile,
2494         .recvfile_fn = smb_full_audit_recvfile,
2495         .rename_fn = smb_full_audit_rename,
2496         .fsync_fn = smb_full_audit_fsync,
2497         .fsync_send_fn = smb_full_audit_fsync_send,
2498         .fsync_recv_fn = smb_full_audit_fsync_recv,
2499         .stat_fn = smb_full_audit_stat,
2500         .fstat_fn = smb_full_audit_fstat,
2501         .lstat_fn = smb_full_audit_lstat,
2502         .get_alloc_size_fn = smb_full_audit_get_alloc_size,
2503         .unlink_fn = smb_full_audit_unlink,
2504         .chmod_fn = smb_full_audit_chmod,
2505         .fchmod_fn = smb_full_audit_fchmod,
2506         .chown_fn = smb_full_audit_chown,
2507         .fchown_fn = smb_full_audit_fchown,
2508         .lchown_fn = smb_full_audit_lchown,
2509         .chdir_fn = smb_full_audit_chdir,
2510         .getwd_fn = smb_full_audit_getwd,
2511         .ntimes_fn = smb_full_audit_ntimes,
2512         .ftruncate_fn = smb_full_audit_ftruncate,
2513         .fallocate_fn = smb_full_audit_fallocate,
2514         .lock_fn = smb_full_audit_lock,
2515         .kernel_flock_fn = smb_full_audit_kernel_flock,
2516         .linux_setlease_fn = smb_full_audit_linux_setlease,
2517         .getlock_fn = smb_full_audit_getlock,
2518         .symlink_fn = smb_full_audit_symlink,
2519         .readlink_fn = smb_full_audit_readlink,
2520         .link_fn = smb_full_audit_link,
2521         .mknod_fn = smb_full_audit_mknod,
2522         .realpath_fn = smb_full_audit_realpath,
2523         .chflags_fn = smb_full_audit_chflags,
2524         .file_id_create_fn = smb_full_audit_file_id_create,
2525         .copy_chunk_send_fn = smb_full_audit_copy_chunk_send,
2526         .copy_chunk_recv_fn = smb_full_audit_copy_chunk_recv,
2527         .get_compression_fn = smb_full_audit_get_compression,
2528         .set_compression_fn = smb_full_audit_set_compression,
2529         .snap_check_path_fn =  smb_full_audit_snap_check_path,
2530         .snap_create_fn = smb_full_audit_snap_create,
2531         .snap_delete_fn = smb_full_audit_snap_delete,
2532         .streaminfo_fn = smb_full_audit_streaminfo,
2533         .get_real_filename_fn = smb_full_audit_get_real_filename,
2534         .connectpath_fn = smb_full_audit_connectpath,
2535         .brl_lock_windows_fn = smb_full_audit_brl_lock_windows,
2536         .brl_unlock_windows_fn = smb_full_audit_brl_unlock_windows,
2537         .brl_cancel_windows_fn = smb_full_audit_brl_cancel_windows,
2538         .strict_lock_fn = smb_full_audit_strict_lock,
2539         .strict_unlock_fn = smb_full_audit_strict_unlock,
2540         .translate_name_fn = smb_full_audit_translate_name,
2541         .fsctl_fn = smb_full_audit_fsctl,
2542         .get_dos_attributes_fn = smb_full_audit_get_dos_attributes,
2543         .fget_dos_attributes_fn = smb_full_audit_fget_dos_attributes,
2544         .set_dos_attributes_fn = smb_full_audit_set_dos_attributes,
2545         .fset_dos_attributes_fn = smb_full_audit_fset_dos_attributes,
2546         .fget_nt_acl_fn = smb_full_audit_fget_nt_acl,
2547         .get_nt_acl_fn = smb_full_audit_get_nt_acl,
2548         .fset_nt_acl_fn = smb_full_audit_fset_nt_acl,
2549         .audit_file_fn = smb_full_audit_audit_file,
2550         .chmod_acl_fn = smb_full_audit_chmod_acl,
2551         .fchmod_acl_fn = smb_full_audit_fchmod_acl,
2552         .sys_acl_get_file_fn = smb_full_audit_sys_acl_get_file,
2553         .sys_acl_get_fd_fn = smb_full_audit_sys_acl_get_fd,
2554         .sys_acl_blob_get_file_fn = smb_full_audit_sys_acl_blob_get_file,
2555         .sys_acl_blob_get_fd_fn = smb_full_audit_sys_acl_blob_get_fd,
2556         .sys_acl_set_file_fn = smb_full_audit_sys_acl_set_file,
2557         .sys_acl_set_fd_fn = smb_full_audit_sys_acl_set_fd,
2558         .sys_acl_delete_def_file_fn = smb_full_audit_sys_acl_delete_def_file,
2559         .getxattr_fn = smb_full_audit_getxattr,
2560         .fgetxattr_fn = smb_full_audit_fgetxattr,
2561         .listxattr_fn = smb_full_audit_listxattr,
2562         .flistxattr_fn = smb_full_audit_flistxattr,
2563         .removexattr_fn = smb_full_audit_removexattr,
2564         .fremovexattr_fn = smb_full_audit_fremovexattr,
2565         .setxattr_fn = smb_full_audit_setxattr,
2566         .fsetxattr_fn = smb_full_audit_fsetxattr,
2567         .aio_force_fn = smb_full_audit_aio_force,
2568         .durable_cookie_fn = smb_full_audit_durable_cookie,
2569         .durable_disconnect_fn = smb_full_audit_durable_disconnect,
2570         .durable_reconnect_fn = smb_full_audit_durable_reconnect,
2571         .readdir_attr_fn = smb_full_audit_readdir_attr
2572
2573 };
2574
2575 static_decl_vfs;
2576 NTSTATUS vfs_full_audit_init(TALLOC_CTX *ctx)
2577 {
2578         NTSTATUS ret;
2579
2580         smb_vfs_assert_all_fns(&vfs_full_audit_fns, "full_audit");
2581
2582         ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "full_audit",
2583                                &vfs_full_audit_fns);
2584
2585         if (!NT_STATUS_IS_OK(ret))
2586                 return ret;
2587
2588         vfs_full_audit_debug_level = debug_add_class("full_audit");
2589         if (vfs_full_audit_debug_level == -1) {
2590                 vfs_full_audit_debug_level = DBGC_VFS;
2591                 DEBUG(0, ("vfs_full_audit: Couldn't register custom debugging "
2592                           "class!\n"));
2593         } else {
2594                 DEBUG(10, ("vfs_full_audit: Debug class number of "
2595                            "'full_audit': %d\n", vfs_full_audit_debug_level));
2596         }
2597         
2598         return ret;
2599 }