Following Björn JACKE's patch, unify the detection of the timespec code in configure...
[Samba.git] / source / modules / vfs_full_audit.c
blobfd91bfe3d2b0daee2c61204f654cdc0c9890f56b
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 extern userdom_struct current_user_info;
64 static int vfs_full_audit_debug_level = DBGC_VFS;
66 struct vfs_full_audit_private_data {
67 struct bitmap *success_ops;
68 struct bitmap *failure_ops;
71 #undef DBGC_CLASS
72 #define DBGC_CLASS vfs_full_audit_debug_level
74 /* Function prototypes */
76 static int smb_full_audit_connect(vfs_handle_struct *handle,
77 const char *svc, const char *user);
78 static void smb_full_audit_disconnect(vfs_handle_struct *handle);
79 static SMB_BIG_UINT smb_full_audit_disk_free(vfs_handle_struct *handle,
80 const char *path,
81 bool small_query, SMB_BIG_UINT *bsize,
82 SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize);
83 static int smb_full_audit_get_quota(struct vfs_handle_struct *handle,
84 enum SMB_QUOTA_TYPE qtype, unid_t id,
85 SMB_DISK_QUOTA *qt);
86 static int smb_full_audit_set_quota(struct vfs_handle_struct *handle,
87 enum SMB_QUOTA_TYPE qtype, unid_t id,
88 SMB_DISK_QUOTA *qt);
89 static int smb_full_audit_get_shadow_copy_data(struct vfs_handle_struct *handle,
90 struct files_struct *fsp,
91 SHADOW_COPY_DATA *shadow_copy_data, bool labels);
92 static int smb_full_audit_statvfs(struct vfs_handle_struct *handle,
93 const char *path,
94 struct vfs_statvfs_struct *statbuf);
96 static SMB_STRUCT_DIR *smb_full_audit_opendir(vfs_handle_struct *handle,
97 const char *fname, const char *mask, uint32 attr);
98 static SMB_STRUCT_DIRENT *smb_full_audit_readdir(vfs_handle_struct *handle,
99 SMB_STRUCT_DIR *dirp);
100 static void smb_full_audit_seekdir(vfs_handle_struct *handle,
101 SMB_STRUCT_DIR *dirp, long offset);
102 static long smb_full_audit_telldir(vfs_handle_struct *handle,
103 SMB_STRUCT_DIR *dirp);
104 static void smb_full_audit_rewinddir(vfs_handle_struct *handle,
105 SMB_STRUCT_DIR *dirp);
106 static int smb_full_audit_mkdir(vfs_handle_struct *handle,
107 const char *path, mode_t mode);
108 static int smb_full_audit_rmdir(vfs_handle_struct *handle,
109 const char *path);
110 static int smb_full_audit_closedir(vfs_handle_struct *handle,
111 SMB_STRUCT_DIR *dirp);
112 static int smb_full_audit_open(vfs_handle_struct *handle,
113 const char *fname, files_struct *fsp, int flags, mode_t mode);
114 static int smb_full_audit_close(vfs_handle_struct *handle, files_struct *fsp);
115 static ssize_t smb_full_audit_read(vfs_handle_struct *handle, files_struct *fsp,
116 void *data, size_t n);
117 static ssize_t smb_full_audit_pread(vfs_handle_struct *handle, files_struct *fsp,
118 void *data, size_t n, SMB_OFF_T offset);
119 static ssize_t smb_full_audit_write(vfs_handle_struct *handle, files_struct *fsp,
120 const void *data, size_t n);
121 static ssize_t smb_full_audit_pwrite(vfs_handle_struct *handle, files_struct *fsp,
122 const void *data, size_t n,
123 SMB_OFF_T offset);
124 static SMB_OFF_T smb_full_audit_lseek(vfs_handle_struct *handle, files_struct *fsp,
125 SMB_OFF_T offset, int whence);
126 static ssize_t smb_full_audit_sendfile(vfs_handle_struct *handle, int tofd,
127 files_struct *fromfsp,
128 const DATA_BLOB *hdr, SMB_OFF_T offset,
129 size_t n);
130 static ssize_t smb_full_audit_recvfile(vfs_handle_struct *handle, int fromfd,
131 files_struct *tofsp,
132 SMB_OFF_T offset,
133 size_t n);
134 static int smb_full_audit_rename(vfs_handle_struct *handle,
135 const char *oldname, const char *newname);
136 static int smb_full_audit_fsync(vfs_handle_struct *handle, files_struct *fsp);
137 static int smb_full_audit_stat(vfs_handle_struct *handle,
138 const char *fname, SMB_STRUCT_STAT *sbuf);
139 static int smb_full_audit_fstat(vfs_handle_struct *handle, files_struct *fsp,
140 SMB_STRUCT_STAT *sbuf);
141 static int smb_full_audit_lstat(vfs_handle_struct *handle,
142 const char *path, SMB_STRUCT_STAT *sbuf);
143 static int smb_full_audit_unlink(vfs_handle_struct *handle,
144 const char *path);
145 static int smb_full_audit_chmod(vfs_handle_struct *handle,
146 const char *path, mode_t mode);
147 static int smb_full_audit_fchmod(vfs_handle_struct *handle, files_struct *fsp,
148 mode_t mode);
149 static int smb_full_audit_chown(vfs_handle_struct *handle,
150 const char *path, uid_t uid, gid_t gid);
151 static int smb_full_audit_fchown(vfs_handle_struct *handle, files_struct *fsp,
152 uid_t uid, gid_t gid);
153 static int smb_full_audit_lchown(vfs_handle_struct *handle,
154 const char *path, uid_t uid, gid_t gid);
155 static int smb_full_audit_chdir(vfs_handle_struct *handle,
156 const char *path);
157 static char *smb_full_audit_getwd(vfs_handle_struct *handle,
158 char *path);
159 static int smb_full_audit_ntimes(vfs_handle_struct *handle,
160 const char *path, const struct timespec ts[2]);
161 static int smb_full_audit_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
162 SMB_OFF_T len);
163 static bool smb_full_audit_lock(vfs_handle_struct *handle, files_struct *fsp,
164 int op, SMB_OFF_T offset, SMB_OFF_T count, int type);
165 static int smb_full_audit_kernel_flock(struct vfs_handle_struct *handle,
166 struct files_struct *fsp,
167 uint32 share_mode);
168 static int smb_full_audit_linux_setlease(vfs_handle_struct *handle, files_struct *fsp,
169 int leasetype);
170 static bool smb_full_audit_getlock(vfs_handle_struct *handle, files_struct *fsp,
171 SMB_OFF_T *poffset, SMB_OFF_T *pcount, int *ptype, pid_t *ppid);
172 static int smb_full_audit_symlink(vfs_handle_struct *handle,
173 const char *oldpath, const char *newpath);
174 static int smb_full_audit_readlink(vfs_handle_struct *handle,
175 const char *path, char *buf, size_t bufsiz);
176 static int smb_full_audit_link(vfs_handle_struct *handle,
177 const char *oldpath, const char *newpath);
178 static int smb_full_audit_mknod(vfs_handle_struct *handle,
179 const char *pathname, mode_t mode, SMB_DEV_T dev);
180 static char *smb_full_audit_realpath(vfs_handle_struct *handle,
181 const char *path, char *resolved_path);
182 static NTSTATUS smb_full_audit_notify_watch(struct vfs_handle_struct *handle,
183 struct sys_notify_context *ctx,
184 struct notify_entry *e,
185 void (*callback)(struct sys_notify_context *ctx,
186 void *private_data,
187 struct notify_event *ev),
188 void *private_data, void *handle_p);
189 static int smb_full_audit_chflags(vfs_handle_struct *handle,
190 const char *path, unsigned int flags);
191 static struct file_id smb_full_audit_file_id_create(struct vfs_handle_struct *handle,
192 SMB_DEV_T dev, SMB_INO_T inode);
193 static NTSTATUS smb_full_audit_streaminfo(vfs_handle_struct *handle,
194 struct files_struct *fsp,
195 const char *fname,
196 TALLOC_CTX *mem_ctx,
197 unsigned int *pnum_streams,
198 struct stream_struct **pstreams);
199 static NTSTATUS smb_full_audit_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
200 uint32 security_info,
201 SEC_DESC **ppdesc);
202 static NTSTATUS smb_full_audit_get_nt_acl(vfs_handle_struct *handle,
203 const char *name, uint32 security_info,
204 SEC_DESC **ppdesc);
205 static NTSTATUS smb_full_audit_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
206 uint32 security_info_sent,
207 SEC_DESC *psd);
208 static NTSTATUS smb_full_audit_set_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
209 const char *name, uint32 security_info_sent,
210 SEC_DESC *psd);
211 static int smb_full_audit_chmod_acl(vfs_handle_struct *handle,
212 const char *path, mode_t mode);
213 static int smb_full_audit_fchmod_acl(vfs_handle_struct *handle, files_struct *fsp,
214 mode_t mode);
215 static int smb_full_audit_sys_acl_get_entry(vfs_handle_struct *handle,
216 SMB_ACL_T theacl, int entry_id,
217 SMB_ACL_ENTRY_T *entry_p);
218 static int smb_full_audit_sys_acl_get_tag_type(vfs_handle_struct *handle,
219 SMB_ACL_ENTRY_T entry_d,
220 SMB_ACL_TAG_T *tag_type_p);
221 static int smb_full_audit_sys_acl_get_permset(vfs_handle_struct *handle,
222 SMB_ACL_ENTRY_T entry_d,
223 SMB_ACL_PERMSET_T *permset_p);
224 static void * smb_full_audit_sys_acl_get_qualifier(vfs_handle_struct *handle,
225 SMB_ACL_ENTRY_T entry_d);
226 static SMB_ACL_T smb_full_audit_sys_acl_get_file(vfs_handle_struct *handle,
227 const char *path_p,
228 SMB_ACL_TYPE_T type);
229 static SMB_ACL_T smb_full_audit_sys_acl_get_fd(vfs_handle_struct *handle,
230 files_struct *fsp);
231 static int smb_full_audit_sys_acl_clear_perms(vfs_handle_struct *handle,
232 SMB_ACL_PERMSET_T permset);
233 static int smb_full_audit_sys_acl_add_perm(vfs_handle_struct *handle,
234 SMB_ACL_PERMSET_T permset,
235 SMB_ACL_PERM_T perm);
236 static char * smb_full_audit_sys_acl_to_text(vfs_handle_struct *handle,
237 SMB_ACL_T theacl,
238 ssize_t *plen);
239 static SMB_ACL_T smb_full_audit_sys_acl_init(vfs_handle_struct *handle,
240 int count);
241 static int smb_full_audit_sys_acl_create_entry(vfs_handle_struct *handle,
242 SMB_ACL_T *pacl,
243 SMB_ACL_ENTRY_T *pentry);
244 static int smb_full_audit_sys_acl_set_tag_type(vfs_handle_struct *handle,
245 SMB_ACL_ENTRY_T entry,
246 SMB_ACL_TAG_T tagtype);
247 static int smb_full_audit_sys_acl_set_qualifier(vfs_handle_struct *handle,
248 SMB_ACL_ENTRY_T entry,
249 void *qual);
250 static int smb_full_audit_sys_acl_set_permset(vfs_handle_struct *handle,
251 SMB_ACL_ENTRY_T entry,
252 SMB_ACL_PERMSET_T permset);
253 static int smb_full_audit_sys_acl_valid(vfs_handle_struct *handle,
254 SMB_ACL_T theacl );
255 static int smb_full_audit_sys_acl_set_file(vfs_handle_struct *handle,
256 const char *name, SMB_ACL_TYPE_T acltype,
257 SMB_ACL_T theacl);
258 static int smb_full_audit_sys_acl_set_fd(vfs_handle_struct *handle, files_struct *fsp,
259 SMB_ACL_T theacl);
260 static int smb_full_audit_sys_acl_delete_def_file(vfs_handle_struct *handle,
261 const char *path);
262 static int smb_full_audit_sys_acl_get_perm(vfs_handle_struct *handle,
263 SMB_ACL_PERMSET_T permset,
264 SMB_ACL_PERM_T perm);
265 static int smb_full_audit_sys_acl_free_text(vfs_handle_struct *handle,
266 char *text);
267 static int smb_full_audit_sys_acl_free_acl(vfs_handle_struct *handle,
268 SMB_ACL_T posix_acl);
269 static int smb_full_audit_sys_acl_free_qualifier(vfs_handle_struct *handle,
270 void *qualifier,
271 SMB_ACL_TAG_T tagtype);
272 static ssize_t smb_full_audit_getxattr(struct vfs_handle_struct *handle,
273 const char *path,
274 const char *name, void *value, size_t size);
275 static ssize_t smb_full_audit_lgetxattr(struct vfs_handle_struct *handle,
276 const char *path, const char *name,
277 void *value, size_t size);
278 static ssize_t smb_full_audit_fgetxattr(struct vfs_handle_struct *handle,
279 struct files_struct *fsp,
280 const char *name, void *value, size_t size);
281 static ssize_t smb_full_audit_listxattr(struct vfs_handle_struct *handle,
282 const char *path, char *list, size_t size);
283 static ssize_t smb_full_audit_llistxattr(struct vfs_handle_struct *handle,
284 const char *path, char *list, size_t size);
285 static ssize_t smb_full_audit_flistxattr(struct vfs_handle_struct *handle,
286 struct files_struct *fsp, char *list,
287 size_t size);
288 static int smb_full_audit_removexattr(struct vfs_handle_struct *handle,
289 const char *path,
290 const char *name);
291 static int smb_full_audit_lremovexattr(struct vfs_handle_struct *handle,
292 const char *path,
293 const char *name);
294 static int smb_full_audit_fremovexattr(struct vfs_handle_struct *handle,
295 struct files_struct *fsp,
296 const char *name);
297 static int smb_full_audit_setxattr(struct vfs_handle_struct *handle,
298 const char *path,
299 const char *name, const void *value, size_t size,
300 int flags);
301 static int smb_full_audit_lsetxattr(struct vfs_handle_struct *handle,
302 const char *path,
303 const char *name, const void *value, size_t size,
304 int flags);
305 static int smb_full_audit_fsetxattr(struct vfs_handle_struct *handle,
306 struct files_struct *fsp, const char *name,
307 const void *value, size_t size, int flags);
309 static int smb_full_audit_aio_read(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb);
310 static int smb_full_audit_aio_write(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb);
311 static ssize_t smb_full_audit_aio_return(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb);
312 static int smb_full_audit_aio_cancel(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb);
313 static int smb_full_audit_aio_error(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb);
314 static int smb_full_audit_aio_fsync(struct vfs_handle_struct *handle, struct files_struct *fsp, int op, SMB_STRUCT_AIOCB *aiocb);
315 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);
317 /* VFS operations */
319 static vfs_op_tuple audit_op_tuples[] = {
321 /* Disk operations */
323 {SMB_VFS_OP(smb_full_audit_connect), SMB_VFS_OP_CONNECT,
324 SMB_VFS_LAYER_LOGGER},
325 {SMB_VFS_OP(smb_full_audit_disconnect), SMB_VFS_OP_DISCONNECT,
326 SMB_VFS_LAYER_LOGGER},
327 {SMB_VFS_OP(smb_full_audit_disk_free), SMB_VFS_OP_DISK_FREE,
328 SMB_VFS_LAYER_LOGGER},
329 {SMB_VFS_OP(smb_full_audit_get_quota), SMB_VFS_OP_GET_QUOTA,
330 SMB_VFS_LAYER_LOGGER},
331 {SMB_VFS_OP(smb_full_audit_set_quota), SMB_VFS_OP_SET_QUOTA,
332 SMB_VFS_LAYER_LOGGER},
333 {SMB_VFS_OP(smb_full_audit_get_shadow_copy_data), SMB_VFS_OP_GET_SHADOW_COPY_DATA,
334 SMB_VFS_LAYER_LOGGER},
335 {SMB_VFS_OP(smb_full_audit_statvfs), SMB_VFS_OP_STATVFS,
336 SMB_VFS_LAYER_LOGGER},
338 /* Directory operations */
340 {SMB_VFS_OP(smb_full_audit_opendir), SMB_VFS_OP_OPENDIR,
341 SMB_VFS_LAYER_LOGGER},
342 {SMB_VFS_OP(smb_full_audit_readdir), SMB_VFS_OP_READDIR,
343 SMB_VFS_LAYER_LOGGER},
344 {SMB_VFS_OP(smb_full_audit_seekdir), SMB_VFS_OP_SEEKDIR,
345 SMB_VFS_LAYER_LOGGER},
346 {SMB_VFS_OP(smb_full_audit_telldir), SMB_VFS_OP_TELLDIR,
347 SMB_VFS_LAYER_LOGGER},
348 {SMB_VFS_OP(smb_full_audit_rewinddir), SMB_VFS_OP_REWINDDIR,
349 SMB_VFS_LAYER_LOGGER},
350 {SMB_VFS_OP(smb_full_audit_mkdir), SMB_VFS_OP_MKDIR,
351 SMB_VFS_LAYER_LOGGER},
352 {SMB_VFS_OP(smb_full_audit_rmdir), SMB_VFS_OP_RMDIR,
353 SMB_VFS_LAYER_LOGGER},
354 {SMB_VFS_OP(smb_full_audit_closedir), SMB_VFS_OP_CLOSEDIR,
355 SMB_VFS_LAYER_LOGGER},
357 /* File operations */
359 {SMB_VFS_OP(smb_full_audit_open), SMB_VFS_OP_OPEN,
360 SMB_VFS_LAYER_LOGGER},
361 {SMB_VFS_OP(smb_full_audit_close), SMB_VFS_OP_CLOSE,
362 SMB_VFS_LAYER_LOGGER},
363 {SMB_VFS_OP(smb_full_audit_read), SMB_VFS_OP_READ,
364 SMB_VFS_LAYER_LOGGER},
365 {SMB_VFS_OP(smb_full_audit_pread), SMB_VFS_OP_PREAD,
366 SMB_VFS_LAYER_LOGGER},
367 {SMB_VFS_OP(smb_full_audit_write), SMB_VFS_OP_WRITE,
368 SMB_VFS_LAYER_LOGGER},
369 {SMB_VFS_OP(smb_full_audit_pwrite), SMB_VFS_OP_PWRITE,
370 SMB_VFS_LAYER_LOGGER},
371 {SMB_VFS_OP(smb_full_audit_lseek), SMB_VFS_OP_LSEEK,
372 SMB_VFS_LAYER_LOGGER},
373 {SMB_VFS_OP(smb_full_audit_sendfile), SMB_VFS_OP_SENDFILE,
374 SMB_VFS_LAYER_LOGGER},
375 {SMB_VFS_OP(smb_full_audit_recvfile), SMB_VFS_OP_RECVFILE,
376 SMB_VFS_LAYER_LOGGER},
377 {SMB_VFS_OP(smb_full_audit_rename), SMB_VFS_OP_RENAME,
378 SMB_VFS_LAYER_LOGGER},
379 {SMB_VFS_OP(smb_full_audit_fsync), SMB_VFS_OP_FSYNC,
380 SMB_VFS_LAYER_LOGGER},
381 {SMB_VFS_OP(smb_full_audit_stat), SMB_VFS_OP_STAT,
382 SMB_VFS_LAYER_LOGGER},
383 {SMB_VFS_OP(smb_full_audit_fstat), SMB_VFS_OP_FSTAT,
384 SMB_VFS_LAYER_LOGGER},
385 {SMB_VFS_OP(smb_full_audit_lstat), SMB_VFS_OP_LSTAT,
386 SMB_VFS_LAYER_LOGGER},
387 {SMB_VFS_OP(smb_full_audit_unlink), SMB_VFS_OP_UNLINK,
388 SMB_VFS_LAYER_LOGGER},
389 {SMB_VFS_OP(smb_full_audit_chmod), SMB_VFS_OP_CHMOD,
390 SMB_VFS_LAYER_LOGGER},
391 {SMB_VFS_OP(smb_full_audit_fchmod), SMB_VFS_OP_FCHMOD,
392 SMB_VFS_LAYER_LOGGER},
393 {SMB_VFS_OP(smb_full_audit_chown), SMB_VFS_OP_CHOWN,
394 SMB_VFS_LAYER_LOGGER},
395 {SMB_VFS_OP(smb_full_audit_fchown), SMB_VFS_OP_FCHOWN,
396 SMB_VFS_LAYER_LOGGER},
397 {SMB_VFS_OP(smb_full_audit_lchown), SMB_VFS_OP_LCHOWN,
398 SMB_VFS_LAYER_LOGGER},
399 {SMB_VFS_OP(smb_full_audit_chdir), SMB_VFS_OP_CHDIR,
400 SMB_VFS_LAYER_LOGGER},
401 {SMB_VFS_OP(smb_full_audit_getwd), SMB_VFS_OP_GETWD,
402 SMB_VFS_LAYER_LOGGER},
403 {SMB_VFS_OP(smb_full_audit_ntimes), SMB_VFS_OP_NTIMES,
404 SMB_VFS_LAYER_LOGGER},
405 {SMB_VFS_OP(smb_full_audit_ftruncate), SMB_VFS_OP_FTRUNCATE,
406 SMB_VFS_LAYER_LOGGER},
407 {SMB_VFS_OP(smb_full_audit_lock), SMB_VFS_OP_LOCK,
408 SMB_VFS_LAYER_LOGGER},
409 {SMB_VFS_OP(smb_full_audit_kernel_flock), SMB_VFS_OP_KERNEL_FLOCK,
410 SMB_VFS_LAYER_LOGGER},
411 {SMB_VFS_OP(smb_full_audit_linux_setlease), SMB_VFS_OP_LINUX_SETLEASE,
412 SMB_VFS_LAYER_LOGGER},
413 {SMB_VFS_OP(smb_full_audit_getlock), SMB_VFS_OP_GETLOCK,
414 SMB_VFS_LAYER_LOGGER},
415 {SMB_VFS_OP(smb_full_audit_symlink), SMB_VFS_OP_SYMLINK,
416 SMB_VFS_LAYER_LOGGER},
417 {SMB_VFS_OP(smb_full_audit_readlink), SMB_VFS_OP_READLINK,
418 SMB_VFS_LAYER_LOGGER},
419 {SMB_VFS_OP(smb_full_audit_link), SMB_VFS_OP_LINK,
420 SMB_VFS_LAYER_LOGGER},
421 {SMB_VFS_OP(smb_full_audit_mknod), SMB_VFS_OP_MKNOD,
422 SMB_VFS_LAYER_LOGGER},
423 {SMB_VFS_OP(smb_full_audit_realpath), SMB_VFS_OP_REALPATH,
424 SMB_VFS_LAYER_LOGGER},
425 {SMB_VFS_OP(smb_full_audit_notify_watch),SMB_VFS_OP_NOTIFY_WATCH,
426 SMB_VFS_LAYER_LOGGER},
427 {SMB_VFS_OP(smb_full_audit_chflags), SMB_VFS_OP_CHFLAGS,
428 SMB_VFS_LAYER_LOGGER},
429 {SMB_VFS_OP(smb_full_audit_file_id_create), SMB_VFS_OP_FILE_ID_CREATE,
430 SMB_VFS_LAYER_LOGGER},
431 {SMB_VFS_OP(smb_full_audit_streaminfo), SMB_VFS_OP_STREAMINFO,
432 SMB_VFS_LAYER_LOGGER},
434 /* NT ACL operations. */
436 {SMB_VFS_OP(smb_full_audit_fget_nt_acl), SMB_VFS_OP_FGET_NT_ACL,
437 SMB_VFS_LAYER_LOGGER},
438 {SMB_VFS_OP(smb_full_audit_get_nt_acl), SMB_VFS_OP_GET_NT_ACL,
439 SMB_VFS_LAYER_LOGGER},
440 {SMB_VFS_OP(smb_full_audit_fset_nt_acl), SMB_VFS_OP_FSET_NT_ACL,
441 SMB_VFS_LAYER_LOGGER},
442 {SMB_VFS_OP(smb_full_audit_set_nt_acl), SMB_VFS_OP_SET_NT_ACL,
443 SMB_VFS_LAYER_LOGGER},
445 /* POSIX ACL operations. */
447 {SMB_VFS_OP(smb_full_audit_chmod_acl), SMB_VFS_OP_CHMOD_ACL,
448 SMB_VFS_LAYER_LOGGER},
449 {SMB_VFS_OP(smb_full_audit_fchmod_acl), SMB_VFS_OP_FCHMOD_ACL,
450 SMB_VFS_LAYER_LOGGER},
451 {SMB_VFS_OP(smb_full_audit_sys_acl_get_entry), SMB_VFS_OP_SYS_ACL_GET_ENTRY,
452 SMB_VFS_LAYER_LOGGER},
453 {SMB_VFS_OP(smb_full_audit_sys_acl_get_tag_type), SMB_VFS_OP_SYS_ACL_GET_TAG_TYPE,
454 SMB_VFS_LAYER_LOGGER},
455 {SMB_VFS_OP(smb_full_audit_sys_acl_get_permset), SMB_VFS_OP_SYS_ACL_GET_PERMSET,
456 SMB_VFS_LAYER_LOGGER},
457 {SMB_VFS_OP(smb_full_audit_sys_acl_get_qualifier), SMB_VFS_OP_SYS_ACL_GET_QUALIFIER,
458 SMB_VFS_LAYER_LOGGER},
459 {SMB_VFS_OP(smb_full_audit_sys_acl_get_file), SMB_VFS_OP_SYS_ACL_GET_FILE,
460 SMB_VFS_LAYER_LOGGER},
461 {SMB_VFS_OP(smb_full_audit_sys_acl_get_fd), SMB_VFS_OP_SYS_ACL_GET_FD,
462 SMB_VFS_LAYER_LOGGER},
463 {SMB_VFS_OP(smb_full_audit_sys_acl_clear_perms), SMB_VFS_OP_SYS_ACL_CLEAR_PERMS,
464 SMB_VFS_LAYER_LOGGER},
465 {SMB_VFS_OP(smb_full_audit_sys_acl_add_perm), SMB_VFS_OP_SYS_ACL_ADD_PERM,
466 SMB_VFS_LAYER_LOGGER},
467 {SMB_VFS_OP(smb_full_audit_sys_acl_to_text), SMB_VFS_OP_SYS_ACL_TO_TEXT,
468 SMB_VFS_LAYER_LOGGER},
469 {SMB_VFS_OP(smb_full_audit_sys_acl_init), SMB_VFS_OP_SYS_ACL_INIT,
470 SMB_VFS_LAYER_LOGGER},
471 {SMB_VFS_OP(smb_full_audit_sys_acl_create_entry), SMB_VFS_OP_SYS_ACL_CREATE_ENTRY,
472 SMB_VFS_LAYER_LOGGER},
473 {SMB_VFS_OP(smb_full_audit_sys_acl_set_tag_type), SMB_VFS_OP_SYS_ACL_SET_TAG_TYPE,
474 SMB_VFS_LAYER_LOGGER},
475 {SMB_VFS_OP(smb_full_audit_sys_acl_set_qualifier), SMB_VFS_OP_SYS_ACL_SET_QUALIFIER,
476 SMB_VFS_LAYER_LOGGER},
477 {SMB_VFS_OP(smb_full_audit_sys_acl_set_permset), SMB_VFS_OP_SYS_ACL_SET_PERMSET,
478 SMB_VFS_LAYER_LOGGER},
479 {SMB_VFS_OP(smb_full_audit_sys_acl_valid), SMB_VFS_OP_SYS_ACL_VALID,
480 SMB_VFS_LAYER_LOGGER},
481 {SMB_VFS_OP(smb_full_audit_sys_acl_set_file), SMB_VFS_OP_SYS_ACL_SET_FILE,
482 SMB_VFS_LAYER_LOGGER},
483 {SMB_VFS_OP(smb_full_audit_sys_acl_set_fd), SMB_VFS_OP_SYS_ACL_SET_FD,
484 SMB_VFS_LAYER_LOGGER},
485 {SMB_VFS_OP(smb_full_audit_sys_acl_delete_def_file), SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE,
486 SMB_VFS_LAYER_LOGGER},
487 {SMB_VFS_OP(smb_full_audit_sys_acl_get_perm), SMB_VFS_OP_SYS_ACL_GET_PERM,
488 SMB_VFS_LAYER_LOGGER},
489 {SMB_VFS_OP(smb_full_audit_sys_acl_free_text), SMB_VFS_OP_SYS_ACL_FREE_TEXT,
490 SMB_VFS_LAYER_LOGGER},
491 {SMB_VFS_OP(smb_full_audit_sys_acl_free_acl), SMB_VFS_OP_SYS_ACL_FREE_ACL,
492 SMB_VFS_LAYER_LOGGER},
493 {SMB_VFS_OP(smb_full_audit_sys_acl_free_qualifier), SMB_VFS_OP_SYS_ACL_FREE_QUALIFIER,
494 SMB_VFS_LAYER_LOGGER},
496 /* EA operations. */
498 {SMB_VFS_OP(smb_full_audit_getxattr), SMB_VFS_OP_GETXATTR,
499 SMB_VFS_LAYER_LOGGER},
500 {SMB_VFS_OP(smb_full_audit_lgetxattr), SMB_VFS_OP_LGETXATTR,
501 SMB_VFS_LAYER_LOGGER},
502 {SMB_VFS_OP(smb_full_audit_fgetxattr), SMB_VFS_OP_FGETXATTR,
503 SMB_VFS_LAYER_LOGGER},
504 {SMB_VFS_OP(smb_full_audit_listxattr), SMB_VFS_OP_LISTXATTR,
505 SMB_VFS_LAYER_LOGGER},
506 {SMB_VFS_OP(smb_full_audit_llistxattr), SMB_VFS_OP_LLISTXATTR,
507 SMB_VFS_LAYER_LOGGER},
508 {SMB_VFS_OP(smb_full_audit_flistxattr), SMB_VFS_OP_FLISTXATTR,
509 SMB_VFS_LAYER_LOGGER},
510 {SMB_VFS_OP(smb_full_audit_removexattr), SMB_VFS_OP_REMOVEXATTR,
511 SMB_VFS_LAYER_LOGGER},
512 {SMB_VFS_OP(smb_full_audit_lremovexattr), SMB_VFS_OP_LREMOVEXATTR,
513 SMB_VFS_LAYER_LOGGER},
514 {SMB_VFS_OP(smb_full_audit_fremovexattr), SMB_VFS_OP_FREMOVEXATTR,
515 SMB_VFS_LAYER_LOGGER},
516 {SMB_VFS_OP(smb_full_audit_setxattr), SMB_VFS_OP_SETXATTR,
517 SMB_VFS_LAYER_LOGGER},
518 {SMB_VFS_OP(smb_full_audit_lsetxattr), SMB_VFS_OP_LSETXATTR,
519 SMB_VFS_LAYER_LOGGER},
520 {SMB_VFS_OP(smb_full_audit_fsetxattr), SMB_VFS_OP_FSETXATTR,
521 SMB_VFS_LAYER_LOGGER},
523 {SMB_VFS_OP(smb_full_audit_aio_read), SMB_VFS_OP_AIO_READ,
524 SMB_VFS_LAYER_LOGGER},
525 {SMB_VFS_OP(smb_full_audit_aio_write), SMB_VFS_OP_AIO_WRITE,
526 SMB_VFS_LAYER_LOGGER},
527 {SMB_VFS_OP(smb_full_audit_aio_return), SMB_VFS_OP_AIO_RETURN,
528 SMB_VFS_LAYER_LOGGER},
529 {SMB_VFS_OP(smb_full_audit_aio_cancel), SMB_VFS_OP_AIO_CANCEL,
530 SMB_VFS_LAYER_LOGGER},
531 {SMB_VFS_OP(smb_full_audit_aio_error), SMB_VFS_OP_AIO_ERROR,
532 SMB_VFS_LAYER_LOGGER},
533 {SMB_VFS_OP(smb_full_audit_aio_fsync), SMB_VFS_OP_AIO_FSYNC,
534 SMB_VFS_LAYER_LOGGER},
535 {SMB_VFS_OP(smb_full_audit_aio_suspend),SMB_VFS_OP_AIO_SUSPEND,
536 SMB_VFS_LAYER_LOGGER},
538 /* Finish VFS operations definition */
540 {SMB_VFS_OP(NULL), SMB_VFS_OP_NOOP,
541 SMB_VFS_LAYER_NOOP}
544 /* The following array *must* be in the same order as defined in vfs.h */
546 static struct {
547 vfs_op_type type;
548 const char *name;
549 } vfs_op_names[] = {
550 { SMB_VFS_OP_CONNECT, "connect" },
551 { SMB_VFS_OP_DISCONNECT, "disconnect" },
552 { SMB_VFS_OP_DISK_FREE, "disk_free" },
553 { SMB_VFS_OP_GET_QUOTA, "get_quota" },
554 { SMB_VFS_OP_SET_QUOTA, "set_quota" },
555 { SMB_VFS_OP_GET_SHADOW_COPY_DATA, "get_shadow_copy_data" },
556 { SMB_VFS_OP_STATVFS, "statvfs" },
557 { SMB_VFS_OP_FS_CAPABILITIES, "fs_capabilities" },
558 { SMB_VFS_OP_OPENDIR, "opendir" },
559 { SMB_VFS_OP_READDIR, "readdir" },
560 { SMB_VFS_OP_SEEKDIR, "seekdir" },
561 { SMB_VFS_OP_TELLDIR, "telldir" },
562 { SMB_VFS_OP_REWINDDIR, "rewinddir" },
563 { SMB_VFS_OP_MKDIR, "mkdir" },
564 { SMB_VFS_OP_RMDIR, "rmdir" },
565 { SMB_VFS_OP_CLOSEDIR, "closedir" },
566 { SMB_VFS_OP_OPEN, "open" },
567 { SMB_VFS_OP_CLOSE, "close" },
568 { SMB_VFS_OP_READ, "read" },
569 { SMB_VFS_OP_PREAD, "pread" },
570 { SMB_VFS_OP_WRITE, "write" },
571 { SMB_VFS_OP_PWRITE, "pwrite" },
572 { SMB_VFS_OP_LSEEK, "lseek" },
573 { SMB_VFS_OP_SENDFILE, "sendfile" },
574 { SMB_VFS_OP_RECVFILE, "recvfile" },
575 { SMB_VFS_OP_RENAME, "rename" },
576 { SMB_VFS_OP_FSYNC, "fsync" },
577 { SMB_VFS_OP_STAT, "stat" },
578 { SMB_VFS_OP_FSTAT, "fstat" },
579 { SMB_VFS_OP_LSTAT, "lstat" },
580 { SMB_VFS_OP_UNLINK, "unlink" },
581 { SMB_VFS_OP_CHMOD, "chmod" },
582 { SMB_VFS_OP_FCHMOD, "fchmod" },
583 { SMB_VFS_OP_CHOWN, "chown" },
584 { SMB_VFS_OP_FCHOWN, "fchown" },
585 { SMB_VFS_OP_LCHOWN, "lchown" },
586 { SMB_VFS_OP_CHDIR, "chdir" },
587 { SMB_VFS_OP_GETWD, "getwd" },
588 { SMB_VFS_OP_NTIMES, "ntimes" },
589 { SMB_VFS_OP_FTRUNCATE, "ftruncate" },
590 { SMB_VFS_OP_LOCK, "lock" },
591 { SMB_VFS_OP_KERNEL_FLOCK, "kernel_flock" },
592 { SMB_VFS_OP_LINUX_SETLEASE, "linux_setlease" },
593 { SMB_VFS_OP_GETLOCK, "getlock" },
594 { SMB_VFS_OP_SYMLINK, "symlink" },
595 { SMB_VFS_OP_READLINK, "readlink" },
596 { SMB_VFS_OP_LINK, "link" },
597 { SMB_VFS_OP_MKNOD, "mknod" },
598 { SMB_VFS_OP_REALPATH, "realpath" },
599 { SMB_VFS_OP_NOTIFY_WATCH, "notify_watch" },
600 { SMB_VFS_OP_CHFLAGS, "chflags" },
601 { SMB_VFS_OP_FILE_ID_CREATE, "file_id_create" },
602 { SMB_VFS_OP_STREAMINFO, "streaminfo" },
603 { SMB_VFS_OP_FGET_NT_ACL, "fget_nt_acl" },
604 { SMB_VFS_OP_GET_NT_ACL, "get_nt_acl" },
605 { SMB_VFS_OP_FSET_NT_ACL, "fset_nt_acl" },
606 { SMB_VFS_OP_SET_NT_ACL, "set_nt_acl" },
607 { SMB_VFS_OP_CHMOD_ACL, "chmod_acl" },
608 { SMB_VFS_OP_FCHMOD_ACL, "fchmod_acl" },
609 { SMB_VFS_OP_SYS_ACL_GET_ENTRY, "sys_acl_get_entry" },
610 { SMB_VFS_OP_SYS_ACL_GET_TAG_TYPE, "sys_acl_get_tag_type" },
611 { SMB_VFS_OP_SYS_ACL_GET_PERMSET, "sys_acl_get_permset" },
612 { SMB_VFS_OP_SYS_ACL_GET_QUALIFIER, "sys_acl_get_qualifier" },
613 { SMB_VFS_OP_SYS_ACL_GET_FILE, "sys_acl_get_file" },
614 { SMB_VFS_OP_SYS_ACL_GET_FD, "sys_acl_get_fd" },
615 { SMB_VFS_OP_SYS_ACL_CLEAR_PERMS, "sys_acl_clear_perms" },
616 { SMB_VFS_OP_SYS_ACL_ADD_PERM, "sys_acl_add_perm" },
617 { SMB_VFS_OP_SYS_ACL_TO_TEXT, "sys_acl_to_text" },
618 { SMB_VFS_OP_SYS_ACL_INIT, "sys_acl_init" },
619 { SMB_VFS_OP_SYS_ACL_CREATE_ENTRY, "sys_acl_create_entry" },
620 { SMB_VFS_OP_SYS_ACL_SET_TAG_TYPE, "sys_acl_set_tag_type" },
621 { SMB_VFS_OP_SYS_ACL_SET_QUALIFIER, "sys_acl_set_qualifier" },
622 { SMB_VFS_OP_SYS_ACL_SET_PERMSET, "sys_acl_set_permset" },
623 { SMB_VFS_OP_SYS_ACL_VALID, "sys_acl_valid" },
624 { SMB_VFS_OP_SYS_ACL_SET_FILE, "sys_acl_set_file" },
625 { SMB_VFS_OP_SYS_ACL_SET_FD, "sys_acl_set_fd" },
626 { SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE, "sys_acl_delete_def_file" },
627 { SMB_VFS_OP_SYS_ACL_GET_PERM, "sys_acl_get_perm" },
628 { SMB_VFS_OP_SYS_ACL_FREE_TEXT, "sys_acl_free_text" },
629 { SMB_VFS_OP_SYS_ACL_FREE_ACL, "sys_acl_free_acl" },
630 { SMB_VFS_OP_SYS_ACL_FREE_QUALIFIER, "sys_acl_free_qualifier" },
631 { SMB_VFS_OP_GETXATTR, "getxattr" },
632 { SMB_VFS_OP_LGETXATTR, "lgetxattr" },
633 { SMB_VFS_OP_FGETXATTR, "fgetxattr" },
634 { SMB_VFS_OP_LISTXATTR, "listxattr" },
635 { SMB_VFS_OP_LLISTXATTR, "llistxattr" },
636 { SMB_VFS_OP_FLISTXATTR, "flistxattr" },
637 { SMB_VFS_OP_REMOVEXATTR, "removexattr" },
638 { SMB_VFS_OP_LREMOVEXATTR, "lremovexattr" },
639 { SMB_VFS_OP_FREMOVEXATTR, "fremovexattr" },
640 { SMB_VFS_OP_SETXATTR, "setxattr" },
641 { SMB_VFS_OP_LSETXATTR, "lsetxattr" },
642 { SMB_VFS_OP_FSETXATTR, "fsetxattr" },
643 { SMB_VFS_OP_AIO_READ, "aio_read" },
644 { SMB_VFS_OP_AIO_WRITE, "aio_write" },
645 { SMB_VFS_OP_AIO_RETURN,"aio_return" },
646 { SMB_VFS_OP_AIO_CANCEL,"aio_cancel" },
647 { SMB_VFS_OP_AIO_ERROR, "aio_error" },
648 { SMB_VFS_OP_AIO_FSYNC, "aio_fsync" },
649 { SMB_VFS_OP_AIO_SUSPEND,"aio_suspend" },
650 { SMB_VFS_OP_AIO_FORCE, "aio_force" },
651 { SMB_VFS_OP_IS_OFFLINE, "aio_is_offline" },
652 { SMB_VFS_OP_SET_OFFLINE, "aio_set_offline" },
653 { SMB_VFS_OP_LAST, NULL }
656 static int audit_syslog_facility(vfs_handle_struct *handle)
658 static const struct enum_list enum_log_facilities[] = {
659 { LOG_USER, "USER" },
660 { LOG_LOCAL0, "LOCAL0" },
661 { LOG_LOCAL1, "LOCAL1" },
662 { LOG_LOCAL2, "LOCAL2" },
663 { LOG_LOCAL3, "LOCAL3" },
664 { LOG_LOCAL4, "LOCAL4" },
665 { LOG_LOCAL5, "LOCAL5" },
666 { LOG_LOCAL6, "LOCAL6" },
667 { LOG_LOCAL7, "LOCAL7" }
670 int facility;
672 facility = lp_parm_enum(SNUM(handle->conn), "full_audit", "facility", enum_log_facilities, LOG_USER);
674 return facility;
677 static int audit_syslog_priority(vfs_handle_struct *handle)
679 static const struct enum_list enum_log_priorities[] = {
680 { LOG_EMERG, "EMERG" },
681 { LOG_ALERT, "ALERT" },
682 { LOG_CRIT, "CRIT" },
683 { LOG_ERR, "ERR" },
684 { LOG_WARNING, "WARNING" },
685 { LOG_NOTICE, "NOTICE" },
686 { LOG_INFO, "INFO" },
687 { LOG_DEBUG, "DEBUG" }
690 int priority;
692 priority = lp_parm_enum(SNUM(handle->conn), "full_audit", "priority",
693 enum_log_priorities, LOG_NOTICE);
694 if (priority == -1) {
695 priority = LOG_WARNING;
698 return priority;
701 static char *audit_prefix(TALLOC_CTX *ctx, connection_struct *conn)
703 char *prefix = NULL;
704 char *result;
706 prefix = talloc_strdup(ctx,
707 lp_parm_const_string(SNUM(conn), "full_audit",
708 "prefix", "%u|%I"));
709 if (!prefix) {
710 return NULL;
712 result = talloc_sub_advanced(ctx,
713 lp_servicename(SNUM(conn)), conn->user,
714 conn->connectpath, conn->gid,
715 get_current_username(),
716 current_user_info.domain,
717 prefix);
718 TALLOC_FREE(prefix);
719 return result;
722 static bool log_success(vfs_handle_struct *handle, vfs_op_type op)
724 struct vfs_full_audit_private_data *pd = NULL;
726 SMB_VFS_HANDLE_GET_DATA(handle, pd,
727 struct vfs_full_audit_private_data,
728 return True);
730 if (pd->success_ops == NULL) {
731 return True;
734 return bitmap_query(pd->success_ops, op);
737 static bool log_failure(vfs_handle_struct *handle, vfs_op_type op)
739 struct vfs_full_audit_private_data *pd = NULL;
741 SMB_VFS_HANDLE_GET_DATA(handle, pd,
742 struct vfs_full_audit_private_data,
743 return True);
745 if (pd->failure_ops == NULL)
746 return True;
748 return bitmap_query(pd->failure_ops, op);
751 static void init_bitmap(struct bitmap **bm, const char **ops)
753 bool log_all = False;
755 if (*bm != NULL)
756 return;
758 *bm = bitmap_allocate(SMB_VFS_OP_LAST);
760 if (*bm == NULL) {
761 DEBUG(0, ("Could not alloc bitmap -- "
762 "defaulting to logging everything\n"));
763 return;
766 while (*ops != NULL) {
767 int i;
768 bool found = False;
770 if (strequal(*ops, "all")) {
771 log_all = True;
772 break;
775 if (strequal(*ops, "none")) {
776 break;
779 for (i=0; i<SMB_VFS_OP_LAST; i++) {
780 if (vfs_op_names[i].name == NULL) {
781 smb_panic("vfs_full_audit.c: name table not "
782 "in sync with vfs.h\n");
785 if (strequal(*ops, vfs_op_names[i].name)) {
786 bitmap_set(*bm, i);
787 found = True;
790 if (!found) {
791 DEBUG(0, ("Could not find opname %s, logging all\n",
792 *ops));
793 log_all = True;
794 break;
796 ops += 1;
799 if (log_all) {
800 /* The query functions default to True */
801 bitmap_free(*bm);
802 *bm = NULL;
806 static const char *audit_opname(vfs_op_type op)
808 if (op >= SMB_VFS_OP_LAST)
809 return "INVALID VFS OP";
810 return vfs_op_names[op].name;
813 static void do_log(vfs_op_type op, bool success, vfs_handle_struct *handle,
814 const char *format, ...)
816 fstring err_msg;
817 char *audit_pre = NULL;
818 va_list ap;
819 char *op_msg = NULL;
821 if (success && (!log_success(handle, op)))
822 return;
824 if (!success && (!log_failure(handle, op)))
825 return;
827 if (success)
828 fstrcpy(err_msg, "ok");
829 else
830 fstr_sprintf(err_msg, "fail (%s)", strerror(errno));
832 va_start(ap, format);
833 op_msg = talloc_vasprintf(NULL, format, ap);
834 va_end(ap);
836 if (!op_msg) {
837 return;
840 audit_pre = audit_prefix(NULL, handle->conn);
841 syslog(audit_syslog_priority(handle), "%s|%s|%s|%s\n",
842 audit_pre ? audit_pre : "",
843 audit_opname(op), err_msg, op_msg);
845 TALLOC_FREE(audit_pre);
846 TALLOC_FREE(op_msg);
848 return;
851 /* Free function for the private data. */
853 static void free_private_data(void **p_data)
855 struct vfs_full_audit_private_data *pd = *(struct vfs_full_audit_private_data **)p_data;
857 if (pd->success_ops) {
858 bitmap_free(pd->success_ops);
860 if (pd->failure_ops) {
861 bitmap_free(pd->failure_ops);
863 SAFE_FREE(pd);
864 *p_data = NULL;
867 /* Implementation of vfs_ops. Pass everything on to the default
868 operation but log event first. */
870 static int smb_full_audit_connect(vfs_handle_struct *handle,
871 const char *svc, const char *user)
873 int result;
874 struct vfs_full_audit_private_data *pd = NULL;
875 const char *none[] = { NULL };
876 const char *all [] = { "all" };
878 if (!handle) {
879 return -1;
882 pd = SMB_MALLOC_P(struct vfs_full_audit_private_data);
883 if (!pd) {
884 return -1;
886 ZERO_STRUCTP(pd);
888 openlog("smbd_audit", 0, audit_syslog_facility(handle));
890 init_bitmap(&pd->success_ops,
891 lp_parm_string_list(SNUM(handle->conn), "full_audit", "success",
892 none));
893 init_bitmap(&pd->failure_ops,
894 lp_parm_string_list(SNUM(handle->conn), "full_audit", "failure",
895 all));
897 /* Store the private data. */
898 SMB_VFS_HANDLE_SET_DATA(handle, pd, free_private_data,
899 struct vfs_full_audit_private_data, return -1);
901 result = SMB_VFS_NEXT_CONNECT(handle, svc, user);
903 do_log(SMB_VFS_OP_CONNECT, True, handle,
904 "%s", svc);
906 return result;
909 static void smb_full_audit_disconnect(vfs_handle_struct *handle)
911 SMB_VFS_NEXT_DISCONNECT(handle);
913 do_log(SMB_VFS_OP_DISCONNECT, True, handle,
914 "%s", lp_servicename(SNUM(handle->conn)));
916 /* The bitmaps will be disconnected when the private
917 data is deleted. */
919 return;
922 static SMB_BIG_UINT smb_full_audit_disk_free(vfs_handle_struct *handle,
923 const char *path,
924 bool small_query, SMB_BIG_UINT *bsize,
925 SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize)
927 SMB_BIG_UINT result;
929 result = SMB_VFS_NEXT_DISK_FREE(handle, path, small_query, bsize,
930 dfree, dsize);
932 /* Don't have a reasonable notion of failure here */
934 do_log(SMB_VFS_OP_DISK_FREE, True, handle, "%s", path);
936 return result;
939 static int smb_full_audit_get_quota(struct vfs_handle_struct *handle,
940 enum SMB_QUOTA_TYPE qtype, unid_t id,
941 SMB_DISK_QUOTA *qt)
943 int result;
945 result = SMB_VFS_NEXT_GET_QUOTA(handle, qtype, id, qt);
947 do_log(SMB_VFS_OP_GET_QUOTA, (result >= 0), handle, "");
949 return result;
953 static int smb_full_audit_set_quota(struct vfs_handle_struct *handle,
954 enum SMB_QUOTA_TYPE qtype, unid_t id,
955 SMB_DISK_QUOTA *qt)
957 int result;
959 result = SMB_VFS_NEXT_SET_QUOTA(handle, qtype, id, qt);
961 do_log(SMB_VFS_OP_SET_QUOTA, (result >= 0), handle, "");
963 return result;
966 static int smb_full_audit_get_shadow_copy_data(struct vfs_handle_struct *handle,
967 struct files_struct *fsp,
968 SHADOW_COPY_DATA *shadow_copy_data, bool labels)
970 int result;
972 result = SMB_VFS_NEXT_GET_SHADOW_COPY_DATA(handle, fsp, shadow_copy_data, labels);
974 do_log(SMB_VFS_OP_GET_SHADOW_COPY_DATA, (result >= 0), handle, "");
976 return result;
979 static int smb_full_audit_statvfs(struct vfs_handle_struct *handle,
980 const char *path,
981 struct vfs_statvfs_struct *statbuf)
983 int result;
985 result = SMB_VFS_NEXT_STATVFS(handle, path, statbuf);
987 do_log(SMB_VFS_OP_STATVFS, (result >= 0), handle, "");
989 return result;
992 static SMB_STRUCT_DIR *smb_full_audit_opendir(vfs_handle_struct *handle,
993 const char *fname, const char *mask, uint32 attr)
995 SMB_STRUCT_DIR *result;
997 result = SMB_VFS_NEXT_OPENDIR(handle, fname, mask, attr);
999 do_log(SMB_VFS_OP_OPENDIR, (result != NULL), handle, "%s", fname);
1001 return result;
1004 static SMB_STRUCT_DIRENT *smb_full_audit_readdir(vfs_handle_struct *handle,
1005 SMB_STRUCT_DIR *dirp)
1007 SMB_STRUCT_DIRENT *result;
1009 result = SMB_VFS_NEXT_READDIR(handle, dirp);
1011 /* This operation has no reasonable error condition
1012 * (End of dir is also failure), so always succeed.
1014 do_log(SMB_VFS_OP_READDIR, True, handle, "");
1016 return result;
1019 static void smb_full_audit_seekdir(vfs_handle_struct *handle,
1020 SMB_STRUCT_DIR *dirp, long offset)
1022 SMB_VFS_NEXT_SEEKDIR(handle, dirp, offset);
1024 do_log(SMB_VFS_OP_SEEKDIR, True, handle, "");
1025 return;
1028 static long smb_full_audit_telldir(vfs_handle_struct *handle,
1029 SMB_STRUCT_DIR *dirp)
1031 long result;
1033 result = SMB_VFS_NEXT_TELLDIR(handle, dirp);
1035 do_log(SMB_VFS_OP_TELLDIR, True, handle, "");
1037 return result;
1040 static void smb_full_audit_rewinddir(vfs_handle_struct *handle,
1041 SMB_STRUCT_DIR *dirp)
1043 SMB_VFS_NEXT_REWINDDIR(handle, dirp);
1045 do_log(SMB_VFS_OP_REWINDDIR, True, handle, "");
1046 return;
1049 static int smb_full_audit_mkdir(vfs_handle_struct *handle,
1050 const char *path, mode_t mode)
1052 int result;
1054 result = SMB_VFS_NEXT_MKDIR(handle, path, mode);
1056 do_log(SMB_VFS_OP_MKDIR, (result >= 0), handle, "%s", path);
1058 return result;
1061 static int smb_full_audit_rmdir(vfs_handle_struct *handle,
1062 const char *path)
1064 int result;
1066 result = SMB_VFS_NEXT_RMDIR(handle, path);
1068 do_log(SMB_VFS_OP_RMDIR, (result >= 0), handle, "%s", path);
1070 return result;
1073 static int smb_full_audit_closedir(vfs_handle_struct *handle,
1074 SMB_STRUCT_DIR *dirp)
1076 int result;
1078 result = SMB_VFS_NEXT_CLOSEDIR(handle, dirp);
1080 do_log(SMB_VFS_OP_CLOSEDIR, (result >= 0), handle, "");
1082 return result;
1085 static int smb_full_audit_open(vfs_handle_struct *handle,
1086 const char *fname, files_struct *fsp, int flags, mode_t mode)
1088 int result;
1090 result = SMB_VFS_NEXT_OPEN(handle, fname, fsp, flags, mode);
1092 do_log(SMB_VFS_OP_OPEN, (result >= 0), handle, "%s|%s",
1093 ((flags & O_WRONLY) || (flags & O_RDWR))?"w":"r",
1094 fname);
1096 return result;
1099 static int smb_full_audit_close(vfs_handle_struct *handle, files_struct *fsp)
1101 int result;
1103 result = SMB_VFS_NEXT_CLOSE(handle, fsp);
1105 do_log(SMB_VFS_OP_CLOSE, (result >= 0), handle, "%s", fsp->fsp_name);
1107 return result;
1110 static ssize_t smb_full_audit_read(vfs_handle_struct *handle, files_struct *fsp,
1111 void *data, size_t n)
1113 ssize_t result;
1115 result = SMB_VFS_NEXT_READ(handle, fsp, data, n);
1117 do_log(SMB_VFS_OP_READ, (result >= 0), handle, "%s", fsp->fsp_name);
1119 return result;
1122 static ssize_t smb_full_audit_pread(vfs_handle_struct *handle, files_struct *fsp,
1123 void *data, size_t n, SMB_OFF_T offset)
1125 ssize_t result;
1127 result = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
1129 do_log(SMB_VFS_OP_PREAD, (result >= 0), handle, "%s", fsp->fsp_name);
1131 return result;
1134 static ssize_t smb_full_audit_write(vfs_handle_struct *handle, files_struct *fsp,
1135 const void *data, size_t n)
1137 ssize_t result;
1139 result = SMB_VFS_NEXT_WRITE(handle, fsp, data, n);
1141 do_log(SMB_VFS_OP_WRITE, (result >= 0), handle, "%s", fsp->fsp_name);
1143 return result;
1146 static ssize_t smb_full_audit_pwrite(vfs_handle_struct *handle, files_struct *fsp,
1147 const void *data, size_t n,
1148 SMB_OFF_T offset)
1150 ssize_t result;
1152 result = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
1154 do_log(SMB_VFS_OP_PWRITE, (result >= 0), handle, "%s", fsp->fsp_name);
1156 return result;
1159 static SMB_OFF_T smb_full_audit_lseek(vfs_handle_struct *handle, files_struct *fsp,
1160 SMB_OFF_T offset, int whence)
1162 ssize_t result;
1164 result = SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence);
1166 do_log(SMB_VFS_OP_LSEEK, (result != (ssize_t)-1), handle,
1167 "%s", fsp->fsp_name);
1169 return result;
1172 static ssize_t smb_full_audit_sendfile(vfs_handle_struct *handle, int tofd,
1173 files_struct *fromfsp,
1174 const DATA_BLOB *hdr, SMB_OFF_T offset,
1175 size_t n)
1177 ssize_t result;
1179 result = SMB_VFS_NEXT_SENDFILE(handle, tofd, fromfsp, hdr, offset, n);
1181 do_log(SMB_VFS_OP_SENDFILE, (result >= 0), handle,
1182 "%s", fromfsp->fsp_name);
1184 return result;
1187 static ssize_t smb_full_audit_recvfile(vfs_handle_struct *handle, int fromfd,
1188 files_struct *tofsp,
1189 SMB_OFF_T offset,
1190 size_t n)
1192 ssize_t result;
1194 result = SMB_VFS_NEXT_RECVFILE(handle, fromfd, tofsp, offset, n);
1196 do_log(SMB_VFS_OP_RECVFILE, (result >= 0), handle,
1197 "%s", tofsp->fsp_name);
1199 return result;
1202 static int smb_full_audit_rename(vfs_handle_struct *handle,
1203 const char *oldname, const char *newname)
1205 int result;
1207 result = SMB_VFS_NEXT_RENAME(handle, oldname, newname);
1209 do_log(SMB_VFS_OP_RENAME, (result >= 0), handle, "%s|%s", oldname, newname);
1211 return result;
1214 static int smb_full_audit_fsync(vfs_handle_struct *handle, files_struct *fsp)
1216 int result;
1218 result = SMB_VFS_NEXT_FSYNC(handle, fsp);
1220 do_log(SMB_VFS_OP_FSYNC, (result >= 0), handle, "%s", fsp->fsp_name);
1222 return result;
1225 static int smb_full_audit_stat(vfs_handle_struct *handle,
1226 const char *fname, SMB_STRUCT_STAT *sbuf)
1228 int result;
1230 result = SMB_VFS_NEXT_STAT(handle, fname, sbuf);
1232 do_log(SMB_VFS_OP_STAT, (result >= 0), handle, "%s", fname);
1234 return result;
1237 static int smb_full_audit_fstat(vfs_handle_struct *handle, files_struct *fsp,
1238 SMB_STRUCT_STAT *sbuf)
1240 int result;
1242 result = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1244 do_log(SMB_VFS_OP_FSTAT, (result >= 0), handle, "%s", fsp->fsp_name);
1246 return result;
1249 static int smb_full_audit_lstat(vfs_handle_struct *handle,
1250 const char *path, SMB_STRUCT_STAT *sbuf)
1252 int result;
1254 result = SMB_VFS_NEXT_LSTAT(handle, path, sbuf);
1256 do_log(SMB_VFS_OP_LSTAT, (result >= 0), handle, "%s", path);
1258 return result;
1261 static int smb_full_audit_unlink(vfs_handle_struct *handle,
1262 const char *path)
1264 int result;
1266 result = SMB_VFS_NEXT_UNLINK(handle, path);
1268 do_log(SMB_VFS_OP_UNLINK, (result >= 0), handle, "%s", path);
1270 return result;
1273 static int smb_full_audit_chmod(vfs_handle_struct *handle,
1274 const char *path, mode_t mode)
1276 int result;
1278 result = SMB_VFS_NEXT_CHMOD(handle, path, mode);
1280 do_log(SMB_VFS_OP_CHMOD, (result >= 0), handle, "%s|%o", path, mode);
1282 return result;
1285 static int smb_full_audit_fchmod(vfs_handle_struct *handle, files_struct *fsp,
1286 mode_t mode)
1288 int result;
1290 result = SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1292 do_log(SMB_VFS_OP_FCHMOD, (result >= 0), handle,
1293 "%s|%o", fsp->fsp_name, mode);
1295 return result;
1298 static int smb_full_audit_chown(vfs_handle_struct *handle,
1299 const char *path, uid_t uid, gid_t gid)
1301 int result;
1303 result = SMB_VFS_NEXT_CHOWN(handle, path, uid, gid);
1305 do_log(SMB_VFS_OP_CHOWN, (result >= 0), handle, "%s|%ld|%ld",
1306 path, (long int)uid, (long int)gid);
1308 return result;
1311 static int smb_full_audit_fchown(vfs_handle_struct *handle, files_struct *fsp,
1312 uid_t uid, gid_t gid)
1314 int result;
1316 result = SMB_VFS_NEXT_FCHOWN(handle, fsp, uid, gid);
1318 do_log(SMB_VFS_OP_FCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1319 fsp->fsp_name, (long int)uid, (long int)gid);
1321 return result;
1324 static int smb_full_audit_lchown(vfs_handle_struct *handle,
1325 const char *path, uid_t uid, gid_t gid)
1327 int result;
1329 result = SMB_VFS_NEXT_LCHOWN(handle, path, uid, gid);
1331 do_log(SMB_VFS_OP_LCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1332 path, (long int)uid, (long int)gid);
1334 return result;
1337 static int smb_full_audit_chdir(vfs_handle_struct *handle,
1338 const char *path)
1340 int result;
1342 result = SMB_VFS_NEXT_CHDIR(handle, path);
1344 do_log(SMB_VFS_OP_CHDIR, (result >= 0), handle, "chdir|%s", path);
1346 return result;
1349 static char *smb_full_audit_getwd(vfs_handle_struct *handle,
1350 char *path)
1352 char *result;
1354 result = SMB_VFS_NEXT_GETWD(handle, path);
1356 do_log(SMB_VFS_OP_GETWD, (result != NULL), handle, "%s", path);
1358 return result;
1361 static int smb_full_audit_ntimes(vfs_handle_struct *handle,
1362 const char *path, const struct timespec ts[2])
1364 int result;
1366 result = SMB_VFS_NEXT_NTIMES(handle, path, ts);
1368 do_log(SMB_VFS_OP_NTIMES, (result >= 0), handle, "%s", path);
1370 return result;
1373 static int smb_full_audit_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
1374 SMB_OFF_T len)
1376 int result;
1378 result = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1380 do_log(SMB_VFS_OP_FTRUNCATE, (result >= 0), handle,
1381 "%s", fsp->fsp_name);
1383 return result;
1386 static bool smb_full_audit_lock(vfs_handle_struct *handle, files_struct *fsp,
1387 int op, SMB_OFF_T offset, SMB_OFF_T count, int type)
1389 bool result;
1391 result = SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type);
1393 do_log(SMB_VFS_OP_LOCK, result, handle, "%s", fsp->fsp_name);
1395 return result;
1398 static int smb_full_audit_kernel_flock(struct vfs_handle_struct *handle,
1399 struct files_struct *fsp,
1400 uint32 share_mode)
1402 int result;
1404 result = SMB_VFS_NEXT_KERNEL_FLOCK(handle, fsp, share_mode);
1406 do_log(SMB_VFS_OP_KERNEL_FLOCK, (result >= 0), handle, "%s",
1407 fsp->fsp_name);
1409 return result;
1412 static int smb_full_audit_linux_setlease(vfs_handle_struct *handle, files_struct *fsp,
1413 int leasetype)
1415 int result;
1417 result = SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
1419 do_log(SMB_VFS_OP_LINUX_SETLEASE, (result >= 0), handle, "%s",
1420 fsp->fsp_name);
1422 return result;
1425 static bool smb_full_audit_getlock(vfs_handle_struct *handle, files_struct *fsp,
1426 SMB_OFF_T *poffset, SMB_OFF_T *pcount, int *ptype, pid_t *ppid)
1428 bool result;
1430 result = SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype, ppid);
1432 do_log(SMB_VFS_OP_GETLOCK, result, handle, "%s", fsp->fsp_name);
1434 return result;
1437 static int smb_full_audit_symlink(vfs_handle_struct *handle,
1438 const char *oldpath, const char *newpath)
1440 int result;
1442 result = SMB_VFS_NEXT_SYMLINK(handle, oldpath, newpath);
1444 do_log(SMB_VFS_OP_SYMLINK, (result >= 0), handle,
1445 "%s|%s", oldpath, newpath);
1447 return result;
1450 static int smb_full_audit_readlink(vfs_handle_struct *handle,
1451 const char *path, char *buf, size_t bufsiz)
1453 int result;
1455 result = SMB_VFS_NEXT_READLINK(handle, path, buf, bufsiz);
1457 do_log(SMB_VFS_OP_READLINK, (result >= 0), handle, "%s", path);
1459 return result;
1462 static int smb_full_audit_link(vfs_handle_struct *handle,
1463 const char *oldpath, const char *newpath)
1465 int result;
1467 result = SMB_VFS_NEXT_LINK(handle, oldpath, newpath);
1469 do_log(SMB_VFS_OP_LINK, (result >= 0), handle,
1470 "%s|%s", oldpath, newpath);
1472 return result;
1475 static int smb_full_audit_mknod(vfs_handle_struct *handle,
1476 const char *pathname, mode_t mode, SMB_DEV_T dev)
1478 int result;
1480 result = SMB_VFS_NEXT_MKNOD(handle, pathname, mode, dev);
1482 do_log(SMB_VFS_OP_MKNOD, (result >= 0), handle, "%s", pathname);
1484 return result;
1487 static char *smb_full_audit_realpath(vfs_handle_struct *handle,
1488 const char *path, char *resolved_path)
1490 char *result;
1492 result = SMB_VFS_NEXT_REALPATH(handle, path, resolved_path);
1494 do_log(SMB_VFS_OP_REALPATH, (result != NULL), handle, "%s", path);
1496 return result;
1499 static NTSTATUS smb_full_audit_notify_watch(struct vfs_handle_struct *handle,
1500 struct sys_notify_context *ctx,
1501 struct notify_entry *e,
1502 void (*callback)(struct sys_notify_context *ctx,
1503 void *private_data,
1504 struct notify_event *ev),
1505 void *private_data, void *handle_p)
1507 NTSTATUS result;
1509 result = SMB_VFS_NEXT_NOTIFY_WATCH(handle, ctx, e, callback, private_data, handle_p);
1511 do_log(SMB_VFS_OP_NOTIFY_WATCH, NT_STATUS_IS_OK(result), handle, "");
1513 return result;
1516 static int smb_full_audit_chflags(vfs_handle_struct *handle,
1517 const char *path, unsigned int flags)
1519 int result;
1521 result = SMB_VFS_NEXT_CHFLAGS(handle, path, flags);
1523 do_log(SMB_VFS_OP_CHFLAGS, (result != 0), handle, "%s", path);
1525 return result;
1528 static struct file_id smb_full_audit_file_id_create(struct vfs_handle_struct *handle,
1529 SMB_DEV_T dev, SMB_INO_T inode)
1531 struct file_id id_zero;
1532 struct file_id result;
1534 ZERO_STRUCT(id_zero);
1536 result = SMB_VFS_NEXT_FILE_ID_CREATE(handle, dev, inode);
1538 do_log(SMB_VFS_OP_FILE_ID_CREATE,
1539 !file_id_equal(&id_zero, &result),
1540 handle, "%s", file_id_string_tos(&result));
1542 return result;
1545 static NTSTATUS smb_full_audit_streaminfo(vfs_handle_struct *handle,
1546 struct files_struct *fsp,
1547 const char *fname,
1548 TALLOC_CTX *mem_ctx,
1549 unsigned int *pnum_streams,
1550 struct stream_struct **pstreams)
1552 NTSTATUS result;
1554 result = SMB_VFS_NEXT_STREAMINFO(handle, fsp, fname, mem_ctx,
1555 pnum_streams, pstreams);
1557 do_log(SMB_VFS_OP_STREAMINFO, NT_STATUS_IS_OK(result), handle,
1558 "%s", fname);
1560 return result;
1563 static NTSTATUS smb_full_audit_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
1564 uint32 security_info,
1565 SEC_DESC **ppdesc)
1567 NTSTATUS result;
1569 result = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info, ppdesc);
1571 do_log(SMB_VFS_OP_FGET_NT_ACL, NT_STATUS_IS_OK(result), handle,
1572 "%s", fsp->fsp_name);
1574 return result;
1577 static NTSTATUS smb_full_audit_get_nt_acl(vfs_handle_struct *handle,
1578 const char *name,
1579 uint32 security_info,
1580 SEC_DESC **ppdesc)
1582 NTSTATUS result;
1584 result = SMB_VFS_NEXT_GET_NT_ACL(handle, name, security_info, ppdesc);
1586 do_log(SMB_VFS_OP_GET_NT_ACL, NT_STATUS_IS_OK(result), handle,
1587 "%s", name);
1589 return result;
1592 static NTSTATUS smb_full_audit_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
1593 uint32 security_info_sent,
1594 SEC_DESC *psd)
1596 NTSTATUS result;
1598 result = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
1600 do_log(SMB_VFS_OP_FSET_NT_ACL, NT_STATUS_IS_OK(result), handle, "%s", fsp->fsp_name);
1602 return result;
1605 static NTSTATUS smb_full_audit_set_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
1606 const char *name, uint32 security_info_sent,
1607 SEC_DESC *psd)
1609 NTSTATUS result;
1611 result = SMB_VFS_NEXT_SET_NT_ACL(handle, fsp, name, security_info_sent,
1612 psd);
1614 do_log(SMB_VFS_OP_SET_NT_ACL, NT_STATUS_IS_OK(result), handle, "%s", fsp->fsp_name);
1616 return result;
1619 static int smb_full_audit_chmod_acl(vfs_handle_struct *handle,
1620 const char *path, mode_t mode)
1622 int result;
1624 result = SMB_VFS_NEXT_CHMOD_ACL(handle, path, mode);
1626 do_log(SMB_VFS_OP_CHMOD_ACL, (result >= 0), handle,
1627 "%s|%o", path, mode);
1629 return result;
1632 static int smb_full_audit_fchmod_acl(vfs_handle_struct *handle, files_struct *fsp,
1633 mode_t mode)
1635 int result;
1637 result = SMB_VFS_NEXT_FCHMOD_ACL(handle, fsp, mode);
1639 do_log(SMB_VFS_OP_FCHMOD_ACL, (result >= 0), handle,
1640 "%s|%o", fsp->fsp_name, mode);
1642 return result;
1645 static int smb_full_audit_sys_acl_get_entry(vfs_handle_struct *handle,
1647 SMB_ACL_T theacl, int entry_id,
1648 SMB_ACL_ENTRY_T *entry_p)
1650 int result;
1652 result = SMB_VFS_NEXT_SYS_ACL_GET_ENTRY(handle, theacl, entry_id,
1653 entry_p);
1655 do_log(SMB_VFS_OP_SYS_ACL_GET_ENTRY, (result >= 0), handle,
1656 "");
1658 return result;
1661 static int smb_full_audit_sys_acl_get_tag_type(vfs_handle_struct *handle,
1663 SMB_ACL_ENTRY_T entry_d,
1664 SMB_ACL_TAG_T *tag_type_p)
1666 int result;
1668 result = SMB_VFS_NEXT_SYS_ACL_GET_TAG_TYPE(handle, entry_d,
1669 tag_type_p);
1671 do_log(SMB_VFS_OP_SYS_ACL_GET_TAG_TYPE, (result >= 0), handle,
1672 "");
1674 return result;
1677 static int smb_full_audit_sys_acl_get_permset(vfs_handle_struct *handle,
1679 SMB_ACL_ENTRY_T entry_d,
1680 SMB_ACL_PERMSET_T *permset_p)
1682 int result;
1684 result = SMB_VFS_NEXT_SYS_ACL_GET_PERMSET(handle, entry_d,
1685 permset_p);
1687 do_log(SMB_VFS_OP_SYS_ACL_GET_PERMSET, (result >= 0), handle,
1688 "");
1690 return result;
1693 static void * smb_full_audit_sys_acl_get_qualifier(vfs_handle_struct *handle,
1695 SMB_ACL_ENTRY_T entry_d)
1697 void *result;
1699 result = SMB_VFS_NEXT_SYS_ACL_GET_QUALIFIER(handle, entry_d);
1701 do_log(SMB_VFS_OP_SYS_ACL_GET_QUALIFIER, (result != NULL), handle,
1702 "");
1704 return result;
1707 static SMB_ACL_T smb_full_audit_sys_acl_get_file(vfs_handle_struct *handle,
1708 const char *path_p,
1709 SMB_ACL_TYPE_T type)
1711 SMB_ACL_T result;
1713 result = SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, path_p, type);
1715 do_log(SMB_VFS_OP_SYS_ACL_GET_FILE, (result != NULL), handle,
1716 "%s", path_p);
1718 return result;
1721 static SMB_ACL_T smb_full_audit_sys_acl_get_fd(vfs_handle_struct *handle,
1722 files_struct *fsp)
1724 SMB_ACL_T result;
1726 result = SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp);
1728 do_log(SMB_VFS_OP_SYS_ACL_GET_FD, (result != NULL), handle,
1729 "%s", fsp->fsp_name);
1731 return result;
1734 static int smb_full_audit_sys_acl_clear_perms(vfs_handle_struct *handle,
1736 SMB_ACL_PERMSET_T permset)
1738 int result;
1740 result = SMB_VFS_NEXT_SYS_ACL_CLEAR_PERMS(handle, permset);
1742 do_log(SMB_VFS_OP_SYS_ACL_CLEAR_PERMS, (result >= 0), handle,
1743 "");
1745 return result;
1748 static int smb_full_audit_sys_acl_add_perm(vfs_handle_struct *handle,
1750 SMB_ACL_PERMSET_T permset,
1751 SMB_ACL_PERM_T perm)
1753 int result;
1755 result = SMB_VFS_NEXT_SYS_ACL_ADD_PERM(handle, permset, perm);
1757 do_log(SMB_VFS_OP_SYS_ACL_ADD_PERM, (result >= 0), handle,
1758 "");
1760 return result;
1763 static char * smb_full_audit_sys_acl_to_text(vfs_handle_struct *handle,
1764 SMB_ACL_T theacl,
1765 ssize_t *plen)
1767 char * result;
1769 result = SMB_VFS_NEXT_SYS_ACL_TO_TEXT(handle, theacl, plen);
1771 do_log(SMB_VFS_OP_SYS_ACL_TO_TEXT, (result != NULL), handle,
1772 "");
1774 return result;
1777 static SMB_ACL_T smb_full_audit_sys_acl_init(vfs_handle_struct *handle,
1779 int count)
1781 SMB_ACL_T result;
1783 result = SMB_VFS_NEXT_SYS_ACL_INIT(handle, count);
1785 do_log(SMB_VFS_OP_SYS_ACL_INIT, (result != NULL), handle,
1786 "");
1788 return result;
1791 static int smb_full_audit_sys_acl_create_entry(vfs_handle_struct *handle,
1792 SMB_ACL_T *pacl,
1793 SMB_ACL_ENTRY_T *pentry)
1795 int result;
1797 result = SMB_VFS_NEXT_SYS_ACL_CREATE_ENTRY(handle, pacl, pentry);
1799 do_log(SMB_VFS_OP_SYS_ACL_CREATE_ENTRY, (result >= 0), handle,
1800 "");
1802 return result;
1805 static int smb_full_audit_sys_acl_set_tag_type(vfs_handle_struct *handle,
1807 SMB_ACL_ENTRY_T entry,
1808 SMB_ACL_TAG_T tagtype)
1810 int result;
1812 result = SMB_VFS_NEXT_SYS_ACL_SET_TAG_TYPE(handle, entry,
1813 tagtype);
1815 do_log(SMB_VFS_OP_SYS_ACL_SET_TAG_TYPE, (result >= 0), handle,
1816 "");
1818 return result;
1821 static int smb_full_audit_sys_acl_set_qualifier(vfs_handle_struct *handle,
1823 SMB_ACL_ENTRY_T entry,
1824 void *qual)
1826 int result;
1828 result = SMB_VFS_NEXT_SYS_ACL_SET_QUALIFIER(handle, entry, qual);
1830 do_log(SMB_VFS_OP_SYS_ACL_SET_QUALIFIER, (result >= 0), handle,
1831 "");
1833 return result;
1836 static int smb_full_audit_sys_acl_set_permset(vfs_handle_struct *handle,
1838 SMB_ACL_ENTRY_T entry,
1839 SMB_ACL_PERMSET_T permset)
1841 int result;
1843 result = SMB_VFS_NEXT_SYS_ACL_SET_PERMSET(handle, entry, permset);
1845 do_log(SMB_VFS_OP_SYS_ACL_SET_PERMSET, (result >= 0), handle,
1846 "");
1848 return result;
1851 static int smb_full_audit_sys_acl_valid(vfs_handle_struct *handle,
1853 SMB_ACL_T theacl )
1855 int result;
1857 result = SMB_VFS_NEXT_SYS_ACL_VALID(handle, theacl);
1859 do_log(SMB_VFS_OP_SYS_ACL_VALID, (result >= 0), handle,
1860 "");
1862 return result;
1865 static int smb_full_audit_sys_acl_set_file(vfs_handle_struct *handle,
1867 const char *name, SMB_ACL_TYPE_T acltype,
1868 SMB_ACL_T theacl)
1870 int result;
1872 result = SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, name, acltype,
1873 theacl);
1875 do_log(SMB_VFS_OP_SYS_ACL_SET_FILE, (result >= 0), handle,
1876 "%s", name);
1878 return result;
1881 static int smb_full_audit_sys_acl_set_fd(vfs_handle_struct *handle, files_struct *fsp,
1882 SMB_ACL_T theacl)
1884 int result;
1886 result = SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, theacl);
1888 do_log(SMB_VFS_OP_SYS_ACL_SET_FD, (result >= 0), handle,
1889 "%s", fsp->fsp_name);
1891 return result;
1894 static int smb_full_audit_sys_acl_delete_def_file(vfs_handle_struct *handle,
1896 const char *path)
1898 int result;
1900 result = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, path);
1902 do_log(SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE, (result >= 0), handle,
1903 "%s", path);
1905 return result;
1908 static int smb_full_audit_sys_acl_get_perm(vfs_handle_struct *handle,
1910 SMB_ACL_PERMSET_T permset,
1911 SMB_ACL_PERM_T perm)
1913 int result;
1915 result = SMB_VFS_NEXT_SYS_ACL_GET_PERM(handle, permset, perm);
1917 do_log(SMB_VFS_OP_SYS_ACL_GET_PERM, (result >= 0), handle,
1918 "");
1920 return result;
1923 static int smb_full_audit_sys_acl_free_text(vfs_handle_struct *handle,
1925 char *text)
1927 int result;
1929 result = SMB_VFS_NEXT_SYS_ACL_FREE_TEXT(handle, text);
1931 do_log(SMB_VFS_OP_SYS_ACL_FREE_TEXT, (result >= 0), handle,
1932 "");
1934 return result;
1937 static int smb_full_audit_sys_acl_free_acl(vfs_handle_struct *handle,
1939 SMB_ACL_T posix_acl)
1941 int result;
1943 result = SMB_VFS_NEXT_SYS_ACL_FREE_ACL(handle, posix_acl);
1945 do_log(SMB_VFS_OP_SYS_ACL_FREE_ACL, (result >= 0), handle,
1946 "");
1948 return result;
1951 static int smb_full_audit_sys_acl_free_qualifier(vfs_handle_struct *handle,
1952 void *qualifier,
1953 SMB_ACL_TAG_T tagtype)
1955 int result;
1957 result = SMB_VFS_NEXT_SYS_ACL_FREE_QUALIFIER(handle, qualifier,
1958 tagtype);
1960 do_log(SMB_VFS_OP_SYS_ACL_FREE_QUALIFIER, (result >= 0), handle,
1961 "");
1963 return result;
1966 static ssize_t smb_full_audit_getxattr(struct vfs_handle_struct *handle,
1967 const char *path,
1968 const char *name, void *value, size_t size)
1970 ssize_t result;
1972 result = SMB_VFS_NEXT_GETXATTR(handle, path, name, value, size);
1974 do_log(SMB_VFS_OP_GETXATTR, (result >= 0), handle,
1975 "%s|%s", path, name);
1977 return result;
1980 static ssize_t smb_full_audit_lgetxattr(struct vfs_handle_struct *handle,
1981 const char *path, const char *name,
1982 void *value, size_t size)
1984 ssize_t result;
1986 result = SMB_VFS_NEXT_LGETXATTR(handle, path, name, value, size);
1988 do_log(SMB_VFS_OP_LGETXATTR, (result >= 0), handle,
1989 "%s|%s", path, name);
1991 return result;
1994 static ssize_t smb_full_audit_fgetxattr(struct vfs_handle_struct *handle,
1995 struct files_struct *fsp,
1996 const char *name, void *value, size_t size)
1998 ssize_t result;
2000 result = SMB_VFS_NEXT_FGETXATTR(handle, fsp, name, value, size);
2002 do_log(SMB_VFS_OP_FGETXATTR, (result >= 0), handle,
2003 "%s|%s", fsp->fsp_name, name);
2005 return result;
2008 static ssize_t smb_full_audit_listxattr(struct vfs_handle_struct *handle,
2009 const char *path, char *list, size_t size)
2011 ssize_t result;
2013 result = SMB_VFS_NEXT_LISTXATTR(handle, path, list, size);
2015 do_log(SMB_VFS_OP_LISTXATTR, (result >= 0), handle, "%s", path);
2017 return result;
2020 static ssize_t smb_full_audit_llistxattr(struct vfs_handle_struct *handle,
2021 const char *path, char *list, size_t size)
2023 ssize_t result;
2025 result = SMB_VFS_NEXT_LLISTXATTR(handle, path, list, size);
2027 do_log(SMB_VFS_OP_LLISTXATTR, (result >= 0), handle, "%s", path);
2029 return result;
2032 static ssize_t smb_full_audit_flistxattr(struct vfs_handle_struct *handle,
2033 struct files_struct *fsp, char *list,
2034 size_t size)
2036 ssize_t result;
2038 result = SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
2040 do_log(SMB_VFS_OP_FLISTXATTR, (result >= 0), handle,
2041 "%s", fsp->fsp_name);
2043 return result;
2046 static int smb_full_audit_removexattr(struct vfs_handle_struct *handle,
2047 const char *path,
2048 const char *name)
2050 int result;
2052 result = SMB_VFS_NEXT_REMOVEXATTR(handle, path, name);
2054 do_log(SMB_VFS_OP_REMOVEXATTR, (result >= 0), handle,
2055 "%s|%s", path, name);
2057 return result;
2060 static int smb_full_audit_lremovexattr(struct vfs_handle_struct *handle,
2061 const char *path,
2062 const char *name)
2064 int result;
2066 result = SMB_VFS_NEXT_LREMOVEXATTR(handle, path, name);
2068 do_log(SMB_VFS_OP_LREMOVEXATTR, (result >= 0), handle,
2069 "%s|%s", path, name);
2071 return result;
2074 static int smb_full_audit_fremovexattr(struct vfs_handle_struct *handle,
2075 struct files_struct *fsp,
2076 const char *name)
2078 int result;
2080 result = SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, name);
2082 do_log(SMB_VFS_OP_FREMOVEXATTR, (result >= 0), handle,
2083 "%s|%s", fsp->fsp_name, name);
2085 return result;
2088 static int smb_full_audit_setxattr(struct vfs_handle_struct *handle,
2089 const char *path,
2090 const char *name, const void *value, size_t size,
2091 int flags)
2093 int result;
2095 result = SMB_VFS_NEXT_SETXATTR(handle, path, name, value, size,
2096 flags);
2098 do_log(SMB_VFS_OP_SETXATTR, (result >= 0), handle,
2099 "%s|%s", path, name);
2101 return result;
2104 static int smb_full_audit_lsetxattr(struct vfs_handle_struct *handle,
2105 const char *path,
2106 const char *name, const void *value, size_t size,
2107 int flags)
2109 int result;
2111 result = SMB_VFS_NEXT_LSETXATTR(handle, path, name, value, size,
2112 flags);
2114 do_log(SMB_VFS_OP_LSETXATTR, (result >= 0), handle,
2115 "%s|%s", path, name);
2117 return result;
2120 static int smb_full_audit_fsetxattr(struct vfs_handle_struct *handle,
2121 struct files_struct *fsp, const char *name,
2122 const void *value, size_t size, int flags)
2124 int result;
2126 result = SMB_VFS_NEXT_FSETXATTR(handle, fsp, name, value, size, flags);
2128 do_log(SMB_VFS_OP_FSETXATTR, (result >= 0), handle,
2129 "%s|%s", fsp->fsp_name, name);
2131 return result;
2134 static int smb_full_audit_aio_read(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
2136 int result;
2138 result = SMB_VFS_NEXT_AIO_READ(handle, fsp, aiocb);
2139 do_log(SMB_VFS_OP_AIO_READ, (result >= 0), handle,
2140 "%s", fsp->fsp_name);
2142 return result;
2145 static int smb_full_audit_aio_write(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
2147 int result;
2149 result = SMB_VFS_NEXT_AIO_WRITE(handle, fsp, aiocb);
2150 do_log(SMB_VFS_OP_AIO_WRITE, (result >= 0), handle,
2151 "%s", fsp->fsp_name);
2153 return result;
2156 static ssize_t smb_full_audit_aio_return(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
2158 int result;
2160 result = SMB_VFS_NEXT_AIO_RETURN(handle, fsp, aiocb);
2161 do_log(SMB_VFS_OP_AIO_RETURN, (result >= 0), handle,
2162 "%s", fsp->fsp_name);
2164 return result;
2167 static int smb_full_audit_aio_cancel(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
2169 int result;
2171 result = SMB_VFS_NEXT_AIO_CANCEL(handle, fsp, aiocb);
2172 do_log(SMB_VFS_OP_AIO_CANCEL, (result >= 0), handle,
2173 "%s", fsp->fsp_name);
2175 return result;
2178 static int smb_full_audit_aio_error(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
2180 int result;
2182 result = SMB_VFS_NEXT_AIO_ERROR(handle, fsp, aiocb);
2183 do_log(SMB_VFS_OP_AIO_ERROR, (result >= 0), handle,
2184 "%s", fsp->fsp_name);
2186 return result;
2189 static int smb_full_audit_aio_fsync(struct vfs_handle_struct *handle, struct files_struct *fsp, int op, SMB_STRUCT_AIOCB *aiocb)
2191 int result;
2193 result = SMB_VFS_NEXT_AIO_FSYNC(handle, fsp, op, aiocb);
2194 do_log(SMB_VFS_OP_AIO_FSYNC, (result >= 0), handle,
2195 "%s", fsp->fsp_name);
2197 return result;
2200 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)
2202 int result;
2204 result = SMB_VFS_NEXT_AIO_SUSPEND(handle, fsp, aiocb, n, ts);
2205 do_log(SMB_VFS_OP_AIO_SUSPEND, (result >= 0), handle,
2206 "%s", fsp->fsp_name);
2208 return result;
2212 NTSTATUS vfs_full_audit_init(void);
2213 NTSTATUS vfs_full_audit_init(void)
2215 NTSTATUS ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION,
2216 "full_audit", audit_op_tuples);
2218 if (!NT_STATUS_IS_OK(ret))
2219 return ret;
2221 vfs_full_audit_debug_level = debug_add_class("full_audit");
2222 if (vfs_full_audit_debug_level == -1) {
2223 vfs_full_audit_debug_level = DBGC_VFS;
2224 DEBUG(0, ("vfs_full_audit: Couldn't register custom debugging "
2225 "class!\n"));
2226 } else {
2227 DEBUG(10, ("vfs_full_audit: Debug class number of "
2228 "'full_audit': %d\n", vfs_full_audit_debug_level));
2231 return ret;