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;
82 #define DBGC_CLASS vfs_full_audit_debug_level
84 typedef enum _vfs_op_type {
89 SMB_VFS_OP_CONNECT = 0,
90 SMB_VFS_OP_DISCONNECT,
94 SMB_VFS_OP_GET_SHADOW_COPY_DATA,
96 SMB_VFS_OP_FS_CAPABILITIES,
98 /* Directory operations */
101 SMB_VFS_OP_FDOPENDIR,
105 SMB_VFS_OP_REWINDDIR,
109 SMB_VFS_OP_INIT_SEARCH_OP,
111 /* File operations */
114 SMB_VFS_OP_CREATE_FILE,
118 SMB_VFS_OP_PREAD_SEND,
119 SMB_VFS_OP_PREAD_RECV,
122 SMB_VFS_OP_PWRITE_SEND,
123 SMB_VFS_OP_PWRITE_RECV,
129 SMB_VFS_OP_FSYNC_SEND,
130 SMB_VFS_OP_FSYNC_RECV,
134 SMB_VFS_OP_GET_ALLOC_SIZE,
144 SMB_VFS_OP_FTRUNCATE,
145 SMB_VFS_OP_FALLOCATE,
147 SMB_VFS_OP_KERNEL_FLOCK,
148 SMB_VFS_OP_LINUX_SETLEASE,
155 SMB_VFS_OP_NOTIFY_WATCH,
157 SMB_VFS_OP_FILE_ID_CREATE,
158 SMB_VFS_OP_STREAMINFO,
159 SMB_VFS_OP_GET_REAL_FILENAME,
160 SMB_VFS_OP_CONNECTPATH,
161 SMB_VFS_OP_BRL_LOCK_WINDOWS,
162 SMB_VFS_OP_BRL_UNLOCK_WINDOWS,
163 SMB_VFS_OP_BRL_CANCEL_WINDOWS,
164 SMB_VFS_OP_STRICT_LOCK,
165 SMB_VFS_OP_STRICT_UNLOCK,
166 SMB_VFS_OP_TRANSLATE_NAME,
167 SMB_VFS_OP_COPY_CHUNK_SEND,
168 SMB_VFS_OP_COPY_CHUNK_RECV,
169 SMB_VFS_OP_GET_COMPRESSION,
170 SMB_VFS_OP_SET_COMPRESSION,
172 /* NT ACL operations. */
174 SMB_VFS_OP_FGET_NT_ACL,
175 SMB_VFS_OP_GET_NT_ACL,
176 SMB_VFS_OP_FSET_NT_ACL,
178 /* POSIX ACL operations. */
180 SMB_VFS_OP_CHMOD_ACL,
181 SMB_VFS_OP_FCHMOD_ACL,
183 SMB_VFS_OP_SYS_ACL_GET_FILE,
184 SMB_VFS_OP_SYS_ACL_GET_FD,
185 SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE,
186 SMB_VFS_OP_SYS_ACL_BLOB_GET_FD,
187 SMB_VFS_OP_SYS_ACL_SET_FILE,
188 SMB_VFS_OP_SYS_ACL_SET_FD,
189 SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE,
193 SMB_VFS_OP_FGETXATTR,
194 SMB_VFS_OP_LISTXATTR,
195 SMB_VFS_OP_FLISTXATTR,
196 SMB_VFS_OP_REMOVEXATTR,
197 SMB_VFS_OP_FREMOVEXATTR,
199 SMB_VFS_OP_FSETXATTR,
202 SMB_VFS_OP_AIO_FORCE,
204 /* offline operations */
205 SMB_VFS_OP_IS_OFFLINE,
206 SMB_VFS_OP_SET_OFFLINE,
208 /* This should always be last enum value */
213 /* The following array *must* be in the same order as defined in vfs_op_type */
219 { SMB_VFS_OP_CONNECT, "connect" },
220 { SMB_VFS_OP_DISCONNECT, "disconnect" },
221 { SMB_VFS_OP_DISK_FREE, "disk_free" },
222 { SMB_VFS_OP_GET_QUOTA, "get_quota" },
223 { SMB_VFS_OP_SET_QUOTA, "set_quota" },
224 { SMB_VFS_OP_GET_SHADOW_COPY_DATA, "get_shadow_copy_data" },
225 { SMB_VFS_OP_STATVFS, "statvfs" },
226 { SMB_VFS_OP_FS_CAPABILITIES, "fs_capabilities" },
227 { SMB_VFS_OP_OPENDIR, "opendir" },
228 { SMB_VFS_OP_FDOPENDIR, "fdopendir" },
229 { SMB_VFS_OP_READDIR, "readdir" },
230 { SMB_VFS_OP_SEEKDIR, "seekdir" },
231 { SMB_VFS_OP_TELLDIR, "telldir" },
232 { SMB_VFS_OP_REWINDDIR, "rewinddir" },
233 { SMB_VFS_OP_MKDIR, "mkdir" },
234 { SMB_VFS_OP_RMDIR, "rmdir" },
235 { SMB_VFS_OP_CLOSEDIR, "closedir" },
236 { SMB_VFS_OP_INIT_SEARCH_OP, "init_search_op" },
237 { SMB_VFS_OP_OPEN, "open" },
238 { SMB_VFS_OP_CREATE_FILE, "create_file" },
239 { SMB_VFS_OP_CLOSE, "close" },
240 { SMB_VFS_OP_READ, "read" },
241 { SMB_VFS_OP_PREAD, "pread" },
242 { SMB_VFS_OP_PREAD_SEND, "pread_send" },
243 { SMB_VFS_OP_PREAD_RECV, "pread_recv" },
244 { SMB_VFS_OP_WRITE, "write" },
245 { SMB_VFS_OP_PWRITE, "pwrite" },
246 { SMB_VFS_OP_PWRITE_SEND, "pwrite_send" },
247 { SMB_VFS_OP_PWRITE_RECV, "pwrite_recv" },
248 { SMB_VFS_OP_LSEEK, "lseek" },
249 { SMB_VFS_OP_SENDFILE, "sendfile" },
250 { SMB_VFS_OP_RECVFILE, "recvfile" },
251 { SMB_VFS_OP_RENAME, "rename" },
252 { SMB_VFS_OP_FSYNC, "fsync" },
253 { SMB_VFS_OP_FSYNC_SEND, "fsync_send" },
254 { SMB_VFS_OP_FSYNC_RECV, "fsync_recv" },
255 { SMB_VFS_OP_STAT, "stat" },
256 { SMB_VFS_OP_FSTAT, "fstat" },
257 { SMB_VFS_OP_LSTAT, "lstat" },
258 { SMB_VFS_OP_GET_ALLOC_SIZE, "get_alloc_size" },
259 { SMB_VFS_OP_UNLINK, "unlink" },
260 { SMB_VFS_OP_CHMOD, "chmod" },
261 { SMB_VFS_OP_FCHMOD, "fchmod" },
262 { SMB_VFS_OP_CHOWN, "chown" },
263 { SMB_VFS_OP_FCHOWN, "fchown" },
264 { SMB_VFS_OP_LCHOWN, "lchown" },
265 { SMB_VFS_OP_CHDIR, "chdir" },
266 { SMB_VFS_OP_GETWD, "getwd" },
267 { SMB_VFS_OP_NTIMES, "ntimes" },
268 { SMB_VFS_OP_FTRUNCATE, "ftruncate" },
269 { SMB_VFS_OP_FALLOCATE,"fallocate" },
270 { SMB_VFS_OP_LOCK, "lock" },
271 { SMB_VFS_OP_KERNEL_FLOCK, "kernel_flock" },
272 { SMB_VFS_OP_LINUX_SETLEASE, "linux_setlease" },
273 { SMB_VFS_OP_GETLOCK, "getlock" },
274 { SMB_VFS_OP_SYMLINK, "symlink" },
275 { SMB_VFS_OP_READLINK, "readlink" },
276 { SMB_VFS_OP_LINK, "link" },
277 { SMB_VFS_OP_MKNOD, "mknod" },
278 { SMB_VFS_OP_REALPATH, "realpath" },
279 { SMB_VFS_OP_NOTIFY_WATCH, "notify_watch" },
280 { SMB_VFS_OP_CHFLAGS, "chflags" },
281 { SMB_VFS_OP_FILE_ID_CREATE, "file_id_create" },
282 { SMB_VFS_OP_STREAMINFO, "streaminfo" },
283 { SMB_VFS_OP_GET_REAL_FILENAME, "get_real_filename" },
284 { SMB_VFS_OP_CONNECTPATH, "connectpath" },
285 { SMB_VFS_OP_BRL_LOCK_WINDOWS, "brl_lock_windows" },
286 { SMB_VFS_OP_BRL_UNLOCK_WINDOWS, "brl_unlock_windows" },
287 { SMB_VFS_OP_BRL_CANCEL_WINDOWS, "brl_cancel_windows" },
288 { SMB_VFS_OP_STRICT_LOCK, "strict_lock" },
289 { SMB_VFS_OP_STRICT_UNLOCK, "strict_unlock" },
290 { SMB_VFS_OP_TRANSLATE_NAME, "translate_name" },
291 { SMB_VFS_OP_COPY_CHUNK_SEND, "copy_chunk_send" },
292 { SMB_VFS_OP_COPY_CHUNK_RECV, "copy_chunk_recv" },
293 { SMB_VFS_OP_GET_COMPRESSION, "get_compression" },
294 { SMB_VFS_OP_SET_COMPRESSION, "set_compression" },
295 { SMB_VFS_OP_FGET_NT_ACL, "fget_nt_acl" },
296 { SMB_VFS_OP_GET_NT_ACL, "get_nt_acl" },
297 { SMB_VFS_OP_FSET_NT_ACL, "fset_nt_acl" },
298 { SMB_VFS_OP_CHMOD_ACL, "chmod_acl" },
299 { SMB_VFS_OP_FCHMOD_ACL, "fchmod_acl" },
300 { SMB_VFS_OP_SYS_ACL_GET_FILE, "sys_acl_get_file" },
301 { SMB_VFS_OP_SYS_ACL_GET_FD, "sys_acl_get_fd" },
302 { SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE, "sys_acl_blob_get_file" },
303 { SMB_VFS_OP_SYS_ACL_BLOB_GET_FD, "sys_acl_blob_get_fd" },
304 { SMB_VFS_OP_SYS_ACL_SET_FILE, "sys_acl_set_file" },
305 { SMB_VFS_OP_SYS_ACL_SET_FD, "sys_acl_set_fd" },
306 { SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE, "sys_acl_delete_def_file" },
307 { SMB_VFS_OP_GETXATTR, "getxattr" },
308 { SMB_VFS_OP_FGETXATTR, "fgetxattr" },
309 { SMB_VFS_OP_LISTXATTR, "listxattr" },
310 { SMB_VFS_OP_FLISTXATTR, "flistxattr" },
311 { SMB_VFS_OP_REMOVEXATTR, "removexattr" },
312 { SMB_VFS_OP_FREMOVEXATTR, "fremovexattr" },
313 { SMB_VFS_OP_SETXATTR, "setxattr" },
314 { SMB_VFS_OP_FSETXATTR, "fsetxattr" },
315 { SMB_VFS_OP_AIO_FORCE, "aio_force" },
316 { SMB_VFS_OP_IS_OFFLINE, "is_offline" },
317 { SMB_VFS_OP_SET_OFFLINE, "set_offline" },
318 { SMB_VFS_OP_LAST, NULL }
321 static int audit_syslog_facility(vfs_handle_struct *handle)
323 static const struct enum_list enum_log_facilities[] = {
324 { LOG_USER, "USER" },
325 { LOG_LOCAL0, "LOCAL0" },
326 { LOG_LOCAL1, "LOCAL1" },
327 { LOG_LOCAL2, "LOCAL2" },
328 { LOG_LOCAL3, "LOCAL3" },
329 { LOG_LOCAL4, "LOCAL4" },
330 { LOG_LOCAL5, "LOCAL5" },
331 { LOG_LOCAL6, "LOCAL6" },
332 { LOG_LOCAL7, "LOCAL7" },
338 facility = lp_parm_enum(SNUM(handle->conn), "full_audit", "facility", enum_log_facilities, LOG_USER);
343 static int audit_syslog_priority(vfs_handle_struct *handle)
345 static const struct enum_list enum_log_priorities[] = {
346 { LOG_EMERG, "EMERG" },
347 { LOG_ALERT, "ALERT" },
348 { LOG_CRIT, "CRIT" },
350 { LOG_WARNING, "WARNING" },
351 { LOG_NOTICE, "NOTICE" },
352 { LOG_INFO, "INFO" },
353 { LOG_DEBUG, "DEBUG" },
359 priority = lp_parm_enum(SNUM(handle->conn), "full_audit", "priority",
360 enum_log_priorities, LOG_NOTICE);
361 if (priority == -1) {
362 priority = LOG_WARNING;
368 static char *audit_prefix(TALLOC_CTX *ctx, connection_struct *conn)
373 prefix = talloc_strdup(ctx,
374 lp_parm_const_string(SNUM(conn), "full_audit",
379 result = talloc_sub_advanced(ctx,
380 lp_servicename(talloc_tos(), SNUM(conn)),
381 conn->session_info->unix_info->unix_name,
383 conn->session_info->unix_token->gid,
384 conn->session_info->unix_info->sanitized_username,
385 conn->session_info->info->domain_name,
391 static bool log_success(struct vfs_full_audit_private_data *pd, vfs_op_type op)
393 if (pd->success_ops == NULL) {
397 return bitmap_query(pd->success_ops, op);
400 static bool log_failure(struct vfs_full_audit_private_data *pd, vfs_op_type op)
402 if (pd->failure_ops == NULL)
405 return bitmap_query(pd->failure_ops, op);
408 static struct bitmap *init_bitmap(TALLOC_CTX *mem_ctx, const char **ops)
416 bm = bitmap_talloc(mem_ctx, SMB_VFS_OP_LAST);
418 DEBUG(0, ("Could not alloc bitmap -- "
419 "defaulting to logging everything\n"));
423 for (; *ops != NULL; ops += 1) {
428 if (strequal(*ops, "all")) {
429 for (i=0; i<SMB_VFS_OP_LAST; i++) {
435 if (strequal(*ops, "none")) {
445 for (i=0; i<SMB_VFS_OP_LAST; i++) {
446 if ((vfs_op_names[i].name == NULL)
447 || (vfs_op_names[i].type != i)) {
448 smb_panic("vfs_full_audit.c: name table not "
449 "in sync with vfs_op_type enums\n");
451 if (strequal(op, vfs_op_names[i].name)) {
460 if (i == SMB_VFS_OP_LAST) {
461 DEBUG(0, ("Could not find opname %s, logging all\n",
470 static const char *audit_opname(vfs_op_type op)
472 if (op >= SMB_VFS_OP_LAST)
473 return "INVALID VFS OP";
474 return vfs_op_names[op].name;
477 static TALLOC_CTX *tmp_do_log_ctx;
479 * Get us a temporary talloc context usable just for DEBUG arguments
481 static TALLOC_CTX *do_log_ctx(void)
483 if (tmp_do_log_ctx == NULL) {
484 tmp_do_log_ctx = talloc_named_const(NULL, 0, "do_log_ctx");
486 return tmp_do_log_ctx;
489 static void do_log(vfs_op_type op, bool success, vfs_handle_struct *handle,
490 const char *format, ...)
492 struct vfs_full_audit_private_data *pd;
494 char *audit_pre = NULL;
498 SMB_VFS_HANDLE_GET_DATA(handle, pd,
499 struct vfs_full_audit_private_data,
502 if (success && (!log_success(pd, op)))
505 if (!success && (!log_failure(pd, op)))
509 fstrcpy(err_msg, "ok");
511 fstr_sprintf(err_msg, "fail (%s)", strerror(errno));
513 va_start(ap, format);
514 op_msg = talloc_vasprintf(talloc_tos(), format, ap);
521 audit_pre = audit_prefix(talloc_tos(), handle->conn);
527 * Specify the facility to interoperate with other syslog
528 * callers (smbd for example).
530 priority = pd->syslog_priority | pd->syslog_facility;
532 syslog(priority, "%s|%s|%s|%s\n",
533 audit_pre ? audit_pre : "",
534 audit_opname(op), err_msg, op_msg);
536 DEBUG(1, ("%s|%s|%s|%s\n",
537 audit_pre ? audit_pre : "",
538 audit_opname(op), err_msg, op_msg));
541 TALLOC_FREE(audit_pre);
543 TALLOC_FREE(tmp_do_log_ctx);
547 * Return a string using the do_log_ctx()
549 static const char *smb_fname_str_do_log(const struct smb_filename *smb_fname)
554 if (smb_fname == NULL) {
557 status = get_full_smb_filename(do_log_ctx(), smb_fname, &fname);
558 if (!NT_STATUS_IS_OK(status)) {
565 * Return an fsp debug string using the do_log_ctx()
567 static const char *fsp_str_do_log(const struct files_struct *fsp)
569 return smb_fname_str_do_log(fsp->fsp_name);
572 /* Implementation of vfs_ops. Pass everything on to the default
573 operation but log event first. */
575 static int smb_full_audit_connect(vfs_handle_struct *handle,
576 const char *svc, const char *user)
579 struct vfs_full_audit_private_data *pd = NULL;
581 result = SMB_VFS_NEXT_CONNECT(handle, svc, user);
586 pd = talloc_zero(handle, struct vfs_full_audit_private_data);
588 SMB_VFS_NEXT_DISCONNECT(handle);
592 pd->syslog_facility = audit_syslog_facility(handle);
593 if (pd->syslog_facility == -1) {
594 DEBUG(1, ("%s: Unknown facility %s\n", __func__,
595 lp_parm_const_string(SNUM(handle->conn),
596 "full_audit", "facility",
598 SMB_VFS_NEXT_DISCONNECT(handle);
602 pd->syslog_priority = audit_syslog_priority(handle);
604 pd->do_syslog = lp_parm_bool(SNUM(handle->conn),
605 "full_audit", "syslog", true);
609 openlog("smbd_audit", 0, pd->syslog_facility);
613 pd->success_ops = init_bitmap(
614 pd, lp_parm_string_list(SNUM(handle->conn), "full_audit",
616 pd->failure_ops = init_bitmap(
617 pd, lp_parm_string_list(SNUM(handle->conn), "full_audit",
620 /* Store the private data. */
621 SMB_VFS_HANDLE_SET_DATA(handle, pd, NULL,
622 struct vfs_full_audit_private_data, return -1);
624 do_log(SMB_VFS_OP_CONNECT, True, handle,
630 static void smb_full_audit_disconnect(vfs_handle_struct *handle)
632 SMB_VFS_NEXT_DISCONNECT(handle);
634 do_log(SMB_VFS_OP_DISCONNECT, True, handle,
635 "%s", lp_servicename(talloc_tos(), SNUM(handle->conn)));
637 /* The bitmaps will be disconnected when the private
641 static uint64_t smb_full_audit_disk_free(vfs_handle_struct *handle,
643 bool small_query, uint64_t *bsize,
644 uint64_t *dfree, uint64_t *dsize)
648 result = SMB_VFS_NEXT_DISK_FREE(handle, path, small_query, bsize,
651 /* Don't have a reasonable notion of failure here */
653 do_log(SMB_VFS_OP_DISK_FREE, True, handle, "%s", path);
658 static int smb_full_audit_get_quota(struct vfs_handle_struct *handle,
659 enum SMB_QUOTA_TYPE qtype, unid_t id,
664 result = SMB_VFS_NEXT_GET_QUOTA(handle, qtype, id, qt);
666 do_log(SMB_VFS_OP_GET_QUOTA, (result >= 0), handle, "");
672 static int smb_full_audit_set_quota(struct vfs_handle_struct *handle,
673 enum SMB_QUOTA_TYPE qtype, unid_t id,
678 result = SMB_VFS_NEXT_SET_QUOTA(handle, qtype, id, qt);
680 do_log(SMB_VFS_OP_SET_QUOTA, (result >= 0), handle, "");
685 static int smb_full_audit_get_shadow_copy_data(struct vfs_handle_struct *handle,
686 struct files_struct *fsp,
687 struct shadow_copy_data *shadow_copy_data,
692 result = SMB_VFS_NEXT_GET_SHADOW_COPY_DATA(handle, fsp, shadow_copy_data, labels);
694 do_log(SMB_VFS_OP_GET_SHADOW_COPY_DATA, (result >= 0), handle, "");
699 static int smb_full_audit_statvfs(struct vfs_handle_struct *handle,
701 struct vfs_statvfs_struct *statbuf)
705 result = SMB_VFS_NEXT_STATVFS(handle, path, statbuf);
707 do_log(SMB_VFS_OP_STATVFS, (result >= 0), handle, "");
712 static uint32_t smb_full_audit_fs_capabilities(struct vfs_handle_struct *handle, enum timestamp_set_resolution *p_ts_res)
716 result = SMB_VFS_NEXT_FS_CAPABILITIES(handle, p_ts_res);
718 do_log(SMB_VFS_OP_FS_CAPABILITIES, true, handle, "");
723 static DIR *smb_full_audit_opendir(vfs_handle_struct *handle,
724 const char *fname, const char *mask, uint32 attr)
728 result = SMB_VFS_NEXT_OPENDIR(handle, fname, mask, attr);
730 do_log(SMB_VFS_OP_OPENDIR, (result != NULL), handle, "%s", fname);
735 static DIR *smb_full_audit_fdopendir(vfs_handle_struct *handle,
736 files_struct *fsp, const char *mask, uint32 attr)
740 result = SMB_VFS_NEXT_FDOPENDIR(handle, fsp, mask, attr);
742 do_log(SMB_VFS_OP_FDOPENDIR, (result != NULL), handle, "%s",
743 fsp_str_do_log(fsp));
748 static struct dirent *smb_full_audit_readdir(vfs_handle_struct *handle,
749 DIR *dirp, SMB_STRUCT_STAT *sbuf)
751 struct dirent *result;
753 result = SMB_VFS_NEXT_READDIR(handle, dirp, sbuf);
755 /* This operation has no reasonable error condition
756 * (End of dir is also failure), so always succeed.
758 do_log(SMB_VFS_OP_READDIR, True, handle, "");
763 static void smb_full_audit_seekdir(vfs_handle_struct *handle,
764 DIR *dirp, long offset)
766 SMB_VFS_NEXT_SEEKDIR(handle, dirp, offset);
768 do_log(SMB_VFS_OP_SEEKDIR, True, handle, "");
771 static long smb_full_audit_telldir(vfs_handle_struct *handle,
776 result = SMB_VFS_NEXT_TELLDIR(handle, dirp);
778 do_log(SMB_VFS_OP_TELLDIR, True, handle, "");
783 static void smb_full_audit_rewinddir(vfs_handle_struct *handle,
786 SMB_VFS_NEXT_REWINDDIR(handle, dirp);
788 do_log(SMB_VFS_OP_REWINDDIR, True, handle, "");
791 static int smb_full_audit_mkdir(vfs_handle_struct *handle,
792 const char *path, mode_t mode)
796 result = SMB_VFS_NEXT_MKDIR(handle, path, mode);
798 do_log(SMB_VFS_OP_MKDIR, (result >= 0), handle, "%s", path);
803 static int smb_full_audit_rmdir(vfs_handle_struct *handle,
808 result = SMB_VFS_NEXT_RMDIR(handle, path);
810 do_log(SMB_VFS_OP_RMDIR, (result >= 0), handle, "%s", path);
815 static int smb_full_audit_closedir(vfs_handle_struct *handle,
820 result = SMB_VFS_NEXT_CLOSEDIR(handle, dirp);
822 do_log(SMB_VFS_OP_CLOSEDIR, (result >= 0), handle, "");
827 static void smb_full_audit_init_search_op(vfs_handle_struct *handle,
830 SMB_VFS_NEXT_INIT_SEARCH_OP(handle, dirp);
832 do_log(SMB_VFS_OP_INIT_SEARCH_OP, True, handle, "");
835 static int smb_full_audit_open(vfs_handle_struct *handle,
836 struct smb_filename *smb_fname,
837 files_struct *fsp, int flags, mode_t mode)
841 result = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
843 do_log(SMB_VFS_OP_OPEN, (result >= 0), handle, "%s|%s",
844 ((flags & O_WRONLY) || (flags & O_RDWR))?"w":"r",
845 smb_fname_str_do_log(smb_fname));
850 static NTSTATUS smb_full_audit_create_file(vfs_handle_struct *handle,
851 struct smb_request *req,
852 uint16_t root_dir_fid,
853 struct smb_filename *smb_fname,
854 uint32_t access_mask,
855 uint32_t share_access,
856 uint32_t create_disposition,
857 uint32_t create_options,
858 uint32_t file_attributes,
859 uint32_t oplock_request,
860 uint64_t allocation_size,
861 uint32_t private_flags,
862 struct security_descriptor *sd,
863 struct ea_list *ea_list,
864 files_struct **result_fsp,
868 const char* str_create_disposition;
870 switch (create_disposition) {
872 str_create_disposition = "supersede";
874 case FILE_OVERWRITE_IF:
875 str_create_disposition = "overwrite_if";
878 str_create_disposition = "open";
881 str_create_disposition = "overwrite";
884 str_create_disposition = "create";
887 str_create_disposition = "open_if";
890 str_create_disposition = "unknown";
893 result = SMB_VFS_NEXT_CREATE_FILE(
896 root_dir_fid, /* root_dir_fid */
897 smb_fname, /* fname */
898 access_mask, /* access_mask */
899 share_access, /* share_access */
900 create_disposition, /* create_disposition*/
901 create_options, /* create_options */
902 file_attributes, /* file_attributes */
903 oplock_request, /* oplock_request */
904 allocation_size, /* allocation_size */
907 ea_list, /* ea_list */
908 result_fsp, /* result */
911 do_log(SMB_VFS_OP_CREATE_FILE, (NT_STATUS_IS_OK(result)), handle,
912 "0x%x|%s|%s|%s", access_mask,
913 create_options & FILE_DIRECTORY_FILE ? "dir" : "file",
914 str_create_disposition, smb_fname_str_do_log(smb_fname));
919 static int smb_full_audit_close(vfs_handle_struct *handle, files_struct *fsp)
923 result = SMB_VFS_NEXT_CLOSE(handle, fsp);
925 do_log(SMB_VFS_OP_CLOSE, (result >= 0), handle, "%s",
926 fsp_str_do_log(fsp));
931 static ssize_t smb_full_audit_read(vfs_handle_struct *handle, files_struct *fsp,
932 void *data, size_t n)
936 result = SMB_VFS_NEXT_READ(handle, fsp, data, n);
938 do_log(SMB_VFS_OP_READ, (result >= 0), handle, "%s",
939 fsp_str_do_log(fsp));
944 static ssize_t smb_full_audit_pread(vfs_handle_struct *handle, files_struct *fsp,
945 void *data, size_t n, off_t offset)
949 result = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
951 do_log(SMB_VFS_OP_PREAD, (result >= 0), handle, "%s",
952 fsp_str_do_log(fsp));
957 struct smb_full_audit_pread_state {
958 vfs_handle_struct *handle;
964 static void smb_full_audit_pread_done(struct tevent_req *subreq);
966 static struct tevent_req *smb_full_audit_pread_send(
967 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
968 struct tevent_context *ev, struct files_struct *fsp,
969 void *data, size_t n, off_t offset)
971 struct tevent_req *req, *subreq;
972 struct smb_full_audit_pread_state *state;
974 req = tevent_req_create(mem_ctx, &state,
975 struct smb_full_audit_pread_state);
977 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
978 fsp_str_do_log(fsp));
981 state->handle = handle;
984 subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
986 if (tevent_req_nomem(subreq, req)) {
987 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
988 fsp_str_do_log(fsp));
989 return tevent_req_post(req, ev);
991 tevent_req_set_callback(subreq, smb_full_audit_pread_done, req);
993 do_log(SMB_VFS_OP_PREAD_SEND, true, handle, "%s", fsp_str_do_log(fsp));
997 static void smb_full_audit_pread_done(struct tevent_req *subreq)
999 struct tevent_req *req = tevent_req_callback_data(
1000 subreq, struct tevent_req);
1001 struct smb_full_audit_pread_state *state = tevent_req_data(
1002 req, struct smb_full_audit_pread_state);
1004 state->ret = SMB_VFS_PREAD_RECV(subreq, &state->err);
1005 TALLOC_FREE(subreq);
1006 tevent_req_done(req);
1009 static ssize_t smb_full_audit_pread_recv(struct tevent_req *req, int *err)
1011 struct smb_full_audit_pread_state *state = tevent_req_data(
1012 req, struct smb_full_audit_pread_state);
1014 if (tevent_req_is_unix_error(req, err)) {
1015 do_log(SMB_VFS_OP_PREAD_RECV, false, state->handle, "%s",
1016 fsp_str_do_log(state->fsp));
1020 do_log(SMB_VFS_OP_PREAD_RECV, (state->ret >= 0), state->handle, "%s",
1021 fsp_str_do_log(state->fsp));
1027 static ssize_t smb_full_audit_write(vfs_handle_struct *handle, files_struct *fsp,
1028 const void *data, size_t n)
1032 result = SMB_VFS_NEXT_WRITE(handle, fsp, data, n);
1034 do_log(SMB_VFS_OP_WRITE, (result >= 0), handle, "%s",
1035 fsp_str_do_log(fsp));
1040 static ssize_t smb_full_audit_pwrite(vfs_handle_struct *handle, files_struct *fsp,
1041 const void *data, size_t n,
1046 result = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
1048 do_log(SMB_VFS_OP_PWRITE, (result >= 0), handle, "%s",
1049 fsp_str_do_log(fsp));
1054 struct smb_full_audit_pwrite_state {
1055 vfs_handle_struct *handle;
1061 static void smb_full_audit_pwrite_done(struct tevent_req *subreq);
1063 static struct tevent_req *smb_full_audit_pwrite_send(
1064 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1065 struct tevent_context *ev, struct files_struct *fsp,
1066 const void *data, size_t n, off_t offset)
1068 struct tevent_req *req, *subreq;
1069 struct smb_full_audit_pwrite_state *state;
1071 req = tevent_req_create(mem_ctx, &state,
1072 struct smb_full_audit_pwrite_state);
1074 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1075 fsp_str_do_log(fsp));
1078 state->handle = handle;
1081 subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
1083 if (tevent_req_nomem(subreq, req)) {
1084 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1085 fsp_str_do_log(fsp));
1086 return tevent_req_post(req, ev);
1088 tevent_req_set_callback(subreq, smb_full_audit_pwrite_done, req);
1090 do_log(SMB_VFS_OP_PWRITE_SEND, true, handle, "%s",
1091 fsp_str_do_log(fsp));
1095 static void smb_full_audit_pwrite_done(struct tevent_req *subreq)
1097 struct tevent_req *req = tevent_req_callback_data(
1098 subreq, struct tevent_req);
1099 struct smb_full_audit_pwrite_state *state = tevent_req_data(
1100 req, struct smb_full_audit_pwrite_state);
1102 state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->err);
1103 TALLOC_FREE(subreq);
1104 tevent_req_done(req);
1107 static ssize_t smb_full_audit_pwrite_recv(struct tevent_req *req, int *err)
1109 struct smb_full_audit_pwrite_state *state = tevent_req_data(
1110 req, struct smb_full_audit_pwrite_state);
1112 if (tevent_req_is_unix_error(req, err)) {
1113 do_log(SMB_VFS_OP_PWRITE_RECV, false, state->handle, "%s",
1114 fsp_str_do_log(state->fsp));
1118 do_log(SMB_VFS_OP_PWRITE_RECV, (state->ret >= 0), state->handle, "%s",
1119 fsp_str_do_log(state->fsp));
1125 static off_t smb_full_audit_lseek(vfs_handle_struct *handle, files_struct *fsp,
1126 off_t offset, int whence)
1130 result = SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence);
1132 do_log(SMB_VFS_OP_LSEEK, (result != (ssize_t)-1), handle,
1133 "%s", fsp_str_do_log(fsp));
1138 static ssize_t smb_full_audit_sendfile(vfs_handle_struct *handle, int tofd,
1139 files_struct *fromfsp,
1140 const DATA_BLOB *hdr, off_t offset,
1145 result = SMB_VFS_NEXT_SENDFILE(handle, tofd, fromfsp, hdr, offset, n);
1147 do_log(SMB_VFS_OP_SENDFILE, (result >= 0), handle,
1148 "%s", fsp_str_do_log(fromfsp));
1153 static ssize_t smb_full_audit_recvfile(vfs_handle_struct *handle, int fromfd,
1154 files_struct *tofsp,
1160 result = SMB_VFS_NEXT_RECVFILE(handle, fromfd, tofsp, offset, n);
1162 do_log(SMB_VFS_OP_RECVFILE, (result >= 0), handle,
1163 "%s", fsp_str_do_log(tofsp));
1168 static int smb_full_audit_rename(vfs_handle_struct *handle,
1169 const struct smb_filename *smb_fname_src,
1170 const struct smb_filename *smb_fname_dst)
1174 result = SMB_VFS_NEXT_RENAME(handle, smb_fname_src, smb_fname_dst);
1176 do_log(SMB_VFS_OP_RENAME, (result >= 0), handle, "%s|%s",
1177 smb_fname_str_do_log(smb_fname_src),
1178 smb_fname_str_do_log(smb_fname_dst));
1183 static int smb_full_audit_fsync(vfs_handle_struct *handle, files_struct *fsp)
1187 result = SMB_VFS_NEXT_FSYNC(handle, fsp);
1189 do_log(SMB_VFS_OP_FSYNC, (result >= 0), handle, "%s",
1190 fsp_str_do_log(fsp));
1195 struct smb_full_audit_fsync_state {
1196 vfs_handle_struct *handle;
1202 static void smb_full_audit_fsync_done(struct tevent_req *subreq);
1204 static struct tevent_req *smb_full_audit_fsync_send(
1205 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1206 struct tevent_context *ev, struct files_struct *fsp)
1208 struct tevent_req *req, *subreq;
1209 struct smb_full_audit_fsync_state *state;
1211 req = tevent_req_create(mem_ctx, &state,
1212 struct smb_full_audit_fsync_state);
1214 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1215 fsp_str_do_log(fsp));
1218 state->handle = handle;
1221 subreq = SMB_VFS_NEXT_FSYNC_SEND(state, ev, handle, fsp);
1222 if (tevent_req_nomem(subreq, req)) {
1223 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1224 fsp_str_do_log(fsp));
1225 return tevent_req_post(req, ev);
1227 tevent_req_set_callback(subreq, smb_full_audit_fsync_done, req);
1229 do_log(SMB_VFS_OP_FSYNC_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1233 static void smb_full_audit_fsync_done(struct tevent_req *subreq)
1235 struct tevent_req *req = tevent_req_callback_data(
1236 subreq, struct tevent_req);
1237 struct smb_full_audit_fsync_state *state = tevent_req_data(
1238 req, struct smb_full_audit_fsync_state);
1240 state->ret = SMB_VFS_FSYNC_RECV(subreq, &state->err);
1241 TALLOC_FREE(subreq);
1242 tevent_req_done(req);
1245 static int smb_full_audit_fsync_recv(struct tevent_req *req, int *err)
1247 struct smb_full_audit_fsync_state *state = tevent_req_data(
1248 req, struct smb_full_audit_fsync_state);
1250 if (tevent_req_is_unix_error(req, err)) {
1251 do_log(SMB_VFS_OP_FSYNC_RECV, false, state->handle, "%s",
1252 fsp_str_do_log(state->fsp));
1256 do_log(SMB_VFS_OP_FSYNC_RECV, (state->ret >= 0), state->handle, "%s",
1257 fsp_str_do_log(state->fsp));
1263 static int smb_full_audit_stat(vfs_handle_struct *handle,
1264 struct smb_filename *smb_fname)
1268 result = SMB_VFS_NEXT_STAT(handle, smb_fname);
1270 do_log(SMB_VFS_OP_STAT, (result >= 0), handle, "%s",
1271 smb_fname_str_do_log(smb_fname));
1276 static int smb_full_audit_fstat(vfs_handle_struct *handle, files_struct *fsp,
1277 SMB_STRUCT_STAT *sbuf)
1281 result = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1283 do_log(SMB_VFS_OP_FSTAT, (result >= 0), handle, "%s",
1284 fsp_str_do_log(fsp));
1289 static int smb_full_audit_lstat(vfs_handle_struct *handle,
1290 struct smb_filename *smb_fname)
1294 result = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
1296 do_log(SMB_VFS_OP_LSTAT, (result >= 0), handle, "%s",
1297 smb_fname_str_do_log(smb_fname));
1302 static uint64_t smb_full_audit_get_alloc_size(vfs_handle_struct *handle,
1303 files_struct *fsp, const SMB_STRUCT_STAT *sbuf)
1307 result = SMB_VFS_NEXT_GET_ALLOC_SIZE(handle, fsp, sbuf);
1309 do_log(SMB_VFS_OP_GET_ALLOC_SIZE, (result != (uint64_t)-1), handle,
1315 static int smb_full_audit_unlink(vfs_handle_struct *handle,
1316 const struct smb_filename *smb_fname)
1320 result = SMB_VFS_NEXT_UNLINK(handle, smb_fname);
1322 do_log(SMB_VFS_OP_UNLINK, (result >= 0), handle, "%s",
1323 smb_fname_str_do_log(smb_fname));
1328 static int smb_full_audit_chmod(vfs_handle_struct *handle,
1329 const char *path, mode_t mode)
1333 result = SMB_VFS_NEXT_CHMOD(handle, path, mode);
1335 do_log(SMB_VFS_OP_CHMOD, (result >= 0), handle, "%s|%o", path, mode);
1340 static int smb_full_audit_fchmod(vfs_handle_struct *handle, files_struct *fsp,
1345 result = SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1347 do_log(SMB_VFS_OP_FCHMOD, (result >= 0), handle,
1348 "%s|%o", fsp_str_do_log(fsp), mode);
1353 static int smb_full_audit_chown(vfs_handle_struct *handle,
1354 const char *path, uid_t uid, gid_t gid)
1358 result = SMB_VFS_NEXT_CHOWN(handle, path, uid, gid);
1360 do_log(SMB_VFS_OP_CHOWN, (result >= 0), handle, "%s|%ld|%ld",
1361 path, (long int)uid, (long int)gid);
1366 static int smb_full_audit_fchown(vfs_handle_struct *handle, files_struct *fsp,
1367 uid_t uid, gid_t gid)
1371 result = SMB_VFS_NEXT_FCHOWN(handle, fsp, uid, gid);
1373 do_log(SMB_VFS_OP_FCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1374 fsp_str_do_log(fsp), (long int)uid, (long int)gid);
1379 static int smb_full_audit_lchown(vfs_handle_struct *handle,
1380 const char *path, uid_t uid, gid_t gid)
1384 result = SMB_VFS_NEXT_LCHOWN(handle, path, uid, gid);
1386 do_log(SMB_VFS_OP_LCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1387 path, (long int)uid, (long int)gid);
1392 static int smb_full_audit_chdir(vfs_handle_struct *handle,
1397 result = SMB_VFS_NEXT_CHDIR(handle, path);
1399 do_log(SMB_VFS_OP_CHDIR, (result >= 0), handle, "chdir|%s", path);
1404 static char *smb_full_audit_getwd(vfs_handle_struct *handle)
1408 result = SMB_VFS_NEXT_GETWD(handle);
1410 do_log(SMB_VFS_OP_GETWD, (result != NULL), handle, "%s",
1411 result == NULL? "" : result);
1416 static int smb_full_audit_ntimes(vfs_handle_struct *handle,
1417 const struct smb_filename *smb_fname,
1418 struct smb_file_time *ft)
1422 result = SMB_VFS_NEXT_NTIMES(handle, smb_fname, ft);
1424 do_log(SMB_VFS_OP_NTIMES, (result >= 0), handle, "%s",
1425 smb_fname_str_do_log(smb_fname));
1430 static int smb_full_audit_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
1435 result = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1437 do_log(SMB_VFS_OP_FTRUNCATE, (result >= 0), handle,
1438 "%s", fsp_str_do_log(fsp));
1443 static int smb_full_audit_fallocate(vfs_handle_struct *handle, files_struct *fsp,
1444 enum vfs_fallocate_mode mode,
1450 result = SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
1452 do_log(SMB_VFS_OP_FALLOCATE, (result >= 0), handle,
1453 "%s", fsp_str_do_log(fsp));
1458 static bool smb_full_audit_lock(vfs_handle_struct *handle, files_struct *fsp,
1459 int op, off_t offset, off_t count, int type)
1463 result = SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type);
1465 do_log(SMB_VFS_OP_LOCK, result, handle, "%s", fsp_str_do_log(fsp));
1470 static int smb_full_audit_kernel_flock(struct vfs_handle_struct *handle,
1471 struct files_struct *fsp,
1472 uint32 share_mode, uint32 access_mask)
1476 result = SMB_VFS_NEXT_KERNEL_FLOCK(handle, fsp, share_mode, access_mask);
1478 do_log(SMB_VFS_OP_KERNEL_FLOCK, (result >= 0), handle, "%s",
1479 fsp_str_do_log(fsp));
1484 static int smb_full_audit_linux_setlease(vfs_handle_struct *handle, files_struct *fsp,
1489 result = SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
1491 do_log(SMB_VFS_OP_LINUX_SETLEASE, (result >= 0), handle, "%s",
1492 fsp_str_do_log(fsp));
1497 static bool smb_full_audit_getlock(vfs_handle_struct *handle, files_struct *fsp,
1498 off_t *poffset, off_t *pcount, int *ptype, pid_t *ppid)
1502 result = SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype, ppid);
1504 do_log(SMB_VFS_OP_GETLOCK, result, handle, "%s", fsp_str_do_log(fsp));
1509 static int smb_full_audit_symlink(vfs_handle_struct *handle,
1510 const char *oldpath, const char *newpath)
1514 result = SMB_VFS_NEXT_SYMLINK(handle, oldpath, newpath);
1516 do_log(SMB_VFS_OP_SYMLINK, (result >= 0), handle,
1517 "%s|%s", oldpath, newpath);
1522 static int smb_full_audit_readlink(vfs_handle_struct *handle,
1523 const char *path, char *buf, size_t bufsiz)
1527 result = SMB_VFS_NEXT_READLINK(handle, path, buf, bufsiz);
1529 do_log(SMB_VFS_OP_READLINK, (result >= 0), handle, "%s", path);
1534 static int smb_full_audit_link(vfs_handle_struct *handle,
1535 const char *oldpath, const char *newpath)
1539 result = SMB_VFS_NEXT_LINK(handle, oldpath, newpath);
1541 do_log(SMB_VFS_OP_LINK, (result >= 0), handle,
1542 "%s|%s", oldpath, newpath);
1547 static int smb_full_audit_mknod(vfs_handle_struct *handle,
1548 const char *pathname, mode_t mode, SMB_DEV_T dev)
1552 result = SMB_VFS_NEXT_MKNOD(handle, pathname, mode, dev);
1554 do_log(SMB_VFS_OP_MKNOD, (result >= 0), handle, "%s", pathname);
1559 static char *smb_full_audit_realpath(vfs_handle_struct *handle,
1564 result = SMB_VFS_NEXT_REALPATH(handle, path);
1566 do_log(SMB_VFS_OP_REALPATH, (result != NULL), handle, "%s", path);
1571 static NTSTATUS smb_full_audit_notify_watch(struct vfs_handle_struct *handle,
1572 struct sys_notify_context *ctx,
1575 uint32_t *subdir_filter,
1576 void (*callback)(struct sys_notify_context *ctx,
1578 struct notify_event *ev),
1579 void *private_data, void *handle_p)
1583 result = SMB_VFS_NEXT_NOTIFY_WATCH(handle, ctx, path,
1584 filter, subdir_filter, callback,
1585 private_data, handle_p);
1587 do_log(SMB_VFS_OP_NOTIFY_WATCH, NT_STATUS_IS_OK(result), handle, "");
1592 static int smb_full_audit_chflags(vfs_handle_struct *handle,
1593 const char *path, unsigned int flags)
1597 result = SMB_VFS_NEXT_CHFLAGS(handle, path, flags);
1599 do_log(SMB_VFS_OP_CHFLAGS, (result != 0), handle, "%s", path);
1604 static struct file_id smb_full_audit_file_id_create(struct vfs_handle_struct *handle,
1605 const SMB_STRUCT_STAT *sbuf)
1607 struct file_id id_zero;
1608 struct file_id result;
1610 ZERO_STRUCT(id_zero);
1612 result = SMB_VFS_NEXT_FILE_ID_CREATE(handle, sbuf);
1614 do_log(SMB_VFS_OP_FILE_ID_CREATE,
1615 !file_id_equal(&id_zero, &result),
1616 handle, "%s", file_id_string_tos(&result));
1621 static NTSTATUS smb_full_audit_streaminfo(vfs_handle_struct *handle,
1622 struct files_struct *fsp,
1624 TALLOC_CTX *mem_ctx,
1625 unsigned int *pnum_streams,
1626 struct stream_struct **pstreams)
1630 result = SMB_VFS_NEXT_STREAMINFO(handle, fsp, fname, mem_ctx,
1631 pnum_streams, pstreams);
1633 do_log(SMB_VFS_OP_STREAMINFO, NT_STATUS_IS_OK(result), handle,
1639 static int smb_full_audit_get_real_filename(struct vfs_handle_struct *handle,
1642 TALLOC_CTX *mem_ctx,
1647 result = SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name, mem_ctx,
1650 do_log(SMB_VFS_OP_GET_REAL_FILENAME, (result == 0), handle,
1651 "%s/%s->%s", path, name, (result == 0) ? "" : *found_name);
1656 static const char *smb_full_audit_connectpath(vfs_handle_struct *handle,
1661 result = SMB_VFS_NEXT_CONNECTPATH(handle, fname);
1663 do_log(SMB_VFS_OP_CONNECTPATH, result != NULL, handle,
1669 static NTSTATUS smb_full_audit_brl_lock_windows(struct vfs_handle_struct *handle,
1670 struct byte_range_lock *br_lck,
1671 struct lock_struct *plock,
1676 result = SMB_VFS_NEXT_BRL_LOCK_WINDOWS(handle, br_lck, plock,
1679 do_log(SMB_VFS_OP_BRL_LOCK_WINDOWS, NT_STATUS_IS_OK(result), handle,
1680 "%s:%llu-%llu. type=%d. blocking=%d",
1681 fsp_str_do_log(brl_fsp(br_lck)),
1682 plock->start, plock->size, plock->lock_type, blocking_lock);
1687 static bool smb_full_audit_brl_unlock_windows(struct vfs_handle_struct *handle,
1688 struct messaging_context *msg_ctx,
1689 struct byte_range_lock *br_lck,
1690 const struct lock_struct *plock)
1694 result = SMB_VFS_NEXT_BRL_UNLOCK_WINDOWS(handle, msg_ctx, br_lck,
1697 do_log(SMB_VFS_OP_BRL_UNLOCK_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_brl_cancel_windows(struct vfs_handle_struct *handle,
1706 struct byte_range_lock *br_lck,
1707 struct lock_struct *plock)
1711 result = SMB_VFS_NEXT_BRL_CANCEL_WINDOWS(handle, br_lck, plock);
1713 do_log(SMB_VFS_OP_BRL_CANCEL_WINDOWS, (result == 0), handle,
1714 "%s:%llu-%llu:%d", fsp_str_do_log(brl_fsp(br_lck)),
1716 plock->size, plock->lock_type);
1721 static bool smb_full_audit_strict_lock(struct vfs_handle_struct *handle,
1722 struct files_struct *fsp,
1723 struct lock_struct *plock)
1727 result = SMB_VFS_NEXT_STRICT_LOCK(handle, fsp, plock);
1729 do_log(SMB_VFS_OP_STRICT_LOCK, result, handle,
1730 "%s:%llu-%llu:%d", fsp_str_do_log(fsp), plock->start,
1731 plock->size, plock->lock_type);
1736 static void smb_full_audit_strict_unlock(struct vfs_handle_struct *handle,
1737 struct files_struct *fsp,
1738 struct lock_struct *plock)
1740 SMB_VFS_NEXT_STRICT_UNLOCK(handle, fsp, plock);
1742 do_log(SMB_VFS_OP_STRICT_UNLOCK, true, handle,
1743 "%s:%llu-%llu:%d", fsp_str_do_log(fsp), plock->start,
1744 plock->size, plock->lock_type);
1747 static NTSTATUS smb_full_audit_translate_name(struct vfs_handle_struct *handle,
1749 enum vfs_translate_direction direction,
1750 TALLOC_CTX *mem_ctx,
1755 result = SMB_VFS_NEXT_TRANSLATE_NAME(handle, name, direction, mem_ctx,
1758 do_log(SMB_VFS_OP_TRANSLATE_NAME, NT_STATUS_IS_OK(result), handle, "");
1763 static struct tevent_req *smb_full_audit_copy_chunk_send(struct vfs_handle_struct *handle,
1764 TALLOC_CTX *mem_ctx,
1765 struct tevent_context *ev,
1766 struct files_struct *src_fsp,
1768 struct files_struct *dest_fsp,
1772 struct tevent_req *req;
1774 req = SMB_VFS_NEXT_COPY_CHUNK_SEND(handle, mem_ctx, ev, src_fsp,
1775 src_off, dest_fsp, dest_off, num);
1777 do_log(SMB_VFS_OP_COPY_CHUNK_SEND, req, handle, "");
1782 static NTSTATUS smb_full_audit_copy_chunk_recv(struct vfs_handle_struct *handle,
1783 struct tevent_req *req,
1788 result = SMB_VFS_NEXT_COPY_CHUNK_RECV(handle, req, copied);
1790 do_log(SMB_VFS_OP_COPY_CHUNK_RECV, NT_STATUS_IS_OK(result), handle, "");
1795 static NTSTATUS smb_full_audit_get_compression(vfs_handle_struct *handle,
1796 TALLOC_CTX *mem_ctx,
1797 struct files_struct *fsp,
1798 struct smb_filename *smb_fname,
1799 uint16_t *_compression_fmt)
1803 result = SMB_VFS_NEXT_GET_COMPRESSION(handle, mem_ctx, fsp, smb_fname,
1806 do_log(SMB_VFS_OP_GET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
1808 (fsp ? fsp_str_do_log(fsp) : smb_fname_str_do_log(smb_fname)));
1813 static NTSTATUS smb_full_audit_set_compression(vfs_handle_struct *handle,
1814 TALLOC_CTX *mem_ctx,
1815 struct files_struct *fsp,
1816 uint16_t compression_fmt)
1820 result = SMB_VFS_NEXT_SET_COMPRESSION(handle, mem_ctx, fsp,
1823 do_log(SMB_VFS_OP_SET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
1824 "%s", fsp_str_do_log(fsp));
1829 static NTSTATUS smb_full_audit_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
1830 uint32 security_info,
1831 TALLOC_CTX *mem_ctx,
1832 struct security_descriptor **ppdesc)
1836 result = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
1839 do_log(SMB_VFS_OP_FGET_NT_ACL, NT_STATUS_IS_OK(result), handle,
1840 "%s", fsp_str_do_log(fsp));
1845 static NTSTATUS smb_full_audit_get_nt_acl(vfs_handle_struct *handle,
1847 uint32 security_info,
1848 TALLOC_CTX *mem_ctx,
1849 struct security_descriptor **ppdesc)
1853 result = SMB_VFS_NEXT_GET_NT_ACL(handle, name, security_info,
1856 do_log(SMB_VFS_OP_GET_NT_ACL, NT_STATUS_IS_OK(result), handle,
1862 static NTSTATUS smb_full_audit_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
1863 uint32 security_info_sent,
1864 const struct security_descriptor *psd)
1868 result = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
1870 do_log(SMB_VFS_OP_FSET_NT_ACL, NT_STATUS_IS_OK(result), handle, "%s",
1871 fsp_str_do_log(fsp));
1876 static int smb_full_audit_chmod_acl(vfs_handle_struct *handle,
1877 const char *path, mode_t mode)
1881 result = SMB_VFS_NEXT_CHMOD_ACL(handle, path, mode);
1883 do_log(SMB_VFS_OP_CHMOD_ACL, (result >= 0), handle,
1884 "%s|%o", path, mode);
1889 static int smb_full_audit_fchmod_acl(vfs_handle_struct *handle, files_struct *fsp,
1894 result = SMB_VFS_NEXT_FCHMOD_ACL(handle, fsp, mode);
1896 do_log(SMB_VFS_OP_FCHMOD_ACL, (result >= 0), handle,
1897 "%s|%o", fsp_str_do_log(fsp), mode);
1902 static SMB_ACL_T smb_full_audit_sys_acl_get_file(vfs_handle_struct *handle,
1904 SMB_ACL_TYPE_T type,
1905 TALLOC_CTX *mem_ctx)
1909 result = SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, path_p, type, mem_ctx);
1911 do_log(SMB_VFS_OP_SYS_ACL_GET_FILE, (result != NULL), handle,
1917 static SMB_ACL_T smb_full_audit_sys_acl_get_fd(vfs_handle_struct *handle,
1918 files_struct *fsp, TALLOC_CTX *mem_ctx)
1922 result = SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp, mem_ctx);
1924 do_log(SMB_VFS_OP_SYS_ACL_GET_FD, (result != NULL), handle,
1925 "%s", fsp_str_do_log(fsp));
1930 static int smb_full_audit_sys_acl_blob_get_file(vfs_handle_struct *handle,
1932 TALLOC_CTX *mem_ctx,
1933 char **blob_description,
1938 result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FILE(handle, path_p, mem_ctx, blob_description, blob);
1940 do_log(SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE, (result >= 0), handle,
1946 static int smb_full_audit_sys_acl_blob_get_fd(vfs_handle_struct *handle,
1948 TALLOC_CTX *mem_ctx,
1949 char **blob_description,
1954 result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle, fsp, mem_ctx, blob_description, blob);
1956 do_log(SMB_VFS_OP_SYS_ACL_BLOB_GET_FD, (result >= 0), handle,
1957 "%s", fsp_str_do_log(fsp));
1962 static int smb_full_audit_sys_acl_set_file(vfs_handle_struct *handle,
1964 const char *name, SMB_ACL_TYPE_T acltype,
1969 result = SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, name, acltype,
1972 do_log(SMB_VFS_OP_SYS_ACL_SET_FILE, (result >= 0), handle,
1978 static int smb_full_audit_sys_acl_set_fd(vfs_handle_struct *handle, files_struct *fsp,
1983 result = SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, theacl);
1985 do_log(SMB_VFS_OP_SYS_ACL_SET_FD, (result >= 0), handle,
1986 "%s", fsp_str_do_log(fsp));
1991 static int smb_full_audit_sys_acl_delete_def_file(vfs_handle_struct *handle,
1997 result = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, path);
1999 do_log(SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE, (result >= 0), handle,
2005 static ssize_t smb_full_audit_getxattr(struct vfs_handle_struct *handle,
2007 const char *name, void *value, size_t size)
2011 result = SMB_VFS_NEXT_GETXATTR(handle, path, name, value, size);
2013 do_log(SMB_VFS_OP_GETXATTR, (result >= 0), handle,
2014 "%s|%s", path, name);
2019 static ssize_t smb_full_audit_fgetxattr(struct vfs_handle_struct *handle,
2020 struct files_struct *fsp,
2021 const char *name, void *value, size_t size)
2025 result = SMB_VFS_NEXT_FGETXATTR(handle, fsp, name, value, size);
2027 do_log(SMB_VFS_OP_FGETXATTR, (result >= 0), handle,
2028 "%s|%s", fsp_str_do_log(fsp), name);
2033 static ssize_t smb_full_audit_listxattr(struct vfs_handle_struct *handle,
2034 const char *path, char *list, size_t size)
2038 result = SMB_VFS_NEXT_LISTXATTR(handle, path, list, size);
2040 do_log(SMB_VFS_OP_LISTXATTR, (result >= 0), handle, "%s", path);
2045 static ssize_t smb_full_audit_flistxattr(struct vfs_handle_struct *handle,
2046 struct files_struct *fsp, char *list,
2051 result = SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
2053 do_log(SMB_VFS_OP_FLISTXATTR, (result >= 0), handle,
2054 "%s", fsp_str_do_log(fsp));
2059 static int smb_full_audit_removexattr(struct vfs_handle_struct *handle,
2065 result = SMB_VFS_NEXT_REMOVEXATTR(handle, path, name);
2067 do_log(SMB_VFS_OP_REMOVEXATTR, (result >= 0), handle,
2068 "%s|%s", path, name);
2073 static int smb_full_audit_fremovexattr(struct vfs_handle_struct *handle,
2074 struct files_struct *fsp,
2079 result = SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, name);
2081 do_log(SMB_VFS_OP_FREMOVEXATTR, (result >= 0), handle,
2082 "%s|%s", fsp_str_do_log(fsp), name);
2087 static int smb_full_audit_setxattr(struct vfs_handle_struct *handle,
2089 const char *name, const void *value, size_t size,
2094 result = SMB_VFS_NEXT_SETXATTR(handle, path, name, value, size,
2097 do_log(SMB_VFS_OP_SETXATTR, (result >= 0), handle,
2098 "%s|%s", path, name);
2103 static int smb_full_audit_fsetxattr(struct vfs_handle_struct *handle,
2104 struct files_struct *fsp, const char *name,
2105 const void *value, size_t size, int flags)
2109 result = SMB_VFS_NEXT_FSETXATTR(handle, fsp, name, value, size, flags);
2111 do_log(SMB_VFS_OP_FSETXATTR, (result >= 0), handle,
2112 "%s|%s", fsp_str_do_log(fsp), name);
2117 static bool smb_full_audit_aio_force(struct vfs_handle_struct *handle,
2118 struct files_struct *fsp)
2122 result = SMB_VFS_NEXT_AIO_FORCE(handle, fsp);
2123 do_log(SMB_VFS_OP_AIO_FORCE, result, handle,
2124 "%s", fsp_str_do_log(fsp));
2129 static bool smb_full_audit_is_offline(struct vfs_handle_struct *handle,
2130 const struct smb_filename *fname,
2131 SMB_STRUCT_STAT *sbuf)
2135 result = SMB_VFS_NEXT_IS_OFFLINE(handle, fname, sbuf);
2136 do_log(SMB_VFS_OP_IS_OFFLINE, result, handle, "%s",
2137 smb_fname_str_do_log(fname));
2141 static int smb_full_audit_set_offline(struct vfs_handle_struct *handle,
2142 const struct smb_filename *fname)
2146 result = SMB_VFS_NEXT_SET_OFFLINE(handle, fname);
2147 do_log(SMB_VFS_OP_SET_OFFLINE, result >= 0, handle, "%s",
2148 smb_fname_str_do_log(fname));
2152 static struct vfs_fn_pointers vfs_full_audit_fns = {
2154 /* Disk operations */
2156 .connect_fn = smb_full_audit_connect,
2157 .disconnect_fn = smb_full_audit_disconnect,
2158 .disk_free_fn = smb_full_audit_disk_free,
2159 .get_quota_fn = smb_full_audit_get_quota,
2160 .set_quota_fn = smb_full_audit_set_quota,
2161 .get_shadow_copy_data_fn = smb_full_audit_get_shadow_copy_data,
2162 .statvfs_fn = smb_full_audit_statvfs,
2163 .fs_capabilities_fn = smb_full_audit_fs_capabilities,
2164 .opendir_fn = smb_full_audit_opendir,
2165 .fdopendir_fn = smb_full_audit_fdopendir,
2166 .readdir_fn = smb_full_audit_readdir,
2167 .seekdir_fn = smb_full_audit_seekdir,
2168 .telldir_fn = smb_full_audit_telldir,
2169 .rewind_dir_fn = smb_full_audit_rewinddir,
2170 .mkdir_fn = smb_full_audit_mkdir,
2171 .rmdir_fn = smb_full_audit_rmdir,
2172 .closedir_fn = smb_full_audit_closedir,
2173 .init_search_op_fn = smb_full_audit_init_search_op,
2174 .open_fn = smb_full_audit_open,
2175 .create_file_fn = smb_full_audit_create_file,
2176 .close_fn = smb_full_audit_close,
2177 .read_fn = smb_full_audit_read,
2178 .pread_fn = smb_full_audit_pread,
2179 .pread_send_fn = smb_full_audit_pread_send,
2180 .pread_recv_fn = smb_full_audit_pread_recv,
2181 .write_fn = smb_full_audit_write,
2182 .pwrite_fn = smb_full_audit_pwrite,
2183 .pwrite_send_fn = smb_full_audit_pwrite_send,
2184 .pwrite_recv_fn = smb_full_audit_pwrite_recv,
2185 .lseek_fn = smb_full_audit_lseek,
2186 .sendfile_fn = smb_full_audit_sendfile,
2187 .recvfile_fn = smb_full_audit_recvfile,
2188 .rename_fn = smb_full_audit_rename,
2189 .fsync_fn = smb_full_audit_fsync,
2190 .fsync_send_fn = smb_full_audit_fsync_send,
2191 .fsync_recv_fn = smb_full_audit_fsync_recv,
2192 .stat_fn = smb_full_audit_stat,
2193 .fstat_fn = smb_full_audit_fstat,
2194 .lstat_fn = smb_full_audit_lstat,
2195 .get_alloc_size_fn = smb_full_audit_get_alloc_size,
2196 .unlink_fn = smb_full_audit_unlink,
2197 .chmod_fn = smb_full_audit_chmod,
2198 .fchmod_fn = smb_full_audit_fchmod,
2199 .chown_fn = smb_full_audit_chown,
2200 .fchown_fn = smb_full_audit_fchown,
2201 .lchown_fn = smb_full_audit_lchown,
2202 .chdir_fn = smb_full_audit_chdir,
2203 .getwd_fn = smb_full_audit_getwd,
2204 .ntimes_fn = smb_full_audit_ntimes,
2205 .ftruncate_fn = smb_full_audit_ftruncate,
2206 .fallocate_fn = smb_full_audit_fallocate,
2207 .lock_fn = smb_full_audit_lock,
2208 .kernel_flock_fn = smb_full_audit_kernel_flock,
2209 .linux_setlease_fn = smb_full_audit_linux_setlease,
2210 .getlock_fn = smb_full_audit_getlock,
2211 .symlink_fn = smb_full_audit_symlink,
2212 .readlink_fn = smb_full_audit_readlink,
2213 .link_fn = smb_full_audit_link,
2214 .mknod_fn = smb_full_audit_mknod,
2215 .realpath_fn = smb_full_audit_realpath,
2216 .notify_watch_fn = smb_full_audit_notify_watch,
2217 .chflags_fn = smb_full_audit_chflags,
2218 .file_id_create_fn = smb_full_audit_file_id_create,
2219 .streaminfo_fn = smb_full_audit_streaminfo,
2220 .get_real_filename_fn = smb_full_audit_get_real_filename,
2221 .connectpath_fn = smb_full_audit_connectpath,
2222 .brl_lock_windows_fn = smb_full_audit_brl_lock_windows,
2223 .brl_unlock_windows_fn = smb_full_audit_brl_unlock_windows,
2224 .brl_cancel_windows_fn = smb_full_audit_brl_cancel_windows,
2225 .strict_lock_fn = smb_full_audit_strict_lock,
2226 .strict_unlock_fn = smb_full_audit_strict_unlock,
2227 .translate_name_fn = smb_full_audit_translate_name,
2228 .copy_chunk_send_fn = smb_full_audit_copy_chunk_send,
2229 .copy_chunk_recv_fn = smb_full_audit_copy_chunk_recv,
2230 .get_compression_fn = smb_full_audit_get_compression,
2231 .set_compression_fn = smb_full_audit_set_compression,
2232 .fget_nt_acl_fn = smb_full_audit_fget_nt_acl,
2233 .get_nt_acl_fn = smb_full_audit_get_nt_acl,
2234 .fset_nt_acl_fn = smb_full_audit_fset_nt_acl,
2235 .chmod_acl_fn = smb_full_audit_chmod_acl,
2236 .fchmod_acl_fn = smb_full_audit_fchmod_acl,
2237 .sys_acl_get_file_fn = smb_full_audit_sys_acl_get_file,
2238 .sys_acl_get_fd_fn = smb_full_audit_sys_acl_get_fd,
2239 .sys_acl_blob_get_file_fn = smb_full_audit_sys_acl_blob_get_file,
2240 .sys_acl_blob_get_fd_fn = smb_full_audit_sys_acl_blob_get_fd,
2241 .sys_acl_set_file_fn = smb_full_audit_sys_acl_set_file,
2242 .sys_acl_set_fd_fn = smb_full_audit_sys_acl_set_fd,
2243 .sys_acl_delete_def_file_fn = smb_full_audit_sys_acl_delete_def_file,
2244 .getxattr_fn = smb_full_audit_getxattr,
2245 .fgetxattr_fn = smb_full_audit_fgetxattr,
2246 .listxattr_fn = smb_full_audit_listxattr,
2247 .flistxattr_fn = smb_full_audit_flistxattr,
2248 .removexattr_fn = smb_full_audit_removexattr,
2249 .fremovexattr_fn = smb_full_audit_fremovexattr,
2250 .setxattr_fn = smb_full_audit_setxattr,
2251 .fsetxattr_fn = smb_full_audit_fsetxattr,
2252 .aio_force_fn = smb_full_audit_aio_force,
2253 .is_offline_fn = smb_full_audit_is_offline,
2254 .set_offline_fn = smb_full_audit_set_offline,
2257 NTSTATUS vfs_full_audit_init(void)
2259 NTSTATUS ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION,
2260 "full_audit", &vfs_full_audit_fns);
2262 if (!NT_STATUS_IS_OK(ret))
2265 vfs_full_audit_debug_level = debug_add_class("full_audit");
2266 if (vfs_full_audit_debug_level == -1) {
2267 vfs_full_audit_debug_level = DBGC_VFS;
2268 DEBUG(0, ("vfs_full_audit: Couldn't register custom debugging "
2271 DEBUG(10, ("vfs_full_audit: Debug class number of "
2272 "'full_audit': %d\n", vfs_full_audit_debug_level));