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"
76 #include "source3/lib/substitute.h"
78 static int vfs_full_audit_debug_level = DBGC_VFS;
80 struct vfs_full_audit_private_data {
81 struct bitmap *success_ops;
82 struct bitmap *failure_ops;
90 #define DBGC_CLASS vfs_full_audit_debug_level
92 typedef enum _vfs_op_type {
97 SMB_VFS_OP_CONNECT = 0,
98 SMB_VFS_OP_DISCONNECT,
100 SMB_VFS_OP_GET_QUOTA,
101 SMB_VFS_OP_SET_QUOTA,
102 SMB_VFS_OP_GET_SHADOW_COPY_DATA,
104 SMB_VFS_OP_FS_CAPABILITIES,
105 SMB_VFS_OP_GET_DFS_REFERRALS,
106 SMB_VFS_OP_CREATE_DFS_PATHAT,
107 SMB_VFS_OP_READ_DFS_PATHAT,
109 /* Directory operations */
111 SMB_VFS_OP_FDOPENDIR,
115 SMB_VFS_OP_REWINDDIR,
119 /* File operations */
123 SMB_VFS_OP_CREATE_FILE,
127 SMB_VFS_OP_PREAD_SEND,
128 SMB_VFS_OP_PREAD_RECV,
131 SMB_VFS_OP_PWRITE_SEND,
132 SMB_VFS_OP_PWRITE_RECV,
138 SMB_VFS_OP_FSYNC_SEND,
139 SMB_VFS_OP_FSYNC_RECV,
144 SMB_VFS_OP_GET_ALLOC_SIZE,
153 SMB_VFS_OP_FTRUNCATE,
154 SMB_VFS_OP_FALLOCATE,
156 SMB_VFS_OP_FILESYSTEM_SHAREMODE,
158 SMB_VFS_OP_LINUX_SETLEASE,
160 SMB_VFS_OP_SYMLINKAT,
161 SMB_VFS_OP_READLINKAT,
166 SMB_VFS_OP_FILE_ID_CREATE,
167 SMB_VFS_OP_FS_FILE_ID,
168 SMB_VFS_OP_FSTREAMINFO,
169 SMB_VFS_OP_GET_REAL_FILENAME,
170 SMB_VFS_OP_CONNECTPATH,
171 SMB_VFS_OP_BRL_LOCK_WINDOWS,
172 SMB_VFS_OP_BRL_UNLOCK_WINDOWS,
173 SMB_VFS_OP_STRICT_LOCK_CHECK,
174 SMB_VFS_OP_TRANSLATE_NAME,
175 SMB_VFS_OP_PARENT_PATHNAME,
177 SMB_VFS_OP_OFFLOAD_READ_SEND,
178 SMB_VFS_OP_OFFLOAD_READ_RECV,
179 SMB_VFS_OP_OFFLOAD_WRITE_SEND,
180 SMB_VFS_OP_OFFLOAD_WRITE_RECV,
181 SMB_VFS_OP_FGET_COMPRESSION,
182 SMB_VFS_OP_SET_COMPRESSION,
183 SMB_VFS_OP_SNAP_CHECK_PATH,
184 SMB_VFS_OP_SNAP_CREATE,
185 SMB_VFS_OP_SNAP_DELETE,
187 /* DOS attribute operations. */
188 SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
189 SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV,
190 SMB_VFS_OP_FGET_DOS_ATTRIBUTES,
191 SMB_VFS_OP_FSET_DOS_ATTRIBUTES,
193 /* NT ACL operations. */
195 SMB_VFS_OP_FGET_NT_ACL,
196 SMB_VFS_OP_FSET_NT_ACL,
197 SMB_VFS_OP_AUDIT_FILE,
199 /* POSIX ACL operations. */
201 SMB_VFS_OP_SYS_ACL_GET_FD,
202 SMB_VFS_OP_SYS_ACL_BLOB_GET_FD,
203 SMB_VFS_OP_SYS_ACL_SET_FD,
204 SMB_VFS_OP_SYS_ACL_DELETE_DEF_FD,
207 SMB_VFS_OP_GETXATTRAT_SEND,
208 SMB_VFS_OP_GETXATTRAT_RECV,
209 SMB_VFS_OP_FGETXATTR,
210 SMB_VFS_OP_FLISTXATTR,
211 SMB_VFS_OP_REMOVEXATTR,
212 SMB_VFS_OP_FREMOVEXATTR,
213 SMB_VFS_OP_FSETXATTR,
216 SMB_VFS_OP_AIO_FORCE,
218 /* offline operations */
219 SMB_VFS_OP_IS_OFFLINE,
220 SMB_VFS_OP_SET_OFFLINE,
222 /* Durable handle operations. */
223 SMB_VFS_OP_DURABLE_COOKIE,
224 SMB_VFS_OP_DURABLE_DISCONNECT,
225 SMB_VFS_OP_DURABLE_RECONNECT,
227 SMB_VFS_OP_FREADDIR_ATTR,
229 /* This should always be last enum value */
234 /* The following array *must* be in the same order as defined in vfs_op_type */
240 { SMB_VFS_OP_CONNECT, "connect" },
241 { SMB_VFS_OP_DISCONNECT, "disconnect" },
242 { SMB_VFS_OP_DISK_FREE, "disk_free" },
243 { SMB_VFS_OP_GET_QUOTA, "get_quota" },
244 { SMB_VFS_OP_SET_QUOTA, "set_quota" },
245 { SMB_VFS_OP_GET_SHADOW_COPY_DATA, "get_shadow_copy_data" },
246 { SMB_VFS_OP_STATVFS, "statvfs" },
247 { SMB_VFS_OP_FS_CAPABILITIES, "fs_capabilities" },
248 { SMB_VFS_OP_GET_DFS_REFERRALS, "get_dfs_referrals" },
249 { SMB_VFS_OP_CREATE_DFS_PATHAT, "create_dfs_pathat" },
250 { SMB_VFS_OP_READ_DFS_PATHAT, "read_dfs_pathat" },
251 { SMB_VFS_OP_FDOPENDIR, "fdopendir" },
252 { SMB_VFS_OP_READDIR, "readdir" },
253 { SMB_VFS_OP_SEEKDIR, "seekdir" },
254 { SMB_VFS_OP_TELLDIR, "telldir" },
255 { SMB_VFS_OP_REWINDDIR, "rewinddir" },
256 { SMB_VFS_OP_MKDIRAT, "mkdirat" },
257 { SMB_VFS_OP_CLOSEDIR, "closedir" },
258 { SMB_VFS_OP_OPEN, "open" },
259 { SMB_VFS_OP_OPENAT, "openat" },
260 { SMB_VFS_OP_CREATE_FILE, "create_file" },
261 { SMB_VFS_OP_CLOSE, "close" },
262 { SMB_VFS_OP_READ, "read" },
263 { SMB_VFS_OP_PREAD, "pread" },
264 { SMB_VFS_OP_PREAD_SEND, "pread_send" },
265 { SMB_VFS_OP_PREAD_RECV, "pread_recv" },
266 { SMB_VFS_OP_WRITE, "write" },
267 { SMB_VFS_OP_PWRITE, "pwrite" },
268 { SMB_VFS_OP_PWRITE_SEND, "pwrite_send" },
269 { SMB_VFS_OP_PWRITE_RECV, "pwrite_recv" },
270 { SMB_VFS_OP_LSEEK, "lseek" },
271 { SMB_VFS_OP_SENDFILE, "sendfile" },
272 { SMB_VFS_OP_RECVFILE, "recvfile" },
273 { SMB_VFS_OP_RENAMEAT, "renameat" },
274 { SMB_VFS_OP_FSYNC, "fsync" },
275 { SMB_VFS_OP_FSYNC_SEND, "fsync_send" },
276 { SMB_VFS_OP_FSYNC_RECV, "fsync_recv" },
277 { SMB_VFS_OP_STAT, "stat" },
278 { SMB_VFS_OP_FSTAT, "fstat" },
279 { SMB_VFS_OP_LSTAT, "lstat" },
280 { SMB_VFS_OP_FSTATAT, "fstatat" },
281 { SMB_VFS_OP_GET_ALLOC_SIZE, "get_alloc_size" },
282 { SMB_VFS_OP_UNLINKAT, "unlinkat" },
283 { SMB_VFS_OP_FCHMOD, "fchmod" },
284 { SMB_VFS_OP_FCHOWN, "fchown" },
285 { SMB_VFS_OP_LCHOWN, "lchown" },
286 { SMB_VFS_OP_CHDIR, "chdir" },
287 { SMB_VFS_OP_GETWD, "getwd" },
288 { SMB_VFS_OP_NTIMES, "ntimes" },
289 { SMB_VFS_OP_FNTIMES, "fntimes" },
290 { SMB_VFS_OP_FTRUNCATE, "ftruncate" },
291 { SMB_VFS_OP_FALLOCATE,"fallocate" },
292 { SMB_VFS_OP_LOCK, "lock" },
293 { SMB_VFS_OP_FILESYSTEM_SHAREMODE, "filesystem_sharemode" },
294 { SMB_VFS_OP_FCNTL, "fcntl" },
295 { SMB_VFS_OP_LINUX_SETLEASE, "linux_setlease" },
296 { SMB_VFS_OP_GETLOCK, "getlock" },
297 { SMB_VFS_OP_SYMLINKAT, "symlinkat" },
298 { SMB_VFS_OP_READLINKAT,"readlinkat" },
299 { SMB_VFS_OP_LINKAT, "linkat" },
300 { SMB_VFS_OP_MKNODAT, "mknodat" },
301 { SMB_VFS_OP_REALPATH, "realpath" },
302 { SMB_VFS_OP_FCHFLAGS, "fchflags" },
303 { SMB_VFS_OP_FILE_ID_CREATE, "file_id_create" },
304 { SMB_VFS_OP_FS_FILE_ID, "fs_file_id" },
305 { SMB_VFS_OP_FSTREAMINFO, "fstreaminfo" },
306 { SMB_VFS_OP_GET_REAL_FILENAME, "get_real_filename" },
307 { SMB_VFS_OP_CONNECTPATH, "connectpath" },
308 { SMB_VFS_OP_BRL_LOCK_WINDOWS, "brl_lock_windows" },
309 { SMB_VFS_OP_BRL_UNLOCK_WINDOWS, "brl_unlock_windows" },
310 { SMB_VFS_OP_STRICT_LOCK_CHECK, "strict_lock_check" },
311 { SMB_VFS_OP_TRANSLATE_NAME, "translate_name" },
312 { SMB_VFS_OP_PARENT_PATHNAME, "parent_pathname" },
313 { SMB_VFS_OP_FSCTL, "fsctl" },
314 { SMB_VFS_OP_OFFLOAD_READ_SEND, "offload_read_send" },
315 { SMB_VFS_OP_OFFLOAD_READ_RECV, "offload_read_recv" },
316 { SMB_VFS_OP_OFFLOAD_WRITE_SEND, "offload_write_send" },
317 { SMB_VFS_OP_OFFLOAD_WRITE_RECV, "offload_write_recv" },
318 { SMB_VFS_OP_FGET_COMPRESSION, "fget_compression" },
319 { SMB_VFS_OP_SET_COMPRESSION, "set_compression" },
320 { SMB_VFS_OP_SNAP_CHECK_PATH, "snap_check_path" },
321 { SMB_VFS_OP_SNAP_CREATE, "snap_create" },
322 { SMB_VFS_OP_SNAP_DELETE, "snap_delete" },
323 { SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND, "get_dos_attributes_send" },
324 { SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV, "get_dos_attributes_recv" },
325 { SMB_VFS_OP_FGET_DOS_ATTRIBUTES, "fget_dos_attributes" },
326 { SMB_VFS_OP_FSET_DOS_ATTRIBUTES, "fset_dos_attributes" },
327 { SMB_VFS_OP_FGET_NT_ACL, "fget_nt_acl" },
328 { SMB_VFS_OP_FSET_NT_ACL, "fset_nt_acl" },
329 { SMB_VFS_OP_AUDIT_FILE, "audit_file" },
330 { SMB_VFS_OP_SYS_ACL_GET_FD, "sys_acl_get_fd" },
331 { SMB_VFS_OP_SYS_ACL_BLOB_GET_FD, "sys_acl_blob_get_fd" },
332 { SMB_VFS_OP_SYS_ACL_SET_FD, "sys_acl_set_fd" },
333 { SMB_VFS_OP_SYS_ACL_DELETE_DEF_FD, "sys_acl_delete_def_fd" },
334 { SMB_VFS_OP_GETXATTRAT_SEND, "getxattrat_send" },
335 { SMB_VFS_OP_GETXATTRAT_RECV, "getxattrat_recv" },
336 { SMB_VFS_OP_FGETXATTR, "fgetxattr" },
337 { SMB_VFS_OP_FLISTXATTR, "flistxattr" },
338 { SMB_VFS_OP_REMOVEXATTR, "removexattr" },
339 { SMB_VFS_OP_FREMOVEXATTR, "fremovexattr" },
340 { SMB_VFS_OP_FSETXATTR, "fsetxattr" },
341 { SMB_VFS_OP_AIO_FORCE, "aio_force" },
342 { SMB_VFS_OP_IS_OFFLINE, "is_offline" },
343 { SMB_VFS_OP_SET_OFFLINE, "set_offline" },
344 { SMB_VFS_OP_DURABLE_COOKIE, "durable_cookie" },
345 { SMB_VFS_OP_DURABLE_DISCONNECT, "durable_disconnect" },
346 { SMB_VFS_OP_DURABLE_RECONNECT, "durable_reconnect" },
347 { SMB_VFS_OP_FREADDIR_ATTR, "freaddir_attr" },
348 { SMB_VFS_OP_LAST, NULL }
351 static int audit_syslog_facility(vfs_handle_struct *handle)
353 static const struct enum_list enum_log_facilities[] = {
355 { LOG_AUTH, "AUTH" },
358 { LOG_AUTHPRIV, "AUTHPRIV" },
361 { LOG_AUDIT, "AUDIT" },
364 { LOG_CONSOLE, "CONSOLE" },
367 { LOG_CRON, "CRON" },
370 { LOG_DAEMON, "DAEMON" },
376 { LOG_INSTALL, "INSTALL" },
379 { LOG_KERN, "KERN" },
382 { LOG_LAUNCHD, "LAUNCHD" },
385 { LOG_LFMT, "LFMT" },
391 { LOG_MAIL, "MAIL" },
394 { LOG_MEGASAFE, "MEGASAFE" },
397 { LOG_NETINFO, "NETINFO" },
400 { LOG_NEWS, "NEWS" },
402 #ifdef LOG_NFACILITIES
403 { LOG_NFACILITIES, "NFACILITIES" },
411 #ifdef LOG_REMOTEAUTH
412 { LOG_REMOTEAUTH, "REMOTEAUTH" },
415 { LOG_SECURITY, "SECURITY" },
418 { LOG_SYSLOG, "SYSLOG" },
421 { LOG_USER, "USER" },
424 { LOG_UUCP, "UUCP" },
426 { LOG_LOCAL0, "LOCAL0" },
427 { LOG_LOCAL1, "LOCAL1" },
428 { LOG_LOCAL2, "LOCAL2" },
429 { LOG_LOCAL3, "LOCAL3" },
430 { LOG_LOCAL4, "LOCAL4" },
431 { LOG_LOCAL5, "LOCAL5" },
432 { LOG_LOCAL6, "LOCAL6" },
433 { LOG_LOCAL7, "LOCAL7" },
439 facility = lp_parm_enum(SNUM(handle->conn), "full_audit", "facility", enum_log_facilities, LOG_USER);
444 static int audit_syslog_priority(vfs_handle_struct *handle)
446 static const struct enum_list enum_log_priorities[] = {
447 { LOG_EMERG, "EMERG" },
448 { LOG_ALERT, "ALERT" },
449 { LOG_CRIT, "CRIT" },
451 { LOG_WARNING, "WARNING" },
452 { LOG_NOTICE, "NOTICE" },
453 { LOG_INFO, "INFO" },
454 { LOG_DEBUG, "DEBUG" },
460 priority = lp_parm_enum(SNUM(handle->conn), "full_audit", "priority",
461 enum_log_priorities, LOG_NOTICE);
462 if (priority == -1) {
463 priority = LOG_WARNING;
469 static char *audit_prefix(TALLOC_CTX *ctx, connection_struct *conn)
471 const struct loadparm_substitution *lp_sub =
472 loadparm_s3_global_substitution();
476 prefix = talloc_strdup(ctx,
477 lp_parm_const_string(SNUM(conn), "full_audit",
482 result = talloc_sub_full(ctx,
483 lp_servicename(talloc_tos(), lp_sub, SNUM(conn)),
484 conn->session_info->unix_info->unix_name,
486 conn->session_info->unix_token->gid,
487 conn->session_info->unix_info->sanitized_username,
488 conn->session_info->info->domain_name,
494 static bool log_success(struct vfs_full_audit_private_data *pd, vfs_op_type op)
496 if (pd->success_ops == NULL) {
500 return bitmap_query(pd->success_ops, op);
503 static bool log_failure(struct vfs_full_audit_private_data *pd, vfs_op_type op)
505 if (pd->failure_ops == NULL)
508 return bitmap_query(pd->failure_ops, op);
511 static struct bitmap *init_bitmap(TALLOC_CTX *mem_ctx, const char **ops)
519 bm = bitmap_talloc(mem_ctx, SMB_VFS_OP_LAST);
521 DEBUG(0, ("Could not alloc bitmap -- "
522 "defaulting to logging everything\n"));
526 for (; *ops != NULL; ops += 1) {
531 if (strequal(*ops, "all")) {
532 for (i=0; i<SMB_VFS_OP_LAST; i++) {
538 if (strequal(*ops, "none")) {
548 for (i=0; i<SMB_VFS_OP_LAST; i++) {
549 if ((vfs_op_names[i].name == NULL)
550 || (vfs_op_names[i].type != i)) {
551 smb_panic("vfs_full_audit.c: name table not "
552 "in sync with vfs_op_type enums\n");
554 if (strequal(op, vfs_op_names[i].name)) {
563 if (i == SMB_VFS_OP_LAST) {
564 DEBUG(0, ("Could not find opname %s, logging all\n",
573 static const char *audit_opname(vfs_op_type op)
575 if (op >= SMB_VFS_OP_LAST)
576 return "INVALID VFS OP";
577 return vfs_op_names[op].name;
580 static TALLOC_CTX *tmp_do_log_ctx;
582 * Get us a temporary talloc context usable just for DEBUG arguments
584 static TALLOC_CTX *do_log_ctx(void)
586 if (tmp_do_log_ctx == NULL) {
587 tmp_do_log_ctx = talloc_named_const(NULL, 0, "do_log_ctx");
589 return tmp_do_log_ctx;
592 static void do_log(vfs_op_type op, bool success, vfs_handle_struct *handle,
593 const char *format, ...) PRINTF_ATTRIBUTE(4, 5);
595 static void do_log(vfs_op_type op, bool success, vfs_handle_struct *handle,
596 const char *format, ...)
598 struct vfs_full_audit_private_data *pd;
600 char *audit_pre = NULL;
604 SMB_VFS_HANDLE_GET_DATA(handle, pd,
605 struct vfs_full_audit_private_data,
608 if (success && (!log_success(pd, op)))
611 if (!success && (!log_failure(pd, op)))
615 fstrcpy(err_msg, "ok");
617 fstr_sprintf(err_msg, "fail (%s)", strerror(errno));
619 va_start(ap, format);
620 op_msg = talloc_vasprintf(talloc_tos(), format, ap);
627 audit_pre = audit_prefix(talloc_tos(), handle->conn);
633 * Specify the facility to interoperate with other syslog
634 * callers (smbd for example).
636 priority = pd->syslog_priority | pd->syslog_facility;
638 syslog(priority, "%s|%s|%s|%s\n",
639 audit_pre ? audit_pre : "",
640 audit_opname(op), err_msg, op_msg);
642 DEBUG(1, ("%s|%s|%s|%s\n",
643 audit_pre ? audit_pre : "",
644 audit_opname(op), err_msg, op_msg));
647 TALLOC_FREE(audit_pre);
649 TALLOC_FREE(tmp_do_log_ctx);
653 * Return a string using the do_log_ctx()
655 static const char *smb_fname_str_do_log(struct connection_struct *conn,
656 const struct smb_filename *smb_fname)
661 if (smb_fname == NULL) {
665 if (smb_fname->base_name[0] != '/') {
666 char *abs_name = NULL;
667 struct smb_filename *fname_copy = cp_smb_filename(
670 if (fname_copy == NULL) {
674 if (!ISDOT(smb_fname->base_name)) {
675 abs_name = talloc_asprintf(do_log_ctx(),
677 conn->cwd_fsp->fsp_name->base_name,
678 smb_fname->base_name);
680 abs_name = talloc_strdup(do_log_ctx(),
681 conn->cwd_fsp->fsp_name->base_name);
683 if (abs_name == NULL) {
686 fname_copy->base_name = abs_name;
687 smb_fname = fname_copy;
690 status = get_full_smb_filename(do_log_ctx(), smb_fname, &fname);
691 if (!NT_STATUS_IS_OK(status)) {
698 * Return an fsp debug string using the do_log_ctx()
700 static const char *fsp_str_do_log(const struct files_struct *fsp)
702 return smb_fname_str_do_log(fsp->conn, fsp->fsp_name);
705 /* Implementation of vfs_ops. Pass everything on to the default
706 operation but log event first. */
708 static int smb_full_audit_connect(vfs_handle_struct *handle,
709 const char *svc, const char *user)
712 const char *none[] = { "none" };
713 struct vfs_full_audit_private_data *pd = NULL;
715 result = SMB_VFS_NEXT_CONNECT(handle, svc, user);
720 pd = talloc_zero(handle, struct vfs_full_audit_private_data);
722 SMB_VFS_NEXT_DISCONNECT(handle);
726 pd->syslog_facility = audit_syslog_facility(handle);
727 if (pd->syslog_facility == -1) {
728 DEBUG(1, ("%s: Unknown facility %s\n", __func__,
729 lp_parm_const_string(SNUM(handle->conn),
730 "full_audit", "facility",
732 SMB_VFS_NEXT_DISCONNECT(handle);
736 pd->syslog_priority = audit_syslog_priority(handle);
738 pd->log_secdesc = lp_parm_bool(SNUM(handle->conn),
739 "full_audit", "log_secdesc", false);
741 pd->do_syslog = lp_parm_bool(SNUM(handle->conn),
742 "full_audit", "syslog", true);
746 openlog("smbd_audit", 0, pd->syslog_facility);
750 pd->success_ops = init_bitmap(
751 pd, lp_parm_string_list(SNUM(handle->conn), "full_audit",
753 pd->failure_ops = init_bitmap(
754 pd, lp_parm_string_list(SNUM(handle->conn), "full_audit",
757 /* Store the private data. */
758 SMB_VFS_HANDLE_SET_DATA(handle, pd, NULL,
759 struct vfs_full_audit_private_data, return -1);
761 do_log(SMB_VFS_OP_CONNECT, True, handle,
767 static void smb_full_audit_disconnect(vfs_handle_struct *handle)
769 const struct loadparm_substitution *lp_sub =
770 loadparm_s3_global_substitution();
772 SMB_VFS_NEXT_DISCONNECT(handle);
774 do_log(SMB_VFS_OP_DISCONNECT, True, handle,
775 "%s", lp_servicename(talloc_tos(), lp_sub, SNUM(handle->conn)));
777 /* The bitmaps will be disconnected when the private
781 static uint64_t smb_full_audit_disk_free(vfs_handle_struct *handle,
782 const struct smb_filename *smb_fname,
789 result = SMB_VFS_NEXT_DISK_FREE(handle, smb_fname, bsize, dfree, dsize);
791 /* Don't have a reasonable notion of failure here */
793 do_log(SMB_VFS_OP_DISK_FREE,
797 smb_fname_str_do_log(handle->conn, smb_fname));
802 static int smb_full_audit_get_quota(struct vfs_handle_struct *handle,
803 const struct smb_filename *smb_fname,
804 enum SMB_QUOTA_TYPE qtype,
810 result = SMB_VFS_NEXT_GET_QUOTA(handle, smb_fname, qtype, id, qt);
812 do_log(SMB_VFS_OP_GET_QUOTA,
816 smb_fname_str_do_log(handle->conn, smb_fname));
821 static int smb_full_audit_set_quota(struct vfs_handle_struct *handle,
822 enum SMB_QUOTA_TYPE qtype, unid_t id,
827 result = SMB_VFS_NEXT_SET_QUOTA(handle, qtype, id, qt);
829 do_log(SMB_VFS_OP_SET_QUOTA, (result >= 0), handle, "");
834 static int smb_full_audit_get_shadow_copy_data(struct vfs_handle_struct *handle,
835 struct files_struct *fsp,
836 struct shadow_copy_data *shadow_copy_data,
841 result = SMB_VFS_NEXT_GET_SHADOW_COPY_DATA(handle, fsp, shadow_copy_data, labels);
843 do_log(SMB_VFS_OP_GET_SHADOW_COPY_DATA, (result >= 0), handle, "");
848 static int smb_full_audit_statvfs(struct vfs_handle_struct *handle,
849 const struct smb_filename *smb_fname,
850 struct vfs_statvfs_struct *statbuf)
854 result = SMB_VFS_NEXT_STATVFS(handle, smb_fname, statbuf);
856 do_log(SMB_VFS_OP_STATVFS, (result >= 0), handle, "");
861 static uint32_t smb_full_audit_fs_capabilities(struct vfs_handle_struct *handle, enum timestamp_set_resolution *p_ts_res)
865 result = SMB_VFS_NEXT_FS_CAPABILITIES(handle, p_ts_res);
867 do_log(SMB_VFS_OP_FS_CAPABILITIES, true, handle, "");
872 static NTSTATUS smb_full_audit_get_dfs_referrals(
873 struct vfs_handle_struct *handle,
874 struct dfs_GetDFSReferral *r)
878 status = SMB_VFS_NEXT_GET_DFS_REFERRALS(handle, r);
880 do_log(SMB_VFS_OP_GET_DFS_REFERRALS, NT_STATUS_IS_OK(status),
886 static NTSTATUS smb_full_audit_create_dfs_pathat(struct vfs_handle_struct *handle,
887 struct files_struct *dirfsp,
888 const struct smb_filename *smb_fname,
889 const struct referral *reflist,
890 size_t referral_count)
893 struct smb_filename *full_fname = NULL;
895 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
898 if (full_fname == NULL) {
899 return NT_STATUS_NO_MEMORY;
902 status = SMB_VFS_NEXT_CREATE_DFS_PATHAT(handle,
908 do_log(SMB_VFS_OP_CREATE_DFS_PATHAT,
909 NT_STATUS_IS_OK(status),
912 smb_fname_str_do_log(handle->conn, full_fname));
914 TALLOC_FREE(full_fname);
918 static NTSTATUS smb_full_audit_read_dfs_pathat(struct vfs_handle_struct *handle,
920 struct files_struct *dirfsp,
921 struct smb_filename *smb_fname,
922 struct referral **ppreflist,
923 size_t *preferral_count)
925 struct smb_filename *full_fname = NULL;
928 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
931 if (full_fname == NULL) {
932 return NT_STATUS_NO_MEMORY;
935 status = SMB_VFS_NEXT_READ_DFS_PATHAT(handle,
942 do_log(SMB_VFS_OP_READ_DFS_PATHAT,
943 NT_STATUS_IS_OK(status),
946 smb_fname_str_do_log(handle->conn, full_fname));
948 TALLOC_FREE(full_fname);
952 static NTSTATUS smb_full_audit_snap_check_path(struct vfs_handle_struct *handle,
954 const char *service_path,
959 status = SMB_VFS_NEXT_SNAP_CHECK_PATH(handle, mem_ctx, service_path,
961 do_log(SMB_VFS_OP_SNAP_CHECK_PATH, NT_STATUS_IS_OK(status),
967 static NTSTATUS smb_full_audit_snap_create(struct vfs_handle_struct *handle,
969 const char *base_volume,
977 status = SMB_VFS_NEXT_SNAP_CREATE(handle, mem_ctx, base_volume, tstamp,
978 rw, base_path, snap_path);
979 do_log(SMB_VFS_OP_SNAP_CREATE, NT_STATUS_IS_OK(status), handle, "");
984 static NTSTATUS smb_full_audit_snap_delete(struct vfs_handle_struct *handle,
991 status = SMB_VFS_NEXT_SNAP_DELETE(handle, mem_ctx, base_path,
993 do_log(SMB_VFS_OP_SNAP_DELETE, NT_STATUS_IS_OK(status), handle, "");
998 static DIR *smb_full_audit_fdopendir(vfs_handle_struct *handle,
999 files_struct *fsp, const char *mask, uint32_t attr)
1003 result = SMB_VFS_NEXT_FDOPENDIR(handle, fsp, mask, attr);
1005 do_log(SMB_VFS_OP_FDOPENDIR, (result != NULL), handle, "%s",
1006 fsp_str_do_log(fsp));
1011 static struct dirent *smb_full_audit_readdir(vfs_handle_struct *handle,
1012 struct files_struct *dirfsp,
1014 SMB_STRUCT_STAT *sbuf)
1016 struct dirent *result;
1018 result = SMB_VFS_NEXT_READDIR(handle, dirfsp, dirp, sbuf);
1020 /* This operation has no reasonable error condition
1021 * (End of dir is also failure), so always succeed.
1023 do_log(SMB_VFS_OP_READDIR, True, handle, "");
1028 static void smb_full_audit_seekdir(vfs_handle_struct *handle,
1029 DIR *dirp, long offset)
1031 SMB_VFS_NEXT_SEEKDIR(handle, dirp, offset);
1033 do_log(SMB_VFS_OP_SEEKDIR, True, handle, "");
1036 static long smb_full_audit_telldir(vfs_handle_struct *handle,
1041 result = SMB_VFS_NEXT_TELLDIR(handle, dirp);
1043 do_log(SMB_VFS_OP_TELLDIR, True, handle, "");
1048 static void smb_full_audit_rewinddir(vfs_handle_struct *handle,
1051 SMB_VFS_NEXT_REWINDDIR(handle, dirp);
1053 do_log(SMB_VFS_OP_REWINDDIR, True, handle, "");
1056 static int smb_full_audit_mkdirat(vfs_handle_struct *handle,
1057 struct files_struct *dirfsp,
1058 const struct smb_filename *smb_fname,
1061 struct smb_filename *full_fname = NULL;
1064 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1067 if (full_fname == NULL) {
1072 result = SMB_VFS_NEXT_MKDIRAT(handle,
1077 do_log(SMB_VFS_OP_MKDIRAT,
1081 smb_fname_str_do_log(handle->conn, full_fname));
1083 TALLOC_FREE(full_fname);
1088 static int smb_full_audit_closedir(vfs_handle_struct *handle,
1093 result = SMB_VFS_NEXT_CLOSEDIR(handle, dirp);
1095 do_log(SMB_VFS_OP_CLOSEDIR, (result >= 0), handle, "");
1100 static int smb_full_audit_openat(vfs_handle_struct *handle,
1101 const struct files_struct *dirfsp,
1102 const struct smb_filename *smb_fname,
1103 struct files_struct *fsp,
1109 result = SMB_VFS_NEXT_OPENAT(handle, dirfsp, smb_fname, fsp, flags, mode);
1111 do_log(SMB_VFS_OP_OPENAT, (result >= 0), handle, "%s|%s",
1112 ((flags & O_WRONLY) || (flags & O_RDWR))?"w":"r",
1113 fsp_str_do_log(fsp));
1118 static NTSTATUS smb_full_audit_create_file(vfs_handle_struct *handle,
1119 struct smb_request *req,
1120 struct smb_filename *smb_fname,
1121 uint32_t access_mask,
1122 uint32_t share_access,
1123 uint32_t create_disposition,
1124 uint32_t create_options,
1125 uint32_t file_attributes,
1126 uint32_t oplock_request,
1127 const struct smb2_lease *lease,
1128 uint64_t allocation_size,
1129 uint32_t private_flags,
1130 struct security_descriptor *sd,
1131 struct ea_list *ea_list,
1132 files_struct **result_fsp,
1134 const struct smb2_create_blobs *in_context_blobs,
1135 struct smb2_create_blobs *out_context_blobs)
1138 const char* str_create_disposition;
1140 switch (create_disposition) {
1141 case FILE_SUPERSEDE:
1142 str_create_disposition = "supersede";
1144 case FILE_OVERWRITE_IF:
1145 str_create_disposition = "overwrite_if";
1148 str_create_disposition = "open";
1150 case FILE_OVERWRITE:
1151 str_create_disposition = "overwrite";
1154 str_create_disposition = "create";
1157 str_create_disposition = "open_if";
1160 str_create_disposition = "unknown";
1163 result = SMB_VFS_NEXT_CREATE_FILE(
1164 handle, /* handle */
1166 smb_fname, /* fname */
1167 access_mask, /* access_mask */
1168 share_access, /* share_access */
1169 create_disposition, /* create_disposition*/
1170 create_options, /* create_options */
1171 file_attributes, /* file_attributes */
1172 oplock_request, /* oplock_request */
1174 allocation_size, /* allocation_size */
1177 ea_list, /* ea_list */
1178 result_fsp, /* result */
1180 in_context_blobs, out_context_blobs); /* create context */
1182 do_log(SMB_VFS_OP_CREATE_FILE, (NT_STATUS_IS_OK(result)), handle,
1183 "0x%x|%s|%s|%s", access_mask,
1184 create_options & FILE_DIRECTORY_FILE ? "dir" : "file",
1185 str_create_disposition,
1186 smb_fname_str_do_log(handle->conn, smb_fname));
1191 static int smb_full_audit_close(vfs_handle_struct *handle, files_struct *fsp)
1195 result = SMB_VFS_NEXT_CLOSE(handle, fsp);
1197 do_log(SMB_VFS_OP_CLOSE, (result >= 0), handle, "%s",
1198 fsp_str_do_log(fsp));
1203 static ssize_t smb_full_audit_pread(vfs_handle_struct *handle, files_struct *fsp,
1204 void *data, size_t n, off_t offset)
1208 result = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
1210 do_log(SMB_VFS_OP_PREAD, (result >= 0), handle, "%s",
1211 fsp_str_do_log(fsp));
1216 struct smb_full_audit_pread_state {
1217 vfs_handle_struct *handle;
1220 struct vfs_aio_state vfs_aio_state;
1223 static void smb_full_audit_pread_done(struct tevent_req *subreq);
1225 static struct tevent_req *smb_full_audit_pread_send(
1226 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1227 struct tevent_context *ev, struct files_struct *fsp,
1228 void *data, size_t n, off_t offset)
1230 struct tevent_req *req, *subreq;
1231 struct smb_full_audit_pread_state *state;
1233 req = tevent_req_create(mem_ctx, &state,
1234 struct smb_full_audit_pread_state);
1236 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
1237 fsp_str_do_log(fsp));
1240 state->handle = handle;
1243 subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
1245 if (tevent_req_nomem(subreq, req)) {
1246 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
1247 fsp_str_do_log(fsp));
1248 return tevent_req_post(req, ev);
1250 tevent_req_set_callback(subreq, smb_full_audit_pread_done, req);
1252 do_log(SMB_VFS_OP_PREAD_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1256 static void smb_full_audit_pread_done(struct tevent_req *subreq)
1258 struct tevent_req *req = tevent_req_callback_data(
1259 subreq, struct tevent_req);
1260 struct smb_full_audit_pread_state *state = tevent_req_data(
1261 req, struct smb_full_audit_pread_state);
1263 state->ret = SMB_VFS_PREAD_RECV(subreq, &state->vfs_aio_state);
1264 TALLOC_FREE(subreq);
1265 tevent_req_done(req);
1268 static ssize_t smb_full_audit_pread_recv(struct tevent_req *req,
1269 struct vfs_aio_state *vfs_aio_state)
1271 struct smb_full_audit_pread_state *state = tevent_req_data(
1272 req, struct smb_full_audit_pread_state);
1274 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1275 do_log(SMB_VFS_OP_PREAD_RECV, false, state->handle, "%s",
1276 fsp_str_do_log(state->fsp));
1280 do_log(SMB_VFS_OP_PREAD_RECV, (state->ret >= 0), state->handle, "%s",
1281 fsp_str_do_log(state->fsp));
1283 *vfs_aio_state = state->vfs_aio_state;
1287 static ssize_t smb_full_audit_pwrite(vfs_handle_struct *handle, files_struct *fsp,
1288 const void *data, size_t n,
1293 result = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
1295 do_log(SMB_VFS_OP_PWRITE, (result >= 0), handle, "%s",
1296 fsp_str_do_log(fsp));
1301 struct smb_full_audit_pwrite_state {
1302 vfs_handle_struct *handle;
1305 struct vfs_aio_state vfs_aio_state;
1308 static void smb_full_audit_pwrite_done(struct tevent_req *subreq);
1310 static struct tevent_req *smb_full_audit_pwrite_send(
1311 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1312 struct tevent_context *ev, struct files_struct *fsp,
1313 const void *data, size_t n, off_t offset)
1315 struct tevent_req *req, *subreq;
1316 struct smb_full_audit_pwrite_state *state;
1318 req = tevent_req_create(mem_ctx, &state,
1319 struct smb_full_audit_pwrite_state);
1321 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1322 fsp_str_do_log(fsp));
1325 state->handle = handle;
1328 subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
1330 if (tevent_req_nomem(subreq, req)) {
1331 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1332 fsp_str_do_log(fsp));
1333 return tevent_req_post(req, ev);
1335 tevent_req_set_callback(subreq, smb_full_audit_pwrite_done, req);
1337 do_log(SMB_VFS_OP_PWRITE_SEND, true, handle, "%s",
1338 fsp_str_do_log(fsp));
1342 static void smb_full_audit_pwrite_done(struct tevent_req *subreq)
1344 struct tevent_req *req = tevent_req_callback_data(
1345 subreq, struct tevent_req);
1346 struct smb_full_audit_pwrite_state *state = tevent_req_data(
1347 req, struct smb_full_audit_pwrite_state);
1349 state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->vfs_aio_state);
1350 TALLOC_FREE(subreq);
1351 tevent_req_done(req);
1354 static ssize_t smb_full_audit_pwrite_recv(struct tevent_req *req,
1355 struct vfs_aio_state *vfs_aio_state)
1357 struct smb_full_audit_pwrite_state *state = tevent_req_data(
1358 req, struct smb_full_audit_pwrite_state);
1360 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1361 do_log(SMB_VFS_OP_PWRITE_RECV, false, state->handle, "%s",
1362 fsp_str_do_log(state->fsp));
1366 do_log(SMB_VFS_OP_PWRITE_RECV, (state->ret >= 0), state->handle, "%s",
1367 fsp_str_do_log(state->fsp));
1369 *vfs_aio_state = state->vfs_aio_state;
1373 static off_t smb_full_audit_lseek(vfs_handle_struct *handle, files_struct *fsp,
1374 off_t offset, int whence)
1378 result = SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence);
1380 do_log(SMB_VFS_OP_LSEEK, (result != (ssize_t)-1), handle,
1381 "%s", fsp_str_do_log(fsp));
1386 static ssize_t smb_full_audit_sendfile(vfs_handle_struct *handle, int tofd,
1387 files_struct *fromfsp,
1388 const DATA_BLOB *hdr, off_t offset,
1393 result = SMB_VFS_NEXT_SENDFILE(handle, tofd, fromfsp, hdr, offset, n);
1395 do_log(SMB_VFS_OP_SENDFILE, (result >= 0), handle,
1396 "%s", fsp_str_do_log(fromfsp));
1401 static ssize_t smb_full_audit_recvfile(vfs_handle_struct *handle, int fromfd,
1402 files_struct *tofsp,
1408 result = SMB_VFS_NEXT_RECVFILE(handle, fromfd, tofsp, offset, n);
1410 do_log(SMB_VFS_OP_RECVFILE, (result >= 0), handle,
1411 "%s", fsp_str_do_log(tofsp));
1416 static int smb_full_audit_renameat(vfs_handle_struct *handle,
1417 files_struct *srcfsp,
1418 const struct smb_filename *smb_fname_src,
1419 files_struct *dstfsp,
1420 const struct smb_filename *smb_fname_dst)
1424 struct smb_filename *full_fname_src = NULL;
1425 struct smb_filename *full_fname_dst = NULL;
1427 full_fname_src = full_path_from_dirfsp_atname(talloc_tos(),
1430 if (full_fname_src == NULL) {
1434 full_fname_dst = full_path_from_dirfsp_atname(talloc_tos(),
1437 if (full_fname_dst == NULL) {
1438 TALLOC_FREE(full_fname_src);
1443 result = SMB_VFS_NEXT_RENAMEAT(handle,
1450 saved_errno = errno;
1452 do_log(SMB_VFS_OP_RENAMEAT, (result >= 0), handle, "%s|%s",
1453 smb_fname_str_do_log(handle->conn, full_fname_src),
1454 smb_fname_str_do_log(handle->conn, full_fname_dst));
1456 TALLOC_FREE(full_fname_src);
1457 TALLOC_FREE(full_fname_dst);
1460 errno = saved_errno;
1465 struct smb_full_audit_fsync_state {
1466 vfs_handle_struct *handle;
1469 struct vfs_aio_state vfs_aio_state;
1472 static void smb_full_audit_fsync_done(struct tevent_req *subreq);
1474 static struct tevent_req *smb_full_audit_fsync_send(
1475 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1476 struct tevent_context *ev, struct files_struct *fsp)
1478 struct tevent_req *req, *subreq;
1479 struct smb_full_audit_fsync_state *state;
1481 req = tevent_req_create(mem_ctx, &state,
1482 struct smb_full_audit_fsync_state);
1484 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1485 fsp_str_do_log(fsp));
1488 state->handle = handle;
1491 subreq = SMB_VFS_NEXT_FSYNC_SEND(state, ev, handle, fsp);
1492 if (tevent_req_nomem(subreq, req)) {
1493 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1494 fsp_str_do_log(fsp));
1495 return tevent_req_post(req, ev);
1497 tevent_req_set_callback(subreq, smb_full_audit_fsync_done, req);
1499 do_log(SMB_VFS_OP_FSYNC_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1503 static void smb_full_audit_fsync_done(struct tevent_req *subreq)
1505 struct tevent_req *req = tevent_req_callback_data(
1506 subreq, struct tevent_req);
1507 struct smb_full_audit_fsync_state *state = tevent_req_data(
1508 req, struct smb_full_audit_fsync_state);
1510 state->ret = SMB_VFS_FSYNC_RECV(subreq, &state->vfs_aio_state);
1511 TALLOC_FREE(subreq);
1512 tevent_req_done(req);
1515 static int smb_full_audit_fsync_recv(struct tevent_req *req,
1516 struct vfs_aio_state *vfs_aio_state)
1518 struct smb_full_audit_fsync_state *state = tevent_req_data(
1519 req, struct smb_full_audit_fsync_state);
1521 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1522 do_log(SMB_VFS_OP_FSYNC_RECV, false, state->handle, "%s",
1523 fsp_str_do_log(state->fsp));
1527 do_log(SMB_VFS_OP_FSYNC_RECV, (state->ret >= 0), state->handle, "%s",
1528 fsp_str_do_log(state->fsp));
1530 *vfs_aio_state = state->vfs_aio_state;
1534 static int smb_full_audit_stat(vfs_handle_struct *handle,
1535 struct smb_filename *smb_fname)
1539 result = SMB_VFS_NEXT_STAT(handle, smb_fname);
1541 do_log(SMB_VFS_OP_STAT, (result >= 0), handle, "%s",
1542 smb_fname_str_do_log(handle->conn, smb_fname));
1547 static int smb_full_audit_fstat(vfs_handle_struct *handle, files_struct *fsp,
1548 SMB_STRUCT_STAT *sbuf)
1552 result = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1554 do_log(SMB_VFS_OP_FSTAT, (result >= 0), handle, "%s",
1555 fsp_str_do_log(fsp));
1560 static int smb_full_audit_lstat(vfs_handle_struct *handle,
1561 struct smb_filename *smb_fname)
1565 result = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
1567 do_log(SMB_VFS_OP_LSTAT, (result >= 0), handle, "%s",
1568 smb_fname_str_do_log(handle->conn, smb_fname));
1573 static int smb_full_audit_fstatat(
1574 struct vfs_handle_struct *handle,
1575 const struct files_struct *dirfsp,
1576 const struct smb_filename *smb_fname,
1577 SMB_STRUCT_STAT *sbuf,
1582 result = SMB_VFS_NEXT_FSTATAT(handle, dirfsp, smb_fname, sbuf, flags);
1584 do_log(SMB_VFS_OP_FSTATAT,
1588 fsp_str_do_log(dirfsp),
1589 smb_fname_str_do_log(handle->conn, smb_fname));
1593 static uint64_t smb_full_audit_get_alloc_size(vfs_handle_struct *handle,
1594 files_struct *fsp, const SMB_STRUCT_STAT *sbuf)
1598 result = SMB_VFS_NEXT_GET_ALLOC_SIZE(handle, fsp, sbuf);
1600 do_log(SMB_VFS_OP_GET_ALLOC_SIZE, (result != (uint64_t)-1), handle,
1601 "%llu", (unsigned long long)result);
1606 static int smb_full_audit_unlinkat(vfs_handle_struct *handle,
1607 struct files_struct *dirfsp,
1608 const struct smb_filename *smb_fname,
1611 struct smb_filename *full_fname = NULL;
1614 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1617 if (full_fname == NULL) {
1621 result = SMB_VFS_NEXT_UNLINKAT(handle,
1626 do_log(SMB_VFS_OP_UNLINKAT, (result >= 0), handle, "%s",
1627 smb_fname_str_do_log(handle->conn, full_fname));
1629 TALLOC_FREE(full_fname);
1633 static int smb_full_audit_fchmod(vfs_handle_struct *handle, files_struct *fsp,
1638 result = SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1640 do_log(SMB_VFS_OP_FCHMOD, (result >= 0), handle,
1641 "%s|%o", fsp_str_do_log(fsp), mode);
1646 static int smb_full_audit_fchown(vfs_handle_struct *handle, files_struct *fsp,
1647 uid_t uid, gid_t gid)
1651 result = SMB_VFS_NEXT_FCHOWN(handle, fsp, uid, gid);
1653 do_log(SMB_VFS_OP_FCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1654 fsp_str_do_log(fsp), (long int)uid, (long int)gid);
1659 static int smb_full_audit_lchown(vfs_handle_struct *handle,
1660 const struct smb_filename *smb_fname,
1666 result = SMB_VFS_NEXT_LCHOWN(handle, smb_fname, uid, gid);
1668 do_log(SMB_VFS_OP_LCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1669 smb_fname->base_name, (long int)uid, (long int)gid);
1674 static int smb_full_audit_chdir(vfs_handle_struct *handle,
1675 const struct smb_filename *smb_fname)
1679 result = SMB_VFS_NEXT_CHDIR(handle, smb_fname);
1681 do_log(SMB_VFS_OP_CHDIR,
1685 smb_fname_str_do_log(handle->conn, smb_fname));
1690 static struct smb_filename *smb_full_audit_getwd(vfs_handle_struct *handle,
1693 struct smb_filename *result;
1695 result = SMB_VFS_NEXT_GETWD(handle, ctx);
1697 do_log(SMB_VFS_OP_GETWD, (result != NULL), handle, "%s",
1698 result == NULL? "" : result->base_name);
1703 static int smb_full_audit_fntimes(vfs_handle_struct *handle,
1705 struct smb_file_time *ft)
1708 time_t create_time = convert_timespec_to_time_t(ft->create_time);
1709 time_t atime = convert_timespec_to_time_t(ft->atime);
1710 time_t mtime = convert_timespec_to_time_t(ft->mtime);
1711 time_t ctime = convert_timespec_to_time_t(ft->ctime);
1712 const char *create_time_str = "";
1713 const char *atime_str = "";
1714 const char *mtime_str = "";
1715 const char *ctime_str = "";
1716 TALLOC_CTX *frame = talloc_stackframe();
1718 if (frame == NULL) {
1723 result = SMB_VFS_NEXT_FNTIMES(handle, fsp, ft);
1725 if (create_time > 0) {
1726 create_time_str = timestring(frame, create_time);
1729 atime_str = timestring(frame, atime);
1732 mtime_str = timestring(frame, mtime);
1735 ctime_str = timestring(frame, ctime);
1738 do_log(SMB_VFS_OP_FNTIMES,
1742 fsp_str_do_log(fsp),
1753 static int smb_full_audit_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
1758 result = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1760 do_log(SMB_VFS_OP_FTRUNCATE, (result >= 0), handle,
1761 "%s", fsp_str_do_log(fsp));
1766 static int smb_full_audit_fallocate(vfs_handle_struct *handle, files_struct *fsp,
1773 result = SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
1775 do_log(SMB_VFS_OP_FALLOCATE, (result >= 0), handle,
1776 "%s", fsp_str_do_log(fsp));
1781 static bool smb_full_audit_lock(vfs_handle_struct *handle, files_struct *fsp,
1782 int op, off_t offset, off_t count, int type)
1786 result = SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type);
1788 do_log(SMB_VFS_OP_LOCK, result, handle, "%s", fsp_str_do_log(fsp));
1793 static int smb_full_audit_filesystem_sharemode(struct vfs_handle_struct *handle,
1794 struct files_struct *fsp,
1795 uint32_t share_access,
1796 uint32_t access_mask)
1800 result = SMB_VFS_NEXT_FILESYSTEM_SHAREMODE(handle,
1805 do_log(SMB_VFS_OP_FILESYSTEM_SHAREMODE, (result >= 0), handle, "%s",
1806 fsp_str_do_log(fsp));
1811 static int smb_full_audit_fcntl(struct vfs_handle_struct *handle,
1812 struct files_struct *fsp,
1813 int cmd, va_list cmd_arg)
1816 va_list dup_cmd_arg;
1819 va_copy(dup_cmd_arg, cmd_arg);
1820 arg = va_arg(dup_cmd_arg, void *);
1821 result = SMB_VFS_NEXT_FCNTL(handle, fsp, cmd, arg);
1822 va_end(dup_cmd_arg);
1824 do_log(SMB_VFS_OP_FCNTL, (result >= 0), handle, "%s",
1825 fsp_str_do_log(fsp));
1830 static int smb_full_audit_linux_setlease(vfs_handle_struct *handle, files_struct *fsp,
1835 result = SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
1837 do_log(SMB_VFS_OP_LINUX_SETLEASE, (result >= 0), handle, "%s",
1838 fsp_str_do_log(fsp));
1843 static bool smb_full_audit_getlock(vfs_handle_struct *handle, files_struct *fsp,
1844 off_t *poffset, off_t *pcount, int *ptype, pid_t *ppid)
1848 result = SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype, ppid);
1850 do_log(SMB_VFS_OP_GETLOCK, result, handle, "%s", fsp_str_do_log(fsp));
1855 static int smb_full_audit_symlinkat(vfs_handle_struct *handle,
1856 const struct smb_filename *link_contents,
1857 struct files_struct *dirfsp,
1858 const struct smb_filename *new_smb_fname)
1860 struct smb_filename *full_fname = NULL;
1863 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1866 if (full_fname == NULL) {
1870 result = SMB_VFS_NEXT_SYMLINKAT(handle,
1875 do_log(SMB_VFS_OP_SYMLINKAT,
1879 link_contents->base_name,
1880 smb_fname_str_do_log(handle->conn, full_fname));
1882 TALLOC_FREE(full_fname);
1887 static int smb_full_audit_readlinkat(vfs_handle_struct *handle,
1888 const struct files_struct *dirfsp,
1889 const struct smb_filename *smb_fname,
1893 struct smb_filename *full_fname = NULL;
1896 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1899 if (full_fname == NULL) {
1903 result = SMB_VFS_NEXT_READLINKAT(handle,
1909 do_log(SMB_VFS_OP_READLINKAT,
1913 smb_fname_str_do_log(handle->conn, full_fname));
1915 TALLOC_FREE(full_fname);
1920 static int smb_full_audit_linkat(vfs_handle_struct *handle,
1921 files_struct *srcfsp,
1922 const struct smb_filename *old_smb_fname,
1923 files_struct *dstfsp,
1924 const struct smb_filename *new_smb_fname,
1927 struct smb_filename *old_full_fname = NULL;
1928 struct smb_filename *new_full_fname = NULL;
1931 old_full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1934 if (old_full_fname == NULL) {
1937 new_full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1940 if (new_full_fname == NULL) {
1941 TALLOC_FREE(old_full_fname);
1944 result = SMB_VFS_NEXT_LINKAT(handle,
1951 do_log(SMB_VFS_OP_LINKAT,
1955 smb_fname_str_do_log(handle->conn, old_full_fname),
1956 smb_fname_str_do_log(handle->conn, new_full_fname));
1958 TALLOC_FREE(old_full_fname);
1959 TALLOC_FREE(new_full_fname);
1964 static int smb_full_audit_mknodat(vfs_handle_struct *handle,
1965 files_struct *dirfsp,
1966 const struct smb_filename *smb_fname,
1970 struct smb_filename *full_fname = NULL;
1973 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1976 if (full_fname == NULL) {
1980 result = SMB_VFS_NEXT_MKNODAT(handle,
1986 do_log(SMB_VFS_OP_MKNODAT,
1990 smb_fname_str_do_log(handle->conn, full_fname));
1992 TALLOC_FREE(full_fname);
1997 static struct smb_filename *smb_full_audit_realpath(vfs_handle_struct *handle,
1999 const struct smb_filename *smb_fname)
2001 struct smb_filename *result_fname = NULL;
2003 result_fname = SMB_VFS_NEXT_REALPATH(handle, ctx, smb_fname);
2005 do_log(SMB_VFS_OP_REALPATH,
2006 (result_fname != NULL),
2009 smb_fname_str_do_log(handle->conn, smb_fname));
2011 return result_fname;
2014 static int smb_full_audit_fchflags(vfs_handle_struct *handle,
2015 struct files_struct *fsp,
2020 result = SMB_VFS_NEXT_FCHFLAGS(handle, fsp, flags);
2022 do_log(SMB_VFS_OP_FCHFLAGS,
2026 smb_fname_str_do_log(handle->conn, fsp->fsp_name));
2031 static struct file_id smb_full_audit_file_id_create(struct vfs_handle_struct *handle,
2032 const SMB_STRUCT_STAT *sbuf)
2034 struct file_id id_zero = { 0 };
2035 struct file_id result;
2036 struct file_id_buf idbuf;
2038 result = SMB_VFS_NEXT_FILE_ID_CREATE(handle, sbuf);
2040 do_log(SMB_VFS_OP_FILE_ID_CREATE,
2041 !file_id_equal(&id_zero, &result),
2044 file_id_str_buf(result, &idbuf));
2049 static uint64_t smb_full_audit_fs_file_id(struct vfs_handle_struct *handle,
2050 const SMB_STRUCT_STAT *sbuf)
2054 result = SMB_VFS_NEXT_FS_FILE_ID(handle, sbuf);
2056 do_log(SMB_VFS_OP_FS_FILE_ID,
2058 handle, "%" PRIu64, result);
2063 static NTSTATUS smb_full_audit_fstreaminfo(vfs_handle_struct *handle,
2064 struct files_struct *fsp,
2065 TALLOC_CTX *mem_ctx,
2066 unsigned int *pnum_streams,
2067 struct stream_struct **pstreams)
2071 result = SMB_VFS_NEXT_FSTREAMINFO(handle, fsp, mem_ctx,
2072 pnum_streams, pstreams);
2074 do_log(SMB_VFS_OP_FSTREAMINFO,
2075 NT_STATUS_IS_OK(result),
2078 smb_fname_str_do_log(handle->conn, fsp->fsp_name));
2083 static NTSTATUS smb_full_audit_get_real_filename(
2084 struct vfs_handle_struct *handle,
2085 const struct smb_filename *path,
2087 TALLOC_CTX *mem_ctx,
2092 result = SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name, mem_ctx,
2095 do_log(SMB_VFS_OP_GET_REAL_FILENAME,
2096 NT_STATUS_IS_OK(result),
2101 NT_STATUS_IS_OK(result) ? *found_name : "");
2106 static const char *smb_full_audit_connectpath(vfs_handle_struct *handle,
2107 const struct smb_filename *smb_fname)
2111 result = SMB_VFS_NEXT_CONNECTPATH(handle, smb_fname);
2113 do_log(SMB_VFS_OP_CONNECTPATH,
2117 smb_fname_str_do_log(handle->conn, smb_fname));
2122 static NTSTATUS smb_full_audit_brl_lock_windows(struct vfs_handle_struct *handle,
2123 struct byte_range_lock *br_lck,
2124 struct lock_struct *plock)
2128 result = SMB_VFS_NEXT_BRL_LOCK_WINDOWS(handle, br_lck, plock);
2130 do_log(SMB_VFS_OP_BRL_LOCK_WINDOWS, NT_STATUS_IS_OK(result), handle,
2131 "%s:%llu-%llu. type=%d.",
2132 fsp_str_do_log(brl_fsp(br_lck)),
2133 (unsigned long long)plock->start,
2134 (unsigned long long)plock->size,
2140 static bool smb_full_audit_brl_unlock_windows(struct vfs_handle_struct *handle,
2141 struct byte_range_lock *br_lck,
2142 const struct lock_struct *plock)
2146 result = SMB_VFS_NEXT_BRL_UNLOCK_WINDOWS(handle, br_lck, plock);
2148 do_log(SMB_VFS_OP_BRL_UNLOCK_WINDOWS, (result == 0), handle,
2149 "%s:%llu-%llu:%d", fsp_str_do_log(brl_fsp(br_lck)),
2150 (unsigned long long)plock->start,
2151 (unsigned long long)plock->size,
2157 static bool smb_full_audit_strict_lock_check(struct vfs_handle_struct *handle,
2158 struct files_struct *fsp,
2159 struct lock_struct *plock)
2163 result = SMB_VFS_NEXT_STRICT_LOCK_CHECK(handle, fsp, plock);
2165 do_log(SMB_VFS_OP_STRICT_LOCK_CHECK, result, handle,
2166 "%s:%llu-%llu:%d", fsp_str_do_log(fsp),
2167 (unsigned long long)plock->start,
2168 (unsigned long long)plock->size,
2174 static NTSTATUS smb_full_audit_translate_name(struct vfs_handle_struct *handle,
2176 enum vfs_translate_direction direction,
2177 TALLOC_CTX *mem_ctx,
2182 result = SMB_VFS_NEXT_TRANSLATE_NAME(handle, name, direction, mem_ctx,
2185 do_log(SMB_VFS_OP_TRANSLATE_NAME, NT_STATUS_IS_OK(result), handle, "");
2190 static NTSTATUS smb_full_audit_parent_pathname(struct vfs_handle_struct *handle,
2191 TALLOC_CTX *mem_ctx,
2192 const struct smb_filename *smb_fname_in,
2193 struct smb_filename **parent_dir_out,
2194 struct smb_filename **atname_out)
2198 result = SMB_VFS_NEXT_PARENT_PATHNAME(handle,
2203 do_log(SMB_VFS_OP_CONNECTPATH,
2204 NT_STATUS_IS_OK(result),
2207 smb_fname_str_do_log(handle->conn, smb_fname_in));
2212 static NTSTATUS smb_full_audit_fsctl(struct vfs_handle_struct *handle,
2213 struct files_struct *fsp,
2217 const uint8_t *_in_data,
2219 uint8_t **_out_data,
2220 uint32_t max_out_len,
2225 result = SMB_VFS_NEXT_FSCTL(handle,
2236 do_log(SMB_VFS_OP_FSCTL, NT_STATUS_IS_OK(result), handle, "");
2241 static struct tevent_req *smb_full_audit_offload_read_send(
2242 TALLOC_CTX *mem_ctx,
2243 struct tevent_context *ev,
2244 struct vfs_handle_struct *handle,
2245 struct files_struct *fsp,
2251 struct tevent_req *req = NULL;
2253 req = SMB_VFS_NEXT_OFFLOAD_READ_SEND(mem_ctx, ev, handle, fsp,
2254 fsctl, ttl, offset, to_copy);
2256 do_log(SMB_VFS_OP_OFFLOAD_READ_SEND, req, handle, "");
2261 static NTSTATUS smb_full_audit_offload_read_recv(
2262 struct tevent_req *req,
2263 struct vfs_handle_struct *handle,
2264 TALLOC_CTX *mem_ctx,
2267 DATA_BLOB *_token_blob)
2271 status = SMB_VFS_NEXT_OFFLOAD_READ_RECV(req, handle, mem_ctx,
2272 flags, xferlen, _token_blob);
2274 do_log(SMB_VFS_OP_OFFLOAD_READ_RECV, NT_STATUS_IS_OK(status), handle, "");
2279 static struct tevent_req *smb_full_audit_offload_write_send(struct vfs_handle_struct *handle,
2280 TALLOC_CTX *mem_ctx,
2281 struct tevent_context *ev,
2284 off_t transfer_offset,
2285 struct files_struct *dest_fsp,
2289 struct tevent_req *req;
2291 req = SMB_VFS_NEXT_OFFLOAD_WRITE_SEND(handle, mem_ctx, ev,
2292 fsctl, token, transfer_offset,
2293 dest_fsp, dest_off, num);
2295 do_log(SMB_VFS_OP_OFFLOAD_WRITE_SEND, req, handle, "");
2300 static NTSTATUS smb_full_audit_offload_write_recv(struct vfs_handle_struct *handle,
2301 struct tevent_req *req,
2306 result = SMB_VFS_NEXT_OFFLOAD_WRITE_RECV(handle, req, copied);
2308 do_log(SMB_VFS_OP_OFFLOAD_WRITE_RECV, NT_STATUS_IS_OK(result), handle, "");
2313 static NTSTATUS smb_full_audit_fget_compression(vfs_handle_struct *handle,
2314 TALLOC_CTX *mem_ctx,
2315 struct files_struct *fsp,
2316 uint16_t *_compression_fmt)
2320 result = SMB_VFS_NEXT_FGET_COMPRESSION(handle, mem_ctx, fsp,
2323 do_log(SMB_VFS_OP_FGET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
2325 fsp_str_do_log(fsp));
2330 static NTSTATUS smb_full_audit_set_compression(vfs_handle_struct *handle,
2331 TALLOC_CTX *mem_ctx,
2332 struct files_struct *fsp,
2333 uint16_t compression_fmt)
2337 result = SMB_VFS_NEXT_SET_COMPRESSION(handle, mem_ctx, fsp,
2340 do_log(SMB_VFS_OP_SET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
2341 "%s", fsp_str_do_log(fsp));
2346 static NTSTATUS smb_full_audit_freaddir_attr(struct vfs_handle_struct *handle,
2347 struct files_struct *fsp,
2348 TALLOC_CTX *mem_ctx,
2349 struct readdir_attr_data **pattr_data)
2353 status = SMB_VFS_NEXT_FREADDIR_ATTR(handle, fsp, mem_ctx, pattr_data);
2355 do_log(SMB_VFS_OP_FREADDIR_ATTR,
2356 NT_STATUS_IS_OK(status),
2359 fsp_str_do_log(fsp));
2364 struct smb_full_audit_get_dos_attributes_state {
2365 struct vfs_aio_state aio_state;
2366 vfs_handle_struct *handle;
2367 files_struct *dir_fsp;
2368 const struct smb_filename *smb_fname;
2372 static void smb_full_audit_get_dos_attributes_done(struct tevent_req *subreq);
2374 static struct tevent_req *smb_full_audit_get_dos_attributes_send(
2375 TALLOC_CTX *mem_ctx,
2376 struct tevent_context *ev,
2377 struct vfs_handle_struct *handle,
2378 files_struct *dir_fsp,
2379 struct smb_filename *smb_fname)
2381 struct tevent_req *req = NULL;
2382 struct smb_full_audit_get_dos_attributes_state *state = NULL;
2383 struct tevent_req *subreq = NULL;
2385 req = tevent_req_create(mem_ctx, &state,
2386 struct smb_full_audit_get_dos_attributes_state);
2388 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2392 fsp_str_do_log(dir_fsp),
2393 smb_fname->base_name);
2396 *state = (struct smb_full_audit_get_dos_attributes_state) {
2399 .smb_fname = smb_fname,
2402 subreq = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES_SEND(mem_ctx,
2407 if (tevent_req_nomem(subreq, req)) {
2408 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2412 fsp_str_do_log(dir_fsp),
2413 smb_fname->base_name);
2414 return tevent_req_post(req, ev);
2416 tevent_req_set_callback(subreq,
2417 smb_full_audit_get_dos_attributes_done,
2420 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2424 fsp_str_do_log(dir_fsp),
2425 smb_fname->base_name);
2430 static void smb_full_audit_get_dos_attributes_done(struct tevent_req *subreq)
2432 struct tevent_req *req =
2433 tevent_req_callback_data(subreq,
2435 struct smb_full_audit_get_dos_attributes_state *state =
2436 tevent_req_data(req,
2437 struct smb_full_audit_get_dos_attributes_state);
2440 status = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES_RECV(subreq,
2443 TALLOC_FREE(subreq);
2444 if (tevent_req_nterror(req, status)) {
2448 tevent_req_done(req);
2452 static NTSTATUS smb_full_audit_get_dos_attributes_recv(struct tevent_req *req,
2453 struct vfs_aio_state *aio_state,
2456 struct smb_full_audit_get_dos_attributes_state *state =
2457 tevent_req_data(req,
2458 struct smb_full_audit_get_dos_attributes_state);
2461 if (tevent_req_is_nterror(req, &status)) {
2462 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV,
2466 fsp_str_do_log(state->dir_fsp),
2467 state->smb_fname->base_name);
2468 tevent_req_received(req);
2472 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV,
2476 fsp_str_do_log(state->dir_fsp),
2477 state->smb_fname->base_name);
2479 *aio_state = state->aio_state;
2480 *dosmode = state->dosmode;
2481 tevent_req_received(req);
2482 return NT_STATUS_OK;
2485 static NTSTATUS smb_full_audit_fget_dos_attributes(
2486 struct vfs_handle_struct *handle,
2487 struct files_struct *fsp,
2492 status = SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle,
2496 do_log(SMB_VFS_OP_FGET_DOS_ATTRIBUTES,
2497 NT_STATUS_IS_OK(status),
2500 fsp_str_do_log(fsp));
2505 static NTSTATUS smb_full_audit_fset_dos_attributes(
2506 struct vfs_handle_struct *handle,
2507 struct files_struct *fsp,
2512 status = SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle,
2516 do_log(SMB_VFS_OP_FSET_DOS_ATTRIBUTES,
2517 NT_STATUS_IS_OK(status),
2520 fsp_str_do_log(fsp));
2525 static NTSTATUS smb_full_audit_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
2526 uint32_t security_info,
2527 TALLOC_CTX *mem_ctx,
2528 struct security_descriptor **ppdesc)
2532 result = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
2535 do_log(SMB_VFS_OP_FGET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2536 "%s", fsp_str_do_log(fsp));
2541 static NTSTATUS smb_full_audit_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
2542 uint32_t security_info_sent,
2543 const struct security_descriptor *psd)
2545 struct vfs_full_audit_private_data *pd;
2549 SMB_VFS_HANDLE_GET_DATA(handle, pd,
2550 struct vfs_full_audit_private_data,
2551 return NT_STATUS_INTERNAL_ERROR);
2553 if (pd->log_secdesc) {
2554 sd = sddl_encode(talloc_tos(), psd, get_global_sam_sid());
2557 result = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
2559 do_log(SMB_VFS_OP_FSET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2560 "%s [%s]", fsp_str_do_log(fsp), sd ? sd : "");
2567 static NTSTATUS smb_full_audit_audit_file(struct vfs_handle_struct *handle,
2568 struct smb_filename *file,
2569 struct security_acl *sacl,
2570 uint32_t access_requested,
2571 uint32_t access_denied)
2575 result = SMB_VFS_NEXT_AUDIT_FILE(handle,
2581 do_log(SMB_VFS_OP_AUDIT_FILE, NT_STATUS_IS_OK(result), handle,
2583 smb_fname_str_do_log(handle->conn, file));
2588 static SMB_ACL_T smb_full_audit_sys_acl_get_fd(vfs_handle_struct *handle,
2590 SMB_ACL_TYPE_T type,
2591 TALLOC_CTX *mem_ctx)
2595 result = SMB_VFS_NEXT_SYS_ACL_GET_FD(handle,
2600 do_log(SMB_VFS_OP_SYS_ACL_GET_FD, (result != NULL), handle,
2601 "%s", fsp_str_do_log(fsp));
2606 static int smb_full_audit_sys_acl_blob_get_fd(vfs_handle_struct *handle,
2608 TALLOC_CTX *mem_ctx,
2609 char **blob_description,
2614 result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle, fsp, mem_ctx, blob_description, blob);
2616 do_log(SMB_VFS_OP_SYS_ACL_BLOB_GET_FD, (result >= 0), handle,
2617 "%s", fsp_str_do_log(fsp));
2622 static int smb_full_audit_sys_acl_set_fd(vfs_handle_struct *handle,
2623 struct files_struct *fsp,
2624 SMB_ACL_TYPE_T type,
2629 result = SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, type, theacl);
2631 do_log(SMB_VFS_OP_SYS_ACL_SET_FD, (result >= 0), handle,
2632 "%s", fsp_str_do_log(fsp));
2637 static int smb_full_audit_sys_acl_delete_def_fd(vfs_handle_struct *handle,
2638 struct files_struct *fsp)
2642 result = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FD(handle, fsp);
2644 do_log(SMB_VFS_OP_SYS_ACL_DELETE_DEF_FD,
2648 fsp_str_do_log(fsp));
2653 struct smb_full_audit_getxattrat_state {
2654 struct vfs_aio_state aio_state;
2655 vfs_handle_struct *handle;
2656 files_struct *dir_fsp;
2657 const struct smb_filename *smb_fname;
2658 const char *xattr_name;
2660 uint8_t *xattr_value;
2663 static void smb_full_audit_getxattrat_done(struct tevent_req *subreq);
2665 static struct tevent_req *smb_full_audit_getxattrat_send(
2666 TALLOC_CTX *mem_ctx,
2667 struct tevent_context *ev,
2668 struct vfs_handle_struct *handle,
2669 files_struct *dir_fsp,
2670 const struct smb_filename *smb_fname,
2671 const char *xattr_name,
2674 struct tevent_req *req = NULL;
2675 struct tevent_req *subreq = NULL;
2676 struct smb_full_audit_getxattrat_state *state = NULL;
2678 req = tevent_req_create(mem_ctx, &state,
2679 struct smb_full_audit_getxattrat_state);
2681 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2685 fsp_str_do_log(dir_fsp),
2686 smb_fname->base_name,
2690 *state = (struct smb_full_audit_getxattrat_state) {
2693 .smb_fname = smb_fname,
2694 .xattr_name = xattr_name,
2697 subreq = SMB_VFS_NEXT_GETXATTRAT_SEND(state,
2704 if (tevent_req_nomem(subreq, req)) {
2705 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2709 fsp_str_do_log(dir_fsp),
2710 smb_fname->base_name,
2712 return tevent_req_post(req, ev);
2714 tevent_req_set_callback(subreq, smb_full_audit_getxattrat_done, req);
2716 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2720 fsp_str_do_log(dir_fsp),
2721 smb_fname->base_name,
2727 static void smb_full_audit_getxattrat_done(struct tevent_req *subreq)
2729 struct tevent_req *req = tevent_req_callback_data(
2730 subreq, struct tevent_req);
2731 struct smb_full_audit_getxattrat_state *state = tevent_req_data(
2732 req, struct smb_full_audit_getxattrat_state);
2734 state->xattr_size = SMB_VFS_NEXT_GETXATTRAT_RECV(subreq,
2737 &state->xattr_value);
2738 TALLOC_FREE(subreq);
2739 if (state->xattr_size == -1) {
2740 tevent_req_error(req, state->aio_state.error);
2744 tevent_req_done(req);
2747 static ssize_t smb_full_audit_getxattrat_recv(struct tevent_req *req,
2748 struct vfs_aio_state *aio_state,
2749 TALLOC_CTX *mem_ctx,
2750 uint8_t **xattr_value)
2752 struct smb_full_audit_getxattrat_state *state = tevent_req_data(
2753 req, struct smb_full_audit_getxattrat_state);
2756 if (tevent_req_is_unix_error(req, &aio_state->error)) {
2757 do_log(SMB_VFS_OP_GETXATTRAT_RECV,
2761 fsp_str_do_log(state->dir_fsp),
2762 state->smb_fname->base_name,
2764 tevent_req_received(req);
2768 do_log(SMB_VFS_OP_GETXATTRAT_RECV,
2772 fsp_str_do_log(state->dir_fsp),
2773 state->smb_fname->base_name,
2776 *aio_state = state->aio_state;
2777 xattr_size = state->xattr_size;
2778 if (xattr_value != NULL) {
2779 *xattr_value = talloc_move(mem_ctx, &state->xattr_value);
2782 tevent_req_received(req);
2786 static ssize_t smb_full_audit_fgetxattr(struct vfs_handle_struct *handle,
2787 struct files_struct *fsp,
2788 const char *name, void *value, size_t size)
2792 result = SMB_VFS_NEXT_FGETXATTR(handle, fsp, name, value, size);
2794 do_log(SMB_VFS_OP_FGETXATTR, (result >= 0), handle,
2795 "%s|%s", fsp_str_do_log(fsp), name);
2800 static ssize_t smb_full_audit_flistxattr(struct vfs_handle_struct *handle,
2801 struct files_struct *fsp, char *list,
2806 result = SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
2808 do_log(SMB_VFS_OP_FLISTXATTR, (result >= 0), handle,
2809 "%s", fsp_str_do_log(fsp));
2814 static int smb_full_audit_fremovexattr(struct vfs_handle_struct *handle,
2815 struct files_struct *fsp,
2820 result = SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, name);
2822 do_log(SMB_VFS_OP_FREMOVEXATTR, (result >= 0), handle,
2823 "%s|%s", fsp_str_do_log(fsp), name);
2828 static int smb_full_audit_fsetxattr(struct vfs_handle_struct *handle,
2829 struct files_struct *fsp, const char *name,
2830 const void *value, size_t size, int flags)
2834 result = SMB_VFS_NEXT_FSETXATTR(handle, fsp, name, value, size, flags);
2836 do_log(SMB_VFS_OP_FSETXATTR, (result >= 0), handle,
2837 "%s|%s", fsp_str_do_log(fsp), name);
2842 static bool smb_full_audit_aio_force(struct vfs_handle_struct *handle,
2843 struct files_struct *fsp)
2847 result = SMB_VFS_NEXT_AIO_FORCE(handle, fsp);
2848 do_log(SMB_VFS_OP_AIO_FORCE, result, handle,
2849 "%s", fsp_str_do_log(fsp));
2854 static NTSTATUS smb_full_audit_durable_cookie(struct vfs_handle_struct *handle,
2855 struct files_struct *fsp,
2856 TALLOC_CTX *mem_ctx,
2861 result = SMB_VFS_NEXT_DURABLE_COOKIE(handle,
2866 do_log(SMB_VFS_OP_DURABLE_COOKIE, NT_STATUS_IS_OK(result), handle,
2867 "%s", fsp_str_do_log(fsp));
2872 static NTSTATUS smb_full_audit_durable_disconnect(
2873 struct vfs_handle_struct *handle,
2874 struct files_struct *fsp,
2875 const DATA_BLOB old_cookie,
2876 TALLOC_CTX *mem_ctx,
2877 DATA_BLOB *new_cookie)
2881 result = SMB_VFS_NEXT_DURABLE_DISCONNECT(handle,
2887 do_log(SMB_VFS_OP_DURABLE_DISCONNECT, NT_STATUS_IS_OK(result), handle,
2888 "%s", fsp_str_do_log(fsp));
2893 static NTSTATUS smb_full_audit_durable_reconnect(
2894 struct vfs_handle_struct *handle,
2895 struct smb_request *smb1req,
2896 struct smbXsrv_open *op,
2897 const DATA_BLOB old_cookie,
2898 TALLOC_CTX *mem_ctx,
2899 struct files_struct **fsp,
2900 DATA_BLOB *new_cookie)
2904 result = SMB_VFS_NEXT_DURABLE_RECONNECT(handle,
2912 do_log(SMB_VFS_OP_DURABLE_RECONNECT,
2913 NT_STATUS_IS_OK(result),
2920 static struct vfs_fn_pointers vfs_full_audit_fns = {
2922 /* Disk operations */
2924 .connect_fn = smb_full_audit_connect,
2925 .disconnect_fn = smb_full_audit_disconnect,
2926 .disk_free_fn = smb_full_audit_disk_free,
2927 .get_quota_fn = smb_full_audit_get_quota,
2928 .set_quota_fn = smb_full_audit_set_quota,
2929 .get_shadow_copy_data_fn = smb_full_audit_get_shadow_copy_data,
2930 .statvfs_fn = smb_full_audit_statvfs,
2931 .fs_capabilities_fn = smb_full_audit_fs_capabilities,
2932 .get_dfs_referrals_fn = smb_full_audit_get_dfs_referrals,
2933 .create_dfs_pathat_fn = smb_full_audit_create_dfs_pathat,
2934 .read_dfs_pathat_fn = smb_full_audit_read_dfs_pathat,
2935 .fdopendir_fn = smb_full_audit_fdopendir,
2936 .readdir_fn = smb_full_audit_readdir,
2937 .seekdir_fn = smb_full_audit_seekdir,
2938 .telldir_fn = smb_full_audit_telldir,
2939 .rewind_dir_fn = smb_full_audit_rewinddir,
2940 .mkdirat_fn = smb_full_audit_mkdirat,
2941 .closedir_fn = smb_full_audit_closedir,
2942 .openat_fn = smb_full_audit_openat,
2943 .create_file_fn = smb_full_audit_create_file,
2944 .close_fn = smb_full_audit_close,
2945 .pread_fn = smb_full_audit_pread,
2946 .pread_send_fn = smb_full_audit_pread_send,
2947 .pread_recv_fn = smb_full_audit_pread_recv,
2948 .pwrite_fn = smb_full_audit_pwrite,
2949 .pwrite_send_fn = smb_full_audit_pwrite_send,
2950 .pwrite_recv_fn = smb_full_audit_pwrite_recv,
2951 .lseek_fn = smb_full_audit_lseek,
2952 .sendfile_fn = smb_full_audit_sendfile,
2953 .recvfile_fn = smb_full_audit_recvfile,
2954 .renameat_fn = smb_full_audit_renameat,
2955 .fsync_send_fn = smb_full_audit_fsync_send,
2956 .fsync_recv_fn = smb_full_audit_fsync_recv,
2957 .stat_fn = smb_full_audit_stat,
2958 .fstat_fn = smb_full_audit_fstat,
2959 .lstat_fn = smb_full_audit_lstat,
2960 .fstatat_fn = smb_full_audit_fstatat,
2961 .get_alloc_size_fn = smb_full_audit_get_alloc_size,
2962 .unlinkat_fn = smb_full_audit_unlinkat,
2963 .fchmod_fn = smb_full_audit_fchmod,
2964 .fchown_fn = smb_full_audit_fchown,
2965 .lchown_fn = smb_full_audit_lchown,
2966 .chdir_fn = smb_full_audit_chdir,
2967 .getwd_fn = smb_full_audit_getwd,
2968 .fntimes_fn = smb_full_audit_fntimes,
2969 .ftruncate_fn = smb_full_audit_ftruncate,
2970 .fallocate_fn = smb_full_audit_fallocate,
2971 .lock_fn = smb_full_audit_lock,
2972 .filesystem_sharemode_fn = smb_full_audit_filesystem_sharemode,
2973 .fcntl_fn = smb_full_audit_fcntl,
2974 .linux_setlease_fn = smb_full_audit_linux_setlease,
2975 .getlock_fn = smb_full_audit_getlock,
2976 .symlinkat_fn = smb_full_audit_symlinkat,
2977 .readlinkat_fn = smb_full_audit_readlinkat,
2978 .linkat_fn = smb_full_audit_linkat,
2979 .mknodat_fn = smb_full_audit_mknodat,
2980 .realpath_fn = smb_full_audit_realpath,
2981 .fchflags_fn = smb_full_audit_fchflags,
2982 .file_id_create_fn = smb_full_audit_file_id_create,
2983 .fs_file_id_fn = smb_full_audit_fs_file_id,
2984 .offload_read_send_fn = smb_full_audit_offload_read_send,
2985 .offload_read_recv_fn = smb_full_audit_offload_read_recv,
2986 .offload_write_send_fn = smb_full_audit_offload_write_send,
2987 .offload_write_recv_fn = smb_full_audit_offload_write_recv,
2988 .fget_compression_fn = smb_full_audit_fget_compression,
2989 .set_compression_fn = smb_full_audit_set_compression,
2990 .snap_check_path_fn = smb_full_audit_snap_check_path,
2991 .snap_create_fn = smb_full_audit_snap_create,
2992 .snap_delete_fn = smb_full_audit_snap_delete,
2993 .fstreaminfo_fn = smb_full_audit_fstreaminfo,
2994 .get_real_filename_fn = smb_full_audit_get_real_filename,
2995 .connectpath_fn = smb_full_audit_connectpath,
2996 .brl_lock_windows_fn = smb_full_audit_brl_lock_windows,
2997 .brl_unlock_windows_fn = smb_full_audit_brl_unlock_windows,
2998 .strict_lock_check_fn = smb_full_audit_strict_lock_check,
2999 .translate_name_fn = smb_full_audit_translate_name,
3000 .parent_pathname_fn = smb_full_audit_parent_pathname,
3001 .fsctl_fn = smb_full_audit_fsctl,
3002 .get_dos_attributes_send_fn = smb_full_audit_get_dos_attributes_send,
3003 .get_dos_attributes_recv_fn = smb_full_audit_get_dos_attributes_recv,
3004 .fget_dos_attributes_fn = smb_full_audit_fget_dos_attributes,
3005 .fset_dos_attributes_fn = smb_full_audit_fset_dos_attributes,
3006 .fget_nt_acl_fn = smb_full_audit_fget_nt_acl,
3007 .fset_nt_acl_fn = smb_full_audit_fset_nt_acl,
3008 .audit_file_fn = smb_full_audit_audit_file,
3009 .sys_acl_get_fd_fn = smb_full_audit_sys_acl_get_fd,
3010 .sys_acl_blob_get_fd_fn = smb_full_audit_sys_acl_blob_get_fd,
3011 .sys_acl_set_fd_fn = smb_full_audit_sys_acl_set_fd,
3012 .sys_acl_delete_def_fd_fn = smb_full_audit_sys_acl_delete_def_fd,
3013 .getxattrat_send_fn = smb_full_audit_getxattrat_send,
3014 .getxattrat_recv_fn = smb_full_audit_getxattrat_recv,
3015 .fgetxattr_fn = smb_full_audit_fgetxattr,
3016 .flistxattr_fn = smb_full_audit_flistxattr,
3017 .fremovexattr_fn = smb_full_audit_fremovexattr,
3018 .fsetxattr_fn = smb_full_audit_fsetxattr,
3019 .aio_force_fn = smb_full_audit_aio_force,
3020 .durable_cookie_fn = smb_full_audit_durable_cookie,
3021 .durable_disconnect_fn = smb_full_audit_durable_disconnect,
3022 .durable_reconnect_fn = smb_full_audit_durable_reconnect,
3023 .freaddir_attr_fn = smb_full_audit_freaddir_attr,
3027 NTSTATUS vfs_full_audit_init(TALLOC_CTX *ctx)
3031 smb_vfs_assert_all_fns(&vfs_full_audit_fns, "full_audit");
3033 ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "full_audit",
3034 &vfs_full_audit_fns);
3036 if (!NT_STATUS_IS_OK(ret))
3039 vfs_full_audit_debug_level = debug_add_class("full_audit");
3040 if (vfs_full_audit_debug_level == -1) {
3041 vfs_full_audit_debug_level = DBGC_VFS;
3042 DEBUG(0, ("vfs_full_audit: Couldn't register custom debugging "
3045 DEBUG(10, ("vfs_full_audit: Debug class number of "
3046 "'full_audit': %d\n", vfs_full_audit_debug_level));