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"
76 #include "source3/lib/substitute.h"
78 static int vfs_full_audit_debug_level
= DBGC_VFS
;
80 struct vfs_full_audit_private_data
{
81 struct bitmap
*success_ops
;
82 struct bitmap
*failure_ops
;
90 #define DBGC_CLASS vfs_full_audit_debug_level
92 typedef enum _vfs_op_type
{
97 SMB_VFS_OP_CONNECT
= 0,
98 SMB_VFS_OP_DISCONNECT
,
100 SMB_VFS_OP_GET_QUOTA
,
101 SMB_VFS_OP_SET_QUOTA
,
102 SMB_VFS_OP_GET_SHADOW_COPY_DATA
,
104 SMB_VFS_OP_FS_CAPABILITIES
,
105 SMB_VFS_OP_GET_DFS_REFERRALS
,
106 SMB_VFS_OP_CREATE_DFS_PATHAT
,
107 SMB_VFS_OP_READ_DFS_PATHAT
,
109 /* Directory operations */
111 SMB_VFS_OP_FDOPENDIR
,
115 SMB_VFS_OP_REWINDDIR
,
119 /* File operations */
123 SMB_VFS_OP_CREATE_FILE
,
127 SMB_VFS_OP_PREAD_SEND
,
128 SMB_VFS_OP_PREAD_RECV
,
131 SMB_VFS_OP_PWRITE_SEND
,
132 SMB_VFS_OP_PWRITE_RECV
,
138 SMB_VFS_OP_FSYNC_SEND
,
139 SMB_VFS_OP_FSYNC_RECV
,
143 SMB_VFS_OP_GET_ALLOC_SIZE
,
152 SMB_VFS_OP_FTRUNCATE
,
153 SMB_VFS_OP_FALLOCATE
,
155 SMB_VFS_OP_FILESYSTEM_SHAREMODE
,
157 SMB_VFS_OP_LINUX_SETLEASE
,
159 SMB_VFS_OP_SYMLINKAT
,
160 SMB_VFS_OP_READLINKAT
,
165 SMB_VFS_OP_FILE_ID_CREATE
,
166 SMB_VFS_OP_FS_FILE_ID
,
167 SMB_VFS_OP_FSTREAMINFO
,
168 SMB_VFS_OP_GET_REAL_FILENAME
,
169 SMB_VFS_OP_CONNECTPATH
,
170 SMB_VFS_OP_BRL_LOCK_WINDOWS
,
171 SMB_VFS_OP_BRL_UNLOCK_WINDOWS
,
172 SMB_VFS_OP_STRICT_LOCK_CHECK
,
173 SMB_VFS_OP_TRANSLATE_NAME
,
174 SMB_VFS_OP_PARENT_PATHNAME
,
176 SMB_VFS_OP_OFFLOAD_READ_SEND
,
177 SMB_VFS_OP_OFFLOAD_READ_RECV
,
178 SMB_VFS_OP_OFFLOAD_WRITE_SEND
,
179 SMB_VFS_OP_OFFLOAD_WRITE_RECV
,
180 SMB_VFS_OP_FGET_COMPRESSION
,
181 SMB_VFS_OP_SET_COMPRESSION
,
182 SMB_VFS_OP_SNAP_CHECK_PATH
,
183 SMB_VFS_OP_SNAP_CREATE
,
184 SMB_VFS_OP_SNAP_DELETE
,
186 /* DOS attribute operations. */
187 SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND
,
188 SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV
,
189 SMB_VFS_OP_FGET_DOS_ATTRIBUTES
,
190 SMB_VFS_OP_FSET_DOS_ATTRIBUTES
,
192 /* NT ACL operations. */
194 SMB_VFS_OP_FGET_NT_ACL
,
195 SMB_VFS_OP_FSET_NT_ACL
,
196 SMB_VFS_OP_AUDIT_FILE
,
198 /* POSIX ACL operations. */
200 SMB_VFS_OP_SYS_ACL_GET_FD
,
201 SMB_VFS_OP_SYS_ACL_BLOB_GET_FD
,
202 SMB_VFS_OP_SYS_ACL_SET_FD
,
203 SMB_VFS_OP_SYS_ACL_DELETE_DEF_FD
,
206 SMB_VFS_OP_GETXATTRAT_SEND
,
207 SMB_VFS_OP_GETXATTRAT_RECV
,
208 SMB_VFS_OP_FGETXATTR
,
209 SMB_VFS_OP_FLISTXATTR
,
210 SMB_VFS_OP_REMOVEXATTR
,
211 SMB_VFS_OP_FREMOVEXATTR
,
212 SMB_VFS_OP_FSETXATTR
,
215 SMB_VFS_OP_AIO_FORCE
,
217 /* offline operations */
218 SMB_VFS_OP_IS_OFFLINE
,
219 SMB_VFS_OP_SET_OFFLINE
,
221 /* Durable handle operations. */
222 SMB_VFS_OP_DURABLE_COOKIE
,
223 SMB_VFS_OP_DURABLE_DISCONNECT
,
224 SMB_VFS_OP_DURABLE_RECONNECT
,
226 SMB_VFS_OP_FREADDIR_ATTR
,
228 /* This should always be last enum value */
233 /* The following array *must* be in the same order as defined in vfs_op_type */
239 { SMB_VFS_OP_CONNECT
, "connect" },
240 { SMB_VFS_OP_DISCONNECT
, "disconnect" },
241 { SMB_VFS_OP_DISK_FREE
, "disk_free" },
242 { SMB_VFS_OP_GET_QUOTA
, "get_quota" },
243 { SMB_VFS_OP_SET_QUOTA
, "set_quota" },
244 { SMB_VFS_OP_GET_SHADOW_COPY_DATA
, "get_shadow_copy_data" },
245 { SMB_VFS_OP_STATVFS
, "statvfs" },
246 { SMB_VFS_OP_FS_CAPABILITIES
, "fs_capabilities" },
247 { SMB_VFS_OP_GET_DFS_REFERRALS
, "get_dfs_referrals" },
248 { SMB_VFS_OP_CREATE_DFS_PATHAT
, "create_dfs_pathat" },
249 { SMB_VFS_OP_READ_DFS_PATHAT
, "read_dfs_pathat" },
250 { SMB_VFS_OP_FDOPENDIR
, "fdopendir" },
251 { SMB_VFS_OP_READDIR
, "readdir" },
252 { SMB_VFS_OP_SEEKDIR
, "seekdir" },
253 { SMB_VFS_OP_TELLDIR
, "telldir" },
254 { SMB_VFS_OP_REWINDDIR
, "rewinddir" },
255 { SMB_VFS_OP_MKDIRAT
, "mkdirat" },
256 { SMB_VFS_OP_CLOSEDIR
, "closedir" },
257 { SMB_VFS_OP_OPEN
, "open" },
258 { SMB_VFS_OP_OPENAT
, "openat" },
259 { SMB_VFS_OP_CREATE_FILE
, "create_file" },
260 { SMB_VFS_OP_CLOSE
, "close" },
261 { SMB_VFS_OP_READ
, "read" },
262 { SMB_VFS_OP_PREAD
, "pread" },
263 { SMB_VFS_OP_PREAD_SEND
, "pread_send" },
264 { SMB_VFS_OP_PREAD_RECV
, "pread_recv" },
265 { SMB_VFS_OP_WRITE
, "write" },
266 { SMB_VFS_OP_PWRITE
, "pwrite" },
267 { SMB_VFS_OP_PWRITE_SEND
, "pwrite_send" },
268 { SMB_VFS_OP_PWRITE_RECV
, "pwrite_recv" },
269 { SMB_VFS_OP_LSEEK
, "lseek" },
270 { SMB_VFS_OP_SENDFILE
, "sendfile" },
271 { SMB_VFS_OP_RECVFILE
, "recvfile" },
272 { SMB_VFS_OP_RENAMEAT
, "renameat" },
273 { SMB_VFS_OP_FSYNC
, "fsync" },
274 { SMB_VFS_OP_FSYNC_SEND
, "fsync_send" },
275 { SMB_VFS_OP_FSYNC_RECV
, "fsync_recv" },
276 { SMB_VFS_OP_STAT
, "stat" },
277 { SMB_VFS_OP_FSTAT
, "fstat" },
278 { SMB_VFS_OP_LSTAT
, "lstat" },
279 { SMB_VFS_OP_GET_ALLOC_SIZE
, "get_alloc_size" },
280 { SMB_VFS_OP_UNLINKAT
, "unlinkat" },
281 { SMB_VFS_OP_FCHMOD
, "fchmod" },
282 { SMB_VFS_OP_FCHOWN
, "fchown" },
283 { SMB_VFS_OP_LCHOWN
, "lchown" },
284 { SMB_VFS_OP_CHDIR
, "chdir" },
285 { SMB_VFS_OP_GETWD
, "getwd" },
286 { SMB_VFS_OP_NTIMES
, "ntimes" },
287 { SMB_VFS_OP_FNTIMES
, "fntimes" },
288 { SMB_VFS_OP_FTRUNCATE
, "ftruncate" },
289 { SMB_VFS_OP_FALLOCATE
,"fallocate" },
290 { SMB_VFS_OP_LOCK
, "lock" },
291 { SMB_VFS_OP_FILESYSTEM_SHAREMODE
, "filesystem_sharemode" },
292 { SMB_VFS_OP_FCNTL
, "fcntl" },
293 { SMB_VFS_OP_LINUX_SETLEASE
, "linux_setlease" },
294 { SMB_VFS_OP_GETLOCK
, "getlock" },
295 { SMB_VFS_OP_SYMLINKAT
, "symlinkat" },
296 { SMB_VFS_OP_READLINKAT
,"readlinkat" },
297 { SMB_VFS_OP_LINKAT
, "linkat" },
298 { SMB_VFS_OP_MKNODAT
, "mknodat" },
299 { SMB_VFS_OP_REALPATH
, "realpath" },
300 { SMB_VFS_OP_FCHFLAGS
, "fchflags" },
301 { SMB_VFS_OP_FILE_ID_CREATE
, "file_id_create" },
302 { SMB_VFS_OP_FS_FILE_ID
, "fs_file_id" },
303 { SMB_VFS_OP_FSTREAMINFO
, "fstreaminfo" },
304 { SMB_VFS_OP_GET_REAL_FILENAME
, "get_real_filename" },
305 { SMB_VFS_OP_CONNECTPATH
, "connectpath" },
306 { SMB_VFS_OP_BRL_LOCK_WINDOWS
, "brl_lock_windows" },
307 { SMB_VFS_OP_BRL_UNLOCK_WINDOWS
, "brl_unlock_windows" },
308 { SMB_VFS_OP_STRICT_LOCK_CHECK
, "strict_lock_check" },
309 { SMB_VFS_OP_TRANSLATE_NAME
, "translate_name" },
310 { SMB_VFS_OP_PARENT_PATHNAME
, "parent_pathname" },
311 { SMB_VFS_OP_FSCTL
, "fsctl" },
312 { SMB_VFS_OP_OFFLOAD_READ_SEND
, "offload_read_send" },
313 { SMB_VFS_OP_OFFLOAD_READ_RECV
, "offload_read_recv" },
314 { SMB_VFS_OP_OFFLOAD_WRITE_SEND
, "offload_write_send" },
315 { SMB_VFS_OP_OFFLOAD_WRITE_RECV
, "offload_write_recv" },
316 { SMB_VFS_OP_FGET_COMPRESSION
, "fget_compression" },
317 { SMB_VFS_OP_SET_COMPRESSION
, "set_compression" },
318 { SMB_VFS_OP_SNAP_CHECK_PATH
, "snap_check_path" },
319 { SMB_VFS_OP_SNAP_CREATE
, "snap_create" },
320 { SMB_VFS_OP_SNAP_DELETE
, "snap_delete" },
321 { SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND
, "get_dos_attributes_send" },
322 { SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV
, "get_dos_attributes_recv" },
323 { SMB_VFS_OP_FGET_DOS_ATTRIBUTES
, "fget_dos_attributes" },
324 { SMB_VFS_OP_FSET_DOS_ATTRIBUTES
, "fset_dos_attributes" },
325 { SMB_VFS_OP_FGET_NT_ACL
, "fget_nt_acl" },
326 { SMB_VFS_OP_FSET_NT_ACL
, "fset_nt_acl" },
327 { SMB_VFS_OP_AUDIT_FILE
, "audit_file" },
328 { SMB_VFS_OP_SYS_ACL_GET_FD
, "sys_acl_get_fd" },
329 { SMB_VFS_OP_SYS_ACL_BLOB_GET_FD
, "sys_acl_blob_get_fd" },
330 { SMB_VFS_OP_SYS_ACL_SET_FD
, "sys_acl_set_fd" },
331 { SMB_VFS_OP_SYS_ACL_DELETE_DEF_FD
, "sys_acl_delete_def_fd" },
332 { SMB_VFS_OP_GETXATTRAT_SEND
, "getxattrat_send" },
333 { SMB_VFS_OP_GETXATTRAT_RECV
, "getxattrat_recv" },
334 { SMB_VFS_OP_FGETXATTR
, "fgetxattr" },
335 { SMB_VFS_OP_FLISTXATTR
, "flistxattr" },
336 { SMB_VFS_OP_REMOVEXATTR
, "removexattr" },
337 { SMB_VFS_OP_FREMOVEXATTR
, "fremovexattr" },
338 { SMB_VFS_OP_FSETXATTR
, "fsetxattr" },
339 { SMB_VFS_OP_AIO_FORCE
, "aio_force" },
340 { SMB_VFS_OP_IS_OFFLINE
, "is_offline" },
341 { SMB_VFS_OP_SET_OFFLINE
, "set_offline" },
342 { SMB_VFS_OP_DURABLE_COOKIE
, "durable_cookie" },
343 { SMB_VFS_OP_DURABLE_DISCONNECT
, "durable_disconnect" },
344 { SMB_VFS_OP_DURABLE_RECONNECT
, "durable_reconnect" },
345 { SMB_VFS_OP_FREADDIR_ATTR
, "freaddir_attr" },
346 { SMB_VFS_OP_LAST
, NULL
}
349 static int audit_syslog_facility(vfs_handle_struct
*handle
)
351 static const struct enum_list enum_log_facilities
[] = {
353 { LOG_AUTH
, "AUTH" },
356 { LOG_AUTHPRIV
, "AUTHPRIV" },
359 { LOG_AUDIT
, "AUDIT" },
362 { LOG_CONSOLE
, "CONSOLE" },
365 { LOG_CRON
, "CRON" },
368 { LOG_DAEMON
, "DAEMON" },
374 { LOG_INSTALL
, "INSTALL" },
377 { LOG_KERN
, "KERN" },
380 { LOG_LAUNCHD
, "LAUNCHD" },
383 { LOG_LFMT
, "LFMT" },
389 { LOG_MAIL
, "MAIL" },
392 { LOG_MEGASAFE
, "MEGASAFE" },
395 { LOG_NETINFO
, "NETINFO" },
398 { LOG_NEWS
, "NEWS" },
400 #ifdef LOG_NFACILITIES
401 { LOG_NFACILITIES
, "NFACILITIES" },
409 #ifdef LOG_REMOTEAUTH
410 { LOG_REMOTEAUTH
, "REMOTEAUTH" },
413 { LOG_SECURITY
, "SECURITY" },
416 { LOG_SYSLOG
, "SYSLOG" },
419 { LOG_USER
, "USER" },
422 { LOG_UUCP
, "UUCP" },
424 { LOG_LOCAL0
, "LOCAL0" },
425 { LOG_LOCAL1
, "LOCAL1" },
426 { LOG_LOCAL2
, "LOCAL2" },
427 { LOG_LOCAL3
, "LOCAL3" },
428 { LOG_LOCAL4
, "LOCAL4" },
429 { LOG_LOCAL5
, "LOCAL5" },
430 { LOG_LOCAL6
, "LOCAL6" },
431 { LOG_LOCAL7
, "LOCAL7" },
437 facility
= lp_parm_enum(SNUM(handle
->conn
), "full_audit", "facility", enum_log_facilities
, LOG_USER
);
442 static int audit_syslog_priority(vfs_handle_struct
*handle
)
444 static const struct enum_list enum_log_priorities
[] = {
445 { LOG_EMERG
, "EMERG" },
446 { LOG_ALERT
, "ALERT" },
447 { LOG_CRIT
, "CRIT" },
449 { LOG_WARNING
, "WARNING" },
450 { LOG_NOTICE
, "NOTICE" },
451 { LOG_INFO
, "INFO" },
452 { LOG_DEBUG
, "DEBUG" },
458 priority
= lp_parm_enum(SNUM(handle
->conn
), "full_audit", "priority",
459 enum_log_priorities
, LOG_NOTICE
);
460 if (priority
== -1) {
461 priority
= LOG_WARNING
;
467 static char *audit_prefix(TALLOC_CTX
*ctx
, connection_struct
*conn
)
469 const struct loadparm_substitution
*lp_sub
=
470 loadparm_s3_global_substitution();
474 prefix
= talloc_strdup(ctx
,
475 lp_parm_const_string(SNUM(conn
), "full_audit",
480 result
= talloc_sub_full(ctx
,
481 lp_servicename(talloc_tos(), lp_sub
, SNUM(conn
)),
482 conn
->session_info
->unix_info
->unix_name
,
484 conn
->session_info
->unix_token
->gid
,
485 conn
->session_info
->unix_info
->sanitized_username
,
486 conn
->session_info
->info
->domain_name
,
492 static bool log_success(struct vfs_full_audit_private_data
*pd
, vfs_op_type op
)
494 if (pd
->success_ops
== NULL
) {
498 return bitmap_query(pd
->success_ops
, op
);
501 static bool log_failure(struct vfs_full_audit_private_data
*pd
, vfs_op_type op
)
503 if (pd
->failure_ops
== NULL
)
506 return bitmap_query(pd
->failure_ops
, op
);
509 static struct bitmap
*init_bitmap(TALLOC_CTX
*mem_ctx
, const char **ops
)
517 bm
= bitmap_talloc(mem_ctx
, SMB_VFS_OP_LAST
);
519 DEBUG(0, ("Could not alloc bitmap -- "
520 "defaulting to logging everything\n"));
524 for (; *ops
!= NULL
; ops
+= 1) {
529 if (strequal(*ops
, "all")) {
530 for (i
=0; i
<SMB_VFS_OP_LAST
; i
++) {
536 if (strequal(*ops
, "none")) {
546 for (i
=0; i
<SMB_VFS_OP_LAST
; i
++) {
547 if ((vfs_op_names
[i
].name
== NULL
)
548 || (vfs_op_names
[i
].type
!= i
)) {
549 smb_panic("vfs_full_audit.c: name table not "
550 "in sync with vfs_op_type enums\n");
552 if (strequal(op
, vfs_op_names
[i
].name
)) {
561 if (i
== SMB_VFS_OP_LAST
) {
562 DEBUG(0, ("Could not find opname %s, logging all\n",
571 static const char *audit_opname(vfs_op_type op
)
573 if (op
>= SMB_VFS_OP_LAST
)
574 return "INVALID VFS OP";
575 return vfs_op_names
[op
].name
;
578 static TALLOC_CTX
*tmp_do_log_ctx
;
580 * Get us a temporary talloc context usable just for DEBUG arguments
582 static TALLOC_CTX
*do_log_ctx(void)
584 if (tmp_do_log_ctx
== NULL
) {
585 tmp_do_log_ctx
= talloc_named_const(NULL
, 0, "do_log_ctx");
587 return tmp_do_log_ctx
;
590 static void do_log(vfs_op_type op
, bool success
, vfs_handle_struct
*handle
,
591 const char *format
, ...) PRINTF_ATTRIBUTE(4, 5);
593 static void do_log(vfs_op_type op
, bool success
, vfs_handle_struct
*handle
,
594 const char *format
, ...)
596 struct vfs_full_audit_private_data
*pd
;
598 char *audit_pre
= NULL
;
602 SMB_VFS_HANDLE_GET_DATA(handle
, pd
,
603 struct vfs_full_audit_private_data
,
606 if (success
&& (!log_success(pd
, op
)))
609 if (!success
&& (!log_failure(pd
, op
)))
613 fstrcpy(err_msg
, "ok");
615 fstr_sprintf(err_msg
, "fail (%s)", strerror(errno
));
617 va_start(ap
, format
);
618 op_msg
= talloc_vasprintf(talloc_tos(), format
, ap
);
625 audit_pre
= audit_prefix(talloc_tos(), handle
->conn
);
631 * Specify the facility to interoperate with other syslog
632 * callers (smbd for example).
634 priority
= pd
->syslog_priority
| pd
->syslog_facility
;
636 syslog(priority
, "%s|%s|%s|%s\n",
637 audit_pre
? audit_pre
: "",
638 audit_opname(op
), err_msg
, op_msg
);
640 DEBUG(1, ("%s|%s|%s|%s\n",
641 audit_pre
? audit_pre
: "",
642 audit_opname(op
), err_msg
, op_msg
));
645 TALLOC_FREE(audit_pre
);
647 TALLOC_FREE(tmp_do_log_ctx
);
651 * Return a string using the do_log_ctx()
653 static const char *smb_fname_str_do_log(struct connection_struct
*conn
,
654 const struct smb_filename
*smb_fname
)
659 if (smb_fname
== NULL
) {
663 if (smb_fname
->base_name
[0] != '/') {
664 char *abs_name
= NULL
;
665 struct smb_filename
*fname_copy
= cp_smb_filename(
668 if (fname_copy
== NULL
) {
672 if (!ISDOT(smb_fname
->base_name
)) {
673 abs_name
= talloc_asprintf(do_log_ctx(),
675 conn
->cwd_fsp
->fsp_name
->base_name
,
676 smb_fname
->base_name
);
678 abs_name
= talloc_strdup(do_log_ctx(),
679 conn
->cwd_fsp
->fsp_name
->base_name
);
681 if (abs_name
== NULL
) {
684 fname_copy
->base_name
= abs_name
;
685 smb_fname
= fname_copy
;
688 status
= get_full_smb_filename(do_log_ctx(), smb_fname
, &fname
);
689 if (!NT_STATUS_IS_OK(status
)) {
696 * Return an fsp debug string using the do_log_ctx()
698 static const char *fsp_str_do_log(const struct files_struct
*fsp
)
700 return smb_fname_str_do_log(fsp
->conn
, fsp
->fsp_name
);
703 /* Implementation of vfs_ops. Pass everything on to the default
704 operation but log event first. */
706 static int smb_full_audit_connect(vfs_handle_struct
*handle
,
707 const char *svc
, const char *user
)
710 const char *none
[] = { "none" };
711 struct vfs_full_audit_private_data
*pd
= NULL
;
713 result
= SMB_VFS_NEXT_CONNECT(handle
, svc
, user
);
718 pd
= talloc_zero(handle
, struct vfs_full_audit_private_data
);
720 SMB_VFS_NEXT_DISCONNECT(handle
);
724 pd
->syslog_facility
= audit_syslog_facility(handle
);
725 if (pd
->syslog_facility
== -1) {
726 DEBUG(1, ("%s: Unknown facility %s\n", __func__
,
727 lp_parm_const_string(SNUM(handle
->conn
),
728 "full_audit", "facility",
730 SMB_VFS_NEXT_DISCONNECT(handle
);
734 pd
->syslog_priority
= audit_syslog_priority(handle
);
736 pd
->log_secdesc
= lp_parm_bool(SNUM(handle
->conn
),
737 "full_audit", "log_secdesc", false);
739 pd
->do_syslog
= lp_parm_bool(SNUM(handle
->conn
),
740 "full_audit", "syslog", true);
744 openlog("smbd_audit", 0, pd
->syslog_facility
);
748 pd
->success_ops
= init_bitmap(
749 pd
, lp_parm_string_list(SNUM(handle
->conn
), "full_audit",
751 pd
->failure_ops
= init_bitmap(
752 pd
, lp_parm_string_list(SNUM(handle
->conn
), "full_audit",
755 /* Store the private data. */
756 SMB_VFS_HANDLE_SET_DATA(handle
, pd
, NULL
,
757 struct vfs_full_audit_private_data
, return -1);
759 do_log(SMB_VFS_OP_CONNECT
, True
, handle
,
765 static void smb_full_audit_disconnect(vfs_handle_struct
*handle
)
767 const struct loadparm_substitution
*lp_sub
=
768 loadparm_s3_global_substitution();
770 SMB_VFS_NEXT_DISCONNECT(handle
);
772 do_log(SMB_VFS_OP_DISCONNECT
, True
, handle
,
773 "%s", lp_servicename(talloc_tos(), lp_sub
, SNUM(handle
->conn
)));
775 /* The bitmaps will be disconnected when the private
779 static uint64_t smb_full_audit_disk_free(vfs_handle_struct
*handle
,
780 const struct smb_filename
*smb_fname
,
787 result
= SMB_VFS_NEXT_DISK_FREE(handle
, smb_fname
, bsize
, dfree
, dsize
);
789 /* Don't have a reasonable notion of failure here */
791 do_log(SMB_VFS_OP_DISK_FREE
,
795 smb_fname_str_do_log(handle
->conn
, smb_fname
));
800 static int smb_full_audit_get_quota(struct vfs_handle_struct
*handle
,
801 const struct smb_filename
*smb_fname
,
802 enum SMB_QUOTA_TYPE qtype
,
808 result
= SMB_VFS_NEXT_GET_QUOTA(handle
, smb_fname
, qtype
, id
, qt
);
810 do_log(SMB_VFS_OP_GET_QUOTA
,
814 smb_fname_str_do_log(handle
->conn
, smb_fname
));
819 static int smb_full_audit_set_quota(struct vfs_handle_struct
*handle
,
820 enum SMB_QUOTA_TYPE qtype
, unid_t id
,
825 result
= SMB_VFS_NEXT_SET_QUOTA(handle
, qtype
, id
, qt
);
827 do_log(SMB_VFS_OP_SET_QUOTA
, (result
>= 0), handle
, "");
832 static int smb_full_audit_get_shadow_copy_data(struct vfs_handle_struct
*handle
,
833 struct files_struct
*fsp
,
834 struct shadow_copy_data
*shadow_copy_data
,
839 result
= SMB_VFS_NEXT_GET_SHADOW_COPY_DATA(handle
, fsp
, shadow_copy_data
, labels
);
841 do_log(SMB_VFS_OP_GET_SHADOW_COPY_DATA
, (result
>= 0), handle
, "");
846 static int smb_full_audit_statvfs(struct vfs_handle_struct
*handle
,
847 const struct smb_filename
*smb_fname
,
848 struct vfs_statvfs_struct
*statbuf
)
852 result
= SMB_VFS_NEXT_STATVFS(handle
, smb_fname
, statbuf
);
854 do_log(SMB_VFS_OP_STATVFS
, (result
>= 0), handle
, "");
859 static uint32_t smb_full_audit_fs_capabilities(struct vfs_handle_struct
*handle
, enum timestamp_set_resolution
*p_ts_res
)
863 result
= SMB_VFS_NEXT_FS_CAPABILITIES(handle
, p_ts_res
);
865 do_log(SMB_VFS_OP_FS_CAPABILITIES
, true, handle
, "");
870 static NTSTATUS
smb_full_audit_get_dfs_referrals(
871 struct vfs_handle_struct
*handle
,
872 struct dfs_GetDFSReferral
*r
)
876 status
= SMB_VFS_NEXT_GET_DFS_REFERRALS(handle
, r
);
878 do_log(SMB_VFS_OP_GET_DFS_REFERRALS
, NT_STATUS_IS_OK(status
),
884 static NTSTATUS
smb_full_audit_create_dfs_pathat(struct vfs_handle_struct
*handle
,
885 struct files_struct
*dirfsp
,
886 const struct smb_filename
*smb_fname
,
887 const struct referral
*reflist
,
888 size_t referral_count
)
891 struct smb_filename
*full_fname
= NULL
;
893 full_fname
= full_path_from_dirfsp_atname(talloc_tos(),
896 if (full_fname
== NULL
) {
897 return NT_STATUS_NO_MEMORY
;
900 status
= SMB_VFS_NEXT_CREATE_DFS_PATHAT(handle
,
906 do_log(SMB_VFS_OP_CREATE_DFS_PATHAT
,
907 NT_STATUS_IS_OK(status
),
910 smb_fname_str_do_log(handle
->conn
, full_fname
));
912 TALLOC_FREE(full_fname
);
916 static NTSTATUS
smb_full_audit_read_dfs_pathat(struct vfs_handle_struct
*handle
,
918 struct files_struct
*dirfsp
,
919 struct smb_filename
*smb_fname
,
920 struct referral
**ppreflist
,
921 size_t *preferral_count
)
923 struct smb_filename
*full_fname
= NULL
;
926 full_fname
= full_path_from_dirfsp_atname(talloc_tos(),
929 if (full_fname
== NULL
) {
930 return NT_STATUS_NO_MEMORY
;
933 status
= SMB_VFS_NEXT_READ_DFS_PATHAT(handle
,
940 do_log(SMB_VFS_OP_READ_DFS_PATHAT
,
941 NT_STATUS_IS_OK(status
),
944 smb_fname_str_do_log(handle
->conn
, full_fname
));
946 TALLOC_FREE(full_fname
);
950 static NTSTATUS
smb_full_audit_snap_check_path(struct vfs_handle_struct
*handle
,
952 const char *service_path
,
957 status
= SMB_VFS_NEXT_SNAP_CHECK_PATH(handle
, mem_ctx
, service_path
,
959 do_log(SMB_VFS_OP_SNAP_CHECK_PATH
, NT_STATUS_IS_OK(status
),
965 static NTSTATUS
smb_full_audit_snap_create(struct vfs_handle_struct
*handle
,
967 const char *base_volume
,
975 status
= SMB_VFS_NEXT_SNAP_CREATE(handle
, mem_ctx
, base_volume
, tstamp
,
976 rw
, base_path
, snap_path
);
977 do_log(SMB_VFS_OP_SNAP_CREATE
, NT_STATUS_IS_OK(status
), handle
, "");
982 static NTSTATUS
smb_full_audit_snap_delete(struct vfs_handle_struct
*handle
,
989 status
= SMB_VFS_NEXT_SNAP_DELETE(handle
, mem_ctx
, base_path
,
991 do_log(SMB_VFS_OP_SNAP_DELETE
, NT_STATUS_IS_OK(status
), handle
, "");
996 static DIR *smb_full_audit_fdopendir(vfs_handle_struct
*handle
,
997 files_struct
*fsp
, const char *mask
, uint32_t attr
)
1001 result
= SMB_VFS_NEXT_FDOPENDIR(handle
, fsp
, mask
, attr
);
1003 do_log(SMB_VFS_OP_FDOPENDIR
, (result
!= NULL
), handle
, "%s",
1004 fsp_str_do_log(fsp
));
1009 static struct dirent
*smb_full_audit_readdir(vfs_handle_struct
*handle
,
1010 struct files_struct
*dirfsp
,
1012 SMB_STRUCT_STAT
*sbuf
)
1014 struct dirent
*result
;
1016 result
= SMB_VFS_NEXT_READDIR(handle
, dirfsp
, dirp
, sbuf
);
1018 /* This operation has no reasonable error condition
1019 * (End of dir is also failure), so always succeed.
1021 do_log(SMB_VFS_OP_READDIR
, True
, handle
, "");
1026 static void smb_full_audit_seekdir(vfs_handle_struct
*handle
,
1027 DIR *dirp
, long offset
)
1029 SMB_VFS_NEXT_SEEKDIR(handle
, dirp
, offset
);
1031 do_log(SMB_VFS_OP_SEEKDIR
, True
, handle
, "");
1034 static long smb_full_audit_telldir(vfs_handle_struct
*handle
,
1039 result
= SMB_VFS_NEXT_TELLDIR(handle
, dirp
);
1041 do_log(SMB_VFS_OP_TELLDIR
, True
, handle
, "");
1046 static void smb_full_audit_rewinddir(vfs_handle_struct
*handle
,
1049 SMB_VFS_NEXT_REWINDDIR(handle
, dirp
);
1051 do_log(SMB_VFS_OP_REWINDDIR
, True
, handle
, "");
1054 static int smb_full_audit_mkdirat(vfs_handle_struct
*handle
,
1055 struct files_struct
*dirfsp
,
1056 const struct smb_filename
*smb_fname
,
1059 struct smb_filename
*full_fname
= NULL
;
1062 full_fname
= full_path_from_dirfsp_atname(talloc_tos(),
1065 if (full_fname
== NULL
) {
1070 result
= SMB_VFS_NEXT_MKDIRAT(handle
,
1075 do_log(SMB_VFS_OP_MKDIRAT
,
1079 smb_fname_str_do_log(handle
->conn
, full_fname
));
1081 TALLOC_FREE(full_fname
);
1086 static int smb_full_audit_closedir(vfs_handle_struct
*handle
,
1091 result
= SMB_VFS_NEXT_CLOSEDIR(handle
, dirp
);
1093 do_log(SMB_VFS_OP_CLOSEDIR
, (result
>= 0), handle
, "");
1098 static int smb_full_audit_openat(vfs_handle_struct
*handle
,
1099 const struct files_struct
*dirfsp
,
1100 const struct smb_filename
*smb_fname
,
1101 struct files_struct
*fsp
,
1107 result
= SMB_VFS_NEXT_OPENAT(handle
, dirfsp
, smb_fname
, fsp
, flags
, mode
);
1109 do_log(SMB_VFS_OP_OPENAT
, (result
>= 0), handle
, "%s|%s",
1110 ((flags
& O_WRONLY
) || (flags
& O_RDWR
))?"w":"r",
1111 fsp_str_do_log(fsp
));
1116 static NTSTATUS
smb_full_audit_create_file(vfs_handle_struct
*handle
,
1117 struct smb_request
*req
,
1118 struct smb_filename
*smb_fname
,
1119 uint32_t access_mask
,
1120 uint32_t share_access
,
1121 uint32_t create_disposition
,
1122 uint32_t create_options
,
1123 uint32_t file_attributes
,
1124 uint32_t oplock_request
,
1125 const struct smb2_lease
*lease
,
1126 uint64_t allocation_size
,
1127 uint32_t private_flags
,
1128 struct security_descriptor
*sd
,
1129 struct ea_list
*ea_list
,
1130 files_struct
**result_fsp
,
1132 const struct smb2_create_blobs
*in_context_blobs
,
1133 struct smb2_create_blobs
*out_context_blobs
)
1136 const char* str_create_disposition
;
1138 switch (create_disposition
) {
1139 case FILE_SUPERSEDE
:
1140 str_create_disposition
= "supersede";
1142 case FILE_OVERWRITE_IF
:
1143 str_create_disposition
= "overwrite_if";
1146 str_create_disposition
= "open";
1148 case FILE_OVERWRITE
:
1149 str_create_disposition
= "overwrite";
1152 str_create_disposition
= "create";
1155 str_create_disposition
= "open_if";
1158 str_create_disposition
= "unknown";
1161 result
= SMB_VFS_NEXT_CREATE_FILE(
1162 handle
, /* handle */
1164 smb_fname
, /* fname */
1165 access_mask
, /* access_mask */
1166 share_access
, /* share_access */
1167 create_disposition
, /* create_disposition*/
1168 create_options
, /* create_options */
1169 file_attributes
, /* file_attributes */
1170 oplock_request
, /* oplock_request */
1172 allocation_size
, /* allocation_size */
1175 ea_list
, /* ea_list */
1176 result_fsp
, /* result */
1178 in_context_blobs
, out_context_blobs
); /* create context */
1180 do_log(SMB_VFS_OP_CREATE_FILE
, (NT_STATUS_IS_OK(result
)), handle
,
1181 "0x%x|%s|%s|%s", access_mask
,
1182 create_options
& FILE_DIRECTORY_FILE
? "dir" : "file",
1183 str_create_disposition
,
1184 smb_fname_str_do_log(handle
->conn
, smb_fname
));
1189 static int smb_full_audit_close(vfs_handle_struct
*handle
, files_struct
*fsp
)
1193 result
= SMB_VFS_NEXT_CLOSE(handle
, fsp
);
1195 do_log(SMB_VFS_OP_CLOSE
, (result
>= 0), handle
, "%s",
1196 fsp_str_do_log(fsp
));
1201 static ssize_t
smb_full_audit_pread(vfs_handle_struct
*handle
, files_struct
*fsp
,
1202 void *data
, size_t n
, off_t offset
)
1206 result
= SMB_VFS_NEXT_PREAD(handle
, fsp
, data
, n
, offset
);
1208 do_log(SMB_VFS_OP_PREAD
, (result
>= 0), handle
, "%s",
1209 fsp_str_do_log(fsp
));
1214 struct smb_full_audit_pread_state
{
1215 vfs_handle_struct
*handle
;
1218 struct vfs_aio_state vfs_aio_state
;
1221 static void smb_full_audit_pread_done(struct tevent_req
*subreq
);
1223 static struct tevent_req
*smb_full_audit_pread_send(
1224 struct vfs_handle_struct
*handle
, TALLOC_CTX
*mem_ctx
,
1225 struct tevent_context
*ev
, struct files_struct
*fsp
,
1226 void *data
, size_t n
, off_t offset
)
1228 struct tevent_req
*req
, *subreq
;
1229 struct smb_full_audit_pread_state
*state
;
1231 req
= tevent_req_create(mem_ctx
, &state
,
1232 struct smb_full_audit_pread_state
);
1234 do_log(SMB_VFS_OP_PREAD_SEND
, false, handle
, "%s",
1235 fsp_str_do_log(fsp
));
1238 state
->handle
= handle
;
1241 subreq
= SMB_VFS_NEXT_PREAD_SEND(state
, ev
, handle
, fsp
, data
,
1243 if (tevent_req_nomem(subreq
, req
)) {
1244 do_log(SMB_VFS_OP_PREAD_SEND
, false, handle
, "%s",
1245 fsp_str_do_log(fsp
));
1246 return tevent_req_post(req
, ev
);
1248 tevent_req_set_callback(subreq
, smb_full_audit_pread_done
, req
);
1250 do_log(SMB_VFS_OP_PREAD_SEND
, true, handle
, "%s", fsp_str_do_log(fsp
));
1254 static void smb_full_audit_pread_done(struct tevent_req
*subreq
)
1256 struct tevent_req
*req
= tevent_req_callback_data(
1257 subreq
, struct tevent_req
);
1258 struct smb_full_audit_pread_state
*state
= tevent_req_data(
1259 req
, struct smb_full_audit_pread_state
);
1261 state
->ret
= SMB_VFS_PREAD_RECV(subreq
, &state
->vfs_aio_state
);
1262 TALLOC_FREE(subreq
);
1263 tevent_req_done(req
);
1266 static ssize_t
smb_full_audit_pread_recv(struct tevent_req
*req
,
1267 struct vfs_aio_state
*vfs_aio_state
)
1269 struct smb_full_audit_pread_state
*state
= tevent_req_data(
1270 req
, struct smb_full_audit_pread_state
);
1272 if (tevent_req_is_unix_error(req
, &vfs_aio_state
->error
)) {
1273 do_log(SMB_VFS_OP_PREAD_RECV
, false, state
->handle
, "%s",
1274 fsp_str_do_log(state
->fsp
));
1278 do_log(SMB_VFS_OP_PREAD_RECV
, (state
->ret
>= 0), state
->handle
, "%s",
1279 fsp_str_do_log(state
->fsp
));
1281 *vfs_aio_state
= state
->vfs_aio_state
;
1285 static ssize_t
smb_full_audit_pwrite(vfs_handle_struct
*handle
, files_struct
*fsp
,
1286 const void *data
, size_t n
,
1291 result
= SMB_VFS_NEXT_PWRITE(handle
, fsp
, data
, n
, offset
);
1293 do_log(SMB_VFS_OP_PWRITE
, (result
>= 0), handle
, "%s",
1294 fsp_str_do_log(fsp
));
1299 struct smb_full_audit_pwrite_state
{
1300 vfs_handle_struct
*handle
;
1303 struct vfs_aio_state vfs_aio_state
;
1306 static void smb_full_audit_pwrite_done(struct tevent_req
*subreq
);
1308 static struct tevent_req
*smb_full_audit_pwrite_send(
1309 struct vfs_handle_struct
*handle
, TALLOC_CTX
*mem_ctx
,
1310 struct tevent_context
*ev
, struct files_struct
*fsp
,
1311 const void *data
, size_t n
, off_t offset
)
1313 struct tevent_req
*req
, *subreq
;
1314 struct smb_full_audit_pwrite_state
*state
;
1316 req
= tevent_req_create(mem_ctx
, &state
,
1317 struct smb_full_audit_pwrite_state
);
1319 do_log(SMB_VFS_OP_PWRITE_SEND
, false, handle
, "%s",
1320 fsp_str_do_log(fsp
));
1323 state
->handle
= handle
;
1326 subreq
= SMB_VFS_NEXT_PWRITE_SEND(state
, ev
, handle
, fsp
, data
,
1328 if (tevent_req_nomem(subreq
, req
)) {
1329 do_log(SMB_VFS_OP_PWRITE_SEND
, false, handle
, "%s",
1330 fsp_str_do_log(fsp
));
1331 return tevent_req_post(req
, ev
);
1333 tevent_req_set_callback(subreq
, smb_full_audit_pwrite_done
, req
);
1335 do_log(SMB_VFS_OP_PWRITE_SEND
, true, handle
, "%s",
1336 fsp_str_do_log(fsp
));
1340 static void smb_full_audit_pwrite_done(struct tevent_req
*subreq
)
1342 struct tevent_req
*req
= tevent_req_callback_data(
1343 subreq
, struct tevent_req
);
1344 struct smb_full_audit_pwrite_state
*state
= tevent_req_data(
1345 req
, struct smb_full_audit_pwrite_state
);
1347 state
->ret
= SMB_VFS_PWRITE_RECV(subreq
, &state
->vfs_aio_state
);
1348 TALLOC_FREE(subreq
);
1349 tevent_req_done(req
);
1352 static ssize_t
smb_full_audit_pwrite_recv(struct tevent_req
*req
,
1353 struct vfs_aio_state
*vfs_aio_state
)
1355 struct smb_full_audit_pwrite_state
*state
= tevent_req_data(
1356 req
, struct smb_full_audit_pwrite_state
);
1358 if (tevent_req_is_unix_error(req
, &vfs_aio_state
->error
)) {
1359 do_log(SMB_VFS_OP_PWRITE_RECV
, false, state
->handle
, "%s",
1360 fsp_str_do_log(state
->fsp
));
1364 do_log(SMB_VFS_OP_PWRITE_RECV
, (state
->ret
>= 0), state
->handle
, "%s",
1365 fsp_str_do_log(state
->fsp
));
1367 *vfs_aio_state
= state
->vfs_aio_state
;
1371 static off_t
smb_full_audit_lseek(vfs_handle_struct
*handle
, files_struct
*fsp
,
1372 off_t offset
, int whence
)
1376 result
= SMB_VFS_NEXT_LSEEK(handle
, fsp
, offset
, whence
);
1378 do_log(SMB_VFS_OP_LSEEK
, (result
!= (ssize_t
)-1), handle
,
1379 "%s", fsp_str_do_log(fsp
));
1384 static ssize_t
smb_full_audit_sendfile(vfs_handle_struct
*handle
, int tofd
,
1385 files_struct
*fromfsp
,
1386 const DATA_BLOB
*hdr
, off_t offset
,
1391 result
= SMB_VFS_NEXT_SENDFILE(handle
, tofd
, fromfsp
, hdr
, offset
, n
);
1393 do_log(SMB_VFS_OP_SENDFILE
, (result
>= 0), handle
,
1394 "%s", fsp_str_do_log(fromfsp
));
1399 static ssize_t
smb_full_audit_recvfile(vfs_handle_struct
*handle
, int fromfd
,
1400 files_struct
*tofsp
,
1406 result
= SMB_VFS_NEXT_RECVFILE(handle
, fromfd
, tofsp
, offset
, n
);
1408 do_log(SMB_VFS_OP_RECVFILE
, (result
>= 0), handle
,
1409 "%s", fsp_str_do_log(tofsp
));
1414 static int smb_full_audit_renameat(vfs_handle_struct
*handle
,
1415 files_struct
*srcfsp
,
1416 const struct smb_filename
*smb_fname_src
,
1417 files_struct
*dstfsp
,
1418 const struct smb_filename
*smb_fname_dst
)
1422 struct smb_filename
*full_fname_src
= NULL
;
1423 struct smb_filename
*full_fname_dst
= NULL
;
1425 full_fname_src
= full_path_from_dirfsp_atname(talloc_tos(),
1428 if (full_fname_src
== NULL
) {
1432 full_fname_dst
= full_path_from_dirfsp_atname(talloc_tos(),
1435 if (full_fname_dst
== NULL
) {
1436 TALLOC_FREE(full_fname_src
);
1441 result
= SMB_VFS_NEXT_RENAMEAT(handle
,
1448 saved_errno
= errno
;
1450 do_log(SMB_VFS_OP_RENAMEAT
, (result
>= 0), handle
, "%s|%s",
1451 smb_fname_str_do_log(handle
->conn
, full_fname_src
),
1452 smb_fname_str_do_log(handle
->conn
, full_fname_dst
));
1454 TALLOC_FREE(full_fname_src
);
1455 TALLOC_FREE(full_fname_dst
);
1458 errno
= saved_errno
;
1463 struct smb_full_audit_fsync_state
{
1464 vfs_handle_struct
*handle
;
1467 struct vfs_aio_state vfs_aio_state
;
1470 static void smb_full_audit_fsync_done(struct tevent_req
*subreq
);
1472 static struct tevent_req
*smb_full_audit_fsync_send(
1473 struct vfs_handle_struct
*handle
, TALLOC_CTX
*mem_ctx
,
1474 struct tevent_context
*ev
, struct files_struct
*fsp
)
1476 struct tevent_req
*req
, *subreq
;
1477 struct smb_full_audit_fsync_state
*state
;
1479 req
= tevent_req_create(mem_ctx
, &state
,
1480 struct smb_full_audit_fsync_state
);
1482 do_log(SMB_VFS_OP_FSYNC_SEND
, false, handle
, "%s",
1483 fsp_str_do_log(fsp
));
1486 state
->handle
= handle
;
1489 subreq
= SMB_VFS_NEXT_FSYNC_SEND(state
, ev
, handle
, fsp
);
1490 if (tevent_req_nomem(subreq
, req
)) {
1491 do_log(SMB_VFS_OP_FSYNC_SEND
, false, handle
, "%s",
1492 fsp_str_do_log(fsp
));
1493 return tevent_req_post(req
, ev
);
1495 tevent_req_set_callback(subreq
, smb_full_audit_fsync_done
, req
);
1497 do_log(SMB_VFS_OP_FSYNC_SEND
, true, handle
, "%s", fsp_str_do_log(fsp
));
1501 static void smb_full_audit_fsync_done(struct tevent_req
*subreq
)
1503 struct tevent_req
*req
= tevent_req_callback_data(
1504 subreq
, struct tevent_req
);
1505 struct smb_full_audit_fsync_state
*state
= tevent_req_data(
1506 req
, struct smb_full_audit_fsync_state
);
1508 state
->ret
= SMB_VFS_FSYNC_RECV(subreq
, &state
->vfs_aio_state
);
1509 TALLOC_FREE(subreq
);
1510 tevent_req_done(req
);
1513 static int smb_full_audit_fsync_recv(struct tevent_req
*req
,
1514 struct vfs_aio_state
*vfs_aio_state
)
1516 struct smb_full_audit_fsync_state
*state
= tevent_req_data(
1517 req
, struct smb_full_audit_fsync_state
);
1519 if (tevent_req_is_unix_error(req
, &vfs_aio_state
->error
)) {
1520 do_log(SMB_VFS_OP_FSYNC_RECV
, false, state
->handle
, "%s",
1521 fsp_str_do_log(state
->fsp
));
1525 do_log(SMB_VFS_OP_FSYNC_RECV
, (state
->ret
>= 0), state
->handle
, "%s",
1526 fsp_str_do_log(state
->fsp
));
1528 *vfs_aio_state
= state
->vfs_aio_state
;
1532 static int smb_full_audit_stat(vfs_handle_struct
*handle
,
1533 struct smb_filename
*smb_fname
)
1537 result
= SMB_VFS_NEXT_STAT(handle
, smb_fname
);
1539 do_log(SMB_VFS_OP_STAT
, (result
>= 0), handle
, "%s",
1540 smb_fname_str_do_log(handle
->conn
, smb_fname
));
1545 static int smb_full_audit_fstat(vfs_handle_struct
*handle
, files_struct
*fsp
,
1546 SMB_STRUCT_STAT
*sbuf
)
1550 result
= SMB_VFS_NEXT_FSTAT(handle
, fsp
, sbuf
);
1552 do_log(SMB_VFS_OP_FSTAT
, (result
>= 0), handle
, "%s",
1553 fsp_str_do_log(fsp
));
1558 static int smb_full_audit_lstat(vfs_handle_struct
*handle
,
1559 struct smb_filename
*smb_fname
)
1563 result
= SMB_VFS_NEXT_LSTAT(handle
, smb_fname
);
1565 do_log(SMB_VFS_OP_LSTAT
, (result
>= 0), handle
, "%s",
1566 smb_fname_str_do_log(handle
->conn
, smb_fname
));
1571 static uint64_t smb_full_audit_get_alloc_size(vfs_handle_struct
*handle
,
1572 files_struct
*fsp
, const SMB_STRUCT_STAT
*sbuf
)
1576 result
= SMB_VFS_NEXT_GET_ALLOC_SIZE(handle
, fsp
, sbuf
);
1578 do_log(SMB_VFS_OP_GET_ALLOC_SIZE
, (result
!= (uint64_t)-1), handle
,
1579 "%llu", (unsigned long long)result
);
1584 static int smb_full_audit_unlinkat(vfs_handle_struct
*handle
,
1585 struct files_struct
*dirfsp
,
1586 const struct smb_filename
*smb_fname
,
1589 struct smb_filename
*full_fname
= NULL
;
1592 full_fname
= full_path_from_dirfsp_atname(talloc_tos(),
1595 if (full_fname
== NULL
) {
1599 result
= SMB_VFS_NEXT_UNLINKAT(handle
,
1604 do_log(SMB_VFS_OP_UNLINKAT
, (result
>= 0), handle
, "%s",
1605 smb_fname_str_do_log(handle
->conn
, full_fname
));
1607 TALLOC_FREE(full_fname
);
1611 static int smb_full_audit_fchmod(vfs_handle_struct
*handle
, files_struct
*fsp
,
1616 result
= SMB_VFS_NEXT_FCHMOD(handle
, fsp
, mode
);
1618 do_log(SMB_VFS_OP_FCHMOD
, (result
>= 0), handle
,
1619 "%s|%o", fsp_str_do_log(fsp
), mode
);
1624 static int smb_full_audit_fchown(vfs_handle_struct
*handle
, files_struct
*fsp
,
1625 uid_t uid
, gid_t gid
)
1629 result
= SMB_VFS_NEXT_FCHOWN(handle
, fsp
, uid
, gid
);
1631 do_log(SMB_VFS_OP_FCHOWN
, (result
>= 0), handle
, "%s|%ld|%ld",
1632 fsp_str_do_log(fsp
), (long int)uid
, (long int)gid
);
1637 static int smb_full_audit_lchown(vfs_handle_struct
*handle
,
1638 const struct smb_filename
*smb_fname
,
1644 result
= SMB_VFS_NEXT_LCHOWN(handle
, smb_fname
, uid
, gid
);
1646 do_log(SMB_VFS_OP_LCHOWN
, (result
>= 0), handle
, "%s|%ld|%ld",
1647 smb_fname
->base_name
, (long int)uid
, (long int)gid
);
1652 static int smb_full_audit_chdir(vfs_handle_struct
*handle
,
1653 const struct smb_filename
*smb_fname
)
1657 result
= SMB_VFS_NEXT_CHDIR(handle
, smb_fname
);
1659 do_log(SMB_VFS_OP_CHDIR
,
1663 smb_fname_str_do_log(handle
->conn
, smb_fname
));
1668 static struct smb_filename
*smb_full_audit_getwd(vfs_handle_struct
*handle
,
1671 struct smb_filename
*result
;
1673 result
= SMB_VFS_NEXT_GETWD(handle
, ctx
);
1675 do_log(SMB_VFS_OP_GETWD
, (result
!= NULL
), handle
, "%s",
1676 result
== NULL
? "" : result
->base_name
);
1681 static int smb_full_audit_fntimes(vfs_handle_struct
*handle
,
1683 struct smb_file_time
*ft
)
1686 time_t create_time
= convert_timespec_to_time_t(ft
->create_time
);
1687 time_t atime
= convert_timespec_to_time_t(ft
->atime
);
1688 time_t mtime
= convert_timespec_to_time_t(ft
->mtime
);
1689 time_t ctime
= convert_timespec_to_time_t(ft
->ctime
);
1690 const char *create_time_str
= "";
1691 const char *atime_str
= "";
1692 const char *mtime_str
= "";
1693 const char *ctime_str
= "";
1694 TALLOC_CTX
*frame
= talloc_stackframe();
1696 if (frame
== NULL
) {
1701 result
= SMB_VFS_NEXT_FNTIMES(handle
, fsp
, ft
);
1703 if (create_time
> 0) {
1704 create_time_str
= timestring(frame
, create_time
);
1707 atime_str
= timestring(frame
, atime
);
1710 mtime_str
= timestring(frame
, mtime
);
1713 ctime_str
= timestring(frame
, ctime
);
1716 do_log(SMB_VFS_OP_FNTIMES
,
1720 fsp_str_do_log(fsp
),
1731 static int smb_full_audit_ftruncate(vfs_handle_struct
*handle
, files_struct
*fsp
,
1736 result
= SMB_VFS_NEXT_FTRUNCATE(handle
, fsp
, len
);
1738 do_log(SMB_VFS_OP_FTRUNCATE
, (result
>= 0), handle
,
1739 "%s", fsp_str_do_log(fsp
));
1744 static int smb_full_audit_fallocate(vfs_handle_struct
*handle
, files_struct
*fsp
,
1751 result
= SMB_VFS_NEXT_FALLOCATE(handle
, fsp
, mode
, offset
, len
);
1753 do_log(SMB_VFS_OP_FALLOCATE
, (result
>= 0), handle
,
1754 "%s", fsp_str_do_log(fsp
));
1759 static bool smb_full_audit_lock(vfs_handle_struct
*handle
, files_struct
*fsp
,
1760 int op
, off_t offset
, off_t count
, int type
)
1764 result
= SMB_VFS_NEXT_LOCK(handle
, fsp
, op
, offset
, count
, type
);
1766 do_log(SMB_VFS_OP_LOCK
, result
, handle
, "%s", fsp_str_do_log(fsp
));
1771 static int smb_full_audit_filesystem_sharemode(struct vfs_handle_struct
*handle
,
1772 struct files_struct
*fsp
,
1773 uint32_t share_access
,
1774 uint32_t access_mask
)
1778 result
= SMB_VFS_NEXT_FILESYSTEM_SHAREMODE(handle
,
1783 do_log(SMB_VFS_OP_FILESYSTEM_SHAREMODE
, (result
>= 0), handle
, "%s",
1784 fsp_str_do_log(fsp
));
1789 static int smb_full_audit_fcntl(struct vfs_handle_struct
*handle
,
1790 struct files_struct
*fsp
,
1791 int cmd
, va_list cmd_arg
)
1794 va_list dup_cmd_arg
;
1797 va_copy(dup_cmd_arg
, cmd_arg
);
1798 arg
= va_arg(dup_cmd_arg
, void *);
1799 result
= SMB_VFS_NEXT_FCNTL(handle
, fsp
, cmd
, arg
);
1800 va_end(dup_cmd_arg
);
1802 do_log(SMB_VFS_OP_FCNTL
, (result
>= 0), handle
, "%s",
1803 fsp_str_do_log(fsp
));
1808 static int smb_full_audit_linux_setlease(vfs_handle_struct
*handle
, files_struct
*fsp
,
1813 result
= SMB_VFS_NEXT_LINUX_SETLEASE(handle
, fsp
, leasetype
);
1815 do_log(SMB_VFS_OP_LINUX_SETLEASE
, (result
>= 0), handle
, "%s",
1816 fsp_str_do_log(fsp
));
1821 static bool smb_full_audit_getlock(vfs_handle_struct
*handle
, files_struct
*fsp
,
1822 off_t
*poffset
, off_t
*pcount
, int *ptype
, pid_t
*ppid
)
1826 result
= SMB_VFS_NEXT_GETLOCK(handle
, fsp
, poffset
, pcount
, ptype
, ppid
);
1828 do_log(SMB_VFS_OP_GETLOCK
, result
, handle
, "%s", fsp_str_do_log(fsp
));
1833 static int smb_full_audit_symlinkat(vfs_handle_struct
*handle
,
1834 const struct smb_filename
*link_contents
,
1835 struct files_struct
*dirfsp
,
1836 const struct smb_filename
*new_smb_fname
)
1838 struct smb_filename
*full_fname
= NULL
;
1841 full_fname
= full_path_from_dirfsp_atname(talloc_tos(),
1844 if (full_fname
== NULL
) {
1848 result
= SMB_VFS_NEXT_SYMLINKAT(handle
,
1853 do_log(SMB_VFS_OP_SYMLINKAT
,
1857 link_contents
->base_name
,
1858 smb_fname_str_do_log(handle
->conn
, full_fname
));
1860 TALLOC_FREE(full_fname
);
1865 static int smb_full_audit_readlinkat(vfs_handle_struct
*handle
,
1866 const struct files_struct
*dirfsp
,
1867 const struct smb_filename
*smb_fname
,
1871 struct smb_filename
*full_fname
= NULL
;
1874 full_fname
= full_path_from_dirfsp_atname(talloc_tos(),
1877 if (full_fname
== NULL
) {
1881 result
= SMB_VFS_NEXT_READLINKAT(handle
,
1887 do_log(SMB_VFS_OP_READLINKAT
,
1891 smb_fname_str_do_log(handle
->conn
, full_fname
));
1893 TALLOC_FREE(full_fname
);
1898 static int smb_full_audit_linkat(vfs_handle_struct
*handle
,
1899 files_struct
*srcfsp
,
1900 const struct smb_filename
*old_smb_fname
,
1901 files_struct
*dstfsp
,
1902 const struct smb_filename
*new_smb_fname
,
1905 struct smb_filename
*old_full_fname
= NULL
;
1906 struct smb_filename
*new_full_fname
= NULL
;
1909 old_full_fname
= full_path_from_dirfsp_atname(talloc_tos(),
1912 if (old_full_fname
== NULL
) {
1915 new_full_fname
= full_path_from_dirfsp_atname(talloc_tos(),
1918 if (new_full_fname
== NULL
) {
1919 TALLOC_FREE(old_full_fname
);
1922 result
= SMB_VFS_NEXT_LINKAT(handle
,
1929 do_log(SMB_VFS_OP_LINKAT
,
1933 smb_fname_str_do_log(handle
->conn
, old_full_fname
),
1934 smb_fname_str_do_log(handle
->conn
, new_full_fname
));
1936 TALLOC_FREE(old_full_fname
);
1937 TALLOC_FREE(new_full_fname
);
1942 static int smb_full_audit_mknodat(vfs_handle_struct
*handle
,
1943 files_struct
*dirfsp
,
1944 const struct smb_filename
*smb_fname
,
1948 struct smb_filename
*full_fname
= NULL
;
1951 full_fname
= full_path_from_dirfsp_atname(talloc_tos(),
1954 if (full_fname
== NULL
) {
1958 result
= SMB_VFS_NEXT_MKNODAT(handle
,
1964 do_log(SMB_VFS_OP_MKNODAT
,
1968 smb_fname_str_do_log(handle
->conn
, full_fname
));
1970 TALLOC_FREE(full_fname
);
1975 static struct smb_filename
*smb_full_audit_realpath(vfs_handle_struct
*handle
,
1977 const struct smb_filename
*smb_fname
)
1979 struct smb_filename
*result_fname
= NULL
;
1981 result_fname
= SMB_VFS_NEXT_REALPATH(handle
, ctx
, smb_fname
);
1983 do_log(SMB_VFS_OP_REALPATH
,
1984 (result_fname
!= NULL
),
1987 smb_fname_str_do_log(handle
->conn
, smb_fname
));
1989 return result_fname
;
1992 static int smb_full_audit_fchflags(vfs_handle_struct
*handle
,
1993 struct files_struct
*fsp
,
1998 result
= SMB_VFS_NEXT_FCHFLAGS(handle
, fsp
, flags
);
2000 do_log(SMB_VFS_OP_FCHFLAGS
,
2004 smb_fname_str_do_log(handle
->conn
, fsp
->fsp_name
));
2009 static struct file_id
smb_full_audit_file_id_create(struct vfs_handle_struct
*handle
,
2010 const SMB_STRUCT_STAT
*sbuf
)
2012 struct file_id id_zero
= { 0 };
2013 struct file_id result
;
2014 struct file_id_buf idbuf
;
2016 result
= SMB_VFS_NEXT_FILE_ID_CREATE(handle
, sbuf
);
2018 do_log(SMB_VFS_OP_FILE_ID_CREATE
,
2019 !file_id_equal(&id_zero
, &result
),
2022 file_id_str_buf(result
, &idbuf
));
2027 static uint64_t smb_full_audit_fs_file_id(struct vfs_handle_struct
*handle
,
2028 const SMB_STRUCT_STAT
*sbuf
)
2032 result
= SMB_VFS_NEXT_FS_FILE_ID(handle
, sbuf
);
2034 do_log(SMB_VFS_OP_FS_FILE_ID
,
2036 handle
, "%" PRIu64
, result
);
2041 static NTSTATUS
smb_full_audit_fstreaminfo(vfs_handle_struct
*handle
,
2042 struct files_struct
*fsp
,
2043 TALLOC_CTX
*mem_ctx
,
2044 unsigned int *pnum_streams
,
2045 struct stream_struct
**pstreams
)
2049 result
= SMB_VFS_NEXT_FSTREAMINFO(handle
, fsp
, mem_ctx
,
2050 pnum_streams
, pstreams
);
2052 do_log(SMB_VFS_OP_FSTREAMINFO
,
2053 NT_STATUS_IS_OK(result
),
2056 smb_fname_str_do_log(handle
->conn
, fsp
->fsp_name
));
2061 static int smb_full_audit_get_real_filename(struct vfs_handle_struct
*handle
,
2062 const struct smb_filename
*path
,
2064 TALLOC_CTX
*mem_ctx
,
2069 result
= SMB_VFS_NEXT_GET_REAL_FILENAME(handle
, path
, name
, mem_ctx
,
2072 do_log(SMB_VFS_OP_GET_REAL_FILENAME
, (result
== 0), handle
,
2074 path
->base_name
, name
, (result
== 0) ? *found_name
: "");
2079 static const char *smb_full_audit_connectpath(vfs_handle_struct
*handle
,
2080 const struct smb_filename
*smb_fname
)
2084 result
= SMB_VFS_NEXT_CONNECTPATH(handle
, smb_fname
);
2086 do_log(SMB_VFS_OP_CONNECTPATH
,
2090 smb_fname_str_do_log(handle
->conn
, smb_fname
));
2095 static NTSTATUS
smb_full_audit_brl_lock_windows(struct vfs_handle_struct
*handle
,
2096 struct byte_range_lock
*br_lck
,
2097 struct lock_struct
*plock
)
2101 result
= SMB_VFS_NEXT_BRL_LOCK_WINDOWS(handle
, br_lck
, plock
);
2103 do_log(SMB_VFS_OP_BRL_LOCK_WINDOWS
, NT_STATUS_IS_OK(result
), handle
,
2104 "%s:%llu-%llu. type=%d.",
2105 fsp_str_do_log(brl_fsp(br_lck
)),
2106 (unsigned long long)plock
->start
,
2107 (unsigned long long)plock
->size
,
2113 static bool smb_full_audit_brl_unlock_windows(struct vfs_handle_struct
*handle
,
2114 struct byte_range_lock
*br_lck
,
2115 const struct lock_struct
*plock
)
2119 result
= SMB_VFS_NEXT_BRL_UNLOCK_WINDOWS(handle
, br_lck
, plock
);
2121 do_log(SMB_VFS_OP_BRL_UNLOCK_WINDOWS
, (result
== 0), handle
,
2122 "%s:%llu-%llu:%d", fsp_str_do_log(brl_fsp(br_lck
)),
2123 (unsigned long long)plock
->start
,
2124 (unsigned long long)plock
->size
,
2130 static bool smb_full_audit_strict_lock_check(struct vfs_handle_struct
*handle
,
2131 struct files_struct
*fsp
,
2132 struct lock_struct
*plock
)
2136 result
= SMB_VFS_NEXT_STRICT_LOCK_CHECK(handle
, fsp
, plock
);
2138 do_log(SMB_VFS_OP_STRICT_LOCK_CHECK
, result
, handle
,
2139 "%s:%llu-%llu:%d", fsp_str_do_log(fsp
),
2140 (unsigned long long)plock
->start
,
2141 (unsigned long long)plock
->size
,
2147 static NTSTATUS
smb_full_audit_translate_name(struct vfs_handle_struct
*handle
,
2149 enum vfs_translate_direction direction
,
2150 TALLOC_CTX
*mem_ctx
,
2155 result
= SMB_VFS_NEXT_TRANSLATE_NAME(handle
, name
, direction
, mem_ctx
,
2158 do_log(SMB_VFS_OP_TRANSLATE_NAME
, NT_STATUS_IS_OK(result
), handle
, "");
2163 static NTSTATUS
smb_full_audit_parent_pathname(struct vfs_handle_struct
*handle
,
2164 TALLOC_CTX
*mem_ctx
,
2165 const struct smb_filename
*smb_fname_in
,
2166 struct smb_filename
**parent_dir_out
,
2167 struct smb_filename
**atname_out
)
2171 result
= SMB_VFS_NEXT_PARENT_PATHNAME(handle
,
2176 do_log(SMB_VFS_OP_CONNECTPATH
,
2177 NT_STATUS_IS_OK(result
),
2180 smb_fname_str_do_log(handle
->conn
, smb_fname_in
));
2185 static NTSTATUS
smb_full_audit_fsctl(struct vfs_handle_struct
*handle
,
2186 struct files_struct
*fsp
,
2190 const uint8_t *_in_data
,
2192 uint8_t **_out_data
,
2193 uint32_t max_out_len
,
2198 result
= SMB_VFS_NEXT_FSCTL(handle
,
2209 do_log(SMB_VFS_OP_FSCTL
, NT_STATUS_IS_OK(result
), handle
, "");
2214 static struct tevent_req
*smb_full_audit_offload_read_send(
2215 TALLOC_CTX
*mem_ctx
,
2216 struct tevent_context
*ev
,
2217 struct vfs_handle_struct
*handle
,
2218 struct files_struct
*fsp
,
2224 struct tevent_req
*req
= NULL
;
2226 req
= SMB_VFS_NEXT_OFFLOAD_READ_SEND(mem_ctx
, ev
, handle
, fsp
,
2227 fsctl
, ttl
, offset
, to_copy
);
2229 do_log(SMB_VFS_OP_OFFLOAD_READ_SEND
, req
, handle
, "");
2234 static NTSTATUS
smb_full_audit_offload_read_recv(
2235 struct tevent_req
*req
,
2236 struct vfs_handle_struct
*handle
,
2237 TALLOC_CTX
*mem_ctx
,
2240 DATA_BLOB
*_token_blob
)
2244 status
= SMB_VFS_NEXT_OFFLOAD_READ_RECV(req
, handle
, mem_ctx
,
2245 flags
, xferlen
, _token_blob
);
2247 do_log(SMB_VFS_OP_OFFLOAD_READ_RECV
, NT_STATUS_IS_OK(status
), handle
, "");
2252 static struct tevent_req
*smb_full_audit_offload_write_send(struct vfs_handle_struct
*handle
,
2253 TALLOC_CTX
*mem_ctx
,
2254 struct tevent_context
*ev
,
2257 off_t transfer_offset
,
2258 struct files_struct
*dest_fsp
,
2262 struct tevent_req
*req
;
2264 req
= SMB_VFS_NEXT_OFFLOAD_WRITE_SEND(handle
, mem_ctx
, ev
,
2265 fsctl
, token
, transfer_offset
,
2266 dest_fsp
, dest_off
, num
);
2268 do_log(SMB_VFS_OP_OFFLOAD_WRITE_SEND
, req
, handle
, "");
2273 static NTSTATUS
smb_full_audit_offload_write_recv(struct vfs_handle_struct
*handle
,
2274 struct tevent_req
*req
,
2279 result
= SMB_VFS_NEXT_OFFLOAD_WRITE_RECV(handle
, req
, copied
);
2281 do_log(SMB_VFS_OP_OFFLOAD_WRITE_RECV
, NT_STATUS_IS_OK(result
), handle
, "");
2286 static NTSTATUS
smb_full_audit_fget_compression(vfs_handle_struct
*handle
,
2287 TALLOC_CTX
*mem_ctx
,
2288 struct files_struct
*fsp
,
2289 uint16_t *_compression_fmt
)
2293 result
= SMB_VFS_NEXT_FGET_COMPRESSION(handle
, mem_ctx
, fsp
,
2296 do_log(SMB_VFS_OP_FGET_COMPRESSION
, NT_STATUS_IS_OK(result
), handle
,
2298 fsp_str_do_log(fsp
));
2303 static NTSTATUS
smb_full_audit_set_compression(vfs_handle_struct
*handle
,
2304 TALLOC_CTX
*mem_ctx
,
2305 struct files_struct
*fsp
,
2306 uint16_t compression_fmt
)
2310 result
= SMB_VFS_NEXT_SET_COMPRESSION(handle
, mem_ctx
, fsp
,
2313 do_log(SMB_VFS_OP_SET_COMPRESSION
, NT_STATUS_IS_OK(result
), handle
,
2314 "%s", fsp_str_do_log(fsp
));
2319 static NTSTATUS
smb_full_audit_freaddir_attr(struct vfs_handle_struct
*handle
,
2320 struct files_struct
*fsp
,
2321 TALLOC_CTX
*mem_ctx
,
2322 struct readdir_attr_data
**pattr_data
)
2326 status
= SMB_VFS_NEXT_FREADDIR_ATTR(handle
, fsp
, mem_ctx
, pattr_data
);
2328 do_log(SMB_VFS_OP_FREADDIR_ATTR
,
2329 NT_STATUS_IS_OK(status
),
2332 fsp_str_do_log(fsp
));
2337 struct smb_full_audit_get_dos_attributes_state
{
2338 struct vfs_aio_state aio_state
;
2339 vfs_handle_struct
*handle
;
2340 files_struct
*dir_fsp
;
2341 const struct smb_filename
*smb_fname
;
2345 static void smb_full_audit_get_dos_attributes_done(struct tevent_req
*subreq
);
2347 static struct tevent_req
*smb_full_audit_get_dos_attributes_send(
2348 TALLOC_CTX
*mem_ctx
,
2349 struct tevent_context
*ev
,
2350 struct vfs_handle_struct
*handle
,
2351 files_struct
*dir_fsp
,
2352 struct smb_filename
*smb_fname
)
2354 struct tevent_req
*req
= NULL
;
2355 struct smb_full_audit_get_dos_attributes_state
*state
= NULL
;
2356 struct tevent_req
*subreq
= NULL
;
2358 req
= tevent_req_create(mem_ctx
, &state
,
2359 struct smb_full_audit_get_dos_attributes_state
);
2361 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND
,
2365 fsp_str_do_log(dir_fsp
),
2366 smb_fname
->base_name
);
2369 *state
= (struct smb_full_audit_get_dos_attributes_state
) {
2372 .smb_fname
= smb_fname
,
2375 subreq
= SMB_VFS_NEXT_GET_DOS_ATTRIBUTES_SEND(mem_ctx
,
2380 if (tevent_req_nomem(subreq
, req
)) {
2381 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND
,
2385 fsp_str_do_log(dir_fsp
),
2386 smb_fname
->base_name
);
2387 return tevent_req_post(req
, ev
);
2389 tevent_req_set_callback(subreq
,
2390 smb_full_audit_get_dos_attributes_done
,
2393 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND
,
2397 fsp_str_do_log(dir_fsp
),
2398 smb_fname
->base_name
);
2403 static void smb_full_audit_get_dos_attributes_done(struct tevent_req
*subreq
)
2405 struct tevent_req
*req
=
2406 tevent_req_callback_data(subreq
,
2408 struct smb_full_audit_get_dos_attributes_state
*state
=
2409 tevent_req_data(req
,
2410 struct smb_full_audit_get_dos_attributes_state
);
2413 status
= SMB_VFS_NEXT_GET_DOS_ATTRIBUTES_RECV(subreq
,
2416 TALLOC_FREE(subreq
);
2417 if (tevent_req_nterror(req
, status
)) {
2421 tevent_req_done(req
);
2425 static NTSTATUS
smb_full_audit_get_dos_attributes_recv(struct tevent_req
*req
,
2426 struct vfs_aio_state
*aio_state
,
2429 struct smb_full_audit_get_dos_attributes_state
*state
=
2430 tevent_req_data(req
,
2431 struct smb_full_audit_get_dos_attributes_state
);
2434 if (tevent_req_is_nterror(req
, &status
)) {
2435 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV
,
2439 fsp_str_do_log(state
->dir_fsp
),
2440 state
->smb_fname
->base_name
);
2441 tevent_req_received(req
);
2445 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV
,
2449 fsp_str_do_log(state
->dir_fsp
),
2450 state
->smb_fname
->base_name
);
2452 *aio_state
= state
->aio_state
;
2453 *dosmode
= state
->dosmode
;
2454 tevent_req_received(req
);
2455 return NT_STATUS_OK
;
2458 static NTSTATUS
smb_full_audit_fget_dos_attributes(
2459 struct vfs_handle_struct
*handle
,
2460 struct files_struct
*fsp
,
2465 status
= SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle
,
2469 do_log(SMB_VFS_OP_FGET_DOS_ATTRIBUTES
,
2470 NT_STATUS_IS_OK(status
),
2473 fsp_str_do_log(fsp
));
2478 static NTSTATUS
smb_full_audit_fset_dos_attributes(
2479 struct vfs_handle_struct
*handle
,
2480 struct files_struct
*fsp
,
2485 status
= SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle
,
2489 do_log(SMB_VFS_OP_FSET_DOS_ATTRIBUTES
,
2490 NT_STATUS_IS_OK(status
),
2493 fsp_str_do_log(fsp
));
2498 static NTSTATUS
smb_full_audit_fget_nt_acl(vfs_handle_struct
*handle
, files_struct
*fsp
,
2499 uint32_t security_info
,
2500 TALLOC_CTX
*mem_ctx
,
2501 struct security_descriptor
**ppdesc
)
2505 result
= SMB_VFS_NEXT_FGET_NT_ACL(handle
, fsp
, security_info
,
2508 do_log(SMB_VFS_OP_FGET_NT_ACL
, NT_STATUS_IS_OK(result
), handle
,
2509 "%s", fsp_str_do_log(fsp
));
2514 static NTSTATUS
smb_full_audit_fset_nt_acl(vfs_handle_struct
*handle
, files_struct
*fsp
,
2515 uint32_t security_info_sent
,
2516 const struct security_descriptor
*psd
)
2518 struct vfs_full_audit_private_data
*pd
;
2522 SMB_VFS_HANDLE_GET_DATA(handle
, pd
,
2523 struct vfs_full_audit_private_data
,
2524 return NT_STATUS_INTERNAL_ERROR
);
2526 if (pd
->log_secdesc
) {
2527 sd
= sddl_encode(talloc_tos(), psd
, get_global_sam_sid());
2530 result
= SMB_VFS_NEXT_FSET_NT_ACL(handle
, fsp
, security_info_sent
, psd
);
2532 do_log(SMB_VFS_OP_FSET_NT_ACL
, NT_STATUS_IS_OK(result
), handle
,
2533 "%s [%s]", fsp_str_do_log(fsp
), sd
? sd
: "");
2540 static NTSTATUS
smb_full_audit_audit_file(struct vfs_handle_struct
*handle
,
2541 struct smb_filename
*file
,
2542 struct security_acl
*sacl
,
2543 uint32_t access_requested
,
2544 uint32_t access_denied
)
2548 result
= SMB_VFS_NEXT_AUDIT_FILE(handle
,
2554 do_log(SMB_VFS_OP_AUDIT_FILE
, NT_STATUS_IS_OK(result
), handle
,
2556 smb_fname_str_do_log(handle
->conn
, file
));
2561 static SMB_ACL_T
smb_full_audit_sys_acl_get_fd(vfs_handle_struct
*handle
,
2563 SMB_ACL_TYPE_T type
,
2564 TALLOC_CTX
*mem_ctx
)
2568 result
= SMB_VFS_NEXT_SYS_ACL_GET_FD(handle
,
2573 do_log(SMB_VFS_OP_SYS_ACL_GET_FD
, (result
!= NULL
), handle
,
2574 "%s", fsp_str_do_log(fsp
));
2579 static int smb_full_audit_sys_acl_blob_get_fd(vfs_handle_struct
*handle
,
2581 TALLOC_CTX
*mem_ctx
,
2582 char **blob_description
,
2587 result
= SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle
, fsp
, mem_ctx
, blob_description
, blob
);
2589 do_log(SMB_VFS_OP_SYS_ACL_BLOB_GET_FD
, (result
>= 0), handle
,
2590 "%s", fsp_str_do_log(fsp
));
2595 static int smb_full_audit_sys_acl_set_fd(vfs_handle_struct
*handle
,
2596 struct files_struct
*fsp
,
2597 SMB_ACL_TYPE_T type
,
2602 result
= SMB_VFS_NEXT_SYS_ACL_SET_FD(handle
, fsp
, type
, theacl
);
2604 do_log(SMB_VFS_OP_SYS_ACL_SET_FD
, (result
>= 0), handle
,
2605 "%s", fsp_str_do_log(fsp
));
2610 static int smb_full_audit_sys_acl_delete_def_fd(vfs_handle_struct
*handle
,
2611 struct files_struct
*fsp
)
2615 result
= SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FD(handle
, fsp
);
2617 do_log(SMB_VFS_OP_SYS_ACL_DELETE_DEF_FD
,
2621 fsp_str_do_log(fsp
));
2626 struct smb_full_audit_getxattrat_state
{
2627 struct vfs_aio_state aio_state
;
2628 vfs_handle_struct
*handle
;
2629 files_struct
*dir_fsp
;
2630 const struct smb_filename
*smb_fname
;
2631 const char *xattr_name
;
2633 uint8_t *xattr_value
;
2636 static void smb_full_audit_getxattrat_done(struct tevent_req
*subreq
);
2638 static struct tevent_req
*smb_full_audit_getxattrat_send(
2639 TALLOC_CTX
*mem_ctx
,
2640 struct tevent_context
*ev
,
2641 struct vfs_handle_struct
*handle
,
2642 files_struct
*dir_fsp
,
2643 const struct smb_filename
*smb_fname
,
2644 const char *xattr_name
,
2647 struct tevent_req
*req
= NULL
;
2648 struct tevent_req
*subreq
= NULL
;
2649 struct smb_full_audit_getxattrat_state
*state
= NULL
;
2651 req
= tevent_req_create(mem_ctx
, &state
,
2652 struct smb_full_audit_getxattrat_state
);
2654 do_log(SMB_VFS_OP_GETXATTRAT_SEND
,
2658 fsp_str_do_log(dir_fsp
),
2659 smb_fname
->base_name
,
2663 *state
= (struct smb_full_audit_getxattrat_state
) {
2666 .smb_fname
= smb_fname
,
2667 .xattr_name
= xattr_name
,
2670 subreq
= SMB_VFS_NEXT_GETXATTRAT_SEND(state
,
2677 if (tevent_req_nomem(subreq
, req
)) {
2678 do_log(SMB_VFS_OP_GETXATTRAT_SEND
,
2682 fsp_str_do_log(dir_fsp
),
2683 smb_fname
->base_name
,
2685 return tevent_req_post(req
, ev
);
2687 tevent_req_set_callback(subreq
, smb_full_audit_getxattrat_done
, req
);
2689 do_log(SMB_VFS_OP_GETXATTRAT_SEND
,
2693 fsp_str_do_log(dir_fsp
),
2694 smb_fname
->base_name
,
2700 static void smb_full_audit_getxattrat_done(struct tevent_req
*subreq
)
2702 struct tevent_req
*req
= tevent_req_callback_data(
2703 subreq
, struct tevent_req
);
2704 struct smb_full_audit_getxattrat_state
*state
= tevent_req_data(
2705 req
, struct smb_full_audit_getxattrat_state
);
2707 state
->xattr_size
= SMB_VFS_NEXT_GETXATTRAT_RECV(subreq
,
2710 &state
->xattr_value
);
2711 TALLOC_FREE(subreq
);
2712 if (state
->xattr_size
== -1) {
2713 tevent_req_error(req
, state
->aio_state
.error
);
2717 tevent_req_done(req
);
2720 static ssize_t
smb_full_audit_getxattrat_recv(struct tevent_req
*req
,
2721 struct vfs_aio_state
*aio_state
,
2722 TALLOC_CTX
*mem_ctx
,
2723 uint8_t **xattr_value
)
2725 struct smb_full_audit_getxattrat_state
*state
= tevent_req_data(
2726 req
, struct smb_full_audit_getxattrat_state
);
2729 if (tevent_req_is_unix_error(req
, &aio_state
->error
)) {
2730 do_log(SMB_VFS_OP_GETXATTRAT_RECV
,
2734 fsp_str_do_log(state
->dir_fsp
),
2735 state
->smb_fname
->base_name
,
2737 tevent_req_received(req
);
2741 do_log(SMB_VFS_OP_GETXATTRAT_RECV
,
2745 fsp_str_do_log(state
->dir_fsp
),
2746 state
->smb_fname
->base_name
,
2749 *aio_state
= state
->aio_state
;
2750 xattr_size
= state
->xattr_size
;
2751 if (xattr_value
!= NULL
) {
2752 *xattr_value
= talloc_move(mem_ctx
, &state
->xattr_value
);
2755 tevent_req_received(req
);
2759 static ssize_t
smb_full_audit_fgetxattr(struct vfs_handle_struct
*handle
,
2760 struct files_struct
*fsp
,
2761 const char *name
, void *value
, size_t size
)
2765 result
= SMB_VFS_NEXT_FGETXATTR(handle
, fsp
, name
, value
, size
);
2767 do_log(SMB_VFS_OP_FGETXATTR
, (result
>= 0), handle
,
2768 "%s|%s", fsp_str_do_log(fsp
), name
);
2773 static ssize_t
smb_full_audit_flistxattr(struct vfs_handle_struct
*handle
,
2774 struct files_struct
*fsp
, char *list
,
2779 result
= SMB_VFS_NEXT_FLISTXATTR(handle
, fsp
, list
, size
);
2781 do_log(SMB_VFS_OP_FLISTXATTR
, (result
>= 0), handle
,
2782 "%s", fsp_str_do_log(fsp
));
2787 static int smb_full_audit_fremovexattr(struct vfs_handle_struct
*handle
,
2788 struct files_struct
*fsp
,
2793 result
= SMB_VFS_NEXT_FREMOVEXATTR(handle
, fsp
, name
);
2795 do_log(SMB_VFS_OP_FREMOVEXATTR
, (result
>= 0), handle
,
2796 "%s|%s", fsp_str_do_log(fsp
), name
);
2801 static int smb_full_audit_fsetxattr(struct vfs_handle_struct
*handle
,
2802 struct files_struct
*fsp
, const char *name
,
2803 const void *value
, size_t size
, int flags
)
2807 result
= SMB_VFS_NEXT_FSETXATTR(handle
, fsp
, name
, value
, size
, flags
);
2809 do_log(SMB_VFS_OP_FSETXATTR
, (result
>= 0), handle
,
2810 "%s|%s", fsp_str_do_log(fsp
), name
);
2815 static bool smb_full_audit_aio_force(struct vfs_handle_struct
*handle
,
2816 struct files_struct
*fsp
)
2820 result
= SMB_VFS_NEXT_AIO_FORCE(handle
, fsp
);
2821 do_log(SMB_VFS_OP_AIO_FORCE
, result
, handle
,
2822 "%s", fsp_str_do_log(fsp
));
2827 static NTSTATUS
smb_full_audit_durable_cookie(struct vfs_handle_struct
*handle
,
2828 struct files_struct
*fsp
,
2829 TALLOC_CTX
*mem_ctx
,
2834 result
= SMB_VFS_NEXT_DURABLE_COOKIE(handle
,
2839 do_log(SMB_VFS_OP_DURABLE_COOKIE
, NT_STATUS_IS_OK(result
), handle
,
2840 "%s", fsp_str_do_log(fsp
));
2845 static NTSTATUS
smb_full_audit_durable_disconnect(
2846 struct vfs_handle_struct
*handle
,
2847 struct files_struct
*fsp
,
2848 const DATA_BLOB old_cookie
,
2849 TALLOC_CTX
*mem_ctx
,
2850 DATA_BLOB
*new_cookie
)
2854 result
= SMB_VFS_NEXT_DURABLE_DISCONNECT(handle
,
2860 do_log(SMB_VFS_OP_DURABLE_DISCONNECT
, NT_STATUS_IS_OK(result
), handle
,
2861 "%s", fsp_str_do_log(fsp
));
2866 static NTSTATUS
smb_full_audit_durable_reconnect(
2867 struct vfs_handle_struct
*handle
,
2868 struct smb_request
*smb1req
,
2869 struct smbXsrv_open
*op
,
2870 const DATA_BLOB old_cookie
,
2871 TALLOC_CTX
*mem_ctx
,
2872 struct files_struct
**fsp
,
2873 DATA_BLOB
*new_cookie
)
2877 result
= SMB_VFS_NEXT_DURABLE_RECONNECT(handle
,
2885 do_log(SMB_VFS_OP_DURABLE_RECONNECT
,
2886 NT_STATUS_IS_OK(result
),
2893 static struct vfs_fn_pointers vfs_full_audit_fns
= {
2895 /* Disk operations */
2897 .connect_fn
= smb_full_audit_connect
,
2898 .disconnect_fn
= smb_full_audit_disconnect
,
2899 .disk_free_fn
= smb_full_audit_disk_free
,
2900 .get_quota_fn
= smb_full_audit_get_quota
,
2901 .set_quota_fn
= smb_full_audit_set_quota
,
2902 .get_shadow_copy_data_fn
= smb_full_audit_get_shadow_copy_data
,
2903 .statvfs_fn
= smb_full_audit_statvfs
,
2904 .fs_capabilities_fn
= smb_full_audit_fs_capabilities
,
2905 .get_dfs_referrals_fn
= smb_full_audit_get_dfs_referrals
,
2906 .create_dfs_pathat_fn
= smb_full_audit_create_dfs_pathat
,
2907 .read_dfs_pathat_fn
= smb_full_audit_read_dfs_pathat
,
2908 .fdopendir_fn
= smb_full_audit_fdopendir
,
2909 .readdir_fn
= smb_full_audit_readdir
,
2910 .seekdir_fn
= smb_full_audit_seekdir
,
2911 .telldir_fn
= smb_full_audit_telldir
,
2912 .rewind_dir_fn
= smb_full_audit_rewinddir
,
2913 .mkdirat_fn
= smb_full_audit_mkdirat
,
2914 .closedir_fn
= smb_full_audit_closedir
,
2915 .openat_fn
= smb_full_audit_openat
,
2916 .create_file_fn
= smb_full_audit_create_file
,
2917 .close_fn
= smb_full_audit_close
,
2918 .pread_fn
= smb_full_audit_pread
,
2919 .pread_send_fn
= smb_full_audit_pread_send
,
2920 .pread_recv_fn
= smb_full_audit_pread_recv
,
2921 .pwrite_fn
= smb_full_audit_pwrite
,
2922 .pwrite_send_fn
= smb_full_audit_pwrite_send
,
2923 .pwrite_recv_fn
= smb_full_audit_pwrite_recv
,
2924 .lseek_fn
= smb_full_audit_lseek
,
2925 .sendfile_fn
= smb_full_audit_sendfile
,
2926 .recvfile_fn
= smb_full_audit_recvfile
,
2927 .renameat_fn
= smb_full_audit_renameat
,
2928 .fsync_send_fn
= smb_full_audit_fsync_send
,
2929 .fsync_recv_fn
= smb_full_audit_fsync_recv
,
2930 .stat_fn
= smb_full_audit_stat
,
2931 .fstat_fn
= smb_full_audit_fstat
,
2932 .lstat_fn
= smb_full_audit_lstat
,
2933 .get_alloc_size_fn
= smb_full_audit_get_alloc_size
,
2934 .unlinkat_fn
= smb_full_audit_unlinkat
,
2935 .fchmod_fn
= smb_full_audit_fchmod
,
2936 .fchown_fn
= smb_full_audit_fchown
,
2937 .lchown_fn
= smb_full_audit_lchown
,
2938 .chdir_fn
= smb_full_audit_chdir
,
2939 .getwd_fn
= smb_full_audit_getwd
,
2940 .fntimes_fn
= smb_full_audit_fntimes
,
2941 .ftruncate_fn
= smb_full_audit_ftruncate
,
2942 .fallocate_fn
= smb_full_audit_fallocate
,
2943 .lock_fn
= smb_full_audit_lock
,
2944 .filesystem_sharemode_fn
= smb_full_audit_filesystem_sharemode
,
2945 .fcntl_fn
= smb_full_audit_fcntl
,
2946 .linux_setlease_fn
= smb_full_audit_linux_setlease
,
2947 .getlock_fn
= smb_full_audit_getlock
,
2948 .symlinkat_fn
= smb_full_audit_symlinkat
,
2949 .readlinkat_fn
= smb_full_audit_readlinkat
,
2950 .linkat_fn
= smb_full_audit_linkat
,
2951 .mknodat_fn
= smb_full_audit_mknodat
,
2952 .realpath_fn
= smb_full_audit_realpath
,
2953 .fchflags_fn
= smb_full_audit_fchflags
,
2954 .file_id_create_fn
= smb_full_audit_file_id_create
,
2955 .fs_file_id_fn
= smb_full_audit_fs_file_id
,
2956 .offload_read_send_fn
= smb_full_audit_offload_read_send
,
2957 .offload_read_recv_fn
= smb_full_audit_offload_read_recv
,
2958 .offload_write_send_fn
= smb_full_audit_offload_write_send
,
2959 .offload_write_recv_fn
= smb_full_audit_offload_write_recv
,
2960 .fget_compression_fn
= smb_full_audit_fget_compression
,
2961 .set_compression_fn
= smb_full_audit_set_compression
,
2962 .snap_check_path_fn
= smb_full_audit_snap_check_path
,
2963 .snap_create_fn
= smb_full_audit_snap_create
,
2964 .snap_delete_fn
= smb_full_audit_snap_delete
,
2965 .fstreaminfo_fn
= smb_full_audit_fstreaminfo
,
2966 .get_real_filename_fn
= smb_full_audit_get_real_filename
,
2967 .connectpath_fn
= smb_full_audit_connectpath
,
2968 .brl_lock_windows_fn
= smb_full_audit_brl_lock_windows
,
2969 .brl_unlock_windows_fn
= smb_full_audit_brl_unlock_windows
,
2970 .strict_lock_check_fn
= smb_full_audit_strict_lock_check
,
2971 .translate_name_fn
= smb_full_audit_translate_name
,
2972 .parent_pathname_fn
= smb_full_audit_parent_pathname
,
2973 .fsctl_fn
= smb_full_audit_fsctl
,
2974 .get_dos_attributes_send_fn
= smb_full_audit_get_dos_attributes_send
,
2975 .get_dos_attributes_recv_fn
= smb_full_audit_get_dos_attributes_recv
,
2976 .fget_dos_attributes_fn
= smb_full_audit_fget_dos_attributes
,
2977 .fset_dos_attributes_fn
= smb_full_audit_fset_dos_attributes
,
2978 .fget_nt_acl_fn
= smb_full_audit_fget_nt_acl
,
2979 .fset_nt_acl_fn
= smb_full_audit_fset_nt_acl
,
2980 .audit_file_fn
= smb_full_audit_audit_file
,
2981 .sys_acl_get_fd_fn
= smb_full_audit_sys_acl_get_fd
,
2982 .sys_acl_blob_get_fd_fn
= smb_full_audit_sys_acl_blob_get_fd
,
2983 .sys_acl_set_fd_fn
= smb_full_audit_sys_acl_set_fd
,
2984 .sys_acl_delete_def_fd_fn
= smb_full_audit_sys_acl_delete_def_fd
,
2985 .getxattrat_send_fn
= smb_full_audit_getxattrat_send
,
2986 .getxattrat_recv_fn
= smb_full_audit_getxattrat_recv
,
2987 .fgetxattr_fn
= smb_full_audit_fgetxattr
,
2988 .flistxattr_fn
= smb_full_audit_flistxattr
,
2989 .fremovexattr_fn
= smb_full_audit_fremovexattr
,
2990 .fsetxattr_fn
= smb_full_audit_fsetxattr
,
2991 .aio_force_fn
= smb_full_audit_aio_force
,
2992 .durable_cookie_fn
= smb_full_audit_durable_cookie
,
2993 .durable_disconnect_fn
= smb_full_audit_durable_disconnect
,
2994 .durable_reconnect_fn
= smb_full_audit_durable_reconnect
,
2995 .freaddir_attr_fn
= smb_full_audit_freaddir_attr
,
2999 NTSTATUS
vfs_full_audit_init(TALLOC_CTX
*ctx
)
3003 smb_vfs_assert_all_fns(&vfs_full_audit_fns
, "full_audit");
3005 ret
= smb_register_vfs(SMB_VFS_INTERFACE_VERSION
, "full_audit",
3006 &vfs_full_audit_fns
);
3008 if (!NT_STATUS_IS_OK(ret
))
3011 vfs_full_audit_debug_level
= debug_add_class("full_audit");
3012 if (vfs_full_audit_debug_level
== -1) {
3013 vfs_full_audit_debug_level
= DBGC_VFS
;
3014 DEBUG(0, ("vfs_full_audit: Couldn't register custom debugging "
3017 DEBUG(10, ("vfs_full_audit: Debug class number of "
3018 "'full_audit': %d\n", vfs_full_audit_debug_level
));