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