2 * Auditing VFS module for samba. Log selected file operations to syslog
5 * Copyright (C) Tim Potter, 1999-2000
6 * Copyright (C) Alexander Bokovoy, 2002
7 * Copyright (C) John H Terpstra, 2003
8 * Copyright (C) Stefan (metze) Metzmacher, 2003
9 * Copyright (C) Volker Lendecke, 2004
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, see <http://www.gnu.org/licenses/>.
26 * This module implements parseable logging for all Samba VFS operations.
28 * You use it as follows:
32 * vfs objects = full_audit
33 * full_audit:prefix = %u|%I
34 * full_audit:success = open opendir create_file
35 * full_audit:failure = all
37 * vfs op can be "all" which means log all operations.
38 * vfs op can be "none" which means no logging.
40 * This leads to syslog entries of the form:
41 * smbd_audit: nobody|192.168.234.1|opendir|ok|/tmp
42 * smbd_audit: nobody|192.168.234.1|create_file|fail (No such file or directory)|0x1|file|open|/ts/doesNotExist
43 * smbd_audit: nobody|192.168.234.1|open|ok|w|/tmp/file.txt
44 * smbd_audit: nobody|192.168.234.1|create_file|ok|0x3|file|open|/tmp/file.txt
46 * where "nobody" is the connected username and "192.168.234.1" is the
47 * client's IP address.
51 * prefix: A macro expansion template prepended to the syslog entry.
53 * success: A list of VFS operations for which a successful completion should
54 * be logged. Defaults to no logging at all. The special operation "all" logs
55 * - you guessed it - everything.
57 * failure: A list of VFS operations for which failure to complete should be
58 * logged. Defaults to logging everything.
63 #include "system/filesys.h"
64 #include "system/syslog.h"
65 #include "smbd/smbd.h"
66 #include "../librpc/gen_ndr/ndr_netlogon.h"
69 #include "lib/param/loadparm.h"
70 #include "lib/util/bitmap.h"
71 #include "lib/util/tevent_unix.h"
72 #include "libcli/security/sddl.h"
73 #include "passdb/machine_sid.h"
74 #include "lib/util/tevent_ntstatus.h"
76 static int vfs_full_audit_debug_level = DBGC_VFS;
78 struct vfs_full_audit_private_data {
79 struct bitmap *success_ops;
80 struct bitmap *failure_ops;
88 #define DBGC_CLASS vfs_full_audit_debug_level
90 typedef enum _vfs_op_type {
95 SMB_VFS_OP_CONNECT = 0,
96 SMB_VFS_OP_DISCONNECT,
100 SMB_VFS_OP_GET_SHADOW_COPY_DATA,
102 SMB_VFS_OP_FS_CAPABILITIES,
103 SMB_VFS_OP_GET_DFS_REFERRALS,
104 SMB_VFS_OP_CREATE_DFS_PATHAT,
105 SMB_VFS_OP_READ_DFS_PATHAT,
107 /* Directory operations */
109 SMB_VFS_OP_FDOPENDIR,
113 SMB_VFS_OP_REWINDDIR,
117 /* File operations */
120 SMB_VFS_OP_CREATE_FILE,
124 SMB_VFS_OP_PREAD_SEND,
125 SMB_VFS_OP_PREAD_RECV,
128 SMB_VFS_OP_PWRITE_SEND,
129 SMB_VFS_OP_PWRITE_RECV,
135 SMB_VFS_OP_FSYNC_SEND,
136 SMB_VFS_OP_FSYNC_RECV,
140 SMB_VFS_OP_GET_ALLOC_SIZE,
149 SMB_VFS_OP_FTRUNCATE,
150 SMB_VFS_OP_FALLOCATE,
152 SMB_VFS_OP_KERNEL_FLOCK,
154 SMB_VFS_OP_LINUX_SETLEASE,
156 SMB_VFS_OP_SYMLINKAT,
157 SMB_VFS_OP_READLINKAT,
162 SMB_VFS_OP_FILE_ID_CREATE,
163 SMB_VFS_OP_FS_FILE_ID,
164 SMB_VFS_OP_STREAMINFO,
165 SMB_VFS_OP_GET_REAL_FILENAME,
166 SMB_VFS_OP_CONNECTPATH,
167 SMB_VFS_OP_BRL_LOCK_WINDOWS,
168 SMB_VFS_OP_BRL_UNLOCK_WINDOWS,
169 SMB_VFS_OP_STRICT_LOCK_CHECK,
170 SMB_VFS_OP_TRANSLATE_NAME,
172 SMB_VFS_OP_OFFLOAD_READ_SEND,
173 SMB_VFS_OP_OFFLOAD_READ_RECV,
174 SMB_VFS_OP_OFFLOAD_WRITE_SEND,
175 SMB_VFS_OP_OFFLOAD_WRITE_RECV,
176 SMB_VFS_OP_GET_COMPRESSION,
177 SMB_VFS_OP_SET_COMPRESSION,
178 SMB_VFS_OP_SNAP_CHECK_PATH,
179 SMB_VFS_OP_SNAP_CREATE,
180 SMB_VFS_OP_SNAP_DELETE,
182 /* DOS attribute operations. */
183 SMB_VFS_OP_GET_DOS_ATTRIBUTES,
184 SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
185 SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV,
186 SMB_VFS_OP_FGET_DOS_ATTRIBUTES,
187 SMB_VFS_OP_SET_DOS_ATTRIBUTES,
188 SMB_VFS_OP_FSET_DOS_ATTRIBUTES,
190 /* NT ACL operations. */
192 SMB_VFS_OP_FGET_NT_ACL,
193 SMB_VFS_OP_GET_NT_ACL,
194 SMB_VFS_OP_FSET_NT_ACL,
195 SMB_VFS_OP_AUDIT_FILE,
197 /* POSIX ACL operations. */
199 SMB_VFS_OP_SYS_ACL_GET_FILE,
200 SMB_VFS_OP_SYS_ACL_GET_FD,
201 SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE,
202 SMB_VFS_OP_SYS_ACL_BLOB_GET_FD,
203 SMB_VFS_OP_SYS_ACL_SET_FILE,
204 SMB_VFS_OP_SYS_ACL_SET_FD,
205 SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE,
209 SMB_VFS_OP_GETXATTRAT_SEND,
210 SMB_VFS_OP_GETXATTRAT_RECV,
211 SMB_VFS_OP_FGETXATTR,
212 SMB_VFS_OP_LISTXATTR,
213 SMB_VFS_OP_FLISTXATTR,
214 SMB_VFS_OP_REMOVEXATTR,
215 SMB_VFS_OP_FREMOVEXATTR,
217 SMB_VFS_OP_FSETXATTR,
220 SMB_VFS_OP_AIO_FORCE,
222 /* offline operations */
223 SMB_VFS_OP_IS_OFFLINE,
224 SMB_VFS_OP_SET_OFFLINE,
226 /* Durable handle operations. */
227 SMB_VFS_OP_DURABLE_COOKIE,
228 SMB_VFS_OP_DURABLE_DISCONNECT,
229 SMB_VFS_OP_DURABLE_RECONNECT,
231 SMB_VFS_OP_READDIR_ATTR,
233 /* This should always be last enum value */
238 /* The following array *must* be in the same order as defined in vfs_op_type */
244 { SMB_VFS_OP_CONNECT, "connect" },
245 { SMB_VFS_OP_DISCONNECT, "disconnect" },
246 { SMB_VFS_OP_DISK_FREE, "disk_free" },
247 { SMB_VFS_OP_GET_QUOTA, "get_quota" },
248 { SMB_VFS_OP_SET_QUOTA, "set_quota" },
249 { SMB_VFS_OP_GET_SHADOW_COPY_DATA, "get_shadow_copy_data" },
250 { SMB_VFS_OP_STATVFS, "statvfs" },
251 { SMB_VFS_OP_FS_CAPABILITIES, "fs_capabilities" },
252 { SMB_VFS_OP_GET_DFS_REFERRALS, "get_dfs_referrals" },
253 { SMB_VFS_OP_CREATE_DFS_PATHAT, "create_dfs_pathat" },
254 { SMB_VFS_OP_READ_DFS_PATHAT, "read_dfs_pathat" },
255 { SMB_VFS_OP_FDOPENDIR, "fdopendir" },
256 { SMB_VFS_OP_READDIR, "readdir" },
257 { SMB_VFS_OP_SEEKDIR, "seekdir" },
258 { SMB_VFS_OP_TELLDIR, "telldir" },
259 { SMB_VFS_OP_REWINDDIR, "rewinddir" },
260 { SMB_VFS_OP_MKDIRAT, "mkdirat" },
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_UNLINKAT, "unlinkat" },
285 { SMB_VFS_OP_CHMOD, "chmod" },
286 { SMB_VFS_OP_FCHMOD, "fchmod" },
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_SYMLINKAT, "symlinkat" },
299 { SMB_VFS_OP_READLINKAT,"readlinkat" },
300 { SMB_VFS_OP_LINKAT, "linkat" },
301 { SMB_VFS_OP_MKNODAT, "mknodat" },
302 { SMB_VFS_OP_REALPATH, "realpath" },
303 { SMB_VFS_OP_CHFLAGS, "chflags" },
304 { SMB_VFS_OP_FILE_ID_CREATE, "file_id_create" },
305 { SMB_VFS_OP_FS_FILE_ID, "fs_file_id" },
306 { SMB_VFS_OP_STREAMINFO, "streaminfo" },
307 { SMB_VFS_OP_GET_REAL_FILENAME, "get_real_filename" },
308 { SMB_VFS_OP_CONNECTPATH, "connectpath" },
309 { SMB_VFS_OP_BRL_LOCK_WINDOWS, "brl_lock_windows" },
310 { SMB_VFS_OP_BRL_UNLOCK_WINDOWS, "brl_unlock_windows" },
311 { SMB_VFS_OP_STRICT_LOCK_CHECK, "strict_lock_check" },
312 { SMB_VFS_OP_TRANSLATE_NAME, "translate_name" },
313 { SMB_VFS_OP_FSCTL, "fsctl" },
314 { SMB_VFS_OP_OFFLOAD_READ_SEND, "offload_read_send" },
315 { SMB_VFS_OP_OFFLOAD_READ_RECV, "offload_read_recv" },
316 { SMB_VFS_OP_OFFLOAD_WRITE_SEND, "offload_write_send" },
317 { SMB_VFS_OP_OFFLOAD_WRITE_RECV, "offload_write_recv" },
318 { SMB_VFS_OP_GET_COMPRESSION, "get_compression" },
319 { SMB_VFS_OP_SET_COMPRESSION, "set_compression" },
320 { SMB_VFS_OP_SNAP_CHECK_PATH, "snap_check_path" },
321 { SMB_VFS_OP_SNAP_CREATE, "snap_create" },
322 { SMB_VFS_OP_SNAP_DELETE, "snap_delete" },
323 { SMB_VFS_OP_GET_DOS_ATTRIBUTES, "get_dos_attributes" },
324 { SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND, "get_dos_attributes_send" },
325 { SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV, "get_dos_attributes_recv" },
326 { SMB_VFS_OP_FGET_DOS_ATTRIBUTES, "fget_dos_attributes" },
327 { SMB_VFS_OP_SET_DOS_ATTRIBUTES, "set_dos_attributes" },
328 { SMB_VFS_OP_FSET_DOS_ATTRIBUTES, "fset_dos_attributes" },
329 { SMB_VFS_OP_FGET_NT_ACL, "fget_nt_acl" },
330 { SMB_VFS_OP_GET_NT_ACL, "get_nt_acl" },
331 { SMB_VFS_OP_FSET_NT_ACL, "fset_nt_acl" },
332 { SMB_VFS_OP_AUDIT_FILE, "audit_file" },
333 { SMB_VFS_OP_SYS_ACL_GET_FILE, "sys_acl_get_file" },
334 { SMB_VFS_OP_SYS_ACL_GET_FD, "sys_acl_get_fd" },
335 { SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE, "sys_acl_blob_get_file" },
336 { SMB_VFS_OP_SYS_ACL_BLOB_GET_FD, "sys_acl_blob_get_fd" },
337 { SMB_VFS_OP_SYS_ACL_SET_FILE, "sys_acl_set_file" },
338 { SMB_VFS_OP_SYS_ACL_SET_FD, "sys_acl_set_fd" },
339 { SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE, "sys_acl_delete_def_file" },
340 { SMB_VFS_OP_GETXATTR, "getxattr" },
341 { SMB_VFS_OP_GETXATTRAT_SEND, "getxattrat_send" },
342 { SMB_VFS_OP_GETXATTRAT_RECV, "getxattrat_recv" },
343 { SMB_VFS_OP_FGETXATTR, "fgetxattr" },
344 { SMB_VFS_OP_LISTXATTR, "listxattr" },
345 { SMB_VFS_OP_FLISTXATTR, "flistxattr" },
346 { SMB_VFS_OP_REMOVEXATTR, "removexattr" },
347 { SMB_VFS_OP_FREMOVEXATTR, "fremovexattr" },
348 { SMB_VFS_OP_SETXATTR, "setxattr" },
349 { SMB_VFS_OP_FSETXATTR, "fsetxattr" },
350 { SMB_VFS_OP_AIO_FORCE, "aio_force" },
351 { SMB_VFS_OP_IS_OFFLINE, "is_offline" },
352 { SMB_VFS_OP_SET_OFFLINE, "set_offline" },
353 { SMB_VFS_OP_DURABLE_COOKIE, "durable_cookie" },
354 { SMB_VFS_OP_DURABLE_DISCONNECT, "durable_disconnect" },
355 { SMB_VFS_OP_DURABLE_RECONNECT, "durable_reconnect" },
356 { SMB_VFS_OP_READDIR_ATTR, "readdir_attr" },
357 { SMB_VFS_OP_LAST, NULL }
360 static int audit_syslog_facility(vfs_handle_struct *handle)
362 static const struct enum_list enum_log_facilities[] = {
364 { LOG_AUTH, "AUTH" },
367 { LOG_AUTHPRIV, "AUTHPRIV" },
370 { LOG_AUDIT, "AUDIT" },
373 { LOG_CONSOLE, "CONSOLE" },
376 { LOG_CRON, "CRON" },
379 { LOG_DAEMON, "DAEMON" },
385 { LOG_INSTALL, "INSTALL" },
388 { LOG_KERN, "KERN" },
391 { LOG_LAUNCHD, "LAUNCHD" },
394 { LOG_LFMT, "LFMT" },
400 { LOG_MAIL, "MAIL" },
403 { LOG_MEGASAFE, "MEGASAFE" },
406 { LOG_NETINFO, "NETINFO" },
409 { LOG_NEWS, "NEWS" },
411 #ifdef LOG_NFACILITIES
412 { LOG_NFACILITIES, "NFACILITIES" },
420 #ifdef LOG_REMOTEAUTH
421 { LOG_REMOTEAUTH, "REMOTEAUTH" },
424 { LOG_SECURITY, "SECURITY" },
427 { LOG_SYSLOG, "SYSLOG" },
430 { LOG_USER, "USER" },
433 { LOG_UUCP, "UUCP" },
435 { LOG_LOCAL0, "LOCAL0" },
436 { LOG_LOCAL1, "LOCAL1" },
437 { LOG_LOCAL2, "LOCAL2" },
438 { LOG_LOCAL3, "LOCAL3" },
439 { LOG_LOCAL4, "LOCAL4" },
440 { LOG_LOCAL5, "LOCAL5" },
441 { LOG_LOCAL6, "LOCAL6" },
442 { LOG_LOCAL7, "LOCAL7" },
448 facility = lp_parm_enum(SNUM(handle->conn), "full_audit", "facility", enum_log_facilities, LOG_USER);
453 static int audit_syslog_priority(vfs_handle_struct *handle)
455 static const struct enum_list enum_log_priorities[] = {
456 { LOG_EMERG, "EMERG" },
457 { LOG_ALERT, "ALERT" },
458 { LOG_CRIT, "CRIT" },
460 { LOG_WARNING, "WARNING" },
461 { LOG_NOTICE, "NOTICE" },
462 { LOG_INFO, "INFO" },
463 { LOG_DEBUG, "DEBUG" },
469 priority = lp_parm_enum(SNUM(handle->conn), "full_audit", "priority",
470 enum_log_priorities, LOG_NOTICE);
471 if (priority == -1) {
472 priority = LOG_WARNING;
478 static char *audit_prefix(TALLOC_CTX *ctx, connection_struct *conn)
480 const struct loadparm_substitution *lp_sub =
481 loadparm_s3_global_substitution();
485 prefix = talloc_strdup(ctx,
486 lp_parm_const_string(SNUM(conn), "full_audit",
491 result = talloc_sub_full(ctx,
492 lp_servicename(talloc_tos(), lp_sub, SNUM(conn)),
493 conn->session_info->unix_info->unix_name,
495 conn->session_info->unix_token->gid,
496 conn->session_info->unix_info->sanitized_username,
497 conn->session_info->info->domain_name,
503 static bool log_success(struct vfs_full_audit_private_data *pd, vfs_op_type op)
505 if (pd->success_ops == NULL) {
509 return bitmap_query(pd->success_ops, op);
512 static bool log_failure(struct vfs_full_audit_private_data *pd, vfs_op_type op)
514 if (pd->failure_ops == NULL)
517 return bitmap_query(pd->failure_ops, op);
520 static struct bitmap *init_bitmap(TALLOC_CTX *mem_ctx, const char **ops)
528 bm = bitmap_talloc(mem_ctx, SMB_VFS_OP_LAST);
530 DEBUG(0, ("Could not alloc bitmap -- "
531 "defaulting to logging everything\n"));
535 for (; *ops != NULL; ops += 1) {
540 if (strequal(*ops, "all")) {
541 for (i=0; i<SMB_VFS_OP_LAST; i++) {
547 if (strequal(*ops, "none")) {
557 for (i=0; i<SMB_VFS_OP_LAST; i++) {
558 if ((vfs_op_names[i].name == NULL)
559 || (vfs_op_names[i].type != i)) {
560 smb_panic("vfs_full_audit.c: name table not "
561 "in sync with vfs_op_type enums\n");
563 if (strequal(op, vfs_op_names[i].name)) {
572 if (i == SMB_VFS_OP_LAST) {
573 DEBUG(0, ("Could not find opname %s, logging all\n",
582 static const char *audit_opname(vfs_op_type op)
584 if (op >= SMB_VFS_OP_LAST)
585 return "INVALID VFS OP";
586 return vfs_op_names[op].name;
589 static TALLOC_CTX *tmp_do_log_ctx;
591 * Get us a temporary talloc context usable just for DEBUG arguments
593 static TALLOC_CTX *do_log_ctx(void)
595 if (tmp_do_log_ctx == NULL) {
596 tmp_do_log_ctx = talloc_named_const(NULL, 0, "do_log_ctx");
598 return tmp_do_log_ctx;
601 static void do_log(vfs_op_type op, bool success, vfs_handle_struct *handle,
602 const char *format, ...) PRINTF_ATTRIBUTE(4, 5);
604 static void do_log(vfs_op_type op, bool success, vfs_handle_struct *handle,
605 const char *format, ...)
607 struct vfs_full_audit_private_data *pd;
609 char *audit_pre = NULL;
613 SMB_VFS_HANDLE_GET_DATA(handle, pd,
614 struct vfs_full_audit_private_data,
617 if (success && (!log_success(pd, op)))
620 if (!success && (!log_failure(pd, op)))
624 fstrcpy(err_msg, "ok");
626 fstr_sprintf(err_msg, "fail (%s)", strerror(errno));
628 va_start(ap, format);
629 op_msg = talloc_vasprintf(talloc_tos(), format, ap);
636 audit_pre = audit_prefix(talloc_tos(), handle->conn);
642 * Specify the facility to interoperate with other syslog
643 * callers (smbd for example).
645 priority = pd->syslog_priority | pd->syslog_facility;
647 syslog(priority, "%s|%s|%s|%s\n",
648 audit_pre ? audit_pre : "",
649 audit_opname(op), err_msg, op_msg);
651 DEBUG(1, ("%s|%s|%s|%s\n",
652 audit_pre ? audit_pre : "",
653 audit_opname(op), err_msg, op_msg));
656 TALLOC_FREE(audit_pre);
658 TALLOC_FREE(tmp_do_log_ctx);
662 * Return a string using the do_log_ctx()
664 static const char *smb_fname_str_do_log(struct connection_struct *conn,
665 const struct smb_filename *smb_fname)
670 if (smb_fname == NULL) {
674 if (smb_fname->base_name[0] != '/') {
675 char *abs_name = NULL;
676 struct smb_filename *fname_copy = cp_smb_filename(
679 if (fname_copy == NULL) {
683 if (!ISDOT(smb_fname->base_name)) {
684 abs_name = talloc_asprintf(do_log_ctx(),
686 conn->cwd_fsp->fsp_name->base_name,
687 smb_fname->base_name);
689 abs_name = talloc_strdup(do_log_ctx(),
690 conn->cwd_fsp->fsp_name->base_name);
692 if (abs_name == NULL) {
695 fname_copy->base_name = abs_name;
696 smb_fname = fname_copy;
699 status = get_full_smb_filename(do_log_ctx(), smb_fname, &fname);
700 if (!NT_STATUS_IS_OK(status)) {
707 * Return an fsp debug string using the do_log_ctx()
709 static const char *fsp_str_do_log(const struct files_struct *fsp)
711 return smb_fname_str_do_log(fsp->conn, fsp->fsp_name);
714 /* Implementation of vfs_ops. Pass everything on to the default
715 operation but log event first. */
717 static int smb_full_audit_connect(vfs_handle_struct *handle,
718 const char *svc, const char *user)
721 const char *none[] = { "none" };
722 struct vfs_full_audit_private_data *pd = NULL;
724 result = SMB_VFS_NEXT_CONNECT(handle, svc, user);
729 pd = talloc_zero(handle, struct vfs_full_audit_private_data);
731 SMB_VFS_NEXT_DISCONNECT(handle);
735 pd->syslog_facility = audit_syslog_facility(handle);
736 if (pd->syslog_facility == -1) {
737 DEBUG(1, ("%s: Unknown facility %s\n", __func__,
738 lp_parm_const_string(SNUM(handle->conn),
739 "full_audit", "facility",
741 SMB_VFS_NEXT_DISCONNECT(handle);
745 pd->syslog_priority = audit_syslog_priority(handle);
747 pd->log_secdesc = lp_parm_bool(SNUM(handle->conn),
748 "full_audit", "log_secdesc", false);
750 pd->do_syslog = lp_parm_bool(SNUM(handle->conn),
751 "full_audit", "syslog", true);
755 openlog("smbd_audit", 0, pd->syslog_facility);
759 pd->success_ops = init_bitmap(
760 pd, lp_parm_string_list(SNUM(handle->conn), "full_audit",
762 pd->failure_ops = init_bitmap(
763 pd, lp_parm_string_list(SNUM(handle->conn), "full_audit",
766 /* Store the private data. */
767 SMB_VFS_HANDLE_SET_DATA(handle, pd, NULL,
768 struct vfs_full_audit_private_data, return -1);
770 do_log(SMB_VFS_OP_CONNECT, True, handle,
776 static void smb_full_audit_disconnect(vfs_handle_struct *handle)
778 const struct loadparm_substitution *lp_sub =
779 loadparm_s3_global_substitution();
781 SMB_VFS_NEXT_DISCONNECT(handle);
783 do_log(SMB_VFS_OP_DISCONNECT, True, handle,
784 "%s", lp_servicename(talloc_tos(), lp_sub, SNUM(handle->conn)));
786 /* The bitmaps will be disconnected when the private
790 static uint64_t smb_full_audit_disk_free(vfs_handle_struct *handle,
791 const struct smb_filename *smb_fname,
798 result = SMB_VFS_NEXT_DISK_FREE(handle, smb_fname, bsize, dfree, dsize);
800 /* Don't have a reasonable notion of failure here */
802 do_log(SMB_VFS_OP_DISK_FREE,
806 smb_fname_str_do_log(handle->conn, smb_fname));
811 static int smb_full_audit_get_quota(struct vfs_handle_struct *handle,
812 const struct smb_filename *smb_fname,
813 enum SMB_QUOTA_TYPE qtype,
819 result = SMB_VFS_NEXT_GET_QUOTA(handle, smb_fname, qtype, id, qt);
821 do_log(SMB_VFS_OP_GET_QUOTA,
825 smb_fname_str_do_log(handle->conn, smb_fname));
830 static int smb_full_audit_set_quota(struct vfs_handle_struct *handle,
831 enum SMB_QUOTA_TYPE qtype, unid_t id,
836 result = SMB_VFS_NEXT_SET_QUOTA(handle, qtype, id, qt);
838 do_log(SMB_VFS_OP_SET_QUOTA, (result >= 0), handle, "");
843 static int smb_full_audit_get_shadow_copy_data(struct vfs_handle_struct *handle,
844 struct files_struct *fsp,
845 struct shadow_copy_data *shadow_copy_data,
850 result = SMB_VFS_NEXT_GET_SHADOW_COPY_DATA(handle, fsp, shadow_copy_data, labels);
852 do_log(SMB_VFS_OP_GET_SHADOW_COPY_DATA, (result >= 0), handle, "");
857 static int smb_full_audit_statvfs(struct vfs_handle_struct *handle,
858 const struct smb_filename *smb_fname,
859 struct vfs_statvfs_struct *statbuf)
863 result = SMB_VFS_NEXT_STATVFS(handle, smb_fname, statbuf);
865 do_log(SMB_VFS_OP_STATVFS, (result >= 0), handle, "");
870 static uint32_t smb_full_audit_fs_capabilities(struct vfs_handle_struct *handle, enum timestamp_set_resolution *p_ts_res)
874 result = SMB_VFS_NEXT_FS_CAPABILITIES(handle, p_ts_res);
876 do_log(SMB_VFS_OP_FS_CAPABILITIES, true, handle, "");
881 static NTSTATUS smb_full_audit_get_dfs_referrals(
882 struct vfs_handle_struct *handle,
883 struct dfs_GetDFSReferral *r)
887 status = SMB_VFS_NEXT_GET_DFS_REFERRALS(handle, r);
889 do_log(SMB_VFS_OP_GET_DFS_REFERRALS, NT_STATUS_IS_OK(status),
895 static NTSTATUS smb_full_audit_create_dfs_pathat(struct vfs_handle_struct *handle,
896 struct files_struct *dirfsp,
897 const struct smb_filename *smb_fname,
898 const struct referral *reflist,
899 size_t referral_count)
903 status = SMB_VFS_NEXT_CREATE_DFS_PATHAT(handle,
909 do_log(SMB_VFS_OP_CREATE_DFS_PATHAT,
910 NT_STATUS_IS_OK(status),
913 smb_fname_str_do_log(handle->conn, smb_fname));
918 static NTSTATUS smb_full_audit_read_dfs_pathat(struct vfs_handle_struct *handle,
920 struct files_struct *dirfsp,
921 const struct smb_filename *smb_fname,
922 struct referral **ppreflist,
923 size_t *preferral_count)
927 status = SMB_VFS_NEXT_READ_DFS_PATHAT(handle,
934 do_log(SMB_VFS_OP_READ_DFS_PATHAT,
935 NT_STATUS_IS_OK(status),
938 smb_fname_str_do_log(handle->conn, smb_fname));
943 static NTSTATUS smb_full_audit_snap_check_path(struct vfs_handle_struct *handle,
945 const char *service_path,
950 status = SMB_VFS_NEXT_SNAP_CHECK_PATH(handle, mem_ctx, service_path,
952 do_log(SMB_VFS_OP_SNAP_CHECK_PATH, NT_STATUS_IS_OK(status),
958 static NTSTATUS smb_full_audit_snap_create(struct vfs_handle_struct *handle,
960 const char *base_volume,
968 status = SMB_VFS_NEXT_SNAP_CREATE(handle, mem_ctx, base_volume, tstamp,
969 rw, base_path, snap_path);
970 do_log(SMB_VFS_OP_SNAP_CREATE, NT_STATUS_IS_OK(status), handle, "");
975 static NTSTATUS smb_full_audit_snap_delete(struct vfs_handle_struct *handle,
982 status = SMB_VFS_NEXT_SNAP_DELETE(handle, mem_ctx, base_path,
984 do_log(SMB_VFS_OP_SNAP_DELETE, NT_STATUS_IS_OK(status), handle, "");
989 static DIR *smb_full_audit_fdopendir(vfs_handle_struct *handle,
990 files_struct *fsp, const char *mask, uint32_t attr)
994 result = SMB_VFS_NEXT_FDOPENDIR(handle, fsp, mask, attr);
996 do_log(SMB_VFS_OP_FDOPENDIR, (result != NULL), handle, "%s",
997 fsp_str_do_log(fsp));
1002 static struct dirent *smb_full_audit_readdir(vfs_handle_struct *handle,
1003 DIR *dirp, SMB_STRUCT_STAT *sbuf)
1005 struct dirent *result;
1007 result = SMB_VFS_NEXT_READDIR(handle, dirp, sbuf);
1009 /* This operation has no reasonable error condition
1010 * (End of dir is also failure), so always succeed.
1012 do_log(SMB_VFS_OP_READDIR, True, handle, "");
1017 static void smb_full_audit_seekdir(vfs_handle_struct *handle,
1018 DIR *dirp, long offset)
1020 SMB_VFS_NEXT_SEEKDIR(handle, dirp, offset);
1022 do_log(SMB_VFS_OP_SEEKDIR, True, handle, "");
1025 static long smb_full_audit_telldir(vfs_handle_struct *handle,
1030 result = SMB_VFS_NEXT_TELLDIR(handle, dirp);
1032 do_log(SMB_VFS_OP_TELLDIR, True, handle, "");
1037 static void smb_full_audit_rewinddir(vfs_handle_struct *handle,
1040 SMB_VFS_NEXT_REWINDDIR(handle, dirp);
1042 do_log(SMB_VFS_OP_REWINDDIR, True, handle, "");
1045 static int smb_full_audit_mkdirat(vfs_handle_struct *handle,
1046 struct files_struct *dirfsp,
1047 const struct smb_filename *smb_fname,
1052 result = SMB_VFS_NEXT_MKDIRAT(handle,
1057 do_log(SMB_VFS_OP_MKDIRAT,
1061 smb_fname_str_do_log(handle->conn, smb_fname));
1066 static int smb_full_audit_closedir(vfs_handle_struct *handle,
1071 result = SMB_VFS_NEXT_CLOSEDIR(handle, dirp);
1073 do_log(SMB_VFS_OP_CLOSEDIR, (result >= 0), handle, "");
1078 static int smb_full_audit_open(vfs_handle_struct *handle,
1079 struct smb_filename *smb_fname,
1080 files_struct *fsp, int flags, mode_t mode)
1084 result = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
1086 do_log(SMB_VFS_OP_OPEN, (result >= 0), handle, "%s|%s",
1087 ((flags & O_WRONLY) || (flags & O_RDWR))?"w":"r",
1088 smb_fname_str_do_log(handle->conn, smb_fname));
1093 static NTSTATUS smb_full_audit_create_file(vfs_handle_struct *handle,
1094 struct smb_request *req,
1095 uint16_t root_dir_fid,
1096 struct smb_filename *smb_fname,
1097 uint32_t access_mask,
1098 uint32_t share_access,
1099 uint32_t create_disposition,
1100 uint32_t create_options,
1101 uint32_t file_attributes,
1102 uint32_t oplock_request,
1103 const struct smb2_lease *lease,
1104 uint64_t allocation_size,
1105 uint32_t private_flags,
1106 struct security_descriptor *sd,
1107 struct ea_list *ea_list,
1108 files_struct **result_fsp,
1110 const struct smb2_create_blobs *in_context_blobs,
1111 struct smb2_create_blobs *out_context_blobs)
1114 const char* str_create_disposition;
1116 switch (create_disposition) {
1117 case FILE_SUPERSEDE:
1118 str_create_disposition = "supersede";
1120 case FILE_OVERWRITE_IF:
1121 str_create_disposition = "overwrite_if";
1124 str_create_disposition = "open";
1126 case FILE_OVERWRITE:
1127 str_create_disposition = "overwrite";
1130 str_create_disposition = "create";
1133 str_create_disposition = "open_if";
1136 str_create_disposition = "unknown";
1139 result = SMB_VFS_NEXT_CREATE_FILE(
1140 handle, /* handle */
1142 root_dir_fid, /* root_dir_fid */
1143 smb_fname, /* fname */
1144 access_mask, /* access_mask */
1145 share_access, /* share_access */
1146 create_disposition, /* create_disposition*/
1147 create_options, /* create_options */
1148 file_attributes, /* file_attributes */
1149 oplock_request, /* oplock_request */
1151 allocation_size, /* allocation_size */
1154 ea_list, /* ea_list */
1155 result_fsp, /* result */
1157 in_context_blobs, out_context_blobs); /* create context */
1159 do_log(SMB_VFS_OP_CREATE_FILE, (NT_STATUS_IS_OK(result)), handle,
1160 "0x%x|%s|%s|%s", access_mask,
1161 create_options & FILE_DIRECTORY_FILE ? "dir" : "file",
1162 str_create_disposition,
1163 smb_fname_str_do_log(handle->conn, smb_fname));
1168 static int smb_full_audit_close(vfs_handle_struct *handle, files_struct *fsp)
1172 result = SMB_VFS_NEXT_CLOSE(handle, fsp);
1174 do_log(SMB_VFS_OP_CLOSE, (result >= 0), handle, "%s",
1175 fsp_str_do_log(fsp));
1180 static ssize_t smb_full_audit_pread(vfs_handle_struct *handle, files_struct *fsp,
1181 void *data, size_t n, off_t offset)
1185 result = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
1187 do_log(SMB_VFS_OP_PREAD, (result >= 0), handle, "%s",
1188 fsp_str_do_log(fsp));
1193 struct smb_full_audit_pread_state {
1194 vfs_handle_struct *handle;
1197 struct vfs_aio_state vfs_aio_state;
1200 static void smb_full_audit_pread_done(struct tevent_req *subreq);
1202 static struct tevent_req *smb_full_audit_pread_send(
1203 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1204 struct tevent_context *ev, struct files_struct *fsp,
1205 void *data, size_t n, off_t offset)
1207 struct tevent_req *req, *subreq;
1208 struct smb_full_audit_pread_state *state;
1210 req = tevent_req_create(mem_ctx, &state,
1211 struct smb_full_audit_pread_state);
1213 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
1214 fsp_str_do_log(fsp));
1217 state->handle = handle;
1220 subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
1222 if (tevent_req_nomem(subreq, req)) {
1223 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
1224 fsp_str_do_log(fsp));
1225 return tevent_req_post(req, ev);
1227 tevent_req_set_callback(subreq, smb_full_audit_pread_done, req);
1229 do_log(SMB_VFS_OP_PREAD_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1233 static void smb_full_audit_pread_done(struct tevent_req *subreq)
1235 struct tevent_req *req = tevent_req_callback_data(
1236 subreq, struct tevent_req);
1237 struct smb_full_audit_pread_state *state = tevent_req_data(
1238 req, struct smb_full_audit_pread_state);
1240 state->ret = SMB_VFS_PREAD_RECV(subreq, &state->vfs_aio_state);
1241 TALLOC_FREE(subreq);
1242 tevent_req_done(req);
1245 static ssize_t smb_full_audit_pread_recv(struct tevent_req *req,
1246 struct vfs_aio_state *vfs_aio_state)
1248 struct smb_full_audit_pread_state *state = tevent_req_data(
1249 req, struct smb_full_audit_pread_state);
1251 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1252 do_log(SMB_VFS_OP_PREAD_RECV, false, state->handle, "%s",
1253 fsp_str_do_log(state->fsp));
1257 do_log(SMB_VFS_OP_PREAD_RECV, (state->ret >= 0), state->handle, "%s",
1258 fsp_str_do_log(state->fsp));
1260 *vfs_aio_state = state->vfs_aio_state;
1264 static ssize_t smb_full_audit_pwrite(vfs_handle_struct *handle, files_struct *fsp,
1265 const void *data, size_t n,
1270 result = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
1272 do_log(SMB_VFS_OP_PWRITE, (result >= 0), handle, "%s",
1273 fsp_str_do_log(fsp));
1278 struct smb_full_audit_pwrite_state {
1279 vfs_handle_struct *handle;
1282 struct vfs_aio_state vfs_aio_state;
1285 static void smb_full_audit_pwrite_done(struct tevent_req *subreq);
1287 static struct tevent_req *smb_full_audit_pwrite_send(
1288 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1289 struct tevent_context *ev, struct files_struct *fsp,
1290 const void *data, size_t n, off_t offset)
1292 struct tevent_req *req, *subreq;
1293 struct smb_full_audit_pwrite_state *state;
1295 req = tevent_req_create(mem_ctx, &state,
1296 struct smb_full_audit_pwrite_state);
1298 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1299 fsp_str_do_log(fsp));
1302 state->handle = handle;
1305 subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
1307 if (tevent_req_nomem(subreq, req)) {
1308 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1309 fsp_str_do_log(fsp));
1310 return tevent_req_post(req, ev);
1312 tevent_req_set_callback(subreq, smb_full_audit_pwrite_done, req);
1314 do_log(SMB_VFS_OP_PWRITE_SEND, true, handle, "%s",
1315 fsp_str_do_log(fsp));
1319 static void smb_full_audit_pwrite_done(struct tevent_req *subreq)
1321 struct tevent_req *req = tevent_req_callback_data(
1322 subreq, struct tevent_req);
1323 struct smb_full_audit_pwrite_state *state = tevent_req_data(
1324 req, struct smb_full_audit_pwrite_state);
1326 state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->vfs_aio_state);
1327 TALLOC_FREE(subreq);
1328 tevent_req_done(req);
1331 static ssize_t smb_full_audit_pwrite_recv(struct tevent_req *req,
1332 struct vfs_aio_state *vfs_aio_state)
1334 struct smb_full_audit_pwrite_state *state = tevent_req_data(
1335 req, struct smb_full_audit_pwrite_state);
1337 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1338 do_log(SMB_VFS_OP_PWRITE_RECV, false, state->handle, "%s",
1339 fsp_str_do_log(state->fsp));
1343 do_log(SMB_VFS_OP_PWRITE_RECV, (state->ret >= 0), state->handle, "%s",
1344 fsp_str_do_log(state->fsp));
1346 *vfs_aio_state = state->vfs_aio_state;
1350 static off_t smb_full_audit_lseek(vfs_handle_struct *handle, files_struct *fsp,
1351 off_t offset, int whence)
1355 result = SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence);
1357 do_log(SMB_VFS_OP_LSEEK, (result != (ssize_t)-1), handle,
1358 "%s", fsp_str_do_log(fsp));
1363 static ssize_t smb_full_audit_sendfile(vfs_handle_struct *handle, int tofd,
1364 files_struct *fromfsp,
1365 const DATA_BLOB *hdr, off_t offset,
1370 result = SMB_VFS_NEXT_SENDFILE(handle, tofd, fromfsp, hdr, offset, n);
1372 do_log(SMB_VFS_OP_SENDFILE, (result >= 0), handle,
1373 "%s", fsp_str_do_log(fromfsp));
1378 static ssize_t smb_full_audit_recvfile(vfs_handle_struct *handle, int fromfd,
1379 files_struct *tofsp,
1385 result = SMB_VFS_NEXT_RECVFILE(handle, fromfd, tofsp, offset, n);
1387 do_log(SMB_VFS_OP_RECVFILE, (result >= 0), handle,
1388 "%s", fsp_str_do_log(tofsp));
1393 static int smb_full_audit_renameat(vfs_handle_struct *handle,
1394 files_struct *srcfsp,
1395 const struct smb_filename *smb_fname_src,
1396 files_struct *dstfsp,
1397 const struct smb_filename *smb_fname_dst)
1401 result = SMB_VFS_NEXT_RENAMEAT(handle,
1407 do_log(SMB_VFS_OP_RENAMEAT, (result >= 0), handle, "%s|%s",
1408 smb_fname_str_do_log(handle->conn, smb_fname_src),
1409 smb_fname_str_do_log(handle->conn, smb_fname_dst));
1414 struct smb_full_audit_fsync_state {
1415 vfs_handle_struct *handle;
1418 struct vfs_aio_state vfs_aio_state;
1421 static void smb_full_audit_fsync_done(struct tevent_req *subreq);
1423 static struct tevent_req *smb_full_audit_fsync_send(
1424 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1425 struct tevent_context *ev, struct files_struct *fsp)
1427 struct tevent_req *req, *subreq;
1428 struct smb_full_audit_fsync_state *state;
1430 req = tevent_req_create(mem_ctx, &state,
1431 struct smb_full_audit_fsync_state);
1433 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1434 fsp_str_do_log(fsp));
1437 state->handle = handle;
1440 subreq = SMB_VFS_NEXT_FSYNC_SEND(state, ev, handle, fsp);
1441 if (tevent_req_nomem(subreq, req)) {
1442 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1443 fsp_str_do_log(fsp));
1444 return tevent_req_post(req, ev);
1446 tevent_req_set_callback(subreq, smb_full_audit_fsync_done, req);
1448 do_log(SMB_VFS_OP_FSYNC_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1452 static void smb_full_audit_fsync_done(struct tevent_req *subreq)
1454 struct tevent_req *req = tevent_req_callback_data(
1455 subreq, struct tevent_req);
1456 struct smb_full_audit_fsync_state *state = tevent_req_data(
1457 req, struct smb_full_audit_fsync_state);
1459 state->ret = SMB_VFS_FSYNC_RECV(subreq, &state->vfs_aio_state);
1460 TALLOC_FREE(subreq);
1461 tevent_req_done(req);
1464 static int smb_full_audit_fsync_recv(struct tevent_req *req,
1465 struct vfs_aio_state *vfs_aio_state)
1467 struct smb_full_audit_fsync_state *state = tevent_req_data(
1468 req, struct smb_full_audit_fsync_state);
1470 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1471 do_log(SMB_VFS_OP_FSYNC_RECV, false, state->handle, "%s",
1472 fsp_str_do_log(state->fsp));
1476 do_log(SMB_VFS_OP_FSYNC_RECV, (state->ret >= 0), state->handle, "%s",
1477 fsp_str_do_log(state->fsp));
1479 *vfs_aio_state = state->vfs_aio_state;
1483 static int smb_full_audit_stat(vfs_handle_struct *handle,
1484 struct smb_filename *smb_fname)
1488 result = SMB_VFS_NEXT_STAT(handle, smb_fname);
1490 do_log(SMB_VFS_OP_STAT, (result >= 0), handle, "%s",
1491 smb_fname_str_do_log(handle->conn, smb_fname));
1496 static int smb_full_audit_fstat(vfs_handle_struct *handle, files_struct *fsp,
1497 SMB_STRUCT_STAT *sbuf)
1501 result = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1503 do_log(SMB_VFS_OP_FSTAT, (result >= 0), handle, "%s",
1504 fsp_str_do_log(fsp));
1509 static int smb_full_audit_lstat(vfs_handle_struct *handle,
1510 struct smb_filename *smb_fname)
1514 result = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
1516 do_log(SMB_VFS_OP_LSTAT, (result >= 0), handle, "%s",
1517 smb_fname_str_do_log(handle->conn, smb_fname));
1522 static uint64_t smb_full_audit_get_alloc_size(vfs_handle_struct *handle,
1523 files_struct *fsp, const SMB_STRUCT_STAT *sbuf)
1527 result = SMB_VFS_NEXT_GET_ALLOC_SIZE(handle, fsp, sbuf);
1529 do_log(SMB_VFS_OP_GET_ALLOC_SIZE, (result != (uint64_t)-1), handle,
1530 "%llu", (unsigned long long)result);
1535 static int smb_full_audit_unlinkat(vfs_handle_struct *handle,
1536 struct files_struct *dirfsp,
1537 const struct smb_filename *smb_fname,
1542 result = SMB_VFS_NEXT_UNLINKAT(handle,
1547 do_log(SMB_VFS_OP_UNLINKAT, (result >= 0), handle, "%s",
1548 smb_fname_str_do_log(handle->conn, smb_fname));
1553 static int smb_full_audit_chmod(vfs_handle_struct *handle,
1554 const struct smb_filename *smb_fname,
1559 result = SMB_VFS_NEXT_CHMOD(handle, smb_fname, mode);
1561 do_log(SMB_VFS_OP_CHMOD,
1565 smb_fname_str_do_log(handle->conn, smb_fname),
1571 static int smb_full_audit_fchmod(vfs_handle_struct *handle, files_struct *fsp,
1576 result = SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1578 do_log(SMB_VFS_OP_FCHMOD, (result >= 0), handle,
1579 "%s|%o", fsp_str_do_log(fsp), mode);
1584 static int smb_full_audit_fchown(vfs_handle_struct *handle, files_struct *fsp,
1585 uid_t uid, gid_t gid)
1589 result = SMB_VFS_NEXT_FCHOWN(handle, fsp, uid, gid);
1591 do_log(SMB_VFS_OP_FCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1592 fsp_str_do_log(fsp), (long int)uid, (long int)gid);
1597 static int smb_full_audit_lchown(vfs_handle_struct *handle,
1598 const struct smb_filename *smb_fname,
1604 result = SMB_VFS_NEXT_LCHOWN(handle, smb_fname, uid, gid);
1606 do_log(SMB_VFS_OP_LCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1607 smb_fname->base_name, (long int)uid, (long int)gid);
1612 static int smb_full_audit_chdir(vfs_handle_struct *handle,
1613 const struct smb_filename *smb_fname)
1617 result = SMB_VFS_NEXT_CHDIR(handle, smb_fname);
1619 do_log(SMB_VFS_OP_CHDIR,
1623 smb_fname_str_do_log(handle->conn, smb_fname));
1628 static struct smb_filename *smb_full_audit_getwd(vfs_handle_struct *handle,
1631 struct smb_filename *result;
1633 result = SMB_VFS_NEXT_GETWD(handle, ctx);
1635 do_log(SMB_VFS_OP_GETWD, (result != NULL), handle, "%s",
1636 result == NULL? "" : result->base_name);
1641 static int smb_full_audit_ntimes(vfs_handle_struct *handle,
1642 const struct smb_filename *smb_fname,
1643 struct smb_file_time *ft)
1646 time_t create_time = convert_timespec_to_time_t(ft->create_time);
1647 time_t atime = convert_timespec_to_time_t(ft->atime);
1648 time_t mtime = convert_timespec_to_time_t(ft->mtime);
1649 time_t ctime = convert_timespec_to_time_t(ft->ctime);
1650 const char *create_time_str = "";
1651 const char *atime_str = "";
1652 const char *mtime_str = "";
1653 const char *ctime_str = "";
1654 TALLOC_CTX *frame = talloc_stackframe();
1656 result = SMB_VFS_NEXT_NTIMES(handle, smb_fname, ft);
1658 if (create_time > 0) {
1659 create_time_str = timestring(frame, create_time);
1662 atime_str = timestring(frame, atime);
1665 mtime_str = timestring(frame, mtime);
1668 ctime_str = timestring(frame, ctime);
1671 do_log(SMB_VFS_OP_NTIMES,
1675 smb_fname_str_do_log(handle->conn, smb_fname),
1686 static int smb_full_audit_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
1691 result = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1693 do_log(SMB_VFS_OP_FTRUNCATE, (result >= 0), handle,
1694 "%s", fsp_str_do_log(fsp));
1699 static int smb_full_audit_fallocate(vfs_handle_struct *handle, files_struct *fsp,
1706 result = SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
1708 do_log(SMB_VFS_OP_FALLOCATE, (result >= 0), handle,
1709 "%s", fsp_str_do_log(fsp));
1714 static bool smb_full_audit_lock(vfs_handle_struct *handle, files_struct *fsp,
1715 int op, off_t offset, off_t count, int type)
1719 result = SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type);
1721 do_log(SMB_VFS_OP_LOCK, result, handle, "%s", fsp_str_do_log(fsp));
1726 static int smb_full_audit_kernel_flock(struct vfs_handle_struct *handle,
1727 struct files_struct *fsp,
1728 uint32_t share_access,
1729 uint32_t access_mask)
1733 result = SMB_VFS_NEXT_KERNEL_FLOCK(handle,
1738 do_log(SMB_VFS_OP_KERNEL_FLOCK, (result >= 0), handle, "%s",
1739 fsp_str_do_log(fsp));
1744 static int smb_full_audit_fcntl(struct vfs_handle_struct *handle,
1745 struct files_struct *fsp,
1746 int cmd, va_list cmd_arg)
1749 va_list dup_cmd_arg;
1752 va_copy(dup_cmd_arg, cmd_arg);
1753 arg = va_arg(dup_cmd_arg, void *);
1754 result = SMB_VFS_NEXT_FCNTL(handle, fsp, cmd, arg);
1755 va_end(dup_cmd_arg);
1757 do_log(SMB_VFS_OP_FCNTL, (result >= 0), handle, "%s",
1758 fsp_str_do_log(fsp));
1763 static int smb_full_audit_linux_setlease(vfs_handle_struct *handle, files_struct *fsp,
1768 result = SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
1770 do_log(SMB_VFS_OP_LINUX_SETLEASE, (result >= 0), handle, "%s",
1771 fsp_str_do_log(fsp));
1776 static bool smb_full_audit_getlock(vfs_handle_struct *handle, files_struct *fsp,
1777 off_t *poffset, off_t *pcount, int *ptype, pid_t *ppid)
1781 result = SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype, ppid);
1783 do_log(SMB_VFS_OP_GETLOCK, result, handle, "%s", fsp_str_do_log(fsp));
1788 static int smb_full_audit_symlinkat(vfs_handle_struct *handle,
1789 const char *link_contents,
1790 struct files_struct *dirfsp,
1791 const struct smb_filename *new_smb_fname)
1795 result = SMB_VFS_NEXT_SYMLINKAT(handle,
1800 do_log(SMB_VFS_OP_SYMLINKAT,
1805 smb_fname_str_do_log(handle->conn, new_smb_fname));
1810 static int smb_full_audit_readlinkat(vfs_handle_struct *handle,
1811 files_struct *dirfsp,
1812 const struct smb_filename *smb_fname,
1818 result = SMB_VFS_NEXT_READLINKAT(handle,
1824 do_log(SMB_VFS_OP_READLINKAT,
1828 smb_fname_str_do_log(handle->conn, smb_fname));
1833 static int smb_full_audit_linkat(vfs_handle_struct *handle,
1834 files_struct *srcfsp,
1835 const struct smb_filename *old_smb_fname,
1836 files_struct *dstfsp,
1837 const struct smb_filename *new_smb_fname,
1842 result = SMB_VFS_NEXT_LINKAT(handle,
1849 do_log(SMB_VFS_OP_LINKAT,
1853 smb_fname_str_do_log(handle->conn, old_smb_fname),
1854 smb_fname_str_do_log(handle->conn, new_smb_fname));
1859 static int smb_full_audit_mknodat(vfs_handle_struct *handle,
1860 files_struct *dirfsp,
1861 const struct smb_filename *smb_fname,
1867 result = SMB_VFS_NEXT_MKNODAT(handle,
1873 do_log(SMB_VFS_OP_MKNODAT,
1877 smb_fname_str_do_log(handle->conn, smb_fname));
1882 static struct smb_filename *smb_full_audit_realpath(vfs_handle_struct *handle,
1884 const struct smb_filename *smb_fname)
1886 struct smb_filename *result_fname = NULL;
1888 result_fname = SMB_VFS_NEXT_REALPATH(handle, ctx, smb_fname);
1890 do_log(SMB_VFS_OP_REALPATH,
1891 (result_fname != NULL),
1894 smb_fname_str_do_log(handle->conn, smb_fname));
1896 return result_fname;
1899 static int smb_full_audit_chflags(vfs_handle_struct *handle,
1900 const struct smb_filename *smb_fname,
1905 result = SMB_VFS_NEXT_CHFLAGS(handle, smb_fname, flags);
1907 do_log(SMB_VFS_OP_CHFLAGS,
1911 smb_fname_str_do_log(handle->conn, smb_fname));
1916 static struct file_id smb_full_audit_file_id_create(struct vfs_handle_struct *handle,
1917 const SMB_STRUCT_STAT *sbuf)
1919 struct file_id id_zero = { 0 };
1920 struct file_id result;
1921 struct file_id_buf idbuf;
1923 result = SMB_VFS_NEXT_FILE_ID_CREATE(handle, sbuf);
1925 do_log(SMB_VFS_OP_FILE_ID_CREATE,
1926 !file_id_equal(&id_zero, &result),
1929 file_id_str_buf(result, &idbuf));
1934 static uint64_t smb_full_audit_fs_file_id(struct vfs_handle_struct *handle,
1935 const SMB_STRUCT_STAT *sbuf)
1939 result = SMB_VFS_NEXT_FS_FILE_ID(handle, sbuf);
1941 do_log(SMB_VFS_OP_FS_FILE_ID,
1943 handle, "%" PRIu64, result);
1948 static NTSTATUS smb_full_audit_streaminfo(vfs_handle_struct *handle,
1949 struct files_struct *fsp,
1950 const struct smb_filename *smb_fname,
1951 TALLOC_CTX *mem_ctx,
1952 unsigned int *pnum_streams,
1953 struct stream_struct **pstreams)
1957 result = SMB_VFS_NEXT_STREAMINFO(handle, fsp, smb_fname, mem_ctx,
1958 pnum_streams, pstreams);
1960 do_log(SMB_VFS_OP_STREAMINFO,
1961 NT_STATUS_IS_OK(result),
1964 smb_fname_str_do_log(handle->conn, smb_fname));
1969 static int smb_full_audit_get_real_filename(struct vfs_handle_struct *handle,
1972 TALLOC_CTX *mem_ctx,
1977 result = SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name, mem_ctx,
1980 do_log(SMB_VFS_OP_GET_REAL_FILENAME, (result == 0), handle,
1981 "%s/%s->%s", path, name, (result == 0) ? *found_name : "");
1986 static const char *smb_full_audit_connectpath(vfs_handle_struct *handle,
1987 const struct smb_filename *smb_fname)
1991 result = SMB_VFS_NEXT_CONNECTPATH(handle, smb_fname);
1993 do_log(SMB_VFS_OP_CONNECTPATH,
1997 smb_fname_str_do_log(handle->conn, smb_fname));
2002 static NTSTATUS smb_full_audit_brl_lock_windows(struct vfs_handle_struct *handle,
2003 struct byte_range_lock *br_lck,
2004 struct lock_struct *plock)
2008 result = SMB_VFS_NEXT_BRL_LOCK_WINDOWS(handle, br_lck, plock);
2010 do_log(SMB_VFS_OP_BRL_LOCK_WINDOWS, NT_STATUS_IS_OK(result), handle,
2011 "%s:%llu-%llu. type=%d.",
2012 fsp_str_do_log(brl_fsp(br_lck)),
2013 (unsigned long long)plock->start,
2014 (unsigned long long)plock->size,
2020 static bool smb_full_audit_brl_unlock_windows(struct vfs_handle_struct *handle,
2021 struct byte_range_lock *br_lck,
2022 const struct lock_struct *plock)
2026 result = SMB_VFS_NEXT_BRL_UNLOCK_WINDOWS(handle, br_lck, plock);
2028 do_log(SMB_VFS_OP_BRL_UNLOCK_WINDOWS, (result == 0), handle,
2029 "%s:%llu-%llu:%d", fsp_str_do_log(brl_fsp(br_lck)),
2030 (unsigned long long)plock->start,
2031 (unsigned long long)plock->size,
2037 static bool smb_full_audit_strict_lock_check(struct vfs_handle_struct *handle,
2038 struct files_struct *fsp,
2039 struct lock_struct *plock)
2043 result = SMB_VFS_NEXT_STRICT_LOCK_CHECK(handle, fsp, plock);
2045 do_log(SMB_VFS_OP_STRICT_LOCK_CHECK, result, handle,
2046 "%s:%llu-%llu:%d", fsp_str_do_log(fsp),
2047 (unsigned long long)plock->start,
2048 (unsigned long long)plock->size,
2054 static NTSTATUS smb_full_audit_translate_name(struct vfs_handle_struct *handle,
2056 enum vfs_translate_direction direction,
2057 TALLOC_CTX *mem_ctx,
2062 result = SMB_VFS_NEXT_TRANSLATE_NAME(handle, name, direction, mem_ctx,
2065 do_log(SMB_VFS_OP_TRANSLATE_NAME, NT_STATUS_IS_OK(result), handle, "");
2070 static NTSTATUS smb_full_audit_fsctl(struct vfs_handle_struct *handle,
2071 struct files_struct *fsp,
2075 const uint8_t *_in_data,
2077 uint8_t **_out_data,
2078 uint32_t max_out_len,
2083 result = SMB_VFS_NEXT_FSCTL(handle,
2094 do_log(SMB_VFS_OP_FSCTL, NT_STATUS_IS_OK(result), handle, "");
2099 static struct tevent_req *smb_full_audit_offload_read_send(
2100 TALLOC_CTX *mem_ctx,
2101 struct tevent_context *ev,
2102 struct vfs_handle_struct *handle,
2103 struct files_struct *fsp,
2109 struct tevent_req *req = NULL;
2111 req = SMB_VFS_NEXT_OFFLOAD_READ_SEND(mem_ctx, ev, handle, fsp,
2112 fsctl, ttl, offset, to_copy);
2114 do_log(SMB_VFS_OP_OFFLOAD_READ_SEND, req, handle, "");
2119 static NTSTATUS smb_full_audit_offload_read_recv(
2120 struct tevent_req *req,
2121 struct vfs_handle_struct *handle,
2122 TALLOC_CTX *mem_ctx,
2123 DATA_BLOB *_token_blob)
2127 status = SMB_VFS_NEXT_OFFLOAD_READ_RECV(req, handle, mem_ctx,
2130 do_log(SMB_VFS_OP_OFFLOAD_READ_RECV, NT_STATUS_IS_OK(status), handle, "");
2135 static struct tevent_req *smb_full_audit_offload_write_send(struct vfs_handle_struct *handle,
2136 TALLOC_CTX *mem_ctx,
2137 struct tevent_context *ev,
2140 off_t transfer_offset,
2141 struct files_struct *dest_fsp,
2145 struct tevent_req *req;
2147 req = SMB_VFS_NEXT_OFFLOAD_WRITE_SEND(handle, mem_ctx, ev,
2148 fsctl, token, transfer_offset,
2149 dest_fsp, dest_off, num);
2151 do_log(SMB_VFS_OP_OFFLOAD_WRITE_SEND, req, handle, "");
2156 static NTSTATUS smb_full_audit_offload_write_recv(struct vfs_handle_struct *handle,
2157 struct tevent_req *req,
2162 result = SMB_VFS_NEXT_OFFLOAD_WRITE_RECV(handle, req, copied);
2164 do_log(SMB_VFS_OP_OFFLOAD_WRITE_RECV, NT_STATUS_IS_OK(result), handle, "");
2169 static NTSTATUS smb_full_audit_get_compression(vfs_handle_struct *handle,
2170 TALLOC_CTX *mem_ctx,
2171 struct files_struct *fsp,
2172 struct smb_filename *smb_fname,
2173 uint16_t *_compression_fmt)
2177 result = SMB_VFS_NEXT_GET_COMPRESSION(handle, mem_ctx, fsp, smb_fname,
2180 do_log(SMB_VFS_OP_GET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
2182 (fsp ? fsp_str_do_log(fsp) :
2183 smb_fname_str_do_log(handle->conn, smb_fname)));
2188 static NTSTATUS smb_full_audit_set_compression(vfs_handle_struct *handle,
2189 TALLOC_CTX *mem_ctx,
2190 struct files_struct *fsp,
2191 uint16_t compression_fmt)
2195 result = SMB_VFS_NEXT_SET_COMPRESSION(handle, mem_ctx, fsp,
2198 do_log(SMB_VFS_OP_SET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
2199 "%s", fsp_str_do_log(fsp));
2204 static NTSTATUS smb_full_audit_readdir_attr(struct vfs_handle_struct *handle,
2205 const struct smb_filename *fname,
2206 TALLOC_CTX *mem_ctx,
2207 struct readdir_attr_data **pattr_data)
2211 status = SMB_VFS_NEXT_READDIR_ATTR(handle, fname, mem_ctx, pattr_data);
2213 do_log(SMB_VFS_OP_READDIR_ATTR, NT_STATUS_IS_OK(status), handle, "%s",
2214 smb_fname_str_do_log(handle->conn, fname));
2219 static NTSTATUS smb_full_audit_get_dos_attributes(
2220 struct vfs_handle_struct *handle,
2221 struct smb_filename *smb_fname,
2226 status = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES(handle,
2230 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES,
2231 NT_STATUS_IS_OK(status),
2234 smb_fname_str_do_log(handle->conn, smb_fname));
2239 struct smb_full_audit_get_dos_attributes_state {
2240 struct vfs_aio_state aio_state;
2241 vfs_handle_struct *handle;
2242 files_struct *dir_fsp;
2243 const struct smb_filename *smb_fname;
2247 static void smb_full_audit_get_dos_attributes_done(struct tevent_req *subreq);
2249 static struct tevent_req *smb_full_audit_get_dos_attributes_send(
2250 TALLOC_CTX *mem_ctx,
2251 struct tevent_context *ev,
2252 struct vfs_handle_struct *handle,
2253 files_struct *dir_fsp,
2254 struct smb_filename *smb_fname)
2256 struct tevent_req *req = NULL;
2257 struct smb_full_audit_get_dos_attributes_state *state = NULL;
2258 struct tevent_req *subreq = NULL;
2260 req = tevent_req_create(mem_ctx, &state,
2261 struct smb_full_audit_get_dos_attributes_state);
2263 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2267 fsp_str_do_log(dir_fsp),
2268 smb_fname->base_name);
2271 *state = (struct smb_full_audit_get_dos_attributes_state) {
2274 .smb_fname = smb_fname,
2277 subreq = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES_SEND(mem_ctx,
2282 if (tevent_req_nomem(subreq, req)) {
2283 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2287 fsp_str_do_log(dir_fsp),
2288 smb_fname->base_name);
2289 return tevent_req_post(req, ev);
2291 tevent_req_set_callback(subreq,
2292 smb_full_audit_get_dos_attributes_done,
2295 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2299 fsp_str_do_log(dir_fsp),
2300 smb_fname->base_name);
2305 static void smb_full_audit_get_dos_attributes_done(struct tevent_req *subreq)
2307 struct tevent_req *req =
2308 tevent_req_callback_data(subreq,
2310 struct smb_full_audit_get_dos_attributes_state *state =
2311 tevent_req_data(req,
2312 struct smb_full_audit_get_dos_attributes_state);
2315 status = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES_RECV(subreq,
2318 TALLOC_FREE(subreq);
2319 if (tevent_req_nterror(req, status)) {
2323 tevent_req_done(req);
2327 static NTSTATUS smb_full_audit_get_dos_attributes_recv(struct tevent_req *req,
2328 struct vfs_aio_state *aio_state,
2331 struct smb_full_audit_get_dos_attributes_state *state =
2332 tevent_req_data(req,
2333 struct smb_full_audit_get_dos_attributes_state);
2336 if (tevent_req_is_nterror(req, &status)) {
2337 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV,
2341 fsp_str_do_log(state->dir_fsp),
2342 state->smb_fname->base_name);
2343 tevent_req_received(req);
2347 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV,
2351 fsp_str_do_log(state->dir_fsp),
2352 state->smb_fname->base_name);
2354 *aio_state = state->aio_state;
2355 *dosmode = state->dosmode;
2356 tevent_req_received(req);
2357 return NT_STATUS_OK;
2360 static NTSTATUS smb_full_audit_fget_dos_attributes(
2361 struct vfs_handle_struct *handle,
2362 struct files_struct *fsp,
2367 status = SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle,
2371 do_log(SMB_VFS_OP_FGET_DOS_ATTRIBUTES,
2372 NT_STATUS_IS_OK(status),
2375 fsp_str_do_log(fsp));
2380 static NTSTATUS smb_full_audit_set_dos_attributes(
2381 struct vfs_handle_struct *handle,
2382 const struct smb_filename *smb_fname,
2387 status = SMB_VFS_NEXT_SET_DOS_ATTRIBUTES(handle,
2391 do_log(SMB_VFS_OP_SET_DOS_ATTRIBUTES,
2392 NT_STATUS_IS_OK(status),
2395 smb_fname_str_do_log(handle->conn, smb_fname));
2400 static NTSTATUS smb_full_audit_fset_dos_attributes(
2401 struct vfs_handle_struct *handle,
2402 struct files_struct *fsp,
2407 status = SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle,
2411 do_log(SMB_VFS_OP_FSET_DOS_ATTRIBUTES,
2412 NT_STATUS_IS_OK(status),
2415 fsp_str_do_log(fsp));
2420 static NTSTATUS smb_full_audit_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
2421 uint32_t security_info,
2422 TALLOC_CTX *mem_ctx,
2423 struct security_descriptor **ppdesc)
2427 result = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
2430 do_log(SMB_VFS_OP_FGET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2431 "%s", fsp_str_do_log(fsp));
2436 static NTSTATUS smb_full_audit_get_nt_acl(vfs_handle_struct *handle,
2437 const struct smb_filename *smb_fname,
2438 uint32_t security_info,
2439 TALLOC_CTX *mem_ctx,
2440 struct security_descriptor **ppdesc)
2444 result = SMB_VFS_NEXT_GET_NT_ACL(handle, smb_fname, security_info,
2447 do_log(SMB_VFS_OP_GET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2448 "%s", smb_fname_str_do_log(handle->conn, smb_fname));
2453 static NTSTATUS smb_full_audit_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
2454 uint32_t security_info_sent,
2455 const struct security_descriptor *psd)
2457 struct vfs_full_audit_private_data *pd;
2461 SMB_VFS_HANDLE_GET_DATA(handle, pd,
2462 struct vfs_full_audit_private_data,
2463 return NT_STATUS_INTERNAL_ERROR);
2465 if (pd->log_secdesc) {
2466 sd = sddl_encode(talloc_tos(), psd, get_global_sam_sid());
2469 result = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
2471 do_log(SMB_VFS_OP_FSET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2472 "%s [%s]", fsp_str_do_log(fsp), sd ? sd : "");
2479 static NTSTATUS smb_full_audit_audit_file(struct vfs_handle_struct *handle,
2480 struct smb_filename *file,
2481 struct security_acl *sacl,
2482 uint32_t access_requested,
2483 uint32_t access_denied)
2487 result = SMB_VFS_NEXT_AUDIT_FILE(handle,
2493 do_log(SMB_VFS_OP_AUDIT_FILE, NT_STATUS_IS_OK(result), handle,
2495 smb_fname_str_do_log(handle->conn, file));
2500 static SMB_ACL_T smb_full_audit_sys_acl_get_file(vfs_handle_struct *handle,
2501 const struct smb_filename *smb_fname,
2502 SMB_ACL_TYPE_T type,
2503 TALLOC_CTX *mem_ctx)
2507 result = SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, smb_fname,
2510 do_log(SMB_VFS_OP_SYS_ACL_GET_FILE,
2514 smb_fname_str_do_log(handle->conn, smb_fname));
2519 static SMB_ACL_T smb_full_audit_sys_acl_get_fd(vfs_handle_struct *handle,
2520 files_struct *fsp, TALLOC_CTX *mem_ctx)
2524 result = SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp, mem_ctx);
2526 do_log(SMB_VFS_OP_SYS_ACL_GET_FD, (result != NULL), handle,
2527 "%s", fsp_str_do_log(fsp));
2532 static int smb_full_audit_sys_acl_blob_get_file(vfs_handle_struct *handle,
2533 const struct smb_filename *smb_fname,
2534 TALLOC_CTX *mem_ctx,
2535 char **blob_description,
2540 result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FILE(handle, smb_fname,
2541 mem_ctx, blob_description, blob);
2543 do_log(SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE,
2547 smb_fname_str_do_log(handle->conn, smb_fname));
2552 static int smb_full_audit_sys_acl_blob_get_fd(vfs_handle_struct *handle,
2554 TALLOC_CTX *mem_ctx,
2555 char **blob_description,
2560 result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle, fsp, mem_ctx, blob_description, blob);
2562 do_log(SMB_VFS_OP_SYS_ACL_BLOB_GET_FD, (result >= 0), handle,
2563 "%s", fsp_str_do_log(fsp));
2568 static int smb_full_audit_sys_acl_set_file(vfs_handle_struct *handle,
2569 const struct smb_filename *smb_fname,
2570 SMB_ACL_TYPE_T acltype,
2575 result = SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, smb_fname, acltype,
2578 do_log(SMB_VFS_OP_SYS_ACL_SET_FILE,
2582 smb_fname_str_do_log(handle->conn, smb_fname));
2587 static int smb_full_audit_sys_acl_set_fd(vfs_handle_struct *handle, files_struct *fsp,
2592 result = SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, theacl);
2594 do_log(SMB_VFS_OP_SYS_ACL_SET_FD, (result >= 0), handle,
2595 "%s", fsp_str_do_log(fsp));
2600 static int smb_full_audit_sys_acl_delete_def_file(vfs_handle_struct *handle,
2601 const struct smb_filename *smb_fname)
2605 result = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, smb_fname);
2607 do_log(SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE,
2611 smb_fname_str_do_log(handle->conn, smb_fname));
2616 static ssize_t smb_full_audit_getxattr(struct vfs_handle_struct *handle,
2617 const struct smb_filename *smb_fname,
2618 const char *name, void *value, size_t size)
2622 result = SMB_VFS_NEXT_GETXATTR(handle, smb_fname, name, value, size);
2624 do_log(SMB_VFS_OP_GETXATTR,
2628 smb_fname_str_do_log(handle->conn, smb_fname),
2634 struct smb_full_audit_getxattrat_state {
2635 struct vfs_aio_state aio_state;
2636 vfs_handle_struct *handle;
2637 files_struct *dir_fsp;
2638 const struct smb_filename *smb_fname;
2639 const char *xattr_name;
2641 uint8_t *xattr_value;
2644 static void smb_full_audit_getxattrat_done(struct tevent_req *subreq);
2646 static struct tevent_req *smb_full_audit_getxattrat_send(
2647 TALLOC_CTX *mem_ctx,
2648 struct tevent_context *ev,
2649 struct vfs_handle_struct *handle,
2650 files_struct *dir_fsp,
2651 const struct smb_filename *smb_fname,
2652 const char *xattr_name,
2655 struct tevent_req *req = NULL;
2656 struct tevent_req *subreq = NULL;
2657 struct smb_full_audit_getxattrat_state *state = NULL;
2659 req = tevent_req_create(mem_ctx, &state,
2660 struct smb_full_audit_getxattrat_state);
2662 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2666 fsp_str_do_log(dir_fsp),
2667 smb_fname->base_name,
2671 *state = (struct smb_full_audit_getxattrat_state) {
2674 .smb_fname = smb_fname,
2675 .xattr_name = xattr_name,
2678 subreq = SMB_VFS_NEXT_GETXATTRAT_SEND(state,
2685 if (tevent_req_nomem(subreq, req)) {
2686 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2690 fsp_str_do_log(dir_fsp),
2691 smb_fname->base_name,
2693 return tevent_req_post(req, ev);
2695 tevent_req_set_callback(subreq, smb_full_audit_getxattrat_done, req);
2697 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2701 fsp_str_do_log(dir_fsp),
2702 smb_fname->base_name,
2708 static void smb_full_audit_getxattrat_done(struct tevent_req *subreq)
2710 struct tevent_req *req = tevent_req_callback_data(
2711 subreq, struct tevent_req);
2712 struct smb_full_audit_getxattrat_state *state = tevent_req_data(
2713 req, struct smb_full_audit_getxattrat_state);
2715 state->xattr_size = SMB_VFS_NEXT_GETXATTRAT_RECV(subreq,
2718 &state->xattr_value);
2719 TALLOC_FREE(subreq);
2720 if (state->xattr_size == -1) {
2721 tevent_req_error(req, state->aio_state.error);
2725 tevent_req_done(req);
2728 static ssize_t smb_full_audit_getxattrat_recv(struct tevent_req *req,
2729 struct vfs_aio_state *aio_state,
2730 TALLOC_CTX *mem_ctx,
2731 uint8_t **xattr_value)
2733 struct smb_full_audit_getxattrat_state *state = tevent_req_data(
2734 req, struct smb_full_audit_getxattrat_state);
2737 if (tevent_req_is_unix_error(req, &aio_state->error)) {
2738 do_log(SMB_VFS_OP_GETXATTRAT_RECV,
2742 fsp_str_do_log(state->dir_fsp),
2743 state->smb_fname->base_name,
2745 tevent_req_received(req);
2749 do_log(SMB_VFS_OP_GETXATTRAT_RECV,
2753 fsp_str_do_log(state->dir_fsp),
2754 state->smb_fname->base_name,
2757 *aio_state = state->aio_state;
2758 xattr_size = state->xattr_size;
2759 if (xattr_value != NULL) {
2760 *xattr_value = talloc_move(mem_ctx, &state->xattr_value);
2763 tevent_req_received(req);
2767 static ssize_t smb_full_audit_fgetxattr(struct vfs_handle_struct *handle,
2768 struct files_struct *fsp,
2769 const char *name, void *value, size_t size)
2773 result = SMB_VFS_NEXT_FGETXATTR(handle, fsp, name, value, size);
2775 do_log(SMB_VFS_OP_FGETXATTR, (result >= 0), handle,
2776 "%s|%s", fsp_str_do_log(fsp), name);
2781 static ssize_t smb_full_audit_listxattr(struct vfs_handle_struct *handle,
2782 const struct smb_filename *smb_fname,
2788 result = SMB_VFS_NEXT_LISTXATTR(handle, smb_fname, list, size);
2790 do_log(SMB_VFS_OP_LISTXATTR,
2794 smb_fname_str_do_log(handle->conn, smb_fname));
2799 static ssize_t smb_full_audit_flistxattr(struct vfs_handle_struct *handle,
2800 struct files_struct *fsp, char *list,
2805 result = SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
2807 do_log(SMB_VFS_OP_FLISTXATTR, (result >= 0), handle,
2808 "%s", fsp_str_do_log(fsp));
2813 static int smb_full_audit_removexattr(struct vfs_handle_struct *handle,
2814 const struct smb_filename *smb_fname,
2819 result = SMB_VFS_NEXT_REMOVEXATTR(handle, smb_fname, name);
2821 do_log(SMB_VFS_OP_REMOVEXATTR,
2825 smb_fname_str_do_log(handle->conn, smb_fname),
2831 static int smb_full_audit_fremovexattr(struct vfs_handle_struct *handle,
2832 struct files_struct *fsp,
2837 result = SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, name);
2839 do_log(SMB_VFS_OP_FREMOVEXATTR, (result >= 0), handle,
2840 "%s|%s", fsp_str_do_log(fsp), name);
2845 static int smb_full_audit_setxattr(struct vfs_handle_struct *handle,
2846 const struct smb_filename *smb_fname,
2847 const char *name, const void *value, size_t size,
2852 result = SMB_VFS_NEXT_SETXATTR(handle, smb_fname, name, value, size,
2855 do_log(SMB_VFS_OP_SETXATTR,
2859 smb_fname_str_do_log(handle->conn, smb_fname),
2865 static int smb_full_audit_fsetxattr(struct vfs_handle_struct *handle,
2866 struct files_struct *fsp, const char *name,
2867 const void *value, size_t size, int flags)
2871 result = SMB_VFS_NEXT_FSETXATTR(handle, fsp, name, value, size, flags);
2873 do_log(SMB_VFS_OP_FSETXATTR, (result >= 0), handle,
2874 "%s|%s", fsp_str_do_log(fsp), name);
2879 static bool smb_full_audit_aio_force(struct vfs_handle_struct *handle,
2880 struct files_struct *fsp)
2884 result = SMB_VFS_NEXT_AIO_FORCE(handle, fsp);
2885 do_log(SMB_VFS_OP_AIO_FORCE, result, handle,
2886 "%s", fsp_str_do_log(fsp));
2891 static NTSTATUS smb_full_audit_durable_cookie(struct vfs_handle_struct *handle,
2892 struct files_struct *fsp,
2893 TALLOC_CTX *mem_ctx,
2898 result = SMB_VFS_NEXT_DURABLE_COOKIE(handle,
2903 do_log(SMB_VFS_OP_DURABLE_COOKIE, NT_STATUS_IS_OK(result), handle,
2904 "%s", fsp_str_do_log(fsp));
2909 static NTSTATUS smb_full_audit_durable_disconnect(
2910 struct vfs_handle_struct *handle,
2911 struct files_struct *fsp,
2912 const DATA_BLOB old_cookie,
2913 TALLOC_CTX *mem_ctx,
2914 DATA_BLOB *new_cookie)
2918 result = SMB_VFS_NEXT_DURABLE_DISCONNECT(handle,
2924 do_log(SMB_VFS_OP_DURABLE_DISCONNECT, NT_STATUS_IS_OK(result), handle,
2925 "%s", fsp_str_do_log(fsp));
2930 static NTSTATUS smb_full_audit_durable_reconnect(
2931 struct vfs_handle_struct *handle,
2932 struct smb_request *smb1req,
2933 struct smbXsrv_open *op,
2934 const DATA_BLOB old_cookie,
2935 TALLOC_CTX *mem_ctx,
2936 struct files_struct **fsp,
2937 DATA_BLOB *new_cookie)
2941 result = SMB_VFS_NEXT_DURABLE_RECONNECT(handle,
2949 do_log(SMB_VFS_OP_DURABLE_RECONNECT,
2950 NT_STATUS_IS_OK(result),
2957 static struct vfs_fn_pointers vfs_full_audit_fns = {
2959 /* Disk operations */
2961 .connect_fn = smb_full_audit_connect,
2962 .disconnect_fn = smb_full_audit_disconnect,
2963 .disk_free_fn = smb_full_audit_disk_free,
2964 .get_quota_fn = smb_full_audit_get_quota,
2965 .set_quota_fn = smb_full_audit_set_quota,
2966 .get_shadow_copy_data_fn = smb_full_audit_get_shadow_copy_data,
2967 .statvfs_fn = smb_full_audit_statvfs,
2968 .fs_capabilities_fn = smb_full_audit_fs_capabilities,
2969 .get_dfs_referrals_fn = smb_full_audit_get_dfs_referrals,
2970 .create_dfs_pathat_fn = smb_full_audit_create_dfs_pathat,
2971 .read_dfs_pathat_fn = smb_full_audit_read_dfs_pathat,
2972 .fdopendir_fn = smb_full_audit_fdopendir,
2973 .readdir_fn = smb_full_audit_readdir,
2974 .seekdir_fn = smb_full_audit_seekdir,
2975 .telldir_fn = smb_full_audit_telldir,
2976 .rewind_dir_fn = smb_full_audit_rewinddir,
2977 .mkdirat_fn = smb_full_audit_mkdirat,
2978 .closedir_fn = smb_full_audit_closedir,
2979 .open_fn = smb_full_audit_open,
2980 .create_file_fn = smb_full_audit_create_file,
2981 .close_fn = smb_full_audit_close,
2982 .pread_fn = smb_full_audit_pread,
2983 .pread_send_fn = smb_full_audit_pread_send,
2984 .pread_recv_fn = smb_full_audit_pread_recv,
2985 .pwrite_fn = smb_full_audit_pwrite,
2986 .pwrite_send_fn = smb_full_audit_pwrite_send,
2987 .pwrite_recv_fn = smb_full_audit_pwrite_recv,
2988 .lseek_fn = smb_full_audit_lseek,
2989 .sendfile_fn = smb_full_audit_sendfile,
2990 .recvfile_fn = smb_full_audit_recvfile,
2991 .renameat_fn = smb_full_audit_renameat,
2992 .fsync_send_fn = smb_full_audit_fsync_send,
2993 .fsync_recv_fn = smb_full_audit_fsync_recv,
2994 .stat_fn = smb_full_audit_stat,
2995 .fstat_fn = smb_full_audit_fstat,
2996 .lstat_fn = smb_full_audit_lstat,
2997 .get_alloc_size_fn = smb_full_audit_get_alloc_size,
2998 .unlinkat_fn = smb_full_audit_unlinkat,
2999 .chmod_fn = smb_full_audit_chmod,
3000 .fchmod_fn = smb_full_audit_fchmod,
3001 .fchown_fn = smb_full_audit_fchown,
3002 .lchown_fn = smb_full_audit_lchown,
3003 .chdir_fn = smb_full_audit_chdir,
3004 .getwd_fn = smb_full_audit_getwd,
3005 .ntimes_fn = smb_full_audit_ntimes,
3006 .ftruncate_fn = smb_full_audit_ftruncate,
3007 .fallocate_fn = smb_full_audit_fallocate,
3008 .lock_fn = smb_full_audit_lock,
3009 .kernel_flock_fn = smb_full_audit_kernel_flock,
3010 .fcntl_fn = smb_full_audit_fcntl,
3011 .linux_setlease_fn = smb_full_audit_linux_setlease,
3012 .getlock_fn = smb_full_audit_getlock,
3013 .symlinkat_fn = smb_full_audit_symlinkat,
3014 .readlinkat_fn = smb_full_audit_readlinkat,
3015 .linkat_fn = smb_full_audit_linkat,
3016 .mknodat_fn = smb_full_audit_mknodat,
3017 .realpath_fn = smb_full_audit_realpath,
3018 .chflags_fn = smb_full_audit_chflags,
3019 .file_id_create_fn = smb_full_audit_file_id_create,
3020 .fs_file_id_fn = smb_full_audit_fs_file_id,
3021 .offload_read_send_fn = smb_full_audit_offload_read_send,
3022 .offload_read_recv_fn = smb_full_audit_offload_read_recv,
3023 .offload_write_send_fn = smb_full_audit_offload_write_send,
3024 .offload_write_recv_fn = smb_full_audit_offload_write_recv,
3025 .get_compression_fn = smb_full_audit_get_compression,
3026 .set_compression_fn = smb_full_audit_set_compression,
3027 .snap_check_path_fn = smb_full_audit_snap_check_path,
3028 .snap_create_fn = smb_full_audit_snap_create,
3029 .snap_delete_fn = smb_full_audit_snap_delete,
3030 .streaminfo_fn = smb_full_audit_streaminfo,
3031 .get_real_filename_fn = smb_full_audit_get_real_filename,
3032 .connectpath_fn = smb_full_audit_connectpath,
3033 .brl_lock_windows_fn = smb_full_audit_brl_lock_windows,
3034 .brl_unlock_windows_fn = smb_full_audit_brl_unlock_windows,
3035 .strict_lock_check_fn = smb_full_audit_strict_lock_check,
3036 .translate_name_fn = smb_full_audit_translate_name,
3037 .fsctl_fn = smb_full_audit_fsctl,
3038 .get_dos_attributes_fn = smb_full_audit_get_dos_attributes,
3039 .get_dos_attributes_send_fn = smb_full_audit_get_dos_attributes_send,
3040 .get_dos_attributes_recv_fn = smb_full_audit_get_dos_attributes_recv,
3041 .fget_dos_attributes_fn = smb_full_audit_fget_dos_attributes,
3042 .set_dos_attributes_fn = smb_full_audit_set_dos_attributes,
3043 .fset_dos_attributes_fn = smb_full_audit_fset_dos_attributes,
3044 .fget_nt_acl_fn = smb_full_audit_fget_nt_acl,
3045 .get_nt_acl_fn = smb_full_audit_get_nt_acl,
3046 .fset_nt_acl_fn = smb_full_audit_fset_nt_acl,
3047 .audit_file_fn = smb_full_audit_audit_file,
3048 .sys_acl_get_file_fn = smb_full_audit_sys_acl_get_file,
3049 .sys_acl_get_fd_fn = smb_full_audit_sys_acl_get_fd,
3050 .sys_acl_blob_get_file_fn = smb_full_audit_sys_acl_blob_get_file,
3051 .sys_acl_blob_get_fd_fn = smb_full_audit_sys_acl_blob_get_fd,
3052 .sys_acl_set_file_fn = smb_full_audit_sys_acl_set_file,
3053 .sys_acl_set_fd_fn = smb_full_audit_sys_acl_set_fd,
3054 .sys_acl_delete_def_file_fn = smb_full_audit_sys_acl_delete_def_file,
3055 .getxattr_fn = smb_full_audit_getxattr,
3056 .getxattrat_send_fn = smb_full_audit_getxattrat_send,
3057 .getxattrat_recv_fn = smb_full_audit_getxattrat_recv,
3058 .fgetxattr_fn = smb_full_audit_fgetxattr,
3059 .listxattr_fn = smb_full_audit_listxattr,
3060 .flistxattr_fn = smb_full_audit_flistxattr,
3061 .removexattr_fn = smb_full_audit_removexattr,
3062 .fremovexattr_fn = smb_full_audit_fremovexattr,
3063 .setxattr_fn = smb_full_audit_setxattr,
3064 .fsetxattr_fn = smb_full_audit_fsetxattr,
3065 .aio_force_fn = smb_full_audit_aio_force,
3066 .durable_cookie_fn = smb_full_audit_durable_cookie,
3067 .durable_disconnect_fn = smb_full_audit_durable_disconnect,
3068 .durable_reconnect_fn = smb_full_audit_durable_reconnect,
3069 .readdir_attr_fn = smb_full_audit_readdir_attr
3074 NTSTATUS vfs_full_audit_init(TALLOC_CTX *ctx)
3078 smb_vfs_assert_all_fns(&vfs_full_audit_fns, "full_audit");
3080 ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "full_audit",
3081 &vfs_full_audit_fns);
3083 if (!NT_STATUS_IS_OK(ret))
3086 vfs_full_audit_debug_level = debug_add_class("full_audit");
3087 if (vfs_full_audit_debug_level == -1) {
3088 vfs_full_audit_debug_level = DBGC_VFS;
3089 DEBUG(0, ("vfs_full_audit: Couldn't register custom debugging "
3092 DEBUG(10, ("vfs_full_audit: Debug class number of "
3093 "'full_audit': %d\n", vfs_full_audit_debug_level));