make read/write to internal pipes available externally
[Samba/gebeck_regimport.git] / source / modules / vfs_full_audit.c
blob6aa47aff9b1ea68e2dc9f88b40bc90fd582fcc63
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_RECVFILE, "recvfile" },
568 { SMB_VFS_OP_RENAME, "rename" },
569 { SMB_VFS_OP_FSYNC, "fsync" },
570 { SMB_VFS_OP_STAT, "stat" },
571 { SMB_VFS_OP_FSTAT, "fstat" },
572 { SMB_VFS_OP_LSTAT, "lstat" },
573 { SMB_VFS_OP_UNLINK, "unlink" },
574 { SMB_VFS_OP_CHMOD, "chmod" },
575 { SMB_VFS_OP_FCHMOD, "fchmod" },
576 { SMB_VFS_OP_CHOWN, "chown" },
577 { SMB_VFS_OP_FCHOWN, "fchown" },
578 { SMB_VFS_OP_LCHOWN, "lchown" },
579 { SMB_VFS_OP_CHDIR, "chdir" },
580 { SMB_VFS_OP_GETWD, "getwd" },
581 { SMB_VFS_OP_NTIMES, "ntimes" },
582 { SMB_VFS_OP_FTRUNCATE, "ftruncate" },
583 { SMB_VFS_OP_LOCK, "lock" },
584 { SMB_VFS_OP_KERNEL_FLOCK, "kernel_flock" },
585 { SMB_VFS_OP_LINUX_SETLEASE, "linux_setlease" },
586 { SMB_VFS_OP_GETLOCK, "getlock" },
587 { SMB_VFS_OP_SYMLINK, "symlink" },
588 { SMB_VFS_OP_READLINK, "readlink" },
589 { SMB_VFS_OP_LINK, "link" },
590 { SMB_VFS_OP_MKNOD, "mknod" },
591 { SMB_VFS_OP_REALPATH, "realpath" },
592 { SMB_VFS_OP_NOTIFY_WATCH, "notify_watch" },
593 { SMB_VFS_OP_CHFLAGS, "chflags" },
594 { SMB_VFS_OP_FILE_ID_CREATE, "file_id_create" },
595 { SMB_VFS_OP_STREAMINFO, "streaminfo" },
596 { SMB_VFS_OP_FGET_NT_ACL, "fget_nt_acl" },
597 { SMB_VFS_OP_GET_NT_ACL, "get_nt_acl" },
598 { SMB_VFS_OP_FSET_NT_ACL, "fset_nt_acl" },
599 { SMB_VFS_OP_CHMOD_ACL, "chmod_acl" },
600 { SMB_VFS_OP_FCHMOD_ACL, "fchmod_acl" },
601 { SMB_VFS_OP_SYS_ACL_GET_ENTRY, "sys_acl_get_entry" },
602 { SMB_VFS_OP_SYS_ACL_GET_TAG_TYPE, "sys_acl_get_tag_type" },
603 { SMB_VFS_OP_SYS_ACL_GET_PERMSET, "sys_acl_get_permset" },
604 { SMB_VFS_OP_SYS_ACL_GET_QUALIFIER, "sys_acl_get_qualifier" },
605 { SMB_VFS_OP_SYS_ACL_GET_FILE, "sys_acl_get_file" },
606 { SMB_VFS_OP_SYS_ACL_GET_FD, "sys_acl_get_fd" },
607 { SMB_VFS_OP_SYS_ACL_CLEAR_PERMS, "sys_acl_clear_perms" },
608 { SMB_VFS_OP_SYS_ACL_ADD_PERM, "sys_acl_add_perm" },
609 { SMB_VFS_OP_SYS_ACL_TO_TEXT, "sys_acl_to_text" },
610 { SMB_VFS_OP_SYS_ACL_INIT, "sys_acl_init" },
611 { SMB_VFS_OP_SYS_ACL_CREATE_ENTRY, "sys_acl_create_entry" },
612 { SMB_VFS_OP_SYS_ACL_SET_TAG_TYPE, "sys_acl_set_tag_type" },
613 { SMB_VFS_OP_SYS_ACL_SET_QUALIFIER, "sys_acl_set_qualifier" },
614 { SMB_VFS_OP_SYS_ACL_SET_PERMSET, "sys_acl_set_permset" },
615 { SMB_VFS_OP_SYS_ACL_VALID, "sys_acl_valid" },
616 { SMB_VFS_OP_SYS_ACL_SET_FILE, "sys_acl_set_file" },
617 { SMB_VFS_OP_SYS_ACL_SET_FD, "sys_acl_set_fd" },
618 { SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE, "sys_acl_delete_def_file" },
619 { SMB_VFS_OP_SYS_ACL_GET_PERM, "sys_acl_get_perm" },
620 { SMB_VFS_OP_SYS_ACL_FREE_TEXT, "sys_acl_free_text" },
621 { SMB_VFS_OP_SYS_ACL_FREE_ACL, "sys_acl_free_acl" },
622 { SMB_VFS_OP_SYS_ACL_FREE_QUALIFIER, "sys_acl_free_qualifier" },
623 { SMB_VFS_OP_GETXATTR, "getxattr" },
624 { SMB_VFS_OP_LGETXATTR, "lgetxattr" },
625 { SMB_VFS_OP_FGETXATTR, "fgetxattr" },
626 { SMB_VFS_OP_LISTXATTR, "listxattr" },
627 { SMB_VFS_OP_LLISTXATTR, "llistxattr" },
628 { SMB_VFS_OP_FLISTXATTR, "flistxattr" },
629 { SMB_VFS_OP_REMOVEXATTR, "removexattr" },
630 { SMB_VFS_OP_LREMOVEXATTR, "lremovexattr" },
631 { SMB_VFS_OP_FREMOVEXATTR, "fremovexattr" },
632 { SMB_VFS_OP_SETXATTR, "setxattr" },
633 { SMB_VFS_OP_LSETXATTR, "lsetxattr" },
634 { SMB_VFS_OP_FSETXATTR, "fsetxattr" },
635 { SMB_VFS_OP_AIO_READ, "aio_read" },
636 { SMB_VFS_OP_AIO_WRITE, "aio_write" },
637 { SMB_VFS_OP_AIO_RETURN,"aio_return" },
638 { SMB_VFS_OP_AIO_CANCEL,"aio_cancel" },
639 { SMB_VFS_OP_AIO_ERROR, "aio_error" },
640 { SMB_VFS_OP_AIO_FSYNC, "aio_fsync" },
641 { SMB_VFS_OP_AIO_SUSPEND,"aio_suspend" },
642 { SMB_VFS_OP_AIO_FORCE, "aio_force" },
643 { SMB_VFS_OP_IS_OFFLINE, "aio_is_offline" },
644 { SMB_VFS_OP_SET_OFFLINE, "aio_set_offline" },
645 { SMB_VFS_OP_LAST, NULL }
648 static int audit_syslog_facility(vfs_handle_struct *handle)
650 static const struct enum_list enum_log_facilities[] = {
651 { LOG_USER, "USER" },
652 { LOG_LOCAL0, "LOCAL0" },
653 { LOG_LOCAL1, "LOCAL1" },
654 { LOG_LOCAL2, "LOCAL2" },
655 { LOG_LOCAL3, "LOCAL3" },
656 { LOG_LOCAL4, "LOCAL4" },
657 { LOG_LOCAL5, "LOCAL5" },
658 { LOG_LOCAL6, "LOCAL6" },
659 { LOG_LOCAL7, "LOCAL7" }
662 int facility;
664 facility = lp_parm_enum(SNUM(handle->conn), "full_audit", "facility", enum_log_facilities, LOG_USER);
666 return facility;
669 static int audit_syslog_priority(vfs_handle_struct *handle)
671 static const struct enum_list enum_log_priorities[] = {
672 { LOG_EMERG, "EMERG" },
673 { LOG_ALERT, "ALERT" },
674 { LOG_CRIT, "CRIT" },
675 { LOG_ERR, "ERR" },
676 { LOG_WARNING, "WARNING" },
677 { LOG_NOTICE, "NOTICE" },
678 { LOG_INFO, "INFO" },
679 { LOG_DEBUG, "DEBUG" }
682 int priority;
684 priority = lp_parm_enum(SNUM(handle->conn), "full_audit", "priority",
685 enum_log_priorities, LOG_NOTICE);
686 if (priority == -1) {
687 priority = LOG_WARNING;
690 return priority;
693 static char *audit_prefix(TALLOC_CTX *ctx, connection_struct *conn)
695 char *prefix = NULL;
697 prefix = talloc_strdup(ctx,
698 lp_parm_const_string(SNUM(conn), "full_audit",
699 "prefix", "%u|%I"));
700 if (!prefix) {
701 return NULL;
703 return talloc_sub_advanced(ctx,
704 lp_servicename(SNUM(conn)),
705 conn->server_info->unix_name,
706 conn->connectpath,
707 conn->server_info->utok.gid,
708 conn->server_info->sanitized_username,
709 pdb_get_domain(conn->server_info->sam_account),
710 prefix);
713 static bool log_success(vfs_handle_struct *handle, vfs_op_type op)
715 struct vfs_full_audit_private_data *pd = NULL;
717 SMB_VFS_HANDLE_GET_DATA(handle, pd,
718 struct vfs_full_audit_private_data,
719 return True);
721 if (pd->success_ops == NULL) {
722 return True;
725 return bitmap_query(pd->success_ops, op);
728 static bool log_failure(vfs_handle_struct *handle, vfs_op_type op)
730 struct vfs_full_audit_private_data *pd = NULL;
732 SMB_VFS_HANDLE_GET_DATA(handle, pd,
733 struct vfs_full_audit_private_data,
734 return True);
736 if (pd->failure_ops == NULL)
737 return True;
739 return bitmap_query(pd->failure_ops, op);
742 static void init_bitmap(struct bitmap **bm, const char **ops)
744 bool log_all = False;
746 if (*bm != NULL)
747 return;
749 *bm = bitmap_allocate(SMB_VFS_OP_LAST);
751 if (*bm == NULL) {
752 DEBUG(0, ("Could not alloc bitmap -- "
753 "defaulting to logging everything\n"));
754 return;
757 while (*ops != NULL) {
758 int i;
759 bool found = False;
761 if (strequal(*ops, "all")) {
762 log_all = True;
763 break;
766 if (strequal(*ops, "none")) {
767 break;
770 for (i=0; i<SMB_VFS_OP_LAST; i++) {
771 if (vfs_op_names[i].name == NULL) {
772 smb_panic("vfs_full_audit.c: name table not "
773 "in sync with vfs.h\n");
776 if (strequal(*ops, vfs_op_names[i].name)) {
777 bitmap_set(*bm, i);
778 found = True;
781 if (!found) {
782 DEBUG(0, ("Could not find opname %s, logging all\n",
783 *ops));
784 log_all = True;
785 break;
787 ops += 1;
790 if (log_all) {
791 /* The query functions default to True */
792 bitmap_free(*bm);
793 *bm = NULL;
797 static const char *audit_opname(vfs_op_type op)
799 if (op >= SMB_VFS_OP_LAST)
800 return "INVALID VFS OP";
801 return vfs_op_names[op].name;
804 static void do_log(vfs_op_type op, bool success, vfs_handle_struct *handle,
805 const char *format, ...)
807 fstring err_msg;
808 char *audit_pre = NULL;
809 va_list ap;
810 char *op_msg = NULL;
812 if (success && (!log_success(handle, op)))
813 return;
815 if (!success && (!log_failure(handle, op)))
816 return;
818 if (success)
819 fstrcpy(err_msg, "ok");
820 else
821 fstr_sprintf(err_msg, "fail (%s)", strerror(errno));
823 va_start(ap, format);
824 op_msg = talloc_vasprintf(NULL, format, ap);
825 va_end(ap);
827 if (!op_msg) {
828 return;
831 audit_pre = audit_prefix(NULL, handle->conn);
832 syslog(audit_syslog_priority(handle), "%s|%s|%s|%s\n",
833 audit_pre ? audit_pre : "",
834 audit_opname(op), err_msg, op_msg);
836 TALLOC_FREE(audit_pre);
837 TALLOC_FREE(op_msg);
839 return;
842 /* Free function for the private data. */
844 static void free_private_data(void **p_data)
846 struct vfs_full_audit_private_data *pd = *(struct vfs_full_audit_private_data **)p_data;
848 if (pd->success_ops) {
849 bitmap_free(pd->success_ops);
851 if (pd->failure_ops) {
852 bitmap_free(pd->failure_ops);
854 SAFE_FREE(pd);
855 *p_data = NULL;
858 /* Implementation of vfs_ops. Pass everything on to the default
859 operation but log event first. */
861 static int smb_full_audit_connect(vfs_handle_struct *handle,
862 const char *svc, const char *user)
864 int result;
865 struct vfs_full_audit_private_data *pd = NULL;
866 const char *none[] = { NULL };
867 const char *all [] = { "all" };
869 if (!handle) {
870 return -1;
873 pd = SMB_MALLOC_P(struct vfs_full_audit_private_data);
874 if (!pd) {
875 return -1;
877 ZERO_STRUCTP(pd);
879 openlog("smbd_audit", 0, audit_syslog_facility(handle));
881 init_bitmap(&pd->success_ops,
882 lp_parm_string_list(SNUM(handle->conn), "full_audit", "success",
883 none));
884 init_bitmap(&pd->failure_ops,
885 lp_parm_string_list(SNUM(handle->conn), "full_audit", "failure",
886 all));
888 /* Store the private data. */
889 SMB_VFS_HANDLE_SET_DATA(handle, pd, free_private_data,
890 struct vfs_full_audit_private_data, return -1);
892 result = SMB_VFS_NEXT_CONNECT(handle, svc, user);
894 do_log(SMB_VFS_OP_CONNECT, True, handle,
895 "%s", svc);
897 return result;
900 static void smb_full_audit_disconnect(vfs_handle_struct *handle)
902 SMB_VFS_NEXT_DISCONNECT(handle);
904 do_log(SMB_VFS_OP_DISCONNECT, True, handle,
905 "%s", lp_servicename(SNUM(handle->conn)));
907 /* The bitmaps will be disconnected when the private
908 data is deleted. */
910 return;
913 static SMB_BIG_UINT smb_full_audit_disk_free(vfs_handle_struct *handle,
914 const char *path,
915 bool small_query, SMB_BIG_UINT *bsize,
916 SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize)
918 SMB_BIG_UINT result;
920 result = SMB_VFS_NEXT_DISK_FREE(handle, path, small_query, bsize,
921 dfree, dsize);
923 /* Don't have a reasonable notion of failure here */
925 do_log(SMB_VFS_OP_DISK_FREE, True, handle, "%s", path);
927 return result;
930 static int smb_full_audit_get_quota(struct vfs_handle_struct *handle,
931 enum SMB_QUOTA_TYPE qtype, unid_t id,
932 SMB_DISK_QUOTA *qt)
934 int result;
936 result = SMB_VFS_NEXT_GET_QUOTA(handle, qtype, id, qt);
938 do_log(SMB_VFS_OP_GET_QUOTA, (result >= 0), handle, "");
940 return result;
944 static int smb_full_audit_set_quota(struct vfs_handle_struct *handle,
945 enum SMB_QUOTA_TYPE qtype, unid_t id,
946 SMB_DISK_QUOTA *qt)
948 int result;
950 result = SMB_VFS_NEXT_SET_QUOTA(handle, qtype, id, qt);
952 do_log(SMB_VFS_OP_SET_QUOTA, (result >= 0), handle, "");
954 return result;
957 static int smb_full_audit_get_shadow_copy_data(struct vfs_handle_struct *handle,
958 struct files_struct *fsp,
959 SHADOW_COPY_DATA *shadow_copy_data, bool labels)
961 int result;
963 result = SMB_VFS_NEXT_GET_SHADOW_COPY_DATA(handle, fsp, shadow_copy_data, labels);
965 do_log(SMB_VFS_OP_GET_SHADOW_COPY_DATA, (result >= 0), handle, "");
967 return result;
970 static int smb_full_audit_statvfs(struct vfs_handle_struct *handle,
971 const char *path,
972 struct vfs_statvfs_struct *statbuf)
974 int result;
976 result = SMB_VFS_NEXT_STATVFS(handle, path, statbuf);
978 do_log(SMB_VFS_OP_STATVFS, (result >= 0), handle, "");
980 return result;
983 static SMB_STRUCT_DIR *smb_full_audit_opendir(vfs_handle_struct *handle,
984 const char *fname, const char *mask, uint32 attr)
986 SMB_STRUCT_DIR *result;
988 result = SMB_VFS_NEXT_OPENDIR(handle, fname, mask, attr);
990 do_log(SMB_VFS_OP_OPENDIR, (result != NULL), handle, "%s", fname);
992 return result;
995 static SMB_STRUCT_DIRENT *smb_full_audit_readdir(vfs_handle_struct *handle,
996 SMB_STRUCT_DIR *dirp)
998 SMB_STRUCT_DIRENT *result;
1000 result = SMB_VFS_NEXT_READDIR(handle, dirp);
1002 /* This operation has no reasonable error condition
1003 * (End of dir is also failure), so always succeed.
1005 do_log(SMB_VFS_OP_READDIR, True, handle, "");
1007 return result;
1010 static void smb_full_audit_seekdir(vfs_handle_struct *handle,
1011 SMB_STRUCT_DIR *dirp, long offset)
1013 SMB_VFS_NEXT_SEEKDIR(handle, dirp, offset);
1015 do_log(SMB_VFS_OP_SEEKDIR, True, handle, "");
1016 return;
1019 static long smb_full_audit_telldir(vfs_handle_struct *handle,
1020 SMB_STRUCT_DIR *dirp)
1022 long result;
1024 result = SMB_VFS_NEXT_TELLDIR(handle, dirp);
1026 do_log(SMB_VFS_OP_TELLDIR, True, handle, "");
1028 return result;
1031 static void smb_full_audit_rewinddir(vfs_handle_struct *handle,
1032 SMB_STRUCT_DIR *dirp)
1034 SMB_VFS_NEXT_REWINDDIR(handle, dirp);
1036 do_log(SMB_VFS_OP_REWINDDIR, True, handle, "");
1037 return;
1040 static int smb_full_audit_mkdir(vfs_handle_struct *handle,
1041 const char *path, mode_t mode)
1043 int result;
1045 result = SMB_VFS_NEXT_MKDIR(handle, path, mode);
1047 do_log(SMB_VFS_OP_MKDIR, (result >= 0), handle, "%s", path);
1049 return result;
1052 static int smb_full_audit_rmdir(vfs_handle_struct *handle,
1053 const char *path)
1055 int result;
1057 result = SMB_VFS_NEXT_RMDIR(handle, path);
1059 do_log(SMB_VFS_OP_RMDIR, (result >= 0), handle, "%s", path);
1061 return result;
1064 static int smb_full_audit_closedir(vfs_handle_struct *handle,
1065 SMB_STRUCT_DIR *dirp)
1067 int result;
1069 result = SMB_VFS_NEXT_CLOSEDIR(handle, dirp);
1071 do_log(SMB_VFS_OP_CLOSEDIR, (result >= 0), handle, "");
1073 return result;
1076 static int smb_full_audit_open(vfs_handle_struct *handle,
1077 const char *fname, files_struct *fsp, int flags, mode_t mode)
1079 int result;
1081 result = SMB_VFS_NEXT_OPEN(handle, fname, fsp, flags, mode);
1083 do_log(SMB_VFS_OP_OPEN, (result >= 0), handle, "%s|%s",
1084 ((flags & O_WRONLY) || (flags & O_RDWR))?"w":"r",
1085 fname);
1087 return result;
1090 static int smb_full_audit_close(vfs_handle_struct *handle, files_struct *fsp)
1092 int result;
1094 result = SMB_VFS_NEXT_CLOSE(handle, fsp);
1096 do_log(SMB_VFS_OP_CLOSE, (result >= 0), handle, "%s", fsp->fsp_name);
1098 return result;
1101 static ssize_t smb_full_audit_read(vfs_handle_struct *handle, files_struct *fsp,
1102 void *data, size_t n)
1104 ssize_t result;
1106 result = SMB_VFS_NEXT_READ(handle, fsp, data, n);
1108 do_log(SMB_VFS_OP_READ, (result >= 0), handle, "%s", fsp->fsp_name);
1110 return result;
1113 static ssize_t smb_full_audit_pread(vfs_handle_struct *handle, files_struct *fsp,
1114 void *data, size_t n, SMB_OFF_T offset)
1116 ssize_t result;
1118 result = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
1120 do_log(SMB_VFS_OP_PREAD, (result >= 0), handle, "%s", fsp->fsp_name);
1122 return result;
1125 static ssize_t smb_full_audit_write(vfs_handle_struct *handle, files_struct *fsp,
1126 const void *data, size_t n)
1128 ssize_t result;
1130 result = SMB_VFS_NEXT_WRITE(handle, fsp, data, n);
1132 do_log(SMB_VFS_OP_WRITE, (result >= 0), handle, "%s", fsp->fsp_name);
1134 return result;
1137 static ssize_t smb_full_audit_pwrite(vfs_handle_struct *handle, files_struct *fsp,
1138 const void *data, size_t n,
1139 SMB_OFF_T offset)
1141 ssize_t result;
1143 result = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
1145 do_log(SMB_VFS_OP_PWRITE, (result >= 0), handle, "%s", fsp->fsp_name);
1147 return result;
1150 static SMB_OFF_T smb_full_audit_lseek(vfs_handle_struct *handle, files_struct *fsp,
1151 SMB_OFF_T offset, int whence)
1153 ssize_t result;
1155 result = SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence);
1157 do_log(SMB_VFS_OP_LSEEK, (result != (ssize_t)-1), handle,
1158 "%s", fsp->fsp_name);
1160 return result;
1163 static ssize_t smb_full_audit_sendfile(vfs_handle_struct *handle, int tofd,
1164 files_struct *fromfsp,
1165 const DATA_BLOB *hdr, SMB_OFF_T offset,
1166 size_t n)
1168 ssize_t result;
1170 result = SMB_VFS_NEXT_SENDFILE(handle, tofd, fromfsp, hdr, offset, n);
1172 do_log(SMB_VFS_OP_SENDFILE, (result >= 0), handle,
1173 "%s", fromfsp->fsp_name);
1175 return result;
1178 static ssize_t smb_full_audit_recvfile(vfs_handle_struct *handle, int fromfd,
1179 files_struct *tofsp,
1180 SMB_OFF_T offset,
1181 size_t n)
1183 ssize_t result;
1185 result = SMB_VFS_NEXT_RECVFILE(handle, fromfd, tofsp, offset, n);
1187 do_log(SMB_VFS_OP_RECVFILE, (result >= 0), handle,
1188 "%s", tofsp->fsp_name);
1190 return result;
1193 static int smb_full_audit_rename(vfs_handle_struct *handle,
1194 const char *oldname, const char *newname)
1196 int result;
1198 result = SMB_VFS_NEXT_RENAME(handle, oldname, newname);
1200 do_log(SMB_VFS_OP_RENAME, (result >= 0), handle, "%s|%s", oldname, newname);
1202 return result;
1205 static int smb_full_audit_fsync(vfs_handle_struct *handle, files_struct *fsp)
1207 int result;
1209 result = SMB_VFS_NEXT_FSYNC(handle, fsp);
1211 do_log(SMB_VFS_OP_FSYNC, (result >= 0), handle, "%s", fsp->fsp_name);
1213 return result;
1216 static int smb_full_audit_stat(vfs_handle_struct *handle,
1217 const char *fname, SMB_STRUCT_STAT *sbuf)
1219 int result;
1221 result = SMB_VFS_NEXT_STAT(handle, fname, sbuf);
1223 do_log(SMB_VFS_OP_STAT, (result >= 0), handle, "%s", fname);
1225 return result;
1228 static int smb_full_audit_fstat(vfs_handle_struct *handle, files_struct *fsp,
1229 SMB_STRUCT_STAT *sbuf)
1231 int result;
1233 result = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1235 do_log(SMB_VFS_OP_FSTAT, (result >= 0), handle, "%s", fsp->fsp_name);
1237 return result;
1240 static int smb_full_audit_lstat(vfs_handle_struct *handle,
1241 const char *path, SMB_STRUCT_STAT *sbuf)
1243 int result;
1245 result = SMB_VFS_NEXT_LSTAT(handle, path, sbuf);
1247 do_log(SMB_VFS_OP_LSTAT, (result >= 0), handle, "%s", path);
1249 return result;
1252 static int smb_full_audit_unlink(vfs_handle_struct *handle,
1253 const char *path)
1255 int result;
1257 result = SMB_VFS_NEXT_UNLINK(handle, path);
1259 do_log(SMB_VFS_OP_UNLINK, (result >= 0), handle, "%s", path);
1261 return result;
1264 static int smb_full_audit_chmod(vfs_handle_struct *handle,
1265 const char *path, mode_t mode)
1267 int result;
1269 result = SMB_VFS_NEXT_CHMOD(handle, path, mode);
1271 do_log(SMB_VFS_OP_CHMOD, (result >= 0), handle, "%s|%o", path, mode);
1273 return result;
1276 static int smb_full_audit_fchmod(vfs_handle_struct *handle, files_struct *fsp,
1277 mode_t mode)
1279 int result;
1281 result = SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1283 do_log(SMB_VFS_OP_FCHMOD, (result >= 0), handle,
1284 "%s|%o", fsp->fsp_name, mode);
1286 return result;
1289 static int smb_full_audit_chown(vfs_handle_struct *handle,
1290 const char *path, uid_t uid, gid_t gid)
1292 int result;
1294 result = SMB_VFS_NEXT_CHOWN(handle, path, uid, gid);
1296 do_log(SMB_VFS_OP_CHOWN, (result >= 0), handle, "%s|%ld|%ld",
1297 path, (long int)uid, (long int)gid);
1299 return result;
1302 static int smb_full_audit_fchown(vfs_handle_struct *handle, files_struct *fsp,
1303 uid_t uid, gid_t gid)
1305 int result;
1307 result = SMB_VFS_NEXT_FCHOWN(handle, fsp, uid, gid);
1309 do_log(SMB_VFS_OP_FCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1310 fsp->fsp_name, (long int)uid, (long int)gid);
1312 return result;
1315 static int smb_full_audit_lchown(vfs_handle_struct *handle,
1316 const char *path, uid_t uid, gid_t gid)
1318 int result;
1320 result = SMB_VFS_NEXT_LCHOWN(handle, path, uid, gid);
1322 do_log(SMB_VFS_OP_LCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1323 path, (long int)uid, (long int)gid);
1325 return result;
1328 static int smb_full_audit_chdir(vfs_handle_struct *handle,
1329 const char *path)
1331 int result;
1333 result = SMB_VFS_NEXT_CHDIR(handle, path);
1335 do_log(SMB_VFS_OP_CHDIR, (result >= 0), handle, "chdir|%s", path);
1337 return result;
1340 static char *smb_full_audit_getwd(vfs_handle_struct *handle,
1341 char *path)
1343 char *result;
1345 result = SMB_VFS_NEXT_GETWD(handle, path);
1347 do_log(SMB_VFS_OP_GETWD, (result != NULL), handle, "%s", path);
1349 return result;
1352 static int smb_full_audit_ntimes(vfs_handle_struct *handle,
1353 const char *path, const struct timespec ts[2])
1355 int result;
1357 result = SMB_VFS_NEXT_NTIMES(handle, path, ts);
1359 do_log(SMB_VFS_OP_NTIMES, (result >= 0), handle, "%s", path);
1361 return result;
1364 static int smb_full_audit_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
1365 SMB_OFF_T len)
1367 int result;
1369 result = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1371 do_log(SMB_VFS_OP_FTRUNCATE, (result >= 0), handle,
1372 "%s", fsp->fsp_name);
1374 return result;
1377 static bool smb_full_audit_lock(vfs_handle_struct *handle, files_struct *fsp,
1378 int op, SMB_OFF_T offset, SMB_OFF_T count, int type)
1380 bool result;
1382 result = SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type);
1384 do_log(SMB_VFS_OP_LOCK, result, handle, "%s", fsp->fsp_name);
1386 return result;
1389 static int smb_full_audit_kernel_flock(struct vfs_handle_struct *handle,
1390 struct files_struct *fsp,
1391 uint32 share_mode)
1393 int result;
1395 result = SMB_VFS_NEXT_KERNEL_FLOCK(handle, fsp, share_mode);
1397 do_log(SMB_VFS_OP_KERNEL_FLOCK, (result >= 0), handle, "%s",
1398 fsp->fsp_name);
1400 return result;
1403 static int smb_full_audit_linux_setlease(vfs_handle_struct *handle, files_struct *fsp,
1404 int leasetype)
1406 int result;
1408 result = SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
1410 do_log(SMB_VFS_OP_LINUX_SETLEASE, (result >= 0), handle, "%s",
1411 fsp->fsp_name);
1413 return result;
1416 static bool smb_full_audit_getlock(vfs_handle_struct *handle, files_struct *fsp,
1417 SMB_OFF_T *poffset, SMB_OFF_T *pcount, int *ptype, pid_t *ppid)
1419 bool result;
1421 result = SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype, ppid);
1423 do_log(SMB_VFS_OP_GETLOCK, result, handle, "%s", fsp->fsp_name);
1425 return result;
1428 static int smb_full_audit_symlink(vfs_handle_struct *handle,
1429 const char *oldpath, const char *newpath)
1431 int result;
1433 result = SMB_VFS_NEXT_SYMLINK(handle, oldpath, newpath);
1435 do_log(SMB_VFS_OP_SYMLINK, (result >= 0), handle,
1436 "%s|%s", oldpath, newpath);
1438 return result;
1441 static int smb_full_audit_readlink(vfs_handle_struct *handle,
1442 const char *path, char *buf, size_t bufsiz)
1444 int result;
1446 result = SMB_VFS_NEXT_READLINK(handle, path, buf, bufsiz);
1448 do_log(SMB_VFS_OP_READLINK, (result >= 0), handle, "%s", path);
1450 return result;
1453 static int smb_full_audit_link(vfs_handle_struct *handle,
1454 const char *oldpath, const char *newpath)
1456 int result;
1458 result = SMB_VFS_NEXT_LINK(handle, oldpath, newpath);
1460 do_log(SMB_VFS_OP_LINK, (result >= 0), handle,
1461 "%s|%s", oldpath, newpath);
1463 return result;
1466 static int smb_full_audit_mknod(vfs_handle_struct *handle,
1467 const char *pathname, mode_t mode, SMB_DEV_T dev)
1469 int result;
1471 result = SMB_VFS_NEXT_MKNOD(handle, pathname, mode, dev);
1473 do_log(SMB_VFS_OP_MKNOD, (result >= 0), handle, "%s", pathname);
1475 return result;
1478 static char *smb_full_audit_realpath(vfs_handle_struct *handle,
1479 const char *path, char *resolved_path)
1481 char *result;
1483 result = SMB_VFS_NEXT_REALPATH(handle, path, resolved_path);
1485 do_log(SMB_VFS_OP_REALPATH, (result != NULL), handle, "%s", path);
1487 return result;
1490 static NTSTATUS smb_full_audit_notify_watch(struct vfs_handle_struct *handle,
1491 struct sys_notify_context *ctx,
1492 struct notify_entry *e,
1493 void (*callback)(struct sys_notify_context *ctx,
1494 void *private_data,
1495 struct notify_event *ev),
1496 void *private_data, void *handle_p)
1498 NTSTATUS result;
1500 result = SMB_VFS_NEXT_NOTIFY_WATCH(handle, ctx, e, callback, private_data, handle_p);
1502 do_log(SMB_VFS_OP_NOTIFY_WATCH, NT_STATUS_IS_OK(result), handle, "");
1504 return result;
1507 static int smb_full_audit_chflags(vfs_handle_struct *handle,
1508 const char *path, unsigned int flags)
1510 int result;
1512 result = SMB_VFS_NEXT_CHFLAGS(handle, path, flags);
1514 do_log(SMB_VFS_OP_CHFLAGS, (result != 0), handle, "%s", path);
1516 return result;
1519 static struct file_id smb_full_audit_file_id_create(struct vfs_handle_struct *handle,
1520 SMB_DEV_T dev, SMB_INO_T inode)
1522 struct file_id id_zero;
1523 struct file_id result;
1525 ZERO_STRUCT(id_zero);
1527 result = SMB_VFS_NEXT_FILE_ID_CREATE(handle, dev, inode);
1529 do_log(SMB_VFS_OP_FILE_ID_CREATE,
1530 !file_id_equal(&id_zero, &result),
1531 handle, "%s", file_id_string_tos(&result));
1533 return result;
1536 static NTSTATUS smb_full_audit_streaminfo(vfs_handle_struct *handle,
1537 struct files_struct *fsp,
1538 const char *fname,
1539 TALLOC_CTX *mem_ctx,
1540 unsigned int *pnum_streams,
1541 struct stream_struct **pstreams)
1543 NTSTATUS result;
1545 result = SMB_VFS_NEXT_STREAMINFO(handle, fsp, fname, mem_ctx,
1546 pnum_streams, pstreams);
1548 do_log(SMB_VFS_OP_STREAMINFO, NT_STATUS_IS_OK(result), handle,
1549 "%s", fname);
1551 return result;
1554 static NTSTATUS smb_full_audit_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
1555 uint32 security_info,
1556 SEC_DESC **ppdesc)
1558 NTSTATUS result;
1560 result = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info, ppdesc);
1562 do_log(SMB_VFS_OP_FGET_NT_ACL, NT_STATUS_IS_OK(result), handle,
1563 "%s", fsp->fsp_name);
1565 return result;
1568 static NTSTATUS smb_full_audit_get_nt_acl(vfs_handle_struct *handle,
1569 files_struct *fsp,
1570 const char *name,
1571 uint32 security_info,
1572 SEC_DESC **ppdesc)
1574 NTSTATUS result;
1576 result = SMB_VFS_NEXT_GET_NT_ACL(handle, name, security_info, ppdesc);
1578 do_log(SMB_VFS_OP_GET_NT_ACL, NT_STATUS_IS_OK(result), handle,
1579 "%s", fsp->fsp_name);
1581 return result;
1584 static NTSTATUS smb_full_audit_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
1585 uint32 security_info_sent,
1586 SEC_DESC *psd)
1588 NTSTATUS result;
1590 result = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
1592 do_log(SMB_VFS_OP_FSET_NT_ACL, NT_STATUS_IS_OK(result), handle, "%s", fsp->fsp_name);
1594 return result;
1597 static int smb_full_audit_chmod_acl(vfs_handle_struct *handle,
1598 const char *path, mode_t mode)
1600 int result;
1602 result = SMB_VFS_NEXT_CHMOD_ACL(handle, path, mode);
1604 do_log(SMB_VFS_OP_CHMOD_ACL, (result >= 0), handle,
1605 "%s|%o", path, mode);
1607 return result;
1610 static int smb_full_audit_fchmod_acl(vfs_handle_struct *handle, files_struct *fsp,
1611 mode_t mode)
1613 int result;
1615 result = SMB_VFS_NEXT_FCHMOD_ACL(handle, fsp, mode);
1617 do_log(SMB_VFS_OP_FCHMOD_ACL, (result >= 0), handle,
1618 "%s|%o", fsp->fsp_name, mode);
1620 return result;
1623 static int smb_full_audit_sys_acl_get_entry(vfs_handle_struct *handle,
1625 SMB_ACL_T theacl, int entry_id,
1626 SMB_ACL_ENTRY_T *entry_p)
1628 int result;
1630 result = SMB_VFS_NEXT_SYS_ACL_GET_ENTRY(handle, theacl, entry_id,
1631 entry_p);
1633 do_log(SMB_VFS_OP_SYS_ACL_GET_ENTRY, (result >= 0), handle,
1634 "");
1636 return result;
1639 static int smb_full_audit_sys_acl_get_tag_type(vfs_handle_struct *handle,
1641 SMB_ACL_ENTRY_T entry_d,
1642 SMB_ACL_TAG_T *tag_type_p)
1644 int result;
1646 result = SMB_VFS_NEXT_SYS_ACL_GET_TAG_TYPE(handle, entry_d,
1647 tag_type_p);
1649 do_log(SMB_VFS_OP_SYS_ACL_GET_TAG_TYPE, (result >= 0), handle,
1650 "");
1652 return result;
1655 static int smb_full_audit_sys_acl_get_permset(vfs_handle_struct *handle,
1657 SMB_ACL_ENTRY_T entry_d,
1658 SMB_ACL_PERMSET_T *permset_p)
1660 int result;
1662 result = SMB_VFS_NEXT_SYS_ACL_GET_PERMSET(handle, entry_d,
1663 permset_p);
1665 do_log(SMB_VFS_OP_SYS_ACL_GET_PERMSET, (result >= 0), handle,
1666 "");
1668 return result;
1671 static void * smb_full_audit_sys_acl_get_qualifier(vfs_handle_struct *handle,
1673 SMB_ACL_ENTRY_T entry_d)
1675 void *result;
1677 result = SMB_VFS_NEXT_SYS_ACL_GET_QUALIFIER(handle, entry_d);
1679 do_log(SMB_VFS_OP_SYS_ACL_GET_QUALIFIER, (result != NULL), handle,
1680 "");
1682 return result;
1685 static SMB_ACL_T smb_full_audit_sys_acl_get_file(vfs_handle_struct *handle,
1686 const char *path_p,
1687 SMB_ACL_TYPE_T type)
1689 SMB_ACL_T result;
1691 result = SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, path_p, type);
1693 do_log(SMB_VFS_OP_SYS_ACL_GET_FILE, (result != NULL), handle,
1694 "%s", path_p);
1696 return result;
1699 static SMB_ACL_T smb_full_audit_sys_acl_get_fd(vfs_handle_struct *handle,
1700 files_struct *fsp)
1702 SMB_ACL_T result;
1704 result = SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp);
1706 do_log(SMB_VFS_OP_SYS_ACL_GET_FD, (result != NULL), handle,
1707 "%s", fsp->fsp_name);
1709 return result;
1712 static int smb_full_audit_sys_acl_clear_perms(vfs_handle_struct *handle,
1714 SMB_ACL_PERMSET_T permset)
1716 int result;
1718 result = SMB_VFS_NEXT_SYS_ACL_CLEAR_PERMS(handle, permset);
1720 do_log(SMB_VFS_OP_SYS_ACL_CLEAR_PERMS, (result >= 0), handle,
1721 "");
1723 return result;
1726 static int smb_full_audit_sys_acl_add_perm(vfs_handle_struct *handle,
1728 SMB_ACL_PERMSET_T permset,
1729 SMB_ACL_PERM_T perm)
1731 int result;
1733 result = SMB_VFS_NEXT_SYS_ACL_ADD_PERM(handle, permset, perm);
1735 do_log(SMB_VFS_OP_SYS_ACL_ADD_PERM, (result >= 0), handle,
1736 "");
1738 return result;
1741 static char * smb_full_audit_sys_acl_to_text(vfs_handle_struct *handle,
1742 SMB_ACL_T theacl,
1743 ssize_t *plen)
1745 char * result;
1747 result = SMB_VFS_NEXT_SYS_ACL_TO_TEXT(handle, theacl, plen);
1749 do_log(SMB_VFS_OP_SYS_ACL_TO_TEXT, (result != NULL), handle,
1750 "");
1752 return result;
1755 static SMB_ACL_T smb_full_audit_sys_acl_init(vfs_handle_struct *handle,
1757 int count)
1759 SMB_ACL_T result;
1761 result = SMB_VFS_NEXT_SYS_ACL_INIT(handle, count);
1763 do_log(SMB_VFS_OP_SYS_ACL_INIT, (result != NULL), handle,
1764 "");
1766 return result;
1769 static int smb_full_audit_sys_acl_create_entry(vfs_handle_struct *handle,
1770 SMB_ACL_T *pacl,
1771 SMB_ACL_ENTRY_T *pentry)
1773 int result;
1775 result = SMB_VFS_NEXT_SYS_ACL_CREATE_ENTRY(handle, pacl, pentry);
1777 do_log(SMB_VFS_OP_SYS_ACL_CREATE_ENTRY, (result >= 0), handle,
1778 "");
1780 return result;
1783 static int smb_full_audit_sys_acl_set_tag_type(vfs_handle_struct *handle,
1785 SMB_ACL_ENTRY_T entry,
1786 SMB_ACL_TAG_T tagtype)
1788 int result;
1790 result = SMB_VFS_NEXT_SYS_ACL_SET_TAG_TYPE(handle, entry,
1791 tagtype);
1793 do_log(SMB_VFS_OP_SYS_ACL_SET_TAG_TYPE, (result >= 0), handle,
1794 "");
1796 return result;
1799 static int smb_full_audit_sys_acl_set_qualifier(vfs_handle_struct *handle,
1801 SMB_ACL_ENTRY_T entry,
1802 void *qual)
1804 int result;
1806 result = SMB_VFS_NEXT_SYS_ACL_SET_QUALIFIER(handle, entry, qual);
1808 do_log(SMB_VFS_OP_SYS_ACL_SET_QUALIFIER, (result >= 0), handle,
1809 "");
1811 return result;
1814 static int smb_full_audit_sys_acl_set_permset(vfs_handle_struct *handle,
1816 SMB_ACL_ENTRY_T entry,
1817 SMB_ACL_PERMSET_T permset)
1819 int result;
1821 result = SMB_VFS_NEXT_SYS_ACL_SET_PERMSET(handle, entry, permset);
1823 do_log(SMB_VFS_OP_SYS_ACL_SET_PERMSET, (result >= 0), handle,
1824 "");
1826 return result;
1829 static int smb_full_audit_sys_acl_valid(vfs_handle_struct *handle,
1831 SMB_ACL_T theacl )
1833 int result;
1835 result = SMB_VFS_NEXT_SYS_ACL_VALID(handle, theacl);
1837 do_log(SMB_VFS_OP_SYS_ACL_VALID, (result >= 0), handle,
1838 "");
1840 return result;
1843 static int smb_full_audit_sys_acl_set_file(vfs_handle_struct *handle,
1845 const char *name, SMB_ACL_TYPE_T acltype,
1846 SMB_ACL_T theacl)
1848 int result;
1850 result = SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, name, acltype,
1851 theacl);
1853 do_log(SMB_VFS_OP_SYS_ACL_SET_FILE, (result >= 0), handle,
1854 "%s", name);
1856 return result;
1859 static int smb_full_audit_sys_acl_set_fd(vfs_handle_struct *handle, files_struct *fsp,
1860 SMB_ACL_T theacl)
1862 int result;
1864 result = SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, theacl);
1866 do_log(SMB_VFS_OP_SYS_ACL_SET_FD, (result >= 0), handle,
1867 "%s", fsp->fsp_name);
1869 return result;
1872 static int smb_full_audit_sys_acl_delete_def_file(vfs_handle_struct *handle,
1874 const char *path)
1876 int result;
1878 result = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, path);
1880 do_log(SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE, (result >= 0), handle,
1881 "%s", path);
1883 return result;
1886 static int smb_full_audit_sys_acl_get_perm(vfs_handle_struct *handle,
1888 SMB_ACL_PERMSET_T permset,
1889 SMB_ACL_PERM_T perm)
1891 int result;
1893 result = SMB_VFS_NEXT_SYS_ACL_GET_PERM(handle, permset, perm);
1895 do_log(SMB_VFS_OP_SYS_ACL_GET_PERM, (result >= 0), handle,
1896 "");
1898 return result;
1901 static int smb_full_audit_sys_acl_free_text(vfs_handle_struct *handle,
1903 char *text)
1905 int result;
1907 result = SMB_VFS_NEXT_SYS_ACL_FREE_TEXT(handle, text);
1909 do_log(SMB_VFS_OP_SYS_ACL_FREE_TEXT, (result >= 0), handle,
1910 "");
1912 return result;
1915 static int smb_full_audit_sys_acl_free_acl(vfs_handle_struct *handle,
1917 SMB_ACL_T posix_acl)
1919 int result;
1921 result = SMB_VFS_NEXT_SYS_ACL_FREE_ACL(handle, posix_acl);
1923 do_log(SMB_VFS_OP_SYS_ACL_FREE_ACL, (result >= 0), handle,
1924 "");
1926 return result;
1929 static int smb_full_audit_sys_acl_free_qualifier(vfs_handle_struct *handle,
1930 void *qualifier,
1931 SMB_ACL_TAG_T tagtype)
1933 int result;
1935 result = SMB_VFS_NEXT_SYS_ACL_FREE_QUALIFIER(handle, qualifier,
1936 tagtype);
1938 do_log(SMB_VFS_OP_SYS_ACL_FREE_QUALIFIER, (result >= 0), handle,
1939 "");
1941 return result;
1944 static ssize_t smb_full_audit_getxattr(struct vfs_handle_struct *handle,
1945 const char *path,
1946 const char *name, void *value, size_t size)
1948 ssize_t result;
1950 result = SMB_VFS_NEXT_GETXATTR(handle, path, name, value, size);
1952 do_log(SMB_VFS_OP_GETXATTR, (result >= 0), handle,
1953 "%s|%s", path, name);
1955 return result;
1958 static ssize_t smb_full_audit_lgetxattr(struct vfs_handle_struct *handle,
1959 const char *path, const char *name,
1960 void *value, size_t size)
1962 ssize_t result;
1964 result = SMB_VFS_NEXT_LGETXATTR(handle, path, name, value, size);
1966 do_log(SMB_VFS_OP_LGETXATTR, (result >= 0), handle,
1967 "%s|%s", path, name);
1969 return result;
1972 static ssize_t smb_full_audit_fgetxattr(struct vfs_handle_struct *handle,
1973 struct files_struct *fsp,
1974 const char *name, void *value, size_t size)
1976 ssize_t result;
1978 result = SMB_VFS_NEXT_FGETXATTR(handle, fsp, name, value, size);
1980 do_log(SMB_VFS_OP_FGETXATTR, (result >= 0), handle,
1981 "%s|%s", fsp->fsp_name, name);
1983 return result;
1986 static ssize_t smb_full_audit_listxattr(struct vfs_handle_struct *handle,
1987 const char *path, char *list, size_t size)
1989 ssize_t result;
1991 result = SMB_VFS_NEXT_LISTXATTR(handle, path, list, size);
1993 do_log(SMB_VFS_OP_LISTXATTR, (result >= 0), handle, "%s", path);
1995 return result;
1998 static ssize_t smb_full_audit_llistxattr(struct vfs_handle_struct *handle,
1999 const char *path, char *list, size_t size)
2001 ssize_t result;
2003 result = SMB_VFS_NEXT_LLISTXATTR(handle, path, list, size);
2005 do_log(SMB_VFS_OP_LLISTXATTR, (result >= 0), handle, "%s", path);
2007 return result;
2010 static ssize_t smb_full_audit_flistxattr(struct vfs_handle_struct *handle,
2011 struct files_struct *fsp, char *list,
2012 size_t size)
2014 ssize_t result;
2016 result = SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
2018 do_log(SMB_VFS_OP_FLISTXATTR, (result >= 0), handle,
2019 "%s", fsp->fsp_name);
2021 return result;
2024 static int smb_full_audit_removexattr(struct vfs_handle_struct *handle,
2025 const char *path,
2026 const char *name)
2028 int result;
2030 result = SMB_VFS_NEXT_REMOVEXATTR(handle, path, name);
2032 do_log(SMB_VFS_OP_REMOVEXATTR, (result >= 0), handle,
2033 "%s|%s", path, name);
2035 return result;
2038 static int smb_full_audit_lremovexattr(struct vfs_handle_struct *handle,
2039 const char *path,
2040 const char *name)
2042 int result;
2044 result = SMB_VFS_NEXT_LREMOVEXATTR(handle, path, name);
2046 do_log(SMB_VFS_OP_LREMOVEXATTR, (result >= 0), handle,
2047 "%s|%s", path, name);
2049 return result;
2052 static int smb_full_audit_fremovexattr(struct vfs_handle_struct *handle,
2053 struct files_struct *fsp,
2054 const char *name)
2056 int result;
2058 result = SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, name);
2060 do_log(SMB_VFS_OP_FREMOVEXATTR, (result >= 0), handle,
2061 "%s|%s", fsp->fsp_name, name);
2063 return result;
2066 static int smb_full_audit_setxattr(struct vfs_handle_struct *handle,
2067 const char *path,
2068 const char *name, const void *value, size_t size,
2069 int flags)
2071 int result;
2073 result = SMB_VFS_NEXT_SETXATTR(handle, path, name, value, size,
2074 flags);
2076 do_log(SMB_VFS_OP_SETXATTR, (result >= 0), handle,
2077 "%s|%s", path, name);
2079 return result;
2082 static int smb_full_audit_lsetxattr(struct vfs_handle_struct *handle,
2083 const char *path,
2084 const char *name, const void *value, size_t size,
2085 int flags)
2087 int result;
2089 result = SMB_VFS_NEXT_LSETXATTR(handle, path, name, value, size,
2090 flags);
2092 do_log(SMB_VFS_OP_LSETXATTR, (result >= 0), handle,
2093 "%s|%s", path, name);
2095 return result;
2098 static int smb_full_audit_fsetxattr(struct vfs_handle_struct *handle,
2099 struct files_struct *fsp, const char *name,
2100 const void *value, size_t size, int flags)
2102 int result;
2104 result = SMB_VFS_NEXT_FSETXATTR(handle, fsp, name, value, size, flags);
2106 do_log(SMB_VFS_OP_FSETXATTR, (result >= 0), handle,
2107 "%s|%s", fsp->fsp_name, name);
2109 return result;
2112 static int smb_full_audit_aio_read(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
2114 int result;
2116 result = SMB_VFS_NEXT_AIO_READ(handle, fsp, aiocb);
2117 do_log(SMB_VFS_OP_AIO_READ, (result >= 0), handle,
2118 "%s", fsp->fsp_name);
2120 return result;
2123 static int smb_full_audit_aio_write(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
2125 int result;
2127 result = SMB_VFS_NEXT_AIO_WRITE(handle, fsp, aiocb);
2128 do_log(SMB_VFS_OP_AIO_WRITE, (result >= 0), handle,
2129 "%s", fsp->fsp_name);
2131 return result;
2134 static ssize_t smb_full_audit_aio_return(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
2136 int result;
2138 result = SMB_VFS_NEXT_AIO_RETURN(handle, fsp, aiocb);
2139 do_log(SMB_VFS_OP_AIO_RETURN, (result >= 0), handle,
2140 "%s", fsp->fsp_name);
2142 return result;
2145 static int smb_full_audit_aio_cancel(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
2147 int result;
2149 result = SMB_VFS_NEXT_AIO_CANCEL(handle, fsp, aiocb);
2150 do_log(SMB_VFS_OP_AIO_CANCEL, (result >= 0), handle,
2151 "%s", fsp->fsp_name);
2153 return result;
2156 static int smb_full_audit_aio_error(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
2158 int result;
2160 result = SMB_VFS_NEXT_AIO_ERROR(handle, fsp, aiocb);
2161 do_log(SMB_VFS_OP_AIO_ERROR, (result >= 0), handle,
2162 "%s", fsp->fsp_name);
2164 return result;
2167 static int smb_full_audit_aio_fsync(struct vfs_handle_struct *handle, struct files_struct *fsp, int op, SMB_STRUCT_AIOCB *aiocb)
2169 int result;
2171 result = SMB_VFS_NEXT_AIO_FSYNC(handle, fsp, op, aiocb);
2172 do_log(SMB_VFS_OP_AIO_FSYNC, (result >= 0), handle,
2173 "%s", fsp->fsp_name);
2175 return result;
2178 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)
2180 int result;
2182 result = SMB_VFS_NEXT_AIO_SUSPEND(handle, fsp, aiocb, n, ts);
2183 do_log(SMB_VFS_OP_AIO_SUSPEND, (result >= 0), handle,
2184 "%s", fsp->fsp_name);
2186 return result;
2190 NTSTATUS vfs_full_audit_init(void);
2191 NTSTATUS vfs_full_audit_init(void)
2193 NTSTATUS ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION,
2194 "full_audit", audit_op_tuples);
2196 if (!NT_STATUS_IS_OK(ret))
2197 return ret;
2199 vfs_full_audit_debug_level = debug_add_class("full_audit");
2200 if (vfs_full_audit_debug_level == -1) {
2201 vfs_full_audit_debug_level = DBGC_VFS;
2202 DEBUG(0, ("vfs_full_audit: Couldn't register custom debugging "
2203 "class!\n"));
2204 } else {
2205 DEBUG(10, ("vfs_full_audit: Debug class number of "
2206 "'full_audit': %d\n", vfs_full_audit_debug_level));
2209 return ret;