Wrap the unix token info in a unix_user_token in auth_serversupplied_info
[Samba.git] / source / modules / vfs_full_audit.c
blob3cefbcda34256f2d9344cc255cf338ed981dae96
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"
62 static int vfs_full_audit_debug_level = DBGC_VFS;
64 struct vfs_full_audit_private_data {
65 struct bitmap *success_ops;
66 struct bitmap *failure_ops;
69 #undef DBGC_CLASS
70 #define DBGC_CLASS vfs_full_audit_debug_level
72 /* Function prototypes */
74 static int smb_full_audit_connect(vfs_handle_struct *handle,
75 const char *svc, const char *user);
76 static void smb_full_audit_disconnect(vfs_handle_struct *handle);
77 static SMB_BIG_UINT smb_full_audit_disk_free(vfs_handle_struct *handle,
78 const char *path,
79 bool small_query, SMB_BIG_UINT *bsize,
80 SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize);
81 static int smb_full_audit_get_quota(struct vfs_handle_struct *handle,
82 enum SMB_QUOTA_TYPE qtype, unid_t id,
83 SMB_DISK_QUOTA *qt);
84 static int smb_full_audit_set_quota(struct vfs_handle_struct *handle,
85 enum SMB_QUOTA_TYPE qtype, unid_t id,
86 SMB_DISK_QUOTA *qt);
87 static int smb_full_audit_get_shadow_copy_data(struct vfs_handle_struct *handle,
88 struct files_struct *fsp,
89 SHADOW_COPY_DATA *shadow_copy_data, bool labels);
90 static int smb_full_audit_statvfs(struct vfs_handle_struct *handle,
91 const char *path,
92 struct vfs_statvfs_struct *statbuf);
94 static SMB_STRUCT_DIR *smb_full_audit_opendir(vfs_handle_struct *handle,
95 const char *fname, const char *mask, uint32 attr);
96 static SMB_STRUCT_DIRENT *smb_full_audit_readdir(vfs_handle_struct *handle,
97 SMB_STRUCT_DIR *dirp);
98 static void smb_full_audit_seekdir(vfs_handle_struct *handle,
99 SMB_STRUCT_DIR *dirp, long offset);
100 static long smb_full_audit_telldir(vfs_handle_struct *handle,
101 SMB_STRUCT_DIR *dirp);
102 static void smb_full_audit_rewinddir(vfs_handle_struct *handle,
103 SMB_STRUCT_DIR *dirp);
104 static int smb_full_audit_mkdir(vfs_handle_struct *handle,
105 const char *path, mode_t mode);
106 static int smb_full_audit_rmdir(vfs_handle_struct *handle,
107 const char *path);
108 static int smb_full_audit_closedir(vfs_handle_struct *handle,
109 SMB_STRUCT_DIR *dirp);
110 static int smb_full_audit_open(vfs_handle_struct *handle,
111 const char *fname, files_struct *fsp, int flags, mode_t mode);
112 static int smb_full_audit_close(vfs_handle_struct *handle, files_struct *fsp);
113 static ssize_t smb_full_audit_read(vfs_handle_struct *handle, files_struct *fsp,
114 void *data, size_t n);
115 static ssize_t smb_full_audit_pread(vfs_handle_struct *handle, files_struct *fsp,
116 void *data, size_t n, SMB_OFF_T offset);
117 static ssize_t smb_full_audit_write(vfs_handle_struct *handle, files_struct *fsp,
118 const void *data, size_t n);
119 static ssize_t smb_full_audit_pwrite(vfs_handle_struct *handle, files_struct *fsp,
120 const void *data, size_t n,
121 SMB_OFF_T offset);
122 static SMB_OFF_T smb_full_audit_lseek(vfs_handle_struct *handle, files_struct *fsp,
123 SMB_OFF_T offset, int whence);
124 static ssize_t smb_full_audit_sendfile(vfs_handle_struct *handle, int tofd,
125 files_struct *fromfsp,
126 const DATA_BLOB *hdr, SMB_OFF_T offset,
127 size_t n);
128 static ssize_t smb_full_audit_recvfile(vfs_handle_struct *handle, int fromfd,
129 files_struct *tofsp,
130 SMB_OFF_T offset,
131 size_t n);
132 static int smb_full_audit_rename(vfs_handle_struct *handle,
133 const char *oldname, const char *newname);
134 static int smb_full_audit_fsync(vfs_handle_struct *handle, files_struct *fsp);
135 static int smb_full_audit_stat(vfs_handle_struct *handle,
136 const char *fname, SMB_STRUCT_STAT *sbuf);
137 static int smb_full_audit_fstat(vfs_handle_struct *handle, files_struct *fsp,
138 SMB_STRUCT_STAT *sbuf);
139 static int smb_full_audit_lstat(vfs_handle_struct *handle,
140 const char *path, SMB_STRUCT_STAT *sbuf);
141 static int smb_full_audit_unlink(vfs_handle_struct *handle,
142 const char *path);
143 static int smb_full_audit_chmod(vfs_handle_struct *handle,
144 const char *path, mode_t mode);
145 static int smb_full_audit_fchmod(vfs_handle_struct *handle, files_struct *fsp,
146 mode_t mode);
147 static int smb_full_audit_chown(vfs_handle_struct *handle,
148 const char *path, uid_t uid, gid_t gid);
149 static int smb_full_audit_fchown(vfs_handle_struct *handle, files_struct *fsp,
150 uid_t uid, gid_t gid);
151 static int smb_full_audit_lchown(vfs_handle_struct *handle,
152 const char *path, uid_t uid, gid_t gid);
153 static int smb_full_audit_chdir(vfs_handle_struct *handle,
154 const char *path);
155 static char *smb_full_audit_getwd(vfs_handle_struct *handle,
156 char *path);
157 static int smb_full_audit_ntimes(vfs_handle_struct *handle,
158 const char *path, const struct timespec ts[2]);
159 static int smb_full_audit_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
160 SMB_OFF_T len);
161 static bool smb_full_audit_lock(vfs_handle_struct *handle, files_struct *fsp,
162 int op, SMB_OFF_T offset, SMB_OFF_T count, int type);
163 static int smb_full_audit_kernel_flock(struct vfs_handle_struct *handle,
164 struct files_struct *fsp,
165 uint32 share_mode);
166 static int smb_full_audit_linux_setlease(vfs_handle_struct *handle, files_struct *fsp,
167 int leasetype);
168 static bool smb_full_audit_getlock(vfs_handle_struct *handle, files_struct *fsp,
169 SMB_OFF_T *poffset, SMB_OFF_T *pcount, int *ptype, pid_t *ppid);
170 static int smb_full_audit_symlink(vfs_handle_struct *handle,
171 const char *oldpath, const char *newpath);
172 static int smb_full_audit_readlink(vfs_handle_struct *handle,
173 const char *path, char *buf, size_t bufsiz);
174 static int smb_full_audit_link(vfs_handle_struct *handle,
175 const char *oldpath, const char *newpath);
176 static int smb_full_audit_mknod(vfs_handle_struct *handle,
177 const char *pathname, mode_t mode, SMB_DEV_T dev);
178 static char *smb_full_audit_realpath(vfs_handle_struct *handle,
179 const char *path, char *resolved_path);
180 static NTSTATUS smb_full_audit_notify_watch(struct vfs_handle_struct *handle,
181 struct sys_notify_context *ctx,
182 struct notify_entry *e,
183 void (*callback)(struct sys_notify_context *ctx,
184 void *private_data,
185 struct notify_event *ev),
186 void *private_data, void *handle_p);
187 static int smb_full_audit_chflags(vfs_handle_struct *handle,
188 const char *path, unsigned int flags);
189 static struct file_id smb_full_audit_file_id_create(struct vfs_handle_struct *handle,
190 SMB_DEV_T dev, SMB_INO_T inode);
191 static NTSTATUS smb_full_audit_streaminfo(vfs_handle_struct *handle,
192 struct files_struct *fsp,
193 const char *fname,
194 TALLOC_CTX *mem_ctx,
195 unsigned int *pnum_streams,
196 struct stream_struct **pstreams);
197 static NTSTATUS smb_full_audit_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
198 uint32 security_info,
199 SEC_DESC **ppdesc);
200 static NTSTATUS smb_full_audit_get_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
201 const char *name, uint32 security_info,
202 SEC_DESC **ppdesc);
203 static NTSTATUS smb_full_audit_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
204 uint32 security_info_sent,
205 SEC_DESC *psd);
206 static int smb_full_audit_chmod_acl(vfs_handle_struct *handle,
207 const char *path, mode_t mode);
208 static int smb_full_audit_fchmod_acl(vfs_handle_struct *handle, files_struct *fsp,
209 mode_t mode);
210 static int smb_full_audit_sys_acl_get_entry(vfs_handle_struct *handle,
211 SMB_ACL_T theacl, int entry_id,
212 SMB_ACL_ENTRY_T *entry_p);
213 static int smb_full_audit_sys_acl_get_tag_type(vfs_handle_struct *handle,
214 SMB_ACL_ENTRY_T entry_d,
215 SMB_ACL_TAG_T *tag_type_p);
216 static int smb_full_audit_sys_acl_get_permset(vfs_handle_struct *handle,
217 SMB_ACL_ENTRY_T entry_d,
218 SMB_ACL_PERMSET_T *permset_p);
219 static void * smb_full_audit_sys_acl_get_qualifier(vfs_handle_struct *handle,
220 SMB_ACL_ENTRY_T entry_d);
221 static SMB_ACL_T smb_full_audit_sys_acl_get_file(vfs_handle_struct *handle,
222 const char *path_p,
223 SMB_ACL_TYPE_T type);
224 static SMB_ACL_T smb_full_audit_sys_acl_get_fd(vfs_handle_struct *handle,
225 files_struct *fsp);
226 static int smb_full_audit_sys_acl_clear_perms(vfs_handle_struct *handle,
227 SMB_ACL_PERMSET_T permset);
228 static int smb_full_audit_sys_acl_add_perm(vfs_handle_struct *handle,
229 SMB_ACL_PERMSET_T permset,
230 SMB_ACL_PERM_T perm);
231 static char * smb_full_audit_sys_acl_to_text(vfs_handle_struct *handle,
232 SMB_ACL_T theacl,
233 ssize_t *plen);
234 static SMB_ACL_T smb_full_audit_sys_acl_init(vfs_handle_struct *handle,
235 int count);
236 static int smb_full_audit_sys_acl_create_entry(vfs_handle_struct *handle,
237 SMB_ACL_T *pacl,
238 SMB_ACL_ENTRY_T *pentry);
239 static int smb_full_audit_sys_acl_set_tag_type(vfs_handle_struct *handle,
240 SMB_ACL_ENTRY_T entry,
241 SMB_ACL_TAG_T tagtype);
242 static int smb_full_audit_sys_acl_set_qualifier(vfs_handle_struct *handle,
243 SMB_ACL_ENTRY_T entry,
244 void *qual);
245 static int smb_full_audit_sys_acl_set_permset(vfs_handle_struct *handle,
246 SMB_ACL_ENTRY_T entry,
247 SMB_ACL_PERMSET_T permset);
248 static int smb_full_audit_sys_acl_valid(vfs_handle_struct *handle,
249 SMB_ACL_T theacl );
250 static int smb_full_audit_sys_acl_set_file(vfs_handle_struct *handle,
251 const char *name, SMB_ACL_TYPE_T acltype,
252 SMB_ACL_T theacl);
253 static int smb_full_audit_sys_acl_set_fd(vfs_handle_struct *handle, files_struct *fsp,
254 SMB_ACL_T theacl);
255 static int smb_full_audit_sys_acl_delete_def_file(vfs_handle_struct *handle,
256 const char *path);
257 static int smb_full_audit_sys_acl_get_perm(vfs_handle_struct *handle,
258 SMB_ACL_PERMSET_T permset,
259 SMB_ACL_PERM_T perm);
260 static int smb_full_audit_sys_acl_free_text(vfs_handle_struct *handle,
261 char *text);
262 static int smb_full_audit_sys_acl_free_acl(vfs_handle_struct *handle,
263 SMB_ACL_T posix_acl);
264 static int smb_full_audit_sys_acl_free_qualifier(vfs_handle_struct *handle,
265 void *qualifier,
266 SMB_ACL_TAG_T tagtype);
267 static ssize_t smb_full_audit_getxattr(struct vfs_handle_struct *handle,
268 const char *path,
269 const char *name, void *value, size_t size);
270 static ssize_t smb_full_audit_lgetxattr(struct vfs_handle_struct *handle,
271 const char *path, const char *name,
272 void *value, size_t size);
273 static ssize_t smb_full_audit_fgetxattr(struct vfs_handle_struct *handle,
274 struct files_struct *fsp,
275 const char *name, void *value, size_t size);
276 static ssize_t smb_full_audit_listxattr(struct vfs_handle_struct *handle,
277 const char *path, char *list, size_t size);
278 static ssize_t smb_full_audit_llistxattr(struct vfs_handle_struct *handle,
279 const char *path, char *list, size_t size);
280 static ssize_t smb_full_audit_flistxattr(struct vfs_handle_struct *handle,
281 struct files_struct *fsp, char *list,
282 size_t size);
283 static int smb_full_audit_removexattr(struct vfs_handle_struct *handle,
284 const char *path,
285 const char *name);
286 static int smb_full_audit_lremovexattr(struct vfs_handle_struct *handle,
287 const char *path,
288 const char *name);
289 static int smb_full_audit_fremovexattr(struct vfs_handle_struct *handle,
290 struct files_struct *fsp,
291 const char *name);
292 static int smb_full_audit_setxattr(struct vfs_handle_struct *handle,
293 const char *path,
294 const char *name, const void *value, size_t size,
295 int flags);
296 static int smb_full_audit_lsetxattr(struct vfs_handle_struct *handle,
297 const char *path,
298 const char *name, const void *value, size_t size,
299 int flags);
300 static int smb_full_audit_fsetxattr(struct vfs_handle_struct *handle,
301 struct files_struct *fsp, const char *name,
302 const void *value, size_t size, int flags);
304 static int smb_full_audit_aio_read(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb);
305 static int smb_full_audit_aio_write(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb);
306 static ssize_t smb_full_audit_aio_return(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb);
307 static int smb_full_audit_aio_cancel(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb);
308 static int smb_full_audit_aio_error(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb);
309 static int smb_full_audit_aio_fsync(struct vfs_handle_struct *handle, struct files_struct *fsp, int op, SMB_STRUCT_AIOCB *aiocb);
310 static int smb_full_audit_aio_suspend(struct vfs_handle_struct *handle, struct files_struct *fsp, const SMB_STRUCT_AIOCB * const aiocb[], int n, const struct timespec *ts);
312 /* VFS operations */
314 static vfs_op_tuple audit_op_tuples[] = {
316 /* Disk operations */
318 {SMB_VFS_OP(smb_full_audit_connect), SMB_VFS_OP_CONNECT,
319 SMB_VFS_LAYER_LOGGER},
320 {SMB_VFS_OP(smb_full_audit_disconnect), SMB_VFS_OP_DISCONNECT,
321 SMB_VFS_LAYER_LOGGER},
322 {SMB_VFS_OP(smb_full_audit_disk_free), SMB_VFS_OP_DISK_FREE,
323 SMB_VFS_LAYER_LOGGER},
324 {SMB_VFS_OP(smb_full_audit_get_quota), SMB_VFS_OP_GET_QUOTA,
325 SMB_VFS_LAYER_LOGGER},
326 {SMB_VFS_OP(smb_full_audit_set_quota), SMB_VFS_OP_SET_QUOTA,
327 SMB_VFS_LAYER_LOGGER},
328 {SMB_VFS_OP(smb_full_audit_get_shadow_copy_data), SMB_VFS_OP_GET_SHADOW_COPY_DATA,
329 SMB_VFS_LAYER_LOGGER},
330 {SMB_VFS_OP(smb_full_audit_statvfs), SMB_VFS_OP_STATVFS,
331 SMB_VFS_LAYER_LOGGER},
333 /* Directory operations */
335 {SMB_VFS_OP(smb_full_audit_opendir), SMB_VFS_OP_OPENDIR,
336 SMB_VFS_LAYER_LOGGER},
337 {SMB_VFS_OP(smb_full_audit_readdir), SMB_VFS_OP_READDIR,
338 SMB_VFS_LAYER_LOGGER},
339 {SMB_VFS_OP(smb_full_audit_seekdir), SMB_VFS_OP_SEEKDIR,
340 SMB_VFS_LAYER_LOGGER},
341 {SMB_VFS_OP(smb_full_audit_telldir), SMB_VFS_OP_TELLDIR,
342 SMB_VFS_LAYER_LOGGER},
343 {SMB_VFS_OP(smb_full_audit_rewinddir), SMB_VFS_OP_REWINDDIR,
344 SMB_VFS_LAYER_LOGGER},
345 {SMB_VFS_OP(smb_full_audit_mkdir), SMB_VFS_OP_MKDIR,
346 SMB_VFS_LAYER_LOGGER},
347 {SMB_VFS_OP(smb_full_audit_rmdir), SMB_VFS_OP_RMDIR,
348 SMB_VFS_LAYER_LOGGER},
349 {SMB_VFS_OP(smb_full_audit_closedir), SMB_VFS_OP_CLOSEDIR,
350 SMB_VFS_LAYER_LOGGER},
352 /* File operations */
354 {SMB_VFS_OP(smb_full_audit_open), SMB_VFS_OP_OPEN,
355 SMB_VFS_LAYER_LOGGER},
356 {SMB_VFS_OP(smb_full_audit_close), SMB_VFS_OP_CLOSE,
357 SMB_VFS_LAYER_LOGGER},
358 {SMB_VFS_OP(smb_full_audit_read), SMB_VFS_OP_READ,
359 SMB_VFS_LAYER_LOGGER},
360 {SMB_VFS_OP(smb_full_audit_pread), SMB_VFS_OP_PREAD,
361 SMB_VFS_LAYER_LOGGER},
362 {SMB_VFS_OP(smb_full_audit_write), SMB_VFS_OP_WRITE,
363 SMB_VFS_LAYER_LOGGER},
364 {SMB_VFS_OP(smb_full_audit_pwrite), SMB_VFS_OP_PWRITE,
365 SMB_VFS_LAYER_LOGGER},
366 {SMB_VFS_OP(smb_full_audit_lseek), SMB_VFS_OP_LSEEK,
367 SMB_VFS_LAYER_LOGGER},
368 {SMB_VFS_OP(smb_full_audit_sendfile), SMB_VFS_OP_SENDFILE,
369 SMB_VFS_LAYER_LOGGER},
370 {SMB_VFS_OP(smb_full_audit_recvfile), SMB_VFS_OP_RECVFILE,
371 SMB_VFS_LAYER_LOGGER},
372 {SMB_VFS_OP(smb_full_audit_rename), SMB_VFS_OP_RENAME,
373 SMB_VFS_LAYER_LOGGER},
374 {SMB_VFS_OP(smb_full_audit_fsync), SMB_VFS_OP_FSYNC,
375 SMB_VFS_LAYER_LOGGER},
376 {SMB_VFS_OP(smb_full_audit_stat), SMB_VFS_OP_STAT,
377 SMB_VFS_LAYER_LOGGER},
378 {SMB_VFS_OP(smb_full_audit_fstat), SMB_VFS_OP_FSTAT,
379 SMB_VFS_LAYER_LOGGER},
380 {SMB_VFS_OP(smb_full_audit_lstat), SMB_VFS_OP_LSTAT,
381 SMB_VFS_LAYER_LOGGER},
382 {SMB_VFS_OP(smb_full_audit_unlink), SMB_VFS_OP_UNLINK,
383 SMB_VFS_LAYER_LOGGER},
384 {SMB_VFS_OP(smb_full_audit_chmod), SMB_VFS_OP_CHMOD,
385 SMB_VFS_LAYER_LOGGER},
386 {SMB_VFS_OP(smb_full_audit_fchmod), SMB_VFS_OP_FCHMOD,
387 SMB_VFS_LAYER_LOGGER},
388 {SMB_VFS_OP(smb_full_audit_chown), SMB_VFS_OP_CHOWN,
389 SMB_VFS_LAYER_LOGGER},
390 {SMB_VFS_OP(smb_full_audit_fchown), SMB_VFS_OP_FCHOWN,
391 SMB_VFS_LAYER_LOGGER},
392 {SMB_VFS_OP(smb_full_audit_lchown), SMB_VFS_OP_LCHOWN,
393 SMB_VFS_LAYER_LOGGER},
394 {SMB_VFS_OP(smb_full_audit_chdir), SMB_VFS_OP_CHDIR,
395 SMB_VFS_LAYER_LOGGER},
396 {SMB_VFS_OP(smb_full_audit_getwd), SMB_VFS_OP_GETWD,
397 SMB_VFS_LAYER_LOGGER},
398 {SMB_VFS_OP(smb_full_audit_ntimes), SMB_VFS_OP_NTIMES,
399 SMB_VFS_LAYER_LOGGER},
400 {SMB_VFS_OP(smb_full_audit_ftruncate), SMB_VFS_OP_FTRUNCATE,
401 SMB_VFS_LAYER_LOGGER},
402 {SMB_VFS_OP(smb_full_audit_lock), SMB_VFS_OP_LOCK,
403 SMB_VFS_LAYER_LOGGER},
404 {SMB_VFS_OP(smb_full_audit_kernel_flock), SMB_VFS_OP_KERNEL_FLOCK,
405 SMB_VFS_LAYER_LOGGER},
406 {SMB_VFS_OP(smb_full_audit_linux_setlease), SMB_VFS_OP_LINUX_SETLEASE,
407 SMB_VFS_LAYER_LOGGER},
408 {SMB_VFS_OP(smb_full_audit_getlock), SMB_VFS_OP_GETLOCK,
409 SMB_VFS_LAYER_LOGGER},
410 {SMB_VFS_OP(smb_full_audit_symlink), SMB_VFS_OP_SYMLINK,
411 SMB_VFS_LAYER_LOGGER},
412 {SMB_VFS_OP(smb_full_audit_readlink), SMB_VFS_OP_READLINK,
413 SMB_VFS_LAYER_LOGGER},
414 {SMB_VFS_OP(smb_full_audit_link), SMB_VFS_OP_LINK,
415 SMB_VFS_LAYER_LOGGER},
416 {SMB_VFS_OP(smb_full_audit_mknod), SMB_VFS_OP_MKNOD,
417 SMB_VFS_LAYER_LOGGER},
418 {SMB_VFS_OP(smb_full_audit_realpath), SMB_VFS_OP_REALPATH,
419 SMB_VFS_LAYER_LOGGER},
420 {SMB_VFS_OP(smb_full_audit_notify_watch),SMB_VFS_OP_NOTIFY_WATCH,
421 SMB_VFS_LAYER_LOGGER},
422 {SMB_VFS_OP(smb_full_audit_chflags), SMB_VFS_OP_CHFLAGS,
423 SMB_VFS_LAYER_LOGGER},
424 {SMB_VFS_OP(smb_full_audit_file_id_create), SMB_VFS_OP_FILE_ID_CREATE,
425 SMB_VFS_LAYER_LOGGER},
426 {SMB_VFS_OP(smb_full_audit_streaminfo), SMB_VFS_OP_STREAMINFO,
427 SMB_VFS_LAYER_LOGGER},
429 /* NT ACL operations. */
431 {SMB_VFS_OP(smb_full_audit_fget_nt_acl), SMB_VFS_OP_FGET_NT_ACL,
432 SMB_VFS_LAYER_LOGGER},
433 {SMB_VFS_OP(smb_full_audit_get_nt_acl), SMB_VFS_OP_GET_NT_ACL,
434 SMB_VFS_LAYER_LOGGER},
435 {SMB_VFS_OP(smb_full_audit_fset_nt_acl), SMB_VFS_OP_FSET_NT_ACL,
436 SMB_VFS_LAYER_LOGGER},
438 /* POSIX ACL operations. */
440 {SMB_VFS_OP(smb_full_audit_chmod_acl), SMB_VFS_OP_CHMOD_ACL,
441 SMB_VFS_LAYER_LOGGER},
442 {SMB_VFS_OP(smb_full_audit_fchmod_acl), SMB_VFS_OP_FCHMOD_ACL,
443 SMB_VFS_LAYER_LOGGER},
444 {SMB_VFS_OP(smb_full_audit_sys_acl_get_entry), SMB_VFS_OP_SYS_ACL_GET_ENTRY,
445 SMB_VFS_LAYER_LOGGER},
446 {SMB_VFS_OP(smb_full_audit_sys_acl_get_tag_type), SMB_VFS_OP_SYS_ACL_GET_TAG_TYPE,
447 SMB_VFS_LAYER_LOGGER},
448 {SMB_VFS_OP(smb_full_audit_sys_acl_get_permset), SMB_VFS_OP_SYS_ACL_GET_PERMSET,
449 SMB_VFS_LAYER_LOGGER},
450 {SMB_VFS_OP(smb_full_audit_sys_acl_get_qualifier), SMB_VFS_OP_SYS_ACL_GET_QUALIFIER,
451 SMB_VFS_LAYER_LOGGER},
452 {SMB_VFS_OP(smb_full_audit_sys_acl_get_file), SMB_VFS_OP_SYS_ACL_GET_FILE,
453 SMB_VFS_LAYER_LOGGER},
454 {SMB_VFS_OP(smb_full_audit_sys_acl_get_fd), SMB_VFS_OP_SYS_ACL_GET_FD,
455 SMB_VFS_LAYER_LOGGER},
456 {SMB_VFS_OP(smb_full_audit_sys_acl_clear_perms), SMB_VFS_OP_SYS_ACL_CLEAR_PERMS,
457 SMB_VFS_LAYER_LOGGER},
458 {SMB_VFS_OP(smb_full_audit_sys_acl_add_perm), SMB_VFS_OP_SYS_ACL_ADD_PERM,
459 SMB_VFS_LAYER_LOGGER},
460 {SMB_VFS_OP(smb_full_audit_sys_acl_to_text), SMB_VFS_OP_SYS_ACL_TO_TEXT,
461 SMB_VFS_LAYER_LOGGER},
462 {SMB_VFS_OP(smb_full_audit_sys_acl_init), SMB_VFS_OP_SYS_ACL_INIT,
463 SMB_VFS_LAYER_LOGGER},
464 {SMB_VFS_OP(smb_full_audit_sys_acl_create_entry), SMB_VFS_OP_SYS_ACL_CREATE_ENTRY,
465 SMB_VFS_LAYER_LOGGER},
466 {SMB_VFS_OP(smb_full_audit_sys_acl_set_tag_type), SMB_VFS_OP_SYS_ACL_SET_TAG_TYPE,
467 SMB_VFS_LAYER_LOGGER},
468 {SMB_VFS_OP(smb_full_audit_sys_acl_set_qualifier), SMB_VFS_OP_SYS_ACL_SET_QUALIFIER,
469 SMB_VFS_LAYER_LOGGER},
470 {SMB_VFS_OP(smb_full_audit_sys_acl_set_permset), SMB_VFS_OP_SYS_ACL_SET_PERMSET,
471 SMB_VFS_LAYER_LOGGER},
472 {SMB_VFS_OP(smb_full_audit_sys_acl_valid), SMB_VFS_OP_SYS_ACL_VALID,
473 SMB_VFS_LAYER_LOGGER},
474 {SMB_VFS_OP(smb_full_audit_sys_acl_set_file), SMB_VFS_OP_SYS_ACL_SET_FILE,
475 SMB_VFS_LAYER_LOGGER},
476 {SMB_VFS_OP(smb_full_audit_sys_acl_set_fd), SMB_VFS_OP_SYS_ACL_SET_FD,
477 SMB_VFS_LAYER_LOGGER},
478 {SMB_VFS_OP(smb_full_audit_sys_acl_delete_def_file), SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE,
479 SMB_VFS_LAYER_LOGGER},
480 {SMB_VFS_OP(smb_full_audit_sys_acl_get_perm), SMB_VFS_OP_SYS_ACL_GET_PERM,
481 SMB_VFS_LAYER_LOGGER},
482 {SMB_VFS_OP(smb_full_audit_sys_acl_free_text), SMB_VFS_OP_SYS_ACL_FREE_TEXT,
483 SMB_VFS_LAYER_LOGGER},
484 {SMB_VFS_OP(smb_full_audit_sys_acl_free_acl), SMB_VFS_OP_SYS_ACL_FREE_ACL,
485 SMB_VFS_LAYER_LOGGER},
486 {SMB_VFS_OP(smb_full_audit_sys_acl_free_qualifier), SMB_VFS_OP_SYS_ACL_FREE_QUALIFIER,
487 SMB_VFS_LAYER_LOGGER},
489 /* EA operations. */
491 {SMB_VFS_OP(smb_full_audit_getxattr), SMB_VFS_OP_GETXATTR,
492 SMB_VFS_LAYER_LOGGER},
493 {SMB_VFS_OP(smb_full_audit_lgetxattr), SMB_VFS_OP_LGETXATTR,
494 SMB_VFS_LAYER_LOGGER},
495 {SMB_VFS_OP(smb_full_audit_fgetxattr), SMB_VFS_OP_FGETXATTR,
496 SMB_VFS_LAYER_LOGGER},
497 {SMB_VFS_OP(smb_full_audit_listxattr), SMB_VFS_OP_LISTXATTR,
498 SMB_VFS_LAYER_LOGGER},
499 {SMB_VFS_OP(smb_full_audit_llistxattr), SMB_VFS_OP_LLISTXATTR,
500 SMB_VFS_LAYER_LOGGER},
501 {SMB_VFS_OP(smb_full_audit_flistxattr), SMB_VFS_OP_FLISTXATTR,
502 SMB_VFS_LAYER_LOGGER},
503 {SMB_VFS_OP(smb_full_audit_removexattr), SMB_VFS_OP_REMOVEXATTR,
504 SMB_VFS_LAYER_LOGGER},
505 {SMB_VFS_OP(smb_full_audit_lremovexattr), SMB_VFS_OP_LREMOVEXATTR,
506 SMB_VFS_LAYER_LOGGER},
507 {SMB_VFS_OP(smb_full_audit_fremovexattr), SMB_VFS_OP_FREMOVEXATTR,
508 SMB_VFS_LAYER_LOGGER},
509 {SMB_VFS_OP(smb_full_audit_setxattr), SMB_VFS_OP_SETXATTR,
510 SMB_VFS_LAYER_LOGGER},
511 {SMB_VFS_OP(smb_full_audit_lsetxattr), SMB_VFS_OP_LSETXATTR,
512 SMB_VFS_LAYER_LOGGER},
513 {SMB_VFS_OP(smb_full_audit_fsetxattr), SMB_VFS_OP_FSETXATTR,
514 SMB_VFS_LAYER_LOGGER},
516 {SMB_VFS_OP(smb_full_audit_aio_read), SMB_VFS_OP_AIO_READ,
517 SMB_VFS_LAYER_LOGGER},
518 {SMB_VFS_OP(smb_full_audit_aio_write), SMB_VFS_OP_AIO_WRITE,
519 SMB_VFS_LAYER_LOGGER},
520 {SMB_VFS_OP(smb_full_audit_aio_return), SMB_VFS_OP_AIO_RETURN,
521 SMB_VFS_LAYER_LOGGER},
522 {SMB_VFS_OP(smb_full_audit_aio_cancel), SMB_VFS_OP_AIO_CANCEL,
523 SMB_VFS_LAYER_LOGGER},
524 {SMB_VFS_OP(smb_full_audit_aio_error), SMB_VFS_OP_AIO_ERROR,
525 SMB_VFS_LAYER_LOGGER},
526 {SMB_VFS_OP(smb_full_audit_aio_fsync), SMB_VFS_OP_AIO_FSYNC,
527 SMB_VFS_LAYER_LOGGER},
528 {SMB_VFS_OP(smb_full_audit_aio_suspend),SMB_VFS_OP_AIO_SUSPEND,
529 SMB_VFS_LAYER_LOGGER},
531 /* Finish VFS operations definition */
533 {SMB_VFS_OP(NULL), SMB_VFS_OP_NOOP,
534 SMB_VFS_LAYER_NOOP}
537 /* The following array *must* be in the same order as defined in vfs.h */
539 static struct {
540 vfs_op_type type;
541 const char *name;
542 } vfs_op_names[] = {
543 { SMB_VFS_OP_CONNECT, "connect" },
544 { SMB_VFS_OP_DISCONNECT, "disconnect" },
545 { SMB_VFS_OP_DISK_FREE, "disk_free" },
546 { SMB_VFS_OP_GET_QUOTA, "get_quota" },
547 { SMB_VFS_OP_SET_QUOTA, "set_quota" },
548 { SMB_VFS_OP_GET_SHADOW_COPY_DATA, "get_shadow_copy_data" },
549 { SMB_VFS_OP_STATVFS, "statvfs" },
550 { SMB_VFS_OP_FS_CAPABILITIES, "fs_capabilities" },
551 { SMB_VFS_OP_OPENDIR, "opendir" },
552 { SMB_VFS_OP_READDIR, "readdir" },
553 { SMB_VFS_OP_SEEKDIR, "seekdir" },
554 { SMB_VFS_OP_TELLDIR, "telldir" },
555 { SMB_VFS_OP_REWINDDIR, "rewinddir" },
556 { SMB_VFS_OP_MKDIR, "mkdir" },
557 { SMB_VFS_OP_RMDIR, "rmdir" },
558 { SMB_VFS_OP_CLOSEDIR, "closedir" },
559 { SMB_VFS_OP_OPEN, "open" },
560 { SMB_VFS_OP_CLOSE, "close" },
561 { SMB_VFS_OP_READ, "read" },
562 { SMB_VFS_OP_PREAD, "pread" },
563 { SMB_VFS_OP_WRITE, "write" },
564 { SMB_VFS_OP_PWRITE, "pwrite" },
565 { SMB_VFS_OP_LSEEK, "lseek" },
566 { SMB_VFS_OP_SENDFILE, "sendfile" },
567 { SMB_VFS_OP_RENAME, "rename" },
568 { SMB_VFS_OP_FSYNC, "fsync" },
569 { SMB_VFS_OP_STAT, "stat" },
570 { SMB_VFS_OP_FSTAT, "fstat" },
571 { SMB_VFS_OP_LSTAT, "lstat" },
572 { SMB_VFS_OP_UNLINK, "unlink" },
573 { SMB_VFS_OP_CHMOD, "chmod" },
574 { SMB_VFS_OP_FCHMOD, "fchmod" },
575 { SMB_VFS_OP_CHOWN, "chown" },
576 { SMB_VFS_OP_FCHOWN, "fchown" },
577 { SMB_VFS_OP_LCHOWN, "lchown" },
578 { SMB_VFS_OP_CHDIR, "chdir" },
579 { SMB_VFS_OP_GETWD, "getwd" },
580 { SMB_VFS_OP_NTIMES, "ntimes" },
581 { SMB_VFS_OP_FTRUNCATE, "ftruncate" },
582 { SMB_VFS_OP_LOCK, "lock" },
583 { SMB_VFS_OP_KERNEL_FLOCK, "kernel_flock" },
584 { SMB_VFS_OP_LINUX_SETLEASE, "linux_setlease" },
585 { SMB_VFS_OP_GETLOCK, "getlock" },
586 { SMB_VFS_OP_SYMLINK, "symlink" },
587 { SMB_VFS_OP_READLINK, "readlink" },
588 { SMB_VFS_OP_LINK, "link" },
589 { SMB_VFS_OP_MKNOD, "mknod" },
590 { SMB_VFS_OP_REALPATH, "realpath" },
591 { SMB_VFS_OP_NOTIFY_WATCH, "notify_watch" },
592 { SMB_VFS_OP_CHFLAGS, "chflags" },
593 { SMB_VFS_OP_FILE_ID_CREATE, "file_id_create" },
594 { SMB_VFS_OP_STREAMINFO, "streaminfo" },
595 { SMB_VFS_OP_FGET_NT_ACL, "fget_nt_acl" },
596 { SMB_VFS_OP_GET_NT_ACL, "get_nt_acl" },
597 { SMB_VFS_OP_FSET_NT_ACL, "fset_nt_acl" },
598 { SMB_VFS_OP_CHMOD_ACL, "chmod_acl" },
599 { SMB_VFS_OP_FCHMOD_ACL, "fchmod_acl" },
600 { SMB_VFS_OP_SYS_ACL_GET_ENTRY, "sys_acl_get_entry" },
601 { SMB_VFS_OP_SYS_ACL_GET_TAG_TYPE, "sys_acl_get_tag_type" },
602 { SMB_VFS_OP_SYS_ACL_GET_PERMSET, "sys_acl_get_permset" },
603 { SMB_VFS_OP_SYS_ACL_GET_QUALIFIER, "sys_acl_get_qualifier" },
604 { SMB_VFS_OP_SYS_ACL_GET_FILE, "sys_acl_get_file" },
605 { SMB_VFS_OP_SYS_ACL_GET_FD, "sys_acl_get_fd" },
606 { SMB_VFS_OP_SYS_ACL_CLEAR_PERMS, "sys_acl_clear_perms" },
607 { SMB_VFS_OP_SYS_ACL_ADD_PERM, "sys_acl_add_perm" },
608 { SMB_VFS_OP_SYS_ACL_TO_TEXT, "sys_acl_to_text" },
609 { SMB_VFS_OP_SYS_ACL_INIT, "sys_acl_init" },
610 { SMB_VFS_OP_SYS_ACL_CREATE_ENTRY, "sys_acl_create_entry" },
611 { SMB_VFS_OP_SYS_ACL_SET_TAG_TYPE, "sys_acl_set_tag_type" },
612 { SMB_VFS_OP_SYS_ACL_SET_QUALIFIER, "sys_acl_set_qualifier" },
613 { SMB_VFS_OP_SYS_ACL_SET_PERMSET, "sys_acl_set_permset" },
614 { SMB_VFS_OP_SYS_ACL_VALID, "sys_acl_valid" },
615 { SMB_VFS_OP_SYS_ACL_SET_FILE, "sys_acl_set_file" },
616 { SMB_VFS_OP_SYS_ACL_SET_FD, "sys_acl_set_fd" },
617 { SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE, "sys_acl_delete_def_file" },
618 { SMB_VFS_OP_SYS_ACL_GET_PERM, "sys_acl_get_perm" },
619 { SMB_VFS_OP_SYS_ACL_FREE_TEXT, "sys_acl_free_text" },
620 { SMB_VFS_OP_SYS_ACL_FREE_ACL, "sys_acl_free_acl" },
621 { SMB_VFS_OP_SYS_ACL_FREE_QUALIFIER, "sys_acl_free_qualifier" },
622 { SMB_VFS_OP_GETXATTR, "getxattr" },
623 { SMB_VFS_OP_LGETXATTR, "lgetxattr" },
624 { SMB_VFS_OP_FGETXATTR, "fgetxattr" },
625 { SMB_VFS_OP_LISTXATTR, "listxattr" },
626 { SMB_VFS_OP_LLISTXATTR, "llistxattr" },
627 { SMB_VFS_OP_FLISTXATTR, "flistxattr" },
628 { SMB_VFS_OP_REMOVEXATTR, "removexattr" },
629 { SMB_VFS_OP_LREMOVEXATTR, "lremovexattr" },
630 { SMB_VFS_OP_FREMOVEXATTR, "fremovexattr" },
631 { SMB_VFS_OP_SETXATTR, "setxattr" },
632 { SMB_VFS_OP_LSETXATTR, "lsetxattr" },
633 { SMB_VFS_OP_FSETXATTR, "fsetxattr" },
634 { SMB_VFS_OP_AIO_READ, "aio_read" },
635 { SMB_VFS_OP_AIO_WRITE, "aio_write" },
636 { SMB_VFS_OP_AIO_RETURN,"aio_return" },
637 { SMB_VFS_OP_AIO_CANCEL,"aio_cancel" },
638 { SMB_VFS_OP_AIO_ERROR, "aio_error" },
639 { SMB_VFS_OP_AIO_FSYNC, "aio_fsync" },
640 { SMB_VFS_OP_AIO_SUSPEND,"aio_suspend" },
641 { SMB_VFS_OP_AIO_FORCE, "aio_force" },
642 { SMB_VFS_OP_IS_OFFLINE, "aio_is_offline" },
643 { SMB_VFS_OP_SET_OFFLINE, "aio_set_offline" },
644 { SMB_VFS_OP_LAST, NULL }
647 static int audit_syslog_facility(vfs_handle_struct *handle)
649 static const struct enum_list enum_log_facilities[] = {
650 { LOG_USER, "USER" },
651 { LOG_LOCAL0, "LOCAL0" },
652 { LOG_LOCAL1, "LOCAL1" },
653 { LOG_LOCAL2, "LOCAL2" },
654 { LOG_LOCAL3, "LOCAL3" },
655 { LOG_LOCAL4, "LOCAL4" },
656 { LOG_LOCAL5, "LOCAL5" },
657 { LOG_LOCAL6, "LOCAL6" },
658 { LOG_LOCAL7, "LOCAL7" }
661 int facility;
663 facility = lp_parm_enum(SNUM(handle->conn), "full_audit", "facility", enum_log_facilities, LOG_USER);
665 return facility;
668 static int audit_syslog_priority(vfs_handle_struct *handle)
670 static const struct enum_list enum_log_priorities[] = {
671 { LOG_EMERG, "EMERG" },
672 { LOG_ALERT, "ALERT" },
673 { LOG_CRIT, "CRIT" },
674 { LOG_ERR, "ERR" },
675 { LOG_WARNING, "WARNING" },
676 { LOG_NOTICE, "NOTICE" },
677 { LOG_INFO, "INFO" },
678 { LOG_DEBUG, "DEBUG" }
681 int priority;
683 priority = lp_parm_enum(SNUM(handle->conn), "full_audit", "priority",
684 enum_log_priorities, LOG_NOTICE);
685 if (priority == -1) {
686 priority = LOG_WARNING;
689 return priority;
692 static char *audit_prefix(TALLOC_CTX *ctx, connection_struct *conn)
694 char *prefix = NULL;
696 prefix = talloc_strdup(ctx,
697 lp_parm_const_string(SNUM(conn), "full_audit",
698 "prefix", "%u|%I"));
699 if (!prefix) {
700 return NULL;
702 return talloc_sub_advanced(ctx,
703 lp_servicename(SNUM(conn)),
704 conn->server_info->unix_name,
705 conn->connectpath,
706 conn->server_info->utok.gid,
707 conn->server_info->sanitized_username,
708 pdb_get_domain(conn->server_info->sam_account),
709 prefix);
712 static bool log_success(vfs_handle_struct *handle, vfs_op_type op)
714 struct vfs_full_audit_private_data *pd = NULL;
716 SMB_VFS_HANDLE_GET_DATA(handle, pd,
717 struct vfs_full_audit_private_data,
718 return True);
720 if (pd->success_ops == NULL) {
721 return True;
724 return bitmap_query(pd->success_ops, op);
727 static bool log_failure(vfs_handle_struct *handle, vfs_op_type op)
729 struct vfs_full_audit_private_data *pd = NULL;
731 SMB_VFS_HANDLE_GET_DATA(handle, pd,
732 struct vfs_full_audit_private_data,
733 return True);
735 if (pd->failure_ops == NULL)
736 return True;
738 return bitmap_query(pd->failure_ops, op);
741 static void init_bitmap(struct bitmap **bm, const char **ops)
743 bool log_all = False;
745 if (*bm != NULL)
746 return;
748 *bm = bitmap_allocate(SMB_VFS_OP_LAST);
750 if (*bm == NULL) {
751 DEBUG(0, ("Could not alloc bitmap -- "
752 "defaulting to logging everything\n"));
753 return;
756 while (*ops != NULL) {
757 int i;
758 bool found = False;
760 if (strequal(*ops, "all")) {
761 log_all = True;
762 break;
765 if (strequal(*ops, "none")) {
766 break;
769 for (i=0; i<SMB_VFS_OP_LAST; i++) {
770 if (vfs_op_names[i].name == NULL) {
771 smb_panic("vfs_full_audit.c: name table not "
772 "in sync with vfs.h\n");
775 if (strequal(*ops, vfs_op_names[i].name)) {
776 bitmap_set(*bm, i);
777 found = True;
780 if (!found) {
781 DEBUG(0, ("Could not find opname %s, logging all\n",
782 *ops));
783 log_all = True;
784 break;
786 ops += 1;
789 if (log_all) {
790 /* The query functions default to True */
791 bitmap_free(*bm);
792 *bm = NULL;
796 static const char *audit_opname(vfs_op_type op)
798 if (op >= SMB_VFS_OP_LAST)
799 return "INVALID VFS OP";
800 return vfs_op_names[op].name;
803 static void do_log(vfs_op_type op, bool success, vfs_handle_struct *handle,
804 const char *format, ...)
806 fstring err_msg;
807 char *audit_pre = NULL;
808 va_list ap;
809 char *op_msg = NULL;
811 if (success && (!log_success(handle, op)))
812 return;
814 if (!success && (!log_failure(handle, op)))
815 return;
817 if (success)
818 fstrcpy(err_msg, "ok");
819 else
820 fstr_sprintf(err_msg, "fail (%s)", strerror(errno));
822 va_start(ap, format);
823 op_msg = talloc_vasprintf(NULL, format, ap);
824 va_end(ap);
826 if (!op_msg) {
827 return;
830 audit_pre = audit_prefix(NULL, handle->conn);
831 syslog(audit_syslog_priority(handle), "%s|%s|%s|%s\n",
832 audit_pre ? audit_pre : "",
833 audit_opname(op), err_msg, op_msg);
835 TALLOC_FREE(audit_pre);
836 TALLOC_FREE(op_msg);
838 return;
841 /* Free function for the private data. */
843 static void free_private_data(void **p_data)
845 struct vfs_full_audit_private_data *pd = *(struct vfs_full_audit_private_data **)p_data;
847 if (pd->success_ops) {
848 bitmap_free(pd->success_ops);
850 if (pd->failure_ops) {
851 bitmap_free(pd->failure_ops);
853 SAFE_FREE(pd);
854 *p_data = NULL;
857 /* Implementation of vfs_ops. Pass everything on to the default
858 operation but log event first. */
860 static int smb_full_audit_connect(vfs_handle_struct *handle,
861 const char *svc, const char *user)
863 int result;
864 struct vfs_full_audit_private_data *pd = NULL;
865 const char *none[] = { NULL };
866 const char *all [] = { "all" };
868 if (!handle) {
869 return -1;
872 pd = SMB_MALLOC_P(struct vfs_full_audit_private_data);
873 if (!pd) {
874 return -1;
876 ZERO_STRUCTP(pd);
878 openlog("smbd_audit", 0, audit_syslog_facility(handle));
880 init_bitmap(&pd->success_ops,
881 lp_parm_string_list(SNUM(handle->conn), "full_audit", "success",
882 none));
883 init_bitmap(&pd->failure_ops,
884 lp_parm_string_list(SNUM(handle->conn), "full_audit", "failure",
885 all));
887 /* Store the private data. */
888 SMB_VFS_HANDLE_SET_DATA(handle, pd, free_private_data,
889 struct vfs_full_audit_private_data, return -1);
891 result = SMB_VFS_NEXT_CONNECT(handle, svc, user);
893 do_log(SMB_VFS_OP_CONNECT, True, handle,
894 "%s", svc);
896 return result;
899 static void smb_full_audit_disconnect(vfs_handle_struct *handle)
901 SMB_VFS_NEXT_DISCONNECT(handle);
903 do_log(SMB_VFS_OP_DISCONNECT, True, handle,
904 "%s", lp_servicename(SNUM(handle->conn)));
906 /* The bitmaps will be disconnected when the private
907 data is deleted. */
909 return;
912 static SMB_BIG_UINT smb_full_audit_disk_free(vfs_handle_struct *handle,
913 const char *path,
914 bool small_query, SMB_BIG_UINT *bsize,
915 SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize)
917 SMB_BIG_UINT result;
919 result = SMB_VFS_NEXT_DISK_FREE(handle, path, small_query, bsize,
920 dfree, dsize);
922 /* Don't have a reasonable notion of failure here */
924 do_log(SMB_VFS_OP_DISK_FREE, True, handle, "%s", path);
926 return result;
929 static int smb_full_audit_get_quota(struct vfs_handle_struct *handle,
930 enum SMB_QUOTA_TYPE qtype, unid_t id,
931 SMB_DISK_QUOTA *qt)
933 int result;
935 result = SMB_VFS_NEXT_GET_QUOTA(handle, qtype, id, qt);
937 do_log(SMB_VFS_OP_GET_QUOTA, (result >= 0), handle, "");
939 return result;
943 static int smb_full_audit_set_quota(struct vfs_handle_struct *handle,
944 enum SMB_QUOTA_TYPE qtype, unid_t id,
945 SMB_DISK_QUOTA *qt)
947 int result;
949 result = SMB_VFS_NEXT_SET_QUOTA(handle, qtype, id, qt);
951 do_log(SMB_VFS_OP_SET_QUOTA, (result >= 0), handle, "");
953 return result;
956 static int smb_full_audit_get_shadow_copy_data(struct vfs_handle_struct *handle,
957 struct files_struct *fsp,
958 SHADOW_COPY_DATA *shadow_copy_data, bool labels)
960 int result;
962 result = SMB_VFS_NEXT_GET_SHADOW_COPY_DATA(handle, fsp, shadow_copy_data, labels);
964 do_log(SMB_VFS_OP_GET_SHADOW_COPY_DATA, (result >= 0), handle, "");
966 return result;
969 static int smb_full_audit_statvfs(struct vfs_handle_struct *handle,
970 const char *path,
971 struct vfs_statvfs_struct *statbuf)
973 int result;
975 result = SMB_VFS_NEXT_STATVFS(handle, path, statbuf);
977 do_log(SMB_VFS_OP_STATVFS, (result >= 0), handle, "");
979 return result;
982 static SMB_STRUCT_DIR *smb_full_audit_opendir(vfs_handle_struct *handle,
983 const char *fname, const char *mask, uint32 attr)
985 SMB_STRUCT_DIR *result;
987 result = SMB_VFS_NEXT_OPENDIR(handle, fname, mask, attr);
989 do_log(SMB_VFS_OP_OPENDIR, (result != NULL), handle, "%s", fname);
991 return result;
994 static SMB_STRUCT_DIRENT *smb_full_audit_readdir(vfs_handle_struct *handle,
995 SMB_STRUCT_DIR *dirp)
997 SMB_STRUCT_DIRENT *result;
999 result = SMB_VFS_NEXT_READDIR(handle, dirp);
1001 /* This operation has no reasonable error condition
1002 * (End of dir is also failure), so always succeed.
1004 do_log(SMB_VFS_OP_READDIR, True, handle, "");
1006 return result;
1009 static void smb_full_audit_seekdir(vfs_handle_struct *handle,
1010 SMB_STRUCT_DIR *dirp, long offset)
1012 SMB_VFS_NEXT_SEEKDIR(handle, dirp, offset);
1014 do_log(SMB_VFS_OP_SEEKDIR, True, handle, "");
1015 return;
1018 static long smb_full_audit_telldir(vfs_handle_struct *handle,
1019 SMB_STRUCT_DIR *dirp)
1021 long result;
1023 result = SMB_VFS_NEXT_TELLDIR(handle, dirp);
1025 do_log(SMB_VFS_OP_TELLDIR, True, handle, "");
1027 return result;
1030 static void smb_full_audit_rewinddir(vfs_handle_struct *handle,
1031 SMB_STRUCT_DIR *dirp)
1033 SMB_VFS_NEXT_REWINDDIR(handle, dirp);
1035 do_log(SMB_VFS_OP_REWINDDIR, True, handle, "");
1036 return;
1039 static int smb_full_audit_mkdir(vfs_handle_struct *handle,
1040 const char *path, mode_t mode)
1042 int result;
1044 result = SMB_VFS_NEXT_MKDIR(handle, path, mode);
1046 do_log(SMB_VFS_OP_MKDIR, (result >= 0), handle, "%s", path);
1048 return result;
1051 static int smb_full_audit_rmdir(vfs_handle_struct *handle,
1052 const char *path)
1054 int result;
1056 result = SMB_VFS_NEXT_RMDIR(handle, path);
1058 do_log(SMB_VFS_OP_RMDIR, (result >= 0), handle, "%s", path);
1060 return result;
1063 static int smb_full_audit_closedir(vfs_handle_struct *handle,
1064 SMB_STRUCT_DIR *dirp)
1066 int result;
1068 result = SMB_VFS_NEXT_CLOSEDIR(handle, dirp);
1070 do_log(SMB_VFS_OP_CLOSEDIR, (result >= 0), handle, "");
1072 return result;
1075 static int smb_full_audit_open(vfs_handle_struct *handle,
1076 const char *fname, files_struct *fsp, int flags, mode_t mode)
1078 int result;
1080 result = SMB_VFS_NEXT_OPEN(handle, fname, fsp, flags, mode);
1082 do_log(SMB_VFS_OP_OPEN, (result >= 0), handle, "%s|%s",
1083 ((flags & O_WRONLY) || (flags & O_RDWR))?"w":"r",
1084 fname);
1086 return result;
1089 static int smb_full_audit_close(vfs_handle_struct *handle, files_struct *fsp)
1091 int result;
1093 result = SMB_VFS_NEXT_CLOSE(handle, fsp);
1095 do_log(SMB_VFS_OP_CLOSE, (result >= 0), handle, "%s", fsp->fsp_name);
1097 return result;
1100 static ssize_t smb_full_audit_read(vfs_handle_struct *handle, files_struct *fsp,
1101 void *data, size_t n)
1103 ssize_t result;
1105 result = SMB_VFS_NEXT_READ(handle, fsp, data, n);
1107 do_log(SMB_VFS_OP_READ, (result >= 0), handle, "%s", fsp->fsp_name);
1109 return result;
1112 static ssize_t smb_full_audit_pread(vfs_handle_struct *handle, files_struct *fsp,
1113 void *data, size_t n, SMB_OFF_T offset)
1115 ssize_t result;
1117 result = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
1119 do_log(SMB_VFS_OP_PREAD, (result >= 0), handle, "%s", fsp->fsp_name);
1121 return result;
1124 static ssize_t smb_full_audit_write(vfs_handle_struct *handle, files_struct *fsp,
1125 const void *data, size_t n)
1127 ssize_t result;
1129 result = SMB_VFS_NEXT_WRITE(handle, fsp, data, n);
1131 do_log(SMB_VFS_OP_WRITE, (result >= 0), handle, "%s", fsp->fsp_name);
1133 return result;
1136 static ssize_t smb_full_audit_pwrite(vfs_handle_struct *handle, files_struct *fsp,
1137 const void *data, size_t n,
1138 SMB_OFF_T offset)
1140 ssize_t result;
1142 result = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
1144 do_log(SMB_VFS_OP_PWRITE, (result >= 0), handle, "%s", fsp->fsp_name);
1146 return result;
1149 static SMB_OFF_T smb_full_audit_lseek(vfs_handle_struct *handle, files_struct *fsp,
1150 SMB_OFF_T offset, int whence)
1152 ssize_t result;
1154 result = SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence);
1156 do_log(SMB_VFS_OP_LSEEK, (result != (ssize_t)-1), handle,
1157 "%s", fsp->fsp_name);
1159 return result;
1162 static ssize_t smb_full_audit_sendfile(vfs_handle_struct *handle, int tofd,
1163 files_struct *fromfsp,
1164 const DATA_BLOB *hdr, SMB_OFF_T offset,
1165 size_t n)
1167 ssize_t result;
1169 result = SMB_VFS_NEXT_SENDFILE(handle, tofd, fromfsp, hdr, offset, n);
1171 do_log(SMB_VFS_OP_SENDFILE, (result >= 0), handle,
1172 "%s", fromfsp->fsp_name);
1174 return result;
1177 static ssize_t smb_full_audit_recvfile(vfs_handle_struct *handle, int fromfd,
1178 files_struct *tofsp,
1179 SMB_OFF_T offset,
1180 size_t n)
1182 ssize_t result;
1184 result = SMB_VFS_NEXT_RECVFILE(handle, fromfd, tofsp, offset, n);
1186 do_log(SMB_VFS_OP_RECVFILE, (result >= 0), handle,
1187 "%s", tofsp->fsp_name);
1189 return result;
1192 static int smb_full_audit_rename(vfs_handle_struct *handle,
1193 const char *oldname, const char *newname)
1195 int result;
1197 result = SMB_VFS_NEXT_RENAME(handle, oldname, newname);
1199 do_log(SMB_VFS_OP_RENAME, (result >= 0), handle, "%s|%s", oldname, newname);
1201 return result;
1204 static int smb_full_audit_fsync(vfs_handle_struct *handle, files_struct *fsp)
1206 int result;
1208 result = SMB_VFS_NEXT_FSYNC(handle, fsp);
1210 do_log(SMB_VFS_OP_FSYNC, (result >= 0), handle, "%s", fsp->fsp_name);
1212 return result;
1215 static int smb_full_audit_stat(vfs_handle_struct *handle,
1216 const char *fname, SMB_STRUCT_STAT *sbuf)
1218 int result;
1220 result = SMB_VFS_NEXT_STAT(handle, fname, sbuf);
1222 do_log(SMB_VFS_OP_STAT, (result >= 0), handle, "%s", fname);
1224 return result;
1227 static int smb_full_audit_fstat(vfs_handle_struct *handle, files_struct *fsp,
1228 SMB_STRUCT_STAT *sbuf)
1230 int result;
1232 result = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1234 do_log(SMB_VFS_OP_FSTAT, (result >= 0), handle, "%s", fsp->fsp_name);
1236 return result;
1239 static int smb_full_audit_lstat(vfs_handle_struct *handle,
1240 const char *path, SMB_STRUCT_STAT *sbuf)
1242 int result;
1244 result = SMB_VFS_NEXT_LSTAT(handle, path, sbuf);
1246 do_log(SMB_VFS_OP_LSTAT, (result >= 0), handle, "%s", path);
1248 return result;
1251 static int smb_full_audit_unlink(vfs_handle_struct *handle,
1252 const char *path)
1254 int result;
1256 result = SMB_VFS_NEXT_UNLINK(handle, path);
1258 do_log(SMB_VFS_OP_UNLINK, (result >= 0), handle, "%s", path);
1260 return result;
1263 static int smb_full_audit_chmod(vfs_handle_struct *handle,
1264 const char *path, mode_t mode)
1266 int result;
1268 result = SMB_VFS_NEXT_CHMOD(handle, path, mode);
1270 do_log(SMB_VFS_OP_CHMOD, (result >= 0), handle, "%s|%o", path, mode);
1272 return result;
1275 static int smb_full_audit_fchmod(vfs_handle_struct *handle, files_struct *fsp,
1276 mode_t mode)
1278 int result;
1280 result = SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1282 do_log(SMB_VFS_OP_FCHMOD, (result >= 0), handle,
1283 "%s|%o", fsp->fsp_name, mode);
1285 return result;
1288 static int smb_full_audit_chown(vfs_handle_struct *handle,
1289 const char *path, uid_t uid, gid_t gid)
1291 int result;
1293 result = SMB_VFS_NEXT_CHOWN(handle, path, uid, gid);
1295 do_log(SMB_VFS_OP_CHOWN, (result >= 0), handle, "%s|%ld|%ld",
1296 path, (long int)uid, (long int)gid);
1298 return result;
1301 static int smb_full_audit_fchown(vfs_handle_struct *handle, files_struct *fsp,
1302 uid_t uid, gid_t gid)
1304 int result;
1306 result = SMB_VFS_NEXT_FCHOWN(handle, fsp, uid, gid);
1308 do_log(SMB_VFS_OP_FCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1309 fsp->fsp_name, (long int)uid, (long int)gid);
1311 return result;
1314 static int smb_full_audit_lchown(vfs_handle_struct *handle,
1315 const char *path, uid_t uid, gid_t gid)
1317 int result;
1319 result = SMB_VFS_NEXT_LCHOWN(handle, path, uid, gid);
1321 do_log(SMB_VFS_OP_LCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1322 path, (long int)uid, (long int)gid);
1324 return result;
1327 static int smb_full_audit_chdir(vfs_handle_struct *handle,
1328 const char *path)
1330 int result;
1332 result = SMB_VFS_NEXT_CHDIR(handle, path);
1334 do_log(SMB_VFS_OP_CHDIR, (result >= 0), handle, "chdir|%s", path);
1336 return result;
1339 static char *smb_full_audit_getwd(vfs_handle_struct *handle,
1340 char *path)
1342 char *result;
1344 result = SMB_VFS_NEXT_GETWD(handle, path);
1346 do_log(SMB_VFS_OP_GETWD, (result != NULL), handle, "%s", path);
1348 return result;
1351 static int smb_full_audit_ntimes(vfs_handle_struct *handle,
1352 const char *path, const struct timespec ts[2])
1354 int result;
1356 result = SMB_VFS_NEXT_NTIMES(handle, path, ts);
1358 do_log(SMB_VFS_OP_NTIMES, (result >= 0), handle, "%s", path);
1360 return result;
1363 static int smb_full_audit_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
1364 SMB_OFF_T len)
1366 int result;
1368 result = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1370 do_log(SMB_VFS_OP_FTRUNCATE, (result >= 0), handle,
1371 "%s", fsp->fsp_name);
1373 return result;
1376 static bool smb_full_audit_lock(vfs_handle_struct *handle, files_struct *fsp,
1377 int op, SMB_OFF_T offset, SMB_OFF_T count, int type)
1379 bool result;
1381 result = SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type);
1383 do_log(SMB_VFS_OP_LOCK, result, handle, "%s", fsp->fsp_name);
1385 return result;
1388 static int smb_full_audit_kernel_flock(struct vfs_handle_struct *handle,
1389 struct files_struct *fsp,
1390 uint32 share_mode)
1392 int result;
1394 result = SMB_VFS_NEXT_KERNEL_FLOCK(handle, fsp, share_mode);
1396 do_log(SMB_VFS_OP_KERNEL_FLOCK, (result >= 0), handle, "%s",
1397 fsp->fsp_name);
1399 return result;
1402 static int smb_full_audit_linux_setlease(vfs_handle_struct *handle, files_struct *fsp,
1403 int leasetype)
1405 int result;
1407 result = SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
1409 do_log(SMB_VFS_OP_LINUX_SETLEASE, (result >= 0), handle, "%s",
1410 fsp->fsp_name);
1412 return result;
1415 static bool smb_full_audit_getlock(vfs_handle_struct *handle, files_struct *fsp,
1416 SMB_OFF_T *poffset, SMB_OFF_T *pcount, int *ptype, pid_t *ppid)
1418 bool result;
1420 result = SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype, ppid);
1422 do_log(SMB_VFS_OP_GETLOCK, result, handle, "%s", fsp->fsp_name);
1424 return result;
1427 static int smb_full_audit_symlink(vfs_handle_struct *handle,
1428 const char *oldpath, const char *newpath)
1430 int result;
1432 result = SMB_VFS_NEXT_SYMLINK(handle, oldpath, newpath);
1434 do_log(SMB_VFS_OP_SYMLINK, (result >= 0), handle,
1435 "%s|%s", oldpath, newpath);
1437 return result;
1440 static int smb_full_audit_readlink(vfs_handle_struct *handle,
1441 const char *path, char *buf, size_t bufsiz)
1443 int result;
1445 result = SMB_VFS_NEXT_READLINK(handle, path, buf, bufsiz);
1447 do_log(SMB_VFS_OP_READLINK, (result >= 0), handle, "%s", path);
1449 return result;
1452 static int smb_full_audit_link(vfs_handle_struct *handle,
1453 const char *oldpath, const char *newpath)
1455 int result;
1457 result = SMB_VFS_NEXT_LINK(handle, oldpath, newpath);
1459 do_log(SMB_VFS_OP_LINK, (result >= 0), handle,
1460 "%s|%s", oldpath, newpath);
1462 return result;
1465 static int smb_full_audit_mknod(vfs_handle_struct *handle,
1466 const char *pathname, mode_t mode, SMB_DEV_T dev)
1468 int result;
1470 result = SMB_VFS_NEXT_MKNOD(handle, pathname, mode, dev);
1472 do_log(SMB_VFS_OP_MKNOD, (result >= 0), handle, "%s", pathname);
1474 return result;
1477 static char *smb_full_audit_realpath(vfs_handle_struct *handle,
1478 const char *path, char *resolved_path)
1480 char *result;
1482 result = SMB_VFS_NEXT_REALPATH(handle, path, resolved_path);
1484 do_log(SMB_VFS_OP_REALPATH, (result != NULL), handle, "%s", path);
1486 return result;
1489 static NTSTATUS smb_full_audit_notify_watch(struct vfs_handle_struct *handle,
1490 struct sys_notify_context *ctx,
1491 struct notify_entry *e,
1492 void (*callback)(struct sys_notify_context *ctx,
1493 void *private_data,
1494 struct notify_event *ev),
1495 void *private_data, void *handle_p)
1497 NTSTATUS result;
1499 result = SMB_VFS_NEXT_NOTIFY_WATCH(handle, ctx, e, callback, private_data, handle_p);
1501 do_log(SMB_VFS_OP_NOTIFY_WATCH, NT_STATUS_IS_OK(result), handle, "");
1503 return result;
1506 static int smb_full_audit_chflags(vfs_handle_struct *handle,
1507 const char *path, unsigned int flags)
1509 int result;
1511 result = SMB_VFS_NEXT_CHFLAGS(handle, path, flags);
1513 do_log(SMB_VFS_OP_CHFLAGS, (result != 0), handle, "%s", path);
1515 return result;
1518 static struct file_id smb_full_audit_file_id_create(struct vfs_handle_struct *handle,
1519 SMB_DEV_T dev, SMB_INO_T inode)
1521 struct file_id id_zero;
1522 struct file_id result;
1524 ZERO_STRUCT(id_zero);
1526 result = SMB_VFS_NEXT_FILE_ID_CREATE(handle, dev, inode);
1528 do_log(SMB_VFS_OP_FILE_ID_CREATE,
1529 !file_id_equal(&id_zero, &result),
1530 handle, "%s", file_id_string_tos(&result));
1532 return result;
1535 static NTSTATUS smb_full_audit_streaminfo(vfs_handle_struct *handle,
1536 struct files_struct *fsp,
1537 const char *fname,
1538 TALLOC_CTX *mem_ctx,
1539 unsigned int *pnum_streams,
1540 struct stream_struct **pstreams)
1542 NTSTATUS result;
1544 result = SMB_VFS_NEXT_STREAMINFO(handle, fsp, fname, mem_ctx,
1545 pnum_streams, pstreams);
1547 do_log(SMB_VFS_OP_STREAMINFO, NT_STATUS_IS_OK(result), handle,
1548 "%s", fname);
1550 return result;
1553 static NTSTATUS smb_full_audit_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
1554 uint32 security_info,
1555 SEC_DESC **ppdesc)
1557 NTSTATUS result;
1559 result = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info, ppdesc);
1561 do_log(SMB_VFS_OP_FGET_NT_ACL, NT_STATUS_IS_OK(result), handle,
1562 "%s", fsp->fsp_name);
1564 return result;
1567 static NTSTATUS smb_full_audit_get_nt_acl(vfs_handle_struct *handle,
1568 files_struct *fsp,
1569 const char *name,
1570 uint32 security_info,
1571 SEC_DESC **ppdesc)
1573 NTSTATUS result;
1575 result = SMB_VFS_NEXT_GET_NT_ACL(handle, name, security_info, ppdesc);
1577 do_log(SMB_VFS_OP_GET_NT_ACL, NT_STATUS_IS_OK(result), handle,
1578 "%s", fsp->fsp_name);
1580 return result;
1583 static NTSTATUS smb_full_audit_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
1584 uint32 security_info_sent,
1585 SEC_DESC *psd)
1587 NTSTATUS result;
1589 result = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
1591 do_log(SMB_VFS_OP_FSET_NT_ACL, NT_STATUS_IS_OK(result), handle, "%s", fsp->fsp_name);
1593 return result;
1596 static int smb_full_audit_chmod_acl(vfs_handle_struct *handle,
1597 const char *path, mode_t mode)
1599 int result;
1601 result = SMB_VFS_NEXT_CHMOD_ACL(handle, path, mode);
1603 do_log(SMB_VFS_OP_CHMOD_ACL, (result >= 0), handle,
1604 "%s|%o", path, mode);
1606 return result;
1609 static int smb_full_audit_fchmod_acl(vfs_handle_struct *handle, files_struct *fsp,
1610 mode_t mode)
1612 int result;
1614 result = SMB_VFS_NEXT_FCHMOD_ACL(handle, fsp, mode);
1616 do_log(SMB_VFS_OP_FCHMOD_ACL, (result >= 0), handle,
1617 "%s|%o", fsp->fsp_name, mode);
1619 return result;
1622 static int smb_full_audit_sys_acl_get_entry(vfs_handle_struct *handle,
1624 SMB_ACL_T theacl, int entry_id,
1625 SMB_ACL_ENTRY_T *entry_p)
1627 int result;
1629 result = SMB_VFS_NEXT_SYS_ACL_GET_ENTRY(handle, theacl, entry_id,
1630 entry_p);
1632 do_log(SMB_VFS_OP_SYS_ACL_GET_ENTRY, (result >= 0), handle,
1633 "");
1635 return result;
1638 static int smb_full_audit_sys_acl_get_tag_type(vfs_handle_struct *handle,
1640 SMB_ACL_ENTRY_T entry_d,
1641 SMB_ACL_TAG_T *tag_type_p)
1643 int result;
1645 result = SMB_VFS_NEXT_SYS_ACL_GET_TAG_TYPE(handle, entry_d,
1646 tag_type_p);
1648 do_log(SMB_VFS_OP_SYS_ACL_GET_TAG_TYPE, (result >= 0), handle,
1649 "");
1651 return result;
1654 static int smb_full_audit_sys_acl_get_permset(vfs_handle_struct *handle,
1656 SMB_ACL_ENTRY_T entry_d,
1657 SMB_ACL_PERMSET_T *permset_p)
1659 int result;
1661 result = SMB_VFS_NEXT_SYS_ACL_GET_PERMSET(handle, entry_d,
1662 permset_p);
1664 do_log(SMB_VFS_OP_SYS_ACL_GET_PERMSET, (result >= 0), handle,
1665 "");
1667 return result;
1670 static void * smb_full_audit_sys_acl_get_qualifier(vfs_handle_struct *handle,
1672 SMB_ACL_ENTRY_T entry_d)
1674 void *result;
1676 result = SMB_VFS_NEXT_SYS_ACL_GET_QUALIFIER(handle, entry_d);
1678 do_log(SMB_VFS_OP_SYS_ACL_GET_QUALIFIER, (result != NULL), handle,
1679 "");
1681 return result;
1684 static SMB_ACL_T smb_full_audit_sys_acl_get_file(vfs_handle_struct *handle,
1685 const char *path_p,
1686 SMB_ACL_TYPE_T type)
1688 SMB_ACL_T result;
1690 result = SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, path_p, type);
1692 do_log(SMB_VFS_OP_SYS_ACL_GET_FILE, (result != NULL), handle,
1693 "%s", path_p);
1695 return result;
1698 static SMB_ACL_T smb_full_audit_sys_acl_get_fd(vfs_handle_struct *handle,
1699 files_struct *fsp)
1701 SMB_ACL_T result;
1703 result = SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp);
1705 do_log(SMB_VFS_OP_SYS_ACL_GET_FD, (result != NULL), handle,
1706 "%s", fsp->fsp_name);
1708 return result;
1711 static int smb_full_audit_sys_acl_clear_perms(vfs_handle_struct *handle,
1713 SMB_ACL_PERMSET_T permset)
1715 int result;
1717 result = SMB_VFS_NEXT_SYS_ACL_CLEAR_PERMS(handle, permset);
1719 do_log(SMB_VFS_OP_SYS_ACL_CLEAR_PERMS, (result >= 0), handle,
1720 "");
1722 return result;
1725 static int smb_full_audit_sys_acl_add_perm(vfs_handle_struct *handle,
1727 SMB_ACL_PERMSET_T permset,
1728 SMB_ACL_PERM_T perm)
1730 int result;
1732 result = SMB_VFS_NEXT_SYS_ACL_ADD_PERM(handle, permset, perm);
1734 do_log(SMB_VFS_OP_SYS_ACL_ADD_PERM, (result >= 0), handle,
1735 "");
1737 return result;
1740 static char * smb_full_audit_sys_acl_to_text(vfs_handle_struct *handle,
1741 SMB_ACL_T theacl,
1742 ssize_t *plen)
1744 char * result;
1746 result = SMB_VFS_NEXT_SYS_ACL_TO_TEXT(handle, theacl, plen);
1748 do_log(SMB_VFS_OP_SYS_ACL_TO_TEXT, (result != NULL), handle,
1749 "");
1751 return result;
1754 static SMB_ACL_T smb_full_audit_sys_acl_init(vfs_handle_struct *handle,
1756 int count)
1758 SMB_ACL_T result;
1760 result = SMB_VFS_NEXT_SYS_ACL_INIT(handle, count);
1762 do_log(SMB_VFS_OP_SYS_ACL_INIT, (result != NULL), handle,
1763 "");
1765 return result;
1768 static int smb_full_audit_sys_acl_create_entry(vfs_handle_struct *handle,
1769 SMB_ACL_T *pacl,
1770 SMB_ACL_ENTRY_T *pentry)
1772 int result;
1774 result = SMB_VFS_NEXT_SYS_ACL_CREATE_ENTRY(handle, pacl, pentry);
1776 do_log(SMB_VFS_OP_SYS_ACL_CREATE_ENTRY, (result >= 0), handle,
1777 "");
1779 return result;
1782 static int smb_full_audit_sys_acl_set_tag_type(vfs_handle_struct *handle,
1784 SMB_ACL_ENTRY_T entry,
1785 SMB_ACL_TAG_T tagtype)
1787 int result;
1789 result = SMB_VFS_NEXT_SYS_ACL_SET_TAG_TYPE(handle, entry,
1790 tagtype);
1792 do_log(SMB_VFS_OP_SYS_ACL_SET_TAG_TYPE, (result >= 0), handle,
1793 "");
1795 return result;
1798 static int smb_full_audit_sys_acl_set_qualifier(vfs_handle_struct *handle,
1800 SMB_ACL_ENTRY_T entry,
1801 void *qual)
1803 int result;
1805 result = SMB_VFS_NEXT_SYS_ACL_SET_QUALIFIER(handle, entry, qual);
1807 do_log(SMB_VFS_OP_SYS_ACL_SET_QUALIFIER, (result >= 0), handle,
1808 "");
1810 return result;
1813 static int smb_full_audit_sys_acl_set_permset(vfs_handle_struct *handle,
1815 SMB_ACL_ENTRY_T entry,
1816 SMB_ACL_PERMSET_T permset)
1818 int result;
1820 result = SMB_VFS_NEXT_SYS_ACL_SET_PERMSET(handle, entry, permset);
1822 do_log(SMB_VFS_OP_SYS_ACL_SET_PERMSET, (result >= 0), handle,
1823 "");
1825 return result;
1828 static int smb_full_audit_sys_acl_valid(vfs_handle_struct *handle,
1830 SMB_ACL_T theacl )
1832 int result;
1834 result = SMB_VFS_NEXT_SYS_ACL_VALID(handle, theacl);
1836 do_log(SMB_VFS_OP_SYS_ACL_VALID, (result >= 0), handle,
1837 "");
1839 return result;
1842 static int smb_full_audit_sys_acl_set_file(vfs_handle_struct *handle,
1844 const char *name, SMB_ACL_TYPE_T acltype,
1845 SMB_ACL_T theacl)
1847 int result;
1849 result = SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, name, acltype,
1850 theacl);
1852 do_log(SMB_VFS_OP_SYS_ACL_SET_FILE, (result >= 0), handle,
1853 "%s", name);
1855 return result;
1858 static int smb_full_audit_sys_acl_set_fd(vfs_handle_struct *handle, files_struct *fsp,
1859 SMB_ACL_T theacl)
1861 int result;
1863 result = SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, theacl);
1865 do_log(SMB_VFS_OP_SYS_ACL_SET_FD, (result >= 0), handle,
1866 "%s", fsp->fsp_name);
1868 return result;
1871 static int smb_full_audit_sys_acl_delete_def_file(vfs_handle_struct *handle,
1873 const char *path)
1875 int result;
1877 result = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, path);
1879 do_log(SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE, (result >= 0), handle,
1880 "%s", path);
1882 return result;
1885 static int smb_full_audit_sys_acl_get_perm(vfs_handle_struct *handle,
1887 SMB_ACL_PERMSET_T permset,
1888 SMB_ACL_PERM_T perm)
1890 int result;
1892 result = SMB_VFS_NEXT_SYS_ACL_GET_PERM(handle, permset, perm);
1894 do_log(SMB_VFS_OP_SYS_ACL_GET_PERM, (result >= 0), handle,
1895 "");
1897 return result;
1900 static int smb_full_audit_sys_acl_free_text(vfs_handle_struct *handle,
1902 char *text)
1904 int result;
1906 result = SMB_VFS_NEXT_SYS_ACL_FREE_TEXT(handle, text);
1908 do_log(SMB_VFS_OP_SYS_ACL_FREE_TEXT, (result >= 0), handle,
1909 "");
1911 return result;
1914 static int smb_full_audit_sys_acl_free_acl(vfs_handle_struct *handle,
1916 SMB_ACL_T posix_acl)
1918 int result;
1920 result = SMB_VFS_NEXT_SYS_ACL_FREE_ACL(handle, posix_acl);
1922 do_log(SMB_VFS_OP_SYS_ACL_FREE_ACL, (result >= 0), handle,
1923 "");
1925 return result;
1928 static int smb_full_audit_sys_acl_free_qualifier(vfs_handle_struct *handle,
1929 void *qualifier,
1930 SMB_ACL_TAG_T tagtype)
1932 int result;
1934 result = SMB_VFS_NEXT_SYS_ACL_FREE_QUALIFIER(handle, qualifier,
1935 tagtype);
1937 do_log(SMB_VFS_OP_SYS_ACL_FREE_QUALIFIER, (result >= 0), handle,
1938 "");
1940 return result;
1943 static ssize_t smb_full_audit_getxattr(struct vfs_handle_struct *handle,
1944 const char *path,
1945 const char *name, void *value, size_t size)
1947 ssize_t result;
1949 result = SMB_VFS_NEXT_GETXATTR(handle, path, name, value, size);
1951 do_log(SMB_VFS_OP_GETXATTR, (result >= 0), handle,
1952 "%s|%s", path, name);
1954 return result;
1957 static ssize_t smb_full_audit_lgetxattr(struct vfs_handle_struct *handle,
1958 const char *path, const char *name,
1959 void *value, size_t size)
1961 ssize_t result;
1963 result = SMB_VFS_NEXT_LGETXATTR(handle, path, name, value, size);
1965 do_log(SMB_VFS_OP_LGETXATTR, (result >= 0), handle,
1966 "%s|%s", path, name);
1968 return result;
1971 static ssize_t smb_full_audit_fgetxattr(struct vfs_handle_struct *handle,
1972 struct files_struct *fsp,
1973 const char *name, void *value, size_t size)
1975 ssize_t result;
1977 result = SMB_VFS_NEXT_FGETXATTR(handle, fsp, name, value, size);
1979 do_log(SMB_VFS_OP_FGETXATTR, (result >= 0), handle,
1980 "%s|%s", fsp->fsp_name, name);
1982 return result;
1985 static ssize_t smb_full_audit_listxattr(struct vfs_handle_struct *handle,
1986 const char *path, char *list, size_t size)
1988 ssize_t result;
1990 result = SMB_VFS_NEXT_LISTXATTR(handle, path, list, size);
1992 do_log(SMB_VFS_OP_LISTXATTR, (result >= 0), handle, "%s", path);
1994 return result;
1997 static ssize_t smb_full_audit_llistxattr(struct vfs_handle_struct *handle,
1998 const char *path, char *list, size_t size)
2000 ssize_t result;
2002 result = SMB_VFS_NEXT_LLISTXATTR(handle, path, list, size);
2004 do_log(SMB_VFS_OP_LLISTXATTR, (result >= 0), handle, "%s", path);
2006 return result;
2009 static ssize_t smb_full_audit_flistxattr(struct vfs_handle_struct *handle,
2010 struct files_struct *fsp, char *list,
2011 size_t size)
2013 ssize_t result;
2015 result = SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
2017 do_log(SMB_VFS_OP_FLISTXATTR, (result >= 0), handle,
2018 "%s", fsp->fsp_name);
2020 return result;
2023 static int smb_full_audit_removexattr(struct vfs_handle_struct *handle,
2024 const char *path,
2025 const char *name)
2027 int result;
2029 result = SMB_VFS_NEXT_REMOVEXATTR(handle, path, name);
2031 do_log(SMB_VFS_OP_REMOVEXATTR, (result >= 0), handle,
2032 "%s|%s", path, name);
2034 return result;
2037 static int smb_full_audit_lremovexattr(struct vfs_handle_struct *handle,
2038 const char *path,
2039 const char *name)
2041 int result;
2043 result = SMB_VFS_NEXT_LREMOVEXATTR(handle, path, name);
2045 do_log(SMB_VFS_OP_LREMOVEXATTR, (result >= 0), handle,
2046 "%s|%s", path, name);
2048 return result;
2051 static int smb_full_audit_fremovexattr(struct vfs_handle_struct *handle,
2052 struct files_struct *fsp,
2053 const char *name)
2055 int result;
2057 result = SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, name);
2059 do_log(SMB_VFS_OP_FREMOVEXATTR, (result >= 0), handle,
2060 "%s|%s", fsp->fsp_name, name);
2062 return result;
2065 static int smb_full_audit_setxattr(struct vfs_handle_struct *handle,
2066 const char *path,
2067 const char *name, const void *value, size_t size,
2068 int flags)
2070 int result;
2072 result = SMB_VFS_NEXT_SETXATTR(handle, path, name, value, size,
2073 flags);
2075 do_log(SMB_VFS_OP_SETXATTR, (result >= 0), handle,
2076 "%s|%s", path, name);
2078 return result;
2081 static int smb_full_audit_lsetxattr(struct vfs_handle_struct *handle,
2082 const char *path,
2083 const char *name, const void *value, size_t size,
2084 int flags)
2086 int result;
2088 result = SMB_VFS_NEXT_LSETXATTR(handle, path, name, value, size,
2089 flags);
2091 do_log(SMB_VFS_OP_LSETXATTR, (result >= 0), handle,
2092 "%s|%s", path, name);
2094 return result;
2097 static int smb_full_audit_fsetxattr(struct vfs_handle_struct *handle,
2098 struct files_struct *fsp, const char *name,
2099 const void *value, size_t size, int flags)
2101 int result;
2103 result = SMB_VFS_NEXT_FSETXATTR(handle, fsp, name, value, size, flags);
2105 do_log(SMB_VFS_OP_FSETXATTR, (result >= 0), handle,
2106 "%s|%s", fsp->fsp_name, name);
2108 return result;
2111 static int smb_full_audit_aio_read(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
2113 int result;
2115 result = SMB_VFS_NEXT_AIO_READ(handle, fsp, aiocb);
2116 do_log(SMB_VFS_OP_AIO_READ, (result >= 0), handle,
2117 "%s", fsp->fsp_name);
2119 return result;
2122 static int smb_full_audit_aio_write(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
2124 int result;
2126 result = SMB_VFS_NEXT_AIO_WRITE(handle, fsp, aiocb);
2127 do_log(SMB_VFS_OP_AIO_WRITE, (result >= 0), handle,
2128 "%s", fsp->fsp_name);
2130 return result;
2133 static ssize_t smb_full_audit_aio_return(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
2135 int result;
2137 result = SMB_VFS_NEXT_AIO_RETURN(handle, fsp, aiocb);
2138 do_log(SMB_VFS_OP_AIO_RETURN, (result >= 0), handle,
2139 "%s", fsp->fsp_name);
2141 return result;
2144 static int smb_full_audit_aio_cancel(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
2146 int result;
2148 result = SMB_VFS_NEXT_AIO_CANCEL(handle, fsp, aiocb);
2149 do_log(SMB_VFS_OP_AIO_CANCEL, (result >= 0), handle,
2150 "%s", fsp->fsp_name);
2152 return result;
2155 static int smb_full_audit_aio_error(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
2157 int result;
2159 result = SMB_VFS_NEXT_AIO_ERROR(handle, fsp, aiocb);
2160 do_log(SMB_VFS_OP_AIO_ERROR, (result >= 0), handle,
2161 "%s", fsp->fsp_name);
2163 return result;
2166 static int smb_full_audit_aio_fsync(struct vfs_handle_struct *handle, struct files_struct *fsp, int op, SMB_STRUCT_AIOCB *aiocb)
2168 int result;
2170 result = SMB_VFS_NEXT_AIO_FSYNC(handle, fsp, op, aiocb);
2171 do_log(SMB_VFS_OP_AIO_FSYNC, (result >= 0), handle,
2172 "%s", fsp->fsp_name);
2174 return result;
2177 static int smb_full_audit_aio_suspend(struct vfs_handle_struct *handle, struct files_struct *fsp, const SMB_STRUCT_AIOCB * const aiocb[], int n, const struct timespec *ts)
2179 int result;
2181 result = SMB_VFS_NEXT_AIO_SUSPEND(handle, fsp, aiocb, n, ts);
2182 do_log(SMB_VFS_OP_AIO_SUSPEND, (result >= 0), handle,
2183 "%s", fsp->fsp_name);
2185 return result;
2189 NTSTATUS vfs_full_audit_init(void);
2190 NTSTATUS vfs_full_audit_init(void)
2192 NTSTATUS ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION,
2193 "full_audit", audit_op_tuples);
2195 if (!NT_STATUS_IS_OK(ret))
2196 return ret;
2198 vfs_full_audit_debug_level = debug_add_class("full_audit");
2199 if (vfs_full_audit_debug_level == -1) {
2200 vfs_full_audit_debug_level = DBGC_VFS;
2201 DEBUG(0, ("vfs_full_audit: Couldn't register custom debugging "
2202 "class!\n"));
2203 } else {
2204 DEBUG(10, ("vfs_full_audit: Debug class number of "
2205 "'full_audit': %d\n", vfs_full_audit_debug_level));
2208 return ret;