libcli/smb: Allow smb2cli_validate_negotiate_info_done() to ignore NT_STATUS_INVALID_...
[Samba.git] / source3 / modules / vfs_full_audit.c
blobb0237cdacbad393be0e6ff89158c3096598a2bf7
1 /*
2 * Auditing VFS module for samba. Log selected file operations to syslog
3 * facility.
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
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.
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.
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/>.
26 * This module implements parseable logging for all Samba VFS operations.
28 * You use it as follows:
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
37 * vfs op can be "all" which means log all operations.
38 * vfs op can be "none" which means no logging.
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
46 * where "nobody" is the connected username and "192.168.234.1" is the
47 * client's IP address.
49 * Options:
51 * prefix: A macro expansion template prepended to the syslog entry.
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.
57 * failure: A list of VFS operations for which failure to complete should be
58 * logged. Defaults to logging everything.
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"
76 static int vfs_full_audit_debug_level = DBGC_VFS;
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;
87 #undef DBGC_CLASS
88 #define DBGC_CLASS vfs_full_audit_debug_level
90 typedef enum _vfs_op_type {
91 SMB_VFS_OP_NOOP = -1,
93 /* Disk operations */
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 SMB_VFS_OP_READ_DFS_PATHAT,
107 /* Directory operations */
109 SMB_VFS_OP_OPENDIR,
110 SMB_VFS_OP_FDOPENDIR,
111 SMB_VFS_OP_READDIR,
112 SMB_VFS_OP_SEEKDIR,
113 SMB_VFS_OP_TELLDIR,
114 SMB_VFS_OP_REWINDDIR,
115 SMB_VFS_OP_MKDIRAT,
116 SMB_VFS_OP_CLOSEDIR,
118 /* File operations */
120 SMB_VFS_OP_OPEN,
121 SMB_VFS_OP_CREATE_FILE,
122 SMB_VFS_OP_CLOSE,
123 SMB_VFS_OP_READ,
124 SMB_VFS_OP_PREAD,
125 SMB_VFS_OP_PREAD_SEND,
126 SMB_VFS_OP_PREAD_RECV,
127 SMB_VFS_OP_WRITE,
128 SMB_VFS_OP_PWRITE,
129 SMB_VFS_OP_PWRITE_SEND,
130 SMB_VFS_OP_PWRITE_RECV,
131 SMB_VFS_OP_LSEEK,
132 SMB_VFS_OP_SENDFILE,
133 SMB_VFS_OP_RECVFILE,
134 SMB_VFS_OP_RENAMEAT,
135 SMB_VFS_OP_FSYNC,
136 SMB_VFS_OP_FSYNC_SEND,
137 SMB_VFS_OP_FSYNC_RECV,
138 SMB_VFS_OP_STAT,
139 SMB_VFS_OP_FSTAT,
140 SMB_VFS_OP_LSTAT,
141 SMB_VFS_OP_GET_ALLOC_SIZE,
142 SMB_VFS_OP_UNLINKAT,
143 SMB_VFS_OP_CHMOD,
144 SMB_VFS_OP_FCHMOD,
145 SMB_VFS_OP_FCHOWN,
146 SMB_VFS_OP_LCHOWN,
147 SMB_VFS_OP_CHDIR,
148 SMB_VFS_OP_GETWD,
149 SMB_VFS_OP_NTIMES,
150 SMB_VFS_OP_FTRUNCATE,
151 SMB_VFS_OP_FALLOCATE,
152 SMB_VFS_OP_LOCK,
153 SMB_VFS_OP_KERNEL_FLOCK,
154 SMB_VFS_OP_FCNTL,
155 SMB_VFS_OP_LINUX_SETLEASE,
156 SMB_VFS_OP_GETLOCK,
157 SMB_VFS_OP_SYMLINKAT,
158 SMB_VFS_OP_READLINKAT,
159 SMB_VFS_OP_LINKAT,
160 SMB_VFS_OP_MKNODAT,
161 SMB_VFS_OP_REALPATH,
162 SMB_VFS_OP_CHFLAGS,
163 SMB_VFS_OP_FILE_ID_CREATE,
164 SMB_VFS_OP_FS_FILE_ID,
165 SMB_VFS_OP_STREAMINFO,
166 SMB_VFS_OP_GET_REAL_FILENAME,
167 SMB_VFS_OP_CONNECTPATH,
168 SMB_VFS_OP_BRL_LOCK_WINDOWS,
169 SMB_VFS_OP_BRL_UNLOCK_WINDOWS,
170 SMB_VFS_OP_STRICT_LOCK_CHECK,
171 SMB_VFS_OP_TRANSLATE_NAME,
172 SMB_VFS_OP_FSCTL,
173 SMB_VFS_OP_OFFLOAD_READ_SEND,
174 SMB_VFS_OP_OFFLOAD_READ_RECV,
175 SMB_VFS_OP_OFFLOAD_WRITE_SEND,
176 SMB_VFS_OP_OFFLOAD_WRITE_RECV,
177 SMB_VFS_OP_GET_COMPRESSION,
178 SMB_VFS_OP_SET_COMPRESSION,
179 SMB_VFS_OP_SNAP_CHECK_PATH,
180 SMB_VFS_OP_SNAP_CREATE,
181 SMB_VFS_OP_SNAP_DELETE,
183 /* DOS attribute operations. */
184 SMB_VFS_OP_GET_DOS_ATTRIBUTES,
185 SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
186 SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV,
187 SMB_VFS_OP_FGET_DOS_ATTRIBUTES,
188 SMB_VFS_OP_SET_DOS_ATTRIBUTES,
189 SMB_VFS_OP_FSET_DOS_ATTRIBUTES,
191 /* NT ACL operations. */
193 SMB_VFS_OP_FGET_NT_ACL,
194 SMB_VFS_OP_GET_NT_ACL,
195 SMB_VFS_OP_FSET_NT_ACL,
196 SMB_VFS_OP_AUDIT_FILE,
198 /* POSIX ACL operations. */
200 SMB_VFS_OP_SYS_ACL_GET_FILE,
201 SMB_VFS_OP_SYS_ACL_GET_FD,
202 SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE,
203 SMB_VFS_OP_SYS_ACL_BLOB_GET_FD,
204 SMB_VFS_OP_SYS_ACL_SET_FILE,
205 SMB_VFS_OP_SYS_ACL_SET_FD,
206 SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE,
208 /* EA operations. */
209 SMB_VFS_OP_GETXATTR,
210 SMB_VFS_OP_GETXATTRAT_SEND,
211 SMB_VFS_OP_GETXATTRAT_RECV,
212 SMB_VFS_OP_FGETXATTR,
213 SMB_VFS_OP_LISTXATTR,
214 SMB_VFS_OP_FLISTXATTR,
215 SMB_VFS_OP_REMOVEXATTR,
216 SMB_VFS_OP_FREMOVEXATTR,
217 SMB_VFS_OP_SETXATTR,
218 SMB_VFS_OP_FSETXATTR,
220 /* aio operations */
221 SMB_VFS_OP_AIO_FORCE,
223 /* offline operations */
224 SMB_VFS_OP_IS_OFFLINE,
225 SMB_VFS_OP_SET_OFFLINE,
227 /* Durable handle operations. */
228 SMB_VFS_OP_DURABLE_COOKIE,
229 SMB_VFS_OP_DURABLE_DISCONNECT,
230 SMB_VFS_OP_DURABLE_RECONNECT,
232 SMB_VFS_OP_READDIR_ATTR,
234 /* This should always be last enum value */
236 SMB_VFS_OP_LAST
237 } vfs_op_type;
239 /* The following array *must* be in the same order as defined in vfs_op_type */
241 static struct {
242 vfs_op_type type;
243 const char *name;
244 } vfs_op_names[] = {
245 { SMB_VFS_OP_CONNECT, "connect" },
246 { SMB_VFS_OP_DISCONNECT, "disconnect" },
247 { SMB_VFS_OP_DISK_FREE, "disk_free" },
248 { SMB_VFS_OP_GET_QUOTA, "get_quota" },
249 { SMB_VFS_OP_SET_QUOTA, "set_quota" },
250 { SMB_VFS_OP_GET_SHADOW_COPY_DATA, "get_shadow_copy_data" },
251 { SMB_VFS_OP_STATVFS, "statvfs" },
252 { SMB_VFS_OP_FS_CAPABILITIES, "fs_capabilities" },
253 { SMB_VFS_OP_GET_DFS_REFERRALS, "get_dfs_referrals" },
254 { SMB_VFS_OP_CREATE_DFS_PATHAT, "create_dfs_pathat" },
255 { SMB_VFS_OP_READ_DFS_PATHAT, "read_dfs_pathat" },
256 { SMB_VFS_OP_OPENDIR, "opendir" },
257 { SMB_VFS_OP_FDOPENDIR, "fdopendir" },
258 { SMB_VFS_OP_READDIR, "readdir" },
259 { SMB_VFS_OP_SEEKDIR, "seekdir" },
260 { SMB_VFS_OP_TELLDIR, "telldir" },
261 { SMB_VFS_OP_REWINDDIR, "rewinddir" },
262 { SMB_VFS_OP_MKDIRAT, "mkdirat" },
263 { SMB_VFS_OP_CLOSEDIR, "closedir" },
264 { SMB_VFS_OP_OPEN, "open" },
265 { SMB_VFS_OP_CREATE_FILE, "create_file" },
266 { SMB_VFS_OP_CLOSE, "close" },
267 { SMB_VFS_OP_READ, "read" },
268 { SMB_VFS_OP_PREAD, "pread" },
269 { SMB_VFS_OP_PREAD_SEND, "pread_send" },
270 { SMB_VFS_OP_PREAD_RECV, "pread_recv" },
271 { SMB_VFS_OP_WRITE, "write" },
272 { SMB_VFS_OP_PWRITE, "pwrite" },
273 { SMB_VFS_OP_PWRITE_SEND, "pwrite_send" },
274 { SMB_VFS_OP_PWRITE_RECV, "pwrite_recv" },
275 { SMB_VFS_OP_LSEEK, "lseek" },
276 { SMB_VFS_OP_SENDFILE, "sendfile" },
277 { SMB_VFS_OP_RECVFILE, "recvfile" },
278 { SMB_VFS_OP_RENAMEAT, "renameat" },
279 { SMB_VFS_OP_FSYNC, "fsync" },
280 { SMB_VFS_OP_FSYNC_SEND, "fsync_send" },
281 { SMB_VFS_OP_FSYNC_RECV, "fsync_recv" },
282 { SMB_VFS_OP_STAT, "stat" },
283 { SMB_VFS_OP_FSTAT, "fstat" },
284 { SMB_VFS_OP_LSTAT, "lstat" },
285 { SMB_VFS_OP_GET_ALLOC_SIZE, "get_alloc_size" },
286 { SMB_VFS_OP_UNLINKAT, "unlinkat" },
287 { SMB_VFS_OP_CHMOD, "chmod" },
288 { SMB_VFS_OP_FCHMOD, "fchmod" },
289 { SMB_VFS_OP_FCHOWN, "fchown" },
290 { SMB_VFS_OP_LCHOWN, "lchown" },
291 { SMB_VFS_OP_CHDIR, "chdir" },
292 { SMB_VFS_OP_GETWD, "getwd" },
293 { SMB_VFS_OP_NTIMES, "ntimes" },
294 { SMB_VFS_OP_FTRUNCATE, "ftruncate" },
295 { SMB_VFS_OP_FALLOCATE,"fallocate" },
296 { SMB_VFS_OP_LOCK, "lock" },
297 { SMB_VFS_OP_KERNEL_FLOCK, "kernel_flock" },
298 { SMB_VFS_OP_FCNTL, "fcntl" },
299 { SMB_VFS_OP_LINUX_SETLEASE, "linux_setlease" },
300 { SMB_VFS_OP_GETLOCK, "getlock" },
301 { SMB_VFS_OP_SYMLINKAT, "symlinkat" },
302 { SMB_VFS_OP_READLINKAT,"readlinkat" },
303 { SMB_VFS_OP_LINKAT, "linkat" },
304 { SMB_VFS_OP_MKNODAT, "mknodat" },
305 { SMB_VFS_OP_REALPATH, "realpath" },
306 { SMB_VFS_OP_CHFLAGS, "chflags" },
307 { SMB_VFS_OP_FILE_ID_CREATE, "file_id_create" },
308 { SMB_VFS_OP_FS_FILE_ID, "fs_file_id" },
309 { SMB_VFS_OP_STREAMINFO, "streaminfo" },
310 { SMB_VFS_OP_GET_REAL_FILENAME, "get_real_filename" },
311 { SMB_VFS_OP_CONNECTPATH, "connectpath" },
312 { SMB_VFS_OP_BRL_LOCK_WINDOWS, "brl_lock_windows" },
313 { SMB_VFS_OP_BRL_UNLOCK_WINDOWS, "brl_unlock_windows" },
314 { SMB_VFS_OP_STRICT_LOCK_CHECK, "strict_lock_check" },
315 { SMB_VFS_OP_TRANSLATE_NAME, "translate_name" },
316 { SMB_VFS_OP_FSCTL, "fsctl" },
317 { SMB_VFS_OP_OFFLOAD_READ_SEND, "offload_read_send" },
318 { SMB_VFS_OP_OFFLOAD_READ_RECV, "offload_read_recv" },
319 { SMB_VFS_OP_OFFLOAD_WRITE_SEND, "offload_write_send" },
320 { SMB_VFS_OP_OFFLOAD_WRITE_RECV, "offload_write_recv" },
321 { SMB_VFS_OP_GET_COMPRESSION, "get_compression" },
322 { SMB_VFS_OP_SET_COMPRESSION, "set_compression" },
323 { SMB_VFS_OP_SNAP_CHECK_PATH, "snap_check_path" },
324 { SMB_VFS_OP_SNAP_CREATE, "snap_create" },
325 { SMB_VFS_OP_SNAP_DELETE, "snap_delete" },
326 { SMB_VFS_OP_GET_DOS_ATTRIBUTES, "get_dos_attributes" },
327 { SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND, "get_dos_attributes_send" },
328 { SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV, "get_dos_attributes_recv" },
329 { SMB_VFS_OP_FGET_DOS_ATTRIBUTES, "fget_dos_attributes" },
330 { SMB_VFS_OP_SET_DOS_ATTRIBUTES, "set_dos_attributes" },
331 { SMB_VFS_OP_FSET_DOS_ATTRIBUTES, "fset_dos_attributes" },
332 { SMB_VFS_OP_FGET_NT_ACL, "fget_nt_acl" },
333 { SMB_VFS_OP_GET_NT_ACL, "get_nt_acl" },
334 { SMB_VFS_OP_FSET_NT_ACL, "fset_nt_acl" },
335 { SMB_VFS_OP_AUDIT_FILE, "audit_file" },
336 { SMB_VFS_OP_SYS_ACL_GET_FILE, "sys_acl_get_file" },
337 { SMB_VFS_OP_SYS_ACL_GET_FD, "sys_acl_get_fd" },
338 { SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE, "sys_acl_blob_get_file" },
339 { SMB_VFS_OP_SYS_ACL_BLOB_GET_FD, "sys_acl_blob_get_fd" },
340 { SMB_VFS_OP_SYS_ACL_SET_FILE, "sys_acl_set_file" },
341 { SMB_VFS_OP_SYS_ACL_SET_FD, "sys_acl_set_fd" },
342 { SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE, "sys_acl_delete_def_file" },
343 { SMB_VFS_OP_GETXATTR, "getxattr" },
344 { SMB_VFS_OP_GETXATTRAT_SEND, "getxattrat_send" },
345 { SMB_VFS_OP_GETXATTRAT_RECV, "getxattrat_recv" },
346 { SMB_VFS_OP_FGETXATTR, "fgetxattr" },
347 { SMB_VFS_OP_LISTXATTR, "listxattr" },
348 { SMB_VFS_OP_FLISTXATTR, "flistxattr" },
349 { SMB_VFS_OP_REMOVEXATTR, "removexattr" },
350 { SMB_VFS_OP_FREMOVEXATTR, "fremovexattr" },
351 { SMB_VFS_OP_SETXATTR, "setxattr" },
352 { SMB_VFS_OP_FSETXATTR, "fsetxattr" },
353 { SMB_VFS_OP_AIO_FORCE, "aio_force" },
354 { SMB_VFS_OP_IS_OFFLINE, "is_offline" },
355 { SMB_VFS_OP_SET_OFFLINE, "set_offline" },
356 { SMB_VFS_OP_DURABLE_COOKIE, "durable_cookie" },
357 { SMB_VFS_OP_DURABLE_DISCONNECT, "durable_disconnect" },
358 { SMB_VFS_OP_DURABLE_RECONNECT, "durable_reconnect" },
359 { SMB_VFS_OP_READDIR_ATTR, "readdir_attr" },
360 { SMB_VFS_OP_LAST, NULL }
363 static int audit_syslog_facility(vfs_handle_struct *handle)
365 static const struct enum_list enum_log_facilities[] = {
366 #ifdef LOG_AUTH
367 { LOG_AUTH, "AUTH" },
368 #endif
369 #ifdef LOG_AUTHPRIV
370 { LOG_AUTHPRIV, "AUTHPRIV" },
371 #endif
372 #ifdef LOG_AUDIT
373 { LOG_AUDIT, "AUDIT" },
374 #endif
375 #ifdef LOG_CONSOLE
376 { LOG_CONSOLE, "CONSOLE" },
377 #endif
378 #ifdef LOG_CRON
379 { LOG_CRON, "CRON" },
380 #endif
381 #ifdef LOG_DAEMON
382 { LOG_DAEMON, "DAEMON" },
383 #endif
384 #ifdef LOG_FTP
385 { LOG_FTP, "FTP" },
386 #endif
387 #ifdef LOG_INSTALL
388 { LOG_INSTALL, "INSTALL" },
389 #endif
390 #ifdef LOG_KERN
391 { LOG_KERN, "KERN" },
392 #endif
393 #ifdef LOG_LAUNCHD
394 { LOG_LAUNCHD, "LAUNCHD" },
395 #endif
396 #ifdef LOG_LFMT
397 { LOG_LFMT, "LFMT" },
398 #endif
399 #ifdef LOG_LPR
400 { LOG_LPR, "LPR" },
401 #endif
402 #ifdef LOG_MAIL
403 { LOG_MAIL, "MAIL" },
404 #endif
405 #ifdef LOG_MEGASAFE
406 { LOG_MEGASAFE, "MEGASAFE" },
407 #endif
408 #ifdef LOG_NETINFO
409 { LOG_NETINFO, "NETINFO" },
410 #endif
411 #ifdef LOG_NEWS
412 { LOG_NEWS, "NEWS" },
413 #endif
414 #ifdef LOG_NFACILITIES
415 { LOG_NFACILITIES, "NFACILITIES" },
416 #endif
417 #ifdef LOG_NTP
418 { LOG_NTP, "NTP" },
419 #endif
420 #ifdef LOG_RAS
421 { LOG_RAS, "RAS" },
422 #endif
423 #ifdef LOG_REMOTEAUTH
424 { LOG_REMOTEAUTH, "REMOTEAUTH" },
425 #endif
426 #ifdef LOG_SECURITY
427 { LOG_SECURITY, "SECURITY" },
428 #endif
429 #ifdef LOG_SYSLOG
430 { LOG_SYSLOG, "SYSLOG" },
431 #endif
432 #ifdef LOG_USER
433 { LOG_USER, "USER" },
434 #endif
435 #ifdef LOG_UUCP
436 { LOG_UUCP, "UUCP" },
437 #endif
438 { LOG_LOCAL0, "LOCAL0" },
439 { LOG_LOCAL1, "LOCAL1" },
440 { LOG_LOCAL2, "LOCAL2" },
441 { LOG_LOCAL3, "LOCAL3" },
442 { LOG_LOCAL4, "LOCAL4" },
443 { LOG_LOCAL5, "LOCAL5" },
444 { LOG_LOCAL6, "LOCAL6" },
445 { LOG_LOCAL7, "LOCAL7" },
446 { -1, NULL }
449 int facility;
451 facility = lp_parm_enum(SNUM(handle->conn), "full_audit", "facility", enum_log_facilities, LOG_USER);
453 return facility;
456 static int audit_syslog_priority(vfs_handle_struct *handle)
458 static const struct enum_list enum_log_priorities[] = {
459 { LOG_EMERG, "EMERG" },
460 { LOG_ALERT, "ALERT" },
461 { LOG_CRIT, "CRIT" },
462 { LOG_ERR, "ERR" },
463 { LOG_WARNING, "WARNING" },
464 { LOG_NOTICE, "NOTICE" },
465 { LOG_INFO, "INFO" },
466 { LOG_DEBUG, "DEBUG" },
467 { -1, NULL }
470 int priority;
472 priority = lp_parm_enum(SNUM(handle->conn), "full_audit", "priority",
473 enum_log_priorities, LOG_NOTICE);
474 if (priority == -1) {
475 priority = LOG_WARNING;
478 return priority;
481 static char *audit_prefix(TALLOC_CTX *ctx, connection_struct *conn)
483 const struct loadparm_substitution *lp_sub =
484 loadparm_s3_global_substitution();
485 char *prefix = NULL;
486 char *result;
488 prefix = talloc_strdup(ctx,
489 lp_parm_const_string(SNUM(conn), "full_audit",
490 "prefix", "%u|%I"));
491 if (!prefix) {
492 return NULL;
494 result = talloc_sub_full(ctx,
495 lp_servicename(talloc_tos(), lp_sub, SNUM(conn)),
496 conn->session_info->unix_info->unix_name,
497 conn->connectpath,
498 conn->session_info->unix_token->gid,
499 conn->session_info->unix_info->sanitized_username,
500 conn->session_info->info->domain_name,
501 prefix);
502 TALLOC_FREE(prefix);
503 return result;
506 static bool log_success(struct vfs_full_audit_private_data *pd, vfs_op_type op)
508 if (pd->success_ops == NULL) {
509 return True;
512 return bitmap_query(pd->success_ops, op);
515 static bool log_failure(struct vfs_full_audit_private_data *pd, vfs_op_type op)
517 if (pd->failure_ops == NULL)
518 return True;
520 return bitmap_query(pd->failure_ops, op);
523 static struct bitmap *init_bitmap(TALLOC_CTX *mem_ctx, const char **ops)
525 struct bitmap *bm;
527 if (ops == NULL) {
528 return NULL;
531 bm = bitmap_talloc(mem_ctx, SMB_VFS_OP_LAST);
532 if (bm == NULL) {
533 DEBUG(0, ("Could not alloc bitmap -- "
534 "defaulting to logging everything\n"));
535 return NULL;
538 for (; *ops != NULL; ops += 1) {
539 int i;
540 bool neg = false;
541 const char *op;
543 if (strequal(*ops, "all")) {
544 for (i=0; i<SMB_VFS_OP_LAST; i++) {
545 bitmap_set(bm, i);
547 continue;
550 if (strequal(*ops, "none")) {
551 break;
554 op = ops[0];
555 if (op[0] == '!') {
556 neg = true;
557 op += 1;
560 for (i=0; i<SMB_VFS_OP_LAST; i++) {
561 if ((vfs_op_names[i].name == NULL)
562 || (vfs_op_names[i].type != i)) {
563 smb_panic("vfs_full_audit.c: name table not "
564 "in sync with vfs_op_type enums\n");
566 if (strequal(op, vfs_op_names[i].name)) {
567 if (neg) {
568 bitmap_clear(bm, i);
569 } else {
570 bitmap_set(bm, i);
572 break;
575 if (i == SMB_VFS_OP_LAST) {
576 DEBUG(0, ("Could not find opname %s, logging all\n",
577 *ops));
578 TALLOC_FREE(bm);
579 return NULL;
582 return bm;
585 static const char *audit_opname(vfs_op_type op)
587 if (op >= SMB_VFS_OP_LAST)
588 return "INVALID VFS OP";
589 return vfs_op_names[op].name;
592 static TALLOC_CTX *tmp_do_log_ctx;
594 * Get us a temporary talloc context usable just for DEBUG arguments
596 static TALLOC_CTX *do_log_ctx(void)
598 if (tmp_do_log_ctx == NULL) {
599 tmp_do_log_ctx = talloc_named_const(NULL, 0, "do_log_ctx");
601 return tmp_do_log_ctx;
604 static void do_log(vfs_op_type op, bool success, vfs_handle_struct *handle,
605 const char *format, ...) PRINTF_ATTRIBUTE(4, 5);
607 static void do_log(vfs_op_type op, bool success, vfs_handle_struct *handle,
608 const char *format, ...)
610 struct vfs_full_audit_private_data *pd;
611 fstring err_msg;
612 char *audit_pre = NULL;
613 va_list ap;
614 char *op_msg = NULL;
616 SMB_VFS_HANDLE_GET_DATA(handle, pd,
617 struct vfs_full_audit_private_data,
618 return;);
620 if (success && (!log_success(pd, op)))
621 goto out;
623 if (!success && (!log_failure(pd, op)))
624 goto out;
626 if (success)
627 fstrcpy(err_msg, "ok");
628 else
629 fstr_sprintf(err_msg, "fail (%s)", strerror(errno));
631 va_start(ap, format);
632 op_msg = talloc_vasprintf(talloc_tos(), format, ap);
633 va_end(ap);
635 if (!op_msg) {
636 goto out;
639 audit_pre = audit_prefix(talloc_tos(), handle->conn);
641 if (pd->do_syslog) {
642 int priority;
645 * Specify the facility to interoperate with other syslog
646 * callers (smbd for example).
648 priority = pd->syslog_priority | pd->syslog_facility;
650 syslog(priority, "%s|%s|%s|%s\n",
651 audit_pre ? audit_pre : "",
652 audit_opname(op), err_msg, op_msg);
653 } else {
654 DEBUG(1, ("%s|%s|%s|%s\n",
655 audit_pre ? audit_pre : "",
656 audit_opname(op), err_msg, op_msg));
658 out:
659 TALLOC_FREE(audit_pre);
660 TALLOC_FREE(op_msg);
661 TALLOC_FREE(tmp_do_log_ctx);
665 * Return a string using the do_log_ctx()
667 static const char *smb_fname_str_do_log(struct connection_struct *conn,
668 const struct smb_filename *smb_fname)
670 char *fname = NULL;
671 NTSTATUS status;
673 if (smb_fname == NULL) {
674 return "";
677 if (smb_fname->base_name[0] != '/') {
678 char *abs_name = NULL;
679 struct smb_filename *fname_copy = cp_smb_filename(
680 do_log_ctx(),
681 smb_fname);
682 if (fname_copy == NULL) {
683 return "";
686 if (!ISDOT(smb_fname->base_name)) {
687 abs_name = talloc_asprintf(do_log_ctx(),
688 "%s/%s",
689 conn->cwd_fsp->fsp_name->base_name,
690 smb_fname->base_name);
691 } else {
692 abs_name = talloc_strdup(do_log_ctx(),
693 conn->cwd_fsp->fsp_name->base_name);
695 if (abs_name == NULL) {
696 return "";
698 fname_copy->base_name = abs_name;
699 smb_fname = fname_copy;
702 status = get_full_smb_filename(do_log_ctx(), smb_fname, &fname);
703 if (!NT_STATUS_IS_OK(status)) {
704 return "";
706 return fname;
710 * Return an fsp debug string using the do_log_ctx()
712 static const char *fsp_str_do_log(const struct files_struct *fsp)
714 return smb_fname_str_do_log(fsp->conn, fsp->fsp_name);
717 /* Implementation of vfs_ops. Pass everything on to the default
718 operation but log event first. */
720 static int smb_full_audit_connect(vfs_handle_struct *handle,
721 const char *svc, const char *user)
723 int result;
724 const char *none[] = { "none" };
725 struct vfs_full_audit_private_data *pd = NULL;
727 result = SMB_VFS_NEXT_CONNECT(handle, svc, user);
728 if (result < 0) {
729 return result;
732 pd = talloc_zero(handle, struct vfs_full_audit_private_data);
733 if (!pd) {
734 SMB_VFS_NEXT_DISCONNECT(handle);
735 return -1;
738 pd->syslog_facility = audit_syslog_facility(handle);
739 if (pd->syslog_facility == -1) {
740 DEBUG(1, ("%s: Unknown facility %s\n", __func__,
741 lp_parm_const_string(SNUM(handle->conn),
742 "full_audit", "facility",
743 "USER")));
744 SMB_VFS_NEXT_DISCONNECT(handle);
745 return -1;
748 pd->syslog_priority = audit_syslog_priority(handle);
750 pd->log_secdesc = lp_parm_bool(SNUM(handle->conn),
751 "full_audit", "log_secdesc", false);
753 pd->do_syslog = lp_parm_bool(SNUM(handle->conn),
754 "full_audit", "syslog", true);
756 #ifdef WITH_SYSLOG
757 if (pd->do_syslog) {
758 openlog("smbd_audit", 0, pd->syslog_facility);
760 #endif
762 pd->success_ops = init_bitmap(
763 pd, lp_parm_string_list(SNUM(handle->conn), "full_audit",
764 "success", none));
765 pd->failure_ops = init_bitmap(
766 pd, lp_parm_string_list(SNUM(handle->conn), "full_audit",
767 "failure", none));
769 /* Store the private data. */
770 SMB_VFS_HANDLE_SET_DATA(handle, pd, NULL,
771 struct vfs_full_audit_private_data, return -1);
773 do_log(SMB_VFS_OP_CONNECT, True, handle,
774 "%s", svc);
776 return 0;
779 static void smb_full_audit_disconnect(vfs_handle_struct *handle)
781 const struct loadparm_substitution *lp_sub =
782 loadparm_s3_global_substitution();
784 SMB_VFS_NEXT_DISCONNECT(handle);
786 do_log(SMB_VFS_OP_DISCONNECT, True, handle,
787 "%s", lp_servicename(talloc_tos(), lp_sub, SNUM(handle->conn)));
789 /* The bitmaps will be disconnected when the private
790 data is deleted. */
793 static uint64_t smb_full_audit_disk_free(vfs_handle_struct *handle,
794 const struct smb_filename *smb_fname,
795 uint64_t *bsize,
796 uint64_t *dfree,
797 uint64_t *dsize)
799 uint64_t result;
801 result = SMB_VFS_NEXT_DISK_FREE(handle, smb_fname, bsize, dfree, dsize);
803 /* Don't have a reasonable notion of failure here */
805 do_log(SMB_VFS_OP_DISK_FREE,
806 True,
807 handle,
808 "%s",
809 smb_fname_str_do_log(handle->conn, smb_fname));
811 return result;
814 static int smb_full_audit_get_quota(struct vfs_handle_struct *handle,
815 const struct smb_filename *smb_fname,
816 enum SMB_QUOTA_TYPE qtype,
817 unid_t id,
818 SMB_DISK_QUOTA *qt)
820 int result;
822 result = SMB_VFS_NEXT_GET_QUOTA(handle, smb_fname, qtype, id, qt);
824 do_log(SMB_VFS_OP_GET_QUOTA,
825 (result >= 0),
826 handle,
827 "%s",
828 smb_fname_str_do_log(handle->conn, smb_fname));
830 return result;
833 static int smb_full_audit_set_quota(struct vfs_handle_struct *handle,
834 enum SMB_QUOTA_TYPE qtype, unid_t id,
835 SMB_DISK_QUOTA *qt)
837 int result;
839 result = SMB_VFS_NEXT_SET_QUOTA(handle, qtype, id, qt);
841 do_log(SMB_VFS_OP_SET_QUOTA, (result >= 0), handle, "");
843 return result;
846 static int smb_full_audit_get_shadow_copy_data(struct vfs_handle_struct *handle,
847 struct files_struct *fsp,
848 struct shadow_copy_data *shadow_copy_data,
849 bool labels)
851 int result;
853 result = SMB_VFS_NEXT_GET_SHADOW_COPY_DATA(handle, fsp, shadow_copy_data, labels);
855 do_log(SMB_VFS_OP_GET_SHADOW_COPY_DATA, (result >= 0), handle, "");
857 return result;
860 static int smb_full_audit_statvfs(struct vfs_handle_struct *handle,
861 const struct smb_filename *smb_fname,
862 struct vfs_statvfs_struct *statbuf)
864 int result;
866 result = SMB_VFS_NEXT_STATVFS(handle, smb_fname, statbuf);
868 do_log(SMB_VFS_OP_STATVFS, (result >= 0), handle, "");
870 return result;
873 static uint32_t smb_full_audit_fs_capabilities(struct vfs_handle_struct *handle, enum timestamp_set_resolution *p_ts_res)
875 int result;
877 result = SMB_VFS_NEXT_FS_CAPABILITIES(handle, p_ts_res);
879 do_log(SMB_VFS_OP_FS_CAPABILITIES, true, handle, "");
881 return result;
884 static NTSTATUS smb_full_audit_get_dfs_referrals(
885 struct vfs_handle_struct *handle,
886 struct dfs_GetDFSReferral *r)
888 NTSTATUS status;
890 status = SMB_VFS_NEXT_GET_DFS_REFERRALS(handle, r);
892 do_log(SMB_VFS_OP_GET_DFS_REFERRALS, NT_STATUS_IS_OK(status),
893 handle, "");
895 return status;
898 static NTSTATUS smb_full_audit_create_dfs_pathat(struct vfs_handle_struct *handle,
899 struct files_struct *dirfsp,
900 const struct smb_filename *smb_fname,
901 const struct referral *reflist,
902 size_t referral_count)
904 NTSTATUS status;
906 status = SMB_VFS_NEXT_CREATE_DFS_PATHAT(handle,
907 dirfsp,
908 smb_fname,
909 reflist,
910 referral_count);
912 do_log(SMB_VFS_OP_CREATE_DFS_PATHAT,
913 NT_STATUS_IS_OK(status),
914 handle,
915 "%s",
916 smb_fname_str_do_log(handle->conn, smb_fname));
918 return status;
921 static NTSTATUS smb_full_audit_read_dfs_pathat(struct vfs_handle_struct *handle,
922 TALLOC_CTX *mem_ctx,
923 struct files_struct *dirfsp,
924 const struct smb_filename *smb_fname,
925 struct referral **ppreflist,
926 size_t *preferral_count)
928 NTSTATUS status;
930 status = SMB_VFS_NEXT_READ_DFS_PATHAT(handle,
931 mem_ctx,
932 dirfsp,
933 smb_fname,
934 ppreflist,
935 preferral_count);
937 do_log(SMB_VFS_OP_READ_DFS_PATHAT,
938 NT_STATUS_IS_OK(status),
939 handle,
940 "%s",
941 smb_fname_str_do_log(handle->conn, smb_fname));
943 return status;
946 static NTSTATUS smb_full_audit_snap_check_path(struct vfs_handle_struct *handle,
947 TALLOC_CTX *mem_ctx,
948 const char *service_path,
949 char **base_volume)
951 NTSTATUS status;
953 status = SMB_VFS_NEXT_SNAP_CHECK_PATH(handle, mem_ctx, service_path,
954 base_volume);
955 do_log(SMB_VFS_OP_SNAP_CHECK_PATH, NT_STATUS_IS_OK(status),
956 handle, "");
958 return status;
961 static NTSTATUS smb_full_audit_snap_create(struct vfs_handle_struct *handle,
962 TALLOC_CTX *mem_ctx,
963 const char *base_volume,
964 time_t *tstamp,
965 bool rw,
966 char **base_path,
967 char **snap_path)
969 NTSTATUS status;
971 status = SMB_VFS_NEXT_SNAP_CREATE(handle, mem_ctx, base_volume, tstamp,
972 rw, base_path, snap_path);
973 do_log(SMB_VFS_OP_SNAP_CREATE, NT_STATUS_IS_OK(status), handle, "");
975 return status;
978 static NTSTATUS smb_full_audit_snap_delete(struct vfs_handle_struct *handle,
979 TALLOC_CTX *mem_ctx,
980 char *base_path,
981 char *snap_path)
983 NTSTATUS status;
985 status = SMB_VFS_NEXT_SNAP_DELETE(handle, mem_ctx, base_path,
986 snap_path);
987 do_log(SMB_VFS_OP_SNAP_DELETE, NT_STATUS_IS_OK(status), handle, "");
989 return status;
992 static DIR *smb_full_audit_opendir(vfs_handle_struct *handle,
993 const struct smb_filename *smb_fname,
994 const char *mask,
995 uint32_t attr)
997 DIR *result;
999 result = SMB_VFS_NEXT_OPENDIR(handle, smb_fname, mask, attr);
1001 do_log(SMB_VFS_OP_OPENDIR,
1002 (result != NULL),
1003 handle,
1004 "%s",
1005 smb_fname_str_do_log(handle->conn, smb_fname));
1007 return result;
1010 static DIR *smb_full_audit_fdopendir(vfs_handle_struct *handle,
1011 files_struct *fsp, const char *mask, uint32_t attr)
1013 DIR *result;
1015 result = SMB_VFS_NEXT_FDOPENDIR(handle, fsp, mask, attr);
1017 do_log(SMB_VFS_OP_FDOPENDIR, (result != NULL), handle, "%s",
1018 fsp_str_do_log(fsp));
1020 return result;
1023 static struct dirent *smb_full_audit_readdir(vfs_handle_struct *handle,
1024 DIR *dirp, SMB_STRUCT_STAT *sbuf)
1026 struct dirent *result;
1028 result = SMB_VFS_NEXT_READDIR(handle, dirp, sbuf);
1030 /* This operation has no reasonable error condition
1031 * (End of dir is also failure), so always succeed.
1033 do_log(SMB_VFS_OP_READDIR, True, handle, "");
1035 return result;
1038 static void smb_full_audit_seekdir(vfs_handle_struct *handle,
1039 DIR *dirp, long offset)
1041 SMB_VFS_NEXT_SEEKDIR(handle, dirp, offset);
1043 do_log(SMB_VFS_OP_SEEKDIR, True, handle, "");
1046 static long smb_full_audit_telldir(vfs_handle_struct *handle,
1047 DIR *dirp)
1049 long result;
1051 result = SMB_VFS_NEXT_TELLDIR(handle, dirp);
1053 do_log(SMB_VFS_OP_TELLDIR, True, handle, "");
1055 return result;
1058 static void smb_full_audit_rewinddir(vfs_handle_struct *handle,
1059 DIR *dirp)
1061 SMB_VFS_NEXT_REWINDDIR(handle, dirp);
1063 do_log(SMB_VFS_OP_REWINDDIR, True, handle, "");
1066 static int smb_full_audit_mkdirat(vfs_handle_struct *handle,
1067 struct files_struct *dirfsp,
1068 const struct smb_filename *smb_fname,
1069 mode_t mode)
1071 int result;
1073 result = SMB_VFS_NEXT_MKDIRAT(handle,
1074 dirfsp,
1075 smb_fname,
1076 mode);
1078 do_log(SMB_VFS_OP_MKDIRAT,
1079 (result >= 0),
1080 handle,
1081 "%s",
1082 smb_fname_str_do_log(handle->conn, smb_fname));
1084 return result;
1087 static int smb_full_audit_closedir(vfs_handle_struct *handle,
1088 DIR *dirp)
1090 int result;
1092 result = SMB_VFS_NEXT_CLOSEDIR(handle, dirp);
1094 do_log(SMB_VFS_OP_CLOSEDIR, (result >= 0), handle, "");
1096 return result;
1099 static int smb_full_audit_open(vfs_handle_struct *handle,
1100 struct smb_filename *smb_fname,
1101 files_struct *fsp, int flags, mode_t mode)
1103 int result;
1105 result = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
1107 do_log(SMB_VFS_OP_OPEN, (result >= 0), handle, "%s|%s",
1108 ((flags & O_WRONLY) || (flags & O_RDWR))?"w":"r",
1109 smb_fname_str_do_log(handle->conn, smb_fname));
1111 return result;
1114 static NTSTATUS smb_full_audit_create_file(vfs_handle_struct *handle,
1115 struct smb_request *req,
1116 uint16_t root_dir_fid,
1117 struct smb_filename *smb_fname,
1118 uint32_t access_mask,
1119 uint32_t share_access,
1120 uint32_t create_disposition,
1121 uint32_t create_options,
1122 uint32_t file_attributes,
1123 uint32_t oplock_request,
1124 const struct smb2_lease *lease,
1125 uint64_t allocation_size,
1126 uint32_t private_flags,
1127 struct security_descriptor *sd,
1128 struct ea_list *ea_list,
1129 files_struct **result_fsp,
1130 int *pinfo,
1131 const struct smb2_create_blobs *in_context_blobs,
1132 struct smb2_create_blobs *out_context_blobs)
1134 NTSTATUS result;
1135 const char* str_create_disposition;
1137 switch (create_disposition) {
1138 case FILE_SUPERSEDE:
1139 str_create_disposition = "supersede";
1140 break;
1141 case FILE_OVERWRITE_IF:
1142 str_create_disposition = "overwrite_if";
1143 break;
1144 case FILE_OPEN:
1145 str_create_disposition = "open";
1146 break;
1147 case FILE_OVERWRITE:
1148 str_create_disposition = "overwrite";
1149 break;
1150 case FILE_CREATE:
1151 str_create_disposition = "create";
1152 break;
1153 case FILE_OPEN_IF:
1154 str_create_disposition = "open_if";
1155 break;
1156 default:
1157 str_create_disposition = "unknown";
1160 result = SMB_VFS_NEXT_CREATE_FILE(
1161 handle, /* handle */
1162 req, /* req */
1163 root_dir_fid, /* root_dir_fid */
1164 smb_fname, /* fname */
1165 access_mask, /* access_mask */
1166 share_access, /* share_access */
1167 create_disposition, /* create_disposition*/
1168 create_options, /* create_options */
1169 file_attributes, /* file_attributes */
1170 oplock_request, /* oplock_request */
1171 lease, /* lease */
1172 allocation_size, /* allocation_size */
1173 private_flags,
1174 sd, /* sd */
1175 ea_list, /* ea_list */
1176 result_fsp, /* result */
1177 pinfo, /* pinfo */
1178 in_context_blobs, out_context_blobs); /* create context */
1180 do_log(SMB_VFS_OP_CREATE_FILE, (NT_STATUS_IS_OK(result)), handle,
1181 "0x%x|%s|%s|%s", access_mask,
1182 create_options & FILE_DIRECTORY_FILE ? "dir" : "file",
1183 str_create_disposition,
1184 smb_fname_str_do_log(handle->conn, smb_fname));
1186 return result;
1189 static int smb_full_audit_close(vfs_handle_struct *handle, files_struct *fsp)
1191 int result;
1193 result = SMB_VFS_NEXT_CLOSE(handle, fsp);
1195 do_log(SMB_VFS_OP_CLOSE, (result >= 0), handle, "%s",
1196 fsp_str_do_log(fsp));
1198 return result;
1201 static ssize_t smb_full_audit_pread(vfs_handle_struct *handle, files_struct *fsp,
1202 void *data, size_t n, off_t offset)
1204 ssize_t result;
1206 result = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
1208 do_log(SMB_VFS_OP_PREAD, (result >= 0), handle, "%s",
1209 fsp_str_do_log(fsp));
1211 return result;
1214 struct smb_full_audit_pread_state {
1215 vfs_handle_struct *handle;
1216 files_struct *fsp;
1217 ssize_t ret;
1218 struct vfs_aio_state vfs_aio_state;
1221 static void smb_full_audit_pread_done(struct tevent_req *subreq);
1223 static struct tevent_req *smb_full_audit_pread_send(
1224 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1225 struct tevent_context *ev, struct files_struct *fsp,
1226 void *data, size_t n, off_t offset)
1228 struct tevent_req *req, *subreq;
1229 struct smb_full_audit_pread_state *state;
1231 req = tevent_req_create(mem_ctx, &state,
1232 struct smb_full_audit_pread_state);
1233 if (req == NULL) {
1234 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
1235 fsp_str_do_log(fsp));
1236 return NULL;
1238 state->handle = handle;
1239 state->fsp = fsp;
1241 subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
1242 n, offset);
1243 if (tevent_req_nomem(subreq, req)) {
1244 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
1245 fsp_str_do_log(fsp));
1246 return tevent_req_post(req, ev);
1248 tevent_req_set_callback(subreq, smb_full_audit_pread_done, req);
1250 do_log(SMB_VFS_OP_PREAD_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1251 return req;
1254 static void smb_full_audit_pread_done(struct tevent_req *subreq)
1256 struct tevent_req *req = tevent_req_callback_data(
1257 subreq, struct tevent_req);
1258 struct smb_full_audit_pread_state *state = tevent_req_data(
1259 req, struct smb_full_audit_pread_state);
1261 state->ret = SMB_VFS_PREAD_RECV(subreq, &state->vfs_aio_state);
1262 TALLOC_FREE(subreq);
1263 tevent_req_done(req);
1266 static ssize_t smb_full_audit_pread_recv(struct tevent_req *req,
1267 struct vfs_aio_state *vfs_aio_state)
1269 struct smb_full_audit_pread_state *state = tevent_req_data(
1270 req, struct smb_full_audit_pread_state);
1272 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1273 do_log(SMB_VFS_OP_PREAD_RECV, false, state->handle, "%s",
1274 fsp_str_do_log(state->fsp));
1275 return -1;
1278 do_log(SMB_VFS_OP_PREAD_RECV, (state->ret >= 0), state->handle, "%s",
1279 fsp_str_do_log(state->fsp));
1281 *vfs_aio_state = state->vfs_aio_state;
1282 return state->ret;
1285 static ssize_t smb_full_audit_pwrite(vfs_handle_struct *handle, files_struct *fsp,
1286 const void *data, size_t n,
1287 off_t offset)
1289 ssize_t result;
1291 result = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
1293 do_log(SMB_VFS_OP_PWRITE, (result >= 0), handle, "%s",
1294 fsp_str_do_log(fsp));
1296 return result;
1299 struct smb_full_audit_pwrite_state {
1300 vfs_handle_struct *handle;
1301 files_struct *fsp;
1302 ssize_t ret;
1303 struct vfs_aio_state vfs_aio_state;
1306 static void smb_full_audit_pwrite_done(struct tevent_req *subreq);
1308 static struct tevent_req *smb_full_audit_pwrite_send(
1309 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1310 struct tevent_context *ev, struct files_struct *fsp,
1311 const void *data, size_t n, off_t offset)
1313 struct tevent_req *req, *subreq;
1314 struct smb_full_audit_pwrite_state *state;
1316 req = tevent_req_create(mem_ctx, &state,
1317 struct smb_full_audit_pwrite_state);
1318 if (req == NULL) {
1319 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1320 fsp_str_do_log(fsp));
1321 return NULL;
1323 state->handle = handle;
1324 state->fsp = fsp;
1326 subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
1327 n, offset);
1328 if (tevent_req_nomem(subreq, req)) {
1329 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1330 fsp_str_do_log(fsp));
1331 return tevent_req_post(req, ev);
1333 tevent_req_set_callback(subreq, smb_full_audit_pwrite_done, req);
1335 do_log(SMB_VFS_OP_PWRITE_SEND, true, handle, "%s",
1336 fsp_str_do_log(fsp));
1337 return req;
1340 static void smb_full_audit_pwrite_done(struct tevent_req *subreq)
1342 struct tevent_req *req = tevent_req_callback_data(
1343 subreq, struct tevent_req);
1344 struct smb_full_audit_pwrite_state *state = tevent_req_data(
1345 req, struct smb_full_audit_pwrite_state);
1347 state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->vfs_aio_state);
1348 TALLOC_FREE(subreq);
1349 tevent_req_done(req);
1352 static ssize_t smb_full_audit_pwrite_recv(struct tevent_req *req,
1353 struct vfs_aio_state *vfs_aio_state)
1355 struct smb_full_audit_pwrite_state *state = tevent_req_data(
1356 req, struct smb_full_audit_pwrite_state);
1358 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1359 do_log(SMB_VFS_OP_PWRITE_RECV, false, state->handle, "%s",
1360 fsp_str_do_log(state->fsp));
1361 return -1;
1364 do_log(SMB_VFS_OP_PWRITE_RECV, (state->ret >= 0), state->handle, "%s",
1365 fsp_str_do_log(state->fsp));
1367 *vfs_aio_state = state->vfs_aio_state;
1368 return state->ret;
1371 static off_t smb_full_audit_lseek(vfs_handle_struct *handle, files_struct *fsp,
1372 off_t offset, int whence)
1374 ssize_t result;
1376 result = SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence);
1378 do_log(SMB_VFS_OP_LSEEK, (result != (ssize_t)-1), handle,
1379 "%s", fsp_str_do_log(fsp));
1381 return result;
1384 static ssize_t smb_full_audit_sendfile(vfs_handle_struct *handle, int tofd,
1385 files_struct *fromfsp,
1386 const DATA_BLOB *hdr, off_t offset,
1387 size_t n)
1389 ssize_t result;
1391 result = SMB_VFS_NEXT_SENDFILE(handle, tofd, fromfsp, hdr, offset, n);
1393 do_log(SMB_VFS_OP_SENDFILE, (result >= 0), handle,
1394 "%s", fsp_str_do_log(fromfsp));
1396 return result;
1399 static ssize_t smb_full_audit_recvfile(vfs_handle_struct *handle, int fromfd,
1400 files_struct *tofsp,
1401 off_t offset,
1402 size_t n)
1404 ssize_t result;
1406 result = SMB_VFS_NEXT_RECVFILE(handle, fromfd, tofsp, offset, n);
1408 do_log(SMB_VFS_OP_RECVFILE, (result >= 0), handle,
1409 "%s", fsp_str_do_log(tofsp));
1411 return result;
1414 static int smb_full_audit_renameat(vfs_handle_struct *handle,
1415 files_struct *srcfsp,
1416 const struct smb_filename *smb_fname_src,
1417 files_struct *dstfsp,
1418 const struct smb_filename *smb_fname_dst)
1420 int result;
1422 result = SMB_VFS_NEXT_RENAMEAT(handle,
1423 srcfsp,
1424 smb_fname_src,
1425 dstfsp,
1426 smb_fname_dst);
1428 do_log(SMB_VFS_OP_RENAMEAT, (result >= 0), handle, "%s|%s",
1429 smb_fname_str_do_log(handle->conn, smb_fname_src),
1430 smb_fname_str_do_log(handle->conn, smb_fname_dst));
1432 return result;
1435 struct smb_full_audit_fsync_state {
1436 vfs_handle_struct *handle;
1437 files_struct *fsp;
1438 int ret;
1439 struct vfs_aio_state vfs_aio_state;
1442 static void smb_full_audit_fsync_done(struct tevent_req *subreq);
1444 static struct tevent_req *smb_full_audit_fsync_send(
1445 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1446 struct tevent_context *ev, struct files_struct *fsp)
1448 struct tevent_req *req, *subreq;
1449 struct smb_full_audit_fsync_state *state;
1451 req = tevent_req_create(mem_ctx, &state,
1452 struct smb_full_audit_fsync_state);
1453 if (req == NULL) {
1454 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1455 fsp_str_do_log(fsp));
1456 return NULL;
1458 state->handle = handle;
1459 state->fsp = fsp;
1461 subreq = SMB_VFS_NEXT_FSYNC_SEND(state, ev, handle, fsp);
1462 if (tevent_req_nomem(subreq, req)) {
1463 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1464 fsp_str_do_log(fsp));
1465 return tevent_req_post(req, ev);
1467 tevent_req_set_callback(subreq, smb_full_audit_fsync_done, req);
1469 do_log(SMB_VFS_OP_FSYNC_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1470 return req;
1473 static void smb_full_audit_fsync_done(struct tevent_req *subreq)
1475 struct tevent_req *req = tevent_req_callback_data(
1476 subreq, struct tevent_req);
1477 struct smb_full_audit_fsync_state *state = tevent_req_data(
1478 req, struct smb_full_audit_fsync_state);
1480 state->ret = SMB_VFS_FSYNC_RECV(subreq, &state->vfs_aio_state);
1481 TALLOC_FREE(subreq);
1482 tevent_req_done(req);
1485 static int smb_full_audit_fsync_recv(struct tevent_req *req,
1486 struct vfs_aio_state *vfs_aio_state)
1488 struct smb_full_audit_fsync_state *state = tevent_req_data(
1489 req, struct smb_full_audit_fsync_state);
1491 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1492 do_log(SMB_VFS_OP_FSYNC_RECV, false, state->handle, "%s",
1493 fsp_str_do_log(state->fsp));
1494 return -1;
1497 do_log(SMB_VFS_OP_FSYNC_RECV, (state->ret >= 0), state->handle, "%s",
1498 fsp_str_do_log(state->fsp));
1500 *vfs_aio_state = state->vfs_aio_state;
1501 return state->ret;
1504 static int smb_full_audit_stat(vfs_handle_struct *handle,
1505 struct smb_filename *smb_fname)
1507 int result;
1509 result = SMB_VFS_NEXT_STAT(handle, smb_fname);
1511 do_log(SMB_VFS_OP_STAT, (result >= 0), handle, "%s",
1512 smb_fname_str_do_log(handle->conn, smb_fname));
1514 return result;
1517 static int smb_full_audit_fstat(vfs_handle_struct *handle, files_struct *fsp,
1518 SMB_STRUCT_STAT *sbuf)
1520 int result;
1522 result = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1524 do_log(SMB_VFS_OP_FSTAT, (result >= 0), handle, "%s",
1525 fsp_str_do_log(fsp));
1527 return result;
1530 static int smb_full_audit_lstat(vfs_handle_struct *handle,
1531 struct smb_filename *smb_fname)
1533 int result;
1535 result = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
1537 do_log(SMB_VFS_OP_LSTAT, (result >= 0), handle, "%s",
1538 smb_fname_str_do_log(handle->conn, smb_fname));
1540 return result;
1543 static uint64_t smb_full_audit_get_alloc_size(vfs_handle_struct *handle,
1544 files_struct *fsp, const SMB_STRUCT_STAT *sbuf)
1546 uint64_t result;
1548 result = SMB_VFS_NEXT_GET_ALLOC_SIZE(handle, fsp, sbuf);
1550 do_log(SMB_VFS_OP_GET_ALLOC_SIZE, (result != (uint64_t)-1), handle,
1551 "%llu", (unsigned long long)result);
1553 return result;
1556 static int smb_full_audit_unlinkat(vfs_handle_struct *handle,
1557 struct files_struct *dirfsp,
1558 const struct smb_filename *smb_fname,
1559 int flags)
1561 int result;
1563 result = SMB_VFS_NEXT_UNLINKAT(handle,
1564 dirfsp,
1565 smb_fname,
1566 flags);
1568 do_log(SMB_VFS_OP_UNLINKAT, (result >= 0), handle, "%s",
1569 smb_fname_str_do_log(handle->conn, smb_fname));
1571 return result;
1574 static int smb_full_audit_chmod(vfs_handle_struct *handle,
1575 const struct smb_filename *smb_fname,
1576 mode_t mode)
1578 int result;
1580 result = SMB_VFS_NEXT_CHMOD(handle, smb_fname, mode);
1582 do_log(SMB_VFS_OP_CHMOD,
1583 (result >= 0),
1584 handle,
1585 "%s|%o",
1586 smb_fname_str_do_log(handle->conn, smb_fname),
1587 mode);
1589 return result;
1592 static int smb_full_audit_fchmod(vfs_handle_struct *handle, files_struct *fsp,
1593 mode_t mode)
1595 int result;
1597 result = SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1599 do_log(SMB_VFS_OP_FCHMOD, (result >= 0), handle,
1600 "%s|%o", fsp_str_do_log(fsp), mode);
1602 return result;
1605 static int smb_full_audit_fchown(vfs_handle_struct *handle, files_struct *fsp,
1606 uid_t uid, gid_t gid)
1608 int result;
1610 result = SMB_VFS_NEXT_FCHOWN(handle, fsp, uid, gid);
1612 do_log(SMB_VFS_OP_FCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1613 fsp_str_do_log(fsp), (long int)uid, (long int)gid);
1615 return result;
1618 static int smb_full_audit_lchown(vfs_handle_struct *handle,
1619 const struct smb_filename *smb_fname,
1620 uid_t uid,
1621 gid_t gid)
1623 int result;
1625 result = SMB_VFS_NEXT_LCHOWN(handle, smb_fname, uid, gid);
1627 do_log(SMB_VFS_OP_LCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1628 smb_fname->base_name, (long int)uid, (long int)gid);
1630 return result;
1633 static int smb_full_audit_chdir(vfs_handle_struct *handle,
1634 const struct smb_filename *smb_fname)
1636 int result;
1638 result = SMB_VFS_NEXT_CHDIR(handle, smb_fname);
1640 do_log(SMB_VFS_OP_CHDIR,
1641 (result >= 0),
1642 handle,
1643 "chdir|%s",
1644 smb_fname_str_do_log(handle->conn, smb_fname));
1646 return result;
1649 static struct smb_filename *smb_full_audit_getwd(vfs_handle_struct *handle,
1650 TALLOC_CTX *ctx)
1652 struct smb_filename *result;
1654 result = SMB_VFS_NEXT_GETWD(handle, ctx);
1656 do_log(SMB_VFS_OP_GETWD, (result != NULL), handle, "%s",
1657 result == NULL? "" : result->base_name);
1659 return result;
1662 static int smb_full_audit_ntimes(vfs_handle_struct *handle,
1663 const struct smb_filename *smb_fname,
1664 struct smb_file_time *ft)
1666 int result;
1667 time_t create_time = convert_timespec_to_time_t(ft->create_time);
1668 time_t atime = convert_timespec_to_time_t(ft->atime);
1669 time_t mtime = convert_timespec_to_time_t(ft->mtime);
1670 time_t ctime = convert_timespec_to_time_t(ft->ctime);
1671 const char *create_time_str = "";
1672 const char *atime_str = "";
1673 const char *mtime_str = "";
1674 const char *ctime_str = "";
1675 TALLOC_CTX *frame = talloc_stackframe();
1677 result = SMB_VFS_NEXT_NTIMES(handle, smb_fname, ft);
1679 if (create_time > 0) {
1680 create_time_str = timestring(frame, create_time);
1682 if (atime > 0) {
1683 atime_str = timestring(frame, atime);
1685 if (mtime > 0) {
1686 mtime_str = timestring(frame, mtime);
1688 if (ctime > 0) {
1689 ctime_str = timestring(frame, ctime);
1692 do_log(SMB_VFS_OP_NTIMES,
1693 (result >= 0),
1694 handle,
1695 "%s|%s|%s|%s|%s",
1696 smb_fname_str_do_log(handle->conn, smb_fname),
1697 create_time_str,
1698 atime_str,
1699 mtime_str,
1700 ctime_str);
1702 TALLOC_FREE(frame);
1704 return result;
1707 static int smb_full_audit_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
1708 off_t len)
1710 int result;
1712 result = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1714 do_log(SMB_VFS_OP_FTRUNCATE, (result >= 0), handle,
1715 "%s", fsp_str_do_log(fsp));
1717 return result;
1720 static int smb_full_audit_fallocate(vfs_handle_struct *handle, files_struct *fsp,
1721 uint32_t mode,
1722 off_t offset,
1723 off_t len)
1725 int result;
1727 result = SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
1729 do_log(SMB_VFS_OP_FALLOCATE, (result >= 0), handle,
1730 "%s", fsp_str_do_log(fsp));
1732 return result;
1735 static bool smb_full_audit_lock(vfs_handle_struct *handle, files_struct *fsp,
1736 int op, off_t offset, off_t count, int type)
1738 bool result;
1740 result = SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type);
1742 do_log(SMB_VFS_OP_LOCK, result, handle, "%s", fsp_str_do_log(fsp));
1744 return result;
1747 static int smb_full_audit_kernel_flock(struct vfs_handle_struct *handle,
1748 struct files_struct *fsp,
1749 uint32_t share_access,
1750 uint32_t access_mask)
1752 int result;
1754 result = SMB_VFS_NEXT_KERNEL_FLOCK(handle,
1755 fsp,
1756 share_access,
1757 access_mask);
1759 do_log(SMB_VFS_OP_KERNEL_FLOCK, (result >= 0), handle, "%s",
1760 fsp_str_do_log(fsp));
1762 return result;
1765 static int smb_full_audit_fcntl(struct vfs_handle_struct *handle,
1766 struct files_struct *fsp,
1767 int cmd, va_list cmd_arg)
1769 void *arg;
1770 va_list dup_cmd_arg;
1771 int result;
1773 va_copy(dup_cmd_arg, cmd_arg);
1774 arg = va_arg(dup_cmd_arg, void *);
1775 result = SMB_VFS_NEXT_FCNTL(handle, fsp, cmd, arg);
1776 va_end(dup_cmd_arg);
1778 do_log(SMB_VFS_OP_FCNTL, (result >= 0), handle, "%s",
1779 fsp_str_do_log(fsp));
1781 return result;
1784 static int smb_full_audit_linux_setlease(vfs_handle_struct *handle, files_struct *fsp,
1785 int leasetype)
1787 int result;
1789 result = SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
1791 do_log(SMB_VFS_OP_LINUX_SETLEASE, (result >= 0), handle, "%s",
1792 fsp_str_do_log(fsp));
1794 return result;
1797 static bool smb_full_audit_getlock(vfs_handle_struct *handle, files_struct *fsp,
1798 off_t *poffset, off_t *pcount, int *ptype, pid_t *ppid)
1800 bool result;
1802 result = SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype, ppid);
1804 do_log(SMB_VFS_OP_GETLOCK, result, handle, "%s", fsp_str_do_log(fsp));
1806 return result;
1809 static int smb_full_audit_symlinkat(vfs_handle_struct *handle,
1810 const char *link_contents,
1811 struct files_struct *dirfsp,
1812 const struct smb_filename *new_smb_fname)
1814 int result;
1816 result = SMB_VFS_NEXT_SYMLINKAT(handle,
1817 link_contents,
1818 dirfsp,
1819 new_smb_fname);
1821 do_log(SMB_VFS_OP_SYMLINKAT,
1822 (result >= 0),
1823 handle,
1824 "%s|%s",
1825 link_contents,
1826 smb_fname_str_do_log(handle->conn, new_smb_fname));
1828 return result;
1831 static int smb_full_audit_readlinkat(vfs_handle_struct *handle,
1832 files_struct *dirfsp,
1833 const struct smb_filename *smb_fname,
1834 char *buf,
1835 size_t bufsiz)
1837 int result;
1839 result = SMB_VFS_NEXT_READLINKAT(handle,
1840 dirfsp,
1841 smb_fname,
1842 buf,
1843 bufsiz);
1845 do_log(SMB_VFS_OP_READLINKAT,
1846 (result >= 0),
1847 handle,
1848 "%s",
1849 smb_fname_str_do_log(handle->conn, smb_fname));
1851 return result;
1854 static int smb_full_audit_linkat(vfs_handle_struct *handle,
1855 files_struct *srcfsp,
1856 const struct smb_filename *old_smb_fname,
1857 files_struct *dstfsp,
1858 const struct smb_filename *new_smb_fname,
1859 int flags)
1861 int result;
1863 result = SMB_VFS_NEXT_LINKAT(handle,
1864 srcfsp,
1865 old_smb_fname,
1866 dstfsp,
1867 new_smb_fname,
1868 flags);
1870 do_log(SMB_VFS_OP_LINKAT,
1871 (result >= 0),
1872 handle,
1873 "%s|%s",
1874 smb_fname_str_do_log(handle->conn, old_smb_fname),
1875 smb_fname_str_do_log(handle->conn, new_smb_fname));
1877 return result;
1880 static int smb_full_audit_mknodat(vfs_handle_struct *handle,
1881 files_struct *dirfsp,
1882 const struct smb_filename *smb_fname,
1883 mode_t mode,
1884 SMB_DEV_T dev)
1886 int result;
1888 result = SMB_VFS_NEXT_MKNODAT(handle,
1889 dirfsp,
1890 smb_fname,
1891 mode,
1892 dev);
1894 do_log(SMB_VFS_OP_MKNODAT,
1895 (result >= 0),
1896 handle,
1897 "%s",
1898 smb_fname_str_do_log(handle->conn, smb_fname));
1900 return result;
1903 static struct smb_filename *smb_full_audit_realpath(vfs_handle_struct *handle,
1904 TALLOC_CTX *ctx,
1905 const struct smb_filename *smb_fname)
1907 struct smb_filename *result_fname = NULL;
1909 result_fname = SMB_VFS_NEXT_REALPATH(handle, ctx, smb_fname);
1911 do_log(SMB_VFS_OP_REALPATH,
1912 (result_fname != NULL),
1913 handle,
1914 "%s",
1915 smb_fname_str_do_log(handle->conn, smb_fname));
1917 return result_fname;
1920 static int smb_full_audit_chflags(vfs_handle_struct *handle,
1921 const struct smb_filename *smb_fname,
1922 unsigned int flags)
1924 int result;
1926 result = SMB_VFS_NEXT_CHFLAGS(handle, smb_fname, flags);
1928 do_log(SMB_VFS_OP_CHFLAGS,
1929 (result != 0),
1930 handle,
1931 "%s",
1932 smb_fname_str_do_log(handle->conn, smb_fname));
1934 return result;
1937 static struct file_id smb_full_audit_file_id_create(struct vfs_handle_struct *handle,
1938 const SMB_STRUCT_STAT *sbuf)
1940 struct file_id id_zero = { 0 };
1941 struct file_id result;
1942 struct file_id_buf idbuf;
1944 result = SMB_VFS_NEXT_FILE_ID_CREATE(handle, sbuf);
1946 do_log(SMB_VFS_OP_FILE_ID_CREATE,
1947 !file_id_equal(&id_zero, &result),
1948 handle,
1949 "%s",
1950 file_id_str_buf(result, &idbuf));
1952 return result;
1955 static uint64_t smb_full_audit_fs_file_id(struct vfs_handle_struct *handle,
1956 const SMB_STRUCT_STAT *sbuf)
1958 uint64_t result;
1960 result = SMB_VFS_NEXT_FS_FILE_ID(handle, sbuf);
1962 do_log(SMB_VFS_OP_FS_FILE_ID,
1963 result != 0,
1964 handle, "%" PRIu64, result);
1966 return result;
1969 static NTSTATUS smb_full_audit_streaminfo(vfs_handle_struct *handle,
1970 struct files_struct *fsp,
1971 const struct smb_filename *smb_fname,
1972 TALLOC_CTX *mem_ctx,
1973 unsigned int *pnum_streams,
1974 struct stream_struct **pstreams)
1976 NTSTATUS result;
1978 result = SMB_VFS_NEXT_STREAMINFO(handle, fsp, smb_fname, mem_ctx,
1979 pnum_streams, pstreams);
1981 do_log(SMB_VFS_OP_STREAMINFO,
1982 NT_STATUS_IS_OK(result),
1983 handle,
1984 "%s",
1985 smb_fname_str_do_log(handle->conn, smb_fname));
1987 return result;
1990 static int smb_full_audit_get_real_filename(struct vfs_handle_struct *handle,
1991 const char *path,
1992 const char *name,
1993 TALLOC_CTX *mem_ctx,
1994 char **found_name)
1996 int result;
1998 result = SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name, mem_ctx,
1999 found_name);
2001 do_log(SMB_VFS_OP_GET_REAL_FILENAME, (result == 0), handle,
2002 "%s/%s->%s", path, name, (result == 0) ? *found_name : "");
2004 return result;
2007 static const char *smb_full_audit_connectpath(vfs_handle_struct *handle,
2008 const struct smb_filename *smb_fname)
2010 const char *result;
2012 result = SMB_VFS_NEXT_CONNECTPATH(handle, smb_fname);
2014 do_log(SMB_VFS_OP_CONNECTPATH,
2015 result != NULL,
2016 handle,
2017 "%s",
2018 smb_fname_str_do_log(handle->conn, smb_fname));
2020 return result;
2023 static NTSTATUS smb_full_audit_brl_lock_windows(struct vfs_handle_struct *handle,
2024 struct byte_range_lock *br_lck,
2025 struct lock_struct *plock)
2027 NTSTATUS result;
2029 result = SMB_VFS_NEXT_BRL_LOCK_WINDOWS(handle, br_lck, plock);
2031 do_log(SMB_VFS_OP_BRL_LOCK_WINDOWS, NT_STATUS_IS_OK(result), handle,
2032 "%s:%llu-%llu. type=%d.",
2033 fsp_str_do_log(brl_fsp(br_lck)),
2034 (unsigned long long)plock->start,
2035 (unsigned long long)plock->size,
2036 plock->lock_type);
2038 return result;
2041 static bool smb_full_audit_brl_unlock_windows(struct vfs_handle_struct *handle,
2042 struct byte_range_lock *br_lck,
2043 const struct lock_struct *plock)
2045 bool result;
2047 result = SMB_VFS_NEXT_BRL_UNLOCK_WINDOWS(handle, br_lck, plock);
2049 do_log(SMB_VFS_OP_BRL_UNLOCK_WINDOWS, (result == 0), handle,
2050 "%s:%llu-%llu:%d", fsp_str_do_log(brl_fsp(br_lck)),
2051 (unsigned long long)plock->start,
2052 (unsigned long long)plock->size,
2053 plock->lock_type);
2055 return result;
2058 static bool smb_full_audit_strict_lock_check(struct vfs_handle_struct *handle,
2059 struct files_struct *fsp,
2060 struct lock_struct *plock)
2062 bool result;
2064 result = SMB_VFS_NEXT_STRICT_LOCK_CHECK(handle, fsp, plock);
2066 do_log(SMB_VFS_OP_STRICT_LOCK_CHECK, result, handle,
2067 "%s:%llu-%llu:%d", fsp_str_do_log(fsp),
2068 (unsigned long long)plock->start,
2069 (unsigned long long)plock->size,
2070 plock->lock_type);
2072 return result;
2075 static NTSTATUS smb_full_audit_translate_name(struct vfs_handle_struct *handle,
2076 const char *name,
2077 enum vfs_translate_direction direction,
2078 TALLOC_CTX *mem_ctx,
2079 char **mapped_name)
2081 NTSTATUS result;
2083 result = SMB_VFS_NEXT_TRANSLATE_NAME(handle, name, direction, mem_ctx,
2084 mapped_name);
2086 do_log(SMB_VFS_OP_TRANSLATE_NAME, NT_STATUS_IS_OK(result), handle, "");
2088 return result;
2091 static NTSTATUS smb_full_audit_fsctl(struct vfs_handle_struct *handle,
2092 struct files_struct *fsp,
2093 TALLOC_CTX *ctx,
2094 uint32_t function,
2095 uint16_t req_flags,
2096 const uint8_t *_in_data,
2097 uint32_t in_len,
2098 uint8_t **_out_data,
2099 uint32_t max_out_len,
2100 uint32_t *out_len)
2102 NTSTATUS result;
2104 result = SMB_VFS_NEXT_FSCTL(handle,
2105 fsp,
2106 ctx,
2107 function,
2108 req_flags,
2109 _in_data,
2110 in_len,
2111 _out_data,
2112 max_out_len,
2113 out_len);
2115 do_log(SMB_VFS_OP_FSCTL, NT_STATUS_IS_OK(result), handle, "");
2117 return result;
2120 static struct tevent_req *smb_full_audit_offload_read_send(
2121 TALLOC_CTX *mem_ctx,
2122 struct tevent_context *ev,
2123 struct vfs_handle_struct *handle,
2124 struct files_struct *fsp,
2125 uint32_t fsctl,
2126 uint32_t ttl,
2127 off_t offset,
2128 size_t to_copy)
2130 struct tevent_req *req = NULL;
2132 req = SMB_VFS_NEXT_OFFLOAD_READ_SEND(mem_ctx, ev, handle, fsp,
2133 fsctl, ttl, offset, to_copy);
2135 do_log(SMB_VFS_OP_OFFLOAD_READ_SEND, req, handle, "");
2137 return req;
2140 static NTSTATUS smb_full_audit_offload_read_recv(
2141 struct tevent_req *req,
2142 struct vfs_handle_struct *handle,
2143 TALLOC_CTX *mem_ctx,
2144 DATA_BLOB *_token_blob)
2146 NTSTATUS status;
2148 status = SMB_VFS_NEXT_OFFLOAD_READ_RECV(req, handle, mem_ctx,
2149 _token_blob);
2151 do_log(SMB_VFS_OP_OFFLOAD_READ_RECV, NT_STATUS_IS_OK(status), handle, "");
2153 return status;
2156 static struct tevent_req *smb_full_audit_offload_write_send(struct vfs_handle_struct *handle,
2157 TALLOC_CTX *mem_ctx,
2158 struct tevent_context *ev,
2159 uint32_t fsctl,
2160 DATA_BLOB *token,
2161 off_t transfer_offset,
2162 struct files_struct *dest_fsp,
2163 off_t dest_off,
2164 off_t num)
2166 struct tevent_req *req;
2168 req = SMB_VFS_NEXT_OFFLOAD_WRITE_SEND(handle, mem_ctx, ev,
2169 fsctl, token, transfer_offset,
2170 dest_fsp, dest_off, num);
2172 do_log(SMB_VFS_OP_OFFLOAD_WRITE_SEND, req, handle, "");
2174 return req;
2177 static NTSTATUS smb_full_audit_offload_write_recv(struct vfs_handle_struct *handle,
2178 struct tevent_req *req,
2179 off_t *copied)
2181 NTSTATUS result;
2183 result = SMB_VFS_NEXT_OFFLOAD_WRITE_RECV(handle, req, copied);
2185 do_log(SMB_VFS_OP_OFFLOAD_WRITE_RECV, NT_STATUS_IS_OK(result), handle, "");
2187 return result;
2190 static NTSTATUS smb_full_audit_get_compression(vfs_handle_struct *handle,
2191 TALLOC_CTX *mem_ctx,
2192 struct files_struct *fsp,
2193 struct smb_filename *smb_fname,
2194 uint16_t *_compression_fmt)
2196 NTSTATUS result;
2198 result = SMB_VFS_NEXT_GET_COMPRESSION(handle, mem_ctx, fsp, smb_fname,
2199 _compression_fmt);
2201 do_log(SMB_VFS_OP_GET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
2202 "%s",
2203 (fsp ? fsp_str_do_log(fsp) :
2204 smb_fname_str_do_log(handle->conn, smb_fname)));
2206 return result;
2209 static NTSTATUS smb_full_audit_set_compression(vfs_handle_struct *handle,
2210 TALLOC_CTX *mem_ctx,
2211 struct files_struct *fsp,
2212 uint16_t compression_fmt)
2214 NTSTATUS result;
2216 result = SMB_VFS_NEXT_SET_COMPRESSION(handle, mem_ctx, fsp,
2217 compression_fmt);
2219 do_log(SMB_VFS_OP_SET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
2220 "%s", fsp_str_do_log(fsp));
2222 return result;
2225 static NTSTATUS smb_full_audit_readdir_attr(struct vfs_handle_struct *handle,
2226 const struct smb_filename *fname,
2227 TALLOC_CTX *mem_ctx,
2228 struct readdir_attr_data **pattr_data)
2230 NTSTATUS status;
2232 status = SMB_VFS_NEXT_READDIR_ATTR(handle, fname, mem_ctx, pattr_data);
2234 do_log(SMB_VFS_OP_READDIR_ATTR, NT_STATUS_IS_OK(status), handle, "%s",
2235 smb_fname_str_do_log(handle->conn, fname));
2237 return status;
2240 static NTSTATUS smb_full_audit_get_dos_attributes(
2241 struct vfs_handle_struct *handle,
2242 struct smb_filename *smb_fname,
2243 uint32_t *dosmode)
2245 NTSTATUS status;
2247 status = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES(handle,
2248 smb_fname,
2249 dosmode);
2251 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES,
2252 NT_STATUS_IS_OK(status),
2253 handle,
2254 "%s",
2255 smb_fname_str_do_log(handle->conn, smb_fname));
2257 return status;
2260 struct smb_full_audit_get_dos_attributes_state {
2261 struct vfs_aio_state aio_state;
2262 vfs_handle_struct *handle;
2263 files_struct *dir_fsp;
2264 const struct smb_filename *smb_fname;
2265 uint32_t dosmode;
2268 static void smb_full_audit_get_dos_attributes_done(struct tevent_req *subreq);
2270 static struct tevent_req *smb_full_audit_get_dos_attributes_send(
2271 TALLOC_CTX *mem_ctx,
2272 struct tevent_context *ev,
2273 struct vfs_handle_struct *handle,
2274 files_struct *dir_fsp,
2275 struct smb_filename *smb_fname)
2277 struct tevent_req *req = NULL;
2278 struct smb_full_audit_get_dos_attributes_state *state = NULL;
2279 struct tevent_req *subreq = NULL;
2281 req = tevent_req_create(mem_ctx, &state,
2282 struct smb_full_audit_get_dos_attributes_state);
2283 if (req == NULL) {
2284 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2285 false,
2286 handle,
2287 "%s/%s",
2288 fsp_str_do_log(dir_fsp),
2289 smb_fname->base_name);
2290 return NULL;
2292 *state = (struct smb_full_audit_get_dos_attributes_state) {
2293 .handle = handle,
2294 .dir_fsp = dir_fsp,
2295 .smb_fname = smb_fname,
2298 subreq = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES_SEND(mem_ctx,
2300 handle,
2301 dir_fsp,
2302 smb_fname);
2303 if (tevent_req_nomem(subreq, req)) {
2304 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2305 false,
2306 handle,
2307 "%s/%s",
2308 fsp_str_do_log(dir_fsp),
2309 smb_fname->base_name);
2310 return tevent_req_post(req, ev);
2312 tevent_req_set_callback(subreq,
2313 smb_full_audit_get_dos_attributes_done,
2314 req);
2316 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2317 true,
2318 handle,
2319 "%s/%s",
2320 fsp_str_do_log(dir_fsp),
2321 smb_fname->base_name);
2323 return req;
2326 static void smb_full_audit_get_dos_attributes_done(struct tevent_req *subreq)
2328 struct tevent_req *req =
2329 tevent_req_callback_data(subreq,
2330 struct tevent_req);
2331 struct smb_full_audit_get_dos_attributes_state *state =
2332 tevent_req_data(req,
2333 struct smb_full_audit_get_dos_attributes_state);
2334 NTSTATUS status;
2336 status = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES_RECV(subreq,
2337 &state->aio_state,
2338 &state->dosmode);
2339 TALLOC_FREE(subreq);
2340 if (tevent_req_nterror(req, status)) {
2341 return;
2344 tevent_req_done(req);
2345 return;
2348 static NTSTATUS smb_full_audit_get_dos_attributes_recv(struct tevent_req *req,
2349 struct vfs_aio_state *aio_state,
2350 uint32_t *dosmode)
2352 struct smb_full_audit_get_dos_attributes_state *state =
2353 tevent_req_data(req,
2354 struct smb_full_audit_get_dos_attributes_state);
2355 NTSTATUS status;
2357 if (tevent_req_is_nterror(req, &status)) {
2358 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV,
2359 false,
2360 state->handle,
2361 "%s/%s",
2362 fsp_str_do_log(state->dir_fsp),
2363 state->smb_fname->base_name);
2364 tevent_req_received(req);
2365 return status;
2368 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV,
2369 true,
2370 state->handle,
2371 "%s/%s",
2372 fsp_str_do_log(state->dir_fsp),
2373 state->smb_fname->base_name);
2375 *aio_state = state->aio_state;
2376 *dosmode = state->dosmode;
2377 tevent_req_received(req);
2378 return NT_STATUS_OK;
2381 static NTSTATUS smb_full_audit_fget_dos_attributes(
2382 struct vfs_handle_struct *handle,
2383 struct files_struct *fsp,
2384 uint32_t *dosmode)
2386 NTSTATUS status;
2388 status = SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle,
2389 fsp,
2390 dosmode);
2392 do_log(SMB_VFS_OP_FGET_DOS_ATTRIBUTES,
2393 NT_STATUS_IS_OK(status),
2394 handle,
2395 "%s",
2396 fsp_str_do_log(fsp));
2398 return status;
2401 static NTSTATUS smb_full_audit_set_dos_attributes(
2402 struct vfs_handle_struct *handle,
2403 const struct smb_filename *smb_fname,
2404 uint32_t dosmode)
2406 NTSTATUS status;
2408 status = SMB_VFS_NEXT_SET_DOS_ATTRIBUTES(handle,
2409 smb_fname,
2410 dosmode);
2412 do_log(SMB_VFS_OP_SET_DOS_ATTRIBUTES,
2413 NT_STATUS_IS_OK(status),
2414 handle,
2415 "%s",
2416 smb_fname_str_do_log(handle->conn, smb_fname));
2418 return status;
2421 static NTSTATUS smb_full_audit_fset_dos_attributes(
2422 struct vfs_handle_struct *handle,
2423 struct files_struct *fsp,
2424 uint32_t dosmode)
2426 NTSTATUS status;
2428 status = SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle,
2429 fsp,
2430 dosmode);
2432 do_log(SMB_VFS_OP_FSET_DOS_ATTRIBUTES,
2433 NT_STATUS_IS_OK(status),
2434 handle,
2435 "%s",
2436 fsp_str_do_log(fsp));
2438 return status;
2441 static NTSTATUS smb_full_audit_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
2442 uint32_t security_info,
2443 TALLOC_CTX *mem_ctx,
2444 struct security_descriptor **ppdesc)
2446 NTSTATUS result;
2448 result = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
2449 mem_ctx, ppdesc);
2451 do_log(SMB_VFS_OP_FGET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2452 "%s", fsp_str_do_log(fsp));
2454 return result;
2457 static NTSTATUS smb_full_audit_get_nt_acl(vfs_handle_struct *handle,
2458 const struct smb_filename *smb_fname,
2459 uint32_t security_info,
2460 TALLOC_CTX *mem_ctx,
2461 struct security_descriptor **ppdesc)
2463 NTSTATUS result;
2465 result = SMB_VFS_NEXT_GET_NT_ACL(handle, smb_fname, security_info,
2466 mem_ctx, ppdesc);
2468 do_log(SMB_VFS_OP_GET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2469 "%s", smb_fname_str_do_log(handle->conn, smb_fname));
2471 return result;
2474 static NTSTATUS smb_full_audit_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
2475 uint32_t security_info_sent,
2476 const struct security_descriptor *psd)
2478 struct vfs_full_audit_private_data *pd;
2479 NTSTATUS result;
2480 char *sd = NULL;
2482 SMB_VFS_HANDLE_GET_DATA(handle, pd,
2483 struct vfs_full_audit_private_data,
2484 return NT_STATUS_INTERNAL_ERROR);
2486 if (pd->log_secdesc) {
2487 sd = sddl_encode(talloc_tos(), psd, get_global_sam_sid());
2490 result = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
2492 do_log(SMB_VFS_OP_FSET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2493 "%s [%s]", fsp_str_do_log(fsp), sd ? sd : "");
2495 TALLOC_FREE(sd);
2497 return result;
2500 static NTSTATUS smb_full_audit_audit_file(struct vfs_handle_struct *handle,
2501 struct smb_filename *file,
2502 struct security_acl *sacl,
2503 uint32_t access_requested,
2504 uint32_t access_denied)
2506 NTSTATUS result;
2508 result = SMB_VFS_NEXT_AUDIT_FILE(handle,
2509 file,
2510 sacl,
2511 access_requested,
2512 access_denied);
2514 do_log(SMB_VFS_OP_AUDIT_FILE, NT_STATUS_IS_OK(result), handle,
2515 "%s",
2516 smb_fname_str_do_log(handle->conn, file));
2518 return result;
2521 static SMB_ACL_T smb_full_audit_sys_acl_get_file(vfs_handle_struct *handle,
2522 const struct smb_filename *smb_fname,
2523 SMB_ACL_TYPE_T type,
2524 TALLOC_CTX *mem_ctx)
2526 SMB_ACL_T result;
2528 result = SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, smb_fname,
2529 type, mem_ctx);
2531 do_log(SMB_VFS_OP_SYS_ACL_GET_FILE,
2532 (result != NULL),
2533 handle,
2534 "%s",
2535 smb_fname_str_do_log(handle->conn, smb_fname));
2537 return result;
2540 static SMB_ACL_T smb_full_audit_sys_acl_get_fd(vfs_handle_struct *handle,
2541 files_struct *fsp, TALLOC_CTX *mem_ctx)
2543 SMB_ACL_T result;
2545 result = SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp, mem_ctx);
2547 do_log(SMB_VFS_OP_SYS_ACL_GET_FD, (result != NULL), handle,
2548 "%s", fsp_str_do_log(fsp));
2550 return result;
2553 static int smb_full_audit_sys_acl_blob_get_file(vfs_handle_struct *handle,
2554 const struct smb_filename *smb_fname,
2555 TALLOC_CTX *mem_ctx,
2556 char **blob_description,
2557 DATA_BLOB *blob)
2559 int result;
2561 result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FILE(handle, smb_fname,
2562 mem_ctx, blob_description, blob);
2564 do_log(SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE,
2565 (result >= 0),
2566 handle,
2567 "%s",
2568 smb_fname_str_do_log(handle->conn, smb_fname));
2570 return result;
2573 static int smb_full_audit_sys_acl_blob_get_fd(vfs_handle_struct *handle,
2574 files_struct *fsp,
2575 TALLOC_CTX *mem_ctx,
2576 char **blob_description,
2577 DATA_BLOB *blob)
2579 int result;
2581 result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle, fsp, mem_ctx, blob_description, blob);
2583 do_log(SMB_VFS_OP_SYS_ACL_BLOB_GET_FD, (result >= 0), handle,
2584 "%s", fsp_str_do_log(fsp));
2586 return result;
2589 static int smb_full_audit_sys_acl_set_file(vfs_handle_struct *handle,
2590 const struct smb_filename *smb_fname,
2591 SMB_ACL_TYPE_T acltype,
2592 SMB_ACL_T theacl)
2594 int result;
2596 result = SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, smb_fname, acltype,
2597 theacl);
2599 do_log(SMB_VFS_OP_SYS_ACL_SET_FILE,
2600 (result >= 0),
2601 handle,
2602 "%s",
2603 smb_fname_str_do_log(handle->conn, smb_fname));
2605 return result;
2608 static int smb_full_audit_sys_acl_set_fd(vfs_handle_struct *handle, files_struct *fsp,
2609 SMB_ACL_T theacl)
2611 int result;
2613 result = SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, theacl);
2615 do_log(SMB_VFS_OP_SYS_ACL_SET_FD, (result >= 0), handle,
2616 "%s", fsp_str_do_log(fsp));
2618 return result;
2621 static int smb_full_audit_sys_acl_delete_def_file(vfs_handle_struct *handle,
2622 const struct smb_filename *smb_fname)
2624 int result;
2626 result = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, smb_fname);
2628 do_log(SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE,
2629 (result >= 0),
2630 handle,
2631 "%s",
2632 smb_fname_str_do_log(handle->conn, smb_fname));
2634 return result;
2637 static ssize_t smb_full_audit_getxattr(struct vfs_handle_struct *handle,
2638 const struct smb_filename *smb_fname,
2639 const char *name, void *value, size_t size)
2641 ssize_t result;
2643 result = SMB_VFS_NEXT_GETXATTR(handle, smb_fname, name, value, size);
2645 do_log(SMB_VFS_OP_GETXATTR,
2646 (result >= 0),
2647 handle,
2648 "%s|%s",
2649 smb_fname_str_do_log(handle->conn, smb_fname),
2650 name);
2652 return result;
2655 struct smb_full_audit_getxattrat_state {
2656 struct vfs_aio_state aio_state;
2657 vfs_handle_struct *handle;
2658 files_struct *dir_fsp;
2659 const struct smb_filename *smb_fname;
2660 const char *xattr_name;
2661 ssize_t xattr_size;
2662 uint8_t *xattr_value;
2665 static void smb_full_audit_getxattrat_done(struct tevent_req *subreq);
2667 static struct tevent_req *smb_full_audit_getxattrat_send(
2668 TALLOC_CTX *mem_ctx,
2669 struct tevent_context *ev,
2670 struct vfs_handle_struct *handle,
2671 files_struct *dir_fsp,
2672 const struct smb_filename *smb_fname,
2673 const char *xattr_name,
2674 size_t alloc_hint)
2676 struct tevent_req *req = NULL;
2677 struct tevent_req *subreq = NULL;
2678 struct smb_full_audit_getxattrat_state *state = NULL;
2680 req = tevent_req_create(mem_ctx, &state,
2681 struct smb_full_audit_getxattrat_state);
2682 if (req == NULL) {
2683 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2684 false,
2685 handle,
2686 "%s/%s|%s",
2687 fsp_str_do_log(dir_fsp),
2688 smb_fname->base_name,
2689 xattr_name);
2690 return NULL;
2692 *state = (struct smb_full_audit_getxattrat_state) {
2693 .handle = handle,
2694 .dir_fsp = dir_fsp,
2695 .smb_fname = smb_fname,
2696 .xattr_name = xattr_name,
2699 subreq = SMB_VFS_NEXT_GETXATTRAT_SEND(state,
2701 handle,
2702 dir_fsp,
2703 smb_fname,
2704 xattr_name,
2705 alloc_hint);
2706 if (tevent_req_nomem(subreq, req)) {
2707 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2708 false,
2709 handle,
2710 "%s/%s|%s",
2711 fsp_str_do_log(dir_fsp),
2712 smb_fname->base_name,
2713 xattr_name);
2714 return tevent_req_post(req, ev);
2716 tevent_req_set_callback(subreq, smb_full_audit_getxattrat_done, req);
2718 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2719 true,
2720 handle,
2721 "%s/%s|%s",
2722 fsp_str_do_log(dir_fsp),
2723 smb_fname->base_name,
2724 xattr_name);
2726 return req;
2729 static void smb_full_audit_getxattrat_done(struct tevent_req *subreq)
2731 struct tevent_req *req = tevent_req_callback_data(
2732 subreq, struct tevent_req);
2733 struct smb_full_audit_getxattrat_state *state = tevent_req_data(
2734 req, struct smb_full_audit_getxattrat_state);
2736 state->xattr_size = SMB_VFS_NEXT_GETXATTRAT_RECV(subreq,
2737 &state->aio_state,
2738 state,
2739 &state->xattr_value);
2740 TALLOC_FREE(subreq);
2741 if (state->xattr_size == -1) {
2742 tevent_req_error(req, state->aio_state.error);
2743 return;
2746 tevent_req_done(req);
2749 static ssize_t smb_full_audit_getxattrat_recv(struct tevent_req *req,
2750 struct vfs_aio_state *aio_state,
2751 TALLOC_CTX *mem_ctx,
2752 uint8_t **xattr_value)
2754 struct smb_full_audit_getxattrat_state *state = tevent_req_data(
2755 req, struct smb_full_audit_getxattrat_state);
2756 ssize_t xattr_size;
2758 if (tevent_req_is_unix_error(req, &aio_state->error)) {
2759 do_log(SMB_VFS_OP_GETXATTRAT_RECV,
2760 false,
2761 state->handle,
2762 "%s/%s|%s",
2763 fsp_str_do_log(state->dir_fsp),
2764 state->smb_fname->base_name,
2765 state->xattr_name);
2766 tevent_req_received(req);
2767 return -1;
2770 do_log(SMB_VFS_OP_GETXATTRAT_RECV,
2771 true,
2772 state->handle,
2773 "%s/%s|%s",
2774 fsp_str_do_log(state->dir_fsp),
2775 state->smb_fname->base_name,
2776 state->xattr_name);
2778 *aio_state = state->aio_state;
2779 xattr_size = state->xattr_size;
2780 if (xattr_value != NULL) {
2781 *xattr_value = talloc_move(mem_ctx, &state->xattr_value);
2784 tevent_req_received(req);
2785 return xattr_size;
2788 static ssize_t smb_full_audit_fgetxattr(struct vfs_handle_struct *handle,
2789 struct files_struct *fsp,
2790 const char *name, void *value, size_t size)
2792 ssize_t result;
2794 result = SMB_VFS_NEXT_FGETXATTR(handle, fsp, name, value, size);
2796 do_log(SMB_VFS_OP_FGETXATTR, (result >= 0), handle,
2797 "%s|%s", fsp_str_do_log(fsp), name);
2799 return result;
2802 static ssize_t smb_full_audit_listxattr(struct vfs_handle_struct *handle,
2803 const struct smb_filename *smb_fname,
2804 char *list,
2805 size_t size)
2807 ssize_t result;
2809 result = SMB_VFS_NEXT_LISTXATTR(handle, smb_fname, list, size);
2811 do_log(SMB_VFS_OP_LISTXATTR,
2812 (result >= 0),
2813 handle,
2814 "%s",
2815 smb_fname_str_do_log(handle->conn, smb_fname));
2817 return result;
2820 static ssize_t smb_full_audit_flistxattr(struct vfs_handle_struct *handle,
2821 struct files_struct *fsp, char *list,
2822 size_t size)
2824 ssize_t result;
2826 result = SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
2828 do_log(SMB_VFS_OP_FLISTXATTR, (result >= 0), handle,
2829 "%s", fsp_str_do_log(fsp));
2831 return result;
2834 static int smb_full_audit_removexattr(struct vfs_handle_struct *handle,
2835 const struct smb_filename *smb_fname,
2836 const char *name)
2838 int result;
2840 result = SMB_VFS_NEXT_REMOVEXATTR(handle, smb_fname, name);
2842 do_log(SMB_VFS_OP_REMOVEXATTR,
2843 (result >= 0),
2844 handle,
2845 "%s|%s",
2846 smb_fname_str_do_log(handle->conn, smb_fname),
2847 name);
2849 return result;
2852 static int smb_full_audit_fremovexattr(struct vfs_handle_struct *handle,
2853 struct files_struct *fsp,
2854 const char *name)
2856 int result;
2858 result = SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, name);
2860 do_log(SMB_VFS_OP_FREMOVEXATTR, (result >= 0), handle,
2861 "%s|%s", fsp_str_do_log(fsp), name);
2863 return result;
2866 static int smb_full_audit_setxattr(struct vfs_handle_struct *handle,
2867 const struct smb_filename *smb_fname,
2868 const char *name, const void *value, size_t size,
2869 int flags)
2871 int result;
2873 result = SMB_VFS_NEXT_SETXATTR(handle, smb_fname, name, value, size,
2874 flags);
2876 do_log(SMB_VFS_OP_SETXATTR,
2877 (result >= 0),
2878 handle,
2879 "%s|%s",
2880 smb_fname_str_do_log(handle->conn, smb_fname),
2881 name);
2883 return result;
2886 static int smb_full_audit_fsetxattr(struct vfs_handle_struct *handle,
2887 struct files_struct *fsp, const char *name,
2888 const void *value, size_t size, int flags)
2890 int result;
2892 result = SMB_VFS_NEXT_FSETXATTR(handle, fsp, name, value, size, flags);
2894 do_log(SMB_VFS_OP_FSETXATTR, (result >= 0), handle,
2895 "%s|%s", fsp_str_do_log(fsp), name);
2897 return result;
2900 static bool smb_full_audit_aio_force(struct vfs_handle_struct *handle,
2901 struct files_struct *fsp)
2903 bool result;
2905 result = SMB_VFS_NEXT_AIO_FORCE(handle, fsp);
2906 do_log(SMB_VFS_OP_AIO_FORCE, result, handle,
2907 "%s", fsp_str_do_log(fsp));
2909 return result;
2912 static NTSTATUS smb_full_audit_durable_cookie(struct vfs_handle_struct *handle,
2913 struct files_struct *fsp,
2914 TALLOC_CTX *mem_ctx,
2915 DATA_BLOB *cookie)
2917 NTSTATUS result;
2919 result = SMB_VFS_NEXT_DURABLE_COOKIE(handle,
2920 fsp,
2921 mem_ctx,
2922 cookie);
2924 do_log(SMB_VFS_OP_DURABLE_COOKIE, NT_STATUS_IS_OK(result), handle,
2925 "%s", fsp_str_do_log(fsp));
2927 return result;
2930 static NTSTATUS smb_full_audit_durable_disconnect(
2931 struct vfs_handle_struct *handle,
2932 struct files_struct *fsp,
2933 const DATA_BLOB old_cookie,
2934 TALLOC_CTX *mem_ctx,
2935 DATA_BLOB *new_cookie)
2937 NTSTATUS result;
2939 result = SMB_VFS_NEXT_DURABLE_DISCONNECT(handle,
2940 fsp,
2941 old_cookie,
2942 mem_ctx,
2943 new_cookie);
2945 do_log(SMB_VFS_OP_DURABLE_DISCONNECT, NT_STATUS_IS_OK(result), handle,
2946 "%s", fsp_str_do_log(fsp));
2948 return result;
2951 static NTSTATUS smb_full_audit_durable_reconnect(
2952 struct vfs_handle_struct *handle,
2953 struct smb_request *smb1req,
2954 struct smbXsrv_open *op,
2955 const DATA_BLOB old_cookie,
2956 TALLOC_CTX *mem_ctx,
2957 struct files_struct **fsp,
2958 DATA_BLOB *new_cookie)
2960 NTSTATUS result;
2962 result = SMB_VFS_NEXT_DURABLE_RECONNECT(handle,
2963 smb1req,
2965 old_cookie,
2966 mem_ctx,
2967 fsp,
2968 new_cookie);
2970 do_log(SMB_VFS_OP_DURABLE_RECONNECT,
2971 NT_STATUS_IS_OK(result),
2972 handle,
2973 "");
2975 return result;
2978 static struct vfs_fn_pointers vfs_full_audit_fns = {
2980 /* Disk operations */
2982 .connect_fn = smb_full_audit_connect,
2983 .disconnect_fn = smb_full_audit_disconnect,
2984 .disk_free_fn = smb_full_audit_disk_free,
2985 .get_quota_fn = smb_full_audit_get_quota,
2986 .set_quota_fn = smb_full_audit_set_quota,
2987 .get_shadow_copy_data_fn = smb_full_audit_get_shadow_copy_data,
2988 .statvfs_fn = smb_full_audit_statvfs,
2989 .fs_capabilities_fn = smb_full_audit_fs_capabilities,
2990 .get_dfs_referrals_fn = smb_full_audit_get_dfs_referrals,
2991 .create_dfs_pathat_fn = smb_full_audit_create_dfs_pathat,
2992 .read_dfs_pathat_fn = smb_full_audit_read_dfs_pathat,
2993 .opendir_fn = smb_full_audit_opendir,
2994 .fdopendir_fn = smb_full_audit_fdopendir,
2995 .readdir_fn = smb_full_audit_readdir,
2996 .seekdir_fn = smb_full_audit_seekdir,
2997 .telldir_fn = smb_full_audit_telldir,
2998 .rewind_dir_fn = smb_full_audit_rewinddir,
2999 .mkdirat_fn = smb_full_audit_mkdirat,
3000 .closedir_fn = smb_full_audit_closedir,
3001 .open_fn = smb_full_audit_open,
3002 .create_file_fn = smb_full_audit_create_file,
3003 .close_fn = smb_full_audit_close,
3004 .pread_fn = smb_full_audit_pread,
3005 .pread_send_fn = smb_full_audit_pread_send,
3006 .pread_recv_fn = smb_full_audit_pread_recv,
3007 .pwrite_fn = smb_full_audit_pwrite,
3008 .pwrite_send_fn = smb_full_audit_pwrite_send,
3009 .pwrite_recv_fn = smb_full_audit_pwrite_recv,
3010 .lseek_fn = smb_full_audit_lseek,
3011 .sendfile_fn = smb_full_audit_sendfile,
3012 .recvfile_fn = smb_full_audit_recvfile,
3013 .renameat_fn = smb_full_audit_renameat,
3014 .fsync_send_fn = smb_full_audit_fsync_send,
3015 .fsync_recv_fn = smb_full_audit_fsync_recv,
3016 .stat_fn = smb_full_audit_stat,
3017 .fstat_fn = smb_full_audit_fstat,
3018 .lstat_fn = smb_full_audit_lstat,
3019 .get_alloc_size_fn = smb_full_audit_get_alloc_size,
3020 .unlinkat_fn = smb_full_audit_unlinkat,
3021 .chmod_fn = smb_full_audit_chmod,
3022 .fchmod_fn = smb_full_audit_fchmod,
3023 .fchown_fn = smb_full_audit_fchown,
3024 .lchown_fn = smb_full_audit_lchown,
3025 .chdir_fn = smb_full_audit_chdir,
3026 .getwd_fn = smb_full_audit_getwd,
3027 .ntimes_fn = smb_full_audit_ntimes,
3028 .ftruncate_fn = smb_full_audit_ftruncate,
3029 .fallocate_fn = smb_full_audit_fallocate,
3030 .lock_fn = smb_full_audit_lock,
3031 .kernel_flock_fn = smb_full_audit_kernel_flock,
3032 .fcntl_fn = smb_full_audit_fcntl,
3033 .linux_setlease_fn = smb_full_audit_linux_setlease,
3034 .getlock_fn = smb_full_audit_getlock,
3035 .symlinkat_fn = smb_full_audit_symlinkat,
3036 .readlinkat_fn = smb_full_audit_readlinkat,
3037 .linkat_fn = smb_full_audit_linkat,
3038 .mknodat_fn = smb_full_audit_mknodat,
3039 .realpath_fn = smb_full_audit_realpath,
3040 .chflags_fn = smb_full_audit_chflags,
3041 .file_id_create_fn = smb_full_audit_file_id_create,
3042 .fs_file_id_fn = smb_full_audit_fs_file_id,
3043 .offload_read_send_fn = smb_full_audit_offload_read_send,
3044 .offload_read_recv_fn = smb_full_audit_offload_read_recv,
3045 .offload_write_send_fn = smb_full_audit_offload_write_send,
3046 .offload_write_recv_fn = smb_full_audit_offload_write_recv,
3047 .get_compression_fn = smb_full_audit_get_compression,
3048 .set_compression_fn = smb_full_audit_set_compression,
3049 .snap_check_path_fn = smb_full_audit_snap_check_path,
3050 .snap_create_fn = smb_full_audit_snap_create,
3051 .snap_delete_fn = smb_full_audit_snap_delete,
3052 .streaminfo_fn = smb_full_audit_streaminfo,
3053 .get_real_filename_fn = smb_full_audit_get_real_filename,
3054 .connectpath_fn = smb_full_audit_connectpath,
3055 .brl_lock_windows_fn = smb_full_audit_brl_lock_windows,
3056 .brl_unlock_windows_fn = smb_full_audit_brl_unlock_windows,
3057 .strict_lock_check_fn = smb_full_audit_strict_lock_check,
3058 .translate_name_fn = smb_full_audit_translate_name,
3059 .fsctl_fn = smb_full_audit_fsctl,
3060 .get_dos_attributes_fn = smb_full_audit_get_dos_attributes,
3061 .get_dos_attributes_send_fn = smb_full_audit_get_dos_attributes_send,
3062 .get_dos_attributes_recv_fn = smb_full_audit_get_dos_attributes_recv,
3063 .fget_dos_attributes_fn = smb_full_audit_fget_dos_attributes,
3064 .set_dos_attributes_fn = smb_full_audit_set_dos_attributes,
3065 .fset_dos_attributes_fn = smb_full_audit_fset_dos_attributes,
3066 .fget_nt_acl_fn = smb_full_audit_fget_nt_acl,
3067 .get_nt_acl_fn = smb_full_audit_get_nt_acl,
3068 .fset_nt_acl_fn = smb_full_audit_fset_nt_acl,
3069 .audit_file_fn = smb_full_audit_audit_file,
3070 .sys_acl_get_file_fn = smb_full_audit_sys_acl_get_file,
3071 .sys_acl_get_fd_fn = smb_full_audit_sys_acl_get_fd,
3072 .sys_acl_blob_get_file_fn = smb_full_audit_sys_acl_blob_get_file,
3073 .sys_acl_blob_get_fd_fn = smb_full_audit_sys_acl_blob_get_fd,
3074 .sys_acl_set_file_fn = smb_full_audit_sys_acl_set_file,
3075 .sys_acl_set_fd_fn = smb_full_audit_sys_acl_set_fd,
3076 .sys_acl_delete_def_file_fn = smb_full_audit_sys_acl_delete_def_file,
3077 .getxattr_fn = smb_full_audit_getxattr,
3078 .getxattrat_send_fn = smb_full_audit_getxattrat_send,
3079 .getxattrat_recv_fn = smb_full_audit_getxattrat_recv,
3080 .fgetxattr_fn = smb_full_audit_fgetxattr,
3081 .listxattr_fn = smb_full_audit_listxattr,
3082 .flistxattr_fn = smb_full_audit_flistxattr,
3083 .removexattr_fn = smb_full_audit_removexattr,
3084 .fremovexattr_fn = smb_full_audit_fremovexattr,
3085 .setxattr_fn = smb_full_audit_setxattr,
3086 .fsetxattr_fn = smb_full_audit_fsetxattr,
3087 .aio_force_fn = smb_full_audit_aio_force,
3088 .durable_cookie_fn = smb_full_audit_durable_cookie,
3089 .durable_disconnect_fn = smb_full_audit_durable_disconnect,
3090 .durable_reconnect_fn = smb_full_audit_durable_reconnect,
3091 .readdir_attr_fn = smb_full_audit_readdir_attr
3095 static_decl_vfs;
3096 NTSTATUS vfs_full_audit_init(TALLOC_CTX *ctx)
3098 NTSTATUS ret;
3100 smb_vfs_assert_all_fns(&vfs_full_audit_fns, "full_audit");
3102 ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "full_audit",
3103 &vfs_full_audit_fns);
3105 if (!NT_STATUS_IS_OK(ret))
3106 return ret;
3108 vfs_full_audit_debug_level = debug_add_class("full_audit");
3109 if (vfs_full_audit_debug_level == -1) {
3110 vfs_full_audit_debug_level = DBGC_VFS;
3111 DEBUG(0, ("vfs_full_audit: Couldn't register custom debugging "
3112 "class!\n"));
3113 } else {
3114 DEBUG(10, ("vfs_full_audit: Debug class number of "
3115 "'full_audit': %d\n", vfs_full_audit_debug_level));
3118 return ret;