s3: VFS: Implement create_dfs_pathat() in full_audit.
[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         SMB_VFS_OP_CREATE_DFS_PATHAT,
105
106         /* Directory operations */
107
108         SMB_VFS_OP_OPENDIR,
109         SMB_VFS_OP_FDOPENDIR,
110         SMB_VFS_OP_READDIR,
111         SMB_VFS_OP_SEEKDIR,
112         SMB_VFS_OP_TELLDIR,
113         SMB_VFS_OP_REWINDDIR,
114         SMB_VFS_OP_MKDIRAT,
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_FCHOWN,
145         SMB_VFS_OP_LCHOWN,
146         SMB_VFS_OP_CHDIR,
147         SMB_VFS_OP_GETWD,
148         SMB_VFS_OP_NTIMES,
149         SMB_VFS_OP_FTRUNCATE,
150         SMB_VFS_OP_FALLOCATE,
151         SMB_VFS_OP_LOCK,
152         SMB_VFS_OP_KERNEL_FLOCK,
153         SMB_VFS_OP_FCNTL,
154         SMB_VFS_OP_LINUX_SETLEASE,
155         SMB_VFS_OP_GETLOCK,
156         SMB_VFS_OP_SYMLINKAT,
157         SMB_VFS_OP_READLINKAT,
158         SMB_VFS_OP_LINKAT,
159         SMB_VFS_OP_MKNODAT,
160         SMB_VFS_OP_REALPATH,
161         SMB_VFS_OP_CHFLAGS,
162         SMB_VFS_OP_FILE_ID_CREATE,
163         SMB_VFS_OP_FS_FILE_ID,
164         SMB_VFS_OP_STREAMINFO,
165         SMB_VFS_OP_GET_REAL_FILENAME,
166         SMB_VFS_OP_CONNECTPATH,
167         SMB_VFS_OP_BRL_LOCK_WINDOWS,
168         SMB_VFS_OP_BRL_UNLOCK_WINDOWS,
169         SMB_VFS_OP_STRICT_LOCK_CHECK,
170         SMB_VFS_OP_TRANSLATE_NAME,
171         SMB_VFS_OP_FSCTL,
172         SMB_VFS_OP_OFFLOAD_READ_SEND,
173         SMB_VFS_OP_OFFLOAD_READ_RECV,
174         SMB_VFS_OP_OFFLOAD_WRITE_SEND,
175         SMB_VFS_OP_OFFLOAD_WRITE_RECV,
176         SMB_VFS_OP_GET_COMPRESSION,
177         SMB_VFS_OP_SET_COMPRESSION,
178         SMB_VFS_OP_SNAP_CHECK_PATH,
179         SMB_VFS_OP_SNAP_CREATE,
180         SMB_VFS_OP_SNAP_DELETE,
181
182         /* DOS attribute operations. */
183         SMB_VFS_OP_GET_DOS_ATTRIBUTES,
184         SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
185         SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV,
186         SMB_VFS_OP_FGET_DOS_ATTRIBUTES,
187         SMB_VFS_OP_SET_DOS_ATTRIBUTES,
188         SMB_VFS_OP_FSET_DOS_ATTRIBUTES,
189
190         /* NT ACL operations. */
191
192         SMB_VFS_OP_FGET_NT_ACL,
193         SMB_VFS_OP_GET_NT_ACL,
194         SMB_VFS_OP_FSET_NT_ACL,
195         SMB_VFS_OP_AUDIT_FILE,
196
197         /* POSIX ACL operations. */
198
199         SMB_VFS_OP_SYS_ACL_GET_FILE,
200         SMB_VFS_OP_SYS_ACL_GET_FD,
201         SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE,
202         SMB_VFS_OP_SYS_ACL_BLOB_GET_FD,
203         SMB_VFS_OP_SYS_ACL_SET_FILE,
204         SMB_VFS_OP_SYS_ACL_SET_FD,
205         SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE,
206
207         /* EA operations. */
208         SMB_VFS_OP_GETXATTR,
209         SMB_VFS_OP_GETXATTRAT_SEND,
210         SMB_VFS_OP_GETXATTRAT_RECV,
211         SMB_VFS_OP_FGETXATTR,
212         SMB_VFS_OP_LISTXATTR,
213         SMB_VFS_OP_FLISTXATTR,
214         SMB_VFS_OP_REMOVEXATTR,
215         SMB_VFS_OP_FREMOVEXATTR,
216         SMB_VFS_OP_SETXATTR,
217         SMB_VFS_OP_FSETXATTR,
218
219         /* aio operations */
220         SMB_VFS_OP_AIO_FORCE,
221
222         /* offline operations */
223         SMB_VFS_OP_IS_OFFLINE,
224         SMB_VFS_OP_SET_OFFLINE,
225
226         /* Durable handle operations. */
227         SMB_VFS_OP_DURABLE_COOKIE,
228         SMB_VFS_OP_DURABLE_DISCONNECT,
229         SMB_VFS_OP_DURABLE_RECONNECT,
230
231         SMB_VFS_OP_READDIR_ATTR,
232
233         /* This should always be last enum value */
234
235         SMB_VFS_OP_LAST
236 } vfs_op_type;
237
238 /* The following array *must* be in the same order as defined in vfs_op_type */
239
240 static struct {
241         vfs_op_type type;
242         const char *name;
243 } vfs_op_names[] = {
244         { SMB_VFS_OP_CONNECT,   "connect" },
245         { SMB_VFS_OP_DISCONNECT,        "disconnect" },
246         { SMB_VFS_OP_DISK_FREE, "disk_free" },
247         { SMB_VFS_OP_GET_QUOTA, "get_quota" },
248         { SMB_VFS_OP_SET_QUOTA, "set_quota" },
249         { SMB_VFS_OP_GET_SHADOW_COPY_DATA,      "get_shadow_copy_data" },
250         { SMB_VFS_OP_STATVFS,   "statvfs" },
251         { SMB_VFS_OP_FS_CAPABILITIES,   "fs_capabilities" },
252         { SMB_VFS_OP_GET_DFS_REFERRALS, "get_dfs_referrals" },
253         { SMB_VFS_OP_CREATE_DFS_PATHAT, "create_dfs_pathat" },
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_CLOSEDIR,  "closedir" },
262         { SMB_VFS_OP_OPEN,      "open" },
263         { SMB_VFS_OP_CREATE_FILE, "create_file" },
264         { SMB_VFS_OP_CLOSE,     "close" },
265         { SMB_VFS_OP_READ,      "read" },
266         { SMB_VFS_OP_PREAD,     "pread" },
267         { SMB_VFS_OP_PREAD_SEND,        "pread_send" },
268         { SMB_VFS_OP_PREAD_RECV,        "pread_recv" },
269         { SMB_VFS_OP_WRITE,     "write" },
270         { SMB_VFS_OP_PWRITE,    "pwrite" },
271         { SMB_VFS_OP_PWRITE_SEND,       "pwrite_send" },
272         { SMB_VFS_OP_PWRITE_RECV,       "pwrite_recv" },
273         { SMB_VFS_OP_LSEEK,     "lseek" },
274         { SMB_VFS_OP_SENDFILE,  "sendfile" },
275         { SMB_VFS_OP_RECVFILE,  "recvfile" },
276         { SMB_VFS_OP_RENAMEAT,  "renameat" },
277         { SMB_VFS_OP_FSYNC,     "fsync" },
278         { SMB_VFS_OP_FSYNC_SEND,        "fsync_send" },
279         { SMB_VFS_OP_FSYNC_RECV,        "fsync_recv" },
280         { SMB_VFS_OP_STAT,      "stat" },
281         { SMB_VFS_OP_FSTAT,     "fstat" },
282         { SMB_VFS_OP_LSTAT,     "lstat" },
283         { SMB_VFS_OP_GET_ALLOC_SIZE,    "get_alloc_size" },
284         { SMB_VFS_OP_UNLINKAT,  "unlinkat" },
285         { SMB_VFS_OP_CHMOD,     "chmod" },
286         { SMB_VFS_OP_FCHMOD,    "fchmod" },
287         { SMB_VFS_OP_FCHOWN,    "fchown" },
288         { SMB_VFS_OP_LCHOWN,    "lchown" },
289         { SMB_VFS_OP_CHDIR,     "chdir" },
290         { SMB_VFS_OP_GETWD,     "getwd" },
291         { SMB_VFS_OP_NTIMES,    "ntimes" },
292         { SMB_VFS_OP_FTRUNCATE, "ftruncate" },
293         { SMB_VFS_OP_FALLOCATE,"fallocate" },
294         { SMB_VFS_OP_LOCK,      "lock" },
295         { SMB_VFS_OP_KERNEL_FLOCK,      "kernel_flock" },
296         { SMB_VFS_OP_LINUX_SETLEASE, "linux_setlease" },
297         { SMB_VFS_OP_GETLOCK,   "getlock" },
298         { SMB_VFS_OP_SYMLINKAT, "symlinkat" },
299         { SMB_VFS_OP_READLINKAT,"readlinkat" },
300         { SMB_VFS_OP_LINKAT,    "linkat" },
301         { SMB_VFS_OP_MKNODAT,   "mknodat" },
302         { SMB_VFS_OP_REALPATH,  "realpath" },
303         { SMB_VFS_OP_CHFLAGS,   "chflags" },
304         { SMB_VFS_OP_FILE_ID_CREATE,    "file_id_create" },
305         { SMB_VFS_OP_FS_FILE_ID,        "fs_file_id" },
306         { SMB_VFS_OP_STREAMINFO,        "streaminfo" },
307         { SMB_VFS_OP_GET_REAL_FILENAME, "get_real_filename" },
308         { SMB_VFS_OP_CONNECTPATH,       "connectpath" },
309         { SMB_VFS_OP_BRL_LOCK_WINDOWS,  "brl_lock_windows" },
310         { SMB_VFS_OP_BRL_UNLOCK_WINDOWS, "brl_unlock_windows" },
311         { SMB_VFS_OP_STRICT_LOCK_CHECK, "strict_lock_check" },
312         { SMB_VFS_OP_TRANSLATE_NAME,    "translate_name" },
313         { SMB_VFS_OP_FSCTL,             "fsctl" },
314         { SMB_VFS_OP_OFFLOAD_READ_SEND, "offload_read_send" },
315         { SMB_VFS_OP_OFFLOAD_READ_RECV, "offload_read_recv" },
316         { SMB_VFS_OP_OFFLOAD_WRITE_SEND,        "offload_write_send" },
317         { SMB_VFS_OP_OFFLOAD_WRITE_RECV,        "offload_write_recv" },
318         { SMB_VFS_OP_GET_COMPRESSION,   "get_compression" },
319         { SMB_VFS_OP_SET_COMPRESSION,   "set_compression" },
320         { SMB_VFS_OP_SNAP_CHECK_PATH, "snap_check_path" },
321         { SMB_VFS_OP_SNAP_CREATE, "snap_create" },
322         { SMB_VFS_OP_SNAP_DELETE, "snap_delete" },
323         { SMB_VFS_OP_GET_DOS_ATTRIBUTES, "get_dos_attributes" },
324         { SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND, "get_dos_attributes_send" },
325         { SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV, "get_dos_attributes_recv" },
326         { SMB_VFS_OP_FGET_DOS_ATTRIBUTES, "fget_dos_attributes" },
327         { SMB_VFS_OP_SET_DOS_ATTRIBUTES, "set_dos_attributes" },
328         { SMB_VFS_OP_FSET_DOS_ATTRIBUTES, "fset_dos_attributes" },
329         { SMB_VFS_OP_FGET_NT_ACL,       "fget_nt_acl" },
330         { SMB_VFS_OP_GET_NT_ACL,        "get_nt_acl" },
331         { SMB_VFS_OP_FSET_NT_ACL,       "fset_nt_acl" },
332         { SMB_VFS_OP_AUDIT_FILE,        "audit_file" },
333         { SMB_VFS_OP_SYS_ACL_GET_FILE,  "sys_acl_get_file" },
334         { SMB_VFS_OP_SYS_ACL_GET_FD,    "sys_acl_get_fd" },
335         { SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE,     "sys_acl_blob_get_file" },
336         { SMB_VFS_OP_SYS_ACL_BLOB_GET_FD,       "sys_acl_blob_get_fd" },
337         { SMB_VFS_OP_SYS_ACL_SET_FILE,  "sys_acl_set_file" },
338         { SMB_VFS_OP_SYS_ACL_SET_FD,    "sys_acl_set_fd" },
339         { SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE,   "sys_acl_delete_def_file" },
340         { SMB_VFS_OP_GETXATTR,  "getxattr" },
341         { SMB_VFS_OP_GETXATTRAT_SEND, "getxattrat_send" },
342         { SMB_VFS_OP_GETXATTRAT_RECV, "getxattrat_recv" },
343         { SMB_VFS_OP_FGETXATTR, "fgetxattr" },
344         { SMB_VFS_OP_LISTXATTR, "listxattr" },
345         { SMB_VFS_OP_FLISTXATTR,        "flistxattr" },
346         { SMB_VFS_OP_REMOVEXATTR,       "removexattr" },
347         { SMB_VFS_OP_FREMOVEXATTR,      "fremovexattr" },
348         { SMB_VFS_OP_SETXATTR,  "setxattr" },
349         { SMB_VFS_OP_FSETXATTR, "fsetxattr" },
350         { SMB_VFS_OP_AIO_FORCE, "aio_force" },
351         { SMB_VFS_OP_IS_OFFLINE, "is_offline" },
352         { SMB_VFS_OP_SET_OFFLINE, "set_offline" },
353         { SMB_VFS_OP_DURABLE_COOKIE, "durable_cookie" },
354         { SMB_VFS_OP_DURABLE_DISCONNECT, "durable_disconnect" },
355         { SMB_VFS_OP_DURABLE_RECONNECT, "durable_reconnect" },
356         { SMB_VFS_OP_READDIR_ATTR,      "readdir_attr" },
357         { SMB_VFS_OP_LAST, NULL }
358 };
359
360 static int audit_syslog_facility(vfs_handle_struct *handle)
361 {
362         static const struct enum_list enum_log_facilities[] = {
363 #ifdef LOG_AUTH
364                 { LOG_AUTH,             "AUTH" },
365 #endif
366 #ifdef LOG_AUTHPRIV
367                 { LOG_AUTHPRIV,         "AUTHPRIV" },
368 #endif
369 #ifdef LOG_AUDIT
370                 { LOG_AUDIT,            "AUDIT" },
371 #endif
372 #ifdef LOG_CONSOLE
373                 { LOG_CONSOLE,          "CONSOLE" },
374 #endif
375 #ifdef LOG_CRON
376                 { LOG_CRON,             "CRON" },
377 #endif
378 #ifdef LOG_DAEMON
379                 { LOG_DAEMON,           "DAEMON" },
380 #endif
381 #ifdef LOG_FTP
382                 { LOG_FTP,              "FTP" },
383 #endif
384 #ifdef LOG_INSTALL
385                 { LOG_INSTALL,          "INSTALL" },
386 #endif
387 #ifdef LOG_KERN
388                 { LOG_KERN,             "KERN" },
389 #endif
390 #ifdef LOG_LAUNCHD
391                 { LOG_LAUNCHD,          "LAUNCHD" },
392 #endif
393 #ifdef LOG_LFMT
394                 { LOG_LFMT,             "LFMT" },
395 #endif
396 #ifdef LOG_LPR
397                 { LOG_LPR,              "LPR" },
398 #endif
399 #ifdef LOG_MAIL
400                 { LOG_MAIL,             "MAIL" },
401 #endif
402 #ifdef LOG_MEGASAFE
403                 { LOG_MEGASAFE,         "MEGASAFE" },
404 #endif
405 #ifdef LOG_NETINFO
406                 { LOG_NETINFO,          "NETINFO" },
407 #endif
408 #ifdef LOG_NEWS
409                 { LOG_NEWS,             "NEWS" },
410 #endif
411 #ifdef LOG_NFACILITIES
412                 { LOG_NFACILITIES,      "NFACILITIES" },
413 #endif
414 #ifdef LOG_NTP
415                 { LOG_NTP,              "NTP" },
416 #endif
417 #ifdef LOG_RAS
418                 { LOG_RAS,              "RAS" },
419 #endif
420 #ifdef LOG_REMOTEAUTH
421                 { LOG_REMOTEAUTH,       "REMOTEAUTH" },
422 #endif
423 #ifdef LOG_SECURITY
424                 { LOG_SECURITY,         "SECURITY" },
425 #endif
426 #ifdef LOG_SYSLOG
427                 { LOG_SYSLOG,           "SYSLOG" },
428 #endif
429 #ifdef LOG_USER
430                 { LOG_USER,             "USER" },
431 #endif
432 #ifdef LOG_UUCP
433                 { LOG_UUCP,             "UUCP" },
434 #endif
435                 { LOG_LOCAL0,           "LOCAL0" },
436                 { LOG_LOCAL1,           "LOCAL1" },
437                 { LOG_LOCAL2,           "LOCAL2" },
438                 { LOG_LOCAL3,           "LOCAL3" },
439                 { LOG_LOCAL4,           "LOCAL4" },
440                 { LOG_LOCAL5,           "LOCAL5" },
441                 { LOG_LOCAL6,           "LOCAL6" },
442                 { LOG_LOCAL7,           "LOCAL7" },
443                 { -1,                   NULL }
444         };
445
446         int facility;
447
448         facility = lp_parm_enum(SNUM(handle->conn), "full_audit", "facility", enum_log_facilities, LOG_USER);
449
450         return facility;
451 }
452
453 static int audit_syslog_priority(vfs_handle_struct *handle)
454 {
455         static const struct enum_list enum_log_priorities[] = {
456                 { LOG_EMERG, "EMERG" },
457                 { LOG_ALERT, "ALERT" },
458                 { LOG_CRIT, "CRIT" },
459                 { LOG_ERR, "ERR" },
460                 { LOG_WARNING, "WARNING" },
461                 { LOG_NOTICE, "NOTICE" },
462                 { LOG_INFO, "INFO" },
463                 { LOG_DEBUG, "DEBUG" },
464                 { -1, NULL }
465         };
466
467         int priority;
468
469         priority = lp_parm_enum(SNUM(handle->conn), "full_audit", "priority",
470                                 enum_log_priorities, LOG_NOTICE);
471         if (priority == -1) {
472                 priority = LOG_WARNING;
473         }
474
475         return priority;
476 }
477
478 static char *audit_prefix(TALLOC_CTX *ctx, connection_struct *conn)
479 {
480         const struct loadparm_substitution *lp_sub =
481                 loadparm_s3_global_substitution();
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_full(ctx,
492                         lp_servicename(talloc_tos(), lp_sub, 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         const struct loadparm_substitution *lp_sub =
779                 loadparm_s3_global_substitution();
780
781         SMB_VFS_NEXT_DISCONNECT(handle);
782
783         do_log(SMB_VFS_OP_DISCONNECT, True, handle,
784                "%s", lp_servicename(talloc_tos(), lp_sub, SNUM(handle->conn)));
785
786         /* The bitmaps will be disconnected when the private
787            data is deleted. */
788 }
789
790 static uint64_t smb_full_audit_disk_free(vfs_handle_struct *handle,
791                                 const struct smb_filename *smb_fname,
792                                 uint64_t *bsize,
793                                 uint64_t *dfree,
794                                 uint64_t *dsize)
795 {
796         uint64_t result;
797
798         result = SMB_VFS_NEXT_DISK_FREE(handle, smb_fname, bsize, dfree, dsize);
799
800         /* Don't have a reasonable notion of failure here */
801
802         do_log(SMB_VFS_OP_DISK_FREE,
803                True,
804                handle,
805                "%s",
806                smb_fname_str_do_log(handle->conn, smb_fname));
807
808         return result;
809 }
810
811 static int smb_full_audit_get_quota(struct vfs_handle_struct *handle,
812                                 const struct smb_filename *smb_fname,
813                                 enum SMB_QUOTA_TYPE qtype,
814                                 unid_t id,
815                                 SMB_DISK_QUOTA *qt)
816 {
817         int result;
818
819         result = SMB_VFS_NEXT_GET_QUOTA(handle, smb_fname, qtype, id, qt);
820
821         do_log(SMB_VFS_OP_GET_QUOTA,
822                (result >= 0),
823                handle,
824                "%s",
825                smb_fname_str_do_log(handle->conn, smb_fname));
826
827         return result;
828 }
829
830 static int smb_full_audit_set_quota(struct vfs_handle_struct *handle,
831                            enum SMB_QUOTA_TYPE qtype, unid_t id,
832                            SMB_DISK_QUOTA *qt)
833 {
834         int result;
835
836         result = SMB_VFS_NEXT_SET_QUOTA(handle, qtype, id, qt);
837
838         do_log(SMB_VFS_OP_SET_QUOTA, (result >= 0), handle, "");
839
840         return result;
841 }
842
843 static int smb_full_audit_get_shadow_copy_data(struct vfs_handle_struct *handle,
844                                 struct files_struct *fsp,
845                                 struct shadow_copy_data *shadow_copy_data,
846                                 bool labels)
847 {
848         int result;
849
850         result = SMB_VFS_NEXT_GET_SHADOW_COPY_DATA(handle, fsp, shadow_copy_data, labels);
851
852         do_log(SMB_VFS_OP_GET_SHADOW_COPY_DATA, (result >= 0), handle, "");
853
854         return result;
855 }
856
857 static int smb_full_audit_statvfs(struct vfs_handle_struct *handle,
858                                 const struct smb_filename *smb_fname,
859                                 struct vfs_statvfs_struct *statbuf)
860 {
861         int result;
862
863         result = SMB_VFS_NEXT_STATVFS(handle, smb_fname, statbuf);
864
865         do_log(SMB_VFS_OP_STATVFS, (result >= 0), handle, "");
866
867         return result;
868 }
869
870 static uint32_t smb_full_audit_fs_capabilities(struct vfs_handle_struct *handle, enum timestamp_set_resolution *p_ts_res)
871 {
872         int result;
873
874         result = SMB_VFS_NEXT_FS_CAPABILITIES(handle, p_ts_res);
875
876         do_log(SMB_VFS_OP_FS_CAPABILITIES, true, handle, "");
877
878         return result;
879 }
880
881 static NTSTATUS smb_full_audit_get_dfs_referrals(
882                                 struct vfs_handle_struct *handle,
883                                 struct dfs_GetDFSReferral *r)
884 {
885         NTSTATUS status;
886
887         status = SMB_VFS_NEXT_GET_DFS_REFERRALS(handle, r);
888
889         do_log(SMB_VFS_OP_GET_DFS_REFERRALS, NT_STATUS_IS_OK(status),
890                handle, "");
891
892         return status;
893 }
894
895 static NTSTATUS smb_full_audit_create_dfs_pathat(struct vfs_handle_struct *handle,
896                                 struct files_struct *dirfsp,
897                                 const struct smb_filename *smb_fname,
898                                 const struct referral *reflist,
899                                 size_t referral_count)
900 {
901         NTSTATUS status;
902
903         status = SMB_VFS_NEXT_CREATE_DFS_PATHAT(handle,
904                         dirfsp,
905                         smb_fname,
906                         reflist,
907                         referral_count);
908
909         do_log(SMB_VFS_OP_CREATE_DFS_PATHAT,
910                 NT_STATUS_IS_OK(status),
911                 handle,
912                 "%s",
913                 smb_fname_str_do_log(handle->conn, smb_fname));
914
915         return status;
916 }
917
918 static NTSTATUS smb_full_audit_snap_check_path(struct vfs_handle_struct *handle,
919                                                TALLOC_CTX *mem_ctx,
920                                                const char *service_path,
921                                                char **base_volume)
922 {
923         NTSTATUS status;
924
925         status = SMB_VFS_NEXT_SNAP_CHECK_PATH(handle, mem_ctx, service_path,
926                                               base_volume);
927         do_log(SMB_VFS_OP_SNAP_CHECK_PATH, NT_STATUS_IS_OK(status),
928                handle, "");
929
930         return status;
931 }
932
933 static NTSTATUS smb_full_audit_snap_create(struct vfs_handle_struct *handle,
934                                            TALLOC_CTX *mem_ctx,
935                                            const char *base_volume,
936                                            time_t *tstamp,
937                                            bool rw,
938                                            char **base_path,
939                                            char **snap_path)
940 {
941         NTSTATUS status;
942
943         status = SMB_VFS_NEXT_SNAP_CREATE(handle, mem_ctx, base_volume, tstamp,
944                                           rw, base_path, snap_path);
945         do_log(SMB_VFS_OP_SNAP_CREATE, NT_STATUS_IS_OK(status), handle, "");
946
947         return status;
948 }
949
950 static NTSTATUS smb_full_audit_snap_delete(struct vfs_handle_struct *handle,
951                                            TALLOC_CTX *mem_ctx,
952                                            char *base_path,
953                                            char *snap_path)
954 {
955         NTSTATUS status;
956
957         status = SMB_VFS_NEXT_SNAP_DELETE(handle, mem_ctx, base_path,
958                                           snap_path);
959         do_log(SMB_VFS_OP_SNAP_DELETE, NT_STATUS_IS_OK(status), handle, "");
960
961         return status;
962 }
963
964 static DIR *smb_full_audit_opendir(vfs_handle_struct *handle,
965                         const struct smb_filename *smb_fname,
966                         const char *mask,
967                         uint32_t attr)
968 {
969         DIR *result;
970
971         result = SMB_VFS_NEXT_OPENDIR(handle, smb_fname, mask, attr);
972
973         do_log(SMB_VFS_OP_OPENDIR,
974                (result != NULL),
975                handle,
976                "%s",
977                smb_fname_str_do_log(handle->conn, smb_fname));
978
979         return result;
980 }
981
982 static DIR *smb_full_audit_fdopendir(vfs_handle_struct *handle,
983                           files_struct *fsp, const char *mask, uint32_t attr)
984 {
985         DIR *result;
986
987         result = SMB_VFS_NEXT_FDOPENDIR(handle, fsp, mask, attr);
988
989         do_log(SMB_VFS_OP_FDOPENDIR, (result != NULL), handle, "%s",
990                         fsp_str_do_log(fsp));
991
992         return result;
993 }
994
995 static struct dirent *smb_full_audit_readdir(vfs_handle_struct *handle,
996                                     DIR *dirp, SMB_STRUCT_STAT *sbuf)
997 {
998         struct dirent *result;
999
1000         result = SMB_VFS_NEXT_READDIR(handle, dirp, sbuf);
1001
1002         /* This operation has no reasonable error condition
1003          * (End of dir is also failure), so always succeed.
1004          */
1005         do_log(SMB_VFS_OP_READDIR, True, handle, "");
1006
1007         return result;
1008 }
1009
1010 static void smb_full_audit_seekdir(vfs_handle_struct *handle,
1011                         DIR *dirp, long offset)
1012 {
1013         SMB_VFS_NEXT_SEEKDIR(handle, dirp, offset);
1014
1015         do_log(SMB_VFS_OP_SEEKDIR, True, handle, "");
1016 }
1017
1018 static long smb_full_audit_telldir(vfs_handle_struct *handle,
1019                         DIR *dirp)
1020 {
1021         long result;
1022
1023         result = SMB_VFS_NEXT_TELLDIR(handle, dirp);
1024
1025         do_log(SMB_VFS_OP_TELLDIR, True, handle, "");
1026
1027         return result;
1028 }
1029
1030 static void smb_full_audit_rewinddir(vfs_handle_struct *handle,
1031                         DIR *dirp)
1032 {
1033         SMB_VFS_NEXT_REWINDDIR(handle, dirp);
1034
1035         do_log(SMB_VFS_OP_REWINDDIR, True, handle, "");
1036 }
1037
1038 static int smb_full_audit_mkdirat(vfs_handle_struct *handle,
1039                         struct files_struct *dirfsp,
1040                         const struct smb_filename *smb_fname,
1041                         mode_t mode)
1042 {
1043         int result;
1044
1045         result = SMB_VFS_NEXT_MKDIRAT(handle,
1046                         dirfsp,
1047                         smb_fname,
1048                         mode);
1049
1050         do_log(SMB_VFS_OP_MKDIRAT,
1051                (result >= 0),
1052                handle,
1053                "%s",
1054                smb_fname_str_do_log(handle->conn, smb_fname));
1055
1056         return result;
1057 }
1058
1059 static int smb_full_audit_closedir(vfs_handle_struct *handle,
1060                           DIR *dirp)
1061 {
1062         int result;
1063
1064         result = SMB_VFS_NEXT_CLOSEDIR(handle, dirp);
1065         
1066         do_log(SMB_VFS_OP_CLOSEDIR, (result >= 0), handle, "");
1067
1068         return result;
1069 }
1070
1071 static int smb_full_audit_open(vfs_handle_struct *handle,
1072                                struct smb_filename *smb_fname,
1073                                files_struct *fsp, int flags, mode_t mode)
1074 {
1075         int result;
1076         
1077         result = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
1078
1079         do_log(SMB_VFS_OP_OPEN, (result >= 0), handle, "%s|%s",
1080                ((flags & O_WRONLY) || (flags & O_RDWR))?"w":"r",
1081                smb_fname_str_do_log(handle->conn, smb_fname));
1082
1083         return result;
1084 }
1085
1086 static NTSTATUS smb_full_audit_create_file(vfs_handle_struct *handle,
1087                                       struct smb_request *req,
1088                                       uint16_t root_dir_fid,
1089                                       struct smb_filename *smb_fname,
1090                                       uint32_t access_mask,
1091                                       uint32_t share_access,
1092                                       uint32_t create_disposition,
1093                                       uint32_t create_options,
1094                                       uint32_t file_attributes,
1095                                       uint32_t oplock_request,
1096                                       const struct smb2_lease *lease,
1097                                       uint64_t allocation_size,
1098                                       uint32_t private_flags,
1099                                       struct security_descriptor *sd,
1100                                       struct ea_list *ea_list,
1101                                       files_struct **result_fsp,
1102                                       int *pinfo,
1103                                       const struct smb2_create_blobs *in_context_blobs,
1104                                       struct smb2_create_blobs *out_context_blobs)
1105 {
1106         NTSTATUS result;
1107         const char* str_create_disposition;
1108
1109         switch (create_disposition) {
1110         case FILE_SUPERSEDE:
1111                 str_create_disposition = "supersede";
1112                 break;
1113         case FILE_OVERWRITE_IF:
1114                 str_create_disposition = "overwrite_if";
1115                 break;
1116         case FILE_OPEN:
1117                 str_create_disposition = "open";
1118                 break;
1119         case FILE_OVERWRITE:
1120                 str_create_disposition = "overwrite";
1121                 break;
1122         case FILE_CREATE:
1123                 str_create_disposition = "create";
1124                 break;
1125         case FILE_OPEN_IF:
1126                 str_create_disposition = "open_if";
1127                 break;
1128         default:
1129                 str_create_disposition = "unknown";
1130         }
1131
1132         result = SMB_VFS_NEXT_CREATE_FILE(
1133                 handle,                                 /* handle */
1134                 req,                                    /* req */
1135                 root_dir_fid,                           /* root_dir_fid */
1136                 smb_fname,                              /* fname */
1137                 access_mask,                            /* access_mask */
1138                 share_access,                           /* share_access */
1139                 create_disposition,                     /* create_disposition*/
1140                 create_options,                         /* create_options */
1141                 file_attributes,                        /* file_attributes */
1142                 oplock_request,                         /* oplock_request */
1143                 lease,                                  /* lease */
1144                 allocation_size,                        /* allocation_size */
1145                 private_flags,
1146                 sd,                                     /* sd */
1147                 ea_list,                                /* ea_list */
1148                 result_fsp,                             /* result */
1149                 pinfo,                                  /* pinfo */
1150                 in_context_blobs, out_context_blobs);   /* create context */
1151
1152         do_log(SMB_VFS_OP_CREATE_FILE, (NT_STATUS_IS_OK(result)), handle,
1153                "0x%x|%s|%s|%s", access_mask,
1154                create_options & FILE_DIRECTORY_FILE ? "dir" : "file",
1155                str_create_disposition,
1156                 smb_fname_str_do_log(handle->conn, smb_fname));
1157
1158         return result;
1159 }
1160
1161 static int smb_full_audit_close(vfs_handle_struct *handle, files_struct *fsp)
1162 {
1163         int result;
1164         
1165         result = SMB_VFS_NEXT_CLOSE(handle, fsp);
1166
1167         do_log(SMB_VFS_OP_CLOSE, (result >= 0), handle, "%s",
1168                fsp_str_do_log(fsp));
1169
1170         return result;
1171 }
1172
1173 static ssize_t smb_full_audit_pread(vfs_handle_struct *handle, files_struct *fsp,
1174                            void *data, size_t n, off_t offset)
1175 {
1176         ssize_t result;
1177
1178         result = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
1179
1180         do_log(SMB_VFS_OP_PREAD, (result >= 0), handle, "%s",
1181                fsp_str_do_log(fsp));
1182
1183         return result;
1184 }
1185
1186 struct smb_full_audit_pread_state {
1187         vfs_handle_struct *handle;
1188         files_struct *fsp;
1189         ssize_t ret;
1190         struct vfs_aio_state vfs_aio_state;
1191 };
1192
1193 static void smb_full_audit_pread_done(struct tevent_req *subreq);
1194
1195 static struct tevent_req *smb_full_audit_pread_send(
1196         struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1197         struct tevent_context *ev, struct files_struct *fsp,
1198         void *data, size_t n, off_t offset)
1199 {
1200         struct tevent_req *req, *subreq;
1201         struct smb_full_audit_pread_state *state;
1202
1203         req = tevent_req_create(mem_ctx, &state,
1204                                 struct smb_full_audit_pread_state);
1205         if (req == NULL) {
1206                 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
1207                        fsp_str_do_log(fsp));
1208                 return NULL;
1209         }
1210         state->handle = handle;
1211         state->fsp = fsp;
1212
1213         subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
1214                                          n, offset);
1215         if (tevent_req_nomem(subreq, req)) {
1216                 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
1217                        fsp_str_do_log(fsp));
1218                 return tevent_req_post(req, ev);
1219         }
1220         tevent_req_set_callback(subreq, smb_full_audit_pread_done, req);
1221
1222         do_log(SMB_VFS_OP_PREAD_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1223         return req;
1224 }
1225
1226 static void smb_full_audit_pread_done(struct tevent_req *subreq)
1227 {
1228         struct tevent_req *req = tevent_req_callback_data(
1229                 subreq, struct tevent_req);
1230         struct smb_full_audit_pread_state *state = tevent_req_data(
1231                 req, struct smb_full_audit_pread_state);
1232
1233         state->ret = SMB_VFS_PREAD_RECV(subreq, &state->vfs_aio_state);
1234         TALLOC_FREE(subreq);
1235         tevent_req_done(req);
1236 }
1237
1238 static ssize_t smb_full_audit_pread_recv(struct tevent_req *req,
1239                                          struct vfs_aio_state *vfs_aio_state)
1240 {
1241         struct smb_full_audit_pread_state *state = tevent_req_data(
1242                 req, struct smb_full_audit_pread_state);
1243
1244         if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1245                 do_log(SMB_VFS_OP_PREAD_RECV, false, state->handle, "%s",
1246                        fsp_str_do_log(state->fsp));
1247                 return -1;
1248         }
1249
1250         do_log(SMB_VFS_OP_PREAD_RECV, (state->ret >= 0), state->handle, "%s",
1251                fsp_str_do_log(state->fsp));
1252
1253         *vfs_aio_state = state->vfs_aio_state;
1254         return state->ret;
1255 }
1256
1257 static ssize_t smb_full_audit_pwrite(vfs_handle_struct *handle, files_struct *fsp,
1258                             const void *data, size_t n,
1259                             off_t offset)
1260 {
1261         ssize_t result;
1262
1263         result = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
1264
1265         do_log(SMB_VFS_OP_PWRITE, (result >= 0), handle, "%s",
1266                fsp_str_do_log(fsp));
1267
1268         return result;
1269 }
1270
1271 struct smb_full_audit_pwrite_state {
1272         vfs_handle_struct *handle;
1273         files_struct *fsp;
1274         ssize_t ret;
1275         struct vfs_aio_state vfs_aio_state;
1276 };
1277
1278 static void smb_full_audit_pwrite_done(struct tevent_req *subreq);
1279
1280 static struct tevent_req *smb_full_audit_pwrite_send(
1281         struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1282         struct tevent_context *ev, struct files_struct *fsp,
1283         const void *data, size_t n, off_t offset)
1284 {
1285         struct tevent_req *req, *subreq;
1286         struct smb_full_audit_pwrite_state *state;
1287
1288         req = tevent_req_create(mem_ctx, &state,
1289                                 struct smb_full_audit_pwrite_state);
1290         if (req == NULL) {
1291                 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1292                        fsp_str_do_log(fsp));
1293                 return NULL;
1294         }
1295         state->handle = handle;
1296         state->fsp = fsp;
1297
1298         subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
1299                                          n, offset);
1300         if (tevent_req_nomem(subreq, req)) {
1301                 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1302                        fsp_str_do_log(fsp));
1303                 return tevent_req_post(req, ev);
1304         }
1305         tevent_req_set_callback(subreq, smb_full_audit_pwrite_done, req);
1306
1307         do_log(SMB_VFS_OP_PWRITE_SEND, true, handle, "%s",
1308                fsp_str_do_log(fsp));
1309         return req;
1310 }
1311
1312 static void smb_full_audit_pwrite_done(struct tevent_req *subreq)
1313 {
1314         struct tevent_req *req = tevent_req_callback_data(
1315                 subreq, struct tevent_req);
1316         struct smb_full_audit_pwrite_state *state = tevent_req_data(
1317                 req, struct smb_full_audit_pwrite_state);
1318
1319         state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->vfs_aio_state);
1320         TALLOC_FREE(subreq);
1321         tevent_req_done(req);
1322 }
1323
1324 static ssize_t smb_full_audit_pwrite_recv(struct tevent_req *req,
1325                                           struct vfs_aio_state *vfs_aio_state)
1326 {
1327         struct smb_full_audit_pwrite_state *state = tevent_req_data(
1328                 req, struct smb_full_audit_pwrite_state);
1329
1330         if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1331                 do_log(SMB_VFS_OP_PWRITE_RECV, false, state->handle, "%s",
1332                        fsp_str_do_log(state->fsp));
1333                 return -1;
1334         }
1335
1336         do_log(SMB_VFS_OP_PWRITE_RECV, (state->ret >= 0), state->handle, "%s",
1337                fsp_str_do_log(state->fsp));
1338
1339         *vfs_aio_state = state->vfs_aio_state;
1340         return state->ret;
1341 }
1342
1343 static off_t smb_full_audit_lseek(vfs_handle_struct *handle, files_struct *fsp,
1344                              off_t offset, int whence)
1345 {
1346         ssize_t result;
1347
1348         result = SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence);
1349
1350         do_log(SMB_VFS_OP_LSEEK, (result != (ssize_t)-1), handle,
1351                "%s", fsp_str_do_log(fsp));
1352
1353         return result;
1354 }
1355
1356 static ssize_t smb_full_audit_sendfile(vfs_handle_struct *handle, int tofd,
1357                               files_struct *fromfsp,
1358                               const DATA_BLOB *hdr, off_t offset,
1359                               size_t n)
1360 {
1361         ssize_t result;
1362
1363         result = SMB_VFS_NEXT_SENDFILE(handle, tofd, fromfsp, hdr, offset, n);
1364
1365         do_log(SMB_VFS_OP_SENDFILE, (result >= 0), handle,
1366                "%s", fsp_str_do_log(fromfsp));
1367
1368         return result;
1369 }
1370
1371 static ssize_t smb_full_audit_recvfile(vfs_handle_struct *handle, int fromfd,
1372                       files_struct *tofsp,
1373                               off_t offset,
1374                               size_t n)
1375 {
1376         ssize_t result;
1377
1378         result = SMB_VFS_NEXT_RECVFILE(handle, fromfd, tofsp, offset, n);
1379
1380         do_log(SMB_VFS_OP_RECVFILE, (result >= 0), handle,
1381                "%s", fsp_str_do_log(tofsp));
1382
1383         return result;
1384 }
1385
1386 static int smb_full_audit_renameat(vfs_handle_struct *handle,
1387                                 files_struct *srcfsp,
1388                                 const struct smb_filename *smb_fname_src,
1389                                 files_struct *dstfsp,
1390                                 const struct smb_filename *smb_fname_dst)
1391 {
1392         int result;
1393
1394         result = SMB_VFS_NEXT_RENAMEAT(handle,
1395                                 srcfsp,
1396                                 smb_fname_src,
1397                                 dstfsp,
1398                                 smb_fname_dst);
1399
1400         do_log(SMB_VFS_OP_RENAMEAT, (result >= 0), handle, "%s|%s",
1401                smb_fname_str_do_log(handle->conn, smb_fname_src),
1402                smb_fname_str_do_log(handle->conn, smb_fname_dst));
1403
1404         return result;
1405 }
1406
1407 struct smb_full_audit_fsync_state {
1408         vfs_handle_struct *handle;
1409         files_struct *fsp;
1410         int ret;
1411         struct vfs_aio_state vfs_aio_state;
1412 };
1413
1414 static void smb_full_audit_fsync_done(struct tevent_req *subreq);
1415
1416 static struct tevent_req *smb_full_audit_fsync_send(
1417         struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1418         struct tevent_context *ev, struct files_struct *fsp)
1419 {
1420         struct tevent_req *req, *subreq;
1421         struct smb_full_audit_fsync_state *state;
1422
1423         req = tevent_req_create(mem_ctx, &state,
1424                                 struct smb_full_audit_fsync_state);
1425         if (req == NULL) {
1426                 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1427                        fsp_str_do_log(fsp));
1428                 return NULL;
1429         }
1430         state->handle = handle;
1431         state->fsp = fsp;
1432
1433         subreq = SMB_VFS_NEXT_FSYNC_SEND(state, ev, handle, fsp);
1434         if (tevent_req_nomem(subreq, req)) {
1435                 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1436                        fsp_str_do_log(fsp));
1437                 return tevent_req_post(req, ev);
1438         }
1439         tevent_req_set_callback(subreq, smb_full_audit_fsync_done, req);
1440
1441         do_log(SMB_VFS_OP_FSYNC_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1442         return req;
1443 }
1444
1445 static void smb_full_audit_fsync_done(struct tevent_req *subreq)
1446 {
1447         struct tevent_req *req = tevent_req_callback_data(
1448                 subreq, struct tevent_req);
1449         struct smb_full_audit_fsync_state *state = tevent_req_data(
1450                 req, struct smb_full_audit_fsync_state);
1451
1452         state->ret = SMB_VFS_FSYNC_RECV(subreq, &state->vfs_aio_state);
1453         TALLOC_FREE(subreq);
1454         tevent_req_done(req);
1455 }
1456
1457 static int smb_full_audit_fsync_recv(struct tevent_req *req,
1458                                      struct vfs_aio_state *vfs_aio_state)
1459 {
1460         struct smb_full_audit_fsync_state *state = tevent_req_data(
1461                 req, struct smb_full_audit_fsync_state);
1462
1463         if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1464                 do_log(SMB_VFS_OP_FSYNC_RECV, false, state->handle, "%s",
1465                        fsp_str_do_log(state->fsp));
1466                 return -1;
1467         }
1468
1469         do_log(SMB_VFS_OP_FSYNC_RECV, (state->ret >= 0), state->handle, "%s",
1470                fsp_str_do_log(state->fsp));
1471
1472         *vfs_aio_state = state->vfs_aio_state;
1473         return state->ret;
1474 }
1475
1476 static int smb_full_audit_stat(vfs_handle_struct *handle,
1477                                struct smb_filename *smb_fname)
1478 {
1479         int result;
1480         
1481         result = SMB_VFS_NEXT_STAT(handle, smb_fname);
1482
1483         do_log(SMB_VFS_OP_STAT, (result >= 0), handle, "%s",
1484                smb_fname_str_do_log(handle->conn, smb_fname));
1485
1486         return result;    
1487 }
1488
1489 static int smb_full_audit_fstat(vfs_handle_struct *handle, files_struct *fsp,
1490                        SMB_STRUCT_STAT *sbuf)
1491 {
1492         int result;
1493         
1494         result = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1495
1496         do_log(SMB_VFS_OP_FSTAT, (result >= 0), handle, "%s",
1497                fsp_str_do_log(fsp));
1498
1499         return result;
1500 }
1501
1502 static int smb_full_audit_lstat(vfs_handle_struct *handle,
1503                                 struct smb_filename *smb_fname)
1504 {
1505         int result;
1506         
1507         result = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
1508
1509         do_log(SMB_VFS_OP_LSTAT, (result >= 0), handle, "%s",
1510                smb_fname_str_do_log(handle->conn, smb_fname));
1511
1512         return result;    
1513 }
1514
1515 static uint64_t smb_full_audit_get_alloc_size(vfs_handle_struct *handle,
1516                        files_struct *fsp, const SMB_STRUCT_STAT *sbuf)
1517 {
1518         uint64_t result;
1519
1520         result = SMB_VFS_NEXT_GET_ALLOC_SIZE(handle, fsp, sbuf);
1521
1522         do_log(SMB_VFS_OP_GET_ALLOC_SIZE, (result != (uint64_t)-1), handle,
1523                         "%llu", (unsigned long long)result);
1524
1525         return result;
1526 }
1527
1528 static int smb_full_audit_unlinkat(vfs_handle_struct *handle,
1529                         struct files_struct *dirfsp,
1530                         const struct smb_filename *smb_fname,
1531                         int flags)
1532 {
1533         int result;
1534
1535         result = SMB_VFS_NEXT_UNLINKAT(handle,
1536                         dirfsp,
1537                         smb_fname,
1538                         flags);
1539
1540         do_log(SMB_VFS_OP_UNLINKAT, (result >= 0), handle, "%s",
1541                smb_fname_str_do_log(handle->conn, smb_fname));
1542
1543         return result;
1544 }
1545
1546 static int smb_full_audit_chmod(vfs_handle_struct *handle,
1547                                 const struct smb_filename *smb_fname,
1548                                 mode_t mode)
1549 {
1550         int result;
1551
1552         result = SMB_VFS_NEXT_CHMOD(handle, smb_fname, mode);
1553
1554         do_log(SMB_VFS_OP_CHMOD,
1555                (result >= 0),
1556                handle,
1557                "%s|%o",
1558                smb_fname_str_do_log(handle->conn, smb_fname),
1559                mode);
1560
1561         return result;
1562 }
1563
1564 static int smb_full_audit_fchmod(vfs_handle_struct *handle, files_struct *fsp,
1565                         mode_t mode)
1566 {
1567         int result;
1568         
1569         result = SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1570
1571         do_log(SMB_VFS_OP_FCHMOD, (result >= 0), handle,
1572                "%s|%o", fsp_str_do_log(fsp), mode);
1573
1574         return result;
1575 }
1576
1577 static int smb_full_audit_fchown(vfs_handle_struct *handle, files_struct *fsp,
1578                         uid_t uid, gid_t gid)
1579 {
1580         int result;
1581
1582         result = SMB_VFS_NEXT_FCHOWN(handle, fsp, uid, gid);
1583
1584         do_log(SMB_VFS_OP_FCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1585                fsp_str_do_log(fsp), (long int)uid, (long int)gid);
1586
1587         return result;
1588 }
1589
1590 static int smb_full_audit_lchown(vfs_handle_struct *handle,
1591                         const struct smb_filename *smb_fname,
1592                         uid_t uid,
1593                         gid_t gid)
1594 {
1595         int result;
1596
1597         result = SMB_VFS_NEXT_LCHOWN(handle, smb_fname, uid, gid);
1598
1599         do_log(SMB_VFS_OP_LCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1600                smb_fname->base_name, (long int)uid, (long int)gid);
1601
1602         return result;
1603 }
1604
1605 static int smb_full_audit_chdir(vfs_handle_struct *handle,
1606                         const struct smb_filename *smb_fname)
1607 {
1608         int result;
1609
1610         result = SMB_VFS_NEXT_CHDIR(handle, smb_fname);
1611
1612         do_log(SMB_VFS_OP_CHDIR,
1613                (result >= 0),
1614                handle,
1615                "chdir|%s",
1616                smb_fname_str_do_log(handle->conn, smb_fname));
1617
1618         return result;
1619 }
1620
1621 static struct smb_filename *smb_full_audit_getwd(vfs_handle_struct *handle,
1622                                 TALLOC_CTX *ctx)
1623 {
1624         struct smb_filename *result;
1625
1626         result = SMB_VFS_NEXT_GETWD(handle, ctx);
1627         
1628         do_log(SMB_VFS_OP_GETWD, (result != NULL), handle, "%s",
1629                 result == NULL? "" : result->base_name);
1630
1631         return result;
1632 }
1633
1634 static int smb_full_audit_ntimes(vfs_handle_struct *handle,
1635                                  const struct smb_filename *smb_fname,
1636                                  struct smb_file_time *ft)
1637 {
1638         int result;
1639         time_t create_time = convert_timespec_to_time_t(ft->create_time);
1640         time_t atime = convert_timespec_to_time_t(ft->atime);
1641         time_t mtime = convert_timespec_to_time_t(ft->mtime);
1642         time_t ctime = convert_timespec_to_time_t(ft->ctime);
1643         const char *create_time_str = "";
1644         const char *atime_str = "";
1645         const char *mtime_str = "";
1646         const char *ctime_str = "";
1647         TALLOC_CTX *frame = talloc_stackframe();
1648
1649         result = SMB_VFS_NEXT_NTIMES(handle, smb_fname, ft);
1650
1651         if (create_time > 0) {
1652                 create_time_str = timestring(frame, create_time);
1653         }
1654         if (atime > 0) {
1655                 atime_str = timestring(frame, atime);
1656         }
1657         if (mtime > 0) {
1658                 mtime_str = timestring(frame, mtime);
1659         }
1660         if (ctime > 0) {
1661                 ctime_str = timestring(frame, ctime);
1662         }
1663
1664         do_log(SMB_VFS_OP_NTIMES,
1665                (result >= 0),
1666                handle,
1667                "%s|%s|%s|%s|%s",
1668                smb_fname_str_do_log(handle->conn, smb_fname),
1669                create_time_str,
1670                atime_str,
1671                mtime_str,
1672                ctime_str);
1673
1674         TALLOC_FREE(frame);
1675
1676         return result;
1677 }
1678
1679 static int smb_full_audit_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
1680                            off_t len)
1681 {
1682         int result;
1683
1684         result = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1685
1686         do_log(SMB_VFS_OP_FTRUNCATE, (result >= 0), handle,
1687                "%s", fsp_str_do_log(fsp));
1688
1689         return result;
1690 }
1691
1692 static int smb_full_audit_fallocate(vfs_handle_struct *handle, files_struct *fsp,
1693                            uint32_t mode,
1694                            off_t offset,
1695                            off_t len)
1696 {
1697         int result;
1698
1699         result = SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
1700
1701         do_log(SMB_VFS_OP_FALLOCATE, (result >= 0), handle,
1702                "%s", fsp_str_do_log(fsp));
1703
1704         return result;
1705 }
1706
1707 static bool smb_full_audit_lock(vfs_handle_struct *handle, files_struct *fsp,
1708                        int op, off_t offset, off_t count, int type)
1709 {
1710         bool result;
1711
1712         result = SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type);
1713
1714         do_log(SMB_VFS_OP_LOCK, result, handle, "%s", fsp_str_do_log(fsp));
1715
1716         return result;
1717 }
1718
1719 static int smb_full_audit_kernel_flock(struct vfs_handle_struct *handle,
1720                                        struct files_struct *fsp,
1721                                        uint32_t share_access,
1722                                        uint32_t access_mask)
1723 {
1724         int result;
1725
1726         result = SMB_VFS_NEXT_KERNEL_FLOCK(handle,
1727                                            fsp,
1728                                            share_access,
1729                                            access_mask);
1730
1731         do_log(SMB_VFS_OP_KERNEL_FLOCK, (result >= 0), handle, "%s",
1732                fsp_str_do_log(fsp));
1733
1734         return result;
1735 }
1736
1737 static int smb_full_audit_fcntl(struct vfs_handle_struct *handle,
1738                                 struct files_struct *fsp,
1739                                 int cmd, va_list cmd_arg)
1740 {
1741         void *arg;
1742         va_list dup_cmd_arg;
1743         int result;
1744
1745         va_copy(dup_cmd_arg, cmd_arg);
1746         arg = va_arg(dup_cmd_arg, void *);
1747         result = SMB_VFS_NEXT_FCNTL(handle, fsp, cmd, arg);
1748         va_end(dup_cmd_arg);
1749
1750         do_log(SMB_VFS_OP_FCNTL, (result >= 0), handle, "%s",
1751                fsp_str_do_log(fsp));
1752
1753         return result;
1754 }
1755
1756 static int smb_full_audit_linux_setlease(vfs_handle_struct *handle, files_struct *fsp,
1757                                  int leasetype)
1758 {
1759         int result;
1760
1761         result = SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
1762
1763         do_log(SMB_VFS_OP_LINUX_SETLEASE, (result >= 0), handle, "%s",
1764                fsp_str_do_log(fsp));
1765
1766         return result;
1767 }
1768
1769 static bool smb_full_audit_getlock(vfs_handle_struct *handle, files_struct *fsp,
1770                        off_t *poffset, off_t *pcount, int *ptype, pid_t *ppid)
1771 {
1772         bool result;
1773
1774         result = SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype, ppid);
1775
1776         do_log(SMB_VFS_OP_GETLOCK, result, handle, "%s", fsp_str_do_log(fsp));
1777
1778         return result;
1779 }
1780
1781 static int smb_full_audit_symlinkat(vfs_handle_struct *handle,
1782                         const char *link_contents,
1783                         struct files_struct *dirfsp,
1784                         const struct smb_filename *new_smb_fname)
1785 {
1786         int result;
1787
1788         result = SMB_VFS_NEXT_SYMLINKAT(handle,
1789                                 link_contents,
1790                                 dirfsp,
1791                                 new_smb_fname);
1792
1793         do_log(SMB_VFS_OP_SYMLINKAT,
1794                (result >= 0),
1795                handle,
1796                "%s|%s",
1797                link_contents,
1798                smb_fname_str_do_log(handle->conn, new_smb_fname));
1799
1800         return result;
1801 }
1802
1803 static int smb_full_audit_readlinkat(vfs_handle_struct *handle,
1804                         files_struct *dirfsp,
1805                         const struct smb_filename *smb_fname,
1806                         char *buf,
1807                         size_t bufsiz)
1808 {
1809         int result;
1810
1811         result = SMB_VFS_NEXT_READLINKAT(handle,
1812                         dirfsp,
1813                         smb_fname,
1814                         buf,
1815                         bufsiz);
1816
1817         do_log(SMB_VFS_OP_READLINKAT,
1818                (result >= 0),
1819                handle,
1820                "%s",
1821                smb_fname_str_do_log(handle->conn, smb_fname));
1822
1823         return result;
1824 }
1825
1826 static int smb_full_audit_linkat(vfs_handle_struct *handle,
1827                         files_struct *srcfsp,
1828                         const struct smb_filename *old_smb_fname,
1829                         files_struct *dstfsp,
1830                         const struct smb_filename *new_smb_fname,
1831                         int flags)
1832 {
1833         int result;
1834
1835         result = SMB_VFS_NEXT_LINKAT(handle,
1836                         srcfsp,
1837                         old_smb_fname,
1838                         dstfsp,
1839                         new_smb_fname,
1840                         flags);
1841
1842         do_log(SMB_VFS_OP_LINKAT,
1843                (result >= 0),
1844                handle,
1845                "%s|%s",
1846                smb_fname_str_do_log(handle->conn, old_smb_fname),
1847                smb_fname_str_do_log(handle->conn, new_smb_fname));
1848
1849         return result;
1850 }
1851
1852 static int smb_full_audit_mknodat(vfs_handle_struct *handle,
1853                         files_struct *dirfsp,
1854                         const struct smb_filename *smb_fname,
1855                         mode_t mode,
1856                         SMB_DEV_T dev)
1857 {
1858         int result;
1859
1860         result = SMB_VFS_NEXT_MKNODAT(handle,
1861                                 dirfsp,
1862                                 smb_fname,
1863                                 mode,
1864                                 dev);
1865
1866         do_log(SMB_VFS_OP_MKNODAT,
1867                (result >= 0),
1868                handle,
1869                "%s",
1870                smb_fname_str_do_log(handle->conn, smb_fname));
1871
1872         return result;
1873 }
1874
1875 static struct smb_filename *smb_full_audit_realpath(vfs_handle_struct *handle,
1876                                 TALLOC_CTX *ctx,
1877                                 const struct smb_filename *smb_fname)
1878 {
1879         struct smb_filename *result_fname = NULL;
1880
1881         result_fname = SMB_VFS_NEXT_REALPATH(handle, ctx, smb_fname);
1882
1883         do_log(SMB_VFS_OP_REALPATH,
1884                (result_fname != NULL),
1885                handle,
1886                "%s",
1887                smb_fname_str_do_log(handle->conn, smb_fname));
1888
1889         return result_fname;
1890 }
1891
1892 static int smb_full_audit_chflags(vfs_handle_struct *handle,
1893                         const struct smb_filename *smb_fname,
1894                         unsigned int flags)
1895 {
1896         int result;
1897
1898         result = SMB_VFS_NEXT_CHFLAGS(handle, smb_fname, flags);
1899
1900         do_log(SMB_VFS_OP_CHFLAGS,
1901                (result != 0),
1902                handle,
1903                "%s",
1904                smb_fname_str_do_log(handle->conn, smb_fname));
1905
1906         return result;
1907 }
1908
1909 static struct file_id smb_full_audit_file_id_create(struct vfs_handle_struct *handle,
1910                                                     const SMB_STRUCT_STAT *sbuf)
1911 {
1912         struct file_id id_zero = { 0 };
1913         struct file_id result;
1914         struct file_id_buf idbuf;
1915
1916         result = SMB_VFS_NEXT_FILE_ID_CREATE(handle, sbuf);
1917
1918         do_log(SMB_VFS_OP_FILE_ID_CREATE,
1919                !file_id_equal(&id_zero, &result),
1920                handle,
1921                "%s",
1922                file_id_str_buf(result, &idbuf));
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         .create_dfs_pathat_fn = smb_full_audit_create_dfs_pathat,
2964         .opendir_fn = smb_full_audit_opendir,
2965         .fdopendir_fn = smb_full_audit_fdopendir,
2966         .readdir_fn = smb_full_audit_readdir,
2967         .seekdir_fn = smb_full_audit_seekdir,
2968         .telldir_fn = smb_full_audit_telldir,
2969         .rewind_dir_fn = smb_full_audit_rewinddir,
2970         .mkdirat_fn = smb_full_audit_mkdirat,
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         .fchown_fn = smb_full_audit_fchown,
2995         .lchown_fn = smb_full_audit_lchown,
2996         .chdir_fn = smb_full_audit_chdir,
2997         .getwd_fn = smb_full_audit_getwd,
2998         .ntimes_fn = smb_full_audit_ntimes,
2999         .ftruncate_fn = smb_full_audit_ftruncate,
3000         .fallocate_fn = smb_full_audit_fallocate,
3001         .lock_fn = smb_full_audit_lock,
3002         .kernel_flock_fn = smb_full_audit_kernel_flock,
3003         .fcntl_fn = smb_full_audit_fcntl,
3004         .linux_setlease_fn = smb_full_audit_linux_setlease,
3005         .getlock_fn = smb_full_audit_getlock,
3006         .symlinkat_fn = smb_full_audit_symlinkat,
3007         .readlinkat_fn = smb_full_audit_readlinkat,
3008         .linkat_fn = smb_full_audit_linkat,
3009         .mknodat_fn = smb_full_audit_mknodat,
3010         .realpath_fn = smb_full_audit_realpath,
3011         .chflags_fn = smb_full_audit_chflags,
3012         .file_id_create_fn = smb_full_audit_file_id_create,
3013         .fs_file_id_fn = smb_full_audit_fs_file_id,
3014         .offload_read_send_fn = smb_full_audit_offload_read_send,
3015         .offload_read_recv_fn = smb_full_audit_offload_read_recv,
3016         .offload_write_send_fn = smb_full_audit_offload_write_send,
3017         .offload_write_recv_fn = smb_full_audit_offload_write_recv,
3018         .get_compression_fn = smb_full_audit_get_compression,
3019         .set_compression_fn = smb_full_audit_set_compression,
3020         .snap_check_path_fn =  smb_full_audit_snap_check_path,
3021         .snap_create_fn = smb_full_audit_snap_create,
3022         .snap_delete_fn = smb_full_audit_snap_delete,
3023         .streaminfo_fn = smb_full_audit_streaminfo,
3024         .get_real_filename_fn = smb_full_audit_get_real_filename,
3025         .connectpath_fn = smb_full_audit_connectpath,
3026         .brl_lock_windows_fn = smb_full_audit_brl_lock_windows,
3027         .brl_unlock_windows_fn = smb_full_audit_brl_unlock_windows,
3028         .strict_lock_check_fn = smb_full_audit_strict_lock_check,
3029         .translate_name_fn = smb_full_audit_translate_name,
3030         .fsctl_fn = smb_full_audit_fsctl,
3031         .get_dos_attributes_fn = smb_full_audit_get_dos_attributes,
3032         .get_dos_attributes_send_fn = smb_full_audit_get_dos_attributes_send,
3033         .get_dos_attributes_recv_fn = smb_full_audit_get_dos_attributes_recv,
3034         .fget_dos_attributes_fn = smb_full_audit_fget_dos_attributes,
3035         .set_dos_attributes_fn = smb_full_audit_set_dos_attributes,
3036         .fset_dos_attributes_fn = smb_full_audit_fset_dos_attributes,
3037         .fget_nt_acl_fn = smb_full_audit_fget_nt_acl,
3038         .get_nt_acl_fn = smb_full_audit_get_nt_acl,
3039         .fset_nt_acl_fn = smb_full_audit_fset_nt_acl,
3040         .audit_file_fn = smb_full_audit_audit_file,
3041         .sys_acl_get_file_fn = smb_full_audit_sys_acl_get_file,
3042         .sys_acl_get_fd_fn = smb_full_audit_sys_acl_get_fd,
3043         .sys_acl_blob_get_file_fn = smb_full_audit_sys_acl_blob_get_file,
3044         .sys_acl_blob_get_fd_fn = smb_full_audit_sys_acl_blob_get_fd,
3045         .sys_acl_set_file_fn = smb_full_audit_sys_acl_set_file,
3046         .sys_acl_set_fd_fn = smb_full_audit_sys_acl_set_fd,
3047         .sys_acl_delete_def_file_fn = smb_full_audit_sys_acl_delete_def_file,
3048         .getxattr_fn = smb_full_audit_getxattr,
3049         .getxattrat_send_fn = smb_full_audit_getxattrat_send,
3050         .getxattrat_recv_fn = smb_full_audit_getxattrat_recv,
3051         .fgetxattr_fn = smb_full_audit_fgetxattr,
3052         .listxattr_fn = smb_full_audit_listxattr,
3053         .flistxattr_fn = smb_full_audit_flistxattr,
3054         .removexattr_fn = smb_full_audit_removexattr,
3055         .fremovexattr_fn = smb_full_audit_fremovexattr,
3056         .setxattr_fn = smb_full_audit_setxattr,
3057         .fsetxattr_fn = smb_full_audit_fsetxattr,
3058         .aio_force_fn = smb_full_audit_aio_force,
3059         .durable_cookie_fn = smb_full_audit_durable_cookie,
3060         .durable_disconnect_fn = smb_full_audit_durable_disconnect,
3061         .durable_reconnect_fn = smb_full_audit_durable_reconnect,
3062         .readdir_attr_fn = smb_full_audit_readdir_attr
3063
3064 };
3065
3066 static_decl_vfs;
3067 NTSTATUS vfs_full_audit_init(TALLOC_CTX *ctx)
3068 {
3069         NTSTATUS ret;
3070
3071         smb_vfs_assert_all_fns(&vfs_full_audit_fns, "full_audit");
3072
3073         ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "full_audit",
3074                                &vfs_full_audit_fns);
3075
3076         if (!NT_STATUS_IS_OK(ret))
3077                 return ret;
3078
3079         vfs_full_audit_debug_level = debug_add_class("full_audit");
3080         if (vfs_full_audit_debug_level == -1) {
3081                 vfs_full_audit_debug_level = DBGC_VFS;
3082                 DEBUG(0, ("vfs_full_audit: Couldn't register custom debugging "
3083                           "class!\n"));
3084         } else {
3085                 DEBUG(10, ("vfs_full_audit: Debug class number of "
3086                            "'full_audit': %d\n", vfs_full_audit_debug_level));
3087         }
3088         
3089         return ret;
3090 }