2 * Auditing VFS module for samba. Log selected file operations to syslog
5 * Copyright (C) Tim Potter, 1999-2000
6 * Copyright (C) Alexander Bokovoy, 2002
7 * Copyright (C) John H Terpstra, 2003
8 * Copyright (C) Stefan (metze) Metzmacher, 2003
9 * Copyright (C) Volker Lendecke, 2004
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, see <http://www.gnu.org/licenses/>.
26 * This module implements parseable logging for all Samba VFS operations.
28 * You use it as follows:
32 * vfs objects = full_audit
33 * full_audit:prefix = %u|%I
34 * full_audit:success = open opendir create_file
35 * full_audit:failure = all
37 * vfs op can be "all" which means log all operations.
38 * vfs op can be "none" which means no logging.
40 * This leads to syslog entries of the form:
41 * smbd_audit: nobody|192.168.234.1|opendir|ok|/tmp
42 * smbd_audit: nobody|192.168.234.1|create_file|fail (No such file or directory)|0x1|file|open|/ts/doesNotExist
43 * smbd_audit: nobody|192.168.234.1|open|ok|w|/tmp/file.txt
44 * smbd_audit: nobody|192.168.234.1|create_file|ok|0x3|file|open|/tmp/file.txt
46 * where "nobody" is the connected username and "192.168.234.1" is the
47 * client's IP address.
51 * prefix: A macro expansion template prepended to the syslog entry.
53 * success: A list of VFS operations for which a successful completion should
54 * be logged. Defaults to no logging at all. The special operation "all" logs
55 * - you guessed it - everything.
57 * failure: A list of VFS operations for which failure to complete should be
58 * logged. Defaults to logging everything.
63 #include "system/filesys.h"
64 #include "system/syslog.h"
65 #include "smbd/smbd.h"
66 #include "../librpc/gen_ndr/ndr_netlogon.h"
69 #include "lib/param/loadparm.h"
70 #include "lib/util/bitmap.h"
71 #include "lib/util/tevent_unix.h"
72 #include "libcli/security/sddl.h"
73 #include "passdb/machine_sid.h"
74 #include "lib/util/tevent_ntstatus.h"
75 #include "lib/util/string_wrappers.h"
77 static int vfs_full_audit_debug_level = DBGC_VFS;
79 struct vfs_full_audit_private_data {
80 struct bitmap *success_ops;
81 struct bitmap *failure_ops;
89 #define DBGC_CLASS vfs_full_audit_debug_level
91 typedef enum _vfs_op_type {
96 SMB_VFS_OP_CONNECT = 0,
97 SMB_VFS_OP_DISCONNECT,
100 SMB_VFS_OP_SET_QUOTA,
101 SMB_VFS_OP_GET_SHADOW_COPY_DATA,
103 SMB_VFS_OP_FS_CAPABILITIES,
104 SMB_VFS_OP_GET_DFS_REFERRALS,
105 SMB_VFS_OP_CREATE_DFS_PATHAT,
106 SMB_VFS_OP_READ_DFS_PATHAT,
108 /* Directory operations */
110 SMB_VFS_OP_FDOPENDIR,
114 SMB_VFS_OP_REWINDDIR,
118 /* File operations */
122 SMB_VFS_OP_CREATE_FILE,
126 SMB_VFS_OP_PREAD_SEND,
127 SMB_VFS_OP_PREAD_RECV,
130 SMB_VFS_OP_PWRITE_SEND,
131 SMB_VFS_OP_PWRITE_RECV,
137 SMB_VFS_OP_FSYNC_SEND,
138 SMB_VFS_OP_FSYNC_RECV,
142 SMB_VFS_OP_GET_ALLOC_SIZE,
151 SMB_VFS_OP_FTRUNCATE,
152 SMB_VFS_OP_FALLOCATE,
154 SMB_VFS_OP_KERNEL_FLOCK,
156 SMB_VFS_OP_LINUX_SETLEASE,
158 SMB_VFS_OP_SYMLINKAT,
159 SMB_VFS_OP_READLINKAT,
164 SMB_VFS_OP_FILE_ID_CREATE,
165 SMB_VFS_OP_FS_FILE_ID,
166 SMB_VFS_OP_STREAMINFO,
167 SMB_VFS_OP_GET_REAL_FILENAME,
168 SMB_VFS_OP_CONNECTPATH,
169 SMB_VFS_OP_BRL_LOCK_WINDOWS,
170 SMB_VFS_OP_BRL_UNLOCK_WINDOWS,
171 SMB_VFS_OP_STRICT_LOCK_CHECK,
172 SMB_VFS_OP_TRANSLATE_NAME,
174 SMB_VFS_OP_OFFLOAD_READ_SEND,
175 SMB_VFS_OP_OFFLOAD_READ_RECV,
176 SMB_VFS_OP_OFFLOAD_WRITE_SEND,
177 SMB_VFS_OP_OFFLOAD_WRITE_RECV,
178 SMB_VFS_OP_FGET_COMPRESSION,
179 SMB_VFS_OP_SET_COMPRESSION,
180 SMB_VFS_OP_SNAP_CHECK_PATH,
181 SMB_VFS_OP_SNAP_CREATE,
182 SMB_VFS_OP_SNAP_DELETE,
184 /* DOS attribute operations. */
185 SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
186 SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV,
187 SMB_VFS_OP_FGET_DOS_ATTRIBUTES,
188 SMB_VFS_OP_SET_DOS_ATTRIBUTES,
189 SMB_VFS_OP_FSET_DOS_ATTRIBUTES,
191 /* NT ACL operations. */
193 SMB_VFS_OP_FGET_NT_ACL,
194 SMB_VFS_OP_GET_NT_ACL_AT,
195 SMB_VFS_OP_FSET_NT_ACL,
196 SMB_VFS_OP_AUDIT_FILE,
198 /* POSIX ACL operations. */
200 SMB_VFS_OP_SYS_ACL_GET_FILE,
201 SMB_VFS_OP_SYS_ACL_GET_FD,
202 SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE,
203 SMB_VFS_OP_SYS_ACL_BLOB_GET_FD,
204 SMB_VFS_OP_SYS_ACL_SET_FILE,
205 SMB_VFS_OP_SYS_ACL_SET_FD,
206 SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE,
210 SMB_VFS_OP_GETXATTRAT_SEND,
211 SMB_VFS_OP_GETXATTRAT_RECV,
212 SMB_VFS_OP_FGETXATTR,
213 SMB_VFS_OP_LISTXATTR,
214 SMB_VFS_OP_FLISTXATTR,
215 SMB_VFS_OP_REMOVEXATTR,
216 SMB_VFS_OP_FREMOVEXATTR,
218 SMB_VFS_OP_FSETXATTR,
221 SMB_VFS_OP_AIO_FORCE,
223 /* offline operations */
224 SMB_VFS_OP_IS_OFFLINE,
225 SMB_VFS_OP_SET_OFFLINE,
227 /* Durable handle operations. */
228 SMB_VFS_OP_DURABLE_COOKIE,
229 SMB_VFS_OP_DURABLE_DISCONNECT,
230 SMB_VFS_OP_DURABLE_RECONNECT,
232 SMB_VFS_OP_READDIR_ATTR,
234 /* This should always be last enum value */
239 /* The following array *must* be in the same order as defined in vfs_op_type */
245 { SMB_VFS_OP_CONNECT, "connect" },
246 { SMB_VFS_OP_DISCONNECT, "disconnect" },
247 { SMB_VFS_OP_DISK_FREE, "disk_free" },
248 { SMB_VFS_OP_GET_QUOTA, "get_quota" },
249 { SMB_VFS_OP_SET_QUOTA, "set_quota" },
250 { SMB_VFS_OP_GET_SHADOW_COPY_DATA, "get_shadow_copy_data" },
251 { SMB_VFS_OP_STATVFS, "statvfs" },
252 { SMB_VFS_OP_FS_CAPABILITIES, "fs_capabilities" },
253 { SMB_VFS_OP_GET_DFS_REFERRALS, "get_dfs_referrals" },
254 { SMB_VFS_OP_CREATE_DFS_PATHAT, "create_dfs_pathat" },
255 { SMB_VFS_OP_READ_DFS_PATHAT, "read_dfs_pathat" },
256 { SMB_VFS_OP_FDOPENDIR, "fdopendir" },
257 { SMB_VFS_OP_READDIR, "readdir" },
258 { SMB_VFS_OP_SEEKDIR, "seekdir" },
259 { SMB_VFS_OP_TELLDIR, "telldir" },
260 { SMB_VFS_OP_REWINDDIR, "rewinddir" },
261 { SMB_VFS_OP_MKDIRAT, "mkdirat" },
262 { SMB_VFS_OP_CLOSEDIR, "closedir" },
263 { SMB_VFS_OP_OPEN, "open" },
264 { SMB_VFS_OP_OPENAT, "openat" },
265 { SMB_VFS_OP_CREATE_FILE, "create_file" },
266 { SMB_VFS_OP_CLOSE, "close" },
267 { SMB_VFS_OP_READ, "read" },
268 { SMB_VFS_OP_PREAD, "pread" },
269 { SMB_VFS_OP_PREAD_SEND, "pread_send" },
270 { SMB_VFS_OP_PREAD_RECV, "pread_recv" },
271 { SMB_VFS_OP_WRITE, "write" },
272 { SMB_VFS_OP_PWRITE, "pwrite" },
273 { SMB_VFS_OP_PWRITE_SEND, "pwrite_send" },
274 { SMB_VFS_OP_PWRITE_RECV, "pwrite_recv" },
275 { SMB_VFS_OP_LSEEK, "lseek" },
276 { SMB_VFS_OP_SENDFILE, "sendfile" },
277 { SMB_VFS_OP_RECVFILE, "recvfile" },
278 { SMB_VFS_OP_RENAMEAT, "renameat" },
279 { SMB_VFS_OP_FSYNC, "fsync" },
280 { SMB_VFS_OP_FSYNC_SEND, "fsync_send" },
281 { SMB_VFS_OP_FSYNC_RECV, "fsync_recv" },
282 { SMB_VFS_OP_STAT, "stat" },
283 { SMB_VFS_OP_FSTAT, "fstat" },
284 { SMB_VFS_OP_LSTAT, "lstat" },
285 { SMB_VFS_OP_GET_ALLOC_SIZE, "get_alloc_size" },
286 { SMB_VFS_OP_UNLINKAT, "unlinkat" },
287 { SMB_VFS_OP_CHMOD, "chmod" },
288 { SMB_VFS_OP_FCHMOD, "fchmod" },
289 { SMB_VFS_OP_FCHOWN, "fchown" },
290 { SMB_VFS_OP_LCHOWN, "lchown" },
291 { SMB_VFS_OP_CHDIR, "chdir" },
292 { SMB_VFS_OP_GETWD, "getwd" },
293 { SMB_VFS_OP_NTIMES, "ntimes" },
294 { SMB_VFS_OP_FTRUNCATE, "ftruncate" },
295 { SMB_VFS_OP_FALLOCATE,"fallocate" },
296 { SMB_VFS_OP_LOCK, "lock" },
297 { SMB_VFS_OP_KERNEL_FLOCK, "kernel_flock" },
298 { SMB_VFS_OP_FCNTL, "fcntl" },
299 { SMB_VFS_OP_LINUX_SETLEASE, "linux_setlease" },
300 { SMB_VFS_OP_GETLOCK, "getlock" },
301 { SMB_VFS_OP_SYMLINKAT, "symlinkat" },
302 { SMB_VFS_OP_READLINKAT,"readlinkat" },
303 { SMB_VFS_OP_LINKAT, "linkat" },
304 { SMB_VFS_OP_MKNODAT, "mknodat" },
305 { SMB_VFS_OP_REALPATH, "realpath" },
306 { SMB_VFS_OP_CHFLAGS, "chflags" },
307 { SMB_VFS_OP_FILE_ID_CREATE, "file_id_create" },
308 { SMB_VFS_OP_FS_FILE_ID, "fs_file_id" },
309 { SMB_VFS_OP_STREAMINFO, "streaminfo" },
310 { SMB_VFS_OP_GET_REAL_FILENAME, "get_real_filename" },
311 { SMB_VFS_OP_CONNECTPATH, "connectpath" },
312 { SMB_VFS_OP_BRL_LOCK_WINDOWS, "brl_lock_windows" },
313 { SMB_VFS_OP_BRL_UNLOCK_WINDOWS, "brl_unlock_windows" },
314 { SMB_VFS_OP_STRICT_LOCK_CHECK, "strict_lock_check" },
315 { SMB_VFS_OP_TRANSLATE_NAME, "translate_name" },
316 { SMB_VFS_OP_FSCTL, "fsctl" },
317 { SMB_VFS_OP_OFFLOAD_READ_SEND, "offload_read_send" },
318 { SMB_VFS_OP_OFFLOAD_READ_RECV, "offload_read_recv" },
319 { SMB_VFS_OP_OFFLOAD_WRITE_SEND, "offload_write_send" },
320 { SMB_VFS_OP_OFFLOAD_WRITE_RECV, "offload_write_recv" },
321 { SMB_VFS_OP_FGET_COMPRESSION, "fget_compression" },
322 { SMB_VFS_OP_SET_COMPRESSION, "set_compression" },
323 { SMB_VFS_OP_SNAP_CHECK_PATH, "snap_check_path" },
324 { SMB_VFS_OP_SNAP_CREATE, "snap_create" },
325 { SMB_VFS_OP_SNAP_DELETE, "snap_delete" },
326 { SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND, "get_dos_attributes_send" },
327 { SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV, "get_dos_attributes_recv" },
328 { SMB_VFS_OP_FGET_DOS_ATTRIBUTES, "fget_dos_attributes" },
329 { SMB_VFS_OP_SET_DOS_ATTRIBUTES, "set_dos_attributes" },
330 { SMB_VFS_OP_FSET_DOS_ATTRIBUTES, "fset_dos_attributes" },
331 { SMB_VFS_OP_FGET_NT_ACL, "fget_nt_acl" },
332 { SMB_VFS_OP_GET_NT_ACL_AT, "get_nt_acl_at" },
333 { SMB_VFS_OP_FSET_NT_ACL, "fset_nt_acl" },
334 { SMB_VFS_OP_AUDIT_FILE, "audit_file" },
335 { SMB_VFS_OP_SYS_ACL_GET_FILE, "sys_acl_get_file" },
336 { SMB_VFS_OP_SYS_ACL_GET_FD, "sys_acl_get_fd" },
337 { SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE, "sys_acl_blob_get_file" },
338 { SMB_VFS_OP_SYS_ACL_BLOB_GET_FD, "sys_acl_blob_get_fd" },
339 { SMB_VFS_OP_SYS_ACL_SET_FILE, "sys_acl_set_file" },
340 { SMB_VFS_OP_SYS_ACL_SET_FD, "sys_acl_set_fd" },
341 { SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE, "sys_acl_delete_def_file" },
342 { SMB_VFS_OP_GETXATTR, "getxattr" },
343 { SMB_VFS_OP_GETXATTRAT_SEND, "getxattrat_send" },
344 { SMB_VFS_OP_GETXATTRAT_RECV, "getxattrat_recv" },
345 { SMB_VFS_OP_FGETXATTR, "fgetxattr" },
346 { SMB_VFS_OP_LISTXATTR, "listxattr" },
347 { SMB_VFS_OP_FLISTXATTR, "flistxattr" },
348 { SMB_VFS_OP_REMOVEXATTR, "removexattr" },
349 { SMB_VFS_OP_FREMOVEXATTR, "fremovexattr" },
350 { SMB_VFS_OP_SETXATTR, "setxattr" },
351 { SMB_VFS_OP_FSETXATTR, "fsetxattr" },
352 { SMB_VFS_OP_AIO_FORCE, "aio_force" },
353 { SMB_VFS_OP_IS_OFFLINE, "is_offline" },
354 { SMB_VFS_OP_SET_OFFLINE, "set_offline" },
355 { SMB_VFS_OP_DURABLE_COOKIE, "durable_cookie" },
356 { SMB_VFS_OP_DURABLE_DISCONNECT, "durable_disconnect" },
357 { SMB_VFS_OP_DURABLE_RECONNECT, "durable_reconnect" },
358 { SMB_VFS_OP_READDIR_ATTR, "readdir_attr" },
359 { SMB_VFS_OP_LAST, NULL }
362 static int audit_syslog_facility(vfs_handle_struct *handle)
364 static const struct enum_list enum_log_facilities[] = {
366 { LOG_AUTH, "AUTH" },
369 { LOG_AUTHPRIV, "AUTHPRIV" },
372 { LOG_AUDIT, "AUDIT" },
375 { LOG_CONSOLE, "CONSOLE" },
378 { LOG_CRON, "CRON" },
381 { LOG_DAEMON, "DAEMON" },
387 { LOG_INSTALL, "INSTALL" },
390 { LOG_KERN, "KERN" },
393 { LOG_LAUNCHD, "LAUNCHD" },
396 { LOG_LFMT, "LFMT" },
402 { LOG_MAIL, "MAIL" },
405 { LOG_MEGASAFE, "MEGASAFE" },
408 { LOG_NETINFO, "NETINFO" },
411 { LOG_NEWS, "NEWS" },
413 #ifdef LOG_NFACILITIES
414 { LOG_NFACILITIES, "NFACILITIES" },
422 #ifdef LOG_REMOTEAUTH
423 { LOG_REMOTEAUTH, "REMOTEAUTH" },
426 { LOG_SECURITY, "SECURITY" },
429 { LOG_SYSLOG, "SYSLOG" },
432 { LOG_USER, "USER" },
435 { LOG_UUCP, "UUCP" },
437 { LOG_LOCAL0, "LOCAL0" },
438 { LOG_LOCAL1, "LOCAL1" },
439 { LOG_LOCAL2, "LOCAL2" },
440 { LOG_LOCAL3, "LOCAL3" },
441 { LOG_LOCAL4, "LOCAL4" },
442 { LOG_LOCAL5, "LOCAL5" },
443 { LOG_LOCAL6, "LOCAL6" },
444 { LOG_LOCAL7, "LOCAL7" },
450 facility = lp_parm_enum(SNUM(handle->conn), "full_audit", "facility", enum_log_facilities, LOG_USER);
455 static int audit_syslog_priority(vfs_handle_struct *handle)
457 static const struct enum_list enum_log_priorities[] = {
458 { LOG_EMERG, "EMERG" },
459 { LOG_ALERT, "ALERT" },
460 { LOG_CRIT, "CRIT" },
462 { LOG_WARNING, "WARNING" },
463 { LOG_NOTICE, "NOTICE" },
464 { LOG_INFO, "INFO" },
465 { LOG_DEBUG, "DEBUG" },
471 priority = lp_parm_enum(SNUM(handle->conn), "full_audit", "priority",
472 enum_log_priorities, LOG_NOTICE);
473 if (priority == -1) {
474 priority = LOG_WARNING;
480 static char *audit_prefix(TALLOC_CTX *ctx, connection_struct *conn)
482 const struct loadparm_substitution *lp_sub =
483 loadparm_s3_global_substitution();
487 prefix = talloc_strdup(ctx,
488 lp_parm_const_string(SNUM(conn), "full_audit",
493 result = talloc_sub_full(ctx,
494 lp_servicename(talloc_tos(), lp_sub, SNUM(conn)),
495 conn->session_info->unix_info->unix_name,
497 conn->session_info->unix_token->gid,
498 conn->session_info->unix_info->sanitized_username,
499 conn->session_info->info->domain_name,
505 static bool log_success(struct vfs_full_audit_private_data *pd, vfs_op_type op)
507 if (pd->success_ops == NULL) {
511 return bitmap_query(pd->success_ops, op);
514 static bool log_failure(struct vfs_full_audit_private_data *pd, vfs_op_type op)
516 if (pd->failure_ops == NULL)
519 return bitmap_query(pd->failure_ops, op);
522 static struct bitmap *init_bitmap(TALLOC_CTX *mem_ctx, const char **ops)
530 bm = bitmap_talloc(mem_ctx, SMB_VFS_OP_LAST);
532 DEBUG(0, ("Could not alloc bitmap -- "
533 "defaulting to logging everything\n"));
537 for (; *ops != NULL; ops += 1) {
542 if (strequal(*ops, "all")) {
543 for (i=0; i<SMB_VFS_OP_LAST; i++) {
549 if (strequal(*ops, "none")) {
559 for (i=0; i<SMB_VFS_OP_LAST; i++) {
560 if ((vfs_op_names[i].name == NULL)
561 || (vfs_op_names[i].type != i)) {
562 smb_panic("vfs_full_audit.c: name table not "
563 "in sync with vfs_op_type enums\n");
565 if (strequal(op, vfs_op_names[i].name)) {
574 if (i == SMB_VFS_OP_LAST) {
575 DEBUG(0, ("Could not find opname %s, logging all\n",
584 static const char *audit_opname(vfs_op_type op)
586 if (op >= SMB_VFS_OP_LAST)
587 return "INVALID VFS OP";
588 return vfs_op_names[op].name;
591 static TALLOC_CTX *tmp_do_log_ctx;
593 * Get us a temporary talloc context usable just for DEBUG arguments
595 static TALLOC_CTX *do_log_ctx(void)
597 if (tmp_do_log_ctx == NULL) {
598 tmp_do_log_ctx = talloc_named_const(NULL, 0, "do_log_ctx");
600 return tmp_do_log_ctx;
603 static void do_log(vfs_op_type op, bool success, vfs_handle_struct *handle,
604 const char *format, ...) PRINTF_ATTRIBUTE(4, 5);
606 static void do_log(vfs_op_type op, bool success, vfs_handle_struct *handle,
607 const char *format, ...)
609 struct vfs_full_audit_private_data *pd;
611 char *audit_pre = NULL;
615 SMB_VFS_HANDLE_GET_DATA(handle, pd,
616 struct vfs_full_audit_private_data,
619 if (success && (!log_success(pd, op)))
622 if (!success && (!log_failure(pd, op)))
626 fstrcpy(err_msg, "ok");
628 fstr_sprintf(err_msg, "fail (%s)", strerror(errno));
630 va_start(ap, format);
631 op_msg = talloc_vasprintf(talloc_tos(), format, ap);
638 audit_pre = audit_prefix(talloc_tos(), handle->conn);
644 * Specify the facility to interoperate with other syslog
645 * callers (smbd for example).
647 priority = pd->syslog_priority | pd->syslog_facility;
649 syslog(priority, "%s|%s|%s|%s\n",
650 audit_pre ? audit_pre : "",
651 audit_opname(op), err_msg, op_msg);
653 DEBUG(1, ("%s|%s|%s|%s\n",
654 audit_pre ? audit_pre : "",
655 audit_opname(op), err_msg, op_msg));
658 TALLOC_FREE(audit_pre);
660 TALLOC_FREE(tmp_do_log_ctx);
664 * Return a string using the do_log_ctx()
666 static const char *smb_fname_str_do_log(struct connection_struct *conn,
667 const struct smb_filename *smb_fname)
672 if (smb_fname == NULL) {
676 if (smb_fname->base_name[0] != '/') {
677 char *abs_name = NULL;
678 struct smb_filename *fname_copy = cp_smb_filename(
681 if (fname_copy == NULL) {
685 if (!ISDOT(smb_fname->base_name)) {
686 abs_name = talloc_asprintf(do_log_ctx(),
688 conn->cwd_fsp->fsp_name->base_name,
689 smb_fname->base_name);
691 abs_name = talloc_strdup(do_log_ctx(),
692 conn->cwd_fsp->fsp_name->base_name);
694 if (abs_name == NULL) {
697 fname_copy->base_name = abs_name;
698 smb_fname = fname_copy;
701 status = get_full_smb_filename(do_log_ctx(), smb_fname, &fname);
702 if (!NT_STATUS_IS_OK(status)) {
709 * Return an fsp debug string using the do_log_ctx()
711 static const char *fsp_str_do_log(const struct files_struct *fsp)
713 return smb_fname_str_do_log(fsp->conn, fsp->fsp_name);
716 /* Implementation of vfs_ops. Pass everything on to the default
717 operation but log event first. */
719 static int smb_full_audit_connect(vfs_handle_struct *handle,
720 const char *svc, const char *user)
723 const char *none[] = { "none" };
724 struct vfs_full_audit_private_data *pd = NULL;
726 result = SMB_VFS_NEXT_CONNECT(handle, svc, user);
731 pd = talloc_zero(handle, struct vfs_full_audit_private_data);
733 SMB_VFS_NEXT_DISCONNECT(handle);
737 pd->syslog_facility = audit_syslog_facility(handle);
738 if (pd->syslog_facility == -1) {
739 DEBUG(1, ("%s: Unknown facility %s\n", __func__,
740 lp_parm_const_string(SNUM(handle->conn),
741 "full_audit", "facility",
743 SMB_VFS_NEXT_DISCONNECT(handle);
747 pd->syslog_priority = audit_syslog_priority(handle);
749 pd->log_secdesc = lp_parm_bool(SNUM(handle->conn),
750 "full_audit", "log_secdesc", false);
752 pd->do_syslog = lp_parm_bool(SNUM(handle->conn),
753 "full_audit", "syslog", true);
757 openlog("smbd_audit", 0, pd->syslog_facility);
761 pd->success_ops = init_bitmap(
762 pd, lp_parm_string_list(SNUM(handle->conn), "full_audit",
764 pd->failure_ops = init_bitmap(
765 pd, lp_parm_string_list(SNUM(handle->conn), "full_audit",
768 /* Store the private data. */
769 SMB_VFS_HANDLE_SET_DATA(handle, pd, NULL,
770 struct vfs_full_audit_private_data, return -1);
772 do_log(SMB_VFS_OP_CONNECT, True, handle,
778 static void smb_full_audit_disconnect(vfs_handle_struct *handle)
780 const struct loadparm_substitution *lp_sub =
781 loadparm_s3_global_substitution();
783 SMB_VFS_NEXT_DISCONNECT(handle);
785 do_log(SMB_VFS_OP_DISCONNECT, True, handle,
786 "%s", lp_servicename(talloc_tos(), lp_sub, SNUM(handle->conn)));
788 /* The bitmaps will be disconnected when the private
792 static uint64_t smb_full_audit_disk_free(vfs_handle_struct *handle,
793 const struct smb_filename *smb_fname,
800 result = SMB_VFS_NEXT_DISK_FREE(handle, smb_fname, bsize, dfree, dsize);
802 /* Don't have a reasonable notion of failure here */
804 do_log(SMB_VFS_OP_DISK_FREE,
808 smb_fname_str_do_log(handle->conn, smb_fname));
813 static int smb_full_audit_get_quota(struct vfs_handle_struct *handle,
814 const struct smb_filename *smb_fname,
815 enum SMB_QUOTA_TYPE qtype,
821 result = SMB_VFS_NEXT_GET_QUOTA(handle, smb_fname, qtype, id, qt);
823 do_log(SMB_VFS_OP_GET_QUOTA,
827 smb_fname_str_do_log(handle->conn, smb_fname));
832 static int smb_full_audit_set_quota(struct vfs_handle_struct *handle,
833 enum SMB_QUOTA_TYPE qtype, unid_t id,
838 result = SMB_VFS_NEXT_SET_QUOTA(handle, qtype, id, qt);
840 do_log(SMB_VFS_OP_SET_QUOTA, (result >= 0), handle, "");
845 static int smb_full_audit_get_shadow_copy_data(struct vfs_handle_struct *handle,
846 struct files_struct *fsp,
847 struct shadow_copy_data *shadow_copy_data,
852 result = SMB_VFS_NEXT_GET_SHADOW_COPY_DATA(handle, fsp, shadow_copy_data, labels);
854 do_log(SMB_VFS_OP_GET_SHADOW_COPY_DATA, (result >= 0), handle, "");
859 static int smb_full_audit_statvfs(struct vfs_handle_struct *handle,
860 const struct smb_filename *smb_fname,
861 struct vfs_statvfs_struct *statbuf)
865 result = SMB_VFS_NEXT_STATVFS(handle, smb_fname, statbuf);
867 do_log(SMB_VFS_OP_STATVFS, (result >= 0), handle, "");
872 static uint32_t smb_full_audit_fs_capabilities(struct vfs_handle_struct *handle, enum timestamp_set_resolution *p_ts_res)
876 result = SMB_VFS_NEXT_FS_CAPABILITIES(handle, p_ts_res);
878 do_log(SMB_VFS_OP_FS_CAPABILITIES, true, handle, "");
883 static NTSTATUS smb_full_audit_get_dfs_referrals(
884 struct vfs_handle_struct *handle,
885 struct dfs_GetDFSReferral *r)
889 status = SMB_VFS_NEXT_GET_DFS_REFERRALS(handle, r);
891 do_log(SMB_VFS_OP_GET_DFS_REFERRALS, NT_STATUS_IS_OK(status),
897 static NTSTATUS smb_full_audit_create_dfs_pathat(struct vfs_handle_struct *handle,
898 struct files_struct *dirfsp,
899 const struct smb_filename *smb_fname,
900 const struct referral *reflist,
901 size_t referral_count)
905 status = SMB_VFS_NEXT_CREATE_DFS_PATHAT(handle,
911 do_log(SMB_VFS_OP_CREATE_DFS_PATHAT,
912 NT_STATUS_IS_OK(status),
915 smb_fname_str_do_log(handle->conn, smb_fname));
920 static NTSTATUS smb_full_audit_read_dfs_pathat(struct vfs_handle_struct *handle,
922 struct files_struct *dirfsp,
923 struct smb_filename *smb_fname,
924 struct referral **ppreflist,
925 size_t *preferral_count)
929 status = SMB_VFS_NEXT_READ_DFS_PATHAT(handle,
936 do_log(SMB_VFS_OP_READ_DFS_PATHAT,
937 NT_STATUS_IS_OK(status),
940 smb_fname_str_do_log(handle->conn, smb_fname));
945 static NTSTATUS smb_full_audit_snap_check_path(struct vfs_handle_struct *handle,
947 const char *service_path,
952 status = SMB_VFS_NEXT_SNAP_CHECK_PATH(handle, mem_ctx, service_path,
954 do_log(SMB_VFS_OP_SNAP_CHECK_PATH, NT_STATUS_IS_OK(status),
960 static NTSTATUS smb_full_audit_snap_create(struct vfs_handle_struct *handle,
962 const char *base_volume,
970 status = SMB_VFS_NEXT_SNAP_CREATE(handle, mem_ctx, base_volume, tstamp,
971 rw, base_path, snap_path);
972 do_log(SMB_VFS_OP_SNAP_CREATE, NT_STATUS_IS_OK(status), handle, "");
977 static NTSTATUS smb_full_audit_snap_delete(struct vfs_handle_struct *handle,
984 status = SMB_VFS_NEXT_SNAP_DELETE(handle, mem_ctx, base_path,
986 do_log(SMB_VFS_OP_SNAP_DELETE, NT_STATUS_IS_OK(status), handle, "");
991 static DIR *smb_full_audit_fdopendir(vfs_handle_struct *handle,
992 files_struct *fsp, const char *mask, uint32_t attr)
996 result = SMB_VFS_NEXT_FDOPENDIR(handle, fsp, mask, attr);
998 do_log(SMB_VFS_OP_FDOPENDIR, (result != NULL), handle, "%s",
999 fsp_str_do_log(fsp));
1004 static struct dirent *smb_full_audit_readdir(vfs_handle_struct *handle,
1005 struct files_struct *dirfsp,
1007 SMB_STRUCT_STAT *sbuf)
1009 struct dirent *result;
1011 result = SMB_VFS_NEXT_READDIR(handle, dirfsp, dirp, sbuf);
1013 /* This operation has no reasonable error condition
1014 * (End of dir is also failure), so always succeed.
1016 do_log(SMB_VFS_OP_READDIR, True, handle, "");
1021 static void smb_full_audit_seekdir(vfs_handle_struct *handle,
1022 DIR *dirp, long offset)
1024 SMB_VFS_NEXT_SEEKDIR(handle, dirp, offset);
1026 do_log(SMB_VFS_OP_SEEKDIR, True, handle, "");
1029 static long smb_full_audit_telldir(vfs_handle_struct *handle,
1034 result = SMB_VFS_NEXT_TELLDIR(handle, dirp);
1036 do_log(SMB_VFS_OP_TELLDIR, True, handle, "");
1041 static void smb_full_audit_rewinddir(vfs_handle_struct *handle,
1044 SMB_VFS_NEXT_REWINDDIR(handle, dirp);
1046 do_log(SMB_VFS_OP_REWINDDIR, True, handle, "");
1049 static int smb_full_audit_mkdirat(vfs_handle_struct *handle,
1050 struct files_struct *dirfsp,
1051 const struct smb_filename *smb_fname,
1056 result = SMB_VFS_NEXT_MKDIRAT(handle,
1061 do_log(SMB_VFS_OP_MKDIRAT,
1065 smb_fname_str_do_log(handle->conn, smb_fname));
1070 static int smb_full_audit_closedir(vfs_handle_struct *handle,
1075 result = SMB_VFS_NEXT_CLOSEDIR(handle, dirp);
1077 do_log(SMB_VFS_OP_CLOSEDIR, (result >= 0), handle, "");
1082 static int smb_full_audit_openat(vfs_handle_struct *handle,
1083 const struct files_struct *dirfsp,
1084 const struct smb_filename *smb_fname,
1085 struct files_struct *fsp,
1091 result = SMB_VFS_NEXT_OPENAT(handle, dirfsp, smb_fname, fsp, flags, mode);
1093 do_log(SMB_VFS_OP_OPENAT, (result >= 0), handle, "%s|%s",
1094 ((flags & O_WRONLY) || (flags & O_RDWR))?"w":"r",
1095 fsp_str_do_log(fsp));
1100 static NTSTATUS smb_full_audit_create_file(vfs_handle_struct *handle,
1101 struct smb_request *req,
1102 struct smb_filename *smb_fname,
1103 uint32_t access_mask,
1104 uint32_t share_access,
1105 uint32_t create_disposition,
1106 uint32_t create_options,
1107 uint32_t file_attributes,
1108 uint32_t oplock_request,
1109 const struct smb2_lease *lease,
1110 uint64_t allocation_size,
1111 uint32_t private_flags,
1112 struct security_descriptor *sd,
1113 struct ea_list *ea_list,
1114 files_struct **result_fsp,
1116 const struct smb2_create_blobs *in_context_blobs,
1117 struct smb2_create_blobs *out_context_blobs)
1120 const char* str_create_disposition;
1122 switch (create_disposition) {
1123 case FILE_SUPERSEDE:
1124 str_create_disposition = "supersede";
1126 case FILE_OVERWRITE_IF:
1127 str_create_disposition = "overwrite_if";
1130 str_create_disposition = "open";
1132 case FILE_OVERWRITE:
1133 str_create_disposition = "overwrite";
1136 str_create_disposition = "create";
1139 str_create_disposition = "open_if";
1142 str_create_disposition = "unknown";
1145 result = SMB_VFS_NEXT_CREATE_FILE(
1146 handle, /* handle */
1148 smb_fname, /* fname */
1149 access_mask, /* access_mask */
1150 share_access, /* share_access */
1151 create_disposition, /* create_disposition*/
1152 create_options, /* create_options */
1153 file_attributes, /* file_attributes */
1154 oplock_request, /* oplock_request */
1156 allocation_size, /* allocation_size */
1159 ea_list, /* ea_list */
1160 result_fsp, /* result */
1162 in_context_blobs, out_context_blobs); /* create context */
1164 do_log(SMB_VFS_OP_CREATE_FILE, (NT_STATUS_IS_OK(result)), handle,
1165 "0x%x|%s|%s|%s", access_mask,
1166 create_options & FILE_DIRECTORY_FILE ? "dir" : "file",
1167 str_create_disposition,
1168 smb_fname_str_do_log(handle->conn, smb_fname));
1173 static int smb_full_audit_close(vfs_handle_struct *handle, files_struct *fsp)
1177 result = SMB_VFS_NEXT_CLOSE(handle, fsp);
1179 do_log(SMB_VFS_OP_CLOSE, (result >= 0), handle, "%s",
1180 fsp_str_do_log(fsp));
1185 static ssize_t smb_full_audit_pread(vfs_handle_struct *handle, files_struct *fsp,
1186 void *data, size_t n, off_t offset)
1190 result = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
1192 do_log(SMB_VFS_OP_PREAD, (result >= 0), handle, "%s",
1193 fsp_str_do_log(fsp));
1198 struct smb_full_audit_pread_state {
1199 vfs_handle_struct *handle;
1202 struct vfs_aio_state vfs_aio_state;
1205 static void smb_full_audit_pread_done(struct tevent_req *subreq);
1207 static struct tevent_req *smb_full_audit_pread_send(
1208 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1209 struct tevent_context *ev, struct files_struct *fsp,
1210 void *data, size_t n, off_t offset)
1212 struct tevent_req *req, *subreq;
1213 struct smb_full_audit_pread_state *state;
1215 req = tevent_req_create(mem_ctx, &state,
1216 struct smb_full_audit_pread_state);
1218 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
1219 fsp_str_do_log(fsp));
1222 state->handle = handle;
1225 subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
1227 if (tevent_req_nomem(subreq, req)) {
1228 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
1229 fsp_str_do_log(fsp));
1230 return tevent_req_post(req, ev);
1232 tevent_req_set_callback(subreq, smb_full_audit_pread_done, req);
1234 do_log(SMB_VFS_OP_PREAD_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1238 static void smb_full_audit_pread_done(struct tevent_req *subreq)
1240 struct tevent_req *req = tevent_req_callback_data(
1241 subreq, struct tevent_req);
1242 struct smb_full_audit_pread_state *state = tevent_req_data(
1243 req, struct smb_full_audit_pread_state);
1245 state->ret = SMB_VFS_PREAD_RECV(subreq, &state->vfs_aio_state);
1246 TALLOC_FREE(subreq);
1247 tevent_req_done(req);
1250 static ssize_t smb_full_audit_pread_recv(struct tevent_req *req,
1251 struct vfs_aio_state *vfs_aio_state)
1253 struct smb_full_audit_pread_state *state = tevent_req_data(
1254 req, struct smb_full_audit_pread_state);
1256 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1257 do_log(SMB_VFS_OP_PREAD_RECV, false, state->handle, "%s",
1258 fsp_str_do_log(state->fsp));
1262 do_log(SMB_VFS_OP_PREAD_RECV, (state->ret >= 0), state->handle, "%s",
1263 fsp_str_do_log(state->fsp));
1265 *vfs_aio_state = state->vfs_aio_state;
1269 static ssize_t smb_full_audit_pwrite(vfs_handle_struct *handle, files_struct *fsp,
1270 const void *data, size_t n,
1275 result = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
1277 do_log(SMB_VFS_OP_PWRITE, (result >= 0), handle, "%s",
1278 fsp_str_do_log(fsp));
1283 struct smb_full_audit_pwrite_state {
1284 vfs_handle_struct *handle;
1287 struct vfs_aio_state vfs_aio_state;
1290 static void smb_full_audit_pwrite_done(struct tevent_req *subreq);
1292 static struct tevent_req *smb_full_audit_pwrite_send(
1293 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1294 struct tevent_context *ev, struct files_struct *fsp,
1295 const void *data, size_t n, off_t offset)
1297 struct tevent_req *req, *subreq;
1298 struct smb_full_audit_pwrite_state *state;
1300 req = tevent_req_create(mem_ctx, &state,
1301 struct smb_full_audit_pwrite_state);
1303 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1304 fsp_str_do_log(fsp));
1307 state->handle = handle;
1310 subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
1312 if (tevent_req_nomem(subreq, req)) {
1313 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1314 fsp_str_do_log(fsp));
1315 return tevent_req_post(req, ev);
1317 tevent_req_set_callback(subreq, smb_full_audit_pwrite_done, req);
1319 do_log(SMB_VFS_OP_PWRITE_SEND, true, handle, "%s",
1320 fsp_str_do_log(fsp));
1324 static void smb_full_audit_pwrite_done(struct tevent_req *subreq)
1326 struct tevent_req *req = tevent_req_callback_data(
1327 subreq, struct tevent_req);
1328 struct smb_full_audit_pwrite_state *state = tevent_req_data(
1329 req, struct smb_full_audit_pwrite_state);
1331 state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->vfs_aio_state);
1332 TALLOC_FREE(subreq);
1333 tevent_req_done(req);
1336 static ssize_t smb_full_audit_pwrite_recv(struct tevent_req *req,
1337 struct vfs_aio_state *vfs_aio_state)
1339 struct smb_full_audit_pwrite_state *state = tevent_req_data(
1340 req, struct smb_full_audit_pwrite_state);
1342 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1343 do_log(SMB_VFS_OP_PWRITE_RECV, false, state->handle, "%s",
1344 fsp_str_do_log(state->fsp));
1348 do_log(SMB_VFS_OP_PWRITE_RECV, (state->ret >= 0), state->handle, "%s",
1349 fsp_str_do_log(state->fsp));
1351 *vfs_aio_state = state->vfs_aio_state;
1355 static off_t smb_full_audit_lseek(vfs_handle_struct *handle, files_struct *fsp,
1356 off_t offset, int whence)
1360 result = SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence);
1362 do_log(SMB_VFS_OP_LSEEK, (result != (ssize_t)-1), handle,
1363 "%s", fsp_str_do_log(fsp));
1368 static ssize_t smb_full_audit_sendfile(vfs_handle_struct *handle, int tofd,
1369 files_struct *fromfsp,
1370 const DATA_BLOB *hdr, off_t offset,
1375 result = SMB_VFS_NEXT_SENDFILE(handle, tofd, fromfsp, hdr, offset, n);
1377 do_log(SMB_VFS_OP_SENDFILE, (result >= 0), handle,
1378 "%s", fsp_str_do_log(fromfsp));
1383 static ssize_t smb_full_audit_recvfile(vfs_handle_struct *handle, int fromfd,
1384 files_struct *tofsp,
1390 result = SMB_VFS_NEXT_RECVFILE(handle, fromfd, tofsp, offset, n);
1392 do_log(SMB_VFS_OP_RECVFILE, (result >= 0), handle,
1393 "%s", fsp_str_do_log(tofsp));
1398 static int smb_full_audit_renameat(vfs_handle_struct *handle,
1399 files_struct *srcfsp,
1400 const struct smb_filename *smb_fname_src,
1401 files_struct *dstfsp,
1402 const struct smb_filename *smb_fname_dst)
1406 result = SMB_VFS_NEXT_RENAMEAT(handle,
1412 do_log(SMB_VFS_OP_RENAMEAT, (result >= 0), handle, "%s|%s",
1413 smb_fname_str_do_log(handle->conn, smb_fname_src),
1414 smb_fname_str_do_log(handle->conn, smb_fname_dst));
1419 struct smb_full_audit_fsync_state {
1420 vfs_handle_struct *handle;
1423 struct vfs_aio_state vfs_aio_state;
1426 static void smb_full_audit_fsync_done(struct tevent_req *subreq);
1428 static struct tevent_req *smb_full_audit_fsync_send(
1429 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1430 struct tevent_context *ev, struct files_struct *fsp)
1432 struct tevent_req *req, *subreq;
1433 struct smb_full_audit_fsync_state *state;
1435 req = tevent_req_create(mem_ctx, &state,
1436 struct smb_full_audit_fsync_state);
1438 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1439 fsp_str_do_log(fsp));
1442 state->handle = handle;
1445 subreq = SMB_VFS_NEXT_FSYNC_SEND(state, ev, handle, fsp);
1446 if (tevent_req_nomem(subreq, req)) {
1447 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1448 fsp_str_do_log(fsp));
1449 return tevent_req_post(req, ev);
1451 tevent_req_set_callback(subreq, smb_full_audit_fsync_done, req);
1453 do_log(SMB_VFS_OP_FSYNC_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1457 static void smb_full_audit_fsync_done(struct tevent_req *subreq)
1459 struct tevent_req *req = tevent_req_callback_data(
1460 subreq, struct tevent_req);
1461 struct smb_full_audit_fsync_state *state = tevent_req_data(
1462 req, struct smb_full_audit_fsync_state);
1464 state->ret = SMB_VFS_FSYNC_RECV(subreq, &state->vfs_aio_state);
1465 TALLOC_FREE(subreq);
1466 tevent_req_done(req);
1469 static int smb_full_audit_fsync_recv(struct tevent_req *req,
1470 struct vfs_aio_state *vfs_aio_state)
1472 struct smb_full_audit_fsync_state *state = tevent_req_data(
1473 req, struct smb_full_audit_fsync_state);
1475 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1476 do_log(SMB_VFS_OP_FSYNC_RECV, false, state->handle, "%s",
1477 fsp_str_do_log(state->fsp));
1481 do_log(SMB_VFS_OP_FSYNC_RECV, (state->ret >= 0), state->handle, "%s",
1482 fsp_str_do_log(state->fsp));
1484 *vfs_aio_state = state->vfs_aio_state;
1488 static int smb_full_audit_stat(vfs_handle_struct *handle,
1489 struct smb_filename *smb_fname)
1493 result = SMB_VFS_NEXT_STAT(handle, smb_fname);
1495 do_log(SMB_VFS_OP_STAT, (result >= 0), handle, "%s",
1496 smb_fname_str_do_log(handle->conn, smb_fname));
1501 static int smb_full_audit_fstat(vfs_handle_struct *handle, files_struct *fsp,
1502 SMB_STRUCT_STAT *sbuf)
1506 result = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1508 do_log(SMB_VFS_OP_FSTAT, (result >= 0), handle, "%s",
1509 fsp_str_do_log(fsp));
1514 static int smb_full_audit_lstat(vfs_handle_struct *handle,
1515 struct smb_filename *smb_fname)
1519 result = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
1521 do_log(SMB_VFS_OP_LSTAT, (result >= 0), handle, "%s",
1522 smb_fname_str_do_log(handle->conn, smb_fname));
1527 static uint64_t smb_full_audit_get_alloc_size(vfs_handle_struct *handle,
1528 files_struct *fsp, const SMB_STRUCT_STAT *sbuf)
1532 result = SMB_VFS_NEXT_GET_ALLOC_SIZE(handle, fsp, sbuf);
1534 do_log(SMB_VFS_OP_GET_ALLOC_SIZE, (result != (uint64_t)-1), handle,
1535 "%llu", (unsigned long long)result);
1540 static int smb_full_audit_unlinkat(vfs_handle_struct *handle,
1541 struct files_struct *dirfsp,
1542 const struct smb_filename *smb_fname,
1547 result = SMB_VFS_NEXT_UNLINKAT(handle,
1552 do_log(SMB_VFS_OP_UNLINKAT, (result >= 0), handle, "%s",
1553 smb_fname_str_do_log(handle->conn, smb_fname));
1558 static int smb_full_audit_chmod(vfs_handle_struct *handle,
1559 const struct smb_filename *smb_fname,
1564 result = SMB_VFS_NEXT_CHMOD(handle, smb_fname, mode);
1566 do_log(SMB_VFS_OP_CHMOD,
1570 smb_fname_str_do_log(handle->conn, smb_fname),
1576 static int smb_full_audit_fchmod(vfs_handle_struct *handle, files_struct *fsp,
1581 result = SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1583 do_log(SMB_VFS_OP_FCHMOD, (result >= 0), handle,
1584 "%s|%o", fsp_str_do_log(fsp), mode);
1589 static int smb_full_audit_fchown(vfs_handle_struct *handle, files_struct *fsp,
1590 uid_t uid, gid_t gid)
1594 result = SMB_VFS_NEXT_FCHOWN(handle, fsp, uid, gid);
1596 do_log(SMB_VFS_OP_FCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1597 fsp_str_do_log(fsp), (long int)uid, (long int)gid);
1602 static int smb_full_audit_lchown(vfs_handle_struct *handle,
1603 const struct smb_filename *smb_fname,
1609 result = SMB_VFS_NEXT_LCHOWN(handle, smb_fname, uid, gid);
1611 do_log(SMB_VFS_OP_LCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1612 smb_fname->base_name, (long int)uid, (long int)gid);
1617 static int smb_full_audit_chdir(vfs_handle_struct *handle,
1618 const struct smb_filename *smb_fname)
1622 result = SMB_VFS_NEXT_CHDIR(handle, smb_fname);
1624 do_log(SMB_VFS_OP_CHDIR,
1628 smb_fname_str_do_log(handle->conn, smb_fname));
1633 static struct smb_filename *smb_full_audit_getwd(vfs_handle_struct *handle,
1636 struct smb_filename *result;
1638 result = SMB_VFS_NEXT_GETWD(handle, ctx);
1640 do_log(SMB_VFS_OP_GETWD, (result != NULL), handle, "%s",
1641 result == NULL? "" : result->base_name);
1646 static int smb_full_audit_ntimes(vfs_handle_struct *handle,
1647 const struct smb_filename *smb_fname,
1648 struct smb_file_time *ft)
1651 time_t create_time = convert_timespec_to_time_t(ft->create_time);
1652 time_t atime = convert_timespec_to_time_t(ft->atime);
1653 time_t mtime = convert_timespec_to_time_t(ft->mtime);
1654 time_t ctime = convert_timespec_to_time_t(ft->ctime);
1655 const char *create_time_str = "";
1656 const char *atime_str = "";
1657 const char *mtime_str = "";
1658 const char *ctime_str = "";
1659 TALLOC_CTX *frame = talloc_stackframe();
1661 result = SMB_VFS_NEXT_NTIMES(handle, smb_fname, ft);
1663 if (create_time > 0) {
1664 create_time_str = timestring(frame, create_time);
1667 atime_str = timestring(frame, atime);
1670 mtime_str = timestring(frame, mtime);
1673 ctime_str = timestring(frame, ctime);
1676 do_log(SMB_VFS_OP_NTIMES,
1680 smb_fname_str_do_log(handle->conn, smb_fname),
1691 static int smb_full_audit_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
1696 result = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1698 do_log(SMB_VFS_OP_FTRUNCATE, (result >= 0), handle,
1699 "%s", fsp_str_do_log(fsp));
1704 static int smb_full_audit_fallocate(vfs_handle_struct *handle, files_struct *fsp,
1711 result = SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
1713 do_log(SMB_VFS_OP_FALLOCATE, (result >= 0), handle,
1714 "%s", fsp_str_do_log(fsp));
1719 static bool smb_full_audit_lock(vfs_handle_struct *handle, files_struct *fsp,
1720 int op, off_t offset, off_t count, int type)
1724 result = SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type);
1726 do_log(SMB_VFS_OP_LOCK, result, handle, "%s", fsp_str_do_log(fsp));
1731 static int smb_full_audit_kernel_flock(struct vfs_handle_struct *handle,
1732 struct files_struct *fsp,
1733 uint32_t share_access,
1734 uint32_t access_mask)
1738 result = SMB_VFS_NEXT_KERNEL_FLOCK(handle,
1743 do_log(SMB_VFS_OP_KERNEL_FLOCK, (result >= 0), handle, "%s",
1744 fsp_str_do_log(fsp));
1749 static int smb_full_audit_fcntl(struct vfs_handle_struct *handle,
1750 struct files_struct *fsp,
1751 int cmd, va_list cmd_arg)
1754 va_list dup_cmd_arg;
1757 va_copy(dup_cmd_arg, cmd_arg);
1758 arg = va_arg(dup_cmd_arg, void *);
1759 result = SMB_VFS_NEXT_FCNTL(handle, fsp, cmd, arg);
1760 va_end(dup_cmd_arg);
1762 do_log(SMB_VFS_OP_FCNTL, (result >= 0), handle, "%s",
1763 fsp_str_do_log(fsp));
1768 static int smb_full_audit_linux_setlease(vfs_handle_struct *handle, files_struct *fsp,
1773 result = SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
1775 do_log(SMB_VFS_OP_LINUX_SETLEASE, (result >= 0), handle, "%s",
1776 fsp_str_do_log(fsp));
1781 static bool smb_full_audit_getlock(vfs_handle_struct *handle, files_struct *fsp,
1782 off_t *poffset, off_t *pcount, int *ptype, pid_t *ppid)
1786 result = SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype, ppid);
1788 do_log(SMB_VFS_OP_GETLOCK, result, handle, "%s", fsp_str_do_log(fsp));
1793 static int smb_full_audit_symlinkat(vfs_handle_struct *handle,
1794 const struct smb_filename *link_contents,
1795 struct files_struct *dirfsp,
1796 const struct smb_filename *new_smb_fname)
1800 result = SMB_VFS_NEXT_SYMLINKAT(handle,
1805 do_log(SMB_VFS_OP_SYMLINKAT,
1809 link_contents->base_name,
1810 smb_fname_str_do_log(handle->conn, new_smb_fname));
1815 static int smb_full_audit_readlinkat(vfs_handle_struct *handle,
1816 const struct files_struct *dirfsp,
1817 const struct smb_filename *smb_fname,
1823 result = SMB_VFS_NEXT_READLINKAT(handle,
1829 do_log(SMB_VFS_OP_READLINKAT,
1833 smb_fname_str_do_log(handle->conn, smb_fname));
1838 static int smb_full_audit_linkat(vfs_handle_struct *handle,
1839 files_struct *srcfsp,
1840 const struct smb_filename *old_smb_fname,
1841 files_struct *dstfsp,
1842 const struct smb_filename *new_smb_fname,
1847 result = SMB_VFS_NEXT_LINKAT(handle,
1854 do_log(SMB_VFS_OP_LINKAT,
1858 smb_fname_str_do_log(handle->conn, old_smb_fname),
1859 smb_fname_str_do_log(handle->conn, new_smb_fname));
1864 static int smb_full_audit_mknodat(vfs_handle_struct *handle,
1865 files_struct *dirfsp,
1866 const struct smb_filename *smb_fname,
1872 result = SMB_VFS_NEXT_MKNODAT(handle,
1878 do_log(SMB_VFS_OP_MKNODAT,
1882 smb_fname_str_do_log(handle->conn, smb_fname));
1887 static struct smb_filename *smb_full_audit_realpath(vfs_handle_struct *handle,
1889 const struct smb_filename *smb_fname)
1891 struct smb_filename *result_fname = NULL;
1893 result_fname = SMB_VFS_NEXT_REALPATH(handle, ctx, smb_fname);
1895 do_log(SMB_VFS_OP_REALPATH,
1896 (result_fname != NULL),
1899 smb_fname_str_do_log(handle->conn, smb_fname));
1901 return result_fname;
1904 static int smb_full_audit_chflags(vfs_handle_struct *handle,
1905 const struct smb_filename *smb_fname,
1910 result = SMB_VFS_NEXT_CHFLAGS(handle, smb_fname, flags);
1912 do_log(SMB_VFS_OP_CHFLAGS,
1916 smb_fname_str_do_log(handle->conn, smb_fname));
1921 static struct file_id smb_full_audit_file_id_create(struct vfs_handle_struct *handle,
1922 const SMB_STRUCT_STAT *sbuf)
1924 struct file_id id_zero = { 0 };
1925 struct file_id result;
1926 struct file_id_buf idbuf;
1928 result = SMB_VFS_NEXT_FILE_ID_CREATE(handle, sbuf);
1930 do_log(SMB_VFS_OP_FILE_ID_CREATE,
1931 !file_id_equal(&id_zero, &result),
1934 file_id_str_buf(result, &idbuf));
1939 static uint64_t smb_full_audit_fs_file_id(struct vfs_handle_struct *handle,
1940 const SMB_STRUCT_STAT *sbuf)
1944 result = SMB_VFS_NEXT_FS_FILE_ID(handle, sbuf);
1946 do_log(SMB_VFS_OP_FS_FILE_ID,
1948 handle, "%" PRIu64, result);
1953 static NTSTATUS smb_full_audit_streaminfo(vfs_handle_struct *handle,
1954 struct files_struct *fsp,
1955 const struct smb_filename *smb_fname,
1956 TALLOC_CTX *mem_ctx,
1957 unsigned int *pnum_streams,
1958 struct stream_struct **pstreams)
1962 result = SMB_VFS_NEXT_STREAMINFO(handle, fsp, smb_fname, mem_ctx,
1963 pnum_streams, pstreams);
1965 do_log(SMB_VFS_OP_STREAMINFO,
1966 NT_STATUS_IS_OK(result),
1969 smb_fname_str_do_log(handle->conn, smb_fname));
1974 static int smb_full_audit_get_real_filename(struct vfs_handle_struct *handle,
1975 const struct smb_filename *path,
1977 TALLOC_CTX *mem_ctx,
1982 result = SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name, mem_ctx,
1985 do_log(SMB_VFS_OP_GET_REAL_FILENAME, (result == 0), handle,
1987 path->base_name, name, (result == 0) ? *found_name : "");
1992 static const char *smb_full_audit_connectpath(vfs_handle_struct *handle,
1993 const struct smb_filename *smb_fname)
1997 result = SMB_VFS_NEXT_CONNECTPATH(handle, smb_fname);
1999 do_log(SMB_VFS_OP_CONNECTPATH,
2003 smb_fname_str_do_log(handle->conn, smb_fname));
2008 static NTSTATUS smb_full_audit_brl_lock_windows(struct vfs_handle_struct *handle,
2009 struct byte_range_lock *br_lck,
2010 struct lock_struct *plock)
2014 result = SMB_VFS_NEXT_BRL_LOCK_WINDOWS(handle, br_lck, plock);
2016 do_log(SMB_VFS_OP_BRL_LOCK_WINDOWS, NT_STATUS_IS_OK(result), handle,
2017 "%s:%llu-%llu. type=%d.",
2018 fsp_str_do_log(brl_fsp(br_lck)),
2019 (unsigned long long)plock->start,
2020 (unsigned long long)plock->size,
2026 static bool smb_full_audit_brl_unlock_windows(struct vfs_handle_struct *handle,
2027 struct byte_range_lock *br_lck,
2028 const struct lock_struct *plock)
2032 result = SMB_VFS_NEXT_BRL_UNLOCK_WINDOWS(handle, br_lck, plock);
2034 do_log(SMB_VFS_OP_BRL_UNLOCK_WINDOWS, (result == 0), handle,
2035 "%s:%llu-%llu:%d", fsp_str_do_log(brl_fsp(br_lck)),
2036 (unsigned long long)plock->start,
2037 (unsigned long long)plock->size,
2043 static bool smb_full_audit_strict_lock_check(struct vfs_handle_struct *handle,
2044 struct files_struct *fsp,
2045 struct lock_struct *plock)
2049 result = SMB_VFS_NEXT_STRICT_LOCK_CHECK(handle, fsp, plock);
2051 do_log(SMB_VFS_OP_STRICT_LOCK_CHECK, result, handle,
2052 "%s:%llu-%llu:%d", fsp_str_do_log(fsp),
2053 (unsigned long long)plock->start,
2054 (unsigned long long)plock->size,
2060 static NTSTATUS smb_full_audit_translate_name(struct vfs_handle_struct *handle,
2062 enum vfs_translate_direction direction,
2063 TALLOC_CTX *mem_ctx,
2068 result = SMB_VFS_NEXT_TRANSLATE_NAME(handle, name, direction, mem_ctx,
2071 do_log(SMB_VFS_OP_TRANSLATE_NAME, NT_STATUS_IS_OK(result), handle, "");
2076 static NTSTATUS smb_full_audit_fsctl(struct vfs_handle_struct *handle,
2077 struct files_struct *fsp,
2081 const uint8_t *_in_data,
2083 uint8_t **_out_data,
2084 uint32_t max_out_len,
2089 result = SMB_VFS_NEXT_FSCTL(handle,
2100 do_log(SMB_VFS_OP_FSCTL, NT_STATUS_IS_OK(result), handle, "");
2105 static struct tevent_req *smb_full_audit_offload_read_send(
2106 TALLOC_CTX *mem_ctx,
2107 struct tevent_context *ev,
2108 struct vfs_handle_struct *handle,
2109 struct files_struct *fsp,
2115 struct tevent_req *req = NULL;
2117 req = SMB_VFS_NEXT_OFFLOAD_READ_SEND(mem_ctx, ev, handle, fsp,
2118 fsctl, ttl, offset, to_copy);
2120 do_log(SMB_VFS_OP_OFFLOAD_READ_SEND, req, handle, "");
2125 static NTSTATUS smb_full_audit_offload_read_recv(
2126 struct tevent_req *req,
2127 struct vfs_handle_struct *handle,
2128 TALLOC_CTX *mem_ctx,
2129 DATA_BLOB *_token_blob)
2133 status = SMB_VFS_NEXT_OFFLOAD_READ_RECV(req, handle, mem_ctx,
2136 do_log(SMB_VFS_OP_OFFLOAD_READ_RECV, NT_STATUS_IS_OK(status), handle, "");
2141 static struct tevent_req *smb_full_audit_offload_write_send(struct vfs_handle_struct *handle,
2142 TALLOC_CTX *mem_ctx,
2143 struct tevent_context *ev,
2146 off_t transfer_offset,
2147 struct files_struct *dest_fsp,
2151 struct tevent_req *req;
2153 req = SMB_VFS_NEXT_OFFLOAD_WRITE_SEND(handle, mem_ctx, ev,
2154 fsctl, token, transfer_offset,
2155 dest_fsp, dest_off, num);
2157 do_log(SMB_VFS_OP_OFFLOAD_WRITE_SEND, req, handle, "");
2162 static NTSTATUS smb_full_audit_offload_write_recv(struct vfs_handle_struct *handle,
2163 struct tevent_req *req,
2168 result = SMB_VFS_NEXT_OFFLOAD_WRITE_RECV(handle, req, copied);
2170 do_log(SMB_VFS_OP_OFFLOAD_WRITE_RECV, NT_STATUS_IS_OK(result), handle, "");
2175 static NTSTATUS smb_full_audit_fget_compression(vfs_handle_struct *handle,
2176 TALLOC_CTX *mem_ctx,
2177 struct files_struct *fsp,
2178 uint16_t *_compression_fmt)
2182 result = SMB_VFS_NEXT_FGET_COMPRESSION(handle, mem_ctx, fsp,
2185 do_log(SMB_VFS_OP_FGET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
2187 fsp_str_do_log(fsp));
2192 static NTSTATUS smb_full_audit_set_compression(vfs_handle_struct *handle,
2193 TALLOC_CTX *mem_ctx,
2194 struct files_struct *fsp,
2195 uint16_t compression_fmt)
2199 result = SMB_VFS_NEXT_SET_COMPRESSION(handle, mem_ctx, fsp,
2202 do_log(SMB_VFS_OP_SET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
2203 "%s", fsp_str_do_log(fsp));
2208 static NTSTATUS smb_full_audit_readdir_attr(struct vfs_handle_struct *handle,
2209 const struct smb_filename *fname,
2210 TALLOC_CTX *mem_ctx,
2211 struct readdir_attr_data **pattr_data)
2215 status = SMB_VFS_NEXT_READDIR_ATTR(handle, fname, mem_ctx, pattr_data);
2217 do_log(SMB_VFS_OP_READDIR_ATTR, NT_STATUS_IS_OK(status), handle, "%s",
2218 smb_fname_str_do_log(handle->conn, fname));
2223 struct smb_full_audit_get_dos_attributes_state {
2224 struct vfs_aio_state aio_state;
2225 vfs_handle_struct *handle;
2226 files_struct *dir_fsp;
2227 const struct smb_filename *smb_fname;
2231 static void smb_full_audit_get_dos_attributes_done(struct tevent_req *subreq);
2233 static struct tevent_req *smb_full_audit_get_dos_attributes_send(
2234 TALLOC_CTX *mem_ctx,
2235 struct tevent_context *ev,
2236 struct vfs_handle_struct *handle,
2237 files_struct *dir_fsp,
2238 struct smb_filename *smb_fname)
2240 struct tevent_req *req = NULL;
2241 struct smb_full_audit_get_dos_attributes_state *state = NULL;
2242 struct tevent_req *subreq = NULL;
2244 req = tevent_req_create(mem_ctx, &state,
2245 struct smb_full_audit_get_dos_attributes_state);
2247 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2251 fsp_str_do_log(dir_fsp),
2252 smb_fname->base_name);
2255 *state = (struct smb_full_audit_get_dos_attributes_state) {
2258 .smb_fname = smb_fname,
2261 subreq = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES_SEND(mem_ctx,
2266 if (tevent_req_nomem(subreq, req)) {
2267 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2271 fsp_str_do_log(dir_fsp),
2272 smb_fname->base_name);
2273 return tevent_req_post(req, ev);
2275 tevent_req_set_callback(subreq,
2276 smb_full_audit_get_dos_attributes_done,
2279 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2283 fsp_str_do_log(dir_fsp),
2284 smb_fname->base_name);
2289 static void smb_full_audit_get_dos_attributes_done(struct tevent_req *subreq)
2291 struct tevent_req *req =
2292 tevent_req_callback_data(subreq,
2294 struct smb_full_audit_get_dos_attributes_state *state =
2295 tevent_req_data(req,
2296 struct smb_full_audit_get_dos_attributes_state);
2299 status = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES_RECV(subreq,
2302 TALLOC_FREE(subreq);
2303 if (tevent_req_nterror(req, status)) {
2307 tevent_req_done(req);
2311 static NTSTATUS smb_full_audit_get_dos_attributes_recv(struct tevent_req *req,
2312 struct vfs_aio_state *aio_state,
2315 struct smb_full_audit_get_dos_attributes_state *state =
2316 tevent_req_data(req,
2317 struct smb_full_audit_get_dos_attributes_state);
2320 if (tevent_req_is_nterror(req, &status)) {
2321 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV,
2325 fsp_str_do_log(state->dir_fsp),
2326 state->smb_fname->base_name);
2327 tevent_req_received(req);
2331 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV,
2335 fsp_str_do_log(state->dir_fsp),
2336 state->smb_fname->base_name);
2338 *aio_state = state->aio_state;
2339 *dosmode = state->dosmode;
2340 tevent_req_received(req);
2341 return NT_STATUS_OK;
2344 static NTSTATUS smb_full_audit_fget_dos_attributes(
2345 struct vfs_handle_struct *handle,
2346 struct files_struct *fsp,
2351 status = SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle,
2355 do_log(SMB_VFS_OP_FGET_DOS_ATTRIBUTES,
2356 NT_STATUS_IS_OK(status),
2359 fsp_str_do_log(fsp));
2364 static NTSTATUS smb_full_audit_set_dos_attributes(
2365 struct vfs_handle_struct *handle,
2366 const struct smb_filename *smb_fname,
2371 status = SMB_VFS_NEXT_SET_DOS_ATTRIBUTES(handle,
2375 do_log(SMB_VFS_OP_SET_DOS_ATTRIBUTES,
2376 NT_STATUS_IS_OK(status),
2379 smb_fname_str_do_log(handle->conn, smb_fname));
2384 static NTSTATUS smb_full_audit_fset_dos_attributes(
2385 struct vfs_handle_struct *handle,
2386 struct files_struct *fsp,
2391 status = SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle,
2395 do_log(SMB_VFS_OP_FSET_DOS_ATTRIBUTES,
2396 NT_STATUS_IS_OK(status),
2399 fsp_str_do_log(fsp));
2404 static NTSTATUS smb_full_audit_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
2405 uint32_t security_info,
2406 TALLOC_CTX *mem_ctx,
2407 struct security_descriptor **ppdesc)
2411 result = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
2414 do_log(SMB_VFS_OP_FGET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2415 "%s", fsp_str_do_log(fsp));
2420 static NTSTATUS smb_full_audit_get_nt_acl_at(vfs_handle_struct *handle,
2421 struct files_struct *dirfsp,
2422 const struct smb_filename *smb_fname,
2423 uint32_t security_info,
2424 TALLOC_CTX *mem_ctx,
2425 struct security_descriptor **ppdesc)
2429 result = SMB_VFS_NEXT_GET_NT_ACL_AT(handle,
2436 do_log(SMB_VFS_OP_GET_NT_ACL_AT,
2437 NT_STATUS_IS_OK(result),
2440 smb_fname_str_do_log(handle->conn, smb_fname));
2445 static NTSTATUS smb_full_audit_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
2446 uint32_t security_info_sent,
2447 const struct security_descriptor *psd)
2449 struct vfs_full_audit_private_data *pd;
2453 SMB_VFS_HANDLE_GET_DATA(handle, pd,
2454 struct vfs_full_audit_private_data,
2455 return NT_STATUS_INTERNAL_ERROR);
2457 if (pd->log_secdesc) {
2458 sd = sddl_encode(talloc_tos(), psd, get_global_sam_sid());
2461 result = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
2463 do_log(SMB_VFS_OP_FSET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2464 "%s [%s]", fsp_str_do_log(fsp), sd ? sd : "");
2471 static NTSTATUS smb_full_audit_audit_file(struct vfs_handle_struct *handle,
2472 struct smb_filename *file,
2473 struct security_acl *sacl,
2474 uint32_t access_requested,
2475 uint32_t access_denied)
2479 result = SMB_VFS_NEXT_AUDIT_FILE(handle,
2485 do_log(SMB_VFS_OP_AUDIT_FILE, NT_STATUS_IS_OK(result), handle,
2487 smb_fname_str_do_log(handle->conn, file));
2492 static SMB_ACL_T smb_full_audit_sys_acl_get_file(vfs_handle_struct *handle,
2493 const struct smb_filename *smb_fname,
2494 SMB_ACL_TYPE_T type,
2495 TALLOC_CTX *mem_ctx)
2499 result = SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, smb_fname,
2502 do_log(SMB_VFS_OP_SYS_ACL_GET_FILE,
2506 smb_fname_str_do_log(handle->conn, smb_fname));
2511 static SMB_ACL_T smb_full_audit_sys_acl_get_fd(vfs_handle_struct *handle,
2512 files_struct *fsp, TALLOC_CTX *mem_ctx)
2516 result = SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp, mem_ctx);
2518 do_log(SMB_VFS_OP_SYS_ACL_GET_FD, (result != NULL), handle,
2519 "%s", fsp_str_do_log(fsp));
2524 static int smb_full_audit_sys_acl_blob_get_file(vfs_handle_struct *handle,
2525 const struct smb_filename *smb_fname,
2526 TALLOC_CTX *mem_ctx,
2527 char **blob_description,
2532 result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FILE(handle, smb_fname,
2533 mem_ctx, blob_description, blob);
2535 do_log(SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE,
2539 smb_fname_str_do_log(handle->conn, smb_fname));
2544 static int smb_full_audit_sys_acl_blob_get_fd(vfs_handle_struct *handle,
2546 TALLOC_CTX *mem_ctx,
2547 char **blob_description,
2552 result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle, fsp, mem_ctx, blob_description, blob);
2554 do_log(SMB_VFS_OP_SYS_ACL_BLOB_GET_FD, (result >= 0), handle,
2555 "%s", fsp_str_do_log(fsp));
2560 static int smb_full_audit_sys_acl_set_file(vfs_handle_struct *handle,
2561 const struct smb_filename *smb_fname,
2562 SMB_ACL_TYPE_T acltype,
2567 result = SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, smb_fname, acltype,
2570 do_log(SMB_VFS_OP_SYS_ACL_SET_FILE,
2574 smb_fname_str_do_log(handle->conn, smb_fname));
2579 static int smb_full_audit_sys_acl_set_fd(vfs_handle_struct *handle,
2580 struct files_struct *fsp,
2581 SMB_ACL_TYPE_T type,
2586 result = SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, type, theacl);
2588 do_log(SMB_VFS_OP_SYS_ACL_SET_FD, (result >= 0), handle,
2589 "%s", fsp_str_do_log(fsp));
2594 static int smb_full_audit_sys_acl_delete_def_file(vfs_handle_struct *handle,
2595 const struct smb_filename *smb_fname)
2599 result = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, smb_fname);
2601 do_log(SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE,
2605 smb_fname_str_do_log(handle->conn, smb_fname));
2610 static ssize_t smb_full_audit_getxattr(struct vfs_handle_struct *handle,
2611 const struct smb_filename *smb_fname,
2612 const char *name, void *value, size_t size)
2616 result = SMB_VFS_NEXT_GETXATTR(handle, smb_fname, name, value, size);
2618 do_log(SMB_VFS_OP_GETXATTR,
2622 smb_fname_str_do_log(handle->conn, smb_fname),
2628 struct smb_full_audit_getxattrat_state {
2629 struct vfs_aio_state aio_state;
2630 vfs_handle_struct *handle;
2631 files_struct *dir_fsp;
2632 const struct smb_filename *smb_fname;
2633 const char *xattr_name;
2635 uint8_t *xattr_value;
2638 static void smb_full_audit_getxattrat_done(struct tevent_req *subreq);
2640 static struct tevent_req *smb_full_audit_getxattrat_send(
2641 TALLOC_CTX *mem_ctx,
2642 struct tevent_context *ev,
2643 struct vfs_handle_struct *handle,
2644 files_struct *dir_fsp,
2645 const struct smb_filename *smb_fname,
2646 const char *xattr_name,
2649 struct tevent_req *req = NULL;
2650 struct tevent_req *subreq = NULL;
2651 struct smb_full_audit_getxattrat_state *state = NULL;
2653 req = tevent_req_create(mem_ctx, &state,
2654 struct smb_full_audit_getxattrat_state);
2656 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2660 fsp_str_do_log(dir_fsp),
2661 smb_fname->base_name,
2665 *state = (struct smb_full_audit_getxattrat_state) {
2668 .smb_fname = smb_fname,
2669 .xattr_name = xattr_name,
2672 subreq = SMB_VFS_NEXT_GETXATTRAT_SEND(state,
2679 if (tevent_req_nomem(subreq, req)) {
2680 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2684 fsp_str_do_log(dir_fsp),
2685 smb_fname->base_name,
2687 return tevent_req_post(req, ev);
2689 tevent_req_set_callback(subreq, smb_full_audit_getxattrat_done, req);
2691 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2695 fsp_str_do_log(dir_fsp),
2696 smb_fname->base_name,
2702 static void smb_full_audit_getxattrat_done(struct tevent_req *subreq)
2704 struct tevent_req *req = tevent_req_callback_data(
2705 subreq, struct tevent_req);
2706 struct smb_full_audit_getxattrat_state *state = tevent_req_data(
2707 req, struct smb_full_audit_getxattrat_state);
2709 state->xattr_size = SMB_VFS_NEXT_GETXATTRAT_RECV(subreq,
2712 &state->xattr_value);
2713 TALLOC_FREE(subreq);
2714 if (state->xattr_size == -1) {
2715 tevent_req_error(req, state->aio_state.error);
2719 tevent_req_done(req);
2722 static ssize_t smb_full_audit_getxattrat_recv(struct tevent_req *req,
2723 struct vfs_aio_state *aio_state,
2724 TALLOC_CTX *mem_ctx,
2725 uint8_t **xattr_value)
2727 struct smb_full_audit_getxattrat_state *state = tevent_req_data(
2728 req, struct smb_full_audit_getxattrat_state);
2731 if (tevent_req_is_unix_error(req, &aio_state->error)) {
2732 do_log(SMB_VFS_OP_GETXATTRAT_RECV,
2736 fsp_str_do_log(state->dir_fsp),
2737 state->smb_fname->base_name,
2739 tevent_req_received(req);
2743 do_log(SMB_VFS_OP_GETXATTRAT_RECV,
2747 fsp_str_do_log(state->dir_fsp),
2748 state->smb_fname->base_name,
2751 *aio_state = state->aio_state;
2752 xattr_size = state->xattr_size;
2753 if (xattr_value != NULL) {
2754 *xattr_value = talloc_move(mem_ctx, &state->xattr_value);
2757 tevent_req_received(req);
2761 static ssize_t smb_full_audit_fgetxattr(struct vfs_handle_struct *handle,
2762 struct files_struct *fsp,
2763 const char *name, void *value, size_t size)
2767 result = SMB_VFS_NEXT_FGETXATTR(handle, fsp, name, value, size);
2769 do_log(SMB_VFS_OP_FGETXATTR, (result >= 0), handle,
2770 "%s|%s", fsp_str_do_log(fsp), name);
2775 static ssize_t smb_full_audit_listxattr(struct vfs_handle_struct *handle,
2776 const struct smb_filename *smb_fname,
2782 result = SMB_VFS_NEXT_LISTXATTR(handle, smb_fname, list, size);
2784 do_log(SMB_VFS_OP_LISTXATTR,
2788 smb_fname_str_do_log(handle->conn, smb_fname));
2793 static ssize_t smb_full_audit_flistxattr(struct vfs_handle_struct *handle,
2794 struct files_struct *fsp, char *list,
2799 result = SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
2801 do_log(SMB_VFS_OP_FLISTXATTR, (result >= 0), handle,
2802 "%s", fsp_str_do_log(fsp));
2807 static int smb_full_audit_removexattr(struct vfs_handle_struct *handle,
2808 const struct smb_filename *smb_fname,
2813 result = SMB_VFS_NEXT_REMOVEXATTR(handle, smb_fname, name);
2815 do_log(SMB_VFS_OP_REMOVEXATTR,
2819 smb_fname_str_do_log(handle->conn, smb_fname),
2825 static int smb_full_audit_fremovexattr(struct vfs_handle_struct *handle,
2826 struct files_struct *fsp,
2831 result = SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, name);
2833 do_log(SMB_VFS_OP_FREMOVEXATTR, (result >= 0), handle,
2834 "%s|%s", fsp_str_do_log(fsp), name);
2839 static int smb_full_audit_setxattr(struct vfs_handle_struct *handle,
2840 const struct smb_filename *smb_fname,
2841 const char *name, const void *value, size_t size,
2846 result = SMB_VFS_NEXT_SETXATTR(handle, smb_fname, name, value, size,
2849 do_log(SMB_VFS_OP_SETXATTR,
2853 smb_fname_str_do_log(handle->conn, smb_fname),
2859 static int smb_full_audit_fsetxattr(struct vfs_handle_struct *handle,
2860 struct files_struct *fsp, const char *name,
2861 const void *value, size_t size, int flags)
2865 result = SMB_VFS_NEXT_FSETXATTR(handle, fsp, name, value, size, flags);
2867 do_log(SMB_VFS_OP_FSETXATTR, (result >= 0), handle,
2868 "%s|%s", fsp_str_do_log(fsp), name);
2873 static bool smb_full_audit_aio_force(struct vfs_handle_struct *handle,
2874 struct files_struct *fsp)
2878 result = SMB_VFS_NEXT_AIO_FORCE(handle, fsp);
2879 do_log(SMB_VFS_OP_AIO_FORCE, result, handle,
2880 "%s", fsp_str_do_log(fsp));
2885 static NTSTATUS smb_full_audit_durable_cookie(struct vfs_handle_struct *handle,
2886 struct files_struct *fsp,
2887 TALLOC_CTX *mem_ctx,
2892 result = SMB_VFS_NEXT_DURABLE_COOKIE(handle,
2897 do_log(SMB_VFS_OP_DURABLE_COOKIE, NT_STATUS_IS_OK(result), handle,
2898 "%s", fsp_str_do_log(fsp));
2903 static NTSTATUS smb_full_audit_durable_disconnect(
2904 struct vfs_handle_struct *handle,
2905 struct files_struct *fsp,
2906 const DATA_BLOB old_cookie,
2907 TALLOC_CTX *mem_ctx,
2908 DATA_BLOB *new_cookie)
2912 result = SMB_VFS_NEXT_DURABLE_DISCONNECT(handle,
2918 do_log(SMB_VFS_OP_DURABLE_DISCONNECT, NT_STATUS_IS_OK(result), handle,
2919 "%s", fsp_str_do_log(fsp));
2924 static NTSTATUS smb_full_audit_durable_reconnect(
2925 struct vfs_handle_struct *handle,
2926 struct smb_request *smb1req,
2927 struct smbXsrv_open *op,
2928 const DATA_BLOB old_cookie,
2929 TALLOC_CTX *mem_ctx,
2930 struct files_struct **fsp,
2931 DATA_BLOB *new_cookie)
2935 result = SMB_VFS_NEXT_DURABLE_RECONNECT(handle,
2943 do_log(SMB_VFS_OP_DURABLE_RECONNECT,
2944 NT_STATUS_IS_OK(result),
2951 static struct vfs_fn_pointers vfs_full_audit_fns = {
2953 /* Disk operations */
2955 .connect_fn = smb_full_audit_connect,
2956 .disconnect_fn = smb_full_audit_disconnect,
2957 .disk_free_fn = smb_full_audit_disk_free,
2958 .get_quota_fn = smb_full_audit_get_quota,
2959 .set_quota_fn = smb_full_audit_set_quota,
2960 .get_shadow_copy_data_fn = smb_full_audit_get_shadow_copy_data,
2961 .statvfs_fn = smb_full_audit_statvfs,
2962 .fs_capabilities_fn = smb_full_audit_fs_capabilities,
2963 .get_dfs_referrals_fn = smb_full_audit_get_dfs_referrals,
2964 .create_dfs_pathat_fn = smb_full_audit_create_dfs_pathat,
2965 .read_dfs_pathat_fn = smb_full_audit_read_dfs_pathat,
2966 .fdopendir_fn = smb_full_audit_fdopendir,
2967 .readdir_fn = smb_full_audit_readdir,
2968 .seekdir_fn = smb_full_audit_seekdir,
2969 .telldir_fn = smb_full_audit_telldir,
2970 .rewind_dir_fn = smb_full_audit_rewinddir,
2971 .mkdirat_fn = smb_full_audit_mkdirat,
2972 .closedir_fn = smb_full_audit_closedir,
2973 .openat_fn = smb_full_audit_openat,
2974 .create_file_fn = smb_full_audit_create_file,
2975 .close_fn = smb_full_audit_close,
2976 .pread_fn = smb_full_audit_pread,
2977 .pread_send_fn = smb_full_audit_pread_send,
2978 .pread_recv_fn = smb_full_audit_pread_recv,
2979 .pwrite_fn = smb_full_audit_pwrite,
2980 .pwrite_send_fn = smb_full_audit_pwrite_send,
2981 .pwrite_recv_fn = smb_full_audit_pwrite_recv,
2982 .lseek_fn = smb_full_audit_lseek,
2983 .sendfile_fn = smb_full_audit_sendfile,
2984 .recvfile_fn = smb_full_audit_recvfile,
2985 .renameat_fn = smb_full_audit_renameat,
2986 .fsync_send_fn = smb_full_audit_fsync_send,
2987 .fsync_recv_fn = smb_full_audit_fsync_recv,
2988 .stat_fn = smb_full_audit_stat,
2989 .fstat_fn = smb_full_audit_fstat,
2990 .lstat_fn = smb_full_audit_lstat,
2991 .get_alloc_size_fn = smb_full_audit_get_alloc_size,
2992 .unlinkat_fn = smb_full_audit_unlinkat,
2993 .chmod_fn = smb_full_audit_chmod,
2994 .fchmod_fn = smb_full_audit_fchmod,
2995 .fchown_fn = smb_full_audit_fchown,
2996 .lchown_fn = smb_full_audit_lchown,
2997 .chdir_fn = smb_full_audit_chdir,
2998 .getwd_fn = smb_full_audit_getwd,
2999 .ntimes_fn = smb_full_audit_ntimes,
3000 .ftruncate_fn = smb_full_audit_ftruncate,
3001 .fallocate_fn = smb_full_audit_fallocate,
3002 .lock_fn = smb_full_audit_lock,
3003 .kernel_flock_fn = smb_full_audit_kernel_flock,
3004 .fcntl_fn = smb_full_audit_fcntl,
3005 .linux_setlease_fn = smb_full_audit_linux_setlease,
3006 .getlock_fn = smb_full_audit_getlock,
3007 .symlinkat_fn = smb_full_audit_symlinkat,
3008 .readlinkat_fn = smb_full_audit_readlinkat,
3009 .linkat_fn = smb_full_audit_linkat,
3010 .mknodat_fn = smb_full_audit_mknodat,
3011 .realpath_fn = smb_full_audit_realpath,
3012 .chflags_fn = smb_full_audit_chflags,
3013 .file_id_create_fn = smb_full_audit_file_id_create,
3014 .fs_file_id_fn = smb_full_audit_fs_file_id,
3015 .offload_read_send_fn = smb_full_audit_offload_read_send,
3016 .offload_read_recv_fn = smb_full_audit_offload_read_recv,
3017 .offload_write_send_fn = smb_full_audit_offload_write_send,
3018 .offload_write_recv_fn = smb_full_audit_offload_write_recv,
3019 .fget_compression_fn = smb_full_audit_fget_compression,
3020 .set_compression_fn = smb_full_audit_set_compression,
3021 .snap_check_path_fn = smb_full_audit_snap_check_path,
3022 .snap_create_fn = smb_full_audit_snap_create,
3023 .snap_delete_fn = smb_full_audit_snap_delete,
3024 .streaminfo_fn = smb_full_audit_streaminfo,
3025 .get_real_filename_fn = smb_full_audit_get_real_filename,
3026 .connectpath_fn = smb_full_audit_connectpath,
3027 .brl_lock_windows_fn = smb_full_audit_brl_lock_windows,
3028 .brl_unlock_windows_fn = smb_full_audit_brl_unlock_windows,
3029 .strict_lock_check_fn = smb_full_audit_strict_lock_check,
3030 .translate_name_fn = smb_full_audit_translate_name,
3031 .fsctl_fn = smb_full_audit_fsctl,
3032 .get_dos_attributes_send_fn = smb_full_audit_get_dos_attributes_send,
3033 .get_dos_attributes_recv_fn = smb_full_audit_get_dos_attributes_recv,
3034 .fget_dos_attributes_fn = smb_full_audit_fget_dos_attributes,
3035 .set_dos_attributes_fn = smb_full_audit_set_dos_attributes,
3036 .fset_dos_attributes_fn = smb_full_audit_fset_dos_attributes,
3037 .fget_nt_acl_fn = smb_full_audit_fget_nt_acl,
3038 .get_nt_acl_at_fn = smb_full_audit_get_nt_acl_at,
3039 .fset_nt_acl_fn = smb_full_audit_fset_nt_acl,
3040 .audit_file_fn = smb_full_audit_audit_file,
3041 .sys_acl_get_file_fn = smb_full_audit_sys_acl_get_file,
3042 .sys_acl_get_fd_fn = smb_full_audit_sys_acl_get_fd,
3043 .sys_acl_blob_get_file_fn = smb_full_audit_sys_acl_blob_get_file,
3044 .sys_acl_blob_get_fd_fn = smb_full_audit_sys_acl_blob_get_fd,
3045 .sys_acl_set_file_fn = smb_full_audit_sys_acl_set_file,
3046 .sys_acl_set_fd_fn = smb_full_audit_sys_acl_set_fd,
3047 .sys_acl_delete_def_file_fn = smb_full_audit_sys_acl_delete_def_file,
3048 .getxattr_fn = smb_full_audit_getxattr,
3049 .getxattrat_send_fn = smb_full_audit_getxattrat_send,
3050 .getxattrat_recv_fn = smb_full_audit_getxattrat_recv,
3051 .fgetxattr_fn = smb_full_audit_fgetxattr,
3052 .listxattr_fn = smb_full_audit_listxattr,
3053 .flistxattr_fn = smb_full_audit_flistxattr,
3054 .removexattr_fn = smb_full_audit_removexattr,
3055 .fremovexattr_fn = smb_full_audit_fremovexattr,
3056 .setxattr_fn = smb_full_audit_setxattr,
3057 .fsetxattr_fn = smb_full_audit_fsetxattr,
3058 .aio_force_fn = smb_full_audit_aio_force,
3059 .durable_cookie_fn = smb_full_audit_durable_cookie,
3060 .durable_disconnect_fn = smb_full_audit_durable_disconnect,
3061 .durable_reconnect_fn = smb_full_audit_durable_reconnect,
3062 .readdir_attr_fn = smb_full_audit_readdir_attr
3067 NTSTATUS vfs_full_audit_init(TALLOC_CTX *ctx)
3071 smb_vfs_assert_all_fns(&vfs_full_audit_fns, "full_audit");
3073 ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "full_audit",
3074 &vfs_full_audit_fns);
3076 if (!NT_STATUS_IS_OK(ret))
3079 vfs_full_audit_debug_level = debug_add_class("full_audit");
3080 if (vfs_full_audit_debug_level == -1) {
3081 vfs_full_audit_debug_level = DBGC_VFS;
3082 DEBUG(0, ("vfs_full_audit: Couldn't register custom debugging "
3085 DEBUG(10, ("vfs_full_audit: Debug class number of "
3086 "'full_audit': %d\n", vfs_full_audit_debug_level));