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