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