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;
1879 struct file_id result;
1881 ZERO_STRUCT(id_zero);
1883 result = SMB_VFS_NEXT_FILE_ID_CREATE(handle, sbuf);
1885 do_log(SMB_VFS_OP_FILE_ID_CREATE,
1886 !file_id_equal(&id_zero, &result),
1887 handle, "%s", file_id_string_tos(&result));
1892 static uint64_t smb_full_audit_fs_file_id(struct vfs_handle_struct *handle,
1893 const SMB_STRUCT_STAT *sbuf)
1897 result = SMB_VFS_NEXT_FS_FILE_ID(handle, sbuf);
1899 do_log(SMB_VFS_OP_FS_FILE_ID,
1901 handle, "%" PRIu64, result);
1906 static NTSTATUS smb_full_audit_streaminfo(vfs_handle_struct *handle,
1907 struct files_struct *fsp,
1908 const struct smb_filename *smb_fname,
1909 TALLOC_CTX *mem_ctx,
1910 unsigned int *pnum_streams,
1911 struct stream_struct **pstreams)
1915 result = SMB_VFS_NEXT_STREAMINFO(handle, fsp, smb_fname, mem_ctx,
1916 pnum_streams, pstreams);
1918 do_log(SMB_VFS_OP_STREAMINFO,
1919 NT_STATUS_IS_OK(result),
1922 smb_fname_str_do_log(handle->conn, smb_fname));
1927 static int smb_full_audit_get_real_filename(struct vfs_handle_struct *handle,
1930 TALLOC_CTX *mem_ctx,
1935 result = SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name, mem_ctx,
1938 do_log(SMB_VFS_OP_GET_REAL_FILENAME, (result == 0), handle,
1939 "%s/%s->%s", path, name, (result == 0) ? *found_name : "");
1944 static const char *smb_full_audit_connectpath(vfs_handle_struct *handle,
1945 const struct smb_filename *smb_fname)
1949 result = SMB_VFS_NEXT_CONNECTPATH(handle, smb_fname);
1951 do_log(SMB_VFS_OP_CONNECTPATH,
1955 smb_fname_str_do_log(handle->conn, smb_fname));
1960 static NTSTATUS smb_full_audit_brl_lock_windows(struct vfs_handle_struct *handle,
1961 struct byte_range_lock *br_lck,
1962 struct lock_struct *plock)
1966 result = SMB_VFS_NEXT_BRL_LOCK_WINDOWS(handle, br_lck, plock);
1968 do_log(SMB_VFS_OP_BRL_LOCK_WINDOWS, NT_STATUS_IS_OK(result), handle,
1969 "%s:%llu-%llu. type=%d.",
1970 fsp_str_do_log(brl_fsp(br_lck)),
1971 (unsigned long long)plock->start,
1972 (unsigned long long)plock->size,
1978 static bool smb_full_audit_brl_unlock_windows(struct vfs_handle_struct *handle,
1979 struct byte_range_lock *br_lck,
1980 const struct lock_struct *plock)
1984 result = SMB_VFS_NEXT_BRL_UNLOCK_WINDOWS(handle, br_lck, plock);
1986 do_log(SMB_VFS_OP_BRL_UNLOCK_WINDOWS, (result == 0), handle,
1987 "%s:%llu-%llu:%d", fsp_str_do_log(brl_fsp(br_lck)),
1988 (unsigned long long)plock->start,
1989 (unsigned long long)plock->size,
1995 static bool smb_full_audit_strict_lock_check(struct vfs_handle_struct *handle,
1996 struct files_struct *fsp,
1997 struct lock_struct *plock)
2001 result = SMB_VFS_NEXT_STRICT_LOCK_CHECK(handle, fsp, plock);
2003 do_log(SMB_VFS_OP_STRICT_LOCK_CHECK, result, handle,
2004 "%s:%llu-%llu:%d", fsp_str_do_log(fsp),
2005 (unsigned long long)plock->start,
2006 (unsigned long long)plock->size,
2012 static NTSTATUS smb_full_audit_translate_name(struct vfs_handle_struct *handle,
2014 enum vfs_translate_direction direction,
2015 TALLOC_CTX *mem_ctx,
2020 result = SMB_VFS_NEXT_TRANSLATE_NAME(handle, name, direction, mem_ctx,
2023 do_log(SMB_VFS_OP_TRANSLATE_NAME, NT_STATUS_IS_OK(result), handle, "");
2028 static NTSTATUS smb_full_audit_fsctl(struct vfs_handle_struct *handle,
2029 struct files_struct *fsp,
2033 const uint8_t *_in_data,
2035 uint8_t **_out_data,
2036 uint32_t max_out_len,
2041 result = SMB_VFS_NEXT_FSCTL(handle,
2052 do_log(SMB_VFS_OP_FSCTL, NT_STATUS_IS_OK(result), handle, "");
2057 static struct tevent_req *smb_full_audit_offload_read_send(
2058 TALLOC_CTX *mem_ctx,
2059 struct tevent_context *ev,
2060 struct vfs_handle_struct *handle,
2061 struct files_struct *fsp,
2067 struct tevent_req *req = NULL;
2069 req = SMB_VFS_NEXT_OFFLOAD_READ_SEND(mem_ctx, ev, handle, fsp,
2070 fsctl, ttl, offset, to_copy);
2072 do_log(SMB_VFS_OP_OFFLOAD_READ_SEND, req, handle, "");
2077 static NTSTATUS smb_full_audit_offload_read_recv(
2078 struct tevent_req *req,
2079 struct vfs_handle_struct *handle,
2080 TALLOC_CTX *mem_ctx,
2081 DATA_BLOB *_token_blob)
2085 status = SMB_VFS_NEXT_OFFLOAD_READ_RECV(req, handle, mem_ctx,
2088 do_log(SMB_VFS_OP_OFFLOAD_READ_RECV, NT_STATUS_IS_OK(status), handle, "");
2093 static struct tevent_req *smb_full_audit_offload_write_send(struct vfs_handle_struct *handle,
2094 TALLOC_CTX *mem_ctx,
2095 struct tevent_context *ev,
2098 off_t transfer_offset,
2099 struct files_struct *dest_fsp,
2103 struct tevent_req *req;
2105 req = SMB_VFS_NEXT_OFFLOAD_WRITE_SEND(handle, mem_ctx, ev,
2106 fsctl, token, transfer_offset,
2107 dest_fsp, dest_off, num);
2109 do_log(SMB_VFS_OP_OFFLOAD_WRITE_SEND, req, handle, "");
2114 static NTSTATUS smb_full_audit_offload_write_recv(struct vfs_handle_struct *handle,
2115 struct tevent_req *req,
2120 result = SMB_VFS_NEXT_OFFLOAD_WRITE_RECV(handle, req, copied);
2122 do_log(SMB_VFS_OP_OFFLOAD_WRITE_RECV, NT_STATUS_IS_OK(result), handle, "");
2127 static NTSTATUS smb_full_audit_get_compression(vfs_handle_struct *handle,
2128 TALLOC_CTX *mem_ctx,
2129 struct files_struct *fsp,
2130 struct smb_filename *smb_fname,
2131 uint16_t *_compression_fmt)
2135 result = SMB_VFS_NEXT_GET_COMPRESSION(handle, mem_ctx, fsp, smb_fname,
2138 do_log(SMB_VFS_OP_GET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
2140 (fsp ? fsp_str_do_log(fsp) :
2141 smb_fname_str_do_log(handle->conn, smb_fname)));
2146 static NTSTATUS smb_full_audit_set_compression(vfs_handle_struct *handle,
2147 TALLOC_CTX *mem_ctx,
2148 struct files_struct *fsp,
2149 uint16_t compression_fmt)
2153 result = SMB_VFS_NEXT_SET_COMPRESSION(handle, mem_ctx, fsp,
2156 do_log(SMB_VFS_OP_SET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
2157 "%s", fsp_str_do_log(fsp));
2162 static NTSTATUS smb_full_audit_readdir_attr(struct vfs_handle_struct *handle,
2163 const struct smb_filename *fname,
2164 TALLOC_CTX *mem_ctx,
2165 struct readdir_attr_data **pattr_data)
2169 status = SMB_VFS_NEXT_READDIR_ATTR(handle, fname, mem_ctx, pattr_data);
2171 do_log(SMB_VFS_OP_READDIR_ATTR, NT_STATUS_IS_OK(status), handle, "%s",
2172 smb_fname_str_do_log(handle->conn, fname));
2177 static NTSTATUS smb_full_audit_get_dos_attributes(
2178 struct vfs_handle_struct *handle,
2179 struct smb_filename *smb_fname,
2184 status = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES(handle,
2188 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES,
2189 NT_STATUS_IS_OK(status),
2192 smb_fname_str_do_log(handle->conn, smb_fname));
2197 struct smb_full_audit_get_dos_attributes_state {
2198 struct vfs_aio_state aio_state;
2199 vfs_handle_struct *handle;
2200 files_struct *dir_fsp;
2201 const struct smb_filename *smb_fname;
2205 static void smb_full_audit_get_dos_attributes_done(struct tevent_req *subreq);
2207 static struct tevent_req *smb_full_audit_get_dos_attributes_send(
2208 TALLOC_CTX *mem_ctx,
2209 struct tevent_context *ev,
2210 struct vfs_handle_struct *handle,
2211 files_struct *dir_fsp,
2212 struct smb_filename *smb_fname)
2214 struct tevent_req *req = NULL;
2215 struct smb_full_audit_get_dos_attributes_state *state = NULL;
2216 struct tevent_req *subreq = NULL;
2218 req = tevent_req_create(mem_ctx, &state,
2219 struct smb_full_audit_get_dos_attributes_state);
2221 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2225 fsp_str_do_log(dir_fsp),
2226 smb_fname->base_name);
2229 *state = (struct smb_full_audit_get_dos_attributes_state) {
2232 .smb_fname = smb_fname,
2235 subreq = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES_SEND(mem_ctx,
2240 if (tevent_req_nomem(subreq, req)) {
2241 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2245 fsp_str_do_log(dir_fsp),
2246 smb_fname->base_name);
2247 return tevent_req_post(req, ev);
2249 tevent_req_set_callback(subreq,
2250 smb_full_audit_get_dos_attributes_done,
2253 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2257 fsp_str_do_log(dir_fsp),
2258 smb_fname->base_name);
2263 static void smb_full_audit_get_dos_attributes_done(struct tevent_req *subreq)
2265 struct tevent_req *req =
2266 tevent_req_callback_data(subreq,
2268 struct smb_full_audit_get_dos_attributes_state *state =
2269 tevent_req_data(req,
2270 struct smb_full_audit_get_dos_attributes_state);
2273 status = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES_RECV(subreq,
2276 TALLOC_FREE(subreq);
2277 if (tevent_req_nterror(req, status)) {
2281 tevent_req_done(req);
2285 static NTSTATUS smb_full_audit_get_dos_attributes_recv(struct tevent_req *req,
2286 struct vfs_aio_state *aio_state,
2289 struct smb_full_audit_get_dos_attributes_state *state =
2290 tevent_req_data(req,
2291 struct smb_full_audit_get_dos_attributes_state);
2294 if (tevent_req_is_nterror(req, &status)) {
2295 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV,
2299 fsp_str_do_log(state->dir_fsp),
2300 state->smb_fname->base_name);
2301 tevent_req_received(req);
2305 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV,
2309 fsp_str_do_log(state->dir_fsp),
2310 state->smb_fname->base_name);
2312 *aio_state = state->aio_state;
2313 *dosmode = state->dosmode;
2314 tevent_req_received(req);
2315 return NT_STATUS_OK;
2318 static NTSTATUS smb_full_audit_fget_dos_attributes(
2319 struct vfs_handle_struct *handle,
2320 struct files_struct *fsp,
2325 status = SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle,
2329 do_log(SMB_VFS_OP_FGET_DOS_ATTRIBUTES,
2330 NT_STATUS_IS_OK(status),
2333 fsp_str_do_log(fsp));
2338 static NTSTATUS smb_full_audit_set_dos_attributes(
2339 struct vfs_handle_struct *handle,
2340 const struct smb_filename *smb_fname,
2345 status = SMB_VFS_NEXT_SET_DOS_ATTRIBUTES(handle,
2349 do_log(SMB_VFS_OP_SET_DOS_ATTRIBUTES,
2350 NT_STATUS_IS_OK(status),
2353 smb_fname_str_do_log(handle->conn, smb_fname));
2358 static NTSTATUS smb_full_audit_fset_dos_attributes(
2359 struct vfs_handle_struct *handle,
2360 struct files_struct *fsp,
2365 status = SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle,
2369 do_log(SMB_VFS_OP_FSET_DOS_ATTRIBUTES,
2370 NT_STATUS_IS_OK(status),
2373 fsp_str_do_log(fsp));
2378 static NTSTATUS smb_full_audit_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
2379 uint32_t security_info,
2380 TALLOC_CTX *mem_ctx,
2381 struct security_descriptor **ppdesc)
2385 result = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
2388 do_log(SMB_VFS_OP_FGET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2389 "%s", fsp_str_do_log(fsp));
2394 static NTSTATUS smb_full_audit_get_nt_acl(vfs_handle_struct *handle,
2395 const struct smb_filename *smb_fname,
2396 uint32_t security_info,
2397 TALLOC_CTX *mem_ctx,
2398 struct security_descriptor **ppdesc)
2402 result = SMB_VFS_NEXT_GET_NT_ACL(handle, smb_fname, security_info,
2405 do_log(SMB_VFS_OP_GET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2406 "%s", smb_fname_str_do_log(handle->conn, smb_fname));
2411 static NTSTATUS smb_full_audit_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
2412 uint32_t security_info_sent,
2413 const struct security_descriptor *psd)
2415 struct vfs_full_audit_private_data *pd;
2419 SMB_VFS_HANDLE_GET_DATA(handle, pd,
2420 struct vfs_full_audit_private_data,
2421 return NT_STATUS_INTERNAL_ERROR);
2423 if (pd->log_secdesc) {
2424 sd = sddl_encode(talloc_tos(), psd, get_global_sam_sid());
2427 result = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
2429 do_log(SMB_VFS_OP_FSET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2430 "%s [%s]", fsp_str_do_log(fsp), sd ? sd : "");
2437 static NTSTATUS smb_full_audit_audit_file(struct vfs_handle_struct *handle,
2438 struct smb_filename *file,
2439 struct security_acl *sacl,
2440 uint32_t access_requested,
2441 uint32_t access_denied)
2445 result = SMB_VFS_NEXT_AUDIT_FILE(handle,
2451 do_log(SMB_VFS_OP_AUDIT_FILE, NT_STATUS_IS_OK(result), handle,
2453 smb_fname_str_do_log(handle->conn, file));
2458 static SMB_ACL_T smb_full_audit_sys_acl_get_file(vfs_handle_struct *handle,
2459 const struct smb_filename *smb_fname,
2460 SMB_ACL_TYPE_T type,
2461 TALLOC_CTX *mem_ctx)
2465 result = SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, smb_fname,
2468 do_log(SMB_VFS_OP_SYS_ACL_GET_FILE,
2472 smb_fname_str_do_log(handle->conn, smb_fname));
2477 static SMB_ACL_T smb_full_audit_sys_acl_get_fd(vfs_handle_struct *handle,
2478 files_struct *fsp, TALLOC_CTX *mem_ctx)
2482 result = SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp, mem_ctx);
2484 do_log(SMB_VFS_OP_SYS_ACL_GET_FD, (result != NULL), handle,
2485 "%s", fsp_str_do_log(fsp));
2490 static int smb_full_audit_sys_acl_blob_get_file(vfs_handle_struct *handle,
2491 const struct smb_filename *smb_fname,
2492 TALLOC_CTX *mem_ctx,
2493 char **blob_description,
2498 result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FILE(handle, smb_fname,
2499 mem_ctx, blob_description, blob);
2501 do_log(SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE,
2505 smb_fname_str_do_log(handle->conn, smb_fname));
2510 static int smb_full_audit_sys_acl_blob_get_fd(vfs_handle_struct *handle,
2512 TALLOC_CTX *mem_ctx,
2513 char **blob_description,
2518 result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle, fsp, mem_ctx, blob_description, blob);
2520 do_log(SMB_VFS_OP_SYS_ACL_BLOB_GET_FD, (result >= 0), handle,
2521 "%s", fsp_str_do_log(fsp));
2526 static int smb_full_audit_sys_acl_set_file(vfs_handle_struct *handle,
2527 const struct smb_filename *smb_fname,
2528 SMB_ACL_TYPE_T acltype,
2533 result = SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, smb_fname, acltype,
2536 do_log(SMB_VFS_OP_SYS_ACL_SET_FILE,
2540 smb_fname_str_do_log(handle->conn, smb_fname));
2545 static int smb_full_audit_sys_acl_set_fd(vfs_handle_struct *handle, files_struct *fsp,
2550 result = SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, theacl);
2552 do_log(SMB_VFS_OP_SYS_ACL_SET_FD, (result >= 0), handle,
2553 "%s", fsp_str_do_log(fsp));
2558 static int smb_full_audit_sys_acl_delete_def_file(vfs_handle_struct *handle,
2559 const struct smb_filename *smb_fname)
2563 result = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, smb_fname);
2565 do_log(SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE,
2569 smb_fname_str_do_log(handle->conn, smb_fname));
2574 static ssize_t smb_full_audit_getxattr(struct vfs_handle_struct *handle,
2575 const struct smb_filename *smb_fname,
2576 const char *name, void *value, size_t size)
2580 result = SMB_VFS_NEXT_GETXATTR(handle, smb_fname, name, value, size);
2582 do_log(SMB_VFS_OP_GETXATTR,
2586 smb_fname_str_do_log(handle->conn, smb_fname),
2592 struct smb_full_audit_getxattrat_state {
2593 struct vfs_aio_state aio_state;
2594 vfs_handle_struct *handle;
2595 files_struct *dir_fsp;
2596 const struct smb_filename *smb_fname;
2597 const char *xattr_name;
2599 uint8_t *xattr_value;
2602 static void smb_full_audit_getxattrat_done(struct tevent_req *subreq);
2604 static struct tevent_req *smb_full_audit_getxattrat_send(
2605 TALLOC_CTX *mem_ctx,
2606 struct tevent_context *ev,
2607 struct vfs_handle_struct *handle,
2608 files_struct *dir_fsp,
2609 const struct smb_filename *smb_fname,
2610 const char *xattr_name,
2613 struct tevent_req *req = NULL;
2614 struct tevent_req *subreq = NULL;
2615 struct smb_full_audit_getxattrat_state *state = NULL;
2617 req = tevent_req_create(mem_ctx, &state,
2618 struct smb_full_audit_getxattrat_state);
2620 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2624 fsp_str_do_log(dir_fsp),
2625 smb_fname->base_name,
2629 *state = (struct smb_full_audit_getxattrat_state) {
2632 .smb_fname = smb_fname,
2633 .xattr_name = xattr_name,
2636 subreq = SMB_VFS_NEXT_GETXATTRAT_SEND(state,
2643 if (tevent_req_nomem(subreq, req)) {
2644 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2648 fsp_str_do_log(dir_fsp),
2649 smb_fname->base_name,
2651 return tevent_req_post(req, ev);
2653 tevent_req_set_callback(subreq, smb_full_audit_getxattrat_done, req);
2655 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2659 fsp_str_do_log(dir_fsp),
2660 smb_fname->base_name,
2666 static void smb_full_audit_getxattrat_done(struct tevent_req *subreq)
2668 struct tevent_req *req = tevent_req_callback_data(
2669 subreq, struct tevent_req);
2670 struct smb_full_audit_getxattrat_state *state = tevent_req_data(
2671 req, struct smb_full_audit_getxattrat_state);
2673 state->xattr_size = SMB_VFS_NEXT_GETXATTRAT_RECV(subreq,
2676 &state->xattr_value);
2677 TALLOC_FREE(subreq);
2678 if (state->xattr_size == -1) {
2679 tevent_req_error(req, state->aio_state.error);
2683 tevent_req_done(req);
2686 static ssize_t smb_full_audit_getxattrat_recv(struct tevent_req *req,
2687 struct vfs_aio_state *aio_state,
2688 TALLOC_CTX *mem_ctx,
2689 uint8_t **xattr_value)
2691 struct smb_full_audit_getxattrat_state *state = tevent_req_data(
2692 req, struct smb_full_audit_getxattrat_state);
2695 if (tevent_req_is_unix_error(req, &aio_state->error)) {
2696 do_log(SMB_VFS_OP_GETXATTRAT_RECV,
2700 fsp_str_do_log(state->dir_fsp),
2701 state->smb_fname->base_name,
2703 tevent_req_received(req);
2707 do_log(SMB_VFS_OP_GETXATTRAT_RECV,
2711 fsp_str_do_log(state->dir_fsp),
2712 state->smb_fname->base_name,
2715 *aio_state = state->aio_state;
2716 xattr_size = state->xattr_size;
2717 if (xattr_value != NULL) {
2718 *xattr_value = talloc_move(mem_ctx, &state->xattr_value);
2721 tevent_req_received(req);
2725 static ssize_t smb_full_audit_fgetxattr(struct vfs_handle_struct *handle,
2726 struct files_struct *fsp,
2727 const char *name, void *value, size_t size)
2731 result = SMB_VFS_NEXT_FGETXATTR(handle, fsp, name, value, size);
2733 do_log(SMB_VFS_OP_FGETXATTR, (result >= 0), handle,
2734 "%s|%s", fsp_str_do_log(fsp), name);
2739 static ssize_t smb_full_audit_listxattr(struct vfs_handle_struct *handle,
2740 const struct smb_filename *smb_fname,
2746 result = SMB_VFS_NEXT_LISTXATTR(handle, smb_fname, list, size);
2748 do_log(SMB_VFS_OP_LISTXATTR,
2752 smb_fname_str_do_log(handle->conn, smb_fname));
2757 static ssize_t smb_full_audit_flistxattr(struct vfs_handle_struct *handle,
2758 struct files_struct *fsp, char *list,
2763 result = SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
2765 do_log(SMB_VFS_OP_FLISTXATTR, (result >= 0), handle,
2766 "%s", fsp_str_do_log(fsp));
2771 static int smb_full_audit_removexattr(struct vfs_handle_struct *handle,
2772 const struct smb_filename *smb_fname,
2777 result = SMB_VFS_NEXT_REMOVEXATTR(handle, smb_fname, name);
2779 do_log(SMB_VFS_OP_REMOVEXATTR,
2783 smb_fname_str_do_log(handle->conn, smb_fname),
2789 static int smb_full_audit_fremovexattr(struct vfs_handle_struct *handle,
2790 struct files_struct *fsp,
2795 result = SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, name);
2797 do_log(SMB_VFS_OP_FREMOVEXATTR, (result >= 0), handle,
2798 "%s|%s", fsp_str_do_log(fsp), name);
2803 static int smb_full_audit_setxattr(struct vfs_handle_struct *handle,
2804 const struct smb_filename *smb_fname,
2805 const char *name, const void *value, size_t size,
2810 result = SMB_VFS_NEXT_SETXATTR(handle, smb_fname, name, value, size,
2813 do_log(SMB_VFS_OP_SETXATTR,
2817 smb_fname_str_do_log(handle->conn, smb_fname),
2823 static int smb_full_audit_fsetxattr(struct vfs_handle_struct *handle,
2824 struct files_struct *fsp, const char *name,
2825 const void *value, size_t size, int flags)
2829 result = SMB_VFS_NEXT_FSETXATTR(handle, fsp, name, value, size, flags);
2831 do_log(SMB_VFS_OP_FSETXATTR, (result >= 0), handle,
2832 "%s|%s", fsp_str_do_log(fsp), name);
2837 static bool smb_full_audit_aio_force(struct vfs_handle_struct *handle,
2838 struct files_struct *fsp)
2842 result = SMB_VFS_NEXT_AIO_FORCE(handle, fsp);
2843 do_log(SMB_VFS_OP_AIO_FORCE, result, handle,
2844 "%s", fsp_str_do_log(fsp));
2849 static NTSTATUS smb_full_audit_durable_cookie(struct vfs_handle_struct *handle,
2850 struct files_struct *fsp,
2851 TALLOC_CTX *mem_ctx,
2856 result = SMB_VFS_NEXT_DURABLE_COOKIE(handle,
2861 do_log(SMB_VFS_OP_DURABLE_COOKIE, NT_STATUS_IS_OK(result), handle,
2862 "%s", fsp_str_do_log(fsp));
2867 static NTSTATUS smb_full_audit_durable_disconnect(
2868 struct vfs_handle_struct *handle,
2869 struct files_struct *fsp,
2870 const DATA_BLOB old_cookie,
2871 TALLOC_CTX *mem_ctx,
2872 DATA_BLOB *new_cookie)
2876 result = SMB_VFS_NEXT_DURABLE_DISCONNECT(handle,
2882 do_log(SMB_VFS_OP_DURABLE_DISCONNECT, NT_STATUS_IS_OK(result), handle,
2883 "%s", fsp_str_do_log(fsp));
2888 static NTSTATUS smb_full_audit_durable_reconnect(
2889 struct vfs_handle_struct *handle,
2890 struct smb_request *smb1req,
2891 struct smbXsrv_open *op,
2892 const DATA_BLOB old_cookie,
2893 TALLOC_CTX *mem_ctx,
2894 struct files_struct **fsp,
2895 DATA_BLOB *new_cookie)
2899 result = SMB_VFS_NEXT_DURABLE_RECONNECT(handle,
2907 do_log(SMB_VFS_OP_DURABLE_RECONNECT,
2908 NT_STATUS_IS_OK(result),
2915 static struct vfs_fn_pointers vfs_full_audit_fns = {
2917 /* Disk operations */
2919 .connect_fn = smb_full_audit_connect,
2920 .disconnect_fn = smb_full_audit_disconnect,
2921 .disk_free_fn = smb_full_audit_disk_free,
2922 .get_quota_fn = smb_full_audit_get_quota,
2923 .set_quota_fn = smb_full_audit_set_quota,
2924 .get_shadow_copy_data_fn = smb_full_audit_get_shadow_copy_data,
2925 .statvfs_fn = smb_full_audit_statvfs,
2926 .fs_capabilities_fn = smb_full_audit_fs_capabilities,
2927 .get_dfs_referrals_fn = smb_full_audit_get_dfs_referrals,
2928 .opendir_fn = smb_full_audit_opendir,
2929 .fdopendir_fn = smb_full_audit_fdopendir,
2930 .readdir_fn = smb_full_audit_readdir,
2931 .seekdir_fn = smb_full_audit_seekdir,
2932 .telldir_fn = smb_full_audit_telldir,
2933 .rewind_dir_fn = smb_full_audit_rewinddir,
2934 .mkdirat_fn = smb_full_audit_mkdirat,
2935 .closedir_fn = smb_full_audit_closedir,
2936 .open_fn = smb_full_audit_open,
2937 .create_file_fn = smb_full_audit_create_file,
2938 .close_fn = smb_full_audit_close,
2939 .pread_fn = smb_full_audit_pread,
2940 .pread_send_fn = smb_full_audit_pread_send,
2941 .pread_recv_fn = smb_full_audit_pread_recv,
2942 .pwrite_fn = smb_full_audit_pwrite,
2943 .pwrite_send_fn = smb_full_audit_pwrite_send,
2944 .pwrite_recv_fn = smb_full_audit_pwrite_recv,
2945 .lseek_fn = smb_full_audit_lseek,
2946 .sendfile_fn = smb_full_audit_sendfile,
2947 .recvfile_fn = smb_full_audit_recvfile,
2948 .renameat_fn = smb_full_audit_renameat,
2949 .fsync_send_fn = smb_full_audit_fsync_send,
2950 .fsync_recv_fn = smb_full_audit_fsync_recv,
2951 .stat_fn = smb_full_audit_stat,
2952 .fstat_fn = smb_full_audit_fstat,
2953 .lstat_fn = smb_full_audit_lstat,
2954 .get_alloc_size_fn = smb_full_audit_get_alloc_size,
2955 .unlinkat_fn = smb_full_audit_unlinkat,
2956 .chmod_fn = smb_full_audit_chmod,
2957 .fchmod_fn = smb_full_audit_fchmod,
2958 .fchown_fn = smb_full_audit_fchown,
2959 .lchown_fn = smb_full_audit_lchown,
2960 .chdir_fn = smb_full_audit_chdir,
2961 .getwd_fn = smb_full_audit_getwd,
2962 .ntimes_fn = smb_full_audit_ntimes,
2963 .ftruncate_fn = smb_full_audit_ftruncate,
2964 .fallocate_fn = smb_full_audit_fallocate,
2965 .lock_fn = smb_full_audit_lock,
2966 .kernel_flock_fn = smb_full_audit_kernel_flock,
2967 .fcntl_fn = smb_full_audit_fcntl,
2968 .linux_setlease_fn = smb_full_audit_linux_setlease,
2969 .getlock_fn = smb_full_audit_getlock,
2970 .symlinkat_fn = smb_full_audit_symlinkat,
2971 .readlinkat_fn = smb_full_audit_readlinkat,
2972 .linkat_fn = smb_full_audit_linkat,
2973 .mknodat_fn = smb_full_audit_mknodat,
2974 .realpath_fn = smb_full_audit_realpath,
2975 .chflags_fn = smb_full_audit_chflags,
2976 .file_id_create_fn = smb_full_audit_file_id_create,
2977 .fs_file_id_fn = smb_full_audit_fs_file_id,
2978 .offload_read_send_fn = smb_full_audit_offload_read_send,
2979 .offload_read_recv_fn = smb_full_audit_offload_read_recv,
2980 .offload_write_send_fn = smb_full_audit_offload_write_send,
2981 .offload_write_recv_fn = smb_full_audit_offload_write_recv,
2982 .get_compression_fn = smb_full_audit_get_compression,
2983 .set_compression_fn = smb_full_audit_set_compression,
2984 .snap_check_path_fn = smb_full_audit_snap_check_path,
2985 .snap_create_fn = smb_full_audit_snap_create,
2986 .snap_delete_fn = smb_full_audit_snap_delete,
2987 .streaminfo_fn = smb_full_audit_streaminfo,
2988 .get_real_filename_fn = smb_full_audit_get_real_filename,
2989 .connectpath_fn = smb_full_audit_connectpath,
2990 .brl_lock_windows_fn = smb_full_audit_brl_lock_windows,
2991 .brl_unlock_windows_fn = smb_full_audit_brl_unlock_windows,
2992 .strict_lock_check_fn = smb_full_audit_strict_lock_check,
2993 .translate_name_fn = smb_full_audit_translate_name,
2994 .fsctl_fn = smb_full_audit_fsctl,
2995 .get_dos_attributes_fn = smb_full_audit_get_dos_attributes,
2996 .get_dos_attributes_send_fn = smb_full_audit_get_dos_attributes_send,
2997 .get_dos_attributes_recv_fn = smb_full_audit_get_dos_attributes_recv,
2998 .fget_dos_attributes_fn = smb_full_audit_fget_dos_attributes,
2999 .set_dos_attributes_fn = smb_full_audit_set_dos_attributes,
3000 .fset_dos_attributes_fn = smb_full_audit_fset_dos_attributes,
3001 .fget_nt_acl_fn = smb_full_audit_fget_nt_acl,
3002 .get_nt_acl_fn = smb_full_audit_get_nt_acl,
3003 .fset_nt_acl_fn = smb_full_audit_fset_nt_acl,
3004 .audit_file_fn = smb_full_audit_audit_file,
3005 .sys_acl_get_file_fn = smb_full_audit_sys_acl_get_file,
3006 .sys_acl_get_fd_fn = smb_full_audit_sys_acl_get_fd,
3007 .sys_acl_blob_get_file_fn = smb_full_audit_sys_acl_blob_get_file,
3008 .sys_acl_blob_get_fd_fn = smb_full_audit_sys_acl_blob_get_fd,
3009 .sys_acl_set_file_fn = smb_full_audit_sys_acl_set_file,
3010 .sys_acl_set_fd_fn = smb_full_audit_sys_acl_set_fd,
3011 .sys_acl_delete_def_file_fn = smb_full_audit_sys_acl_delete_def_file,
3012 .getxattr_fn = smb_full_audit_getxattr,
3013 .getxattrat_send_fn = smb_full_audit_getxattrat_send,
3014 .getxattrat_recv_fn = smb_full_audit_getxattrat_recv,
3015 .fgetxattr_fn = smb_full_audit_fgetxattr,
3016 .listxattr_fn = smb_full_audit_listxattr,
3017 .flistxattr_fn = smb_full_audit_flistxattr,
3018 .removexattr_fn = smb_full_audit_removexattr,
3019 .fremovexattr_fn = smb_full_audit_fremovexattr,
3020 .setxattr_fn = smb_full_audit_setxattr,
3021 .fsetxattr_fn = smb_full_audit_fsetxattr,
3022 .aio_force_fn = smb_full_audit_aio_force,
3023 .durable_cookie_fn = smb_full_audit_durable_cookie,
3024 .durable_disconnect_fn = smb_full_audit_durable_disconnect,
3025 .durable_reconnect_fn = smb_full_audit_durable_reconnect,
3026 .readdir_attr_fn = smb_full_audit_readdir_attr
3031 NTSTATUS vfs_full_audit_init(TALLOC_CTX *ctx)
3035 smb_vfs_assert_all_fns(&vfs_full_audit_fns, "full_audit");
3037 ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "full_audit",
3038 &vfs_full_audit_fns);
3040 if (!NT_STATUS_IS_OK(ret))
3043 vfs_full_audit_debug_level = debug_add_class("full_audit");
3044 if (vfs_full_audit_debug_level == -1) {
3045 vfs_full_audit_debug_level = DBGC_VFS;
3046 DEBUG(0, ("vfs_full_audit: Couldn't register custom debugging "
3049 DEBUG(10, ("vfs_full_audit: Debug class number of "
3050 "'full_audit': %d\n", vfs_full_audit_debug_level));