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