757cd26d3f1952894a15b7ae528fbd4925e0a7f6
[samba.git] / source3 / modules / vfs_full_audit.c
1 /* 
2  * Auditing VFS module for samba.  Log selected file operations to syslog
3  * facility.
4  *
5  * Copyright (C) Tim Potter, 1999-2000
6  * Copyright (C) Alexander Bokovoy, 2002
7  * Copyright (C) John H Terpstra, 2003
8  * Copyright (C) Stefan (metze) Metzmacher, 2003
9  * Copyright (C) Volker Lendecke, 2004
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 3 of the License, or
14  * (at your option) any later version.
15  *  
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *  
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, see <http://www.gnu.org/licenses/>.
23  */
24
25 /*
26  * This module implements parseable logging for all Samba VFS operations.
27  *
28  * You use it as follows:
29  *
30  * [tmp]
31  * path = /tmp
32  * vfs objects = full_audit
33  * full_audit:prefix = %u|%I
34  * full_audit:success = open opendir create_file
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|/tmp
42  * smbd_audit: nobody|192.168.234.1|create_file|fail (No such file or directory)|0x1|file|open|/ts/doesNotExist
43  * smbd_audit: nobody|192.168.234.1|open|ok|w|/tmp/file.txt
44  * smbd_audit: nobody|192.168.234.1|create_file|ok|0x3|file|open|/tmp/file.txt
45  *
46  * where "nobody" is the connected username and "192.168.234.1" is the
47  * client's IP address. 
48  *
49  * Options:
50  *
51  * prefix: A macro expansion template prepended to the syslog entry.
52  *
53  * success: A list of VFS operations for which a successful completion should
54  * be logged. Defaults to no logging at all. The special operation "all" logs
55  * - you guessed it - everything.
56  *
57  * failure: A list of VFS operations for which failure to complete should be
58  * logged. Defaults to logging everything.
59  */
60
61
62 #include "includes.h"
63 #include "system/filesys.h"
64 #include "system/syslog.h"
65 #include "smbd/smbd.h"
66 #include "../librpc/gen_ndr/ndr_netlogon.h"
67 #include "auth.h"
68 #include "ntioctl.h"
69 #include "lib/param/loadparm.h"
70 #include "lib/util/bitmap.h"
71 #include "lib/util/tevent_unix.h"
72 #include "libcli/security/sddl.h"
73 #include "passdb/machine_sid.h"
74 #include "lib/util/tevent_ntstatus.h"
75
76 static int vfs_full_audit_debug_level = DBGC_VFS;
77
78 struct vfs_full_audit_private_data {
79         struct bitmap *success_ops;
80         struct bitmap *failure_ops;
81         int syslog_facility;
82         int syslog_priority;
83         bool log_secdesc;
84         bool do_syslog;
85 };
86
87 #undef DBGC_CLASS
88 #define DBGC_CLASS vfs_full_audit_debug_level
89
90 typedef enum _vfs_op_type {
91         SMB_VFS_OP_NOOP = -1,
92
93         /* Disk operations */
94
95         SMB_VFS_OP_CONNECT = 0,
96         SMB_VFS_OP_DISCONNECT,
97         SMB_VFS_OP_DISK_FREE,
98         SMB_VFS_OP_GET_QUOTA,
99         SMB_VFS_OP_SET_QUOTA,
100         SMB_VFS_OP_GET_SHADOW_COPY_DATA,
101         SMB_VFS_OP_STATVFS,
102         SMB_VFS_OP_FS_CAPABILITIES,
103         SMB_VFS_OP_GET_DFS_REFERRALS,
104
105         /* Directory operations */
106
107         SMB_VFS_OP_OPENDIR,
108         SMB_VFS_OP_FDOPENDIR,
109         SMB_VFS_OP_READDIR,
110         SMB_VFS_OP_SEEKDIR,
111         SMB_VFS_OP_TELLDIR,
112         SMB_VFS_OP_REWINDDIR,
113         SMB_VFS_OP_MKDIRAT,
114         SMB_VFS_OP_RMDIR,
115         SMB_VFS_OP_CLOSEDIR,
116
117         /* File operations */
118
119         SMB_VFS_OP_OPEN,
120         SMB_VFS_OP_CREATE_FILE,
121         SMB_VFS_OP_CLOSE,
122         SMB_VFS_OP_READ,
123         SMB_VFS_OP_PREAD,
124         SMB_VFS_OP_PREAD_SEND,
125         SMB_VFS_OP_PREAD_RECV,
126         SMB_VFS_OP_WRITE,
127         SMB_VFS_OP_PWRITE,
128         SMB_VFS_OP_PWRITE_SEND,
129         SMB_VFS_OP_PWRITE_RECV,
130         SMB_VFS_OP_LSEEK,
131         SMB_VFS_OP_SENDFILE,
132         SMB_VFS_OP_RECVFILE,
133         SMB_VFS_OP_RENAMEAT,
134         SMB_VFS_OP_FSYNC,
135         SMB_VFS_OP_FSYNC_SEND,
136         SMB_VFS_OP_FSYNC_RECV,
137         SMB_VFS_OP_STAT,
138         SMB_VFS_OP_FSTAT,
139         SMB_VFS_OP_LSTAT,
140         SMB_VFS_OP_GET_ALLOC_SIZE,
141         SMB_VFS_OP_UNLINKAT,
142         SMB_VFS_OP_CHMOD,
143         SMB_VFS_OP_FCHMOD,
144         SMB_VFS_OP_CHOWN,
145         SMB_VFS_OP_FCHOWN,
146         SMB_VFS_OP_LCHOWN,
147         SMB_VFS_OP_CHDIR,
148         SMB_VFS_OP_GETWD,
149         SMB_VFS_OP_NTIMES,
150         SMB_VFS_OP_FTRUNCATE,
151         SMB_VFS_OP_FALLOCATE,
152         SMB_VFS_OP_LOCK,
153         SMB_VFS_OP_KERNEL_FLOCK,
154         SMB_VFS_OP_FCNTL,
155         SMB_VFS_OP_LINUX_SETLEASE,
156         SMB_VFS_OP_GETLOCK,
157         SMB_VFS_OP_SYMLINKAT,
158         SMB_VFS_OP_READLINKAT,
159         SMB_VFS_OP_LINKAT,
160         SMB_VFS_OP_MKNODAT,
161         SMB_VFS_OP_REALPATH,
162         SMB_VFS_OP_CHFLAGS,
163         SMB_VFS_OP_FILE_ID_CREATE,
164         SMB_VFS_OP_FS_FILE_ID,
165         SMB_VFS_OP_STREAMINFO,
166         SMB_VFS_OP_GET_REAL_FILENAME,
167         SMB_VFS_OP_CONNECTPATH,
168         SMB_VFS_OP_BRL_LOCK_WINDOWS,
169         SMB_VFS_OP_BRL_UNLOCK_WINDOWS,
170         SMB_VFS_OP_STRICT_LOCK_CHECK,
171         SMB_VFS_OP_TRANSLATE_NAME,
172         SMB_VFS_OP_FSCTL,
173         SMB_VFS_OP_OFFLOAD_READ_SEND,
174         SMB_VFS_OP_OFFLOAD_READ_RECV,
175         SMB_VFS_OP_OFFLOAD_WRITE_SEND,
176         SMB_VFS_OP_OFFLOAD_WRITE_RECV,
177         SMB_VFS_OP_GET_COMPRESSION,
178         SMB_VFS_OP_SET_COMPRESSION,
179         SMB_VFS_OP_SNAP_CHECK_PATH,
180         SMB_VFS_OP_SNAP_CREATE,
181         SMB_VFS_OP_SNAP_DELETE,
182
183         /* DOS attribute operations. */
184         SMB_VFS_OP_GET_DOS_ATTRIBUTES,
185         SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
186         SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV,
187         SMB_VFS_OP_FGET_DOS_ATTRIBUTES,
188         SMB_VFS_OP_SET_DOS_ATTRIBUTES,
189         SMB_VFS_OP_FSET_DOS_ATTRIBUTES,
190
191         /* NT ACL operations. */
192
193         SMB_VFS_OP_FGET_NT_ACL,
194         SMB_VFS_OP_GET_NT_ACL,
195         SMB_VFS_OP_FSET_NT_ACL,
196         SMB_VFS_OP_AUDIT_FILE,
197
198         /* POSIX ACL operations. */
199
200         SMB_VFS_OP_SYS_ACL_GET_FILE,
201         SMB_VFS_OP_SYS_ACL_GET_FD,
202         SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE,
203         SMB_VFS_OP_SYS_ACL_BLOB_GET_FD,
204         SMB_VFS_OP_SYS_ACL_SET_FILE,
205         SMB_VFS_OP_SYS_ACL_SET_FD,
206         SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE,
207
208         /* EA operations. */
209         SMB_VFS_OP_GETXATTR,
210         SMB_VFS_OP_GETXATTRAT_SEND,
211         SMB_VFS_OP_GETXATTRAT_RECV,
212         SMB_VFS_OP_FGETXATTR,
213         SMB_VFS_OP_LISTXATTR,
214         SMB_VFS_OP_FLISTXATTR,
215         SMB_VFS_OP_REMOVEXATTR,
216         SMB_VFS_OP_FREMOVEXATTR,
217         SMB_VFS_OP_SETXATTR,
218         SMB_VFS_OP_FSETXATTR,
219
220         /* aio operations */
221         SMB_VFS_OP_AIO_FORCE,
222
223         /* offline operations */
224         SMB_VFS_OP_IS_OFFLINE,
225         SMB_VFS_OP_SET_OFFLINE,
226
227         /* Durable handle operations. */
228         SMB_VFS_OP_DURABLE_COOKIE,
229         SMB_VFS_OP_DURABLE_DISCONNECT,
230         SMB_VFS_OP_DURABLE_RECONNECT,
231
232         SMB_VFS_OP_READDIR_ATTR,
233
234         /* This should always be last enum value */
235
236         SMB_VFS_OP_LAST
237 } vfs_op_type;
238
239 /* The following array *must* be in the same order as defined in vfs_op_type */
240
241 static struct {
242         vfs_op_type type;
243         const char *name;
244 } vfs_op_names[] = {
245         { SMB_VFS_OP_CONNECT,   "connect" },
246         { SMB_VFS_OP_DISCONNECT,        "disconnect" },
247         { SMB_VFS_OP_DISK_FREE, "disk_free" },
248         { SMB_VFS_OP_GET_QUOTA, "get_quota" },
249         { SMB_VFS_OP_SET_QUOTA, "set_quota" },
250         { SMB_VFS_OP_GET_SHADOW_COPY_DATA,      "get_shadow_copy_data" },
251         { SMB_VFS_OP_STATVFS,   "statvfs" },
252         { SMB_VFS_OP_FS_CAPABILITIES,   "fs_capabilities" },
253         { SMB_VFS_OP_GET_DFS_REFERRALS, "get_dfs_referrals" },
254         { SMB_VFS_OP_OPENDIR,   "opendir" },
255         { SMB_VFS_OP_FDOPENDIR, "fdopendir" },
256         { SMB_VFS_OP_READDIR,   "readdir" },
257         { SMB_VFS_OP_SEEKDIR,   "seekdir" },
258         { SMB_VFS_OP_TELLDIR,   "telldir" },
259         { SMB_VFS_OP_REWINDDIR, "rewinddir" },
260         { SMB_VFS_OP_MKDIRAT,   "mkdirat" },
261         { SMB_VFS_OP_RMDIR,     "rmdir" },
262         { SMB_VFS_OP_CLOSEDIR,  "closedir" },
263         { SMB_VFS_OP_OPEN,      "open" },
264         { SMB_VFS_OP_CREATE_FILE, "create_file" },
265         { SMB_VFS_OP_CLOSE,     "close" },
266         { SMB_VFS_OP_READ,      "read" },
267         { SMB_VFS_OP_PREAD,     "pread" },
268         { SMB_VFS_OP_PREAD_SEND,        "pread_send" },
269         { SMB_VFS_OP_PREAD_RECV,        "pread_recv" },
270         { SMB_VFS_OP_WRITE,     "write" },
271         { SMB_VFS_OP_PWRITE,    "pwrite" },
272         { SMB_VFS_OP_PWRITE_SEND,       "pwrite_send" },
273         { SMB_VFS_OP_PWRITE_RECV,       "pwrite_recv" },
274         { SMB_VFS_OP_LSEEK,     "lseek" },
275         { SMB_VFS_OP_SENDFILE,  "sendfile" },
276         { SMB_VFS_OP_RECVFILE,  "recvfile" },
277         { SMB_VFS_OP_RENAMEAT,  "renameat" },
278         { SMB_VFS_OP_FSYNC,     "fsync" },
279         { SMB_VFS_OP_FSYNC_SEND,        "fsync_send" },
280         { SMB_VFS_OP_FSYNC_RECV,        "fsync_recv" },
281         { SMB_VFS_OP_STAT,      "stat" },
282         { SMB_VFS_OP_FSTAT,     "fstat" },
283         { SMB_VFS_OP_LSTAT,     "lstat" },
284         { SMB_VFS_OP_GET_ALLOC_SIZE,    "get_alloc_size" },
285         { SMB_VFS_OP_UNLINKAT,  "unlinkat" },
286         { SMB_VFS_OP_CHMOD,     "chmod" },
287         { SMB_VFS_OP_FCHMOD,    "fchmod" },
288         { SMB_VFS_OP_CHOWN,     "chown" },
289         { SMB_VFS_OP_FCHOWN,    "fchown" },
290         { SMB_VFS_OP_LCHOWN,    "lchown" },
291         { SMB_VFS_OP_CHDIR,     "chdir" },
292         { SMB_VFS_OP_GETWD,     "getwd" },
293         { SMB_VFS_OP_NTIMES,    "ntimes" },
294         { SMB_VFS_OP_FTRUNCATE, "ftruncate" },
295         { SMB_VFS_OP_FALLOCATE,"fallocate" },
296         { SMB_VFS_OP_LOCK,      "lock" },
297         { SMB_VFS_OP_KERNEL_FLOCK,      "kernel_flock" },
298         { SMB_VFS_OP_LINUX_SETLEASE, "linux_setlease" },
299         { SMB_VFS_OP_GETLOCK,   "getlock" },
300         { SMB_VFS_OP_SYMLINKAT, "symlinkat" },
301         { SMB_VFS_OP_READLINKAT,"readlinkat" },
302         { SMB_VFS_OP_LINKAT,    "linkat" },
303         { SMB_VFS_OP_MKNODAT,   "mknodat" },
304         { SMB_VFS_OP_REALPATH,  "realpath" },
305         { SMB_VFS_OP_CHFLAGS,   "chflags" },
306         { SMB_VFS_OP_FILE_ID_CREATE,    "file_id_create" },
307         { SMB_VFS_OP_FS_FILE_ID,        "fs_file_id" },
308         { SMB_VFS_OP_STREAMINFO,        "streaminfo" },
309         { SMB_VFS_OP_GET_REAL_FILENAME, "get_real_filename" },
310         { SMB_VFS_OP_CONNECTPATH,       "connectpath" },
311         { SMB_VFS_OP_BRL_LOCK_WINDOWS,  "brl_lock_windows" },
312         { SMB_VFS_OP_BRL_UNLOCK_WINDOWS, "brl_unlock_windows" },
313         { SMB_VFS_OP_STRICT_LOCK_CHECK, "strict_lock_check" },
314         { SMB_VFS_OP_TRANSLATE_NAME,    "translate_name" },
315         { SMB_VFS_OP_FSCTL,             "fsctl" },
316         { SMB_VFS_OP_OFFLOAD_READ_SEND, "offload_read_send" },
317         { SMB_VFS_OP_OFFLOAD_READ_RECV, "offload_read_recv" },
318         { SMB_VFS_OP_OFFLOAD_WRITE_SEND,        "offload_write_send" },
319         { SMB_VFS_OP_OFFLOAD_WRITE_RECV,        "offload_write_recv" },
320         { SMB_VFS_OP_GET_COMPRESSION,   "get_compression" },
321         { SMB_VFS_OP_SET_COMPRESSION,   "set_compression" },
322         { SMB_VFS_OP_SNAP_CHECK_PATH, "snap_check_path" },
323         { SMB_VFS_OP_SNAP_CREATE, "snap_create" },
324         { SMB_VFS_OP_SNAP_DELETE, "snap_delete" },
325         { SMB_VFS_OP_GET_DOS_ATTRIBUTES, "get_dos_attributes" },
326         { SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND, "get_dos_attributes_send" },
327         { SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV, "get_dos_attributes_recv" },
328         { SMB_VFS_OP_FGET_DOS_ATTRIBUTES, "fget_dos_attributes" },
329         { SMB_VFS_OP_SET_DOS_ATTRIBUTES, "set_dos_attributes" },
330         { SMB_VFS_OP_FSET_DOS_ATTRIBUTES, "fset_dos_attributes" },
331         { SMB_VFS_OP_FGET_NT_ACL,       "fget_nt_acl" },
332         { SMB_VFS_OP_GET_NT_ACL,        "get_nt_acl" },
333         { SMB_VFS_OP_FSET_NT_ACL,       "fset_nt_acl" },
334         { SMB_VFS_OP_AUDIT_FILE,        "audit_file" },
335         { SMB_VFS_OP_SYS_ACL_GET_FILE,  "sys_acl_get_file" },
336         { SMB_VFS_OP_SYS_ACL_GET_FD,    "sys_acl_get_fd" },
337         { SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE,     "sys_acl_blob_get_file" },
338         { SMB_VFS_OP_SYS_ACL_BLOB_GET_FD,       "sys_acl_blob_get_fd" },
339         { SMB_VFS_OP_SYS_ACL_SET_FILE,  "sys_acl_set_file" },
340         { SMB_VFS_OP_SYS_ACL_SET_FD,    "sys_acl_set_fd" },
341         { SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE,   "sys_acl_delete_def_file" },
342         { SMB_VFS_OP_GETXATTR,  "getxattr" },
343         { SMB_VFS_OP_GETXATTRAT_SEND, "getxattrat_send" },
344         { SMB_VFS_OP_GETXATTRAT_RECV, "getxattrat_recv" },
345         { SMB_VFS_OP_FGETXATTR, "fgetxattr" },
346         { SMB_VFS_OP_LISTXATTR, "listxattr" },
347         { SMB_VFS_OP_FLISTXATTR,        "flistxattr" },
348         { SMB_VFS_OP_REMOVEXATTR,       "removexattr" },
349         { SMB_VFS_OP_FREMOVEXATTR,      "fremovexattr" },
350         { SMB_VFS_OP_SETXATTR,  "setxattr" },
351         { SMB_VFS_OP_FSETXATTR, "fsetxattr" },
352         { SMB_VFS_OP_AIO_FORCE, "aio_force" },
353         { SMB_VFS_OP_IS_OFFLINE, "is_offline" },
354         { SMB_VFS_OP_SET_OFFLINE, "set_offline" },
355         { SMB_VFS_OP_DURABLE_COOKIE, "durable_cookie" },
356         { SMB_VFS_OP_DURABLE_DISCONNECT, "durable_disconnect" },
357         { SMB_VFS_OP_DURABLE_RECONNECT, "durable_reconnect" },
358         { SMB_VFS_OP_READDIR_ATTR,      "readdir_attr" },
359         { SMB_VFS_OP_LAST, NULL }
360 };
361
362 static int audit_syslog_facility(vfs_handle_struct *handle)
363 {
364         static const struct enum_list enum_log_facilities[] = {
365 #ifdef LOG_AUTH
366                 { LOG_AUTH,             "AUTH" },
367 #endif
368 #ifdef LOG_AUTHPRIV
369                 { LOG_AUTHPRIV,         "AUTHPRIV" },
370 #endif
371 #ifdef LOG_AUDIT
372                 { LOG_AUDIT,            "AUDIT" },
373 #endif
374 #ifdef LOG_CONSOLE
375                 { LOG_CONSOLE,          "CONSOLE" },
376 #endif
377 #ifdef LOG_CRON
378                 { LOG_CRON,             "CRON" },
379 #endif
380 #ifdef LOG_DAEMON
381                 { LOG_DAEMON,           "DAEMON" },
382 #endif
383 #ifdef LOG_FTP
384                 { LOG_FTP,              "FTP" },
385 #endif
386 #ifdef LOG_INSTALL
387                 { LOG_INSTALL,          "INSTALL" },
388 #endif
389 #ifdef LOG_KERN
390                 { LOG_KERN,             "KERN" },
391 #endif
392 #ifdef LOG_LAUNCHD
393                 { LOG_LAUNCHD,          "LAUNCHD" },
394 #endif
395 #ifdef LOG_LFMT
396                 { LOG_LFMT,             "LFMT" },
397 #endif
398 #ifdef LOG_LPR
399                 { LOG_LPR,              "LPR" },
400 #endif
401 #ifdef LOG_MAIL
402                 { LOG_MAIL,             "MAIL" },
403 #endif
404 #ifdef LOG_MEGASAFE
405                 { LOG_MEGASAFE,         "MEGASAFE" },
406 #endif
407 #ifdef LOG_NETINFO
408                 { LOG_NETINFO,          "NETINFO" },
409 #endif
410 #ifdef LOG_NEWS
411                 { LOG_NEWS,             "NEWS" },
412 #endif
413 #ifdef LOG_NFACILITIES
414                 { LOG_NFACILITIES,      "NFACILITIES" },
415 #endif
416 #ifdef LOG_NTP
417                 { LOG_NTP,              "NTP" },
418 #endif
419 #ifdef LOG_RAS
420                 { LOG_RAS,              "RAS" },
421 #endif
422 #ifdef LOG_REMOTEAUTH
423                 { LOG_REMOTEAUTH,       "REMOTEAUTH" },
424 #endif
425 #ifdef LOG_SECURITY
426                 { LOG_SECURITY,         "SECURITY" },
427 #endif
428 #ifdef LOG_SYSLOG
429                 { LOG_SYSLOG,           "SYSLOG" },
430 #endif
431 #ifdef LOG_USER
432                 { LOG_USER,             "USER" },
433 #endif
434 #ifdef LOG_UUCP
435                 { LOG_UUCP,             "UUCP" },
436 #endif
437                 { LOG_LOCAL0,           "LOCAL0" },
438                 { LOG_LOCAL1,           "LOCAL1" },
439                 { LOG_LOCAL2,           "LOCAL2" },
440                 { LOG_LOCAL3,           "LOCAL3" },
441                 { LOG_LOCAL4,           "LOCAL4" },
442                 { LOG_LOCAL5,           "LOCAL5" },
443                 { LOG_LOCAL6,           "LOCAL6" },
444                 { LOG_LOCAL7,           "LOCAL7" },
445                 { -1,                   NULL }
446         };
447
448         int facility;
449
450         facility = lp_parm_enum(SNUM(handle->conn), "full_audit", "facility", enum_log_facilities, LOG_USER);
451
452         return facility;
453 }
454
455 static int audit_syslog_priority(vfs_handle_struct *handle)
456 {
457         static const struct enum_list enum_log_priorities[] = {
458                 { LOG_EMERG, "EMERG" },
459                 { LOG_ALERT, "ALERT" },
460                 { LOG_CRIT, "CRIT" },
461                 { LOG_ERR, "ERR" },
462                 { LOG_WARNING, "WARNING" },
463                 { LOG_NOTICE, "NOTICE" },
464                 { LOG_INFO, "INFO" },
465                 { LOG_DEBUG, "DEBUG" },
466                 { -1, NULL }
467         };
468
469         int priority;
470
471         priority = lp_parm_enum(SNUM(handle->conn), "full_audit", "priority",
472                                 enum_log_priorities, LOG_NOTICE);
473         if (priority == -1) {
474                 priority = LOG_WARNING;
475         }
476
477         return priority;
478 }
479
480 static char *audit_prefix(TALLOC_CTX *ctx, connection_struct *conn)
481 {
482         char *prefix = NULL;
483         char *result;
484
485         prefix = talloc_strdup(ctx,
486                         lp_parm_const_string(SNUM(conn), "full_audit",
487                                              "prefix", "%u|%I"));
488         if (!prefix) {
489                 return NULL;
490         }
491         result = talloc_sub_advanced(ctx,
492                         lp_servicename(talloc_tos(), SNUM(conn)),
493                         conn->session_info->unix_info->unix_name,
494                         conn->connectpath,
495                         conn->session_info->unix_token->gid,
496                         conn->session_info->unix_info->sanitized_username,
497                         conn->session_info->info->domain_name,
498                         prefix);
499         TALLOC_FREE(prefix);
500         return result;
501 }
502
503 static bool log_success(struct vfs_full_audit_private_data *pd, vfs_op_type op)
504 {
505         if (pd->success_ops == NULL) {
506                 return True;
507         }
508
509         return bitmap_query(pd->success_ops, op);
510 }
511
512 static bool log_failure(struct vfs_full_audit_private_data *pd, vfs_op_type op)
513 {
514         if (pd->failure_ops == NULL)
515                 return True;
516
517         return bitmap_query(pd->failure_ops, op);
518 }
519
520 static struct bitmap *init_bitmap(TALLOC_CTX *mem_ctx, const char **ops)
521 {
522         struct bitmap *bm;
523
524         if (ops == NULL) {
525                 return NULL;
526         }
527
528         bm = bitmap_talloc(mem_ctx, SMB_VFS_OP_LAST);
529         if (bm == NULL) {
530                 DEBUG(0, ("Could not alloc bitmap -- "
531                           "defaulting to logging everything\n"));
532                 return NULL;
533         }
534
535         for (; *ops != NULL; ops += 1) {
536                 int i;
537                 bool neg = false;
538                 const char *op;
539
540                 if (strequal(*ops, "all")) {
541                         for (i=0; i<SMB_VFS_OP_LAST; i++) {
542                                 bitmap_set(bm, i);
543                         }
544                         continue;
545                 }
546
547                 if (strequal(*ops, "none")) {
548                         break;
549                 }
550
551                 op = ops[0];
552                 if (op[0] == '!') {
553                         neg = true;
554                         op += 1;
555                 }
556
557                 for (i=0; i<SMB_VFS_OP_LAST; i++) {
558                         if ((vfs_op_names[i].name == NULL)
559                          || (vfs_op_names[i].type != i)) {
560                                 smb_panic("vfs_full_audit.c: name table not "
561                                           "in sync with vfs_op_type enums\n");
562                         }
563                         if (strequal(op, vfs_op_names[i].name)) {
564                                 if (neg) {
565                                         bitmap_clear(bm, i);
566                                 } else {
567                                         bitmap_set(bm, i);
568                                 }
569                                 break;
570                         }
571                 }
572                 if (i == SMB_VFS_OP_LAST) {
573                         DEBUG(0, ("Could not find opname %s, logging all\n",
574                                   *ops));
575                         TALLOC_FREE(bm);
576                         return NULL;
577                 }
578         }
579         return bm;
580 }
581
582 static const char *audit_opname(vfs_op_type op)
583 {
584         if (op >= SMB_VFS_OP_LAST)
585                 return "INVALID VFS OP";
586         return vfs_op_names[op].name;
587 }
588
589 static TALLOC_CTX *tmp_do_log_ctx;
590 /*
591  * Get us a temporary talloc context usable just for DEBUG arguments
592  */
593 static TALLOC_CTX *do_log_ctx(void)
594 {
595         if (tmp_do_log_ctx == NULL) {
596                 tmp_do_log_ctx = talloc_named_const(NULL, 0, "do_log_ctx");
597         }
598         return tmp_do_log_ctx;
599 }
600
601 static void do_log(vfs_op_type op, bool success, vfs_handle_struct *handle,
602                    const char *format, ...) PRINTF_ATTRIBUTE(4, 5);
603
604 static void do_log(vfs_op_type op, bool success, vfs_handle_struct *handle,
605                    const char *format, ...)
606 {
607         struct vfs_full_audit_private_data *pd;
608         fstring err_msg;
609         char *audit_pre = NULL;
610         va_list ap;
611         char *op_msg = NULL;
612
613         SMB_VFS_HANDLE_GET_DATA(handle, pd,
614                                 struct vfs_full_audit_private_data,
615                                 return;);
616
617         if (success && (!log_success(pd, op)))
618                 goto out;
619
620         if (!success && (!log_failure(pd, op)))
621                 goto out;
622
623         if (success)
624                 fstrcpy(err_msg, "ok");
625         else
626                 fstr_sprintf(err_msg, "fail (%s)", strerror(errno));
627
628         va_start(ap, format);
629         op_msg = talloc_vasprintf(talloc_tos(), format, ap);
630         va_end(ap);
631
632         if (!op_msg) {
633                 goto out;
634         }
635
636         audit_pre = audit_prefix(talloc_tos(), handle->conn);
637
638         if (pd->do_syslog) {
639                 int priority;
640
641                 /*
642                  * Specify the facility to interoperate with other syslog
643                  * callers (smbd for example).
644                  */
645                 priority = pd->syslog_priority | pd->syslog_facility;
646
647                 syslog(priority, "%s|%s|%s|%s\n",
648                        audit_pre ? audit_pre : "",
649                        audit_opname(op), err_msg, op_msg);
650         } else {
651                 DEBUG(1, ("%s|%s|%s|%s\n",
652                           audit_pre ? audit_pre : "",
653                           audit_opname(op), err_msg, op_msg));
654         }
655  out:
656         TALLOC_FREE(audit_pre);
657         TALLOC_FREE(op_msg);
658         TALLOC_FREE(tmp_do_log_ctx);
659 }
660
661 /**
662  * Return a string using the do_log_ctx()
663  */
664 static const char *smb_fname_str_do_log(struct connection_struct *conn,
665                                 const struct smb_filename *smb_fname)
666 {
667         char *fname = NULL;
668         NTSTATUS status;
669
670         if (smb_fname == NULL) {
671                 return "";
672         }
673
674         if (smb_fname->base_name[0] != '/') {
675                 char *abs_name = NULL;
676                 struct smb_filename *fname_copy = cp_smb_filename(
677                                                         do_log_ctx(),
678                                                         smb_fname);
679                 if (fname_copy == NULL) {
680                         return "";
681                 }
682
683                 if (!ISDOT(smb_fname->base_name)) {
684                         abs_name = talloc_asprintf(do_log_ctx(),
685                                         "%s/%s",
686                                         conn->cwd_fsp->fsp_name->base_name,
687                                         smb_fname->base_name);
688                 } else {
689                         abs_name = talloc_strdup(do_log_ctx(),
690                                         conn->cwd_fsp->fsp_name->base_name);
691                 }
692                 if (abs_name == NULL) {
693                         return "";
694                 }
695                 fname_copy->base_name = abs_name;
696                 smb_fname = fname_copy;
697         }
698
699         status = get_full_smb_filename(do_log_ctx(), smb_fname, &fname);
700         if (!NT_STATUS_IS_OK(status)) {
701                 return "";
702         }
703         return fname;
704 }
705
706 /**
707  * Return an fsp debug string using the do_log_ctx()
708  */
709 static const char *fsp_str_do_log(const struct files_struct *fsp)
710 {
711         return smb_fname_str_do_log(fsp->conn, fsp->fsp_name);
712 }
713
714 /* Implementation of vfs_ops.  Pass everything on to the default
715    operation but log event first. */
716
717 static int smb_full_audit_connect(vfs_handle_struct *handle,
718                          const char *svc, const char *user)
719 {
720         int result;
721         const char *none[] = { "none" };
722         struct vfs_full_audit_private_data *pd = NULL;
723
724         result = SMB_VFS_NEXT_CONNECT(handle, svc, user);
725         if (result < 0) {
726                 return result;
727         }
728
729         pd = talloc_zero(handle, struct vfs_full_audit_private_data);
730         if (!pd) {
731                 SMB_VFS_NEXT_DISCONNECT(handle);
732                 return -1;
733         }
734
735         pd->syslog_facility = audit_syslog_facility(handle);
736         if (pd->syslog_facility == -1) {
737                 DEBUG(1, ("%s: Unknown facility %s\n", __func__,
738                           lp_parm_const_string(SNUM(handle->conn),
739                                                "full_audit", "facility",
740                                                "USER")));
741                 SMB_VFS_NEXT_DISCONNECT(handle);
742                 return -1;
743         }
744
745         pd->syslog_priority = audit_syslog_priority(handle);
746
747         pd->log_secdesc = lp_parm_bool(SNUM(handle->conn),
748                                        "full_audit", "log_secdesc", false);
749
750         pd->do_syslog = lp_parm_bool(SNUM(handle->conn),
751                                      "full_audit", "syslog", true);
752
753 #ifdef WITH_SYSLOG
754         if (pd->do_syslog) {
755                 openlog("smbd_audit", 0, pd->syslog_facility);
756         }
757 #endif
758
759         pd->success_ops = init_bitmap(
760                 pd, lp_parm_string_list(SNUM(handle->conn), "full_audit",
761                                         "success", none));
762         pd->failure_ops = init_bitmap(
763                 pd, lp_parm_string_list(SNUM(handle->conn), "full_audit",
764                                         "failure", none));
765
766         /* Store the private data. */
767         SMB_VFS_HANDLE_SET_DATA(handle, pd, NULL,
768                                 struct vfs_full_audit_private_data, return -1);
769
770         do_log(SMB_VFS_OP_CONNECT, True, handle,
771                "%s", svc);
772
773         return 0;
774 }
775
776 static void smb_full_audit_disconnect(vfs_handle_struct *handle)
777 {
778         SMB_VFS_NEXT_DISCONNECT(handle);
779
780         do_log(SMB_VFS_OP_DISCONNECT, True, handle,
781                "%s", lp_servicename(talloc_tos(), SNUM(handle->conn)));
782
783         /* The bitmaps will be disconnected when the private
784            data is deleted. */
785 }
786
787 static uint64_t smb_full_audit_disk_free(vfs_handle_struct *handle,
788                                 const struct smb_filename *smb_fname,
789                                 uint64_t *bsize,
790                                 uint64_t *dfree,
791                                 uint64_t *dsize)
792 {
793         uint64_t result;
794
795         result = SMB_VFS_NEXT_DISK_FREE(handle, smb_fname, bsize, dfree, dsize);
796
797         /* Don't have a reasonable notion of failure here */
798
799         do_log(SMB_VFS_OP_DISK_FREE,
800                True,
801                handle,
802                "%s",
803                smb_fname_str_do_log(handle->conn, smb_fname));
804
805         return result;
806 }
807
808 static int smb_full_audit_get_quota(struct vfs_handle_struct *handle,
809                                 const struct smb_filename *smb_fname,
810                                 enum SMB_QUOTA_TYPE qtype,
811                                 unid_t id,
812                                 SMB_DISK_QUOTA *qt)
813 {
814         int result;
815
816         result = SMB_VFS_NEXT_GET_QUOTA(handle, smb_fname, qtype, id, qt);
817
818         do_log(SMB_VFS_OP_GET_QUOTA,
819                (result >= 0),
820                handle,
821                "%s",
822                smb_fname_str_do_log(handle->conn, smb_fname));
823
824         return result;
825 }
826
827 static int smb_full_audit_set_quota(struct vfs_handle_struct *handle,
828                            enum SMB_QUOTA_TYPE qtype, unid_t id,
829                            SMB_DISK_QUOTA *qt)
830 {
831         int result;
832
833         result = SMB_VFS_NEXT_SET_QUOTA(handle, qtype, id, qt);
834
835         do_log(SMB_VFS_OP_SET_QUOTA, (result >= 0), handle, "");
836
837         return result;
838 }
839
840 static int smb_full_audit_get_shadow_copy_data(struct vfs_handle_struct *handle,
841                                 struct files_struct *fsp,
842                                 struct shadow_copy_data *shadow_copy_data,
843                                 bool labels)
844 {
845         int result;
846
847         result = SMB_VFS_NEXT_GET_SHADOW_COPY_DATA(handle, fsp, shadow_copy_data, labels);
848
849         do_log(SMB_VFS_OP_GET_SHADOW_COPY_DATA, (result >= 0), handle, "");
850
851         return result;
852 }
853
854 static int smb_full_audit_statvfs(struct vfs_handle_struct *handle,
855                                 const struct smb_filename *smb_fname,
856                                 struct vfs_statvfs_struct *statbuf)
857 {
858         int result;
859
860         result = SMB_VFS_NEXT_STATVFS(handle, smb_fname, statbuf);
861
862         do_log(SMB_VFS_OP_STATVFS, (result >= 0), handle, "");
863
864         return result;
865 }
866
867 static uint32_t smb_full_audit_fs_capabilities(struct vfs_handle_struct *handle, enum timestamp_set_resolution *p_ts_res)
868 {
869         int result;
870
871         result = SMB_VFS_NEXT_FS_CAPABILITIES(handle, p_ts_res);
872
873         do_log(SMB_VFS_OP_FS_CAPABILITIES, true, handle, "");
874
875         return result;
876 }
877
878 static NTSTATUS smb_full_audit_get_dfs_referrals(
879                                 struct vfs_handle_struct *handle,
880                                 struct dfs_GetDFSReferral *r)
881 {
882         NTSTATUS status;
883
884         status = SMB_VFS_NEXT_GET_DFS_REFERRALS(handle, r);
885
886         do_log(SMB_VFS_OP_GET_DFS_REFERRALS, NT_STATUS_IS_OK(status),
887                handle, "");
888
889         return status;
890 }
891
892 static NTSTATUS smb_full_audit_snap_check_path(struct vfs_handle_struct *handle,
893                                                TALLOC_CTX *mem_ctx,
894                                                const char *service_path,
895                                                char **base_volume)
896 {
897         NTSTATUS status;
898
899         status = SMB_VFS_NEXT_SNAP_CHECK_PATH(handle, mem_ctx, service_path,
900                                               base_volume);
901         do_log(SMB_VFS_OP_SNAP_CHECK_PATH, NT_STATUS_IS_OK(status),
902                handle, "");
903
904         return status;
905 }
906
907 static NTSTATUS smb_full_audit_snap_create(struct vfs_handle_struct *handle,
908                                            TALLOC_CTX *mem_ctx,
909                                            const char *base_volume,
910                                            time_t *tstamp,
911                                            bool rw,
912                                            char **base_path,
913                                            char **snap_path)
914 {
915         NTSTATUS status;
916
917         status = SMB_VFS_NEXT_SNAP_CREATE(handle, mem_ctx, base_volume, tstamp,
918                                           rw, base_path, snap_path);
919         do_log(SMB_VFS_OP_SNAP_CREATE, NT_STATUS_IS_OK(status), handle, "");
920
921         return status;
922 }
923
924 static NTSTATUS smb_full_audit_snap_delete(struct vfs_handle_struct *handle,
925                                            TALLOC_CTX *mem_ctx,
926                                            char *base_path,
927                                            char *snap_path)
928 {
929         NTSTATUS status;
930
931         status = SMB_VFS_NEXT_SNAP_DELETE(handle, mem_ctx, base_path,
932                                           snap_path);
933         do_log(SMB_VFS_OP_SNAP_DELETE, NT_STATUS_IS_OK(status), handle, "");
934
935         return status;
936 }
937
938 static DIR *smb_full_audit_opendir(vfs_handle_struct *handle,
939                         const struct smb_filename *smb_fname,
940                         const char *mask,
941                         uint32_t attr)
942 {
943         DIR *result;
944
945         result = SMB_VFS_NEXT_OPENDIR(handle, smb_fname, mask, attr);
946
947         do_log(SMB_VFS_OP_OPENDIR,
948                (result != NULL),
949                handle,
950                "%s",
951                smb_fname_str_do_log(handle->conn, smb_fname));
952
953         return result;
954 }
955
956 static DIR *smb_full_audit_fdopendir(vfs_handle_struct *handle,
957                           files_struct *fsp, const char *mask, uint32_t attr)
958 {
959         DIR *result;
960
961         result = SMB_VFS_NEXT_FDOPENDIR(handle, fsp, mask, attr);
962
963         do_log(SMB_VFS_OP_FDOPENDIR, (result != NULL), handle, "%s",
964                         fsp_str_do_log(fsp));
965
966         return result;
967 }
968
969 static struct dirent *smb_full_audit_readdir(vfs_handle_struct *handle,
970                                     DIR *dirp, SMB_STRUCT_STAT *sbuf)
971 {
972         struct dirent *result;
973
974         result = SMB_VFS_NEXT_READDIR(handle, dirp, sbuf);
975
976         /* This operation has no reasonable error condition
977          * (End of dir is also failure), so always succeed.
978          */
979         do_log(SMB_VFS_OP_READDIR, True, handle, "");
980
981         return result;
982 }
983
984 static void smb_full_audit_seekdir(vfs_handle_struct *handle,
985                         DIR *dirp, long offset)
986 {
987         SMB_VFS_NEXT_SEEKDIR(handle, dirp, offset);
988
989         do_log(SMB_VFS_OP_SEEKDIR, True, handle, "");
990 }
991
992 static long smb_full_audit_telldir(vfs_handle_struct *handle,
993                         DIR *dirp)
994 {
995         long result;
996
997         result = SMB_VFS_NEXT_TELLDIR(handle, dirp);
998
999         do_log(SMB_VFS_OP_TELLDIR, True, handle, "");
1000
1001         return result;
1002 }
1003
1004 static void smb_full_audit_rewinddir(vfs_handle_struct *handle,
1005                         DIR *dirp)
1006 {
1007         SMB_VFS_NEXT_REWINDDIR(handle, dirp);
1008
1009         do_log(SMB_VFS_OP_REWINDDIR, True, handle, "");
1010 }
1011
1012 static int smb_full_audit_mkdirat(vfs_handle_struct *handle,
1013                         struct files_struct *dirfsp,
1014                         const struct smb_filename *smb_fname,
1015                         mode_t mode)
1016 {
1017         int result;
1018
1019         result = SMB_VFS_NEXT_MKDIRAT(handle,
1020                         dirfsp,
1021                         smb_fname,
1022                         mode);
1023
1024         do_log(SMB_VFS_OP_MKDIRAT,
1025                (result >= 0),
1026                handle,
1027                "%s",
1028                smb_fname_str_do_log(handle->conn, smb_fname));
1029
1030         return result;
1031 }
1032
1033 static int smb_full_audit_rmdir(vfs_handle_struct *handle,
1034                        const struct smb_filename *smb_fname)
1035 {
1036         int result;
1037         
1038         result = SMB_VFS_NEXT_RMDIR(handle, smb_fname);
1039
1040         do_log(SMB_VFS_OP_RMDIR,
1041                (result >= 0),
1042                handle,
1043                "%s",
1044                smb_fname_str_do_log(handle->conn, smb_fname));
1045
1046         return result;
1047 }
1048
1049 static int smb_full_audit_closedir(vfs_handle_struct *handle,
1050                           DIR *dirp)
1051 {
1052         int result;
1053
1054         result = SMB_VFS_NEXT_CLOSEDIR(handle, dirp);
1055         
1056         do_log(SMB_VFS_OP_CLOSEDIR, (result >= 0), handle, "");
1057
1058         return result;
1059 }
1060
1061 static int smb_full_audit_open(vfs_handle_struct *handle,
1062                                struct smb_filename *smb_fname,
1063                                files_struct *fsp, int flags, mode_t mode)
1064 {
1065         int result;
1066         
1067         result = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
1068
1069         do_log(SMB_VFS_OP_OPEN, (result >= 0), handle, "%s|%s",
1070                ((flags & O_WRONLY) || (flags & O_RDWR))?"w":"r",
1071                smb_fname_str_do_log(handle->conn, smb_fname));
1072
1073         return result;
1074 }
1075
1076 static NTSTATUS smb_full_audit_create_file(vfs_handle_struct *handle,
1077                                       struct smb_request *req,
1078                                       uint16_t root_dir_fid,
1079                                       struct smb_filename *smb_fname,
1080                                       uint32_t access_mask,
1081                                       uint32_t share_access,
1082                                       uint32_t create_disposition,
1083                                       uint32_t create_options,
1084                                       uint32_t file_attributes,
1085                                       uint32_t oplock_request,
1086                                       const struct smb2_lease *lease,
1087                                       uint64_t allocation_size,
1088                                       uint32_t private_flags,
1089                                       struct security_descriptor *sd,
1090                                       struct ea_list *ea_list,
1091                                       files_struct **result_fsp,
1092                                       int *pinfo,
1093                                       const struct smb2_create_blobs *in_context_blobs,
1094                                       struct smb2_create_blobs *out_context_blobs)
1095 {
1096         NTSTATUS result;
1097         const char* str_create_disposition;
1098
1099         switch (create_disposition) {
1100         case FILE_SUPERSEDE:
1101                 str_create_disposition = "supersede";
1102                 break;
1103         case FILE_OVERWRITE_IF:
1104                 str_create_disposition = "overwrite_if";
1105                 break;
1106         case FILE_OPEN:
1107                 str_create_disposition = "open";
1108                 break;
1109         case FILE_OVERWRITE:
1110                 str_create_disposition = "overwrite";
1111                 break;
1112         case FILE_CREATE:
1113                 str_create_disposition = "create";
1114                 break;
1115         case FILE_OPEN_IF:
1116                 str_create_disposition = "open_if";
1117                 break;
1118         default:
1119                 str_create_disposition = "unknown";
1120         }
1121
1122         result = SMB_VFS_NEXT_CREATE_FILE(
1123                 handle,                                 /* handle */
1124                 req,                                    /* req */
1125                 root_dir_fid,                           /* root_dir_fid */
1126                 smb_fname,                              /* fname */
1127                 access_mask,                            /* access_mask */
1128                 share_access,                           /* share_access */
1129                 create_disposition,                     /* create_disposition*/
1130                 create_options,                         /* create_options */
1131                 file_attributes,                        /* file_attributes */
1132                 oplock_request,                         /* oplock_request */
1133                 lease,                                  /* lease */
1134                 allocation_size,                        /* allocation_size */
1135                 private_flags,
1136                 sd,                                     /* sd */
1137                 ea_list,                                /* ea_list */
1138                 result_fsp,                             /* result */
1139                 pinfo,                                  /* pinfo */
1140                 in_context_blobs, out_context_blobs);   /* create context */
1141
1142         do_log(SMB_VFS_OP_CREATE_FILE, (NT_STATUS_IS_OK(result)), handle,
1143                "0x%x|%s|%s|%s", access_mask,
1144                create_options & FILE_DIRECTORY_FILE ? "dir" : "file",
1145                str_create_disposition,
1146                 smb_fname_str_do_log(handle->conn, smb_fname));
1147
1148         return result;
1149 }
1150
1151 static int smb_full_audit_close(vfs_handle_struct *handle, files_struct *fsp)
1152 {
1153         int result;
1154         
1155         result = SMB_VFS_NEXT_CLOSE(handle, fsp);
1156
1157         do_log(SMB_VFS_OP_CLOSE, (result >= 0), handle, "%s",
1158                fsp_str_do_log(fsp));
1159
1160         return result;
1161 }
1162
1163 static ssize_t smb_full_audit_pread(vfs_handle_struct *handle, files_struct *fsp,
1164                            void *data, size_t n, off_t offset)
1165 {
1166         ssize_t result;
1167
1168         result = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
1169
1170         do_log(SMB_VFS_OP_PREAD, (result >= 0), handle, "%s",
1171                fsp_str_do_log(fsp));
1172
1173         return result;
1174 }
1175
1176 struct smb_full_audit_pread_state {
1177         vfs_handle_struct *handle;
1178         files_struct *fsp;
1179         ssize_t ret;
1180         struct vfs_aio_state vfs_aio_state;
1181 };
1182
1183 static void smb_full_audit_pread_done(struct tevent_req *subreq);
1184
1185 static struct tevent_req *smb_full_audit_pread_send(
1186         struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1187         struct tevent_context *ev, struct files_struct *fsp,
1188         void *data, size_t n, off_t offset)
1189 {
1190         struct tevent_req *req, *subreq;
1191         struct smb_full_audit_pread_state *state;
1192
1193         req = tevent_req_create(mem_ctx, &state,
1194                                 struct smb_full_audit_pread_state);
1195         if (req == NULL) {
1196                 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
1197                        fsp_str_do_log(fsp));
1198                 return NULL;
1199         }
1200         state->handle = handle;
1201         state->fsp = fsp;
1202
1203         subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
1204                                          n, offset);
1205         if (tevent_req_nomem(subreq, req)) {
1206                 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
1207                        fsp_str_do_log(fsp));
1208                 return tevent_req_post(req, ev);
1209         }
1210         tevent_req_set_callback(subreq, smb_full_audit_pread_done, req);
1211
1212         do_log(SMB_VFS_OP_PREAD_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1213         return req;
1214 }
1215
1216 static void smb_full_audit_pread_done(struct tevent_req *subreq)
1217 {
1218         struct tevent_req *req = tevent_req_callback_data(
1219                 subreq, struct tevent_req);
1220         struct smb_full_audit_pread_state *state = tevent_req_data(
1221                 req, struct smb_full_audit_pread_state);
1222
1223         state->ret = SMB_VFS_PREAD_RECV(subreq, &state->vfs_aio_state);
1224         TALLOC_FREE(subreq);
1225         tevent_req_done(req);
1226 }
1227
1228 static ssize_t smb_full_audit_pread_recv(struct tevent_req *req,
1229                                          struct vfs_aio_state *vfs_aio_state)
1230 {
1231         struct smb_full_audit_pread_state *state = tevent_req_data(
1232                 req, struct smb_full_audit_pread_state);
1233
1234         if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1235                 do_log(SMB_VFS_OP_PREAD_RECV, false, state->handle, "%s",
1236                        fsp_str_do_log(state->fsp));
1237                 return -1;
1238         }
1239
1240         do_log(SMB_VFS_OP_PREAD_RECV, (state->ret >= 0), state->handle, "%s",
1241                fsp_str_do_log(state->fsp));
1242
1243         *vfs_aio_state = state->vfs_aio_state;
1244         return state->ret;
1245 }
1246
1247 static ssize_t smb_full_audit_pwrite(vfs_handle_struct *handle, files_struct *fsp,
1248                             const void *data, size_t n,
1249                             off_t offset)
1250 {
1251         ssize_t result;
1252
1253         result = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
1254
1255         do_log(SMB_VFS_OP_PWRITE, (result >= 0), handle, "%s",
1256                fsp_str_do_log(fsp));
1257
1258         return result;
1259 }
1260
1261 struct smb_full_audit_pwrite_state {
1262         vfs_handle_struct *handle;
1263         files_struct *fsp;
1264         ssize_t ret;
1265         struct vfs_aio_state vfs_aio_state;
1266 };
1267
1268 static void smb_full_audit_pwrite_done(struct tevent_req *subreq);
1269
1270 static struct tevent_req *smb_full_audit_pwrite_send(
1271         struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1272         struct tevent_context *ev, struct files_struct *fsp,
1273         const void *data, size_t n, off_t offset)
1274 {
1275         struct tevent_req *req, *subreq;
1276         struct smb_full_audit_pwrite_state *state;
1277
1278         req = tevent_req_create(mem_ctx, &state,
1279                                 struct smb_full_audit_pwrite_state);
1280         if (req == NULL) {
1281                 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1282                        fsp_str_do_log(fsp));
1283                 return NULL;
1284         }
1285         state->handle = handle;
1286         state->fsp = fsp;
1287
1288         subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
1289                                          n, offset);
1290         if (tevent_req_nomem(subreq, req)) {
1291                 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1292                        fsp_str_do_log(fsp));
1293                 return tevent_req_post(req, ev);
1294         }
1295         tevent_req_set_callback(subreq, smb_full_audit_pwrite_done, req);
1296
1297         do_log(SMB_VFS_OP_PWRITE_SEND, true, handle, "%s",
1298                fsp_str_do_log(fsp));
1299         return req;
1300 }
1301
1302 static void smb_full_audit_pwrite_done(struct tevent_req *subreq)
1303 {
1304         struct tevent_req *req = tevent_req_callback_data(
1305                 subreq, struct tevent_req);
1306         struct smb_full_audit_pwrite_state *state = tevent_req_data(
1307                 req, struct smb_full_audit_pwrite_state);
1308
1309         state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->vfs_aio_state);
1310         TALLOC_FREE(subreq);
1311         tevent_req_done(req);
1312 }
1313
1314 static ssize_t smb_full_audit_pwrite_recv(struct tevent_req *req,
1315                                           struct vfs_aio_state *vfs_aio_state)
1316 {
1317         struct smb_full_audit_pwrite_state *state = tevent_req_data(
1318                 req, struct smb_full_audit_pwrite_state);
1319
1320         if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1321                 do_log(SMB_VFS_OP_PWRITE_RECV, false, state->handle, "%s",
1322                        fsp_str_do_log(state->fsp));
1323                 return -1;
1324         }
1325
1326         do_log(SMB_VFS_OP_PWRITE_RECV, (state->ret >= 0), state->handle, "%s",
1327                fsp_str_do_log(state->fsp));
1328
1329         *vfs_aio_state = state->vfs_aio_state;
1330         return state->ret;
1331 }
1332
1333 static off_t smb_full_audit_lseek(vfs_handle_struct *handle, files_struct *fsp,
1334                              off_t offset, int whence)
1335 {
1336         ssize_t result;
1337
1338         result = SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence);
1339
1340         do_log(SMB_VFS_OP_LSEEK, (result != (ssize_t)-1), handle,
1341                "%s", fsp_str_do_log(fsp));
1342
1343         return result;
1344 }
1345
1346 static ssize_t smb_full_audit_sendfile(vfs_handle_struct *handle, int tofd,
1347                               files_struct *fromfsp,
1348                               const DATA_BLOB *hdr, off_t offset,
1349                               size_t n)
1350 {
1351         ssize_t result;
1352
1353         result = SMB_VFS_NEXT_SENDFILE(handle, tofd, fromfsp, hdr, offset, n);
1354
1355         do_log(SMB_VFS_OP_SENDFILE, (result >= 0), handle,
1356                "%s", fsp_str_do_log(fromfsp));
1357
1358         return result;
1359 }
1360
1361 static ssize_t smb_full_audit_recvfile(vfs_handle_struct *handle, int fromfd,
1362                       files_struct *tofsp,
1363                               off_t offset,
1364                               size_t n)
1365 {
1366         ssize_t result;
1367
1368         result = SMB_VFS_NEXT_RECVFILE(handle, fromfd, tofsp, offset, n);
1369
1370         do_log(SMB_VFS_OP_RECVFILE, (result >= 0), handle,
1371                "%s", fsp_str_do_log(tofsp));
1372
1373         return result;
1374 }
1375
1376 static int smb_full_audit_renameat(vfs_handle_struct *handle,
1377                                 files_struct *srcfsp,
1378                                 const struct smb_filename *smb_fname_src,
1379                                 files_struct *dstfsp,
1380                                 const struct smb_filename *smb_fname_dst)
1381 {
1382         int result;
1383
1384         result = SMB_VFS_NEXT_RENAMEAT(handle,
1385                                 srcfsp,
1386                                 smb_fname_src,
1387                                 dstfsp,
1388                                 smb_fname_dst);
1389
1390         do_log(SMB_VFS_OP_RENAMEAT, (result >= 0), handle, "%s|%s",
1391                smb_fname_str_do_log(handle->conn, smb_fname_src),
1392                smb_fname_str_do_log(handle->conn, smb_fname_dst));
1393
1394         return result;
1395 }
1396
1397 struct smb_full_audit_fsync_state {
1398         vfs_handle_struct *handle;
1399         files_struct *fsp;
1400         int ret;
1401         struct vfs_aio_state vfs_aio_state;
1402 };
1403
1404 static void smb_full_audit_fsync_done(struct tevent_req *subreq);
1405
1406 static struct tevent_req *smb_full_audit_fsync_send(
1407         struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1408         struct tevent_context *ev, struct files_struct *fsp)
1409 {
1410         struct tevent_req *req, *subreq;
1411         struct smb_full_audit_fsync_state *state;
1412
1413         req = tevent_req_create(mem_ctx, &state,
1414                                 struct smb_full_audit_fsync_state);
1415         if (req == NULL) {
1416                 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1417                        fsp_str_do_log(fsp));
1418                 return NULL;
1419         }
1420         state->handle = handle;
1421         state->fsp = fsp;
1422
1423         subreq = SMB_VFS_NEXT_FSYNC_SEND(state, ev, handle, fsp);
1424         if (tevent_req_nomem(subreq, req)) {
1425                 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1426                        fsp_str_do_log(fsp));
1427                 return tevent_req_post(req, ev);
1428         }
1429         tevent_req_set_callback(subreq, smb_full_audit_fsync_done, req);
1430
1431         do_log(SMB_VFS_OP_FSYNC_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1432         return req;
1433 }
1434
1435 static void smb_full_audit_fsync_done(struct tevent_req *subreq)
1436 {
1437         struct tevent_req *req = tevent_req_callback_data(
1438                 subreq, struct tevent_req);
1439         struct smb_full_audit_fsync_state *state = tevent_req_data(
1440                 req, struct smb_full_audit_fsync_state);
1441
1442         state->ret = SMB_VFS_FSYNC_RECV(subreq, &state->vfs_aio_state);
1443         TALLOC_FREE(subreq);
1444         tevent_req_done(req);
1445 }
1446
1447 static int smb_full_audit_fsync_recv(struct tevent_req *req,
1448                                      struct vfs_aio_state *vfs_aio_state)
1449 {
1450         struct smb_full_audit_fsync_state *state = tevent_req_data(
1451                 req, struct smb_full_audit_fsync_state);
1452
1453         if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1454                 do_log(SMB_VFS_OP_FSYNC_RECV, false, state->handle, "%s",
1455                        fsp_str_do_log(state->fsp));
1456                 return -1;
1457         }
1458
1459         do_log(SMB_VFS_OP_FSYNC_RECV, (state->ret >= 0), state->handle, "%s",
1460                fsp_str_do_log(state->fsp));
1461
1462         *vfs_aio_state = state->vfs_aio_state;
1463         return state->ret;
1464 }
1465
1466 static int smb_full_audit_stat(vfs_handle_struct *handle,
1467                                struct smb_filename *smb_fname)
1468 {
1469         int result;
1470         
1471         result = SMB_VFS_NEXT_STAT(handle, smb_fname);
1472
1473         do_log(SMB_VFS_OP_STAT, (result >= 0), handle, "%s",
1474                smb_fname_str_do_log(handle->conn, smb_fname));
1475
1476         return result;    
1477 }
1478
1479 static int smb_full_audit_fstat(vfs_handle_struct *handle, files_struct *fsp,
1480                        SMB_STRUCT_STAT *sbuf)
1481 {
1482         int result;
1483         
1484         result = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1485
1486         do_log(SMB_VFS_OP_FSTAT, (result >= 0), handle, "%s",
1487                fsp_str_do_log(fsp));
1488
1489         return result;
1490 }
1491
1492 static int smb_full_audit_lstat(vfs_handle_struct *handle,
1493                                 struct smb_filename *smb_fname)
1494 {
1495         int result;
1496         
1497         result = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
1498
1499         do_log(SMB_VFS_OP_LSTAT, (result >= 0), handle, "%s",
1500                smb_fname_str_do_log(handle->conn, smb_fname));
1501
1502         return result;    
1503 }
1504
1505 static uint64_t smb_full_audit_get_alloc_size(vfs_handle_struct *handle,
1506                        files_struct *fsp, const SMB_STRUCT_STAT *sbuf)
1507 {
1508         uint64_t result;
1509
1510         result = SMB_VFS_NEXT_GET_ALLOC_SIZE(handle, fsp, sbuf);
1511
1512         do_log(SMB_VFS_OP_GET_ALLOC_SIZE, (result != (uint64_t)-1), handle,
1513                         "%llu", (unsigned long long)result);
1514
1515         return result;
1516 }
1517
1518 static int smb_full_audit_unlinkat(vfs_handle_struct *handle,
1519                         struct files_struct *dirfsp,
1520                         const struct smb_filename *smb_fname,
1521                         int flags)
1522 {
1523         int result;
1524
1525         result = SMB_VFS_NEXT_UNLINKAT(handle,
1526                         dirfsp,
1527                         smb_fname,
1528                         flags);
1529
1530         do_log(SMB_VFS_OP_UNLINKAT, (result >= 0), handle, "%s",
1531                smb_fname_str_do_log(handle->conn, smb_fname));
1532
1533         return result;
1534 }
1535
1536 static int smb_full_audit_chmod(vfs_handle_struct *handle,
1537                                 const struct smb_filename *smb_fname,
1538                                 mode_t mode)
1539 {
1540         int result;
1541
1542         result = SMB_VFS_NEXT_CHMOD(handle, smb_fname, mode);
1543
1544         do_log(SMB_VFS_OP_CHMOD,
1545                (result >= 0),
1546                handle,
1547                "%s|%o",
1548                smb_fname_str_do_log(handle->conn, smb_fname),
1549                mode);
1550
1551         return result;
1552 }
1553
1554 static int smb_full_audit_fchmod(vfs_handle_struct *handle, files_struct *fsp,
1555                         mode_t mode)
1556 {
1557         int result;
1558         
1559         result = SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1560
1561         do_log(SMB_VFS_OP_FCHMOD, (result >= 0), handle,
1562                "%s|%o", fsp_str_do_log(fsp), mode);
1563
1564         return result;
1565 }
1566
1567 static int smb_full_audit_chown(vfs_handle_struct *handle,
1568                         const struct smb_filename *smb_fname,
1569                         uid_t uid,
1570                         gid_t gid)
1571 {
1572         int result;
1573
1574         result = SMB_VFS_NEXT_CHOWN(handle, smb_fname, uid, gid);
1575
1576         do_log(SMB_VFS_OP_CHOWN, (result >= 0), handle, "%s|%ld|%ld",
1577                smb_fname->base_name, (long int)uid, (long int)gid);
1578
1579         return result;
1580 }
1581
1582 static int smb_full_audit_fchown(vfs_handle_struct *handle, files_struct *fsp,
1583                         uid_t uid, gid_t gid)
1584 {
1585         int result;
1586
1587         result = SMB_VFS_NEXT_FCHOWN(handle, fsp, uid, gid);
1588
1589         do_log(SMB_VFS_OP_FCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1590                fsp_str_do_log(fsp), (long int)uid, (long int)gid);
1591
1592         return result;
1593 }
1594
1595 static int smb_full_audit_lchown(vfs_handle_struct *handle,
1596                         const struct smb_filename *smb_fname,
1597                         uid_t uid,
1598                         gid_t gid)
1599 {
1600         int result;
1601
1602         result = SMB_VFS_NEXT_LCHOWN(handle, smb_fname, uid, gid);
1603
1604         do_log(SMB_VFS_OP_LCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1605                smb_fname->base_name, (long int)uid, (long int)gid);
1606
1607         return result;
1608 }
1609
1610 static int smb_full_audit_chdir(vfs_handle_struct *handle,
1611                         const struct smb_filename *smb_fname)
1612 {
1613         int result;
1614
1615         result = SMB_VFS_NEXT_CHDIR(handle, smb_fname);
1616
1617         do_log(SMB_VFS_OP_CHDIR,
1618                (result >= 0),
1619                handle,
1620                "chdir|%s",
1621                smb_fname_str_do_log(handle->conn, smb_fname));
1622
1623         return result;
1624 }
1625
1626 static struct smb_filename *smb_full_audit_getwd(vfs_handle_struct *handle,
1627                                 TALLOC_CTX *ctx)
1628 {
1629         struct smb_filename *result;
1630
1631         result = SMB_VFS_NEXT_GETWD(handle, ctx);
1632         
1633         do_log(SMB_VFS_OP_GETWD, (result != NULL), handle, "%s",
1634                 result == NULL? "" : result->base_name);
1635
1636         return result;
1637 }
1638
1639 static int smb_full_audit_ntimes(vfs_handle_struct *handle,
1640                                  const struct smb_filename *smb_fname,
1641                                  struct smb_file_time *ft)
1642 {
1643         int result;
1644         time_t create_time = convert_timespec_to_time_t(ft->create_time);
1645         time_t atime = convert_timespec_to_time_t(ft->atime);
1646         time_t mtime = convert_timespec_to_time_t(ft->mtime);
1647         time_t ctime = convert_timespec_to_time_t(ft->ctime);
1648         const char *create_time_str = "";
1649         const char *atime_str = "";
1650         const char *mtime_str = "";
1651         const char *ctime_str = "";
1652         TALLOC_CTX *frame = talloc_stackframe();
1653
1654         result = SMB_VFS_NEXT_NTIMES(handle, smb_fname, ft);
1655
1656         if (create_time > 0) {
1657                 create_time_str = timestring(frame, create_time);
1658         }
1659         if (atime > 0) {
1660                 atime_str = timestring(frame, atime);
1661         }
1662         if (mtime > 0) {
1663                 mtime_str = timestring(frame, mtime);
1664         }
1665         if (ctime > 0) {
1666                 ctime_str = timestring(frame, ctime);
1667         }
1668
1669         do_log(SMB_VFS_OP_NTIMES,
1670                (result >= 0),
1671                handle,
1672                "%s|%s|%s|%s|%s",
1673                smb_fname_str_do_log(handle->conn, smb_fname),
1674                create_time_str,
1675                atime_str,
1676                mtime_str,
1677                ctime_str);
1678
1679         TALLOC_FREE(frame);
1680
1681         return result;
1682 }
1683
1684 static int smb_full_audit_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
1685                            off_t len)
1686 {
1687         int result;
1688
1689         result = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1690
1691         do_log(SMB_VFS_OP_FTRUNCATE, (result >= 0), handle,
1692                "%s", fsp_str_do_log(fsp));
1693
1694         return result;
1695 }
1696
1697 static int smb_full_audit_fallocate(vfs_handle_struct *handle, files_struct *fsp,
1698                            uint32_t mode,
1699                            off_t offset,
1700                            off_t len)
1701 {
1702         int result;
1703
1704         result = SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
1705
1706         do_log(SMB_VFS_OP_FALLOCATE, (result >= 0), handle,
1707                "%s", fsp_str_do_log(fsp));
1708
1709         return result;
1710 }
1711
1712 static bool smb_full_audit_lock(vfs_handle_struct *handle, files_struct *fsp,
1713                        int op, off_t offset, off_t count, int type)
1714 {
1715         bool result;
1716
1717         result = SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type);
1718
1719         do_log(SMB_VFS_OP_LOCK, result, handle, "%s", fsp_str_do_log(fsp));
1720
1721         return result;
1722 }
1723
1724 static int smb_full_audit_kernel_flock(struct vfs_handle_struct *handle,
1725                                        struct files_struct *fsp,
1726                                        uint32_t share_mode, uint32_t access_mask)
1727 {
1728         int result;
1729
1730         result = SMB_VFS_NEXT_KERNEL_FLOCK(handle, fsp, share_mode, access_mask);
1731
1732         do_log(SMB_VFS_OP_KERNEL_FLOCK, (result >= 0), handle, "%s",
1733                fsp_str_do_log(fsp));
1734
1735         return result;
1736 }
1737
1738 static int smb_full_audit_fcntl(struct vfs_handle_struct *handle,
1739                                 struct files_struct *fsp,
1740                                 int cmd, va_list cmd_arg)
1741 {
1742         void *arg;
1743         va_list dup_cmd_arg;
1744         int result;
1745
1746         va_copy(dup_cmd_arg, cmd_arg);
1747         arg = va_arg(dup_cmd_arg, void *);
1748         result = SMB_VFS_NEXT_FCNTL(handle, fsp, cmd, arg);
1749         va_end(dup_cmd_arg);
1750
1751         do_log(SMB_VFS_OP_FCNTL, (result >= 0), handle, "%s",
1752                fsp_str_do_log(fsp));
1753
1754         return result;
1755 }
1756
1757 static int smb_full_audit_linux_setlease(vfs_handle_struct *handle, files_struct *fsp,
1758                                  int leasetype)
1759 {
1760         int result;
1761
1762         result = SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
1763
1764         do_log(SMB_VFS_OP_LINUX_SETLEASE, (result >= 0), handle, "%s",
1765                fsp_str_do_log(fsp));
1766
1767         return result;
1768 }
1769
1770 static bool smb_full_audit_getlock(vfs_handle_struct *handle, files_struct *fsp,
1771                        off_t *poffset, off_t *pcount, int *ptype, pid_t *ppid)
1772 {
1773         bool result;
1774
1775         result = SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype, ppid);
1776
1777         do_log(SMB_VFS_OP_GETLOCK, result, handle, "%s", fsp_str_do_log(fsp));
1778
1779         return result;
1780 }
1781
1782 static int smb_full_audit_symlinkat(vfs_handle_struct *handle,
1783                         const char *link_contents,
1784                         struct files_struct *dirfsp,
1785                         const struct smb_filename *new_smb_fname)
1786 {
1787         int result;
1788
1789         result = SMB_VFS_NEXT_SYMLINKAT(handle,
1790                                 link_contents,
1791                                 dirfsp,
1792                                 new_smb_fname);
1793
1794         do_log(SMB_VFS_OP_SYMLINKAT,
1795                (result >= 0),
1796                handle,
1797                "%s|%s",
1798                link_contents,
1799                smb_fname_str_do_log(handle->conn, new_smb_fname));
1800
1801         return result;
1802 }
1803
1804 static int smb_full_audit_readlinkat(vfs_handle_struct *handle,
1805                         files_struct *dirfsp,
1806                         const struct smb_filename *smb_fname,
1807                         char *buf,
1808                         size_t bufsiz)
1809 {
1810         int result;
1811
1812         result = SMB_VFS_NEXT_READLINKAT(handle,
1813                         dirfsp,
1814                         smb_fname,
1815                         buf,
1816                         bufsiz);
1817
1818         do_log(SMB_VFS_OP_READLINKAT,
1819                (result >= 0),
1820                handle,
1821                "%s",
1822                smb_fname_str_do_log(handle->conn, smb_fname));
1823
1824         return result;
1825 }
1826
1827 static int smb_full_audit_linkat(vfs_handle_struct *handle,
1828                         files_struct *srcfsp,
1829                         const struct smb_filename *old_smb_fname,
1830                         files_struct *dstfsp,
1831                         const struct smb_filename *new_smb_fname,
1832                         int flags)
1833 {
1834         int result;
1835
1836         result = SMB_VFS_NEXT_LINKAT(handle,
1837                         srcfsp,
1838                         old_smb_fname,
1839                         dstfsp,
1840                         new_smb_fname,
1841                         flags);
1842
1843         do_log(SMB_VFS_OP_LINKAT,
1844                (result >= 0),
1845                handle,
1846                "%s|%s",
1847                smb_fname_str_do_log(handle->conn, old_smb_fname),
1848                smb_fname_str_do_log(handle->conn, new_smb_fname));
1849
1850         return result;
1851 }
1852
1853 static int smb_full_audit_mknodat(vfs_handle_struct *handle,
1854                         files_struct *dirfsp,
1855                         const struct smb_filename *smb_fname,
1856                         mode_t mode,
1857                         SMB_DEV_T dev)
1858 {
1859         int result;
1860
1861         result = SMB_VFS_NEXT_MKNODAT(handle,
1862                                 dirfsp,
1863                                 smb_fname,
1864                                 mode,
1865                                 dev);
1866
1867         do_log(SMB_VFS_OP_MKNODAT,
1868                (result >= 0),
1869                handle,
1870                "%s",
1871                smb_fname_str_do_log(handle->conn, smb_fname));
1872
1873         return result;
1874 }
1875
1876 static struct smb_filename *smb_full_audit_realpath(vfs_handle_struct *handle,
1877                                 TALLOC_CTX *ctx,
1878                                 const struct smb_filename *smb_fname)
1879 {
1880         struct smb_filename *result_fname = NULL;
1881
1882         result_fname = SMB_VFS_NEXT_REALPATH(handle, ctx, smb_fname);
1883
1884         do_log(SMB_VFS_OP_REALPATH,
1885                (result_fname != NULL),
1886                handle,
1887                "%s",
1888                smb_fname_str_do_log(handle->conn, smb_fname));
1889
1890         return result_fname;
1891 }
1892
1893 static int smb_full_audit_chflags(vfs_handle_struct *handle,
1894                         const struct smb_filename *smb_fname,
1895                         unsigned int flags)
1896 {
1897         int result;
1898
1899         result = SMB_VFS_NEXT_CHFLAGS(handle, smb_fname, flags);
1900
1901         do_log(SMB_VFS_OP_CHFLAGS,
1902                (result != 0),
1903                handle,
1904                "%s",
1905                smb_fname_str_do_log(handle->conn, smb_fname));
1906
1907         return result;
1908 }
1909
1910 static struct file_id smb_full_audit_file_id_create(struct vfs_handle_struct *handle,
1911                                                     const SMB_STRUCT_STAT *sbuf)
1912 {
1913         struct file_id id_zero;
1914         struct file_id result;
1915
1916         ZERO_STRUCT(id_zero);
1917
1918         result = SMB_VFS_NEXT_FILE_ID_CREATE(handle, sbuf);
1919
1920         do_log(SMB_VFS_OP_FILE_ID_CREATE,
1921                !file_id_equal(&id_zero, &result),
1922                handle, "%s", file_id_string_tos(&result));
1923
1924         return result;
1925 }
1926
1927 static uint64_t smb_full_audit_fs_file_id(struct vfs_handle_struct *handle,
1928                                           const SMB_STRUCT_STAT *sbuf)
1929 {
1930         uint64_t result;
1931
1932         result = SMB_VFS_NEXT_FS_FILE_ID(handle, sbuf);
1933
1934         do_log(SMB_VFS_OP_FS_FILE_ID,
1935                result != 0,
1936                handle, "%" PRIu64, result);
1937
1938         return result;
1939 }
1940
1941 static NTSTATUS smb_full_audit_streaminfo(vfs_handle_struct *handle,
1942                                           struct files_struct *fsp,
1943                                           const struct smb_filename *smb_fname,
1944                                           TALLOC_CTX *mem_ctx,
1945                                           unsigned int *pnum_streams,
1946                                           struct stream_struct **pstreams)
1947 {
1948         NTSTATUS result;
1949
1950         result = SMB_VFS_NEXT_STREAMINFO(handle, fsp, smb_fname, mem_ctx,
1951                                          pnum_streams, pstreams);
1952
1953         do_log(SMB_VFS_OP_STREAMINFO,
1954                NT_STATUS_IS_OK(result),
1955                handle,
1956                "%s",
1957                smb_fname_str_do_log(handle->conn, smb_fname));
1958
1959         return result;
1960 }
1961
1962 static int smb_full_audit_get_real_filename(struct vfs_handle_struct *handle,
1963                                             const char *path,
1964                                             const char *name,
1965                                             TALLOC_CTX *mem_ctx,
1966                                             char **found_name)
1967 {
1968         int result;
1969
1970         result = SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name, mem_ctx,
1971                                                 found_name);
1972
1973         do_log(SMB_VFS_OP_GET_REAL_FILENAME, (result == 0), handle,
1974                "%s/%s->%s", path, name, (result == 0) ? *found_name : "");
1975
1976         return result;
1977 }
1978
1979 static const char *smb_full_audit_connectpath(vfs_handle_struct *handle,
1980                                         const struct smb_filename *smb_fname)
1981 {
1982         const char *result;
1983
1984         result = SMB_VFS_NEXT_CONNECTPATH(handle, smb_fname);
1985
1986         do_log(SMB_VFS_OP_CONNECTPATH,
1987                result != NULL,
1988                handle,
1989                "%s",
1990                smb_fname_str_do_log(handle->conn, smb_fname));
1991
1992         return result;
1993 }
1994
1995 static NTSTATUS smb_full_audit_brl_lock_windows(struct vfs_handle_struct *handle,
1996                                                 struct byte_range_lock *br_lck,
1997                                                 struct lock_struct *plock)
1998 {
1999         NTSTATUS result;
2000
2001         result = SMB_VFS_NEXT_BRL_LOCK_WINDOWS(handle, br_lck, plock);
2002
2003         do_log(SMB_VFS_OP_BRL_LOCK_WINDOWS, NT_STATUS_IS_OK(result), handle,
2004             "%s:%llu-%llu. type=%d.",
2005                fsp_str_do_log(brl_fsp(br_lck)),
2006                (unsigned long long)plock->start,
2007                (unsigned long long)plock->size,
2008                plock->lock_type);
2009
2010         return result;
2011 }
2012
2013 static bool smb_full_audit_brl_unlock_windows(struct vfs_handle_struct *handle,
2014                                               struct byte_range_lock *br_lck,
2015                                               const struct lock_struct *plock)
2016 {
2017         bool result;
2018
2019         result = SMB_VFS_NEXT_BRL_UNLOCK_WINDOWS(handle, br_lck, plock);
2020
2021         do_log(SMB_VFS_OP_BRL_UNLOCK_WINDOWS, (result == 0), handle,
2022                "%s:%llu-%llu:%d", fsp_str_do_log(brl_fsp(br_lck)),
2023                (unsigned long long)plock->start,
2024                (unsigned long long)plock->size,
2025                plock->lock_type);
2026
2027         return result;
2028 }
2029
2030 static bool smb_full_audit_strict_lock_check(struct vfs_handle_struct *handle,
2031                                              struct files_struct *fsp,
2032                                              struct lock_struct *plock)
2033 {
2034         bool result;
2035
2036         result = SMB_VFS_NEXT_STRICT_LOCK_CHECK(handle, fsp, plock);
2037
2038         do_log(SMB_VFS_OP_STRICT_LOCK_CHECK, result, handle,
2039                "%s:%llu-%llu:%d", fsp_str_do_log(fsp),
2040                (unsigned long long)plock->start,
2041                (unsigned long long)plock->size,
2042                plock->lock_type);
2043
2044         return result;
2045 }
2046
2047 static NTSTATUS smb_full_audit_translate_name(struct vfs_handle_struct *handle,
2048                                               const char *name,
2049                                               enum vfs_translate_direction direction,
2050                                               TALLOC_CTX *mem_ctx,
2051                                               char **mapped_name)
2052 {
2053         NTSTATUS result;
2054
2055         result = SMB_VFS_NEXT_TRANSLATE_NAME(handle, name, direction, mem_ctx,
2056                                              mapped_name);
2057
2058         do_log(SMB_VFS_OP_TRANSLATE_NAME, NT_STATUS_IS_OK(result), handle, "");
2059
2060         return result;
2061 }
2062
2063 static NTSTATUS smb_full_audit_fsctl(struct vfs_handle_struct *handle,
2064                                 struct files_struct *fsp,
2065                                 TALLOC_CTX *ctx,
2066                                 uint32_t function,
2067                                 uint16_t req_flags,
2068                                 const uint8_t *_in_data,
2069                                 uint32_t in_len,
2070                                 uint8_t **_out_data,
2071                                 uint32_t max_out_len,
2072                                 uint32_t *out_len)
2073 {
2074         NTSTATUS result;
2075
2076         result = SMB_VFS_NEXT_FSCTL(handle,
2077                                 fsp,
2078                                 ctx,
2079                                 function,
2080                                 req_flags,
2081                                 _in_data,
2082                                 in_len,
2083                                 _out_data,
2084                                 max_out_len,
2085                                 out_len);
2086
2087         do_log(SMB_VFS_OP_FSCTL, NT_STATUS_IS_OK(result), handle, "");
2088
2089         return result;
2090 }
2091
2092 static struct tevent_req *smb_full_audit_offload_read_send(
2093         TALLOC_CTX *mem_ctx,
2094         struct tevent_context *ev,
2095         struct vfs_handle_struct *handle,
2096         struct files_struct *fsp,
2097         uint32_t fsctl,
2098         uint32_t ttl,
2099         off_t offset,
2100         size_t to_copy)
2101 {
2102         struct tevent_req *req = NULL;
2103
2104         req = SMB_VFS_NEXT_OFFLOAD_READ_SEND(mem_ctx, ev, handle, fsp,
2105                                              fsctl, ttl, offset, to_copy);
2106
2107         do_log(SMB_VFS_OP_OFFLOAD_READ_SEND, req, handle, "");
2108
2109         return req;
2110 }
2111
2112 static NTSTATUS smb_full_audit_offload_read_recv(
2113         struct tevent_req *req,
2114         struct vfs_handle_struct *handle,
2115         TALLOC_CTX *mem_ctx,
2116         DATA_BLOB *_token_blob)
2117 {
2118         NTSTATUS status;
2119
2120         status = SMB_VFS_NEXT_OFFLOAD_READ_RECV(req, handle, mem_ctx,
2121                                                 _token_blob);
2122
2123         do_log(SMB_VFS_OP_OFFLOAD_READ_RECV, NT_STATUS_IS_OK(status), handle, "");
2124
2125         return status;
2126 }
2127
2128 static struct tevent_req *smb_full_audit_offload_write_send(struct vfs_handle_struct *handle,
2129                                                          TALLOC_CTX *mem_ctx,
2130                                                          struct tevent_context *ev,
2131                                                          uint32_t fsctl,
2132                                                          DATA_BLOB *token,
2133                                                          off_t transfer_offset,
2134                                                          struct files_struct *dest_fsp,
2135                                                          off_t dest_off,
2136                                                             off_t num)
2137 {
2138         struct tevent_req *req;
2139
2140         req = SMB_VFS_NEXT_OFFLOAD_WRITE_SEND(handle, mem_ctx, ev,
2141                                            fsctl, token, transfer_offset,
2142                                            dest_fsp, dest_off, num);
2143
2144         do_log(SMB_VFS_OP_OFFLOAD_WRITE_SEND, req, handle, "");
2145
2146         return req;
2147 }
2148
2149 static NTSTATUS smb_full_audit_offload_write_recv(struct vfs_handle_struct *handle,
2150                                                struct tevent_req *req,
2151                                                off_t *copied)
2152 {
2153         NTSTATUS result;
2154
2155         result = SMB_VFS_NEXT_OFFLOAD_WRITE_RECV(handle, req, copied);
2156
2157         do_log(SMB_VFS_OP_OFFLOAD_WRITE_RECV, NT_STATUS_IS_OK(result), handle, "");
2158
2159         return result;
2160 }
2161
2162 static NTSTATUS smb_full_audit_get_compression(vfs_handle_struct *handle,
2163                                                TALLOC_CTX *mem_ctx,
2164                                                struct files_struct *fsp,
2165                                                struct smb_filename *smb_fname,
2166                                                uint16_t *_compression_fmt)
2167 {
2168         NTSTATUS result;
2169
2170         result = SMB_VFS_NEXT_GET_COMPRESSION(handle, mem_ctx, fsp, smb_fname,
2171                                               _compression_fmt);
2172
2173         do_log(SMB_VFS_OP_GET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
2174                "%s",
2175                (fsp ? fsp_str_do_log(fsp) :
2176                 smb_fname_str_do_log(handle->conn, smb_fname)));
2177
2178         return result;
2179 }
2180
2181 static NTSTATUS smb_full_audit_set_compression(vfs_handle_struct *handle,
2182                                                TALLOC_CTX *mem_ctx,
2183                                                struct files_struct *fsp,
2184                                                uint16_t compression_fmt)
2185 {
2186         NTSTATUS result;
2187
2188         result = SMB_VFS_NEXT_SET_COMPRESSION(handle, mem_ctx, fsp,
2189                                               compression_fmt);
2190
2191         do_log(SMB_VFS_OP_SET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
2192                "%s", fsp_str_do_log(fsp));
2193
2194         return result;
2195 }
2196
2197 static NTSTATUS smb_full_audit_readdir_attr(struct vfs_handle_struct *handle,
2198                                             const struct smb_filename *fname,
2199                                             TALLOC_CTX *mem_ctx,
2200                                             struct readdir_attr_data **pattr_data)
2201 {
2202         NTSTATUS status;
2203
2204         status = SMB_VFS_NEXT_READDIR_ATTR(handle, fname, mem_ctx, pattr_data);
2205
2206         do_log(SMB_VFS_OP_READDIR_ATTR, NT_STATUS_IS_OK(status), handle, "%s",
2207                smb_fname_str_do_log(handle->conn, fname));
2208
2209         return status;
2210 }
2211
2212 static NTSTATUS smb_full_audit_get_dos_attributes(
2213                                 struct vfs_handle_struct *handle,
2214                                 struct smb_filename *smb_fname,
2215                                 uint32_t *dosmode)
2216 {
2217         NTSTATUS status;
2218
2219         status = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES(handle,
2220                                 smb_fname,
2221                                 dosmode);
2222
2223         do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES,
2224                 NT_STATUS_IS_OK(status),
2225                 handle,
2226                 "%s",
2227                 smb_fname_str_do_log(handle->conn, smb_fname));
2228
2229         return status;
2230 }
2231
2232 struct smb_full_audit_get_dos_attributes_state {
2233         struct vfs_aio_state aio_state;
2234         vfs_handle_struct *handle;
2235         files_struct *dir_fsp;
2236         const struct smb_filename *smb_fname;
2237         uint32_t dosmode;
2238 };
2239
2240 static void smb_full_audit_get_dos_attributes_done(struct tevent_req *subreq);
2241
2242 static struct tevent_req *smb_full_audit_get_dos_attributes_send(
2243                 TALLOC_CTX *mem_ctx,
2244                 struct tevent_context *ev,
2245                 struct vfs_handle_struct *handle,
2246                 files_struct *dir_fsp,
2247                 struct smb_filename *smb_fname)
2248 {
2249         struct tevent_req *req = NULL;
2250         struct smb_full_audit_get_dos_attributes_state *state = NULL;
2251         struct tevent_req *subreq = NULL;
2252
2253         req = tevent_req_create(mem_ctx, &state,
2254                                 struct smb_full_audit_get_dos_attributes_state);
2255         if (req == NULL) {
2256                 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2257                        false,
2258                        handle,
2259                        "%s/%s",
2260                        fsp_str_do_log(dir_fsp),
2261                        smb_fname->base_name);
2262                 return NULL;
2263         }
2264         *state = (struct smb_full_audit_get_dos_attributes_state) {
2265                 .handle = handle,
2266                 .dir_fsp = dir_fsp,
2267                 .smb_fname = smb_fname,
2268         };
2269
2270         subreq = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES_SEND(mem_ctx,
2271                                                       ev,
2272                                                       handle,
2273                                                       dir_fsp,
2274                                                       smb_fname);
2275         if (tevent_req_nomem(subreq, req)) {
2276                 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2277                        false,
2278                        handle,
2279                        "%s/%s",
2280                        fsp_str_do_log(dir_fsp),
2281                        smb_fname->base_name);
2282                 return tevent_req_post(req, ev);
2283         }
2284         tevent_req_set_callback(subreq,
2285                                 smb_full_audit_get_dos_attributes_done,
2286                                 req);
2287
2288         do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2289                true,
2290                handle,
2291                "%s/%s",
2292                fsp_str_do_log(dir_fsp),
2293                smb_fname->base_name);
2294
2295         return req;
2296 }
2297
2298 static void smb_full_audit_get_dos_attributes_done(struct tevent_req *subreq)
2299 {
2300         struct tevent_req *req =
2301                 tevent_req_callback_data(subreq,
2302                 struct tevent_req);
2303         struct smb_full_audit_get_dos_attributes_state *state =
2304                 tevent_req_data(req,
2305                 struct smb_full_audit_get_dos_attributes_state);
2306         NTSTATUS status;
2307
2308         status = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES_RECV(subreq,
2309                                                       &state->aio_state,
2310                                                       &state->dosmode);
2311         TALLOC_FREE(subreq);
2312         if (tevent_req_nterror(req, status)) {
2313                 return;
2314         }
2315
2316         tevent_req_done(req);
2317         return;
2318 }
2319
2320 static NTSTATUS smb_full_audit_get_dos_attributes_recv(struct tevent_req *req,
2321                                                 struct vfs_aio_state *aio_state,
2322                                                 uint32_t *dosmode)
2323 {
2324         struct smb_full_audit_get_dos_attributes_state *state =
2325                 tevent_req_data(req,
2326                 struct smb_full_audit_get_dos_attributes_state);
2327         NTSTATUS status;
2328
2329         if (tevent_req_is_nterror(req, &status)) {
2330                 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV,
2331                        false,
2332                        state->handle,
2333                        "%s/%s",
2334                        fsp_str_do_log(state->dir_fsp),
2335                        state->smb_fname->base_name);
2336                 tevent_req_received(req);
2337                 return status;
2338         }
2339
2340         do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV,
2341                true,
2342                state->handle,
2343                "%s/%s",
2344                fsp_str_do_log(state->dir_fsp),
2345                state->smb_fname->base_name);
2346
2347         *aio_state = state->aio_state;
2348         *dosmode = state->dosmode;
2349         tevent_req_received(req);
2350         return NT_STATUS_OK;
2351 }
2352
2353 static NTSTATUS smb_full_audit_fget_dos_attributes(
2354                                 struct vfs_handle_struct *handle,
2355                                 struct files_struct *fsp,
2356                                 uint32_t *dosmode)
2357 {
2358         NTSTATUS status;
2359
2360         status = SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle,
2361                                 fsp,
2362                                 dosmode);
2363
2364         do_log(SMB_VFS_OP_FGET_DOS_ATTRIBUTES,
2365                 NT_STATUS_IS_OK(status),
2366                 handle,
2367                 "%s",
2368                 fsp_str_do_log(fsp));
2369
2370         return status;
2371 }
2372
2373 static NTSTATUS smb_full_audit_set_dos_attributes(
2374                                 struct vfs_handle_struct *handle,
2375                                 const struct smb_filename *smb_fname,
2376                                 uint32_t dosmode)
2377 {
2378         NTSTATUS status;
2379
2380         status = SMB_VFS_NEXT_SET_DOS_ATTRIBUTES(handle,
2381                                 smb_fname,
2382                                 dosmode);
2383
2384         do_log(SMB_VFS_OP_SET_DOS_ATTRIBUTES,
2385                 NT_STATUS_IS_OK(status),
2386                 handle,
2387                 "%s",
2388                 smb_fname_str_do_log(handle->conn, smb_fname));
2389
2390         return status;
2391 }
2392
2393 static NTSTATUS smb_full_audit_fset_dos_attributes(
2394                                 struct vfs_handle_struct *handle,
2395                                 struct files_struct *fsp,
2396                                 uint32_t dosmode)
2397 {
2398         NTSTATUS status;
2399
2400         status = SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle,
2401                                 fsp,
2402                                 dosmode);
2403
2404         do_log(SMB_VFS_OP_FSET_DOS_ATTRIBUTES,
2405                 NT_STATUS_IS_OK(status),
2406                 handle,
2407                 "%s",
2408                 fsp_str_do_log(fsp));
2409
2410         return status;
2411 }
2412
2413 static NTSTATUS smb_full_audit_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
2414                                            uint32_t security_info,
2415                                            TALLOC_CTX *mem_ctx,
2416                                            struct security_descriptor **ppdesc)
2417 {
2418         NTSTATUS result;
2419
2420         result = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
2421                                           mem_ctx, ppdesc);
2422
2423         do_log(SMB_VFS_OP_FGET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2424                "%s", fsp_str_do_log(fsp));
2425
2426         return result;
2427 }
2428
2429 static NTSTATUS smb_full_audit_get_nt_acl(vfs_handle_struct *handle,
2430                                           const struct smb_filename *smb_fname,
2431                                           uint32_t security_info,
2432                                           TALLOC_CTX *mem_ctx,
2433                                           struct security_descriptor **ppdesc)
2434 {
2435         NTSTATUS result;
2436
2437         result = SMB_VFS_NEXT_GET_NT_ACL(handle, smb_fname, security_info,
2438                                          mem_ctx, ppdesc);
2439
2440         do_log(SMB_VFS_OP_GET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2441                "%s", smb_fname_str_do_log(handle->conn, smb_fname));
2442
2443         return result;
2444 }
2445
2446 static NTSTATUS smb_full_audit_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
2447                               uint32_t security_info_sent,
2448                               const struct security_descriptor *psd)
2449 {
2450         struct vfs_full_audit_private_data *pd;
2451         NTSTATUS result;
2452         char *sd = NULL;
2453
2454         SMB_VFS_HANDLE_GET_DATA(handle, pd,
2455                                 struct vfs_full_audit_private_data,
2456                                 return NT_STATUS_INTERNAL_ERROR);
2457
2458         if (pd->log_secdesc) {
2459                 sd = sddl_encode(talloc_tos(), psd, get_global_sam_sid());
2460         }
2461
2462         result = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
2463
2464         do_log(SMB_VFS_OP_FSET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2465                "%s [%s]", fsp_str_do_log(fsp), sd ? sd : "");
2466
2467         TALLOC_FREE(sd);
2468
2469         return result;
2470 }
2471
2472 static NTSTATUS smb_full_audit_audit_file(struct vfs_handle_struct *handle,
2473                                 struct smb_filename *file,
2474                                 struct security_acl *sacl,
2475                                 uint32_t access_requested,
2476                                 uint32_t access_denied)
2477 {
2478         NTSTATUS result;
2479
2480         result = SMB_VFS_NEXT_AUDIT_FILE(handle,
2481                                         file,
2482                                         sacl,
2483                                         access_requested,
2484                                         access_denied);
2485
2486         do_log(SMB_VFS_OP_AUDIT_FILE, NT_STATUS_IS_OK(result), handle,
2487                         "%s",
2488                         smb_fname_str_do_log(handle->conn, file));
2489
2490         return result;
2491 }
2492
2493 static SMB_ACL_T smb_full_audit_sys_acl_get_file(vfs_handle_struct *handle,
2494                                 const struct smb_filename *smb_fname,
2495                                 SMB_ACL_TYPE_T type,
2496                                 TALLOC_CTX *mem_ctx)
2497 {
2498         SMB_ACL_T result;
2499
2500         result = SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, smb_fname,
2501                                 type, mem_ctx);
2502
2503         do_log(SMB_VFS_OP_SYS_ACL_GET_FILE,
2504                (result != NULL),
2505                handle,
2506                "%s",
2507                smb_fname_str_do_log(handle->conn, smb_fname));
2508
2509         return result;
2510 }
2511
2512 static SMB_ACL_T smb_full_audit_sys_acl_get_fd(vfs_handle_struct *handle,
2513                                                files_struct *fsp, TALLOC_CTX *mem_ctx)
2514 {
2515         SMB_ACL_T result;
2516
2517         result = SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp, mem_ctx);
2518
2519         do_log(SMB_VFS_OP_SYS_ACL_GET_FD, (result != NULL), handle,
2520                "%s", fsp_str_do_log(fsp));
2521
2522         return result;
2523 }
2524
2525 static int smb_full_audit_sys_acl_blob_get_file(vfs_handle_struct *handle,
2526                                 const struct smb_filename *smb_fname,
2527                                 TALLOC_CTX *mem_ctx,
2528                                 char **blob_description,
2529                                 DATA_BLOB *blob)
2530 {
2531         int result;
2532
2533         result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FILE(handle, smb_fname,
2534                         mem_ctx, blob_description, blob);
2535
2536         do_log(SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE,
2537                (result >= 0),
2538                handle,
2539                "%s",
2540                smb_fname_str_do_log(handle->conn, smb_fname));
2541
2542         return result;
2543 }
2544
2545 static int smb_full_audit_sys_acl_blob_get_fd(vfs_handle_struct *handle,
2546                                               files_struct *fsp,
2547                                               TALLOC_CTX *mem_ctx,
2548                                               char **blob_description,
2549                                               DATA_BLOB *blob)
2550 {
2551         int result;
2552
2553         result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle, fsp, mem_ctx, blob_description, blob);
2554
2555         do_log(SMB_VFS_OP_SYS_ACL_BLOB_GET_FD, (result >= 0), handle,
2556                "%s", fsp_str_do_log(fsp));
2557
2558         return result;
2559 }
2560
2561 static int smb_full_audit_sys_acl_set_file(vfs_handle_struct *handle,
2562                                 const struct smb_filename *smb_fname,
2563                                 SMB_ACL_TYPE_T acltype,
2564                                 SMB_ACL_T theacl)
2565 {
2566         int result;
2567
2568         result = SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, smb_fname, acltype,
2569                                                theacl);
2570
2571         do_log(SMB_VFS_OP_SYS_ACL_SET_FILE,
2572                (result >= 0),
2573                handle,
2574                "%s",
2575                smb_fname_str_do_log(handle->conn, smb_fname));
2576
2577         return result;
2578 }
2579
2580 static int smb_full_audit_sys_acl_set_fd(vfs_handle_struct *handle, files_struct *fsp,
2581                                 SMB_ACL_T theacl)
2582 {
2583         int result;
2584
2585         result = SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, theacl);
2586
2587         do_log(SMB_VFS_OP_SYS_ACL_SET_FD, (result >= 0), handle,
2588                "%s", fsp_str_do_log(fsp));
2589
2590         return result;
2591 }
2592
2593 static int smb_full_audit_sys_acl_delete_def_file(vfs_handle_struct *handle,
2594                                 const struct smb_filename *smb_fname)
2595 {
2596         int result;
2597
2598         result = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, smb_fname);
2599
2600         do_log(SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE,
2601                (result >= 0),
2602                handle,
2603                "%s",
2604                smb_fname_str_do_log(handle->conn, smb_fname));
2605
2606         return result;
2607 }
2608
2609 static ssize_t smb_full_audit_getxattr(struct vfs_handle_struct *handle,
2610                               const struct smb_filename *smb_fname,
2611                               const char *name, void *value, size_t size)
2612 {
2613         ssize_t result;
2614
2615         result = SMB_VFS_NEXT_GETXATTR(handle, smb_fname, name, value, size);
2616
2617         do_log(SMB_VFS_OP_GETXATTR,
2618                (result >= 0),
2619                handle,
2620                "%s|%s",
2621                smb_fname_str_do_log(handle->conn, smb_fname),
2622                name);
2623
2624         return result;
2625 }
2626
2627 struct smb_full_audit_getxattrat_state {
2628         struct vfs_aio_state aio_state;
2629         vfs_handle_struct *handle;
2630         files_struct *dir_fsp;
2631         const struct smb_filename *smb_fname;
2632         const char *xattr_name;
2633         ssize_t xattr_size;
2634         uint8_t *xattr_value;
2635 };
2636
2637 static void smb_full_audit_getxattrat_done(struct tevent_req *subreq);
2638
2639 static struct tevent_req *smb_full_audit_getxattrat_send(
2640                         TALLOC_CTX *mem_ctx,
2641                         struct tevent_context *ev,
2642                         struct vfs_handle_struct *handle,
2643                         files_struct *dir_fsp,
2644                         const struct smb_filename *smb_fname,
2645                         const char *xattr_name,
2646                         size_t alloc_hint)
2647 {
2648         struct tevent_req *req = NULL;
2649         struct tevent_req *subreq = NULL;
2650         struct smb_full_audit_getxattrat_state *state = NULL;
2651
2652         req = tevent_req_create(mem_ctx, &state,
2653                                 struct smb_full_audit_getxattrat_state);
2654         if (req == NULL) {
2655                 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2656                        false,
2657                        handle,
2658                        "%s/%s|%s",
2659                        fsp_str_do_log(dir_fsp),
2660                        smb_fname->base_name,
2661                        xattr_name);
2662                 return NULL;
2663         }
2664         *state = (struct smb_full_audit_getxattrat_state) {
2665                 .handle = handle,
2666                 .dir_fsp = dir_fsp,
2667                 .smb_fname = smb_fname,
2668                 .xattr_name = xattr_name,
2669         };
2670
2671         subreq = SMB_VFS_NEXT_GETXATTRAT_SEND(state,
2672                                               ev,
2673                                               handle,
2674                                               dir_fsp,
2675                                               smb_fname,
2676                                               xattr_name,
2677                                               alloc_hint);
2678         if (tevent_req_nomem(subreq, req)) {
2679                 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2680                        false,
2681                        handle,
2682                        "%s/%s|%s",
2683                        fsp_str_do_log(dir_fsp),
2684                        smb_fname->base_name,
2685                        xattr_name);
2686                 return tevent_req_post(req, ev);
2687         }
2688         tevent_req_set_callback(subreq, smb_full_audit_getxattrat_done, req);
2689
2690         do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2691                true,
2692                handle,
2693                "%s/%s|%s",
2694                fsp_str_do_log(dir_fsp),
2695                smb_fname->base_name,
2696                xattr_name);
2697
2698         return req;
2699 }
2700
2701 static void smb_full_audit_getxattrat_done(struct tevent_req *subreq)
2702 {
2703         struct tevent_req *req = tevent_req_callback_data(
2704                 subreq, struct tevent_req);
2705         struct smb_full_audit_getxattrat_state *state = tevent_req_data(
2706                 req, struct smb_full_audit_getxattrat_state);
2707
2708         state->xattr_size = SMB_VFS_NEXT_GETXATTRAT_RECV(subreq,
2709                                                          &state->aio_state,
2710                                                          state,
2711                                                          &state->xattr_value);
2712         TALLOC_FREE(subreq);
2713         if (state->xattr_size == -1) {
2714                 tevent_req_error(req, state->aio_state.error);
2715                 return;
2716         }
2717
2718         tevent_req_done(req);
2719 }
2720
2721 static ssize_t smb_full_audit_getxattrat_recv(struct tevent_req *req,
2722                                               struct vfs_aio_state *aio_state,
2723                                               TALLOC_CTX *mem_ctx,
2724                                               uint8_t **xattr_value)
2725 {
2726         struct smb_full_audit_getxattrat_state *state = tevent_req_data(
2727                 req, struct smb_full_audit_getxattrat_state);
2728         ssize_t xattr_size;
2729
2730         if (tevent_req_is_unix_error(req, &aio_state->error)) {
2731                 do_log(SMB_VFS_OP_GETXATTRAT_RECV,
2732                        false,
2733                        state->handle,
2734                        "%s/%s|%s",
2735                        fsp_str_do_log(state->dir_fsp),
2736                        state->smb_fname->base_name,
2737                        state->xattr_name);
2738                 tevent_req_received(req);
2739                 return -1;
2740         }
2741
2742         do_log(SMB_VFS_OP_GETXATTRAT_RECV,
2743                true,
2744                state->handle,
2745                "%s/%s|%s",
2746                fsp_str_do_log(state->dir_fsp),
2747                state->smb_fname->base_name,
2748                state->xattr_name);
2749
2750         *aio_state = state->aio_state;
2751         xattr_size = state->xattr_size;
2752         if (xattr_value != NULL) {
2753                 *xattr_value = talloc_move(mem_ctx, &state->xattr_value);
2754         }
2755
2756         tevent_req_received(req);
2757         return xattr_size;
2758 }
2759
2760 static ssize_t smb_full_audit_fgetxattr(struct vfs_handle_struct *handle,
2761                                struct files_struct *fsp,
2762                                const char *name, void *value, size_t size)
2763 {
2764         ssize_t result;
2765
2766         result = SMB_VFS_NEXT_FGETXATTR(handle, fsp, name, value, size);
2767
2768         do_log(SMB_VFS_OP_FGETXATTR, (result >= 0), handle,
2769                "%s|%s", fsp_str_do_log(fsp), name);
2770
2771         return result;
2772 }
2773
2774 static ssize_t smb_full_audit_listxattr(struct vfs_handle_struct *handle,
2775                                 const struct smb_filename *smb_fname,
2776                                 char *list,
2777                                 size_t size)
2778 {
2779         ssize_t result;
2780
2781         result = SMB_VFS_NEXT_LISTXATTR(handle, smb_fname, list, size);
2782
2783         do_log(SMB_VFS_OP_LISTXATTR,
2784                (result >= 0),
2785                handle,
2786                "%s",
2787                smb_fname_str_do_log(handle->conn, smb_fname));
2788
2789         return result;
2790 }
2791
2792 static ssize_t smb_full_audit_flistxattr(struct vfs_handle_struct *handle,
2793                                 struct files_struct *fsp, char *list,
2794                                 size_t size)
2795 {
2796         ssize_t result;
2797
2798         result = SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
2799
2800         do_log(SMB_VFS_OP_FLISTXATTR, (result >= 0), handle,
2801                "%s", fsp_str_do_log(fsp));
2802
2803         return result;
2804 }
2805
2806 static int smb_full_audit_removexattr(struct vfs_handle_struct *handle,
2807                              const struct smb_filename *smb_fname,
2808                              const char *name)
2809 {
2810         int result;
2811
2812         result = SMB_VFS_NEXT_REMOVEXATTR(handle, smb_fname, name);
2813
2814         do_log(SMB_VFS_OP_REMOVEXATTR,
2815                (result >= 0),
2816                handle,
2817                "%s|%s",
2818                smb_fname_str_do_log(handle->conn, smb_fname),
2819                name);
2820
2821         return result;
2822 }
2823
2824 static int smb_full_audit_fremovexattr(struct vfs_handle_struct *handle,
2825                               struct files_struct *fsp,
2826                               const char *name)
2827 {
2828         int result;
2829
2830         result = SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, name);
2831
2832         do_log(SMB_VFS_OP_FREMOVEXATTR, (result >= 0), handle,
2833                "%s|%s", fsp_str_do_log(fsp), name);
2834
2835         return result;
2836 }
2837
2838 static int smb_full_audit_setxattr(struct vfs_handle_struct *handle,
2839                           const struct smb_filename *smb_fname,
2840                           const char *name, const void *value, size_t size,
2841                           int flags)
2842 {
2843         int result;
2844
2845         result = SMB_VFS_NEXT_SETXATTR(handle, smb_fname, name, value, size,
2846                                        flags);
2847
2848         do_log(SMB_VFS_OP_SETXATTR,
2849                (result >= 0),
2850                handle,
2851                "%s|%s",
2852                smb_fname_str_do_log(handle->conn, smb_fname),
2853                name);
2854
2855         return result;
2856 }
2857
2858 static int smb_full_audit_fsetxattr(struct vfs_handle_struct *handle,
2859                            struct files_struct *fsp, const char *name,
2860                            const void *value, size_t size, int flags)
2861 {
2862         int result;
2863
2864         result = SMB_VFS_NEXT_FSETXATTR(handle, fsp, name, value, size, flags);
2865
2866         do_log(SMB_VFS_OP_FSETXATTR, (result >= 0), handle,
2867                "%s|%s", fsp_str_do_log(fsp), name);
2868
2869         return result;
2870 }
2871
2872 static bool smb_full_audit_aio_force(struct vfs_handle_struct *handle,
2873                                      struct files_struct *fsp)
2874 {
2875         bool result;
2876
2877         result = SMB_VFS_NEXT_AIO_FORCE(handle, fsp);
2878         do_log(SMB_VFS_OP_AIO_FORCE, result, handle,
2879                 "%s", fsp_str_do_log(fsp));
2880
2881         return result;
2882 }
2883
2884 static NTSTATUS smb_full_audit_durable_cookie(struct vfs_handle_struct *handle,
2885                                 struct files_struct *fsp,
2886                                 TALLOC_CTX *mem_ctx,
2887                                 DATA_BLOB *cookie)
2888 {
2889         NTSTATUS result;
2890
2891         result = SMB_VFS_NEXT_DURABLE_COOKIE(handle,
2892                                         fsp,
2893                                         mem_ctx,
2894                                         cookie);
2895
2896         do_log(SMB_VFS_OP_DURABLE_COOKIE, NT_STATUS_IS_OK(result), handle,
2897                         "%s", fsp_str_do_log(fsp));
2898
2899         return result;
2900 }
2901
2902 static NTSTATUS smb_full_audit_durable_disconnect(
2903                                 struct vfs_handle_struct *handle,
2904                                 struct files_struct *fsp,
2905                                 const DATA_BLOB old_cookie,
2906                                 TALLOC_CTX *mem_ctx,
2907                                 DATA_BLOB *new_cookie)
2908 {
2909         NTSTATUS result;
2910
2911         result = SMB_VFS_NEXT_DURABLE_DISCONNECT(handle,
2912                                         fsp,
2913                                         old_cookie,
2914                                         mem_ctx,
2915                                         new_cookie);
2916
2917         do_log(SMB_VFS_OP_DURABLE_DISCONNECT, NT_STATUS_IS_OK(result), handle,
2918                         "%s", fsp_str_do_log(fsp));
2919
2920         return result;
2921 }
2922
2923 static NTSTATUS smb_full_audit_durable_reconnect(
2924                                 struct vfs_handle_struct *handle,
2925                                 struct smb_request *smb1req,
2926                                 struct smbXsrv_open *op,
2927                                 const DATA_BLOB old_cookie,
2928                                 TALLOC_CTX *mem_ctx,
2929                                 struct files_struct **fsp,
2930                                 DATA_BLOB *new_cookie)
2931 {
2932         NTSTATUS result;
2933
2934         result = SMB_VFS_NEXT_DURABLE_RECONNECT(handle,
2935                                         smb1req,
2936                                         op,
2937                                         old_cookie,
2938                                         mem_ctx,
2939                                         fsp,
2940                                         new_cookie);
2941
2942         do_log(SMB_VFS_OP_DURABLE_RECONNECT,
2943                         NT_STATUS_IS_OK(result),
2944                         handle,
2945                         "");
2946
2947         return result;
2948 }
2949
2950 static struct vfs_fn_pointers vfs_full_audit_fns = {
2951
2952         /* Disk operations */
2953
2954         .connect_fn = smb_full_audit_connect,
2955         .disconnect_fn = smb_full_audit_disconnect,
2956         .disk_free_fn = smb_full_audit_disk_free,
2957         .get_quota_fn = smb_full_audit_get_quota,
2958         .set_quota_fn = smb_full_audit_set_quota,
2959         .get_shadow_copy_data_fn = smb_full_audit_get_shadow_copy_data,
2960         .statvfs_fn = smb_full_audit_statvfs,
2961         .fs_capabilities_fn = smb_full_audit_fs_capabilities,
2962         .get_dfs_referrals_fn = smb_full_audit_get_dfs_referrals,
2963         .opendir_fn = smb_full_audit_opendir,
2964         .fdopendir_fn = smb_full_audit_fdopendir,
2965         .readdir_fn = smb_full_audit_readdir,
2966         .seekdir_fn = smb_full_audit_seekdir,
2967         .telldir_fn = smb_full_audit_telldir,
2968         .rewind_dir_fn = smb_full_audit_rewinddir,
2969         .mkdirat_fn = smb_full_audit_mkdirat,
2970         .rmdir_fn = smb_full_audit_rmdir,
2971         .closedir_fn = smb_full_audit_closedir,
2972         .open_fn = smb_full_audit_open,
2973         .create_file_fn = smb_full_audit_create_file,
2974         .close_fn = smb_full_audit_close,
2975         .pread_fn = smb_full_audit_pread,
2976         .pread_send_fn = smb_full_audit_pread_send,
2977         .pread_recv_fn = smb_full_audit_pread_recv,
2978         .pwrite_fn = smb_full_audit_pwrite,
2979         .pwrite_send_fn = smb_full_audit_pwrite_send,
2980         .pwrite_recv_fn = smb_full_audit_pwrite_recv,
2981         .lseek_fn = smb_full_audit_lseek,
2982         .sendfile_fn = smb_full_audit_sendfile,
2983         .recvfile_fn = smb_full_audit_recvfile,
2984         .renameat_fn = smb_full_audit_renameat,
2985         .fsync_send_fn = smb_full_audit_fsync_send,
2986         .fsync_recv_fn = smb_full_audit_fsync_recv,
2987         .stat_fn = smb_full_audit_stat,
2988         .fstat_fn = smb_full_audit_fstat,
2989         .lstat_fn = smb_full_audit_lstat,
2990         .get_alloc_size_fn = smb_full_audit_get_alloc_size,
2991         .unlinkat_fn = smb_full_audit_unlinkat,
2992         .chmod_fn = smb_full_audit_chmod,
2993         .fchmod_fn = smb_full_audit_fchmod,
2994         .chown_fn = smb_full_audit_chown,
2995         .fchown_fn = smb_full_audit_fchown,
2996         .lchown_fn = smb_full_audit_lchown,
2997         .chdir_fn = smb_full_audit_chdir,
2998         .getwd_fn = smb_full_audit_getwd,
2999         .ntimes_fn = smb_full_audit_ntimes,
3000         .ftruncate_fn = smb_full_audit_ftruncate,
3001         .fallocate_fn = smb_full_audit_fallocate,
3002         .lock_fn = smb_full_audit_lock,
3003         .kernel_flock_fn = smb_full_audit_kernel_flock,
3004         .fcntl_fn = smb_full_audit_fcntl,
3005         .linux_setlease_fn = smb_full_audit_linux_setlease,
3006         .getlock_fn = smb_full_audit_getlock,
3007         .symlinkat_fn = smb_full_audit_symlinkat,
3008         .readlinkat_fn = smb_full_audit_readlinkat,
3009         .linkat_fn = smb_full_audit_linkat,
3010         .mknodat_fn = smb_full_audit_mknodat,
3011         .realpath_fn = smb_full_audit_realpath,
3012         .chflags_fn = smb_full_audit_chflags,
3013         .file_id_create_fn = smb_full_audit_file_id_create,
3014         .fs_file_id_fn = smb_full_audit_fs_file_id,
3015         .offload_read_send_fn = smb_full_audit_offload_read_send,
3016         .offload_read_recv_fn = smb_full_audit_offload_read_recv,
3017         .offload_write_send_fn = smb_full_audit_offload_write_send,
3018         .offload_write_recv_fn = smb_full_audit_offload_write_recv,
3019         .get_compression_fn = smb_full_audit_get_compression,
3020         .set_compression_fn = smb_full_audit_set_compression,
3021         .snap_check_path_fn =  smb_full_audit_snap_check_path,
3022         .snap_create_fn = smb_full_audit_snap_create,
3023         .snap_delete_fn = smb_full_audit_snap_delete,
3024         .streaminfo_fn = smb_full_audit_streaminfo,
3025         .get_real_filename_fn = smb_full_audit_get_real_filename,
3026         .connectpath_fn = smb_full_audit_connectpath,
3027         .brl_lock_windows_fn = smb_full_audit_brl_lock_windows,
3028         .brl_unlock_windows_fn = smb_full_audit_brl_unlock_windows,
3029         .strict_lock_check_fn = smb_full_audit_strict_lock_check,
3030         .translate_name_fn = smb_full_audit_translate_name,
3031         .fsctl_fn = smb_full_audit_fsctl,
3032         .get_dos_attributes_fn = smb_full_audit_get_dos_attributes,
3033         .get_dos_attributes_send_fn = smb_full_audit_get_dos_attributes_send,
3034         .get_dos_attributes_recv_fn = smb_full_audit_get_dos_attributes_recv,
3035         .fget_dos_attributes_fn = smb_full_audit_fget_dos_attributes,
3036         .set_dos_attributes_fn = smb_full_audit_set_dos_attributes,
3037         .fset_dos_attributes_fn = smb_full_audit_fset_dos_attributes,
3038         .fget_nt_acl_fn = smb_full_audit_fget_nt_acl,
3039         .get_nt_acl_fn = smb_full_audit_get_nt_acl,
3040         .fset_nt_acl_fn = smb_full_audit_fset_nt_acl,
3041         .audit_file_fn = smb_full_audit_audit_file,
3042         .sys_acl_get_file_fn = smb_full_audit_sys_acl_get_file,
3043         .sys_acl_get_fd_fn = smb_full_audit_sys_acl_get_fd,
3044         .sys_acl_blob_get_file_fn = smb_full_audit_sys_acl_blob_get_file,
3045         .sys_acl_blob_get_fd_fn = smb_full_audit_sys_acl_blob_get_fd,
3046         .sys_acl_set_file_fn = smb_full_audit_sys_acl_set_file,
3047         .sys_acl_set_fd_fn = smb_full_audit_sys_acl_set_fd,
3048         .sys_acl_delete_def_file_fn = smb_full_audit_sys_acl_delete_def_file,
3049         .getxattr_fn = smb_full_audit_getxattr,
3050         .getxattrat_send_fn = smb_full_audit_getxattrat_send,
3051         .getxattrat_recv_fn = smb_full_audit_getxattrat_recv,
3052         .fgetxattr_fn = smb_full_audit_fgetxattr,
3053         .listxattr_fn = smb_full_audit_listxattr,
3054         .flistxattr_fn = smb_full_audit_flistxattr,
3055         .removexattr_fn = smb_full_audit_removexattr,
3056         .fremovexattr_fn = smb_full_audit_fremovexattr,
3057         .setxattr_fn = smb_full_audit_setxattr,
3058         .fsetxattr_fn = smb_full_audit_fsetxattr,
3059         .aio_force_fn = smb_full_audit_aio_force,
3060         .durable_cookie_fn = smb_full_audit_durable_cookie,
3061         .durable_disconnect_fn = smb_full_audit_durable_disconnect,
3062         .durable_reconnect_fn = smb_full_audit_durable_reconnect,
3063         .readdir_attr_fn = smb_full_audit_readdir_attr
3064
3065 };
3066
3067 static_decl_vfs;
3068 NTSTATUS vfs_full_audit_init(TALLOC_CTX *ctx)
3069 {
3070         NTSTATUS ret;
3071
3072         smb_vfs_assert_all_fns(&vfs_full_audit_fns, "full_audit");
3073
3074         ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "full_audit",
3075                                &vfs_full_audit_fns);
3076
3077         if (!NT_STATUS_IS_OK(ret))
3078                 return ret;
3079
3080         vfs_full_audit_debug_level = debug_add_class("full_audit");
3081         if (vfs_full_audit_debug_level == -1) {
3082                 vfs_full_audit_debug_level = DBGC_VFS;
3083                 DEBUG(0, ("vfs_full_audit: Couldn't register custom debugging "
3084                           "class!\n"));
3085         } else {
3086                 DEBUG(10, ("vfs_full_audit: Debug class number of "
3087                            "'full_audit': %d\n", vfs_full_audit_debug_level));
3088         }
3089         
3090         return ret;
3091 }