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_FSTREAMINFO,
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,
173 SMB_VFS_OP_PARENT_PATHNAME,
175 SMB_VFS_OP_OFFLOAD_READ_SEND,
176 SMB_VFS_OP_OFFLOAD_READ_RECV,
177 SMB_VFS_OP_OFFLOAD_WRITE_SEND,
178 SMB_VFS_OP_OFFLOAD_WRITE_RECV,
179 SMB_VFS_OP_FGET_COMPRESSION,
180 SMB_VFS_OP_SET_COMPRESSION,
181 SMB_VFS_OP_SNAP_CHECK_PATH,
182 SMB_VFS_OP_SNAP_CREATE,
183 SMB_VFS_OP_SNAP_DELETE,
185 /* DOS attribute operations. */
186 SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
187 SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV,
188 SMB_VFS_OP_FGET_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_FD,
209 SMB_VFS_OP_GETXATTRAT_SEND,
210 SMB_VFS_OP_GETXATTRAT_RECV,
211 SMB_VFS_OP_FGETXATTR,
212 SMB_VFS_OP_FLISTXATTR,
213 SMB_VFS_OP_REMOVEXATTR,
214 SMB_VFS_OP_FREMOVEXATTR,
215 SMB_VFS_OP_FSETXATTR,
218 SMB_VFS_OP_AIO_FORCE,
220 /* offline operations */
221 SMB_VFS_OP_IS_OFFLINE,
222 SMB_VFS_OP_SET_OFFLINE,
224 /* Durable handle operations. */
225 SMB_VFS_OP_DURABLE_COOKIE,
226 SMB_VFS_OP_DURABLE_DISCONNECT,
227 SMB_VFS_OP_DURABLE_RECONNECT,
229 SMB_VFS_OP_FREADDIR_ATTR,
231 /* This should always be last enum value */
236 /* The following array *must* be in the same order as defined in vfs_op_type */
242 { SMB_VFS_OP_CONNECT, "connect" },
243 { SMB_VFS_OP_DISCONNECT, "disconnect" },
244 { SMB_VFS_OP_DISK_FREE, "disk_free" },
245 { SMB_VFS_OP_GET_QUOTA, "get_quota" },
246 { SMB_VFS_OP_SET_QUOTA, "set_quota" },
247 { SMB_VFS_OP_GET_SHADOW_COPY_DATA, "get_shadow_copy_data" },
248 { SMB_VFS_OP_STATVFS, "statvfs" },
249 { SMB_VFS_OP_FS_CAPABILITIES, "fs_capabilities" },
250 { SMB_VFS_OP_GET_DFS_REFERRALS, "get_dfs_referrals" },
251 { SMB_VFS_OP_CREATE_DFS_PATHAT, "create_dfs_pathat" },
252 { SMB_VFS_OP_READ_DFS_PATHAT, "read_dfs_pathat" },
253 { SMB_VFS_OP_FDOPENDIR, "fdopendir" },
254 { SMB_VFS_OP_READDIR, "readdir" },
255 { SMB_VFS_OP_SEEKDIR, "seekdir" },
256 { SMB_VFS_OP_TELLDIR, "telldir" },
257 { SMB_VFS_OP_REWINDDIR, "rewinddir" },
258 { SMB_VFS_OP_MKDIRAT, "mkdirat" },
259 { SMB_VFS_OP_CLOSEDIR, "closedir" },
260 { SMB_VFS_OP_OPEN, "open" },
261 { SMB_VFS_OP_OPENAT, "openat" },
262 { SMB_VFS_OP_CREATE_FILE, "create_file" },
263 { SMB_VFS_OP_CLOSE, "close" },
264 { SMB_VFS_OP_READ, "read" },
265 { SMB_VFS_OP_PREAD, "pread" },
266 { SMB_VFS_OP_PREAD_SEND, "pread_send" },
267 { SMB_VFS_OP_PREAD_RECV, "pread_recv" },
268 { SMB_VFS_OP_WRITE, "write" },
269 { SMB_VFS_OP_PWRITE, "pwrite" },
270 { SMB_VFS_OP_PWRITE_SEND, "pwrite_send" },
271 { SMB_VFS_OP_PWRITE_RECV, "pwrite_recv" },
272 { SMB_VFS_OP_LSEEK, "lseek" },
273 { SMB_VFS_OP_SENDFILE, "sendfile" },
274 { SMB_VFS_OP_RECVFILE, "recvfile" },
275 { SMB_VFS_OP_RENAMEAT, "renameat" },
276 { SMB_VFS_OP_FSYNC, "fsync" },
277 { SMB_VFS_OP_FSYNC_SEND, "fsync_send" },
278 { SMB_VFS_OP_FSYNC_RECV, "fsync_recv" },
279 { SMB_VFS_OP_STAT, "stat" },
280 { SMB_VFS_OP_FSTAT, "fstat" },
281 { SMB_VFS_OP_LSTAT, "lstat" },
282 { SMB_VFS_OP_GET_ALLOC_SIZE, "get_alloc_size" },
283 { SMB_VFS_OP_UNLINKAT, "unlinkat" },
284 { SMB_VFS_OP_FCHMOD, "fchmod" },
285 { SMB_VFS_OP_FCHOWN, "fchown" },
286 { SMB_VFS_OP_LCHOWN, "lchown" },
287 { SMB_VFS_OP_CHDIR, "chdir" },
288 { SMB_VFS_OP_GETWD, "getwd" },
289 { SMB_VFS_OP_NTIMES, "ntimes" },
290 { SMB_VFS_OP_FNTIMES, "fntimes" },
291 { SMB_VFS_OP_FTRUNCATE, "ftruncate" },
292 { SMB_VFS_OP_FALLOCATE,"fallocate" },
293 { SMB_VFS_OP_LOCK, "lock" },
294 { SMB_VFS_OP_KERNEL_FLOCK, "kernel_flock" },
295 { SMB_VFS_OP_FCNTL, "fcntl" },
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_FSTREAMINFO, "fstreaminfo" },
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_PARENT_PATHNAME, "parent_pathname" },
314 { SMB_VFS_OP_FSCTL, "fsctl" },
315 { SMB_VFS_OP_OFFLOAD_READ_SEND, "offload_read_send" },
316 { SMB_VFS_OP_OFFLOAD_READ_RECV, "offload_read_recv" },
317 { SMB_VFS_OP_OFFLOAD_WRITE_SEND, "offload_write_send" },
318 { SMB_VFS_OP_OFFLOAD_WRITE_RECV, "offload_write_recv" },
319 { SMB_VFS_OP_FGET_COMPRESSION, "fget_compression" },
320 { SMB_VFS_OP_SET_COMPRESSION, "set_compression" },
321 { SMB_VFS_OP_SNAP_CHECK_PATH, "snap_check_path" },
322 { SMB_VFS_OP_SNAP_CREATE, "snap_create" },
323 { SMB_VFS_OP_SNAP_DELETE, "snap_delete" },
324 { SMB_VFS_OP_GET_DOS_ATTRIBUTES_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_FSET_DOS_ATTRIBUTES, "fset_dos_attributes" },
328 { SMB_VFS_OP_FGET_NT_ACL, "fget_nt_acl" },
329 { SMB_VFS_OP_GET_NT_ACL_AT, "get_nt_acl_at" },
330 { SMB_VFS_OP_FSET_NT_ACL, "fset_nt_acl" },
331 { SMB_VFS_OP_AUDIT_FILE, "audit_file" },
332 { SMB_VFS_OP_SYS_ACL_GET_FILE, "sys_acl_get_file" },
333 { SMB_VFS_OP_SYS_ACL_GET_FD, "sys_acl_get_fd" },
334 { SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE, "sys_acl_blob_get_file" },
335 { SMB_VFS_OP_SYS_ACL_BLOB_GET_FD, "sys_acl_blob_get_fd" },
336 { SMB_VFS_OP_SYS_ACL_SET_FD, "sys_acl_set_fd" },
337 { SMB_VFS_OP_SYS_ACL_DELETE_DEF_FD, "sys_acl_delete_def_fd" },
338 { SMB_VFS_OP_GETXATTR, "getxattr" },
339 { SMB_VFS_OP_GETXATTRAT_SEND, "getxattrat_send" },
340 { SMB_VFS_OP_GETXATTRAT_RECV, "getxattrat_recv" },
341 { SMB_VFS_OP_FGETXATTR, "fgetxattr" },
342 { SMB_VFS_OP_FLISTXATTR, "flistxattr" },
343 { SMB_VFS_OP_REMOVEXATTR, "removexattr" },
344 { SMB_VFS_OP_FREMOVEXATTR, "fremovexattr" },
345 { SMB_VFS_OP_FSETXATTR, "fsetxattr" },
346 { SMB_VFS_OP_AIO_FORCE, "aio_force" },
347 { SMB_VFS_OP_IS_OFFLINE, "is_offline" },
348 { SMB_VFS_OP_SET_OFFLINE, "set_offline" },
349 { SMB_VFS_OP_DURABLE_COOKIE, "durable_cookie" },
350 { SMB_VFS_OP_DURABLE_DISCONNECT, "durable_disconnect" },
351 { SMB_VFS_OP_DURABLE_RECONNECT, "durable_reconnect" },
352 { SMB_VFS_OP_FREADDIR_ATTR, "freaddir_attr" },
353 { SMB_VFS_OP_LAST, NULL }
356 static int audit_syslog_facility(vfs_handle_struct *handle)
358 static const struct enum_list enum_log_facilities[] = {
360 { LOG_AUTH, "AUTH" },
363 { LOG_AUTHPRIV, "AUTHPRIV" },
366 { LOG_AUDIT, "AUDIT" },
369 { LOG_CONSOLE, "CONSOLE" },
372 { LOG_CRON, "CRON" },
375 { LOG_DAEMON, "DAEMON" },
381 { LOG_INSTALL, "INSTALL" },
384 { LOG_KERN, "KERN" },
387 { LOG_LAUNCHD, "LAUNCHD" },
390 { LOG_LFMT, "LFMT" },
396 { LOG_MAIL, "MAIL" },
399 { LOG_MEGASAFE, "MEGASAFE" },
402 { LOG_NETINFO, "NETINFO" },
405 { LOG_NEWS, "NEWS" },
407 #ifdef LOG_NFACILITIES
408 { LOG_NFACILITIES, "NFACILITIES" },
416 #ifdef LOG_REMOTEAUTH
417 { LOG_REMOTEAUTH, "REMOTEAUTH" },
420 { LOG_SECURITY, "SECURITY" },
423 { LOG_SYSLOG, "SYSLOG" },
426 { LOG_USER, "USER" },
429 { LOG_UUCP, "UUCP" },
431 { LOG_LOCAL0, "LOCAL0" },
432 { LOG_LOCAL1, "LOCAL1" },
433 { LOG_LOCAL2, "LOCAL2" },
434 { LOG_LOCAL3, "LOCAL3" },
435 { LOG_LOCAL4, "LOCAL4" },
436 { LOG_LOCAL5, "LOCAL5" },
437 { LOG_LOCAL6, "LOCAL6" },
438 { LOG_LOCAL7, "LOCAL7" },
444 facility = lp_parm_enum(SNUM(handle->conn), "full_audit", "facility", enum_log_facilities, LOG_USER);
449 static int audit_syslog_priority(vfs_handle_struct *handle)
451 static const struct enum_list enum_log_priorities[] = {
452 { LOG_EMERG, "EMERG" },
453 { LOG_ALERT, "ALERT" },
454 { LOG_CRIT, "CRIT" },
456 { LOG_WARNING, "WARNING" },
457 { LOG_NOTICE, "NOTICE" },
458 { LOG_INFO, "INFO" },
459 { LOG_DEBUG, "DEBUG" },
465 priority = lp_parm_enum(SNUM(handle->conn), "full_audit", "priority",
466 enum_log_priorities, LOG_NOTICE);
467 if (priority == -1) {
468 priority = LOG_WARNING;
474 static char *audit_prefix(TALLOC_CTX *ctx, connection_struct *conn)
476 const struct loadparm_substitution *lp_sub =
477 loadparm_s3_global_substitution();
481 prefix = talloc_strdup(ctx,
482 lp_parm_const_string(SNUM(conn), "full_audit",
487 result = talloc_sub_full(ctx,
488 lp_servicename(talloc_tos(), lp_sub, SNUM(conn)),
489 conn->session_info->unix_info->unix_name,
491 conn->session_info->unix_token->gid,
492 conn->session_info->unix_info->sanitized_username,
493 conn->session_info->info->domain_name,
499 static bool log_success(struct vfs_full_audit_private_data *pd, vfs_op_type op)
501 if (pd->success_ops == NULL) {
505 return bitmap_query(pd->success_ops, op);
508 static bool log_failure(struct vfs_full_audit_private_data *pd, vfs_op_type op)
510 if (pd->failure_ops == NULL)
513 return bitmap_query(pd->failure_ops, op);
516 static struct bitmap *init_bitmap(TALLOC_CTX *mem_ctx, const char **ops)
524 bm = bitmap_talloc(mem_ctx, SMB_VFS_OP_LAST);
526 DEBUG(0, ("Could not alloc bitmap -- "
527 "defaulting to logging everything\n"));
531 for (; *ops != NULL; ops += 1) {
536 if (strequal(*ops, "all")) {
537 for (i=0; i<SMB_VFS_OP_LAST; i++) {
543 if (strequal(*ops, "none")) {
553 for (i=0; i<SMB_VFS_OP_LAST; i++) {
554 if ((vfs_op_names[i].name == NULL)
555 || (vfs_op_names[i].type != i)) {
556 smb_panic("vfs_full_audit.c: name table not "
557 "in sync with vfs_op_type enums\n");
559 if (strequal(op, vfs_op_names[i].name)) {
568 if (i == SMB_VFS_OP_LAST) {
569 DEBUG(0, ("Could not find opname %s, logging all\n",
578 static const char *audit_opname(vfs_op_type op)
580 if (op >= SMB_VFS_OP_LAST)
581 return "INVALID VFS OP";
582 return vfs_op_names[op].name;
585 static TALLOC_CTX *tmp_do_log_ctx;
587 * Get us a temporary talloc context usable just for DEBUG arguments
589 static TALLOC_CTX *do_log_ctx(void)
591 if (tmp_do_log_ctx == NULL) {
592 tmp_do_log_ctx = talloc_named_const(NULL, 0, "do_log_ctx");
594 return tmp_do_log_ctx;
597 static void do_log(vfs_op_type op, bool success, vfs_handle_struct *handle,
598 const char *format, ...) PRINTF_ATTRIBUTE(4, 5);
600 static void do_log(vfs_op_type op, bool success, vfs_handle_struct *handle,
601 const char *format, ...)
603 struct vfs_full_audit_private_data *pd;
605 char *audit_pre = NULL;
609 SMB_VFS_HANDLE_GET_DATA(handle, pd,
610 struct vfs_full_audit_private_data,
613 if (success && (!log_success(pd, op)))
616 if (!success && (!log_failure(pd, op)))
620 fstrcpy(err_msg, "ok");
622 fstr_sprintf(err_msg, "fail (%s)", strerror(errno));
624 va_start(ap, format);
625 op_msg = talloc_vasprintf(talloc_tos(), format, ap);
632 audit_pre = audit_prefix(talloc_tos(), handle->conn);
638 * Specify the facility to interoperate with other syslog
639 * callers (smbd for example).
641 priority = pd->syslog_priority | pd->syslog_facility;
643 syslog(priority, "%s|%s|%s|%s\n",
644 audit_pre ? audit_pre : "",
645 audit_opname(op), err_msg, op_msg);
647 DEBUG(1, ("%s|%s|%s|%s\n",
648 audit_pre ? audit_pre : "",
649 audit_opname(op), err_msg, op_msg));
652 TALLOC_FREE(audit_pre);
654 TALLOC_FREE(tmp_do_log_ctx);
658 * Return a string using the do_log_ctx()
660 static const char *smb_fname_str_do_log(struct connection_struct *conn,
661 const struct smb_filename *smb_fname)
666 if (smb_fname == NULL) {
670 if (smb_fname->base_name[0] != '/') {
671 char *abs_name = NULL;
672 struct smb_filename *fname_copy = cp_smb_filename(
675 if (fname_copy == NULL) {
679 if (!ISDOT(smb_fname->base_name)) {
680 abs_name = talloc_asprintf(do_log_ctx(),
682 conn->cwd_fsp->fsp_name->base_name,
683 smb_fname->base_name);
685 abs_name = talloc_strdup(do_log_ctx(),
686 conn->cwd_fsp->fsp_name->base_name);
688 if (abs_name == NULL) {
691 fname_copy->base_name = abs_name;
692 smb_fname = fname_copy;
695 status = get_full_smb_filename(do_log_ctx(), smb_fname, &fname);
696 if (!NT_STATUS_IS_OK(status)) {
703 * Return an fsp debug string using the do_log_ctx()
705 static const char *fsp_str_do_log(const struct files_struct *fsp)
707 return smb_fname_str_do_log(fsp->conn, fsp->fsp_name);
710 /* Implementation of vfs_ops. Pass everything on to the default
711 operation but log event first. */
713 static int smb_full_audit_connect(vfs_handle_struct *handle,
714 const char *svc, const char *user)
717 const char *none[] = { "none" };
718 struct vfs_full_audit_private_data *pd = NULL;
720 result = SMB_VFS_NEXT_CONNECT(handle, svc, user);
725 pd = talloc_zero(handle, struct vfs_full_audit_private_data);
727 SMB_VFS_NEXT_DISCONNECT(handle);
731 pd->syslog_facility = audit_syslog_facility(handle);
732 if (pd->syslog_facility == -1) {
733 DEBUG(1, ("%s: Unknown facility %s\n", __func__,
734 lp_parm_const_string(SNUM(handle->conn),
735 "full_audit", "facility",
737 SMB_VFS_NEXT_DISCONNECT(handle);
741 pd->syslog_priority = audit_syslog_priority(handle);
743 pd->log_secdesc = lp_parm_bool(SNUM(handle->conn),
744 "full_audit", "log_secdesc", false);
746 pd->do_syslog = lp_parm_bool(SNUM(handle->conn),
747 "full_audit", "syslog", true);
751 openlog("smbd_audit", 0, pd->syslog_facility);
755 pd->success_ops = init_bitmap(
756 pd, lp_parm_string_list(SNUM(handle->conn), "full_audit",
758 pd->failure_ops = init_bitmap(
759 pd, lp_parm_string_list(SNUM(handle->conn), "full_audit",
762 /* Store the private data. */
763 SMB_VFS_HANDLE_SET_DATA(handle, pd, NULL,
764 struct vfs_full_audit_private_data, return -1);
766 do_log(SMB_VFS_OP_CONNECT, True, handle,
772 static void smb_full_audit_disconnect(vfs_handle_struct *handle)
774 const struct loadparm_substitution *lp_sub =
775 loadparm_s3_global_substitution();
777 SMB_VFS_NEXT_DISCONNECT(handle);
779 do_log(SMB_VFS_OP_DISCONNECT, True, handle,
780 "%s", lp_servicename(talloc_tos(), lp_sub, SNUM(handle->conn)));
782 /* The bitmaps will be disconnected when the private
786 static uint64_t smb_full_audit_disk_free(vfs_handle_struct *handle,
787 const struct smb_filename *smb_fname,
794 result = SMB_VFS_NEXT_DISK_FREE(handle, smb_fname, bsize, dfree, dsize);
796 /* Don't have a reasonable notion of failure here */
798 do_log(SMB_VFS_OP_DISK_FREE,
802 smb_fname_str_do_log(handle->conn, smb_fname));
807 static int smb_full_audit_get_quota(struct vfs_handle_struct *handle,
808 const struct smb_filename *smb_fname,
809 enum SMB_QUOTA_TYPE qtype,
815 result = SMB_VFS_NEXT_GET_QUOTA(handle, smb_fname, qtype, id, qt);
817 do_log(SMB_VFS_OP_GET_QUOTA,
821 smb_fname_str_do_log(handle->conn, smb_fname));
826 static int smb_full_audit_set_quota(struct vfs_handle_struct *handle,
827 enum SMB_QUOTA_TYPE qtype, unid_t id,
832 result = SMB_VFS_NEXT_SET_QUOTA(handle, qtype, id, qt);
834 do_log(SMB_VFS_OP_SET_QUOTA, (result >= 0), handle, "");
839 static int smb_full_audit_get_shadow_copy_data(struct vfs_handle_struct *handle,
840 struct files_struct *fsp,
841 struct shadow_copy_data *shadow_copy_data,
846 result = SMB_VFS_NEXT_GET_SHADOW_COPY_DATA(handle, fsp, shadow_copy_data, labels);
848 do_log(SMB_VFS_OP_GET_SHADOW_COPY_DATA, (result >= 0), handle, "");
853 static int smb_full_audit_statvfs(struct vfs_handle_struct *handle,
854 const struct smb_filename *smb_fname,
855 struct vfs_statvfs_struct *statbuf)
859 result = SMB_VFS_NEXT_STATVFS(handle, smb_fname, statbuf);
861 do_log(SMB_VFS_OP_STATVFS, (result >= 0), handle, "");
866 static uint32_t smb_full_audit_fs_capabilities(struct vfs_handle_struct *handle, enum timestamp_set_resolution *p_ts_res)
870 result = SMB_VFS_NEXT_FS_CAPABILITIES(handle, p_ts_res);
872 do_log(SMB_VFS_OP_FS_CAPABILITIES, true, handle, "");
877 static NTSTATUS smb_full_audit_get_dfs_referrals(
878 struct vfs_handle_struct *handle,
879 struct dfs_GetDFSReferral *r)
883 status = SMB_VFS_NEXT_GET_DFS_REFERRALS(handle, r);
885 do_log(SMB_VFS_OP_GET_DFS_REFERRALS, NT_STATUS_IS_OK(status),
891 static NTSTATUS smb_full_audit_create_dfs_pathat(struct vfs_handle_struct *handle,
892 struct files_struct *dirfsp,
893 const struct smb_filename *smb_fname,
894 const struct referral *reflist,
895 size_t referral_count)
898 struct smb_filename *full_fname = NULL;
900 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
903 if (full_fname == NULL) {
904 return NT_STATUS_NO_MEMORY;
907 status = SMB_VFS_NEXT_CREATE_DFS_PATHAT(handle,
913 do_log(SMB_VFS_OP_CREATE_DFS_PATHAT,
914 NT_STATUS_IS_OK(status),
917 smb_fname_str_do_log(handle->conn, full_fname));
919 TALLOC_FREE(full_fname);
923 static NTSTATUS smb_full_audit_read_dfs_pathat(struct vfs_handle_struct *handle,
925 struct files_struct *dirfsp,
926 struct smb_filename *smb_fname,
927 struct referral **ppreflist,
928 size_t *preferral_count)
932 status = SMB_VFS_NEXT_READ_DFS_PATHAT(handle,
939 do_log(SMB_VFS_OP_READ_DFS_PATHAT,
940 NT_STATUS_IS_OK(status),
943 smb_fname_str_do_log(handle->conn, smb_fname));
948 static NTSTATUS smb_full_audit_snap_check_path(struct vfs_handle_struct *handle,
950 const char *service_path,
955 status = SMB_VFS_NEXT_SNAP_CHECK_PATH(handle, mem_ctx, service_path,
957 do_log(SMB_VFS_OP_SNAP_CHECK_PATH, NT_STATUS_IS_OK(status),
963 static NTSTATUS smb_full_audit_snap_create(struct vfs_handle_struct *handle,
965 const char *base_volume,
973 status = SMB_VFS_NEXT_SNAP_CREATE(handle, mem_ctx, base_volume, tstamp,
974 rw, base_path, snap_path);
975 do_log(SMB_VFS_OP_SNAP_CREATE, NT_STATUS_IS_OK(status), handle, "");
980 static NTSTATUS smb_full_audit_snap_delete(struct vfs_handle_struct *handle,
987 status = SMB_VFS_NEXT_SNAP_DELETE(handle, mem_ctx, base_path,
989 do_log(SMB_VFS_OP_SNAP_DELETE, NT_STATUS_IS_OK(status), handle, "");
994 static DIR *smb_full_audit_fdopendir(vfs_handle_struct *handle,
995 files_struct *fsp, const char *mask, uint32_t attr)
999 result = SMB_VFS_NEXT_FDOPENDIR(handle, fsp, mask, attr);
1001 do_log(SMB_VFS_OP_FDOPENDIR, (result != NULL), handle, "%s",
1002 fsp_str_do_log(fsp));
1007 static struct dirent *smb_full_audit_readdir(vfs_handle_struct *handle,
1008 struct files_struct *dirfsp,
1010 SMB_STRUCT_STAT *sbuf)
1012 struct dirent *result;
1014 result = SMB_VFS_NEXT_READDIR(handle, dirfsp, dirp, sbuf);
1016 /* This operation has no reasonable error condition
1017 * (End of dir is also failure), so always succeed.
1019 do_log(SMB_VFS_OP_READDIR, True, handle, "");
1024 static void smb_full_audit_seekdir(vfs_handle_struct *handle,
1025 DIR *dirp, long offset)
1027 SMB_VFS_NEXT_SEEKDIR(handle, dirp, offset);
1029 do_log(SMB_VFS_OP_SEEKDIR, True, handle, "");
1032 static long smb_full_audit_telldir(vfs_handle_struct *handle,
1037 result = SMB_VFS_NEXT_TELLDIR(handle, dirp);
1039 do_log(SMB_VFS_OP_TELLDIR, True, handle, "");
1044 static void smb_full_audit_rewinddir(vfs_handle_struct *handle,
1047 SMB_VFS_NEXT_REWINDDIR(handle, dirp);
1049 do_log(SMB_VFS_OP_REWINDDIR, True, handle, "");
1052 static int smb_full_audit_mkdirat(vfs_handle_struct *handle,
1053 struct files_struct *dirfsp,
1054 const struct smb_filename *smb_fname,
1057 struct smb_filename *full_fname = NULL;
1060 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1063 if (full_fname == NULL) {
1068 result = SMB_VFS_NEXT_MKDIRAT(handle,
1073 do_log(SMB_VFS_OP_MKDIRAT,
1077 smb_fname_str_do_log(handle->conn, full_fname));
1079 TALLOC_FREE(full_fname);
1084 static int smb_full_audit_closedir(vfs_handle_struct *handle,
1089 result = SMB_VFS_NEXT_CLOSEDIR(handle, dirp);
1091 do_log(SMB_VFS_OP_CLOSEDIR, (result >= 0), handle, "");
1096 static int smb_full_audit_openat(vfs_handle_struct *handle,
1097 const struct files_struct *dirfsp,
1098 const struct smb_filename *smb_fname,
1099 struct files_struct *fsp,
1105 result = SMB_VFS_NEXT_OPENAT(handle, dirfsp, smb_fname, fsp, flags, mode);
1107 do_log(SMB_VFS_OP_OPENAT, (result >= 0), handle, "%s|%s",
1108 ((flags & O_WRONLY) || (flags & O_RDWR))?"w":"r",
1109 fsp_str_do_log(fsp));
1114 static NTSTATUS smb_full_audit_create_file(vfs_handle_struct *handle,
1115 struct smb_request *req,
1116 struct smb_filename *smb_fname,
1117 uint32_t access_mask,
1118 uint32_t share_access,
1119 uint32_t create_disposition,
1120 uint32_t create_options,
1121 uint32_t file_attributes,
1122 uint32_t oplock_request,
1123 const struct smb2_lease *lease,
1124 uint64_t allocation_size,
1125 uint32_t private_flags,
1126 struct security_descriptor *sd,
1127 struct ea_list *ea_list,
1128 files_struct **result_fsp,
1130 const struct smb2_create_blobs *in_context_blobs,
1131 struct smb2_create_blobs *out_context_blobs)
1134 const char* str_create_disposition;
1136 switch (create_disposition) {
1137 case FILE_SUPERSEDE:
1138 str_create_disposition = "supersede";
1140 case FILE_OVERWRITE_IF:
1141 str_create_disposition = "overwrite_if";
1144 str_create_disposition = "open";
1146 case FILE_OVERWRITE:
1147 str_create_disposition = "overwrite";
1150 str_create_disposition = "create";
1153 str_create_disposition = "open_if";
1156 str_create_disposition = "unknown";
1159 result = SMB_VFS_NEXT_CREATE_FILE(
1160 handle, /* handle */
1162 smb_fname, /* fname */
1163 access_mask, /* access_mask */
1164 share_access, /* share_access */
1165 create_disposition, /* create_disposition*/
1166 create_options, /* create_options */
1167 file_attributes, /* file_attributes */
1168 oplock_request, /* oplock_request */
1170 allocation_size, /* allocation_size */
1173 ea_list, /* ea_list */
1174 result_fsp, /* result */
1176 in_context_blobs, out_context_blobs); /* create context */
1178 do_log(SMB_VFS_OP_CREATE_FILE, (NT_STATUS_IS_OK(result)), handle,
1179 "0x%x|%s|%s|%s", access_mask,
1180 create_options & FILE_DIRECTORY_FILE ? "dir" : "file",
1181 str_create_disposition,
1182 smb_fname_str_do_log(handle->conn, smb_fname));
1187 static int smb_full_audit_close(vfs_handle_struct *handle, files_struct *fsp)
1191 result = SMB_VFS_NEXT_CLOSE(handle, fsp);
1193 do_log(SMB_VFS_OP_CLOSE, (result >= 0), handle, "%s",
1194 fsp_str_do_log(fsp));
1199 static ssize_t smb_full_audit_pread(vfs_handle_struct *handle, files_struct *fsp,
1200 void *data, size_t n, off_t offset)
1204 result = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
1206 do_log(SMB_VFS_OP_PREAD, (result >= 0), handle, "%s",
1207 fsp_str_do_log(fsp));
1212 struct smb_full_audit_pread_state {
1213 vfs_handle_struct *handle;
1216 struct vfs_aio_state vfs_aio_state;
1219 static void smb_full_audit_pread_done(struct tevent_req *subreq);
1221 static struct tevent_req *smb_full_audit_pread_send(
1222 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1223 struct tevent_context *ev, struct files_struct *fsp,
1224 void *data, size_t n, off_t offset)
1226 struct tevent_req *req, *subreq;
1227 struct smb_full_audit_pread_state *state;
1229 req = tevent_req_create(mem_ctx, &state,
1230 struct smb_full_audit_pread_state);
1232 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
1233 fsp_str_do_log(fsp));
1236 state->handle = handle;
1239 subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
1241 if (tevent_req_nomem(subreq, req)) {
1242 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
1243 fsp_str_do_log(fsp));
1244 return tevent_req_post(req, ev);
1246 tevent_req_set_callback(subreq, smb_full_audit_pread_done, req);
1248 do_log(SMB_VFS_OP_PREAD_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1252 static void smb_full_audit_pread_done(struct tevent_req *subreq)
1254 struct tevent_req *req = tevent_req_callback_data(
1255 subreq, struct tevent_req);
1256 struct smb_full_audit_pread_state *state = tevent_req_data(
1257 req, struct smb_full_audit_pread_state);
1259 state->ret = SMB_VFS_PREAD_RECV(subreq, &state->vfs_aio_state);
1260 TALLOC_FREE(subreq);
1261 tevent_req_done(req);
1264 static ssize_t smb_full_audit_pread_recv(struct tevent_req *req,
1265 struct vfs_aio_state *vfs_aio_state)
1267 struct smb_full_audit_pread_state *state = tevent_req_data(
1268 req, struct smb_full_audit_pread_state);
1270 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1271 do_log(SMB_VFS_OP_PREAD_RECV, false, state->handle, "%s",
1272 fsp_str_do_log(state->fsp));
1276 do_log(SMB_VFS_OP_PREAD_RECV, (state->ret >= 0), state->handle, "%s",
1277 fsp_str_do_log(state->fsp));
1279 *vfs_aio_state = state->vfs_aio_state;
1283 static ssize_t smb_full_audit_pwrite(vfs_handle_struct *handle, files_struct *fsp,
1284 const void *data, size_t n,
1289 result = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
1291 do_log(SMB_VFS_OP_PWRITE, (result >= 0), handle, "%s",
1292 fsp_str_do_log(fsp));
1297 struct smb_full_audit_pwrite_state {
1298 vfs_handle_struct *handle;
1301 struct vfs_aio_state vfs_aio_state;
1304 static void smb_full_audit_pwrite_done(struct tevent_req *subreq);
1306 static struct tevent_req *smb_full_audit_pwrite_send(
1307 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1308 struct tevent_context *ev, struct files_struct *fsp,
1309 const void *data, size_t n, off_t offset)
1311 struct tevent_req *req, *subreq;
1312 struct smb_full_audit_pwrite_state *state;
1314 req = tevent_req_create(mem_ctx, &state,
1315 struct smb_full_audit_pwrite_state);
1317 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1318 fsp_str_do_log(fsp));
1321 state->handle = handle;
1324 subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
1326 if (tevent_req_nomem(subreq, req)) {
1327 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1328 fsp_str_do_log(fsp));
1329 return tevent_req_post(req, ev);
1331 tevent_req_set_callback(subreq, smb_full_audit_pwrite_done, req);
1333 do_log(SMB_VFS_OP_PWRITE_SEND, true, handle, "%s",
1334 fsp_str_do_log(fsp));
1338 static void smb_full_audit_pwrite_done(struct tevent_req *subreq)
1340 struct tevent_req *req = tevent_req_callback_data(
1341 subreq, struct tevent_req);
1342 struct smb_full_audit_pwrite_state *state = tevent_req_data(
1343 req, struct smb_full_audit_pwrite_state);
1345 state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->vfs_aio_state);
1346 TALLOC_FREE(subreq);
1347 tevent_req_done(req);
1350 static ssize_t smb_full_audit_pwrite_recv(struct tevent_req *req,
1351 struct vfs_aio_state *vfs_aio_state)
1353 struct smb_full_audit_pwrite_state *state = tevent_req_data(
1354 req, struct smb_full_audit_pwrite_state);
1356 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1357 do_log(SMB_VFS_OP_PWRITE_RECV, false, state->handle, "%s",
1358 fsp_str_do_log(state->fsp));
1362 do_log(SMB_VFS_OP_PWRITE_RECV, (state->ret >= 0), state->handle, "%s",
1363 fsp_str_do_log(state->fsp));
1365 *vfs_aio_state = state->vfs_aio_state;
1369 static off_t smb_full_audit_lseek(vfs_handle_struct *handle, files_struct *fsp,
1370 off_t offset, int whence)
1374 result = SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence);
1376 do_log(SMB_VFS_OP_LSEEK, (result != (ssize_t)-1), handle,
1377 "%s", fsp_str_do_log(fsp));
1382 static ssize_t smb_full_audit_sendfile(vfs_handle_struct *handle, int tofd,
1383 files_struct *fromfsp,
1384 const DATA_BLOB *hdr, off_t offset,
1389 result = SMB_VFS_NEXT_SENDFILE(handle, tofd, fromfsp, hdr, offset, n);
1391 do_log(SMB_VFS_OP_SENDFILE, (result >= 0), handle,
1392 "%s", fsp_str_do_log(fromfsp));
1397 static ssize_t smb_full_audit_recvfile(vfs_handle_struct *handle, int fromfd,
1398 files_struct *tofsp,
1404 result = SMB_VFS_NEXT_RECVFILE(handle, fromfd, tofsp, offset, n);
1406 do_log(SMB_VFS_OP_RECVFILE, (result >= 0), handle,
1407 "%s", fsp_str_do_log(tofsp));
1412 static int smb_full_audit_renameat(vfs_handle_struct *handle,
1413 files_struct *srcfsp,
1414 const struct smb_filename *smb_fname_src,
1415 files_struct *dstfsp,
1416 const struct smb_filename *smb_fname_dst)
1420 result = SMB_VFS_NEXT_RENAMEAT(handle,
1426 do_log(SMB_VFS_OP_RENAMEAT, (result >= 0), handle, "%s|%s",
1427 smb_fname_str_do_log(handle->conn, smb_fname_src),
1428 smb_fname_str_do_log(handle->conn, smb_fname_dst));
1433 struct smb_full_audit_fsync_state {
1434 vfs_handle_struct *handle;
1437 struct vfs_aio_state vfs_aio_state;
1440 static void smb_full_audit_fsync_done(struct tevent_req *subreq);
1442 static struct tevent_req *smb_full_audit_fsync_send(
1443 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1444 struct tevent_context *ev, struct files_struct *fsp)
1446 struct tevent_req *req, *subreq;
1447 struct smb_full_audit_fsync_state *state;
1449 req = tevent_req_create(mem_ctx, &state,
1450 struct smb_full_audit_fsync_state);
1452 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1453 fsp_str_do_log(fsp));
1456 state->handle = handle;
1459 subreq = SMB_VFS_NEXT_FSYNC_SEND(state, ev, handle, fsp);
1460 if (tevent_req_nomem(subreq, req)) {
1461 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1462 fsp_str_do_log(fsp));
1463 return tevent_req_post(req, ev);
1465 tevent_req_set_callback(subreq, smb_full_audit_fsync_done, req);
1467 do_log(SMB_VFS_OP_FSYNC_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1471 static void smb_full_audit_fsync_done(struct tevent_req *subreq)
1473 struct tevent_req *req = tevent_req_callback_data(
1474 subreq, struct tevent_req);
1475 struct smb_full_audit_fsync_state *state = tevent_req_data(
1476 req, struct smb_full_audit_fsync_state);
1478 state->ret = SMB_VFS_FSYNC_RECV(subreq, &state->vfs_aio_state);
1479 TALLOC_FREE(subreq);
1480 tevent_req_done(req);
1483 static int smb_full_audit_fsync_recv(struct tevent_req *req,
1484 struct vfs_aio_state *vfs_aio_state)
1486 struct smb_full_audit_fsync_state *state = tevent_req_data(
1487 req, struct smb_full_audit_fsync_state);
1489 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1490 do_log(SMB_VFS_OP_FSYNC_RECV, false, state->handle, "%s",
1491 fsp_str_do_log(state->fsp));
1495 do_log(SMB_VFS_OP_FSYNC_RECV, (state->ret >= 0), state->handle, "%s",
1496 fsp_str_do_log(state->fsp));
1498 *vfs_aio_state = state->vfs_aio_state;
1502 static int smb_full_audit_stat(vfs_handle_struct *handle,
1503 struct smb_filename *smb_fname)
1507 result = SMB_VFS_NEXT_STAT(handle, smb_fname);
1509 do_log(SMB_VFS_OP_STAT, (result >= 0), handle, "%s",
1510 smb_fname_str_do_log(handle->conn, smb_fname));
1515 static int smb_full_audit_fstat(vfs_handle_struct *handle, files_struct *fsp,
1516 SMB_STRUCT_STAT *sbuf)
1520 result = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1522 do_log(SMB_VFS_OP_FSTAT, (result >= 0), handle, "%s",
1523 fsp_str_do_log(fsp));
1528 static int smb_full_audit_lstat(vfs_handle_struct *handle,
1529 struct smb_filename *smb_fname)
1533 result = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
1535 do_log(SMB_VFS_OP_LSTAT, (result >= 0), handle, "%s",
1536 smb_fname_str_do_log(handle->conn, smb_fname));
1541 static uint64_t smb_full_audit_get_alloc_size(vfs_handle_struct *handle,
1542 files_struct *fsp, const SMB_STRUCT_STAT *sbuf)
1546 result = SMB_VFS_NEXT_GET_ALLOC_SIZE(handle, fsp, sbuf);
1548 do_log(SMB_VFS_OP_GET_ALLOC_SIZE, (result != (uint64_t)-1), handle,
1549 "%llu", (unsigned long long)result);
1554 static int smb_full_audit_unlinkat(vfs_handle_struct *handle,
1555 struct files_struct *dirfsp,
1556 const struct smb_filename *smb_fname,
1559 struct smb_filename *full_fname = NULL;
1562 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1565 if (full_fname == NULL) {
1569 result = SMB_VFS_NEXT_UNLINKAT(handle,
1574 do_log(SMB_VFS_OP_UNLINKAT, (result >= 0), handle, "%s",
1575 smb_fname_str_do_log(handle->conn, full_fname));
1577 TALLOC_FREE(full_fname);
1581 static int smb_full_audit_fchmod(vfs_handle_struct *handle, files_struct *fsp,
1586 result = SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1588 do_log(SMB_VFS_OP_FCHMOD, (result >= 0), handle,
1589 "%s|%o", fsp_str_do_log(fsp), mode);
1594 static int smb_full_audit_fchown(vfs_handle_struct *handle, files_struct *fsp,
1595 uid_t uid, gid_t gid)
1599 result = SMB_VFS_NEXT_FCHOWN(handle, fsp, uid, gid);
1601 do_log(SMB_VFS_OP_FCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1602 fsp_str_do_log(fsp), (long int)uid, (long int)gid);
1607 static int smb_full_audit_lchown(vfs_handle_struct *handle,
1608 const struct smb_filename *smb_fname,
1614 result = SMB_VFS_NEXT_LCHOWN(handle, smb_fname, uid, gid);
1616 do_log(SMB_VFS_OP_LCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1617 smb_fname->base_name, (long int)uid, (long int)gid);
1622 static int smb_full_audit_chdir(vfs_handle_struct *handle,
1623 const struct smb_filename *smb_fname)
1627 result = SMB_VFS_NEXT_CHDIR(handle, smb_fname);
1629 do_log(SMB_VFS_OP_CHDIR,
1633 smb_fname_str_do_log(handle->conn, smb_fname));
1638 static struct smb_filename *smb_full_audit_getwd(vfs_handle_struct *handle,
1641 struct smb_filename *result;
1643 result = SMB_VFS_NEXT_GETWD(handle, ctx);
1645 do_log(SMB_VFS_OP_GETWD, (result != NULL), handle, "%s",
1646 result == NULL? "" : result->base_name);
1651 static int smb_full_audit_fntimes(vfs_handle_struct *handle,
1653 struct smb_file_time *ft)
1656 time_t create_time = convert_timespec_to_time_t(ft->create_time);
1657 time_t atime = convert_timespec_to_time_t(ft->atime);
1658 time_t mtime = convert_timespec_to_time_t(ft->mtime);
1659 time_t ctime = convert_timespec_to_time_t(ft->ctime);
1660 const char *create_time_str = "";
1661 const char *atime_str = "";
1662 const char *mtime_str = "";
1663 const char *ctime_str = "";
1664 TALLOC_CTX *frame = talloc_stackframe();
1666 if (frame == NULL) {
1671 result = SMB_VFS_NEXT_FNTIMES(handle, fsp, ft);
1673 if (create_time > 0) {
1674 create_time_str = timestring(frame, create_time);
1677 atime_str = timestring(frame, atime);
1680 mtime_str = timestring(frame, mtime);
1683 ctime_str = timestring(frame, ctime);
1686 do_log(SMB_VFS_OP_FNTIMES,
1690 fsp_str_do_log(fsp),
1701 static int smb_full_audit_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
1706 result = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1708 do_log(SMB_VFS_OP_FTRUNCATE, (result >= 0), handle,
1709 "%s", fsp_str_do_log(fsp));
1714 static int smb_full_audit_fallocate(vfs_handle_struct *handle, files_struct *fsp,
1721 result = SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
1723 do_log(SMB_VFS_OP_FALLOCATE, (result >= 0), handle,
1724 "%s", fsp_str_do_log(fsp));
1729 static bool smb_full_audit_lock(vfs_handle_struct *handle, files_struct *fsp,
1730 int op, off_t offset, off_t count, int type)
1734 result = SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type);
1736 do_log(SMB_VFS_OP_LOCK, result, handle, "%s", fsp_str_do_log(fsp));
1741 static int smb_full_audit_kernel_flock(struct vfs_handle_struct *handle,
1742 struct files_struct *fsp,
1743 uint32_t share_access,
1744 uint32_t access_mask)
1748 result = SMB_VFS_NEXT_KERNEL_FLOCK(handle,
1753 do_log(SMB_VFS_OP_KERNEL_FLOCK, (result >= 0), handle, "%s",
1754 fsp_str_do_log(fsp));
1759 static int smb_full_audit_fcntl(struct vfs_handle_struct *handle,
1760 struct files_struct *fsp,
1761 int cmd, va_list cmd_arg)
1764 va_list dup_cmd_arg;
1767 va_copy(dup_cmd_arg, cmd_arg);
1768 arg = va_arg(dup_cmd_arg, void *);
1769 result = SMB_VFS_NEXT_FCNTL(handle, fsp, cmd, arg);
1770 va_end(dup_cmd_arg);
1772 do_log(SMB_VFS_OP_FCNTL, (result >= 0), handle, "%s",
1773 fsp_str_do_log(fsp));
1778 static int smb_full_audit_linux_setlease(vfs_handle_struct *handle, files_struct *fsp,
1783 result = SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
1785 do_log(SMB_VFS_OP_LINUX_SETLEASE, (result >= 0), handle, "%s",
1786 fsp_str_do_log(fsp));
1791 static bool smb_full_audit_getlock(vfs_handle_struct *handle, files_struct *fsp,
1792 off_t *poffset, off_t *pcount, int *ptype, pid_t *ppid)
1796 result = SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype, ppid);
1798 do_log(SMB_VFS_OP_GETLOCK, result, handle, "%s", fsp_str_do_log(fsp));
1803 static int smb_full_audit_symlinkat(vfs_handle_struct *handle,
1804 const struct smb_filename *link_contents,
1805 struct files_struct *dirfsp,
1806 const struct smb_filename *new_smb_fname)
1808 struct smb_filename *full_fname = NULL;
1811 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1814 if (full_fname == NULL) {
1818 result = SMB_VFS_NEXT_SYMLINKAT(handle,
1823 do_log(SMB_VFS_OP_SYMLINKAT,
1827 link_contents->base_name,
1828 smb_fname_str_do_log(handle->conn, full_fname));
1830 TALLOC_FREE(full_fname);
1835 static int smb_full_audit_readlinkat(vfs_handle_struct *handle,
1836 const struct files_struct *dirfsp,
1837 const struct smb_filename *smb_fname,
1841 struct smb_filename *full_fname = NULL;
1844 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1847 if (full_fname == NULL) {
1851 result = SMB_VFS_NEXT_READLINKAT(handle,
1857 do_log(SMB_VFS_OP_READLINKAT,
1861 smb_fname_str_do_log(handle->conn, full_fname));
1863 TALLOC_FREE(full_fname);
1868 static int smb_full_audit_linkat(vfs_handle_struct *handle,
1869 files_struct *srcfsp,
1870 const struct smb_filename *old_smb_fname,
1871 files_struct *dstfsp,
1872 const struct smb_filename *new_smb_fname,
1875 struct smb_filename *old_full_fname = NULL;
1876 struct smb_filename *new_full_fname = NULL;
1879 old_full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1882 if (old_full_fname == NULL) {
1885 new_full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1888 if (new_full_fname == NULL) {
1889 TALLOC_FREE(old_full_fname);
1892 result = SMB_VFS_NEXT_LINKAT(handle,
1899 do_log(SMB_VFS_OP_LINKAT,
1903 smb_fname_str_do_log(handle->conn, old_full_fname),
1904 smb_fname_str_do_log(handle->conn, new_full_fname));
1906 TALLOC_FREE(old_full_fname);
1907 TALLOC_FREE(new_full_fname);
1912 static int smb_full_audit_mknodat(vfs_handle_struct *handle,
1913 files_struct *dirfsp,
1914 const struct smb_filename *smb_fname,
1918 struct smb_filename *full_fname = NULL;
1921 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1924 if (full_fname == NULL) {
1928 result = SMB_VFS_NEXT_MKNODAT(handle,
1934 do_log(SMB_VFS_OP_MKNODAT,
1938 smb_fname_str_do_log(handle->conn, full_fname));
1940 TALLOC_FREE(full_fname);
1945 static struct smb_filename *smb_full_audit_realpath(vfs_handle_struct *handle,
1947 const struct smb_filename *smb_fname)
1949 struct smb_filename *result_fname = NULL;
1951 result_fname = SMB_VFS_NEXT_REALPATH(handle, ctx, smb_fname);
1953 do_log(SMB_VFS_OP_REALPATH,
1954 (result_fname != NULL),
1957 smb_fname_str_do_log(handle->conn, smb_fname));
1959 return result_fname;
1962 static int smb_full_audit_chflags(vfs_handle_struct *handle,
1963 const struct smb_filename *smb_fname,
1968 result = SMB_VFS_NEXT_CHFLAGS(handle, smb_fname, flags);
1970 do_log(SMB_VFS_OP_CHFLAGS,
1974 smb_fname_str_do_log(handle->conn, smb_fname));
1979 static struct file_id smb_full_audit_file_id_create(struct vfs_handle_struct *handle,
1980 const SMB_STRUCT_STAT *sbuf)
1982 struct file_id id_zero = { 0 };
1983 struct file_id result;
1984 struct file_id_buf idbuf;
1986 result = SMB_VFS_NEXT_FILE_ID_CREATE(handle, sbuf);
1988 do_log(SMB_VFS_OP_FILE_ID_CREATE,
1989 !file_id_equal(&id_zero, &result),
1992 file_id_str_buf(result, &idbuf));
1997 static uint64_t smb_full_audit_fs_file_id(struct vfs_handle_struct *handle,
1998 const SMB_STRUCT_STAT *sbuf)
2002 result = SMB_VFS_NEXT_FS_FILE_ID(handle, sbuf);
2004 do_log(SMB_VFS_OP_FS_FILE_ID,
2006 handle, "%" PRIu64, result);
2011 static NTSTATUS smb_full_audit_fstreaminfo(vfs_handle_struct *handle,
2012 struct files_struct *fsp,
2013 TALLOC_CTX *mem_ctx,
2014 unsigned int *pnum_streams,
2015 struct stream_struct **pstreams)
2019 result = SMB_VFS_NEXT_FSTREAMINFO(handle, fsp, mem_ctx,
2020 pnum_streams, pstreams);
2022 do_log(SMB_VFS_OP_FSTREAMINFO,
2023 NT_STATUS_IS_OK(result),
2026 smb_fname_str_do_log(handle->conn, fsp->fsp_name));
2031 static int smb_full_audit_get_real_filename(struct vfs_handle_struct *handle,
2032 const struct smb_filename *path,
2034 TALLOC_CTX *mem_ctx,
2039 result = SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name, mem_ctx,
2042 do_log(SMB_VFS_OP_GET_REAL_FILENAME, (result == 0), handle,
2044 path->base_name, name, (result == 0) ? *found_name : "");
2049 static const char *smb_full_audit_connectpath(vfs_handle_struct *handle,
2050 const struct smb_filename *smb_fname)
2054 result = SMB_VFS_NEXT_CONNECTPATH(handle, smb_fname);
2056 do_log(SMB_VFS_OP_CONNECTPATH,
2060 smb_fname_str_do_log(handle->conn, smb_fname));
2065 static NTSTATUS smb_full_audit_brl_lock_windows(struct vfs_handle_struct *handle,
2066 struct byte_range_lock *br_lck,
2067 struct lock_struct *plock)
2071 result = SMB_VFS_NEXT_BRL_LOCK_WINDOWS(handle, br_lck, plock);
2073 do_log(SMB_VFS_OP_BRL_LOCK_WINDOWS, NT_STATUS_IS_OK(result), handle,
2074 "%s:%llu-%llu. type=%d.",
2075 fsp_str_do_log(brl_fsp(br_lck)),
2076 (unsigned long long)plock->start,
2077 (unsigned long long)plock->size,
2083 static bool smb_full_audit_brl_unlock_windows(struct vfs_handle_struct *handle,
2084 struct byte_range_lock *br_lck,
2085 const struct lock_struct *plock)
2089 result = SMB_VFS_NEXT_BRL_UNLOCK_WINDOWS(handle, br_lck, plock);
2091 do_log(SMB_VFS_OP_BRL_UNLOCK_WINDOWS, (result == 0), handle,
2092 "%s:%llu-%llu:%d", fsp_str_do_log(brl_fsp(br_lck)),
2093 (unsigned long long)plock->start,
2094 (unsigned long long)plock->size,
2100 static bool smb_full_audit_strict_lock_check(struct vfs_handle_struct *handle,
2101 struct files_struct *fsp,
2102 struct lock_struct *plock)
2106 result = SMB_VFS_NEXT_STRICT_LOCK_CHECK(handle, fsp, plock);
2108 do_log(SMB_VFS_OP_STRICT_LOCK_CHECK, result, handle,
2109 "%s:%llu-%llu:%d", fsp_str_do_log(fsp),
2110 (unsigned long long)plock->start,
2111 (unsigned long long)plock->size,
2117 static NTSTATUS smb_full_audit_translate_name(struct vfs_handle_struct *handle,
2119 enum vfs_translate_direction direction,
2120 TALLOC_CTX *mem_ctx,
2125 result = SMB_VFS_NEXT_TRANSLATE_NAME(handle, name, direction, mem_ctx,
2128 do_log(SMB_VFS_OP_TRANSLATE_NAME, NT_STATUS_IS_OK(result), handle, "");
2133 static NTSTATUS smb_full_audit_parent_pathname(struct vfs_handle_struct *handle,
2134 TALLOC_CTX *mem_ctx,
2135 const struct smb_filename *smb_fname_in,
2136 struct smb_filename **parent_dir_out,
2137 struct smb_filename **atname_out)
2141 result = SMB_VFS_NEXT_PARENT_PATHNAME(handle,
2146 do_log(SMB_VFS_OP_CONNECTPATH,
2147 NT_STATUS_IS_OK(result),
2150 smb_fname_str_do_log(handle->conn, smb_fname_in));
2155 static NTSTATUS smb_full_audit_fsctl(struct vfs_handle_struct *handle,
2156 struct files_struct *fsp,
2160 const uint8_t *_in_data,
2162 uint8_t **_out_data,
2163 uint32_t max_out_len,
2168 result = SMB_VFS_NEXT_FSCTL(handle,
2179 do_log(SMB_VFS_OP_FSCTL, NT_STATUS_IS_OK(result), handle, "");
2184 static struct tevent_req *smb_full_audit_offload_read_send(
2185 TALLOC_CTX *mem_ctx,
2186 struct tevent_context *ev,
2187 struct vfs_handle_struct *handle,
2188 struct files_struct *fsp,
2194 struct tevent_req *req = NULL;
2196 req = SMB_VFS_NEXT_OFFLOAD_READ_SEND(mem_ctx, ev, handle, fsp,
2197 fsctl, ttl, offset, to_copy);
2199 do_log(SMB_VFS_OP_OFFLOAD_READ_SEND, req, handle, "");
2204 static NTSTATUS smb_full_audit_offload_read_recv(
2205 struct tevent_req *req,
2206 struct vfs_handle_struct *handle,
2207 TALLOC_CTX *mem_ctx,
2208 DATA_BLOB *_token_blob)
2212 status = SMB_VFS_NEXT_OFFLOAD_READ_RECV(req, handle, mem_ctx,
2215 do_log(SMB_VFS_OP_OFFLOAD_READ_RECV, NT_STATUS_IS_OK(status), handle, "");
2220 static struct tevent_req *smb_full_audit_offload_write_send(struct vfs_handle_struct *handle,
2221 TALLOC_CTX *mem_ctx,
2222 struct tevent_context *ev,
2225 off_t transfer_offset,
2226 struct files_struct *dest_fsp,
2230 struct tevent_req *req;
2232 req = SMB_VFS_NEXT_OFFLOAD_WRITE_SEND(handle, mem_ctx, ev,
2233 fsctl, token, transfer_offset,
2234 dest_fsp, dest_off, num);
2236 do_log(SMB_VFS_OP_OFFLOAD_WRITE_SEND, req, handle, "");
2241 static NTSTATUS smb_full_audit_offload_write_recv(struct vfs_handle_struct *handle,
2242 struct tevent_req *req,
2247 result = SMB_VFS_NEXT_OFFLOAD_WRITE_RECV(handle, req, copied);
2249 do_log(SMB_VFS_OP_OFFLOAD_WRITE_RECV, NT_STATUS_IS_OK(result), handle, "");
2254 static NTSTATUS smb_full_audit_fget_compression(vfs_handle_struct *handle,
2255 TALLOC_CTX *mem_ctx,
2256 struct files_struct *fsp,
2257 uint16_t *_compression_fmt)
2261 result = SMB_VFS_NEXT_FGET_COMPRESSION(handle, mem_ctx, fsp,
2264 do_log(SMB_VFS_OP_FGET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
2266 fsp_str_do_log(fsp));
2271 static NTSTATUS smb_full_audit_set_compression(vfs_handle_struct *handle,
2272 TALLOC_CTX *mem_ctx,
2273 struct files_struct *fsp,
2274 uint16_t compression_fmt)
2278 result = SMB_VFS_NEXT_SET_COMPRESSION(handle, mem_ctx, fsp,
2281 do_log(SMB_VFS_OP_SET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
2282 "%s", fsp_str_do_log(fsp));
2287 static NTSTATUS smb_full_audit_freaddir_attr(struct vfs_handle_struct *handle,
2288 struct files_struct *fsp,
2289 TALLOC_CTX *mem_ctx,
2290 struct readdir_attr_data **pattr_data)
2294 status = SMB_VFS_NEXT_FREADDIR_ATTR(handle, fsp, mem_ctx, pattr_data);
2296 do_log(SMB_VFS_OP_FREADDIR_ATTR,
2297 NT_STATUS_IS_OK(status),
2300 fsp_str_do_log(fsp));
2305 struct smb_full_audit_get_dos_attributes_state {
2306 struct vfs_aio_state aio_state;
2307 vfs_handle_struct *handle;
2308 files_struct *dir_fsp;
2309 const struct smb_filename *smb_fname;
2313 static void smb_full_audit_get_dos_attributes_done(struct tevent_req *subreq);
2315 static struct tevent_req *smb_full_audit_get_dos_attributes_send(
2316 TALLOC_CTX *mem_ctx,
2317 struct tevent_context *ev,
2318 struct vfs_handle_struct *handle,
2319 files_struct *dir_fsp,
2320 struct smb_filename *smb_fname)
2322 struct tevent_req *req = NULL;
2323 struct smb_full_audit_get_dos_attributes_state *state = NULL;
2324 struct tevent_req *subreq = NULL;
2326 req = tevent_req_create(mem_ctx, &state,
2327 struct smb_full_audit_get_dos_attributes_state);
2329 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2333 fsp_str_do_log(dir_fsp),
2334 smb_fname->base_name);
2337 *state = (struct smb_full_audit_get_dos_attributes_state) {
2340 .smb_fname = smb_fname,
2343 subreq = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES_SEND(mem_ctx,
2348 if (tevent_req_nomem(subreq, req)) {
2349 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2353 fsp_str_do_log(dir_fsp),
2354 smb_fname->base_name);
2355 return tevent_req_post(req, ev);
2357 tevent_req_set_callback(subreq,
2358 smb_full_audit_get_dos_attributes_done,
2361 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2365 fsp_str_do_log(dir_fsp),
2366 smb_fname->base_name);
2371 static void smb_full_audit_get_dos_attributes_done(struct tevent_req *subreq)
2373 struct tevent_req *req =
2374 tevent_req_callback_data(subreq,
2376 struct smb_full_audit_get_dos_attributes_state *state =
2377 tevent_req_data(req,
2378 struct smb_full_audit_get_dos_attributes_state);
2381 status = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES_RECV(subreq,
2384 TALLOC_FREE(subreq);
2385 if (tevent_req_nterror(req, status)) {
2389 tevent_req_done(req);
2393 static NTSTATUS smb_full_audit_get_dos_attributes_recv(struct tevent_req *req,
2394 struct vfs_aio_state *aio_state,
2397 struct smb_full_audit_get_dos_attributes_state *state =
2398 tevent_req_data(req,
2399 struct smb_full_audit_get_dos_attributes_state);
2402 if (tevent_req_is_nterror(req, &status)) {
2403 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV,
2407 fsp_str_do_log(state->dir_fsp),
2408 state->smb_fname->base_name);
2409 tevent_req_received(req);
2413 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV,
2417 fsp_str_do_log(state->dir_fsp),
2418 state->smb_fname->base_name);
2420 *aio_state = state->aio_state;
2421 *dosmode = state->dosmode;
2422 tevent_req_received(req);
2423 return NT_STATUS_OK;
2426 static NTSTATUS smb_full_audit_fget_dos_attributes(
2427 struct vfs_handle_struct *handle,
2428 struct files_struct *fsp,
2433 status = SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle,
2437 do_log(SMB_VFS_OP_FGET_DOS_ATTRIBUTES,
2438 NT_STATUS_IS_OK(status),
2441 fsp_str_do_log(fsp));
2446 static NTSTATUS smb_full_audit_fset_dos_attributes(
2447 struct vfs_handle_struct *handle,
2448 struct files_struct *fsp,
2453 status = SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle,
2457 do_log(SMB_VFS_OP_FSET_DOS_ATTRIBUTES,
2458 NT_STATUS_IS_OK(status),
2461 fsp_str_do_log(fsp));
2466 static NTSTATUS smb_full_audit_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
2467 uint32_t security_info,
2468 TALLOC_CTX *mem_ctx,
2469 struct security_descriptor **ppdesc)
2473 result = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
2476 do_log(SMB_VFS_OP_FGET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2477 "%s", fsp_str_do_log(fsp));
2482 static NTSTATUS smb_full_audit_get_nt_acl_at(vfs_handle_struct *handle,
2483 struct files_struct *dirfsp,
2484 const struct smb_filename *smb_fname,
2485 uint32_t security_info,
2486 TALLOC_CTX *mem_ctx,
2487 struct security_descriptor **ppdesc)
2491 result = SMB_VFS_NEXT_GET_NT_ACL_AT(handle,
2498 do_log(SMB_VFS_OP_GET_NT_ACL_AT,
2499 NT_STATUS_IS_OK(result),
2502 smb_fname_str_do_log(handle->conn, smb_fname));
2507 static NTSTATUS smb_full_audit_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
2508 uint32_t security_info_sent,
2509 const struct security_descriptor *psd)
2511 struct vfs_full_audit_private_data *pd;
2515 SMB_VFS_HANDLE_GET_DATA(handle, pd,
2516 struct vfs_full_audit_private_data,
2517 return NT_STATUS_INTERNAL_ERROR);
2519 if (pd->log_secdesc) {
2520 sd = sddl_encode(talloc_tos(), psd, get_global_sam_sid());
2523 result = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
2525 do_log(SMB_VFS_OP_FSET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2526 "%s [%s]", fsp_str_do_log(fsp), sd ? sd : "");
2533 static NTSTATUS smb_full_audit_audit_file(struct vfs_handle_struct *handle,
2534 struct smb_filename *file,
2535 struct security_acl *sacl,
2536 uint32_t access_requested,
2537 uint32_t access_denied)
2541 result = SMB_VFS_NEXT_AUDIT_FILE(handle,
2547 do_log(SMB_VFS_OP_AUDIT_FILE, NT_STATUS_IS_OK(result), handle,
2549 smb_fname_str_do_log(handle->conn, file));
2554 static SMB_ACL_T smb_full_audit_sys_acl_get_file(vfs_handle_struct *handle,
2555 const struct smb_filename *smb_fname,
2556 SMB_ACL_TYPE_T type,
2557 TALLOC_CTX *mem_ctx)
2561 result = SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, smb_fname,
2564 do_log(SMB_VFS_OP_SYS_ACL_GET_FILE,
2568 smb_fname_str_do_log(handle->conn, smb_fname));
2573 static SMB_ACL_T smb_full_audit_sys_acl_get_fd(vfs_handle_struct *handle,
2575 SMB_ACL_TYPE_T type,
2576 TALLOC_CTX *mem_ctx)
2580 result = SMB_VFS_NEXT_SYS_ACL_GET_FD(handle,
2585 do_log(SMB_VFS_OP_SYS_ACL_GET_FD, (result != NULL), handle,
2586 "%s", fsp_str_do_log(fsp));
2591 static int smb_full_audit_sys_acl_blob_get_file(vfs_handle_struct *handle,
2592 const struct smb_filename *smb_fname,
2593 TALLOC_CTX *mem_ctx,
2594 char **blob_description,
2599 result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FILE(handle, smb_fname,
2600 mem_ctx, blob_description, blob);
2602 do_log(SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE,
2606 smb_fname_str_do_log(handle->conn, smb_fname));
2611 static int smb_full_audit_sys_acl_blob_get_fd(vfs_handle_struct *handle,
2613 TALLOC_CTX *mem_ctx,
2614 char **blob_description,
2619 result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle, fsp, mem_ctx, blob_description, blob);
2621 do_log(SMB_VFS_OP_SYS_ACL_BLOB_GET_FD, (result >= 0), handle,
2622 "%s", fsp_str_do_log(fsp));
2627 static int smb_full_audit_sys_acl_set_fd(vfs_handle_struct *handle,
2628 struct files_struct *fsp,
2629 SMB_ACL_TYPE_T type,
2634 result = SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, type, theacl);
2636 do_log(SMB_VFS_OP_SYS_ACL_SET_FD, (result >= 0), handle,
2637 "%s", fsp_str_do_log(fsp));
2642 static int smb_full_audit_sys_acl_delete_def_fd(vfs_handle_struct *handle,
2643 struct files_struct *fsp)
2647 result = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FD(handle, fsp);
2649 do_log(SMB_VFS_OP_SYS_ACL_DELETE_DEF_FD,
2653 fsp_str_do_log(fsp));
2658 static ssize_t smb_full_audit_getxattr(struct vfs_handle_struct *handle,
2659 const struct smb_filename *smb_fname,
2660 const char *name, void *value, size_t size)
2664 result = SMB_VFS_NEXT_GETXATTR(handle, smb_fname, name, value, size);
2666 do_log(SMB_VFS_OP_GETXATTR,
2670 smb_fname_str_do_log(handle->conn, smb_fname),
2676 struct smb_full_audit_getxattrat_state {
2677 struct vfs_aio_state aio_state;
2678 vfs_handle_struct *handle;
2679 files_struct *dir_fsp;
2680 const struct smb_filename *smb_fname;
2681 const char *xattr_name;
2683 uint8_t *xattr_value;
2686 static void smb_full_audit_getxattrat_done(struct tevent_req *subreq);
2688 static struct tevent_req *smb_full_audit_getxattrat_send(
2689 TALLOC_CTX *mem_ctx,
2690 struct tevent_context *ev,
2691 struct vfs_handle_struct *handle,
2692 files_struct *dir_fsp,
2693 const struct smb_filename *smb_fname,
2694 const char *xattr_name,
2697 struct tevent_req *req = NULL;
2698 struct tevent_req *subreq = NULL;
2699 struct smb_full_audit_getxattrat_state *state = NULL;
2701 req = tevent_req_create(mem_ctx, &state,
2702 struct smb_full_audit_getxattrat_state);
2704 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2708 fsp_str_do_log(dir_fsp),
2709 smb_fname->base_name,
2713 *state = (struct smb_full_audit_getxattrat_state) {
2716 .smb_fname = smb_fname,
2717 .xattr_name = xattr_name,
2720 subreq = SMB_VFS_NEXT_GETXATTRAT_SEND(state,
2727 if (tevent_req_nomem(subreq, req)) {
2728 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2732 fsp_str_do_log(dir_fsp),
2733 smb_fname->base_name,
2735 return tevent_req_post(req, ev);
2737 tevent_req_set_callback(subreq, smb_full_audit_getxattrat_done, req);
2739 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2743 fsp_str_do_log(dir_fsp),
2744 smb_fname->base_name,
2750 static void smb_full_audit_getxattrat_done(struct tevent_req *subreq)
2752 struct tevent_req *req = tevent_req_callback_data(
2753 subreq, struct tevent_req);
2754 struct smb_full_audit_getxattrat_state *state = tevent_req_data(
2755 req, struct smb_full_audit_getxattrat_state);
2757 state->xattr_size = SMB_VFS_NEXT_GETXATTRAT_RECV(subreq,
2760 &state->xattr_value);
2761 TALLOC_FREE(subreq);
2762 if (state->xattr_size == -1) {
2763 tevent_req_error(req, state->aio_state.error);
2767 tevent_req_done(req);
2770 static ssize_t smb_full_audit_getxattrat_recv(struct tevent_req *req,
2771 struct vfs_aio_state *aio_state,
2772 TALLOC_CTX *mem_ctx,
2773 uint8_t **xattr_value)
2775 struct smb_full_audit_getxattrat_state *state = tevent_req_data(
2776 req, struct smb_full_audit_getxattrat_state);
2779 if (tevent_req_is_unix_error(req, &aio_state->error)) {
2780 do_log(SMB_VFS_OP_GETXATTRAT_RECV,
2784 fsp_str_do_log(state->dir_fsp),
2785 state->smb_fname->base_name,
2787 tevent_req_received(req);
2791 do_log(SMB_VFS_OP_GETXATTRAT_RECV,
2795 fsp_str_do_log(state->dir_fsp),
2796 state->smb_fname->base_name,
2799 *aio_state = state->aio_state;
2800 xattr_size = state->xattr_size;
2801 if (xattr_value != NULL) {
2802 *xattr_value = talloc_move(mem_ctx, &state->xattr_value);
2805 tevent_req_received(req);
2809 static ssize_t smb_full_audit_fgetxattr(struct vfs_handle_struct *handle,
2810 struct files_struct *fsp,
2811 const char *name, void *value, size_t size)
2815 result = SMB_VFS_NEXT_FGETXATTR(handle, fsp, name, value, size);
2817 do_log(SMB_VFS_OP_FGETXATTR, (result >= 0), handle,
2818 "%s|%s", fsp_str_do_log(fsp), name);
2823 static ssize_t smb_full_audit_flistxattr(struct vfs_handle_struct *handle,
2824 struct files_struct *fsp, char *list,
2829 result = SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
2831 do_log(SMB_VFS_OP_FLISTXATTR, (result >= 0), handle,
2832 "%s", fsp_str_do_log(fsp));
2837 static int smb_full_audit_fremovexattr(struct vfs_handle_struct *handle,
2838 struct files_struct *fsp,
2843 result = SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, name);
2845 do_log(SMB_VFS_OP_FREMOVEXATTR, (result >= 0), handle,
2846 "%s|%s", fsp_str_do_log(fsp), name);
2851 static int smb_full_audit_fsetxattr(struct vfs_handle_struct *handle,
2852 struct files_struct *fsp, const char *name,
2853 const void *value, size_t size, int flags)
2857 result = SMB_VFS_NEXT_FSETXATTR(handle, fsp, name, value, size, flags);
2859 do_log(SMB_VFS_OP_FSETXATTR, (result >= 0), handle,
2860 "%s|%s", fsp_str_do_log(fsp), name);
2865 static bool smb_full_audit_aio_force(struct vfs_handle_struct *handle,
2866 struct files_struct *fsp)
2870 result = SMB_VFS_NEXT_AIO_FORCE(handle, fsp);
2871 do_log(SMB_VFS_OP_AIO_FORCE, result, handle,
2872 "%s", fsp_str_do_log(fsp));
2877 static NTSTATUS smb_full_audit_durable_cookie(struct vfs_handle_struct *handle,
2878 struct files_struct *fsp,
2879 TALLOC_CTX *mem_ctx,
2884 result = SMB_VFS_NEXT_DURABLE_COOKIE(handle,
2889 do_log(SMB_VFS_OP_DURABLE_COOKIE, NT_STATUS_IS_OK(result), handle,
2890 "%s", fsp_str_do_log(fsp));
2895 static NTSTATUS smb_full_audit_durable_disconnect(
2896 struct vfs_handle_struct *handle,
2897 struct files_struct *fsp,
2898 const DATA_BLOB old_cookie,
2899 TALLOC_CTX *mem_ctx,
2900 DATA_BLOB *new_cookie)
2904 result = SMB_VFS_NEXT_DURABLE_DISCONNECT(handle,
2910 do_log(SMB_VFS_OP_DURABLE_DISCONNECT, NT_STATUS_IS_OK(result), handle,
2911 "%s", fsp_str_do_log(fsp));
2916 static NTSTATUS smb_full_audit_durable_reconnect(
2917 struct vfs_handle_struct *handle,
2918 struct smb_request *smb1req,
2919 struct smbXsrv_open *op,
2920 const DATA_BLOB old_cookie,
2921 TALLOC_CTX *mem_ctx,
2922 struct files_struct **fsp,
2923 DATA_BLOB *new_cookie)
2927 result = SMB_VFS_NEXT_DURABLE_RECONNECT(handle,
2935 do_log(SMB_VFS_OP_DURABLE_RECONNECT,
2936 NT_STATUS_IS_OK(result),
2943 static struct vfs_fn_pointers vfs_full_audit_fns = {
2945 /* Disk operations */
2947 .connect_fn = smb_full_audit_connect,
2948 .disconnect_fn = smb_full_audit_disconnect,
2949 .disk_free_fn = smb_full_audit_disk_free,
2950 .get_quota_fn = smb_full_audit_get_quota,
2951 .set_quota_fn = smb_full_audit_set_quota,
2952 .get_shadow_copy_data_fn = smb_full_audit_get_shadow_copy_data,
2953 .statvfs_fn = smb_full_audit_statvfs,
2954 .fs_capabilities_fn = smb_full_audit_fs_capabilities,
2955 .get_dfs_referrals_fn = smb_full_audit_get_dfs_referrals,
2956 .create_dfs_pathat_fn = smb_full_audit_create_dfs_pathat,
2957 .read_dfs_pathat_fn = smb_full_audit_read_dfs_pathat,
2958 .fdopendir_fn = smb_full_audit_fdopendir,
2959 .readdir_fn = smb_full_audit_readdir,
2960 .seekdir_fn = smb_full_audit_seekdir,
2961 .telldir_fn = smb_full_audit_telldir,
2962 .rewind_dir_fn = smb_full_audit_rewinddir,
2963 .mkdirat_fn = smb_full_audit_mkdirat,
2964 .closedir_fn = smb_full_audit_closedir,
2965 .openat_fn = smb_full_audit_openat,
2966 .create_file_fn = smb_full_audit_create_file,
2967 .close_fn = smb_full_audit_close,
2968 .pread_fn = smb_full_audit_pread,
2969 .pread_send_fn = smb_full_audit_pread_send,
2970 .pread_recv_fn = smb_full_audit_pread_recv,
2971 .pwrite_fn = smb_full_audit_pwrite,
2972 .pwrite_send_fn = smb_full_audit_pwrite_send,
2973 .pwrite_recv_fn = smb_full_audit_pwrite_recv,
2974 .lseek_fn = smb_full_audit_lseek,
2975 .sendfile_fn = smb_full_audit_sendfile,
2976 .recvfile_fn = smb_full_audit_recvfile,
2977 .renameat_fn = smb_full_audit_renameat,
2978 .fsync_send_fn = smb_full_audit_fsync_send,
2979 .fsync_recv_fn = smb_full_audit_fsync_recv,
2980 .stat_fn = smb_full_audit_stat,
2981 .fstat_fn = smb_full_audit_fstat,
2982 .lstat_fn = smb_full_audit_lstat,
2983 .get_alloc_size_fn = smb_full_audit_get_alloc_size,
2984 .unlinkat_fn = smb_full_audit_unlinkat,
2985 .fchmod_fn = smb_full_audit_fchmod,
2986 .fchown_fn = smb_full_audit_fchown,
2987 .lchown_fn = smb_full_audit_lchown,
2988 .chdir_fn = smb_full_audit_chdir,
2989 .getwd_fn = smb_full_audit_getwd,
2990 .fntimes_fn = smb_full_audit_fntimes,
2991 .ftruncate_fn = smb_full_audit_ftruncate,
2992 .fallocate_fn = smb_full_audit_fallocate,
2993 .lock_fn = smb_full_audit_lock,
2994 .kernel_flock_fn = smb_full_audit_kernel_flock,
2995 .fcntl_fn = smb_full_audit_fcntl,
2996 .linux_setlease_fn = smb_full_audit_linux_setlease,
2997 .getlock_fn = smb_full_audit_getlock,
2998 .symlinkat_fn = smb_full_audit_symlinkat,
2999 .readlinkat_fn = smb_full_audit_readlinkat,
3000 .linkat_fn = smb_full_audit_linkat,
3001 .mknodat_fn = smb_full_audit_mknodat,
3002 .realpath_fn = smb_full_audit_realpath,
3003 .chflags_fn = smb_full_audit_chflags,
3004 .file_id_create_fn = smb_full_audit_file_id_create,
3005 .fs_file_id_fn = smb_full_audit_fs_file_id,
3006 .offload_read_send_fn = smb_full_audit_offload_read_send,
3007 .offload_read_recv_fn = smb_full_audit_offload_read_recv,
3008 .offload_write_send_fn = smb_full_audit_offload_write_send,
3009 .offload_write_recv_fn = smb_full_audit_offload_write_recv,
3010 .fget_compression_fn = smb_full_audit_fget_compression,
3011 .set_compression_fn = smb_full_audit_set_compression,
3012 .snap_check_path_fn = smb_full_audit_snap_check_path,
3013 .snap_create_fn = smb_full_audit_snap_create,
3014 .snap_delete_fn = smb_full_audit_snap_delete,
3015 .fstreaminfo_fn = smb_full_audit_fstreaminfo,
3016 .get_real_filename_fn = smb_full_audit_get_real_filename,
3017 .connectpath_fn = smb_full_audit_connectpath,
3018 .brl_lock_windows_fn = smb_full_audit_brl_lock_windows,
3019 .brl_unlock_windows_fn = smb_full_audit_brl_unlock_windows,
3020 .strict_lock_check_fn = smb_full_audit_strict_lock_check,
3021 .translate_name_fn = smb_full_audit_translate_name,
3022 .parent_pathname_fn = smb_full_audit_parent_pathname,
3023 .fsctl_fn = smb_full_audit_fsctl,
3024 .get_dos_attributes_send_fn = smb_full_audit_get_dos_attributes_send,
3025 .get_dos_attributes_recv_fn = smb_full_audit_get_dos_attributes_recv,
3026 .fget_dos_attributes_fn = smb_full_audit_fget_dos_attributes,
3027 .fset_dos_attributes_fn = smb_full_audit_fset_dos_attributes,
3028 .fget_nt_acl_fn = smb_full_audit_fget_nt_acl,
3029 .get_nt_acl_at_fn = smb_full_audit_get_nt_acl_at,
3030 .fset_nt_acl_fn = smb_full_audit_fset_nt_acl,
3031 .audit_file_fn = smb_full_audit_audit_file,
3032 .sys_acl_get_file_fn = smb_full_audit_sys_acl_get_file,
3033 .sys_acl_get_fd_fn = smb_full_audit_sys_acl_get_fd,
3034 .sys_acl_blob_get_file_fn = smb_full_audit_sys_acl_blob_get_file,
3035 .sys_acl_blob_get_fd_fn = smb_full_audit_sys_acl_blob_get_fd,
3036 .sys_acl_set_fd_fn = smb_full_audit_sys_acl_set_fd,
3037 .sys_acl_delete_def_fd_fn = smb_full_audit_sys_acl_delete_def_fd,
3038 .getxattr_fn = smb_full_audit_getxattr,
3039 .getxattrat_send_fn = smb_full_audit_getxattrat_send,
3040 .getxattrat_recv_fn = smb_full_audit_getxattrat_recv,
3041 .fgetxattr_fn = smb_full_audit_fgetxattr,
3042 .flistxattr_fn = smb_full_audit_flistxattr,
3043 .fremovexattr_fn = smb_full_audit_fremovexattr,
3044 .fsetxattr_fn = smb_full_audit_fsetxattr,
3045 .aio_force_fn = smb_full_audit_aio_force,
3046 .durable_cookie_fn = smb_full_audit_durable_cookie,
3047 .durable_disconnect_fn = smb_full_audit_durable_disconnect,
3048 .durable_reconnect_fn = smb_full_audit_durable_reconnect,
3049 .freaddir_attr_fn = smb_full_audit_freaddir_attr,
3053 NTSTATUS vfs_full_audit_init(TALLOC_CTX *ctx)
3057 smb_vfs_assert_all_fns(&vfs_full_audit_fns, "full_audit");
3059 ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "full_audit",
3060 &vfs_full_audit_fns);
3062 if (!NT_STATUS_IS_OK(ret))
3065 vfs_full_audit_debug_level = debug_add_class("full_audit");
3066 if (vfs_full_audit_debug_level == -1) {
3067 vfs_full_audit_debug_level = DBGC_VFS;
3068 DEBUG(0, ("vfs_full_audit: Couldn't register custom debugging "
3071 DEBUG(10, ("vfs_full_audit: Debug class number of "
3072 "'full_audit': %d\n", vfs_full_audit_debug_level));