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