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