2 * Auditing VFS module for samba. Log selected file operations to syslog
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:
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.
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.
63 #include "system/filesys.h"
64 #include "system/syslog.h"
65 #include "smbd/smbd.h"
66 #include "../librpc/gen_ndr/ndr_netlogon.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 #include "lib/util/string_wrappers.h"
77 static int vfs_full_audit_debug_level = DBGC_VFS;
79 struct vfs_full_audit_private_data {
80 struct bitmap *success_ops;
81 struct bitmap *failure_ops;
89 #define DBGC_CLASS vfs_full_audit_debug_level
91 typedef enum _vfs_op_type {
96 SMB_VFS_OP_CONNECT = 0,
97 SMB_VFS_OP_DISCONNECT,
100 SMB_VFS_OP_SET_QUOTA,
101 SMB_VFS_OP_GET_SHADOW_COPY_DATA,
103 SMB_VFS_OP_FS_CAPABILITIES,
104 SMB_VFS_OP_GET_DFS_REFERRALS,
105 SMB_VFS_OP_CREATE_DFS_PATHAT,
106 SMB_VFS_OP_READ_DFS_PATHAT,
108 /* Directory operations */
110 SMB_VFS_OP_FDOPENDIR,
114 SMB_VFS_OP_REWINDDIR,
118 /* File operations */
122 SMB_VFS_OP_CREATE_FILE,
126 SMB_VFS_OP_PREAD_SEND,
127 SMB_VFS_OP_PREAD_RECV,
130 SMB_VFS_OP_PWRITE_SEND,
131 SMB_VFS_OP_PWRITE_RECV,
137 SMB_VFS_OP_FSYNC_SEND,
138 SMB_VFS_OP_FSYNC_RECV,
142 SMB_VFS_OP_GET_ALLOC_SIZE,
151 SMB_VFS_OP_FTRUNCATE,
152 SMB_VFS_OP_FALLOCATE,
154 SMB_VFS_OP_KERNEL_FLOCK,
156 SMB_VFS_OP_LINUX_SETLEASE,
158 SMB_VFS_OP_SYMLINKAT,
159 SMB_VFS_OP_READLINKAT,
164 SMB_VFS_OP_FILE_ID_CREATE,
165 SMB_VFS_OP_FS_FILE_ID,
166 SMB_VFS_OP_FSTREAMINFO,
167 SMB_VFS_OP_GET_REAL_FILENAME,
168 SMB_VFS_OP_CONNECTPATH,
169 SMB_VFS_OP_BRL_LOCK_WINDOWS,
170 SMB_VFS_OP_BRL_UNLOCK_WINDOWS,
171 SMB_VFS_OP_STRICT_LOCK_CHECK,
172 SMB_VFS_OP_TRANSLATE_NAME,
173 SMB_VFS_OP_PARENT_PATHNAME,
175 SMB_VFS_OP_OFFLOAD_READ_SEND,
176 SMB_VFS_OP_OFFLOAD_READ_RECV,
177 SMB_VFS_OP_OFFLOAD_WRITE_SEND,
178 SMB_VFS_OP_OFFLOAD_WRITE_RECV,
179 SMB_VFS_OP_FGET_COMPRESSION,
180 SMB_VFS_OP_SET_COMPRESSION,
181 SMB_VFS_OP_SNAP_CHECK_PATH,
182 SMB_VFS_OP_SNAP_CREATE,
183 SMB_VFS_OP_SNAP_DELETE,
185 /* DOS attribute operations. */
186 SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
187 SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV,
188 SMB_VFS_OP_FGET_DOS_ATTRIBUTES,
189 SMB_VFS_OP_FSET_DOS_ATTRIBUTES,
191 /* NT ACL operations. */
193 SMB_VFS_OP_FGET_NT_ACL,
194 SMB_VFS_OP_FSET_NT_ACL,
195 SMB_VFS_OP_AUDIT_FILE,
197 /* POSIX ACL operations. */
199 SMB_VFS_OP_SYS_ACL_GET_FD,
200 SMB_VFS_OP_SYS_ACL_BLOB_GET_FD,
201 SMB_VFS_OP_SYS_ACL_SET_FD,
202 SMB_VFS_OP_SYS_ACL_DELETE_DEF_FD,
205 SMB_VFS_OP_GETXATTRAT_SEND,
206 SMB_VFS_OP_GETXATTRAT_RECV,
207 SMB_VFS_OP_FGETXATTR,
208 SMB_VFS_OP_FLISTXATTR,
209 SMB_VFS_OP_REMOVEXATTR,
210 SMB_VFS_OP_FREMOVEXATTR,
211 SMB_VFS_OP_FSETXATTR,
214 SMB_VFS_OP_AIO_FORCE,
216 /* offline operations */
217 SMB_VFS_OP_IS_OFFLINE,
218 SMB_VFS_OP_SET_OFFLINE,
220 /* Durable handle operations. */
221 SMB_VFS_OP_DURABLE_COOKIE,
222 SMB_VFS_OP_DURABLE_DISCONNECT,
223 SMB_VFS_OP_DURABLE_RECONNECT,
225 SMB_VFS_OP_FREADDIR_ATTR,
227 /* This should always be last enum value */
232 /* The following array *must* be in the same order as defined in vfs_op_type */
238 { SMB_VFS_OP_CONNECT, "connect" },
239 { SMB_VFS_OP_DISCONNECT, "disconnect" },
240 { SMB_VFS_OP_DISK_FREE, "disk_free" },
241 { SMB_VFS_OP_GET_QUOTA, "get_quota" },
242 { SMB_VFS_OP_SET_QUOTA, "set_quota" },
243 { SMB_VFS_OP_GET_SHADOW_COPY_DATA, "get_shadow_copy_data" },
244 { SMB_VFS_OP_STATVFS, "statvfs" },
245 { SMB_VFS_OP_FS_CAPABILITIES, "fs_capabilities" },
246 { SMB_VFS_OP_GET_DFS_REFERRALS, "get_dfs_referrals" },
247 { SMB_VFS_OP_CREATE_DFS_PATHAT, "create_dfs_pathat" },
248 { SMB_VFS_OP_READ_DFS_PATHAT, "read_dfs_pathat" },
249 { SMB_VFS_OP_FDOPENDIR, "fdopendir" },
250 { SMB_VFS_OP_READDIR, "readdir" },
251 { SMB_VFS_OP_SEEKDIR, "seekdir" },
252 { SMB_VFS_OP_TELLDIR, "telldir" },
253 { SMB_VFS_OP_REWINDDIR, "rewinddir" },
254 { SMB_VFS_OP_MKDIRAT, "mkdirat" },
255 { SMB_VFS_OP_CLOSEDIR, "closedir" },
256 { SMB_VFS_OP_OPEN, "open" },
257 { SMB_VFS_OP_OPENAT, "openat" },
258 { SMB_VFS_OP_CREATE_FILE, "create_file" },
259 { SMB_VFS_OP_CLOSE, "close" },
260 { SMB_VFS_OP_READ, "read" },
261 { SMB_VFS_OP_PREAD, "pread" },
262 { SMB_VFS_OP_PREAD_SEND, "pread_send" },
263 { SMB_VFS_OP_PREAD_RECV, "pread_recv" },
264 { SMB_VFS_OP_WRITE, "write" },
265 { SMB_VFS_OP_PWRITE, "pwrite" },
266 { SMB_VFS_OP_PWRITE_SEND, "pwrite_send" },
267 { SMB_VFS_OP_PWRITE_RECV, "pwrite_recv" },
268 { SMB_VFS_OP_LSEEK, "lseek" },
269 { SMB_VFS_OP_SENDFILE, "sendfile" },
270 { SMB_VFS_OP_RECVFILE, "recvfile" },
271 { SMB_VFS_OP_RENAMEAT, "renameat" },
272 { SMB_VFS_OP_FSYNC, "fsync" },
273 { SMB_VFS_OP_FSYNC_SEND, "fsync_send" },
274 { SMB_VFS_OP_FSYNC_RECV, "fsync_recv" },
275 { SMB_VFS_OP_STAT, "stat" },
276 { SMB_VFS_OP_FSTAT, "fstat" },
277 { SMB_VFS_OP_LSTAT, "lstat" },
278 { SMB_VFS_OP_GET_ALLOC_SIZE, "get_alloc_size" },
279 { SMB_VFS_OP_UNLINKAT, "unlinkat" },
280 { SMB_VFS_OP_FCHMOD, "fchmod" },
281 { SMB_VFS_OP_FCHOWN, "fchown" },
282 { SMB_VFS_OP_LCHOWN, "lchown" },
283 { SMB_VFS_OP_CHDIR, "chdir" },
284 { SMB_VFS_OP_GETWD, "getwd" },
285 { SMB_VFS_OP_NTIMES, "ntimes" },
286 { SMB_VFS_OP_FNTIMES, "fntimes" },
287 { SMB_VFS_OP_FTRUNCATE, "ftruncate" },
288 { SMB_VFS_OP_FALLOCATE,"fallocate" },
289 { SMB_VFS_OP_LOCK, "lock" },
290 { SMB_VFS_OP_KERNEL_FLOCK, "kernel_flock" },
291 { SMB_VFS_OP_FCNTL, "fcntl" },
292 { SMB_VFS_OP_LINUX_SETLEASE, "linux_setlease" },
293 { SMB_VFS_OP_GETLOCK, "getlock" },
294 { SMB_VFS_OP_SYMLINKAT, "symlinkat" },
295 { SMB_VFS_OP_READLINKAT,"readlinkat" },
296 { SMB_VFS_OP_LINKAT, "linkat" },
297 { SMB_VFS_OP_MKNODAT, "mknodat" },
298 { SMB_VFS_OP_REALPATH, "realpath" },
299 { SMB_VFS_OP_FCHFLAGS, "fchflags" },
300 { SMB_VFS_OP_FILE_ID_CREATE, "file_id_create" },
301 { SMB_VFS_OP_FS_FILE_ID, "fs_file_id" },
302 { SMB_VFS_OP_FSTREAMINFO, "fstreaminfo" },
303 { SMB_VFS_OP_GET_REAL_FILENAME, "get_real_filename" },
304 { SMB_VFS_OP_CONNECTPATH, "connectpath" },
305 { SMB_VFS_OP_BRL_LOCK_WINDOWS, "brl_lock_windows" },
306 { SMB_VFS_OP_BRL_UNLOCK_WINDOWS, "brl_unlock_windows" },
307 { SMB_VFS_OP_STRICT_LOCK_CHECK, "strict_lock_check" },
308 { SMB_VFS_OP_TRANSLATE_NAME, "translate_name" },
309 { SMB_VFS_OP_PARENT_PATHNAME, "parent_pathname" },
310 { SMB_VFS_OP_FSCTL, "fsctl" },
311 { SMB_VFS_OP_OFFLOAD_READ_SEND, "offload_read_send" },
312 { SMB_VFS_OP_OFFLOAD_READ_RECV, "offload_read_recv" },
313 { SMB_VFS_OP_OFFLOAD_WRITE_SEND, "offload_write_send" },
314 { SMB_VFS_OP_OFFLOAD_WRITE_RECV, "offload_write_recv" },
315 { SMB_VFS_OP_FGET_COMPRESSION, "fget_compression" },
316 { SMB_VFS_OP_SET_COMPRESSION, "set_compression" },
317 { SMB_VFS_OP_SNAP_CHECK_PATH, "snap_check_path" },
318 { SMB_VFS_OP_SNAP_CREATE, "snap_create" },
319 { SMB_VFS_OP_SNAP_DELETE, "snap_delete" },
320 { SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND, "get_dos_attributes_send" },
321 { SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV, "get_dos_attributes_recv" },
322 { SMB_VFS_OP_FGET_DOS_ATTRIBUTES, "fget_dos_attributes" },
323 { SMB_VFS_OP_FSET_DOS_ATTRIBUTES, "fset_dos_attributes" },
324 { SMB_VFS_OP_FGET_NT_ACL, "fget_nt_acl" },
325 { SMB_VFS_OP_FSET_NT_ACL, "fset_nt_acl" },
326 { SMB_VFS_OP_AUDIT_FILE, "audit_file" },
327 { SMB_VFS_OP_SYS_ACL_GET_FD, "sys_acl_get_fd" },
328 { SMB_VFS_OP_SYS_ACL_BLOB_GET_FD, "sys_acl_blob_get_fd" },
329 { SMB_VFS_OP_SYS_ACL_SET_FD, "sys_acl_set_fd" },
330 { SMB_VFS_OP_SYS_ACL_DELETE_DEF_FD, "sys_acl_delete_def_fd" },
331 { SMB_VFS_OP_GETXATTRAT_SEND, "getxattrat_send" },
332 { SMB_VFS_OP_GETXATTRAT_RECV, "getxattrat_recv" },
333 { SMB_VFS_OP_FGETXATTR, "fgetxattr" },
334 { SMB_VFS_OP_FLISTXATTR, "flistxattr" },
335 { SMB_VFS_OP_REMOVEXATTR, "removexattr" },
336 { SMB_VFS_OP_FREMOVEXATTR, "fremovexattr" },
337 { SMB_VFS_OP_FSETXATTR, "fsetxattr" },
338 { SMB_VFS_OP_AIO_FORCE, "aio_force" },
339 { SMB_VFS_OP_IS_OFFLINE, "is_offline" },
340 { SMB_VFS_OP_SET_OFFLINE, "set_offline" },
341 { SMB_VFS_OP_DURABLE_COOKIE, "durable_cookie" },
342 { SMB_VFS_OP_DURABLE_DISCONNECT, "durable_disconnect" },
343 { SMB_VFS_OP_DURABLE_RECONNECT, "durable_reconnect" },
344 { SMB_VFS_OP_FREADDIR_ATTR, "freaddir_attr" },
345 { SMB_VFS_OP_LAST, NULL }
348 static int audit_syslog_facility(vfs_handle_struct *handle)
350 static const struct enum_list enum_log_facilities[] = {
352 { LOG_AUTH, "AUTH" },
355 { LOG_AUTHPRIV, "AUTHPRIV" },
358 { LOG_AUDIT, "AUDIT" },
361 { LOG_CONSOLE, "CONSOLE" },
364 { LOG_CRON, "CRON" },
367 { LOG_DAEMON, "DAEMON" },
373 { LOG_INSTALL, "INSTALL" },
376 { LOG_KERN, "KERN" },
379 { LOG_LAUNCHD, "LAUNCHD" },
382 { LOG_LFMT, "LFMT" },
388 { LOG_MAIL, "MAIL" },
391 { LOG_MEGASAFE, "MEGASAFE" },
394 { LOG_NETINFO, "NETINFO" },
397 { LOG_NEWS, "NEWS" },
399 #ifdef LOG_NFACILITIES
400 { LOG_NFACILITIES, "NFACILITIES" },
408 #ifdef LOG_REMOTEAUTH
409 { LOG_REMOTEAUTH, "REMOTEAUTH" },
412 { LOG_SECURITY, "SECURITY" },
415 { LOG_SYSLOG, "SYSLOG" },
418 { LOG_USER, "USER" },
421 { LOG_UUCP, "UUCP" },
423 { LOG_LOCAL0, "LOCAL0" },
424 { LOG_LOCAL1, "LOCAL1" },
425 { LOG_LOCAL2, "LOCAL2" },
426 { LOG_LOCAL3, "LOCAL3" },
427 { LOG_LOCAL4, "LOCAL4" },
428 { LOG_LOCAL5, "LOCAL5" },
429 { LOG_LOCAL6, "LOCAL6" },
430 { LOG_LOCAL7, "LOCAL7" },
436 facility = lp_parm_enum(SNUM(handle->conn), "full_audit", "facility", enum_log_facilities, LOG_USER);
441 static int audit_syslog_priority(vfs_handle_struct *handle)
443 static const struct enum_list enum_log_priorities[] = {
444 { LOG_EMERG, "EMERG" },
445 { LOG_ALERT, "ALERT" },
446 { LOG_CRIT, "CRIT" },
448 { LOG_WARNING, "WARNING" },
449 { LOG_NOTICE, "NOTICE" },
450 { LOG_INFO, "INFO" },
451 { LOG_DEBUG, "DEBUG" },
457 priority = lp_parm_enum(SNUM(handle->conn), "full_audit", "priority",
458 enum_log_priorities, LOG_NOTICE);
459 if (priority == -1) {
460 priority = LOG_WARNING;
466 static char *audit_prefix(TALLOC_CTX *ctx, connection_struct *conn)
468 const struct loadparm_substitution *lp_sub =
469 loadparm_s3_global_substitution();
473 prefix = talloc_strdup(ctx,
474 lp_parm_const_string(SNUM(conn), "full_audit",
479 result = talloc_sub_full(ctx,
480 lp_servicename(talloc_tos(), lp_sub, SNUM(conn)),
481 conn->session_info->unix_info->unix_name,
483 conn->session_info->unix_token->gid,
484 conn->session_info->unix_info->sanitized_username,
485 conn->session_info->info->domain_name,
491 static bool log_success(struct vfs_full_audit_private_data *pd, vfs_op_type op)
493 if (pd->success_ops == NULL) {
497 return bitmap_query(pd->success_ops, op);
500 static bool log_failure(struct vfs_full_audit_private_data *pd, vfs_op_type op)
502 if (pd->failure_ops == NULL)
505 return bitmap_query(pd->failure_ops, op);
508 static struct bitmap *init_bitmap(TALLOC_CTX *mem_ctx, const char **ops)
516 bm = bitmap_talloc(mem_ctx, SMB_VFS_OP_LAST);
518 DEBUG(0, ("Could not alloc bitmap -- "
519 "defaulting to logging everything\n"));
523 for (; *ops != NULL; ops += 1) {
528 if (strequal(*ops, "all")) {
529 for (i=0; i<SMB_VFS_OP_LAST; i++) {
535 if (strequal(*ops, "none")) {
545 for (i=0; i<SMB_VFS_OP_LAST; i++) {
546 if ((vfs_op_names[i].name == NULL)
547 || (vfs_op_names[i].type != i)) {
548 smb_panic("vfs_full_audit.c: name table not "
549 "in sync with vfs_op_type enums\n");
551 if (strequal(op, vfs_op_names[i].name)) {
560 if (i == SMB_VFS_OP_LAST) {
561 DEBUG(0, ("Could not find opname %s, logging all\n",
570 static const char *audit_opname(vfs_op_type op)
572 if (op >= SMB_VFS_OP_LAST)
573 return "INVALID VFS OP";
574 return vfs_op_names[op].name;
577 static TALLOC_CTX *tmp_do_log_ctx;
579 * Get us a temporary talloc context usable just for DEBUG arguments
581 static TALLOC_CTX *do_log_ctx(void)
583 if (tmp_do_log_ctx == NULL) {
584 tmp_do_log_ctx = talloc_named_const(NULL, 0, "do_log_ctx");
586 return tmp_do_log_ctx;
589 static void do_log(vfs_op_type op, bool success, vfs_handle_struct *handle,
590 const char *format, ...) PRINTF_ATTRIBUTE(4, 5);
592 static void do_log(vfs_op_type op, bool success, vfs_handle_struct *handle,
593 const char *format, ...)
595 struct vfs_full_audit_private_data *pd;
597 char *audit_pre = NULL;
601 SMB_VFS_HANDLE_GET_DATA(handle, pd,
602 struct vfs_full_audit_private_data,
605 if (success && (!log_success(pd, op)))
608 if (!success && (!log_failure(pd, op)))
612 fstrcpy(err_msg, "ok");
614 fstr_sprintf(err_msg, "fail (%s)", strerror(errno));
616 va_start(ap, format);
617 op_msg = talloc_vasprintf(talloc_tos(), format, ap);
624 audit_pre = audit_prefix(talloc_tos(), handle->conn);
630 * Specify the facility to interoperate with other syslog
631 * callers (smbd for example).
633 priority = pd->syslog_priority | pd->syslog_facility;
635 syslog(priority, "%s|%s|%s|%s\n",
636 audit_pre ? audit_pre : "",
637 audit_opname(op), err_msg, op_msg);
639 DEBUG(1, ("%s|%s|%s|%s\n",
640 audit_pre ? audit_pre : "",
641 audit_opname(op), err_msg, op_msg));
644 TALLOC_FREE(audit_pre);
646 TALLOC_FREE(tmp_do_log_ctx);
650 * Return a string using the do_log_ctx()
652 static const char *smb_fname_str_do_log(struct connection_struct *conn,
653 const struct smb_filename *smb_fname)
658 if (smb_fname == NULL) {
662 if (smb_fname->base_name[0] != '/') {
663 char *abs_name = NULL;
664 struct smb_filename *fname_copy = cp_smb_filename(
667 if (fname_copy == NULL) {
671 if (!ISDOT(smb_fname->base_name)) {
672 abs_name = talloc_asprintf(do_log_ctx(),
674 conn->cwd_fsp->fsp_name->base_name,
675 smb_fname->base_name);
677 abs_name = talloc_strdup(do_log_ctx(),
678 conn->cwd_fsp->fsp_name->base_name);
680 if (abs_name == NULL) {
683 fname_copy->base_name = abs_name;
684 smb_fname = fname_copy;
687 status = get_full_smb_filename(do_log_ctx(), smb_fname, &fname);
688 if (!NT_STATUS_IS_OK(status)) {
695 * Return an fsp debug string using the do_log_ctx()
697 static const char *fsp_str_do_log(const struct files_struct *fsp)
699 return smb_fname_str_do_log(fsp->conn, fsp->fsp_name);
702 /* Implementation of vfs_ops. Pass everything on to the default
703 operation but log event first. */
705 static int smb_full_audit_connect(vfs_handle_struct *handle,
706 const char *svc, const char *user)
709 const char *none[] = { "none" };
710 struct vfs_full_audit_private_data *pd = NULL;
712 result = SMB_VFS_NEXT_CONNECT(handle, svc, user);
717 pd = talloc_zero(handle, struct vfs_full_audit_private_data);
719 SMB_VFS_NEXT_DISCONNECT(handle);
723 pd->syslog_facility = audit_syslog_facility(handle);
724 if (pd->syslog_facility == -1) {
725 DEBUG(1, ("%s: Unknown facility %s\n", __func__,
726 lp_parm_const_string(SNUM(handle->conn),
727 "full_audit", "facility",
729 SMB_VFS_NEXT_DISCONNECT(handle);
733 pd->syslog_priority = audit_syslog_priority(handle);
735 pd->log_secdesc = lp_parm_bool(SNUM(handle->conn),
736 "full_audit", "log_secdesc", false);
738 pd->do_syslog = lp_parm_bool(SNUM(handle->conn),
739 "full_audit", "syslog", true);
743 openlog("smbd_audit", 0, pd->syslog_facility);
747 pd->success_ops = init_bitmap(
748 pd, lp_parm_string_list(SNUM(handle->conn), "full_audit",
750 pd->failure_ops = init_bitmap(
751 pd, lp_parm_string_list(SNUM(handle->conn), "full_audit",
754 /* Store the private data. */
755 SMB_VFS_HANDLE_SET_DATA(handle, pd, NULL,
756 struct vfs_full_audit_private_data, return -1);
758 do_log(SMB_VFS_OP_CONNECT, True, handle,
764 static void smb_full_audit_disconnect(vfs_handle_struct *handle)
766 const struct loadparm_substitution *lp_sub =
767 loadparm_s3_global_substitution();
769 SMB_VFS_NEXT_DISCONNECT(handle);
771 do_log(SMB_VFS_OP_DISCONNECT, True, handle,
772 "%s", lp_servicename(talloc_tos(), lp_sub, SNUM(handle->conn)));
774 /* The bitmaps will be disconnected when the private
778 static uint64_t smb_full_audit_disk_free(vfs_handle_struct *handle,
779 const struct smb_filename *smb_fname,
786 result = SMB_VFS_NEXT_DISK_FREE(handle, smb_fname, bsize, dfree, dsize);
788 /* Don't have a reasonable notion of failure here */
790 do_log(SMB_VFS_OP_DISK_FREE,
794 smb_fname_str_do_log(handle->conn, smb_fname));
799 static int smb_full_audit_get_quota(struct vfs_handle_struct *handle,
800 const struct smb_filename *smb_fname,
801 enum SMB_QUOTA_TYPE qtype,
807 result = SMB_VFS_NEXT_GET_QUOTA(handle, smb_fname, qtype, id, qt);
809 do_log(SMB_VFS_OP_GET_QUOTA,
813 smb_fname_str_do_log(handle->conn, smb_fname));
818 static int smb_full_audit_set_quota(struct vfs_handle_struct *handle,
819 enum SMB_QUOTA_TYPE qtype, unid_t id,
824 result = SMB_VFS_NEXT_SET_QUOTA(handle, qtype, id, qt);
826 do_log(SMB_VFS_OP_SET_QUOTA, (result >= 0), handle, "");
831 static int smb_full_audit_get_shadow_copy_data(struct vfs_handle_struct *handle,
832 struct files_struct *fsp,
833 struct shadow_copy_data *shadow_copy_data,
838 result = SMB_VFS_NEXT_GET_SHADOW_COPY_DATA(handle, fsp, shadow_copy_data, labels);
840 do_log(SMB_VFS_OP_GET_SHADOW_COPY_DATA, (result >= 0), handle, "");
845 static int smb_full_audit_statvfs(struct vfs_handle_struct *handle,
846 const struct smb_filename *smb_fname,
847 struct vfs_statvfs_struct *statbuf)
851 result = SMB_VFS_NEXT_STATVFS(handle, smb_fname, statbuf);
853 do_log(SMB_VFS_OP_STATVFS, (result >= 0), handle, "");
858 static uint32_t smb_full_audit_fs_capabilities(struct vfs_handle_struct *handle, enum timestamp_set_resolution *p_ts_res)
862 result = SMB_VFS_NEXT_FS_CAPABILITIES(handle, p_ts_res);
864 do_log(SMB_VFS_OP_FS_CAPABILITIES, true, handle, "");
869 static NTSTATUS smb_full_audit_get_dfs_referrals(
870 struct vfs_handle_struct *handle,
871 struct dfs_GetDFSReferral *r)
875 status = SMB_VFS_NEXT_GET_DFS_REFERRALS(handle, r);
877 do_log(SMB_VFS_OP_GET_DFS_REFERRALS, NT_STATUS_IS_OK(status),
883 static NTSTATUS smb_full_audit_create_dfs_pathat(struct vfs_handle_struct *handle,
884 struct files_struct *dirfsp,
885 const struct smb_filename *smb_fname,
886 const struct referral *reflist,
887 size_t referral_count)
890 struct smb_filename *full_fname = NULL;
892 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
895 if (full_fname == NULL) {
896 return NT_STATUS_NO_MEMORY;
899 status = SMB_VFS_NEXT_CREATE_DFS_PATHAT(handle,
905 do_log(SMB_VFS_OP_CREATE_DFS_PATHAT,
906 NT_STATUS_IS_OK(status),
909 smb_fname_str_do_log(handle->conn, full_fname));
911 TALLOC_FREE(full_fname);
915 static NTSTATUS smb_full_audit_read_dfs_pathat(struct vfs_handle_struct *handle,
917 struct files_struct *dirfsp,
918 struct smb_filename *smb_fname,
919 struct referral **ppreflist,
920 size_t *preferral_count)
922 struct smb_filename *full_fname = NULL;
925 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
928 if (full_fname == NULL) {
929 return NT_STATUS_NO_MEMORY;
932 status = SMB_VFS_NEXT_READ_DFS_PATHAT(handle,
939 do_log(SMB_VFS_OP_READ_DFS_PATHAT,
940 NT_STATUS_IS_OK(status),
943 smb_fname_str_do_log(handle->conn, full_fname));
945 TALLOC_FREE(full_fname);
949 static NTSTATUS smb_full_audit_snap_check_path(struct vfs_handle_struct *handle,
951 const char *service_path,
956 status = SMB_VFS_NEXT_SNAP_CHECK_PATH(handle, mem_ctx, service_path,
958 do_log(SMB_VFS_OP_SNAP_CHECK_PATH, NT_STATUS_IS_OK(status),
964 static NTSTATUS smb_full_audit_snap_create(struct vfs_handle_struct *handle,
966 const char *base_volume,
974 status = SMB_VFS_NEXT_SNAP_CREATE(handle, mem_ctx, base_volume, tstamp,
975 rw, base_path, snap_path);
976 do_log(SMB_VFS_OP_SNAP_CREATE, NT_STATUS_IS_OK(status), handle, "");
981 static NTSTATUS smb_full_audit_snap_delete(struct vfs_handle_struct *handle,
988 status = SMB_VFS_NEXT_SNAP_DELETE(handle, mem_ctx, base_path,
990 do_log(SMB_VFS_OP_SNAP_DELETE, NT_STATUS_IS_OK(status), handle, "");
995 static DIR *smb_full_audit_fdopendir(vfs_handle_struct *handle,
996 files_struct *fsp, const char *mask, uint32_t attr)
1000 result = SMB_VFS_NEXT_FDOPENDIR(handle, fsp, mask, attr);
1002 do_log(SMB_VFS_OP_FDOPENDIR, (result != NULL), handle, "%s",
1003 fsp_str_do_log(fsp));
1008 static struct dirent *smb_full_audit_readdir(vfs_handle_struct *handle,
1009 struct files_struct *dirfsp,
1011 SMB_STRUCT_STAT *sbuf)
1013 struct dirent *result;
1015 result = SMB_VFS_NEXT_READDIR(handle, dirfsp, dirp, sbuf);
1017 /* This operation has no reasonable error condition
1018 * (End of dir is also failure), so always succeed.
1020 do_log(SMB_VFS_OP_READDIR, True, handle, "");
1025 static void smb_full_audit_seekdir(vfs_handle_struct *handle,
1026 DIR *dirp, long offset)
1028 SMB_VFS_NEXT_SEEKDIR(handle, dirp, offset);
1030 do_log(SMB_VFS_OP_SEEKDIR, True, handle, "");
1033 static long smb_full_audit_telldir(vfs_handle_struct *handle,
1038 result = SMB_VFS_NEXT_TELLDIR(handle, dirp);
1040 do_log(SMB_VFS_OP_TELLDIR, True, handle, "");
1045 static void smb_full_audit_rewinddir(vfs_handle_struct *handle,
1048 SMB_VFS_NEXT_REWINDDIR(handle, dirp);
1050 do_log(SMB_VFS_OP_REWINDDIR, True, handle, "");
1053 static int smb_full_audit_mkdirat(vfs_handle_struct *handle,
1054 struct files_struct *dirfsp,
1055 const struct smb_filename *smb_fname,
1058 struct smb_filename *full_fname = NULL;
1061 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1064 if (full_fname == NULL) {
1069 result = SMB_VFS_NEXT_MKDIRAT(handle,
1074 do_log(SMB_VFS_OP_MKDIRAT,
1078 smb_fname_str_do_log(handle->conn, full_fname));
1080 TALLOC_FREE(full_fname);
1085 static int smb_full_audit_closedir(vfs_handle_struct *handle,
1090 result = SMB_VFS_NEXT_CLOSEDIR(handle, dirp);
1092 do_log(SMB_VFS_OP_CLOSEDIR, (result >= 0), handle, "");
1097 static int smb_full_audit_openat(vfs_handle_struct *handle,
1098 const struct files_struct *dirfsp,
1099 const struct smb_filename *smb_fname,
1100 struct files_struct *fsp,
1106 result = SMB_VFS_NEXT_OPENAT(handle, dirfsp, smb_fname, fsp, flags, mode);
1108 do_log(SMB_VFS_OP_OPENAT, (result >= 0), handle, "%s|%s",
1109 ((flags & O_WRONLY) || (flags & O_RDWR))?"w":"r",
1110 fsp_str_do_log(fsp));
1115 static NTSTATUS smb_full_audit_create_file(vfs_handle_struct *handle,
1116 struct smb_request *req,
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,
1131 const struct smb2_create_blobs *in_context_blobs,
1132 struct smb2_create_blobs *out_context_blobs)
1135 const char* str_create_disposition;
1137 switch (create_disposition) {
1138 case FILE_SUPERSEDE:
1139 str_create_disposition = "supersede";
1141 case FILE_OVERWRITE_IF:
1142 str_create_disposition = "overwrite_if";
1145 str_create_disposition = "open";
1147 case FILE_OVERWRITE:
1148 str_create_disposition = "overwrite";
1151 str_create_disposition = "create";
1154 str_create_disposition = "open_if";
1157 str_create_disposition = "unknown";
1160 result = SMB_VFS_NEXT_CREATE_FILE(
1161 handle, /* handle */
1163 smb_fname, /* fname */
1164 access_mask, /* access_mask */
1165 share_access, /* share_access */
1166 create_disposition, /* create_disposition*/
1167 create_options, /* create_options */
1168 file_attributes, /* file_attributes */
1169 oplock_request, /* oplock_request */
1171 allocation_size, /* allocation_size */
1174 ea_list, /* ea_list */
1175 result_fsp, /* result */
1177 in_context_blobs, out_context_blobs); /* create context */
1179 do_log(SMB_VFS_OP_CREATE_FILE, (NT_STATUS_IS_OK(result)), handle,
1180 "0x%x|%s|%s|%s", access_mask,
1181 create_options & FILE_DIRECTORY_FILE ? "dir" : "file",
1182 str_create_disposition,
1183 smb_fname_str_do_log(handle->conn, smb_fname));
1188 static int smb_full_audit_close(vfs_handle_struct *handle, files_struct *fsp)
1192 result = SMB_VFS_NEXT_CLOSE(handle, fsp);
1194 do_log(SMB_VFS_OP_CLOSE, (result >= 0), handle, "%s",
1195 fsp_str_do_log(fsp));
1200 static ssize_t smb_full_audit_pread(vfs_handle_struct *handle, files_struct *fsp,
1201 void *data, size_t n, off_t offset)
1205 result = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
1207 do_log(SMB_VFS_OP_PREAD, (result >= 0), handle, "%s",
1208 fsp_str_do_log(fsp));
1213 struct smb_full_audit_pread_state {
1214 vfs_handle_struct *handle;
1217 struct vfs_aio_state vfs_aio_state;
1220 static void smb_full_audit_pread_done(struct tevent_req *subreq);
1222 static struct tevent_req *smb_full_audit_pread_send(
1223 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1224 struct tevent_context *ev, struct files_struct *fsp,
1225 void *data, size_t n, off_t offset)
1227 struct tevent_req *req, *subreq;
1228 struct smb_full_audit_pread_state *state;
1230 req = tevent_req_create(mem_ctx, &state,
1231 struct smb_full_audit_pread_state);
1233 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
1234 fsp_str_do_log(fsp));
1237 state->handle = handle;
1240 subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
1242 if (tevent_req_nomem(subreq, req)) {
1243 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
1244 fsp_str_do_log(fsp));
1245 return tevent_req_post(req, ev);
1247 tevent_req_set_callback(subreq, smb_full_audit_pread_done, req);
1249 do_log(SMB_VFS_OP_PREAD_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1253 static void smb_full_audit_pread_done(struct tevent_req *subreq)
1255 struct tevent_req *req = tevent_req_callback_data(
1256 subreq, struct tevent_req);
1257 struct smb_full_audit_pread_state *state = tevent_req_data(
1258 req, struct smb_full_audit_pread_state);
1260 state->ret = SMB_VFS_PREAD_RECV(subreq, &state->vfs_aio_state);
1261 TALLOC_FREE(subreq);
1262 tevent_req_done(req);
1265 static ssize_t smb_full_audit_pread_recv(struct tevent_req *req,
1266 struct vfs_aio_state *vfs_aio_state)
1268 struct smb_full_audit_pread_state *state = tevent_req_data(
1269 req, struct smb_full_audit_pread_state);
1271 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1272 do_log(SMB_VFS_OP_PREAD_RECV, false, state->handle, "%s",
1273 fsp_str_do_log(state->fsp));
1277 do_log(SMB_VFS_OP_PREAD_RECV, (state->ret >= 0), state->handle, "%s",
1278 fsp_str_do_log(state->fsp));
1280 *vfs_aio_state = state->vfs_aio_state;
1284 static ssize_t smb_full_audit_pwrite(vfs_handle_struct *handle, files_struct *fsp,
1285 const void *data, size_t n,
1290 result = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
1292 do_log(SMB_VFS_OP_PWRITE, (result >= 0), handle, "%s",
1293 fsp_str_do_log(fsp));
1298 struct smb_full_audit_pwrite_state {
1299 vfs_handle_struct *handle;
1302 struct vfs_aio_state vfs_aio_state;
1305 static void smb_full_audit_pwrite_done(struct tevent_req *subreq);
1307 static struct tevent_req *smb_full_audit_pwrite_send(
1308 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1309 struct tevent_context *ev, struct files_struct *fsp,
1310 const void *data, size_t n, off_t offset)
1312 struct tevent_req *req, *subreq;
1313 struct smb_full_audit_pwrite_state *state;
1315 req = tevent_req_create(mem_ctx, &state,
1316 struct smb_full_audit_pwrite_state);
1318 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1319 fsp_str_do_log(fsp));
1322 state->handle = handle;
1325 subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
1327 if (tevent_req_nomem(subreq, req)) {
1328 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1329 fsp_str_do_log(fsp));
1330 return tevent_req_post(req, ev);
1332 tevent_req_set_callback(subreq, smb_full_audit_pwrite_done, req);
1334 do_log(SMB_VFS_OP_PWRITE_SEND, true, handle, "%s",
1335 fsp_str_do_log(fsp));
1339 static void smb_full_audit_pwrite_done(struct tevent_req *subreq)
1341 struct tevent_req *req = tevent_req_callback_data(
1342 subreq, struct tevent_req);
1343 struct smb_full_audit_pwrite_state *state = tevent_req_data(
1344 req, struct smb_full_audit_pwrite_state);
1346 state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->vfs_aio_state);
1347 TALLOC_FREE(subreq);
1348 tevent_req_done(req);
1351 static ssize_t smb_full_audit_pwrite_recv(struct tevent_req *req,
1352 struct vfs_aio_state *vfs_aio_state)
1354 struct smb_full_audit_pwrite_state *state = tevent_req_data(
1355 req, struct smb_full_audit_pwrite_state);
1357 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1358 do_log(SMB_VFS_OP_PWRITE_RECV, false, state->handle, "%s",
1359 fsp_str_do_log(state->fsp));
1363 do_log(SMB_VFS_OP_PWRITE_RECV, (state->ret >= 0), state->handle, "%s",
1364 fsp_str_do_log(state->fsp));
1366 *vfs_aio_state = state->vfs_aio_state;
1370 static off_t smb_full_audit_lseek(vfs_handle_struct *handle, files_struct *fsp,
1371 off_t offset, int whence)
1375 result = SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence);
1377 do_log(SMB_VFS_OP_LSEEK, (result != (ssize_t)-1), handle,
1378 "%s", fsp_str_do_log(fsp));
1383 static ssize_t smb_full_audit_sendfile(vfs_handle_struct *handle, int tofd,
1384 files_struct *fromfsp,
1385 const DATA_BLOB *hdr, off_t offset,
1390 result = SMB_VFS_NEXT_SENDFILE(handle, tofd, fromfsp, hdr, offset, n);
1392 do_log(SMB_VFS_OP_SENDFILE, (result >= 0), handle,
1393 "%s", fsp_str_do_log(fromfsp));
1398 static ssize_t smb_full_audit_recvfile(vfs_handle_struct *handle, int fromfd,
1399 files_struct *tofsp,
1405 result = SMB_VFS_NEXT_RECVFILE(handle, fromfd, tofsp, offset, n);
1407 do_log(SMB_VFS_OP_RECVFILE, (result >= 0), handle,
1408 "%s", fsp_str_do_log(tofsp));
1413 static int smb_full_audit_renameat(vfs_handle_struct *handle,
1414 files_struct *srcfsp,
1415 const struct smb_filename *smb_fname_src,
1416 files_struct *dstfsp,
1417 const struct smb_filename *smb_fname_dst)
1421 struct smb_filename *full_fname_src = NULL;
1422 struct smb_filename *full_fname_dst = NULL;
1424 full_fname_src = full_path_from_dirfsp_atname(talloc_tos(),
1427 if (full_fname_src == NULL) {
1431 full_fname_dst = full_path_from_dirfsp_atname(talloc_tos(),
1434 if (full_fname_dst == NULL) {
1435 TALLOC_FREE(full_fname_src);
1440 result = SMB_VFS_NEXT_RENAMEAT(handle,
1447 saved_errno = errno;
1449 do_log(SMB_VFS_OP_RENAMEAT, (result >= 0), handle, "%s|%s",
1450 smb_fname_str_do_log(handle->conn, full_fname_src),
1451 smb_fname_str_do_log(handle->conn, full_fname_dst));
1453 TALLOC_FREE(full_fname_src);
1454 TALLOC_FREE(full_fname_dst);
1457 errno = saved_errno;
1462 struct smb_full_audit_fsync_state {
1463 vfs_handle_struct *handle;
1466 struct vfs_aio_state vfs_aio_state;
1469 static void smb_full_audit_fsync_done(struct tevent_req *subreq);
1471 static struct tevent_req *smb_full_audit_fsync_send(
1472 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1473 struct tevent_context *ev, struct files_struct *fsp)
1475 struct tevent_req *req, *subreq;
1476 struct smb_full_audit_fsync_state *state;
1478 req = tevent_req_create(mem_ctx, &state,
1479 struct smb_full_audit_fsync_state);
1481 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1482 fsp_str_do_log(fsp));
1485 state->handle = handle;
1488 subreq = SMB_VFS_NEXT_FSYNC_SEND(state, ev, handle, fsp);
1489 if (tevent_req_nomem(subreq, req)) {
1490 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1491 fsp_str_do_log(fsp));
1492 return tevent_req_post(req, ev);
1494 tevent_req_set_callback(subreq, smb_full_audit_fsync_done, req);
1496 do_log(SMB_VFS_OP_FSYNC_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1500 static void smb_full_audit_fsync_done(struct tevent_req *subreq)
1502 struct tevent_req *req = tevent_req_callback_data(
1503 subreq, struct tevent_req);
1504 struct smb_full_audit_fsync_state *state = tevent_req_data(
1505 req, struct smb_full_audit_fsync_state);
1507 state->ret = SMB_VFS_FSYNC_RECV(subreq, &state->vfs_aio_state);
1508 TALLOC_FREE(subreq);
1509 tevent_req_done(req);
1512 static int smb_full_audit_fsync_recv(struct tevent_req *req,
1513 struct vfs_aio_state *vfs_aio_state)
1515 struct smb_full_audit_fsync_state *state = tevent_req_data(
1516 req, struct smb_full_audit_fsync_state);
1518 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1519 do_log(SMB_VFS_OP_FSYNC_RECV, false, state->handle, "%s",
1520 fsp_str_do_log(state->fsp));
1524 do_log(SMB_VFS_OP_FSYNC_RECV, (state->ret >= 0), state->handle, "%s",
1525 fsp_str_do_log(state->fsp));
1527 *vfs_aio_state = state->vfs_aio_state;
1531 static int smb_full_audit_stat(vfs_handle_struct *handle,
1532 struct smb_filename *smb_fname)
1536 result = SMB_VFS_NEXT_STAT(handle, smb_fname);
1538 do_log(SMB_VFS_OP_STAT, (result >= 0), handle, "%s",
1539 smb_fname_str_do_log(handle->conn, smb_fname));
1544 static int smb_full_audit_fstat(vfs_handle_struct *handle, files_struct *fsp,
1545 SMB_STRUCT_STAT *sbuf)
1549 result = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1551 do_log(SMB_VFS_OP_FSTAT, (result >= 0), handle, "%s",
1552 fsp_str_do_log(fsp));
1557 static int smb_full_audit_lstat(vfs_handle_struct *handle,
1558 struct smb_filename *smb_fname)
1562 result = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
1564 do_log(SMB_VFS_OP_LSTAT, (result >= 0), handle, "%s",
1565 smb_fname_str_do_log(handle->conn, smb_fname));
1570 static uint64_t smb_full_audit_get_alloc_size(vfs_handle_struct *handle,
1571 files_struct *fsp, const SMB_STRUCT_STAT *sbuf)
1575 result = SMB_VFS_NEXT_GET_ALLOC_SIZE(handle, fsp, sbuf);
1577 do_log(SMB_VFS_OP_GET_ALLOC_SIZE, (result != (uint64_t)-1), handle,
1578 "%llu", (unsigned long long)result);
1583 static int smb_full_audit_unlinkat(vfs_handle_struct *handle,
1584 struct files_struct *dirfsp,
1585 const struct smb_filename *smb_fname,
1588 struct smb_filename *full_fname = NULL;
1591 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1594 if (full_fname == NULL) {
1598 result = SMB_VFS_NEXT_UNLINKAT(handle,
1603 do_log(SMB_VFS_OP_UNLINKAT, (result >= 0), handle, "%s",
1604 smb_fname_str_do_log(handle->conn, full_fname));
1606 TALLOC_FREE(full_fname);
1610 static int smb_full_audit_fchmod(vfs_handle_struct *handle, files_struct *fsp,
1615 result = SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1617 do_log(SMB_VFS_OP_FCHMOD, (result >= 0), handle,
1618 "%s|%o", fsp_str_do_log(fsp), mode);
1623 static int smb_full_audit_fchown(vfs_handle_struct *handle, files_struct *fsp,
1624 uid_t uid, gid_t gid)
1628 result = SMB_VFS_NEXT_FCHOWN(handle, fsp, uid, gid);
1630 do_log(SMB_VFS_OP_FCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1631 fsp_str_do_log(fsp), (long int)uid, (long int)gid);
1636 static int smb_full_audit_lchown(vfs_handle_struct *handle,
1637 const struct smb_filename *smb_fname,
1643 result = SMB_VFS_NEXT_LCHOWN(handle, smb_fname, uid, gid);
1645 do_log(SMB_VFS_OP_LCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1646 smb_fname->base_name, (long int)uid, (long int)gid);
1651 static int smb_full_audit_chdir(vfs_handle_struct *handle,
1652 const struct smb_filename *smb_fname)
1656 result = SMB_VFS_NEXT_CHDIR(handle, smb_fname);
1658 do_log(SMB_VFS_OP_CHDIR,
1662 smb_fname_str_do_log(handle->conn, smb_fname));
1667 static struct smb_filename *smb_full_audit_getwd(vfs_handle_struct *handle,
1670 struct smb_filename *result;
1672 result = SMB_VFS_NEXT_GETWD(handle, ctx);
1674 do_log(SMB_VFS_OP_GETWD, (result != NULL), handle, "%s",
1675 result == NULL? "" : result->base_name);
1680 static int smb_full_audit_fntimes(vfs_handle_struct *handle,
1682 struct smb_file_time *ft)
1685 time_t create_time = convert_timespec_to_time_t(ft->create_time);
1686 time_t atime = convert_timespec_to_time_t(ft->atime);
1687 time_t mtime = convert_timespec_to_time_t(ft->mtime);
1688 time_t ctime = convert_timespec_to_time_t(ft->ctime);
1689 const char *create_time_str = "";
1690 const char *atime_str = "";
1691 const char *mtime_str = "";
1692 const char *ctime_str = "";
1693 TALLOC_CTX *frame = talloc_stackframe();
1695 if (frame == NULL) {
1700 result = SMB_VFS_NEXT_FNTIMES(handle, fsp, ft);
1702 if (create_time > 0) {
1703 create_time_str = timestring(frame, create_time);
1706 atime_str = timestring(frame, atime);
1709 mtime_str = timestring(frame, mtime);
1712 ctime_str = timestring(frame, ctime);
1715 do_log(SMB_VFS_OP_FNTIMES,
1719 fsp_str_do_log(fsp),
1730 static int smb_full_audit_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
1735 result = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1737 do_log(SMB_VFS_OP_FTRUNCATE, (result >= 0), handle,
1738 "%s", fsp_str_do_log(fsp));
1743 static int smb_full_audit_fallocate(vfs_handle_struct *handle, files_struct *fsp,
1750 result = SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
1752 do_log(SMB_VFS_OP_FALLOCATE, (result >= 0), handle,
1753 "%s", fsp_str_do_log(fsp));
1758 static bool smb_full_audit_lock(vfs_handle_struct *handle, files_struct *fsp,
1759 int op, off_t offset, off_t count, int type)
1763 result = SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type);
1765 do_log(SMB_VFS_OP_LOCK, result, handle, "%s", fsp_str_do_log(fsp));
1770 static int smb_full_audit_kernel_flock(struct vfs_handle_struct *handle,
1771 struct files_struct *fsp,
1772 uint32_t share_access,
1773 uint32_t access_mask)
1777 result = SMB_VFS_NEXT_FILESYSTEM_SHAREMODE(handle,
1782 do_log(SMB_VFS_OP_KERNEL_FLOCK, (result >= 0), handle, "%s",
1783 fsp_str_do_log(fsp));
1788 static int smb_full_audit_fcntl(struct vfs_handle_struct *handle,
1789 struct files_struct *fsp,
1790 int cmd, va_list cmd_arg)
1793 va_list dup_cmd_arg;
1796 va_copy(dup_cmd_arg, cmd_arg);
1797 arg = va_arg(dup_cmd_arg, void *);
1798 result = SMB_VFS_NEXT_FCNTL(handle, fsp, cmd, arg);
1799 va_end(dup_cmd_arg);
1801 do_log(SMB_VFS_OP_FCNTL, (result >= 0), handle, "%s",
1802 fsp_str_do_log(fsp));
1807 static int smb_full_audit_linux_setlease(vfs_handle_struct *handle, files_struct *fsp,
1812 result = SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
1814 do_log(SMB_VFS_OP_LINUX_SETLEASE, (result >= 0), handle, "%s",
1815 fsp_str_do_log(fsp));
1820 static bool smb_full_audit_getlock(vfs_handle_struct *handle, files_struct *fsp,
1821 off_t *poffset, off_t *pcount, int *ptype, pid_t *ppid)
1825 result = SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype, ppid);
1827 do_log(SMB_VFS_OP_GETLOCK, result, handle, "%s", fsp_str_do_log(fsp));
1832 static int smb_full_audit_symlinkat(vfs_handle_struct *handle,
1833 const struct smb_filename *link_contents,
1834 struct files_struct *dirfsp,
1835 const struct smb_filename *new_smb_fname)
1837 struct smb_filename *full_fname = NULL;
1840 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1843 if (full_fname == NULL) {
1847 result = SMB_VFS_NEXT_SYMLINKAT(handle,
1852 do_log(SMB_VFS_OP_SYMLINKAT,
1856 link_contents->base_name,
1857 smb_fname_str_do_log(handle->conn, full_fname));
1859 TALLOC_FREE(full_fname);
1864 static int smb_full_audit_readlinkat(vfs_handle_struct *handle,
1865 const struct files_struct *dirfsp,
1866 const struct smb_filename *smb_fname,
1870 struct smb_filename *full_fname = NULL;
1873 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1876 if (full_fname == NULL) {
1880 result = SMB_VFS_NEXT_READLINKAT(handle,
1886 do_log(SMB_VFS_OP_READLINKAT,
1890 smb_fname_str_do_log(handle->conn, full_fname));
1892 TALLOC_FREE(full_fname);
1897 static int smb_full_audit_linkat(vfs_handle_struct *handle,
1898 files_struct *srcfsp,
1899 const struct smb_filename *old_smb_fname,
1900 files_struct *dstfsp,
1901 const struct smb_filename *new_smb_fname,
1904 struct smb_filename *old_full_fname = NULL;
1905 struct smb_filename *new_full_fname = NULL;
1908 old_full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1911 if (old_full_fname == NULL) {
1914 new_full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1917 if (new_full_fname == NULL) {
1918 TALLOC_FREE(old_full_fname);
1921 result = SMB_VFS_NEXT_LINKAT(handle,
1928 do_log(SMB_VFS_OP_LINKAT,
1932 smb_fname_str_do_log(handle->conn, old_full_fname),
1933 smb_fname_str_do_log(handle->conn, new_full_fname));
1935 TALLOC_FREE(old_full_fname);
1936 TALLOC_FREE(new_full_fname);
1941 static int smb_full_audit_mknodat(vfs_handle_struct *handle,
1942 files_struct *dirfsp,
1943 const struct smb_filename *smb_fname,
1947 struct smb_filename *full_fname = NULL;
1950 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1953 if (full_fname == NULL) {
1957 result = SMB_VFS_NEXT_MKNODAT(handle,
1963 do_log(SMB_VFS_OP_MKNODAT,
1967 smb_fname_str_do_log(handle->conn, full_fname));
1969 TALLOC_FREE(full_fname);
1974 static struct smb_filename *smb_full_audit_realpath(vfs_handle_struct *handle,
1976 const struct smb_filename *smb_fname)
1978 struct smb_filename *result_fname = NULL;
1980 result_fname = SMB_VFS_NEXT_REALPATH(handle, ctx, smb_fname);
1982 do_log(SMB_VFS_OP_REALPATH,
1983 (result_fname != NULL),
1986 smb_fname_str_do_log(handle->conn, smb_fname));
1988 return result_fname;
1991 static int smb_full_audit_fchflags(vfs_handle_struct *handle,
1992 struct files_struct *fsp,
1997 result = SMB_VFS_NEXT_FCHFLAGS(handle, fsp, flags);
1999 do_log(SMB_VFS_OP_FCHFLAGS,
2003 smb_fname_str_do_log(handle->conn, fsp->fsp_name));
2008 static struct file_id smb_full_audit_file_id_create(struct vfs_handle_struct *handle,
2009 const SMB_STRUCT_STAT *sbuf)
2011 struct file_id id_zero = { 0 };
2012 struct file_id result;
2013 struct file_id_buf idbuf;
2015 result = SMB_VFS_NEXT_FILE_ID_CREATE(handle, sbuf);
2017 do_log(SMB_VFS_OP_FILE_ID_CREATE,
2018 !file_id_equal(&id_zero, &result),
2021 file_id_str_buf(result, &idbuf));
2026 static uint64_t smb_full_audit_fs_file_id(struct vfs_handle_struct *handle,
2027 const SMB_STRUCT_STAT *sbuf)
2031 result = SMB_VFS_NEXT_FS_FILE_ID(handle, sbuf);
2033 do_log(SMB_VFS_OP_FS_FILE_ID,
2035 handle, "%" PRIu64, result);
2040 static NTSTATUS smb_full_audit_fstreaminfo(vfs_handle_struct *handle,
2041 struct files_struct *fsp,
2042 TALLOC_CTX *mem_ctx,
2043 unsigned int *pnum_streams,
2044 struct stream_struct **pstreams)
2048 result = SMB_VFS_NEXT_FSTREAMINFO(handle, fsp, mem_ctx,
2049 pnum_streams, pstreams);
2051 do_log(SMB_VFS_OP_FSTREAMINFO,
2052 NT_STATUS_IS_OK(result),
2055 smb_fname_str_do_log(handle->conn, fsp->fsp_name));
2060 static int smb_full_audit_get_real_filename(struct vfs_handle_struct *handle,
2061 const struct smb_filename *path,
2063 TALLOC_CTX *mem_ctx,
2068 result = SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name, mem_ctx,
2071 do_log(SMB_VFS_OP_GET_REAL_FILENAME, (result == 0), handle,
2073 path->base_name, name, (result == 0) ? *found_name : "");
2078 static const char *smb_full_audit_connectpath(vfs_handle_struct *handle,
2079 const struct smb_filename *smb_fname)
2083 result = SMB_VFS_NEXT_CONNECTPATH(handle, smb_fname);
2085 do_log(SMB_VFS_OP_CONNECTPATH,
2089 smb_fname_str_do_log(handle->conn, smb_fname));
2094 static NTSTATUS smb_full_audit_brl_lock_windows(struct vfs_handle_struct *handle,
2095 struct byte_range_lock *br_lck,
2096 struct lock_struct *plock)
2100 result = SMB_VFS_NEXT_BRL_LOCK_WINDOWS(handle, br_lck, plock);
2102 do_log(SMB_VFS_OP_BRL_LOCK_WINDOWS, NT_STATUS_IS_OK(result), handle,
2103 "%s:%llu-%llu. type=%d.",
2104 fsp_str_do_log(brl_fsp(br_lck)),
2105 (unsigned long long)plock->start,
2106 (unsigned long long)plock->size,
2112 static bool smb_full_audit_brl_unlock_windows(struct vfs_handle_struct *handle,
2113 struct byte_range_lock *br_lck,
2114 const struct lock_struct *plock)
2118 result = SMB_VFS_NEXT_BRL_UNLOCK_WINDOWS(handle, br_lck, plock);
2120 do_log(SMB_VFS_OP_BRL_UNLOCK_WINDOWS, (result == 0), handle,
2121 "%s:%llu-%llu:%d", fsp_str_do_log(brl_fsp(br_lck)),
2122 (unsigned long long)plock->start,
2123 (unsigned long long)plock->size,
2129 static bool smb_full_audit_strict_lock_check(struct vfs_handle_struct *handle,
2130 struct files_struct *fsp,
2131 struct lock_struct *plock)
2135 result = SMB_VFS_NEXT_STRICT_LOCK_CHECK(handle, fsp, plock);
2137 do_log(SMB_VFS_OP_STRICT_LOCK_CHECK, result, handle,
2138 "%s:%llu-%llu:%d", fsp_str_do_log(fsp),
2139 (unsigned long long)plock->start,
2140 (unsigned long long)plock->size,
2146 static NTSTATUS smb_full_audit_translate_name(struct vfs_handle_struct *handle,
2148 enum vfs_translate_direction direction,
2149 TALLOC_CTX *mem_ctx,
2154 result = SMB_VFS_NEXT_TRANSLATE_NAME(handle, name, direction, mem_ctx,
2157 do_log(SMB_VFS_OP_TRANSLATE_NAME, NT_STATUS_IS_OK(result), handle, "");
2162 static NTSTATUS smb_full_audit_parent_pathname(struct vfs_handle_struct *handle,
2163 TALLOC_CTX *mem_ctx,
2164 const struct smb_filename *smb_fname_in,
2165 struct smb_filename **parent_dir_out,
2166 struct smb_filename **atname_out)
2170 result = SMB_VFS_NEXT_PARENT_PATHNAME(handle,
2175 do_log(SMB_VFS_OP_CONNECTPATH,
2176 NT_STATUS_IS_OK(result),
2179 smb_fname_str_do_log(handle->conn, smb_fname_in));
2184 static NTSTATUS smb_full_audit_fsctl(struct vfs_handle_struct *handle,
2185 struct files_struct *fsp,
2189 const uint8_t *_in_data,
2191 uint8_t **_out_data,
2192 uint32_t max_out_len,
2197 result = SMB_VFS_NEXT_FSCTL(handle,
2208 do_log(SMB_VFS_OP_FSCTL, NT_STATUS_IS_OK(result), handle, "");
2213 static struct tevent_req *smb_full_audit_offload_read_send(
2214 TALLOC_CTX *mem_ctx,
2215 struct tevent_context *ev,
2216 struct vfs_handle_struct *handle,
2217 struct files_struct *fsp,
2223 struct tevent_req *req = NULL;
2225 req = SMB_VFS_NEXT_OFFLOAD_READ_SEND(mem_ctx, ev, handle, fsp,
2226 fsctl, ttl, offset, to_copy);
2228 do_log(SMB_VFS_OP_OFFLOAD_READ_SEND, req, handle, "");
2233 static NTSTATUS smb_full_audit_offload_read_recv(
2234 struct tevent_req *req,
2235 struct vfs_handle_struct *handle,
2236 TALLOC_CTX *mem_ctx,
2237 DATA_BLOB *_token_blob)
2241 status = SMB_VFS_NEXT_OFFLOAD_READ_RECV(req, handle, mem_ctx,
2244 do_log(SMB_VFS_OP_OFFLOAD_READ_RECV, NT_STATUS_IS_OK(status), handle, "");
2249 static struct tevent_req *smb_full_audit_offload_write_send(struct vfs_handle_struct *handle,
2250 TALLOC_CTX *mem_ctx,
2251 struct tevent_context *ev,
2254 off_t transfer_offset,
2255 struct files_struct *dest_fsp,
2259 struct tevent_req *req;
2261 req = SMB_VFS_NEXT_OFFLOAD_WRITE_SEND(handle, mem_ctx, ev,
2262 fsctl, token, transfer_offset,
2263 dest_fsp, dest_off, num);
2265 do_log(SMB_VFS_OP_OFFLOAD_WRITE_SEND, req, handle, "");
2270 static NTSTATUS smb_full_audit_offload_write_recv(struct vfs_handle_struct *handle,
2271 struct tevent_req *req,
2276 result = SMB_VFS_NEXT_OFFLOAD_WRITE_RECV(handle, req, copied);
2278 do_log(SMB_VFS_OP_OFFLOAD_WRITE_RECV, NT_STATUS_IS_OK(result), handle, "");
2283 static NTSTATUS smb_full_audit_fget_compression(vfs_handle_struct *handle,
2284 TALLOC_CTX *mem_ctx,
2285 struct files_struct *fsp,
2286 uint16_t *_compression_fmt)
2290 result = SMB_VFS_NEXT_FGET_COMPRESSION(handle, mem_ctx, fsp,
2293 do_log(SMB_VFS_OP_FGET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
2295 fsp_str_do_log(fsp));
2300 static NTSTATUS smb_full_audit_set_compression(vfs_handle_struct *handle,
2301 TALLOC_CTX *mem_ctx,
2302 struct files_struct *fsp,
2303 uint16_t compression_fmt)
2307 result = SMB_VFS_NEXT_SET_COMPRESSION(handle, mem_ctx, fsp,
2310 do_log(SMB_VFS_OP_SET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
2311 "%s", fsp_str_do_log(fsp));
2316 static NTSTATUS smb_full_audit_freaddir_attr(struct vfs_handle_struct *handle,
2317 struct files_struct *fsp,
2318 TALLOC_CTX *mem_ctx,
2319 struct readdir_attr_data **pattr_data)
2323 status = SMB_VFS_NEXT_FREADDIR_ATTR(handle, fsp, mem_ctx, pattr_data);
2325 do_log(SMB_VFS_OP_FREADDIR_ATTR,
2326 NT_STATUS_IS_OK(status),
2329 fsp_str_do_log(fsp));
2334 struct smb_full_audit_get_dos_attributes_state {
2335 struct vfs_aio_state aio_state;
2336 vfs_handle_struct *handle;
2337 files_struct *dir_fsp;
2338 const struct smb_filename *smb_fname;
2342 static void smb_full_audit_get_dos_attributes_done(struct tevent_req *subreq);
2344 static struct tevent_req *smb_full_audit_get_dos_attributes_send(
2345 TALLOC_CTX *mem_ctx,
2346 struct tevent_context *ev,
2347 struct vfs_handle_struct *handle,
2348 files_struct *dir_fsp,
2349 struct smb_filename *smb_fname)
2351 struct tevent_req *req = NULL;
2352 struct smb_full_audit_get_dos_attributes_state *state = NULL;
2353 struct tevent_req *subreq = NULL;
2355 req = tevent_req_create(mem_ctx, &state,
2356 struct smb_full_audit_get_dos_attributes_state);
2358 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2362 fsp_str_do_log(dir_fsp),
2363 smb_fname->base_name);
2366 *state = (struct smb_full_audit_get_dos_attributes_state) {
2369 .smb_fname = smb_fname,
2372 subreq = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES_SEND(mem_ctx,
2377 if (tevent_req_nomem(subreq, req)) {
2378 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2382 fsp_str_do_log(dir_fsp),
2383 smb_fname->base_name);
2384 return tevent_req_post(req, ev);
2386 tevent_req_set_callback(subreq,
2387 smb_full_audit_get_dos_attributes_done,
2390 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2394 fsp_str_do_log(dir_fsp),
2395 smb_fname->base_name);
2400 static void smb_full_audit_get_dos_attributes_done(struct tevent_req *subreq)
2402 struct tevent_req *req =
2403 tevent_req_callback_data(subreq,
2405 struct smb_full_audit_get_dos_attributes_state *state =
2406 tevent_req_data(req,
2407 struct smb_full_audit_get_dos_attributes_state);
2410 status = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES_RECV(subreq,
2413 TALLOC_FREE(subreq);
2414 if (tevent_req_nterror(req, status)) {
2418 tevent_req_done(req);
2422 static NTSTATUS smb_full_audit_get_dos_attributes_recv(struct tevent_req *req,
2423 struct vfs_aio_state *aio_state,
2426 struct smb_full_audit_get_dos_attributes_state *state =
2427 tevent_req_data(req,
2428 struct smb_full_audit_get_dos_attributes_state);
2431 if (tevent_req_is_nterror(req, &status)) {
2432 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV,
2436 fsp_str_do_log(state->dir_fsp),
2437 state->smb_fname->base_name);
2438 tevent_req_received(req);
2442 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV,
2446 fsp_str_do_log(state->dir_fsp),
2447 state->smb_fname->base_name);
2449 *aio_state = state->aio_state;
2450 *dosmode = state->dosmode;
2451 tevent_req_received(req);
2452 return NT_STATUS_OK;
2455 static NTSTATUS smb_full_audit_fget_dos_attributes(
2456 struct vfs_handle_struct *handle,
2457 struct files_struct *fsp,
2462 status = SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle,
2466 do_log(SMB_VFS_OP_FGET_DOS_ATTRIBUTES,
2467 NT_STATUS_IS_OK(status),
2470 fsp_str_do_log(fsp));
2475 static NTSTATUS smb_full_audit_fset_dos_attributes(
2476 struct vfs_handle_struct *handle,
2477 struct files_struct *fsp,
2482 status = SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle,
2486 do_log(SMB_VFS_OP_FSET_DOS_ATTRIBUTES,
2487 NT_STATUS_IS_OK(status),
2490 fsp_str_do_log(fsp));
2495 static NTSTATUS smb_full_audit_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
2496 uint32_t security_info,
2497 TALLOC_CTX *mem_ctx,
2498 struct security_descriptor **ppdesc)
2502 result = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
2505 do_log(SMB_VFS_OP_FGET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2506 "%s", fsp_str_do_log(fsp));
2511 static NTSTATUS smb_full_audit_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
2512 uint32_t security_info_sent,
2513 const struct security_descriptor *psd)
2515 struct vfs_full_audit_private_data *pd;
2519 SMB_VFS_HANDLE_GET_DATA(handle, pd,
2520 struct vfs_full_audit_private_data,
2521 return NT_STATUS_INTERNAL_ERROR);
2523 if (pd->log_secdesc) {
2524 sd = sddl_encode(talloc_tos(), psd, get_global_sam_sid());
2527 result = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
2529 do_log(SMB_VFS_OP_FSET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2530 "%s [%s]", fsp_str_do_log(fsp), sd ? sd : "");
2537 static NTSTATUS smb_full_audit_audit_file(struct vfs_handle_struct *handle,
2538 struct smb_filename *file,
2539 struct security_acl *sacl,
2540 uint32_t access_requested,
2541 uint32_t access_denied)
2545 result = SMB_VFS_NEXT_AUDIT_FILE(handle,
2551 do_log(SMB_VFS_OP_AUDIT_FILE, NT_STATUS_IS_OK(result), handle,
2553 smb_fname_str_do_log(handle->conn, file));
2558 static SMB_ACL_T smb_full_audit_sys_acl_get_fd(vfs_handle_struct *handle,
2560 SMB_ACL_TYPE_T type,
2561 TALLOC_CTX *mem_ctx)
2565 result = SMB_VFS_NEXT_SYS_ACL_GET_FD(handle,
2570 do_log(SMB_VFS_OP_SYS_ACL_GET_FD, (result != NULL), handle,
2571 "%s", fsp_str_do_log(fsp));
2576 static int smb_full_audit_sys_acl_blob_get_fd(vfs_handle_struct *handle,
2578 TALLOC_CTX *mem_ctx,
2579 char **blob_description,
2584 result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle, fsp, mem_ctx, blob_description, blob);
2586 do_log(SMB_VFS_OP_SYS_ACL_BLOB_GET_FD, (result >= 0), handle,
2587 "%s", fsp_str_do_log(fsp));
2592 static int smb_full_audit_sys_acl_set_fd(vfs_handle_struct *handle,
2593 struct files_struct *fsp,
2594 SMB_ACL_TYPE_T type,
2599 result = SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, type, theacl);
2601 do_log(SMB_VFS_OP_SYS_ACL_SET_FD, (result >= 0), handle,
2602 "%s", fsp_str_do_log(fsp));
2607 static int smb_full_audit_sys_acl_delete_def_fd(vfs_handle_struct *handle,
2608 struct files_struct *fsp)
2612 result = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FD(handle, fsp);
2614 do_log(SMB_VFS_OP_SYS_ACL_DELETE_DEF_FD,
2618 fsp_str_do_log(fsp));
2623 struct smb_full_audit_getxattrat_state {
2624 struct vfs_aio_state aio_state;
2625 vfs_handle_struct *handle;
2626 files_struct *dir_fsp;
2627 const struct smb_filename *smb_fname;
2628 const char *xattr_name;
2630 uint8_t *xattr_value;
2633 static void smb_full_audit_getxattrat_done(struct tevent_req *subreq);
2635 static struct tevent_req *smb_full_audit_getxattrat_send(
2636 TALLOC_CTX *mem_ctx,
2637 struct tevent_context *ev,
2638 struct vfs_handle_struct *handle,
2639 files_struct *dir_fsp,
2640 const struct smb_filename *smb_fname,
2641 const char *xattr_name,
2644 struct tevent_req *req = NULL;
2645 struct tevent_req *subreq = NULL;
2646 struct smb_full_audit_getxattrat_state *state = NULL;
2648 req = tevent_req_create(mem_ctx, &state,
2649 struct smb_full_audit_getxattrat_state);
2651 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2655 fsp_str_do_log(dir_fsp),
2656 smb_fname->base_name,
2660 *state = (struct smb_full_audit_getxattrat_state) {
2663 .smb_fname = smb_fname,
2664 .xattr_name = xattr_name,
2667 subreq = SMB_VFS_NEXT_GETXATTRAT_SEND(state,
2674 if (tevent_req_nomem(subreq, req)) {
2675 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2679 fsp_str_do_log(dir_fsp),
2680 smb_fname->base_name,
2682 return tevent_req_post(req, ev);
2684 tevent_req_set_callback(subreq, smb_full_audit_getxattrat_done, req);
2686 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2690 fsp_str_do_log(dir_fsp),
2691 smb_fname->base_name,
2697 static void smb_full_audit_getxattrat_done(struct tevent_req *subreq)
2699 struct tevent_req *req = tevent_req_callback_data(
2700 subreq, struct tevent_req);
2701 struct smb_full_audit_getxattrat_state *state = tevent_req_data(
2702 req, struct smb_full_audit_getxattrat_state);
2704 state->xattr_size = SMB_VFS_NEXT_GETXATTRAT_RECV(subreq,
2707 &state->xattr_value);
2708 TALLOC_FREE(subreq);
2709 if (state->xattr_size == -1) {
2710 tevent_req_error(req, state->aio_state.error);
2714 tevent_req_done(req);
2717 static ssize_t smb_full_audit_getxattrat_recv(struct tevent_req *req,
2718 struct vfs_aio_state *aio_state,
2719 TALLOC_CTX *mem_ctx,
2720 uint8_t **xattr_value)
2722 struct smb_full_audit_getxattrat_state *state = tevent_req_data(
2723 req, struct smb_full_audit_getxattrat_state);
2726 if (tevent_req_is_unix_error(req, &aio_state->error)) {
2727 do_log(SMB_VFS_OP_GETXATTRAT_RECV,
2731 fsp_str_do_log(state->dir_fsp),
2732 state->smb_fname->base_name,
2734 tevent_req_received(req);
2738 do_log(SMB_VFS_OP_GETXATTRAT_RECV,
2742 fsp_str_do_log(state->dir_fsp),
2743 state->smb_fname->base_name,
2746 *aio_state = state->aio_state;
2747 xattr_size = state->xattr_size;
2748 if (xattr_value != NULL) {
2749 *xattr_value = talloc_move(mem_ctx, &state->xattr_value);
2752 tevent_req_received(req);
2756 static ssize_t smb_full_audit_fgetxattr(struct vfs_handle_struct *handle,
2757 struct files_struct *fsp,
2758 const char *name, void *value, size_t size)
2762 result = SMB_VFS_NEXT_FGETXATTR(handle, fsp, name, value, size);
2764 do_log(SMB_VFS_OP_FGETXATTR, (result >= 0), handle,
2765 "%s|%s", fsp_str_do_log(fsp), name);
2770 static ssize_t smb_full_audit_flistxattr(struct vfs_handle_struct *handle,
2771 struct files_struct *fsp, char *list,
2776 result = SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
2778 do_log(SMB_VFS_OP_FLISTXATTR, (result >= 0), handle,
2779 "%s", fsp_str_do_log(fsp));
2784 static int smb_full_audit_fremovexattr(struct vfs_handle_struct *handle,
2785 struct files_struct *fsp,
2790 result = SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, name);
2792 do_log(SMB_VFS_OP_FREMOVEXATTR, (result >= 0), handle,
2793 "%s|%s", fsp_str_do_log(fsp), name);
2798 static int smb_full_audit_fsetxattr(struct vfs_handle_struct *handle,
2799 struct files_struct *fsp, const char *name,
2800 const void *value, size_t size, int flags)
2804 result = SMB_VFS_NEXT_FSETXATTR(handle, fsp, name, value, size, flags);
2806 do_log(SMB_VFS_OP_FSETXATTR, (result >= 0), handle,
2807 "%s|%s", fsp_str_do_log(fsp), name);
2812 static bool smb_full_audit_aio_force(struct vfs_handle_struct *handle,
2813 struct files_struct *fsp)
2817 result = SMB_VFS_NEXT_AIO_FORCE(handle, fsp);
2818 do_log(SMB_VFS_OP_AIO_FORCE, result, handle,
2819 "%s", fsp_str_do_log(fsp));
2824 static NTSTATUS smb_full_audit_durable_cookie(struct vfs_handle_struct *handle,
2825 struct files_struct *fsp,
2826 TALLOC_CTX *mem_ctx,
2831 result = SMB_VFS_NEXT_DURABLE_COOKIE(handle,
2836 do_log(SMB_VFS_OP_DURABLE_COOKIE, NT_STATUS_IS_OK(result), handle,
2837 "%s", fsp_str_do_log(fsp));
2842 static NTSTATUS smb_full_audit_durable_disconnect(
2843 struct vfs_handle_struct *handle,
2844 struct files_struct *fsp,
2845 const DATA_BLOB old_cookie,
2846 TALLOC_CTX *mem_ctx,
2847 DATA_BLOB *new_cookie)
2851 result = SMB_VFS_NEXT_DURABLE_DISCONNECT(handle,
2857 do_log(SMB_VFS_OP_DURABLE_DISCONNECT, NT_STATUS_IS_OK(result), handle,
2858 "%s", fsp_str_do_log(fsp));
2863 static NTSTATUS smb_full_audit_durable_reconnect(
2864 struct vfs_handle_struct *handle,
2865 struct smb_request *smb1req,
2866 struct smbXsrv_open *op,
2867 const DATA_BLOB old_cookie,
2868 TALLOC_CTX *mem_ctx,
2869 struct files_struct **fsp,
2870 DATA_BLOB *new_cookie)
2874 result = SMB_VFS_NEXT_DURABLE_RECONNECT(handle,
2882 do_log(SMB_VFS_OP_DURABLE_RECONNECT,
2883 NT_STATUS_IS_OK(result),
2890 static struct vfs_fn_pointers vfs_full_audit_fns = {
2892 /* Disk operations */
2894 .connect_fn = smb_full_audit_connect,
2895 .disconnect_fn = smb_full_audit_disconnect,
2896 .disk_free_fn = smb_full_audit_disk_free,
2897 .get_quota_fn = smb_full_audit_get_quota,
2898 .set_quota_fn = smb_full_audit_set_quota,
2899 .get_shadow_copy_data_fn = smb_full_audit_get_shadow_copy_data,
2900 .statvfs_fn = smb_full_audit_statvfs,
2901 .fs_capabilities_fn = smb_full_audit_fs_capabilities,
2902 .get_dfs_referrals_fn = smb_full_audit_get_dfs_referrals,
2903 .create_dfs_pathat_fn = smb_full_audit_create_dfs_pathat,
2904 .read_dfs_pathat_fn = smb_full_audit_read_dfs_pathat,
2905 .fdopendir_fn = smb_full_audit_fdopendir,
2906 .readdir_fn = smb_full_audit_readdir,
2907 .seekdir_fn = smb_full_audit_seekdir,
2908 .telldir_fn = smb_full_audit_telldir,
2909 .rewind_dir_fn = smb_full_audit_rewinddir,
2910 .mkdirat_fn = smb_full_audit_mkdirat,
2911 .closedir_fn = smb_full_audit_closedir,
2912 .openat_fn = smb_full_audit_openat,
2913 .create_file_fn = smb_full_audit_create_file,
2914 .close_fn = smb_full_audit_close,
2915 .pread_fn = smb_full_audit_pread,
2916 .pread_send_fn = smb_full_audit_pread_send,
2917 .pread_recv_fn = smb_full_audit_pread_recv,
2918 .pwrite_fn = smb_full_audit_pwrite,
2919 .pwrite_send_fn = smb_full_audit_pwrite_send,
2920 .pwrite_recv_fn = smb_full_audit_pwrite_recv,
2921 .lseek_fn = smb_full_audit_lseek,
2922 .sendfile_fn = smb_full_audit_sendfile,
2923 .recvfile_fn = smb_full_audit_recvfile,
2924 .renameat_fn = smb_full_audit_renameat,
2925 .fsync_send_fn = smb_full_audit_fsync_send,
2926 .fsync_recv_fn = smb_full_audit_fsync_recv,
2927 .stat_fn = smb_full_audit_stat,
2928 .fstat_fn = smb_full_audit_fstat,
2929 .lstat_fn = smb_full_audit_lstat,
2930 .get_alloc_size_fn = smb_full_audit_get_alloc_size,
2931 .unlinkat_fn = smb_full_audit_unlinkat,
2932 .fchmod_fn = smb_full_audit_fchmod,
2933 .fchown_fn = smb_full_audit_fchown,
2934 .lchown_fn = smb_full_audit_lchown,
2935 .chdir_fn = smb_full_audit_chdir,
2936 .getwd_fn = smb_full_audit_getwd,
2937 .fntimes_fn = smb_full_audit_fntimes,
2938 .ftruncate_fn = smb_full_audit_ftruncate,
2939 .fallocate_fn = smb_full_audit_fallocate,
2940 .lock_fn = smb_full_audit_lock,
2941 .filesystem_sharemode_fn = smb_full_audit_kernel_flock,
2942 .fcntl_fn = smb_full_audit_fcntl,
2943 .linux_setlease_fn = smb_full_audit_linux_setlease,
2944 .getlock_fn = smb_full_audit_getlock,
2945 .symlinkat_fn = smb_full_audit_symlinkat,
2946 .readlinkat_fn = smb_full_audit_readlinkat,
2947 .linkat_fn = smb_full_audit_linkat,
2948 .mknodat_fn = smb_full_audit_mknodat,
2949 .realpath_fn = smb_full_audit_realpath,
2950 .fchflags_fn = smb_full_audit_fchflags,
2951 .file_id_create_fn = smb_full_audit_file_id_create,
2952 .fs_file_id_fn = smb_full_audit_fs_file_id,
2953 .offload_read_send_fn = smb_full_audit_offload_read_send,
2954 .offload_read_recv_fn = smb_full_audit_offload_read_recv,
2955 .offload_write_send_fn = smb_full_audit_offload_write_send,
2956 .offload_write_recv_fn = smb_full_audit_offload_write_recv,
2957 .fget_compression_fn = smb_full_audit_fget_compression,
2958 .set_compression_fn = smb_full_audit_set_compression,
2959 .snap_check_path_fn = smb_full_audit_snap_check_path,
2960 .snap_create_fn = smb_full_audit_snap_create,
2961 .snap_delete_fn = smb_full_audit_snap_delete,
2962 .fstreaminfo_fn = smb_full_audit_fstreaminfo,
2963 .get_real_filename_fn = smb_full_audit_get_real_filename,
2964 .connectpath_fn = smb_full_audit_connectpath,
2965 .brl_lock_windows_fn = smb_full_audit_brl_lock_windows,
2966 .brl_unlock_windows_fn = smb_full_audit_brl_unlock_windows,
2967 .strict_lock_check_fn = smb_full_audit_strict_lock_check,
2968 .translate_name_fn = smb_full_audit_translate_name,
2969 .parent_pathname_fn = smb_full_audit_parent_pathname,
2970 .fsctl_fn = smb_full_audit_fsctl,
2971 .get_dos_attributes_send_fn = smb_full_audit_get_dos_attributes_send,
2972 .get_dos_attributes_recv_fn = smb_full_audit_get_dos_attributes_recv,
2973 .fget_dos_attributes_fn = smb_full_audit_fget_dos_attributes,
2974 .fset_dos_attributes_fn = smb_full_audit_fset_dos_attributes,
2975 .fget_nt_acl_fn = smb_full_audit_fget_nt_acl,
2976 .fset_nt_acl_fn = smb_full_audit_fset_nt_acl,
2977 .audit_file_fn = smb_full_audit_audit_file,
2978 .sys_acl_get_fd_fn = smb_full_audit_sys_acl_get_fd,
2979 .sys_acl_blob_get_fd_fn = smb_full_audit_sys_acl_blob_get_fd,
2980 .sys_acl_set_fd_fn = smb_full_audit_sys_acl_set_fd,
2981 .sys_acl_delete_def_fd_fn = smb_full_audit_sys_acl_delete_def_fd,
2982 .getxattrat_send_fn = smb_full_audit_getxattrat_send,
2983 .getxattrat_recv_fn = smb_full_audit_getxattrat_recv,
2984 .fgetxattr_fn = smb_full_audit_fgetxattr,
2985 .flistxattr_fn = smb_full_audit_flistxattr,
2986 .fremovexattr_fn = smb_full_audit_fremovexattr,
2987 .fsetxattr_fn = smb_full_audit_fsetxattr,
2988 .aio_force_fn = smb_full_audit_aio_force,
2989 .durable_cookie_fn = smb_full_audit_durable_cookie,
2990 .durable_disconnect_fn = smb_full_audit_durable_disconnect,
2991 .durable_reconnect_fn = smb_full_audit_durable_reconnect,
2992 .freaddir_attr_fn = smb_full_audit_freaddir_attr,
2996 NTSTATUS vfs_full_audit_init(TALLOC_CTX *ctx)
3000 smb_vfs_assert_all_fns(&vfs_full_audit_fns, "full_audit");
3002 ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "full_audit",
3003 &vfs_full_audit_fns);
3005 if (!NT_STATUS_IS_OK(ret))
3008 vfs_full_audit_debug_level = debug_add_class("full_audit");
3009 if (vfs_full_audit_debug_level == -1) {
3010 vfs_full_audit_debug_level = DBGC_VFS;
3011 DEBUG(0, ("vfs_full_audit: Couldn't register custom debugging "
3014 DEBUG(10, ("vfs_full_audit: Debug class number of "
3015 "'full_audit': %d\n", vfs_full_audit_debug_level));