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,
206 SMB_VFS_OP_GETXATTRAT_SEND,
207 SMB_VFS_OP_GETXATTRAT_RECV,
208 SMB_VFS_OP_FGETXATTR,
209 SMB_VFS_OP_FLISTXATTR,
210 SMB_VFS_OP_REMOVEXATTR,
211 SMB_VFS_OP_FREMOVEXATTR,
212 SMB_VFS_OP_FSETXATTR,
215 SMB_VFS_OP_AIO_FORCE,
217 /* offline operations */
218 SMB_VFS_OP_IS_OFFLINE,
219 SMB_VFS_OP_SET_OFFLINE,
221 /* Durable handle operations. */
222 SMB_VFS_OP_DURABLE_COOKIE,
223 SMB_VFS_OP_DURABLE_DISCONNECT,
224 SMB_VFS_OP_DURABLE_RECONNECT,
226 SMB_VFS_OP_FREADDIR_ATTR,
228 /* This should always be last enum value */
233 /* The following array *must* be in the same order as defined in vfs_op_type */
239 { SMB_VFS_OP_CONNECT, "connect" },
240 { SMB_VFS_OP_DISCONNECT, "disconnect" },
241 { SMB_VFS_OP_DISK_FREE, "disk_free" },
242 { SMB_VFS_OP_GET_QUOTA, "get_quota" },
243 { SMB_VFS_OP_SET_QUOTA, "set_quota" },
244 { SMB_VFS_OP_GET_SHADOW_COPY_DATA, "get_shadow_copy_data" },
245 { SMB_VFS_OP_STATVFS, "statvfs" },
246 { SMB_VFS_OP_FS_CAPABILITIES, "fs_capabilities" },
247 { SMB_VFS_OP_GET_DFS_REFERRALS, "get_dfs_referrals" },
248 { SMB_VFS_OP_CREATE_DFS_PATHAT, "create_dfs_pathat" },
249 { SMB_VFS_OP_READ_DFS_PATHAT, "read_dfs_pathat" },
250 { SMB_VFS_OP_FDOPENDIR, "fdopendir" },
251 { SMB_VFS_OP_READDIR, "readdir" },
252 { SMB_VFS_OP_SEEKDIR, "seekdir" },
253 { SMB_VFS_OP_TELLDIR, "telldir" },
254 { SMB_VFS_OP_REWINDDIR, "rewinddir" },
255 { SMB_VFS_OP_MKDIRAT, "mkdirat" },
256 { SMB_VFS_OP_CLOSEDIR, "closedir" },
257 { SMB_VFS_OP_OPEN, "open" },
258 { SMB_VFS_OP_OPENAT, "openat" },
259 { SMB_VFS_OP_CREATE_FILE, "create_file" },
260 { SMB_VFS_OP_CLOSE, "close" },
261 { SMB_VFS_OP_READ, "read" },
262 { SMB_VFS_OP_PREAD, "pread" },
263 { SMB_VFS_OP_PREAD_SEND, "pread_send" },
264 { SMB_VFS_OP_PREAD_RECV, "pread_recv" },
265 { SMB_VFS_OP_WRITE, "write" },
266 { SMB_VFS_OP_PWRITE, "pwrite" },
267 { SMB_VFS_OP_PWRITE_SEND, "pwrite_send" },
268 { SMB_VFS_OP_PWRITE_RECV, "pwrite_recv" },
269 { SMB_VFS_OP_LSEEK, "lseek" },
270 { SMB_VFS_OP_SENDFILE, "sendfile" },
271 { SMB_VFS_OP_RECVFILE, "recvfile" },
272 { SMB_VFS_OP_RENAMEAT, "renameat" },
273 { SMB_VFS_OP_FSYNC, "fsync" },
274 { SMB_VFS_OP_FSYNC_SEND, "fsync_send" },
275 { SMB_VFS_OP_FSYNC_RECV, "fsync_recv" },
276 { SMB_VFS_OP_STAT, "stat" },
277 { SMB_VFS_OP_FSTAT, "fstat" },
278 { SMB_VFS_OP_LSTAT, "lstat" },
279 { SMB_VFS_OP_GET_ALLOC_SIZE, "get_alloc_size" },
280 { SMB_VFS_OP_UNLINKAT, "unlinkat" },
281 { SMB_VFS_OP_FCHMOD, "fchmod" },
282 { SMB_VFS_OP_FCHOWN, "fchown" },
283 { SMB_VFS_OP_LCHOWN, "lchown" },
284 { SMB_VFS_OP_CHDIR, "chdir" },
285 { SMB_VFS_OP_GETWD, "getwd" },
286 { SMB_VFS_OP_NTIMES, "ntimes" },
287 { SMB_VFS_OP_FNTIMES, "fntimes" },
288 { SMB_VFS_OP_FTRUNCATE, "ftruncate" },
289 { SMB_VFS_OP_FALLOCATE,"fallocate" },
290 { SMB_VFS_OP_LOCK, "lock" },
291 { SMB_VFS_OP_KERNEL_FLOCK, "kernel_flock" },
292 { SMB_VFS_OP_FCNTL, "fcntl" },
293 { SMB_VFS_OP_LINUX_SETLEASE, "linux_setlease" },
294 { SMB_VFS_OP_GETLOCK, "getlock" },
295 { SMB_VFS_OP_SYMLINKAT, "symlinkat" },
296 { SMB_VFS_OP_READLINKAT,"readlinkat" },
297 { SMB_VFS_OP_LINKAT, "linkat" },
298 { SMB_VFS_OP_MKNODAT, "mknodat" },
299 { SMB_VFS_OP_REALPATH, "realpath" },
300 { SMB_VFS_OP_CHFLAGS, "chflags" },
301 { SMB_VFS_OP_FILE_ID_CREATE, "file_id_create" },
302 { SMB_VFS_OP_FS_FILE_ID, "fs_file_id" },
303 { SMB_VFS_OP_FSTREAMINFO, "fstreaminfo" },
304 { SMB_VFS_OP_GET_REAL_FILENAME, "get_real_filename" },
305 { SMB_VFS_OP_CONNECTPATH, "connectpath" },
306 { SMB_VFS_OP_BRL_LOCK_WINDOWS, "brl_lock_windows" },
307 { SMB_VFS_OP_BRL_UNLOCK_WINDOWS, "brl_unlock_windows" },
308 { SMB_VFS_OP_STRICT_LOCK_CHECK, "strict_lock_check" },
309 { SMB_VFS_OP_TRANSLATE_NAME, "translate_name" },
310 { SMB_VFS_OP_PARENT_PATHNAME, "parent_pathname" },
311 { SMB_VFS_OP_FSCTL, "fsctl" },
312 { SMB_VFS_OP_OFFLOAD_READ_SEND, "offload_read_send" },
313 { SMB_VFS_OP_OFFLOAD_READ_RECV, "offload_read_recv" },
314 { SMB_VFS_OP_OFFLOAD_WRITE_SEND, "offload_write_send" },
315 { SMB_VFS_OP_OFFLOAD_WRITE_RECV, "offload_write_recv" },
316 { SMB_VFS_OP_FGET_COMPRESSION, "fget_compression" },
317 { SMB_VFS_OP_SET_COMPRESSION, "set_compression" },
318 { SMB_VFS_OP_SNAP_CHECK_PATH, "snap_check_path" },
319 { SMB_VFS_OP_SNAP_CREATE, "snap_create" },
320 { SMB_VFS_OP_SNAP_DELETE, "snap_delete" },
321 { SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND, "get_dos_attributes_send" },
322 { SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV, "get_dos_attributes_recv" },
323 { SMB_VFS_OP_FGET_DOS_ATTRIBUTES, "fget_dos_attributes" },
324 { SMB_VFS_OP_FSET_DOS_ATTRIBUTES, "fset_dos_attributes" },
325 { SMB_VFS_OP_FGET_NT_ACL, "fget_nt_acl" },
326 { SMB_VFS_OP_FSET_NT_ACL, "fset_nt_acl" },
327 { SMB_VFS_OP_AUDIT_FILE, "audit_file" },
328 { SMB_VFS_OP_SYS_ACL_GET_FD, "sys_acl_get_fd" },
329 { SMB_VFS_OP_SYS_ACL_BLOB_GET_FD, "sys_acl_blob_get_fd" },
330 { SMB_VFS_OP_SYS_ACL_SET_FD, "sys_acl_set_fd" },
331 { SMB_VFS_OP_SYS_ACL_DELETE_DEF_FD, "sys_acl_delete_def_fd" },
332 { SMB_VFS_OP_GETXATTR, "getxattr" },
333 { SMB_VFS_OP_GETXATTRAT_SEND, "getxattrat_send" },
334 { SMB_VFS_OP_GETXATTRAT_RECV, "getxattrat_recv" },
335 { SMB_VFS_OP_FGETXATTR, "fgetxattr" },
336 { SMB_VFS_OP_FLISTXATTR, "flistxattr" },
337 { SMB_VFS_OP_REMOVEXATTR, "removexattr" },
338 { SMB_VFS_OP_FREMOVEXATTR, "fremovexattr" },
339 { SMB_VFS_OP_FSETXATTR, "fsetxattr" },
340 { SMB_VFS_OP_AIO_FORCE, "aio_force" },
341 { SMB_VFS_OP_IS_OFFLINE, "is_offline" },
342 { SMB_VFS_OP_SET_OFFLINE, "set_offline" },
343 { SMB_VFS_OP_DURABLE_COOKIE, "durable_cookie" },
344 { SMB_VFS_OP_DURABLE_DISCONNECT, "durable_disconnect" },
345 { SMB_VFS_OP_DURABLE_RECONNECT, "durable_reconnect" },
346 { SMB_VFS_OP_FREADDIR_ATTR, "freaddir_attr" },
347 { SMB_VFS_OP_LAST, NULL }
350 static int audit_syslog_facility(vfs_handle_struct *handle)
352 static const struct enum_list enum_log_facilities[] = {
354 { LOG_AUTH, "AUTH" },
357 { LOG_AUTHPRIV, "AUTHPRIV" },
360 { LOG_AUDIT, "AUDIT" },
363 { LOG_CONSOLE, "CONSOLE" },
366 { LOG_CRON, "CRON" },
369 { LOG_DAEMON, "DAEMON" },
375 { LOG_INSTALL, "INSTALL" },
378 { LOG_KERN, "KERN" },
381 { LOG_LAUNCHD, "LAUNCHD" },
384 { LOG_LFMT, "LFMT" },
390 { LOG_MAIL, "MAIL" },
393 { LOG_MEGASAFE, "MEGASAFE" },
396 { LOG_NETINFO, "NETINFO" },
399 { LOG_NEWS, "NEWS" },
401 #ifdef LOG_NFACILITIES
402 { LOG_NFACILITIES, "NFACILITIES" },
410 #ifdef LOG_REMOTEAUTH
411 { LOG_REMOTEAUTH, "REMOTEAUTH" },
414 { LOG_SECURITY, "SECURITY" },
417 { LOG_SYSLOG, "SYSLOG" },
420 { LOG_USER, "USER" },
423 { LOG_UUCP, "UUCP" },
425 { LOG_LOCAL0, "LOCAL0" },
426 { LOG_LOCAL1, "LOCAL1" },
427 { LOG_LOCAL2, "LOCAL2" },
428 { LOG_LOCAL3, "LOCAL3" },
429 { LOG_LOCAL4, "LOCAL4" },
430 { LOG_LOCAL5, "LOCAL5" },
431 { LOG_LOCAL6, "LOCAL6" },
432 { LOG_LOCAL7, "LOCAL7" },
438 facility = lp_parm_enum(SNUM(handle->conn), "full_audit", "facility", enum_log_facilities, LOG_USER);
443 static int audit_syslog_priority(vfs_handle_struct *handle)
445 static const struct enum_list enum_log_priorities[] = {
446 { LOG_EMERG, "EMERG" },
447 { LOG_ALERT, "ALERT" },
448 { LOG_CRIT, "CRIT" },
450 { LOG_WARNING, "WARNING" },
451 { LOG_NOTICE, "NOTICE" },
452 { LOG_INFO, "INFO" },
453 { LOG_DEBUG, "DEBUG" },
459 priority = lp_parm_enum(SNUM(handle->conn), "full_audit", "priority",
460 enum_log_priorities, LOG_NOTICE);
461 if (priority == -1) {
462 priority = LOG_WARNING;
468 static char *audit_prefix(TALLOC_CTX *ctx, connection_struct *conn)
470 const struct loadparm_substitution *lp_sub =
471 loadparm_s3_global_substitution();
475 prefix = talloc_strdup(ctx,
476 lp_parm_const_string(SNUM(conn), "full_audit",
481 result = talloc_sub_full(ctx,
482 lp_servicename(talloc_tos(), lp_sub, SNUM(conn)),
483 conn->session_info->unix_info->unix_name,
485 conn->session_info->unix_token->gid,
486 conn->session_info->unix_info->sanitized_username,
487 conn->session_info->info->domain_name,
493 static bool log_success(struct vfs_full_audit_private_data *pd, vfs_op_type op)
495 if (pd->success_ops == NULL) {
499 return bitmap_query(pd->success_ops, op);
502 static bool log_failure(struct vfs_full_audit_private_data *pd, vfs_op_type op)
504 if (pd->failure_ops == NULL)
507 return bitmap_query(pd->failure_ops, op);
510 static struct bitmap *init_bitmap(TALLOC_CTX *mem_ctx, const char **ops)
518 bm = bitmap_talloc(mem_ctx, SMB_VFS_OP_LAST);
520 DEBUG(0, ("Could not alloc bitmap -- "
521 "defaulting to logging everything\n"));
525 for (; *ops != NULL; ops += 1) {
530 if (strequal(*ops, "all")) {
531 for (i=0; i<SMB_VFS_OP_LAST; i++) {
537 if (strequal(*ops, "none")) {
547 for (i=0; i<SMB_VFS_OP_LAST; i++) {
548 if ((vfs_op_names[i].name == NULL)
549 || (vfs_op_names[i].type != i)) {
550 smb_panic("vfs_full_audit.c: name table not "
551 "in sync with vfs_op_type enums\n");
553 if (strequal(op, vfs_op_names[i].name)) {
562 if (i == SMB_VFS_OP_LAST) {
563 DEBUG(0, ("Could not find opname %s, logging all\n",
572 static const char *audit_opname(vfs_op_type op)
574 if (op >= SMB_VFS_OP_LAST)
575 return "INVALID VFS OP";
576 return vfs_op_names[op].name;
579 static TALLOC_CTX *tmp_do_log_ctx;
581 * Get us a temporary talloc context usable just for DEBUG arguments
583 static TALLOC_CTX *do_log_ctx(void)
585 if (tmp_do_log_ctx == NULL) {
586 tmp_do_log_ctx = talloc_named_const(NULL, 0, "do_log_ctx");
588 return tmp_do_log_ctx;
591 static void do_log(vfs_op_type op, bool success, vfs_handle_struct *handle,
592 const char *format, ...) PRINTF_ATTRIBUTE(4, 5);
594 static void do_log(vfs_op_type op, bool success, vfs_handle_struct *handle,
595 const char *format, ...)
597 struct vfs_full_audit_private_data *pd;
599 char *audit_pre = NULL;
603 SMB_VFS_HANDLE_GET_DATA(handle, pd,
604 struct vfs_full_audit_private_data,
607 if (success && (!log_success(pd, op)))
610 if (!success && (!log_failure(pd, op)))
614 fstrcpy(err_msg, "ok");
616 fstr_sprintf(err_msg, "fail (%s)", strerror(errno));
618 va_start(ap, format);
619 op_msg = talloc_vasprintf(talloc_tos(), format, ap);
626 audit_pre = audit_prefix(talloc_tos(), handle->conn);
632 * Specify the facility to interoperate with other syslog
633 * callers (smbd for example).
635 priority = pd->syslog_priority | pd->syslog_facility;
637 syslog(priority, "%s|%s|%s|%s\n",
638 audit_pre ? audit_pre : "",
639 audit_opname(op), err_msg, op_msg);
641 DEBUG(1, ("%s|%s|%s|%s\n",
642 audit_pre ? audit_pre : "",
643 audit_opname(op), err_msg, op_msg));
646 TALLOC_FREE(audit_pre);
648 TALLOC_FREE(tmp_do_log_ctx);
652 * Return a string using the do_log_ctx()
654 static const char *smb_fname_str_do_log(struct connection_struct *conn,
655 const struct smb_filename *smb_fname)
660 if (smb_fname == NULL) {
664 if (smb_fname->base_name[0] != '/') {
665 char *abs_name = NULL;
666 struct smb_filename *fname_copy = cp_smb_filename(
669 if (fname_copy == NULL) {
673 if (!ISDOT(smb_fname->base_name)) {
674 abs_name = talloc_asprintf(do_log_ctx(),
676 conn->cwd_fsp->fsp_name->base_name,
677 smb_fname->base_name);
679 abs_name = talloc_strdup(do_log_ctx(),
680 conn->cwd_fsp->fsp_name->base_name);
682 if (abs_name == NULL) {
685 fname_copy->base_name = abs_name;
686 smb_fname = fname_copy;
689 status = get_full_smb_filename(do_log_ctx(), smb_fname, &fname);
690 if (!NT_STATUS_IS_OK(status)) {
697 * Return an fsp debug string using the do_log_ctx()
699 static const char *fsp_str_do_log(const struct files_struct *fsp)
701 return smb_fname_str_do_log(fsp->conn, fsp->fsp_name);
704 /* Implementation of vfs_ops. Pass everything on to the default
705 operation but log event first. */
707 static int smb_full_audit_connect(vfs_handle_struct *handle,
708 const char *svc, const char *user)
711 const char *none[] = { "none" };
712 struct vfs_full_audit_private_data *pd = NULL;
714 result = SMB_VFS_NEXT_CONNECT(handle, svc, user);
719 pd = talloc_zero(handle, struct vfs_full_audit_private_data);
721 SMB_VFS_NEXT_DISCONNECT(handle);
725 pd->syslog_facility = audit_syslog_facility(handle);
726 if (pd->syslog_facility == -1) {
727 DEBUG(1, ("%s: Unknown facility %s\n", __func__,
728 lp_parm_const_string(SNUM(handle->conn),
729 "full_audit", "facility",
731 SMB_VFS_NEXT_DISCONNECT(handle);
735 pd->syslog_priority = audit_syslog_priority(handle);
737 pd->log_secdesc = lp_parm_bool(SNUM(handle->conn),
738 "full_audit", "log_secdesc", false);
740 pd->do_syslog = lp_parm_bool(SNUM(handle->conn),
741 "full_audit", "syslog", true);
745 openlog("smbd_audit", 0, pd->syslog_facility);
749 pd->success_ops = init_bitmap(
750 pd, lp_parm_string_list(SNUM(handle->conn), "full_audit",
752 pd->failure_ops = init_bitmap(
753 pd, lp_parm_string_list(SNUM(handle->conn), "full_audit",
756 /* Store the private data. */
757 SMB_VFS_HANDLE_SET_DATA(handle, pd, NULL,
758 struct vfs_full_audit_private_data, return -1);
760 do_log(SMB_VFS_OP_CONNECT, True, handle,
766 static void smb_full_audit_disconnect(vfs_handle_struct *handle)
768 const struct loadparm_substitution *lp_sub =
769 loadparm_s3_global_substitution();
771 SMB_VFS_NEXT_DISCONNECT(handle);
773 do_log(SMB_VFS_OP_DISCONNECT, True, handle,
774 "%s", lp_servicename(talloc_tos(), lp_sub, SNUM(handle->conn)));
776 /* The bitmaps will be disconnected when the private
780 static uint64_t smb_full_audit_disk_free(vfs_handle_struct *handle,
781 const struct smb_filename *smb_fname,
788 result = SMB_VFS_NEXT_DISK_FREE(handle, smb_fname, bsize, dfree, dsize);
790 /* Don't have a reasonable notion of failure here */
792 do_log(SMB_VFS_OP_DISK_FREE,
796 smb_fname_str_do_log(handle->conn, smb_fname));
801 static int smb_full_audit_get_quota(struct vfs_handle_struct *handle,
802 const struct smb_filename *smb_fname,
803 enum SMB_QUOTA_TYPE qtype,
809 result = SMB_VFS_NEXT_GET_QUOTA(handle, smb_fname, qtype, id, qt);
811 do_log(SMB_VFS_OP_GET_QUOTA,
815 smb_fname_str_do_log(handle->conn, smb_fname));
820 static int smb_full_audit_set_quota(struct vfs_handle_struct *handle,
821 enum SMB_QUOTA_TYPE qtype, unid_t id,
826 result = SMB_VFS_NEXT_SET_QUOTA(handle, qtype, id, qt);
828 do_log(SMB_VFS_OP_SET_QUOTA, (result >= 0), handle, "");
833 static int smb_full_audit_get_shadow_copy_data(struct vfs_handle_struct *handle,
834 struct files_struct *fsp,
835 struct shadow_copy_data *shadow_copy_data,
840 result = SMB_VFS_NEXT_GET_SHADOW_COPY_DATA(handle, fsp, shadow_copy_data, labels);
842 do_log(SMB_VFS_OP_GET_SHADOW_COPY_DATA, (result >= 0), handle, "");
847 static int smb_full_audit_statvfs(struct vfs_handle_struct *handle,
848 const struct smb_filename *smb_fname,
849 struct vfs_statvfs_struct *statbuf)
853 result = SMB_VFS_NEXT_STATVFS(handle, smb_fname, statbuf);
855 do_log(SMB_VFS_OP_STATVFS, (result >= 0), handle, "");
860 static uint32_t smb_full_audit_fs_capabilities(struct vfs_handle_struct *handle, enum timestamp_set_resolution *p_ts_res)
864 result = SMB_VFS_NEXT_FS_CAPABILITIES(handle, p_ts_res);
866 do_log(SMB_VFS_OP_FS_CAPABILITIES, true, handle, "");
871 static NTSTATUS smb_full_audit_get_dfs_referrals(
872 struct vfs_handle_struct *handle,
873 struct dfs_GetDFSReferral *r)
877 status = SMB_VFS_NEXT_GET_DFS_REFERRALS(handle, r);
879 do_log(SMB_VFS_OP_GET_DFS_REFERRALS, NT_STATUS_IS_OK(status),
885 static NTSTATUS smb_full_audit_create_dfs_pathat(struct vfs_handle_struct *handle,
886 struct files_struct *dirfsp,
887 const struct smb_filename *smb_fname,
888 const struct referral *reflist,
889 size_t referral_count)
892 struct smb_filename *full_fname = NULL;
894 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
897 if (full_fname == NULL) {
898 return NT_STATUS_NO_MEMORY;
901 status = SMB_VFS_NEXT_CREATE_DFS_PATHAT(handle,
907 do_log(SMB_VFS_OP_CREATE_DFS_PATHAT,
908 NT_STATUS_IS_OK(status),
911 smb_fname_str_do_log(handle->conn, full_fname));
913 TALLOC_FREE(full_fname);
917 static NTSTATUS smb_full_audit_read_dfs_pathat(struct vfs_handle_struct *handle,
919 struct files_struct *dirfsp,
920 struct smb_filename *smb_fname,
921 struct referral **ppreflist,
922 size_t *preferral_count)
926 status = SMB_VFS_NEXT_READ_DFS_PATHAT(handle,
933 do_log(SMB_VFS_OP_READ_DFS_PATHAT,
934 NT_STATUS_IS_OK(status),
937 smb_fname_str_do_log(handle->conn, smb_fname));
942 static NTSTATUS smb_full_audit_snap_check_path(struct vfs_handle_struct *handle,
944 const char *service_path,
949 status = SMB_VFS_NEXT_SNAP_CHECK_PATH(handle, mem_ctx, service_path,
951 do_log(SMB_VFS_OP_SNAP_CHECK_PATH, NT_STATUS_IS_OK(status),
957 static NTSTATUS smb_full_audit_snap_create(struct vfs_handle_struct *handle,
959 const char *base_volume,
967 status = SMB_VFS_NEXT_SNAP_CREATE(handle, mem_ctx, base_volume, tstamp,
968 rw, base_path, snap_path);
969 do_log(SMB_VFS_OP_SNAP_CREATE, NT_STATUS_IS_OK(status), handle, "");
974 static NTSTATUS smb_full_audit_snap_delete(struct vfs_handle_struct *handle,
981 status = SMB_VFS_NEXT_SNAP_DELETE(handle, mem_ctx, base_path,
983 do_log(SMB_VFS_OP_SNAP_DELETE, NT_STATUS_IS_OK(status), handle, "");
988 static DIR *smb_full_audit_fdopendir(vfs_handle_struct *handle,
989 files_struct *fsp, const char *mask, uint32_t attr)
993 result = SMB_VFS_NEXT_FDOPENDIR(handle, fsp, mask, attr);
995 do_log(SMB_VFS_OP_FDOPENDIR, (result != NULL), handle, "%s",
996 fsp_str_do_log(fsp));
1001 static struct dirent *smb_full_audit_readdir(vfs_handle_struct *handle,
1002 struct files_struct *dirfsp,
1004 SMB_STRUCT_STAT *sbuf)
1006 struct dirent *result;
1008 result = SMB_VFS_NEXT_READDIR(handle, dirfsp, dirp, sbuf);
1010 /* This operation has no reasonable error condition
1011 * (End of dir is also failure), so always succeed.
1013 do_log(SMB_VFS_OP_READDIR, True, handle, "");
1018 static void smb_full_audit_seekdir(vfs_handle_struct *handle,
1019 DIR *dirp, long offset)
1021 SMB_VFS_NEXT_SEEKDIR(handle, dirp, offset);
1023 do_log(SMB_VFS_OP_SEEKDIR, True, handle, "");
1026 static long smb_full_audit_telldir(vfs_handle_struct *handle,
1031 result = SMB_VFS_NEXT_TELLDIR(handle, dirp);
1033 do_log(SMB_VFS_OP_TELLDIR, True, handle, "");
1038 static void smb_full_audit_rewinddir(vfs_handle_struct *handle,
1041 SMB_VFS_NEXT_REWINDDIR(handle, dirp);
1043 do_log(SMB_VFS_OP_REWINDDIR, True, handle, "");
1046 static int smb_full_audit_mkdirat(vfs_handle_struct *handle,
1047 struct files_struct *dirfsp,
1048 const struct smb_filename *smb_fname,
1051 struct smb_filename *full_fname = NULL;
1054 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1057 if (full_fname == NULL) {
1062 result = SMB_VFS_NEXT_MKDIRAT(handle,
1067 do_log(SMB_VFS_OP_MKDIRAT,
1071 smb_fname_str_do_log(handle->conn, full_fname));
1073 TALLOC_FREE(full_fname);
1078 static int smb_full_audit_closedir(vfs_handle_struct *handle,
1083 result = SMB_VFS_NEXT_CLOSEDIR(handle, dirp);
1085 do_log(SMB_VFS_OP_CLOSEDIR, (result >= 0), handle, "");
1090 static int smb_full_audit_openat(vfs_handle_struct *handle,
1091 const struct files_struct *dirfsp,
1092 const struct smb_filename *smb_fname,
1093 struct files_struct *fsp,
1099 result = SMB_VFS_NEXT_OPENAT(handle, dirfsp, smb_fname, fsp, flags, mode);
1101 do_log(SMB_VFS_OP_OPENAT, (result >= 0), handle, "%s|%s",
1102 ((flags & O_WRONLY) || (flags & O_RDWR))?"w":"r",
1103 fsp_str_do_log(fsp));
1108 static NTSTATUS smb_full_audit_create_file(vfs_handle_struct *handle,
1109 struct smb_request *req,
1110 struct smb_filename *smb_fname,
1111 uint32_t access_mask,
1112 uint32_t share_access,
1113 uint32_t create_disposition,
1114 uint32_t create_options,
1115 uint32_t file_attributes,
1116 uint32_t oplock_request,
1117 const struct smb2_lease *lease,
1118 uint64_t allocation_size,
1119 uint32_t private_flags,
1120 struct security_descriptor *sd,
1121 struct ea_list *ea_list,
1122 files_struct **result_fsp,
1124 const struct smb2_create_blobs *in_context_blobs,
1125 struct smb2_create_blobs *out_context_blobs)
1128 const char* str_create_disposition;
1130 switch (create_disposition) {
1131 case FILE_SUPERSEDE:
1132 str_create_disposition = "supersede";
1134 case FILE_OVERWRITE_IF:
1135 str_create_disposition = "overwrite_if";
1138 str_create_disposition = "open";
1140 case FILE_OVERWRITE:
1141 str_create_disposition = "overwrite";
1144 str_create_disposition = "create";
1147 str_create_disposition = "open_if";
1150 str_create_disposition = "unknown";
1153 result = SMB_VFS_NEXT_CREATE_FILE(
1154 handle, /* handle */
1156 smb_fname, /* fname */
1157 access_mask, /* access_mask */
1158 share_access, /* share_access */
1159 create_disposition, /* create_disposition*/
1160 create_options, /* create_options */
1161 file_attributes, /* file_attributes */
1162 oplock_request, /* oplock_request */
1164 allocation_size, /* allocation_size */
1167 ea_list, /* ea_list */
1168 result_fsp, /* result */
1170 in_context_blobs, out_context_blobs); /* create context */
1172 do_log(SMB_VFS_OP_CREATE_FILE, (NT_STATUS_IS_OK(result)), handle,
1173 "0x%x|%s|%s|%s", access_mask,
1174 create_options & FILE_DIRECTORY_FILE ? "dir" : "file",
1175 str_create_disposition,
1176 smb_fname_str_do_log(handle->conn, smb_fname));
1181 static int smb_full_audit_close(vfs_handle_struct *handle, files_struct *fsp)
1185 result = SMB_VFS_NEXT_CLOSE(handle, fsp);
1187 do_log(SMB_VFS_OP_CLOSE, (result >= 0), handle, "%s",
1188 fsp_str_do_log(fsp));
1193 static ssize_t smb_full_audit_pread(vfs_handle_struct *handle, files_struct *fsp,
1194 void *data, size_t n, off_t offset)
1198 result = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
1200 do_log(SMB_VFS_OP_PREAD, (result >= 0), handle, "%s",
1201 fsp_str_do_log(fsp));
1206 struct smb_full_audit_pread_state {
1207 vfs_handle_struct *handle;
1210 struct vfs_aio_state vfs_aio_state;
1213 static void smb_full_audit_pread_done(struct tevent_req *subreq);
1215 static struct tevent_req *smb_full_audit_pread_send(
1216 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1217 struct tevent_context *ev, struct files_struct *fsp,
1218 void *data, size_t n, off_t offset)
1220 struct tevent_req *req, *subreq;
1221 struct smb_full_audit_pread_state *state;
1223 req = tevent_req_create(mem_ctx, &state,
1224 struct smb_full_audit_pread_state);
1226 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
1227 fsp_str_do_log(fsp));
1230 state->handle = handle;
1233 subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
1235 if (tevent_req_nomem(subreq, req)) {
1236 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
1237 fsp_str_do_log(fsp));
1238 return tevent_req_post(req, ev);
1240 tevent_req_set_callback(subreq, smb_full_audit_pread_done, req);
1242 do_log(SMB_VFS_OP_PREAD_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1246 static void smb_full_audit_pread_done(struct tevent_req *subreq)
1248 struct tevent_req *req = tevent_req_callback_data(
1249 subreq, struct tevent_req);
1250 struct smb_full_audit_pread_state *state = tevent_req_data(
1251 req, struct smb_full_audit_pread_state);
1253 state->ret = SMB_VFS_PREAD_RECV(subreq, &state->vfs_aio_state);
1254 TALLOC_FREE(subreq);
1255 tevent_req_done(req);
1258 static ssize_t smb_full_audit_pread_recv(struct tevent_req *req,
1259 struct vfs_aio_state *vfs_aio_state)
1261 struct smb_full_audit_pread_state *state = tevent_req_data(
1262 req, struct smb_full_audit_pread_state);
1264 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1265 do_log(SMB_VFS_OP_PREAD_RECV, false, state->handle, "%s",
1266 fsp_str_do_log(state->fsp));
1270 do_log(SMB_VFS_OP_PREAD_RECV, (state->ret >= 0), state->handle, "%s",
1271 fsp_str_do_log(state->fsp));
1273 *vfs_aio_state = state->vfs_aio_state;
1277 static ssize_t smb_full_audit_pwrite(vfs_handle_struct *handle, files_struct *fsp,
1278 const void *data, size_t n,
1283 result = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
1285 do_log(SMB_VFS_OP_PWRITE, (result >= 0), handle, "%s",
1286 fsp_str_do_log(fsp));
1291 struct smb_full_audit_pwrite_state {
1292 vfs_handle_struct *handle;
1295 struct vfs_aio_state vfs_aio_state;
1298 static void smb_full_audit_pwrite_done(struct tevent_req *subreq);
1300 static struct tevent_req *smb_full_audit_pwrite_send(
1301 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1302 struct tevent_context *ev, struct files_struct *fsp,
1303 const void *data, size_t n, off_t offset)
1305 struct tevent_req *req, *subreq;
1306 struct smb_full_audit_pwrite_state *state;
1308 req = tevent_req_create(mem_ctx, &state,
1309 struct smb_full_audit_pwrite_state);
1311 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1312 fsp_str_do_log(fsp));
1315 state->handle = handle;
1318 subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
1320 if (tevent_req_nomem(subreq, req)) {
1321 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1322 fsp_str_do_log(fsp));
1323 return tevent_req_post(req, ev);
1325 tevent_req_set_callback(subreq, smb_full_audit_pwrite_done, req);
1327 do_log(SMB_VFS_OP_PWRITE_SEND, true, handle, "%s",
1328 fsp_str_do_log(fsp));
1332 static void smb_full_audit_pwrite_done(struct tevent_req *subreq)
1334 struct tevent_req *req = tevent_req_callback_data(
1335 subreq, struct tevent_req);
1336 struct smb_full_audit_pwrite_state *state = tevent_req_data(
1337 req, struct smb_full_audit_pwrite_state);
1339 state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->vfs_aio_state);
1340 TALLOC_FREE(subreq);
1341 tevent_req_done(req);
1344 static ssize_t smb_full_audit_pwrite_recv(struct tevent_req *req,
1345 struct vfs_aio_state *vfs_aio_state)
1347 struct smb_full_audit_pwrite_state *state = tevent_req_data(
1348 req, struct smb_full_audit_pwrite_state);
1350 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1351 do_log(SMB_VFS_OP_PWRITE_RECV, false, state->handle, "%s",
1352 fsp_str_do_log(state->fsp));
1356 do_log(SMB_VFS_OP_PWRITE_RECV, (state->ret >= 0), state->handle, "%s",
1357 fsp_str_do_log(state->fsp));
1359 *vfs_aio_state = state->vfs_aio_state;
1363 static off_t smb_full_audit_lseek(vfs_handle_struct *handle, files_struct *fsp,
1364 off_t offset, int whence)
1368 result = SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence);
1370 do_log(SMB_VFS_OP_LSEEK, (result != (ssize_t)-1), handle,
1371 "%s", fsp_str_do_log(fsp));
1376 static ssize_t smb_full_audit_sendfile(vfs_handle_struct *handle, int tofd,
1377 files_struct *fromfsp,
1378 const DATA_BLOB *hdr, off_t offset,
1383 result = SMB_VFS_NEXT_SENDFILE(handle, tofd, fromfsp, hdr, offset, n);
1385 do_log(SMB_VFS_OP_SENDFILE, (result >= 0), handle,
1386 "%s", fsp_str_do_log(fromfsp));
1391 static ssize_t smb_full_audit_recvfile(vfs_handle_struct *handle, int fromfd,
1392 files_struct *tofsp,
1398 result = SMB_VFS_NEXT_RECVFILE(handle, fromfd, tofsp, offset, n);
1400 do_log(SMB_VFS_OP_RECVFILE, (result >= 0), handle,
1401 "%s", fsp_str_do_log(tofsp));
1406 static int smb_full_audit_renameat(vfs_handle_struct *handle,
1407 files_struct *srcfsp,
1408 const struct smb_filename *smb_fname_src,
1409 files_struct *dstfsp,
1410 const struct smb_filename *smb_fname_dst)
1414 struct smb_filename *full_fname_src = NULL;
1415 struct smb_filename *full_fname_dst = NULL;
1417 full_fname_src = full_path_from_dirfsp_atname(talloc_tos(),
1420 if (full_fname_src == NULL) {
1424 full_fname_dst = full_path_from_dirfsp_atname(talloc_tos(),
1427 if (full_fname_dst == NULL) {
1428 TALLOC_FREE(full_fname_src);
1433 result = SMB_VFS_NEXT_RENAMEAT(handle,
1440 saved_errno = errno;
1442 do_log(SMB_VFS_OP_RENAMEAT, (result >= 0), handle, "%s|%s",
1443 smb_fname_str_do_log(handle->conn, full_fname_src),
1444 smb_fname_str_do_log(handle->conn, full_fname_dst));
1446 TALLOC_FREE(full_fname_src);
1447 TALLOC_FREE(full_fname_dst);
1450 errno = saved_errno;
1455 struct smb_full_audit_fsync_state {
1456 vfs_handle_struct *handle;
1459 struct vfs_aio_state vfs_aio_state;
1462 static void smb_full_audit_fsync_done(struct tevent_req *subreq);
1464 static struct tevent_req *smb_full_audit_fsync_send(
1465 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1466 struct tevent_context *ev, struct files_struct *fsp)
1468 struct tevent_req *req, *subreq;
1469 struct smb_full_audit_fsync_state *state;
1471 req = tevent_req_create(mem_ctx, &state,
1472 struct smb_full_audit_fsync_state);
1474 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1475 fsp_str_do_log(fsp));
1478 state->handle = handle;
1481 subreq = SMB_VFS_NEXT_FSYNC_SEND(state, ev, handle, fsp);
1482 if (tevent_req_nomem(subreq, req)) {
1483 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1484 fsp_str_do_log(fsp));
1485 return tevent_req_post(req, ev);
1487 tevent_req_set_callback(subreq, smb_full_audit_fsync_done, req);
1489 do_log(SMB_VFS_OP_FSYNC_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1493 static void smb_full_audit_fsync_done(struct tevent_req *subreq)
1495 struct tevent_req *req = tevent_req_callback_data(
1496 subreq, struct tevent_req);
1497 struct smb_full_audit_fsync_state *state = tevent_req_data(
1498 req, struct smb_full_audit_fsync_state);
1500 state->ret = SMB_VFS_FSYNC_RECV(subreq, &state->vfs_aio_state);
1501 TALLOC_FREE(subreq);
1502 tevent_req_done(req);
1505 static int smb_full_audit_fsync_recv(struct tevent_req *req,
1506 struct vfs_aio_state *vfs_aio_state)
1508 struct smb_full_audit_fsync_state *state = tevent_req_data(
1509 req, struct smb_full_audit_fsync_state);
1511 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1512 do_log(SMB_VFS_OP_FSYNC_RECV, false, state->handle, "%s",
1513 fsp_str_do_log(state->fsp));
1517 do_log(SMB_VFS_OP_FSYNC_RECV, (state->ret >= 0), state->handle, "%s",
1518 fsp_str_do_log(state->fsp));
1520 *vfs_aio_state = state->vfs_aio_state;
1524 static int smb_full_audit_stat(vfs_handle_struct *handle,
1525 struct smb_filename *smb_fname)
1529 result = SMB_VFS_NEXT_STAT(handle, smb_fname);
1531 do_log(SMB_VFS_OP_STAT, (result >= 0), handle, "%s",
1532 smb_fname_str_do_log(handle->conn, smb_fname));
1537 static int smb_full_audit_fstat(vfs_handle_struct *handle, files_struct *fsp,
1538 SMB_STRUCT_STAT *sbuf)
1542 result = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1544 do_log(SMB_VFS_OP_FSTAT, (result >= 0), handle, "%s",
1545 fsp_str_do_log(fsp));
1550 static int smb_full_audit_lstat(vfs_handle_struct *handle,
1551 struct smb_filename *smb_fname)
1555 result = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
1557 do_log(SMB_VFS_OP_LSTAT, (result >= 0), handle, "%s",
1558 smb_fname_str_do_log(handle->conn, smb_fname));
1563 static uint64_t smb_full_audit_get_alloc_size(vfs_handle_struct *handle,
1564 files_struct *fsp, const SMB_STRUCT_STAT *sbuf)
1568 result = SMB_VFS_NEXT_GET_ALLOC_SIZE(handle, fsp, sbuf);
1570 do_log(SMB_VFS_OP_GET_ALLOC_SIZE, (result != (uint64_t)-1), handle,
1571 "%llu", (unsigned long long)result);
1576 static int smb_full_audit_unlinkat(vfs_handle_struct *handle,
1577 struct files_struct *dirfsp,
1578 const struct smb_filename *smb_fname,
1581 struct smb_filename *full_fname = NULL;
1584 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1587 if (full_fname == NULL) {
1591 result = SMB_VFS_NEXT_UNLINKAT(handle,
1596 do_log(SMB_VFS_OP_UNLINKAT, (result >= 0), handle, "%s",
1597 smb_fname_str_do_log(handle->conn, full_fname));
1599 TALLOC_FREE(full_fname);
1603 static int smb_full_audit_fchmod(vfs_handle_struct *handle, files_struct *fsp,
1608 result = SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1610 do_log(SMB_VFS_OP_FCHMOD, (result >= 0), handle,
1611 "%s|%o", fsp_str_do_log(fsp), mode);
1616 static int smb_full_audit_fchown(vfs_handle_struct *handle, files_struct *fsp,
1617 uid_t uid, gid_t gid)
1621 result = SMB_VFS_NEXT_FCHOWN(handle, fsp, uid, gid);
1623 do_log(SMB_VFS_OP_FCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1624 fsp_str_do_log(fsp), (long int)uid, (long int)gid);
1629 static int smb_full_audit_lchown(vfs_handle_struct *handle,
1630 const struct smb_filename *smb_fname,
1636 result = SMB_VFS_NEXT_LCHOWN(handle, smb_fname, uid, gid);
1638 do_log(SMB_VFS_OP_LCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1639 smb_fname->base_name, (long int)uid, (long int)gid);
1644 static int smb_full_audit_chdir(vfs_handle_struct *handle,
1645 const struct smb_filename *smb_fname)
1649 result = SMB_VFS_NEXT_CHDIR(handle, smb_fname);
1651 do_log(SMB_VFS_OP_CHDIR,
1655 smb_fname_str_do_log(handle->conn, smb_fname));
1660 static struct smb_filename *smb_full_audit_getwd(vfs_handle_struct *handle,
1663 struct smb_filename *result;
1665 result = SMB_VFS_NEXT_GETWD(handle, ctx);
1667 do_log(SMB_VFS_OP_GETWD, (result != NULL), handle, "%s",
1668 result == NULL? "" : result->base_name);
1673 static int smb_full_audit_fntimes(vfs_handle_struct *handle,
1675 struct smb_file_time *ft)
1678 time_t create_time = convert_timespec_to_time_t(ft->create_time);
1679 time_t atime = convert_timespec_to_time_t(ft->atime);
1680 time_t mtime = convert_timespec_to_time_t(ft->mtime);
1681 time_t ctime = convert_timespec_to_time_t(ft->ctime);
1682 const char *create_time_str = "";
1683 const char *atime_str = "";
1684 const char *mtime_str = "";
1685 const char *ctime_str = "";
1686 TALLOC_CTX *frame = talloc_stackframe();
1688 if (frame == NULL) {
1693 result = SMB_VFS_NEXT_FNTIMES(handle, fsp, ft);
1695 if (create_time > 0) {
1696 create_time_str = timestring(frame, create_time);
1699 atime_str = timestring(frame, atime);
1702 mtime_str = timestring(frame, mtime);
1705 ctime_str = timestring(frame, ctime);
1708 do_log(SMB_VFS_OP_FNTIMES,
1712 fsp_str_do_log(fsp),
1723 static int smb_full_audit_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
1728 result = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1730 do_log(SMB_VFS_OP_FTRUNCATE, (result >= 0), handle,
1731 "%s", fsp_str_do_log(fsp));
1736 static int smb_full_audit_fallocate(vfs_handle_struct *handle, files_struct *fsp,
1743 result = SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
1745 do_log(SMB_VFS_OP_FALLOCATE, (result >= 0), handle,
1746 "%s", fsp_str_do_log(fsp));
1751 static bool smb_full_audit_lock(vfs_handle_struct *handle, files_struct *fsp,
1752 int op, off_t offset, off_t count, int type)
1756 result = SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type);
1758 do_log(SMB_VFS_OP_LOCK, result, handle, "%s", fsp_str_do_log(fsp));
1763 static int smb_full_audit_kernel_flock(struct vfs_handle_struct *handle,
1764 struct files_struct *fsp,
1765 uint32_t share_access,
1766 uint32_t access_mask)
1770 result = SMB_VFS_NEXT_KERNEL_FLOCK(handle,
1775 do_log(SMB_VFS_OP_KERNEL_FLOCK, (result >= 0), handle, "%s",
1776 fsp_str_do_log(fsp));
1781 static int smb_full_audit_fcntl(struct vfs_handle_struct *handle,
1782 struct files_struct *fsp,
1783 int cmd, va_list cmd_arg)
1786 va_list dup_cmd_arg;
1789 va_copy(dup_cmd_arg, cmd_arg);
1790 arg = va_arg(dup_cmd_arg, void *);
1791 result = SMB_VFS_NEXT_FCNTL(handle, fsp, cmd, arg);
1792 va_end(dup_cmd_arg);
1794 do_log(SMB_VFS_OP_FCNTL, (result >= 0), handle, "%s",
1795 fsp_str_do_log(fsp));
1800 static int smb_full_audit_linux_setlease(vfs_handle_struct *handle, files_struct *fsp,
1805 result = SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
1807 do_log(SMB_VFS_OP_LINUX_SETLEASE, (result >= 0), handle, "%s",
1808 fsp_str_do_log(fsp));
1813 static bool smb_full_audit_getlock(vfs_handle_struct *handle, files_struct *fsp,
1814 off_t *poffset, off_t *pcount, int *ptype, pid_t *ppid)
1818 result = SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype, ppid);
1820 do_log(SMB_VFS_OP_GETLOCK, result, handle, "%s", fsp_str_do_log(fsp));
1825 static int smb_full_audit_symlinkat(vfs_handle_struct *handle,
1826 const struct smb_filename *link_contents,
1827 struct files_struct *dirfsp,
1828 const struct smb_filename *new_smb_fname)
1830 struct smb_filename *full_fname = NULL;
1833 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1836 if (full_fname == NULL) {
1840 result = SMB_VFS_NEXT_SYMLINKAT(handle,
1845 do_log(SMB_VFS_OP_SYMLINKAT,
1849 link_contents->base_name,
1850 smb_fname_str_do_log(handle->conn, full_fname));
1852 TALLOC_FREE(full_fname);
1857 static int smb_full_audit_readlinkat(vfs_handle_struct *handle,
1858 const struct files_struct *dirfsp,
1859 const struct smb_filename *smb_fname,
1863 struct smb_filename *full_fname = NULL;
1866 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1869 if (full_fname == NULL) {
1873 result = SMB_VFS_NEXT_READLINKAT(handle,
1879 do_log(SMB_VFS_OP_READLINKAT,
1883 smb_fname_str_do_log(handle->conn, full_fname));
1885 TALLOC_FREE(full_fname);
1890 static int smb_full_audit_linkat(vfs_handle_struct *handle,
1891 files_struct *srcfsp,
1892 const struct smb_filename *old_smb_fname,
1893 files_struct *dstfsp,
1894 const struct smb_filename *new_smb_fname,
1897 struct smb_filename *old_full_fname = NULL;
1898 struct smb_filename *new_full_fname = NULL;
1901 old_full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1904 if (old_full_fname == NULL) {
1907 new_full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1910 if (new_full_fname == NULL) {
1911 TALLOC_FREE(old_full_fname);
1914 result = SMB_VFS_NEXT_LINKAT(handle,
1921 do_log(SMB_VFS_OP_LINKAT,
1925 smb_fname_str_do_log(handle->conn, old_full_fname),
1926 smb_fname_str_do_log(handle->conn, new_full_fname));
1928 TALLOC_FREE(old_full_fname);
1929 TALLOC_FREE(new_full_fname);
1934 static int smb_full_audit_mknodat(vfs_handle_struct *handle,
1935 files_struct *dirfsp,
1936 const struct smb_filename *smb_fname,
1940 struct smb_filename *full_fname = NULL;
1943 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1946 if (full_fname == NULL) {
1950 result = SMB_VFS_NEXT_MKNODAT(handle,
1956 do_log(SMB_VFS_OP_MKNODAT,
1960 smb_fname_str_do_log(handle->conn, full_fname));
1962 TALLOC_FREE(full_fname);
1967 static struct smb_filename *smb_full_audit_realpath(vfs_handle_struct *handle,
1969 const struct smb_filename *smb_fname)
1971 struct smb_filename *result_fname = NULL;
1973 result_fname = SMB_VFS_NEXT_REALPATH(handle, ctx, smb_fname);
1975 do_log(SMB_VFS_OP_REALPATH,
1976 (result_fname != NULL),
1979 smb_fname_str_do_log(handle->conn, smb_fname));
1981 return result_fname;
1984 static int smb_full_audit_chflags(vfs_handle_struct *handle,
1985 const struct smb_filename *smb_fname,
1990 result = SMB_VFS_NEXT_CHFLAGS(handle, smb_fname, flags);
1992 do_log(SMB_VFS_OP_CHFLAGS,
1996 smb_fname_str_do_log(handle->conn, smb_fname));
2001 static struct file_id smb_full_audit_file_id_create(struct vfs_handle_struct *handle,
2002 const SMB_STRUCT_STAT *sbuf)
2004 struct file_id id_zero = { 0 };
2005 struct file_id result;
2006 struct file_id_buf idbuf;
2008 result = SMB_VFS_NEXT_FILE_ID_CREATE(handle, sbuf);
2010 do_log(SMB_VFS_OP_FILE_ID_CREATE,
2011 !file_id_equal(&id_zero, &result),
2014 file_id_str_buf(result, &idbuf));
2019 static uint64_t smb_full_audit_fs_file_id(struct vfs_handle_struct *handle,
2020 const SMB_STRUCT_STAT *sbuf)
2024 result = SMB_VFS_NEXT_FS_FILE_ID(handle, sbuf);
2026 do_log(SMB_VFS_OP_FS_FILE_ID,
2028 handle, "%" PRIu64, result);
2033 static NTSTATUS smb_full_audit_fstreaminfo(vfs_handle_struct *handle,
2034 struct files_struct *fsp,
2035 TALLOC_CTX *mem_ctx,
2036 unsigned int *pnum_streams,
2037 struct stream_struct **pstreams)
2041 result = SMB_VFS_NEXT_FSTREAMINFO(handle, fsp, mem_ctx,
2042 pnum_streams, pstreams);
2044 do_log(SMB_VFS_OP_FSTREAMINFO,
2045 NT_STATUS_IS_OK(result),
2048 smb_fname_str_do_log(handle->conn, fsp->fsp_name));
2053 static int smb_full_audit_get_real_filename(struct vfs_handle_struct *handle,
2054 const struct smb_filename *path,
2056 TALLOC_CTX *mem_ctx,
2061 result = SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name, mem_ctx,
2064 do_log(SMB_VFS_OP_GET_REAL_FILENAME, (result == 0), handle,
2066 path->base_name, name, (result == 0) ? *found_name : "");
2071 static const char *smb_full_audit_connectpath(vfs_handle_struct *handle,
2072 const struct smb_filename *smb_fname)
2076 result = SMB_VFS_NEXT_CONNECTPATH(handle, smb_fname);
2078 do_log(SMB_VFS_OP_CONNECTPATH,
2082 smb_fname_str_do_log(handle->conn, smb_fname));
2087 static NTSTATUS smb_full_audit_brl_lock_windows(struct vfs_handle_struct *handle,
2088 struct byte_range_lock *br_lck,
2089 struct lock_struct *plock)
2093 result = SMB_VFS_NEXT_BRL_LOCK_WINDOWS(handle, br_lck, plock);
2095 do_log(SMB_VFS_OP_BRL_LOCK_WINDOWS, NT_STATUS_IS_OK(result), handle,
2096 "%s:%llu-%llu. type=%d.",
2097 fsp_str_do_log(brl_fsp(br_lck)),
2098 (unsigned long long)plock->start,
2099 (unsigned long long)plock->size,
2105 static bool smb_full_audit_brl_unlock_windows(struct vfs_handle_struct *handle,
2106 struct byte_range_lock *br_lck,
2107 const struct lock_struct *plock)
2111 result = SMB_VFS_NEXT_BRL_UNLOCK_WINDOWS(handle, br_lck, plock);
2113 do_log(SMB_VFS_OP_BRL_UNLOCK_WINDOWS, (result == 0), handle,
2114 "%s:%llu-%llu:%d", fsp_str_do_log(brl_fsp(br_lck)),
2115 (unsigned long long)plock->start,
2116 (unsigned long long)plock->size,
2122 static bool smb_full_audit_strict_lock_check(struct vfs_handle_struct *handle,
2123 struct files_struct *fsp,
2124 struct lock_struct *plock)
2128 result = SMB_VFS_NEXT_STRICT_LOCK_CHECK(handle, fsp, plock);
2130 do_log(SMB_VFS_OP_STRICT_LOCK_CHECK, result, handle,
2131 "%s:%llu-%llu:%d", fsp_str_do_log(fsp),
2132 (unsigned long long)plock->start,
2133 (unsigned long long)plock->size,
2139 static NTSTATUS smb_full_audit_translate_name(struct vfs_handle_struct *handle,
2141 enum vfs_translate_direction direction,
2142 TALLOC_CTX *mem_ctx,
2147 result = SMB_VFS_NEXT_TRANSLATE_NAME(handle, name, direction, mem_ctx,
2150 do_log(SMB_VFS_OP_TRANSLATE_NAME, NT_STATUS_IS_OK(result), handle, "");
2155 static NTSTATUS smb_full_audit_parent_pathname(struct vfs_handle_struct *handle,
2156 TALLOC_CTX *mem_ctx,
2157 const struct smb_filename *smb_fname_in,
2158 struct smb_filename **parent_dir_out,
2159 struct smb_filename **atname_out)
2163 result = SMB_VFS_NEXT_PARENT_PATHNAME(handle,
2168 do_log(SMB_VFS_OP_CONNECTPATH,
2169 NT_STATUS_IS_OK(result),
2172 smb_fname_str_do_log(handle->conn, smb_fname_in));
2177 static NTSTATUS smb_full_audit_fsctl(struct vfs_handle_struct *handle,
2178 struct files_struct *fsp,
2182 const uint8_t *_in_data,
2184 uint8_t **_out_data,
2185 uint32_t max_out_len,
2190 result = SMB_VFS_NEXT_FSCTL(handle,
2201 do_log(SMB_VFS_OP_FSCTL, NT_STATUS_IS_OK(result), handle, "");
2206 static struct tevent_req *smb_full_audit_offload_read_send(
2207 TALLOC_CTX *mem_ctx,
2208 struct tevent_context *ev,
2209 struct vfs_handle_struct *handle,
2210 struct files_struct *fsp,
2216 struct tevent_req *req = NULL;
2218 req = SMB_VFS_NEXT_OFFLOAD_READ_SEND(mem_ctx, ev, handle, fsp,
2219 fsctl, ttl, offset, to_copy);
2221 do_log(SMB_VFS_OP_OFFLOAD_READ_SEND, req, handle, "");
2226 static NTSTATUS smb_full_audit_offload_read_recv(
2227 struct tevent_req *req,
2228 struct vfs_handle_struct *handle,
2229 TALLOC_CTX *mem_ctx,
2230 DATA_BLOB *_token_blob)
2234 status = SMB_VFS_NEXT_OFFLOAD_READ_RECV(req, handle, mem_ctx,
2237 do_log(SMB_VFS_OP_OFFLOAD_READ_RECV, NT_STATUS_IS_OK(status), handle, "");
2242 static struct tevent_req *smb_full_audit_offload_write_send(struct vfs_handle_struct *handle,
2243 TALLOC_CTX *mem_ctx,
2244 struct tevent_context *ev,
2247 off_t transfer_offset,
2248 struct files_struct *dest_fsp,
2252 struct tevent_req *req;
2254 req = SMB_VFS_NEXT_OFFLOAD_WRITE_SEND(handle, mem_ctx, ev,
2255 fsctl, token, transfer_offset,
2256 dest_fsp, dest_off, num);
2258 do_log(SMB_VFS_OP_OFFLOAD_WRITE_SEND, req, handle, "");
2263 static NTSTATUS smb_full_audit_offload_write_recv(struct vfs_handle_struct *handle,
2264 struct tevent_req *req,
2269 result = SMB_VFS_NEXT_OFFLOAD_WRITE_RECV(handle, req, copied);
2271 do_log(SMB_VFS_OP_OFFLOAD_WRITE_RECV, NT_STATUS_IS_OK(result), handle, "");
2276 static NTSTATUS smb_full_audit_fget_compression(vfs_handle_struct *handle,
2277 TALLOC_CTX *mem_ctx,
2278 struct files_struct *fsp,
2279 uint16_t *_compression_fmt)
2283 result = SMB_VFS_NEXT_FGET_COMPRESSION(handle, mem_ctx, fsp,
2286 do_log(SMB_VFS_OP_FGET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
2288 fsp_str_do_log(fsp));
2293 static NTSTATUS smb_full_audit_set_compression(vfs_handle_struct *handle,
2294 TALLOC_CTX *mem_ctx,
2295 struct files_struct *fsp,
2296 uint16_t compression_fmt)
2300 result = SMB_VFS_NEXT_SET_COMPRESSION(handle, mem_ctx, fsp,
2303 do_log(SMB_VFS_OP_SET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
2304 "%s", fsp_str_do_log(fsp));
2309 static NTSTATUS smb_full_audit_freaddir_attr(struct vfs_handle_struct *handle,
2310 struct files_struct *fsp,
2311 TALLOC_CTX *mem_ctx,
2312 struct readdir_attr_data **pattr_data)
2316 status = SMB_VFS_NEXT_FREADDIR_ATTR(handle, fsp, mem_ctx, pattr_data);
2318 do_log(SMB_VFS_OP_FREADDIR_ATTR,
2319 NT_STATUS_IS_OK(status),
2322 fsp_str_do_log(fsp));
2327 struct smb_full_audit_get_dos_attributes_state {
2328 struct vfs_aio_state aio_state;
2329 vfs_handle_struct *handle;
2330 files_struct *dir_fsp;
2331 const struct smb_filename *smb_fname;
2335 static void smb_full_audit_get_dos_attributes_done(struct tevent_req *subreq);
2337 static struct tevent_req *smb_full_audit_get_dos_attributes_send(
2338 TALLOC_CTX *mem_ctx,
2339 struct tevent_context *ev,
2340 struct vfs_handle_struct *handle,
2341 files_struct *dir_fsp,
2342 struct smb_filename *smb_fname)
2344 struct tevent_req *req = NULL;
2345 struct smb_full_audit_get_dos_attributes_state *state = NULL;
2346 struct tevent_req *subreq = NULL;
2348 req = tevent_req_create(mem_ctx, &state,
2349 struct smb_full_audit_get_dos_attributes_state);
2351 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2355 fsp_str_do_log(dir_fsp),
2356 smb_fname->base_name);
2359 *state = (struct smb_full_audit_get_dos_attributes_state) {
2362 .smb_fname = smb_fname,
2365 subreq = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES_SEND(mem_ctx,
2370 if (tevent_req_nomem(subreq, req)) {
2371 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2375 fsp_str_do_log(dir_fsp),
2376 smb_fname->base_name);
2377 return tevent_req_post(req, ev);
2379 tevent_req_set_callback(subreq,
2380 smb_full_audit_get_dos_attributes_done,
2383 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2387 fsp_str_do_log(dir_fsp),
2388 smb_fname->base_name);
2393 static void smb_full_audit_get_dos_attributes_done(struct tevent_req *subreq)
2395 struct tevent_req *req =
2396 tevent_req_callback_data(subreq,
2398 struct smb_full_audit_get_dos_attributes_state *state =
2399 tevent_req_data(req,
2400 struct smb_full_audit_get_dos_attributes_state);
2403 status = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES_RECV(subreq,
2406 TALLOC_FREE(subreq);
2407 if (tevent_req_nterror(req, status)) {
2411 tevent_req_done(req);
2415 static NTSTATUS smb_full_audit_get_dos_attributes_recv(struct tevent_req *req,
2416 struct vfs_aio_state *aio_state,
2419 struct smb_full_audit_get_dos_attributes_state *state =
2420 tevent_req_data(req,
2421 struct smb_full_audit_get_dos_attributes_state);
2424 if (tevent_req_is_nterror(req, &status)) {
2425 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV,
2429 fsp_str_do_log(state->dir_fsp),
2430 state->smb_fname->base_name);
2431 tevent_req_received(req);
2435 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV,
2439 fsp_str_do_log(state->dir_fsp),
2440 state->smb_fname->base_name);
2442 *aio_state = state->aio_state;
2443 *dosmode = state->dosmode;
2444 tevent_req_received(req);
2445 return NT_STATUS_OK;
2448 static NTSTATUS smb_full_audit_fget_dos_attributes(
2449 struct vfs_handle_struct *handle,
2450 struct files_struct *fsp,
2455 status = SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle,
2459 do_log(SMB_VFS_OP_FGET_DOS_ATTRIBUTES,
2460 NT_STATUS_IS_OK(status),
2463 fsp_str_do_log(fsp));
2468 static NTSTATUS smb_full_audit_fset_dos_attributes(
2469 struct vfs_handle_struct *handle,
2470 struct files_struct *fsp,
2475 status = SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle,
2479 do_log(SMB_VFS_OP_FSET_DOS_ATTRIBUTES,
2480 NT_STATUS_IS_OK(status),
2483 fsp_str_do_log(fsp));
2488 static NTSTATUS smb_full_audit_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
2489 uint32_t security_info,
2490 TALLOC_CTX *mem_ctx,
2491 struct security_descriptor **ppdesc)
2495 result = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
2498 do_log(SMB_VFS_OP_FGET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2499 "%s", fsp_str_do_log(fsp));
2504 static NTSTATUS smb_full_audit_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
2505 uint32_t security_info_sent,
2506 const struct security_descriptor *psd)
2508 struct vfs_full_audit_private_data *pd;
2512 SMB_VFS_HANDLE_GET_DATA(handle, pd,
2513 struct vfs_full_audit_private_data,
2514 return NT_STATUS_INTERNAL_ERROR);
2516 if (pd->log_secdesc) {
2517 sd = sddl_encode(talloc_tos(), psd, get_global_sam_sid());
2520 result = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
2522 do_log(SMB_VFS_OP_FSET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2523 "%s [%s]", fsp_str_do_log(fsp), sd ? sd : "");
2530 static NTSTATUS smb_full_audit_audit_file(struct vfs_handle_struct *handle,
2531 struct smb_filename *file,
2532 struct security_acl *sacl,
2533 uint32_t access_requested,
2534 uint32_t access_denied)
2538 result = SMB_VFS_NEXT_AUDIT_FILE(handle,
2544 do_log(SMB_VFS_OP_AUDIT_FILE, NT_STATUS_IS_OK(result), handle,
2546 smb_fname_str_do_log(handle->conn, file));
2551 static SMB_ACL_T smb_full_audit_sys_acl_get_fd(vfs_handle_struct *handle,
2553 SMB_ACL_TYPE_T type,
2554 TALLOC_CTX *mem_ctx)
2558 result = SMB_VFS_NEXT_SYS_ACL_GET_FD(handle,
2563 do_log(SMB_VFS_OP_SYS_ACL_GET_FD, (result != NULL), handle,
2564 "%s", fsp_str_do_log(fsp));
2569 static int smb_full_audit_sys_acl_blob_get_fd(vfs_handle_struct *handle,
2571 TALLOC_CTX *mem_ctx,
2572 char **blob_description,
2577 result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle, fsp, mem_ctx, blob_description, blob);
2579 do_log(SMB_VFS_OP_SYS_ACL_BLOB_GET_FD, (result >= 0), handle,
2580 "%s", fsp_str_do_log(fsp));
2585 static int smb_full_audit_sys_acl_set_fd(vfs_handle_struct *handle,
2586 struct files_struct *fsp,
2587 SMB_ACL_TYPE_T type,
2592 result = SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, type, theacl);
2594 do_log(SMB_VFS_OP_SYS_ACL_SET_FD, (result >= 0), handle,
2595 "%s", fsp_str_do_log(fsp));
2600 static int smb_full_audit_sys_acl_delete_def_fd(vfs_handle_struct *handle,
2601 struct files_struct *fsp)
2605 result = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FD(handle, fsp);
2607 do_log(SMB_VFS_OP_SYS_ACL_DELETE_DEF_FD,
2611 fsp_str_do_log(fsp));
2616 static ssize_t smb_full_audit_getxattr(struct vfs_handle_struct *handle,
2617 const struct smb_filename *smb_fname,
2618 const char *name, void *value, size_t size)
2622 result = SMB_VFS_NEXT_GETXATTR(handle, smb_fname, name, value, size);
2624 do_log(SMB_VFS_OP_GETXATTR,
2628 smb_fname_str_do_log(handle->conn, smb_fname),
2634 struct smb_full_audit_getxattrat_state {
2635 struct vfs_aio_state aio_state;
2636 vfs_handle_struct *handle;
2637 files_struct *dir_fsp;
2638 const struct smb_filename *smb_fname;
2639 const char *xattr_name;
2641 uint8_t *xattr_value;
2644 static void smb_full_audit_getxattrat_done(struct tevent_req *subreq);
2646 static struct tevent_req *smb_full_audit_getxattrat_send(
2647 TALLOC_CTX *mem_ctx,
2648 struct tevent_context *ev,
2649 struct vfs_handle_struct *handle,
2650 files_struct *dir_fsp,
2651 const struct smb_filename *smb_fname,
2652 const char *xattr_name,
2655 struct tevent_req *req = NULL;
2656 struct tevent_req *subreq = NULL;
2657 struct smb_full_audit_getxattrat_state *state = NULL;
2659 req = tevent_req_create(mem_ctx, &state,
2660 struct smb_full_audit_getxattrat_state);
2662 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2666 fsp_str_do_log(dir_fsp),
2667 smb_fname->base_name,
2671 *state = (struct smb_full_audit_getxattrat_state) {
2674 .smb_fname = smb_fname,
2675 .xattr_name = xattr_name,
2678 subreq = SMB_VFS_NEXT_GETXATTRAT_SEND(state,
2685 if (tevent_req_nomem(subreq, req)) {
2686 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2690 fsp_str_do_log(dir_fsp),
2691 smb_fname->base_name,
2693 return tevent_req_post(req, ev);
2695 tevent_req_set_callback(subreq, smb_full_audit_getxattrat_done, req);
2697 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2701 fsp_str_do_log(dir_fsp),
2702 smb_fname->base_name,
2708 static void smb_full_audit_getxattrat_done(struct tevent_req *subreq)
2710 struct tevent_req *req = tevent_req_callback_data(
2711 subreq, struct tevent_req);
2712 struct smb_full_audit_getxattrat_state *state = tevent_req_data(
2713 req, struct smb_full_audit_getxattrat_state);
2715 state->xattr_size = SMB_VFS_NEXT_GETXATTRAT_RECV(subreq,
2718 &state->xattr_value);
2719 TALLOC_FREE(subreq);
2720 if (state->xattr_size == -1) {
2721 tevent_req_error(req, state->aio_state.error);
2725 tevent_req_done(req);
2728 static ssize_t smb_full_audit_getxattrat_recv(struct tevent_req *req,
2729 struct vfs_aio_state *aio_state,
2730 TALLOC_CTX *mem_ctx,
2731 uint8_t **xattr_value)
2733 struct smb_full_audit_getxattrat_state *state = tevent_req_data(
2734 req, struct smb_full_audit_getxattrat_state);
2737 if (tevent_req_is_unix_error(req, &aio_state->error)) {
2738 do_log(SMB_VFS_OP_GETXATTRAT_RECV,
2742 fsp_str_do_log(state->dir_fsp),
2743 state->smb_fname->base_name,
2745 tevent_req_received(req);
2749 do_log(SMB_VFS_OP_GETXATTRAT_RECV,
2753 fsp_str_do_log(state->dir_fsp),
2754 state->smb_fname->base_name,
2757 *aio_state = state->aio_state;
2758 xattr_size = state->xattr_size;
2759 if (xattr_value != NULL) {
2760 *xattr_value = talloc_move(mem_ctx, &state->xattr_value);
2763 tevent_req_received(req);
2767 static ssize_t smb_full_audit_fgetxattr(struct vfs_handle_struct *handle,
2768 struct files_struct *fsp,
2769 const char *name, void *value, size_t size)
2773 result = SMB_VFS_NEXT_FGETXATTR(handle, fsp, name, value, size);
2775 do_log(SMB_VFS_OP_FGETXATTR, (result >= 0), handle,
2776 "%s|%s", fsp_str_do_log(fsp), name);
2781 static ssize_t smb_full_audit_flistxattr(struct vfs_handle_struct *handle,
2782 struct files_struct *fsp, char *list,
2787 result = SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
2789 do_log(SMB_VFS_OP_FLISTXATTR, (result >= 0), handle,
2790 "%s", fsp_str_do_log(fsp));
2795 static int smb_full_audit_fremovexattr(struct vfs_handle_struct *handle,
2796 struct files_struct *fsp,
2801 result = SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, name);
2803 do_log(SMB_VFS_OP_FREMOVEXATTR, (result >= 0), handle,
2804 "%s|%s", fsp_str_do_log(fsp), name);
2809 static int smb_full_audit_fsetxattr(struct vfs_handle_struct *handle,
2810 struct files_struct *fsp, const char *name,
2811 const void *value, size_t size, int flags)
2815 result = SMB_VFS_NEXT_FSETXATTR(handle, fsp, name, value, size, flags);
2817 do_log(SMB_VFS_OP_FSETXATTR, (result >= 0), handle,
2818 "%s|%s", fsp_str_do_log(fsp), name);
2823 static bool smb_full_audit_aio_force(struct vfs_handle_struct *handle,
2824 struct files_struct *fsp)
2828 result = SMB_VFS_NEXT_AIO_FORCE(handle, fsp);
2829 do_log(SMB_VFS_OP_AIO_FORCE, result, handle,
2830 "%s", fsp_str_do_log(fsp));
2835 static NTSTATUS smb_full_audit_durable_cookie(struct vfs_handle_struct *handle,
2836 struct files_struct *fsp,
2837 TALLOC_CTX *mem_ctx,
2842 result = SMB_VFS_NEXT_DURABLE_COOKIE(handle,
2847 do_log(SMB_VFS_OP_DURABLE_COOKIE, NT_STATUS_IS_OK(result), handle,
2848 "%s", fsp_str_do_log(fsp));
2853 static NTSTATUS smb_full_audit_durable_disconnect(
2854 struct vfs_handle_struct *handle,
2855 struct files_struct *fsp,
2856 const DATA_BLOB old_cookie,
2857 TALLOC_CTX *mem_ctx,
2858 DATA_BLOB *new_cookie)
2862 result = SMB_VFS_NEXT_DURABLE_DISCONNECT(handle,
2868 do_log(SMB_VFS_OP_DURABLE_DISCONNECT, NT_STATUS_IS_OK(result), handle,
2869 "%s", fsp_str_do_log(fsp));
2874 static NTSTATUS smb_full_audit_durable_reconnect(
2875 struct vfs_handle_struct *handle,
2876 struct smb_request *smb1req,
2877 struct smbXsrv_open *op,
2878 const DATA_BLOB old_cookie,
2879 TALLOC_CTX *mem_ctx,
2880 struct files_struct **fsp,
2881 DATA_BLOB *new_cookie)
2885 result = SMB_VFS_NEXT_DURABLE_RECONNECT(handle,
2893 do_log(SMB_VFS_OP_DURABLE_RECONNECT,
2894 NT_STATUS_IS_OK(result),
2901 static struct vfs_fn_pointers vfs_full_audit_fns = {
2903 /* Disk operations */
2905 .connect_fn = smb_full_audit_connect,
2906 .disconnect_fn = smb_full_audit_disconnect,
2907 .disk_free_fn = smb_full_audit_disk_free,
2908 .get_quota_fn = smb_full_audit_get_quota,
2909 .set_quota_fn = smb_full_audit_set_quota,
2910 .get_shadow_copy_data_fn = smb_full_audit_get_shadow_copy_data,
2911 .statvfs_fn = smb_full_audit_statvfs,
2912 .fs_capabilities_fn = smb_full_audit_fs_capabilities,
2913 .get_dfs_referrals_fn = smb_full_audit_get_dfs_referrals,
2914 .create_dfs_pathat_fn = smb_full_audit_create_dfs_pathat,
2915 .read_dfs_pathat_fn = smb_full_audit_read_dfs_pathat,
2916 .fdopendir_fn = smb_full_audit_fdopendir,
2917 .readdir_fn = smb_full_audit_readdir,
2918 .seekdir_fn = smb_full_audit_seekdir,
2919 .telldir_fn = smb_full_audit_telldir,
2920 .rewind_dir_fn = smb_full_audit_rewinddir,
2921 .mkdirat_fn = smb_full_audit_mkdirat,
2922 .closedir_fn = smb_full_audit_closedir,
2923 .openat_fn = smb_full_audit_openat,
2924 .create_file_fn = smb_full_audit_create_file,
2925 .close_fn = smb_full_audit_close,
2926 .pread_fn = smb_full_audit_pread,
2927 .pread_send_fn = smb_full_audit_pread_send,
2928 .pread_recv_fn = smb_full_audit_pread_recv,
2929 .pwrite_fn = smb_full_audit_pwrite,
2930 .pwrite_send_fn = smb_full_audit_pwrite_send,
2931 .pwrite_recv_fn = smb_full_audit_pwrite_recv,
2932 .lseek_fn = smb_full_audit_lseek,
2933 .sendfile_fn = smb_full_audit_sendfile,
2934 .recvfile_fn = smb_full_audit_recvfile,
2935 .renameat_fn = smb_full_audit_renameat,
2936 .fsync_send_fn = smb_full_audit_fsync_send,
2937 .fsync_recv_fn = smb_full_audit_fsync_recv,
2938 .stat_fn = smb_full_audit_stat,
2939 .fstat_fn = smb_full_audit_fstat,
2940 .lstat_fn = smb_full_audit_lstat,
2941 .get_alloc_size_fn = smb_full_audit_get_alloc_size,
2942 .unlinkat_fn = smb_full_audit_unlinkat,
2943 .fchmod_fn = smb_full_audit_fchmod,
2944 .fchown_fn = smb_full_audit_fchown,
2945 .lchown_fn = smb_full_audit_lchown,
2946 .chdir_fn = smb_full_audit_chdir,
2947 .getwd_fn = smb_full_audit_getwd,
2948 .fntimes_fn = smb_full_audit_fntimes,
2949 .ftruncate_fn = smb_full_audit_ftruncate,
2950 .fallocate_fn = smb_full_audit_fallocate,
2951 .lock_fn = smb_full_audit_lock,
2952 .kernel_flock_fn = smb_full_audit_kernel_flock,
2953 .fcntl_fn = smb_full_audit_fcntl,
2954 .linux_setlease_fn = smb_full_audit_linux_setlease,
2955 .getlock_fn = smb_full_audit_getlock,
2956 .symlinkat_fn = smb_full_audit_symlinkat,
2957 .readlinkat_fn = smb_full_audit_readlinkat,
2958 .linkat_fn = smb_full_audit_linkat,
2959 .mknodat_fn = smb_full_audit_mknodat,
2960 .realpath_fn = smb_full_audit_realpath,
2961 .chflags_fn = smb_full_audit_chflags,
2962 .file_id_create_fn = smb_full_audit_file_id_create,
2963 .fs_file_id_fn = smb_full_audit_fs_file_id,
2964 .offload_read_send_fn = smb_full_audit_offload_read_send,
2965 .offload_read_recv_fn = smb_full_audit_offload_read_recv,
2966 .offload_write_send_fn = smb_full_audit_offload_write_send,
2967 .offload_write_recv_fn = smb_full_audit_offload_write_recv,
2968 .fget_compression_fn = smb_full_audit_fget_compression,
2969 .set_compression_fn = smb_full_audit_set_compression,
2970 .snap_check_path_fn = smb_full_audit_snap_check_path,
2971 .snap_create_fn = smb_full_audit_snap_create,
2972 .snap_delete_fn = smb_full_audit_snap_delete,
2973 .fstreaminfo_fn = smb_full_audit_fstreaminfo,
2974 .get_real_filename_fn = smb_full_audit_get_real_filename,
2975 .connectpath_fn = smb_full_audit_connectpath,
2976 .brl_lock_windows_fn = smb_full_audit_brl_lock_windows,
2977 .brl_unlock_windows_fn = smb_full_audit_brl_unlock_windows,
2978 .strict_lock_check_fn = smb_full_audit_strict_lock_check,
2979 .translate_name_fn = smb_full_audit_translate_name,
2980 .parent_pathname_fn = smb_full_audit_parent_pathname,
2981 .fsctl_fn = smb_full_audit_fsctl,
2982 .get_dos_attributes_send_fn = smb_full_audit_get_dos_attributes_send,
2983 .get_dos_attributes_recv_fn = smb_full_audit_get_dos_attributes_recv,
2984 .fget_dos_attributes_fn = smb_full_audit_fget_dos_attributes,
2985 .fset_dos_attributes_fn = smb_full_audit_fset_dos_attributes,
2986 .fget_nt_acl_fn = smb_full_audit_fget_nt_acl,
2987 .fset_nt_acl_fn = smb_full_audit_fset_nt_acl,
2988 .audit_file_fn = smb_full_audit_audit_file,
2989 .sys_acl_get_fd_fn = smb_full_audit_sys_acl_get_fd,
2990 .sys_acl_blob_get_fd_fn = smb_full_audit_sys_acl_blob_get_fd,
2991 .sys_acl_set_fd_fn = smb_full_audit_sys_acl_set_fd,
2992 .sys_acl_delete_def_fd_fn = smb_full_audit_sys_acl_delete_def_fd,
2993 .getxattr_fn = smb_full_audit_getxattr,
2994 .getxattrat_send_fn = smb_full_audit_getxattrat_send,
2995 .getxattrat_recv_fn = smb_full_audit_getxattrat_recv,
2996 .fgetxattr_fn = smb_full_audit_fgetxattr,
2997 .flistxattr_fn = smb_full_audit_flistxattr,
2998 .fremovexattr_fn = smb_full_audit_fremovexattr,
2999 .fsetxattr_fn = smb_full_audit_fsetxattr,
3000 .aio_force_fn = smb_full_audit_aio_force,
3001 .durable_cookie_fn = smb_full_audit_durable_cookie,
3002 .durable_disconnect_fn = smb_full_audit_durable_disconnect,
3003 .durable_reconnect_fn = smb_full_audit_durable_reconnect,
3004 .freaddir_attr_fn = smb_full_audit_freaddir_attr,
3008 NTSTATUS vfs_full_audit_init(TALLOC_CTX *ctx)
3012 smb_vfs_assert_all_fns(&vfs_full_audit_fns, "full_audit");
3014 ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "full_audit",
3015 &vfs_full_audit_fns);
3017 if (!NT_STATUS_IS_OK(ret))
3020 vfs_full_audit_debug_level = debug_add_class("full_audit");
3021 if (vfs_full_audit_debug_level == -1) {
3022 vfs_full_audit_debug_level = DBGC_VFS;
3023 DEBUG(0, ("vfs_full_audit: Couldn't register custom debugging "
3026 DEBUG(10, ("vfs_full_audit: Debug class number of "
3027 "'full_audit': %d\n", vfs_full_audit_debug_level));