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,
115 /* File operations */
118 SMB_VFS_OP_CREATE_FILE,
122 SMB_VFS_OP_PREAD_SEND,
123 SMB_VFS_OP_PREAD_RECV,
126 SMB_VFS_OP_PWRITE_SEND,
127 SMB_VFS_OP_PWRITE_RECV,
133 SMB_VFS_OP_FSYNC_SEND,
134 SMB_VFS_OP_FSYNC_RECV,
138 SMB_VFS_OP_GET_ALLOC_SIZE,
148 SMB_VFS_OP_FTRUNCATE,
149 SMB_VFS_OP_FALLOCATE,
151 SMB_VFS_OP_KERNEL_FLOCK,
152 SMB_VFS_OP_LINUX_SETLEASE,
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_RMDIR, "rmdir" },
260 { SMB_VFS_OP_CLOSEDIR, "closedir" },
261 { SMB_VFS_OP_OPEN, "open" },
262 { SMB_VFS_OP_CREATE_FILE, "create_file" },
263 { SMB_VFS_OP_CLOSE, "close" },
264 { SMB_VFS_OP_READ, "read" },
265 { SMB_VFS_OP_PREAD, "pread" },
266 { SMB_VFS_OP_PREAD_SEND, "pread_send" },
267 { SMB_VFS_OP_PREAD_RECV, "pread_recv" },
268 { SMB_VFS_OP_WRITE, "write" },
269 { SMB_VFS_OP_PWRITE, "pwrite" },
270 { SMB_VFS_OP_PWRITE_SEND, "pwrite_send" },
271 { SMB_VFS_OP_PWRITE_RECV, "pwrite_recv" },
272 { SMB_VFS_OP_LSEEK, "lseek" },
273 { SMB_VFS_OP_SENDFILE, "sendfile" },
274 { SMB_VFS_OP_RECVFILE, "recvfile" },
275 { SMB_VFS_OP_RENAMEAT, "renameat" },
276 { SMB_VFS_OP_FSYNC, "fsync" },
277 { SMB_VFS_OP_FSYNC_SEND, "fsync_send" },
278 { SMB_VFS_OP_FSYNC_RECV, "fsync_recv" },
279 { SMB_VFS_OP_STAT, "stat" },
280 { SMB_VFS_OP_FSTAT, "fstat" },
281 { SMB_VFS_OP_LSTAT, "lstat" },
282 { SMB_VFS_OP_GET_ALLOC_SIZE, "get_alloc_size" },
283 { SMB_VFS_OP_UNLINK, "unlink" },
284 { SMB_VFS_OP_CHMOD, "chmod" },
285 { SMB_VFS_OP_FCHMOD, "fchmod" },
286 { SMB_VFS_OP_CHOWN, "chown" },
287 { SMB_VFS_OP_FCHOWN, "fchown" },
288 { SMB_VFS_OP_LCHOWN, "lchown" },
289 { SMB_VFS_OP_CHDIR, "chdir" },
290 { SMB_VFS_OP_GETWD, "getwd" },
291 { SMB_VFS_OP_NTIMES, "ntimes" },
292 { SMB_VFS_OP_FTRUNCATE, "ftruncate" },
293 { SMB_VFS_OP_FALLOCATE,"fallocate" },
294 { SMB_VFS_OP_LOCK, "lock" },
295 { SMB_VFS_OP_KERNEL_FLOCK, "kernel_flock" },
296 { SMB_VFS_OP_LINUX_SETLEASE, "linux_setlease" },
297 { SMB_VFS_OP_GETLOCK, "getlock" },
298 { SMB_VFS_OP_SYMLINK, "symlink" },
299 { SMB_VFS_OP_READLINK, "readlink" },
300 { SMB_VFS_OP_LINK, "link" },
301 { SMB_VFS_OP_LINKAT, "linkat" },
302 { SMB_VFS_OP_MKNOD, "mknod" },
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_rmdir(vfs_handle_struct *handle,
1015 const struct smb_filename *smb_fname)
1019 result = SMB_VFS_NEXT_RMDIR(handle, smb_fname);
1021 do_log(SMB_VFS_OP_RMDIR, (result >= 0), handle, "%s",
1022 smb_fname->base_name);
1027 static int smb_full_audit_closedir(vfs_handle_struct *handle,
1032 result = SMB_VFS_NEXT_CLOSEDIR(handle, dirp);
1034 do_log(SMB_VFS_OP_CLOSEDIR, (result >= 0), handle, "");
1039 static int smb_full_audit_open(vfs_handle_struct *handle,
1040 struct smb_filename *smb_fname,
1041 files_struct *fsp, int flags, mode_t mode)
1045 result = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
1047 do_log(SMB_VFS_OP_OPEN, (result >= 0), handle, "%s|%s",
1048 ((flags & O_WRONLY) || (flags & O_RDWR))?"w":"r",
1049 smb_fname_str_do_log(handle->conn, smb_fname));
1054 static NTSTATUS smb_full_audit_create_file(vfs_handle_struct *handle,
1055 struct smb_request *req,
1056 uint16_t root_dir_fid,
1057 struct smb_filename *smb_fname,
1058 uint32_t access_mask,
1059 uint32_t share_access,
1060 uint32_t create_disposition,
1061 uint32_t create_options,
1062 uint32_t file_attributes,
1063 uint32_t oplock_request,
1064 const struct smb2_lease *lease,
1065 uint64_t allocation_size,
1066 uint32_t private_flags,
1067 struct security_descriptor *sd,
1068 struct ea_list *ea_list,
1069 files_struct **result_fsp,
1071 const struct smb2_create_blobs *in_context_blobs,
1072 struct smb2_create_blobs *out_context_blobs)
1075 const char* str_create_disposition;
1077 switch (create_disposition) {
1078 case FILE_SUPERSEDE:
1079 str_create_disposition = "supersede";
1081 case FILE_OVERWRITE_IF:
1082 str_create_disposition = "overwrite_if";
1085 str_create_disposition = "open";
1087 case FILE_OVERWRITE:
1088 str_create_disposition = "overwrite";
1091 str_create_disposition = "create";
1094 str_create_disposition = "open_if";
1097 str_create_disposition = "unknown";
1100 result = SMB_VFS_NEXT_CREATE_FILE(
1101 handle, /* handle */
1103 root_dir_fid, /* root_dir_fid */
1104 smb_fname, /* fname */
1105 access_mask, /* access_mask */
1106 share_access, /* share_access */
1107 create_disposition, /* create_disposition*/
1108 create_options, /* create_options */
1109 file_attributes, /* file_attributes */
1110 oplock_request, /* oplock_request */
1112 allocation_size, /* allocation_size */
1115 ea_list, /* ea_list */
1116 result_fsp, /* result */
1118 in_context_blobs, out_context_blobs); /* create context */
1120 do_log(SMB_VFS_OP_CREATE_FILE, (NT_STATUS_IS_OK(result)), handle,
1121 "0x%x|%s|%s|%s", access_mask,
1122 create_options & FILE_DIRECTORY_FILE ? "dir" : "file",
1123 str_create_disposition,
1124 smb_fname_str_do_log(handle->conn, smb_fname));
1129 static int smb_full_audit_close(vfs_handle_struct *handle, files_struct *fsp)
1133 result = SMB_VFS_NEXT_CLOSE(handle, fsp);
1135 do_log(SMB_VFS_OP_CLOSE, (result >= 0), handle, "%s",
1136 fsp_str_do_log(fsp));
1141 static ssize_t smb_full_audit_pread(vfs_handle_struct *handle, files_struct *fsp,
1142 void *data, size_t n, off_t offset)
1146 result = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
1148 do_log(SMB_VFS_OP_PREAD, (result >= 0), handle, "%s",
1149 fsp_str_do_log(fsp));
1154 struct smb_full_audit_pread_state {
1155 vfs_handle_struct *handle;
1158 struct vfs_aio_state vfs_aio_state;
1161 static void smb_full_audit_pread_done(struct tevent_req *subreq);
1163 static struct tevent_req *smb_full_audit_pread_send(
1164 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1165 struct tevent_context *ev, struct files_struct *fsp,
1166 void *data, size_t n, off_t offset)
1168 struct tevent_req *req, *subreq;
1169 struct smb_full_audit_pread_state *state;
1171 req = tevent_req_create(mem_ctx, &state,
1172 struct smb_full_audit_pread_state);
1174 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
1175 fsp_str_do_log(fsp));
1178 state->handle = handle;
1181 subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
1183 if (tevent_req_nomem(subreq, req)) {
1184 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
1185 fsp_str_do_log(fsp));
1186 return tevent_req_post(req, ev);
1188 tevent_req_set_callback(subreq, smb_full_audit_pread_done, req);
1190 do_log(SMB_VFS_OP_PREAD_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1194 static void smb_full_audit_pread_done(struct tevent_req *subreq)
1196 struct tevent_req *req = tevent_req_callback_data(
1197 subreq, struct tevent_req);
1198 struct smb_full_audit_pread_state *state = tevent_req_data(
1199 req, struct smb_full_audit_pread_state);
1201 state->ret = SMB_VFS_PREAD_RECV(subreq, &state->vfs_aio_state);
1202 TALLOC_FREE(subreq);
1203 tevent_req_done(req);
1206 static ssize_t smb_full_audit_pread_recv(struct tevent_req *req,
1207 struct vfs_aio_state *vfs_aio_state)
1209 struct smb_full_audit_pread_state *state = tevent_req_data(
1210 req, struct smb_full_audit_pread_state);
1212 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1213 do_log(SMB_VFS_OP_PREAD_RECV, false, state->handle, "%s",
1214 fsp_str_do_log(state->fsp));
1218 do_log(SMB_VFS_OP_PREAD_RECV, (state->ret >= 0), state->handle, "%s",
1219 fsp_str_do_log(state->fsp));
1221 *vfs_aio_state = state->vfs_aio_state;
1225 static ssize_t smb_full_audit_pwrite(vfs_handle_struct *handle, files_struct *fsp,
1226 const void *data, size_t n,
1231 result = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
1233 do_log(SMB_VFS_OP_PWRITE, (result >= 0), handle, "%s",
1234 fsp_str_do_log(fsp));
1239 struct smb_full_audit_pwrite_state {
1240 vfs_handle_struct *handle;
1243 struct vfs_aio_state vfs_aio_state;
1246 static void smb_full_audit_pwrite_done(struct tevent_req *subreq);
1248 static struct tevent_req *smb_full_audit_pwrite_send(
1249 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1250 struct tevent_context *ev, struct files_struct *fsp,
1251 const void *data, size_t n, off_t offset)
1253 struct tevent_req *req, *subreq;
1254 struct smb_full_audit_pwrite_state *state;
1256 req = tevent_req_create(mem_ctx, &state,
1257 struct smb_full_audit_pwrite_state);
1259 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1260 fsp_str_do_log(fsp));
1263 state->handle = handle;
1266 subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
1268 if (tevent_req_nomem(subreq, req)) {
1269 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1270 fsp_str_do_log(fsp));
1271 return tevent_req_post(req, ev);
1273 tevent_req_set_callback(subreq, smb_full_audit_pwrite_done, req);
1275 do_log(SMB_VFS_OP_PWRITE_SEND, true, handle, "%s",
1276 fsp_str_do_log(fsp));
1280 static void smb_full_audit_pwrite_done(struct tevent_req *subreq)
1282 struct tevent_req *req = tevent_req_callback_data(
1283 subreq, struct tevent_req);
1284 struct smb_full_audit_pwrite_state *state = tevent_req_data(
1285 req, struct smb_full_audit_pwrite_state);
1287 state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->vfs_aio_state);
1288 TALLOC_FREE(subreq);
1289 tevent_req_done(req);
1292 static ssize_t smb_full_audit_pwrite_recv(struct tevent_req *req,
1293 struct vfs_aio_state *vfs_aio_state)
1295 struct smb_full_audit_pwrite_state *state = tevent_req_data(
1296 req, struct smb_full_audit_pwrite_state);
1298 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1299 do_log(SMB_VFS_OP_PWRITE_RECV, false, state->handle, "%s",
1300 fsp_str_do_log(state->fsp));
1304 do_log(SMB_VFS_OP_PWRITE_RECV, (state->ret >= 0), state->handle, "%s",
1305 fsp_str_do_log(state->fsp));
1307 *vfs_aio_state = state->vfs_aio_state;
1311 static off_t smb_full_audit_lseek(vfs_handle_struct *handle, files_struct *fsp,
1312 off_t offset, int whence)
1316 result = SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence);
1318 do_log(SMB_VFS_OP_LSEEK, (result != (ssize_t)-1), handle,
1319 "%s", fsp_str_do_log(fsp));
1324 static ssize_t smb_full_audit_sendfile(vfs_handle_struct *handle, int tofd,
1325 files_struct *fromfsp,
1326 const DATA_BLOB *hdr, off_t offset,
1331 result = SMB_VFS_NEXT_SENDFILE(handle, tofd, fromfsp, hdr, offset, n);
1333 do_log(SMB_VFS_OP_SENDFILE, (result >= 0), handle,
1334 "%s", fsp_str_do_log(fromfsp));
1339 static ssize_t smb_full_audit_recvfile(vfs_handle_struct *handle, int fromfd,
1340 files_struct *tofsp,
1346 result = SMB_VFS_NEXT_RECVFILE(handle, fromfd, tofsp, offset, n);
1348 do_log(SMB_VFS_OP_RECVFILE, (result >= 0), handle,
1349 "%s", fsp_str_do_log(tofsp));
1354 static int smb_full_audit_renameat(vfs_handle_struct *handle,
1355 files_struct *srcfsp,
1356 const struct smb_filename *smb_fname_src,
1357 files_struct *dstfsp,
1358 const struct smb_filename *smb_fname_dst)
1362 result = SMB_VFS_NEXT_RENAMEAT(handle,
1368 do_log(SMB_VFS_OP_RENAMEAT, (result >= 0), handle, "%s|%s",
1369 smb_fname_str_do_log(handle->conn, smb_fname_src),
1370 smb_fname_str_do_log(handle->conn, smb_fname_dst));
1375 struct smb_full_audit_fsync_state {
1376 vfs_handle_struct *handle;
1379 struct vfs_aio_state vfs_aio_state;
1382 static void smb_full_audit_fsync_done(struct tevent_req *subreq);
1384 static struct tevent_req *smb_full_audit_fsync_send(
1385 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1386 struct tevent_context *ev, struct files_struct *fsp)
1388 struct tevent_req *req, *subreq;
1389 struct smb_full_audit_fsync_state *state;
1391 req = tevent_req_create(mem_ctx, &state,
1392 struct smb_full_audit_fsync_state);
1394 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1395 fsp_str_do_log(fsp));
1398 state->handle = handle;
1401 subreq = SMB_VFS_NEXT_FSYNC_SEND(state, ev, handle, fsp);
1402 if (tevent_req_nomem(subreq, req)) {
1403 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1404 fsp_str_do_log(fsp));
1405 return tevent_req_post(req, ev);
1407 tevent_req_set_callback(subreq, smb_full_audit_fsync_done, req);
1409 do_log(SMB_VFS_OP_FSYNC_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1413 static void smb_full_audit_fsync_done(struct tevent_req *subreq)
1415 struct tevent_req *req = tevent_req_callback_data(
1416 subreq, struct tevent_req);
1417 struct smb_full_audit_fsync_state *state = tevent_req_data(
1418 req, struct smb_full_audit_fsync_state);
1420 state->ret = SMB_VFS_FSYNC_RECV(subreq, &state->vfs_aio_state);
1421 TALLOC_FREE(subreq);
1422 tevent_req_done(req);
1425 static int smb_full_audit_fsync_recv(struct tevent_req *req,
1426 struct vfs_aio_state *vfs_aio_state)
1428 struct smb_full_audit_fsync_state *state = tevent_req_data(
1429 req, struct smb_full_audit_fsync_state);
1431 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1432 do_log(SMB_VFS_OP_FSYNC_RECV, false, state->handle, "%s",
1433 fsp_str_do_log(state->fsp));
1437 do_log(SMB_VFS_OP_FSYNC_RECV, (state->ret >= 0), state->handle, "%s",
1438 fsp_str_do_log(state->fsp));
1440 *vfs_aio_state = state->vfs_aio_state;
1444 static int smb_full_audit_stat(vfs_handle_struct *handle,
1445 struct smb_filename *smb_fname)
1449 result = SMB_VFS_NEXT_STAT(handle, smb_fname);
1451 do_log(SMB_VFS_OP_STAT, (result >= 0), handle, "%s",
1452 smb_fname_str_do_log(handle->conn, smb_fname));
1457 static int smb_full_audit_fstat(vfs_handle_struct *handle, files_struct *fsp,
1458 SMB_STRUCT_STAT *sbuf)
1462 result = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1464 do_log(SMB_VFS_OP_FSTAT, (result >= 0), handle, "%s",
1465 fsp_str_do_log(fsp));
1470 static int smb_full_audit_lstat(vfs_handle_struct *handle,
1471 struct smb_filename *smb_fname)
1475 result = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
1477 do_log(SMB_VFS_OP_LSTAT, (result >= 0), handle, "%s",
1478 smb_fname_str_do_log(handle->conn, smb_fname));
1483 static uint64_t smb_full_audit_get_alloc_size(vfs_handle_struct *handle,
1484 files_struct *fsp, const SMB_STRUCT_STAT *sbuf)
1488 result = SMB_VFS_NEXT_GET_ALLOC_SIZE(handle, fsp, sbuf);
1490 do_log(SMB_VFS_OP_GET_ALLOC_SIZE, (result != (uint64_t)-1), handle,
1491 "%llu", (unsigned long long)result);
1496 static int smb_full_audit_unlink(vfs_handle_struct *handle,
1497 const struct smb_filename *smb_fname)
1501 result = SMB_VFS_NEXT_UNLINK(handle, smb_fname);
1503 do_log(SMB_VFS_OP_UNLINK, (result >= 0), handle, "%s",
1504 smb_fname_str_do_log(handle->conn, smb_fname));
1509 static int smb_full_audit_chmod(vfs_handle_struct *handle,
1510 const struct smb_filename *smb_fname,
1515 result = SMB_VFS_NEXT_CHMOD(handle, smb_fname, mode);
1517 do_log(SMB_VFS_OP_CHMOD, (result >= 0), handle, "%s|%o",
1518 smb_fname->base_name,
1524 static int smb_full_audit_fchmod(vfs_handle_struct *handle, files_struct *fsp,
1529 result = SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1531 do_log(SMB_VFS_OP_FCHMOD, (result >= 0), handle,
1532 "%s|%o", fsp_str_do_log(fsp), mode);
1537 static int smb_full_audit_chown(vfs_handle_struct *handle,
1538 const struct smb_filename *smb_fname,
1544 result = SMB_VFS_NEXT_CHOWN(handle, smb_fname, uid, gid);
1546 do_log(SMB_VFS_OP_CHOWN, (result >= 0), handle, "%s|%ld|%ld",
1547 smb_fname->base_name, (long int)uid, (long int)gid);
1552 static int smb_full_audit_fchown(vfs_handle_struct *handle, files_struct *fsp,
1553 uid_t uid, gid_t gid)
1557 result = SMB_VFS_NEXT_FCHOWN(handle, fsp, uid, gid);
1559 do_log(SMB_VFS_OP_FCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1560 fsp_str_do_log(fsp), (long int)uid, (long int)gid);
1565 static int smb_full_audit_lchown(vfs_handle_struct *handle,
1566 const struct smb_filename *smb_fname,
1572 result = SMB_VFS_NEXT_LCHOWN(handle, smb_fname, uid, gid);
1574 do_log(SMB_VFS_OP_LCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1575 smb_fname->base_name, (long int)uid, (long int)gid);
1580 static int smb_full_audit_chdir(vfs_handle_struct *handle,
1581 const struct smb_filename *smb_fname)
1585 result = SMB_VFS_NEXT_CHDIR(handle, smb_fname);
1587 do_log(SMB_VFS_OP_CHDIR, (result >= 0), handle, "chdir|%s",
1588 smb_fname->base_name);
1593 static struct smb_filename *smb_full_audit_getwd(vfs_handle_struct *handle,
1596 struct smb_filename *result;
1598 result = SMB_VFS_NEXT_GETWD(handle, ctx);
1600 do_log(SMB_VFS_OP_GETWD, (result != NULL), handle, "%s",
1601 result == NULL? "" : result->base_name);
1606 static int smb_full_audit_ntimes(vfs_handle_struct *handle,
1607 const struct smb_filename *smb_fname,
1608 struct smb_file_time *ft)
1611 time_t create_time = convert_timespec_to_time_t(ft->create_time);
1612 time_t atime = convert_timespec_to_time_t(ft->atime);
1613 time_t mtime = convert_timespec_to_time_t(ft->mtime);
1614 time_t ctime = convert_timespec_to_time_t(ft->ctime);
1615 const char *create_time_str = "";
1616 const char *atime_str = "";
1617 const char *mtime_str = "";
1618 const char *ctime_str = "";
1619 TALLOC_CTX *frame = talloc_stackframe();
1621 result = SMB_VFS_NEXT_NTIMES(handle, smb_fname, ft);
1623 if (create_time > 0) {
1624 create_time_str = timestring(frame, create_time);
1627 atime_str = timestring(frame, atime);
1630 mtime_str = timestring(frame, mtime);
1633 ctime_str = timestring(frame, ctime);
1636 do_log(SMB_VFS_OP_NTIMES,
1640 smb_fname_str_do_log(handle->conn, smb_fname),
1651 static int smb_full_audit_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
1656 result = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1658 do_log(SMB_VFS_OP_FTRUNCATE, (result >= 0), handle,
1659 "%s", fsp_str_do_log(fsp));
1664 static int smb_full_audit_fallocate(vfs_handle_struct *handle, files_struct *fsp,
1671 result = SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
1673 do_log(SMB_VFS_OP_FALLOCATE, (result >= 0), handle,
1674 "%s", fsp_str_do_log(fsp));
1679 static bool smb_full_audit_lock(vfs_handle_struct *handle, files_struct *fsp,
1680 int op, off_t offset, off_t count, int type)
1684 result = SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type);
1686 do_log(SMB_VFS_OP_LOCK, result, handle, "%s", fsp_str_do_log(fsp));
1691 static int smb_full_audit_kernel_flock(struct vfs_handle_struct *handle,
1692 struct files_struct *fsp,
1693 uint32_t share_mode, uint32_t access_mask)
1697 result = SMB_VFS_NEXT_KERNEL_FLOCK(handle, fsp, share_mode, access_mask);
1699 do_log(SMB_VFS_OP_KERNEL_FLOCK, (result >= 0), handle, "%s",
1700 fsp_str_do_log(fsp));
1705 static int smb_full_audit_linux_setlease(vfs_handle_struct *handle, files_struct *fsp,
1710 result = SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
1712 do_log(SMB_VFS_OP_LINUX_SETLEASE, (result >= 0), handle, "%s",
1713 fsp_str_do_log(fsp));
1718 static bool smb_full_audit_getlock(vfs_handle_struct *handle, files_struct *fsp,
1719 off_t *poffset, off_t *pcount, int *ptype, pid_t *ppid)
1723 result = SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype, ppid);
1725 do_log(SMB_VFS_OP_GETLOCK, result, handle, "%s", fsp_str_do_log(fsp));
1730 static int smb_full_audit_symlink(vfs_handle_struct *handle,
1731 const char *link_contents,
1732 const struct smb_filename *new_smb_fname)
1736 result = SMB_VFS_NEXT_SYMLINK(handle, link_contents, new_smb_fname);
1738 do_log(SMB_VFS_OP_SYMLINK, (result >= 0), handle,
1739 "%s|%s", link_contents, new_smb_fname->base_name);
1744 static int smb_full_audit_readlink(vfs_handle_struct *handle,
1745 const struct smb_filename *smb_fname,
1751 result = SMB_VFS_NEXT_READLINK(handle, smb_fname, buf, bufsiz);
1753 do_log(SMB_VFS_OP_READLINK, (result >= 0), handle, "%s",
1754 smb_fname->base_name);
1759 static int smb_full_audit_link(vfs_handle_struct *handle,
1760 const struct smb_filename *old_smb_fname,
1761 const struct smb_filename *new_smb_fname)
1765 result = SMB_VFS_NEXT_LINK(handle, old_smb_fname, new_smb_fname);
1767 do_log(SMB_VFS_OP_LINK, (result >= 0), handle,
1768 "%s|%s", old_smb_fname->base_name, new_smb_fname->base_name);
1773 static int smb_full_audit_linkat(vfs_handle_struct *handle,
1774 files_struct *srcfsp,
1775 const struct smb_filename *old_smb_fname,
1776 files_struct *dstfsp,
1777 const struct smb_filename *new_smb_fname,
1782 result = SMB_VFS_NEXT_LINKAT(handle,
1789 do_log(SMB_VFS_OP_LINKAT, (result >= 0), handle,
1790 "%s|%s", old_smb_fname->base_name, new_smb_fname->base_name);
1795 static int smb_full_audit_mknod(vfs_handle_struct *handle,
1796 const struct smb_filename *smb_fname,
1802 result = SMB_VFS_NEXT_MKNOD(handle, smb_fname, mode, dev);
1804 do_log(SMB_VFS_OP_MKNOD, (result >= 0), handle, "%s",
1805 smb_fname->base_name);
1810 static struct smb_filename *smb_full_audit_realpath(vfs_handle_struct *handle,
1812 const struct smb_filename *smb_fname)
1814 struct smb_filename *result_fname = NULL;
1816 result_fname = SMB_VFS_NEXT_REALPATH(handle, ctx, smb_fname);
1818 do_log(SMB_VFS_OP_REALPATH, (result_fname != NULL), handle, "%s",
1819 smb_fname->base_name);
1821 return result_fname;
1824 static int smb_full_audit_chflags(vfs_handle_struct *handle,
1825 const struct smb_filename *smb_fname,
1830 result = SMB_VFS_NEXT_CHFLAGS(handle, smb_fname, flags);
1832 do_log(SMB_VFS_OP_CHFLAGS, (result != 0), handle, "%s",
1833 smb_fname->base_name);
1838 static struct file_id smb_full_audit_file_id_create(struct vfs_handle_struct *handle,
1839 const SMB_STRUCT_STAT *sbuf)
1841 struct file_id id_zero;
1842 struct file_id result;
1844 ZERO_STRUCT(id_zero);
1846 result = SMB_VFS_NEXT_FILE_ID_CREATE(handle, sbuf);
1848 do_log(SMB_VFS_OP_FILE_ID_CREATE,
1849 !file_id_equal(&id_zero, &result),
1850 handle, "%s", file_id_string_tos(&result));
1855 static uint64_t smb_full_audit_fs_file_id(struct vfs_handle_struct *handle,
1856 const SMB_STRUCT_STAT *sbuf)
1860 result = SMB_VFS_NEXT_FS_FILE_ID(handle, sbuf);
1862 do_log(SMB_VFS_OP_FS_FILE_ID,
1864 handle, "%" PRIu64, result);
1869 static NTSTATUS smb_full_audit_streaminfo(vfs_handle_struct *handle,
1870 struct files_struct *fsp,
1871 const struct smb_filename *smb_fname,
1872 TALLOC_CTX *mem_ctx,
1873 unsigned int *pnum_streams,
1874 struct stream_struct **pstreams)
1878 result = SMB_VFS_NEXT_STREAMINFO(handle, fsp, smb_fname, mem_ctx,
1879 pnum_streams, pstreams);
1881 do_log(SMB_VFS_OP_STREAMINFO, NT_STATUS_IS_OK(result), handle,
1882 "%s", smb_fname->base_name);
1887 static int smb_full_audit_get_real_filename(struct vfs_handle_struct *handle,
1890 TALLOC_CTX *mem_ctx,
1895 result = SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name, mem_ctx,
1898 do_log(SMB_VFS_OP_GET_REAL_FILENAME, (result == 0), handle,
1899 "%s/%s->%s", path, name, (result == 0) ? *found_name : "");
1904 static const char *smb_full_audit_connectpath(vfs_handle_struct *handle,
1905 const struct smb_filename *smb_fname)
1909 result = SMB_VFS_NEXT_CONNECTPATH(handle, smb_fname);
1911 do_log(SMB_VFS_OP_CONNECTPATH, result != NULL, handle,
1912 "%s", smb_fname->base_name);
1917 static NTSTATUS smb_full_audit_brl_lock_windows(struct vfs_handle_struct *handle,
1918 struct byte_range_lock *br_lck,
1919 struct lock_struct *plock)
1923 result = SMB_VFS_NEXT_BRL_LOCK_WINDOWS(handle, br_lck, plock);
1925 do_log(SMB_VFS_OP_BRL_LOCK_WINDOWS, NT_STATUS_IS_OK(result), handle,
1926 "%s:%llu-%llu. type=%d.",
1927 fsp_str_do_log(brl_fsp(br_lck)),
1928 (unsigned long long)plock->start,
1929 (unsigned long long)plock->size,
1935 static bool smb_full_audit_brl_unlock_windows(struct vfs_handle_struct *handle,
1936 struct byte_range_lock *br_lck,
1937 const struct lock_struct *plock)
1941 result = SMB_VFS_NEXT_BRL_UNLOCK_WINDOWS(handle, br_lck, plock);
1943 do_log(SMB_VFS_OP_BRL_UNLOCK_WINDOWS, (result == 0), handle,
1944 "%s:%llu-%llu:%d", fsp_str_do_log(brl_fsp(br_lck)),
1945 (unsigned long long)plock->start,
1946 (unsigned long long)plock->size,
1952 static bool smb_full_audit_strict_lock_check(struct vfs_handle_struct *handle,
1953 struct files_struct *fsp,
1954 struct lock_struct *plock)
1958 result = SMB_VFS_NEXT_STRICT_LOCK_CHECK(handle, fsp, plock);
1960 do_log(SMB_VFS_OP_STRICT_LOCK_CHECK, result, handle,
1961 "%s:%llu-%llu:%d", fsp_str_do_log(fsp),
1962 (unsigned long long)plock->start,
1963 (unsigned long long)plock->size,
1969 static NTSTATUS smb_full_audit_translate_name(struct vfs_handle_struct *handle,
1971 enum vfs_translate_direction direction,
1972 TALLOC_CTX *mem_ctx,
1977 result = SMB_VFS_NEXT_TRANSLATE_NAME(handle, name, direction, mem_ctx,
1980 do_log(SMB_VFS_OP_TRANSLATE_NAME, NT_STATUS_IS_OK(result), handle, "");
1985 static NTSTATUS smb_full_audit_fsctl(struct vfs_handle_struct *handle,
1986 struct files_struct *fsp,
1990 const uint8_t *_in_data,
1992 uint8_t **_out_data,
1993 uint32_t max_out_len,
1998 result = SMB_VFS_NEXT_FSCTL(handle,
2009 do_log(SMB_VFS_OP_FSCTL, NT_STATUS_IS_OK(result), handle, "");
2014 static struct tevent_req *smb_full_audit_offload_read_send(
2015 TALLOC_CTX *mem_ctx,
2016 struct tevent_context *ev,
2017 struct vfs_handle_struct *handle,
2018 struct files_struct *fsp,
2024 struct tevent_req *req = NULL;
2026 req = SMB_VFS_NEXT_OFFLOAD_READ_SEND(mem_ctx, ev, handle, fsp,
2027 fsctl, ttl, offset, to_copy);
2029 do_log(SMB_VFS_OP_OFFLOAD_READ_SEND, req, handle, "");
2034 static NTSTATUS smb_full_audit_offload_read_recv(
2035 struct tevent_req *req,
2036 struct vfs_handle_struct *handle,
2037 TALLOC_CTX *mem_ctx,
2038 DATA_BLOB *_token_blob)
2042 status = SMB_VFS_NEXT_OFFLOAD_READ_RECV(req, handle, mem_ctx,
2045 do_log(SMB_VFS_OP_OFFLOAD_READ_RECV, NT_STATUS_IS_OK(status), handle, "");
2050 static struct tevent_req *smb_full_audit_offload_write_send(struct vfs_handle_struct *handle,
2051 TALLOC_CTX *mem_ctx,
2052 struct tevent_context *ev,
2055 off_t transfer_offset,
2056 struct files_struct *dest_fsp,
2060 struct tevent_req *req;
2062 req = SMB_VFS_NEXT_OFFLOAD_WRITE_SEND(handle, mem_ctx, ev,
2063 fsctl, token, transfer_offset,
2064 dest_fsp, dest_off, num);
2066 do_log(SMB_VFS_OP_OFFLOAD_WRITE_SEND, req, handle, "");
2071 static NTSTATUS smb_full_audit_offload_write_recv(struct vfs_handle_struct *handle,
2072 struct tevent_req *req,
2077 result = SMB_VFS_NEXT_OFFLOAD_WRITE_RECV(handle, req, copied);
2079 do_log(SMB_VFS_OP_OFFLOAD_WRITE_RECV, NT_STATUS_IS_OK(result), handle, "");
2084 static NTSTATUS smb_full_audit_get_compression(vfs_handle_struct *handle,
2085 TALLOC_CTX *mem_ctx,
2086 struct files_struct *fsp,
2087 struct smb_filename *smb_fname,
2088 uint16_t *_compression_fmt)
2092 result = SMB_VFS_NEXT_GET_COMPRESSION(handle, mem_ctx, fsp, smb_fname,
2095 do_log(SMB_VFS_OP_GET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
2097 (fsp ? fsp_str_do_log(fsp) :
2098 smb_fname_str_do_log(handle->conn, smb_fname)));
2103 static NTSTATUS smb_full_audit_set_compression(vfs_handle_struct *handle,
2104 TALLOC_CTX *mem_ctx,
2105 struct files_struct *fsp,
2106 uint16_t compression_fmt)
2110 result = SMB_VFS_NEXT_SET_COMPRESSION(handle, mem_ctx, fsp,
2113 do_log(SMB_VFS_OP_SET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
2114 "%s", fsp_str_do_log(fsp));
2119 static NTSTATUS smb_full_audit_readdir_attr(struct vfs_handle_struct *handle,
2120 const struct smb_filename *fname,
2121 TALLOC_CTX *mem_ctx,
2122 struct readdir_attr_data **pattr_data)
2126 status = SMB_VFS_NEXT_READDIR_ATTR(handle, fname, mem_ctx, pattr_data);
2128 do_log(SMB_VFS_OP_READDIR_ATTR, NT_STATUS_IS_OK(status), handle, "%s",
2129 smb_fname_str_do_log(handle->conn, fname));
2134 static NTSTATUS smb_full_audit_get_dos_attributes(
2135 struct vfs_handle_struct *handle,
2136 struct smb_filename *smb_fname,
2141 status = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES(handle,
2145 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES,
2146 NT_STATUS_IS_OK(status),
2149 smb_fname_str_do_log(handle->conn, smb_fname));
2154 struct smb_full_audit_get_dos_attributes_state {
2155 struct vfs_aio_state aio_state;
2156 vfs_handle_struct *handle;
2157 files_struct *dir_fsp;
2158 const struct smb_filename *smb_fname;
2162 static void smb_full_audit_get_dos_attributes_done(struct tevent_req *subreq);
2164 static struct tevent_req *smb_full_audit_get_dos_attributes_send(
2165 TALLOC_CTX *mem_ctx,
2166 struct tevent_context *ev,
2167 struct vfs_handle_struct *handle,
2168 files_struct *dir_fsp,
2169 struct smb_filename *smb_fname)
2171 struct tevent_req *req = NULL;
2172 struct smb_full_audit_get_dos_attributes_state *state = NULL;
2173 struct tevent_req *subreq = NULL;
2175 req = tevent_req_create(mem_ctx, &state,
2176 struct smb_full_audit_get_dos_attributes_state);
2178 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2182 fsp_str_do_log(dir_fsp),
2183 smb_fname->base_name);
2186 *state = (struct smb_full_audit_get_dos_attributes_state) {
2189 .smb_fname = smb_fname,
2192 subreq = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES_SEND(mem_ctx,
2197 if (tevent_req_nomem(subreq, req)) {
2198 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2202 fsp_str_do_log(dir_fsp),
2203 smb_fname->base_name);
2204 return tevent_req_post(req, ev);
2206 tevent_req_set_callback(subreq,
2207 smb_full_audit_get_dos_attributes_done,
2210 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2214 fsp_str_do_log(dir_fsp),
2215 smb_fname->base_name);
2220 static void smb_full_audit_get_dos_attributes_done(struct tevent_req *subreq)
2222 struct tevent_req *req =
2223 tevent_req_callback_data(subreq,
2225 struct smb_full_audit_get_dos_attributes_state *state =
2226 tevent_req_data(req,
2227 struct smb_full_audit_get_dos_attributes_state);
2230 status = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES_RECV(subreq,
2233 TALLOC_FREE(subreq);
2234 if (tevent_req_nterror(req, status)) {
2238 tevent_req_done(req);
2242 static NTSTATUS smb_full_audit_get_dos_attributes_recv(struct tevent_req *req,
2243 struct vfs_aio_state *aio_state,
2246 struct smb_full_audit_get_dos_attributes_state *state =
2247 tevent_req_data(req,
2248 struct smb_full_audit_get_dos_attributes_state);
2251 if (tevent_req_is_nterror(req, &status)) {
2252 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV,
2256 fsp_str_do_log(state->dir_fsp),
2257 state->smb_fname->base_name);
2258 tevent_req_received(req);
2262 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV,
2266 fsp_str_do_log(state->dir_fsp),
2267 state->smb_fname->base_name);
2269 *aio_state = state->aio_state;
2270 *dosmode = state->dosmode;
2271 tevent_req_received(req);
2272 return NT_STATUS_OK;
2275 static NTSTATUS smb_full_audit_fget_dos_attributes(
2276 struct vfs_handle_struct *handle,
2277 struct files_struct *fsp,
2282 status = SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle,
2286 do_log(SMB_VFS_OP_FGET_DOS_ATTRIBUTES,
2287 NT_STATUS_IS_OK(status),
2290 fsp_str_do_log(fsp));
2295 static NTSTATUS smb_full_audit_set_dos_attributes(
2296 struct vfs_handle_struct *handle,
2297 const struct smb_filename *smb_fname,
2302 status = SMB_VFS_NEXT_SET_DOS_ATTRIBUTES(handle,
2306 do_log(SMB_VFS_OP_SET_DOS_ATTRIBUTES,
2307 NT_STATUS_IS_OK(status),
2310 smb_fname_str_do_log(handle->conn, smb_fname));
2315 static NTSTATUS smb_full_audit_fset_dos_attributes(
2316 struct vfs_handle_struct *handle,
2317 struct files_struct *fsp,
2322 status = SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle,
2326 do_log(SMB_VFS_OP_FSET_DOS_ATTRIBUTES,
2327 NT_STATUS_IS_OK(status),
2330 fsp_str_do_log(fsp));
2335 static NTSTATUS smb_full_audit_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
2336 uint32_t security_info,
2337 TALLOC_CTX *mem_ctx,
2338 struct security_descriptor **ppdesc)
2342 result = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
2345 do_log(SMB_VFS_OP_FGET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2346 "%s", fsp_str_do_log(fsp));
2351 static NTSTATUS smb_full_audit_get_nt_acl(vfs_handle_struct *handle,
2352 const struct smb_filename *smb_fname,
2353 uint32_t security_info,
2354 TALLOC_CTX *mem_ctx,
2355 struct security_descriptor **ppdesc)
2359 result = SMB_VFS_NEXT_GET_NT_ACL(handle, smb_fname, security_info,
2362 do_log(SMB_VFS_OP_GET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2363 "%s", smb_fname_str_do_log(handle->conn, smb_fname));
2368 static NTSTATUS smb_full_audit_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
2369 uint32_t security_info_sent,
2370 const struct security_descriptor *psd)
2372 struct vfs_full_audit_private_data *pd;
2376 SMB_VFS_HANDLE_GET_DATA(handle, pd,
2377 struct vfs_full_audit_private_data,
2378 return NT_STATUS_INTERNAL_ERROR);
2380 if (pd->log_secdesc) {
2381 sd = sddl_encode(talloc_tos(), psd, get_global_sam_sid());
2384 result = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
2386 do_log(SMB_VFS_OP_FSET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2387 "%s [%s]", fsp_str_do_log(fsp), sd ? sd : "");
2394 static NTSTATUS smb_full_audit_audit_file(struct vfs_handle_struct *handle,
2395 struct smb_filename *file,
2396 struct security_acl *sacl,
2397 uint32_t access_requested,
2398 uint32_t access_denied)
2402 result = SMB_VFS_NEXT_AUDIT_FILE(handle,
2408 do_log(SMB_VFS_OP_AUDIT_FILE, NT_STATUS_IS_OK(result), handle,
2410 smb_fname_str_do_log(handle->conn, file));
2415 static SMB_ACL_T smb_full_audit_sys_acl_get_file(vfs_handle_struct *handle,
2416 const struct smb_filename *smb_fname,
2417 SMB_ACL_TYPE_T type,
2418 TALLOC_CTX *mem_ctx)
2422 result = SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, smb_fname,
2425 do_log(SMB_VFS_OP_SYS_ACL_GET_FILE, (result != NULL), handle,
2426 "%s", smb_fname->base_name);
2431 static SMB_ACL_T smb_full_audit_sys_acl_get_fd(vfs_handle_struct *handle,
2432 files_struct *fsp, TALLOC_CTX *mem_ctx)
2436 result = SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp, mem_ctx);
2438 do_log(SMB_VFS_OP_SYS_ACL_GET_FD, (result != NULL), handle,
2439 "%s", fsp_str_do_log(fsp));
2444 static int smb_full_audit_sys_acl_blob_get_file(vfs_handle_struct *handle,
2445 const struct smb_filename *smb_fname,
2446 TALLOC_CTX *mem_ctx,
2447 char **blob_description,
2452 result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FILE(handle, smb_fname,
2453 mem_ctx, blob_description, blob);
2455 do_log(SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE, (result >= 0), handle,
2456 "%s", smb_fname->base_name);
2461 static int smb_full_audit_sys_acl_blob_get_fd(vfs_handle_struct *handle,
2463 TALLOC_CTX *mem_ctx,
2464 char **blob_description,
2469 result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle, fsp, mem_ctx, blob_description, blob);
2471 do_log(SMB_VFS_OP_SYS_ACL_BLOB_GET_FD, (result >= 0), handle,
2472 "%s", fsp_str_do_log(fsp));
2477 static int smb_full_audit_sys_acl_set_file(vfs_handle_struct *handle,
2478 const struct smb_filename *smb_fname,
2479 SMB_ACL_TYPE_T acltype,
2484 result = SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, smb_fname, acltype,
2487 do_log(SMB_VFS_OP_SYS_ACL_SET_FILE, (result >= 0), handle,
2488 "%s", smb_fname->base_name);
2493 static int smb_full_audit_sys_acl_set_fd(vfs_handle_struct *handle, files_struct *fsp,
2498 result = SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, theacl);
2500 do_log(SMB_VFS_OP_SYS_ACL_SET_FD, (result >= 0), handle,
2501 "%s", fsp_str_do_log(fsp));
2506 static int smb_full_audit_sys_acl_delete_def_file(vfs_handle_struct *handle,
2507 const struct smb_filename *smb_fname)
2511 result = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, smb_fname);
2513 do_log(SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE, (result >= 0), handle,
2514 "%s", smb_fname->base_name);
2519 static ssize_t smb_full_audit_getxattr(struct vfs_handle_struct *handle,
2520 const struct smb_filename *smb_fname,
2521 const char *name, void *value, size_t size)
2525 result = SMB_VFS_NEXT_GETXATTR(handle, smb_fname, name, value, size);
2527 do_log(SMB_VFS_OP_GETXATTR, (result >= 0), handle,
2528 "%s|%s", smb_fname->base_name, name);
2533 struct smb_full_audit_getxattrat_state {
2534 struct vfs_aio_state aio_state;
2535 vfs_handle_struct *handle;
2536 files_struct *dir_fsp;
2537 const struct smb_filename *smb_fname;
2538 const char *xattr_name;
2540 uint8_t *xattr_value;
2543 static void smb_full_audit_getxattrat_done(struct tevent_req *subreq);
2545 static struct tevent_req *smb_full_audit_getxattrat_send(
2546 TALLOC_CTX *mem_ctx,
2547 struct tevent_context *ev,
2548 struct vfs_handle_struct *handle,
2549 files_struct *dir_fsp,
2550 const struct smb_filename *smb_fname,
2551 const char *xattr_name,
2554 struct tevent_req *req = NULL;
2555 struct tevent_req *subreq = NULL;
2556 struct smb_full_audit_getxattrat_state *state = NULL;
2558 req = tevent_req_create(mem_ctx, &state,
2559 struct smb_full_audit_getxattrat_state);
2561 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2565 fsp_str_do_log(dir_fsp),
2566 smb_fname->base_name,
2570 *state = (struct smb_full_audit_getxattrat_state) {
2573 .smb_fname = smb_fname,
2574 .xattr_name = xattr_name,
2577 subreq = SMB_VFS_NEXT_GETXATTRAT_SEND(state,
2584 if (tevent_req_nomem(subreq, req)) {
2585 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2589 fsp_str_do_log(dir_fsp),
2590 smb_fname->base_name,
2592 return tevent_req_post(req, ev);
2594 tevent_req_set_callback(subreq, smb_full_audit_getxattrat_done, req);
2596 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2600 fsp_str_do_log(dir_fsp),
2601 smb_fname->base_name,
2607 static void smb_full_audit_getxattrat_done(struct tevent_req *subreq)
2609 struct tevent_req *req = tevent_req_callback_data(
2610 subreq, struct tevent_req);
2611 struct smb_full_audit_getxattrat_state *state = tevent_req_data(
2612 req, struct smb_full_audit_getxattrat_state);
2614 state->xattr_size = SMB_VFS_NEXT_GETXATTRAT_RECV(subreq,
2617 &state->xattr_value);
2618 TALLOC_FREE(subreq);
2619 if (state->xattr_size == -1) {
2620 tevent_req_error(req, state->aio_state.error);
2624 tevent_req_done(req);
2627 static ssize_t smb_full_audit_getxattrat_recv(struct tevent_req *req,
2628 struct vfs_aio_state *aio_state,
2629 TALLOC_CTX *mem_ctx,
2630 uint8_t **xattr_value)
2632 struct smb_full_audit_getxattrat_state *state = tevent_req_data(
2633 req, struct smb_full_audit_getxattrat_state);
2636 if (tevent_req_is_unix_error(req, &aio_state->error)) {
2637 do_log(SMB_VFS_OP_GETXATTRAT_RECV,
2641 fsp_str_do_log(state->dir_fsp),
2642 state->smb_fname->base_name,
2644 tevent_req_received(req);
2648 do_log(SMB_VFS_OP_GETXATTRAT_RECV,
2652 fsp_str_do_log(state->dir_fsp),
2653 state->smb_fname->base_name,
2656 *aio_state = state->aio_state;
2657 xattr_size = state->xattr_size;
2658 if (xattr_value != NULL) {
2659 *xattr_value = talloc_move(mem_ctx, &state->xattr_value);
2662 tevent_req_received(req);
2666 static ssize_t smb_full_audit_fgetxattr(struct vfs_handle_struct *handle,
2667 struct files_struct *fsp,
2668 const char *name, void *value, size_t size)
2672 result = SMB_VFS_NEXT_FGETXATTR(handle, fsp, name, value, size);
2674 do_log(SMB_VFS_OP_FGETXATTR, (result >= 0), handle,
2675 "%s|%s", fsp_str_do_log(fsp), name);
2680 static ssize_t smb_full_audit_listxattr(struct vfs_handle_struct *handle,
2681 const struct smb_filename *smb_fname,
2687 result = SMB_VFS_NEXT_LISTXATTR(handle, smb_fname, list, size);
2689 do_log(SMB_VFS_OP_LISTXATTR, (result >= 0), handle, "%s",
2690 smb_fname->base_name);
2695 static ssize_t smb_full_audit_flistxattr(struct vfs_handle_struct *handle,
2696 struct files_struct *fsp, char *list,
2701 result = SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
2703 do_log(SMB_VFS_OP_FLISTXATTR, (result >= 0), handle,
2704 "%s", fsp_str_do_log(fsp));
2709 static int smb_full_audit_removexattr(struct vfs_handle_struct *handle,
2710 const struct smb_filename *smb_fname,
2715 result = SMB_VFS_NEXT_REMOVEXATTR(handle, smb_fname, name);
2717 do_log(SMB_VFS_OP_REMOVEXATTR, (result >= 0), handle,
2718 "%s|%s", smb_fname->base_name, name);
2723 static int smb_full_audit_fremovexattr(struct vfs_handle_struct *handle,
2724 struct files_struct *fsp,
2729 result = SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, name);
2731 do_log(SMB_VFS_OP_FREMOVEXATTR, (result >= 0), handle,
2732 "%s|%s", fsp_str_do_log(fsp), name);
2737 static int smb_full_audit_setxattr(struct vfs_handle_struct *handle,
2738 const struct smb_filename *smb_fname,
2739 const char *name, const void *value, size_t size,
2744 result = SMB_VFS_NEXT_SETXATTR(handle, smb_fname, name, value, size,
2747 do_log(SMB_VFS_OP_SETXATTR, (result >= 0), handle,
2748 "%s|%s", smb_fname->base_name, name);
2753 static int smb_full_audit_fsetxattr(struct vfs_handle_struct *handle,
2754 struct files_struct *fsp, const char *name,
2755 const void *value, size_t size, int flags)
2759 result = SMB_VFS_NEXT_FSETXATTR(handle, fsp, name, value, size, flags);
2761 do_log(SMB_VFS_OP_FSETXATTR, (result >= 0), handle,
2762 "%s|%s", fsp_str_do_log(fsp), name);
2767 static bool smb_full_audit_aio_force(struct vfs_handle_struct *handle,
2768 struct files_struct *fsp)
2772 result = SMB_VFS_NEXT_AIO_FORCE(handle, fsp);
2773 do_log(SMB_VFS_OP_AIO_FORCE, result, handle,
2774 "%s", fsp_str_do_log(fsp));
2779 static NTSTATUS smb_full_audit_durable_cookie(struct vfs_handle_struct *handle,
2780 struct files_struct *fsp,
2781 TALLOC_CTX *mem_ctx,
2786 result = SMB_VFS_NEXT_DURABLE_COOKIE(handle,
2791 do_log(SMB_VFS_OP_DURABLE_COOKIE, NT_STATUS_IS_OK(result), handle,
2792 "%s", fsp_str_do_log(fsp));
2797 static NTSTATUS smb_full_audit_durable_disconnect(
2798 struct vfs_handle_struct *handle,
2799 struct files_struct *fsp,
2800 const DATA_BLOB old_cookie,
2801 TALLOC_CTX *mem_ctx,
2802 DATA_BLOB *new_cookie)
2806 result = SMB_VFS_NEXT_DURABLE_DISCONNECT(handle,
2812 do_log(SMB_VFS_OP_DURABLE_DISCONNECT, NT_STATUS_IS_OK(result), handle,
2813 "%s", fsp_str_do_log(fsp));
2818 static NTSTATUS smb_full_audit_durable_reconnect(
2819 struct vfs_handle_struct *handle,
2820 struct smb_request *smb1req,
2821 struct smbXsrv_open *op,
2822 const DATA_BLOB old_cookie,
2823 TALLOC_CTX *mem_ctx,
2824 struct files_struct **fsp,
2825 DATA_BLOB *new_cookie)
2829 result = SMB_VFS_NEXT_DURABLE_RECONNECT(handle,
2837 do_log(SMB_VFS_OP_DURABLE_RECONNECT,
2838 NT_STATUS_IS_OK(result),
2845 static struct vfs_fn_pointers vfs_full_audit_fns = {
2847 /* Disk operations */
2849 .connect_fn = smb_full_audit_connect,
2850 .disconnect_fn = smb_full_audit_disconnect,
2851 .disk_free_fn = smb_full_audit_disk_free,
2852 .get_quota_fn = smb_full_audit_get_quota,
2853 .set_quota_fn = smb_full_audit_set_quota,
2854 .get_shadow_copy_data_fn = smb_full_audit_get_shadow_copy_data,
2855 .statvfs_fn = smb_full_audit_statvfs,
2856 .fs_capabilities_fn = smb_full_audit_fs_capabilities,
2857 .get_dfs_referrals_fn = smb_full_audit_get_dfs_referrals,
2858 .opendir_fn = smb_full_audit_opendir,
2859 .fdopendir_fn = smb_full_audit_fdopendir,
2860 .readdir_fn = smb_full_audit_readdir,
2861 .seekdir_fn = smb_full_audit_seekdir,
2862 .telldir_fn = smb_full_audit_telldir,
2863 .rewind_dir_fn = smb_full_audit_rewinddir,
2864 .mkdir_fn = smb_full_audit_mkdir,
2865 .rmdir_fn = smb_full_audit_rmdir,
2866 .closedir_fn = smb_full_audit_closedir,
2867 .open_fn = smb_full_audit_open,
2868 .create_file_fn = smb_full_audit_create_file,
2869 .close_fn = smb_full_audit_close,
2870 .pread_fn = smb_full_audit_pread,
2871 .pread_send_fn = smb_full_audit_pread_send,
2872 .pread_recv_fn = smb_full_audit_pread_recv,
2873 .pwrite_fn = smb_full_audit_pwrite,
2874 .pwrite_send_fn = smb_full_audit_pwrite_send,
2875 .pwrite_recv_fn = smb_full_audit_pwrite_recv,
2876 .lseek_fn = smb_full_audit_lseek,
2877 .sendfile_fn = smb_full_audit_sendfile,
2878 .recvfile_fn = smb_full_audit_recvfile,
2879 .renameat_fn = smb_full_audit_renameat,
2880 .fsync_send_fn = smb_full_audit_fsync_send,
2881 .fsync_recv_fn = smb_full_audit_fsync_recv,
2882 .stat_fn = smb_full_audit_stat,
2883 .fstat_fn = smb_full_audit_fstat,
2884 .lstat_fn = smb_full_audit_lstat,
2885 .get_alloc_size_fn = smb_full_audit_get_alloc_size,
2886 .unlink_fn = smb_full_audit_unlink,
2887 .chmod_fn = smb_full_audit_chmod,
2888 .fchmod_fn = smb_full_audit_fchmod,
2889 .chown_fn = smb_full_audit_chown,
2890 .fchown_fn = smb_full_audit_fchown,
2891 .lchown_fn = smb_full_audit_lchown,
2892 .chdir_fn = smb_full_audit_chdir,
2893 .getwd_fn = smb_full_audit_getwd,
2894 .ntimes_fn = smb_full_audit_ntimes,
2895 .ftruncate_fn = smb_full_audit_ftruncate,
2896 .fallocate_fn = smb_full_audit_fallocate,
2897 .lock_fn = smb_full_audit_lock,
2898 .kernel_flock_fn = smb_full_audit_kernel_flock,
2899 .linux_setlease_fn = smb_full_audit_linux_setlease,
2900 .getlock_fn = smb_full_audit_getlock,
2901 .symlink_fn = smb_full_audit_symlink,
2902 .readlink_fn = smb_full_audit_readlink,
2903 .link_fn = smb_full_audit_link,
2904 .linkat_fn = smb_full_audit_linkat,
2905 .mknod_fn = smb_full_audit_mknod,
2906 .realpath_fn = smb_full_audit_realpath,
2907 .chflags_fn = smb_full_audit_chflags,
2908 .file_id_create_fn = smb_full_audit_file_id_create,
2909 .fs_file_id_fn = smb_full_audit_fs_file_id,
2910 .offload_read_send_fn = smb_full_audit_offload_read_send,
2911 .offload_read_recv_fn = smb_full_audit_offload_read_recv,
2912 .offload_write_send_fn = smb_full_audit_offload_write_send,
2913 .offload_write_recv_fn = smb_full_audit_offload_write_recv,
2914 .get_compression_fn = smb_full_audit_get_compression,
2915 .set_compression_fn = smb_full_audit_set_compression,
2916 .snap_check_path_fn = smb_full_audit_snap_check_path,
2917 .snap_create_fn = smb_full_audit_snap_create,
2918 .snap_delete_fn = smb_full_audit_snap_delete,
2919 .streaminfo_fn = smb_full_audit_streaminfo,
2920 .get_real_filename_fn = smb_full_audit_get_real_filename,
2921 .connectpath_fn = smb_full_audit_connectpath,
2922 .brl_lock_windows_fn = smb_full_audit_brl_lock_windows,
2923 .brl_unlock_windows_fn = smb_full_audit_brl_unlock_windows,
2924 .strict_lock_check_fn = smb_full_audit_strict_lock_check,
2925 .translate_name_fn = smb_full_audit_translate_name,
2926 .fsctl_fn = smb_full_audit_fsctl,
2927 .get_dos_attributes_fn = smb_full_audit_get_dos_attributes,
2928 .get_dos_attributes_send_fn = smb_full_audit_get_dos_attributes_send,
2929 .get_dos_attributes_recv_fn = smb_full_audit_get_dos_attributes_recv,
2930 .fget_dos_attributes_fn = smb_full_audit_fget_dos_attributes,
2931 .set_dos_attributes_fn = smb_full_audit_set_dos_attributes,
2932 .fset_dos_attributes_fn = smb_full_audit_fset_dos_attributes,
2933 .fget_nt_acl_fn = smb_full_audit_fget_nt_acl,
2934 .get_nt_acl_fn = smb_full_audit_get_nt_acl,
2935 .fset_nt_acl_fn = smb_full_audit_fset_nt_acl,
2936 .audit_file_fn = smb_full_audit_audit_file,
2937 .sys_acl_get_file_fn = smb_full_audit_sys_acl_get_file,
2938 .sys_acl_get_fd_fn = smb_full_audit_sys_acl_get_fd,
2939 .sys_acl_blob_get_file_fn = smb_full_audit_sys_acl_blob_get_file,
2940 .sys_acl_blob_get_fd_fn = smb_full_audit_sys_acl_blob_get_fd,
2941 .sys_acl_set_file_fn = smb_full_audit_sys_acl_set_file,
2942 .sys_acl_set_fd_fn = smb_full_audit_sys_acl_set_fd,
2943 .sys_acl_delete_def_file_fn = smb_full_audit_sys_acl_delete_def_file,
2944 .getxattr_fn = smb_full_audit_getxattr,
2945 .getxattrat_send_fn = smb_full_audit_getxattrat_send,
2946 .getxattrat_recv_fn = smb_full_audit_getxattrat_recv,
2947 .fgetxattr_fn = smb_full_audit_fgetxattr,
2948 .listxattr_fn = smb_full_audit_listxattr,
2949 .flistxattr_fn = smb_full_audit_flistxattr,
2950 .removexattr_fn = smb_full_audit_removexattr,
2951 .fremovexattr_fn = smb_full_audit_fremovexattr,
2952 .setxattr_fn = smb_full_audit_setxattr,
2953 .fsetxattr_fn = smb_full_audit_fsetxattr,
2954 .aio_force_fn = smb_full_audit_aio_force,
2955 .durable_cookie_fn = smb_full_audit_durable_cookie,
2956 .durable_disconnect_fn = smb_full_audit_durable_disconnect,
2957 .durable_reconnect_fn = smb_full_audit_durable_reconnect,
2958 .readdir_attr_fn = smb_full_audit_readdir_attr
2963 NTSTATUS vfs_full_audit_init(TALLOC_CTX *ctx)
2967 smb_vfs_assert_all_fns(&vfs_full_audit_fns, "full_audit");
2969 ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "full_audit",
2970 &vfs_full_audit_fns);
2972 if (!NT_STATUS_IS_OK(ret))
2975 vfs_full_audit_debug_level = debug_add_class("full_audit");
2976 if (vfs_full_audit_debug_level == -1) {
2977 vfs_full_audit_debug_level = DBGC_VFS;
2978 DEBUG(0, ("vfs_full_audit: Couldn't register custom debugging "
2981 DEBUG(10, ("vfs_full_audit: Debug class number of "
2982 "'full_audit': %d\n", vfs_full_audit_debug_level));