Transition to waf 1.8: replaced on_results by update_outputs
[Samba.git] / source3 / modules / vfs_full_audit.c
blob87a2f9c3bc4d173eebd4fbffb03f2d949efa2e6a
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"
70 #include "libcli/security/sddl.h"
71 #include "passdb/machine_sid.h"
73 static int vfs_full_audit_debug_level = DBGC_VFS;
75 struct vfs_full_audit_private_data {
76 struct bitmap *success_ops;
77 struct bitmap *failure_ops;
78 int syslog_facility;
79 int syslog_priority;
80 bool log_secdesc;
81 bool do_syslog;
84 #undef DBGC_CLASS
85 #define DBGC_CLASS vfs_full_audit_debug_level
87 typedef enum _vfs_op_type {
88 SMB_VFS_OP_NOOP = -1,
90 /* Disk operations */
92 SMB_VFS_OP_CONNECT = 0,
93 SMB_VFS_OP_DISCONNECT,
94 SMB_VFS_OP_DISK_FREE,
95 SMB_VFS_OP_GET_QUOTA,
96 SMB_VFS_OP_SET_QUOTA,
97 SMB_VFS_OP_GET_SHADOW_COPY_DATA,
98 SMB_VFS_OP_STATVFS,
99 SMB_VFS_OP_FS_CAPABILITIES,
101 /* Directory operations */
103 SMB_VFS_OP_OPENDIR,
104 SMB_VFS_OP_FDOPENDIR,
105 SMB_VFS_OP_READDIR,
106 SMB_VFS_OP_SEEKDIR,
107 SMB_VFS_OP_TELLDIR,
108 SMB_VFS_OP_REWINDDIR,
109 SMB_VFS_OP_MKDIR,
110 SMB_VFS_OP_RMDIR,
111 SMB_VFS_OP_CLOSEDIR,
112 SMB_VFS_OP_INIT_SEARCH_OP,
114 /* File operations */
116 SMB_VFS_OP_OPEN,
117 SMB_VFS_OP_CREATE_FILE,
118 SMB_VFS_OP_CLOSE,
119 SMB_VFS_OP_READ,
120 SMB_VFS_OP_PREAD,
121 SMB_VFS_OP_PREAD_SEND,
122 SMB_VFS_OP_PREAD_RECV,
123 SMB_VFS_OP_WRITE,
124 SMB_VFS_OP_PWRITE,
125 SMB_VFS_OP_PWRITE_SEND,
126 SMB_VFS_OP_PWRITE_RECV,
127 SMB_VFS_OP_LSEEK,
128 SMB_VFS_OP_SENDFILE,
129 SMB_VFS_OP_RECVFILE,
130 SMB_VFS_OP_RENAME,
131 SMB_VFS_OP_FSYNC,
132 SMB_VFS_OP_FSYNC_SEND,
133 SMB_VFS_OP_FSYNC_RECV,
134 SMB_VFS_OP_STAT,
135 SMB_VFS_OP_FSTAT,
136 SMB_VFS_OP_LSTAT,
137 SMB_VFS_OP_GET_ALLOC_SIZE,
138 SMB_VFS_OP_UNLINK,
139 SMB_VFS_OP_CHMOD,
140 SMB_VFS_OP_FCHMOD,
141 SMB_VFS_OP_CHOWN,
142 SMB_VFS_OP_FCHOWN,
143 SMB_VFS_OP_LCHOWN,
144 SMB_VFS_OP_CHDIR,
145 SMB_VFS_OP_GETWD,
146 SMB_VFS_OP_NTIMES,
147 SMB_VFS_OP_FTRUNCATE,
148 SMB_VFS_OP_FALLOCATE,
149 SMB_VFS_OP_LOCK,
150 SMB_VFS_OP_KERNEL_FLOCK,
151 SMB_VFS_OP_LINUX_SETLEASE,
152 SMB_VFS_OP_GETLOCK,
153 SMB_VFS_OP_SYMLINK,
154 SMB_VFS_OP_READLINK,
155 SMB_VFS_OP_LINK,
156 SMB_VFS_OP_MKNOD,
157 SMB_VFS_OP_REALPATH,
158 SMB_VFS_OP_NOTIFY_WATCH,
159 SMB_VFS_OP_CHFLAGS,
160 SMB_VFS_OP_FILE_ID_CREATE,
161 SMB_VFS_OP_STREAMINFO,
162 SMB_VFS_OP_GET_REAL_FILENAME,
163 SMB_VFS_OP_CONNECTPATH,
164 SMB_VFS_OP_BRL_LOCK_WINDOWS,
165 SMB_VFS_OP_BRL_UNLOCK_WINDOWS,
166 SMB_VFS_OP_BRL_CANCEL_WINDOWS,
167 SMB_VFS_OP_STRICT_LOCK,
168 SMB_VFS_OP_STRICT_UNLOCK,
169 SMB_VFS_OP_TRANSLATE_NAME,
170 SMB_VFS_OP_COPY_CHUNK_SEND,
171 SMB_VFS_OP_COPY_CHUNK_RECV,
172 SMB_VFS_OP_GET_COMPRESSION,
173 SMB_VFS_OP_SET_COMPRESSION,
174 SMB_VFS_OP_READDIR_ATTR,
176 /* NT ACL operations. */
178 SMB_VFS_OP_FGET_NT_ACL,
179 SMB_VFS_OP_GET_NT_ACL,
180 SMB_VFS_OP_FSET_NT_ACL,
182 /* POSIX ACL operations. */
184 SMB_VFS_OP_CHMOD_ACL,
185 SMB_VFS_OP_FCHMOD_ACL,
187 SMB_VFS_OP_SYS_ACL_GET_FILE,
188 SMB_VFS_OP_SYS_ACL_GET_FD,
189 SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE,
190 SMB_VFS_OP_SYS_ACL_BLOB_GET_FD,
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,
195 /* EA operations. */
196 SMB_VFS_OP_GETXATTR,
197 SMB_VFS_OP_FGETXATTR,
198 SMB_VFS_OP_LISTXATTR,
199 SMB_VFS_OP_FLISTXATTR,
200 SMB_VFS_OP_REMOVEXATTR,
201 SMB_VFS_OP_FREMOVEXATTR,
202 SMB_VFS_OP_SETXATTR,
203 SMB_VFS_OP_FSETXATTR,
205 /* aio operations */
206 SMB_VFS_OP_AIO_FORCE,
208 /* offline operations */
209 SMB_VFS_OP_IS_OFFLINE,
210 SMB_VFS_OP_SET_OFFLINE,
212 /* This should always be last enum value */
214 SMB_VFS_OP_LAST
215 } vfs_op_type;
217 /* The following array *must* be in the same order as defined in vfs_op_type */
219 static struct {
220 vfs_op_type type;
221 const char *name;
222 } vfs_op_names[] = {
223 { SMB_VFS_OP_CONNECT, "connect" },
224 { SMB_VFS_OP_DISCONNECT, "disconnect" },
225 { SMB_VFS_OP_DISK_FREE, "disk_free" },
226 { SMB_VFS_OP_GET_QUOTA, "get_quota" },
227 { SMB_VFS_OP_SET_QUOTA, "set_quota" },
228 { SMB_VFS_OP_GET_SHADOW_COPY_DATA, "get_shadow_copy_data" },
229 { SMB_VFS_OP_STATVFS, "statvfs" },
230 { SMB_VFS_OP_FS_CAPABILITIES, "fs_capabilities" },
231 { SMB_VFS_OP_OPENDIR, "opendir" },
232 { SMB_VFS_OP_FDOPENDIR, "fdopendir" },
233 { SMB_VFS_OP_READDIR, "readdir" },
234 { SMB_VFS_OP_SEEKDIR, "seekdir" },
235 { SMB_VFS_OP_TELLDIR, "telldir" },
236 { SMB_VFS_OP_REWINDDIR, "rewinddir" },
237 { SMB_VFS_OP_MKDIR, "mkdir" },
238 { SMB_VFS_OP_RMDIR, "rmdir" },
239 { SMB_VFS_OP_CLOSEDIR, "closedir" },
240 { SMB_VFS_OP_INIT_SEARCH_OP, "init_search_op" },
241 { SMB_VFS_OP_OPEN, "open" },
242 { SMB_VFS_OP_CREATE_FILE, "create_file" },
243 { SMB_VFS_OP_CLOSE, "close" },
244 { SMB_VFS_OP_READ, "read" },
245 { SMB_VFS_OP_PREAD, "pread" },
246 { SMB_VFS_OP_PREAD_SEND, "pread_send" },
247 { SMB_VFS_OP_PREAD_RECV, "pread_recv" },
248 { SMB_VFS_OP_WRITE, "write" },
249 { SMB_VFS_OP_PWRITE, "pwrite" },
250 { SMB_VFS_OP_PWRITE_SEND, "pwrite_send" },
251 { SMB_VFS_OP_PWRITE_RECV, "pwrite_recv" },
252 { SMB_VFS_OP_LSEEK, "lseek" },
253 { SMB_VFS_OP_SENDFILE, "sendfile" },
254 { SMB_VFS_OP_RECVFILE, "recvfile" },
255 { SMB_VFS_OP_RENAME, "rename" },
256 { SMB_VFS_OP_FSYNC, "fsync" },
257 { SMB_VFS_OP_FSYNC_SEND, "fsync_send" },
258 { SMB_VFS_OP_FSYNC_RECV, "fsync_recv" },
259 { SMB_VFS_OP_STAT, "stat" },
260 { SMB_VFS_OP_FSTAT, "fstat" },
261 { SMB_VFS_OP_LSTAT, "lstat" },
262 { SMB_VFS_OP_GET_ALLOC_SIZE, "get_alloc_size" },
263 { SMB_VFS_OP_UNLINK, "unlink" },
264 { SMB_VFS_OP_CHMOD, "chmod" },
265 { SMB_VFS_OP_FCHMOD, "fchmod" },
266 { SMB_VFS_OP_CHOWN, "chown" },
267 { SMB_VFS_OP_FCHOWN, "fchown" },
268 { SMB_VFS_OP_LCHOWN, "lchown" },
269 { SMB_VFS_OP_CHDIR, "chdir" },
270 { SMB_VFS_OP_GETWD, "getwd" },
271 { SMB_VFS_OP_NTIMES, "ntimes" },
272 { SMB_VFS_OP_FTRUNCATE, "ftruncate" },
273 { SMB_VFS_OP_FALLOCATE,"fallocate" },
274 { SMB_VFS_OP_LOCK, "lock" },
275 { SMB_VFS_OP_KERNEL_FLOCK, "kernel_flock" },
276 { SMB_VFS_OP_LINUX_SETLEASE, "linux_setlease" },
277 { SMB_VFS_OP_GETLOCK, "getlock" },
278 { SMB_VFS_OP_SYMLINK, "symlink" },
279 { SMB_VFS_OP_READLINK, "readlink" },
280 { SMB_VFS_OP_LINK, "link" },
281 { SMB_VFS_OP_MKNOD, "mknod" },
282 { SMB_VFS_OP_REALPATH, "realpath" },
283 { SMB_VFS_OP_NOTIFY_WATCH, "notify_watch" },
284 { SMB_VFS_OP_CHFLAGS, "chflags" },
285 { SMB_VFS_OP_FILE_ID_CREATE, "file_id_create" },
286 { SMB_VFS_OP_STREAMINFO, "streaminfo" },
287 { SMB_VFS_OP_GET_REAL_FILENAME, "get_real_filename" },
288 { SMB_VFS_OP_CONNECTPATH, "connectpath" },
289 { SMB_VFS_OP_BRL_LOCK_WINDOWS, "brl_lock_windows" },
290 { SMB_VFS_OP_BRL_UNLOCK_WINDOWS, "brl_unlock_windows" },
291 { SMB_VFS_OP_BRL_CANCEL_WINDOWS, "brl_cancel_windows" },
292 { SMB_VFS_OP_STRICT_LOCK, "strict_lock" },
293 { SMB_VFS_OP_STRICT_UNLOCK, "strict_unlock" },
294 { SMB_VFS_OP_TRANSLATE_NAME, "translate_name" },
295 { SMB_VFS_OP_COPY_CHUNK_SEND, "copy_chunk_send" },
296 { SMB_VFS_OP_COPY_CHUNK_RECV, "copy_chunk_recv" },
297 { SMB_VFS_OP_GET_COMPRESSION, "get_compression" },
298 { SMB_VFS_OP_SET_COMPRESSION, "set_compression" },
299 { SMB_VFS_OP_READDIR_ATTR, "readdir_attr" },
300 { SMB_VFS_OP_FGET_NT_ACL, "fget_nt_acl" },
301 { SMB_VFS_OP_GET_NT_ACL, "get_nt_acl" },
302 { SMB_VFS_OP_FSET_NT_ACL, "fset_nt_acl" },
303 { SMB_VFS_OP_CHMOD_ACL, "chmod_acl" },
304 { SMB_VFS_OP_FCHMOD_ACL, "fchmod_acl" },
305 { SMB_VFS_OP_SYS_ACL_GET_FILE, "sys_acl_get_file" },
306 { SMB_VFS_OP_SYS_ACL_GET_FD, "sys_acl_get_fd" },
307 { SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE, "sys_acl_blob_get_file" },
308 { SMB_VFS_OP_SYS_ACL_BLOB_GET_FD, "sys_acl_blob_get_fd" },
309 { SMB_VFS_OP_SYS_ACL_SET_FILE, "sys_acl_set_file" },
310 { SMB_VFS_OP_SYS_ACL_SET_FD, "sys_acl_set_fd" },
311 { SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE, "sys_acl_delete_def_file" },
312 { SMB_VFS_OP_GETXATTR, "getxattr" },
313 { SMB_VFS_OP_FGETXATTR, "fgetxattr" },
314 { SMB_VFS_OP_LISTXATTR, "listxattr" },
315 { SMB_VFS_OP_FLISTXATTR, "flistxattr" },
316 { SMB_VFS_OP_REMOVEXATTR, "removexattr" },
317 { SMB_VFS_OP_FREMOVEXATTR, "fremovexattr" },
318 { SMB_VFS_OP_SETXATTR, "setxattr" },
319 { SMB_VFS_OP_FSETXATTR, "fsetxattr" },
320 { SMB_VFS_OP_AIO_FORCE, "aio_force" },
321 { SMB_VFS_OP_IS_OFFLINE, "is_offline" },
322 { SMB_VFS_OP_SET_OFFLINE, "set_offline" },
323 { SMB_VFS_OP_LAST, NULL }
326 static int audit_syslog_facility(vfs_handle_struct *handle)
328 static const struct enum_list enum_log_facilities[] = {
329 { LOG_USER, "USER" },
330 { LOG_LOCAL0, "LOCAL0" },
331 { LOG_LOCAL1, "LOCAL1" },
332 { LOG_LOCAL2, "LOCAL2" },
333 { LOG_LOCAL3, "LOCAL3" },
334 { LOG_LOCAL4, "LOCAL4" },
335 { LOG_LOCAL5, "LOCAL5" },
336 { LOG_LOCAL6, "LOCAL6" },
337 { LOG_LOCAL7, "LOCAL7" },
338 { -1, NULL}
341 int facility;
343 facility = lp_parm_enum(SNUM(handle->conn), "full_audit", "facility", enum_log_facilities, LOG_USER);
345 return facility;
348 static int audit_syslog_priority(vfs_handle_struct *handle)
350 static const struct enum_list enum_log_priorities[] = {
351 { LOG_EMERG, "EMERG" },
352 { LOG_ALERT, "ALERT" },
353 { LOG_CRIT, "CRIT" },
354 { LOG_ERR, "ERR" },
355 { LOG_WARNING, "WARNING" },
356 { LOG_NOTICE, "NOTICE" },
357 { LOG_INFO, "INFO" },
358 { LOG_DEBUG, "DEBUG" },
359 { -1, NULL}
362 int priority;
364 priority = lp_parm_enum(SNUM(handle->conn), "full_audit", "priority",
365 enum_log_priorities, LOG_NOTICE);
366 if (priority == -1) {
367 priority = LOG_WARNING;
370 return priority;
373 static char *audit_prefix(TALLOC_CTX *ctx, connection_struct *conn)
375 char *prefix = NULL;
376 char *result;
378 prefix = talloc_strdup(ctx,
379 lp_parm_const_string(SNUM(conn), "full_audit",
380 "prefix", "%u|%I"));
381 if (!prefix) {
382 return NULL;
384 result = talloc_sub_advanced(ctx,
385 lp_servicename(talloc_tos(), SNUM(conn)),
386 conn->session_info->unix_info->unix_name,
387 conn->connectpath,
388 conn->session_info->unix_token->gid,
389 conn->session_info->unix_info->sanitized_username,
390 conn->session_info->info->domain_name,
391 prefix);
392 TALLOC_FREE(prefix);
393 return result;
396 static bool log_success(struct vfs_full_audit_private_data *pd, vfs_op_type op)
398 if (pd->success_ops == NULL) {
399 return True;
402 return bitmap_query(pd->success_ops, op);
405 static bool log_failure(struct vfs_full_audit_private_data *pd, vfs_op_type op)
407 if (pd->failure_ops == NULL)
408 return True;
410 return bitmap_query(pd->failure_ops, op);
413 static struct bitmap *init_bitmap(TALLOC_CTX *mem_ctx, const char **ops)
415 struct bitmap *bm;
417 if (ops == NULL) {
418 return NULL;
421 bm = bitmap_talloc(mem_ctx, SMB_VFS_OP_LAST);
422 if (bm == NULL) {
423 DEBUG(0, ("Could not alloc bitmap -- "
424 "defaulting to logging everything\n"));
425 return NULL;
428 for (; *ops != NULL; ops += 1) {
429 int i;
430 bool neg = false;
431 const char *op;
433 if (strequal(*ops, "all")) {
434 for (i=0; i<SMB_VFS_OP_LAST; i++) {
435 bitmap_set(bm, i);
437 continue;
440 if (strequal(*ops, "none")) {
441 break;
444 op = ops[0];
445 if (op[0] == '!') {
446 neg = true;
447 op += 1;
450 for (i=0; i<SMB_VFS_OP_LAST; i++) {
451 if ((vfs_op_names[i].name == NULL)
452 || (vfs_op_names[i].type != i)) {
453 smb_panic("vfs_full_audit.c: name table not "
454 "in sync with vfs_op_type enums\n");
456 if (strequal(op, vfs_op_names[i].name)) {
457 if (neg) {
458 bitmap_clear(bm, i);
459 } else {
460 bitmap_set(bm, i);
462 break;
465 if (i == SMB_VFS_OP_LAST) {
466 DEBUG(0, ("Could not find opname %s, logging all\n",
467 *ops));
468 TALLOC_FREE(bm);
469 return NULL;
472 return bm;
475 static const char *audit_opname(vfs_op_type op)
477 if (op >= SMB_VFS_OP_LAST)
478 return "INVALID VFS OP";
479 return vfs_op_names[op].name;
482 static TALLOC_CTX *tmp_do_log_ctx;
484 * Get us a temporary talloc context usable just for DEBUG arguments
486 static TALLOC_CTX *do_log_ctx(void)
488 if (tmp_do_log_ctx == NULL) {
489 tmp_do_log_ctx = talloc_named_const(NULL, 0, "do_log_ctx");
491 return tmp_do_log_ctx;
494 static void do_log(vfs_op_type op, bool success, vfs_handle_struct *handle,
495 const char *format, ...)
497 struct vfs_full_audit_private_data *pd;
498 fstring err_msg;
499 char *audit_pre = NULL;
500 va_list ap;
501 char *op_msg = NULL;
503 SMB_VFS_HANDLE_GET_DATA(handle, pd,
504 struct vfs_full_audit_private_data,
505 return;);
507 if (success && (!log_success(pd, op)))
508 goto out;
510 if (!success && (!log_failure(pd, op)))
511 goto out;
513 if (success)
514 fstrcpy(err_msg, "ok");
515 else
516 fstr_sprintf(err_msg, "fail (%s)", strerror(errno));
518 va_start(ap, format);
519 op_msg = talloc_vasprintf(talloc_tos(), format, ap);
520 va_end(ap);
522 if (!op_msg) {
523 goto out;
526 audit_pre = audit_prefix(talloc_tos(), handle->conn);
528 if (pd->do_syslog) {
529 int priority;
532 * Specify the facility to interoperate with other syslog
533 * callers (smbd for example).
535 priority = pd->syslog_priority | pd->syslog_facility;
537 syslog(priority, "%s|%s|%s|%s\n",
538 audit_pre ? audit_pre : "",
539 audit_opname(op), err_msg, op_msg);
540 } else {
541 DEBUG(1, ("%s|%s|%s|%s\n",
542 audit_pre ? audit_pre : "",
543 audit_opname(op), err_msg, op_msg));
545 out:
546 TALLOC_FREE(audit_pre);
547 TALLOC_FREE(op_msg);
548 TALLOC_FREE(tmp_do_log_ctx);
552 * Return a string using the do_log_ctx()
554 static const char *smb_fname_str_do_log(const struct smb_filename *smb_fname)
556 char *fname = NULL;
557 NTSTATUS status;
559 if (smb_fname == NULL) {
560 return "";
562 status = get_full_smb_filename(do_log_ctx(), smb_fname, &fname);
563 if (!NT_STATUS_IS_OK(status)) {
564 return "";
566 return fname;
570 * Return an fsp debug string using the do_log_ctx()
572 static const char *fsp_str_do_log(const struct files_struct *fsp)
574 return smb_fname_str_do_log(fsp->fsp_name);
577 /* Implementation of vfs_ops. Pass everything on to the default
578 operation but log event first. */
580 static int smb_full_audit_connect(vfs_handle_struct *handle,
581 const char *svc, const char *user)
583 int result;
584 struct vfs_full_audit_private_data *pd = NULL;
586 result = SMB_VFS_NEXT_CONNECT(handle, svc, user);
587 if (result < 0) {
588 return result;
591 pd = talloc_zero(handle, struct vfs_full_audit_private_data);
592 if (!pd) {
593 SMB_VFS_NEXT_DISCONNECT(handle);
594 return -1;
597 pd->syslog_facility = audit_syslog_facility(handle);
598 if (pd->syslog_facility == -1) {
599 DEBUG(1, ("%s: Unknown facility %s\n", __func__,
600 lp_parm_const_string(SNUM(handle->conn),
601 "full_audit", "facility",
602 "USER")));
603 SMB_VFS_NEXT_DISCONNECT(handle);
604 return -1;
607 pd->syslog_priority = audit_syslog_priority(handle);
609 pd->log_secdesc = lp_parm_bool(SNUM(handle->conn),
610 "full_audit", "log_secdesc", false);
612 pd->do_syslog = lp_parm_bool(SNUM(handle->conn),
613 "full_audit", "syslog", true);
615 #ifdef WITH_SYSLOG
616 if (pd->do_syslog) {
617 openlog("smbd_audit", 0, pd->syslog_facility);
619 #endif
621 pd->success_ops = init_bitmap(
622 pd, lp_parm_string_list(SNUM(handle->conn), "full_audit",
623 "success", NULL));
624 pd->failure_ops = init_bitmap(
625 pd, lp_parm_string_list(SNUM(handle->conn), "full_audit",
626 "failure", NULL));
628 /* Store the private data. */
629 SMB_VFS_HANDLE_SET_DATA(handle, pd, NULL,
630 struct vfs_full_audit_private_data, return -1);
632 do_log(SMB_VFS_OP_CONNECT, True, handle,
633 "%s", svc);
635 return 0;
638 static void smb_full_audit_disconnect(vfs_handle_struct *handle)
640 SMB_VFS_NEXT_DISCONNECT(handle);
642 do_log(SMB_VFS_OP_DISCONNECT, True, handle,
643 "%s", lp_servicename(talloc_tos(), SNUM(handle->conn)));
645 /* The bitmaps will be disconnected when the private
646 data is deleted. */
649 static uint64_t smb_full_audit_disk_free(vfs_handle_struct *handle,
650 const char *path, uint64_t *bsize,
651 uint64_t *dfree, uint64_t *dsize)
653 uint64_t result;
655 result = SMB_VFS_NEXT_DISK_FREE(handle, path, bsize, dfree, dsize);
657 /* Don't have a reasonable notion of failure here */
659 do_log(SMB_VFS_OP_DISK_FREE, True, handle, "%s", path);
661 return result;
664 static int smb_full_audit_get_quota(struct vfs_handle_struct *handle,
665 enum SMB_QUOTA_TYPE qtype, unid_t id,
666 SMB_DISK_QUOTA *qt)
668 int result;
670 result = SMB_VFS_NEXT_GET_QUOTA(handle, qtype, id, qt);
672 do_log(SMB_VFS_OP_GET_QUOTA, (result >= 0), handle, "");
674 return result;
678 static int smb_full_audit_set_quota(struct vfs_handle_struct *handle,
679 enum SMB_QUOTA_TYPE qtype, unid_t id,
680 SMB_DISK_QUOTA *qt)
682 int result;
684 result = SMB_VFS_NEXT_SET_QUOTA(handle, qtype, id, qt);
686 do_log(SMB_VFS_OP_SET_QUOTA, (result >= 0), handle, "");
688 return result;
691 static int smb_full_audit_get_shadow_copy_data(struct vfs_handle_struct *handle,
692 struct files_struct *fsp,
693 struct shadow_copy_data *shadow_copy_data,
694 bool labels)
696 int result;
698 result = SMB_VFS_NEXT_GET_SHADOW_COPY_DATA(handle, fsp, shadow_copy_data, labels);
700 do_log(SMB_VFS_OP_GET_SHADOW_COPY_DATA, (result >= 0), handle, "");
702 return result;
705 static int smb_full_audit_statvfs(struct vfs_handle_struct *handle,
706 const char *path,
707 struct vfs_statvfs_struct *statbuf)
709 int result;
711 result = SMB_VFS_NEXT_STATVFS(handle, path, statbuf);
713 do_log(SMB_VFS_OP_STATVFS, (result >= 0), handle, "");
715 return result;
718 static uint32_t smb_full_audit_fs_capabilities(struct vfs_handle_struct *handle, enum timestamp_set_resolution *p_ts_res)
720 int result;
722 result = SMB_VFS_NEXT_FS_CAPABILITIES(handle, p_ts_res);
724 do_log(SMB_VFS_OP_FS_CAPABILITIES, true, handle, "");
726 return result;
729 static DIR *smb_full_audit_opendir(vfs_handle_struct *handle,
730 const char *fname, const char *mask, uint32 attr)
732 DIR *result;
734 result = SMB_VFS_NEXT_OPENDIR(handle, fname, mask, attr);
736 do_log(SMB_VFS_OP_OPENDIR, (result != NULL), handle, "%s", fname);
738 return result;
741 static DIR *smb_full_audit_fdopendir(vfs_handle_struct *handle,
742 files_struct *fsp, const char *mask, uint32 attr)
744 DIR *result;
746 result = SMB_VFS_NEXT_FDOPENDIR(handle, fsp, mask, attr);
748 do_log(SMB_VFS_OP_FDOPENDIR, (result != NULL), handle, "%s",
749 fsp_str_do_log(fsp));
751 return result;
754 static struct dirent *smb_full_audit_readdir(vfs_handle_struct *handle,
755 DIR *dirp, SMB_STRUCT_STAT *sbuf)
757 struct dirent *result;
759 result = SMB_VFS_NEXT_READDIR(handle, dirp, sbuf);
761 /* This operation has no reasonable error condition
762 * (End of dir is also failure), so always succeed.
764 do_log(SMB_VFS_OP_READDIR, True, handle, "");
766 return result;
769 static void smb_full_audit_seekdir(vfs_handle_struct *handle,
770 DIR *dirp, long offset)
772 SMB_VFS_NEXT_SEEKDIR(handle, dirp, offset);
774 do_log(SMB_VFS_OP_SEEKDIR, True, handle, "");
777 static long smb_full_audit_telldir(vfs_handle_struct *handle,
778 DIR *dirp)
780 long result;
782 result = SMB_VFS_NEXT_TELLDIR(handle, dirp);
784 do_log(SMB_VFS_OP_TELLDIR, True, handle, "");
786 return result;
789 static void smb_full_audit_rewinddir(vfs_handle_struct *handle,
790 DIR *dirp)
792 SMB_VFS_NEXT_REWINDDIR(handle, dirp);
794 do_log(SMB_VFS_OP_REWINDDIR, True, handle, "");
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, "");
841 static int smb_full_audit_open(vfs_handle_struct *handle,
842 struct smb_filename *smb_fname,
843 files_struct *fsp, int flags, mode_t mode)
845 int result;
847 result = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
849 do_log(SMB_VFS_OP_OPEN, (result >= 0), handle, "%s|%s",
850 ((flags & O_WRONLY) || (flags & O_RDWR))?"w":"r",
851 smb_fname_str_do_log(smb_fname));
853 return result;
856 static NTSTATUS smb_full_audit_create_file(vfs_handle_struct *handle,
857 struct smb_request *req,
858 uint16_t root_dir_fid,
859 struct smb_filename *smb_fname,
860 uint32_t access_mask,
861 uint32_t share_access,
862 uint32_t create_disposition,
863 uint32_t create_options,
864 uint32_t file_attributes,
865 uint32_t oplock_request,
866 struct smb2_lease *lease,
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,
873 const struct smb2_create_blobs *in_context_blobs,
874 struct smb2_create_blobs *out_context_blobs)
876 NTSTATUS result;
877 const char* str_create_disposition;
879 switch (create_disposition) {
880 case FILE_SUPERSEDE:
881 str_create_disposition = "supersede";
882 break;
883 case FILE_OVERWRITE_IF:
884 str_create_disposition = "overwrite_if";
885 break;
886 case FILE_OPEN:
887 str_create_disposition = "open";
888 break;
889 case FILE_OVERWRITE:
890 str_create_disposition = "overwrite";
891 break;
892 case FILE_CREATE:
893 str_create_disposition = "create";
894 break;
895 case FILE_OPEN_IF:
896 str_create_disposition = "open_if";
897 break;
898 default:
899 str_create_disposition = "unknown";
902 result = SMB_VFS_NEXT_CREATE_FILE(
903 handle, /* handle */
904 req, /* req */
905 root_dir_fid, /* root_dir_fid */
906 smb_fname, /* fname */
907 access_mask, /* access_mask */
908 share_access, /* share_access */
909 create_disposition, /* create_disposition*/
910 create_options, /* create_options */
911 file_attributes, /* file_attributes */
912 oplock_request, /* oplock_request */
913 lease, /* lease */
914 allocation_size, /* allocation_size */
915 private_flags,
916 sd, /* sd */
917 ea_list, /* ea_list */
918 result_fsp, /* result */
919 pinfo, /* pinfo */
920 in_context_blobs, out_context_blobs); /* create context */
922 do_log(SMB_VFS_OP_CREATE_FILE, (NT_STATUS_IS_OK(result)), handle,
923 "0x%x|%s|%s|%s", access_mask,
924 create_options & FILE_DIRECTORY_FILE ? "dir" : "file",
925 str_create_disposition, smb_fname_str_do_log(smb_fname));
927 return result;
930 static int smb_full_audit_close(vfs_handle_struct *handle, files_struct *fsp)
932 int result;
934 result = SMB_VFS_NEXT_CLOSE(handle, fsp);
936 do_log(SMB_VFS_OP_CLOSE, (result >= 0), handle, "%s",
937 fsp_str_do_log(fsp));
939 return result;
942 static ssize_t smb_full_audit_read(vfs_handle_struct *handle, files_struct *fsp,
943 void *data, size_t n)
945 ssize_t result;
947 result = SMB_VFS_NEXT_READ(handle, fsp, data, n);
949 do_log(SMB_VFS_OP_READ, (result >= 0), handle, "%s",
950 fsp_str_do_log(fsp));
952 return result;
955 static ssize_t smb_full_audit_pread(vfs_handle_struct *handle, files_struct *fsp,
956 void *data, size_t n, off_t offset)
958 ssize_t result;
960 result = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
962 do_log(SMB_VFS_OP_PREAD, (result >= 0), handle, "%s",
963 fsp_str_do_log(fsp));
965 return result;
968 struct smb_full_audit_pread_state {
969 vfs_handle_struct *handle;
970 files_struct *fsp;
971 ssize_t ret;
972 int err;
975 static void smb_full_audit_pread_done(struct tevent_req *subreq);
977 static struct tevent_req *smb_full_audit_pread_send(
978 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
979 struct tevent_context *ev, struct files_struct *fsp,
980 void *data, size_t n, off_t offset)
982 struct tevent_req *req, *subreq;
983 struct smb_full_audit_pread_state *state;
985 req = tevent_req_create(mem_ctx, &state,
986 struct smb_full_audit_pread_state);
987 if (req == NULL) {
988 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
989 fsp_str_do_log(fsp));
990 return NULL;
992 state->handle = handle;
993 state->fsp = fsp;
995 subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
996 n, offset);
997 if (tevent_req_nomem(subreq, req)) {
998 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
999 fsp_str_do_log(fsp));
1000 return tevent_req_post(req, ev);
1002 tevent_req_set_callback(subreq, smb_full_audit_pread_done, req);
1004 do_log(SMB_VFS_OP_PREAD_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1005 return req;
1008 static void smb_full_audit_pread_done(struct tevent_req *subreq)
1010 struct tevent_req *req = tevent_req_callback_data(
1011 subreq, struct tevent_req);
1012 struct smb_full_audit_pread_state *state = tevent_req_data(
1013 req, struct smb_full_audit_pread_state);
1015 state->ret = SMB_VFS_PREAD_RECV(subreq, &state->err);
1016 TALLOC_FREE(subreq);
1017 tevent_req_done(req);
1020 static ssize_t smb_full_audit_pread_recv(struct tevent_req *req, int *err)
1022 struct smb_full_audit_pread_state *state = tevent_req_data(
1023 req, struct smb_full_audit_pread_state);
1025 if (tevent_req_is_unix_error(req, err)) {
1026 do_log(SMB_VFS_OP_PREAD_RECV, false, state->handle, "%s",
1027 fsp_str_do_log(state->fsp));
1028 return -1;
1031 do_log(SMB_VFS_OP_PREAD_RECV, (state->ret >= 0), state->handle, "%s",
1032 fsp_str_do_log(state->fsp));
1034 *err = state->err;
1035 return state->ret;
1038 static ssize_t smb_full_audit_write(vfs_handle_struct *handle, files_struct *fsp,
1039 const void *data, size_t n)
1041 ssize_t result;
1043 result = SMB_VFS_NEXT_WRITE(handle, fsp, data, n);
1045 do_log(SMB_VFS_OP_WRITE, (result >= 0), handle, "%s",
1046 fsp_str_do_log(fsp));
1048 return result;
1051 static ssize_t smb_full_audit_pwrite(vfs_handle_struct *handle, files_struct *fsp,
1052 const void *data, size_t n,
1053 off_t offset)
1055 ssize_t result;
1057 result = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
1059 do_log(SMB_VFS_OP_PWRITE, (result >= 0), handle, "%s",
1060 fsp_str_do_log(fsp));
1062 return result;
1065 struct smb_full_audit_pwrite_state {
1066 vfs_handle_struct *handle;
1067 files_struct *fsp;
1068 ssize_t ret;
1069 int err;
1072 static void smb_full_audit_pwrite_done(struct tevent_req *subreq);
1074 static struct tevent_req *smb_full_audit_pwrite_send(
1075 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1076 struct tevent_context *ev, struct files_struct *fsp,
1077 const void *data, size_t n, off_t offset)
1079 struct tevent_req *req, *subreq;
1080 struct smb_full_audit_pwrite_state *state;
1082 req = tevent_req_create(mem_ctx, &state,
1083 struct smb_full_audit_pwrite_state);
1084 if (req == NULL) {
1085 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1086 fsp_str_do_log(fsp));
1087 return NULL;
1089 state->handle = handle;
1090 state->fsp = fsp;
1092 subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
1093 n, offset);
1094 if (tevent_req_nomem(subreq, req)) {
1095 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1096 fsp_str_do_log(fsp));
1097 return tevent_req_post(req, ev);
1099 tevent_req_set_callback(subreq, smb_full_audit_pwrite_done, req);
1101 do_log(SMB_VFS_OP_PWRITE_SEND, true, handle, "%s",
1102 fsp_str_do_log(fsp));
1103 return req;
1106 static void smb_full_audit_pwrite_done(struct tevent_req *subreq)
1108 struct tevent_req *req = tevent_req_callback_data(
1109 subreq, struct tevent_req);
1110 struct smb_full_audit_pwrite_state *state = tevent_req_data(
1111 req, struct smb_full_audit_pwrite_state);
1113 state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->err);
1114 TALLOC_FREE(subreq);
1115 tevent_req_done(req);
1118 static ssize_t smb_full_audit_pwrite_recv(struct tevent_req *req, int *err)
1120 struct smb_full_audit_pwrite_state *state = tevent_req_data(
1121 req, struct smb_full_audit_pwrite_state);
1123 if (tevent_req_is_unix_error(req, err)) {
1124 do_log(SMB_VFS_OP_PWRITE_RECV, false, state->handle, "%s",
1125 fsp_str_do_log(state->fsp));
1126 return -1;
1129 do_log(SMB_VFS_OP_PWRITE_RECV, (state->ret >= 0), state->handle, "%s",
1130 fsp_str_do_log(state->fsp));
1132 *err = state->err;
1133 return state->ret;
1136 static off_t smb_full_audit_lseek(vfs_handle_struct *handle, files_struct *fsp,
1137 off_t offset, int whence)
1139 ssize_t result;
1141 result = SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence);
1143 do_log(SMB_VFS_OP_LSEEK, (result != (ssize_t)-1), handle,
1144 "%s", fsp_str_do_log(fsp));
1146 return result;
1149 static ssize_t smb_full_audit_sendfile(vfs_handle_struct *handle, int tofd,
1150 files_struct *fromfsp,
1151 const DATA_BLOB *hdr, off_t offset,
1152 size_t n)
1154 ssize_t result;
1156 result = SMB_VFS_NEXT_SENDFILE(handle, tofd, fromfsp, hdr, offset, n);
1158 do_log(SMB_VFS_OP_SENDFILE, (result >= 0), handle,
1159 "%s", fsp_str_do_log(fromfsp));
1161 return result;
1164 static ssize_t smb_full_audit_recvfile(vfs_handle_struct *handle, int fromfd,
1165 files_struct *tofsp,
1166 off_t offset,
1167 size_t n)
1169 ssize_t result;
1171 result = SMB_VFS_NEXT_RECVFILE(handle, fromfd, tofsp, offset, n);
1173 do_log(SMB_VFS_OP_RECVFILE, (result >= 0), handle,
1174 "%s", fsp_str_do_log(tofsp));
1176 return result;
1179 static int smb_full_audit_rename(vfs_handle_struct *handle,
1180 const struct smb_filename *smb_fname_src,
1181 const struct smb_filename *smb_fname_dst)
1183 int result;
1185 result = SMB_VFS_NEXT_RENAME(handle, smb_fname_src, smb_fname_dst);
1187 do_log(SMB_VFS_OP_RENAME, (result >= 0), handle, "%s|%s",
1188 smb_fname_str_do_log(smb_fname_src),
1189 smb_fname_str_do_log(smb_fname_dst));
1191 return result;
1194 static int smb_full_audit_fsync(vfs_handle_struct *handle, files_struct *fsp)
1196 int result;
1198 result = SMB_VFS_NEXT_FSYNC(handle, fsp);
1200 do_log(SMB_VFS_OP_FSYNC, (result >= 0), handle, "%s",
1201 fsp_str_do_log(fsp));
1203 return result;
1206 struct smb_full_audit_fsync_state {
1207 vfs_handle_struct *handle;
1208 files_struct *fsp;
1209 int ret;
1210 int err;
1213 static void smb_full_audit_fsync_done(struct tevent_req *subreq);
1215 static struct tevent_req *smb_full_audit_fsync_send(
1216 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1217 struct tevent_context *ev, struct files_struct *fsp)
1219 struct tevent_req *req, *subreq;
1220 struct smb_full_audit_fsync_state *state;
1222 req = tevent_req_create(mem_ctx, &state,
1223 struct smb_full_audit_fsync_state);
1224 if (req == NULL) {
1225 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1226 fsp_str_do_log(fsp));
1227 return NULL;
1229 state->handle = handle;
1230 state->fsp = fsp;
1232 subreq = SMB_VFS_NEXT_FSYNC_SEND(state, ev, handle, fsp);
1233 if (tevent_req_nomem(subreq, req)) {
1234 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1235 fsp_str_do_log(fsp));
1236 return tevent_req_post(req, ev);
1238 tevent_req_set_callback(subreq, smb_full_audit_fsync_done, req);
1240 do_log(SMB_VFS_OP_FSYNC_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1241 return req;
1244 static void smb_full_audit_fsync_done(struct tevent_req *subreq)
1246 struct tevent_req *req = tevent_req_callback_data(
1247 subreq, struct tevent_req);
1248 struct smb_full_audit_fsync_state *state = tevent_req_data(
1249 req, struct smb_full_audit_fsync_state);
1251 state->ret = SMB_VFS_FSYNC_RECV(subreq, &state->err);
1252 TALLOC_FREE(subreq);
1253 tevent_req_done(req);
1256 static int smb_full_audit_fsync_recv(struct tevent_req *req, int *err)
1258 struct smb_full_audit_fsync_state *state = tevent_req_data(
1259 req, struct smb_full_audit_fsync_state);
1261 if (tevent_req_is_unix_error(req, err)) {
1262 do_log(SMB_VFS_OP_FSYNC_RECV, false, state->handle, "%s",
1263 fsp_str_do_log(state->fsp));
1264 return -1;
1267 do_log(SMB_VFS_OP_FSYNC_RECV, (state->ret >= 0), state->handle, "%s",
1268 fsp_str_do_log(state->fsp));
1270 *err = state->err;
1271 return state->ret;
1274 static int smb_full_audit_stat(vfs_handle_struct *handle,
1275 struct smb_filename *smb_fname)
1277 int result;
1279 result = SMB_VFS_NEXT_STAT(handle, smb_fname);
1281 do_log(SMB_VFS_OP_STAT, (result >= 0), handle, "%s",
1282 smb_fname_str_do_log(smb_fname));
1284 return result;
1287 static int smb_full_audit_fstat(vfs_handle_struct *handle, files_struct *fsp,
1288 SMB_STRUCT_STAT *sbuf)
1290 int result;
1292 result = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1294 do_log(SMB_VFS_OP_FSTAT, (result >= 0), handle, "%s",
1295 fsp_str_do_log(fsp));
1297 return result;
1300 static int smb_full_audit_lstat(vfs_handle_struct *handle,
1301 struct smb_filename *smb_fname)
1303 int result;
1305 result = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
1307 do_log(SMB_VFS_OP_LSTAT, (result >= 0), handle, "%s",
1308 smb_fname_str_do_log(smb_fname));
1310 return result;
1313 static uint64_t smb_full_audit_get_alloc_size(vfs_handle_struct *handle,
1314 files_struct *fsp, const SMB_STRUCT_STAT *sbuf)
1316 uint64_t result;
1318 result = SMB_VFS_NEXT_GET_ALLOC_SIZE(handle, fsp, sbuf);
1320 do_log(SMB_VFS_OP_GET_ALLOC_SIZE, (result != (uint64_t)-1), handle,
1321 "%llu", result);
1323 return result;
1326 static int smb_full_audit_unlink(vfs_handle_struct *handle,
1327 const struct smb_filename *smb_fname)
1329 int result;
1331 result = SMB_VFS_NEXT_UNLINK(handle, smb_fname);
1333 do_log(SMB_VFS_OP_UNLINK, (result >= 0), handle, "%s",
1334 smb_fname_str_do_log(smb_fname));
1336 return result;
1339 static int smb_full_audit_chmod(vfs_handle_struct *handle,
1340 const char *path, mode_t mode)
1342 int result;
1344 result = SMB_VFS_NEXT_CHMOD(handle, path, mode);
1346 do_log(SMB_VFS_OP_CHMOD, (result >= 0), handle, "%s|%o", path, mode);
1348 return result;
1351 static int smb_full_audit_fchmod(vfs_handle_struct *handle, files_struct *fsp,
1352 mode_t mode)
1354 int result;
1356 result = SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1358 do_log(SMB_VFS_OP_FCHMOD, (result >= 0), handle,
1359 "%s|%o", fsp_str_do_log(fsp), mode);
1361 return result;
1364 static int smb_full_audit_chown(vfs_handle_struct *handle,
1365 const char *path, uid_t uid, gid_t gid)
1367 int result;
1369 result = SMB_VFS_NEXT_CHOWN(handle, path, uid, gid);
1371 do_log(SMB_VFS_OP_CHOWN, (result >= 0), handle, "%s|%ld|%ld",
1372 path, (long int)uid, (long int)gid);
1374 return result;
1377 static int smb_full_audit_fchown(vfs_handle_struct *handle, files_struct *fsp,
1378 uid_t uid, gid_t gid)
1380 int result;
1382 result = SMB_VFS_NEXT_FCHOWN(handle, fsp, uid, gid);
1384 do_log(SMB_VFS_OP_FCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1385 fsp_str_do_log(fsp), (long int)uid, (long int)gid);
1387 return result;
1390 static int smb_full_audit_lchown(vfs_handle_struct *handle,
1391 const char *path, uid_t uid, gid_t gid)
1393 int result;
1395 result = SMB_VFS_NEXT_LCHOWN(handle, path, uid, gid);
1397 do_log(SMB_VFS_OP_LCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1398 path, (long int)uid, (long int)gid);
1400 return result;
1403 static int smb_full_audit_chdir(vfs_handle_struct *handle,
1404 const char *path)
1406 int result;
1408 result = SMB_VFS_NEXT_CHDIR(handle, path);
1410 do_log(SMB_VFS_OP_CHDIR, (result >= 0), handle, "chdir|%s", path);
1412 return result;
1415 static char *smb_full_audit_getwd(vfs_handle_struct *handle)
1417 char *result;
1419 result = SMB_VFS_NEXT_GETWD(handle);
1421 do_log(SMB_VFS_OP_GETWD, (result != NULL), handle, "%s",
1422 result == NULL? "" : result);
1424 return result;
1427 static int smb_full_audit_ntimes(vfs_handle_struct *handle,
1428 const struct smb_filename *smb_fname,
1429 struct smb_file_time *ft)
1431 int result;
1433 result = SMB_VFS_NEXT_NTIMES(handle, smb_fname, ft);
1435 do_log(SMB_VFS_OP_NTIMES, (result >= 0), handle, "%s",
1436 smb_fname_str_do_log(smb_fname));
1438 return result;
1441 static int smb_full_audit_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
1442 off_t len)
1444 int result;
1446 result = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1448 do_log(SMB_VFS_OP_FTRUNCATE, (result >= 0), handle,
1449 "%s", fsp_str_do_log(fsp));
1451 return result;
1454 static int smb_full_audit_fallocate(vfs_handle_struct *handle, files_struct *fsp,
1455 uint32_t mode,
1456 off_t offset,
1457 off_t len)
1459 int result;
1461 result = SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
1463 do_log(SMB_VFS_OP_FALLOCATE, (result >= 0), handle,
1464 "%s", fsp_str_do_log(fsp));
1466 return result;
1469 static bool smb_full_audit_lock(vfs_handle_struct *handle, files_struct *fsp,
1470 int op, off_t offset, off_t count, int type)
1472 bool result;
1474 result = SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type);
1476 do_log(SMB_VFS_OP_LOCK, result, handle, "%s", fsp_str_do_log(fsp));
1478 return result;
1481 static int smb_full_audit_kernel_flock(struct vfs_handle_struct *handle,
1482 struct files_struct *fsp,
1483 uint32 share_mode, uint32 access_mask)
1485 int result;
1487 result = SMB_VFS_NEXT_KERNEL_FLOCK(handle, fsp, share_mode, access_mask);
1489 do_log(SMB_VFS_OP_KERNEL_FLOCK, (result >= 0), handle, "%s",
1490 fsp_str_do_log(fsp));
1492 return result;
1495 static int smb_full_audit_linux_setlease(vfs_handle_struct *handle, files_struct *fsp,
1496 int leasetype)
1498 int result;
1500 result = SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
1502 do_log(SMB_VFS_OP_LINUX_SETLEASE, (result >= 0), handle, "%s",
1503 fsp_str_do_log(fsp));
1505 return result;
1508 static bool smb_full_audit_getlock(vfs_handle_struct *handle, files_struct *fsp,
1509 off_t *poffset, off_t *pcount, int *ptype, pid_t *ppid)
1511 bool result;
1513 result = SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype, ppid);
1515 do_log(SMB_VFS_OP_GETLOCK, result, handle, "%s", fsp_str_do_log(fsp));
1517 return result;
1520 static int smb_full_audit_symlink(vfs_handle_struct *handle,
1521 const char *oldpath, const char *newpath)
1523 int result;
1525 result = SMB_VFS_NEXT_SYMLINK(handle, oldpath, newpath);
1527 do_log(SMB_VFS_OP_SYMLINK, (result >= 0), handle,
1528 "%s|%s", oldpath, newpath);
1530 return result;
1533 static int smb_full_audit_readlink(vfs_handle_struct *handle,
1534 const char *path, char *buf, size_t bufsiz)
1536 int result;
1538 result = SMB_VFS_NEXT_READLINK(handle, path, buf, bufsiz);
1540 do_log(SMB_VFS_OP_READLINK, (result >= 0), handle, "%s", path);
1542 return result;
1545 static int smb_full_audit_link(vfs_handle_struct *handle,
1546 const char *oldpath, const char *newpath)
1548 int result;
1550 result = SMB_VFS_NEXT_LINK(handle, oldpath, newpath);
1552 do_log(SMB_VFS_OP_LINK, (result >= 0), handle,
1553 "%s|%s", oldpath, newpath);
1555 return result;
1558 static int smb_full_audit_mknod(vfs_handle_struct *handle,
1559 const char *pathname, mode_t mode, SMB_DEV_T dev)
1561 int result;
1563 result = SMB_VFS_NEXT_MKNOD(handle, pathname, mode, dev);
1565 do_log(SMB_VFS_OP_MKNOD, (result >= 0), handle, "%s", pathname);
1567 return result;
1570 static char *smb_full_audit_realpath(vfs_handle_struct *handle,
1571 const char *path)
1573 char *result;
1575 result = SMB_VFS_NEXT_REALPATH(handle, path);
1577 do_log(SMB_VFS_OP_REALPATH, (result != NULL), handle, "%s", path);
1579 return result;
1582 static NTSTATUS smb_full_audit_notify_watch(struct vfs_handle_struct *handle,
1583 struct sys_notify_context *ctx,
1584 const char *path,
1585 uint32_t *filter,
1586 uint32_t *subdir_filter,
1587 void (*callback)(struct sys_notify_context *ctx,
1588 void *private_data,
1589 struct notify_event *ev),
1590 void *private_data, void *handle_p)
1592 NTSTATUS result;
1594 result = SMB_VFS_NEXT_NOTIFY_WATCH(handle, ctx, path,
1595 filter, subdir_filter, callback,
1596 private_data, handle_p);
1598 do_log(SMB_VFS_OP_NOTIFY_WATCH, NT_STATUS_IS_OK(result), handle, "");
1600 return result;
1603 static int smb_full_audit_chflags(vfs_handle_struct *handle,
1604 const char *path, unsigned int flags)
1606 int result;
1608 result = SMB_VFS_NEXT_CHFLAGS(handle, path, flags);
1610 do_log(SMB_VFS_OP_CHFLAGS, (result != 0), handle, "%s", path);
1612 return result;
1615 static struct file_id smb_full_audit_file_id_create(struct vfs_handle_struct *handle,
1616 const SMB_STRUCT_STAT *sbuf)
1618 struct file_id id_zero;
1619 struct file_id result;
1621 ZERO_STRUCT(id_zero);
1623 result = SMB_VFS_NEXT_FILE_ID_CREATE(handle, sbuf);
1625 do_log(SMB_VFS_OP_FILE_ID_CREATE,
1626 !file_id_equal(&id_zero, &result),
1627 handle, "%s", file_id_string_tos(&result));
1629 return result;
1632 static NTSTATUS smb_full_audit_streaminfo(vfs_handle_struct *handle,
1633 struct files_struct *fsp,
1634 const char *fname,
1635 TALLOC_CTX *mem_ctx,
1636 unsigned int *pnum_streams,
1637 struct stream_struct **pstreams)
1639 NTSTATUS result;
1641 result = SMB_VFS_NEXT_STREAMINFO(handle, fsp, fname, mem_ctx,
1642 pnum_streams, pstreams);
1644 do_log(SMB_VFS_OP_STREAMINFO, NT_STATUS_IS_OK(result), handle,
1645 "%s", fname);
1647 return result;
1650 static int smb_full_audit_get_real_filename(struct vfs_handle_struct *handle,
1651 const char *path,
1652 const char *name,
1653 TALLOC_CTX *mem_ctx,
1654 char **found_name)
1656 int result;
1658 result = SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name, mem_ctx,
1659 found_name);
1661 do_log(SMB_VFS_OP_GET_REAL_FILENAME, (result == 0), handle,
1662 "%s/%s->%s", path, name, (result == 0) ? "" : *found_name);
1664 return result;
1667 static const char *smb_full_audit_connectpath(vfs_handle_struct *handle,
1668 const char *fname)
1670 const char *result;
1672 result = SMB_VFS_NEXT_CONNECTPATH(handle, fname);
1674 do_log(SMB_VFS_OP_CONNECTPATH, result != NULL, handle,
1675 "%s", fname);
1677 return result;
1680 static NTSTATUS smb_full_audit_brl_lock_windows(struct vfs_handle_struct *handle,
1681 struct byte_range_lock *br_lck,
1682 struct lock_struct *plock,
1683 bool blocking_lock)
1685 NTSTATUS result;
1687 result = SMB_VFS_NEXT_BRL_LOCK_WINDOWS(handle, br_lck, plock,
1688 blocking_lock);
1690 do_log(SMB_VFS_OP_BRL_LOCK_WINDOWS, NT_STATUS_IS_OK(result), handle,
1691 "%s:%llu-%llu. type=%d. blocking=%d",
1692 fsp_str_do_log(brl_fsp(br_lck)),
1693 plock->start, plock->size, plock->lock_type, blocking_lock);
1695 return result;
1698 static bool smb_full_audit_brl_unlock_windows(struct vfs_handle_struct *handle,
1699 struct messaging_context *msg_ctx,
1700 struct byte_range_lock *br_lck,
1701 const struct lock_struct *plock)
1703 bool result;
1705 result = SMB_VFS_NEXT_BRL_UNLOCK_WINDOWS(handle, msg_ctx, br_lck,
1706 plock);
1708 do_log(SMB_VFS_OP_BRL_UNLOCK_WINDOWS, (result == 0), handle,
1709 "%s:%llu-%llu:%d", fsp_str_do_log(brl_fsp(br_lck)),
1710 plock->start,
1711 plock->size, plock->lock_type);
1713 return result;
1716 static bool smb_full_audit_brl_cancel_windows(struct vfs_handle_struct *handle,
1717 struct byte_range_lock *br_lck,
1718 struct lock_struct *plock)
1720 bool result;
1722 result = SMB_VFS_NEXT_BRL_CANCEL_WINDOWS(handle, br_lck, plock);
1724 do_log(SMB_VFS_OP_BRL_CANCEL_WINDOWS, (result == 0), handle,
1725 "%s:%llu-%llu:%d", fsp_str_do_log(brl_fsp(br_lck)),
1726 plock->start,
1727 plock->size, plock->lock_type);
1729 return result;
1732 static bool smb_full_audit_strict_lock(struct vfs_handle_struct *handle,
1733 struct files_struct *fsp,
1734 struct lock_struct *plock)
1736 bool result;
1738 result = SMB_VFS_NEXT_STRICT_LOCK(handle, fsp, plock);
1740 do_log(SMB_VFS_OP_STRICT_LOCK, result, handle,
1741 "%s:%llu-%llu:%d", fsp_str_do_log(fsp), plock->start,
1742 plock->size, plock->lock_type);
1744 return result;
1747 static void smb_full_audit_strict_unlock(struct vfs_handle_struct *handle,
1748 struct files_struct *fsp,
1749 struct lock_struct *plock)
1751 SMB_VFS_NEXT_STRICT_UNLOCK(handle, fsp, plock);
1753 do_log(SMB_VFS_OP_STRICT_UNLOCK, true, handle,
1754 "%s:%llu-%llu:%d", fsp_str_do_log(fsp), plock->start,
1755 plock->size, plock->lock_type);
1758 static NTSTATUS smb_full_audit_translate_name(struct vfs_handle_struct *handle,
1759 const char *name,
1760 enum vfs_translate_direction direction,
1761 TALLOC_CTX *mem_ctx,
1762 char **mapped_name)
1764 NTSTATUS result;
1766 result = SMB_VFS_NEXT_TRANSLATE_NAME(handle, name, direction, mem_ctx,
1767 mapped_name);
1769 do_log(SMB_VFS_OP_TRANSLATE_NAME, NT_STATUS_IS_OK(result), handle, "");
1771 return result;
1774 static struct tevent_req *smb_full_audit_copy_chunk_send(struct vfs_handle_struct *handle,
1775 TALLOC_CTX *mem_ctx,
1776 struct tevent_context *ev,
1777 struct files_struct *src_fsp,
1778 off_t src_off,
1779 struct files_struct *dest_fsp,
1780 off_t dest_off,
1781 off_t num)
1783 struct tevent_req *req;
1785 req = SMB_VFS_NEXT_COPY_CHUNK_SEND(handle, mem_ctx, ev, src_fsp,
1786 src_off, dest_fsp, dest_off, num);
1788 do_log(SMB_VFS_OP_COPY_CHUNK_SEND, req, handle, "");
1790 return req;
1793 static NTSTATUS smb_full_audit_copy_chunk_recv(struct vfs_handle_struct *handle,
1794 struct tevent_req *req,
1795 off_t *copied)
1797 NTSTATUS result;
1799 result = SMB_VFS_NEXT_COPY_CHUNK_RECV(handle, req, copied);
1801 do_log(SMB_VFS_OP_COPY_CHUNK_RECV, NT_STATUS_IS_OK(result), handle, "");
1803 return result;
1806 static NTSTATUS smb_full_audit_get_compression(vfs_handle_struct *handle,
1807 TALLOC_CTX *mem_ctx,
1808 struct files_struct *fsp,
1809 struct smb_filename *smb_fname,
1810 uint16_t *_compression_fmt)
1812 NTSTATUS result;
1814 result = SMB_VFS_NEXT_GET_COMPRESSION(handle, mem_ctx, fsp, smb_fname,
1815 _compression_fmt);
1817 do_log(SMB_VFS_OP_GET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
1818 "%s",
1819 (fsp ? fsp_str_do_log(fsp) : smb_fname_str_do_log(smb_fname)));
1821 return result;
1824 static NTSTATUS smb_full_audit_set_compression(vfs_handle_struct *handle,
1825 TALLOC_CTX *mem_ctx,
1826 struct files_struct *fsp,
1827 uint16_t compression_fmt)
1829 NTSTATUS result;
1831 result = SMB_VFS_NEXT_SET_COMPRESSION(handle, mem_ctx, fsp,
1832 compression_fmt);
1834 do_log(SMB_VFS_OP_SET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
1835 "%s", fsp_str_do_log(fsp));
1837 return result;
1840 static NTSTATUS smb_full_audit_readdir_attr(struct vfs_handle_struct *handle,
1841 const struct smb_filename *fname,
1842 TALLOC_CTX *mem_ctx,
1843 struct readdir_attr_data **pattr_data)
1845 NTSTATUS status;
1847 status = SMB_VFS_NEXT_READDIR_ATTR(handle, fname, mem_ctx, pattr_data);
1849 do_log(SMB_VFS_OP_READDIR_ATTR, NT_STATUS_IS_OK(status), handle, "%s",
1850 smb_fname_str_do_log(fname));
1852 return status;
1855 static NTSTATUS smb_full_audit_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
1856 uint32 security_info,
1857 TALLOC_CTX *mem_ctx,
1858 struct security_descriptor **ppdesc)
1860 NTSTATUS result;
1862 result = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
1863 mem_ctx, ppdesc);
1865 do_log(SMB_VFS_OP_FGET_NT_ACL, NT_STATUS_IS_OK(result), handle,
1866 "%s", fsp_str_do_log(fsp));
1868 return result;
1871 static NTSTATUS smb_full_audit_get_nt_acl(vfs_handle_struct *handle,
1872 const char *name,
1873 uint32 security_info,
1874 TALLOC_CTX *mem_ctx,
1875 struct security_descriptor **ppdesc)
1877 NTSTATUS result;
1879 result = SMB_VFS_NEXT_GET_NT_ACL(handle, name, security_info,
1880 mem_ctx, ppdesc);
1882 do_log(SMB_VFS_OP_GET_NT_ACL, NT_STATUS_IS_OK(result), handle,
1883 "%s", name);
1885 return result;
1888 static NTSTATUS smb_full_audit_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
1889 uint32 security_info_sent,
1890 const struct security_descriptor *psd)
1892 struct vfs_full_audit_private_data *pd;
1893 NTSTATUS result;
1894 char *sd = NULL;
1896 SMB_VFS_HANDLE_GET_DATA(handle, pd,
1897 struct vfs_full_audit_private_data,
1898 return NT_STATUS_INTERNAL_ERROR);
1900 if (pd->log_secdesc) {
1901 sd = sddl_encode(talloc_tos(), psd, get_global_sam_sid());
1904 result = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
1906 do_log(SMB_VFS_OP_FSET_NT_ACL, NT_STATUS_IS_OK(result), handle,
1907 "%s [%s]", fsp_str_do_log(fsp), sd ? sd : "");
1909 TALLOC_FREE(sd);
1911 return result;
1914 static int smb_full_audit_chmod_acl(vfs_handle_struct *handle,
1915 const char *path, mode_t mode)
1917 int result;
1919 result = SMB_VFS_NEXT_CHMOD_ACL(handle, path, mode);
1921 do_log(SMB_VFS_OP_CHMOD_ACL, (result >= 0), handle,
1922 "%s|%o", path, mode);
1924 return result;
1927 static int smb_full_audit_fchmod_acl(vfs_handle_struct *handle, files_struct *fsp,
1928 mode_t mode)
1930 int result;
1932 result = SMB_VFS_NEXT_FCHMOD_ACL(handle, fsp, mode);
1934 do_log(SMB_VFS_OP_FCHMOD_ACL, (result >= 0), handle,
1935 "%s|%o", fsp_str_do_log(fsp), mode);
1937 return result;
1940 static SMB_ACL_T smb_full_audit_sys_acl_get_file(vfs_handle_struct *handle,
1941 const char *path_p,
1942 SMB_ACL_TYPE_T type,
1943 TALLOC_CTX *mem_ctx)
1945 SMB_ACL_T result;
1947 result = SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, path_p, type, mem_ctx);
1949 do_log(SMB_VFS_OP_SYS_ACL_GET_FILE, (result != NULL), handle,
1950 "%s", path_p);
1952 return result;
1955 static SMB_ACL_T smb_full_audit_sys_acl_get_fd(vfs_handle_struct *handle,
1956 files_struct *fsp, TALLOC_CTX *mem_ctx)
1958 SMB_ACL_T result;
1960 result = SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp, mem_ctx);
1962 do_log(SMB_VFS_OP_SYS_ACL_GET_FD, (result != NULL), handle,
1963 "%s", fsp_str_do_log(fsp));
1965 return result;
1968 static int smb_full_audit_sys_acl_blob_get_file(vfs_handle_struct *handle,
1969 const char *path_p,
1970 TALLOC_CTX *mem_ctx,
1971 char **blob_description,
1972 DATA_BLOB *blob)
1974 int result;
1976 result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FILE(handle, path_p, mem_ctx, blob_description, blob);
1978 do_log(SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE, (result >= 0), handle,
1979 "%s", path_p);
1981 return result;
1984 static int smb_full_audit_sys_acl_blob_get_fd(vfs_handle_struct *handle,
1985 files_struct *fsp,
1986 TALLOC_CTX *mem_ctx,
1987 char **blob_description,
1988 DATA_BLOB *blob)
1990 int result;
1992 result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle, fsp, mem_ctx, blob_description, blob);
1994 do_log(SMB_VFS_OP_SYS_ACL_BLOB_GET_FD, (result >= 0), handle,
1995 "%s", fsp_str_do_log(fsp));
1997 return result;
2000 static int smb_full_audit_sys_acl_set_file(vfs_handle_struct *handle,
2002 const char *name, SMB_ACL_TYPE_T acltype,
2003 SMB_ACL_T theacl)
2005 int result;
2007 result = SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, name, acltype,
2008 theacl);
2010 do_log(SMB_VFS_OP_SYS_ACL_SET_FILE, (result >= 0), handle,
2011 "%s", name);
2013 return result;
2016 static int smb_full_audit_sys_acl_set_fd(vfs_handle_struct *handle, files_struct *fsp,
2017 SMB_ACL_T theacl)
2019 int result;
2021 result = SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, theacl);
2023 do_log(SMB_VFS_OP_SYS_ACL_SET_FD, (result >= 0), handle,
2024 "%s", fsp_str_do_log(fsp));
2026 return result;
2029 static int smb_full_audit_sys_acl_delete_def_file(vfs_handle_struct *handle,
2031 const char *path)
2033 int result;
2035 result = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, path);
2037 do_log(SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE, (result >= 0), handle,
2038 "%s", path);
2040 return result;
2043 static ssize_t smb_full_audit_getxattr(struct vfs_handle_struct *handle,
2044 const char *path,
2045 const char *name, void *value, size_t size)
2047 ssize_t result;
2049 result = SMB_VFS_NEXT_GETXATTR(handle, path, name, value, size);
2051 do_log(SMB_VFS_OP_GETXATTR, (result >= 0), handle,
2052 "%s|%s", path, name);
2054 return result;
2057 static ssize_t smb_full_audit_fgetxattr(struct vfs_handle_struct *handle,
2058 struct files_struct *fsp,
2059 const char *name, void *value, size_t size)
2061 ssize_t result;
2063 result = SMB_VFS_NEXT_FGETXATTR(handle, fsp, name, value, size);
2065 do_log(SMB_VFS_OP_FGETXATTR, (result >= 0), handle,
2066 "%s|%s", fsp_str_do_log(fsp), name);
2068 return result;
2071 static ssize_t smb_full_audit_listxattr(struct vfs_handle_struct *handle,
2072 const char *path, char *list, size_t size)
2074 ssize_t result;
2076 result = SMB_VFS_NEXT_LISTXATTR(handle, path, list, size);
2078 do_log(SMB_VFS_OP_LISTXATTR, (result >= 0), handle, "%s", path);
2080 return result;
2083 static ssize_t smb_full_audit_flistxattr(struct vfs_handle_struct *handle,
2084 struct files_struct *fsp, char *list,
2085 size_t size)
2087 ssize_t result;
2089 result = SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
2091 do_log(SMB_VFS_OP_FLISTXATTR, (result >= 0), handle,
2092 "%s", fsp_str_do_log(fsp));
2094 return result;
2097 static int smb_full_audit_removexattr(struct vfs_handle_struct *handle,
2098 const char *path,
2099 const char *name)
2101 int result;
2103 result = SMB_VFS_NEXT_REMOVEXATTR(handle, path, name);
2105 do_log(SMB_VFS_OP_REMOVEXATTR, (result >= 0), handle,
2106 "%s|%s", path, name);
2108 return result;
2111 static int smb_full_audit_fremovexattr(struct vfs_handle_struct *handle,
2112 struct files_struct *fsp,
2113 const char *name)
2115 int result;
2117 result = SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, name);
2119 do_log(SMB_VFS_OP_FREMOVEXATTR, (result >= 0), handle,
2120 "%s|%s", fsp_str_do_log(fsp), name);
2122 return result;
2125 static int smb_full_audit_setxattr(struct vfs_handle_struct *handle,
2126 const char *path,
2127 const char *name, const void *value, size_t size,
2128 int flags)
2130 int result;
2132 result = SMB_VFS_NEXT_SETXATTR(handle, path, name, value, size,
2133 flags);
2135 do_log(SMB_VFS_OP_SETXATTR, (result >= 0), handle,
2136 "%s|%s", path, name);
2138 return result;
2141 static int smb_full_audit_fsetxattr(struct vfs_handle_struct *handle,
2142 struct files_struct *fsp, const char *name,
2143 const void *value, size_t size, int flags)
2145 int result;
2147 result = SMB_VFS_NEXT_FSETXATTR(handle, fsp, name, value, size, flags);
2149 do_log(SMB_VFS_OP_FSETXATTR, (result >= 0), handle,
2150 "%s|%s", fsp_str_do_log(fsp), name);
2152 return result;
2155 static bool smb_full_audit_aio_force(struct vfs_handle_struct *handle,
2156 struct files_struct *fsp)
2158 bool result;
2160 result = SMB_VFS_NEXT_AIO_FORCE(handle, fsp);
2161 do_log(SMB_VFS_OP_AIO_FORCE, result, handle,
2162 "%s", fsp_str_do_log(fsp));
2164 return result;
2167 static bool smb_full_audit_is_offline(struct vfs_handle_struct *handle,
2168 const struct smb_filename *fname,
2169 SMB_STRUCT_STAT *sbuf)
2171 bool result;
2173 result = SMB_VFS_NEXT_IS_OFFLINE(handle, fname, sbuf);
2174 do_log(SMB_VFS_OP_IS_OFFLINE, result, handle, "%s",
2175 smb_fname_str_do_log(fname));
2176 return result;
2179 static int smb_full_audit_set_offline(struct vfs_handle_struct *handle,
2180 const struct smb_filename *fname)
2182 int result;
2184 result = SMB_VFS_NEXT_SET_OFFLINE(handle, fname);
2185 do_log(SMB_VFS_OP_SET_OFFLINE, result >= 0, handle, "%s",
2186 smb_fname_str_do_log(fname));
2187 return result;
2190 static struct vfs_fn_pointers vfs_full_audit_fns = {
2192 /* Disk operations */
2194 .connect_fn = smb_full_audit_connect,
2195 .disconnect_fn = smb_full_audit_disconnect,
2196 .disk_free_fn = smb_full_audit_disk_free,
2197 .get_quota_fn = smb_full_audit_get_quota,
2198 .set_quota_fn = smb_full_audit_set_quota,
2199 .get_shadow_copy_data_fn = smb_full_audit_get_shadow_copy_data,
2200 .statvfs_fn = smb_full_audit_statvfs,
2201 .fs_capabilities_fn = smb_full_audit_fs_capabilities,
2202 .opendir_fn = smb_full_audit_opendir,
2203 .fdopendir_fn = smb_full_audit_fdopendir,
2204 .readdir_fn = smb_full_audit_readdir,
2205 .seekdir_fn = smb_full_audit_seekdir,
2206 .telldir_fn = smb_full_audit_telldir,
2207 .rewind_dir_fn = smb_full_audit_rewinddir,
2208 .mkdir_fn = smb_full_audit_mkdir,
2209 .rmdir_fn = smb_full_audit_rmdir,
2210 .closedir_fn = smb_full_audit_closedir,
2211 .init_search_op_fn = smb_full_audit_init_search_op,
2212 .open_fn = smb_full_audit_open,
2213 .create_file_fn = smb_full_audit_create_file,
2214 .close_fn = smb_full_audit_close,
2215 .read_fn = smb_full_audit_read,
2216 .pread_fn = smb_full_audit_pread,
2217 .pread_send_fn = smb_full_audit_pread_send,
2218 .pread_recv_fn = smb_full_audit_pread_recv,
2219 .write_fn = smb_full_audit_write,
2220 .pwrite_fn = smb_full_audit_pwrite,
2221 .pwrite_send_fn = smb_full_audit_pwrite_send,
2222 .pwrite_recv_fn = smb_full_audit_pwrite_recv,
2223 .lseek_fn = smb_full_audit_lseek,
2224 .sendfile_fn = smb_full_audit_sendfile,
2225 .recvfile_fn = smb_full_audit_recvfile,
2226 .rename_fn = smb_full_audit_rename,
2227 .fsync_fn = smb_full_audit_fsync,
2228 .fsync_send_fn = smb_full_audit_fsync_send,
2229 .fsync_recv_fn = smb_full_audit_fsync_recv,
2230 .stat_fn = smb_full_audit_stat,
2231 .fstat_fn = smb_full_audit_fstat,
2232 .lstat_fn = smb_full_audit_lstat,
2233 .get_alloc_size_fn = smb_full_audit_get_alloc_size,
2234 .unlink_fn = smb_full_audit_unlink,
2235 .chmod_fn = smb_full_audit_chmod,
2236 .fchmod_fn = smb_full_audit_fchmod,
2237 .chown_fn = smb_full_audit_chown,
2238 .fchown_fn = smb_full_audit_fchown,
2239 .lchown_fn = smb_full_audit_lchown,
2240 .chdir_fn = smb_full_audit_chdir,
2241 .getwd_fn = smb_full_audit_getwd,
2242 .ntimes_fn = smb_full_audit_ntimes,
2243 .ftruncate_fn = smb_full_audit_ftruncate,
2244 .fallocate_fn = smb_full_audit_fallocate,
2245 .lock_fn = smb_full_audit_lock,
2246 .kernel_flock_fn = smb_full_audit_kernel_flock,
2247 .linux_setlease_fn = smb_full_audit_linux_setlease,
2248 .getlock_fn = smb_full_audit_getlock,
2249 .symlink_fn = smb_full_audit_symlink,
2250 .readlink_fn = smb_full_audit_readlink,
2251 .link_fn = smb_full_audit_link,
2252 .mknod_fn = smb_full_audit_mknod,
2253 .realpath_fn = smb_full_audit_realpath,
2254 .notify_watch_fn = smb_full_audit_notify_watch,
2255 .chflags_fn = smb_full_audit_chflags,
2256 .file_id_create_fn = smb_full_audit_file_id_create,
2257 .streaminfo_fn = smb_full_audit_streaminfo,
2258 .get_real_filename_fn = smb_full_audit_get_real_filename,
2259 .connectpath_fn = smb_full_audit_connectpath,
2260 .brl_lock_windows_fn = smb_full_audit_brl_lock_windows,
2261 .brl_unlock_windows_fn = smb_full_audit_brl_unlock_windows,
2262 .brl_cancel_windows_fn = smb_full_audit_brl_cancel_windows,
2263 .strict_lock_fn = smb_full_audit_strict_lock,
2264 .strict_unlock_fn = smb_full_audit_strict_unlock,
2265 .translate_name_fn = smb_full_audit_translate_name,
2266 .copy_chunk_send_fn = smb_full_audit_copy_chunk_send,
2267 .copy_chunk_recv_fn = smb_full_audit_copy_chunk_recv,
2268 .get_compression_fn = smb_full_audit_get_compression,
2269 .set_compression_fn = smb_full_audit_set_compression,
2270 .readdir_attr_fn = smb_full_audit_readdir_attr,
2271 .fget_nt_acl_fn = smb_full_audit_fget_nt_acl,
2272 .get_nt_acl_fn = smb_full_audit_get_nt_acl,
2273 .fset_nt_acl_fn = smb_full_audit_fset_nt_acl,
2274 .chmod_acl_fn = smb_full_audit_chmod_acl,
2275 .fchmod_acl_fn = smb_full_audit_fchmod_acl,
2276 .sys_acl_get_file_fn = smb_full_audit_sys_acl_get_file,
2277 .sys_acl_get_fd_fn = smb_full_audit_sys_acl_get_fd,
2278 .sys_acl_blob_get_file_fn = smb_full_audit_sys_acl_blob_get_file,
2279 .sys_acl_blob_get_fd_fn = smb_full_audit_sys_acl_blob_get_fd,
2280 .sys_acl_set_file_fn = smb_full_audit_sys_acl_set_file,
2281 .sys_acl_set_fd_fn = smb_full_audit_sys_acl_set_fd,
2282 .sys_acl_delete_def_file_fn = smb_full_audit_sys_acl_delete_def_file,
2283 .getxattr_fn = smb_full_audit_getxattr,
2284 .fgetxattr_fn = smb_full_audit_fgetxattr,
2285 .listxattr_fn = smb_full_audit_listxattr,
2286 .flistxattr_fn = smb_full_audit_flistxattr,
2287 .removexattr_fn = smb_full_audit_removexattr,
2288 .fremovexattr_fn = smb_full_audit_fremovexattr,
2289 .setxattr_fn = smb_full_audit_setxattr,
2290 .fsetxattr_fn = smb_full_audit_fsetxattr,
2291 .aio_force_fn = smb_full_audit_aio_force,
2292 .is_offline_fn = smb_full_audit_is_offline,
2293 .set_offline_fn = smb_full_audit_set_offline,
2296 NTSTATUS vfs_full_audit_init(void)
2298 NTSTATUS ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION,
2299 "full_audit", &vfs_full_audit_fns);
2301 if (!NT_STATUS_IS_OK(ret))
2302 return ret;
2304 vfs_full_audit_debug_level = debug_add_class("full_audit");
2305 if (vfs_full_audit_debug_level == -1) {
2306 vfs_full_audit_debug_level = DBGC_VFS;
2307 DEBUG(0, ("vfs_full_audit: Couldn't register custom debugging "
2308 "class!\n"));
2309 } else {
2310 DEBUG(10, ("vfs_full_audit: Debug class number of "
2311 "'full_audit': %d\n", vfs_full_audit_debug_level));
2314 return ret;