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