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