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_GET_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,
186 SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
187 SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV,
188 SMB_VFS_OP_FGET_DOS_ATTRIBUTES,
189 SMB_VFS_OP_SET_DOS_ATTRIBUTES,
190 SMB_VFS_OP_FSET_DOS_ATTRIBUTES,
192 /* NT ACL operations. */
194 SMB_VFS_OP_FGET_NT_ACL,
195 SMB_VFS_OP_GET_NT_ACL_AT,
196 SMB_VFS_OP_FSET_NT_ACL,
197 SMB_VFS_OP_AUDIT_FILE,
199 /* POSIX ACL operations. */
201 SMB_VFS_OP_SYS_ACL_GET_FILE,
202 SMB_VFS_OP_SYS_ACL_GET_FD,
203 SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE,
204 SMB_VFS_OP_SYS_ACL_BLOB_GET_FD,
205 SMB_VFS_OP_SYS_ACL_SET_FILE,
206 SMB_VFS_OP_SYS_ACL_SET_FD,
207 SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE,
211 SMB_VFS_OP_GETXATTRAT_SEND,
212 SMB_VFS_OP_GETXATTRAT_RECV,
213 SMB_VFS_OP_FGETXATTR,
214 SMB_VFS_OP_LISTXATTR,
215 SMB_VFS_OP_FLISTXATTR,
216 SMB_VFS_OP_REMOVEXATTR,
217 SMB_VFS_OP_FREMOVEXATTR,
219 SMB_VFS_OP_FSETXATTR,
222 SMB_VFS_OP_AIO_FORCE,
224 /* offline operations */
225 SMB_VFS_OP_IS_OFFLINE,
226 SMB_VFS_OP_SET_OFFLINE,
228 /* Durable handle operations. */
229 SMB_VFS_OP_DURABLE_COOKIE,
230 SMB_VFS_OP_DURABLE_DISCONNECT,
231 SMB_VFS_OP_DURABLE_RECONNECT,
233 SMB_VFS_OP_READDIR_ATTR,
235 /* This should always be last enum value */
240 /* The following array *must* be in the same order as defined in vfs_op_type */
246 { SMB_VFS_OP_CONNECT, "connect" },
247 { SMB_VFS_OP_DISCONNECT, "disconnect" },
248 { SMB_VFS_OP_DISK_FREE, "disk_free" },
249 { SMB_VFS_OP_GET_QUOTA, "get_quota" },
250 { SMB_VFS_OP_SET_QUOTA, "set_quota" },
251 { SMB_VFS_OP_GET_SHADOW_COPY_DATA, "get_shadow_copy_data" },
252 { SMB_VFS_OP_STATVFS, "statvfs" },
253 { SMB_VFS_OP_FS_CAPABILITIES, "fs_capabilities" },
254 { SMB_VFS_OP_GET_DFS_REFERRALS, "get_dfs_referrals" },
255 { SMB_VFS_OP_CREATE_DFS_PATHAT, "create_dfs_pathat" },
256 { SMB_VFS_OP_READ_DFS_PATHAT, "read_dfs_pathat" },
257 { SMB_VFS_OP_FDOPENDIR, "fdopendir" },
258 { SMB_VFS_OP_READDIR, "readdir" },
259 { SMB_VFS_OP_SEEKDIR, "seekdir" },
260 { SMB_VFS_OP_TELLDIR, "telldir" },
261 { SMB_VFS_OP_REWINDDIR, "rewinddir" },
262 { SMB_VFS_OP_MKDIRAT, "mkdirat" },
263 { SMB_VFS_OP_CLOSEDIR, "closedir" },
264 { SMB_VFS_OP_OPEN, "open" },
265 { SMB_VFS_OP_OPENAT, "openat" },
266 { SMB_VFS_OP_CREATE_FILE, "create_file" },
267 { SMB_VFS_OP_CLOSE, "close" },
268 { SMB_VFS_OP_READ, "read" },
269 { SMB_VFS_OP_PREAD, "pread" },
270 { SMB_VFS_OP_PREAD_SEND, "pread_send" },
271 { SMB_VFS_OP_PREAD_RECV, "pread_recv" },
272 { SMB_VFS_OP_WRITE, "write" },
273 { SMB_VFS_OP_PWRITE, "pwrite" },
274 { SMB_VFS_OP_PWRITE_SEND, "pwrite_send" },
275 { SMB_VFS_OP_PWRITE_RECV, "pwrite_recv" },
276 { SMB_VFS_OP_LSEEK, "lseek" },
277 { SMB_VFS_OP_SENDFILE, "sendfile" },
278 { SMB_VFS_OP_RECVFILE, "recvfile" },
279 { SMB_VFS_OP_RENAMEAT, "renameat" },
280 { SMB_VFS_OP_FSYNC, "fsync" },
281 { SMB_VFS_OP_FSYNC_SEND, "fsync_send" },
282 { SMB_VFS_OP_FSYNC_RECV, "fsync_recv" },
283 { SMB_VFS_OP_STAT, "stat" },
284 { SMB_VFS_OP_FSTAT, "fstat" },
285 { SMB_VFS_OP_LSTAT, "lstat" },
286 { SMB_VFS_OP_GET_ALLOC_SIZE, "get_alloc_size" },
287 { SMB_VFS_OP_UNLINKAT, "unlinkat" },
288 { SMB_VFS_OP_CHMOD, "chmod" },
289 { SMB_VFS_OP_FCHMOD, "fchmod" },
290 { SMB_VFS_OP_FCHOWN, "fchown" },
291 { SMB_VFS_OP_LCHOWN, "lchown" },
292 { SMB_VFS_OP_CHDIR, "chdir" },
293 { SMB_VFS_OP_GETWD, "getwd" },
294 { SMB_VFS_OP_NTIMES, "ntimes" },
295 { SMB_VFS_OP_FTRUNCATE, "ftruncate" },
296 { SMB_VFS_OP_FALLOCATE,"fallocate" },
297 { SMB_VFS_OP_LOCK, "lock" },
298 { SMB_VFS_OP_KERNEL_FLOCK, "kernel_flock" },
299 { SMB_VFS_OP_FCNTL, "fcntl" },
300 { SMB_VFS_OP_LINUX_SETLEASE, "linux_setlease" },
301 { SMB_VFS_OP_GETLOCK, "getlock" },
302 { SMB_VFS_OP_SYMLINKAT, "symlinkat" },
303 { SMB_VFS_OP_READLINKAT,"readlinkat" },
304 { SMB_VFS_OP_LINKAT, "linkat" },
305 { SMB_VFS_OP_MKNODAT, "mknodat" },
306 { SMB_VFS_OP_REALPATH, "realpath" },
307 { SMB_VFS_OP_CHFLAGS, "chflags" },
308 { SMB_VFS_OP_FILE_ID_CREATE, "file_id_create" },
309 { SMB_VFS_OP_FS_FILE_ID, "fs_file_id" },
310 { SMB_VFS_OP_STREAMINFO, "streaminfo" },
311 { SMB_VFS_OP_GET_REAL_FILENAME, "get_real_filename" },
312 { SMB_VFS_OP_CONNECTPATH, "connectpath" },
313 { SMB_VFS_OP_BRL_LOCK_WINDOWS, "brl_lock_windows" },
314 { SMB_VFS_OP_BRL_UNLOCK_WINDOWS, "brl_unlock_windows" },
315 { SMB_VFS_OP_STRICT_LOCK_CHECK, "strict_lock_check" },
316 { SMB_VFS_OP_TRANSLATE_NAME, "translate_name" },
317 { SMB_VFS_OP_FSCTL, "fsctl" },
318 { SMB_VFS_OP_OFFLOAD_READ_SEND, "offload_read_send" },
319 { SMB_VFS_OP_OFFLOAD_READ_RECV, "offload_read_recv" },
320 { SMB_VFS_OP_OFFLOAD_WRITE_SEND, "offload_write_send" },
321 { SMB_VFS_OP_OFFLOAD_WRITE_RECV, "offload_write_recv" },
322 { SMB_VFS_OP_GET_COMPRESSION, "get_compression" },
323 { SMB_VFS_OP_SET_COMPRESSION, "set_compression" },
324 { SMB_VFS_OP_SNAP_CHECK_PATH, "snap_check_path" },
325 { SMB_VFS_OP_SNAP_CREATE, "snap_create" },
326 { SMB_VFS_OP_SNAP_DELETE, "snap_delete" },
327 { SMB_VFS_OP_GET_DOS_ATTRIBUTES, "get_dos_attributes" },
328 { SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND, "get_dos_attributes_send" },
329 { SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV, "get_dos_attributes_recv" },
330 { SMB_VFS_OP_FGET_DOS_ATTRIBUTES, "fget_dos_attributes" },
331 { SMB_VFS_OP_SET_DOS_ATTRIBUTES, "set_dos_attributes" },
332 { SMB_VFS_OP_FSET_DOS_ATTRIBUTES, "fset_dos_attributes" },
333 { SMB_VFS_OP_FGET_NT_ACL, "fget_nt_acl" },
334 { SMB_VFS_OP_GET_NT_ACL_AT, "get_nt_acl_at" },
335 { SMB_VFS_OP_FSET_NT_ACL, "fset_nt_acl" },
336 { SMB_VFS_OP_AUDIT_FILE, "audit_file" },
337 { SMB_VFS_OP_SYS_ACL_GET_FILE, "sys_acl_get_file" },
338 { SMB_VFS_OP_SYS_ACL_GET_FD, "sys_acl_get_fd" },
339 { SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE, "sys_acl_blob_get_file" },
340 { SMB_VFS_OP_SYS_ACL_BLOB_GET_FD, "sys_acl_blob_get_fd" },
341 { SMB_VFS_OP_SYS_ACL_SET_FILE, "sys_acl_set_file" },
342 { SMB_VFS_OP_SYS_ACL_SET_FD, "sys_acl_set_fd" },
343 { SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE, "sys_acl_delete_def_file" },
344 { SMB_VFS_OP_GETXATTR, "getxattr" },
345 { SMB_VFS_OP_GETXATTRAT_SEND, "getxattrat_send" },
346 { SMB_VFS_OP_GETXATTRAT_RECV, "getxattrat_recv" },
347 { SMB_VFS_OP_FGETXATTR, "fgetxattr" },
348 { SMB_VFS_OP_LISTXATTR, "listxattr" },
349 { SMB_VFS_OP_FLISTXATTR, "flistxattr" },
350 { SMB_VFS_OP_REMOVEXATTR, "removexattr" },
351 { SMB_VFS_OP_FREMOVEXATTR, "fremovexattr" },
352 { SMB_VFS_OP_SETXATTR, "setxattr" },
353 { SMB_VFS_OP_FSETXATTR, "fsetxattr" },
354 { SMB_VFS_OP_AIO_FORCE, "aio_force" },
355 { SMB_VFS_OP_IS_OFFLINE, "is_offline" },
356 { SMB_VFS_OP_SET_OFFLINE, "set_offline" },
357 { SMB_VFS_OP_DURABLE_COOKIE, "durable_cookie" },
358 { SMB_VFS_OP_DURABLE_DISCONNECT, "durable_disconnect" },
359 { SMB_VFS_OP_DURABLE_RECONNECT, "durable_reconnect" },
360 { SMB_VFS_OP_READDIR_ATTR, "readdir_attr" },
361 { SMB_VFS_OP_LAST, NULL }
364 static int audit_syslog_facility(vfs_handle_struct *handle)
366 static const struct enum_list enum_log_facilities[] = {
368 { LOG_AUTH, "AUTH" },
371 { LOG_AUTHPRIV, "AUTHPRIV" },
374 { LOG_AUDIT, "AUDIT" },
377 { LOG_CONSOLE, "CONSOLE" },
380 { LOG_CRON, "CRON" },
383 { LOG_DAEMON, "DAEMON" },
389 { LOG_INSTALL, "INSTALL" },
392 { LOG_KERN, "KERN" },
395 { LOG_LAUNCHD, "LAUNCHD" },
398 { LOG_LFMT, "LFMT" },
404 { LOG_MAIL, "MAIL" },
407 { LOG_MEGASAFE, "MEGASAFE" },
410 { LOG_NETINFO, "NETINFO" },
413 { LOG_NEWS, "NEWS" },
415 #ifdef LOG_NFACILITIES
416 { LOG_NFACILITIES, "NFACILITIES" },
424 #ifdef LOG_REMOTEAUTH
425 { LOG_REMOTEAUTH, "REMOTEAUTH" },
428 { LOG_SECURITY, "SECURITY" },
431 { LOG_SYSLOG, "SYSLOG" },
434 { LOG_USER, "USER" },
437 { LOG_UUCP, "UUCP" },
439 { LOG_LOCAL0, "LOCAL0" },
440 { LOG_LOCAL1, "LOCAL1" },
441 { LOG_LOCAL2, "LOCAL2" },
442 { LOG_LOCAL3, "LOCAL3" },
443 { LOG_LOCAL4, "LOCAL4" },
444 { LOG_LOCAL5, "LOCAL5" },
445 { LOG_LOCAL6, "LOCAL6" },
446 { LOG_LOCAL7, "LOCAL7" },
452 facility = lp_parm_enum(SNUM(handle->conn), "full_audit", "facility", enum_log_facilities, LOG_USER);
457 static int audit_syslog_priority(vfs_handle_struct *handle)
459 static const struct enum_list enum_log_priorities[] = {
460 { LOG_EMERG, "EMERG" },
461 { LOG_ALERT, "ALERT" },
462 { LOG_CRIT, "CRIT" },
464 { LOG_WARNING, "WARNING" },
465 { LOG_NOTICE, "NOTICE" },
466 { LOG_INFO, "INFO" },
467 { LOG_DEBUG, "DEBUG" },
473 priority = lp_parm_enum(SNUM(handle->conn), "full_audit", "priority",
474 enum_log_priorities, LOG_NOTICE);
475 if (priority == -1) {
476 priority = LOG_WARNING;
482 static char *audit_prefix(TALLOC_CTX *ctx, connection_struct *conn)
484 const struct loadparm_substitution *lp_sub =
485 loadparm_s3_global_substitution();
489 prefix = talloc_strdup(ctx,
490 lp_parm_const_string(SNUM(conn), "full_audit",
495 result = talloc_sub_full(ctx,
496 lp_servicename(talloc_tos(), lp_sub, SNUM(conn)),
497 conn->session_info->unix_info->unix_name,
499 conn->session_info->unix_token->gid,
500 conn->session_info->unix_info->sanitized_username,
501 conn->session_info->info->domain_name,
507 static bool log_success(struct vfs_full_audit_private_data *pd, vfs_op_type op)
509 if (pd->success_ops == NULL) {
513 return bitmap_query(pd->success_ops, op);
516 static bool log_failure(struct vfs_full_audit_private_data *pd, vfs_op_type op)
518 if (pd->failure_ops == NULL)
521 return bitmap_query(pd->failure_ops, op);
524 static struct bitmap *init_bitmap(TALLOC_CTX *mem_ctx, const char **ops)
532 bm = bitmap_talloc(mem_ctx, SMB_VFS_OP_LAST);
534 DEBUG(0, ("Could not alloc bitmap -- "
535 "defaulting to logging everything\n"));
539 for (; *ops != NULL; ops += 1) {
544 if (strequal(*ops, "all")) {
545 for (i=0; i<SMB_VFS_OP_LAST; i++) {
551 if (strequal(*ops, "none")) {
561 for (i=0; i<SMB_VFS_OP_LAST; i++) {
562 if ((vfs_op_names[i].name == NULL)
563 || (vfs_op_names[i].type != i)) {
564 smb_panic("vfs_full_audit.c: name table not "
565 "in sync with vfs_op_type enums\n");
567 if (strequal(op, vfs_op_names[i].name)) {
576 if (i == SMB_VFS_OP_LAST) {
577 DEBUG(0, ("Could not find opname %s, logging all\n",
586 static const char *audit_opname(vfs_op_type op)
588 if (op >= SMB_VFS_OP_LAST)
589 return "INVALID VFS OP";
590 return vfs_op_names[op].name;
593 static TALLOC_CTX *tmp_do_log_ctx;
595 * Get us a temporary talloc context usable just for DEBUG arguments
597 static TALLOC_CTX *do_log_ctx(void)
599 if (tmp_do_log_ctx == NULL) {
600 tmp_do_log_ctx = talloc_named_const(NULL, 0, "do_log_ctx");
602 return tmp_do_log_ctx;
605 static void do_log(vfs_op_type op, bool success, vfs_handle_struct *handle,
606 const char *format, ...) PRINTF_ATTRIBUTE(4, 5);
608 static void do_log(vfs_op_type op, bool success, vfs_handle_struct *handle,
609 const char *format, ...)
611 struct vfs_full_audit_private_data *pd;
613 char *audit_pre = NULL;
617 SMB_VFS_HANDLE_GET_DATA(handle, pd,
618 struct vfs_full_audit_private_data,
621 if (success && (!log_success(pd, op)))
624 if (!success && (!log_failure(pd, op)))
628 fstrcpy(err_msg, "ok");
630 fstr_sprintf(err_msg, "fail (%s)", strerror(errno));
632 va_start(ap, format);
633 op_msg = talloc_vasprintf(talloc_tos(), format, ap);
640 audit_pre = audit_prefix(talloc_tos(), handle->conn);
646 * Specify the facility to interoperate with other syslog
647 * callers (smbd for example).
649 priority = pd->syslog_priority | pd->syslog_facility;
651 syslog(priority, "%s|%s|%s|%s\n",
652 audit_pre ? audit_pre : "",
653 audit_opname(op), err_msg, op_msg);
655 DEBUG(1, ("%s|%s|%s|%s\n",
656 audit_pre ? audit_pre : "",
657 audit_opname(op), err_msg, op_msg));
660 TALLOC_FREE(audit_pre);
662 TALLOC_FREE(tmp_do_log_ctx);
666 * Return a string using the do_log_ctx()
668 static const char *smb_fname_str_do_log(struct connection_struct *conn,
669 const struct smb_filename *smb_fname)
674 if (smb_fname == NULL) {
678 if (smb_fname->base_name[0] != '/') {
679 char *abs_name = NULL;
680 struct smb_filename *fname_copy = cp_smb_filename(
683 if (fname_copy == NULL) {
687 if (!ISDOT(smb_fname->base_name)) {
688 abs_name = talloc_asprintf(do_log_ctx(),
690 conn->cwd_fsp->fsp_name->base_name,
691 smb_fname->base_name);
693 abs_name = talloc_strdup(do_log_ctx(),
694 conn->cwd_fsp->fsp_name->base_name);
696 if (abs_name == NULL) {
699 fname_copy->base_name = abs_name;
700 smb_fname = fname_copy;
703 status = get_full_smb_filename(do_log_ctx(), smb_fname, &fname);
704 if (!NT_STATUS_IS_OK(status)) {
711 * Return an fsp debug string using the do_log_ctx()
713 static const char *fsp_str_do_log(const struct files_struct *fsp)
715 return smb_fname_str_do_log(fsp->conn, fsp->fsp_name);
718 /* Implementation of vfs_ops. Pass everything on to the default
719 operation but log event first. */
721 static int smb_full_audit_connect(vfs_handle_struct *handle,
722 const char *svc, const char *user)
725 const char *none[] = { "none" };
726 struct vfs_full_audit_private_data *pd = NULL;
728 result = SMB_VFS_NEXT_CONNECT(handle, svc, user);
733 pd = talloc_zero(handle, struct vfs_full_audit_private_data);
735 SMB_VFS_NEXT_DISCONNECT(handle);
739 pd->syslog_facility = audit_syslog_facility(handle);
740 if (pd->syslog_facility == -1) {
741 DEBUG(1, ("%s: Unknown facility %s\n", __func__,
742 lp_parm_const_string(SNUM(handle->conn),
743 "full_audit", "facility",
745 SMB_VFS_NEXT_DISCONNECT(handle);
749 pd->syslog_priority = audit_syslog_priority(handle);
751 pd->log_secdesc = lp_parm_bool(SNUM(handle->conn),
752 "full_audit", "log_secdesc", false);
754 pd->do_syslog = lp_parm_bool(SNUM(handle->conn),
755 "full_audit", "syslog", true);
759 openlog("smbd_audit", 0, pd->syslog_facility);
763 pd->success_ops = init_bitmap(
764 pd, lp_parm_string_list(SNUM(handle->conn), "full_audit",
766 pd->failure_ops = init_bitmap(
767 pd, lp_parm_string_list(SNUM(handle->conn), "full_audit",
770 /* Store the private data. */
771 SMB_VFS_HANDLE_SET_DATA(handle, pd, NULL,
772 struct vfs_full_audit_private_data, return -1);
774 do_log(SMB_VFS_OP_CONNECT, True, handle,
780 static void smb_full_audit_disconnect(vfs_handle_struct *handle)
782 const struct loadparm_substitution *lp_sub =
783 loadparm_s3_global_substitution();
785 SMB_VFS_NEXT_DISCONNECT(handle);
787 do_log(SMB_VFS_OP_DISCONNECT, True, handle,
788 "%s", lp_servicename(talloc_tos(), lp_sub, SNUM(handle->conn)));
790 /* The bitmaps will be disconnected when the private
794 static uint64_t smb_full_audit_disk_free(vfs_handle_struct *handle,
795 const struct smb_filename *smb_fname,
802 result = SMB_VFS_NEXT_DISK_FREE(handle, smb_fname, bsize, dfree, dsize);
804 /* Don't have a reasonable notion of failure here */
806 do_log(SMB_VFS_OP_DISK_FREE,
810 smb_fname_str_do_log(handle->conn, smb_fname));
815 static int smb_full_audit_get_quota(struct vfs_handle_struct *handle,
816 const struct smb_filename *smb_fname,
817 enum SMB_QUOTA_TYPE qtype,
823 result = SMB_VFS_NEXT_GET_QUOTA(handle, smb_fname, qtype, id, qt);
825 do_log(SMB_VFS_OP_GET_QUOTA,
829 smb_fname_str_do_log(handle->conn, smb_fname));
834 static int smb_full_audit_set_quota(struct vfs_handle_struct *handle,
835 enum SMB_QUOTA_TYPE qtype, unid_t id,
840 result = SMB_VFS_NEXT_SET_QUOTA(handle, qtype, id, qt);
842 do_log(SMB_VFS_OP_SET_QUOTA, (result >= 0), handle, "");
847 static int smb_full_audit_get_shadow_copy_data(struct vfs_handle_struct *handle,
848 struct files_struct *fsp,
849 struct shadow_copy_data *shadow_copy_data,
854 result = SMB_VFS_NEXT_GET_SHADOW_COPY_DATA(handle, fsp, shadow_copy_data, labels);
856 do_log(SMB_VFS_OP_GET_SHADOW_COPY_DATA, (result >= 0), handle, "");
861 static int smb_full_audit_statvfs(struct vfs_handle_struct *handle,
862 const struct smb_filename *smb_fname,
863 struct vfs_statvfs_struct *statbuf)
867 result = SMB_VFS_NEXT_STATVFS(handle, smb_fname, statbuf);
869 do_log(SMB_VFS_OP_STATVFS, (result >= 0), handle, "");
874 static uint32_t smb_full_audit_fs_capabilities(struct vfs_handle_struct *handle, enum timestamp_set_resolution *p_ts_res)
878 result = SMB_VFS_NEXT_FS_CAPABILITIES(handle, p_ts_res);
880 do_log(SMB_VFS_OP_FS_CAPABILITIES, true, handle, "");
885 static NTSTATUS smb_full_audit_get_dfs_referrals(
886 struct vfs_handle_struct *handle,
887 struct dfs_GetDFSReferral *r)
891 status = SMB_VFS_NEXT_GET_DFS_REFERRALS(handle, r);
893 do_log(SMB_VFS_OP_GET_DFS_REFERRALS, NT_STATUS_IS_OK(status),
899 static NTSTATUS smb_full_audit_create_dfs_pathat(struct vfs_handle_struct *handle,
900 struct files_struct *dirfsp,
901 const struct smb_filename *smb_fname,
902 const struct referral *reflist,
903 size_t referral_count)
907 status = SMB_VFS_NEXT_CREATE_DFS_PATHAT(handle,
913 do_log(SMB_VFS_OP_CREATE_DFS_PATHAT,
914 NT_STATUS_IS_OK(status),
917 smb_fname_str_do_log(handle->conn, smb_fname));
922 static NTSTATUS smb_full_audit_read_dfs_pathat(struct vfs_handle_struct *handle,
924 struct files_struct *dirfsp,
925 struct smb_filename *smb_fname,
926 struct referral **ppreflist,
927 size_t *preferral_count)
931 status = SMB_VFS_NEXT_READ_DFS_PATHAT(handle,
938 do_log(SMB_VFS_OP_READ_DFS_PATHAT,
939 NT_STATUS_IS_OK(status),
942 smb_fname_str_do_log(handle->conn, smb_fname));
947 static NTSTATUS smb_full_audit_snap_check_path(struct vfs_handle_struct *handle,
949 const char *service_path,
954 status = SMB_VFS_NEXT_SNAP_CHECK_PATH(handle, mem_ctx, service_path,
956 do_log(SMB_VFS_OP_SNAP_CHECK_PATH, NT_STATUS_IS_OK(status),
962 static NTSTATUS smb_full_audit_snap_create(struct vfs_handle_struct *handle,
964 const char *base_volume,
972 status = SMB_VFS_NEXT_SNAP_CREATE(handle, mem_ctx, base_volume, tstamp,
973 rw, base_path, snap_path);
974 do_log(SMB_VFS_OP_SNAP_CREATE, NT_STATUS_IS_OK(status), handle, "");
979 static NTSTATUS smb_full_audit_snap_delete(struct vfs_handle_struct *handle,
986 status = SMB_VFS_NEXT_SNAP_DELETE(handle, mem_ctx, base_path,
988 do_log(SMB_VFS_OP_SNAP_DELETE, NT_STATUS_IS_OK(status), handle, "");
993 static DIR *smb_full_audit_fdopendir(vfs_handle_struct *handle,
994 files_struct *fsp, const char *mask, uint32_t attr)
998 result = SMB_VFS_NEXT_FDOPENDIR(handle, fsp, mask, attr);
1000 do_log(SMB_VFS_OP_FDOPENDIR, (result != NULL), handle, "%s",
1001 fsp_str_do_log(fsp));
1006 static struct dirent *smb_full_audit_readdir(vfs_handle_struct *handle,
1007 DIR *dirp, SMB_STRUCT_STAT *sbuf)
1009 struct dirent *result;
1011 result = SMB_VFS_NEXT_READDIR(handle, 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 files_struct **dirfsp,
1103 struct smb_filename *smb_fname,
1104 uint32_t access_mask,
1105 uint32_t share_access,
1106 uint32_t create_disposition,
1107 uint32_t create_options,
1108 uint32_t file_attributes,
1109 uint32_t oplock_request,
1110 const struct smb2_lease *lease,
1111 uint64_t allocation_size,
1112 uint32_t private_flags,
1113 struct security_descriptor *sd,
1114 struct ea_list *ea_list,
1115 files_struct **result_fsp,
1117 const struct smb2_create_blobs *in_context_blobs,
1118 struct smb2_create_blobs *out_context_blobs)
1121 const char* str_create_disposition;
1123 switch (create_disposition) {
1124 case FILE_SUPERSEDE:
1125 str_create_disposition = "supersede";
1127 case FILE_OVERWRITE_IF:
1128 str_create_disposition = "overwrite_if";
1131 str_create_disposition = "open";
1133 case FILE_OVERWRITE:
1134 str_create_disposition = "overwrite";
1137 str_create_disposition = "create";
1140 str_create_disposition = "open_if";
1143 str_create_disposition = "unknown";
1146 result = SMB_VFS_NEXT_CREATE_FILE(
1147 handle, /* handle */
1150 smb_fname, /* fname */
1151 access_mask, /* access_mask */
1152 share_access, /* share_access */
1153 create_disposition, /* create_disposition*/
1154 create_options, /* create_options */
1155 file_attributes, /* file_attributes */
1156 oplock_request, /* oplock_request */
1158 allocation_size, /* allocation_size */
1161 ea_list, /* ea_list */
1162 result_fsp, /* result */
1164 in_context_blobs, out_context_blobs); /* create context */
1166 do_log(SMB_VFS_OP_CREATE_FILE, (NT_STATUS_IS_OK(result)), handle,
1167 "0x%x|%s|%s|%s", access_mask,
1168 create_options & FILE_DIRECTORY_FILE ? "dir" : "file",
1169 str_create_disposition,
1170 smb_fname_str_do_log(handle->conn, smb_fname));
1175 static int smb_full_audit_close(vfs_handle_struct *handle, files_struct *fsp)
1179 result = SMB_VFS_NEXT_CLOSE(handle, fsp);
1181 do_log(SMB_VFS_OP_CLOSE, (result >= 0), handle, "%s",
1182 fsp_str_do_log(fsp));
1187 static ssize_t smb_full_audit_pread(vfs_handle_struct *handle, files_struct *fsp,
1188 void *data, size_t n, off_t offset)
1192 result = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
1194 do_log(SMB_VFS_OP_PREAD, (result >= 0), handle, "%s",
1195 fsp_str_do_log(fsp));
1200 struct smb_full_audit_pread_state {
1201 vfs_handle_struct *handle;
1204 struct vfs_aio_state vfs_aio_state;
1207 static void smb_full_audit_pread_done(struct tevent_req *subreq);
1209 static struct tevent_req *smb_full_audit_pread_send(
1210 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1211 struct tevent_context *ev, struct files_struct *fsp,
1212 void *data, size_t n, off_t offset)
1214 struct tevent_req *req, *subreq;
1215 struct smb_full_audit_pread_state *state;
1217 req = tevent_req_create(mem_ctx, &state,
1218 struct smb_full_audit_pread_state);
1220 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
1221 fsp_str_do_log(fsp));
1224 state->handle = handle;
1227 subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
1229 if (tevent_req_nomem(subreq, req)) {
1230 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
1231 fsp_str_do_log(fsp));
1232 return tevent_req_post(req, ev);
1234 tevent_req_set_callback(subreq, smb_full_audit_pread_done, req);
1236 do_log(SMB_VFS_OP_PREAD_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1240 static void smb_full_audit_pread_done(struct tevent_req *subreq)
1242 struct tevent_req *req = tevent_req_callback_data(
1243 subreq, struct tevent_req);
1244 struct smb_full_audit_pread_state *state = tevent_req_data(
1245 req, struct smb_full_audit_pread_state);
1247 state->ret = SMB_VFS_PREAD_RECV(subreq, &state->vfs_aio_state);
1248 TALLOC_FREE(subreq);
1249 tevent_req_done(req);
1252 static ssize_t smb_full_audit_pread_recv(struct tevent_req *req,
1253 struct vfs_aio_state *vfs_aio_state)
1255 struct smb_full_audit_pread_state *state = tevent_req_data(
1256 req, struct smb_full_audit_pread_state);
1258 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1259 do_log(SMB_VFS_OP_PREAD_RECV, false, state->handle, "%s",
1260 fsp_str_do_log(state->fsp));
1264 do_log(SMB_VFS_OP_PREAD_RECV, (state->ret >= 0), state->handle, "%s",
1265 fsp_str_do_log(state->fsp));
1267 *vfs_aio_state = state->vfs_aio_state;
1271 static ssize_t smb_full_audit_pwrite(vfs_handle_struct *handle, files_struct *fsp,
1272 const void *data, size_t n,
1277 result = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
1279 do_log(SMB_VFS_OP_PWRITE, (result >= 0), handle, "%s",
1280 fsp_str_do_log(fsp));
1285 struct smb_full_audit_pwrite_state {
1286 vfs_handle_struct *handle;
1289 struct vfs_aio_state vfs_aio_state;
1292 static void smb_full_audit_pwrite_done(struct tevent_req *subreq);
1294 static struct tevent_req *smb_full_audit_pwrite_send(
1295 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1296 struct tevent_context *ev, struct files_struct *fsp,
1297 const void *data, size_t n, off_t offset)
1299 struct tevent_req *req, *subreq;
1300 struct smb_full_audit_pwrite_state *state;
1302 req = tevent_req_create(mem_ctx, &state,
1303 struct smb_full_audit_pwrite_state);
1305 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1306 fsp_str_do_log(fsp));
1309 state->handle = handle;
1312 subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
1314 if (tevent_req_nomem(subreq, req)) {
1315 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1316 fsp_str_do_log(fsp));
1317 return tevent_req_post(req, ev);
1319 tevent_req_set_callback(subreq, smb_full_audit_pwrite_done, req);
1321 do_log(SMB_VFS_OP_PWRITE_SEND, true, handle, "%s",
1322 fsp_str_do_log(fsp));
1326 static void smb_full_audit_pwrite_done(struct tevent_req *subreq)
1328 struct tevent_req *req = tevent_req_callback_data(
1329 subreq, struct tevent_req);
1330 struct smb_full_audit_pwrite_state *state = tevent_req_data(
1331 req, struct smb_full_audit_pwrite_state);
1333 state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->vfs_aio_state);
1334 TALLOC_FREE(subreq);
1335 tevent_req_done(req);
1338 static ssize_t smb_full_audit_pwrite_recv(struct tevent_req *req,
1339 struct vfs_aio_state *vfs_aio_state)
1341 struct smb_full_audit_pwrite_state *state = tevent_req_data(
1342 req, struct smb_full_audit_pwrite_state);
1344 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1345 do_log(SMB_VFS_OP_PWRITE_RECV, false, state->handle, "%s",
1346 fsp_str_do_log(state->fsp));
1350 do_log(SMB_VFS_OP_PWRITE_RECV, (state->ret >= 0), state->handle, "%s",
1351 fsp_str_do_log(state->fsp));
1353 *vfs_aio_state = state->vfs_aio_state;
1357 static off_t smb_full_audit_lseek(vfs_handle_struct *handle, files_struct *fsp,
1358 off_t offset, int whence)
1362 result = SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence);
1364 do_log(SMB_VFS_OP_LSEEK, (result != (ssize_t)-1), handle,
1365 "%s", fsp_str_do_log(fsp));
1370 static ssize_t smb_full_audit_sendfile(vfs_handle_struct *handle, int tofd,
1371 files_struct *fromfsp,
1372 const DATA_BLOB *hdr, off_t offset,
1377 result = SMB_VFS_NEXT_SENDFILE(handle, tofd, fromfsp, hdr, offset, n);
1379 do_log(SMB_VFS_OP_SENDFILE, (result >= 0), handle,
1380 "%s", fsp_str_do_log(fromfsp));
1385 static ssize_t smb_full_audit_recvfile(vfs_handle_struct *handle, int fromfd,
1386 files_struct *tofsp,
1392 result = SMB_VFS_NEXT_RECVFILE(handle, fromfd, tofsp, offset, n);
1394 do_log(SMB_VFS_OP_RECVFILE, (result >= 0), handle,
1395 "%s", fsp_str_do_log(tofsp));
1400 static int smb_full_audit_renameat(vfs_handle_struct *handle,
1401 files_struct *srcfsp,
1402 const struct smb_filename *smb_fname_src,
1403 files_struct *dstfsp,
1404 const struct smb_filename *smb_fname_dst)
1408 result = SMB_VFS_NEXT_RENAMEAT(handle,
1414 do_log(SMB_VFS_OP_RENAMEAT, (result >= 0), handle, "%s|%s",
1415 smb_fname_str_do_log(handle->conn, smb_fname_src),
1416 smb_fname_str_do_log(handle->conn, smb_fname_dst));
1421 struct smb_full_audit_fsync_state {
1422 vfs_handle_struct *handle;
1425 struct vfs_aio_state vfs_aio_state;
1428 static void smb_full_audit_fsync_done(struct tevent_req *subreq);
1430 static struct tevent_req *smb_full_audit_fsync_send(
1431 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1432 struct tevent_context *ev, struct files_struct *fsp)
1434 struct tevent_req *req, *subreq;
1435 struct smb_full_audit_fsync_state *state;
1437 req = tevent_req_create(mem_ctx, &state,
1438 struct smb_full_audit_fsync_state);
1440 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1441 fsp_str_do_log(fsp));
1444 state->handle = handle;
1447 subreq = SMB_VFS_NEXT_FSYNC_SEND(state, ev, handle, fsp);
1448 if (tevent_req_nomem(subreq, req)) {
1449 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1450 fsp_str_do_log(fsp));
1451 return tevent_req_post(req, ev);
1453 tevent_req_set_callback(subreq, smb_full_audit_fsync_done, req);
1455 do_log(SMB_VFS_OP_FSYNC_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1459 static void smb_full_audit_fsync_done(struct tevent_req *subreq)
1461 struct tevent_req *req = tevent_req_callback_data(
1462 subreq, struct tevent_req);
1463 struct smb_full_audit_fsync_state *state = tevent_req_data(
1464 req, struct smb_full_audit_fsync_state);
1466 state->ret = SMB_VFS_FSYNC_RECV(subreq, &state->vfs_aio_state);
1467 TALLOC_FREE(subreq);
1468 tevent_req_done(req);
1471 static int smb_full_audit_fsync_recv(struct tevent_req *req,
1472 struct vfs_aio_state *vfs_aio_state)
1474 struct smb_full_audit_fsync_state *state = tevent_req_data(
1475 req, struct smb_full_audit_fsync_state);
1477 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1478 do_log(SMB_VFS_OP_FSYNC_RECV, false, state->handle, "%s",
1479 fsp_str_do_log(state->fsp));
1483 do_log(SMB_VFS_OP_FSYNC_RECV, (state->ret >= 0), state->handle, "%s",
1484 fsp_str_do_log(state->fsp));
1486 *vfs_aio_state = state->vfs_aio_state;
1490 static int smb_full_audit_stat(vfs_handle_struct *handle,
1491 struct smb_filename *smb_fname)
1495 result = SMB_VFS_NEXT_STAT(handle, smb_fname);
1497 do_log(SMB_VFS_OP_STAT, (result >= 0), handle, "%s",
1498 smb_fname_str_do_log(handle->conn, smb_fname));
1503 static int smb_full_audit_fstat(vfs_handle_struct *handle, files_struct *fsp,
1504 SMB_STRUCT_STAT *sbuf)
1508 result = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1510 do_log(SMB_VFS_OP_FSTAT, (result >= 0), handle, "%s",
1511 fsp_str_do_log(fsp));
1516 static int smb_full_audit_lstat(vfs_handle_struct *handle,
1517 struct smb_filename *smb_fname)
1521 result = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
1523 do_log(SMB_VFS_OP_LSTAT, (result >= 0), handle, "%s",
1524 smb_fname_str_do_log(handle->conn, smb_fname));
1529 static uint64_t smb_full_audit_get_alloc_size(vfs_handle_struct *handle,
1530 files_struct *fsp, const SMB_STRUCT_STAT *sbuf)
1534 result = SMB_VFS_NEXT_GET_ALLOC_SIZE(handle, fsp, sbuf);
1536 do_log(SMB_VFS_OP_GET_ALLOC_SIZE, (result != (uint64_t)-1), handle,
1537 "%llu", (unsigned long long)result);
1542 static int smb_full_audit_unlinkat(vfs_handle_struct *handle,
1543 struct files_struct *dirfsp,
1544 const struct smb_filename *smb_fname,
1549 result = SMB_VFS_NEXT_UNLINKAT(handle,
1554 do_log(SMB_VFS_OP_UNLINKAT, (result >= 0), handle, "%s",
1555 smb_fname_str_do_log(handle->conn, smb_fname));
1560 static int smb_full_audit_chmod(vfs_handle_struct *handle,
1561 const struct smb_filename *smb_fname,
1566 result = SMB_VFS_NEXT_CHMOD(handle, smb_fname, mode);
1568 do_log(SMB_VFS_OP_CHMOD,
1572 smb_fname_str_do_log(handle->conn, smb_fname),
1578 static int smb_full_audit_fchmod(vfs_handle_struct *handle, files_struct *fsp,
1583 result = SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1585 do_log(SMB_VFS_OP_FCHMOD, (result >= 0), handle,
1586 "%s|%o", fsp_str_do_log(fsp), mode);
1591 static int smb_full_audit_fchown(vfs_handle_struct *handle, files_struct *fsp,
1592 uid_t uid, gid_t gid)
1596 result = SMB_VFS_NEXT_FCHOWN(handle, fsp, uid, gid);
1598 do_log(SMB_VFS_OP_FCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1599 fsp_str_do_log(fsp), (long int)uid, (long int)gid);
1604 static int smb_full_audit_lchown(vfs_handle_struct *handle,
1605 const struct smb_filename *smb_fname,
1611 result = SMB_VFS_NEXT_LCHOWN(handle, smb_fname, uid, gid);
1613 do_log(SMB_VFS_OP_LCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1614 smb_fname->base_name, (long int)uid, (long int)gid);
1619 static int smb_full_audit_chdir(vfs_handle_struct *handle,
1620 const struct smb_filename *smb_fname)
1624 result = SMB_VFS_NEXT_CHDIR(handle, smb_fname);
1626 do_log(SMB_VFS_OP_CHDIR,
1630 smb_fname_str_do_log(handle->conn, smb_fname));
1635 static struct smb_filename *smb_full_audit_getwd(vfs_handle_struct *handle,
1638 struct smb_filename *result;
1640 result = SMB_VFS_NEXT_GETWD(handle, ctx);
1642 do_log(SMB_VFS_OP_GETWD, (result != NULL), handle, "%s",
1643 result == NULL? "" : result->base_name);
1648 static int smb_full_audit_ntimes(vfs_handle_struct *handle,
1649 const struct smb_filename *smb_fname,
1650 struct smb_file_time *ft)
1653 time_t create_time = convert_timespec_to_time_t(ft->create_time);
1654 time_t atime = convert_timespec_to_time_t(ft->atime);
1655 time_t mtime = convert_timespec_to_time_t(ft->mtime);
1656 time_t ctime = convert_timespec_to_time_t(ft->ctime);
1657 const char *create_time_str = "";
1658 const char *atime_str = "";
1659 const char *mtime_str = "";
1660 const char *ctime_str = "";
1661 TALLOC_CTX *frame = talloc_stackframe();
1663 result = SMB_VFS_NEXT_NTIMES(handle, smb_fname, ft);
1665 if (create_time > 0) {
1666 create_time_str = timestring(frame, create_time);
1669 atime_str = timestring(frame, atime);
1672 mtime_str = timestring(frame, mtime);
1675 ctime_str = timestring(frame, ctime);
1678 do_log(SMB_VFS_OP_NTIMES,
1682 smb_fname_str_do_log(handle->conn, smb_fname),
1693 static int smb_full_audit_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
1698 result = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1700 do_log(SMB_VFS_OP_FTRUNCATE, (result >= 0), handle,
1701 "%s", fsp_str_do_log(fsp));
1706 static int smb_full_audit_fallocate(vfs_handle_struct *handle, files_struct *fsp,
1713 result = SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
1715 do_log(SMB_VFS_OP_FALLOCATE, (result >= 0), handle,
1716 "%s", fsp_str_do_log(fsp));
1721 static bool smb_full_audit_lock(vfs_handle_struct *handle, files_struct *fsp,
1722 int op, off_t offset, off_t count, int type)
1726 result = SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type);
1728 do_log(SMB_VFS_OP_LOCK, result, handle, "%s", fsp_str_do_log(fsp));
1733 static int smb_full_audit_kernel_flock(struct vfs_handle_struct *handle,
1734 struct files_struct *fsp,
1735 uint32_t share_access,
1736 uint32_t access_mask)
1740 result = SMB_VFS_NEXT_KERNEL_FLOCK(handle,
1745 do_log(SMB_VFS_OP_KERNEL_FLOCK, (result >= 0), handle, "%s",
1746 fsp_str_do_log(fsp));
1751 static int smb_full_audit_fcntl(struct vfs_handle_struct *handle,
1752 struct files_struct *fsp,
1753 int cmd, va_list cmd_arg)
1756 va_list dup_cmd_arg;
1759 va_copy(dup_cmd_arg, cmd_arg);
1760 arg = va_arg(dup_cmd_arg, void *);
1761 result = SMB_VFS_NEXT_FCNTL(handle, fsp, cmd, arg);
1762 va_end(dup_cmd_arg);
1764 do_log(SMB_VFS_OP_FCNTL, (result >= 0), handle, "%s",
1765 fsp_str_do_log(fsp));
1770 static int smb_full_audit_linux_setlease(vfs_handle_struct *handle, files_struct *fsp,
1775 result = SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
1777 do_log(SMB_VFS_OP_LINUX_SETLEASE, (result >= 0), handle, "%s",
1778 fsp_str_do_log(fsp));
1783 static bool smb_full_audit_getlock(vfs_handle_struct *handle, files_struct *fsp,
1784 off_t *poffset, off_t *pcount, int *ptype, pid_t *ppid)
1788 result = SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype, ppid);
1790 do_log(SMB_VFS_OP_GETLOCK, result, handle, "%s", fsp_str_do_log(fsp));
1795 static int smb_full_audit_symlinkat(vfs_handle_struct *handle,
1796 const struct smb_filename *link_contents,
1797 struct files_struct *dirfsp,
1798 const struct smb_filename *new_smb_fname)
1802 result = SMB_VFS_NEXT_SYMLINKAT(handle,
1807 do_log(SMB_VFS_OP_SYMLINKAT,
1811 link_contents->base_name,
1812 smb_fname_str_do_log(handle->conn, new_smb_fname));
1817 static int smb_full_audit_readlinkat(vfs_handle_struct *handle,
1818 files_struct *dirfsp,
1819 const struct smb_filename *smb_fname,
1825 result = SMB_VFS_NEXT_READLINKAT(handle,
1831 do_log(SMB_VFS_OP_READLINKAT,
1835 smb_fname_str_do_log(handle->conn, smb_fname));
1840 static int smb_full_audit_linkat(vfs_handle_struct *handle,
1841 files_struct *srcfsp,
1842 const struct smb_filename *old_smb_fname,
1843 files_struct *dstfsp,
1844 const struct smb_filename *new_smb_fname,
1849 result = SMB_VFS_NEXT_LINKAT(handle,
1856 do_log(SMB_VFS_OP_LINKAT,
1860 smb_fname_str_do_log(handle->conn, old_smb_fname),
1861 smb_fname_str_do_log(handle->conn, new_smb_fname));
1866 static int smb_full_audit_mknodat(vfs_handle_struct *handle,
1867 files_struct *dirfsp,
1868 const struct smb_filename *smb_fname,
1874 result = SMB_VFS_NEXT_MKNODAT(handle,
1880 do_log(SMB_VFS_OP_MKNODAT,
1884 smb_fname_str_do_log(handle->conn, smb_fname));
1889 static struct smb_filename *smb_full_audit_realpath(vfs_handle_struct *handle,
1891 const struct smb_filename *smb_fname)
1893 struct smb_filename *result_fname = NULL;
1895 result_fname = SMB_VFS_NEXT_REALPATH(handle, ctx, smb_fname);
1897 do_log(SMB_VFS_OP_REALPATH,
1898 (result_fname != NULL),
1901 smb_fname_str_do_log(handle->conn, smb_fname));
1903 return result_fname;
1906 static int smb_full_audit_chflags(vfs_handle_struct *handle,
1907 const struct smb_filename *smb_fname,
1912 result = SMB_VFS_NEXT_CHFLAGS(handle, smb_fname, flags);
1914 do_log(SMB_VFS_OP_CHFLAGS,
1918 smb_fname_str_do_log(handle->conn, smb_fname));
1923 static struct file_id smb_full_audit_file_id_create(struct vfs_handle_struct *handle,
1924 const SMB_STRUCT_STAT *sbuf)
1926 struct file_id id_zero = { 0 };
1927 struct file_id result;
1928 struct file_id_buf idbuf;
1930 result = SMB_VFS_NEXT_FILE_ID_CREATE(handle, sbuf);
1932 do_log(SMB_VFS_OP_FILE_ID_CREATE,
1933 !file_id_equal(&id_zero, &result),
1936 file_id_str_buf(result, &idbuf));
1941 static uint64_t smb_full_audit_fs_file_id(struct vfs_handle_struct *handle,
1942 const SMB_STRUCT_STAT *sbuf)
1946 result = SMB_VFS_NEXT_FS_FILE_ID(handle, sbuf);
1948 do_log(SMB_VFS_OP_FS_FILE_ID,
1950 handle, "%" PRIu64, result);
1955 static NTSTATUS smb_full_audit_streaminfo(vfs_handle_struct *handle,
1956 struct files_struct *fsp,
1957 const struct smb_filename *smb_fname,
1958 TALLOC_CTX *mem_ctx,
1959 unsigned int *pnum_streams,
1960 struct stream_struct **pstreams)
1964 result = SMB_VFS_NEXT_STREAMINFO(handle, fsp, smb_fname, mem_ctx,
1965 pnum_streams, pstreams);
1967 do_log(SMB_VFS_OP_STREAMINFO,
1968 NT_STATUS_IS_OK(result),
1971 smb_fname_str_do_log(handle->conn, smb_fname));
1976 static int smb_full_audit_get_real_filename(struct vfs_handle_struct *handle,
1977 const struct smb_filename *path,
1979 TALLOC_CTX *mem_ctx,
1984 result = SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name, mem_ctx,
1987 do_log(SMB_VFS_OP_GET_REAL_FILENAME, (result == 0), handle,
1989 path->base_name, name, (result == 0) ? *found_name : "");
1994 static const char *smb_full_audit_connectpath(vfs_handle_struct *handle,
1995 const struct smb_filename *smb_fname)
1999 result = SMB_VFS_NEXT_CONNECTPATH(handle, smb_fname);
2001 do_log(SMB_VFS_OP_CONNECTPATH,
2005 smb_fname_str_do_log(handle->conn, smb_fname));
2010 static NTSTATUS smb_full_audit_brl_lock_windows(struct vfs_handle_struct *handle,
2011 struct byte_range_lock *br_lck,
2012 struct lock_struct *plock)
2016 result = SMB_VFS_NEXT_BRL_LOCK_WINDOWS(handle, br_lck, plock);
2018 do_log(SMB_VFS_OP_BRL_LOCK_WINDOWS, NT_STATUS_IS_OK(result), handle,
2019 "%s:%llu-%llu. type=%d.",
2020 fsp_str_do_log(brl_fsp(br_lck)),
2021 (unsigned long long)plock->start,
2022 (unsigned long long)plock->size,
2028 static bool smb_full_audit_brl_unlock_windows(struct vfs_handle_struct *handle,
2029 struct byte_range_lock *br_lck,
2030 const struct lock_struct *plock)
2034 result = SMB_VFS_NEXT_BRL_UNLOCK_WINDOWS(handle, br_lck, plock);
2036 do_log(SMB_VFS_OP_BRL_UNLOCK_WINDOWS, (result == 0), handle,
2037 "%s:%llu-%llu:%d", fsp_str_do_log(brl_fsp(br_lck)),
2038 (unsigned long long)plock->start,
2039 (unsigned long long)plock->size,
2045 static bool smb_full_audit_strict_lock_check(struct vfs_handle_struct *handle,
2046 struct files_struct *fsp,
2047 struct lock_struct *plock)
2051 result = SMB_VFS_NEXT_STRICT_LOCK_CHECK(handle, fsp, plock);
2053 do_log(SMB_VFS_OP_STRICT_LOCK_CHECK, result, handle,
2054 "%s:%llu-%llu:%d", fsp_str_do_log(fsp),
2055 (unsigned long long)plock->start,
2056 (unsigned long long)plock->size,
2062 static NTSTATUS smb_full_audit_translate_name(struct vfs_handle_struct *handle,
2064 enum vfs_translate_direction direction,
2065 TALLOC_CTX *mem_ctx,
2070 result = SMB_VFS_NEXT_TRANSLATE_NAME(handle, name, direction, mem_ctx,
2073 do_log(SMB_VFS_OP_TRANSLATE_NAME, NT_STATUS_IS_OK(result), handle, "");
2078 static NTSTATUS smb_full_audit_fsctl(struct vfs_handle_struct *handle,
2079 struct files_struct *fsp,
2083 const uint8_t *_in_data,
2085 uint8_t **_out_data,
2086 uint32_t max_out_len,
2091 result = SMB_VFS_NEXT_FSCTL(handle,
2102 do_log(SMB_VFS_OP_FSCTL, NT_STATUS_IS_OK(result), handle, "");
2107 static struct tevent_req *smb_full_audit_offload_read_send(
2108 TALLOC_CTX *mem_ctx,
2109 struct tevent_context *ev,
2110 struct vfs_handle_struct *handle,
2111 struct files_struct *fsp,
2117 struct tevent_req *req = NULL;
2119 req = SMB_VFS_NEXT_OFFLOAD_READ_SEND(mem_ctx, ev, handle, fsp,
2120 fsctl, ttl, offset, to_copy);
2122 do_log(SMB_VFS_OP_OFFLOAD_READ_SEND, req, handle, "");
2127 static NTSTATUS smb_full_audit_offload_read_recv(
2128 struct tevent_req *req,
2129 struct vfs_handle_struct *handle,
2130 TALLOC_CTX *mem_ctx,
2131 DATA_BLOB *_token_blob)
2135 status = SMB_VFS_NEXT_OFFLOAD_READ_RECV(req, handle, mem_ctx,
2138 do_log(SMB_VFS_OP_OFFLOAD_READ_RECV, NT_STATUS_IS_OK(status), handle, "");
2143 static struct tevent_req *smb_full_audit_offload_write_send(struct vfs_handle_struct *handle,
2144 TALLOC_CTX *mem_ctx,
2145 struct tevent_context *ev,
2148 off_t transfer_offset,
2149 struct files_struct *dest_fsp,
2153 struct tevent_req *req;
2155 req = SMB_VFS_NEXT_OFFLOAD_WRITE_SEND(handle, mem_ctx, ev,
2156 fsctl, token, transfer_offset,
2157 dest_fsp, dest_off, num);
2159 do_log(SMB_VFS_OP_OFFLOAD_WRITE_SEND, req, handle, "");
2164 static NTSTATUS smb_full_audit_offload_write_recv(struct vfs_handle_struct *handle,
2165 struct tevent_req *req,
2170 result = SMB_VFS_NEXT_OFFLOAD_WRITE_RECV(handle, req, copied);
2172 do_log(SMB_VFS_OP_OFFLOAD_WRITE_RECV, NT_STATUS_IS_OK(result), handle, "");
2177 static NTSTATUS smb_full_audit_get_compression(vfs_handle_struct *handle,
2178 TALLOC_CTX *mem_ctx,
2179 struct files_struct *fsp,
2180 struct smb_filename *smb_fname,
2181 uint16_t *_compression_fmt)
2185 result = SMB_VFS_NEXT_GET_COMPRESSION(handle, mem_ctx, fsp, smb_fname,
2188 do_log(SMB_VFS_OP_GET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
2190 (fsp ? fsp_str_do_log(fsp) :
2191 smb_fname_str_do_log(handle->conn, smb_fname)));
2196 static NTSTATUS smb_full_audit_set_compression(vfs_handle_struct *handle,
2197 TALLOC_CTX *mem_ctx,
2198 struct files_struct *fsp,
2199 uint16_t compression_fmt)
2203 result = SMB_VFS_NEXT_SET_COMPRESSION(handle, mem_ctx, fsp,
2206 do_log(SMB_VFS_OP_SET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
2207 "%s", fsp_str_do_log(fsp));
2212 static NTSTATUS smb_full_audit_readdir_attr(struct vfs_handle_struct *handle,
2213 const struct smb_filename *fname,
2214 TALLOC_CTX *mem_ctx,
2215 struct readdir_attr_data **pattr_data)
2219 status = SMB_VFS_NEXT_READDIR_ATTR(handle, fname, mem_ctx, pattr_data);
2221 do_log(SMB_VFS_OP_READDIR_ATTR, NT_STATUS_IS_OK(status), handle, "%s",
2222 smb_fname_str_do_log(handle->conn, fname));
2227 static NTSTATUS smb_full_audit_get_dos_attributes(
2228 struct vfs_handle_struct *handle,
2229 struct smb_filename *smb_fname,
2234 status = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES(handle,
2238 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES,
2239 NT_STATUS_IS_OK(status),
2242 smb_fname_str_do_log(handle->conn, smb_fname));
2247 struct smb_full_audit_get_dos_attributes_state {
2248 struct vfs_aio_state aio_state;
2249 vfs_handle_struct *handle;
2250 files_struct *dir_fsp;
2251 const struct smb_filename *smb_fname;
2255 static void smb_full_audit_get_dos_attributes_done(struct tevent_req *subreq);
2257 static struct tevent_req *smb_full_audit_get_dos_attributes_send(
2258 TALLOC_CTX *mem_ctx,
2259 struct tevent_context *ev,
2260 struct vfs_handle_struct *handle,
2261 files_struct *dir_fsp,
2262 struct smb_filename *smb_fname)
2264 struct tevent_req *req = NULL;
2265 struct smb_full_audit_get_dos_attributes_state *state = NULL;
2266 struct tevent_req *subreq = NULL;
2268 req = tevent_req_create(mem_ctx, &state,
2269 struct smb_full_audit_get_dos_attributes_state);
2271 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2275 fsp_str_do_log(dir_fsp),
2276 smb_fname->base_name);
2279 *state = (struct smb_full_audit_get_dos_attributes_state) {
2282 .smb_fname = smb_fname,
2285 subreq = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES_SEND(mem_ctx,
2290 if (tevent_req_nomem(subreq, req)) {
2291 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2295 fsp_str_do_log(dir_fsp),
2296 smb_fname->base_name);
2297 return tevent_req_post(req, ev);
2299 tevent_req_set_callback(subreq,
2300 smb_full_audit_get_dos_attributes_done,
2303 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2307 fsp_str_do_log(dir_fsp),
2308 smb_fname->base_name);
2313 static void smb_full_audit_get_dos_attributes_done(struct tevent_req *subreq)
2315 struct tevent_req *req =
2316 tevent_req_callback_data(subreq,
2318 struct smb_full_audit_get_dos_attributes_state *state =
2319 tevent_req_data(req,
2320 struct smb_full_audit_get_dos_attributes_state);
2323 status = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES_RECV(subreq,
2326 TALLOC_FREE(subreq);
2327 if (tevent_req_nterror(req, status)) {
2331 tevent_req_done(req);
2335 static NTSTATUS smb_full_audit_get_dos_attributes_recv(struct tevent_req *req,
2336 struct vfs_aio_state *aio_state,
2339 struct smb_full_audit_get_dos_attributes_state *state =
2340 tevent_req_data(req,
2341 struct smb_full_audit_get_dos_attributes_state);
2344 if (tevent_req_is_nterror(req, &status)) {
2345 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV,
2349 fsp_str_do_log(state->dir_fsp),
2350 state->smb_fname->base_name);
2351 tevent_req_received(req);
2355 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV,
2359 fsp_str_do_log(state->dir_fsp),
2360 state->smb_fname->base_name);
2362 *aio_state = state->aio_state;
2363 *dosmode = state->dosmode;
2364 tevent_req_received(req);
2365 return NT_STATUS_OK;
2368 static NTSTATUS smb_full_audit_fget_dos_attributes(
2369 struct vfs_handle_struct *handle,
2370 struct files_struct *fsp,
2375 status = SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle,
2379 do_log(SMB_VFS_OP_FGET_DOS_ATTRIBUTES,
2380 NT_STATUS_IS_OK(status),
2383 fsp_str_do_log(fsp));
2388 static NTSTATUS smb_full_audit_set_dos_attributes(
2389 struct vfs_handle_struct *handle,
2390 const struct smb_filename *smb_fname,
2395 status = SMB_VFS_NEXT_SET_DOS_ATTRIBUTES(handle,
2399 do_log(SMB_VFS_OP_SET_DOS_ATTRIBUTES,
2400 NT_STATUS_IS_OK(status),
2403 smb_fname_str_do_log(handle->conn, smb_fname));
2408 static NTSTATUS smb_full_audit_fset_dos_attributes(
2409 struct vfs_handle_struct *handle,
2410 struct files_struct *fsp,
2415 status = SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle,
2419 do_log(SMB_VFS_OP_FSET_DOS_ATTRIBUTES,
2420 NT_STATUS_IS_OK(status),
2423 fsp_str_do_log(fsp));
2428 static NTSTATUS smb_full_audit_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
2429 uint32_t security_info,
2430 TALLOC_CTX *mem_ctx,
2431 struct security_descriptor **ppdesc)
2435 result = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
2438 do_log(SMB_VFS_OP_FGET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2439 "%s", fsp_str_do_log(fsp));
2444 static NTSTATUS smb_full_audit_get_nt_acl_at(vfs_handle_struct *handle,
2445 struct files_struct *dirfsp,
2446 const struct smb_filename *smb_fname,
2447 uint32_t security_info,
2448 TALLOC_CTX *mem_ctx,
2449 struct security_descriptor **ppdesc)
2453 result = SMB_VFS_NEXT_GET_NT_ACL_AT(handle,
2460 do_log(SMB_VFS_OP_GET_NT_ACL_AT,
2461 NT_STATUS_IS_OK(result),
2464 smb_fname_str_do_log(handle->conn, smb_fname));
2469 static NTSTATUS smb_full_audit_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
2470 uint32_t security_info_sent,
2471 const struct security_descriptor *psd)
2473 struct vfs_full_audit_private_data *pd;
2477 SMB_VFS_HANDLE_GET_DATA(handle, pd,
2478 struct vfs_full_audit_private_data,
2479 return NT_STATUS_INTERNAL_ERROR);
2481 if (pd->log_secdesc) {
2482 sd = sddl_encode(talloc_tos(), psd, get_global_sam_sid());
2485 result = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
2487 do_log(SMB_VFS_OP_FSET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2488 "%s [%s]", fsp_str_do_log(fsp), sd ? sd : "");
2495 static NTSTATUS smb_full_audit_audit_file(struct vfs_handle_struct *handle,
2496 struct smb_filename *file,
2497 struct security_acl *sacl,
2498 uint32_t access_requested,
2499 uint32_t access_denied)
2503 result = SMB_VFS_NEXT_AUDIT_FILE(handle,
2509 do_log(SMB_VFS_OP_AUDIT_FILE, NT_STATUS_IS_OK(result), handle,
2511 smb_fname_str_do_log(handle->conn, file));
2516 static SMB_ACL_T smb_full_audit_sys_acl_get_file(vfs_handle_struct *handle,
2517 const struct smb_filename *smb_fname,
2518 SMB_ACL_TYPE_T type,
2519 TALLOC_CTX *mem_ctx)
2523 result = SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, smb_fname,
2526 do_log(SMB_VFS_OP_SYS_ACL_GET_FILE,
2530 smb_fname_str_do_log(handle->conn, smb_fname));
2535 static SMB_ACL_T smb_full_audit_sys_acl_get_fd(vfs_handle_struct *handle,
2536 files_struct *fsp, TALLOC_CTX *mem_ctx)
2540 result = SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp, mem_ctx);
2542 do_log(SMB_VFS_OP_SYS_ACL_GET_FD, (result != NULL), handle,
2543 "%s", fsp_str_do_log(fsp));
2548 static int smb_full_audit_sys_acl_blob_get_file(vfs_handle_struct *handle,
2549 const struct smb_filename *smb_fname,
2550 TALLOC_CTX *mem_ctx,
2551 char **blob_description,
2556 result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FILE(handle, smb_fname,
2557 mem_ctx, blob_description, blob);
2559 do_log(SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE,
2563 smb_fname_str_do_log(handle->conn, smb_fname));
2568 static int smb_full_audit_sys_acl_blob_get_fd(vfs_handle_struct *handle,
2570 TALLOC_CTX *mem_ctx,
2571 char **blob_description,
2576 result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle, fsp, mem_ctx, blob_description, blob);
2578 do_log(SMB_VFS_OP_SYS_ACL_BLOB_GET_FD, (result >= 0), handle,
2579 "%s", fsp_str_do_log(fsp));
2584 static int smb_full_audit_sys_acl_set_file(vfs_handle_struct *handle,
2585 const struct smb_filename *smb_fname,
2586 SMB_ACL_TYPE_T acltype,
2591 result = SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, smb_fname, acltype,
2594 do_log(SMB_VFS_OP_SYS_ACL_SET_FILE,
2598 smb_fname_str_do_log(handle->conn, smb_fname));
2603 static int smb_full_audit_sys_acl_set_fd(vfs_handle_struct *handle, files_struct *fsp,
2608 result = SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, theacl);
2610 do_log(SMB_VFS_OP_SYS_ACL_SET_FD, (result >= 0), handle,
2611 "%s", fsp_str_do_log(fsp));
2616 static int smb_full_audit_sys_acl_delete_def_file(vfs_handle_struct *handle,
2617 const struct smb_filename *smb_fname)
2621 result = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, smb_fname);
2623 do_log(SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE,
2627 smb_fname_str_do_log(handle->conn, smb_fname));
2632 static ssize_t smb_full_audit_getxattr(struct vfs_handle_struct *handle,
2633 const struct smb_filename *smb_fname,
2634 const char *name, void *value, size_t size)
2638 result = SMB_VFS_NEXT_GETXATTR(handle, smb_fname, name, value, size);
2640 do_log(SMB_VFS_OP_GETXATTR,
2644 smb_fname_str_do_log(handle->conn, smb_fname),
2650 struct smb_full_audit_getxattrat_state {
2651 struct vfs_aio_state aio_state;
2652 vfs_handle_struct *handle;
2653 files_struct *dir_fsp;
2654 const struct smb_filename *smb_fname;
2655 const char *xattr_name;
2657 uint8_t *xattr_value;
2660 static void smb_full_audit_getxattrat_done(struct tevent_req *subreq);
2662 static struct tevent_req *smb_full_audit_getxattrat_send(
2663 TALLOC_CTX *mem_ctx,
2664 struct tevent_context *ev,
2665 struct vfs_handle_struct *handle,
2666 files_struct *dir_fsp,
2667 const struct smb_filename *smb_fname,
2668 const char *xattr_name,
2671 struct tevent_req *req = NULL;
2672 struct tevent_req *subreq = NULL;
2673 struct smb_full_audit_getxattrat_state *state = NULL;
2675 req = tevent_req_create(mem_ctx, &state,
2676 struct smb_full_audit_getxattrat_state);
2678 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2682 fsp_str_do_log(dir_fsp),
2683 smb_fname->base_name,
2687 *state = (struct smb_full_audit_getxattrat_state) {
2690 .smb_fname = smb_fname,
2691 .xattr_name = xattr_name,
2694 subreq = SMB_VFS_NEXT_GETXATTRAT_SEND(state,
2701 if (tevent_req_nomem(subreq, req)) {
2702 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2706 fsp_str_do_log(dir_fsp),
2707 smb_fname->base_name,
2709 return tevent_req_post(req, ev);
2711 tevent_req_set_callback(subreq, smb_full_audit_getxattrat_done, req);
2713 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2717 fsp_str_do_log(dir_fsp),
2718 smb_fname->base_name,
2724 static void smb_full_audit_getxattrat_done(struct tevent_req *subreq)
2726 struct tevent_req *req = tevent_req_callback_data(
2727 subreq, struct tevent_req);
2728 struct smb_full_audit_getxattrat_state *state = tevent_req_data(
2729 req, struct smb_full_audit_getxattrat_state);
2731 state->xattr_size = SMB_VFS_NEXT_GETXATTRAT_RECV(subreq,
2734 &state->xattr_value);
2735 TALLOC_FREE(subreq);
2736 if (state->xattr_size == -1) {
2737 tevent_req_error(req, state->aio_state.error);
2741 tevent_req_done(req);
2744 static ssize_t smb_full_audit_getxattrat_recv(struct tevent_req *req,
2745 struct vfs_aio_state *aio_state,
2746 TALLOC_CTX *mem_ctx,
2747 uint8_t **xattr_value)
2749 struct smb_full_audit_getxattrat_state *state = tevent_req_data(
2750 req, struct smb_full_audit_getxattrat_state);
2753 if (tevent_req_is_unix_error(req, &aio_state->error)) {
2754 do_log(SMB_VFS_OP_GETXATTRAT_RECV,
2758 fsp_str_do_log(state->dir_fsp),
2759 state->smb_fname->base_name,
2761 tevent_req_received(req);
2765 do_log(SMB_VFS_OP_GETXATTRAT_RECV,
2769 fsp_str_do_log(state->dir_fsp),
2770 state->smb_fname->base_name,
2773 *aio_state = state->aio_state;
2774 xattr_size = state->xattr_size;
2775 if (xattr_value != NULL) {
2776 *xattr_value = talloc_move(mem_ctx, &state->xattr_value);
2779 tevent_req_received(req);
2783 static ssize_t smb_full_audit_fgetxattr(struct vfs_handle_struct *handle,
2784 struct files_struct *fsp,
2785 const char *name, void *value, size_t size)
2789 result = SMB_VFS_NEXT_FGETXATTR(handle, fsp, name, value, size);
2791 do_log(SMB_VFS_OP_FGETXATTR, (result >= 0), handle,
2792 "%s|%s", fsp_str_do_log(fsp), name);
2797 static ssize_t smb_full_audit_listxattr(struct vfs_handle_struct *handle,
2798 const struct smb_filename *smb_fname,
2804 result = SMB_VFS_NEXT_LISTXATTR(handle, smb_fname, list, size);
2806 do_log(SMB_VFS_OP_LISTXATTR,
2810 smb_fname_str_do_log(handle->conn, smb_fname));
2815 static ssize_t smb_full_audit_flistxattr(struct vfs_handle_struct *handle,
2816 struct files_struct *fsp, char *list,
2821 result = SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
2823 do_log(SMB_VFS_OP_FLISTXATTR, (result >= 0), handle,
2824 "%s", fsp_str_do_log(fsp));
2829 static int smb_full_audit_removexattr(struct vfs_handle_struct *handle,
2830 const struct smb_filename *smb_fname,
2835 result = SMB_VFS_NEXT_REMOVEXATTR(handle, smb_fname, name);
2837 do_log(SMB_VFS_OP_REMOVEXATTR,
2841 smb_fname_str_do_log(handle->conn, smb_fname),
2847 static int smb_full_audit_fremovexattr(struct vfs_handle_struct *handle,
2848 struct files_struct *fsp,
2853 result = SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, name);
2855 do_log(SMB_VFS_OP_FREMOVEXATTR, (result >= 0), handle,
2856 "%s|%s", fsp_str_do_log(fsp), name);
2861 static int smb_full_audit_setxattr(struct vfs_handle_struct *handle,
2862 const struct smb_filename *smb_fname,
2863 const char *name, const void *value, size_t size,
2868 result = SMB_VFS_NEXT_SETXATTR(handle, smb_fname, name, value, size,
2871 do_log(SMB_VFS_OP_SETXATTR,
2875 smb_fname_str_do_log(handle->conn, smb_fname),
2881 static int smb_full_audit_fsetxattr(struct vfs_handle_struct *handle,
2882 struct files_struct *fsp, const char *name,
2883 const void *value, size_t size, int flags)
2887 result = SMB_VFS_NEXT_FSETXATTR(handle, fsp, name, value, size, flags);
2889 do_log(SMB_VFS_OP_FSETXATTR, (result >= 0), handle,
2890 "%s|%s", fsp_str_do_log(fsp), name);
2895 static bool smb_full_audit_aio_force(struct vfs_handle_struct *handle,
2896 struct files_struct *fsp)
2900 result = SMB_VFS_NEXT_AIO_FORCE(handle, fsp);
2901 do_log(SMB_VFS_OP_AIO_FORCE, result, handle,
2902 "%s", fsp_str_do_log(fsp));
2907 static NTSTATUS smb_full_audit_durable_cookie(struct vfs_handle_struct *handle,
2908 struct files_struct *fsp,
2909 TALLOC_CTX *mem_ctx,
2914 result = SMB_VFS_NEXT_DURABLE_COOKIE(handle,
2919 do_log(SMB_VFS_OP_DURABLE_COOKIE, NT_STATUS_IS_OK(result), handle,
2920 "%s", fsp_str_do_log(fsp));
2925 static NTSTATUS smb_full_audit_durable_disconnect(
2926 struct vfs_handle_struct *handle,
2927 struct files_struct *fsp,
2928 const DATA_BLOB old_cookie,
2929 TALLOC_CTX *mem_ctx,
2930 DATA_BLOB *new_cookie)
2934 result = SMB_VFS_NEXT_DURABLE_DISCONNECT(handle,
2940 do_log(SMB_VFS_OP_DURABLE_DISCONNECT, NT_STATUS_IS_OK(result), handle,
2941 "%s", fsp_str_do_log(fsp));
2946 static NTSTATUS smb_full_audit_durable_reconnect(
2947 struct vfs_handle_struct *handle,
2948 struct smb_request *smb1req,
2949 struct smbXsrv_open *op,
2950 const DATA_BLOB old_cookie,
2951 TALLOC_CTX *mem_ctx,
2952 struct files_struct **fsp,
2953 DATA_BLOB *new_cookie)
2957 result = SMB_VFS_NEXT_DURABLE_RECONNECT(handle,
2965 do_log(SMB_VFS_OP_DURABLE_RECONNECT,
2966 NT_STATUS_IS_OK(result),
2973 static struct vfs_fn_pointers vfs_full_audit_fns = {
2975 /* Disk operations */
2977 .connect_fn = smb_full_audit_connect,
2978 .disconnect_fn = smb_full_audit_disconnect,
2979 .disk_free_fn = smb_full_audit_disk_free,
2980 .get_quota_fn = smb_full_audit_get_quota,
2981 .set_quota_fn = smb_full_audit_set_quota,
2982 .get_shadow_copy_data_fn = smb_full_audit_get_shadow_copy_data,
2983 .statvfs_fn = smb_full_audit_statvfs,
2984 .fs_capabilities_fn = smb_full_audit_fs_capabilities,
2985 .get_dfs_referrals_fn = smb_full_audit_get_dfs_referrals,
2986 .create_dfs_pathat_fn = smb_full_audit_create_dfs_pathat,
2987 .read_dfs_pathat_fn = smb_full_audit_read_dfs_pathat,
2988 .fdopendir_fn = smb_full_audit_fdopendir,
2989 .readdir_fn = smb_full_audit_readdir,
2990 .seekdir_fn = smb_full_audit_seekdir,
2991 .telldir_fn = smb_full_audit_telldir,
2992 .rewind_dir_fn = smb_full_audit_rewinddir,
2993 .mkdirat_fn = smb_full_audit_mkdirat,
2994 .closedir_fn = smb_full_audit_closedir,
2995 .openat_fn = smb_full_audit_openat,
2996 .create_file_fn = smb_full_audit_create_file,
2997 .close_fn = smb_full_audit_close,
2998 .pread_fn = smb_full_audit_pread,
2999 .pread_send_fn = smb_full_audit_pread_send,
3000 .pread_recv_fn = smb_full_audit_pread_recv,
3001 .pwrite_fn = smb_full_audit_pwrite,
3002 .pwrite_send_fn = smb_full_audit_pwrite_send,
3003 .pwrite_recv_fn = smb_full_audit_pwrite_recv,
3004 .lseek_fn = smb_full_audit_lseek,
3005 .sendfile_fn = smb_full_audit_sendfile,
3006 .recvfile_fn = smb_full_audit_recvfile,
3007 .renameat_fn = smb_full_audit_renameat,
3008 .fsync_send_fn = smb_full_audit_fsync_send,
3009 .fsync_recv_fn = smb_full_audit_fsync_recv,
3010 .stat_fn = smb_full_audit_stat,
3011 .fstat_fn = smb_full_audit_fstat,
3012 .lstat_fn = smb_full_audit_lstat,
3013 .get_alloc_size_fn = smb_full_audit_get_alloc_size,
3014 .unlinkat_fn = smb_full_audit_unlinkat,
3015 .chmod_fn = smb_full_audit_chmod,
3016 .fchmod_fn = smb_full_audit_fchmod,
3017 .fchown_fn = smb_full_audit_fchown,
3018 .lchown_fn = smb_full_audit_lchown,
3019 .chdir_fn = smb_full_audit_chdir,
3020 .getwd_fn = smb_full_audit_getwd,
3021 .ntimes_fn = smb_full_audit_ntimes,
3022 .ftruncate_fn = smb_full_audit_ftruncate,
3023 .fallocate_fn = smb_full_audit_fallocate,
3024 .lock_fn = smb_full_audit_lock,
3025 .kernel_flock_fn = smb_full_audit_kernel_flock,
3026 .fcntl_fn = smb_full_audit_fcntl,
3027 .linux_setlease_fn = smb_full_audit_linux_setlease,
3028 .getlock_fn = smb_full_audit_getlock,
3029 .symlinkat_fn = smb_full_audit_symlinkat,
3030 .readlinkat_fn = smb_full_audit_readlinkat,
3031 .linkat_fn = smb_full_audit_linkat,
3032 .mknodat_fn = smb_full_audit_mknodat,
3033 .realpath_fn = smb_full_audit_realpath,
3034 .chflags_fn = smb_full_audit_chflags,
3035 .file_id_create_fn = smb_full_audit_file_id_create,
3036 .fs_file_id_fn = smb_full_audit_fs_file_id,
3037 .offload_read_send_fn = smb_full_audit_offload_read_send,
3038 .offload_read_recv_fn = smb_full_audit_offload_read_recv,
3039 .offload_write_send_fn = smb_full_audit_offload_write_send,
3040 .offload_write_recv_fn = smb_full_audit_offload_write_recv,
3041 .get_compression_fn = smb_full_audit_get_compression,
3042 .set_compression_fn = smb_full_audit_set_compression,
3043 .snap_check_path_fn = smb_full_audit_snap_check_path,
3044 .snap_create_fn = smb_full_audit_snap_create,
3045 .snap_delete_fn = smb_full_audit_snap_delete,
3046 .streaminfo_fn = smb_full_audit_streaminfo,
3047 .get_real_filename_fn = smb_full_audit_get_real_filename,
3048 .connectpath_fn = smb_full_audit_connectpath,
3049 .brl_lock_windows_fn = smb_full_audit_brl_lock_windows,
3050 .brl_unlock_windows_fn = smb_full_audit_brl_unlock_windows,
3051 .strict_lock_check_fn = smb_full_audit_strict_lock_check,
3052 .translate_name_fn = smb_full_audit_translate_name,
3053 .fsctl_fn = smb_full_audit_fsctl,
3054 .get_dos_attributes_fn = smb_full_audit_get_dos_attributes,
3055 .get_dos_attributes_send_fn = smb_full_audit_get_dos_attributes_send,
3056 .get_dos_attributes_recv_fn = smb_full_audit_get_dos_attributes_recv,
3057 .fget_dos_attributes_fn = smb_full_audit_fget_dos_attributes,
3058 .set_dos_attributes_fn = smb_full_audit_set_dos_attributes,
3059 .fset_dos_attributes_fn = smb_full_audit_fset_dos_attributes,
3060 .fget_nt_acl_fn = smb_full_audit_fget_nt_acl,
3061 .get_nt_acl_at_fn = smb_full_audit_get_nt_acl_at,
3062 .fset_nt_acl_fn = smb_full_audit_fset_nt_acl,
3063 .audit_file_fn = smb_full_audit_audit_file,
3064 .sys_acl_get_file_fn = smb_full_audit_sys_acl_get_file,
3065 .sys_acl_get_fd_fn = smb_full_audit_sys_acl_get_fd,
3066 .sys_acl_blob_get_file_fn = smb_full_audit_sys_acl_blob_get_file,
3067 .sys_acl_blob_get_fd_fn = smb_full_audit_sys_acl_blob_get_fd,
3068 .sys_acl_set_file_fn = smb_full_audit_sys_acl_set_file,
3069 .sys_acl_set_fd_fn = smb_full_audit_sys_acl_set_fd,
3070 .sys_acl_delete_def_file_fn = smb_full_audit_sys_acl_delete_def_file,
3071 .getxattr_fn = smb_full_audit_getxattr,
3072 .getxattrat_send_fn = smb_full_audit_getxattrat_send,
3073 .getxattrat_recv_fn = smb_full_audit_getxattrat_recv,
3074 .fgetxattr_fn = smb_full_audit_fgetxattr,
3075 .listxattr_fn = smb_full_audit_listxattr,
3076 .flistxattr_fn = smb_full_audit_flistxattr,
3077 .removexattr_fn = smb_full_audit_removexattr,
3078 .fremovexattr_fn = smb_full_audit_fremovexattr,
3079 .setxattr_fn = smb_full_audit_setxattr,
3080 .fsetxattr_fn = smb_full_audit_fsetxattr,
3081 .aio_force_fn = smb_full_audit_aio_force,
3082 .durable_cookie_fn = smb_full_audit_durable_cookie,
3083 .durable_disconnect_fn = smb_full_audit_durable_disconnect,
3084 .durable_reconnect_fn = smb_full_audit_durable_reconnect,
3085 .readdir_attr_fn = smb_full_audit_readdir_attr
3090 NTSTATUS vfs_full_audit_init(TALLOC_CTX *ctx)
3094 smb_vfs_assert_all_fns(&vfs_full_audit_fns, "full_audit");
3096 ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "full_audit",
3097 &vfs_full_audit_fns);
3099 if (!NT_STATUS_IS_OK(ret))
3102 vfs_full_audit_debug_level = debug_add_class("full_audit");
3103 if (vfs_full_audit_debug_level == -1) {
3104 vfs_full_audit_debug_level = DBGC_VFS;
3105 DEBUG(0, ("vfs_full_audit: Couldn't register custom debugging "
3108 DEBUG(10, ("vfs_full_audit: Debug class number of "
3109 "'full_audit': %d\n", vfs_full_audit_debug_level));