s3: VFS: vfs_full_audit: Add read_dfs_pathat().
[Samba.git] / source3 / modules / vfs_full_audit.c
blob5c8267dea9f4b275ec784c796c2b208b95a9ba81
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 create_file
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|/tmp
42 * smbd_audit: nobody|192.168.234.1|create_file|fail (No such file or directory)|0x1|file|open|/ts/doesNotExist
43 * smbd_audit: nobody|192.168.234.1|open|ok|w|/tmp/file.txt
44 * smbd_audit: nobody|192.168.234.1|create_file|ok|0x3|file|open|/tmp/file.txt
46 * where "nobody" is the connected username and "192.168.234.1" is the
47 * client's IP address.
49 * Options:
51 * prefix: A macro expansion template prepended to the syslog entry.
53 * success: A list of VFS operations for which a successful completion should
54 * be logged. Defaults to no logging at all. The special operation "all" logs
55 * - you guessed it - everything.
57 * failure: A list of VFS operations for which failure to complete should be
58 * logged. Defaults to logging everything.
62 #include "includes.h"
63 #include "system/filesys.h"
64 #include "system/syslog.h"
65 #include "smbd/smbd.h"
66 #include "../librpc/gen_ndr/ndr_netlogon.h"
67 #include "auth.h"
68 #include "ntioctl.h"
69 #include "lib/param/loadparm.h"
70 #include "lib/util/bitmap.h"
71 #include "lib/util/tevent_unix.h"
72 #include "libcli/security/sddl.h"
73 #include "passdb/machine_sid.h"
74 #include "lib/util/tevent_ntstatus.h"
76 static int vfs_full_audit_debug_level = DBGC_VFS;
78 struct vfs_full_audit_private_data {
79 struct bitmap *success_ops;
80 struct bitmap *failure_ops;
81 int syslog_facility;
82 int syslog_priority;
83 bool log_secdesc;
84 bool do_syslog;
87 #undef DBGC_CLASS
88 #define DBGC_CLASS vfs_full_audit_debug_level
90 typedef enum _vfs_op_type {
91 SMB_VFS_OP_NOOP = -1,
93 /* Disk operations */
95 SMB_VFS_OP_CONNECT = 0,
96 SMB_VFS_OP_DISCONNECT,
97 SMB_VFS_OP_DISK_FREE,
98 SMB_VFS_OP_GET_QUOTA,
99 SMB_VFS_OP_SET_QUOTA,
100 SMB_VFS_OP_GET_SHADOW_COPY_DATA,
101 SMB_VFS_OP_STATVFS,
102 SMB_VFS_OP_FS_CAPABILITIES,
103 SMB_VFS_OP_GET_DFS_REFERRALS,
104 SMB_VFS_OP_CREATE_DFS_PATHAT,
105 SMB_VFS_OP_READ_DFS_PATHAT,
107 /* Directory operations */
109 SMB_VFS_OP_OPENDIR,
110 SMB_VFS_OP_FDOPENDIR,
111 SMB_VFS_OP_READDIR,
112 SMB_VFS_OP_SEEKDIR,
113 SMB_VFS_OP_TELLDIR,
114 SMB_VFS_OP_REWINDDIR,
115 SMB_VFS_OP_MKDIRAT,
116 SMB_VFS_OP_CLOSEDIR,
118 /* File operations */
120 SMB_VFS_OP_OPEN,
121 SMB_VFS_OP_CREATE_FILE,
122 SMB_VFS_OP_CLOSE,
123 SMB_VFS_OP_READ,
124 SMB_VFS_OP_PREAD,
125 SMB_VFS_OP_PREAD_SEND,
126 SMB_VFS_OP_PREAD_RECV,
127 SMB_VFS_OP_WRITE,
128 SMB_VFS_OP_PWRITE,
129 SMB_VFS_OP_PWRITE_SEND,
130 SMB_VFS_OP_PWRITE_RECV,
131 SMB_VFS_OP_LSEEK,
132 SMB_VFS_OP_SENDFILE,
133 SMB_VFS_OP_RECVFILE,
134 SMB_VFS_OP_RENAMEAT,
135 SMB_VFS_OP_FSYNC,
136 SMB_VFS_OP_FSYNC_SEND,
137 SMB_VFS_OP_FSYNC_RECV,
138 SMB_VFS_OP_STAT,
139 SMB_VFS_OP_FSTAT,
140 SMB_VFS_OP_LSTAT,
141 SMB_VFS_OP_GET_ALLOC_SIZE,
142 SMB_VFS_OP_UNLINKAT,
143 SMB_VFS_OP_CHMOD,
144 SMB_VFS_OP_FCHMOD,
145 SMB_VFS_OP_FCHOWN,
146 SMB_VFS_OP_LCHOWN,
147 SMB_VFS_OP_CHDIR,
148 SMB_VFS_OP_GETWD,
149 SMB_VFS_OP_NTIMES,
150 SMB_VFS_OP_FTRUNCATE,
151 SMB_VFS_OP_FALLOCATE,
152 SMB_VFS_OP_LOCK,
153 SMB_VFS_OP_KERNEL_FLOCK,
154 SMB_VFS_OP_FCNTL,
155 SMB_VFS_OP_LINUX_SETLEASE,
156 SMB_VFS_OP_GETLOCK,
157 SMB_VFS_OP_SYMLINKAT,
158 SMB_VFS_OP_READLINKAT,
159 SMB_VFS_OP_LINKAT,
160 SMB_VFS_OP_MKNODAT,
161 SMB_VFS_OP_REALPATH,
162 SMB_VFS_OP_CHFLAGS,
163 SMB_VFS_OP_FILE_ID_CREATE,
164 SMB_VFS_OP_FS_FILE_ID,
165 SMB_VFS_OP_STREAMINFO,
166 SMB_VFS_OP_GET_REAL_FILENAME,
167 SMB_VFS_OP_CONNECTPATH,
168 SMB_VFS_OP_BRL_LOCK_WINDOWS,
169 SMB_VFS_OP_BRL_UNLOCK_WINDOWS,
170 SMB_VFS_OP_STRICT_LOCK_CHECK,
171 SMB_VFS_OP_TRANSLATE_NAME,
172 SMB_VFS_OP_FSCTL,
173 SMB_VFS_OP_OFFLOAD_READ_SEND,
174 SMB_VFS_OP_OFFLOAD_READ_RECV,
175 SMB_VFS_OP_OFFLOAD_WRITE_SEND,
176 SMB_VFS_OP_OFFLOAD_WRITE_RECV,
177 SMB_VFS_OP_GET_COMPRESSION,
178 SMB_VFS_OP_SET_COMPRESSION,
179 SMB_VFS_OP_SNAP_CHECK_PATH,
180 SMB_VFS_OP_SNAP_CREATE,
181 SMB_VFS_OP_SNAP_DELETE,
183 /* DOS attribute operations. */
184 SMB_VFS_OP_GET_DOS_ATTRIBUTES,
185 SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
186 SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV,
187 SMB_VFS_OP_FGET_DOS_ATTRIBUTES,
188 SMB_VFS_OP_SET_DOS_ATTRIBUTES,
189 SMB_VFS_OP_FSET_DOS_ATTRIBUTES,
191 /* NT ACL operations. */
193 SMB_VFS_OP_FGET_NT_ACL,
194 SMB_VFS_OP_GET_NT_ACL,
195 SMB_VFS_OP_FSET_NT_ACL,
196 SMB_VFS_OP_AUDIT_FILE,
198 /* POSIX ACL operations. */
200 SMB_VFS_OP_SYS_ACL_GET_FILE,
201 SMB_VFS_OP_SYS_ACL_GET_FD,
202 SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE,
203 SMB_VFS_OP_SYS_ACL_BLOB_GET_FD,
204 SMB_VFS_OP_SYS_ACL_SET_FILE,
205 SMB_VFS_OP_SYS_ACL_SET_FD,
206 SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE,
208 /* EA operations. */
209 SMB_VFS_OP_GETXATTR,
210 SMB_VFS_OP_GETXATTRAT_SEND,
211 SMB_VFS_OP_GETXATTRAT_RECV,
212 SMB_VFS_OP_FGETXATTR,
213 SMB_VFS_OP_LISTXATTR,
214 SMB_VFS_OP_FLISTXATTR,
215 SMB_VFS_OP_REMOVEXATTR,
216 SMB_VFS_OP_FREMOVEXATTR,
217 SMB_VFS_OP_SETXATTR,
218 SMB_VFS_OP_FSETXATTR,
220 /* aio operations */
221 SMB_VFS_OP_AIO_FORCE,
223 /* offline operations */
224 SMB_VFS_OP_IS_OFFLINE,
225 SMB_VFS_OP_SET_OFFLINE,
227 /* Durable handle operations. */
228 SMB_VFS_OP_DURABLE_COOKIE,
229 SMB_VFS_OP_DURABLE_DISCONNECT,
230 SMB_VFS_OP_DURABLE_RECONNECT,
232 SMB_VFS_OP_READDIR_ATTR,
234 /* This should always be last enum value */
236 SMB_VFS_OP_LAST
237 } vfs_op_type;
239 /* The following array *must* be in the same order as defined in vfs_op_type */
241 static struct {
242 vfs_op_type type;
243 const char *name;
244 } vfs_op_names[] = {
245 { SMB_VFS_OP_CONNECT, "connect" },
246 { SMB_VFS_OP_DISCONNECT, "disconnect" },
247 { SMB_VFS_OP_DISK_FREE, "disk_free" },
248 { SMB_VFS_OP_GET_QUOTA, "get_quota" },
249 { SMB_VFS_OP_SET_QUOTA, "set_quota" },
250 { SMB_VFS_OP_GET_SHADOW_COPY_DATA, "get_shadow_copy_data" },
251 { SMB_VFS_OP_STATVFS, "statvfs" },
252 { SMB_VFS_OP_FS_CAPABILITIES, "fs_capabilities" },
253 { SMB_VFS_OP_GET_DFS_REFERRALS, "get_dfs_referrals" },
254 { SMB_VFS_OP_CREATE_DFS_PATHAT, "create_dfs_pathat" },
255 { SMB_VFS_OP_READ_DFS_PATHAT, "read_dfs_pathat" },
256 { SMB_VFS_OP_OPENDIR, "opendir" },
257 { SMB_VFS_OP_FDOPENDIR, "fdopendir" },
258 { SMB_VFS_OP_READDIR, "readdir" },
259 { SMB_VFS_OP_SEEKDIR, "seekdir" },
260 { SMB_VFS_OP_TELLDIR, "telldir" },
261 { SMB_VFS_OP_REWINDDIR, "rewinddir" },
262 { SMB_VFS_OP_MKDIRAT, "mkdirat" },
263 { SMB_VFS_OP_CLOSEDIR, "closedir" },
264 { SMB_VFS_OP_OPEN, "open" },
265 { SMB_VFS_OP_CREATE_FILE, "create_file" },
266 { SMB_VFS_OP_CLOSE, "close" },
267 { SMB_VFS_OP_READ, "read" },
268 { SMB_VFS_OP_PREAD, "pread" },
269 { SMB_VFS_OP_PREAD_SEND, "pread_send" },
270 { SMB_VFS_OP_PREAD_RECV, "pread_recv" },
271 { SMB_VFS_OP_WRITE, "write" },
272 { SMB_VFS_OP_PWRITE, "pwrite" },
273 { SMB_VFS_OP_PWRITE_SEND, "pwrite_send" },
274 { SMB_VFS_OP_PWRITE_RECV, "pwrite_recv" },
275 { SMB_VFS_OP_LSEEK, "lseek" },
276 { SMB_VFS_OP_SENDFILE, "sendfile" },
277 { SMB_VFS_OP_RECVFILE, "recvfile" },
278 { SMB_VFS_OP_RENAMEAT, "renameat" },
279 { SMB_VFS_OP_FSYNC, "fsync" },
280 { SMB_VFS_OP_FSYNC_SEND, "fsync_send" },
281 { SMB_VFS_OP_FSYNC_RECV, "fsync_recv" },
282 { SMB_VFS_OP_STAT, "stat" },
283 { SMB_VFS_OP_FSTAT, "fstat" },
284 { SMB_VFS_OP_LSTAT, "lstat" },
285 { SMB_VFS_OP_GET_ALLOC_SIZE, "get_alloc_size" },
286 { SMB_VFS_OP_UNLINKAT, "unlinkat" },
287 { SMB_VFS_OP_CHMOD, "chmod" },
288 { SMB_VFS_OP_FCHMOD, "fchmod" },
289 { SMB_VFS_OP_FCHOWN, "fchown" },
290 { SMB_VFS_OP_LCHOWN, "lchown" },
291 { SMB_VFS_OP_CHDIR, "chdir" },
292 { SMB_VFS_OP_GETWD, "getwd" },
293 { SMB_VFS_OP_NTIMES, "ntimes" },
294 { SMB_VFS_OP_FTRUNCATE, "ftruncate" },
295 { SMB_VFS_OP_FALLOCATE,"fallocate" },
296 { SMB_VFS_OP_LOCK, "lock" },
297 { SMB_VFS_OP_KERNEL_FLOCK, "kernel_flock" },
298 { SMB_VFS_OP_LINUX_SETLEASE, "linux_setlease" },
299 { SMB_VFS_OP_GETLOCK, "getlock" },
300 { SMB_VFS_OP_SYMLINKAT, "symlinkat" },
301 { SMB_VFS_OP_READLINKAT,"readlinkat" },
302 { SMB_VFS_OP_LINKAT, "linkat" },
303 { SMB_VFS_OP_MKNODAT, "mknodat" },
304 { SMB_VFS_OP_REALPATH, "realpath" },
305 { SMB_VFS_OP_CHFLAGS, "chflags" },
306 { SMB_VFS_OP_FILE_ID_CREATE, "file_id_create" },
307 { SMB_VFS_OP_FS_FILE_ID, "fs_file_id" },
308 { SMB_VFS_OP_STREAMINFO, "streaminfo" },
309 { SMB_VFS_OP_GET_REAL_FILENAME, "get_real_filename" },
310 { SMB_VFS_OP_CONNECTPATH, "connectpath" },
311 { SMB_VFS_OP_BRL_LOCK_WINDOWS, "brl_lock_windows" },
312 { SMB_VFS_OP_BRL_UNLOCK_WINDOWS, "brl_unlock_windows" },
313 { SMB_VFS_OP_STRICT_LOCK_CHECK, "strict_lock_check" },
314 { SMB_VFS_OP_TRANSLATE_NAME, "translate_name" },
315 { SMB_VFS_OP_FSCTL, "fsctl" },
316 { SMB_VFS_OP_OFFLOAD_READ_SEND, "offload_read_send" },
317 { SMB_VFS_OP_OFFLOAD_READ_RECV, "offload_read_recv" },
318 { SMB_VFS_OP_OFFLOAD_WRITE_SEND, "offload_write_send" },
319 { SMB_VFS_OP_OFFLOAD_WRITE_RECV, "offload_write_recv" },
320 { SMB_VFS_OP_GET_COMPRESSION, "get_compression" },
321 { SMB_VFS_OP_SET_COMPRESSION, "set_compression" },
322 { SMB_VFS_OP_SNAP_CHECK_PATH, "snap_check_path" },
323 { SMB_VFS_OP_SNAP_CREATE, "snap_create" },
324 { SMB_VFS_OP_SNAP_DELETE, "snap_delete" },
325 { SMB_VFS_OP_GET_DOS_ATTRIBUTES, "get_dos_attributes" },
326 { SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND, "get_dos_attributes_send" },
327 { SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV, "get_dos_attributes_recv" },
328 { SMB_VFS_OP_FGET_DOS_ATTRIBUTES, "fget_dos_attributes" },
329 { SMB_VFS_OP_SET_DOS_ATTRIBUTES, "set_dos_attributes" },
330 { SMB_VFS_OP_FSET_DOS_ATTRIBUTES, "fset_dos_attributes" },
331 { SMB_VFS_OP_FGET_NT_ACL, "fget_nt_acl" },
332 { SMB_VFS_OP_GET_NT_ACL, "get_nt_acl" },
333 { SMB_VFS_OP_FSET_NT_ACL, "fset_nt_acl" },
334 { SMB_VFS_OP_AUDIT_FILE, "audit_file" },
335 { SMB_VFS_OP_SYS_ACL_GET_FILE, "sys_acl_get_file" },
336 { SMB_VFS_OP_SYS_ACL_GET_FD, "sys_acl_get_fd" },
337 { SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE, "sys_acl_blob_get_file" },
338 { SMB_VFS_OP_SYS_ACL_BLOB_GET_FD, "sys_acl_blob_get_fd" },
339 { SMB_VFS_OP_SYS_ACL_SET_FILE, "sys_acl_set_file" },
340 { SMB_VFS_OP_SYS_ACL_SET_FD, "sys_acl_set_fd" },
341 { SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE, "sys_acl_delete_def_file" },
342 { SMB_VFS_OP_GETXATTR, "getxattr" },
343 { SMB_VFS_OP_GETXATTRAT_SEND, "getxattrat_send" },
344 { SMB_VFS_OP_GETXATTRAT_RECV, "getxattrat_recv" },
345 { SMB_VFS_OP_FGETXATTR, "fgetxattr" },
346 { SMB_VFS_OP_LISTXATTR, "listxattr" },
347 { SMB_VFS_OP_FLISTXATTR, "flistxattr" },
348 { SMB_VFS_OP_REMOVEXATTR, "removexattr" },
349 { SMB_VFS_OP_FREMOVEXATTR, "fremovexattr" },
350 { SMB_VFS_OP_SETXATTR, "setxattr" },
351 { SMB_VFS_OP_FSETXATTR, "fsetxattr" },
352 { SMB_VFS_OP_AIO_FORCE, "aio_force" },
353 { SMB_VFS_OP_IS_OFFLINE, "is_offline" },
354 { SMB_VFS_OP_SET_OFFLINE, "set_offline" },
355 { SMB_VFS_OP_DURABLE_COOKIE, "durable_cookie" },
356 { SMB_VFS_OP_DURABLE_DISCONNECT, "durable_disconnect" },
357 { SMB_VFS_OP_DURABLE_RECONNECT, "durable_reconnect" },
358 { SMB_VFS_OP_READDIR_ATTR, "readdir_attr" },
359 { SMB_VFS_OP_LAST, NULL }
362 static int audit_syslog_facility(vfs_handle_struct *handle)
364 static const struct enum_list enum_log_facilities[] = {
365 #ifdef LOG_AUTH
366 { LOG_AUTH, "AUTH" },
367 #endif
368 #ifdef LOG_AUTHPRIV
369 { LOG_AUTHPRIV, "AUTHPRIV" },
370 #endif
371 #ifdef LOG_AUDIT
372 { LOG_AUDIT, "AUDIT" },
373 #endif
374 #ifdef LOG_CONSOLE
375 { LOG_CONSOLE, "CONSOLE" },
376 #endif
377 #ifdef LOG_CRON
378 { LOG_CRON, "CRON" },
379 #endif
380 #ifdef LOG_DAEMON
381 { LOG_DAEMON, "DAEMON" },
382 #endif
383 #ifdef LOG_FTP
384 { LOG_FTP, "FTP" },
385 #endif
386 #ifdef LOG_INSTALL
387 { LOG_INSTALL, "INSTALL" },
388 #endif
389 #ifdef LOG_KERN
390 { LOG_KERN, "KERN" },
391 #endif
392 #ifdef LOG_LAUNCHD
393 { LOG_LAUNCHD, "LAUNCHD" },
394 #endif
395 #ifdef LOG_LFMT
396 { LOG_LFMT, "LFMT" },
397 #endif
398 #ifdef LOG_LPR
399 { LOG_LPR, "LPR" },
400 #endif
401 #ifdef LOG_MAIL
402 { LOG_MAIL, "MAIL" },
403 #endif
404 #ifdef LOG_MEGASAFE
405 { LOG_MEGASAFE, "MEGASAFE" },
406 #endif
407 #ifdef LOG_NETINFO
408 { LOG_NETINFO, "NETINFO" },
409 #endif
410 #ifdef LOG_NEWS
411 { LOG_NEWS, "NEWS" },
412 #endif
413 #ifdef LOG_NFACILITIES
414 { LOG_NFACILITIES, "NFACILITIES" },
415 #endif
416 #ifdef LOG_NTP
417 { LOG_NTP, "NTP" },
418 #endif
419 #ifdef LOG_RAS
420 { LOG_RAS, "RAS" },
421 #endif
422 #ifdef LOG_REMOTEAUTH
423 { LOG_REMOTEAUTH, "REMOTEAUTH" },
424 #endif
425 #ifdef LOG_SECURITY
426 { LOG_SECURITY, "SECURITY" },
427 #endif
428 #ifdef LOG_SYSLOG
429 { LOG_SYSLOG, "SYSLOG" },
430 #endif
431 #ifdef LOG_USER
432 { LOG_USER, "USER" },
433 #endif
434 #ifdef LOG_UUCP
435 { LOG_UUCP, "UUCP" },
436 #endif
437 { LOG_LOCAL0, "LOCAL0" },
438 { LOG_LOCAL1, "LOCAL1" },
439 { LOG_LOCAL2, "LOCAL2" },
440 { LOG_LOCAL3, "LOCAL3" },
441 { LOG_LOCAL4, "LOCAL4" },
442 { LOG_LOCAL5, "LOCAL5" },
443 { LOG_LOCAL6, "LOCAL6" },
444 { LOG_LOCAL7, "LOCAL7" },
445 { -1, NULL }
448 int facility;
450 facility = lp_parm_enum(SNUM(handle->conn), "full_audit", "facility", enum_log_facilities, LOG_USER);
452 return facility;
455 static int audit_syslog_priority(vfs_handle_struct *handle)
457 static const struct enum_list enum_log_priorities[] = {
458 { LOG_EMERG, "EMERG" },
459 { LOG_ALERT, "ALERT" },
460 { LOG_CRIT, "CRIT" },
461 { LOG_ERR, "ERR" },
462 { LOG_WARNING, "WARNING" },
463 { LOG_NOTICE, "NOTICE" },
464 { LOG_INFO, "INFO" },
465 { LOG_DEBUG, "DEBUG" },
466 { -1, NULL }
469 int priority;
471 priority = lp_parm_enum(SNUM(handle->conn), "full_audit", "priority",
472 enum_log_priorities, LOG_NOTICE);
473 if (priority == -1) {
474 priority = LOG_WARNING;
477 return priority;
480 static char *audit_prefix(TALLOC_CTX *ctx, connection_struct *conn)
482 const struct loadparm_substitution *lp_sub =
483 loadparm_s3_global_substitution();
484 char *prefix = NULL;
485 char *result;
487 prefix = talloc_strdup(ctx,
488 lp_parm_const_string(SNUM(conn), "full_audit",
489 "prefix", "%u|%I"));
490 if (!prefix) {
491 return NULL;
493 result = talloc_sub_full(ctx,
494 lp_servicename(talloc_tos(), lp_sub, SNUM(conn)),
495 conn->session_info->unix_info->unix_name,
496 conn->connectpath,
497 conn->session_info->unix_token->gid,
498 conn->session_info->unix_info->sanitized_username,
499 conn->session_info->info->domain_name,
500 prefix);
501 TALLOC_FREE(prefix);
502 return result;
505 static bool log_success(struct vfs_full_audit_private_data *pd, vfs_op_type op)
507 if (pd->success_ops == NULL) {
508 return True;
511 return bitmap_query(pd->success_ops, op);
514 static bool log_failure(struct vfs_full_audit_private_data *pd, vfs_op_type op)
516 if (pd->failure_ops == NULL)
517 return True;
519 return bitmap_query(pd->failure_ops, op);
522 static struct bitmap *init_bitmap(TALLOC_CTX *mem_ctx, const char **ops)
524 struct bitmap *bm;
526 if (ops == NULL) {
527 return NULL;
530 bm = bitmap_talloc(mem_ctx, SMB_VFS_OP_LAST);
531 if (bm == NULL) {
532 DEBUG(0, ("Could not alloc bitmap -- "
533 "defaulting to logging everything\n"));
534 return NULL;
537 for (; *ops != NULL; ops += 1) {
538 int i;
539 bool neg = false;
540 const char *op;
542 if (strequal(*ops, "all")) {
543 for (i=0; i<SMB_VFS_OP_LAST; i++) {
544 bitmap_set(bm, i);
546 continue;
549 if (strequal(*ops, "none")) {
550 break;
553 op = ops[0];
554 if (op[0] == '!') {
555 neg = true;
556 op += 1;
559 for (i=0; i<SMB_VFS_OP_LAST; i++) {
560 if ((vfs_op_names[i].name == NULL)
561 || (vfs_op_names[i].type != i)) {
562 smb_panic("vfs_full_audit.c: name table not "
563 "in sync with vfs_op_type enums\n");
565 if (strequal(op, vfs_op_names[i].name)) {
566 if (neg) {
567 bitmap_clear(bm, i);
568 } else {
569 bitmap_set(bm, i);
571 break;
574 if (i == SMB_VFS_OP_LAST) {
575 DEBUG(0, ("Could not find opname %s, logging all\n",
576 *ops));
577 TALLOC_FREE(bm);
578 return NULL;
581 return bm;
584 static const char *audit_opname(vfs_op_type op)
586 if (op >= SMB_VFS_OP_LAST)
587 return "INVALID VFS OP";
588 return vfs_op_names[op].name;
591 static TALLOC_CTX *tmp_do_log_ctx;
593 * Get us a temporary talloc context usable just for DEBUG arguments
595 static TALLOC_CTX *do_log_ctx(void)
597 if (tmp_do_log_ctx == NULL) {
598 tmp_do_log_ctx = talloc_named_const(NULL, 0, "do_log_ctx");
600 return tmp_do_log_ctx;
603 static void do_log(vfs_op_type op, bool success, vfs_handle_struct *handle,
604 const char *format, ...) PRINTF_ATTRIBUTE(4, 5);
606 static void do_log(vfs_op_type op, bool success, vfs_handle_struct *handle,
607 const char *format, ...)
609 struct vfs_full_audit_private_data *pd;
610 fstring err_msg;
611 char *audit_pre = NULL;
612 va_list ap;
613 char *op_msg = NULL;
615 SMB_VFS_HANDLE_GET_DATA(handle, pd,
616 struct vfs_full_audit_private_data,
617 return;);
619 if (success && (!log_success(pd, op)))
620 goto out;
622 if (!success && (!log_failure(pd, op)))
623 goto out;
625 if (success)
626 fstrcpy(err_msg, "ok");
627 else
628 fstr_sprintf(err_msg, "fail (%s)", strerror(errno));
630 va_start(ap, format);
631 op_msg = talloc_vasprintf(talloc_tos(), format, ap);
632 va_end(ap);
634 if (!op_msg) {
635 goto out;
638 audit_pre = audit_prefix(talloc_tos(), handle->conn);
640 if (pd->do_syslog) {
641 int priority;
644 * Specify the facility to interoperate with other syslog
645 * callers (smbd for example).
647 priority = pd->syslog_priority | pd->syslog_facility;
649 syslog(priority, "%s|%s|%s|%s\n",
650 audit_pre ? audit_pre : "",
651 audit_opname(op), err_msg, op_msg);
652 } else {
653 DEBUG(1, ("%s|%s|%s|%s\n",
654 audit_pre ? audit_pre : "",
655 audit_opname(op), err_msg, op_msg));
657 out:
658 TALLOC_FREE(audit_pre);
659 TALLOC_FREE(op_msg);
660 TALLOC_FREE(tmp_do_log_ctx);
664 * Return a string using the do_log_ctx()
666 static const char *smb_fname_str_do_log(struct connection_struct *conn,
667 const struct smb_filename *smb_fname)
669 char *fname = NULL;
670 NTSTATUS status;
672 if (smb_fname == NULL) {
673 return "";
676 if (smb_fname->base_name[0] != '/') {
677 char *abs_name = NULL;
678 struct smb_filename *fname_copy = cp_smb_filename(
679 do_log_ctx(),
680 smb_fname);
681 if (fname_copy == NULL) {
682 return "";
685 if (!ISDOT(smb_fname->base_name)) {
686 abs_name = talloc_asprintf(do_log_ctx(),
687 "%s/%s",
688 conn->cwd_fsp->fsp_name->base_name,
689 smb_fname->base_name);
690 } else {
691 abs_name = talloc_strdup(do_log_ctx(),
692 conn->cwd_fsp->fsp_name->base_name);
694 if (abs_name == NULL) {
695 return "";
697 fname_copy->base_name = abs_name;
698 smb_fname = fname_copy;
701 status = get_full_smb_filename(do_log_ctx(), smb_fname, &fname);
702 if (!NT_STATUS_IS_OK(status)) {
703 return "";
705 return fname;
709 * Return an fsp debug string using the do_log_ctx()
711 static const char *fsp_str_do_log(const struct files_struct *fsp)
713 return smb_fname_str_do_log(fsp->conn, fsp->fsp_name);
716 /* Implementation of vfs_ops. Pass everything on to the default
717 operation but log event first. */
719 static int smb_full_audit_connect(vfs_handle_struct *handle,
720 const char *svc, const char *user)
722 int result;
723 const char *none[] = { "none" };
724 struct vfs_full_audit_private_data *pd = NULL;
726 result = SMB_VFS_NEXT_CONNECT(handle, svc, user);
727 if (result < 0) {
728 return result;
731 pd = talloc_zero(handle, struct vfs_full_audit_private_data);
732 if (!pd) {
733 SMB_VFS_NEXT_DISCONNECT(handle);
734 return -1;
737 pd->syslog_facility = audit_syslog_facility(handle);
738 if (pd->syslog_facility == -1) {
739 DEBUG(1, ("%s: Unknown facility %s\n", __func__,
740 lp_parm_const_string(SNUM(handle->conn),
741 "full_audit", "facility",
742 "USER")));
743 SMB_VFS_NEXT_DISCONNECT(handle);
744 return -1;
747 pd->syslog_priority = audit_syslog_priority(handle);
749 pd->log_secdesc = lp_parm_bool(SNUM(handle->conn),
750 "full_audit", "log_secdesc", false);
752 pd->do_syslog = lp_parm_bool(SNUM(handle->conn),
753 "full_audit", "syslog", true);
755 #ifdef WITH_SYSLOG
756 if (pd->do_syslog) {
757 openlog("smbd_audit", 0, pd->syslog_facility);
759 #endif
761 pd->success_ops = init_bitmap(
762 pd, lp_parm_string_list(SNUM(handle->conn), "full_audit",
763 "success", none));
764 pd->failure_ops = init_bitmap(
765 pd, lp_parm_string_list(SNUM(handle->conn), "full_audit",
766 "failure", none));
768 /* Store the private data. */
769 SMB_VFS_HANDLE_SET_DATA(handle, pd, NULL,
770 struct vfs_full_audit_private_data, return -1);
772 do_log(SMB_VFS_OP_CONNECT, True, handle,
773 "%s", svc);
775 return 0;
778 static void smb_full_audit_disconnect(vfs_handle_struct *handle)
780 const struct loadparm_substitution *lp_sub =
781 loadparm_s3_global_substitution();
783 SMB_VFS_NEXT_DISCONNECT(handle);
785 do_log(SMB_VFS_OP_DISCONNECT, True, handle,
786 "%s", lp_servicename(talloc_tos(), lp_sub, SNUM(handle->conn)));
788 /* The bitmaps will be disconnected when the private
789 data is deleted. */
792 static uint64_t smb_full_audit_disk_free(vfs_handle_struct *handle,
793 const struct smb_filename *smb_fname,
794 uint64_t *bsize,
795 uint64_t *dfree,
796 uint64_t *dsize)
798 uint64_t result;
800 result = SMB_VFS_NEXT_DISK_FREE(handle, smb_fname, bsize, dfree, dsize);
802 /* Don't have a reasonable notion of failure here */
804 do_log(SMB_VFS_OP_DISK_FREE,
805 True,
806 handle,
807 "%s",
808 smb_fname_str_do_log(handle->conn, smb_fname));
810 return result;
813 static int smb_full_audit_get_quota(struct vfs_handle_struct *handle,
814 const struct smb_filename *smb_fname,
815 enum SMB_QUOTA_TYPE qtype,
816 unid_t id,
817 SMB_DISK_QUOTA *qt)
819 int result;
821 result = SMB_VFS_NEXT_GET_QUOTA(handle, smb_fname, qtype, id, qt);
823 do_log(SMB_VFS_OP_GET_QUOTA,
824 (result >= 0),
825 handle,
826 "%s",
827 smb_fname_str_do_log(handle->conn, smb_fname));
829 return result;
832 static int smb_full_audit_set_quota(struct vfs_handle_struct *handle,
833 enum SMB_QUOTA_TYPE qtype, unid_t id,
834 SMB_DISK_QUOTA *qt)
836 int result;
838 result = SMB_VFS_NEXT_SET_QUOTA(handle, qtype, id, qt);
840 do_log(SMB_VFS_OP_SET_QUOTA, (result >= 0), handle, "");
842 return result;
845 static int smb_full_audit_get_shadow_copy_data(struct vfs_handle_struct *handle,
846 struct files_struct *fsp,
847 struct shadow_copy_data *shadow_copy_data,
848 bool labels)
850 int result;
852 result = SMB_VFS_NEXT_GET_SHADOW_COPY_DATA(handle, fsp, shadow_copy_data, labels);
854 do_log(SMB_VFS_OP_GET_SHADOW_COPY_DATA, (result >= 0), handle, "");
856 return result;
859 static int smb_full_audit_statvfs(struct vfs_handle_struct *handle,
860 const struct smb_filename *smb_fname,
861 struct vfs_statvfs_struct *statbuf)
863 int result;
865 result = SMB_VFS_NEXT_STATVFS(handle, smb_fname, statbuf);
867 do_log(SMB_VFS_OP_STATVFS, (result >= 0), handle, "");
869 return result;
872 static uint32_t smb_full_audit_fs_capabilities(struct vfs_handle_struct *handle, enum timestamp_set_resolution *p_ts_res)
874 int result;
876 result = SMB_VFS_NEXT_FS_CAPABILITIES(handle, p_ts_res);
878 do_log(SMB_VFS_OP_FS_CAPABILITIES, true, handle, "");
880 return result;
883 static NTSTATUS smb_full_audit_get_dfs_referrals(
884 struct vfs_handle_struct *handle,
885 struct dfs_GetDFSReferral *r)
887 NTSTATUS status;
889 status = SMB_VFS_NEXT_GET_DFS_REFERRALS(handle, r);
891 do_log(SMB_VFS_OP_GET_DFS_REFERRALS, NT_STATUS_IS_OK(status),
892 handle, "");
894 return status;
897 static NTSTATUS smb_full_audit_create_dfs_pathat(struct vfs_handle_struct *handle,
898 struct files_struct *dirfsp,
899 const struct smb_filename *smb_fname,
900 const struct referral *reflist,
901 size_t referral_count)
903 NTSTATUS status;
905 status = SMB_VFS_NEXT_CREATE_DFS_PATHAT(handle,
906 dirfsp,
907 smb_fname,
908 reflist,
909 referral_count);
911 do_log(SMB_VFS_OP_CREATE_DFS_PATHAT,
912 NT_STATUS_IS_OK(status),
913 handle,
914 "%s",
915 smb_fname_str_do_log(handle->conn, smb_fname));
917 return status;
920 static NTSTATUS smb_full_audit_read_dfs_pathat(struct vfs_handle_struct *handle,
921 TALLOC_CTX *mem_ctx,
922 struct files_struct *dirfsp,
923 const struct smb_filename *smb_fname,
924 struct referral **ppreflist,
925 size_t *preferral_count)
927 NTSTATUS status;
929 status = SMB_VFS_NEXT_READ_DFS_PATHAT(handle,
930 mem_ctx,
931 dirfsp,
932 smb_fname,
933 ppreflist,
934 preferral_count);
936 do_log(SMB_VFS_OP_READ_DFS_PATHAT,
937 NT_STATUS_IS_OK(status),
938 handle,
939 "%s",
940 smb_fname_str_do_log(handle->conn, smb_fname));
942 return status;
945 static NTSTATUS smb_full_audit_snap_check_path(struct vfs_handle_struct *handle,
946 TALLOC_CTX *mem_ctx,
947 const char *service_path,
948 char **base_volume)
950 NTSTATUS status;
952 status = SMB_VFS_NEXT_SNAP_CHECK_PATH(handle, mem_ctx, service_path,
953 base_volume);
954 do_log(SMB_VFS_OP_SNAP_CHECK_PATH, NT_STATUS_IS_OK(status),
955 handle, "");
957 return status;
960 static NTSTATUS smb_full_audit_snap_create(struct vfs_handle_struct *handle,
961 TALLOC_CTX *mem_ctx,
962 const char *base_volume,
963 time_t *tstamp,
964 bool rw,
965 char **base_path,
966 char **snap_path)
968 NTSTATUS status;
970 status = SMB_VFS_NEXT_SNAP_CREATE(handle, mem_ctx, base_volume, tstamp,
971 rw, base_path, snap_path);
972 do_log(SMB_VFS_OP_SNAP_CREATE, NT_STATUS_IS_OK(status), handle, "");
974 return status;
977 static NTSTATUS smb_full_audit_snap_delete(struct vfs_handle_struct *handle,
978 TALLOC_CTX *mem_ctx,
979 char *base_path,
980 char *snap_path)
982 NTSTATUS status;
984 status = SMB_VFS_NEXT_SNAP_DELETE(handle, mem_ctx, base_path,
985 snap_path);
986 do_log(SMB_VFS_OP_SNAP_DELETE, NT_STATUS_IS_OK(status), handle, "");
988 return status;
991 static DIR *smb_full_audit_opendir(vfs_handle_struct *handle,
992 const struct smb_filename *smb_fname,
993 const char *mask,
994 uint32_t attr)
996 DIR *result;
998 result = SMB_VFS_NEXT_OPENDIR(handle, smb_fname, mask, attr);
1000 do_log(SMB_VFS_OP_OPENDIR,
1001 (result != NULL),
1002 handle,
1003 "%s",
1004 smb_fname_str_do_log(handle->conn, smb_fname));
1006 return result;
1009 static DIR *smb_full_audit_fdopendir(vfs_handle_struct *handle,
1010 files_struct *fsp, const char *mask, uint32_t attr)
1012 DIR *result;
1014 result = SMB_VFS_NEXT_FDOPENDIR(handle, fsp, mask, attr);
1016 do_log(SMB_VFS_OP_FDOPENDIR, (result != NULL), handle, "%s",
1017 fsp_str_do_log(fsp));
1019 return result;
1022 static struct dirent *smb_full_audit_readdir(vfs_handle_struct *handle,
1023 DIR *dirp, SMB_STRUCT_STAT *sbuf)
1025 struct dirent *result;
1027 result = SMB_VFS_NEXT_READDIR(handle, dirp, sbuf);
1029 /* This operation has no reasonable error condition
1030 * (End of dir is also failure), so always succeed.
1032 do_log(SMB_VFS_OP_READDIR, True, handle, "");
1034 return result;
1037 static void smb_full_audit_seekdir(vfs_handle_struct *handle,
1038 DIR *dirp, long offset)
1040 SMB_VFS_NEXT_SEEKDIR(handle, dirp, offset);
1042 do_log(SMB_VFS_OP_SEEKDIR, True, handle, "");
1045 static long smb_full_audit_telldir(vfs_handle_struct *handle,
1046 DIR *dirp)
1048 long result;
1050 result = SMB_VFS_NEXT_TELLDIR(handle, dirp);
1052 do_log(SMB_VFS_OP_TELLDIR, True, handle, "");
1054 return result;
1057 static void smb_full_audit_rewinddir(vfs_handle_struct *handle,
1058 DIR *dirp)
1060 SMB_VFS_NEXT_REWINDDIR(handle, dirp);
1062 do_log(SMB_VFS_OP_REWINDDIR, True, handle, "");
1065 static int smb_full_audit_mkdirat(vfs_handle_struct *handle,
1066 struct files_struct *dirfsp,
1067 const struct smb_filename *smb_fname,
1068 mode_t mode)
1070 int result;
1072 result = SMB_VFS_NEXT_MKDIRAT(handle,
1073 dirfsp,
1074 smb_fname,
1075 mode);
1077 do_log(SMB_VFS_OP_MKDIRAT,
1078 (result >= 0),
1079 handle,
1080 "%s",
1081 smb_fname_str_do_log(handle->conn, smb_fname));
1083 return result;
1086 static int smb_full_audit_closedir(vfs_handle_struct *handle,
1087 DIR *dirp)
1089 int result;
1091 result = SMB_VFS_NEXT_CLOSEDIR(handle, dirp);
1093 do_log(SMB_VFS_OP_CLOSEDIR, (result >= 0), handle, "");
1095 return result;
1098 static int smb_full_audit_open(vfs_handle_struct *handle,
1099 struct smb_filename *smb_fname,
1100 files_struct *fsp, int flags, mode_t mode)
1102 int result;
1104 result = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
1106 do_log(SMB_VFS_OP_OPEN, (result >= 0), handle, "%s|%s",
1107 ((flags & O_WRONLY) || (flags & O_RDWR))?"w":"r",
1108 smb_fname_str_do_log(handle->conn, smb_fname));
1110 return result;
1113 static NTSTATUS smb_full_audit_create_file(vfs_handle_struct *handle,
1114 struct smb_request *req,
1115 uint16_t root_dir_fid,
1116 struct smb_filename *smb_fname,
1117 uint32_t access_mask,
1118 uint32_t share_access,
1119 uint32_t create_disposition,
1120 uint32_t create_options,
1121 uint32_t file_attributes,
1122 uint32_t oplock_request,
1123 const struct smb2_lease *lease,
1124 uint64_t allocation_size,
1125 uint32_t private_flags,
1126 struct security_descriptor *sd,
1127 struct ea_list *ea_list,
1128 files_struct **result_fsp,
1129 int *pinfo,
1130 const struct smb2_create_blobs *in_context_blobs,
1131 struct smb2_create_blobs *out_context_blobs)
1133 NTSTATUS result;
1134 const char* str_create_disposition;
1136 switch (create_disposition) {
1137 case FILE_SUPERSEDE:
1138 str_create_disposition = "supersede";
1139 break;
1140 case FILE_OVERWRITE_IF:
1141 str_create_disposition = "overwrite_if";
1142 break;
1143 case FILE_OPEN:
1144 str_create_disposition = "open";
1145 break;
1146 case FILE_OVERWRITE:
1147 str_create_disposition = "overwrite";
1148 break;
1149 case FILE_CREATE:
1150 str_create_disposition = "create";
1151 break;
1152 case FILE_OPEN_IF:
1153 str_create_disposition = "open_if";
1154 break;
1155 default:
1156 str_create_disposition = "unknown";
1159 result = SMB_VFS_NEXT_CREATE_FILE(
1160 handle, /* handle */
1161 req, /* req */
1162 root_dir_fid, /* root_dir_fid */
1163 smb_fname, /* fname */
1164 access_mask, /* access_mask */
1165 share_access, /* share_access */
1166 create_disposition, /* create_disposition*/
1167 create_options, /* create_options */
1168 file_attributes, /* file_attributes */
1169 oplock_request, /* oplock_request */
1170 lease, /* lease */
1171 allocation_size, /* allocation_size */
1172 private_flags,
1173 sd, /* sd */
1174 ea_list, /* ea_list */
1175 result_fsp, /* result */
1176 pinfo, /* pinfo */
1177 in_context_blobs, out_context_blobs); /* create context */
1179 do_log(SMB_VFS_OP_CREATE_FILE, (NT_STATUS_IS_OK(result)), handle,
1180 "0x%x|%s|%s|%s", access_mask,
1181 create_options & FILE_DIRECTORY_FILE ? "dir" : "file",
1182 str_create_disposition,
1183 smb_fname_str_do_log(handle->conn, smb_fname));
1185 return result;
1188 static int smb_full_audit_close(vfs_handle_struct *handle, files_struct *fsp)
1190 int result;
1192 result = SMB_VFS_NEXT_CLOSE(handle, fsp);
1194 do_log(SMB_VFS_OP_CLOSE, (result >= 0), handle, "%s",
1195 fsp_str_do_log(fsp));
1197 return result;
1200 static ssize_t smb_full_audit_pread(vfs_handle_struct *handle, files_struct *fsp,
1201 void *data, size_t n, off_t offset)
1203 ssize_t result;
1205 result = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
1207 do_log(SMB_VFS_OP_PREAD, (result >= 0), handle, "%s",
1208 fsp_str_do_log(fsp));
1210 return result;
1213 struct smb_full_audit_pread_state {
1214 vfs_handle_struct *handle;
1215 files_struct *fsp;
1216 ssize_t ret;
1217 struct vfs_aio_state vfs_aio_state;
1220 static void smb_full_audit_pread_done(struct tevent_req *subreq);
1222 static struct tevent_req *smb_full_audit_pread_send(
1223 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1224 struct tevent_context *ev, struct files_struct *fsp,
1225 void *data, size_t n, off_t offset)
1227 struct tevent_req *req, *subreq;
1228 struct smb_full_audit_pread_state *state;
1230 req = tevent_req_create(mem_ctx, &state,
1231 struct smb_full_audit_pread_state);
1232 if (req == NULL) {
1233 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
1234 fsp_str_do_log(fsp));
1235 return NULL;
1237 state->handle = handle;
1238 state->fsp = fsp;
1240 subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
1241 n, offset);
1242 if (tevent_req_nomem(subreq, req)) {
1243 do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
1244 fsp_str_do_log(fsp));
1245 return tevent_req_post(req, ev);
1247 tevent_req_set_callback(subreq, smb_full_audit_pread_done, req);
1249 do_log(SMB_VFS_OP_PREAD_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1250 return req;
1253 static void smb_full_audit_pread_done(struct tevent_req *subreq)
1255 struct tevent_req *req = tevent_req_callback_data(
1256 subreq, struct tevent_req);
1257 struct smb_full_audit_pread_state *state = tevent_req_data(
1258 req, struct smb_full_audit_pread_state);
1260 state->ret = SMB_VFS_PREAD_RECV(subreq, &state->vfs_aio_state);
1261 TALLOC_FREE(subreq);
1262 tevent_req_done(req);
1265 static ssize_t smb_full_audit_pread_recv(struct tevent_req *req,
1266 struct vfs_aio_state *vfs_aio_state)
1268 struct smb_full_audit_pread_state *state = tevent_req_data(
1269 req, struct smb_full_audit_pread_state);
1271 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1272 do_log(SMB_VFS_OP_PREAD_RECV, false, state->handle, "%s",
1273 fsp_str_do_log(state->fsp));
1274 return -1;
1277 do_log(SMB_VFS_OP_PREAD_RECV, (state->ret >= 0), state->handle, "%s",
1278 fsp_str_do_log(state->fsp));
1280 *vfs_aio_state = state->vfs_aio_state;
1281 return state->ret;
1284 static ssize_t smb_full_audit_pwrite(vfs_handle_struct *handle, files_struct *fsp,
1285 const void *data, size_t n,
1286 off_t offset)
1288 ssize_t result;
1290 result = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
1292 do_log(SMB_VFS_OP_PWRITE, (result >= 0), handle, "%s",
1293 fsp_str_do_log(fsp));
1295 return result;
1298 struct smb_full_audit_pwrite_state {
1299 vfs_handle_struct *handle;
1300 files_struct *fsp;
1301 ssize_t ret;
1302 struct vfs_aio_state vfs_aio_state;
1305 static void smb_full_audit_pwrite_done(struct tevent_req *subreq);
1307 static struct tevent_req *smb_full_audit_pwrite_send(
1308 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1309 struct tevent_context *ev, struct files_struct *fsp,
1310 const void *data, size_t n, off_t offset)
1312 struct tevent_req *req, *subreq;
1313 struct smb_full_audit_pwrite_state *state;
1315 req = tevent_req_create(mem_ctx, &state,
1316 struct smb_full_audit_pwrite_state);
1317 if (req == NULL) {
1318 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1319 fsp_str_do_log(fsp));
1320 return NULL;
1322 state->handle = handle;
1323 state->fsp = fsp;
1325 subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
1326 n, offset);
1327 if (tevent_req_nomem(subreq, req)) {
1328 do_log(SMB_VFS_OP_PWRITE_SEND, false, handle, "%s",
1329 fsp_str_do_log(fsp));
1330 return tevent_req_post(req, ev);
1332 tevent_req_set_callback(subreq, smb_full_audit_pwrite_done, req);
1334 do_log(SMB_VFS_OP_PWRITE_SEND, true, handle, "%s",
1335 fsp_str_do_log(fsp));
1336 return req;
1339 static void smb_full_audit_pwrite_done(struct tevent_req *subreq)
1341 struct tevent_req *req = tevent_req_callback_data(
1342 subreq, struct tevent_req);
1343 struct smb_full_audit_pwrite_state *state = tevent_req_data(
1344 req, struct smb_full_audit_pwrite_state);
1346 state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->vfs_aio_state);
1347 TALLOC_FREE(subreq);
1348 tevent_req_done(req);
1351 static ssize_t smb_full_audit_pwrite_recv(struct tevent_req *req,
1352 struct vfs_aio_state *vfs_aio_state)
1354 struct smb_full_audit_pwrite_state *state = tevent_req_data(
1355 req, struct smb_full_audit_pwrite_state);
1357 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1358 do_log(SMB_VFS_OP_PWRITE_RECV, false, state->handle, "%s",
1359 fsp_str_do_log(state->fsp));
1360 return -1;
1363 do_log(SMB_VFS_OP_PWRITE_RECV, (state->ret >= 0), state->handle, "%s",
1364 fsp_str_do_log(state->fsp));
1366 *vfs_aio_state = state->vfs_aio_state;
1367 return state->ret;
1370 static off_t smb_full_audit_lseek(vfs_handle_struct *handle, files_struct *fsp,
1371 off_t offset, int whence)
1373 ssize_t result;
1375 result = SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence);
1377 do_log(SMB_VFS_OP_LSEEK, (result != (ssize_t)-1), handle,
1378 "%s", fsp_str_do_log(fsp));
1380 return result;
1383 static ssize_t smb_full_audit_sendfile(vfs_handle_struct *handle, int tofd,
1384 files_struct *fromfsp,
1385 const DATA_BLOB *hdr, off_t offset,
1386 size_t n)
1388 ssize_t result;
1390 result = SMB_VFS_NEXT_SENDFILE(handle, tofd, fromfsp, hdr, offset, n);
1392 do_log(SMB_VFS_OP_SENDFILE, (result >= 0), handle,
1393 "%s", fsp_str_do_log(fromfsp));
1395 return result;
1398 static ssize_t smb_full_audit_recvfile(vfs_handle_struct *handle, int fromfd,
1399 files_struct *tofsp,
1400 off_t offset,
1401 size_t n)
1403 ssize_t result;
1405 result = SMB_VFS_NEXT_RECVFILE(handle, fromfd, tofsp, offset, n);
1407 do_log(SMB_VFS_OP_RECVFILE, (result >= 0), handle,
1408 "%s", fsp_str_do_log(tofsp));
1410 return result;
1413 static int smb_full_audit_renameat(vfs_handle_struct *handle,
1414 files_struct *srcfsp,
1415 const struct smb_filename *smb_fname_src,
1416 files_struct *dstfsp,
1417 const struct smb_filename *smb_fname_dst)
1419 int result;
1421 result = SMB_VFS_NEXT_RENAMEAT(handle,
1422 srcfsp,
1423 smb_fname_src,
1424 dstfsp,
1425 smb_fname_dst);
1427 do_log(SMB_VFS_OP_RENAMEAT, (result >= 0), handle, "%s|%s",
1428 smb_fname_str_do_log(handle->conn, smb_fname_src),
1429 smb_fname_str_do_log(handle->conn, smb_fname_dst));
1431 return result;
1434 struct smb_full_audit_fsync_state {
1435 vfs_handle_struct *handle;
1436 files_struct *fsp;
1437 int ret;
1438 struct vfs_aio_state vfs_aio_state;
1441 static void smb_full_audit_fsync_done(struct tevent_req *subreq);
1443 static struct tevent_req *smb_full_audit_fsync_send(
1444 struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
1445 struct tevent_context *ev, struct files_struct *fsp)
1447 struct tevent_req *req, *subreq;
1448 struct smb_full_audit_fsync_state *state;
1450 req = tevent_req_create(mem_ctx, &state,
1451 struct smb_full_audit_fsync_state);
1452 if (req == NULL) {
1453 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1454 fsp_str_do_log(fsp));
1455 return NULL;
1457 state->handle = handle;
1458 state->fsp = fsp;
1460 subreq = SMB_VFS_NEXT_FSYNC_SEND(state, ev, handle, fsp);
1461 if (tevent_req_nomem(subreq, req)) {
1462 do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
1463 fsp_str_do_log(fsp));
1464 return tevent_req_post(req, ev);
1466 tevent_req_set_callback(subreq, smb_full_audit_fsync_done, req);
1468 do_log(SMB_VFS_OP_FSYNC_SEND, true, handle, "%s", fsp_str_do_log(fsp));
1469 return req;
1472 static void smb_full_audit_fsync_done(struct tevent_req *subreq)
1474 struct tevent_req *req = tevent_req_callback_data(
1475 subreq, struct tevent_req);
1476 struct smb_full_audit_fsync_state *state = tevent_req_data(
1477 req, struct smb_full_audit_fsync_state);
1479 state->ret = SMB_VFS_FSYNC_RECV(subreq, &state->vfs_aio_state);
1480 TALLOC_FREE(subreq);
1481 tevent_req_done(req);
1484 static int smb_full_audit_fsync_recv(struct tevent_req *req,
1485 struct vfs_aio_state *vfs_aio_state)
1487 struct smb_full_audit_fsync_state *state = tevent_req_data(
1488 req, struct smb_full_audit_fsync_state);
1490 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1491 do_log(SMB_VFS_OP_FSYNC_RECV, false, state->handle, "%s",
1492 fsp_str_do_log(state->fsp));
1493 return -1;
1496 do_log(SMB_VFS_OP_FSYNC_RECV, (state->ret >= 0), state->handle, "%s",
1497 fsp_str_do_log(state->fsp));
1499 *vfs_aio_state = state->vfs_aio_state;
1500 return state->ret;
1503 static int smb_full_audit_stat(vfs_handle_struct *handle,
1504 struct smb_filename *smb_fname)
1506 int result;
1508 result = SMB_VFS_NEXT_STAT(handle, smb_fname);
1510 do_log(SMB_VFS_OP_STAT, (result >= 0), handle, "%s",
1511 smb_fname_str_do_log(handle->conn, smb_fname));
1513 return result;
1516 static int smb_full_audit_fstat(vfs_handle_struct *handle, files_struct *fsp,
1517 SMB_STRUCT_STAT *sbuf)
1519 int result;
1521 result = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1523 do_log(SMB_VFS_OP_FSTAT, (result >= 0), handle, "%s",
1524 fsp_str_do_log(fsp));
1526 return result;
1529 static int smb_full_audit_lstat(vfs_handle_struct *handle,
1530 struct smb_filename *smb_fname)
1532 int result;
1534 result = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
1536 do_log(SMB_VFS_OP_LSTAT, (result >= 0), handle, "%s",
1537 smb_fname_str_do_log(handle->conn, smb_fname));
1539 return result;
1542 static uint64_t smb_full_audit_get_alloc_size(vfs_handle_struct *handle,
1543 files_struct *fsp, const SMB_STRUCT_STAT *sbuf)
1545 uint64_t result;
1547 result = SMB_VFS_NEXT_GET_ALLOC_SIZE(handle, fsp, sbuf);
1549 do_log(SMB_VFS_OP_GET_ALLOC_SIZE, (result != (uint64_t)-1), handle,
1550 "%llu", (unsigned long long)result);
1552 return result;
1555 static int smb_full_audit_unlinkat(vfs_handle_struct *handle,
1556 struct files_struct *dirfsp,
1557 const struct smb_filename *smb_fname,
1558 int flags)
1560 int result;
1562 result = SMB_VFS_NEXT_UNLINKAT(handle,
1563 dirfsp,
1564 smb_fname,
1565 flags);
1567 do_log(SMB_VFS_OP_UNLINKAT, (result >= 0), handle, "%s",
1568 smb_fname_str_do_log(handle->conn, smb_fname));
1570 return result;
1573 static int smb_full_audit_chmod(vfs_handle_struct *handle,
1574 const struct smb_filename *smb_fname,
1575 mode_t mode)
1577 int result;
1579 result = SMB_VFS_NEXT_CHMOD(handle, smb_fname, mode);
1581 do_log(SMB_VFS_OP_CHMOD,
1582 (result >= 0),
1583 handle,
1584 "%s|%o",
1585 smb_fname_str_do_log(handle->conn, smb_fname),
1586 mode);
1588 return result;
1591 static int smb_full_audit_fchmod(vfs_handle_struct *handle, files_struct *fsp,
1592 mode_t mode)
1594 int result;
1596 result = SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1598 do_log(SMB_VFS_OP_FCHMOD, (result >= 0), handle,
1599 "%s|%o", fsp_str_do_log(fsp), mode);
1601 return result;
1604 static int smb_full_audit_fchown(vfs_handle_struct *handle, files_struct *fsp,
1605 uid_t uid, gid_t gid)
1607 int result;
1609 result = SMB_VFS_NEXT_FCHOWN(handle, fsp, uid, gid);
1611 do_log(SMB_VFS_OP_FCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1612 fsp_str_do_log(fsp), (long int)uid, (long int)gid);
1614 return result;
1617 static int smb_full_audit_lchown(vfs_handle_struct *handle,
1618 const struct smb_filename *smb_fname,
1619 uid_t uid,
1620 gid_t gid)
1622 int result;
1624 result = SMB_VFS_NEXT_LCHOWN(handle, smb_fname, uid, gid);
1626 do_log(SMB_VFS_OP_LCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1627 smb_fname->base_name, (long int)uid, (long int)gid);
1629 return result;
1632 static int smb_full_audit_chdir(vfs_handle_struct *handle,
1633 const struct smb_filename *smb_fname)
1635 int result;
1637 result = SMB_VFS_NEXT_CHDIR(handle, smb_fname);
1639 do_log(SMB_VFS_OP_CHDIR,
1640 (result >= 0),
1641 handle,
1642 "chdir|%s",
1643 smb_fname_str_do_log(handle->conn, smb_fname));
1645 return result;
1648 static struct smb_filename *smb_full_audit_getwd(vfs_handle_struct *handle,
1649 TALLOC_CTX *ctx)
1651 struct smb_filename *result;
1653 result = SMB_VFS_NEXT_GETWD(handle, ctx);
1655 do_log(SMB_VFS_OP_GETWD, (result != NULL), handle, "%s",
1656 result == NULL? "" : result->base_name);
1658 return result;
1661 static int smb_full_audit_ntimes(vfs_handle_struct *handle,
1662 const struct smb_filename *smb_fname,
1663 struct smb_file_time *ft)
1665 int result;
1666 time_t create_time = convert_timespec_to_time_t(ft->create_time);
1667 time_t atime = convert_timespec_to_time_t(ft->atime);
1668 time_t mtime = convert_timespec_to_time_t(ft->mtime);
1669 time_t ctime = convert_timespec_to_time_t(ft->ctime);
1670 const char *create_time_str = "";
1671 const char *atime_str = "";
1672 const char *mtime_str = "";
1673 const char *ctime_str = "";
1674 TALLOC_CTX *frame = talloc_stackframe();
1676 result = SMB_VFS_NEXT_NTIMES(handle, smb_fname, ft);
1678 if (create_time > 0) {
1679 create_time_str = timestring(frame, create_time);
1681 if (atime > 0) {
1682 atime_str = timestring(frame, atime);
1684 if (mtime > 0) {
1685 mtime_str = timestring(frame, mtime);
1687 if (ctime > 0) {
1688 ctime_str = timestring(frame, ctime);
1691 do_log(SMB_VFS_OP_NTIMES,
1692 (result >= 0),
1693 handle,
1694 "%s|%s|%s|%s|%s",
1695 smb_fname_str_do_log(handle->conn, smb_fname),
1696 create_time_str,
1697 atime_str,
1698 mtime_str,
1699 ctime_str);
1701 TALLOC_FREE(frame);
1703 return result;
1706 static int smb_full_audit_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
1707 off_t len)
1709 int result;
1711 result = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1713 do_log(SMB_VFS_OP_FTRUNCATE, (result >= 0), handle,
1714 "%s", fsp_str_do_log(fsp));
1716 return result;
1719 static int smb_full_audit_fallocate(vfs_handle_struct *handle, files_struct *fsp,
1720 uint32_t mode,
1721 off_t offset,
1722 off_t len)
1724 int result;
1726 result = SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
1728 do_log(SMB_VFS_OP_FALLOCATE, (result >= 0), handle,
1729 "%s", fsp_str_do_log(fsp));
1731 return result;
1734 static bool smb_full_audit_lock(vfs_handle_struct *handle, files_struct *fsp,
1735 int op, off_t offset, off_t count, int type)
1737 bool result;
1739 result = SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type);
1741 do_log(SMB_VFS_OP_LOCK, result, handle, "%s", fsp_str_do_log(fsp));
1743 return result;
1746 static int smb_full_audit_kernel_flock(struct vfs_handle_struct *handle,
1747 struct files_struct *fsp,
1748 uint32_t share_access,
1749 uint32_t access_mask)
1751 int result;
1753 result = SMB_VFS_NEXT_KERNEL_FLOCK(handle,
1754 fsp,
1755 share_access,
1756 access_mask);
1758 do_log(SMB_VFS_OP_KERNEL_FLOCK, (result >= 0), handle, "%s",
1759 fsp_str_do_log(fsp));
1761 return result;
1764 static int smb_full_audit_fcntl(struct vfs_handle_struct *handle,
1765 struct files_struct *fsp,
1766 int cmd, va_list cmd_arg)
1768 void *arg;
1769 va_list dup_cmd_arg;
1770 int result;
1772 va_copy(dup_cmd_arg, cmd_arg);
1773 arg = va_arg(dup_cmd_arg, void *);
1774 result = SMB_VFS_NEXT_FCNTL(handle, fsp, cmd, arg);
1775 va_end(dup_cmd_arg);
1777 do_log(SMB_VFS_OP_FCNTL, (result >= 0), handle, "%s",
1778 fsp_str_do_log(fsp));
1780 return result;
1783 static int smb_full_audit_linux_setlease(vfs_handle_struct *handle, files_struct *fsp,
1784 int leasetype)
1786 int result;
1788 result = SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
1790 do_log(SMB_VFS_OP_LINUX_SETLEASE, (result >= 0), handle, "%s",
1791 fsp_str_do_log(fsp));
1793 return result;
1796 static bool smb_full_audit_getlock(vfs_handle_struct *handle, files_struct *fsp,
1797 off_t *poffset, off_t *pcount, int *ptype, pid_t *ppid)
1799 bool result;
1801 result = SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype, ppid);
1803 do_log(SMB_VFS_OP_GETLOCK, result, handle, "%s", fsp_str_do_log(fsp));
1805 return result;
1808 static int smb_full_audit_symlinkat(vfs_handle_struct *handle,
1809 const char *link_contents,
1810 struct files_struct *dirfsp,
1811 const struct smb_filename *new_smb_fname)
1813 int result;
1815 result = SMB_VFS_NEXT_SYMLINKAT(handle,
1816 link_contents,
1817 dirfsp,
1818 new_smb_fname);
1820 do_log(SMB_VFS_OP_SYMLINKAT,
1821 (result >= 0),
1822 handle,
1823 "%s|%s",
1824 link_contents,
1825 smb_fname_str_do_log(handle->conn, new_smb_fname));
1827 return result;
1830 static int smb_full_audit_readlinkat(vfs_handle_struct *handle,
1831 files_struct *dirfsp,
1832 const struct smb_filename *smb_fname,
1833 char *buf,
1834 size_t bufsiz)
1836 int result;
1838 result = SMB_VFS_NEXT_READLINKAT(handle,
1839 dirfsp,
1840 smb_fname,
1841 buf,
1842 bufsiz);
1844 do_log(SMB_VFS_OP_READLINKAT,
1845 (result >= 0),
1846 handle,
1847 "%s",
1848 smb_fname_str_do_log(handle->conn, smb_fname));
1850 return result;
1853 static int smb_full_audit_linkat(vfs_handle_struct *handle,
1854 files_struct *srcfsp,
1855 const struct smb_filename *old_smb_fname,
1856 files_struct *dstfsp,
1857 const struct smb_filename *new_smb_fname,
1858 int flags)
1860 int result;
1862 result = SMB_VFS_NEXT_LINKAT(handle,
1863 srcfsp,
1864 old_smb_fname,
1865 dstfsp,
1866 new_smb_fname,
1867 flags);
1869 do_log(SMB_VFS_OP_LINKAT,
1870 (result >= 0),
1871 handle,
1872 "%s|%s",
1873 smb_fname_str_do_log(handle->conn, old_smb_fname),
1874 smb_fname_str_do_log(handle->conn, new_smb_fname));
1876 return result;
1879 static int smb_full_audit_mknodat(vfs_handle_struct *handle,
1880 files_struct *dirfsp,
1881 const struct smb_filename *smb_fname,
1882 mode_t mode,
1883 SMB_DEV_T dev)
1885 int result;
1887 result = SMB_VFS_NEXT_MKNODAT(handle,
1888 dirfsp,
1889 smb_fname,
1890 mode,
1891 dev);
1893 do_log(SMB_VFS_OP_MKNODAT,
1894 (result >= 0),
1895 handle,
1896 "%s",
1897 smb_fname_str_do_log(handle->conn, smb_fname));
1899 return result;
1902 static struct smb_filename *smb_full_audit_realpath(vfs_handle_struct *handle,
1903 TALLOC_CTX *ctx,
1904 const struct smb_filename *smb_fname)
1906 struct smb_filename *result_fname = NULL;
1908 result_fname = SMB_VFS_NEXT_REALPATH(handle, ctx, smb_fname);
1910 do_log(SMB_VFS_OP_REALPATH,
1911 (result_fname != NULL),
1912 handle,
1913 "%s",
1914 smb_fname_str_do_log(handle->conn, smb_fname));
1916 return result_fname;
1919 static int smb_full_audit_chflags(vfs_handle_struct *handle,
1920 const struct smb_filename *smb_fname,
1921 unsigned int flags)
1923 int result;
1925 result = SMB_VFS_NEXT_CHFLAGS(handle, smb_fname, flags);
1927 do_log(SMB_VFS_OP_CHFLAGS,
1928 (result != 0),
1929 handle,
1930 "%s",
1931 smb_fname_str_do_log(handle->conn, smb_fname));
1933 return result;
1936 static struct file_id smb_full_audit_file_id_create(struct vfs_handle_struct *handle,
1937 const SMB_STRUCT_STAT *sbuf)
1939 struct file_id id_zero = { 0 };
1940 struct file_id result;
1941 struct file_id_buf idbuf;
1943 result = SMB_VFS_NEXT_FILE_ID_CREATE(handle, sbuf);
1945 do_log(SMB_VFS_OP_FILE_ID_CREATE,
1946 !file_id_equal(&id_zero, &result),
1947 handle,
1948 "%s",
1949 file_id_str_buf(result, &idbuf));
1951 return result;
1954 static uint64_t smb_full_audit_fs_file_id(struct vfs_handle_struct *handle,
1955 const SMB_STRUCT_STAT *sbuf)
1957 uint64_t result;
1959 result = SMB_VFS_NEXT_FS_FILE_ID(handle, sbuf);
1961 do_log(SMB_VFS_OP_FS_FILE_ID,
1962 result != 0,
1963 handle, "%" PRIu64, result);
1965 return result;
1968 static NTSTATUS smb_full_audit_streaminfo(vfs_handle_struct *handle,
1969 struct files_struct *fsp,
1970 const struct smb_filename *smb_fname,
1971 TALLOC_CTX *mem_ctx,
1972 unsigned int *pnum_streams,
1973 struct stream_struct **pstreams)
1975 NTSTATUS result;
1977 result = SMB_VFS_NEXT_STREAMINFO(handle, fsp, smb_fname, mem_ctx,
1978 pnum_streams, pstreams);
1980 do_log(SMB_VFS_OP_STREAMINFO,
1981 NT_STATUS_IS_OK(result),
1982 handle,
1983 "%s",
1984 smb_fname_str_do_log(handle->conn, smb_fname));
1986 return result;
1989 static int smb_full_audit_get_real_filename(struct vfs_handle_struct *handle,
1990 const char *path,
1991 const char *name,
1992 TALLOC_CTX *mem_ctx,
1993 char **found_name)
1995 int result;
1997 result = SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name, mem_ctx,
1998 found_name);
2000 do_log(SMB_VFS_OP_GET_REAL_FILENAME, (result == 0), handle,
2001 "%s/%s->%s", path, name, (result == 0) ? *found_name : "");
2003 return result;
2006 static const char *smb_full_audit_connectpath(vfs_handle_struct *handle,
2007 const struct smb_filename *smb_fname)
2009 const char *result;
2011 result = SMB_VFS_NEXT_CONNECTPATH(handle, smb_fname);
2013 do_log(SMB_VFS_OP_CONNECTPATH,
2014 result != NULL,
2015 handle,
2016 "%s",
2017 smb_fname_str_do_log(handle->conn, smb_fname));
2019 return result;
2022 static NTSTATUS smb_full_audit_brl_lock_windows(struct vfs_handle_struct *handle,
2023 struct byte_range_lock *br_lck,
2024 struct lock_struct *plock)
2026 NTSTATUS result;
2028 result = SMB_VFS_NEXT_BRL_LOCK_WINDOWS(handle, br_lck, plock);
2030 do_log(SMB_VFS_OP_BRL_LOCK_WINDOWS, NT_STATUS_IS_OK(result), handle,
2031 "%s:%llu-%llu. type=%d.",
2032 fsp_str_do_log(brl_fsp(br_lck)),
2033 (unsigned long long)plock->start,
2034 (unsigned long long)plock->size,
2035 plock->lock_type);
2037 return result;
2040 static bool smb_full_audit_brl_unlock_windows(struct vfs_handle_struct *handle,
2041 struct byte_range_lock *br_lck,
2042 const struct lock_struct *plock)
2044 bool result;
2046 result = SMB_VFS_NEXT_BRL_UNLOCK_WINDOWS(handle, br_lck, plock);
2048 do_log(SMB_VFS_OP_BRL_UNLOCK_WINDOWS, (result == 0), handle,
2049 "%s:%llu-%llu:%d", fsp_str_do_log(brl_fsp(br_lck)),
2050 (unsigned long long)plock->start,
2051 (unsigned long long)plock->size,
2052 plock->lock_type);
2054 return result;
2057 static bool smb_full_audit_strict_lock_check(struct vfs_handle_struct *handle,
2058 struct files_struct *fsp,
2059 struct lock_struct *plock)
2061 bool result;
2063 result = SMB_VFS_NEXT_STRICT_LOCK_CHECK(handle, fsp, plock);
2065 do_log(SMB_VFS_OP_STRICT_LOCK_CHECK, result, handle,
2066 "%s:%llu-%llu:%d", fsp_str_do_log(fsp),
2067 (unsigned long long)plock->start,
2068 (unsigned long long)plock->size,
2069 plock->lock_type);
2071 return result;
2074 static NTSTATUS smb_full_audit_translate_name(struct vfs_handle_struct *handle,
2075 const char *name,
2076 enum vfs_translate_direction direction,
2077 TALLOC_CTX *mem_ctx,
2078 char **mapped_name)
2080 NTSTATUS result;
2082 result = SMB_VFS_NEXT_TRANSLATE_NAME(handle, name, direction, mem_ctx,
2083 mapped_name);
2085 do_log(SMB_VFS_OP_TRANSLATE_NAME, NT_STATUS_IS_OK(result), handle, "");
2087 return result;
2090 static NTSTATUS smb_full_audit_fsctl(struct vfs_handle_struct *handle,
2091 struct files_struct *fsp,
2092 TALLOC_CTX *ctx,
2093 uint32_t function,
2094 uint16_t req_flags,
2095 const uint8_t *_in_data,
2096 uint32_t in_len,
2097 uint8_t **_out_data,
2098 uint32_t max_out_len,
2099 uint32_t *out_len)
2101 NTSTATUS result;
2103 result = SMB_VFS_NEXT_FSCTL(handle,
2104 fsp,
2105 ctx,
2106 function,
2107 req_flags,
2108 _in_data,
2109 in_len,
2110 _out_data,
2111 max_out_len,
2112 out_len);
2114 do_log(SMB_VFS_OP_FSCTL, NT_STATUS_IS_OK(result), handle, "");
2116 return result;
2119 static struct tevent_req *smb_full_audit_offload_read_send(
2120 TALLOC_CTX *mem_ctx,
2121 struct tevent_context *ev,
2122 struct vfs_handle_struct *handle,
2123 struct files_struct *fsp,
2124 uint32_t fsctl,
2125 uint32_t ttl,
2126 off_t offset,
2127 size_t to_copy)
2129 struct tevent_req *req = NULL;
2131 req = SMB_VFS_NEXT_OFFLOAD_READ_SEND(mem_ctx, ev, handle, fsp,
2132 fsctl, ttl, offset, to_copy);
2134 do_log(SMB_VFS_OP_OFFLOAD_READ_SEND, req, handle, "");
2136 return req;
2139 static NTSTATUS smb_full_audit_offload_read_recv(
2140 struct tevent_req *req,
2141 struct vfs_handle_struct *handle,
2142 TALLOC_CTX *mem_ctx,
2143 DATA_BLOB *_token_blob)
2145 NTSTATUS status;
2147 status = SMB_VFS_NEXT_OFFLOAD_READ_RECV(req, handle, mem_ctx,
2148 _token_blob);
2150 do_log(SMB_VFS_OP_OFFLOAD_READ_RECV, NT_STATUS_IS_OK(status), handle, "");
2152 return status;
2155 static struct tevent_req *smb_full_audit_offload_write_send(struct vfs_handle_struct *handle,
2156 TALLOC_CTX *mem_ctx,
2157 struct tevent_context *ev,
2158 uint32_t fsctl,
2159 DATA_BLOB *token,
2160 off_t transfer_offset,
2161 struct files_struct *dest_fsp,
2162 off_t dest_off,
2163 off_t num)
2165 struct tevent_req *req;
2167 req = SMB_VFS_NEXT_OFFLOAD_WRITE_SEND(handle, mem_ctx, ev,
2168 fsctl, token, transfer_offset,
2169 dest_fsp, dest_off, num);
2171 do_log(SMB_VFS_OP_OFFLOAD_WRITE_SEND, req, handle, "");
2173 return req;
2176 static NTSTATUS smb_full_audit_offload_write_recv(struct vfs_handle_struct *handle,
2177 struct tevent_req *req,
2178 off_t *copied)
2180 NTSTATUS result;
2182 result = SMB_VFS_NEXT_OFFLOAD_WRITE_RECV(handle, req, copied);
2184 do_log(SMB_VFS_OP_OFFLOAD_WRITE_RECV, NT_STATUS_IS_OK(result), handle, "");
2186 return result;
2189 static NTSTATUS smb_full_audit_get_compression(vfs_handle_struct *handle,
2190 TALLOC_CTX *mem_ctx,
2191 struct files_struct *fsp,
2192 struct smb_filename *smb_fname,
2193 uint16_t *_compression_fmt)
2195 NTSTATUS result;
2197 result = SMB_VFS_NEXT_GET_COMPRESSION(handle, mem_ctx, fsp, smb_fname,
2198 _compression_fmt);
2200 do_log(SMB_VFS_OP_GET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
2201 "%s",
2202 (fsp ? fsp_str_do_log(fsp) :
2203 smb_fname_str_do_log(handle->conn, smb_fname)));
2205 return result;
2208 static NTSTATUS smb_full_audit_set_compression(vfs_handle_struct *handle,
2209 TALLOC_CTX *mem_ctx,
2210 struct files_struct *fsp,
2211 uint16_t compression_fmt)
2213 NTSTATUS result;
2215 result = SMB_VFS_NEXT_SET_COMPRESSION(handle, mem_ctx, fsp,
2216 compression_fmt);
2218 do_log(SMB_VFS_OP_SET_COMPRESSION, NT_STATUS_IS_OK(result), handle,
2219 "%s", fsp_str_do_log(fsp));
2221 return result;
2224 static NTSTATUS smb_full_audit_readdir_attr(struct vfs_handle_struct *handle,
2225 const struct smb_filename *fname,
2226 TALLOC_CTX *mem_ctx,
2227 struct readdir_attr_data **pattr_data)
2229 NTSTATUS status;
2231 status = SMB_VFS_NEXT_READDIR_ATTR(handle, fname, mem_ctx, pattr_data);
2233 do_log(SMB_VFS_OP_READDIR_ATTR, NT_STATUS_IS_OK(status), handle, "%s",
2234 smb_fname_str_do_log(handle->conn, fname));
2236 return status;
2239 static NTSTATUS smb_full_audit_get_dos_attributes(
2240 struct vfs_handle_struct *handle,
2241 struct smb_filename *smb_fname,
2242 uint32_t *dosmode)
2244 NTSTATUS status;
2246 status = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES(handle,
2247 smb_fname,
2248 dosmode);
2250 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES,
2251 NT_STATUS_IS_OK(status),
2252 handle,
2253 "%s",
2254 smb_fname_str_do_log(handle->conn, smb_fname));
2256 return status;
2259 struct smb_full_audit_get_dos_attributes_state {
2260 struct vfs_aio_state aio_state;
2261 vfs_handle_struct *handle;
2262 files_struct *dir_fsp;
2263 const struct smb_filename *smb_fname;
2264 uint32_t dosmode;
2267 static void smb_full_audit_get_dos_attributes_done(struct tevent_req *subreq);
2269 static struct tevent_req *smb_full_audit_get_dos_attributes_send(
2270 TALLOC_CTX *mem_ctx,
2271 struct tevent_context *ev,
2272 struct vfs_handle_struct *handle,
2273 files_struct *dir_fsp,
2274 struct smb_filename *smb_fname)
2276 struct tevent_req *req = NULL;
2277 struct smb_full_audit_get_dos_attributes_state *state = NULL;
2278 struct tevent_req *subreq = NULL;
2280 req = tevent_req_create(mem_ctx, &state,
2281 struct smb_full_audit_get_dos_attributes_state);
2282 if (req == NULL) {
2283 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2284 false,
2285 handle,
2286 "%s/%s",
2287 fsp_str_do_log(dir_fsp),
2288 smb_fname->base_name);
2289 return NULL;
2291 *state = (struct smb_full_audit_get_dos_attributes_state) {
2292 .handle = handle,
2293 .dir_fsp = dir_fsp,
2294 .smb_fname = smb_fname,
2297 subreq = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES_SEND(mem_ctx,
2299 handle,
2300 dir_fsp,
2301 smb_fname);
2302 if (tevent_req_nomem(subreq, req)) {
2303 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2304 false,
2305 handle,
2306 "%s/%s",
2307 fsp_str_do_log(dir_fsp),
2308 smb_fname->base_name);
2309 return tevent_req_post(req, ev);
2311 tevent_req_set_callback(subreq,
2312 smb_full_audit_get_dos_attributes_done,
2313 req);
2315 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_SEND,
2316 true,
2317 handle,
2318 "%s/%s",
2319 fsp_str_do_log(dir_fsp),
2320 smb_fname->base_name);
2322 return req;
2325 static void smb_full_audit_get_dos_attributes_done(struct tevent_req *subreq)
2327 struct tevent_req *req =
2328 tevent_req_callback_data(subreq,
2329 struct tevent_req);
2330 struct smb_full_audit_get_dos_attributes_state *state =
2331 tevent_req_data(req,
2332 struct smb_full_audit_get_dos_attributes_state);
2333 NTSTATUS status;
2335 status = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES_RECV(subreq,
2336 &state->aio_state,
2337 &state->dosmode);
2338 TALLOC_FREE(subreq);
2339 if (tevent_req_nterror(req, status)) {
2340 return;
2343 tevent_req_done(req);
2344 return;
2347 static NTSTATUS smb_full_audit_get_dos_attributes_recv(struct tevent_req *req,
2348 struct vfs_aio_state *aio_state,
2349 uint32_t *dosmode)
2351 struct smb_full_audit_get_dos_attributes_state *state =
2352 tevent_req_data(req,
2353 struct smb_full_audit_get_dos_attributes_state);
2354 NTSTATUS status;
2356 if (tevent_req_is_nterror(req, &status)) {
2357 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV,
2358 false,
2359 state->handle,
2360 "%s/%s",
2361 fsp_str_do_log(state->dir_fsp),
2362 state->smb_fname->base_name);
2363 tevent_req_received(req);
2364 return status;
2367 do_log(SMB_VFS_OP_GET_DOS_ATTRIBUTES_RECV,
2368 true,
2369 state->handle,
2370 "%s/%s",
2371 fsp_str_do_log(state->dir_fsp),
2372 state->smb_fname->base_name);
2374 *aio_state = state->aio_state;
2375 *dosmode = state->dosmode;
2376 tevent_req_received(req);
2377 return NT_STATUS_OK;
2380 static NTSTATUS smb_full_audit_fget_dos_attributes(
2381 struct vfs_handle_struct *handle,
2382 struct files_struct *fsp,
2383 uint32_t *dosmode)
2385 NTSTATUS status;
2387 status = SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle,
2388 fsp,
2389 dosmode);
2391 do_log(SMB_VFS_OP_FGET_DOS_ATTRIBUTES,
2392 NT_STATUS_IS_OK(status),
2393 handle,
2394 "%s",
2395 fsp_str_do_log(fsp));
2397 return status;
2400 static NTSTATUS smb_full_audit_set_dos_attributes(
2401 struct vfs_handle_struct *handle,
2402 const struct smb_filename *smb_fname,
2403 uint32_t dosmode)
2405 NTSTATUS status;
2407 status = SMB_VFS_NEXT_SET_DOS_ATTRIBUTES(handle,
2408 smb_fname,
2409 dosmode);
2411 do_log(SMB_VFS_OP_SET_DOS_ATTRIBUTES,
2412 NT_STATUS_IS_OK(status),
2413 handle,
2414 "%s",
2415 smb_fname_str_do_log(handle->conn, smb_fname));
2417 return status;
2420 static NTSTATUS smb_full_audit_fset_dos_attributes(
2421 struct vfs_handle_struct *handle,
2422 struct files_struct *fsp,
2423 uint32_t dosmode)
2425 NTSTATUS status;
2427 status = SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle,
2428 fsp,
2429 dosmode);
2431 do_log(SMB_VFS_OP_FSET_DOS_ATTRIBUTES,
2432 NT_STATUS_IS_OK(status),
2433 handle,
2434 "%s",
2435 fsp_str_do_log(fsp));
2437 return status;
2440 static NTSTATUS smb_full_audit_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
2441 uint32_t security_info,
2442 TALLOC_CTX *mem_ctx,
2443 struct security_descriptor **ppdesc)
2445 NTSTATUS result;
2447 result = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
2448 mem_ctx, ppdesc);
2450 do_log(SMB_VFS_OP_FGET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2451 "%s", fsp_str_do_log(fsp));
2453 return result;
2456 static NTSTATUS smb_full_audit_get_nt_acl(vfs_handle_struct *handle,
2457 const struct smb_filename *smb_fname,
2458 uint32_t security_info,
2459 TALLOC_CTX *mem_ctx,
2460 struct security_descriptor **ppdesc)
2462 NTSTATUS result;
2464 result = SMB_VFS_NEXT_GET_NT_ACL(handle, smb_fname, security_info,
2465 mem_ctx, ppdesc);
2467 do_log(SMB_VFS_OP_GET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2468 "%s", smb_fname_str_do_log(handle->conn, smb_fname));
2470 return result;
2473 static NTSTATUS smb_full_audit_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
2474 uint32_t security_info_sent,
2475 const struct security_descriptor *psd)
2477 struct vfs_full_audit_private_data *pd;
2478 NTSTATUS result;
2479 char *sd = NULL;
2481 SMB_VFS_HANDLE_GET_DATA(handle, pd,
2482 struct vfs_full_audit_private_data,
2483 return NT_STATUS_INTERNAL_ERROR);
2485 if (pd->log_secdesc) {
2486 sd = sddl_encode(talloc_tos(), psd, get_global_sam_sid());
2489 result = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
2491 do_log(SMB_VFS_OP_FSET_NT_ACL, NT_STATUS_IS_OK(result), handle,
2492 "%s [%s]", fsp_str_do_log(fsp), sd ? sd : "");
2494 TALLOC_FREE(sd);
2496 return result;
2499 static NTSTATUS smb_full_audit_audit_file(struct vfs_handle_struct *handle,
2500 struct smb_filename *file,
2501 struct security_acl *sacl,
2502 uint32_t access_requested,
2503 uint32_t access_denied)
2505 NTSTATUS result;
2507 result = SMB_VFS_NEXT_AUDIT_FILE(handle,
2508 file,
2509 sacl,
2510 access_requested,
2511 access_denied);
2513 do_log(SMB_VFS_OP_AUDIT_FILE, NT_STATUS_IS_OK(result), handle,
2514 "%s",
2515 smb_fname_str_do_log(handle->conn, file));
2517 return result;
2520 static SMB_ACL_T smb_full_audit_sys_acl_get_file(vfs_handle_struct *handle,
2521 const struct smb_filename *smb_fname,
2522 SMB_ACL_TYPE_T type,
2523 TALLOC_CTX *mem_ctx)
2525 SMB_ACL_T result;
2527 result = SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, smb_fname,
2528 type, mem_ctx);
2530 do_log(SMB_VFS_OP_SYS_ACL_GET_FILE,
2531 (result != NULL),
2532 handle,
2533 "%s",
2534 smb_fname_str_do_log(handle->conn, smb_fname));
2536 return result;
2539 static SMB_ACL_T smb_full_audit_sys_acl_get_fd(vfs_handle_struct *handle,
2540 files_struct *fsp, TALLOC_CTX *mem_ctx)
2542 SMB_ACL_T result;
2544 result = SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp, mem_ctx);
2546 do_log(SMB_VFS_OP_SYS_ACL_GET_FD, (result != NULL), handle,
2547 "%s", fsp_str_do_log(fsp));
2549 return result;
2552 static int smb_full_audit_sys_acl_blob_get_file(vfs_handle_struct *handle,
2553 const struct smb_filename *smb_fname,
2554 TALLOC_CTX *mem_ctx,
2555 char **blob_description,
2556 DATA_BLOB *blob)
2558 int result;
2560 result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FILE(handle, smb_fname,
2561 mem_ctx, blob_description, blob);
2563 do_log(SMB_VFS_OP_SYS_ACL_BLOB_GET_FILE,
2564 (result >= 0),
2565 handle,
2566 "%s",
2567 smb_fname_str_do_log(handle->conn, smb_fname));
2569 return result;
2572 static int smb_full_audit_sys_acl_blob_get_fd(vfs_handle_struct *handle,
2573 files_struct *fsp,
2574 TALLOC_CTX *mem_ctx,
2575 char **blob_description,
2576 DATA_BLOB *blob)
2578 int result;
2580 result = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle, fsp, mem_ctx, blob_description, blob);
2582 do_log(SMB_VFS_OP_SYS_ACL_BLOB_GET_FD, (result >= 0), handle,
2583 "%s", fsp_str_do_log(fsp));
2585 return result;
2588 static int smb_full_audit_sys_acl_set_file(vfs_handle_struct *handle,
2589 const struct smb_filename *smb_fname,
2590 SMB_ACL_TYPE_T acltype,
2591 SMB_ACL_T theacl)
2593 int result;
2595 result = SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, smb_fname, acltype,
2596 theacl);
2598 do_log(SMB_VFS_OP_SYS_ACL_SET_FILE,
2599 (result >= 0),
2600 handle,
2601 "%s",
2602 smb_fname_str_do_log(handle->conn, smb_fname));
2604 return result;
2607 static int smb_full_audit_sys_acl_set_fd(vfs_handle_struct *handle, files_struct *fsp,
2608 SMB_ACL_T theacl)
2610 int result;
2612 result = SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, theacl);
2614 do_log(SMB_VFS_OP_SYS_ACL_SET_FD, (result >= 0), handle,
2615 "%s", fsp_str_do_log(fsp));
2617 return result;
2620 static int smb_full_audit_sys_acl_delete_def_file(vfs_handle_struct *handle,
2621 const struct smb_filename *smb_fname)
2623 int result;
2625 result = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, smb_fname);
2627 do_log(SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE,
2628 (result >= 0),
2629 handle,
2630 "%s",
2631 smb_fname_str_do_log(handle->conn, smb_fname));
2633 return result;
2636 static ssize_t smb_full_audit_getxattr(struct vfs_handle_struct *handle,
2637 const struct smb_filename *smb_fname,
2638 const char *name, void *value, size_t size)
2640 ssize_t result;
2642 result = SMB_VFS_NEXT_GETXATTR(handle, smb_fname, name, value, size);
2644 do_log(SMB_VFS_OP_GETXATTR,
2645 (result >= 0),
2646 handle,
2647 "%s|%s",
2648 smb_fname_str_do_log(handle->conn, smb_fname),
2649 name);
2651 return result;
2654 struct smb_full_audit_getxattrat_state {
2655 struct vfs_aio_state aio_state;
2656 vfs_handle_struct *handle;
2657 files_struct *dir_fsp;
2658 const struct smb_filename *smb_fname;
2659 const char *xattr_name;
2660 ssize_t xattr_size;
2661 uint8_t *xattr_value;
2664 static void smb_full_audit_getxattrat_done(struct tevent_req *subreq);
2666 static struct tevent_req *smb_full_audit_getxattrat_send(
2667 TALLOC_CTX *mem_ctx,
2668 struct tevent_context *ev,
2669 struct vfs_handle_struct *handle,
2670 files_struct *dir_fsp,
2671 const struct smb_filename *smb_fname,
2672 const char *xattr_name,
2673 size_t alloc_hint)
2675 struct tevent_req *req = NULL;
2676 struct tevent_req *subreq = NULL;
2677 struct smb_full_audit_getxattrat_state *state = NULL;
2679 req = tevent_req_create(mem_ctx, &state,
2680 struct smb_full_audit_getxattrat_state);
2681 if (req == NULL) {
2682 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2683 false,
2684 handle,
2685 "%s/%s|%s",
2686 fsp_str_do_log(dir_fsp),
2687 smb_fname->base_name,
2688 xattr_name);
2689 return NULL;
2691 *state = (struct smb_full_audit_getxattrat_state) {
2692 .handle = handle,
2693 .dir_fsp = dir_fsp,
2694 .smb_fname = smb_fname,
2695 .xattr_name = xattr_name,
2698 subreq = SMB_VFS_NEXT_GETXATTRAT_SEND(state,
2700 handle,
2701 dir_fsp,
2702 smb_fname,
2703 xattr_name,
2704 alloc_hint);
2705 if (tevent_req_nomem(subreq, req)) {
2706 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2707 false,
2708 handle,
2709 "%s/%s|%s",
2710 fsp_str_do_log(dir_fsp),
2711 smb_fname->base_name,
2712 xattr_name);
2713 return tevent_req_post(req, ev);
2715 tevent_req_set_callback(subreq, smb_full_audit_getxattrat_done, req);
2717 do_log(SMB_VFS_OP_GETXATTRAT_SEND,
2718 true,
2719 handle,
2720 "%s/%s|%s",
2721 fsp_str_do_log(dir_fsp),
2722 smb_fname->base_name,
2723 xattr_name);
2725 return req;
2728 static void smb_full_audit_getxattrat_done(struct tevent_req *subreq)
2730 struct tevent_req *req = tevent_req_callback_data(
2731 subreq, struct tevent_req);
2732 struct smb_full_audit_getxattrat_state *state = tevent_req_data(
2733 req, struct smb_full_audit_getxattrat_state);
2735 state->xattr_size = SMB_VFS_NEXT_GETXATTRAT_RECV(subreq,
2736 &state->aio_state,
2737 state,
2738 &state->xattr_value);
2739 TALLOC_FREE(subreq);
2740 if (state->xattr_size == -1) {
2741 tevent_req_error(req, state->aio_state.error);
2742 return;
2745 tevent_req_done(req);
2748 static ssize_t smb_full_audit_getxattrat_recv(struct tevent_req *req,
2749 struct vfs_aio_state *aio_state,
2750 TALLOC_CTX *mem_ctx,
2751 uint8_t **xattr_value)
2753 struct smb_full_audit_getxattrat_state *state = tevent_req_data(
2754 req, struct smb_full_audit_getxattrat_state);
2755 ssize_t xattr_size;
2757 if (tevent_req_is_unix_error(req, &aio_state->error)) {
2758 do_log(SMB_VFS_OP_GETXATTRAT_RECV,
2759 false,
2760 state->handle,
2761 "%s/%s|%s",
2762 fsp_str_do_log(state->dir_fsp),
2763 state->smb_fname->base_name,
2764 state->xattr_name);
2765 tevent_req_received(req);
2766 return -1;
2769 do_log(SMB_VFS_OP_GETXATTRAT_RECV,
2770 true,
2771 state->handle,
2772 "%s/%s|%s",
2773 fsp_str_do_log(state->dir_fsp),
2774 state->smb_fname->base_name,
2775 state->xattr_name);
2777 *aio_state = state->aio_state;
2778 xattr_size = state->xattr_size;
2779 if (xattr_value != NULL) {
2780 *xattr_value = talloc_move(mem_ctx, &state->xattr_value);
2783 tevent_req_received(req);
2784 return xattr_size;
2787 static ssize_t smb_full_audit_fgetxattr(struct vfs_handle_struct *handle,
2788 struct files_struct *fsp,
2789 const char *name, void *value, size_t size)
2791 ssize_t result;
2793 result = SMB_VFS_NEXT_FGETXATTR(handle, fsp, name, value, size);
2795 do_log(SMB_VFS_OP_FGETXATTR, (result >= 0), handle,
2796 "%s|%s", fsp_str_do_log(fsp), name);
2798 return result;
2801 static ssize_t smb_full_audit_listxattr(struct vfs_handle_struct *handle,
2802 const struct smb_filename *smb_fname,
2803 char *list,
2804 size_t size)
2806 ssize_t result;
2808 result = SMB_VFS_NEXT_LISTXATTR(handle, smb_fname, list, size);
2810 do_log(SMB_VFS_OP_LISTXATTR,
2811 (result >= 0),
2812 handle,
2813 "%s",
2814 smb_fname_str_do_log(handle->conn, smb_fname));
2816 return result;
2819 static ssize_t smb_full_audit_flistxattr(struct vfs_handle_struct *handle,
2820 struct files_struct *fsp, char *list,
2821 size_t size)
2823 ssize_t result;
2825 result = SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
2827 do_log(SMB_VFS_OP_FLISTXATTR, (result >= 0), handle,
2828 "%s", fsp_str_do_log(fsp));
2830 return result;
2833 static int smb_full_audit_removexattr(struct vfs_handle_struct *handle,
2834 const struct smb_filename *smb_fname,
2835 const char *name)
2837 int result;
2839 result = SMB_VFS_NEXT_REMOVEXATTR(handle, smb_fname, name);
2841 do_log(SMB_VFS_OP_REMOVEXATTR,
2842 (result >= 0),
2843 handle,
2844 "%s|%s",
2845 smb_fname_str_do_log(handle->conn, smb_fname),
2846 name);
2848 return result;
2851 static int smb_full_audit_fremovexattr(struct vfs_handle_struct *handle,
2852 struct files_struct *fsp,
2853 const char *name)
2855 int result;
2857 result = SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, name);
2859 do_log(SMB_VFS_OP_FREMOVEXATTR, (result >= 0), handle,
2860 "%s|%s", fsp_str_do_log(fsp), name);
2862 return result;
2865 static int smb_full_audit_setxattr(struct vfs_handle_struct *handle,
2866 const struct smb_filename *smb_fname,
2867 const char *name, const void *value, size_t size,
2868 int flags)
2870 int result;
2872 result = SMB_VFS_NEXT_SETXATTR(handle, smb_fname, name, value, size,
2873 flags);
2875 do_log(SMB_VFS_OP_SETXATTR,
2876 (result >= 0),
2877 handle,
2878 "%s|%s",
2879 smb_fname_str_do_log(handle->conn, smb_fname),
2880 name);
2882 return result;
2885 static int smb_full_audit_fsetxattr(struct vfs_handle_struct *handle,
2886 struct files_struct *fsp, const char *name,
2887 const void *value, size_t size, int flags)
2889 int result;
2891 result = SMB_VFS_NEXT_FSETXATTR(handle, fsp, name, value, size, flags);
2893 do_log(SMB_VFS_OP_FSETXATTR, (result >= 0), handle,
2894 "%s|%s", fsp_str_do_log(fsp), name);
2896 return result;
2899 static bool smb_full_audit_aio_force(struct vfs_handle_struct *handle,
2900 struct files_struct *fsp)
2902 bool result;
2904 result = SMB_VFS_NEXT_AIO_FORCE(handle, fsp);
2905 do_log(SMB_VFS_OP_AIO_FORCE, result, handle,
2906 "%s", fsp_str_do_log(fsp));
2908 return result;
2911 static NTSTATUS smb_full_audit_durable_cookie(struct vfs_handle_struct *handle,
2912 struct files_struct *fsp,
2913 TALLOC_CTX *mem_ctx,
2914 DATA_BLOB *cookie)
2916 NTSTATUS result;
2918 result = SMB_VFS_NEXT_DURABLE_COOKIE(handle,
2919 fsp,
2920 mem_ctx,
2921 cookie);
2923 do_log(SMB_VFS_OP_DURABLE_COOKIE, NT_STATUS_IS_OK(result), handle,
2924 "%s", fsp_str_do_log(fsp));
2926 return result;
2929 static NTSTATUS smb_full_audit_durable_disconnect(
2930 struct vfs_handle_struct *handle,
2931 struct files_struct *fsp,
2932 const DATA_BLOB old_cookie,
2933 TALLOC_CTX *mem_ctx,
2934 DATA_BLOB *new_cookie)
2936 NTSTATUS result;
2938 result = SMB_VFS_NEXT_DURABLE_DISCONNECT(handle,
2939 fsp,
2940 old_cookie,
2941 mem_ctx,
2942 new_cookie);
2944 do_log(SMB_VFS_OP_DURABLE_DISCONNECT, NT_STATUS_IS_OK(result), handle,
2945 "%s", fsp_str_do_log(fsp));
2947 return result;
2950 static NTSTATUS smb_full_audit_durable_reconnect(
2951 struct vfs_handle_struct *handle,
2952 struct smb_request *smb1req,
2953 struct smbXsrv_open *op,
2954 const DATA_BLOB old_cookie,
2955 TALLOC_CTX *mem_ctx,
2956 struct files_struct **fsp,
2957 DATA_BLOB *new_cookie)
2959 NTSTATUS result;
2961 result = SMB_VFS_NEXT_DURABLE_RECONNECT(handle,
2962 smb1req,
2964 old_cookie,
2965 mem_ctx,
2966 fsp,
2967 new_cookie);
2969 do_log(SMB_VFS_OP_DURABLE_RECONNECT,
2970 NT_STATUS_IS_OK(result),
2971 handle,
2972 "");
2974 return result;
2977 static struct vfs_fn_pointers vfs_full_audit_fns = {
2979 /* Disk operations */
2981 .connect_fn = smb_full_audit_connect,
2982 .disconnect_fn = smb_full_audit_disconnect,
2983 .disk_free_fn = smb_full_audit_disk_free,
2984 .get_quota_fn = smb_full_audit_get_quota,
2985 .set_quota_fn = smb_full_audit_set_quota,
2986 .get_shadow_copy_data_fn = smb_full_audit_get_shadow_copy_data,
2987 .statvfs_fn = smb_full_audit_statvfs,
2988 .fs_capabilities_fn = smb_full_audit_fs_capabilities,
2989 .get_dfs_referrals_fn = smb_full_audit_get_dfs_referrals,
2990 .create_dfs_pathat_fn = smb_full_audit_create_dfs_pathat,
2991 .read_dfs_pathat_fn = smb_full_audit_read_dfs_pathat,
2992 .opendir_fn = smb_full_audit_opendir,
2993 .fdopendir_fn = smb_full_audit_fdopendir,
2994 .readdir_fn = smb_full_audit_readdir,
2995 .seekdir_fn = smb_full_audit_seekdir,
2996 .telldir_fn = smb_full_audit_telldir,
2997 .rewind_dir_fn = smb_full_audit_rewinddir,
2998 .mkdirat_fn = smb_full_audit_mkdirat,
2999 .closedir_fn = smb_full_audit_closedir,
3000 .open_fn = smb_full_audit_open,
3001 .create_file_fn = smb_full_audit_create_file,
3002 .close_fn = smb_full_audit_close,
3003 .pread_fn = smb_full_audit_pread,
3004 .pread_send_fn = smb_full_audit_pread_send,
3005 .pread_recv_fn = smb_full_audit_pread_recv,
3006 .pwrite_fn = smb_full_audit_pwrite,
3007 .pwrite_send_fn = smb_full_audit_pwrite_send,
3008 .pwrite_recv_fn = smb_full_audit_pwrite_recv,
3009 .lseek_fn = smb_full_audit_lseek,
3010 .sendfile_fn = smb_full_audit_sendfile,
3011 .recvfile_fn = smb_full_audit_recvfile,
3012 .renameat_fn = smb_full_audit_renameat,
3013 .fsync_send_fn = smb_full_audit_fsync_send,
3014 .fsync_recv_fn = smb_full_audit_fsync_recv,
3015 .stat_fn = smb_full_audit_stat,
3016 .fstat_fn = smb_full_audit_fstat,
3017 .lstat_fn = smb_full_audit_lstat,
3018 .get_alloc_size_fn = smb_full_audit_get_alloc_size,
3019 .unlinkat_fn = smb_full_audit_unlinkat,
3020 .chmod_fn = smb_full_audit_chmod,
3021 .fchmod_fn = smb_full_audit_fchmod,
3022 .fchown_fn = smb_full_audit_fchown,
3023 .lchown_fn = smb_full_audit_lchown,
3024 .chdir_fn = smb_full_audit_chdir,
3025 .getwd_fn = smb_full_audit_getwd,
3026 .ntimes_fn = smb_full_audit_ntimes,
3027 .ftruncate_fn = smb_full_audit_ftruncate,
3028 .fallocate_fn = smb_full_audit_fallocate,
3029 .lock_fn = smb_full_audit_lock,
3030 .kernel_flock_fn = smb_full_audit_kernel_flock,
3031 .fcntl_fn = smb_full_audit_fcntl,
3032 .linux_setlease_fn = smb_full_audit_linux_setlease,
3033 .getlock_fn = smb_full_audit_getlock,
3034 .symlinkat_fn = smb_full_audit_symlinkat,
3035 .readlinkat_fn = smb_full_audit_readlinkat,
3036 .linkat_fn = smb_full_audit_linkat,
3037 .mknodat_fn = smb_full_audit_mknodat,
3038 .realpath_fn = smb_full_audit_realpath,
3039 .chflags_fn = smb_full_audit_chflags,
3040 .file_id_create_fn = smb_full_audit_file_id_create,
3041 .fs_file_id_fn = smb_full_audit_fs_file_id,
3042 .offload_read_send_fn = smb_full_audit_offload_read_send,
3043 .offload_read_recv_fn = smb_full_audit_offload_read_recv,
3044 .offload_write_send_fn = smb_full_audit_offload_write_send,
3045 .offload_write_recv_fn = smb_full_audit_offload_write_recv,
3046 .get_compression_fn = smb_full_audit_get_compression,
3047 .set_compression_fn = smb_full_audit_set_compression,
3048 .snap_check_path_fn = smb_full_audit_snap_check_path,
3049 .snap_create_fn = smb_full_audit_snap_create,
3050 .snap_delete_fn = smb_full_audit_snap_delete,
3051 .streaminfo_fn = smb_full_audit_streaminfo,
3052 .get_real_filename_fn = smb_full_audit_get_real_filename,
3053 .connectpath_fn = smb_full_audit_connectpath,
3054 .brl_lock_windows_fn = smb_full_audit_brl_lock_windows,
3055 .brl_unlock_windows_fn = smb_full_audit_brl_unlock_windows,
3056 .strict_lock_check_fn = smb_full_audit_strict_lock_check,
3057 .translate_name_fn = smb_full_audit_translate_name,
3058 .fsctl_fn = smb_full_audit_fsctl,
3059 .get_dos_attributes_fn = smb_full_audit_get_dos_attributes,
3060 .get_dos_attributes_send_fn = smb_full_audit_get_dos_attributes_send,
3061 .get_dos_attributes_recv_fn = smb_full_audit_get_dos_attributes_recv,
3062 .fget_dos_attributes_fn = smb_full_audit_fget_dos_attributes,
3063 .set_dos_attributes_fn = smb_full_audit_set_dos_attributes,
3064 .fset_dos_attributes_fn = smb_full_audit_fset_dos_attributes,
3065 .fget_nt_acl_fn = smb_full_audit_fget_nt_acl,
3066 .get_nt_acl_fn = smb_full_audit_get_nt_acl,
3067 .fset_nt_acl_fn = smb_full_audit_fset_nt_acl,
3068 .audit_file_fn = smb_full_audit_audit_file,
3069 .sys_acl_get_file_fn = smb_full_audit_sys_acl_get_file,
3070 .sys_acl_get_fd_fn = smb_full_audit_sys_acl_get_fd,
3071 .sys_acl_blob_get_file_fn = smb_full_audit_sys_acl_blob_get_file,
3072 .sys_acl_blob_get_fd_fn = smb_full_audit_sys_acl_blob_get_fd,
3073 .sys_acl_set_file_fn = smb_full_audit_sys_acl_set_file,
3074 .sys_acl_set_fd_fn = smb_full_audit_sys_acl_set_fd,
3075 .sys_acl_delete_def_file_fn = smb_full_audit_sys_acl_delete_def_file,
3076 .getxattr_fn = smb_full_audit_getxattr,
3077 .getxattrat_send_fn = smb_full_audit_getxattrat_send,
3078 .getxattrat_recv_fn = smb_full_audit_getxattrat_recv,
3079 .fgetxattr_fn = smb_full_audit_fgetxattr,
3080 .listxattr_fn = smb_full_audit_listxattr,
3081 .flistxattr_fn = smb_full_audit_flistxattr,
3082 .removexattr_fn = smb_full_audit_removexattr,
3083 .fremovexattr_fn = smb_full_audit_fremovexattr,
3084 .setxattr_fn = smb_full_audit_setxattr,
3085 .fsetxattr_fn = smb_full_audit_fsetxattr,
3086 .aio_force_fn = smb_full_audit_aio_force,
3087 .durable_cookie_fn = smb_full_audit_durable_cookie,
3088 .durable_disconnect_fn = smb_full_audit_durable_disconnect,
3089 .durable_reconnect_fn = smb_full_audit_durable_reconnect,
3090 .readdir_attr_fn = smb_full_audit_readdir_attr
3094 static_decl_vfs;
3095 NTSTATUS vfs_full_audit_init(TALLOC_CTX *ctx)
3097 NTSTATUS ret;
3099 smb_vfs_assert_all_fns(&vfs_full_audit_fns, "full_audit");
3101 ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "full_audit",
3102 &vfs_full_audit_fns);
3104 if (!NT_STATUS_IS_OK(ret))
3105 return ret;
3107 vfs_full_audit_debug_level = debug_add_class("full_audit");
3108 if (vfs_full_audit_debug_level == -1) {
3109 vfs_full_audit_debug_level = DBGC_VFS;
3110 DEBUG(0, ("vfs_full_audit: Couldn't register custom debugging "
3111 "class!\n"));
3112 } else {
3113 DEBUG(10, ("vfs_full_audit: Debug class number of "
3114 "'full_audit': %d\n", vfs_full_audit_debug_level));
3117 return ret;