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,
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_FSET_DOS_ATTRIBUTES,
190 /* NT ACL operations. */
192 SMB_VFS_OP_FGET_NT_ACL,
193 SMB_VFS_OP_GET_NT_ACL_AT,
194 SMB_VFS_OP_FSET_NT_ACL,
195 SMB_VFS_OP_AUDIT_FILE,
197 /* POSIX ACL operations. */
199 SMB_VFS_OP_SYS_ACL_GET_FILE,
200 SMB_VFS_OP_SYS_ACL_GET_FD,
201 SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE,
202 SMB_VFS_OP_SYS_ACL_BLOB_GET_FD,
203 SMB_VFS_OP_SYS_ACL_SET_FD,
204 SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE,
208 SMB_VFS_OP_GETXATTRAT_SEND,
209 SMB_VFS_OP_GETXATTRAT_RECV,
210 SMB_VFS_OP_FGETXATTR,
211 SMB_VFS_OP_FLISTXATTR,
212 SMB_VFS_OP_REMOVEXATTR,
213 SMB_VFS_OP_FREMOVEXATTR,
214 SMB_VFS_OP_FSETXATTR,
217 SMB_VFS_OP_AIO_FORCE,
219 /* offline operations */
220 SMB_VFS_OP_IS_OFFLINE,
221 SMB_VFS_OP_SET_OFFLINE,
223 /* Durable handle operations. */
224 SMB_VFS_OP_DURABLE_COOKIE,
225 SMB_VFS_OP_DURABLE_DISCONNECT,
226 SMB_VFS_OP_DURABLE_RECONNECT,
228 SMB_VFS_OP_READDIR_ATTR,
230 /* This should always be last enum value */
235 /* The following array *must* be in the same order as defined in vfs_op_type */
241 { SMB_VFS_OP_CONNECT, "connect" },
242 { SMB_VFS_OP_DISCONNECT, "disconnect" },
243 { SMB_VFS_OP_DISK_FREE, "disk_free" },
244 { SMB_VFS_OP_GET_QUOTA, "get_quota" },
245 { SMB_VFS_OP_SET_QUOTA, "set_quota" },
246 { SMB_VFS_OP_GET_SHADOW_COPY_DATA, "get_shadow_copy_data" },
247 { SMB_VFS_OP_STATVFS, "statvfs" },
248 { SMB_VFS_OP_FS_CAPABILITIES, "fs_capabilities" },
249 { SMB_VFS_OP_GET_DFS_REFERRALS, "get_dfs_referrals" },
250 { SMB_VFS_OP_CREATE_DFS_PATHAT, "create_dfs_pathat" },
251 { SMB_VFS_OP_READ_DFS_PATHAT, "read_dfs_pathat" },
252 { SMB_VFS_OP_FDOPENDIR, "fdopendir" },
253 { SMB_VFS_OP_READDIR, "readdir" },
254 { SMB_VFS_OP_SEEKDIR, "seekdir" },
255 { SMB_VFS_OP_TELLDIR, "telldir" },
256 { SMB_VFS_OP_REWINDDIR, "rewinddir" },
257 { SMB_VFS_OP_MKDIRAT, "mkdirat" },
258 { SMB_VFS_OP_CLOSEDIR, "closedir" },
259 { SMB_VFS_OP_OPEN, "open" },
260 { SMB_VFS_OP_OPENAT, "openat" },
261 { SMB_VFS_OP_CREATE_FILE, "create_file" },
262 { SMB_VFS_OP_CLOSE, "close" },
263 { SMB_VFS_OP_READ, "read" },
264 { SMB_VFS_OP_PREAD, "pread" },
265 { SMB_VFS_OP_PREAD_SEND, "pread_send" },
266 { SMB_VFS_OP_PREAD_RECV, "pread_recv" },
267 { SMB_VFS_OP_WRITE, "write" },
268 { SMB_VFS_OP_PWRITE, "pwrite" },
269 { SMB_VFS_OP_PWRITE_SEND, "pwrite_send" },
270 { SMB_VFS_OP_PWRITE_RECV, "pwrite_recv" },
271 { SMB_VFS_OP_LSEEK, "lseek" },
272 { SMB_VFS_OP_SENDFILE, "sendfile" },
273 { SMB_VFS_OP_RECVFILE, "recvfile" },
274 { SMB_VFS_OP_RENAMEAT, "renameat" },
275 { SMB_VFS_OP_FSYNC, "fsync" },
276 { SMB_VFS_OP_FSYNC_SEND, "fsync_send" },
277 { SMB_VFS_OP_FSYNC_RECV, "fsync_recv" },
278 { SMB_VFS_OP_STAT, "stat" },
279 { SMB_VFS_OP_FSTAT, "fstat" },
280 { SMB_VFS_OP_LSTAT, "lstat" },
281 { SMB_VFS_OP_GET_ALLOC_SIZE, "get_alloc_size" },
282 { SMB_VFS_OP_UNLINKAT, "unlinkat" },
283 { SMB_VFS_OP_FCHMOD, "fchmod" },
284 { SMB_VFS_OP_FCHOWN, "fchown" },
285 { SMB_VFS_OP_LCHOWN, "lchown" },
286 { SMB_VFS_OP_CHDIR, "chdir" },
287 { SMB_VFS_OP_GETWD, "getwd" },
288 { SMB_VFS_OP_NTIMES, "ntimes" },
289 { SMB_VFS_OP_FNTIMES, "fntimes" },
290 { SMB_VFS_OP_FTRUNCATE, "ftruncate" },
291 { SMB_VFS_OP_FALLOCATE,"fallocate" },
292 { SMB_VFS_OP_LOCK, "lock" },
293 { SMB_VFS_OP_KERNEL_FLOCK, "kernel_flock" },
294 { SMB_VFS_OP_FCNTL, "fcntl" },
295 { SMB_VFS_OP_LINUX_SETLEASE, "linux_setlease" },
296 { SMB_VFS_OP_GETLOCK, "getlock" },
297 { SMB_VFS_OP_SYMLINKAT, "symlinkat" },
298 { SMB_VFS_OP_READLINKAT,"readlinkat" },
299 { SMB_VFS_OP_LINKAT, "linkat" },
300 { SMB_VFS_OP_MKNODAT, "mknodat" },
301 { SMB_VFS_OP_REALPATH, "realpath" },
302 { SMB_VFS_OP_CHFLAGS, "chflags" },
303 { SMB_VFS_OP_FILE_ID_CREATE, "file_id_create" },
304 { SMB_VFS_OP_FS_FILE_ID, "fs_file_id" },
305 { SMB_VFS_OP_FSTREAMINFO, "fstreaminfo" },
306 { SMB_VFS_OP_GET_REAL_FILENAME, "get_real_filename" },
307 { SMB_VFS_OP_CONNECTPATH, "connectpath" },
308 { SMB_VFS_OP_BRL_LOCK_WINDOWS, "brl_lock_windows" },
309 { SMB_VFS_OP_BRL_UNLOCK_WINDOWS, "brl_unlock_windows" },
310 { SMB_VFS_OP_STRICT_LOCK_CHECK, "strict_lock_check" },
311 { SMB_VFS_OP_TRANSLATE_NAME, "translate_name" },
312 { SMB_VFS_OP_FSCTL, "fsctl" },
313 { SMB_VFS_OP_OFFLOAD_READ_SEND, "offload_read_send" },
314 { SMB_VFS_OP_OFFLOAD_READ_RECV, "offload_read_recv" },
315 { SMB_VFS_OP_OFFLOAD_WRITE_SEND, "offload_write_send" },
316 { SMB_VFS_OP_OFFLOAD_WRITE_RECV, "offload_write_recv" },
317 { SMB_VFS_OP_FGET_COMPRESSION, "fget_compression" },
318 { SMB_VFS_OP_SET_COMPRESSION, "set_compression" },
319 { SMB_VFS_OP_SNAP_CHECK_PATH, "snap_check_path" },
320 { SMB_VFS_OP_SNAP_CREATE, "snap_create" },
321 { SMB_VFS_OP_SNAP_DELETE, "snap_delete" },
322 { SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND, "get_dos_attributes_send" },
323 { SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV, "get_dos_attributes_recv" },
324 { SMB_VFS_OP_FGET_DOS_ATTRIBUTES, "fget_dos_attributes" },
325 { SMB_VFS_OP_FSET_DOS_ATTRIBUTES, "fset_dos_attributes" },
326 { SMB_VFS_OP_FGET_NT_ACL, "fget_nt_acl" },
327 { SMB_VFS_OP_GET_NT_ACL_AT, "get_nt_acl_at" },
328 { SMB_VFS_OP_FSET_NT_ACL, "fset_nt_acl" },
329 { SMB_VFS_OP_AUDIT_FILE, "audit_file" },
330 { SMB_VFS_OP_SYS_ACL_GET_FILE, "sys_acl_get_file" },
331 { SMB_VFS_OP_SYS_ACL_GET_FD, "sys_acl_get_fd" },
332 { SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE, "sys_acl_blob_get_file" },
333 { SMB_VFS_OP_SYS_ACL_BLOB_GET_FD, "sys_acl_blob_get_fd" },
334 { SMB_VFS_OP_SYS_ACL_SET_FD, "sys_acl_set_fd" },
335 { SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE, "sys_acl_delete_def_file" },
336 { SMB_VFS_OP_GETXATTR, "getxattr" },
337 { SMB_VFS_OP_GETXATTRAT_SEND, "getxattrat_send" },
338 { SMB_VFS_OP_GETXATTRAT_RECV, "getxattrat_recv" },
339 { SMB_VFS_OP_FGETXATTR, "fgetxattr" },
340 { SMB_VFS_OP_FLISTXATTR, "flistxattr" },
341 { SMB_VFS_OP_REMOVEXATTR, "removexattr" },
342 { SMB_VFS_OP_FREMOVEXATTR, "fremovexattr" },
343 { SMB_VFS_OP_FSETXATTR, "fsetxattr" },
344 { SMB_VFS_OP_AIO_FORCE, "aio_force" },
345 { SMB_VFS_OP_IS_OFFLINE, "is_offline" },
346 { SMB_VFS_OP_SET_OFFLINE, "set_offline" },
347 { SMB_VFS_OP_DURABLE_COOKIE, "durable_cookie" },
348 { SMB_VFS_OP_DURABLE_DISCONNECT, "durable_disconnect" },
349 { SMB_VFS_OP_DURABLE_RECONNECT, "durable_reconnect" },
350 { SMB_VFS_OP_READDIR_ATTR, "readdir_attr" },
351 { SMB_VFS_OP_LAST, NULL }
354 static int audit_syslog_facility(vfs_handle_struct *handle)
356 static const struct enum_list enum_log_facilities[] = {
358 { LOG_AUTH, "AUTH" },
361 { LOG_AUTHPRIV, "AUTHPRIV" },
364 { LOG_AUDIT, "AUDIT" },
367 { LOG_CONSOLE, "CONSOLE" },
370 { LOG_CRON, "CRON" },
373 { LOG_DAEMON, "DAEMON" },
379 { LOG_INSTALL, "INSTALL" },
382 { LOG_KERN, "KERN" },
385 { LOG_LAUNCHD, "LAUNCHD" },
388 { LOG_LFMT, "LFMT" },
394 { LOG_MAIL, "MAIL" },
397 { LOG_MEGASAFE, "MEGASAFE" },
400 { LOG_NETINFO, "NETINFO" },
403 { LOG_NEWS, "NEWS" },
405 #ifdef LOG_NFACILITIES
406 { LOG_NFACILITIES, "NFACILITIES" },
414 #ifdef LOG_REMOTEAUTH
415 { LOG_REMOTEAUTH, "REMOTEAUTH" },
418 { LOG_SECURITY, "SECURITY" },
421 { LOG_SYSLOG, "SYSLOG" },
424 { LOG_USER, "USER" },
427 { LOG_UUCP, "UUCP" },
429 { LOG_LOCAL0, "LOCAL0" },
430 { LOG_LOCAL1, "LOCAL1" },
431 { LOG_LOCAL2, "LOCAL2" },
432 { LOG_LOCAL3, "LOCAL3" },
433 { LOG_LOCAL4, "LOCAL4" },
434 { LOG_LOCAL5, "LOCAL5" },
435 { LOG_LOCAL6, "LOCAL6" },
436 { LOG_LOCAL7, "LOCAL7" },
442 facility = lp_parm_enum(SNUM(handle->conn), "full_audit", "facility", enum_log_facilities, LOG_USER);
447 static int audit_syslog_priority(vfs_handle_struct *handle)
449 static const struct enum_list enum_log_priorities[] = {
450 { LOG_EMERG, "EMERG" },
451 { LOG_ALERT, "ALERT" },
452 { LOG_CRIT, "CRIT" },
454 { LOG_WARNING, "WARNING" },
455 { LOG_NOTICE, "NOTICE" },
456 { LOG_INFO, "INFO" },
457 { LOG_DEBUG, "DEBUG" },
463 priority = lp_parm_enum(SNUM(handle->conn), "full_audit", "priority",
464 enum_log_priorities, LOG_NOTICE);
465 if (priority == -1) {
466 priority = LOG_WARNING;
472 static char *audit_prefix(TALLOC_CTX *ctx, connection_struct *conn)
474 const struct loadparm_substitution *lp_sub =
475 loadparm_s3_global_substitution();
479 prefix = talloc_strdup(ctx,
480 lp_parm_const_string(SNUM(conn), "full_audit",
485 result = talloc_sub_full(ctx,
486 lp_servicename(talloc_tos(), lp_sub, SNUM(conn)),
487 conn->session_info->unix_info->unix_name,
489 conn->session_info->unix_token->gid,
490 conn->session_info->unix_info->sanitized_username,
491 conn->session_info->info->domain_name,
497 static bool log_success(struct vfs_full_audit_private_data *pd, vfs_op_type op)
499 if (pd->success_ops == NULL) {
503 return bitmap_query(pd->success_ops, op);
506 static bool log_failure(struct vfs_full_audit_private_data *pd, vfs_op_type op)
508 if (pd->failure_ops == NULL)
511 return bitmap_query(pd->failure_ops, op);
514 static struct bitmap *init_bitmap(TALLOC_CTX *mem_ctx, const char **ops)
522 bm = bitmap_talloc(mem_ctx, SMB_VFS_OP_LAST);
524 DEBUG(0, ("Could not alloc bitmap -- "
525 "defaulting to logging everything\n"));
529 for (; *ops != NULL; ops += 1) {
534 if (strequal(*ops, "all")) {
535 for (i=0; i<SMB_VFS_OP_LAST; i++) {
541 if (strequal(*ops, "none")) {
551 for (i=0; i<SMB_VFS_OP_LAST; i++) {
552 if ((vfs_op_names[i].name == NULL)
553 || (vfs_op_names[i].type != i)) {
554 smb_panic("vfs_full_audit.c: name table not "
555 "in sync with vfs_op_type enums\n");
557 if (strequal(op, vfs_op_names[i].name)) {
566 if (i == SMB_VFS_OP_LAST) {
567 DEBUG(0, ("Could not find opname %s, logging all\n",
576 static const char *audit_opname(vfs_op_type op)
578 if (op >= SMB_VFS_OP_LAST)
579 return "INVALID VFS OP";
580 return vfs_op_names[op].name;
583 static TALLOC_CTX *tmp_do_log_ctx;
585 * Get us a temporary talloc context usable just for DEBUG arguments
587 static TALLOC_CTX *do_log_ctx(void)
589 if (tmp_do_log_ctx == NULL) {
590 tmp_do_log_ctx = talloc_named_const(NULL, 0, "do_log_ctx");
592 return tmp_do_log_ctx;
595 static void do_log(vfs_op_type op, bool success, vfs_handle_struct *handle,
596 const char *format, ...) PRINTF_ATTRIBUTE(4, 5);
598 static void do_log(vfs_op_type op, bool success, vfs_handle_struct *handle,
599 const char *format, ...)
601 struct vfs_full_audit_private_data *pd;
603 char *audit_pre = NULL;
607 SMB_VFS_HANDLE_GET_DATA(handle, pd,
608 struct vfs_full_audit_private_data,
611 if (success && (!log_success(pd, op)))
614 if (!success && (!log_failure(pd, op)))
618 fstrcpy(err_msg, "ok");
620 fstr_sprintf(err_msg, "fail (%s)", strerror(errno));
622 va_start(ap, format);
623 op_msg = talloc_vasprintf(talloc_tos(), format, ap);
630 audit_pre = audit_prefix(talloc_tos(), handle->conn);
636 * Specify the facility to interoperate with other syslog
637 * callers (smbd for example).
639 priority = pd->syslog_priority | pd->syslog_facility;
641 syslog(priority, "%s|%s|%s|%s\n",
642 audit_pre ? audit_pre : "",
643 audit_opname(op), err_msg, op_msg);
645 DEBUG(1, ("%s|%s|%s|%s\n",
646 audit_pre ? audit_pre : "",
647 audit_opname(op), err_msg, op_msg));
650 TALLOC_FREE(audit_pre);
652 TALLOC_FREE(tmp_do_log_ctx);
656 * Return a string using the do_log_ctx()
658 static const char *smb_fname_str_do_log(struct connection_struct *conn,
659 const struct smb_filename *smb_fname)
664 if (smb_fname == NULL) {
668 if (smb_fname->base_name[0] != '/') {
669 char *abs_name = NULL;
670 struct smb_filename *fname_copy = cp_smb_filename(
673 if (fname_copy == NULL) {
677 if (!ISDOT(smb_fname->base_name)) {
678 abs_name = talloc_asprintf(do_log_ctx(),
680 conn->cwd_fsp->fsp_name->base_name,
681 smb_fname->base_name);
683 abs_name = talloc_strdup(do_log_ctx(),
684 conn->cwd_fsp->fsp_name->base_name);
686 if (abs_name == NULL) {
689 fname_copy->base_name = abs_name;
690 smb_fname = fname_copy;
693 status = get_full_smb_filename(do_log_ctx(), smb_fname, &fname);
694 if (!NT_STATUS_IS_OK(status)) {
701 * Return an fsp debug string using the do_log_ctx()
703 static const char *fsp_str_do_log(const struct files_struct *fsp)
705 return smb_fname_str_do_log(fsp->conn, fsp->fsp_name);
708 /* Implementation of vfs_ops. Pass everything on to the default
709 operation but log event first. */
711 static int smb_full_audit_connect(vfs_handle_struct *handle,
712 const char *svc, const char *user)
715 const char *none[] = { "none" };
716 struct vfs_full_audit_private_data *pd = NULL;
718 result = SMB_VFS_NEXT_CONNECT(handle, svc, user);
723 pd = talloc_zero(handle, struct vfs_full_audit_private_data);
725 SMB_VFS_NEXT_DISCONNECT(handle);
729 pd->syslog_facility = audit_syslog_facility(handle);
730 if (pd->syslog_facility == -1) {
731 DEBUG(1, ("%s: Unknown facility %s\n", __func__,
732 lp_parm_const_string(SNUM(handle->conn),
733 "full_audit", "facility",
735 SMB_VFS_NEXT_DISCONNECT(handle);
739 pd->syslog_priority = audit_syslog_priority(handle);
741 pd->log_secdesc = lp_parm_bool(SNUM(handle->conn),
742 "full_audit", "log_secdesc", false);
744 pd->do_syslog = lp_parm_bool(SNUM(handle->conn),
745 "full_audit", "syslog", true);
749 openlog("smbd_audit", 0, pd->syslog_facility);
753 pd->success_ops = init_bitmap(
754 pd, lp_parm_string_list(SNUM(handle->conn), "full_audit",
756 pd->failure_ops = init_bitmap(
757 pd, lp_parm_string_list(SNUM(handle->conn), "full_audit",
760 /* Store the private data. */
761 SMB_VFS_HANDLE_SET_DATA(handle, pd, NULL,
762 struct vfs_full_audit_private_data, return -1);
764 do_log(SMB_VFS_OP_CONNECT, True, handle,
770 static void smb_full_audit_disconnect(vfs_handle_struct *handle)
772 const struct loadparm_substitution *lp_sub =
773 loadparm_s3_global_substitution();
775 SMB_VFS_NEXT_DISCONNECT(handle);
777 do_log(SMB_VFS_OP_DISCONNECT, True, handle,
778 "%s", lp_servicename(talloc_tos(), lp_sub, SNUM(handle->conn)));
780 /* The bitmaps will be disconnected when the private
784 static uint64_t smb_full_audit_disk_free(vfs_handle_struct *handle,
785 const struct smb_filename *smb_fname,
792 result = SMB_VFS_NEXT_DISK_FREE(handle, smb_fname, bsize, dfree, dsize);
794 /* Don't have a reasonable notion of failure here */
796 do_log(SMB_VFS_OP_DISK_FREE,
800 smb_fname_str_do_log(handle->conn, smb_fname));
805 static int smb_full_audit_get_quota(struct vfs_handle_struct *handle,
806 const struct smb_filename *smb_fname,
807 enum SMB_QUOTA_TYPE qtype,
813 result = SMB_VFS_NEXT_GET_QUOTA(handle, smb_fname, qtype, id, qt);
815 do_log(SMB_VFS_OP_GET_QUOTA,
819 smb_fname_str_do_log(handle->conn, smb_fname));
824 static int smb_full_audit_set_quota(struct vfs_handle_struct *handle,
825 enum SMB_QUOTA_TYPE qtype, unid_t id,
830 result = SMB_VFS_NEXT_SET_QUOTA(handle, qtype, id, qt);
832 do_log(SMB_VFS_OP_SET_QUOTA, (result >= 0), handle, "");
837 static int smb_full_audit_get_shadow_copy_data(struct vfs_handle_struct *handle,
838 struct files_struct *fsp,
839 struct shadow_copy_data *shadow_copy_data,
844 result = SMB_VFS_NEXT_GET_SHADOW_COPY_DATA(handle, fsp, shadow_copy_data, labels);
846 do_log(SMB_VFS_OP_GET_SHADOW_COPY_DATA, (result >= 0), handle, "");
851 static int smb_full_audit_statvfs(struct vfs_handle_struct *handle,
852 const struct smb_filename *smb_fname,
853 struct vfs_statvfs_struct *statbuf)
857 result = SMB_VFS_NEXT_STATVFS(handle, smb_fname, statbuf);
859 do_log(SMB_VFS_OP_STATVFS, (result >= 0), handle, "");
864 static uint32_t smb_full_audit_fs_capabilities(struct vfs_handle_struct *handle, enum timestamp_set_resolution *p_ts_res)
868 result = SMB_VFS_NEXT_FS_CAPABILITIES(handle, p_ts_res);
870 do_log(SMB_VFS_OP_FS_CAPABILITIES, true, handle, "");
875 static NTSTATUS smb_full_audit_get_dfs_referrals(
876 struct vfs_handle_struct *handle,
877 struct dfs_GetDFSReferral *r)
881 status = SMB_VFS_NEXT_GET_DFS_REFERRALS(handle, r);
883 do_log(SMB_VFS_OP_GET_DFS_REFERRALS, NT_STATUS_IS_OK(status),
889 static NTSTATUS smb_full_audit_create_dfs_pathat(struct vfs_handle_struct *handle,
890 struct files_struct *dirfsp,
891 const struct smb_filename *smb_fname,
892 const struct referral *reflist,
893 size_t referral_count)
896 struct smb_filename *full_fname = NULL;
898 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
901 if (full_fname == NULL) {
902 return NT_STATUS_NO_MEMORY;
905 status = SMB_VFS_NEXT_CREATE_DFS_PATHAT(handle,
911 do_log(SMB_VFS_OP_CREATE_DFS_PATHAT,
912 NT_STATUS_IS_OK(status),
915 smb_fname_str_do_log(handle->conn, full_fname));
917 TALLOC_FREE(full_fname);
921 static NTSTATUS smb_full_audit_read_dfs_pathat(struct vfs_handle_struct *handle,
923 struct files_struct *dirfsp,
924 struct smb_filename *smb_fname,
925 struct referral **ppreflist,
926 size_t *preferral_count)
930 status = SMB_VFS_NEXT_READ_DFS_PATHAT(handle,
937 do_log(SMB_VFS_OP_READ_DFS_PATHAT,
938 NT_STATUS_IS_OK(status),
941 smb_fname_str_do_log(handle->conn, smb_fname));
946 static NTSTATUS smb_full_audit_snap_check_path(struct vfs_handle_struct *handle,
948 const char *service_path,
953 status = SMB_VFS_NEXT_SNAP_CHECK_PATH(handle, mem_ctx, service_path,
955 do_log(SMB_VFS_OP_SNAP_CHECK_PATH, NT_STATUS_IS_OK(status),
961 static NTSTATUS smb_full_audit_snap_create(struct vfs_handle_struct *handle,
963 const char *base_volume,
971 status = SMB_VFS_NEXT_SNAP_CREATE(handle, mem_ctx, base_volume, tstamp,
972 rw, base_path, snap_path);
973 do_log(SMB_VFS_OP_SNAP_CREATE, NT_STATUS_IS_OK(status), handle, "");
978 static NTSTATUS smb_full_audit_snap_delete(struct vfs_handle_struct *handle,
985 status = SMB_VFS_NEXT_SNAP_DELETE(handle, mem_ctx, base_path,
987 do_log(SMB_VFS_OP_SNAP_DELETE, NT_STATUS_IS_OK(status), handle, "");
992 static DIR *smb_full_audit_fdopendir(vfs_handle_struct *handle,
993 files_struct *fsp, const char *mask, uint32_t attr)
997 result = SMB_VFS_NEXT_FDOPENDIR(handle, fsp, mask, attr);
999 do_log(SMB_VFS_OP_FDOPENDIR, (result != NULL), handle, "%s",
1000 fsp_str_do_log(fsp));
1005 static struct dirent *smb_full_audit_readdir(vfs_handle_struct *handle,
1006 struct files_struct *dirfsp,
1008 SMB_STRUCT_STAT *sbuf)
1010 struct dirent *result;
1012 result = SMB_VFS_NEXT_READDIR(handle, dirfsp, dirp, sbuf);
1014 /* This operation has no reasonable error condition
1015 * (End of dir is also failure), so always succeed.
1017 do_log(SMB_VFS_OP_READDIR, True, handle, "");
1022 static void smb_full_audit_seekdir(vfs_handle_struct *handle,
1023 DIR *dirp, long offset)
1025 SMB_VFS_NEXT_SEEKDIR(handle, dirp, offset);
1027 do_log(SMB_VFS_OP_SEEKDIR, True, handle, "");
1030 static long smb_full_audit_telldir(vfs_handle_struct *handle,
1035 result = SMB_VFS_NEXT_TELLDIR(handle, dirp);
1037 do_log(SMB_VFS_OP_TELLDIR, True, handle, "");
1042 static void smb_full_audit_rewinddir(vfs_handle_struct *handle,
1045 SMB_VFS_NEXT_REWINDDIR(handle, dirp);
1047 do_log(SMB_VFS_OP_REWINDDIR, True, handle, "");
1050 static int smb_full_audit_mkdirat(vfs_handle_struct *handle,
1051 struct files_struct *dirfsp,
1052 const struct smb_filename *smb_fname,
1055 struct smb_filename *full_fname = NULL;
1058 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1061 if (full_fname == NULL) {
1066 result = SMB_VFS_NEXT_MKDIRAT(handle,
1071 do_log(SMB_VFS_OP_MKDIRAT,
1075 smb_fname_str_do_log(handle->conn, full_fname));
1077 TALLOC_FREE(full_fname);
1082 static int smb_full_audit_closedir(vfs_handle_struct *handle,
1087 result = SMB_VFS_NEXT_CLOSEDIR(handle, dirp);
1089 do_log(SMB_VFS_OP_CLOSEDIR, (result >= 0), handle, "");
1094 static int smb_full_audit_openat(vfs_handle_struct *handle,
1095 const struct files_struct *dirfsp,
1096 const struct smb_filename *smb_fname,
1097 struct files_struct *fsp,
1103 result = SMB_VFS_NEXT_OPENAT(handle, dirfsp, smb_fname, fsp, flags, mode);
1105 do_log(SMB_VFS_OP_OPENAT, (result >= 0), handle, "%s|%s",
1106 ((flags & O_WRONLY) || (flags & O_RDWR))?"w":"r",
1107 fsp_str_do_log(fsp));
1112 static NTSTATUS smb_full_audit_create_file(vfs_handle_struct *handle,
1113 struct smb_request *req,
1114 struct smb_filename *smb_fname,
1115 uint32_t access_mask,
1116 uint32_t share_access,
1117 uint32_t create_disposition,
1118 uint32_t create_options,
1119 uint32_t file_attributes,
1120 uint32_t oplock_request,
1121 const struct smb2_lease *lease,
1122 uint64_t allocation_size,
1123 uint32_t private_flags,
1124 struct security_descriptor *sd,
1125 struct ea_list *ea_list,
1126 files_struct **result_fsp,
1128 const struct smb2_create_blobs *in_context_blobs,
1129 struct smb2_create_blobs *out_context_blobs)
1132 const char* str_create_disposition;
1134 switch (create_disposition) {
1135 case FILE_SUPERSEDE:
1136 str_create_disposition = "supersede";
1138 case FILE_OVERWRITE_IF:
1139 str_create_disposition = "overwrite_if";
1142 str_create_disposition = "open";
1144 case FILE_OVERWRITE:
1145 str_create_disposition = "overwrite";
1148 str_create_disposition = "create";
1151 str_create_disposition = "open_if";
1154 str_create_disposition = "unknown";
1157 result = SMB_VFS_NEXT_CREATE_FILE(
1158 handle, /* handle */
1160 smb_fname, /* fname */
1161 access_mask, /* access_mask */
1162 share_access, /* share_access */
1163 create_disposition, /* create_disposition*/
1164 create_options, /* create_options */
1165 file_attributes, /* file_attributes */
1166 oplock_request, /* oplock_request */
1168 allocation_size, /* allocation_size */
1171 ea_list, /* ea_list */
1172 result_fsp, /* result */
1174 in_context_blobs, out_context_blobs); /* create context */
1176 do_log(SMB_VFS_OP_CREATE_FILE, (NT_STATUS_IS_OK(result)), handle,
1177 "0x%x|%s|%s|%s", access_mask,
1178 create_options & FILE_DIRECTORY_FILE ? "dir" : "file",
1179 str_create_disposition,
1180 smb_fname_str_do_log(handle->conn, smb_fname));
1185 static int smb_full_audit_close(vfs_handle_struct *handle, files_struct *fsp)
1189 result = SMB_VFS_NEXT_CLOSE(handle, fsp);
1191 do_log(SMB_VFS_OP_CLOSE, (result >= 0), handle, "%s",
1192 fsp_str_do_log(fsp));
1197 static ssize_t smb_full_audit_pread(vfs_handle_struct *handle, files_struct *fsp,
1198 void *data, size_t n, off_t offset)
1202 result = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
1204 do_log(SMB_VFS_OP_PREAD, (result >= 0), handle, "%s",
1205 fsp_str_do_log(fsp));
1210 struct smb_full_audit_pread_state {
1211 vfs_handle_struct *handle;
1214 struct vfs_aio_state vfs_aio_state;
1217 static void smb_full_audit_pread_done(struct tevent_req *subreq);
1219 static struct tevent_req *smb_full_audit_pread_send(
1220 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1221 struct tevent_context *ev, struct files_struct *fsp,
1222 void *data, size_t n, off_t offset)
1224 struct tevent_req *req, *subreq;
1225 struct smb_full_audit_pread_state *state;
1227 req = tevent_req_create(mem_ctx, &state,
1228 struct smb_full_audit_pread_state);
1230 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
1231 fsp_str_do_log(fsp));
1234 state->handle = handle;
1237 subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
1239 if (tevent_req_nomem(subreq, req)) {
1240 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
1241 fsp_str_do_log(fsp));
1242 return tevent_req_post(req, ev);
1244 tevent_req_set_callback(subreq, smb_full_audit_pread_done, req);
1246 do_log(SMB_VFS_OP_PREAD_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1250 static void smb_full_audit_pread_done(struct tevent_req *subreq)
1252 struct tevent_req *req = tevent_req_callback_data(
1253 subreq, struct tevent_req);
1254 struct smb_full_audit_pread_state *state = tevent_req_data(
1255 req, struct smb_full_audit_pread_state);
1257 state->ret = SMB_VFS_PREAD_RECV(subreq, &state->vfs_aio_state);
1258 TALLOC_FREE(subreq);
1259 tevent_req_done(req);
1262 static ssize_t smb_full_audit_pread_recv(struct tevent_req *req,
1263 struct vfs_aio_state *vfs_aio_state)
1265 struct smb_full_audit_pread_state *state = tevent_req_data(
1266 req, struct smb_full_audit_pread_state);
1268 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1269 do_log(SMB_VFS_OP_PREAD_RECV, false, state->handle, "%s",
1270 fsp_str_do_log(state->fsp));
1274 do_log(SMB_VFS_OP_PREAD_RECV, (state->ret >= 0), state->handle, "%s",
1275 fsp_str_do_log(state->fsp));
1277 *vfs_aio_state = state->vfs_aio_state;
1281 static ssize_t smb_full_audit_pwrite(vfs_handle_struct *handle, files_struct *fsp,
1282 const void *data, size_t n,
1287 result = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
1289 do_log(SMB_VFS_OP_PWRITE, (result >= 0), handle, "%s",
1290 fsp_str_do_log(fsp));
1295 struct smb_full_audit_pwrite_state {
1296 vfs_handle_struct *handle;
1299 struct vfs_aio_state vfs_aio_state;
1302 static void smb_full_audit_pwrite_done(struct tevent_req *subreq);
1304 static struct tevent_req *smb_full_audit_pwrite_send(
1305 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1306 struct tevent_context *ev, struct files_struct *fsp,
1307 const void *data, size_t n, off_t offset)
1309 struct tevent_req *req, *subreq;
1310 struct smb_full_audit_pwrite_state *state;
1312 req = tevent_req_create(mem_ctx, &state,
1313 struct smb_full_audit_pwrite_state);
1315 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1316 fsp_str_do_log(fsp));
1319 state->handle = handle;
1322 subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
1324 if (tevent_req_nomem(subreq, req)) {
1325 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1326 fsp_str_do_log(fsp));
1327 return tevent_req_post(req, ev);
1329 tevent_req_set_callback(subreq, smb_full_audit_pwrite_done, req);
1331 do_log(SMB_VFS_OP_PWRITE_SEND, true, handle, "%s",
1332 fsp_str_do_log(fsp));
1336 static void smb_full_audit_pwrite_done(struct tevent_req *subreq)
1338 struct tevent_req *req = tevent_req_callback_data(
1339 subreq, struct tevent_req);
1340 struct smb_full_audit_pwrite_state *state = tevent_req_data(
1341 req, struct smb_full_audit_pwrite_state);
1343 state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->vfs_aio_state);
1344 TALLOC_FREE(subreq);
1345 tevent_req_done(req);
1348 static ssize_t smb_full_audit_pwrite_recv(struct tevent_req *req,
1349 struct vfs_aio_state *vfs_aio_state)
1351 struct smb_full_audit_pwrite_state *state = tevent_req_data(
1352 req, struct smb_full_audit_pwrite_state);
1354 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1355 do_log(SMB_VFS_OP_PWRITE_RECV, false, state->handle, "%s",
1356 fsp_str_do_log(state->fsp));
1360 do_log(SMB_VFS_OP_PWRITE_RECV, (state->ret >= 0), state->handle, "%s",
1361 fsp_str_do_log(state->fsp));
1363 *vfs_aio_state = state->vfs_aio_state;
1367 static off_t smb_full_audit_lseek(vfs_handle_struct *handle, files_struct *fsp,
1368 off_t offset, int whence)
1372 result = SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence);
1374 do_log(SMB_VFS_OP_LSEEK, (result != (ssize_t)-1), handle,
1375 "%s", fsp_str_do_log(fsp));
1380 static ssize_t smb_full_audit_sendfile(vfs_handle_struct *handle, int tofd,
1381 files_struct *fromfsp,
1382 const DATA_BLOB *hdr, off_t offset,
1387 result = SMB_VFS_NEXT_SENDFILE(handle, tofd, fromfsp, hdr, offset, n);
1389 do_log(SMB_VFS_OP_SENDFILE, (result >= 0), handle,
1390 "%s", fsp_str_do_log(fromfsp));
1395 static ssize_t smb_full_audit_recvfile(vfs_handle_struct *handle, int fromfd,
1396 files_struct *tofsp,
1402 result = SMB_VFS_NEXT_RECVFILE(handle, fromfd, tofsp, offset, n);
1404 do_log(SMB_VFS_OP_RECVFILE, (result >= 0), handle,
1405 "%s", fsp_str_do_log(tofsp));
1410 static int smb_full_audit_renameat(vfs_handle_struct *handle,
1411 files_struct *srcfsp,
1412 const struct smb_filename *smb_fname_src,
1413 files_struct *dstfsp,
1414 const struct smb_filename *smb_fname_dst)
1418 result = SMB_VFS_NEXT_RENAMEAT(handle,
1424 do_log(SMB_VFS_OP_RENAMEAT, (result >= 0), handle, "%s|%s",
1425 smb_fname_str_do_log(handle->conn, smb_fname_src),
1426 smb_fname_str_do_log(handle->conn, smb_fname_dst));
1431 struct smb_full_audit_fsync_state {
1432 vfs_handle_struct *handle;
1435 struct vfs_aio_state vfs_aio_state;
1438 static void smb_full_audit_fsync_done(struct tevent_req *subreq);
1440 static struct tevent_req *smb_full_audit_fsync_send(
1441 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1442 struct tevent_context *ev, struct files_struct *fsp)
1444 struct tevent_req *req, *subreq;
1445 struct smb_full_audit_fsync_state *state;
1447 req = tevent_req_create(mem_ctx, &state,
1448 struct smb_full_audit_fsync_state);
1450 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1451 fsp_str_do_log(fsp));
1454 state->handle = handle;
1457 subreq = SMB_VFS_NEXT_FSYNC_SEND(state, ev, handle, fsp);
1458 if (tevent_req_nomem(subreq, req)) {
1459 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1460 fsp_str_do_log(fsp));
1461 return tevent_req_post(req, ev);
1463 tevent_req_set_callback(subreq, smb_full_audit_fsync_done, req);
1465 do_log(SMB_VFS_OP_FSYNC_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1469 static void smb_full_audit_fsync_done(struct tevent_req *subreq)
1471 struct tevent_req *req = tevent_req_callback_data(
1472 subreq, struct tevent_req);
1473 struct smb_full_audit_fsync_state *state = tevent_req_data(
1474 req, struct smb_full_audit_fsync_state);
1476 state->ret = SMB_VFS_FSYNC_RECV(subreq, &state->vfs_aio_state);
1477 TALLOC_FREE(subreq);
1478 tevent_req_done(req);
1481 static int smb_full_audit_fsync_recv(struct tevent_req *req,
1482 struct vfs_aio_state *vfs_aio_state)
1484 struct smb_full_audit_fsync_state *state = tevent_req_data(
1485 req, struct smb_full_audit_fsync_state);
1487 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1488 do_log(SMB_VFS_OP_FSYNC_RECV, false, state->handle, "%s",
1489 fsp_str_do_log(state->fsp));
1493 do_log(SMB_VFS_OP_FSYNC_RECV, (state->ret >= 0), state->handle, "%s",
1494 fsp_str_do_log(state->fsp));
1496 *vfs_aio_state = state->vfs_aio_state;
1500 static int smb_full_audit_stat(vfs_handle_struct *handle,
1501 struct smb_filename *smb_fname)
1505 result = SMB_VFS_NEXT_STAT(handle, smb_fname);
1507 do_log(SMB_VFS_OP_STAT, (result >= 0), handle, "%s",
1508 smb_fname_str_do_log(handle->conn, smb_fname));
1513 static int smb_full_audit_fstat(vfs_handle_struct *handle, files_struct *fsp,
1514 SMB_STRUCT_STAT *sbuf)
1518 result = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1520 do_log(SMB_VFS_OP_FSTAT, (result >= 0), handle, "%s",
1521 fsp_str_do_log(fsp));
1526 static int smb_full_audit_lstat(vfs_handle_struct *handle,
1527 struct smb_filename *smb_fname)
1531 result = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
1533 do_log(SMB_VFS_OP_LSTAT, (result >= 0), handle, "%s",
1534 smb_fname_str_do_log(handle->conn, smb_fname));
1539 static uint64_t smb_full_audit_get_alloc_size(vfs_handle_struct *handle,
1540 files_struct *fsp, const SMB_STRUCT_STAT *sbuf)
1544 result = SMB_VFS_NEXT_GET_ALLOC_SIZE(handle, fsp, sbuf);
1546 do_log(SMB_VFS_OP_GET_ALLOC_SIZE, (result != (uint64_t)-1), handle,
1547 "%llu", (unsigned long long)result);
1552 static int smb_full_audit_unlinkat(vfs_handle_struct *handle,
1553 struct files_struct *dirfsp,
1554 const struct smb_filename *smb_fname,
1557 struct smb_filename *full_fname = NULL;
1560 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1563 if (full_fname == NULL) {
1567 result = SMB_VFS_NEXT_UNLINKAT(handle,
1572 do_log(SMB_VFS_OP_UNLINKAT, (result >= 0), handle, "%s",
1573 smb_fname_str_do_log(handle->conn, full_fname));
1575 TALLOC_FREE(full_fname);
1579 static int smb_full_audit_fchmod(vfs_handle_struct *handle, files_struct *fsp,
1584 result = SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1586 do_log(SMB_VFS_OP_FCHMOD, (result >= 0), handle,
1587 "%s|%o", fsp_str_do_log(fsp), mode);
1592 static int smb_full_audit_fchown(vfs_handle_struct *handle, files_struct *fsp,
1593 uid_t uid, gid_t gid)
1597 result = SMB_VFS_NEXT_FCHOWN(handle, fsp, uid, gid);
1599 do_log(SMB_VFS_OP_FCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1600 fsp_str_do_log(fsp), (long int)uid, (long int)gid);
1605 static int smb_full_audit_lchown(vfs_handle_struct *handle,
1606 const struct smb_filename *smb_fname,
1612 result = SMB_VFS_NEXT_LCHOWN(handle, smb_fname, uid, gid);
1614 do_log(SMB_VFS_OP_LCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1615 smb_fname->base_name, (long int)uid, (long int)gid);
1620 static int smb_full_audit_chdir(vfs_handle_struct *handle,
1621 const struct smb_filename *smb_fname)
1625 result = SMB_VFS_NEXT_CHDIR(handle, smb_fname);
1627 do_log(SMB_VFS_OP_CHDIR,
1631 smb_fname_str_do_log(handle->conn, smb_fname));
1636 static struct smb_filename *smb_full_audit_getwd(vfs_handle_struct *handle,
1639 struct smb_filename *result;
1641 result = SMB_VFS_NEXT_GETWD(handle, ctx);
1643 do_log(SMB_VFS_OP_GETWD, (result != NULL), handle, "%s",
1644 result == NULL? "" : result->base_name);
1649 static int smb_full_audit_fntimes(vfs_handle_struct *handle,
1651 struct smb_file_time *ft)
1654 time_t create_time = convert_timespec_to_time_t(ft->create_time);
1655 time_t atime = convert_timespec_to_time_t(ft->atime);
1656 time_t mtime = convert_timespec_to_time_t(ft->mtime);
1657 time_t ctime = convert_timespec_to_time_t(ft->ctime);
1658 const char *create_time_str = "";
1659 const char *atime_str = "";
1660 const char *mtime_str = "";
1661 const char *ctime_str = "";
1662 TALLOC_CTX *frame = talloc_stackframe();
1664 if (frame == NULL) {
1669 result = SMB_VFS_NEXT_FNTIMES(handle, fsp, ft);
1671 if (create_time > 0) {
1672 create_time_str = timestring(frame, create_time);
1675 atime_str = timestring(frame, atime);
1678 mtime_str = timestring(frame, mtime);
1681 ctime_str = timestring(frame, ctime);
1684 do_log(SMB_VFS_OP_FNTIMES,
1688 fsp_str_do_log(fsp),
1699 static int smb_full_audit_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
1704 result = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1706 do_log(SMB_VFS_OP_FTRUNCATE, (result >= 0), handle,
1707 "%s", fsp_str_do_log(fsp));
1712 static int smb_full_audit_fallocate(vfs_handle_struct *handle, files_struct *fsp,
1719 result = SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
1721 do_log(SMB_VFS_OP_FALLOCATE, (result >= 0), handle,
1722 "%s", fsp_str_do_log(fsp));
1727 static bool smb_full_audit_lock(vfs_handle_struct *handle, files_struct *fsp,
1728 int op, off_t offset, off_t count, int type)
1732 result = SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type);
1734 do_log(SMB_VFS_OP_LOCK, result, handle, "%s", fsp_str_do_log(fsp));
1739 static int smb_full_audit_kernel_flock(struct vfs_handle_struct *handle,
1740 struct files_struct *fsp,
1741 uint32_t share_access,
1742 uint32_t access_mask)
1746 result = SMB_VFS_NEXT_KERNEL_FLOCK(handle,
1751 do_log(SMB_VFS_OP_KERNEL_FLOCK, (result >= 0), handle, "%s",
1752 fsp_str_do_log(fsp));
1757 static int smb_full_audit_fcntl(struct vfs_handle_struct *handle,
1758 struct files_struct *fsp,
1759 int cmd, va_list cmd_arg)
1762 va_list dup_cmd_arg;
1765 va_copy(dup_cmd_arg, cmd_arg);
1766 arg = va_arg(dup_cmd_arg, void *);
1767 result = SMB_VFS_NEXT_FCNTL(handle, fsp, cmd, arg);
1768 va_end(dup_cmd_arg);
1770 do_log(SMB_VFS_OP_FCNTL, (result >= 0), handle, "%s",
1771 fsp_str_do_log(fsp));
1776 static int smb_full_audit_linux_setlease(vfs_handle_struct *handle, files_struct *fsp,
1781 result = SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
1783 do_log(SMB_VFS_OP_LINUX_SETLEASE, (result >= 0), handle, "%s",
1784 fsp_str_do_log(fsp));
1789 static bool smb_full_audit_getlock(vfs_handle_struct *handle, files_struct *fsp,
1790 off_t *poffset, off_t *pcount, int *ptype, pid_t *ppid)
1794 result = SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype, ppid);
1796 do_log(SMB_VFS_OP_GETLOCK, result, handle, "%s", fsp_str_do_log(fsp));
1801 static int smb_full_audit_symlinkat(vfs_handle_struct *handle,
1802 const struct smb_filename *link_contents,
1803 struct files_struct *dirfsp,
1804 const struct smb_filename *new_smb_fname)
1806 struct smb_filename *full_fname = NULL;
1809 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1812 if (full_fname == NULL) {
1816 result = SMB_VFS_NEXT_SYMLINKAT(handle,
1821 do_log(SMB_VFS_OP_SYMLINKAT,
1825 link_contents->base_name,
1826 smb_fname_str_do_log(handle->conn, full_fname));
1828 TALLOC_FREE(full_fname);
1833 static int smb_full_audit_readlinkat(vfs_handle_struct *handle,
1834 const struct files_struct *dirfsp,
1835 const struct smb_filename *smb_fname,
1839 struct smb_filename *full_fname = NULL;
1842 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1845 if (full_fname == NULL) {
1849 result = SMB_VFS_NEXT_READLINKAT(handle,
1855 do_log(SMB_VFS_OP_READLINKAT,
1859 smb_fname_str_do_log(handle->conn, full_fname));
1861 TALLOC_FREE(full_fname);
1866 static int smb_full_audit_linkat(vfs_handle_struct *handle,
1867 files_struct *srcfsp,
1868 const struct smb_filename *old_smb_fname,
1869 files_struct *dstfsp,
1870 const struct smb_filename *new_smb_fname,
1873 struct smb_filename *old_full_fname = NULL;
1874 struct smb_filename *new_full_fname = NULL;
1877 old_full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1880 if (old_full_fname == NULL) {
1883 new_full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1886 if (new_full_fname == NULL) {
1887 TALLOC_FREE(old_full_fname);
1890 result = SMB_VFS_NEXT_LINKAT(handle,
1897 do_log(SMB_VFS_OP_LINKAT,
1901 smb_fname_str_do_log(handle->conn, old_full_fname),
1902 smb_fname_str_do_log(handle->conn, new_full_fname));
1904 TALLOC_FREE(old_full_fname);
1905 TALLOC_FREE(new_full_fname);
1910 static int smb_full_audit_mknodat(vfs_handle_struct *handle,
1911 files_struct *dirfsp,
1912 const struct smb_filename *smb_fname,
1916 struct smb_filename *full_fname = NULL;
1919 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
1922 if (full_fname == NULL) {
1926 result = SMB_VFS_NEXT_MKNODAT(handle,
1932 do_log(SMB_VFS_OP_MKNODAT,
1936 smb_fname_str_do_log(handle->conn, full_fname));
1938 TALLOC_FREE(full_fname);
1943 static struct smb_filename *smb_full_audit_realpath(vfs_handle_struct *handle,
1945 const struct smb_filename *smb_fname)
1947 struct smb_filename *result_fname = NULL;
1949 result_fname = SMB_VFS_NEXT_REALPATH(handle, ctx, smb_fname);
1951 do_log(SMB_VFS_OP_REALPATH,
1952 (result_fname != NULL),
1955 smb_fname_str_do_log(handle->conn, smb_fname));
1957 return result_fname;
1960 static int smb_full_audit_chflags(vfs_handle_struct *handle,
1961 const struct smb_filename *smb_fname,
1966 result = SMB_VFS_NEXT_CHFLAGS(handle, smb_fname, flags);
1968 do_log(SMB_VFS_OP_CHFLAGS,
1972 smb_fname_str_do_log(handle->conn, smb_fname));
1977 static struct file_id smb_full_audit_file_id_create(struct vfs_handle_struct *handle,
1978 const SMB_STRUCT_STAT *sbuf)
1980 struct file_id id_zero = { 0 };
1981 struct file_id result;
1982 struct file_id_buf idbuf;
1984 result = SMB_VFS_NEXT_FILE_ID_CREATE(handle, sbuf);
1986 do_log(SMB_VFS_OP_FILE_ID_CREATE,
1987 !file_id_equal(&id_zero, &result),
1990 file_id_str_buf(result, &idbuf));
1995 static uint64_t smb_full_audit_fs_file_id(struct vfs_handle_struct *handle,
1996 const SMB_STRUCT_STAT *sbuf)
2000 result = SMB_VFS_NEXT_FS_FILE_ID(handle, sbuf);
2002 do_log(SMB_VFS_OP_FS_FILE_ID,
2004 handle, "%" PRIu64, result);
2009 static NTSTATUS smb_full_audit_fstreaminfo(vfs_handle_struct *handle,
2010 struct files_struct *fsp,
2011 TALLOC_CTX *mem_ctx,
2012 unsigned int *pnum_streams,
2013 struct stream_struct **pstreams)
2017 result = SMB_VFS_NEXT_FSTREAMINFO(handle, fsp, mem_ctx,
2018 pnum_streams, pstreams);
2020 do_log(SMB_VFS_OP_FSTREAMINFO,
2021 NT_STATUS_IS_OK(result),
2024 smb_fname_str_do_log(handle->conn, fsp->fsp_name));
2029 static int smb_full_audit_get_real_filename(struct vfs_handle_struct *handle,
2030 const struct smb_filename *path,
2032 TALLOC_CTX *mem_ctx,
2037 result = SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name, mem_ctx,
2040 do_log(SMB_VFS_OP_GET_REAL_FILENAME, (result == 0), handle,
2042 path->base_name, name, (result == 0) ? *found_name : "");
2047 static const char *smb_full_audit_connectpath(vfs_handle_struct *handle,
2048 const struct smb_filename *smb_fname)
2052 result = SMB_VFS_NEXT_CONNECTPATH(handle, smb_fname);
2054 do_log(SMB_VFS_OP_CONNECTPATH,
2058 smb_fname_str_do_log(handle->conn, smb_fname));
2063 static NTSTATUS smb_full_audit_brl_lock_windows(struct vfs_handle_struct *handle,
2064 struct byte_range_lock *br_lck,
2065 struct lock_struct *plock)
2069 result = SMB_VFS_NEXT_BRL_LOCK_WINDOWS(handle, br_lck, plock);
2071 do_log(SMB_VFS_OP_BRL_LOCK_WINDOWS, NT_STATUS_IS_OK(result), handle,
2072 "%s:%llu-%llu. type=%d.",
2073 fsp_str_do_log(brl_fsp(br_lck)),
2074 (unsigned long long)plock->start,
2075 (unsigned long long)plock->size,
2081 static bool smb_full_audit_brl_unlock_windows(struct vfs_handle_struct *handle,
2082 struct byte_range_lock *br_lck,
2083 const struct lock_struct *plock)
2087 result = SMB_VFS_NEXT_BRL_UNLOCK_WINDOWS(handle, br_lck, plock);
2089 do_log(SMB_VFS_OP_BRL_UNLOCK_WINDOWS, (result == 0), handle,
2090 "%s:%llu-%llu:%d", fsp_str_do_log(brl_fsp(br_lck)),
2091 (unsigned long long)plock->start,
2092 (unsigned long long)plock->size,
2098 static bool smb_full_audit_strict_lock_check(struct vfs_handle_struct *handle,
2099 struct files_struct *fsp,
2100 struct lock_struct *plock)
2104 result = SMB_VFS_NEXT_STRICT_LOCK_CHECK(handle, fsp, plock);
2106 do_log(SMB_VFS_OP_STRICT_LOCK_CHECK, result, handle,
2107 "%s:%llu-%llu:%d", fsp_str_do_log(fsp),
2108 (unsigned long long)plock->start,
2109 (unsigned long long)plock->size,
2115 static NTSTATUS smb_full_audit_translate_name(struct vfs_handle_struct *handle,
2117 enum vfs_translate_direction direction,
2118 TALLOC_CTX *mem_ctx,
2123 result = SMB_VFS_NEXT_TRANSLATE_NAME(handle, name, direction, mem_ctx,
2126 do_log(SMB_VFS_OP_TRANSLATE_NAME, NT_STATUS_IS_OK(result), handle, "");
2131 static NTSTATUS smb_full_audit_fsctl(struct vfs_handle_struct *handle,
2132 struct files_struct *fsp,
2136 const uint8_t *_in_data,
2138 uint8_t **_out_data,
2139 uint32_t max_out_len,
2144 result = SMB_VFS_NEXT_FSCTL(handle,
2155 do_log(SMB_VFS_OP_FSCTL, NT_STATUS_IS_OK(result), handle, "");
2160 static struct tevent_req *smb_full_audit_offload_read_send(
2161 TALLOC_CTX *mem_ctx,
2162 struct tevent_context *ev,
2163 struct vfs_handle_struct *handle,
2164 struct files_struct *fsp,
2170 struct tevent_req *req = NULL;
2172 req = SMB_VFS_NEXT_OFFLOAD_READ_SEND(mem_ctx, ev, handle, fsp,
2173 fsctl, ttl, offset, to_copy);
2175 do_log(SMB_VFS_OP_OFFLOAD_READ_SEND, req, handle, "");
2180 static NTSTATUS smb_full_audit_offload_read_recv(
2181 struct tevent_req *req,
2182 struct vfs_handle_struct *handle,
2183 TALLOC_CTX *mem_ctx,
2184 DATA_BLOB *_token_blob)
2188 status = SMB_VFS_NEXT_OFFLOAD_READ_RECV(req, handle, mem_ctx,
2191 do_log(SMB_VFS_OP_OFFLOAD_READ_RECV, NT_STATUS_IS_OK(status), handle, "");
2196 static struct tevent_req *smb_full_audit_offload_write_send(struct vfs_handle_struct *handle,
2197 TALLOC_CTX *mem_ctx,
2198 struct tevent_context *ev,
2201 off_t transfer_offset,
2202 struct files_struct *dest_fsp,
2206 struct tevent_req *req;
2208 req = SMB_VFS_NEXT_OFFLOAD_WRITE_SEND(handle, mem_ctx, ev,
2209 fsctl, token, transfer_offset,
2210 dest_fsp, dest_off, num);
2212 do_log(SMB_VFS_OP_OFFLOAD_WRITE_SEND, req, handle, "");
2217 static NTSTATUS smb_full_audit_offload_write_recv(struct vfs_handle_struct *handle,
2218 struct tevent_req *req,
2223 result = SMB_VFS_NEXT_OFFLOAD_WRITE_RECV(handle, req, copied);
2225 do_log(SMB_VFS_OP_OFFLOAD_WRITE_RECV, NT_STATUS_IS_OK(result), handle, "");
2230 static NTSTATUS smb_full_audit_fget_compression(vfs_handle_struct *handle,
2231 TALLOC_CTX *mem_ctx,
2232 struct files_struct *fsp,
2233 uint16_t *_compression_fmt)
2237 result = SMB_VFS_NEXT_FGET_COMPRESSION(handle, mem_ctx, fsp,
2240 do_log(SMB_VFS_OP_FGET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
2242 fsp_str_do_log(fsp));
2247 static NTSTATUS smb_full_audit_set_compression(vfs_handle_struct *handle,
2248 TALLOC_CTX *mem_ctx,
2249 struct files_struct *fsp,
2250 uint16_t compression_fmt)
2254 result = SMB_VFS_NEXT_SET_COMPRESSION(handle, mem_ctx, fsp,
2257 do_log(SMB_VFS_OP_SET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
2258 "%s", fsp_str_do_log(fsp));
2263 static NTSTATUS smb_full_audit_readdir_attr(struct vfs_handle_struct *handle,
2264 const struct smb_filename *fname,
2265 TALLOC_CTX *mem_ctx,
2266 struct readdir_attr_data **pattr_data)
2270 status = SMB_VFS_NEXT_READDIR_ATTR(handle, fname, mem_ctx, pattr_data);
2272 do_log(SMB_VFS_OP_READDIR_ATTR, NT_STATUS_IS_OK(status), handle, "%s",
2273 smb_fname_str_do_log(handle->conn, fname));
2278 struct smb_full_audit_get_dos_attributes_state {
2279 struct vfs_aio_state aio_state;
2280 vfs_handle_struct *handle;
2281 files_struct *dir_fsp;
2282 const struct smb_filename *smb_fname;
2286 static void smb_full_audit_get_dos_attributes_done(struct tevent_req *subreq);
2288 static struct tevent_req *smb_full_audit_get_dos_attributes_send(
2289 TALLOC_CTX *mem_ctx,
2290 struct tevent_context *ev,
2291 struct vfs_handle_struct *handle,
2292 files_struct *dir_fsp,
2293 struct smb_filename *smb_fname)
2295 struct tevent_req *req = NULL;
2296 struct smb_full_audit_get_dos_attributes_state *state = NULL;
2297 struct tevent_req *subreq = NULL;
2299 req = tevent_req_create(mem_ctx, &state,
2300 struct smb_full_audit_get_dos_attributes_state);
2302 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2306 fsp_str_do_log(dir_fsp),
2307 smb_fname->base_name);
2310 *state = (struct smb_full_audit_get_dos_attributes_state) {
2313 .smb_fname = smb_fname,
2316 subreq = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES_SEND(mem_ctx,
2321 if (tevent_req_nomem(subreq, req)) {
2322 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2326 fsp_str_do_log(dir_fsp),
2327 smb_fname->base_name);
2328 return tevent_req_post(req, ev);
2330 tevent_req_set_callback(subreq,
2331 smb_full_audit_get_dos_attributes_done,
2334 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2338 fsp_str_do_log(dir_fsp),
2339 smb_fname->base_name);
2344 static void smb_full_audit_get_dos_attributes_done(struct tevent_req *subreq)
2346 struct tevent_req *req =
2347 tevent_req_callback_data(subreq,
2349 struct smb_full_audit_get_dos_attributes_state *state =
2350 tevent_req_data(req,
2351 struct smb_full_audit_get_dos_attributes_state);
2354 status = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES_RECV(subreq,
2357 TALLOC_FREE(subreq);
2358 if (tevent_req_nterror(req, status)) {
2362 tevent_req_done(req);
2366 static NTSTATUS smb_full_audit_get_dos_attributes_recv(struct tevent_req *req,
2367 struct vfs_aio_state *aio_state,
2370 struct smb_full_audit_get_dos_attributes_state *state =
2371 tevent_req_data(req,
2372 struct smb_full_audit_get_dos_attributes_state);
2375 if (tevent_req_is_nterror(req, &status)) {
2376 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV,
2380 fsp_str_do_log(state->dir_fsp),
2381 state->smb_fname->base_name);
2382 tevent_req_received(req);
2386 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV,
2390 fsp_str_do_log(state->dir_fsp),
2391 state->smb_fname->base_name);
2393 *aio_state = state->aio_state;
2394 *dosmode = state->dosmode;
2395 tevent_req_received(req);
2396 return NT_STATUS_OK;
2399 static NTSTATUS smb_full_audit_fget_dos_attributes(
2400 struct vfs_handle_struct *handle,
2401 struct files_struct *fsp,
2406 status = SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle,
2410 do_log(SMB_VFS_OP_FGET_DOS_ATTRIBUTES,
2411 NT_STATUS_IS_OK(status),
2414 fsp_str_do_log(fsp));
2419 static NTSTATUS smb_full_audit_fset_dos_attributes(
2420 struct vfs_handle_struct *handle,
2421 struct files_struct *fsp,
2426 status = SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle,
2430 do_log(SMB_VFS_OP_FSET_DOS_ATTRIBUTES,
2431 NT_STATUS_IS_OK(status),
2434 fsp_str_do_log(fsp));
2439 static NTSTATUS smb_full_audit_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
2440 uint32_t security_info,
2441 TALLOC_CTX *mem_ctx,
2442 struct security_descriptor **ppdesc)
2446 result = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
2449 do_log(SMB_VFS_OP_FGET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2450 "%s", fsp_str_do_log(fsp));
2455 static NTSTATUS smb_full_audit_get_nt_acl_at(vfs_handle_struct *handle,
2456 struct files_struct *dirfsp,
2457 const struct smb_filename *smb_fname,
2458 uint32_t security_info,
2459 TALLOC_CTX *mem_ctx,
2460 struct security_descriptor **ppdesc)
2464 result = SMB_VFS_NEXT_GET_NT_ACL_AT(handle,
2471 do_log(SMB_VFS_OP_GET_NT_ACL_AT,
2472 NT_STATUS_IS_OK(result),
2475 smb_fname_str_do_log(handle->conn, smb_fname));
2480 static NTSTATUS smb_full_audit_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
2481 uint32_t security_info_sent,
2482 const struct security_descriptor *psd)
2484 struct vfs_full_audit_private_data *pd;
2488 SMB_VFS_HANDLE_GET_DATA(handle, pd,
2489 struct vfs_full_audit_private_data,
2490 return NT_STATUS_INTERNAL_ERROR);
2492 if (pd->log_secdesc) {
2493 sd = sddl_encode(talloc_tos(), psd, get_global_sam_sid());
2496 result = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
2498 do_log(SMB_VFS_OP_FSET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2499 "%s [%s]", fsp_str_do_log(fsp), sd ? sd : "");
2506 static NTSTATUS smb_full_audit_audit_file(struct vfs_handle_struct *handle,
2507 struct smb_filename *file,
2508 struct security_acl *sacl,
2509 uint32_t access_requested,
2510 uint32_t access_denied)
2514 result = SMB_VFS_NEXT_AUDIT_FILE(handle,
2520 do_log(SMB_VFS_OP_AUDIT_FILE, NT_STATUS_IS_OK(result), handle,
2522 smb_fname_str_do_log(handle->conn, file));
2527 static SMB_ACL_T smb_full_audit_sys_acl_get_file(vfs_handle_struct *handle,
2528 const struct smb_filename *smb_fname,
2529 SMB_ACL_TYPE_T type,
2530 TALLOC_CTX *mem_ctx)
2534 result = SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, smb_fname,
2537 do_log(SMB_VFS_OP_SYS_ACL_GET_FILE,
2541 smb_fname_str_do_log(handle->conn, smb_fname));
2546 static SMB_ACL_T smb_full_audit_sys_acl_get_fd(vfs_handle_struct *handle,
2547 files_struct *fsp, TALLOC_CTX *mem_ctx)
2551 result = SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp, mem_ctx);
2553 do_log(SMB_VFS_OP_SYS_ACL_GET_FD, (result != NULL), handle,
2554 "%s", fsp_str_do_log(fsp));
2559 static int smb_full_audit_sys_acl_blob_get_file(vfs_handle_struct *handle,
2560 const struct smb_filename *smb_fname,
2561 TALLOC_CTX *mem_ctx,
2562 char **blob_description,
2567 result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FILE(handle, smb_fname,
2568 mem_ctx, blob_description, blob);
2570 do_log(SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE,
2574 smb_fname_str_do_log(handle->conn, smb_fname));
2579 static int smb_full_audit_sys_acl_blob_get_fd(vfs_handle_struct *handle,
2581 TALLOC_CTX *mem_ctx,
2582 char **blob_description,
2587 result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle, fsp, mem_ctx, blob_description, blob);
2589 do_log(SMB_VFS_OP_SYS_ACL_BLOB_GET_FD, (result >= 0), handle,
2590 "%s", fsp_str_do_log(fsp));
2595 static int smb_full_audit_sys_acl_set_fd(vfs_handle_struct *handle,
2596 struct files_struct *fsp,
2597 SMB_ACL_TYPE_T type,
2602 result = SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, type, theacl);
2604 do_log(SMB_VFS_OP_SYS_ACL_SET_FD, (result >= 0), handle,
2605 "%s", fsp_str_do_log(fsp));
2610 static int smb_full_audit_sys_acl_delete_def_file(vfs_handle_struct *handle,
2611 const struct smb_filename *smb_fname)
2615 result = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, smb_fname);
2617 do_log(SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE,
2621 smb_fname_str_do_log(handle->conn, smb_fname));
2626 static ssize_t smb_full_audit_getxattr(struct vfs_handle_struct *handle,
2627 const struct smb_filename *smb_fname,
2628 const char *name, void *value, size_t size)
2632 result = SMB_VFS_NEXT_GETXATTR(handle, smb_fname, name, value, size);
2634 do_log(SMB_VFS_OP_GETXATTR,
2638 smb_fname_str_do_log(handle->conn, smb_fname),
2644 struct smb_full_audit_getxattrat_state {
2645 struct vfs_aio_state aio_state;
2646 vfs_handle_struct *handle;
2647 files_struct *dir_fsp;
2648 const struct smb_filename *smb_fname;
2649 const char *xattr_name;
2651 uint8_t *xattr_value;
2654 static void smb_full_audit_getxattrat_done(struct tevent_req *subreq);
2656 static struct tevent_req *smb_full_audit_getxattrat_send(
2657 TALLOC_CTX *mem_ctx,
2658 struct tevent_context *ev,
2659 struct vfs_handle_struct *handle,
2660 files_struct *dir_fsp,
2661 const struct smb_filename *smb_fname,
2662 const char *xattr_name,
2665 struct tevent_req *req = NULL;
2666 struct tevent_req *subreq = NULL;
2667 struct smb_full_audit_getxattrat_state *state = NULL;
2669 req = tevent_req_create(mem_ctx, &state,
2670 struct smb_full_audit_getxattrat_state);
2672 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2676 fsp_str_do_log(dir_fsp),
2677 smb_fname->base_name,
2681 *state = (struct smb_full_audit_getxattrat_state) {
2684 .smb_fname = smb_fname,
2685 .xattr_name = xattr_name,
2688 subreq = SMB_VFS_NEXT_GETXATTRAT_SEND(state,
2695 if (tevent_req_nomem(subreq, req)) {
2696 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2700 fsp_str_do_log(dir_fsp),
2701 smb_fname->base_name,
2703 return tevent_req_post(req, ev);
2705 tevent_req_set_callback(subreq, smb_full_audit_getxattrat_done, req);
2707 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2711 fsp_str_do_log(dir_fsp),
2712 smb_fname->base_name,
2718 static void smb_full_audit_getxattrat_done(struct tevent_req *subreq)
2720 struct tevent_req *req = tevent_req_callback_data(
2721 subreq, struct tevent_req);
2722 struct smb_full_audit_getxattrat_state *state = tevent_req_data(
2723 req, struct smb_full_audit_getxattrat_state);
2725 state->xattr_size = SMB_VFS_NEXT_GETXATTRAT_RECV(subreq,
2728 &state->xattr_value);
2729 TALLOC_FREE(subreq);
2730 if (state->xattr_size == -1) {
2731 tevent_req_error(req, state->aio_state.error);
2735 tevent_req_done(req);
2738 static ssize_t smb_full_audit_getxattrat_recv(struct tevent_req *req,
2739 struct vfs_aio_state *aio_state,
2740 TALLOC_CTX *mem_ctx,
2741 uint8_t **xattr_value)
2743 struct smb_full_audit_getxattrat_state *state = tevent_req_data(
2744 req, struct smb_full_audit_getxattrat_state);
2747 if (tevent_req_is_unix_error(req, &aio_state->error)) {
2748 do_log(SMB_VFS_OP_GETXATTRAT_RECV,
2752 fsp_str_do_log(state->dir_fsp),
2753 state->smb_fname->base_name,
2755 tevent_req_received(req);
2759 do_log(SMB_VFS_OP_GETXATTRAT_RECV,
2763 fsp_str_do_log(state->dir_fsp),
2764 state->smb_fname->base_name,
2767 *aio_state = state->aio_state;
2768 xattr_size = state->xattr_size;
2769 if (xattr_value != NULL) {
2770 *xattr_value = talloc_move(mem_ctx, &state->xattr_value);
2773 tevent_req_received(req);
2777 static ssize_t smb_full_audit_fgetxattr(struct vfs_handle_struct *handle,
2778 struct files_struct *fsp,
2779 const char *name, void *value, size_t size)
2783 result = SMB_VFS_NEXT_FGETXATTR(handle, fsp, name, value, size);
2785 do_log(SMB_VFS_OP_FGETXATTR, (result >= 0), handle,
2786 "%s|%s", fsp_str_do_log(fsp), name);
2791 static ssize_t smb_full_audit_flistxattr(struct vfs_handle_struct *handle,
2792 struct files_struct *fsp, char *list,
2797 result = SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
2799 do_log(SMB_VFS_OP_FLISTXATTR, (result >= 0), handle,
2800 "%s", fsp_str_do_log(fsp));
2805 static int smb_full_audit_fremovexattr(struct vfs_handle_struct *handle,
2806 struct files_struct *fsp,
2811 result = SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, name);
2813 do_log(SMB_VFS_OP_FREMOVEXATTR, (result >= 0), handle,
2814 "%s|%s", fsp_str_do_log(fsp), name);
2819 static int smb_full_audit_fsetxattr(struct vfs_handle_struct *handle,
2820 struct files_struct *fsp, const char *name,
2821 const void *value, size_t size, int flags)
2825 result = SMB_VFS_NEXT_FSETXATTR(handle, fsp, name, value, size, flags);
2827 do_log(SMB_VFS_OP_FSETXATTR, (result >= 0), handle,
2828 "%s|%s", fsp_str_do_log(fsp), name);
2833 static bool smb_full_audit_aio_force(struct vfs_handle_struct *handle,
2834 struct files_struct *fsp)
2838 result = SMB_VFS_NEXT_AIO_FORCE(handle, fsp);
2839 do_log(SMB_VFS_OP_AIO_FORCE, result, handle,
2840 "%s", fsp_str_do_log(fsp));
2845 static NTSTATUS smb_full_audit_durable_cookie(struct vfs_handle_struct *handle,
2846 struct files_struct *fsp,
2847 TALLOC_CTX *mem_ctx,
2852 result = SMB_VFS_NEXT_DURABLE_COOKIE(handle,
2857 do_log(SMB_VFS_OP_DURABLE_COOKIE, NT_STATUS_IS_OK(result), handle,
2858 "%s", fsp_str_do_log(fsp));
2863 static NTSTATUS smb_full_audit_durable_disconnect(
2864 struct vfs_handle_struct *handle,
2865 struct files_struct *fsp,
2866 const DATA_BLOB old_cookie,
2867 TALLOC_CTX *mem_ctx,
2868 DATA_BLOB *new_cookie)
2872 result = SMB_VFS_NEXT_DURABLE_DISCONNECT(handle,
2878 do_log(SMB_VFS_OP_DURABLE_DISCONNECT, NT_STATUS_IS_OK(result), handle,
2879 "%s", fsp_str_do_log(fsp));
2884 static NTSTATUS smb_full_audit_durable_reconnect(
2885 struct vfs_handle_struct *handle,
2886 struct smb_request *smb1req,
2887 struct smbXsrv_open *op,
2888 const DATA_BLOB old_cookie,
2889 TALLOC_CTX *mem_ctx,
2890 struct files_struct **fsp,
2891 DATA_BLOB *new_cookie)
2895 result = SMB_VFS_NEXT_DURABLE_RECONNECT(handle,
2903 do_log(SMB_VFS_OP_DURABLE_RECONNECT,
2904 NT_STATUS_IS_OK(result),
2911 static struct vfs_fn_pointers vfs_full_audit_fns = {
2913 /* Disk operations */
2915 .connect_fn = smb_full_audit_connect,
2916 .disconnect_fn = smb_full_audit_disconnect,
2917 .disk_free_fn = smb_full_audit_disk_free,
2918 .get_quota_fn = smb_full_audit_get_quota,
2919 .set_quota_fn = smb_full_audit_set_quota,
2920 .get_shadow_copy_data_fn = smb_full_audit_get_shadow_copy_data,
2921 .statvfs_fn = smb_full_audit_statvfs,
2922 .fs_capabilities_fn = smb_full_audit_fs_capabilities,
2923 .get_dfs_referrals_fn = smb_full_audit_get_dfs_referrals,
2924 .create_dfs_pathat_fn = smb_full_audit_create_dfs_pathat,
2925 .read_dfs_pathat_fn = smb_full_audit_read_dfs_pathat,
2926 .fdopendir_fn = smb_full_audit_fdopendir,
2927 .readdir_fn = smb_full_audit_readdir,
2928 .seekdir_fn = smb_full_audit_seekdir,
2929 .telldir_fn = smb_full_audit_telldir,
2930 .rewind_dir_fn = smb_full_audit_rewinddir,
2931 .mkdirat_fn = smb_full_audit_mkdirat,
2932 .closedir_fn = smb_full_audit_closedir,
2933 .openat_fn = smb_full_audit_openat,
2934 .create_file_fn = smb_full_audit_create_file,
2935 .close_fn = smb_full_audit_close,
2936 .pread_fn = smb_full_audit_pread,
2937 .pread_send_fn = smb_full_audit_pread_send,
2938 .pread_recv_fn = smb_full_audit_pread_recv,
2939 .pwrite_fn = smb_full_audit_pwrite,
2940 .pwrite_send_fn = smb_full_audit_pwrite_send,
2941 .pwrite_recv_fn = smb_full_audit_pwrite_recv,
2942 .lseek_fn = smb_full_audit_lseek,
2943 .sendfile_fn = smb_full_audit_sendfile,
2944 .recvfile_fn = smb_full_audit_recvfile,
2945 .renameat_fn = smb_full_audit_renameat,
2946 .fsync_send_fn = smb_full_audit_fsync_send,
2947 .fsync_recv_fn = smb_full_audit_fsync_recv,
2948 .stat_fn = smb_full_audit_stat,
2949 .fstat_fn = smb_full_audit_fstat,
2950 .lstat_fn = smb_full_audit_lstat,
2951 .get_alloc_size_fn = smb_full_audit_get_alloc_size,
2952 .unlinkat_fn = smb_full_audit_unlinkat,
2953 .fchmod_fn = smb_full_audit_fchmod,
2954 .fchown_fn = smb_full_audit_fchown,
2955 .lchown_fn = smb_full_audit_lchown,
2956 .chdir_fn = smb_full_audit_chdir,
2957 .getwd_fn = smb_full_audit_getwd,
2958 .fntimes_fn = smb_full_audit_fntimes,
2959 .ftruncate_fn = smb_full_audit_ftruncate,
2960 .fallocate_fn = smb_full_audit_fallocate,
2961 .lock_fn = smb_full_audit_lock,
2962 .kernel_flock_fn = smb_full_audit_kernel_flock,
2963 .fcntl_fn = smb_full_audit_fcntl,
2964 .linux_setlease_fn = smb_full_audit_linux_setlease,
2965 .getlock_fn = smb_full_audit_getlock,
2966 .symlinkat_fn = smb_full_audit_symlinkat,
2967 .readlinkat_fn = smb_full_audit_readlinkat,
2968 .linkat_fn = smb_full_audit_linkat,
2969 .mknodat_fn = smb_full_audit_mknodat,
2970 .realpath_fn = smb_full_audit_realpath,
2971 .chflags_fn = smb_full_audit_chflags,
2972 .file_id_create_fn = smb_full_audit_file_id_create,
2973 .fs_file_id_fn = smb_full_audit_fs_file_id,
2974 .offload_read_send_fn = smb_full_audit_offload_read_send,
2975 .offload_read_recv_fn = smb_full_audit_offload_read_recv,
2976 .offload_write_send_fn = smb_full_audit_offload_write_send,
2977 .offload_write_recv_fn = smb_full_audit_offload_write_recv,
2978 .fget_compression_fn = smb_full_audit_fget_compression,
2979 .set_compression_fn = smb_full_audit_set_compression,
2980 .snap_check_path_fn = smb_full_audit_snap_check_path,
2981 .snap_create_fn = smb_full_audit_snap_create,
2982 .snap_delete_fn = smb_full_audit_snap_delete,
2983 .fstreaminfo_fn = smb_full_audit_fstreaminfo,
2984 .get_real_filename_fn = smb_full_audit_get_real_filename,
2985 .connectpath_fn = smb_full_audit_connectpath,
2986 .brl_lock_windows_fn = smb_full_audit_brl_lock_windows,
2987 .brl_unlock_windows_fn = smb_full_audit_brl_unlock_windows,
2988 .strict_lock_check_fn = smb_full_audit_strict_lock_check,
2989 .translate_name_fn = smb_full_audit_translate_name,
2990 .fsctl_fn = smb_full_audit_fsctl,
2991 .get_dos_attributes_send_fn = smb_full_audit_get_dos_attributes_send,
2992 .get_dos_attributes_recv_fn = smb_full_audit_get_dos_attributes_recv,
2993 .fget_dos_attributes_fn = smb_full_audit_fget_dos_attributes,
2994 .fset_dos_attributes_fn = smb_full_audit_fset_dos_attributes,
2995 .fget_nt_acl_fn = smb_full_audit_fget_nt_acl,
2996 .get_nt_acl_at_fn = smb_full_audit_get_nt_acl_at,
2997 .fset_nt_acl_fn = smb_full_audit_fset_nt_acl,
2998 .audit_file_fn = smb_full_audit_audit_file,
2999 .sys_acl_get_file_fn = smb_full_audit_sys_acl_get_file,
3000 .sys_acl_get_fd_fn = smb_full_audit_sys_acl_get_fd,
3001 .sys_acl_blob_get_file_fn = smb_full_audit_sys_acl_blob_get_file,
3002 .sys_acl_blob_get_fd_fn = smb_full_audit_sys_acl_blob_get_fd,
3003 .sys_acl_set_fd_fn = smb_full_audit_sys_acl_set_fd,
3004 .sys_acl_delete_def_file_fn = smb_full_audit_sys_acl_delete_def_file,
3005 .getxattr_fn = smb_full_audit_getxattr,
3006 .getxattrat_send_fn = smb_full_audit_getxattrat_send,
3007 .getxattrat_recv_fn = smb_full_audit_getxattrat_recv,
3008 .fgetxattr_fn = smb_full_audit_fgetxattr,
3009 .flistxattr_fn = smb_full_audit_flistxattr,
3010 .fremovexattr_fn = smb_full_audit_fremovexattr,
3011 .fsetxattr_fn = smb_full_audit_fsetxattr,
3012 .aio_force_fn = smb_full_audit_aio_force,
3013 .durable_cookie_fn = smb_full_audit_durable_cookie,
3014 .durable_disconnect_fn = smb_full_audit_durable_disconnect,
3015 .durable_reconnect_fn = smb_full_audit_durable_reconnect,
3016 .readdir_attr_fn = smb_full_audit_readdir_attr
3021 NTSTATUS vfs_full_audit_init(TALLOC_CTX *ctx)
3025 smb_vfs_assert_all_fns(&vfs_full_audit_fns, "full_audit");
3027 ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "full_audit",
3028 &vfs_full_audit_fns);
3030 if (!NT_STATUS_IS_OK(ret))
3033 vfs_full_audit_debug_level = debug_add_class("full_audit");
3034 if (vfs_full_audit_debug_level == -1) {
3035 vfs_full_audit_debug_level = DBGC_VFS;
3036 DEBUG(0, ("vfs_full_audit: Couldn't register custom debugging "
3039 DEBUG(10, ("vfs_full_audit: Debug class number of "
3040 "'full_audit': %d\n", vfs_full_audit_debug_level));