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