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_GET_REAL_FILENAME_AT,
171 SMB_VFS_OP_CONNECTPATH,
172 SMB_VFS_OP_BRL_LOCK_WINDOWS,
173 SMB_VFS_OP_BRL_UNLOCK_WINDOWS,
174 SMB_VFS_OP_STRICT_LOCK_CHECK,
175 SMB_VFS_OP_TRANSLATE_NAME,
176 SMB_VFS_OP_PARENT_PATHNAME,
178 SMB_VFS_OP_OFFLOAD_READ_SEND,
179 SMB_VFS_OP_OFFLOAD_READ_RECV,
180 SMB_VFS_OP_OFFLOAD_WRITE_SEND,
181 SMB_VFS_OP_OFFLOAD_WRITE_RECV,
182 SMB_VFS_OP_FGET_COMPRESSION,
183 SMB_VFS_OP_SET_COMPRESSION,
184 SMB_VFS_OP_SNAP_CHECK_PATH,
185 SMB_VFS_OP_SNAP_CREATE,
186 SMB_VFS_OP_SNAP_DELETE,
188 /* DOS attribute operations. */
189 SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
190 SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV,
191 SMB_VFS_OP_FGET_DOS_ATTRIBUTES,
192 SMB_VFS_OP_FSET_DOS_ATTRIBUTES,
194 /* NT ACL operations. */
196 SMB_VFS_OP_FGET_NT_ACL,
197 SMB_VFS_OP_FSET_NT_ACL,
198 SMB_VFS_OP_AUDIT_FILE,
200 /* POSIX ACL operations. */
202 SMB_VFS_OP_SYS_ACL_GET_FD,
203 SMB_VFS_OP_SYS_ACL_BLOB_GET_FD,
204 SMB_VFS_OP_SYS_ACL_SET_FD,
205 SMB_VFS_OP_SYS_ACL_DELETE_DEF_FD,
208 SMB_VFS_OP_GETXATTRAT_SEND,
209 SMB_VFS_OP_GETXATTRAT_RECV,
210 SMB_VFS_OP_FGETXATTR,
211 SMB_VFS_OP_FLISTXATTR,
212 SMB_VFS_OP_REMOVEXATTR,
213 SMB_VFS_OP_FREMOVEXATTR,
214 SMB_VFS_OP_FSETXATTR,
217 SMB_VFS_OP_AIO_FORCE,
219 /* offline operations */
220 SMB_VFS_OP_IS_OFFLINE,
221 SMB_VFS_OP_SET_OFFLINE,
223 /* Durable handle operations. */
224 SMB_VFS_OP_DURABLE_COOKIE,
225 SMB_VFS_OP_DURABLE_DISCONNECT,
226 SMB_VFS_OP_DURABLE_RECONNECT,
228 SMB_VFS_OP_FREADDIR_ATTR,
230 /* This should always be last enum value */
235 /* The following array *must* be in the same order as defined in vfs_op_type */
241 { SMB_VFS_OP_CONNECT, "connect" },
242 { SMB_VFS_OP_DISCONNECT, "disconnect" },
243 { SMB_VFS_OP_DISK_FREE, "disk_free" },
244 { SMB_VFS_OP_GET_QUOTA, "get_quota" },
245 { SMB_VFS_OP_SET_QUOTA, "set_quota" },
246 { SMB_VFS_OP_GET_SHADOW_COPY_DATA, "get_shadow_copy_data" },
247 { SMB_VFS_OP_STATVFS, "statvfs" },
248 { SMB_VFS_OP_FS_CAPABILITIES, "fs_capabilities" },
249 { SMB_VFS_OP_GET_DFS_REFERRALS, "get_dfs_referrals" },
250 { SMB_VFS_OP_CREATE_DFS_PATHAT, "create_dfs_pathat" },
251 { SMB_VFS_OP_READ_DFS_PATHAT, "read_dfs_pathat" },
252 { SMB_VFS_OP_FDOPENDIR, "fdopendir" },
253 { SMB_VFS_OP_READDIR, "readdir" },
254 { SMB_VFS_OP_SEEKDIR, "seekdir" },
255 { SMB_VFS_OP_TELLDIR, "telldir" },
256 { SMB_VFS_OP_REWINDDIR, "rewinddir" },
257 { SMB_VFS_OP_MKDIRAT, "mkdirat" },
258 { SMB_VFS_OP_CLOSEDIR, "closedir" },
259 { SMB_VFS_OP_OPEN, "open" },
260 { SMB_VFS_OP_OPENAT, "openat" },
261 { SMB_VFS_OP_CREATE_FILE, "create_file" },
262 { SMB_VFS_OP_CLOSE, "close" },
263 { SMB_VFS_OP_READ, "read" },
264 { SMB_VFS_OP_PREAD, "pread" },
265 { SMB_VFS_OP_PREAD_SEND, "pread_send" },
266 { SMB_VFS_OP_PREAD_RECV, "pread_recv" },
267 { SMB_VFS_OP_WRITE, "write" },
268 { SMB_VFS_OP_PWRITE, "pwrite" },
269 { SMB_VFS_OP_PWRITE_SEND, "pwrite_send" },
270 { SMB_VFS_OP_PWRITE_RECV, "pwrite_recv" },
271 { SMB_VFS_OP_LSEEK, "lseek" },
272 { SMB_VFS_OP_SENDFILE, "sendfile" },
273 { SMB_VFS_OP_RECVFILE, "recvfile" },
274 { SMB_VFS_OP_RENAMEAT, "renameat" },
275 { SMB_VFS_OP_FSYNC, "fsync" },
276 { SMB_VFS_OP_FSYNC_SEND, "fsync_send" },
277 { SMB_VFS_OP_FSYNC_RECV, "fsync_recv" },
278 { SMB_VFS_OP_STAT, "stat" },
279 { SMB_VFS_OP_FSTAT, "fstat" },
280 { SMB_VFS_OP_LSTAT, "lstat" },
281 { SMB_VFS_OP_FSTATAT, "fstatat" },
282 { SMB_VFS_OP_GET_ALLOC_SIZE, "get_alloc_size" },
283 { SMB_VFS_OP_UNLINKAT, "unlinkat" },
284 { SMB_VFS_OP_FCHMOD, "fchmod" },
285 { SMB_VFS_OP_FCHOWN, "fchown" },
286 { SMB_VFS_OP_LCHOWN, "lchown" },
287 { SMB_VFS_OP_CHDIR, "chdir" },
288 { SMB_VFS_OP_GETWD, "getwd" },
289 { SMB_VFS_OP_NTIMES, "ntimes" },
290 { SMB_VFS_OP_FNTIMES, "fntimes" },
291 { SMB_VFS_OP_FTRUNCATE, "ftruncate" },
292 { SMB_VFS_OP_FALLOCATE,"fallocate" },
293 { SMB_VFS_OP_LOCK, "lock" },
294 { SMB_VFS_OP_FILESYSTEM_SHAREMODE, "filesystem_sharemode" },
295 { SMB_VFS_OP_FCNTL, "fcntl" },
296 { SMB_VFS_OP_LINUX_SETLEASE, "linux_setlease" },
297 { SMB_VFS_OP_GETLOCK, "getlock" },
298 { SMB_VFS_OP_SYMLINKAT, "symlinkat" },
299 { SMB_VFS_OP_READLINKAT,"readlinkat" },
300 { SMB_VFS_OP_LINKAT, "linkat" },
301 { SMB_VFS_OP_MKNODAT, "mknodat" },
302 { SMB_VFS_OP_REALPATH, "realpath" },
303 { SMB_VFS_OP_FCHFLAGS, "fchflags" },
304 { SMB_VFS_OP_FILE_ID_CREATE, "file_id_create" },
305 { SMB_VFS_OP_FS_FILE_ID, "fs_file_id" },
306 { SMB_VFS_OP_FSTREAMINFO, "fstreaminfo" },
307 { SMB_VFS_OP_GET_REAL_FILENAME, "get_real_filename" },
308 { SMB_VFS_OP_GET_REAL_FILENAME_AT, "get_real_filename_at" },
309 { SMB_VFS_OP_CONNECTPATH, "connectpath" },
310 { SMB_VFS_OP_BRL_LOCK_WINDOWS, "brl_lock_windows" },
311 { SMB_VFS_OP_BRL_UNLOCK_WINDOWS, "brl_unlock_windows" },
312 { SMB_VFS_OP_STRICT_LOCK_CHECK, "strict_lock_check" },
313 { SMB_VFS_OP_TRANSLATE_NAME, "translate_name" },
314 { SMB_VFS_OP_PARENT_PATHNAME, "parent_pathname" },
315 { SMB_VFS_OP_FSCTL, "fsctl" },
316 { SMB_VFS_OP_OFFLOAD_READ_SEND, "offload_read_send" },
317 { SMB_VFS_OP_OFFLOAD_READ_RECV, "offload_read_recv" },
318 { SMB_VFS_OP_OFFLOAD_WRITE_SEND, "offload_write_send" },
319 { SMB_VFS_OP_OFFLOAD_WRITE_RECV, "offload_write_recv" },
320 { SMB_VFS_OP_FGET_COMPRESSION, "fget_compression" },
321 { SMB_VFS_OP_SET_COMPRESSION, "set_compression" },
322 { SMB_VFS_OP_SNAP_CHECK_PATH, "snap_check_path" },
323 { SMB_VFS_OP_SNAP_CREATE, "snap_create" },
324 { SMB_VFS_OP_SNAP_DELETE, "snap_delete" },
325 { SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND, "get_dos_attributes_send" },
326 { SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV, "get_dos_attributes_recv" },
327 { SMB_VFS_OP_FGET_DOS_ATTRIBUTES, "fget_dos_attributes" },
328 { SMB_VFS_OP_FSET_DOS_ATTRIBUTES, "fset_dos_attributes" },
329 { SMB_VFS_OP_FGET_NT_ACL, "fget_nt_acl" },
330 { SMB_VFS_OP_FSET_NT_ACL, "fset_nt_acl" },
331 { SMB_VFS_OP_AUDIT_FILE, "audit_file" },
332 { SMB_VFS_OP_SYS_ACL_GET_FD, "sys_acl_get_fd" },
333 { SMB_VFS_OP_SYS_ACL_BLOB_GET_FD, "sys_acl_blob_get_fd" },
334 { SMB_VFS_OP_SYS_ACL_SET_FD, "sys_acl_set_fd" },
335 { SMB_VFS_OP_SYS_ACL_DELETE_DEF_FD, "sys_acl_delete_def_fd" },
336 { SMB_VFS_OP_GETXATTRAT_SEND, "getxattrat_send" },
337 { SMB_VFS_OP_GETXATTRAT_RECV, "getxattrat_recv" },
338 { SMB_VFS_OP_FGETXATTR, "fgetxattr" },
339 { SMB_VFS_OP_FLISTXATTR, "flistxattr" },
340 { SMB_VFS_OP_REMOVEXATTR, "removexattr" },
341 { SMB_VFS_OP_FREMOVEXATTR, "fremovexattr" },
342 { SMB_VFS_OP_FSETXATTR, "fsetxattr" },
343 { SMB_VFS_OP_AIO_FORCE, "aio_force" },
344 { SMB_VFS_OP_IS_OFFLINE, "is_offline" },
345 { SMB_VFS_OP_SET_OFFLINE, "set_offline" },
346 { SMB_VFS_OP_DURABLE_COOKIE, "durable_cookie" },
347 { SMB_VFS_OP_DURABLE_DISCONNECT, "durable_disconnect" },
348 { SMB_VFS_OP_DURABLE_RECONNECT, "durable_reconnect" },
349 { SMB_VFS_OP_FREADDIR_ATTR, "freaddir_attr" },
350 { SMB_VFS_OP_LAST, NULL }
353 static int audit_syslog_facility(vfs_handle_struct *handle)
355 static const struct enum_list enum_log_facilities[] = {
357 { LOG_AUTH, "AUTH" },
360 { LOG_AUTHPRIV, "AUTHPRIV" },
363 { LOG_AUDIT, "AUDIT" },
366 { LOG_CONSOLE, "CONSOLE" },
369 { LOG_CRON, "CRON" },
372 { LOG_DAEMON, "DAEMON" },
378 { LOG_INSTALL, "INSTALL" },
381 { LOG_KERN, "KERN" },
384 { LOG_LAUNCHD, "LAUNCHD" },
387 { LOG_LFMT, "LFMT" },
393 { LOG_MAIL, "MAIL" },
396 { LOG_MEGASAFE, "MEGASAFE" },
399 { LOG_NETINFO, "NETINFO" },
402 { LOG_NEWS, "NEWS" },
404 #ifdef LOG_NFACILITIES
405 { LOG_NFACILITIES, "NFACILITIES" },
413 #ifdef LOG_REMOTEAUTH
414 { LOG_REMOTEAUTH, "REMOTEAUTH" },
417 { LOG_SECURITY, "SECURITY" },
420 { LOG_SYSLOG, "SYSLOG" },
423 { LOG_USER, "USER" },
426 { LOG_UUCP, "UUCP" },
428 { LOG_LOCAL0, "LOCAL0" },
429 { LOG_LOCAL1, "LOCAL1" },
430 { LOG_LOCAL2, "LOCAL2" },
431 { LOG_LOCAL3, "LOCAL3" },
432 { LOG_LOCAL4, "LOCAL4" },
433 { LOG_LOCAL5, "LOCAL5" },
434 { LOG_LOCAL6, "LOCAL6" },
435 { LOG_LOCAL7, "LOCAL7" },
441 facility = lp_parm_enum(SNUM(handle->conn), "full_audit", "facility", enum_log_facilities, LOG_USER);
446 static int audit_syslog_priority(vfs_handle_struct *handle)
448 static const struct enum_list enum_log_priorities[] = {
449 { LOG_EMERG, "EMERG" },
450 { LOG_ALERT, "ALERT" },
451 { LOG_CRIT, "CRIT" },
453 { LOG_WARNING, "WARNING" },
454 { LOG_NOTICE, "NOTICE" },
455 { LOG_INFO, "INFO" },
456 { LOG_DEBUG, "DEBUG" },
462 priority = lp_parm_enum(SNUM(handle->conn), "full_audit", "priority",
463 enum_log_priorities, LOG_NOTICE);
464 if (priority == -1) {
465 priority = LOG_WARNING;
471 static char *audit_prefix(TALLOC_CTX *ctx, connection_struct *conn)
473 const struct loadparm_substitution *lp_sub =
474 loadparm_s3_global_substitution();
478 prefix = talloc_strdup(ctx,
479 lp_parm_const_string(SNUM(conn), "full_audit",
484 result = talloc_sub_full(ctx,
485 lp_servicename(talloc_tos(), lp_sub, SNUM(conn)),
486 conn->session_info->unix_info->unix_name,
488 conn->session_info->unix_token->gid,
489 conn->session_info->unix_info->sanitized_username,
490 conn->session_info->info->domain_name,
496 static bool log_success(struct vfs_full_audit_private_data *pd, vfs_op_type op)
498 if (pd->success_ops == NULL) {
502 return bitmap_query(pd->success_ops, op);
505 static bool log_failure(struct vfs_full_audit_private_data *pd, vfs_op_type op)
507 if (pd->failure_ops == NULL)
510 return bitmap_query(pd->failure_ops, op);
513 static struct bitmap *init_bitmap(TALLOC_CTX *mem_ctx, const char **ops)
518 DBG_ERR("init_bitmap, ops list is empty (logic error)\n");
522 bm = bitmap_talloc(mem_ctx, SMB_VFS_OP_LAST);
524 DBG_ERR("Could not alloc bitmap\n");
528 for (; *ops != NULL; ops += 1) {
533 if (strequal(*ops, "all")) {
534 for (i=0; i<SMB_VFS_OP_LAST; i++) {
540 if (strequal(*ops, "none")) {
550 for (i=0; i<SMB_VFS_OP_LAST; i++) {
551 if ((vfs_op_names[i].name == NULL)
552 || (vfs_op_names[i].type != i)) {
553 smb_panic("vfs_full_audit.c: name table not "
554 "in sync with vfs_op_type enums\n");
556 if (strequal(op, vfs_op_names[i].name)) {
565 if (i == SMB_VFS_OP_LAST) {
566 DBG_ERR("Could not find opname %s\n", *ops);
574 static const char *audit_opname(vfs_op_type op)
576 if (op >= SMB_VFS_OP_LAST)
577 return "INVALID VFS OP";
578 return vfs_op_names[op].name;
581 static TALLOC_CTX *tmp_do_log_ctx;
583 * Get us a temporary talloc context usable just for DEBUG arguments
585 static TALLOC_CTX *do_log_ctx(void)
587 if (tmp_do_log_ctx == NULL) {
588 tmp_do_log_ctx = talloc_named_const(NULL, 0, "do_log_ctx");
590 return tmp_do_log_ctx;
593 static void do_log(vfs_op_type op, bool success, vfs_handle_struct *handle,
594 const char *format, ...) PRINTF_ATTRIBUTE(4, 5);
596 static void do_log(vfs_op_type op, bool success, vfs_handle_struct *handle,
597 const char *format, ...)
599 struct vfs_full_audit_private_data *pd;
601 char *audit_pre = NULL;
605 SMB_VFS_HANDLE_GET_DATA(handle, pd,
606 struct vfs_full_audit_private_data,
609 if (success && (!log_success(pd, op)))
612 if (!success && (!log_failure(pd, op)))
616 fstrcpy(err_msg, "ok");
618 fstr_sprintf(err_msg, "fail (%s)", strerror(errno));
620 va_start(ap, format);
621 op_msg = talloc_vasprintf(talloc_tos(), format, ap);
628 audit_pre = audit_prefix(talloc_tos(), handle->conn);
634 * Specify the facility to interoperate with other syslog
635 * callers (smbd for example).
637 priority = pd->syslog_priority | pd->syslog_facility;
639 syslog(priority, "%s|%s|%s|%s\n",
640 audit_pre ? audit_pre : "",
641 audit_opname(op), err_msg, op_msg);
643 DEBUG(1, ("%s|%s|%s|%s\n",
644 audit_pre ? audit_pre : "",
645 audit_opname(op), err_msg, op_msg));
648 TALLOC_FREE(audit_pre);
650 TALLOC_FREE(tmp_do_log_ctx);
654 * Return a string using the do_log_ctx()
656 static const char *smb_fname_str_do_log(struct connection_struct *conn,
657 const struct smb_filename *smb_fname)
662 if (smb_fname == NULL) {
666 if (smb_fname->base_name[0] != '/') {
667 char *abs_name = NULL;
668 struct smb_filename *fname_copy = cp_smb_filename(
671 if (fname_copy == NULL) {
675 if (!ISDOT(smb_fname->base_name)) {
676 abs_name = talloc_asprintf(do_log_ctx(),
678 conn->cwd_fsp->fsp_name->base_name,
679 smb_fname->base_name);
681 abs_name = talloc_strdup(do_log_ctx(),
682 conn->cwd_fsp->fsp_name->base_name);
684 if (abs_name == NULL) {
687 fname_copy->base_name = abs_name;
688 smb_fname = fname_copy;
691 status = get_full_smb_filename(do_log_ctx(), smb_fname, &fname);
692 if (!NT_STATUS_IS_OK(status)) {
699 * Return an fsp debug string using the do_log_ctx()
701 static const char *fsp_str_do_log(const struct files_struct *fsp)
703 return smb_fname_str_do_log(fsp->conn, fsp->fsp_name);
706 /* Implementation of vfs_ops. Pass everything on to the default
707 operation but log event first. */
709 static int smb_full_audit_connect(vfs_handle_struct *handle,
710 const char *svc, const char *user)
713 const char *none[] = { "none" };
714 struct vfs_full_audit_private_data *pd = NULL;
716 result = SMB_VFS_NEXT_CONNECT(handle, svc, user);
721 pd = talloc_zero(handle, struct vfs_full_audit_private_data);
723 SMB_VFS_NEXT_DISCONNECT(handle);
727 pd->syslog_facility = audit_syslog_facility(handle);
728 if (pd->syslog_facility == -1) {
729 DEBUG(1, ("%s: Unknown facility %s\n", __func__,
730 lp_parm_const_string(SNUM(handle->conn),
731 "full_audit", "facility",
733 SMB_VFS_NEXT_DISCONNECT(handle);
737 pd->syslog_priority = audit_syslog_priority(handle);
739 pd->log_secdesc = lp_parm_bool(SNUM(handle->conn),
740 "full_audit", "log_secdesc", false);
742 pd->do_syslog = lp_parm_bool(SNUM(handle->conn),
743 "full_audit", "syslog", true);
747 openlog("smbd_audit", 0, pd->syslog_facility);
751 pd->success_ops = init_bitmap(
752 pd, lp_parm_string_list(SNUM(handle->conn), "full_audit",
754 if (pd->success_ops == NULL) {
755 DBG_ERR("Invalid success operations list. Failing connect\n");
756 SMB_VFS_NEXT_DISCONNECT(handle);
759 pd->failure_ops = init_bitmap(
760 pd, lp_parm_string_list(SNUM(handle->conn), "full_audit",
762 if (pd->failure_ops == NULL) {
763 DBG_ERR("Invalid failure operations list. Failing connect\n");
764 SMB_VFS_NEXT_DISCONNECT(handle);
768 /* Store the private data. */
769 SMB_VFS_HANDLE_SET_DATA(handle, pd, NULL,
770 struct vfs_full_audit_private_data, return -1);
772 do_log(SMB_VFS_OP_CONNECT, True, handle,
778 static void smb_full_audit_disconnect(vfs_handle_struct *handle)
780 const struct loadparm_substitution *lp_sub =
781 loadparm_s3_global_substitution();
783 SMB_VFS_NEXT_DISCONNECT(handle);
785 do_log(SMB_VFS_OP_DISCONNECT, True, handle,
786 "%s", lp_servicename(talloc_tos(), lp_sub, SNUM(handle->conn)));
788 /* The bitmaps will be disconnected when the private
792 static uint64_t smb_full_audit_disk_free(vfs_handle_struct *handle,
793 const struct smb_filename *smb_fname,
800 result = SMB_VFS_NEXT_DISK_FREE(handle, smb_fname, bsize, dfree, dsize);
802 /* Don't have a reasonable notion of failure here */
804 do_log(SMB_VFS_OP_DISK_FREE,
808 smb_fname_str_do_log(handle->conn, smb_fname));
813 static int smb_full_audit_get_quota(struct vfs_handle_struct *handle,
814 const struct smb_filename *smb_fname,
815 enum SMB_QUOTA_TYPE qtype,
821 result = SMB_VFS_NEXT_GET_QUOTA(handle, smb_fname, qtype, id, qt);
823 do_log(SMB_VFS_OP_GET_QUOTA,
827 smb_fname_str_do_log(handle->conn, smb_fname));
832 static int smb_full_audit_set_quota(struct vfs_handle_struct *handle,
833 enum SMB_QUOTA_TYPE qtype, unid_t id,
838 result = SMB_VFS_NEXT_SET_QUOTA(handle, qtype, id, qt);
840 do_log(SMB_VFS_OP_SET_QUOTA, (result >= 0), handle, "");
845 static int smb_full_audit_get_shadow_copy_data(struct vfs_handle_struct *handle,
846 struct files_struct *fsp,
847 struct shadow_copy_data *shadow_copy_data,
852 result = SMB_VFS_NEXT_GET_SHADOW_COPY_DATA(handle, fsp, shadow_copy_data, labels);
854 do_log(SMB_VFS_OP_GET_SHADOW_COPY_DATA, (result >= 0), handle, "");
859 static int smb_full_audit_statvfs(struct vfs_handle_struct *handle,
860 const struct smb_filename *smb_fname,
861 struct vfs_statvfs_struct *statbuf)
865 result = SMB_VFS_NEXT_STATVFS(handle, smb_fname, statbuf);
867 do_log(SMB_VFS_OP_STATVFS, (result >= 0), handle, "");
872 static uint32_t smb_full_audit_fs_capabilities(struct vfs_handle_struct *handle, enum timestamp_set_resolution *p_ts_res)
876 result = SMB_VFS_NEXT_FS_CAPABILITIES(handle, p_ts_res);
878 do_log(SMB_VFS_OP_FS_CAPABILITIES, true, handle, "");
883 static NTSTATUS smb_full_audit_get_dfs_referrals(
884 struct vfs_handle_struct *handle,
885 struct dfs_GetDFSReferral *r)
889 status = SMB_VFS_NEXT_GET_DFS_REFERRALS(handle, r);
891 do_log(SMB_VFS_OP_GET_DFS_REFERRALS, NT_STATUS_IS_OK(status),
897 static NTSTATUS smb_full_audit_create_dfs_pathat(struct vfs_handle_struct *handle,
898 struct files_struct *dirfsp,
899 const struct smb_filename *smb_fname,
900 const struct referral *reflist,
901 size_t referral_count)
904 struct smb_filename *full_fname = NULL;
906 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
909 if (full_fname == NULL) {
910 return NT_STATUS_NO_MEMORY;
913 status = SMB_VFS_NEXT_CREATE_DFS_PATHAT(handle,
919 do_log(SMB_VFS_OP_CREATE_DFS_PATHAT,
920 NT_STATUS_IS_OK(status),
923 smb_fname_str_do_log(handle->conn, full_fname));
925 TALLOC_FREE(full_fname);
929 static NTSTATUS smb_full_audit_read_dfs_pathat(struct vfs_handle_struct *handle,
931 struct files_struct *dirfsp,
932 struct smb_filename *smb_fname,
933 struct referral **ppreflist,
934 size_t *preferral_count)
936 struct smb_filename *full_fname = NULL;
939 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
942 if (full_fname == NULL) {
943 return NT_STATUS_NO_MEMORY;
946 status = SMB_VFS_NEXT_READ_DFS_PATHAT(handle,
953 do_log(SMB_VFS_OP_READ_DFS_PATHAT,
954 NT_STATUS_IS_OK(status),
957 smb_fname_str_do_log(handle->conn, full_fname));
959 TALLOC_FREE(full_fname);
963 static NTSTATUS smb_full_audit_snap_check_path(struct vfs_handle_struct *handle,
965 const char *service_path,
970 status = SMB_VFS_NEXT_SNAP_CHECK_PATH(handle, mem_ctx, service_path,
972 do_log(SMB_VFS_OP_SNAP_CHECK_PATH, NT_STATUS_IS_OK(status),
978 static NTSTATUS smb_full_audit_snap_create(struct vfs_handle_struct *handle,
980 const char *base_volume,
988 status = SMB_VFS_NEXT_SNAP_CREATE(handle, mem_ctx, base_volume, tstamp,
989 rw, base_path, snap_path);
990 do_log(SMB_VFS_OP_SNAP_CREATE, NT_STATUS_IS_OK(status), handle, "");
995 static NTSTATUS smb_full_audit_snap_delete(struct vfs_handle_struct *handle,
1002 status = SMB_VFS_NEXT_SNAP_DELETE(handle, mem_ctx, base_path,
1004 do_log(SMB_VFS_OP_SNAP_DELETE, NT_STATUS_IS_OK(status), handle, "");
1009 static DIR *smb_full_audit_fdopendir(vfs_handle_struct *handle,
1010 files_struct *fsp, const char *mask, uint32_t attr)
1014 result = SMB_VFS_NEXT_FDOPENDIR(handle, fsp, mask, attr);
1016 do_log(SMB_VFS_OP_FDOPENDIR, (result != NULL), handle, "%s",
1017 fsp_str_do_log(fsp));
1022 static struct dirent *smb_full_audit_readdir(vfs_handle_struct *handle,
1023 struct files_struct *dirfsp,
1025 SMB_STRUCT_STAT *sbuf)
1027 struct dirent *result;
1029 result = SMB_VFS_NEXT_READDIR(handle, dirfsp, dirp, sbuf);
1031 /* This operation has no reasonable error condition
1032 * (End of dir is also failure), so always succeed.
1034 do_log(SMB_VFS_OP_READDIR, True, handle, "");
1039 static void smb_full_audit_seekdir(vfs_handle_struct *handle,
1040 DIR *dirp, long offset)
1042 SMB_VFS_NEXT_SEEKDIR(handle, dirp, offset);
1044 do_log(SMB_VFS_OP_SEEKDIR, True, handle, "");
1047 static long smb_full_audit_telldir(vfs_handle_struct *handle,
1052 result = SMB_VFS_NEXT_TELLDIR(handle, dirp);
1054 do_log(SMB_VFS_OP_TELLDIR, True, handle, "");
1059 static void smb_full_audit_rewinddir(vfs_handle_struct *handle,
1062 SMB_VFS_NEXT_REWINDDIR(handle, dirp);
1064 do_log(SMB_VFS_OP_REWINDDIR, True, handle, "");
1067 static int smb_full_audit_mkdirat(vfs_handle_struct *handle,
1068 struct files_struct *dirfsp,
1069 const struct smb_filename *smb_fname,
1072 struct smb_filename *full_fname = NULL;
1075 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1078 if (full_fname == NULL) {
1083 result = SMB_VFS_NEXT_MKDIRAT(handle,
1088 do_log(SMB_VFS_OP_MKDIRAT,
1092 smb_fname_str_do_log(handle->conn, full_fname));
1094 TALLOC_FREE(full_fname);
1099 static int smb_full_audit_closedir(vfs_handle_struct *handle,
1104 result = SMB_VFS_NEXT_CLOSEDIR(handle, dirp);
1106 do_log(SMB_VFS_OP_CLOSEDIR, (result >= 0), handle, "");
1111 static int smb_full_audit_openat(vfs_handle_struct *handle,
1112 const struct files_struct *dirfsp,
1113 const struct smb_filename *smb_fname,
1114 struct files_struct *fsp,
1115 const struct vfs_open_how *how)
1119 result = SMB_VFS_NEXT_OPENAT(handle, dirfsp, smb_fname, fsp, how);
1121 do_log(SMB_VFS_OP_OPENAT, (result >= 0), handle, "%s|%s",
1122 ((how->flags & O_WRONLY) || (how->flags & O_RDWR))?"w":"r",
1123 fsp_str_do_log(fsp));
1128 static NTSTATUS smb_full_audit_create_file(vfs_handle_struct *handle,
1129 struct smb_request *req,
1130 struct files_struct *dirfsp,
1131 struct smb_filename *smb_fname,
1132 uint32_t access_mask,
1133 uint32_t share_access,
1134 uint32_t create_disposition,
1135 uint32_t create_options,
1136 uint32_t file_attributes,
1137 uint32_t oplock_request,
1138 const struct smb2_lease *lease,
1139 uint64_t allocation_size,
1140 uint32_t private_flags,
1141 struct security_descriptor *sd,
1142 struct ea_list *ea_list,
1143 files_struct **result_fsp,
1145 const struct smb2_create_blobs *in_context_blobs,
1146 struct smb2_create_blobs *out_context_blobs)
1149 const char* str_create_disposition;
1151 switch (create_disposition) {
1152 case FILE_SUPERSEDE:
1153 str_create_disposition = "supersede";
1155 case FILE_OVERWRITE_IF:
1156 str_create_disposition = "overwrite_if";
1159 str_create_disposition = "open";
1161 case FILE_OVERWRITE:
1162 str_create_disposition = "overwrite";
1165 str_create_disposition = "create";
1168 str_create_disposition = "open_if";
1171 str_create_disposition = "unknown";
1174 result = SMB_VFS_NEXT_CREATE_FILE(
1175 handle, /* handle */
1177 dirfsp, /* dirfsp */
1178 smb_fname, /* fname */
1179 access_mask, /* access_mask */
1180 share_access, /* share_access */
1181 create_disposition, /* create_disposition*/
1182 create_options, /* create_options */
1183 file_attributes, /* file_attributes */
1184 oplock_request, /* oplock_request */
1186 allocation_size, /* allocation_size */
1189 ea_list, /* ea_list */
1190 result_fsp, /* result */
1192 in_context_blobs, out_context_blobs); /* create context */
1194 do_log(SMB_VFS_OP_CREATE_FILE, (NT_STATUS_IS_OK(result)), handle,
1195 "0x%x|%s|%s|%s", access_mask,
1196 create_options & FILE_DIRECTORY_FILE ? "dir" : "file",
1197 str_create_disposition,
1198 smb_fname_str_do_log(handle->conn, smb_fname));
1203 static int smb_full_audit_close(vfs_handle_struct *handle, files_struct *fsp)
1207 result = SMB_VFS_NEXT_CLOSE(handle, fsp);
1209 do_log(SMB_VFS_OP_CLOSE, (result >= 0), handle, "%s",
1210 fsp_str_do_log(fsp));
1215 static ssize_t smb_full_audit_pread(vfs_handle_struct *handle, files_struct *fsp,
1216 void *data, size_t n, off_t offset)
1220 result = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
1222 do_log(SMB_VFS_OP_PREAD, (result >= 0), handle, "%s",
1223 fsp_str_do_log(fsp));
1228 struct smb_full_audit_pread_state {
1229 vfs_handle_struct *handle;
1232 struct vfs_aio_state vfs_aio_state;
1235 static void smb_full_audit_pread_done(struct tevent_req *subreq);
1237 static struct tevent_req *smb_full_audit_pread_send(
1238 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1239 struct tevent_context *ev, struct files_struct *fsp,
1240 void *data, size_t n, off_t offset)
1242 struct tevent_req *req, *subreq;
1243 struct smb_full_audit_pread_state *state;
1245 req = tevent_req_create(mem_ctx, &state,
1246 struct smb_full_audit_pread_state);
1248 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
1249 fsp_str_do_log(fsp));
1252 state->handle = handle;
1255 subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
1257 if (tevent_req_nomem(subreq, req)) {
1258 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
1259 fsp_str_do_log(fsp));
1260 return tevent_req_post(req, ev);
1262 tevent_req_set_callback(subreq, smb_full_audit_pread_done, req);
1264 do_log(SMB_VFS_OP_PREAD_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1268 static void smb_full_audit_pread_done(struct tevent_req *subreq)
1270 struct tevent_req *req = tevent_req_callback_data(
1271 subreq, struct tevent_req);
1272 struct smb_full_audit_pread_state *state = tevent_req_data(
1273 req, struct smb_full_audit_pread_state);
1275 state->ret = SMB_VFS_PREAD_RECV(subreq, &state->vfs_aio_state);
1276 TALLOC_FREE(subreq);
1277 tevent_req_done(req);
1280 static ssize_t smb_full_audit_pread_recv(struct tevent_req *req,
1281 struct vfs_aio_state *vfs_aio_state)
1283 struct smb_full_audit_pread_state *state = tevent_req_data(
1284 req, struct smb_full_audit_pread_state);
1286 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1287 do_log(SMB_VFS_OP_PREAD_RECV, false, state->handle, "%s",
1288 fsp_str_do_log(state->fsp));
1292 do_log(SMB_VFS_OP_PREAD_RECV, (state->ret >= 0), state->handle, "%s",
1293 fsp_str_do_log(state->fsp));
1295 *vfs_aio_state = state->vfs_aio_state;
1299 static ssize_t smb_full_audit_pwrite(vfs_handle_struct *handle, files_struct *fsp,
1300 const void *data, size_t n,
1305 result = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
1307 do_log(SMB_VFS_OP_PWRITE, (result >= 0), handle, "%s",
1308 fsp_str_do_log(fsp));
1313 struct smb_full_audit_pwrite_state {
1314 vfs_handle_struct *handle;
1317 struct vfs_aio_state vfs_aio_state;
1320 static void smb_full_audit_pwrite_done(struct tevent_req *subreq);
1322 static struct tevent_req *smb_full_audit_pwrite_send(
1323 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1324 struct tevent_context *ev, struct files_struct *fsp,
1325 const void *data, size_t n, off_t offset)
1327 struct tevent_req *req, *subreq;
1328 struct smb_full_audit_pwrite_state *state;
1330 req = tevent_req_create(mem_ctx, &state,
1331 struct smb_full_audit_pwrite_state);
1333 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1334 fsp_str_do_log(fsp));
1337 state->handle = handle;
1340 subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
1342 if (tevent_req_nomem(subreq, req)) {
1343 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1344 fsp_str_do_log(fsp));
1345 return tevent_req_post(req, ev);
1347 tevent_req_set_callback(subreq, smb_full_audit_pwrite_done, req);
1349 do_log(SMB_VFS_OP_PWRITE_SEND, true, handle, "%s",
1350 fsp_str_do_log(fsp));
1354 static void smb_full_audit_pwrite_done(struct tevent_req *subreq)
1356 struct tevent_req *req = tevent_req_callback_data(
1357 subreq, struct tevent_req);
1358 struct smb_full_audit_pwrite_state *state = tevent_req_data(
1359 req, struct smb_full_audit_pwrite_state);
1361 state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->vfs_aio_state);
1362 TALLOC_FREE(subreq);
1363 tevent_req_done(req);
1366 static ssize_t smb_full_audit_pwrite_recv(struct tevent_req *req,
1367 struct vfs_aio_state *vfs_aio_state)
1369 struct smb_full_audit_pwrite_state *state = tevent_req_data(
1370 req, struct smb_full_audit_pwrite_state);
1372 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1373 do_log(SMB_VFS_OP_PWRITE_RECV, false, state->handle, "%s",
1374 fsp_str_do_log(state->fsp));
1378 do_log(SMB_VFS_OP_PWRITE_RECV, (state->ret >= 0), state->handle, "%s",
1379 fsp_str_do_log(state->fsp));
1381 *vfs_aio_state = state->vfs_aio_state;
1385 static off_t smb_full_audit_lseek(vfs_handle_struct *handle, files_struct *fsp,
1386 off_t offset, int whence)
1390 result = SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence);
1392 do_log(SMB_VFS_OP_LSEEK, (result != (ssize_t)-1), handle,
1393 "%s", fsp_str_do_log(fsp));
1398 static ssize_t smb_full_audit_sendfile(vfs_handle_struct *handle, int tofd,
1399 files_struct *fromfsp,
1400 const DATA_BLOB *hdr, off_t offset,
1405 result = SMB_VFS_NEXT_SENDFILE(handle, tofd, fromfsp, hdr, offset, n);
1407 do_log(SMB_VFS_OP_SENDFILE, (result >= 0), handle,
1408 "%s", fsp_str_do_log(fromfsp));
1413 static ssize_t smb_full_audit_recvfile(vfs_handle_struct *handle, int fromfd,
1414 files_struct *tofsp,
1420 result = SMB_VFS_NEXT_RECVFILE(handle, fromfd, tofsp, offset, n);
1422 do_log(SMB_VFS_OP_RECVFILE, (result >= 0), handle,
1423 "%s", fsp_str_do_log(tofsp));
1428 static int smb_full_audit_renameat(vfs_handle_struct *handle,
1429 files_struct *srcfsp,
1430 const struct smb_filename *smb_fname_src,
1431 files_struct *dstfsp,
1432 const struct smb_filename *smb_fname_dst)
1436 struct smb_filename *full_fname_src = NULL;
1437 struct smb_filename *full_fname_dst = NULL;
1439 full_fname_src = full_path_from_dirfsp_atname(talloc_tos(),
1442 if (full_fname_src == NULL) {
1446 full_fname_dst = full_path_from_dirfsp_atname(talloc_tos(),
1449 if (full_fname_dst == NULL) {
1450 TALLOC_FREE(full_fname_src);
1455 result = SMB_VFS_NEXT_RENAMEAT(handle,
1462 saved_errno = errno;
1464 do_log(SMB_VFS_OP_RENAMEAT, (result >= 0), handle, "%s|%s",
1465 smb_fname_str_do_log(handle->conn, full_fname_src),
1466 smb_fname_str_do_log(handle->conn, full_fname_dst));
1468 TALLOC_FREE(full_fname_src);
1469 TALLOC_FREE(full_fname_dst);
1472 errno = saved_errno;
1477 struct smb_full_audit_fsync_state {
1478 vfs_handle_struct *handle;
1481 struct vfs_aio_state vfs_aio_state;
1484 static void smb_full_audit_fsync_done(struct tevent_req *subreq);
1486 static struct tevent_req *smb_full_audit_fsync_send(
1487 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1488 struct tevent_context *ev, struct files_struct *fsp)
1490 struct tevent_req *req, *subreq;
1491 struct smb_full_audit_fsync_state *state;
1493 req = tevent_req_create(mem_ctx, &state,
1494 struct smb_full_audit_fsync_state);
1496 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1497 fsp_str_do_log(fsp));
1500 state->handle = handle;
1503 subreq = SMB_VFS_NEXT_FSYNC_SEND(state, ev, handle, fsp);
1504 if (tevent_req_nomem(subreq, req)) {
1505 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1506 fsp_str_do_log(fsp));
1507 return tevent_req_post(req, ev);
1509 tevent_req_set_callback(subreq, smb_full_audit_fsync_done, req);
1511 do_log(SMB_VFS_OP_FSYNC_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1515 static void smb_full_audit_fsync_done(struct tevent_req *subreq)
1517 struct tevent_req *req = tevent_req_callback_data(
1518 subreq, struct tevent_req);
1519 struct smb_full_audit_fsync_state *state = tevent_req_data(
1520 req, struct smb_full_audit_fsync_state);
1522 state->ret = SMB_VFS_FSYNC_RECV(subreq, &state->vfs_aio_state);
1523 TALLOC_FREE(subreq);
1524 tevent_req_done(req);
1527 static int smb_full_audit_fsync_recv(struct tevent_req *req,
1528 struct vfs_aio_state *vfs_aio_state)
1530 struct smb_full_audit_fsync_state *state = tevent_req_data(
1531 req, struct smb_full_audit_fsync_state);
1533 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1534 do_log(SMB_VFS_OP_FSYNC_RECV, false, state->handle, "%s",
1535 fsp_str_do_log(state->fsp));
1539 do_log(SMB_VFS_OP_FSYNC_RECV, (state->ret >= 0), state->handle, "%s",
1540 fsp_str_do_log(state->fsp));
1542 *vfs_aio_state = state->vfs_aio_state;
1546 static int smb_full_audit_stat(vfs_handle_struct *handle,
1547 struct smb_filename *smb_fname)
1551 result = SMB_VFS_NEXT_STAT(handle, smb_fname);
1553 do_log(SMB_VFS_OP_STAT, (result >= 0), handle, "%s",
1554 smb_fname_str_do_log(handle->conn, smb_fname));
1559 static int smb_full_audit_fstat(vfs_handle_struct *handle, files_struct *fsp,
1560 SMB_STRUCT_STAT *sbuf)
1564 result = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1566 do_log(SMB_VFS_OP_FSTAT, (result >= 0), handle, "%s",
1567 fsp_str_do_log(fsp));
1572 static int smb_full_audit_lstat(vfs_handle_struct *handle,
1573 struct smb_filename *smb_fname)
1577 result = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
1579 do_log(SMB_VFS_OP_LSTAT, (result >= 0), handle, "%s",
1580 smb_fname_str_do_log(handle->conn, smb_fname));
1585 static int smb_full_audit_fstatat(
1586 struct vfs_handle_struct *handle,
1587 const struct files_struct *dirfsp,
1588 const struct smb_filename *smb_fname,
1589 SMB_STRUCT_STAT *sbuf,
1594 result = SMB_VFS_NEXT_FSTATAT(handle, dirfsp, smb_fname, sbuf, flags);
1596 do_log(SMB_VFS_OP_FSTATAT,
1600 fsp_str_do_log(dirfsp),
1601 smb_fname_str_do_log(handle->conn, smb_fname));
1605 static uint64_t smb_full_audit_get_alloc_size(vfs_handle_struct *handle,
1606 files_struct *fsp, const SMB_STRUCT_STAT *sbuf)
1610 result = SMB_VFS_NEXT_GET_ALLOC_SIZE(handle, fsp, sbuf);
1612 do_log(SMB_VFS_OP_GET_ALLOC_SIZE, (result != (uint64_t)-1), handle,
1613 "%llu", (unsigned long long)result);
1618 static int smb_full_audit_unlinkat(vfs_handle_struct *handle,
1619 struct files_struct *dirfsp,
1620 const struct smb_filename *smb_fname,
1623 struct smb_filename *full_fname = NULL;
1626 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1629 if (full_fname == NULL) {
1633 result = SMB_VFS_NEXT_UNLINKAT(handle,
1638 do_log(SMB_VFS_OP_UNLINKAT, (result >= 0), handle, "%s",
1639 smb_fname_str_do_log(handle->conn, full_fname));
1641 TALLOC_FREE(full_fname);
1645 static int smb_full_audit_fchmod(vfs_handle_struct *handle, files_struct *fsp,
1650 result = SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1652 do_log(SMB_VFS_OP_FCHMOD, (result >= 0), handle,
1653 "%s|%o", fsp_str_do_log(fsp), mode);
1658 static int smb_full_audit_fchown(vfs_handle_struct *handle, files_struct *fsp,
1659 uid_t uid, gid_t gid)
1663 result = SMB_VFS_NEXT_FCHOWN(handle, fsp, uid, gid);
1665 do_log(SMB_VFS_OP_FCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1666 fsp_str_do_log(fsp), (long int)uid, (long int)gid);
1671 static int smb_full_audit_lchown(vfs_handle_struct *handle,
1672 const struct smb_filename *smb_fname,
1678 result = SMB_VFS_NEXT_LCHOWN(handle, smb_fname, uid, gid);
1680 do_log(SMB_VFS_OP_LCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1681 smb_fname->base_name, (long int)uid, (long int)gid);
1686 static int smb_full_audit_chdir(vfs_handle_struct *handle,
1687 const struct smb_filename *smb_fname)
1691 result = SMB_VFS_NEXT_CHDIR(handle, smb_fname);
1693 do_log(SMB_VFS_OP_CHDIR,
1697 smb_fname_str_do_log(handle->conn, smb_fname));
1702 static struct smb_filename *smb_full_audit_getwd(vfs_handle_struct *handle,
1705 struct smb_filename *result;
1707 result = SMB_VFS_NEXT_GETWD(handle, ctx);
1709 do_log(SMB_VFS_OP_GETWD, (result != NULL), handle, "%s",
1710 result == NULL? "" : result->base_name);
1715 static int smb_full_audit_fntimes(vfs_handle_struct *handle,
1717 struct smb_file_time *ft)
1720 time_t create_time = convert_timespec_to_time_t(ft->create_time);
1721 time_t atime = convert_timespec_to_time_t(ft->atime);
1722 time_t mtime = convert_timespec_to_time_t(ft->mtime);
1723 time_t ctime = convert_timespec_to_time_t(ft->ctime);
1724 const char *create_time_str = "";
1725 const char *atime_str = "";
1726 const char *mtime_str = "";
1727 const char *ctime_str = "";
1728 TALLOC_CTX *frame = talloc_stackframe();
1730 if (frame == NULL) {
1735 result = SMB_VFS_NEXT_FNTIMES(handle, fsp, ft);
1737 if (create_time > 0) {
1738 create_time_str = timestring(frame, create_time);
1741 atime_str = timestring(frame, atime);
1744 mtime_str = timestring(frame, mtime);
1747 ctime_str = timestring(frame, ctime);
1750 do_log(SMB_VFS_OP_FNTIMES,
1754 fsp_str_do_log(fsp),
1765 static int smb_full_audit_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
1770 result = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1772 do_log(SMB_VFS_OP_FTRUNCATE, (result >= 0), handle,
1773 "%s", fsp_str_do_log(fsp));
1778 static int smb_full_audit_fallocate(vfs_handle_struct *handle, files_struct *fsp,
1785 result = SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
1787 do_log(SMB_VFS_OP_FALLOCATE, (result >= 0), handle,
1788 "%s", fsp_str_do_log(fsp));
1793 static bool smb_full_audit_lock(vfs_handle_struct *handle, files_struct *fsp,
1794 int op, off_t offset, off_t count, int type)
1798 result = SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type);
1800 do_log(SMB_VFS_OP_LOCK, result, handle, "%s", fsp_str_do_log(fsp));
1805 static int smb_full_audit_filesystem_sharemode(struct vfs_handle_struct *handle,
1806 struct files_struct *fsp,
1807 uint32_t share_access,
1808 uint32_t access_mask)
1812 result = SMB_VFS_NEXT_FILESYSTEM_SHAREMODE(handle,
1817 do_log(SMB_VFS_OP_FILESYSTEM_SHAREMODE, (result >= 0), handle, "%s",
1818 fsp_str_do_log(fsp));
1823 static int smb_full_audit_fcntl(struct vfs_handle_struct *handle,
1824 struct files_struct *fsp,
1825 int cmd, va_list cmd_arg)
1828 va_list dup_cmd_arg;
1831 va_copy(dup_cmd_arg, cmd_arg);
1832 arg = va_arg(dup_cmd_arg, void *);
1833 result = SMB_VFS_NEXT_FCNTL(handle, fsp, cmd, arg);
1834 va_end(dup_cmd_arg);
1836 do_log(SMB_VFS_OP_FCNTL, (result >= 0), handle, "%s",
1837 fsp_str_do_log(fsp));
1842 static int smb_full_audit_linux_setlease(vfs_handle_struct *handle, files_struct *fsp,
1847 result = SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
1849 do_log(SMB_VFS_OP_LINUX_SETLEASE, (result >= 0), handle, "%s",
1850 fsp_str_do_log(fsp));
1855 static bool smb_full_audit_getlock(vfs_handle_struct *handle, files_struct *fsp,
1856 off_t *poffset, off_t *pcount, int *ptype, pid_t *ppid)
1860 result = SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype, ppid);
1862 do_log(SMB_VFS_OP_GETLOCK, result, handle, "%s", fsp_str_do_log(fsp));
1867 static int smb_full_audit_symlinkat(vfs_handle_struct *handle,
1868 const struct smb_filename *link_contents,
1869 struct files_struct *dirfsp,
1870 const struct smb_filename *new_smb_fname)
1872 struct smb_filename *full_fname = NULL;
1875 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1878 if (full_fname == NULL) {
1882 result = SMB_VFS_NEXT_SYMLINKAT(handle,
1887 do_log(SMB_VFS_OP_SYMLINKAT,
1891 link_contents->base_name,
1892 smb_fname_str_do_log(handle->conn, full_fname));
1894 TALLOC_FREE(full_fname);
1899 static int smb_full_audit_readlinkat(vfs_handle_struct *handle,
1900 const struct files_struct *dirfsp,
1901 const struct smb_filename *smb_fname,
1905 struct smb_filename *full_fname = NULL;
1908 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1911 if (full_fname == NULL) {
1915 result = SMB_VFS_NEXT_READLINKAT(handle,
1921 do_log(SMB_VFS_OP_READLINKAT,
1925 smb_fname_str_do_log(handle->conn, full_fname));
1927 TALLOC_FREE(full_fname);
1932 static int smb_full_audit_linkat(vfs_handle_struct *handle,
1933 files_struct *srcfsp,
1934 const struct smb_filename *old_smb_fname,
1935 files_struct *dstfsp,
1936 const struct smb_filename *new_smb_fname,
1939 struct smb_filename *old_full_fname = NULL;
1940 struct smb_filename *new_full_fname = NULL;
1943 old_full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1946 if (old_full_fname == NULL) {
1949 new_full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1952 if (new_full_fname == NULL) {
1953 TALLOC_FREE(old_full_fname);
1956 result = SMB_VFS_NEXT_LINKAT(handle,
1963 do_log(SMB_VFS_OP_LINKAT,
1967 smb_fname_str_do_log(handle->conn, old_full_fname),
1968 smb_fname_str_do_log(handle->conn, new_full_fname));
1970 TALLOC_FREE(old_full_fname);
1971 TALLOC_FREE(new_full_fname);
1976 static int smb_full_audit_mknodat(vfs_handle_struct *handle,
1977 files_struct *dirfsp,
1978 const struct smb_filename *smb_fname,
1982 struct smb_filename *full_fname = NULL;
1985 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1988 if (full_fname == NULL) {
1992 result = SMB_VFS_NEXT_MKNODAT(handle,
1998 do_log(SMB_VFS_OP_MKNODAT,
2002 smb_fname_str_do_log(handle->conn, full_fname));
2004 TALLOC_FREE(full_fname);
2009 static struct smb_filename *smb_full_audit_realpath(vfs_handle_struct *handle,
2011 const struct smb_filename *smb_fname)
2013 struct smb_filename *result_fname = NULL;
2015 result_fname = SMB_VFS_NEXT_REALPATH(handle, ctx, smb_fname);
2017 do_log(SMB_VFS_OP_REALPATH,
2018 (result_fname != NULL),
2021 smb_fname_str_do_log(handle->conn, smb_fname));
2023 return result_fname;
2026 static int smb_full_audit_fchflags(vfs_handle_struct *handle,
2027 struct files_struct *fsp,
2032 result = SMB_VFS_NEXT_FCHFLAGS(handle, fsp, flags);
2034 do_log(SMB_VFS_OP_FCHFLAGS,
2038 smb_fname_str_do_log(handle->conn, fsp->fsp_name));
2043 static struct file_id smb_full_audit_file_id_create(struct vfs_handle_struct *handle,
2044 const SMB_STRUCT_STAT *sbuf)
2046 struct file_id id_zero = { 0 };
2047 struct file_id result;
2048 struct file_id_buf idbuf;
2050 result = SMB_VFS_NEXT_FILE_ID_CREATE(handle, sbuf);
2052 do_log(SMB_VFS_OP_FILE_ID_CREATE,
2053 !file_id_equal(&id_zero, &result),
2056 file_id_str_buf(result, &idbuf));
2061 static uint64_t smb_full_audit_fs_file_id(struct vfs_handle_struct *handle,
2062 const SMB_STRUCT_STAT *sbuf)
2066 result = SMB_VFS_NEXT_FS_FILE_ID(handle, sbuf);
2068 do_log(SMB_VFS_OP_FS_FILE_ID,
2070 handle, "%" PRIu64, result);
2075 static NTSTATUS smb_full_audit_fstreaminfo(vfs_handle_struct *handle,
2076 struct files_struct *fsp,
2077 TALLOC_CTX *mem_ctx,
2078 unsigned int *pnum_streams,
2079 struct stream_struct **pstreams)
2083 result = SMB_VFS_NEXT_FSTREAMINFO(handle, fsp, mem_ctx,
2084 pnum_streams, pstreams);
2086 do_log(SMB_VFS_OP_FSTREAMINFO,
2087 NT_STATUS_IS_OK(result),
2090 smb_fname_str_do_log(handle->conn, fsp->fsp_name));
2095 static NTSTATUS smb_full_audit_get_real_filename_at(
2096 struct vfs_handle_struct *handle,
2097 struct files_struct *dirfsp,
2099 TALLOC_CTX *mem_ctx,
2104 result = SMB_VFS_NEXT_GET_REAL_FILENAME_AT(
2105 handle, dirfsp, name, mem_ctx, found_name);
2107 do_log(SMB_VFS_OP_GET_REAL_FILENAME_AT,
2108 NT_STATUS_IS_OK(result),
2111 fsp_str_dbg(dirfsp),
2113 NT_STATUS_IS_OK(result) ? *found_name : "");
2118 static const char *smb_full_audit_connectpath(vfs_handle_struct *handle,
2119 const struct smb_filename *smb_fname)
2123 result = SMB_VFS_NEXT_CONNECTPATH(handle, smb_fname);
2125 do_log(SMB_VFS_OP_CONNECTPATH,
2129 smb_fname_str_do_log(handle->conn, smb_fname));
2134 static NTSTATUS smb_full_audit_brl_lock_windows(struct vfs_handle_struct *handle,
2135 struct byte_range_lock *br_lck,
2136 struct lock_struct *plock)
2140 result = SMB_VFS_NEXT_BRL_LOCK_WINDOWS(handle, br_lck, plock);
2142 do_log(SMB_VFS_OP_BRL_LOCK_WINDOWS, NT_STATUS_IS_OK(result), handle,
2143 "%s:%llu-%llu. type=%d.",
2144 fsp_str_do_log(brl_fsp(br_lck)),
2145 (unsigned long long)plock->start,
2146 (unsigned long long)plock->size,
2152 static bool smb_full_audit_brl_unlock_windows(struct vfs_handle_struct *handle,
2153 struct byte_range_lock *br_lck,
2154 const struct lock_struct *plock)
2158 result = SMB_VFS_NEXT_BRL_UNLOCK_WINDOWS(handle, br_lck, plock);
2160 do_log(SMB_VFS_OP_BRL_UNLOCK_WINDOWS, (result == 0), handle,
2161 "%s:%llu-%llu:%d", fsp_str_do_log(brl_fsp(br_lck)),
2162 (unsigned long long)plock->start,
2163 (unsigned long long)plock->size,
2169 static bool smb_full_audit_strict_lock_check(struct vfs_handle_struct *handle,
2170 struct files_struct *fsp,
2171 struct lock_struct *plock)
2175 result = SMB_VFS_NEXT_STRICT_LOCK_CHECK(handle, fsp, plock);
2177 do_log(SMB_VFS_OP_STRICT_LOCK_CHECK, result, handle,
2178 "%s:%llu-%llu:%d", fsp_str_do_log(fsp),
2179 (unsigned long long)plock->start,
2180 (unsigned long long)plock->size,
2186 static NTSTATUS smb_full_audit_translate_name(struct vfs_handle_struct *handle,
2188 enum vfs_translate_direction direction,
2189 TALLOC_CTX *mem_ctx,
2194 result = SMB_VFS_NEXT_TRANSLATE_NAME(handle, name, direction, mem_ctx,
2197 do_log(SMB_VFS_OP_TRANSLATE_NAME, NT_STATUS_IS_OK(result), handle, "");
2202 static NTSTATUS smb_full_audit_parent_pathname(struct vfs_handle_struct *handle,
2203 TALLOC_CTX *mem_ctx,
2204 const struct smb_filename *smb_fname_in,
2205 struct smb_filename **parent_dir_out,
2206 struct smb_filename **atname_out)
2210 result = SMB_VFS_NEXT_PARENT_PATHNAME(handle,
2215 do_log(SMB_VFS_OP_CONNECTPATH,
2216 NT_STATUS_IS_OK(result),
2219 smb_fname_str_do_log(handle->conn, smb_fname_in));
2224 static NTSTATUS smb_full_audit_fsctl(struct vfs_handle_struct *handle,
2225 struct files_struct *fsp,
2229 const uint8_t *_in_data,
2231 uint8_t **_out_data,
2232 uint32_t max_out_len,
2237 result = SMB_VFS_NEXT_FSCTL(handle,
2248 do_log(SMB_VFS_OP_FSCTL, NT_STATUS_IS_OK(result), handle, "");
2253 static struct tevent_req *smb_full_audit_offload_read_send(
2254 TALLOC_CTX *mem_ctx,
2255 struct tevent_context *ev,
2256 struct vfs_handle_struct *handle,
2257 struct files_struct *fsp,
2263 struct tevent_req *req = NULL;
2265 req = SMB_VFS_NEXT_OFFLOAD_READ_SEND(mem_ctx, ev, handle, fsp,
2266 fsctl, ttl, offset, to_copy);
2268 do_log(SMB_VFS_OP_OFFLOAD_READ_SEND, req, handle, "");
2273 static NTSTATUS smb_full_audit_offload_read_recv(
2274 struct tevent_req *req,
2275 struct vfs_handle_struct *handle,
2276 TALLOC_CTX *mem_ctx,
2279 DATA_BLOB *_token_blob)
2283 status = SMB_VFS_NEXT_OFFLOAD_READ_RECV(req, handle, mem_ctx,
2284 flags, xferlen, _token_blob);
2286 do_log(SMB_VFS_OP_OFFLOAD_READ_RECV, NT_STATUS_IS_OK(status), handle, "");
2291 static struct tevent_req *smb_full_audit_offload_write_send(struct vfs_handle_struct *handle,
2292 TALLOC_CTX *mem_ctx,
2293 struct tevent_context *ev,
2296 off_t transfer_offset,
2297 struct files_struct *dest_fsp,
2301 struct tevent_req *req;
2303 req = SMB_VFS_NEXT_OFFLOAD_WRITE_SEND(handle, mem_ctx, ev,
2304 fsctl, token, transfer_offset,
2305 dest_fsp, dest_off, num);
2307 do_log(SMB_VFS_OP_OFFLOAD_WRITE_SEND, req, handle, "");
2312 static NTSTATUS smb_full_audit_offload_write_recv(struct vfs_handle_struct *handle,
2313 struct tevent_req *req,
2318 result = SMB_VFS_NEXT_OFFLOAD_WRITE_RECV(handle, req, copied);
2320 do_log(SMB_VFS_OP_OFFLOAD_WRITE_RECV, NT_STATUS_IS_OK(result), handle, "");
2325 static NTSTATUS smb_full_audit_fget_compression(vfs_handle_struct *handle,
2326 TALLOC_CTX *mem_ctx,
2327 struct files_struct *fsp,
2328 uint16_t *_compression_fmt)
2332 result = SMB_VFS_NEXT_FGET_COMPRESSION(handle, mem_ctx, fsp,
2335 do_log(SMB_VFS_OP_FGET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
2337 fsp_str_do_log(fsp));
2342 static NTSTATUS smb_full_audit_set_compression(vfs_handle_struct *handle,
2343 TALLOC_CTX *mem_ctx,
2344 struct files_struct *fsp,
2345 uint16_t compression_fmt)
2349 result = SMB_VFS_NEXT_SET_COMPRESSION(handle, mem_ctx, fsp,
2352 do_log(SMB_VFS_OP_SET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
2353 "%s", fsp_str_do_log(fsp));
2358 static NTSTATUS smb_full_audit_freaddir_attr(struct vfs_handle_struct *handle,
2359 struct files_struct *fsp,
2360 TALLOC_CTX *mem_ctx,
2361 struct readdir_attr_data **pattr_data)
2365 status = SMB_VFS_NEXT_FREADDIR_ATTR(handle, fsp, mem_ctx, pattr_data);
2367 do_log(SMB_VFS_OP_FREADDIR_ATTR,
2368 NT_STATUS_IS_OK(status),
2371 fsp_str_do_log(fsp));
2376 struct smb_full_audit_get_dos_attributes_state {
2377 struct vfs_aio_state aio_state;
2378 vfs_handle_struct *handle;
2379 files_struct *dir_fsp;
2380 const struct smb_filename *smb_fname;
2384 static void smb_full_audit_get_dos_attributes_done(struct tevent_req *subreq);
2386 static struct tevent_req *smb_full_audit_get_dos_attributes_send(
2387 TALLOC_CTX *mem_ctx,
2388 struct tevent_context *ev,
2389 struct vfs_handle_struct *handle,
2390 files_struct *dir_fsp,
2391 struct smb_filename *smb_fname)
2393 struct tevent_req *req = NULL;
2394 struct smb_full_audit_get_dos_attributes_state *state = NULL;
2395 struct tevent_req *subreq = NULL;
2397 req = tevent_req_create(mem_ctx, &state,
2398 struct smb_full_audit_get_dos_attributes_state);
2400 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2404 fsp_str_do_log(dir_fsp),
2405 smb_fname->base_name);
2408 *state = (struct smb_full_audit_get_dos_attributes_state) {
2411 .smb_fname = smb_fname,
2414 subreq = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES_SEND(mem_ctx,
2419 if (tevent_req_nomem(subreq, req)) {
2420 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2424 fsp_str_do_log(dir_fsp),
2425 smb_fname->base_name);
2426 return tevent_req_post(req, ev);
2428 tevent_req_set_callback(subreq,
2429 smb_full_audit_get_dos_attributes_done,
2432 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2436 fsp_str_do_log(dir_fsp),
2437 smb_fname->base_name);
2442 static void smb_full_audit_get_dos_attributes_done(struct tevent_req *subreq)
2444 struct tevent_req *req =
2445 tevent_req_callback_data(subreq,
2447 struct smb_full_audit_get_dos_attributes_state *state =
2448 tevent_req_data(req,
2449 struct smb_full_audit_get_dos_attributes_state);
2452 status = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES_RECV(subreq,
2455 TALLOC_FREE(subreq);
2456 if (tevent_req_nterror(req, status)) {
2460 tevent_req_done(req);
2464 static NTSTATUS smb_full_audit_get_dos_attributes_recv(struct tevent_req *req,
2465 struct vfs_aio_state *aio_state,
2468 struct smb_full_audit_get_dos_attributes_state *state =
2469 tevent_req_data(req,
2470 struct smb_full_audit_get_dos_attributes_state);
2473 if (tevent_req_is_nterror(req, &status)) {
2474 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV,
2478 fsp_str_do_log(state->dir_fsp),
2479 state->smb_fname->base_name);
2480 tevent_req_received(req);
2484 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV,
2488 fsp_str_do_log(state->dir_fsp),
2489 state->smb_fname->base_name);
2491 *aio_state = state->aio_state;
2492 *dosmode = state->dosmode;
2493 tevent_req_received(req);
2494 return NT_STATUS_OK;
2497 static NTSTATUS smb_full_audit_fget_dos_attributes(
2498 struct vfs_handle_struct *handle,
2499 struct files_struct *fsp,
2504 status = SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle,
2508 do_log(SMB_VFS_OP_FGET_DOS_ATTRIBUTES,
2509 NT_STATUS_IS_OK(status),
2512 fsp_str_do_log(fsp));
2517 static NTSTATUS smb_full_audit_fset_dos_attributes(
2518 struct vfs_handle_struct *handle,
2519 struct files_struct *fsp,
2524 status = SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle,
2528 do_log(SMB_VFS_OP_FSET_DOS_ATTRIBUTES,
2529 NT_STATUS_IS_OK(status),
2532 fsp_str_do_log(fsp));
2537 static NTSTATUS smb_full_audit_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
2538 uint32_t security_info,
2539 TALLOC_CTX *mem_ctx,
2540 struct security_descriptor **ppdesc)
2544 result = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
2547 do_log(SMB_VFS_OP_FGET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2548 "%s", fsp_str_do_log(fsp));
2553 static NTSTATUS smb_full_audit_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
2554 uint32_t security_info_sent,
2555 const struct security_descriptor *psd)
2557 struct vfs_full_audit_private_data *pd;
2561 SMB_VFS_HANDLE_GET_DATA(handle, pd,
2562 struct vfs_full_audit_private_data,
2563 return NT_STATUS_INTERNAL_ERROR);
2565 if (pd->log_secdesc) {
2566 sd = sddl_encode(talloc_tos(), psd, get_global_sam_sid());
2569 result = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
2571 do_log(SMB_VFS_OP_FSET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2572 "%s [%s]", fsp_str_do_log(fsp), sd ? sd : "");
2579 static NTSTATUS smb_full_audit_audit_file(struct vfs_handle_struct *handle,
2580 struct smb_filename *file,
2581 struct security_acl *sacl,
2582 uint32_t access_requested,
2583 uint32_t access_denied)
2587 result = SMB_VFS_NEXT_AUDIT_FILE(handle,
2593 do_log(SMB_VFS_OP_AUDIT_FILE, NT_STATUS_IS_OK(result), handle,
2595 smb_fname_str_do_log(handle->conn, file));
2600 static SMB_ACL_T smb_full_audit_sys_acl_get_fd(vfs_handle_struct *handle,
2602 SMB_ACL_TYPE_T type,
2603 TALLOC_CTX *mem_ctx)
2607 result = SMB_VFS_NEXT_SYS_ACL_GET_FD(handle,
2612 do_log(SMB_VFS_OP_SYS_ACL_GET_FD, (result != NULL), handle,
2613 "%s", fsp_str_do_log(fsp));
2618 static int smb_full_audit_sys_acl_blob_get_fd(vfs_handle_struct *handle,
2620 TALLOC_CTX *mem_ctx,
2621 char **blob_description,
2626 result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle, fsp, mem_ctx, blob_description, blob);
2628 do_log(SMB_VFS_OP_SYS_ACL_BLOB_GET_FD, (result >= 0), handle,
2629 "%s", fsp_str_do_log(fsp));
2634 static int smb_full_audit_sys_acl_set_fd(vfs_handle_struct *handle,
2635 struct files_struct *fsp,
2636 SMB_ACL_TYPE_T type,
2641 result = SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, type, theacl);
2643 do_log(SMB_VFS_OP_SYS_ACL_SET_FD, (result >= 0), handle,
2644 "%s", fsp_str_do_log(fsp));
2649 static int smb_full_audit_sys_acl_delete_def_fd(vfs_handle_struct *handle,
2650 struct files_struct *fsp)
2654 result = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FD(handle, fsp);
2656 do_log(SMB_VFS_OP_SYS_ACL_DELETE_DEF_FD,
2660 fsp_str_do_log(fsp));
2665 struct smb_full_audit_getxattrat_state {
2666 struct vfs_aio_state aio_state;
2667 vfs_handle_struct *handle;
2668 files_struct *dir_fsp;
2669 const struct smb_filename *smb_fname;
2670 const char *xattr_name;
2672 uint8_t *xattr_value;
2675 static void smb_full_audit_getxattrat_done(struct tevent_req *subreq);
2677 static struct tevent_req *smb_full_audit_getxattrat_send(
2678 TALLOC_CTX *mem_ctx,
2679 struct tevent_context *ev,
2680 struct vfs_handle_struct *handle,
2681 files_struct *dir_fsp,
2682 const struct smb_filename *smb_fname,
2683 const char *xattr_name,
2686 struct tevent_req *req = NULL;
2687 struct tevent_req *subreq = NULL;
2688 struct smb_full_audit_getxattrat_state *state = NULL;
2690 req = tevent_req_create(mem_ctx, &state,
2691 struct smb_full_audit_getxattrat_state);
2693 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2697 fsp_str_do_log(dir_fsp),
2698 smb_fname->base_name,
2702 *state = (struct smb_full_audit_getxattrat_state) {
2705 .smb_fname = smb_fname,
2706 .xattr_name = xattr_name,
2709 subreq = SMB_VFS_NEXT_GETXATTRAT_SEND(state,
2716 if (tevent_req_nomem(subreq, req)) {
2717 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2721 fsp_str_do_log(dir_fsp),
2722 smb_fname->base_name,
2724 return tevent_req_post(req, ev);
2726 tevent_req_set_callback(subreq, smb_full_audit_getxattrat_done, req);
2728 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2732 fsp_str_do_log(dir_fsp),
2733 smb_fname->base_name,
2739 static void smb_full_audit_getxattrat_done(struct tevent_req *subreq)
2741 struct tevent_req *req = tevent_req_callback_data(
2742 subreq, struct tevent_req);
2743 struct smb_full_audit_getxattrat_state *state = tevent_req_data(
2744 req, struct smb_full_audit_getxattrat_state);
2746 state->xattr_size = SMB_VFS_NEXT_GETXATTRAT_RECV(subreq,
2749 &state->xattr_value);
2750 TALLOC_FREE(subreq);
2751 if (state->xattr_size == -1) {
2752 tevent_req_error(req, state->aio_state.error);
2756 tevent_req_done(req);
2759 static ssize_t smb_full_audit_getxattrat_recv(struct tevent_req *req,
2760 struct vfs_aio_state *aio_state,
2761 TALLOC_CTX *mem_ctx,
2762 uint8_t **xattr_value)
2764 struct smb_full_audit_getxattrat_state *state = tevent_req_data(
2765 req, struct smb_full_audit_getxattrat_state);
2768 if (tevent_req_is_unix_error(req, &aio_state->error)) {
2769 do_log(SMB_VFS_OP_GETXATTRAT_RECV,
2773 fsp_str_do_log(state->dir_fsp),
2774 state->smb_fname->base_name,
2776 tevent_req_received(req);
2780 do_log(SMB_VFS_OP_GETXATTRAT_RECV,
2784 fsp_str_do_log(state->dir_fsp),
2785 state->smb_fname->base_name,
2788 *aio_state = state->aio_state;
2789 xattr_size = state->xattr_size;
2790 if (xattr_value != NULL) {
2791 *xattr_value = talloc_move(mem_ctx, &state->xattr_value);
2794 tevent_req_received(req);
2798 static ssize_t smb_full_audit_fgetxattr(struct vfs_handle_struct *handle,
2799 struct files_struct *fsp,
2800 const char *name, void *value, size_t size)
2804 result = SMB_VFS_NEXT_FGETXATTR(handle, fsp, name, value, size);
2806 do_log(SMB_VFS_OP_FGETXATTR, (result >= 0), handle,
2807 "%s|%s", fsp_str_do_log(fsp), name);
2812 static ssize_t smb_full_audit_flistxattr(struct vfs_handle_struct *handle,
2813 struct files_struct *fsp, char *list,
2818 result = SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
2820 do_log(SMB_VFS_OP_FLISTXATTR, (result >= 0), handle,
2821 "%s", fsp_str_do_log(fsp));
2826 static int smb_full_audit_fremovexattr(struct vfs_handle_struct *handle,
2827 struct files_struct *fsp,
2832 result = SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, name);
2834 do_log(SMB_VFS_OP_FREMOVEXATTR, (result >= 0), handle,
2835 "%s|%s", fsp_str_do_log(fsp), name);
2840 static int smb_full_audit_fsetxattr(struct vfs_handle_struct *handle,
2841 struct files_struct *fsp, const char *name,
2842 const void *value, size_t size, int flags)
2846 result = SMB_VFS_NEXT_FSETXATTR(handle, fsp, name, value, size, flags);
2848 do_log(SMB_VFS_OP_FSETXATTR, (result >= 0), handle,
2849 "%s|%s", fsp_str_do_log(fsp), name);
2854 static bool smb_full_audit_aio_force(struct vfs_handle_struct *handle,
2855 struct files_struct *fsp)
2859 result = SMB_VFS_NEXT_AIO_FORCE(handle, fsp);
2860 do_log(SMB_VFS_OP_AIO_FORCE, result, handle,
2861 "%s", fsp_str_do_log(fsp));
2866 static NTSTATUS smb_full_audit_durable_cookie(struct vfs_handle_struct *handle,
2867 struct files_struct *fsp,
2868 TALLOC_CTX *mem_ctx,
2873 result = SMB_VFS_NEXT_DURABLE_COOKIE(handle,
2878 do_log(SMB_VFS_OP_DURABLE_COOKIE, NT_STATUS_IS_OK(result), handle,
2879 "%s", fsp_str_do_log(fsp));
2884 static NTSTATUS smb_full_audit_durable_disconnect(
2885 struct vfs_handle_struct *handle,
2886 struct files_struct *fsp,
2887 const DATA_BLOB old_cookie,
2888 TALLOC_CTX *mem_ctx,
2889 DATA_BLOB *new_cookie)
2893 result = SMB_VFS_NEXT_DURABLE_DISCONNECT(handle,
2899 do_log(SMB_VFS_OP_DURABLE_DISCONNECT, NT_STATUS_IS_OK(result), handle,
2900 "%s", fsp_str_do_log(fsp));
2905 static NTSTATUS smb_full_audit_durable_reconnect(
2906 struct vfs_handle_struct *handle,
2907 struct smb_request *smb1req,
2908 struct smbXsrv_open *op,
2909 const DATA_BLOB old_cookie,
2910 TALLOC_CTX *mem_ctx,
2911 struct files_struct **fsp,
2912 DATA_BLOB *new_cookie)
2916 result = SMB_VFS_NEXT_DURABLE_RECONNECT(handle,
2924 do_log(SMB_VFS_OP_DURABLE_RECONNECT,
2925 NT_STATUS_IS_OK(result),
2932 static struct vfs_fn_pointers vfs_full_audit_fns = {
2934 /* Disk operations */
2936 .connect_fn = smb_full_audit_connect,
2937 .disconnect_fn = smb_full_audit_disconnect,
2938 .disk_free_fn = smb_full_audit_disk_free,
2939 .get_quota_fn = smb_full_audit_get_quota,
2940 .set_quota_fn = smb_full_audit_set_quota,
2941 .get_shadow_copy_data_fn = smb_full_audit_get_shadow_copy_data,
2942 .statvfs_fn = smb_full_audit_statvfs,
2943 .fs_capabilities_fn = smb_full_audit_fs_capabilities,
2944 .get_dfs_referrals_fn = smb_full_audit_get_dfs_referrals,
2945 .create_dfs_pathat_fn = smb_full_audit_create_dfs_pathat,
2946 .read_dfs_pathat_fn = smb_full_audit_read_dfs_pathat,
2947 .fdopendir_fn = smb_full_audit_fdopendir,
2948 .readdir_fn = smb_full_audit_readdir,
2949 .seekdir_fn = smb_full_audit_seekdir,
2950 .telldir_fn = smb_full_audit_telldir,
2951 .rewind_dir_fn = smb_full_audit_rewinddir,
2952 .mkdirat_fn = smb_full_audit_mkdirat,
2953 .closedir_fn = smb_full_audit_closedir,
2954 .openat_fn = smb_full_audit_openat,
2955 .create_file_fn = smb_full_audit_create_file,
2956 .close_fn = smb_full_audit_close,
2957 .pread_fn = smb_full_audit_pread,
2958 .pread_send_fn = smb_full_audit_pread_send,
2959 .pread_recv_fn = smb_full_audit_pread_recv,
2960 .pwrite_fn = smb_full_audit_pwrite,
2961 .pwrite_send_fn = smb_full_audit_pwrite_send,
2962 .pwrite_recv_fn = smb_full_audit_pwrite_recv,
2963 .lseek_fn = smb_full_audit_lseek,
2964 .sendfile_fn = smb_full_audit_sendfile,
2965 .recvfile_fn = smb_full_audit_recvfile,
2966 .renameat_fn = smb_full_audit_renameat,
2967 .fsync_send_fn = smb_full_audit_fsync_send,
2968 .fsync_recv_fn = smb_full_audit_fsync_recv,
2969 .stat_fn = smb_full_audit_stat,
2970 .fstat_fn = smb_full_audit_fstat,
2971 .lstat_fn = smb_full_audit_lstat,
2972 .fstatat_fn = smb_full_audit_fstatat,
2973 .get_alloc_size_fn = smb_full_audit_get_alloc_size,
2974 .unlinkat_fn = smb_full_audit_unlinkat,
2975 .fchmod_fn = smb_full_audit_fchmod,
2976 .fchown_fn = smb_full_audit_fchown,
2977 .lchown_fn = smb_full_audit_lchown,
2978 .chdir_fn = smb_full_audit_chdir,
2979 .getwd_fn = smb_full_audit_getwd,
2980 .fntimes_fn = smb_full_audit_fntimes,
2981 .ftruncate_fn = smb_full_audit_ftruncate,
2982 .fallocate_fn = smb_full_audit_fallocate,
2983 .lock_fn = smb_full_audit_lock,
2984 .filesystem_sharemode_fn = smb_full_audit_filesystem_sharemode,
2985 .fcntl_fn = smb_full_audit_fcntl,
2986 .linux_setlease_fn = smb_full_audit_linux_setlease,
2987 .getlock_fn = smb_full_audit_getlock,
2988 .symlinkat_fn = smb_full_audit_symlinkat,
2989 .readlinkat_fn = smb_full_audit_readlinkat,
2990 .linkat_fn = smb_full_audit_linkat,
2991 .mknodat_fn = smb_full_audit_mknodat,
2992 .realpath_fn = smb_full_audit_realpath,
2993 .fchflags_fn = smb_full_audit_fchflags,
2994 .file_id_create_fn = smb_full_audit_file_id_create,
2995 .fs_file_id_fn = smb_full_audit_fs_file_id,
2996 .offload_read_send_fn = smb_full_audit_offload_read_send,
2997 .offload_read_recv_fn = smb_full_audit_offload_read_recv,
2998 .offload_write_send_fn = smb_full_audit_offload_write_send,
2999 .offload_write_recv_fn = smb_full_audit_offload_write_recv,
3000 .fget_compression_fn = smb_full_audit_fget_compression,
3001 .set_compression_fn = smb_full_audit_set_compression,
3002 .snap_check_path_fn = smb_full_audit_snap_check_path,
3003 .snap_create_fn = smb_full_audit_snap_create,
3004 .snap_delete_fn = smb_full_audit_snap_delete,
3005 .fstreaminfo_fn = smb_full_audit_fstreaminfo,
3006 .get_real_filename_at_fn = smb_full_audit_get_real_filename_at,
3007 .connectpath_fn = smb_full_audit_connectpath,
3008 .brl_lock_windows_fn = smb_full_audit_brl_lock_windows,
3009 .brl_unlock_windows_fn = smb_full_audit_brl_unlock_windows,
3010 .strict_lock_check_fn = smb_full_audit_strict_lock_check,
3011 .translate_name_fn = smb_full_audit_translate_name,
3012 .parent_pathname_fn = smb_full_audit_parent_pathname,
3013 .fsctl_fn = smb_full_audit_fsctl,
3014 .get_dos_attributes_send_fn = smb_full_audit_get_dos_attributes_send,
3015 .get_dos_attributes_recv_fn = smb_full_audit_get_dos_attributes_recv,
3016 .fget_dos_attributes_fn = smb_full_audit_fget_dos_attributes,
3017 .fset_dos_attributes_fn = smb_full_audit_fset_dos_attributes,
3018 .fget_nt_acl_fn = smb_full_audit_fget_nt_acl,
3019 .fset_nt_acl_fn = smb_full_audit_fset_nt_acl,
3020 .audit_file_fn = smb_full_audit_audit_file,
3021 .sys_acl_get_fd_fn = smb_full_audit_sys_acl_get_fd,
3022 .sys_acl_blob_get_fd_fn = smb_full_audit_sys_acl_blob_get_fd,
3023 .sys_acl_set_fd_fn = smb_full_audit_sys_acl_set_fd,
3024 .sys_acl_delete_def_fd_fn = smb_full_audit_sys_acl_delete_def_fd,
3025 .getxattrat_send_fn = smb_full_audit_getxattrat_send,
3026 .getxattrat_recv_fn = smb_full_audit_getxattrat_recv,
3027 .fgetxattr_fn = smb_full_audit_fgetxattr,
3028 .flistxattr_fn = smb_full_audit_flistxattr,
3029 .fremovexattr_fn = smb_full_audit_fremovexattr,
3030 .fsetxattr_fn = smb_full_audit_fsetxattr,
3031 .aio_force_fn = smb_full_audit_aio_force,
3032 .durable_cookie_fn = smb_full_audit_durable_cookie,
3033 .durable_disconnect_fn = smb_full_audit_durable_disconnect,
3034 .durable_reconnect_fn = smb_full_audit_durable_reconnect,
3035 .freaddir_attr_fn = smb_full_audit_freaddir_attr,
3039 NTSTATUS vfs_full_audit_init(TALLOC_CTX *ctx)
3043 smb_vfs_assert_all_fns(&vfs_full_audit_fns, "full_audit");
3045 ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "full_audit",
3046 &vfs_full_audit_fns);
3048 if (!NT_STATUS_IS_OK(ret))
3051 vfs_full_audit_debug_level = debug_add_class("full_audit");
3052 if (vfs_full_audit_debug_level == -1) {
3053 vfs_full_audit_debug_level = DBGC_VFS;
3054 DEBUG(0, ("vfs_full_audit: Couldn't register custom debugging "
3057 DEBUG(10, ("vfs_full_audit: Debug class number of "
3058 "'full_audit': %d\n", vfs_full_audit_debug_level));