build: format the header check for netinet/ip.h more nicely
[Samba/bb.git] / source / modules / vfs_full_audit.c
blob30da8bde5f42e5a0ef090123bf9d4b1f47e5b085
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 int smb_full_audit_get_real_filename(struct vfs_handle_struct *handle,
198 const char *path,
199 const char *name,
200 TALLOC_CTX *mem_ctx,
201 char **found_name);
202 static NTSTATUS smb_full_audit_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
203 uint32 security_info,
204 SEC_DESC **ppdesc);
205 static NTSTATUS smb_full_audit_get_nt_acl(vfs_handle_struct *handle,
206 const char *name, uint32 security_info,
207 SEC_DESC **ppdesc);
208 static NTSTATUS smb_full_audit_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
209 uint32 security_info_sent,
210 const 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},
433 {SMB_VFS_OP(smb_full_audit_get_real_filename), SMB_VFS_OP_GET_REAL_FILENAME,
434 SMB_VFS_LAYER_LOGGER},
436 /* NT ACL operations. */
438 {SMB_VFS_OP(smb_full_audit_fget_nt_acl), SMB_VFS_OP_FGET_NT_ACL,
439 SMB_VFS_LAYER_LOGGER},
440 {SMB_VFS_OP(smb_full_audit_get_nt_acl), SMB_VFS_OP_GET_NT_ACL,
441 SMB_VFS_LAYER_LOGGER},
442 {SMB_VFS_OP(smb_full_audit_fset_nt_acl), SMB_VFS_OP_FSET_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_GET_REAL_FILENAME, "get_real_filename" },
604 { SMB_VFS_OP_FGET_NT_ACL, "fget_nt_acl" },
605 { SMB_VFS_OP_GET_NT_ACL, "get_nt_acl" },
606 { SMB_VFS_OP_FSET_NT_ACL, "fset_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)),
714 conn->server_info->unix_name,
715 conn->connectpath,
716 conn->server_info->utok.gid,
717 conn->server_info->sanitized_username,
718 pdb_get_domain(conn->server_info->sam_account),
719 prefix);
720 TALLOC_FREE(prefix);
721 return result;
724 static bool log_success(vfs_handle_struct *handle, vfs_op_type op)
726 struct vfs_full_audit_private_data *pd = NULL;
728 SMB_VFS_HANDLE_GET_DATA(handle, pd,
729 struct vfs_full_audit_private_data,
730 return True);
732 if (pd->success_ops == NULL) {
733 return True;
736 return bitmap_query(pd->success_ops, op);
739 static bool log_failure(vfs_handle_struct *handle, vfs_op_type op)
741 struct vfs_full_audit_private_data *pd = NULL;
743 SMB_VFS_HANDLE_GET_DATA(handle, pd,
744 struct vfs_full_audit_private_data,
745 return True);
747 if (pd->failure_ops == NULL)
748 return True;
750 return bitmap_query(pd->failure_ops, op);
753 static void init_bitmap(struct bitmap **bm, const char **ops)
755 bool log_all = False;
757 if (*bm != NULL)
758 return;
760 *bm = bitmap_allocate(SMB_VFS_OP_LAST);
762 if (*bm == NULL) {
763 DEBUG(0, ("Could not alloc bitmap -- "
764 "defaulting to logging everything\n"));
765 return;
768 while (*ops != NULL) {
769 int i;
770 bool found = False;
772 if (strequal(*ops, "all")) {
773 log_all = True;
774 break;
777 if (strequal(*ops, "none")) {
778 break;
781 for (i=0; i<SMB_VFS_OP_LAST; i++) {
782 if (vfs_op_names[i].name == NULL) {
783 smb_panic("vfs_full_audit.c: name table not "
784 "in sync with vfs.h\n");
787 if (strequal(*ops, vfs_op_names[i].name)) {
788 bitmap_set(*bm, i);
789 found = True;
792 if (!found) {
793 DEBUG(0, ("Could not find opname %s, logging all\n",
794 *ops));
795 log_all = True;
796 break;
798 ops += 1;
801 if (log_all) {
802 /* The query functions default to True */
803 bitmap_free(*bm);
804 *bm = NULL;
808 static const char *audit_opname(vfs_op_type op)
810 if (op >= SMB_VFS_OP_LAST)
811 return "INVALID VFS OP";
812 return vfs_op_names[op].name;
815 static void do_log(vfs_op_type op, bool success, vfs_handle_struct *handle,
816 const char *format, ...)
818 fstring err_msg;
819 char *audit_pre = NULL;
820 va_list ap;
821 char *op_msg = NULL;
823 if (success && (!log_success(handle, op)))
824 return;
826 if (!success && (!log_failure(handle, op)))
827 return;
829 if (success)
830 fstrcpy(err_msg, "ok");
831 else
832 fstr_sprintf(err_msg, "fail (%s)", strerror(errno));
834 va_start(ap, format);
835 op_msg = talloc_vasprintf(NULL, format, ap);
836 va_end(ap);
838 if (!op_msg) {
839 return;
842 audit_pre = audit_prefix(NULL, handle->conn);
843 syslog(audit_syslog_priority(handle), "%s|%s|%s|%s\n",
844 audit_pre ? audit_pre : "",
845 audit_opname(op), err_msg, op_msg);
847 TALLOC_FREE(audit_pre);
848 TALLOC_FREE(op_msg);
850 return;
853 /* Free function for the private data. */
855 static void free_private_data(void **p_data)
857 struct vfs_full_audit_private_data *pd = *(struct vfs_full_audit_private_data **)p_data;
859 if (pd->success_ops) {
860 bitmap_free(pd->success_ops);
862 if (pd->failure_ops) {
863 bitmap_free(pd->failure_ops);
865 SAFE_FREE(pd);
866 *p_data = NULL;
869 /* Implementation of vfs_ops. Pass everything on to the default
870 operation but log event first. */
872 static int smb_full_audit_connect(vfs_handle_struct *handle,
873 const char *svc, const char *user)
875 int result;
876 struct vfs_full_audit_private_data *pd = NULL;
877 const char *none[] = { NULL };
878 const char *all [] = { "all" };
880 if (!handle) {
881 return -1;
884 pd = SMB_MALLOC_P(struct vfs_full_audit_private_data);
885 if (!pd) {
886 return -1;
888 ZERO_STRUCTP(pd);
890 openlog("smbd_audit", 0, audit_syslog_facility(handle));
892 init_bitmap(&pd->success_ops,
893 lp_parm_string_list(SNUM(handle->conn), "full_audit", "success",
894 none));
895 init_bitmap(&pd->failure_ops,
896 lp_parm_string_list(SNUM(handle->conn), "full_audit", "failure",
897 all));
899 /* Store the private data. */
900 SMB_VFS_HANDLE_SET_DATA(handle, pd, free_private_data,
901 struct vfs_full_audit_private_data, return -1);
903 result = SMB_VFS_NEXT_CONNECT(handle, svc, user);
905 do_log(SMB_VFS_OP_CONNECT, True, handle,
906 "%s", svc);
908 return result;
911 static void smb_full_audit_disconnect(vfs_handle_struct *handle)
913 SMB_VFS_NEXT_DISCONNECT(handle);
915 do_log(SMB_VFS_OP_DISCONNECT, True, handle,
916 "%s", lp_servicename(SNUM(handle->conn)));
918 /* The bitmaps will be disconnected when the private
919 data is deleted. */
921 return;
924 static SMB_BIG_UINT smb_full_audit_disk_free(vfs_handle_struct *handle,
925 const char *path,
926 bool small_query, SMB_BIG_UINT *bsize,
927 SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize)
929 SMB_BIG_UINT result;
931 result = SMB_VFS_NEXT_DISK_FREE(handle, path, small_query, bsize,
932 dfree, dsize);
934 /* Don't have a reasonable notion of failure here */
936 do_log(SMB_VFS_OP_DISK_FREE, True, handle, "%s", path);
938 return result;
941 static int smb_full_audit_get_quota(struct vfs_handle_struct *handle,
942 enum SMB_QUOTA_TYPE qtype, unid_t id,
943 SMB_DISK_QUOTA *qt)
945 int result;
947 result = SMB_VFS_NEXT_GET_QUOTA(handle, qtype, id, qt);
949 do_log(SMB_VFS_OP_GET_QUOTA, (result >= 0), handle, "");
951 return result;
955 static int smb_full_audit_set_quota(struct vfs_handle_struct *handle,
956 enum SMB_QUOTA_TYPE qtype, unid_t id,
957 SMB_DISK_QUOTA *qt)
959 int result;
961 result = SMB_VFS_NEXT_SET_QUOTA(handle, qtype, id, qt);
963 do_log(SMB_VFS_OP_SET_QUOTA, (result >= 0), handle, "");
965 return result;
968 static int smb_full_audit_get_shadow_copy_data(struct vfs_handle_struct *handle,
969 struct files_struct *fsp,
970 SHADOW_COPY_DATA *shadow_copy_data, bool labels)
972 int result;
974 result = SMB_VFS_NEXT_GET_SHADOW_COPY_DATA(handle, fsp, shadow_copy_data, labels);
976 do_log(SMB_VFS_OP_GET_SHADOW_COPY_DATA, (result >= 0), handle, "");
978 return result;
981 static int smb_full_audit_statvfs(struct vfs_handle_struct *handle,
982 const char *path,
983 struct vfs_statvfs_struct *statbuf)
985 int result;
987 result = SMB_VFS_NEXT_STATVFS(handle, path, statbuf);
989 do_log(SMB_VFS_OP_STATVFS, (result >= 0), handle, "");
991 return result;
994 static SMB_STRUCT_DIR *smb_full_audit_opendir(vfs_handle_struct *handle,
995 const char *fname, const char *mask, uint32 attr)
997 SMB_STRUCT_DIR *result;
999 result = SMB_VFS_NEXT_OPENDIR(handle, fname, mask, attr);
1001 do_log(SMB_VFS_OP_OPENDIR, (result != NULL), handle, "%s", fname);
1003 return result;
1006 static SMB_STRUCT_DIRENT *smb_full_audit_readdir(vfs_handle_struct *handle,
1007 SMB_STRUCT_DIR *dirp)
1009 SMB_STRUCT_DIRENT *result;
1011 result = SMB_VFS_NEXT_READDIR(handle, dirp);
1013 /* This operation has no reasonable error condition
1014 * (End of dir is also failure), so always succeed.
1016 do_log(SMB_VFS_OP_READDIR, True, handle, "");
1018 return result;
1021 static void smb_full_audit_seekdir(vfs_handle_struct *handle,
1022 SMB_STRUCT_DIR *dirp, long offset)
1024 SMB_VFS_NEXT_SEEKDIR(handle, dirp, offset);
1026 do_log(SMB_VFS_OP_SEEKDIR, True, handle, "");
1027 return;
1030 static long smb_full_audit_telldir(vfs_handle_struct *handle,
1031 SMB_STRUCT_DIR *dirp)
1033 long result;
1035 result = SMB_VFS_NEXT_TELLDIR(handle, dirp);
1037 do_log(SMB_VFS_OP_TELLDIR, True, handle, "");
1039 return result;
1042 static void smb_full_audit_rewinddir(vfs_handle_struct *handle,
1043 SMB_STRUCT_DIR *dirp)
1045 SMB_VFS_NEXT_REWINDDIR(handle, dirp);
1047 do_log(SMB_VFS_OP_REWINDDIR, True, handle, "");
1048 return;
1051 static int smb_full_audit_mkdir(vfs_handle_struct *handle,
1052 const char *path, mode_t mode)
1054 int result;
1056 result = SMB_VFS_NEXT_MKDIR(handle, path, mode);
1058 do_log(SMB_VFS_OP_MKDIR, (result >= 0), handle, "%s", path);
1060 return result;
1063 static int smb_full_audit_rmdir(vfs_handle_struct *handle,
1064 const char *path)
1066 int result;
1068 result = SMB_VFS_NEXT_RMDIR(handle, path);
1070 do_log(SMB_VFS_OP_RMDIR, (result >= 0), handle, "%s", path);
1072 return result;
1075 static int smb_full_audit_closedir(vfs_handle_struct *handle,
1076 SMB_STRUCT_DIR *dirp)
1078 int result;
1080 result = SMB_VFS_NEXT_CLOSEDIR(handle, dirp);
1082 do_log(SMB_VFS_OP_CLOSEDIR, (result >= 0), handle, "");
1084 return result;
1087 static int smb_full_audit_open(vfs_handle_struct *handle,
1088 const char *fname, files_struct *fsp, int flags, mode_t mode)
1090 int result;
1092 result = SMB_VFS_NEXT_OPEN(handle, fname, fsp, flags, mode);
1094 do_log(SMB_VFS_OP_OPEN, (result >= 0), handle, "%s|%s",
1095 ((flags & O_WRONLY) || (flags & O_RDWR))?"w":"r",
1096 fname);
1098 return result;
1101 static int smb_full_audit_close(vfs_handle_struct *handle, files_struct *fsp)
1103 int result;
1105 result = SMB_VFS_NEXT_CLOSE(handle, fsp);
1107 do_log(SMB_VFS_OP_CLOSE, (result >= 0), handle, "%s", fsp->fsp_name);
1109 return result;
1112 static ssize_t smb_full_audit_read(vfs_handle_struct *handle, files_struct *fsp,
1113 void *data, size_t n)
1115 ssize_t result;
1117 result = SMB_VFS_NEXT_READ(handle, fsp, data, n);
1119 do_log(SMB_VFS_OP_READ, (result >= 0), handle, "%s", fsp->fsp_name);
1121 return result;
1124 static ssize_t smb_full_audit_pread(vfs_handle_struct *handle, files_struct *fsp,
1125 void *data, size_t n, SMB_OFF_T offset)
1127 ssize_t result;
1129 result = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
1131 do_log(SMB_VFS_OP_PREAD, (result >= 0), handle, "%s", fsp->fsp_name);
1133 return result;
1136 static ssize_t smb_full_audit_write(vfs_handle_struct *handle, files_struct *fsp,
1137 const void *data, size_t n)
1139 ssize_t result;
1141 result = SMB_VFS_NEXT_WRITE(handle, fsp, data, n);
1143 do_log(SMB_VFS_OP_WRITE, (result >= 0), handle, "%s", fsp->fsp_name);
1145 return result;
1148 static ssize_t smb_full_audit_pwrite(vfs_handle_struct *handle, files_struct *fsp,
1149 const void *data, size_t n,
1150 SMB_OFF_T offset)
1152 ssize_t result;
1154 result = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
1156 do_log(SMB_VFS_OP_PWRITE, (result >= 0), handle, "%s", fsp->fsp_name);
1158 return result;
1161 static SMB_OFF_T smb_full_audit_lseek(vfs_handle_struct *handle, files_struct *fsp,
1162 SMB_OFF_T offset, int whence)
1164 ssize_t result;
1166 result = SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence);
1168 do_log(SMB_VFS_OP_LSEEK, (result != (ssize_t)-1), handle,
1169 "%s", fsp->fsp_name);
1171 return result;
1174 static ssize_t smb_full_audit_sendfile(vfs_handle_struct *handle, int tofd,
1175 files_struct *fromfsp,
1176 const DATA_BLOB *hdr, SMB_OFF_T offset,
1177 size_t n)
1179 ssize_t result;
1181 result = SMB_VFS_NEXT_SENDFILE(handle, tofd, fromfsp, hdr, offset, n);
1183 do_log(SMB_VFS_OP_SENDFILE, (result >= 0), handle,
1184 "%s", fromfsp->fsp_name);
1186 return result;
1189 static ssize_t smb_full_audit_recvfile(vfs_handle_struct *handle, int fromfd,
1190 files_struct *tofsp,
1191 SMB_OFF_T offset,
1192 size_t n)
1194 ssize_t result;
1196 result = SMB_VFS_NEXT_RECVFILE(handle, fromfd, tofsp, offset, n);
1198 do_log(SMB_VFS_OP_RECVFILE, (result >= 0), handle,
1199 "%s", tofsp->fsp_name);
1201 return result;
1204 static int smb_full_audit_rename(vfs_handle_struct *handle,
1205 const char *oldname, const char *newname)
1207 int result;
1209 result = SMB_VFS_NEXT_RENAME(handle, oldname, newname);
1211 do_log(SMB_VFS_OP_RENAME, (result >= 0), handle, "%s|%s", oldname, newname);
1213 return result;
1216 static int smb_full_audit_fsync(vfs_handle_struct *handle, files_struct *fsp)
1218 int result;
1220 result = SMB_VFS_NEXT_FSYNC(handle, fsp);
1222 do_log(SMB_VFS_OP_FSYNC, (result >= 0), handle, "%s", fsp->fsp_name);
1224 return result;
1227 static int smb_full_audit_stat(vfs_handle_struct *handle,
1228 const char *fname, SMB_STRUCT_STAT *sbuf)
1230 int result;
1232 result = SMB_VFS_NEXT_STAT(handle, fname, sbuf);
1234 do_log(SMB_VFS_OP_STAT, (result >= 0), handle, "%s", fname);
1236 return result;
1239 static int smb_full_audit_fstat(vfs_handle_struct *handle, files_struct *fsp,
1240 SMB_STRUCT_STAT *sbuf)
1242 int result;
1244 result = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1246 do_log(SMB_VFS_OP_FSTAT, (result >= 0), handle, "%s", fsp->fsp_name);
1248 return result;
1251 static int smb_full_audit_lstat(vfs_handle_struct *handle,
1252 const char *path, SMB_STRUCT_STAT *sbuf)
1254 int result;
1256 result = SMB_VFS_NEXT_LSTAT(handle, path, sbuf);
1258 do_log(SMB_VFS_OP_LSTAT, (result >= 0), handle, "%s", path);
1260 return result;
1263 static int smb_full_audit_unlink(vfs_handle_struct *handle,
1264 const char *path)
1266 int result;
1268 result = SMB_VFS_NEXT_UNLINK(handle, path);
1270 do_log(SMB_VFS_OP_UNLINK, (result >= 0), handle, "%s", path);
1272 return result;
1275 static int smb_full_audit_chmod(vfs_handle_struct *handle,
1276 const char *path, mode_t mode)
1278 int result;
1280 result = SMB_VFS_NEXT_CHMOD(handle, path, mode);
1282 do_log(SMB_VFS_OP_CHMOD, (result >= 0), handle, "%s|%o", path, mode);
1284 return result;
1287 static int smb_full_audit_fchmod(vfs_handle_struct *handle, files_struct *fsp,
1288 mode_t mode)
1290 int result;
1292 result = SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1294 do_log(SMB_VFS_OP_FCHMOD, (result >= 0), handle,
1295 "%s|%o", fsp->fsp_name, mode);
1297 return result;
1300 static int smb_full_audit_chown(vfs_handle_struct *handle,
1301 const char *path, uid_t uid, gid_t gid)
1303 int result;
1305 result = SMB_VFS_NEXT_CHOWN(handle, path, uid, gid);
1307 do_log(SMB_VFS_OP_CHOWN, (result >= 0), handle, "%s|%ld|%ld",
1308 path, (long int)uid, (long int)gid);
1310 return result;
1313 static int smb_full_audit_fchown(vfs_handle_struct *handle, files_struct *fsp,
1314 uid_t uid, gid_t gid)
1316 int result;
1318 result = SMB_VFS_NEXT_FCHOWN(handle, fsp, uid, gid);
1320 do_log(SMB_VFS_OP_FCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1321 fsp->fsp_name, (long int)uid, (long int)gid);
1323 return result;
1326 static int smb_full_audit_lchown(vfs_handle_struct *handle,
1327 const char *path, uid_t uid, gid_t gid)
1329 int result;
1331 result = SMB_VFS_NEXT_LCHOWN(handle, path, uid, gid);
1333 do_log(SMB_VFS_OP_LCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1334 path, (long int)uid, (long int)gid);
1336 return result;
1339 static int smb_full_audit_chdir(vfs_handle_struct *handle,
1340 const char *path)
1342 int result;
1344 result = SMB_VFS_NEXT_CHDIR(handle, path);
1346 do_log(SMB_VFS_OP_CHDIR, (result >= 0), handle, "chdir|%s", path);
1348 return result;
1351 static char *smb_full_audit_getwd(vfs_handle_struct *handle,
1352 char *path)
1354 char *result;
1356 result = SMB_VFS_NEXT_GETWD(handle, path);
1358 do_log(SMB_VFS_OP_GETWD, (result != NULL), handle, "%s", path);
1360 return result;
1363 static int smb_full_audit_ntimes(vfs_handle_struct *handle,
1364 const char *path, const struct timespec ts[2])
1366 int result;
1368 result = SMB_VFS_NEXT_NTIMES(handle, path, ts);
1370 do_log(SMB_VFS_OP_NTIMES, (result >= 0), handle, "%s", path);
1372 return result;
1375 static int smb_full_audit_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
1376 SMB_OFF_T len)
1378 int result;
1380 result = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1382 do_log(SMB_VFS_OP_FTRUNCATE, (result >= 0), handle,
1383 "%s", fsp->fsp_name);
1385 return result;
1388 static bool smb_full_audit_lock(vfs_handle_struct *handle, files_struct *fsp,
1389 int op, SMB_OFF_T offset, SMB_OFF_T count, int type)
1391 bool result;
1393 result = SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type);
1395 do_log(SMB_VFS_OP_LOCK, result, handle, "%s", fsp->fsp_name);
1397 return result;
1400 static int smb_full_audit_kernel_flock(struct vfs_handle_struct *handle,
1401 struct files_struct *fsp,
1402 uint32 share_mode)
1404 int result;
1406 result = SMB_VFS_NEXT_KERNEL_FLOCK(handle, fsp, share_mode);
1408 do_log(SMB_VFS_OP_KERNEL_FLOCK, (result >= 0), handle, "%s",
1409 fsp->fsp_name);
1411 return result;
1414 static int smb_full_audit_linux_setlease(vfs_handle_struct *handle, files_struct *fsp,
1415 int leasetype)
1417 int result;
1419 result = SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
1421 do_log(SMB_VFS_OP_LINUX_SETLEASE, (result >= 0), handle, "%s",
1422 fsp->fsp_name);
1424 return result;
1427 static bool smb_full_audit_getlock(vfs_handle_struct *handle, files_struct *fsp,
1428 SMB_OFF_T *poffset, SMB_OFF_T *pcount, int *ptype, pid_t *ppid)
1430 bool result;
1432 result = SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype, ppid);
1434 do_log(SMB_VFS_OP_GETLOCK, result, handle, "%s", fsp->fsp_name);
1436 return result;
1439 static int smb_full_audit_symlink(vfs_handle_struct *handle,
1440 const char *oldpath, const char *newpath)
1442 int result;
1444 result = SMB_VFS_NEXT_SYMLINK(handle, oldpath, newpath);
1446 do_log(SMB_VFS_OP_SYMLINK, (result >= 0), handle,
1447 "%s|%s", oldpath, newpath);
1449 return result;
1452 static int smb_full_audit_readlink(vfs_handle_struct *handle,
1453 const char *path, char *buf, size_t bufsiz)
1455 int result;
1457 result = SMB_VFS_NEXT_READLINK(handle, path, buf, bufsiz);
1459 do_log(SMB_VFS_OP_READLINK, (result >= 0), handle, "%s", path);
1461 return result;
1464 static int smb_full_audit_link(vfs_handle_struct *handle,
1465 const char *oldpath, const char *newpath)
1467 int result;
1469 result = SMB_VFS_NEXT_LINK(handle, oldpath, newpath);
1471 do_log(SMB_VFS_OP_LINK, (result >= 0), handle,
1472 "%s|%s", oldpath, newpath);
1474 return result;
1477 static int smb_full_audit_mknod(vfs_handle_struct *handle,
1478 const char *pathname, mode_t mode, SMB_DEV_T dev)
1480 int result;
1482 result = SMB_VFS_NEXT_MKNOD(handle, pathname, mode, dev);
1484 do_log(SMB_VFS_OP_MKNOD, (result >= 0), handle, "%s", pathname);
1486 return result;
1489 static char *smb_full_audit_realpath(vfs_handle_struct *handle,
1490 const char *path, char *resolved_path)
1492 char *result;
1494 result = SMB_VFS_NEXT_REALPATH(handle, path, resolved_path);
1496 do_log(SMB_VFS_OP_REALPATH, (result != NULL), handle, "%s", path);
1498 return result;
1501 static NTSTATUS smb_full_audit_notify_watch(struct vfs_handle_struct *handle,
1502 struct sys_notify_context *ctx,
1503 struct notify_entry *e,
1504 void (*callback)(struct sys_notify_context *ctx,
1505 void *private_data,
1506 struct notify_event *ev),
1507 void *private_data, void *handle_p)
1509 NTSTATUS result;
1511 result = SMB_VFS_NEXT_NOTIFY_WATCH(handle, ctx, e, callback, private_data, handle_p);
1513 do_log(SMB_VFS_OP_NOTIFY_WATCH, NT_STATUS_IS_OK(result), handle, "");
1515 return result;
1518 static int smb_full_audit_chflags(vfs_handle_struct *handle,
1519 const char *path, unsigned int flags)
1521 int result;
1523 result = SMB_VFS_NEXT_CHFLAGS(handle, path, flags);
1525 do_log(SMB_VFS_OP_CHFLAGS, (result != 0), handle, "%s", path);
1527 return result;
1530 static struct file_id smb_full_audit_file_id_create(struct vfs_handle_struct *handle,
1531 SMB_DEV_T dev, SMB_INO_T inode)
1533 struct file_id id_zero;
1534 struct file_id result;
1536 ZERO_STRUCT(id_zero);
1538 result = SMB_VFS_NEXT_FILE_ID_CREATE(handle, dev, inode);
1540 do_log(SMB_VFS_OP_FILE_ID_CREATE,
1541 !file_id_equal(&id_zero, &result),
1542 handle, "%s", file_id_string_tos(&result));
1544 return result;
1547 static NTSTATUS smb_full_audit_streaminfo(vfs_handle_struct *handle,
1548 struct files_struct *fsp,
1549 const char *fname,
1550 TALLOC_CTX *mem_ctx,
1551 unsigned int *pnum_streams,
1552 struct stream_struct **pstreams)
1554 NTSTATUS result;
1556 result = SMB_VFS_NEXT_STREAMINFO(handle, fsp, fname, mem_ctx,
1557 pnum_streams, pstreams);
1559 do_log(SMB_VFS_OP_STREAMINFO, NT_STATUS_IS_OK(result), handle,
1560 "%s", fname);
1562 return result;
1565 static int smb_full_audit_get_real_filename(struct vfs_handle_struct *handle,
1566 const char *path,
1567 const char *name,
1568 TALLOC_CTX *mem_ctx,
1569 char **found_name)
1571 int result;
1573 result = SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name, mem_ctx,
1574 found_name);
1576 do_log(SMB_VFS_OP_GET_REAL_FILENAME, (result == 0), handle,
1577 "%s/%s->%s", path, name, (result == 0) ? "" : *found_name);
1579 return result;
1582 static NTSTATUS smb_full_audit_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
1583 uint32 security_info,
1584 SEC_DESC **ppdesc)
1586 NTSTATUS result;
1588 result = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info, ppdesc);
1590 do_log(SMB_VFS_OP_FGET_NT_ACL, NT_STATUS_IS_OK(result), handle,
1591 "%s", fsp->fsp_name);
1593 return result;
1596 static NTSTATUS smb_full_audit_get_nt_acl(vfs_handle_struct *handle,
1597 const char *name,
1598 uint32 security_info,
1599 SEC_DESC **ppdesc)
1601 NTSTATUS result;
1603 result = SMB_VFS_NEXT_GET_NT_ACL(handle, name, security_info, ppdesc);
1605 do_log(SMB_VFS_OP_GET_NT_ACL, NT_STATUS_IS_OK(result), handle,
1606 "%s", name);
1608 return result;
1611 static NTSTATUS smb_full_audit_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
1612 uint32 security_info_sent,
1613 const SEC_DESC *psd)
1615 NTSTATUS result;
1617 result = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
1619 do_log(SMB_VFS_OP_FSET_NT_ACL, NT_STATUS_IS_OK(result), handle, "%s", fsp->fsp_name);
1621 return result;
1624 static int smb_full_audit_chmod_acl(vfs_handle_struct *handle,
1625 const char *path, mode_t mode)
1627 int result;
1629 result = SMB_VFS_NEXT_CHMOD_ACL(handle, path, mode);
1631 do_log(SMB_VFS_OP_CHMOD_ACL, (result >= 0), handle,
1632 "%s|%o", path, mode);
1634 return result;
1637 static int smb_full_audit_fchmod_acl(vfs_handle_struct *handle, files_struct *fsp,
1638 mode_t mode)
1640 int result;
1642 result = SMB_VFS_NEXT_FCHMOD_ACL(handle, fsp, mode);
1644 do_log(SMB_VFS_OP_FCHMOD_ACL, (result >= 0), handle,
1645 "%s|%o", fsp->fsp_name, mode);
1647 return result;
1650 static int smb_full_audit_sys_acl_get_entry(vfs_handle_struct *handle,
1652 SMB_ACL_T theacl, int entry_id,
1653 SMB_ACL_ENTRY_T *entry_p)
1655 int result;
1657 result = SMB_VFS_NEXT_SYS_ACL_GET_ENTRY(handle, theacl, entry_id,
1658 entry_p);
1660 do_log(SMB_VFS_OP_SYS_ACL_GET_ENTRY, (result >= 0), handle,
1661 "");
1663 return result;
1666 static int smb_full_audit_sys_acl_get_tag_type(vfs_handle_struct *handle,
1668 SMB_ACL_ENTRY_T entry_d,
1669 SMB_ACL_TAG_T *tag_type_p)
1671 int result;
1673 result = SMB_VFS_NEXT_SYS_ACL_GET_TAG_TYPE(handle, entry_d,
1674 tag_type_p);
1676 do_log(SMB_VFS_OP_SYS_ACL_GET_TAG_TYPE, (result >= 0), handle,
1677 "");
1679 return result;
1682 static int smb_full_audit_sys_acl_get_permset(vfs_handle_struct *handle,
1684 SMB_ACL_ENTRY_T entry_d,
1685 SMB_ACL_PERMSET_T *permset_p)
1687 int result;
1689 result = SMB_VFS_NEXT_SYS_ACL_GET_PERMSET(handle, entry_d,
1690 permset_p);
1692 do_log(SMB_VFS_OP_SYS_ACL_GET_PERMSET, (result >= 0), handle,
1693 "");
1695 return result;
1698 static void * smb_full_audit_sys_acl_get_qualifier(vfs_handle_struct *handle,
1700 SMB_ACL_ENTRY_T entry_d)
1702 void *result;
1704 result = SMB_VFS_NEXT_SYS_ACL_GET_QUALIFIER(handle, entry_d);
1706 do_log(SMB_VFS_OP_SYS_ACL_GET_QUALIFIER, (result != NULL), handle,
1707 "");
1709 return result;
1712 static SMB_ACL_T smb_full_audit_sys_acl_get_file(vfs_handle_struct *handle,
1713 const char *path_p,
1714 SMB_ACL_TYPE_T type)
1716 SMB_ACL_T result;
1718 result = SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, path_p, type);
1720 do_log(SMB_VFS_OP_SYS_ACL_GET_FILE, (result != NULL), handle,
1721 "%s", path_p);
1723 return result;
1726 static SMB_ACL_T smb_full_audit_sys_acl_get_fd(vfs_handle_struct *handle,
1727 files_struct *fsp)
1729 SMB_ACL_T result;
1731 result = SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp);
1733 do_log(SMB_VFS_OP_SYS_ACL_GET_FD, (result != NULL), handle,
1734 "%s", fsp->fsp_name);
1736 return result;
1739 static int smb_full_audit_sys_acl_clear_perms(vfs_handle_struct *handle,
1741 SMB_ACL_PERMSET_T permset)
1743 int result;
1745 result = SMB_VFS_NEXT_SYS_ACL_CLEAR_PERMS(handle, permset);
1747 do_log(SMB_VFS_OP_SYS_ACL_CLEAR_PERMS, (result >= 0), handle,
1748 "");
1750 return result;
1753 static int smb_full_audit_sys_acl_add_perm(vfs_handle_struct *handle,
1755 SMB_ACL_PERMSET_T permset,
1756 SMB_ACL_PERM_T perm)
1758 int result;
1760 result = SMB_VFS_NEXT_SYS_ACL_ADD_PERM(handle, permset, perm);
1762 do_log(SMB_VFS_OP_SYS_ACL_ADD_PERM, (result >= 0), handle,
1763 "");
1765 return result;
1768 static char * smb_full_audit_sys_acl_to_text(vfs_handle_struct *handle,
1769 SMB_ACL_T theacl,
1770 ssize_t *plen)
1772 char * result;
1774 result = SMB_VFS_NEXT_SYS_ACL_TO_TEXT(handle, theacl, plen);
1776 do_log(SMB_VFS_OP_SYS_ACL_TO_TEXT, (result != NULL), handle,
1777 "");
1779 return result;
1782 static SMB_ACL_T smb_full_audit_sys_acl_init(vfs_handle_struct *handle,
1784 int count)
1786 SMB_ACL_T result;
1788 result = SMB_VFS_NEXT_SYS_ACL_INIT(handle, count);
1790 do_log(SMB_VFS_OP_SYS_ACL_INIT, (result != NULL), handle,
1791 "");
1793 return result;
1796 static int smb_full_audit_sys_acl_create_entry(vfs_handle_struct *handle,
1797 SMB_ACL_T *pacl,
1798 SMB_ACL_ENTRY_T *pentry)
1800 int result;
1802 result = SMB_VFS_NEXT_SYS_ACL_CREATE_ENTRY(handle, pacl, pentry);
1804 do_log(SMB_VFS_OP_SYS_ACL_CREATE_ENTRY, (result >= 0), handle,
1805 "");
1807 return result;
1810 static int smb_full_audit_sys_acl_set_tag_type(vfs_handle_struct *handle,
1812 SMB_ACL_ENTRY_T entry,
1813 SMB_ACL_TAG_T tagtype)
1815 int result;
1817 result = SMB_VFS_NEXT_SYS_ACL_SET_TAG_TYPE(handle, entry,
1818 tagtype);
1820 do_log(SMB_VFS_OP_SYS_ACL_SET_TAG_TYPE, (result >= 0), handle,
1821 "");
1823 return result;
1826 static int smb_full_audit_sys_acl_set_qualifier(vfs_handle_struct *handle,
1828 SMB_ACL_ENTRY_T entry,
1829 void *qual)
1831 int result;
1833 result = SMB_VFS_NEXT_SYS_ACL_SET_QUALIFIER(handle, entry, qual);
1835 do_log(SMB_VFS_OP_SYS_ACL_SET_QUALIFIER, (result >= 0), handle,
1836 "");
1838 return result;
1841 static int smb_full_audit_sys_acl_set_permset(vfs_handle_struct *handle,
1843 SMB_ACL_ENTRY_T entry,
1844 SMB_ACL_PERMSET_T permset)
1846 int result;
1848 result = SMB_VFS_NEXT_SYS_ACL_SET_PERMSET(handle, entry, permset);
1850 do_log(SMB_VFS_OP_SYS_ACL_SET_PERMSET, (result >= 0), handle,
1851 "");
1853 return result;
1856 static int smb_full_audit_sys_acl_valid(vfs_handle_struct *handle,
1858 SMB_ACL_T theacl )
1860 int result;
1862 result = SMB_VFS_NEXT_SYS_ACL_VALID(handle, theacl);
1864 do_log(SMB_VFS_OP_SYS_ACL_VALID, (result >= 0), handle,
1865 "");
1867 return result;
1870 static int smb_full_audit_sys_acl_set_file(vfs_handle_struct *handle,
1872 const char *name, SMB_ACL_TYPE_T acltype,
1873 SMB_ACL_T theacl)
1875 int result;
1877 result = SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, name, acltype,
1878 theacl);
1880 do_log(SMB_VFS_OP_SYS_ACL_SET_FILE, (result >= 0), handle,
1881 "%s", name);
1883 return result;
1886 static int smb_full_audit_sys_acl_set_fd(vfs_handle_struct *handle, files_struct *fsp,
1887 SMB_ACL_T theacl)
1889 int result;
1891 result = SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, theacl);
1893 do_log(SMB_VFS_OP_SYS_ACL_SET_FD, (result >= 0), handle,
1894 "%s", fsp->fsp_name);
1896 return result;
1899 static int smb_full_audit_sys_acl_delete_def_file(vfs_handle_struct *handle,
1901 const char *path)
1903 int result;
1905 result = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, path);
1907 do_log(SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE, (result >= 0), handle,
1908 "%s", path);
1910 return result;
1913 static int smb_full_audit_sys_acl_get_perm(vfs_handle_struct *handle,
1915 SMB_ACL_PERMSET_T permset,
1916 SMB_ACL_PERM_T perm)
1918 int result;
1920 result = SMB_VFS_NEXT_SYS_ACL_GET_PERM(handle, permset, perm);
1922 do_log(SMB_VFS_OP_SYS_ACL_GET_PERM, (result >= 0), handle,
1923 "");
1925 return result;
1928 static int smb_full_audit_sys_acl_free_text(vfs_handle_struct *handle,
1930 char *text)
1932 int result;
1934 result = SMB_VFS_NEXT_SYS_ACL_FREE_TEXT(handle, text);
1936 do_log(SMB_VFS_OP_SYS_ACL_FREE_TEXT, (result >= 0), handle,
1937 "");
1939 return result;
1942 static int smb_full_audit_sys_acl_free_acl(vfs_handle_struct *handle,
1944 SMB_ACL_T posix_acl)
1946 int result;
1948 result = SMB_VFS_NEXT_SYS_ACL_FREE_ACL(handle, posix_acl);
1950 do_log(SMB_VFS_OP_SYS_ACL_FREE_ACL, (result >= 0), handle,
1951 "");
1953 return result;
1956 static int smb_full_audit_sys_acl_free_qualifier(vfs_handle_struct *handle,
1957 void *qualifier,
1958 SMB_ACL_TAG_T tagtype)
1960 int result;
1962 result = SMB_VFS_NEXT_SYS_ACL_FREE_QUALIFIER(handle, qualifier,
1963 tagtype);
1965 do_log(SMB_VFS_OP_SYS_ACL_FREE_QUALIFIER, (result >= 0), handle,
1966 "");
1968 return result;
1971 static ssize_t smb_full_audit_getxattr(struct vfs_handle_struct *handle,
1972 const char *path,
1973 const char *name, void *value, size_t size)
1975 ssize_t result;
1977 result = SMB_VFS_NEXT_GETXATTR(handle, path, name, value, size);
1979 do_log(SMB_VFS_OP_GETXATTR, (result >= 0), handle,
1980 "%s|%s", path, name);
1982 return result;
1985 static ssize_t smb_full_audit_lgetxattr(struct vfs_handle_struct *handle,
1986 const char *path, const char *name,
1987 void *value, size_t size)
1989 ssize_t result;
1991 result = SMB_VFS_NEXT_LGETXATTR(handle, path, name, value, size);
1993 do_log(SMB_VFS_OP_LGETXATTR, (result >= 0), handle,
1994 "%s|%s", path, name);
1996 return result;
1999 static ssize_t smb_full_audit_fgetxattr(struct vfs_handle_struct *handle,
2000 struct files_struct *fsp,
2001 const char *name, void *value, size_t size)
2003 ssize_t result;
2005 result = SMB_VFS_NEXT_FGETXATTR(handle, fsp, name, value, size);
2007 do_log(SMB_VFS_OP_FGETXATTR, (result >= 0), handle,
2008 "%s|%s", fsp->fsp_name, name);
2010 return result;
2013 static ssize_t smb_full_audit_listxattr(struct vfs_handle_struct *handle,
2014 const char *path, char *list, size_t size)
2016 ssize_t result;
2018 result = SMB_VFS_NEXT_LISTXATTR(handle, path, list, size);
2020 do_log(SMB_VFS_OP_LISTXATTR, (result >= 0), handle, "%s", path);
2022 return result;
2025 static ssize_t smb_full_audit_llistxattr(struct vfs_handle_struct *handle,
2026 const char *path, char *list, size_t size)
2028 ssize_t result;
2030 result = SMB_VFS_NEXT_LLISTXATTR(handle, path, list, size);
2032 do_log(SMB_VFS_OP_LLISTXATTR, (result >= 0), handle, "%s", path);
2034 return result;
2037 static ssize_t smb_full_audit_flistxattr(struct vfs_handle_struct *handle,
2038 struct files_struct *fsp, char *list,
2039 size_t size)
2041 ssize_t result;
2043 result = SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
2045 do_log(SMB_VFS_OP_FLISTXATTR, (result >= 0), handle,
2046 "%s", fsp->fsp_name);
2048 return result;
2051 static int smb_full_audit_removexattr(struct vfs_handle_struct *handle,
2052 const char *path,
2053 const char *name)
2055 int result;
2057 result = SMB_VFS_NEXT_REMOVEXATTR(handle, path, name);
2059 do_log(SMB_VFS_OP_REMOVEXATTR, (result >= 0), handle,
2060 "%s|%s", path, name);
2062 return result;
2065 static int smb_full_audit_lremovexattr(struct vfs_handle_struct *handle,
2066 const char *path,
2067 const char *name)
2069 int result;
2071 result = SMB_VFS_NEXT_LREMOVEXATTR(handle, path, name);
2073 do_log(SMB_VFS_OP_LREMOVEXATTR, (result >= 0), handle,
2074 "%s|%s", path, name);
2076 return result;
2079 static int smb_full_audit_fremovexattr(struct vfs_handle_struct *handle,
2080 struct files_struct *fsp,
2081 const char *name)
2083 int result;
2085 result = SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, name);
2087 do_log(SMB_VFS_OP_FREMOVEXATTR, (result >= 0), handle,
2088 "%s|%s", fsp->fsp_name, name);
2090 return result;
2093 static int smb_full_audit_setxattr(struct vfs_handle_struct *handle,
2094 const char *path,
2095 const char *name, const void *value, size_t size,
2096 int flags)
2098 int result;
2100 result = SMB_VFS_NEXT_SETXATTR(handle, path, name, value, size,
2101 flags);
2103 do_log(SMB_VFS_OP_SETXATTR, (result >= 0), handle,
2104 "%s|%s", path, name);
2106 return result;
2109 static int smb_full_audit_lsetxattr(struct vfs_handle_struct *handle,
2110 const char *path,
2111 const char *name, const void *value, size_t size,
2112 int flags)
2114 int result;
2116 result = SMB_VFS_NEXT_LSETXATTR(handle, path, name, value, size,
2117 flags);
2119 do_log(SMB_VFS_OP_LSETXATTR, (result >= 0), handle,
2120 "%s|%s", path, name);
2122 return result;
2125 static int smb_full_audit_fsetxattr(struct vfs_handle_struct *handle,
2126 struct files_struct *fsp, const char *name,
2127 const void *value, size_t size, int flags)
2129 int result;
2131 result = SMB_VFS_NEXT_FSETXATTR(handle, fsp, name, value, size, flags);
2133 do_log(SMB_VFS_OP_FSETXATTR, (result >= 0), handle,
2134 "%s|%s", fsp->fsp_name, name);
2136 return result;
2139 static int smb_full_audit_aio_read(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
2141 int result;
2143 result = SMB_VFS_NEXT_AIO_READ(handle, fsp, aiocb);
2144 do_log(SMB_VFS_OP_AIO_READ, (result >= 0), handle,
2145 "%s", fsp->fsp_name);
2147 return result;
2150 static int smb_full_audit_aio_write(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
2152 int result;
2154 result = SMB_VFS_NEXT_AIO_WRITE(handle, fsp, aiocb);
2155 do_log(SMB_VFS_OP_AIO_WRITE, (result >= 0), handle,
2156 "%s", fsp->fsp_name);
2158 return result;
2161 static ssize_t smb_full_audit_aio_return(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
2163 int result;
2165 result = SMB_VFS_NEXT_AIO_RETURN(handle, fsp, aiocb);
2166 do_log(SMB_VFS_OP_AIO_RETURN, (result >= 0), handle,
2167 "%s", fsp->fsp_name);
2169 return result;
2172 static int smb_full_audit_aio_cancel(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
2174 int result;
2176 result = SMB_VFS_NEXT_AIO_CANCEL(handle, fsp, aiocb);
2177 do_log(SMB_VFS_OP_AIO_CANCEL, (result >= 0), handle,
2178 "%s", fsp->fsp_name);
2180 return result;
2183 static int smb_full_audit_aio_error(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
2185 int result;
2187 result = SMB_VFS_NEXT_AIO_ERROR(handle, fsp, aiocb);
2188 do_log(SMB_VFS_OP_AIO_ERROR, (result >= 0), handle,
2189 "%s", fsp->fsp_name);
2191 return result;
2194 static int smb_full_audit_aio_fsync(struct vfs_handle_struct *handle, struct files_struct *fsp, int op, SMB_STRUCT_AIOCB *aiocb)
2196 int result;
2198 result = SMB_VFS_NEXT_AIO_FSYNC(handle, fsp, op, aiocb);
2199 do_log(SMB_VFS_OP_AIO_FSYNC, (result >= 0), handle,
2200 "%s", fsp->fsp_name);
2202 return result;
2205 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)
2207 int result;
2209 result = SMB_VFS_NEXT_AIO_SUSPEND(handle, fsp, aiocb, n, ts);
2210 do_log(SMB_VFS_OP_AIO_SUSPEND, (result >= 0), handle,
2211 "%s", fsp->fsp_name);
2213 return result;
2217 NTSTATUS vfs_full_audit_init(void);
2218 NTSTATUS vfs_full_audit_init(void)
2220 NTSTATUS ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION,
2221 "full_audit", audit_op_tuples);
2223 if (!NT_STATUS_IS_OK(ret))
2224 return ret;
2226 vfs_full_audit_debug_level = debug_add_class("full_audit");
2227 if (vfs_full_audit_debug_level == -1) {
2228 vfs_full_audit_debug_level = DBGC_VFS;
2229 DEBUG(0, ("vfs_full_audit: Couldn't register custom debugging "
2230 "class!\n"));
2231 } else {
2232 DEBUG(10, ("vfs_full_audit: Debug class number of "
2233 "'full_audit': %d\n", vfs_full_audit_debug_level));
2236 return ret;