smbd: validate_lock_entries does not need mem_ctx anymore
[Samba.git] / source3 / modules / vfs_full_audit.c
blob99e3fcbb45448211b108b45e9bb86355673e5249
1 /*
2 * Auditing VFS module for samba. Log selected file operations to syslog
3 * facility.
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:
30 * [tmp]
31 * path = /tmp
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.
47 * Options:
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.
60 #include "includes.h"
61 #include "system/filesys.h"
62 #include "system/syslog.h"
63 #include "smbd/smbd.h"
64 #include "../librpc/gen_ndr/ndr_netlogon.h"
65 #include "auth.h"
66 #include "ntioctl.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;
78 #undef DBGC_CLASS
79 #define DBGC_CLASS vfs_full_audit_debug_level
81 typedef enum _vfs_op_type {
82 SMB_VFS_OP_NOOP = -1,
84 /* Disk operations */
86 SMB_VFS_OP_CONNECT = 0,
87 SMB_VFS_OP_DISCONNECT,
88 SMB_VFS_OP_DISK_FREE,
89 SMB_VFS_OP_GET_QUOTA,
90 SMB_VFS_OP_SET_QUOTA,
91 SMB_VFS_OP_GET_SHADOW_COPY_DATA,
92 SMB_VFS_OP_STATVFS,
93 SMB_VFS_OP_FS_CAPABILITIES,
95 /* Directory operations */
97 SMB_VFS_OP_OPENDIR,
98 SMB_VFS_OP_FDOPENDIR,
99 SMB_VFS_OP_READDIR,
100 SMB_VFS_OP_SEEKDIR,
101 SMB_VFS_OP_TELLDIR,
102 SMB_VFS_OP_REWINDDIR,
103 SMB_VFS_OP_MKDIR,
104 SMB_VFS_OP_RMDIR,
105 SMB_VFS_OP_CLOSEDIR,
106 SMB_VFS_OP_INIT_SEARCH_OP,
108 /* File operations */
110 SMB_VFS_OP_OPEN,
111 SMB_VFS_OP_CREATE_FILE,
112 SMB_VFS_OP_CLOSE,
113 SMB_VFS_OP_READ,
114 SMB_VFS_OP_PREAD,
115 SMB_VFS_OP_PREAD_SEND,
116 SMB_VFS_OP_PREAD_RECV,
117 SMB_VFS_OP_WRITE,
118 SMB_VFS_OP_PWRITE,
119 SMB_VFS_OP_PWRITE_SEND,
120 SMB_VFS_OP_PWRITE_RECV,
121 SMB_VFS_OP_LSEEK,
122 SMB_VFS_OP_SENDFILE,
123 SMB_VFS_OP_RECVFILE,
124 SMB_VFS_OP_RENAME,
125 SMB_VFS_OP_FSYNC,
126 SMB_VFS_OP_FSYNC_SEND,
127 SMB_VFS_OP_FSYNC_RECV,
128 SMB_VFS_OP_STAT,
129 SMB_VFS_OP_FSTAT,
130 SMB_VFS_OP_LSTAT,
131 SMB_VFS_OP_GET_ALLOC_SIZE,
132 SMB_VFS_OP_UNLINK,
133 SMB_VFS_OP_CHMOD,
134 SMB_VFS_OP_FCHMOD,
135 SMB_VFS_OP_CHOWN,
136 SMB_VFS_OP_FCHOWN,
137 SMB_VFS_OP_LCHOWN,
138 SMB_VFS_OP_CHDIR,
139 SMB_VFS_OP_GETWD,
140 SMB_VFS_OP_NTIMES,
141 SMB_VFS_OP_FTRUNCATE,
142 SMB_VFS_OP_FALLOCATE,
143 SMB_VFS_OP_LOCK,
144 SMB_VFS_OP_KERNEL_FLOCK,
145 SMB_VFS_OP_LINUX_SETLEASE,
146 SMB_VFS_OP_GETLOCK,
147 SMB_VFS_OP_SYMLINK,
148 SMB_VFS_OP_READLINK,
149 SMB_VFS_OP_LINK,
150 SMB_VFS_OP_MKNOD,
151 SMB_VFS_OP_REALPATH,
152 SMB_VFS_OP_NOTIFY_WATCH,
153 SMB_VFS_OP_CHFLAGS,
154 SMB_VFS_OP_FILE_ID_CREATE,
155 SMB_VFS_OP_STREAMINFO,
156 SMB_VFS_OP_GET_REAL_FILENAME,
157 SMB_VFS_OP_CONNECTPATH,
158 SMB_VFS_OP_BRL_LOCK_WINDOWS,
159 SMB_VFS_OP_BRL_UNLOCK_WINDOWS,
160 SMB_VFS_OP_BRL_CANCEL_WINDOWS,
161 SMB_VFS_OP_STRICT_LOCK,
162 SMB_VFS_OP_STRICT_UNLOCK,
163 SMB_VFS_OP_TRANSLATE_NAME,
164 SMB_VFS_OP_COPY_CHUNK_SEND,
165 SMB_VFS_OP_COPY_CHUNK_RECV,
166 SMB_VFS_OP_GET_COMPRESSION,
167 SMB_VFS_OP_SET_COMPRESSION,
169 /* NT ACL operations. */
171 SMB_VFS_OP_FGET_NT_ACL,
172 SMB_VFS_OP_GET_NT_ACL,
173 SMB_VFS_OP_FSET_NT_ACL,
175 /* POSIX ACL operations. */
177 SMB_VFS_OP_CHMOD_ACL,
178 SMB_VFS_OP_FCHMOD_ACL,
180 SMB_VFS_OP_SYS_ACL_GET_FILE,
181 SMB_VFS_OP_SYS_ACL_GET_FD,
182 SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE,
183 SMB_VFS_OP_SYS_ACL_BLOB_GET_FD,
184 SMB_VFS_OP_SYS_ACL_SET_FILE,
185 SMB_VFS_OP_SYS_ACL_SET_FD,
186 SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE,
188 /* EA operations. */
189 SMB_VFS_OP_GETXATTR,
190 SMB_VFS_OP_FGETXATTR,
191 SMB_VFS_OP_LISTXATTR,
192 SMB_VFS_OP_FLISTXATTR,
193 SMB_VFS_OP_REMOVEXATTR,
194 SMB_VFS_OP_FREMOVEXATTR,
195 SMB_VFS_OP_SETXATTR,
196 SMB_VFS_OP_FSETXATTR,
198 /* aio operations */
199 SMB_VFS_OP_AIO_FORCE,
201 /* offline operations */
202 SMB_VFS_OP_IS_OFFLINE,
203 SMB_VFS_OP_SET_OFFLINE,
205 /* This should always be last enum value */
207 SMB_VFS_OP_LAST
208 } vfs_op_type;
210 /* The following array *must* be in the same order as defined in vfs_op_type */
212 static struct {
213 vfs_op_type type;
214 const char *name;
215 } vfs_op_names[] = {
216 { SMB_VFS_OP_CONNECT, "connect" },
217 { SMB_VFS_OP_DISCONNECT, "disconnect" },
218 { SMB_VFS_OP_DISK_FREE, "disk_free" },
219 { SMB_VFS_OP_GET_QUOTA, "get_quota" },
220 { SMB_VFS_OP_SET_QUOTA, "set_quota" },
221 { SMB_VFS_OP_GET_SHADOW_COPY_DATA, "get_shadow_copy_data" },
222 { SMB_VFS_OP_STATVFS, "statvfs" },
223 { SMB_VFS_OP_FS_CAPABILITIES, "fs_capabilities" },
224 { SMB_VFS_OP_OPENDIR, "opendir" },
225 { SMB_VFS_OP_FDOPENDIR, "fdopendir" },
226 { SMB_VFS_OP_READDIR, "readdir" },
227 { SMB_VFS_OP_SEEKDIR, "seekdir" },
228 { SMB_VFS_OP_TELLDIR, "telldir" },
229 { SMB_VFS_OP_REWINDDIR, "rewinddir" },
230 { SMB_VFS_OP_MKDIR, "mkdir" },
231 { SMB_VFS_OP_RMDIR, "rmdir" },
232 { SMB_VFS_OP_CLOSEDIR, "closedir" },
233 { SMB_VFS_OP_INIT_SEARCH_OP, "init_search_op" },
234 { SMB_VFS_OP_OPEN, "open" },
235 { SMB_VFS_OP_CREATE_FILE, "create_file" },
236 { SMB_VFS_OP_CLOSE, "close" },
237 { SMB_VFS_OP_READ, "read" },
238 { SMB_VFS_OP_PREAD, "pread" },
239 { SMB_VFS_OP_PREAD_SEND, "pread_send" },
240 { SMB_VFS_OP_PREAD_RECV, "pread_recv" },
241 { SMB_VFS_OP_WRITE, "write" },
242 { SMB_VFS_OP_PWRITE, "pwrite" },
243 { SMB_VFS_OP_PWRITE_SEND, "pwrite_send" },
244 { SMB_VFS_OP_PWRITE_RECV, "pwrite_recv" },
245 { SMB_VFS_OP_LSEEK, "lseek" },
246 { SMB_VFS_OP_SENDFILE, "sendfile" },
247 { SMB_VFS_OP_RECVFILE, "recvfile" },
248 { SMB_VFS_OP_RENAME, "rename" },
249 { SMB_VFS_OP_FSYNC, "fsync" },
250 { SMB_VFS_OP_FSYNC_SEND, "fsync_send" },
251 { SMB_VFS_OP_FSYNC_RECV, "fsync_recv" },
252 { SMB_VFS_OP_STAT, "stat" },
253 { SMB_VFS_OP_FSTAT, "fstat" },
254 { SMB_VFS_OP_LSTAT, "lstat" },
255 { SMB_VFS_OP_GET_ALLOC_SIZE, "get_alloc_size" },
256 { SMB_VFS_OP_UNLINK, "unlink" },
257 { SMB_VFS_OP_CHMOD, "chmod" },
258 { SMB_VFS_OP_FCHMOD, "fchmod" },
259 { SMB_VFS_OP_CHOWN, "chown" },
260 { SMB_VFS_OP_FCHOWN, "fchown" },
261 { SMB_VFS_OP_LCHOWN, "lchown" },
262 { SMB_VFS_OP_CHDIR, "chdir" },
263 { SMB_VFS_OP_GETWD, "getwd" },
264 { SMB_VFS_OP_NTIMES, "ntimes" },
265 { SMB_VFS_OP_FTRUNCATE, "ftruncate" },
266 { SMB_VFS_OP_FALLOCATE,"fallocate" },
267 { SMB_VFS_OP_LOCK, "lock" },
268 { SMB_VFS_OP_KERNEL_FLOCK, "kernel_flock" },
269 { SMB_VFS_OP_LINUX_SETLEASE, "linux_setlease" },
270 { SMB_VFS_OP_GETLOCK, "getlock" },
271 { SMB_VFS_OP_SYMLINK, "symlink" },
272 { SMB_VFS_OP_READLINK, "readlink" },
273 { SMB_VFS_OP_LINK, "link" },
274 { SMB_VFS_OP_MKNOD, "mknod" },
275 { SMB_VFS_OP_REALPATH, "realpath" },
276 { SMB_VFS_OP_NOTIFY_WATCH, "notify_watch" },
277 { SMB_VFS_OP_CHFLAGS, "chflags" },
278 { SMB_VFS_OP_FILE_ID_CREATE, "file_id_create" },
279 { SMB_VFS_OP_STREAMINFO, "streaminfo" },
280 { SMB_VFS_OP_GET_REAL_FILENAME, "get_real_filename" },
281 { SMB_VFS_OP_CONNECTPATH, "connectpath" },
282 { SMB_VFS_OP_BRL_LOCK_WINDOWS, "brl_lock_windows" },
283 { SMB_VFS_OP_BRL_UNLOCK_WINDOWS, "brl_unlock_windows" },
284 { SMB_VFS_OP_BRL_CANCEL_WINDOWS, "brl_cancel_windows" },
285 { SMB_VFS_OP_STRICT_LOCK, "strict_lock" },
286 { SMB_VFS_OP_STRICT_UNLOCK, "strict_unlock" },
287 { SMB_VFS_OP_TRANSLATE_NAME, "translate_name" },
288 { SMB_VFS_OP_COPY_CHUNK_SEND, "copy_chunk_send" },
289 { SMB_VFS_OP_COPY_CHUNK_RECV, "copy_chunk_recv" },
290 { SMB_VFS_OP_GET_COMPRESSION, "get_compression" },
291 { SMB_VFS_OP_SET_COMPRESSION, "set_compression" },
292 { SMB_VFS_OP_FGET_NT_ACL, "fget_nt_acl" },
293 { SMB_VFS_OP_GET_NT_ACL, "get_nt_acl" },
294 { SMB_VFS_OP_FSET_NT_ACL, "fset_nt_acl" },
295 { SMB_VFS_OP_CHMOD_ACL, "chmod_acl" },
296 { SMB_VFS_OP_FCHMOD_ACL, "fchmod_acl" },
297 { SMB_VFS_OP_SYS_ACL_GET_FILE, "sys_acl_get_file" },
298 { SMB_VFS_OP_SYS_ACL_GET_FD, "sys_acl_get_fd" },
299 { SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE, "sys_acl_blob_get_file" },
300 { SMB_VFS_OP_SYS_ACL_BLOB_GET_FD, "sys_acl_blob_get_fd" },
301 { SMB_VFS_OP_SYS_ACL_SET_FILE, "sys_acl_set_file" },
302 { SMB_VFS_OP_SYS_ACL_SET_FD, "sys_acl_set_fd" },
303 { SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE, "sys_acl_delete_def_file" },
304 { SMB_VFS_OP_GETXATTR, "getxattr" },
305 { SMB_VFS_OP_FGETXATTR, "fgetxattr" },
306 { SMB_VFS_OP_LISTXATTR, "listxattr" },
307 { SMB_VFS_OP_FLISTXATTR, "flistxattr" },
308 { SMB_VFS_OP_REMOVEXATTR, "removexattr" },
309 { SMB_VFS_OP_FREMOVEXATTR, "fremovexattr" },
310 { SMB_VFS_OP_SETXATTR, "setxattr" },
311 { SMB_VFS_OP_FSETXATTR, "fsetxattr" },
312 { SMB_VFS_OP_AIO_FORCE, "aio_force" },
313 { SMB_VFS_OP_IS_OFFLINE, "is_offline" },
314 { SMB_VFS_OP_SET_OFFLINE, "set_offline" },
315 { SMB_VFS_OP_LAST, NULL }
318 static int audit_syslog_facility(vfs_handle_struct *handle)
320 static const struct enum_list enum_log_facilities[] = {
321 { LOG_USER, "USER" },
322 { LOG_LOCAL0, "LOCAL0" },
323 { LOG_LOCAL1, "LOCAL1" },
324 { LOG_LOCAL2, "LOCAL2" },
325 { LOG_LOCAL3, "LOCAL3" },
326 { LOG_LOCAL4, "LOCAL4" },
327 { LOG_LOCAL5, "LOCAL5" },
328 { LOG_LOCAL6, "LOCAL6" },
329 { LOG_LOCAL7, "LOCAL7" },
330 { -1, NULL}
333 int facility;
335 facility = lp_parm_enum(SNUM(handle->conn), "full_audit", "facility", enum_log_facilities, LOG_USER);
337 return facility;
340 static int audit_syslog_priority(vfs_handle_struct *handle)
342 static const struct enum_list enum_log_priorities[] = {
343 { LOG_EMERG, "EMERG" },
344 { LOG_ALERT, "ALERT" },
345 { LOG_CRIT, "CRIT" },
346 { LOG_ERR, "ERR" },
347 { LOG_WARNING, "WARNING" },
348 { LOG_NOTICE, "NOTICE" },
349 { LOG_INFO, "INFO" },
350 { LOG_DEBUG, "DEBUG" },
351 { -1, NULL}
354 int priority;
356 priority = lp_parm_enum(SNUM(handle->conn), "full_audit", "priority",
357 enum_log_priorities, LOG_NOTICE);
358 if (priority == -1) {
359 priority = LOG_WARNING;
362 return priority;
365 static char *audit_prefix(TALLOC_CTX *ctx, connection_struct *conn)
367 char *prefix = NULL;
368 char *result;
370 prefix = talloc_strdup(ctx,
371 lp_parm_const_string(SNUM(conn), "full_audit",
372 "prefix", "%u|%I"));
373 if (!prefix) {
374 return NULL;
376 result = talloc_sub_advanced(ctx,
377 lp_servicename(talloc_tos(), SNUM(conn)),
378 conn->session_info->unix_info->unix_name,
379 conn->connectpath,
380 conn->session_info->unix_token->gid,
381 conn->session_info->unix_info->sanitized_username,
382 conn->session_info->info->domain_name,
383 prefix);
384 TALLOC_FREE(prefix);
385 return result;
388 static bool log_success(vfs_handle_struct *handle, vfs_op_type op)
390 struct vfs_full_audit_private_data *pd = NULL;
392 SMB_VFS_HANDLE_GET_DATA(handle, pd,
393 struct vfs_full_audit_private_data,
394 return True);
396 if (pd->success_ops == NULL) {
397 return True;
400 return bitmap_query(pd->success_ops, op);
403 static bool log_failure(vfs_handle_struct *handle, vfs_op_type op)
405 struct vfs_full_audit_private_data *pd = NULL;
407 SMB_VFS_HANDLE_GET_DATA(handle, pd,
408 struct vfs_full_audit_private_data,
409 return True);
411 if (pd->failure_ops == NULL)
412 return True;
414 return bitmap_query(pd->failure_ops, op);
417 static struct bitmap *init_bitmap(TALLOC_CTX *mem_ctx, const char **ops)
419 struct bitmap *bm;
421 if (ops == NULL) {
422 return NULL;
425 bm = bitmap_talloc(mem_ctx, SMB_VFS_OP_LAST);
426 if (bm == NULL) {
427 DEBUG(0, ("Could not alloc bitmap -- "
428 "defaulting to logging everything\n"));
429 return NULL;
432 for (; *ops != NULL; ops += 1) {
433 int i;
434 bool neg = false;
435 const char *op;
437 if (strequal(*ops, "all")) {
438 for (i=0; i<SMB_VFS_OP_LAST; i++) {
439 bitmap_set(bm, i);
441 continue;
444 if (strequal(*ops, "none")) {
445 break;
448 op = ops[0];
449 if (op[0] == '!') {
450 neg = true;
451 op += 1;
454 for (i=0; i<SMB_VFS_OP_LAST; i++) {
455 if ((vfs_op_names[i].name == NULL)
456 || (vfs_op_names[i].type != i)) {
457 smb_panic("vfs_full_audit.c: name table not "
458 "in sync with vfs_op_type enums\n");
460 if (strequal(op, vfs_op_names[i].name)) {
461 if (neg) {
462 bitmap_clear(bm, i);
463 } else {
464 bitmap_set(bm, i);
466 break;
469 if (i == SMB_VFS_OP_LAST) {
470 DEBUG(0, ("Could not find opname %s, logging all\n",
471 *ops));
472 TALLOC_FREE(bm);
473 return NULL;
476 return bm;
479 static const char *audit_opname(vfs_op_type op)
481 if (op >= SMB_VFS_OP_LAST)
482 return "INVALID VFS OP";
483 return vfs_op_names[op].name;
486 static TALLOC_CTX *tmp_do_log_ctx;
488 * Get us a temporary talloc context usable just for DEBUG arguments
490 static TALLOC_CTX *do_log_ctx(void)
492 if (tmp_do_log_ctx == NULL) {
493 tmp_do_log_ctx = talloc_named_const(NULL, 0, "do_log_ctx");
495 return tmp_do_log_ctx;
498 static void do_log(vfs_op_type op, bool success, vfs_handle_struct *handle,
499 const char *format, ...)
501 fstring err_msg;
502 char *audit_pre = NULL;
503 va_list ap;
504 char *op_msg = NULL;
505 int priority;
507 if (success && (!log_success(handle, op)))
508 goto out;
510 if (!success && (!log_failure(handle, op)))
511 goto out;
513 if (success)
514 fstrcpy(err_msg, "ok");
515 else
516 fstr_sprintf(err_msg, "fail (%s)", strerror(errno));
518 va_start(ap, format);
519 op_msg = talloc_vasprintf(talloc_tos(), format, ap);
520 va_end(ap);
522 if (!op_msg) {
523 goto out;
527 * Specify the facility to interoperate with other syslog callers
528 * (smbd for example).
530 priority = audit_syslog_priority(handle) |
531 audit_syslog_facility(handle);
533 audit_pre = audit_prefix(talloc_tos(), handle->conn);
534 syslog(priority, "%s|%s|%s|%s\n",
535 audit_pre ? audit_pre : "",
536 audit_opname(op), err_msg, op_msg);
538 out:
539 TALLOC_FREE(audit_pre);
540 TALLOC_FREE(op_msg);
541 TALLOC_FREE(tmp_do_log_ctx);
545 * Return a string using the do_log_ctx()
547 static const char *smb_fname_str_do_log(const struct smb_filename *smb_fname)
549 char *fname = NULL;
550 NTSTATUS status;
552 if (smb_fname == NULL) {
553 return "";
555 status = get_full_smb_filename(do_log_ctx(), smb_fname, &fname);
556 if (!NT_STATUS_IS_OK(status)) {
557 return "";
559 return fname;
563 * Return an fsp debug string using the do_log_ctx()
565 static const char *fsp_str_do_log(const struct files_struct *fsp)
567 return smb_fname_str_do_log(fsp->fsp_name);
570 /* Implementation of vfs_ops. Pass everything on to the default
571 operation but log event first. */
573 static int smb_full_audit_connect(vfs_handle_struct *handle,
574 const char *svc, const char *user)
576 int result;
577 struct vfs_full_audit_private_data *pd = NULL;
579 result = SMB_VFS_NEXT_CONNECT(handle, svc, user);
580 if (result < 0) {
581 return result;
584 pd = talloc_zero(handle, struct vfs_full_audit_private_data);
585 if (!pd) {
586 SMB_VFS_NEXT_DISCONNECT(handle);
587 return -1;
590 #ifdef WITH_SYSLOG
591 openlog("smbd_audit", 0, audit_syslog_facility(handle));
592 #endif
594 pd->success_ops = init_bitmap(
595 pd, lp_parm_string_list(SNUM(handle->conn), "full_audit",
596 "success", NULL));
597 pd->failure_ops = init_bitmap(
598 pd, lp_parm_string_list(SNUM(handle->conn), "full_audit",
599 "failure", NULL));
601 /* Store the private data. */
602 SMB_VFS_HANDLE_SET_DATA(handle, pd, NULL,
603 struct vfs_full_audit_private_data, return -1);
605 do_log(SMB_VFS_OP_CONNECT, True, handle,
606 "%s", svc);
608 return 0;
611 static void smb_full_audit_disconnect(vfs_handle_struct *handle)
613 SMB_VFS_NEXT_DISCONNECT(handle);
615 do_log(SMB_VFS_OP_DISCONNECT, True, handle,
616 "%s", lp_servicename(talloc_tos(), SNUM(handle->conn)));
618 /* The bitmaps will be disconnected when the private
619 data is deleted. */
622 static uint64_t smb_full_audit_disk_free(vfs_handle_struct *handle,
623 const char *path,
624 bool small_query, uint64_t *bsize,
625 uint64_t *dfree, uint64_t *dsize)
627 uint64_t result;
629 result = SMB_VFS_NEXT_DISK_FREE(handle, path, small_query, bsize,
630 dfree, dsize);
632 /* Don't have a reasonable notion of failure here */
634 do_log(SMB_VFS_OP_DISK_FREE, True, handle, "%s", path);
636 return result;
639 static int smb_full_audit_get_quota(struct vfs_handle_struct *handle,
640 enum SMB_QUOTA_TYPE qtype, unid_t id,
641 SMB_DISK_QUOTA *qt)
643 int result;
645 result = SMB_VFS_NEXT_GET_QUOTA(handle, qtype, id, qt);
647 do_log(SMB_VFS_OP_GET_QUOTA, (result >= 0), handle, "");
649 return result;
653 static int smb_full_audit_set_quota(struct vfs_handle_struct *handle,
654 enum SMB_QUOTA_TYPE qtype, unid_t id,
655 SMB_DISK_QUOTA *qt)
657 int result;
659 result = SMB_VFS_NEXT_SET_QUOTA(handle, qtype, id, qt);
661 do_log(SMB_VFS_OP_SET_QUOTA, (result >= 0), handle, "");
663 return result;
666 static int smb_full_audit_get_shadow_copy_data(struct vfs_handle_struct *handle,
667 struct files_struct *fsp,
668 struct shadow_copy_data *shadow_copy_data,
669 bool labels)
671 int result;
673 result = SMB_VFS_NEXT_GET_SHADOW_COPY_DATA(handle, fsp, shadow_copy_data, labels);
675 do_log(SMB_VFS_OP_GET_SHADOW_COPY_DATA, (result >= 0), handle, "");
677 return result;
680 static int smb_full_audit_statvfs(struct vfs_handle_struct *handle,
681 const char *path,
682 struct vfs_statvfs_struct *statbuf)
684 int result;
686 result = SMB_VFS_NEXT_STATVFS(handle, path, statbuf);
688 do_log(SMB_VFS_OP_STATVFS, (result >= 0), handle, "");
690 return result;
693 static uint32_t smb_full_audit_fs_capabilities(struct vfs_handle_struct *handle, enum timestamp_set_resolution *p_ts_res)
695 int result;
697 result = SMB_VFS_NEXT_FS_CAPABILITIES(handle, p_ts_res);
699 do_log(SMB_VFS_OP_FS_CAPABILITIES, true, handle, "");
701 return result;
704 static DIR *smb_full_audit_opendir(vfs_handle_struct *handle,
705 const char *fname, const char *mask, uint32 attr)
707 DIR *result;
709 result = SMB_VFS_NEXT_OPENDIR(handle, fname, mask, attr);
711 do_log(SMB_VFS_OP_OPENDIR, (result != NULL), handle, "%s", fname);
713 return result;
716 static DIR *smb_full_audit_fdopendir(vfs_handle_struct *handle,
717 files_struct *fsp, const char *mask, uint32 attr)
719 DIR *result;
721 result = SMB_VFS_NEXT_FDOPENDIR(handle, fsp, mask, attr);
723 do_log(SMB_VFS_OP_FDOPENDIR, (result != NULL), handle, "%s",
724 fsp_str_do_log(fsp));
726 return result;
729 static struct dirent *smb_full_audit_readdir(vfs_handle_struct *handle,
730 DIR *dirp, SMB_STRUCT_STAT *sbuf)
732 struct dirent *result;
734 result = SMB_VFS_NEXT_READDIR(handle, dirp, sbuf);
736 /* This operation has no reasonable error condition
737 * (End of dir is also failure), so always succeed.
739 do_log(SMB_VFS_OP_READDIR, True, handle, "");
741 return result;
744 static void smb_full_audit_seekdir(vfs_handle_struct *handle,
745 DIR *dirp, long offset)
747 SMB_VFS_NEXT_SEEKDIR(handle, dirp, offset);
749 do_log(SMB_VFS_OP_SEEKDIR, True, handle, "");
752 static long smb_full_audit_telldir(vfs_handle_struct *handle,
753 DIR *dirp)
755 long result;
757 result = SMB_VFS_NEXT_TELLDIR(handle, dirp);
759 do_log(SMB_VFS_OP_TELLDIR, True, handle, "");
761 return result;
764 static void smb_full_audit_rewinddir(vfs_handle_struct *handle,
765 DIR *dirp)
767 SMB_VFS_NEXT_REWINDDIR(handle, dirp);
769 do_log(SMB_VFS_OP_REWINDDIR, True, handle, "");
772 static int smb_full_audit_mkdir(vfs_handle_struct *handle,
773 const char *path, mode_t mode)
775 int result;
777 result = SMB_VFS_NEXT_MKDIR(handle, path, mode);
779 do_log(SMB_VFS_OP_MKDIR, (result >= 0), handle, "%s", path);
781 return result;
784 static int smb_full_audit_rmdir(vfs_handle_struct *handle,
785 const char *path)
787 int result;
789 result = SMB_VFS_NEXT_RMDIR(handle, path);
791 do_log(SMB_VFS_OP_RMDIR, (result >= 0), handle, "%s", path);
793 return result;
796 static int smb_full_audit_closedir(vfs_handle_struct *handle,
797 DIR *dirp)
799 int result;
801 result = SMB_VFS_NEXT_CLOSEDIR(handle, dirp);
803 do_log(SMB_VFS_OP_CLOSEDIR, (result >= 0), handle, "");
805 return result;
808 static void smb_full_audit_init_search_op(vfs_handle_struct *handle,
809 DIR *dirp)
811 SMB_VFS_NEXT_INIT_SEARCH_OP(handle, dirp);
813 do_log(SMB_VFS_OP_INIT_SEARCH_OP, True, handle, "");
816 static int smb_full_audit_open(vfs_handle_struct *handle,
817 struct smb_filename *smb_fname,
818 files_struct *fsp, int flags, mode_t mode)
820 int result;
822 result = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
824 do_log(SMB_VFS_OP_OPEN, (result >= 0), handle, "%s|%s",
825 ((flags & O_WRONLY) || (flags & O_RDWR))?"w":"r",
826 smb_fname_str_do_log(smb_fname));
828 return result;
831 static NTSTATUS smb_full_audit_create_file(vfs_handle_struct *handle,
832 struct smb_request *req,
833 uint16_t root_dir_fid,
834 struct smb_filename *smb_fname,
835 uint32_t access_mask,
836 uint32_t share_access,
837 uint32_t create_disposition,
838 uint32_t create_options,
839 uint32_t file_attributes,
840 uint32_t oplock_request,
841 uint64_t allocation_size,
842 uint32_t private_flags,
843 struct security_descriptor *sd,
844 struct ea_list *ea_list,
845 files_struct **result_fsp,
846 int *pinfo)
848 NTSTATUS result;
849 const char* str_create_disposition;
851 switch (create_disposition) {
852 case FILE_SUPERSEDE:
853 str_create_disposition = "supersede";
854 break;
855 case FILE_OVERWRITE_IF:
856 str_create_disposition = "overwrite_if";
857 break;
858 case FILE_OPEN:
859 str_create_disposition = "open";
860 break;
861 case FILE_OVERWRITE:
862 str_create_disposition = "overwrite";
863 break;
864 case FILE_CREATE:
865 str_create_disposition = "create";
866 break;
867 case FILE_OPEN_IF:
868 str_create_disposition = "open_if";
869 break;
870 default:
871 str_create_disposition = "unknown";
874 result = SMB_VFS_NEXT_CREATE_FILE(
875 handle, /* handle */
876 req, /* req */
877 root_dir_fid, /* root_dir_fid */
878 smb_fname, /* fname */
879 access_mask, /* access_mask */
880 share_access, /* share_access */
881 create_disposition, /* create_disposition*/
882 create_options, /* create_options */
883 file_attributes, /* file_attributes */
884 oplock_request, /* oplock_request */
885 allocation_size, /* allocation_size */
886 private_flags,
887 sd, /* sd */
888 ea_list, /* ea_list */
889 result_fsp, /* result */
890 pinfo); /* pinfo */
892 do_log(SMB_VFS_OP_CREATE_FILE, (NT_STATUS_IS_OK(result)), handle,
893 "0x%x|%s|%s|%s", access_mask,
894 create_options & FILE_DIRECTORY_FILE ? "dir" : "file",
895 str_create_disposition, smb_fname_str_do_log(smb_fname));
897 return result;
900 static int smb_full_audit_close(vfs_handle_struct *handle, files_struct *fsp)
902 int result;
904 result = SMB_VFS_NEXT_CLOSE(handle, fsp);
906 do_log(SMB_VFS_OP_CLOSE, (result >= 0), handle, "%s",
907 fsp_str_do_log(fsp));
909 return result;
912 static ssize_t smb_full_audit_read(vfs_handle_struct *handle, files_struct *fsp,
913 void *data, size_t n)
915 ssize_t result;
917 result = SMB_VFS_NEXT_READ(handle, fsp, data, n);
919 do_log(SMB_VFS_OP_READ, (result >= 0), handle, "%s",
920 fsp_str_do_log(fsp));
922 return result;
925 static ssize_t smb_full_audit_pread(vfs_handle_struct *handle, files_struct *fsp,
926 void *data, size_t n, off_t offset)
928 ssize_t result;
930 result = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
932 do_log(SMB_VFS_OP_PREAD, (result >= 0), handle, "%s",
933 fsp_str_do_log(fsp));
935 return result;
938 struct smb_full_audit_pread_state {
939 vfs_handle_struct *handle;
940 files_struct *fsp;
941 ssize_t ret;
942 int err;
945 static void smb_full_audit_pread_done(struct tevent_req *subreq);
947 static struct tevent_req *smb_full_audit_pread_send(
948 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
949 struct tevent_context *ev, struct files_struct *fsp,
950 void *data, size_t n, off_t offset)
952 struct tevent_req *req, *subreq;
953 struct smb_full_audit_pread_state *state;
955 req = tevent_req_create(mem_ctx, &state,
956 struct smb_full_audit_pread_state);
957 if (req == NULL) {
958 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
959 fsp_str_do_log(fsp));
960 return NULL;
962 state->handle = handle;
963 state->fsp = fsp;
965 subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
966 n, offset);
967 if (tevent_req_nomem(subreq, req)) {
968 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
969 fsp_str_do_log(fsp));
970 return tevent_req_post(req, ev);
972 tevent_req_set_callback(subreq, smb_full_audit_pread_done, req);
974 do_log(SMB_VFS_OP_PREAD_SEND, true, handle, "%s", fsp_str_do_log(fsp));
975 return req;
978 static void smb_full_audit_pread_done(struct tevent_req *subreq)
980 struct tevent_req *req = tevent_req_callback_data(
981 subreq, struct tevent_req);
982 struct smb_full_audit_pread_state *state = tevent_req_data(
983 req, struct smb_full_audit_pread_state);
985 state->ret = SMB_VFS_PREAD_RECV(subreq, &state->err);
986 TALLOC_FREE(subreq);
987 tevent_req_done(req);
990 static ssize_t smb_full_audit_pread_recv(struct tevent_req *req, int *err)
992 struct smb_full_audit_pread_state *state = tevent_req_data(
993 req, struct smb_full_audit_pread_state);
995 if (tevent_req_is_unix_error(req, err)) {
996 do_log(SMB_VFS_OP_PREAD_RECV, false, state->handle, "%s",
997 fsp_str_do_log(state->fsp));
998 return -1;
1001 do_log(SMB_VFS_OP_PREAD_RECV, (state->ret >= 0), state->handle, "%s",
1002 fsp_str_do_log(state->fsp));
1004 *err = state->err;
1005 return state->ret;
1008 static ssize_t smb_full_audit_write(vfs_handle_struct *handle, files_struct *fsp,
1009 const void *data, size_t n)
1011 ssize_t result;
1013 result = SMB_VFS_NEXT_WRITE(handle, fsp, data, n);
1015 do_log(SMB_VFS_OP_WRITE, (result >= 0), handle, "%s",
1016 fsp_str_do_log(fsp));
1018 return result;
1021 static ssize_t smb_full_audit_pwrite(vfs_handle_struct *handle, files_struct *fsp,
1022 const void *data, size_t n,
1023 off_t offset)
1025 ssize_t result;
1027 result = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
1029 do_log(SMB_VFS_OP_PWRITE, (result >= 0), handle, "%s",
1030 fsp_str_do_log(fsp));
1032 return result;
1035 struct smb_full_audit_pwrite_state {
1036 vfs_handle_struct *handle;
1037 files_struct *fsp;
1038 ssize_t ret;
1039 int err;
1042 static void smb_full_audit_pwrite_done(struct tevent_req *subreq);
1044 static struct tevent_req *smb_full_audit_pwrite_send(
1045 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1046 struct tevent_context *ev, struct files_struct *fsp,
1047 const void *data, size_t n, off_t offset)
1049 struct tevent_req *req, *subreq;
1050 struct smb_full_audit_pwrite_state *state;
1052 req = tevent_req_create(mem_ctx, &state,
1053 struct smb_full_audit_pwrite_state);
1054 if (req == NULL) {
1055 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1056 fsp_str_do_log(fsp));
1057 return NULL;
1059 state->handle = handle;
1060 state->fsp = fsp;
1062 subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
1063 n, offset);
1064 if (tevent_req_nomem(subreq, req)) {
1065 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1066 fsp_str_do_log(fsp));
1067 return tevent_req_post(req, ev);
1069 tevent_req_set_callback(subreq, smb_full_audit_pwrite_done, req);
1071 do_log(SMB_VFS_OP_PWRITE_SEND, true, handle, "%s",
1072 fsp_str_do_log(fsp));
1073 return req;
1076 static void smb_full_audit_pwrite_done(struct tevent_req *subreq)
1078 struct tevent_req *req = tevent_req_callback_data(
1079 subreq, struct tevent_req);
1080 struct smb_full_audit_pwrite_state *state = tevent_req_data(
1081 req, struct smb_full_audit_pwrite_state);
1083 state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->err);
1084 TALLOC_FREE(subreq);
1085 tevent_req_done(req);
1088 static ssize_t smb_full_audit_pwrite_recv(struct tevent_req *req, int *err)
1090 struct smb_full_audit_pwrite_state *state = tevent_req_data(
1091 req, struct smb_full_audit_pwrite_state);
1093 if (tevent_req_is_unix_error(req, err)) {
1094 do_log(SMB_VFS_OP_PWRITE_RECV, false, state->handle, "%s",
1095 fsp_str_do_log(state->fsp));
1096 return -1;
1099 do_log(SMB_VFS_OP_PWRITE_RECV, (state->ret >= 0), state->handle, "%s",
1100 fsp_str_do_log(state->fsp));
1102 *err = state->err;
1103 return state->ret;
1106 static off_t smb_full_audit_lseek(vfs_handle_struct *handle, files_struct *fsp,
1107 off_t offset, int whence)
1109 ssize_t result;
1111 result = SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence);
1113 do_log(SMB_VFS_OP_LSEEK, (result != (ssize_t)-1), handle,
1114 "%s", fsp_str_do_log(fsp));
1116 return result;
1119 static ssize_t smb_full_audit_sendfile(vfs_handle_struct *handle, int tofd,
1120 files_struct *fromfsp,
1121 const DATA_BLOB *hdr, off_t offset,
1122 size_t n)
1124 ssize_t result;
1126 result = SMB_VFS_NEXT_SENDFILE(handle, tofd, fromfsp, hdr, offset, n);
1128 do_log(SMB_VFS_OP_SENDFILE, (result >= 0), handle,
1129 "%s", fsp_str_do_log(fromfsp));
1131 return result;
1134 static ssize_t smb_full_audit_recvfile(vfs_handle_struct *handle, int fromfd,
1135 files_struct *tofsp,
1136 off_t offset,
1137 size_t n)
1139 ssize_t result;
1141 result = SMB_VFS_NEXT_RECVFILE(handle, fromfd, tofsp, offset, n);
1143 do_log(SMB_VFS_OP_RECVFILE, (result >= 0), handle,
1144 "%s", fsp_str_do_log(tofsp));
1146 return result;
1149 static int smb_full_audit_rename(vfs_handle_struct *handle,
1150 const struct smb_filename *smb_fname_src,
1151 const struct smb_filename *smb_fname_dst)
1153 int result;
1155 result = SMB_VFS_NEXT_RENAME(handle, smb_fname_src, smb_fname_dst);
1157 do_log(SMB_VFS_OP_RENAME, (result >= 0), handle, "%s|%s",
1158 smb_fname_str_do_log(smb_fname_src),
1159 smb_fname_str_do_log(smb_fname_dst));
1161 return result;
1164 static int smb_full_audit_fsync(vfs_handle_struct *handle, files_struct *fsp)
1166 int result;
1168 result = SMB_VFS_NEXT_FSYNC(handle, fsp);
1170 do_log(SMB_VFS_OP_FSYNC, (result >= 0), handle, "%s",
1171 fsp_str_do_log(fsp));
1173 return result;
1176 struct smb_full_audit_fsync_state {
1177 vfs_handle_struct *handle;
1178 files_struct *fsp;
1179 int ret;
1180 int err;
1183 static void smb_full_audit_fsync_done(struct tevent_req *subreq);
1185 static struct tevent_req *smb_full_audit_fsync_send(
1186 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1187 struct tevent_context *ev, struct files_struct *fsp)
1189 struct tevent_req *req, *subreq;
1190 struct smb_full_audit_fsync_state *state;
1192 req = tevent_req_create(mem_ctx, &state,
1193 struct smb_full_audit_fsync_state);
1194 if (req == NULL) {
1195 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1196 fsp_str_do_log(fsp));
1197 return NULL;
1199 state->handle = handle;
1200 state->fsp = fsp;
1202 subreq = SMB_VFS_NEXT_FSYNC_SEND(state, ev, handle, fsp);
1203 if (tevent_req_nomem(subreq, req)) {
1204 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1205 fsp_str_do_log(fsp));
1206 return tevent_req_post(req, ev);
1208 tevent_req_set_callback(subreq, smb_full_audit_fsync_done, req);
1210 do_log(SMB_VFS_OP_FSYNC_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1211 return req;
1214 static void smb_full_audit_fsync_done(struct tevent_req *subreq)
1216 struct tevent_req *req = tevent_req_callback_data(
1217 subreq, struct tevent_req);
1218 struct smb_full_audit_fsync_state *state = tevent_req_data(
1219 req, struct smb_full_audit_fsync_state);
1221 state->ret = SMB_VFS_FSYNC_RECV(subreq, &state->err);
1222 TALLOC_FREE(subreq);
1223 tevent_req_done(req);
1226 static int smb_full_audit_fsync_recv(struct tevent_req *req, int *err)
1228 struct smb_full_audit_fsync_state *state = tevent_req_data(
1229 req, struct smb_full_audit_fsync_state);
1231 if (tevent_req_is_unix_error(req, err)) {
1232 do_log(SMB_VFS_OP_FSYNC_RECV, false, state->handle, "%s",
1233 fsp_str_do_log(state->fsp));
1234 return -1;
1237 do_log(SMB_VFS_OP_FSYNC_RECV, (state->ret >= 0), state->handle, "%s",
1238 fsp_str_do_log(state->fsp));
1240 *err = state->err;
1241 return state->ret;
1244 static int smb_full_audit_stat(vfs_handle_struct *handle,
1245 struct smb_filename *smb_fname)
1247 int result;
1249 result = SMB_VFS_NEXT_STAT(handle, smb_fname);
1251 do_log(SMB_VFS_OP_STAT, (result >= 0), handle, "%s",
1252 smb_fname_str_do_log(smb_fname));
1254 return result;
1257 static int smb_full_audit_fstat(vfs_handle_struct *handle, files_struct *fsp,
1258 SMB_STRUCT_STAT *sbuf)
1260 int result;
1262 result = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1264 do_log(SMB_VFS_OP_FSTAT, (result >= 0), handle, "%s",
1265 fsp_str_do_log(fsp));
1267 return result;
1270 static int smb_full_audit_lstat(vfs_handle_struct *handle,
1271 struct smb_filename *smb_fname)
1273 int result;
1275 result = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
1277 do_log(SMB_VFS_OP_LSTAT, (result >= 0), handle, "%s",
1278 smb_fname_str_do_log(smb_fname));
1280 return result;
1283 static uint64_t smb_full_audit_get_alloc_size(vfs_handle_struct *handle,
1284 files_struct *fsp, const SMB_STRUCT_STAT *sbuf)
1286 uint64_t result;
1288 result = SMB_VFS_NEXT_GET_ALLOC_SIZE(handle, fsp, sbuf);
1290 do_log(SMB_VFS_OP_GET_ALLOC_SIZE, (result != (uint64_t)-1), handle,
1291 "%llu", result);
1293 return result;
1296 static int smb_full_audit_unlink(vfs_handle_struct *handle,
1297 const struct smb_filename *smb_fname)
1299 int result;
1301 result = SMB_VFS_NEXT_UNLINK(handle, smb_fname);
1303 do_log(SMB_VFS_OP_UNLINK, (result >= 0), handle, "%s",
1304 smb_fname_str_do_log(smb_fname));
1306 return result;
1309 static int smb_full_audit_chmod(vfs_handle_struct *handle,
1310 const char *path, mode_t mode)
1312 int result;
1314 result = SMB_VFS_NEXT_CHMOD(handle, path, mode);
1316 do_log(SMB_VFS_OP_CHMOD, (result >= 0), handle, "%s|%o", path, mode);
1318 return result;
1321 static int smb_full_audit_fchmod(vfs_handle_struct *handle, files_struct *fsp,
1322 mode_t mode)
1324 int result;
1326 result = SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1328 do_log(SMB_VFS_OP_FCHMOD, (result >= 0), handle,
1329 "%s|%o", fsp_str_do_log(fsp), mode);
1331 return result;
1334 static int smb_full_audit_chown(vfs_handle_struct *handle,
1335 const char *path, uid_t uid, gid_t gid)
1337 int result;
1339 result = SMB_VFS_NEXT_CHOWN(handle, path, uid, gid);
1341 do_log(SMB_VFS_OP_CHOWN, (result >= 0), handle, "%s|%ld|%ld",
1342 path, (long int)uid, (long int)gid);
1344 return result;
1347 static int smb_full_audit_fchown(vfs_handle_struct *handle, files_struct *fsp,
1348 uid_t uid, gid_t gid)
1350 int result;
1352 result = SMB_VFS_NEXT_FCHOWN(handle, fsp, uid, gid);
1354 do_log(SMB_VFS_OP_FCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1355 fsp_str_do_log(fsp), (long int)uid, (long int)gid);
1357 return result;
1360 static int smb_full_audit_lchown(vfs_handle_struct *handle,
1361 const char *path, uid_t uid, gid_t gid)
1363 int result;
1365 result = SMB_VFS_NEXT_LCHOWN(handle, path, uid, gid);
1367 do_log(SMB_VFS_OP_LCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1368 path, (long int)uid, (long int)gid);
1370 return result;
1373 static int smb_full_audit_chdir(vfs_handle_struct *handle,
1374 const char *path)
1376 int result;
1378 result = SMB_VFS_NEXT_CHDIR(handle, path);
1380 do_log(SMB_VFS_OP_CHDIR, (result >= 0), handle, "chdir|%s", path);
1382 return result;
1385 static char *smb_full_audit_getwd(vfs_handle_struct *handle)
1387 char *result;
1389 result = SMB_VFS_NEXT_GETWD(handle);
1391 do_log(SMB_VFS_OP_GETWD, (result != NULL), handle, "%s",
1392 result == NULL? "" : result);
1394 return result;
1397 static int smb_full_audit_ntimes(vfs_handle_struct *handle,
1398 const struct smb_filename *smb_fname,
1399 struct smb_file_time *ft)
1401 int result;
1403 result = SMB_VFS_NEXT_NTIMES(handle, smb_fname, ft);
1405 do_log(SMB_VFS_OP_NTIMES, (result >= 0), handle, "%s",
1406 smb_fname_str_do_log(smb_fname));
1408 return result;
1411 static int smb_full_audit_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
1412 off_t len)
1414 int result;
1416 result = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1418 do_log(SMB_VFS_OP_FTRUNCATE, (result >= 0), handle,
1419 "%s", fsp_str_do_log(fsp));
1421 return result;
1424 static int smb_full_audit_fallocate(vfs_handle_struct *handle, files_struct *fsp,
1425 enum vfs_fallocate_mode mode,
1426 off_t offset,
1427 off_t len)
1429 int result;
1431 result = SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
1433 do_log(SMB_VFS_OP_FALLOCATE, (result >= 0), handle,
1434 "%s", fsp_str_do_log(fsp));
1436 return result;
1439 static bool smb_full_audit_lock(vfs_handle_struct *handle, files_struct *fsp,
1440 int op, off_t offset, off_t count, int type)
1442 bool result;
1444 result = SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type);
1446 do_log(SMB_VFS_OP_LOCK, result, handle, "%s", fsp_str_do_log(fsp));
1448 return result;
1451 static int smb_full_audit_kernel_flock(struct vfs_handle_struct *handle,
1452 struct files_struct *fsp,
1453 uint32 share_mode, uint32 access_mask)
1455 int result;
1457 result = SMB_VFS_NEXT_KERNEL_FLOCK(handle, fsp, share_mode, access_mask);
1459 do_log(SMB_VFS_OP_KERNEL_FLOCK, (result >= 0), handle, "%s",
1460 fsp_str_do_log(fsp));
1462 return result;
1465 static int smb_full_audit_linux_setlease(vfs_handle_struct *handle, files_struct *fsp,
1466 int leasetype)
1468 int result;
1470 result = SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
1472 do_log(SMB_VFS_OP_LINUX_SETLEASE, (result >= 0), handle, "%s",
1473 fsp_str_do_log(fsp));
1475 return result;
1478 static bool smb_full_audit_getlock(vfs_handle_struct *handle, files_struct *fsp,
1479 off_t *poffset, off_t *pcount, int *ptype, pid_t *ppid)
1481 bool result;
1483 result = SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype, ppid);
1485 do_log(SMB_VFS_OP_GETLOCK, result, handle, "%s", fsp_str_do_log(fsp));
1487 return result;
1490 static int smb_full_audit_symlink(vfs_handle_struct *handle,
1491 const char *oldpath, const char *newpath)
1493 int result;
1495 result = SMB_VFS_NEXT_SYMLINK(handle, oldpath, newpath);
1497 do_log(SMB_VFS_OP_SYMLINK, (result >= 0), handle,
1498 "%s|%s", oldpath, newpath);
1500 return result;
1503 static int smb_full_audit_readlink(vfs_handle_struct *handle,
1504 const char *path, char *buf, size_t bufsiz)
1506 int result;
1508 result = SMB_VFS_NEXT_READLINK(handle, path, buf, bufsiz);
1510 do_log(SMB_VFS_OP_READLINK, (result >= 0), handle, "%s", path);
1512 return result;
1515 static int smb_full_audit_link(vfs_handle_struct *handle,
1516 const char *oldpath, const char *newpath)
1518 int result;
1520 result = SMB_VFS_NEXT_LINK(handle, oldpath, newpath);
1522 do_log(SMB_VFS_OP_LINK, (result >= 0), handle,
1523 "%s|%s", oldpath, newpath);
1525 return result;
1528 static int smb_full_audit_mknod(vfs_handle_struct *handle,
1529 const char *pathname, mode_t mode, SMB_DEV_T dev)
1531 int result;
1533 result = SMB_VFS_NEXT_MKNOD(handle, pathname, mode, dev);
1535 do_log(SMB_VFS_OP_MKNOD, (result >= 0), handle, "%s", pathname);
1537 return result;
1540 static char *smb_full_audit_realpath(vfs_handle_struct *handle,
1541 const char *path)
1543 char *result;
1545 result = SMB_VFS_NEXT_REALPATH(handle, path);
1547 do_log(SMB_VFS_OP_REALPATH, (result != NULL), handle, "%s", path);
1549 return result;
1552 static NTSTATUS smb_full_audit_notify_watch(struct vfs_handle_struct *handle,
1553 struct sys_notify_context *ctx,
1554 const char *path,
1555 uint32_t *filter,
1556 uint32_t *subdir_filter,
1557 void (*callback)(struct sys_notify_context *ctx,
1558 void *private_data,
1559 struct notify_event *ev),
1560 void *private_data, void *handle_p)
1562 NTSTATUS result;
1564 result = SMB_VFS_NEXT_NOTIFY_WATCH(handle, ctx, path,
1565 filter, subdir_filter, callback,
1566 private_data, handle_p);
1568 do_log(SMB_VFS_OP_NOTIFY_WATCH, NT_STATUS_IS_OK(result), handle, "");
1570 return result;
1573 static int smb_full_audit_chflags(vfs_handle_struct *handle,
1574 const char *path, unsigned int flags)
1576 int result;
1578 result = SMB_VFS_NEXT_CHFLAGS(handle, path, flags);
1580 do_log(SMB_VFS_OP_CHFLAGS, (result != 0), handle, "%s", path);
1582 return result;
1585 static struct file_id smb_full_audit_file_id_create(struct vfs_handle_struct *handle,
1586 const SMB_STRUCT_STAT *sbuf)
1588 struct file_id id_zero;
1589 struct file_id result;
1591 ZERO_STRUCT(id_zero);
1593 result = SMB_VFS_NEXT_FILE_ID_CREATE(handle, sbuf);
1595 do_log(SMB_VFS_OP_FILE_ID_CREATE,
1596 !file_id_equal(&id_zero, &result),
1597 handle, "%s", file_id_string_tos(&result));
1599 return result;
1602 static NTSTATUS smb_full_audit_streaminfo(vfs_handle_struct *handle,
1603 struct files_struct *fsp,
1604 const char *fname,
1605 TALLOC_CTX *mem_ctx,
1606 unsigned int *pnum_streams,
1607 struct stream_struct **pstreams)
1609 NTSTATUS result;
1611 result = SMB_VFS_NEXT_STREAMINFO(handle, fsp, fname, mem_ctx,
1612 pnum_streams, pstreams);
1614 do_log(SMB_VFS_OP_STREAMINFO, NT_STATUS_IS_OK(result), handle,
1615 "%s", fname);
1617 return result;
1620 static int smb_full_audit_get_real_filename(struct vfs_handle_struct *handle,
1621 const char *path,
1622 const char *name,
1623 TALLOC_CTX *mem_ctx,
1624 char **found_name)
1626 int result;
1628 result = SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name, mem_ctx,
1629 found_name);
1631 do_log(SMB_VFS_OP_GET_REAL_FILENAME, (result == 0), handle,
1632 "%s/%s->%s", path, name, (result == 0) ? "" : *found_name);
1634 return result;
1637 static const char *smb_full_audit_connectpath(vfs_handle_struct *handle,
1638 const char *fname)
1640 const char *result;
1642 result = SMB_VFS_NEXT_CONNECTPATH(handle, fname);
1644 do_log(SMB_VFS_OP_CONNECTPATH, result != NULL, handle,
1645 "%s", fname);
1647 return result;
1650 static NTSTATUS smb_full_audit_brl_lock_windows(struct vfs_handle_struct *handle,
1651 struct byte_range_lock *br_lck,
1652 struct lock_struct *plock,
1653 bool blocking_lock,
1654 struct blocking_lock_record *blr)
1656 NTSTATUS result;
1658 result = SMB_VFS_NEXT_BRL_LOCK_WINDOWS(handle, br_lck, plock,
1659 blocking_lock, blr);
1661 do_log(SMB_VFS_OP_BRL_LOCK_WINDOWS, NT_STATUS_IS_OK(result), handle,
1662 "%s:%llu-%llu. type=%d. blocking=%d",
1663 fsp_str_do_log(brl_fsp(br_lck)),
1664 plock->start, plock->size, plock->lock_type, blocking_lock);
1666 return result;
1669 static bool smb_full_audit_brl_unlock_windows(struct vfs_handle_struct *handle,
1670 struct messaging_context *msg_ctx,
1671 struct byte_range_lock *br_lck,
1672 const struct lock_struct *plock)
1674 bool result;
1676 result = SMB_VFS_NEXT_BRL_UNLOCK_WINDOWS(handle, msg_ctx, br_lck,
1677 plock);
1679 do_log(SMB_VFS_OP_BRL_UNLOCK_WINDOWS, (result == 0), handle,
1680 "%s:%llu-%llu:%d", fsp_str_do_log(brl_fsp(br_lck)),
1681 plock->start,
1682 plock->size, plock->lock_type);
1684 return result;
1687 static bool smb_full_audit_brl_cancel_windows(struct vfs_handle_struct *handle,
1688 struct byte_range_lock *br_lck,
1689 struct lock_struct *plock,
1690 struct blocking_lock_record *blr)
1692 bool result;
1694 result = SMB_VFS_NEXT_BRL_CANCEL_WINDOWS(handle, br_lck, plock, blr);
1696 do_log(SMB_VFS_OP_BRL_CANCEL_WINDOWS, (result == 0), handle,
1697 "%s:%llu-%llu:%d", fsp_str_do_log(brl_fsp(br_lck)),
1698 plock->start,
1699 plock->size, plock->lock_type);
1701 return result;
1704 static bool smb_full_audit_strict_lock(struct vfs_handle_struct *handle,
1705 struct files_struct *fsp,
1706 struct lock_struct *plock)
1708 bool result;
1710 result = SMB_VFS_NEXT_STRICT_LOCK(handle, fsp, plock);
1712 do_log(SMB_VFS_OP_STRICT_LOCK, result, handle,
1713 "%s:%llu-%llu:%d", fsp_str_do_log(fsp), plock->start,
1714 plock->size, plock->lock_type);
1716 return result;
1719 static void smb_full_audit_strict_unlock(struct vfs_handle_struct *handle,
1720 struct files_struct *fsp,
1721 struct lock_struct *plock)
1723 SMB_VFS_NEXT_STRICT_UNLOCK(handle, fsp, plock);
1725 do_log(SMB_VFS_OP_STRICT_UNLOCK, true, handle,
1726 "%s:%llu-%llu:%d", fsp_str_do_log(fsp), plock->start,
1727 plock->size, plock->lock_type);
1730 static NTSTATUS smb_full_audit_translate_name(struct vfs_handle_struct *handle,
1731 const char *name,
1732 enum vfs_translate_direction direction,
1733 TALLOC_CTX *mem_ctx,
1734 char **mapped_name)
1736 NTSTATUS result;
1738 result = SMB_VFS_NEXT_TRANSLATE_NAME(handle, name, direction, mem_ctx,
1739 mapped_name);
1741 do_log(SMB_VFS_OP_TRANSLATE_NAME, NT_STATUS_IS_OK(result), handle, "");
1743 return result;
1746 static struct tevent_req *smb_full_audit_copy_chunk_send(struct vfs_handle_struct *handle,
1747 TALLOC_CTX *mem_ctx,
1748 struct tevent_context *ev,
1749 struct files_struct *src_fsp,
1750 off_t src_off,
1751 struct files_struct *dest_fsp,
1752 off_t dest_off,
1753 off_t num)
1755 struct tevent_req *req;
1757 req = SMB_VFS_NEXT_COPY_CHUNK_SEND(handle, mem_ctx, ev, src_fsp,
1758 src_off, dest_fsp, dest_off, num);
1760 do_log(SMB_VFS_OP_COPY_CHUNK_SEND, req, handle, "");
1762 return req;
1765 static NTSTATUS smb_full_audit_copy_chunk_recv(struct vfs_handle_struct *handle,
1766 struct tevent_req *req,
1767 off_t *copied)
1769 NTSTATUS result;
1771 result = SMB_VFS_NEXT_COPY_CHUNK_RECV(handle, req, copied);
1773 do_log(SMB_VFS_OP_COPY_CHUNK_RECV, NT_STATUS_IS_OK(result), handle, "");
1775 return result;
1778 static NTSTATUS smb_full_audit_get_compression(vfs_handle_struct *handle,
1779 TALLOC_CTX *mem_ctx,
1780 struct files_struct *fsp,
1781 struct smb_filename *smb_fname,
1782 uint16_t *_compression_fmt)
1784 NTSTATUS result;
1786 result = SMB_VFS_NEXT_GET_COMPRESSION(handle, mem_ctx, fsp, smb_fname,
1787 _compression_fmt);
1789 do_log(SMB_VFS_OP_GET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
1790 "%s",
1791 (fsp ? fsp_str_do_log(fsp) : smb_fname_str_do_log(smb_fname)));
1793 return result;
1796 static NTSTATUS smb_full_audit_set_compression(vfs_handle_struct *handle,
1797 TALLOC_CTX *mem_ctx,
1798 struct files_struct *fsp,
1799 uint16_t compression_fmt)
1801 NTSTATUS result;
1803 result = SMB_VFS_NEXT_SET_COMPRESSION(handle, mem_ctx, fsp,
1804 compression_fmt);
1806 do_log(SMB_VFS_OP_SET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
1807 "%s", fsp_str_do_log(fsp));
1809 return result;
1812 static NTSTATUS smb_full_audit_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
1813 uint32 security_info,
1814 TALLOC_CTX *mem_ctx,
1815 struct security_descriptor **ppdesc)
1817 NTSTATUS result;
1819 result = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
1820 mem_ctx, ppdesc);
1822 do_log(SMB_VFS_OP_FGET_NT_ACL, NT_STATUS_IS_OK(result), handle,
1823 "%s", fsp_str_do_log(fsp));
1825 return result;
1828 static NTSTATUS smb_full_audit_get_nt_acl(vfs_handle_struct *handle,
1829 const char *name,
1830 uint32 security_info,
1831 TALLOC_CTX *mem_ctx,
1832 struct security_descriptor **ppdesc)
1834 NTSTATUS result;
1836 result = SMB_VFS_NEXT_GET_NT_ACL(handle, name, security_info,
1837 mem_ctx, ppdesc);
1839 do_log(SMB_VFS_OP_GET_NT_ACL, NT_STATUS_IS_OK(result), handle,
1840 "%s", name);
1842 return result;
1845 static NTSTATUS smb_full_audit_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
1846 uint32 security_info_sent,
1847 const struct security_descriptor *psd)
1849 NTSTATUS result;
1851 result = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
1853 do_log(SMB_VFS_OP_FSET_NT_ACL, NT_STATUS_IS_OK(result), handle, "%s",
1854 fsp_str_do_log(fsp));
1856 return result;
1859 static int smb_full_audit_chmod_acl(vfs_handle_struct *handle,
1860 const char *path, mode_t mode)
1862 int result;
1864 result = SMB_VFS_NEXT_CHMOD_ACL(handle, path, mode);
1866 do_log(SMB_VFS_OP_CHMOD_ACL, (result >= 0), handle,
1867 "%s|%o", path, mode);
1869 return result;
1872 static int smb_full_audit_fchmod_acl(vfs_handle_struct *handle, files_struct *fsp,
1873 mode_t mode)
1875 int result;
1877 result = SMB_VFS_NEXT_FCHMOD_ACL(handle, fsp, mode);
1879 do_log(SMB_VFS_OP_FCHMOD_ACL, (result >= 0), handle,
1880 "%s|%o", fsp_str_do_log(fsp), mode);
1882 return result;
1885 static SMB_ACL_T smb_full_audit_sys_acl_get_file(vfs_handle_struct *handle,
1886 const char *path_p,
1887 SMB_ACL_TYPE_T type,
1888 TALLOC_CTX *mem_ctx)
1890 SMB_ACL_T result;
1892 result = SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, path_p, type, mem_ctx);
1894 do_log(SMB_VFS_OP_SYS_ACL_GET_FILE, (result != NULL), handle,
1895 "%s", path_p);
1897 return result;
1900 static SMB_ACL_T smb_full_audit_sys_acl_get_fd(vfs_handle_struct *handle,
1901 files_struct *fsp, TALLOC_CTX *mem_ctx)
1903 SMB_ACL_T result;
1905 result = SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp, mem_ctx);
1907 do_log(SMB_VFS_OP_SYS_ACL_GET_FD, (result != NULL), handle,
1908 "%s", fsp_str_do_log(fsp));
1910 return result;
1913 static int smb_full_audit_sys_acl_blob_get_file(vfs_handle_struct *handle,
1914 const char *path_p,
1915 TALLOC_CTX *mem_ctx,
1916 char **blob_description,
1917 DATA_BLOB *blob)
1919 int result;
1921 result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FILE(handle, path_p, mem_ctx, blob_description, blob);
1923 do_log(SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE, (result >= 0), handle,
1924 "%s", path_p);
1926 return result;
1929 static int smb_full_audit_sys_acl_blob_get_fd(vfs_handle_struct *handle,
1930 files_struct *fsp,
1931 TALLOC_CTX *mem_ctx,
1932 char **blob_description,
1933 DATA_BLOB *blob)
1935 int result;
1937 result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle, fsp, mem_ctx, blob_description, blob);
1939 do_log(SMB_VFS_OP_SYS_ACL_BLOB_GET_FD, (result >= 0), handle,
1940 "%s", fsp_str_do_log(fsp));
1942 return result;
1945 static int smb_full_audit_sys_acl_set_file(vfs_handle_struct *handle,
1947 const char *name, SMB_ACL_TYPE_T acltype,
1948 SMB_ACL_T theacl)
1950 int result;
1952 result = SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, name, acltype,
1953 theacl);
1955 do_log(SMB_VFS_OP_SYS_ACL_SET_FILE, (result >= 0), handle,
1956 "%s", name);
1958 return result;
1961 static int smb_full_audit_sys_acl_set_fd(vfs_handle_struct *handle, files_struct *fsp,
1962 SMB_ACL_T theacl)
1964 int result;
1966 result = SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, theacl);
1968 do_log(SMB_VFS_OP_SYS_ACL_SET_FD, (result >= 0), handle,
1969 "%s", fsp_str_do_log(fsp));
1971 return result;
1974 static int smb_full_audit_sys_acl_delete_def_file(vfs_handle_struct *handle,
1976 const char *path)
1978 int result;
1980 result = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, path);
1982 do_log(SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE, (result >= 0), handle,
1983 "%s", path);
1985 return result;
1988 static ssize_t smb_full_audit_getxattr(struct vfs_handle_struct *handle,
1989 const char *path,
1990 const char *name, void *value, size_t size)
1992 ssize_t result;
1994 result = SMB_VFS_NEXT_GETXATTR(handle, path, name, value, size);
1996 do_log(SMB_VFS_OP_GETXATTR, (result >= 0), handle,
1997 "%s|%s", path, name);
1999 return result;
2002 static ssize_t smb_full_audit_fgetxattr(struct vfs_handle_struct *handle,
2003 struct files_struct *fsp,
2004 const char *name, void *value, size_t size)
2006 ssize_t result;
2008 result = SMB_VFS_NEXT_FGETXATTR(handle, fsp, name, value, size);
2010 do_log(SMB_VFS_OP_FGETXATTR, (result >= 0), handle,
2011 "%s|%s", fsp_str_do_log(fsp), name);
2013 return result;
2016 static ssize_t smb_full_audit_listxattr(struct vfs_handle_struct *handle,
2017 const char *path, char *list, size_t size)
2019 ssize_t result;
2021 result = SMB_VFS_NEXT_LISTXATTR(handle, path, list, size);
2023 do_log(SMB_VFS_OP_LISTXATTR, (result >= 0), handle, "%s", path);
2025 return result;
2028 static ssize_t smb_full_audit_flistxattr(struct vfs_handle_struct *handle,
2029 struct files_struct *fsp, char *list,
2030 size_t size)
2032 ssize_t result;
2034 result = SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
2036 do_log(SMB_VFS_OP_FLISTXATTR, (result >= 0), handle,
2037 "%s", fsp_str_do_log(fsp));
2039 return result;
2042 static int smb_full_audit_removexattr(struct vfs_handle_struct *handle,
2043 const char *path,
2044 const char *name)
2046 int result;
2048 result = SMB_VFS_NEXT_REMOVEXATTR(handle, path, name);
2050 do_log(SMB_VFS_OP_REMOVEXATTR, (result >= 0), handle,
2051 "%s|%s", path, name);
2053 return result;
2056 static int smb_full_audit_fremovexattr(struct vfs_handle_struct *handle,
2057 struct files_struct *fsp,
2058 const char *name)
2060 int result;
2062 result = SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, name);
2064 do_log(SMB_VFS_OP_FREMOVEXATTR, (result >= 0), handle,
2065 "%s|%s", fsp_str_do_log(fsp), name);
2067 return result;
2070 static int smb_full_audit_setxattr(struct vfs_handle_struct *handle,
2071 const char *path,
2072 const char *name, const void *value, size_t size,
2073 int flags)
2075 int result;
2077 result = SMB_VFS_NEXT_SETXATTR(handle, path, name, value, size,
2078 flags);
2080 do_log(SMB_VFS_OP_SETXATTR, (result >= 0), handle,
2081 "%s|%s", path, name);
2083 return result;
2086 static int smb_full_audit_fsetxattr(struct vfs_handle_struct *handle,
2087 struct files_struct *fsp, const char *name,
2088 const void *value, size_t size, int flags)
2090 int result;
2092 result = SMB_VFS_NEXT_FSETXATTR(handle, fsp, name, value, size, flags);
2094 do_log(SMB_VFS_OP_FSETXATTR, (result >= 0), handle,
2095 "%s|%s", fsp_str_do_log(fsp), name);
2097 return result;
2100 static bool smb_full_audit_aio_force(struct vfs_handle_struct *handle,
2101 struct files_struct *fsp)
2103 bool result;
2105 result = SMB_VFS_NEXT_AIO_FORCE(handle, fsp);
2106 do_log(SMB_VFS_OP_AIO_FORCE, result, handle,
2107 "%s", fsp_str_do_log(fsp));
2109 return result;
2112 static bool smb_full_audit_is_offline(struct vfs_handle_struct *handle,
2113 const struct smb_filename *fname,
2114 SMB_STRUCT_STAT *sbuf)
2116 bool result;
2118 result = SMB_VFS_NEXT_IS_OFFLINE(handle, fname, sbuf);
2119 do_log(SMB_VFS_OP_IS_OFFLINE, result, handle, "%s",
2120 smb_fname_str_do_log(fname));
2121 return result;
2124 static int smb_full_audit_set_offline(struct vfs_handle_struct *handle,
2125 const struct smb_filename *fname)
2127 int result;
2129 result = SMB_VFS_NEXT_SET_OFFLINE(handle, fname);
2130 do_log(SMB_VFS_OP_SET_OFFLINE, result >= 0, handle, "%s",
2131 smb_fname_str_do_log(fname));
2132 return result;
2135 static struct vfs_fn_pointers vfs_full_audit_fns = {
2137 /* Disk operations */
2139 .connect_fn = smb_full_audit_connect,
2140 .disconnect_fn = smb_full_audit_disconnect,
2141 .disk_free_fn = smb_full_audit_disk_free,
2142 .get_quota_fn = smb_full_audit_get_quota,
2143 .set_quota_fn = smb_full_audit_set_quota,
2144 .get_shadow_copy_data_fn = smb_full_audit_get_shadow_copy_data,
2145 .statvfs_fn = smb_full_audit_statvfs,
2146 .fs_capabilities_fn = smb_full_audit_fs_capabilities,
2147 .opendir_fn = smb_full_audit_opendir,
2148 .fdopendir_fn = smb_full_audit_fdopendir,
2149 .readdir_fn = smb_full_audit_readdir,
2150 .seekdir_fn = smb_full_audit_seekdir,
2151 .telldir_fn = smb_full_audit_telldir,
2152 .rewind_dir_fn = smb_full_audit_rewinddir,
2153 .mkdir_fn = smb_full_audit_mkdir,
2154 .rmdir_fn = smb_full_audit_rmdir,
2155 .closedir_fn = smb_full_audit_closedir,
2156 .init_search_op_fn = smb_full_audit_init_search_op,
2157 .open_fn = smb_full_audit_open,
2158 .create_file_fn = smb_full_audit_create_file,
2159 .close_fn = smb_full_audit_close,
2160 .read_fn = smb_full_audit_read,
2161 .pread_fn = smb_full_audit_pread,
2162 .pread_send_fn = smb_full_audit_pread_send,
2163 .pread_recv_fn = smb_full_audit_pread_recv,
2164 .write_fn = smb_full_audit_write,
2165 .pwrite_fn = smb_full_audit_pwrite,
2166 .pwrite_send_fn = smb_full_audit_pwrite_send,
2167 .pwrite_recv_fn = smb_full_audit_pwrite_recv,
2168 .lseek_fn = smb_full_audit_lseek,
2169 .sendfile_fn = smb_full_audit_sendfile,
2170 .recvfile_fn = smb_full_audit_recvfile,
2171 .rename_fn = smb_full_audit_rename,
2172 .fsync_fn = smb_full_audit_fsync,
2173 .fsync_send_fn = smb_full_audit_fsync_send,
2174 .fsync_recv_fn = smb_full_audit_fsync_recv,
2175 .stat_fn = smb_full_audit_stat,
2176 .fstat_fn = smb_full_audit_fstat,
2177 .lstat_fn = smb_full_audit_lstat,
2178 .get_alloc_size_fn = smb_full_audit_get_alloc_size,
2179 .unlink_fn = smb_full_audit_unlink,
2180 .chmod_fn = smb_full_audit_chmod,
2181 .fchmod_fn = smb_full_audit_fchmod,
2182 .chown_fn = smb_full_audit_chown,
2183 .fchown_fn = smb_full_audit_fchown,
2184 .lchown_fn = smb_full_audit_lchown,
2185 .chdir_fn = smb_full_audit_chdir,
2186 .getwd_fn = smb_full_audit_getwd,
2187 .ntimes_fn = smb_full_audit_ntimes,
2188 .ftruncate_fn = smb_full_audit_ftruncate,
2189 .fallocate_fn = smb_full_audit_fallocate,
2190 .lock_fn = smb_full_audit_lock,
2191 .kernel_flock_fn = smb_full_audit_kernel_flock,
2192 .linux_setlease_fn = smb_full_audit_linux_setlease,
2193 .getlock_fn = smb_full_audit_getlock,
2194 .symlink_fn = smb_full_audit_symlink,
2195 .readlink_fn = smb_full_audit_readlink,
2196 .link_fn = smb_full_audit_link,
2197 .mknod_fn = smb_full_audit_mknod,
2198 .realpath_fn = smb_full_audit_realpath,
2199 .notify_watch_fn = smb_full_audit_notify_watch,
2200 .chflags_fn = smb_full_audit_chflags,
2201 .file_id_create_fn = smb_full_audit_file_id_create,
2202 .streaminfo_fn = smb_full_audit_streaminfo,
2203 .get_real_filename_fn = smb_full_audit_get_real_filename,
2204 .connectpath_fn = smb_full_audit_connectpath,
2205 .brl_lock_windows_fn = smb_full_audit_brl_lock_windows,
2206 .brl_unlock_windows_fn = smb_full_audit_brl_unlock_windows,
2207 .brl_cancel_windows_fn = smb_full_audit_brl_cancel_windows,
2208 .strict_lock_fn = smb_full_audit_strict_lock,
2209 .strict_unlock_fn = smb_full_audit_strict_unlock,
2210 .translate_name_fn = smb_full_audit_translate_name,
2211 .copy_chunk_send_fn = smb_full_audit_copy_chunk_send,
2212 .copy_chunk_recv_fn = smb_full_audit_copy_chunk_recv,
2213 .get_compression_fn = smb_full_audit_get_compression,
2214 .set_compression_fn = smb_full_audit_set_compression,
2215 .fget_nt_acl_fn = smb_full_audit_fget_nt_acl,
2216 .get_nt_acl_fn = smb_full_audit_get_nt_acl,
2217 .fset_nt_acl_fn = smb_full_audit_fset_nt_acl,
2218 .chmod_acl_fn = smb_full_audit_chmod_acl,
2219 .fchmod_acl_fn = smb_full_audit_fchmod_acl,
2220 .sys_acl_get_file_fn = smb_full_audit_sys_acl_get_file,
2221 .sys_acl_get_fd_fn = smb_full_audit_sys_acl_get_fd,
2222 .sys_acl_blob_get_file_fn = smb_full_audit_sys_acl_blob_get_file,
2223 .sys_acl_blob_get_fd_fn = smb_full_audit_sys_acl_blob_get_fd,
2224 .sys_acl_set_file_fn = smb_full_audit_sys_acl_set_file,
2225 .sys_acl_set_fd_fn = smb_full_audit_sys_acl_set_fd,
2226 .sys_acl_delete_def_file_fn = smb_full_audit_sys_acl_delete_def_file,
2227 .getxattr_fn = smb_full_audit_getxattr,
2228 .fgetxattr_fn = smb_full_audit_fgetxattr,
2229 .listxattr_fn = smb_full_audit_listxattr,
2230 .flistxattr_fn = smb_full_audit_flistxattr,
2231 .removexattr_fn = smb_full_audit_removexattr,
2232 .fremovexattr_fn = smb_full_audit_fremovexattr,
2233 .setxattr_fn = smb_full_audit_setxattr,
2234 .fsetxattr_fn = smb_full_audit_fsetxattr,
2235 .aio_force_fn = smb_full_audit_aio_force,
2236 .is_offline_fn = smb_full_audit_is_offline,
2237 .set_offline_fn = smb_full_audit_set_offline,
2240 NTSTATUS vfs_full_audit_init(void)
2242 NTSTATUS ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION,
2243 "full_audit", &vfs_full_audit_fns);
2245 if (!NT_STATUS_IS_OK(ret))
2246 return ret;
2248 vfs_full_audit_debug_level = debug_add_class("full_audit");
2249 if (vfs_full_audit_debug_level == -1) {
2250 vfs_full_audit_debug_level = DBGC_VFS;
2251 DEBUG(0, ("vfs_full_audit: Couldn't register custom debugging "
2252 "class!\n"));
2253 } else {
2254 DEBUG(10, ("vfs_full_audit: Debug class number of "
2255 "'full_audit': %d\n", vfs_full_audit_debug_level));
2258 return ret;