s3-vfs: async fsync
[kai/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
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         return;
563 }
564
565 /**
566  * Return a string using the do_log_ctx()
567  */
568 static const char *smb_fname_str_do_log(const struct smb_filename *smb_fname)
569 {
570         char *fname = NULL;
571         NTSTATUS status;
572
573         if (smb_fname == NULL) {
574                 return "";
575         }
576         status = get_full_smb_filename(do_log_ctx(), smb_fname, &fname);
577         if (!NT_STATUS_IS_OK(status)) {
578                 return "";
579         }
580         return fname;
581 }
582
583 /**
584  * Return an fsp debug string using the do_log_ctx()
585  */
586 static const char *fsp_str_do_log(const struct files_struct *fsp)
587 {
588         return smb_fname_str_do_log(fsp->fsp_name);
589 }
590
591 /* Implementation of vfs_ops.  Pass everything on to the default
592    operation but log event first. */
593
594 static int smb_full_audit_connect(vfs_handle_struct *handle,
595                          const char *svc, const char *user)
596 {
597         int result;
598         struct vfs_full_audit_private_data *pd = NULL;
599
600         result = SMB_VFS_NEXT_CONNECT(handle, svc, user);
601         if (result < 0) {
602                 return result;
603         }
604
605         pd = talloc_zero(handle, struct vfs_full_audit_private_data);
606         if (!pd) {
607                 SMB_VFS_NEXT_DISCONNECT(handle);
608                 return -1;
609         }
610
611 #ifdef WITH_SYSLOG
612         openlog("smbd_audit", 0, audit_syslog_facility(handle));
613 #endif
614
615         pd->success_ops = init_bitmap(
616                 pd, lp_parm_string_list(SNUM(handle->conn), "full_audit",
617                                         "success", NULL));
618         pd->failure_ops = init_bitmap(
619                 pd, lp_parm_string_list(SNUM(handle->conn), "full_audit",
620                                         "failure", NULL));
621
622         /* Store the private data. */
623         SMB_VFS_HANDLE_SET_DATA(handle, pd, NULL,
624                                 struct vfs_full_audit_private_data, return -1);
625
626         do_log(SMB_VFS_OP_CONNECT, True, handle,
627                "%s", svc);
628
629         return 0;
630 }
631
632 static void smb_full_audit_disconnect(vfs_handle_struct *handle)
633 {
634         SMB_VFS_NEXT_DISCONNECT(handle);
635
636         do_log(SMB_VFS_OP_DISCONNECT, True, handle,
637                "%s", lp_servicename(talloc_tos(), SNUM(handle->conn)));
638
639         /* The bitmaps will be disconnected when the private
640            data is deleted. */
641
642         return;
643 }
644
645 static uint64_t smb_full_audit_disk_free(vfs_handle_struct *handle,
646                                     const char *path,
647                                     bool small_query, uint64_t *bsize, 
648                                     uint64_t *dfree, uint64_t *dsize)
649 {
650         uint64_t result;
651
652         result = SMB_VFS_NEXT_DISK_FREE(handle, path, small_query, bsize,
653                                         dfree, dsize);
654
655         /* Don't have a reasonable notion of failure here */
656
657         do_log(SMB_VFS_OP_DISK_FREE, True, handle, "%s", path);
658
659         return result;
660 }
661
662 static int smb_full_audit_get_quota(struct vfs_handle_struct *handle,
663                            enum SMB_QUOTA_TYPE qtype, unid_t id,
664                            SMB_DISK_QUOTA *qt)
665 {
666         int result;
667
668         result = SMB_VFS_NEXT_GET_QUOTA(handle, qtype, id, qt);
669
670         do_log(SMB_VFS_OP_GET_QUOTA, (result >= 0), handle, "");
671
672         return result;
673 }
674
675         
676 static int smb_full_audit_set_quota(struct vfs_handle_struct *handle,
677                            enum SMB_QUOTA_TYPE qtype, unid_t id,
678                            SMB_DISK_QUOTA *qt)
679 {
680         int result;
681
682         result = SMB_VFS_NEXT_SET_QUOTA(handle, qtype, id, qt);
683
684         do_log(SMB_VFS_OP_SET_QUOTA, (result >= 0), handle, "");
685
686         return result;
687 }
688
689 static int smb_full_audit_get_shadow_copy_data(struct vfs_handle_struct *handle,
690                                 struct files_struct *fsp,
691                                 struct shadow_copy_data *shadow_copy_data,
692                                 bool labels)
693 {
694         int result;
695
696         result = SMB_VFS_NEXT_GET_SHADOW_COPY_DATA(handle, fsp, shadow_copy_data, labels);
697
698         do_log(SMB_VFS_OP_GET_SHADOW_COPY_DATA, (result >= 0), handle, "");
699
700         return result;
701 }
702
703 static int smb_full_audit_statvfs(struct vfs_handle_struct *handle,
704                                 const char *path,
705                                 struct vfs_statvfs_struct *statbuf)
706 {
707         int result;
708
709         result = SMB_VFS_NEXT_STATVFS(handle, path, statbuf);
710
711         do_log(SMB_VFS_OP_STATVFS, (result >= 0), handle, "");
712
713         return result;
714 }
715
716 static uint32_t smb_full_audit_fs_capabilities(struct vfs_handle_struct *handle, enum timestamp_set_resolution *p_ts_res)
717 {
718         int result;
719
720         result = SMB_VFS_NEXT_FS_CAPABILITIES(handle, p_ts_res);
721
722         do_log(SMB_VFS_OP_FS_CAPABILITIES, true, handle, "");
723
724         return result;
725 }
726
727 static DIR *smb_full_audit_opendir(vfs_handle_struct *handle,
728                           const char *fname, const char *mask, uint32 attr)
729 {
730         DIR *result;
731
732         result = SMB_VFS_NEXT_OPENDIR(handle, fname, mask, attr);
733
734         do_log(SMB_VFS_OP_OPENDIR, (result != NULL), handle, "%s", fname);
735
736         return result;
737 }
738
739 static DIR *smb_full_audit_fdopendir(vfs_handle_struct *handle,
740                           files_struct *fsp, const char *mask, uint32 attr)
741 {
742         DIR *result;
743
744         result = SMB_VFS_NEXT_FDOPENDIR(handle, fsp, mask, attr);
745
746         do_log(SMB_VFS_OP_FDOPENDIR, (result != NULL), handle, "%s",
747                         fsp_str_do_log(fsp));
748
749         return result;
750 }
751
752 static struct dirent *smb_full_audit_readdir(vfs_handle_struct *handle,
753                                     DIR *dirp, SMB_STRUCT_STAT *sbuf)
754 {
755         struct dirent *result;
756
757         result = SMB_VFS_NEXT_READDIR(handle, dirp, sbuf);
758
759         /* This operation has no reasonable error condition
760          * (End of dir is also failure), so always succeed.
761          */
762         do_log(SMB_VFS_OP_READDIR, True, handle, "");
763
764         return result;
765 }
766
767 static void smb_full_audit_seekdir(vfs_handle_struct *handle,
768                         DIR *dirp, long offset)
769 {
770         SMB_VFS_NEXT_SEEKDIR(handle, dirp, offset);
771
772         do_log(SMB_VFS_OP_SEEKDIR, True, handle, "");
773         return;
774 }
775
776 static long smb_full_audit_telldir(vfs_handle_struct *handle,
777                         DIR *dirp)
778 {
779         long result;
780
781         result = SMB_VFS_NEXT_TELLDIR(handle, dirp);
782
783         do_log(SMB_VFS_OP_TELLDIR, True, handle, "");
784
785         return result;
786 }
787
788 static void smb_full_audit_rewinddir(vfs_handle_struct *handle,
789                         DIR *dirp)
790 {
791         SMB_VFS_NEXT_REWINDDIR(handle, dirp);
792
793         do_log(SMB_VFS_OP_REWINDDIR, True, handle, "");
794         return;
795 }
796
797 static int smb_full_audit_mkdir(vfs_handle_struct *handle,
798                        const char *path, mode_t mode)
799 {
800         int result;
801         
802         result = SMB_VFS_NEXT_MKDIR(handle, path, mode);
803         
804         do_log(SMB_VFS_OP_MKDIR, (result >= 0), handle, "%s", path);
805
806         return result;
807 }
808
809 static int smb_full_audit_rmdir(vfs_handle_struct *handle,
810                        const char *path)
811 {
812         int result;
813         
814         result = SMB_VFS_NEXT_RMDIR(handle, path);
815
816         do_log(SMB_VFS_OP_RMDIR, (result >= 0), handle, "%s", path);
817
818         return result;
819 }
820
821 static int smb_full_audit_closedir(vfs_handle_struct *handle,
822                           DIR *dirp)
823 {
824         int result;
825
826         result = SMB_VFS_NEXT_CLOSEDIR(handle, dirp);
827         
828         do_log(SMB_VFS_OP_CLOSEDIR, (result >= 0), handle, "");
829
830         return result;
831 }
832
833 static void smb_full_audit_init_search_op(vfs_handle_struct *handle,
834                         DIR *dirp)
835 {
836         SMB_VFS_NEXT_INIT_SEARCH_OP(handle, dirp);
837
838         do_log(SMB_VFS_OP_INIT_SEARCH_OP, True, handle, "");
839         return;
840 }
841
842 static int smb_full_audit_open(vfs_handle_struct *handle,
843                                struct smb_filename *smb_fname,
844                                files_struct *fsp, int flags, mode_t mode)
845 {
846         int result;
847         
848         result = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
849
850         do_log(SMB_VFS_OP_OPEN, (result >= 0), handle, "%s|%s",
851                ((flags & O_WRONLY) || (flags & O_RDWR))?"w":"r",
852                smb_fname_str_do_log(smb_fname));
853
854         return result;
855 }
856
857 static NTSTATUS smb_full_audit_create_file(vfs_handle_struct *handle,
858                                       struct smb_request *req,
859                                       uint16_t root_dir_fid,
860                                       struct smb_filename *smb_fname,
861                                       uint32_t access_mask,
862                                       uint32_t share_access,
863                                       uint32_t create_disposition,
864                                       uint32_t create_options,
865                                       uint32_t file_attributes,
866                                       uint32_t oplock_request,
867                                       uint64_t allocation_size,
868                                       uint32_t private_flags,
869                                       struct security_descriptor *sd,
870                                       struct ea_list *ea_list,
871                                       files_struct **result_fsp,
872                                       int *pinfo)
873 {
874         NTSTATUS result;
875         const char* str_create_disposition;
876
877         switch (create_disposition) {
878         case FILE_SUPERSEDE:
879                 str_create_disposition = "supersede";
880                 break;
881         case FILE_OVERWRITE_IF:
882                 str_create_disposition = "overwrite_if";
883                 break;
884         case FILE_OPEN:
885                 str_create_disposition = "open";
886                 break;
887         case FILE_OVERWRITE:
888                 str_create_disposition = "overwrite";
889                 break;
890         case FILE_CREATE:
891                 str_create_disposition = "create";
892                 break;
893         case FILE_OPEN_IF:
894                 str_create_disposition = "open_if";
895                 break;
896         default:
897                 str_create_disposition = "unknown";
898         }
899
900         result = SMB_VFS_NEXT_CREATE_FILE(
901                 handle,                                 /* handle */
902                 req,                                    /* req */
903                 root_dir_fid,                           /* root_dir_fid */
904                 smb_fname,                              /* fname */
905                 access_mask,                            /* access_mask */
906                 share_access,                           /* share_access */
907                 create_disposition,                     /* create_disposition*/
908                 create_options,                         /* create_options */
909                 file_attributes,                        /* file_attributes */
910                 oplock_request,                         /* oplock_request */
911                 allocation_size,                        /* allocation_size */
912                 private_flags,
913                 sd,                                     /* sd */
914                 ea_list,                                /* ea_list */
915                 result_fsp,                             /* result */
916                 pinfo);                                 /* pinfo */
917
918         do_log(SMB_VFS_OP_CREATE_FILE, (NT_STATUS_IS_OK(result)), handle,
919                "0x%x|%s|%s|%s", access_mask,
920                create_options & FILE_DIRECTORY_FILE ? "dir" : "file",
921                str_create_disposition, smb_fname_str_do_log(smb_fname));
922
923         return result;
924 }
925
926 static int smb_full_audit_close(vfs_handle_struct *handle, files_struct *fsp)
927 {
928         int result;
929         
930         result = SMB_VFS_NEXT_CLOSE(handle, fsp);
931
932         do_log(SMB_VFS_OP_CLOSE, (result >= 0), handle, "%s",
933                fsp_str_do_log(fsp));
934
935         return result;
936 }
937
938 static ssize_t smb_full_audit_read(vfs_handle_struct *handle, files_struct *fsp,
939                           void *data, size_t n)
940 {
941         ssize_t result;
942
943         result = SMB_VFS_NEXT_READ(handle, fsp, data, n);
944
945         do_log(SMB_VFS_OP_READ, (result >= 0), handle, "%s",
946                fsp_str_do_log(fsp));
947
948         return result;
949 }
950
951 static ssize_t smb_full_audit_pread(vfs_handle_struct *handle, files_struct *fsp,
952                            void *data, size_t n, off_t offset)
953 {
954         ssize_t result;
955
956         result = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
957
958         do_log(SMB_VFS_OP_PREAD, (result >= 0), handle, "%s",
959                fsp_str_do_log(fsp));
960
961         return result;
962 }
963
964 struct smb_full_audit_pread_state {
965         vfs_handle_struct *handle;
966         files_struct *fsp;
967         ssize_t ret;
968         int err;
969 };
970
971 static void smb_full_audit_pread_done(struct tevent_req *subreq);
972
973 static struct tevent_req *smb_full_audit_pread_send(
974         struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
975         struct tevent_context *ev, struct files_struct *fsp,
976         void *data, size_t n, off_t offset)
977 {
978         struct tevent_req *req, *subreq;
979         struct smb_full_audit_pread_state *state;
980
981         req = tevent_req_create(mem_ctx, &state,
982                                 struct smb_full_audit_pread_state);
983         if (req == NULL) {
984                 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
985                        fsp_str_do_log(fsp));
986                 return NULL;
987         }
988         state->handle = handle;
989         state->fsp = fsp;
990
991         subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
992                                          n, offset);
993         if (tevent_req_nomem(subreq, req)) {
994                 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
995                        fsp_str_do_log(fsp));
996                 return tevent_req_post(req, ev);
997         }
998         tevent_req_set_callback(subreq, smb_full_audit_pread_done, req);
999
1000         do_log(SMB_VFS_OP_PREAD_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1001         return req;
1002 }
1003
1004 static void smb_full_audit_pread_done(struct tevent_req *subreq)
1005 {
1006         struct tevent_req *req = tevent_req_callback_data(
1007                 subreq, struct tevent_req);
1008         struct smb_full_audit_pread_state *state = tevent_req_data(
1009                 req, struct smb_full_audit_pread_state);
1010
1011         state->ret = SMB_VFS_PREAD_RECV(subreq, &state->err);
1012         TALLOC_FREE(subreq);
1013         tevent_req_done(req);
1014 }
1015
1016 static ssize_t smb_full_audit_pread_recv(struct tevent_req *req, int *err)
1017 {
1018         struct smb_full_audit_pread_state *state = tevent_req_data(
1019                 req, struct smb_full_audit_pread_state);
1020
1021         if (tevent_req_is_unix_error(req, err)) {
1022                 do_log(SMB_VFS_OP_PREAD_RECV, false, state->handle, "%s",
1023                        fsp_str_do_log(state->fsp));
1024                 return -1;
1025         }
1026
1027         do_log(SMB_VFS_OP_PREAD_RECV, (state->ret >= 0), state->handle, "%s",
1028                fsp_str_do_log(state->fsp));
1029
1030         *err = state->err;
1031         return state->ret;
1032 }
1033
1034 static ssize_t smb_full_audit_write(vfs_handle_struct *handle, files_struct *fsp,
1035                            const void *data, size_t n)
1036 {
1037         ssize_t result;
1038
1039         result = SMB_VFS_NEXT_WRITE(handle, fsp, data, n);
1040
1041         do_log(SMB_VFS_OP_WRITE, (result >= 0), handle, "%s",
1042                fsp_str_do_log(fsp));
1043
1044         return result;
1045 }
1046
1047 static ssize_t smb_full_audit_pwrite(vfs_handle_struct *handle, files_struct *fsp,
1048                             const void *data, size_t n,
1049                             off_t offset)
1050 {
1051         ssize_t result;
1052
1053         result = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
1054
1055         do_log(SMB_VFS_OP_PWRITE, (result >= 0), handle, "%s",
1056                fsp_str_do_log(fsp));
1057
1058         return result;
1059 }
1060
1061 struct smb_full_audit_pwrite_state {
1062         vfs_handle_struct *handle;
1063         files_struct *fsp;
1064         ssize_t ret;
1065         int err;
1066 };
1067
1068 static void smb_full_audit_pwrite_done(struct tevent_req *subreq);
1069
1070 static struct tevent_req *smb_full_audit_pwrite_send(
1071         struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1072         struct tevent_context *ev, struct files_struct *fsp,
1073         const void *data, size_t n, off_t offset)
1074 {
1075         struct tevent_req *req, *subreq;
1076         struct smb_full_audit_pwrite_state *state;
1077
1078         req = tevent_req_create(mem_ctx, &state,
1079                                 struct smb_full_audit_pwrite_state);
1080         if (req == NULL) {
1081                 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1082                        fsp_str_do_log(fsp));
1083                 return NULL;
1084         }
1085         state->handle = handle;
1086         state->fsp = fsp;
1087
1088         subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
1089                                          n, offset);
1090         if (tevent_req_nomem(subreq, req)) {
1091                 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1092                        fsp_str_do_log(fsp));
1093                 return tevent_req_post(req, ev);
1094         }
1095         tevent_req_set_callback(subreq, smb_full_audit_pwrite_done, req);
1096
1097         do_log(SMB_VFS_OP_PWRITE_SEND, true, handle, "%s",
1098                fsp_str_do_log(fsp));
1099         return req;
1100 }
1101
1102 static void smb_full_audit_pwrite_done(struct tevent_req *subreq)
1103 {
1104         struct tevent_req *req = tevent_req_callback_data(
1105                 subreq, struct tevent_req);
1106         struct smb_full_audit_pwrite_state *state = tevent_req_data(
1107                 req, struct smb_full_audit_pwrite_state);
1108
1109         state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->err);
1110         TALLOC_FREE(subreq);
1111         tevent_req_done(req);
1112 }
1113
1114 static ssize_t smb_full_audit_pwrite_recv(struct tevent_req *req, int *err)
1115 {
1116         struct smb_full_audit_pwrite_state *state = tevent_req_data(
1117                 req, struct smb_full_audit_pwrite_state);
1118
1119         if (tevent_req_is_unix_error(req, err)) {
1120                 do_log(SMB_VFS_OP_PWRITE_RECV, false, state->handle, "%s",
1121                        fsp_str_do_log(state->fsp));
1122                 return -1;
1123         }
1124
1125         do_log(SMB_VFS_OP_PWRITE_RECV, (state->ret >= 0), state->handle, "%s",
1126                fsp_str_do_log(state->fsp));
1127
1128         *err = state->err;
1129         return state->ret;
1130 }
1131
1132 static off_t smb_full_audit_lseek(vfs_handle_struct *handle, files_struct *fsp,
1133                              off_t offset, int whence)
1134 {
1135         ssize_t result;
1136
1137         result = SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence);
1138
1139         do_log(SMB_VFS_OP_LSEEK, (result != (ssize_t)-1), handle,
1140                "%s", fsp_str_do_log(fsp));
1141
1142         return result;
1143 }
1144
1145 static ssize_t smb_full_audit_sendfile(vfs_handle_struct *handle, int tofd,
1146                               files_struct *fromfsp,
1147                               const DATA_BLOB *hdr, off_t offset,
1148                               size_t n)
1149 {
1150         ssize_t result;
1151
1152         result = SMB_VFS_NEXT_SENDFILE(handle, tofd, fromfsp, hdr, offset, n);
1153
1154         do_log(SMB_VFS_OP_SENDFILE, (result >= 0), handle,
1155                "%s", fsp_str_do_log(fromfsp));
1156
1157         return result;
1158 }
1159
1160 static ssize_t smb_full_audit_recvfile(vfs_handle_struct *handle, int fromfd,
1161                       files_struct *tofsp,
1162                               off_t offset,
1163                               size_t n)
1164 {
1165         ssize_t result;
1166
1167         result = SMB_VFS_NEXT_RECVFILE(handle, fromfd, tofsp, offset, n);
1168
1169         do_log(SMB_VFS_OP_RECVFILE, (result >= 0), handle,
1170                "%s", fsp_str_do_log(tofsp));
1171
1172         return result;
1173 }
1174
1175 static int smb_full_audit_rename(vfs_handle_struct *handle,
1176                                  const struct smb_filename *smb_fname_src,
1177                                  const struct smb_filename *smb_fname_dst)
1178 {
1179         int result;
1180         
1181         result = SMB_VFS_NEXT_RENAME(handle, smb_fname_src, smb_fname_dst);
1182
1183         do_log(SMB_VFS_OP_RENAME, (result >= 0), handle, "%s|%s",
1184                smb_fname_str_do_log(smb_fname_src),
1185                smb_fname_str_do_log(smb_fname_dst));
1186
1187         return result;    
1188 }
1189
1190 static int smb_full_audit_fsync(vfs_handle_struct *handle, files_struct *fsp)
1191 {
1192         int result;
1193         
1194         result = SMB_VFS_NEXT_FSYNC(handle, fsp);
1195
1196         do_log(SMB_VFS_OP_FSYNC, (result >= 0), handle, "%s",
1197                fsp_str_do_log(fsp));
1198
1199         return result;    
1200 }
1201
1202 struct smb_full_audit_fsync_state {
1203         vfs_handle_struct *handle;
1204         files_struct *fsp;
1205         int ret;
1206         int err;
1207 };
1208
1209 static void smb_full_audit_fsync_done(struct tevent_req *subreq);
1210
1211 static struct tevent_req *smb_full_audit_fsync_send(
1212         struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1213         struct tevent_context *ev, struct files_struct *fsp)
1214 {
1215         struct tevent_req *req, *subreq;
1216         struct smb_full_audit_fsync_state *state;
1217
1218         req = tevent_req_create(mem_ctx, &state,
1219                                 struct smb_full_audit_fsync_state);
1220         if (req == NULL) {
1221                 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1222                        fsp_str_do_log(fsp));
1223                 return NULL;
1224         }
1225         state->handle = handle;
1226         state->fsp = fsp;
1227
1228         subreq = SMB_VFS_NEXT_FSYNC_SEND(state, ev, handle, fsp);
1229         if (tevent_req_nomem(subreq, req)) {
1230                 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1231                        fsp_str_do_log(fsp));
1232                 return tevent_req_post(req, ev);
1233         }
1234         tevent_req_set_callback(subreq, smb_full_audit_fsync_done, req);
1235
1236         do_log(SMB_VFS_OP_FSYNC_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1237         return req;
1238 }
1239
1240 static void smb_full_audit_fsync_done(struct tevent_req *subreq)
1241 {
1242         struct tevent_req *req = tevent_req_callback_data(
1243                 subreq, struct tevent_req);
1244         struct smb_full_audit_fsync_state *state = tevent_req_data(
1245                 req, struct smb_full_audit_fsync_state);
1246
1247         state->ret = SMB_VFS_FSYNC_RECV(subreq, &state->err);
1248         TALLOC_FREE(subreq);
1249         tevent_req_done(req);
1250 }
1251
1252 static int smb_full_audit_fsync_recv(struct tevent_req *req, int *err)
1253 {
1254         struct smb_full_audit_fsync_state *state = tevent_req_data(
1255                 req, struct smb_full_audit_fsync_state);
1256
1257         if (tevent_req_is_unix_error(req, err)) {
1258                 do_log(SMB_VFS_OP_FSYNC_RECV, false, state->handle, "%s",
1259                        fsp_str_do_log(state->fsp));
1260                 return -1;
1261         }
1262
1263         do_log(SMB_VFS_OP_FSYNC_RECV, (state->ret >= 0), state->handle, "%s",
1264                fsp_str_do_log(state->fsp));
1265
1266         *err = state->err;
1267         return state->ret;
1268 }
1269
1270 static int smb_full_audit_stat(vfs_handle_struct *handle,
1271                                struct smb_filename *smb_fname)
1272 {
1273         int result;
1274         
1275         result = SMB_VFS_NEXT_STAT(handle, smb_fname);
1276
1277         do_log(SMB_VFS_OP_STAT, (result >= 0), handle, "%s",
1278                smb_fname_str_do_log(smb_fname));
1279
1280         return result;    
1281 }
1282
1283 static int smb_full_audit_fstat(vfs_handle_struct *handle, files_struct *fsp,
1284                        SMB_STRUCT_STAT *sbuf)
1285 {
1286         int result;
1287         
1288         result = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1289
1290         do_log(SMB_VFS_OP_FSTAT, (result >= 0), handle, "%s",
1291                fsp_str_do_log(fsp));
1292
1293         return result;
1294 }
1295
1296 static int smb_full_audit_lstat(vfs_handle_struct *handle,
1297                                 struct smb_filename *smb_fname)
1298 {
1299         int result;
1300         
1301         result = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
1302
1303         do_log(SMB_VFS_OP_LSTAT, (result >= 0), handle, "%s",
1304                smb_fname_str_do_log(smb_fname));
1305
1306         return result;    
1307 }
1308
1309 static uint64_t smb_full_audit_get_alloc_size(vfs_handle_struct *handle,
1310                        files_struct *fsp, const SMB_STRUCT_STAT *sbuf)
1311 {
1312         uint64_t result;
1313
1314         result = SMB_VFS_NEXT_GET_ALLOC_SIZE(handle, fsp, sbuf);
1315
1316         do_log(SMB_VFS_OP_GET_ALLOC_SIZE, (result != (uint64_t)-1), handle,
1317                         "%llu", result);
1318
1319         return result;
1320 }
1321
1322 static int smb_full_audit_unlink(vfs_handle_struct *handle,
1323                                  const struct smb_filename *smb_fname)
1324 {
1325         int result;
1326         
1327         result = SMB_VFS_NEXT_UNLINK(handle, smb_fname);
1328
1329         do_log(SMB_VFS_OP_UNLINK, (result >= 0), handle, "%s",
1330                smb_fname_str_do_log(smb_fname));
1331
1332         return result;
1333 }
1334
1335 static int smb_full_audit_chmod(vfs_handle_struct *handle,
1336                        const char *path, mode_t mode)
1337 {
1338         int result;
1339
1340         result = SMB_VFS_NEXT_CHMOD(handle, path, mode);
1341
1342         do_log(SMB_VFS_OP_CHMOD, (result >= 0), handle, "%s|%o", path, mode);
1343
1344         return result;
1345 }
1346
1347 static int smb_full_audit_fchmod(vfs_handle_struct *handle, files_struct *fsp,
1348                         mode_t mode)
1349 {
1350         int result;
1351         
1352         result = SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1353
1354         do_log(SMB_VFS_OP_FCHMOD, (result >= 0), handle,
1355                "%s|%o", fsp_str_do_log(fsp), mode);
1356
1357         return result;
1358 }
1359
1360 static int smb_full_audit_chown(vfs_handle_struct *handle,
1361                        const char *path, uid_t uid, gid_t gid)
1362 {
1363         int result;
1364
1365         result = SMB_VFS_NEXT_CHOWN(handle, path, uid, gid);
1366
1367         do_log(SMB_VFS_OP_CHOWN, (result >= 0), handle, "%s|%ld|%ld",
1368                path, (long int)uid, (long int)gid);
1369
1370         return result;
1371 }
1372
1373 static int smb_full_audit_fchown(vfs_handle_struct *handle, files_struct *fsp,
1374                         uid_t uid, gid_t gid)
1375 {
1376         int result;
1377
1378         result = SMB_VFS_NEXT_FCHOWN(handle, fsp, uid, gid);
1379
1380         do_log(SMB_VFS_OP_FCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1381                fsp_str_do_log(fsp), (long int)uid, (long int)gid);
1382
1383         return result;
1384 }
1385
1386 static int smb_full_audit_lchown(vfs_handle_struct *handle,
1387                        const char *path, uid_t uid, gid_t gid)
1388 {
1389         int result;
1390
1391         result = SMB_VFS_NEXT_LCHOWN(handle, path, uid, gid);
1392
1393         do_log(SMB_VFS_OP_LCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1394                path, (long int)uid, (long int)gid);
1395
1396         return result;
1397 }
1398
1399 static int smb_full_audit_chdir(vfs_handle_struct *handle,
1400                        const char *path)
1401 {
1402         int result;
1403
1404         result = SMB_VFS_NEXT_CHDIR(handle, path);
1405
1406         do_log(SMB_VFS_OP_CHDIR, (result >= 0), handle, "chdir|%s", path);
1407
1408         return result;
1409 }
1410
1411 static char *smb_full_audit_getwd(vfs_handle_struct *handle)
1412 {
1413         char *result;
1414
1415         result = SMB_VFS_NEXT_GETWD(handle);
1416         
1417         do_log(SMB_VFS_OP_GETWD, (result != NULL), handle, "%s",
1418                 result == NULL? "" : result);
1419
1420         return result;
1421 }
1422
1423 static int smb_full_audit_ntimes(vfs_handle_struct *handle,
1424                                  const struct smb_filename *smb_fname,
1425                                  struct smb_file_time *ft)
1426 {
1427         int result;
1428
1429         result = SMB_VFS_NEXT_NTIMES(handle, smb_fname, ft);
1430
1431         do_log(SMB_VFS_OP_NTIMES, (result >= 0), handle, "%s",
1432                smb_fname_str_do_log(smb_fname));
1433
1434         return result;
1435 }
1436
1437 static int smb_full_audit_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
1438                            off_t len)
1439 {
1440         int result;
1441
1442         result = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1443
1444         do_log(SMB_VFS_OP_FTRUNCATE, (result >= 0), handle,
1445                "%s", fsp_str_do_log(fsp));
1446
1447         return result;
1448 }
1449
1450 static int smb_full_audit_fallocate(vfs_handle_struct *handle, files_struct *fsp,
1451                            enum vfs_fallocate_mode mode,
1452                            off_t offset,
1453                            off_t len)
1454 {
1455         int result;
1456
1457         result = SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
1458
1459         do_log(SMB_VFS_OP_FALLOCATE, (result >= 0), handle,
1460                "%s", fsp_str_do_log(fsp));
1461
1462         return result;
1463 }
1464
1465 static bool smb_full_audit_lock(vfs_handle_struct *handle, files_struct *fsp,
1466                        int op, off_t offset, off_t count, int type)
1467 {
1468         bool result;
1469
1470         result = SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type);
1471
1472         do_log(SMB_VFS_OP_LOCK, result, handle, "%s", fsp_str_do_log(fsp));
1473
1474         return result;
1475 }
1476
1477 static int smb_full_audit_kernel_flock(struct vfs_handle_struct *handle,
1478                                        struct files_struct *fsp,
1479                                        uint32 share_mode, uint32 access_mask)
1480 {
1481         int result;
1482
1483         result = SMB_VFS_NEXT_KERNEL_FLOCK(handle, fsp, share_mode, access_mask);
1484
1485         do_log(SMB_VFS_OP_KERNEL_FLOCK, (result >= 0), handle, "%s",
1486                fsp_str_do_log(fsp));
1487
1488         return result;
1489 }
1490
1491 static int smb_full_audit_linux_setlease(vfs_handle_struct *handle, files_struct *fsp,
1492                                  int leasetype)
1493 {
1494         int result;
1495
1496         result = SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
1497
1498         do_log(SMB_VFS_OP_LINUX_SETLEASE, (result >= 0), handle, "%s",
1499                fsp_str_do_log(fsp));
1500
1501         return result;
1502 }
1503
1504 static bool smb_full_audit_getlock(vfs_handle_struct *handle, files_struct *fsp,
1505                        off_t *poffset, off_t *pcount, int *ptype, pid_t *ppid)
1506 {
1507         bool result;
1508
1509         result = SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype, ppid);
1510
1511         do_log(SMB_VFS_OP_GETLOCK, result, handle, "%s", fsp_str_do_log(fsp));
1512
1513         return result;
1514 }
1515
1516 static int smb_full_audit_symlink(vfs_handle_struct *handle,
1517                          const char *oldpath, const char *newpath)
1518 {
1519         int result;
1520
1521         result = SMB_VFS_NEXT_SYMLINK(handle, oldpath, newpath);
1522
1523         do_log(SMB_VFS_OP_SYMLINK, (result >= 0), handle,
1524                "%s|%s", oldpath, newpath);
1525
1526         return result;
1527 }
1528
1529 static int smb_full_audit_readlink(vfs_handle_struct *handle,
1530                           const char *path, char *buf, size_t bufsiz)
1531 {
1532         int result;
1533
1534         result = SMB_VFS_NEXT_READLINK(handle, path, buf, bufsiz);
1535
1536         do_log(SMB_VFS_OP_READLINK, (result >= 0), handle, "%s", path);
1537
1538         return result;
1539 }
1540
1541 static int smb_full_audit_link(vfs_handle_struct *handle,
1542                       const char *oldpath, const char *newpath)
1543 {
1544         int result;
1545
1546         result = SMB_VFS_NEXT_LINK(handle, oldpath, newpath);
1547
1548         do_log(SMB_VFS_OP_LINK, (result >= 0), handle,
1549                "%s|%s", oldpath, newpath);
1550
1551         return result;
1552 }
1553
1554 static int smb_full_audit_mknod(vfs_handle_struct *handle,
1555                        const char *pathname, mode_t mode, SMB_DEV_T dev)
1556 {
1557         int result;
1558
1559         result = SMB_VFS_NEXT_MKNOD(handle, pathname, mode, dev);
1560
1561         do_log(SMB_VFS_OP_MKNOD, (result >= 0), handle, "%s", pathname);
1562
1563         return result;
1564 }
1565
1566 static char *smb_full_audit_realpath(vfs_handle_struct *handle,
1567                             const char *path)
1568 {
1569         char *result;
1570
1571         result = SMB_VFS_NEXT_REALPATH(handle, path);
1572
1573         do_log(SMB_VFS_OP_REALPATH, (result != NULL), handle, "%s", path);
1574
1575         return result;
1576 }
1577
1578 static NTSTATUS smb_full_audit_notify_watch(struct vfs_handle_struct *handle,
1579                         struct sys_notify_context *ctx,
1580                         const char *path,
1581                         uint32_t *filter,
1582                         uint32_t *subdir_filter,
1583                         void (*callback)(struct sys_notify_context *ctx,
1584                                         void *private_data,
1585                                         struct notify_event *ev),
1586                         void *private_data, void *handle_p)
1587 {
1588         NTSTATUS result;
1589
1590         result = SMB_VFS_NEXT_NOTIFY_WATCH(handle, ctx, path,
1591                                            filter, subdir_filter, callback,
1592                                            private_data, handle_p);
1593
1594         do_log(SMB_VFS_OP_NOTIFY_WATCH, NT_STATUS_IS_OK(result), handle, "");
1595
1596         return result;
1597 }
1598
1599 static int smb_full_audit_chflags(vfs_handle_struct *handle,
1600                             const char *path, unsigned int flags)
1601 {
1602         int result;
1603
1604         result = SMB_VFS_NEXT_CHFLAGS(handle, path, flags);
1605
1606         do_log(SMB_VFS_OP_CHFLAGS, (result != 0), handle, "%s", path);
1607
1608         return result;
1609 }
1610
1611 static struct file_id smb_full_audit_file_id_create(struct vfs_handle_struct *handle,
1612                                                     const SMB_STRUCT_STAT *sbuf)
1613 {
1614         struct file_id id_zero;
1615         struct file_id result;
1616
1617         ZERO_STRUCT(id_zero);
1618
1619         result = SMB_VFS_NEXT_FILE_ID_CREATE(handle, sbuf);
1620
1621         do_log(SMB_VFS_OP_FILE_ID_CREATE,
1622                !file_id_equal(&id_zero, &result),
1623                handle, "%s", file_id_string_tos(&result));
1624
1625         return result;
1626 }
1627
1628 static NTSTATUS smb_full_audit_streaminfo(vfs_handle_struct *handle,
1629                                           struct files_struct *fsp,
1630                                           const char *fname,
1631                                           TALLOC_CTX *mem_ctx,
1632                                           unsigned int *pnum_streams,
1633                                           struct stream_struct **pstreams)
1634 {
1635         NTSTATUS result;
1636
1637         result = SMB_VFS_NEXT_STREAMINFO(handle, fsp, fname, mem_ctx,
1638                                          pnum_streams, pstreams);
1639
1640         do_log(SMB_VFS_OP_STREAMINFO, NT_STATUS_IS_OK(result), handle,
1641                "%s", fname);
1642
1643         return result;
1644 }
1645
1646 static int smb_full_audit_get_real_filename(struct vfs_handle_struct *handle,
1647                                             const char *path,
1648                                             const char *name,
1649                                             TALLOC_CTX *mem_ctx,
1650                                             char **found_name)
1651 {
1652         int result;
1653
1654         result = SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name, mem_ctx,
1655                                                 found_name);
1656
1657         do_log(SMB_VFS_OP_GET_REAL_FILENAME, (result == 0), handle,
1658                "%s/%s->%s", path, name, (result == 0) ? "" : *found_name);
1659
1660         return result;
1661 }
1662
1663 static const char *smb_full_audit_connectpath(vfs_handle_struct *handle,
1664                                               const char *fname)
1665 {
1666         const char *result;
1667
1668         result = SMB_VFS_NEXT_CONNECTPATH(handle, fname);
1669
1670         do_log(SMB_VFS_OP_CONNECTPATH, result != NULL, handle,
1671                "%s", fname);
1672
1673         return result;
1674 }
1675
1676 static NTSTATUS smb_full_audit_brl_lock_windows(struct vfs_handle_struct *handle,
1677                                                 struct byte_range_lock *br_lck,
1678                                                 struct lock_struct *plock,
1679                                                 bool blocking_lock,
1680                                                 struct blocking_lock_record *blr)
1681 {
1682         NTSTATUS result;
1683
1684         result = SMB_VFS_NEXT_BRL_LOCK_WINDOWS(handle, br_lck, plock,
1685             blocking_lock, blr);
1686
1687         do_log(SMB_VFS_OP_BRL_LOCK_WINDOWS, NT_STATUS_IS_OK(result), handle,
1688             "%s:%llu-%llu. type=%d. blocking=%d", fsp_str_do_log(br_lck->fsp),
1689             plock->start, plock->size, plock->lock_type, blocking_lock );
1690
1691         return result;
1692 }
1693
1694 static bool smb_full_audit_brl_unlock_windows(struct vfs_handle_struct *handle,
1695                                               struct messaging_context *msg_ctx,
1696                                               struct byte_range_lock *br_lck,
1697                                               const struct lock_struct *plock)
1698 {
1699         bool result;
1700
1701         result = SMB_VFS_NEXT_BRL_UNLOCK_WINDOWS(handle, msg_ctx, br_lck,
1702             plock);
1703
1704         do_log(SMB_VFS_OP_BRL_UNLOCK_WINDOWS, (result == 0), handle,
1705             "%s:%llu-%llu:%d", fsp_str_do_log(br_lck->fsp), plock->start,
1706             plock->size, plock->lock_type);
1707
1708         return result;
1709 }
1710
1711 static bool smb_full_audit_brl_cancel_windows(struct vfs_handle_struct *handle,
1712                                               struct byte_range_lock *br_lck,
1713                                               struct lock_struct *plock,
1714                                               struct blocking_lock_record *blr)
1715 {
1716         bool result;
1717
1718         result = SMB_VFS_NEXT_BRL_CANCEL_WINDOWS(handle, br_lck, plock, blr);
1719
1720         do_log(SMB_VFS_OP_BRL_CANCEL_WINDOWS, (result == 0), handle,
1721             "%s:%llu-%llu:%d", fsp_str_do_log(br_lck->fsp), plock->start,
1722             plock->size);
1723
1724         return result;
1725 }
1726
1727 static bool smb_full_audit_strict_lock(struct vfs_handle_struct *handle,
1728                                        struct files_struct *fsp,
1729                                        struct lock_struct *plock)
1730 {
1731         bool result;
1732
1733         result = SMB_VFS_NEXT_STRICT_LOCK(handle, fsp, plock);
1734
1735         do_log(SMB_VFS_OP_STRICT_LOCK, result, handle,
1736             "%s:%llu-%llu:%d", fsp_str_do_log(fsp), plock->start,
1737             plock->size);
1738
1739         return result;
1740 }
1741
1742 static void smb_full_audit_strict_unlock(struct vfs_handle_struct *handle,
1743                                          struct files_struct *fsp,
1744                                          struct lock_struct *plock)
1745 {
1746         SMB_VFS_NEXT_STRICT_UNLOCK(handle, fsp, plock);
1747
1748         do_log(SMB_VFS_OP_STRICT_UNLOCK, true, handle,
1749             "%s:%llu-%llu:%d", fsp_str_do_log(fsp), plock->start,
1750             plock->size);
1751
1752         return;
1753 }
1754
1755 static NTSTATUS smb_full_audit_translate_name(struct vfs_handle_struct *handle,
1756                                               const char *name,
1757                                               enum vfs_translate_direction direction,
1758                                               TALLOC_CTX *mem_ctx,
1759                                               char **mapped_name)
1760 {
1761         NTSTATUS result;
1762
1763         result = SMB_VFS_NEXT_TRANSLATE_NAME(handle, name, direction, mem_ctx,
1764                                              mapped_name);
1765
1766         do_log(SMB_VFS_OP_TRANSLATE_NAME, NT_STATUS_IS_OK(result), handle, "");
1767
1768         return result;
1769 }
1770
1771 static NTSTATUS smb_full_audit_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
1772                                 uint32 security_info,
1773                                 struct security_descriptor **ppdesc)
1774 {
1775         NTSTATUS result;
1776
1777         result = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info, ppdesc);
1778
1779         do_log(SMB_VFS_OP_FGET_NT_ACL, NT_STATUS_IS_OK(result), handle,
1780                "%s", fsp_str_do_log(fsp));
1781
1782         return result;
1783 }
1784
1785 static NTSTATUS smb_full_audit_get_nt_acl(vfs_handle_struct *handle,
1786                                           const char *name,
1787                                           uint32 security_info,
1788                                           struct security_descriptor **ppdesc)
1789 {
1790         NTSTATUS result;
1791
1792         result = SMB_VFS_NEXT_GET_NT_ACL(handle, name, security_info, ppdesc);
1793
1794         do_log(SMB_VFS_OP_GET_NT_ACL, NT_STATUS_IS_OK(result), handle,
1795                "%s", name);
1796
1797         return result;
1798 }
1799
1800 static NTSTATUS smb_full_audit_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
1801                               uint32 security_info_sent,
1802                               const struct security_descriptor *psd)
1803 {
1804         NTSTATUS result;
1805
1806         result = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
1807
1808         do_log(SMB_VFS_OP_FSET_NT_ACL, NT_STATUS_IS_OK(result), handle, "%s",
1809                fsp_str_do_log(fsp));
1810
1811         return result;
1812 }
1813
1814 static int smb_full_audit_chmod_acl(vfs_handle_struct *handle,
1815                            const char *path, mode_t mode)
1816 {
1817         int result;
1818         
1819         result = SMB_VFS_NEXT_CHMOD_ACL(handle, path, mode);
1820
1821         do_log(SMB_VFS_OP_CHMOD_ACL, (result >= 0), handle,
1822                "%s|%o", path, mode);
1823
1824         return result;
1825 }
1826
1827 static int smb_full_audit_fchmod_acl(vfs_handle_struct *handle, files_struct *fsp,
1828                                      mode_t mode)
1829 {
1830         int result;
1831         
1832         result = SMB_VFS_NEXT_FCHMOD_ACL(handle, fsp, mode);
1833
1834         do_log(SMB_VFS_OP_FCHMOD_ACL, (result >= 0), handle,
1835                "%s|%o", fsp_str_do_log(fsp), mode);
1836
1837         return result;
1838 }
1839
1840 static int smb_full_audit_sys_acl_get_entry(vfs_handle_struct *handle,
1841
1842                                    SMB_ACL_T theacl, int entry_id,
1843                                    SMB_ACL_ENTRY_T *entry_p)
1844 {
1845         int result;
1846
1847         result = SMB_VFS_NEXT_SYS_ACL_GET_ENTRY(handle, theacl, entry_id,
1848                                                 entry_p);
1849
1850         do_log(SMB_VFS_OP_SYS_ACL_GET_ENTRY, (result >= 0), handle,
1851                "");
1852
1853         return result;
1854 }
1855
1856 static int smb_full_audit_sys_acl_get_tag_type(vfs_handle_struct *handle,
1857
1858                                       SMB_ACL_ENTRY_T entry_d,
1859                                       SMB_ACL_TAG_T *tag_type_p)
1860 {
1861         int result;
1862
1863         result = SMB_VFS_NEXT_SYS_ACL_GET_TAG_TYPE(handle, entry_d,
1864                                                    tag_type_p);
1865
1866         do_log(SMB_VFS_OP_SYS_ACL_GET_TAG_TYPE, (result >= 0), handle,
1867                "");
1868
1869         return result;
1870 }
1871
1872 static int smb_full_audit_sys_acl_get_permset(vfs_handle_struct *handle,
1873
1874                                      SMB_ACL_ENTRY_T entry_d,
1875                                      SMB_ACL_PERMSET_T *permset_p)
1876 {
1877         int result;
1878
1879         result = SMB_VFS_NEXT_SYS_ACL_GET_PERMSET(handle, entry_d,
1880                                                   permset_p);
1881
1882         do_log(SMB_VFS_OP_SYS_ACL_GET_PERMSET, (result >= 0), handle,
1883                "");
1884
1885         return result;
1886 }
1887
1888 static void * smb_full_audit_sys_acl_get_qualifier(vfs_handle_struct *handle,
1889
1890                                           SMB_ACL_ENTRY_T entry_d)
1891 {
1892         void *result;
1893
1894         result = SMB_VFS_NEXT_SYS_ACL_GET_QUALIFIER(handle, entry_d);
1895
1896         do_log(SMB_VFS_OP_SYS_ACL_GET_QUALIFIER, (result != NULL), handle,
1897                "");
1898
1899         return result;
1900 }
1901
1902 static SMB_ACL_T smb_full_audit_sys_acl_get_file(vfs_handle_struct *handle,
1903                                         const char *path_p,
1904                                         SMB_ACL_TYPE_T type)
1905 {
1906         SMB_ACL_T result;
1907
1908         result = SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, path_p, type);
1909
1910         do_log(SMB_VFS_OP_SYS_ACL_GET_FILE, (result != NULL), handle,
1911                "%s", path_p);
1912
1913         return result;
1914 }
1915
1916 static SMB_ACL_T smb_full_audit_sys_acl_get_fd(vfs_handle_struct *handle,
1917                                       files_struct *fsp)
1918 {
1919         SMB_ACL_T result;
1920
1921         result = SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp);
1922
1923         do_log(SMB_VFS_OP_SYS_ACL_GET_FD, (result != NULL), handle,
1924                "%s", fsp_str_do_log(fsp));
1925
1926         return result;
1927 }
1928
1929 static int smb_full_audit_sys_acl_clear_perms(vfs_handle_struct *handle,
1930
1931                                      SMB_ACL_PERMSET_T permset)
1932 {
1933         int result;
1934
1935         result = SMB_VFS_NEXT_SYS_ACL_CLEAR_PERMS(handle, permset);
1936
1937         do_log(SMB_VFS_OP_SYS_ACL_CLEAR_PERMS, (result >= 0), handle,
1938                "");
1939
1940         return result;
1941 }
1942
1943 static int smb_full_audit_sys_acl_add_perm(vfs_handle_struct *handle,
1944
1945                                   SMB_ACL_PERMSET_T permset,
1946                                   SMB_ACL_PERM_T perm)
1947 {
1948         int result;
1949
1950         result = SMB_VFS_NEXT_SYS_ACL_ADD_PERM(handle, permset, perm);
1951
1952         do_log(SMB_VFS_OP_SYS_ACL_ADD_PERM, (result >= 0), handle,
1953                "");
1954
1955         return result;
1956 }
1957
1958 static char * smb_full_audit_sys_acl_to_text(vfs_handle_struct *handle,
1959                                     SMB_ACL_T theacl,
1960                                     ssize_t *plen)
1961 {
1962         char * result;
1963
1964         result = SMB_VFS_NEXT_SYS_ACL_TO_TEXT(handle, theacl, plen);
1965
1966         do_log(SMB_VFS_OP_SYS_ACL_TO_TEXT, (result != NULL), handle,
1967                "");
1968
1969         return result;
1970 }
1971
1972 static SMB_ACL_T smb_full_audit_sys_acl_init(vfs_handle_struct *handle,
1973
1974                                     int count)
1975 {
1976         SMB_ACL_T result;
1977
1978         result = SMB_VFS_NEXT_SYS_ACL_INIT(handle, count);
1979
1980         do_log(SMB_VFS_OP_SYS_ACL_INIT, (result != NULL), handle,
1981                "");
1982
1983         return result;
1984 }
1985
1986 static int smb_full_audit_sys_acl_create_entry(vfs_handle_struct *handle,
1987                                       SMB_ACL_T *pacl,
1988                                       SMB_ACL_ENTRY_T *pentry)
1989 {
1990         int result;
1991
1992         result = SMB_VFS_NEXT_SYS_ACL_CREATE_ENTRY(handle, pacl, pentry);
1993
1994         do_log(SMB_VFS_OP_SYS_ACL_CREATE_ENTRY, (result >= 0), handle,
1995                "");
1996
1997         return result;
1998 }
1999
2000 static int smb_full_audit_sys_acl_set_tag_type(vfs_handle_struct *handle,
2001
2002                                       SMB_ACL_ENTRY_T entry,
2003                                       SMB_ACL_TAG_T tagtype)
2004 {
2005         int result;
2006
2007         result = SMB_VFS_NEXT_SYS_ACL_SET_TAG_TYPE(handle, entry,
2008                                                    tagtype);
2009
2010         do_log(SMB_VFS_OP_SYS_ACL_SET_TAG_TYPE, (result >= 0), handle,
2011                "");
2012
2013         return result;
2014 }
2015
2016 static int smb_full_audit_sys_acl_set_qualifier(vfs_handle_struct *handle,
2017
2018                                        SMB_ACL_ENTRY_T entry,
2019                                        void *qual)
2020 {
2021         int result;
2022
2023         result = SMB_VFS_NEXT_SYS_ACL_SET_QUALIFIER(handle, entry, qual);
2024
2025         do_log(SMB_VFS_OP_SYS_ACL_SET_QUALIFIER, (result >= 0), handle,
2026                "");
2027
2028         return result;
2029 }
2030
2031 static int smb_full_audit_sys_acl_set_permset(vfs_handle_struct *handle,
2032
2033                                      SMB_ACL_ENTRY_T entry,
2034                                      SMB_ACL_PERMSET_T permset)
2035 {
2036         int result;
2037
2038         result = SMB_VFS_NEXT_SYS_ACL_SET_PERMSET(handle, entry, permset);
2039
2040         do_log(SMB_VFS_OP_SYS_ACL_SET_PERMSET, (result >= 0), handle,
2041                "");
2042
2043         return result;
2044 }
2045
2046 static int smb_full_audit_sys_acl_valid(vfs_handle_struct *handle,
2047
2048                                SMB_ACL_T theacl )
2049 {
2050         int result;
2051
2052         result = SMB_VFS_NEXT_SYS_ACL_VALID(handle, theacl);
2053
2054         do_log(SMB_VFS_OP_SYS_ACL_VALID, (result >= 0), handle,
2055                "");
2056
2057         return result;
2058 }
2059
2060 static int smb_full_audit_sys_acl_set_file(vfs_handle_struct *handle,
2061
2062                                   const char *name, SMB_ACL_TYPE_T acltype,
2063                                   SMB_ACL_T theacl)
2064 {
2065         int result;
2066
2067         result = SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, name, acltype,
2068                                                theacl);
2069
2070         do_log(SMB_VFS_OP_SYS_ACL_SET_FILE, (result >= 0), handle,
2071                "%s", name);
2072
2073         return result;
2074 }
2075
2076 static int smb_full_audit_sys_acl_set_fd(vfs_handle_struct *handle, files_struct *fsp,
2077                                 SMB_ACL_T theacl)
2078 {
2079         int result;
2080
2081         result = SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, theacl);
2082
2083         do_log(SMB_VFS_OP_SYS_ACL_SET_FD, (result >= 0), handle,
2084                "%s", fsp_str_do_log(fsp));
2085
2086         return result;
2087 }
2088
2089 static int smb_full_audit_sys_acl_delete_def_file(vfs_handle_struct *handle,
2090
2091                                          const char *path)
2092 {
2093         int result;
2094
2095         result = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, path);
2096
2097         do_log(SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE, (result >= 0), handle,
2098                "%s", path);
2099
2100         return result;
2101 }
2102
2103 static int smb_full_audit_sys_acl_get_perm(vfs_handle_struct *handle,
2104
2105                                   SMB_ACL_PERMSET_T permset,
2106                                   SMB_ACL_PERM_T perm)
2107 {
2108         int result;
2109
2110         result = SMB_VFS_NEXT_SYS_ACL_GET_PERM(handle, permset, perm);
2111
2112         do_log(SMB_VFS_OP_SYS_ACL_GET_PERM, (result >= 0), handle,
2113                "");
2114
2115         return result;
2116 }
2117
2118 static int smb_full_audit_sys_acl_free_text(vfs_handle_struct *handle,
2119
2120                                    char *text)
2121 {
2122         int result;
2123
2124         result = SMB_VFS_NEXT_SYS_ACL_FREE_TEXT(handle, text);
2125
2126         do_log(SMB_VFS_OP_SYS_ACL_FREE_TEXT, (result >= 0), handle,
2127                "");
2128
2129         return result;
2130 }
2131
2132 static int smb_full_audit_sys_acl_free_acl(vfs_handle_struct *handle,
2133
2134                                   SMB_ACL_T posix_acl)
2135 {
2136         int result;
2137
2138         result = SMB_VFS_NEXT_SYS_ACL_FREE_ACL(handle, posix_acl);
2139
2140         do_log(SMB_VFS_OP_SYS_ACL_FREE_ACL, (result >= 0), handle,
2141                "");
2142
2143         return result;
2144 }
2145
2146 static int smb_full_audit_sys_acl_free_qualifier(vfs_handle_struct *handle,
2147                                         void *qualifier,
2148                                         SMB_ACL_TAG_T tagtype)
2149 {
2150         int result;
2151
2152         result = SMB_VFS_NEXT_SYS_ACL_FREE_QUALIFIER(handle, qualifier,
2153                                                      tagtype);
2154
2155         do_log(SMB_VFS_OP_SYS_ACL_FREE_QUALIFIER, (result >= 0), handle,
2156                "");
2157
2158         return result;
2159 }
2160
2161 static ssize_t smb_full_audit_getxattr(struct vfs_handle_struct *handle,
2162                               const char *path,
2163                               const char *name, void *value, size_t size)
2164 {
2165         ssize_t result;
2166
2167         result = SMB_VFS_NEXT_GETXATTR(handle, path, name, value, size);
2168
2169         do_log(SMB_VFS_OP_GETXATTR, (result >= 0), handle,
2170                "%s|%s", path, name);
2171
2172         return result;
2173 }
2174
2175 static ssize_t smb_full_audit_fgetxattr(struct vfs_handle_struct *handle,
2176                                struct files_struct *fsp,
2177                                const char *name, void *value, size_t size)
2178 {
2179         ssize_t result;
2180
2181         result = SMB_VFS_NEXT_FGETXATTR(handle, fsp, name, value, size);
2182
2183         do_log(SMB_VFS_OP_FGETXATTR, (result >= 0), handle,
2184                "%s|%s", fsp_str_do_log(fsp), name);
2185
2186         return result;
2187 }
2188
2189 static ssize_t smb_full_audit_listxattr(struct vfs_handle_struct *handle,
2190                                const char *path, char *list, size_t size)
2191 {
2192         ssize_t result;
2193
2194         result = SMB_VFS_NEXT_LISTXATTR(handle, path, list, size);
2195
2196         do_log(SMB_VFS_OP_LISTXATTR, (result >= 0), handle, "%s", path);
2197
2198         return result;
2199 }
2200
2201 static ssize_t smb_full_audit_flistxattr(struct vfs_handle_struct *handle,
2202                                 struct files_struct *fsp, char *list,
2203                                 size_t size)
2204 {
2205         ssize_t result;
2206
2207         result = SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
2208
2209         do_log(SMB_VFS_OP_FLISTXATTR, (result >= 0), handle,
2210                "%s", fsp_str_do_log(fsp));
2211
2212         return result;
2213 }
2214
2215 static int smb_full_audit_removexattr(struct vfs_handle_struct *handle,
2216                              const char *path,
2217                              const char *name)
2218 {
2219         int result;
2220
2221         result = SMB_VFS_NEXT_REMOVEXATTR(handle, path, name);
2222
2223         do_log(SMB_VFS_OP_REMOVEXATTR, (result >= 0), handle,
2224                "%s|%s", path, name);
2225
2226         return result;
2227 }
2228
2229 static int smb_full_audit_fremovexattr(struct vfs_handle_struct *handle,
2230                               struct files_struct *fsp,
2231                               const char *name)
2232 {
2233         int result;
2234
2235         result = SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, name);
2236
2237         do_log(SMB_VFS_OP_FREMOVEXATTR, (result >= 0), handle,
2238                "%s|%s", fsp_str_do_log(fsp), name);
2239
2240         return result;
2241 }
2242
2243 static int smb_full_audit_setxattr(struct vfs_handle_struct *handle,
2244                           const char *path,
2245                           const char *name, const void *value, size_t size,
2246                           int flags)
2247 {
2248         int result;
2249
2250         result = SMB_VFS_NEXT_SETXATTR(handle, path, name, value, size,
2251                                        flags);
2252
2253         do_log(SMB_VFS_OP_SETXATTR, (result >= 0), handle,
2254                "%s|%s", path, name);
2255
2256         return result;
2257 }
2258
2259 static int smb_full_audit_fsetxattr(struct vfs_handle_struct *handle,
2260                            struct files_struct *fsp, const char *name,
2261                            const void *value, size_t size, int flags)
2262 {
2263         int result;
2264
2265         result = SMB_VFS_NEXT_FSETXATTR(handle, fsp, name, value, size, flags);
2266
2267         do_log(SMB_VFS_OP_FSETXATTR, (result >= 0), handle,
2268                "%s|%s", fsp_str_do_log(fsp), name);
2269
2270         return result;
2271 }
2272
2273 static bool smb_full_audit_aio_force(struct vfs_handle_struct *handle,
2274                                      struct files_struct *fsp)
2275 {
2276         bool result;
2277
2278         result = SMB_VFS_NEXT_AIO_FORCE(handle, fsp);
2279         do_log(SMB_VFS_OP_AIO_FORCE, result, handle,
2280                 "%s", fsp_str_do_log(fsp));
2281
2282         return result;
2283 }
2284
2285 static bool smb_full_audit_is_offline(struct vfs_handle_struct *handle,
2286                                       const struct smb_filename *fname,
2287                                       SMB_STRUCT_STAT *sbuf)
2288 {
2289         bool result;
2290
2291         result = SMB_VFS_NEXT_IS_OFFLINE(handle, fname, sbuf);
2292         do_log(SMB_VFS_OP_IS_OFFLINE, result, handle, "%s",
2293                smb_fname_str_do_log(fname));
2294         return result;
2295 }
2296
2297 static int smb_full_audit_set_offline(struct vfs_handle_struct *handle,
2298                                       const struct smb_filename *fname)
2299 {
2300         int result;
2301
2302         result = SMB_VFS_NEXT_SET_OFFLINE(handle, fname);
2303         do_log(SMB_VFS_OP_SET_OFFLINE, result >= 0, handle, "%s",
2304                smb_fname_str_do_log(fname));
2305         return result;
2306 }
2307
2308 static struct vfs_fn_pointers vfs_full_audit_fns = {
2309
2310         /* Disk operations */
2311
2312         .connect_fn = smb_full_audit_connect,
2313         .disconnect_fn = smb_full_audit_disconnect,
2314         .disk_free_fn = smb_full_audit_disk_free,
2315         .get_quota_fn = smb_full_audit_get_quota,
2316         .set_quota_fn = smb_full_audit_set_quota,
2317         .get_shadow_copy_data_fn = smb_full_audit_get_shadow_copy_data,
2318         .statvfs_fn = smb_full_audit_statvfs,
2319         .fs_capabilities_fn = smb_full_audit_fs_capabilities,
2320         .opendir_fn = smb_full_audit_opendir,
2321         .fdopendir_fn = smb_full_audit_fdopendir,
2322         .readdir_fn = smb_full_audit_readdir,
2323         .seekdir_fn = smb_full_audit_seekdir,
2324         .telldir_fn = smb_full_audit_telldir,
2325         .rewind_dir_fn = smb_full_audit_rewinddir,
2326         .mkdir_fn = smb_full_audit_mkdir,
2327         .rmdir_fn = smb_full_audit_rmdir,
2328         .closedir_fn = smb_full_audit_closedir,
2329         .init_search_op_fn = smb_full_audit_init_search_op,
2330         .open_fn = smb_full_audit_open,
2331         .create_file_fn = smb_full_audit_create_file,
2332         .close_fn = smb_full_audit_close,
2333         .read_fn = smb_full_audit_read,
2334         .pread_fn = smb_full_audit_pread,
2335         .pread_send_fn = smb_full_audit_pread_send,
2336         .pread_recv_fn = smb_full_audit_pread_recv,
2337         .write_fn = smb_full_audit_write,
2338         .pwrite_fn = smb_full_audit_pwrite,
2339         .pwrite_send_fn = smb_full_audit_pwrite_send,
2340         .pwrite_recv_fn = smb_full_audit_pwrite_recv,
2341         .lseek_fn = smb_full_audit_lseek,
2342         .sendfile_fn = smb_full_audit_sendfile,
2343         .recvfile_fn = smb_full_audit_recvfile,
2344         .rename_fn = smb_full_audit_rename,
2345         .fsync_fn = smb_full_audit_fsync,
2346         .fsync_send_fn = smb_full_audit_fsync_send,
2347         .fsync_recv_fn = smb_full_audit_fsync_recv,
2348         .stat_fn = smb_full_audit_stat,
2349         .fstat_fn = smb_full_audit_fstat,
2350         .lstat_fn = smb_full_audit_lstat,
2351         .get_alloc_size_fn = smb_full_audit_get_alloc_size,
2352         .unlink_fn = smb_full_audit_unlink,
2353         .chmod_fn = smb_full_audit_chmod,
2354         .fchmod_fn = smb_full_audit_fchmod,
2355         .chown_fn = smb_full_audit_chown,
2356         .fchown_fn = smb_full_audit_fchown,
2357         .lchown_fn = smb_full_audit_lchown,
2358         .chdir_fn = smb_full_audit_chdir,
2359         .getwd_fn = smb_full_audit_getwd,
2360         .ntimes_fn = smb_full_audit_ntimes,
2361         .ftruncate_fn = smb_full_audit_ftruncate,
2362         .fallocate_fn = smb_full_audit_fallocate,
2363         .lock_fn = smb_full_audit_lock,
2364         .kernel_flock_fn = smb_full_audit_kernel_flock,
2365         .linux_setlease_fn = smb_full_audit_linux_setlease,
2366         .getlock_fn = smb_full_audit_getlock,
2367         .symlink_fn = smb_full_audit_symlink,
2368         .readlink_fn = smb_full_audit_readlink,
2369         .link_fn = smb_full_audit_link,
2370         .mknod_fn = smb_full_audit_mknod,
2371         .realpath_fn = smb_full_audit_realpath,
2372         .notify_watch_fn = smb_full_audit_notify_watch,
2373         .chflags_fn = smb_full_audit_chflags,
2374         .file_id_create_fn = smb_full_audit_file_id_create,
2375         .streaminfo_fn = smb_full_audit_streaminfo,
2376         .get_real_filename_fn = smb_full_audit_get_real_filename,
2377         .connectpath_fn = smb_full_audit_connectpath,
2378         .brl_lock_windows_fn = smb_full_audit_brl_lock_windows,
2379         .brl_unlock_windows_fn = smb_full_audit_brl_unlock_windows,
2380         .brl_cancel_windows_fn = smb_full_audit_brl_cancel_windows,
2381         .strict_lock_fn = smb_full_audit_strict_lock,
2382         .strict_unlock_fn = smb_full_audit_strict_unlock,
2383         .translate_name_fn = smb_full_audit_translate_name,
2384         .fget_nt_acl_fn = smb_full_audit_fget_nt_acl,
2385         .get_nt_acl_fn = smb_full_audit_get_nt_acl,
2386         .fset_nt_acl_fn = smb_full_audit_fset_nt_acl,
2387         .chmod_acl_fn = smb_full_audit_chmod_acl,
2388         .fchmod_acl_fn = smb_full_audit_fchmod_acl,
2389         .sys_acl_get_entry_fn = smb_full_audit_sys_acl_get_entry,
2390         .sys_acl_get_tag_type_fn = smb_full_audit_sys_acl_get_tag_type,
2391         .sys_acl_get_permset_fn = smb_full_audit_sys_acl_get_permset,
2392         .sys_acl_get_qualifier_fn = smb_full_audit_sys_acl_get_qualifier,
2393         .sys_acl_get_file_fn = smb_full_audit_sys_acl_get_file,
2394         .sys_acl_get_fd_fn = smb_full_audit_sys_acl_get_fd,
2395         .sys_acl_clear_perms_fn = smb_full_audit_sys_acl_clear_perms,
2396         .sys_acl_add_perm_fn = smb_full_audit_sys_acl_add_perm,
2397         .sys_acl_to_text_fn = smb_full_audit_sys_acl_to_text,
2398         .sys_acl_init_fn = smb_full_audit_sys_acl_init,
2399         .sys_acl_create_entry_fn = smb_full_audit_sys_acl_create_entry,
2400         .sys_acl_set_tag_type_fn = smb_full_audit_sys_acl_set_tag_type,
2401         .sys_acl_set_qualifier_fn = smb_full_audit_sys_acl_set_qualifier,
2402         .sys_acl_set_permset_fn = smb_full_audit_sys_acl_set_permset,
2403         .sys_acl_valid_fn = smb_full_audit_sys_acl_valid,
2404         .sys_acl_set_file_fn = smb_full_audit_sys_acl_set_file,
2405         .sys_acl_set_fd_fn = smb_full_audit_sys_acl_set_fd,
2406         .sys_acl_delete_def_file_fn = smb_full_audit_sys_acl_delete_def_file,
2407         .sys_acl_get_perm_fn = smb_full_audit_sys_acl_get_perm,
2408         .sys_acl_free_text_fn = smb_full_audit_sys_acl_free_text,
2409         .sys_acl_free_acl_fn = smb_full_audit_sys_acl_free_acl,
2410         .sys_acl_free_qualifier_fn = smb_full_audit_sys_acl_free_qualifier,
2411         .getxattr_fn = smb_full_audit_getxattr,
2412         .fgetxattr_fn = smb_full_audit_fgetxattr,
2413         .listxattr_fn = smb_full_audit_listxattr,
2414         .flistxattr_fn = smb_full_audit_flistxattr,
2415         .removexattr_fn = smb_full_audit_removexattr,
2416         .fremovexattr_fn = smb_full_audit_fremovexattr,
2417         .setxattr_fn = smb_full_audit_setxattr,
2418         .fsetxattr_fn = smb_full_audit_fsetxattr,
2419         .aio_force_fn = smb_full_audit_aio_force,
2420         .is_offline_fn = smb_full_audit_is_offline,
2421         .set_offline_fn = smb_full_audit_set_offline,
2422 };
2423
2424 NTSTATUS vfs_full_audit_init(void)
2425 {
2426         NTSTATUS ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION,
2427                                         "full_audit", &vfs_full_audit_fns);
2428         
2429         if (!NT_STATUS_IS_OK(ret))
2430                 return ret;
2431
2432         vfs_full_audit_debug_level = debug_add_class("full_audit");
2433         if (vfs_full_audit_debug_level == -1) {
2434                 vfs_full_audit_debug_level = DBGC_VFS;
2435                 DEBUG(0, ("vfs_full_audit: Couldn't register custom debugging "
2436                           "class!\n"));
2437         } else {
2438                 DEBUG(10, ("vfs_full_audit: Debug class number of "
2439                            "'full_audit': %d\n", vfs_full_audit_debug_level));
2440         }
2441         
2442         return ret;
2443 }