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