2 * Auditing VFS module for samba. Log selected file operations to syslog
5 * Copyright (C) Tim Potter, 1999-2000
6 * Copyright (C) Alexander Bokovoy, 2002
7 * Copyright (C) John H Terpstra, 2003
8 * Copyright (C) Stefan (metze) Metzmacher, 2003
9 * Copyright (C) Volker Lendecke, 2004
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, see <http://www.gnu.org/licenses/>.
26 * This module implements parseable logging for all Samba VFS operations.
28 * You use it as follows:
32 * vfs objects = full_audit
33 * full_audit:prefix = %u|%I
34 * full_audit:success = open opendir create_file
35 * full_audit:failure = all
37 * vfs op can be "all" which means log all operations.
38 * vfs op can be "none" which means no logging.
40 * This leads to syslog entries of the form:
41 * smbd_audit: nobody|192.168.234.1|opendir|ok|/tmp
42 * smbd_audit: nobody|192.168.234.1|create_file|fail (No such file or directory)|0x1|file|open|/ts/doesNotExist
43 * smbd_audit: nobody|192.168.234.1|open|ok|w|/tmp/file.txt
44 * smbd_audit: nobody|192.168.234.1|create_file|ok|0x3|file|open|/tmp/file.txt
46 * where "nobody" is the connected username and "192.168.234.1" is the
47 * client's IP address.
51 * prefix: A macro expansion template prepended to the syslog entry.
53 * success: A list of VFS operations for which a successful completion should
54 * be logged. Defaults to no logging at all. The special operation "all" logs
55 * - you guessed it - everything.
57 * failure: A list of VFS operations for which failure to complete should be
58 * logged. Defaults to logging everything.
63 #include "system/filesys.h"
64 #include "system/syslog.h"
65 #include "smbd/smbd.h"
66 #include "../librpc/gen_ndr/ndr_netlogon.h"
69 #include "lib/param/loadparm.h"
70 #include "lib/util/bitmap.h"
71 #include "lib/util/tevent_unix.h"
72 #include "libcli/security/sddl.h"
73 #include "passdb/machine_sid.h"
74 #include "lib/util/tevent_ntstatus.h"
75 #include "lib/util/string_wrappers.h"
77 static int vfs_full_audit_debug_level = DBGC_VFS;
79 struct vfs_full_audit_private_data {
80 struct bitmap *success_ops;
81 struct bitmap *failure_ops;
89 #define DBGC_CLASS vfs_full_audit_debug_level
91 typedef enum _vfs_op_type {
96 SMB_VFS_OP_CONNECT = 0,
97 SMB_VFS_OP_DISCONNECT,
100 SMB_VFS_OP_SET_QUOTA,
101 SMB_VFS_OP_GET_SHADOW_COPY_DATA,
103 SMB_VFS_OP_FS_CAPABILITIES,
104 SMB_VFS_OP_GET_DFS_REFERRALS,
105 SMB_VFS_OP_CREATE_DFS_PATHAT,
106 SMB_VFS_OP_READ_DFS_PATHAT,
108 /* Directory operations */
110 SMB_VFS_OP_FDOPENDIR,
114 SMB_VFS_OP_REWINDDIR,
118 /* File operations */
122 SMB_VFS_OP_CREATE_FILE,
126 SMB_VFS_OP_PREAD_SEND,
127 SMB_VFS_OP_PREAD_RECV,
130 SMB_VFS_OP_PWRITE_SEND,
131 SMB_VFS_OP_PWRITE_RECV,
137 SMB_VFS_OP_FSYNC_SEND,
138 SMB_VFS_OP_FSYNC_RECV,
142 SMB_VFS_OP_GET_ALLOC_SIZE,
151 SMB_VFS_OP_FTRUNCATE,
152 SMB_VFS_OP_FALLOCATE,
154 SMB_VFS_OP_KERNEL_FLOCK,
156 SMB_VFS_OP_LINUX_SETLEASE,
158 SMB_VFS_OP_SYMLINKAT,
159 SMB_VFS_OP_READLINKAT,
164 SMB_VFS_OP_FILE_ID_CREATE,
165 SMB_VFS_OP_FS_FILE_ID,
166 SMB_VFS_OP_STREAMINFO,
167 SMB_VFS_OP_GET_REAL_FILENAME,
168 SMB_VFS_OP_CONNECTPATH,
169 SMB_VFS_OP_BRL_LOCK_WINDOWS,
170 SMB_VFS_OP_BRL_UNLOCK_WINDOWS,
171 SMB_VFS_OP_STRICT_LOCK_CHECK,
172 SMB_VFS_OP_TRANSLATE_NAME,
174 SMB_VFS_OP_OFFLOAD_READ_SEND,
175 SMB_VFS_OP_OFFLOAD_READ_RECV,
176 SMB_VFS_OP_OFFLOAD_WRITE_SEND,
177 SMB_VFS_OP_OFFLOAD_WRITE_RECV,
178 SMB_VFS_OP_FGET_COMPRESSION,
179 SMB_VFS_OP_SET_COMPRESSION,
180 SMB_VFS_OP_SNAP_CHECK_PATH,
181 SMB_VFS_OP_SNAP_CREATE,
182 SMB_VFS_OP_SNAP_DELETE,
184 /* DOS attribute operations. */
185 SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
186 SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV,
187 SMB_VFS_OP_FGET_DOS_ATTRIBUTES,
188 SMB_VFS_OP_FSET_DOS_ATTRIBUTES,
190 /* NT ACL operations. */
192 SMB_VFS_OP_FGET_NT_ACL,
193 SMB_VFS_OP_GET_NT_ACL_AT,
194 SMB_VFS_OP_FSET_NT_ACL,
195 SMB_VFS_OP_AUDIT_FILE,
197 /* POSIX ACL operations. */
199 SMB_VFS_OP_SYS_ACL_GET_FILE,
200 SMB_VFS_OP_SYS_ACL_GET_FD,
201 SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE,
202 SMB_VFS_OP_SYS_ACL_BLOB_GET_FD,
203 SMB_VFS_OP_SYS_ACL_SET_FD,
204 SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE,
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_READDIR_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_GET_ALLOC_SIZE, "get_alloc_size" },
282 { SMB_VFS_OP_UNLINKAT, "unlinkat" },
283 { SMB_VFS_OP_FCHMOD, "fchmod" },
284 { SMB_VFS_OP_FCHOWN, "fchown" },
285 { SMB_VFS_OP_LCHOWN, "lchown" },
286 { SMB_VFS_OP_CHDIR, "chdir" },
287 { SMB_VFS_OP_GETWD, "getwd" },
288 { SMB_VFS_OP_NTIMES, "ntimes" },
289 { SMB_VFS_OP_FNTIMES, "fntimes" },
290 { SMB_VFS_OP_FTRUNCATE, "ftruncate" },
291 { SMB_VFS_OP_FALLOCATE,"fallocate" },
292 { SMB_VFS_OP_LOCK, "lock" },
293 { SMB_VFS_OP_KERNEL_FLOCK, "kernel_flock" },
294 { SMB_VFS_OP_FCNTL, "fcntl" },
295 { SMB_VFS_OP_LINUX_SETLEASE, "linux_setlease" },
296 { SMB_VFS_OP_GETLOCK, "getlock" },
297 { SMB_VFS_OP_SYMLINKAT, "symlinkat" },
298 { SMB_VFS_OP_READLINKAT,"readlinkat" },
299 { SMB_VFS_OP_LINKAT, "linkat" },
300 { SMB_VFS_OP_MKNODAT, "mknodat" },
301 { SMB_VFS_OP_REALPATH, "realpath" },
302 { SMB_VFS_OP_CHFLAGS, "chflags" },
303 { SMB_VFS_OP_FILE_ID_CREATE, "file_id_create" },
304 { SMB_VFS_OP_FS_FILE_ID, "fs_file_id" },
305 { SMB_VFS_OP_STREAMINFO, "streaminfo" },
306 { SMB_VFS_OP_GET_REAL_FILENAME, "get_real_filename" },
307 { SMB_VFS_OP_CONNECTPATH, "connectpath" },
308 { SMB_VFS_OP_BRL_LOCK_WINDOWS, "brl_lock_windows" },
309 { SMB_VFS_OP_BRL_UNLOCK_WINDOWS, "brl_unlock_windows" },
310 { SMB_VFS_OP_STRICT_LOCK_CHECK, "strict_lock_check" },
311 { SMB_VFS_OP_TRANSLATE_NAME, "translate_name" },
312 { SMB_VFS_OP_FSCTL, "fsctl" },
313 { SMB_VFS_OP_OFFLOAD_READ_SEND, "offload_read_send" },
314 { SMB_VFS_OP_OFFLOAD_READ_RECV, "offload_read_recv" },
315 { SMB_VFS_OP_OFFLOAD_WRITE_SEND, "offload_write_send" },
316 { SMB_VFS_OP_OFFLOAD_WRITE_RECV, "offload_write_recv" },
317 { SMB_VFS_OP_FGET_COMPRESSION, "fget_compression" },
318 { SMB_VFS_OP_SET_COMPRESSION, "set_compression" },
319 { SMB_VFS_OP_SNAP_CHECK_PATH, "snap_check_path" },
320 { SMB_VFS_OP_SNAP_CREATE, "snap_create" },
321 { SMB_VFS_OP_SNAP_DELETE, "snap_delete" },
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_FSET_DOS_ATTRIBUTES, "fset_dos_attributes" },
326 { SMB_VFS_OP_FGET_NT_ACL, "fget_nt_acl" },
327 { SMB_VFS_OP_GET_NT_ACL_AT, "get_nt_acl_at" },
328 { SMB_VFS_OP_FSET_NT_ACL, "fset_nt_acl" },
329 { SMB_VFS_OP_AUDIT_FILE, "audit_file" },
330 { SMB_VFS_OP_SYS_ACL_GET_FILE, "sys_acl_get_file" },
331 { SMB_VFS_OP_SYS_ACL_GET_FD, "sys_acl_get_fd" },
332 { SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE, "sys_acl_blob_get_file" },
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_FILE, "sys_acl_delete_def_file" },
336 { SMB_VFS_OP_GETXATTR, "getxattr" },
337 { SMB_VFS_OP_GETXATTRAT_SEND, "getxattrat_send" },
338 { SMB_VFS_OP_GETXATTRAT_RECV, "getxattrat_recv" },
339 { SMB_VFS_OP_FGETXATTR, "fgetxattr" },
340 { SMB_VFS_OP_FLISTXATTR, "flistxattr" },
341 { SMB_VFS_OP_REMOVEXATTR, "removexattr" },
342 { SMB_VFS_OP_FREMOVEXATTR, "fremovexattr" },
343 { SMB_VFS_OP_FSETXATTR, "fsetxattr" },
344 { SMB_VFS_OP_AIO_FORCE, "aio_force" },
345 { SMB_VFS_OP_IS_OFFLINE, "is_offline" },
346 { SMB_VFS_OP_SET_OFFLINE, "set_offline" },
347 { SMB_VFS_OP_DURABLE_COOKIE, "durable_cookie" },
348 { SMB_VFS_OP_DURABLE_DISCONNECT, "durable_disconnect" },
349 { SMB_VFS_OP_DURABLE_RECONNECT, "durable_reconnect" },
350 { SMB_VFS_OP_READDIR_ATTR, "readdir_attr" },
351 { SMB_VFS_OP_LAST, NULL }
354 static int audit_syslog_facility(vfs_handle_struct *handle)
356 static const struct enum_list enum_log_facilities[] = {
358 { LOG_AUTH, "AUTH" },
361 { LOG_AUTHPRIV, "AUTHPRIV" },
364 { LOG_AUDIT, "AUDIT" },
367 { LOG_CONSOLE, "CONSOLE" },
370 { LOG_CRON, "CRON" },
373 { LOG_DAEMON, "DAEMON" },
379 { LOG_INSTALL, "INSTALL" },
382 { LOG_KERN, "KERN" },
385 { LOG_LAUNCHD, "LAUNCHD" },
388 { LOG_LFMT, "LFMT" },
394 { LOG_MAIL, "MAIL" },
397 { LOG_MEGASAFE, "MEGASAFE" },
400 { LOG_NETINFO, "NETINFO" },
403 { LOG_NEWS, "NEWS" },
405 #ifdef LOG_NFACILITIES
406 { LOG_NFACILITIES, "NFACILITIES" },
414 #ifdef LOG_REMOTEAUTH
415 { LOG_REMOTEAUTH, "REMOTEAUTH" },
418 { LOG_SECURITY, "SECURITY" },
421 { LOG_SYSLOG, "SYSLOG" },
424 { LOG_USER, "USER" },
427 { LOG_UUCP, "UUCP" },
429 { LOG_LOCAL0, "LOCAL0" },
430 { LOG_LOCAL1, "LOCAL1" },
431 { LOG_LOCAL2, "LOCAL2" },
432 { LOG_LOCAL3, "LOCAL3" },
433 { LOG_LOCAL4, "LOCAL4" },
434 { LOG_LOCAL5, "LOCAL5" },
435 { LOG_LOCAL6, "LOCAL6" },
436 { LOG_LOCAL7, "LOCAL7" },
442 facility = lp_parm_enum(SNUM(handle->conn), "full_audit", "facility", enum_log_facilities, LOG_USER);
447 static int audit_syslog_priority(vfs_handle_struct *handle)
449 static const struct enum_list enum_log_priorities[] = {
450 { LOG_EMERG, "EMERG" },
451 { LOG_ALERT, "ALERT" },
452 { LOG_CRIT, "CRIT" },
454 { LOG_WARNING, "WARNING" },
455 { LOG_NOTICE, "NOTICE" },
456 { LOG_INFO, "INFO" },
457 { LOG_DEBUG, "DEBUG" },
463 priority = lp_parm_enum(SNUM(handle->conn), "full_audit", "priority",
464 enum_log_priorities, LOG_NOTICE);
465 if (priority == -1) {
466 priority = LOG_WARNING;
472 static char *audit_prefix(TALLOC_CTX *ctx, connection_struct *conn)
474 const struct loadparm_substitution *lp_sub =
475 loadparm_s3_global_substitution();
479 prefix = talloc_strdup(ctx,
480 lp_parm_const_string(SNUM(conn), "full_audit",
485 result = talloc_sub_full(ctx,
486 lp_servicename(talloc_tos(), lp_sub, SNUM(conn)),
487 conn->session_info->unix_info->unix_name,
489 conn->session_info->unix_token->gid,
490 conn->session_info->unix_info->sanitized_username,
491 conn->session_info->info->domain_name,
497 static bool log_success(struct vfs_full_audit_private_data *pd, vfs_op_type op)
499 if (pd->success_ops == NULL) {
503 return bitmap_query(pd->success_ops, op);
506 static bool log_failure(struct vfs_full_audit_private_data *pd, vfs_op_type op)
508 if (pd->failure_ops == NULL)
511 return bitmap_query(pd->failure_ops, op);
514 static struct bitmap *init_bitmap(TALLOC_CTX *mem_ctx, const char **ops)
522 bm = bitmap_talloc(mem_ctx, SMB_VFS_OP_LAST);
524 DEBUG(0, ("Could not alloc bitmap -- "
525 "defaulting to logging everything\n"));
529 for (; *ops != NULL; ops += 1) {
534 if (strequal(*ops, "all")) {
535 for (i=0; i<SMB_VFS_OP_LAST; i++) {
541 if (strequal(*ops, "none")) {
551 for (i=0; i<SMB_VFS_OP_LAST; i++) {
552 if ((vfs_op_names[i].name == NULL)
553 || (vfs_op_names[i].type != i)) {
554 smb_panic("vfs_full_audit.c: name table not "
555 "in sync with vfs_op_type enums\n");
557 if (strequal(op, vfs_op_names[i].name)) {
566 if (i == SMB_VFS_OP_LAST) {
567 DEBUG(0, ("Could not find opname %s, logging all\n",
576 static const char *audit_opname(vfs_op_type op)
578 if (op >= SMB_VFS_OP_LAST)
579 return "INVALID VFS OP";
580 return vfs_op_names[op].name;
583 static TALLOC_CTX *tmp_do_log_ctx;
585 * Get us a temporary talloc context usable just for DEBUG arguments
587 static TALLOC_CTX *do_log_ctx(void)
589 if (tmp_do_log_ctx == NULL) {
590 tmp_do_log_ctx = talloc_named_const(NULL, 0, "do_log_ctx");
592 return tmp_do_log_ctx;
595 static void do_log(vfs_op_type op, bool success, vfs_handle_struct *handle,
596 const char *format, ...) PRINTF_ATTRIBUTE(4, 5);
598 static void do_log(vfs_op_type op, bool success, vfs_handle_struct *handle,
599 const char *format, ...)
601 struct vfs_full_audit_private_data *pd;
603 char *audit_pre = NULL;
607 SMB_VFS_HANDLE_GET_DATA(handle, pd,
608 struct vfs_full_audit_private_data,
611 if (success && (!log_success(pd, op)))
614 if (!success && (!log_failure(pd, op)))
618 fstrcpy(err_msg, "ok");
620 fstr_sprintf(err_msg, "fail (%s)", strerror(errno));
622 va_start(ap, format);
623 op_msg = talloc_vasprintf(talloc_tos(), format, ap);
630 audit_pre = audit_prefix(talloc_tos(), handle->conn);
636 * Specify the facility to interoperate with other syslog
637 * callers (smbd for example).
639 priority = pd->syslog_priority | pd->syslog_facility;
641 syslog(priority, "%s|%s|%s|%s\n",
642 audit_pre ? audit_pre : "",
643 audit_opname(op), err_msg, op_msg);
645 DEBUG(1, ("%s|%s|%s|%s\n",
646 audit_pre ? audit_pre : "",
647 audit_opname(op), err_msg, op_msg));
650 TALLOC_FREE(audit_pre);
652 TALLOC_FREE(tmp_do_log_ctx);
656 * Return a string using the do_log_ctx()
658 static const char *smb_fname_str_do_log(struct connection_struct *conn,
659 const struct smb_filename *smb_fname)
664 if (smb_fname == NULL) {
668 if (smb_fname->base_name[0] != '/') {
669 char *abs_name = NULL;
670 struct smb_filename *fname_copy = cp_smb_filename(
673 if (fname_copy == NULL) {
677 if (!ISDOT(smb_fname->base_name)) {
678 abs_name = talloc_asprintf(do_log_ctx(),
680 conn->cwd_fsp->fsp_name->base_name,
681 smb_fname->base_name);
683 abs_name = talloc_strdup(do_log_ctx(),
684 conn->cwd_fsp->fsp_name->base_name);
686 if (abs_name == NULL) {
689 fname_copy->base_name = abs_name;
690 smb_fname = fname_copy;
693 status = get_full_smb_filename(do_log_ctx(), smb_fname, &fname);
694 if (!NT_STATUS_IS_OK(status)) {
701 * Return an fsp debug string using the do_log_ctx()
703 static const char *fsp_str_do_log(const struct files_struct *fsp)
705 return smb_fname_str_do_log(fsp->conn, fsp->fsp_name);
708 /* Implementation of vfs_ops. Pass everything on to the default
709 operation but log event first. */
711 static int smb_full_audit_connect(vfs_handle_struct *handle,
712 const char *svc, const char *user)
715 const char *none[] = { "none" };
716 struct vfs_full_audit_private_data *pd = NULL;
718 result = SMB_VFS_NEXT_CONNECT(handle, svc, user);
723 pd = talloc_zero(handle, struct vfs_full_audit_private_data);
725 SMB_VFS_NEXT_DISCONNECT(handle);
729 pd->syslog_facility = audit_syslog_facility(handle);
730 if (pd->syslog_facility == -1) {
731 DEBUG(1, ("%s: Unknown facility %s\n", __func__,
732 lp_parm_const_string(SNUM(handle->conn),
733 "full_audit", "facility",
735 SMB_VFS_NEXT_DISCONNECT(handle);
739 pd->syslog_priority = audit_syslog_priority(handle);
741 pd->log_secdesc = lp_parm_bool(SNUM(handle->conn),
742 "full_audit", "log_secdesc", false);
744 pd->do_syslog = lp_parm_bool(SNUM(handle->conn),
745 "full_audit", "syslog", true);
749 openlog("smbd_audit", 0, pd->syslog_facility);
753 pd->success_ops = init_bitmap(
754 pd, lp_parm_string_list(SNUM(handle->conn), "full_audit",
756 pd->failure_ops = init_bitmap(
757 pd, lp_parm_string_list(SNUM(handle->conn), "full_audit",
760 /* Store the private data. */
761 SMB_VFS_HANDLE_SET_DATA(handle, pd, NULL,
762 struct vfs_full_audit_private_data, return -1);
764 do_log(SMB_VFS_OP_CONNECT, True, handle,
770 static void smb_full_audit_disconnect(vfs_handle_struct *handle)
772 const struct loadparm_substitution *lp_sub =
773 loadparm_s3_global_substitution();
775 SMB_VFS_NEXT_DISCONNECT(handle);
777 do_log(SMB_VFS_OP_DISCONNECT, True, handle,
778 "%s", lp_servicename(talloc_tos(), lp_sub, SNUM(handle->conn)));
780 /* The bitmaps will be disconnected when the private
784 static uint64_t smb_full_audit_disk_free(vfs_handle_struct *handle,
785 const struct smb_filename *smb_fname,
792 result = SMB_VFS_NEXT_DISK_FREE(handle, smb_fname, bsize, dfree, dsize);
794 /* Don't have a reasonable notion of failure here */
796 do_log(SMB_VFS_OP_DISK_FREE,
800 smb_fname_str_do_log(handle->conn, smb_fname));
805 static int smb_full_audit_get_quota(struct vfs_handle_struct *handle,
806 const struct smb_filename *smb_fname,
807 enum SMB_QUOTA_TYPE qtype,
813 result = SMB_VFS_NEXT_GET_QUOTA(handle, smb_fname, qtype, id, qt);
815 do_log(SMB_VFS_OP_GET_QUOTA,
819 smb_fname_str_do_log(handle->conn, smb_fname));
824 static int smb_full_audit_set_quota(struct vfs_handle_struct *handle,
825 enum SMB_QUOTA_TYPE qtype, unid_t id,
830 result = SMB_VFS_NEXT_SET_QUOTA(handle, qtype, id, qt);
832 do_log(SMB_VFS_OP_SET_QUOTA, (result >= 0), handle, "");
837 static int smb_full_audit_get_shadow_copy_data(struct vfs_handle_struct *handle,
838 struct files_struct *fsp,
839 struct shadow_copy_data *shadow_copy_data,
844 result = SMB_VFS_NEXT_GET_SHADOW_COPY_DATA(handle, fsp, shadow_copy_data, labels);
846 do_log(SMB_VFS_OP_GET_SHADOW_COPY_DATA, (result >= 0), handle, "");
851 static int smb_full_audit_statvfs(struct vfs_handle_struct *handle,
852 const struct smb_filename *smb_fname,
853 struct vfs_statvfs_struct *statbuf)
857 result = SMB_VFS_NEXT_STATVFS(handle, smb_fname, statbuf);
859 do_log(SMB_VFS_OP_STATVFS, (result >= 0), handle, "");
864 static uint32_t smb_full_audit_fs_capabilities(struct vfs_handle_struct *handle, enum timestamp_set_resolution *p_ts_res)
868 result = SMB_VFS_NEXT_FS_CAPABILITIES(handle, p_ts_res);
870 do_log(SMB_VFS_OP_FS_CAPABILITIES, true, handle, "");
875 static NTSTATUS smb_full_audit_get_dfs_referrals(
876 struct vfs_handle_struct *handle,
877 struct dfs_GetDFSReferral *r)
881 status = SMB_VFS_NEXT_GET_DFS_REFERRALS(handle, r);
883 do_log(SMB_VFS_OP_GET_DFS_REFERRALS, NT_STATUS_IS_OK(status),
889 static NTSTATUS smb_full_audit_create_dfs_pathat(struct vfs_handle_struct *handle,
890 struct files_struct *dirfsp,
891 const struct smb_filename *smb_fname,
892 const struct referral *reflist,
893 size_t referral_count)
896 struct smb_filename *full_fname = NULL;
898 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
901 if (full_fname == NULL) {
902 return NT_STATUS_NO_MEMORY;
905 status = SMB_VFS_NEXT_CREATE_DFS_PATHAT(handle,
911 do_log(SMB_VFS_OP_CREATE_DFS_PATHAT,
912 NT_STATUS_IS_OK(status),
915 smb_fname_str_do_log(handle->conn, full_fname));
917 TALLOC_FREE(full_fname);
921 static NTSTATUS smb_full_audit_read_dfs_pathat(struct vfs_handle_struct *handle,
923 struct files_struct *dirfsp,
924 struct smb_filename *smb_fname,
925 struct referral **ppreflist,
926 size_t *preferral_count)
930 status = SMB_VFS_NEXT_READ_DFS_PATHAT(handle,
937 do_log(SMB_VFS_OP_READ_DFS_PATHAT,
938 NT_STATUS_IS_OK(status),
941 smb_fname_str_do_log(handle->conn, smb_fname));
946 static NTSTATUS smb_full_audit_snap_check_path(struct vfs_handle_struct *handle,
948 const char *service_path,
953 status = SMB_VFS_NEXT_SNAP_CHECK_PATH(handle, mem_ctx, service_path,
955 do_log(SMB_VFS_OP_SNAP_CHECK_PATH, NT_STATUS_IS_OK(status),
961 static NTSTATUS smb_full_audit_snap_create(struct vfs_handle_struct *handle,
963 const char *base_volume,
971 status = SMB_VFS_NEXT_SNAP_CREATE(handle, mem_ctx, base_volume, tstamp,
972 rw, base_path, snap_path);
973 do_log(SMB_VFS_OP_SNAP_CREATE, NT_STATUS_IS_OK(status), handle, "");
978 static NTSTATUS smb_full_audit_snap_delete(struct vfs_handle_struct *handle,
985 status = SMB_VFS_NEXT_SNAP_DELETE(handle, mem_ctx, base_path,
987 do_log(SMB_VFS_OP_SNAP_DELETE, NT_STATUS_IS_OK(status), handle, "");
992 static DIR *smb_full_audit_fdopendir(vfs_handle_struct *handle,
993 files_struct *fsp, const char *mask, uint32_t attr)
997 result = SMB_VFS_NEXT_FDOPENDIR(handle, fsp, mask, attr);
999 do_log(SMB_VFS_OP_FDOPENDIR, (result != NULL), handle, "%s",
1000 fsp_str_do_log(fsp));
1005 static struct dirent *smb_full_audit_readdir(vfs_handle_struct *handle,
1006 struct files_struct *dirfsp,
1008 SMB_STRUCT_STAT *sbuf)
1010 struct dirent *result;
1012 result = SMB_VFS_NEXT_READDIR(handle, dirfsp, dirp, sbuf);
1014 /* This operation has no reasonable error condition
1015 * (End of dir is also failure), so always succeed.
1017 do_log(SMB_VFS_OP_READDIR, True, handle, "");
1022 static void smb_full_audit_seekdir(vfs_handle_struct *handle,
1023 DIR *dirp, long offset)
1025 SMB_VFS_NEXT_SEEKDIR(handle, dirp, offset);
1027 do_log(SMB_VFS_OP_SEEKDIR, True, handle, "");
1030 static long smb_full_audit_telldir(vfs_handle_struct *handle,
1035 result = SMB_VFS_NEXT_TELLDIR(handle, dirp);
1037 do_log(SMB_VFS_OP_TELLDIR, True, handle, "");
1042 static void smb_full_audit_rewinddir(vfs_handle_struct *handle,
1045 SMB_VFS_NEXT_REWINDDIR(handle, dirp);
1047 do_log(SMB_VFS_OP_REWINDDIR, True, handle, "");
1050 static int smb_full_audit_mkdirat(vfs_handle_struct *handle,
1051 struct files_struct *dirfsp,
1052 const struct smb_filename *smb_fname,
1055 struct smb_filename *full_fname = NULL;
1058 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1061 if (full_fname == NULL) {
1066 result = SMB_VFS_NEXT_MKDIRAT(handle,
1071 do_log(SMB_VFS_OP_MKDIRAT,
1075 smb_fname_str_do_log(handle->conn, full_fname));
1077 TALLOC_FREE(full_fname);
1082 static int smb_full_audit_closedir(vfs_handle_struct *handle,
1087 result = SMB_VFS_NEXT_CLOSEDIR(handle, dirp);
1089 do_log(SMB_VFS_OP_CLOSEDIR, (result >= 0), handle, "");
1094 static int smb_full_audit_openat(vfs_handle_struct *handle,
1095 const struct files_struct *dirfsp,
1096 const struct smb_filename *smb_fname,
1097 struct files_struct *fsp,
1103 result = SMB_VFS_NEXT_OPENAT(handle, dirfsp, smb_fname, fsp, flags, mode);
1105 do_log(SMB_VFS_OP_OPENAT, (result >= 0), handle, "%s|%s",
1106 ((flags & O_WRONLY) || (flags & O_RDWR))?"w":"r",
1107 fsp_str_do_log(fsp));
1112 static NTSTATUS smb_full_audit_create_file(vfs_handle_struct *handle,
1113 struct smb_request *req,
1114 struct smb_filename *smb_fname,
1115 uint32_t access_mask,
1116 uint32_t share_access,
1117 uint32_t create_disposition,
1118 uint32_t create_options,
1119 uint32_t file_attributes,
1120 uint32_t oplock_request,
1121 const struct smb2_lease *lease,
1122 uint64_t allocation_size,
1123 uint32_t private_flags,
1124 struct security_descriptor *sd,
1125 struct ea_list *ea_list,
1126 files_struct **result_fsp,
1128 const struct smb2_create_blobs *in_context_blobs,
1129 struct smb2_create_blobs *out_context_blobs)
1132 const char* str_create_disposition;
1134 switch (create_disposition) {
1135 case FILE_SUPERSEDE:
1136 str_create_disposition = "supersede";
1138 case FILE_OVERWRITE_IF:
1139 str_create_disposition = "overwrite_if";
1142 str_create_disposition = "open";
1144 case FILE_OVERWRITE:
1145 str_create_disposition = "overwrite";
1148 str_create_disposition = "create";
1151 str_create_disposition = "open_if";
1154 str_create_disposition = "unknown";
1157 result = SMB_VFS_NEXT_CREATE_FILE(
1158 handle, /* handle */
1160 smb_fname, /* fname */
1161 access_mask, /* access_mask */
1162 share_access, /* share_access */
1163 create_disposition, /* create_disposition*/
1164 create_options, /* create_options */
1165 file_attributes, /* file_attributes */
1166 oplock_request, /* oplock_request */
1168 allocation_size, /* allocation_size */
1171 ea_list, /* ea_list */
1172 result_fsp, /* result */
1174 in_context_blobs, out_context_blobs); /* create context */
1176 do_log(SMB_VFS_OP_CREATE_FILE, (NT_STATUS_IS_OK(result)), handle,
1177 "0x%x|%s|%s|%s", access_mask,
1178 create_options & FILE_DIRECTORY_FILE ? "dir" : "file",
1179 str_create_disposition,
1180 smb_fname_str_do_log(handle->conn, smb_fname));
1185 static int smb_full_audit_close(vfs_handle_struct *handle, files_struct *fsp)
1189 result = SMB_VFS_NEXT_CLOSE(handle, fsp);
1191 do_log(SMB_VFS_OP_CLOSE, (result >= 0), handle, "%s",
1192 fsp_str_do_log(fsp));
1197 static ssize_t smb_full_audit_pread(vfs_handle_struct *handle, files_struct *fsp,
1198 void *data, size_t n, off_t offset)
1202 result = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
1204 do_log(SMB_VFS_OP_PREAD, (result >= 0), handle, "%s",
1205 fsp_str_do_log(fsp));
1210 struct smb_full_audit_pread_state {
1211 vfs_handle_struct *handle;
1214 struct vfs_aio_state vfs_aio_state;
1217 static void smb_full_audit_pread_done(struct tevent_req *subreq);
1219 static struct tevent_req *smb_full_audit_pread_send(
1220 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1221 struct tevent_context *ev, struct files_struct *fsp,
1222 void *data, size_t n, off_t offset)
1224 struct tevent_req *req, *subreq;
1225 struct smb_full_audit_pread_state *state;
1227 req = tevent_req_create(mem_ctx, &state,
1228 struct smb_full_audit_pread_state);
1230 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
1231 fsp_str_do_log(fsp));
1234 state->handle = handle;
1237 subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
1239 if (tevent_req_nomem(subreq, req)) {
1240 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
1241 fsp_str_do_log(fsp));
1242 return tevent_req_post(req, ev);
1244 tevent_req_set_callback(subreq, smb_full_audit_pread_done, req);
1246 do_log(SMB_VFS_OP_PREAD_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1250 static void smb_full_audit_pread_done(struct tevent_req *subreq)
1252 struct tevent_req *req = tevent_req_callback_data(
1253 subreq, struct tevent_req);
1254 struct smb_full_audit_pread_state *state = tevent_req_data(
1255 req, struct smb_full_audit_pread_state);
1257 state->ret = SMB_VFS_PREAD_RECV(subreq, &state->vfs_aio_state);
1258 TALLOC_FREE(subreq);
1259 tevent_req_done(req);
1262 static ssize_t smb_full_audit_pread_recv(struct tevent_req *req,
1263 struct vfs_aio_state *vfs_aio_state)
1265 struct smb_full_audit_pread_state *state = tevent_req_data(
1266 req, struct smb_full_audit_pread_state);
1268 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1269 do_log(SMB_VFS_OP_PREAD_RECV, false, state->handle, "%s",
1270 fsp_str_do_log(state->fsp));
1274 do_log(SMB_VFS_OP_PREAD_RECV, (state->ret >= 0), state->handle, "%s",
1275 fsp_str_do_log(state->fsp));
1277 *vfs_aio_state = state->vfs_aio_state;
1281 static ssize_t smb_full_audit_pwrite(vfs_handle_struct *handle, files_struct *fsp,
1282 const void *data, size_t n,
1287 result = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
1289 do_log(SMB_VFS_OP_PWRITE, (result >= 0), handle, "%s",
1290 fsp_str_do_log(fsp));
1295 struct smb_full_audit_pwrite_state {
1296 vfs_handle_struct *handle;
1299 struct vfs_aio_state vfs_aio_state;
1302 static void smb_full_audit_pwrite_done(struct tevent_req *subreq);
1304 static struct tevent_req *smb_full_audit_pwrite_send(
1305 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1306 struct tevent_context *ev, struct files_struct *fsp,
1307 const void *data, size_t n, off_t offset)
1309 struct tevent_req *req, *subreq;
1310 struct smb_full_audit_pwrite_state *state;
1312 req = tevent_req_create(mem_ctx, &state,
1313 struct smb_full_audit_pwrite_state);
1315 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1316 fsp_str_do_log(fsp));
1319 state->handle = handle;
1322 subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
1324 if (tevent_req_nomem(subreq, req)) {
1325 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1326 fsp_str_do_log(fsp));
1327 return tevent_req_post(req, ev);
1329 tevent_req_set_callback(subreq, smb_full_audit_pwrite_done, req);
1331 do_log(SMB_VFS_OP_PWRITE_SEND, true, handle, "%s",
1332 fsp_str_do_log(fsp));
1336 static void smb_full_audit_pwrite_done(struct tevent_req *subreq)
1338 struct tevent_req *req = tevent_req_callback_data(
1339 subreq, struct tevent_req);
1340 struct smb_full_audit_pwrite_state *state = tevent_req_data(
1341 req, struct smb_full_audit_pwrite_state);
1343 state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->vfs_aio_state);
1344 TALLOC_FREE(subreq);
1345 tevent_req_done(req);
1348 static ssize_t smb_full_audit_pwrite_recv(struct tevent_req *req,
1349 struct vfs_aio_state *vfs_aio_state)
1351 struct smb_full_audit_pwrite_state *state = tevent_req_data(
1352 req, struct smb_full_audit_pwrite_state);
1354 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1355 do_log(SMB_VFS_OP_PWRITE_RECV, false, state->handle, "%s",
1356 fsp_str_do_log(state->fsp));
1360 do_log(SMB_VFS_OP_PWRITE_RECV, (state->ret >= 0), state->handle, "%s",
1361 fsp_str_do_log(state->fsp));
1363 *vfs_aio_state = state->vfs_aio_state;
1367 static off_t smb_full_audit_lseek(vfs_handle_struct *handle, files_struct *fsp,
1368 off_t offset, int whence)
1372 result = SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence);
1374 do_log(SMB_VFS_OP_LSEEK, (result != (ssize_t)-1), handle,
1375 "%s", fsp_str_do_log(fsp));
1380 static ssize_t smb_full_audit_sendfile(vfs_handle_struct *handle, int tofd,
1381 files_struct *fromfsp,
1382 const DATA_BLOB *hdr, off_t offset,
1387 result = SMB_VFS_NEXT_SENDFILE(handle, tofd, fromfsp, hdr, offset, n);
1389 do_log(SMB_VFS_OP_SENDFILE, (result >= 0), handle,
1390 "%s", fsp_str_do_log(fromfsp));
1395 static ssize_t smb_full_audit_recvfile(vfs_handle_struct *handle, int fromfd,
1396 files_struct *tofsp,
1402 result = SMB_VFS_NEXT_RECVFILE(handle, fromfd, tofsp, offset, n);
1404 do_log(SMB_VFS_OP_RECVFILE, (result >= 0), handle,
1405 "%s", fsp_str_do_log(tofsp));
1410 static int smb_full_audit_renameat(vfs_handle_struct *handle,
1411 files_struct *srcfsp,
1412 const struct smb_filename *smb_fname_src,
1413 files_struct *dstfsp,
1414 const struct smb_filename *smb_fname_dst)
1418 result = SMB_VFS_NEXT_RENAMEAT(handle,
1424 do_log(SMB_VFS_OP_RENAMEAT, (result >= 0), handle, "%s|%s",
1425 smb_fname_str_do_log(handle->conn, smb_fname_src),
1426 smb_fname_str_do_log(handle->conn, smb_fname_dst));
1431 struct smb_full_audit_fsync_state {
1432 vfs_handle_struct *handle;
1435 struct vfs_aio_state vfs_aio_state;
1438 static void smb_full_audit_fsync_done(struct tevent_req *subreq);
1440 static struct tevent_req *smb_full_audit_fsync_send(
1441 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1442 struct tevent_context *ev, struct files_struct *fsp)
1444 struct tevent_req *req, *subreq;
1445 struct smb_full_audit_fsync_state *state;
1447 req = tevent_req_create(mem_ctx, &state,
1448 struct smb_full_audit_fsync_state);
1450 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1451 fsp_str_do_log(fsp));
1454 state->handle = handle;
1457 subreq = SMB_VFS_NEXT_FSYNC_SEND(state, ev, handle, fsp);
1458 if (tevent_req_nomem(subreq, req)) {
1459 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1460 fsp_str_do_log(fsp));
1461 return tevent_req_post(req, ev);
1463 tevent_req_set_callback(subreq, smb_full_audit_fsync_done, req);
1465 do_log(SMB_VFS_OP_FSYNC_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1469 static void smb_full_audit_fsync_done(struct tevent_req *subreq)
1471 struct tevent_req *req = tevent_req_callback_data(
1472 subreq, struct tevent_req);
1473 struct smb_full_audit_fsync_state *state = tevent_req_data(
1474 req, struct smb_full_audit_fsync_state);
1476 state->ret = SMB_VFS_FSYNC_RECV(subreq, &state->vfs_aio_state);
1477 TALLOC_FREE(subreq);
1478 tevent_req_done(req);
1481 static int smb_full_audit_fsync_recv(struct tevent_req *req,
1482 struct vfs_aio_state *vfs_aio_state)
1484 struct smb_full_audit_fsync_state *state = tevent_req_data(
1485 req, struct smb_full_audit_fsync_state);
1487 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1488 do_log(SMB_VFS_OP_FSYNC_RECV, false, state->handle, "%s",
1489 fsp_str_do_log(state->fsp));
1493 do_log(SMB_VFS_OP_FSYNC_RECV, (state->ret >= 0), state->handle, "%s",
1494 fsp_str_do_log(state->fsp));
1496 *vfs_aio_state = state->vfs_aio_state;
1500 static int smb_full_audit_stat(vfs_handle_struct *handle,
1501 struct smb_filename *smb_fname)
1505 result = SMB_VFS_NEXT_STAT(handle, smb_fname);
1507 do_log(SMB_VFS_OP_STAT, (result >= 0), handle, "%s",
1508 smb_fname_str_do_log(handle->conn, smb_fname));
1513 static int smb_full_audit_fstat(vfs_handle_struct *handle, files_struct *fsp,
1514 SMB_STRUCT_STAT *sbuf)
1518 result = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1520 do_log(SMB_VFS_OP_FSTAT, (result >= 0), handle, "%s",
1521 fsp_str_do_log(fsp));
1526 static int smb_full_audit_lstat(vfs_handle_struct *handle,
1527 struct smb_filename *smb_fname)
1531 result = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
1533 do_log(SMB_VFS_OP_LSTAT, (result >= 0), handle, "%s",
1534 smb_fname_str_do_log(handle->conn, smb_fname));
1539 static uint64_t smb_full_audit_get_alloc_size(vfs_handle_struct *handle,
1540 files_struct *fsp, const SMB_STRUCT_STAT *sbuf)
1544 result = SMB_VFS_NEXT_GET_ALLOC_SIZE(handle, fsp, sbuf);
1546 do_log(SMB_VFS_OP_GET_ALLOC_SIZE, (result != (uint64_t)-1), handle,
1547 "%llu", (unsigned long long)result);
1552 static int smb_full_audit_unlinkat(vfs_handle_struct *handle,
1553 struct files_struct *dirfsp,
1554 const struct smb_filename *smb_fname,
1557 struct smb_filename *full_fname = NULL;
1560 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1563 if (full_fname == NULL) {
1567 result = SMB_VFS_NEXT_UNLINKAT(handle,
1572 do_log(SMB_VFS_OP_UNLINKAT, (result >= 0), handle, "%s",
1573 smb_fname_str_do_log(handle->conn, full_fname));
1575 TALLOC_FREE(full_fname);
1579 static int smb_full_audit_fchmod(vfs_handle_struct *handle, files_struct *fsp,
1584 result = SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1586 do_log(SMB_VFS_OP_FCHMOD, (result >= 0), handle,
1587 "%s|%o", fsp_str_do_log(fsp), mode);
1592 static int smb_full_audit_fchown(vfs_handle_struct *handle, files_struct *fsp,
1593 uid_t uid, gid_t gid)
1597 result = SMB_VFS_NEXT_FCHOWN(handle, fsp, uid, gid);
1599 do_log(SMB_VFS_OP_FCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1600 fsp_str_do_log(fsp), (long int)uid, (long int)gid);
1605 static int smb_full_audit_lchown(vfs_handle_struct *handle,
1606 const struct smb_filename *smb_fname,
1612 result = SMB_VFS_NEXT_LCHOWN(handle, smb_fname, uid, gid);
1614 do_log(SMB_VFS_OP_LCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1615 smb_fname->base_name, (long int)uid, (long int)gid);
1620 static int smb_full_audit_chdir(vfs_handle_struct *handle,
1621 const struct smb_filename *smb_fname)
1625 result = SMB_VFS_NEXT_CHDIR(handle, smb_fname);
1627 do_log(SMB_VFS_OP_CHDIR,
1631 smb_fname_str_do_log(handle->conn, smb_fname));
1636 static struct smb_filename *smb_full_audit_getwd(vfs_handle_struct *handle,
1639 struct smb_filename *result;
1641 result = SMB_VFS_NEXT_GETWD(handle, ctx);
1643 do_log(SMB_VFS_OP_GETWD, (result != NULL), handle, "%s",
1644 result == NULL? "" : result->base_name);
1649 static int smb_full_audit_fntimes(vfs_handle_struct *handle,
1651 struct smb_file_time *ft)
1654 time_t create_time = convert_timespec_to_time_t(ft->create_time);
1655 time_t atime = convert_timespec_to_time_t(ft->atime);
1656 time_t mtime = convert_timespec_to_time_t(ft->mtime);
1657 time_t ctime = convert_timespec_to_time_t(ft->ctime);
1658 const char *create_time_str = "";
1659 const char *atime_str = "";
1660 const char *mtime_str = "";
1661 const char *ctime_str = "";
1662 TALLOC_CTX *frame = talloc_stackframe();
1664 if (frame == NULL) {
1669 result = SMB_VFS_NEXT_FNTIMES(handle, fsp, ft);
1671 if (create_time > 0) {
1672 create_time_str = timestring(frame, create_time);
1675 atime_str = timestring(frame, atime);
1678 mtime_str = timestring(frame, mtime);
1681 ctime_str = timestring(frame, ctime);
1684 do_log(SMB_VFS_OP_FNTIMES,
1688 fsp_str_do_log(fsp),
1699 static int smb_full_audit_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
1704 result = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1706 do_log(SMB_VFS_OP_FTRUNCATE, (result >= 0), handle,
1707 "%s", fsp_str_do_log(fsp));
1712 static int smb_full_audit_fallocate(vfs_handle_struct *handle, files_struct *fsp,
1719 result = SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
1721 do_log(SMB_VFS_OP_FALLOCATE, (result >= 0), handle,
1722 "%s", fsp_str_do_log(fsp));
1727 static bool smb_full_audit_lock(vfs_handle_struct *handle, files_struct *fsp,
1728 int op, off_t offset, off_t count, int type)
1732 result = SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type);
1734 do_log(SMB_VFS_OP_LOCK, result, handle, "%s", fsp_str_do_log(fsp));
1739 static int smb_full_audit_kernel_flock(struct vfs_handle_struct *handle,
1740 struct files_struct *fsp,
1741 uint32_t share_access,
1742 uint32_t access_mask)
1746 result = SMB_VFS_NEXT_KERNEL_FLOCK(handle,
1751 do_log(SMB_VFS_OP_KERNEL_FLOCK, (result >= 0), handle, "%s",
1752 fsp_str_do_log(fsp));
1757 static int smb_full_audit_fcntl(struct vfs_handle_struct *handle,
1758 struct files_struct *fsp,
1759 int cmd, va_list cmd_arg)
1762 va_list dup_cmd_arg;
1765 va_copy(dup_cmd_arg, cmd_arg);
1766 arg = va_arg(dup_cmd_arg, void *);
1767 result = SMB_VFS_NEXT_FCNTL(handle, fsp, cmd, arg);
1768 va_end(dup_cmd_arg);
1770 do_log(SMB_VFS_OP_FCNTL, (result >= 0), handle, "%s",
1771 fsp_str_do_log(fsp));
1776 static int smb_full_audit_linux_setlease(vfs_handle_struct *handle, files_struct *fsp,
1781 result = SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
1783 do_log(SMB_VFS_OP_LINUX_SETLEASE, (result >= 0), handle, "%s",
1784 fsp_str_do_log(fsp));
1789 static bool smb_full_audit_getlock(vfs_handle_struct *handle, files_struct *fsp,
1790 off_t *poffset, off_t *pcount, int *ptype, pid_t *ppid)
1794 result = SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype, ppid);
1796 do_log(SMB_VFS_OP_GETLOCK, result, handle, "%s", fsp_str_do_log(fsp));
1801 static int smb_full_audit_symlinkat(vfs_handle_struct *handle,
1802 const struct smb_filename *link_contents,
1803 struct files_struct *dirfsp,
1804 const struct smb_filename *new_smb_fname)
1806 struct smb_filename *full_fname = NULL;
1809 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1812 if (full_fname == NULL) {
1816 result = SMB_VFS_NEXT_SYMLINKAT(handle,
1821 do_log(SMB_VFS_OP_SYMLINKAT,
1825 link_contents->base_name,
1826 smb_fname_str_do_log(handle->conn, full_fname));
1828 TALLOC_FREE(full_fname);
1833 static int smb_full_audit_readlinkat(vfs_handle_struct *handle,
1834 const struct files_struct *dirfsp,
1835 const struct smb_filename *smb_fname,
1839 struct smb_filename *full_fname = NULL;
1842 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1845 if (full_fname == NULL) {
1849 result = SMB_VFS_NEXT_READLINKAT(handle,
1855 do_log(SMB_VFS_OP_READLINKAT,
1859 smb_fname_str_do_log(handle->conn, full_fname));
1861 TALLOC_FREE(full_fname);
1866 static int smb_full_audit_linkat(vfs_handle_struct *handle,
1867 files_struct *srcfsp,
1868 const struct smb_filename *old_smb_fname,
1869 files_struct *dstfsp,
1870 const struct smb_filename *new_smb_fname,
1873 struct smb_filename *old_full_fname = NULL;
1874 struct smb_filename *new_full_fname = NULL;
1877 old_full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1880 if (old_full_fname == NULL) {
1883 new_full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1886 if (new_full_fname == NULL) {
1887 TALLOC_FREE(old_full_fname);
1890 result = SMB_VFS_NEXT_LINKAT(handle,
1897 do_log(SMB_VFS_OP_LINKAT,
1901 smb_fname_str_do_log(handle->conn, old_full_fname),
1902 smb_fname_str_do_log(handle->conn, new_full_fname));
1904 TALLOC_FREE(old_full_fname);
1905 TALLOC_FREE(new_full_fname);
1910 static int smb_full_audit_mknodat(vfs_handle_struct *handle,
1911 files_struct *dirfsp,
1912 const struct smb_filename *smb_fname,
1916 struct smb_filename *full_fname = NULL;
1919 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1922 if (full_fname == NULL) {
1926 result = SMB_VFS_NEXT_MKNODAT(handle,
1932 do_log(SMB_VFS_OP_MKNODAT,
1936 smb_fname_str_do_log(handle->conn, full_fname));
1938 TALLOC_FREE(full_fname);
1943 static struct smb_filename *smb_full_audit_realpath(vfs_handle_struct *handle,
1945 const struct smb_filename *smb_fname)
1947 struct smb_filename *result_fname = NULL;
1949 result_fname = SMB_VFS_NEXT_REALPATH(handle, ctx, smb_fname);
1951 do_log(SMB_VFS_OP_REALPATH,
1952 (result_fname != NULL),
1955 smb_fname_str_do_log(handle->conn, smb_fname));
1957 return result_fname;
1960 static int smb_full_audit_chflags(vfs_handle_struct *handle,
1961 const struct smb_filename *smb_fname,
1966 result = SMB_VFS_NEXT_CHFLAGS(handle, smb_fname, flags);
1968 do_log(SMB_VFS_OP_CHFLAGS,
1972 smb_fname_str_do_log(handle->conn, smb_fname));
1977 static struct file_id smb_full_audit_file_id_create(struct vfs_handle_struct *handle,
1978 const SMB_STRUCT_STAT *sbuf)
1980 struct file_id id_zero = { 0 };
1981 struct file_id result;
1982 struct file_id_buf idbuf;
1984 result = SMB_VFS_NEXT_FILE_ID_CREATE(handle, sbuf);
1986 do_log(SMB_VFS_OP_FILE_ID_CREATE,
1987 !file_id_equal(&id_zero, &result),
1990 file_id_str_buf(result, &idbuf));
1995 static uint64_t smb_full_audit_fs_file_id(struct vfs_handle_struct *handle,
1996 const SMB_STRUCT_STAT *sbuf)
2000 result = SMB_VFS_NEXT_FS_FILE_ID(handle, sbuf);
2002 do_log(SMB_VFS_OP_FS_FILE_ID,
2004 handle, "%" PRIu64, result);
2009 static NTSTATUS smb_full_audit_streaminfo(vfs_handle_struct *handle,
2010 struct files_struct *fsp,
2011 const struct smb_filename *smb_fname,
2012 TALLOC_CTX *mem_ctx,
2013 unsigned int *pnum_streams,
2014 struct stream_struct **pstreams)
2018 result = SMB_VFS_NEXT_STREAMINFO(handle, fsp, smb_fname, mem_ctx,
2019 pnum_streams, pstreams);
2021 do_log(SMB_VFS_OP_STREAMINFO,
2022 NT_STATUS_IS_OK(result),
2025 smb_fname_str_do_log(handle->conn, smb_fname));
2030 static int smb_full_audit_get_real_filename(struct vfs_handle_struct *handle,
2031 const struct smb_filename *path,
2033 TALLOC_CTX *mem_ctx,
2038 result = SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name, mem_ctx,
2041 do_log(SMB_VFS_OP_GET_REAL_FILENAME, (result == 0), handle,
2043 path->base_name, name, (result == 0) ? *found_name : "");
2048 static const char *smb_full_audit_connectpath(vfs_handle_struct *handle,
2049 const struct smb_filename *smb_fname)
2053 result = SMB_VFS_NEXT_CONNECTPATH(handle, smb_fname);
2055 do_log(SMB_VFS_OP_CONNECTPATH,
2059 smb_fname_str_do_log(handle->conn, smb_fname));
2064 static NTSTATUS smb_full_audit_brl_lock_windows(struct vfs_handle_struct *handle,
2065 struct byte_range_lock *br_lck,
2066 struct lock_struct *plock)
2070 result = SMB_VFS_NEXT_BRL_LOCK_WINDOWS(handle, br_lck, plock);
2072 do_log(SMB_VFS_OP_BRL_LOCK_WINDOWS, NT_STATUS_IS_OK(result), handle,
2073 "%s:%llu-%llu. type=%d.",
2074 fsp_str_do_log(brl_fsp(br_lck)),
2075 (unsigned long long)plock->start,
2076 (unsigned long long)plock->size,
2082 static bool smb_full_audit_brl_unlock_windows(struct vfs_handle_struct *handle,
2083 struct byte_range_lock *br_lck,
2084 const struct lock_struct *plock)
2088 result = SMB_VFS_NEXT_BRL_UNLOCK_WINDOWS(handle, br_lck, plock);
2090 do_log(SMB_VFS_OP_BRL_UNLOCK_WINDOWS, (result == 0), handle,
2091 "%s:%llu-%llu:%d", fsp_str_do_log(brl_fsp(br_lck)),
2092 (unsigned long long)plock->start,
2093 (unsigned long long)plock->size,
2099 static bool smb_full_audit_strict_lock_check(struct vfs_handle_struct *handle,
2100 struct files_struct *fsp,
2101 struct lock_struct *plock)
2105 result = SMB_VFS_NEXT_STRICT_LOCK_CHECK(handle, fsp, plock);
2107 do_log(SMB_VFS_OP_STRICT_LOCK_CHECK, result, handle,
2108 "%s:%llu-%llu:%d", fsp_str_do_log(fsp),
2109 (unsigned long long)plock->start,
2110 (unsigned long long)plock->size,
2116 static NTSTATUS smb_full_audit_translate_name(struct vfs_handle_struct *handle,
2118 enum vfs_translate_direction direction,
2119 TALLOC_CTX *mem_ctx,
2124 result = SMB_VFS_NEXT_TRANSLATE_NAME(handle, name, direction, mem_ctx,
2127 do_log(SMB_VFS_OP_TRANSLATE_NAME, NT_STATUS_IS_OK(result), handle, "");
2132 static NTSTATUS smb_full_audit_fsctl(struct vfs_handle_struct *handle,
2133 struct files_struct *fsp,
2137 const uint8_t *_in_data,
2139 uint8_t **_out_data,
2140 uint32_t max_out_len,
2145 result = SMB_VFS_NEXT_FSCTL(handle,
2156 do_log(SMB_VFS_OP_FSCTL, NT_STATUS_IS_OK(result), handle, "");
2161 static struct tevent_req *smb_full_audit_offload_read_send(
2162 TALLOC_CTX *mem_ctx,
2163 struct tevent_context *ev,
2164 struct vfs_handle_struct *handle,
2165 struct files_struct *fsp,
2171 struct tevent_req *req = NULL;
2173 req = SMB_VFS_NEXT_OFFLOAD_READ_SEND(mem_ctx, ev, handle, fsp,
2174 fsctl, ttl, offset, to_copy);
2176 do_log(SMB_VFS_OP_OFFLOAD_READ_SEND, req, handle, "");
2181 static NTSTATUS smb_full_audit_offload_read_recv(
2182 struct tevent_req *req,
2183 struct vfs_handle_struct *handle,
2184 TALLOC_CTX *mem_ctx,
2185 DATA_BLOB *_token_blob)
2189 status = SMB_VFS_NEXT_OFFLOAD_READ_RECV(req, handle, mem_ctx,
2192 do_log(SMB_VFS_OP_OFFLOAD_READ_RECV, NT_STATUS_IS_OK(status), handle, "");
2197 static struct tevent_req *smb_full_audit_offload_write_send(struct vfs_handle_struct *handle,
2198 TALLOC_CTX *mem_ctx,
2199 struct tevent_context *ev,
2202 off_t transfer_offset,
2203 struct files_struct *dest_fsp,
2207 struct tevent_req *req;
2209 req = SMB_VFS_NEXT_OFFLOAD_WRITE_SEND(handle, mem_ctx, ev,
2210 fsctl, token, transfer_offset,
2211 dest_fsp, dest_off, num);
2213 do_log(SMB_VFS_OP_OFFLOAD_WRITE_SEND, req, handle, "");
2218 static NTSTATUS smb_full_audit_offload_write_recv(struct vfs_handle_struct *handle,
2219 struct tevent_req *req,
2224 result = SMB_VFS_NEXT_OFFLOAD_WRITE_RECV(handle, req, copied);
2226 do_log(SMB_VFS_OP_OFFLOAD_WRITE_RECV, NT_STATUS_IS_OK(result), handle, "");
2231 static NTSTATUS smb_full_audit_fget_compression(vfs_handle_struct *handle,
2232 TALLOC_CTX *mem_ctx,
2233 struct files_struct *fsp,
2234 uint16_t *_compression_fmt)
2238 result = SMB_VFS_NEXT_FGET_COMPRESSION(handle, mem_ctx, fsp,
2241 do_log(SMB_VFS_OP_FGET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
2243 fsp_str_do_log(fsp));
2248 static NTSTATUS smb_full_audit_set_compression(vfs_handle_struct *handle,
2249 TALLOC_CTX *mem_ctx,
2250 struct files_struct *fsp,
2251 uint16_t compression_fmt)
2255 result = SMB_VFS_NEXT_SET_COMPRESSION(handle, mem_ctx, fsp,
2258 do_log(SMB_VFS_OP_SET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
2259 "%s", fsp_str_do_log(fsp));
2264 static NTSTATUS smb_full_audit_readdir_attr(struct vfs_handle_struct *handle,
2265 const struct smb_filename *fname,
2266 TALLOC_CTX *mem_ctx,
2267 struct readdir_attr_data **pattr_data)
2271 status = SMB_VFS_NEXT_READDIR_ATTR(handle, fname, mem_ctx, pattr_data);
2273 do_log(SMB_VFS_OP_READDIR_ATTR, NT_STATUS_IS_OK(status), handle, "%s",
2274 smb_fname_str_do_log(handle->conn, fname));
2279 struct smb_full_audit_get_dos_attributes_state {
2280 struct vfs_aio_state aio_state;
2281 vfs_handle_struct *handle;
2282 files_struct *dir_fsp;
2283 const struct smb_filename *smb_fname;
2287 static void smb_full_audit_get_dos_attributes_done(struct tevent_req *subreq);
2289 static struct tevent_req *smb_full_audit_get_dos_attributes_send(
2290 TALLOC_CTX *mem_ctx,
2291 struct tevent_context *ev,
2292 struct vfs_handle_struct *handle,
2293 files_struct *dir_fsp,
2294 struct smb_filename *smb_fname)
2296 struct tevent_req *req = NULL;
2297 struct smb_full_audit_get_dos_attributes_state *state = NULL;
2298 struct tevent_req *subreq = NULL;
2300 req = tevent_req_create(mem_ctx, &state,
2301 struct smb_full_audit_get_dos_attributes_state);
2303 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2307 fsp_str_do_log(dir_fsp),
2308 smb_fname->base_name);
2311 *state = (struct smb_full_audit_get_dos_attributes_state) {
2314 .smb_fname = smb_fname,
2317 subreq = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES_SEND(mem_ctx,
2322 if (tevent_req_nomem(subreq, req)) {
2323 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2327 fsp_str_do_log(dir_fsp),
2328 smb_fname->base_name);
2329 return tevent_req_post(req, ev);
2331 tevent_req_set_callback(subreq,
2332 smb_full_audit_get_dos_attributes_done,
2335 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2339 fsp_str_do_log(dir_fsp),
2340 smb_fname->base_name);
2345 static void smb_full_audit_get_dos_attributes_done(struct tevent_req *subreq)
2347 struct tevent_req *req =
2348 tevent_req_callback_data(subreq,
2350 struct smb_full_audit_get_dos_attributes_state *state =
2351 tevent_req_data(req,
2352 struct smb_full_audit_get_dos_attributes_state);
2355 status = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES_RECV(subreq,
2358 TALLOC_FREE(subreq);
2359 if (tevent_req_nterror(req, status)) {
2363 tevent_req_done(req);
2367 static NTSTATUS smb_full_audit_get_dos_attributes_recv(struct tevent_req *req,
2368 struct vfs_aio_state *aio_state,
2371 struct smb_full_audit_get_dos_attributes_state *state =
2372 tevent_req_data(req,
2373 struct smb_full_audit_get_dos_attributes_state);
2376 if (tevent_req_is_nterror(req, &status)) {
2377 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV,
2381 fsp_str_do_log(state->dir_fsp),
2382 state->smb_fname->base_name);
2383 tevent_req_received(req);
2387 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV,
2391 fsp_str_do_log(state->dir_fsp),
2392 state->smb_fname->base_name);
2394 *aio_state = state->aio_state;
2395 *dosmode = state->dosmode;
2396 tevent_req_received(req);
2397 return NT_STATUS_OK;
2400 static NTSTATUS smb_full_audit_fget_dos_attributes(
2401 struct vfs_handle_struct *handle,
2402 struct files_struct *fsp,
2407 status = SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle,
2411 do_log(SMB_VFS_OP_FGET_DOS_ATTRIBUTES,
2412 NT_STATUS_IS_OK(status),
2415 fsp_str_do_log(fsp));
2420 static NTSTATUS smb_full_audit_fset_dos_attributes(
2421 struct vfs_handle_struct *handle,
2422 struct files_struct *fsp,
2427 status = SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle,
2431 do_log(SMB_VFS_OP_FSET_DOS_ATTRIBUTES,
2432 NT_STATUS_IS_OK(status),
2435 fsp_str_do_log(fsp));
2440 static NTSTATUS smb_full_audit_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
2441 uint32_t security_info,
2442 TALLOC_CTX *mem_ctx,
2443 struct security_descriptor **ppdesc)
2447 result = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
2450 do_log(SMB_VFS_OP_FGET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2451 "%s", fsp_str_do_log(fsp));
2456 static NTSTATUS smb_full_audit_get_nt_acl_at(vfs_handle_struct *handle,
2457 struct files_struct *dirfsp,
2458 const struct smb_filename *smb_fname,
2459 uint32_t security_info,
2460 TALLOC_CTX *mem_ctx,
2461 struct security_descriptor **ppdesc)
2465 result = SMB_VFS_NEXT_GET_NT_ACL_AT(handle,
2472 do_log(SMB_VFS_OP_GET_NT_ACL_AT,
2473 NT_STATUS_IS_OK(result),
2476 smb_fname_str_do_log(handle->conn, smb_fname));
2481 static NTSTATUS smb_full_audit_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
2482 uint32_t security_info_sent,
2483 const struct security_descriptor *psd)
2485 struct vfs_full_audit_private_data *pd;
2489 SMB_VFS_HANDLE_GET_DATA(handle, pd,
2490 struct vfs_full_audit_private_data,
2491 return NT_STATUS_INTERNAL_ERROR);
2493 if (pd->log_secdesc) {
2494 sd = sddl_encode(talloc_tos(), psd, get_global_sam_sid());
2497 result = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
2499 do_log(SMB_VFS_OP_FSET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2500 "%s [%s]", fsp_str_do_log(fsp), sd ? sd : "");
2507 static NTSTATUS smb_full_audit_audit_file(struct vfs_handle_struct *handle,
2508 struct smb_filename *file,
2509 struct security_acl *sacl,
2510 uint32_t access_requested,
2511 uint32_t access_denied)
2515 result = SMB_VFS_NEXT_AUDIT_FILE(handle,
2521 do_log(SMB_VFS_OP_AUDIT_FILE, NT_STATUS_IS_OK(result), handle,
2523 smb_fname_str_do_log(handle->conn, file));
2528 static SMB_ACL_T smb_full_audit_sys_acl_get_file(vfs_handle_struct *handle,
2529 const struct smb_filename *smb_fname,
2530 SMB_ACL_TYPE_T type,
2531 TALLOC_CTX *mem_ctx)
2535 result = SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, smb_fname,
2538 do_log(SMB_VFS_OP_SYS_ACL_GET_FILE,
2542 smb_fname_str_do_log(handle->conn, smb_fname));
2547 static SMB_ACL_T smb_full_audit_sys_acl_get_fd(vfs_handle_struct *handle,
2548 files_struct *fsp, TALLOC_CTX *mem_ctx)
2552 result = SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp, mem_ctx);
2554 do_log(SMB_VFS_OP_SYS_ACL_GET_FD, (result != NULL), handle,
2555 "%s", fsp_str_do_log(fsp));
2560 static int smb_full_audit_sys_acl_blob_get_file(vfs_handle_struct *handle,
2561 const struct smb_filename *smb_fname,
2562 TALLOC_CTX *mem_ctx,
2563 char **blob_description,
2568 result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FILE(handle, smb_fname,
2569 mem_ctx, blob_description, blob);
2571 do_log(SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE,
2575 smb_fname_str_do_log(handle->conn, smb_fname));
2580 static int smb_full_audit_sys_acl_blob_get_fd(vfs_handle_struct *handle,
2582 TALLOC_CTX *mem_ctx,
2583 char **blob_description,
2588 result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle, fsp, mem_ctx, blob_description, blob);
2590 do_log(SMB_VFS_OP_SYS_ACL_BLOB_GET_FD, (result >= 0), handle,
2591 "%s", fsp_str_do_log(fsp));
2596 static int smb_full_audit_sys_acl_set_fd(vfs_handle_struct *handle,
2597 struct files_struct *fsp,
2598 SMB_ACL_TYPE_T type,
2603 result = SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, type, theacl);
2605 do_log(SMB_VFS_OP_SYS_ACL_SET_FD, (result >= 0), handle,
2606 "%s", fsp_str_do_log(fsp));
2611 static int smb_full_audit_sys_acl_delete_def_file(vfs_handle_struct *handle,
2612 const struct smb_filename *smb_fname)
2616 result = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, smb_fname);
2618 do_log(SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE,
2622 smb_fname_str_do_log(handle->conn, smb_fname));
2627 static ssize_t smb_full_audit_getxattr(struct vfs_handle_struct *handle,
2628 const struct smb_filename *smb_fname,
2629 const char *name, void *value, size_t size)
2633 result = SMB_VFS_NEXT_GETXATTR(handle, smb_fname, name, value, size);
2635 do_log(SMB_VFS_OP_GETXATTR,
2639 smb_fname_str_do_log(handle->conn, smb_fname),
2645 struct smb_full_audit_getxattrat_state {
2646 struct vfs_aio_state aio_state;
2647 vfs_handle_struct *handle;
2648 files_struct *dir_fsp;
2649 const struct smb_filename *smb_fname;
2650 const char *xattr_name;
2652 uint8_t *xattr_value;
2655 static void smb_full_audit_getxattrat_done(struct tevent_req *subreq);
2657 static struct tevent_req *smb_full_audit_getxattrat_send(
2658 TALLOC_CTX *mem_ctx,
2659 struct tevent_context *ev,
2660 struct vfs_handle_struct *handle,
2661 files_struct *dir_fsp,
2662 const struct smb_filename *smb_fname,
2663 const char *xattr_name,
2666 struct tevent_req *req = NULL;
2667 struct tevent_req *subreq = NULL;
2668 struct smb_full_audit_getxattrat_state *state = NULL;
2670 req = tevent_req_create(mem_ctx, &state,
2671 struct smb_full_audit_getxattrat_state);
2673 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2677 fsp_str_do_log(dir_fsp),
2678 smb_fname->base_name,
2682 *state = (struct smb_full_audit_getxattrat_state) {
2685 .smb_fname = smb_fname,
2686 .xattr_name = xattr_name,
2689 subreq = SMB_VFS_NEXT_GETXATTRAT_SEND(state,
2696 if (tevent_req_nomem(subreq, req)) {
2697 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2701 fsp_str_do_log(dir_fsp),
2702 smb_fname->base_name,
2704 return tevent_req_post(req, ev);
2706 tevent_req_set_callback(subreq, smb_full_audit_getxattrat_done, req);
2708 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2712 fsp_str_do_log(dir_fsp),
2713 smb_fname->base_name,
2719 static void smb_full_audit_getxattrat_done(struct tevent_req *subreq)
2721 struct tevent_req *req = tevent_req_callback_data(
2722 subreq, struct tevent_req);
2723 struct smb_full_audit_getxattrat_state *state = tevent_req_data(
2724 req, struct smb_full_audit_getxattrat_state);
2726 state->xattr_size = SMB_VFS_NEXT_GETXATTRAT_RECV(subreq,
2729 &state->xattr_value);
2730 TALLOC_FREE(subreq);
2731 if (state->xattr_size == -1) {
2732 tevent_req_error(req, state->aio_state.error);
2736 tevent_req_done(req);
2739 static ssize_t smb_full_audit_getxattrat_recv(struct tevent_req *req,
2740 struct vfs_aio_state *aio_state,
2741 TALLOC_CTX *mem_ctx,
2742 uint8_t **xattr_value)
2744 struct smb_full_audit_getxattrat_state *state = tevent_req_data(
2745 req, struct smb_full_audit_getxattrat_state);
2748 if (tevent_req_is_unix_error(req, &aio_state->error)) {
2749 do_log(SMB_VFS_OP_GETXATTRAT_RECV,
2753 fsp_str_do_log(state->dir_fsp),
2754 state->smb_fname->base_name,
2756 tevent_req_received(req);
2760 do_log(SMB_VFS_OP_GETXATTRAT_RECV,
2764 fsp_str_do_log(state->dir_fsp),
2765 state->smb_fname->base_name,
2768 *aio_state = state->aio_state;
2769 xattr_size = state->xattr_size;
2770 if (xattr_value != NULL) {
2771 *xattr_value = talloc_move(mem_ctx, &state->xattr_value);
2774 tevent_req_received(req);
2778 static ssize_t smb_full_audit_fgetxattr(struct vfs_handle_struct *handle,
2779 struct files_struct *fsp,
2780 const char *name, void *value, size_t size)
2784 result = SMB_VFS_NEXT_FGETXATTR(handle, fsp, name, value, size);
2786 do_log(SMB_VFS_OP_FGETXATTR, (result >= 0), handle,
2787 "%s|%s", fsp_str_do_log(fsp), name);
2792 static ssize_t smb_full_audit_flistxattr(struct vfs_handle_struct *handle,
2793 struct files_struct *fsp, char *list,
2798 result = SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
2800 do_log(SMB_VFS_OP_FLISTXATTR, (result >= 0), handle,
2801 "%s", fsp_str_do_log(fsp));
2806 static int smb_full_audit_fremovexattr(struct vfs_handle_struct *handle,
2807 struct files_struct *fsp,
2812 result = SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, name);
2814 do_log(SMB_VFS_OP_FREMOVEXATTR, (result >= 0), handle,
2815 "%s|%s", fsp_str_do_log(fsp), name);
2820 static int smb_full_audit_fsetxattr(struct vfs_handle_struct *handle,
2821 struct files_struct *fsp, const char *name,
2822 const void *value, size_t size, int flags)
2826 result = SMB_VFS_NEXT_FSETXATTR(handle, fsp, name, value, size, flags);
2828 do_log(SMB_VFS_OP_FSETXATTR, (result >= 0), handle,
2829 "%s|%s", fsp_str_do_log(fsp), name);
2834 static bool smb_full_audit_aio_force(struct vfs_handle_struct *handle,
2835 struct files_struct *fsp)
2839 result = SMB_VFS_NEXT_AIO_FORCE(handle, fsp);
2840 do_log(SMB_VFS_OP_AIO_FORCE, result, handle,
2841 "%s", fsp_str_do_log(fsp));
2846 static NTSTATUS smb_full_audit_durable_cookie(struct vfs_handle_struct *handle,
2847 struct files_struct *fsp,
2848 TALLOC_CTX *mem_ctx,
2853 result = SMB_VFS_NEXT_DURABLE_COOKIE(handle,
2858 do_log(SMB_VFS_OP_DURABLE_COOKIE, NT_STATUS_IS_OK(result), handle,
2859 "%s", fsp_str_do_log(fsp));
2864 static NTSTATUS smb_full_audit_durable_disconnect(
2865 struct vfs_handle_struct *handle,
2866 struct files_struct *fsp,
2867 const DATA_BLOB old_cookie,
2868 TALLOC_CTX *mem_ctx,
2869 DATA_BLOB *new_cookie)
2873 result = SMB_VFS_NEXT_DURABLE_DISCONNECT(handle,
2879 do_log(SMB_VFS_OP_DURABLE_DISCONNECT, NT_STATUS_IS_OK(result), handle,
2880 "%s", fsp_str_do_log(fsp));
2885 static NTSTATUS smb_full_audit_durable_reconnect(
2886 struct vfs_handle_struct *handle,
2887 struct smb_request *smb1req,
2888 struct smbXsrv_open *op,
2889 const DATA_BLOB old_cookie,
2890 TALLOC_CTX *mem_ctx,
2891 struct files_struct **fsp,
2892 DATA_BLOB *new_cookie)
2896 result = SMB_VFS_NEXT_DURABLE_RECONNECT(handle,
2904 do_log(SMB_VFS_OP_DURABLE_RECONNECT,
2905 NT_STATUS_IS_OK(result),
2912 static struct vfs_fn_pointers vfs_full_audit_fns = {
2914 /* Disk operations */
2916 .connect_fn = smb_full_audit_connect,
2917 .disconnect_fn = smb_full_audit_disconnect,
2918 .disk_free_fn = smb_full_audit_disk_free,
2919 .get_quota_fn = smb_full_audit_get_quota,
2920 .set_quota_fn = smb_full_audit_set_quota,
2921 .get_shadow_copy_data_fn = smb_full_audit_get_shadow_copy_data,
2922 .statvfs_fn = smb_full_audit_statvfs,
2923 .fs_capabilities_fn = smb_full_audit_fs_capabilities,
2924 .get_dfs_referrals_fn = smb_full_audit_get_dfs_referrals,
2925 .create_dfs_pathat_fn = smb_full_audit_create_dfs_pathat,
2926 .read_dfs_pathat_fn = smb_full_audit_read_dfs_pathat,
2927 .fdopendir_fn = smb_full_audit_fdopendir,
2928 .readdir_fn = smb_full_audit_readdir,
2929 .seekdir_fn = smb_full_audit_seekdir,
2930 .telldir_fn = smb_full_audit_telldir,
2931 .rewind_dir_fn = smb_full_audit_rewinddir,
2932 .mkdirat_fn = smb_full_audit_mkdirat,
2933 .closedir_fn = smb_full_audit_closedir,
2934 .openat_fn = smb_full_audit_openat,
2935 .create_file_fn = smb_full_audit_create_file,
2936 .close_fn = smb_full_audit_close,
2937 .pread_fn = smb_full_audit_pread,
2938 .pread_send_fn = smb_full_audit_pread_send,
2939 .pread_recv_fn = smb_full_audit_pread_recv,
2940 .pwrite_fn = smb_full_audit_pwrite,
2941 .pwrite_send_fn = smb_full_audit_pwrite_send,
2942 .pwrite_recv_fn = smb_full_audit_pwrite_recv,
2943 .lseek_fn = smb_full_audit_lseek,
2944 .sendfile_fn = smb_full_audit_sendfile,
2945 .recvfile_fn = smb_full_audit_recvfile,
2946 .renameat_fn = smb_full_audit_renameat,
2947 .fsync_send_fn = smb_full_audit_fsync_send,
2948 .fsync_recv_fn = smb_full_audit_fsync_recv,
2949 .stat_fn = smb_full_audit_stat,
2950 .fstat_fn = smb_full_audit_fstat,
2951 .lstat_fn = smb_full_audit_lstat,
2952 .get_alloc_size_fn = smb_full_audit_get_alloc_size,
2953 .unlinkat_fn = smb_full_audit_unlinkat,
2954 .fchmod_fn = smb_full_audit_fchmod,
2955 .fchown_fn = smb_full_audit_fchown,
2956 .lchown_fn = smb_full_audit_lchown,
2957 .chdir_fn = smb_full_audit_chdir,
2958 .getwd_fn = smb_full_audit_getwd,
2959 .fntimes_fn = smb_full_audit_fntimes,
2960 .ftruncate_fn = smb_full_audit_ftruncate,
2961 .fallocate_fn = smb_full_audit_fallocate,
2962 .lock_fn = smb_full_audit_lock,
2963 .kernel_flock_fn = smb_full_audit_kernel_flock,
2964 .fcntl_fn = smb_full_audit_fcntl,
2965 .linux_setlease_fn = smb_full_audit_linux_setlease,
2966 .getlock_fn = smb_full_audit_getlock,
2967 .symlinkat_fn = smb_full_audit_symlinkat,
2968 .readlinkat_fn = smb_full_audit_readlinkat,
2969 .linkat_fn = smb_full_audit_linkat,
2970 .mknodat_fn = smb_full_audit_mknodat,
2971 .realpath_fn = smb_full_audit_realpath,
2972 .chflags_fn = smb_full_audit_chflags,
2973 .file_id_create_fn = smb_full_audit_file_id_create,
2974 .fs_file_id_fn = smb_full_audit_fs_file_id,
2975 .offload_read_send_fn = smb_full_audit_offload_read_send,
2976 .offload_read_recv_fn = smb_full_audit_offload_read_recv,
2977 .offload_write_send_fn = smb_full_audit_offload_write_send,
2978 .offload_write_recv_fn = smb_full_audit_offload_write_recv,
2979 .fget_compression_fn = smb_full_audit_fget_compression,
2980 .set_compression_fn = smb_full_audit_set_compression,
2981 .snap_check_path_fn = smb_full_audit_snap_check_path,
2982 .snap_create_fn = smb_full_audit_snap_create,
2983 .snap_delete_fn = smb_full_audit_snap_delete,
2984 .streaminfo_fn = smb_full_audit_streaminfo,
2985 .get_real_filename_fn = smb_full_audit_get_real_filename,
2986 .connectpath_fn = smb_full_audit_connectpath,
2987 .brl_lock_windows_fn = smb_full_audit_brl_lock_windows,
2988 .brl_unlock_windows_fn = smb_full_audit_brl_unlock_windows,
2989 .strict_lock_check_fn = smb_full_audit_strict_lock_check,
2990 .translate_name_fn = smb_full_audit_translate_name,
2991 .fsctl_fn = smb_full_audit_fsctl,
2992 .get_dos_attributes_send_fn = smb_full_audit_get_dos_attributes_send,
2993 .get_dos_attributes_recv_fn = smb_full_audit_get_dos_attributes_recv,
2994 .fget_dos_attributes_fn = smb_full_audit_fget_dos_attributes,
2995 .fset_dos_attributes_fn = smb_full_audit_fset_dos_attributes,
2996 .fget_nt_acl_fn = smb_full_audit_fget_nt_acl,
2997 .get_nt_acl_at_fn = smb_full_audit_get_nt_acl_at,
2998 .fset_nt_acl_fn = smb_full_audit_fset_nt_acl,
2999 .audit_file_fn = smb_full_audit_audit_file,
3000 .sys_acl_get_file_fn = smb_full_audit_sys_acl_get_file,
3001 .sys_acl_get_fd_fn = smb_full_audit_sys_acl_get_fd,
3002 .sys_acl_blob_get_file_fn = smb_full_audit_sys_acl_blob_get_file,
3003 .sys_acl_blob_get_fd_fn = smb_full_audit_sys_acl_blob_get_fd,
3004 .sys_acl_set_fd_fn = smb_full_audit_sys_acl_set_fd,
3005 .sys_acl_delete_def_file_fn = smb_full_audit_sys_acl_delete_def_file,
3006 .getxattr_fn = smb_full_audit_getxattr,
3007 .getxattrat_send_fn = smb_full_audit_getxattrat_send,
3008 .getxattrat_recv_fn = smb_full_audit_getxattrat_recv,
3009 .fgetxattr_fn = smb_full_audit_fgetxattr,
3010 .flistxattr_fn = smb_full_audit_flistxattr,
3011 .fremovexattr_fn = smb_full_audit_fremovexattr,
3012 .fsetxattr_fn = smb_full_audit_fsetxattr,
3013 .aio_force_fn = smb_full_audit_aio_force,
3014 .durable_cookie_fn = smb_full_audit_durable_cookie,
3015 .durable_disconnect_fn = smb_full_audit_durable_disconnect,
3016 .durable_reconnect_fn = smb_full_audit_durable_reconnect,
3017 .readdir_attr_fn = smb_full_audit_readdir_attr
3022 NTSTATUS vfs_full_audit_init(TALLOC_CTX *ctx)
3026 smb_vfs_assert_all_fns(&vfs_full_audit_fns, "full_audit");
3028 ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "full_audit",
3029 &vfs_full_audit_fns);
3031 if (!NT_STATUS_IS_OK(ret))
3034 vfs_full_audit_debug_level = debug_add_class("full_audit");
3035 if (vfs_full_audit_debug_level == -1) {
3036 vfs_full_audit_debug_level = DBGC_VFS;
3037 DEBUG(0, ("vfs_full_audit: Couldn't register custom debugging "
3040 DEBUG(10, ("vfs_full_audit: Debug class number of "
3041 "'full_audit': %d\n", vfs_full_audit_debug_level));