s3: Lift the server_messaging_context from send_spoolss_notify2_msg
[Samba/gbeck.git] / source3 / modules / vfs_full_audit.c
blob23ca1496bf8348dc8b007d0b37446cba711d2fe6
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 "../librpc/gen_ndr/ndr_netlogon.h"
63 static int vfs_full_audit_debug_level = DBGC_VFS;
65 struct vfs_full_audit_private_data {
66 struct bitmap *success_ops;
67 struct bitmap *failure_ops;
70 #undef DBGC_CLASS
71 #define DBGC_CLASS vfs_full_audit_debug_level
73 typedef enum _vfs_op_type {
74 SMB_VFS_OP_NOOP = -1,
76 /* Disk operations */
78 SMB_VFS_OP_CONNECT = 0,
79 SMB_VFS_OP_DISCONNECT,
80 SMB_VFS_OP_DISK_FREE,
81 SMB_VFS_OP_GET_QUOTA,
82 SMB_VFS_OP_SET_QUOTA,
83 SMB_VFS_OP_GET_SHADOW_COPY_DATA,
84 SMB_VFS_OP_STATVFS,
85 SMB_VFS_OP_FS_CAPABILITIES,
87 /* Directory operations */
89 SMB_VFS_OP_OPENDIR,
90 SMB_VFS_OP_READDIR,
91 SMB_VFS_OP_SEEKDIR,
92 SMB_VFS_OP_TELLDIR,
93 SMB_VFS_OP_REWINDDIR,
94 SMB_VFS_OP_MKDIR,
95 SMB_VFS_OP_RMDIR,
96 SMB_VFS_OP_CLOSEDIR,
97 SMB_VFS_OP_INIT_SEARCH_OP,
99 /* File operations */
101 SMB_VFS_OP_OPEN,
102 SMB_VFS_OP_CREATE_FILE,
103 SMB_VFS_OP_CLOSE,
104 SMB_VFS_OP_READ,
105 SMB_VFS_OP_PREAD,
106 SMB_VFS_OP_WRITE,
107 SMB_VFS_OP_PWRITE,
108 SMB_VFS_OP_LSEEK,
109 SMB_VFS_OP_SENDFILE,
110 SMB_VFS_OP_RECVFILE,
111 SMB_VFS_OP_RENAME,
112 SMB_VFS_OP_FSYNC,
113 SMB_VFS_OP_STAT,
114 SMB_VFS_OP_FSTAT,
115 SMB_VFS_OP_LSTAT,
116 SMB_VFS_OP_GET_ALLOC_SIZE,
117 SMB_VFS_OP_UNLINK,
118 SMB_VFS_OP_CHMOD,
119 SMB_VFS_OP_FCHMOD,
120 SMB_VFS_OP_CHOWN,
121 SMB_VFS_OP_FCHOWN,
122 SMB_VFS_OP_LCHOWN,
123 SMB_VFS_OP_CHDIR,
124 SMB_VFS_OP_GETWD,
125 SMB_VFS_OP_NTIMES,
126 SMB_VFS_OP_FTRUNCATE,
127 SMB_VFS_OP_LOCK,
128 SMB_VFS_OP_KERNEL_FLOCK,
129 SMB_VFS_OP_LINUX_SETLEASE,
130 SMB_VFS_OP_GETLOCK,
131 SMB_VFS_OP_SYMLINK,
132 SMB_VFS_OP_READLINK,
133 SMB_VFS_OP_LINK,
134 SMB_VFS_OP_MKNOD,
135 SMB_VFS_OP_REALPATH,
136 SMB_VFS_OP_NOTIFY_WATCH,
137 SMB_VFS_OP_CHFLAGS,
138 SMB_VFS_OP_FILE_ID_CREATE,
139 SMB_VFS_OP_STREAMINFO,
140 SMB_VFS_OP_GET_REAL_FILENAME,
141 SMB_VFS_OP_CONNECTPATH,
142 SMB_VFS_OP_BRL_LOCK_WINDOWS,
143 SMB_VFS_OP_BRL_UNLOCK_WINDOWS,
144 SMB_VFS_OP_BRL_CANCEL_WINDOWS,
145 SMB_VFS_OP_STRICT_LOCK,
146 SMB_VFS_OP_STRICT_UNLOCK,
147 SMB_VFS_OP_TRANSLATE_NAME,
149 /* NT ACL operations. */
151 SMB_VFS_OP_FGET_NT_ACL,
152 SMB_VFS_OP_GET_NT_ACL,
153 SMB_VFS_OP_FSET_NT_ACL,
155 /* POSIX ACL operations. */
157 SMB_VFS_OP_CHMOD_ACL,
158 SMB_VFS_OP_FCHMOD_ACL,
160 SMB_VFS_OP_SYS_ACL_GET_ENTRY,
161 SMB_VFS_OP_SYS_ACL_GET_TAG_TYPE,
162 SMB_VFS_OP_SYS_ACL_GET_PERMSET,
163 SMB_VFS_OP_SYS_ACL_GET_QUALIFIER,
164 SMB_VFS_OP_SYS_ACL_GET_FILE,
165 SMB_VFS_OP_SYS_ACL_GET_FD,
166 SMB_VFS_OP_SYS_ACL_CLEAR_PERMS,
167 SMB_VFS_OP_SYS_ACL_ADD_PERM,
168 SMB_VFS_OP_SYS_ACL_TO_TEXT,
169 SMB_VFS_OP_SYS_ACL_INIT,
170 SMB_VFS_OP_SYS_ACL_CREATE_ENTRY,
171 SMB_VFS_OP_SYS_ACL_SET_TAG_TYPE,
172 SMB_VFS_OP_SYS_ACL_SET_QUALIFIER,
173 SMB_VFS_OP_SYS_ACL_SET_PERMSET,
174 SMB_VFS_OP_SYS_ACL_VALID,
175 SMB_VFS_OP_SYS_ACL_SET_FILE,
176 SMB_VFS_OP_SYS_ACL_SET_FD,
177 SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE,
178 SMB_VFS_OP_SYS_ACL_GET_PERM,
179 SMB_VFS_OP_SYS_ACL_FREE_TEXT,
180 SMB_VFS_OP_SYS_ACL_FREE_ACL,
181 SMB_VFS_OP_SYS_ACL_FREE_QUALIFIER,
183 /* EA operations. */
184 SMB_VFS_OP_GETXATTR,
185 SMB_VFS_OP_LGETXATTR,
186 SMB_VFS_OP_FGETXATTR,
187 SMB_VFS_OP_LISTXATTR,
188 SMB_VFS_OP_LLISTXATTR,
189 SMB_VFS_OP_FLISTXATTR,
190 SMB_VFS_OP_REMOVEXATTR,
191 SMB_VFS_OP_LREMOVEXATTR,
192 SMB_VFS_OP_FREMOVEXATTR,
193 SMB_VFS_OP_SETXATTR,
194 SMB_VFS_OP_LSETXATTR,
195 SMB_VFS_OP_FSETXATTR,
197 /* aio operations */
198 SMB_VFS_OP_AIO_READ,
199 SMB_VFS_OP_AIO_WRITE,
200 SMB_VFS_OP_AIO_RETURN,
201 SMB_VFS_OP_AIO_CANCEL,
202 SMB_VFS_OP_AIO_ERROR,
203 SMB_VFS_OP_AIO_FSYNC,
204 SMB_VFS_OP_AIO_SUSPEND,
205 SMB_VFS_OP_AIO_FORCE,
207 /* offline operations */
208 SMB_VFS_OP_IS_OFFLINE,
209 SMB_VFS_OP_SET_OFFLINE,
211 /* This should always be last enum value */
213 SMB_VFS_OP_LAST
214 } vfs_op_type;
216 /* The following array *must* be in the same order as defined in vfs.h */
218 static struct {
219 vfs_op_type type;
220 const char *name;
221 } vfs_op_names[] = {
222 { SMB_VFS_OP_CONNECT, "connect" },
223 { SMB_VFS_OP_DISCONNECT, "disconnect" },
224 { SMB_VFS_OP_DISK_FREE, "disk_free" },
225 { SMB_VFS_OP_GET_QUOTA, "get_quota" },
226 { SMB_VFS_OP_SET_QUOTA, "set_quota" },
227 { SMB_VFS_OP_GET_SHADOW_COPY_DATA, "get_shadow_copy_data" },
228 { SMB_VFS_OP_STATVFS, "statvfs" },
229 { SMB_VFS_OP_FS_CAPABILITIES, "fs_capabilities" },
230 { SMB_VFS_OP_OPENDIR, "opendir" },
231 { SMB_VFS_OP_READDIR, "readdir" },
232 { SMB_VFS_OP_SEEKDIR, "seekdir" },
233 { SMB_VFS_OP_TELLDIR, "telldir" },
234 { SMB_VFS_OP_REWINDDIR, "rewinddir" },
235 { SMB_VFS_OP_MKDIR, "mkdir" },
236 { SMB_VFS_OP_RMDIR, "rmdir" },
237 { SMB_VFS_OP_CLOSEDIR, "closedir" },
238 { SMB_VFS_OP_INIT_SEARCH_OP, "init_search_op" },
239 { SMB_VFS_OP_OPEN, "open" },
240 { SMB_VFS_OP_CREATE_FILE, "create_file" },
241 { SMB_VFS_OP_CLOSE, "close" },
242 { SMB_VFS_OP_READ, "read" },
243 { SMB_VFS_OP_PREAD, "pread" },
244 { SMB_VFS_OP_WRITE, "write" },
245 { SMB_VFS_OP_PWRITE, "pwrite" },
246 { SMB_VFS_OP_LSEEK, "lseek" },
247 { SMB_VFS_OP_SENDFILE, "sendfile" },
248 { SMB_VFS_OP_RECVFILE, "recvfile" },
249 { SMB_VFS_OP_RENAME, "rename" },
250 { SMB_VFS_OP_FSYNC, "fsync" },
251 { SMB_VFS_OP_STAT, "stat" },
252 { SMB_VFS_OP_FSTAT, "fstat" },
253 { SMB_VFS_OP_LSTAT, "lstat" },
254 { SMB_VFS_OP_GET_ALLOC_SIZE, "get_alloc_size" },
255 { SMB_VFS_OP_UNLINK, "unlink" },
256 { SMB_VFS_OP_CHMOD, "chmod" },
257 { SMB_VFS_OP_FCHMOD, "fchmod" },
258 { SMB_VFS_OP_CHOWN, "chown" },
259 { SMB_VFS_OP_FCHOWN, "fchown" },
260 { SMB_VFS_OP_LCHOWN, "lchown" },
261 { SMB_VFS_OP_CHDIR, "chdir" },
262 { SMB_VFS_OP_GETWD, "getwd" },
263 { SMB_VFS_OP_NTIMES, "ntimes" },
264 { SMB_VFS_OP_FTRUNCATE, "ftruncate" },
265 { SMB_VFS_OP_LOCK, "lock" },
266 { SMB_VFS_OP_KERNEL_FLOCK, "kernel_flock" },
267 { SMB_VFS_OP_LINUX_SETLEASE, "linux_setlease" },
268 { SMB_VFS_OP_GETLOCK, "getlock" },
269 { SMB_VFS_OP_SYMLINK, "symlink" },
270 { SMB_VFS_OP_READLINK, "readlink" },
271 { SMB_VFS_OP_LINK, "link" },
272 { SMB_VFS_OP_MKNOD, "mknod" },
273 { SMB_VFS_OP_REALPATH, "realpath" },
274 { SMB_VFS_OP_NOTIFY_WATCH, "notify_watch" },
275 { SMB_VFS_OP_CHFLAGS, "chflags" },
276 { SMB_VFS_OP_FILE_ID_CREATE, "file_id_create" },
277 { SMB_VFS_OP_STREAMINFO, "streaminfo" },
278 { SMB_VFS_OP_GET_REAL_FILENAME, "get_real_filename" },
279 { SMB_VFS_OP_CONNECTPATH, "connectpath" },
280 { SMB_VFS_OP_BRL_LOCK_WINDOWS, "brl_lock_windows" },
281 { SMB_VFS_OP_BRL_UNLOCK_WINDOWS, "brl_unlock_windows" },
282 { SMB_VFS_OP_BRL_CANCEL_WINDOWS, "brl_cancel_windows" },
283 { SMB_VFS_OP_STRICT_LOCK, "strict_lock" },
284 { SMB_VFS_OP_STRICT_UNLOCK, "strict_unlock" },
285 { SMB_VFS_OP_TRANSLATE_NAME, "translate_name" },
286 { SMB_VFS_OP_FGET_NT_ACL, "fget_nt_acl" },
287 { SMB_VFS_OP_GET_NT_ACL, "get_nt_acl" },
288 { SMB_VFS_OP_FSET_NT_ACL, "fset_nt_acl" },
289 { SMB_VFS_OP_CHMOD_ACL, "chmod_acl" },
290 { SMB_VFS_OP_FCHMOD_ACL, "fchmod_acl" },
291 { SMB_VFS_OP_SYS_ACL_GET_ENTRY, "sys_acl_get_entry" },
292 { SMB_VFS_OP_SYS_ACL_GET_TAG_TYPE, "sys_acl_get_tag_type" },
293 { SMB_VFS_OP_SYS_ACL_GET_PERMSET, "sys_acl_get_permset" },
294 { SMB_VFS_OP_SYS_ACL_GET_QUALIFIER, "sys_acl_get_qualifier" },
295 { SMB_VFS_OP_SYS_ACL_GET_FILE, "sys_acl_get_file" },
296 { SMB_VFS_OP_SYS_ACL_GET_FD, "sys_acl_get_fd" },
297 { SMB_VFS_OP_SYS_ACL_CLEAR_PERMS, "sys_acl_clear_perms" },
298 { SMB_VFS_OP_SYS_ACL_ADD_PERM, "sys_acl_add_perm" },
299 { SMB_VFS_OP_SYS_ACL_TO_TEXT, "sys_acl_to_text" },
300 { SMB_VFS_OP_SYS_ACL_INIT, "sys_acl_init" },
301 { SMB_VFS_OP_SYS_ACL_CREATE_ENTRY, "sys_acl_create_entry" },
302 { SMB_VFS_OP_SYS_ACL_SET_TAG_TYPE, "sys_acl_set_tag_type" },
303 { SMB_VFS_OP_SYS_ACL_SET_QUALIFIER, "sys_acl_set_qualifier" },
304 { SMB_VFS_OP_SYS_ACL_SET_PERMSET, "sys_acl_set_permset" },
305 { SMB_VFS_OP_SYS_ACL_VALID, "sys_acl_valid" },
306 { SMB_VFS_OP_SYS_ACL_SET_FILE, "sys_acl_set_file" },
307 { SMB_VFS_OP_SYS_ACL_SET_FD, "sys_acl_set_fd" },
308 { SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE, "sys_acl_delete_def_file" },
309 { SMB_VFS_OP_SYS_ACL_GET_PERM, "sys_acl_get_perm" },
310 { SMB_VFS_OP_SYS_ACL_FREE_TEXT, "sys_acl_free_text" },
311 { SMB_VFS_OP_SYS_ACL_FREE_ACL, "sys_acl_free_acl" },
312 { SMB_VFS_OP_SYS_ACL_FREE_QUALIFIER, "sys_acl_free_qualifier" },
313 { SMB_VFS_OP_GETXATTR, "getxattr" },
314 { SMB_VFS_OP_LGETXATTR, "lgetxattr" },
315 { SMB_VFS_OP_FGETXATTR, "fgetxattr" },
316 { SMB_VFS_OP_LISTXATTR, "listxattr" },
317 { SMB_VFS_OP_LLISTXATTR, "llistxattr" },
318 { SMB_VFS_OP_FLISTXATTR, "flistxattr" },
319 { SMB_VFS_OP_REMOVEXATTR, "removexattr" },
320 { SMB_VFS_OP_LREMOVEXATTR, "lremovexattr" },
321 { SMB_VFS_OP_FREMOVEXATTR, "fremovexattr" },
322 { SMB_VFS_OP_SETXATTR, "setxattr" },
323 { SMB_VFS_OP_LSETXATTR, "lsetxattr" },
324 { SMB_VFS_OP_FSETXATTR, "fsetxattr" },
325 { SMB_VFS_OP_AIO_READ, "aio_read" },
326 { SMB_VFS_OP_AIO_WRITE, "aio_write" },
327 { SMB_VFS_OP_AIO_RETURN,"aio_return" },
328 { SMB_VFS_OP_AIO_CANCEL,"aio_cancel" },
329 { SMB_VFS_OP_AIO_ERROR, "aio_error" },
330 { SMB_VFS_OP_AIO_FSYNC, "aio_fsync" },
331 { SMB_VFS_OP_AIO_SUSPEND,"aio_suspend" },
332 { SMB_VFS_OP_AIO_FORCE, "aio_force" },
333 { SMB_VFS_OP_IS_OFFLINE, "aio_is_offline" },
334 { SMB_VFS_OP_SET_OFFLINE, "aio_set_offline" },
335 { SMB_VFS_OP_LAST, NULL }
338 static int audit_syslog_facility(vfs_handle_struct *handle)
340 static const struct enum_list enum_log_facilities[] = {
341 { LOG_USER, "USER" },
342 { LOG_LOCAL0, "LOCAL0" },
343 { LOG_LOCAL1, "LOCAL1" },
344 { LOG_LOCAL2, "LOCAL2" },
345 { LOG_LOCAL3, "LOCAL3" },
346 { LOG_LOCAL4, "LOCAL4" },
347 { LOG_LOCAL5, "LOCAL5" },
348 { LOG_LOCAL6, "LOCAL6" },
349 { LOG_LOCAL7, "LOCAL7" }
352 int facility;
354 facility = lp_parm_enum(SNUM(handle->conn), "full_audit", "facility", enum_log_facilities, LOG_USER);
356 return facility;
359 static int audit_syslog_priority(vfs_handle_struct *handle)
361 static const struct enum_list enum_log_priorities[] = {
362 { LOG_EMERG, "EMERG" },
363 { LOG_ALERT, "ALERT" },
364 { LOG_CRIT, "CRIT" },
365 { LOG_ERR, "ERR" },
366 { LOG_WARNING, "WARNING" },
367 { LOG_NOTICE, "NOTICE" },
368 { LOG_INFO, "INFO" },
369 { LOG_DEBUG, "DEBUG" }
372 int priority;
374 priority = lp_parm_enum(SNUM(handle->conn), "full_audit", "priority",
375 enum_log_priorities, LOG_NOTICE);
376 if (priority == -1) {
377 priority = LOG_WARNING;
380 return priority;
383 static char *audit_prefix(TALLOC_CTX *ctx, connection_struct *conn)
385 char *prefix = NULL;
386 char *result;
388 prefix = talloc_strdup(ctx,
389 lp_parm_const_string(SNUM(conn), "full_audit",
390 "prefix", "%u|%I"));
391 if (!prefix) {
392 return NULL;
394 result = talloc_sub_advanced(ctx,
395 lp_servicename(SNUM(conn)),
396 conn->server_info->unix_name,
397 conn->connectpath,
398 conn->server_info->utok.gid,
399 conn->server_info->sanitized_username,
400 conn->server_info->info3->base.domain.string,
401 prefix);
402 TALLOC_FREE(prefix);
403 return result;
406 static bool log_success(vfs_handle_struct *handle, vfs_op_type op)
408 struct vfs_full_audit_private_data *pd = NULL;
410 SMB_VFS_HANDLE_GET_DATA(handle, pd,
411 struct vfs_full_audit_private_data,
412 return True);
414 if (pd->success_ops == NULL) {
415 return True;
418 return bitmap_query(pd->success_ops, op);
421 static bool log_failure(vfs_handle_struct *handle, vfs_op_type op)
423 struct vfs_full_audit_private_data *pd = NULL;
425 SMB_VFS_HANDLE_GET_DATA(handle, pd,
426 struct vfs_full_audit_private_data,
427 return True);
429 if (pd->failure_ops == NULL)
430 return True;
432 return bitmap_query(pd->failure_ops, op);
435 static struct bitmap *init_bitmap(TALLOC_CTX *mem_ctx, const char **ops)
437 struct bitmap *bm;
439 if (ops == NULL) {
440 return NULL;
443 bm = bitmap_talloc(mem_ctx, SMB_VFS_OP_LAST);
444 if (bm == NULL) {
445 DEBUG(0, ("Could not alloc bitmap -- "
446 "defaulting to logging everything\n"));
447 return NULL;
450 for (; *ops != NULL; ops += 1) {
451 int i;
452 bool neg = false;
453 const char *op;
455 if (strequal(*ops, "all")) {
456 for (i=0; i<SMB_VFS_OP_LAST; i++) {
457 bitmap_set(bm, i);
459 continue;
462 if (strequal(*ops, "none")) {
463 break;
466 op = ops[0];
467 if (op[0] == '!') {
468 neg = true;
469 op += 1;
472 for (i=0; i<SMB_VFS_OP_LAST; i++) {
473 if (vfs_op_names[i].name == NULL) {
474 smb_panic("vfs_full_audit.c: name table not "
475 "in sync with vfs.h\n");
477 if (strequal(op, vfs_op_names[i].name)) {
478 if (neg) {
479 bitmap_clear(bm, i);
480 } else {
481 bitmap_set(bm, i);
483 break;
486 if (i == SMB_VFS_OP_LAST) {
487 DEBUG(0, ("Could not find opname %s, logging all\n",
488 *ops));
489 TALLOC_FREE(bm);
490 return NULL;
493 return bm;
496 static const char *audit_opname(vfs_op_type op)
498 if (op >= SMB_VFS_OP_LAST)
499 return "INVALID VFS OP";
500 return vfs_op_names[op].name;
503 static TALLOC_CTX *tmp_do_log_ctx;
505 * Get us a temporary talloc context usable just for DEBUG arguments
507 static TALLOC_CTX *do_log_ctx(void)
509 if (tmp_do_log_ctx == NULL) {
510 tmp_do_log_ctx = talloc_named_const(NULL, 0, "do_log_ctx");
512 return tmp_do_log_ctx;
515 static void do_log(vfs_op_type op, bool success, vfs_handle_struct *handle,
516 const char *format, ...)
518 fstring err_msg;
519 char *audit_pre = NULL;
520 va_list ap;
521 char *op_msg = NULL;
522 int priority;
524 if (success && (!log_success(handle, op)))
525 goto out;
527 if (!success && (!log_failure(handle, op)))
528 goto out;
530 if (success)
531 fstrcpy(err_msg, "ok");
532 else
533 fstr_sprintf(err_msg, "fail (%s)", strerror(errno));
535 va_start(ap, format);
536 op_msg = talloc_vasprintf(talloc_tos(), format, ap);
537 va_end(ap);
539 if (!op_msg) {
540 goto out;
544 * Specify the facility to interoperate with other syslog callers
545 * (smbd for example).
547 priority = audit_syslog_priority(handle) |
548 audit_syslog_facility(handle);
550 audit_pre = audit_prefix(talloc_tos(), handle->conn);
551 syslog(priority, "%s|%s|%s|%s\n",
552 audit_pre ? audit_pre : "",
553 audit_opname(op), err_msg, op_msg);
555 out:
556 TALLOC_FREE(audit_pre);
557 TALLOC_FREE(op_msg);
558 TALLOC_FREE(tmp_do_log_ctx);
560 return;
564 * Return a string using the do_log_ctx()
566 static const char *smb_fname_str_do_log(const struct smb_filename *smb_fname)
568 char *fname = NULL;
569 NTSTATUS status;
571 if (smb_fname == NULL) {
572 return "";
574 status = get_full_smb_filename(do_log_ctx(), smb_fname, &fname);
575 if (!NT_STATUS_IS_OK(status)) {
576 return "";
578 return fname;
582 * Return an fsp debug string using the do_log_ctx()
584 static const char *fsp_str_do_log(const struct files_struct *fsp)
586 return smb_fname_str_do_log(fsp->fsp_name);
589 /* Implementation of vfs_ops. Pass everything on to the default
590 operation but log event first. */
592 static int smb_full_audit_connect(vfs_handle_struct *handle,
593 const char *svc, const char *user)
595 int result;
596 struct vfs_full_audit_private_data *pd = NULL;
598 result = SMB_VFS_NEXT_CONNECT(handle, svc, user);
599 if (result < 0) {
600 return result;
603 pd = TALLOC_ZERO_P(handle, struct vfs_full_audit_private_data);
604 if (!pd) {
605 SMB_VFS_NEXT_DISCONNECT(handle);
606 return -1;
609 #ifndef WITH_SYSLOG
610 openlog("smbd_audit", 0, audit_syslog_facility(handle));
611 #endif
613 pd->success_ops = init_bitmap(
614 pd, lp_parm_string_list(SNUM(handle->conn), "full_audit",
615 "success", NULL));
616 pd->failure_ops = init_bitmap(
617 pd, lp_parm_string_list(SNUM(handle->conn), "full_audit",
618 "failure", NULL));
620 /* Store the private data. */
621 SMB_VFS_HANDLE_SET_DATA(handle, pd, NULL,
622 struct vfs_full_audit_private_data, return -1);
624 do_log(SMB_VFS_OP_CONNECT, True, handle,
625 "%s", svc);
627 return 0;
630 static void smb_full_audit_disconnect(vfs_handle_struct *handle)
632 SMB_VFS_NEXT_DISCONNECT(handle);
634 do_log(SMB_VFS_OP_DISCONNECT, True, handle,
635 "%s", lp_servicename(SNUM(handle->conn)));
637 /* The bitmaps will be disconnected when the private
638 data is deleted. */
640 return;
643 static uint64_t smb_full_audit_disk_free(vfs_handle_struct *handle,
644 const char *path,
645 bool small_query, uint64_t *bsize,
646 uint64_t *dfree, uint64_t *dsize)
648 uint64_t result;
650 result = SMB_VFS_NEXT_DISK_FREE(handle, path, small_query, bsize,
651 dfree, dsize);
653 /* Don't have a reasonable notion of failure here */
655 do_log(SMB_VFS_OP_DISK_FREE, True, handle, "%s", path);
657 return result;
660 static int smb_full_audit_get_quota(struct vfs_handle_struct *handle,
661 enum SMB_QUOTA_TYPE qtype, unid_t id,
662 SMB_DISK_QUOTA *qt)
664 int result;
666 result = SMB_VFS_NEXT_GET_QUOTA(handle, qtype, id, qt);
668 do_log(SMB_VFS_OP_GET_QUOTA, (result >= 0), handle, "");
670 return result;
674 static int smb_full_audit_set_quota(struct vfs_handle_struct *handle,
675 enum SMB_QUOTA_TYPE qtype, unid_t id,
676 SMB_DISK_QUOTA *qt)
678 int result;
680 result = SMB_VFS_NEXT_SET_QUOTA(handle, qtype, id, qt);
682 do_log(SMB_VFS_OP_SET_QUOTA, (result >= 0), handle, "");
684 return result;
687 static int smb_full_audit_get_shadow_copy_data(struct vfs_handle_struct *handle,
688 struct files_struct *fsp,
689 SHADOW_COPY_DATA *shadow_copy_data, bool labels)
691 int result;
693 result = SMB_VFS_NEXT_GET_SHADOW_COPY_DATA(handle, fsp, shadow_copy_data, labels);
695 do_log(SMB_VFS_OP_GET_SHADOW_COPY_DATA, (result >= 0), handle, "");
697 return result;
700 static int smb_full_audit_statvfs(struct vfs_handle_struct *handle,
701 const char *path,
702 struct vfs_statvfs_struct *statbuf)
704 int result;
706 result = SMB_VFS_NEXT_STATVFS(handle, path, statbuf);
708 do_log(SMB_VFS_OP_STATVFS, (result >= 0), handle, "");
710 return result;
713 static uint32_t smb_full_audit_fs_capabilities(struct vfs_handle_struct *handle, enum timestamp_set_resolution *p_ts_res)
715 int result;
717 result = SMB_VFS_NEXT_FS_CAPABILITIES(handle, p_ts_res);
719 do_log(SMB_VFS_OP_FS_CAPABILITIES, true, handle, "");
721 return result;
724 static SMB_STRUCT_DIR *smb_full_audit_opendir(vfs_handle_struct *handle,
725 const char *fname, const char *mask, uint32 attr)
727 SMB_STRUCT_DIR *result;
729 result = SMB_VFS_NEXT_OPENDIR(handle, fname, mask, attr);
731 do_log(SMB_VFS_OP_OPENDIR, (result != NULL), handle, "%s", fname);
733 return result;
736 static SMB_STRUCT_DIRENT *smb_full_audit_readdir(vfs_handle_struct *handle,
737 SMB_STRUCT_DIR *dirp, SMB_STRUCT_STAT *sbuf)
739 SMB_STRUCT_DIRENT *result;
741 result = SMB_VFS_NEXT_READDIR(handle, dirp, sbuf);
743 /* This operation has no reasonable error condition
744 * (End of dir is also failure), so always succeed.
746 do_log(SMB_VFS_OP_READDIR, True, handle, "");
748 return result;
751 static void smb_full_audit_seekdir(vfs_handle_struct *handle,
752 SMB_STRUCT_DIR *dirp, long offset)
754 SMB_VFS_NEXT_SEEKDIR(handle, dirp, offset);
756 do_log(SMB_VFS_OP_SEEKDIR, True, handle, "");
757 return;
760 static long smb_full_audit_telldir(vfs_handle_struct *handle,
761 SMB_STRUCT_DIR *dirp)
763 long result;
765 result = SMB_VFS_NEXT_TELLDIR(handle, dirp);
767 do_log(SMB_VFS_OP_TELLDIR, True, handle, "");
769 return result;
772 static void smb_full_audit_rewinddir(vfs_handle_struct *handle,
773 SMB_STRUCT_DIR *dirp)
775 SMB_VFS_NEXT_REWINDDIR(handle, dirp);
777 do_log(SMB_VFS_OP_REWINDDIR, True, handle, "");
778 return;
781 static int smb_full_audit_mkdir(vfs_handle_struct *handle,
782 const char *path, mode_t mode)
784 int result;
786 result = SMB_VFS_NEXT_MKDIR(handle, path, mode);
788 do_log(SMB_VFS_OP_MKDIR, (result >= 0), handle, "%s", path);
790 return result;
793 static int smb_full_audit_rmdir(vfs_handle_struct *handle,
794 const char *path)
796 int result;
798 result = SMB_VFS_NEXT_RMDIR(handle, path);
800 do_log(SMB_VFS_OP_RMDIR, (result >= 0), handle, "%s", path);
802 return result;
805 static int smb_full_audit_closedir(vfs_handle_struct *handle,
806 SMB_STRUCT_DIR *dirp)
808 int result;
810 result = SMB_VFS_NEXT_CLOSEDIR(handle, dirp);
812 do_log(SMB_VFS_OP_CLOSEDIR, (result >= 0), handle, "");
814 return result;
817 static void smb_full_audit_init_search_op(vfs_handle_struct *handle,
818 SMB_STRUCT_DIR *dirp)
820 SMB_VFS_NEXT_INIT_SEARCH_OP(handle, dirp);
822 do_log(SMB_VFS_OP_INIT_SEARCH_OP, True, handle, "");
823 return;
826 static int smb_full_audit_open(vfs_handle_struct *handle,
827 struct smb_filename *smb_fname,
828 files_struct *fsp, int flags, mode_t mode)
830 int result;
832 result = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
834 do_log(SMB_VFS_OP_OPEN, (result >= 0), handle, "%s|%s",
835 ((flags & O_WRONLY) || (flags & O_RDWR))?"w":"r",
836 smb_fname_str_do_log(smb_fname));
838 return result;
841 static NTSTATUS smb_full_audit_create_file(vfs_handle_struct *handle,
842 struct smb_request *req,
843 uint16_t root_dir_fid,
844 struct smb_filename *smb_fname,
845 uint32_t access_mask,
846 uint32_t share_access,
847 uint32_t create_disposition,
848 uint32_t create_options,
849 uint32_t file_attributes,
850 uint32_t oplock_request,
851 uint64_t allocation_size,
852 uint32_t private_flags,
853 struct security_descriptor *sd,
854 struct ea_list *ea_list,
855 files_struct **result_fsp,
856 int *pinfo)
858 NTSTATUS result;
859 const char* str_create_disposition;
861 switch (create_disposition) {
862 case FILE_SUPERSEDE:
863 str_create_disposition = "supersede";
864 break;
865 case FILE_OVERWRITE_IF:
866 str_create_disposition = "overwrite_if";
867 break;
868 case FILE_OPEN:
869 str_create_disposition = "open";
870 break;
871 case FILE_OVERWRITE:
872 str_create_disposition = "overwrite";
873 break;
874 case FILE_CREATE:
875 str_create_disposition = "create";
876 break;
877 case FILE_OPEN_IF:
878 str_create_disposition = "open_if";
879 break;
880 default:
881 str_create_disposition = "unknown";
884 result = SMB_VFS_NEXT_CREATE_FILE(
885 handle, /* handle */
886 req, /* req */
887 root_dir_fid, /* root_dir_fid */
888 smb_fname, /* fname */
889 access_mask, /* access_mask */
890 share_access, /* share_access */
891 create_disposition, /* create_disposition*/
892 create_options, /* create_options */
893 file_attributes, /* file_attributes */
894 oplock_request, /* oplock_request */
895 allocation_size, /* allocation_size */
896 private_flags,
897 sd, /* sd */
898 ea_list, /* ea_list */
899 result_fsp, /* result */
900 pinfo); /* pinfo */
902 do_log(SMB_VFS_OP_CREATE_FILE, (NT_STATUS_IS_OK(result)), handle,
903 "0x%x|%s|%s|%s", access_mask,
904 create_options & FILE_DIRECTORY_FILE ? "dir" : "file",
905 str_create_disposition, smb_fname_str_do_log(smb_fname));
907 return result;
910 static int smb_full_audit_close(vfs_handle_struct *handle, files_struct *fsp)
912 int result;
914 result = SMB_VFS_NEXT_CLOSE(handle, fsp);
916 do_log(SMB_VFS_OP_CLOSE, (result >= 0), handle, "%s",
917 fsp_str_do_log(fsp));
919 return result;
922 static ssize_t smb_full_audit_read(vfs_handle_struct *handle, files_struct *fsp,
923 void *data, size_t n)
925 ssize_t result;
927 result = SMB_VFS_NEXT_READ(handle, fsp, data, n);
929 do_log(SMB_VFS_OP_READ, (result >= 0), handle, "%s",
930 fsp_str_do_log(fsp));
932 return result;
935 static ssize_t smb_full_audit_pread(vfs_handle_struct *handle, files_struct *fsp,
936 void *data, size_t n, SMB_OFF_T offset)
938 ssize_t result;
940 result = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
942 do_log(SMB_VFS_OP_PREAD, (result >= 0), handle, "%s",
943 fsp_str_do_log(fsp));
945 return result;
948 static ssize_t smb_full_audit_write(vfs_handle_struct *handle, files_struct *fsp,
949 const void *data, size_t n)
951 ssize_t result;
953 result = SMB_VFS_NEXT_WRITE(handle, fsp, data, n);
955 do_log(SMB_VFS_OP_WRITE, (result >= 0), handle, "%s",
956 fsp_str_do_log(fsp));
958 return result;
961 static ssize_t smb_full_audit_pwrite(vfs_handle_struct *handle, files_struct *fsp,
962 const void *data, size_t n,
963 SMB_OFF_T offset)
965 ssize_t result;
967 result = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
969 do_log(SMB_VFS_OP_PWRITE, (result >= 0), handle, "%s",
970 fsp_str_do_log(fsp));
972 return result;
975 static SMB_OFF_T smb_full_audit_lseek(vfs_handle_struct *handle, files_struct *fsp,
976 SMB_OFF_T offset, int whence)
978 ssize_t result;
980 result = SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence);
982 do_log(SMB_VFS_OP_LSEEK, (result != (ssize_t)-1), handle,
983 "%s", fsp_str_do_log(fsp));
985 return result;
988 static ssize_t smb_full_audit_sendfile(vfs_handle_struct *handle, int tofd,
989 files_struct *fromfsp,
990 const DATA_BLOB *hdr, SMB_OFF_T offset,
991 size_t n)
993 ssize_t result;
995 result = SMB_VFS_NEXT_SENDFILE(handle, tofd, fromfsp, hdr, offset, n);
997 do_log(SMB_VFS_OP_SENDFILE, (result >= 0), handle,
998 "%s", fsp_str_do_log(fromfsp));
1000 return result;
1003 static ssize_t smb_full_audit_recvfile(vfs_handle_struct *handle, int fromfd,
1004 files_struct *tofsp,
1005 SMB_OFF_T offset,
1006 size_t n)
1008 ssize_t result;
1010 result = SMB_VFS_NEXT_RECVFILE(handle, fromfd, tofsp, offset, n);
1012 do_log(SMB_VFS_OP_RECVFILE, (result >= 0), handle,
1013 "%s", fsp_str_do_log(tofsp));
1015 return result;
1018 static int smb_full_audit_rename(vfs_handle_struct *handle,
1019 const struct smb_filename *smb_fname_src,
1020 const struct smb_filename *smb_fname_dst)
1022 int result;
1024 result = SMB_VFS_NEXT_RENAME(handle, smb_fname_src, smb_fname_dst);
1026 do_log(SMB_VFS_OP_RENAME, (result >= 0), handle, "%s|%s",
1027 smb_fname_str_do_log(smb_fname_src),
1028 smb_fname_str_do_log(smb_fname_dst));
1030 return result;
1033 static int smb_full_audit_fsync(vfs_handle_struct *handle, files_struct *fsp)
1035 int result;
1037 result = SMB_VFS_NEXT_FSYNC(handle, fsp);
1039 do_log(SMB_VFS_OP_FSYNC, (result >= 0), handle, "%s",
1040 fsp_str_do_log(fsp));
1042 return result;
1045 static int smb_full_audit_stat(vfs_handle_struct *handle,
1046 struct smb_filename *smb_fname)
1048 int result;
1050 result = SMB_VFS_NEXT_STAT(handle, smb_fname);
1052 do_log(SMB_VFS_OP_STAT, (result >= 0), handle, "%s",
1053 smb_fname_str_do_log(smb_fname));
1055 return result;
1058 static int smb_full_audit_fstat(vfs_handle_struct *handle, files_struct *fsp,
1059 SMB_STRUCT_STAT *sbuf)
1061 int result;
1063 result = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1065 do_log(SMB_VFS_OP_FSTAT, (result >= 0), handle, "%s",
1066 fsp_str_do_log(fsp));
1068 return result;
1071 static int smb_full_audit_lstat(vfs_handle_struct *handle,
1072 struct smb_filename *smb_fname)
1074 int result;
1076 result = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
1078 do_log(SMB_VFS_OP_LSTAT, (result >= 0), handle, "%s",
1079 smb_fname_str_do_log(smb_fname));
1081 return result;
1084 static uint64_t smb_full_audit_get_alloc_size(vfs_handle_struct *handle,
1085 files_struct *fsp, const SMB_STRUCT_STAT *sbuf)
1087 uint64_t result;
1089 result = SMB_VFS_NEXT_GET_ALLOC_SIZE(handle, fsp, sbuf);
1091 do_log(SMB_VFS_OP_GET_ALLOC_SIZE, (result != (uint64_t)-1), handle,
1092 "%llu", result);
1094 return result;
1097 static int smb_full_audit_unlink(vfs_handle_struct *handle,
1098 const struct smb_filename *smb_fname)
1100 int result;
1102 result = SMB_VFS_NEXT_UNLINK(handle, smb_fname);
1104 do_log(SMB_VFS_OP_UNLINK, (result >= 0), handle, "%s",
1105 smb_fname_str_do_log(smb_fname));
1107 return result;
1110 static int smb_full_audit_chmod(vfs_handle_struct *handle,
1111 const char *path, mode_t mode)
1113 int result;
1115 result = SMB_VFS_NEXT_CHMOD(handle, path, mode);
1117 do_log(SMB_VFS_OP_CHMOD, (result >= 0), handle, "%s|%o", path, mode);
1119 return result;
1122 static int smb_full_audit_fchmod(vfs_handle_struct *handle, files_struct *fsp,
1123 mode_t mode)
1125 int result;
1127 result = SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1129 do_log(SMB_VFS_OP_FCHMOD, (result >= 0), handle,
1130 "%s|%o", fsp_str_do_log(fsp), mode);
1132 return result;
1135 static int smb_full_audit_chown(vfs_handle_struct *handle,
1136 const char *path, uid_t uid, gid_t gid)
1138 int result;
1140 result = SMB_VFS_NEXT_CHOWN(handle, path, uid, gid);
1142 do_log(SMB_VFS_OP_CHOWN, (result >= 0), handle, "%s|%ld|%ld",
1143 path, (long int)uid, (long int)gid);
1145 return result;
1148 static int smb_full_audit_fchown(vfs_handle_struct *handle, files_struct *fsp,
1149 uid_t uid, gid_t gid)
1151 int result;
1153 result = SMB_VFS_NEXT_FCHOWN(handle, fsp, uid, gid);
1155 do_log(SMB_VFS_OP_FCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1156 fsp_str_do_log(fsp), (long int)uid, (long int)gid);
1158 return result;
1161 static int smb_full_audit_lchown(vfs_handle_struct *handle,
1162 const char *path, uid_t uid, gid_t gid)
1164 int result;
1166 result = SMB_VFS_NEXT_LCHOWN(handle, path, uid, gid);
1168 do_log(SMB_VFS_OP_LCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1169 path, (long int)uid, (long int)gid);
1171 return result;
1174 static int smb_full_audit_chdir(vfs_handle_struct *handle,
1175 const char *path)
1177 int result;
1179 result = SMB_VFS_NEXT_CHDIR(handle, path);
1181 do_log(SMB_VFS_OP_CHDIR, (result >= 0), handle, "chdir|%s", path);
1183 return result;
1186 static char *smb_full_audit_getwd(vfs_handle_struct *handle,
1187 char *path)
1189 char *result;
1191 result = SMB_VFS_NEXT_GETWD(handle, path);
1193 do_log(SMB_VFS_OP_GETWD, (result != NULL), handle, "%s", path);
1195 return result;
1198 static int smb_full_audit_ntimes(vfs_handle_struct *handle,
1199 const struct smb_filename *smb_fname,
1200 struct smb_file_time *ft)
1202 int result;
1204 result = SMB_VFS_NEXT_NTIMES(handle, smb_fname, ft);
1206 do_log(SMB_VFS_OP_NTIMES, (result >= 0), handle, "%s",
1207 smb_fname_str_do_log(smb_fname));
1209 return result;
1212 static int smb_full_audit_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
1213 SMB_OFF_T len)
1215 int result;
1217 result = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1219 do_log(SMB_VFS_OP_FTRUNCATE, (result >= 0), handle,
1220 "%s", fsp_str_do_log(fsp));
1222 return result;
1225 static bool smb_full_audit_lock(vfs_handle_struct *handle, files_struct *fsp,
1226 int op, SMB_OFF_T offset, SMB_OFF_T count, int type)
1228 bool result;
1230 result = SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type);
1232 do_log(SMB_VFS_OP_LOCK, result, handle, "%s", fsp_str_do_log(fsp));
1234 return result;
1237 static int smb_full_audit_kernel_flock(struct vfs_handle_struct *handle,
1238 struct files_struct *fsp,
1239 uint32 share_mode, uint32 access_mask)
1241 int result;
1243 result = SMB_VFS_NEXT_KERNEL_FLOCK(handle, fsp, share_mode, access_mask);
1245 do_log(SMB_VFS_OP_KERNEL_FLOCK, (result >= 0), handle, "%s",
1246 fsp_str_do_log(fsp));
1248 return result;
1251 static int smb_full_audit_linux_setlease(vfs_handle_struct *handle, files_struct *fsp,
1252 int leasetype)
1254 int result;
1256 result = SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
1258 do_log(SMB_VFS_OP_LINUX_SETLEASE, (result >= 0), handle, "%s",
1259 fsp_str_do_log(fsp));
1261 return result;
1264 static bool smb_full_audit_getlock(vfs_handle_struct *handle, files_struct *fsp,
1265 SMB_OFF_T *poffset, SMB_OFF_T *pcount, int *ptype, pid_t *ppid)
1267 bool result;
1269 result = SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype, ppid);
1271 do_log(SMB_VFS_OP_GETLOCK, result, handle, "%s", fsp_str_do_log(fsp));
1273 return result;
1276 static int smb_full_audit_symlink(vfs_handle_struct *handle,
1277 const char *oldpath, const char *newpath)
1279 int result;
1281 result = SMB_VFS_NEXT_SYMLINK(handle, oldpath, newpath);
1283 do_log(SMB_VFS_OP_SYMLINK, (result >= 0), handle,
1284 "%s|%s", oldpath, newpath);
1286 return result;
1289 static int smb_full_audit_readlink(vfs_handle_struct *handle,
1290 const char *path, char *buf, size_t bufsiz)
1292 int result;
1294 result = SMB_VFS_NEXT_READLINK(handle, path, buf, bufsiz);
1296 do_log(SMB_VFS_OP_READLINK, (result >= 0), handle, "%s", path);
1298 return result;
1301 static int smb_full_audit_link(vfs_handle_struct *handle,
1302 const char *oldpath, const char *newpath)
1304 int result;
1306 result = SMB_VFS_NEXT_LINK(handle, oldpath, newpath);
1308 do_log(SMB_VFS_OP_LINK, (result >= 0), handle,
1309 "%s|%s", oldpath, newpath);
1311 return result;
1314 static int smb_full_audit_mknod(vfs_handle_struct *handle,
1315 const char *pathname, mode_t mode, SMB_DEV_T dev)
1317 int result;
1319 result = SMB_VFS_NEXT_MKNOD(handle, pathname, mode, dev);
1321 do_log(SMB_VFS_OP_MKNOD, (result >= 0), handle, "%s", pathname);
1323 return result;
1326 static char *smb_full_audit_realpath(vfs_handle_struct *handle,
1327 const char *path, char *resolved_path)
1329 char *result;
1331 result = SMB_VFS_NEXT_REALPATH(handle, path, resolved_path);
1333 do_log(SMB_VFS_OP_REALPATH, (result != NULL), handle, "%s", path);
1335 return result;
1338 static NTSTATUS smb_full_audit_notify_watch(struct vfs_handle_struct *handle,
1339 struct sys_notify_context *ctx,
1340 struct notify_entry *e,
1341 void (*callback)(struct sys_notify_context *ctx,
1342 void *private_data,
1343 struct notify_event *ev),
1344 void *private_data, void *handle_p)
1346 NTSTATUS result;
1348 result = SMB_VFS_NEXT_NOTIFY_WATCH(handle, ctx, e, callback, private_data, handle_p);
1350 do_log(SMB_VFS_OP_NOTIFY_WATCH, NT_STATUS_IS_OK(result), handle, "");
1352 return result;
1355 static int smb_full_audit_chflags(vfs_handle_struct *handle,
1356 const char *path, unsigned int flags)
1358 int result;
1360 result = SMB_VFS_NEXT_CHFLAGS(handle, path, flags);
1362 do_log(SMB_VFS_OP_CHFLAGS, (result != 0), handle, "%s", path);
1364 return result;
1367 static struct file_id smb_full_audit_file_id_create(struct vfs_handle_struct *handle,
1368 const SMB_STRUCT_STAT *sbuf)
1370 struct file_id id_zero;
1371 struct file_id result;
1373 ZERO_STRUCT(id_zero);
1375 result = SMB_VFS_NEXT_FILE_ID_CREATE(handle, sbuf);
1377 do_log(SMB_VFS_OP_FILE_ID_CREATE,
1378 !file_id_equal(&id_zero, &result),
1379 handle, "%s", file_id_string_tos(&result));
1381 return result;
1384 static NTSTATUS smb_full_audit_streaminfo(vfs_handle_struct *handle,
1385 struct files_struct *fsp,
1386 const char *fname,
1387 TALLOC_CTX *mem_ctx,
1388 unsigned int *pnum_streams,
1389 struct stream_struct **pstreams)
1391 NTSTATUS result;
1393 result = SMB_VFS_NEXT_STREAMINFO(handle, fsp, fname, mem_ctx,
1394 pnum_streams, pstreams);
1396 do_log(SMB_VFS_OP_STREAMINFO, NT_STATUS_IS_OK(result), handle,
1397 "%s", fname);
1399 return result;
1402 static int smb_full_audit_get_real_filename(struct vfs_handle_struct *handle,
1403 const char *path,
1404 const char *name,
1405 TALLOC_CTX *mem_ctx,
1406 char **found_name)
1408 int result;
1410 result = SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name, mem_ctx,
1411 found_name);
1413 do_log(SMB_VFS_OP_GET_REAL_FILENAME, (result == 0), handle,
1414 "%s/%s->%s", path, name, (result == 0) ? "" : *found_name);
1416 return result;
1419 static const char *smb_full_audit_connectpath(vfs_handle_struct *handle,
1420 const char *fname)
1422 const char *result;
1424 result = SMB_VFS_NEXT_CONNECTPATH(handle, fname);
1426 do_log(SMB_VFS_OP_CONNECTPATH, result != NULL, handle,
1427 "%s", fname);
1429 return result;
1432 static NTSTATUS smb_full_audit_brl_lock_windows(struct vfs_handle_struct *handle,
1433 struct byte_range_lock *br_lck,
1434 struct lock_struct *plock,
1435 bool blocking_lock,
1436 struct blocking_lock_record *blr)
1438 NTSTATUS result;
1440 result = SMB_VFS_NEXT_BRL_LOCK_WINDOWS(handle, br_lck, plock,
1441 blocking_lock, blr);
1443 do_log(SMB_VFS_OP_BRL_LOCK_WINDOWS, NT_STATUS_IS_OK(result), handle,
1444 "%s:%llu-%llu. type=%d. blocking=%d", fsp_str_do_log(br_lck->fsp),
1445 plock->start, plock->size, plock->lock_type, blocking_lock );
1447 return result;
1450 static bool smb_full_audit_brl_unlock_windows(struct vfs_handle_struct *handle,
1451 struct messaging_context *msg_ctx,
1452 struct byte_range_lock *br_lck,
1453 const struct lock_struct *plock)
1455 bool result;
1457 result = SMB_VFS_NEXT_BRL_UNLOCK_WINDOWS(handle, msg_ctx, br_lck,
1458 plock);
1460 do_log(SMB_VFS_OP_BRL_UNLOCK_WINDOWS, (result == 0), handle,
1461 "%s:%llu-%llu:%d", fsp_str_do_log(br_lck->fsp), plock->start,
1462 plock->size, plock->lock_type);
1464 return result;
1467 static bool smb_full_audit_brl_cancel_windows(struct vfs_handle_struct *handle,
1468 struct byte_range_lock *br_lck,
1469 struct lock_struct *plock,
1470 struct blocking_lock_record *blr)
1472 bool result;
1474 result = SMB_VFS_NEXT_BRL_CANCEL_WINDOWS(handle, br_lck, plock, blr);
1476 do_log(SMB_VFS_OP_BRL_CANCEL_WINDOWS, (result == 0), handle,
1477 "%s:%llu-%llu:%d", fsp_str_do_log(br_lck->fsp), plock->start,
1478 plock->size);
1480 return result;
1483 static bool smb_full_audit_strict_lock(struct vfs_handle_struct *handle,
1484 struct files_struct *fsp,
1485 struct lock_struct *plock)
1487 bool result;
1489 result = SMB_VFS_NEXT_STRICT_LOCK(handle, fsp, plock);
1491 do_log(SMB_VFS_OP_STRICT_LOCK, result, handle,
1492 "%s:%llu-%llu:%d", fsp_str_do_log(fsp), plock->start,
1493 plock->size);
1495 return result;
1498 static void smb_full_audit_strict_unlock(struct vfs_handle_struct *handle,
1499 struct files_struct *fsp,
1500 struct lock_struct *plock)
1502 SMB_VFS_NEXT_STRICT_UNLOCK(handle, fsp, plock);
1504 do_log(SMB_VFS_OP_STRICT_UNLOCK, true, handle,
1505 "%s:%llu-%llu:%d", fsp_str_do_log(fsp), plock->start,
1506 plock->size);
1508 return;
1511 static NTSTATUS smb_full_audit_translate_name(struct vfs_handle_struct *handle,
1512 const char *name,
1513 enum vfs_translate_direction direction,
1514 TALLOC_CTX *mem_ctx,
1515 char **mapped_name)
1517 NTSTATUS result;
1519 result = SMB_VFS_NEXT_TRANSLATE_NAME(handle, name, direction, mem_ctx,
1520 mapped_name);
1522 do_log(SMB_VFS_OP_TRANSLATE_NAME, NT_STATUS_IS_OK(result), handle, "");
1524 return result;
1527 static NTSTATUS smb_full_audit_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
1528 uint32 security_info,
1529 struct security_descriptor **ppdesc)
1531 NTSTATUS result;
1533 result = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info, ppdesc);
1535 do_log(SMB_VFS_OP_FGET_NT_ACL, NT_STATUS_IS_OK(result), handle,
1536 "%s", fsp_str_do_log(fsp));
1538 return result;
1541 static NTSTATUS smb_full_audit_get_nt_acl(vfs_handle_struct *handle,
1542 const char *name,
1543 uint32 security_info,
1544 struct security_descriptor **ppdesc)
1546 NTSTATUS result;
1548 result = SMB_VFS_NEXT_GET_NT_ACL(handle, name, security_info, ppdesc);
1550 do_log(SMB_VFS_OP_GET_NT_ACL, NT_STATUS_IS_OK(result), handle,
1551 "%s", name);
1553 return result;
1556 static NTSTATUS smb_full_audit_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
1557 uint32 security_info_sent,
1558 const struct security_descriptor *psd)
1560 NTSTATUS result;
1562 result = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
1564 do_log(SMB_VFS_OP_FSET_NT_ACL, NT_STATUS_IS_OK(result), handle, "%s",
1565 fsp_str_do_log(fsp));
1567 return result;
1570 static int smb_full_audit_chmod_acl(vfs_handle_struct *handle,
1571 const char *path, mode_t mode)
1573 int result;
1575 result = SMB_VFS_NEXT_CHMOD_ACL(handle, path, mode);
1577 do_log(SMB_VFS_OP_CHMOD_ACL, (result >= 0), handle,
1578 "%s|%o", path, mode);
1580 return result;
1583 static int smb_full_audit_fchmod_acl(vfs_handle_struct *handle, files_struct *fsp,
1584 mode_t mode)
1586 int result;
1588 result = SMB_VFS_NEXT_FCHMOD_ACL(handle, fsp, mode);
1590 do_log(SMB_VFS_OP_FCHMOD_ACL, (result >= 0), handle,
1591 "%s|%o", fsp_str_do_log(fsp), mode);
1593 return result;
1596 static int smb_full_audit_sys_acl_get_entry(vfs_handle_struct *handle,
1598 SMB_ACL_T theacl, int entry_id,
1599 SMB_ACL_ENTRY_T *entry_p)
1601 int result;
1603 result = SMB_VFS_NEXT_SYS_ACL_GET_ENTRY(handle, theacl, entry_id,
1604 entry_p);
1606 do_log(SMB_VFS_OP_SYS_ACL_GET_ENTRY, (result >= 0), handle,
1607 "");
1609 return result;
1612 static int smb_full_audit_sys_acl_get_tag_type(vfs_handle_struct *handle,
1614 SMB_ACL_ENTRY_T entry_d,
1615 SMB_ACL_TAG_T *tag_type_p)
1617 int result;
1619 result = SMB_VFS_NEXT_SYS_ACL_GET_TAG_TYPE(handle, entry_d,
1620 tag_type_p);
1622 do_log(SMB_VFS_OP_SYS_ACL_GET_TAG_TYPE, (result >= 0), handle,
1623 "");
1625 return result;
1628 static int smb_full_audit_sys_acl_get_permset(vfs_handle_struct *handle,
1630 SMB_ACL_ENTRY_T entry_d,
1631 SMB_ACL_PERMSET_T *permset_p)
1633 int result;
1635 result = SMB_VFS_NEXT_SYS_ACL_GET_PERMSET(handle, entry_d,
1636 permset_p);
1638 do_log(SMB_VFS_OP_SYS_ACL_GET_PERMSET, (result >= 0), handle,
1639 "");
1641 return result;
1644 static void * smb_full_audit_sys_acl_get_qualifier(vfs_handle_struct *handle,
1646 SMB_ACL_ENTRY_T entry_d)
1648 void *result;
1650 result = SMB_VFS_NEXT_SYS_ACL_GET_QUALIFIER(handle, entry_d);
1652 do_log(SMB_VFS_OP_SYS_ACL_GET_QUALIFIER, (result != NULL), handle,
1653 "");
1655 return result;
1658 static SMB_ACL_T smb_full_audit_sys_acl_get_file(vfs_handle_struct *handle,
1659 const char *path_p,
1660 SMB_ACL_TYPE_T type)
1662 SMB_ACL_T result;
1664 result = SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, path_p, type);
1666 do_log(SMB_VFS_OP_SYS_ACL_GET_FILE, (result != NULL), handle,
1667 "%s", path_p);
1669 return result;
1672 static SMB_ACL_T smb_full_audit_sys_acl_get_fd(vfs_handle_struct *handle,
1673 files_struct *fsp)
1675 SMB_ACL_T result;
1677 result = SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp);
1679 do_log(SMB_VFS_OP_SYS_ACL_GET_FD, (result != NULL), handle,
1680 "%s", fsp_str_do_log(fsp));
1682 return result;
1685 static int smb_full_audit_sys_acl_clear_perms(vfs_handle_struct *handle,
1687 SMB_ACL_PERMSET_T permset)
1689 int result;
1691 result = SMB_VFS_NEXT_SYS_ACL_CLEAR_PERMS(handle, permset);
1693 do_log(SMB_VFS_OP_SYS_ACL_CLEAR_PERMS, (result >= 0), handle,
1694 "");
1696 return result;
1699 static int smb_full_audit_sys_acl_add_perm(vfs_handle_struct *handle,
1701 SMB_ACL_PERMSET_T permset,
1702 SMB_ACL_PERM_T perm)
1704 int result;
1706 result = SMB_VFS_NEXT_SYS_ACL_ADD_PERM(handle, permset, perm);
1708 do_log(SMB_VFS_OP_SYS_ACL_ADD_PERM, (result >= 0), handle,
1709 "");
1711 return result;
1714 static char * smb_full_audit_sys_acl_to_text(vfs_handle_struct *handle,
1715 SMB_ACL_T theacl,
1716 ssize_t *plen)
1718 char * result;
1720 result = SMB_VFS_NEXT_SYS_ACL_TO_TEXT(handle, theacl, plen);
1722 do_log(SMB_VFS_OP_SYS_ACL_TO_TEXT, (result != NULL), handle,
1723 "");
1725 return result;
1728 static SMB_ACL_T smb_full_audit_sys_acl_init(vfs_handle_struct *handle,
1730 int count)
1732 SMB_ACL_T result;
1734 result = SMB_VFS_NEXT_SYS_ACL_INIT(handle, count);
1736 do_log(SMB_VFS_OP_SYS_ACL_INIT, (result != NULL), handle,
1737 "");
1739 return result;
1742 static int smb_full_audit_sys_acl_create_entry(vfs_handle_struct *handle,
1743 SMB_ACL_T *pacl,
1744 SMB_ACL_ENTRY_T *pentry)
1746 int result;
1748 result = SMB_VFS_NEXT_SYS_ACL_CREATE_ENTRY(handle, pacl, pentry);
1750 do_log(SMB_VFS_OP_SYS_ACL_CREATE_ENTRY, (result >= 0), handle,
1751 "");
1753 return result;
1756 static int smb_full_audit_sys_acl_set_tag_type(vfs_handle_struct *handle,
1758 SMB_ACL_ENTRY_T entry,
1759 SMB_ACL_TAG_T tagtype)
1761 int result;
1763 result = SMB_VFS_NEXT_SYS_ACL_SET_TAG_TYPE(handle, entry,
1764 tagtype);
1766 do_log(SMB_VFS_OP_SYS_ACL_SET_TAG_TYPE, (result >= 0), handle,
1767 "");
1769 return result;
1772 static int smb_full_audit_sys_acl_set_qualifier(vfs_handle_struct *handle,
1774 SMB_ACL_ENTRY_T entry,
1775 void *qual)
1777 int result;
1779 result = SMB_VFS_NEXT_SYS_ACL_SET_QUALIFIER(handle, entry, qual);
1781 do_log(SMB_VFS_OP_SYS_ACL_SET_QUALIFIER, (result >= 0), handle,
1782 "");
1784 return result;
1787 static int smb_full_audit_sys_acl_set_permset(vfs_handle_struct *handle,
1789 SMB_ACL_ENTRY_T entry,
1790 SMB_ACL_PERMSET_T permset)
1792 int result;
1794 result = SMB_VFS_NEXT_SYS_ACL_SET_PERMSET(handle, entry, permset);
1796 do_log(SMB_VFS_OP_SYS_ACL_SET_PERMSET, (result >= 0), handle,
1797 "");
1799 return result;
1802 static int smb_full_audit_sys_acl_valid(vfs_handle_struct *handle,
1804 SMB_ACL_T theacl )
1806 int result;
1808 result = SMB_VFS_NEXT_SYS_ACL_VALID(handle, theacl);
1810 do_log(SMB_VFS_OP_SYS_ACL_VALID, (result >= 0), handle,
1811 "");
1813 return result;
1816 static int smb_full_audit_sys_acl_set_file(vfs_handle_struct *handle,
1818 const char *name, SMB_ACL_TYPE_T acltype,
1819 SMB_ACL_T theacl)
1821 int result;
1823 result = SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, name, acltype,
1824 theacl);
1826 do_log(SMB_VFS_OP_SYS_ACL_SET_FILE, (result >= 0), handle,
1827 "%s", name);
1829 return result;
1832 static int smb_full_audit_sys_acl_set_fd(vfs_handle_struct *handle, files_struct *fsp,
1833 SMB_ACL_T theacl)
1835 int result;
1837 result = SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, theacl);
1839 do_log(SMB_VFS_OP_SYS_ACL_SET_FD, (result >= 0), handle,
1840 "%s", fsp_str_do_log(fsp));
1842 return result;
1845 static int smb_full_audit_sys_acl_delete_def_file(vfs_handle_struct *handle,
1847 const char *path)
1849 int result;
1851 result = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, path);
1853 do_log(SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE, (result >= 0), handle,
1854 "%s", path);
1856 return result;
1859 static int smb_full_audit_sys_acl_get_perm(vfs_handle_struct *handle,
1861 SMB_ACL_PERMSET_T permset,
1862 SMB_ACL_PERM_T perm)
1864 int result;
1866 result = SMB_VFS_NEXT_SYS_ACL_GET_PERM(handle, permset, perm);
1868 do_log(SMB_VFS_OP_SYS_ACL_GET_PERM, (result >= 0), handle,
1869 "");
1871 return result;
1874 static int smb_full_audit_sys_acl_free_text(vfs_handle_struct *handle,
1876 char *text)
1878 int result;
1880 result = SMB_VFS_NEXT_SYS_ACL_FREE_TEXT(handle, text);
1882 do_log(SMB_VFS_OP_SYS_ACL_FREE_TEXT, (result >= 0), handle,
1883 "");
1885 return result;
1888 static int smb_full_audit_sys_acl_free_acl(vfs_handle_struct *handle,
1890 SMB_ACL_T posix_acl)
1892 int result;
1894 result = SMB_VFS_NEXT_SYS_ACL_FREE_ACL(handle, posix_acl);
1896 do_log(SMB_VFS_OP_SYS_ACL_FREE_ACL, (result >= 0), handle,
1897 "");
1899 return result;
1902 static int smb_full_audit_sys_acl_free_qualifier(vfs_handle_struct *handle,
1903 void *qualifier,
1904 SMB_ACL_TAG_T tagtype)
1906 int result;
1908 result = SMB_VFS_NEXT_SYS_ACL_FREE_QUALIFIER(handle, qualifier,
1909 tagtype);
1911 do_log(SMB_VFS_OP_SYS_ACL_FREE_QUALIFIER, (result >= 0), handle,
1912 "");
1914 return result;
1917 static ssize_t smb_full_audit_getxattr(struct vfs_handle_struct *handle,
1918 const char *path,
1919 const char *name, void *value, size_t size)
1921 ssize_t result;
1923 result = SMB_VFS_NEXT_GETXATTR(handle, path, name, value, size);
1925 do_log(SMB_VFS_OP_GETXATTR, (result >= 0), handle,
1926 "%s|%s", path, name);
1928 return result;
1931 static ssize_t smb_full_audit_lgetxattr(struct vfs_handle_struct *handle,
1932 const char *path, const char *name,
1933 void *value, size_t size)
1935 ssize_t result;
1937 result = SMB_VFS_NEXT_LGETXATTR(handle, path, name, value, size);
1939 do_log(SMB_VFS_OP_LGETXATTR, (result >= 0), handle,
1940 "%s|%s", path, name);
1942 return result;
1945 static ssize_t smb_full_audit_fgetxattr(struct vfs_handle_struct *handle,
1946 struct files_struct *fsp,
1947 const char *name, void *value, size_t size)
1949 ssize_t result;
1951 result = SMB_VFS_NEXT_FGETXATTR(handle, fsp, name, value, size);
1953 do_log(SMB_VFS_OP_FGETXATTR, (result >= 0), handle,
1954 "%s|%s", fsp_str_do_log(fsp), name);
1956 return result;
1959 static ssize_t smb_full_audit_listxattr(struct vfs_handle_struct *handle,
1960 const char *path, char *list, size_t size)
1962 ssize_t result;
1964 result = SMB_VFS_NEXT_LISTXATTR(handle, path, list, size);
1966 do_log(SMB_VFS_OP_LISTXATTR, (result >= 0), handle, "%s", path);
1968 return result;
1971 static ssize_t smb_full_audit_llistxattr(struct vfs_handle_struct *handle,
1972 const char *path, char *list, size_t size)
1974 ssize_t result;
1976 result = SMB_VFS_NEXT_LLISTXATTR(handle, path, list, size);
1978 do_log(SMB_VFS_OP_LLISTXATTR, (result >= 0), handle, "%s", path);
1980 return result;
1983 static ssize_t smb_full_audit_flistxattr(struct vfs_handle_struct *handle,
1984 struct files_struct *fsp, char *list,
1985 size_t size)
1987 ssize_t result;
1989 result = SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
1991 do_log(SMB_VFS_OP_FLISTXATTR, (result >= 0), handle,
1992 "%s", fsp_str_do_log(fsp));
1994 return result;
1997 static int smb_full_audit_removexattr(struct vfs_handle_struct *handle,
1998 const char *path,
1999 const char *name)
2001 int result;
2003 result = SMB_VFS_NEXT_REMOVEXATTR(handle, path, name);
2005 do_log(SMB_VFS_OP_REMOVEXATTR, (result >= 0), handle,
2006 "%s|%s", path, name);
2008 return result;
2011 static int smb_full_audit_lremovexattr(struct vfs_handle_struct *handle,
2012 const char *path,
2013 const char *name)
2015 int result;
2017 result = SMB_VFS_NEXT_LREMOVEXATTR(handle, path, name);
2019 do_log(SMB_VFS_OP_LREMOVEXATTR, (result >= 0), handle,
2020 "%s|%s", path, name);
2022 return result;
2025 static int smb_full_audit_fremovexattr(struct vfs_handle_struct *handle,
2026 struct files_struct *fsp,
2027 const char *name)
2029 int result;
2031 result = SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, name);
2033 do_log(SMB_VFS_OP_FREMOVEXATTR, (result >= 0), handle,
2034 "%s|%s", fsp_str_do_log(fsp), name);
2036 return result;
2039 static int smb_full_audit_setxattr(struct vfs_handle_struct *handle,
2040 const char *path,
2041 const char *name, const void *value, size_t size,
2042 int flags)
2044 int result;
2046 result = SMB_VFS_NEXT_SETXATTR(handle, path, name, value, size,
2047 flags);
2049 do_log(SMB_VFS_OP_SETXATTR, (result >= 0), handle,
2050 "%s|%s", path, name);
2052 return result;
2055 static int smb_full_audit_lsetxattr(struct vfs_handle_struct *handle,
2056 const char *path,
2057 const char *name, const void *value, size_t size,
2058 int flags)
2060 int result;
2062 result = SMB_VFS_NEXT_LSETXATTR(handle, path, name, value, size,
2063 flags);
2065 do_log(SMB_VFS_OP_LSETXATTR, (result >= 0), handle,
2066 "%s|%s", path, name);
2068 return result;
2071 static int smb_full_audit_fsetxattr(struct vfs_handle_struct *handle,
2072 struct files_struct *fsp, const char *name,
2073 const void *value, size_t size, int flags)
2075 int result;
2077 result = SMB_VFS_NEXT_FSETXATTR(handle, fsp, name, value, size, flags);
2079 do_log(SMB_VFS_OP_FSETXATTR, (result >= 0), handle,
2080 "%s|%s", fsp_str_do_log(fsp), name);
2082 return result;
2085 static int smb_full_audit_aio_read(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
2087 int result;
2089 result = SMB_VFS_NEXT_AIO_READ(handle, fsp, aiocb);
2090 do_log(SMB_VFS_OP_AIO_READ, (result >= 0), handle,
2091 "%s", fsp_str_do_log(fsp));
2093 return result;
2096 static int smb_full_audit_aio_write(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
2098 int result;
2100 result = SMB_VFS_NEXT_AIO_WRITE(handle, fsp, aiocb);
2101 do_log(SMB_VFS_OP_AIO_WRITE, (result >= 0), handle,
2102 "%s", fsp_str_do_log(fsp));
2104 return result;
2107 static ssize_t smb_full_audit_aio_return(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
2109 int result;
2111 result = SMB_VFS_NEXT_AIO_RETURN(handle, fsp, aiocb);
2112 do_log(SMB_VFS_OP_AIO_RETURN, (result >= 0), handle,
2113 "%s", fsp_str_do_log(fsp));
2115 return result;
2118 static int smb_full_audit_aio_cancel(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
2120 int result;
2122 result = SMB_VFS_NEXT_AIO_CANCEL(handle, fsp, aiocb);
2123 do_log(SMB_VFS_OP_AIO_CANCEL, (result >= 0), handle,
2124 "%s", fsp_str_do_log(fsp));
2126 return result;
2129 static int smb_full_audit_aio_error(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
2131 int result;
2133 result = SMB_VFS_NEXT_AIO_ERROR(handle, fsp, aiocb);
2134 do_log(SMB_VFS_OP_AIO_ERROR, (result >= 0), handle,
2135 "%s", fsp_str_do_log(fsp));
2137 return result;
2140 static int smb_full_audit_aio_fsync(struct vfs_handle_struct *handle, struct files_struct *fsp, int op, SMB_STRUCT_AIOCB *aiocb)
2142 int result;
2144 result = SMB_VFS_NEXT_AIO_FSYNC(handle, fsp, op, aiocb);
2145 do_log(SMB_VFS_OP_AIO_FSYNC, (result >= 0), handle,
2146 "%s", fsp_str_do_log(fsp));
2148 return result;
2151 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)
2153 int result;
2155 result = SMB_VFS_NEXT_AIO_SUSPEND(handle, fsp, aiocb, n, ts);
2156 do_log(SMB_VFS_OP_AIO_SUSPEND, (result >= 0), handle,
2157 "%s", fsp_str_do_log(fsp));
2159 return result;
2162 static bool smb_full_audit_aio_force(struct vfs_handle_struct *handle,
2163 struct files_struct *fsp)
2165 bool result;
2167 result = SMB_VFS_NEXT_AIO_FORCE(handle, fsp);
2168 do_log(SMB_VFS_OP_AIO_FORCE, result, handle,
2169 "%s", fsp_str_do_log(fsp));
2171 return result;
2174 static struct vfs_fn_pointers vfs_full_audit_fns = {
2176 /* Disk operations */
2178 .connect_fn = smb_full_audit_connect,
2179 .disconnect = smb_full_audit_disconnect,
2180 .disk_free = smb_full_audit_disk_free,
2181 .get_quota = smb_full_audit_get_quota,
2182 .set_quota = smb_full_audit_set_quota,
2183 .get_shadow_copy_data = smb_full_audit_get_shadow_copy_data,
2184 .statvfs = smb_full_audit_statvfs,
2185 .fs_capabilities = smb_full_audit_fs_capabilities,
2186 .opendir = smb_full_audit_opendir,
2187 .readdir = smb_full_audit_readdir,
2188 .seekdir = smb_full_audit_seekdir,
2189 .telldir = smb_full_audit_telldir,
2190 .rewind_dir = smb_full_audit_rewinddir,
2191 .mkdir = smb_full_audit_mkdir,
2192 .rmdir = smb_full_audit_rmdir,
2193 .closedir = smb_full_audit_closedir,
2194 .init_search_op = smb_full_audit_init_search_op,
2195 .open = smb_full_audit_open,
2196 .create_file = smb_full_audit_create_file,
2197 .close_fn = smb_full_audit_close,
2198 .vfs_read = smb_full_audit_read,
2199 .pread = smb_full_audit_pread,
2200 .write = smb_full_audit_write,
2201 .pwrite = smb_full_audit_pwrite,
2202 .lseek = smb_full_audit_lseek,
2203 .sendfile = smb_full_audit_sendfile,
2204 .recvfile = smb_full_audit_recvfile,
2205 .rename = smb_full_audit_rename,
2206 .fsync = smb_full_audit_fsync,
2207 .stat = smb_full_audit_stat,
2208 .fstat = smb_full_audit_fstat,
2209 .lstat = smb_full_audit_lstat,
2210 .get_alloc_size = smb_full_audit_get_alloc_size,
2211 .unlink = smb_full_audit_unlink,
2212 .chmod = smb_full_audit_chmod,
2213 .fchmod = smb_full_audit_fchmod,
2214 .chown = smb_full_audit_chown,
2215 .fchown = smb_full_audit_fchown,
2216 .lchown = smb_full_audit_lchown,
2217 .chdir = smb_full_audit_chdir,
2218 .getwd = smb_full_audit_getwd,
2219 .ntimes = smb_full_audit_ntimes,
2220 .ftruncate = smb_full_audit_ftruncate,
2221 .lock = smb_full_audit_lock,
2222 .kernel_flock = smb_full_audit_kernel_flock,
2223 .linux_setlease = smb_full_audit_linux_setlease,
2224 .getlock = smb_full_audit_getlock,
2225 .symlink = smb_full_audit_symlink,
2226 .vfs_readlink = smb_full_audit_readlink,
2227 .link = smb_full_audit_link,
2228 .mknod = smb_full_audit_mknod,
2229 .realpath = smb_full_audit_realpath,
2230 .notify_watch = smb_full_audit_notify_watch,
2231 .chflags = smb_full_audit_chflags,
2232 .file_id_create = smb_full_audit_file_id_create,
2233 .streaminfo = smb_full_audit_streaminfo,
2234 .get_real_filename = smb_full_audit_get_real_filename,
2235 .connectpath = smb_full_audit_connectpath,
2236 .brl_lock_windows = smb_full_audit_brl_lock_windows,
2237 .brl_unlock_windows = smb_full_audit_brl_unlock_windows,
2238 .brl_cancel_windows = smb_full_audit_brl_cancel_windows,
2239 .strict_lock = smb_full_audit_strict_lock,
2240 .strict_unlock = smb_full_audit_strict_unlock,
2241 .translate_name = smb_full_audit_translate_name,
2242 .fget_nt_acl = smb_full_audit_fget_nt_acl,
2243 .get_nt_acl = smb_full_audit_get_nt_acl,
2244 .fset_nt_acl = smb_full_audit_fset_nt_acl,
2245 .chmod_acl = smb_full_audit_chmod_acl,
2246 .fchmod_acl = smb_full_audit_fchmod_acl,
2247 .sys_acl_get_entry = smb_full_audit_sys_acl_get_entry,
2248 .sys_acl_get_tag_type = smb_full_audit_sys_acl_get_tag_type,
2249 .sys_acl_get_permset = smb_full_audit_sys_acl_get_permset,
2250 .sys_acl_get_qualifier = smb_full_audit_sys_acl_get_qualifier,
2251 .sys_acl_get_file = smb_full_audit_sys_acl_get_file,
2252 .sys_acl_get_fd = smb_full_audit_sys_acl_get_fd,
2253 .sys_acl_clear_perms = smb_full_audit_sys_acl_clear_perms,
2254 .sys_acl_add_perm = smb_full_audit_sys_acl_add_perm,
2255 .sys_acl_to_text = smb_full_audit_sys_acl_to_text,
2256 .sys_acl_init = smb_full_audit_sys_acl_init,
2257 .sys_acl_create_entry = smb_full_audit_sys_acl_create_entry,
2258 .sys_acl_set_tag_type = smb_full_audit_sys_acl_set_tag_type,
2259 .sys_acl_set_qualifier = smb_full_audit_sys_acl_set_qualifier,
2260 .sys_acl_set_permset = smb_full_audit_sys_acl_set_permset,
2261 .sys_acl_valid = smb_full_audit_sys_acl_valid,
2262 .sys_acl_set_file = smb_full_audit_sys_acl_set_file,
2263 .sys_acl_set_fd = smb_full_audit_sys_acl_set_fd,
2264 .sys_acl_delete_def_file = smb_full_audit_sys_acl_delete_def_file,
2265 .sys_acl_get_perm = smb_full_audit_sys_acl_get_perm,
2266 .sys_acl_free_text = smb_full_audit_sys_acl_free_text,
2267 .sys_acl_free_acl = smb_full_audit_sys_acl_free_acl,
2268 .sys_acl_free_qualifier = smb_full_audit_sys_acl_free_qualifier,
2269 .getxattr = smb_full_audit_getxattr,
2270 .lgetxattr = smb_full_audit_lgetxattr,
2271 .fgetxattr = smb_full_audit_fgetxattr,
2272 .listxattr = smb_full_audit_listxattr,
2273 .llistxattr = smb_full_audit_llistxattr,
2274 .flistxattr = smb_full_audit_flistxattr,
2275 .removexattr = smb_full_audit_removexattr,
2276 .lremovexattr = smb_full_audit_lremovexattr,
2277 .fremovexattr = smb_full_audit_fremovexattr,
2278 .setxattr = smb_full_audit_setxattr,
2279 .lsetxattr = smb_full_audit_lsetxattr,
2280 .fsetxattr = smb_full_audit_fsetxattr,
2281 .aio_read = smb_full_audit_aio_read,
2282 .aio_write = smb_full_audit_aio_write,
2283 .aio_return_fn = smb_full_audit_aio_return,
2284 .aio_cancel = smb_full_audit_aio_cancel,
2285 .aio_error_fn = smb_full_audit_aio_error,
2286 .aio_fsync = smb_full_audit_aio_fsync,
2287 .aio_suspend = smb_full_audit_aio_suspend,
2288 .aio_force = smb_full_audit_aio_force,
2291 NTSTATUS vfs_full_audit_init(void)
2293 NTSTATUS ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION,
2294 "full_audit", &vfs_full_audit_fns);
2296 if (!NT_STATUS_IS_OK(ret))
2297 return ret;
2299 vfs_full_audit_debug_level = debug_add_class("full_audit");
2300 if (vfs_full_audit_debug_level == -1) {
2301 vfs_full_audit_debug_level = DBGC_VFS;
2302 DEBUG(0, ("vfs_full_audit: Couldn't register custom debugging "
2303 "class!\n"));
2304 } else {
2305 DEBUG(10, ("vfs_full_audit: Debug class number of "
2306 "'full_audit': %d\n", vfs_full_audit_debug_level));
2309 return ret;