2 * Auditing VFS module for samba. Log selected file operations to syslog
5 * Copyright (C) Tim Potter, 1999-2000
6 * Copyright (C) Alexander Bokovoy, 2002
7 * Copyright (C) John H Terpstra, 2003
8 * Copyright (C) Stefan (metze) Metzmacher, 2003
9 * Copyright (C) Volker Lendecke, 2004
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, see <http://www.gnu.org/licenses/>.
26 * This module implements parseable logging for all Samba VFS operations.
28 * You use it as follows:
32 * vfs objects = full_audit
33 * full_audit:prefix = %u|%I
34 * full_audit:success = open opendir
35 * full_audit:failure = all
37 * vfs op can be "all" which means log all operations.
38 * vfs op can be "none" which means no logging.
40 * This leads to syslog entries of the form:
41 * smbd_audit: nobody|192.168.234.1|opendir|ok|.
42 * smbd_audit: nobody|192.168.234.1|open|fail (File not found)|r|x.txt
44 * where "nobody" is the connected username and "192.168.234.1" is the
45 * client's IP address.
49 * prefix: A macro expansion template prepended to the syslog entry.
51 * success: A list of VFS operations for which a successful completion should
52 * be logged. Defaults to no logging at all. The special operation "all" logs
53 * - you guessed it - everything.
55 * failure: A list of VFS operations for which failure to complete should be
56 * logged. Defaults to logging everything.
61 #include "system/filesys.h"
62 #include "system/syslog.h"
63 #include "smbd/smbd.h"
64 #include "../librpc/gen_ndr/ndr_netlogon.h"
67 #include "lib/param/loadparm.h"
68 #include "lib/util/bitmap.h"
69 #include "lib/util/tevent_unix.h"
70 #include "libcli/security/sddl.h"
71 #include "passdb/machine_sid.h"
73 static int vfs_full_audit_debug_level = DBGC_VFS;
75 struct vfs_full_audit_private_data {
76 struct bitmap *success_ops;
77 struct bitmap *failure_ops;
85 #define DBGC_CLASS vfs_full_audit_debug_level
87 typedef enum _vfs_op_type {
92 SMB_VFS_OP_CONNECT = 0,
93 SMB_VFS_OP_DISCONNECT,
97 SMB_VFS_OP_GET_SHADOW_COPY_DATA,
99 SMB_VFS_OP_FS_CAPABILITIES,
101 /* Directory operations */
104 SMB_VFS_OP_FDOPENDIR,
108 SMB_VFS_OP_REWINDDIR,
112 SMB_VFS_OP_INIT_SEARCH_OP,
114 /* File operations */
117 SMB_VFS_OP_CREATE_FILE,
121 SMB_VFS_OP_PREAD_SEND,
122 SMB_VFS_OP_PREAD_RECV,
125 SMB_VFS_OP_PWRITE_SEND,
126 SMB_VFS_OP_PWRITE_RECV,
132 SMB_VFS_OP_FSYNC_SEND,
133 SMB_VFS_OP_FSYNC_RECV,
137 SMB_VFS_OP_GET_ALLOC_SIZE,
147 SMB_VFS_OP_FTRUNCATE,
148 SMB_VFS_OP_FALLOCATE,
150 SMB_VFS_OP_KERNEL_FLOCK,
151 SMB_VFS_OP_LINUX_SETLEASE,
158 SMB_VFS_OP_NOTIFY_WATCH,
160 SMB_VFS_OP_FILE_ID_CREATE,
161 SMB_VFS_OP_STREAMINFO,
162 SMB_VFS_OP_GET_REAL_FILENAME,
163 SMB_VFS_OP_CONNECTPATH,
164 SMB_VFS_OP_BRL_LOCK_WINDOWS,
165 SMB_VFS_OP_BRL_UNLOCK_WINDOWS,
166 SMB_VFS_OP_BRL_CANCEL_WINDOWS,
167 SMB_VFS_OP_STRICT_LOCK,
168 SMB_VFS_OP_STRICT_UNLOCK,
169 SMB_VFS_OP_TRANSLATE_NAME,
170 SMB_VFS_OP_COPY_CHUNK_SEND,
171 SMB_VFS_OP_COPY_CHUNK_RECV,
172 SMB_VFS_OP_GET_COMPRESSION,
173 SMB_VFS_OP_SET_COMPRESSION,
174 SMB_VFS_OP_READDIR_ATTR,
176 /* NT ACL operations. */
178 SMB_VFS_OP_FGET_NT_ACL,
179 SMB_VFS_OP_GET_NT_ACL,
180 SMB_VFS_OP_FSET_NT_ACL,
182 /* POSIX ACL operations. */
184 SMB_VFS_OP_CHMOD_ACL,
185 SMB_VFS_OP_FCHMOD_ACL,
187 SMB_VFS_OP_SYS_ACL_GET_FILE,
188 SMB_VFS_OP_SYS_ACL_GET_FD,
189 SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE,
190 SMB_VFS_OP_SYS_ACL_BLOB_GET_FD,
191 SMB_VFS_OP_SYS_ACL_SET_FILE,
192 SMB_VFS_OP_SYS_ACL_SET_FD,
193 SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE,
197 SMB_VFS_OP_FGETXATTR,
198 SMB_VFS_OP_LISTXATTR,
199 SMB_VFS_OP_FLISTXATTR,
200 SMB_VFS_OP_REMOVEXATTR,
201 SMB_VFS_OP_FREMOVEXATTR,
203 SMB_VFS_OP_FSETXATTR,
206 SMB_VFS_OP_AIO_FORCE,
208 /* offline operations */
209 SMB_VFS_OP_IS_OFFLINE,
210 SMB_VFS_OP_SET_OFFLINE,
212 /* This should always be last enum value */
217 /* The following array *must* be in the same order as defined in vfs_op_type */
223 { SMB_VFS_OP_CONNECT, "connect" },
224 { SMB_VFS_OP_DISCONNECT, "disconnect" },
225 { SMB_VFS_OP_DISK_FREE, "disk_free" },
226 { SMB_VFS_OP_GET_QUOTA, "get_quota" },
227 { SMB_VFS_OP_SET_QUOTA, "set_quota" },
228 { SMB_VFS_OP_GET_SHADOW_COPY_DATA, "get_shadow_copy_data" },
229 { SMB_VFS_OP_STATVFS, "statvfs" },
230 { SMB_VFS_OP_FS_CAPABILITIES, "fs_capabilities" },
231 { SMB_VFS_OP_OPENDIR, "opendir" },
232 { SMB_VFS_OP_FDOPENDIR, "fdopendir" },
233 { SMB_VFS_OP_READDIR, "readdir" },
234 { SMB_VFS_OP_SEEKDIR, "seekdir" },
235 { SMB_VFS_OP_TELLDIR, "telldir" },
236 { SMB_VFS_OP_REWINDDIR, "rewinddir" },
237 { SMB_VFS_OP_MKDIR, "mkdir" },
238 { SMB_VFS_OP_RMDIR, "rmdir" },
239 { SMB_VFS_OP_CLOSEDIR, "closedir" },
240 { SMB_VFS_OP_INIT_SEARCH_OP, "init_search_op" },
241 { SMB_VFS_OP_OPEN, "open" },
242 { SMB_VFS_OP_CREATE_FILE, "create_file" },
243 { SMB_VFS_OP_CLOSE, "close" },
244 { SMB_VFS_OP_READ, "read" },
245 { SMB_VFS_OP_PREAD, "pread" },
246 { SMB_VFS_OP_PREAD_SEND, "pread_send" },
247 { SMB_VFS_OP_PREAD_RECV, "pread_recv" },
248 { SMB_VFS_OP_WRITE, "write" },
249 { SMB_VFS_OP_PWRITE, "pwrite" },
250 { SMB_VFS_OP_PWRITE_SEND, "pwrite_send" },
251 { SMB_VFS_OP_PWRITE_RECV, "pwrite_recv" },
252 { SMB_VFS_OP_LSEEK, "lseek" },
253 { SMB_VFS_OP_SENDFILE, "sendfile" },
254 { SMB_VFS_OP_RECVFILE, "recvfile" },
255 { SMB_VFS_OP_RENAME, "rename" },
256 { SMB_VFS_OP_FSYNC, "fsync" },
257 { SMB_VFS_OP_FSYNC_SEND, "fsync_send" },
258 { SMB_VFS_OP_FSYNC_RECV, "fsync_recv" },
259 { SMB_VFS_OP_STAT, "stat" },
260 { SMB_VFS_OP_FSTAT, "fstat" },
261 { SMB_VFS_OP_LSTAT, "lstat" },
262 { SMB_VFS_OP_GET_ALLOC_SIZE, "get_alloc_size" },
263 { SMB_VFS_OP_UNLINK, "unlink" },
264 { SMB_VFS_OP_CHMOD, "chmod" },
265 { SMB_VFS_OP_FCHMOD, "fchmod" },
266 { SMB_VFS_OP_CHOWN, "chown" },
267 { SMB_VFS_OP_FCHOWN, "fchown" },
268 { SMB_VFS_OP_LCHOWN, "lchown" },
269 { SMB_VFS_OP_CHDIR, "chdir" },
270 { SMB_VFS_OP_GETWD, "getwd" },
271 { SMB_VFS_OP_NTIMES, "ntimes" },
272 { SMB_VFS_OP_FTRUNCATE, "ftruncate" },
273 { SMB_VFS_OP_FALLOCATE,"fallocate" },
274 { SMB_VFS_OP_LOCK, "lock" },
275 { SMB_VFS_OP_KERNEL_FLOCK, "kernel_flock" },
276 { SMB_VFS_OP_LINUX_SETLEASE, "linux_setlease" },
277 { SMB_VFS_OP_GETLOCK, "getlock" },
278 { SMB_VFS_OP_SYMLINK, "symlink" },
279 { SMB_VFS_OP_READLINK, "readlink" },
280 { SMB_VFS_OP_LINK, "link" },
281 { SMB_VFS_OP_MKNOD, "mknod" },
282 { SMB_VFS_OP_REALPATH, "realpath" },
283 { SMB_VFS_OP_NOTIFY_WATCH, "notify_watch" },
284 { SMB_VFS_OP_CHFLAGS, "chflags" },
285 { SMB_VFS_OP_FILE_ID_CREATE, "file_id_create" },
286 { SMB_VFS_OP_STREAMINFO, "streaminfo" },
287 { SMB_VFS_OP_GET_REAL_FILENAME, "get_real_filename" },
288 { SMB_VFS_OP_CONNECTPATH, "connectpath" },
289 { SMB_VFS_OP_BRL_LOCK_WINDOWS, "brl_lock_windows" },
290 { SMB_VFS_OP_BRL_UNLOCK_WINDOWS, "brl_unlock_windows" },
291 { SMB_VFS_OP_BRL_CANCEL_WINDOWS, "brl_cancel_windows" },
292 { SMB_VFS_OP_STRICT_LOCK, "strict_lock" },
293 { SMB_VFS_OP_STRICT_UNLOCK, "strict_unlock" },
294 { SMB_VFS_OP_TRANSLATE_NAME, "translate_name" },
295 { SMB_VFS_OP_COPY_CHUNK_SEND, "copy_chunk_send" },
296 { SMB_VFS_OP_COPY_CHUNK_RECV, "copy_chunk_recv" },
297 { SMB_VFS_OP_GET_COMPRESSION, "get_compression" },
298 { SMB_VFS_OP_SET_COMPRESSION, "set_compression" },
299 { SMB_VFS_OP_READDIR_ATTR, "readdir_attr" },
300 { SMB_VFS_OP_FGET_NT_ACL, "fget_nt_acl" },
301 { SMB_VFS_OP_GET_NT_ACL, "get_nt_acl" },
302 { SMB_VFS_OP_FSET_NT_ACL, "fset_nt_acl" },
303 { SMB_VFS_OP_CHMOD_ACL, "chmod_acl" },
304 { SMB_VFS_OP_FCHMOD_ACL, "fchmod_acl" },
305 { SMB_VFS_OP_SYS_ACL_GET_FILE, "sys_acl_get_file" },
306 { SMB_VFS_OP_SYS_ACL_GET_FD, "sys_acl_get_fd" },
307 { SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE, "sys_acl_blob_get_file" },
308 { SMB_VFS_OP_SYS_ACL_BLOB_GET_FD, "sys_acl_blob_get_fd" },
309 { SMB_VFS_OP_SYS_ACL_SET_FILE, "sys_acl_set_file" },
310 { SMB_VFS_OP_SYS_ACL_SET_FD, "sys_acl_set_fd" },
311 { SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE, "sys_acl_delete_def_file" },
312 { SMB_VFS_OP_GETXATTR, "getxattr" },
313 { SMB_VFS_OP_FGETXATTR, "fgetxattr" },
314 { SMB_VFS_OP_LISTXATTR, "listxattr" },
315 { SMB_VFS_OP_FLISTXATTR, "flistxattr" },
316 { SMB_VFS_OP_REMOVEXATTR, "removexattr" },
317 { SMB_VFS_OP_FREMOVEXATTR, "fremovexattr" },
318 { SMB_VFS_OP_SETXATTR, "setxattr" },
319 { SMB_VFS_OP_FSETXATTR, "fsetxattr" },
320 { SMB_VFS_OP_AIO_FORCE, "aio_force" },
321 { SMB_VFS_OP_IS_OFFLINE, "is_offline" },
322 { SMB_VFS_OP_SET_OFFLINE, "set_offline" },
323 { SMB_VFS_OP_LAST, NULL }
326 static int audit_syslog_facility(vfs_handle_struct *handle)
328 static const struct enum_list enum_log_facilities[] = {
329 { LOG_USER, "USER" },
330 { LOG_LOCAL0, "LOCAL0" },
331 { LOG_LOCAL1, "LOCAL1" },
332 { LOG_LOCAL2, "LOCAL2" },
333 { LOG_LOCAL3, "LOCAL3" },
334 { LOG_LOCAL4, "LOCAL4" },
335 { LOG_LOCAL5, "LOCAL5" },
336 { LOG_LOCAL6, "LOCAL6" },
337 { LOG_LOCAL7, "LOCAL7" },
343 facility = lp_parm_enum(SNUM(handle->conn), "full_audit", "facility", enum_log_facilities, LOG_USER);
348 static int audit_syslog_priority(vfs_handle_struct *handle)
350 static const struct enum_list enum_log_priorities[] = {
351 { LOG_EMERG, "EMERG" },
352 { LOG_ALERT, "ALERT" },
353 { LOG_CRIT, "CRIT" },
355 { LOG_WARNING, "WARNING" },
356 { LOG_NOTICE, "NOTICE" },
357 { LOG_INFO, "INFO" },
358 { LOG_DEBUG, "DEBUG" },
364 priority = lp_parm_enum(SNUM(handle->conn), "full_audit", "priority",
365 enum_log_priorities, LOG_NOTICE);
366 if (priority == -1) {
367 priority = LOG_WARNING;
373 static char *audit_prefix(TALLOC_CTX *ctx, connection_struct *conn)
378 prefix = talloc_strdup(ctx,
379 lp_parm_const_string(SNUM(conn), "full_audit",
384 result = talloc_sub_advanced(ctx,
385 lp_servicename(talloc_tos(), SNUM(conn)),
386 conn->session_info->unix_info->unix_name,
388 conn->session_info->unix_token->gid,
389 conn->session_info->unix_info->sanitized_username,
390 conn->session_info->info->domain_name,
396 static bool log_success(struct vfs_full_audit_private_data *pd, vfs_op_type op)
398 if (pd->success_ops == NULL) {
402 return bitmap_query(pd->success_ops, op);
405 static bool log_failure(struct vfs_full_audit_private_data *pd, vfs_op_type op)
407 if (pd->failure_ops == NULL)
410 return bitmap_query(pd->failure_ops, op);
413 static struct bitmap *init_bitmap(TALLOC_CTX *mem_ctx, const char **ops)
421 bm = bitmap_talloc(mem_ctx, SMB_VFS_OP_LAST);
423 DEBUG(0, ("Could not alloc bitmap -- "
424 "defaulting to logging everything\n"));
428 for (; *ops != NULL; ops += 1) {
433 if (strequal(*ops, "all")) {
434 for (i=0; i<SMB_VFS_OP_LAST; i++) {
440 if (strequal(*ops, "none")) {
450 for (i=0; i<SMB_VFS_OP_LAST; i++) {
451 if ((vfs_op_names[i].name == NULL)
452 || (vfs_op_names[i].type != i)) {
453 smb_panic("vfs_full_audit.c: name table not "
454 "in sync with vfs_op_type enums\n");
456 if (strequal(op, vfs_op_names[i].name)) {
465 if (i == SMB_VFS_OP_LAST) {
466 DEBUG(0, ("Could not find opname %s, logging all\n",
475 static const char *audit_opname(vfs_op_type op)
477 if (op >= SMB_VFS_OP_LAST)
478 return "INVALID VFS OP";
479 return vfs_op_names[op].name;
482 static TALLOC_CTX *tmp_do_log_ctx;
484 * Get us a temporary talloc context usable just for DEBUG arguments
486 static TALLOC_CTX *do_log_ctx(void)
488 if (tmp_do_log_ctx == NULL) {
489 tmp_do_log_ctx = talloc_named_const(NULL, 0, "do_log_ctx");
491 return tmp_do_log_ctx;
494 static void do_log(vfs_op_type op, bool success, vfs_handle_struct *handle,
495 const char *format, ...)
497 struct vfs_full_audit_private_data *pd;
499 char *audit_pre = NULL;
503 SMB_VFS_HANDLE_GET_DATA(handle, pd,
504 struct vfs_full_audit_private_data,
507 if (success && (!log_success(pd, op)))
510 if (!success && (!log_failure(pd, op)))
514 fstrcpy(err_msg, "ok");
516 fstr_sprintf(err_msg, "fail (%s)", strerror(errno));
518 va_start(ap, format);
519 op_msg = talloc_vasprintf(talloc_tos(), format, ap);
526 audit_pre = audit_prefix(talloc_tos(), handle->conn);
532 * Specify the facility to interoperate with other syslog
533 * callers (smbd for example).
535 priority = pd->syslog_priority | pd->syslog_facility;
537 syslog(priority, "%s|%s|%s|%s\n",
538 audit_pre ? audit_pre : "",
539 audit_opname(op), err_msg, op_msg);
541 DEBUG(1, ("%s|%s|%s|%s\n",
542 audit_pre ? audit_pre : "",
543 audit_opname(op), err_msg, op_msg));
546 TALLOC_FREE(audit_pre);
548 TALLOC_FREE(tmp_do_log_ctx);
552 * Return a string using the do_log_ctx()
554 static const char *smb_fname_str_do_log(const struct smb_filename *smb_fname)
559 if (smb_fname == NULL) {
562 status = get_full_smb_filename(do_log_ctx(), smb_fname, &fname);
563 if (!NT_STATUS_IS_OK(status)) {
570 * Return an fsp debug string using the do_log_ctx()
572 static const char *fsp_str_do_log(const struct files_struct *fsp)
574 return smb_fname_str_do_log(fsp->fsp_name);
577 /* Implementation of vfs_ops. Pass everything on to the default
578 operation but log event first. */
580 static int smb_full_audit_connect(vfs_handle_struct *handle,
581 const char *svc, const char *user)
584 struct vfs_full_audit_private_data *pd = NULL;
586 result = SMB_VFS_NEXT_CONNECT(handle, svc, user);
591 pd = talloc_zero(handle, struct vfs_full_audit_private_data);
593 SMB_VFS_NEXT_DISCONNECT(handle);
597 pd->syslog_facility = audit_syslog_facility(handle);
598 if (pd->syslog_facility == -1) {
599 DEBUG(1, ("%s: Unknown facility %s\n", __func__,
600 lp_parm_const_string(SNUM(handle->conn),
601 "full_audit", "facility",
603 SMB_VFS_NEXT_DISCONNECT(handle);
607 pd->syslog_priority = audit_syslog_priority(handle);
609 pd->log_secdesc = lp_parm_bool(SNUM(handle->conn),
610 "full_audit", "log_secdesc", false);
612 pd->do_syslog = lp_parm_bool(SNUM(handle->conn),
613 "full_audit", "syslog", true);
617 openlog("smbd_audit", 0, pd->syslog_facility);
621 pd->success_ops = init_bitmap(
622 pd, lp_parm_string_list(SNUM(handle->conn), "full_audit",
624 pd->failure_ops = init_bitmap(
625 pd, lp_parm_string_list(SNUM(handle->conn), "full_audit",
628 /* Store the private data. */
629 SMB_VFS_HANDLE_SET_DATA(handle, pd, NULL,
630 struct vfs_full_audit_private_data, return -1);
632 do_log(SMB_VFS_OP_CONNECT, True, handle,
638 static void smb_full_audit_disconnect(vfs_handle_struct *handle)
640 SMB_VFS_NEXT_DISCONNECT(handle);
642 do_log(SMB_VFS_OP_DISCONNECT, True, handle,
643 "%s", lp_servicename(talloc_tos(), SNUM(handle->conn)));
645 /* The bitmaps will be disconnected when the private
649 static uint64_t smb_full_audit_disk_free(vfs_handle_struct *handle,
651 bool small_query, uint64_t *bsize,
652 uint64_t *dfree, uint64_t *dsize)
656 result = SMB_VFS_NEXT_DISK_FREE(handle, path, small_query, bsize,
659 /* Don't have a reasonable notion of failure here */
661 do_log(SMB_VFS_OP_DISK_FREE, True, handle, "%s", path);
666 static int smb_full_audit_get_quota(struct vfs_handle_struct *handle,
667 enum SMB_QUOTA_TYPE qtype, unid_t id,
672 result = SMB_VFS_NEXT_GET_QUOTA(handle, qtype, id, qt);
674 do_log(SMB_VFS_OP_GET_QUOTA, (result >= 0), handle, "");
680 static int smb_full_audit_set_quota(struct vfs_handle_struct *handle,
681 enum SMB_QUOTA_TYPE qtype, unid_t id,
686 result = SMB_VFS_NEXT_SET_QUOTA(handle, qtype, id, qt);
688 do_log(SMB_VFS_OP_SET_QUOTA, (result >= 0), handle, "");
693 static int smb_full_audit_get_shadow_copy_data(struct vfs_handle_struct *handle,
694 struct files_struct *fsp,
695 struct shadow_copy_data *shadow_copy_data,
700 result = SMB_VFS_NEXT_GET_SHADOW_COPY_DATA(handle, fsp, shadow_copy_data, labels);
702 do_log(SMB_VFS_OP_GET_SHADOW_COPY_DATA, (result >= 0), handle, "");
707 static int smb_full_audit_statvfs(struct vfs_handle_struct *handle,
709 struct vfs_statvfs_struct *statbuf)
713 result = SMB_VFS_NEXT_STATVFS(handle, path, statbuf);
715 do_log(SMB_VFS_OP_STATVFS, (result >= 0), handle, "");
720 static uint32_t smb_full_audit_fs_capabilities(struct vfs_handle_struct *handle, enum timestamp_set_resolution *p_ts_res)
724 result = SMB_VFS_NEXT_FS_CAPABILITIES(handle, p_ts_res);
726 do_log(SMB_VFS_OP_FS_CAPABILITIES, true, handle, "");
731 static DIR *smb_full_audit_opendir(vfs_handle_struct *handle,
732 const char *fname, const char *mask, uint32 attr)
736 result = SMB_VFS_NEXT_OPENDIR(handle, fname, mask, attr);
738 do_log(SMB_VFS_OP_OPENDIR, (result != NULL), handle, "%s", fname);
743 static DIR *smb_full_audit_fdopendir(vfs_handle_struct *handle,
744 files_struct *fsp, const char *mask, uint32 attr)
748 result = SMB_VFS_NEXT_FDOPENDIR(handle, fsp, mask, attr);
750 do_log(SMB_VFS_OP_FDOPENDIR, (result != NULL), handle, "%s",
751 fsp_str_do_log(fsp));
756 static struct dirent *smb_full_audit_readdir(vfs_handle_struct *handle,
757 DIR *dirp, SMB_STRUCT_STAT *sbuf)
759 struct dirent *result;
761 result = SMB_VFS_NEXT_READDIR(handle, dirp, sbuf);
763 /* This operation has no reasonable error condition
764 * (End of dir is also failure), so always succeed.
766 do_log(SMB_VFS_OP_READDIR, True, handle, "");
771 static void smb_full_audit_seekdir(vfs_handle_struct *handle,
772 DIR *dirp, long offset)
774 SMB_VFS_NEXT_SEEKDIR(handle, dirp, offset);
776 do_log(SMB_VFS_OP_SEEKDIR, True, handle, "");
779 static long smb_full_audit_telldir(vfs_handle_struct *handle,
784 result = SMB_VFS_NEXT_TELLDIR(handle, dirp);
786 do_log(SMB_VFS_OP_TELLDIR, True, handle, "");
791 static void smb_full_audit_rewinddir(vfs_handle_struct *handle,
794 SMB_VFS_NEXT_REWINDDIR(handle, dirp);
796 do_log(SMB_VFS_OP_REWINDDIR, True, handle, "");
799 static int smb_full_audit_mkdir(vfs_handle_struct *handle,
800 const char *path, mode_t mode)
804 result = SMB_VFS_NEXT_MKDIR(handle, path, mode);
806 do_log(SMB_VFS_OP_MKDIR, (result >= 0), handle, "%s", path);
811 static int smb_full_audit_rmdir(vfs_handle_struct *handle,
816 result = SMB_VFS_NEXT_RMDIR(handle, path);
818 do_log(SMB_VFS_OP_RMDIR, (result >= 0), handle, "%s", path);
823 static int smb_full_audit_closedir(vfs_handle_struct *handle,
828 result = SMB_VFS_NEXT_CLOSEDIR(handle, dirp);
830 do_log(SMB_VFS_OP_CLOSEDIR, (result >= 0), handle, "");
835 static void smb_full_audit_init_search_op(vfs_handle_struct *handle,
838 SMB_VFS_NEXT_INIT_SEARCH_OP(handle, dirp);
840 do_log(SMB_VFS_OP_INIT_SEARCH_OP, True, handle, "");
843 static int smb_full_audit_open(vfs_handle_struct *handle,
844 struct smb_filename *smb_fname,
845 files_struct *fsp, int flags, mode_t mode)
849 result = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
851 do_log(SMB_VFS_OP_OPEN, (result >= 0), handle, "%s|%s",
852 ((flags & O_WRONLY) || (flags & O_RDWR))?"w":"r",
853 smb_fname_str_do_log(smb_fname));
858 static NTSTATUS smb_full_audit_create_file(vfs_handle_struct *handle,
859 struct smb_request *req,
860 uint16_t root_dir_fid,
861 struct smb_filename *smb_fname,
862 uint32_t access_mask,
863 uint32_t share_access,
864 uint32_t create_disposition,
865 uint32_t create_options,
866 uint32_t file_attributes,
867 uint32_t oplock_request,
868 struct smb2_lease *lease,
869 uint64_t allocation_size,
870 uint32_t private_flags,
871 struct security_descriptor *sd,
872 struct ea_list *ea_list,
873 files_struct **result_fsp,
877 const char* str_create_disposition;
879 switch (create_disposition) {
881 str_create_disposition = "supersede";
883 case FILE_OVERWRITE_IF:
884 str_create_disposition = "overwrite_if";
887 str_create_disposition = "open";
890 str_create_disposition = "overwrite";
893 str_create_disposition = "create";
896 str_create_disposition = "open_if";
899 str_create_disposition = "unknown";
902 result = SMB_VFS_NEXT_CREATE_FILE(
905 root_dir_fid, /* root_dir_fid */
906 smb_fname, /* fname */
907 access_mask, /* access_mask */
908 share_access, /* share_access */
909 create_disposition, /* create_disposition*/
910 create_options, /* create_options */
911 file_attributes, /* file_attributes */
912 oplock_request, /* oplock_request */
914 allocation_size, /* allocation_size */
917 ea_list, /* ea_list */
918 result_fsp, /* result */
921 do_log(SMB_VFS_OP_CREATE_FILE, (NT_STATUS_IS_OK(result)), handle,
922 "0x%x|%s|%s|%s", access_mask,
923 create_options & FILE_DIRECTORY_FILE ? "dir" : "file",
924 str_create_disposition, smb_fname_str_do_log(smb_fname));
929 static int smb_full_audit_close(vfs_handle_struct *handle, files_struct *fsp)
933 result = SMB_VFS_NEXT_CLOSE(handle, fsp);
935 do_log(SMB_VFS_OP_CLOSE, (result >= 0), handle, "%s",
936 fsp_str_do_log(fsp));
941 static ssize_t smb_full_audit_read(vfs_handle_struct *handle, files_struct *fsp,
942 void *data, size_t n)
946 result = SMB_VFS_NEXT_READ(handle, fsp, data, n);
948 do_log(SMB_VFS_OP_READ, (result >= 0), handle, "%s",
949 fsp_str_do_log(fsp));
954 static ssize_t smb_full_audit_pread(vfs_handle_struct *handle, files_struct *fsp,
955 void *data, size_t n, off_t offset)
959 result = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
961 do_log(SMB_VFS_OP_PREAD, (result >= 0), handle, "%s",
962 fsp_str_do_log(fsp));
967 struct smb_full_audit_pread_state {
968 vfs_handle_struct *handle;
974 static void smb_full_audit_pread_done(struct tevent_req *subreq);
976 static struct tevent_req *smb_full_audit_pread_send(
977 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
978 struct tevent_context *ev, struct files_struct *fsp,
979 void *data, size_t n, off_t offset)
981 struct tevent_req *req, *subreq;
982 struct smb_full_audit_pread_state *state;
984 req = tevent_req_create(mem_ctx, &state,
985 struct smb_full_audit_pread_state);
987 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
988 fsp_str_do_log(fsp));
991 state->handle = handle;
994 subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
996 if (tevent_req_nomem(subreq, req)) {
997 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
998 fsp_str_do_log(fsp));
999 return tevent_req_post(req, ev);
1001 tevent_req_set_callback(subreq, smb_full_audit_pread_done, req);
1003 do_log(SMB_VFS_OP_PREAD_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1007 static void smb_full_audit_pread_done(struct tevent_req *subreq)
1009 struct tevent_req *req = tevent_req_callback_data(
1010 subreq, struct tevent_req);
1011 struct smb_full_audit_pread_state *state = tevent_req_data(
1012 req, struct smb_full_audit_pread_state);
1014 state->ret = SMB_VFS_PREAD_RECV(subreq, &state->err);
1015 TALLOC_FREE(subreq);
1016 tevent_req_done(req);
1019 static ssize_t smb_full_audit_pread_recv(struct tevent_req *req, int *err)
1021 struct smb_full_audit_pread_state *state = tevent_req_data(
1022 req, struct smb_full_audit_pread_state);
1024 if (tevent_req_is_unix_error(req, err)) {
1025 do_log(SMB_VFS_OP_PREAD_RECV, false, state->handle, "%s",
1026 fsp_str_do_log(state->fsp));
1030 do_log(SMB_VFS_OP_PREAD_RECV, (state->ret >= 0), state->handle, "%s",
1031 fsp_str_do_log(state->fsp));
1037 static ssize_t smb_full_audit_write(vfs_handle_struct *handle, files_struct *fsp,
1038 const void *data, size_t n)
1042 result = SMB_VFS_NEXT_WRITE(handle, fsp, data, n);
1044 do_log(SMB_VFS_OP_WRITE, (result >= 0), handle, "%s",
1045 fsp_str_do_log(fsp));
1050 static ssize_t smb_full_audit_pwrite(vfs_handle_struct *handle, files_struct *fsp,
1051 const void *data, size_t n,
1056 result = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
1058 do_log(SMB_VFS_OP_PWRITE, (result >= 0), handle, "%s",
1059 fsp_str_do_log(fsp));
1064 struct smb_full_audit_pwrite_state {
1065 vfs_handle_struct *handle;
1071 static void smb_full_audit_pwrite_done(struct tevent_req *subreq);
1073 static struct tevent_req *smb_full_audit_pwrite_send(
1074 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1075 struct tevent_context *ev, struct files_struct *fsp,
1076 const void *data, size_t n, off_t offset)
1078 struct tevent_req *req, *subreq;
1079 struct smb_full_audit_pwrite_state *state;
1081 req = tevent_req_create(mem_ctx, &state,
1082 struct smb_full_audit_pwrite_state);
1084 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1085 fsp_str_do_log(fsp));
1088 state->handle = handle;
1091 subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
1093 if (tevent_req_nomem(subreq, req)) {
1094 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1095 fsp_str_do_log(fsp));
1096 return tevent_req_post(req, ev);
1098 tevent_req_set_callback(subreq, smb_full_audit_pwrite_done, req);
1100 do_log(SMB_VFS_OP_PWRITE_SEND, true, handle, "%s",
1101 fsp_str_do_log(fsp));
1105 static void smb_full_audit_pwrite_done(struct tevent_req *subreq)
1107 struct tevent_req *req = tevent_req_callback_data(
1108 subreq, struct tevent_req);
1109 struct smb_full_audit_pwrite_state *state = tevent_req_data(
1110 req, struct smb_full_audit_pwrite_state);
1112 state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->err);
1113 TALLOC_FREE(subreq);
1114 tevent_req_done(req);
1117 static ssize_t smb_full_audit_pwrite_recv(struct tevent_req *req, int *err)
1119 struct smb_full_audit_pwrite_state *state = tevent_req_data(
1120 req, struct smb_full_audit_pwrite_state);
1122 if (tevent_req_is_unix_error(req, err)) {
1123 do_log(SMB_VFS_OP_PWRITE_RECV, false, state->handle, "%s",
1124 fsp_str_do_log(state->fsp));
1128 do_log(SMB_VFS_OP_PWRITE_RECV, (state->ret >= 0), state->handle, "%s",
1129 fsp_str_do_log(state->fsp));
1135 static off_t smb_full_audit_lseek(vfs_handle_struct *handle, files_struct *fsp,
1136 off_t offset, int whence)
1140 result = SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence);
1142 do_log(SMB_VFS_OP_LSEEK, (result != (ssize_t)-1), handle,
1143 "%s", fsp_str_do_log(fsp));
1148 static ssize_t smb_full_audit_sendfile(vfs_handle_struct *handle, int tofd,
1149 files_struct *fromfsp,
1150 const DATA_BLOB *hdr, off_t offset,
1155 result = SMB_VFS_NEXT_SENDFILE(handle, tofd, fromfsp, hdr, offset, n);
1157 do_log(SMB_VFS_OP_SENDFILE, (result >= 0), handle,
1158 "%s", fsp_str_do_log(fromfsp));
1163 static ssize_t smb_full_audit_recvfile(vfs_handle_struct *handle, int fromfd,
1164 files_struct *tofsp,
1170 result = SMB_VFS_NEXT_RECVFILE(handle, fromfd, tofsp, offset, n);
1172 do_log(SMB_VFS_OP_RECVFILE, (result >= 0), handle,
1173 "%s", fsp_str_do_log(tofsp));
1178 static int smb_full_audit_rename(vfs_handle_struct *handle,
1179 const struct smb_filename *smb_fname_src,
1180 const struct smb_filename *smb_fname_dst)
1184 result = SMB_VFS_NEXT_RENAME(handle, smb_fname_src, smb_fname_dst);
1186 do_log(SMB_VFS_OP_RENAME, (result >= 0), handle, "%s|%s",
1187 smb_fname_str_do_log(smb_fname_src),
1188 smb_fname_str_do_log(smb_fname_dst));
1193 static int smb_full_audit_fsync(vfs_handle_struct *handle, files_struct *fsp)
1197 result = SMB_VFS_NEXT_FSYNC(handle, fsp);
1199 do_log(SMB_VFS_OP_FSYNC, (result >= 0), handle, "%s",
1200 fsp_str_do_log(fsp));
1205 struct smb_full_audit_fsync_state {
1206 vfs_handle_struct *handle;
1212 static void smb_full_audit_fsync_done(struct tevent_req *subreq);
1214 static struct tevent_req *smb_full_audit_fsync_send(
1215 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1216 struct tevent_context *ev, struct files_struct *fsp)
1218 struct tevent_req *req, *subreq;
1219 struct smb_full_audit_fsync_state *state;
1221 req = tevent_req_create(mem_ctx, &state,
1222 struct smb_full_audit_fsync_state);
1224 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1225 fsp_str_do_log(fsp));
1228 state->handle = handle;
1231 subreq = SMB_VFS_NEXT_FSYNC_SEND(state, ev, handle, fsp);
1232 if (tevent_req_nomem(subreq, req)) {
1233 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1234 fsp_str_do_log(fsp));
1235 return tevent_req_post(req, ev);
1237 tevent_req_set_callback(subreq, smb_full_audit_fsync_done, req);
1239 do_log(SMB_VFS_OP_FSYNC_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1243 static void smb_full_audit_fsync_done(struct tevent_req *subreq)
1245 struct tevent_req *req = tevent_req_callback_data(
1246 subreq, struct tevent_req);
1247 struct smb_full_audit_fsync_state *state = tevent_req_data(
1248 req, struct smb_full_audit_fsync_state);
1250 state->ret = SMB_VFS_FSYNC_RECV(subreq, &state->err);
1251 TALLOC_FREE(subreq);
1252 tevent_req_done(req);
1255 static int smb_full_audit_fsync_recv(struct tevent_req *req, int *err)
1257 struct smb_full_audit_fsync_state *state = tevent_req_data(
1258 req, struct smb_full_audit_fsync_state);
1260 if (tevent_req_is_unix_error(req, err)) {
1261 do_log(SMB_VFS_OP_FSYNC_RECV, false, state->handle, "%s",
1262 fsp_str_do_log(state->fsp));
1266 do_log(SMB_VFS_OP_FSYNC_RECV, (state->ret >= 0), state->handle, "%s",
1267 fsp_str_do_log(state->fsp));
1273 static int smb_full_audit_stat(vfs_handle_struct *handle,
1274 struct smb_filename *smb_fname)
1278 result = SMB_VFS_NEXT_STAT(handle, smb_fname);
1280 do_log(SMB_VFS_OP_STAT, (result >= 0), handle, "%s",
1281 smb_fname_str_do_log(smb_fname));
1286 static int smb_full_audit_fstat(vfs_handle_struct *handle, files_struct *fsp,
1287 SMB_STRUCT_STAT *sbuf)
1291 result = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1293 do_log(SMB_VFS_OP_FSTAT, (result >= 0), handle, "%s",
1294 fsp_str_do_log(fsp));
1299 static int smb_full_audit_lstat(vfs_handle_struct *handle,
1300 struct smb_filename *smb_fname)
1304 result = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
1306 do_log(SMB_VFS_OP_LSTAT, (result >= 0), handle, "%s",
1307 smb_fname_str_do_log(smb_fname));
1312 static uint64_t smb_full_audit_get_alloc_size(vfs_handle_struct *handle,
1313 files_struct *fsp, const SMB_STRUCT_STAT *sbuf)
1317 result = SMB_VFS_NEXT_GET_ALLOC_SIZE(handle, fsp, sbuf);
1319 do_log(SMB_VFS_OP_GET_ALLOC_SIZE, (result != (uint64_t)-1), handle,
1325 static int smb_full_audit_unlink(vfs_handle_struct *handle,
1326 const struct smb_filename *smb_fname)
1330 result = SMB_VFS_NEXT_UNLINK(handle, smb_fname);
1332 do_log(SMB_VFS_OP_UNLINK, (result >= 0), handle, "%s",
1333 smb_fname_str_do_log(smb_fname));
1338 static int smb_full_audit_chmod(vfs_handle_struct *handle,
1339 const char *path, mode_t mode)
1343 result = SMB_VFS_NEXT_CHMOD(handle, path, mode);
1345 do_log(SMB_VFS_OP_CHMOD, (result >= 0), handle, "%s|%o", path, mode);
1350 static int smb_full_audit_fchmod(vfs_handle_struct *handle, files_struct *fsp,
1355 result = SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1357 do_log(SMB_VFS_OP_FCHMOD, (result >= 0), handle,
1358 "%s|%o", fsp_str_do_log(fsp), mode);
1363 static int smb_full_audit_chown(vfs_handle_struct *handle,
1364 const char *path, uid_t uid, gid_t gid)
1368 result = SMB_VFS_NEXT_CHOWN(handle, path, uid, gid);
1370 do_log(SMB_VFS_OP_CHOWN, (result >= 0), handle, "%s|%ld|%ld",
1371 path, (long int)uid, (long int)gid);
1376 static int smb_full_audit_fchown(vfs_handle_struct *handle, files_struct *fsp,
1377 uid_t uid, gid_t gid)
1381 result = SMB_VFS_NEXT_FCHOWN(handle, fsp, uid, gid);
1383 do_log(SMB_VFS_OP_FCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1384 fsp_str_do_log(fsp), (long int)uid, (long int)gid);
1389 static int smb_full_audit_lchown(vfs_handle_struct *handle,
1390 const char *path, uid_t uid, gid_t gid)
1394 result = SMB_VFS_NEXT_LCHOWN(handle, path, uid, gid);
1396 do_log(SMB_VFS_OP_LCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1397 path, (long int)uid, (long int)gid);
1402 static int smb_full_audit_chdir(vfs_handle_struct *handle,
1407 result = SMB_VFS_NEXT_CHDIR(handle, path);
1409 do_log(SMB_VFS_OP_CHDIR, (result >= 0), handle, "chdir|%s", path);
1414 static char *smb_full_audit_getwd(vfs_handle_struct *handle)
1418 result = SMB_VFS_NEXT_GETWD(handle);
1420 do_log(SMB_VFS_OP_GETWD, (result != NULL), handle, "%s",
1421 result == NULL? "" : result);
1426 static int smb_full_audit_ntimes(vfs_handle_struct *handle,
1427 const struct smb_filename *smb_fname,
1428 struct smb_file_time *ft)
1432 result = SMB_VFS_NEXT_NTIMES(handle, smb_fname, ft);
1434 do_log(SMB_VFS_OP_NTIMES, (result >= 0), handle, "%s",
1435 smb_fname_str_do_log(smb_fname));
1440 static int smb_full_audit_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
1445 result = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1447 do_log(SMB_VFS_OP_FTRUNCATE, (result >= 0), handle,
1448 "%s", fsp_str_do_log(fsp));
1453 static int smb_full_audit_fallocate(vfs_handle_struct *handle, files_struct *fsp,
1454 enum vfs_fallocate_mode mode,
1460 result = SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
1462 do_log(SMB_VFS_OP_FALLOCATE, (result >= 0), handle,
1463 "%s", fsp_str_do_log(fsp));
1468 static bool smb_full_audit_lock(vfs_handle_struct *handle, files_struct *fsp,
1469 int op, off_t offset, off_t count, int type)
1473 result = SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type);
1475 do_log(SMB_VFS_OP_LOCK, result, handle, "%s", fsp_str_do_log(fsp));
1480 static int smb_full_audit_kernel_flock(struct vfs_handle_struct *handle,
1481 struct files_struct *fsp,
1482 uint32 share_mode, uint32 access_mask)
1486 result = SMB_VFS_NEXT_KERNEL_FLOCK(handle, fsp, share_mode, access_mask);
1488 do_log(SMB_VFS_OP_KERNEL_FLOCK, (result >= 0), handle, "%s",
1489 fsp_str_do_log(fsp));
1494 static int smb_full_audit_linux_setlease(vfs_handle_struct *handle, files_struct *fsp,
1499 result = SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
1501 do_log(SMB_VFS_OP_LINUX_SETLEASE, (result >= 0), handle, "%s",
1502 fsp_str_do_log(fsp));
1507 static bool smb_full_audit_getlock(vfs_handle_struct *handle, files_struct *fsp,
1508 off_t *poffset, off_t *pcount, int *ptype, pid_t *ppid)
1512 result = SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype, ppid);
1514 do_log(SMB_VFS_OP_GETLOCK, result, handle, "%s", fsp_str_do_log(fsp));
1519 static int smb_full_audit_symlink(vfs_handle_struct *handle,
1520 const char *oldpath, const char *newpath)
1524 result = SMB_VFS_NEXT_SYMLINK(handle, oldpath, newpath);
1526 do_log(SMB_VFS_OP_SYMLINK, (result >= 0), handle,
1527 "%s|%s", oldpath, newpath);
1532 static int smb_full_audit_readlink(vfs_handle_struct *handle,
1533 const char *path, char *buf, size_t bufsiz)
1537 result = SMB_VFS_NEXT_READLINK(handle, path, buf, bufsiz);
1539 do_log(SMB_VFS_OP_READLINK, (result >= 0), handle, "%s", path);
1544 static int smb_full_audit_link(vfs_handle_struct *handle,
1545 const char *oldpath, const char *newpath)
1549 result = SMB_VFS_NEXT_LINK(handle, oldpath, newpath);
1551 do_log(SMB_VFS_OP_LINK, (result >= 0), handle,
1552 "%s|%s", oldpath, newpath);
1557 static int smb_full_audit_mknod(vfs_handle_struct *handle,
1558 const char *pathname, mode_t mode, SMB_DEV_T dev)
1562 result = SMB_VFS_NEXT_MKNOD(handle, pathname, mode, dev);
1564 do_log(SMB_VFS_OP_MKNOD, (result >= 0), handle, "%s", pathname);
1569 static char *smb_full_audit_realpath(vfs_handle_struct *handle,
1574 result = SMB_VFS_NEXT_REALPATH(handle, path);
1576 do_log(SMB_VFS_OP_REALPATH, (result != NULL), handle, "%s", path);
1581 static NTSTATUS smb_full_audit_notify_watch(struct vfs_handle_struct *handle,
1582 struct sys_notify_context *ctx,
1585 uint32_t *subdir_filter,
1586 void (*callback)(struct sys_notify_context *ctx,
1588 struct notify_event *ev),
1589 void *private_data, void *handle_p)
1593 result = SMB_VFS_NEXT_NOTIFY_WATCH(handle, ctx, path,
1594 filter, subdir_filter, callback,
1595 private_data, handle_p);
1597 do_log(SMB_VFS_OP_NOTIFY_WATCH, NT_STATUS_IS_OK(result), handle, "");
1602 static int smb_full_audit_chflags(vfs_handle_struct *handle,
1603 const char *path, unsigned int flags)
1607 result = SMB_VFS_NEXT_CHFLAGS(handle, path, flags);
1609 do_log(SMB_VFS_OP_CHFLAGS, (result != 0), handle, "%s", path);
1614 static struct file_id smb_full_audit_file_id_create(struct vfs_handle_struct *handle,
1615 const SMB_STRUCT_STAT *sbuf)
1617 struct file_id id_zero;
1618 struct file_id result;
1620 ZERO_STRUCT(id_zero);
1622 result = SMB_VFS_NEXT_FILE_ID_CREATE(handle, sbuf);
1624 do_log(SMB_VFS_OP_FILE_ID_CREATE,
1625 !file_id_equal(&id_zero, &result),
1626 handle, "%s", file_id_string_tos(&result));
1631 static NTSTATUS smb_full_audit_streaminfo(vfs_handle_struct *handle,
1632 struct files_struct *fsp,
1634 TALLOC_CTX *mem_ctx,
1635 unsigned int *pnum_streams,
1636 struct stream_struct **pstreams)
1640 result = SMB_VFS_NEXT_STREAMINFO(handle, fsp, fname, mem_ctx,
1641 pnum_streams, pstreams);
1643 do_log(SMB_VFS_OP_STREAMINFO, NT_STATUS_IS_OK(result), handle,
1649 static int smb_full_audit_get_real_filename(struct vfs_handle_struct *handle,
1652 TALLOC_CTX *mem_ctx,
1657 result = SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name, mem_ctx,
1660 do_log(SMB_VFS_OP_GET_REAL_FILENAME, (result == 0), handle,
1661 "%s/%s->%s", path, name, (result == 0) ? "" : *found_name);
1666 static const char *smb_full_audit_connectpath(vfs_handle_struct *handle,
1671 result = SMB_VFS_NEXT_CONNECTPATH(handle, fname);
1673 do_log(SMB_VFS_OP_CONNECTPATH, result != NULL, handle,
1679 static NTSTATUS smb_full_audit_brl_lock_windows(struct vfs_handle_struct *handle,
1680 struct byte_range_lock *br_lck,
1681 struct lock_struct *plock,
1686 result = SMB_VFS_NEXT_BRL_LOCK_WINDOWS(handle, br_lck, plock,
1689 do_log(SMB_VFS_OP_BRL_LOCK_WINDOWS, NT_STATUS_IS_OK(result), handle,
1690 "%s:%llu-%llu. type=%d. blocking=%d",
1691 fsp_str_do_log(brl_fsp(br_lck)),
1692 plock->start, plock->size, plock->lock_type, blocking_lock);
1697 static bool smb_full_audit_brl_unlock_windows(struct vfs_handle_struct *handle,
1698 struct messaging_context *msg_ctx,
1699 struct byte_range_lock *br_lck,
1700 const struct lock_struct *plock)
1704 result = SMB_VFS_NEXT_BRL_UNLOCK_WINDOWS(handle, msg_ctx, br_lck,
1707 do_log(SMB_VFS_OP_BRL_UNLOCK_WINDOWS, (result == 0), handle,
1708 "%s:%llu-%llu:%d", fsp_str_do_log(brl_fsp(br_lck)),
1710 plock->size, plock->lock_type);
1715 static bool smb_full_audit_brl_cancel_windows(struct vfs_handle_struct *handle,
1716 struct byte_range_lock *br_lck,
1717 struct lock_struct *plock)
1721 result = SMB_VFS_NEXT_BRL_CANCEL_WINDOWS(handle, br_lck, plock);
1723 do_log(SMB_VFS_OP_BRL_CANCEL_WINDOWS, (result == 0), handle,
1724 "%s:%llu-%llu:%d", fsp_str_do_log(brl_fsp(br_lck)),
1726 plock->size, plock->lock_type);
1731 static bool smb_full_audit_strict_lock(struct vfs_handle_struct *handle,
1732 struct files_struct *fsp,
1733 struct lock_struct *plock)
1737 result = SMB_VFS_NEXT_STRICT_LOCK(handle, fsp, plock);
1739 do_log(SMB_VFS_OP_STRICT_LOCK, result, handle,
1740 "%s:%llu-%llu:%d", fsp_str_do_log(fsp), plock->start,
1741 plock->size, plock->lock_type);
1746 static void smb_full_audit_strict_unlock(struct vfs_handle_struct *handle,
1747 struct files_struct *fsp,
1748 struct lock_struct *plock)
1750 SMB_VFS_NEXT_STRICT_UNLOCK(handle, fsp, plock);
1752 do_log(SMB_VFS_OP_STRICT_UNLOCK, true, handle,
1753 "%s:%llu-%llu:%d", fsp_str_do_log(fsp), plock->start,
1754 plock->size, plock->lock_type);
1757 static NTSTATUS smb_full_audit_translate_name(struct vfs_handle_struct *handle,
1759 enum vfs_translate_direction direction,
1760 TALLOC_CTX *mem_ctx,
1765 result = SMB_VFS_NEXT_TRANSLATE_NAME(handle, name, direction, mem_ctx,
1768 do_log(SMB_VFS_OP_TRANSLATE_NAME, NT_STATUS_IS_OK(result), handle, "");
1773 static struct tevent_req *smb_full_audit_copy_chunk_send(struct vfs_handle_struct *handle,
1774 TALLOC_CTX *mem_ctx,
1775 struct tevent_context *ev,
1776 struct files_struct *src_fsp,
1778 struct files_struct *dest_fsp,
1782 struct tevent_req *req;
1784 req = SMB_VFS_NEXT_COPY_CHUNK_SEND(handle, mem_ctx, ev, src_fsp,
1785 src_off, dest_fsp, dest_off, num);
1787 do_log(SMB_VFS_OP_COPY_CHUNK_SEND, req, handle, "");
1792 static NTSTATUS smb_full_audit_copy_chunk_recv(struct vfs_handle_struct *handle,
1793 struct tevent_req *req,
1798 result = SMB_VFS_NEXT_COPY_CHUNK_RECV(handle, req, copied);
1800 do_log(SMB_VFS_OP_COPY_CHUNK_RECV, NT_STATUS_IS_OK(result), handle, "");
1805 static NTSTATUS smb_full_audit_get_compression(vfs_handle_struct *handle,
1806 TALLOC_CTX *mem_ctx,
1807 struct files_struct *fsp,
1808 struct smb_filename *smb_fname,
1809 uint16_t *_compression_fmt)
1813 result = SMB_VFS_NEXT_GET_COMPRESSION(handle, mem_ctx, fsp, smb_fname,
1816 do_log(SMB_VFS_OP_GET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
1818 (fsp ? fsp_str_do_log(fsp) : smb_fname_str_do_log(smb_fname)));
1823 static NTSTATUS smb_full_audit_set_compression(vfs_handle_struct *handle,
1824 TALLOC_CTX *mem_ctx,
1825 struct files_struct *fsp,
1826 uint16_t compression_fmt)
1830 result = SMB_VFS_NEXT_SET_COMPRESSION(handle, mem_ctx, fsp,
1833 do_log(SMB_VFS_OP_SET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
1834 "%s", fsp_str_do_log(fsp));
1839 static NTSTATUS smb_full_audit_readdir_attr(struct vfs_handle_struct *handle,
1840 const struct smb_filename *fname,
1841 TALLOC_CTX *mem_ctx,
1842 struct readdir_attr_data **pattr_data)
1846 status = SMB_VFS_NEXT_READDIR_ATTR(handle, fname, mem_ctx, pattr_data);
1848 do_log(SMB_VFS_OP_READDIR_ATTR, NT_STATUS_IS_OK(status), handle, "%s",
1849 smb_fname_str_do_log(fname));
1854 static NTSTATUS smb_full_audit_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
1855 uint32 security_info,
1856 TALLOC_CTX *mem_ctx,
1857 struct security_descriptor **ppdesc)
1861 result = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
1864 do_log(SMB_VFS_OP_FGET_NT_ACL, NT_STATUS_IS_OK(result), handle,
1865 "%s", fsp_str_do_log(fsp));
1870 static NTSTATUS smb_full_audit_get_nt_acl(vfs_handle_struct *handle,
1872 uint32 security_info,
1873 TALLOC_CTX *mem_ctx,
1874 struct security_descriptor **ppdesc)
1878 result = SMB_VFS_NEXT_GET_NT_ACL(handle, name, security_info,
1881 do_log(SMB_VFS_OP_GET_NT_ACL, NT_STATUS_IS_OK(result), handle,
1887 static NTSTATUS smb_full_audit_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
1888 uint32 security_info_sent,
1889 const struct security_descriptor *psd)
1891 struct vfs_full_audit_private_data *pd;
1895 SMB_VFS_HANDLE_GET_DATA(handle, pd,
1896 struct vfs_full_audit_private_data,
1897 return NT_STATUS_INTERNAL_ERROR);
1899 if (pd->log_secdesc) {
1900 sd = sddl_encode(talloc_tos(), psd, get_global_sam_sid());
1903 result = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
1905 do_log(SMB_VFS_OP_FSET_NT_ACL, NT_STATUS_IS_OK(result), handle,
1906 "%s [%s]", fsp_str_do_log(fsp), sd ? sd : "");
1913 static int smb_full_audit_chmod_acl(vfs_handle_struct *handle,
1914 const char *path, mode_t mode)
1918 result = SMB_VFS_NEXT_CHMOD_ACL(handle, path, mode);
1920 do_log(SMB_VFS_OP_CHMOD_ACL, (result >= 0), handle,
1921 "%s|%o", path, mode);
1926 static int smb_full_audit_fchmod_acl(vfs_handle_struct *handle, files_struct *fsp,
1931 result = SMB_VFS_NEXT_FCHMOD_ACL(handle, fsp, mode);
1933 do_log(SMB_VFS_OP_FCHMOD_ACL, (result >= 0), handle,
1934 "%s|%o", fsp_str_do_log(fsp), mode);
1939 static SMB_ACL_T smb_full_audit_sys_acl_get_file(vfs_handle_struct *handle,
1941 SMB_ACL_TYPE_T type,
1942 TALLOC_CTX *mem_ctx)
1946 result = SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, path_p, type, mem_ctx);
1948 do_log(SMB_VFS_OP_SYS_ACL_GET_FILE, (result != NULL), handle,
1954 static SMB_ACL_T smb_full_audit_sys_acl_get_fd(vfs_handle_struct *handle,
1955 files_struct *fsp, TALLOC_CTX *mem_ctx)
1959 result = SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp, mem_ctx);
1961 do_log(SMB_VFS_OP_SYS_ACL_GET_FD, (result != NULL), handle,
1962 "%s", fsp_str_do_log(fsp));
1967 static int smb_full_audit_sys_acl_blob_get_file(vfs_handle_struct *handle,
1969 TALLOC_CTX *mem_ctx,
1970 char **blob_description,
1975 result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FILE(handle, path_p, mem_ctx, blob_description, blob);
1977 do_log(SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE, (result >= 0), handle,
1983 static int smb_full_audit_sys_acl_blob_get_fd(vfs_handle_struct *handle,
1985 TALLOC_CTX *mem_ctx,
1986 char **blob_description,
1991 result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle, fsp, mem_ctx, blob_description, blob);
1993 do_log(SMB_VFS_OP_SYS_ACL_BLOB_GET_FD, (result >= 0), handle,
1994 "%s", fsp_str_do_log(fsp));
1999 static int smb_full_audit_sys_acl_set_file(vfs_handle_struct *handle,
2001 const char *name, SMB_ACL_TYPE_T acltype,
2006 result = SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, name, acltype,
2009 do_log(SMB_VFS_OP_SYS_ACL_SET_FILE, (result >= 0), handle,
2015 static int smb_full_audit_sys_acl_set_fd(vfs_handle_struct *handle, files_struct *fsp,
2020 result = SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, theacl);
2022 do_log(SMB_VFS_OP_SYS_ACL_SET_FD, (result >= 0), handle,
2023 "%s", fsp_str_do_log(fsp));
2028 static int smb_full_audit_sys_acl_delete_def_file(vfs_handle_struct *handle,
2034 result = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, path);
2036 do_log(SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE, (result >= 0), handle,
2042 static ssize_t smb_full_audit_getxattr(struct vfs_handle_struct *handle,
2044 const char *name, void *value, size_t size)
2048 result = SMB_VFS_NEXT_GETXATTR(handle, path, name, value, size);
2050 do_log(SMB_VFS_OP_GETXATTR, (result >= 0), handle,
2051 "%s|%s", path, name);
2056 static ssize_t smb_full_audit_fgetxattr(struct vfs_handle_struct *handle,
2057 struct files_struct *fsp,
2058 const char *name, void *value, size_t size)
2062 result = SMB_VFS_NEXT_FGETXATTR(handle, fsp, name, value, size);
2064 do_log(SMB_VFS_OP_FGETXATTR, (result >= 0), handle,
2065 "%s|%s", fsp_str_do_log(fsp), name);
2070 static ssize_t smb_full_audit_listxattr(struct vfs_handle_struct *handle,
2071 const char *path, char *list, size_t size)
2075 result = SMB_VFS_NEXT_LISTXATTR(handle, path, list, size);
2077 do_log(SMB_VFS_OP_LISTXATTR, (result >= 0), handle, "%s", path);
2082 static ssize_t smb_full_audit_flistxattr(struct vfs_handle_struct *handle,
2083 struct files_struct *fsp, char *list,
2088 result = SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
2090 do_log(SMB_VFS_OP_FLISTXATTR, (result >= 0), handle,
2091 "%s", fsp_str_do_log(fsp));
2096 static int smb_full_audit_removexattr(struct vfs_handle_struct *handle,
2102 result = SMB_VFS_NEXT_REMOVEXATTR(handle, path, name);
2104 do_log(SMB_VFS_OP_REMOVEXATTR, (result >= 0), handle,
2105 "%s|%s", path, name);
2110 static int smb_full_audit_fremovexattr(struct vfs_handle_struct *handle,
2111 struct files_struct *fsp,
2116 result = SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, name);
2118 do_log(SMB_VFS_OP_FREMOVEXATTR, (result >= 0), handle,
2119 "%s|%s", fsp_str_do_log(fsp), name);
2124 static int smb_full_audit_setxattr(struct vfs_handle_struct *handle,
2126 const char *name, const void *value, size_t size,
2131 result = SMB_VFS_NEXT_SETXATTR(handle, path, name, value, size,
2134 do_log(SMB_VFS_OP_SETXATTR, (result >= 0), handle,
2135 "%s|%s", path, name);
2140 static int smb_full_audit_fsetxattr(struct vfs_handle_struct *handle,
2141 struct files_struct *fsp, const char *name,
2142 const void *value, size_t size, int flags)
2146 result = SMB_VFS_NEXT_FSETXATTR(handle, fsp, name, value, size, flags);
2148 do_log(SMB_VFS_OP_FSETXATTR, (result >= 0), handle,
2149 "%s|%s", fsp_str_do_log(fsp), name);
2154 static bool smb_full_audit_aio_force(struct vfs_handle_struct *handle,
2155 struct files_struct *fsp)
2159 result = SMB_VFS_NEXT_AIO_FORCE(handle, fsp);
2160 do_log(SMB_VFS_OP_AIO_FORCE, result, handle,
2161 "%s", fsp_str_do_log(fsp));
2166 static bool smb_full_audit_is_offline(struct vfs_handle_struct *handle,
2167 const struct smb_filename *fname,
2168 SMB_STRUCT_STAT *sbuf)
2172 result = SMB_VFS_NEXT_IS_OFFLINE(handle, fname, sbuf);
2173 do_log(SMB_VFS_OP_IS_OFFLINE, result, handle, "%s",
2174 smb_fname_str_do_log(fname));
2178 static int smb_full_audit_set_offline(struct vfs_handle_struct *handle,
2179 const struct smb_filename *fname)
2183 result = SMB_VFS_NEXT_SET_OFFLINE(handle, fname);
2184 do_log(SMB_VFS_OP_SET_OFFLINE, result >= 0, handle, "%s",
2185 smb_fname_str_do_log(fname));
2189 static struct vfs_fn_pointers vfs_full_audit_fns = {
2191 /* Disk operations */
2193 .connect_fn = smb_full_audit_connect,
2194 .disconnect_fn = smb_full_audit_disconnect,
2195 .disk_free_fn = smb_full_audit_disk_free,
2196 .get_quota_fn = smb_full_audit_get_quota,
2197 .set_quota_fn = smb_full_audit_set_quota,
2198 .get_shadow_copy_data_fn = smb_full_audit_get_shadow_copy_data,
2199 .statvfs_fn = smb_full_audit_statvfs,
2200 .fs_capabilities_fn = smb_full_audit_fs_capabilities,
2201 .opendir_fn = smb_full_audit_opendir,
2202 .fdopendir_fn = smb_full_audit_fdopendir,
2203 .readdir_fn = smb_full_audit_readdir,
2204 .seekdir_fn = smb_full_audit_seekdir,
2205 .telldir_fn = smb_full_audit_telldir,
2206 .rewind_dir_fn = smb_full_audit_rewinddir,
2207 .mkdir_fn = smb_full_audit_mkdir,
2208 .rmdir_fn = smb_full_audit_rmdir,
2209 .closedir_fn = smb_full_audit_closedir,
2210 .init_search_op_fn = smb_full_audit_init_search_op,
2211 .open_fn = smb_full_audit_open,
2212 .create_file_fn = smb_full_audit_create_file,
2213 .close_fn = smb_full_audit_close,
2214 .read_fn = smb_full_audit_read,
2215 .pread_fn = smb_full_audit_pread,
2216 .pread_send_fn = smb_full_audit_pread_send,
2217 .pread_recv_fn = smb_full_audit_pread_recv,
2218 .write_fn = smb_full_audit_write,
2219 .pwrite_fn = smb_full_audit_pwrite,
2220 .pwrite_send_fn = smb_full_audit_pwrite_send,
2221 .pwrite_recv_fn = smb_full_audit_pwrite_recv,
2222 .lseek_fn = smb_full_audit_lseek,
2223 .sendfile_fn = smb_full_audit_sendfile,
2224 .recvfile_fn = smb_full_audit_recvfile,
2225 .rename_fn = smb_full_audit_rename,
2226 .fsync_fn = smb_full_audit_fsync,
2227 .fsync_send_fn = smb_full_audit_fsync_send,
2228 .fsync_recv_fn = smb_full_audit_fsync_recv,
2229 .stat_fn = smb_full_audit_stat,
2230 .fstat_fn = smb_full_audit_fstat,
2231 .lstat_fn = smb_full_audit_lstat,
2232 .get_alloc_size_fn = smb_full_audit_get_alloc_size,
2233 .unlink_fn = smb_full_audit_unlink,
2234 .chmod_fn = smb_full_audit_chmod,
2235 .fchmod_fn = smb_full_audit_fchmod,
2236 .chown_fn = smb_full_audit_chown,
2237 .fchown_fn = smb_full_audit_fchown,
2238 .lchown_fn = smb_full_audit_lchown,
2239 .chdir_fn = smb_full_audit_chdir,
2240 .getwd_fn = smb_full_audit_getwd,
2241 .ntimes_fn = smb_full_audit_ntimes,
2242 .ftruncate_fn = smb_full_audit_ftruncate,
2243 .fallocate_fn = smb_full_audit_fallocate,
2244 .lock_fn = smb_full_audit_lock,
2245 .kernel_flock_fn = smb_full_audit_kernel_flock,
2246 .linux_setlease_fn = smb_full_audit_linux_setlease,
2247 .getlock_fn = smb_full_audit_getlock,
2248 .symlink_fn = smb_full_audit_symlink,
2249 .readlink_fn = smb_full_audit_readlink,
2250 .link_fn = smb_full_audit_link,
2251 .mknod_fn = smb_full_audit_mknod,
2252 .realpath_fn = smb_full_audit_realpath,
2253 .notify_watch_fn = smb_full_audit_notify_watch,
2254 .chflags_fn = smb_full_audit_chflags,
2255 .file_id_create_fn = smb_full_audit_file_id_create,
2256 .streaminfo_fn = smb_full_audit_streaminfo,
2257 .get_real_filename_fn = smb_full_audit_get_real_filename,
2258 .connectpath_fn = smb_full_audit_connectpath,
2259 .brl_lock_windows_fn = smb_full_audit_brl_lock_windows,
2260 .brl_unlock_windows_fn = smb_full_audit_brl_unlock_windows,
2261 .brl_cancel_windows_fn = smb_full_audit_brl_cancel_windows,
2262 .strict_lock_fn = smb_full_audit_strict_lock,
2263 .strict_unlock_fn = smb_full_audit_strict_unlock,
2264 .translate_name_fn = smb_full_audit_translate_name,
2265 .copy_chunk_send_fn = smb_full_audit_copy_chunk_send,
2266 .copy_chunk_recv_fn = smb_full_audit_copy_chunk_recv,
2267 .get_compression_fn = smb_full_audit_get_compression,
2268 .set_compression_fn = smb_full_audit_set_compression,
2269 .readdir_attr_fn = smb_full_audit_readdir_attr,
2270 .fget_nt_acl_fn = smb_full_audit_fget_nt_acl,
2271 .get_nt_acl_fn = smb_full_audit_get_nt_acl,
2272 .fset_nt_acl_fn = smb_full_audit_fset_nt_acl,
2273 .chmod_acl_fn = smb_full_audit_chmod_acl,
2274 .fchmod_acl_fn = smb_full_audit_fchmod_acl,
2275 .sys_acl_get_file_fn = smb_full_audit_sys_acl_get_file,
2276 .sys_acl_get_fd_fn = smb_full_audit_sys_acl_get_fd,
2277 .sys_acl_blob_get_file_fn = smb_full_audit_sys_acl_blob_get_file,
2278 .sys_acl_blob_get_fd_fn = smb_full_audit_sys_acl_blob_get_fd,
2279 .sys_acl_set_file_fn = smb_full_audit_sys_acl_set_file,
2280 .sys_acl_set_fd_fn = smb_full_audit_sys_acl_set_fd,
2281 .sys_acl_delete_def_file_fn = smb_full_audit_sys_acl_delete_def_file,
2282 .getxattr_fn = smb_full_audit_getxattr,
2283 .fgetxattr_fn = smb_full_audit_fgetxattr,
2284 .listxattr_fn = smb_full_audit_listxattr,
2285 .flistxattr_fn = smb_full_audit_flistxattr,
2286 .removexattr_fn = smb_full_audit_removexattr,
2287 .fremovexattr_fn = smb_full_audit_fremovexattr,
2288 .setxattr_fn = smb_full_audit_setxattr,
2289 .fsetxattr_fn = smb_full_audit_fsetxattr,
2290 .aio_force_fn = smb_full_audit_aio_force,
2291 .is_offline_fn = smb_full_audit_is_offline,
2292 .set_offline_fn = smb_full_audit_set_offline,
2295 NTSTATUS vfs_full_audit_init(void)
2297 NTSTATUS ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION,
2298 "full_audit", &vfs_full_audit_fns);
2300 if (!NT_STATUS_IS_OK(ret))
2303 vfs_full_audit_debug_level = debug_add_class("full_audit");
2304 if (vfs_full_audit_debug_level == -1) {
2305 vfs_full_audit_debug_level = DBGC_VFS;
2306 DEBUG(0, ("vfs_full_audit: Couldn't register custom debugging "
2309 DEBUG(10, ("vfs_full_audit: Debug class number of "
2310 "'full_audit': %d\n", vfs_full_audit_debug_level));