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
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|.
42 * smbd_audit: nobody|192.168.234.1|open|fail (File not found)|r|x.txt
44 * where "nobody" is the connected username and "192.168.234.1" is the
45 * client's IP address.
49 * prefix: A macro expansion template prepended to the syslog entry.
51 * success: A list of VFS operations for which a successful completion should
52 * be logged. Defaults to no logging at all. The special operation "all" logs
53 * - you guessed it - everything.
55 * failure: A list of VFS operations for which failure to complete should be
56 * logged. Defaults to logging everything.
61 #include "system/filesys.h"
62 #include "system/syslog.h"
63 #include "smbd/smbd.h"
64 #include "../librpc/gen_ndr/ndr_netlogon.h"
67 #include "lib/param/loadparm.h"
68 #include "lib/util/bitmap.h"
69 #include "lib/util/tevent_unix.h"
70 #include "libcli/security/sddl.h"
71 #include "passdb/machine_sid.h"
72 #include "lib/util/tevent_ntstatus.h"
74 static int vfs_full_audit_debug_level = DBGC_VFS;
76 struct vfs_full_audit_private_data {
77 struct bitmap *success_ops;
78 struct bitmap *failure_ops;
86 #define DBGC_CLASS vfs_full_audit_debug_level
88 typedef enum _vfs_op_type {
93 SMB_VFS_OP_CONNECT = 0,
94 SMB_VFS_OP_DISCONNECT,
98 SMB_VFS_OP_GET_SHADOW_COPY_DATA,
100 SMB_VFS_OP_FS_CAPABILITIES,
101 SMB_VFS_OP_GET_DFS_REFERRALS,
103 /* Directory operations */
106 SMB_VFS_OP_FDOPENDIR,
110 SMB_VFS_OP_REWINDDIR,
115 /* File operations */
118 SMB_VFS_OP_CREATE_FILE,
122 SMB_VFS_OP_PREAD_SEND,
123 SMB_VFS_OP_PREAD_RECV,
126 SMB_VFS_OP_PWRITE_SEND,
127 SMB_VFS_OP_PWRITE_RECV,
133 SMB_VFS_OP_FSYNC_SEND,
134 SMB_VFS_OP_FSYNC_RECV,
138 SMB_VFS_OP_GET_ALLOC_SIZE,
148 SMB_VFS_OP_FTRUNCATE,
149 SMB_VFS_OP_FALLOCATE,
151 SMB_VFS_OP_KERNEL_FLOCK,
152 SMB_VFS_OP_LINUX_SETLEASE,
160 SMB_VFS_OP_FILE_ID_CREATE,
161 SMB_VFS_OP_FS_FILE_ID,
162 SMB_VFS_OP_STREAMINFO,
163 SMB_VFS_OP_GET_REAL_FILENAME,
164 SMB_VFS_OP_CONNECTPATH,
165 SMB_VFS_OP_BRL_LOCK_WINDOWS,
166 SMB_VFS_OP_BRL_UNLOCK_WINDOWS,
167 SMB_VFS_OP_STRICT_LOCK_CHECK,
168 SMB_VFS_OP_TRANSLATE_NAME,
170 SMB_VFS_OP_OFFLOAD_READ_SEND,
171 SMB_VFS_OP_OFFLOAD_READ_RECV,
172 SMB_VFS_OP_OFFLOAD_WRITE_SEND,
173 SMB_VFS_OP_OFFLOAD_WRITE_RECV,
174 SMB_VFS_OP_GET_COMPRESSION,
175 SMB_VFS_OP_SET_COMPRESSION,
176 SMB_VFS_OP_SNAP_CHECK_PATH,
177 SMB_VFS_OP_SNAP_CREATE,
178 SMB_VFS_OP_SNAP_DELETE,
180 /* DOS attribute operations. */
181 SMB_VFS_OP_GET_DOS_ATTRIBUTES,
182 SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
183 SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV,
184 SMB_VFS_OP_FGET_DOS_ATTRIBUTES,
185 SMB_VFS_OP_SET_DOS_ATTRIBUTES,
186 SMB_VFS_OP_FSET_DOS_ATTRIBUTES,
188 /* NT ACL operations. */
190 SMB_VFS_OP_FGET_NT_ACL,
191 SMB_VFS_OP_GET_NT_ACL,
192 SMB_VFS_OP_FSET_NT_ACL,
193 SMB_VFS_OP_AUDIT_FILE,
195 /* POSIX ACL operations. */
197 SMB_VFS_OP_SYS_ACL_GET_FILE,
198 SMB_VFS_OP_SYS_ACL_GET_FD,
199 SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE,
200 SMB_VFS_OP_SYS_ACL_BLOB_GET_FD,
201 SMB_VFS_OP_SYS_ACL_SET_FILE,
202 SMB_VFS_OP_SYS_ACL_SET_FD,
203 SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE,
207 SMB_VFS_OP_GETXATTRAT_SEND,
208 SMB_VFS_OP_GETXATTRAT_RECV,
209 SMB_VFS_OP_FGETXATTR,
210 SMB_VFS_OP_LISTXATTR,
211 SMB_VFS_OP_FLISTXATTR,
212 SMB_VFS_OP_REMOVEXATTR,
213 SMB_VFS_OP_FREMOVEXATTR,
215 SMB_VFS_OP_FSETXATTR,
218 SMB_VFS_OP_AIO_FORCE,
220 /* offline operations */
221 SMB_VFS_OP_IS_OFFLINE,
222 SMB_VFS_OP_SET_OFFLINE,
224 /* Durable handle operations. */
225 SMB_VFS_OP_DURABLE_COOKIE,
226 SMB_VFS_OP_DURABLE_DISCONNECT,
227 SMB_VFS_OP_DURABLE_RECONNECT,
229 SMB_VFS_OP_READDIR_ATTR,
231 /* This should always be last enum value */
236 /* The following array *must* be in the same order as defined in vfs_op_type */
242 { SMB_VFS_OP_CONNECT, "connect" },
243 { SMB_VFS_OP_DISCONNECT, "disconnect" },
244 { SMB_VFS_OP_DISK_FREE, "disk_free" },
245 { SMB_VFS_OP_GET_QUOTA, "get_quota" },
246 { SMB_VFS_OP_SET_QUOTA, "set_quota" },
247 { SMB_VFS_OP_GET_SHADOW_COPY_DATA, "get_shadow_copy_data" },
248 { SMB_VFS_OP_STATVFS, "statvfs" },
249 { SMB_VFS_OP_FS_CAPABILITIES, "fs_capabilities" },
250 { SMB_VFS_OP_GET_DFS_REFERRALS, "get_dfs_referrals" },
251 { SMB_VFS_OP_OPENDIR, "opendir" },
252 { SMB_VFS_OP_FDOPENDIR, "fdopendir" },
253 { SMB_VFS_OP_READDIR, "readdir" },
254 { SMB_VFS_OP_SEEKDIR, "seekdir" },
255 { SMB_VFS_OP_TELLDIR, "telldir" },
256 { SMB_VFS_OP_REWINDDIR, "rewinddir" },
257 { SMB_VFS_OP_MKDIR, "mkdir" },
258 { SMB_VFS_OP_RMDIR, "rmdir" },
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_RENAME, "rename" },
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_UNLINK, "unlink" },
283 { SMB_VFS_OP_CHMOD, "chmod" },
284 { SMB_VFS_OP_FCHMOD, "fchmod" },
285 { SMB_VFS_OP_CHOWN, "chown" },
286 { SMB_VFS_OP_FCHOWN, "fchown" },
287 { SMB_VFS_OP_LCHOWN, "lchown" },
288 { SMB_VFS_OP_CHDIR, "chdir" },
289 { SMB_VFS_OP_GETWD, "getwd" },
290 { SMB_VFS_OP_NTIMES, "ntimes" },
291 { SMB_VFS_OP_FTRUNCATE, "ftruncate" },
292 { SMB_VFS_OP_FALLOCATE,"fallocate" },
293 { SMB_VFS_OP_LOCK, "lock" },
294 { SMB_VFS_OP_KERNEL_FLOCK, "kernel_flock" },
295 { SMB_VFS_OP_LINUX_SETLEASE, "linux_setlease" },
296 { SMB_VFS_OP_GETLOCK, "getlock" },
297 { SMB_VFS_OP_SYMLINK, "symlink" },
298 { SMB_VFS_OP_READLINK, "readlink" },
299 { SMB_VFS_OP_LINK, "link" },
300 { SMB_VFS_OP_MKNOD, "mknod" },
301 { SMB_VFS_OP_REALPATH, "realpath" },
302 { SMB_VFS_OP_CHFLAGS, "chflags" },
303 { SMB_VFS_OP_FILE_ID_CREATE, "file_id_create" },
304 { SMB_VFS_OP_FS_FILE_ID, "fs_file_id" },
305 { SMB_VFS_OP_STREAMINFO, "streaminfo" },
306 { SMB_VFS_OP_GET_REAL_FILENAME, "get_real_filename" },
307 { SMB_VFS_OP_CONNECTPATH, "connectpath" },
308 { SMB_VFS_OP_BRL_LOCK_WINDOWS, "brl_lock_windows" },
309 { SMB_VFS_OP_BRL_UNLOCK_WINDOWS, "brl_unlock_windows" },
310 { SMB_VFS_OP_STRICT_LOCK_CHECK, "strict_lock_check" },
311 { SMB_VFS_OP_TRANSLATE_NAME, "translate_name" },
312 { SMB_VFS_OP_FSCTL, "fsctl" },
313 { SMB_VFS_OP_OFFLOAD_READ_SEND, "offload_read_send" },
314 { SMB_VFS_OP_OFFLOAD_READ_RECV, "offload_read_recv" },
315 { SMB_VFS_OP_OFFLOAD_WRITE_SEND, "offload_write_send" },
316 { SMB_VFS_OP_OFFLOAD_WRITE_RECV, "offload_write_recv" },
317 { SMB_VFS_OP_GET_COMPRESSION, "get_compression" },
318 { SMB_VFS_OP_SET_COMPRESSION, "set_compression" },
319 { SMB_VFS_OP_SNAP_CHECK_PATH, "snap_check_path" },
320 { SMB_VFS_OP_SNAP_CREATE, "snap_create" },
321 { SMB_VFS_OP_SNAP_DELETE, "snap_delete" },
322 { SMB_VFS_OP_GET_DOS_ATTRIBUTES, "get_dos_attributes" },
323 { SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND, "get_dos_attributes_send" },
324 { SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV, "get_dos_attributes_recv" },
325 { SMB_VFS_OP_FGET_DOS_ATTRIBUTES, "fget_dos_attributes" },
326 { SMB_VFS_OP_SET_DOS_ATTRIBUTES, "set_dos_attributes" },
327 { SMB_VFS_OP_FSET_DOS_ATTRIBUTES, "fset_dos_attributes" },
328 { SMB_VFS_OP_FGET_NT_ACL, "fget_nt_acl" },
329 { SMB_VFS_OP_GET_NT_ACL, "get_nt_acl" },
330 { SMB_VFS_OP_FSET_NT_ACL, "fset_nt_acl" },
331 { SMB_VFS_OP_AUDIT_FILE, "audit_file" },
332 { SMB_VFS_OP_SYS_ACL_GET_FILE, "sys_acl_get_file" },
333 { SMB_VFS_OP_SYS_ACL_GET_FD, "sys_acl_get_fd" },
334 { SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE, "sys_acl_blob_get_file" },
335 { SMB_VFS_OP_SYS_ACL_BLOB_GET_FD, "sys_acl_blob_get_fd" },
336 { SMB_VFS_OP_SYS_ACL_SET_FILE, "sys_acl_set_file" },
337 { SMB_VFS_OP_SYS_ACL_SET_FD, "sys_acl_set_fd" },
338 { SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE, "sys_acl_delete_def_file" },
339 { SMB_VFS_OP_GETXATTR, "getxattr" },
340 { SMB_VFS_OP_GETXATTRAT_SEND, "getxattrat_send" },
341 { SMB_VFS_OP_GETXATTRAT_RECV, "getxattrat_recv" },
342 { SMB_VFS_OP_FGETXATTR, "fgetxattr" },
343 { SMB_VFS_OP_LISTXATTR, "listxattr" },
344 { SMB_VFS_OP_FLISTXATTR, "flistxattr" },
345 { SMB_VFS_OP_REMOVEXATTR, "removexattr" },
346 { SMB_VFS_OP_FREMOVEXATTR, "fremovexattr" },
347 { SMB_VFS_OP_SETXATTR, "setxattr" },
348 { SMB_VFS_OP_FSETXATTR, "fsetxattr" },
349 { SMB_VFS_OP_AIO_FORCE, "aio_force" },
350 { SMB_VFS_OP_IS_OFFLINE, "is_offline" },
351 { SMB_VFS_OP_SET_OFFLINE, "set_offline" },
352 { SMB_VFS_OP_DURABLE_COOKIE, "durable_cookie" },
353 { SMB_VFS_OP_DURABLE_DISCONNECT, "durable_disconnect" },
354 { SMB_VFS_OP_DURABLE_RECONNECT, "durable_reconnect" },
355 { SMB_VFS_OP_READDIR_ATTR, "readdir_attr" },
356 { SMB_VFS_OP_LAST, NULL }
359 static int audit_syslog_facility(vfs_handle_struct *handle)
361 static const struct enum_list enum_log_facilities[] = {
363 { LOG_AUTH, "AUTH" },
366 { LOG_AUTHPRIV, "AUTHPRIV" },
369 { LOG_AUDIT, "AUDIT" },
372 { LOG_CONSOLE, "CONSOLE" },
375 { LOG_CRON, "CRON" },
378 { LOG_DAEMON, "DAEMON" },
384 { LOG_INSTALL, "INSTALL" },
387 { LOG_KERN, "KERN" },
390 { LOG_LAUNCHD, "LAUNCHD" },
393 { LOG_LFMT, "LFMT" },
399 { LOG_MAIL, "MAIL" },
402 { LOG_MEGASAFE, "MEGASAFE" },
405 { LOG_NETINFO, "NETINFO" },
408 { LOG_NEWS, "NEWS" },
410 #ifdef LOG_NFACILITIES
411 { LOG_NFACILITIES, "NFACILITIES" },
419 #ifdef LOG_REMOTEAUTH
420 { LOG_REMOTEAUTH, "REMOTEAUTH" },
423 { LOG_SECURITY, "SECURITY" },
426 { LOG_SYSLOG, "SYSLOG" },
429 { LOG_USER, "USER" },
432 { LOG_UUCP, "UUCP" },
434 { LOG_LOCAL0, "LOCAL0" },
435 { LOG_LOCAL1, "LOCAL1" },
436 { LOG_LOCAL2, "LOCAL2" },
437 { LOG_LOCAL3, "LOCAL3" },
438 { LOG_LOCAL4, "LOCAL4" },
439 { LOG_LOCAL5, "LOCAL5" },
440 { LOG_LOCAL6, "LOCAL6" },
441 { LOG_LOCAL7, "LOCAL7" },
447 facility = lp_parm_enum(SNUM(handle->conn), "full_audit", "facility", enum_log_facilities, LOG_USER);
452 static int audit_syslog_priority(vfs_handle_struct *handle)
454 static const struct enum_list enum_log_priorities[] = {
455 { LOG_EMERG, "EMERG" },
456 { LOG_ALERT, "ALERT" },
457 { LOG_CRIT, "CRIT" },
459 { LOG_WARNING, "WARNING" },
460 { LOG_NOTICE, "NOTICE" },
461 { LOG_INFO, "INFO" },
462 { LOG_DEBUG, "DEBUG" },
468 priority = lp_parm_enum(SNUM(handle->conn), "full_audit", "priority",
469 enum_log_priorities, LOG_NOTICE);
470 if (priority == -1) {
471 priority = LOG_WARNING;
477 static char *audit_prefix(TALLOC_CTX *ctx, connection_struct *conn)
482 prefix = talloc_strdup(ctx,
483 lp_parm_const_string(SNUM(conn), "full_audit",
488 result = talloc_sub_advanced(ctx,
489 lp_servicename(talloc_tos(), SNUM(conn)),
490 conn->session_info->unix_info->unix_name,
492 conn->session_info->unix_token->gid,
493 conn->session_info->unix_info->sanitized_username,
494 conn->session_info->info->domain_name,
500 static bool log_success(struct vfs_full_audit_private_data *pd, vfs_op_type op)
502 if (pd->success_ops == NULL) {
506 return bitmap_query(pd->success_ops, op);
509 static bool log_failure(struct vfs_full_audit_private_data *pd, vfs_op_type op)
511 if (pd->failure_ops == NULL)
514 return bitmap_query(pd->failure_ops, op);
517 static struct bitmap *init_bitmap(TALLOC_CTX *mem_ctx, const char **ops)
525 bm = bitmap_talloc(mem_ctx, SMB_VFS_OP_LAST);
527 DEBUG(0, ("Could not alloc bitmap -- "
528 "defaulting to logging everything\n"));
532 for (; *ops != NULL; ops += 1) {
537 if (strequal(*ops, "all")) {
538 for (i=0; i<SMB_VFS_OP_LAST; i++) {
544 if (strequal(*ops, "none")) {
554 for (i=0; i<SMB_VFS_OP_LAST; i++) {
555 if ((vfs_op_names[i].name == NULL)
556 || (vfs_op_names[i].type != i)) {
557 smb_panic("vfs_full_audit.c: name table not "
558 "in sync with vfs_op_type enums\n");
560 if (strequal(op, vfs_op_names[i].name)) {
569 if (i == SMB_VFS_OP_LAST) {
570 DEBUG(0, ("Could not find opname %s, logging all\n",
579 static const char *audit_opname(vfs_op_type op)
581 if (op >= SMB_VFS_OP_LAST)
582 return "INVALID VFS OP";
583 return vfs_op_names[op].name;
586 static TALLOC_CTX *tmp_do_log_ctx;
588 * Get us a temporary talloc context usable just for DEBUG arguments
590 static TALLOC_CTX *do_log_ctx(void)
592 if (tmp_do_log_ctx == NULL) {
593 tmp_do_log_ctx = talloc_named_const(NULL, 0, "do_log_ctx");
595 return tmp_do_log_ctx;
598 static void do_log(vfs_op_type op, bool success, vfs_handle_struct *handle,
599 const char *format, ...) PRINTF_ATTRIBUTE(4, 5);
601 static void do_log(vfs_op_type op, bool success, vfs_handle_struct *handle,
602 const char *format, ...)
604 struct vfs_full_audit_private_data *pd;
606 char *audit_pre = NULL;
610 SMB_VFS_HANDLE_GET_DATA(handle, pd,
611 struct vfs_full_audit_private_data,
614 if (success && (!log_success(pd, op)))
617 if (!success && (!log_failure(pd, op)))
621 fstrcpy(err_msg, "ok");
623 fstr_sprintf(err_msg, "fail (%s)", strerror(errno));
625 va_start(ap, format);
626 op_msg = talloc_vasprintf(talloc_tos(), format, ap);
633 audit_pre = audit_prefix(talloc_tos(), handle->conn);
639 * Specify the facility to interoperate with other syslog
640 * callers (smbd for example).
642 priority = pd->syslog_priority | pd->syslog_facility;
644 syslog(priority, "%s|%s|%s|%s\n",
645 audit_pre ? audit_pre : "",
646 audit_opname(op), err_msg, op_msg);
648 DEBUG(1, ("%s|%s|%s|%s\n",
649 audit_pre ? audit_pre : "",
650 audit_opname(op), err_msg, op_msg));
653 TALLOC_FREE(audit_pre);
655 TALLOC_FREE(tmp_do_log_ctx);
659 * Return a string using the do_log_ctx()
661 static const char *smb_fname_str_do_log(const struct smb_filename *cwd,
662 const struct smb_filename *smb_fname)
667 if (smb_fname == NULL) {
671 if (smb_fname->base_name[0] != '/') {
672 char *abs_name = NULL;
673 struct smb_filename *fname_copy = cp_smb_filename(
676 if (fname_copy == NULL) {
680 if (!ISDOT(smb_fname->base_name)) {
681 abs_name = talloc_asprintf(do_log_ctx(),
684 smb_fname->base_name);
686 abs_name = talloc_strdup(do_log_ctx(),
689 if (abs_name == NULL) {
692 fname_copy->base_name = abs_name;
693 smb_fname = fname_copy;
696 status = get_full_smb_filename(do_log_ctx(), smb_fname, &fname);
697 if (!NT_STATUS_IS_OK(status)) {
704 * Return an fsp debug string using the do_log_ctx()
706 static const char *fsp_str_do_log(const struct files_struct *fsp)
708 return smb_fname_str_do_log(fsp->conn->cwd_fname, fsp->fsp_name);
711 /* Implementation of vfs_ops. Pass everything on to the default
712 operation but log event first. */
714 static int smb_full_audit_connect(vfs_handle_struct *handle,
715 const char *svc, const char *user)
718 const char *none[] = { "none" };
719 struct vfs_full_audit_private_data *pd = NULL;
721 result = SMB_VFS_NEXT_CONNECT(handle, svc, user);
726 pd = talloc_zero(handle, struct vfs_full_audit_private_data);
728 SMB_VFS_NEXT_DISCONNECT(handle);
732 pd->syslog_facility = audit_syslog_facility(handle);
733 if (pd->syslog_facility == -1) {
734 DEBUG(1, ("%s: Unknown facility %s\n", __func__,
735 lp_parm_const_string(SNUM(handle->conn),
736 "full_audit", "facility",
738 SMB_VFS_NEXT_DISCONNECT(handle);
742 pd->syslog_priority = audit_syslog_priority(handle);
744 pd->log_secdesc = lp_parm_bool(SNUM(handle->conn),
745 "full_audit", "log_secdesc", false);
747 pd->do_syslog = lp_parm_bool(SNUM(handle->conn),
748 "full_audit", "syslog", true);
752 openlog("smbd_audit", 0, pd->syslog_facility);
756 pd->success_ops = init_bitmap(
757 pd, lp_parm_string_list(SNUM(handle->conn), "full_audit",
759 pd->failure_ops = init_bitmap(
760 pd, lp_parm_string_list(SNUM(handle->conn), "full_audit",
763 /* Store the private data. */
764 SMB_VFS_HANDLE_SET_DATA(handle, pd, NULL,
765 struct vfs_full_audit_private_data, return -1);
767 do_log(SMB_VFS_OP_CONNECT, True, handle,
773 static void smb_full_audit_disconnect(vfs_handle_struct *handle)
775 SMB_VFS_NEXT_DISCONNECT(handle);
777 do_log(SMB_VFS_OP_DISCONNECT, True, handle,
778 "%s", lp_servicename(talloc_tos(), SNUM(handle->conn)));
780 /* The bitmaps will be disconnected when the private
784 static uint64_t smb_full_audit_disk_free(vfs_handle_struct *handle,
785 const struct smb_filename *smb_fname,
792 result = SMB_VFS_NEXT_DISK_FREE(handle, smb_fname, bsize, dfree, dsize);
794 /* Don't have a reasonable notion of failure here */
796 do_log(SMB_VFS_OP_DISK_FREE, True, handle, "%s", smb_fname->base_name);
801 static int smb_full_audit_get_quota(struct vfs_handle_struct *handle,
802 const struct smb_filename *smb_fname,
803 enum SMB_QUOTA_TYPE qtype,
809 result = SMB_VFS_NEXT_GET_QUOTA(handle, smb_fname, qtype, id, qt);
811 do_log(SMB_VFS_OP_GET_QUOTA, (result >= 0), handle, "%s",
812 smb_fname->base_name);
817 static int smb_full_audit_set_quota(struct vfs_handle_struct *handle,
818 enum SMB_QUOTA_TYPE qtype, unid_t id,
823 result = SMB_VFS_NEXT_SET_QUOTA(handle, qtype, id, qt);
825 do_log(SMB_VFS_OP_SET_QUOTA, (result >= 0), handle, "");
830 static int smb_full_audit_get_shadow_copy_data(struct vfs_handle_struct *handle,
831 struct files_struct *fsp,
832 struct shadow_copy_data *shadow_copy_data,
837 result = SMB_VFS_NEXT_GET_SHADOW_COPY_DATA(handle, fsp, shadow_copy_data, labels);
839 do_log(SMB_VFS_OP_GET_SHADOW_COPY_DATA, (result >= 0), handle, "");
844 static int smb_full_audit_statvfs(struct vfs_handle_struct *handle,
845 const struct smb_filename *smb_fname,
846 struct vfs_statvfs_struct *statbuf)
850 result = SMB_VFS_NEXT_STATVFS(handle, smb_fname, statbuf);
852 do_log(SMB_VFS_OP_STATVFS, (result >= 0), handle, "");
857 static uint32_t smb_full_audit_fs_capabilities(struct vfs_handle_struct *handle, enum timestamp_set_resolution *p_ts_res)
861 result = SMB_VFS_NEXT_FS_CAPABILITIES(handle, p_ts_res);
863 do_log(SMB_VFS_OP_FS_CAPABILITIES, true, handle, "");
868 static NTSTATUS smb_full_audit_get_dfs_referrals(
869 struct vfs_handle_struct *handle,
870 struct dfs_GetDFSReferral *r)
874 status = SMB_VFS_NEXT_GET_DFS_REFERRALS(handle, r);
876 do_log(SMB_VFS_OP_GET_DFS_REFERRALS, NT_STATUS_IS_OK(status),
882 static NTSTATUS smb_full_audit_snap_check_path(struct vfs_handle_struct *handle,
884 const char *service_path,
889 status = SMB_VFS_NEXT_SNAP_CHECK_PATH(handle, mem_ctx, service_path,
891 do_log(SMB_VFS_OP_SNAP_CHECK_PATH, NT_STATUS_IS_OK(status),
897 static NTSTATUS smb_full_audit_snap_create(struct vfs_handle_struct *handle,
899 const char *base_volume,
907 status = SMB_VFS_NEXT_SNAP_CREATE(handle, mem_ctx, base_volume, tstamp,
908 rw, base_path, snap_path);
909 do_log(SMB_VFS_OP_SNAP_CREATE, NT_STATUS_IS_OK(status), handle, "");
914 static NTSTATUS smb_full_audit_snap_delete(struct vfs_handle_struct *handle,
921 status = SMB_VFS_NEXT_SNAP_DELETE(handle, mem_ctx, base_path,
923 do_log(SMB_VFS_OP_SNAP_DELETE, NT_STATUS_IS_OK(status), handle, "");
928 static DIR *smb_full_audit_opendir(vfs_handle_struct *handle,
929 const struct smb_filename *smb_fname,
935 result = SMB_VFS_NEXT_OPENDIR(handle, smb_fname, mask, attr);
937 do_log(SMB_VFS_OP_OPENDIR, (result != NULL), handle, "%s",
938 smb_fname->base_name);
943 static DIR *smb_full_audit_fdopendir(vfs_handle_struct *handle,
944 files_struct *fsp, const char *mask, uint32_t attr)
948 result = SMB_VFS_NEXT_FDOPENDIR(handle, fsp, mask, attr);
950 do_log(SMB_VFS_OP_FDOPENDIR, (result != NULL), handle, "%s",
951 fsp_str_do_log(fsp));
956 static struct dirent *smb_full_audit_readdir(vfs_handle_struct *handle,
957 DIR *dirp, SMB_STRUCT_STAT *sbuf)
959 struct dirent *result;
961 result = SMB_VFS_NEXT_READDIR(handle, dirp, sbuf);
963 /* This operation has no reasonable error condition
964 * (End of dir is also failure), so always succeed.
966 do_log(SMB_VFS_OP_READDIR, True, handle, "");
971 static void smb_full_audit_seekdir(vfs_handle_struct *handle,
972 DIR *dirp, long offset)
974 SMB_VFS_NEXT_SEEKDIR(handle, dirp, offset);
976 do_log(SMB_VFS_OP_SEEKDIR, True, handle, "");
979 static long smb_full_audit_telldir(vfs_handle_struct *handle,
984 result = SMB_VFS_NEXT_TELLDIR(handle, dirp);
986 do_log(SMB_VFS_OP_TELLDIR, True, handle, "");
991 static void smb_full_audit_rewinddir(vfs_handle_struct *handle,
994 SMB_VFS_NEXT_REWINDDIR(handle, dirp);
996 do_log(SMB_VFS_OP_REWINDDIR, True, handle, "");
999 static int smb_full_audit_mkdir(vfs_handle_struct *handle,
1000 const struct smb_filename *smb_fname, mode_t mode)
1004 result = SMB_VFS_NEXT_MKDIR(handle, smb_fname, mode);
1006 do_log(SMB_VFS_OP_MKDIR, (result >= 0), handle, "%s",
1007 smb_fname->base_name);
1012 static int smb_full_audit_rmdir(vfs_handle_struct *handle,
1013 const struct smb_filename *smb_fname)
1017 result = SMB_VFS_NEXT_RMDIR(handle, smb_fname);
1019 do_log(SMB_VFS_OP_RMDIR, (result >= 0), handle, "%s",
1020 smb_fname->base_name);
1025 static int smb_full_audit_closedir(vfs_handle_struct *handle,
1030 result = SMB_VFS_NEXT_CLOSEDIR(handle, dirp);
1032 do_log(SMB_VFS_OP_CLOSEDIR, (result >= 0), handle, "");
1037 static int smb_full_audit_open(vfs_handle_struct *handle,
1038 struct smb_filename *smb_fname,
1039 files_struct *fsp, int flags, mode_t mode)
1043 result = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
1045 do_log(SMB_VFS_OP_OPEN, (result >= 0), handle, "%s|%s",
1046 ((flags & O_WRONLY) || (flags & O_RDWR))?"w":"r",
1047 smb_fname_str_do_log(handle->conn->cwd_fname, smb_fname));
1052 static NTSTATUS smb_full_audit_create_file(vfs_handle_struct *handle,
1053 struct smb_request *req,
1054 uint16_t root_dir_fid,
1055 struct smb_filename *smb_fname,
1056 uint32_t access_mask,
1057 uint32_t share_access,
1058 uint32_t create_disposition,
1059 uint32_t create_options,
1060 uint32_t file_attributes,
1061 uint32_t oplock_request,
1062 struct smb2_lease *lease,
1063 uint64_t allocation_size,
1064 uint32_t private_flags,
1065 struct security_descriptor *sd,
1066 struct ea_list *ea_list,
1067 files_struct **result_fsp,
1069 const struct smb2_create_blobs *in_context_blobs,
1070 struct smb2_create_blobs *out_context_blobs)
1073 const char* str_create_disposition;
1075 switch (create_disposition) {
1076 case FILE_SUPERSEDE:
1077 str_create_disposition = "supersede";
1079 case FILE_OVERWRITE_IF:
1080 str_create_disposition = "overwrite_if";
1083 str_create_disposition = "open";
1085 case FILE_OVERWRITE:
1086 str_create_disposition = "overwrite";
1089 str_create_disposition = "create";
1092 str_create_disposition = "open_if";
1095 str_create_disposition = "unknown";
1098 result = SMB_VFS_NEXT_CREATE_FILE(
1099 handle, /* handle */
1101 root_dir_fid, /* root_dir_fid */
1102 smb_fname, /* fname */
1103 access_mask, /* access_mask */
1104 share_access, /* share_access */
1105 create_disposition, /* create_disposition*/
1106 create_options, /* create_options */
1107 file_attributes, /* file_attributes */
1108 oplock_request, /* oplock_request */
1110 allocation_size, /* allocation_size */
1113 ea_list, /* ea_list */
1114 result_fsp, /* result */
1116 in_context_blobs, out_context_blobs); /* create context */
1118 do_log(SMB_VFS_OP_CREATE_FILE, (NT_STATUS_IS_OK(result)), handle,
1119 "0x%x|%s|%s|%s", access_mask,
1120 create_options & FILE_DIRECTORY_FILE ? "dir" : "file",
1121 str_create_disposition,
1122 smb_fname_str_do_log(handle->conn->cwd_fname, smb_fname));
1127 static int smb_full_audit_close(vfs_handle_struct *handle, files_struct *fsp)
1131 result = SMB_VFS_NEXT_CLOSE(handle, fsp);
1133 do_log(SMB_VFS_OP_CLOSE, (result >= 0), handle, "%s",
1134 fsp_str_do_log(fsp));
1139 static ssize_t smb_full_audit_pread(vfs_handle_struct *handle, files_struct *fsp,
1140 void *data, size_t n, off_t offset)
1144 result = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
1146 do_log(SMB_VFS_OP_PREAD, (result >= 0), handle, "%s",
1147 fsp_str_do_log(fsp));
1152 struct smb_full_audit_pread_state {
1153 vfs_handle_struct *handle;
1156 struct vfs_aio_state vfs_aio_state;
1159 static void smb_full_audit_pread_done(struct tevent_req *subreq);
1161 static struct tevent_req *smb_full_audit_pread_send(
1162 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1163 struct tevent_context *ev, struct files_struct *fsp,
1164 void *data, size_t n, off_t offset)
1166 struct tevent_req *req, *subreq;
1167 struct smb_full_audit_pread_state *state;
1169 req = tevent_req_create(mem_ctx, &state,
1170 struct smb_full_audit_pread_state);
1172 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
1173 fsp_str_do_log(fsp));
1176 state->handle = handle;
1179 subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
1181 if (tevent_req_nomem(subreq, req)) {
1182 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
1183 fsp_str_do_log(fsp));
1184 return tevent_req_post(req, ev);
1186 tevent_req_set_callback(subreq, smb_full_audit_pread_done, req);
1188 do_log(SMB_VFS_OP_PREAD_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1192 static void smb_full_audit_pread_done(struct tevent_req *subreq)
1194 struct tevent_req *req = tevent_req_callback_data(
1195 subreq, struct tevent_req);
1196 struct smb_full_audit_pread_state *state = tevent_req_data(
1197 req, struct smb_full_audit_pread_state);
1199 state->ret = SMB_VFS_PREAD_RECV(subreq, &state->vfs_aio_state);
1200 TALLOC_FREE(subreq);
1201 tevent_req_done(req);
1204 static ssize_t smb_full_audit_pread_recv(struct tevent_req *req,
1205 struct vfs_aio_state *vfs_aio_state)
1207 struct smb_full_audit_pread_state *state = tevent_req_data(
1208 req, struct smb_full_audit_pread_state);
1210 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1211 do_log(SMB_VFS_OP_PREAD_RECV, false, state->handle, "%s",
1212 fsp_str_do_log(state->fsp));
1216 do_log(SMB_VFS_OP_PREAD_RECV, (state->ret >= 0), state->handle, "%s",
1217 fsp_str_do_log(state->fsp));
1219 *vfs_aio_state = state->vfs_aio_state;
1223 static ssize_t smb_full_audit_pwrite(vfs_handle_struct *handle, files_struct *fsp,
1224 const void *data, size_t n,
1229 result = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
1231 do_log(SMB_VFS_OP_PWRITE, (result >= 0), handle, "%s",
1232 fsp_str_do_log(fsp));
1237 struct smb_full_audit_pwrite_state {
1238 vfs_handle_struct *handle;
1241 struct vfs_aio_state vfs_aio_state;
1244 static void smb_full_audit_pwrite_done(struct tevent_req *subreq);
1246 static struct tevent_req *smb_full_audit_pwrite_send(
1247 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1248 struct tevent_context *ev, struct files_struct *fsp,
1249 const void *data, size_t n, off_t offset)
1251 struct tevent_req *req, *subreq;
1252 struct smb_full_audit_pwrite_state *state;
1254 req = tevent_req_create(mem_ctx, &state,
1255 struct smb_full_audit_pwrite_state);
1257 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1258 fsp_str_do_log(fsp));
1261 state->handle = handle;
1264 subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
1266 if (tevent_req_nomem(subreq, req)) {
1267 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1268 fsp_str_do_log(fsp));
1269 return tevent_req_post(req, ev);
1271 tevent_req_set_callback(subreq, smb_full_audit_pwrite_done, req);
1273 do_log(SMB_VFS_OP_PWRITE_SEND, true, handle, "%s",
1274 fsp_str_do_log(fsp));
1278 static void smb_full_audit_pwrite_done(struct tevent_req *subreq)
1280 struct tevent_req *req = tevent_req_callback_data(
1281 subreq, struct tevent_req);
1282 struct smb_full_audit_pwrite_state *state = tevent_req_data(
1283 req, struct smb_full_audit_pwrite_state);
1285 state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->vfs_aio_state);
1286 TALLOC_FREE(subreq);
1287 tevent_req_done(req);
1290 static ssize_t smb_full_audit_pwrite_recv(struct tevent_req *req,
1291 struct vfs_aio_state *vfs_aio_state)
1293 struct smb_full_audit_pwrite_state *state = tevent_req_data(
1294 req, struct smb_full_audit_pwrite_state);
1296 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1297 do_log(SMB_VFS_OP_PWRITE_RECV, false, state->handle, "%s",
1298 fsp_str_do_log(state->fsp));
1302 do_log(SMB_VFS_OP_PWRITE_RECV, (state->ret >= 0), state->handle, "%s",
1303 fsp_str_do_log(state->fsp));
1305 *vfs_aio_state = state->vfs_aio_state;
1309 static off_t smb_full_audit_lseek(vfs_handle_struct *handle, files_struct *fsp,
1310 off_t offset, int whence)
1314 result = SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence);
1316 do_log(SMB_VFS_OP_LSEEK, (result != (ssize_t)-1), handle,
1317 "%s", fsp_str_do_log(fsp));
1322 static ssize_t smb_full_audit_sendfile(vfs_handle_struct *handle, int tofd,
1323 files_struct *fromfsp,
1324 const DATA_BLOB *hdr, off_t offset,
1329 result = SMB_VFS_NEXT_SENDFILE(handle, tofd, fromfsp, hdr, offset, n);
1331 do_log(SMB_VFS_OP_SENDFILE, (result >= 0), handle,
1332 "%s", fsp_str_do_log(fromfsp));
1337 static ssize_t smb_full_audit_recvfile(vfs_handle_struct *handle, int fromfd,
1338 files_struct *tofsp,
1344 result = SMB_VFS_NEXT_RECVFILE(handle, fromfd, tofsp, offset, n);
1346 do_log(SMB_VFS_OP_RECVFILE, (result >= 0), handle,
1347 "%s", fsp_str_do_log(tofsp));
1352 static int smb_full_audit_rename(vfs_handle_struct *handle,
1353 const struct smb_filename *smb_fname_src,
1354 const struct smb_filename *smb_fname_dst)
1358 result = SMB_VFS_NEXT_RENAME(handle, smb_fname_src, smb_fname_dst);
1360 do_log(SMB_VFS_OP_RENAME, (result >= 0), handle, "%s|%s",
1361 smb_fname_str_do_log(handle->conn->cwd_fname, smb_fname_src),
1362 smb_fname_str_do_log(handle->conn->cwd_fname, smb_fname_dst));
1367 struct smb_full_audit_fsync_state {
1368 vfs_handle_struct *handle;
1371 struct vfs_aio_state vfs_aio_state;
1374 static void smb_full_audit_fsync_done(struct tevent_req *subreq);
1376 static struct tevent_req *smb_full_audit_fsync_send(
1377 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1378 struct tevent_context *ev, struct files_struct *fsp)
1380 struct tevent_req *req, *subreq;
1381 struct smb_full_audit_fsync_state *state;
1383 req = tevent_req_create(mem_ctx, &state,
1384 struct smb_full_audit_fsync_state);
1386 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1387 fsp_str_do_log(fsp));
1390 state->handle = handle;
1393 subreq = SMB_VFS_NEXT_FSYNC_SEND(state, ev, handle, fsp);
1394 if (tevent_req_nomem(subreq, req)) {
1395 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1396 fsp_str_do_log(fsp));
1397 return tevent_req_post(req, ev);
1399 tevent_req_set_callback(subreq, smb_full_audit_fsync_done, req);
1401 do_log(SMB_VFS_OP_FSYNC_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1405 static void smb_full_audit_fsync_done(struct tevent_req *subreq)
1407 struct tevent_req *req = tevent_req_callback_data(
1408 subreq, struct tevent_req);
1409 struct smb_full_audit_fsync_state *state = tevent_req_data(
1410 req, struct smb_full_audit_fsync_state);
1412 state->ret = SMB_VFS_FSYNC_RECV(subreq, &state->vfs_aio_state);
1413 TALLOC_FREE(subreq);
1414 tevent_req_done(req);
1417 static int smb_full_audit_fsync_recv(struct tevent_req *req,
1418 struct vfs_aio_state *vfs_aio_state)
1420 struct smb_full_audit_fsync_state *state = tevent_req_data(
1421 req, struct smb_full_audit_fsync_state);
1423 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1424 do_log(SMB_VFS_OP_FSYNC_RECV, false, state->handle, "%s",
1425 fsp_str_do_log(state->fsp));
1429 do_log(SMB_VFS_OP_FSYNC_RECV, (state->ret >= 0), state->handle, "%s",
1430 fsp_str_do_log(state->fsp));
1432 *vfs_aio_state = state->vfs_aio_state;
1436 static int smb_full_audit_stat(vfs_handle_struct *handle,
1437 struct smb_filename *smb_fname)
1441 result = SMB_VFS_NEXT_STAT(handle, smb_fname);
1443 do_log(SMB_VFS_OP_STAT, (result >= 0), handle, "%s",
1444 smb_fname_str_do_log(handle->conn->cwd_fname, smb_fname));
1449 static int smb_full_audit_fstat(vfs_handle_struct *handle, files_struct *fsp,
1450 SMB_STRUCT_STAT *sbuf)
1454 result = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1456 do_log(SMB_VFS_OP_FSTAT, (result >= 0), handle, "%s",
1457 fsp_str_do_log(fsp));
1462 static int smb_full_audit_lstat(vfs_handle_struct *handle,
1463 struct smb_filename *smb_fname)
1467 result = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
1469 do_log(SMB_VFS_OP_LSTAT, (result >= 0), handle, "%s",
1470 smb_fname_str_do_log(handle->conn->cwd_fname, smb_fname));
1475 static uint64_t smb_full_audit_get_alloc_size(vfs_handle_struct *handle,
1476 files_struct *fsp, const SMB_STRUCT_STAT *sbuf)
1480 result = SMB_VFS_NEXT_GET_ALLOC_SIZE(handle, fsp, sbuf);
1482 do_log(SMB_VFS_OP_GET_ALLOC_SIZE, (result != (uint64_t)-1), handle,
1483 "%llu", (unsigned long long)result);
1488 static int smb_full_audit_unlink(vfs_handle_struct *handle,
1489 const struct smb_filename *smb_fname)
1493 result = SMB_VFS_NEXT_UNLINK(handle, smb_fname);
1495 do_log(SMB_VFS_OP_UNLINK, (result >= 0), handle, "%s",
1496 smb_fname_str_do_log(handle->conn->cwd_fname, smb_fname));
1501 static int smb_full_audit_chmod(vfs_handle_struct *handle,
1502 const struct smb_filename *smb_fname,
1507 result = SMB_VFS_NEXT_CHMOD(handle, smb_fname, mode);
1509 do_log(SMB_VFS_OP_CHMOD, (result >= 0), handle, "%s|%o",
1510 smb_fname->base_name,
1516 static int smb_full_audit_fchmod(vfs_handle_struct *handle, files_struct *fsp,
1521 result = SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1523 do_log(SMB_VFS_OP_FCHMOD, (result >= 0), handle,
1524 "%s|%o", fsp_str_do_log(fsp), mode);
1529 static int smb_full_audit_chown(vfs_handle_struct *handle,
1530 const struct smb_filename *smb_fname,
1536 result = SMB_VFS_NEXT_CHOWN(handle, smb_fname, uid, gid);
1538 do_log(SMB_VFS_OP_CHOWN, (result >= 0), handle, "%s|%ld|%ld",
1539 smb_fname->base_name, (long int)uid, (long int)gid);
1544 static int smb_full_audit_fchown(vfs_handle_struct *handle, files_struct *fsp,
1545 uid_t uid, gid_t gid)
1549 result = SMB_VFS_NEXT_FCHOWN(handle, fsp, uid, gid);
1551 do_log(SMB_VFS_OP_FCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1552 fsp_str_do_log(fsp), (long int)uid, (long int)gid);
1557 static int smb_full_audit_lchown(vfs_handle_struct *handle,
1558 const struct smb_filename *smb_fname,
1564 result = SMB_VFS_NEXT_LCHOWN(handle, smb_fname, uid, gid);
1566 do_log(SMB_VFS_OP_LCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1567 smb_fname->base_name, (long int)uid, (long int)gid);
1572 static int smb_full_audit_chdir(vfs_handle_struct *handle,
1573 const struct smb_filename *smb_fname)
1577 result = SMB_VFS_NEXT_CHDIR(handle, smb_fname);
1579 do_log(SMB_VFS_OP_CHDIR, (result >= 0), handle, "chdir|%s",
1580 smb_fname->base_name);
1585 static struct smb_filename *smb_full_audit_getwd(vfs_handle_struct *handle,
1588 struct smb_filename *result;
1590 result = SMB_VFS_NEXT_GETWD(handle, ctx);
1592 do_log(SMB_VFS_OP_GETWD, (result != NULL), handle, "%s",
1593 result == NULL? "" : result->base_name);
1598 static int smb_full_audit_ntimes(vfs_handle_struct *handle,
1599 const struct smb_filename *smb_fname,
1600 struct smb_file_time *ft)
1603 time_t create_time = convert_timespec_to_time_t(ft->create_time);
1604 time_t atime = convert_timespec_to_time_t(ft->atime);
1605 time_t mtime = convert_timespec_to_time_t(ft->mtime);
1606 time_t ctime = convert_timespec_to_time_t(ft->ctime);
1607 const char *create_time_str = "";
1608 const char *atime_str = "";
1609 const char *mtime_str = "";
1610 const char *ctime_str = "";
1611 TALLOC_CTX *frame = talloc_stackframe();
1613 result = SMB_VFS_NEXT_NTIMES(handle, smb_fname, ft);
1615 if (create_time > 0) {
1616 create_time_str = timestring(frame, create_time);
1619 atime_str = timestring(frame, atime);
1622 mtime_str = timestring(frame, mtime);
1625 ctime_str = timestring(frame, ctime);
1628 do_log(SMB_VFS_OP_NTIMES,
1632 smb_fname_str_do_log(handle->conn->cwd_fname, smb_fname),
1643 static int smb_full_audit_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
1648 result = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1650 do_log(SMB_VFS_OP_FTRUNCATE, (result >= 0), handle,
1651 "%s", fsp_str_do_log(fsp));
1656 static int smb_full_audit_fallocate(vfs_handle_struct *handle, files_struct *fsp,
1663 result = SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
1665 do_log(SMB_VFS_OP_FALLOCATE, (result >= 0), handle,
1666 "%s", fsp_str_do_log(fsp));
1671 static bool smb_full_audit_lock(vfs_handle_struct *handle, files_struct *fsp,
1672 int op, off_t offset, off_t count, int type)
1676 result = SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type);
1678 do_log(SMB_VFS_OP_LOCK, result, handle, "%s", fsp_str_do_log(fsp));
1683 static int smb_full_audit_kernel_flock(struct vfs_handle_struct *handle,
1684 struct files_struct *fsp,
1685 uint32_t share_mode, uint32_t access_mask)
1689 result = SMB_VFS_NEXT_KERNEL_FLOCK(handle, fsp, share_mode, access_mask);
1691 do_log(SMB_VFS_OP_KERNEL_FLOCK, (result >= 0), handle, "%s",
1692 fsp_str_do_log(fsp));
1697 static int smb_full_audit_linux_setlease(vfs_handle_struct *handle, files_struct *fsp,
1702 result = SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
1704 do_log(SMB_VFS_OP_LINUX_SETLEASE, (result >= 0), handle, "%s",
1705 fsp_str_do_log(fsp));
1710 static bool smb_full_audit_getlock(vfs_handle_struct *handle, files_struct *fsp,
1711 off_t *poffset, off_t *pcount, int *ptype, pid_t *ppid)
1715 result = SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype, ppid);
1717 do_log(SMB_VFS_OP_GETLOCK, result, handle, "%s", fsp_str_do_log(fsp));
1722 static int smb_full_audit_symlink(vfs_handle_struct *handle,
1723 const char *link_contents,
1724 const struct smb_filename *new_smb_fname)
1728 result = SMB_VFS_NEXT_SYMLINK(handle, link_contents, new_smb_fname);
1730 do_log(SMB_VFS_OP_SYMLINK, (result >= 0), handle,
1731 "%s|%s", link_contents, new_smb_fname->base_name);
1736 static int smb_full_audit_readlink(vfs_handle_struct *handle,
1737 const struct smb_filename *smb_fname,
1743 result = SMB_VFS_NEXT_READLINK(handle, smb_fname, buf, bufsiz);
1745 do_log(SMB_VFS_OP_READLINK, (result >= 0), handle, "%s",
1746 smb_fname->base_name);
1751 static int smb_full_audit_link(vfs_handle_struct *handle,
1752 const struct smb_filename *old_smb_fname,
1753 const struct smb_filename *new_smb_fname)
1757 result = SMB_VFS_NEXT_LINK(handle, old_smb_fname, new_smb_fname);
1759 do_log(SMB_VFS_OP_LINK, (result >= 0), handle,
1760 "%s|%s", old_smb_fname->base_name, new_smb_fname->base_name);
1765 static int smb_full_audit_mknod(vfs_handle_struct *handle,
1766 const struct smb_filename *smb_fname,
1772 result = SMB_VFS_NEXT_MKNOD(handle, smb_fname, mode, dev);
1774 do_log(SMB_VFS_OP_MKNOD, (result >= 0), handle, "%s",
1775 smb_fname->base_name);
1780 static struct smb_filename *smb_full_audit_realpath(vfs_handle_struct *handle,
1782 const struct smb_filename *smb_fname)
1784 struct smb_filename *result_fname = NULL;
1786 result_fname = SMB_VFS_NEXT_REALPATH(handle, ctx, smb_fname);
1788 do_log(SMB_VFS_OP_REALPATH, (result_fname != NULL), handle, "%s",
1789 smb_fname->base_name);
1791 return result_fname;
1794 static int smb_full_audit_chflags(vfs_handle_struct *handle,
1795 const struct smb_filename *smb_fname,
1800 result = SMB_VFS_NEXT_CHFLAGS(handle, smb_fname, flags);
1802 do_log(SMB_VFS_OP_CHFLAGS, (result != 0), handle, "%s",
1803 smb_fname->base_name);
1808 static struct file_id smb_full_audit_file_id_create(struct vfs_handle_struct *handle,
1809 const SMB_STRUCT_STAT *sbuf)
1811 struct file_id id_zero;
1812 struct file_id result;
1814 ZERO_STRUCT(id_zero);
1816 result = SMB_VFS_NEXT_FILE_ID_CREATE(handle, sbuf);
1818 do_log(SMB_VFS_OP_FILE_ID_CREATE,
1819 !file_id_equal(&id_zero, &result),
1820 handle, "%s", file_id_string_tos(&result));
1825 static uint64_t smb_full_audit_fs_file_id(struct vfs_handle_struct *handle,
1826 const SMB_STRUCT_STAT *sbuf)
1830 result = SMB_VFS_NEXT_FS_FILE_ID(handle, sbuf);
1832 do_log(SMB_VFS_OP_FS_FILE_ID,
1834 handle, "%" PRIu64, result);
1839 static NTSTATUS smb_full_audit_streaminfo(vfs_handle_struct *handle,
1840 struct files_struct *fsp,
1841 const struct smb_filename *smb_fname,
1842 TALLOC_CTX *mem_ctx,
1843 unsigned int *pnum_streams,
1844 struct stream_struct **pstreams)
1848 result = SMB_VFS_NEXT_STREAMINFO(handle, fsp, smb_fname, mem_ctx,
1849 pnum_streams, pstreams);
1851 do_log(SMB_VFS_OP_STREAMINFO, NT_STATUS_IS_OK(result), handle,
1852 "%s", smb_fname->base_name);
1857 static int smb_full_audit_get_real_filename(struct vfs_handle_struct *handle,
1860 TALLOC_CTX *mem_ctx,
1865 result = SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name, mem_ctx,
1868 do_log(SMB_VFS_OP_GET_REAL_FILENAME, (result == 0), handle,
1869 "%s/%s->%s", path, name, (result == 0) ? *found_name : "");
1874 static const char *smb_full_audit_connectpath(vfs_handle_struct *handle,
1875 const struct smb_filename *smb_fname)
1879 result = SMB_VFS_NEXT_CONNECTPATH(handle, smb_fname);
1881 do_log(SMB_VFS_OP_CONNECTPATH, result != NULL, handle,
1882 "%s", smb_fname->base_name);
1887 static NTSTATUS smb_full_audit_brl_lock_windows(struct vfs_handle_struct *handle,
1888 struct byte_range_lock *br_lck,
1889 struct lock_struct *plock)
1893 result = SMB_VFS_NEXT_BRL_LOCK_WINDOWS(handle, br_lck, plock);
1895 do_log(SMB_VFS_OP_BRL_LOCK_WINDOWS, NT_STATUS_IS_OK(result), handle,
1896 "%s:%llu-%llu. type=%d.",
1897 fsp_str_do_log(brl_fsp(br_lck)),
1898 (unsigned long long)plock->start,
1899 (unsigned long long)plock->size,
1905 static bool smb_full_audit_brl_unlock_windows(struct vfs_handle_struct *handle,
1906 struct messaging_context *msg_ctx,
1907 struct byte_range_lock *br_lck,
1908 const struct lock_struct *plock)
1912 result = SMB_VFS_NEXT_BRL_UNLOCK_WINDOWS(handle, msg_ctx, br_lck,
1915 do_log(SMB_VFS_OP_BRL_UNLOCK_WINDOWS, (result == 0), handle,
1916 "%s:%llu-%llu:%d", fsp_str_do_log(brl_fsp(br_lck)),
1917 (unsigned long long)plock->start,
1918 (unsigned long long)plock->size,
1924 static bool smb_full_audit_strict_lock_check(struct vfs_handle_struct *handle,
1925 struct files_struct *fsp,
1926 struct lock_struct *plock)
1930 result = SMB_VFS_NEXT_STRICT_LOCK_CHECK(handle, fsp, plock);
1932 do_log(SMB_VFS_OP_STRICT_LOCK_CHECK, result, handle,
1933 "%s:%llu-%llu:%d", fsp_str_do_log(fsp),
1934 (unsigned long long)plock->start,
1935 (unsigned long long)plock->size,
1941 static NTSTATUS smb_full_audit_translate_name(struct vfs_handle_struct *handle,
1943 enum vfs_translate_direction direction,
1944 TALLOC_CTX *mem_ctx,
1949 result = SMB_VFS_NEXT_TRANSLATE_NAME(handle, name, direction, mem_ctx,
1952 do_log(SMB_VFS_OP_TRANSLATE_NAME, NT_STATUS_IS_OK(result), handle, "");
1957 static NTSTATUS smb_full_audit_fsctl(struct vfs_handle_struct *handle,
1958 struct files_struct *fsp,
1962 const uint8_t *_in_data,
1964 uint8_t **_out_data,
1965 uint32_t max_out_len,
1970 result = SMB_VFS_NEXT_FSCTL(handle,
1981 do_log(SMB_VFS_OP_FSCTL, NT_STATUS_IS_OK(result), handle, "");
1986 static struct tevent_req *smb_full_audit_offload_read_send(
1987 TALLOC_CTX *mem_ctx,
1988 struct tevent_context *ev,
1989 struct vfs_handle_struct *handle,
1990 struct files_struct *fsp,
1996 struct tevent_req *req = NULL;
1998 req = SMB_VFS_NEXT_OFFLOAD_READ_SEND(mem_ctx, ev, handle, fsp,
1999 fsctl, ttl, offset, to_copy);
2001 do_log(SMB_VFS_OP_OFFLOAD_READ_SEND, req, handle, "");
2006 static NTSTATUS smb_full_audit_offload_read_recv(
2007 struct tevent_req *req,
2008 struct vfs_handle_struct *handle,
2009 TALLOC_CTX *mem_ctx,
2010 DATA_BLOB *_token_blob)
2014 status = SMB_VFS_NEXT_OFFLOAD_READ_RECV(req, handle, mem_ctx,
2017 do_log(SMB_VFS_OP_OFFLOAD_READ_RECV, NT_STATUS_IS_OK(status), handle, "");
2022 static struct tevent_req *smb_full_audit_offload_write_send(struct vfs_handle_struct *handle,
2023 TALLOC_CTX *mem_ctx,
2024 struct tevent_context *ev,
2027 off_t transfer_offset,
2028 struct files_struct *dest_fsp,
2032 struct tevent_req *req;
2034 req = SMB_VFS_NEXT_OFFLOAD_WRITE_SEND(handle, mem_ctx, ev,
2035 fsctl, token, transfer_offset,
2036 dest_fsp, dest_off, num);
2038 do_log(SMB_VFS_OP_OFFLOAD_WRITE_SEND, req, handle, "");
2043 static NTSTATUS smb_full_audit_offload_write_recv(struct vfs_handle_struct *handle,
2044 struct tevent_req *req,
2049 result = SMB_VFS_NEXT_OFFLOAD_WRITE_RECV(handle, req, copied);
2051 do_log(SMB_VFS_OP_OFFLOAD_WRITE_RECV, NT_STATUS_IS_OK(result), handle, "");
2056 static NTSTATUS smb_full_audit_get_compression(vfs_handle_struct *handle,
2057 TALLOC_CTX *mem_ctx,
2058 struct files_struct *fsp,
2059 struct smb_filename *smb_fname,
2060 uint16_t *_compression_fmt)
2064 result = SMB_VFS_NEXT_GET_COMPRESSION(handle, mem_ctx, fsp, smb_fname,
2067 do_log(SMB_VFS_OP_GET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
2069 (fsp ? fsp_str_do_log(fsp) :
2070 smb_fname_str_do_log(handle->conn->cwd_fname, smb_fname)));
2075 static NTSTATUS smb_full_audit_set_compression(vfs_handle_struct *handle,
2076 TALLOC_CTX *mem_ctx,
2077 struct files_struct *fsp,
2078 uint16_t compression_fmt)
2082 result = SMB_VFS_NEXT_SET_COMPRESSION(handle, mem_ctx, fsp,
2085 do_log(SMB_VFS_OP_SET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
2086 "%s", fsp_str_do_log(fsp));
2091 static NTSTATUS smb_full_audit_readdir_attr(struct vfs_handle_struct *handle,
2092 const struct smb_filename *fname,
2093 TALLOC_CTX *mem_ctx,
2094 struct readdir_attr_data **pattr_data)
2098 status = SMB_VFS_NEXT_READDIR_ATTR(handle, fname, mem_ctx, pattr_data);
2100 do_log(SMB_VFS_OP_READDIR_ATTR, NT_STATUS_IS_OK(status), handle, "%s",
2101 smb_fname_str_do_log(handle->conn->cwd_fname, fname));
2106 static NTSTATUS smb_full_audit_get_dos_attributes(
2107 struct vfs_handle_struct *handle,
2108 struct smb_filename *smb_fname,
2113 status = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES(handle,
2117 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES,
2118 NT_STATUS_IS_OK(status),
2121 smb_fname_str_do_log(handle->conn->cwd_fname, smb_fname));
2126 struct smb_full_audit_get_dos_attributes_state {
2127 struct vfs_aio_state aio_state;
2128 vfs_handle_struct *handle;
2129 files_struct *dir_fsp;
2130 const struct smb_filename *smb_fname;
2134 static void smb_full_audit_get_dos_attributes_done(struct tevent_req *subreq);
2136 static struct tevent_req *smb_full_audit_get_dos_attributes_send(
2137 TALLOC_CTX *mem_ctx,
2138 struct tevent_context *ev,
2139 struct vfs_handle_struct *handle,
2140 files_struct *dir_fsp,
2141 struct smb_filename *smb_fname)
2143 struct tevent_req *req = NULL;
2144 struct smb_full_audit_get_dos_attributes_state *state = NULL;
2145 struct tevent_req *subreq = NULL;
2147 req = tevent_req_create(mem_ctx, &state,
2148 struct smb_full_audit_get_dos_attributes_state);
2150 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2154 fsp_str_do_log(dir_fsp),
2155 smb_fname->base_name);
2158 *state = (struct smb_full_audit_get_dos_attributes_state) {
2161 .smb_fname = smb_fname,
2164 subreq = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES_SEND(mem_ctx,
2169 if (tevent_req_nomem(subreq, req)) {
2170 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2174 fsp_str_do_log(dir_fsp),
2175 smb_fname->base_name);
2176 return tevent_req_post(req, ev);
2178 tevent_req_set_callback(subreq,
2179 smb_full_audit_get_dos_attributes_done,
2182 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2186 fsp_str_do_log(dir_fsp),
2187 smb_fname->base_name);
2192 static void smb_full_audit_get_dos_attributes_done(struct tevent_req *subreq)
2194 struct tevent_req *req =
2195 tevent_req_callback_data(subreq,
2197 struct smb_full_audit_get_dos_attributes_state *state =
2198 tevent_req_data(req,
2199 struct smb_full_audit_get_dos_attributes_state);
2202 status = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES_RECV(subreq,
2205 TALLOC_FREE(subreq);
2206 if (tevent_req_nterror(req, status)) {
2210 tevent_req_done(req);
2214 static NTSTATUS smb_full_audit_get_dos_attributes_recv(struct tevent_req *req,
2215 struct vfs_aio_state *aio_state,
2218 struct smb_full_audit_get_dos_attributes_state *state =
2219 tevent_req_data(req,
2220 struct smb_full_audit_get_dos_attributes_state);
2223 if (tevent_req_is_nterror(req, &status)) {
2224 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV,
2228 fsp_str_do_log(state->dir_fsp),
2229 state->smb_fname->base_name);
2230 tevent_req_received(req);
2234 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV,
2238 fsp_str_do_log(state->dir_fsp),
2239 state->smb_fname->base_name);
2241 *aio_state = state->aio_state;
2242 *dosmode = state->dosmode;
2243 tevent_req_received(req);
2244 return NT_STATUS_OK;
2247 static NTSTATUS smb_full_audit_fget_dos_attributes(
2248 struct vfs_handle_struct *handle,
2249 struct files_struct *fsp,
2254 status = SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle,
2258 do_log(SMB_VFS_OP_FGET_DOS_ATTRIBUTES,
2259 NT_STATUS_IS_OK(status),
2262 fsp_str_do_log(fsp));
2267 static NTSTATUS smb_full_audit_set_dos_attributes(
2268 struct vfs_handle_struct *handle,
2269 const struct smb_filename *smb_fname,
2274 status = SMB_VFS_NEXT_SET_DOS_ATTRIBUTES(handle,
2278 do_log(SMB_VFS_OP_SET_DOS_ATTRIBUTES,
2279 NT_STATUS_IS_OK(status),
2282 smb_fname_str_do_log(handle->conn->cwd_fname, smb_fname));
2287 static NTSTATUS smb_full_audit_fset_dos_attributes(
2288 struct vfs_handle_struct *handle,
2289 struct files_struct *fsp,
2294 status = SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle,
2298 do_log(SMB_VFS_OP_FSET_DOS_ATTRIBUTES,
2299 NT_STATUS_IS_OK(status),
2302 fsp_str_do_log(fsp));
2307 static NTSTATUS smb_full_audit_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
2308 uint32_t security_info,
2309 TALLOC_CTX *mem_ctx,
2310 struct security_descriptor **ppdesc)
2314 result = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
2317 do_log(SMB_VFS_OP_FGET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2318 "%s", fsp_str_do_log(fsp));
2323 static NTSTATUS smb_full_audit_get_nt_acl(vfs_handle_struct *handle,
2324 const struct smb_filename *smb_fname,
2325 uint32_t security_info,
2326 TALLOC_CTX *mem_ctx,
2327 struct security_descriptor **ppdesc)
2331 result = SMB_VFS_NEXT_GET_NT_ACL(handle, smb_fname, security_info,
2334 do_log(SMB_VFS_OP_GET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2335 "%s", smb_fname_str_do_log(handle->conn->cwd_fname, smb_fname));
2340 static NTSTATUS smb_full_audit_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
2341 uint32_t security_info_sent,
2342 const struct security_descriptor *psd)
2344 struct vfs_full_audit_private_data *pd;
2348 SMB_VFS_HANDLE_GET_DATA(handle, pd,
2349 struct vfs_full_audit_private_data,
2350 return NT_STATUS_INTERNAL_ERROR);
2352 if (pd->log_secdesc) {
2353 sd = sddl_encode(talloc_tos(), psd, get_global_sam_sid());
2356 result = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
2358 do_log(SMB_VFS_OP_FSET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2359 "%s [%s]", fsp_str_do_log(fsp), sd ? sd : "");
2366 static NTSTATUS smb_full_audit_audit_file(struct vfs_handle_struct *handle,
2367 struct smb_filename *file,
2368 struct security_acl *sacl,
2369 uint32_t access_requested,
2370 uint32_t access_denied)
2374 result = SMB_VFS_NEXT_AUDIT_FILE(handle,
2380 do_log(SMB_VFS_OP_AUDIT_FILE, NT_STATUS_IS_OK(result), handle,
2382 smb_fname_str_do_log(handle->conn->cwd_fname, file));
2387 static SMB_ACL_T smb_full_audit_sys_acl_get_file(vfs_handle_struct *handle,
2388 const struct smb_filename *smb_fname,
2389 SMB_ACL_TYPE_T type,
2390 TALLOC_CTX *mem_ctx)
2394 result = SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, smb_fname,
2397 do_log(SMB_VFS_OP_SYS_ACL_GET_FILE, (result != NULL), handle,
2398 "%s", smb_fname->base_name);
2403 static SMB_ACL_T smb_full_audit_sys_acl_get_fd(vfs_handle_struct *handle,
2404 files_struct *fsp, TALLOC_CTX *mem_ctx)
2408 result = SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp, mem_ctx);
2410 do_log(SMB_VFS_OP_SYS_ACL_GET_FD, (result != NULL), handle,
2411 "%s", fsp_str_do_log(fsp));
2416 static int smb_full_audit_sys_acl_blob_get_file(vfs_handle_struct *handle,
2417 const struct smb_filename *smb_fname,
2418 TALLOC_CTX *mem_ctx,
2419 char **blob_description,
2424 result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FILE(handle, smb_fname,
2425 mem_ctx, blob_description, blob);
2427 do_log(SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE, (result >= 0), handle,
2428 "%s", smb_fname->base_name);
2433 static int smb_full_audit_sys_acl_blob_get_fd(vfs_handle_struct *handle,
2435 TALLOC_CTX *mem_ctx,
2436 char **blob_description,
2441 result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle, fsp, mem_ctx, blob_description, blob);
2443 do_log(SMB_VFS_OP_SYS_ACL_BLOB_GET_FD, (result >= 0), handle,
2444 "%s", fsp_str_do_log(fsp));
2449 static int smb_full_audit_sys_acl_set_file(vfs_handle_struct *handle,
2450 const struct smb_filename *smb_fname,
2451 SMB_ACL_TYPE_T acltype,
2456 result = SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, smb_fname, acltype,
2459 do_log(SMB_VFS_OP_SYS_ACL_SET_FILE, (result >= 0), handle,
2460 "%s", smb_fname->base_name);
2465 static int smb_full_audit_sys_acl_set_fd(vfs_handle_struct *handle, files_struct *fsp,
2470 result = SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, theacl);
2472 do_log(SMB_VFS_OP_SYS_ACL_SET_FD, (result >= 0), handle,
2473 "%s", fsp_str_do_log(fsp));
2478 static int smb_full_audit_sys_acl_delete_def_file(vfs_handle_struct *handle,
2479 const struct smb_filename *smb_fname)
2483 result = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, smb_fname);
2485 do_log(SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE, (result >= 0), handle,
2486 "%s", smb_fname->base_name);
2491 static ssize_t smb_full_audit_getxattr(struct vfs_handle_struct *handle,
2492 const struct smb_filename *smb_fname,
2493 const char *name, void *value, size_t size)
2497 result = SMB_VFS_NEXT_GETXATTR(handle, smb_fname, name, value, size);
2499 do_log(SMB_VFS_OP_GETXATTR, (result >= 0), handle,
2500 "%s|%s", smb_fname->base_name, name);
2505 struct smb_full_audit_getxattrat_state {
2506 struct vfs_aio_state aio_state;
2507 vfs_handle_struct *handle;
2508 files_struct *dir_fsp;
2509 const struct smb_filename *smb_fname;
2510 const char *xattr_name;
2512 uint8_t *xattr_value;
2515 static void smb_full_audit_getxattrat_done(struct tevent_req *subreq);
2517 static struct tevent_req *smb_full_audit_getxattrat_send(
2518 TALLOC_CTX *mem_ctx,
2519 struct tevent_context *ev,
2520 struct vfs_handle_struct *handle,
2521 files_struct *dir_fsp,
2522 const struct smb_filename *smb_fname,
2523 const char *xattr_name,
2526 struct tevent_req *req = NULL;
2527 struct tevent_req *subreq = NULL;
2528 struct smb_full_audit_getxattrat_state *state = NULL;
2530 req = tevent_req_create(mem_ctx, &state,
2531 struct smb_full_audit_getxattrat_state);
2533 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2537 fsp_str_do_log(dir_fsp),
2538 smb_fname->base_name,
2542 *state = (struct smb_full_audit_getxattrat_state) {
2545 .smb_fname = smb_fname,
2546 .xattr_name = xattr_name,
2549 subreq = SMB_VFS_NEXT_GETXATTRAT_SEND(state,
2556 if (tevent_req_nomem(subreq, req)) {
2557 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2561 fsp_str_do_log(dir_fsp),
2562 smb_fname->base_name,
2564 return tevent_req_post(req, ev);
2566 tevent_req_set_callback(subreq, smb_full_audit_getxattrat_done, req);
2568 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2572 fsp_str_do_log(dir_fsp),
2573 smb_fname->base_name,
2579 static void smb_full_audit_getxattrat_done(struct tevent_req *subreq)
2581 struct tevent_req *req = tevent_req_callback_data(
2582 subreq, struct tevent_req);
2583 struct smb_full_audit_getxattrat_state *state = tevent_req_data(
2584 req, struct smb_full_audit_getxattrat_state);
2586 state->xattr_size = SMB_VFS_NEXT_GETXATTRAT_RECV(subreq,
2589 &state->xattr_value);
2590 TALLOC_FREE(subreq);
2591 if (state->xattr_size == -1) {
2592 tevent_req_error(req, state->aio_state.error);
2596 tevent_req_done(req);
2599 static ssize_t smb_full_audit_getxattrat_recv(struct tevent_req *req,
2600 struct vfs_aio_state *aio_state,
2601 TALLOC_CTX *mem_ctx,
2602 uint8_t **xattr_value)
2604 struct smb_full_audit_getxattrat_state *state = tevent_req_data(
2605 req, struct smb_full_audit_getxattrat_state);
2608 if (tevent_req_is_unix_error(req, &aio_state->error)) {
2609 do_log(SMB_VFS_OP_GETXATTRAT_RECV,
2613 fsp_str_do_log(state->dir_fsp),
2614 state->smb_fname->base_name,
2616 tevent_req_received(req);
2620 do_log(SMB_VFS_OP_GETXATTRAT_RECV,
2624 fsp_str_do_log(state->dir_fsp),
2625 state->smb_fname->base_name,
2628 *aio_state = state->aio_state;
2629 xattr_size = state->xattr_size;
2630 if (xattr_value != NULL) {
2631 *xattr_value = talloc_move(mem_ctx, &state->xattr_value);
2634 tevent_req_received(req);
2638 static ssize_t smb_full_audit_fgetxattr(struct vfs_handle_struct *handle,
2639 struct files_struct *fsp,
2640 const char *name, void *value, size_t size)
2644 result = SMB_VFS_NEXT_FGETXATTR(handle, fsp, name, value, size);
2646 do_log(SMB_VFS_OP_FGETXATTR, (result >= 0), handle,
2647 "%s|%s", fsp_str_do_log(fsp), name);
2652 static ssize_t smb_full_audit_listxattr(struct vfs_handle_struct *handle,
2653 const struct smb_filename *smb_fname,
2659 result = SMB_VFS_NEXT_LISTXATTR(handle, smb_fname, list, size);
2661 do_log(SMB_VFS_OP_LISTXATTR, (result >= 0), handle, "%s",
2662 smb_fname->base_name);
2667 static ssize_t smb_full_audit_flistxattr(struct vfs_handle_struct *handle,
2668 struct files_struct *fsp, char *list,
2673 result = SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
2675 do_log(SMB_VFS_OP_FLISTXATTR, (result >= 0), handle,
2676 "%s", fsp_str_do_log(fsp));
2681 static int smb_full_audit_removexattr(struct vfs_handle_struct *handle,
2682 const struct smb_filename *smb_fname,
2687 result = SMB_VFS_NEXT_REMOVEXATTR(handle, smb_fname, name);
2689 do_log(SMB_VFS_OP_REMOVEXATTR, (result >= 0), handle,
2690 "%s|%s", smb_fname->base_name, name);
2695 static int smb_full_audit_fremovexattr(struct vfs_handle_struct *handle,
2696 struct files_struct *fsp,
2701 result = SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, name);
2703 do_log(SMB_VFS_OP_FREMOVEXATTR, (result >= 0), handle,
2704 "%s|%s", fsp_str_do_log(fsp), name);
2709 static int smb_full_audit_setxattr(struct vfs_handle_struct *handle,
2710 const struct smb_filename *smb_fname,
2711 const char *name, const void *value, size_t size,
2716 result = SMB_VFS_NEXT_SETXATTR(handle, smb_fname, name, value, size,
2719 do_log(SMB_VFS_OP_SETXATTR, (result >= 0), handle,
2720 "%s|%s", smb_fname->base_name, name);
2725 static int smb_full_audit_fsetxattr(struct vfs_handle_struct *handle,
2726 struct files_struct *fsp, const char *name,
2727 const void *value, size_t size, int flags)
2731 result = SMB_VFS_NEXT_FSETXATTR(handle, fsp, name, value, size, flags);
2733 do_log(SMB_VFS_OP_FSETXATTR, (result >= 0), handle,
2734 "%s|%s", fsp_str_do_log(fsp), name);
2739 static bool smb_full_audit_aio_force(struct vfs_handle_struct *handle,
2740 struct files_struct *fsp)
2744 result = SMB_VFS_NEXT_AIO_FORCE(handle, fsp);
2745 do_log(SMB_VFS_OP_AIO_FORCE, result, handle,
2746 "%s", fsp_str_do_log(fsp));
2751 static NTSTATUS smb_full_audit_durable_cookie(struct vfs_handle_struct *handle,
2752 struct files_struct *fsp,
2753 TALLOC_CTX *mem_ctx,
2758 result = SMB_VFS_NEXT_DURABLE_COOKIE(handle,
2763 do_log(SMB_VFS_OP_DURABLE_COOKIE, NT_STATUS_IS_OK(result), handle,
2764 "%s", fsp_str_do_log(fsp));
2769 static NTSTATUS smb_full_audit_durable_disconnect(
2770 struct vfs_handle_struct *handle,
2771 struct files_struct *fsp,
2772 const DATA_BLOB old_cookie,
2773 TALLOC_CTX *mem_ctx,
2774 DATA_BLOB *new_cookie)
2778 result = SMB_VFS_NEXT_DURABLE_DISCONNECT(handle,
2784 do_log(SMB_VFS_OP_DURABLE_DISCONNECT, NT_STATUS_IS_OK(result), handle,
2785 "%s", fsp_str_do_log(fsp));
2790 static NTSTATUS smb_full_audit_durable_reconnect(
2791 struct vfs_handle_struct *handle,
2792 struct smb_request *smb1req,
2793 struct smbXsrv_open *op,
2794 const DATA_BLOB old_cookie,
2795 TALLOC_CTX *mem_ctx,
2796 struct files_struct **fsp,
2797 DATA_BLOB *new_cookie)
2801 result = SMB_VFS_NEXT_DURABLE_RECONNECT(handle,
2809 do_log(SMB_VFS_OP_DURABLE_RECONNECT,
2810 NT_STATUS_IS_OK(result),
2817 static struct vfs_fn_pointers vfs_full_audit_fns = {
2819 /* Disk operations */
2821 .connect_fn = smb_full_audit_connect,
2822 .disconnect_fn = smb_full_audit_disconnect,
2823 .disk_free_fn = smb_full_audit_disk_free,
2824 .get_quota_fn = smb_full_audit_get_quota,
2825 .set_quota_fn = smb_full_audit_set_quota,
2826 .get_shadow_copy_data_fn = smb_full_audit_get_shadow_copy_data,
2827 .statvfs_fn = smb_full_audit_statvfs,
2828 .fs_capabilities_fn = smb_full_audit_fs_capabilities,
2829 .get_dfs_referrals_fn = smb_full_audit_get_dfs_referrals,
2830 .opendir_fn = smb_full_audit_opendir,
2831 .fdopendir_fn = smb_full_audit_fdopendir,
2832 .readdir_fn = smb_full_audit_readdir,
2833 .seekdir_fn = smb_full_audit_seekdir,
2834 .telldir_fn = smb_full_audit_telldir,
2835 .rewind_dir_fn = smb_full_audit_rewinddir,
2836 .mkdir_fn = smb_full_audit_mkdir,
2837 .rmdir_fn = smb_full_audit_rmdir,
2838 .closedir_fn = smb_full_audit_closedir,
2839 .open_fn = smb_full_audit_open,
2840 .create_file_fn = smb_full_audit_create_file,
2841 .close_fn = smb_full_audit_close,
2842 .pread_fn = smb_full_audit_pread,
2843 .pread_send_fn = smb_full_audit_pread_send,
2844 .pread_recv_fn = smb_full_audit_pread_recv,
2845 .pwrite_fn = smb_full_audit_pwrite,
2846 .pwrite_send_fn = smb_full_audit_pwrite_send,
2847 .pwrite_recv_fn = smb_full_audit_pwrite_recv,
2848 .lseek_fn = smb_full_audit_lseek,
2849 .sendfile_fn = smb_full_audit_sendfile,
2850 .recvfile_fn = smb_full_audit_recvfile,
2851 .rename_fn = smb_full_audit_rename,
2852 .fsync_send_fn = smb_full_audit_fsync_send,
2853 .fsync_recv_fn = smb_full_audit_fsync_recv,
2854 .stat_fn = smb_full_audit_stat,
2855 .fstat_fn = smb_full_audit_fstat,
2856 .lstat_fn = smb_full_audit_lstat,
2857 .get_alloc_size_fn = smb_full_audit_get_alloc_size,
2858 .unlink_fn = smb_full_audit_unlink,
2859 .chmod_fn = smb_full_audit_chmod,
2860 .fchmod_fn = smb_full_audit_fchmod,
2861 .chown_fn = smb_full_audit_chown,
2862 .fchown_fn = smb_full_audit_fchown,
2863 .lchown_fn = smb_full_audit_lchown,
2864 .chdir_fn = smb_full_audit_chdir,
2865 .getwd_fn = smb_full_audit_getwd,
2866 .ntimes_fn = smb_full_audit_ntimes,
2867 .ftruncate_fn = smb_full_audit_ftruncate,
2868 .fallocate_fn = smb_full_audit_fallocate,
2869 .lock_fn = smb_full_audit_lock,
2870 .kernel_flock_fn = smb_full_audit_kernel_flock,
2871 .linux_setlease_fn = smb_full_audit_linux_setlease,
2872 .getlock_fn = smb_full_audit_getlock,
2873 .symlink_fn = smb_full_audit_symlink,
2874 .readlink_fn = smb_full_audit_readlink,
2875 .link_fn = smb_full_audit_link,
2876 .mknod_fn = smb_full_audit_mknod,
2877 .realpath_fn = smb_full_audit_realpath,
2878 .chflags_fn = smb_full_audit_chflags,
2879 .file_id_create_fn = smb_full_audit_file_id_create,
2880 .fs_file_id_fn = smb_full_audit_fs_file_id,
2881 .offload_read_send_fn = smb_full_audit_offload_read_send,
2882 .offload_read_recv_fn = smb_full_audit_offload_read_recv,
2883 .offload_write_send_fn = smb_full_audit_offload_write_send,
2884 .offload_write_recv_fn = smb_full_audit_offload_write_recv,
2885 .get_compression_fn = smb_full_audit_get_compression,
2886 .set_compression_fn = smb_full_audit_set_compression,
2887 .snap_check_path_fn = smb_full_audit_snap_check_path,
2888 .snap_create_fn = smb_full_audit_snap_create,
2889 .snap_delete_fn = smb_full_audit_snap_delete,
2890 .streaminfo_fn = smb_full_audit_streaminfo,
2891 .get_real_filename_fn = smb_full_audit_get_real_filename,
2892 .connectpath_fn = smb_full_audit_connectpath,
2893 .brl_lock_windows_fn = smb_full_audit_brl_lock_windows,
2894 .brl_unlock_windows_fn = smb_full_audit_brl_unlock_windows,
2895 .strict_lock_check_fn = smb_full_audit_strict_lock_check,
2896 .translate_name_fn = smb_full_audit_translate_name,
2897 .fsctl_fn = smb_full_audit_fsctl,
2898 .get_dos_attributes_fn = smb_full_audit_get_dos_attributes,
2899 .get_dos_attributes_send_fn = smb_full_audit_get_dos_attributes_send,
2900 .get_dos_attributes_recv_fn = smb_full_audit_get_dos_attributes_recv,
2901 .fget_dos_attributes_fn = smb_full_audit_fget_dos_attributes,
2902 .set_dos_attributes_fn = smb_full_audit_set_dos_attributes,
2903 .fset_dos_attributes_fn = smb_full_audit_fset_dos_attributes,
2904 .fget_nt_acl_fn = smb_full_audit_fget_nt_acl,
2905 .get_nt_acl_fn = smb_full_audit_get_nt_acl,
2906 .fset_nt_acl_fn = smb_full_audit_fset_nt_acl,
2907 .audit_file_fn = smb_full_audit_audit_file,
2908 .sys_acl_get_file_fn = smb_full_audit_sys_acl_get_file,
2909 .sys_acl_get_fd_fn = smb_full_audit_sys_acl_get_fd,
2910 .sys_acl_blob_get_file_fn = smb_full_audit_sys_acl_blob_get_file,
2911 .sys_acl_blob_get_fd_fn = smb_full_audit_sys_acl_blob_get_fd,
2912 .sys_acl_set_file_fn = smb_full_audit_sys_acl_set_file,
2913 .sys_acl_set_fd_fn = smb_full_audit_sys_acl_set_fd,
2914 .sys_acl_delete_def_file_fn = smb_full_audit_sys_acl_delete_def_file,
2915 .getxattr_fn = smb_full_audit_getxattr,
2916 .getxattrat_send_fn = smb_full_audit_getxattrat_send,
2917 .getxattrat_recv_fn = smb_full_audit_getxattrat_recv,
2918 .fgetxattr_fn = smb_full_audit_fgetxattr,
2919 .listxattr_fn = smb_full_audit_listxattr,
2920 .flistxattr_fn = smb_full_audit_flistxattr,
2921 .removexattr_fn = smb_full_audit_removexattr,
2922 .fremovexattr_fn = smb_full_audit_fremovexattr,
2923 .setxattr_fn = smb_full_audit_setxattr,
2924 .fsetxattr_fn = smb_full_audit_fsetxattr,
2925 .aio_force_fn = smb_full_audit_aio_force,
2926 .durable_cookie_fn = smb_full_audit_durable_cookie,
2927 .durable_disconnect_fn = smb_full_audit_durable_disconnect,
2928 .durable_reconnect_fn = smb_full_audit_durable_reconnect,
2929 .readdir_attr_fn = smb_full_audit_readdir_attr
2934 NTSTATUS vfs_full_audit_init(TALLOC_CTX *ctx)
2938 smb_vfs_assert_all_fns(&vfs_full_audit_fns, "full_audit");
2940 ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "full_audit",
2941 &vfs_full_audit_fns);
2943 if (!NT_STATUS_IS_OK(ret))
2946 vfs_full_audit_debug_level = debug_add_class("full_audit");
2947 if (vfs_full_audit_debug_level == -1) {
2948 vfs_full_audit_debug_level = DBGC_VFS;
2949 DEBUG(0, ("vfs_full_audit: Couldn't register custom debugging "
2952 DEBUG(10, ("vfs_full_audit: Debug class number of "
2953 "'full_audit': %d\n", vfs_full_audit_debug_level));