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
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|.
42 * smbd_audit: nobody|192.168.234.1|open|fail (File not found)|r|x.txt
44 * where "nobody" is the connected username and "192.168.234.1" is the
45 * client's IP address.
49 * prefix: A macro expansion template prepended to the syslog entry.
51 * success: A list of VFS operations for which a successful completion should
52 * be logged. Defaults to no logging at all. The special operation "all" logs
53 * - you guessed it - everything.
55 * failure: A list of VFS operations for which failure to complete should be
56 * logged. Defaults to logging everything.
61 #include "system/filesys.h"
62 #include "system/syslog.h"
63 #include "smbd/smbd.h"
64 #include "../librpc/gen_ndr/ndr_netlogon.h"
67 #include "lib/param/loadparm.h"
68 #include "lib/util/bitmap.h"
69 #include "lib/util/tevent_unix.h"
70 #include "libcli/security/sddl.h"
71 #include "passdb/machine_sid.h"
72 #include "lib/util/tevent_ntstatus.h"
74 static int vfs_full_audit_debug_level = DBGC_VFS;
76 struct vfs_full_audit_private_data {
77 struct bitmap *success_ops;
78 struct bitmap *failure_ops;
86 #define DBGC_CLASS vfs_full_audit_debug_level
88 typedef enum _vfs_op_type {
93 SMB_VFS_OP_CONNECT = 0,
94 SMB_VFS_OP_DISCONNECT,
98 SMB_VFS_OP_GET_SHADOW_COPY_DATA,
100 SMB_VFS_OP_FS_CAPABILITIES,
101 SMB_VFS_OP_GET_DFS_REFERRALS,
103 /* Directory operations */
106 SMB_VFS_OP_FDOPENDIR,
110 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,
149 SMB_VFS_OP_FTRUNCATE,
150 SMB_VFS_OP_FALLOCATE,
152 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_MKDIR, "mkdir" },
259 { SMB_VFS_OP_MKDIRAT, "mkdirat" },
260 { SMB_VFS_OP_RMDIR, "rmdir" },
261 { SMB_VFS_OP_CLOSEDIR, "closedir" },
262 { SMB_VFS_OP_OPEN, "open" },
263 { SMB_VFS_OP_CREATE_FILE, "create_file" },
264 { SMB_VFS_OP_CLOSE, "close" },
265 { SMB_VFS_OP_READ, "read" },
266 { SMB_VFS_OP_PREAD, "pread" },
267 { SMB_VFS_OP_PREAD_SEND, "pread_send" },
268 { SMB_VFS_OP_PREAD_RECV, "pread_recv" },
269 { SMB_VFS_OP_WRITE, "write" },
270 { SMB_VFS_OP_PWRITE, "pwrite" },
271 { SMB_VFS_OP_PWRITE_SEND, "pwrite_send" },
272 { SMB_VFS_OP_PWRITE_RECV, "pwrite_recv" },
273 { SMB_VFS_OP_LSEEK, "lseek" },
274 { SMB_VFS_OP_SENDFILE, "sendfile" },
275 { SMB_VFS_OP_RECVFILE, "recvfile" },
276 { SMB_VFS_OP_RENAMEAT, "renameat" },
277 { SMB_VFS_OP_FSYNC, "fsync" },
278 { SMB_VFS_OP_FSYNC_SEND, "fsync_send" },
279 { SMB_VFS_OP_FSYNC_RECV, "fsync_recv" },
280 { SMB_VFS_OP_STAT, "stat" },
281 { SMB_VFS_OP_FSTAT, "fstat" },
282 { SMB_VFS_OP_LSTAT, "lstat" },
283 { SMB_VFS_OP_GET_ALLOC_SIZE, "get_alloc_size" },
284 { SMB_VFS_OP_UNLINK, "unlink" },
285 { SMB_VFS_OP_CHMOD, "chmod" },
286 { SMB_VFS_OP_FCHMOD, "fchmod" },
287 { SMB_VFS_OP_CHOWN, "chown" },
288 { SMB_VFS_OP_FCHOWN, "fchown" },
289 { SMB_VFS_OP_LCHOWN, "lchown" },
290 { SMB_VFS_OP_CHDIR, "chdir" },
291 { SMB_VFS_OP_GETWD, "getwd" },
292 { SMB_VFS_OP_NTIMES, "ntimes" },
293 { SMB_VFS_OP_FTRUNCATE, "ftruncate" },
294 { SMB_VFS_OP_FALLOCATE,"fallocate" },
295 { SMB_VFS_OP_LOCK, "lock" },
296 { SMB_VFS_OP_KERNEL_FLOCK, "kernel_flock" },
297 { SMB_VFS_OP_LINUX_SETLEASE, "linux_setlease" },
298 { SMB_VFS_OP_GETLOCK, "getlock" },
299 { SMB_VFS_OP_SYMLINKAT, "symlinkat" },
300 { SMB_VFS_OP_READLINKAT,"readlinkat" },
301 { SMB_VFS_OP_LINKAT, "linkat" },
302 { SMB_VFS_OP_MKNODAT, "mknodat" },
303 { SMB_VFS_OP_REALPATH, "realpath" },
304 { SMB_VFS_OP_CHFLAGS, "chflags" },
305 { SMB_VFS_OP_FILE_ID_CREATE, "file_id_create" },
306 { SMB_VFS_OP_FS_FILE_ID, "fs_file_id" },
307 { SMB_VFS_OP_STREAMINFO, "streaminfo" },
308 { SMB_VFS_OP_GET_REAL_FILENAME, "get_real_filename" },
309 { SMB_VFS_OP_CONNECTPATH, "connectpath" },
310 { SMB_VFS_OP_BRL_LOCK_WINDOWS, "brl_lock_windows" },
311 { SMB_VFS_OP_BRL_UNLOCK_WINDOWS, "brl_unlock_windows" },
312 { SMB_VFS_OP_STRICT_LOCK_CHECK, "strict_lock_check" },
313 { SMB_VFS_OP_TRANSLATE_NAME, "translate_name" },
314 { SMB_VFS_OP_FSCTL, "fsctl" },
315 { SMB_VFS_OP_OFFLOAD_READ_SEND, "offload_read_send" },
316 { SMB_VFS_OP_OFFLOAD_READ_RECV, "offload_read_recv" },
317 { SMB_VFS_OP_OFFLOAD_WRITE_SEND, "offload_write_send" },
318 { SMB_VFS_OP_OFFLOAD_WRITE_RECV, "offload_write_recv" },
319 { SMB_VFS_OP_GET_COMPRESSION, "get_compression" },
320 { SMB_VFS_OP_SET_COMPRESSION, "set_compression" },
321 { SMB_VFS_OP_SNAP_CHECK_PATH, "snap_check_path" },
322 { SMB_VFS_OP_SNAP_CREATE, "snap_create" },
323 { SMB_VFS_OP_SNAP_DELETE, "snap_delete" },
324 { SMB_VFS_OP_GET_DOS_ATTRIBUTES, "get_dos_attributes" },
325 { SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND, "get_dos_attributes_send" },
326 { SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV, "get_dos_attributes_recv" },
327 { SMB_VFS_OP_FGET_DOS_ATTRIBUTES, "fget_dos_attributes" },
328 { SMB_VFS_OP_SET_DOS_ATTRIBUTES, "set_dos_attributes" },
329 { SMB_VFS_OP_FSET_DOS_ATTRIBUTES, "fset_dos_attributes" },
330 { SMB_VFS_OP_FGET_NT_ACL, "fget_nt_acl" },
331 { SMB_VFS_OP_GET_NT_ACL, "get_nt_acl" },
332 { SMB_VFS_OP_FSET_NT_ACL, "fset_nt_acl" },
333 { SMB_VFS_OP_AUDIT_FILE, "audit_file" },
334 { SMB_VFS_OP_SYS_ACL_GET_FILE, "sys_acl_get_file" },
335 { SMB_VFS_OP_SYS_ACL_GET_FD, "sys_acl_get_fd" },
336 { SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE, "sys_acl_blob_get_file" },
337 { SMB_VFS_OP_SYS_ACL_BLOB_GET_FD, "sys_acl_blob_get_fd" },
338 { SMB_VFS_OP_SYS_ACL_SET_FILE, "sys_acl_set_file" },
339 { SMB_VFS_OP_SYS_ACL_SET_FD, "sys_acl_set_fd" },
340 { SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE, "sys_acl_delete_def_file" },
341 { SMB_VFS_OP_GETXATTR, "getxattr" },
342 { SMB_VFS_OP_GETXATTRAT_SEND, "getxattrat_send" },
343 { SMB_VFS_OP_GETXATTRAT_RECV, "getxattrat_recv" },
344 { SMB_VFS_OP_FGETXATTR, "fgetxattr" },
345 { SMB_VFS_OP_LISTXATTR, "listxattr" },
346 { SMB_VFS_OP_FLISTXATTR, "flistxattr" },
347 { SMB_VFS_OP_REMOVEXATTR, "removexattr" },
348 { SMB_VFS_OP_FREMOVEXATTR, "fremovexattr" },
349 { SMB_VFS_OP_SETXATTR, "setxattr" },
350 { SMB_VFS_OP_FSETXATTR, "fsetxattr" },
351 { SMB_VFS_OP_AIO_FORCE, "aio_force" },
352 { SMB_VFS_OP_IS_OFFLINE, "is_offline" },
353 { SMB_VFS_OP_SET_OFFLINE, "set_offline" },
354 { SMB_VFS_OP_DURABLE_COOKIE, "durable_cookie" },
355 { SMB_VFS_OP_DURABLE_DISCONNECT, "durable_disconnect" },
356 { SMB_VFS_OP_DURABLE_RECONNECT, "durable_reconnect" },
357 { SMB_VFS_OP_READDIR_ATTR, "readdir_attr" },
358 { SMB_VFS_OP_LAST, NULL }
361 static int audit_syslog_facility(vfs_handle_struct *handle)
363 static const struct enum_list enum_log_facilities[] = {
365 { LOG_AUTH, "AUTH" },
368 { LOG_AUTHPRIV, "AUTHPRIV" },
371 { LOG_AUDIT, "AUDIT" },
374 { LOG_CONSOLE, "CONSOLE" },
377 { LOG_CRON, "CRON" },
380 { LOG_DAEMON, "DAEMON" },
386 { LOG_INSTALL, "INSTALL" },
389 { LOG_KERN, "KERN" },
392 { LOG_LAUNCHD, "LAUNCHD" },
395 { LOG_LFMT, "LFMT" },
401 { LOG_MAIL, "MAIL" },
404 { LOG_MEGASAFE, "MEGASAFE" },
407 { LOG_NETINFO, "NETINFO" },
410 { LOG_NEWS, "NEWS" },
412 #ifdef LOG_NFACILITIES
413 { LOG_NFACILITIES, "NFACILITIES" },
421 #ifdef LOG_REMOTEAUTH
422 { LOG_REMOTEAUTH, "REMOTEAUTH" },
425 { LOG_SECURITY, "SECURITY" },
428 { LOG_SYSLOG, "SYSLOG" },
431 { LOG_USER, "USER" },
434 { LOG_UUCP, "UUCP" },
436 { LOG_LOCAL0, "LOCAL0" },
437 { LOG_LOCAL1, "LOCAL1" },
438 { LOG_LOCAL2, "LOCAL2" },
439 { LOG_LOCAL3, "LOCAL3" },
440 { LOG_LOCAL4, "LOCAL4" },
441 { LOG_LOCAL5, "LOCAL5" },
442 { LOG_LOCAL6, "LOCAL6" },
443 { LOG_LOCAL7, "LOCAL7" },
449 facility = lp_parm_enum(SNUM(handle->conn), "full_audit", "facility", enum_log_facilities, LOG_USER);
454 static int audit_syslog_priority(vfs_handle_struct *handle)
456 static const struct enum_list enum_log_priorities[] = {
457 { LOG_EMERG, "EMERG" },
458 { LOG_ALERT, "ALERT" },
459 { LOG_CRIT, "CRIT" },
461 { LOG_WARNING, "WARNING" },
462 { LOG_NOTICE, "NOTICE" },
463 { LOG_INFO, "INFO" },
464 { LOG_DEBUG, "DEBUG" },
470 priority = lp_parm_enum(SNUM(handle->conn), "full_audit", "priority",
471 enum_log_priorities, LOG_NOTICE);
472 if (priority == -1) {
473 priority = LOG_WARNING;
479 static char *audit_prefix(TALLOC_CTX *ctx, connection_struct *conn)
484 prefix = talloc_strdup(ctx,
485 lp_parm_const_string(SNUM(conn), "full_audit",
490 result = talloc_sub_advanced(ctx,
491 lp_servicename(talloc_tos(), SNUM(conn)),
492 conn->session_info->unix_info->unix_name,
494 conn->session_info->unix_token->gid,
495 conn->session_info->unix_info->sanitized_username,
496 conn->session_info->info->domain_name,
502 static bool log_success(struct vfs_full_audit_private_data *pd, vfs_op_type op)
504 if (pd->success_ops == NULL) {
508 return bitmap_query(pd->success_ops, op);
511 static bool log_failure(struct vfs_full_audit_private_data *pd, vfs_op_type op)
513 if (pd->failure_ops == NULL)
516 return bitmap_query(pd->failure_ops, op);
519 static struct bitmap *init_bitmap(TALLOC_CTX *mem_ctx, const char **ops)
527 bm = bitmap_talloc(mem_ctx, SMB_VFS_OP_LAST);
529 DEBUG(0, ("Could not alloc bitmap -- "
530 "defaulting to logging everything\n"));
534 for (; *ops != NULL; ops += 1) {
539 if (strequal(*ops, "all")) {
540 for (i=0; i<SMB_VFS_OP_LAST; i++) {
546 if (strequal(*ops, "none")) {
556 for (i=0; i<SMB_VFS_OP_LAST; i++) {
557 if ((vfs_op_names[i].name == NULL)
558 || (vfs_op_names[i].type != i)) {
559 smb_panic("vfs_full_audit.c: name table not "
560 "in sync with vfs_op_type enums\n");
562 if (strequal(op, vfs_op_names[i].name)) {
571 if (i == SMB_VFS_OP_LAST) {
572 DEBUG(0, ("Could not find opname %s, logging all\n",
581 static const char *audit_opname(vfs_op_type op)
583 if (op >= SMB_VFS_OP_LAST)
584 return "INVALID VFS OP";
585 return vfs_op_names[op].name;
588 static TALLOC_CTX *tmp_do_log_ctx;
590 * Get us a temporary talloc context usable just for DEBUG arguments
592 static TALLOC_CTX *do_log_ctx(void)
594 if (tmp_do_log_ctx == NULL) {
595 tmp_do_log_ctx = talloc_named_const(NULL, 0, "do_log_ctx");
597 return tmp_do_log_ctx;
600 static void do_log(vfs_op_type op, bool success, vfs_handle_struct *handle,
601 const char *format, ...) PRINTF_ATTRIBUTE(4, 5);
603 static void do_log(vfs_op_type op, bool success, vfs_handle_struct *handle,
604 const char *format, ...)
606 struct vfs_full_audit_private_data *pd;
608 char *audit_pre = NULL;
612 SMB_VFS_HANDLE_GET_DATA(handle, pd,
613 struct vfs_full_audit_private_data,
616 if (success && (!log_success(pd, op)))
619 if (!success && (!log_failure(pd, op)))
623 fstrcpy(err_msg, "ok");
625 fstr_sprintf(err_msg, "fail (%s)", strerror(errno));
627 va_start(ap, format);
628 op_msg = talloc_vasprintf(talloc_tos(), format, ap);
635 audit_pre = audit_prefix(talloc_tos(), handle->conn);
641 * Specify the facility to interoperate with other syslog
642 * callers (smbd for example).
644 priority = pd->syslog_priority | pd->syslog_facility;
646 syslog(priority, "%s|%s|%s|%s\n",
647 audit_pre ? audit_pre : "",
648 audit_opname(op), err_msg, op_msg);
650 DEBUG(1, ("%s|%s|%s|%s\n",
651 audit_pre ? audit_pre : "",
652 audit_opname(op), err_msg, op_msg));
655 TALLOC_FREE(audit_pre);
657 TALLOC_FREE(tmp_do_log_ctx);
661 * Return a string using the do_log_ctx()
663 static const char *smb_fname_str_do_log(struct connection_struct *conn,
664 const struct smb_filename *smb_fname)
669 if (smb_fname == NULL) {
673 if (smb_fname->base_name[0] != '/') {
674 char *abs_name = NULL;
675 struct smb_filename *fname_copy = cp_smb_filename(
678 if (fname_copy == NULL) {
682 if (!ISDOT(smb_fname->base_name)) {
683 abs_name = talloc_asprintf(do_log_ctx(),
685 conn->cwd_fsp->fsp_name->base_name,
686 smb_fname->base_name);
688 abs_name = talloc_strdup(do_log_ctx(),
689 conn->cwd_fsp->fsp_name->base_name);
691 if (abs_name == NULL) {
694 fname_copy->base_name = abs_name;
695 smb_fname = fname_copy;
698 status = get_full_smb_filename(do_log_ctx(), smb_fname, &fname);
699 if (!NT_STATUS_IS_OK(status)) {
706 * Return an fsp debug string using the do_log_ctx()
708 static const char *fsp_str_do_log(const struct files_struct *fsp)
710 return smb_fname_str_do_log(fsp->conn, fsp->fsp_name);
713 /* Implementation of vfs_ops. Pass everything on to the default
714 operation but log event first. */
716 static int smb_full_audit_connect(vfs_handle_struct *handle,
717 const char *svc, const char *user)
720 const char *none[] = { "none" };
721 struct vfs_full_audit_private_data *pd = NULL;
723 result = SMB_VFS_NEXT_CONNECT(handle, svc, user);
728 pd = talloc_zero(handle, struct vfs_full_audit_private_data);
730 SMB_VFS_NEXT_DISCONNECT(handle);
734 pd->syslog_facility = audit_syslog_facility(handle);
735 if (pd->syslog_facility == -1) {
736 DEBUG(1, ("%s: Unknown facility %s\n", __func__,
737 lp_parm_const_string(SNUM(handle->conn),
738 "full_audit", "facility",
740 SMB_VFS_NEXT_DISCONNECT(handle);
744 pd->syslog_priority = audit_syslog_priority(handle);
746 pd->log_secdesc = lp_parm_bool(SNUM(handle->conn),
747 "full_audit", "log_secdesc", false);
749 pd->do_syslog = lp_parm_bool(SNUM(handle->conn),
750 "full_audit", "syslog", true);
754 openlog("smbd_audit", 0, pd->syslog_facility);
758 pd->success_ops = init_bitmap(
759 pd, lp_parm_string_list(SNUM(handle->conn), "full_audit",
761 pd->failure_ops = init_bitmap(
762 pd, lp_parm_string_list(SNUM(handle->conn), "full_audit",
765 /* Store the private data. */
766 SMB_VFS_HANDLE_SET_DATA(handle, pd, NULL,
767 struct vfs_full_audit_private_data, return -1);
769 do_log(SMB_VFS_OP_CONNECT, True, handle,
775 static void smb_full_audit_disconnect(vfs_handle_struct *handle)
777 SMB_VFS_NEXT_DISCONNECT(handle);
779 do_log(SMB_VFS_OP_DISCONNECT, True, handle,
780 "%s", lp_servicename(talloc_tos(), SNUM(handle->conn)));
782 /* The bitmaps will be disconnected when the private
786 static uint64_t smb_full_audit_disk_free(vfs_handle_struct *handle,
787 const struct smb_filename *smb_fname,
794 result = SMB_VFS_NEXT_DISK_FREE(handle, smb_fname, bsize, dfree, dsize);
796 /* Don't have a reasonable notion of failure here */
798 do_log(SMB_VFS_OP_DISK_FREE, True, handle, "%s", smb_fname->base_name);
803 static int smb_full_audit_get_quota(struct vfs_handle_struct *handle,
804 const struct smb_filename *smb_fname,
805 enum SMB_QUOTA_TYPE qtype,
811 result = SMB_VFS_NEXT_GET_QUOTA(handle, smb_fname, qtype, id, qt);
813 do_log(SMB_VFS_OP_GET_QUOTA, (result >= 0), handle, "%s",
814 smb_fname->base_name);
819 static int smb_full_audit_set_quota(struct vfs_handle_struct *handle,
820 enum SMB_QUOTA_TYPE qtype, unid_t id,
825 result = SMB_VFS_NEXT_SET_QUOTA(handle, qtype, id, qt);
827 do_log(SMB_VFS_OP_SET_QUOTA, (result >= 0), handle, "");
832 static int smb_full_audit_get_shadow_copy_data(struct vfs_handle_struct *handle,
833 struct files_struct *fsp,
834 struct shadow_copy_data *shadow_copy_data,
839 result = SMB_VFS_NEXT_GET_SHADOW_COPY_DATA(handle, fsp, shadow_copy_data, labels);
841 do_log(SMB_VFS_OP_GET_SHADOW_COPY_DATA, (result >= 0), handle, "");
846 static int smb_full_audit_statvfs(struct vfs_handle_struct *handle,
847 const struct smb_filename *smb_fname,
848 struct vfs_statvfs_struct *statbuf)
852 result = SMB_VFS_NEXT_STATVFS(handle, smb_fname, statbuf);
854 do_log(SMB_VFS_OP_STATVFS, (result >= 0), handle, "");
859 static uint32_t smb_full_audit_fs_capabilities(struct vfs_handle_struct *handle, enum timestamp_set_resolution *p_ts_res)
863 result = SMB_VFS_NEXT_FS_CAPABILITIES(handle, p_ts_res);
865 do_log(SMB_VFS_OP_FS_CAPABILITIES, true, handle, "");
870 static NTSTATUS smb_full_audit_get_dfs_referrals(
871 struct vfs_handle_struct *handle,
872 struct dfs_GetDFSReferral *r)
876 status = SMB_VFS_NEXT_GET_DFS_REFERRALS(handle, r);
878 do_log(SMB_VFS_OP_GET_DFS_REFERRALS, NT_STATUS_IS_OK(status),
884 static NTSTATUS smb_full_audit_snap_check_path(struct vfs_handle_struct *handle,
886 const char *service_path,
891 status = SMB_VFS_NEXT_SNAP_CHECK_PATH(handle, mem_ctx, service_path,
893 do_log(SMB_VFS_OP_SNAP_CHECK_PATH, NT_STATUS_IS_OK(status),
899 static NTSTATUS smb_full_audit_snap_create(struct vfs_handle_struct *handle,
901 const char *base_volume,
909 status = SMB_VFS_NEXT_SNAP_CREATE(handle, mem_ctx, base_volume, tstamp,
910 rw, base_path, snap_path);
911 do_log(SMB_VFS_OP_SNAP_CREATE, NT_STATUS_IS_OK(status), handle, "");
916 static NTSTATUS smb_full_audit_snap_delete(struct vfs_handle_struct *handle,
923 status = SMB_VFS_NEXT_SNAP_DELETE(handle, mem_ctx, base_path,
925 do_log(SMB_VFS_OP_SNAP_DELETE, NT_STATUS_IS_OK(status), handle, "");
930 static DIR *smb_full_audit_opendir(vfs_handle_struct *handle,
931 const struct smb_filename *smb_fname,
937 result = SMB_VFS_NEXT_OPENDIR(handle, smb_fname, mask, attr);
939 do_log(SMB_VFS_OP_OPENDIR, (result != NULL), handle, "%s",
940 smb_fname->base_name);
945 static DIR *smb_full_audit_fdopendir(vfs_handle_struct *handle,
946 files_struct *fsp, const char *mask, uint32_t attr)
950 result = SMB_VFS_NEXT_FDOPENDIR(handle, fsp, mask, attr);
952 do_log(SMB_VFS_OP_FDOPENDIR, (result != NULL), handle, "%s",
953 fsp_str_do_log(fsp));
958 static struct dirent *smb_full_audit_readdir(vfs_handle_struct *handle,
959 DIR *dirp, SMB_STRUCT_STAT *sbuf)
961 struct dirent *result;
963 result = SMB_VFS_NEXT_READDIR(handle, dirp, sbuf);
965 /* This operation has no reasonable error condition
966 * (End of dir is also failure), so always succeed.
968 do_log(SMB_VFS_OP_READDIR, True, handle, "");
973 static void smb_full_audit_seekdir(vfs_handle_struct *handle,
974 DIR *dirp, long offset)
976 SMB_VFS_NEXT_SEEKDIR(handle, dirp, offset);
978 do_log(SMB_VFS_OP_SEEKDIR, True, handle, "");
981 static long smb_full_audit_telldir(vfs_handle_struct *handle,
986 result = SMB_VFS_NEXT_TELLDIR(handle, dirp);
988 do_log(SMB_VFS_OP_TELLDIR, True, handle, "");
993 static void smb_full_audit_rewinddir(vfs_handle_struct *handle,
996 SMB_VFS_NEXT_REWINDDIR(handle, dirp);
998 do_log(SMB_VFS_OP_REWINDDIR, True, handle, "");
1001 static int smb_full_audit_mkdir(vfs_handle_struct *handle,
1002 const struct smb_filename *smb_fname, mode_t mode)
1006 result = SMB_VFS_NEXT_MKDIR(handle, smb_fname, mode);
1008 do_log(SMB_VFS_OP_MKDIR, (result >= 0), handle, "%s",
1009 smb_fname->base_name);
1014 static int smb_full_audit_mkdirat(vfs_handle_struct *handle,
1015 struct files_struct *dirfsp,
1016 const struct smb_filename *smb_fname,
1021 result = SMB_VFS_NEXT_MKDIRAT(handle,
1026 do_log(SMB_VFS_OP_MKDIRAT, (result >= 0), handle, "%s",
1027 smb_fname->base_name);
1032 static int smb_full_audit_rmdir(vfs_handle_struct *handle,
1033 const struct smb_filename *smb_fname)
1037 result = SMB_VFS_NEXT_RMDIR(handle, smb_fname);
1039 do_log(SMB_VFS_OP_RMDIR, (result >= 0), handle, "%s",
1040 smb_fname->base_name);
1045 static int smb_full_audit_closedir(vfs_handle_struct *handle,
1050 result = SMB_VFS_NEXT_CLOSEDIR(handle, dirp);
1052 do_log(SMB_VFS_OP_CLOSEDIR, (result >= 0), handle, "");
1057 static int smb_full_audit_open(vfs_handle_struct *handle,
1058 struct smb_filename *smb_fname,
1059 files_struct *fsp, int flags, mode_t mode)
1063 result = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
1065 do_log(SMB_VFS_OP_OPEN, (result >= 0), handle, "%s|%s",
1066 ((flags & O_WRONLY) || (flags & O_RDWR))?"w":"r",
1067 smb_fname_str_do_log(handle->conn, smb_fname));
1072 static NTSTATUS smb_full_audit_create_file(vfs_handle_struct *handle,
1073 struct smb_request *req,
1074 uint16_t root_dir_fid,
1075 struct smb_filename *smb_fname,
1076 uint32_t access_mask,
1077 uint32_t share_access,
1078 uint32_t create_disposition,
1079 uint32_t create_options,
1080 uint32_t file_attributes,
1081 uint32_t oplock_request,
1082 const struct smb2_lease *lease,
1083 uint64_t allocation_size,
1084 uint32_t private_flags,
1085 struct security_descriptor *sd,
1086 struct ea_list *ea_list,
1087 files_struct **result_fsp,
1089 const struct smb2_create_blobs *in_context_blobs,
1090 struct smb2_create_blobs *out_context_blobs)
1093 const char* str_create_disposition;
1095 switch (create_disposition) {
1096 case FILE_SUPERSEDE:
1097 str_create_disposition = "supersede";
1099 case FILE_OVERWRITE_IF:
1100 str_create_disposition = "overwrite_if";
1103 str_create_disposition = "open";
1105 case FILE_OVERWRITE:
1106 str_create_disposition = "overwrite";
1109 str_create_disposition = "create";
1112 str_create_disposition = "open_if";
1115 str_create_disposition = "unknown";
1118 result = SMB_VFS_NEXT_CREATE_FILE(
1119 handle, /* handle */
1121 root_dir_fid, /* root_dir_fid */
1122 smb_fname, /* fname */
1123 access_mask, /* access_mask */
1124 share_access, /* share_access */
1125 create_disposition, /* create_disposition*/
1126 create_options, /* create_options */
1127 file_attributes, /* file_attributes */
1128 oplock_request, /* oplock_request */
1130 allocation_size, /* allocation_size */
1133 ea_list, /* ea_list */
1134 result_fsp, /* result */
1136 in_context_blobs, out_context_blobs); /* create context */
1138 do_log(SMB_VFS_OP_CREATE_FILE, (NT_STATUS_IS_OK(result)), handle,
1139 "0x%x|%s|%s|%s", access_mask,
1140 create_options & FILE_DIRECTORY_FILE ? "dir" : "file",
1141 str_create_disposition,
1142 smb_fname_str_do_log(handle->conn, smb_fname));
1147 static int smb_full_audit_close(vfs_handle_struct *handle, files_struct *fsp)
1151 result = SMB_VFS_NEXT_CLOSE(handle, fsp);
1153 do_log(SMB_VFS_OP_CLOSE, (result >= 0), handle, "%s",
1154 fsp_str_do_log(fsp));
1159 static ssize_t smb_full_audit_pread(vfs_handle_struct *handle, files_struct *fsp,
1160 void *data, size_t n, off_t offset)
1164 result = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
1166 do_log(SMB_VFS_OP_PREAD, (result >= 0), handle, "%s",
1167 fsp_str_do_log(fsp));
1172 struct smb_full_audit_pread_state {
1173 vfs_handle_struct *handle;
1176 struct vfs_aio_state vfs_aio_state;
1179 static void smb_full_audit_pread_done(struct tevent_req *subreq);
1181 static struct tevent_req *smb_full_audit_pread_send(
1182 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1183 struct tevent_context *ev, struct files_struct *fsp,
1184 void *data, size_t n, off_t offset)
1186 struct tevent_req *req, *subreq;
1187 struct smb_full_audit_pread_state *state;
1189 req = tevent_req_create(mem_ctx, &state,
1190 struct smb_full_audit_pread_state);
1192 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
1193 fsp_str_do_log(fsp));
1196 state->handle = handle;
1199 subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
1201 if (tevent_req_nomem(subreq, req)) {
1202 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
1203 fsp_str_do_log(fsp));
1204 return tevent_req_post(req, ev);
1206 tevent_req_set_callback(subreq, smb_full_audit_pread_done, req);
1208 do_log(SMB_VFS_OP_PREAD_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1212 static void smb_full_audit_pread_done(struct tevent_req *subreq)
1214 struct tevent_req *req = tevent_req_callback_data(
1215 subreq, struct tevent_req);
1216 struct smb_full_audit_pread_state *state = tevent_req_data(
1217 req, struct smb_full_audit_pread_state);
1219 state->ret = SMB_VFS_PREAD_RECV(subreq, &state->vfs_aio_state);
1220 TALLOC_FREE(subreq);
1221 tevent_req_done(req);
1224 static ssize_t smb_full_audit_pread_recv(struct tevent_req *req,
1225 struct vfs_aio_state *vfs_aio_state)
1227 struct smb_full_audit_pread_state *state = tevent_req_data(
1228 req, struct smb_full_audit_pread_state);
1230 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1231 do_log(SMB_VFS_OP_PREAD_RECV, false, state->handle, "%s",
1232 fsp_str_do_log(state->fsp));
1236 do_log(SMB_VFS_OP_PREAD_RECV, (state->ret >= 0), state->handle, "%s",
1237 fsp_str_do_log(state->fsp));
1239 *vfs_aio_state = state->vfs_aio_state;
1243 static ssize_t smb_full_audit_pwrite(vfs_handle_struct *handle, files_struct *fsp,
1244 const void *data, size_t n,
1249 result = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
1251 do_log(SMB_VFS_OP_PWRITE, (result >= 0), handle, "%s",
1252 fsp_str_do_log(fsp));
1257 struct smb_full_audit_pwrite_state {
1258 vfs_handle_struct *handle;
1261 struct vfs_aio_state vfs_aio_state;
1264 static void smb_full_audit_pwrite_done(struct tevent_req *subreq);
1266 static struct tevent_req *smb_full_audit_pwrite_send(
1267 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1268 struct tevent_context *ev, struct files_struct *fsp,
1269 const void *data, size_t n, off_t offset)
1271 struct tevent_req *req, *subreq;
1272 struct smb_full_audit_pwrite_state *state;
1274 req = tevent_req_create(mem_ctx, &state,
1275 struct smb_full_audit_pwrite_state);
1277 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1278 fsp_str_do_log(fsp));
1281 state->handle = handle;
1284 subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
1286 if (tevent_req_nomem(subreq, req)) {
1287 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1288 fsp_str_do_log(fsp));
1289 return tevent_req_post(req, ev);
1291 tevent_req_set_callback(subreq, smb_full_audit_pwrite_done, req);
1293 do_log(SMB_VFS_OP_PWRITE_SEND, true, handle, "%s",
1294 fsp_str_do_log(fsp));
1298 static void smb_full_audit_pwrite_done(struct tevent_req *subreq)
1300 struct tevent_req *req = tevent_req_callback_data(
1301 subreq, struct tevent_req);
1302 struct smb_full_audit_pwrite_state *state = tevent_req_data(
1303 req, struct smb_full_audit_pwrite_state);
1305 state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->vfs_aio_state);
1306 TALLOC_FREE(subreq);
1307 tevent_req_done(req);
1310 static ssize_t smb_full_audit_pwrite_recv(struct tevent_req *req,
1311 struct vfs_aio_state *vfs_aio_state)
1313 struct smb_full_audit_pwrite_state *state = tevent_req_data(
1314 req, struct smb_full_audit_pwrite_state);
1316 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1317 do_log(SMB_VFS_OP_PWRITE_RECV, false, state->handle, "%s",
1318 fsp_str_do_log(state->fsp));
1322 do_log(SMB_VFS_OP_PWRITE_RECV, (state->ret >= 0), state->handle, "%s",
1323 fsp_str_do_log(state->fsp));
1325 *vfs_aio_state = state->vfs_aio_state;
1329 static off_t smb_full_audit_lseek(vfs_handle_struct *handle, files_struct *fsp,
1330 off_t offset, int whence)
1334 result = SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence);
1336 do_log(SMB_VFS_OP_LSEEK, (result != (ssize_t)-1), handle,
1337 "%s", fsp_str_do_log(fsp));
1342 static ssize_t smb_full_audit_sendfile(vfs_handle_struct *handle, int tofd,
1343 files_struct *fromfsp,
1344 const DATA_BLOB *hdr, off_t offset,
1349 result = SMB_VFS_NEXT_SENDFILE(handle, tofd, fromfsp, hdr, offset, n);
1351 do_log(SMB_VFS_OP_SENDFILE, (result >= 0), handle,
1352 "%s", fsp_str_do_log(fromfsp));
1357 static ssize_t smb_full_audit_recvfile(vfs_handle_struct *handle, int fromfd,
1358 files_struct *tofsp,
1364 result = SMB_VFS_NEXT_RECVFILE(handle, fromfd, tofsp, offset, n);
1366 do_log(SMB_VFS_OP_RECVFILE, (result >= 0), handle,
1367 "%s", fsp_str_do_log(tofsp));
1372 static int smb_full_audit_renameat(vfs_handle_struct *handle,
1373 files_struct *srcfsp,
1374 const struct smb_filename *smb_fname_src,
1375 files_struct *dstfsp,
1376 const struct smb_filename *smb_fname_dst)
1380 result = SMB_VFS_NEXT_RENAMEAT(handle,
1386 do_log(SMB_VFS_OP_RENAMEAT, (result >= 0), handle, "%s|%s",
1387 smb_fname_str_do_log(handle->conn, smb_fname_src),
1388 smb_fname_str_do_log(handle->conn, smb_fname_dst));
1393 struct smb_full_audit_fsync_state {
1394 vfs_handle_struct *handle;
1397 struct vfs_aio_state vfs_aio_state;
1400 static void smb_full_audit_fsync_done(struct tevent_req *subreq);
1402 static struct tevent_req *smb_full_audit_fsync_send(
1403 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1404 struct tevent_context *ev, struct files_struct *fsp)
1406 struct tevent_req *req, *subreq;
1407 struct smb_full_audit_fsync_state *state;
1409 req = tevent_req_create(mem_ctx, &state,
1410 struct smb_full_audit_fsync_state);
1412 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1413 fsp_str_do_log(fsp));
1416 state->handle = handle;
1419 subreq = SMB_VFS_NEXT_FSYNC_SEND(state, ev, handle, fsp);
1420 if (tevent_req_nomem(subreq, req)) {
1421 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1422 fsp_str_do_log(fsp));
1423 return tevent_req_post(req, ev);
1425 tevent_req_set_callback(subreq, smb_full_audit_fsync_done, req);
1427 do_log(SMB_VFS_OP_FSYNC_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1431 static void smb_full_audit_fsync_done(struct tevent_req *subreq)
1433 struct tevent_req *req = tevent_req_callback_data(
1434 subreq, struct tevent_req);
1435 struct smb_full_audit_fsync_state *state = tevent_req_data(
1436 req, struct smb_full_audit_fsync_state);
1438 state->ret = SMB_VFS_FSYNC_RECV(subreq, &state->vfs_aio_state);
1439 TALLOC_FREE(subreq);
1440 tevent_req_done(req);
1443 static int smb_full_audit_fsync_recv(struct tevent_req *req,
1444 struct vfs_aio_state *vfs_aio_state)
1446 struct smb_full_audit_fsync_state *state = tevent_req_data(
1447 req, struct smb_full_audit_fsync_state);
1449 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1450 do_log(SMB_VFS_OP_FSYNC_RECV, false, state->handle, "%s",
1451 fsp_str_do_log(state->fsp));
1455 do_log(SMB_VFS_OP_FSYNC_RECV, (state->ret >= 0), state->handle, "%s",
1456 fsp_str_do_log(state->fsp));
1458 *vfs_aio_state = state->vfs_aio_state;
1462 static int smb_full_audit_stat(vfs_handle_struct *handle,
1463 struct smb_filename *smb_fname)
1467 result = SMB_VFS_NEXT_STAT(handle, smb_fname);
1469 do_log(SMB_VFS_OP_STAT, (result >= 0), handle, "%s",
1470 smb_fname_str_do_log(handle->conn, smb_fname));
1475 static int smb_full_audit_fstat(vfs_handle_struct *handle, files_struct *fsp,
1476 SMB_STRUCT_STAT *sbuf)
1480 result = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1482 do_log(SMB_VFS_OP_FSTAT, (result >= 0), handle, "%s",
1483 fsp_str_do_log(fsp));
1488 static int smb_full_audit_lstat(vfs_handle_struct *handle,
1489 struct smb_filename *smb_fname)
1493 result = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
1495 do_log(SMB_VFS_OP_LSTAT, (result >= 0), handle, "%s",
1496 smb_fname_str_do_log(handle->conn, smb_fname));
1501 static uint64_t smb_full_audit_get_alloc_size(vfs_handle_struct *handle,
1502 files_struct *fsp, const SMB_STRUCT_STAT *sbuf)
1506 result = SMB_VFS_NEXT_GET_ALLOC_SIZE(handle, fsp, sbuf);
1508 do_log(SMB_VFS_OP_GET_ALLOC_SIZE, (result != (uint64_t)-1), handle,
1509 "%llu", (unsigned long long)result);
1514 static int smb_full_audit_unlink(vfs_handle_struct *handle,
1515 const struct smb_filename *smb_fname)
1519 result = SMB_VFS_NEXT_UNLINK(handle, smb_fname);
1521 do_log(SMB_VFS_OP_UNLINK, (result >= 0), handle, "%s",
1522 smb_fname_str_do_log(handle->conn, smb_fname));
1527 static int smb_full_audit_chmod(vfs_handle_struct *handle,
1528 const struct smb_filename *smb_fname,
1533 result = SMB_VFS_NEXT_CHMOD(handle, smb_fname, mode);
1535 do_log(SMB_VFS_OP_CHMOD, (result >= 0), handle, "%s|%o",
1536 smb_fname->base_name,
1542 static int smb_full_audit_fchmod(vfs_handle_struct *handle, files_struct *fsp,
1547 result = SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1549 do_log(SMB_VFS_OP_FCHMOD, (result >= 0), handle,
1550 "%s|%o", fsp_str_do_log(fsp), mode);
1555 static int smb_full_audit_chown(vfs_handle_struct *handle,
1556 const struct smb_filename *smb_fname,
1562 result = SMB_VFS_NEXT_CHOWN(handle, smb_fname, uid, gid);
1564 do_log(SMB_VFS_OP_CHOWN, (result >= 0), handle, "%s|%ld|%ld",
1565 smb_fname->base_name, (long int)uid, (long int)gid);
1570 static int smb_full_audit_fchown(vfs_handle_struct *handle, files_struct *fsp,
1571 uid_t uid, gid_t gid)
1575 result = SMB_VFS_NEXT_FCHOWN(handle, fsp, uid, gid);
1577 do_log(SMB_VFS_OP_FCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1578 fsp_str_do_log(fsp), (long int)uid, (long int)gid);
1583 static int smb_full_audit_lchown(vfs_handle_struct *handle,
1584 const struct smb_filename *smb_fname,
1590 result = SMB_VFS_NEXT_LCHOWN(handle, smb_fname, uid, gid);
1592 do_log(SMB_VFS_OP_LCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1593 smb_fname->base_name, (long int)uid, (long int)gid);
1598 static int smb_full_audit_chdir(vfs_handle_struct *handle,
1599 const struct smb_filename *smb_fname)
1603 result = SMB_VFS_NEXT_CHDIR(handle, smb_fname);
1605 do_log(SMB_VFS_OP_CHDIR, (result >= 0), handle, "chdir|%s",
1606 smb_fname->base_name);
1611 static struct smb_filename *smb_full_audit_getwd(vfs_handle_struct *handle,
1614 struct smb_filename *result;
1616 result = SMB_VFS_NEXT_GETWD(handle, ctx);
1618 do_log(SMB_VFS_OP_GETWD, (result != NULL), handle, "%s",
1619 result == NULL? "" : result->base_name);
1624 static int smb_full_audit_ntimes(vfs_handle_struct *handle,
1625 const struct smb_filename *smb_fname,
1626 struct smb_file_time *ft)
1629 time_t create_time = convert_timespec_to_time_t(ft->create_time);
1630 time_t atime = convert_timespec_to_time_t(ft->atime);
1631 time_t mtime = convert_timespec_to_time_t(ft->mtime);
1632 time_t ctime = convert_timespec_to_time_t(ft->ctime);
1633 const char *create_time_str = "";
1634 const char *atime_str = "";
1635 const char *mtime_str = "";
1636 const char *ctime_str = "";
1637 TALLOC_CTX *frame = talloc_stackframe();
1639 result = SMB_VFS_NEXT_NTIMES(handle, smb_fname, ft);
1641 if (create_time > 0) {
1642 create_time_str = timestring(frame, create_time);
1645 atime_str = timestring(frame, atime);
1648 mtime_str = timestring(frame, mtime);
1651 ctime_str = timestring(frame, ctime);
1654 do_log(SMB_VFS_OP_NTIMES,
1658 smb_fname_str_do_log(handle->conn, smb_fname),
1669 static int smb_full_audit_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
1674 result = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1676 do_log(SMB_VFS_OP_FTRUNCATE, (result >= 0), handle,
1677 "%s", fsp_str_do_log(fsp));
1682 static int smb_full_audit_fallocate(vfs_handle_struct *handle, files_struct *fsp,
1689 result = SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
1691 do_log(SMB_VFS_OP_FALLOCATE, (result >= 0), handle,
1692 "%s", fsp_str_do_log(fsp));
1697 static bool smb_full_audit_lock(vfs_handle_struct *handle, files_struct *fsp,
1698 int op, off_t offset, off_t count, int type)
1702 result = SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type);
1704 do_log(SMB_VFS_OP_LOCK, result, handle, "%s", fsp_str_do_log(fsp));
1709 static int smb_full_audit_kernel_flock(struct vfs_handle_struct *handle,
1710 struct files_struct *fsp,
1711 uint32_t share_mode, uint32_t access_mask)
1715 result = SMB_VFS_NEXT_KERNEL_FLOCK(handle, fsp, share_mode, access_mask);
1717 do_log(SMB_VFS_OP_KERNEL_FLOCK, (result >= 0), handle, "%s",
1718 fsp_str_do_log(fsp));
1723 static int smb_full_audit_linux_setlease(vfs_handle_struct *handle, files_struct *fsp,
1728 result = SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
1730 do_log(SMB_VFS_OP_LINUX_SETLEASE, (result >= 0), handle, "%s",
1731 fsp_str_do_log(fsp));
1736 static bool smb_full_audit_getlock(vfs_handle_struct *handle, files_struct *fsp,
1737 off_t *poffset, off_t *pcount, int *ptype, pid_t *ppid)
1741 result = SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype, ppid);
1743 do_log(SMB_VFS_OP_GETLOCK, result, handle, "%s", fsp_str_do_log(fsp));
1748 static int smb_full_audit_symlinkat(vfs_handle_struct *handle,
1749 const char *link_contents,
1750 struct files_struct *dirfsp,
1751 const struct smb_filename *new_smb_fname)
1755 result = SMB_VFS_NEXT_SYMLINKAT(handle,
1760 do_log(SMB_VFS_OP_SYMLINKAT, (result >= 0), handle,
1761 "%s|%s", link_contents, new_smb_fname->base_name);
1766 static int smb_full_audit_readlinkat(vfs_handle_struct *handle,
1767 files_struct *dirfsp,
1768 const struct smb_filename *smb_fname,
1774 result = SMB_VFS_NEXT_READLINKAT(handle,
1780 do_log(SMB_VFS_OP_READLINKAT, (result >= 0), handle, "%s",
1781 smb_fname->base_name);
1786 static int smb_full_audit_linkat(vfs_handle_struct *handle,
1787 files_struct *srcfsp,
1788 const struct smb_filename *old_smb_fname,
1789 files_struct *dstfsp,
1790 const struct smb_filename *new_smb_fname,
1795 result = SMB_VFS_NEXT_LINKAT(handle,
1802 do_log(SMB_VFS_OP_LINKAT, (result >= 0), handle,
1803 "%s|%s", old_smb_fname->base_name, new_smb_fname->base_name);
1808 static int smb_full_audit_mknodat(vfs_handle_struct *handle,
1809 files_struct *dirfsp,
1810 const struct smb_filename *smb_fname,
1816 result = SMB_VFS_NEXT_MKNODAT(handle,
1822 do_log(SMB_VFS_OP_MKNODAT, (result >= 0), handle, "%s",
1823 smb_fname->base_name);
1828 static struct smb_filename *smb_full_audit_realpath(vfs_handle_struct *handle,
1830 const struct smb_filename *smb_fname)
1832 struct smb_filename *result_fname = NULL;
1834 result_fname = SMB_VFS_NEXT_REALPATH(handle, ctx, smb_fname);
1836 do_log(SMB_VFS_OP_REALPATH, (result_fname != NULL), handle, "%s",
1837 smb_fname->base_name);
1839 return result_fname;
1842 static int smb_full_audit_chflags(vfs_handle_struct *handle,
1843 const struct smb_filename *smb_fname,
1848 result = SMB_VFS_NEXT_CHFLAGS(handle, smb_fname, flags);
1850 do_log(SMB_VFS_OP_CHFLAGS, (result != 0), handle, "%s",
1851 smb_fname->base_name);
1856 static struct file_id smb_full_audit_file_id_create(struct vfs_handle_struct *handle,
1857 const SMB_STRUCT_STAT *sbuf)
1859 struct file_id id_zero;
1860 struct file_id result;
1862 ZERO_STRUCT(id_zero);
1864 result = SMB_VFS_NEXT_FILE_ID_CREATE(handle, sbuf);
1866 do_log(SMB_VFS_OP_FILE_ID_CREATE,
1867 !file_id_equal(&id_zero, &result),
1868 handle, "%s", file_id_string_tos(&result));
1873 static uint64_t smb_full_audit_fs_file_id(struct vfs_handle_struct *handle,
1874 const SMB_STRUCT_STAT *sbuf)
1878 result = SMB_VFS_NEXT_FS_FILE_ID(handle, sbuf);
1880 do_log(SMB_VFS_OP_FS_FILE_ID,
1882 handle, "%" PRIu64, result);
1887 static NTSTATUS smb_full_audit_streaminfo(vfs_handle_struct *handle,
1888 struct files_struct *fsp,
1889 const struct smb_filename *smb_fname,
1890 TALLOC_CTX *mem_ctx,
1891 unsigned int *pnum_streams,
1892 struct stream_struct **pstreams)
1896 result = SMB_VFS_NEXT_STREAMINFO(handle, fsp, smb_fname, mem_ctx,
1897 pnum_streams, pstreams);
1899 do_log(SMB_VFS_OP_STREAMINFO, NT_STATUS_IS_OK(result), handle,
1900 "%s", smb_fname->base_name);
1905 static int smb_full_audit_get_real_filename(struct vfs_handle_struct *handle,
1908 TALLOC_CTX *mem_ctx,
1913 result = SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name, mem_ctx,
1916 do_log(SMB_VFS_OP_GET_REAL_FILENAME, (result == 0), handle,
1917 "%s/%s->%s", path, name, (result == 0) ? *found_name : "");
1922 static const char *smb_full_audit_connectpath(vfs_handle_struct *handle,
1923 const struct smb_filename *smb_fname)
1927 result = SMB_VFS_NEXT_CONNECTPATH(handle, smb_fname);
1929 do_log(SMB_VFS_OP_CONNECTPATH, result != NULL, handle,
1930 "%s", smb_fname->base_name);
1935 static NTSTATUS smb_full_audit_brl_lock_windows(struct vfs_handle_struct *handle,
1936 struct byte_range_lock *br_lck,
1937 struct lock_struct *plock)
1941 result = SMB_VFS_NEXT_BRL_LOCK_WINDOWS(handle, br_lck, plock);
1943 do_log(SMB_VFS_OP_BRL_LOCK_WINDOWS, NT_STATUS_IS_OK(result), handle,
1944 "%s:%llu-%llu. type=%d.",
1945 fsp_str_do_log(brl_fsp(br_lck)),
1946 (unsigned long long)plock->start,
1947 (unsigned long long)plock->size,
1953 static bool smb_full_audit_brl_unlock_windows(struct vfs_handle_struct *handle,
1954 struct byte_range_lock *br_lck,
1955 const struct lock_struct *plock)
1959 result = SMB_VFS_NEXT_BRL_UNLOCK_WINDOWS(handle, br_lck, plock);
1961 do_log(SMB_VFS_OP_BRL_UNLOCK_WINDOWS, (result == 0), handle,
1962 "%s:%llu-%llu:%d", fsp_str_do_log(brl_fsp(br_lck)),
1963 (unsigned long long)plock->start,
1964 (unsigned long long)plock->size,
1970 static bool smb_full_audit_strict_lock_check(struct vfs_handle_struct *handle,
1971 struct files_struct *fsp,
1972 struct lock_struct *plock)
1976 result = SMB_VFS_NEXT_STRICT_LOCK_CHECK(handle, fsp, plock);
1978 do_log(SMB_VFS_OP_STRICT_LOCK_CHECK, result, handle,
1979 "%s:%llu-%llu:%d", fsp_str_do_log(fsp),
1980 (unsigned long long)plock->start,
1981 (unsigned long long)plock->size,
1987 static NTSTATUS smb_full_audit_translate_name(struct vfs_handle_struct *handle,
1989 enum vfs_translate_direction direction,
1990 TALLOC_CTX *mem_ctx,
1995 result = SMB_VFS_NEXT_TRANSLATE_NAME(handle, name, direction, mem_ctx,
1998 do_log(SMB_VFS_OP_TRANSLATE_NAME, NT_STATUS_IS_OK(result), handle, "");
2003 static NTSTATUS smb_full_audit_fsctl(struct vfs_handle_struct *handle,
2004 struct files_struct *fsp,
2008 const uint8_t *_in_data,
2010 uint8_t **_out_data,
2011 uint32_t max_out_len,
2016 result = SMB_VFS_NEXT_FSCTL(handle,
2027 do_log(SMB_VFS_OP_FSCTL, NT_STATUS_IS_OK(result), handle, "");
2032 static struct tevent_req *smb_full_audit_offload_read_send(
2033 TALLOC_CTX *mem_ctx,
2034 struct tevent_context *ev,
2035 struct vfs_handle_struct *handle,
2036 struct files_struct *fsp,
2042 struct tevent_req *req = NULL;
2044 req = SMB_VFS_NEXT_OFFLOAD_READ_SEND(mem_ctx, ev, handle, fsp,
2045 fsctl, ttl, offset, to_copy);
2047 do_log(SMB_VFS_OP_OFFLOAD_READ_SEND, req, handle, "");
2052 static NTSTATUS smb_full_audit_offload_read_recv(
2053 struct tevent_req *req,
2054 struct vfs_handle_struct *handle,
2055 TALLOC_CTX *mem_ctx,
2056 DATA_BLOB *_token_blob)
2060 status = SMB_VFS_NEXT_OFFLOAD_READ_RECV(req, handle, mem_ctx,
2063 do_log(SMB_VFS_OP_OFFLOAD_READ_RECV, NT_STATUS_IS_OK(status), handle, "");
2068 static struct tevent_req *smb_full_audit_offload_write_send(struct vfs_handle_struct *handle,
2069 TALLOC_CTX *mem_ctx,
2070 struct tevent_context *ev,
2073 off_t transfer_offset,
2074 struct files_struct *dest_fsp,
2078 struct tevent_req *req;
2080 req = SMB_VFS_NEXT_OFFLOAD_WRITE_SEND(handle, mem_ctx, ev,
2081 fsctl, token, transfer_offset,
2082 dest_fsp, dest_off, num);
2084 do_log(SMB_VFS_OP_OFFLOAD_WRITE_SEND, req, handle, "");
2089 static NTSTATUS smb_full_audit_offload_write_recv(struct vfs_handle_struct *handle,
2090 struct tevent_req *req,
2095 result = SMB_VFS_NEXT_OFFLOAD_WRITE_RECV(handle, req, copied);
2097 do_log(SMB_VFS_OP_OFFLOAD_WRITE_RECV, NT_STATUS_IS_OK(result), handle, "");
2102 static NTSTATUS smb_full_audit_get_compression(vfs_handle_struct *handle,
2103 TALLOC_CTX *mem_ctx,
2104 struct files_struct *fsp,
2105 struct smb_filename *smb_fname,
2106 uint16_t *_compression_fmt)
2110 result = SMB_VFS_NEXT_GET_COMPRESSION(handle, mem_ctx, fsp, smb_fname,
2113 do_log(SMB_VFS_OP_GET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
2115 (fsp ? fsp_str_do_log(fsp) :
2116 smb_fname_str_do_log(handle->conn, smb_fname)));
2121 static NTSTATUS smb_full_audit_set_compression(vfs_handle_struct *handle,
2122 TALLOC_CTX *mem_ctx,
2123 struct files_struct *fsp,
2124 uint16_t compression_fmt)
2128 result = SMB_VFS_NEXT_SET_COMPRESSION(handle, mem_ctx, fsp,
2131 do_log(SMB_VFS_OP_SET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
2132 "%s", fsp_str_do_log(fsp));
2137 static NTSTATUS smb_full_audit_readdir_attr(struct vfs_handle_struct *handle,
2138 const struct smb_filename *fname,
2139 TALLOC_CTX *mem_ctx,
2140 struct readdir_attr_data **pattr_data)
2144 status = SMB_VFS_NEXT_READDIR_ATTR(handle, fname, mem_ctx, pattr_data);
2146 do_log(SMB_VFS_OP_READDIR_ATTR, NT_STATUS_IS_OK(status), handle, "%s",
2147 smb_fname_str_do_log(handle->conn, fname));
2152 static NTSTATUS smb_full_audit_get_dos_attributes(
2153 struct vfs_handle_struct *handle,
2154 struct smb_filename *smb_fname,
2159 status = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES(handle,
2163 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES,
2164 NT_STATUS_IS_OK(status),
2167 smb_fname_str_do_log(handle->conn, smb_fname));
2172 struct smb_full_audit_get_dos_attributes_state {
2173 struct vfs_aio_state aio_state;
2174 vfs_handle_struct *handle;
2175 files_struct *dir_fsp;
2176 const struct smb_filename *smb_fname;
2180 static void smb_full_audit_get_dos_attributes_done(struct tevent_req *subreq);
2182 static struct tevent_req *smb_full_audit_get_dos_attributes_send(
2183 TALLOC_CTX *mem_ctx,
2184 struct tevent_context *ev,
2185 struct vfs_handle_struct *handle,
2186 files_struct *dir_fsp,
2187 struct smb_filename *smb_fname)
2189 struct tevent_req *req = NULL;
2190 struct smb_full_audit_get_dos_attributes_state *state = NULL;
2191 struct tevent_req *subreq = NULL;
2193 req = tevent_req_create(mem_ctx, &state,
2194 struct smb_full_audit_get_dos_attributes_state);
2196 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2200 fsp_str_do_log(dir_fsp),
2201 smb_fname->base_name);
2204 *state = (struct smb_full_audit_get_dos_attributes_state) {
2207 .smb_fname = smb_fname,
2210 subreq = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES_SEND(mem_ctx,
2215 if (tevent_req_nomem(subreq, req)) {
2216 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2220 fsp_str_do_log(dir_fsp),
2221 smb_fname->base_name);
2222 return tevent_req_post(req, ev);
2224 tevent_req_set_callback(subreq,
2225 smb_full_audit_get_dos_attributes_done,
2228 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2232 fsp_str_do_log(dir_fsp),
2233 smb_fname->base_name);
2238 static void smb_full_audit_get_dos_attributes_done(struct tevent_req *subreq)
2240 struct tevent_req *req =
2241 tevent_req_callback_data(subreq,
2243 struct smb_full_audit_get_dos_attributes_state *state =
2244 tevent_req_data(req,
2245 struct smb_full_audit_get_dos_attributes_state);
2248 status = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES_RECV(subreq,
2251 TALLOC_FREE(subreq);
2252 if (tevent_req_nterror(req, status)) {
2256 tevent_req_done(req);
2260 static NTSTATUS smb_full_audit_get_dos_attributes_recv(struct tevent_req *req,
2261 struct vfs_aio_state *aio_state,
2264 struct smb_full_audit_get_dos_attributes_state *state =
2265 tevent_req_data(req,
2266 struct smb_full_audit_get_dos_attributes_state);
2269 if (tevent_req_is_nterror(req, &status)) {
2270 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV,
2274 fsp_str_do_log(state->dir_fsp),
2275 state->smb_fname->base_name);
2276 tevent_req_received(req);
2280 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV,
2284 fsp_str_do_log(state->dir_fsp),
2285 state->smb_fname->base_name);
2287 *aio_state = state->aio_state;
2288 *dosmode = state->dosmode;
2289 tevent_req_received(req);
2290 return NT_STATUS_OK;
2293 static NTSTATUS smb_full_audit_fget_dos_attributes(
2294 struct vfs_handle_struct *handle,
2295 struct files_struct *fsp,
2300 status = SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle,
2304 do_log(SMB_VFS_OP_FGET_DOS_ATTRIBUTES,
2305 NT_STATUS_IS_OK(status),
2308 fsp_str_do_log(fsp));
2313 static NTSTATUS smb_full_audit_set_dos_attributes(
2314 struct vfs_handle_struct *handle,
2315 const struct smb_filename *smb_fname,
2320 status = SMB_VFS_NEXT_SET_DOS_ATTRIBUTES(handle,
2324 do_log(SMB_VFS_OP_SET_DOS_ATTRIBUTES,
2325 NT_STATUS_IS_OK(status),
2328 smb_fname_str_do_log(handle->conn, smb_fname));
2333 static NTSTATUS smb_full_audit_fset_dos_attributes(
2334 struct vfs_handle_struct *handle,
2335 struct files_struct *fsp,
2340 status = SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle,
2344 do_log(SMB_VFS_OP_FSET_DOS_ATTRIBUTES,
2345 NT_STATUS_IS_OK(status),
2348 fsp_str_do_log(fsp));
2353 static NTSTATUS smb_full_audit_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
2354 uint32_t security_info,
2355 TALLOC_CTX *mem_ctx,
2356 struct security_descriptor **ppdesc)
2360 result = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
2363 do_log(SMB_VFS_OP_FGET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2364 "%s", fsp_str_do_log(fsp));
2369 static NTSTATUS smb_full_audit_get_nt_acl(vfs_handle_struct *handle,
2370 const struct smb_filename *smb_fname,
2371 uint32_t security_info,
2372 TALLOC_CTX *mem_ctx,
2373 struct security_descriptor **ppdesc)
2377 result = SMB_VFS_NEXT_GET_NT_ACL(handle, smb_fname, security_info,
2380 do_log(SMB_VFS_OP_GET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2381 "%s", smb_fname_str_do_log(handle->conn, smb_fname));
2386 static NTSTATUS smb_full_audit_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
2387 uint32_t security_info_sent,
2388 const struct security_descriptor *psd)
2390 struct vfs_full_audit_private_data *pd;
2394 SMB_VFS_HANDLE_GET_DATA(handle, pd,
2395 struct vfs_full_audit_private_data,
2396 return NT_STATUS_INTERNAL_ERROR);
2398 if (pd->log_secdesc) {
2399 sd = sddl_encode(talloc_tos(), psd, get_global_sam_sid());
2402 result = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
2404 do_log(SMB_VFS_OP_FSET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2405 "%s [%s]", fsp_str_do_log(fsp), sd ? sd : "");
2412 static NTSTATUS smb_full_audit_audit_file(struct vfs_handle_struct *handle,
2413 struct smb_filename *file,
2414 struct security_acl *sacl,
2415 uint32_t access_requested,
2416 uint32_t access_denied)
2420 result = SMB_VFS_NEXT_AUDIT_FILE(handle,
2426 do_log(SMB_VFS_OP_AUDIT_FILE, NT_STATUS_IS_OK(result), handle,
2428 smb_fname_str_do_log(handle->conn, file));
2433 static SMB_ACL_T smb_full_audit_sys_acl_get_file(vfs_handle_struct *handle,
2434 const struct smb_filename *smb_fname,
2435 SMB_ACL_TYPE_T type,
2436 TALLOC_CTX *mem_ctx)
2440 result = SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, smb_fname,
2443 do_log(SMB_VFS_OP_SYS_ACL_GET_FILE, (result != NULL), handle,
2444 "%s", smb_fname->base_name);
2449 static SMB_ACL_T smb_full_audit_sys_acl_get_fd(vfs_handle_struct *handle,
2450 files_struct *fsp, TALLOC_CTX *mem_ctx)
2454 result = SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp, mem_ctx);
2456 do_log(SMB_VFS_OP_SYS_ACL_GET_FD, (result != NULL), handle,
2457 "%s", fsp_str_do_log(fsp));
2462 static int smb_full_audit_sys_acl_blob_get_file(vfs_handle_struct *handle,
2463 const struct smb_filename *smb_fname,
2464 TALLOC_CTX *mem_ctx,
2465 char **blob_description,
2470 result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FILE(handle, smb_fname,
2471 mem_ctx, blob_description, blob);
2473 do_log(SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE, (result >= 0), handle,
2474 "%s", smb_fname->base_name);
2479 static int smb_full_audit_sys_acl_blob_get_fd(vfs_handle_struct *handle,
2481 TALLOC_CTX *mem_ctx,
2482 char **blob_description,
2487 result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle, fsp, mem_ctx, blob_description, blob);
2489 do_log(SMB_VFS_OP_SYS_ACL_BLOB_GET_FD, (result >= 0), handle,
2490 "%s", fsp_str_do_log(fsp));
2495 static int smb_full_audit_sys_acl_set_file(vfs_handle_struct *handle,
2496 const struct smb_filename *smb_fname,
2497 SMB_ACL_TYPE_T acltype,
2502 result = SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, smb_fname, acltype,
2505 do_log(SMB_VFS_OP_SYS_ACL_SET_FILE, (result >= 0), handle,
2506 "%s", smb_fname->base_name);
2511 static int smb_full_audit_sys_acl_set_fd(vfs_handle_struct *handle, files_struct *fsp,
2516 result = SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, theacl);
2518 do_log(SMB_VFS_OP_SYS_ACL_SET_FD, (result >= 0), handle,
2519 "%s", fsp_str_do_log(fsp));
2524 static int smb_full_audit_sys_acl_delete_def_file(vfs_handle_struct *handle,
2525 const struct smb_filename *smb_fname)
2529 result = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, smb_fname);
2531 do_log(SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE, (result >= 0), handle,
2532 "%s", smb_fname->base_name);
2537 static ssize_t smb_full_audit_getxattr(struct vfs_handle_struct *handle,
2538 const struct smb_filename *smb_fname,
2539 const char *name, void *value, size_t size)
2543 result = SMB_VFS_NEXT_GETXATTR(handle, smb_fname, name, value, size);
2545 do_log(SMB_VFS_OP_GETXATTR, (result >= 0), handle,
2546 "%s|%s", smb_fname->base_name, name);
2551 struct smb_full_audit_getxattrat_state {
2552 struct vfs_aio_state aio_state;
2553 vfs_handle_struct *handle;
2554 files_struct *dir_fsp;
2555 const struct smb_filename *smb_fname;
2556 const char *xattr_name;
2558 uint8_t *xattr_value;
2561 static void smb_full_audit_getxattrat_done(struct tevent_req *subreq);
2563 static struct tevent_req *smb_full_audit_getxattrat_send(
2564 TALLOC_CTX *mem_ctx,
2565 struct tevent_context *ev,
2566 struct vfs_handle_struct *handle,
2567 files_struct *dir_fsp,
2568 const struct smb_filename *smb_fname,
2569 const char *xattr_name,
2572 struct tevent_req *req = NULL;
2573 struct tevent_req *subreq = NULL;
2574 struct smb_full_audit_getxattrat_state *state = NULL;
2576 req = tevent_req_create(mem_ctx, &state,
2577 struct smb_full_audit_getxattrat_state);
2579 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2583 fsp_str_do_log(dir_fsp),
2584 smb_fname->base_name,
2588 *state = (struct smb_full_audit_getxattrat_state) {
2591 .smb_fname = smb_fname,
2592 .xattr_name = xattr_name,
2595 subreq = SMB_VFS_NEXT_GETXATTRAT_SEND(state,
2602 if (tevent_req_nomem(subreq, req)) {
2603 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2607 fsp_str_do_log(dir_fsp),
2608 smb_fname->base_name,
2610 return tevent_req_post(req, ev);
2612 tevent_req_set_callback(subreq, smb_full_audit_getxattrat_done, req);
2614 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2618 fsp_str_do_log(dir_fsp),
2619 smb_fname->base_name,
2625 static void smb_full_audit_getxattrat_done(struct tevent_req *subreq)
2627 struct tevent_req *req = tevent_req_callback_data(
2628 subreq, struct tevent_req);
2629 struct smb_full_audit_getxattrat_state *state = tevent_req_data(
2630 req, struct smb_full_audit_getxattrat_state);
2632 state->xattr_size = SMB_VFS_NEXT_GETXATTRAT_RECV(subreq,
2635 &state->xattr_value);
2636 TALLOC_FREE(subreq);
2637 if (state->xattr_size == -1) {
2638 tevent_req_error(req, state->aio_state.error);
2642 tevent_req_done(req);
2645 static ssize_t smb_full_audit_getxattrat_recv(struct tevent_req *req,
2646 struct vfs_aio_state *aio_state,
2647 TALLOC_CTX *mem_ctx,
2648 uint8_t **xattr_value)
2650 struct smb_full_audit_getxattrat_state *state = tevent_req_data(
2651 req, struct smb_full_audit_getxattrat_state);
2654 if (tevent_req_is_unix_error(req, &aio_state->error)) {
2655 do_log(SMB_VFS_OP_GETXATTRAT_RECV,
2659 fsp_str_do_log(state->dir_fsp),
2660 state->smb_fname->base_name,
2662 tevent_req_received(req);
2666 do_log(SMB_VFS_OP_GETXATTRAT_RECV,
2670 fsp_str_do_log(state->dir_fsp),
2671 state->smb_fname->base_name,
2674 *aio_state = state->aio_state;
2675 xattr_size = state->xattr_size;
2676 if (xattr_value != NULL) {
2677 *xattr_value = talloc_move(mem_ctx, &state->xattr_value);
2680 tevent_req_received(req);
2684 static ssize_t smb_full_audit_fgetxattr(struct vfs_handle_struct *handle,
2685 struct files_struct *fsp,
2686 const char *name, void *value, size_t size)
2690 result = SMB_VFS_NEXT_FGETXATTR(handle, fsp, name, value, size);
2692 do_log(SMB_VFS_OP_FGETXATTR, (result >= 0), handle,
2693 "%s|%s", fsp_str_do_log(fsp), name);
2698 static ssize_t smb_full_audit_listxattr(struct vfs_handle_struct *handle,
2699 const struct smb_filename *smb_fname,
2705 result = SMB_VFS_NEXT_LISTXATTR(handle, smb_fname, list, size);
2707 do_log(SMB_VFS_OP_LISTXATTR, (result >= 0), handle, "%s",
2708 smb_fname->base_name);
2713 static ssize_t smb_full_audit_flistxattr(struct vfs_handle_struct *handle,
2714 struct files_struct *fsp, char *list,
2719 result = SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
2721 do_log(SMB_VFS_OP_FLISTXATTR, (result >= 0), handle,
2722 "%s", fsp_str_do_log(fsp));
2727 static int smb_full_audit_removexattr(struct vfs_handle_struct *handle,
2728 const struct smb_filename *smb_fname,
2733 result = SMB_VFS_NEXT_REMOVEXATTR(handle, smb_fname, name);
2735 do_log(SMB_VFS_OP_REMOVEXATTR, (result >= 0), handle,
2736 "%s|%s", smb_fname->base_name, name);
2741 static int smb_full_audit_fremovexattr(struct vfs_handle_struct *handle,
2742 struct files_struct *fsp,
2747 result = SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, name);
2749 do_log(SMB_VFS_OP_FREMOVEXATTR, (result >= 0), handle,
2750 "%s|%s", fsp_str_do_log(fsp), name);
2755 static int smb_full_audit_setxattr(struct vfs_handle_struct *handle,
2756 const struct smb_filename *smb_fname,
2757 const char *name, const void *value, size_t size,
2762 result = SMB_VFS_NEXT_SETXATTR(handle, smb_fname, name, value, size,
2765 do_log(SMB_VFS_OP_SETXATTR, (result >= 0), handle,
2766 "%s|%s", smb_fname->base_name, name);
2771 static int smb_full_audit_fsetxattr(struct vfs_handle_struct *handle,
2772 struct files_struct *fsp, const char *name,
2773 const void *value, size_t size, int flags)
2777 result = SMB_VFS_NEXT_FSETXATTR(handle, fsp, name, value, size, flags);
2779 do_log(SMB_VFS_OP_FSETXATTR, (result >= 0), handle,
2780 "%s|%s", fsp_str_do_log(fsp), name);
2785 static bool smb_full_audit_aio_force(struct vfs_handle_struct *handle,
2786 struct files_struct *fsp)
2790 result = SMB_VFS_NEXT_AIO_FORCE(handle, fsp);
2791 do_log(SMB_VFS_OP_AIO_FORCE, result, handle,
2792 "%s", fsp_str_do_log(fsp));
2797 static NTSTATUS smb_full_audit_durable_cookie(struct vfs_handle_struct *handle,
2798 struct files_struct *fsp,
2799 TALLOC_CTX *mem_ctx,
2804 result = SMB_VFS_NEXT_DURABLE_COOKIE(handle,
2809 do_log(SMB_VFS_OP_DURABLE_COOKIE, NT_STATUS_IS_OK(result), handle,
2810 "%s", fsp_str_do_log(fsp));
2815 static NTSTATUS smb_full_audit_durable_disconnect(
2816 struct vfs_handle_struct *handle,
2817 struct files_struct *fsp,
2818 const DATA_BLOB old_cookie,
2819 TALLOC_CTX *mem_ctx,
2820 DATA_BLOB *new_cookie)
2824 result = SMB_VFS_NEXT_DURABLE_DISCONNECT(handle,
2830 do_log(SMB_VFS_OP_DURABLE_DISCONNECT, NT_STATUS_IS_OK(result), handle,
2831 "%s", fsp_str_do_log(fsp));
2836 static NTSTATUS smb_full_audit_durable_reconnect(
2837 struct vfs_handle_struct *handle,
2838 struct smb_request *smb1req,
2839 struct smbXsrv_open *op,
2840 const DATA_BLOB old_cookie,
2841 TALLOC_CTX *mem_ctx,
2842 struct files_struct **fsp,
2843 DATA_BLOB *new_cookie)
2847 result = SMB_VFS_NEXT_DURABLE_RECONNECT(handle,
2855 do_log(SMB_VFS_OP_DURABLE_RECONNECT,
2856 NT_STATUS_IS_OK(result),
2863 static struct vfs_fn_pointers vfs_full_audit_fns = {
2865 /* Disk operations */
2867 .connect_fn = smb_full_audit_connect,
2868 .disconnect_fn = smb_full_audit_disconnect,
2869 .disk_free_fn = smb_full_audit_disk_free,
2870 .get_quota_fn = smb_full_audit_get_quota,
2871 .set_quota_fn = smb_full_audit_set_quota,
2872 .get_shadow_copy_data_fn = smb_full_audit_get_shadow_copy_data,
2873 .statvfs_fn = smb_full_audit_statvfs,
2874 .fs_capabilities_fn = smb_full_audit_fs_capabilities,
2875 .get_dfs_referrals_fn = smb_full_audit_get_dfs_referrals,
2876 .opendir_fn = smb_full_audit_opendir,
2877 .fdopendir_fn = smb_full_audit_fdopendir,
2878 .readdir_fn = smb_full_audit_readdir,
2879 .seekdir_fn = smb_full_audit_seekdir,
2880 .telldir_fn = smb_full_audit_telldir,
2881 .rewind_dir_fn = smb_full_audit_rewinddir,
2882 .mkdir_fn = smb_full_audit_mkdir,
2883 .mkdirat_fn = smb_full_audit_mkdirat,
2884 .rmdir_fn = smb_full_audit_rmdir,
2885 .closedir_fn = smb_full_audit_closedir,
2886 .open_fn = smb_full_audit_open,
2887 .create_file_fn = smb_full_audit_create_file,
2888 .close_fn = smb_full_audit_close,
2889 .pread_fn = smb_full_audit_pread,
2890 .pread_send_fn = smb_full_audit_pread_send,
2891 .pread_recv_fn = smb_full_audit_pread_recv,
2892 .pwrite_fn = smb_full_audit_pwrite,
2893 .pwrite_send_fn = smb_full_audit_pwrite_send,
2894 .pwrite_recv_fn = smb_full_audit_pwrite_recv,
2895 .lseek_fn = smb_full_audit_lseek,
2896 .sendfile_fn = smb_full_audit_sendfile,
2897 .recvfile_fn = smb_full_audit_recvfile,
2898 .renameat_fn = smb_full_audit_renameat,
2899 .fsync_send_fn = smb_full_audit_fsync_send,
2900 .fsync_recv_fn = smb_full_audit_fsync_recv,
2901 .stat_fn = smb_full_audit_stat,
2902 .fstat_fn = smb_full_audit_fstat,
2903 .lstat_fn = smb_full_audit_lstat,
2904 .get_alloc_size_fn = smb_full_audit_get_alloc_size,
2905 .unlink_fn = smb_full_audit_unlink,
2906 .chmod_fn = smb_full_audit_chmod,
2907 .fchmod_fn = smb_full_audit_fchmod,
2908 .chown_fn = smb_full_audit_chown,
2909 .fchown_fn = smb_full_audit_fchown,
2910 .lchown_fn = smb_full_audit_lchown,
2911 .chdir_fn = smb_full_audit_chdir,
2912 .getwd_fn = smb_full_audit_getwd,
2913 .ntimes_fn = smb_full_audit_ntimes,
2914 .ftruncate_fn = smb_full_audit_ftruncate,
2915 .fallocate_fn = smb_full_audit_fallocate,
2916 .lock_fn = smb_full_audit_lock,
2917 .kernel_flock_fn = smb_full_audit_kernel_flock,
2918 .linux_setlease_fn = smb_full_audit_linux_setlease,
2919 .getlock_fn = smb_full_audit_getlock,
2920 .symlinkat_fn = smb_full_audit_symlinkat,
2921 .readlinkat_fn = smb_full_audit_readlinkat,
2922 .linkat_fn = smb_full_audit_linkat,
2923 .mknodat_fn = smb_full_audit_mknodat,
2924 .realpath_fn = smb_full_audit_realpath,
2925 .chflags_fn = smb_full_audit_chflags,
2926 .file_id_create_fn = smb_full_audit_file_id_create,
2927 .fs_file_id_fn = smb_full_audit_fs_file_id,
2928 .offload_read_send_fn = smb_full_audit_offload_read_send,
2929 .offload_read_recv_fn = smb_full_audit_offload_read_recv,
2930 .offload_write_send_fn = smb_full_audit_offload_write_send,
2931 .offload_write_recv_fn = smb_full_audit_offload_write_recv,
2932 .get_compression_fn = smb_full_audit_get_compression,
2933 .set_compression_fn = smb_full_audit_set_compression,
2934 .snap_check_path_fn = smb_full_audit_snap_check_path,
2935 .snap_create_fn = smb_full_audit_snap_create,
2936 .snap_delete_fn = smb_full_audit_snap_delete,
2937 .streaminfo_fn = smb_full_audit_streaminfo,
2938 .get_real_filename_fn = smb_full_audit_get_real_filename,
2939 .connectpath_fn = smb_full_audit_connectpath,
2940 .brl_lock_windows_fn = smb_full_audit_brl_lock_windows,
2941 .brl_unlock_windows_fn = smb_full_audit_brl_unlock_windows,
2942 .strict_lock_check_fn = smb_full_audit_strict_lock_check,
2943 .translate_name_fn = smb_full_audit_translate_name,
2944 .fsctl_fn = smb_full_audit_fsctl,
2945 .get_dos_attributes_fn = smb_full_audit_get_dos_attributes,
2946 .get_dos_attributes_send_fn = smb_full_audit_get_dos_attributes_send,
2947 .get_dos_attributes_recv_fn = smb_full_audit_get_dos_attributes_recv,
2948 .fget_dos_attributes_fn = smb_full_audit_fget_dos_attributes,
2949 .set_dos_attributes_fn = smb_full_audit_set_dos_attributes,
2950 .fset_dos_attributes_fn = smb_full_audit_fset_dos_attributes,
2951 .fget_nt_acl_fn = smb_full_audit_fget_nt_acl,
2952 .get_nt_acl_fn = smb_full_audit_get_nt_acl,
2953 .fset_nt_acl_fn = smb_full_audit_fset_nt_acl,
2954 .audit_file_fn = smb_full_audit_audit_file,
2955 .sys_acl_get_file_fn = smb_full_audit_sys_acl_get_file,
2956 .sys_acl_get_fd_fn = smb_full_audit_sys_acl_get_fd,
2957 .sys_acl_blob_get_file_fn = smb_full_audit_sys_acl_blob_get_file,
2958 .sys_acl_blob_get_fd_fn = smb_full_audit_sys_acl_blob_get_fd,
2959 .sys_acl_set_file_fn = smb_full_audit_sys_acl_set_file,
2960 .sys_acl_set_fd_fn = smb_full_audit_sys_acl_set_fd,
2961 .sys_acl_delete_def_file_fn = smb_full_audit_sys_acl_delete_def_file,
2962 .getxattr_fn = smb_full_audit_getxattr,
2963 .getxattrat_send_fn = smb_full_audit_getxattrat_send,
2964 .getxattrat_recv_fn = smb_full_audit_getxattrat_recv,
2965 .fgetxattr_fn = smb_full_audit_fgetxattr,
2966 .listxattr_fn = smb_full_audit_listxattr,
2967 .flistxattr_fn = smb_full_audit_flistxattr,
2968 .removexattr_fn = smb_full_audit_removexattr,
2969 .fremovexattr_fn = smb_full_audit_fremovexattr,
2970 .setxattr_fn = smb_full_audit_setxattr,
2971 .fsetxattr_fn = smb_full_audit_fsetxattr,
2972 .aio_force_fn = smb_full_audit_aio_force,
2973 .durable_cookie_fn = smb_full_audit_durable_cookie,
2974 .durable_disconnect_fn = smb_full_audit_durable_disconnect,
2975 .durable_reconnect_fn = smb_full_audit_durable_reconnect,
2976 .readdir_attr_fn = smb_full_audit_readdir_attr
2981 NTSTATUS vfs_full_audit_init(TALLOC_CTX *ctx)
2985 smb_vfs_assert_all_fns(&vfs_full_audit_fns, "full_audit");
2987 ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "full_audit",
2988 &vfs_full_audit_fns);
2990 if (!NT_STATUS_IS_OK(ret))
2993 vfs_full_audit_debug_level = debug_add_class("full_audit");
2994 if (vfs_full_audit_debug_level == -1) {
2995 vfs_full_audit_debug_level = DBGC_VFS;
2996 DEBUG(0, ("vfs_full_audit: Couldn't register custom debugging "
2999 DEBUG(10, ("vfs_full_audit: Debug class number of "
3000 "'full_audit': %d\n", vfs_full_audit_debug_level));