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"
76 static int vfs_full_audit_debug_level = DBGC_VFS;
78 struct vfs_full_audit_private_data {
79 struct bitmap *success_ops;
80 struct bitmap *failure_ops;
88 #define DBGC_CLASS vfs_full_audit_debug_level
90 typedef enum _vfs_op_type {
95 SMB_VFS_OP_CONNECT = 0,
96 SMB_VFS_OP_DISCONNECT,
100 SMB_VFS_OP_GET_SHADOW_COPY_DATA,
102 SMB_VFS_OP_FS_CAPABILITIES,
103 SMB_VFS_OP_GET_DFS_REFERRALS,
105 /* Directory operations */
108 SMB_VFS_OP_FDOPENDIR,
112 SMB_VFS_OP_REWINDDIR,
116 /* File operations */
119 SMB_VFS_OP_CREATE_FILE,
123 SMB_VFS_OP_PREAD_SEND,
124 SMB_VFS_OP_PREAD_RECV,
127 SMB_VFS_OP_PWRITE_SEND,
128 SMB_VFS_OP_PWRITE_RECV,
134 SMB_VFS_OP_FSYNC_SEND,
135 SMB_VFS_OP_FSYNC_RECV,
139 SMB_VFS_OP_GET_ALLOC_SIZE,
148 SMB_VFS_OP_FTRUNCATE,
149 SMB_VFS_OP_FALLOCATE,
151 SMB_VFS_OP_KERNEL_FLOCK,
153 SMB_VFS_OP_LINUX_SETLEASE,
155 SMB_VFS_OP_SYMLINKAT,
156 SMB_VFS_OP_READLINKAT,
161 SMB_VFS_OP_FILE_ID_CREATE,
162 SMB_VFS_OP_FS_FILE_ID,
163 SMB_VFS_OP_STREAMINFO,
164 SMB_VFS_OP_GET_REAL_FILENAME,
165 SMB_VFS_OP_CONNECTPATH,
166 SMB_VFS_OP_BRL_LOCK_WINDOWS,
167 SMB_VFS_OP_BRL_UNLOCK_WINDOWS,
168 SMB_VFS_OP_STRICT_LOCK_CHECK,
169 SMB_VFS_OP_TRANSLATE_NAME,
171 SMB_VFS_OP_OFFLOAD_READ_SEND,
172 SMB_VFS_OP_OFFLOAD_READ_RECV,
173 SMB_VFS_OP_OFFLOAD_WRITE_SEND,
174 SMB_VFS_OP_OFFLOAD_WRITE_RECV,
175 SMB_VFS_OP_GET_COMPRESSION,
176 SMB_VFS_OP_SET_COMPRESSION,
177 SMB_VFS_OP_SNAP_CHECK_PATH,
178 SMB_VFS_OP_SNAP_CREATE,
179 SMB_VFS_OP_SNAP_DELETE,
181 /* DOS attribute operations. */
182 SMB_VFS_OP_GET_DOS_ATTRIBUTES,
183 SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
184 SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV,
185 SMB_VFS_OP_FGET_DOS_ATTRIBUTES,
186 SMB_VFS_OP_SET_DOS_ATTRIBUTES,
187 SMB_VFS_OP_FSET_DOS_ATTRIBUTES,
189 /* NT ACL operations. */
191 SMB_VFS_OP_FGET_NT_ACL,
192 SMB_VFS_OP_GET_NT_ACL,
193 SMB_VFS_OP_FSET_NT_ACL,
194 SMB_VFS_OP_AUDIT_FILE,
196 /* POSIX ACL operations. */
198 SMB_VFS_OP_SYS_ACL_GET_FILE,
199 SMB_VFS_OP_SYS_ACL_GET_FD,
200 SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE,
201 SMB_VFS_OP_SYS_ACL_BLOB_GET_FD,
202 SMB_VFS_OP_SYS_ACL_SET_FILE,
203 SMB_VFS_OP_SYS_ACL_SET_FD,
204 SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE,
208 SMB_VFS_OP_GETXATTRAT_SEND,
209 SMB_VFS_OP_GETXATTRAT_RECV,
210 SMB_VFS_OP_FGETXATTR,
211 SMB_VFS_OP_LISTXATTR,
212 SMB_VFS_OP_FLISTXATTR,
213 SMB_VFS_OP_REMOVEXATTR,
214 SMB_VFS_OP_FREMOVEXATTR,
216 SMB_VFS_OP_FSETXATTR,
219 SMB_VFS_OP_AIO_FORCE,
221 /* offline operations */
222 SMB_VFS_OP_IS_OFFLINE,
223 SMB_VFS_OP_SET_OFFLINE,
225 /* Durable handle operations. */
226 SMB_VFS_OP_DURABLE_COOKIE,
227 SMB_VFS_OP_DURABLE_DISCONNECT,
228 SMB_VFS_OP_DURABLE_RECONNECT,
230 SMB_VFS_OP_READDIR_ATTR,
232 /* This should always be last enum value */
237 /* The following array *must* be in the same order as defined in vfs_op_type */
243 { SMB_VFS_OP_CONNECT, "connect" },
244 { SMB_VFS_OP_DISCONNECT, "disconnect" },
245 { SMB_VFS_OP_DISK_FREE, "disk_free" },
246 { SMB_VFS_OP_GET_QUOTA, "get_quota" },
247 { SMB_VFS_OP_SET_QUOTA, "set_quota" },
248 { SMB_VFS_OP_GET_SHADOW_COPY_DATA, "get_shadow_copy_data" },
249 { SMB_VFS_OP_STATVFS, "statvfs" },
250 { SMB_VFS_OP_FS_CAPABILITIES, "fs_capabilities" },
251 { SMB_VFS_OP_GET_DFS_REFERRALS, "get_dfs_referrals" },
252 { SMB_VFS_OP_OPENDIR, "opendir" },
253 { SMB_VFS_OP_FDOPENDIR, "fdopendir" },
254 { SMB_VFS_OP_READDIR, "readdir" },
255 { SMB_VFS_OP_SEEKDIR, "seekdir" },
256 { SMB_VFS_OP_TELLDIR, "telldir" },
257 { SMB_VFS_OP_REWINDDIR, "rewinddir" },
258 { SMB_VFS_OP_MKDIRAT, "mkdirat" },
259 { SMB_VFS_OP_CLOSEDIR, "closedir" },
260 { SMB_VFS_OP_OPEN, "open" },
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_GET_ALLOC_SIZE, "get_alloc_size" },
282 { SMB_VFS_OP_UNLINKAT, "unlinkat" },
283 { SMB_VFS_OP_CHMOD, "chmod" },
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_FTRUNCATE, "ftruncate" },
291 { SMB_VFS_OP_FALLOCATE,"fallocate" },
292 { SMB_VFS_OP_LOCK, "lock" },
293 { SMB_VFS_OP_KERNEL_FLOCK, "kernel_flock" },
294 { SMB_VFS_OP_LINUX_SETLEASE, "linux_setlease" },
295 { SMB_VFS_OP_GETLOCK, "getlock" },
296 { SMB_VFS_OP_SYMLINKAT, "symlinkat" },
297 { SMB_VFS_OP_READLINKAT,"readlinkat" },
298 { SMB_VFS_OP_LINKAT, "linkat" },
299 { SMB_VFS_OP_MKNODAT, "mknodat" },
300 { SMB_VFS_OP_REALPATH, "realpath" },
301 { SMB_VFS_OP_CHFLAGS, "chflags" },
302 { SMB_VFS_OP_FILE_ID_CREATE, "file_id_create" },
303 { SMB_VFS_OP_FS_FILE_ID, "fs_file_id" },
304 { SMB_VFS_OP_STREAMINFO, "streaminfo" },
305 { SMB_VFS_OP_GET_REAL_FILENAME, "get_real_filename" },
306 { SMB_VFS_OP_CONNECTPATH, "connectpath" },
307 { SMB_VFS_OP_BRL_LOCK_WINDOWS, "brl_lock_windows" },
308 { SMB_VFS_OP_BRL_UNLOCK_WINDOWS, "brl_unlock_windows" },
309 { SMB_VFS_OP_STRICT_LOCK_CHECK, "strict_lock_check" },
310 { SMB_VFS_OP_TRANSLATE_NAME, "translate_name" },
311 { SMB_VFS_OP_FSCTL, "fsctl" },
312 { SMB_VFS_OP_OFFLOAD_READ_SEND, "offload_read_send" },
313 { SMB_VFS_OP_OFFLOAD_READ_RECV, "offload_read_recv" },
314 { SMB_VFS_OP_OFFLOAD_WRITE_SEND, "offload_write_send" },
315 { SMB_VFS_OP_OFFLOAD_WRITE_RECV, "offload_write_recv" },
316 { SMB_VFS_OP_GET_COMPRESSION, "get_compression" },
317 { SMB_VFS_OP_SET_COMPRESSION, "set_compression" },
318 { SMB_VFS_OP_SNAP_CHECK_PATH, "snap_check_path" },
319 { SMB_VFS_OP_SNAP_CREATE, "snap_create" },
320 { SMB_VFS_OP_SNAP_DELETE, "snap_delete" },
321 { SMB_VFS_OP_GET_DOS_ATTRIBUTES, "get_dos_attributes" },
322 { SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND, "get_dos_attributes_send" },
323 { SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV, "get_dos_attributes_recv" },
324 { SMB_VFS_OP_FGET_DOS_ATTRIBUTES, "fget_dos_attributes" },
325 { SMB_VFS_OP_SET_DOS_ATTRIBUTES, "set_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_GET_NT_ACL, "get_nt_acl" },
329 { SMB_VFS_OP_FSET_NT_ACL, "fset_nt_acl" },
330 { SMB_VFS_OP_AUDIT_FILE, "audit_file" },
331 { SMB_VFS_OP_SYS_ACL_GET_FILE, "sys_acl_get_file" },
332 { SMB_VFS_OP_SYS_ACL_GET_FD, "sys_acl_get_fd" },
333 { SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE, "sys_acl_blob_get_file" },
334 { SMB_VFS_OP_SYS_ACL_BLOB_GET_FD, "sys_acl_blob_get_fd" },
335 { SMB_VFS_OP_SYS_ACL_SET_FILE, "sys_acl_set_file" },
336 { SMB_VFS_OP_SYS_ACL_SET_FD, "sys_acl_set_fd" },
337 { SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE, "sys_acl_delete_def_file" },
338 { SMB_VFS_OP_GETXATTR, "getxattr" },
339 { SMB_VFS_OP_GETXATTRAT_SEND, "getxattrat_send" },
340 { SMB_VFS_OP_GETXATTRAT_RECV, "getxattrat_recv" },
341 { SMB_VFS_OP_FGETXATTR, "fgetxattr" },
342 { SMB_VFS_OP_LISTXATTR, "listxattr" },
343 { SMB_VFS_OP_FLISTXATTR, "flistxattr" },
344 { SMB_VFS_OP_REMOVEXATTR, "removexattr" },
345 { SMB_VFS_OP_FREMOVEXATTR, "fremovexattr" },
346 { SMB_VFS_OP_SETXATTR, "setxattr" },
347 { SMB_VFS_OP_FSETXATTR, "fsetxattr" },
348 { SMB_VFS_OP_AIO_FORCE, "aio_force" },
349 { SMB_VFS_OP_IS_OFFLINE, "is_offline" },
350 { SMB_VFS_OP_SET_OFFLINE, "set_offline" },
351 { SMB_VFS_OP_DURABLE_COOKIE, "durable_cookie" },
352 { SMB_VFS_OP_DURABLE_DISCONNECT, "durable_disconnect" },
353 { SMB_VFS_OP_DURABLE_RECONNECT, "durable_reconnect" },
354 { SMB_VFS_OP_READDIR_ATTR, "readdir_attr" },
355 { SMB_VFS_OP_LAST, NULL }
358 static int audit_syslog_facility(vfs_handle_struct *handle)
360 static const struct enum_list enum_log_facilities[] = {
362 { LOG_AUTH, "AUTH" },
365 { LOG_AUTHPRIV, "AUTHPRIV" },
368 { LOG_AUDIT, "AUDIT" },
371 { LOG_CONSOLE, "CONSOLE" },
374 { LOG_CRON, "CRON" },
377 { LOG_DAEMON, "DAEMON" },
383 { LOG_INSTALL, "INSTALL" },
386 { LOG_KERN, "KERN" },
389 { LOG_LAUNCHD, "LAUNCHD" },
392 { LOG_LFMT, "LFMT" },
398 { LOG_MAIL, "MAIL" },
401 { LOG_MEGASAFE, "MEGASAFE" },
404 { LOG_NETINFO, "NETINFO" },
407 { LOG_NEWS, "NEWS" },
409 #ifdef LOG_NFACILITIES
410 { LOG_NFACILITIES, "NFACILITIES" },
418 #ifdef LOG_REMOTEAUTH
419 { LOG_REMOTEAUTH, "REMOTEAUTH" },
422 { LOG_SECURITY, "SECURITY" },
425 { LOG_SYSLOG, "SYSLOG" },
428 { LOG_USER, "USER" },
431 { LOG_UUCP, "UUCP" },
433 { LOG_LOCAL0, "LOCAL0" },
434 { LOG_LOCAL1, "LOCAL1" },
435 { LOG_LOCAL2, "LOCAL2" },
436 { LOG_LOCAL3, "LOCAL3" },
437 { LOG_LOCAL4, "LOCAL4" },
438 { LOG_LOCAL5, "LOCAL5" },
439 { LOG_LOCAL6, "LOCAL6" },
440 { LOG_LOCAL7, "LOCAL7" },
446 facility = lp_parm_enum(SNUM(handle->conn), "full_audit", "facility", enum_log_facilities, LOG_USER);
451 static int audit_syslog_priority(vfs_handle_struct *handle)
453 static const struct enum_list enum_log_priorities[] = {
454 { LOG_EMERG, "EMERG" },
455 { LOG_ALERT, "ALERT" },
456 { LOG_CRIT, "CRIT" },
458 { LOG_WARNING, "WARNING" },
459 { LOG_NOTICE, "NOTICE" },
460 { LOG_INFO, "INFO" },
461 { LOG_DEBUG, "DEBUG" },
467 priority = lp_parm_enum(SNUM(handle->conn), "full_audit", "priority",
468 enum_log_priorities, LOG_NOTICE);
469 if (priority == -1) {
470 priority = LOG_WARNING;
476 static char *audit_prefix(TALLOC_CTX *ctx, connection_struct *conn)
478 const struct loadparm_substitution *lp_sub =
479 loadparm_s3_global_substitution();
483 prefix = talloc_strdup(ctx,
484 lp_parm_const_string(SNUM(conn), "full_audit",
489 result = talloc_sub_full(ctx,
490 lp_servicename(talloc_tos(), lp_sub, SNUM(conn)),
491 conn->session_info->unix_info->unix_name,
493 conn->session_info->unix_token->gid,
494 conn->session_info->unix_info->sanitized_username,
495 conn->session_info->info->domain_name,
501 static bool log_success(struct vfs_full_audit_private_data *pd, vfs_op_type op)
503 if (pd->success_ops == NULL) {
507 return bitmap_query(pd->success_ops, op);
510 static bool log_failure(struct vfs_full_audit_private_data *pd, vfs_op_type op)
512 if (pd->failure_ops == NULL)
515 return bitmap_query(pd->failure_ops, op);
518 static struct bitmap *init_bitmap(TALLOC_CTX *mem_ctx, const char **ops)
526 bm = bitmap_talloc(mem_ctx, SMB_VFS_OP_LAST);
528 DEBUG(0, ("Could not alloc bitmap -- "
529 "defaulting to logging everything\n"));
533 for (; *ops != NULL; ops += 1) {
538 if (strequal(*ops, "all")) {
539 for (i=0; i<SMB_VFS_OP_LAST; i++) {
545 if (strequal(*ops, "none")) {
555 for (i=0; i<SMB_VFS_OP_LAST; i++) {
556 if ((vfs_op_names[i].name == NULL)
557 || (vfs_op_names[i].type != i)) {
558 smb_panic("vfs_full_audit.c: name table not "
559 "in sync with vfs_op_type enums\n");
561 if (strequal(op, vfs_op_names[i].name)) {
570 if (i == SMB_VFS_OP_LAST) {
571 DEBUG(0, ("Could not find opname %s, logging all\n",
580 static const char *audit_opname(vfs_op_type op)
582 if (op >= SMB_VFS_OP_LAST)
583 return "INVALID VFS OP";
584 return vfs_op_names[op].name;
587 static TALLOC_CTX *tmp_do_log_ctx;
589 * Get us a temporary talloc context usable just for DEBUG arguments
591 static TALLOC_CTX *do_log_ctx(void)
593 if (tmp_do_log_ctx == NULL) {
594 tmp_do_log_ctx = talloc_named_const(NULL, 0, "do_log_ctx");
596 return tmp_do_log_ctx;
599 static void do_log(vfs_op_type op, bool success, vfs_handle_struct *handle,
600 const char *format, ...) PRINTF_ATTRIBUTE(4, 5);
602 static void do_log(vfs_op_type op, bool success, vfs_handle_struct *handle,
603 const char *format, ...)
605 struct vfs_full_audit_private_data *pd;
607 char *audit_pre = NULL;
611 SMB_VFS_HANDLE_GET_DATA(handle, pd,
612 struct vfs_full_audit_private_data,
615 if (success && (!log_success(pd, op)))
618 if (!success && (!log_failure(pd, op)))
622 fstrcpy(err_msg, "ok");
624 fstr_sprintf(err_msg, "fail (%s)", strerror(errno));
626 va_start(ap, format);
627 op_msg = talloc_vasprintf(talloc_tos(), format, ap);
634 audit_pre = audit_prefix(talloc_tos(), handle->conn);
640 * Specify the facility to interoperate with other syslog
641 * callers (smbd for example).
643 priority = pd->syslog_priority | pd->syslog_facility;
645 syslog(priority, "%s|%s|%s|%s\n",
646 audit_pre ? audit_pre : "",
647 audit_opname(op), err_msg, op_msg);
649 DEBUG(1, ("%s|%s|%s|%s\n",
650 audit_pre ? audit_pre : "",
651 audit_opname(op), err_msg, op_msg));
654 TALLOC_FREE(audit_pre);
656 TALLOC_FREE(tmp_do_log_ctx);
660 * Return a string using the do_log_ctx()
662 static const char *smb_fname_str_do_log(struct connection_struct *conn,
663 const struct smb_filename *smb_fname)
668 if (smb_fname == NULL) {
672 if (smb_fname->base_name[0] != '/') {
673 char *abs_name = NULL;
674 struct smb_filename *fname_copy = cp_smb_filename(
677 if (fname_copy == NULL) {
681 if (!ISDOT(smb_fname->base_name)) {
682 abs_name = talloc_asprintf(do_log_ctx(),
684 conn->cwd_fsp->fsp_name->base_name,
685 smb_fname->base_name);
687 abs_name = talloc_strdup(do_log_ctx(),
688 conn->cwd_fsp->fsp_name->base_name);
690 if (abs_name == NULL) {
693 fname_copy->base_name = abs_name;
694 smb_fname = fname_copy;
697 status = get_full_smb_filename(do_log_ctx(), smb_fname, &fname);
698 if (!NT_STATUS_IS_OK(status)) {
705 * Return an fsp debug string using the do_log_ctx()
707 static const char *fsp_str_do_log(const struct files_struct *fsp)
709 return smb_fname_str_do_log(fsp->conn, fsp->fsp_name);
712 /* Implementation of vfs_ops. Pass everything on to the default
713 operation but log event first. */
715 static int smb_full_audit_connect(vfs_handle_struct *handle,
716 const char *svc, const char *user)
719 const char *none[] = { "none" };
720 struct vfs_full_audit_private_data *pd = NULL;
722 result = SMB_VFS_NEXT_CONNECT(handle, svc, user);
727 pd = talloc_zero(handle, struct vfs_full_audit_private_data);
729 SMB_VFS_NEXT_DISCONNECT(handle);
733 pd->syslog_facility = audit_syslog_facility(handle);
734 if (pd->syslog_facility == -1) {
735 DEBUG(1, ("%s: Unknown facility %s\n", __func__,
736 lp_parm_const_string(SNUM(handle->conn),
737 "full_audit", "facility",
739 SMB_VFS_NEXT_DISCONNECT(handle);
743 pd->syslog_priority = audit_syslog_priority(handle);
745 pd->log_secdesc = lp_parm_bool(SNUM(handle->conn),
746 "full_audit", "log_secdesc", false);
748 pd->do_syslog = lp_parm_bool(SNUM(handle->conn),
749 "full_audit", "syslog", true);
753 openlog("smbd_audit", 0, pd->syslog_facility);
757 pd->success_ops = init_bitmap(
758 pd, lp_parm_string_list(SNUM(handle->conn), "full_audit",
760 pd->failure_ops = init_bitmap(
761 pd, lp_parm_string_list(SNUM(handle->conn), "full_audit",
764 /* Store the private data. */
765 SMB_VFS_HANDLE_SET_DATA(handle, pd, NULL,
766 struct vfs_full_audit_private_data, return -1);
768 do_log(SMB_VFS_OP_CONNECT, True, handle,
774 static void smb_full_audit_disconnect(vfs_handle_struct *handle)
776 const struct loadparm_substitution *lp_sub =
777 loadparm_s3_global_substitution();
779 SMB_VFS_NEXT_DISCONNECT(handle);
781 do_log(SMB_VFS_OP_DISCONNECT, True, handle,
782 "%s", lp_servicename(talloc_tos(), lp_sub, SNUM(handle->conn)));
784 /* The bitmaps will be disconnected when the private
788 static uint64_t smb_full_audit_disk_free(vfs_handle_struct *handle,
789 const struct smb_filename *smb_fname,
796 result = SMB_VFS_NEXT_DISK_FREE(handle, smb_fname, bsize, dfree, dsize);
798 /* Don't have a reasonable notion of failure here */
800 do_log(SMB_VFS_OP_DISK_FREE,
804 smb_fname_str_do_log(handle->conn, smb_fname));
809 static int smb_full_audit_get_quota(struct vfs_handle_struct *handle,
810 const struct smb_filename *smb_fname,
811 enum SMB_QUOTA_TYPE qtype,
817 result = SMB_VFS_NEXT_GET_QUOTA(handle, smb_fname, qtype, id, qt);
819 do_log(SMB_VFS_OP_GET_QUOTA,
823 smb_fname_str_do_log(handle->conn, smb_fname));
828 static int smb_full_audit_set_quota(struct vfs_handle_struct *handle,
829 enum SMB_QUOTA_TYPE qtype, unid_t id,
834 result = SMB_VFS_NEXT_SET_QUOTA(handle, qtype, id, qt);
836 do_log(SMB_VFS_OP_SET_QUOTA, (result >= 0), handle, "");
841 static int smb_full_audit_get_shadow_copy_data(struct vfs_handle_struct *handle,
842 struct files_struct *fsp,
843 struct shadow_copy_data *shadow_copy_data,
848 result = SMB_VFS_NEXT_GET_SHADOW_COPY_DATA(handle, fsp, shadow_copy_data, labels);
850 do_log(SMB_VFS_OP_GET_SHADOW_COPY_DATA, (result >= 0), handle, "");
855 static int smb_full_audit_statvfs(struct vfs_handle_struct *handle,
856 const struct smb_filename *smb_fname,
857 struct vfs_statvfs_struct *statbuf)
861 result = SMB_VFS_NEXT_STATVFS(handle, smb_fname, statbuf);
863 do_log(SMB_VFS_OP_STATVFS, (result >= 0), handle, "");
868 static uint32_t smb_full_audit_fs_capabilities(struct vfs_handle_struct *handle, enum timestamp_set_resolution *p_ts_res)
872 result = SMB_VFS_NEXT_FS_CAPABILITIES(handle, p_ts_res);
874 do_log(SMB_VFS_OP_FS_CAPABILITIES, true, handle, "");
879 static NTSTATUS smb_full_audit_get_dfs_referrals(
880 struct vfs_handle_struct *handle,
881 struct dfs_GetDFSReferral *r)
885 status = SMB_VFS_NEXT_GET_DFS_REFERRALS(handle, r);
887 do_log(SMB_VFS_OP_GET_DFS_REFERRALS, NT_STATUS_IS_OK(status),
893 static NTSTATUS smb_full_audit_snap_check_path(struct vfs_handle_struct *handle,
895 const char *service_path,
900 status = SMB_VFS_NEXT_SNAP_CHECK_PATH(handle, mem_ctx, service_path,
902 do_log(SMB_VFS_OP_SNAP_CHECK_PATH, NT_STATUS_IS_OK(status),
908 static NTSTATUS smb_full_audit_snap_create(struct vfs_handle_struct *handle,
910 const char *base_volume,
918 status = SMB_VFS_NEXT_SNAP_CREATE(handle, mem_ctx, base_volume, tstamp,
919 rw, base_path, snap_path);
920 do_log(SMB_VFS_OP_SNAP_CREATE, NT_STATUS_IS_OK(status), handle, "");
925 static NTSTATUS smb_full_audit_snap_delete(struct vfs_handle_struct *handle,
932 status = SMB_VFS_NEXT_SNAP_DELETE(handle, mem_ctx, base_path,
934 do_log(SMB_VFS_OP_SNAP_DELETE, NT_STATUS_IS_OK(status), handle, "");
939 static DIR *smb_full_audit_opendir(vfs_handle_struct *handle,
940 const struct smb_filename *smb_fname,
946 result = SMB_VFS_NEXT_OPENDIR(handle, smb_fname, mask, attr);
948 do_log(SMB_VFS_OP_OPENDIR,
952 smb_fname_str_do_log(handle->conn, smb_fname));
957 static DIR *smb_full_audit_fdopendir(vfs_handle_struct *handle,
958 files_struct *fsp, const char *mask, uint32_t attr)
962 result = SMB_VFS_NEXT_FDOPENDIR(handle, fsp, mask, attr);
964 do_log(SMB_VFS_OP_FDOPENDIR, (result != NULL), handle, "%s",
965 fsp_str_do_log(fsp));
970 static struct dirent *smb_full_audit_readdir(vfs_handle_struct *handle,
971 DIR *dirp, SMB_STRUCT_STAT *sbuf)
973 struct dirent *result;
975 result = SMB_VFS_NEXT_READDIR(handle, dirp, sbuf);
977 /* This operation has no reasonable error condition
978 * (End of dir is also failure), so always succeed.
980 do_log(SMB_VFS_OP_READDIR, True, handle, "");
985 static void smb_full_audit_seekdir(vfs_handle_struct *handle,
986 DIR *dirp, long offset)
988 SMB_VFS_NEXT_SEEKDIR(handle, dirp, offset);
990 do_log(SMB_VFS_OP_SEEKDIR, True, handle, "");
993 static long smb_full_audit_telldir(vfs_handle_struct *handle,
998 result = SMB_VFS_NEXT_TELLDIR(handle, dirp);
1000 do_log(SMB_VFS_OP_TELLDIR, True, handle, "");
1005 static void smb_full_audit_rewinddir(vfs_handle_struct *handle,
1008 SMB_VFS_NEXT_REWINDDIR(handle, dirp);
1010 do_log(SMB_VFS_OP_REWINDDIR, True, handle, "");
1013 static int smb_full_audit_mkdirat(vfs_handle_struct *handle,
1014 struct files_struct *dirfsp,
1015 const struct smb_filename *smb_fname,
1020 result = SMB_VFS_NEXT_MKDIRAT(handle,
1025 do_log(SMB_VFS_OP_MKDIRAT,
1029 smb_fname_str_do_log(handle->conn, smb_fname));
1034 static int smb_full_audit_closedir(vfs_handle_struct *handle,
1039 result = SMB_VFS_NEXT_CLOSEDIR(handle, dirp);
1041 do_log(SMB_VFS_OP_CLOSEDIR, (result >= 0), handle, "");
1046 static int smb_full_audit_open(vfs_handle_struct *handle,
1047 struct smb_filename *smb_fname,
1048 files_struct *fsp, int flags, mode_t mode)
1052 result = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
1054 do_log(SMB_VFS_OP_OPEN, (result >= 0), handle, "%s|%s",
1055 ((flags & O_WRONLY) || (flags & O_RDWR))?"w":"r",
1056 smb_fname_str_do_log(handle->conn, smb_fname));
1061 static NTSTATUS smb_full_audit_create_file(vfs_handle_struct *handle,
1062 struct smb_request *req,
1063 uint16_t root_dir_fid,
1064 struct smb_filename *smb_fname,
1065 uint32_t access_mask,
1066 uint32_t share_access,
1067 uint32_t create_disposition,
1068 uint32_t create_options,
1069 uint32_t file_attributes,
1070 uint32_t oplock_request,
1071 const struct smb2_lease *lease,
1072 uint64_t allocation_size,
1073 uint32_t private_flags,
1074 struct security_descriptor *sd,
1075 struct ea_list *ea_list,
1076 files_struct **result_fsp,
1078 const struct smb2_create_blobs *in_context_blobs,
1079 struct smb2_create_blobs *out_context_blobs)
1082 const char* str_create_disposition;
1084 switch (create_disposition) {
1085 case FILE_SUPERSEDE:
1086 str_create_disposition = "supersede";
1088 case FILE_OVERWRITE_IF:
1089 str_create_disposition = "overwrite_if";
1092 str_create_disposition = "open";
1094 case FILE_OVERWRITE:
1095 str_create_disposition = "overwrite";
1098 str_create_disposition = "create";
1101 str_create_disposition = "open_if";
1104 str_create_disposition = "unknown";
1107 result = SMB_VFS_NEXT_CREATE_FILE(
1108 handle, /* handle */
1110 root_dir_fid, /* root_dir_fid */
1111 smb_fname, /* fname */
1112 access_mask, /* access_mask */
1113 share_access, /* share_access */
1114 create_disposition, /* create_disposition*/
1115 create_options, /* create_options */
1116 file_attributes, /* file_attributes */
1117 oplock_request, /* oplock_request */
1119 allocation_size, /* allocation_size */
1122 ea_list, /* ea_list */
1123 result_fsp, /* result */
1125 in_context_blobs, out_context_blobs); /* create context */
1127 do_log(SMB_VFS_OP_CREATE_FILE, (NT_STATUS_IS_OK(result)), handle,
1128 "0x%x|%s|%s|%s", access_mask,
1129 create_options & FILE_DIRECTORY_FILE ? "dir" : "file",
1130 str_create_disposition,
1131 smb_fname_str_do_log(handle->conn, smb_fname));
1136 static int smb_full_audit_close(vfs_handle_struct *handle, files_struct *fsp)
1140 result = SMB_VFS_NEXT_CLOSE(handle, fsp);
1142 do_log(SMB_VFS_OP_CLOSE, (result >= 0), handle, "%s",
1143 fsp_str_do_log(fsp));
1148 static ssize_t smb_full_audit_pread(vfs_handle_struct *handle, files_struct *fsp,
1149 void *data, size_t n, off_t offset)
1153 result = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
1155 do_log(SMB_VFS_OP_PREAD, (result >= 0), handle, "%s",
1156 fsp_str_do_log(fsp));
1161 struct smb_full_audit_pread_state {
1162 vfs_handle_struct *handle;
1165 struct vfs_aio_state vfs_aio_state;
1168 static void smb_full_audit_pread_done(struct tevent_req *subreq);
1170 static struct tevent_req *smb_full_audit_pread_send(
1171 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1172 struct tevent_context *ev, struct files_struct *fsp,
1173 void *data, size_t n, off_t offset)
1175 struct tevent_req *req, *subreq;
1176 struct smb_full_audit_pread_state *state;
1178 req = tevent_req_create(mem_ctx, &state,
1179 struct smb_full_audit_pread_state);
1181 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
1182 fsp_str_do_log(fsp));
1185 state->handle = handle;
1188 subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
1190 if (tevent_req_nomem(subreq, req)) {
1191 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
1192 fsp_str_do_log(fsp));
1193 return tevent_req_post(req, ev);
1195 tevent_req_set_callback(subreq, smb_full_audit_pread_done, req);
1197 do_log(SMB_VFS_OP_PREAD_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1201 static void smb_full_audit_pread_done(struct tevent_req *subreq)
1203 struct tevent_req *req = tevent_req_callback_data(
1204 subreq, struct tevent_req);
1205 struct smb_full_audit_pread_state *state = tevent_req_data(
1206 req, struct smb_full_audit_pread_state);
1208 state->ret = SMB_VFS_PREAD_RECV(subreq, &state->vfs_aio_state);
1209 TALLOC_FREE(subreq);
1210 tevent_req_done(req);
1213 static ssize_t smb_full_audit_pread_recv(struct tevent_req *req,
1214 struct vfs_aio_state *vfs_aio_state)
1216 struct smb_full_audit_pread_state *state = tevent_req_data(
1217 req, struct smb_full_audit_pread_state);
1219 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1220 do_log(SMB_VFS_OP_PREAD_RECV, false, state->handle, "%s",
1221 fsp_str_do_log(state->fsp));
1225 do_log(SMB_VFS_OP_PREAD_RECV, (state->ret >= 0), state->handle, "%s",
1226 fsp_str_do_log(state->fsp));
1228 *vfs_aio_state = state->vfs_aio_state;
1232 static ssize_t smb_full_audit_pwrite(vfs_handle_struct *handle, files_struct *fsp,
1233 const void *data, size_t n,
1238 result = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
1240 do_log(SMB_VFS_OP_PWRITE, (result >= 0), handle, "%s",
1241 fsp_str_do_log(fsp));
1246 struct smb_full_audit_pwrite_state {
1247 vfs_handle_struct *handle;
1250 struct vfs_aio_state vfs_aio_state;
1253 static void smb_full_audit_pwrite_done(struct tevent_req *subreq);
1255 static struct tevent_req *smb_full_audit_pwrite_send(
1256 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1257 struct tevent_context *ev, struct files_struct *fsp,
1258 const void *data, size_t n, off_t offset)
1260 struct tevent_req *req, *subreq;
1261 struct smb_full_audit_pwrite_state *state;
1263 req = tevent_req_create(mem_ctx, &state,
1264 struct smb_full_audit_pwrite_state);
1266 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1267 fsp_str_do_log(fsp));
1270 state->handle = handle;
1273 subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
1275 if (tevent_req_nomem(subreq, req)) {
1276 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1277 fsp_str_do_log(fsp));
1278 return tevent_req_post(req, ev);
1280 tevent_req_set_callback(subreq, smb_full_audit_pwrite_done, req);
1282 do_log(SMB_VFS_OP_PWRITE_SEND, true, handle, "%s",
1283 fsp_str_do_log(fsp));
1287 static void smb_full_audit_pwrite_done(struct tevent_req *subreq)
1289 struct tevent_req *req = tevent_req_callback_data(
1290 subreq, struct tevent_req);
1291 struct smb_full_audit_pwrite_state *state = tevent_req_data(
1292 req, struct smb_full_audit_pwrite_state);
1294 state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->vfs_aio_state);
1295 TALLOC_FREE(subreq);
1296 tevent_req_done(req);
1299 static ssize_t smb_full_audit_pwrite_recv(struct tevent_req *req,
1300 struct vfs_aio_state *vfs_aio_state)
1302 struct smb_full_audit_pwrite_state *state = tevent_req_data(
1303 req, struct smb_full_audit_pwrite_state);
1305 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1306 do_log(SMB_VFS_OP_PWRITE_RECV, false, state->handle, "%s",
1307 fsp_str_do_log(state->fsp));
1311 do_log(SMB_VFS_OP_PWRITE_RECV, (state->ret >= 0), state->handle, "%s",
1312 fsp_str_do_log(state->fsp));
1314 *vfs_aio_state = state->vfs_aio_state;
1318 static off_t smb_full_audit_lseek(vfs_handle_struct *handle, files_struct *fsp,
1319 off_t offset, int whence)
1323 result = SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence);
1325 do_log(SMB_VFS_OP_LSEEK, (result != (ssize_t)-1), handle,
1326 "%s", fsp_str_do_log(fsp));
1331 static ssize_t smb_full_audit_sendfile(vfs_handle_struct *handle, int tofd,
1332 files_struct *fromfsp,
1333 const DATA_BLOB *hdr, off_t offset,
1338 result = SMB_VFS_NEXT_SENDFILE(handle, tofd, fromfsp, hdr, offset, n);
1340 do_log(SMB_VFS_OP_SENDFILE, (result >= 0), handle,
1341 "%s", fsp_str_do_log(fromfsp));
1346 static ssize_t smb_full_audit_recvfile(vfs_handle_struct *handle, int fromfd,
1347 files_struct *tofsp,
1353 result = SMB_VFS_NEXT_RECVFILE(handle, fromfd, tofsp, offset, n);
1355 do_log(SMB_VFS_OP_RECVFILE, (result >= 0), handle,
1356 "%s", fsp_str_do_log(tofsp));
1361 static int smb_full_audit_renameat(vfs_handle_struct *handle,
1362 files_struct *srcfsp,
1363 const struct smb_filename *smb_fname_src,
1364 files_struct *dstfsp,
1365 const struct smb_filename *smb_fname_dst)
1369 result = SMB_VFS_NEXT_RENAMEAT(handle,
1375 do_log(SMB_VFS_OP_RENAMEAT, (result >= 0), handle, "%s|%s",
1376 smb_fname_str_do_log(handle->conn, smb_fname_src),
1377 smb_fname_str_do_log(handle->conn, smb_fname_dst));
1382 struct smb_full_audit_fsync_state {
1383 vfs_handle_struct *handle;
1386 struct vfs_aio_state vfs_aio_state;
1389 static void smb_full_audit_fsync_done(struct tevent_req *subreq);
1391 static struct tevent_req *smb_full_audit_fsync_send(
1392 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1393 struct tevent_context *ev, struct files_struct *fsp)
1395 struct tevent_req *req, *subreq;
1396 struct smb_full_audit_fsync_state *state;
1398 req = tevent_req_create(mem_ctx, &state,
1399 struct smb_full_audit_fsync_state);
1401 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1402 fsp_str_do_log(fsp));
1405 state->handle = handle;
1408 subreq = SMB_VFS_NEXT_FSYNC_SEND(state, ev, handle, fsp);
1409 if (tevent_req_nomem(subreq, req)) {
1410 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1411 fsp_str_do_log(fsp));
1412 return tevent_req_post(req, ev);
1414 tevent_req_set_callback(subreq, smb_full_audit_fsync_done, req);
1416 do_log(SMB_VFS_OP_FSYNC_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1420 static void smb_full_audit_fsync_done(struct tevent_req *subreq)
1422 struct tevent_req *req = tevent_req_callback_data(
1423 subreq, struct tevent_req);
1424 struct smb_full_audit_fsync_state *state = tevent_req_data(
1425 req, struct smb_full_audit_fsync_state);
1427 state->ret = SMB_VFS_FSYNC_RECV(subreq, &state->vfs_aio_state);
1428 TALLOC_FREE(subreq);
1429 tevent_req_done(req);
1432 static int smb_full_audit_fsync_recv(struct tevent_req *req,
1433 struct vfs_aio_state *vfs_aio_state)
1435 struct smb_full_audit_fsync_state *state = tevent_req_data(
1436 req, struct smb_full_audit_fsync_state);
1438 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1439 do_log(SMB_VFS_OP_FSYNC_RECV, false, state->handle, "%s",
1440 fsp_str_do_log(state->fsp));
1444 do_log(SMB_VFS_OP_FSYNC_RECV, (state->ret >= 0), state->handle, "%s",
1445 fsp_str_do_log(state->fsp));
1447 *vfs_aio_state = state->vfs_aio_state;
1451 static int smb_full_audit_stat(vfs_handle_struct *handle,
1452 struct smb_filename *smb_fname)
1456 result = SMB_VFS_NEXT_STAT(handle, smb_fname);
1458 do_log(SMB_VFS_OP_STAT, (result >= 0), handle, "%s",
1459 smb_fname_str_do_log(handle->conn, smb_fname));
1464 static int smb_full_audit_fstat(vfs_handle_struct *handle, files_struct *fsp,
1465 SMB_STRUCT_STAT *sbuf)
1469 result = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1471 do_log(SMB_VFS_OP_FSTAT, (result >= 0), handle, "%s",
1472 fsp_str_do_log(fsp));
1477 static int smb_full_audit_lstat(vfs_handle_struct *handle,
1478 struct smb_filename *smb_fname)
1482 result = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
1484 do_log(SMB_VFS_OP_LSTAT, (result >= 0), handle, "%s",
1485 smb_fname_str_do_log(handle->conn, smb_fname));
1490 static uint64_t smb_full_audit_get_alloc_size(vfs_handle_struct *handle,
1491 files_struct *fsp, const SMB_STRUCT_STAT *sbuf)
1495 result = SMB_VFS_NEXT_GET_ALLOC_SIZE(handle, fsp, sbuf);
1497 do_log(SMB_VFS_OP_GET_ALLOC_SIZE, (result != (uint64_t)-1), handle,
1498 "%llu", (unsigned long long)result);
1503 static int smb_full_audit_unlinkat(vfs_handle_struct *handle,
1504 struct files_struct *dirfsp,
1505 const struct smb_filename *smb_fname,
1510 result = SMB_VFS_NEXT_UNLINKAT(handle,
1515 do_log(SMB_VFS_OP_UNLINKAT, (result >= 0), handle, "%s",
1516 smb_fname_str_do_log(handle->conn, smb_fname));
1521 static int smb_full_audit_chmod(vfs_handle_struct *handle,
1522 const struct smb_filename *smb_fname,
1527 result = SMB_VFS_NEXT_CHMOD(handle, smb_fname, mode);
1529 do_log(SMB_VFS_OP_CHMOD,
1533 smb_fname_str_do_log(handle->conn, smb_fname),
1539 static int smb_full_audit_fchmod(vfs_handle_struct *handle, files_struct *fsp,
1544 result = SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1546 do_log(SMB_VFS_OP_FCHMOD, (result >= 0), handle,
1547 "%s|%o", fsp_str_do_log(fsp), mode);
1552 static int smb_full_audit_fchown(vfs_handle_struct *handle, files_struct *fsp,
1553 uid_t uid, gid_t gid)
1557 result = SMB_VFS_NEXT_FCHOWN(handle, fsp, uid, gid);
1559 do_log(SMB_VFS_OP_FCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1560 fsp_str_do_log(fsp), (long int)uid, (long int)gid);
1565 static int smb_full_audit_lchown(vfs_handle_struct *handle,
1566 const struct smb_filename *smb_fname,
1572 result = SMB_VFS_NEXT_LCHOWN(handle, smb_fname, uid, gid);
1574 do_log(SMB_VFS_OP_LCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1575 smb_fname->base_name, (long int)uid, (long int)gid);
1580 static int smb_full_audit_chdir(vfs_handle_struct *handle,
1581 const struct smb_filename *smb_fname)
1585 result = SMB_VFS_NEXT_CHDIR(handle, smb_fname);
1587 do_log(SMB_VFS_OP_CHDIR,
1591 smb_fname_str_do_log(handle->conn, smb_fname));
1596 static struct smb_filename *smb_full_audit_getwd(vfs_handle_struct *handle,
1599 struct smb_filename *result;
1601 result = SMB_VFS_NEXT_GETWD(handle, ctx);
1603 do_log(SMB_VFS_OP_GETWD, (result != NULL), handle, "%s",
1604 result == NULL? "" : result->base_name);
1609 static int smb_full_audit_ntimes(vfs_handle_struct *handle,
1610 const struct smb_filename *smb_fname,
1611 struct smb_file_time *ft)
1614 time_t create_time = convert_timespec_to_time_t(ft->create_time);
1615 time_t atime = convert_timespec_to_time_t(ft->atime);
1616 time_t mtime = convert_timespec_to_time_t(ft->mtime);
1617 time_t ctime = convert_timespec_to_time_t(ft->ctime);
1618 const char *create_time_str = "";
1619 const char *atime_str = "";
1620 const char *mtime_str = "";
1621 const char *ctime_str = "";
1622 TALLOC_CTX *frame = talloc_stackframe();
1624 result = SMB_VFS_NEXT_NTIMES(handle, smb_fname, ft);
1626 if (create_time > 0) {
1627 create_time_str = timestring(frame, create_time);
1630 atime_str = timestring(frame, atime);
1633 mtime_str = timestring(frame, mtime);
1636 ctime_str = timestring(frame, ctime);
1639 do_log(SMB_VFS_OP_NTIMES,
1643 smb_fname_str_do_log(handle->conn, smb_fname),
1654 static int smb_full_audit_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
1659 result = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1661 do_log(SMB_VFS_OP_FTRUNCATE, (result >= 0), handle,
1662 "%s", fsp_str_do_log(fsp));
1667 static int smb_full_audit_fallocate(vfs_handle_struct *handle, files_struct *fsp,
1674 result = SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
1676 do_log(SMB_VFS_OP_FALLOCATE, (result >= 0), handle,
1677 "%s", fsp_str_do_log(fsp));
1682 static bool smb_full_audit_lock(vfs_handle_struct *handle, files_struct *fsp,
1683 int op, off_t offset, off_t count, int type)
1687 result = SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type);
1689 do_log(SMB_VFS_OP_LOCK, result, handle, "%s", fsp_str_do_log(fsp));
1694 static int smb_full_audit_kernel_flock(struct vfs_handle_struct *handle,
1695 struct files_struct *fsp,
1696 uint32_t share_access,
1697 uint32_t access_mask)
1701 result = SMB_VFS_NEXT_KERNEL_FLOCK(handle,
1706 do_log(SMB_VFS_OP_KERNEL_FLOCK, (result >= 0), handle, "%s",
1707 fsp_str_do_log(fsp));
1712 static int smb_full_audit_fcntl(struct vfs_handle_struct *handle,
1713 struct files_struct *fsp,
1714 int cmd, va_list cmd_arg)
1717 va_list dup_cmd_arg;
1720 va_copy(dup_cmd_arg, cmd_arg);
1721 arg = va_arg(dup_cmd_arg, void *);
1722 result = SMB_VFS_NEXT_FCNTL(handle, fsp, cmd, arg);
1723 va_end(dup_cmd_arg);
1725 do_log(SMB_VFS_OP_FCNTL, (result >= 0), handle, "%s",
1726 fsp_str_do_log(fsp));
1731 static int smb_full_audit_linux_setlease(vfs_handle_struct *handle, files_struct *fsp,
1736 result = SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
1738 do_log(SMB_VFS_OP_LINUX_SETLEASE, (result >= 0), handle, "%s",
1739 fsp_str_do_log(fsp));
1744 static bool smb_full_audit_getlock(vfs_handle_struct *handle, files_struct *fsp,
1745 off_t *poffset, off_t *pcount, int *ptype, pid_t *ppid)
1749 result = SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype, ppid);
1751 do_log(SMB_VFS_OP_GETLOCK, result, handle, "%s", fsp_str_do_log(fsp));
1756 static int smb_full_audit_symlinkat(vfs_handle_struct *handle,
1757 const char *link_contents,
1758 struct files_struct *dirfsp,
1759 const struct smb_filename *new_smb_fname)
1763 result = SMB_VFS_NEXT_SYMLINKAT(handle,
1768 do_log(SMB_VFS_OP_SYMLINKAT,
1773 smb_fname_str_do_log(handle->conn, new_smb_fname));
1778 static int smb_full_audit_readlinkat(vfs_handle_struct *handle,
1779 files_struct *dirfsp,
1780 const struct smb_filename *smb_fname,
1786 result = SMB_VFS_NEXT_READLINKAT(handle,
1792 do_log(SMB_VFS_OP_READLINKAT,
1796 smb_fname_str_do_log(handle->conn, smb_fname));
1801 static int smb_full_audit_linkat(vfs_handle_struct *handle,
1802 files_struct *srcfsp,
1803 const struct smb_filename *old_smb_fname,
1804 files_struct *dstfsp,
1805 const struct smb_filename *new_smb_fname,
1810 result = SMB_VFS_NEXT_LINKAT(handle,
1817 do_log(SMB_VFS_OP_LINKAT,
1821 smb_fname_str_do_log(handle->conn, old_smb_fname),
1822 smb_fname_str_do_log(handle->conn, new_smb_fname));
1827 static int smb_full_audit_mknodat(vfs_handle_struct *handle,
1828 files_struct *dirfsp,
1829 const struct smb_filename *smb_fname,
1835 result = SMB_VFS_NEXT_MKNODAT(handle,
1841 do_log(SMB_VFS_OP_MKNODAT,
1845 smb_fname_str_do_log(handle->conn, smb_fname));
1850 static struct smb_filename *smb_full_audit_realpath(vfs_handle_struct *handle,
1852 const struct smb_filename *smb_fname)
1854 struct smb_filename *result_fname = NULL;
1856 result_fname = SMB_VFS_NEXT_REALPATH(handle, ctx, smb_fname);
1858 do_log(SMB_VFS_OP_REALPATH,
1859 (result_fname != NULL),
1862 smb_fname_str_do_log(handle->conn, smb_fname));
1864 return result_fname;
1867 static int smb_full_audit_chflags(vfs_handle_struct *handle,
1868 const struct smb_filename *smb_fname,
1873 result = SMB_VFS_NEXT_CHFLAGS(handle, smb_fname, flags);
1875 do_log(SMB_VFS_OP_CHFLAGS,
1879 smb_fname_str_do_log(handle->conn, smb_fname));
1884 static struct file_id smb_full_audit_file_id_create(struct vfs_handle_struct *handle,
1885 const SMB_STRUCT_STAT *sbuf)
1887 struct file_id id_zero = { 0 };
1888 struct file_id result;
1889 struct file_id_buf idbuf;
1891 result = SMB_VFS_NEXT_FILE_ID_CREATE(handle, sbuf);
1893 do_log(SMB_VFS_OP_FILE_ID_CREATE,
1894 !file_id_equal(&id_zero, &result),
1897 file_id_str_buf(result, &idbuf));
1902 static uint64_t smb_full_audit_fs_file_id(struct vfs_handle_struct *handle,
1903 const SMB_STRUCT_STAT *sbuf)
1907 result = SMB_VFS_NEXT_FS_FILE_ID(handle, sbuf);
1909 do_log(SMB_VFS_OP_FS_FILE_ID,
1911 handle, "%" PRIu64, result);
1916 static NTSTATUS smb_full_audit_streaminfo(vfs_handle_struct *handle,
1917 struct files_struct *fsp,
1918 const struct smb_filename *smb_fname,
1919 TALLOC_CTX *mem_ctx,
1920 unsigned int *pnum_streams,
1921 struct stream_struct **pstreams)
1925 result = SMB_VFS_NEXT_STREAMINFO(handle, fsp, smb_fname, mem_ctx,
1926 pnum_streams, pstreams);
1928 do_log(SMB_VFS_OP_STREAMINFO,
1929 NT_STATUS_IS_OK(result),
1932 smb_fname_str_do_log(handle->conn, smb_fname));
1937 static int smb_full_audit_get_real_filename(struct vfs_handle_struct *handle,
1940 TALLOC_CTX *mem_ctx,
1945 result = SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name, mem_ctx,
1948 do_log(SMB_VFS_OP_GET_REAL_FILENAME, (result == 0), handle,
1949 "%s/%s->%s", path, name, (result == 0) ? *found_name : "");
1954 static const char *smb_full_audit_connectpath(vfs_handle_struct *handle,
1955 const struct smb_filename *smb_fname)
1959 result = SMB_VFS_NEXT_CONNECTPATH(handle, smb_fname);
1961 do_log(SMB_VFS_OP_CONNECTPATH,
1965 smb_fname_str_do_log(handle->conn, smb_fname));
1970 static NTSTATUS smb_full_audit_brl_lock_windows(struct vfs_handle_struct *handle,
1971 struct byte_range_lock *br_lck,
1972 struct lock_struct *plock)
1976 result = SMB_VFS_NEXT_BRL_LOCK_WINDOWS(handle, br_lck, plock);
1978 do_log(SMB_VFS_OP_BRL_LOCK_WINDOWS, NT_STATUS_IS_OK(result), handle,
1979 "%s:%llu-%llu. type=%d.",
1980 fsp_str_do_log(brl_fsp(br_lck)),
1981 (unsigned long long)plock->start,
1982 (unsigned long long)plock->size,
1988 static bool smb_full_audit_brl_unlock_windows(struct vfs_handle_struct *handle,
1989 struct byte_range_lock *br_lck,
1990 const struct lock_struct *plock)
1994 result = SMB_VFS_NEXT_BRL_UNLOCK_WINDOWS(handle, br_lck, plock);
1996 do_log(SMB_VFS_OP_BRL_UNLOCK_WINDOWS, (result == 0), handle,
1997 "%s:%llu-%llu:%d", fsp_str_do_log(brl_fsp(br_lck)),
1998 (unsigned long long)plock->start,
1999 (unsigned long long)plock->size,
2005 static bool smb_full_audit_strict_lock_check(struct vfs_handle_struct *handle,
2006 struct files_struct *fsp,
2007 struct lock_struct *plock)
2011 result = SMB_VFS_NEXT_STRICT_LOCK_CHECK(handle, fsp, plock);
2013 do_log(SMB_VFS_OP_STRICT_LOCK_CHECK, result, handle,
2014 "%s:%llu-%llu:%d", fsp_str_do_log(fsp),
2015 (unsigned long long)plock->start,
2016 (unsigned long long)plock->size,
2022 static NTSTATUS smb_full_audit_translate_name(struct vfs_handle_struct *handle,
2024 enum vfs_translate_direction direction,
2025 TALLOC_CTX *mem_ctx,
2030 result = SMB_VFS_NEXT_TRANSLATE_NAME(handle, name, direction, mem_ctx,
2033 do_log(SMB_VFS_OP_TRANSLATE_NAME, NT_STATUS_IS_OK(result), handle, "");
2038 static NTSTATUS smb_full_audit_fsctl(struct vfs_handle_struct *handle,
2039 struct files_struct *fsp,
2043 const uint8_t *_in_data,
2045 uint8_t **_out_data,
2046 uint32_t max_out_len,
2051 result = SMB_VFS_NEXT_FSCTL(handle,
2062 do_log(SMB_VFS_OP_FSCTL, NT_STATUS_IS_OK(result), handle, "");
2067 static struct tevent_req *smb_full_audit_offload_read_send(
2068 TALLOC_CTX *mem_ctx,
2069 struct tevent_context *ev,
2070 struct vfs_handle_struct *handle,
2071 struct files_struct *fsp,
2077 struct tevent_req *req = NULL;
2079 req = SMB_VFS_NEXT_OFFLOAD_READ_SEND(mem_ctx, ev, handle, fsp,
2080 fsctl, ttl, offset, to_copy);
2082 do_log(SMB_VFS_OP_OFFLOAD_READ_SEND, req, handle, "");
2087 static NTSTATUS smb_full_audit_offload_read_recv(
2088 struct tevent_req *req,
2089 struct vfs_handle_struct *handle,
2090 TALLOC_CTX *mem_ctx,
2091 DATA_BLOB *_token_blob)
2095 status = SMB_VFS_NEXT_OFFLOAD_READ_RECV(req, handle, mem_ctx,
2098 do_log(SMB_VFS_OP_OFFLOAD_READ_RECV, NT_STATUS_IS_OK(status), handle, "");
2103 static struct tevent_req *smb_full_audit_offload_write_send(struct vfs_handle_struct *handle,
2104 TALLOC_CTX *mem_ctx,
2105 struct tevent_context *ev,
2108 off_t transfer_offset,
2109 struct files_struct *dest_fsp,
2113 struct tevent_req *req;
2115 req = SMB_VFS_NEXT_OFFLOAD_WRITE_SEND(handle, mem_ctx, ev,
2116 fsctl, token, transfer_offset,
2117 dest_fsp, dest_off, num);
2119 do_log(SMB_VFS_OP_OFFLOAD_WRITE_SEND, req, handle, "");
2124 static NTSTATUS smb_full_audit_offload_write_recv(struct vfs_handle_struct *handle,
2125 struct tevent_req *req,
2130 result = SMB_VFS_NEXT_OFFLOAD_WRITE_RECV(handle, req, copied);
2132 do_log(SMB_VFS_OP_OFFLOAD_WRITE_RECV, NT_STATUS_IS_OK(result), handle, "");
2137 static NTSTATUS smb_full_audit_get_compression(vfs_handle_struct *handle,
2138 TALLOC_CTX *mem_ctx,
2139 struct files_struct *fsp,
2140 struct smb_filename *smb_fname,
2141 uint16_t *_compression_fmt)
2145 result = SMB_VFS_NEXT_GET_COMPRESSION(handle, mem_ctx, fsp, smb_fname,
2148 do_log(SMB_VFS_OP_GET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
2150 (fsp ? fsp_str_do_log(fsp) :
2151 smb_fname_str_do_log(handle->conn, smb_fname)));
2156 static NTSTATUS smb_full_audit_set_compression(vfs_handle_struct *handle,
2157 TALLOC_CTX *mem_ctx,
2158 struct files_struct *fsp,
2159 uint16_t compression_fmt)
2163 result = SMB_VFS_NEXT_SET_COMPRESSION(handle, mem_ctx, fsp,
2166 do_log(SMB_VFS_OP_SET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
2167 "%s", fsp_str_do_log(fsp));
2172 static NTSTATUS smb_full_audit_readdir_attr(struct vfs_handle_struct *handle,
2173 const struct smb_filename *fname,
2174 TALLOC_CTX *mem_ctx,
2175 struct readdir_attr_data **pattr_data)
2179 status = SMB_VFS_NEXT_READDIR_ATTR(handle, fname, mem_ctx, pattr_data);
2181 do_log(SMB_VFS_OP_READDIR_ATTR, NT_STATUS_IS_OK(status), handle, "%s",
2182 smb_fname_str_do_log(handle->conn, fname));
2187 static NTSTATUS smb_full_audit_get_dos_attributes(
2188 struct vfs_handle_struct *handle,
2189 struct smb_filename *smb_fname,
2194 status = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES(handle,
2198 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES,
2199 NT_STATUS_IS_OK(status),
2202 smb_fname_str_do_log(handle->conn, smb_fname));
2207 struct smb_full_audit_get_dos_attributes_state {
2208 struct vfs_aio_state aio_state;
2209 vfs_handle_struct *handle;
2210 files_struct *dir_fsp;
2211 const struct smb_filename *smb_fname;
2215 static void smb_full_audit_get_dos_attributes_done(struct tevent_req *subreq);
2217 static struct tevent_req *smb_full_audit_get_dos_attributes_send(
2218 TALLOC_CTX *mem_ctx,
2219 struct tevent_context *ev,
2220 struct vfs_handle_struct *handle,
2221 files_struct *dir_fsp,
2222 struct smb_filename *smb_fname)
2224 struct tevent_req *req = NULL;
2225 struct smb_full_audit_get_dos_attributes_state *state = NULL;
2226 struct tevent_req *subreq = NULL;
2228 req = tevent_req_create(mem_ctx, &state,
2229 struct smb_full_audit_get_dos_attributes_state);
2231 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2235 fsp_str_do_log(dir_fsp),
2236 smb_fname->base_name);
2239 *state = (struct smb_full_audit_get_dos_attributes_state) {
2242 .smb_fname = smb_fname,
2245 subreq = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES_SEND(mem_ctx,
2250 if (tevent_req_nomem(subreq, req)) {
2251 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2255 fsp_str_do_log(dir_fsp),
2256 smb_fname->base_name);
2257 return tevent_req_post(req, ev);
2259 tevent_req_set_callback(subreq,
2260 smb_full_audit_get_dos_attributes_done,
2263 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2267 fsp_str_do_log(dir_fsp),
2268 smb_fname->base_name);
2273 static void smb_full_audit_get_dos_attributes_done(struct tevent_req *subreq)
2275 struct tevent_req *req =
2276 tevent_req_callback_data(subreq,
2278 struct smb_full_audit_get_dos_attributes_state *state =
2279 tevent_req_data(req,
2280 struct smb_full_audit_get_dos_attributes_state);
2283 status = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES_RECV(subreq,
2286 TALLOC_FREE(subreq);
2287 if (tevent_req_nterror(req, status)) {
2291 tevent_req_done(req);
2295 static NTSTATUS smb_full_audit_get_dos_attributes_recv(struct tevent_req *req,
2296 struct vfs_aio_state *aio_state,
2299 struct smb_full_audit_get_dos_attributes_state *state =
2300 tevent_req_data(req,
2301 struct smb_full_audit_get_dos_attributes_state);
2304 if (tevent_req_is_nterror(req, &status)) {
2305 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV,
2309 fsp_str_do_log(state->dir_fsp),
2310 state->smb_fname->base_name);
2311 tevent_req_received(req);
2315 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV,
2319 fsp_str_do_log(state->dir_fsp),
2320 state->smb_fname->base_name);
2322 *aio_state = state->aio_state;
2323 *dosmode = state->dosmode;
2324 tevent_req_received(req);
2325 return NT_STATUS_OK;
2328 static NTSTATUS smb_full_audit_fget_dos_attributes(
2329 struct vfs_handle_struct *handle,
2330 struct files_struct *fsp,
2335 status = SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle,
2339 do_log(SMB_VFS_OP_FGET_DOS_ATTRIBUTES,
2340 NT_STATUS_IS_OK(status),
2343 fsp_str_do_log(fsp));
2348 static NTSTATUS smb_full_audit_set_dos_attributes(
2349 struct vfs_handle_struct *handle,
2350 const struct smb_filename *smb_fname,
2355 status = SMB_VFS_NEXT_SET_DOS_ATTRIBUTES(handle,
2359 do_log(SMB_VFS_OP_SET_DOS_ATTRIBUTES,
2360 NT_STATUS_IS_OK(status),
2363 smb_fname_str_do_log(handle->conn, smb_fname));
2368 static NTSTATUS smb_full_audit_fset_dos_attributes(
2369 struct vfs_handle_struct *handle,
2370 struct files_struct *fsp,
2375 status = SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle,
2379 do_log(SMB_VFS_OP_FSET_DOS_ATTRIBUTES,
2380 NT_STATUS_IS_OK(status),
2383 fsp_str_do_log(fsp));
2388 static NTSTATUS smb_full_audit_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
2389 uint32_t security_info,
2390 TALLOC_CTX *mem_ctx,
2391 struct security_descriptor **ppdesc)
2395 result = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
2398 do_log(SMB_VFS_OP_FGET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2399 "%s", fsp_str_do_log(fsp));
2404 static NTSTATUS smb_full_audit_get_nt_acl(vfs_handle_struct *handle,
2405 const struct smb_filename *smb_fname,
2406 uint32_t security_info,
2407 TALLOC_CTX *mem_ctx,
2408 struct security_descriptor **ppdesc)
2412 result = SMB_VFS_NEXT_GET_NT_ACL(handle, smb_fname, security_info,
2415 do_log(SMB_VFS_OP_GET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2416 "%s", smb_fname_str_do_log(handle->conn, smb_fname));
2421 static NTSTATUS smb_full_audit_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
2422 uint32_t security_info_sent,
2423 const struct security_descriptor *psd)
2425 struct vfs_full_audit_private_data *pd;
2429 SMB_VFS_HANDLE_GET_DATA(handle, pd,
2430 struct vfs_full_audit_private_data,
2431 return NT_STATUS_INTERNAL_ERROR);
2433 if (pd->log_secdesc) {
2434 sd = sddl_encode(talloc_tos(), psd, get_global_sam_sid());
2437 result = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
2439 do_log(SMB_VFS_OP_FSET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2440 "%s [%s]", fsp_str_do_log(fsp), sd ? sd : "");
2447 static NTSTATUS smb_full_audit_audit_file(struct vfs_handle_struct *handle,
2448 struct smb_filename *file,
2449 struct security_acl *sacl,
2450 uint32_t access_requested,
2451 uint32_t access_denied)
2455 result = SMB_VFS_NEXT_AUDIT_FILE(handle,
2461 do_log(SMB_VFS_OP_AUDIT_FILE, NT_STATUS_IS_OK(result), handle,
2463 smb_fname_str_do_log(handle->conn, file));
2468 static SMB_ACL_T smb_full_audit_sys_acl_get_file(vfs_handle_struct *handle,
2469 const struct smb_filename *smb_fname,
2470 SMB_ACL_TYPE_T type,
2471 TALLOC_CTX *mem_ctx)
2475 result = SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, smb_fname,
2478 do_log(SMB_VFS_OP_SYS_ACL_GET_FILE,
2482 smb_fname_str_do_log(handle->conn, smb_fname));
2487 static SMB_ACL_T smb_full_audit_sys_acl_get_fd(vfs_handle_struct *handle,
2488 files_struct *fsp, TALLOC_CTX *mem_ctx)
2492 result = SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp, mem_ctx);
2494 do_log(SMB_VFS_OP_SYS_ACL_GET_FD, (result != NULL), handle,
2495 "%s", fsp_str_do_log(fsp));
2500 static int smb_full_audit_sys_acl_blob_get_file(vfs_handle_struct *handle,
2501 const struct smb_filename *smb_fname,
2502 TALLOC_CTX *mem_ctx,
2503 char **blob_description,
2508 result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FILE(handle, smb_fname,
2509 mem_ctx, blob_description, blob);
2511 do_log(SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE,
2515 smb_fname_str_do_log(handle->conn, smb_fname));
2520 static int smb_full_audit_sys_acl_blob_get_fd(vfs_handle_struct *handle,
2522 TALLOC_CTX *mem_ctx,
2523 char **blob_description,
2528 result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle, fsp, mem_ctx, blob_description, blob);
2530 do_log(SMB_VFS_OP_SYS_ACL_BLOB_GET_FD, (result >= 0), handle,
2531 "%s", fsp_str_do_log(fsp));
2536 static int smb_full_audit_sys_acl_set_file(vfs_handle_struct *handle,
2537 const struct smb_filename *smb_fname,
2538 SMB_ACL_TYPE_T acltype,
2543 result = SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, smb_fname, acltype,
2546 do_log(SMB_VFS_OP_SYS_ACL_SET_FILE,
2550 smb_fname_str_do_log(handle->conn, smb_fname));
2555 static int smb_full_audit_sys_acl_set_fd(vfs_handle_struct *handle, files_struct *fsp,
2560 result = SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, theacl);
2562 do_log(SMB_VFS_OP_SYS_ACL_SET_FD, (result >= 0), handle,
2563 "%s", fsp_str_do_log(fsp));
2568 static int smb_full_audit_sys_acl_delete_def_file(vfs_handle_struct *handle,
2569 const struct smb_filename *smb_fname)
2573 result = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, smb_fname);
2575 do_log(SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE,
2579 smb_fname_str_do_log(handle->conn, smb_fname));
2584 static ssize_t smb_full_audit_getxattr(struct vfs_handle_struct *handle,
2585 const struct smb_filename *smb_fname,
2586 const char *name, void *value, size_t size)
2590 result = SMB_VFS_NEXT_GETXATTR(handle, smb_fname, name, value, size);
2592 do_log(SMB_VFS_OP_GETXATTR,
2596 smb_fname_str_do_log(handle->conn, smb_fname),
2602 struct smb_full_audit_getxattrat_state {
2603 struct vfs_aio_state aio_state;
2604 vfs_handle_struct *handle;
2605 files_struct *dir_fsp;
2606 const struct smb_filename *smb_fname;
2607 const char *xattr_name;
2609 uint8_t *xattr_value;
2612 static void smb_full_audit_getxattrat_done(struct tevent_req *subreq);
2614 static struct tevent_req *smb_full_audit_getxattrat_send(
2615 TALLOC_CTX *mem_ctx,
2616 struct tevent_context *ev,
2617 struct vfs_handle_struct *handle,
2618 files_struct *dir_fsp,
2619 const struct smb_filename *smb_fname,
2620 const char *xattr_name,
2623 struct tevent_req *req = NULL;
2624 struct tevent_req *subreq = NULL;
2625 struct smb_full_audit_getxattrat_state *state = NULL;
2627 req = tevent_req_create(mem_ctx, &state,
2628 struct smb_full_audit_getxattrat_state);
2630 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2634 fsp_str_do_log(dir_fsp),
2635 smb_fname->base_name,
2639 *state = (struct smb_full_audit_getxattrat_state) {
2642 .smb_fname = smb_fname,
2643 .xattr_name = xattr_name,
2646 subreq = SMB_VFS_NEXT_GETXATTRAT_SEND(state,
2653 if (tevent_req_nomem(subreq, req)) {
2654 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2658 fsp_str_do_log(dir_fsp),
2659 smb_fname->base_name,
2661 return tevent_req_post(req, ev);
2663 tevent_req_set_callback(subreq, smb_full_audit_getxattrat_done, req);
2665 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2669 fsp_str_do_log(dir_fsp),
2670 smb_fname->base_name,
2676 static void smb_full_audit_getxattrat_done(struct tevent_req *subreq)
2678 struct tevent_req *req = tevent_req_callback_data(
2679 subreq, struct tevent_req);
2680 struct smb_full_audit_getxattrat_state *state = tevent_req_data(
2681 req, struct smb_full_audit_getxattrat_state);
2683 state->xattr_size = SMB_VFS_NEXT_GETXATTRAT_RECV(subreq,
2686 &state->xattr_value);
2687 TALLOC_FREE(subreq);
2688 if (state->xattr_size == -1) {
2689 tevent_req_error(req, state->aio_state.error);
2693 tevent_req_done(req);
2696 static ssize_t smb_full_audit_getxattrat_recv(struct tevent_req *req,
2697 struct vfs_aio_state *aio_state,
2698 TALLOC_CTX *mem_ctx,
2699 uint8_t **xattr_value)
2701 struct smb_full_audit_getxattrat_state *state = tevent_req_data(
2702 req, struct smb_full_audit_getxattrat_state);
2705 if (tevent_req_is_unix_error(req, &aio_state->error)) {
2706 do_log(SMB_VFS_OP_GETXATTRAT_RECV,
2710 fsp_str_do_log(state->dir_fsp),
2711 state->smb_fname->base_name,
2713 tevent_req_received(req);
2717 do_log(SMB_VFS_OP_GETXATTRAT_RECV,
2721 fsp_str_do_log(state->dir_fsp),
2722 state->smb_fname->base_name,
2725 *aio_state = state->aio_state;
2726 xattr_size = state->xattr_size;
2727 if (xattr_value != NULL) {
2728 *xattr_value = talloc_move(mem_ctx, &state->xattr_value);
2731 tevent_req_received(req);
2735 static ssize_t smb_full_audit_fgetxattr(struct vfs_handle_struct *handle,
2736 struct files_struct *fsp,
2737 const char *name, void *value, size_t size)
2741 result = SMB_VFS_NEXT_FGETXATTR(handle, fsp, name, value, size);
2743 do_log(SMB_VFS_OP_FGETXATTR, (result >= 0), handle,
2744 "%s|%s", fsp_str_do_log(fsp), name);
2749 static ssize_t smb_full_audit_listxattr(struct vfs_handle_struct *handle,
2750 const struct smb_filename *smb_fname,
2756 result = SMB_VFS_NEXT_LISTXATTR(handle, smb_fname, list, size);
2758 do_log(SMB_VFS_OP_LISTXATTR,
2762 smb_fname_str_do_log(handle->conn, smb_fname));
2767 static ssize_t smb_full_audit_flistxattr(struct vfs_handle_struct *handle,
2768 struct files_struct *fsp, char *list,
2773 result = SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
2775 do_log(SMB_VFS_OP_FLISTXATTR, (result >= 0), handle,
2776 "%s", fsp_str_do_log(fsp));
2781 static int smb_full_audit_removexattr(struct vfs_handle_struct *handle,
2782 const struct smb_filename *smb_fname,
2787 result = SMB_VFS_NEXT_REMOVEXATTR(handle, smb_fname, name);
2789 do_log(SMB_VFS_OP_REMOVEXATTR,
2793 smb_fname_str_do_log(handle->conn, smb_fname),
2799 static int smb_full_audit_fremovexattr(struct vfs_handle_struct *handle,
2800 struct files_struct *fsp,
2805 result = SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, name);
2807 do_log(SMB_VFS_OP_FREMOVEXATTR, (result >= 0), handle,
2808 "%s|%s", fsp_str_do_log(fsp), name);
2813 static int smb_full_audit_setxattr(struct vfs_handle_struct *handle,
2814 const struct smb_filename *smb_fname,
2815 const char *name, const void *value, size_t size,
2820 result = SMB_VFS_NEXT_SETXATTR(handle, smb_fname, name, value, size,
2823 do_log(SMB_VFS_OP_SETXATTR,
2827 smb_fname_str_do_log(handle->conn, smb_fname),
2833 static int smb_full_audit_fsetxattr(struct vfs_handle_struct *handle,
2834 struct files_struct *fsp, const char *name,
2835 const void *value, size_t size, int flags)
2839 result = SMB_VFS_NEXT_FSETXATTR(handle, fsp, name, value, size, flags);
2841 do_log(SMB_VFS_OP_FSETXATTR, (result >= 0), handle,
2842 "%s|%s", fsp_str_do_log(fsp), name);
2847 static bool smb_full_audit_aio_force(struct vfs_handle_struct *handle,
2848 struct files_struct *fsp)
2852 result = SMB_VFS_NEXT_AIO_FORCE(handle, fsp);
2853 do_log(SMB_VFS_OP_AIO_FORCE, result, handle,
2854 "%s", fsp_str_do_log(fsp));
2859 static NTSTATUS smb_full_audit_durable_cookie(struct vfs_handle_struct *handle,
2860 struct files_struct *fsp,
2861 TALLOC_CTX *mem_ctx,
2866 result = SMB_VFS_NEXT_DURABLE_COOKIE(handle,
2871 do_log(SMB_VFS_OP_DURABLE_COOKIE, NT_STATUS_IS_OK(result), handle,
2872 "%s", fsp_str_do_log(fsp));
2877 static NTSTATUS smb_full_audit_durable_disconnect(
2878 struct vfs_handle_struct *handle,
2879 struct files_struct *fsp,
2880 const DATA_BLOB old_cookie,
2881 TALLOC_CTX *mem_ctx,
2882 DATA_BLOB *new_cookie)
2886 result = SMB_VFS_NEXT_DURABLE_DISCONNECT(handle,
2892 do_log(SMB_VFS_OP_DURABLE_DISCONNECT, NT_STATUS_IS_OK(result), handle,
2893 "%s", fsp_str_do_log(fsp));
2898 static NTSTATUS smb_full_audit_durable_reconnect(
2899 struct vfs_handle_struct *handle,
2900 struct smb_request *smb1req,
2901 struct smbXsrv_open *op,
2902 const DATA_BLOB old_cookie,
2903 TALLOC_CTX *mem_ctx,
2904 struct files_struct **fsp,
2905 DATA_BLOB *new_cookie)
2909 result = SMB_VFS_NEXT_DURABLE_RECONNECT(handle,
2917 do_log(SMB_VFS_OP_DURABLE_RECONNECT,
2918 NT_STATUS_IS_OK(result),
2925 static struct vfs_fn_pointers vfs_full_audit_fns = {
2927 /* Disk operations */
2929 .connect_fn = smb_full_audit_connect,
2930 .disconnect_fn = smb_full_audit_disconnect,
2931 .disk_free_fn = smb_full_audit_disk_free,
2932 .get_quota_fn = smb_full_audit_get_quota,
2933 .set_quota_fn = smb_full_audit_set_quota,
2934 .get_shadow_copy_data_fn = smb_full_audit_get_shadow_copy_data,
2935 .statvfs_fn = smb_full_audit_statvfs,
2936 .fs_capabilities_fn = smb_full_audit_fs_capabilities,
2937 .get_dfs_referrals_fn = smb_full_audit_get_dfs_referrals,
2938 .opendir_fn = smb_full_audit_opendir,
2939 .fdopendir_fn = smb_full_audit_fdopendir,
2940 .readdir_fn = smb_full_audit_readdir,
2941 .seekdir_fn = smb_full_audit_seekdir,
2942 .telldir_fn = smb_full_audit_telldir,
2943 .rewind_dir_fn = smb_full_audit_rewinddir,
2944 .mkdirat_fn = smb_full_audit_mkdirat,
2945 .closedir_fn = smb_full_audit_closedir,
2946 .open_fn = smb_full_audit_open,
2947 .create_file_fn = smb_full_audit_create_file,
2948 .close_fn = smb_full_audit_close,
2949 .pread_fn = smb_full_audit_pread,
2950 .pread_send_fn = smb_full_audit_pread_send,
2951 .pread_recv_fn = smb_full_audit_pread_recv,
2952 .pwrite_fn = smb_full_audit_pwrite,
2953 .pwrite_send_fn = smb_full_audit_pwrite_send,
2954 .pwrite_recv_fn = smb_full_audit_pwrite_recv,
2955 .lseek_fn = smb_full_audit_lseek,
2956 .sendfile_fn = smb_full_audit_sendfile,
2957 .recvfile_fn = smb_full_audit_recvfile,
2958 .renameat_fn = smb_full_audit_renameat,
2959 .fsync_send_fn = smb_full_audit_fsync_send,
2960 .fsync_recv_fn = smb_full_audit_fsync_recv,
2961 .stat_fn = smb_full_audit_stat,
2962 .fstat_fn = smb_full_audit_fstat,
2963 .lstat_fn = smb_full_audit_lstat,
2964 .get_alloc_size_fn = smb_full_audit_get_alloc_size,
2965 .unlinkat_fn = smb_full_audit_unlinkat,
2966 .chmod_fn = smb_full_audit_chmod,
2967 .fchmod_fn = smb_full_audit_fchmod,
2968 .fchown_fn = smb_full_audit_fchown,
2969 .lchown_fn = smb_full_audit_lchown,
2970 .chdir_fn = smb_full_audit_chdir,
2971 .getwd_fn = smb_full_audit_getwd,
2972 .ntimes_fn = smb_full_audit_ntimes,
2973 .ftruncate_fn = smb_full_audit_ftruncate,
2974 .fallocate_fn = smb_full_audit_fallocate,
2975 .lock_fn = smb_full_audit_lock,
2976 .kernel_flock_fn = smb_full_audit_kernel_flock,
2977 .fcntl_fn = smb_full_audit_fcntl,
2978 .linux_setlease_fn = smb_full_audit_linux_setlease,
2979 .getlock_fn = smb_full_audit_getlock,
2980 .symlinkat_fn = smb_full_audit_symlinkat,
2981 .readlinkat_fn = smb_full_audit_readlinkat,
2982 .linkat_fn = smb_full_audit_linkat,
2983 .mknodat_fn = smb_full_audit_mknodat,
2984 .realpath_fn = smb_full_audit_realpath,
2985 .chflags_fn = smb_full_audit_chflags,
2986 .file_id_create_fn = smb_full_audit_file_id_create,
2987 .fs_file_id_fn = smb_full_audit_fs_file_id,
2988 .offload_read_send_fn = smb_full_audit_offload_read_send,
2989 .offload_read_recv_fn = smb_full_audit_offload_read_recv,
2990 .offload_write_send_fn = smb_full_audit_offload_write_send,
2991 .offload_write_recv_fn = smb_full_audit_offload_write_recv,
2992 .get_compression_fn = smb_full_audit_get_compression,
2993 .set_compression_fn = smb_full_audit_set_compression,
2994 .snap_check_path_fn = smb_full_audit_snap_check_path,
2995 .snap_create_fn = smb_full_audit_snap_create,
2996 .snap_delete_fn = smb_full_audit_snap_delete,
2997 .streaminfo_fn = smb_full_audit_streaminfo,
2998 .get_real_filename_fn = smb_full_audit_get_real_filename,
2999 .connectpath_fn = smb_full_audit_connectpath,
3000 .brl_lock_windows_fn = smb_full_audit_brl_lock_windows,
3001 .brl_unlock_windows_fn = smb_full_audit_brl_unlock_windows,
3002 .strict_lock_check_fn = smb_full_audit_strict_lock_check,
3003 .translate_name_fn = smb_full_audit_translate_name,
3004 .fsctl_fn = smb_full_audit_fsctl,
3005 .get_dos_attributes_fn = smb_full_audit_get_dos_attributes,
3006 .get_dos_attributes_send_fn = smb_full_audit_get_dos_attributes_send,
3007 .get_dos_attributes_recv_fn = smb_full_audit_get_dos_attributes_recv,
3008 .fget_dos_attributes_fn = smb_full_audit_fget_dos_attributes,
3009 .set_dos_attributes_fn = smb_full_audit_set_dos_attributes,
3010 .fset_dos_attributes_fn = smb_full_audit_fset_dos_attributes,
3011 .fget_nt_acl_fn = smb_full_audit_fget_nt_acl,
3012 .get_nt_acl_fn = smb_full_audit_get_nt_acl,
3013 .fset_nt_acl_fn = smb_full_audit_fset_nt_acl,
3014 .audit_file_fn = smb_full_audit_audit_file,
3015 .sys_acl_get_file_fn = smb_full_audit_sys_acl_get_file,
3016 .sys_acl_get_fd_fn = smb_full_audit_sys_acl_get_fd,
3017 .sys_acl_blob_get_file_fn = smb_full_audit_sys_acl_blob_get_file,
3018 .sys_acl_blob_get_fd_fn = smb_full_audit_sys_acl_blob_get_fd,
3019 .sys_acl_set_file_fn = smb_full_audit_sys_acl_set_file,
3020 .sys_acl_set_fd_fn = smb_full_audit_sys_acl_set_fd,
3021 .sys_acl_delete_def_file_fn = smb_full_audit_sys_acl_delete_def_file,
3022 .getxattr_fn = smb_full_audit_getxattr,
3023 .getxattrat_send_fn = smb_full_audit_getxattrat_send,
3024 .getxattrat_recv_fn = smb_full_audit_getxattrat_recv,
3025 .fgetxattr_fn = smb_full_audit_fgetxattr,
3026 .listxattr_fn = smb_full_audit_listxattr,
3027 .flistxattr_fn = smb_full_audit_flistxattr,
3028 .removexattr_fn = smb_full_audit_removexattr,
3029 .fremovexattr_fn = smb_full_audit_fremovexattr,
3030 .setxattr_fn = smb_full_audit_setxattr,
3031 .fsetxattr_fn = smb_full_audit_fsetxattr,
3032 .aio_force_fn = smb_full_audit_aio_force,
3033 .durable_cookie_fn = smb_full_audit_durable_cookie,
3034 .durable_disconnect_fn = smb_full_audit_durable_disconnect,
3035 .durable_reconnect_fn = smb_full_audit_durable_reconnect,
3036 .readdir_attr_fn = smb_full_audit_readdir_attr
3041 NTSTATUS vfs_full_audit_init(TALLOC_CTX *ctx)
3045 smb_vfs_assert_all_fns(&vfs_full_audit_fns, "full_audit");
3047 ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "full_audit",
3048 &vfs_full_audit_fns);
3050 if (!NT_STATUS_IS_OK(ret))
3053 vfs_full_audit_debug_level = debug_add_class("full_audit");
3054 if (vfs_full_audit_debug_level == -1) {
3055 vfs_full_audit_debug_level = DBGC_VFS;
3056 DEBUG(0, ("vfs_full_audit: Couldn't register custom debugging "
3059 DEBUG(10, ("vfs_full_audit: Debug class number of "
3060 "'full_audit': %d\n", vfs_full_audit_debug_level));