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