s3-vfs: Add pread_send/recv to vfs modules
[Samba/gebeck_regimport.git] / source3 / modules / vfs_full_audit.c
bloba1b1f4ef387759ec8e2f7ef489f420b7df1bac3a
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_LSEEK,
120 SMB_VFS_OP_SENDFILE,
121 SMB_VFS_OP_RECVFILE,
122 SMB_VFS_OP_RENAME,
123 SMB_VFS_OP_FSYNC,
124 SMB_VFS_OP_STAT,
125 SMB_VFS_OP_FSTAT,
126 SMB_VFS_OP_LSTAT,
127 SMB_VFS_OP_GET_ALLOC_SIZE,
128 SMB_VFS_OP_UNLINK,
129 SMB_VFS_OP_CHMOD,
130 SMB_VFS_OP_FCHMOD,
131 SMB_VFS_OP_CHOWN,
132 SMB_VFS_OP_FCHOWN,
133 SMB_VFS_OP_LCHOWN,
134 SMB_VFS_OP_CHDIR,
135 SMB_VFS_OP_GETWD,
136 SMB_VFS_OP_NTIMES,
137 SMB_VFS_OP_FTRUNCATE,
138 SMB_VFS_OP_FALLOCATE,
139 SMB_VFS_OP_LOCK,
140 SMB_VFS_OP_KERNEL_FLOCK,
141 SMB_VFS_OP_LINUX_SETLEASE,
142 SMB_VFS_OP_GETLOCK,
143 SMB_VFS_OP_SYMLINK,
144 SMB_VFS_OP_READLINK,
145 SMB_VFS_OP_LINK,
146 SMB_VFS_OP_MKNOD,
147 SMB_VFS_OP_REALPATH,
148 SMB_VFS_OP_NOTIFY_WATCH,
149 SMB_VFS_OP_CHFLAGS,
150 SMB_VFS_OP_FILE_ID_CREATE,
151 SMB_VFS_OP_STREAMINFO,
152 SMB_VFS_OP_GET_REAL_FILENAME,
153 SMB_VFS_OP_CONNECTPATH,
154 SMB_VFS_OP_BRL_LOCK_WINDOWS,
155 SMB_VFS_OP_BRL_UNLOCK_WINDOWS,
156 SMB_VFS_OP_BRL_CANCEL_WINDOWS,
157 SMB_VFS_OP_STRICT_LOCK,
158 SMB_VFS_OP_STRICT_UNLOCK,
159 SMB_VFS_OP_TRANSLATE_NAME,
161 /* NT ACL operations. */
163 SMB_VFS_OP_FGET_NT_ACL,
164 SMB_VFS_OP_GET_NT_ACL,
165 SMB_VFS_OP_FSET_NT_ACL,
167 /* POSIX ACL operations. */
169 SMB_VFS_OP_CHMOD_ACL,
170 SMB_VFS_OP_FCHMOD_ACL,
172 SMB_VFS_OP_SYS_ACL_GET_ENTRY,
173 SMB_VFS_OP_SYS_ACL_GET_TAG_TYPE,
174 SMB_VFS_OP_SYS_ACL_GET_PERMSET,
175 SMB_VFS_OP_SYS_ACL_GET_QUALIFIER,
176 SMB_VFS_OP_SYS_ACL_GET_FILE,
177 SMB_VFS_OP_SYS_ACL_GET_FD,
178 SMB_VFS_OP_SYS_ACL_CLEAR_PERMS,
179 SMB_VFS_OP_SYS_ACL_ADD_PERM,
180 SMB_VFS_OP_SYS_ACL_TO_TEXT,
181 SMB_VFS_OP_SYS_ACL_INIT,
182 SMB_VFS_OP_SYS_ACL_CREATE_ENTRY,
183 SMB_VFS_OP_SYS_ACL_SET_TAG_TYPE,
184 SMB_VFS_OP_SYS_ACL_SET_QUALIFIER,
185 SMB_VFS_OP_SYS_ACL_SET_PERMSET,
186 SMB_VFS_OP_SYS_ACL_VALID,
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,
190 SMB_VFS_OP_SYS_ACL_GET_PERM,
191 SMB_VFS_OP_SYS_ACL_FREE_TEXT,
192 SMB_VFS_OP_SYS_ACL_FREE_ACL,
193 SMB_VFS_OP_SYS_ACL_FREE_QUALIFIER,
195 /* EA operations. */
196 SMB_VFS_OP_GETXATTR,
197 SMB_VFS_OP_FGETXATTR,
198 SMB_VFS_OP_LISTXATTR,
199 SMB_VFS_OP_FLISTXATTR,
200 SMB_VFS_OP_REMOVEXATTR,
201 SMB_VFS_OP_FREMOVEXATTR,
202 SMB_VFS_OP_SETXATTR,
203 SMB_VFS_OP_FSETXATTR,
205 /* aio operations */
206 SMB_VFS_OP_AIO_READ,
207 SMB_VFS_OP_AIO_WRITE,
208 SMB_VFS_OP_AIO_RETURN,
209 SMB_VFS_OP_AIO_CANCEL,
210 SMB_VFS_OP_AIO_ERROR,
211 SMB_VFS_OP_AIO_FSYNC,
212 SMB_VFS_OP_AIO_SUSPEND,
213 SMB_VFS_OP_AIO_FORCE,
215 /* offline operations */
216 SMB_VFS_OP_IS_OFFLINE,
217 SMB_VFS_OP_SET_OFFLINE,
219 /* This should always be last enum value */
221 SMB_VFS_OP_LAST
222 } vfs_op_type;
224 /* The following array *must* be in the same order as defined in vfs.h */
226 static struct {
227 vfs_op_type type;
228 const char *name;
229 } vfs_op_names[] = {
230 { SMB_VFS_OP_CONNECT, "connect" },
231 { SMB_VFS_OP_DISCONNECT, "disconnect" },
232 { SMB_VFS_OP_DISK_FREE, "disk_free" },
233 { SMB_VFS_OP_GET_QUOTA, "get_quota" },
234 { SMB_VFS_OP_SET_QUOTA, "set_quota" },
235 { SMB_VFS_OP_GET_SHADOW_COPY_DATA, "get_shadow_copy_data" },
236 { SMB_VFS_OP_STATVFS, "statvfs" },
237 { SMB_VFS_OP_FS_CAPABILITIES, "fs_capabilities" },
238 { SMB_VFS_OP_OPENDIR, "opendir" },
239 { SMB_VFS_OP_FDOPENDIR, "fdopendir" },
240 { SMB_VFS_OP_READDIR, "readdir" },
241 { SMB_VFS_OP_SEEKDIR, "seekdir" },
242 { SMB_VFS_OP_TELLDIR, "telldir" },
243 { SMB_VFS_OP_REWINDDIR, "rewinddir" },
244 { SMB_VFS_OP_MKDIR, "mkdir" },
245 { SMB_VFS_OP_RMDIR, "rmdir" },
246 { SMB_VFS_OP_CLOSEDIR, "closedir" },
247 { SMB_VFS_OP_INIT_SEARCH_OP, "init_search_op" },
248 { SMB_VFS_OP_OPEN, "open" },
249 { SMB_VFS_OP_CREATE_FILE, "create_file" },
250 { SMB_VFS_OP_CLOSE, "close" },
251 { SMB_VFS_OP_READ, "read" },
252 { SMB_VFS_OP_PREAD, "pread" },
253 { SMB_VFS_OP_PREAD_SEND, "pread_send" },
254 { SMB_VFS_OP_PREAD_RECV, "pread_recv" },
255 { SMB_VFS_OP_WRITE, "write" },
256 { SMB_VFS_OP_PWRITE, "pwrite" },
257 { SMB_VFS_OP_LSEEK, "lseek" },
258 { SMB_VFS_OP_SENDFILE, "sendfile" },
259 { SMB_VFS_OP_RECVFILE, "recvfile" },
260 { SMB_VFS_OP_RENAME, "rename" },
261 { SMB_VFS_OP_FSYNC, "fsync" },
262 { SMB_VFS_OP_STAT, "stat" },
263 { SMB_VFS_OP_FSTAT, "fstat" },
264 { SMB_VFS_OP_LSTAT, "lstat" },
265 { SMB_VFS_OP_GET_ALLOC_SIZE, "get_alloc_size" },
266 { SMB_VFS_OP_UNLINK, "unlink" },
267 { SMB_VFS_OP_CHMOD, "chmod" },
268 { SMB_VFS_OP_FCHMOD, "fchmod" },
269 { SMB_VFS_OP_CHOWN, "chown" },
270 { SMB_VFS_OP_FCHOWN, "fchown" },
271 { SMB_VFS_OP_LCHOWN, "lchown" },
272 { SMB_VFS_OP_CHDIR, "chdir" },
273 { SMB_VFS_OP_GETWD, "getwd" },
274 { SMB_VFS_OP_NTIMES, "ntimes" },
275 { SMB_VFS_OP_FTRUNCATE, "ftruncate" },
276 { SMB_VFS_OP_FALLOCATE,"fallocate" },
277 { SMB_VFS_OP_LOCK, "lock" },
278 { SMB_VFS_OP_KERNEL_FLOCK, "kernel_flock" },
279 { SMB_VFS_OP_LINUX_SETLEASE, "linux_setlease" },
280 { SMB_VFS_OP_GETLOCK, "getlock" },
281 { SMB_VFS_OP_SYMLINK, "symlink" },
282 { SMB_VFS_OP_READLINK, "readlink" },
283 { SMB_VFS_OP_LINK, "link" },
284 { SMB_VFS_OP_MKNOD, "mknod" },
285 { SMB_VFS_OP_REALPATH, "realpath" },
286 { SMB_VFS_OP_NOTIFY_WATCH, "notify_watch" },
287 { SMB_VFS_OP_CHFLAGS, "chflags" },
288 { SMB_VFS_OP_FILE_ID_CREATE, "file_id_create" },
289 { SMB_VFS_OP_STREAMINFO, "streaminfo" },
290 { SMB_VFS_OP_GET_REAL_FILENAME, "get_real_filename" },
291 { SMB_VFS_OP_CONNECTPATH, "connectpath" },
292 { SMB_VFS_OP_BRL_LOCK_WINDOWS, "brl_lock_windows" },
293 { SMB_VFS_OP_BRL_UNLOCK_WINDOWS, "brl_unlock_windows" },
294 { SMB_VFS_OP_BRL_CANCEL_WINDOWS, "brl_cancel_windows" },
295 { SMB_VFS_OP_STRICT_LOCK, "strict_lock" },
296 { SMB_VFS_OP_STRICT_UNLOCK, "strict_unlock" },
297 { SMB_VFS_OP_TRANSLATE_NAME, "translate_name" },
298 { SMB_VFS_OP_FGET_NT_ACL, "fget_nt_acl" },
299 { SMB_VFS_OP_GET_NT_ACL, "get_nt_acl" },
300 { SMB_VFS_OP_FSET_NT_ACL, "fset_nt_acl" },
301 { SMB_VFS_OP_CHMOD_ACL, "chmod_acl" },
302 { SMB_VFS_OP_FCHMOD_ACL, "fchmod_acl" },
303 { SMB_VFS_OP_SYS_ACL_GET_ENTRY, "sys_acl_get_entry" },
304 { SMB_VFS_OP_SYS_ACL_GET_TAG_TYPE, "sys_acl_get_tag_type" },
305 { SMB_VFS_OP_SYS_ACL_GET_PERMSET, "sys_acl_get_permset" },
306 { SMB_VFS_OP_SYS_ACL_GET_QUALIFIER, "sys_acl_get_qualifier" },
307 { SMB_VFS_OP_SYS_ACL_GET_FILE, "sys_acl_get_file" },
308 { SMB_VFS_OP_SYS_ACL_GET_FD, "sys_acl_get_fd" },
309 { SMB_VFS_OP_SYS_ACL_CLEAR_PERMS, "sys_acl_clear_perms" },
310 { SMB_VFS_OP_SYS_ACL_ADD_PERM, "sys_acl_add_perm" },
311 { SMB_VFS_OP_SYS_ACL_TO_TEXT, "sys_acl_to_text" },
312 { SMB_VFS_OP_SYS_ACL_INIT, "sys_acl_init" },
313 { SMB_VFS_OP_SYS_ACL_CREATE_ENTRY, "sys_acl_create_entry" },
314 { SMB_VFS_OP_SYS_ACL_SET_TAG_TYPE, "sys_acl_set_tag_type" },
315 { SMB_VFS_OP_SYS_ACL_SET_QUALIFIER, "sys_acl_set_qualifier" },
316 { SMB_VFS_OP_SYS_ACL_SET_PERMSET, "sys_acl_set_permset" },
317 { SMB_VFS_OP_SYS_ACL_VALID, "sys_acl_valid" },
318 { SMB_VFS_OP_SYS_ACL_SET_FILE, "sys_acl_set_file" },
319 { SMB_VFS_OP_SYS_ACL_SET_FD, "sys_acl_set_fd" },
320 { SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE, "sys_acl_delete_def_file" },
321 { SMB_VFS_OP_SYS_ACL_GET_PERM, "sys_acl_get_perm" },
322 { SMB_VFS_OP_SYS_ACL_FREE_TEXT, "sys_acl_free_text" },
323 { SMB_VFS_OP_SYS_ACL_FREE_ACL, "sys_acl_free_acl" },
324 { SMB_VFS_OP_SYS_ACL_FREE_QUALIFIER, "sys_acl_free_qualifier" },
325 { SMB_VFS_OP_GETXATTR, "getxattr" },
326 { SMB_VFS_OP_FGETXATTR, "fgetxattr" },
327 { SMB_VFS_OP_LISTXATTR, "listxattr" },
328 { SMB_VFS_OP_FLISTXATTR, "flistxattr" },
329 { SMB_VFS_OP_REMOVEXATTR, "removexattr" },
330 { SMB_VFS_OP_FREMOVEXATTR, "fremovexattr" },
331 { SMB_VFS_OP_SETXATTR, "setxattr" },
332 { SMB_VFS_OP_FSETXATTR, "fsetxattr" },
333 { SMB_VFS_OP_AIO_READ, "aio_read" },
334 { SMB_VFS_OP_AIO_WRITE, "aio_write" },
335 { SMB_VFS_OP_AIO_RETURN,"aio_return" },
336 { SMB_VFS_OP_AIO_CANCEL,"aio_cancel" },
337 { SMB_VFS_OP_AIO_ERROR, "aio_error" },
338 { SMB_VFS_OP_AIO_FSYNC, "aio_fsync" },
339 { SMB_VFS_OP_AIO_SUSPEND,"aio_suspend" },
340 { SMB_VFS_OP_AIO_FORCE, "aio_force" },
341 { SMB_VFS_OP_IS_OFFLINE, "is_offline" },
342 { SMB_VFS_OP_SET_OFFLINE, "set_offline" },
343 { SMB_VFS_OP_LAST, NULL }
346 static int audit_syslog_facility(vfs_handle_struct *handle)
348 static const struct enum_list enum_log_facilities[] = {
349 { LOG_USER, "USER" },
350 { LOG_LOCAL0, "LOCAL0" },
351 { LOG_LOCAL1, "LOCAL1" },
352 { LOG_LOCAL2, "LOCAL2" },
353 { LOG_LOCAL3, "LOCAL3" },
354 { LOG_LOCAL4, "LOCAL4" },
355 { LOG_LOCAL5, "LOCAL5" },
356 { LOG_LOCAL6, "LOCAL6" },
357 { LOG_LOCAL7, "LOCAL7" },
358 { -1, NULL}
361 int facility;
363 facility = lp_parm_enum(SNUM(handle->conn), "full_audit", "facility", enum_log_facilities, LOG_USER);
365 return facility;
368 static int audit_syslog_priority(vfs_handle_struct *handle)
370 static const struct enum_list enum_log_priorities[] = {
371 { LOG_EMERG, "EMERG" },
372 { LOG_ALERT, "ALERT" },
373 { LOG_CRIT, "CRIT" },
374 { LOG_ERR, "ERR" },
375 { LOG_WARNING, "WARNING" },
376 { LOG_NOTICE, "NOTICE" },
377 { LOG_INFO, "INFO" },
378 { LOG_DEBUG, "DEBUG" },
379 { -1, NULL}
382 int priority;
384 priority = lp_parm_enum(SNUM(handle->conn), "full_audit", "priority",
385 enum_log_priorities, LOG_NOTICE);
386 if (priority == -1) {
387 priority = LOG_WARNING;
390 return priority;
393 static char *audit_prefix(TALLOC_CTX *ctx, connection_struct *conn)
395 char *prefix = NULL;
396 char *result;
398 prefix = talloc_strdup(ctx,
399 lp_parm_const_string(SNUM(conn), "full_audit",
400 "prefix", "%u|%I"));
401 if (!prefix) {
402 return NULL;
404 result = talloc_sub_advanced(ctx,
405 lp_servicename(talloc_tos(), SNUM(conn)),
406 conn->session_info->unix_info->unix_name,
407 conn->connectpath,
408 conn->session_info->unix_token->gid,
409 conn->session_info->unix_info->sanitized_username,
410 conn->session_info->info->domain_name,
411 prefix);
412 TALLOC_FREE(prefix);
413 return result;
416 static bool log_success(vfs_handle_struct *handle, vfs_op_type op)
418 struct vfs_full_audit_private_data *pd = NULL;
420 SMB_VFS_HANDLE_GET_DATA(handle, pd,
421 struct vfs_full_audit_private_data,
422 return True);
424 if (pd->success_ops == NULL) {
425 return True;
428 return bitmap_query(pd->success_ops, op);
431 static bool log_failure(vfs_handle_struct *handle, vfs_op_type op)
433 struct vfs_full_audit_private_data *pd = NULL;
435 SMB_VFS_HANDLE_GET_DATA(handle, pd,
436 struct vfs_full_audit_private_data,
437 return True);
439 if (pd->failure_ops == NULL)
440 return True;
442 return bitmap_query(pd->failure_ops, op);
445 static struct bitmap *init_bitmap(TALLOC_CTX *mem_ctx, const char **ops)
447 struct bitmap *bm;
449 if (ops == NULL) {
450 return NULL;
453 bm = bitmap_talloc(mem_ctx, SMB_VFS_OP_LAST);
454 if (bm == NULL) {
455 DEBUG(0, ("Could not alloc bitmap -- "
456 "defaulting to logging everything\n"));
457 return NULL;
460 for (; *ops != NULL; ops += 1) {
461 int i;
462 bool neg = false;
463 const char *op;
465 if (strequal(*ops, "all")) {
466 for (i=0; i<SMB_VFS_OP_LAST; i++) {
467 bitmap_set(bm, i);
469 continue;
472 if (strequal(*ops, "none")) {
473 break;
476 op = ops[0];
477 if (op[0] == '!') {
478 neg = true;
479 op += 1;
482 for (i=0; i<SMB_VFS_OP_LAST; i++) {
483 if (vfs_op_names[i].name == NULL) {
484 smb_panic("vfs_full_audit.c: name table not "
485 "in sync with vfs.h\n");
487 if (strequal(op, vfs_op_names[i].name)) {
488 if (neg) {
489 bitmap_clear(bm, i);
490 } else {
491 bitmap_set(bm, i);
493 break;
496 if (i == SMB_VFS_OP_LAST) {
497 DEBUG(0, ("Could not find opname %s, logging all\n",
498 *ops));
499 TALLOC_FREE(bm);
500 return NULL;
503 return bm;
506 static const char *audit_opname(vfs_op_type op)
508 if (op >= SMB_VFS_OP_LAST)
509 return "INVALID VFS OP";
510 return vfs_op_names[op].name;
513 static TALLOC_CTX *tmp_do_log_ctx;
515 * Get us a temporary talloc context usable just for DEBUG arguments
517 static TALLOC_CTX *do_log_ctx(void)
519 if (tmp_do_log_ctx == NULL) {
520 tmp_do_log_ctx = talloc_named_const(NULL, 0, "do_log_ctx");
522 return tmp_do_log_ctx;
525 static void do_log(vfs_op_type op, bool success, vfs_handle_struct *handle,
526 const char *format, ...)
528 fstring err_msg;
529 char *audit_pre = NULL;
530 va_list ap;
531 char *op_msg = NULL;
532 int priority;
534 if (success && (!log_success(handle, op)))
535 goto out;
537 if (!success && (!log_failure(handle, op)))
538 goto out;
540 if (success)
541 fstrcpy(err_msg, "ok");
542 else
543 fstr_sprintf(err_msg, "fail (%s)", strerror(errno));
545 va_start(ap, format);
546 op_msg = talloc_vasprintf(talloc_tos(), format, ap);
547 va_end(ap);
549 if (!op_msg) {
550 goto out;
554 * Specify the facility to interoperate with other syslog callers
555 * (smbd for example).
557 priority = audit_syslog_priority(handle) |
558 audit_syslog_facility(handle);
560 audit_pre = audit_prefix(talloc_tos(), handle->conn);
561 syslog(priority, "%s|%s|%s|%s\n",
562 audit_pre ? audit_pre : "",
563 audit_opname(op), err_msg, op_msg);
565 out:
566 TALLOC_FREE(audit_pre);
567 TALLOC_FREE(op_msg);
568 TALLOC_FREE(tmp_do_log_ctx);
570 return;
574 * Return a string using the do_log_ctx()
576 static const char *smb_fname_str_do_log(const struct smb_filename *smb_fname)
578 char *fname = NULL;
579 NTSTATUS status;
581 if (smb_fname == NULL) {
582 return "";
584 status = get_full_smb_filename(do_log_ctx(), smb_fname, &fname);
585 if (!NT_STATUS_IS_OK(status)) {
586 return "";
588 return fname;
592 * Return an fsp debug string using the do_log_ctx()
594 static const char *fsp_str_do_log(const struct files_struct *fsp)
596 return smb_fname_str_do_log(fsp->fsp_name);
599 /* Implementation of vfs_ops. Pass everything on to the default
600 operation but log event first. */
602 static int smb_full_audit_connect(vfs_handle_struct *handle,
603 const char *svc, const char *user)
605 int result;
606 struct vfs_full_audit_private_data *pd = NULL;
608 result = SMB_VFS_NEXT_CONNECT(handle, svc, user);
609 if (result < 0) {
610 return result;
613 pd = talloc_zero(handle, struct vfs_full_audit_private_data);
614 if (!pd) {
615 SMB_VFS_NEXT_DISCONNECT(handle);
616 return -1;
619 #ifdef WITH_SYSLOG
620 openlog("smbd_audit", 0, audit_syslog_facility(handle));
621 #endif
623 pd->success_ops = init_bitmap(
624 pd, lp_parm_string_list(SNUM(handle->conn), "full_audit",
625 "success", NULL));
626 pd->failure_ops = init_bitmap(
627 pd, lp_parm_string_list(SNUM(handle->conn), "full_audit",
628 "failure", NULL));
630 /* Store the private data. */
631 SMB_VFS_HANDLE_SET_DATA(handle, pd, NULL,
632 struct vfs_full_audit_private_data, return -1);
634 do_log(SMB_VFS_OP_CONNECT, True, handle,
635 "%s", svc);
637 return 0;
640 static void smb_full_audit_disconnect(vfs_handle_struct *handle)
642 SMB_VFS_NEXT_DISCONNECT(handle);
644 do_log(SMB_VFS_OP_DISCONNECT, True, handle,
645 "%s", lp_servicename(talloc_tos(), SNUM(handle->conn)));
647 /* The bitmaps will be disconnected when the private
648 data is deleted. */
650 return;
653 static uint64_t smb_full_audit_disk_free(vfs_handle_struct *handle,
654 const char *path,
655 bool small_query, uint64_t *bsize,
656 uint64_t *dfree, uint64_t *dsize)
658 uint64_t result;
660 result = SMB_VFS_NEXT_DISK_FREE(handle, path, small_query, bsize,
661 dfree, dsize);
663 /* Don't have a reasonable notion of failure here */
665 do_log(SMB_VFS_OP_DISK_FREE, True, handle, "%s", path);
667 return result;
670 static int smb_full_audit_get_quota(struct vfs_handle_struct *handle,
671 enum SMB_QUOTA_TYPE qtype, unid_t id,
672 SMB_DISK_QUOTA *qt)
674 int result;
676 result = SMB_VFS_NEXT_GET_QUOTA(handle, qtype, id, qt);
678 do_log(SMB_VFS_OP_GET_QUOTA, (result >= 0), handle, "");
680 return result;
684 static int smb_full_audit_set_quota(struct vfs_handle_struct *handle,
685 enum SMB_QUOTA_TYPE qtype, unid_t id,
686 SMB_DISK_QUOTA *qt)
688 int result;
690 result = SMB_VFS_NEXT_SET_QUOTA(handle, qtype, id, qt);
692 do_log(SMB_VFS_OP_SET_QUOTA, (result >= 0), handle, "");
694 return result;
697 static int smb_full_audit_get_shadow_copy_data(struct vfs_handle_struct *handle,
698 struct files_struct *fsp,
699 struct shadow_copy_data *shadow_copy_data,
700 bool labels)
702 int result;
704 result = SMB_VFS_NEXT_GET_SHADOW_COPY_DATA(handle, fsp, shadow_copy_data, labels);
706 do_log(SMB_VFS_OP_GET_SHADOW_COPY_DATA, (result >= 0), handle, "");
708 return result;
711 static int smb_full_audit_statvfs(struct vfs_handle_struct *handle,
712 const char *path,
713 struct vfs_statvfs_struct *statbuf)
715 int result;
717 result = SMB_VFS_NEXT_STATVFS(handle, path, statbuf);
719 do_log(SMB_VFS_OP_STATVFS, (result >= 0), handle, "");
721 return result;
724 static uint32_t smb_full_audit_fs_capabilities(struct vfs_handle_struct *handle, enum timestamp_set_resolution *p_ts_res)
726 int result;
728 result = SMB_VFS_NEXT_FS_CAPABILITIES(handle, p_ts_res);
730 do_log(SMB_VFS_OP_FS_CAPABILITIES, true, handle, "");
732 return result;
735 static DIR *smb_full_audit_opendir(vfs_handle_struct *handle,
736 const char *fname, const char *mask, uint32 attr)
738 DIR *result;
740 result = SMB_VFS_NEXT_OPENDIR(handle, fname, mask, attr);
742 do_log(SMB_VFS_OP_OPENDIR, (result != NULL), handle, "%s", fname);
744 return result;
747 static DIR *smb_full_audit_fdopendir(vfs_handle_struct *handle,
748 files_struct *fsp, const char *mask, uint32 attr)
750 DIR *result;
752 result = SMB_VFS_NEXT_FDOPENDIR(handle, fsp, mask, attr);
754 do_log(SMB_VFS_OP_FDOPENDIR, (result != NULL), handle, "%s",
755 fsp_str_do_log(fsp));
757 return result;
760 static struct dirent *smb_full_audit_readdir(vfs_handle_struct *handle,
761 DIR *dirp, SMB_STRUCT_STAT *sbuf)
763 struct dirent *result;
765 result = SMB_VFS_NEXT_READDIR(handle, dirp, sbuf);
767 /* This operation has no reasonable error condition
768 * (End of dir is also failure), so always succeed.
770 do_log(SMB_VFS_OP_READDIR, True, handle, "");
772 return result;
775 static void smb_full_audit_seekdir(vfs_handle_struct *handle,
776 DIR *dirp, long offset)
778 SMB_VFS_NEXT_SEEKDIR(handle, dirp, offset);
780 do_log(SMB_VFS_OP_SEEKDIR, True, handle, "");
781 return;
784 static long smb_full_audit_telldir(vfs_handle_struct *handle,
785 DIR *dirp)
787 long result;
789 result = SMB_VFS_NEXT_TELLDIR(handle, dirp);
791 do_log(SMB_VFS_OP_TELLDIR, True, handle, "");
793 return result;
796 static void smb_full_audit_rewinddir(vfs_handle_struct *handle,
797 DIR *dirp)
799 SMB_VFS_NEXT_REWINDDIR(handle, dirp);
801 do_log(SMB_VFS_OP_REWINDDIR, True, handle, "");
802 return;
805 static int smb_full_audit_mkdir(vfs_handle_struct *handle,
806 const char *path, mode_t mode)
808 int result;
810 result = SMB_VFS_NEXT_MKDIR(handle, path, mode);
812 do_log(SMB_VFS_OP_MKDIR, (result >= 0), handle, "%s", path);
814 return result;
817 static int smb_full_audit_rmdir(vfs_handle_struct *handle,
818 const char *path)
820 int result;
822 result = SMB_VFS_NEXT_RMDIR(handle, path);
824 do_log(SMB_VFS_OP_RMDIR, (result >= 0), handle, "%s", path);
826 return result;
829 static int smb_full_audit_closedir(vfs_handle_struct *handle,
830 DIR *dirp)
832 int result;
834 result = SMB_VFS_NEXT_CLOSEDIR(handle, dirp);
836 do_log(SMB_VFS_OP_CLOSEDIR, (result >= 0), handle, "");
838 return result;
841 static void smb_full_audit_init_search_op(vfs_handle_struct *handle,
842 DIR *dirp)
844 SMB_VFS_NEXT_INIT_SEARCH_OP(handle, dirp);
846 do_log(SMB_VFS_OP_INIT_SEARCH_OP, True, handle, "");
847 return;
850 static int smb_full_audit_open(vfs_handle_struct *handle,
851 struct smb_filename *smb_fname,
852 files_struct *fsp, int flags, mode_t mode)
854 int result;
856 result = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
858 do_log(SMB_VFS_OP_OPEN, (result >= 0), handle, "%s|%s",
859 ((flags & O_WRONLY) || (flags & O_RDWR))?"w":"r",
860 smb_fname_str_do_log(smb_fname));
862 return result;
865 static NTSTATUS smb_full_audit_create_file(vfs_handle_struct *handle,
866 struct smb_request *req,
867 uint16_t root_dir_fid,
868 struct smb_filename *smb_fname,
869 uint32_t access_mask,
870 uint32_t share_access,
871 uint32_t create_disposition,
872 uint32_t create_options,
873 uint32_t file_attributes,
874 uint32_t oplock_request,
875 uint64_t allocation_size,
876 uint32_t private_flags,
877 struct security_descriptor *sd,
878 struct ea_list *ea_list,
879 files_struct **result_fsp,
880 int *pinfo)
882 NTSTATUS result;
883 const char* str_create_disposition;
885 switch (create_disposition) {
886 case FILE_SUPERSEDE:
887 str_create_disposition = "supersede";
888 break;
889 case FILE_OVERWRITE_IF:
890 str_create_disposition = "overwrite_if";
891 break;
892 case FILE_OPEN:
893 str_create_disposition = "open";
894 break;
895 case FILE_OVERWRITE:
896 str_create_disposition = "overwrite";
897 break;
898 case FILE_CREATE:
899 str_create_disposition = "create";
900 break;
901 case FILE_OPEN_IF:
902 str_create_disposition = "open_if";
903 break;
904 default:
905 str_create_disposition = "unknown";
908 result = SMB_VFS_NEXT_CREATE_FILE(
909 handle, /* handle */
910 req, /* req */
911 root_dir_fid, /* root_dir_fid */
912 smb_fname, /* fname */
913 access_mask, /* access_mask */
914 share_access, /* share_access */
915 create_disposition, /* create_disposition*/
916 create_options, /* create_options */
917 file_attributes, /* file_attributes */
918 oplock_request, /* oplock_request */
919 allocation_size, /* allocation_size */
920 private_flags,
921 sd, /* sd */
922 ea_list, /* ea_list */
923 result_fsp, /* result */
924 pinfo); /* pinfo */
926 do_log(SMB_VFS_OP_CREATE_FILE, (NT_STATUS_IS_OK(result)), handle,
927 "0x%x|%s|%s|%s", access_mask,
928 create_options & FILE_DIRECTORY_FILE ? "dir" : "file",
929 str_create_disposition, smb_fname_str_do_log(smb_fname));
931 return result;
934 static int smb_full_audit_close(vfs_handle_struct *handle, files_struct *fsp)
936 int result;
938 result = SMB_VFS_NEXT_CLOSE(handle, fsp);
940 do_log(SMB_VFS_OP_CLOSE, (result >= 0), handle, "%s",
941 fsp_str_do_log(fsp));
943 return result;
946 static ssize_t smb_full_audit_read(vfs_handle_struct *handle, files_struct *fsp,
947 void *data, size_t n)
949 ssize_t result;
951 result = SMB_VFS_NEXT_READ(handle, fsp, data, n);
953 do_log(SMB_VFS_OP_READ, (result >= 0), handle, "%s",
954 fsp_str_do_log(fsp));
956 return result;
959 static ssize_t smb_full_audit_pread(vfs_handle_struct *handle, files_struct *fsp,
960 void *data, size_t n, off_t offset)
962 ssize_t result;
964 result = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
966 do_log(SMB_VFS_OP_PREAD, (result >= 0), handle, "%s",
967 fsp_str_do_log(fsp));
969 return result;
972 struct smb_full_audit_pread_state {
973 vfs_handle_struct *handle;
974 files_struct *fsp;
975 ssize_t ret;
976 int err;
979 static void smb_full_audit_pread_done(struct tevent_req *subreq);
981 static struct tevent_req *smb_full_audit_pread_send(
982 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
983 struct tevent_context *ev, struct files_struct *fsp,
984 void *data, size_t n, off_t offset)
986 struct tevent_req *req, *subreq;
987 struct smb_full_audit_pread_state *state;
989 req = tevent_req_create(mem_ctx, &state,
990 struct smb_full_audit_pread_state);
991 if (req == NULL) {
992 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
993 fsp_str_do_log(fsp));
994 return NULL;
996 state->handle = handle;
997 state->fsp = fsp;
999 subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
1000 n, offset);
1001 if (tevent_req_nomem(subreq, req)) {
1002 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
1003 fsp_str_do_log(fsp));
1004 return tevent_req_post(req, ev);
1006 tevent_req_set_callback(subreq, smb_full_audit_pread_done, req);
1008 do_log(SMB_VFS_OP_PREAD_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1009 return req;
1012 static void smb_full_audit_pread_done(struct tevent_req *subreq)
1014 struct tevent_req *req = tevent_req_callback_data(
1015 subreq, struct tevent_req);
1016 struct smb_full_audit_pread_state *state = tevent_req_data(
1017 req, struct smb_full_audit_pread_state);
1019 state->ret = SMB_VFS_PREAD_RECV(subreq, &state->err);
1020 TALLOC_FREE(subreq);
1021 tevent_req_done(req);
1024 static ssize_t smb_full_audit_pread_recv(struct tevent_req *req, int *err)
1026 struct smb_full_audit_pread_state *state = tevent_req_data(
1027 req, struct smb_full_audit_pread_state);
1029 if (tevent_req_is_unix_error(req, err)) {
1030 do_log(SMB_VFS_OP_PREAD_RECV, false, state->handle, "%s",
1031 fsp_str_do_log(state->fsp));
1032 return -1;
1035 do_log(SMB_VFS_OP_PREAD_RECV, (state->ret >= 0), state->handle, "%s",
1036 fsp_str_do_log(state->fsp));
1038 *err = state->err;
1039 return state->ret;
1042 static ssize_t smb_full_audit_write(vfs_handle_struct *handle, files_struct *fsp,
1043 const void *data, size_t n)
1045 ssize_t result;
1047 result = SMB_VFS_NEXT_WRITE(handle, fsp, data, n);
1049 do_log(SMB_VFS_OP_WRITE, (result >= 0), handle, "%s",
1050 fsp_str_do_log(fsp));
1052 return result;
1055 static ssize_t smb_full_audit_pwrite(vfs_handle_struct *handle, files_struct *fsp,
1056 const void *data, size_t n,
1057 off_t offset)
1059 ssize_t result;
1061 result = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
1063 do_log(SMB_VFS_OP_PWRITE, (result >= 0), handle, "%s",
1064 fsp_str_do_log(fsp));
1066 return result;
1069 static off_t smb_full_audit_lseek(vfs_handle_struct *handle, files_struct *fsp,
1070 off_t offset, int whence)
1072 ssize_t result;
1074 result = SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence);
1076 do_log(SMB_VFS_OP_LSEEK, (result != (ssize_t)-1), handle,
1077 "%s", fsp_str_do_log(fsp));
1079 return result;
1082 static ssize_t smb_full_audit_sendfile(vfs_handle_struct *handle, int tofd,
1083 files_struct *fromfsp,
1084 const DATA_BLOB *hdr, off_t offset,
1085 size_t n)
1087 ssize_t result;
1089 result = SMB_VFS_NEXT_SENDFILE(handle, tofd, fromfsp, hdr, offset, n);
1091 do_log(SMB_VFS_OP_SENDFILE, (result >= 0), handle,
1092 "%s", fsp_str_do_log(fromfsp));
1094 return result;
1097 static ssize_t smb_full_audit_recvfile(vfs_handle_struct *handle, int fromfd,
1098 files_struct *tofsp,
1099 off_t offset,
1100 size_t n)
1102 ssize_t result;
1104 result = SMB_VFS_NEXT_RECVFILE(handle, fromfd, tofsp, offset, n);
1106 do_log(SMB_VFS_OP_RECVFILE, (result >= 0), handle,
1107 "%s", fsp_str_do_log(tofsp));
1109 return result;
1112 static int smb_full_audit_rename(vfs_handle_struct *handle,
1113 const struct smb_filename *smb_fname_src,
1114 const struct smb_filename *smb_fname_dst)
1116 int result;
1118 result = SMB_VFS_NEXT_RENAME(handle, smb_fname_src, smb_fname_dst);
1120 do_log(SMB_VFS_OP_RENAME, (result >= 0), handle, "%s|%s",
1121 smb_fname_str_do_log(smb_fname_src),
1122 smb_fname_str_do_log(smb_fname_dst));
1124 return result;
1127 static int smb_full_audit_fsync(vfs_handle_struct *handle, files_struct *fsp)
1129 int result;
1131 result = SMB_VFS_NEXT_FSYNC(handle, fsp);
1133 do_log(SMB_VFS_OP_FSYNC, (result >= 0), handle, "%s",
1134 fsp_str_do_log(fsp));
1136 return result;
1139 static int smb_full_audit_stat(vfs_handle_struct *handle,
1140 struct smb_filename *smb_fname)
1142 int result;
1144 result = SMB_VFS_NEXT_STAT(handle, smb_fname);
1146 do_log(SMB_VFS_OP_STAT, (result >= 0), handle, "%s",
1147 smb_fname_str_do_log(smb_fname));
1149 return result;
1152 static int smb_full_audit_fstat(vfs_handle_struct *handle, files_struct *fsp,
1153 SMB_STRUCT_STAT *sbuf)
1155 int result;
1157 result = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1159 do_log(SMB_VFS_OP_FSTAT, (result >= 0), handle, "%s",
1160 fsp_str_do_log(fsp));
1162 return result;
1165 static int smb_full_audit_lstat(vfs_handle_struct *handle,
1166 struct smb_filename *smb_fname)
1168 int result;
1170 result = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
1172 do_log(SMB_VFS_OP_LSTAT, (result >= 0), handle, "%s",
1173 smb_fname_str_do_log(smb_fname));
1175 return result;
1178 static uint64_t smb_full_audit_get_alloc_size(vfs_handle_struct *handle,
1179 files_struct *fsp, const SMB_STRUCT_STAT *sbuf)
1181 uint64_t result;
1183 result = SMB_VFS_NEXT_GET_ALLOC_SIZE(handle, fsp, sbuf);
1185 do_log(SMB_VFS_OP_GET_ALLOC_SIZE, (result != (uint64_t)-1), handle,
1186 "%llu", result);
1188 return result;
1191 static int smb_full_audit_unlink(vfs_handle_struct *handle,
1192 const struct smb_filename *smb_fname)
1194 int result;
1196 result = SMB_VFS_NEXT_UNLINK(handle, smb_fname);
1198 do_log(SMB_VFS_OP_UNLINK, (result >= 0), handle, "%s",
1199 smb_fname_str_do_log(smb_fname));
1201 return result;
1204 static int smb_full_audit_chmod(vfs_handle_struct *handle,
1205 const char *path, mode_t mode)
1207 int result;
1209 result = SMB_VFS_NEXT_CHMOD(handle, path, mode);
1211 do_log(SMB_VFS_OP_CHMOD, (result >= 0), handle, "%s|%o", path, mode);
1213 return result;
1216 static int smb_full_audit_fchmod(vfs_handle_struct *handle, files_struct *fsp,
1217 mode_t mode)
1219 int result;
1221 result = SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1223 do_log(SMB_VFS_OP_FCHMOD, (result >= 0), handle,
1224 "%s|%o", fsp_str_do_log(fsp), mode);
1226 return result;
1229 static int smb_full_audit_chown(vfs_handle_struct *handle,
1230 const char *path, uid_t uid, gid_t gid)
1232 int result;
1234 result = SMB_VFS_NEXT_CHOWN(handle, path, uid, gid);
1236 do_log(SMB_VFS_OP_CHOWN, (result >= 0), handle, "%s|%ld|%ld",
1237 path, (long int)uid, (long int)gid);
1239 return result;
1242 static int smb_full_audit_fchown(vfs_handle_struct *handle, files_struct *fsp,
1243 uid_t uid, gid_t gid)
1245 int result;
1247 result = SMB_VFS_NEXT_FCHOWN(handle, fsp, uid, gid);
1249 do_log(SMB_VFS_OP_FCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1250 fsp_str_do_log(fsp), (long int)uid, (long int)gid);
1252 return result;
1255 static int smb_full_audit_lchown(vfs_handle_struct *handle,
1256 const char *path, uid_t uid, gid_t gid)
1258 int result;
1260 result = SMB_VFS_NEXT_LCHOWN(handle, path, uid, gid);
1262 do_log(SMB_VFS_OP_LCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1263 path, (long int)uid, (long int)gid);
1265 return result;
1268 static int smb_full_audit_chdir(vfs_handle_struct *handle,
1269 const char *path)
1271 int result;
1273 result = SMB_VFS_NEXT_CHDIR(handle, path);
1275 do_log(SMB_VFS_OP_CHDIR, (result >= 0), handle, "chdir|%s", path);
1277 return result;
1280 static char *smb_full_audit_getwd(vfs_handle_struct *handle)
1282 char *result;
1284 result = SMB_VFS_NEXT_GETWD(handle);
1286 do_log(SMB_VFS_OP_GETWD, (result != NULL), handle, "%s",
1287 result == NULL? "" : result);
1289 return result;
1292 static int smb_full_audit_ntimes(vfs_handle_struct *handle,
1293 const struct smb_filename *smb_fname,
1294 struct smb_file_time *ft)
1296 int result;
1298 result = SMB_VFS_NEXT_NTIMES(handle, smb_fname, ft);
1300 do_log(SMB_VFS_OP_NTIMES, (result >= 0), handle, "%s",
1301 smb_fname_str_do_log(smb_fname));
1303 return result;
1306 static int smb_full_audit_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
1307 off_t len)
1309 int result;
1311 result = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1313 do_log(SMB_VFS_OP_FTRUNCATE, (result >= 0), handle,
1314 "%s", fsp_str_do_log(fsp));
1316 return result;
1319 static int smb_full_audit_fallocate(vfs_handle_struct *handle, files_struct *fsp,
1320 enum vfs_fallocate_mode mode,
1321 off_t offset,
1322 off_t len)
1324 int result;
1326 result = SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
1328 do_log(SMB_VFS_OP_FALLOCATE, (result >= 0), handle,
1329 "%s", fsp_str_do_log(fsp));
1331 return result;
1334 static bool smb_full_audit_lock(vfs_handle_struct *handle, files_struct *fsp,
1335 int op, off_t offset, off_t count, int type)
1337 bool result;
1339 result = SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type);
1341 do_log(SMB_VFS_OP_LOCK, result, handle, "%s", fsp_str_do_log(fsp));
1343 return result;
1346 static int smb_full_audit_kernel_flock(struct vfs_handle_struct *handle,
1347 struct files_struct *fsp,
1348 uint32 share_mode, uint32 access_mask)
1350 int result;
1352 result = SMB_VFS_NEXT_KERNEL_FLOCK(handle, fsp, share_mode, access_mask);
1354 do_log(SMB_VFS_OP_KERNEL_FLOCK, (result >= 0), handle, "%s",
1355 fsp_str_do_log(fsp));
1357 return result;
1360 static int smb_full_audit_linux_setlease(vfs_handle_struct *handle, files_struct *fsp,
1361 int leasetype)
1363 int result;
1365 result = SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
1367 do_log(SMB_VFS_OP_LINUX_SETLEASE, (result >= 0), handle, "%s",
1368 fsp_str_do_log(fsp));
1370 return result;
1373 static bool smb_full_audit_getlock(vfs_handle_struct *handle, files_struct *fsp,
1374 off_t *poffset, off_t *pcount, int *ptype, pid_t *ppid)
1376 bool result;
1378 result = SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype, ppid);
1380 do_log(SMB_VFS_OP_GETLOCK, result, handle, "%s", fsp_str_do_log(fsp));
1382 return result;
1385 static int smb_full_audit_symlink(vfs_handle_struct *handle,
1386 const char *oldpath, const char *newpath)
1388 int result;
1390 result = SMB_VFS_NEXT_SYMLINK(handle, oldpath, newpath);
1392 do_log(SMB_VFS_OP_SYMLINK, (result >= 0), handle,
1393 "%s|%s", oldpath, newpath);
1395 return result;
1398 static int smb_full_audit_readlink(vfs_handle_struct *handle,
1399 const char *path, char *buf, size_t bufsiz)
1401 int result;
1403 result = SMB_VFS_NEXT_READLINK(handle, path, buf, bufsiz);
1405 do_log(SMB_VFS_OP_READLINK, (result >= 0), handle, "%s", path);
1407 return result;
1410 static int smb_full_audit_link(vfs_handle_struct *handle,
1411 const char *oldpath, const char *newpath)
1413 int result;
1415 result = SMB_VFS_NEXT_LINK(handle, oldpath, newpath);
1417 do_log(SMB_VFS_OP_LINK, (result >= 0), handle,
1418 "%s|%s", oldpath, newpath);
1420 return result;
1423 static int smb_full_audit_mknod(vfs_handle_struct *handle,
1424 const char *pathname, mode_t mode, SMB_DEV_T dev)
1426 int result;
1428 result = SMB_VFS_NEXT_MKNOD(handle, pathname, mode, dev);
1430 do_log(SMB_VFS_OP_MKNOD, (result >= 0), handle, "%s", pathname);
1432 return result;
1435 static char *smb_full_audit_realpath(vfs_handle_struct *handle,
1436 const char *path)
1438 char *result;
1440 result = SMB_VFS_NEXT_REALPATH(handle, path);
1442 do_log(SMB_VFS_OP_REALPATH, (result != NULL), handle, "%s", path);
1444 return result;
1447 static NTSTATUS smb_full_audit_notify_watch(struct vfs_handle_struct *handle,
1448 struct sys_notify_context *ctx,
1449 const char *path,
1450 uint32_t *filter,
1451 uint32_t *subdir_filter,
1452 void (*callback)(struct sys_notify_context *ctx,
1453 void *private_data,
1454 struct notify_event *ev),
1455 void *private_data, void *handle_p)
1457 NTSTATUS result;
1459 result = SMB_VFS_NEXT_NOTIFY_WATCH(handle, ctx, path,
1460 filter, subdir_filter, callback,
1461 private_data, handle_p);
1463 do_log(SMB_VFS_OP_NOTIFY_WATCH, NT_STATUS_IS_OK(result), handle, "");
1465 return result;
1468 static int smb_full_audit_chflags(vfs_handle_struct *handle,
1469 const char *path, unsigned int flags)
1471 int result;
1473 result = SMB_VFS_NEXT_CHFLAGS(handle, path, flags);
1475 do_log(SMB_VFS_OP_CHFLAGS, (result != 0), handle, "%s", path);
1477 return result;
1480 static struct file_id smb_full_audit_file_id_create(struct vfs_handle_struct *handle,
1481 const SMB_STRUCT_STAT *sbuf)
1483 struct file_id id_zero;
1484 struct file_id result;
1486 ZERO_STRUCT(id_zero);
1488 result = SMB_VFS_NEXT_FILE_ID_CREATE(handle, sbuf);
1490 do_log(SMB_VFS_OP_FILE_ID_CREATE,
1491 !file_id_equal(&id_zero, &result),
1492 handle, "%s", file_id_string_tos(&result));
1494 return result;
1497 static NTSTATUS smb_full_audit_streaminfo(vfs_handle_struct *handle,
1498 struct files_struct *fsp,
1499 const char *fname,
1500 TALLOC_CTX *mem_ctx,
1501 unsigned int *pnum_streams,
1502 struct stream_struct **pstreams)
1504 NTSTATUS result;
1506 result = SMB_VFS_NEXT_STREAMINFO(handle, fsp, fname, mem_ctx,
1507 pnum_streams, pstreams);
1509 do_log(SMB_VFS_OP_STREAMINFO, NT_STATUS_IS_OK(result), handle,
1510 "%s", fname);
1512 return result;
1515 static int smb_full_audit_get_real_filename(struct vfs_handle_struct *handle,
1516 const char *path,
1517 const char *name,
1518 TALLOC_CTX *mem_ctx,
1519 char **found_name)
1521 int result;
1523 result = SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name, mem_ctx,
1524 found_name);
1526 do_log(SMB_VFS_OP_GET_REAL_FILENAME, (result == 0), handle,
1527 "%s/%s->%s", path, name, (result == 0) ? "" : *found_name);
1529 return result;
1532 static const char *smb_full_audit_connectpath(vfs_handle_struct *handle,
1533 const char *fname)
1535 const char *result;
1537 result = SMB_VFS_NEXT_CONNECTPATH(handle, fname);
1539 do_log(SMB_VFS_OP_CONNECTPATH, result != NULL, handle,
1540 "%s", fname);
1542 return result;
1545 static NTSTATUS smb_full_audit_brl_lock_windows(struct vfs_handle_struct *handle,
1546 struct byte_range_lock *br_lck,
1547 struct lock_struct *plock,
1548 bool blocking_lock,
1549 struct blocking_lock_record *blr)
1551 NTSTATUS result;
1553 result = SMB_VFS_NEXT_BRL_LOCK_WINDOWS(handle, br_lck, plock,
1554 blocking_lock, blr);
1556 do_log(SMB_VFS_OP_BRL_LOCK_WINDOWS, NT_STATUS_IS_OK(result), handle,
1557 "%s:%llu-%llu. type=%d. blocking=%d", fsp_str_do_log(br_lck->fsp),
1558 plock->start, plock->size, plock->lock_type, blocking_lock );
1560 return result;
1563 static bool smb_full_audit_brl_unlock_windows(struct vfs_handle_struct *handle,
1564 struct messaging_context *msg_ctx,
1565 struct byte_range_lock *br_lck,
1566 const struct lock_struct *plock)
1568 bool result;
1570 result = SMB_VFS_NEXT_BRL_UNLOCK_WINDOWS(handle, msg_ctx, br_lck,
1571 plock);
1573 do_log(SMB_VFS_OP_BRL_UNLOCK_WINDOWS, (result == 0), handle,
1574 "%s:%llu-%llu:%d", fsp_str_do_log(br_lck->fsp), plock->start,
1575 plock->size, plock->lock_type);
1577 return result;
1580 static bool smb_full_audit_brl_cancel_windows(struct vfs_handle_struct *handle,
1581 struct byte_range_lock *br_lck,
1582 struct lock_struct *plock,
1583 struct blocking_lock_record *blr)
1585 bool result;
1587 result = SMB_VFS_NEXT_BRL_CANCEL_WINDOWS(handle, br_lck, plock, blr);
1589 do_log(SMB_VFS_OP_BRL_CANCEL_WINDOWS, (result == 0), handle,
1590 "%s:%llu-%llu:%d", fsp_str_do_log(br_lck->fsp), plock->start,
1591 plock->size);
1593 return result;
1596 static bool smb_full_audit_strict_lock(struct vfs_handle_struct *handle,
1597 struct files_struct *fsp,
1598 struct lock_struct *plock)
1600 bool result;
1602 result = SMB_VFS_NEXT_STRICT_LOCK(handle, fsp, plock);
1604 do_log(SMB_VFS_OP_STRICT_LOCK, result, handle,
1605 "%s:%llu-%llu:%d", fsp_str_do_log(fsp), plock->start,
1606 plock->size);
1608 return result;
1611 static void smb_full_audit_strict_unlock(struct vfs_handle_struct *handle,
1612 struct files_struct *fsp,
1613 struct lock_struct *plock)
1615 SMB_VFS_NEXT_STRICT_UNLOCK(handle, fsp, plock);
1617 do_log(SMB_VFS_OP_STRICT_UNLOCK, true, handle,
1618 "%s:%llu-%llu:%d", fsp_str_do_log(fsp), plock->start,
1619 plock->size);
1621 return;
1624 static NTSTATUS smb_full_audit_translate_name(struct vfs_handle_struct *handle,
1625 const char *name,
1626 enum vfs_translate_direction direction,
1627 TALLOC_CTX *mem_ctx,
1628 char **mapped_name)
1630 NTSTATUS result;
1632 result = SMB_VFS_NEXT_TRANSLATE_NAME(handle, name, direction, mem_ctx,
1633 mapped_name);
1635 do_log(SMB_VFS_OP_TRANSLATE_NAME, NT_STATUS_IS_OK(result), handle, "");
1637 return result;
1640 static NTSTATUS smb_full_audit_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
1641 uint32 security_info,
1642 struct security_descriptor **ppdesc)
1644 NTSTATUS result;
1646 result = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info, ppdesc);
1648 do_log(SMB_VFS_OP_FGET_NT_ACL, NT_STATUS_IS_OK(result), handle,
1649 "%s", fsp_str_do_log(fsp));
1651 return result;
1654 static NTSTATUS smb_full_audit_get_nt_acl(vfs_handle_struct *handle,
1655 const char *name,
1656 uint32 security_info,
1657 struct security_descriptor **ppdesc)
1659 NTSTATUS result;
1661 result = SMB_VFS_NEXT_GET_NT_ACL(handle, name, security_info, ppdesc);
1663 do_log(SMB_VFS_OP_GET_NT_ACL, NT_STATUS_IS_OK(result), handle,
1664 "%s", name);
1666 return result;
1669 static NTSTATUS smb_full_audit_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
1670 uint32 security_info_sent,
1671 const struct security_descriptor *psd)
1673 NTSTATUS result;
1675 result = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
1677 do_log(SMB_VFS_OP_FSET_NT_ACL, NT_STATUS_IS_OK(result), handle, "%s",
1678 fsp_str_do_log(fsp));
1680 return result;
1683 static int smb_full_audit_chmod_acl(vfs_handle_struct *handle,
1684 const char *path, mode_t mode)
1686 int result;
1688 result = SMB_VFS_NEXT_CHMOD_ACL(handle, path, mode);
1690 do_log(SMB_VFS_OP_CHMOD_ACL, (result >= 0), handle,
1691 "%s|%o", path, mode);
1693 return result;
1696 static int smb_full_audit_fchmod_acl(vfs_handle_struct *handle, files_struct *fsp,
1697 mode_t mode)
1699 int result;
1701 result = SMB_VFS_NEXT_FCHMOD_ACL(handle, fsp, mode);
1703 do_log(SMB_VFS_OP_FCHMOD_ACL, (result >= 0), handle,
1704 "%s|%o", fsp_str_do_log(fsp), mode);
1706 return result;
1709 static int smb_full_audit_sys_acl_get_entry(vfs_handle_struct *handle,
1711 SMB_ACL_T theacl, int entry_id,
1712 SMB_ACL_ENTRY_T *entry_p)
1714 int result;
1716 result = SMB_VFS_NEXT_SYS_ACL_GET_ENTRY(handle, theacl, entry_id,
1717 entry_p);
1719 do_log(SMB_VFS_OP_SYS_ACL_GET_ENTRY, (result >= 0), handle,
1720 "");
1722 return result;
1725 static int smb_full_audit_sys_acl_get_tag_type(vfs_handle_struct *handle,
1727 SMB_ACL_ENTRY_T entry_d,
1728 SMB_ACL_TAG_T *tag_type_p)
1730 int result;
1732 result = SMB_VFS_NEXT_SYS_ACL_GET_TAG_TYPE(handle, entry_d,
1733 tag_type_p);
1735 do_log(SMB_VFS_OP_SYS_ACL_GET_TAG_TYPE, (result >= 0), handle,
1736 "");
1738 return result;
1741 static int smb_full_audit_sys_acl_get_permset(vfs_handle_struct *handle,
1743 SMB_ACL_ENTRY_T entry_d,
1744 SMB_ACL_PERMSET_T *permset_p)
1746 int result;
1748 result = SMB_VFS_NEXT_SYS_ACL_GET_PERMSET(handle, entry_d,
1749 permset_p);
1751 do_log(SMB_VFS_OP_SYS_ACL_GET_PERMSET, (result >= 0), handle,
1752 "");
1754 return result;
1757 static void * smb_full_audit_sys_acl_get_qualifier(vfs_handle_struct *handle,
1759 SMB_ACL_ENTRY_T entry_d)
1761 void *result;
1763 result = SMB_VFS_NEXT_SYS_ACL_GET_QUALIFIER(handle, entry_d);
1765 do_log(SMB_VFS_OP_SYS_ACL_GET_QUALIFIER, (result != NULL), handle,
1766 "");
1768 return result;
1771 static SMB_ACL_T smb_full_audit_sys_acl_get_file(vfs_handle_struct *handle,
1772 const char *path_p,
1773 SMB_ACL_TYPE_T type)
1775 SMB_ACL_T result;
1777 result = SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, path_p, type);
1779 do_log(SMB_VFS_OP_SYS_ACL_GET_FILE, (result != NULL), handle,
1780 "%s", path_p);
1782 return result;
1785 static SMB_ACL_T smb_full_audit_sys_acl_get_fd(vfs_handle_struct *handle,
1786 files_struct *fsp)
1788 SMB_ACL_T result;
1790 result = SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp);
1792 do_log(SMB_VFS_OP_SYS_ACL_GET_FD, (result != NULL), handle,
1793 "%s", fsp_str_do_log(fsp));
1795 return result;
1798 static int smb_full_audit_sys_acl_clear_perms(vfs_handle_struct *handle,
1800 SMB_ACL_PERMSET_T permset)
1802 int result;
1804 result = SMB_VFS_NEXT_SYS_ACL_CLEAR_PERMS(handle, permset);
1806 do_log(SMB_VFS_OP_SYS_ACL_CLEAR_PERMS, (result >= 0), handle,
1807 "");
1809 return result;
1812 static int smb_full_audit_sys_acl_add_perm(vfs_handle_struct *handle,
1814 SMB_ACL_PERMSET_T permset,
1815 SMB_ACL_PERM_T perm)
1817 int result;
1819 result = SMB_VFS_NEXT_SYS_ACL_ADD_PERM(handle, permset, perm);
1821 do_log(SMB_VFS_OP_SYS_ACL_ADD_PERM, (result >= 0), handle,
1822 "");
1824 return result;
1827 static char * smb_full_audit_sys_acl_to_text(vfs_handle_struct *handle,
1828 SMB_ACL_T theacl,
1829 ssize_t *plen)
1831 char * result;
1833 result = SMB_VFS_NEXT_SYS_ACL_TO_TEXT(handle, theacl, plen);
1835 do_log(SMB_VFS_OP_SYS_ACL_TO_TEXT, (result != NULL), handle,
1836 "");
1838 return result;
1841 static SMB_ACL_T smb_full_audit_sys_acl_init(vfs_handle_struct *handle,
1843 int count)
1845 SMB_ACL_T result;
1847 result = SMB_VFS_NEXT_SYS_ACL_INIT(handle, count);
1849 do_log(SMB_VFS_OP_SYS_ACL_INIT, (result != NULL), handle,
1850 "");
1852 return result;
1855 static int smb_full_audit_sys_acl_create_entry(vfs_handle_struct *handle,
1856 SMB_ACL_T *pacl,
1857 SMB_ACL_ENTRY_T *pentry)
1859 int result;
1861 result = SMB_VFS_NEXT_SYS_ACL_CREATE_ENTRY(handle, pacl, pentry);
1863 do_log(SMB_VFS_OP_SYS_ACL_CREATE_ENTRY, (result >= 0), handle,
1864 "");
1866 return result;
1869 static int smb_full_audit_sys_acl_set_tag_type(vfs_handle_struct *handle,
1871 SMB_ACL_ENTRY_T entry,
1872 SMB_ACL_TAG_T tagtype)
1874 int result;
1876 result = SMB_VFS_NEXT_SYS_ACL_SET_TAG_TYPE(handle, entry,
1877 tagtype);
1879 do_log(SMB_VFS_OP_SYS_ACL_SET_TAG_TYPE, (result >= 0), handle,
1880 "");
1882 return result;
1885 static int smb_full_audit_sys_acl_set_qualifier(vfs_handle_struct *handle,
1887 SMB_ACL_ENTRY_T entry,
1888 void *qual)
1890 int result;
1892 result = SMB_VFS_NEXT_SYS_ACL_SET_QUALIFIER(handle, entry, qual);
1894 do_log(SMB_VFS_OP_SYS_ACL_SET_QUALIFIER, (result >= 0), handle,
1895 "");
1897 return result;
1900 static int smb_full_audit_sys_acl_set_permset(vfs_handle_struct *handle,
1902 SMB_ACL_ENTRY_T entry,
1903 SMB_ACL_PERMSET_T permset)
1905 int result;
1907 result = SMB_VFS_NEXT_SYS_ACL_SET_PERMSET(handle, entry, permset);
1909 do_log(SMB_VFS_OP_SYS_ACL_SET_PERMSET, (result >= 0), handle,
1910 "");
1912 return result;
1915 static int smb_full_audit_sys_acl_valid(vfs_handle_struct *handle,
1917 SMB_ACL_T theacl )
1919 int result;
1921 result = SMB_VFS_NEXT_SYS_ACL_VALID(handle, theacl);
1923 do_log(SMB_VFS_OP_SYS_ACL_VALID, (result >= 0), handle,
1924 "");
1926 return result;
1929 static int smb_full_audit_sys_acl_set_file(vfs_handle_struct *handle,
1931 const char *name, SMB_ACL_TYPE_T acltype,
1932 SMB_ACL_T theacl)
1934 int result;
1936 result = SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, name, acltype,
1937 theacl);
1939 do_log(SMB_VFS_OP_SYS_ACL_SET_FILE, (result >= 0), handle,
1940 "%s", name);
1942 return result;
1945 static int smb_full_audit_sys_acl_set_fd(vfs_handle_struct *handle, files_struct *fsp,
1946 SMB_ACL_T theacl)
1948 int result;
1950 result = SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, theacl);
1952 do_log(SMB_VFS_OP_SYS_ACL_SET_FD, (result >= 0), handle,
1953 "%s", fsp_str_do_log(fsp));
1955 return result;
1958 static int smb_full_audit_sys_acl_delete_def_file(vfs_handle_struct *handle,
1960 const char *path)
1962 int result;
1964 result = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, path);
1966 do_log(SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE, (result >= 0), handle,
1967 "%s", path);
1969 return result;
1972 static int smb_full_audit_sys_acl_get_perm(vfs_handle_struct *handle,
1974 SMB_ACL_PERMSET_T permset,
1975 SMB_ACL_PERM_T perm)
1977 int result;
1979 result = SMB_VFS_NEXT_SYS_ACL_GET_PERM(handle, permset, perm);
1981 do_log(SMB_VFS_OP_SYS_ACL_GET_PERM, (result >= 0), handle,
1982 "");
1984 return result;
1987 static int smb_full_audit_sys_acl_free_text(vfs_handle_struct *handle,
1989 char *text)
1991 int result;
1993 result = SMB_VFS_NEXT_SYS_ACL_FREE_TEXT(handle, text);
1995 do_log(SMB_VFS_OP_SYS_ACL_FREE_TEXT, (result >= 0), handle,
1996 "");
1998 return result;
2001 static int smb_full_audit_sys_acl_free_acl(vfs_handle_struct *handle,
2003 SMB_ACL_T posix_acl)
2005 int result;
2007 result = SMB_VFS_NEXT_SYS_ACL_FREE_ACL(handle, posix_acl);
2009 do_log(SMB_VFS_OP_SYS_ACL_FREE_ACL, (result >= 0), handle,
2010 "");
2012 return result;
2015 static int smb_full_audit_sys_acl_free_qualifier(vfs_handle_struct *handle,
2016 void *qualifier,
2017 SMB_ACL_TAG_T tagtype)
2019 int result;
2021 result = SMB_VFS_NEXT_SYS_ACL_FREE_QUALIFIER(handle, qualifier,
2022 tagtype);
2024 do_log(SMB_VFS_OP_SYS_ACL_FREE_QUALIFIER, (result >= 0), handle,
2025 "");
2027 return result;
2030 static ssize_t smb_full_audit_getxattr(struct vfs_handle_struct *handle,
2031 const char *path,
2032 const char *name, void *value, size_t size)
2034 ssize_t result;
2036 result = SMB_VFS_NEXT_GETXATTR(handle, path, name, value, size);
2038 do_log(SMB_VFS_OP_GETXATTR, (result >= 0), handle,
2039 "%s|%s", path, name);
2041 return result;
2044 static ssize_t smb_full_audit_fgetxattr(struct vfs_handle_struct *handle,
2045 struct files_struct *fsp,
2046 const char *name, void *value, size_t size)
2048 ssize_t result;
2050 result = SMB_VFS_NEXT_FGETXATTR(handle, fsp, name, value, size);
2052 do_log(SMB_VFS_OP_FGETXATTR, (result >= 0), handle,
2053 "%s|%s", fsp_str_do_log(fsp), name);
2055 return result;
2058 static ssize_t smb_full_audit_listxattr(struct vfs_handle_struct *handle,
2059 const char *path, char *list, size_t size)
2061 ssize_t result;
2063 result = SMB_VFS_NEXT_LISTXATTR(handle, path, list, size);
2065 do_log(SMB_VFS_OP_LISTXATTR, (result >= 0), handle, "%s", path);
2067 return result;
2070 static ssize_t smb_full_audit_flistxattr(struct vfs_handle_struct *handle,
2071 struct files_struct *fsp, char *list,
2072 size_t size)
2074 ssize_t result;
2076 result = SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
2078 do_log(SMB_VFS_OP_FLISTXATTR, (result >= 0), handle,
2079 "%s", fsp_str_do_log(fsp));
2081 return result;
2084 static int smb_full_audit_removexattr(struct vfs_handle_struct *handle,
2085 const char *path,
2086 const char *name)
2088 int result;
2090 result = SMB_VFS_NEXT_REMOVEXATTR(handle, path, name);
2092 do_log(SMB_VFS_OP_REMOVEXATTR, (result >= 0), handle,
2093 "%s|%s", path, name);
2095 return result;
2098 static int smb_full_audit_fremovexattr(struct vfs_handle_struct *handle,
2099 struct files_struct *fsp,
2100 const char *name)
2102 int result;
2104 result = SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, name);
2106 do_log(SMB_VFS_OP_FREMOVEXATTR, (result >= 0), handle,
2107 "%s|%s", fsp_str_do_log(fsp), name);
2109 return result;
2112 static int smb_full_audit_setxattr(struct vfs_handle_struct *handle,
2113 const char *path,
2114 const char *name, const void *value, size_t size,
2115 int flags)
2117 int result;
2119 result = SMB_VFS_NEXT_SETXATTR(handle, path, name, value, size,
2120 flags);
2122 do_log(SMB_VFS_OP_SETXATTR, (result >= 0), handle,
2123 "%s|%s", path, name);
2125 return result;
2128 static int smb_full_audit_fsetxattr(struct vfs_handle_struct *handle,
2129 struct files_struct *fsp, const char *name,
2130 const void *value, size_t size, int flags)
2132 int result;
2134 result = SMB_VFS_NEXT_FSETXATTR(handle, fsp, name, value, size, flags);
2136 do_log(SMB_VFS_OP_FSETXATTR, (result >= 0), handle,
2137 "%s|%s", fsp_str_do_log(fsp), name);
2139 return result;
2142 static int smb_full_audit_aio_read(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
2144 int result;
2146 result = SMB_VFS_NEXT_AIO_READ(handle, fsp, aiocb);
2147 do_log(SMB_VFS_OP_AIO_READ, (result >= 0), handle,
2148 "%s", fsp_str_do_log(fsp));
2150 return result;
2153 static int smb_full_audit_aio_write(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
2155 int result;
2157 result = SMB_VFS_NEXT_AIO_WRITE(handle, fsp, aiocb);
2158 do_log(SMB_VFS_OP_AIO_WRITE, (result >= 0), handle,
2159 "%s", fsp_str_do_log(fsp));
2161 return result;
2164 static ssize_t smb_full_audit_aio_return(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
2166 int result;
2168 result = SMB_VFS_NEXT_AIO_RETURN(handle, fsp, aiocb);
2169 do_log(SMB_VFS_OP_AIO_RETURN, (result >= 0), handle,
2170 "%s", fsp_str_do_log(fsp));
2172 return result;
2175 static int smb_full_audit_aio_cancel(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
2177 int result;
2179 result = SMB_VFS_NEXT_AIO_CANCEL(handle, fsp, aiocb);
2180 do_log(SMB_VFS_OP_AIO_CANCEL, (result >= 0), handle,
2181 "%s", fsp_str_do_log(fsp));
2183 return result;
2186 static int smb_full_audit_aio_error(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
2188 int result;
2190 result = SMB_VFS_NEXT_AIO_ERROR(handle, fsp, aiocb);
2191 do_log(SMB_VFS_OP_AIO_ERROR, (result >= 0), handle,
2192 "%s", fsp_str_do_log(fsp));
2194 return result;
2197 static int smb_full_audit_aio_fsync(struct vfs_handle_struct *handle, struct files_struct *fsp, int op, SMB_STRUCT_AIOCB *aiocb)
2199 int result;
2201 result = SMB_VFS_NEXT_AIO_FSYNC(handle, fsp, op, aiocb);
2202 do_log(SMB_VFS_OP_AIO_FSYNC, (result >= 0), handle,
2203 "%s", fsp_str_do_log(fsp));
2205 return result;
2208 static int smb_full_audit_aio_suspend(struct vfs_handle_struct *handle, struct files_struct *fsp, const SMB_STRUCT_AIOCB * const aiocb[], int n, const struct timespec *ts)
2210 int result;
2212 result = SMB_VFS_NEXT_AIO_SUSPEND(handle, fsp, aiocb, n, ts);
2213 do_log(SMB_VFS_OP_AIO_SUSPEND, (result >= 0), handle,
2214 "%s", fsp_str_do_log(fsp));
2216 return result;
2219 static bool smb_full_audit_aio_force(struct vfs_handle_struct *handle,
2220 struct files_struct *fsp)
2222 bool result;
2224 result = SMB_VFS_NEXT_AIO_FORCE(handle, fsp);
2225 do_log(SMB_VFS_OP_AIO_FORCE, result, handle,
2226 "%s", fsp_str_do_log(fsp));
2228 return result;
2231 static bool smb_full_audit_is_offline(struct vfs_handle_struct *handle,
2232 const struct smb_filename *fname,
2233 SMB_STRUCT_STAT *sbuf)
2235 bool result;
2237 result = SMB_VFS_NEXT_IS_OFFLINE(handle, fname, sbuf);
2238 do_log(SMB_VFS_OP_IS_OFFLINE, result, handle, "%s",
2239 smb_fname_str_do_log(fname));
2240 return result;
2243 static int smb_full_audit_set_offline(struct vfs_handle_struct *handle,
2244 const struct smb_filename *fname)
2246 int result;
2248 result = SMB_VFS_NEXT_SET_OFFLINE(handle, fname);
2249 do_log(SMB_VFS_OP_SET_OFFLINE, result >= 0, handle, "%s",
2250 smb_fname_str_do_log(fname));
2251 return result;
2254 static struct vfs_fn_pointers vfs_full_audit_fns = {
2256 /* Disk operations */
2258 .connect_fn = smb_full_audit_connect,
2259 .disconnect_fn = smb_full_audit_disconnect,
2260 .disk_free_fn = smb_full_audit_disk_free,
2261 .get_quota_fn = smb_full_audit_get_quota,
2262 .set_quota_fn = smb_full_audit_set_quota,
2263 .get_shadow_copy_data_fn = smb_full_audit_get_shadow_copy_data,
2264 .statvfs_fn = smb_full_audit_statvfs,
2265 .fs_capabilities_fn = smb_full_audit_fs_capabilities,
2266 .opendir_fn = smb_full_audit_opendir,
2267 .fdopendir_fn = smb_full_audit_fdopendir,
2268 .readdir_fn = smb_full_audit_readdir,
2269 .seekdir_fn = smb_full_audit_seekdir,
2270 .telldir_fn = smb_full_audit_telldir,
2271 .rewind_dir_fn = smb_full_audit_rewinddir,
2272 .mkdir_fn = smb_full_audit_mkdir,
2273 .rmdir_fn = smb_full_audit_rmdir,
2274 .closedir_fn = smb_full_audit_closedir,
2275 .init_search_op_fn = smb_full_audit_init_search_op,
2276 .open_fn = smb_full_audit_open,
2277 .create_file_fn = smb_full_audit_create_file,
2278 .close_fn = smb_full_audit_close,
2279 .read_fn = smb_full_audit_read,
2280 .pread_fn = smb_full_audit_pread,
2281 .pread_send_fn = smb_full_audit_pread_send,
2282 .pread_recv_fn = smb_full_audit_pread_recv,
2283 .write_fn = smb_full_audit_write,
2284 .pwrite_fn = smb_full_audit_pwrite,
2285 .lseek_fn = smb_full_audit_lseek,
2286 .sendfile_fn = smb_full_audit_sendfile,
2287 .recvfile_fn = smb_full_audit_recvfile,
2288 .rename_fn = smb_full_audit_rename,
2289 .fsync_fn = smb_full_audit_fsync,
2290 .stat_fn = smb_full_audit_stat,
2291 .fstat_fn = smb_full_audit_fstat,
2292 .lstat_fn = smb_full_audit_lstat,
2293 .get_alloc_size_fn = smb_full_audit_get_alloc_size,
2294 .unlink_fn = smb_full_audit_unlink,
2295 .chmod_fn = smb_full_audit_chmod,
2296 .fchmod_fn = smb_full_audit_fchmod,
2297 .chown_fn = smb_full_audit_chown,
2298 .fchown_fn = smb_full_audit_fchown,
2299 .lchown_fn = smb_full_audit_lchown,
2300 .chdir_fn = smb_full_audit_chdir,
2301 .getwd_fn = smb_full_audit_getwd,
2302 .ntimes_fn = smb_full_audit_ntimes,
2303 .ftruncate_fn = smb_full_audit_ftruncate,
2304 .fallocate_fn = smb_full_audit_fallocate,
2305 .lock_fn = smb_full_audit_lock,
2306 .kernel_flock_fn = smb_full_audit_kernel_flock,
2307 .linux_setlease_fn = smb_full_audit_linux_setlease,
2308 .getlock_fn = smb_full_audit_getlock,
2309 .symlink_fn = smb_full_audit_symlink,
2310 .readlink_fn = smb_full_audit_readlink,
2311 .link_fn = smb_full_audit_link,
2312 .mknod_fn = smb_full_audit_mknod,
2313 .realpath_fn = smb_full_audit_realpath,
2314 .notify_watch_fn = smb_full_audit_notify_watch,
2315 .chflags_fn = smb_full_audit_chflags,
2316 .file_id_create_fn = smb_full_audit_file_id_create,
2317 .streaminfo_fn = smb_full_audit_streaminfo,
2318 .get_real_filename_fn = smb_full_audit_get_real_filename,
2319 .connectpath_fn = smb_full_audit_connectpath,
2320 .brl_lock_windows_fn = smb_full_audit_brl_lock_windows,
2321 .brl_unlock_windows_fn = smb_full_audit_brl_unlock_windows,
2322 .brl_cancel_windows_fn = smb_full_audit_brl_cancel_windows,
2323 .strict_lock_fn = smb_full_audit_strict_lock,
2324 .strict_unlock_fn = smb_full_audit_strict_unlock,
2325 .translate_name_fn = smb_full_audit_translate_name,
2326 .fget_nt_acl_fn = smb_full_audit_fget_nt_acl,
2327 .get_nt_acl_fn = smb_full_audit_get_nt_acl,
2328 .fset_nt_acl_fn = smb_full_audit_fset_nt_acl,
2329 .chmod_acl_fn = smb_full_audit_chmod_acl,
2330 .fchmod_acl_fn = smb_full_audit_fchmod_acl,
2331 .sys_acl_get_entry_fn = smb_full_audit_sys_acl_get_entry,
2332 .sys_acl_get_tag_type_fn = smb_full_audit_sys_acl_get_tag_type,
2333 .sys_acl_get_permset_fn = smb_full_audit_sys_acl_get_permset,
2334 .sys_acl_get_qualifier_fn = smb_full_audit_sys_acl_get_qualifier,
2335 .sys_acl_get_file_fn = smb_full_audit_sys_acl_get_file,
2336 .sys_acl_get_fd_fn = smb_full_audit_sys_acl_get_fd,
2337 .sys_acl_clear_perms_fn = smb_full_audit_sys_acl_clear_perms,
2338 .sys_acl_add_perm_fn = smb_full_audit_sys_acl_add_perm,
2339 .sys_acl_to_text_fn = smb_full_audit_sys_acl_to_text,
2340 .sys_acl_init_fn = smb_full_audit_sys_acl_init,
2341 .sys_acl_create_entry_fn = smb_full_audit_sys_acl_create_entry,
2342 .sys_acl_set_tag_type_fn = smb_full_audit_sys_acl_set_tag_type,
2343 .sys_acl_set_qualifier_fn = smb_full_audit_sys_acl_set_qualifier,
2344 .sys_acl_set_permset_fn = smb_full_audit_sys_acl_set_permset,
2345 .sys_acl_valid_fn = smb_full_audit_sys_acl_valid,
2346 .sys_acl_set_file_fn = smb_full_audit_sys_acl_set_file,
2347 .sys_acl_set_fd_fn = smb_full_audit_sys_acl_set_fd,
2348 .sys_acl_delete_def_file_fn = smb_full_audit_sys_acl_delete_def_file,
2349 .sys_acl_get_perm_fn = smb_full_audit_sys_acl_get_perm,
2350 .sys_acl_free_text_fn = smb_full_audit_sys_acl_free_text,
2351 .sys_acl_free_acl_fn = smb_full_audit_sys_acl_free_acl,
2352 .sys_acl_free_qualifier_fn = smb_full_audit_sys_acl_free_qualifier,
2353 .getxattr_fn = smb_full_audit_getxattr,
2354 .fgetxattr_fn = smb_full_audit_fgetxattr,
2355 .listxattr_fn = smb_full_audit_listxattr,
2356 .flistxattr_fn = smb_full_audit_flistxattr,
2357 .removexattr_fn = smb_full_audit_removexattr,
2358 .fremovexattr_fn = smb_full_audit_fremovexattr,
2359 .setxattr_fn = smb_full_audit_setxattr,
2360 .fsetxattr_fn = smb_full_audit_fsetxattr,
2361 .aio_read_fn = smb_full_audit_aio_read,
2362 .aio_write_fn = smb_full_audit_aio_write,
2363 .aio_return_fn = smb_full_audit_aio_return,
2364 .aio_cancel_fn = smb_full_audit_aio_cancel,
2365 .aio_error_fn = smb_full_audit_aio_error,
2366 .aio_fsync_fn = smb_full_audit_aio_fsync,
2367 .aio_suspend_fn = smb_full_audit_aio_suspend,
2368 .aio_force_fn = smb_full_audit_aio_force,
2369 .is_offline_fn = smb_full_audit_is_offline,
2370 .set_offline_fn = smb_full_audit_set_offline,
2373 NTSTATUS vfs_full_audit_init(void)
2375 NTSTATUS ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION,
2376 "full_audit", &vfs_full_audit_fns);
2378 if (!NT_STATUS_IS_OK(ret))
2379 return ret;
2381 vfs_full_audit_debug_level = debug_add_class("full_audit");
2382 if (vfs_full_audit_debug_level == -1) {
2383 vfs_full_audit_debug_level = DBGC_VFS;
2384 DEBUG(0, ("vfs_full_audit: Couldn't register custom debugging "
2385 "class!\n"));
2386 } else {
2387 DEBUG(10, ("vfs_full_audit: Debug class number of "
2388 "'full_audit': %d\n", vfs_full_audit_debug_level));
2391 return ret;