2 * Auditing VFS module for samba. Log selected file operations to syslog
5 * Copyright (C) Tim Potter, 1999-2000
6 * Copyright (C) Alexander Bokovoy, 2002
7 * Copyright (C) John H Terpstra, 2003
8 * Copyright (C) Stefan (metze) Metzmacher, 2003
9 * Copyright (C) Volker Lendecke, 2004
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, see <http://www.gnu.org/licenses/>.
26 * This module implements parseable logging for all Samba VFS operations.
28 * You use it as follows:
32 * vfs objects = full_audit
33 * full_audit:prefix = %u|%I
34 * full_audit:success = open opendir create_file
35 * full_audit:failure = all
37 * vfs op can be "all" which means log all operations.
38 * vfs op can be "none" which means no logging.
40 * This leads to syslog entries of the form:
41 * smbd_audit: nobody|192.168.234.1|opendir|ok|/tmp
42 * smbd_audit: nobody|192.168.234.1|create_file|fail (No such file or directory)|0x1|file|open|/ts/doesNotExist
43 * smbd_audit: nobody|192.168.234.1|open|ok|w|/tmp/file.txt
44 * smbd_audit: nobody|192.168.234.1|create_file|ok|0x3|file|open|/tmp/file.txt
46 * where "nobody" is the connected username and "192.168.234.1" is the
47 * client's IP address.
51 * prefix: A macro expansion template prepended to the syslog entry.
53 * success: A list of VFS operations for which a successful completion should
54 * be logged. Defaults to no logging at all. The special operation "all" logs
55 * - you guessed it - everything.
57 * failure: A list of VFS operations for which failure to complete should be
58 * logged. Defaults to logging everything.
63 #include "system/filesys.h"
64 #include "system/syslog.h"
65 #include "smbd/smbd.h"
66 #include "../librpc/gen_ndr/ndr_netlogon.h"
69 #include "lib/param/loadparm.h"
70 #include "lib/util/bitmap.h"
71 #include "lib/util/tevent_unix.h"
72 #include "libcli/security/sddl.h"
73 #include "passdb/machine_sid.h"
74 #include "lib/util/tevent_ntstatus.h"
75 #include "lib/util/string_wrappers.h"
77 static int vfs_full_audit_debug_level = DBGC_VFS;
79 struct vfs_full_audit_private_data {
80 struct bitmap *success_ops;
81 struct bitmap *failure_ops;
89 #define DBGC_CLASS vfs_full_audit_debug_level
91 typedef enum _vfs_op_type {
96 SMB_VFS_OP_CONNECT = 0,
97 SMB_VFS_OP_DISCONNECT,
100 SMB_VFS_OP_SET_QUOTA,
101 SMB_VFS_OP_GET_SHADOW_COPY_DATA,
103 SMB_VFS_OP_FS_CAPABILITIES,
104 SMB_VFS_OP_GET_DFS_REFERRALS,
105 SMB_VFS_OP_CREATE_DFS_PATHAT,
106 SMB_VFS_OP_READ_DFS_PATHAT,
108 /* Directory operations */
110 SMB_VFS_OP_FDOPENDIR,
114 SMB_VFS_OP_REWINDDIR,
118 /* File operations */
122 SMB_VFS_OP_CREATE_FILE,
126 SMB_VFS_OP_PREAD_SEND,
127 SMB_VFS_OP_PREAD_RECV,
130 SMB_VFS_OP_PWRITE_SEND,
131 SMB_VFS_OP_PWRITE_RECV,
137 SMB_VFS_OP_FSYNC_SEND,
138 SMB_VFS_OP_FSYNC_RECV,
142 SMB_VFS_OP_GET_ALLOC_SIZE,
151 SMB_VFS_OP_FTRUNCATE,
152 SMB_VFS_OP_FALLOCATE,
154 SMB_VFS_OP_KERNEL_FLOCK,
156 SMB_VFS_OP_LINUX_SETLEASE,
158 SMB_VFS_OP_SYMLINKAT,
159 SMB_VFS_OP_READLINKAT,
164 SMB_VFS_OP_FILE_ID_CREATE,
165 SMB_VFS_OP_FS_FILE_ID,
166 SMB_VFS_OP_STREAMINFO,
167 SMB_VFS_OP_GET_REAL_FILENAME,
168 SMB_VFS_OP_CONNECTPATH,
169 SMB_VFS_OP_BRL_LOCK_WINDOWS,
170 SMB_VFS_OP_BRL_UNLOCK_WINDOWS,
171 SMB_VFS_OP_STRICT_LOCK_CHECK,
172 SMB_VFS_OP_TRANSLATE_NAME,
174 SMB_VFS_OP_OFFLOAD_READ_SEND,
175 SMB_VFS_OP_OFFLOAD_READ_RECV,
176 SMB_VFS_OP_OFFLOAD_WRITE_SEND,
177 SMB_VFS_OP_OFFLOAD_WRITE_RECV,
178 SMB_VFS_OP_FGET_COMPRESSION,
179 SMB_VFS_OP_SET_COMPRESSION,
180 SMB_VFS_OP_SNAP_CHECK_PATH,
181 SMB_VFS_OP_SNAP_CREATE,
182 SMB_VFS_OP_SNAP_DELETE,
184 /* DOS attribute operations. */
185 SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
186 SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV,
187 SMB_VFS_OP_FGET_DOS_ATTRIBUTES,
188 SMB_VFS_OP_SET_DOS_ATTRIBUTES,
189 SMB_VFS_OP_FSET_DOS_ATTRIBUTES,
191 /* NT ACL operations. */
193 SMB_VFS_OP_FGET_NT_ACL,
194 SMB_VFS_OP_GET_NT_ACL_AT,
195 SMB_VFS_OP_FSET_NT_ACL,
196 SMB_VFS_OP_AUDIT_FILE,
198 /* POSIX ACL operations. */
200 SMB_VFS_OP_SYS_ACL_GET_FILE,
201 SMB_VFS_OP_SYS_ACL_GET_FD,
202 SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE,
203 SMB_VFS_OP_SYS_ACL_BLOB_GET_FD,
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_OPENAT, "openat" },
264 { SMB_VFS_OP_CREATE_FILE, "create_file" },
265 { SMB_VFS_OP_CLOSE, "close" },
266 { SMB_VFS_OP_READ, "read" },
267 { SMB_VFS_OP_PREAD, "pread" },
268 { SMB_VFS_OP_PREAD_SEND, "pread_send" },
269 { SMB_VFS_OP_PREAD_RECV, "pread_recv" },
270 { SMB_VFS_OP_WRITE, "write" },
271 { SMB_VFS_OP_PWRITE, "pwrite" },
272 { SMB_VFS_OP_PWRITE_SEND, "pwrite_send" },
273 { SMB_VFS_OP_PWRITE_RECV, "pwrite_recv" },
274 { SMB_VFS_OP_LSEEK, "lseek" },
275 { SMB_VFS_OP_SENDFILE, "sendfile" },
276 { SMB_VFS_OP_RECVFILE, "recvfile" },
277 { SMB_VFS_OP_RENAMEAT, "renameat" },
278 { SMB_VFS_OP_FSYNC, "fsync" },
279 { SMB_VFS_OP_FSYNC_SEND, "fsync_send" },
280 { SMB_VFS_OP_FSYNC_RECV, "fsync_recv" },
281 { SMB_VFS_OP_STAT, "stat" },
282 { SMB_VFS_OP_FSTAT, "fstat" },
283 { SMB_VFS_OP_LSTAT, "lstat" },
284 { SMB_VFS_OP_GET_ALLOC_SIZE, "get_alloc_size" },
285 { SMB_VFS_OP_UNLINKAT, "unlinkat" },
286 { SMB_VFS_OP_CHMOD, "chmod" },
287 { SMB_VFS_OP_FCHMOD, "fchmod" },
288 { SMB_VFS_OP_FCHOWN, "fchown" },
289 { SMB_VFS_OP_LCHOWN, "lchown" },
290 { SMB_VFS_OP_CHDIR, "chdir" },
291 { SMB_VFS_OP_GETWD, "getwd" },
292 { SMB_VFS_OP_NTIMES, "ntimes" },
293 { SMB_VFS_OP_FTRUNCATE, "ftruncate" },
294 { SMB_VFS_OP_FALLOCATE,"fallocate" },
295 { SMB_VFS_OP_LOCK, "lock" },
296 { SMB_VFS_OP_KERNEL_FLOCK, "kernel_flock" },
297 { SMB_VFS_OP_FCNTL, "fcntl" },
298 { SMB_VFS_OP_LINUX_SETLEASE, "linux_setlease" },
299 { SMB_VFS_OP_GETLOCK, "getlock" },
300 { SMB_VFS_OP_SYMLINKAT, "symlinkat" },
301 { SMB_VFS_OP_READLINKAT,"readlinkat" },
302 { SMB_VFS_OP_LINKAT, "linkat" },
303 { SMB_VFS_OP_MKNODAT, "mknodat" },
304 { SMB_VFS_OP_REALPATH, "realpath" },
305 { SMB_VFS_OP_CHFLAGS, "chflags" },
306 { SMB_VFS_OP_FILE_ID_CREATE, "file_id_create" },
307 { SMB_VFS_OP_FS_FILE_ID, "fs_file_id" },
308 { SMB_VFS_OP_STREAMINFO, "streaminfo" },
309 { SMB_VFS_OP_GET_REAL_FILENAME, "get_real_filename" },
310 { SMB_VFS_OP_CONNECTPATH, "connectpath" },
311 { SMB_VFS_OP_BRL_LOCK_WINDOWS, "brl_lock_windows" },
312 { SMB_VFS_OP_BRL_UNLOCK_WINDOWS, "brl_unlock_windows" },
313 { SMB_VFS_OP_STRICT_LOCK_CHECK, "strict_lock_check" },
314 { SMB_VFS_OP_TRANSLATE_NAME, "translate_name" },
315 { SMB_VFS_OP_FSCTL, "fsctl" },
316 { SMB_VFS_OP_OFFLOAD_READ_SEND, "offload_read_send" },
317 { SMB_VFS_OP_OFFLOAD_READ_RECV, "offload_read_recv" },
318 { SMB_VFS_OP_OFFLOAD_WRITE_SEND, "offload_write_send" },
319 { SMB_VFS_OP_OFFLOAD_WRITE_RECV, "offload_write_recv" },
320 { SMB_VFS_OP_FGET_COMPRESSION, "fget_compression" },
321 { SMB_VFS_OP_SET_COMPRESSION, "set_compression" },
322 { SMB_VFS_OP_SNAP_CHECK_PATH, "snap_check_path" },
323 { SMB_VFS_OP_SNAP_CREATE, "snap_create" },
324 { SMB_VFS_OP_SNAP_DELETE, "snap_delete" },
325 { SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND, "get_dos_attributes_send" },
326 { SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV, "get_dos_attributes_recv" },
327 { SMB_VFS_OP_FGET_DOS_ATTRIBUTES, "fget_dos_attributes" },
328 { SMB_VFS_OP_SET_DOS_ATTRIBUTES, "set_dos_attributes" },
329 { SMB_VFS_OP_FSET_DOS_ATTRIBUTES, "fset_dos_attributes" },
330 { SMB_VFS_OP_FGET_NT_ACL, "fget_nt_acl" },
331 { SMB_VFS_OP_GET_NT_ACL_AT, "get_nt_acl_at" },
332 { SMB_VFS_OP_FSET_NT_ACL, "fset_nt_acl" },
333 { SMB_VFS_OP_AUDIT_FILE, "audit_file" },
334 { SMB_VFS_OP_SYS_ACL_GET_FILE, "sys_acl_get_file" },
335 { SMB_VFS_OP_SYS_ACL_GET_FD, "sys_acl_get_fd" },
336 { SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE, "sys_acl_blob_get_file" },
337 { SMB_VFS_OP_SYS_ACL_BLOB_GET_FD, "sys_acl_blob_get_fd" },
338 { SMB_VFS_OP_SYS_ACL_SET_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 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 struct files_struct *dirfsp,
1005 SMB_STRUCT_STAT *sbuf)
1007 struct dirent *result;
1009 result = SMB_VFS_NEXT_READDIR(handle, dirfsp, dirp, sbuf);
1011 /* This operation has no reasonable error condition
1012 * (End of dir is also failure), so always succeed.
1014 do_log(SMB_VFS_OP_READDIR, True, handle, "");
1019 static void smb_full_audit_seekdir(vfs_handle_struct *handle,
1020 DIR *dirp, long offset)
1022 SMB_VFS_NEXT_SEEKDIR(handle, dirp, offset);
1024 do_log(SMB_VFS_OP_SEEKDIR, True, handle, "");
1027 static long smb_full_audit_telldir(vfs_handle_struct *handle,
1032 result = SMB_VFS_NEXT_TELLDIR(handle, dirp);
1034 do_log(SMB_VFS_OP_TELLDIR, True, handle, "");
1039 static void smb_full_audit_rewinddir(vfs_handle_struct *handle,
1042 SMB_VFS_NEXT_REWINDDIR(handle, dirp);
1044 do_log(SMB_VFS_OP_REWINDDIR, True, handle, "");
1047 static int smb_full_audit_mkdirat(vfs_handle_struct *handle,
1048 struct files_struct *dirfsp,
1049 const struct smb_filename *smb_fname,
1052 struct smb_filename *full_fname = NULL;
1055 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1058 if (full_fname == NULL) {
1063 result = SMB_VFS_NEXT_MKDIRAT(handle,
1068 do_log(SMB_VFS_OP_MKDIRAT,
1072 smb_fname_str_do_log(handle->conn, full_fname));
1074 TALLOC_FREE(full_fname);
1079 static int smb_full_audit_closedir(vfs_handle_struct *handle,
1084 result = SMB_VFS_NEXT_CLOSEDIR(handle, dirp);
1086 do_log(SMB_VFS_OP_CLOSEDIR, (result >= 0), handle, "");
1091 static int smb_full_audit_openat(vfs_handle_struct *handle,
1092 const struct files_struct *dirfsp,
1093 const struct smb_filename *smb_fname,
1094 struct files_struct *fsp,
1100 result = SMB_VFS_NEXT_OPENAT(handle, dirfsp, smb_fname, fsp, flags, mode);
1102 do_log(SMB_VFS_OP_OPENAT, (result >= 0), handle, "%s|%s",
1103 ((flags & O_WRONLY) || (flags & O_RDWR))?"w":"r",
1104 fsp_str_do_log(fsp));
1109 static NTSTATUS smb_full_audit_create_file(vfs_handle_struct *handle,
1110 struct smb_request *req,
1111 struct smb_filename *smb_fname,
1112 uint32_t access_mask,
1113 uint32_t share_access,
1114 uint32_t create_disposition,
1115 uint32_t create_options,
1116 uint32_t file_attributes,
1117 uint32_t oplock_request,
1118 const struct smb2_lease *lease,
1119 uint64_t allocation_size,
1120 uint32_t private_flags,
1121 struct security_descriptor *sd,
1122 struct ea_list *ea_list,
1123 files_struct **result_fsp,
1125 const struct smb2_create_blobs *in_context_blobs,
1126 struct smb2_create_blobs *out_context_blobs)
1129 const char* str_create_disposition;
1131 switch (create_disposition) {
1132 case FILE_SUPERSEDE:
1133 str_create_disposition = "supersede";
1135 case FILE_OVERWRITE_IF:
1136 str_create_disposition = "overwrite_if";
1139 str_create_disposition = "open";
1141 case FILE_OVERWRITE:
1142 str_create_disposition = "overwrite";
1145 str_create_disposition = "create";
1148 str_create_disposition = "open_if";
1151 str_create_disposition = "unknown";
1154 result = SMB_VFS_NEXT_CREATE_FILE(
1155 handle, /* handle */
1157 smb_fname, /* fname */
1158 access_mask, /* access_mask */
1159 share_access, /* share_access */
1160 create_disposition, /* create_disposition*/
1161 create_options, /* create_options */
1162 file_attributes, /* file_attributes */
1163 oplock_request, /* oplock_request */
1165 allocation_size, /* allocation_size */
1168 ea_list, /* ea_list */
1169 result_fsp, /* result */
1171 in_context_blobs, out_context_blobs); /* create context */
1173 do_log(SMB_VFS_OP_CREATE_FILE, (NT_STATUS_IS_OK(result)), handle,
1174 "0x%x|%s|%s|%s", access_mask,
1175 create_options & FILE_DIRECTORY_FILE ? "dir" : "file",
1176 str_create_disposition,
1177 smb_fname_str_do_log(handle->conn, smb_fname));
1182 static int smb_full_audit_close(vfs_handle_struct *handle, files_struct *fsp)
1186 result = SMB_VFS_NEXT_CLOSE(handle, fsp);
1188 do_log(SMB_VFS_OP_CLOSE, (result >= 0), handle, "%s",
1189 fsp_str_do_log(fsp));
1194 static ssize_t smb_full_audit_pread(vfs_handle_struct *handle, files_struct *fsp,
1195 void *data, size_t n, off_t offset)
1199 result = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
1201 do_log(SMB_VFS_OP_PREAD, (result >= 0), handle, "%s",
1202 fsp_str_do_log(fsp));
1207 struct smb_full_audit_pread_state {
1208 vfs_handle_struct *handle;
1211 struct vfs_aio_state vfs_aio_state;
1214 static void smb_full_audit_pread_done(struct tevent_req *subreq);
1216 static struct tevent_req *smb_full_audit_pread_send(
1217 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1218 struct tevent_context *ev, struct files_struct *fsp,
1219 void *data, size_t n, off_t offset)
1221 struct tevent_req *req, *subreq;
1222 struct smb_full_audit_pread_state *state;
1224 req = tevent_req_create(mem_ctx, &state,
1225 struct smb_full_audit_pread_state);
1227 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
1228 fsp_str_do_log(fsp));
1231 state->handle = handle;
1234 subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
1236 if (tevent_req_nomem(subreq, req)) {
1237 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
1238 fsp_str_do_log(fsp));
1239 return tevent_req_post(req, ev);
1241 tevent_req_set_callback(subreq, smb_full_audit_pread_done, req);
1243 do_log(SMB_VFS_OP_PREAD_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1247 static void smb_full_audit_pread_done(struct tevent_req *subreq)
1249 struct tevent_req *req = tevent_req_callback_data(
1250 subreq, struct tevent_req);
1251 struct smb_full_audit_pread_state *state = tevent_req_data(
1252 req, struct smb_full_audit_pread_state);
1254 state->ret = SMB_VFS_PREAD_RECV(subreq, &state->vfs_aio_state);
1255 TALLOC_FREE(subreq);
1256 tevent_req_done(req);
1259 static ssize_t smb_full_audit_pread_recv(struct tevent_req *req,
1260 struct vfs_aio_state *vfs_aio_state)
1262 struct smb_full_audit_pread_state *state = tevent_req_data(
1263 req, struct smb_full_audit_pread_state);
1265 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1266 do_log(SMB_VFS_OP_PREAD_RECV, false, state->handle, "%s",
1267 fsp_str_do_log(state->fsp));
1271 do_log(SMB_VFS_OP_PREAD_RECV, (state->ret >= 0), state->handle, "%s",
1272 fsp_str_do_log(state->fsp));
1274 *vfs_aio_state = state->vfs_aio_state;
1278 static ssize_t smb_full_audit_pwrite(vfs_handle_struct *handle, files_struct *fsp,
1279 const void *data, size_t n,
1284 result = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
1286 do_log(SMB_VFS_OP_PWRITE, (result >= 0), handle, "%s",
1287 fsp_str_do_log(fsp));
1292 struct smb_full_audit_pwrite_state {
1293 vfs_handle_struct *handle;
1296 struct vfs_aio_state vfs_aio_state;
1299 static void smb_full_audit_pwrite_done(struct tevent_req *subreq);
1301 static struct tevent_req *smb_full_audit_pwrite_send(
1302 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1303 struct tevent_context *ev, struct files_struct *fsp,
1304 const void *data, size_t n, off_t offset)
1306 struct tevent_req *req, *subreq;
1307 struct smb_full_audit_pwrite_state *state;
1309 req = tevent_req_create(mem_ctx, &state,
1310 struct smb_full_audit_pwrite_state);
1312 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1313 fsp_str_do_log(fsp));
1316 state->handle = handle;
1319 subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
1321 if (tevent_req_nomem(subreq, req)) {
1322 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1323 fsp_str_do_log(fsp));
1324 return tevent_req_post(req, ev);
1326 tevent_req_set_callback(subreq, smb_full_audit_pwrite_done, req);
1328 do_log(SMB_VFS_OP_PWRITE_SEND, true, handle, "%s",
1329 fsp_str_do_log(fsp));
1333 static void smb_full_audit_pwrite_done(struct tevent_req *subreq)
1335 struct tevent_req *req = tevent_req_callback_data(
1336 subreq, struct tevent_req);
1337 struct smb_full_audit_pwrite_state *state = tevent_req_data(
1338 req, struct smb_full_audit_pwrite_state);
1340 state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->vfs_aio_state);
1341 TALLOC_FREE(subreq);
1342 tevent_req_done(req);
1345 static ssize_t smb_full_audit_pwrite_recv(struct tevent_req *req,
1346 struct vfs_aio_state *vfs_aio_state)
1348 struct smb_full_audit_pwrite_state *state = tevent_req_data(
1349 req, struct smb_full_audit_pwrite_state);
1351 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1352 do_log(SMB_VFS_OP_PWRITE_RECV, false, state->handle, "%s",
1353 fsp_str_do_log(state->fsp));
1357 do_log(SMB_VFS_OP_PWRITE_RECV, (state->ret >= 0), state->handle, "%s",
1358 fsp_str_do_log(state->fsp));
1360 *vfs_aio_state = state->vfs_aio_state;
1364 static off_t smb_full_audit_lseek(vfs_handle_struct *handle, files_struct *fsp,
1365 off_t offset, int whence)
1369 result = SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence);
1371 do_log(SMB_VFS_OP_LSEEK, (result != (ssize_t)-1), handle,
1372 "%s", fsp_str_do_log(fsp));
1377 static ssize_t smb_full_audit_sendfile(vfs_handle_struct *handle, int tofd,
1378 files_struct *fromfsp,
1379 const DATA_BLOB *hdr, off_t offset,
1384 result = SMB_VFS_NEXT_SENDFILE(handle, tofd, fromfsp, hdr, offset, n);
1386 do_log(SMB_VFS_OP_SENDFILE, (result >= 0), handle,
1387 "%s", fsp_str_do_log(fromfsp));
1392 static ssize_t smb_full_audit_recvfile(vfs_handle_struct *handle, int fromfd,
1393 files_struct *tofsp,
1399 result = SMB_VFS_NEXT_RECVFILE(handle, fromfd, tofsp, offset, n);
1401 do_log(SMB_VFS_OP_RECVFILE, (result >= 0), handle,
1402 "%s", fsp_str_do_log(tofsp));
1407 static int smb_full_audit_renameat(vfs_handle_struct *handle,
1408 files_struct *srcfsp,
1409 const struct smb_filename *smb_fname_src,
1410 files_struct *dstfsp,
1411 const struct smb_filename *smb_fname_dst)
1415 result = SMB_VFS_NEXT_RENAMEAT(handle,
1421 do_log(SMB_VFS_OP_RENAMEAT, (result >= 0), handle, "%s|%s",
1422 smb_fname_str_do_log(handle->conn, smb_fname_src),
1423 smb_fname_str_do_log(handle->conn, smb_fname_dst));
1428 struct smb_full_audit_fsync_state {
1429 vfs_handle_struct *handle;
1432 struct vfs_aio_state vfs_aio_state;
1435 static void smb_full_audit_fsync_done(struct tevent_req *subreq);
1437 static struct tevent_req *smb_full_audit_fsync_send(
1438 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1439 struct tevent_context *ev, struct files_struct *fsp)
1441 struct tevent_req *req, *subreq;
1442 struct smb_full_audit_fsync_state *state;
1444 req = tevent_req_create(mem_ctx, &state,
1445 struct smb_full_audit_fsync_state);
1447 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1448 fsp_str_do_log(fsp));
1451 state->handle = handle;
1454 subreq = SMB_VFS_NEXT_FSYNC_SEND(state, ev, handle, fsp);
1455 if (tevent_req_nomem(subreq, req)) {
1456 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1457 fsp_str_do_log(fsp));
1458 return tevent_req_post(req, ev);
1460 tevent_req_set_callback(subreq, smb_full_audit_fsync_done, req);
1462 do_log(SMB_VFS_OP_FSYNC_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1466 static void smb_full_audit_fsync_done(struct tevent_req *subreq)
1468 struct tevent_req *req = tevent_req_callback_data(
1469 subreq, struct tevent_req);
1470 struct smb_full_audit_fsync_state *state = tevent_req_data(
1471 req, struct smb_full_audit_fsync_state);
1473 state->ret = SMB_VFS_FSYNC_RECV(subreq, &state->vfs_aio_state);
1474 TALLOC_FREE(subreq);
1475 tevent_req_done(req);
1478 static int smb_full_audit_fsync_recv(struct tevent_req *req,
1479 struct vfs_aio_state *vfs_aio_state)
1481 struct smb_full_audit_fsync_state *state = tevent_req_data(
1482 req, struct smb_full_audit_fsync_state);
1484 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1485 do_log(SMB_VFS_OP_FSYNC_RECV, false, state->handle, "%s",
1486 fsp_str_do_log(state->fsp));
1490 do_log(SMB_VFS_OP_FSYNC_RECV, (state->ret >= 0), state->handle, "%s",
1491 fsp_str_do_log(state->fsp));
1493 *vfs_aio_state = state->vfs_aio_state;
1497 static int smb_full_audit_stat(vfs_handle_struct *handle,
1498 struct smb_filename *smb_fname)
1502 result = SMB_VFS_NEXT_STAT(handle, smb_fname);
1504 do_log(SMB_VFS_OP_STAT, (result >= 0), handle, "%s",
1505 smb_fname_str_do_log(handle->conn, smb_fname));
1510 static int smb_full_audit_fstat(vfs_handle_struct *handle, files_struct *fsp,
1511 SMB_STRUCT_STAT *sbuf)
1515 result = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1517 do_log(SMB_VFS_OP_FSTAT, (result >= 0), handle, "%s",
1518 fsp_str_do_log(fsp));
1523 static int smb_full_audit_lstat(vfs_handle_struct *handle,
1524 struct smb_filename *smb_fname)
1528 result = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
1530 do_log(SMB_VFS_OP_LSTAT, (result >= 0), handle, "%s",
1531 smb_fname_str_do_log(handle->conn, smb_fname));
1536 static uint64_t smb_full_audit_get_alloc_size(vfs_handle_struct *handle,
1537 files_struct *fsp, const SMB_STRUCT_STAT *sbuf)
1541 result = SMB_VFS_NEXT_GET_ALLOC_SIZE(handle, fsp, sbuf);
1543 do_log(SMB_VFS_OP_GET_ALLOC_SIZE, (result != (uint64_t)-1), handle,
1544 "%llu", (unsigned long long)result);
1549 static int smb_full_audit_unlinkat(vfs_handle_struct *handle,
1550 struct files_struct *dirfsp,
1551 const struct smb_filename *smb_fname,
1556 result = SMB_VFS_NEXT_UNLINKAT(handle,
1561 do_log(SMB_VFS_OP_UNLINKAT, (result >= 0), handle, "%s",
1562 smb_fname_str_do_log(handle->conn, smb_fname));
1567 static int smb_full_audit_chmod(vfs_handle_struct *handle,
1568 const struct smb_filename *smb_fname,
1573 result = SMB_VFS_NEXT_CHMOD(handle, smb_fname, mode);
1575 do_log(SMB_VFS_OP_CHMOD,
1579 smb_fname_str_do_log(handle->conn, smb_fname),
1585 static int smb_full_audit_fchmod(vfs_handle_struct *handle, files_struct *fsp,
1590 result = SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1592 do_log(SMB_VFS_OP_FCHMOD, (result >= 0), handle,
1593 "%s|%o", fsp_str_do_log(fsp), mode);
1598 static int smb_full_audit_fchown(vfs_handle_struct *handle, files_struct *fsp,
1599 uid_t uid, gid_t gid)
1603 result = SMB_VFS_NEXT_FCHOWN(handle, fsp, uid, gid);
1605 do_log(SMB_VFS_OP_FCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1606 fsp_str_do_log(fsp), (long int)uid, (long int)gid);
1611 static int smb_full_audit_lchown(vfs_handle_struct *handle,
1612 const struct smb_filename *smb_fname,
1618 result = SMB_VFS_NEXT_LCHOWN(handle, smb_fname, uid, gid);
1620 do_log(SMB_VFS_OP_LCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1621 smb_fname->base_name, (long int)uid, (long int)gid);
1626 static int smb_full_audit_chdir(vfs_handle_struct *handle,
1627 const struct smb_filename *smb_fname)
1631 result = SMB_VFS_NEXT_CHDIR(handle, smb_fname);
1633 do_log(SMB_VFS_OP_CHDIR,
1637 smb_fname_str_do_log(handle->conn, smb_fname));
1642 static struct smb_filename *smb_full_audit_getwd(vfs_handle_struct *handle,
1645 struct smb_filename *result;
1647 result = SMB_VFS_NEXT_GETWD(handle, ctx);
1649 do_log(SMB_VFS_OP_GETWD, (result != NULL), handle, "%s",
1650 result == NULL? "" : result->base_name);
1655 static int smb_full_audit_ntimes(vfs_handle_struct *handle,
1656 const struct smb_filename *smb_fname,
1657 struct smb_file_time *ft)
1660 time_t create_time = convert_timespec_to_time_t(ft->create_time);
1661 time_t atime = convert_timespec_to_time_t(ft->atime);
1662 time_t mtime = convert_timespec_to_time_t(ft->mtime);
1663 time_t ctime = convert_timespec_to_time_t(ft->ctime);
1664 const char *create_time_str = "";
1665 const char *atime_str = "";
1666 const char *mtime_str = "";
1667 const char *ctime_str = "";
1668 TALLOC_CTX *frame = talloc_stackframe();
1670 result = SMB_VFS_NEXT_NTIMES(handle, smb_fname, ft);
1672 if (create_time > 0) {
1673 create_time_str = timestring(frame, create_time);
1676 atime_str = timestring(frame, atime);
1679 mtime_str = timestring(frame, mtime);
1682 ctime_str = timestring(frame, ctime);
1685 do_log(SMB_VFS_OP_NTIMES,
1689 smb_fname_str_do_log(handle->conn, smb_fname),
1700 static int smb_full_audit_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
1705 result = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1707 do_log(SMB_VFS_OP_FTRUNCATE, (result >= 0), handle,
1708 "%s", fsp_str_do_log(fsp));
1713 static int smb_full_audit_fallocate(vfs_handle_struct *handle, files_struct *fsp,
1720 result = SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
1722 do_log(SMB_VFS_OP_FALLOCATE, (result >= 0), handle,
1723 "%s", fsp_str_do_log(fsp));
1728 static bool smb_full_audit_lock(vfs_handle_struct *handle, files_struct *fsp,
1729 int op, off_t offset, off_t count, int type)
1733 result = SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type);
1735 do_log(SMB_VFS_OP_LOCK, result, handle, "%s", fsp_str_do_log(fsp));
1740 static int smb_full_audit_kernel_flock(struct vfs_handle_struct *handle,
1741 struct files_struct *fsp,
1742 uint32_t share_access,
1743 uint32_t access_mask)
1747 result = SMB_VFS_NEXT_KERNEL_FLOCK(handle,
1752 do_log(SMB_VFS_OP_KERNEL_FLOCK, (result >= 0), handle, "%s",
1753 fsp_str_do_log(fsp));
1758 static int smb_full_audit_fcntl(struct vfs_handle_struct *handle,
1759 struct files_struct *fsp,
1760 int cmd, va_list cmd_arg)
1763 va_list dup_cmd_arg;
1766 va_copy(dup_cmd_arg, cmd_arg);
1767 arg = va_arg(dup_cmd_arg, void *);
1768 result = SMB_VFS_NEXT_FCNTL(handle, fsp, cmd, arg);
1769 va_end(dup_cmd_arg);
1771 do_log(SMB_VFS_OP_FCNTL, (result >= 0), handle, "%s",
1772 fsp_str_do_log(fsp));
1777 static int smb_full_audit_linux_setlease(vfs_handle_struct *handle, files_struct *fsp,
1782 result = SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
1784 do_log(SMB_VFS_OP_LINUX_SETLEASE, (result >= 0), handle, "%s",
1785 fsp_str_do_log(fsp));
1790 static bool smb_full_audit_getlock(vfs_handle_struct *handle, files_struct *fsp,
1791 off_t *poffset, off_t *pcount, int *ptype, pid_t *ppid)
1795 result = SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype, ppid);
1797 do_log(SMB_VFS_OP_GETLOCK, result, handle, "%s", fsp_str_do_log(fsp));
1802 static int smb_full_audit_symlinkat(vfs_handle_struct *handle,
1803 const struct smb_filename *link_contents,
1804 struct files_struct *dirfsp,
1805 const struct smb_filename *new_smb_fname)
1807 struct smb_filename *full_fname = NULL;
1810 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1813 if (full_fname == NULL) {
1817 result = SMB_VFS_NEXT_SYMLINKAT(handle,
1822 do_log(SMB_VFS_OP_SYMLINKAT,
1826 link_contents->base_name,
1827 smb_fname_str_do_log(handle->conn, full_fname));
1829 TALLOC_FREE(full_fname);
1834 static int smb_full_audit_readlinkat(vfs_handle_struct *handle,
1835 const struct files_struct *dirfsp,
1836 const struct smb_filename *smb_fname,
1842 result = SMB_VFS_NEXT_READLINKAT(handle,
1848 do_log(SMB_VFS_OP_READLINKAT,
1852 smb_fname_str_do_log(handle->conn, smb_fname));
1857 static int smb_full_audit_linkat(vfs_handle_struct *handle,
1858 files_struct *srcfsp,
1859 const struct smb_filename *old_smb_fname,
1860 files_struct *dstfsp,
1861 const struct smb_filename *new_smb_fname,
1866 result = SMB_VFS_NEXT_LINKAT(handle,
1873 do_log(SMB_VFS_OP_LINKAT,
1877 smb_fname_str_do_log(handle->conn, old_smb_fname),
1878 smb_fname_str_do_log(handle->conn, new_smb_fname));
1883 static int smb_full_audit_mknodat(vfs_handle_struct *handle,
1884 files_struct *dirfsp,
1885 const struct smb_filename *smb_fname,
1889 struct smb_filename *full_fname = NULL;
1892 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1895 if (full_fname == NULL) {
1899 result = SMB_VFS_NEXT_MKNODAT(handle,
1905 do_log(SMB_VFS_OP_MKNODAT,
1909 smb_fname_str_do_log(handle->conn, full_fname));
1911 TALLOC_FREE(full_fname);
1916 static struct smb_filename *smb_full_audit_realpath(vfs_handle_struct *handle,
1918 const struct smb_filename *smb_fname)
1920 struct smb_filename *result_fname = NULL;
1922 result_fname = SMB_VFS_NEXT_REALPATH(handle, ctx, smb_fname);
1924 do_log(SMB_VFS_OP_REALPATH,
1925 (result_fname != NULL),
1928 smb_fname_str_do_log(handle->conn, smb_fname));
1930 return result_fname;
1933 static int smb_full_audit_chflags(vfs_handle_struct *handle,
1934 const struct smb_filename *smb_fname,
1939 result = SMB_VFS_NEXT_CHFLAGS(handle, smb_fname, flags);
1941 do_log(SMB_VFS_OP_CHFLAGS,
1945 smb_fname_str_do_log(handle->conn, smb_fname));
1950 static struct file_id smb_full_audit_file_id_create(struct vfs_handle_struct *handle,
1951 const SMB_STRUCT_STAT *sbuf)
1953 struct file_id id_zero = { 0 };
1954 struct file_id result;
1955 struct file_id_buf idbuf;
1957 result = SMB_VFS_NEXT_FILE_ID_CREATE(handle, sbuf);
1959 do_log(SMB_VFS_OP_FILE_ID_CREATE,
1960 !file_id_equal(&id_zero, &result),
1963 file_id_str_buf(result, &idbuf));
1968 static uint64_t smb_full_audit_fs_file_id(struct vfs_handle_struct *handle,
1969 const SMB_STRUCT_STAT *sbuf)
1973 result = SMB_VFS_NEXT_FS_FILE_ID(handle, sbuf);
1975 do_log(SMB_VFS_OP_FS_FILE_ID,
1977 handle, "%" PRIu64, result);
1982 static NTSTATUS smb_full_audit_streaminfo(vfs_handle_struct *handle,
1983 struct files_struct *fsp,
1984 const struct smb_filename *smb_fname,
1985 TALLOC_CTX *mem_ctx,
1986 unsigned int *pnum_streams,
1987 struct stream_struct **pstreams)
1991 result = SMB_VFS_NEXT_STREAMINFO(handle, fsp, smb_fname, mem_ctx,
1992 pnum_streams, pstreams);
1994 do_log(SMB_VFS_OP_STREAMINFO,
1995 NT_STATUS_IS_OK(result),
1998 smb_fname_str_do_log(handle->conn, smb_fname));
2003 static int smb_full_audit_get_real_filename(struct vfs_handle_struct *handle,
2004 const struct smb_filename *path,
2006 TALLOC_CTX *mem_ctx,
2011 result = SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name, mem_ctx,
2014 do_log(SMB_VFS_OP_GET_REAL_FILENAME, (result == 0), handle,
2016 path->base_name, name, (result == 0) ? *found_name : "");
2021 static const char *smb_full_audit_connectpath(vfs_handle_struct *handle,
2022 const struct smb_filename *smb_fname)
2026 result = SMB_VFS_NEXT_CONNECTPATH(handle, smb_fname);
2028 do_log(SMB_VFS_OP_CONNECTPATH,
2032 smb_fname_str_do_log(handle->conn, smb_fname));
2037 static NTSTATUS smb_full_audit_brl_lock_windows(struct vfs_handle_struct *handle,
2038 struct byte_range_lock *br_lck,
2039 struct lock_struct *plock)
2043 result = SMB_VFS_NEXT_BRL_LOCK_WINDOWS(handle, br_lck, plock);
2045 do_log(SMB_VFS_OP_BRL_LOCK_WINDOWS, NT_STATUS_IS_OK(result), handle,
2046 "%s:%llu-%llu. type=%d.",
2047 fsp_str_do_log(brl_fsp(br_lck)),
2048 (unsigned long long)plock->start,
2049 (unsigned long long)plock->size,
2055 static bool smb_full_audit_brl_unlock_windows(struct vfs_handle_struct *handle,
2056 struct byte_range_lock *br_lck,
2057 const struct lock_struct *plock)
2061 result = SMB_VFS_NEXT_BRL_UNLOCK_WINDOWS(handle, br_lck, plock);
2063 do_log(SMB_VFS_OP_BRL_UNLOCK_WINDOWS, (result == 0), handle,
2064 "%s:%llu-%llu:%d", fsp_str_do_log(brl_fsp(br_lck)),
2065 (unsigned long long)plock->start,
2066 (unsigned long long)plock->size,
2072 static bool smb_full_audit_strict_lock_check(struct vfs_handle_struct *handle,
2073 struct files_struct *fsp,
2074 struct lock_struct *plock)
2078 result = SMB_VFS_NEXT_STRICT_LOCK_CHECK(handle, fsp, plock);
2080 do_log(SMB_VFS_OP_STRICT_LOCK_CHECK, result, handle,
2081 "%s:%llu-%llu:%d", fsp_str_do_log(fsp),
2082 (unsigned long long)plock->start,
2083 (unsigned long long)plock->size,
2089 static NTSTATUS smb_full_audit_translate_name(struct vfs_handle_struct *handle,
2091 enum vfs_translate_direction direction,
2092 TALLOC_CTX *mem_ctx,
2097 result = SMB_VFS_NEXT_TRANSLATE_NAME(handle, name, direction, mem_ctx,
2100 do_log(SMB_VFS_OP_TRANSLATE_NAME, NT_STATUS_IS_OK(result), handle, "");
2105 static NTSTATUS smb_full_audit_fsctl(struct vfs_handle_struct *handle,
2106 struct files_struct *fsp,
2110 const uint8_t *_in_data,
2112 uint8_t **_out_data,
2113 uint32_t max_out_len,
2118 result = SMB_VFS_NEXT_FSCTL(handle,
2129 do_log(SMB_VFS_OP_FSCTL, NT_STATUS_IS_OK(result), handle, "");
2134 static struct tevent_req *smb_full_audit_offload_read_send(
2135 TALLOC_CTX *mem_ctx,
2136 struct tevent_context *ev,
2137 struct vfs_handle_struct *handle,
2138 struct files_struct *fsp,
2144 struct tevent_req *req = NULL;
2146 req = SMB_VFS_NEXT_OFFLOAD_READ_SEND(mem_ctx, ev, handle, fsp,
2147 fsctl, ttl, offset, to_copy);
2149 do_log(SMB_VFS_OP_OFFLOAD_READ_SEND, req, handle, "");
2154 static NTSTATUS smb_full_audit_offload_read_recv(
2155 struct tevent_req *req,
2156 struct vfs_handle_struct *handle,
2157 TALLOC_CTX *mem_ctx,
2158 DATA_BLOB *_token_blob)
2162 status = SMB_VFS_NEXT_OFFLOAD_READ_RECV(req, handle, mem_ctx,
2165 do_log(SMB_VFS_OP_OFFLOAD_READ_RECV, NT_STATUS_IS_OK(status), handle, "");
2170 static struct tevent_req *smb_full_audit_offload_write_send(struct vfs_handle_struct *handle,
2171 TALLOC_CTX *mem_ctx,
2172 struct tevent_context *ev,
2175 off_t transfer_offset,
2176 struct files_struct *dest_fsp,
2180 struct tevent_req *req;
2182 req = SMB_VFS_NEXT_OFFLOAD_WRITE_SEND(handle, mem_ctx, ev,
2183 fsctl, token, transfer_offset,
2184 dest_fsp, dest_off, num);
2186 do_log(SMB_VFS_OP_OFFLOAD_WRITE_SEND, req, handle, "");
2191 static NTSTATUS smb_full_audit_offload_write_recv(struct vfs_handle_struct *handle,
2192 struct tevent_req *req,
2197 result = SMB_VFS_NEXT_OFFLOAD_WRITE_RECV(handle, req, copied);
2199 do_log(SMB_VFS_OP_OFFLOAD_WRITE_RECV, NT_STATUS_IS_OK(result), handle, "");
2204 static NTSTATUS smb_full_audit_fget_compression(vfs_handle_struct *handle,
2205 TALLOC_CTX *mem_ctx,
2206 struct files_struct *fsp,
2207 uint16_t *_compression_fmt)
2211 result = SMB_VFS_NEXT_FGET_COMPRESSION(handle, mem_ctx, fsp,
2214 do_log(SMB_VFS_OP_FGET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
2216 fsp_str_do_log(fsp));
2221 static NTSTATUS smb_full_audit_set_compression(vfs_handle_struct *handle,
2222 TALLOC_CTX *mem_ctx,
2223 struct files_struct *fsp,
2224 uint16_t compression_fmt)
2228 result = SMB_VFS_NEXT_SET_COMPRESSION(handle, mem_ctx, fsp,
2231 do_log(SMB_VFS_OP_SET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
2232 "%s", fsp_str_do_log(fsp));
2237 static NTSTATUS smb_full_audit_readdir_attr(struct vfs_handle_struct *handle,
2238 const struct smb_filename *fname,
2239 TALLOC_CTX *mem_ctx,
2240 struct readdir_attr_data **pattr_data)
2244 status = SMB_VFS_NEXT_READDIR_ATTR(handle, fname, mem_ctx, pattr_data);
2246 do_log(SMB_VFS_OP_READDIR_ATTR, NT_STATUS_IS_OK(status), handle, "%s",
2247 smb_fname_str_do_log(handle->conn, fname));
2252 struct smb_full_audit_get_dos_attributes_state {
2253 struct vfs_aio_state aio_state;
2254 vfs_handle_struct *handle;
2255 files_struct *dir_fsp;
2256 const struct smb_filename *smb_fname;
2260 static void smb_full_audit_get_dos_attributes_done(struct tevent_req *subreq);
2262 static struct tevent_req *smb_full_audit_get_dos_attributes_send(
2263 TALLOC_CTX *mem_ctx,
2264 struct tevent_context *ev,
2265 struct vfs_handle_struct *handle,
2266 files_struct *dir_fsp,
2267 struct smb_filename *smb_fname)
2269 struct tevent_req *req = NULL;
2270 struct smb_full_audit_get_dos_attributes_state *state = NULL;
2271 struct tevent_req *subreq = NULL;
2273 req = tevent_req_create(mem_ctx, &state,
2274 struct smb_full_audit_get_dos_attributes_state);
2276 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2280 fsp_str_do_log(dir_fsp),
2281 smb_fname->base_name);
2284 *state = (struct smb_full_audit_get_dos_attributes_state) {
2287 .smb_fname = smb_fname,
2290 subreq = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES_SEND(mem_ctx,
2295 if (tevent_req_nomem(subreq, req)) {
2296 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2300 fsp_str_do_log(dir_fsp),
2301 smb_fname->base_name);
2302 return tevent_req_post(req, ev);
2304 tevent_req_set_callback(subreq,
2305 smb_full_audit_get_dos_attributes_done,
2308 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2312 fsp_str_do_log(dir_fsp),
2313 smb_fname->base_name);
2318 static void smb_full_audit_get_dos_attributes_done(struct tevent_req *subreq)
2320 struct tevent_req *req =
2321 tevent_req_callback_data(subreq,
2323 struct smb_full_audit_get_dos_attributes_state *state =
2324 tevent_req_data(req,
2325 struct smb_full_audit_get_dos_attributes_state);
2328 status = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES_RECV(subreq,
2331 TALLOC_FREE(subreq);
2332 if (tevent_req_nterror(req, status)) {
2336 tevent_req_done(req);
2340 static NTSTATUS smb_full_audit_get_dos_attributes_recv(struct tevent_req *req,
2341 struct vfs_aio_state *aio_state,
2344 struct smb_full_audit_get_dos_attributes_state *state =
2345 tevent_req_data(req,
2346 struct smb_full_audit_get_dos_attributes_state);
2349 if (tevent_req_is_nterror(req, &status)) {
2350 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV,
2354 fsp_str_do_log(state->dir_fsp),
2355 state->smb_fname->base_name);
2356 tevent_req_received(req);
2360 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV,
2364 fsp_str_do_log(state->dir_fsp),
2365 state->smb_fname->base_name);
2367 *aio_state = state->aio_state;
2368 *dosmode = state->dosmode;
2369 tevent_req_received(req);
2370 return NT_STATUS_OK;
2373 static NTSTATUS smb_full_audit_fget_dos_attributes(
2374 struct vfs_handle_struct *handle,
2375 struct files_struct *fsp,
2380 status = SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle,
2384 do_log(SMB_VFS_OP_FGET_DOS_ATTRIBUTES,
2385 NT_STATUS_IS_OK(status),
2388 fsp_str_do_log(fsp));
2393 static NTSTATUS smb_full_audit_set_dos_attributes(
2394 struct vfs_handle_struct *handle,
2395 const struct smb_filename *smb_fname,
2400 status = SMB_VFS_NEXT_SET_DOS_ATTRIBUTES(handle,
2404 do_log(SMB_VFS_OP_SET_DOS_ATTRIBUTES,
2405 NT_STATUS_IS_OK(status),
2408 smb_fname_str_do_log(handle->conn, smb_fname));
2413 static NTSTATUS smb_full_audit_fset_dos_attributes(
2414 struct vfs_handle_struct *handle,
2415 struct files_struct *fsp,
2420 status = SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle,
2424 do_log(SMB_VFS_OP_FSET_DOS_ATTRIBUTES,
2425 NT_STATUS_IS_OK(status),
2428 fsp_str_do_log(fsp));
2433 static NTSTATUS smb_full_audit_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
2434 uint32_t security_info,
2435 TALLOC_CTX *mem_ctx,
2436 struct security_descriptor **ppdesc)
2440 result = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
2443 do_log(SMB_VFS_OP_FGET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2444 "%s", fsp_str_do_log(fsp));
2449 static NTSTATUS smb_full_audit_get_nt_acl_at(vfs_handle_struct *handle,
2450 struct files_struct *dirfsp,
2451 const struct smb_filename *smb_fname,
2452 uint32_t security_info,
2453 TALLOC_CTX *mem_ctx,
2454 struct security_descriptor **ppdesc)
2458 result = SMB_VFS_NEXT_GET_NT_ACL_AT(handle,
2465 do_log(SMB_VFS_OP_GET_NT_ACL_AT,
2466 NT_STATUS_IS_OK(result),
2469 smb_fname_str_do_log(handle->conn, smb_fname));
2474 static NTSTATUS smb_full_audit_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
2475 uint32_t security_info_sent,
2476 const struct security_descriptor *psd)
2478 struct vfs_full_audit_private_data *pd;
2482 SMB_VFS_HANDLE_GET_DATA(handle, pd,
2483 struct vfs_full_audit_private_data,
2484 return NT_STATUS_INTERNAL_ERROR);
2486 if (pd->log_secdesc) {
2487 sd = sddl_encode(talloc_tos(), psd, get_global_sam_sid());
2490 result = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
2492 do_log(SMB_VFS_OP_FSET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2493 "%s [%s]", fsp_str_do_log(fsp), sd ? sd : "");
2500 static NTSTATUS smb_full_audit_audit_file(struct vfs_handle_struct *handle,
2501 struct smb_filename *file,
2502 struct security_acl *sacl,
2503 uint32_t access_requested,
2504 uint32_t access_denied)
2508 result = SMB_VFS_NEXT_AUDIT_FILE(handle,
2514 do_log(SMB_VFS_OP_AUDIT_FILE, NT_STATUS_IS_OK(result), handle,
2516 smb_fname_str_do_log(handle->conn, file));
2521 static SMB_ACL_T smb_full_audit_sys_acl_get_file(vfs_handle_struct *handle,
2522 const struct smb_filename *smb_fname,
2523 SMB_ACL_TYPE_T type,
2524 TALLOC_CTX *mem_ctx)
2528 result = SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, smb_fname,
2531 do_log(SMB_VFS_OP_SYS_ACL_GET_FILE,
2535 smb_fname_str_do_log(handle->conn, smb_fname));
2540 static SMB_ACL_T smb_full_audit_sys_acl_get_fd(vfs_handle_struct *handle,
2541 files_struct *fsp, TALLOC_CTX *mem_ctx)
2545 result = SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp, mem_ctx);
2547 do_log(SMB_VFS_OP_SYS_ACL_GET_FD, (result != NULL), handle,
2548 "%s", fsp_str_do_log(fsp));
2553 static int smb_full_audit_sys_acl_blob_get_file(vfs_handle_struct *handle,
2554 const struct smb_filename *smb_fname,
2555 TALLOC_CTX *mem_ctx,
2556 char **blob_description,
2561 result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FILE(handle, smb_fname,
2562 mem_ctx, blob_description, blob);
2564 do_log(SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE,
2568 smb_fname_str_do_log(handle->conn, smb_fname));
2573 static int smb_full_audit_sys_acl_blob_get_fd(vfs_handle_struct *handle,
2575 TALLOC_CTX *mem_ctx,
2576 char **blob_description,
2581 result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle, fsp, mem_ctx, blob_description, blob);
2583 do_log(SMB_VFS_OP_SYS_ACL_BLOB_GET_FD, (result >= 0), handle,
2584 "%s", fsp_str_do_log(fsp));
2589 static int smb_full_audit_sys_acl_set_fd(vfs_handle_struct *handle,
2590 struct files_struct *fsp,
2591 SMB_ACL_TYPE_T type,
2596 result = SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, type, theacl);
2598 do_log(SMB_VFS_OP_SYS_ACL_SET_FD, (result >= 0), handle,
2599 "%s", fsp_str_do_log(fsp));
2604 static int smb_full_audit_sys_acl_delete_def_file(vfs_handle_struct *handle,
2605 const struct smb_filename *smb_fname)
2609 result = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, smb_fname);
2611 do_log(SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE,
2615 smb_fname_str_do_log(handle->conn, smb_fname));
2620 static ssize_t smb_full_audit_getxattr(struct vfs_handle_struct *handle,
2621 const struct smb_filename *smb_fname,
2622 const char *name, void *value, size_t size)
2626 result = SMB_VFS_NEXT_GETXATTR(handle, smb_fname, name, value, size);
2628 do_log(SMB_VFS_OP_GETXATTR,
2632 smb_fname_str_do_log(handle->conn, smb_fname),
2638 struct smb_full_audit_getxattrat_state {
2639 struct vfs_aio_state aio_state;
2640 vfs_handle_struct *handle;
2641 files_struct *dir_fsp;
2642 const struct smb_filename *smb_fname;
2643 const char *xattr_name;
2645 uint8_t *xattr_value;
2648 static void smb_full_audit_getxattrat_done(struct tevent_req *subreq);
2650 static struct tevent_req *smb_full_audit_getxattrat_send(
2651 TALLOC_CTX *mem_ctx,
2652 struct tevent_context *ev,
2653 struct vfs_handle_struct *handle,
2654 files_struct *dir_fsp,
2655 const struct smb_filename *smb_fname,
2656 const char *xattr_name,
2659 struct tevent_req *req = NULL;
2660 struct tevent_req *subreq = NULL;
2661 struct smb_full_audit_getxattrat_state *state = NULL;
2663 req = tevent_req_create(mem_ctx, &state,
2664 struct smb_full_audit_getxattrat_state);
2666 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2670 fsp_str_do_log(dir_fsp),
2671 smb_fname->base_name,
2675 *state = (struct smb_full_audit_getxattrat_state) {
2678 .smb_fname = smb_fname,
2679 .xattr_name = xattr_name,
2682 subreq = SMB_VFS_NEXT_GETXATTRAT_SEND(state,
2689 if (tevent_req_nomem(subreq, req)) {
2690 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2694 fsp_str_do_log(dir_fsp),
2695 smb_fname->base_name,
2697 return tevent_req_post(req, ev);
2699 tevent_req_set_callback(subreq, smb_full_audit_getxattrat_done, req);
2701 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2705 fsp_str_do_log(dir_fsp),
2706 smb_fname->base_name,
2712 static void smb_full_audit_getxattrat_done(struct tevent_req *subreq)
2714 struct tevent_req *req = tevent_req_callback_data(
2715 subreq, struct tevent_req);
2716 struct smb_full_audit_getxattrat_state *state = tevent_req_data(
2717 req, struct smb_full_audit_getxattrat_state);
2719 state->xattr_size = SMB_VFS_NEXT_GETXATTRAT_RECV(subreq,
2722 &state->xattr_value);
2723 TALLOC_FREE(subreq);
2724 if (state->xattr_size == -1) {
2725 tevent_req_error(req, state->aio_state.error);
2729 tevent_req_done(req);
2732 static ssize_t smb_full_audit_getxattrat_recv(struct tevent_req *req,
2733 struct vfs_aio_state *aio_state,
2734 TALLOC_CTX *mem_ctx,
2735 uint8_t **xattr_value)
2737 struct smb_full_audit_getxattrat_state *state = tevent_req_data(
2738 req, struct smb_full_audit_getxattrat_state);
2741 if (tevent_req_is_unix_error(req, &aio_state->error)) {
2742 do_log(SMB_VFS_OP_GETXATTRAT_RECV,
2746 fsp_str_do_log(state->dir_fsp),
2747 state->smb_fname->base_name,
2749 tevent_req_received(req);
2753 do_log(SMB_VFS_OP_GETXATTRAT_RECV,
2757 fsp_str_do_log(state->dir_fsp),
2758 state->smb_fname->base_name,
2761 *aio_state = state->aio_state;
2762 xattr_size = state->xattr_size;
2763 if (xattr_value != NULL) {
2764 *xattr_value = talloc_move(mem_ctx, &state->xattr_value);
2767 tevent_req_received(req);
2771 static ssize_t smb_full_audit_fgetxattr(struct vfs_handle_struct *handle,
2772 struct files_struct *fsp,
2773 const char *name, void *value, size_t size)
2777 result = SMB_VFS_NEXT_FGETXATTR(handle, fsp, name, value, size);
2779 do_log(SMB_VFS_OP_FGETXATTR, (result >= 0), handle,
2780 "%s|%s", fsp_str_do_log(fsp), name);
2785 static ssize_t smb_full_audit_listxattr(struct vfs_handle_struct *handle,
2786 const struct smb_filename *smb_fname,
2792 result = SMB_VFS_NEXT_LISTXATTR(handle, smb_fname, list, size);
2794 do_log(SMB_VFS_OP_LISTXATTR,
2798 smb_fname_str_do_log(handle->conn, smb_fname));
2803 static ssize_t smb_full_audit_flistxattr(struct vfs_handle_struct *handle,
2804 struct files_struct *fsp, char *list,
2809 result = SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
2811 do_log(SMB_VFS_OP_FLISTXATTR, (result >= 0), handle,
2812 "%s", fsp_str_do_log(fsp));
2817 static int smb_full_audit_removexattr(struct vfs_handle_struct *handle,
2818 const struct smb_filename *smb_fname,
2823 result = SMB_VFS_NEXT_REMOVEXATTR(handle, smb_fname, name);
2825 do_log(SMB_VFS_OP_REMOVEXATTR,
2829 smb_fname_str_do_log(handle->conn, smb_fname),
2835 static int smb_full_audit_fremovexattr(struct vfs_handle_struct *handle,
2836 struct files_struct *fsp,
2841 result = SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, name);
2843 do_log(SMB_VFS_OP_FREMOVEXATTR, (result >= 0), handle,
2844 "%s|%s", fsp_str_do_log(fsp), name);
2849 static int smb_full_audit_setxattr(struct vfs_handle_struct *handle,
2850 const struct smb_filename *smb_fname,
2851 const char *name, const void *value, size_t size,
2856 result = SMB_VFS_NEXT_SETXATTR(handle, smb_fname, name, value, size,
2859 do_log(SMB_VFS_OP_SETXATTR,
2863 smb_fname_str_do_log(handle->conn, smb_fname),
2869 static int smb_full_audit_fsetxattr(struct vfs_handle_struct *handle,
2870 struct files_struct *fsp, const char *name,
2871 const void *value, size_t size, int flags)
2875 result = SMB_VFS_NEXT_FSETXATTR(handle, fsp, name, value, size, flags);
2877 do_log(SMB_VFS_OP_FSETXATTR, (result >= 0), handle,
2878 "%s|%s", fsp_str_do_log(fsp), name);
2883 static bool smb_full_audit_aio_force(struct vfs_handle_struct *handle,
2884 struct files_struct *fsp)
2888 result = SMB_VFS_NEXT_AIO_FORCE(handle, fsp);
2889 do_log(SMB_VFS_OP_AIO_FORCE, result, handle,
2890 "%s", fsp_str_do_log(fsp));
2895 static NTSTATUS smb_full_audit_durable_cookie(struct vfs_handle_struct *handle,
2896 struct files_struct *fsp,
2897 TALLOC_CTX *mem_ctx,
2902 result = SMB_VFS_NEXT_DURABLE_COOKIE(handle,
2907 do_log(SMB_VFS_OP_DURABLE_COOKIE, NT_STATUS_IS_OK(result), handle,
2908 "%s", fsp_str_do_log(fsp));
2913 static NTSTATUS smb_full_audit_durable_disconnect(
2914 struct vfs_handle_struct *handle,
2915 struct files_struct *fsp,
2916 const DATA_BLOB old_cookie,
2917 TALLOC_CTX *mem_ctx,
2918 DATA_BLOB *new_cookie)
2922 result = SMB_VFS_NEXT_DURABLE_DISCONNECT(handle,
2928 do_log(SMB_VFS_OP_DURABLE_DISCONNECT, NT_STATUS_IS_OK(result), handle,
2929 "%s", fsp_str_do_log(fsp));
2934 static NTSTATUS smb_full_audit_durable_reconnect(
2935 struct vfs_handle_struct *handle,
2936 struct smb_request *smb1req,
2937 struct smbXsrv_open *op,
2938 const DATA_BLOB old_cookie,
2939 TALLOC_CTX *mem_ctx,
2940 struct files_struct **fsp,
2941 DATA_BLOB *new_cookie)
2945 result = SMB_VFS_NEXT_DURABLE_RECONNECT(handle,
2953 do_log(SMB_VFS_OP_DURABLE_RECONNECT,
2954 NT_STATUS_IS_OK(result),
2961 static struct vfs_fn_pointers vfs_full_audit_fns = {
2963 /* Disk operations */
2965 .connect_fn = smb_full_audit_connect,
2966 .disconnect_fn = smb_full_audit_disconnect,
2967 .disk_free_fn = smb_full_audit_disk_free,
2968 .get_quota_fn = smb_full_audit_get_quota,
2969 .set_quota_fn = smb_full_audit_set_quota,
2970 .get_shadow_copy_data_fn = smb_full_audit_get_shadow_copy_data,
2971 .statvfs_fn = smb_full_audit_statvfs,
2972 .fs_capabilities_fn = smb_full_audit_fs_capabilities,
2973 .get_dfs_referrals_fn = smb_full_audit_get_dfs_referrals,
2974 .create_dfs_pathat_fn = smb_full_audit_create_dfs_pathat,
2975 .read_dfs_pathat_fn = smb_full_audit_read_dfs_pathat,
2976 .fdopendir_fn = smb_full_audit_fdopendir,
2977 .readdir_fn = smb_full_audit_readdir,
2978 .seekdir_fn = smb_full_audit_seekdir,
2979 .telldir_fn = smb_full_audit_telldir,
2980 .rewind_dir_fn = smb_full_audit_rewinddir,
2981 .mkdirat_fn = smb_full_audit_mkdirat,
2982 .closedir_fn = smb_full_audit_closedir,
2983 .openat_fn = smb_full_audit_openat,
2984 .create_file_fn = smb_full_audit_create_file,
2985 .close_fn = smb_full_audit_close,
2986 .pread_fn = smb_full_audit_pread,
2987 .pread_send_fn = smb_full_audit_pread_send,
2988 .pread_recv_fn = smb_full_audit_pread_recv,
2989 .pwrite_fn = smb_full_audit_pwrite,
2990 .pwrite_send_fn = smb_full_audit_pwrite_send,
2991 .pwrite_recv_fn = smb_full_audit_pwrite_recv,
2992 .lseek_fn = smb_full_audit_lseek,
2993 .sendfile_fn = smb_full_audit_sendfile,
2994 .recvfile_fn = smb_full_audit_recvfile,
2995 .renameat_fn = smb_full_audit_renameat,
2996 .fsync_send_fn = smb_full_audit_fsync_send,
2997 .fsync_recv_fn = smb_full_audit_fsync_recv,
2998 .stat_fn = smb_full_audit_stat,
2999 .fstat_fn = smb_full_audit_fstat,
3000 .lstat_fn = smb_full_audit_lstat,
3001 .get_alloc_size_fn = smb_full_audit_get_alloc_size,
3002 .unlinkat_fn = smb_full_audit_unlinkat,
3003 .chmod_fn = smb_full_audit_chmod,
3004 .fchmod_fn = smb_full_audit_fchmod,
3005 .fchown_fn = smb_full_audit_fchown,
3006 .lchown_fn = smb_full_audit_lchown,
3007 .chdir_fn = smb_full_audit_chdir,
3008 .getwd_fn = smb_full_audit_getwd,
3009 .ntimes_fn = smb_full_audit_ntimes,
3010 .ftruncate_fn = smb_full_audit_ftruncate,
3011 .fallocate_fn = smb_full_audit_fallocate,
3012 .lock_fn = smb_full_audit_lock,
3013 .kernel_flock_fn = smb_full_audit_kernel_flock,
3014 .fcntl_fn = smb_full_audit_fcntl,
3015 .linux_setlease_fn = smb_full_audit_linux_setlease,
3016 .getlock_fn = smb_full_audit_getlock,
3017 .symlinkat_fn = smb_full_audit_symlinkat,
3018 .readlinkat_fn = smb_full_audit_readlinkat,
3019 .linkat_fn = smb_full_audit_linkat,
3020 .mknodat_fn = smb_full_audit_mknodat,
3021 .realpath_fn = smb_full_audit_realpath,
3022 .chflags_fn = smb_full_audit_chflags,
3023 .file_id_create_fn = smb_full_audit_file_id_create,
3024 .fs_file_id_fn = smb_full_audit_fs_file_id,
3025 .offload_read_send_fn = smb_full_audit_offload_read_send,
3026 .offload_read_recv_fn = smb_full_audit_offload_read_recv,
3027 .offload_write_send_fn = smb_full_audit_offload_write_send,
3028 .offload_write_recv_fn = smb_full_audit_offload_write_recv,
3029 .fget_compression_fn = smb_full_audit_fget_compression,
3030 .set_compression_fn = smb_full_audit_set_compression,
3031 .snap_check_path_fn = smb_full_audit_snap_check_path,
3032 .snap_create_fn = smb_full_audit_snap_create,
3033 .snap_delete_fn = smb_full_audit_snap_delete,
3034 .streaminfo_fn = smb_full_audit_streaminfo,
3035 .get_real_filename_fn = smb_full_audit_get_real_filename,
3036 .connectpath_fn = smb_full_audit_connectpath,
3037 .brl_lock_windows_fn = smb_full_audit_brl_lock_windows,
3038 .brl_unlock_windows_fn = smb_full_audit_brl_unlock_windows,
3039 .strict_lock_check_fn = smb_full_audit_strict_lock_check,
3040 .translate_name_fn = smb_full_audit_translate_name,
3041 .fsctl_fn = smb_full_audit_fsctl,
3042 .get_dos_attributes_send_fn = smb_full_audit_get_dos_attributes_send,
3043 .get_dos_attributes_recv_fn = smb_full_audit_get_dos_attributes_recv,
3044 .fget_dos_attributes_fn = smb_full_audit_fget_dos_attributes,
3045 .set_dos_attributes_fn = smb_full_audit_set_dos_attributes,
3046 .fset_dos_attributes_fn = smb_full_audit_fset_dos_attributes,
3047 .fget_nt_acl_fn = smb_full_audit_fget_nt_acl,
3048 .get_nt_acl_at_fn = smb_full_audit_get_nt_acl_at,
3049 .fset_nt_acl_fn = smb_full_audit_fset_nt_acl,
3050 .audit_file_fn = smb_full_audit_audit_file,
3051 .sys_acl_get_file_fn = smb_full_audit_sys_acl_get_file,
3052 .sys_acl_get_fd_fn = smb_full_audit_sys_acl_get_fd,
3053 .sys_acl_blob_get_file_fn = smb_full_audit_sys_acl_blob_get_file,
3054 .sys_acl_blob_get_fd_fn = smb_full_audit_sys_acl_blob_get_fd,
3055 .sys_acl_set_fd_fn = smb_full_audit_sys_acl_set_fd,
3056 .sys_acl_delete_def_file_fn = smb_full_audit_sys_acl_delete_def_file,
3057 .getxattr_fn = smb_full_audit_getxattr,
3058 .getxattrat_send_fn = smb_full_audit_getxattrat_send,
3059 .getxattrat_recv_fn = smb_full_audit_getxattrat_recv,
3060 .fgetxattr_fn = smb_full_audit_fgetxattr,
3061 .listxattr_fn = smb_full_audit_listxattr,
3062 .flistxattr_fn = smb_full_audit_flistxattr,
3063 .removexattr_fn = smb_full_audit_removexattr,
3064 .fremovexattr_fn = smb_full_audit_fremovexattr,
3065 .setxattr_fn = smb_full_audit_setxattr,
3066 .fsetxattr_fn = smb_full_audit_fsetxattr,
3067 .aio_force_fn = smb_full_audit_aio_force,
3068 .durable_cookie_fn = smb_full_audit_durable_cookie,
3069 .durable_disconnect_fn = smb_full_audit_durable_disconnect,
3070 .durable_reconnect_fn = smb_full_audit_durable_reconnect,
3071 .readdir_attr_fn = smb_full_audit_readdir_attr
3076 NTSTATUS vfs_full_audit_init(TALLOC_CTX *ctx)
3080 smb_vfs_assert_all_fns(&vfs_full_audit_fns, "full_audit");
3082 ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "full_audit",
3083 &vfs_full_audit_fns);
3085 if (!NT_STATUS_IS_OK(ret))
3088 vfs_full_audit_debug_level = debug_add_class("full_audit");
3089 if (vfs_full_audit_debug_level == -1) {
3090 vfs_full_audit_debug_level = DBGC_VFS;
3091 DEBUG(0, ("vfs_full_audit: Couldn't register custom debugging "
3094 DEBUG(10, ("vfs_full_audit: Debug class number of "
3095 "'full_audit': %d\n", vfs_full_audit_debug_level));