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 result = SMB_VFS_NEXT_RENAMEAT(handle,
1420 do_log(SMB_VFS_OP_RENAMEAT, (result >= 0), handle, "%s|%s",
1421 smb_fname_str_do_log(handle->conn, smb_fname_src),
1422 smb_fname_str_do_log(handle->conn, smb_fname_dst));
1427 struct smb_full_audit_fsync_state {
1428 vfs_handle_struct *handle;
1431 struct vfs_aio_state vfs_aio_state;
1434 static void smb_full_audit_fsync_done(struct tevent_req *subreq);
1436 static struct tevent_req *smb_full_audit_fsync_send(
1437 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1438 struct tevent_context *ev, struct files_struct *fsp)
1440 struct tevent_req *req, *subreq;
1441 struct smb_full_audit_fsync_state *state;
1443 req = tevent_req_create(mem_ctx, &state,
1444 struct smb_full_audit_fsync_state);
1446 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1447 fsp_str_do_log(fsp));
1450 state->handle = handle;
1453 subreq = SMB_VFS_NEXT_FSYNC_SEND(state, ev, handle, fsp);
1454 if (tevent_req_nomem(subreq, req)) {
1455 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1456 fsp_str_do_log(fsp));
1457 return tevent_req_post(req, ev);
1459 tevent_req_set_callback(subreq, smb_full_audit_fsync_done, req);
1461 do_log(SMB_VFS_OP_FSYNC_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1465 static void smb_full_audit_fsync_done(struct tevent_req *subreq)
1467 struct tevent_req *req = tevent_req_callback_data(
1468 subreq, struct tevent_req);
1469 struct smb_full_audit_fsync_state *state = tevent_req_data(
1470 req, struct smb_full_audit_fsync_state);
1472 state->ret = SMB_VFS_FSYNC_RECV(subreq, &state->vfs_aio_state);
1473 TALLOC_FREE(subreq);
1474 tevent_req_done(req);
1477 static int smb_full_audit_fsync_recv(struct tevent_req *req,
1478 struct vfs_aio_state *vfs_aio_state)
1480 struct smb_full_audit_fsync_state *state = tevent_req_data(
1481 req, struct smb_full_audit_fsync_state);
1483 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1484 do_log(SMB_VFS_OP_FSYNC_RECV, false, state->handle, "%s",
1485 fsp_str_do_log(state->fsp));
1489 do_log(SMB_VFS_OP_FSYNC_RECV, (state->ret >= 0), state->handle, "%s",
1490 fsp_str_do_log(state->fsp));
1492 *vfs_aio_state = state->vfs_aio_state;
1496 static int smb_full_audit_stat(vfs_handle_struct *handle,
1497 struct smb_filename *smb_fname)
1501 result = SMB_VFS_NEXT_STAT(handle, smb_fname);
1503 do_log(SMB_VFS_OP_STAT, (result >= 0), handle, "%s",
1504 smb_fname_str_do_log(handle->conn, smb_fname));
1509 static int smb_full_audit_fstat(vfs_handle_struct *handle, files_struct *fsp,
1510 SMB_STRUCT_STAT *sbuf)
1514 result = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1516 do_log(SMB_VFS_OP_FSTAT, (result >= 0), handle, "%s",
1517 fsp_str_do_log(fsp));
1522 static int smb_full_audit_lstat(vfs_handle_struct *handle,
1523 struct smb_filename *smb_fname)
1527 result = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
1529 do_log(SMB_VFS_OP_LSTAT, (result >= 0), handle, "%s",
1530 smb_fname_str_do_log(handle->conn, smb_fname));
1535 static uint64_t smb_full_audit_get_alloc_size(vfs_handle_struct *handle,
1536 files_struct *fsp, const SMB_STRUCT_STAT *sbuf)
1540 result = SMB_VFS_NEXT_GET_ALLOC_SIZE(handle, fsp, sbuf);
1542 do_log(SMB_VFS_OP_GET_ALLOC_SIZE, (result != (uint64_t)-1), handle,
1543 "%llu", (unsigned long long)result);
1548 static int smb_full_audit_unlinkat(vfs_handle_struct *handle,
1549 struct files_struct *dirfsp,
1550 const struct smb_filename *smb_fname,
1553 struct smb_filename *full_fname = NULL;
1556 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1559 if (full_fname == NULL) {
1563 result = SMB_VFS_NEXT_UNLINKAT(handle,
1568 do_log(SMB_VFS_OP_UNLINKAT, (result >= 0), handle, "%s",
1569 smb_fname_str_do_log(handle->conn, full_fname));
1571 TALLOC_FREE(full_fname);
1575 static int smb_full_audit_fchmod(vfs_handle_struct *handle, files_struct *fsp,
1580 result = SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1582 do_log(SMB_VFS_OP_FCHMOD, (result >= 0), handle,
1583 "%s|%o", fsp_str_do_log(fsp), mode);
1588 static int smb_full_audit_fchown(vfs_handle_struct *handle, files_struct *fsp,
1589 uid_t uid, gid_t gid)
1593 result = SMB_VFS_NEXT_FCHOWN(handle, fsp, uid, gid);
1595 do_log(SMB_VFS_OP_FCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1596 fsp_str_do_log(fsp), (long int)uid, (long int)gid);
1601 static int smb_full_audit_lchown(vfs_handle_struct *handle,
1602 const struct smb_filename *smb_fname,
1608 result = SMB_VFS_NEXT_LCHOWN(handle, smb_fname, uid, gid);
1610 do_log(SMB_VFS_OP_LCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1611 smb_fname->base_name, (long int)uid, (long int)gid);
1616 static int smb_full_audit_chdir(vfs_handle_struct *handle,
1617 const struct smb_filename *smb_fname)
1621 result = SMB_VFS_NEXT_CHDIR(handle, smb_fname);
1623 do_log(SMB_VFS_OP_CHDIR,
1627 smb_fname_str_do_log(handle->conn, smb_fname));
1632 static struct smb_filename *smb_full_audit_getwd(vfs_handle_struct *handle,
1635 struct smb_filename *result;
1637 result = SMB_VFS_NEXT_GETWD(handle, ctx);
1639 do_log(SMB_VFS_OP_GETWD, (result != NULL), handle, "%s",
1640 result == NULL? "" : result->base_name);
1645 static int smb_full_audit_fntimes(vfs_handle_struct *handle,
1647 struct smb_file_time *ft)
1650 time_t create_time = convert_timespec_to_time_t(ft->create_time);
1651 time_t atime = convert_timespec_to_time_t(ft->atime);
1652 time_t mtime = convert_timespec_to_time_t(ft->mtime);
1653 time_t ctime = convert_timespec_to_time_t(ft->ctime);
1654 const char *create_time_str = "";
1655 const char *atime_str = "";
1656 const char *mtime_str = "";
1657 const char *ctime_str = "";
1658 TALLOC_CTX *frame = talloc_stackframe();
1660 if (frame == NULL) {
1665 result = SMB_VFS_NEXT_FNTIMES(handle, fsp, ft);
1667 if (create_time > 0) {
1668 create_time_str = timestring(frame, create_time);
1671 atime_str = timestring(frame, atime);
1674 mtime_str = timestring(frame, mtime);
1677 ctime_str = timestring(frame, ctime);
1680 do_log(SMB_VFS_OP_FNTIMES,
1684 fsp_str_do_log(fsp),
1695 static int smb_full_audit_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
1700 result = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1702 do_log(SMB_VFS_OP_FTRUNCATE, (result >= 0), handle,
1703 "%s", fsp_str_do_log(fsp));
1708 static int smb_full_audit_fallocate(vfs_handle_struct *handle, files_struct *fsp,
1715 result = SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
1717 do_log(SMB_VFS_OP_FALLOCATE, (result >= 0), handle,
1718 "%s", fsp_str_do_log(fsp));
1723 static bool smb_full_audit_lock(vfs_handle_struct *handle, files_struct *fsp,
1724 int op, off_t offset, off_t count, int type)
1728 result = SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type);
1730 do_log(SMB_VFS_OP_LOCK, result, handle, "%s", fsp_str_do_log(fsp));
1735 static int smb_full_audit_kernel_flock(struct vfs_handle_struct *handle,
1736 struct files_struct *fsp,
1737 uint32_t share_access,
1738 uint32_t access_mask)
1742 result = SMB_VFS_NEXT_KERNEL_FLOCK(handle,
1747 do_log(SMB_VFS_OP_KERNEL_FLOCK, (result >= 0), handle, "%s",
1748 fsp_str_do_log(fsp));
1753 static int smb_full_audit_fcntl(struct vfs_handle_struct *handle,
1754 struct files_struct *fsp,
1755 int cmd, va_list cmd_arg)
1758 va_list dup_cmd_arg;
1761 va_copy(dup_cmd_arg, cmd_arg);
1762 arg = va_arg(dup_cmd_arg, void *);
1763 result = SMB_VFS_NEXT_FCNTL(handle, fsp, cmd, arg);
1764 va_end(dup_cmd_arg);
1766 do_log(SMB_VFS_OP_FCNTL, (result >= 0), handle, "%s",
1767 fsp_str_do_log(fsp));
1772 static int smb_full_audit_linux_setlease(vfs_handle_struct *handle, files_struct *fsp,
1777 result = SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
1779 do_log(SMB_VFS_OP_LINUX_SETLEASE, (result >= 0), handle, "%s",
1780 fsp_str_do_log(fsp));
1785 static bool smb_full_audit_getlock(vfs_handle_struct *handle, files_struct *fsp,
1786 off_t *poffset, off_t *pcount, int *ptype, pid_t *ppid)
1790 result = SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype, ppid);
1792 do_log(SMB_VFS_OP_GETLOCK, result, handle, "%s", fsp_str_do_log(fsp));
1797 static int smb_full_audit_symlinkat(vfs_handle_struct *handle,
1798 const struct smb_filename *link_contents,
1799 struct files_struct *dirfsp,
1800 const struct smb_filename *new_smb_fname)
1802 struct smb_filename *full_fname = NULL;
1805 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1808 if (full_fname == NULL) {
1812 result = SMB_VFS_NEXT_SYMLINKAT(handle,
1817 do_log(SMB_VFS_OP_SYMLINKAT,
1821 link_contents->base_name,
1822 smb_fname_str_do_log(handle->conn, full_fname));
1824 TALLOC_FREE(full_fname);
1829 static int smb_full_audit_readlinkat(vfs_handle_struct *handle,
1830 const struct files_struct *dirfsp,
1831 const struct smb_filename *smb_fname,
1835 struct smb_filename *full_fname = NULL;
1838 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1841 if (full_fname == NULL) {
1845 result = SMB_VFS_NEXT_READLINKAT(handle,
1851 do_log(SMB_VFS_OP_READLINKAT,
1855 smb_fname_str_do_log(handle->conn, full_fname));
1857 TALLOC_FREE(full_fname);
1862 static int smb_full_audit_linkat(vfs_handle_struct *handle,
1863 files_struct *srcfsp,
1864 const struct smb_filename *old_smb_fname,
1865 files_struct *dstfsp,
1866 const struct smb_filename *new_smb_fname,
1869 struct smb_filename *old_full_fname = NULL;
1870 struct smb_filename *new_full_fname = NULL;
1873 old_full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1876 if (old_full_fname == NULL) {
1879 new_full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1882 if (new_full_fname == NULL) {
1883 TALLOC_FREE(old_full_fname);
1886 result = SMB_VFS_NEXT_LINKAT(handle,
1893 do_log(SMB_VFS_OP_LINKAT,
1897 smb_fname_str_do_log(handle->conn, old_full_fname),
1898 smb_fname_str_do_log(handle->conn, new_full_fname));
1900 TALLOC_FREE(old_full_fname);
1901 TALLOC_FREE(new_full_fname);
1906 static int smb_full_audit_mknodat(vfs_handle_struct *handle,
1907 files_struct *dirfsp,
1908 const struct smb_filename *smb_fname,
1912 struct smb_filename *full_fname = NULL;
1915 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1918 if (full_fname == NULL) {
1922 result = SMB_VFS_NEXT_MKNODAT(handle,
1928 do_log(SMB_VFS_OP_MKNODAT,
1932 smb_fname_str_do_log(handle->conn, full_fname));
1934 TALLOC_FREE(full_fname);
1939 static struct smb_filename *smb_full_audit_realpath(vfs_handle_struct *handle,
1941 const struct smb_filename *smb_fname)
1943 struct smb_filename *result_fname = NULL;
1945 result_fname = SMB_VFS_NEXT_REALPATH(handle, ctx, smb_fname);
1947 do_log(SMB_VFS_OP_REALPATH,
1948 (result_fname != NULL),
1951 smb_fname_str_do_log(handle->conn, smb_fname));
1953 return result_fname;
1956 static int smb_full_audit_chflags(vfs_handle_struct *handle,
1957 const struct smb_filename *smb_fname,
1962 result = SMB_VFS_NEXT_CHFLAGS(handle, smb_fname, flags);
1964 do_log(SMB_VFS_OP_CHFLAGS,
1968 smb_fname_str_do_log(handle->conn, smb_fname));
1973 static struct file_id smb_full_audit_file_id_create(struct vfs_handle_struct *handle,
1974 const SMB_STRUCT_STAT *sbuf)
1976 struct file_id id_zero = { 0 };
1977 struct file_id result;
1978 struct file_id_buf idbuf;
1980 result = SMB_VFS_NEXT_FILE_ID_CREATE(handle, sbuf);
1982 do_log(SMB_VFS_OP_FILE_ID_CREATE,
1983 !file_id_equal(&id_zero, &result),
1986 file_id_str_buf(result, &idbuf));
1991 static uint64_t smb_full_audit_fs_file_id(struct vfs_handle_struct *handle,
1992 const SMB_STRUCT_STAT *sbuf)
1996 result = SMB_VFS_NEXT_FS_FILE_ID(handle, sbuf);
1998 do_log(SMB_VFS_OP_FS_FILE_ID,
2000 handle, "%" PRIu64, result);
2005 static NTSTATUS smb_full_audit_fstreaminfo(vfs_handle_struct *handle,
2006 struct files_struct *fsp,
2007 TALLOC_CTX *mem_ctx,
2008 unsigned int *pnum_streams,
2009 struct stream_struct **pstreams)
2013 result = SMB_VFS_NEXT_FSTREAMINFO(handle, fsp, mem_ctx,
2014 pnum_streams, pstreams);
2016 do_log(SMB_VFS_OP_FSTREAMINFO,
2017 NT_STATUS_IS_OK(result),
2020 smb_fname_str_do_log(handle->conn, fsp->fsp_name));
2025 static int smb_full_audit_get_real_filename(struct vfs_handle_struct *handle,
2026 const struct smb_filename *path,
2028 TALLOC_CTX *mem_ctx,
2033 result = SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name, mem_ctx,
2036 do_log(SMB_VFS_OP_GET_REAL_FILENAME, (result == 0), handle,
2038 path->base_name, name, (result == 0) ? *found_name : "");
2043 static const char *smb_full_audit_connectpath(vfs_handle_struct *handle,
2044 const struct smb_filename *smb_fname)
2048 result = SMB_VFS_NEXT_CONNECTPATH(handle, smb_fname);
2050 do_log(SMB_VFS_OP_CONNECTPATH,
2054 smb_fname_str_do_log(handle->conn, smb_fname));
2059 static NTSTATUS smb_full_audit_brl_lock_windows(struct vfs_handle_struct *handle,
2060 struct byte_range_lock *br_lck,
2061 struct lock_struct *plock)
2065 result = SMB_VFS_NEXT_BRL_LOCK_WINDOWS(handle, br_lck, plock);
2067 do_log(SMB_VFS_OP_BRL_LOCK_WINDOWS, NT_STATUS_IS_OK(result), handle,
2068 "%s:%llu-%llu. type=%d.",
2069 fsp_str_do_log(brl_fsp(br_lck)),
2070 (unsigned long long)plock->start,
2071 (unsigned long long)plock->size,
2077 static bool smb_full_audit_brl_unlock_windows(struct vfs_handle_struct *handle,
2078 struct byte_range_lock *br_lck,
2079 const struct lock_struct *plock)
2083 result = SMB_VFS_NEXT_BRL_UNLOCK_WINDOWS(handle, br_lck, plock);
2085 do_log(SMB_VFS_OP_BRL_UNLOCK_WINDOWS, (result == 0), handle,
2086 "%s:%llu-%llu:%d", fsp_str_do_log(brl_fsp(br_lck)),
2087 (unsigned long long)plock->start,
2088 (unsigned long long)plock->size,
2094 static bool smb_full_audit_strict_lock_check(struct vfs_handle_struct *handle,
2095 struct files_struct *fsp,
2096 struct lock_struct *plock)
2100 result = SMB_VFS_NEXT_STRICT_LOCK_CHECK(handle, fsp, plock);
2102 do_log(SMB_VFS_OP_STRICT_LOCK_CHECK, result, handle,
2103 "%s:%llu-%llu:%d", fsp_str_do_log(fsp),
2104 (unsigned long long)plock->start,
2105 (unsigned long long)plock->size,
2111 static NTSTATUS smb_full_audit_translate_name(struct vfs_handle_struct *handle,
2113 enum vfs_translate_direction direction,
2114 TALLOC_CTX *mem_ctx,
2119 result = SMB_VFS_NEXT_TRANSLATE_NAME(handle, name, direction, mem_ctx,
2122 do_log(SMB_VFS_OP_TRANSLATE_NAME, NT_STATUS_IS_OK(result), handle, "");
2127 static NTSTATUS smb_full_audit_parent_pathname(struct vfs_handle_struct *handle,
2128 TALLOC_CTX *mem_ctx,
2129 const struct smb_filename *smb_fname_in,
2130 struct smb_filename **parent_dir_out,
2131 struct smb_filename **atname_out)
2135 result = SMB_VFS_NEXT_PARENT_PATHNAME(handle,
2140 do_log(SMB_VFS_OP_CONNECTPATH,
2141 NT_STATUS_IS_OK(result),
2144 smb_fname_str_do_log(handle->conn, smb_fname_in));
2149 static NTSTATUS smb_full_audit_fsctl(struct vfs_handle_struct *handle,
2150 struct files_struct *fsp,
2154 const uint8_t *_in_data,
2156 uint8_t **_out_data,
2157 uint32_t max_out_len,
2162 result = SMB_VFS_NEXT_FSCTL(handle,
2173 do_log(SMB_VFS_OP_FSCTL, NT_STATUS_IS_OK(result), handle, "");
2178 static struct tevent_req *smb_full_audit_offload_read_send(
2179 TALLOC_CTX *mem_ctx,
2180 struct tevent_context *ev,
2181 struct vfs_handle_struct *handle,
2182 struct files_struct *fsp,
2188 struct tevent_req *req = NULL;
2190 req = SMB_VFS_NEXT_OFFLOAD_READ_SEND(mem_ctx, ev, handle, fsp,
2191 fsctl, ttl, offset, to_copy);
2193 do_log(SMB_VFS_OP_OFFLOAD_READ_SEND, req, handle, "");
2198 static NTSTATUS smb_full_audit_offload_read_recv(
2199 struct tevent_req *req,
2200 struct vfs_handle_struct *handle,
2201 TALLOC_CTX *mem_ctx,
2202 DATA_BLOB *_token_blob)
2206 status = SMB_VFS_NEXT_OFFLOAD_READ_RECV(req, handle, mem_ctx,
2209 do_log(SMB_VFS_OP_OFFLOAD_READ_RECV, NT_STATUS_IS_OK(status), handle, "");
2214 static struct tevent_req *smb_full_audit_offload_write_send(struct vfs_handle_struct *handle,
2215 TALLOC_CTX *mem_ctx,
2216 struct tevent_context *ev,
2219 off_t transfer_offset,
2220 struct files_struct *dest_fsp,
2224 struct tevent_req *req;
2226 req = SMB_VFS_NEXT_OFFLOAD_WRITE_SEND(handle, mem_ctx, ev,
2227 fsctl, token, transfer_offset,
2228 dest_fsp, dest_off, num);
2230 do_log(SMB_VFS_OP_OFFLOAD_WRITE_SEND, req, handle, "");
2235 static NTSTATUS smb_full_audit_offload_write_recv(struct vfs_handle_struct *handle,
2236 struct tevent_req *req,
2241 result = SMB_VFS_NEXT_OFFLOAD_WRITE_RECV(handle, req, copied);
2243 do_log(SMB_VFS_OP_OFFLOAD_WRITE_RECV, NT_STATUS_IS_OK(result), handle, "");
2248 static NTSTATUS smb_full_audit_fget_compression(vfs_handle_struct *handle,
2249 TALLOC_CTX *mem_ctx,
2250 struct files_struct *fsp,
2251 uint16_t *_compression_fmt)
2255 result = SMB_VFS_NEXT_FGET_COMPRESSION(handle, mem_ctx, fsp,
2258 do_log(SMB_VFS_OP_FGET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
2260 fsp_str_do_log(fsp));
2265 static NTSTATUS smb_full_audit_set_compression(vfs_handle_struct *handle,
2266 TALLOC_CTX *mem_ctx,
2267 struct files_struct *fsp,
2268 uint16_t compression_fmt)
2272 result = SMB_VFS_NEXT_SET_COMPRESSION(handle, mem_ctx, fsp,
2275 do_log(SMB_VFS_OP_SET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
2276 "%s", fsp_str_do_log(fsp));
2281 static NTSTATUS smb_full_audit_freaddir_attr(struct vfs_handle_struct *handle,
2282 struct files_struct *fsp,
2283 TALLOC_CTX *mem_ctx,
2284 struct readdir_attr_data **pattr_data)
2288 status = SMB_VFS_NEXT_FREADDIR_ATTR(handle, fsp, mem_ctx, pattr_data);
2290 do_log(SMB_VFS_OP_FREADDIR_ATTR,
2291 NT_STATUS_IS_OK(status),
2294 fsp_str_do_log(fsp));
2299 struct smb_full_audit_get_dos_attributes_state {
2300 struct vfs_aio_state aio_state;
2301 vfs_handle_struct *handle;
2302 files_struct *dir_fsp;
2303 const struct smb_filename *smb_fname;
2307 static void smb_full_audit_get_dos_attributes_done(struct tevent_req *subreq);
2309 static struct tevent_req *smb_full_audit_get_dos_attributes_send(
2310 TALLOC_CTX *mem_ctx,
2311 struct tevent_context *ev,
2312 struct vfs_handle_struct *handle,
2313 files_struct *dir_fsp,
2314 struct smb_filename *smb_fname)
2316 struct tevent_req *req = NULL;
2317 struct smb_full_audit_get_dos_attributes_state *state = NULL;
2318 struct tevent_req *subreq = NULL;
2320 req = tevent_req_create(mem_ctx, &state,
2321 struct smb_full_audit_get_dos_attributes_state);
2323 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2327 fsp_str_do_log(dir_fsp),
2328 smb_fname->base_name);
2331 *state = (struct smb_full_audit_get_dos_attributes_state) {
2334 .smb_fname = smb_fname,
2337 subreq = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES_SEND(mem_ctx,
2342 if (tevent_req_nomem(subreq, req)) {
2343 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2347 fsp_str_do_log(dir_fsp),
2348 smb_fname->base_name);
2349 return tevent_req_post(req, ev);
2351 tevent_req_set_callback(subreq,
2352 smb_full_audit_get_dos_attributes_done,
2355 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2359 fsp_str_do_log(dir_fsp),
2360 smb_fname->base_name);
2365 static void smb_full_audit_get_dos_attributes_done(struct tevent_req *subreq)
2367 struct tevent_req *req =
2368 tevent_req_callback_data(subreq,
2370 struct smb_full_audit_get_dos_attributes_state *state =
2371 tevent_req_data(req,
2372 struct smb_full_audit_get_dos_attributes_state);
2375 status = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES_RECV(subreq,
2378 TALLOC_FREE(subreq);
2379 if (tevent_req_nterror(req, status)) {
2383 tevent_req_done(req);
2387 static NTSTATUS smb_full_audit_get_dos_attributes_recv(struct tevent_req *req,
2388 struct vfs_aio_state *aio_state,
2391 struct smb_full_audit_get_dos_attributes_state *state =
2392 tevent_req_data(req,
2393 struct smb_full_audit_get_dos_attributes_state);
2396 if (tevent_req_is_nterror(req, &status)) {
2397 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV,
2401 fsp_str_do_log(state->dir_fsp),
2402 state->smb_fname->base_name);
2403 tevent_req_received(req);
2407 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV,
2411 fsp_str_do_log(state->dir_fsp),
2412 state->smb_fname->base_name);
2414 *aio_state = state->aio_state;
2415 *dosmode = state->dosmode;
2416 tevent_req_received(req);
2417 return NT_STATUS_OK;
2420 static NTSTATUS smb_full_audit_fget_dos_attributes(
2421 struct vfs_handle_struct *handle,
2422 struct files_struct *fsp,
2427 status = SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle,
2431 do_log(SMB_VFS_OP_FGET_DOS_ATTRIBUTES,
2432 NT_STATUS_IS_OK(status),
2435 fsp_str_do_log(fsp));
2440 static NTSTATUS smb_full_audit_fset_dos_attributes(
2441 struct vfs_handle_struct *handle,
2442 struct files_struct *fsp,
2447 status = SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle,
2451 do_log(SMB_VFS_OP_FSET_DOS_ATTRIBUTES,
2452 NT_STATUS_IS_OK(status),
2455 fsp_str_do_log(fsp));
2460 static NTSTATUS smb_full_audit_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
2461 uint32_t security_info,
2462 TALLOC_CTX *mem_ctx,
2463 struct security_descriptor **ppdesc)
2467 result = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
2470 do_log(SMB_VFS_OP_FGET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2471 "%s", fsp_str_do_log(fsp));
2476 static NTSTATUS smb_full_audit_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
2477 uint32_t security_info_sent,
2478 const struct security_descriptor *psd)
2480 struct vfs_full_audit_private_data *pd;
2484 SMB_VFS_HANDLE_GET_DATA(handle, pd,
2485 struct vfs_full_audit_private_data,
2486 return NT_STATUS_INTERNAL_ERROR);
2488 if (pd->log_secdesc) {
2489 sd = sddl_encode(talloc_tos(), psd, get_global_sam_sid());
2492 result = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
2494 do_log(SMB_VFS_OP_FSET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2495 "%s [%s]", fsp_str_do_log(fsp), sd ? sd : "");
2502 static NTSTATUS smb_full_audit_audit_file(struct vfs_handle_struct *handle,
2503 struct smb_filename *file,
2504 struct security_acl *sacl,
2505 uint32_t access_requested,
2506 uint32_t access_denied)
2510 result = SMB_VFS_NEXT_AUDIT_FILE(handle,
2516 do_log(SMB_VFS_OP_AUDIT_FILE, NT_STATUS_IS_OK(result), handle,
2518 smb_fname_str_do_log(handle->conn, file));
2523 static SMB_ACL_T smb_full_audit_sys_acl_get_fd(vfs_handle_struct *handle,
2525 SMB_ACL_TYPE_T type,
2526 TALLOC_CTX *mem_ctx)
2530 result = SMB_VFS_NEXT_SYS_ACL_GET_FD(handle,
2535 do_log(SMB_VFS_OP_SYS_ACL_GET_FD, (result != NULL), handle,
2536 "%s", fsp_str_do_log(fsp));
2541 static int smb_full_audit_sys_acl_blob_get_fd(vfs_handle_struct *handle,
2543 TALLOC_CTX *mem_ctx,
2544 char **blob_description,
2549 result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle, fsp, mem_ctx, blob_description, blob);
2551 do_log(SMB_VFS_OP_SYS_ACL_BLOB_GET_FD, (result >= 0), handle,
2552 "%s", fsp_str_do_log(fsp));
2557 static int smb_full_audit_sys_acl_set_fd(vfs_handle_struct *handle,
2558 struct files_struct *fsp,
2559 SMB_ACL_TYPE_T type,
2564 result = SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, type, theacl);
2566 do_log(SMB_VFS_OP_SYS_ACL_SET_FD, (result >= 0), handle,
2567 "%s", fsp_str_do_log(fsp));
2572 static int smb_full_audit_sys_acl_delete_def_fd(vfs_handle_struct *handle,
2573 struct files_struct *fsp)
2577 result = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FD(handle, fsp);
2579 do_log(SMB_VFS_OP_SYS_ACL_DELETE_DEF_FD,
2583 fsp_str_do_log(fsp));
2588 static ssize_t smb_full_audit_getxattr(struct vfs_handle_struct *handle,
2589 const struct smb_filename *smb_fname,
2590 const char *name, void *value, size_t size)
2594 result = SMB_VFS_NEXT_GETXATTR(handle, smb_fname, name, value, size);
2596 do_log(SMB_VFS_OP_GETXATTR,
2600 smb_fname_str_do_log(handle->conn, smb_fname),
2606 struct smb_full_audit_getxattrat_state {
2607 struct vfs_aio_state aio_state;
2608 vfs_handle_struct *handle;
2609 files_struct *dir_fsp;
2610 const struct smb_filename *smb_fname;
2611 const char *xattr_name;
2613 uint8_t *xattr_value;
2616 static void smb_full_audit_getxattrat_done(struct tevent_req *subreq);
2618 static struct tevent_req *smb_full_audit_getxattrat_send(
2619 TALLOC_CTX *mem_ctx,
2620 struct tevent_context *ev,
2621 struct vfs_handle_struct *handle,
2622 files_struct *dir_fsp,
2623 const struct smb_filename *smb_fname,
2624 const char *xattr_name,
2627 struct tevent_req *req = NULL;
2628 struct tevent_req *subreq = NULL;
2629 struct smb_full_audit_getxattrat_state *state = NULL;
2631 req = tevent_req_create(mem_ctx, &state,
2632 struct smb_full_audit_getxattrat_state);
2634 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2638 fsp_str_do_log(dir_fsp),
2639 smb_fname->base_name,
2643 *state = (struct smb_full_audit_getxattrat_state) {
2646 .smb_fname = smb_fname,
2647 .xattr_name = xattr_name,
2650 subreq = SMB_VFS_NEXT_GETXATTRAT_SEND(state,
2657 if (tevent_req_nomem(subreq, req)) {
2658 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2662 fsp_str_do_log(dir_fsp),
2663 smb_fname->base_name,
2665 return tevent_req_post(req, ev);
2667 tevent_req_set_callback(subreq, smb_full_audit_getxattrat_done, req);
2669 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2673 fsp_str_do_log(dir_fsp),
2674 smb_fname->base_name,
2680 static void smb_full_audit_getxattrat_done(struct tevent_req *subreq)
2682 struct tevent_req *req = tevent_req_callback_data(
2683 subreq, struct tevent_req);
2684 struct smb_full_audit_getxattrat_state *state = tevent_req_data(
2685 req, struct smb_full_audit_getxattrat_state);
2687 state->xattr_size = SMB_VFS_NEXT_GETXATTRAT_RECV(subreq,
2690 &state->xattr_value);
2691 TALLOC_FREE(subreq);
2692 if (state->xattr_size == -1) {
2693 tevent_req_error(req, state->aio_state.error);
2697 tevent_req_done(req);
2700 static ssize_t smb_full_audit_getxattrat_recv(struct tevent_req *req,
2701 struct vfs_aio_state *aio_state,
2702 TALLOC_CTX *mem_ctx,
2703 uint8_t **xattr_value)
2705 struct smb_full_audit_getxattrat_state *state = tevent_req_data(
2706 req, struct smb_full_audit_getxattrat_state);
2709 if (tevent_req_is_unix_error(req, &aio_state->error)) {
2710 do_log(SMB_VFS_OP_GETXATTRAT_RECV,
2714 fsp_str_do_log(state->dir_fsp),
2715 state->smb_fname->base_name,
2717 tevent_req_received(req);
2721 do_log(SMB_VFS_OP_GETXATTRAT_RECV,
2725 fsp_str_do_log(state->dir_fsp),
2726 state->smb_fname->base_name,
2729 *aio_state = state->aio_state;
2730 xattr_size = state->xattr_size;
2731 if (xattr_value != NULL) {
2732 *xattr_value = talloc_move(mem_ctx, &state->xattr_value);
2735 tevent_req_received(req);
2739 static ssize_t smb_full_audit_fgetxattr(struct vfs_handle_struct *handle,
2740 struct files_struct *fsp,
2741 const char *name, void *value, size_t size)
2745 result = SMB_VFS_NEXT_FGETXATTR(handle, fsp, name, value, size);
2747 do_log(SMB_VFS_OP_FGETXATTR, (result >= 0), handle,
2748 "%s|%s", fsp_str_do_log(fsp), name);
2753 static ssize_t smb_full_audit_flistxattr(struct vfs_handle_struct *handle,
2754 struct files_struct *fsp, char *list,
2759 result = SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
2761 do_log(SMB_VFS_OP_FLISTXATTR, (result >= 0), handle,
2762 "%s", fsp_str_do_log(fsp));
2767 static int smb_full_audit_fremovexattr(struct vfs_handle_struct *handle,
2768 struct files_struct *fsp,
2773 result = SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, name);
2775 do_log(SMB_VFS_OP_FREMOVEXATTR, (result >= 0), handle,
2776 "%s|%s", fsp_str_do_log(fsp), name);
2781 static int smb_full_audit_fsetxattr(struct vfs_handle_struct *handle,
2782 struct files_struct *fsp, const char *name,
2783 const void *value, size_t size, int flags)
2787 result = SMB_VFS_NEXT_FSETXATTR(handle, fsp, name, value, size, flags);
2789 do_log(SMB_VFS_OP_FSETXATTR, (result >= 0), handle,
2790 "%s|%s", fsp_str_do_log(fsp), name);
2795 static bool smb_full_audit_aio_force(struct vfs_handle_struct *handle,
2796 struct files_struct *fsp)
2800 result = SMB_VFS_NEXT_AIO_FORCE(handle, fsp);
2801 do_log(SMB_VFS_OP_AIO_FORCE, result, handle,
2802 "%s", fsp_str_do_log(fsp));
2807 static NTSTATUS smb_full_audit_durable_cookie(struct vfs_handle_struct *handle,
2808 struct files_struct *fsp,
2809 TALLOC_CTX *mem_ctx,
2814 result = SMB_VFS_NEXT_DURABLE_COOKIE(handle,
2819 do_log(SMB_VFS_OP_DURABLE_COOKIE, NT_STATUS_IS_OK(result), handle,
2820 "%s", fsp_str_do_log(fsp));
2825 static NTSTATUS smb_full_audit_durable_disconnect(
2826 struct vfs_handle_struct *handle,
2827 struct files_struct *fsp,
2828 const DATA_BLOB old_cookie,
2829 TALLOC_CTX *mem_ctx,
2830 DATA_BLOB *new_cookie)
2834 result = SMB_VFS_NEXT_DURABLE_DISCONNECT(handle,
2840 do_log(SMB_VFS_OP_DURABLE_DISCONNECT, NT_STATUS_IS_OK(result), handle,
2841 "%s", fsp_str_do_log(fsp));
2846 static NTSTATUS smb_full_audit_durable_reconnect(
2847 struct vfs_handle_struct *handle,
2848 struct smb_request *smb1req,
2849 struct smbXsrv_open *op,
2850 const DATA_BLOB old_cookie,
2851 TALLOC_CTX *mem_ctx,
2852 struct files_struct **fsp,
2853 DATA_BLOB *new_cookie)
2857 result = SMB_VFS_NEXT_DURABLE_RECONNECT(handle,
2865 do_log(SMB_VFS_OP_DURABLE_RECONNECT,
2866 NT_STATUS_IS_OK(result),
2873 static struct vfs_fn_pointers vfs_full_audit_fns = {
2875 /* Disk operations */
2877 .connect_fn = smb_full_audit_connect,
2878 .disconnect_fn = smb_full_audit_disconnect,
2879 .disk_free_fn = smb_full_audit_disk_free,
2880 .get_quota_fn = smb_full_audit_get_quota,
2881 .set_quota_fn = smb_full_audit_set_quota,
2882 .get_shadow_copy_data_fn = smb_full_audit_get_shadow_copy_data,
2883 .statvfs_fn = smb_full_audit_statvfs,
2884 .fs_capabilities_fn = smb_full_audit_fs_capabilities,
2885 .get_dfs_referrals_fn = smb_full_audit_get_dfs_referrals,
2886 .create_dfs_pathat_fn = smb_full_audit_create_dfs_pathat,
2887 .read_dfs_pathat_fn = smb_full_audit_read_dfs_pathat,
2888 .fdopendir_fn = smb_full_audit_fdopendir,
2889 .readdir_fn = smb_full_audit_readdir,
2890 .seekdir_fn = smb_full_audit_seekdir,
2891 .telldir_fn = smb_full_audit_telldir,
2892 .rewind_dir_fn = smb_full_audit_rewinddir,
2893 .mkdirat_fn = smb_full_audit_mkdirat,
2894 .closedir_fn = smb_full_audit_closedir,
2895 .openat_fn = smb_full_audit_openat,
2896 .create_file_fn = smb_full_audit_create_file,
2897 .close_fn = smb_full_audit_close,
2898 .pread_fn = smb_full_audit_pread,
2899 .pread_send_fn = smb_full_audit_pread_send,
2900 .pread_recv_fn = smb_full_audit_pread_recv,
2901 .pwrite_fn = smb_full_audit_pwrite,
2902 .pwrite_send_fn = smb_full_audit_pwrite_send,
2903 .pwrite_recv_fn = smb_full_audit_pwrite_recv,
2904 .lseek_fn = smb_full_audit_lseek,
2905 .sendfile_fn = smb_full_audit_sendfile,
2906 .recvfile_fn = smb_full_audit_recvfile,
2907 .renameat_fn = smb_full_audit_renameat,
2908 .fsync_send_fn = smb_full_audit_fsync_send,
2909 .fsync_recv_fn = smb_full_audit_fsync_recv,
2910 .stat_fn = smb_full_audit_stat,
2911 .fstat_fn = smb_full_audit_fstat,
2912 .lstat_fn = smb_full_audit_lstat,
2913 .get_alloc_size_fn = smb_full_audit_get_alloc_size,
2914 .unlinkat_fn = smb_full_audit_unlinkat,
2915 .fchmod_fn = smb_full_audit_fchmod,
2916 .fchown_fn = smb_full_audit_fchown,
2917 .lchown_fn = smb_full_audit_lchown,
2918 .chdir_fn = smb_full_audit_chdir,
2919 .getwd_fn = smb_full_audit_getwd,
2920 .fntimes_fn = smb_full_audit_fntimes,
2921 .ftruncate_fn = smb_full_audit_ftruncate,
2922 .fallocate_fn = smb_full_audit_fallocate,
2923 .lock_fn = smb_full_audit_lock,
2924 .kernel_flock_fn = smb_full_audit_kernel_flock,
2925 .fcntl_fn = smb_full_audit_fcntl,
2926 .linux_setlease_fn = smb_full_audit_linux_setlease,
2927 .getlock_fn = smb_full_audit_getlock,
2928 .symlinkat_fn = smb_full_audit_symlinkat,
2929 .readlinkat_fn = smb_full_audit_readlinkat,
2930 .linkat_fn = smb_full_audit_linkat,
2931 .mknodat_fn = smb_full_audit_mknodat,
2932 .realpath_fn = smb_full_audit_realpath,
2933 .chflags_fn = smb_full_audit_chflags,
2934 .file_id_create_fn = smb_full_audit_file_id_create,
2935 .fs_file_id_fn = smb_full_audit_fs_file_id,
2936 .offload_read_send_fn = smb_full_audit_offload_read_send,
2937 .offload_read_recv_fn = smb_full_audit_offload_read_recv,
2938 .offload_write_send_fn = smb_full_audit_offload_write_send,
2939 .offload_write_recv_fn = smb_full_audit_offload_write_recv,
2940 .fget_compression_fn = smb_full_audit_fget_compression,
2941 .set_compression_fn = smb_full_audit_set_compression,
2942 .snap_check_path_fn = smb_full_audit_snap_check_path,
2943 .snap_create_fn = smb_full_audit_snap_create,
2944 .snap_delete_fn = smb_full_audit_snap_delete,
2945 .fstreaminfo_fn = smb_full_audit_fstreaminfo,
2946 .get_real_filename_fn = smb_full_audit_get_real_filename,
2947 .connectpath_fn = smb_full_audit_connectpath,
2948 .brl_lock_windows_fn = smb_full_audit_brl_lock_windows,
2949 .brl_unlock_windows_fn = smb_full_audit_brl_unlock_windows,
2950 .strict_lock_check_fn = smb_full_audit_strict_lock_check,
2951 .translate_name_fn = smb_full_audit_translate_name,
2952 .parent_pathname_fn = smb_full_audit_parent_pathname,
2953 .fsctl_fn = smb_full_audit_fsctl,
2954 .get_dos_attributes_send_fn = smb_full_audit_get_dos_attributes_send,
2955 .get_dos_attributes_recv_fn = smb_full_audit_get_dos_attributes_recv,
2956 .fget_dos_attributes_fn = smb_full_audit_fget_dos_attributes,
2957 .fset_dos_attributes_fn = smb_full_audit_fset_dos_attributes,
2958 .fget_nt_acl_fn = smb_full_audit_fget_nt_acl,
2959 .fset_nt_acl_fn = smb_full_audit_fset_nt_acl,
2960 .audit_file_fn = smb_full_audit_audit_file,
2961 .sys_acl_get_fd_fn = smb_full_audit_sys_acl_get_fd,
2962 .sys_acl_blob_get_fd_fn = smb_full_audit_sys_acl_blob_get_fd,
2963 .sys_acl_set_fd_fn = smb_full_audit_sys_acl_set_fd,
2964 .sys_acl_delete_def_fd_fn = smb_full_audit_sys_acl_delete_def_fd,
2965 .getxattr_fn = smb_full_audit_getxattr,
2966 .getxattrat_send_fn = smb_full_audit_getxattrat_send,
2967 .getxattrat_recv_fn = smb_full_audit_getxattrat_recv,
2968 .fgetxattr_fn = smb_full_audit_fgetxattr,
2969 .flistxattr_fn = smb_full_audit_flistxattr,
2970 .fremovexattr_fn = smb_full_audit_fremovexattr,
2971 .fsetxattr_fn = smb_full_audit_fsetxattr,
2972 .aio_force_fn = smb_full_audit_aio_force,
2973 .durable_cookie_fn = smb_full_audit_durable_cookie,
2974 .durable_disconnect_fn = smb_full_audit_durable_disconnect,
2975 .durable_reconnect_fn = smb_full_audit_durable_reconnect,
2976 .freaddir_attr_fn = smb_full_audit_freaddir_attr,
2980 NTSTATUS vfs_full_audit_init(TALLOC_CTX *ctx)
2984 smb_vfs_assert_all_fns(&vfs_full_audit_fns, "full_audit");
2986 ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "full_audit",
2987 &vfs_full_audit_fns);
2989 if (!NT_STATUS_IS_OK(ret))
2992 vfs_full_audit_debug_level = debug_add_class("full_audit");
2993 if (vfs_full_audit_debug_level == -1) {
2994 vfs_full_audit_debug_level = DBGC_VFS;
2995 DEBUG(0, ("vfs_full_audit: Couldn't register custom debugging "
2998 DEBUG(10, ("vfs_full_audit: Debug class number of "
2999 "'full_audit': %d\n", vfs_full_audit_debug_level));