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"
71 static int vfs_full_audit_debug_level = DBGC_VFS;
73 struct vfs_full_audit_private_data {
74 struct bitmap *success_ops;
75 struct bitmap *failure_ops;
80 #define DBGC_CLASS vfs_full_audit_debug_level
82 typedef enum _vfs_op_type {
87 SMB_VFS_OP_CONNECT = 0,
88 SMB_VFS_OP_DISCONNECT,
92 SMB_VFS_OP_GET_SHADOW_COPY_DATA,
94 SMB_VFS_OP_FS_CAPABILITIES,
96 /* Directory operations */
103 SMB_VFS_OP_REWINDDIR,
107 SMB_VFS_OP_INIT_SEARCH_OP,
109 /* File operations */
112 SMB_VFS_OP_CREATE_FILE,
116 SMB_VFS_OP_PREAD_SEND,
117 SMB_VFS_OP_PREAD_RECV,
120 SMB_VFS_OP_PWRITE_SEND,
121 SMB_VFS_OP_PWRITE_RECV,
127 SMB_VFS_OP_FSYNC_SEND,
128 SMB_VFS_OP_FSYNC_RECV,
132 SMB_VFS_OP_GET_ALLOC_SIZE,
142 SMB_VFS_OP_FTRUNCATE,
143 SMB_VFS_OP_FALLOCATE,
145 SMB_VFS_OP_KERNEL_FLOCK,
146 SMB_VFS_OP_LINUX_SETLEASE,
153 SMB_VFS_OP_NOTIFY_WATCH,
155 SMB_VFS_OP_FILE_ID_CREATE,
156 SMB_VFS_OP_STREAMINFO,
157 SMB_VFS_OP_GET_REAL_FILENAME,
158 SMB_VFS_OP_CONNECTPATH,
159 SMB_VFS_OP_BRL_LOCK_WINDOWS,
160 SMB_VFS_OP_BRL_UNLOCK_WINDOWS,
161 SMB_VFS_OP_BRL_CANCEL_WINDOWS,
162 SMB_VFS_OP_STRICT_LOCK,
163 SMB_VFS_OP_STRICT_UNLOCK,
164 SMB_VFS_OP_TRANSLATE_NAME,
165 SMB_VFS_OP_COPY_CHUNK_SEND,
166 SMB_VFS_OP_COPY_CHUNK_RECV,
167 SMB_VFS_OP_GET_COMPRESSION,
168 SMB_VFS_OP_SET_COMPRESSION,
170 /* NT ACL operations. */
172 SMB_VFS_OP_FGET_NT_ACL,
173 SMB_VFS_OP_GET_NT_ACL,
174 SMB_VFS_OP_FSET_NT_ACL,
176 /* POSIX ACL operations. */
178 SMB_VFS_OP_CHMOD_ACL,
179 SMB_VFS_OP_FCHMOD_ACL,
181 SMB_VFS_OP_SYS_ACL_GET_FILE,
182 SMB_VFS_OP_SYS_ACL_GET_FD,
183 SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE,
184 SMB_VFS_OP_SYS_ACL_BLOB_GET_FD,
185 SMB_VFS_OP_SYS_ACL_SET_FILE,
186 SMB_VFS_OP_SYS_ACL_SET_FD,
187 SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE,
191 SMB_VFS_OP_FGETXATTR,
192 SMB_VFS_OP_LISTXATTR,
193 SMB_VFS_OP_FLISTXATTR,
194 SMB_VFS_OP_REMOVEXATTR,
195 SMB_VFS_OP_FREMOVEXATTR,
197 SMB_VFS_OP_FSETXATTR,
200 SMB_VFS_OP_AIO_FORCE,
202 /* offline operations */
203 SMB_VFS_OP_IS_OFFLINE,
204 SMB_VFS_OP_SET_OFFLINE,
206 /* This should always be last enum value */
211 /* The following array *must* be in the same order as defined in vfs_op_type */
217 { SMB_VFS_OP_CONNECT, "connect" },
218 { SMB_VFS_OP_DISCONNECT, "disconnect" },
219 { SMB_VFS_OP_DISK_FREE, "disk_free" },
220 { SMB_VFS_OP_GET_QUOTA, "get_quota" },
221 { SMB_VFS_OP_SET_QUOTA, "set_quota" },
222 { SMB_VFS_OP_GET_SHADOW_COPY_DATA, "get_shadow_copy_data" },
223 { SMB_VFS_OP_STATVFS, "statvfs" },
224 { SMB_VFS_OP_FS_CAPABILITIES, "fs_capabilities" },
225 { SMB_VFS_OP_OPENDIR, "opendir" },
226 { SMB_VFS_OP_FDOPENDIR, "fdopendir" },
227 { SMB_VFS_OP_READDIR, "readdir" },
228 { SMB_VFS_OP_SEEKDIR, "seekdir" },
229 { SMB_VFS_OP_TELLDIR, "telldir" },
230 { SMB_VFS_OP_REWINDDIR, "rewinddir" },
231 { SMB_VFS_OP_MKDIR, "mkdir" },
232 { SMB_VFS_OP_RMDIR, "rmdir" },
233 { SMB_VFS_OP_CLOSEDIR, "closedir" },
234 { SMB_VFS_OP_INIT_SEARCH_OP, "init_search_op" },
235 { SMB_VFS_OP_OPEN, "open" },
236 { SMB_VFS_OP_CREATE_FILE, "create_file" },
237 { SMB_VFS_OP_CLOSE, "close" },
238 { SMB_VFS_OP_READ, "read" },
239 { SMB_VFS_OP_PREAD, "pread" },
240 { SMB_VFS_OP_PREAD_SEND, "pread_send" },
241 { SMB_VFS_OP_PREAD_RECV, "pread_recv" },
242 { SMB_VFS_OP_WRITE, "write" },
243 { SMB_VFS_OP_PWRITE, "pwrite" },
244 { SMB_VFS_OP_PWRITE_SEND, "pwrite_send" },
245 { SMB_VFS_OP_PWRITE_RECV, "pwrite_recv" },
246 { SMB_VFS_OP_LSEEK, "lseek" },
247 { SMB_VFS_OP_SENDFILE, "sendfile" },
248 { SMB_VFS_OP_RECVFILE, "recvfile" },
249 { SMB_VFS_OP_RENAME, "rename" },
250 { SMB_VFS_OP_FSYNC, "fsync" },
251 { SMB_VFS_OP_FSYNC_SEND, "fsync_send" },
252 { SMB_VFS_OP_FSYNC_RECV, "fsync_recv" },
253 { SMB_VFS_OP_STAT, "stat" },
254 { SMB_VFS_OP_FSTAT, "fstat" },
255 { SMB_VFS_OP_LSTAT, "lstat" },
256 { SMB_VFS_OP_GET_ALLOC_SIZE, "get_alloc_size" },
257 { SMB_VFS_OP_UNLINK, "unlink" },
258 { SMB_VFS_OP_CHMOD, "chmod" },
259 { SMB_VFS_OP_FCHMOD, "fchmod" },
260 { SMB_VFS_OP_CHOWN, "chown" },
261 { SMB_VFS_OP_FCHOWN, "fchown" },
262 { SMB_VFS_OP_LCHOWN, "lchown" },
263 { SMB_VFS_OP_CHDIR, "chdir" },
264 { SMB_VFS_OP_GETWD, "getwd" },
265 { SMB_VFS_OP_NTIMES, "ntimes" },
266 { SMB_VFS_OP_FTRUNCATE, "ftruncate" },
267 { SMB_VFS_OP_FALLOCATE,"fallocate" },
268 { SMB_VFS_OP_LOCK, "lock" },
269 { SMB_VFS_OP_KERNEL_FLOCK, "kernel_flock" },
270 { SMB_VFS_OP_LINUX_SETLEASE, "linux_setlease" },
271 { SMB_VFS_OP_GETLOCK, "getlock" },
272 { SMB_VFS_OP_SYMLINK, "symlink" },
273 { SMB_VFS_OP_READLINK, "readlink" },
274 { SMB_VFS_OP_LINK, "link" },
275 { SMB_VFS_OP_MKNOD, "mknod" },
276 { SMB_VFS_OP_REALPATH, "realpath" },
277 { SMB_VFS_OP_NOTIFY_WATCH, "notify_watch" },
278 { SMB_VFS_OP_CHFLAGS, "chflags" },
279 { SMB_VFS_OP_FILE_ID_CREATE, "file_id_create" },
280 { SMB_VFS_OP_STREAMINFO, "streaminfo" },
281 { SMB_VFS_OP_GET_REAL_FILENAME, "get_real_filename" },
282 { SMB_VFS_OP_CONNECTPATH, "connectpath" },
283 { SMB_VFS_OP_BRL_LOCK_WINDOWS, "brl_lock_windows" },
284 { SMB_VFS_OP_BRL_UNLOCK_WINDOWS, "brl_unlock_windows" },
285 { SMB_VFS_OP_BRL_CANCEL_WINDOWS, "brl_cancel_windows" },
286 { SMB_VFS_OP_STRICT_LOCK, "strict_lock" },
287 { SMB_VFS_OP_STRICT_UNLOCK, "strict_unlock" },
288 { SMB_VFS_OP_TRANSLATE_NAME, "translate_name" },
289 { SMB_VFS_OP_COPY_CHUNK_SEND, "copy_chunk_send" },
290 { SMB_VFS_OP_COPY_CHUNK_RECV, "copy_chunk_recv" },
291 { SMB_VFS_OP_GET_COMPRESSION, "get_compression" },
292 { SMB_VFS_OP_SET_COMPRESSION, "set_compression" },
293 { SMB_VFS_OP_FGET_NT_ACL, "fget_nt_acl" },
294 { SMB_VFS_OP_GET_NT_ACL, "get_nt_acl" },
295 { SMB_VFS_OP_FSET_NT_ACL, "fset_nt_acl" },
296 { SMB_VFS_OP_CHMOD_ACL, "chmod_acl" },
297 { SMB_VFS_OP_FCHMOD_ACL, "fchmod_acl" },
298 { SMB_VFS_OP_SYS_ACL_GET_FILE, "sys_acl_get_file" },
299 { SMB_VFS_OP_SYS_ACL_GET_FD, "sys_acl_get_fd" },
300 { SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE, "sys_acl_blob_get_file" },
301 { SMB_VFS_OP_SYS_ACL_BLOB_GET_FD, "sys_acl_blob_get_fd" },
302 { SMB_VFS_OP_SYS_ACL_SET_FILE, "sys_acl_set_file" },
303 { SMB_VFS_OP_SYS_ACL_SET_FD, "sys_acl_set_fd" },
304 { SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE, "sys_acl_delete_def_file" },
305 { SMB_VFS_OP_GETXATTR, "getxattr" },
306 { SMB_VFS_OP_FGETXATTR, "fgetxattr" },
307 { SMB_VFS_OP_LISTXATTR, "listxattr" },
308 { SMB_VFS_OP_FLISTXATTR, "flistxattr" },
309 { SMB_VFS_OP_REMOVEXATTR, "removexattr" },
310 { SMB_VFS_OP_FREMOVEXATTR, "fremovexattr" },
311 { SMB_VFS_OP_SETXATTR, "setxattr" },
312 { SMB_VFS_OP_FSETXATTR, "fsetxattr" },
313 { SMB_VFS_OP_AIO_FORCE, "aio_force" },
314 { SMB_VFS_OP_IS_OFFLINE, "is_offline" },
315 { SMB_VFS_OP_SET_OFFLINE, "set_offline" },
316 { SMB_VFS_OP_LAST, NULL }
319 static int audit_syslog_facility(vfs_handle_struct *handle)
321 static const struct enum_list enum_log_facilities[] = {
322 { LOG_USER, "USER" },
323 { LOG_LOCAL0, "LOCAL0" },
324 { LOG_LOCAL1, "LOCAL1" },
325 { LOG_LOCAL2, "LOCAL2" },
326 { LOG_LOCAL3, "LOCAL3" },
327 { LOG_LOCAL4, "LOCAL4" },
328 { LOG_LOCAL5, "LOCAL5" },
329 { LOG_LOCAL6, "LOCAL6" },
330 { LOG_LOCAL7, "LOCAL7" },
336 facility = lp_parm_enum(SNUM(handle->conn), "full_audit", "facility", enum_log_facilities, LOG_USER);
341 static int audit_syslog_priority(vfs_handle_struct *handle)
343 static const struct enum_list enum_log_priorities[] = {
344 { LOG_EMERG, "EMERG" },
345 { LOG_ALERT, "ALERT" },
346 { LOG_CRIT, "CRIT" },
348 { LOG_WARNING, "WARNING" },
349 { LOG_NOTICE, "NOTICE" },
350 { LOG_INFO, "INFO" },
351 { LOG_DEBUG, "DEBUG" },
357 priority = lp_parm_enum(SNUM(handle->conn), "full_audit", "priority",
358 enum_log_priorities, LOG_NOTICE);
359 if (priority == -1) {
360 priority = LOG_WARNING;
366 static char *audit_prefix(TALLOC_CTX *ctx, connection_struct *conn)
371 prefix = talloc_strdup(ctx,
372 lp_parm_const_string(SNUM(conn), "full_audit",
377 result = talloc_sub_advanced(ctx,
378 lp_servicename(talloc_tos(), SNUM(conn)),
379 conn->session_info->unix_info->unix_name,
381 conn->session_info->unix_token->gid,
382 conn->session_info->unix_info->sanitized_username,
383 conn->session_info->info->domain_name,
389 static bool log_success(struct vfs_full_audit_private_data *pd, vfs_op_type op)
391 if (pd->success_ops == NULL) {
395 return bitmap_query(pd->success_ops, op);
398 static bool log_failure(struct vfs_full_audit_private_data *pd, vfs_op_type op)
400 if (pd->failure_ops == NULL)
403 return bitmap_query(pd->failure_ops, op);
406 static struct bitmap *init_bitmap(TALLOC_CTX *mem_ctx, const char **ops)
414 bm = bitmap_talloc(mem_ctx, SMB_VFS_OP_LAST);
416 DEBUG(0, ("Could not alloc bitmap -- "
417 "defaulting to logging everything\n"));
421 for (; *ops != NULL; ops += 1) {
426 if (strequal(*ops, "all")) {
427 for (i=0; i<SMB_VFS_OP_LAST; i++) {
433 if (strequal(*ops, "none")) {
443 for (i=0; i<SMB_VFS_OP_LAST; i++) {
444 if ((vfs_op_names[i].name == NULL)
445 || (vfs_op_names[i].type != i)) {
446 smb_panic("vfs_full_audit.c: name table not "
447 "in sync with vfs_op_type enums\n");
449 if (strequal(op, vfs_op_names[i].name)) {
458 if (i == SMB_VFS_OP_LAST) {
459 DEBUG(0, ("Could not find opname %s, logging all\n",
468 static const char *audit_opname(vfs_op_type op)
470 if (op >= SMB_VFS_OP_LAST)
471 return "INVALID VFS OP";
472 return vfs_op_names[op].name;
475 static TALLOC_CTX *tmp_do_log_ctx;
477 * Get us a temporary talloc context usable just for DEBUG arguments
479 static TALLOC_CTX *do_log_ctx(void)
481 if (tmp_do_log_ctx == NULL) {
482 tmp_do_log_ctx = talloc_named_const(NULL, 0, "do_log_ctx");
484 return tmp_do_log_ctx;
487 static void do_log(vfs_op_type op, bool success, vfs_handle_struct *handle,
488 const char *format, ...)
490 struct vfs_full_audit_private_data *pd;
492 char *audit_pre = NULL;
497 SMB_VFS_HANDLE_GET_DATA(handle, pd,
498 struct vfs_full_audit_private_data,
501 if (success && (!log_success(pd, op)))
504 if (!success && (!log_failure(pd, op)))
508 fstrcpy(err_msg, "ok");
510 fstr_sprintf(err_msg, "fail (%s)", strerror(errno));
512 va_start(ap, format);
513 op_msg = talloc_vasprintf(talloc_tos(), format, ap);
521 * Specify the facility to interoperate with other syslog callers
522 * (smbd for example).
524 priority = audit_syslog_priority(handle) | pd->syslog_facility;
526 audit_pre = audit_prefix(talloc_tos(), handle->conn);
527 syslog(priority, "%s|%s|%s|%s\n",
528 audit_pre ? audit_pre : "",
529 audit_opname(op), err_msg, op_msg);
532 TALLOC_FREE(audit_pre);
534 TALLOC_FREE(tmp_do_log_ctx);
538 * Return a string using the do_log_ctx()
540 static const char *smb_fname_str_do_log(const struct smb_filename *smb_fname)
545 if (smb_fname == NULL) {
548 status = get_full_smb_filename(do_log_ctx(), smb_fname, &fname);
549 if (!NT_STATUS_IS_OK(status)) {
556 * Return an fsp debug string using the do_log_ctx()
558 static const char *fsp_str_do_log(const struct files_struct *fsp)
560 return smb_fname_str_do_log(fsp->fsp_name);
563 /* Implementation of vfs_ops. Pass everything on to the default
564 operation but log event first. */
566 static int smb_full_audit_connect(vfs_handle_struct *handle,
567 const char *svc, const char *user)
570 struct vfs_full_audit_private_data *pd = NULL;
572 result = SMB_VFS_NEXT_CONNECT(handle, svc, user);
577 pd = talloc_zero(handle, struct vfs_full_audit_private_data);
579 SMB_VFS_NEXT_DISCONNECT(handle);
583 pd->syslog_facility = audit_syslog_facility(handle);
584 if (pd->syslog_facility == -1) {
585 DEBUG(1, ("%s: Unknown facility %s\n", __func__,
586 lp_parm_const_string(SNUM(handle->conn),
587 "full_audit", "facility",
589 SMB_VFS_NEXT_DISCONNECT(handle);
594 openlog("smbd_audit", 0, pd->syslog_facility);
597 pd->success_ops = init_bitmap(
598 pd, lp_parm_string_list(SNUM(handle->conn), "full_audit",
600 pd->failure_ops = init_bitmap(
601 pd, lp_parm_string_list(SNUM(handle->conn), "full_audit",
604 /* Store the private data. */
605 SMB_VFS_HANDLE_SET_DATA(handle, pd, NULL,
606 struct vfs_full_audit_private_data, return -1);
608 do_log(SMB_VFS_OP_CONNECT, True, handle,
614 static void smb_full_audit_disconnect(vfs_handle_struct *handle)
616 SMB_VFS_NEXT_DISCONNECT(handle);
618 do_log(SMB_VFS_OP_DISCONNECT, True, handle,
619 "%s", lp_servicename(talloc_tos(), SNUM(handle->conn)));
621 /* The bitmaps will be disconnected when the private
625 static uint64_t smb_full_audit_disk_free(vfs_handle_struct *handle,
627 bool small_query, uint64_t *bsize,
628 uint64_t *dfree, uint64_t *dsize)
632 result = SMB_VFS_NEXT_DISK_FREE(handle, path, small_query, bsize,
635 /* Don't have a reasonable notion of failure here */
637 do_log(SMB_VFS_OP_DISK_FREE, True, handle, "%s", path);
642 static int smb_full_audit_get_quota(struct vfs_handle_struct *handle,
643 enum SMB_QUOTA_TYPE qtype, unid_t id,
648 result = SMB_VFS_NEXT_GET_QUOTA(handle, qtype, id, qt);
650 do_log(SMB_VFS_OP_GET_QUOTA, (result >= 0), handle, "");
656 static int smb_full_audit_set_quota(struct vfs_handle_struct *handle,
657 enum SMB_QUOTA_TYPE qtype, unid_t id,
662 result = SMB_VFS_NEXT_SET_QUOTA(handle, qtype, id, qt);
664 do_log(SMB_VFS_OP_SET_QUOTA, (result >= 0), handle, "");
669 static int smb_full_audit_get_shadow_copy_data(struct vfs_handle_struct *handle,
670 struct files_struct *fsp,
671 struct shadow_copy_data *shadow_copy_data,
676 result = SMB_VFS_NEXT_GET_SHADOW_COPY_DATA(handle, fsp, shadow_copy_data, labels);
678 do_log(SMB_VFS_OP_GET_SHADOW_COPY_DATA, (result >= 0), handle, "");
683 static int smb_full_audit_statvfs(struct vfs_handle_struct *handle,
685 struct vfs_statvfs_struct *statbuf)
689 result = SMB_VFS_NEXT_STATVFS(handle, path, statbuf);
691 do_log(SMB_VFS_OP_STATVFS, (result >= 0), handle, "");
696 static uint32_t smb_full_audit_fs_capabilities(struct vfs_handle_struct *handle, enum timestamp_set_resolution *p_ts_res)
700 result = SMB_VFS_NEXT_FS_CAPABILITIES(handle, p_ts_res);
702 do_log(SMB_VFS_OP_FS_CAPABILITIES, true, handle, "");
707 static DIR *smb_full_audit_opendir(vfs_handle_struct *handle,
708 const char *fname, const char *mask, uint32 attr)
712 result = SMB_VFS_NEXT_OPENDIR(handle, fname, mask, attr);
714 do_log(SMB_VFS_OP_OPENDIR, (result != NULL), handle, "%s", fname);
719 static DIR *smb_full_audit_fdopendir(vfs_handle_struct *handle,
720 files_struct *fsp, const char *mask, uint32 attr)
724 result = SMB_VFS_NEXT_FDOPENDIR(handle, fsp, mask, attr);
726 do_log(SMB_VFS_OP_FDOPENDIR, (result != NULL), handle, "%s",
727 fsp_str_do_log(fsp));
732 static struct dirent *smb_full_audit_readdir(vfs_handle_struct *handle,
733 DIR *dirp, SMB_STRUCT_STAT *sbuf)
735 struct dirent *result;
737 result = SMB_VFS_NEXT_READDIR(handle, dirp, sbuf);
739 /* This operation has no reasonable error condition
740 * (End of dir is also failure), so always succeed.
742 do_log(SMB_VFS_OP_READDIR, True, handle, "");
747 static void smb_full_audit_seekdir(vfs_handle_struct *handle,
748 DIR *dirp, long offset)
750 SMB_VFS_NEXT_SEEKDIR(handle, dirp, offset);
752 do_log(SMB_VFS_OP_SEEKDIR, True, handle, "");
755 static long smb_full_audit_telldir(vfs_handle_struct *handle,
760 result = SMB_VFS_NEXT_TELLDIR(handle, dirp);
762 do_log(SMB_VFS_OP_TELLDIR, True, handle, "");
767 static void smb_full_audit_rewinddir(vfs_handle_struct *handle,
770 SMB_VFS_NEXT_REWINDDIR(handle, dirp);
772 do_log(SMB_VFS_OP_REWINDDIR, True, handle, "");
775 static int smb_full_audit_mkdir(vfs_handle_struct *handle,
776 const char *path, mode_t mode)
780 result = SMB_VFS_NEXT_MKDIR(handle, path, mode);
782 do_log(SMB_VFS_OP_MKDIR, (result >= 0), handle, "%s", path);
787 static int smb_full_audit_rmdir(vfs_handle_struct *handle,
792 result = SMB_VFS_NEXT_RMDIR(handle, path);
794 do_log(SMB_VFS_OP_RMDIR, (result >= 0), handle, "%s", path);
799 static int smb_full_audit_closedir(vfs_handle_struct *handle,
804 result = SMB_VFS_NEXT_CLOSEDIR(handle, dirp);
806 do_log(SMB_VFS_OP_CLOSEDIR, (result >= 0), handle, "");
811 static void smb_full_audit_init_search_op(vfs_handle_struct *handle,
814 SMB_VFS_NEXT_INIT_SEARCH_OP(handle, dirp);
816 do_log(SMB_VFS_OP_INIT_SEARCH_OP, True, handle, "");
819 static int smb_full_audit_open(vfs_handle_struct *handle,
820 struct smb_filename *smb_fname,
821 files_struct *fsp, int flags, mode_t mode)
825 result = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
827 do_log(SMB_VFS_OP_OPEN, (result >= 0), handle, "%s|%s",
828 ((flags & O_WRONLY) || (flags & O_RDWR))?"w":"r",
829 smb_fname_str_do_log(smb_fname));
834 static NTSTATUS smb_full_audit_create_file(vfs_handle_struct *handle,
835 struct smb_request *req,
836 uint16_t root_dir_fid,
837 struct smb_filename *smb_fname,
838 uint32_t access_mask,
839 uint32_t share_access,
840 uint32_t create_disposition,
841 uint32_t create_options,
842 uint32_t file_attributes,
843 uint32_t oplock_request,
844 uint64_t allocation_size,
845 uint32_t private_flags,
846 struct security_descriptor *sd,
847 struct ea_list *ea_list,
848 files_struct **result_fsp,
852 const char* str_create_disposition;
854 switch (create_disposition) {
856 str_create_disposition = "supersede";
858 case FILE_OVERWRITE_IF:
859 str_create_disposition = "overwrite_if";
862 str_create_disposition = "open";
865 str_create_disposition = "overwrite";
868 str_create_disposition = "create";
871 str_create_disposition = "open_if";
874 str_create_disposition = "unknown";
877 result = SMB_VFS_NEXT_CREATE_FILE(
880 root_dir_fid, /* root_dir_fid */
881 smb_fname, /* fname */
882 access_mask, /* access_mask */
883 share_access, /* share_access */
884 create_disposition, /* create_disposition*/
885 create_options, /* create_options */
886 file_attributes, /* file_attributes */
887 oplock_request, /* oplock_request */
888 allocation_size, /* allocation_size */
891 ea_list, /* ea_list */
892 result_fsp, /* result */
895 do_log(SMB_VFS_OP_CREATE_FILE, (NT_STATUS_IS_OK(result)), handle,
896 "0x%x|%s|%s|%s", access_mask,
897 create_options & FILE_DIRECTORY_FILE ? "dir" : "file",
898 str_create_disposition, smb_fname_str_do_log(smb_fname));
903 static int smb_full_audit_close(vfs_handle_struct *handle, files_struct *fsp)
907 result = SMB_VFS_NEXT_CLOSE(handle, fsp);
909 do_log(SMB_VFS_OP_CLOSE, (result >= 0), handle, "%s",
910 fsp_str_do_log(fsp));
915 static ssize_t smb_full_audit_read(vfs_handle_struct *handle, files_struct *fsp,
916 void *data, size_t n)
920 result = SMB_VFS_NEXT_READ(handle, fsp, data, n);
922 do_log(SMB_VFS_OP_READ, (result >= 0), handle, "%s",
923 fsp_str_do_log(fsp));
928 static ssize_t smb_full_audit_pread(vfs_handle_struct *handle, files_struct *fsp,
929 void *data, size_t n, off_t offset)
933 result = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
935 do_log(SMB_VFS_OP_PREAD, (result >= 0), handle, "%s",
936 fsp_str_do_log(fsp));
941 struct smb_full_audit_pread_state {
942 vfs_handle_struct *handle;
948 static void smb_full_audit_pread_done(struct tevent_req *subreq);
950 static struct tevent_req *smb_full_audit_pread_send(
951 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
952 struct tevent_context *ev, struct files_struct *fsp,
953 void *data, size_t n, off_t offset)
955 struct tevent_req *req, *subreq;
956 struct smb_full_audit_pread_state *state;
958 req = tevent_req_create(mem_ctx, &state,
959 struct smb_full_audit_pread_state);
961 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
962 fsp_str_do_log(fsp));
965 state->handle = handle;
968 subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
970 if (tevent_req_nomem(subreq, req)) {
971 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
972 fsp_str_do_log(fsp));
973 return tevent_req_post(req, ev);
975 tevent_req_set_callback(subreq, smb_full_audit_pread_done, req);
977 do_log(SMB_VFS_OP_PREAD_SEND, true, handle, "%s", fsp_str_do_log(fsp));
981 static void smb_full_audit_pread_done(struct tevent_req *subreq)
983 struct tevent_req *req = tevent_req_callback_data(
984 subreq, struct tevent_req);
985 struct smb_full_audit_pread_state *state = tevent_req_data(
986 req, struct smb_full_audit_pread_state);
988 state->ret = SMB_VFS_PREAD_RECV(subreq, &state->err);
990 tevent_req_done(req);
993 static ssize_t smb_full_audit_pread_recv(struct tevent_req *req, int *err)
995 struct smb_full_audit_pread_state *state = tevent_req_data(
996 req, struct smb_full_audit_pread_state);
998 if (tevent_req_is_unix_error(req, err)) {
999 do_log(SMB_VFS_OP_PREAD_RECV, false, state->handle, "%s",
1000 fsp_str_do_log(state->fsp));
1004 do_log(SMB_VFS_OP_PREAD_RECV, (state->ret >= 0), state->handle, "%s",
1005 fsp_str_do_log(state->fsp));
1011 static ssize_t smb_full_audit_write(vfs_handle_struct *handle, files_struct *fsp,
1012 const void *data, size_t n)
1016 result = SMB_VFS_NEXT_WRITE(handle, fsp, data, n);
1018 do_log(SMB_VFS_OP_WRITE, (result >= 0), handle, "%s",
1019 fsp_str_do_log(fsp));
1024 static ssize_t smb_full_audit_pwrite(vfs_handle_struct *handle, files_struct *fsp,
1025 const void *data, size_t n,
1030 result = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
1032 do_log(SMB_VFS_OP_PWRITE, (result >= 0), handle, "%s",
1033 fsp_str_do_log(fsp));
1038 struct smb_full_audit_pwrite_state {
1039 vfs_handle_struct *handle;
1045 static void smb_full_audit_pwrite_done(struct tevent_req *subreq);
1047 static struct tevent_req *smb_full_audit_pwrite_send(
1048 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1049 struct tevent_context *ev, struct files_struct *fsp,
1050 const void *data, size_t n, off_t offset)
1052 struct tevent_req *req, *subreq;
1053 struct smb_full_audit_pwrite_state *state;
1055 req = tevent_req_create(mem_ctx, &state,
1056 struct smb_full_audit_pwrite_state);
1058 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1059 fsp_str_do_log(fsp));
1062 state->handle = handle;
1065 subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
1067 if (tevent_req_nomem(subreq, req)) {
1068 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1069 fsp_str_do_log(fsp));
1070 return tevent_req_post(req, ev);
1072 tevent_req_set_callback(subreq, smb_full_audit_pwrite_done, req);
1074 do_log(SMB_VFS_OP_PWRITE_SEND, true, handle, "%s",
1075 fsp_str_do_log(fsp));
1079 static void smb_full_audit_pwrite_done(struct tevent_req *subreq)
1081 struct tevent_req *req = tevent_req_callback_data(
1082 subreq, struct tevent_req);
1083 struct smb_full_audit_pwrite_state *state = tevent_req_data(
1084 req, struct smb_full_audit_pwrite_state);
1086 state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->err);
1087 TALLOC_FREE(subreq);
1088 tevent_req_done(req);
1091 static ssize_t smb_full_audit_pwrite_recv(struct tevent_req *req, int *err)
1093 struct smb_full_audit_pwrite_state *state = tevent_req_data(
1094 req, struct smb_full_audit_pwrite_state);
1096 if (tevent_req_is_unix_error(req, err)) {
1097 do_log(SMB_VFS_OP_PWRITE_RECV, false, state->handle, "%s",
1098 fsp_str_do_log(state->fsp));
1102 do_log(SMB_VFS_OP_PWRITE_RECV, (state->ret >= 0), state->handle, "%s",
1103 fsp_str_do_log(state->fsp));
1109 static off_t smb_full_audit_lseek(vfs_handle_struct *handle, files_struct *fsp,
1110 off_t offset, int whence)
1114 result = SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence);
1116 do_log(SMB_VFS_OP_LSEEK, (result != (ssize_t)-1), handle,
1117 "%s", fsp_str_do_log(fsp));
1122 static ssize_t smb_full_audit_sendfile(vfs_handle_struct *handle, int tofd,
1123 files_struct *fromfsp,
1124 const DATA_BLOB *hdr, off_t offset,
1129 result = SMB_VFS_NEXT_SENDFILE(handle, tofd, fromfsp, hdr, offset, n);
1131 do_log(SMB_VFS_OP_SENDFILE, (result >= 0), handle,
1132 "%s", fsp_str_do_log(fromfsp));
1137 static ssize_t smb_full_audit_recvfile(vfs_handle_struct *handle, int fromfd,
1138 files_struct *tofsp,
1144 result = SMB_VFS_NEXT_RECVFILE(handle, fromfd, tofsp, offset, n);
1146 do_log(SMB_VFS_OP_RECVFILE, (result >= 0), handle,
1147 "%s", fsp_str_do_log(tofsp));
1152 static int smb_full_audit_rename(vfs_handle_struct *handle,
1153 const struct smb_filename *smb_fname_src,
1154 const struct smb_filename *smb_fname_dst)
1158 result = SMB_VFS_NEXT_RENAME(handle, smb_fname_src, smb_fname_dst);
1160 do_log(SMB_VFS_OP_RENAME, (result >= 0), handle, "%s|%s",
1161 smb_fname_str_do_log(smb_fname_src),
1162 smb_fname_str_do_log(smb_fname_dst));
1167 static int smb_full_audit_fsync(vfs_handle_struct *handle, files_struct *fsp)
1171 result = SMB_VFS_NEXT_FSYNC(handle, fsp);
1173 do_log(SMB_VFS_OP_FSYNC, (result >= 0), handle, "%s",
1174 fsp_str_do_log(fsp));
1179 struct smb_full_audit_fsync_state {
1180 vfs_handle_struct *handle;
1186 static void smb_full_audit_fsync_done(struct tevent_req *subreq);
1188 static struct tevent_req *smb_full_audit_fsync_send(
1189 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1190 struct tevent_context *ev, struct files_struct *fsp)
1192 struct tevent_req *req, *subreq;
1193 struct smb_full_audit_fsync_state *state;
1195 req = tevent_req_create(mem_ctx, &state,
1196 struct smb_full_audit_fsync_state);
1198 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1199 fsp_str_do_log(fsp));
1202 state->handle = handle;
1205 subreq = SMB_VFS_NEXT_FSYNC_SEND(state, ev, handle, fsp);
1206 if (tevent_req_nomem(subreq, req)) {
1207 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1208 fsp_str_do_log(fsp));
1209 return tevent_req_post(req, ev);
1211 tevent_req_set_callback(subreq, smb_full_audit_fsync_done, req);
1213 do_log(SMB_VFS_OP_FSYNC_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1217 static void smb_full_audit_fsync_done(struct tevent_req *subreq)
1219 struct tevent_req *req = tevent_req_callback_data(
1220 subreq, struct tevent_req);
1221 struct smb_full_audit_fsync_state *state = tevent_req_data(
1222 req, struct smb_full_audit_fsync_state);
1224 state->ret = SMB_VFS_FSYNC_RECV(subreq, &state->err);
1225 TALLOC_FREE(subreq);
1226 tevent_req_done(req);
1229 static int smb_full_audit_fsync_recv(struct tevent_req *req, int *err)
1231 struct smb_full_audit_fsync_state *state = tevent_req_data(
1232 req, struct smb_full_audit_fsync_state);
1234 if (tevent_req_is_unix_error(req, err)) {
1235 do_log(SMB_VFS_OP_FSYNC_RECV, false, state->handle, "%s",
1236 fsp_str_do_log(state->fsp));
1240 do_log(SMB_VFS_OP_FSYNC_RECV, (state->ret >= 0), state->handle, "%s",
1241 fsp_str_do_log(state->fsp));
1247 static int smb_full_audit_stat(vfs_handle_struct *handle,
1248 struct smb_filename *smb_fname)
1252 result = SMB_VFS_NEXT_STAT(handle, smb_fname);
1254 do_log(SMB_VFS_OP_STAT, (result >= 0), handle, "%s",
1255 smb_fname_str_do_log(smb_fname));
1260 static int smb_full_audit_fstat(vfs_handle_struct *handle, files_struct *fsp,
1261 SMB_STRUCT_STAT *sbuf)
1265 result = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1267 do_log(SMB_VFS_OP_FSTAT, (result >= 0), handle, "%s",
1268 fsp_str_do_log(fsp));
1273 static int smb_full_audit_lstat(vfs_handle_struct *handle,
1274 struct smb_filename *smb_fname)
1278 result = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
1280 do_log(SMB_VFS_OP_LSTAT, (result >= 0), handle, "%s",
1281 smb_fname_str_do_log(smb_fname));
1286 static uint64_t smb_full_audit_get_alloc_size(vfs_handle_struct *handle,
1287 files_struct *fsp, const SMB_STRUCT_STAT *sbuf)
1291 result = SMB_VFS_NEXT_GET_ALLOC_SIZE(handle, fsp, sbuf);
1293 do_log(SMB_VFS_OP_GET_ALLOC_SIZE, (result != (uint64_t)-1), handle,
1299 static int smb_full_audit_unlink(vfs_handle_struct *handle,
1300 const struct smb_filename *smb_fname)
1304 result = SMB_VFS_NEXT_UNLINK(handle, smb_fname);
1306 do_log(SMB_VFS_OP_UNLINK, (result >= 0), handle, "%s",
1307 smb_fname_str_do_log(smb_fname));
1312 static int smb_full_audit_chmod(vfs_handle_struct *handle,
1313 const char *path, mode_t mode)
1317 result = SMB_VFS_NEXT_CHMOD(handle, path, mode);
1319 do_log(SMB_VFS_OP_CHMOD, (result >= 0), handle, "%s|%o", path, mode);
1324 static int smb_full_audit_fchmod(vfs_handle_struct *handle, files_struct *fsp,
1329 result = SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1331 do_log(SMB_VFS_OP_FCHMOD, (result >= 0), handle,
1332 "%s|%o", fsp_str_do_log(fsp), mode);
1337 static int smb_full_audit_chown(vfs_handle_struct *handle,
1338 const char *path, uid_t uid, gid_t gid)
1342 result = SMB_VFS_NEXT_CHOWN(handle, path, uid, gid);
1344 do_log(SMB_VFS_OP_CHOWN, (result >= 0), handle, "%s|%ld|%ld",
1345 path, (long int)uid, (long int)gid);
1350 static int smb_full_audit_fchown(vfs_handle_struct *handle, files_struct *fsp,
1351 uid_t uid, gid_t gid)
1355 result = SMB_VFS_NEXT_FCHOWN(handle, fsp, uid, gid);
1357 do_log(SMB_VFS_OP_FCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1358 fsp_str_do_log(fsp), (long int)uid, (long int)gid);
1363 static int smb_full_audit_lchown(vfs_handle_struct *handle,
1364 const char *path, uid_t uid, gid_t gid)
1368 result = SMB_VFS_NEXT_LCHOWN(handle, path, uid, gid);
1370 do_log(SMB_VFS_OP_LCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1371 path, (long int)uid, (long int)gid);
1376 static int smb_full_audit_chdir(vfs_handle_struct *handle,
1381 result = SMB_VFS_NEXT_CHDIR(handle, path);
1383 do_log(SMB_VFS_OP_CHDIR, (result >= 0), handle, "chdir|%s", path);
1388 static char *smb_full_audit_getwd(vfs_handle_struct *handle)
1392 result = SMB_VFS_NEXT_GETWD(handle);
1394 do_log(SMB_VFS_OP_GETWD, (result != NULL), handle, "%s",
1395 result == NULL? "" : result);
1400 static int smb_full_audit_ntimes(vfs_handle_struct *handle,
1401 const struct smb_filename *smb_fname,
1402 struct smb_file_time *ft)
1406 result = SMB_VFS_NEXT_NTIMES(handle, smb_fname, ft);
1408 do_log(SMB_VFS_OP_NTIMES, (result >= 0), handle, "%s",
1409 smb_fname_str_do_log(smb_fname));
1414 static int smb_full_audit_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
1419 result = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1421 do_log(SMB_VFS_OP_FTRUNCATE, (result >= 0), handle,
1422 "%s", fsp_str_do_log(fsp));
1427 static int smb_full_audit_fallocate(vfs_handle_struct *handle, files_struct *fsp,
1428 enum vfs_fallocate_mode mode,
1434 result = SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
1436 do_log(SMB_VFS_OP_FALLOCATE, (result >= 0), handle,
1437 "%s", fsp_str_do_log(fsp));
1442 static bool smb_full_audit_lock(vfs_handle_struct *handle, files_struct *fsp,
1443 int op, off_t offset, off_t count, int type)
1447 result = SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type);
1449 do_log(SMB_VFS_OP_LOCK, result, handle, "%s", fsp_str_do_log(fsp));
1454 static int smb_full_audit_kernel_flock(struct vfs_handle_struct *handle,
1455 struct files_struct *fsp,
1456 uint32 share_mode, uint32 access_mask)
1460 result = SMB_VFS_NEXT_KERNEL_FLOCK(handle, fsp, share_mode, access_mask);
1462 do_log(SMB_VFS_OP_KERNEL_FLOCK, (result >= 0), handle, "%s",
1463 fsp_str_do_log(fsp));
1468 static int smb_full_audit_linux_setlease(vfs_handle_struct *handle, files_struct *fsp,
1473 result = SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
1475 do_log(SMB_VFS_OP_LINUX_SETLEASE, (result >= 0), handle, "%s",
1476 fsp_str_do_log(fsp));
1481 static bool smb_full_audit_getlock(vfs_handle_struct *handle, files_struct *fsp,
1482 off_t *poffset, off_t *pcount, int *ptype, pid_t *ppid)
1486 result = SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype, ppid);
1488 do_log(SMB_VFS_OP_GETLOCK, result, handle, "%s", fsp_str_do_log(fsp));
1493 static int smb_full_audit_symlink(vfs_handle_struct *handle,
1494 const char *oldpath, const char *newpath)
1498 result = SMB_VFS_NEXT_SYMLINK(handle, oldpath, newpath);
1500 do_log(SMB_VFS_OP_SYMLINK, (result >= 0), handle,
1501 "%s|%s", oldpath, newpath);
1506 static int smb_full_audit_readlink(vfs_handle_struct *handle,
1507 const char *path, char *buf, size_t bufsiz)
1511 result = SMB_VFS_NEXT_READLINK(handle, path, buf, bufsiz);
1513 do_log(SMB_VFS_OP_READLINK, (result >= 0), handle, "%s", path);
1518 static int smb_full_audit_link(vfs_handle_struct *handle,
1519 const char *oldpath, const char *newpath)
1523 result = SMB_VFS_NEXT_LINK(handle, oldpath, newpath);
1525 do_log(SMB_VFS_OP_LINK, (result >= 0), handle,
1526 "%s|%s", oldpath, newpath);
1531 static int smb_full_audit_mknod(vfs_handle_struct *handle,
1532 const char *pathname, mode_t mode, SMB_DEV_T dev)
1536 result = SMB_VFS_NEXT_MKNOD(handle, pathname, mode, dev);
1538 do_log(SMB_VFS_OP_MKNOD, (result >= 0), handle, "%s", pathname);
1543 static char *smb_full_audit_realpath(vfs_handle_struct *handle,
1548 result = SMB_VFS_NEXT_REALPATH(handle, path);
1550 do_log(SMB_VFS_OP_REALPATH, (result != NULL), handle, "%s", path);
1555 static NTSTATUS smb_full_audit_notify_watch(struct vfs_handle_struct *handle,
1556 struct sys_notify_context *ctx,
1559 uint32_t *subdir_filter,
1560 void (*callback)(struct sys_notify_context *ctx,
1562 struct notify_event *ev),
1563 void *private_data, void *handle_p)
1567 result = SMB_VFS_NEXT_NOTIFY_WATCH(handle, ctx, path,
1568 filter, subdir_filter, callback,
1569 private_data, handle_p);
1571 do_log(SMB_VFS_OP_NOTIFY_WATCH, NT_STATUS_IS_OK(result), handle, "");
1576 static int smb_full_audit_chflags(vfs_handle_struct *handle,
1577 const char *path, unsigned int flags)
1581 result = SMB_VFS_NEXT_CHFLAGS(handle, path, flags);
1583 do_log(SMB_VFS_OP_CHFLAGS, (result != 0), handle, "%s", path);
1588 static struct file_id smb_full_audit_file_id_create(struct vfs_handle_struct *handle,
1589 const SMB_STRUCT_STAT *sbuf)
1591 struct file_id id_zero;
1592 struct file_id result;
1594 ZERO_STRUCT(id_zero);
1596 result = SMB_VFS_NEXT_FILE_ID_CREATE(handle, sbuf);
1598 do_log(SMB_VFS_OP_FILE_ID_CREATE,
1599 !file_id_equal(&id_zero, &result),
1600 handle, "%s", file_id_string_tos(&result));
1605 static NTSTATUS smb_full_audit_streaminfo(vfs_handle_struct *handle,
1606 struct files_struct *fsp,
1608 TALLOC_CTX *mem_ctx,
1609 unsigned int *pnum_streams,
1610 struct stream_struct **pstreams)
1614 result = SMB_VFS_NEXT_STREAMINFO(handle, fsp, fname, mem_ctx,
1615 pnum_streams, pstreams);
1617 do_log(SMB_VFS_OP_STREAMINFO, NT_STATUS_IS_OK(result), handle,
1623 static int smb_full_audit_get_real_filename(struct vfs_handle_struct *handle,
1626 TALLOC_CTX *mem_ctx,
1631 result = SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name, mem_ctx,
1634 do_log(SMB_VFS_OP_GET_REAL_FILENAME, (result == 0), handle,
1635 "%s/%s->%s", path, name, (result == 0) ? "" : *found_name);
1640 static const char *smb_full_audit_connectpath(vfs_handle_struct *handle,
1645 result = SMB_VFS_NEXT_CONNECTPATH(handle, fname);
1647 do_log(SMB_VFS_OP_CONNECTPATH, result != NULL, handle,
1653 static NTSTATUS smb_full_audit_brl_lock_windows(struct vfs_handle_struct *handle,
1654 struct byte_range_lock *br_lck,
1655 struct lock_struct *plock,
1660 result = SMB_VFS_NEXT_BRL_LOCK_WINDOWS(handle, br_lck, plock,
1663 do_log(SMB_VFS_OP_BRL_LOCK_WINDOWS, NT_STATUS_IS_OK(result), handle,
1664 "%s:%llu-%llu. type=%d. blocking=%d",
1665 fsp_str_do_log(brl_fsp(br_lck)),
1666 plock->start, plock->size, plock->lock_type, blocking_lock);
1671 static bool smb_full_audit_brl_unlock_windows(struct vfs_handle_struct *handle,
1672 struct messaging_context *msg_ctx,
1673 struct byte_range_lock *br_lck,
1674 const struct lock_struct *plock)
1678 result = SMB_VFS_NEXT_BRL_UNLOCK_WINDOWS(handle, msg_ctx, br_lck,
1681 do_log(SMB_VFS_OP_BRL_UNLOCK_WINDOWS, (result == 0), handle,
1682 "%s:%llu-%llu:%d", fsp_str_do_log(brl_fsp(br_lck)),
1684 plock->size, plock->lock_type);
1689 static bool smb_full_audit_brl_cancel_windows(struct vfs_handle_struct *handle,
1690 struct byte_range_lock *br_lck,
1691 struct lock_struct *plock)
1695 result = SMB_VFS_NEXT_BRL_CANCEL_WINDOWS(handle, br_lck, plock);
1697 do_log(SMB_VFS_OP_BRL_CANCEL_WINDOWS, (result == 0), handle,
1698 "%s:%llu-%llu:%d", fsp_str_do_log(brl_fsp(br_lck)),
1700 plock->size, plock->lock_type);
1705 static bool smb_full_audit_strict_lock(struct vfs_handle_struct *handle,
1706 struct files_struct *fsp,
1707 struct lock_struct *plock)
1711 result = SMB_VFS_NEXT_STRICT_LOCK(handle, fsp, plock);
1713 do_log(SMB_VFS_OP_STRICT_LOCK, result, handle,
1714 "%s:%llu-%llu:%d", fsp_str_do_log(fsp), plock->start,
1715 plock->size, plock->lock_type);
1720 static void smb_full_audit_strict_unlock(struct vfs_handle_struct *handle,
1721 struct files_struct *fsp,
1722 struct lock_struct *plock)
1724 SMB_VFS_NEXT_STRICT_UNLOCK(handle, fsp, plock);
1726 do_log(SMB_VFS_OP_STRICT_UNLOCK, true, handle,
1727 "%s:%llu-%llu:%d", fsp_str_do_log(fsp), plock->start,
1728 plock->size, plock->lock_type);
1731 static NTSTATUS smb_full_audit_translate_name(struct vfs_handle_struct *handle,
1733 enum vfs_translate_direction direction,
1734 TALLOC_CTX *mem_ctx,
1739 result = SMB_VFS_NEXT_TRANSLATE_NAME(handle, name, direction, mem_ctx,
1742 do_log(SMB_VFS_OP_TRANSLATE_NAME, NT_STATUS_IS_OK(result), handle, "");
1747 static struct tevent_req *smb_full_audit_copy_chunk_send(struct vfs_handle_struct *handle,
1748 TALLOC_CTX *mem_ctx,
1749 struct tevent_context *ev,
1750 struct files_struct *src_fsp,
1752 struct files_struct *dest_fsp,
1756 struct tevent_req *req;
1758 req = SMB_VFS_NEXT_COPY_CHUNK_SEND(handle, mem_ctx, ev, src_fsp,
1759 src_off, dest_fsp, dest_off, num);
1761 do_log(SMB_VFS_OP_COPY_CHUNK_SEND, req, handle, "");
1766 static NTSTATUS smb_full_audit_copy_chunk_recv(struct vfs_handle_struct *handle,
1767 struct tevent_req *req,
1772 result = SMB_VFS_NEXT_COPY_CHUNK_RECV(handle, req, copied);
1774 do_log(SMB_VFS_OP_COPY_CHUNK_RECV, NT_STATUS_IS_OK(result), handle, "");
1779 static NTSTATUS smb_full_audit_get_compression(vfs_handle_struct *handle,
1780 TALLOC_CTX *mem_ctx,
1781 struct files_struct *fsp,
1782 struct smb_filename *smb_fname,
1783 uint16_t *_compression_fmt)
1787 result = SMB_VFS_NEXT_GET_COMPRESSION(handle, mem_ctx, fsp, smb_fname,
1790 do_log(SMB_VFS_OP_GET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
1792 (fsp ? fsp_str_do_log(fsp) : smb_fname_str_do_log(smb_fname)));
1797 static NTSTATUS smb_full_audit_set_compression(vfs_handle_struct *handle,
1798 TALLOC_CTX *mem_ctx,
1799 struct files_struct *fsp,
1800 uint16_t compression_fmt)
1804 result = SMB_VFS_NEXT_SET_COMPRESSION(handle, mem_ctx, fsp,
1807 do_log(SMB_VFS_OP_SET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
1808 "%s", fsp_str_do_log(fsp));
1813 static NTSTATUS smb_full_audit_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
1814 uint32 security_info,
1815 TALLOC_CTX *mem_ctx,
1816 struct security_descriptor **ppdesc)
1820 result = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
1823 do_log(SMB_VFS_OP_FGET_NT_ACL, NT_STATUS_IS_OK(result), handle,
1824 "%s", fsp_str_do_log(fsp));
1829 static NTSTATUS smb_full_audit_get_nt_acl(vfs_handle_struct *handle,
1831 uint32 security_info,
1832 TALLOC_CTX *mem_ctx,
1833 struct security_descriptor **ppdesc)
1837 result = SMB_VFS_NEXT_GET_NT_ACL(handle, name, security_info,
1840 do_log(SMB_VFS_OP_GET_NT_ACL, NT_STATUS_IS_OK(result), handle,
1846 static NTSTATUS smb_full_audit_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
1847 uint32 security_info_sent,
1848 const struct security_descriptor *psd)
1852 result = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
1854 do_log(SMB_VFS_OP_FSET_NT_ACL, NT_STATUS_IS_OK(result), handle, "%s",
1855 fsp_str_do_log(fsp));
1860 static int smb_full_audit_chmod_acl(vfs_handle_struct *handle,
1861 const char *path, mode_t mode)
1865 result = SMB_VFS_NEXT_CHMOD_ACL(handle, path, mode);
1867 do_log(SMB_VFS_OP_CHMOD_ACL, (result >= 0), handle,
1868 "%s|%o", path, mode);
1873 static int smb_full_audit_fchmod_acl(vfs_handle_struct *handle, files_struct *fsp,
1878 result = SMB_VFS_NEXT_FCHMOD_ACL(handle, fsp, mode);
1880 do_log(SMB_VFS_OP_FCHMOD_ACL, (result >= 0), handle,
1881 "%s|%o", fsp_str_do_log(fsp), mode);
1886 static SMB_ACL_T smb_full_audit_sys_acl_get_file(vfs_handle_struct *handle,
1888 SMB_ACL_TYPE_T type,
1889 TALLOC_CTX *mem_ctx)
1893 result = SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, path_p, type, mem_ctx);
1895 do_log(SMB_VFS_OP_SYS_ACL_GET_FILE, (result != NULL), handle,
1901 static SMB_ACL_T smb_full_audit_sys_acl_get_fd(vfs_handle_struct *handle,
1902 files_struct *fsp, TALLOC_CTX *mem_ctx)
1906 result = SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp, mem_ctx);
1908 do_log(SMB_VFS_OP_SYS_ACL_GET_FD, (result != NULL), handle,
1909 "%s", fsp_str_do_log(fsp));
1914 static int smb_full_audit_sys_acl_blob_get_file(vfs_handle_struct *handle,
1916 TALLOC_CTX *mem_ctx,
1917 char **blob_description,
1922 result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FILE(handle, path_p, mem_ctx, blob_description, blob);
1924 do_log(SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE, (result >= 0), handle,
1930 static int smb_full_audit_sys_acl_blob_get_fd(vfs_handle_struct *handle,
1932 TALLOC_CTX *mem_ctx,
1933 char **blob_description,
1938 result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle, fsp, mem_ctx, blob_description, blob);
1940 do_log(SMB_VFS_OP_SYS_ACL_BLOB_GET_FD, (result >= 0), handle,
1941 "%s", fsp_str_do_log(fsp));
1946 static int smb_full_audit_sys_acl_set_file(vfs_handle_struct *handle,
1948 const char *name, SMB_ACL_TYPE_T acltype,
1953 result = SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, name, acltype,
1956 do_log(SMB_VFS_OP_SYS_ACL_SET_FILE, (result >= 0), handle,
1962 static int smb_full_audit_sys_acl_set_fd(vfs_handle_struct *handle, files_struct *fsp,
1967 result = SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, theacl);
1969 do_log(SMB_VFS_OP_SYS_ACL_SET_FD, (result >= 0), handle,
1970 "%s", fsp_str_do_log(fsp));
1975 static int smb_full_audit_sys_acl_delete_def_file(vfs_handle_struct *handle,
1981 result = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, path);
1983 do_log(SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE, (result >= 0), handle,
1989 static ssize_t smb_full_audit_getxattr(struct vfs_handle_struct *handle,
1991 const char *name, void *value, size_t size)
1995 result = SMB_VFS_NEXT_GETXATTR(handle, path, name, value, size);
1997 do_log(SMB_VFS_OP_GETXATTR, (result >= 0), handle,
1998 "%s|%s", path, name);
2003 static ssize_t smb_full_audit_fgetxattr(struct vfs_handle_struct *handle,
2004 struct files_struct *fsp,
2005 const char *name, void *value, size_t size)
2009 result = SMB_VFS_NEXT_FGETXATTR(handle, fsp, name, value, size);
2011 do_log(SMB_VFS_OP_FGETXATTR, (result >= 0), handle,
2012 "%s|%s", fsp_str_do_log(fsp), name);
2017 static ssize_t smb_full_audit_listxattr(struct vfs_handle_struct *handle,
2018 const char *path, char *list, size_t size)
2022 result = SMB_VFS_NEXT_LISTXATTR(handle, path, list, size);
2024 do_log(SMB_VFS_OP_LISTXATTR, (result >= 0), handle, "%s", path);
2029 static ssize_t smb_full_audit_flistxattr(struct vfs_handle_struct *handle,
2030 struct files_struct *fsp, char *list,
2035 result = SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
2037 do_log(SMB_VFS_OP_FLISTXATTR, (result >= 0), handle,
2038 "%s", fsp_str_do_log(fsp));
2043 static int smb_full_audit_removexattr(struct vfs_handle_struct *handle,
2049 result = SMB_VFS_NEXT_REMOVEXATTR(handle, path, name);
2051 do_log(SMB_VFS_OP_REMOVEXATTR, (result >= 0), handle,
2052 "%s|%s", path, name);
2057 static int smb_full_audit_fremovexattr(struct vfs_handle_struct *handle,
2058 struct files_struct *fsp,
2063 result = SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, name);
2065 do_log(SMB_VFS_OP_FREMOVEXATTR, (result >= 0), handle,
2066 "%s|%s", fsp_str_do_log(fsp), name);
2071 static int smb_full_audit_setxattr(struct vfs_handle_struct *handle,
2073 const char *name, const void *value, size_t size,
2078 result = SMB_VFS_NEXT_SETXATTR(handle, path, name, value, size,
2081 do_log(SMB_VFS_OP_SETXATTR, (result >= 0), handle,
2082 "%s|%s", path, name);
2087 static int smb_full_audit_fsetxattr(struct vfs_handle_struct *handle,
2088 struct files_struct *fsp, const char *name,
2089 const void *value, size_t size, int flags)
2093 result = SMB_VFS_NEXT_FSETXATTR(handle, fsp, name, value, size, flags);
2095 do_log(SMB_VFS_OP_FSETXATTR, (result >= 0), handle,
2096 "%s|%s", fsp_str_do_log(fsp), name);
2101 static bool smb_full_audit_aio_force(struct vfs_handle_struct *handle,
2102 struct files_struct *fsp)
2106 result = SMB_VFS_NEXT_AIO_FORCE(handle, fsp);
2107 do_log(SMB_VFS_OP_AIO_FORCE, result, handle,
2108 "%s", fsp_str_do_log(fsp));
2113 static bool smb_full_audit_is_offline(struct vfs_handle_struct *handle,
2114 const struct smb_filename *fname,
2115 SMB_STRUCT_STAT *sbuf)
2119 result = SMB_VFS_NEXT_IS_OFFLINE(handle, fname, sbuf);
2120 do_log(SMB_VFS_OP_IS_OFFLINE, result, handle, "%s",
2121 smb_fname_str_do_log(fname));
2125 static int smb_full_audit_set_offline(struct vfs_handle_struct *handle,
2126 const struct smb_filename *fname)
2130 result = SMB_VFS_NEXT_SET_OFFLINE(handle, fname);
2131 do_log(SMB_VFS_OP_SET_OFFLINE, result >= 0, handle, "%s",
2132 smb_fname_str_do_log(fname));
2136 static struct vfs_fn_pointers vfs_full_audit_fns = {
2138 /* Disk operations */
2140 .connect_fn = smb_full_audit_connect,
2141 .disconnect_fn = smb_full_audit_disconnect,
2142 .disk_free_fn = smb_full_audit_disk_free,
2143 .get_quota_fn = smb_full_audit_get_quota,
2144 .set_quota_fn = smb_full_audit_set_quota,
2145 .get_shadow_copy_data_fn = smb_full_audit_get_shadow_copy_data,
2146 .statvfs_fn = smb_full_audit_statvfs,
2147 .fs_capabilities_fn = smb_full_audit_fs_capabilities,
2148 .opendir_fn = smb_full_audit_opendir,
2149 .fdopendir_fn = smb_full_audit_fdopendir,
2150 .readdir_fn = smb_full_audit_readdir,
2151 .seekdir_fn = smb_full_audit_seekdir,
2152 .telldir_fn = smb_full_audit_telldir,
2153 .rewind_dir_fn = smb_full_audit_rewinddir,
2154 .mkdir_fn = smb_full_audit_mkdir,
2155 .rmdir_fn = smb_full_audit_rmdir,
2156 .closedir_fn = smb_full_audit_closedir,
2157 .init_search_op_fn = smb_full_audit_init_search_op,
2158 .open_fn = smb_full_audit_open,
2159 .create_file_fn = smb_full_audit_create_file,
2160 .close_fn = smb_full_audit_close,
2161 .read_fn = smb_full_audit_read,
2162 .pread_fn = smb_full_audit_pread,
2163 .pread_send_fn = smb_full_audit_pread_send,
2164 .pread_recv_fn = smb_full_audit_pread_recv,
2165 .write_fn = smb_full_audit_write,
2166 .pwrite_fn = smb_full_audit_pwrite,
2167 .pwrite_send_fn = smb_full_audit_pwrite_send,
2168 .pwrite_recv_fn = smb_full_audit_pwrite_recv,
2169 .lseek_fn = smb_full_audit_lseek,
2170 .sendfile_fn = smb_full_audit_sendfile,
2171 .recvfile_fn = smb_full_audit_recvfile,
2172 .rename_fn = smb_full_audit_rename,
2173 .fsync_fn = smb_full_audit_fsync,
2174 .fsync_send_fn = smb_full_audit_fsync_send,
2175 .fsync_recv_fn = smb_full_audit_fsync_recv,
2176 .stat_fn = smb_full_audit_stat,
2177 .fstat_fn = smb_full_audit_fstat,
2178 .lstat_fn = smb_full_audit_lstat,
2179 .get_alloc_size_fn = smb_full_audit_get_alloc_size,
2180 .unlink_fn = smb_full_audit_unlink,
2181 .chmod_fn = smb_full_audit_chmod,
2182 .fchmod_fn = smb_full_audit_fchmod,
2183 .chown_fn = smb_full_audit_chown,
2184 .fchown_fn = smb_full_audit_fchown,
2185 .lchown_fn = smb_full_audit_lchown,
2186 .chdir_fn = smb_full_audit_chdir,
2187 .getwd_fn = smb_full_audit_getwd,
2188 .ntimes_fn = smb_full_audit_ntimes,
2189 .ftruncate_fn = smb_full_audit_ftruncate,
2190 .fallocate_fn = smb_full_audit_fallocate,
2191 .lock_fn = smb_full_audit_lock,
2192 .kernel_flock_fn = smb_full_audit_kernel_flock,
2193 .linux_setlease_fn = smb_full_audit_linux_setlease,
2194 .getlock_fn = smb_full_audit_getlock,
2195 .symlink_fn = smb_full_audit_symlink,
2196 .readlink_fn = smb_full_audit_readlink,
2197 .link_fn = smb_full_audit_link,
2198 .mknod_fn = smb_full_audit_mknod,
2199 .realpath_fn = smb_full_audit_realpath,
2200 .notify_watch_fn = smb_full_audit_notify_watch,
2201 .chflags_fn = smb_full_audit_chflags,
2202 .file_id_create_fn = smb_full_audit_file_id_create,
2203 .streaminfo_fn = smb_full_audit_streaminfo,
2204 .get_real_filename_fn = smb_full_audit_get_real_filename,
2205 .connectpath_fn = smb_full_audit_connectpath,
2206 .brl_lock_windows_fn = smb_full_audit_brl_lock_windows,
2207 .brl_unlock_windows_fn = smb_full_audit_brl_unlock_windows,
2208 .brl_cancel_windows_fn = smb_full_audit_brl_cancel_windows,
2209 .strict_lock_fn = smb_full_audit_strict_lock,
2210 .strict_unlock_fn = smb_full_audit_strict_unlock,
2211 .translate_name_fn = smb_full_audit_translate_name,
2212 .copy_chunk_send_fn = smb_full_audit_copy_chunk_send,
2213 .copy_chunk_recv_fn = smb_full_audit_copy_chunk_recv,
2214 .get_compression_fn = smb_full_audit_get_compression,
2215 .set_compression_fn = smb_full_audit_set_compression,
2216 .fget_nt_acl_fn = smb_full_audit_fget_nt_acl,
2217 .get_nt_acl_fn = smb_full_audit_get_nt_acl,
2218 .fset_nt_acl_fn = smb_full_audit_fset_nt_acl,
2219 .chmod_acl_fn = smb_full_audit_chmod_acl,
2220 .fchmod_acl_fn = smb_full_audit_fchmod_acl,
2221 .sys_acl_get_file_fn = smb_full_audit_sys_acl_get_file,
2222 .sys_acl_get_fd_fn = smb_full_audit_sys_acl_get_fd,
2223 .sys_acl_blob_get_file_fn = smb_full_audit_sys_acl_blob_get_file,
2224 .sys_acl_blob_get_fd_fn = smb_full_audit_sys_acl_blob_get_fd,
2225 .sys_acl_set_file_fn = smb_full_audit_sys_acl_set_file,
2226 .sys_acl_set_fd_fn = smb_full_audit_sys_acl_set_fd,
2227 .sys_acl_delete_def_file_fn = smb_full_audit_sys_acl_delete_def_file,
2228 .getxattr_fn = smb_full_audit_getxattr,
2229 .fgetxattr_fn = smb_full_audit_fgetxattr,
2230 .listxattr_fn = smb_full_audit_listxattr,
2231 .flistxattr_fn = smb_full_audit_flistxattr,
2232 .removexattr_fn = smb_full_audit_removexattr,
2233 .fremovexattr_fn = smb_full_audit_fremovexattr,
2234 .setxattr_fn = smb_full_audit_setxattr,
2235 .fsetxattr_fn = smb_full_audit_fsetxattr,
2236 .aio_force_fn = smb_full_audit_aio_force,
2237 .is_offline_fn = smb_full_audit_is_offline,
2238 .set_offline_fn = smb_full_audit_set_offline,
2241 NTSTATUS vfs_full_audit_init(void)
2243 NTSTATUS ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION,
2244 "full_audit", &vfs_full_audit_fns);
2246 if (!NT_STATUS_IS_OK(ret))
2249 vfs_full_audit_debug_level = debug_add_class("full_audit");
2250 if (vfs_full_audit_debug_level == -1) {
2251 vfs_full_audit_debug_level = DBGC_VFS;
2252 DEBUG(0, ("vfs_full_audit: Couldn't register custom debugging "
2255 DEBUG(10, ("vfs_full_audit: Debug class number of "
2256 "'full_audit': %d\n", vfs_full_audit_debug_level));