2 * Auditing VFS module for samba. Log selected file operations to syslog
5 * Copyright (C) Tim Potter, 1999-2000
6 * Copyright (C) Alexander Bokovoy, 2002
7 * Copyright (C) John H Terpstra, 2003
8 * Copyright (C) Stefan (metze) Metzmacher, 2003
9 * Copyright (C) Volker Lendecke, 2004
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, see <http://www.gnu.org/licenses/>.
26 * This module implements parseable logging for all Samba VFS operations.
28 * You use it as follows:
32 * vfs objects = full_audit
33 * full_audit:prefix = %u|%I
34 * full_audit:success = open opendir create_file
35 * full_audit:failure = all
37 * vfs op can be "all" which means log all operations.
38 * vfs op can be "none" which means no logging.
40 * This leads to syslog entries of the form:
41 * smbd_audit: nobody|192.168.234.1|opendir|ok|/tmp
42 * smbd_audit: nobody|192.168.234.1|create_file|fail (No such file or directory)|0x1|file|open|/ts/doesNotExist
43 * smbd_audit: nobody|192.168.234.1|open|ok|w|/tmp/file.txt
44 * smbd_audit: nobody|192.168.234.1|create_file|ok|0x3|file|open|/tmp/file.txt
46 * where "nobody" is the connected username and "192.168.234.1" is the
47 * client's IP address.
51 * prefix: A macro expansion template prepended to the syslog entry.
53 * success: A list of VFS operations for which a successful completion should
54 * be logged. Defaults to no logging at all. The special operation "all" logs
55 * - you guessed it - everything.
57 * failure: A list of VFS operations for which failure to complete should be
58 * logged. Defaults to logging everything.
63 #include "system/filesys.h"
64 #include "system/syslog.h"
65 #include "smbd/smbd.h"
66 #include "../librpc/gen_ndr/ndr_netlogon.h"
69 #include "lib/param/loadparm.h"
70 #include "lib/util/bitmap.h"
71 #include "lib/util/tevent_unix.h"
72 #include "libcli/security/sddl.h"
73 #include "passdb/machine_sid.h"
74 #include "lib/util/tevent_ntstatus.h"
76 static int vfs_full_audit_debug_level = DBGC_VFS;
78 struct vfs_full_audit_private_data {
79 struct bitmap *success_ops;
80 struct bitmap *failure_ops;
88 #define DBGC_CLASS vfs_full_audit_debug_level
90 typedef enum _vfs_op_type {
95 SMB_VFS_OP_CONNECT = 0,
96 SMB_VFS_OP_DISCONNECT,
100 SMB_VFS_OP_GET_SHADOW_COPY_DATA,
102 SMB_VFS_OP_FS_CAPABILITIES,
103 SMB_VFS_OP_GET_DFS_REFERRALS,
105 /* Directory operations */
108 SMB_VFS_OP_FDOPENDIR,
112 SMB_VFS_OP_REWINDDIR,
116 /* File operations */
119 SMB_VFS_OP_CREATE_FILE,
123 SMB_VFS_OP_PREAD_SEND,
124 SMB_VFS_OP_PREAD_RECV,
127 SMB_VFS_OP_PWRITE_SEND,
128 SMB_VFS_OP_PWRITE_RECV,
134 SMB_VFS_OP_FSYNC_SEND,
135 SMB_VFS_OP_FSYNC_RECV,
139 SMB_VFS_OP_GET_ALLOC_SIZE,
148 SMB_VFS_OP_FTRUNCATE,
149 SMB_VFS_OP_FALLOCATE,
151 SMB_VFS_OP_KERNEL_FLOCK,
153 SMB_VFS_OP_LINUX_SETLEASE,
155 SMB_VFS_OP_SYMLINKAT,
156 SMB_VFS_OP_READLINKAT,
161 SMB_VFS_OP_FILE_ID_CREATE,
162 SMB_VFS_OP_FS_FILE_ID,
163 SMB_VFS_OP_STREAMINFO,
164 SMB_VFS_OP_GET_REAL_FILENAME,
165 SMB_VFS_OP_CONNECTPATH,
166 SMB_VFS_OP_BRL_LOCK_WINDOWS,
167 SMB_VFS_OP_BRL_UNLOCK_WINDOWS,
168 SMB_VFS_OP_STRICT_LOCK_CHECK,
169 SMB_VFS_OP_TRANSLATE_NAME,
171 SMB_VFS_OP_OFFLOAD_READ_SEND,
172 SMB_VFS_OP_OFFLOAD_READ_RECV,
173 SMB_VFS_OP_OFFLOAD_WRITE_SEND,
174 SMB_VFS_OP_OFFLOAD_WRITE_RECV,
175 SMB_VFS_OP_GET_COMPRESSION,
176 SMB_VFS_OP_SET_COMPRESSION,
177 SMB_VFS_OP_SNAP_CHECK_PATH,
178 SMB_VFS_OP_SNAP_CREATE,
179 SMB_VFS_OP_SNAP_DELETE,
181 /* DOS attribute operations. */
182 SMB_VFS_OP_GET_DOS_ATTRIBUTES,
183 SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
184 SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV,
185 SMB_VFS_OP_FGET_DOS_ATTRIBUTES,
186 SMB_VFS_OP_SET_DOS_ATTRIBUTES,
187 SMB_VFS_OP_FSET_DOS_ATTRIBUTES,
189 /* NT ACL operations. */
191 SMB_VFS_OP_FGET_NT_ACL,
192 SMB_VFS_OP_GET_NT_ACL,
193 SMB_VFS_OP_FSET_NT_ACL,
194 SMB_VFS_OP_AUDIT_FILE,
196 /* POSIX ACL operations. */
198 SMB_VFS_OP_SYS_ACL_GET_FILE,
199 SMB_VFS_OP_SYS_ACL_GET_FD,
200 SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE,
201 SMB_VFS_OP_SYS_ACL_BLOB_GET_FD,
202 SMB_VFS_OP_SYS_ACL_SET_FILE,
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_LISTXATTR,
212 SMB_VFS_OP_FLISTXATTR,
213 SMB_VFS_OP_REMOVEXATTR,
214 SMB_VFS_OP_FREMOVEXATTR,
216 SMB_VFS_OP_FSETXATTR,
219 SMB_VFS_OP_AIO_FORCE,
221 /* offline operations */
222 SMB_VFS_OP_IS_OFFLINE,
223 SMB_VFS_OP_SET_OFFLINE,
225 /* Durable handle operations. */
226 SMB_VFS_OP_DURABLE_COOKIE,
227 SMB_VFS_OP_DURABLE_DISCONNECT,
228 SMB_VFS_OP_DURABLE_RECONNECT,
230 SMB_VFS_OP_READDIR_ATTR,
232 /* This should always be last enum value */
237 /* The following array *must* be in the same order as defined in vfs_op_type */
243 { SMB_VFS_OP_CONNECT, "connect" },
244 { SMB_VFS_OP_DISCONNECT, "disconnect" },
245 { SMB_VFS_OP_DISK_FREE, "disk_free" },
246 { SMB_VFS_OP_GET_QUOTA, "get_quota" },
247 { SMB_VFS_OP_SET_QUOTA, "set_quota" },
248 { SMB_VFS_OP_GET_SHADOW_COPY_DATA, "get_shadow_copy_data" },
249 { SMB_VFS_OP_STATVFS, "statvfs" },
250 { SMB_VFS_OP_FS_CAPABILITIES, "fs_capabilities" },
251 { SMB_VFS_OP_GET_DFS_REFERRALS, "get_dfs_referrals" },
252 { SMB_VFS_OP_OPENDIR, "opendir" },
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_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_CHMOD, "chmod" },
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_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_LINUX_SETLEASE, "linux_setlease" },
295 { SMB_VFS_OP_GETLOCK, "getlock" },
296 { SMB_VFS_OP_SYMLINKAT, "symlinkat" },
297 { SMB_VFS_OP_READLINKAT,"readlinkat" },
298 { SMB_VFS_OP_LINKAT, "linkat" },
299 { SMB_VFS_OP_MKNODAT, "mknodat" },
300 { SMB_VFS_OP_REALPATH, "realpath" },
301 { SMB_VFS_OP_CHFLAGS, "chflags" },
302 { SMB_VFS_OP_FILE_ID_CREATE, "file_id_create" },
303 { SMB_VFS_OP_FS_FILE_ID, "fs_file_id" },
304 { SMB_VFS_OP_STREAMINFO, "streaminfo" },
305 { SMB_VFS_OP_GET_REAL_FILENAME, "get_real_filename" },
306 { SMB_VFS_OP_CONNECTPATH, "connectpath" },
307 { SMB_VFS_OP_BRL_LOCK_WINDOWS, "brl_lock_windows" },
308 { SMB_VFS_OP_BRL_UNLOCK_WINDOWS, "brl_unlock_windows" },
309 { SMB_VFS_OP_STRICT_LOCK_CHECK, "strict_lock_check" },
310 { SMB_VFS_OP_TRANSLATE_NAME, "translate_name" },
311 { SMB_VFS_OP_FSCTL, "fsctl" },
312 { SMB_VFS_OP_OFFLOAD_READ_SEND, "offload_read_send" },
313 { SMB_VFS_OP_OFFLOAD_READ_RECV, "offload_read_recv" },
314 { SMB_VFS_OP_OFFLOAD_WRITE_SEND, "offload_write_send" },
315 { SMB_VFS_OP_OFFLOAD_WRITE_RECV, "offload_write_recv" },
316 { SMB_VFS_OP_GET_COMPRESSION, "get_compression" },
317 { SMB_VFS_OP_SET_COMPRESSION, "set_compression" },
318 { SMB_VFS_OP_SNAP_CHECK_PATH, "snap_check_path" },
319 { SMB_VFS_OP_SNAP_CREATE, "snap_create" },
320 { SMB_VFS_OP_SNAP_DELETE, "snap_delete" },
321 { SMB_VFS_OP_GET_DOS_ATTRIBUTES, "get_dos_attributes" },
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_SET_DOS_ATTRIBUTES, "set_dos_attributes" },
326 { SMB_VFS_OP_FSET_DOS_ATTRIBUTES, "fset_dos_attributes" },
327 { SMB_VFS_OP_FGET_NT_ACL, "fget_nt_acl" },
328 { SMB_VFS_OP_GET_NT_ACL, "get_nt_acl" },
329 { SMB_VFS_OP_FSET_NT_ACL, "fset_nt_acl" },
330 { SMB_VFS_OP_AUDIT_FILE, "audit_file" },
331 { SMB_VFS_OP_SYS_ACL_GET_FILE, "sys_acl_get_file" },
332 { SMB_VFS_OP_SYS_ACL_GET_FD, "sys_acl_get_fd" },
333 { SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE, "sys_acl_blob_get_file" },
334 { SMB_VFS_OP_SYS_ACL_BLOB_GET_FD, "sys_acl_blob_get_fd" },
335 { SMB_VFS_OP_SYS_ACL_SET_FILE, "sys_acl_set_file" },
336 { SMB_VFS_OP_SYS_ACL_SET_FD, "sys_acl_set_fd" },
337 { SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE, "sys_acl_delete_def_file" },
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_LISTXATTR, "listxattr" },
343 { SMB_VFS_OP_FLISTXATTR, "flistxattr" },
344 { SMB_VFS_OP_REMOVEXATTR, "removexattr" },
345 { SMB_VFS_OP_FREMOVEXATTR, "fremovexattr" },
346 { SMB_VFS_OP_SETXATTR, "setxattr" },
347 { SMB_VFS_OP_FSETXATTR, "fsetxattr" },
348 { SMB_VFS_OP_AIO_FORCE, "aio_force" },
349 { SMB_VFS_OP_IS_OFFLINE, "is_offline" },
350 { SMB_VFS_OP_SET_OFFLINE, "set_offline" },
351 { SMB_VFS_OP_DURABLE_COOKIE, "durable_cookie" },
352 { SMB_VFS_OP_DURABLE_DISCONNECT, "durable_disconnect" },
353 { SMB_VFS_OP_DURABLE_RECONNECT, "durable_reconnect" },
354 { SMB_VFS_OP_READDIR_ATTR, "readdir_attr" },
355 { SMB_VFS_OP_LAST, NULL }
358 static int audit_syslog_facility(vfs_handle_struct *handle)
360 static const struct enum_list enum_log_facilities[] = {
362 { LOG_AUTH, "AUTH" },
365 { LOG_AUTHPRIV, "AUTHPRIV" },
368 { LOG_AUDIT, "AUDIT" },
371 { LOG_CONSOLE, "CONSOLE" },
374 { LOG_CRON, "CRON" },
377 { LOG_DAEMON, "DAEMON" },
383 { LOG_INSTALL, "INSTALL" },
386 { LOG_KERN, "KERN" },
389 { LOG_LAUNCHD, "LAUNCHD" },
392 { LOG_LFMT, "LFMT" },
398 { LOG_MAIL, "MAIL" },
401 { LOG_MEGASAFE, "MEGASAFE" },
404 { LOG_NETINFO, "NETINFO" },
407 { LOG_NEWS, "NEWS" },
409 #ifdef LOG_NFACILITIES
410 { LOG_NFACILITIES, "NFACILITIES" },
418 #ifdef LOG_REMOTEAUTH
419 { LOG_REMOTEAUTH, "REMOTEAUTH" },
422 { LOG_SECURITY, "SECURITY" },
425 { LOG_SYSLOG, "SYSLOG" },
428 { LOG_USER, "USER" },
431 { LOG_UUCP, "UUCP" },
433 { LOG_LOCAL0, "LOCAL0" },
434 { LOG_LOCAL1, "LOCAL1" },
435 { LOG_LOCAL2, "LOCAL2" },
436 { LOG_LOCAL3, "LOCAL3" },
437 { LOG_LOCAL4, "LOCAL4" },
438 { LOG_LOCAL5, "LOCAL5" },
439 { LOG_LOCAL6, "LOCAL6" },
440 { LOG_LOCAL7, "LOCAL7" },
446 facility = lp_parm_enum(SNUM(handle->conn), "full_audit", "facility", enum_log_facilities, LOG_USER);
451 static int audit_syslog_priority(vfs_handle_struct *handle)
453 static const struct enum_list enum_log_priorities[] = {
454 { LOG_EMERG, "EMERG" },
455 { LOG_ALERT, "ALERT" },
456 { LOG_CRIT, "CRIT" },
458 { LOG_WARNING, "WARNING" },
459 { LOG_NOTICE, "NOTICE" },
460 { LOG_INFO, "INFO" },
461 { LOG_DEBUG, "DEBUG" },
467 priority = lp_parm_enum(SNUM(handle->conn), "full_audit", "priority",
468 enum_log_priorities, LOG_NOTICE);
469 if (priority == -1) {
470 priority = LOG_WARNING;
476 static char *audit_prefix(TALLOC_CTX *ctx, connection_struct *conn)
481 prefix = talloc_strdup(ctx,
482 lp_parm_const_string(SNUM(conn), "full_audit",
487 result = talloc_sub_advanced(ctx,
488 lp_servicename(talloc_tos(), 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 SMB_VFS_NEXT_DISCONNECT(handle);
776 do_log(SMB_VFS_OP_DISCONNECT, True, handle,
777 "%s", lp_servicename(talloc_tos(), SNUM(handle->conn)));
779 /* The bitmaps will be disconnected when the private
783 static uint64_t smb_full_audit_disk_free(vfs_handle_struct *handle,
784 const struct smb_filename *smb_fname,
791 result = SMB_VFS_NEXT_DISK_FREE(handle, smb_fname, bsize, dfree, dsize);
793 /* Don't have a reasonable notion of failure here */
795 do_log(SMB_VFS_OP_DISK_FREE,
799 smb_fname_str_do_log(handle->conn, smb_fname));
804 static int smb_full_audit_get_quota(struct vfs_handle_struct *handle,
805 const struct smb_filename *smb_fname,
806 enum SMB_QUOTA_TYPE qtype,
812 result = SMB_VFS_NEXT_GET_QUOTA(handle, smb_fname, qtype, id, qt);
814 do_log(SMB_VFS_OP_GET_QUOTA,
818 smb_fname_str_do_log(handle->conn, smb_fname));
823 static int smb_full_audit_set_quota(struct vfs_handle_struct *handle,
824 enum SMB_QUOTA_TYPE qtype, unid_t id,
829 result = SMB_VFS_NEXT_SET_QUOTA(handle, qtype, id, qt);
831 do_log(SMB_VFS_OP_SET_QUOTA, (result >= 0), handle, "");
836 static int smb_full_audit_get_shadow_copy_data(struct vfs_handle_struct *handle,
837 struct files_struct *fsp,
838 struct shadow_copy_data *shadow_copy_data,
843 result = SMB_VFS_NEXT_GET_SHADOW_COPY_DATA(handle, fsp, shadow_copy_data, labels);
845 do_log(SMB_VFS_OP_GET_SHADOW_COPY_DATA, (result >= 0), handle, "");
850 static int smb_full_audit_statvfs(struct vfs_handle_struct *handle,
851 const struct smb_filename *smb_fname,
852 struct vfs_statvfs_struct *statbuf)
856 result = SMB_VFS_NEXT_STATVFS(handle, smb_fname, statbuf);
858 do_log(SMB_VFS_OP_STATVFS, (result >= 0), handle, "");
863 static uint32_t smb_full_audit_fs_capabilities(struct vfs_handle_struct *handle, enum timestamp_set_resolution *p_ts_res)
867 result = SMB_VFS_NEXT_FS_CAPABILITIES(handle, p_ts_res);
869 do_log(SMB_VFS_OP_FS_CAPABILITIES, true, handle, "");
874 static NTSTATUS smb_full_audit_get_dfs_referrals(
875 struct vfs_handle_struct *handle,
876 struct dfs_GetDFSReferral *r)
880 status = SMB_VFS_NEXT_GET_DFS_REFERRALS(handle, r);
882 do_log(SMB_VFS_OP_GET_DFS_REFERRALS, NT_STATUS_IS_OK(status),
888 static NTSTATUS smb_full_audit_snap_check_path(struct vfs_handle_struct *handle,
890 const char *service_path,
895 status = SMB_VFS_NEXT_SNAP_CHECK_PATH(handle, mem_ctx, service_path,
897 do_log(SMB_VFS_OP_SNAP_CHECK_PATH, NT_STATUS_IS_OK(status),
903 static NTSTATUS smb_full_audit_snap_create(struct vfs_handle_struct *handle,
905 const char *base_volume,
913 status = SMB_VFS_NEXT_SNAP_CREATE(handle, mem_ctx, base_volume, tstamp,
914 rw, base_path, snap_path);
915 do_log(SMB_VFS_OP_SNAP_CREATE, NT_STATUS_IS_OK(status), handle, "");
920 static NTSTATUS smb_full_audit_snap_delete(struct vfs_handle_struct *handle,
927 status = SMB_VFS_NEXT_SNAP_DELETE(handle, mem_ctx, base_path,
929 do_log(SMB_VFS_OP_SNAP_DELETE, NT_STATUS_IS_OK(status), handle, "");
934 static DIR *smb_full_audit_opendir(vfs_handle_struct *handle,
935 const struct smb_filename *smb_fname,
941 result = SMB_VFS_NEXT_OPENDIR(handle, smb_fname, mask, attr);
943 do_log(SMB_VFS_OP_OPENDIR,
947 smb_fname_str_do_log(handle->conn, smb_fname));
952 static DIR *smb_full_audit_fdopendir(vfs_handle_struct *handle,
953 files_struct *fsp, const char *mask, uint32_t attr)
957 result = SMB_VFS_NEXT_FDOPENDIR(handle, fsp, mask, attr);
959 do_log(SMB_VFS_OP_FDOPENDIR, (result != NULL), handle, "%s",
960 fsp_str_do_log(fsp));
965 static struct dirent *smb_full_audit_readdir(vfs_handle_struct *handle,
966 DIR *dirp, SMB_STRUCT_STAT *sbuf)
968 struct dirent *result;
970 result = SMB_VFS_NEXT_READDIR(handle, dirp, sbuf);
972 /* This operation has no reasonable error condition
973 * (End of dir is also failure), so always succeed.
975 do_log(SMB_VFS_OP_READDIR, True, handle, "");
980 static void smb_full_audit_seekdir(vfs_handle_struct *handle,
981 DIR *dirp, long offset)
983 SMB_VFS_NEXT_SEEKDIR(handle, dirp, offset);
985 do_log(SMB_VFS_OP_SEEKDIR, True, handle, "");
988 static long smb_full_audit_telldir(vfs_handle_struct *handle,
993 result = SMB_VFS_NEXT_TELLDIR(handle, dirp);
995 do_log(SMB_VFS_OP_TELLDIR, True, handle, "");
1000 static void smb_full_audit_rewinddir(vfs_handle_struct *handle,
1003 SMB_VFS_NEXT_REWINDDIR(handle, dirp);
1005 do_log(SMB_VFS_OP_REWINDDIR, True, handle, "");
1008 static int smb_full_audit_mkdirat(vfs_handle_struct *handle,
1009 struct files_struct *dirfsp,
1010 const struct smb_filename *smb_fname,
1015 result = SMB_VFS_NEXT_MKDIRAT(handle,
1020 do_log(SMB_VFS_OP_MKDIRAT,
1024 smb_fname_str_do_log(handle->conn, smb_fname));
1029 static int smb_full_audit_closedir(vfs_handle_struct *handle,
1034 result = SMB_VFS_NEXT_CLOSEDIR(handle, dirp);
1036 do_log(SMB_VFS_OP_CLOSEDIR, (result >= 0), handle, "");
1041 static int smb_full_audit_open(vfs_handle_struct *handle,
1042 struct smb_filename *smb_fname,
1043 files_struct *fsp, int flags, mode_t mode)
1047 result = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
1049 do_log(SMB_VFS_OP_OPEN, (result >= 0), handle, "%s|%s",
1050 ((flags & O_WRONLY) || (flags & O_RDWR))?"w":"r",
1051 smb_fname_str_do_log(handle->conn, smb_fname));
1056 static NTSTATUS smb_full_audit_create_file(vfs_handle_struct *handle,
1057 struct smb_request *req,
1058 uint16_t root_dir_fid,
1059 struct smb_filename *smb_fname,
1060 uint32_t access_mask,
1061 uint32_t share_access,
1062 uint32_t create_disposition,
1063 uint32_t create_options,
1064 uint32_t file_attributes,
1065 uint32_t oplock_request,
1066 const struct smb2_lease *lease,
1067 uint64_t allocation_size,
1068 uint32_t private_flags,
1069 struct security_descriptor *sd,
1070 struct ea_list *ea_list,
1071 files_struct **result_fsp,
1073 const struct smb2_create_blobs *in_context_blobs,
1074 struct smb2_create_blobs *out_context_blobs)
1077 const char* str_create_disposition;
1079 switch (create_disposition) {
1080 case FILE_SUPERSEDE:
1081 str_create_disposition = "supersede";
1083 case FILE_OVERWRITE_IF:
1084 str_create_disposition = "overwrite_if";
1087 str_create_disposition = "open";
1089 case FILE_OVERWRITE:
1090 str_create_disposition = "overwrite";
1093 str_create_disposition = "create";
1096 str_create_disposition = "open_if";
1099 str_create_disposition = "unknown";
1102 result = SMB_VFS_NEXT_CREATE_FILE(
1103 handle, /* handle */
1105 root_dir_fid, /* root_dir_fid */
1106 smb_fname, /* fname */
1107 access_mask, /* access_mask */
1108 share_access, /* share_access */
1109 create_disposition, /* create_disposition*/
1110 create_options, /* create_options */
1111 file_attributes, /* file_attributes */
1112 oplock_request, /* oplock_request */
1114 allocation_size, /* allocation_size */
1117 ea_list, /* ea_list */
1118 result_fsp, /* result */
1120 in_context_blobs, out_context_blobs); /* create context */
1122 do_log(SMB_VFS_OP_CREATE_FILE, (NT_STATUS_IS_OK(result)), handle,
1123 "0x%x|%s|%s|%s", access_mask,
1124 create_options & FILE_DIRECTORY_FILE ? "dir" : "file",
1125 str_create_disposition,
1126 smb_fname_str_do_log(handle->conn, smb_fname));
1131 static int smb_full_audit_close(vfs_handle_struct *handle, files_struct *fsp)
1135 result = SMB_VFS_NEXT_CLOSE(handle, fsp);
1137 do_log(SMB_VFS_OP_CLOSE, (result >= 0), handle, "%s",
1138 fsp_str_do_log(fsp));
1143 static ssize_t smb_full_audit_pread(vfs_handle_struct *handle, files_struct *fsp,
1144 void *data, size_t n, off_t offset)
1148 result = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
1150 do_log(SMB_VFS_OP_PREAD, (result >= 0), handle, "%s",
1151 fsp_str_do_log(fsp));
1156 struct smb_full_audit_pread_state {
1157 vfs_handle_struct *handle;
1160 struct vfs_aio_state vfs_aio_state;
1163 static void smb_full_audit_pread_done(struct tevent_req *subreq);
1165 static struct tevent_req *smb_full_audit_pread_send(
1166 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1167 struct tevent_context *ev, struct files_struct *fsp,
1168 void *data, size_t n, off_t offset)
1170 struct tevent_req *req, *subreq;
1171 struct smb_full_audit_pread_state *state;
1173 req = tevent_req_create(mem_ctx, &state,
1174 struct smb_full_audit_pread_state);
1176 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
1177 fsp_str_do_log(fsp));
1180 state->handle = handle;
1183 subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
1185 if (tevent_req_nomem(subreq, req)) {
1186 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
1187 fsp_str_do_log(fsp));
1188 return tevent_req_post(req, ev);
1190 tevent_req_set_callback(subreq, smb_full_audit_pread_done, req);
1192 do_log(SMB_VFS_OP_PREAD_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1196 static void smb_full_audit_pread_done(struct tevent_req *subreq)
1198 struct tevent_req *req = tevent_req_callback_data(
1199 subreq, struct tevent_req);
1200 struct smb_full_audit_pread_state *state = tevent_req_data(
1201 req, struct smb_full_audit_pread_state);
1203 state->ret = SMB_VFS_PREAD_RECV(subreq, &state->vfs_aio_state);
1204 TALLOC_FREE(subreq);
1205 tevent_req_done(req);
1208 static ssize_t smb_full_audit_pread_recv(struct tevent_req *req,
1209 struct vfs_aio_state *vfs_aio_state)
1211 struct smb_full_audit_pread_state *state = tevent_req_data(
1212 req, struct smb_full_audit_pread_state);
1214 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1215 do_log(SMB_VFS_OP_PREAD_RECV, false, state->handle, "%s",
1216 fsp_str_do_log(state->fsp));
1220 do_log(SMB_VFS_OP_PREAD_RECV, (state->ret >= 0), state->handle, "%s",
1221 fsp_str_do_log(state->fsp));
1223 *vfs_aio_state = state->vfs_aio_state;
1227 static ssize_t smb_full_audit_pwrite(vfs_handle_struct *handle, files_struct *fsp,
1228 const void *data, size_t n,
1233 result = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
1235 do_log(SMB_VFS_OP_PWRITE, (result >= 0), handle, "%s",
1236 fsp_str_do_log(fsp));
1241 struct smb_full_audit_pwrite_state {
1242 vfs_handle_struct *handle;
1245 struct vfs_aio_state vfs_aio_state;
1248 static void smb_full_audit_pwrite_done(struct tevent_req *subreq);
1250 static struct tevent_req *smb_full_audit_pwrite_send(
1251 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1252 struct tevent_context *ev, struct files_struct *fsp,
1253 const void *data, size_t n, off_t offset)
1255 struct tevent_req *req, *subreq;
1256 struct smb_full_audit_pwrite_state *state;
1258 req = tevent_req_create(mem_ctx, &state,
1259 struct smb_full_audit_pwrite_state);
1261 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1262 fsp_str_do_log(fsp));
1265 state->handle = handle;
1268 subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
1270 if (tevent_req_nomem(subreq, req)) {
1271 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1272 fsp_str_do_log(fsp));
1273 return tevent_req_post(req, ev);
1275 tevent_req_set_callback(subreq, smb_full_audit_pwrite_done, req);
1277 do_log(SMB_VFS_OP_PWRITE_SEND, true, handle, "%s",
1278 fsp_str_do_log(fsp));
1282 static void smb_full_audit_pwrite_done(struct tevent_req *subreq)
1284 struct tevent_req *req = tevent_req_callback_data(
1285 subreq, struct tevent_req);
1286 struct smb_full_audit_pwrite_state *state = tevent_req_data(
1287 req, struct smb_full_audit_pwrite_state);
1289 state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->vfs_aio_state);
1290 TALLOC_FREE(subreq);
1291 tevent_req_done(req);
1294 static ssize_t smb_full_audit_pwrite_recv(struct tevent_req *req,
1295 struct vfs_aio_state *vfs_aio_state)
1297 struct smb_full_audit_pwrite_state *state = tevent_req_data(
1298 req, struct smb_full_audit_pwrite_state);
1300 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1301 do_log(SMB_VFS_OP_PWRITE_RECV, false, state->handle, "%s",
1302 fsp_str_do_log(state->fsp));
1306 do_log(SMB_VFS_OP_PWRITE_RECV, (state->ret >= 0), state->handle, "%s",
1307 fsp_str_do_log(state->fsp));
1309 *vfs_aio_state = state->vfs_aio_state;
1313 static off_t smb_full_audit_lseek(vfs_handle_struct *handle, files_struct *fsp,
1314 off_t offset, int whence)
1318 result = SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence);
1320 do_log(SMB_VFS_OP_LSEEK, (result != (ssize_t)-1), handle,
1321 "%s", fsp_str_do_log(fsp));
1326 static ssize_t smb_full_audit_sendfile(vfs_handle_struct *handle, int tofd,
1327 files_struct *fromfsp,
1328 const DATA_BLOB *hdr, off_t offset,
1333 result = SMB_VFS_NEXT_SENDFILE(handle, tofd, fromfsp, hdr, offset, n);
1335 do_log(SMB_VFS_OP_SENDFILE, (result >= 0), handle,
1336 "%s", fsp_str_do_log(fromfsp));
1341 static ssize_t smb_full_audit_recvfile(vfs_handle_struct *handle, int fromfd,
1342 files_struct *tofsp,
1348 result = SMB_VFS_NEXT_RECVFILE(handle, fromfd, tofsp, offset, n);
1350 do_log(SMB_VFS_OP_RECVFILE, (result >= 0), handle,
1351 "%s", fsp_str_do_log(tofsp));
1356 static int smb_full_audit_renameat(vfs_handle_struct *handle,
1357 files_struct *srcfsp,
1358 const struct smb_filename *smb_fname_src,
1359 files_struct *dstfsp,
1360 const struct smb_filename *smb_fname_dst)
1364 result = SMB_VFS_NEXT_RENAMEAT(handle,
1370 do_log(SMB_VFS_OP_RENAMEAT, (result >= 0), handle, "%s|%s",
1371 smb_fname_str_do_log(handle->conn, smb_fname_src),
1372 smb_fname_str_do_log(handle->conn, smb_fname_dst));
1377 struct smb_full_audit_fsync_state {
1378 vfs_handle_struct *handle;
1381 struct vfs_aio_state vfs_aio_state;
1384 static void smb_full_audit_fsync_done(struct tevent_req *subreq);
1386 static struct tevent_req *smb_full_audit_fsync_send(
1387 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1388 struct tevent_context *ev, struct files_struct *fsp)
1390 struct tevent_req *req, *subreq;
1391 struct smb_full_audit_fsync_state *state;
1393 req = tevent_req_create(mem_ctx, &state,
1394 struct smb_full_audit_fsync_state);
1396 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1397 fsp_str_do_log(fsp));
1400 state->handle = handle;
1403 subreq = SMB_VFS_NEXT_FSYNC_SEND(state, ev, handle, fsp);
1404 if (tevent_req_nomem(subreq, req)) {
1405 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1406 fsp_str_do_log(fsp));
1407 return tevent_req_post(req, ev);
1409 tevent_req_set_callback(subreq, smb_full_audit_fsync_done, req);
1411 do_log(SMB_VFS_OP_FSYNC_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1415 static void smb_full_audit_fsync_done(struct tevent_req *subreq)
1417 struct tevent_req *req = tevent_req_callback_data(
1418 subreq, struct tevent_req);
1419 struct smb_full_audit_fsync_state *state = tevent_req_data(
1420 req, struct smb_full_audit_fsync_state);
1422 state->ret = SMB_VFS_FSYNC_RECV(subreq, &state->vfs_aio_state);
1423 TALLOC_FREE(subreq);
1424 tevent_req_done(req);
1427 static int smb_full_audit_fsync_recv(struct tevent_req *req,
1428 struct vfs_aio_state *vfs_aio_state)
1430 struct smb_full_audit_fsync_state *state = tevent_req_data(
1431 req, struct smb_full_audit_fsync_state);
1433 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1434 do_log(SMB_VFS_OP_FSYNC_RECV, false, state->handle, "%s",
1435 fsp_str_do_log(state->fsp));
1439 do_log(SMB_VFS_OP_FSYNC_RECV, (state->ret >= 0), state->handle, "%s",
1440 fsp_str_do_log(state->fsp));
1442 *vfs_aio_state = state->vfs_aio_state;
1446 static int smb_full_audit_stat(vfs_handle_struct *handle,
1447 struct smb_filename *smb_fname)
1451 result = SMB_VFS_NEXT_STAT(handle, smb_fname);
1453 do_log(SMB_VFS_OP_STAT, (result >= 0), handle, "%s",
1454 smb_fname_str_do_log(handle->conn, smb_fname));
1459 static int smb_full_audit_fstat(vfs_handle_struct *handle, files_struct *fsp,
1460 SMB_STRUCT_STAT *sbuf)
1464 result = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1466 do_log(SMB_VFS_OP_FSTAT, (result >= 0), handle, "%s",
1467 fsp_str_do_log(fsp));
1472 static int smb_full_audit_lstat(vfs_handle_struct *handle,
1473 struct smb_filename *smb_fname)
1477 result = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
1479 do_log(SMB_VFS_OP_LSTAT, (result >= 0), handle, "%s",
1480 smb_fname_str_do_log(handle->conn, smb_fname));
1485 static uint64_t smb_full_audit_get_alloc_size(vfs_handle_struct *handle,
1486 files_struct *fsp, const SMB_STRUCT_STAT *sbuf)
1490 result = SMB_VFS_NEXT_GET_ALLOC_SIZE(handle, fsp, sbuf);
1492 do_log(SMB_VFS_OP_GET_ALLOC_SIZE, (result != (uint64_t)-1), handle,
1493 "%llu", (unsigned long long)result);
1498 static int smb_full_audit_unlinkat(vfs_handle_struct *handle,
1499 struct files_struct *dirfsp,
1500 const struct smb_filename *smb_fname,
1505 result = SMB_VFS_NEXT_UNLINKAT(handle,
1510 do_log(SMB_VFS_OP_UNLINKAT, (result >= 0), handle, "%s",
1511 smb_fname_str_do_log(handle->conn, smb_fname));
1516 static int smb_full_audit_chmod(vfs_handle_struct *handle,
1517 const struct smb_filename *smb_fname,
1522 result = SMB_VFS_NEXT_CHMOD(handle, smb_fname, mode);
1524 do_log(SMB_VFS_OP_CHMOD,
1528 smb_fname_str_do_log(handle->conn, smb_fname),
1534 static int smb_full_audit_fchmod(vfs_handle_struct *handle, files_struct *fsp,
1539 result = SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1541 do_log(SMB_VFS_OP_FCHMOD, (result >= 0), handle,
1542 "%s|%o", fsp_str_do_log(fsp), mode);
1547 static int smb_full_audit_fchown(vfs_handle_struct *handle, files_struct *fsp,
1548 uid_t uid, gid_t gid)
1552 result = SMB_VFS_NEXT_FCHOWN(handle, fsp, uid, gid);
1554 do_log(SMB_VFS_OP_FCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1555 fsp_str_do_log(fsp), (long int)uid, (long int)gid);
1560 static int smb_full_audit_lchown(vfs_handle_struct *handle,
1561 const struct smb_filename *smb_fname,
1567 result = SMB_VFS_NEXT_LCHOWN(handle, smb_fname, uid, gid);
1569 do_log(SMB_VFS_OP_LCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1570 smb_fname->base_name, (long int)uid, (long int)gid);
1575 static int smb_full_audit_chdir(vfs_handle_struct *handle,
1576 const struct smb_filename *smb_fname)
1580 result = SMB_VFS_NEXT_CHDIR(handle, smb_fname);
1582 do_log(SMB_VFS_OP_CHDIR,
1586 smb_fname_str_do_log(handle->conn, smb_fname));
1591 static struct smb_filename *smb_full_audit_getwd(vfs_handle_struct *handle,
1594 struct smb_filename *result;
1596 result = SMB_VFS_NEXT_GETWD(handle, ctx);
1598 do_log(SMB_VFS_OP_GETWD, (result != NULL), handle, "%s",
1599 result == NULL? "" : result->base_name);
1604 static int smb_full_audit_ntimes(vfs_handle_struct *handle,
1605 const struct smb_filename *smb_fname,
1606 struct smb_file_time *ft)
1609 time_t create_time = convert_timespec_to_time_t(ft->create_time);
1610 time_t atime = convert_timespec_to_time_t(ft->atime);
1611 time_t mtime = convert_timespec_to_time_t(ft->mtime);
1612 time_t ctime = convert_timespec_to_time_t(ft->ctime);
1613 const char *create_time_str = "";
1614 const char *atime_str = "";
1615 const char *mtime_str = "";
1616 const char *ctime_str = "";
1617 TALLOC_CTX *frame = talloc_stackframe();
1619 result = SMB_VFS_NEXT_NTIMES(handle, smb_fname, ft);
1621 if (create_time > 0) {
1622 create_time_str = timestring(frame, create_time);
1625 atime_str = timestring(frame, atime);
1628 mtime_str = timestring(frame, mtime);
1631 ctime_str = timestring(frame, ctime);
1634 do_log(SMB_VFS_OP_NTIMES,
1638 smb_fname_str_do_log(handle->conn, smb_fname),
1649 static int smb_full_audit_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
1654 result = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1656 do_log(SMB_VFS_OP_FTRUNCATE, (result >= 0), handle,
1657 "%s", fsp_str_do_log(fsp));
1662 static int smb_full_audit_fallocate(vfs_handle_struct *handle, files_struct *fsp,
1669 result = SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
1671 do_log(SMB_VFS_OP_FALLOCATE, (result >= 0), handle,
1672 "%s", fsp_str_do_log(fsp));
1677 static bool smb_full_audit_lock(vfs_handle_struct *handle, files_struct *fsp,
1678 int op, off_t offset, off_t count, int type)
1682 result = SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type);
1684 do_log(SMB_VFS_OP_LOCK, result, handle, "%s", fsp_str_do_log(fsp));
1689 static int smb_full_audit_kernel_flock(struct vfs_handle_struct *handle,
1690 struct files_struct *fsp,
1691 uint32_t share_mode, uint32_t access_mask)
1695 result = SMB_VFS_NEXT_KERNEL_FLOCK(handle, fsp, share_mode, access_mask);
1697 do_log(SMB_VFS_OP_KERNEL_FLOCK, (result >= 0), handle, "%s",
1698 fsp_str_do_log(fsp));
1703 static int smb_full_audit_fcntl(struct vfs_handle_struct *handle,
1704 struct files_struct *fsp,
1705 int cmd, va_list cmd_arg)
1708 va_list dup_cmd_arg;
1711 va_copy(dup_cmd_arg, cmd_arg);
1712 arg = va_arg(dup_cmd_arg, void *);
1713 result = SMB_VFS_NEXT_FCNTL(handle, fsp, cmd, arg);
1714 va_end(dup_cmd_arg);
1716 do_log(SMB_VFS_OP_FCNTL, (result >= 0), handle, "%s",
1717 fsp_str_do_log(fsp));
1722 static int smb_full_audit_linux_setlease(vfs_handle_struct *handle, files_struct *fsp,
1727 result = SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
1729 do_log(SMB_VFS_OP_LINUX_SETLEASE, (result >= 0), handle, "%s",
1730 fsp_str_do_log(fsp));
1735 static bool smb_full_audit_getlock(vfs_handle_struct *handle, files_struct *fsp,
1736 off_t *poffset, off_t *pcount, int *ptype, pid_t *ppid)
1740 result = SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype, ppid);
1742 do_log(SMB_VFS_OP_GETLOCK, result, handle, "%s", fsp_str_do_log(fsp));
1747 static int smb_full_audit_symlinkat(vfs_handle_struct *handle,
1748 const char *link_contents,
1749 struct files_struct *dirfsp,
1750 const struct smb_filename *new_smb_fname)
1754 result = SMB_VFS_NEXT_SYMLINKAT(handle,
1759 do_log(SMB_VFS_OP_SYMLINKAT,
1764 smb_fname_str_do_log(handle->conn, new_smb_fname));
1769 static int smb_full_audit_readlinkat(vfs_handle_struct *handle,
1770 files_struct *dirfsp,
1771 const struct smb_filename *smb_fname,
1777 result = SMB_VFS_NEXT_READLINKAT(handle,
1783 do_log(SMB_VFS_OP_READLINKAT,
1787 smb_fname_str_do_log(handle->conn, smb_fname));
1792 static int smb_full_audit_linkat(vfs_handle_struct *handle,
1793 files_struct *srcfsp,
1794 const struct smb_filename *old_smb_fname,
1795 files_struct *dstfsp,
1796 const struct smb_filename *new_smb_fname,
1801 result = SMB_VFS_NEXT_LINKAT(handle,
1808 do_log(SMB_VFS_OP_LINKAT,
1812 smb_fname_str_do_log(handle->conn, old_smb_fname),
1813 smb_fname_str_do_log(handle->conn, new_smb_fname));
1818 static int smb_full_audit_mknodat(vfs_handle_struct *handle,
1819 files_struct *dirfsp,
1820 const struct smb_filename *smb_fname,
1826 result = SMB_VFS_NEXT_MKNODAT(handle,
1832 do_log(SMB_VFS_OP_MKNODAT,
1836 smb_fname_str_do_log(handle->conn, smb_fname));
1841 static struct smb_filename *smb_full_audit_realpath(vfs_handle_struct *handle,
1843 const struct smb_filename *smb_fname)
1845 struct smb_filename *result_fname = NULL;
1847 result_fname = SMB_VFS_NEXT_REALPATH(handle, ctx, smb_fname);
1849 do_log(SMB_VFS_OP_REALPATH,
1850 (result_fname != NULL),
1853 smb_fname_str_do_log(handle->conn, smb_fname));
1855 return result_fname;
1858 static int smb_full_audit_chflags(vfs_handle_struct *handle,
1859 const struct smb_filename *smb_fname,
1864 result = SMB_VFS_NEXT_CHFLAGS(handle, smb_fname, flags);
1866 do_log(SMB_VFS_OP_CHFLAGS,
1870 smb_fname_str_do_log(handle->conn, smb_fname));
1875 static struct file_id smb_full_audit_file_id_create(struct vfs_handle_struct *handle,
1876 const SMB_STRUCT_STAT *sbuf)
1878 struct file_id id_zero = { 0 };
1879 struct file_id result;
1880 struct file_id_buf idbuf;
1882 result = SMB_VFS_NEXT_FILE_ID_CREATE(handle, sbuf);
1884 do_log(SMB_VFS_OP_FILE_ID_CREATE,
1885 !file_id_equal(&id_zero, &result),
1888 file_id_str_buf(result, &idbuf));
1893 static uint64_t smb_full_audit_fs_file_id(struct vfs_handle_struct *handle,
1894 const SMB_STRUCT_STAT *sbuf)
1898 result = SMB_VFS_NEXT_FS_FILE_ID(handle, sbuf);
1900 do_log(SMB_VFS_OP_FS_FILE_ID,
1902 handle, "%" PRIu64, result);
1907 static NTSTATUS smb_full_audit_streaminfo(vfs_handle_struct *handle,
1908 struct files_struct *fsp,
1909 const struct smb_filename *smb_fname,
1910 TALLOC_CTX *mem_ctx,
1911 unsigned int *pnum_streams,
1912 struct stream_struct **pstreams)
1916 result = SMB_VFS_NEXT_STREAMINFO(handle, fsp, smb_fname, mem_ctx,
1917 pnum_streams, pstreams);
1919 do_log(SMB_VFS_OP_STREAMINFO,
1920 NT_STATUS_IS_OK(result),
1923 smb_fname_str_do_log(handle->conn, smb_fname));
1928 static int smb_full_audit_get_real_filename(struct vfs_handle_struct *handle,
1931 TALLOC_CTX *mem_ctx,
1936 result = SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name, mem_ctx,
1939 do_log(SMB_VFS_OP_GET_REAL_FILENAME, (result == 0), handle,
1940 "%s/%s->%s", path, name, (result == 0) ? *found_name : "");
1945 static const char *smb_full_audit_connectpath(vfs_handle_struct *handle,
1946 const struct smb_filename *smb_fname)
1950 result = SMB_VFS_NEXT_CONNECTPATH(handle, smb_fname);
1952 do_log(SMB_VFS_OP_CONNECTPATH,
1956 smb_fname_str_do_log(handle->conn, smb_fname));
1961 static NTSTATUS smb_full_audit_brl_lock_windows(struct vfs_handle_struct *handle,
1962 struct byte_range_lock *br_lck,
1963 struct lock_struct *plock)
1967 result = SMB_VFS_NEXT_BRL_LOCK_WINDOWS(handle, br_lck, plock);
1969 do_log(SMB_VFS_OP_BRL_LOCK_WINDOWS, NT_STATUS_IS_OK(result), handle,
1970 "%s:%llu-%llu. type=%d.",
1971 fsp_str_do_log(brl_fsp(br_lck)),
1972 (unsigned long long)plock->start,
1973 (unsigned long long)plock->size,
1979 static bool smb_full_audit_brl_unlock_windows(struct vfs_handle_struct *handle,
1980 struct byte_range_lock *br_lck,
1981 const struct lock_struct *plock)
1985 result = SMB_VFS_NEXT_BRL_UNLOCK_WINDOWS(handle, br_lck, plock);
1987 do_log(SMB_VFS_OP_BRL_UNLOCK_WINDOWS, (result == 0), handle,
1988 "%s:%llu-%llu:%d", fsp_str_do_log(brl_fsp(br_lck)),
1989 (unsigned long long)plock->start,
1990 (unsigned long long)plock->size,
1996 static bool smb_full_audit_strict_lock_check(struct vfs_handle_struct *handle,
1997 struct files_struct *fsp,
1998 struct lock_struct *plock)
2002 result = SMB_VFS_NEXT_STRICT_LOCK_CHECK(handle, fsp, plock);
2004 do_log(SMB_VFS_OP_STRICT_LOCK_CHECK, result, handle,
2005 "%s:%llu-%llu:%d", fsp_str_do_log(fsp),
2006 (unsigned long long)plock->start,
2007 (unsigned long long)plock->size,
2013 static NTSTATUS smb_full_audit_translate_name(struct vfs_handle_struct *handle,
2015 enum vfs_translate_direction direction,
2016 TALLOC_CTX *mem_ctx,
2021 result = SMB_VFS_NEXT_TRANSLATE_NAME(handle, name, direction, mem_ctx,
2024 do_log(SMB_VFS_OP_TRANSLATE_NAME, NT_STATUS_IS_OK(result), handle, "");
2029 static NTSTATUS smb_full_audit_fsctl(struct vfs_handle_struct *handle,
2030 struct files_struct *fsp,
2034 const uint8_t *_in_data,
2036 uint8_t **_out_data,
2037 uint32_t max_out_len,
2042 result = SMB_VFS_NEXT_FSCTL(handle,
2053 do_log(SMB_VFS_OP_FSCTL, NT_STATUS_IS_OK(result), handle, "");
2058 static struct tevent_req *smb_full_audit_offload_read_send(
2059 TALLOC_CTX *mem_ctx,
2060 struct tevent_context *ev,
2061 struct vfs_handle_struct *handle,
2062 struct files_struct *fsp,
2068 struct tevent_req *req = NULL;
2070 req = SMB_VFS_NEXT_OFFLOAD_READ_SEND(mem_ctx, ev, handle, fsp,
2071 fsctl, ttl, offset, to_copy);
2073 do_log(SMB_VFS_OP_OFFLOAD_READ_SEND, req, handle, "");
2078 static NTSTATUS smb_full_audit_offload_read_recv(
2079 struct tevent_req *req,
2080 struct vfs_handle_struct *handle,
2081 TALLOC_CTX *mem_ctx,
2082 DATA_BLOB *_token_blob)
2086 status = SMB_VFS_NEXT_OFFLOAD_READ_RECV(req, handle, mem_ctx,
2089 do_log(SMB_VFS_OP_OFFLOAD_READ_RECV, NT_STATUS_IS_OK(status), handle, "");
2094 static struct tevent_req *smb_full_audit_offload_write_send(struct vfs_handle_struct *handle,
2095 TALLOC_CTX *mem_ctx,
2096 struct tevent_context *ev,
2099 off_t transfer_offset,
2100 struct files_struct *dest_fsp,
2104 struct tevent_req *req;
2106 req = SMB_VFS_NEXT_OFFLOAD_WRITE_SEND(handle, mem_ctx, ev,
2107 fsctl, token, transfer_offset,
2108 dest_fsp, dest_off, num);
2110 do_log(SMB_VFS_OP_OFFLOAD_WRITE_SEND, req, handle, "");
2115 static NTSTATUS smb_full_audit_offload_write_recv(struct vfs_handle_struct *handle,
2116 struct tevent_req *req,
2121 result = SMB_VFS_NEXT_OFFLOAD_WRITE_RECV(handle, req, copied);
2123 do_log(SMB_VFS_OP_OFFLOAD_WRITE_RECV, NT_STATUS_IS_OK(result), handle, "");
2128 static NTSTATUS smb_full_audit_get_compression(vfs_handle_struct *handle,
2129 TALLOC_CTX *mem_ctx,
2130 struct files_struct *fsp,
2131 struct smb_filename *smb_fname,
2132 uint16_t *_compression_fmt)
2136 result = SMB_VFS_NEXT_GET_COMPRESSION(handle, mem_ctx, fsp, smb_fname,
2139 do_log(SMB_VFS_OP_GET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
2141 (fsp ? fsp_str_do_log(fsp) :
2142 smb_fname_str_do_log(handle->conn, smb_fname)));
2147 static NTSTATUS smb_full_audit_set_compression(vfs_handle_struct *handle,
2148 TALLOC_CTX *mem_ctx,
2149 struct files_struct *fsp,
2150 uint16_t compression_fmt)
2154 result = SMB_VFS_NEXT_SET_COMPRESSION(handle, mem_ctx, fsp,
2157 do_log(SMB_VFS_OP_SET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
2158 "%s", fsp_str_do_log(fsp));
2163 static NTSTATUS smb_full_audit_readdir_attr(struct vfs_handle_struct *handle,
2164 const struct smb_filename *fname,
2165 TALLOC_CTX *mem_ctx,
2166 struct readdir_attr_data **pattr_data)
2170 status = SMB_VFS_NEXT_READDIR_ATTR(handle, fname, mem_ctx, pattr_data);
2172 do_log(SMB_VFS_OP_READDIR_ATTR, NT_STATUS_IS_OK(status), handle, "%s",
2173 smb_fname_str_do_log(handle->conn, fname));
2178 static NTSTATUS smb_full_audit_get_dos_attributes(
2179 struct vfs_handle_struct *handle,
2180 struct smb_filename *smb_fname,
2185 status = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES(handle,
2189 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES,
2190 NT_STATUS_IS_OK(status),
2193 smb_fname_str_do_log(handle->conn, smb_fname));
2198 struct smb_full_audit_get_dos_attributes_state {
2199 struct vfs_aio_state aio_state;
2200 vfs_handle_struct *handle;
2201 files_struct *dir_fsp;
2202 const struct smb_filename *smb_fname;
2206 static void smb_full_audit_get_dos_attributes_done(struct tevent_req *subreq);
2208 static struct tevent_req *smb_full_audit_get_dos_attributes_send(
2209 TALLOC_CTX *mem_ctx,
2210 struct tevent_context *ev,
2211 struct vfs_handle_struct *handle,
2212 files_struct *dir_fsp,
2213 struct smb_filename *smb_fname)
2215 struct tevent_req *req = NULL;
2216 struct smb_full_audit_get_dos_attributes_state *state = NULL;
2217 struct tevent_req *subreq = NULL;
2219 req = tevent_req_create(mem_ctx, &state,
2220 struct smb_full_audit_get_dos_attributes_state);
2222 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2226 fsp_str_do_log(dir_fsp),
2227 smb_fname->base_name);
2230 *state = (struct smb_full_audit_get_dos_attributes_state) {
2233 .smb_fname = smb_fname,
2236 subreq = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES_SEND(mem_ctx,
2241 if (tevent_req_nomem(subreq, req)) {
2242 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2246 fsp_str_do_log(dir_fsp),
2247 smb_fname->base_name);
2248 return tevent_req_post(req, ev);
2250 tevent_req_set_callback(subreq,
2251 smb_full_audit_get_dos_attributes_done,
2254 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2258 fsp_str_do_log(dir_fsp),
2259 smb_fname->base_name);
2264 static void smb_full_audit_get_dos_attributes_done(struct tevent_req *subreq)
2266 struct tevent_req *req =
2267 tevent_req_callback_data(subreq,
2269 struct smb_full_audit_get_dos_attributes_state *state =
2270 tevent_req_data(req,
2271 struct smb_full_audit_get_dos_attributes_state);
2274 status = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES_RECV(subreq,
2277 TALLOC_FREE(subreq);
2278 if (tevent_req_nterror(req, status)) {
2282 tevent_req_done(req);
2286 static NTSTATUS smb_full_audit_get_dos_attributes_recv(struct tevent_req *req,
2287 struct vfs_aio_state *aio_state,
2290 struct smb_full_audit_get_dos_attributes_state *state =
2291 tevent_req_data(req,
2292 struct smb_full_audit_get_dos_attributes_state);
2295 if (tevent_req_is_nterror(req, &status)) {
2296 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV,
2300 fsp_str_do_log(state->dir_fsp),
2301 state->smb_fname->base_name);
2302 tevent_req_received(req);
2306 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV,
2310 fsp_str_do_log(state->dir_fsp),
2311 state->smb_fname->base_name);
2313 *aio_state = state->aio_state;
2314 *dosmode = state->dosmode;
2315 tevent_req_received(req);
2316 return NT_STATUS_OK;
2319 static NTSTATUS smb_full_audit_fget_dos_attributes(
2320 struct vfs_handle_struct *handle,
2321 struct files_struct *fsp,
2326 status = SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle,
2330 do_log(SMB_VFS_OP_FGET_DOS_ATTRIBUTES,
2331 NT_STATUS_IS_OK(status),
2334 fsp_str_do_log(fsp));
2339 static NTSTATUS smb_full_audit_set_dos_attributes(
2340 struct vfs_handle_struct *handle,
2341 const struct smb_filename *smb_fname,
2346 status = SMB_VFS_NEXT_SET_DOS_ATTRIBUTES(handle,
2350 do_log(SMB_VFS_OP_SET_DOS_ATTRIBUTES,
2351 NT_STATUS_IS_OK(status),
2354 smb_fname_str_do_log(handle->conn, smb_fname));
2359 static NTSTATUS smb_full_audit_fset_dos_attributes(
2360 struct vfs_handle_struct *handle,
2361 struct files_struct *fsp,
2366 status = SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle,
2370 do_log(SMB_VFS_OP_FSET_DOS_ATTRIBUTES,
2371 NT_STATUS_IS_OK(status),
2374 fsp_str_do_log(fsp));
2379 static NTSTATUS smb_full_audit_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
2380 uint32_t security_info,
2381 TALLOC_CTX *mem_ctx,
2382 struct security_descriptor **ppdesc)
2386 result = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
2389 do_log(SMB_VFS_OP_FGET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2390 "%s", fsp_str_do_log(fsp));
2395 static NTSTATUS smb_full_audit_get_nt_acl(vfs_handle_struct *handle,
2396 const struct smb_filename *smb_fname,
2397 uint32_t security_info,
2398 TALLOC_CTX *mem_ctx,
2399 struct security_descriptor **ppdesc)
2403 result = SMB_VFS_NEXT_GET_NT_ACL(handle, smb_fname, security_info,
2406 do_log(SMB_VFS_OP_GET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2407 "%s", smb_fname_str_do_log(handle->conn, smb_fname));
2412 static NTSTATUS smb_full_audit_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
2413 uint32_t security_info_sent,
2414 const struct security_descriptor *psd)
2416 struct vfs_full_audit_private_data *pd;
2420 SMB_VFS_HANDLE_GET_DATA(handle, pd,
2421 struct vfs_full_audit_private_data,
2422 return NT_STATUS_INTERNAL_ERROR);
2424 if (pd->log_secdesc) {
2425 sd = sddl_encode(talloc_tos(), psd, get_global_sam_sid());
2428 result = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
2430 do_log(SMB_VFS_OP_FSET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2431 "%s [%s]", fsp_str_do_log(fsp), sd ? sd : "");
2438 static NTSTATUS smb_full_audit_audit_file(struct vfs_handle_struct *handle,
2439 struct smb_filename *file,
2440 struct security_acl *sacl,
2441 uint32_t access_requested,
2442 uint32_t access_denied)
2446 result = SMB_VFS_NEXT_AUDIT_FILE(handle,
2452 do_log(SMB_VFS_OP_AUDIT_FILE, NT_STATUS_IS_OK(result), handle,
2454 smb_fname_str_do_log(handle->conn, file));
2459 static SMB_ACL_T smb_full_audit_sys_acl_get_file(vfs_handle_struct *handle,
2460 const struct smb_filename *smb_fname,
2461 SMB_ACL_TYPE_T type,
2462 TALLOC_CTX *mem_ctx)
2466 result = SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, smb_fname,
2469 do_log(SMB_VFS_OP_SYS_ACL_GET_FILE,
2473 smb_fname_str_do_log(handle->conn, smb_fname));
2478 static SMB_ACL_T smb_full_audit_sys_acl_get_fd(vfs_handle_struct *handle,
2479 files_struct *fsp, TALLOC_CTX *mem_ctx)
2483 result = SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp, mem_ctx);
2485 do_log(SMB_VFS_OP_SYS_ACL_GET_FD, (result != NULL), handle,
2486 "%s", fsp_str_do_log(fsp));
2491 static int smb_full_audit_sys_acl_blob_get_file(vfs_handle_struct *handle,
2492 const struct smb_filename *smb_fname,
2493 TALLOC_CTX *mem_ctx,
2494 char **blob_description,
2499 result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FILE(handle, smb_fname,
2500 mem_ctx, blob_description, blob);
2502 do_log(SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE,
2506 smb_fname_str_do_log(handle->conn, smb_fname));
2511 static int smb_full_audit_sys_acl_blob_get_fd(vfs_handle_struct *handle,
2513 TALLOC_CTX *mem_ctx,
2514 char **blob_description,
2519 result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle, fsp, mem_ctx, blob_description, blob);
2521 do_log(SMB_VFS_OP_SYS_ACL_BLOB_GET_FD, (result >= 0), handle,
2522 "%s", fsp_str_do_log(fsp));
2527 static int smb_full_audit_sys_acl_set_file(vfs_handle_struct *handle,
2528 const struct smb_filename *smb_fname,
2529 SMB_ACL_TYPE_T acltype,
2534 result = SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, smb_fname, acltype,
2537 do_log(SMB_VFS_OP_SYS_ACL_SET_FILE,
2541 smb_fname_str_do_log(handle->conn, smb_fname));
2546 static int smb_full_audit_sys_acl_set_fd(vfs_handle_struct *handle, files_struct *fsp,
2551 result = SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, theacl);
2553 do_log(SMB_VFS_OP_SYS_ACL_SET_FD, (result >= 0), handle,
2554 "%s", fsp_str_do_log(fsp));
2559 static int smb_full_audit_sys_acl_delete_def_file(vfs_handle_struct *handle,
2560 const struct smb_filename *smb_fname)
2564 result = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, smb_fname);
2566 do_log(SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE,
2570 smb_fname_str_do_log(handle->conn, smb_fname));
2575 static ssize_t smb_full_audit_getxattr(struct vfs_handle_struct *handle,
2576 const struct smb_filename *smb_fname,
2577 const char *name, void *value, size_t size)
2581 result = SMB_VFS_NEXT_GETXATTR(handle, smb_fname, name, value, size);
2583 do_log(SMB_VFS_OP_GETXATTR,
2587 smb_fname_str_do_log(handle->conn, smb_fname),
2593 struct smb_full_audit_getxattrat_state {
2594 struct vfs_aio_state aio_state;
2595 vfs_handle_struct *handle;
2596 files_struct *dir_fsp;
2597 const struct smb_filename *smb_fname;
2598 const char *xattr_name;
2600 uint8_t *xattr_value;
2603 static void smb_full_audit_getxattrat_done(struct tevent_req *subreq);
2605 static struct tevent_req *smb_full_audit_getxattrat_send(
2606 TALLOC_CTX *mem_ctx,
2607 struct tevent_context *ev,
2608 struct vfs_handle_struct *handle,
2609 files_struct *dir_fsp,
2610 const struct smb_filename *smb_fname,
2611 const char *xattr_name,
2614 struct tevent_req *req = NULL;
2615 struct tevent_req *subreq = NULL;
2616 struct smb_full_audit_getxattrat_state *state = NULL;
2618 req = tevent_req_create(mem_ctx, &state,
2619 struct smb_full_audit_getxattrat_state);
2621 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2625 fsp_str_do_log(dir_fsp),
2626 smb_fname->base_name,
2630 *state = (struct smb_full_audit_getxattrat_state) {
2633 .smb_fname = smb_fname,
2634 .xattr_name = xattr_name,
2637 subreq = SMB_VFS_NEXT_GETXATTRAT_SEND(state,
2644 if (tevent_req_nomem(subreq, req)) {
2645 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2649 fsp_str_do_log(dir_fsp),
2650 smb_fname->base_name,
2652 return tevent_req_post(req, ev);
2654 tevent_req_set_callback(subreq, smb_full_audit_getxattrat_done, req);
2656 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2660 fsp_str_do_log(dir_fsp),
2661 smb_fname->base_name,
2667 static void smb_full_audit_getxattrat_done(struct tevent_req *subreq)
2669 struct tevent_req *req = tevent_req_callback_data(
2670 subreq, struct tevent_req);
2671 struct smb_full_audit_getxattrat_state *state = tevent_req_data(
2672 req, struct smb_full_audit_getxattrat_state);
2674 state->xattr_size = SMB_VFS_NEXT_GETXATTRAT_RECV(subreq,
2677 &state->xattr_value);
2678 TALLOC_FREE(subreq);
2679 if (state->xattr_size == -1) {
2680 tevent_req_error(req, state->aio_state.error);
2684 tevent_req_done(req);
2687 static ssize_t smb_full_audit_getxattrat_recv(struct tevent_req *req,
2688 struct vfs_aio_state *aio_state,
2689 TALLOC_CTX *mem_ctx,
2690 uint8_t **xattr_value)
2692 struct smb_full_audit_getxattrat_state *state = tevent_req_data(
2693 req, struct smb_full_audit_getxattrat_state);
2696 if (tevent_req_is_unix_error(req, &aio_state->error)) {
2697 do_log(SMB_VFS_OP_GETXATTRAT_RECV,
2701 fsp_str_do_log(state->dir_fsp),
2702 state->smb_fname->base_name,
2704 tevent_req_received(req);
2708 do_log(SMB_VFS_OP_GETXATTRAT_RECV,
2712 fsp_str_do_log(state->dir_fsp),
2713 state->smb_fname->base_name,
2716 *aio_state = state->aio_state;
2717 xattr_size = state->xattr_size;
2718 if (xattr_value != NULL) {
2719 *xattr_value = talloc_move(mem_ctx, &state->xattr_value);
2722 tevent_req_received(req);
2726 static ssize_t smb_full_audit_fgetxattr(struct vfs_handle_struct *handle,
2727 struct files_struct *fsp,
2728 const char *name, void *value, size_t size)
2732 result = SMB_VFS_NEXT_FGETXATTR(handle, fsp, name, value, size);
2734 do_log(SMB_VFS_OP_FGETXATTR, (result >= 0), handle,
2735 "%s|%s", fsp_str_do_log(fsp), name);
2740 static ssize_t smb_full_audit_listxattr(struct vfs_handle_struct *handle,
2741 const struct smb_filename *smb_fname,
2747 result = SMB_VFS_NEXT_LISTXATTR(handle, smb_fname, list, size);
2749 do_log(SMB_VFS_OP_LISTXATTR,
2753 smb_fname_str_do_log(handle->conn, smb_fname));
2758 static ssize_t smb_full_audit_flistxattr(struct vfs_handle_struct *handle,
2759 struct files_struct *fsp, char *list,
2764 result = SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
2766 do_log(SMB_VFS_OP_FLISTXATTR, (result >= 0), handle,
2767 "%s", fsp_str_do_log(fsp));
2772 static int smb_full_audit_removexattr(struct vfs_handle_struct *handle,
2773 const struct smb_filename *smb_fname,
2778 result = SMB_VFS_NEXT_REMOVEXATTR(handle, smb_fname, name);
2780 do_log(SMB_VFS_OP_REMOVEXATTR,
2784 smb_fname_str_do_log(handle->conn, smb_fname),
2790 static int smb_full_audit_fremovexattr(struct vfs_handle_struct *handle,
2791 struct files_struct *fsp,
2796 result = SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, name);
2798 do_log(SMB_VFS_OP_FREMOVEXATTR, (result >= 0), handle,
2799 "%s|%s", fsp_str_do_log(fsp), name);
2804 static int smb_full_audit_setxattr(struct vfs_handle_struct *handle,
2805 const struct smb_filename *smb_fname,
2806 const char *name, const void *value, size_t size,
2811 result = SMB_VFS_NEXT_SETXATTR(handle, smb_fname, name, value, size,
2814 do_log(SMB_VFS_OP_SETXATTR,
2818 smb_fname_str_do_log(handle->conn, smb_fname),
2824 static int smb_full_audit_fsetxattr(struct vfs_handle_struct *handle,
2825 struct files_struct *fsp, const char *name,
2826 const void *value, size_t size, int flags)
2830 result = SMB_VFS_NEXT_FSETXATTR(handle, fsp, name, value, size, flags);
2832 do_log(SMB_VFS_OP_FSETXATTR, (result >= 0), handle,
2833 "%s|%s", fsp_str_do_log(fsp), name);
2838 static bool smb_full_audit_aio_force(struct vfs_handle_struct *handle,
2839 struct files_struct *fsp)
2843 result = SMB_VFS_NEXT_AIO_FORCE(handle, fsp);
2844 do_log(SMB_VFS_OP_AIO_FORCE, result, handle,
2845 "%s", fsp_str_do_log(fsp));
2850 static NTSTATUS smb_full_audit_durable_cookie(struct vfs_handle_struct *handle,
2851 struct files_struct *fsp,
2852 TALLOC_CTX *mem_ctx,
2857 result = SMB_VFS_NEXT_DURABLE_COOKIE(handle,
2862 do_log(SMB_VFS_OP_DURABLE_COOKIE, NT_STATUS_IS_OK(result), handle,
2863 "%s", fsp_str_do_log(fsp));
2868 static NTSTATUS smb_full_audit_durable_disconnect(
2869 struct vfs_handle_struct *handle,
2870 struct files_struct *fsp,
2871 const DATA_BLOB old_cookie,
2872 TALLOC_CTX *mem_ctx,
2873 DATA_BLOB *new_cookie)
2877 result = SMB_VFS_NEXT_DURABLE_DISCONNECT(handle,
2883 do_log(SMB_VFS_OP_DURABLE_DISCONNECT, NT_STATUS_IS_OK(result), handle,
2884 "%s", fsp_str_do_log(fsp));
2889 static NTSTATUS smb_full_audit_durable_reconnect(
2890 struct vfs_handle_struct *handle,
2891 struct smb_request *smb1req,
2892 struct smbXsrv_open *op,
2893 const DATA_BLOB old_cookie,
2894 TALLOC_CTX *mem_ctx,
2895 struct files_struct **fsp,
2896 DATA_BLOB *new_cookie)
2900 result = SMB_VFS_NEXT_DURABLE_RECONNECT(handle,
2908 do_log(SMB_VFS_OP_DURABLE_RECONNECT,
2909 NT_STATUS_IS_OK(result),
2916 static struct vfs_fn_pointers vfs_full_audit_fns = {
2918 /* Disk operations */
2920 .connect_fn = smb_full_audit_connect,
2921 .disconnect_fn = smb_full_audit_disconnect,
2922 .disk_free_fn = smb_full_audit_disk_free,
2923 .get_quota_fn = smb_full_audit_get_quota,
2924 .set_quota_fn = smb_full_audit_set_quota,
2925 .get_shadow_copy_data_fn = smb_full_audit_get_shadow_copy_data,
2926 .statvfs_fn = smb_full_audit_statvfs,
2927 .fs_capabilities_fn = smb_full_audit_fs_capabilities,
2928 .get_dfs_referrals_fn = smb_full_audit_get_dfs_referrals,
2929 .opendir_fn = smb_full_audit_opendir,
2930 .fdopendir_fn = smb_full_audit_fdopendir,
2931 .readdir_fn = smb_full_audit_readdir,
2932 .seekdir_fn = smb_full_audit_seekdir,
2933 .telldir_fn = smb_full_audit_telldir,
2934 .rewind_dir_fn = smb_full_audit_rewinddir,
2935 .mkdirat_fn = smb_full_audit_mkdirat,
2936 .closedir_fn = smb_full_audit_closedir,
2937 .open_fn = smb_full_audit_open,
2938 .create_file_fn = smb_full_audit_create_file,
2939 .close_fn = smb_full_audit_close,
2940 .pread_fn = smb_full_audit_pread,
2941 .pread_send_fn = smb_full_audit_pread_send,
2942 .pread_recv_fn = smb_full_audit_pread_recv,
2943 .pwrite_fn = smb_full_audit_pwrite,
2944 .pwrite_send_fn = smb_full_audit_pwrite_send,
2945 .pwrite_recv_fn = smb_full_audit_pwrite_recv,
2946 .lseek_fn = smb_full_audit_lseek,
2947 .sendfile_fn = smb_full_audit_sendfile,
2948 .recvfile_fn = smb_full_audit_recvfile,
2949 .renameat_fn = smb_full_audit_renameat,
2950 .fsync_send_fn = smb_full_audit_fsync_send,
2951 .fsync_recv_fn = smb_full_audit_fsync_recv,
2952 .stat_fn = smb_full_audit_stat,
2953 .fstat_fn = smb_full_audit_fstat,
2954 .lstat_fn = smb_full_audit_lstat,
2955 .get_alloc_size_fn = smb_full_audit_get_alloc_size,
2956 .unlinkat_fn = smb_full_audit_unlinkat,
2957 .chmod_fn = smb_full_audit_chmod,
2958 .fchmod_fn = smb_full_audit_fchmod,
2959 .fchown_fn = smb_full_audit_fchown,
2960 .lchown_fn = smb_full_audit_lchown,
2961 .chdir_fn = smb_full_audit_chdir,
2962 .getwd_fn = smb_full_audit_getwd,
2963 .ntimes_fn = smb_full_audit_ntimes,
2964 .ftruncate_fn = smb_full_audit_ftruncate,
2965 .fallocate_fn = smb_full_audit_fallocate,
2966 .lock_fn = smb_full_audit_lock,
2967 .kernel_flock_fn = smb_full_audit_kernel_flock,
2968 .fcntl_fn = smb_full_audit_fcntl,
2969 .linux_setlease_fn = smb_full_audit_linux_setlease,
2970 .getlock_fn = smb_full_audit_getlock,
2971 .symlinkat_fn = smb_full_audit_symlinkat,
2972 .readlinkat_fn = smb_full_audit_readlinkat,
2973 .linkat_fn = smb_full_audit_linkat,
2974 .mknodat_fn = smb_full_audit_mknodat,
2975 .realpath_fn = smb_full_audit_realpath,
2976 .chflags_fn = smb_full_audit_chflags,
2977 .file_id_create_fn = smb_full_audit_file_id_create,
2978 .fs_file_id_fn = smb_full_audit_fs_file_id,
2979 .offload_read_send_fn = smb_full_audit_offload_read_send,
2980 .offload_read_recv_fn = smb_full_audit_offload_read_recv,
2981 .offload_write_send_fn = smb_full_audit_offload_write_send,
2982 .offload_write_recv_fn = smb_full_audit_offload_write_recv,
2983 .get_compression_fn = smb_full_audit_get_compression,
2984 .set_compression_fn = smb_full_audit_set_compression,
2985 .snap_check_path_fn = smb_full_audit_snap_check_path,
2986 .snap_create_fn = smb_full_audit_snap_create,
2987 .snap_delete_fn = smb_full_audit_snap_delete,
2988 .streaminfo_fn = smb_full_audit_streaminfo,
2989 .get_real_filename_fn = smb_full_audit_get_real_filename,
2990 .connectpath_fn = smb_full_audit_connectpath,
2991 .brl_lock_windows_fn = smb_full_audit_brl_lock_windows,
2992 .brl_unlock_windows_fn = smb_full_audit_brl_unlock_windows,
2993 .strict_lock_check_fn = smb_full_audit_strict_lock_check,
2994 .translate_name_fn = smb_full_audit_translate_name,
2995 .fsctl_fn = smb_full_audit_fsctl,
2996 .get_dos_attributes_fn = smb_full_audit_get_dos_attributes,
2997 .get_dos_attributes_send_fn = smb_full_audit_get_dos_attributes_send,
2998 .get_dos_attributes_recv_fn = smb_full_audit_get_dos_attributes_recv,
2999 .fget_dos_attributes_fn = smb_full_audit_fget_dos_attributes,
3000 .set_dos_attributes_fn = smb_full_audit_set_dos_attributes,
3001 .fset_dos_attributes_fn = smb_full_audit_fset_dos_attributes,
3002 .fget_nt_acl_fn = smb_full_audit_fget_nt_acl,
3003 .get_nt_acl_fn = smb_full_audit_get_nt_acl,
3004 .fset_nt_acl_fn = smb_full_audit_fset_nt_acl,
3005 .audit_file_fn = smb_full_audit_audit_file,
3006 .sys_acl_get_file_fn = smb_full_audit_sys_acl_get_file,
3007 .sys_acl_get_fd_fn = smb_full_audit_sys_acl_get_fd,
3008 .sys_acl_blob_get_file_fn = smb_full_audit_sys_acl_blob_get_file,
3009 .sys_acl_blob_get_fd_fn = smb_full_audit_sys_acl_blob_get_fd,
3010 .sys_acl_set_file_fn = smb_full_audit_sys_acl_set_file,
3011 .sys_acl_set_fd_fn = smb_full_audit_sys_acl_set_fd,
3012 .sys_acl_delete_def_file_fn = smb_full_audit_sys_acl_delete_def_file,
3013 .getxattr_fn = smb_full_audit_getxattr,
3014 .getxattrat_send_fn = smb_full_audit_getxattrat_send,
3015 .getxattrat_recv_fn = smb_full_audit_getxattrat_recv,
3016 .fgetxattr_fn = smb_full_audit_fgetxattr,
3017 .listxattr_fn = smb_full_audit_listxattr,
3018 .flistxattr_fn = smb_full_audit_flistxattr,
3019 .removexattr_fn = smb_full_audit_removexattr,
3020 .fremovexattr_fn = smb_full_audit_fremovexattr,
3021 .setxattr_fn = smb_full_audit_setxattr,
3022 .fsetxattr_fn = smb_full_audit_fsetxattr,
3023 .aio_force_fn = smb_full_audit_aio_force,
3024 .durable_cookie_fn = smb_full_audit_durable_cookie,
3025 .durable_disconnect_fn = smb_full_audit_durable_disconnect,
3026 .durable_reconnect_fn = smb_full_audit_durable_reconnect,
3027 .readdir_attr_fn = smb_full_audit_readdir_attr
3032 NTSTATUS vfs_full_audit_init(TALLOC_CTX *ctx)
3036 smb_vfs_assert_all_fns(&vfs_full_audit_fns, "full_audit");
3038 ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "full_audit",
3039 &vfs_full_audit_fns);
3041 if (!NT_STATUS_IS_OK(ret))
3044 vfs_full_audit_debug_level = debug_add_class("full_audit");
3045 if (vfs_full_audit_debug_level == -1) {
3046 vfs_full_audit_debug_level = DBGC_VFS;
3047 DEBUG(0, ("vfs_full_audit: Couldn't register custom debugging "
3050 DEBUG(10, ("vfs_full_audit: Debug class number of "
3051 "'full_audit': %d\n", vfs_full_audit_debug_level));