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