s3:vfs: add create tags to SMB_VFS_CREATEFILE
[obnox/samba/samba-obnox.git] / source3 / modules / vfs_full_audit.c
1 /* 
2  * Auditing VFS module for samba.  Log selected file operations to syslog
3  * facility.
4  *
5  * Copyright (C) Tim Potter, 1999-2000
6  * Copyright (C) Alexander Bokovoy, 2002
7  * Copyright (C) John H Terpstra, 2003
8  * Copyright (C) Stefan (metze) Metzmacher, 2003
9  * Copyright (C) Volker Lendecke, 2004
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 3 of the License, or
14  * (at your option) any later version.
15  *  
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *  
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, see <http://www.gnu.org/licenses/>.
23  */
24
25 /*
26  * This module implements parseable logging for all Samba VFS operations.
27  *
28  * You use it as follows:
29  *
30  * [tmp]
31  * path = /tmp
32  * vfs objects = full_audit
33  * full_audit:prefix = %u|%I
34  * full_audit:success = open opendir
35  * full_audit:failure = all
36  *
37  * vfs op can be "all" which means log all operations.
38  * vfs op can be "none" which means no logging.
39  *
40  * This leads to syslog entries of the form:
41  * smbd_audit: nobody|192.168.234.1|opendir|ok|.
42  * smbd_audit: nobody|192.168.234.1|open|fail (File not found)|r|x.txt
43  *
44  * where "nobody" is the connected username and "192.168.234.1" is the
45  * client's IP address. 
46  *
47  * Options:
48  *
49  * prefix: A macro expansion template prepended to the syslog entry.
50  *
51  * success: A list of VFS operations for which a successful completion should
52  * be logged. Defaults to no logging at all. The special operation "all" logs
53  * - you guessed it - everything.
54  *
55  * failure: A list of VFS operations for which failure to complete should be
56  * logged. Defaults to logging everything.
57  */
58
59
60 #include "includes.h"
61 #include "system/filesys.h"
62 #include "system/syslog.h"
63 #include "smbd/smbd.h"
64 #include "../librpc/gen_ndr/ndr_netlogon.h"
65 #include "auth.h"
66 #include "ntioctl.h"
67 #include "lib/param/loadparm.h"
68 #include "lib/util/bitmap.h"
69 #include "lib/util/tevent_unix.h"
70 #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                                       const struct smb2_create_blobs *in_context_blobs,
876                                       struct smb2_create_blobs *out_context_blobs)
877 {
878         NTSTATUS result;
879         const char* str_create_disposition;
880
881         switch (create_disposition) {
882         case FILE_SUPERSEDE:
883                 str_create_disposition = "supersede";
884                 break;
885         case FILE_OVERWRITE_IF:
886                 str_create_disposition = "overwrite_if";
887                 break;
888         case FILE_OPEN:
889                 str_create_disposition = "open";
890                 break;
891         case FILE_OVERWRITE:
892                 str_create_disposition = "overwrite";
893                 break;
894         case FILE_CREATE:
895                 str_create_disposition = "create";
896                 break;
897         case FILE_OPEN_IF:
898                 str_create_disposition = "open_if";
899                 break;
900         default:
901                 str_create_disposition = "unknown";
902         }
903
904         result = SMB_VFS_NEXT_CREATE_FILE(
905                 handle,                                 /* handle */
906                 req,                                    /* req */
907                 root_dir_fid,                           /* root_dir_fid */
908                 smb_fname,                              /* fname */
909                 access_mask,                            /* access_mask */
910                 share_access,                           /* share_access */
911                 create_disposition,                     /* create_disposition*/
912                 create_options,                         /* create_options */
913                 file_attributes,                        /* file_attributes */
914                 oplock_request,                         /* oplock_request */
915                 lease,                                  /* lease */
916                 allocation_size,                        /* allocation_size */
917                 private_flags,
918                 sd,                                     /* sd */
919                 ea_list,                                /* ea_list */
920                 result_fsp,                             /* result */
921                 pinfo,                                  /* pinfo */
922                 in_context_blobs, out_context_blobs);   /* create context */
923
924         do_log(SMB_VFS_OP_CREATE_FILE, (NT_STATUS_IS_OK(result)), handle,
925                "0x%x|%s|%s|%s", access_mask,
926                create_options & FILE_DIRECTORY_FILE ? "dir" : "file",
927                str_create_disposition, smb_fname_str_do_log(smb_fname));
928
929         return result;
930 }
931
932 static int smb_full_audit_close(vfs_handle_struct *handle, files_struct *fsp)
933 {
934         int result;
935         
936         result = SMB_VFS_NEXT_CLOSE(handle, fsp);
937
938         do_log(SMB_VFS_OP_CLOSE, (result >= 0), handle, "%s",
939                fsp_str_do_log(fsp));
940
941         return result;
942 }
943
944 static ssize_t smb_full_audit_read(vfs_handle_struct *handle, files_struct *fsp,
945                           void *data, size_t n)
946 {
947         ssize_t result;
948
949         result = SMB_VFS_NEXT_READ(handle, fsp, data, n);
950
951         do_log(SMB_VFS_OP_READ, (result >= 0), handle, "%s",
952                fsp_str_do_log(fsp));
953
954         return result;
955 }
956
957 static ssize_t smb_full_audit_pread(vfs_handle_struct *handle, files_struct *fsp,
958                            void *data, size_t n, off_t offset)
959 {
960         ssize_t result;
961
962         result = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
963
964         do_log(SMB_VFS_OP_PREAD, (result >= 0), handle, "%s",
965                fsp_str_do_log(fsp));
966
967         return result;
968 }
969
970 struct smb_full_audit_pread_state {
971         vfs_handle_struct *handle;
972         files_struct *fsp;
973         ssize_t ret;
974         int err;
975 };
976
977 static void smb_full_audit_pread_done(struct tevent_req *subreq);
978
979 static struct tevent_req *smb_full_audit_pread_send(
980         struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
981         struct tevent_context *ev, struct files_struct *fsp,
982         void *data, size_t n, off_t offset)
983 {
984         struct tevent_req *req, *subreq;
985         struct smb_full_audit_pread_state *state;
986
987         req = tevent_req_create(mem_ctx, &state,
988                                 struct smb_full_audit_pread_state);
989         if (req == NULL) {
990                 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
991                        fsp_str_do_log(fsp));
992                 return NULL;
993         }
994         state->handle = handle;
995         state->fsp = fsp;
996
997         subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
998                                          n, offset);
999         if (tevent_req_nomem(subreq, req)) {
1000                 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
1001                        fsp_str_do_log(fsp));
1002                 return tevent_req_post(req, ev);
1003         }
1004         tevent_req_set_callback(subreq, smb_full_audit_pread_done, req);
1005
1006         do_log(SMB_VFS_OP_PREAD_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1007         return req;
1008 }
1009
1010 static void smb_full_audit_pread_done(struct tevent_req *subreq)
1011 {
1012         struct tevent_req *req = tevent_req_callback_data(
1013                 subreq, struct tevent_req);
1014         struct smb_full_audit_pread_state *state = tevent_req_data(
1015                 req, struct smb_full_audit_pread_state);
1016
1017         state->ret = SMB_VFS_PREAD_RECV(subreq, &state->err);
1018         TALLOC_FREE(subreq);
1019         tevent_req_done(req);
1020 }
1021
1022 static ssize_t smb_full_audit_pread_recv(struct tevent_req *req, int *err)
1023 {
1024         struct smb_full_audit_pread_state *state = tevent_req_data(
1025                 req, struct smb_full_audit_pread_state);
1026
1027         if (tevent_req_is_unix_error(req, err)) {
1028                 do_log(SMB_VFS_OP_PREAD_RECV, false, state->handle, "%s",
1029                        fsp_str_do_log(state->fsp));
1030                 return -1;
1031         }
1032
1033         do_log(SMB_VFS_OP_PREAD_RECV, (state->ret >= 0), state->handle, "%s",
1034                fsp_str_do_log(state->fsp));
1035
1036         *err = state->err;
1037         return state->ret;
1038 }
1039
1040 static ssize_t smb_full_audit_write(vfs_handle_struct *handle, files_struct *fsp,
1041                            const void *data, size_t n)
1042 {
1043         ssize_t result;
1044
1045         result = SMB_VFS_NEXT_WRITE(handle, fsp, data, n);
1046
1047         do_log(SMB_VFS_OP_WRITE, (result >= 0), handle, "%s",
1048                fsp_str_do_log(fsp));
1049
1050         return result;
1051 }
1052
1053 static ssize_t smb_full_audit_pwrite(vfs_handle_struct *handle, files_struct *fsp,
1054                             const void *data, size_t n,
1055                             off_t offset)
1056 {
1057         ssize_t result;
1058
1059         result = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
1060
1061         do_log(SMB_VFS_OP_PWRITE, (result >= 0), handle, "%s",
1062                fsp_str_do_log(fsp));
1063
1064         return result;
1065 }
1066
1067 struct smb_full_audit_pwrite_state {
1068         vfs_handle_struct *handle;
1069         files_struct *fsp;
1070         ssize_t ret;
1071         int err;
1072 };
1073
1074 static void smb_full_audit_pwrite_done(struct tevent_req *subreq);
1075
1076 static struct tevent_req *smb_full_audit_pwrite_send(
1077         struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1078         struct tevent_context *ev, struct files_struct *fsp,
1079         const void *data, size_t n, off_t offset)
1080 {
1081         struct tevent_req *req, *subreq;
1082         struct smb_full_audit_pwrite_state *state;
1083
1084         req = tevent_req_create(mem_ctx, &state,
1085                                 struct smb_full_audit_pwrite_state);
1086         if (req == NULL) {
1087                 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1088                        fsp_str_do_log(fsp));
1089                 return NULL;
1090         }
1091         state->handle = handle;
1092         state->fsp = fsp;
1093
1094         subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
1095                                          n, offset);
1096         if (tevent_req_nomem(subreq, req)) {
1097                 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1098                        fsp_str_do_log(fsp));
1099                 return tevent_req_post(req, ev);
1100         }
1101         tevent_req_set_callback(subreq, smb_full_audit_pwrite_done, req);
1102
1103         do_log(SMB_VFS_OP_PWRITE_SEND, true, handle, "%s",
1104                fsp_str_do_log(fsp));
1105         return req;
1106 }
1107
1108 static void smb_full_audit_pwrite_done(struct tevent_req *subreq)
1109 {
1110         struct tevent_req *req = tevent_req_callback_data(
1111                 subreq, struct tevent_req);
1112         struct smb_full_audit_pwrite_state *state = tevent_req_data(
1113                 req, struct smb_full_audit_pwrite_state);
1114
1115         state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->err);
1116         TALLOC_FREE(subreq);
1117         tevent_req_done(req);
1118 }
1119
1120 static ssize_t smb_full_audit_pwrite_recv(struct tevent_req *req, int *err)
1121 {
1122         struct smb_full_audit_pwrite_state *state = tevent_req_data(
1123                 req, struct smb_full_audit_pwrite_state);
1124
1125         if (tevent_req_is_unix_error(req, err)) {
1126                 do_log(SMB_VFS_OP_PWRITE_RECV, false, state->handle, "%s",
1127                        fsp_str_do_log(state->fsp));
1128                 return -1;
1129         }
1130
1131         do_log(SMB_VFS_OP_PWRITE_RECV, (state->ret >= 0), state->handle, "%s",
1132                fsp_str_do_log(state->fsp));
1133
1134         *err = state->err;
1135         return state->ret;
1136 }
1137
1138 static off_t smb_full_audit_lseek(vfs_handle_struct *handle, files_struct *fsp,
1139                              off_t offset, int whence)
1140 {
1141         ssize_t result;
1142
1143         result = SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence);
1144
1145         do_log(SMB_VFS_OP_LSEEK, (result != (ssize_t)-1), handle,
1146                "%s", fsp_str_do_log(fsp));
1147
1148         return result;
1149 }
1150
1151 static ssize_t smb_full_audit_sendfile(vfs_handle_struct *handle, int tofd,
1152                               files_struct *fromfsp,
1153                               const DATA_BLOB *hdr, off_t offset,
1154                               size_t n)
1155 {
1156         ssize_t result;
1157
1158         result = SMB_VFS_NEXT_SENDFILE(handle, tofd, fromfsp, hdr, offset, n);
1159
1160         do_log(SMB_VFS_OP_SENDFILE, (result >= 0), handle,
1161                "%s", fsp_str_do_log(fromfsp));
1162
1163         return result;
1164 }
1165
1166 static ssize_t smb_full_audit_recvfile(vfs_handle_struct *handle, int fromfd,
1167                       files_struct *tofsp,
1168                               off_t offset,
1169                               size_t n)
1170 {
1171         ssize_t result;
1172
1173         result = SMB_VFS_NEXT_RECVFILE(handle, fromfd, tofsp, offset, n);
1174
1175         do_log(SMB_VFS_OP_RECVFILE, (result >= 0), handle,
1176                "%s", fsp_str_do_log(tofsp));
1177
1178         return result;
1179 }
1180
1181 static int smb_full_audit_rename(vfs_handle_struct *handle,
1182                                  const struct smb_filename *smb_fname_src,
1183                                  const struct smb_filename *smb_fname_dst)
1184 {
1185         int result;
1186         
1187         result = SMB_VFS_NEXT_RENAME(handle, smb_fname_src, smb_fname_dst);
1188
1189         do_log(SMB_VFS_OP_RENAME, (result >= 0), handle, "%s|%s",
1190                smb_fname_str_do_log(smb_fname_src),
1191                smb_fname_str_do_log(smb_fname_dst));
1192
1193         return result;    
1194 }
1195
1196 static int smb_full_audit_fsync(vfs_handle_struct *handle, files_struct *fsp)
1197 {
1198         int result;
1199         
1200         result = SMB_VFS_NEXT_FSYNC(handle, fsp);
1201
1202         do_log(SMB_VFS_OP_FSYNC, (result >= 0), handle, "%s",
1203                fsp_str_do_log(fsp));
1204
1205         return result;    
1206 }
1207
1208 struct smb_full_audit_fsync_state {
1209         vfs_handle_struct *handle;
1210         files_struct *fsp;
1211         int ret;
1212         int err;
1213 };
1214
1215 static void smb_full_audit_fsync_done(struct tevent_req *subreq);
1216
1217 static struct tevent_req *smb_full_audit_fsync_send(
1218         struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1219         struct tevent_context *ev, struct files_struct *fsp)
1220 {
1221         struct tevent_req *req, *subreq;
1222         struct smb_full_audit_fsync_state *state;
1223
1224         req = tevent_req_create(mem_ctx, &state,
1225                                 struct smb_full_audit_fsync_state);
1226         if (req == NULL) {
1227                 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1228                        fsp_str_do_log(fsp));
1229                 return NULL;
1230         }
1231         state->handle = handle;
1232         state->fsp = fsp;
1233
1234         subreq = SMB_VFS_NEXT_FSYNC_SEND(state, ev, handle, fsp);
1235         if (tevent_req_nomem(subreq, req)) {
1236                 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1237                        fsp_str_do_log(fsp));
1238                 return tevent_req_post(req, ev);
1239         }
1240         tevent_req_set_callback(subreq, smb_full_audit_fsync_done, req);
1241
1242         do_log(SMB_VFS_OP_FSYNC_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1243         return req;
1244 }
1245
1246 static void smb_full_audit_fsync_done(struct tevent_req *subreq)
1247 {
1248         struct tevent_req *req = tevent_req_callback_data(
1249                 subreq, struct tevent_req);
1250         struct smb_full_audit_fsync_state *state = tevent_req_data(
1251                 req, struct smb_full_audit_fsync_state);
1252
1253         state->ret = SMB_VFS_FSYNC_RECV(subreq, &state->err);
1254         TALLOC_FREE(subreq);
1255         tevent_req_done(req);
1256 }
1257
1258 static int smb_full_audit_fsync_recv(struct tevent_req *req, int *err)
1259 {
1260         struct smb_full_audit_fsync_state *state = tevent_req_data(
1261                 req, struct smb_full_audit_fsync_state);
1262
1263         if (tevent_req_is_unix_error(req, err)) {
1264                 do_log(SMB_VFS_OP_FSYNC_RECV, false, state->handle, "%s",
1265                        fsp_str_do_log(state->fsp));
1266                 return -1;
1267         }
1268
1269         do_log(SMB_VFS_OP_FSYNC_RECV, (state->ret >= 0), state->handle, "%s",
1270                fsp_str_do_log(state->fsp));
1271
1272         *err = state->err;
1273         return state->ret;
1274 }
1275
1276 static int smb_full_audit_stat(vfs_handle_struct *handle,
1277                                struct smb_filename *smb_fname)
1278 {
1279         int result;
1280         
1281         result = SMB_VFS_NEXT_STAT(handle, smb_fname);
1282
1283         do_log(SMB_VFS_OP_STAT, (result >= 0), handle, "%s",
1284                smb_fname_str_do_log(smb_fname));
1285
1286         return result;    
1287 }
1288
1289 static int smb_full_audit_fstat(vfs_handle_struct *handle, files_struct *fsp,
1290                        SMB_STRUCT_STAT *sbuf)
1291 {
1292         int result;
1293         
1294         result = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1295
1296         do_log(SMB_VFS_OP_FSTAT, (result >= 0), handle, "%s",
1297                fsp_str_do_log(fsp));
1298
1299         return result;
1300 }
1301
1302 static int smb_full_audit_lstat(vfs_handle_struct *handle,
1303                                 struct smb_filename *smb_fname)
1304 {
1305         int result;
1306         
1307         result = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
1308
1309         do_log(SMB_VFS_OP_LSTAT, (result >= 0), handle, "%s",
1310                smb_fname_str_do_log(smb_fname));
1311
1312         return result;    
1313 }
1314
1315 static uint64_t smb_full_audit_get_alloc_size(vfs_handle_struct *handle,
1316                        files_struct *fsp, const SMB_STRUCT_STAT *sbuf)
1317 {
1318         uint64_t result;
1319
1320         result = SMB_VFS_NEXT_GET_ALLOC_SIZE(handle, fsp, sbuf);
1321
1322         do_log(SMB_VFS_OP_GET_ALLOC_SIZE, (result != (uint64_t)-1), handle,
1323                         "%llu", result);
1324
1325         return result;
1326 }
1327
1328 static int smb_full_audit_unlink(vfs_handle_struct *handle,
1329                                  const struct smb_filename *smb_fname)
1330 {
1331         int result;
1332         
1333         result = SMB_VFS_NEXT_UNLINK(handle, smb_fname);
1334
1335         do_log(SMB_VFS_OP_UNLINK, (result >= 0), handle, "%s",
1336                smb_fname_str_do_log(smb_fname));
1337
1338         return result;
1339 }
1340
1341 static int smb_full_audit_chmod(vfs_handle_struct *handle,
1342                        const char *path, mode_t mode)
1343 {
1344         int result;
1345
1346         result = SMB_VFS_NEXT_CHMOD(handle, path, mode);
1347
1348         do_log(SMB_VFS_OP_CHMOD, (result >= 0), handle, "%s|%o", path, mode);
1349
1350         return result;
1351 }
1352
1353 static int smb_full_audit_fchmod(vfs_handle_struct *handle, files_struct *fsp,
1354                         mode_t mode)
1355 {
1356         int result;
1357         
1358         result = SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1359
1360         do_log(SMB_VFS_OP_FCHMOD, (result >= 0), handle,
1361                "%s|%o", fsp_str_do_log(fsp), mode);
1362
1363         return result;
1364 }
1365
1366 static int smb_full_audit_chown(vfs_handle_struct *handle,
1367                        const char *path, uid_t uid, gid_t gid)
1368 {
1369         int result;
1370
1371         result = SMB_VFS_NEXT_CHOWN(handle, path, uid, gid);
1372
1373         do_log(SMB_VFS_OP_CHOWN, (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_fchown(vfs_handle_struct *handle, files_struct *fsp,
1380                         uid_t uid, gid_t gid)
1381 {
1382         int result;
1383
1384         result = SMB_VFS_NEXT_FCHOWN(handle, fsp, uid, gid);
1385
1386         do_log(SMB_VFS_OP_FCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1387                fsp_str_do_log(fsp), (long int)uid, (long int)gid);
1388
1389         return result;
1390 }
1391
1392 static int smb_full_audit_lchown(vfs_handle_struct *handle,
1393                        const char *path, uid_t uid, gid_t gid)
1394 {
1395         int result;
1396
1397         result = SMB_VFS_NEXT_LCHOWN(handle, path, uid, gid);
1398
1399         do_log(SMB_VFS_OP_LCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1400                path, (long int)uid, (long int)gid);
1401
1402         return result;
1403 }
1404
1405 static int smb_full_audit_chdir(vfs_handle_struct *handle,
1406                        const char *path)
1407 {
1408         int result;
1409
1410         result = SMB_VFS_NEXT_CHDIR(handle, path);
1411
1412         do_log(SMB_VFS_OP_CHDIR, (result >= 0), handle, "chdir|%s", path);
1413
1414         return result;
1415 }
1416
1417 static char *smb_full_audit_getwd(vfs_handle_struct *handle)
1418 {
1419         char *result;
1420
1421         result = SMB_VFS_NEXT_GETWD(handle);
1422         
1423         do_log(SMB_VFS_OP_GETWD, (result != NULL), handle, "%s",
1424                 result == NULL? "" : result);
1425
1426         return result;
1427 }
1428
1429 static int smb_full_audit_ntimes(vfs_handle_struct *handle,
1430                                  const struct smb_filename *smb_fname,
1431                                  struct smb_file_time *ft)
1432 {
1433         int result;
1434
1435         result = SMB_VFS_NEXT_NTIMES(handle, smb_fname, ft);
1436
1437         do_log(SMB_VFS_OP_NTIMES, (result >= 0), handle, "%s",
1438                smb_fname_str_do_log(smb_fname));
1439
1440         return result;
1441 }
1442
1443 static int smb_full_audit_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
1444                            off_t len)
1445 {
1446         int result;
1447
1448         result = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1449
1450         do_log(SMB_VFS_OP_FTRUNCATE, (result >= 0), handle,
1451                "%s", fsp_str_do_log(fsp));
1452
1453         return result;
1454 }
1455
1456 static int smb_full_audit_fallocate(vfs_handle_struct *handle, files_struct *fsp,
1457                            enum vfs_fallocate_mode mode,
1458                            off_t offset,
1459                            off_t len)
1460 {
1461         int result;
1462
1463         result = SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
1464
1465         do_log(SMB_VFS_OP_FALLOCATE, (result >= 0), handle,
1466                "%s", fsp_str_do_log(fsp));
1467
1468         return result;
1469 }
1470
1471 static bool smb_full_audit_lock(vfs_handle_struct *handle, files_struct *fsp,
1472                        int op, off_t offset, off_t count, int type)
1473 {
1474         bool result;
1475
1476         result = SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type);
1477
1478         do_log(SMB_VFS_OP_LOCK, result, handle, "%s", fsp_str_do_log(fsp));
1479
1480         return result;
1481 }
1482
1483 static int smb_full_audit_kernel_flock(struct vfs_handle_struct *handle,
1484                                        struct files_struct *fsp,
1485                                        uint32 share_mode, uint32 access_mask)
1486 {
1487         int result;
1488
1489         result = SMB_VFS_NEXT_KERNEL_FLOCK(handle, fsp, share_mode, access_mask);
1490
1491         do_log(SMB_VFS_OP_KERNEL_FLOCK, (result >= 0), handle, "%s",
1492                fsp_str_do_log(fsp));
1493
1494         return result;
1495 }
1496
1497 static int smb_full_audit_linux_setlease(vfs_handle_struct *handle, files_struct *fsp,
1498                                  int leasetype)
1499 {
1500         int result;
1501
1502         result = SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
1503
1504         do_log(SMB_VFS_OP_LINUX_SETLEASE, (result >= 0), handle, "%s",
1505                fsp_str_do_log(fsp));
1506
1507         return result;
1508 }
1509
1510 static bool smb_full_audit_getlock(vfs_handle_struct *handle, files_struct *fsp,
1511                        off_t *poffset, off_t *pcount, int *ptype, pid_t *ppid)
1512 {
1513         bool result;
1514
1515         result = SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype, ppid);
1516
1517         do_log(SMB_VFS_OP_GETLOCK, result, handle, "%s", fsp_str_do_log(fsp));
1518
1519         return result;
1520 }
1521
1522 static int smb_full_audit_symlink(vfs_handle_struct *handle,
1523                          const char *oldpath, const char *newpath)
1524 {
1525         int result;
1526
1527         result = SMB_VFS_NEXT_SYMLINK(handle, oldpath, newpath);
1528
1529         do_log(SMB_VFS_OP_SYMLINK, (result >= 0), handle,
1530                "%s|%s", oldpath, newpath);
1531
1532         return result;
1533 }
1534
1535 static int smb_full_audit_readlink(vfs_handle_struct *handle,
1536                           const char *path, char *buf, size_t bufsiz)
1537 {
1538         int result;
1539
1540         result = SMB_VFS_NEXT_READLINK(handle, path, buf, bufsiz);
1541
1542         do_log(SMB_VFS_OP_READLINK, (result >= 0), handle, "%s", path);
1543
1544         return result;
1545 }
1546
1547 static int smb_full_audit_link(vfs_handle_struct *handle,
1548                       const char *oldpath, const char *newpath)
1549 {
1550         int result;
1551
1552         result = SMB_VFS_NEXT_LINK(handle, oldpath, newpath);
1553
1554         do_log(SMB_VFS_OP_LINK, (result >= 0), handle,
1555                "%s|%s", oldpath, newpath);
1556
1557         return result;
1558 }
1559
1560 static int smb_full_audit_mknod(vfs_handle_struct *handle,
1561                        const char *pathname, mode_t mode, SMB_DEV_T dev)
1562 {
1563         int result;
1564
1565         result = SMB_VFS_NEXT_MKNOD(handle, pathname, mode, dev);
1566
1567         do_log(SMB_VFS_OP_MKNOD, (result >= 0), handle, "%s", pathname);
1568
1569         return result;
1570 }
1571
1572 static char *smb_full_audit_realpath(vfs_handle_struct *handle,
1573                             const char *path)
1574 {
1575         char *result;
1576
1577         result = SMB_VFS_NEXT_REALPATH(handle, path);
1578
1579         do_log(SMB_VFS_OP_REALPATH, (result != NULL), handle, "%s", path);
1580
1581         return result;
1582 }
1583
1584 static NTSTATUS smb_full_audit_notify_watch(struct vfs_handle_struct *handle,
1585                         struct sys_notify_context *ctx,
1586                         const char *path,
1587                         uint32_t *filter,
1588                         uint32_t *subdir_filter,
1589                         void (*callback)(struct sys_notify_context *ctx,
1590                                         void *private_data,
1591                                         struct notify_event *ev),
1592                         void *private_data, void *handle_p)
1593 {
1594         NTSTATUS result;
1595
1596         result = SMB_VFS_NEXT_NOTIFY_WATCH(handle, ctx, path,
1597                                            filter, subdir_filter, callback,
1598                                            private_data, handle_p);
1599
1600         do_log(SMB_VFS_OP_NOTIFY_WATCH, NT_STATUS_IS_OK(result), handle, "");
1601
1602         return result;
1603 }
1604
1605 static int smb_full_audit_chflags(vfs_handle_struct *handle,
1606                             const char *path, unsigned int flags)
1607 {
1608         int result;
1609
1610         result = SMB_VFS_NEXT_CHFLAGS(handle, path, flags);
1611
1612         do_log(SMB_VFS_OP_CHFLAGS, (result != 0), handle, "%s", path);
1613
1614         return result;
1615 }
1616
1617 static struct file_id smb_full_audit_file_id_create(struct vfs_handle_struct *handle,
1618                                                     const SMB_STRUCT_STAT *sbuf)
1619 {
1620         struct file_id id_zero;
1621         struct file_id result;
1622
1623         ZERO_STRUCT(id_zero);
1624
1625         result = SMB_VFS_NEXT_FILE_ID_CREATE(handle, sbuf);
1626
1627         do_log(SMB_VFS_OP_FILE_ID_CREATE,
1628                !file_id_equal(&id_zero, &result),
1629                handle, "%s", file_id_string_tos(&result));
1630
1631         return result;
1632 }
1633
1634 static NTSTATUS smb_full_audit_streaminfo(vfs_handle_struct *handle,
1635                                           struct files_struct *fsp,
1636                                           const char *fname,
1637                                           TALLOC_CTX *mem_ctx,
1638                                           unsigned int *pnum_streams,
1639                                           struct stream_struct **pstreams)
1640 {
1641         NTSTATUS result;
1642
1643         result = SMB_VFS_NEXT_STREAMINFO(handle, fsp, fname, mem_ctx,
1644                                          pnum_streams, pstreams);
1645
1646         do_log(SMB_VFS_OP_STREAMINFO, NT_STATUS_IS_OK(result), handle,
1647                "%s", fname);
1648
1649         return result;
1650 }
1651
1652 static int smb_full_audit_get_real_filename(struct vfs_handle_struct *handle,
1653                                             const char *path,
1654                                             const char *name,
1655                                             TALLOC_CTX *mem_ctx,
1656                                             char **found_name)
1657 {
1658         int result;
1659
1660         result = SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name, mem_ctx,
1661                                                 found_name);
1662
1663         do_log(SMB_VFS_OP_GET_REAL_FILENAME, (result == 0), handle,
1664                "%s/%s->%s", path, name, (result == 0) ? "" : *found_name);
1665
1666         return result;
1667 }
1668
1669 static const char *smb_full_audit_connectpath(vfs_handle_struct *handle,
1670                                               const char *fname)
1671 {
1672         const char *result;
1673
1674         result = SMB_VFS_NEXT_CONNECTPATH(handle, fname);
1675
1676         do_log(SMB_VFS_OP_CONNECTPATH, result != NULL, handle,
1677                "%s", fname);
1678
1679         return result;
1680 }
1681
1682 static NTSTATUS smb_full_audit_brl_lock_windows(struct vfs_handle_struct *handle,
1683                                                 struct byte_range_lock *br_lck,
1684                                                 struct lock_struct *plock,
1685                                                 bool blocking_lock)
1686 {
1687         NTSTATUS result;
1688
1689         result = SMB_VFS_NEXT_BRL_LOCK_WINDOWS(handle, br_lck, plock,
1690                                                blocking_lock);
1691
1692         do_log(SMB_VFS_OP_BRL_LOCK_WINDOWS, NT_STATUS_IS_OK(result), handle,
1693             "%s:%llu-%llu. type=%d. blocking=%d",
1694                fsp_str_do_log(brl_fsp(br_lck)),
1695             plock->start, plock->size, plock->lock_type, blocking_lock);
1696
1697         return result;
1698 }
1699
1700 static bool smb_full_audit_brl_unlock_windows(struct vfs_handle_struct *handle,
1701                                               struct messaging_context *msg_ctx,
1702                                               struct byte_range_lock *br_lck,
1703                                               const struct lock_struct *plock)
1704 {
1705         bool result;
1706
1707         result = SMB_VFS_NEXT_BRL_UNLOCK_WINDOWS(handle, msg_ctx, br_lck,
1708             plock);
1709
1710         do_log(SMB_VFS_OP_BRL_UNLOCK_WINDOWS, (result == 0), handle,
1711                "%s:%llu-%llu:%d", fsp_str_do_log(brl_fsp(br_lck)),
1712                plock->start,
1713             plock->size, plock->lock_type);
1714
1715         return result;
1716 }
1717
1718 static bool smb_full_audit_brl_cancel_windows(struct vfs_handle_struct *handle,
1719                                               struct byte_range_lock *br_lck,
1720                                               struct lock_struct *plock)
1721 {
1722         bool result;
1723
1724         result = SMB_VFS_NEXT_BRL_CANCEL_WINDOWS(handle, br_lck, plock);
1725
1726         do_log(SMB_VFS_OP_BRL_CANCEL_WINDOWS, (result == 0), handle,
1727                "%s:%llu-%llu:%d", fsp_str_do_log(brl_fsp(br_lck)),
1728                plock->start,
1729             plock->size, plock->lock_type);
1730
1731         return result;
1732 }
1733
1734 static bool smb_full_audit_strict_lock(struct vfs_handle_struct *handle,
1735                                        struct files_struct *fsp,
1736                                        struct lock_struct *plock)
1737 {
1738         bool result;
1739
1740         result = SMB_VFS_NEXT_STRICT_LOCK(handle, fsp, plock);
1741
1742         do_log(SMB_VFS_OP_STRICT_LOCK, result, handle,
1743             "%s:%llu-%llu:%d", fsp_str_do_log(fsp), plock->start,
1744             plock->size, plock->lock_type);
1745
1746         return result;
1747 }
1748
1749 static void smb_full_audit_strict_unlock(struct vfs_handle_struct *handle,
1750                                          struct files_struct *fsp,
1751                                          struct lock_struct *plock)
1752 {
1753         SMB_VFS_NEXT_STRICT_UNLOCK(handle, fsp, plock);
1754
1755         do_log(SMB_VFS_OP_STRICT_UNLOCK, true, handle,
1756             "%s:%llu-%llu:%d", fsp_str_do_log(fsp), plock->start,
1757             plock->size, plock->lock_type);
1758 }
1759
1760 static NTSTATUS smb_full_audit_translate_name(struct vfs_handle_struct *handle,
1761                                               const char *name,
1762                                               enum vfs_translate_direction direction,
1763                                               TALLOC_CTX *mem_ctx,
1764                                               char **mapped_name)
1765 {
1766         NTSTATUS result;
1767
1768         result = SMB_VFS_NEXT_TRANSLATE_NAME(handle, name, direction, mem_ctx,
1769                                              mapped_name);
1770
1771         do_log(SMB_VFS_OP_TRANSLATE_NAME, NT_STATUS_IS_OK(result), handle, "");
1772
1773         return result;
1774 }
1775
1776 static struct tevent_req *smb_full_audit_copy_chunk_send(struct vfs_handle_struct *handle,
1777                                                          TALLOC_CTX *mem_ctx,
1778                                                          struct tevent_context *ev,
1779                                                          struct files_struct *src_fsp,
1780                                                          off_t src_off,
1781                                                          struct files_struct *dest_fsp,
1782                                                          off_t dest_off,
1783                                                          off_t num)
1784 {
1785         struct tevent_req *req;
1786
1787         req = SMB_VFS_NEXT_COPY_CHUNK_SEND(handle, mem_ctx, ev, src_fsp,
1788                                            src_off, dest_fsp, dest_off, num);
1789
1790         do_log(SMB_VFS_OP_COPY_CHUNK_SEND, req, handle, "");
1791
1792         return req;
1793 }
1794
1795 static NTSTATUS smb_full_audit_copy_chunk_recv(struct vfs_handle_struct *handle,
1796                                                struct tevent_req *req,
1797                                                off_t *copied)
1798 {
1799         NTSTATUS result;
1800
1801         result = SMB_VFS_NEXT_COPY_CHUNK_RECV(handle, req, copied);
1802
1803         do_log(SMB_VFS_OP_COPY_CHUNK_RECV, NT_STATUS_IS_OK(result), handle, "");
1804
1805         return result;
1806 }
1807
1808 static NTSTATUS smb_full_audit_get_compression(vfs_handle_struct *handle,
1809                                                TALLOC_CTX *mem_ctx,
1810                                                struct files_struct *fsp,
1811                                                struct smb_filename *smb_fname,
1812                                                uint16_t *_compression_fmt)
1813 {
1814         NTSTATUS result;
1815
1816         result = SMB_VFS_NEXT_GET_COMPRESSION(handle, mem_ctx, fsp, smb_fname,
1817                                               _compression_fmt);
1818
1819         do_log(SMB_VFS_OP_GET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
1820                "%s",
1821                (fsp ? fsp_str_do_log(fsp) : smb_fname_str_do_log(smb_fname)));
1822
1823         return result;
1824 }
1825
1826 static NTSTATUS smb_full_audit_set_compression(vfs_handle_struct *handle,
1827                                                TALLOC_CTX *mem_ctx,
1828                                                struct files_struct *fsp,
1829                                                uint16_t compression_fmt)
1830 {
1831         NTSTATUS result;
1832
1833         result = SMB_VFS_NEXT_SET_COMPRESSION(handle, mem_ctx, fsp,
1834                                               compression_fmt);
1835
1836         do_log(SMB_VFS_OP_SET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
1837                "%s", fsp_str_do_log(fsp));
1838
1839         return result;
1840 }
1841
1842 static NTSTATUS smb_full_audit_readdir_attr(struct vfs_handle_struct *handle,
1843                                             const struct smb_filename *fname,
1844                                             TALLOC_CTX *mem_ctx,
1845                                             struct readdir_attr_data **pattr_data)
1846 {
1847         NTSTATUS status;
1848
1849         status = SMB_VFS_NEXT_READDIR_ATTR(handle, fname, mem_ctx, pattr_data);
1850
1851         do_log(SMB_VFS_OP_READDIR_ATTR, NT_STATUS_IS_OK(status), handle, "%s",
1852                smb_fname_str_do_log(fname));
1853
1854         return status;
1855 }
1856
1857 static NTSTATUS smb_full_audit_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
1858                                            uint32 security_info,
1859                                            TALLOC_CTX *mem_ctx,
1860                                            struct security_descriptor **ppdesc)
1861 {
1862         NTSTATUS result;
1863
1864         result = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
1865                                           mem_ctx, ppdesc);
1866
1867         do_log(SMB_VFS_OP_FGET_NT_ACL, NT_STATUS_IS_OK(result), handle,
1868                "%s", fsp_str_do_log(fsp));
1869
1870         return result;
1871 }
1872
1873 static NTSTATUS smb_full_audit_get_nt_acl(vfs_handle_struct *handle,
1874                                           const char *name,
1875                                           uint32 security_info,
1876                                           TALLOC_CTX *mem_ctx,
1877                                           struct security_descriptor **ppdesc)
1878 {
1879         NTSTATUS result;
1880
1881         result = SMB_VFS_NEXT_GET_NT_ACL(handle, name, security_info,
1882                                          mem_ctx, ppdesc);
1883
1884         do_log(SMB_VFS_OP_GET_NT_ACL, NT_STATUS_IS_OK(result), handle,
1885                "%s", name);
1886
1887         return result;
1888 }
1889
1890 static NTSTATUS smb_full_audit_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
1891                               uint32 security_info_sent,
1892                               const struct security_descriptor *psd)
1893 {
1894         struct vfs_full_audit_private_data *pd;
1895         NTSTATUS result;
1896         char *sd = NULL;
1897
1898         SMB_VFS_HANDLE_GET_DATA(handle, pd,
1899                                 struct vfs_full_audit_private_data,
1900                                 return NT_STATUS_INTERNAL_ERROR);
1901
1902         if (pd->log_secdesc) {
1903                 sd = sddl_encode(talloc_tos(), psd, get_global_sam_sid());
1904         }
1905
1906         result = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
1907
1908         do_log(SMB_VFS_OP_FSET_NT_ACL, NT_STATUS_IS_OK(result), handle,
1909                "%s [%s]", fsp_str_do_log(fsp), sd ? sd : "");
1910
1911         TALLOC_FREE(sd);
1912
1913         return result;
1914 }
1915
1916 static int smb_full_audit_chmod_acl(vfs_handle_struct *handle,
1917                            const char *path, mode_t mode)
1918 {
1919         int result;
1920         
1921         result = SMB_VFS_NEXT_CHMOD_ACL(handle, path, mode);
1922
1923         do_log(SMB_VFS_OP_CHMOD_ACL, (result >= 0), handle,
1924                "%s|%o", path, mode);
1925
1926         return result;
1927 }
1928
1929 static int smb_full_audit_fchmod_acl(vfs_handle_struct *handle, files_struct *fsp,
1930                                      mode_t mode)
1931 {
1932         int result;
1933         
1934         result = SMB_VFS_NEXT_FCHMOD_ACL(handle, fsp, mode);
1935
1936         do_log(SMB_VFS_OP_FCHMOD_ACL, (result >= 0), handle,
1937                "%s|%o", fsp_str_do_log(fsp), mode);
1938
1939         return result;
1940 }
1941
1942 static SMB_ACL_T smb_full_audit_sys_acl_get_file(vfs_handle_struct *handle,
1943                                         const char *path_p,
1944                                                  SMB_ACL_TYPE_T type,
1945                                                  TALLOC_CTX *mem_ctx)
1946 {
1947         SMB_ACL_T result;
1948
1949         result = SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, path_p, type, mem_ctx);
1950
1951         do_log(SMB_VFS_OP_SYS_ACL_GET_FILE, (result != NULL), handle,
1952                "%s", path_p);
1953
1954         return result;
1955 }
1956
1957 static SMB_ACL_T smb_full_audit_sys_acl_get_fd(vfs_handle_struct *handle,
1958                                                files_struct *fsp, TALLOC_CTX *mem_ctx)
1959 {
1960         SMB_ACL_T result;
1961
1962         result = SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp, mem_ctx);
1963
1964         do_log(SMB_VFS_OP_SYS_ACL_GET_FD, (result != NULL), handle,
1965                "%s", fsp_str_do_log(fsp));
1966
1967         return result;
1968 }
1969
1970 static int smb_full_audit_sys_acl_blob_get_file(vfs_handle_struct *handle,
1971                                                 const char *path_p,
1972                                                 TALLOC_CTX *mem_ctx,
1973                                                 char **blob_description,
1974                                                 DATA_BLOB *blob)
1975 {
1976         int result;
1977
1978         result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FILE(handle, path_p, mem_ctx, blob_description, blob);
1979
1980         do_log(SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE, (result >= 0), handle,
1981                "%s", path_p);
1982
1983         return result;
1984 }
1985
1986 static int smb_full_audit_sys_acl_blob_get_fd(vfs_handle_struct *handle,
1987                                               files_struct *fsp,
1988                                               TALLOC_CTX *mem_ctx,
1989                                               char **blob_description,
1990                                               DATA_BLOB *blob)
1991 {
1992         int result;
1993
1994         result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle, fsp, mem_ctx, blob_description, blob);
1995
1996         do_log(SMB_VFS_OP_SYS_ACL_BLOB_GET_FD, (result >= 0), handle,
1997                "%s", fsp_str_do_log(fsp));
1998
1999         return result;
2000 }
2001
2002 static int smb_full_audit_sys_acl_set_file(vfs_handle_struct *handle,
2003
2004                                   const char *name, SMB_ACL_TYPE_T acltype,
2005                                   SMB_ACL_T theacl)
2006 {
2007         int result;
2008
2009         result = SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, name, acltype,
2010                                                theacl);
2011
2012         do_log(SMB_VFS_OP_SYS_ACL_SET_FILE, (result >= 0), handle,
2013                "%s", name);
2014
2015         return result;
2016 }
2017
2018 static int smb_full_audit_sys_acl_set_fd(vfs_handle_struct *handle, files_struct *fsp,
2019                                 SMB_ACL_T theacl)
2020 {
2021         int result;
2022
2023         result = SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, theacl);
2024
2025         do_log(SMB_VFS_OP_SYS_ACL_SET_FD, (result >= 0), handle,
2026                "%s", fsp_str_do_log(fsp));
2027
2028         return result;
2029 }
2030
2031 static int smb_full_audit_sys_acl_delete_def_file(vfs_handle_struct *handle,
2032
2033                                          const char *path)
2034 {
2035         int result;
2036
2037         result = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, path);
2038
2039         do_log(SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE, (result >= 0), handle,
2040                "%s", path);
2041
2042         return result;
2043 }
2044
2045 static ssize_t smb_full_audit_getxattr(struct vfs_handle_struct *handle,
2046                               const char *path,
2047                               const char *name, void *value, size_t size)
2048 {
2049         ssize_t result;
2050
2051         result = SMB_VFS_NEXT_GETXATTR(handle, path, name, value, size);
2052
2053         do_log(SMB_VFS_OP_GETXATTR, (result >= 0), handle,
2054                "%s|%s", path, name);
2055
2056         return result;
2057 }
2058
2059 static ssize_t smb_full_audit_fgetxattr(struct vfs_handle_struct *handle,
2060                                struct files_struct *fsp,
2061                                const char *name, void *value, size_t size)
2062 {
2063         ssize_t result;
2064
2065         result = SMB_VFS_NEXT_FGETXATTR(handle, fsp, name, value, size);
2066
2067         do_log(SMB_VFS_OP_FGETXATTR, (result >= 0), handle,
2068                "%s|%s", fsp_str_do_log(fsp), name);
2069
2070         return result;
2071 }
2072
2073 static ssize_t smb_full_audit_listxattr(struct vfs_handle_struct *handle,
2074                                const char *path, char *list, size_t size)
2075 {
2076         ssize_t result;
2077
2078         result = SMB_VFS_NEXT_LISTXATTR(handle, path, list, size);
2079
2080         do_log(SMB_VFS_OP_LISTXATTR, (result >= 0), handle, "%s", path);
2081
2082         return result;
2083 }
2084
2085 static ssize_t smb_full_audit_flistxattr(struct vfs_handle_struct *handle,
2086                                 struct files_struct *fsp, char *list,
2087                                 size_t size)
2088 {
2089         ssize_t result;
2090
2091         result = SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
2092
2093         do_log(SMB_VFS_OP_FLISTXATTR, (result >= 0), handle,
2094                "%s", fsp_str_do_log(fsp));
2095
2096         return result;
2097 }
2098
2099 static int smb_full_audit_removexattr(struct vfs_handle_struct *handle,
2100                              const char *path,
2101                              const char *name)
2102 {
2103         int result;
2104
2105         result = SMB_VFS_NEXT_REMOVEXATTR(handle, path, name);
2106
2107         do_log(SMB_VFS_OP_REMOVEXATTR, (result >= 0), handle,
2108                "%s|%s", path, name);
2109
2110         return result;
2111 }
2112
2113 static int smb_full_audit_fremovexattr(struct vfs_handle_struct *handle,
2114                               struct files_struct *fsp,
2115                               const char *name)
2116 {
2117         int result;
2118
2119         result = SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, name);
2120
2121         do_log(SMB_VFS_OP_FREMOVEXATTR, (result >= 0), handle,
2122                "%s|%s", fsp_str_do_log(fsp), name);
2123
2124         return result;
2125 }
2126
2127 static int smb_full_audit_setxattr(struct vfs_handle_struct *handle,
2128                           const char *path,
2129                           const char *name, const void *value, size_t size,
2130                           int flags)
2131 {
2132         int result;
2133
2134         result = SMB_VFS_NEXT_SETXATTR(handle, path, name, value, size,
2135                                        flags);
2136
2137         do_log(SMB_VFS_OP_SETXATTR, (result >= 0), handle,
2138                "%s|%s", path, name);
2139
2140         return result;
2141 }
2142
2143 static int smb_full_audit_fsetxattr(struct vfs_handle_struct *handle,
2144                            struct files_struct *fsp, const char *name,
2145                            const void *value, size_t size, int flags)
2146 {
2147         int result;
2148
2149         result = SMB_VFS_NEXT_FSETXATTR(handle, fsp, name, value, size, flags);
2150
2151         do_log(SMB_VFS_OP_FSETXATTR, (result >= 0), handle,
2152                "%s|%s", fsp_str_do_log(fsp), name);
2153
2154         return result;
2155 }
2156
2157 static bool smb_full_audit_aio_force(struct vfs_handle_struct *handle,
2158                                      struct files_struct *fsp)
2159 {
2160         bool result;
2161
2162         result = SMB_VFS_NEXT_AIO_FORCE(handle, fsp);
2163         do_log(SMB_VFS_OP_AIO_FORCE, result, handle,
2164                 "%s", fsp_str_do_log(fsp));
2165
2166         return result;
2167 }
2168
2169 static bool smb_full_audit_is_offline(struct vfs_handle_struct *handle,
2170                                       const struct smb_filename *fname,
2171                                       SMB_STRUCT_STAT *sbuf)
2172 {
2173         bool result;
2174
2175         result = SMB_VFS_NEXT_IS_OFFLINE(handle, fname, sbuf);
2176         do_log(SMB_VFS_OP_IS_OFFLINE, result, handle, "%s",
2177                smb_fname_str_do_log(fname));
2178         return result;
2179 }
2180
2181 static int smb_full_audit_set_offline(struct vfs_handle_struct *handle,
2182                                       const struct smb_filename *fname)
2183 {
2184         int result;
2185
2186         result = SMB_VFS_NEXT_SET_OFFLINE(handle, fname);
2187         do_log(SMB_VFS_OP_SET_OFFLINE, result >= 0, handle, "%s",
2188                smb_fname_str_do_log(fname));
2189         return result;
2190 }
2191
2192 static struct vfs_fn_pointers vfs_full_audit_fns = {
2193
2194         /* Disk operations */
2195
2196         .connect_fn = smb_full_audit_connect,
2197         .disconnect_fn = smb_full_audit_disconnect,
2198         .disk_free_fn = smb_full_audit_disk_free,
2199         .get_quota_fn = smb_full_audit_get_quota,
2200         .set_quota_fn = smb_full_audit_set_quota,
2201         .get_shadow_copy_data_fn = smb_full_audit_get_shadow_copy_data,
2202         .statvfs_fn = smb_full_audit_statvfs,
2203         .fs_capabilities_fn = smb_full_audit_fs_capabilities,
2204         .opendir_fn = smb_full_audit_opendir,
2205         .fdopendir_fn = smb_full_audit_fdopendir,
2206         .readdir_fn = smb_full_audit_readdir,
2207         .seekdir_fn = smb_full_audit_seekdir,
2208         .telldir_fn = smb_full_audit_telldir,
2209         .rewind_dir_fn = smb_full_audit_rewinddir,
2210         .mkdir_fn = smb_full_audit_mkdir,
2211         .rmdir_fn = smb_full_audit_rmdir,
2212         .closedir_fn = smb_full_audit_closedir,
2213         .init_search_op_fn = smb_full_audit_init_search_op,
2214         .open_fn = smb_full_audit_open,
2215         .create_file_fn = smb_full_audit_create_file,
2216         .close_fn = smb_full_audit_close,
2217         .read_fn = smb_full_audit_read,
2218         .pread_fn = smb_full_audit_pread,
2219         .pread_send_fn = smb_full_audit_pread_send,
2220         .pread_recv_fn = smb_full_audit_pread_recv,
2221         .write_fn = smb_full_audit_write,
2222         .pwrite_fn = smb_full_audit_pwrite,
2223         .pwrite_send_fn = smb_full_audit_pwrite_send,
2224         .pwrite_recv_fn = smb_full_audit_pwrite_recv,
2225         .lseek_fn = smb_full_audit_lseek,
2226         .sendfile_fn = smb_full_audit_sendfile,
2227         .recvfile_fn = smb_full_audit_recvfile,
2228         .rename_fn = smb_full_audit_rename,
2229         .fsync_fn = smb_full_audit_fsync,
2230         .fsync_send_fn = smb_full_audit_fsync_send,
2231         .fsync_recv_fn = smb_full_audit_fsync_recv,
2232         .stat_fn = smb_full_audit_stat,
2233         .fstat_fn = smb_full_audit_fstat,
2234         .lstat_fn = smb_full_audit_lstat,
2235         .get_alloc_size_fn = smb_full_audit_get_alloc_size,
2236         .unlink_fn = smb_full_audit_unlink,
2237         .chmod_fn = smb_full_audit_chmod,
2238         .fchmod_fn = smb_full_audit_fchmod,
2239         .chown_fn = smb_full_audit_chown,
2240         .fchown_fn = smb_full_audit_fchown,
2241         .lchown_fn = smb_full_audit_lchown,
2242         .chdir_fn = smb_full_audit_chdir,
2243         .getwd_fn = smb_full_audit_getwd,
2244         .ntimes_fn = smb_full_audit_ntimes,
2245         .ftruncate_fn = smb_full_audit_ftruncate,
2246         .fallocate_fn = smb_full_audit_fallocate,
2247         .lock_fn = smb_full_audit_lock,
2248         .kernel_flock_fn = smb_full_audit_kernel_flock,
2249         .linux_setlease_fn = smb_full_audit_linux_setlease,
2250         .getlock_fn = smb_full_audit_getlock,
2251         .symlink_fn = smb_full_audit_symlink,
2252         .readlink_fn = smb_full_audit_readlink,
2253         .link_fn = smb_full_audit_link,
2254         .mknod_fn = smb_full_audit_mknod,
2255         .realpath_fn = smb_full_audit_realpath,
2256         .notify_watch_fn = smb_full_audit_notify_watch,
2257         .chflags_fn = smb_full_audit_chflags,
2258         .file_id_create_fn = smb_full_audit_file_id_create,
2259         .streaminfo_fn = smb_full_audit_streaminfo,
2260         .get_real_filename_fn = smb_full_audit_get_real_filename,
2261         .connectpath_fn = smb_full_audit_connectpath,
2262         .brl_lock_windows_fn = smb_full_audit_brl_lock_windows,
2263         .brl_unlock_windows_fn = smb_full_audit_brl_unlock_windows,
2264         .brl_cancel_windows_fn = smb_full_audit_brl_cancel_windows,
2265         .strict_lock_fn = smb_full_audit_strict_lock,
2266         .strict_unlock_fn = smb_full_audit_strict_unlock,
2267         .translate_name_fn = smb_full_audit_translate_name,
2268         .copy_chunk_send_fn = smb_full_audit_copy_chunk_send,
2269         .copy_chunk_recv_fn = smb_full_audit_copy_chunk_recv,
2270         .get_compression_fn = smb_full_audit_get_compression,
2271         .set_compression_fn = smb_full_audit_set_compression,
2272         .readdir_attr_fn = smb_full_audit_readdir_attr,
2273         .fget_nt_acl_fn = smb_full_audit_fget_nt_acl,
2274         .get_nt_acl_fn = smb_full_audit_get_nt_acl,
2275         .fset_nt_acl_fn = smb_full_audit_fset_nt_acl,
2276         .chmod_acl_fn = smb_full_audit_chmod_acl,
2277         .fchmod_acl_fn = smb_full_audit_fchmod_acl,
2278         .sys_acl_get_file_fn = smb_full_audit_sys_acl_get_file,
2279         .sys_acl_get_fd_fn = smb_full_audit_sys_acl_get_fd,
2280         .sys_acl_blob_get_file_fn = smb_full_audit_sys_acl_blob_get_file,
2281         .sys_acl_blob_get_fd_fn = smb_full_audit_sys_acl_blob_get_fd,
2282         .sys_acl_set_file_fn = smb_full_audit_sys_acl_set_file,
2283         .sys_acl_set_fd_fn = smb_full_audit_sys_acl_set_fd,
2284         .sys_acl_delete_def_file_fn = smb_full_audit_sys_acl_delete_def_file,
2285         .getxattr_fn = smb_full_audit_getxattr,
2286         .fgetxattr_fn = smb_full_audit_fgetxattr,
2287         .listxattr_fn = smb_full_audit_listxattr,
2288         .flistxattr_fn = smb_full_audit_flistxattr,
2289         .removexattr_fn = smb_full_audit_removexattr,
2290         .fremovexattr_fn = smb_full_audit_fremovexattr,
2291         .setxattr_fn = smb_full_audit_setxattr,
2292         .fsetxattr_fn = smb_full_audit_fsetxattr,
2293         .aio_force_fn = smb_full_audit_aio_force,
2294         .is_offline_fn = smb_full_audit_is_offline,
2295         .set_offline_fn = smb_full_audit_set_offline,
2296 };
2297
2298 NTSTATUS vfs_full_audit_init(void)
2299 {
2300         NTSTATUS ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION,
2301                                         "full_audit", &vfs_full_audit_fns);
2302         
2303         if (!NT_STATUS_IS_OK(ret))
2304                 return ret;
2305
2306         vfs_full_audit_debug_level = debug_add_class("full_audit");
2307         if (vfs_full_audit_debug_level == -1) {
2308                 vfs_full_audit_debug_level = DBGC_VFS;
2309                 DEBUG(0, ("vfs_full_audit: Couldn't register custom debugging "
2310                           "class!\n"));
2311         } else {
2312                 DEBUG(10, ("vfs_full_audit: Debug class number of "
2313                            "'full_audit': %d\n", vfs_full_audit_debug_level));
2314         }
2315         
2316         return ret;
2317 }