vfs_full_audit: Remove some unnecessary return; statements
[Samba/gebeck_regimport.git] / source3 / modules / vfs_full_audit.c
blob3199503e521c079555b8004e9e7e70b4b3abb66f
1 /*
2 * Auditing VFS module for samba. Log selected file operations to syslog
3 * facility.
5 * Copyright (C) Tim Potter, 1999-2000
6 * Copyright (C) Alexander Bokovoy, 2002
7 * Copyright (C) John H Terpstra, 2003
8 * Copyright (C) Stefan (metze) Metzmacher, 2003
9 * Copyright (C) Volker Lendecke, 2004
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, see <http://www.gnu.org/licenses/>.
26 * This module implements parseable logging for all Samba VFS operations.
28 * You use it as follows:
30 * [tmp]
31 * path = /tmp
32 * vfs objects = full_audit
33 * full_audit:prefix = %u|%I
34 * full_audit:success = open opendir
35 * full_audit:failure = all
37 * vfs op can be "all" which means log all operations.
38 * vfs op can be "none" which means no logging.
40 * This leads to syslog entries of the form:
41 * smbd_audit: nobody|192.168.234.1|opendir|ok|.
42 * smbd_audit: nobody|192.168.234.1|open|fail (File not found)|r|x.txt
44 * where "nobody" is the connected username and "192.168.234.1" is the
45 * client's IP address.
47 * Options:
49 * prefix: A macro expansion template prepended to the syslog entry.
51 * success: A list of VFS operations for which a successful completion should
52 * be logged. Defaults to no logging at all. The special operation "all" logs
53 * - you guessed it - everything.
55 * failure: A list of VFS operations for which failure to complete should be
56 * logged. Defaults to logging everything.
60 #include "includes.h"
61 #include "system/filesys.h"
62 #include "system/syslog.h"
63 #include "smbd/smbd.h"
64 #include "../librpc/gen_ndr/ndr_netlogon.h"
65 #include "auth.h"
66 #include "ntioctl.h"
67 #include "lib/param/loadparm.h"
68 #include "lib/util/bitmap.h"
69 #include "lib/util/tevent_unix.h"
71 static int vfs_full_audit_debug_level = DBGC_VFS;
73 struct vfs_full_audit_private_data {
74 struct bitmap *success_ops;
75 struct bitmap *failure_ops;
78 #undef DBGC_CLASS
79 #define DBGC_CLASS vfs_full_audit_debug_level
81 typedef enum _vfs_op_type {
82 SMB_VFS_OP_NOOP = -1,
84 /* Disk operations */
86 SMB_VFS_OP_CONNECT = 0,
87 SMB_VFS_OP_DISCONNECT,
88 SMB_VFS_OP_DISK_FREE,
89 SMB_VFS_OP_GET_QUOTA,
90 SMB_VFS_OP_SET_QUOTA,
91 SMB_VFS_OP_GET_SHADOW_COPY_DATA,
92 SMB_VFS_OP_STATVFS,
93 SMB_VFS_OP_FS_CAPABILITIES,
95 /* Directory operations */
97 SMB_VFS_OP_OPENDIR,
98 SMB_VFS_OP_FDOPENDIR,
99 SMB_VFS_OP_READDIR,
100 SMB_VFS_OP_SEEKDIR,
101 SMB_VFS_OP_TELLDIR,
102 SMB_VFS_OP_REWINDDIR,
103 SMB_VFS_OP_MKDIR,
104 SMB_VFS_OP_RMDIR,
105 SMB_VFS_OP_CLOSEDIR,
106 SMB_VFS_OP_INIT_SEARCH_OP,
108 /* File operations */
110 SMB_VFS_OP_OPEN,
111 SMB_VFS_OP_CREATE_FILE,
112 SMB_VFS_OP_CLOSE,
113 SMB_VFS_OP_READ,
114 SMB_VFS_OP_PREAD,
115 SMB_VFS_OP_PREAD_SEND,
116 SMB_VFS_OP_PREAD_RECV,
117 SMB_VFS_OP_WRITE,
118 SMB_VFS_OP_PWRITE,
119 SMB_VFS_OP_PWRITE_SEND,
120 SMB_VFS_OP_PWRITE_RECV,
121 SMB_VFS_OP_LSEEK,
122 SMB_VFS_OP_SENDFILE,
123 SMB_VFS_OP_RECVFILE,
124 SMB_VFS_OP_RENAME,
125 SMB_VFS_OP_FSYNC,
126 SMB_VFS_OP_FSYNC_SEND,
127 SMB_VFS_OP_FSYNC_RECV,
128 SMB_VFS_OP_STAT,
129 SMB_VFS_OP_FSTAT,
130 SMB_VFS_OP_LSTAT,
131 SMB_VFS_OP_GET_ALLOC_SIZE,
132 SMB_VFS_OP_UNLINK,
133 SMB_VFS_OP_CHMOD,
134 SMB_VFS_OP_FCHMOD,
135 SMB_VFS_OP_CHOWN,
136 SMB_VFS_OP_FCHOWN,
137 SMB_VFS_OP_LCHOWN,
138 SMB_VFS_OP_CHDIR,
139 SMB_VFS_OP_GETWD,
140 SMB_VFS_OP_NTIMES,
141 SMB_VFS_OP_FTRUNCATE,
142 SMB_VFS_OP_FALLOCATE,
143 SMB_VFS_OP_LOCK,
144 SMB_VFS_OP_KERNEL_FLOCK,
145 SMB_VFS_OP_LINUX_SETLEASE,
146 SMB_VFS_OP_GETLOCK,
147 SMB_VFS_OP_SYMLINK,
148 SMB_VFS_OP_READLINK,
149 SMB_VFS_OP_LINK,
150 SMB_VFS_OP_MKNOD,
151 SMB_VFS_OP_REALPATH,
152 SMB_VFS_OP_NOTIFY_WATCH,
153 SMB_VFS_OP_CHFLAGS,
154 SMB_VFS_OP_FILE_ID_CREATE,
155 SMB_VFS_OP_STREAMINFO,
156 SMB_VFS_OP_GET_REAL_FILENAME,
157 SMB_VFS_OP_CONNECTPATH,
158 SMB_VFS_OP_BRL_LOCK_WINDOWS,
159 SMB_VFS_OP_BRL_UNLOCK_WINDOWS,
160 SMB_VFS_OP_BRL_CANCEL_WINDOWS,
161 SMB_VFS_OP_STRICT_LOCK,
162 SMB_VFS_OP_STRICT_UNLOCK,
163 SMB_VFS_OP_TRANSLATE_NAME,
165 /* NT ACL operations. */
167 SMB_VFS_OP_FGET_NT_ACL,
168 SMB_VFS_OP_GET_NT_ACL,
169 SMB_VFS_OP_FSET_NT_ACL,
171 /* POSIX ACL operations. */
173 SMB_VFS_OP_CHMOD_ACL,
174 SMB_VFS_OP_FCHMOD_ACL,
176 SMB_VFS_OP_SYS_ACL_GET_ENTRY,
177 SMB_VFS_OP_SYS_ACL_GET_TAG_TYPE,
178 SMB_VFS_OP_SYS_ACL_GET_PERMSET,
179 SMB_VFS_OP_SYS_ACL_GET_QUALIFIER,
180 SMB_VFS_OP_SYS_ACL_GET_FILE,
181 SMB_VFS_OP_SYS_ACL_GET_FD,
182 SMB_VFS_OP_SYS_ACL_CLEAR_PERMS,
183 SMB_VFS_OP_SYS_ACL_ADD_PERM,
184 SMB_VFS_OP_SYS_ACL_TO_TEXT,
185 SMB_VFS_OP_SYS_ACL_INIT,
186 SMB_VFS_OP_SYS_ACL_CREATE_ENTRY,
187 SMB_VFS_OP_SYS_ACL_SET_TAG_TYPE,
188 SMB_VFS_OP_SYS_ACL_SET_QUALIFIER,
189 SMB_VFS_OP_SYS_ACL_SET_PERMSET,
190 SMB_VFS_OP_SYS_ACL_VALID,
191 SMB_VFS_OP_SYS_ACL_SET_FILE,
192 SMB_VFS_OP_SYS_ACL_SET_FD,
193 SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE,
194 SMB_VFS_OP_SYS_ACL_GET_PERM,
195 SMB_VFS_OP_SYS_ACL_FREE_TEXT,
196 SMB_VFS_OP_SYS_ACL_FREE_ACL,
197 SMB_VFS_OP_SYS_ACL_FREE_QUALIFIER,
199 /* EA operations. */
200 SMB_VFS_OP_GETXATTR,
201 SMB_VFS_OP_FGETXATTR,
202 SMB_VFS_OP_LISTXATTR,
203 SMB_VFS_OP_FLISTXATTR,
204 SMB_VFS_OP_REMOVEXATTR,
205 SMB_VFS_OP_FREMOVEXATTR,
206 SMB_VFS_OP_SETXATTR,
207 SMB_VFS_OP_FSETXATTR,
209 /* aio operations */
210 SMB_VFS_OP_AIO_FORCE,
212 /* offline operations */
213 SMB_VFS_OP_IS_OFFLINE,
214 SMB_VFS_OP_SET_OFFLINE,
216 /* This should always be last enum value */
218 SMB_VFS_OP_LAST
219 } vfs_op_type;
221 /* The following array *must* be in the same order as defined in vfs.h */
223 static struct {
224 vfs_op_type type;
225 const char *name;
226 } vfs_op_names[] = {
227 { SMB_VFS_OP_CONNECT, "connect" },
228 { SMB_VFS_OP_DISCONNECT, "disconnect" },
229 { SMB_VFS_OP_DISK_FREE, "disk_free" },
230 { SMB_VFS_OP_GET_QUOTA, "get_quota" },
231 { SMB_VFS_OP_SET_QUOTA, "set_quota" },
232 { SMB_VFS_OP_GET_SHADOW_COPY_DATA, "get_shadow_copy_data" },
233 { SMB_VFS_OP_STATVFS, "statvfs" },
234 { SMB_VFS_OP_FS_CAPABILITIES, "fs_capabilities" },
235 { SMB_VFS_OP_OPENDIR, "opendir" },
236 { SMB_VFS_OP_FDOPENDIR, "fdopendir" },
237 { SMB_VFS_OP_READDIR, "readdir" },
238 { SMB_VFS_OP_SEEKDIR, "seekdir" },
239 { SMB_VFS_OP_TELLDIR, "telldir" },
240 { SMB_VFS_OP_REWINDDIR, "rewinddir" },
241 { SMB_VFS_OP_MKDIR, "mkdir" },
242 { SMB_VFS_OP_RMDIR, "rmdir" },
243 { SMB_VFS_OP_CLOSEDIR, "closedir" },
244 { SMB_VFS_OP_INIT_SEARCH_OP, "init_search_op" },
245 { SMB_VFS_OP_OPEN, "open" },
246 { SMB_VFS_OP_CREATE_FILE, "create_file" },
247 { SMB_VFS_OP_CLOSE, "close" },
248 { SMB_VFS_OP_READ, "read" },
249 { SMB_VFS_OP_PREAD, "pread" },
250 { SMB_VFS_OP_PREAD_SEND, "pread_send" },
251 { SMB_VFS_OP_PREAD_RECV, "pread_recv" },
252 { SMB_VFS_OP_WRITE, "write" },
253 { SMB_VFS_OP_PWRITE, "pwrite" },
254 { SMB_VFS_OP_LSEEK, "lseek" },
255 { SMB_VFS_OP_SENDFILE, "sendfile" },
256 { SMB_VFS_OP_RECVFILE, "recvfile" },
257 { SMB_VFS_OP_RENAME, "rename" },
258 { SMB_VFS_OP_FSYNC, "fsync" },
259 { SMB_VFS_OP_FSYNC_SEND, "fsync_send" },
260 { SMB_VFS_OP_FSYNC_RECV, "fsync_recv" },
261 { SMB_VFS_OP_STAT, "stat" },
262 { SMB_VFS_OP_FSTAT, "fstat" },
263 { SMB_VFS_OP_LSTAT, "lstat" },
264 { SMB_VFS_OP_GET_ALLOC_SIZE, "get_alloc_size" },
265 { SMB_VFS_OP_UNLINK, "unlink" },
266 { SMB_VFS_OP_CHMOD, "chmod" },
267 { SMB_VFS_OP_FCHMOD, "fchmod" },
268 { SMB_VFS_OP_CHOWN, "chown" },
269 { SMB_VFS_OP_FCHOWN, "fchown" },
270 { SMB_VFS_OP_LCHOWN, "lchown" },
271 { SMB_VFS_OP_CHDIR, "chdir" },
272 { SMB_VFS_OP_GETWD, "getwd" },
273 { SMB_VFS_OP_NTIMES, "ntimes" },
274 { SMB_VFS_OP_FTRUNCATE, "ftruncate" },
275 { SMB_VFS_OP_FALLOCATE,"fallocate" },
276 { SMB_VFS_OP_LOCK, "lock" },
277 { SMB_VFS_OP_KERNEL_FLOCK, "kernel_flock" },
278 { SMB_VFS_OP_LINUX_SETLEASE, "linux_setlease" },
279 { SMB_VFS_OP_GETLOCK, "getlock" },
280 { SMB_VFS_OP_SYMLINK, "symlink" },
281 { SMB_VFS_OP_READLINK, "readlink" },
282 { SMB_VFS_OP_LINK, "link" },
283 { SMB_VFS_OP_MKNOD, "mknod" },
284 { SMB_VFS_OP_REALPATH, "realpath" },
285 { SMB_VFS_OP_NOTIFY_WATCH, "notify_watch" },
286 { SMB_VFS_OP_CHFLAGS, "chflags" },
287 { SMB_VFS_OP_FILE_ID_CREATE, "file_id_create" },
288 { SMB_VFS_OP_STREAMINFO, "streaminfo" },
289 { SMB_VFS_OP_GET_REAL_FILENAME, "get_real_filename" },
290 { SMB_VFS_OP_CONNECTPATH, "connectpath" },
291 { SMB_VFS_OP_BRL_LOCK_WINDOWS, "brl_lock_windows" },
292 { SMB_VFS_OP_BRL_UNLOCK_WINDOWS, "brl_unlock_windows" },
293 { SMB_VFS_OP_BRL_CANCEL_WINDOWS, "brl_cancel_windows" },
294 { SMB_VFS_OP_STRICT_LOCK, "strict_lock" },
295 { SMB_VFS_OP_STRICT_UNLOCK, "strict_unlock" },
296 { SMB_VFS_OP_TRANSLATE_NAME, "translate_name" },
297 { SMB_VFS_OP_FGET_NT_ACL, "fget_nt_acl" },
298 { SMB_VFS_OP_GET_NT_ACL, "get_nt_acl" },
299 { SMB_VFS_OP_FSET_NT_ACL, "fset_nt_acl" },
300 { SMB_VFS_OP_CHMOD_ACL, "chmod_acl" },
301 { SMB_VFS_OP_FCHMOD_ACL, "fchmod_acl" },
302 { SMB_VFS_OP_SYS_ACL_GET_ENTRY, "sys_acl_get_entry" },
303 { SMB_VFS_OP_SYS_ACL_GET_TAG_TYPE, "sys_acl_get_tag_type" },
304 { SMB_VFS_OP_SYS_ACL_GET_PERMSET, "sys_acl_get_permset" },
305 { SMB_VFS_OP_SYS_ACL_GET_QUALIFIER, "sys_acl_get_qualifier" },
306 { SMB_VFS_OP_SYS_ACL_GET_FILE, "sys_acl_get_file" },
307 { SMB_VFS_OP_SYS_ACL_GET_FD, "sys_acl_get_fd" },
308 { SMB_VFS_OP_SYS_ACL_CLEAR_PERMS, "sys_acl_clear_perms" },
309 { SMB_VFS_OP_SYS_ACL_ADD_PERM, "sys_acl_add_perm" },
310 { SMB_VFS_OP_SYS_ACL_TO_TEXT, "sys_acl_to_text" },
311 { SMB_VFS_OP_SYS_ACL_INIT, "sys_acl_init" },
312 { SMB_VFS_OP_SYS_ACL_CREATE_ENTRY, "sys_acl_create_entry" },
313 { SMB_VFS_OP_SYS_ACL_SET_TAG_TYPE, "sys_acl_set_tag_type" },
314 { SMB_VFS_OP_SYS_ACL_SET_QUALIFIER, "sys_acl_set_qualifier" },
315 { SMB_VFS_OP_SYS_ACL_SET_PERMSET, "sys_acl_set_permset" },
316 { SMB_VFS_OP_SYS_ACL_VALID, "sys_acl_valid" },
317 { SMB_VFS_OP_SYS_ACL_SET_FILE, "sys_acl_set_file" },
318 { SMB_VFS_OP_SYS_ACL_SET_FD, "sys_acl_set_fd" },
319 { SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE, "sys_acl_delete_def_file" },
320 { SMB_VFS_OP_SYS_ACL_GET_PERM, "sys_acl_get_perm" },
321 { SMB_VFS_OP_SYS_ACL_FREE_TEXT, "sys_acl_free_text" },
322 { SMB_VFS_OP_SYS_ACL_FREE_ACL, "sys_acl_free_acl" },
323 { SMB_VFS_OP_SYS_ACL_FREE_QUALIFIER, "sys_acl_free_qualifier" },
324 { SMB_VFS_OP_GETXATTR, "getxattr" },
325 { SMB_VFS_OP_FGETXATTR, "fgetxattr" },
326 { SMB_VFS_OP_LISTXATTR, "listxattr" },
327 { SMB_VFS_OP_FLISTXATTR, "flistxattr" },
328 { SMB_VFS_OP_REMOVEXATTR, "removexattr" },
329 { SMB_VFS_OP_FREMOVEXATTR, "fremovexattr" },
330 { SMB_VFS_OP_SETXATTR, "setxattr" },
331 { SMB_VFS_OP_FSETXATTR, "fsetxattr" },
332 { SMB_VFS_OP_AIO_FORCE, "aio_force" },
333 { SMB_VFS_OP_IS_OFFLINE, "is_offline" },
334 { SMB_VFS_OP_SET_OFFLINE, "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" },
350 { -1, NULL}
353 int facility;
355 facility = lp_parm_enum(SNUM(handle->conn), "full_audit", "facility", enum_log_facilities, LOG_USER);
357 return facility;
360 static int audit_syslog_priority(vfs_handle_struct *handle)
362 static const struct enum_list enum_log_priorities[] = {
363 { LOG_EMERG, "EMERG" },
364 { LOG_ALERT, "ALERT" },
365 { LOG_CRIT, "CRIT" },
366 { LOG_ERR, "ERR" },
367 { LOG_WARNING, "WARNING" },
368 { LOG_NOTICE, "NOTICE" },
369 { LOG_INFO, "INFO" },
370 { LOG_DEBUG, "DEBUG" },
371 { -1, NULL}
374 int priority;
376 priority = lp_parm_enum(SNUM(handle->conn), "full_audit", "priority",
377 enum_log_priorities, LOG_NOTICE);
378 if (priority == -1) {
379 priority = LOG_WARNING;
382 return priority;
385 static char *audit_prefix(TALLOC_CTX *ctx, connection_struct *conn)
387 char *prefix = NULL;
388 char *result;
390 prefix = talloc_strdup(ctx,
391 lp_parm_const_string(SNUM(conn), "full_audit",
392 "prefix", "%u|%I"));
393 if (!prefix) {
394 return NULL;
396 result = talloc_sub_advanced(ctx,
397 lp_servicename(talloc_tos(), SNUM(conn)),
398 conn->session_info->unix_info->unix_name,
399 conn->connectpath,
400 conn->session_info->unix_token->gid,
401 conn->session_info->unix_info->sanitized_username,
402 conn->session_info->info->domain_name,
403 prefix);
404 TALLOC_FREE(prefix);
405 return result;
408 static bool log_success(vfs_handle_struct *handle, vfs_op_type op)
410 struct vfs_full_audit_private_data *pd = NULL;
412 SMB_VFS_HANDLE_GET_DATA(handle, pd,
413 struct vfs_full_audit_private_data,
414 return True);
416 if (pd->success_ops == NULL) {
417 return True;
420 return bitmap_query(pd->success_ops, op);
423 static bool log_failure(vfs_handle_struct *handle, vfs_op_type op)
425 struct vfs_full_audit_private_data *pd = NULL;
427 SMB_VFS_HANDLE_GET_DATA(handle, pd,
428 struct vfs_full_audit_private_data,
429 return True);
431 if (pd->failure_ops == NULL)
432 return True;
434 return bitmap_query(pd->failure_ops, op);
437 static struct bitmap *init_bitmap(TALLOC_CTX *mem_ctx, const char **ops)
439 struct bitmap *bm;
441 if (ops == NULL) {
442 return NULL;
445 bm = bitmap_talloc(mem_ctx, SMB_VFS_OP_LAST);
446 if (bm == NULL) {
447 DEBUG(0, ("Could not alloc bitmap -- "
448 "defaulting to logging everything\n"));
449 return NULL;
452 for (; *ops != NULL; ops += 1) {
453 int i;
454 bool neg = false;
455 const char *op;
457 if (strequal(*ops, "all")) {
458 for (i=0; i<SMB_VFS_OP_LAST; i++) {
459 bitmap_set(bm, i);
461 continue;
464 if (strequal(*ops, "none")) {
465 break;
468 op = ops[0];
469 if (op[0] == '!') {
470 neg = true;
471 op += 1;
474 for (i=0; i<SMB_VFS_OP_LAST; i++) {
475 if (vfs_op_names[i].name == NULL) {
476 smb_panic("vfs_full_audit.c: name table not "
477 "in sync with vfs.h\n");
479 if (strequal(op, vfs_op_names[i].name)) {
480 if (neg) {
481 bitmap_clear(bm, i);
482 } else {
483 bitmap_set(bm, i);
485 break;
488 if (i == SMB_VFS_OP_LAST) {
489 DEBUG(0, ("Could not find opname %s, logging all\n",
490 *ops));
491 TALLOC_FREE(bm);
492 return NULL;
495 return bm;
498 static const char *audit_opname(vfs_op_type op)
500 if (op >= SMB_VFS_OP_LAST)
501 return "INVALID VFS OP";
502 return vfs_op_names[op].name;
505 static TALLOC_CTX *tmp_do_log_ctx;
507 * Get us a temporary talloc context usable just for DEBUG arguments
509 static TALLOC_CTX *do_log_ctx(void)
511 if (tmp_do_log_ctx == NULL) {
512 tmp_do_log_ctx = talloc_named_const(NULL, 0, "do_log_ctx");
514 return tmp_do_log_ctx;
517 static void do_log(vfs_op_type op, bool success, vfs_handle_struct *handle,
518 const char *format, ...)
520 fstring err_msg;
521 char *audit_pre = NULL;
522 va_list ap;
523 char *op_msg = NULL;
524 int priority;
526 if (success && (!log_success(handle, op)))
527 goto out;
529 if (!success && (!log_failure(handle, op)))
530 goto out;
532 if (success)
533 fstrcpy(err_msg, "ok");
534 else
535 fstr_sprintf(err_msg, "fail (%s)", strerror(errno));
537 va_start(ap, format);
538 op_msg = talloc_vasprintf(talloc_tos(), format, ap);
539 va_end(ap);
541 if (!op_msg) {
542 goto out;
546 * Specify the facility to interoperate with other syslog callers
547 * (smbd for example).
549 priority = audit_syslog_priority(handle) |
550 audit_syslog_facility(handle);
552 audit_pre = audit_prefix(talloc_tos(), handle->conn);
553 syslog(priority, "%s|%s|%s|%s\n",
554 audit_pre ? audit_pre : "",
555 audit_opname(op), err_msg, op_msg);
557 out:
558 TALLOC_FREE(audit_pre);
559 TALLOC_FREE(op_msg);
560 TALLOC_FREE(tmp_do_log_ctx);
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(handle, struct vfs_full_audit_private_data);
604 if (!pd) {
605 SMB_VFS_NEXT_DISCONNECT(handle);
606 return -1;
609 #ifdef 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(talloc_tos(), SNUM(handle->conn)));
637 /* The bitmaps will be disconnected when the private
638 data is deleted. */
641 static uint64_t smb_full_audit_disk_free(vfs_handle_struct *handle,
642 const char *path,
643 bool small_query, uint64_t *bsize,
644 uint64_t *dfree, uint64_t *dsize)
646 uint64_t result;
648 result = SMB_VFS_NEXT_DISK_FREE(handle, path, small_query, bsize,
649 dfree, dsize);
651 /* Don't have a reasonable notion of failure here */
653 do_log(SMB_VFS_OP_DISK_FREE, True, handle, "%s", path);
655 return result;
658 static int smb_full_audit_get_quota(struct vfs_handle_struct *handle,
659 enum SMB_QUOTA_TYPE qtype, unid_t id,
660 SMB_DISK_QUOTA *qt)
662 int result;
664 result = SMB_VFS_NEXT_GET_QUOTA(handle, qtype, id, qt);
666 do_log(SMB_VFS_OP_GET_QUOTA, (result >= 0), handle, "");
668 return result;
672 static int smb_full_audit_set_quota(struct vfs_handle_struct *handle,
673 enum SMB_QUOTA_TYPE qtype, unid_t id,
674 SMB_DISK_QUOTA *qt)
676 int result;
678 result = SMB_VFS_NEXT_SET_QUOTA(handle, qtype, id, qt);
680 do_log(SMB_VFS_OP_SET_QUOTA, (result >= 0), handle, "");
682 return result;
685 static int smb_full_audit_get_shadow_copy_data(struct vfs_handle_struct *handle,
686 struct files_struct *fsp,
687 struct shadow_copy_data *shadow_copy_data,
688 bool labels)
690 int result;
692 result = SMB_VFS_NEXT_GET_SHADOW_COPY_DATA(handle, fsp, shadow_copy_data, labels);
694 do_log(SMB_VFS_OP_GET_SHADOW_COPY_DATA, (result >= 0), handle, "");
696 return result;
699 static int smb_full_audit_statvfs(struct vfs_handle_struct *handle,
700 const char *path,
701 struct vfs_statvfs_struct *statbuf)
703 int result;
705 result = SMB_VFS_NEXT_STATVFS(handle, path, statbuf);
707 do_log(SMB_VFS_OP_STATVFS, (result >= 0), handle, "");
709 return result;
712 static uint32_t smb_full_audit_fs_capabilities(struct vfs_handle_struct *handle, enum timestamp_set_resolution *p_ts_res)
714 int result;
716 result = SMB_VFS_NEXT_FS_CAPABILITIES(handle, p_ts_res);
718 do_log(SMB_VFS_OP_FS_CAPABILITIES, true, handle, "");
720 return result;
723 static DIR *smb_full_audit_opendir(vfs_handle_struct *handle,
724 const char *fname, const char *mask, uint32 attr)
726 DIR *result;
728 result = SMB_VFS_NEXT_OPENDIR(handle, fname, mask, attr);
730 do_log(SMB_VFS_OP_OPENDIR, (result != NULL), handle, "%s", fname);
732 return result;
735 static DIR *smb_full_audit_fdopendir(vfs_handle_struct *handle,
736 files_struct *fsp, const char *mask, uint32 attr)
738 DIR *result;
740 result = SMB_VFS_NEXT_FDOPENDIR(handle, fsp, mask, attr);
742 do_log(SMB_VFS_OP_FDOPENDIR, (result != NULL), handle, "%s",
743 fsp_str_do_log(fsp));
745 return result;
748 static struct dirent *smb_full_audit_readdir(vfs_handle_struct *handle,
749 DIR *dirp, SMB_STRUCT_STAT *sbuf)
751 struct dirent *result;
753 result = SMB_VFS_NEXT_READDIR(handle, dirp, sbuf);
755 /* This operation has no reasonable error condition
756 * (End of dir is also failure), so always succeed.
758 do_log(SMB_VFS_OP_READDIR, True, handle, "");
760 return result;
763 static void smb_full_audit_seekdir(vfs_handle_struct *handle,
764 DIR *dirp, long offset)
766 SMB_VFS_NEXT_SEEKDIR(handle, dirp, offset);
768 do_log(SMB_VFS_OP_SEEKDIR, True, handle, "");
771 static long smb_full_audit_telldir(vfs_handle_struct *handle,
772 DIR *dirp)
774 long result;
776 result = SMB_VFS_NEXT_TELLDIR(handle, dirp);
778 do_log(SMB_VFS_OP_TELLDIR, True, handle, "");
780 return result;
783 static void smb_full_audit_rewinddir(vfs_handle_struct *handle,
784 DIR *dirp)
786 SMB_VFS_NEXT_REWINDDIR(handle, dirp);
788 do_log(SMB_VFS_OP_REWINDDIR, True, handle, "");
791 static int smb_full_audit_mkdir(vfs_handle_struct *handle,
792 const char *path, mode_t mode)
794 int result;
796 result = SMB_VFS_NEXT_MKDIR(handle, path, mode);
798 do_log(SMB_VFS_OP_MKDIR, (result >= 0), handle, "%s", path);
800 return result;
803 static int smb_full_audit_rmdir(vfs_handle_struct *handle,
804 const char *path)
806 int result;
808 result = SMB_VFS_NEXT_RMDIR(handle, path);
810 do_log(SMB_VFS_OP_RMDIR, (result >= 0), handle, "%s", path);
812 return result;
815 static int smb_full_audit_closedir(vfs_handle_struct *handle,
816 DIR *dirp)
818 int result;
820 result = SMB_VFS_NEXT_CLOSEDIR(handle, dirp);
822 do_log(SMB_VFS_OP_CLOSEDIR, (result >= 0), handle, "");
824 return result;
827 static void smb_full_audit_init_search_op(vfs_handle_struct *handle,
828 DIR *dirp)
830 SMB_VFS_NEXT_INIT_SEARCH_OP(handle, dirp);
832 do_log(SMB_VFS_OP_INIT_SEARCH_OP, True, handle, "");
835 static int smb_full_audit_open(vfs_handle_struct *handle,
836 struct smb_filename *smb_fname,
837 files_struct *fsp, int flags, mode_t mode)
839 int result;
841 result = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
843 do_log(SMB_VFS_OP_OPEN, (result >= 0), handle, "%s|%s",
844 ((flags & O_WRONLY) || (flags & O_RDWR))?"w":"r",
845 smb_fname_str_do_log(smb_fname));
847 return result;
850 static NTSTATUS smb_full_audit_create_file(vfs_handle_struct *handle,
851 struct smb_request *req,
852 uint16_t root_dir_fid,
853 struct smb_filename *smb_fname,
854 uint32_t access_mask,
855 uint32_t share_access,
856 uint32_t create_disposition,
857 uint32_t create_options,
858 uint32_t file_attributes,
859 uint32_t oplock_request,
860 uint64_t allocation_size,
861 uint32_t private_flags,
862 struct security_descriptor *sd,
863 struct ea_list *ea_list,
864 files_struct **result_fsp,
865 int *pinfo)
867 NTSTATUS result;
868 const char* str_create_disposition;
870 switch (create_disposition) {
871 case FILE_SUPERSEDE:
872 str_create_disposition = "supersede";
873 break;
874 case FILE_OVERWRITE_IF:
875 str_create_disposition = "overwrite_if";
876 break;
877 case FILE_OPEN:
878 str_create_disposition = "open";
879 break;
880 case FILE_OVERWRITE:
881 str_create_disposition = "overwrite";
882 break;
883 case FILE_CREATE:
884 str_create_disposition = "create";
885 break;
886 case FILE_OPEN_IF:
887 str_create_disposition = "open_if";
888 break;
889 default:
890 str_create_disposition = "unknown";
893 result = SMB_VFS_NEXT_CREATE_FILE(
894 handle, /* handle */
895 req, /* req */
896 root_dir_fid, /* root_dir_fid */
897 smb_fname, /* fname */
898 access_mask, /* access_mask */
899 share_access, /* share_access */
900 create_disposition, /* create_disposition*/
901 create_options, /* create_options */
902 file_attributes, /* file_attributes */
903 oplock_request, /* oplock_request */
904 allocation_size, /* allocation_size */
905 private_flags,
906 sd, /* sd */
907 ea_list, /* ea_list */
908 result_fsp, /* result */
909 pinfo); /* pinfo */
911 do_log(SMB_VFS_OP_CREATE_FILE, (NT_STATUS_IS_OK(result)), handle,
912 "0x%x|%s|%s|%s", access_mask,
913 create_options & FILE_DIRECTORY_FILE ? "dir" : "file",
914 str_create_disposition, smb_fname_str_do_log(smb_fname));
916 return result;
919 static int smb_full_audit_close(vfs_handle_struct *handle, files_struct *fsp)
921 int result;
923 result = SMB_VFS_NEXT_CLOSE(handle, fsp);
925 do_log(SMB_VFS_OP_CLOSE, (result >= 0), handle, "%s",
926 fsp_str_do_log(fsp));
928 return result;
931 static ssize_t smb_full_audit_read(vfs_handle_struct *handle, files_struct *fsp,
932 void *data, size_t n)
934 ssize_t result;
936 result = SMB_VFS_NEXT_READ(handle, fsp, data, n);
938 do_log(SMB_VFS_OP_READ, (result >= 0), handle, "%s",
939 fsp_str_do_log(fsp));
941 return result;
944 static ssize_t smb_full_audit_pread(vfs_handle_struct *handle, files_struct *fsp,
945 void *data, size_t n, off_t offset)
947 ssize_t result;
949 result = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
951 do_log(SMB_VFS_OP_PREAD, (result >= 0), handle, "%s",
952 fsp_str_do_log(fsp));
954 return result;
957 struct smb_full_audit_pread_state {
958 vfs_handle_struct *handle;
959 files_struct *fsp;
960 ssize_t ret;
961 int err;
964 static void smb_full_audit_pread_done(struct tevent_req *subreq);
966 static struct tevent_req *smb_full_audit_pread_send(
967 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
968 struct tevent_context *ev, struct files_struct *fsp,
969 void *data, size_t n, off_t offset)
971 struct tevent_req *req, *subreq;
972 struct smb_full_audit_pread_state *state;
974 req = tevent_req_create(mem_ctx, &state,
975 struct smb_full_audit_pread_state);
976 if (req == NULL) {
977 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
978 fsp_str_do_log(fsp));
979 return NULL;
981 state->handle = handle;
982 state->fsp = fsp;
984 subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
985 n, offset);
986 if (tevent_req_nomem(subreq, req)) {
987 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
988 fsp_str_do_log(fsp));
989 return tevent_req_post(req, ev);
991 tevent_req_set_callback(subreq, smb_full_audit_pread_done, req);
993 do_log(SMB_VFS_OP_PREAD_SEND, true, handle, "%s", fsp_str_do_log(fsp));
994 return req;
997 static void smb_full_audit_pread_done(struct tevent_req *subreq)
999 struct tevent_req *req = tevent_req_callback_data(
1000 subreq, struct tevent_req);
1001 struct smb_full_audit_pread_state *state = tevent_req_data(
1002 req, struct smb_full_audit_pread_state);
1004 state->ret = SMB_VFS_PREAD_RECV(subreq, &state->err);
1005 TALLOC_FREE(subreq);
1006 tevent_req_done(req);
1009 static ssize_t smb_full_audit_pread_recv(struct tevent_req *req, int *err)
1011 struct smb_full_audit_pread_state *state = tevent_req_data(
1012 req, struct smb_full_audit_pread_state);
1014 if (tevent_req_is_unix_error(req, err)) {
1015 do_log(SMB_VFS_OP_PREAD_RECV, false, state->handle, "%s",
1016 fsp_str_do_log(state->fsp));
1017 return -1;
1020 do_log(SMB_VFS_OP_PREAD_RECV, (state->ret >= 0), state->handle, "%s",
1021 fsp_str_do_log(state->fsp));
1023 *err = state->err;
1024 return state->ret;
1027 static ssize_t smb_full_audit_write(vfs_handle_struct *handle, files_struct *fsp,
1028 const void *data, size_t n)
1030 ssize_t result;
1032 result = SMB_VFS_NEXT_WRITE(handle, fsp, data, n);
1034 do_log(SMB_VFS_OP_WRITE, (result >= 0), handle, "%s",
1035 fsp_str_do_log(fsp));
1037 return result;
1040 static ssize_t smb_full_audit_pwrite(vfs_handle_struct *handle, files_struct *fsp,
1041 const void *data, size_t n,
1042 off_t offset)
1044 ssize_t result;
1046 result = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
1048 do_log(SMB_VFS_OP_PWRITE, (result >= 0), handle, "%s",
1049 fsp_str_do_log(fsp));
1051 return result;
1054 struct smb_full_audit_pwrite_state {
1055 vfs_handle_struct *handle;
1056 files_struct *fsp;
1057 ssize_t ret;
1058 int err;
1061 static void smb_full_audit_pwrite_done(struct tevent_req *subreq);
1063 static struct tevent_req *smb_full_audit_pwrite_send(
1064 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1065 struct tevent_context *ev, struct files_struct *fsp,
1066 const void *data, size_t n, off_t offset)
1068 struct tevent_req *req, *subreq;
1069 struct smb_full_audit_pwrite_state *state;
1071 req = tevent_req_create(mem_ctx, &state,
1072 struct smb_full_audit_pwrite_state);
1073 if (req == NULL) {
1074 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1075 fsp_str_do_log(fsp));
1076 return NULL;
1078 state->handle = handle;
1079 state->fsp = fsp;
1081 subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
1082 n, offset);
1083 if (tevent_req_nomem(subreq, req)) {
1084 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1085 fsp_str_do_log(fsp));
1086 return tevent_req_post(req, ev);
1088 tevent_req_set_callback(subreq, smb_full_audit_pwrite_done, req);
1090 do_log(SMB_VFS_OP_PWRITE_SEND, true, handle, "%s",
1091 fsp_str_do_log(fsp));
1092 return req;
1095 static void smb_full_audit_pwrite_done(struct tevent_req *subreq)
1097 struct tevent_req *req = tevent_req_callback_data(
1098 subreq, struct tevent_req);
1099 struct smb_full_audit_pwrite_state *state = tevent_req_data(
1100 req, struct smb_full_audit_pwrite_state);
1102 state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->err);
1103 TALLOC_FREE(subreq);
1104 tevent_req_done(req);
1107 static ssize_t smb_full_audit_pwrite_recv(struct tevent_req *req, int *err)
1109 struct smb_full_audit_pwrite_state *state = tevent_req_data(
1110 req, struct smb_full_audit_pwrite_state);
1112 if (tevent_req_is_unix_error(req, err)) {
1113 do_log(SMB_VFS_OP_PWRITE_RECV, false, state->handle, "%s",
1114 fsp_str_do_log(state->fsp));
1115 return -1;
1118 do_log(SMB_VFS_OP_PWRITE_RECV, (state->ret >= 0), state->handle, "%s",
1119 fsp_str_do_log(state->fsp));
1121 *err = state->err;
1122 return state->ret;
1125 static off_t smb_full_audit_lseek(vfs_handle_struct *handle, files_struct *fsp,
1126 off_t offset, int whence)
1128 ssize_t result;
1130 result = SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence);
1132 do_log(SMB_VFS_OP_LSEEK, (result != (ssize_t)-1), handle,
1133 "%s", fsp_str_do_log(fsp));
1135 return result;
1138 static ssize_t smb_full_audit_sendfile(vfs_handle_struct *handle, int tofd,
1139 files_struct *fromfsp,
1140 const DATA_BLOB *hdr, off_t offset,
1141 size_t n)
1143 ssize_t result;
1145 result = SMB_VFS_NEXT_SENDFILE(handle, tofd, fromfsp, hdr, offset, n);
1147 do_log(SMB_VFS_OP_SENDFILE, (result >= 0), handle,
1148 "%s", fsp_str_do_log(fromfsp));
1150 return result;
1153 static ssize_t smb_full_audit_recvfile(vfs_handle_struct *handle, int fromfd,
1154 files_struct *tofsp,
1155 off_t offset,
1156 size_t n)
1158 ssize_t result;
1160 result = SMB_VFS_NEXT_RECVFILE(handle, fromfd, tofsp, offset, n);
1162 do_log(SMB_VFS_OP_RECVFILE, (result >= 0), handle,
1163 "%s", fsp_str_do_log(tofsp));
1165 return result;
1168 static int smb_full_audit_rename(vfs_handle_struct *handle,
1169 const struct smb_filename *smb_fname_src,
1170 const struct smb_filename *smb_fname_dst)
1172 int result;
1174 result = SMB_VFS_NEXT_RENAME(handle, smb_fname_src, smb_fname_dst);
1176 do_log(SMB_VFS_OP_RENAME, (result >= 0), handle, "%s|%s",
1177 smb_fname_str_do_log(smb_fname_src),
1178 smb_fname_str_do_log(smb_fname_dst));
1180 return result;
1183 static int smb_full_audit_fsync(vfs_handle_struct *handle, files_struct *fsp)
1185 int result;
1187 result = SMB_VFS_NEXT_FSYNC(handle, fsp);
1189 do_log(SMB_VFS_OP_FSYNC, (result >= 0), handle, "%s",
1190 fsp_str_do_log(fsp));
1192 return result;
1195 struct smb_full_audit_fsync_state {
1196 vfs_handle_struct *handle;
1197 files_struct *fsp;
1198 int ret;
1199 int err;
1202 static void smb_full_audit_fsync_done(struct tevent_req *subreq);
1204 static struct tevent_req *smb_full_audit_fsync_send(
1205 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1206 struct tevent_context *ev, struct files_struct *fsp)
1208 struct tevent_req *req, *subreq;
1209 struct smb_full_audit_fsync_state *state;
1211 req = tevent_req_create(mem_ctx, &state,
1212 struct smb_full_audit_fsync_state);
1213 if (req == NULL) {
1214 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1215 fsp_str_do_log(fsp));
1216 return NULL;
1218 state->handle = handle;
1219 state->fsp = fsp;
1221 subreq = SMB_VFS_NEXT_FSYNC_SEND(state, ev, handle, fsp);
1222 if (tevent_req_nomem(subreq, req)) {
1223 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1224 fsp_str_do_log(fsp));
1225 return tevent_req_post(req, ev);
1227 tevent_req_set_callback(subreq, smb_full_audit_fsync_done, req);
1229 do_log(SMB_VFS_OP_FSYNC_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1230 return req;
1233 static void smb_full_audit_fsync_done(struct tevent_req *subreq)
1235 struct tevent_req *req = tevent_req_callback_data(
1236 subreq, struct tevent_req);
1237 struct smb_full_audit_fsync_state *state = tevent_req_data(
1238 req, struct smb_full_audit_fsync_state);
1240 state->ret = SMB_VFS_FSYNC_RECV(subreq, &state->err);
1241 TALLOC_FREE(subreq);
1242 tevent_req_done(req);
1245 static int smb_full_audit_fsync_recv(struct tevent_req *req, int *err)
1247 struct smb_full_audit_fsync_state *state = tevent_req_data(
1248 req, struct smb_full_audit_fsync_state);
1250 if (tevent_req_is_unix_error(req, err)) {
1251 do_log(SMB_VFS_OP_FSYNC_RECV, false, state->handle, "%s",
1252 fsp_str_do_log(state->fsp));
1253 return -1;
1256 do_log(SMB_VFS_OP_FSYNC_RECV, (state->ret >= 0), state->handle, "%s",
1257 fsp_str_do_log(state->fsp));
1259 *err = state->err;
1260 return state->ret;
1263 static int smb_full_audit_stat(vfs_handle_struct *handle,
1264 struct smb_filename *smb_fname)
1266 int result;
1268 result = SMB_VFS_NEXT_STAT(handle, smb_fname);
1270 do_log(SMB_VFS_OP_STAT, (result >= 0), handle, "%s",
1271 smb_fname_str_do_log(smb_fname));
1273 return result;
1276 static int smb_full_audit_fstat(vfs_handle_struct *handle, files_struct *fsp,
1277 SMB_STRUCT_STAT *sbuf)
1279 int result;
1281 result = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1283 do_log(SMB_VFS_OP_FSTAT, (result >= 0), handle, "%s",
1284 fsp_str_do_log(fsp));
1286 return result;
1289 static int smb_full_audit_lstat(vfs_handle_struct *handle,
1290 struct smb_filename *smb_fname)
1292 int result;
1294 result = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
1296 do_log(SMB_VFS_OP_LSTAT, (result >= 0), handle, "%s",
1297 smb_fname_str_do_log(smb_fname));
1299 return result;
1302 static uint64_t smb_full_audit_get_alloc_size(vfs_handle_struct *handle,
1303 files_struct *fsp, const SMB_STRUCT_STAT *sbuf)
1305 uint64_t result;
1307 result = SMB_VFS_NEXT_GET_ALLOC_SIZE(handle, fsp, sbuf);
1309 do_log(SMB_VFS_OP_GET_ALLOC_SIZE, (result != (uint64_t)-1), handle,
1310 "%llu", result);
1312 return result;
1315 static int smb_full_audit_unlink(vfs_handle_struct *handle,
1316 const struct smb_filename *smb_fname)
1318 int result;
1320 result = SMB_VFS_NEXT_UNLINK(handle, smb_fname);
1322 do_log(SMB_VFS_OP_UNLINK, (result >= 0), handle, "%s",
1323 smb_fname_str_do_log(smb_fname));
1325 return result;
1328 static int smb_full_audit_chmod(vfs_handle_struct *handle,
1329 const char *path, mode_t mode)
1331 int result;
1333 result = SMB_VFS_NEXT_CHMOD(handle, path, mode);
1335 do_log(SMB_VFS_OP_CHMOD, (result >= 0), handle, "%s|%o", path, mode);
1337 return result;
1340 static int smb_full_audit_fchmod(vfs_handle_struct *handle, files_struct *fsp,
1341 mode_t mode)
1343 int result;
1345 result = SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1347 do_log(SMB_VFS_OP_FCHMOD, (result >= 0), handle,
1348 "%s|%o", fsp_str_do_log(fsp), mode);
1350 return result;
1353 static int smb_full_audit_chown(vfs_handle_struct *handle,
1354 const char *path, uid_t uid, gid_t gid)
1356 int result;
1358 result = SMB_VFS_NEXT_CHOWN(handle, path, uid, gid);
1360 do_log(SMB_VFS_OP_CHOWN, (result >= 0), handle, "%s|%ld|%ld",
1361 path, (long int)uid, (long int)gid);
1363 return result;
1366 static int smb_full_audit_fchown(vfs_handle_struct *handle, files_struct *fsp,
1367 uid_t uid, gid_t gid)
1369 int result;
1371 result = SMB_VFS_NEXT_FCHOWN(handle, fsp, uid, gid);
1373 do_log(SMB_VFS_OP_FCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1374 fsp_str_do_log(fsp), (long int)uid, (long int)gid);
1376 return result;
1379 static int smb_full_audit_lchown(vfs_handle_struct *handle,
1380 const char *path, uid_t uid, gid_t gid)
1382 int result;
1384 result = SMB_VFS_NEXT_LCHOWN(handle, path, uid, gid);
1386 do_log(SMB_VFS_OP_LCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1387 path, (long int)uid, (long int)gid);
1389 return result;
1392 static int smb_full_audit_chdir(vfs_handle_struct *handle,
1393 const char *path)
1395 int result;
1397 result = SMB_VFS_NEXT_CHDIR(handle, path);
1399 do_log(SMB_VFS_OP_CHDIR, (result >= 0), handle, "chdir|%s", path);
1401 return result;
1404 static char *smb_full_audit_getwd(vfs_handle_struct *handle)
1406 char *result;
1408 result = SMB_VFS_NEXT_GETWD(handle);
1410 do_log(SMB_VFS_OP_GETWD, (result != NULL), handle, "%s",
1411 result == NULL? "" : result);
1413 return result;
1416 static int smb_full_audit_ntimes(vfs_handle_struct *handle,
1417 const struct smb_filename *smb_fname,
1418 struct smb_file_time *ft)
1420 int result;
1422 result = SMB_VFS_NEXT_NTIMES(handle, smb_fname, ft);
1424 do_log(SMB_VFS_OP_NTIMES, (result >= 0), handle, "%s",
1425 smb_fname_str_do_log(smb_fname));
1427 return result;
1430 static int smb_full_audit_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
1431 off_t len)
1433 int result;
1435 result = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1437 do_log(SMB_VFS_OP_FTRUNCATE, (result >= 0), handle,
1438 "%s", fsp_str_do_log(fsp));
1440 return result;
1443 static int smb_full_audit_fallocate(vfs_handle_struct *handle, files_struct *fsp,
1444 enum vfs_fallocate_mode mode,
1445 off_t offset,
1446 off_t len)
1448 int result;
1450 result = SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
1452 do_log(SMB_VFS_OP_FALLOCATE, (result >= 0), handle,
1453 "%s", fsp_str_do_log(fsp));
1455 return result;
1458 static bool smb_full_audit_lock(vfs_handle_struct *handle, files_struct *fsp,
1459 int op, off_t offset, off_t count, int type)
1461 bool result;
1463 result = SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type);
1465 do_log(SMB_VFS_OP_LOCK, result, handle, "%s", fsp_str_do_log(fsp));
1467 return result;
1470 static int smb_full_audit_kernel_flock(struct vfs_handle_struct *handle,
1471 struct files_struct *fsp,
1472 uint32 share_mode, uint32 access_mask)
1474 int result;
1476 result = SMB_VFS_NEXT_KERNEL_FLOCK(handle, fsp, share_mode, access_mask);
1478 do_log(SMB_VFS_OP_KERNEL_FLOCK, (result >= 0), handle, "%s",
1479 fsp_str_do_log(fsp));
1481 return result;
1484 static int smb_full_audit_linux_setlease(vfs_handle_struct *handle, files_struct *fsp,
1485 int leasetype)
1487 int result;
1489 result = SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
1491 do_log(SMB_VFS_OP_LINUX_SETLEASE, (result >= 0), handle, "%s",
1492 fsp_str_do_log(fsp));
1494 return result;
1497 static bool smb_full_audit_getlock(vfs_handle_struct *handle, files_struct *fsp,
1498 off_t *poffset, off_t *pcount, int *ptype, pid_t *ppid)
1500 bool result;
1502 result = SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype, ppid);
1504 do_log(SMB_VFS_OP_GETLOCK, result, handle, "%s", fsp_str_do_log(fsp));
1506 return result;
1509 static int smb_full_audit_symlink(vfs_handle_struct *handle,
1510 const char *oldpath, const char *newpath)
1512 int result;
1514 result = SMB_VFS_NEXT_SYMLINK(handle, oldpath, newpath);
1516 do_log(SMB_VFS_OP_SYMLINK, (result >= 0), handle,
1517 "%s|%s", oldpath, newpath);
1519 return result;
1522 static int smb_full_audit_readlink(vfs_handle_struct *handle,
1523 const char *path, char *buf, size_t bufsiz)
1525 int result;
1527 result = SMB_VFS_NEXT_READLINK(handle, path, buf, bufsiz);
1529 do_log(SMB_VFS_OP_READLINK, (result >= 0), handle, "%s", path);
1531 return result;
1534 static int smb_full_audit_link(vfs_handle_struct *handle,
1535 const char *oldpath, const char *newpath)
1537 int result;
1539 result = SMB_VFS_NEXT_LINK(handle, oldpath, newpath);
1541 do_log(SMB_VFS_OP_LINK, (result >= 0), handle,
1542 "%s|%s", oldpath, newpath);
1544 return result;
1547 static int smb_full_audit_mknod(vfs_handle_struct *handle,
1548 const char *pathname, mode_t mode, SMB_DEV_T dev)
1550 int result;
1552 result = SMB_VFS_NEXT_MKNOD(handle, pathname, mode, dev);
1554 do_log(SMB_VFS_OP_MKNOD, (result >= 0), handle, "%s", pathname);
1556 return result;
1559 static char *smb_full_audit_realpath(vfs_handle_struct *handle,
1560 const char *path)
1562 char *result;
1564 result = SMB_VFS_NEXT_REALPATH(handle, path);
1566 do_log(SMB_VFS_OP_REALPATH, (result != NULL), handle, "%s", path);
1568 return result;
1571 static NTSTATUS smb_full_audit_notify_watch(struct vfs_handle_struct *handle,
1572 struct sys_notify_context *ctx,
1573 const char *path,
1574 uint32_t *filter,
1575 uint32_t *subdir_filter,
1576 void (*callback)(struct sys_notify_context *ctx,
1577 void *private_data,
1578 struct notify_event *ev),
1579 void *private_data, void *handle_p)
1581 NTSTATUS result;
1583 result = SMB_VFS_NEXT_NOTIFY_WATCH(handle, ctx, path,
1584 filter, subdir_filter, callback,
1585 private_data, handle_p);
1587 do_log(SMB_VFS_OP_NOTIFY_WATCH, NT_STATUS_IS_OK(result), handle, "");
1589 return result;
1592 static int smb_full_audit_chflags(vfs_handle_struct *handle,
1593 const char *path, unsigned int flags)
1595 int result;
1597 result = SMB_VFS_NEXT_CHFLAGS(handle, path, flags);
1599 do_log(SMB_VFS_OP_CHFLAGS, (result != 0), handle, "%s", path);
1601 return result;
1604 static struct file_id smb_full_audit_file_id_create(struct vfs_handle_struct *handle,
1605 const SMB_STRUCT_STAT *sbuf)
1607 struct file_id id_zero;
1608 struct file_id result;
1610 ZERO_STRUCT(id_zero);
1612 result = SMB_VFS_NEXT_FILE_ID_CREATE(handle, sbuf);
1614 do_log(SMB_VFS_OP_FILE_ID_CREATE,
1615 !file_id_equal(&id_zero, &result),
1616 handle, "%s", file_id_string_tos(&result));
1618 return result;
1621 static NTSTATUS smb_full_audit_streaminfo(vfs_handle_struct *handle,
1622 struct files_struct *fsp,
1623 const char *fname,
1624 TALLOC_CTX *mem_ctx,
1625 unsigned int *pnum_streams,
1626 struct stream_struct **pstreams)
1628 NTSTATUS result;
1630 result = SMB_VFS_NEXT_STREAMINFO(handle, fsp, fname, mem_ctx,
1631 pnum_streams, pstreams);
1633 do_log(SMB_VFS_OP_STREAMINFO, NT_STATUS_IS_OK(result), handle,
1634 "%s", fname);
1636 return result;
1639 static int smb_full_audit_get_real_filename(struct vfs_handle_struct *handle,
1640 const char *path,
1641 const char *name,
1642 TALLOC_CTX *mem_ctx,
1643 char **found_name)
1645 int result;
1647 result = SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name, mem_ctx,
1648 found_name);
1650 do_log(SMB_VFS_OP_GET_REAL_FILENAME, (result == 0), handle,
1651 "%s/%s->%s", path, name, (result == 0) ? "" : *found_name);
1653 return result;
1656 static const char *smb_full_audit_connectpath(vfs_handle_struct *handle,
1657 const char *fname)
1659 const char *result;
1661 result = SMB_VFS_NEXT_CONNECTPATH(handle, fname);
1663 do_log(SMB_VFS_OP_CONNECTPATH, result != NULL, handle,
1664 "%s", fname);
1666 return result;
1669 static NTSTATUS smb_full_audit_brl_lock_windows(struct vfs_handle_struct *handle,
1670 struct byte_range_lock *br_lck,
1671 struct lock_struct *plock,
1672 bool blocking_lock,
1673 struct blocking_lock_record *blr)
1675 NTSTATUS result;
1677 result = SMB_VFS_NEXT_BRL_LOCK_WINDOWS(handle, br_lck, plock,
1678 blocking_lock, blr);
1680 do_log(SMB_VFS_OP_BRL_LOCK_WINDOWS, NT_STATUS_IS_OK(result), handle,
1681 "%s:%llu-%llu. type=%d. blocking=%d", fsp_str_do_log(br_lck->fsp),
1682 plock->start, plock->size, plock->lock_type, blocking_lock );
1684 return result;
1687 static bool smb_full_audit_brl_unlock_windows(struct vfs_handle_struct *handle,
1688 struct messaging_context *msg_ctx,
1689 struct byte_range_lock *br_lck,
1690 const struct lock_struct *plock)
1692 bool result;
1694 result = SMB_VFS_NEXT_BRL_UNLOCK_WINDOWS(handle, msg_ctx, br_lck,
1695 plock);
1697 do_log(SMB_VFS_OP_BRL_UNLOCK_WINDOWS, (result == 0), handle,
1698 "%s:%llu-%llu:%d", fsp_str_do_log(br_lck->fsp), plock->start,
1699 plock->size, plock->lock_type);
1701 return result;
1704 static bool smb_full_audit_brl_cancel_windows(struct vfs_handle_struct *handle,
1705 struct byte_range_lock *br_lck,
1706 struct lock_struct *plock,
1707 struct blocking_lock_record *blr)
1709 bool result;
1711 result = SMB_VFS_NEXT_BRL_CANCEL_WINDOWS(handle, br_lck, plock, blr);
1713 do_log(SMB_VFS_OP_BRL_CANCEL_WINDOWS, (result == 0), handle,
1714 "%s:%llu-%llu:%d", fsp_str_do_log(br_lck->fsp), plock->start,
1715 plock->size);
1717 return result;
1720 static bool smb_full_audit_strict_lock(struct vfs_handle_struct *handle,
1721 struct files_struct *fsp,
1722 struct lock_struct *plock)
1724 bool result;
1726 result = SMB_VFS_NEXT_STRICT_LOCK(handle, fsp, plock);
1728 do_log(SMB_VFS_OP_STRICT_LOCK, result, handle,
1729 "%s:%llu-%llu:%d", fsp_str_do_log(fsp), plock->start,
1730 plock->size);
1732 return result;
1735 static void smb_full_audit_strict_unlock(struct vfs_handle_struct *handle,
1736 struct files_struct *fsp,
1737 struct lock_struct *plock)
1739 SMB_VFS_NEXT_STRICT_UNLOCK(handle, fsp, plock);
1741 do_log(SMB_VFS_OP_STRICT_UNLOCK, true, handle,
1742 "%s:%llu-%llu:%d", fsp_str_do_log(fsp), plock->start,
1743 plock->size);
1746 static NTSTATUS smb_full_audit_translate_name(struct vfs_handle_struct *handle,
1747 const char *name,
1748 enum vfs_translate_direction direction,
1749 TALLOC_CTX *mem_ctx,
1750 char **mapped_name)
1752 NTSTATUS result;
1754 result = SMB_VFS_NEXT_TRANSLATE_NAME(handle, name, direction, mem_ctx,
1755 mapped_name);
1757 do_log(SMB_VFS_OP_TRANSLATE_NAME, NT_STATUS_IS_OK(result), handle, "");
1759 return result;
1762 static NTSTATUS smb_full_audit_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
1763 uint32 security_info,
1764 struct security_descriptor **ppdesc)
1766 NTSTATUS result;
1768 result = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info, ppdesc);
1770 do_log(SMB_VFS_OP_FGET_NT_ACL, NT_STATUS_IS_OK(result), handle,
1771 "%s", fsp_str_do_log(fsp));
1773 return result;
1776 static NTSTATUS smb_full_audit_get_nt_acl(vfs_handle_struct *handle,
1777 const char *name,
1778 uint32 security_info,
1779 struct security_descriptor **ppdesc)
1781 NTSTATUS result;
1783 result = SMB_VFS_NEXT_GET_NT_ACL(handle, name, security_info, ppdesc);
1785 do_log(SMB_VFS_OP_GET_NT_ACL, NT_STATUS_IS_OK(result), handle,
1786 "%s", name);
1788 return result;
1791 static NTSTATUS smb_full_audit_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
1792 uint32 security_info_sent,
1793 const struct security_descriptor *psd)
1795 NTSTATUS result;
1797 result = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
1799 do_log(SMB_VFS_OP_FSET_NT_ACL, NT_STATUS_IS_OK(result), handle, "%s",
1800 fsp_str_do_log(fsp));
1802 return result;
1805 static int smb_full_audit_chmod_acl(vfs_handle_struct *handle,
1806 const char *path, mode_t mode)
1808 int result;
1810 result = SMB_VFS_NEXT_CHMOD_ACL(handle, path, mode);
1812 do_log(SMB_VFS_OP_CHMOD_ACL, (result >= 0), handle,
1813 "%s|%o", path, mode);
1815 return result;
1818 static int smb_full_audit_fchmod_acl(vfs_handle_struct *handle, files_struct *fsp,
1819 mode_t mode)
1821 int result;
1823 result = SMB_VFS_NEXT_FCHMOD_ACL(handle, fsp, mode);
1825 do_log(SMB_VFS_OP_FCHMOD_ACL, (result >= 0), handle,
1826 "%s|%o", fsp_str_do_log(fsp), mode);
1828 return result;
1831 static int smb_full_audit_sys_acl_get_entry(vfs_handle_struct *handle,
1833 SMB_ACL_T theacl, int entry_id,
1834 SMB_ACL_ENTRY_T *entry_p)
1836 int result;
1838 result = SMB_VFS_NEXT_SYS_ACL_GET_ENTRY(handle, theacl, entry_id,
1839 entry_p);
1841 do_log(SMB_VFS_OP_SYS_ACL_GET_ENTRY, (result >= 0), handle,
1842 "");
1844 return result;
1847 static int smb_full_audit_sys_acl_get_tag_type(vfs_handle_struct *handle,
1849 SMB_ACL_ENTRY_T entry_d,
1850 SMB_ACL_TAG_T *tag_type_p)
1852 int result;
1854 result = SMB_VFS_NEXT_SYS_ACL_GET_TAG_TYPE(handle, entry_d,
1855 tag_type_p);
1857 do_log(SMB_VFS_OP_SYS_ACL_GET_TAG_TYPE, (result >= 0), handle,
1858 "");
1860 return result;
1863 static int smb_full_audit_sys_acl_get_permset(vfs_handle_struct *handle,
1865 SMB_ACL_ENTRY_T entry_d,
1866 SMB_ACL_PERMSET_T *permset_p)
1868 int result;
1870 result = SMB_VFS_NEXT_SYS_ACL_GET_PERMSET(handle, entry_d,
1871 permset_p);
1873 do_log(SMB_VFS_OP_SYS_ACL_GET_PERMSET, (result >= 0), handle,
1874 "");
1876 return result;
1879 static void * smb_full_audit_sys_acl_get_qualifier(vfs_handle_struct *handle,
1881 SMB_ACL_ENTRY_T entry_d)
1883 void *result;
1885 result = SMB_VFS_NEXT_SYS_ACL_GET_QUALIFIER(handle, entry_d);
1887 do_log(SMB_VFS_OP_SYS_ACL_GET_QUALIFIER, (result != NULL), handle,
1888 "");
1890 return result;
1893 static SMB_ACL_T smb_full_audit_sys_acl_get_file(vfs_handle_struct *handle,
1894 const char *path_p,
1895 SMB_ACL_TYPE_T type)
1897 SMB_ACL_T result;
1899 result = SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, path_p, type);
1901 do_log(SMB_VFS_OP_SYS_ACL_GET_FILE, (result != NULL), handle,
1902 "%s", path_p);
1904 return result;
1907 static SMB_ACL_T smb_full_audit_sys_acl_get_fd(vfs_handle_struct *handle,
1908 files_struct *fsp)
1910 SMB_ACL_T result;
1912 result = SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp);
1914 do_log(SMB_VFS_OP_SYS_ACL_GET_FD, (result != NULL), handle,
1915 "%s", fsp_str_do_log(fsp));
1917 return result;
1920 static int smb_full_audit_sys_acl_clear_perms(vfs_handle_struct *handle,
1922 SMB_ACL_PERMSET_T permset)
1924 int result;
1926 result = SMB_VFS_NEXT_SYS_ACL_CLEAR_PERMS(handle, permset);
1928 do_log(SMB_VFS_OP_SYS_ACL_CLEAR_PERMS, (result >= 0), handle,
1929 "");
1931 return result;
1934 static int smb_full_audit_sys_acl_add_perm(vfs_handle_struct *handle,
1936 SMB_ACL_PERMSET_T permset,
1937 SMB_ACL_PERM_T perm)
1939 int result;
1941 result = SMB_VFS_NEXT_SYS_ACL_ADD_PERM(handle, permset, perm);
1943 do_log(SMB_VFS_OP_SYS_ACL_ADD_PERM, (result >= 0), handle,
1944 "");
1946 return result;
1949 static char * smb_full_audit_sys_acl_to_text(vfs_handle_struct *handle,
1950 SMB_ACL_T theacl,
1951 ssize_t *plen)
1953 char * result;
1955 result = SMB_VFS_NEXT_SYS_ACL_TO_TEXT(handle, theacl, plen);
1957 do_log(SMB_VFS_OP_SYS_ACL_TO_TEXT, (result != NULL), handle,
1958 "");
1960 return result;
1963 static SMB_ACL_T smb_full_audit_sys_acl_init(vfs_handle_struct *handle,
1965 int count)
1967 SMB_ACL_T result;
1969 result = SMB_VFS_NEXT_SYS_ACL_INIT(handle, count);
1971 do_log(SMB_VFS_OP_SYS_ACL_INIT, (result != NULL), handle,
1972 "");
1974 return result;
1977 static int smb_full_audit_sys_acl_create_entry(vfs_handle_struct *handle,
1978 SMB_ACL_T *pacl,
1979 SMB_ACL_ENTRY_T *pentry)
1981 int result;
1983 result = SMB_VFS_NEXT_SYS_ACL_CREATE_ENTRY(handle, pacl, pentry);
1985 do_log(SMB_VFS_OP_SYS_ACL_CREATE_ENTRY, (result >= 0), handle,
1986 "");
1988 return result;
1991 static int smb_full_audit_sys_acl_set_tag_type(vfs_handle_struct *handle,
1993 SMB_ACL_ENTRY_T entry,
1994 SMB_ACL_TAG_T tagtype)
1996 int result;
1998 result = SMB_VFS_NEXT_SYS_ACL_SET_TAG_TYPE(handle, entry,
1999 tagtype);
2001 do_log(SMB_VFS_OP_SYS_ACL_SET_TAG_TYPE, (result >= 0), handle,
2002 "");
2004 return result;
2007 static int smb_full_audit_sys_acl_set_qualifier(vfs_handle_struct *handle,
2009 SMB_ACL_ENTRY_T entry,
2010 void *qual)
2012 int result;
2014 result = SMB_VFS_NEXT_SYS_ACL_SET_QUALIFIER(handle, entry, qual);
2016 do_log(SMB_VFS_OP_SYS_ACL_SET_QUALIFIER, (result >= 0), handle,
2017 "");
2019 return result;
2022 static int smb_full_audit_sys_acl_set_permset(vfs_handle_struct *handle,
2024 SMB_ACL_ENTRY_T entry,
2025 SMB_ACL_PERMSET_T permset)
2027 int result;
2029 result = SMB_VFS_NEXT_SYS_ACL_SET_PERMSET(handle, entry, permset);
2031 do_log(SMB_VFS_OP_SYS_ACL_SET_PERMSET, (result >= 0), handle,
2032 "");
2034 return result;
2037 static int smb_full_audit_sys_acl_valid(vfs_handle_struct *handle,
2039 SMB_ACL_T theacl )
2041 int result;
2043 result = SMB_VFS_NEXT_SYS_ACL_VALID(handle, theacl);
2045 do_log(SMB_VFS_OP_SYS_ACL_VALID, (result >= 0), handle,
2046 "");
2048 return result;
2051 static int smb_full_audit_sys_acl_set_file(vfs_handle_struct *handle,
2053 const char *name, SMB_ACL_TYPE_T acltype,
2054 SMB_ACL_T theacl)
2056 int result;
2058 result = SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, name, acltype,
2059 theacl);
2061 do_log(SMB_VFS_OP_SYS_ACL_SET_FILE, (result >= 0), handle,
2062 "%s", name);
2064 return result;
2067 static int smb_full_audit_sys_acl_set_fd(vfs_handle_struct *handle, files_struct *fsp,
2068 SMB_ACL_T theacl)
2070 int result;
2072 result = SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, theacl);
2074 do_log(SMB_VFS_OP_SYS_ACL_SET_FD, (result >= 0), handle,
2075 "%s", fsp_str_do_log(fsp));
2077 return result;
2080 static int smb_full_audit_sys_acl_delete_def_file(vfs_handle_struct *handle,
2082 const char *path)
2084 int result;
2086 result = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, path);
2088 do_log(SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE, (result >= 0), handle,
2089 "%s", path);
2091 return result;
2094 static int smb_full_audit_sys_acl_get_perm(vfs_handle_struct *handle,
2096 SMB_ACL_PERMSET_T permset,
2097 SMB_ACL_PERM_T perm)
2099 int result;
2101 result = SMB_VFS_NEXT_SYS_ACL_GET_PERM(handle, permset, perm);
2103 do_log(SMB_VFS_OP_SYS_ACL_GET_PERM, (result >= 0), handle,
2104 "");
2106 return result;
2109 static int smb_full_audit_sys_acl_free_text(vfs_handle_struct *handle,
2111 char *text)
2113 int result;
2115 result = SMB_VFS_NEXT_SYS_ACL_FREE_TEXT(handle, text);
2117 do_log(SMB_VFS_OP_SYS_ACL_FREE_TEXT, (result >= 0), handle,
2118 "");
2120 return result;
2123 static int smb_full_audit_sys_acl_free_acl(vfs_handle_struct *handle,
2125 SMB_ACL_T posix_acl)
2127 int result;
2129 result = SMB_VFS_NEXT_SYS_ACL_FREE_ACL(handle, posix_acl);
2131 do_log(SMB_VFS_OP_SYS_ACL_FREE_ACL, (result >= 0), handle,
2132 "");
2134 return result;
2137 static int smb_full_audit_sys_acl_free_qualifier(vfs_handle_struct *handle,
2138 void *qualifier,
2139 SMB_ACL_TAG_T tagtype)
2141 int result;
2143 result = SMB_VFS_NEXT_SYS_ACL_FREE_QUALIFIER(handle, qualifier,
2144 tagtype);
2146 do_log(SMB_VFS_OP_SYS_ACL_FREE_QUALIFIER, (result >= 0), handle,
2147 "");
2149 return result;
2152 static ssize_t smb_full_audit_getxattr(struct vfs_handle_struct *handle,
2153 const char *path,
2154 const char *name, void *value, size_t size)
2156 ssize_t result;
2158 result = SMB_VFS_NEXT_GETXATTR(handle, path, name, value, size);
2160 do_log(SMB_VFS_OP_GETXATTR, (result >= 0), handle,
2161 "%s|%s", path, name);
2163 return result;
2166 static ssize_t smb_full_audit_fgetxattr(struct vfs_handle_struct *handle,
2167 struct files_struct *fsp,
2168 const char *name, void *value, size_t size)
2170 ssize_t result;
2172 result = SMB_VFS_NEXT_FGETXATTR(handle, fsp, name, value, size);
2174 do_log(SMB_VFS_OP_FGETXATTR, (result >= 0), handle,
2175 "%s|%s", fsp_str_do_log(fsp), name);
2177 return result;
2180 static ssize_t smb_full_audit_listxattr(struct vfs_handle_struct *handle,
2181 const char *path, char *list, size_t size)
2183 ssize_t result;
2185 result = SMB_VFS_NEXT_LISTXATTR(handle, path, list, size);
2187 do_log(SMB_VFS_OP_LISTXATTR, (result >= 0), handle, "%s", path);
2189 return result;
2192 static ssize_t smb_full_audit_flistxattr(struct vfs_handle_struct *handle,
2193 struct files_struct *fsp, char *list,
2194 size_t size)
2196 ssize_t result;
2198 result = SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
2200 do_log(SMB_VFS_OP_FLISTXATTR, (result >= 0), handle,
2201 "%s", fsp_str_do_log(fsp));
2203 return result;
2206 static int smb_full_audit_removexattr(struct vfs_handle_struct *handle,
2207 const char *path,
2208 const char *name)
2210 int result;
2212 result = SMB_VFS_NEXT_REMOVEXATTR(handle, path, name);
2214 do_log(SMB_VFS_OP_REMOVEXATTR, (result >= 0), handle,
2215 "%s|%s", path, name);
2217 return result;
2220 static int smb_full_audit_fremovexattr(struct vfs_handle_struct *handle,
2221 struct files_struct *fsp,
2222 const char *name)
2224 int result;
2226 result = SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, name);
2228 do_log(SMB_VFS_OP_FREMOVEXATTR, (result >= 0), handle,
2229 "%s|%s", fsp_str_do_log(fsp), name);
2231 return result;
2234 static int smb_full_audit_setxattr(struct vfs_handle_struct *handle,
2235 const char *path,
2236 const char *name, const void *value, size_t size,
2237 int flags)
2239 int result;
2241 result = SMB_VFS_NEXT_SETXATTR(handle, path, name, value, size,
2242 flags);
2244 do_log(SMB_VFS_OP_SETXATTR, (result >= 0), handle,
2245 "%s|%s", path, name);
2247 return result;
2250 static int smb_full_audit_fsetxattr(struct vfs_handle_struct *handle,
2251 struct files_struct *fsp, const char *name,
2252 const void *value, size_t size, int flags)
2254 int result;
2256 result = SMB_VFS_NEXT_FSETXATTR(handle, fsp, name, value, size, flags);
2258 do_log(SMB_VFS_OP_FSETXATTR, (result >= 0), handle,
2259 "%s|%s", fsp_str_do_log(fsp), name);
2261 return result;
2264 static bool smb_full_audit_aio_force(struct vfs_handle_struct *handle,
2265 struct files_struct *fsp)
2267 bool result;
2269 result = SMB_VFS_NEXT_AIO_FORCE(handle, fsp);
2270 do_log(SMB_VFS_OP_AIO_FORCE, result, handle,
2271 "%s", fsp_str_do_log(fsp));
2273 return result;
2276 static bool smb_full_audit_is_offline(struct vfs_handle_struct *handle,
2277 const struct smb_filename *fname,
2278 SMB_STRUCT_STAT *sbuf)
2280 bool result;
2282 result = SMB_VFS_NEXT_IS_OFFLINE(handle, fname, sbuf);
2283 do_log(SMB_VFS_OP_IS_OFFLINE, result, handle, "%s",
2284 smb_fname_str_do_log(fname));
2285 return result;
2288 static int smb_full_audit_set_offline(struct vfs_handle_struct *handle,
2289 const struct smb_filename *fname)
2291 int result;
2293 result = SMB_VFS_NEXT_SET_OFFLINE(handle, fname);
2294 do_log(SMB_VFS_OP_SET_OFFLINE, result >= 0, handle, "%s",
2295 smb_fname_str_do_log(fname));
2296 return result;
2299 static struct vfs_fn_pointers vfs_full_audit_fns = {
2301 /* Disk operations */
2303 .connect_fn = smb_full_audit_connect,
2304 .disconnect_fn = smb_full_audit_disconnect,
2305 .disk_free_fn = smb_full_audit_disk_free,
2306 .get_quota_fn = smb_full_audit_get_quota,
2307 .set_quota_fn = smb_full_audit_set_quota,
2308 .get_shadow_copy_data_fn = smb_full_audit_get_shadow_copy_data,
2309 .statvfs_fn = smb_full_audit_statvfs,
2310 .fs_capabilities_fn = smb_full_audit_fs_capabilities,
2311 .opendir_fn = smb_full_audit_opendir,
2312 .fdopendir_fn = smb_full_audit_fdopendir,
2313 .readdir_fn = smb_full_audit_readdir,
2314 .seekdir_fn = smb_full_audit_seekdir,
2315 .telldir_fn = smb_full_audit_telldir,
2316 .rewind_dir_fn = smb_full_audit_rewinddir,
2317 .mkdir_fn = smb_full_audit_mkdir,
2318 .rmdir_fn = smb_full_audit_rmdir,
2319 .closedir_fn = smb_full_audit_closedir,
2320 .init_search_op_fn = smb_full_audit_init_search_op,
2321 .open_fn = smb_full_audit_open,
2322 .create_file_fn = smb_full_audit_create_file,
2323 .close_fn = smb_full_audit_close,
2324 .read_fn = smb_full_audit_read,
2325 .pread_fn = smb_full_audit_pread,
2326 .pread_send_fn = smb_full_audit_pread_send,
2327 .pread_recv_fn = smb_full_audit_pread_recv,
2328 .write_fn = smb_full_audit_write,
2329 .pwrite_fn = smb_full_audit_pwrite,
2330 .pwrite_send_fn = smb_full_audit_pwrite_send,
2331 .pwrite_recv_fn = smb_full_audit_pwrite_recv,
2332 .lseek_fn = smb_full_audit_lseek,
2333 .sendfile_fn = smb_full_audit_sendfile,
2334 .recvfile_fn = smb_full_audit_recvfile,
2335 .rename_fn = smb_full_audit_rename,
2336 .fsync_fn = smb_full_audit_fsync,
2337 .fsync_send_fn = smb_full_audit_fsync_send,
2338 .fsync_recv_fn = smb_full_audit_fsync_recv,
2339 .stat_fn = smb_full_audit_stat,
2340 .fstat_fn = smb_full_audit_fstat,
2341 .lstat_fn = smb_full_audit_lstat,
2342 .get_alloc_size_fn = smb_full_audit_get_alloc_size,
2343 .unlink_fn = smb_full_audit_unlink,
2344 .chmod_fn = smb_full_audit_chmod,
2345 .fchmod_fn = smb_full_audit_fchmod,
2346 .chown_fn = smb_full_audit_chown,
2347 .fchown_fn = smb_full_audit_fchown,
2348 .lchown_fn = smb_full_audit_lchown,
2349 .chdir_fn = smb_full_audit_chdir,
2350 .getwd_fn = smb_full_audit_getwd,
2351 .ntimes_fn = smb_full_audit_ntimes,
2352 .ftruncate_fn = smb_full_audit_ftruncate,
2353 .fallocate_fn = smb_full_audit_fallocate,
2354 .lock_fn = smb_full_audit_lock,
2355 .kernel_flock_fn = smb_full_audit_kernel_flock,
2356 .linux_setlease_fn = smb_full_audit_linux_setlease,
2357 .getlock_fn = smb_full_audit_getlock,
2358 .symlink_fn = smb_full_audit_symlink,
2359 .readlink_fn = smb_full_audit_readlink,
2360 .link_fn = smb_full_audit_link,
2361 .mknod_fn = smb_full_audit_mknod,
2362 .realpath_fn = smb_full_audit_realpath,
2363 .notify_watch_fn = smb_full_audit_notify_watch,
2364 .chflags_fn = smb_full_audit_chflags,
2365 .file_id_create_fn = smb_full_audit_file_id_create,
2366 .streaminfo_fn = smb_full_audit_streaminfo,
2367 .get_real_filename_fn = smb_full_audit_get_real_filename,
2368 .connectpath_fn = smb_full_audit_connectpath,
2369 .brl_lock_windows_fn = smb_full_audit_brl_lock_windows,
2370 .brl_unlock_windows_fn = smb_full_audit_brl_unlock_windows,
2371 .brl_cancel_windows_fn = smb_full_audit_brl_cancel_windows,
2372 .strict_lock_fn = smb_full_audit_strict_lock,
2373 .strict_unlock_fn = smb_full_audit_strict_unlock,
2374 .translate_name_fn = smb_full_audit_translate_name,
2375 .fget_nt_acl_fn = smb_full_audit_fget_nt_acl,
2376 .get_nt_acl_fn = smb_full_audit_get_nt_acl,
2377 .fset_nt_acl_fn = smb_full_audit_fset_nt_acl,
2378 .chmod_acl_fn = smb_full_audit_chmod_acl,
2379 .fchmod_acl_fn = smb_full_audit_fchmod_acl,
2380 .sys_acl_get_entry_fn = smb_full_audit_sys_acl_get_entry,
2381 .sys_acl_get_tag_type_fn = smb_full_audit_sys_acl_get_tag_type,
2382 .sys_acl_get_permset_fn = smb_full_audit_sys_acl_get_permset,
2383 .sys_acl_get_qualifier_fn = smb_full_audit_sys_acl_get_qualifier,
2384 .sys_acl_get_file_fn = smb_full_audit_sys_acl_get_file,
2385 .sys_acl_get_fd_fn = smb_full_audit_sys_acl_get_fd,
2386 .sys_acl_clear_perms_fn = smb_full_audit_sys_acl_clear_perms,
2387 .sys_acl_add_perm_fn = smb_full_audit_sys_acl_add_perm,
2388 .sys_acl_to_text_fn = smb_full_audit_sys_acl_to_text,
2389 .sys_acl_init_fn = smb_full_audit_sys_acl_init,
2390 .sys_acl_create_entry_fn = smb_full_audit_sys_acl_create_entry,
2391 .sys_acl_set_tag_type_fn = smb_full_audit_sys_acl_set_tag_type,
2392 .sys_acl_set_qualifier_fn = smb_full_audit_sys_acl_set_qualifier,
2393 .sys_acl_set_permset_fn = smb_full_audit_sys_acl_set_permset,
2394 .sys_acl_valid_fn = smb_full_audit_sys_acl_valid,
2395 .sys_acl_set_file_fn = smb_full_audit_sys_acl_set_file,
2396 .sys_acl_set_fd_fn = smb_full_audit_sys_acl_set_fd,
2397 .sys_acl_delete_def_file_fn = smb_full_audit_sys_acl_delete_def_file,
2398 .sys_acl_get_perm_fn = smb_full_audit_sys_acl_get_perm,
2399 .sys_acl_free_text_fn = smb_full_audit_sys_acl_free_text,
2400 .sys_acl_free_acl_fn = smb_full_audit_sys_acl_free_acl,
2401 .sys_acl_free_qualifier_fn = smb_full_audit_sys_acl_free_qualifier,
2402 .getxattr_fn = smb_full_audit_getxattr,
2403 .fgetxattr_fn = smb_full_audit_fgetxattr,
2404 .listxattr_fn = smb_full_audit_listxattr,
2405 .flistxattr_fn = smb_full_audit_flistxattr,
2406 .removexattr_fn = smb_full_audit_removexattr,
2407 .fremovexattr_fn = smb_full_audit_fremovexattr,
2408 .setxattr_fn = smb_full_audit_setxattr,
2409 .fsetxattr_fn = smb_full_audit_fsetxattr,
2410 .aio_force_fn = smb_full_audit_aio_force,
2411 .is_offline_fn = smb_full_audit_is_offline,
2412 .set_offline_fn = smb_full_audit_set_offline,
2415 NTSTATUS vfs_full_audit_init(void)
2417 NTSTATUS ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION,
2418 "full_audit", &vfs_full_audit_fns);
2420 if (!NT_STATUS_IS_OK(ret))
2421 return ret;
2423 vfs_full_audit_debug_level = debug_add_class("full_audit");
2424 if (vfs_full_audit_debug_level == -1) {
2425 vfs_full_audit_debug_level = DBGC_VFS;
2426 DEBUG(0, ("vfs_full_audit: Couldn't register custom debugging "
2427 "class!\n"));
2428 } else {
2429 DEBUG(10, ("vfs_full_audit: Debug class number of "
2430 "'full_audit': %d\n", vfs_full_audit_debug_level));
2433 return ret;