lib/param: Allow enum values to also be white-space insentive in comparison
[Samba.git] / source3 / modules / vfs_full_audit.c
bloba51ab758154c40c36b06b702d3113164653e650b
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,
175 /* NT ACL operations. */
177 SMB_VFS_OP_FGET_NT_ACL,
178 SMB_VFS_OP_GET_NT_ACL,
179 SMB_VFS_OP_FSET_NT_ACL,
181 /* POSIX ACL operations. */
183 SMB_VFS_OP_CHMOD_ACL,
184 SMB_VFS_OP_FCHMOD_ACL,
186 SMB_VFS_OP_SYS_ACL_GET_FILE,
187 SMB_VFS_OP_SYS_ACL_GET_FD,
188 SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE,
189 SMB_VFS_OP_SYS_ACL_BLOB_GET_FD,
190 SMB_VFS_OP_SYS_ACL_SET_FILE,
191 SMB_VFS_OP_SYS_ACL_SET_FD,
192 SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE,
194 /* EA operations. */
195 SMB_VFS_OP_GETXATTR,
196 SMB_VFS_OP_FGETXATTR,
197 SMB_VFS_OP_LISTXATTR,
198 SMB_VFS_OP_FLISTXATTR,
199 SMB_VFS_OP_REMOVEXATTR,
200 SMB_VFS_OP_FREMOVEXATTR,
201 SMB_VFS_OP_SETXATTR,
202 SMB_VFS_OP_FSETXATTR,
204 /* aio operations */
205 SMB_VFS_OP_AIO_FORCE,
207 /* offline operations */
208 SMB_VFS_OP_IS_OFFLINE,
209 SMB_VFS_OP_SET_OFFLINE,
211 /* This should always be last enum value */
213 SMB_VFS_OP_LAST
214 } vfs_op_type;
216 /* The following array *must* be in the same order as defined in vfs_op_type */
218 static struct {
219 vfs_op_type type;
220 const char *name;
221 } vfs_op_names[] = {
222 { SMB_VFS_OP_CONNECT, "connect" },
223 { SMB_VFS_OP_DISCONNECT, "disconnect" },
224 { SMB_VFS_OP_DISK_FREE, "disk_free" },
225 { SMB_VFS_OP_GET_QUOTA, "get_quota" },
226 { SMB_VFS_OP_SET_QUOTA, "set_quota" },
227 { SMB_VFS_OP_GET_SHADOW_COPY_DATA, "get_shadow_copy_data" },
228 { SMB_VFS_OP_STATVFS, "statvfs" },
229 { SMB_VFS_OP_FS_CAPABILITIES, "fs_capabilities" },
230 { SMB_VFS_OP_OPENDIR, "opendir" },
231 { SMB_VFS_OP_FDOPENDIR, "fdopendir" },
232 { SMB_VFS_OP_READDIR, "readdir" },
233 { SMB_VFS_OP_SEEKDIR, "seekdir" },
234 { SMB_VFS_OP_TELLDIR, "telldir" },
235 { SMB_VFS_OP_REWINDDIR, "rewinddir" },
236 { SMB_VFS_OP_MKDIR, "mkdir" },
237 { SMB_VFS_OP_RMDIR, "rmdir" },
238 { SMB_VFS_OP_CLOSEDIR, "closedir" },
239 { SMB_VFS_OP_INIT_SEARCH_OP, "init_search_op" },
240 { SMB_VFS_OP_OPEN, "open" },
241 { SMB_VFS_OP_CREATE_FILE, "create_file" },
242 { SMB_VFS_OP_CLOSE, "close" },
243 { SMB_VFS_OP_READ, "read" },
244 { SMB_VFS_OP_PREAD, "pread" },
245 { SMB_VFS_OP_PREAD_SEND, "pread_send" },
246 { SMB_VFS_OP_PREAD_RECV, "pread_recv" },
247 { SMB_VFS_OP_WRITE, "write" },
248 { SMB_VFS_OP_PWRITE, "pwrite" },
249 { SMB_VFS_OP_PWRITE_SEND, "pwrite_send" },
250 { SMB_VFS_OP_PWRITE_RECV, "pwrite_recv" },
251 { SMB_VFS_OP_LSEEK, "lseek" },
252 { SMB_VFS_OP_SENDFILE, "sendfile" },
253 { SMB_VFS_OP_RECVFILE, "recvfile" },
254 { SMB_VFS_OP_RENAME, "rename" },
255 { SMB_VFS_OP_FSYNC, "fsync" },
256 { SMB_VFS_OP_FSYNC_SEND, "fsync_send" },
257 { SMB_VFS_OP_FSYNC_RECV, "fsync_recv" },
258 { SMB_VFS_OP_STAT, "stat" },
259 { SMB_VFS_OP_FSTAT, "fstat" },
260 { SMB_VFS_OP_LSTAT, "lstat" },
261 { SMB_VFS_OP_GET_ALLOC_SIZE, "get_alloc_size" },
262 { SMB_VFS_OP_UNLINK, "unlink" },
263 { SMB_VFS_OP_CHMOD, "chmod" },
264 { SMB_VFS_OP_FCHMOD, "fchmod" },
265 { SMB_VFS_OP_CHOWN, "chown" },
266 { SMB_VFS_OP_FCHOWN, "fchown" },
267 { SMB_VFS_OP_LCHOWN, "lchown" },
268 { SMB_VFS_OP_CHDIR, "chdir" },
269 { SMB_VFS_OP_GETWD, "getwd" },
270 { SMB_VFS_OP_NTIMES, "ntimes" },
271 { SMB_VFS_OP_FTRUNCATE, "ftruncate" },
272 { SMB_VFS_OP_FALLOCATE,"fallocate" },
273 { SMB_VFS_OP_LOCK, "lock" },
274 { SMB_VFS_OP_KERNEL_FLOCK, "kernel_flock" },
275 { SMB_VFS_OP_LINUX_SETLEASE, "linux_setlease" },
276 { SMB_VFS_OP_GETLOCK, "getlock" },
277 { SMB_VFS_OP_SYMLINK, "symlink" },
278 { SMB_VFS_OP_READLINK, "readlink" },
279 { SMB_VFS_OP_LINK, "link" },
280 { SMB_VFS_OP_MKNOD, "mknod" },
281 { SMB_VFS_OP_REALPATH, "realpath" },
282 { SMB_VFS_OP_NOTIFY_WATCH, "notify_watch" },
283 { SMB_VFS_OP_CHFLAGS, "chflags" },
284 { SMB_VFS_OP_FILE_ID_CREATE, "file_id_create" },
285 { SMB_VFS_OP_STREAMINFO, "streaminfo" },
286 { SMB_VFS_OP_GET_REAL_FILENAME, "get_real_filename" },
287 { SMB_VFS_OP_CONNECTPATH, "connectpath" },
288 { SMB_VFS_OP_BRL_LOCK_WINDOWS, "brl_lock_windows" },
289 { SMB_VFS_OP_BRL_UNLOCK_WINDOWS, "brl_unlock_windows" },
290 { SMB_VFS_OP_BRL_CANCEL_WINDOWS, "brl_cancel_windows" },
291 { SMB_VFS_OP_STRICT_LOCK, "strict_lock" },
292 { SMB_VFS_OP_STRICT_UNLOCK, "strict_unlock" },
293 { SMB_VFS_OP_TRANSLATE_NAME, "translate_name" },
294 { SMB_VFS_OP_COPY_CHUNK_SEND, "copy_chunk_send" },
295 { SMB_VFS_OP_COPY_CHUNK_RECV, "copy_chunk_recv" },
296 { SMB_VFS_OP_GET_COMPRESSION, "get_compression" },
297 { SMB_VFS_OP_SET_COMPRESSION, "set_compression" },
298 { SMB_VFS_OP_FGET_NT_ACL, "fget_nt_acl" },
299 { SMB_VFS_OP_GET_NT_ACL, "get_nt_acl" },
300 { SMB_VFS_OP_FSET_NT_ACL, "fset_nt_acl" },
301 { SMB_VFS_OP_CHMOD_ACL, "chmod_acl" },
302 { SMB_VFS_OP_FCHMOD_ACL, "fchmod_acl" },
303 { SMB_VFS_OP_SYS_ACL_GET_FILE, "sys_acl_get_file" },
304 { SMB_VFS_OP_SYS_ACL_GET_FD, "sys_acl_get_fd" },
305 { SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE, "sys_acl_blob_get_file" },
306 { SMB_VFS_OP_SYS_ACL_BLOB_GET_FD, "sys_acl_blob_get_fd" },
307 { SMB_VFS_OP_SYS_ACL_SET_FILE, "sys_acl_set_file" },
308 { SMB_VFS_OP_SYS_ACL_SET_FD, "sys_acl_set_fd" },
309 { SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE, "sys_acl_delete_def_file" },
310 { SMB_VFS_OP_GETXATTR, "getxattr" },
311 { SMB_VFS_OP_FGETXATTR, "fgetxattr" },
312 { SMB_VFS_OP_LISTXATTR, "listxattr" },
313 { SMB_VFS_OP_FLISTXATTR, "flistxattr" },
314 { SMB_VFS_OP_REMOVEXATTR, "removexattr" },
315 { SMB_VFS_OP_FREMOVEXATTR, "fremovexattr" },
316 { SMB_VFS_OP_SETXATTR, "setxattr" },
317 { SMB_VFS_OP_FSETXATTR, "fsetxattr" },
318 { SMB_VFS_OP_AIO_FORCE, "aio_force" },
319 { SMB_VFS_OP_IS_OFFLINE, "is_offline" },
320 { SMB_VFS_OP_SET_OFFLINE, "set_offline" },
321 { SMB_VFS_OP_LAST, NULL }
324 static int audit_syslog_facility(vfs_handle_struct *handle)
326 static const struct enum_list enum_log_facilities[] = {
327 { LOG_USER, "USER" },
328 { LOG_LOCAL0, "LOCAL0" },
329 { LOG_LOCAL1, "LOCAL1" },
330 { LOG_LOCAL2, "LOCAL2" },
331 { LOG_LOCAL3, "LOCAL3" },
332 { LOG_LOCAL4, "LOCAL4" },
333 { LOG_LOCAL5, "LOCAL5" },
334 { LOG_LOCAL6, "LOCAL6" },
335 { LOG_LOCAL7, "LOCAL7" },
336 { -1, NULL}
339 int facility;
341 facility = lp_parm_enum(SNUM(handle->conn), "full_audit", "facility", enum_log_facilities, LOG_USER);
343 return facility;
346 static int audit_syslog_priority(vfs_handle_struct *handle)
348 static const struct enum_list enum_log_priorities[] = {
349 { LOG_EMERG, "EMERG" },
350 { LOG_ALERT, "ALERT" },
351 { LOG_CRIT, "CRIT" },
352 { LOG_ERR, "ERR" },
353 { LOG_WARNING, "WARNING" },
354 { LOG_NOTICE, "NOTICE" },
355 { LOG_INFO, "INFO" },
356 { LOG_DEBUG, "DEBUG" },
357 { -1, NULL}
360 int priority;
362 priority = lp_parm_enum(SNUM(handle->conn), "full_audit", "priority",
363 enum_log_priorities, LOG_NOTICE);
364 if (priority == -1) {
365 priority = LOG_WARNING;
368 return priority;
371 static char *audit_prefix(TALLOC_CTX *ctx, connection_struct *conn)
373 char *prefix = NULL;
374 char *result;
376 prefix = talloc_strdup(ctx,
377 lp_parm_const_string(SNUM(conn), "full_audit",
378 "prefix", "%u|%I"));
379 if (!prefix) {
380 return NULL;
382 result = talloc_sub_advanced(ctx,
383 lp_servicename(talloc_tos(), SNUM(conn)),
384 conn->session_info->unix_info->unix_name,
385 conn->connectpath,
386 conn->session_info->unix_token->gid,
387 conn->session_info->unix_info->sanitized_username,
388 conn->session_info->info->domain_name,
389 prefix);
390 TALLOC_FREE(prefix);
391 return result;
394 static bool log_success(struct vfs_full_audit_private_data *pd, vfs_op_type op)
396 if (pd->success_ops == NULL) {
397 return True;
400 return bitmap_query(pd->success_ops, op);
403 static bool log_failure(struct vfs_full_audit_private_data *pd, vfs_op_type op)
405 if (pd->failure_ops == NULL)
406 return True;
408 return bitmap_query(pd->failure_ops, op);
411 static struct bitmap *init_bitmap(TALLOC_CTX *mem_ctx, const char **ops)
413 struct bitmap *bm;
415 if (ops == NULL) {
416 return NULL;
419 bm = bitmap_talloc(mem_ctx, SMB_VFS_OP_LAST);
420 if (bm == NULL) {
421 DEBUG(0, ("Could not alloc bitmap -- "
422 "defaulting to logging everything\n"));
423 return NULL;
426 for (; *ops != NULL; ops += 1) {
427 int i;
428 bool neg = false;
429 const char *op;
431 if (strequal(*ops, "all")) {
432 for (i=0; i<SMB_VFS_OP_LAST; i++) {
433 bitmap_set(bm, i);
435 continue;
438 if (strequal(*ops, "none")) {
439 break;
442 op = ops[0];
443 if (op[0] == '!') {
444 neg = true;
445 op += 1;
448 for (i=0; i<SMB_VFS_OP_LAST; i++) {
449 if ((vfs_op_names[i].name == NULL)
450 || (vfs_op_names[i].type != i)) {
451 smb_panic("vfs_full_audit.c: name table not "
452 "in sync with vfs_op_type enums\n");
454 if (strequal(op, vfs_op_names[i].name)) {
455 if (neg) {
456 bitmap_clear(bm, i);
457 } else {
458 bitmap_set(bm, i);
460 break;
463 if (i == SMB_VFS_OP_LAST) {
464 DEBUG(0, ("Could not find opname %s, logging all\n",
465 *ops));
466 TALLOC_FREE(bm);
467 return NULL;
470 return bm;
473 static const char *audit_opname(vfs_op_type op)
475 if (op >= SMB_VFS_OP_LAST)
476 return "INVALID VFS OP";
477 return vfs_op_names[op].name;
480 static TALLOC_CTX *tmp_do_log_ctx;
482 * Get us a temporary talloc context usable just for DEBUG arguments
484 static TALLOC_CTX *do_log_ctx(void)
486 if (tmp_do_log_ctx == NULL) {
487 tmp_do_log_ctx = talloc_named_const(NULL, 0, "do_log_ctx");
489 return tmp_do_log_ctx;
492 static void do_log(vfs_op_type op, bool success, vfs_handle_struct *handle,
493 const char *format, ...)
495 struct vfs_full_audit_private_data *pd;
496 fstring err_msg;
497 char *audit_pre = NULL;
498 va_list ap;
499 char *op_msg = NULL;
501 SMB_VFS_HANDLE_GET_DATA(handle, pd,
502 struct vfs_full_audit_private_data,
503 return;);
505 if (success && (!log_success(pd, op)))
506 goto out;
508 if (!success && (!log_failure(pd, op)))
509 goto out;
511 if (success)
512 fstrcpy(err_msg, "ok");
513 else
514 fstr_sprintf(err_msg, "fail (%s)", strerror(errno));
516 va_start(ap, format);
517 op_msg = talloc_vasprintf(talloc_tos(), format, ap);
518 va_end(ap);
520 if (!op_msg) {
521 goto out;
524 audit_pre = audit_prefix(talloc_tos(), handle->conn);
526 if (pd->do_syslog) {
527 int priority;
530 * Specify the facility to interoperate with other syslog
531 * callers (smbd for example).
533 priority = pd->syslog_priority | pd->syslog_facility;
535 syslog(priority, "%s|%s|%s|%s\n",
536 audit_pre ? audit_pre : "",
537 audit_opname(op), err_msg, op_msg);
538 } else {
539 DEBUG(1, ("%s|%s|%s|%s\n",
540 audit_pre ? audit_pre : "",
541 audit_opname(op), err_msg, op_msg));
543 out:
544 TALLOC_FREE(audit_pre);
545 TALLOC_FREE(op_msg);
546 TALLOC_FREE(tmp_do_log_ctx);
550 * Return a string using the do_log_ctx()
552 static const char *smb_fname_str_do_log(const struct smb_filename *smb_fname)
554 char *fname = NULL;
555 NTSTATUS status;
557 if (smb_fname == NULL) {
558 return "";
560 status = get_full_smb_filename(do_log_ctx(), smb_fname, &fname);
561 if (!NT_STATUS_IS_OK(status)) {
562 return "";
564 return fname;
568 * Return an fsp debug string using the do_log_ctx()
570 static const char *fsp_str_do_log(const struct files_struct *fsp)
572 return smb_fname_str_do_log(fsp->fsp_name);
575 /* Implementation of vfs_ops. Pass everything on to the default
576 operation but log event first. */
578 static int smb_full_audit_connect(vfs_handle_struct *handle,
579 const char *svc, const char *user)
581 int result;
582 struct vfs_full_audit_private_data *pd = NULL;
584 result = SMB_VFS_NEXT_CONNECT(handle, svc, user);
585 if (result < 0) {
586 return result;
589 pd = talloc_zero(handle, struct vfs_full_audit_private_data);
590 if (!pd) {
591 SMB_VFS_NEXT_DISCONNECT(handle);
592 return -1;
595 pd->syslog_facility = audit_syslog_facility(handle);
596 if (pd->syslog_facility == -1) {
597 DEBUG(1, ("%s: Unknown facility %s\n", __func__,
598 lp_parm_const_string(SNUM(handle->conn),
599 "full_audit", "facility",
600 "USER")));
601 SMB_VFS_NEXT_DISCONNECT(handle);
602 return -1;
605 pd->syslog_priority = audit_syslog_priority(handle);
607 pd->log_secdesc = lp_parm_bool(SNUM(handle->conn),
608 "full_audit", "log_secdesc", false);
610 pd->do_syslog = lp_parm_bool(SNUM(handle->conn),
611 "full_audit", "syslog", true);
613 #ifdef WITH_SYSLOG
614 if (pd->do_syslog) {
615 openlog("smbd_audit", 0, pd->syslog_facility);
617 #endif
619 pd->success_ops = init_bitmap(
620 pd, lp_parm_string_list(SNUM(handle->conn), "full_audit",
621 "success", NULL));
622 pd->failure_ops = init_bitmap(
623 pd, lp_parm_string_list(SNUM(handle->conn), "full_audit",
624 "failure", NULL));
626 /* Store the private data. */
627 SMB_VFS_HANDLE_SET_DATA(handle, pd, NULL,
628 struct vfs_full_audit_private_data, return -1);
630 do_log(SMB_VFS_OP_CONNECT, True, handle,
631 "%s", svc);
633 return 0;
636 static void smb_full_audit_disconnect(vfs_handle_struct *handle)
638 SMB_VFS_NEXT_DISCONNECT(handle);
640 do_log(SMB_VFS_OP_DISCONNECT, True, handle,
641 "%s", lp_servicename(talloc_tos(), SNUM(handle->conn)));
643 /* The bitmaps will be disconnected when the private
644 data is deleted. */
647 static uint64_t smb_full_audit_disk_free(vfs_handle_struct *handle,
648 const char *path,
649 bool small_query, uint64_t *bsize,
650 uint64_t *dfree, uint64_t *dsize)
652 uint64_t result;
654 result = SMB_VFS_NEXT_DISK_FREE(handle, path, small_query, bsize,
655 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)
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 lease, /* lease */
912 allocation_size, /* allocation_size */
913 private_flags,
914 sd, /* sd */
915 ea_list, /* ea_list */
916 result_fsp, /* result */
917 pinfo); /* pinfo */
919 do_log(SMB_VFS_OP_CREATE_FILE, (NT_STATUS_IS_OK(result)), handle,
920 "0x%x|%s|%s|%s", access_mask,
921 create_options & FILE_DIRECTORY_FILE ? "dir" : "file",
922 str_create_disposition, smb_fname_str_do_log(smb_fname));
924 return result;
927 static int smb_full_audit_close(vfs_handle_struct *handle, files_struct *fsp)
929 int result;
931 result = SMB_VFS_NEXT_CLOSE(handle, fsp);
933 do_log(SMB_VFS_OP_CLOSE, (result >= 0), handle, "%s",
934 fsp_str_do_log(fsp));
936 return result;
939 static ssize_t smb_full_audit_read(vfs_handle_struct *handle, files_struct *fsp,
940 void *data, size_t n)
942 ssize_t result;
944 result = SMB_VFS_NEXT_READ(handle, fsp, data, n);
946 do_log(SMB_VFS_OP_READ, (result >= 0), handle, "%s",
947 fsp_str_do_log(fsp));
949 return result;
952 static ssize_t smb_full_audit_pread(vfs_handle_struct *handle, files_struct *fsp,
953 void *data, size_t n, off_t offset)
955 ssize_t result;
957 result = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
959 do_log(SMB_VFS_OP_PREAD, (result >= 0), handle, "%s",
960 fsp_str_do_log(fsp));
962 return result;
965 struct smb_full_audit_pread_state {
966 vfs_handle_struct *handle;
967 files_struct *fsp;
968 ssize_t ret;
969 int err;
972 static void smb_full_audit_pread_done(struct tevent_req *subreq);
974 static struct tevent_req *smb_full_audit_pread_send(
975 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
976 struct tevent_context *ev, struct files_struct *fsp,
977 void *data, size_t n, off_t offset)
979 struct tevent_req *req, *subreq;
980 struct smb_full_audit_pread_state *state;
982 req = tevent_req_create(mem_ctx, &state,
983 struct smb_full_audit_pread_state);
984 if (req == NULL) {
985 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
986 fsp_str_do_log(fsp));
987 return NULL;
989 state->handle = handle;
990 state->fsp = fsp;
992 subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
993 n, offset);
994 if (tevent_req_nomem(subreq, req)) {
995 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
996 fsp_str_do_log(fsp));
997 return tevent_req_post(req, ev);
999 tevent_req_set_callback(subreq, smb_full_audit_pread_done, req);
1001 do_log(SMB_VFS_OP_PREAD_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1002 return req;
1005 static void smb_full_audit_pread_done(struct tevent_req *subreq)
1007 struct tevent_req *req = tevent_req_callback_data(
1008 subreq, struct tevent_req);
1009 struct smb_full_audit_pread_state *state = tevent_req_data(
1010 req, struct smb_full_audit_pread_state);
1012 state->ret = SMB_VFS_PREAD_RECV(subreq, &state->err);
1013 TALLOC_FREE(subreq);
1014 tevent_req_done(req);
1017 static ssize_t smb_full_audit_pread_recv(struct tevent_req *req, int *err)
1019 struct smb_full_audit_pread_state *state = tevent_req_data(
1020 req, struct smb_full_audit_pread_state);
1022 if (tevent_req_is_unix_error(req, err)) {
1023 do_log(SMB_VFS_OP_PREAD_RECV, false, state->handle, "%s",
1024 fsp_str_do_log(state->fsp));
1025 return -1;
1028 do_log(SMB_VFS_OP_PREAD_RECV, (state->ret >= 0), state->handle, "%s",
1029 fsp_str_do_log(state->fsp));
1031 *err = state->err;
1032 return state->ret;
1035 static ssize_t smb_full_audit_write(vfs_handle_struct *handle, files_struct *fsp,
1036 const void *data, size_t n)
1038 ssize_t result;
1040 result = SMB_VFS_NEXT_WRITE(handle, fsp, data, n);
1042 do_log(SMB_VFS_OP_WRITE, (result >= 0), handle, "%s",
1043 fsp_str_do_log(fsp));
1045 return result;
1048 static ssize_t smb_full_audit_pwrite(vfs_handle_struct *handle, files_struct *fsp,
1049 const void *data, size_t n,
1050 off_t offset)
1052 ssize_t result;
1054 result = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
1056 do_log(SMB_VFS_OP_PWRITE, (result >= 0), handle, "%s",
1057 fsp_str_do_log(fsp));
1059 return result;
1062 struct smb_full_audit_pwrite_state {
1063 vfs_handle_struct *handle;
1064 files_struct *fsp;
1065 ssize_t ret;
1066 int err;
1069 static void smb_full_audit_pwrite_done(struct tevent_req *subreq);
1071 static struct tevent_req *smb_full_audit_pwrite_send(
1072 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1073 struct tevent_context *ev, struct files_struct *fsp,
1074 const void *data, size_t n, off_t offset)
1076 struct tevent_req *req, *subreq;
1077 struct smb_full_audit_pwrite_state *state;
1079 req = tevent_req_create(mem_ctx, &state,
1080 struct smb_full_audit_pwrite_state);
1081 if (req == NULL) {
1082 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1083 fsp_str_do_log(fsp));
1084 return NULL;
1086 state->handle = handle;
1087 state->fsp = fsp;
1089 subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
1090 n, offset);
1091 if (tevent_req_nomem(subreq, req)) {
1092 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1093 fsp_str_do_log(fsp));
1094 return tevent_req_post(req, ev);
1096 tevent_req_set_callback(subreq, smb_full_audit_pwrite_done, req);
1098 do_log(SMB_VFS_OP_PWRITE_SEND, true, handle, "%s",
1099 fsp_str_do_log(fsp));
1100 return req;
1103 static void smb_full_audit_pwrite_done(struct tevent_req *subreq)
1105 struct tevent_req *req = tevent_req_callback_data(
1106 subreq, struct tevent_req);
1107 struct smb_full_audit_pwrite_state *state = tevent_req_data(
1108 req, struct smb_full_audit_pwrite_state);
1110 state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->err);
1111 TALLOC_FREE(subreq);
1112 tevent_req_done(req);
1115 static ssize_t smb_full_audit_pwrite_recv(struct tevent_req *req, int *err)
1117 struct smb_full_audit_pwrite_state *state = tevent_req_data(
1118 req, struct smb_full_audit_pwrite_state);
1120 if (tevent_req_is_unix_error(req, err)) {
1121 do_log(SMB_VFS_OP_PWRITE_RECV, false, state->handle, "%s",
1122 fsp_str_do_log(state->fsp));
1123 return -1;
1126 do_log(SMB_VFS_OP_PWRITE_RECV, (state->ret >= 0), state->handle, "%s",
1127 fsp_str_do_log(state->fsp));
1129 *err = state->err;
1130 return state->ret;
1133 static off_t smb_full_audit_lseek(vfs_handle_struct *handle, files_struct *fsp,
1134 off_t offset, int whence)
1136 ssize_t result;
1138 result = SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence);
1140 do_log(SMB_VFS_OP_LSEEK, (result != (ssize_t)-1), handle,
1141 "%s", fsp_str_do_log(fsp));
1143 return result;
1146 static ssize_t smb_full_audit_sendfile(vfs_handle_struct *handle, int tofd,
1147 files_struct *fromfsp,
1148 const DATA_BLOB *hdr, off_t offset,
1149 size_t n)
1151 ssize_t result;
1153 result = SMB_VFS_NEXT_SENDFILE(handle, tofd, fromfsp, hdr, offset, n);
1155 do_log(SMB_VFS_OP_SENDFILE, (result >= 0), handle,
1156 "%s", fsp_str_do_log(fromfsp));
1158 return result;
1161 static ssize_t smb_full_audit_recvfile(vfs_handle_struct *handle, int fromfd,
1162 files_struct *tofsp,
1163 off_t offset,
1164 size_t n)
1166 ssize_t result;
1168 result = SMB_VFS_NEXT_RECVFILE(handle, fromfd, tofsp, offset, n);
1170 do_log(SMB_VFS_OP_RECVFILE, (result >= 0), handle,
1171 "%s", fsp_str_do_log(tofsp));
1173 return result;
1176 static int smb_full_audit_rename(vfs_handle_struct *handle,
1177 const struct smb_filename *smb_fname_src,
1178 const struct smb_filename *smb_fname_dst)
1180 int result;
1182 result = SMB_VFS_NEXT_RENAME(handle, smb_fname_src, smb_fname_dst);
1184 do_log(SMB_VFS_OP_RENAME, (result >= 0), handle, "%s|%s",
1185 smb_fname_str_do_log(smb_fname_src),
1186 smb_fname_str_do_log(smb_fname_dst));
1188 return result;
1191 static int smb_full_audit_fsync(vfs_handle_struct *handle, files_struct *fsp)
1193 int result;
1195 result = SMB_VFS_NEXT_FSYNC(handle, fsp);
1197 do_log(SMB_VFS_OP_FSYNC, (result >= 0), handle, "%s",
1198 fsp_str_do_log(fsp));
1200 return result;
1203 struct smb_full_audit_fsync_state {
1204 vfs_handle_struct *handle;
1205 files_struct *fsp;
1206 int ret;
1207 int err;
1210 static void smb_full_audit_fsync_done(struct tevent_req *subreq);
1212 static struct tevent_req *smb_full_audit_fsync_send(
1213 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1214 struct tevent_context *ev, struct files_struct *fsp)
1216 struct tevent_req *req, *subreq;
1217 struct smb_full_audit_fsync_state *state;
1219 req = tevent_req_create(mem_ctx, &state,
1220 struct smb_full_audit_fsync_state);
1221 if (req == NULL) {
1222 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1223 fsp_str_do_log(fsp));
1224 return NULL;
1226 state->handle = handle;
1227 state->fsp = fsp;
1229 subreq = SMB_VFS_NEXT_FSYNC_SEND(state, ev, handle, fsp);
1230 if (tevent_req_nomem(subreq, req)) {
1231 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1232 fsp_str_do_log(fsp));
1233 return tevent_req_post(req, ev);
1235 tevent_req_set_callback(subreq, smb_full_audit_fsync_done, req);
1237 do_log(SMB_VFS_OP_FSYNC_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1238 return req;
1241 static void smb_full_audit_fsync_done(struct tevent_req *subreq)
1243 struct tevent_req *req = tevent_req_callback_data(
1244 subreq, struct tevent_req);
1245 struct smb_full_audit_fsync_state *state = tevent_req_data(
1246 req, struct smb_full_audit_fsync_state);
1248 state->ret = SMB_VFS_FSYNC_RECV(subreq, &state->err);
1249 TALLOC_FREE(subreq);
1250 tevent_req_done(req);
1253 static int smb_full_audit_fsync_recv(struct tevent_req *req, int *err)
1255 struct smb_full_audit_fsync_state *state = tevent_req_data(
1256 req, struct smb_full_audit_fsync_state);
1258 if (tevent_req_is_unix_error(req, err)) {
1259 do_log(SMB_VFS_OP_FSYNC_RECV, false, state->handle, "%s",
1260 fsp_str_do_log(state->fsp));
1261 return -1;
1264 do_log(SMB_VFS_OP_FSYNC_RECV, (state->ret >= 0), state->handle, "%s",
1265 fsp_str_do_log(state->fsp));
1267 *err = state->err;
1268 return state->ret;
1271 static int smb_full_audit_stat(vfs_handle_struct *handle,
1272 struct smb_filename *smb_fname)
1274 int result;
1276 result = SMB_VFS_NEXT_STAT(handle, smb_fname);
1278 do_log(SMB_VFS_OP_STAT, (result >= 0), handle, "%s",
1279 smb_fname_str_do_log(smb_fname));
1281 return result;
1284 static int smb_full_audit_fstat(vfs_handle_struct *handle, files_struct *fsp,
1285 SMB_STRUCT_STAT *sbuf)
1287 int result;
1289 result = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1291 do_log(SMB_VFS_OP_FSTAT, (result >= 0), handle, "%s",
1292 fsp_str_do_log(fsp));
1294 return result;
1297 static int smb_full_audit_lstat(vfs_handle_struct *handle,
1298 struct smb_filename *smb_fname)
1300 int result;
1302 result = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
1304 do_log(SMB_VFS_OP_LSTAT, (result >= 0), handle, "%s",
1305 smb_fname_str_do_log(smb_fname));
1307 return result;
1310 static uint64_t smb_full_audit_get_alloc_size(vfs_handle_struct *handle,
1311 files_struct *fsp, const SMB_STRUCT_STAT *sbuf)
1313 uint64_t result;
1315 result = SMB_VFS_NEXT_GET_ALLOC_SIZE(handle, fsp, sbuf);
1317 do_log(SMB_VFS_OP_GET_ALLOC_SIZE, (result != (uint64_t)-1), handle,
1318 "%llu", result);
1320 return result;
1323 static int smb_full_audit_unlink(vfs_handle_struct *handle,
1324 const struct smb_filename *smb_fname)
1326 int result;
1328 result = SMB_VFS_NEXT_UNLINK(handle, smb_fname);
1330 do_log(SMB_VFS_OP_UNLINK, (result >= 0), handle, "%s",
1331 smb_fname_str_do_log(smb_fname));
1333 return result;
1336 static int smb_full_audit_chmod(vfs_handle_struct *handle,
1337 const char *path, mode_t mode)
1339 int result;
1341 result = SMB_VFS_NEXT_CHMOD(handle, path, mode);
1343 do_log(SMB_VFS_OP_CHMOD, (result >= 0), handle, "%s|%o", path, mode);
1345 return result;
1348 static int smb_full_audit_fchmod(vfs_handle_struct *handle, files_struct *fsp,
1349 mode_t mode)
1351 int result;
1353 result = SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1355 do_log(SMB_VFS_OP_FCHMOD, (result >= 0), handle,
1356 "%s|%o", fsp_str_do_log(fsp), mode);
1358 return result;
1361 static int smb_full_audit_chown(vfs_handle_struct *handle,
1362 const char *path, uid_t uid, gid_t gid)
1364 int result;
1366 result = SMB_VFS_NEXT_CHOWN(handle, path, uid, gid);
1368 do_log(SMB_VFS_OP_CHOWN, (result >= 0), handle, "%s|%ld|%ld",
1369 path, (long int)uid, (long int)gid);
1371 return result;
1374 static int smb_full_audit_fchown(vfs_handle_struct *handle, files_struct *fsp,
1375 uid_t uid, gid_t gid)
1377 int result;
1379 result = SMB_VFS_NEXT_FCHOWN(handle, fsp, uid, gid);
1381 do_log(SMB_VFS_OP_FCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1382 fsp_str_do_log(fsp), (long int)uid, (long int)gid);
1384 return result;
1387 static int smb_full_audit_lchown(vfs_handle_struct *handle,
1388 const char *path, uid_t uid, gid_t gid)
1390 int result;
1392 result = SMB_VFS_NEXT_LCHOWN(handle, path, uid, gid);
1394 do_log(SMB_VFS_OP_LCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1395 path, (long int)uid, (long int)gid);
1397 return result;
1400 static int smb_full_audit_chdir(vfs_handle_struct *handle,
1401 const char *path)
1403 int result;
1405 result = SMB_VFS_NEXT_CHDIR(handle, path);
1407 do_log(SMB_VFS_OP_CHDIR, (result >= 0), handle, "chdir|%s", path);
1409 return result;
1412 static char *smb_full_audit_getwd(vfs_handle_struct *handle)
1414 char *result;
1416 result = SMB_VFS_NEXT_GETWD(handle);
1418 do_log(SMB_VFS_OP_GETWD, (result != NULL), handle, "%s",
1419 result == NULL? "" : result);
1421 return result;
1424 static int smb_full_audit_ntimes(vfs_handle_struct *handle,
1425 const struct smb_filename *smb_fname,
1426 struct smb_file_time *ft)
1428 int result;
1430 result = SMB_VFS_NEXT_NTIMES(handle, smb_fname, ft);
1432 do_log(SMB_VFS_OP_NTIMES, (result >= 0), handle, "%s",
1433 smb_fname_str_do_log(smb_fname));
1435 return result;
1438 static int smb_full_audit_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
1439 off_t len)
1441 int result;
1443 result = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1445 do_log(SMB_VFS_OP_FTRUNCATE, (result >= 0), handle,
1446 "%s", fsp_str_do_log(fsp));
1448 return result;
1451 static int smb_full_audit_fallocate(vfs_handle_struct *handle, files_struct *fsp,
1452 enum vfs_fallocate_mode mode,
1453 off_t offset,
1454 off_t len)
1456 int result;
1458 result = SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
1460 do_log(SMB_VFS_OP_FALLOCATE, (result >= 0), handle,
1461 "%s", fsp_str_do_log(fsp));
1463 return result;
1466 static bool smb_full_audit_lock(vfs_handle_struct *handle, files_struct *fsp,
1467 int op, off_t offset, off_t count, int type)
1469 bool result;
1471 result = SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type);
1473 do_log(SMB_VFS_OP_LOCK, result, handle, "%s", fsp_str_do_log(fsp));
1475 return result;
1478 static int smb_full_audit_kernel_flock(struct vfs_handle_struct *handle,
1479 struct files_struct *fsp,
1480 uint32 share_mode, uint32 access_mask)
1482 int result;
1484 result = SMB_VFS_NEXT_KERNEL_FLOCK(handle, fsp, share_mode, access_mask);
1486 do_log(SMB_VFS_OP_KERNEL_FLOCK, (result >= 0), handle, "%s",
1487 fsp_str_do_log(fsp));
1489 return result;
1492 static int smb_full_audit_linux_setlease(vfs_handle_struct *handle, files_struct *fsp,
1493 int leasetype)
1495 int result;
1497 result = SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
1499 do_log(SMB_VFS_OP_LINUX_SETLEASE, (result >= 0), handle, "%s",
1500 fsp_str_do_log(fsp));
1502 return result;
1505 static bool smb_full_audit_getlock(vfs_handle_struct *handle, files_struct *fsp,
1506 off_t *poffset, off_t *pcount, int *ptype, pid_t *ppid)
1508 bool result;
1510 result = SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype, ppid);
1512 do_log(SMB_VFS_OP_GETLOCK, result, handle, "%s", fsp_str_do_log(fsp));
1514 return result;
1517 static int smb_full_audit_symlink(vfs_handle_struct *handle,
1518 const char *oldpath, const char *newpath)
1520 int result;
1522 result = SMB_VFS_NEXT_SYMLINK(handle, oldpath, newpath);
1524 do_log(SMB_VFS_OP_SYMLINK, (result >= 0), handle,
1525 "%s|%s", oldpath, newpath);
1527 return result;
1530 static int smb_full_audit_readlink(vfs_handle_struct *handle,
1531 const char *path, char *buf, size_t bufsiz)
1533 int result;
1535 result = SMB_VFS_NEXT_READLINK(handle, path, buf, bufsiz);
1537 do_log(SMB_VFS_OP_READLINK, (result >= 0), handle, "%s", path);
1539 return result;
1542 static int smb_full_audit_link(vfs_handle_struct *handle,
1543 const char *oldpath, const char *newpath)
1545 int result;
1547 result = SMB_VFS_NEXT_LINK(handle, oldpath, newpath);
1549 do_log(SMB_VFS_OP_LINK, (result >= 0), handle,
1550 "%s|%s", oldpath, newpath);
1552 return result;
1555 static int smb_full_audit_mknod(vfs_handle_struct *handle,
1556 const char *pathname, mode_t mode, SMB_DEV_T dev)
1558 int result;
1560 result = SMB_VFS_NEXT_MKNOD(handle, pathname, mode, dev);
1562 do_log(SMB_VFS_OP_MKNOD, (result >= 0), handle, "%s", pathname);
1564 return result;
1567 static char *smb_full_audit_realpath(vfs_handle_struct *handle,
1568 const char *path)
1570 char *result;
1572 result = SMB_VFS_NEXT_REALPATH(handle, path);
1574 do_log(SMB_VFS_OP_REALPATH, (result != NULL), handle, "%s", path);
1576 return result;
1579 static NTSTATUS smb_full_audit_notify_watch(struct vfs_handle_struct *handle,
1580 struct sys_notify_context *ctx,
1581 const char *path,
1582 uint32_t *filter,
1583 uint32_t *subdir_filter,
1584 void (*callback)(struct sys_notify_context *ctx,
1585 void *private_data,
1586 struct notify_event *ev),
1587 void *private_data, void *handle_p)
1589 NTSTATUS result;
1591 result = SMB_VFS_NEXT_NOTIFY_WATCH(handle, ctx, path,
1592 filter, subdir_filter, callback,
1593 private_data, handle_p);
1595 do_log(SMB_VFS_OP_NOTIFY_WATCH, NT_STATUS_IS_OK(result), handle, "");
1597 return result;
1600 static int smb_full_audit_chflags(vfs_handle_struct *handle,
1601 const char *path, unsigned int flags)
1603 int result;
1605 result = SMB_VFS_NEXT_CHFLAGS(handle, path, flags);
1607 do_log(SMB_VFS_OP_CHFLAGS, (result != 0), handle, "%s", path);
1609 return result;
1612 static struct file_id smb_full_audit_file_id_create(struct vfs_handle_struct *handle,
1613 const SMB_STRUCT_STAT *sbuf)
1615 struct file_id id_zero;
1616 struct file_id result;
1618 ZERO_STRUCT(id_zero);
1620 result = SMB_VFS_NEXT_FILE_ID_CREATE(handle, sbuf);
1622 do_log(SMB_VFS_OP_FILE_ID_CREATE,
1623 !file_id_equal(&id_zero, &result),
1624 handle, "%s", file_id_string_tos(&result));
1626 return result;
1629 static NTSTATUS smb_full_audit_streaminfo(vfs_handle_struct *handle,
1630 struct files_struct *fsp,
1631 const char *fname,
1632 TALLOC_CTX *mem_ctx,
1633 unsigned int *pnum_streams,
1634 struct stream_struct **pstreams)
1636 NTSTATUS result;
1638 result = SMB_VFS_NEXT_STREAMINFO(handle, fsp, fname, mem_ctx,
1639 pnum_streams, pstreams);
1641 do_log(SMB_VFS_OP_STREAMINFO, NT_STATUS_IS_OK(result), handle,
1642 "%s", fname);
1644 return result;
1647 static int smb_full_audit_get_real_filename(struct vfs_handle_struct *handle,
1648 const char *path,
1649 const char *name,
1650 TALLOC_CTX *mem_ctx,
1651 char **found_name)
1653 int result;
1655 result = SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name, mem_ctx,
1656 found_name);
1658 do_log(SMB_VFS_OP_GET_REAL_FILENAME, (result == 0), handle,
1659 "%s/%s->%s", path, name, (result == 0) ? "" : *found_name);
1661 return result;
1664 static const char *smb_full_audit_connectpath(vfs_handle_struct *handle,
1665 const char *fname)
1667 const char *result;
1669 result = SMB_VFS_NEXT_CONNECTPATH(handle, fname);
1671 do_log(SMB_VFS_OP_CONNECTPATH, result != NULL, handle,
1672 "%s", fname);
1674 return result;
1677 static NTSTATUS smb_full_audit_brl_lock_windows(struct vfs_handle_struct *handle,
1678 struct byte_range_lock *br_lck,
1679 struct lock_struct *plock,
1680 bool blocking_lock)
1682 NTSTATUS result;
1684 result = SMB_VFS_NEXT_BRL_LOCK_WINDOWS(handle, br_lck, plock,
1685 blocking_lock);
1687 do_log(SMB_VFS_OP_BRL_LOCK_WINDOWS, NT_STATUS_IS_OK(result), handle,
1688 "%s:%llu-%llu. type=%d. blocking=%d",
1689 fsp_str_do_log(brl_fsp(br_lck)),
1690 plock->start, plock->size, plock->lock_type, blocking_lock);
1692 return result;
1695 static bool smb_full_audit_brl_unlock_windows(struct vfs_handle_struct *handle,
1696 struct messaging_context *msg_ctx,
1697 struct byte_range_lock *br_lck,
1698 const struct lock_struct *plock)
1700 bool result;
1702 result = SMB_VFS_NEXT_BRL_UNLOCK_WINDOWS(handle, msg_ctx, br_lck,
1703 plock);
1705 do_log(SMB_VFS_OP_BRL_UNLOCK_WINDOWS, (result == 0), handle,
1706 "%s:%llu-%llu:%d", fsp_str_do_log(brl_fsp(br_lck)),
1707 plock->start,
1708 plock->size, plock->lock_type);
1710 return result;
1713 static bool smb_full_audit_brl_cancel_windows(struct vfs_handle_struct *handle,
1714 struct byte_range_lock *br_lck,
1715 struct lock_struct *plock)
1717 bool result;
1719 result = SMB_VFS_NEXT_BRL_CANCEL_WINDOWS(handle, br_lck, plock);
1721 do_log(SMB_VFS_OP_BRL_CANCEL_WINDOWS, (result == 0), handle,
1722 "%s:%llu-%llu:%d", fsp_str_do_log(brl_fsp(br_lck)),
1723 plock->start,
1724 plock->size, plock->lock_type);
1726 return result;
1729 static bool smb_full_audit_strict_lock(struct vfs_handle_struct *handle,
1730 struct files_struct *fsp,
1731 struct lock_struct *plock)
1733 bool result;
1735 result = SMB_VFS_NEXT_STRICT_LOCK(handle, fsp, plock);
1737 do_log(SMB_VFS_OP_STRICT_LOCK, result, handle,
1738 "%s:%llu-%llu:%d", fsp_str_do_log(fsp), plock->start,
1739 plock->size, plock->lock_type);
1741 return result;
1744 static void smb_full_audit_strict_unlock(struct vfs_handle_struct *handle,
1745 struct files_struct *fsp,
1746 struct lock_struct *plock)
1748 SMB_VFS_NEXT_STRICT_UNLOCK(handle, fsp, plock);
1750 do_log(SMB_VFS_OP_STRICT_UNLOCK, true, handle,
1751 "%s:%llu-%llu:%d", fsp_str_do_log(fsp), plock->start,
1752 plock->size, plock->lock_type);
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 struct tevent_req *smb_full_audit_copy_chunk_send(struct vfs_handle_struct *handle,
1772 TALLOC_CTX *mem_ctx,
1773 struct tevent_context *ev,
1774 struct files_struct *src_fsp,
1775 off_t src_off,
1776 struct files_struct *dest_fsp,
1777 off_t dest_off,
1778 off_t num)
1780 struct tevent_req *req;
1782 req = SMB_VFS_NEXT_COPY_CHUNK_SEND(handle, mem_ctx, ev, src_fsp,
1783 src_off, dest_fsp, dest_off, num);
1785 do_log(SMB_VFS_OP_COPY_CHUNK_SEND, req, handle, "");
1787 return req;
1790 static NTSTATUS smb_full_audit_copy_chunk_recv(struct vfs_handle_struct *handle,
1791 struct tevent_req *req,
1792 off_t *copied)
1794 NTSTATUS result;
1796 result = SMB_VFS_NEXT_COPY_CHUNK_RECV(handle, req, copied);
1798 do_log(SMB_VFS_OP_COPY_CHUNK_RECV, NT_STATUS_IS_OK(result), handle, "");
1800 return result;
1803 static NTSTATUS smb_full_audit_get_compression(vfs_handle_struct *handle,
1804 TALLOC_CTX *mem_ctx,
1805 struct files_struct *fsp,
1806 struct smb_filename *smb_fname,
1807 uint16_t *_compression_fmt)
1809 NTSTATUS result;
1811 result = SMB_VFS_NEXT_GET_COMPRESSION(handle, mem_ctx, fsp, smb_fname,
1812 _compression_fmt);
1814 do_log(SMB_VFS_OP_GET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
1815 "%s",
1816 (fsp ? fsp_str_do_log(fsp) : smb_fname_str_do_log(smb_fname)));
1818 return result;
1821 static NTSTATUS smb_full_audit_set_compression(vfs_handle_struct *handle,
1822 TALLOC_CTX *mem_ctx,
1823 struct files_struct *fsp,
1824 uint16_t compression_fmt)
1826 NTSTATUS result;
1828 result = SMB_VFS_NEXT_SET_COMPRESSION(handle, mem_ctx, fsp,
1829 compression_fmt);
1831 do_log(SMB_VFS_OP_SET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
1832 "%s", fsp_str_do_log(fsp));
1834 return result;
1837 static NTSTATUS smb_full_audit_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
1838 uint32 security_info,
1839 TALLOC_CTX *mem_ctx,
1840 struct security_descriptor **ppdesc)
1842 NTSTATUS result;
1844 result = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
1845 mem_ctx, ppdesc);
1847 do_log(SMB_VFS_OP_FGET_NT_ACL, NT_STATUS_IS_OK(result), handle,
1848 "%s", fsp_str_do_log(fsp));
1850 return result;
1853 static NTSTATUS smb_full_audit_get_nt_acl(vfs_handle_struct *handle,
1854 const char *name,
1855 uint32 security_info,
1856 TALLOC_CTX *mem_ctx,
1857 struct security_descriptor **ppdesc)
1859 NTSTATUS result;
1861 result = SMB_VFS_NEXT_GET_NT_ACL(handle, name, security_info,
1862 mem_ctx, ppdesc);
1864 do_log(SMB_VFS_OP_GET_NT_ACL, NT_STATUS_IS_OK(result), handle,
1865 "%s", name);
1867 return result;
1870 static NTSTATUS smb_full_audit_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
1871 uint32 security_info_sent,
1872 const struct security_descriptor *psd)
1874 struct vfs_full_audit_private_data *pd;
1875 NTSTATUS result;
1876 char *sd = NULL;
1878 SMB_VFS_HANDLE_GET_DATA(handle, pd,
1879 struct vfs_full_audit_private_data,
1880 return NT_STATUS_INTERNAL_ERROR);
1882 if (pd->log_secdesc) {
1883 sd = sddl_encode(talloc_tos(), psd, get_global_sam_sid());
1886 result = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
1888 do_log(SMB_VFS_OP_FSET_NT_ACL, NT_STATUS_IS_OK(result), handle,
1889 "%s [%s]", fsp_str_do_log(fsp), sd ? sd : "");
1891 TALLOC_FREE(sd);
1893 return result;
1896 static int smb_full_audit_chmod_acl(vfs_handle_struct *handle,
1897 const char *path, mode_t mode)
1899 int result;
1901 result = SMB_VFS_NEXT_CHMOD_ACL(handle, path, mode);
1903 do_log(SMB_VFS_OP_CHMOD_ACL, (result >= 0), handle,
1904 "%s|%o", path, mode);
1906 return result;
1909 static int smb_full_audit_fchmod_acl(vfs_handle_struct *handle, files_struct *fsp,
1910 mode_t mode)
1912 int result;
1914 result = SMB_VFS_NEXT_FCHMOD_ACL(handle, fsp, mode);
1916 do_log(SMB_VFS_OP_FCHMOD_ACL, (result >= 0), handle,
1917 "%s|%o", fsp_str_do_log(fsp), mode);
1919 return result;
1922 static SMB_ACL_T smb_full_audit_sys_acl_get_file(vfs_handle_struct *handle,
1923 const char *path_p,
1924 SMB_ACL_TYPE_T type,
1925 TALLOC_CTX *mem_ctx)
1927 SMB_ACL_T result;
1929 result = SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, path_p, type, mem_ctx);
1931 do_log(SMB_VFS_OP_SYS_ACL_GET_FILE, (result != NULL), handle,
1932 "%s", path_p);
1934 return result;
1937 static SMB_ACL_T smb_full_audit_sys_acl_get_fd(vfs_handle_struct *handle,
1938 files_struct *fsp, TALLOC_CTX *mem_ctx)
1940 SMB_ACL_T result;
1942 result = SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp, mem_ctx);
1944 do_log(SMB_VFS_OP_SYS_ACL_GET_FD, (result != NULL), handle,
1945 "%s", fsp_str_do_log(fsp));
1947 return result;
1950 static int smb_full_audit_sys_acl_blob_get_file(vfs_handle_struct *handle,
1951 const char *path_p,
1952 TALLOC_CTX *mem_ctx,
1953 char **blob_description,
1954 DATA_BLOB *blob)
1956 int result;
1958 result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FILE(handle, path_p, mem_ctx, blob_description, blob);
1960 do_log(SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE, (result >= 0), handle,
1961 "%s", path_p);
1963 return result;
1966 static int smb_full_audit_sys_acl_blob_get_fd(vfs_handle_struct *handle,
1967 files_struct *fsp,
1968 TALLOC_CTX *mem_ctx,
1969 char **blob_description,
1970 DATA_BLOB *blob)
1972 int result;
1974 result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle, fsp, mem_ctx, blob_description, blob);
1976 do_log(SMB_VFS_OP_SYS_ACL_BLOB_GET_FD, (result >= 0), handle,
1977 "%s", fsp_str_do_log(fsp));
1979 return result;
1982 static int smb_full_audit_sys_acl_set_file(vfs_handle_struct *handle,
1984 const char *name, SMB_ACL_TYPE_T acltype,
1985 SMB_ACL_T theacl)
1987 int result;
1989 result = SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, name, acltype,
1990 theacl);
1992 do_log(SMB_VFS_OP_SYS_ACL_SET_FILE, (result >= 0), handle,
1993 "%s", name);
1995 return result;
1998 static int smb_full_audit_sys_acl_set_fd(vfs_handle_struct *handle, files_struct *fsp,
1999 SMB_ACL_T theacl)
2001 int result;
2003 result = SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, theacl);
2005 do_log(SMB_VFS_OP_SYS_ACL_SET_FD, (result >= 0), handle,
2006 "%s", fsp_str_do_log(fsp));
2008 return result;
2011 static int smb_full_audit_sys_acl_delete_def_file(vfs_handle_struct *handle,
2013 const char *path)
2015 int result;
2017 result = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, path);
2019 do_log(SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE, (result >= 0), handle,
2020 "%s", path);
2022 return result;
2025 static ssize_t smb_full_audit_getxattr(struct vfs_handle_struct *handle,
2026 const char *path,
2027 const char *name, void *value, size_t size)
2029 ssize_t result;
2031 result = SMB_VFS_NEXT_GETXATTR(handle, path, name, value, size);
2033 do_log(SMB_VFS_OP_GETXATTR, (result >= 0), handle,
2034 "%s|%s", path, name);
2036 return result;
2039 static ssize_t smb_full_audit_fgetxattr(struct vfs_handle_struct *handle,
2040 struct files_struct *fsp,
2041 const char *name, void *value, size_t size)
2043 ssize_t result;
2045 result = SMB_VFS_NEXT_FGETXATTR(handle, fsp, name, value, size);
2047 do_log(SMB_VFS_OP_FGETXATTR, (result >= 0), handle,
2048 "%s|%s", fsp_str_do_log(fsp), name);
2050 return result;
2053 static ssize_t smb_full_audit_listxattr(struct vfs_handle_struct *handle,
2054 const char *path, char *list, size_t size)
2056 ssize_t result;
2058 result = SMB_VFS_NEXT_LISTXATTR(handle, path, list, size);
2060 do_log(SMB_VFS_OP_LISTXATTR, (result >= 0), handle, "%s", path);
2062 return result;
2065 static ssize_t smb_full_audit_flistxattr(struct vfs_handle_struct *handle,
2066 struct files_struct *fsp, char *list,
2067 size_t size)
2069 ssize_t result;
2071 result = SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
2073 do_log(SMB_VFS_OP_FLISTXATTR, (result >= 0), handle,
2074 "%s", fsp_str_do_log(fsp));
2076 return result;
2079 static int smb_full_audit_removexattr(struct vfs_handle_struct *handle,
2080 const char *path,
2081 const char *name)
2083 int result;
2085 result = SMB_VFS_NEXT_REMOVEXATTR(handle, path, name);
2087 do_log(SMB_VFS_OP_REMOVEXATTR, (result >= 0), handle,
2088 "%s|%s", path, name);
2090 return result;
2093 static int smb_full_audit_fremovexattr(struct vfs_handle_struct *handle,
2094 struct files_struct *fsp,
2095 const char *name)
2097 int result;
2099 result = SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, name);
2101 do_log(SMB_VFS_OP_FREMOVEXATTR, (result >= 0), handle,
2102 "%s|%s", fsp_str_do_log(fsp), name);
2104 return result;
2107 static int smb_full_audit_setxattr(struct vfs_handle_struct *handle,
2108 const char *path,
2109 const char *name, const void *value, size_t size,
2110 int flags)
2112 int result;
2114 result = SMB_VFS_NEXT_SETXATTR(handle, path, name, value, size,
2115 flags);
2117 do_log(SMB_VFS_OP_SETXATTR, (result >= 0), handle,
2118 "%s|%s", path, name);
2120 return result;
2123 static int smb_full_audit_fsetxattr(struct vfs_handle_struct *handle,
2124 struct files_struct *fsp, const char *name,
2125 const void *value, size_t size, int flags)
2127 int result;
2129 result = SMB_VFS_NEXT_FSETXATTR(handle, fsp, name, value, size, flags);
2131 do_log(SMB_VFS_OP_FSETXATTR, (result >= 0), handle,
2132 "%s|%s", fsp_str_do_log(fsp), name);
2134 return result;
2137 static bool smb_full_audit_aio_force(struct vfs_handle_struct *handle,
2138 struct files_struct *fsp)
2140 bool result;
2142 result = SMB_VFS_NEXT_AIO_FORCE(handle, fsp);
2143 do_log(SMB_VFS_OP_AIO_FORCE, result, handle,
2144 "%s", fsp_str_do_log(fsp));
2146 return result;
2149 static bool smb_full_audit_is_offline(struct vfs_handle_struct *handle,
2150 const struct smb_filename *fname,
2151 SMB_STRUCT_STAT *sbuf)
2153 bool result;
2155 result = SMB_VFS_NEXT_IS_OFFLINE(handle, fname, sbuf);
2156 do_log(SMB_VFS_OP_IS_OFFLINE, result, handle, "%s",
2157 smb_fname_str_do_log(fname));
2158 return result;
2161 static int smb_full_audit_set_offline(struct vfs_handle_struct *handle,
2162 const struct smb_filename *fname)
2164 int result;
2166 result = SMB_VFS_NEXT_SET_OFFLINE(handle, fname);
2167 do_log(SMB_VFS_OP_SET_OFFLINE, result >= 0, handle, "%s",
2168 smb_fname_str_do_log(fname));
2169 return result;
2172 static struct vfs_fn_pointers vfs_full_audit_fns = {
2174 /* Disk operations */
2176 .connect_fn = smb_full_audit_connect,
2177 .disconnect_fn = smb_full_audit_disconnect,
2178 .disk_free_fn = smb_full_audit_disk_free,
2179 .get_quota_fn = smb_full_audit_get_quota,
2180 .set_quota_fn = smb_full_audit_set_quota,
2181 .get_shadow_copy_data_fn = smb_full_audit_get_shadow_copy_data,
2182 .statvfs_fn = smb_full_audit_statvfs,
2183 .fs_capabilities_fn = smb_full_audit_fs_capabilities,
2184 .opendir_fn = smb_full_audit_opendir,
2185 .fdopendir_fn = smb_full_audit_fdopendir,
2186 .readdir_fn = smb_full_audit_readdir,
2187 .seekdir_fn = smb_full_audit_seekdir,
2188 .telldir_fn = smb_full_audit_telldir,
2189 .rewind_dir_fn = smb_full_audit_rewinddir,
2190 .mkdir_fn = smb_full_audit_mkdir,
2191 .rmdir_fn = smb_full_audit_rmdir,
2192 .closedir_fn = smb_full_audit_closedir,
2193 .init_search_op_fn = smb_full_audit_init_search_op,
2194 .open_fn = smb_full_audit_open,
2195 .create_file_fn = smb_full_audit_create_file,
2196 .close_fn = smb_full_audit_close,
2197 .read_fn = smb_full_audit_read,
2198 .pread_fn = smb_full_audit_pread,
2199 .pread_send_fn = smb_full_audit_pread_send,
2200 .pread_recv_fn = smb_full_audit_pread_recv,
2201 .write_fn = smb_full_audit_write,
2202 .pwrite_fn = smb_full_audit_pwrite,
2203 .pwrite_send_fn = smb_full_audit_pwrite_send,
2204 .pwrite_recv_fn = smb_full_audit_pwrite_recv,
2205 .lseek_fn = smb_full_audit_lseek,
2206 .sendfile_fn = smb_full_audit_sendfile,
2207 .recvfile_fn = smb_full_audit_recvfile,
2208 .rename_fn = smb_full_audit_rename,
2209 .fsync_fn = smb_full_audit_fsync,
2210 .fsync_send_fn = smb_full_audit_fsync_send,
2211 .fsync_recv_fn = smb_full_audit_fsync_recv,
2212 .stat_fn = smb_full_audit_stat,
2213 .fstat_fn = smb_full_audit_fstat,
2214 .lstat_fn = smb_full_audit_lstat,
2215 .get_alloc_size_fn = smb_full_audit_get_alloc_size,
2216 .unlink_fn = smb_full_audit_unlink,
2217 .chmod_fn = smb_full_audit_chmod,
2218 .fchmod_fn = smb_full_audit_fchmod,
2219 .chown_fn = smb_full_audit_chown,
2220 .fchown_fn = smb_full_audit_fchown,
2221 .lchown_fn = smb_full_audit_lchown,
2222 .chdir_fn = smb_full_audit_chdir,
2223 .getwd_fn = smb_full_audit_getwd,
2224 .ntimes_fn = smb_full_audit_ntimes,
2225 .ftruncate_fn = smb_full_audit_ftruncate,
2226 .fallocate_fn = smb_full_audit_fallocate,
2227 .lock_fn = smb_full_audit_lock,
2228 .kernel_flock_fn = smb_full_audit_kernel_flock,
2229 .linux_setlease_fn = smb_full_audit_linux_setlease,
2230 .getlock_fn = smb_full_audit_getlock,
2231 .symlink_fn = smb_full_audit_symlink,
2232 .readlink_fn = smb_full_audit_readlink,
2233 .link_fn = smb_full_audit_link,
2234 .mknod_fn = smb_full_audit_mknod,
2235 .realpath_fn = smb_full_audit_realpath,
2236 .notify_watch_fn = smb_full_audit_notify_watch,
2237 .chflags_fn = smb_full_audit_chflags,
2238 .file_id_create_fn = smb_full_audit_file_id_create,
2239 .streaminfo_fn = smb_full_audit_streaminfo,
2240 .get_real_filename_fn = smb_full_audit_get_real_filename,
2241 .connectpath_fn = smb_full_audit_connectpath,
2242 .brl_lock_windows_fn = smb_full_audit_brl_lock_windows,
2243 .brl_unlock_windows_fn = smb_full_audit_brl_unlock_windows,
2244 .brl_cancel_windows_fn = smb_full_audit_brl_cancel_windows,
2245 .strict_lock_fn = smb_full_audit_strict_lock,
2246 .strict_unlock_fn = smb_full_audit_strict_unlock,
2247 .translate_name_fn = smb_full_audit_translate_name,
2248 .copy_chunk_send_fn = smb_full_audit_copy_chunk_send,
2249 .copy_chunk_recv_fn = smb_full_audit_copy_chunk_recv,
2250 .get_compression_fn = smb_full_audit_get_compression,
2251 .set_compression_fn = smb_full_audit_set_compression,
2252 .fget_nt_acl_fn = smb_full_audit_fget_nt_acl,
2253 .get_nt_acl_fn = smb_full_audit_get_nt_acl,
2254 .fset_nt_acl_fn = smb_full_audit_fset_nt_acl,
2255 .chmod_acl_fn = smb_full_audit_chmod_acl,
2256 .fchmod_acl_fn = smb_full_audit_fchmod_acl,
2257 .sys_acl_get_file_fn = smb_full_audit_sys_acl_get_file,
2258 .sys_acl_get_fd_fn = smb_full_audit_sys_acl_get_fd,
2259 .sys_acl_blob_get_file_fn = smb_full_audit_sys_acl_blob_get_file,
2260 .sys_acl_blob_get_fd_fn = smb_full_audit_sys_acl_blob_get_fd,
2261 .sys_acl_set_file_fn = smb_full_audit_sys_acl_set_file,
2262 .sys_acl_set_fd_fn = smb_full_audit_sys_acl_set_fd,
2263 .sys_acl_delete_def_file_fn = smb_full_audit_sys_acl_delete_def_file,
2264 .getxattr_fn = smb_full_audit_getxattr,
2265 .fgetxattr_fn = smb_full_audit_fgetxattr,
2266 .listxattr_fn = smb_full_audit_listxattr,
2267 .flistxattr_fn = smb_full_audit_flistxattr,
2268 .removexattr_fn = smb_full_audit_removexattr,
2269 .fremovexattr_fn = smb_full_audit_fremovexattr,
2270 .setxattr_fn = smb_full_audit_setxattr,
2271 .fsetxattr_fn = smb_full_audit_fsetxattr,
2272 .aio_force_fn = smb_full_audit_aio_force,
2273 .is_offline_fn = smb_full_audit_is_offline,
2274 .set_offline_fn = smb_full_audit_set_offline,
2277 NTSTATUS vfs_full_audit_init(void)
2279 NTSTATUS ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION,
2280 "full_audit", &vfs_full_audit_fns);
2282 if (!NT_STATUS_IS_OK(ret))
2283 return ret;
2285 vfs_full_audit_debug_level = debug_add_class("full_audit");
2286 if (vfs_full_audit_debug_level == -1) {
2287 vfs_full_audit_debug_level = DBGC_VFS;
2288 DEBUG(0, ("vfs_full_audit: Couldn't register custom debugging "
2289 "class!\n"));
2290 } else {
2291 DEBUG(10, ("vfs_full_audit: Debug class number of "
2292 "'full_audit': %d\n", vfs_full_audit_debug_level));
2295 return ret;