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