s4:libcli/smb2: remove unused variable
[Samba/gebeck_regimport.git] / source3 / modules / vfs_full_audit.c
blob1e5679dd6b29c82d6271c9f7da6e2974405f52f6
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);
562 return;
566 * Return a string using the do_log_ctx()
568 static const char *smb_fname_str_do_log(const struct smb_filename *smb_fname)
570 char *fname = NULL;
571 NTSTATUS status;
573 if (smb_fname == NULL) {
574 return "";
576 status = get_full_smb_filename(do_log_ctx(), smb_fname, &fname);
577 if (!NT_STATUS_IS_OK(status)) {
578 return "";
580 return fname;
584 * Return an fsp debug string using the do_log_ctx()
586 static const char *fsp_str_do_log(const struct files_struct *fsp)
588 return smb_fname_str_do_log(fsp->fsp_name);
591 /* Implementation of vfs_ops. Pass everything on to the default
592 operation but log event first. */
594 static int smb_full_audit_connect(vfs_handle_struct *handle,
595 const char *svc, const char *user)
597 int result;
598 struct vfs_full_audit_private_data *pd = NULL;
600 result = SMB_VFS_NEXT_CONNECT(handle, svc, user);
601 if (result < 0) {
602 return result;
605 pd = talloc_zero(handle, struct vfs_full_audit_private_data);
606 if (!pd) {
607 SMB_VFS_NEXT_DISCONNECT(handle);
608 return -1;
611 #ifdef WITH_SYSLOG
612 openlog("smbd_audit", 0, audit_syslog_facility(handle));
613 #endif
615 pd->success_ops = init_bitmap(
616 pd, lp_parm_string_list(SNUM(handle->conn), "full_audit",
617 "success", NULL));
618 pd->failure_ops = init_bitmap(
619 pd, lp_parm_string_list(SNUM(handle->conn), "full_audit",
620 "failure", NULL));
622 /* Store the private data. */
623 SMB_VFS_HANDLE_SET_DATA(handle, pd, NULL,
624 struct vfs_full_audit_private_data, return -1);
626 do_log(SMB_VFS_OP_CONNECT, True, handle,
627 "%s", svc);
629 return 0;
632 static void smb_full_audit_disconnect(vfs_handle_struct *handle)
634 SMB_VFS_NEXT_DISCONNECT(handle);
636 do_log(SMB_VFS_OP_DISCONNECT, True, handle,
637 "%s", lp_servicename(talloc_tos(), SNUM(handle->conn)));
639 /* The bitmaps will be disconnected when the private
640 data is deleted. */
642 return;
645 static uint64_t smb_full_audit_disk_free(vfs_handle_struct *handle,
646 const char *path,
647 bool small_query, uint64_t *bsize,
648 uint64_t *dfree, uint64_t *dsize)
650 uint64_t result;
652 result = SMB_VFS_NEXT_DISK_FREE(handle, path, small_query, bsize,
653 dfree, dsize);
655 /* Don't have a reasonable notion of failure here */
657 do_log(SMB_VFS_OP_DISK_FREE, True, handle, "%s", path);
659 return result;
662 static int smb_full_audit_get_quota(struct vfs_handle_struct *handle,
663 enum SMB_QUOTA_TYPE qtype, unid_t id,
664 SMB_DISK_QUOTA *qt)
666 int result;
668 result = SMB_VFS_NEXT_GET_QUOTA(handle, qtype, id, qt);
670 do_log(SMB_VFS_OP_GET_QUOTA, (result >= 0), handle, "");
672 return result;
676 static int smb_full_audit_set_quota(struct vfs_handle_struct *handle,
677 enum SMB_QUOTA_TYPE qtype, unid_t id,
678 SMB_DISK_QUOTA *qt)
680 int result;
682 result = SMB_VFS_NEXT_SET_QUOTA(handle, qtype, id, qt);
684 do_log(SMB_VFS_OP_SET_QUOTA, (result >= 0), handle, "");
686 return result;
689 static int smb_full_audit_get_shadow_copy_data(struct vfs_handle_struct *handle,
690 struct files_struct *fsp,
691 struct shadow_copy_data *shadow_copy_data,
692 bool labels)
694 int result;
696 result = SMB_VFS_NEXT_GET_SHADOW_COPY_DATA(handle, fsp, shadow_copy_data, labels);
698 do_log(SMB_VFS_OP_GET_SHADOW_COPY_DATA, (result >= 0), handle, "");
700 return result;
703 static int smb_full_audit_statvfs(struct vfs_handle_struct *handle,
704 const char *path,
705 struct vfs_statvfs_struct *statbuf)
707 int result;
709 result = SMB_VFS_NEXT_STATVFS(handle, path, statbuf);
711 do_log(SMB_VFS_OP_STATVFS, (result >= 0), handle, "");
713 return result;
716 static uint32_t smb_full_audit_fs_capabilities(struct vfs_handle_struct *handle, enum timestamp_set_resolution *p_ts_res)
718 int result;
720 result = SMB_VFS_NEXT_FS_CAPABILITIES(handle, p_ts_res);
722 do_log(SMB_VFS_OP_FS_CAPABILITIES, true, handle, "");
724 return result;
727 static DIR *smb_full_audit_opendir(vfs_handle_struct *handle,
728 const char *fname, const char *mask, uint32 attr)
730 DIR *result;
732 result = SMB_VFS_NEXT_OPENDIR(handle, fname, mask, attr);
734 do_log(SMB_VFS_OP_OPENDIR, (result != NULL), handle, "%s", fname);
736 return result;
739 static DIR *smb_full_audit_fdopendir(vfs_handle_struct *handle,
740 files_struct *fsp, const char *mask, uint32 attr)
742 DIR *result;
744 result = SMB_VFS_NEXT_FDOPENDIR(handle, fsp, mask, attr);
746 do_log(SMB_VFS_OP_FDOPENDIR, (result != NULL), handle, "%s",
747 fsp_str_do_log(fsp));
749 return result;
752 static struct dirent *smb_full_audit_readdir(vfs_handle_struct *handle,
753 DIR *dirp, SMB_STRUCT_STAT *sbuf)
755 struct dirent *result;
757 result = SMB_VFS_NEXT_READDIR(handle, dirp, sbuf);
759 /* This operation has no reasonable error condition
760 * (End of dir is also failure), so always succeed.
762 do_log(SMB_VFS_OP_READDIR, True, handle, "");
764 return result;
767 static void smb_full_audit_seekdir(vfs_handle_struct *handle,
768 DIR *dirp, long offset)
770 SMB_VFS_NEXT_SEEKDIR(handle, dirp, offset);
772 do_log(SMB_VFS_OP_SEEKDIR, True, handle, "");
773 return;
776 static long smb_full_audit_telldir(vfs_handle_struct *handle,
777 DIR *dirp)
779 long result;
781 result = SMB_VFS_NEXT_TELLDIR(handle, dirp);
783 do_log(SMB_VFS_OP_TELLDIR, True, handle, "");
785 return result;
788 static void smb_full_audit_rewinddir(vfs_handle_struct *handle,
789 DIR *dirp)
791 SMB_VFS_NEXT_REWINDDIR(handle, dirp);
793 do_log(SMB_VFS_OP_REWINDDIR, True, handle, "");
794 return;
797 static int smb_full_audit_mkdir(vfs_handle_struct *handle,
798 const char *path, mode_t mode)
800 int result;
802 result = SMB_VFS_NEXT_MKDIR(handle, path, mode);
804 do_log(SMB_VFS_OP_MKDIR, (result >= 0), handle, "%s", path);
806 return result;
809 static int smb_full_audit_rmdir(vfs_handle_struct *handle,
810 const char *path)
812 int result;
814 result = SMB_VFS_NEXT_RMDIR(handle, path);
816 do_log(SMB_VFS_OP_RMDIR, (result >= 0), handle, "%s", path);
818 return result;
821 static int smb_full_audit_closedir(vfs_handle_struct *handle,
822 DIR *dirp)
824 int result;
826 result = SMB_VFS_NEXT_CLOSEDIR(handle, dirp);
828 do_log(SMB_VFS_OP_CLOSEDIR, (result >= 0), handle, "");
830 return result;
833 static void smb_full_audit_init_search_op(vfs_handle_struct *handle,
834 DIR *dirp)
836 SMB_VFS_NEXT_INIT_SEARCH_OP(handle, dirp);
838 do_log(SMB_VFS_OP_INIT_SEARCH_OP, True, handle, "");
839 return;
842 static int smb_full_audit_open(vfs_handle_struct *handle,
843 struct smb_filename *smb_fname,
844 files_struct *fsp, int flags, mode_t mode)
846 int result;
848 result = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
850 do_log(SMB_VFS_OP_OPEN, (result >= 0), handle, "%s|%s",
851 ((flags & O_WRONLY) || (flags & O_RDWR))?"w":"r",
852 smb_fname_str_do_log(smb_fname));
854 return result;
857 static NTSTATUS smb_full_audit_create_file(vfs_handle_struct *handle,
858 struct smb_request *req,
859 uint16_t root_dir_fid,
860 struct smb_filename *smb_fname,
861 uint32_t access_mask,
862 uint32_t share_access,
863 uint32_t create_disposition,
864 uint32_t create_options,
865 uint32_t file_attributes,
866 uint32_t oplock_request,
867 uint64_t allocation_size,
868 uint32_t private_flags,
869 struct security_descriptor *sd,
870 struct ea_list *ea_list,
871 files_struct **result_fsp,
872 int *pinfo)
874 NTSTATUS result;
875 const char* str_create_disposition;
877 switch (create_disposition) {
878 case FILE_SUPERSEDE:
879 str_create_disposition = "supersede";
880 break;
881 case FILE_OVERWRITE_IF:
882 str_create_disposition = "overwrite_if";
883 break;
884 case FILE_OPEN:
885 str_create_disposition = "open";
886 break;
887 case FILE_OVERWRITE:
888 str_create_disposition = "overwrite";
889 break;
890 case FILE_CREATE:
891 str_create_disposition = "create";
892 break;
893 case FILE_OPEN_IF:
894 str_create_disposition = "open_if";
895 break;
896 default:
897 str_create_disposition = "unknown";
900 result = SMB_VFS_NEXT_CREATE_FILE(
901 handle, /* handle */
902 req, /* req */
903 root_dir_fid, /* root_dir_fid */
904 smb_fname, /* fname */
905 access_mask, /* access_mask */
906 share_access, /* share_access */
907 create_disposition, /* create_disposition*/
908 create_options, /* create_options */
909 file_attributes, /* file_attributes */
910 oplock_request, /* oplock_request */
911 allocation_size, /* allocation_size */
912 private_flags,
913 sd, /* sd */
914 ea_list, /* ea_list */
915 result_fsp, /* result */
916 pinfo); /* pinfo */
918 do_log(SMB_VFS_OP_CREATE_FILE, (NT_STATUS_IS_OK(result)), handle,
919 "0x%x|%s|%s|%s", access_mask,
920 create_options & FILE_DIRECTORY_FILE ? "dir" : "file",
921 str_create_disposition, smb_fname_str_do_log(smb_fname));
923 return result;
926 static int smb_full_audit_close(vfs_handle_struct *handle, files_struct *fsp)
928 int result;
930 result = SMB_VFS_NEXT_CLOSE(handle, fsp);
932 do_log(SMB_VFS_OP_CLOSE, (result >= 0), handle, "%s",
933 fsp_str_do_log(fsp));
935 return result;
938 static ssize_t smb_full_audit_read(vfs_handle_struct *handle, files_struct *fsp,
939 void *data, size_t n)
941 ssize_t result;
943 result = SMB_VFS_NEXT_READ(handle, fsp, data, n);
945 do_log(SMB_VFS_OP_READ, (result >= 0), handle, "%s",
946 fsp_str_do_log(fsp));
948 return result;
951 static ssize_t smb_full_audit_pread(vfs_handle_struct *handle, files_struct *fsp,
952 void *data, size_t n, off_t offset)
954 ssize_t result;
956 result = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
958 do_log(SMB_VFS_OP_PREAD, (result >= 0), handle, "%s",
959 fsp_str_do_log(fsp));
961 return result;
964 struct smb_full_audit_pread_state {
965 vfs_handle_struct *handle;
966 files_struct *fsp;
967 ssize_t ret;
968 int err;
971 static void smb_full_audit_pread_done(struct tevent_req *subreq);
973 static struct tevent_req *smb_full_audit_pread_send(
974 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
975 struct tevent_context *ev, struct files_struct *fsp,
976 void *data, size_t n, off_t offset)
978 struct tevent_req *req, *subreq;
979 struct smb_full_audit_pread_state *state;
981 req = tevent_req_create(mem_ctx, &state,
982 struct smb_full_audit_pread_state);
983 if (req == NULL) {
984 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
985 fsp_str_do_log(fsp));
986 return NULL;
988 state->handle = handle;
989 state->fsp = fsp;
991 subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
992 n, offset);
993 if (tevent_req_nomem(subreq, req)) {
994 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
995 fsp_str_do_log(fsp));
996 return tevent_req_post(req, ev);
998 tevent_req_set_callback(subreq, smb_full_audit_pread_done, req);
1000 do_log(SMB_VFS_OP_PREAD_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1001 return req;
1004 static void smb_full_audit_pread_done(struct tevent_req *subreq)
1006 struct tevent_req *req = tevent_req_callback_data(
1007 subreq, struct tevent_req);
1008 struct smb_full_audit_pread_state *state = tevent_req_data(
1009 req, struct smb_full_audit_pread_state);
1011 state->ret = SMB_VFS_PREAD_RECV(subreq, &state->err);
1012 TALLOC_FREE(subreq);
1013 tevent_req_done(req);
1016 static ssize_t smb_full_audit_pread_recv(struct tevent_req *req, int *err)
1018 struct smb_full_audit_pread_state *state = tevent_req_data(
1019 req, struct smb_full_audit_pread_state);
1021 if (tevent_req_is_unix_error(req, err)) {
1022 do_log(SMB_VFS_OP_PREAD_RECV, false, state->handle, "%s",
1023 fsp_str_do_log(state->fsp));
1024 return -1;
1027 do_log(SMB_VFS_OP_PREAD_RECV, (state->ret >= 0), state->handle, "%s",
1028 fsp_str_do_log(state->fsp));
1030 *err = state->err;
1031 return state->ret;
1034 static ssize_t smb_full_audit_write(vfs_handle_struct *handle, files_struct *fsp,
1035 const void *data, size_t n)
1037 ssize_t result;
1039 result = SMB_VFS_NEXT_WRITE(handle, fsp, data, n);
1041 do_log(SMB_VFS_OP_WRITE, (result >= 0), handle, "%s",
1042 fsp_str_do_log(fsp));
1044 return result;
1047 static ssize_t smb_full_audit_pwrite(vfs_handle_struct *handle, files_struct *fsp,
1048 const void *data, size_t n,
1049 off_t offset)
1051 ssize_t result;
1053 result = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
1055 do_log(SMB_VFS_OP_PWRITE, (result >= 0), handle, "%s",
1056 fsp_str_do_log(fsp));
1058 return result;
1061 struct smb_full_audit_pwrite_state {
1062 vfs_handle_struct *handle;
1063 files_struct *fsp;
1064 ssize_t ret;
1065 int err;
1068 static void smb_full_audit_pwrite_done(struct tevent_req *subreq);
1070 static struct tevent_req *smb_full_audit_pwrite_send(
1071 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1072 struct tevent_context *ev, struct files_struct *fsp,
1073 const void *data, size_t n, off_t offset)
1075 struct tevent_req *req, *subreq;
1076 struct smb_full_audit_pwrite_state *state;
1078 req = tevent_req_create(mem_ctx, &state,
1079 struct smb_full_audit_pwrite_state);
1080 if (req == NULL) {
1081 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1082 fsp_str_do_log(fsp));
1083 return NULL;
1085 state->handle = handle;
1086 state->fsp = fsp;
1088 subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
1089 n, offset);
1090 if (tevent_req_nomem(subreq, req)) {
1091 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1092 fsp_str_do_log(fsp));
1093 return tevent_req_post(req, ev);
1095 tevent_req_set_callback(subreq, smb_full_audit_pwrite_done, req);
1097 do_log(SMB_VFS_OP_PWRITE_SEND, true, handle, "%s",
1098 fsp_str_do_log(fsp));
1099 return req;
1102 static void smb_full_audit_pwrite_done(struct tevent_req *subreq)
1104 struct tevent_req *req = tevent_req_callback_data(
1105 subreq, struct tevent_req);
1106 struct smb_full_audit_pwrite_state *state = tevent_req_data(
1107 req, struct smb_full_audit_pwrite_state);
1109 state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->err);
1110 TALLOC_FREE(subreq);
1111 tevent_req_done(req);
1114 static ssize_t smb_full_audit_pwrite_recv(struct tevent_req *req, int *err)
1116 struct smb_full_audit_pwrite_state *state = tevent_req_data(
1117 req, struct smb_full_audit_pwrite_state);
1119 if (tevent_req_is_unix_error(req, err)) {
1120 do_log(SMB_VFS_OP_PWRITE_RECV, false, state->handle, "%s",
1121 fsp_str_do_log(state->fsp));
1122 return -1;
1125 do_log(SMB_VFS_OP_PWRITE_RECV, (state->ret >= 0), state->handle, "%s",
1126 fsp_str_do_log(state->fsp));
1128 *err = state->err;
1129 return state->ret;
1132 static off_t smb_full_audit_lseek(vfs_handle_struct *handle, files_struct *fsp,
1133 off_t offset, int whence)
1135 ssize_t result;
1137 result = SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence);
1139 do_log(SMB_VFS_OP_LSEEK, (result != (ssize_t)-1), handle,
1140 "%s", fsp_str_do_log(fsp));
1142 return result;
1145 static ssize_t smb_full_audit_sendfile(vfs_handle_struct *handle, int tofd,
1146 files_struct *fromfsp,
1147 const DATA_BLOB *hdr, off_t offset,
1148 size_t n)
1150 ssize_t result;
1152 result = SMB_VFS_NEXT_SENDFILE(handle, tofd, fromfsp, hdr, offset, n);
1154 do_log(SMB_VFS_OP_SENDFILE, (result >= 0), handle,
1155 "%s", fsp_str_do_log(fromfsp));
1157 return result;
1160 static ssize_t smb_full_audit_recvfile(vfs_handle_struct *handle, int fromfd,
1161 files_struct *tofsp,
1162 off_t offset,
1163 size_t n)
1165 ssize_t result;
1167 result = SMB_VFS_NEXT_RECVFILE(handle, fromfd, tofsp, offset, n);
1169 do_log(SMB_VFS_OP_RECVFILE, (result >= 0), handle,
1170 "%s", fsp_str_do_log(tofsp));
1172 return result;
1175 static int smb_full_audit_rename(vfs_handle_struct *handle,
1176 const struct smb_filename *smb_fname_src,
1177 const struct smb_filename *smb_fname_dst)
1179 int result;
1181 result = SMB_VFS_NEXT_RENAME(handle, smb_fname_src, smb_fname_dst);
1183 do_log(SMB_VFS_OP_RENAME, (result >= 0), handle, "%s|%s",
1184 smb_fname_str_do_log(smb_fname_src),
1185 smb_fname_str_do_log(smb_fname_dst));
1187 return result;
1190 static int smb_full_audit_fsync(vfs_handle_struct *handle, files_struct *fsp)
1192 int result;
1194 result = SMB_VFS_NEXT_FSYNC(handle, fsp);
1196 do_log(SMB_VFS_OP_FSYNC, (result >= 0), handle, "%s",
1197 fsp_str_do_log(fsp));
1199 return result;
1202 struct smb_full_audit_fsync_state {
1203 vfs_handle_struct *handle;
1204 files_struct *fsp;
1205 int ret;
1206 int err;
1209 static void smb_full_audit_fsync_done(struct tevent_req *subreq);
1211 static struct tevent_req *smb_full_audit_fsync_send(
1212 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1213 struct tevent_context *ev, struct files_struct *fsp)
1215 struct tevent_req *req, *subreq;
1216 struct smb_full_audit_fsync_state *state;
1218 req = tevent_req_create(mem_ctx, &state,
1219 struct smb_full_audit_fsync_state);
1220 if (req == NULL) {
1221 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1222 fsp_str_do_log(fsp));
1223 return NULL;
1225 state->handle = handle;
1226 state->fsp = fsp;
1228 subreq = SMB_VFS_NEXT_FSYNC_SEND(state, ev, handle, fsp);
1229 if (tevent_req_nomem(subreq, req)) {
1230 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1231 fsp_str_do_log(fsp));
1232 return tevent_req_post(req, ev);
1234 tevent_req_set_callback(subreq, smb_full_audit_fsync_done, req);
1236 do_log(SMB_VFS_OP_FSYNC_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1237 return req;
1240 static void smb_full_audit_fsync_done(struct tevent_req *subreq)
1242 struct tevent_req *req = tevent_req_callback_data(
1243 subreq, struct tevent_req);
1244 struct smb_full_audit_fsync_state *state = tevent_req_data(
1245 req, struct smb_full_audit_fsync_state);
1247 state->ret = SMB_VFS_FSYNC_RECV(subreq, &state->err);
1248 TALLOC_FREE(subreq);
1249 tevent_req_done(req);
1252 static int smb_full_audit_fsync_recv(struct tevent_req *req, int *err)
1254 struct smb_full_audit_fsync_state *state = tevent_req_data(
1255 req, struct smb_full_audit_fsync_state);
1257 if (tevent_req_is_unix_error(req, err)) {
1258 do_log(SMB_VFS_OP_FSYNC_RECV, false, state->handle, "%s",
1259 fsp_str_do_log(state->fsp));
1260 return -1;
1263 do_log(SMB_VFS_OP_FSYNC_RECV, (state->ret >= 0), state->handle, "%s",
1264 fsp_str_do_log(state->fsp));
1266 *err = state->err;
1267 return state->ret;
1270 static int smb_full_audit_stat(vfs_handle_struct *handle,
1271 struct smb_filename *smb_fname)
1273 int result;
1275 result = SMB_VFS_NEXT_STAT(handle, smb_fname);
1277 do_log(SMB_VFS_OP_STAT, (result >= 0), handle, "%s",
1278 smb_fname_str_do_log(smb_fname));
1280 return result;
1283 static int smb_full_audit_fstat(vfs_handle_struct *handle, files_struct *fsp,
1284 SMB_STRUCT_STAT *sbuf)
1286 int result;
1288 result = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1290 do_log(SMB_VFS_OP_FSTAT, (result >= 0), handle, "%s",
1291 fsp_str_do_log(fsp));
1293 return result;
1296 static int smb_full_audit_lstat(vfs_handle_struct *handle,
1297 struct smb_filename *smb_fname)
1299 int result;
1301 result = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
1303 do_log(SMB_VFS_OP_LSTAT, (result >= 0), handle, "%s",
1304 smb_fname_str_do_log(smb_fname));
1306 return result;
1309 static uint64_t smb_full_audit_get_alloc_size(vfs_handle_struct *handle,
1310 files_struct *fsp, const SMB_STRUCT_STAT *sbuf)
1312 uint64_t result;
1314 result = SMB_VFS_NEXT_GET_ALLOC_SIZE(handle, fsp, sbuf);
1316 do_log(SMB_VFS_OP_GET_ALLOC_SIZE, (result != (uint64_t)-1), handle,
1317 "%llu", result);
1319 return result;
1322 static int smb_full_audit_unlink(vfs_handle_struct *handle,
1323 const struct smb_filename *smb_fname)
1325 int result;
1327 result = SMB_VFS_NEXT_UNLINK(handle, smb_fname);
1329 do_log(SMB_VFS_OP_UNLINK, (result >= 0), handle, "%s",
1330 smb_fname_str_do_log(smb_fname));
1332 return result;
1335 static int smb_full_audit_chmod(vfs_handle_struct *handle,
1336 const char *path, mode_t mode)
1338 int result;
1340 result = SMB_VFS_NEXT_CHMOD(handle, path, mode);
1342 do_log(SMB_VFS_OP_CHMOD, (result >= 0), handle, "%s|%o", path, mode);
1344 return result;
1347 static int smb_full_audit_fchmod(vfs_handle_struct *handle, files_struct *fsp,
1348 mode_t mode)
1350 int result;
1352 result = SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1354 do_log(SMB_VFS_OP_FCHMOD, (result >= 0), handle,
1355 "%s|%o", fsp_str_do_log(fsp), mode);
1357 return result;
1360 static int smb_full_audit_chown(vfs_handle_struct *handle,
1361 const char *path, uid_t uid, gid_t gid)
1363 int result;
1365 result = SMB_VFS_NEXT_CHOWN(handle, path, uid, gid);
1367 do_log(SMB_VFS_OP_CHOWN, (result >= 0), handle, "%s|%ld|%ld",
1368 path, (long int)uid, (long int)gid);
1370 return result;
1373 static int smb_full_audit_fchown(vfs_handle_struct *handle, files_struct *fsp,
1374 uid_t uid, gid_t gid)
1376 int result;
1378 result = SMB_VFS_NEXT_FCHOWN(handle, fsp, uid, gid);
1380 do_log(SMB_VFS_OP_FCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1381 fsp_str_do_log(fsp), (long int)uid, (long int)gid);
1383 return result;
1386 static int smb_full_audit_lchown(vfs_handle_struct *handle,
1387 const char *path, uid_t uid, gid_t gid)
1389 int result;
1391 result = SMB_VFS_NEXT_LCHOWN(handle, path, uid, gid);
1393 do_log(SMB_VFS_OP_LCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1394 path, (long int)uid, (long int)gid);
1396 return result;
1399 static int smb_full_audit_chdir(vfs_handle_struct *handle,
1400 const char *path)
1402 int result;
1404 result = SMB_VFS_NEXT_CHDIR(handle, path);
1406 do_log(SMB_VFS_OP_CHDIR, (result >= 0), handle, "chdir|%s", path);
1408 return result;
1411 static char *smb_full_audit_getwd(vfs_handle_struct *handle)
1413 char *result;
1415 result = SMB_VFS_NEXT_GETWD(handle);
1417 do_log(SMB_VFS_OP_GETWD, (result != NULL), handle, "%s",
1418 result == NULL? "" : result);
1420 return result;
1423 static int smb_full_audit_ntimes(vfs_handle_struct *handle,
1424 const struct smb_filename *smb_fname,
1425 struct smb_file_time *ft)
1427 int result;
1429 result = SMB_VFS_NEXT_NTIMES(handle, smb_fname, ft);
1431 do_log(SMB_VFS_OP_NTIMES, (result >= 0), handle, "%s",
1432 smb_fname_str_do_log(smb_fname));
1434 return result;
1437 static int smb_full_audit_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
1438 off_t len)
1440 int result;
1442 result = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1444 do_log(SMB_VFS_OP_FTRUNCATE, (result >= 0), handle,
1445 "%s", fsp_str_do_log(fsp));
1447 return result;
1450 static int smb_full_audit_fallocate(vfs_handle_struct *handle, files_struct *fsp,
1451 enum vfs_fallocate_mode mode,
1452 off_t offset,
1453 off_t len)
1455 int result;
1457 result = SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
1459 do_log(SMB_VFS_OP_FALLOCATE, (result >= 0), handle,
1460 "%s", fsp_str_do_log(fsp));
1462 return result;
1465 static bool smb_full_audit_lock(vfs_handle_struct *handle, files_struct *fsp,
1466 int op, off_t offset, off_t count, int type)
1468 bool result;
1470 result = SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type);
1472 do_log(SMB_VFS_OP_LOCK, result, handle, "%s", fsp_str_do_log(fsp));
1474 return result;
1477 static int smb_full_audit_kernel_flock(struct vfs_handle_struct *handle,
1478 struct files_struct *fsp,
1479 uint32 share_mode, uint32 access_mask)
1481 int result;
1483 result = SMB_VFS_NEXT_KERNEL_FLOCK(handle, fsp, share_mode, access_mask);
1485 do_log(SMB_VFS_OP_KERNEL_FLOCK, (result >= 0), handle, "%s",
1486 fsp_str_do_log(fsp));
1488 return result;
1491 static int smb_full_audit_linux_setlease(vfs_handle_struct *handle, files_struct *fsp,
1492 int leasetype)
1494 int result;
1496 result = SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
1498 do_log(SMB_VFS_OP_LINUX_SETLEASE, (result >= 0), handle, "%s",
1499 fsp_str_do_log(fsp));
1501 return result;
1504 static bool smb_full_audit_getlock(vfs_handle_struct *handle, files_struct *fsp,
1505 off_t *poffset, off_t *pcount, int *ptype, pid_t *ppid)
1507 bool result;
1509 result = SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype, ppid);
1511 do_log(SMB_VFS_OP_GETLOCK, result, handle, "%s", fsp_str_do_log(fsp));
1513 return result;
1516 static int smb_full_audit_symlink(vfs_handle_struct *handle,
1517 const char *oldpath, const char *newpath)
1519 int result;
1521 result = SMB_VFS_NEXT_SYMLINK(handle, oldpath, newpath);
1523 do_log(SMB_VFS_OP_SYMLINK, (result >= 0), handle,
1524 "%s|%s", oldpath, newpath);
1526 return result;
1529 static int smb_full_audit_readlink(vfs_handle_struct *handle,
1530 const char *path, char *buf, size_t bufsiz)
1532 int result;
1534 result = SMB_VFS_NEXT_READLINK(handle, path, buf, bufsiz);
1536 do_log(SMB_VFS_OP_READLINK, (result >= 0), handle, "%s", path);
1538 return result;
1541 static int smb_full_audit_link(vfs_handle_struct *handle,
1542 const char *oldpath, const char *newpath)
1544 int result;
1546 result = SMB_VFS_NEXT_LINK(handle, oldpath, newpath);
1548 do_log(SMB_VFS_OP_LINK, (result >= 0), handle,
1549 "%s|%s", oldpath, newpath);
1551 return result;
1554 static int smb_full_audit_mknod(vfs_handle_struct *handle,
1555 const char *pathname, mode_t mode, SMB_DEV_T dev)
1557 int result;
1559 result = SMB_VFS_NEXT_MKNOD(handle, pathname, mode, dev);
1561 do_log(SMB_VFS_OP_MKNOD, (result >= 0), handle, "%s", pathname);
1563 return result;
1566 static char *smb_full_audit_realpath(vfs_handle_struct *handle,
1567 const char *path)
1569 char *result;
1571 result = SMB_VFS_NEXT_REALPATH(handle, path);
1573 do_log(SMB_VFS_OP_REALPATH, (result != NULL), handle, "%s", path);
1575 return result;
1578 static NTSTATUS smb_full_audit_notify_watch(struct vfs_handle_struct *handle,
1579 struct sys_notify_context *ctx,
1580 const char *path,
1581 uint32_t *filter,
1582 uint32_t *subdir_filter,
1583 void (*callback)(struct sys_notify_context *ctx,
1584 void *private_data,
1585 struct notify_event *ev),
1586 void *private_data, void *handle_p)
1588 NTSTATUS result;
1590 result = SMB_VFS_NEXT_NOTIFY_WATCH(handle, ctx, path,
1591 filter, subdir_filter, callback,
1592 private_data, handle_p);
1594 do_log(SMB_VFS_OP_NOTIFY_WATCH, NT_STATUS_IS_OK(result), handle, "");
1596 return result;
1599 static int smb_full_audit_chflags(vfs_handle_struct *handle,
1600 const char *path, unsigned int flags)
1602 int result;
1604 result = SMB_VFS_NEXT_CHFLAGS(handle, path, flags);
1606 do_log(SMB_VFS_OP_CHFLAGS, (result != 0), handle, "%s", path);
1608 return result;
1611 static struct file_id smb_full_audit_file_id_create(struct vfs_handle_struct *handle,
1612 const SMB_STRUCT_STAT *sbuf)
1614 struct file_id id_zero;
1615 struct file_id result;
1617 ZERO_STRUCT(id_zero);
1619 result = SMB_VFS_NEXT_FILE_ID_CREATE(handle, sbuf);
1621 do_log(SMB_VFS_OP_FILE_ID_CREATE,
1622 !file_id_equal(&id_zero, &result),
1623 handle, "%s", file_id_string_tos(&result));
1625 return result;
1628 static NTSTATUS smb_full_audit_streaminfo(vfs_handle_struct *handle,
1629 struct files_struct *fsp,
1630 const char *fname,
1631 TALLOC_CTX *mem_ctx,
1632 unsigned int *pnum_streams,
1633 struct stream_struct **pstreams)
1635 NTSTATUS result;
1637 result = SMB_VFS_NEXT_STREAMINFO(handle, fsp, fname, mem_ctx,
1638 pnum_streams, pstreams);
1640 do_log(SMB_VFS_OP_STREAMINFO, NT_STATUS_IS_OK(result), handle,
1641 "%s", fname);
1643 return result;
1646 static int smb_full_audit_get_real_filename(struct vfs_handle_struct *handle,
1647 const char *path,
1648 const char *name,
1649 TALLOC_CTX *mem_ctx,
1650 char **found_name)
1652 int result;
1654 result = SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name, mem_ctx,
1655 found_name);
1657 do_log(SMB_VFS_OP_GET_REAL_FILENAME, (result == 0), handle,
1658 "%s/%s->%s", path, name, (result == 0) ? "" : *found_name);
1660 return result;
1663 static const char *smb_full_audit_connectpath(vfs_handle_struct *handle,
1664 const char *fname)
1666 const char *result;
1668 result = SMB_VFS_NEXT_CONNECTPATH(handle, fname);
1670 do_log(SMB_VFS_OP_CONNECTPATH, result != NULL, handle,
1671 "%s", fname);
1673 return result;
1676 static NTSTATUS smb_full_audit_brl_lock_windows(struct vfs_handle_struct *handle,
1677 struct byte_range_lock *br_lck,
1678 struct lock_struct *plock,
1679 bool blocking_lock,
1680 struct blocking_lock_record *blr)
1682 NTSTATUS result;
1684 result = SMB_VFS_NEXT_BRL_LOCK_WINDOWS(handle, br_lck, plock,
1685 blocking_lock, blr);
1687 do_log(SMB_VFS_OP_BRL_LOCK_WINDOWS, NT_STATUS_IS_OK(result), handle,
1688 "%s:%llu-%llu. type=%d. blocking=%d", fsp_str_do_log(br_lck->fsp),
1689 plock->start, plock->size, plock->lock_type, blocking_lock );
1691 return result;
1694 static bool smb_full_audit_brl_unlock_windows(struct vfs_handle_struct *handle,
1695 struct messaging_context *msg_ctx,
1696 struct byte_range_lock *br_lck,
1697 const struct lock_struct *plock)
1699 bool result;
1701 result = SMB_VFS_NEXT_BRL_UNLOCK_WINDOWS(handle, msg_ctx, br_lck,
1702 plock);
1704 do_log(SMB_VFS_OP_BRL_UNLOCK_WINDOWS, (result == 0), handle,
1705 "%s:%llu-%llu:%d", fsp_str_do_log(br_lck->fsp), plock->start,
1706 plock->size, plock->lock_type);
1708 return result;
1711 static bool smb_full_audit_brl_cancel_windows(struct vfs_handle_struct *handle,
1712 struct byte_range_lock *br_lck,
1713 struct lock_struct *plock,
1714 struct blocking_lock_record *blr)
1716 bool result;
1718 result = SMB_VFS_NEXT_BRL_CANCEL_WINDOWS(handle, br_lck, plock, blr);
1720 do_log(SMB_VFS_OP_BRL_CANCEL_WINDOWS, (result == 0), handle,
1721 "%s:%llu-%llu:%d", fsp_str_do_log(br_lck->fsp), plock->start,
1722 plock->size);
1724 return result;
1727 static bool smb_full_audit_strict_lock(struct vfs_handle_struct *handle,
1728 struct files_struct *fsp,
1729 struct lock_struct *plock)
1731 bool result;
1733 result = SMB_VFS_NEXT_STRICT_LOCK(handle, fsp, plock);
1735 do_log(SMB_VFS_OP_STRICT_LOCK, result, handle,
1736 "%s:%llu-%llu:%d", fsp_str_do_log(fsp), plock->start,
1737 plock->size);
1739 return result;
1742 static void smb_full_audit_strict_unlock(struct vfs_handle_struct *handle,
1743 struct files_struct *fsp,
1744 struct lock_struct *plock)
1746 SMB_VFS_NEXT_STRICT_UNLOCK(handle, fsp, plock);
1748 do_log(SMB_VFS_OP_STRICT_UNLOCK, true, handle,
1749 "%s:%llu-%llu:%d", fsp_str_do_log(fsp), plock->start,
1750 plock->size);
1752 return;
1755 static NTSTATUS smb_full_audit_translate_name(struct vfs_handle_struct *handle,
1756 const char *name,
1757 enum vfs_translate_direction direction,
1758 TALLOC_CTX *mem_ctx,
1759 char **mapped_name)
1761 NTSTATUS result;
1763 result = SMB_VFS_NEXT_TRANSLATE_NAME(handle, name, direction, mem_ctx,
1764 mapped_name);
1766 do_log(SMB_VFS_OP_TRANSLATE_NAME, NT_STATUS_IS_OK(result), handle, "");
1768 return result;
1771 static NTSTATUS smb_full_audit_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
1772 uint32 security_info,
1773 struct security_descriptor **ppdesc)
1775 NTSTATUS result;
1777 result = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info, ppdesc);
1779 do_log(SMB_VFS_OP_FGET_NT_ACL, NT_STATUS_IS_OK(result), handle,
1780 "%s", fsp_str_do_log(fsp));
1782 return result;
1785 static NTSTATUS smb_full_audit_get_nt_acl(vfs_handle_struct *handle,
1786 const char *name,
1787 uint32 security_info,
1788 struct security_descriptor **ppdesc)
1790 NTSTATUS result;
1792 result = SMB_VFS_NEXT_GET_NT_ACL(handle, name, security_info, ppdesc);
1794 do_log(SMB_VFS_OP_GET_NT_ACL, NT_STATUS_IS_OK(result), handle,
1795 "%s", name);
1797 return result;
1800 static NTSTATUS smb_full_audit_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
1801 uint32 security_info_sent,
1802 const struct security_descriptor *psd)
1804 NTSTATUS result;
1806 result = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
1808 do_log(SMB_VFS_OP_FSET_NT_ACL, NT_STATUS_IS_OK(result), handle, "%s",
1809 fsp_str_do_log(fsp));
1811 return result;
1814 static int smb_full_audit_chmod_acl(vfs_handle_struct *handle,
1815 const char *path, mode_t mode)
1817 int result;
1819 result = SMB_VFS_NEXT_CHMOD_ACL(handle, path, mode);
1821 do_log(SMB_VFS_OP_CHMOD_ACL, (result >= 0), handle,
1822 "%s|%o", path, mode);
1824 return result;
1827 static int smb_full_audit_fchmod_acl(vfs_handle_struct *handle, files_struct *fsp,
1828 mode_t mode)
1830 int result;
1832 result = SMB_VFS_NEXT_FCHMOD_ACL(handle, fsp, mode);
1834 do_log(SMB_VFS_OP_FCHMOD_ACL, (result >= 0), handle,
1835 "%s|%o", fsp_str_do_log(fsp), mode);
1837 return result;
1840 static int smb_full_audit_sys_acl_get_entry(vfs_handle_struct *handle,
1842 SMB_ACL_T theacl, int entry_id,
1843 SMB_ACL_ENTRY_T *entry_p)
1845 int result;
1847 result = SMB_VFS_NEXT_SYS_ACL_GET_ENTRY(handle, theacl, entry_id,
1848 entry_p);
1850 do_log(SMB_VFS_OP_SYS_ACL_GET_ENTRY, (result >= 0), handle,
1851 "");
1853 return result;
1856 static int smb_full_audit_sys_acl_get_tag_type(vfs_handle_struct *handle,
1858 SMB_ACL_ENTRY_T entry_d,
1859 SMB_ACL_TAG_T *tag_type_p)
1861 int result;
1863 result = SMB_VFS_NEXT_SYS_ACL_GET_TAG_TYPE(handle, entry_d,
1864 tag_type_p);
1866 do_log(SMB_VFS_OP_SYS_ACL_GET_TAG_TYPE, (result >= 0), handle,
1867 "");
1869 return result;
1872 static int smb_full_audit_sys_acl_get_permset(vfs_handle_struct *handle,
1874 SMB_ACL_ENTRY_T entry_d,
1875 SMB_ACL_PERMSET_T *permset_p)
1877 int result;
1879 result = SMB_VFS_NEXT_SYS_ACL_GET_PERMSET(handle, entry_d,
1880 permset_p);
1882 do_log(SMB_VFS_OP_SYS_ACL_GET_PERMSET, (result >= 0), handle,
1883 "");
1885 return result;
1888 static void * smb_full_audit_sys_acl_get_qualifier(vfs_handle_struct *handle,
1890 SMB_ACL_ENTRY_T entry_d)
1892 void *result;
1894 result = SMB_VFS_NEXT_SYS_ACL_GET_QUALIFIER(handle, entry_d);
1896 do_log(SMB_VFS_OP_SYS_ACL_GET_QUALIFIER, (result != NULL), handle,
1897 "");
1899 return result;
1902 static SMB_ACL_T smb_full_audit_sys_acl_get_file(vfs_handle_struct *handle,
1903 const char *path_p,
1904 SMB_ACL_TYPE_T type)
1906 SMB_ACL_T result;
1908 result = SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, path_p, type);
1910 do_log(SMB_VFS_OP_SYS_ACL_GET_FILE, (result != NULL), handle,
1911 "%s", path_p);
1913 return result;
1916 static SMB_ACL_T smb_full_audit_sys_acl_get_fd(vfs_handle_struct *handle,
1917 files_struct *fsp)
1919 SMB_ACL_T result;
1921 result = SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp);
1923 do_log(SMB_VFS_OP_SYS_ACL_GET_FD, (result != NULL), handle,
1924 "%s", fsp_str_do_log(fsp));
1926 return result;
1929 static int smb_full_audit_sys_acl_clear_perms(vfs_handle_struct *handle,
1931 SMB_ACL_PERMSET_T permset)
1933 int result;
1935 result = SMB_VFS_NEXT_SYS_ACL_CLEAR_PERMS(handle, permset);
1937 do_log(SMB_VFS_OP_SYS_ACL_CLEAR_PERMS, (result >= 0), handle,
1938 "");
1940 return result;
1943 static int smb_full_audit_sys_acl_add_perm(vfs_handle_struct *handle,
1945 SMB_ACL_PERMSET_T permset,
1946 SMB_ACL_PERM_T perm)
1948 int result;
1950 result = SMB_VFS_NEXT_SYS_ACL_ADD_PERM(handle, permset, perm);
1952 do_log(SMB_VFS_OP_SYS_ACL_ADD_PERM, (result >= 0), handle,
1953 "");
1955 return result;
1958 static char * smb_full_audit_sys_acl_to_text(vfs_handle_struct *handle,
1959 SMB_ACL_T theacl,
1960 ssize_t *plen)
1962 char * result;
1964 result = SMB_VFS_NEXT_SYS_ACL_TO_TEXT(handle, theacl, plen);
1966 do_log(SMB_VFS_OP_SYS_ACL_TO_TEXT, (result != NULL), handle,
1967 "");
1969 return result;
1972 static SMB_ACL_T smb_full_audit_sys_acl_init(vfs_handle_struct *handle,
1974 int count)
1976 SMB_ACL_T result;
1978 result = SMB_VFS_NEXT_SYS_ACL_INIT(handle, count);
1980 do_log(SMB_VFS_OP_SYS_ACL_INIT, (result != NULL), handle,
1981 "");
1983 return result;
1986 static int smb_full_audit_sys_acl_create_entry(vfs_handle_struct *handle,
1987 SMB_ACL_T *pacl,
1988 SMB_ACL_ENTRY_T *pentry)
1990 int result;
1992 result = SMB_VFS_NEXT_SYS_ACL_CREATE_ENTRY(handle, pacl, pentry);
1994 do_log(SMB_VFS_OP_SYS_ACL_CREATE_ENTRY, (result >= 0), handle,
1995 "");
1997 return result;
2000 static int smb_full_audit_sys_acl_set_tag_type(vfs_handle_struct *handle,
2002 SMB_ACL_ENTRY_T entry,
2003 SMB_ACL_TAG_T tagtype)
2005 int result;
2007 result = SMB_VFS_NEXT_SYS_ACL_SET_TAG_TYPE(handle, entry,
2008 tagtype);
2010 do_log(SMB_VFS_OP_SYS_ACL_SET_TAG_TYPE, (result >= 0), handle,
2011 "");
2013 return result;
2016 static int smb_full_audit_sys_acl_set_qualifier(vfs_handle_struct *handle,
2018 SMB_ACL_ENTRY_T entry,
2019 void *qual)
2021 int result;
2023 result = SMB_VFS_NEXT_SYS_ACL_SET_QUALIFIER(handle, entry, qual);
2025 do_log(SMB_VFS_OP_SYS_ACL_SET_QUALIFIER, (result >= 0), handle,
2026 "");
2028 return result;
2031 static int smb_full_audit_sys_acl_set_permset(vfs_handle_struct *handle,
2033 SMB_ACL_ENTRY_T entry,
2034 SMB_ACL_PERMSET_T permset)
2036 int result;
2038 result = SMB_VFS_NEXT_SYS_ACL_SET_PERMSET(handle, entry, permset);
2040 do_log(SMB_VFS_OP_SYS_ACL_SET_PERMSET, (result >= 0), handle,
2041 "");
2043 return result;
2046 static int smb_full_audit_sys_acl_valid(vfs_handle_struct *handle,
2048 SMB_ACL_T theacl )
2050 int result;
2052 result = SMB_VFS_NEXT_SYS_ACL_VALID(handle, theacl);
2054 do_log(SMB_VFS_OP_SYS_ACL_VALID, (result >= 0), handle,
2055 "");
2057 return result;
2060 static int smb_full_audit_sys_acl_set_file(vfs_handle_struct *handle,
2062 const char *name, SMB_ACL_TYPE_T acltype,
2063 SMB_ACL_T theacl)
2065 int result;
2067 result = SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, name, acltype,
2068 theacl);
2070 do_log(SMB_VFS_OP_SYS_ACL_SET_FILE, (result >= 0), handle,
2071 "%s", name);
2073 return result;
2076 static int smb_full_audit_sys_acl_set_fd(vfs_handle_struct *handle, files_struct *fsp,
2077 SMB_ACL_T theacl)
2079 int result;
2081 result = SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, theacl);
2083 do_log(SMB_VFS_OP_SYS_ACL_SET_FD, (result >= 0), handle,
2084 "%s", fsp_str_do_log(fsp));
2086 return result;
2089 static int smb_full_audit_sys_acl_delete_def_file(vfs_handle_struct *handle,
2091 const char *path)
2093 int result;
2095 result = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, path);
2097 do_log(SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE, (result >= 0), handle,
2098 "%s", path);
2100 return result;
2103 static int smb_full_audit_sys_acl_get_perm(vfs_handle_struct *handle,
2105 SMB_ACL_PERMSET_T permset,
2106 SMB_ACL_PERM_T perm)
2108 int result;
2110 result = SMB_VFS_NEXT_SYS_ACL_GET_PERM(handle, permset, perm);
2112 do_log(SMB_VFS_OP_SYS_ACL_GET_PERM, (result >= 0), handle,
2113 "");
2115 return result;
2118 static int smb_full_audit_sys_acl_free_text(vfs_handle_struct *handle,
2120 char *text)
2122 int result;
2124 result = SMB_VFS_NEXT_SYS_ACL_FREE_TEXT(handle, text);
2126 do_log(SMB_VFS_OP_SYS_ACL_FREE_TEXT, (result >= 0), handle,
2127 "");
2129 return result;
2132 static int smb_full_audit_sys_acl_free_acl(vfs_handle_struct *handle,
2134 SMB_ACL_T posix_acl)
2136 int result;
2138 result = SMB_VFS_NEXT_SYS_ACL_FREE_ACL(handle, posix_acl);
2140 do_log(SMB_VFS_OP_SYS_ACL_FREE_ACL, (result >= 0), handle,
2141 "");
2143 return result;
2146 static int smb_full_audit_sys_acl_free_qualifier(vfs_handle_struct *handle,
2147 void *qualifier,
2148 SMB_ACL_TAG_T tagtype)
2150 int result;
2152 result = SMB_VFS_NEXT_SYS_ACL_FREE_QUALIFIER(handle, qualifier,
2153 tagtype);
2155 do_log(SMB_VFS_OP_SYS_ACL_FREE_QUALIFIER, (result >= 0), handle,
2156 "");
2158 return result;
2161 static ssize_t smb_full_audit_getxattr(struct vfs_handle_struct *handle,
2162 const char *path,
2163 const char *name, void *value, size_t size)
2165 ssize_t result;
2167 result = SMB_VFS_NEXT_GETXATTR(handle, path, name, value, size);
2169 do_log(SMB_VFS_OP_GETXATTR, (result >= 0), handle,
2170 "%s|%s", path, name);
2172 return result;
2175 static ssize_t smb_full_audit_fgetxattr(struct vfs_handle_struct *handle,
2176 struct files_struct *fsp,
2177 const char *name, void *value, size_t size)
2179 ssize_t result;
2181 result = SMB_VFS_NEXT_FGETXATTR(handle, fsp, name, value, size);
2183 do_log(SMB_VFS_OP_FGETXATTR, (result >= 0), handle,
2184 "%s|%s", fsp_str_do_log(fsp), name);
2186 return result;
2189 static ssize_t smb_full_audit_listxattr(struct vfs_handle_struct *handle,
2190 const char *path, char *list, size_t size)
2192 ssize_t result;
2194 result = SMB_VFS_NEXT_LISTXATTR(handle, path, list, size);
2196 do_log(SMB_VFS_OP_LISTXATTR, (result >= 0), handle, "%s", path);
2198 return result;
2201 static ssize_t smb_full_audit_flistxattr(struct vfs_handle_struct *handle,
2202 struct files_struct *fsp, char *list,
2203 size_t size)
2205 ssize_t result;
2207 result = SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
2209 do_log(SMB_VFS_OP_FLISTXATTR, (result >= 0), handle,
2210 "%s", fsp_str_do_log(fsp));
2212 return result;
2215 static int smb_full_audit_removexattr(struct vfs_handle_struct *handle,
2216 const char *path,
2217 const char *name)
2219 int result;
2221 result = SMB_VFS_NEXT_REMOVEXATTR(handle, path, name);
2223 do_log(SMB_VFS_OP_REMOVEXATTR, (result >= 0), handle,
2224 "%s|%s", path, name);
2226 return result;
2229 static int smb_full_audit_fremovexattr(struct vfs_handle_struct *handle,
2230 struct files_struct *fsp,
2231 const char *name)
2233 int result;
2235 result = SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, name);
2237 do_log(SMB_VFS_OP_FREMOVEXATTR, (result >= 0), handle,
2238 "%s|%s", fsp_str_do_log(fsp), name);
2240 return result;
2243 static int smb_full_audit_setxattr(struct vfs_handle_struct *handle,
2244 const char *path,
2245 const char *name, const void *value, size_t size,
2246 int flags)
2248 int result;
2250 result = SMB_VFS_NEXT_SETXATTR(handle, path, name, value, size,
2251 flags);
2253 do_log(SMB_VFS_OP_SETXATTR, (result >= 0), handle,
2254 "%s|%s", path, name);
2256 return result;
2259 static int smb_full_audit_fsetxattr(struct vfs_handle_struct *handle,
2260 struct files_struct *fsp, const char *name,
2261 const void *value, size_t size, int flags)
2263 int result;
2265 result = SMB_VFS_NEXT_FSETXATTR(handle, fsp, name, value, size, flags);
2267 do_log(SMB_VFS_OP_FSETXATTR, (result >= 0), handle,
2268 "%s|%s", fsp_str_do_log(fsp), name);
2270 return result;
2273 static bool smb_full_audit_aio_force(struct vfs_handle_struct *handle,
2274 struct files_struct *fsp)
2276 bool result;
2278 result = SMB_VFS_NEXT_AIO_FORCE(handle, fsp);
2279 do_log(SMB_VFS_OP_AIO_FORCE, result, handle,
2280 "%s", fsp_str_do_log(fsp));
2282 return result;
2285 static bool smb_full_audit_is_offline(struct vfs_handle_struct *handle,
2286 const struct smb_filename *fname,
2287 SMB_STRUCT_STAT *sbuf)
2289 bool result;
2291 result = SMB_VFS_NEXT_IS_OFFLINE(handle, fname, sbuf);
2292 do_log(SMB_VFS_OP_IS_OFFLINE, result, handle, "%s",
2293 smb_fname_str_do_log(fname));
2294 return result;
2297 static int smb_full_audit_set_offline(struct vfs_handle_struct *handle,
2298 const struct smb_filename *fname)
2300 int result;
2302 result = SMB_VFS_NEXT_SET_OFFLINE(handle, fname);
2303 do_log(SMB_VFS_OP_SET_OFFLINE, result >= 0, handle, "%s",
2304 smb_fname_str_do_log(fname));
2305 return result;
2308 static struct vfs_fn_pointers vfs_full_audit_fns = {
2310 /* Disk operations */
2312 .connect_fn = smb_full_audit_connect,
2313 .disconnect_fn = smb_full_audit_disconnect,
2314 .disk_free_fn = smb_full_audit_disk_free,
2315 .get_quota_fn = smb_full_audit_get_quota,
2316 .set_quota_fn = smb_full_audit_set_quota,
2317 .get_shadow_copy_data_fn = smb_full_audit_get_shadow_copy_data,
2318 .statvfs_fn = smb_full_audit_statvfs,
2319 .fs_capabilities_fn = smb_full_audit_fs_capabilities,
2320 .opendir_fn = smb_full_audit_opendir,
2321 .fdopendir_fn = smb_full_audit_fdopendir,
2322 .readdir_fn = smb_full_audit_readdir,
2323 .seekdir_fn = smb_full_audit_seekdir,
2324 .telldir_fn = smb_full_audit_telldir,
2325 .rewind_dir_fn = smb_full_audit_rewinddir,
2326 .mkdir_fn = smb_full_audit_mkdir,
2327 .rmdir_fn = smb_full_audit_rmdir,
2328 .closedir_fn = smb_full_audit_closedir,
2329 .init_search_op_fn = smb_full_audit_init_search_op,
2330 .open_fn = smb_full_audit_open,
2331 .create_file_fn = smb_full_audit_create_file,
2332 .close_fn = smb_full_audit_close,
2333 .read_fn = smb_full_audit_read,
2334 .pread_fn = smb_full_audit_pread,
2335 .pread_send_fn = smb_full_audit_pread_send,
2336 .pread_recv_fn = smb_full_audit_pread_recv,
2337 .write_fn = smb_full_audit_write,
2338 .pwrite_fn = smb_full_audit_pwrite,
2339 .pwrite_send_fn = smb_full_audit_pwrite_send,
2340 .pwrite_recv_fn = smb_full_audit_pwrite_recv,
2341 .lseek_fn = smb_full_audit_lseek,
2342 .sendfile_fn = smb_full_audit_sendfile,
2343 .recvfile_fn = smb_full_audit_recvfile,
2344 .rename_fn = smb_full_audit_rename,
2345 .fsync_fn = smb_full_audit_fsync,
2346 .fsync_send_fn = smb_full_audit_fsync_send,
2347 .fsync_recv_fn = smb_full_audit_fsync_recv,
2348 .stat_fn = smb_full_audit_stat,
2349 .fstat_fn = smb_full_audit_fstat,
2350 .lstat_fn = smb_full_audit_lstat,
2351 .get_alloc_size_fn = smb_full_audit_get_alloc_size,
2352 .unlink_fn = smb_full_audit_unlink,
2353 .chmod_fn = smb_full_audit_chmod,
2354 .fchmod_fn = smb_full_audit_fchmod,
2355 .chown_fn = smb_full_audit_chown,
2356 .fchown_fn = smb_full_audit_fchown,
2357 .lchown_fn = smb_full_audit_lchown,
2358 .chdir_fn = smb_full_audit_chdir,
2359 .getwd_fn = smb_full_audit_getwd,
2360 .ntimes_fn = smb_full_audit_ntimes,
2361 .ftruncate_fn = smb_full_audit_ftruncate,
2362 .fallocate_fn = smb_full_audit_fallocate,
2363 .lock_fn = smb_full_audit_lock,
2364 .kernel_flock_fn = smb_full_audit_kernel_flock,
2365 .linux_setlease_fn = smb_full_audit_linux_setlease,
2366 .getlock_fn = smb_full_audit_getlock,
2367 .symlink_fn = smb_full_audit_symlink,
2368 .readlink_fn = smb_full_audit_readlink,
2369 .link_fn = smb_full_audit_link,
2370 .mknod_fn = smb_full_audit_mknod,
2371 .realpath_fn = smb_full_audit_realpath,
2372 .notify_watch_fn = smb_full_audit_notify_watch,
2373 .chflags_fn = smb_full_audit_chflags,
2374 .file_id_create_fn = smb_full_audit_file_id_create,
2375 .streaminfo_fn = smb_full_audit_streaminfo,
2376 .get_real_filename_fn = smb_full_audit_get_real_filename,
2377 .connectpath_fn = smb_full_audit_connectpath,
2378 .brl_lock_windows_fn = smb_full_audit_brl_lock_windows,
2379 .brl_unlock_windows_fn = smb_full_audit_brl_unlock_windows,
2380 .brl_cancel_windows_fn = smb_full_audit_brl_cancel_windows,
2381 .strict_lock_fn = smb_full_audit_strict_lock,
2382 .strict_unlock_fn = smb_full_audit_strict_unlock,
2383 .translate_name_fn = smb_full_audit_translate_name,
2384 .fget_nt_acl_fn = smb_full_audit_fget_nt_acl,
2385 .get_nt_acl_fn = smb_full_audit_get_nt_acl,
2386 .fset_nt_acl_fn = smb_full_audit_fset_nt_acl,
2387 .chmod_acl_fn = smb_full_audit_chmod_acl,
2388 .fchmod_acl_fn = smb_full_audit_fchmod_acl,
2389 .sys_acl_get_entry_fn = smb_full_audit_sys_acl_get_entry,
2390 .sys_acl_get_tag_type_fn = smb_full_audit_sys_acl_get_tag_type,
2391 .sys_acl_get_permset_fn = smb_full_audit_sys_acl_get_permset,
2392 .sys_acl_get_qualifier_fn = smb_full_audit_sys_acl_get_qualifier,
2393 .sys_acl_get_file_fn = smb_full_audit_sys_acl_get_file,
2394 .sys_acl_get_fd_fn = smb_full_audit_sys_acl_get_fd,
2395 .sys_acl_clear_perms_fn = smb_full_audit_sys_acl_clear_perms,
2396 .sys_acl_add_perm_fn = smb_full_audit_sys_acl_add_perm,
2397 .sys_acl_to_text_fn = smb_full_audit_sys_acl_to_text,
2398 .sys_acl_init_fn = smb_full_audit_sys_acl_init,
2399 .sys_acl_create_entry_fn = smb_full_audit_sys_acl_create_entry,
2400 .sys_acl_set_tag_type_fn = smb_full_audit_sys_acl_set_tag_type,
2401 .sys_acl_set_qualifier_fn = smb_full_audit_sys_acl_set_qualifier,
2402 .sys_acl_set_permset_fn = smb_full_audit_sys_acl_set_permset,
2403 .sys_acl_valid_fn = smb_full_audit_sys_acl_valid,
2404 .sys_acl_set_file_fn = smb_full_audit_sys_acl_set_file,
2405 .sys_acl_set_fd_fn = smb_full_audit_sys_acl_set_fd,
2406 .sys_acl_delete_def_file_fn = smb_full_audit_sys_acl_delete_def_file,
2407 .sys_acl_get_perm_fn = smb_full_audit_sys_acl_get_perm,
2408 .sys_acl_free_text_fn = smb_full_audit_sys_acl_free_text,
2409 .sys_acl_free_acl_fn = smb_full_audit_sys_acl_free_acl,
2410 .sys_acl_free_qualifier_fn = smb_full_audit_sys_acl_free_qualifier,
2411 .getxattr_fn = smb_full_audit_getxattr,
2412 .fgetxattr_fn = smb_full_audit_fgetxattr,
2413 .listxattr_fn = smb_full_audit_listxattr,
2414 .flistxattr_fn = smb_full_audit_flistxattr,
2415 .removexattr_fn = smb_full_audit_removexattr,
2416 .fremovexattr_fn = smb_full_audit_fremovexattr,
2417 .setxattr_fn = smb_full_audit_setxattr,
2418 .fsetxattr_fn = smb_full_audit_fsetxattr,
2419 .aio_force_fn = smb_full_audit_aio_force,
2420 .is_offline_fn = smb_full_audit_is_offline,
2421 .set_offline_fn = smb_full_audit_set_offline,
2424 NTSTATUS vfs_full_audit_init(void)
2426 NTSTATUS ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION,
2427 "full_audit", &vfs_full_audit_fns);
2429 if (!NT_STATUS_IS_OK(ret))
2430 return ret;
2432 vfs_full_audit_debug_level = debug_add_class("full_audit");
2433 if (vfs_full_audit_debug_level == -1) {
2434 vfs_full_audit_debug_level = DBGC_VFS;
2435 DEBUG(0, ("vfs_full_audit: Couldn't register custom debugging "
2436 "class!\n"));
2437 } else {
2438 DEBUG(10, ("vfs_full_audit: Debug class number of "
2439 "'full_audit': %d\n", vfs_full_audit_debug_level));
2442 return ret;