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,
106 /* 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_OPENDIR, "opendir" },
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_snap_check_path(struct vfs_handle_struct *handle,
920 const char *service_path,
925 status = SMB_VFS_NEXT_SNAP_CHECK_PATH(handle, mem_ctx, service_path,
927 do_log(SMB_VFS_OP_SNAP_CHECK_PATH, NT_STATUS_IS_OK(status),
933 static NTSTATUS smb_full_audit_snap_create(struct vfs_handle_struct *handle,
935 const char *base_volume,
943 status = SMB_VFS_NEXT_SNAP_CREATE(handle, mem_ctx, base_volume, tstamp,
944 rw, base_path, snap_path);
945 do_log(SMB_VFS_OP_SNAP_CREATE, NT_STATUS_IS_OK(status), handle, "");
950 static NTSTATUS smb_full_audit_snap_delete(struct vfs_handle_struct *handle,
957 status = SMB_VFS_NEXT_SNAP_DELETE(handle, mem_ctx, base_path,
959 do_log(SMB_VFS_OP_SNAP_DELETE, NT_STATUS_IS_OK(status), handle, "");
964 static DIR *smb_full_audit_opendir(vfs_handle_struct *handle,
965 const struct smb_filename *smb_fname,
971 result = SMB_VFS_NEXT_OPENDIR(handle, smb_fname, mask, attr);
973 do_log(SMB_VFS_OP_OPENDIR,
977 smb_fname_str_do_log(handle->conn, smb_fname));
982 static DIR *smb_full_audit_fdopendir(vfs_handle_struct *handle,
983 files_struct *fsp, const char *mask, uint32_t attr)
987 result = SMB_VFS_NEXT_FDOPENDIR(handle, fsp, mask, attr);
989 do_log(SMB_VFS_OP_FDOPENDIR, (result != NULL), handle, "%s",
990 fsp_str_do_log(fsp));
995 static struct dirent *smb_full_audit_readdir(vfs_handle_struct *handle,
996 DIR *dirp, SMB_STRUCT_STAT *sbuf)
998 struct dirent *result;
1000 result = SMB_VFS_NEXT_READDIR(handle, dirp, sbuf);
1002 /* This operation has no reasonable error condition
1003 * (End of dir is also failure), so always succeed.
1005 do_log(SMB_VFS_OP_READDIR, True, handle, "");
1010 static void smb_full_audit_seekdir(vfs_handle_struct *handle,
1011 DIR *dirp, long offset)
1013 SMB_VFS_NEXT_SEEKDIR(handle, dirp, offset);
1015 do_log(SMB_VFS_OP_SEEKDIR, True, handle, "");
1018 static long smb_full_audit_telldir(vfs_handle_struct *handle,
1023 result = SMB_VFS_NEXT_TELLDIR(handle, dirp);
1025 do_log(SMB_VFS_OP_TELLDIR, True, handle, "");
1030 static void smb_full_audit_rewinddir(vfs_handle_struct *handle,
1033 SMB_VFS_NEXT_REWINDDIR(handle, dirp);
1035 do_log(SMB_VFS_OP_REWINDDIR, True, handle, "");
1038 static int smb_full_audit_mkdirat(vfs_handle_struct *handle,
1039 struct files_struct *dirfsp,
1040 const struct smb_filename *smb_fname,
1045 result = SMB_VFS_NEXT_MKDIRAT(handle,
1050 do_log(SMB_VFS_OP_MKDIRAT,
1054 smb_fname_str_do_log(handle->conn, smb_fname));
1059 static int smb_full_audit_closedir(vfs_handle_struct *handle,
1064 result = SMB_VFS_NEXT_CLOSEDIR(handle, dirp);
1066 do_log(SMB_VFS_OP_CLOSEDIR, (result >= 0), handle, "");
1071 static int smb_full_audit_open(vfs_handle_struct *handle,
1072 struct smb_filename *smb_fname,
1073 files_struct *fsp, int flags, mode_t mode)
1077 result = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
1079 do_log(SMB_VFS_OP_OPEN, (result >= 0), handle, "%s|%s",
1080 ((flags & O_WRONLY) || (flags & O_RDWR))?"w":"r",
1081 smb_fname_str_do_log(handle->conn, smb_fname));
1086 static NTSTATUS smb_full_audit_create_file(vfs_handle_struct *handle,
1087 struct smb_request *req,
1088 uint16_t root_dir_fid,
1089 struct smb_filename *smb_fname,
1090 uint32_t access_mask,
1091 uint32_t share_access,
1092 uint32_t create_disposition,
1093 uint32_t create_options,
1094 uint32_t file_attributes,
1095 uint32_t oplock_request,
1096 const struct smb2_lease *lease,
1097 uint64_t allocation_size,
1098 uint32_t private_flags,
1099 struct security_descriptor *sd,
1100 struct ea_list *ea_list,
1101 files_struct **result_fsp,
1103 const struct smb2_create_blobs *in_context_blobs,
1104 struct smb2_create_blobs *out_context_blobs)
1107 const char* str_create_disposition;
1109 switch (create_disposition) {
1110 case FILE_SUPERSEDE:
1111 str_create_disposition = "supersede";
1113 case FILE_OVERWRITE_IF:
1114 str_create_disposition = "overwrite_if";
1117 str_create_disposition = "open";
1119 case FILE_OVERWRITE:
1120 str_create_disposition = "overwrite";
1123 str_create_disposition = "create";
1126 str_create_disposition = "open_if";
1129 str_create_disposition = "unknown";
1132 result = SMB_VFS_NEXT_CREATE_FILE(
1133 handle, /* handle */
1135 root_dir_fid, /* root_dir_fid */
1136 smb_fname, /* fname */
1137 access_mask, /* access_mask */
1138 share_access, /* share_access */
1139 create_disposition, /* create_disposition*/
1140 create_options, /* create_options */
1141 file_attributes, /* file_attributes */
1142 oplock_request, /* oplock_request */
1144 allocation_size, /* allocation_size */
1147 ea_list, /* ea_list */
1148 result_fsp, /* result */
1150 in_context_blobs, out_context_blobs); /* create context */
1152 do_log(SMB_VFS_OP_CREATE_FILE, (NT_STATUS_IS_OK(result)), handle,
1153 "0x%x|%s|%s|%s", access_mask,
1154 create_options & FILE_DIRECTORY_FILE ? "dir" : "file",
1155 str_create_disposition,
1156 smb_fname_str_do_log(handle->conn, smb_fname));
1161 static int smb_full_audit_close(vfs_handle_struct *handle, files_struct *fsp)
1165 result = SMB_VFS_NEXT_CLOSE(handle, fsp);
1167 do_log(SMB_VFS_OP_CLOSE, (result >= 0), handle, "%s",
1168 fsp_str_do_log(fsp));
1173 static ssize_t smb_full_audit_pread(vfs_handle_struct *handle, files_struct *fsp,
1174 void *data, size_t n, off_t offset)
1178 result = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
1180 do_log(SMB_VFS_OP_PREAD, (result >= 0), handle, "%s",
1181 fsp_str_do_log(fsp));
1186 struct smb_full_audit_pread_state {
1187 vfs_handle_struct *handle;
1190 struct vfs_aio_state vfs_aio_state;
1193 static void smb_full_audit_pread_done(struct tevent_req *subreq);
1195 static struct tevent_req *smb_full_audit_pread_send(
1196 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1197 struct tevent_context *ev, struct files_struct *fsp,
1198 void *data, size_t n, off_t offset)
1200 struct tevent_req *req, *subreq;
1201 struct smb_full_audit_pread_state *state;
1203 req = tevent_req_create(mem_ctx, &state,
1204 struct smb_full_audit_pread_state);
1206 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
1207 fsp_str_do_log(fsp));
1210 state->handle = handle;
1213 subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
1215 if (tevent_req_nomem(subreq, req)) {
1216 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
1217 fsp_str_do_log(fsp));
1218 return tevent_req_post(req, ev);
1220 tevent_req_set_callback(subreq, smb_full_audit_pread_done, req);
1222 do_log(SMB_VFS_OP_PREAD_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1226 static void smb_full_audit_pread_done(struct tevent_req *subreq)
1228 struct tevent_req *req = tevent_req_callback_data(
1229 subreq, struct tevent_req);
1230 struct smb_full_audit_pread_state *state = tevent_req_data(
1231 req, struct smb_full_audit_pread_state);
1233 state->ret = SMB_VFS_PREAD_RECV(subreq, &state->vfs_aio_state);
1234 TALLOC_FREE(subreq);
1235 tevent_req_done(req);
1238 static ssize_t smb_full_audit_pread_recv(struct tevent_req *req,
1239 struct vfs_aio_state *vfs_aio_state)
1241 struct smb_full_audit_pread_state *state = tevent_req_data(
1242 req, struct smb_full_audit_pread_state);
1244 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1245 do_log(SMB_VFS_OP_PREAD_RECV, false, state->handle, "%s",
1246 fsp_str_do_log(state->fsp));
1250 do_log(SMB_VFS_OP_PREAD_RECV, (state->ret >= 0), state->handle, "%s",
1251 fsp_str_do_log(state->fsp));
1253 *vfs_aio_state = state->vfs_aio_state;
1257 static ssize_t smb_full_audit_pwrite(vfs_handle_struct *handle, files_struct *fsp,
1258 const void *data, size_t n,
1263 result = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
1265 do_log(SMB_VFS_OP_PWRITE, (result >= 0), handle, "%s",
1266 fsp_str_do_log(fsp));
1271 struct smb_full_audit_pwrite_state {
1272 vfs_handle_struct *handle;
1275 struct vfs_aio_state vfs_aio_state;
1278 static void smb_full_audit_pwrite_done(struct tevent_req *subreq);
1280 static struct tevent_req *smb_full_audit_pwrite_send(
1281 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1282 struct tevent_context *ev, struct files_struct *fsp,
1283 const void *data, size_t n, off_t offset)
1285 struct tevent_req *req, *subreq;
1286 struct smb_full_audit_pwrite_state *state;
1288 req = tevent_req_create(mem_ctx, &state,
1289 struct smb_full_audit_pwrite_state);
1291 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1292 fsp_str_do_log(fsp));
1295 state->handle = handle;
1298 subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
1300 if (tevent_req_nomem(subreq, req)) {
1301 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1302 fsp_str_do_log(fsp));
1303 return tevent_req_post(req, ev);
1305 tevent_req_set_callback(subreq, smb_full_audit_pwrite_done, req);
1307 do_log(SMB_VFS_OP_PWRITE_SEND, true, handle, "%s",
1308 fsp_str_do_log(fsp));
1312 static void smb_full_audit_pwrite_done(struct tevent_req *subreq)
1314 struct tevent_req *req = tevent_req_callback_data(
1315 subreq, struct tevent_req);
1316 struct smb_full_audit_pwrite_state *state = tevent_req_data(
1317 req, struct smb_full_audit_pwrite_state);
1319 state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->vfs_aio_state);
1320 TALLOC_FREE(subreq);
1321 tevent_req_done(req);
1324 static ssize_t smb_full_audit_pwrite_recv(struct tevent_req *req,
1325 struct vfs_aio_state *vfs_aio_state)
1327 struct smb_full_audit_pwrite_state *state = tevent_req_data(
1328 req, struct smb_full_audit_pwrite_state);
1330 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1331 do_log(SMB_VFS_OP_PWRITE_RECV, false, state->handle, "%s",
1332 fsp_str_do_log(state->fsp));
1336 do_log(SMB_VFS_OP_PWRITE_RECV, (state->ret >= 0), state->handle, "%s",
1337 fsp_str_do_log(state->fsp));
1339 *vfs_aio_state = state->vfs_aio_state;
1343 static off_t smb_full_audit_lseek(vfs_handle_struct *handle, files_struct *fsp,
1344 off_t offset, int whence)
1348 result = SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence);
1350 do_log(SMB_VFS_OP_LSEEK, (result != (ssize_t)-1), handle,
1351 "%s", fsp_str_do_log(fsp));
1356 static ssize_t smb_full_audit_sendfile(vfs_handle_struct *handle, int tofd,
1357 files_struct *fromfsp,
1358 const DATA_BLOB *hdr, off_t offset,
1363 result = SMB_VFS_NEXT_SENDFILE(handle, tofd, fromfsp, hdr, offset, n);
1365 do_log(SMB_VFS_OP_SENDFILE, (result >= 0), handle,
1366 "%s", fsp_str_do_log(fromfsp));
1371 static ssize_t smb_full_audit_recvfile(vfs_handle_struct *handle, int fromfd,
1372 files_struct *tofsp,
1378 result = SMB_VFS_NEXT_RECVFILE(handle, fromfd, tofsp, offset, n);
1380 do_log(SMB_VFS_OP_RECVFILE, (result >= 0), handle,
1381 "%s", fsp_str_do_log(tofsp));
1386 static int smb_full_audit_renameat(vfs_handle_struct *handle,
1387 files_struct *srcfsp,
1388 const struct smb_filename *smb_fname_src,
1389 files_struct *dstfsp,
1390 const struct smb_filename *smb_fname_dst)
1394 result = SMB_VFS_NEXT_RENAMEAT(handle,
1400 do_log(SMB_VFS_OP_RENAMEAT, (result >= 0), handle, "%s|%s",
1401 smb_fname_str_do_log(handle->conn, smb_fname_src),
1402 smb_fname_str_do_log(handle->conn, smb_fname_dst));
1407 struct smb_full_audit_fsync_state {
1408 vfs_handle_struct *handle;
1411 struct vfs_aio_state vfs_aio_state;
1414 static void smb_full_audit_fsync_done(struct tevent_req *subreq);
1416 static struct tevent_req *smb_full_audit_fsync_send(
1417 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1418 struct tevent_context *ev, struct files_struct *fsp)
1420 struct tevent_req *req, *subreq;
1421 struct smb_full_audit_fsync_state *state;
1423 req = tevent_req_create(mem_ctx, &state,
1424 struct smb_full_audit_fsync_state);
1426 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1427 fsp_str_do_log(fsp));
1430 state->handle = handle;
1433 subreq = SMB_VFS_NEXT_FSYNC_SEND(state, ev, handle, fsp);
1434 if (tevent_req_nomem(subreq, req)) {
1435 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1436 fsp_str_do_log(fsp));
1437 return tevent_req_post(req, ev);
1439 tevent_req_set_callback(subreq, smb_full_audit_fsync_done, req);
1441 do_log(SMB_VFS_OP_FSYNC_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1445 static void smb_full_audit_fsync_done(struct tevent_req *subreq)
1447 struct tevent_req *req = tevent_req_callback_data(
1448 subreq, struct tevent_req);
1449 struct smb_full_audit_fsync_state *state = tevent_req_data(
1450 req, struct smb_full_audit_fsync_state);
1452 state->ret = SMB_VFS_FSYNC_RECV(subreq, &state->vfs_aio_state);
1453 TALLOC_FREE(subreq);
1454 tevent_req_done(req);
1457 static int smb_full_audit_fsync_recv(struct tevent_req *req,
1458 struct vfs_aio_state *vfs_aio_state)
1460 struct smb_full_audit_fsync_state *state = tevent_req_data(
1461 req, struct smb_full_audit_fsync_state);
1463 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1464 do_log(SMB_VFS_OP_FSYNC_RECV, false, state->handle, "%s",
1465 fsp_str_do_log(state->fsp));
1469 do_log(SMB_VFS_OP_FSYNC_RECV, (state->ret >= 0), state->handle, "%s",
1470 fsp_str_do_log(state->fsp));
1472 *vfs_aio_state = state->vfs_aio_state;
1476 static int smb_full_audit_stat(vfs_handle_struct *handle,
1477 struct smb_filename *smb_fname)
1481 result = SMB_VFS_NEXT_STAT(handle, smb_fname);
1483 do_log(SMB_VFS_OP_STAT, (result >= 0), handle, "%s",
1484 smb_fname_str_do_log(handle->conn, smb_fname));
1489 static int smb_full_audit_fstat(vfs_handle_struct *handle, files_struct *fsp,
1490 SMB_STRUCT_STAT *sbuf)
1494 result = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1496 do_log(SMB_VFS_OP_FSTAT, (result >= 0), handle, "%s",
1497 fsp_str_do_log(fsp));
1502 static int smb_full_audit_lstat(vfs_handle_struct *handle,
1503 struct smb_filename *smb_fname)
1507 result = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
1509 do_log(SMB_VFS_OP_LSTAT, (result >= 0), handle, "%s",
1510 smb_fname_str_do_log(handle->conn, smb_fname));
1515 static uint64_t smb_full_audit_get_alloc_size(vfs_handle_struct *handle,
1516 files_struct *fsp, const SMB_STRUCT_STAT *sbuf)
1520 result = SMB_VFS_NEXT_GET_ALLOC_SIZE(handle, fsp, sbuf);
1522 do_log(SMB_VFS_OP_GET_ALLOC_SIZE, (result != (uint64_t)-1), handle,
1523 "%llu", (unsigned long long)result);
1528 static int smb_full_audit_unlinkat(vfs_handle_struct *handle,
1529 struct files_struct *dirfsp,
1530 const struct smb_filename *smb_fname,
1535 result = SMB_VFS_NEXT_UNLINKAT(handle,
1540 do_log(SMB_VFS_OP_UNLINKAT, (result >= 0), handle, "%s",
1541 smb_fname_str_do_log(handle->conn, smb_fname));
1546 static int smb_full_audit_chmod(vfs_handle_struct *handle,
1547 const struct smb_filename *smb_fname,
1552 result = SMB_VFS_NEXT_CHMOD(handle, smb_fname, mode);
1554 do_log(SMB_VFS_OP_CHMOD,
1558 smb_fname_str_do_log(handle->conn, smb_fname),
1564 static int smb_full_audit_fchmod(vfs_handle_struct *handle, files_struct *fsp,
1569 result = SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1571 do_log(SMB_VFS_OP_FCHMOD, (result >= 0), handle,
1572 "%s|%o", fsp_str_do_log(fsp), mode);
1577 static int smb_full_audit_fchown(vfs_handle_struct *handle, files_struct *fsp,
1578 uid_t uid, gid_t gid)
1582 result = SMB_VFS_NEXT_FCHOWN(handle, fsp, uid, gid);
1584 do_log(SMB_VFS_OP_FCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1585 fsp_str_do_log(fsp), (long int)uid, (long int)gid);
1590 static int smb_full_audit_lchown(vfs_handle_struct *handle,
1591 const struct smb_filename *smb_fname,
1597 result = SMB_VFS_NEXT_LCHOWN(handle, smb_fname, uid, gid);
1599 do_log(SMB_VFS_OP_LCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1600 smb_fname->base_name, (long int)uid, (long int)gid);
1605 static int smb_full_audit_chdir(vfs_handle_struct *handle,
1606 const struct smb_filename *smb_fname)
1610 result = SMB_VFS_NEXT_CHDIR(handle, smb_fname);
1612 do_log(SMB_VFS_OP_CHDIR,
1616 smb_fname_str_do_log(handle->conn, smb_fname));
1621 static struct smb_filename *smb_full_audit_getwd(vfs_handle_struct *handle,
1624 struct smb_filename *result;
1626 result = SMB_VFS_NEXT_GETWD(handle, ctx);
1628 do_log(SMB_VFS_OP_GETWD, (result != NULL), handle, "%s",
1629 result == NULL? "" : result->base_name);
1634 static int smb_full_audit_ntimes(vfs_handle_struct *handle,
1635 const struct smb_filename *smb_fname,
1636 struct smb_file_time *ft)
1639 time_t create_time = convert_timespec_to_time_t(ft->create_time);
1640 time_t atime = convert_timespec_to_time_t(ft->atime);
1641 time_t mtime = convert_timespec_to_time_t(ft->mtime);
1642 time_t ctime = convert_timespec_to_time_t(ft->ctime);
1643 const char *create_time_str = "";
1644 const char *atime_str = "";
1645 const char *mtime_str = "";
1646 const char *ctime_str = "";
1647 TALLOC_CTX *frame = talloc_stackframe();
1649 result = SMB_VFS_NEXT_NTIMES(handle, smb_fname, ft);
1651 if (create_time > 0) {
1652 create_time_str = timestring(frame, create_time);
1655 atime_str = timestring(frame, atime);
1658 mtime_str = timestring(frame, mtime);
1661 ctime_str = timestring(frame, ctime);
1664 do_log(SMB_VFS_OP_NTIMES,
1668 smb_fname_str_do_log(handle->conn, smb_fname),
1679 static int smb_full_audit_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
1684 result = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1686 do_log(SMB_VFS_OP_FTRUNCATE, (result >= 0), handle,
1687 "%s", fsp_str_do_log(fsp));
1692 static int smb_full_audit_fallocate(vfs_handle_struct *handle, files_struct *fsp,
1699 result = SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
1701 do_log(SMB_VFS_OP_FALLOCATE, (result >= 0), handle,
1702 "%s", fsp_str_do_log(fsp));
1707 static bool smb_full_audit_lock(vfs_handle_struct *handle, files_struct *fsp,
1708 int op, off_t offset, off_t count, int type)
1712 result = SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type);
1714 do_log(SMB_VFS_OP_LOCK, result, handle, "%s", fsp_str_do_log(fsp));
1719 static int smb_full_audit_kernel_flock(struct vfs_handle_struct *handle,
1720 struct files_struct *fsp,
1721 uint32_t share_access,
1722 uint32_t access_mask)
1726 result = SMB_VFS_NEXT_KERNEL_FLOCK(handle,
1731 do_log(SMB_VFS_OP_KERNEL_FLOCK, (result >= 0), handle, "%s",
1732 fsp_str_do_log(fsp));
1737 static int smb_full_audit_fcntl(struct vfs_handle_struct *handle,
1738 struct files_struct *fsp,
1739 int cmd, va_list cmd_arg)
1742 va_list dup_cmd_arg;
1745 va_copy(dup_cmd_arg, cmd_arg);
1746 arg = va_arg(dup_cmd_arg, void *);
1747 result = SMB_VFS_NEXT_FCNTL(handle, fsp, cmd, arg);
1748 va_end(dup_cmd_arg);
1750 do_log(SMB_VFS_OP_FCNTL, (result >= 0), handle, "%s",
1751 fsp_str_do_log(fsp));
1756 static int smb_full_audit_linux_setlease(vfs_handle_struct *handle, files_struct *fsp,
1761 result = SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
1763 do_log(SMB_VFS_OP_LINUX_SETLEASE, (result >= 0), handle, "%s",
1764 fsp_str_do_log(fsp));
1769 static bool smb_full_audit_getlock(vfs_handle_struct *handle, files_struct *fsp,
1770 off_t *poffset, off_t *pcount, int *ptype, pid_t *ppid)
1774 result = SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype, ppid);
1776 do_log(SMB_VFS_OP_GETLOCK, result, handle, "%s", fsp_str_do_log(fsp));
1781 static int smb_full_audit_symlinkat(vfs_handle_struct *handle,
1782 const char *link_contents,
1783 struct files_struct *dirfsp,
1784 const struct smb_filename *new_smb_fname)
1788 result = SMB_VFS_NEXT_SYMLINKAT(handle,
1793 do_log(SMB_VFS_OP_SYMLINKAT,
1798 smb_fname_str_do_log(handle->conn, new_smb_fname));
1803 static int smb_full_audit_readlinkat(vfs_handle_struct *handle,
1804 files_struct *dirfsp,
1805 const struct smb_filename *smb_fname,
1811 result = SMB_VFS_NEXT_READLINKAT(handle,
1817 do_log(SMB_VFS_OP_READLINKAT,
1821 smb_fname_str_do_log(handle->conn, smb_fname));
1826 static int smb_full_audit_linkat(vfs_handle_struct *handle,
1827 files_struct *srcfsp,
1828 const struct smb_filename *old_smb_fname,
1829 files_struct *dstfsp,
1830 const struct smb_filename *new_smb_fname,
1835 result = SMB_VFS_NEXT_LINKAT(handle,
1842 do_log(SMB_VFS_OP_LINKAT,
1846 smb_fname_str_do_log(handle->conn, old_smb_fname),
1847 smb_fname_str_do_log(handle->conn, new_smb_fname));
1852 static int smb_full_audit_mknodat(vfs_handle_struct *handle,
1853 files_struct *dirfsp,
1854 const struct smb_filename *smb_fname,
1860 result = SMB_VFS_NEXT_MKNODAT(handle,
1866 do_log(SMB_VFS_OP_MKNODAT,
1870 smb_fname_str_do_log(handle->conn, smb_fname));
1875 static struct smb_filename *smb_full_audit_realpath(vfs_handle_struct *handle,
1877 const struct smb_filename *smb_fname)
1879 struct smb_filename *result_fname = NULL;
1881 result_fname = SMB_VFS_NEXT_REALPATH(handle, ctx, smb_fname);
1883 do_log(SMB_VFS_OP_REALPATH,
1884 (result_fname != NULL),
1887 smb_fname_str_do_log(handle->conn, smb_fname));
1889 return result_fname;
1892 static int smb_full_audit_chflags(vfs_handle_struct *handle,
1893 const struct smb_filename *smb_fname,
1898 result = SMB_VFS_NEXT_CHFLAGS(handle, smb_fname, flags);
1900 do_log(SMB_VFS_OP_CHFLAGS,
1904 smb_fname_str_do_log(handle->conn, smb_fname));
1909 static struct file_id smb_full_audit_file_id_create(struct vfs_handle_struct *handle,
1910 const SMB_STRUCT_STAT *sbuf)
1912 struct file_id id_zero = { 0 };
1913 struct file_id result;
1914 struct file_id_buf idbuf;
1916 result = SMB_VFS_NEXT_FILE_ID_CREATE(handle, sbuf);
1918 do_log(SMB_VFS_OP_FILE_ID_CREATE,
1919 !file_id_equal(&id_zero, &result),
1922 file_id_str_buf(result, &idbuf));
1927 static uint64_t smb_full_audit_fs_file_id(struct vfs_handle_struct *handle,
1928 const SMB_STRUCT_STAT *sbuf)
1932 result = SMB_VFS_NEXT_FS_FILE_ID(handle, sbuf);
1934 do_log(SMB_VFS_OP_FS_FILE_ID,
1936 handle, "%" PRIu64, result);
1941 static NTSTATUS smb_full_audit_streaminfo(vfs_handle_struct *handle,
1942 struct files_struct *fsp,
1943 const struct smb_filename *smb_fname,
1944 TALLOC_CTX *mem_ctx,
1945 unsigned int *pnum_streams,
1946 struct stream_struct **pstreams)
1950 result = SMB_VFS_NEXT_STREAMINFO(handle, fsp, smb_fname, mem_ctx,
1951 pnum_streams, pstreams);
1953 do_log(SMB_VFS_OP_STREAMINFO,
1954 NT_STATUS_IS_OK(result),
1957 smb_fname_str_do_log(handle->conn, smb_fname));
1962 static int smb_full_audit_get_real_filename(struct vfs_handle_struct *handle,
1965 TALLOC_CTX *mem_ctx,
1970 result = SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name, mem_ctx,
1973 do_log(SMB_VFS_OP_GET_REAL_FILENAME, (result == 0), handle,
1974 "%s/%s->%s", path, name, (result == 0) ? *found_name : "");
1979 static const char *smb_full_audit_connectpath(vfs_handle_struct *handle,
1980 const struct smb_filename *smb_fname)
1984 result = SMB_VFS_NEXT_CONNECTPATH(handle, smb_fname);
1986 do_log(SMB_VFS_OP_CONNECTPATH,
1990 smb_fname_str_do_log(handle->conn, smb_fname));
1995 static NTSTATUS smb_full_audit_brl_lock_windows(struct vfs_handle_struct *handle,
1996 struct byte_range_lock *br_lck,
1997 struct lock_struct *plock)
2001 result = SMB_VFS_NEXT_BRL_LOCK_WINDOWS(handle, br_lck, plock);
2003 do_log(SMB_VFS_OP_BRL_LOCK_WINDOWS, NT_STATUS_IS_OK(result), handle,
2004 "%s:%llu-%llu. type=%d.",
2005 fsp_str_do_log(brl_fsp(br_lck)),
2006 (unsigned long long)plock->start,
2007 (unsigned long long)plock->size,
2013 static bool smb_full_audit_brl_unlock_windows(struct vfs_handle_struct *handle,
2014 struct byte_range_lock *br_lck,
2015 const struct lock_struct *plock)
2019 result = SMB_VFS_NEXT_BRL_UNLOCK_WINDOWS(handle, br_lck, plock);
2021 do_log(SMB_VFS_OP_BRL_UNLOCK_WINDOWS, (result == 0), handle,
2022 "%s:%llu-%llu:%d", fsp_str_do_log(brl_fsp(br_lck)),
2023 (unsigned long long)plock->start,
2024 (unsigned long long)plock->size,
2030 static bool smb_full_audit_strict_lock_check(struct vfs_handle_struct *handle,
2031 struct files_struct *fsp,
2032 struct lock_struct *plock)
2036 result = SMB_VFS_NEXT_STRICT_LOCK_CHECK(handle, fsp, plock);
2038 do_log(SMB_VFS_OP_STRICT_LOCK_CHECK, result, handle,
2039 "%s:%llu-%llu:%d", fsp_str_do_log(fsp),
2040 (unsigned long long)plock->start,
2041 (unsigned long long)plock->size,
2047 static NTSTATUS smb_full_audit_translate_name(struct vfs_handle_struct *handle,
2049 enum vfs_translate_direction direction,
2050 TALLOC_CTX *mem_ctx,
2055 result = SMB_VFS_NEXT_TRANSLATE_NAME(handle, name, direction, mem_ctx,
2058 do_log(SMB_VFS_OP_TRANSLATE_NAME, NT_STATUS_IS_OK(result), handle, "");
2063 static NTSTATUS smb_full_audit_fsctl(struct vfs_handle_struct *handle,
2064 struct files_struct *fsp,
2068 const uint8_t *_in_data,
2070 uint8_t **_out_data,
2071 uint32_t max_out_len,
2076 result = SMB_VFS_NEXT_FSCTL(handle,
2087 do_log(SMB_VFS_OP_FSCTL, NT_STATUS_IS_OK(result), handle, "");
2092 static struct tevent_req *smb_full_audit_offload_read_send(
2093 TALLOC_CTX *mem_ctx,
2094 struct tevent_context *ev,
2095 struct vfs_handle_struct *handle,
2096 struct files_struct *fsp,
2102 struct tevent_req *req = NULL;
2104 req = SMB_VFS_NEXT_OFFLOAD_READ_SEND(mem_ctx, ev, handle, fsp,
2105 fsctl, ttl, offset, to_copy);
2107 do_log(SMB_VFS_OP_OFFLOAD_READ_SEND, req, handle, "");
2112 static NTSTATUS smb_full_audit_offload_read_recv(
2113 struct tevent_req *req,
2114 struct vfs_handle_struct *handle,
2115 TALLOC_CTX *mem_ctx,
2116 DATA_BLOB *_token_blob)
2120 status = SMB_VFS_NEXT_OFFLOAD_READ_RECV(req, handle, mem_ctx,
2123 do_log(SMB_VFS_OP_OFFLOAD_READ_RECV, NT_STATUS_IS_OK(status), handle, "");
2128 static struct tevent_req *smb_full_audit_offload_write_send(struct vfs_handle_struct *handle,
2129 TALLOC_CTX *mem_ctx,
2130 struct tevent_context *ev,
2133 off_t transfer_offset,
2134 struct files_struct *dest_fsp,
2138 struct tevent_req *req;
2140 req = SMB_VFS_NEXT_OFFLOAD_WRITE_SEND(handle, mem_ctx, ev,
2141 fsctl, token, transfer_offset,
2142 dest_fsp, dest_off, num);
2144 do_log(SMB_VFS_OP_OFFLOAD_WRITE_SEND, req, handle, "");
2149 static NTSTATUS smb_full_audit_offload_write_recv(struct vfs_handle_struct *handle,
2150 struct tevent_req *req,
2155 result = SMB_VFS_NEXT_OFFLOAD_WRITE_RECV(handle, req, copied);
2157 do_log(SMB_VFS_OP_OFFLOAD_WRITE_RECV, NT_STATUS_IS_OK(result), handle, "");
2162 static NTSTATUS smb_full_audit_get_compression(vfs_handle_struct *handle,
2163 TALLOC_CTX *mem_ctx,
2164 struct files_struct *fsp,
2165 struct smb_filename *smb_fname,
2166 uint16_t *_compression_fmt)
2170 result = SMB_VFS_NEXT_GET_COMPRESSION(handle, mem_ctx, fsp, smb_fname,
2173 do_log(SMB_VFS_OP_GET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
2175 (fsp ? fsp_str_do_log(fsp) :
2176 smb_fname_str_do_log(handle->conn, smb_fname)));
2181 static NTSTATUS smb_full_audit_set_compression(vfs_handle_struct *handle,
2182 TALLOC_CTX *mem_ctx,
2183 struct files_struct *fsp,
2184 uint16_t compression_fmt)
2188 result = SMB_VFS_NEXT_SET_COMPRESSION(handle, mem_ctx, fsp,
2191 do_log(SMB_VFS_OP_SET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
2192 "%s", fsp_str_do_log(fsp));
2197 static NTSTATUS smb_full_audit_readdir_attr(struct vfs_handle_struct *handle,
2198 const struct smb_filename *fname,
2199 TALLOC_CTX *mem_ctx,
2200 struct readdir_attr_data **pattr_data)
2204 status = SMB_VFS_NEXT_READDIR_ATTR(handle, fname, mem_ctx, pattr_data);
2206 do_log(SMB_VFS_OP_READDIR_ATTR, NT_STATUS_IS_OK(status), handle, "%s",
2207 smb_fname_str_do_log(handle->conn, fname));
2212 static NTSTATUS smb_full_audit_get_dos_attributes(
2213 struct vfs_handle_struct *handle,
2214 struct smb_filename *smb_fname,
2219 status = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES(handle,
2223 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES,
2224 NT_STATUS_IS_OK(status),
2227 smb_fname_str_do_log(handle->conn, smb_fname));
2232 struct smb_full_audit_get_dos_attributes_state {
2233 struct vfs_aio_state aio_state;
2234 vfs_handle_struct *handle;
2235 files_struct *dir_fsp;
2236 const struct smb_filename *smb_fname;
2240 static void smb_full_audit_get_dos_attributes_done(struct tevent_req *subreq);
2242 static struct tevent_req *smb_full_audit_get_dos_attributes_send(
2243 TALLOC_CTX *mem_ctx,
2244 struct tevent_context *ev,
2245 struct vfs_handle_struct *handle,
2246 files_struct *dir_fsp,
2247 struct smb_filename *smb_fname)
2249 struct tevent_req *req = NULL;
2250 struct smb_full_audit_get_dos_attributes_state *state = NULL;
2251 struct tevent_req *subreq = NULL;
2253 req = tevent_req_create(mem_ctx, &state,
2254 struct smb_full_audit_get_dos_attributes_state);
2256 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2260 fsp_str_do_log(dir_fsp),
2261 smb_fname->base_name);
2264 *state = (struct smb_full_audit_get_dos_attributes_state) {
2267 .smb_fname = smb_fname,
2270 subreq = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES_SEND(mem_ctx,
2275 if (tevent_req_nomem(subreq, req)) {
2276 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2280 fsp_str_do_log(dir_fsp),
2281 smb_fname->base_name);
2282 return tevent_req_post(req, ev);
2284 tevent_req_set_callback(subreq,
2285 smb_full_audit_get_dos_attributes_done,
2288 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2292 fsp_str_do_log(dir_fsp),
2293 smb_fname->base_name);
2298 static void smb_full_audit_get_dos_attributes_done(struct tevent_req *subreq)
2300 struct tevent_req *req =
2301 tevent_req_callback_data(subreq,
2303 struct smb_full_audit_get_dos_attributes_state *state =
2304 tevent_req_data(req,
2305 struct smb_full_audit_get_dos_attributes_state);
2308 status = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES_RECV(subreq,
2311 TALLOC_FREE(subreq);
2312 if (tevent_req_nterror(req, status)) {
2316 tevent_req_done(req);
2320 static NTSTATUS smb_full_audit_get_dos_attributes_recv(struct tevent_req *req,
2321 struct vfs_aio_state *aio_state,
2324 struct smb_full_audit_get_dos_attributes_state *state =
2325 tevent_req_data(req,
2326 struct smb_full_audit_get_dos_attributes_state);
2329 if (tevent_req_is_nterror(req, &status)) {
2330 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV,
2334 fsp_str_do_log(state->dir_fsp),
2335 state->smb_fname->base_name);
2336 tevent_req_received(req);
2340 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV,
2344 fsp_str_do_log(state->dir_fsp),
2345 state->smb_fname->base_name);
2347 *aio_state = state->aio_state;
2348 *dosmode = state->dosmode;
2349 tevent_req_received(req);
2350 return NT_STATUS_OK;
2353 static NTSTATUS smb_full_audit_fget_dos_attributes(
2354 struct vfs_handle_struct *handle,
2355 struct files_struct *fsp,
2360 status = SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle,
2364 do_log(SMB_VFS_OP_FGET_DOS_ATTRIBUTES,
2365 NT_STATUS_IS_OK(status),
2368 fsp_str_do_log(fsp));
2373 static NTSTATUS smb_full_audit_set_dos_attributes(
2374 struct vfs_handle_struct *handle,
2375 const struct smb_filename *smb_fname,
2380 status = SMB_VFS_NEXT_SET_DOS_ATTRIBUTES(handle,
2384 do_log(SMB_VFS_OP_SET_DOS_ATTRIBUTES,
2385 NT_STATUS_IS_OK(status),
2388 smb_fname_str_do_log(handle->conn, smb_fname));
2393 static NTSTATUS smb_full_audit_fset_dos_attributes(
2394 struct vfs_handle_struct *handle,
2395 struct files_struct *fsp,
2400 status = SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle,
2404 do_log(SMB_VFS_OP_FSET_DOS_ATTRIBUTES,
2405 NT_STATUS_IS_OK(status),
2408 fsp_str_do_log(fsp));
2413 static NTSTATUS smb_full_audit_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
2414 uint32_t security_info,
2415 TALLOC_CTX *mem_ctx,
2416 struct security_descriptor **ppdesc)
2420 result = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
2423 do_log(SMB_VFS_OP_FGET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2424 "%s", fsp_str_do_log(fsp));
2429 static NTSTATUS smb_full_audit_get_nt_acl(vfs_handle_struct *handle,
2430 const struct smb_filename *smb_fname,
2431 uint32_t security_info,
2432 TALLOC_CTX *mem_ctx,
2433 struct security_descriptor **ppdesc)
2437 result = SMB_VFS_NEXT_GET_NT_ACL(handle, smb_fname, security_info,
2440 do_log(SMB_VFS_OP_GET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2441 "%s", smb_fname_str_do_log(handle->conn, smb_fname));
2446 static NTSTATUS smb_full_audit_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
2447 uint32_t security_info_sent,
2448 const struct security_descriptor *psd)
2450 struct vfs_full_audit_private_data *pd;
2454 SMB_VFS_HANDLE_GET_DATA(handle, pd,
2455 struct vfs_full_audit_private_data,
2456 return NT_STATUS_INTERNAL_ERROR);
2458 if (pd->log_secdesc) {
2459 sd = sddl_encode(talloc_tos(), psd, get_global_sam_sid());
2462 result = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
2464 do_log(SMB_VFS_OP_FSET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2465 "%s [%s]", fsp_str_do_log(fsp), sd ? sd : "");
2472 static NTSTATUS smb_full_audit_audit_file(struct vfs_handle_struct *handle,
2473 struct smb_filename *file,
2474 struct security_acl *sacl,
2475 uint32_t access_requested,
2476 uint32_t access_denied)
2480 result = SMB_VFS_NEXT_AUDIT_FILE(handle,
2486 do_log(SMB_VFS_OP_AUDIT_FILE, NT_STATUS_IS_OK(result), handle,
2488 smb_fname_str_do_log(handle->conn, file));
2493 static SMB_ACL_T smb_full_audit_sys_acl_get_file(vfs_handle_struct *handle,
2494 const struct smb_filename *smb_fname,
2495 SMB_ACL_TYPE_T type,
2496 TALLOC_CTX *mem_ctx)
2500 result = SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, smb_fname,
2503 do_log(SMB_VFS_OP_SYS_ACL_GET_FILE,
2507 smb_fname_str_do_log(handle->conn, smb_fname));
2512 static SMB_ACL_T smb_full_audit_sys_acl_get_fd(vfs_handle_struct *handle,
2513 files_struct *fsp, TALLOC_CTX *mem_ctx)
2517 result = SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp, mem_ctx);
2519 do_log(SMB_VFS_OP_SYS_ACL_GET_FD, (result != NULL), handle,
2520 "%s", fsp_str_do_log(fsp));
2525 static int smb_full_audit_sys_acl_blob_get_file(vfs_handle_struct *handle,
2526 const struct smb_filename *smb_fname,
2527 TALLOC_CTX *mem_ctx,
2528 char **blob_description,
2533 result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FILE(handle, smb_fname,
2534 mem_ctx, blob_description, blob);
2536 do_log(SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE,
2540 smb_fname_str_do_log(handle->conn, smb_fname));
2545 static int smb_full_audit_sys_acl_blob_get_fd(vfs_handle_struct *handle,
2547 TALLOC_CTX *mem_ctx,
2548 char **blob_description,
2553 result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle, fsp, mem_ctx, blob_description, blob);
2555 do_log(SMB_VFS_OP_SYS_ACL_BLOB_GET_FD, (result >= 0), handle,
2556 "%s", fsp_str_do_log(fsp));
2561 static int smb_full_audit_sys_acl_set_file(vfs_handle_struct *handle,
2562 const struct smb_filename *smb_fname,
2563 SMB_ACL_TYPE_T acltype,
2568 result = SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, smb_fname, acltype,
2571 do_log(SMB_VFS_OP_SYS_ACL_SET_FILE,
2575 smb_fname_str_do_log(handle->conn, smb_fname));
2580 static int smb_full_audit_sys_acl_set_fd(vfs_handle_struct *handle, files_struct *fsp,
2585 result = SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, theacl);
2587 do_log(SMB_VFS_OP_SYS_ACL_SET_FD, (result >= 0), handle,
2588 "%s", fsp_str_do_log(fsp));
2593 static int smb_full_audit_sys_acl_delete_def_file(vfs_handle_struct *handle,
2594 const struct smb_filename *smb_fname)
2598 result = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, smb_fname);
2600 do_log(SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE,
2604 smb_fname_str_do_log(handle->conn, smb_fname));
2609 static ssize_t smb_full_audit_getxattr(struct vfs_handle_struct *handle,
2610 const struct smb_filename *smb_fname,
2611 const char *name, void *value, size_t size)
2615 result = SMB_VFS_NEXT_GETXATTR(handle, smb_fname, name, value, size);
2617 do_log(SMB_VFS_OP_GETXATTR,
2621 smb_fname_str_do_log(handle->conn, smb_fname),
2627 struct smb_full_audit_getxattrat_state {
2628 struct vfs_aio_state aio_state;
2629 vfs_handle_struct *handle;
2630 files_struct *dir_fsp;
2631 const struct smb_filename *smb_fname;
2632 const char *xattr_name;
2634 uint8_t *xattr_value;
2637 static void smb_full_audit_getxattrat_done(struct tevent_req *subreq);
2639 static struct tevent_req *smb_full_audit_getxattrat_send(
2640 TALLOC_CTX *mem_ctx,
2641 struct tevent_context *ev,
2642 struct vfs_handle_struct *handle,
2643 files_struct *dir_fsp,
2644 const struct smb_filename *smb_fname,
2645 const char *xattr_name,
2648 struct tevent_req *req = NULL;
2649 struct tevent_req *subreq = NULL;
2650 struct smb_full_audit_getxattrat_state *state = NULL;
2652 req = tevent_req_create(mem_ctx, &state,
2653 struct smb_full_audit_getxattrat_state);
2655 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2659 fsp_str_do_log(dir_fsp),
2660 smb_fname->base_name,
2664 *state = (struct smb_full_audit_getxattrat_state) {
2667 .smb_fname = smb_fname,
2668 .xattr_name = xattr_name,
2671 subreq = SMB_VFS_NEXT_GETXATTRAT_SEND(state,
2678 if (tevent_req_nomem(subreq, req)) {
2679 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2683 fsp_str_do_log(dir_fsp),
2684 smb_fname->base_name,
2686 return tevent_req_post(req, ev);
2688 tevent_req_set_callback(subreq, smb_full_audit_getxattrat_done, req);
2690 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2694 fsp_str_do_log(dir_fsp),
2695 smb_fname->base_name,
2701 static void smb_full_audit_getxattrat_done(struct tevent_req *subreq)
2703 struct tevent_req *req = tevent_req_callback_data(
2704 subreq, struct tevent_req);
2705 struct smb_full_audit_getxattrat_state *state = tevent_req_data(
2706 req, struct smb_full_audit_getxattrat_state);
2708 state->xattr_size = SMB_VFS_NEXT_GETXATTRAT_RECV(subreq,
2711 &state->xattr_value);
2712 TALLOC_FREE(subreq);
2713 if (state->xattr_size == -1) {
2714 tevent_req_error(req, state->aio_state.error);
2718 tevent_req_done(req);
2721 static ssize_t smb_full_audit_getxattrat_recv(struct tevent_req *req,
2722 struct vfs_aio_state *aio_state,
2723 TALLOC_CTX *mem_ctx,
2724 uint8_t **xattr_value)
2726 struct smb_full_audit_getxattrat_state *state = tevent_req_data(
2727 req, struct smb_full_audit_getxattrat_state);
2730 if (tevent_req_is_unix_error(req, &aio_state->error)) {
2731 do_log(SMB_VFS_OP_GETXATTRAT_RECV,
2735 fsp_str_do_log(state->dir_fsp),
2736 state->smb_fname->base_name,
2738 tevent_req_received(req);
2742 do_log(SMB_VFS_OP_GETXATTRAT_RECV,
2746 fsp_str_do_log(state->dir_fsp),
2747 state->smb_fname->base_name,
2750 *aio_state = state->aio_state;
2751 xattr_size = state->xattr_size;
2752 if (xattr_value != NULL) {
2753 *xattr_value = talloc_move(mem_ctx, &state->xattr_value);
2756 tevent_req_received(req);
2760 static ssize_t smb_full_audit_fgetxattr(struct vfs_handle_struct *handle,
2761 struct files_struct *fsp,
2762 const char *name, void *value, size_t size)
2766 result = SMB_VFS_NEXT_FGETXATTR(handle, fsp, name, value, size);
2768 do_log(SMB_VFS_OP_FGETXATTR, (result >= 0), handle,
2769 "%s|%s", fsp_str_do_log(fsp), name);
2774 static ssize_t smb_full_audit_listxattr(struct vfs_handle_struct *handle,
2775 const struct smb_filename *smb_fname,
2781 result = SMB_VFS_NEXT_LISTXATTR(handle, smb_fname, list, size);
2783 do_log(SMB_VFS_OP_LISTXATTR,
2787 smb_fname_str_do_log(handle->conn, smb_fname));
2792 static ssize_t smb_full_audit_flistxattr(struct vfs_handle_struct *handle,
2793 struct files_struct *fsp, char *list,
2798 result = SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
2800 do_log(SMB_VFS_OP_FLISTXATTR, (result >= 0), handle,
2801 "%s", fsp_str_do_log(fsp));
2806 static int smb_full_audit_removexattr(struct vfs_handle_struct *handle,
2807 const struct smb_filename *smb_fname,
2812 result = SMB_VFS_NEXT_REMOVEXATTR(handle, smb_fname, name);
2814 do_log(SMB_VFS_OP_REMOVEXATTR,
2818 smb_fname_str_do_log(handle->conn, smb_fname),
2824 static int smb_full_audit_fremovexattr(struct vfs_handle_struct *handle,
2825 struct files_struct *fsp,
2830 result = SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, name);
2832 do_log(SMB_VFS_OP_FREMOVEXATTR, (result >= 0), handle,
2833 "%s|%s", fsp_str_do_log(fsp), name);
2838 static int smb_full_audit_setxattr(struct vfs_handle_struct *handle,
2839 const struct smb_filename *smb_fname,
2840 const char *name, const void *value, size_t size,
2845 result = SMB_VFS_NEXT_SETXATTR(handle, smb_fname, name, value, size,
2848 do_log(SMB_VFS_OP_SETXATTR,
2852 smb_fname_str_do_log(handle->conn, smb_fname),
2858 static int smb_full_audit_fsetxattr(struct vfs_handle_struct *handle,
2859 struct files_struct *fsp, const char *name,
2860 const void *value, size_t size, int flags)
2864 result = SMB_VFS_NEXT_FSETXATTR(handle, fsp, name, value, size, flags);
2866 do_log(SMB_VFS_OP_FSETXATTR, (result >= 0), handle,
2867 "%s|%s", fsp_str_do_log(fsp), name);
2872 static bool smb_full_audit_aio_force(struct vfs_handle_struct *handle,
2873 struct files_struct *fsp)
2877 result = SMB_VFS_NEXT_AIO_FORCE(handle, fsp);
2878 do_log(SMB_VFS_OP_AIO_FORCE, result, handle,
2879 "%s", fsp_str_do_log(fsp));
2884 static NTSTATUS smb_full_audit_durable_cookie(struct vfs_handle_struct *handle,
2885 struct files_struct *fsp,
2886 TALLOC_CTX *mem_ctx,
2891 result = SMB_VFS_NEXT_DURABLE_COOKIE(handle,
2896 do_log(SMB_VFS_OP_DURABLE_COOKIE, NT_STATUS_IS_OK(result), handle,
2897 "%s", fsp_str_do_log(fsp));
2902 static NTSTATUS smb_full_audit_durable_disconnect(
2903 struct vfs_handle_struct *handle,
2904 struct files_struct *fsp,
2905 const DATA_BLOB old_cookie,
2906 TALLOC_CTX *mem_ctx,
2907 DATA_BLOB *new_cookie)
2911 result = SMB_VFS_NEXT_DURABLE_DISCONNECT(handle,
2917 do_log(SMB_VFS_OP_DURABLE_DISCONNECT, NT_STATUS_IS_OK(result), handle,
2918 "%s", fsp_str_do_log(fsp));
2923 static NTSTATUS smb_full_audit_durable_reconnect(
2924 struct vfs_handle_struct *handle,
2925 struct smb_request *smb1req,
2926 struct smbXsrv_open *op,
2927 const DATA_BLOB old_cookie,
2928 TALLOC_CTX *mem_ctx,
2929 struct files_struct **fsp,
2930 DATA_BLOB *new_cookie)
2934 result = SMB_VFS_NEXT_DURABLE_RECONNECT(handle,
2942 do_log(SMB_VFS_OP_DURABLE_RECONNECT,
2943 NT_STATUS_IS_OK(result),
2950 static struct vfs_fn_pointers vfs_full_audit_fns = {
2952 /* Disk operations */
2954 .connect_fn = smb_full_audit_connect,
2955 .disconnect_fn = smb_full_audit_disconnect,
2956 .disk_free_fn = smb_full_audit_disk_free,
2957 .get_quota_fn = smb_full_audit_get_quota,
2958 .set_quota_fn = smb_full_audit_set_quota,
2959 .get_shadow_copy_data_fn = smb_full_audit_get_shadow_copy_data,
2960 .statvfs_fn = smb_full_audit_statvfs,
2961 .fs_capabilities_fn = smb_full_audit_fs_capabilities,
2962 .get_dfs_referrals_fn = smb_full_audit_get_dfs_referrals,
2963 .create_dfs_pathat_fn = smb_full_audit_create_dfs_pathat,
2964 .opendir_fn = smb_full_audit_opendir,
2965 .fdopendir_fn = smb_full_audit_fdopendir,
2966 .readdir_fn = smb_full_audit_readdir,
2967 .seekdir_fn = smb_full_audit_seekdir,
2968 .telldir_fn = smb_full_audit_telldir,
2969 .rewind_dir_fn = smb_full_audit_rewinddir,
2970 .mkdirat_fn = smb_full_audit_mkdirat,
2971 .closedir_fn = smb_full_audit_closedir,
2972 .open_fn = smb_full_audit_open,
2973 .create_file_fn = smb_full_audit_create_file,
2974 .close_fn = smb_full_audit_close,
2975 .pread_fn = smb_full_audit_pread,
2976 .pread_send_fn = smb_full_audit_pread_send,
2977 .pread_recv_fn = smb_full_audit_pread_recv,
2978 .pwrite_fn = smb_full_audit_pwrite,
2979 .pwrite_send_fn = smb_full_audit_pwrite_send,
2980 .pwrite_recv_fn = smb_full_audit_pwrite_recv,
2981 .lseek_fn = smb_full_audit_lseek,
2982 .sendfile_fn = smb_full_audit_sendfile,
2983 .recvfile_fn = smb_full_audit_recvfile,
2984 .renameat_fn = smb_full_audit_renameat,
2985 .fsync_send_fn = smb_full_audit_fsync_send,
2986 .fsync_recv_fn = smb_full_audit_fsync_recv,
2987 .stat_fn = smb_full_audit_stat,
2988 .fstat_fn = smb_full_audit_fstat,
2989 .lstat_fn = smb_full_audit_lstat,
2990 .get_alloc_size_fn = smb_full_audit_get_alloc_size,
2991 .unlinkat_fn = smb_full_audit_unlinkat,
2992 .chmod_fn = smb_full_audit_chmod,
2993 .fchmod_fn = smb_full_audit_fchmod,
2994 .fchown_fn = smb_full_audit_fchown,
2995 .lchown_fn = smb_full_audit_lchown,
2996 .chdir_fn = smb_full_audit_chdir,
2997 .getwd_fn = smb_full_audit_getwd,
2998 .ntimes_fn = smb_full_audit_ntimes,
2999 .ftruncate_fn = smb_full_audit_ftruncate,
3000 .fallocate_fn = smb_full_audit_fallocate,
3001 .lock_fn = smb_full_audit_lock,
3002 .kernel_flock_fn = smb_full_audit_kernel_flock,
3003 .fcntl_fn = smb_full_audit_fcntl,
3004 .linux_setlease_fn = smb_full_audit_linux_setlease,
3005 .getlock_fn = smb_full_audit_getlock,
3006 .symlinkat_fn = smb_full_audit_symlinkat,
3007 .readlinkat_fn = smb_full_audit_readlinkat,
3008 .linkat_fn = smb_full_audit_linkat,
3009 .mknodat_fn = smb_full_audit_mknodat,
3010 .realpath_fn = smb_full_audit_realpath,
3011 .chflags_fn = smb_full_audit_chflags,
3012 .file_id_create_fn = smb_full_audit_file_id_create,
3013 .fs_file_id_fn = smb_full_audit_fs_file_id,
3014 .offload_read_send_fn = smb_full_audit_offload_read_send,
3015 .offload_read_recv_fn = smb_full_audit_offload_read_recv,
3016 .offload_write_send_fn = smb_full_audit_offload_write_send,
3017 .offload_write_recv_fn = smb_full_audit_offload_write_recv,
3018 .get_compression_fn = smb_full_audit_get_compression,
3019 .set_compression_fn = smb_full_audit_set_compression,
3020 .snap_check_path_fn = smb_full_audit_snap_check_path,
3021 .snap_create_fn = smb_full_audit_snap_create,
3022 .snap_delete_fn = smb_full_audit_snap_delete,
3023 .streaminfo_fn = smb_full_audit_streaminfo,
3024 .get_real_filename_fn = smb_full_audit_get_real_filename,
3025 .connectpath_fn = smb_full_audit_connectpath,
3026 .brl_lock_windows_fn = smb_full_audit_brl_lock_windows,
3027 .brl_unlock_windows_fn = smb_full_audit_brl_unlock_windows,
3028 .strict_lock_check_fn = smb_full_audit_strict_lock_check,
3029 .translate_name_fn = smb_full_audit_translate_name,
3030 .fsctl_fn = smb_full_audit_fsctl,
3031 .get_dos_attributes_fn = smb_full_audit_get_dos_attributes,
3032 .get_dos_attributes_send_fn = smb_full_audit_get_dos_attributes_send,
3033 .get_dos_attributes_recv_fn = smb_full_audit_get_dos_attributes_recv,
3034 .fget_dos_attributes_fn = smb_full_audit_fget_dos_attributes,
3035 .set_dos_attributes_fn = smb_full_audit_set_dos_attributes,
3036 .fset_dos_attributes_fn = smb_full_audit_fset_dos_attributes,
3037 .fget_nt_acl_fn = smb_full_audit_fget_nt_acl,
3038 .get_nt_acl_fn = smb_full_audit_get_nt_acl,
3039 .fset_nt_acl_fn = smb_full_audit_fset_nt_acl,
3040 .audit_file_fn = smb_full_audit_audit_file,
3041 .sys_acl_get_file_fn = smb_full_audit_sys_acl_get_file,
3042 .sys_acl_get_fd_fn = smb_full_audit_sys_acl_get_fd,
3043 .sys_acl_blob_get_file_fn = smb_full_audit_sys_acl_blob_get_file,
3044 .sys_acl_blob_get_fd_fn = smb_full_audit_sys_acl_blob_get_fd,
3045 .sys_acl_set_file_fn = smb_full_audit_sys_acl_set_file,
3046 .sys_acl_set_fd_fn = smb_full_audit_sys_acl_set_fd,
3047 .sys_acl_delete_def_file_fn = smb_full_audit_sys_acl_delete_def_file,
3048 .getxattr_fn = smb_full_audit_getxattr,
3049 .getxattrat_send_fn = smb_full_audit_getxattrat_send,
3050 .getxattrat_recv_fn = smb_full_audit_getxattrat_recv,
3051 .fgetxattr_fn = smb_full_audit_fgetxattr,
3052 .listxattr_fn = smb_full_audit_listxattr,
3053 .flistxattr_fn = smb_full_audit_flistxattr,
3054 .removexattr_fn = smb_full_audit_removexattr,
3055 .fremovexattr_fn = smb_full_audit_fremovexattr,
3056 .setxattr_fn = smb_full_audit_setxattr,
3057 .fsetxattr_fn = smb_full_audit_fsetxattr,
3058 .aio_force_fn = smb_full_audit_aio_force,
3059 .durable_cookie_fn = smb_full_audit_durable_cookie,
3060 .durable_disconnect_fn = smb_full_audit_durable_disconnect,
3061 .durable_reconnect_fn = smb_full_audit_durable_reconnect,
3062 .readdir_attr_fn = smb_full_audit_readdir_attr
3067 NTSTATUS vfs_full_audit_init(TALLOC_CTX *ctx)
3071 smb_vfs_assert_all_fns(&vfs_full_audit_fns, "full_audit");
3073 ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "full_audit",
3074 &vfs_full_audit_fns);
3076 if (!NT_STATUS_IS_OK(ret))
3079 vfs_full_audit_debug_level = debug_add_class("full_audit");
3080 if (vfs_full_audit_debug_level == -1) {
3081 vfs_full_audit_debug_level = DBGC_VFS;
3082 DEBUG(0, ("vfs_full_audit: Couldn't register custom debugging "
3085 DEBUG(10, ("vfs_full_audit: Debug class number of "
3086 "'full_audit': %d\n", vfs_full_audit_debug_level));