fd97a4ccff8f7d97b809bd5f111d5a03f7e170fd
[metze/samba/wip.git] / source3 / modules / vfs_full_audit.c
1 /* 
2  * Auditing VFS module for samba.  Log selected file operations to syslog
3  * facility.
4  *
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
10  *
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.
15  *  
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.
20  *  
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/>.
23  */
24
25 /*
26  * This module implements parseable logging for all Samba VFS operations.
27  *
28  * You use it as follows:
29  *
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
36  *
37  * vfs op can be "all" which means log all operations.
38  * vfs op can be "none" which means no logging.
39  *
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
43  *
44  * where "nobody" is the connected username and "192.168.234.1" is the
45  * client's IP address. 
46  *
47  * Options:
48  *
49  * prefix: A macro expansion template prepended to the syslog entry.
50  *
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.
54  *
55  * failure: A list of VFS operations for which failure to complete should be
56  * logged. Defaults to logging everything.
57  */
58
59
60 #include "includes.h"
61
62 static int vfs_full_audit_debug_level = DBGC_VFS;
63
64 struct vfs_full_audit_private_data {
65         struct bitmap *success_ops;
66         struct bitmap *failure_ops;
67 };
68
69 #undef DBGC_CLASS
70 #define DBGC_CLASS vfs_full_audit_debug_level
71
72 /* Function prototypes */
73
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 uint64_t smb_full_audit_disk_free(vfs_handle_struct *handle,
78                                     const char *path,
79                                     bool small_query, uint64_t *bsize, 
80                                     uint64_t *dfree, uint64_t *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);
93
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 NTSTATUS smb_full_audit_create_file(vfs_handle_struct *handle,
113                                       struct smb_request *req,
114                                       uint16_t root_dir_fid,
115                                       const char *fname,
116                                       bool is_dos_path,
117                                       uint32_t access_mask,
118                                       uint32_t share_access,
119                                       uint32_t create_disposition,
120                                       uint32_t create_options,
121                                       uint32_t file_attributes,
122                                       uint32_t oplock_request,
123                                       uint64_t allocation_size,
124                                       struct security_descriptor *sd,
125                                       struct ea_list *ea_list,
126                                       files_struct **result,
127                                       int *pinfo,
128                                       SMB_STRUCT_STAT *psbuf);
129 static int smb_full_audit_close(vfs_handle_struct *handle, files_struct *fsp);
130 static ssize_t smb_full_audit_read(vfs_handle_struct *handle, files_struct *fsp,
131                           void *data, size_t n);
132 static ssize_t smb_full_audit_pread(vfs_handle_struct *handle, files_struct *fsp,
133                            void *data, size_t n, SMB_OFF_T offset);
134 static ssize_t smb_full_audit_write(vfs_handle_struct *handle, files_struct *fsp,
135                            const void *data, size_t n);
136 static ssize_t smb_full_audit_pwrite(vfs_handle_struct *handle, files_struct *fsp,
137                             const void *data, size_t n,
138                             SMB_OFF_T offset);
139 static SMB_OFF_T smb_full_audit_lseek(vfs_handle_struct *handle, files_struct *fsp,
140                              SMB_OFF_T offset, int whence);
141 static ssize_t smb_full_audit_sendfile(vfs_handle_struct *handle, int tofd,
142                               files_struct *fromfsp,
143                               const DATA_BLOB *hdr, SMB_OFF_T offset,
144                               size_t n);
145 static ssize_t smb_full_audit_recvfile(vfs_handle_struct *handle, int fromfd,
146                               files_struct *tofsp,
147                               SMB_OFF_T offset,
148                               size_t n);
149 static int smb_full_audit_rename(vfs_handle_struct *handle,
150                         const char *oldname, const char *newname);
151 static int smb_full_audit_fsync(vfs_handle_struct *handle, files_struct *fsp);
152 static int smb_full_audit_stat(vfs_handle_struct *handle,
153                       const char *fname, SMB_STRUCT_STAT *sbuf);
154 static int smb_full_audit_fstat(vfs_handle_struct *handle, files_struct *fsp,
155                        SMB_STRUCT_STAT *sbuf);
156 static int smb_full_audit_lstat(vfs_handle_struct *handle,
157                        const char *path, SMB_STRUCT_STAT *sbuf);
158 static int smb_full_audit_unlink(vfs_handle_struct *handle,
159                         const char *path);
160 static int smb_full_audit_chmod(vfs_handle_struct *handle,
161                        const char *path, mode_t mode);
162 static int smb_full_audit_fchmod(vfs_handle_struct *handle, files_struct *fsp,
163                         mode_t mode);
164 static int smb_full_audit_chown(vfs_handle_struct *handle,
165                        const char *path, uid_t uid, gid_t gid);
166 static int smb_full_audit_fchown(vfs_handle_struct *handle, files_struct *fsp,
167                         uid_t uid, gid_t gid);
168 static int smb_full_audit_lchown(vfs_handle_struct *handle,
169                        const char *path, uid_t uid, gid_t gid);
170 static int smb_full_audit_chdir(vfs_handle_struct *handle,
171                        const char *path);
172 static char *smb_full_audit_getwd(vfs_handle_struct *handle,
173                          char *path);
174 static int smb_full_audit_ntimes(vfs_handle_struct *handle,
175                        const char *path, const struct timespec ts[2]);
176 static int smb_full_audit_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
177                            SMB_OFF_T len);
178 static bool smb_full_audit_lock(vfs_handle_struct *handle, files_struct *fsp,
179                        int op, SMB_OFF_T offset, SMB_OFF_T count, int type);
180 static int smb_full_audit_kernel_flock(struct vfs_handle_struct *handle,
181                                        struct files_struct *fsp,
182                                        uint32 share_mode);
183 static int smb_full_audit_linux_setlease(vfs_handle_struct *handle, files_struct *fsp,
184                                         int leasetype);
185 static bool smb_full_audit_getlock(vfs_handle_struct *handle, files_struct *fsp,
186                        SMB_OFF_T *poffset, SMB_OFF_T *pcount, int *ptype, pid_t *ppid);
187 static int smb_full_audit_symlink(vfs_handle_struct *handle,
188                          const char *oldpath, const char *newpath);
189 static int smb_full_audit_readlink(vfs_handle_struct *handle,
190                           const char *path, char *buf, size_t bufsiz);
191 static int smb_full_audit_link(vfs_handle_struct *handle,
192                       const char *oldpath, const char *newpath);
193 static int smb_full_audit_mknod(vfs_handle_struct *handle,
194                        const char *pathname, mode_t mode, SMB_DEV_T dev);
195 static char *smb_full_audit_realpath(vfs_handle_struct *handle,
196                             const char *path, char *resolved_path);
197 static NTSTATUS smb_full_audit_notify_watch(struct vfs_handle_struct *handle,
198                         struct sys_notify_context *ctx,
199                         struct notify_entry *e,
200                         void (*callback)(struct sys_notify_context *ctx,
201                                         void *private_data,
202                                         struct notify_event *ev),
203                         void *private_data, void *handle_p);
204 static int smb_full_audit_chflags(vfs_handle_struct *handle,
205                             const char *path, unsigned int flags);
206 static struct file_id smb_full_audit_file_id_create(struct vfs_handle_struct *handle,
207                                                     SMB_DEV_T dev, SMB_INO_T inode);
208 static NTSTATUS smb_full_audit_streaminfo(vfs_handle_struct *handle,
209                                           struct files_struct *fsp,
210                                           const char *fname,
211                                           TALLOC_CTX *mem_ctx,
212                                           unsigned int *pnum_streams,
213                                           struct stream_struct **pstreams);
214 static NTSTATUS smb_full_audit_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
215                                 uint32 security_info,
216                                 SEC_DESC **ppdesc);
217 static NTSTATUS smb_full_audit_get_nt_acl(vfs_handle_struct *handle,
218                                const char *name, uint32 security_info,
219                                SEC_DESC **ppdesc);
220 static NTSTATUS smb_full_audit_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
221                               uint32 security_info_sent,
222                               const SEC_DESC *psd);
223 static int smb_full_audit_chmod_acl(vfs_handle_struct *handle,
224                            const char *path, mode_t mode);
225 static int smb_full_audit_fchmod_acl(vfs_handle_struct *handle, files_struct *fsp,
226                                      mode_t mode);
227 static int smb_full_audit_sys_acl_get_entry(vfs_handle_struct *handle,
228                                    SMB_ACL_T theacl, int entry_id,
229                                    SMB_ACL_ENTRY_T *entry_p);
230 static int smb_full_audit_sys_acl_get_tag_type(vfs_handle_struct *handle,
231                                       SMB_ACL_ENTRY_T entry_d,
232                                       SMB_ACL_TAG_T *tag_type_p);
233 static int smb_full_audit_sys_acl_get_permset(vfs_handle_struct *handle,
234                                      SMB_ACL_ENTRY_T entry_d,
235                                      SMB_ACL_PERMSET_T *permset_p);
236 static void * smb_full_audit_sys_acl_get_qualifier(vfs_handle_struct *handle,
237                                           SMB_ACL_ENTRY_T entry_d);
238 static SMB_ACL_T smb_full_audit_sys_acl_get_file(vfs_handle_struct *handle,
239                                         const char *path_p,
240                                         SMB_ACL_TYPE_T type);
241 static SMB_ACL_T smb_full_audit_sys_acl_get_fd(vfs_handle_struct *handle,
242                                       files_struct *fsp);
243 static int smb_full_audit_sys_acl_clear_perms(vfs_handle_struct *handle,
244                                      SMB_ACL_PERMSET_T permset);
245 static int smb_full_audit_sys_acl_add_perm(vfs_handle_struct *handle,
246                                   SMB_ACL_PERMSET_T permset,
247                                   SMB_ACL_PERM_T perm);
248 static char * smb_full_audit_sys_acl_to_text(vfs_handle_struct *handle,
249                                     SMB_ACL_T theacl,
250                                     ssize_t *plen);
251 static SMB_ACL_T smb_full_audit_sys_acl_init(vfs_handle_struct *handle,
252                                     int count);
253 static int smb_full_audit_sys_acl_create_entry(vfs_handle_struct *handle,
254                                       SMB_ACL_T *pacl,
255                                       SMB_ACL_ENTRY_T *pentry);
256 static int smb_full_audit_sys_acl_set_tag_type(vfs_handle_struct *handle,
257                                       SMB_ACL_ENTRY_T entry,
258                                       SMB_ACL_TAG_T tagtype);
259 static int smb_full_audit_sys_acl_set_qualifier(vfs_handle_struct *handle,
260                                        SMB_ACL_ENTRY_T entry,
261                                        void *qual);
262 static int smb_full_audit_sys_acl_set_permset(vfs_handle_struct *handle,
263                                      SMB_ACL_ENTRY_T entry,
264                                      SMB_ACL_PERMSET_T permset);
265 static int smb_full_audit_sys_acl_valid(vfs_handle_struct *handle,
266                                SMB_ACL_T theacl );
267 static int smb_full_audit_sys_acl_set_file(vfs_handle_struct *handle,
268                                   const char *name, SMB_ACL_TYPE_T acltype,
269                                   SMB_ACL_T theacl);
270 static int smb_full_audit_sys_acl_set_fd(vfs_handle_struct *handle, files_struct *fsp,
271                                 SMB_ACL_T theacl);
272 static int smb_full_audit_sys_acl_delete_def_file(vfs_handle_struct *handle,
273                                          const char *path);
274 static int smb_full_audit_sys_acl_get_perm(vfs_handle_struct *handle,
275                                   SMB_ACL_PERMSET_T permset,
276                                   SMB_ACL_PERM_T perm);
277 static int smb_full_audit_sys_acl_free_text(vfs_handle_struct *handle,
278                                    char *text);
279 static int smb_full_audit_sys_acl_free_acl(vfs_handle_struct *handle,
280                                   SMB_ACL_T posix_acl);
281 static int smb_full_audit_sys_acl_free_qualifier(vfs_handle_struct *handle,
282                                         void *qualifier,
283                                         SMB_ACL_TAG_T tagtype);
284 static ssize_t smb_full_audit_getxattr(struct vfs_handle_struct *handle,
285                               const char *path,
286                               const char *name, void *value, size_t size);
287 static ssize_t smb_full_audit_lgetxattr(struct vfs_handle_struct *handle,
288                                const char *path, const char *name,
289                                void *value, size_t size);
290 static ssize_t smb_full_audit_fgetxattr(struct vfs_handle_struct *handle,
291                                struct files_struct *fsp,
292                                const char *name, void *value, size_t size);
293 static ssize_t smb_full_audit_listxattr(struct vfs_handle_struct *handle,
294                                const char *path, char *list, size_t size);
295 static ssize_t smb_full_audit_llistxattr(struct vfs_handle_struct *handle,
296                                 const char *path, char *list, size_t size);
297 static ssize_t smb_full_audit_flistxattr(struct vfs_handle_struct *handle,
298                                 struct files_struct *fsp, char *list,
299                                 size_t size);
300 static int smb_full_audit_removexattr(struct vfs_handle_struct *handle,
301                              const char *path,
302                              const char *name);
303 static int smb_full_audit_lremovexattr(struct vfs_handle_struct *handle,
304                               const char *path,
305                               const char *name);
306 static int smb_full_audit_fremovexattr(struct vfs_handle_struct *handle,
307                               struct files_struct *fsp,
308                               const char *name);
309 static int smb_full_audit_setxattr(struct vfs_handle_struct *handle,
310                           const char *path,
311                           const char *name, const void *value, size_t size,
312                           int flags);
313 static int smb_full_audit_lsetxattr(struct vfs_handle_struct *handle,
314                            const char *path,
315                            const char *name, const void *value, size_t size,
316                            int flags);
317 static int smb_full_audit_fsetxattr(struct vfs_handle_struct *handle,
318                            struct files_struct *fsp, const char *name,
319                            const void *value, size_t size, int flags);
320
321 static int smb_full_audit_aio_read(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb);
322 static int smb_full_audit_aio_write(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb);
323 static ssize_t smb_full_audit_aio_return(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb);
324 static int smb_full_audit_aio_cancel(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb);
325 static int smb_full_audit_aio_error(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb);
326 static int smb_full_audit_aio_fsync(struct vfs_handle_struct *handle, struct files_struct *fsp, int op, SMB_STRUCT_AIOCB *aiocb);
327 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);
328
329 /* VFS operations */
330
331 static vfs_op_tuple audit_op_tuples[] = {
332     
333         /* Disk operations */
334
335         {SMB_VFS_OP(smb_full_audit_connect),    SMB_VFS_OP_CONNECT,
336          SMB_VFS_LAYER_LOGGER},
337         {SMB_VFS_OP(smb_full_audit_disconnect), SMB_VFS_OP_DISCONNECT,
338          SMB_VFS_LAYER_LOGGER},
339         {SMB_VFS_OP(smb_full_audit_disk_free),  SMB_VFS_OP_DISK_FREE,
340          SMB_VFS_LAYER_LOGGER},
341         {SMB_VFS_OP(smb_full_audit_get_quota),  SMB_VFS_OP_GET_QUOTA,
342          SMB_VFS_LAYER_LOGGER},
343         {SMB_VFS_OP(smb_full_audit_set_quota),  SMB_VFS_OP_SET_QUOTA,
344          SMB_VFS_LAYER_LOGGER},
345         {SMB_VFS_OP(smb_full_audit_get_shadow_copy_data), SMB_VFS_OP_GET_SHADOW_COPY_DATA,
346          SMB_VFS_LAYER_LOGGER},
347         {SMB_VFS_OP(smb_full_audit_statvfs),    SMB_VFS_OP_STATVFS,
348          SMB_VFS_LAYER_LOGGER},
349
350         /* Directory operations */
351
352         {SMB_VFS_OP(smb_full_audit_opendir),    SMB_VFS_OP_OPENDIR,
353          SMB_VFS_LAYER_LOGGER},
354         {SMB_VFS_OP(smb_full_audit_readdir),    SMB_VFS_OP_READDIR,
355          SMB_VFS_LAYER_LOGGER},
356         {SMB_VFS_OP(smb_full_audit_seekdir),    SMB_VFS_OP_SEEKDIR,
357          SMB_VFS_LAYER_LOGGER},
358         {SMB_VFS_OP(smb_full_audit_telldir),    SMB_VFS_OP_TELLDIR,
359          SMB_VFS_LAYER_LOGGER},
360         {SMB_VFS_OP(smb_full_audit_rewinddir),  SMB_VFS_OP_REWINDDIR,
361          SMB_VFS_LAYER_LOGGER},
362         {SMB_VFS_OP(smb_full_audit_mkdir),      SMB_VFS_OP_MKDIR,
363          SMB_VFS_LAYER_LOGGER},
364         {SMB_VFS_OP(smb_full_audit_rmdir),      SMB_VFS_OP_RMDIR,
365          SMB_VFS_LAYER_LOGGER},
366         {SMB_VFS_OP(smb_full_audit_closedir),   SMB_VFS_OP_CLOSEDIR,
367          SMB_VFS_LAYER_LOGGER},
368
369         /* File operations */
370
371         {SMB_VFS_OP(smb_full_audit_open),       SMB_VFS_OP_OPEN,
372          SMB_VFS_LAYER_LOGGER},
373         {SMB_VFS_OP(smb_full_audit_create_file),SMB_VFS_OP_CREATE_FILE,
374          SMB_VFS_LAYER_LOGGER},
375         {SMB_VFS_OP(smb_full_audit_close),      SMB_VFS_OP_CLOSE,
376          SMB_VFS_LAYER_LOGGER},
377         {SMB_VFS_OP(smb_full_audit_read),       SMB_VFS_OP_READ,
378          SMB_VFS_LAYER_LOGGER},
379         {SMB_VFS_OP(smb_full_audit_pread),      SMB_VFS_OP_PREAD,
380          SMB_VFS_LAYER_LOGGER},
381         {SMB_VFS_OP(smb_full_audit_write),      SMB_VFS_OP_WRITE,
382          SMB_VFS_LAYER_LOGGER},
383         {SMB_VFS_OP(smb_full_audit_pwrite),     SMB_VFS_OP_PWRITE,
384          SMB_VFS_LAYER_LOGGER},
385         {SMB_VFS_OP(smb_full_audit_lseek),      SMB_VFS_OP_LSEEK,
386          SMB_VFS_LAYER_LOGGER},
387         {SMB_VFS_OP(smb_full_audit_sendfile),   SMB_VFS_OP_SENDFILE,
388          SMB_VFS_LAYER_LOGGER},
389         {SMB_VFS_OP(smb_full_audit_recvfile),   SMB_VFS_OP_RECVFILE,
390          SMB_VFS_LAYER_LOGGER},
391         {SMB_VFS_OP(smb_full_audit_rename),     SMB_VFS_OP_RENAME,
392          SMB_VFS_LAYER_LOGGER},
393         {SMB_VFS_OP(smb_full_audit_fsync),      SMB_VFS_OP_FSYNC,
394          SMB_VFS_LAYER_LOGGER},
395         {SMB_VFS_OP(smb_full_audit_stat),       SMB_VFS_OP_STAT,
396          SMB_VFS_LAYER_LOGGER},
397         {SMB_VFS_OP(smb_full_audit_fstat),      SMB_VFS_OP_FSTAT,
398          SMB_VFS_LAYER_LOGGER},
399         {SMB_VFS_OP(smb_full_audit_lstat),      SMB_VFS_OP_LSTAT,
400          SMB_VFS_LAYER_LOGGER},
401         {SMB_VFS_OP(smb_full_audit_unlink),     SMB_VFS_OP_UNLINK,
402          SMB_VFS_LAYER_LOGGER},
403         {SMB_VFS_OP(smb_full_audit_chmod),      SMB_VFS_OP_CHMOD,
404          SMB_VFS_LAYER_LOGGER},
405         {SMB_VFS_OP(smb_full_audit_fchmod),     SMB_VFS_OP_FCHMOD,
406          SMB_VFS_LAYER_LOGGER},
407         {SMB_VFS_OP(smb_full_audit_chown),      SMB_VFS_OP_CHOWN,
408          SMB_VFS_LAYER_LOGGER},
409         {SMB_VFS_OP(smb_full_audit_fchown),     SMB_VFS_OP_FCHOWN,
410          SMB_VFS_LAYER_LOGGER},
411         {SMB_VFS_OP(smb_full_audit_lchown),     SMB_VFS_OP_LCHOWN,
412          SMB_VFS_LAYER_LOGGER},
413         {SMB_VFS_OP(smb_full_audit_chdir),      SMB_VFS_OP_CHDIR,
414          SMB_VFS_LAYER_LOGGER},
415         {SMB_VFS_OP(smb_full_audit_getwd),      SMB_VFS_OP_GETWD,
416          SMB_VFS_LAYER_LOGGER},
417         {SMB_VFS_OP(smb_full_audit_ntimes),     SMB_VFS_OP_NTIMES,
418          SMB_VFS_LAYER_LOGGER},
419         {SMB_VFS_OP(smb_full_audit_ftruncate),  SMB_VFS_OP_FTRUNCATE,
420          SMB_VFS_LAYER_LOGGER},
421         {SMB_VFS_OP(smb_full_audit_lock),       SMB_VFS_OP_LOCK,
422          SMB_VFS_LAYER_LOGGER},
423         {SMB_VFS_OP(smb_full_audit_kernel_flock),       SMB_VFS_OP_KERNEL_FLOCK,
424          SMB_VFS_LAYER_LOGGER},
425         {SMB_VFS_OP(smb_full_audit_linux_setlease),       SMB_VFS_OP_LINUX_SETLEASE,
426          SMB_VFS_LAYER_LOGGER},
427         {SMB_VFS_OP(smb_full_audit_getlock),    SMB_VFS_OP_GETLOCK,
428          SMB_VFS_LAYER_LOGGER},
429         {SMB_VFS_OP(smb_full_audit_symlink),    SMB_VFS_OP_SYMLINK,
430          SMB_VFS_LAYER_LOGGER},
431         {SMB_VFS_OP(smb_full_audit_readlink),   SMB_VFS_OP_READLINK,
432          SMB_VFS_LAYER_LOGGER},
433         {SMB_VFS_OP(smb_full_audit_link),       SMB_VFS_OP_LINK,
434          SMB_VFS_LAYER_LOGGER},
435         {SMB_VFS_OP(smb_full_audit_mknod),      SMB_VFS_OP_MKNOD,
436          SMB_VFS_LAYER_LOGGER},
437         {SMB_VFS_OP(smb_full_audit_realpath),   SMB_VFS_OP_REALPATH,
438          SMB_VFS_LAYER_LOGGER},
439         {SMB_VFS_OP(smb_full_audit_notify_watch),SMB_VFS_OP_NOTIFY_WATCH,
440          SMB_VFS_LAYER_LOGGER},
441         {SMB_VFS_OP(smb_full_audit_chflags),    SMB_VFS_OP_CHFLAGS,
442          SMB_VFS_LAYER_LOGGER},
443         {SMB_VFS_OP(smb_full_audit_file_id_create),     SMB_VFS_OP_FILE_ID_CREATE,
444          SMB_VFS_LAYER_LOGGER},
445         {SMB_VFS_OP(smb_full_audit_streaminfo), SMB_VFS_OP_STREAMINFO,
446          SMB_VFS_LAYER_LOGGER},
447
448         /* NT ACL operations. */
449
450         {SMB_VFS_OP(smb_full_audit_fget_nt_acl),        SMB_VFS_OP_FGET_NT_ACL,
451          SMB_VFS_LAYER_LOGGER},
452         {SMB_VFS_OP(smb_full_audit_get_nt_acl), SMB_VFS_OP_GET_NT_ACL,
453          SMB_VFS_LAYER_LOGGER},
454         {SMB_VFS_OP(smb_full_audit_fset_nt_acl),        SMB_VFS_OP_FSET_NT_ACL,
455          SMB_VFS_LAYER_LOGGER},
456
457         /* POSIX ACL operations. */
458
459         {SMB_VFS_OP(smb_full_audit_chmod_acl),  SMB_VFS_OP_CHMOD_ACL,
460          SMB_VFS_LAYER_LOGGER},
461         {SMB_VFS_OP(smb_full_audit_fchmod_acl), SMB_VFS_OP_FCHMOD_ACL,
462          SMB_VFS_LAYER_LOGGER},
463         {SMB_VFS_OP(smb_full_audit_sys_acl_get_entry),  SMB_VFS_OP_SYS_ACL_GET_ENTRY,
464          SMB_VFS_LAYER_LOGGER},
465         {SMB_VFS_OP(smb_full_audit_sys_acl_get_tag_type),       SMB_VFS_OP_SYS_ACL_GET_TAG_TYPE,
466          SMB_VFS_LAYER_LOGGER},
467         {SMB_VFS_OP(smb_full_audit_sys_acl_get_permset),        SMB_VFS_OP_SYS_ACL_GET_PERMSET,
468          SMB_VFS_LAYER_LOGGER},
469         {SMB_VFS_OP(smb_full_audit_sys_acl_get_qualifier),      SMB_VFS_OP_SYS_ACL_GET_QUALIFIER,
470          SMB_VFS_LAYER_LOGGER},
471         {SMB_VFS_OP(smb_full_audit_sys_acl_get_file),   SMB_VFS_OP_SYS_ACL_GET_FILE,
472          SMB_VFS_LAYER_LOGGER},
473 {SMB_VFS_OP(smb_full_audit_sys_acl_get_fd),     SMB_VFS_OP_SYS_ACL_GET_FD,
474          SMB_VFS_LAYER_LOGGER},
475         {SMB_VFS_OP(smb_full_audit_sys_acl_clear_perms),        SMB_VFS_OP_SYS_ACL_CLEAR_PERMS,
476          SMB_VFS_LAYER_LOGGER},
477         {SMB_VFS_OP(smb_full_audit_sys_acl_add_perm),   SMB_VFS_OP_SYS_ACL_ADD_PERM,
478          SMB_VFS_LAYER_LOGGER},
479         {SMB_VFS_OP(smb_full_audit_sys_acl_to_text),    SMB_VFS_OP_SYS_ACL_TO_TEXT,
480          SMB_VFS_LAYER_LOGGER},
481         {SMB_VFS_OP(smb_full_audit_sys_acl_init),       SMB_VFS_OP_SYS_ACL_INIT,
482          SMB_VFS_LAYER_LOGGER},
483         {SMB_VFS_OP(smb_full_audit_sys_acl_create_entry),       SMB_VFS_OP_SYS_ACL_CREATE_ENTRY,
484          SMB_VFS_LAYER_LOGGER},
485         {SMB_VFS_OP(smb_full_audit_sys_acl_set_tag_type),       SMB_VFS_OP_SYS_ACL_SET_TAG_TYPE,
486          SMB_VFS_LAYER_LOGGER},
487         {SMB_VFS_OP(smb_full_audit_sys_acl_set_qualifier),      SMB_VFS_OP_SYS_ACL_SET_QUALIFIER,
488          SMB_VFS_LAYER_LOGGER},
489         {SMB_VFS_OP(smb_full_audit_sys_acl_set_permset),        SMB_VFS_OP_SYS_ACL_SET_PERMSET,
490          SMB_VFS_LAYER_LOGGER},
491         {SMB_VFS_OP(smb_full_audit_sys_acl_valid),      SMB_VFS_OP_SYS_ACL_VALID,
492          SMB_VFS_LAYER_LOGGER},
493         {SMB_VFS_OP(smb_full_audit_sys_acl_set_file),   SMB_VFS_OP_SYS_ACL_SET_FILE,
494          SMB_VFS_LAYER_LOGGER},
495         {SMB_VFS_OP(smb_full_audit_sys_acl_set_fd),     SMB_VFS_OP_SYS_ACL_SET_FD,
496          SMB_VFS_LAYER_LOGGER},
497         {SMB_VFS_OP(smb_full_audit_sys_acl_delete_def_file),    SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE,
498          SMB_VFS_LAYER_LOGGER},
499         {SMB_VFS_OP(smb_full_audit_sys_acl_get_perm),   SMB_VFS_OP_SYS_ACL_GET_PERM,
500          SMB_VFS_LAYER_LOGGER},
501         {SMB_VFS_OP(smb_full_audit_sys_acl_free_text),  SMB_VFS_OP_SYS_ACL_FREE_TEXT,
502          SMB_VFS_LAYER_LOGGER},
503         {SMB_VFS_OP(smb_full_audit_sys_acl_free_acl),   SMB_VFS_OP_SYS_ACL_FREE_ACL,
504          SMB_VFS_LAYER_LOGGER},
505         {SMB_VFS_OP(smb_full_audit_sys_acl_free_qualifier),     SMB_VFS_OP_SYS_ACL_FREE_QUALIFIER,
506          SMB_VFS_LAYER_LOGGER},
507         
508         /* EA operations. */
509
510         {SMB_VFS_OP(smb_full_audit_getxattr),   SMB_VFS_OP_GETXATTR,
511          SMB_VFS_LAYER_LOGGER},
512         {SMB_VFS_OP(smb_full_audit_lgetxattr),  SMB_VFS_OP_LGETXATTR,
513          SMB_VFS_LAYER_LOGGER},
514         {SMB_VFS_OP(smb_full_audit_fgetxattr),  SMB_VFS_OP_FGETXATTR,
515          SMB_VFS_LAYER_LOGGER},
516         {SMB_VFS_OP(smb_full_audit_listxattr),  SMB_VFS_OP_LISTXATTR,
517          SMB_VFS_LAYER_LOGGER},
518         {SMB_VFS_OP(smb_full_audit_llistxattr), SMB_VFS_OP_LLISTXATTR,
519          SMB_VFS_LAYER_LOGGER},
520         {SMB_VFS_OP(smb_full_audit_flistxattr), SMB_VFS_OP_FLISTXATTR,
521          SMB_VFS_LAYER_LOGGER},
522         {SMB_VFS_OP(smb_full_audit_removexattr),        SMB_VFS_OP_REMOVEXATTR,
523          SMB_VFS_LAYER_LOGGER},
524         {SMB_VFS_OP(smb_full_audit_lremovexattr),       SMB_VFS_OP_LREMOVEXATTR,
525          SMB_VFS_LAYER_LOGGER},
526         {SMB_VFS_OP(smb_full_audit_fremovexattr),       SMB_VFS_OP_FREMOVEXATTR,
527          SMB_VFS_LAYER_LOGGER},
528         {SMB_VFS_OP(smb_full_audit_setxattr),   SMB_VFS_OP_SETXATTR,
529          SMB_VFS_LAYER_LOGGER},
530         {SMB_VFS_OP(smb_full_audit_lsetxattr),  SMB_VFS_OP_LSETXATTR,
531          SMB_VFS_LAYER_LOGGER},
532         {SMB_VFS_OP(smb_full_audit_fsetxattr),  SMB_VFS_OP_FSETXATTR,
533          SMB_VFS_LAYER_LOGGER},
534         
535         {SMB_VFS_OP(smb_full_audit_aio_read),   SMB_VFS_OP_AIO_READ,
536          SMB_VFS_LAYER_LOGGER},
537         {SMB_VFS_OP(smb_full_audit_aio_write),  SMB_VFS_OP_AIO_WRITE,
538          SMB_VFS_LAYER_LOGGER},
539         {SMB_VFS_OP(smb_full_audit_aio_return), SMB_VFS_OP_AIO_RETURN,
540          SMB_VFS_LAYER_LOGGER},
541         {SMB_VFS_OP(smb_full_audit_aio_cancel), SMB_VFS_OP_AIO_CANCEL,
542          SMB_VFS_LAYER_LOGGER},
543         {SMB_VFS_OP(smb_full_audit_aio_error),  SMB_VFS_OP_AIO_ERROR,
544          SMB_VFS_LAYER_LOGGER},
545         {SMB_VFS_OP(smb_full_audit_aio_fsync),  SMB_VFS_OP_AIO_FSYNC,
546          SMB_VFS_LAYER_LOGGER},
547         {SMB_VFS_OP(smb_full_audit_aio_suspend),SMB_VFS_OP_AIO_SUSPEND,
548          SMB_VFS_LAYER_LOGGER},
549
550         /* Finish VFS operations definition */
551         
552         {SMB_VFS_OP(NULL),              SMB_VFS_OP_NOOP,
553          SMB_VFS_LAYER_NOOP}
554 };
555
556 /* The following array *must* be in the same order as defined in vfs.h */
557
558 static struct {
559         vfs_op_type type;
560         const char *name;
561 } vfs_op_names[] = {
562         { SMB_VFS_OP_CONNECT,   "connect" },
563         { SMB_VFS_OP_DISCONNECT,        "disconnect" },
564         { SMB_VFS_OP_DISK_FREE, "disk_free" },
565         { SMB_VFS_OP_GET_QUOTA, "get_quota" },
566         { SMB_VFS_OP_SET_QUOTA, "set_quota" },
567         { SMB_VFS_OP_GET_SHADOW_COPY_DATA,      "get_shadow_copy_data" },
568         { SMB_VFS_OP_STATVFS,   "statvfs" },
569         { SMB_VFS_OP_FS_CAPABILITIES,   "fs_capabilities" },
570         { SMB_VFS_OP_OPENDIR,   "opendir" },
571         { SMB_VFS_OP_READDIR,   "readdir" },
572         { SMB_VFS_OP_SEEKDIR,   "seekdir" },
573         { SMB_VFS_OP_TELLDIR,   "telldir" },
574         { SMB_VFS_OP_REWINDDIR, "rewinddir" },
575         { SMB_VFS_OP_MKDIR,     "mkdir" },
576         { SMB_VFS_OP_RMDIR,     "rmdir" },
577         { SMB_VFS_OP_CLOSEDIR,  "closedir" },
578         { SMB_VFS_OP_OPEN,      "open" },
579         { SMB_VFS_OP_CLOSE,     "close" },
580         { SMB_VFS_OP_READ,      "read" },
581         { SMB_VFS_OP_PREAD,     "pread" },
582         { SMB_VFS_OP_WRITE,     "write" },
583         { SMB_VFS_OP_PWRITE,    "pwrite" },
584         { SMB_VFS_OP_LSEEK,     "lseek" },
585         { SMB_VFS_OP_SENDFILE,  "sendfile" },
586         { SMB_VFS_OP_RECVFILE,  "recvfile" },
587         { SMB_VFS_OP_RENAME,    "rename" },
588         { SMB_VFS_OP_FSYNC,     "fsync" },
589         { SMB_VFS_OP_STAT,      "stat" },
590         { SMB_VFS_OP_FSTAT,     "fstat" },
591         { SMB_VFS_OP_LSTAT,     "lstat" },
592         { SMB_VFS_OP_UNLINK,    "unlink" },
593         { SMB_VFS_OP_CHMOD,     "chmod" },
594         { SMB_VFS_OP_FCHMOD,    "fchmod" },
595         { SMB_VFS_OP_CHOWN,     "chown" },
596         { SMB_VFS_OP_FCHOWN,    "fchown" },
597         { SMB_VFS_OP_LCHOWN,    "lchown" },
598         { SMB_VFS_OP_CHDIR,     "chdir" },
599         { SMB_VFS_OP_GETWD,     "getwd" },
600         { SMB_VFS_OP_NTIMES,    "ntimes" },
601         { SMB_VFS_OP_FTRUNCATE, "ftruncate" },
602         { SMB_VFS_OP_LOCK,      "lock" },
603         { SMB_VFS_OP_KERNEL_FLOCK,      "kernel_flock" },
604         { SMB_VFS_OP_LINUX_SETLEASE, "linux_setlease" },
605         { SMB_VFS_OP_GETLOCK,   "getlock" },
606         { SMB_VFS_OP_SYMLINK,   "symlink" },
607         { SMB_VFS_OP_READLINK,  "readlink" },
608         { SMB_VFS_OP_LINK,      "link" },
609         { SMB_VFS_OP_MKNOD,     "mknod" },
610         { SMB_VFS_OP_REALPATH,  "realpath" },
611         { SMB_VFS_OP_NOTIFY_WATCH, "notify_watch" },
612         { SMB_VFS_OP_CHFLAGS,   "chflags" },
613         { SMB_VFS_OP_FILE_ID_CREATE,    "file_id_create" },
614         { SMB_VFS_OP_STREAMINFO,        "streaminfo" },
615         { SMB_VFS_OP_FGET_NT_ACL,       "fget_nt_acl" },
616         { SMB_VFS_OP_GET_NT_ACL,        "get_nt_acl" },
617         { SMB_VFS_OP_FSET_NT_ACL,       "fset_nt_acl" },
618         { SMB_VFS_OP_CHMOD_ACL, "chmod_acl" },
619         { SMB_VFS_OP_FCHMOD_ACL,        "fchmod_acl" },
620         { SMB_VFS_OP_SYS_ACL_GET_ENTRY, "sys_acl_get_entry" },
621         { SMB_VFS_OP_SYS_ACL_GET_TAG_TYPE,      "sys_acl_get_tag_type" },
622         { SMB_VFS_OP_SYS_ACL_GET_PERMSET,       "sys_acl_get_permset" },
623         { SMB_VFS_OP_SYS_ACL_GET_QUALIFIER,     "sys_acl_get_qualifier" },
624         { SMB_VFS_OP_SYS_ACL_GET_FILE,  "sys_acl_get_file" },
625         { SMB_VFS_OP_SYS_ACL_GET_FD,    "sys_acl_get_fd" },
626         { SMB_VFS_OP_SYS_ACL_CLEAR_PERMS,       "sys_acl_clear_perms" },
627         { SMB_VFS_OP_SYS_ACL_ADD_PERM,  "sys_acl_add_perm" },
628         { SMB_VFS_OP_SYS_ACL_TO_TEXT,   "sys_acl_to_text" },
629         { SMB_VFS_OP_SYS_ACL_INIT,      "sys_acl_init" },
630         { SMB_VFS_OP_SYS_ACL_CREATE_ENTRY,      "sys_acl_create_entry" },
631         { SMB_VFS_OP_SYS_ACL_SET_TAG_TYPE,      "sys_acl_set_tag_type" },
632         { SMB_VFS_OP_SYS_ACL_SET_QUALIFIER,     "sys_acl_set_qualifier" },
633         { SMB_VFS_OP_SYS_ACL_SET_PERMSET,       "sys_acl_set_permset" },
634         { SMB_VFS_OP_SYS_ACL_VALID,     "sys_acl_valid" },
635         { SMB_VFS_OP_SYS_ACL_SET_FILE,  "sys_acl_set_file" },
636         { SMB_VFS_OP_SYS_ACL_SET_FD,    "sys_acl_set_fd" },
637         { SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE,   "sys_acl_delete_def_file" },
638         { SMB_VFS_OP_SYS_ACL_GET_PERM,  "sys_acl_get_perm" },
639         { SMB_VFS_OP_SYS_ACL_FREE_TEXT, "sys_acl_free_text" },
640         { SMB_VFS_OP_SYS_ACL_FREE_ACL,  "sys_acl_free_acl" },
641         { SMB_VFS_OP_SYS_ACL_FREE_QUALIFIER,    "sys_acl_free_qualifier" },
642         { SMB_VFS_OP_GETXATTR,  "getxattr" },
643         { SMB_VFS_OP_LGETXATTR, "lgetxattr" },
644         { SMB_VFS_OP_FGETXATTR, "fgetxattr" },
645         { SMB_VFS_OP_LISTXATTR, "listxattr" },
646         { SMB_VFS_OP_LLISTXATTR,        "llistxattr" },
647         { SMB_VFS_OP_FLISTXATTR,        "flistxattr" },
648         { SMB_VFS_OP_REMOVEXATTR,       "removexattr" },
649         { SMB_VFS_OP_LREMOVEXATTR,      "lremovexattr" },
650         { SMB_VFS_OP_FREMOVEXATTR,      "fremovexattr" },
651         { SMB_VFS_OP_SETXATTR,  "setxattr" },
652         { SMB_VFS_OP_LSETXATTR, "lsetxattr" },
653         { SMB_VFS_OP_FSETXATTR, "fsetxattr" },
654         { SMB_VFS_OP_AIO_READ,  "aio_read" },
655         { SMB_VFS_OP_AIO_WRITE, "aio_write" },
656         { SMB_VFS_OP_AIO_RETURN,"aio_return" },
657         { SMB_VFS_OP_AIO_CANCEL,"aio_cancel" },
658         { SMB_VFS_OP_AIO_ERROR, "aio_error" },
659         { SMB_VFS_OP_AIO_FSYNC, "aio_fsync" },
660         { SMB_VFS_OP_AIO_SUSPEND,"aio_suspend" },
661         { SMB_VFS_OP_AIO_FORCE, "aio_force" },
662         { SMB_VFS_OP_IS_OFFLINE, "aio_is_offline" },
663         { SMB_VFS_OP_SET_OFFLINE, "aio_set_offline" },
664         { SMB_VFS_OP_LAST, NULL }
665 };      
666
667 static int audit_syslog_facility(vfs_handle_struct *handle)
668 {
669         static const struct enum_list enum_log_facilities[] = {
670                 { LOG_USER, "USER" },
671                 { LOG_LOCAL0, "LOCAL0" },
672                 { LOG_LOCAL1, "LOCAL1" },
673                 { LOG_LOCAL2, "LOCAL2" },
674                 { LOG_LOCAL3, "LOCAL3" },
675                 { LOG_LOCAL4, "LOCAL4" },
676                 { LOG_LOCAL5, "LOCAL5" },
677                 { LOG_LOCAL6, "LOCAL6" },
678                 { LOG_LOCAL7, "LOCAL7" }
679         };
680
681         int facility;
682
683         facility = lp_parm_enum(SNUM(handle->conn), "full_audit", "facility", enum_log_facilities, LOG_USER);
684
685         return facility;
686 }
687
688 static int audit_syslog_priority(vfs_handle_struct *handle)
689 {
690         static const struct enum_list enum_log_priorities[] = {
691                 { LOG_EMERG, "EMERG" },
692                 { LOG_ALERT, "ALERT" },
693                 { LOG_CRIT, "CRIT" },
694                 { LOG_ERR, "ERR" },
695                 { LOG_WARNING, "WARNING" },
696                 { LOG_NOTICE, "NOTICE" },
697                 { LOG_INFO, "INFO" },
698                 { LOG_DEBUG, "DEBUG" }
699         };
700
701         int priority;
702
703         priority = lp_parm_enum(SNUM(handle->conn), "full_audit", "priority",
704                                 enum_log_priorities, LOG_NOTICE);
705         if (priority == -1) {
706                 priority = LOG_WARNING;
707         }
708
709         return priority;
710 }
711
712 static char *audit_prefix(TALLOC_CTX *ctx, connection_struct *conn)
713 {
714         char *prefix = NULL;
715
716         prefix = talloc_strdup(ctx,
717                         lp_parm_const_string(SNUM(conn), "full_audit",
718                                              "prefix", "%u|%I"));
719         if (!prefix) {
720                 return NULL;
721         }
722         return talloc_sub_advanced(ctx,
723                         lp_servicename(SNUM(conn)),
724                         conn->server_info->unix_name,
725                         conn->connectpath,
726                         conn->server_info->utok.gid,
727                         conn->server_info->sanitized_username,
728                         pdb_get_domain(conn->server_info->sam_account),
729                         prefix);
730 }
731
732 static bool log_success(vfs_handle_struct *handle, vfs_op_type op)
733 {
734         struct vfs_full_audit_private_data *pd = NULL;
735
736         SMB_VFS_HANDLE_GET_DATA(handle, pd,
737                 struct vfs_full_audit_private_data,
738                 return True);
739
740         if (pd->success_ops == NULL) {
741                 return True;
742         }
743
744         return bitmap_query(pd->success_ops, op);
745 }
746
747 static bool log_failure(vfs_handle_struct *handle, vfs_op_type op)
748 {
749         struct vfs_full_audit_private_data *pd = NULL;
750
751         SMB_VFS_HANDLE_GET_DATA(handle, pd,
752                 struct vfs_full_audit_private_data,
753                 return True);
754
755         if (pd->failure_ops == NULL)
756                 return True;
757
758         return bitmap_query(pd->failure_ops, op);
759 }
760
761 static void init_bitmap(struct bitmap **bm, const char **ops)
762 {
763         bool log_all = False;
764
765         if (*bm != NULL)
766                 return;
767
768         *bm = bitmap_allocate(SMB_VFS_OP_LAST);
769
770         if (*bm == NULL) {
771                 DEBUG(0, ("Could not alloc bitmap -- "
772                           "defaulting to logging everything\n"));
773                 return;
774         }
775
776         while (*ops != NULL) {
777                 int i;
778                 bool found = False;
779
780                 if (strequal(*ops, "all")) {
781                         log_all = True;
782                         break;
783                 }
784
785                 if (strequal(*ops, "none")) {
786                         break;
787                 }
788
789                 for (i=0; i<SMB_VFS_OP_LAST; i++) {
790                         if (vfs_op_names[i].name == NULL) {
791                                 smb_panic("vfs_full_audit.c: name table not "
792                                           "in sync with vfs.h\n");
793                         }
794
795                         if (strequal(*ops, vfs_op_names[i].name)) {
796                                 bitmap_set(*bm, i);
797                                 found = True;
798                         }
799                 }
800                 if (!found) {
801                         DEBUG(0, ("Could not find opname %s, logging all\n",
802                                   *ops));
803                         log_all = True;
804                         break;
805                 }
806                 ops += 1;
807         }
808
809         if (log_all) {
810                 /* The query functions default to True */
811                 bitmap_free(*bm);
812                 *bm = NULL;
813         }
814 }
815
816 static const char *audit_opname(vfs_op_type op)
817 {
818         if (op >= SMB_VFS_OP_LAST)
819                 return "INVALID VFS OP";
820         return vfs_op_names[op].name;
821 }
822
823 static void do_log(vfs_op_type op, bool success, vfs_handle_struct *handle,
824                    const char *format, ...)
825 {
826         fstring err_msg;
827         char *audit_pre = NULL;
828         va_list ap;
829         char *op_msg = NULL;
830
831         if (success && (!log_success(handle, op)))
832                 return;
833
834         if (!success && (!log_failure(handle, op)))
835                 return;
836
837         if (success)
838                 fstrcpy(err_msg, "ok");
839         else
840                 fstr_sprintf(err_msg, "fail (%s)", strerror(errno));
841
842         va_start(ap, format);
843         op_msg = talloc_vasprintf(NULL, format, ap);
844         va_end(ap);
845
846         if (!op_msg) {
847                 return;
848         }
849
850         audit_pre = audit_prefix(NULL, handle->conn);
851         syslog(audit_syslog_priority(handle), "%s|%s|%s|%s\n",
852                 audit_pre ? audit_pre : "",
853                 audit_opname(op), err_msg, op_msg);
854
855         TALLOC_FREE(audit_pre);
856         TALLOC_FREE(op_msg);
857
858         return;
859 }
860
861 /* Free function for the private data. */
862
863 static void free_private_data(void **p_data)
864 {
865         struct vfs_full_audit_private_data *pd = *(struct vfs_full_audit_private_data **)p_data;
866
867         if (pd->success_ops) {
868                 bitmap_free(pd->success_ops);
869         }
870         if (pd->failure_ops) {
871                 bitmap_free(pd->failure_ops);
872         }
873         SAFE_FREE(pd);
874         *p_data = NULL;
875 }
876
877 /* Implementation of vfs_ops.  Pass everything on to the default
878    operation but log event first. */
879
880 static int smb_full_audit_connect(vfs_handle_struct *handle,
881                          const char *svc, const char *user)
882 {
883         int result;
884         struct vfs_full_audit_private_data *pd = NULL;
885         const char *none[] = { NULL };
886         const char *all [] = { "all" };
887
888         if (!handle) {
889                 return -1;
890         }
891
892         pd = SMB_MALLOC_P(struct vfs_full_audit_private_data);
893         if (!pd) {
894                 return -1;
895         }
896         ZERO_STRUCTP(pd);
897
898         openlog("smbd_audit", 0, audit_syslog_facility(handle));
899
900         init_bitmap(&pd->success_ops,
901                     lp_parm_string_list(SNUM(handle->conn), "full_audit", "success",
902                                         none));
903         init_bitmap(&pd->failure_ops,
904                     lp_parm_string_list(SNUM(handle->conn), "full_audit", "failure",
905                                         all));
906
907         /* Store the private data. */
908         SMB_VFS_HANDLE_SET_DATA(handle, pd, free_private_data,
909                                 struct vfs_full_audit_private_data, return -1);
910
911         result = SMB_VFS_NEXT_CONNECT(handle, svc, user);
912
913         do_log(SMB_VFS_OP_CONNECT, True, handle,
914                "%s", svc);
915
916         return result;
917 }
918
919 static void smb_full_audit_disconnect(vfs_handle_struct *handle)
920 {
921         SMB_VFS_NEXT_DISCONNECT(handle);
922
923         do_log(SMB_VFS_OP_DISCONNECT, True, handle,
924                "%s", lp_servicename(SNUM(handle->conn)));
925
926         /* The bitmaps will be disconnected when the private
927            data is deleted. */
928
929         return;
930 }
931
932 static uint64_t smb_full_audit_disk_free(vfs_handle_struct *handle,
933                                     const char *path,
934                                     bool small_query, uint64_t *bsize, 
935                                     uint64_t *dfree, uint64_t *dsize)
936 {
937         uint64_t result;
938
939         result = SMB_VFS_NEXT_DISK_FREE(handle, path, small_query, bsize,
940                                         dfree, dsize);
941
942         /* Don't have a reasonable notion of failure here */
943
944         do_log(SMB_VFS_OP_DISK_FREE, True, handle, "%s", path);
945
946         return result;
947 }
948
949 static int smb_full_audit_get_quota(struct vfs_handle_struct *handle,
950                            enum SMB_QUOTA_TYPE qtype, unid_t id,
951                            SMB_DISK_QUOTA *qt)
952 {
953         int result;
954
955         result = SMB_VFS_NEXT_GET_QUOTA(handle, qtype, id, qt);
956
957         do_log(SMB_VFS_OP_GET_QUOTA, (result >= 0), handle, "");
958
959         return result;
960 }
961
962         
963 static int smb_full_audit_set_quota(struct vfs_handle_struct *handle,
964                            enum SMB_QUOTA_TYPE qtype, unid_t id,
965                            SMB_DISK_QUOTA *qt)
966 {
967         int result;
968
969         result = SMB_VFS_NEXT_SET_QUOTA(handle, qtype, id, qt);
970
971         do_log(SMB_VFS_OP_SET_QUOTA, (result >= 0), handle, "");
972
973         return result;
974 }
975
976 static int smb_full_audit_get_shadow_copy_data(struct vfs_handle_struct *handle,
977                                 struct files_struct *fsp,
978                                 SHADOW_COPY_DATA *shadow_copy_data, bool labels)
979 {
980         int result;
981
982         result = SMB_VFS_NEXT_GET_SHADOW_COPY_DATA(handle, fsp, shadow_copy_data, labels);
983
984         do_log(SMB_VFS_OP_GET_SHADOW_COPY_DATA, (result >= 0), handle, "");
985
986         return result;
987 }
988
989 static int smb_full_audit_statvfs(struct vfs_handle_struct *handle,
990                                 const char *path,
991                                 struct vfs_statvfs_struct *statbuf)
992 {
993         int result;
994
995         result = SMB_VFS_NEXT_STATVFS(handle, path, statbuf);
996
997         do_log(SMB_VFS_OP_STATVFS, (result >= 0), handle, "");
998
999         return result;
1000 }
1001
1002 static SMB_STRUCT_DIR *smb_full_audit_opendir(vfs_handle_struct *handle,
1003                           const char *fname, const char *mask, uint32 attr)
1004 {
1005         SMB_STRUCT_DIR *result;
1006
1007         result = SMB_VFS_NEXT_OPENDIR(handle, fname, mask, attr);
1008
1009         do_log(SMB_VFS_OP_OPENDIR, (result != NULL), handle, "%s", fname);
1010
1011         return result;
1012 }
1013
1014 static SMB_STRUCT_DIRENT *smb_full_audit_readdir(vfs_handle_struct *handle,
1015                                     SMB_STRUCT_DIR *dirp)
1016 {
1017         SMB_STRUCT_DIRENT *result;
1018
1019         result = SMB_VFS_NEXT_READDIR(handle, dirp);
1020
1021         /* This operation has no reasonable error condition
1022          * (End of dir is also failure), so always succeed.
1023          */
1024         do_log(SMB_VFS_OP_READDIR, True, handle, "");
1025
1026         return result;
1027 }
1028
1029 static void smb_full_audit_seekdir(vfs_handle_struct *handle,
1030                         SMB_STRUCT_DIR *dirp, long offset)
1031 {
1032         SMB_VFS_NEXT_SEEKDIR(handle, dirp, offset);
1033
1034         do_log(SMB_VFS_OP_SEEKDIR, True, handle, "");
1035         return;
1036 }
1037
1038 static long smb_full_audit_telldir(vfs_handle_struct *handle,
1039                         SMB_STRUCT_DIR *dirp)
1040 {
1041         long result;
1042
1043         result = SMB_VFS_NEXT_TELLDIR(handle, dirp);
1044
1045         do_log(SMB_VFS_OP_TELLDIR, True, handle, "");
1046
1047         return result;
1048 }
1049
1050 static void smb_full_audit_rewinddir(vfs_handle_struct *handle,
1051                         SMB_STRUCT_DIR *dirp)
1052 {
1053         SMB_VFS_NEXT_REWINDDIR(handle, dirp);
1054
1055         do_log(SMB_VFS_OP_REWINDDIR, True, handle, "");
1056         return;
1057 }
1058
1059 static int smb_full_audit_mkdir(vfs_handle_struct *handle,
1060                        const char *path, mode_t mode)
1061 {
1062         int result;
1063         
1064         result = SMB_VFS_NEXT_MKDIR(handle, path, mode);
1065         
1066         do_log(SMB_VFS_OP_MKDIR, (result >= 0), handle, "%s", path);
1067
1068         return result;
1069 }
1070
1071 static int smb_full_audit_rmdir(vfs_handle_struct *handle,
1072                        const char *path)
1073 {
1074         int result;
1075         
1076         result = SMB_VFS_NEXT_RMDIR(handle, path);
1077
1078         do_log(SMB_VFS_OP_RMDIR, (result >= 0), handle, "%s", path);
1079
1080         return result;
1081 }
1082
1083 static int smb_full_audit_closedir(vfs_handle_struct *handle,
1084                           SMB_STRUCT_DIR *dirp)
1085 {
1086         int result;
1087
1088         result = SMB_VFS_NEXT_CLOSEDIR(handle, dirp);
1089         
1090         do_log(SMB_VFS_OP_CLOSEDIR, (result >= 0), handle, "");
1091
1092         return result;
1093 }
1094
1095 static int smb_full_audit_open(vfs_handle_struct *handle,
1096                       const char *fname, files_struct *fsp, int flags, mode_t mode)
1097 {
1098         int result;
1099         
1100         result = SMB_VFS_NEXT_OPEN(handle, fname, fsp, flags, mode);
1101
1102         do_log(SMB_VFS_OP_OPEN, (result >= 0), handle, "%s|%s",
1103                ((flags & O_WRONLY) || (flags & O_RDWR))?"w":"r",
1104                fname);
1105
1106         return result;
1107 }
1108
1109 static NTSTATUS smb_full_audit_create_file(vfs_handle_struct *handle,
1110                                       struct smb_request *req,
1111                                       uint16_t root_dir_fid,
1112                                       const char *fname,
1113                                       bool is_dos_path,
1114                                       uint32_t access_mask,
1115                                       uint32_t share_access,
1116                                       uint32_t create_disposition,
1117                                       uint32_t create_options,
1118                                       uint32_t file_attributes,
1119                                       uint32_t oplock_request,
1120                                       uint64_t allocation_size,
1121                                       struct security_descriptor *sd,
1122                                       struct ea_list *ea_list,
1123                                       files_struct **result_fsp,
1124                                       int *pinfo,
1125                                       SMB_STRUCT_STAT *psbuf)
1126 {
1127         NTSTATUS result;
1128
1129         result = SMB_VFS_NEXT_CREATE_FILE(
1130                 handle,                                 /* handle */
1131                 req,                                    /* req */
1132                 root_dir_fid,                           /* root_dir_fid */
1133                 fname,                                  /* fname */
1134                 is_dos_path,                            /* is_dos_path */
1135                 access_mask,                            /* access_mask */
1136                 share_access,                           /* share_access */
1137                 create_disposition,                     /* create_disposition*/
1138                 create_options,                         /* create_options */
1139                 file_attributes,                        /* file_attributes */
1140                 oplock_request,                         /* oplock_request */
1141                 allocation_size,                        /* allocation_size */
1142                 sd,                                     /* sd */
1143                 ea_list,                                /* ea_list */
1144                 result_fsp,                             /* result */
1145                 pinfo,                                  /* pinfo */
1146                 psbuf);                                 /* psbuf */
1147
1148         do_log(SMB_VFS_OP_CREATE_FILE, (NT_STATUS_IS_OK(result)), handle, "0x%x|%s",
1149                access_mask, fname);
1150
1151         return result;
1152 }
1153
1154 static int smb_full_audit_close(vfs_handle_struct *handle, files_struct *fsp)
1155 {
1156         int result;
1157         
1158         result = SMB_VFS_NEXT_CLOSE(handle, fsp);
1159
1160         do_log(SMB_VFS_OP_CLOSE, (result >= 0), handle, "%s", fsp->fsp_name);
1161
1162         return result;
1163 }
1164
1165 static ssize_t smb_full_audit_read(vfs_handle_struct *handle, files_struct *fsp,
1166                           void *data, size_t n)
1167 {
1168         ssize_t result;
1169
1170         result = SMB_VFS_NEXT_READ(handle, fsp, data, n);
1171
1172         do_log(SMB_VFS_OP_READ, (result >= 0), handle, "%s", fsp->fsp_name);
1173
1174         return result;
1175 }
1176
1177 static ssize_t smb_full_audit_pread(vfs_handle_struct *handle, files_struct *fsp,
1178                            void *data, size_t n, SMB_OFF_T offset)
1179 {
1180         ssize_t result;
1181
1182         result = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
1183
1184         do_log(SMB_VFS_OP_PREAD, (result >= 0), handle, "%s", fsp->fsp_name);
1185
1186         return result;
1187 }
1188
1189 static ssize_t smb_full_audit_write(vfs_handle_struct *handle, files_struct *fsp,
1190                            const void *data, size_t n)
1191 {
1192         ssize_t result;
1193
1194         result = SMB_VFS_NEXT_WRITE(handle, fsp, data, n);
1195
1196         do_log(SMB_VFS_OP_WRITE, (result >= 0), handle, "%s", fsp->fsp_name);
1197
1198         return result;
1199 }
1200
1201 static ssize_t smb_full_audit_pwrite(vfs_handle_struct *handle, files_struct *fsp,
1202                             const void *data, size_t n,
1203                             SMB_OFF_T offset)
1204 {
1205         ssize_t result;
1206
1207         result = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
1208
1209         do_log(SMB_VFS_OP_PWRITE, (result >= 0), handle, "%s", fsp->fsp_name);
1210
1211         return result;
1212 }
1213
1214 static SMB_OFF_T smb_full_audit_lseek(vfs_handle_struct *handle, files_struct *fsp,
1215                              SMB_OFF_T offset, int whence)
1216 {
1217         ssize_t result;
1218
1219         result = SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence);
1220
1221         do_log(SMB_VFS_OP_LSEEK, (result != (ssize_t)-1), handle,
1222                "%s", fsp->fsp_name);
1223
1224         return result;
1225 }
1226
1227 static ssize_t smb_full_audit_sendfile(vfs_handle_struct *handle, int tofd,
1228                               files_struct *fromfsp,
1229                               const DATA_BLOB *hdr, SMB_OFF_T offset,
1230                               size_t n)
1231 {
1232         ssize_t result;
1233
1234         result = SMB_VFS_NEXT_SENDFILE(handle, tofd, fromfsp, hdr, offset, n);
1235
1236         do_log(SMB_VFS_OP_SENDFILE, (result >= 0), handle,
1237                "%s", fromfsp->fsp_name);
1238
1239         return result;
1240 }
1241
1242 static ssize_t smb_full_audit_recvfile(vfs_handle_struct *handle, int fromfd,
1243                       files_struct *tofsp,
1244                               SMB_OFF_T offset,
1245                               size_t n)
1246 {
1247         ssize_t result;
1248
1249         result = SMB_VFS_NEXT_RECVFILE(handle, fromfd, tofsp, offset, n);
1250
1251         do_log(SMB_VFS_OP_RECVFILE, (result >= 0), handle,
1252                "%s", tofsp->fsp_name);
1253
1254         return result;
1255 }
1256
1257 static int smb_full_audit_rename(vfs_handle_struct *handle,
1258                         const char *oldname, const char *newname)
1259 {
1260         int result;
1261         
1262         result = SMB_VFS_NEXT_RENAME(handle, oldname, newname);
1263
1264         do_log(SMB_VFS_OP_RENAME, (result >= 0), handle, "%s|%s", oldname, newname);
1265
1266         return result;    
1267 }
1268
1269 static int smb_full_audit_fsync(vfs_handle_struct *handle, files_struct *fsp)
1270 {
1271         int result;
1272         
1273         result = SMB_VFS_NEXT_FSYNC(handle, fsp);
1274
1275         do_log(SMB_VFS_OP_FSYNC, (result >= 0), handle, "%s", fsp->fsp_name);
1276
1277         return result;    
1278 }
1279
1280 static int smb_full_audit_stat(vfs_handle_struct *handle,
1281                       const char *fname, SMB_STRUCT_STAT *sbuf)
1282 {
1283         int result;
1284         
1285         result = SMB_VFS_NEXT_STAT(handle, fname, sbuf);
1286
1287         do_log(SMB_VFS_OP_STAT, (result >= 0), handle, "%s", fname);
1288
1289         return result;    
1290 }
1291
1292 static int smb_full_audit_fstat(vfs_handle_struct *handle, files_struct *fsp,
1293                        SMB_STRUCT_STAT *sbuf)
1294 {
1295         int result;
1296         
1297         result = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1298
1299         do_log(SMB_VFS_OP_FSTAT, (result >= 0), handle, "%s", fsp->fsp_name);
1300
1301         return result;
1302 }
1303
1304 static int smb_full_audit_lstat(vfs_handle_struct *handle,
1305                        const char *path, SMB_STRUCT_STAT *sbuf)
1306 {
1307         int result;
1308         
1309         result = SMB_VFS_NEXT_LSTAT(handle, path, sbuf);
1310
1311         do_log(SMB_VFS_OP_LSTAT, (result >= 0), handle, "%s", path);
1312
1313         return result;    
1314 }
1315
1316 static int smb_full_audit_unlink(vfs_handle_struct *handle,
1317                         const char *path)
1318 {
1319         int result;
1320         
1321         result = SMB_VFS_NEXT_UNLINK(handle, path);
1322
1323         do_log(SMB_VFS_OP_UNLINK, (result >= 0), handle, "%s", path);
1324
1325         return result;
1326 }
1327
1328 static int smb_full_audit_chmod(vfs_handle_struct *handle,
1329                        const char *path, mode_t mode)
1330 {
1331         int result;
1332
1333         result = SMB_VFS_NEXT_CHMOD(handle, path, mode);
1334
1335         do_log(SMB_VFS_OP_CHMOD, (result >= 0), handle, "%s|%o", path, mode);
1336
1337         return result;
1338 }
1339
1340 static int smb_full_audit_fchmod(vfs_handle_struct *handle, files_struct *fsp,
1341                         mode_t mode)
1342 {
1343         int result;
1344         
1345         result = SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1346
1347         do_log(SMB_VFS_OP_FCHMOD, (result >= 0), handle,
1348                "%s|%o", fsp->fsp_name, mode);
1349
1350         return result;
1351 }
1352
1353 static int smb_full_audit_chown(vfs_handle_struct *handle,
1354                        const char *path, uid_t uid, gid_t gid)
1355 {
1356         int result;
1357
1358         result = SMB_VFS_NEXT_CHOWN(handle, path, uid, gid);
1359
1360         do_log(SMB_VFS_OP_CHOWN, (result >= 0), handle, "%s|%ld|%ld",
1361                path, (long int)uid, (long int)gid);
1362
1363         return result;
1364 }
1365
1366 static int smb_full_audit_fchown(vfs_handle_struct *handle, files_struct *fsp,
1367                         uid_t uid, gid_t gid)
1368 {
1369         int result;
1370
1371         result = SMB_VFS_NEXT_FCHOWN(handle, fsp, uid, gid);
1372
1373         do_log(SMB_VFS_OP_FCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1374                fsp->fsp_name, (long int)uid, (long int)gid);
1375
1376         return result;
1377 }
1378
1379 static int smb_full_audit_lchown(vfs_handle_struct *handle,
1380                        const char *path, uid_t uid, gid_t gid)
1381 {
1382         int result;
1383
1384         result = SMB_VFS_NEXT_LCHOWN(handle, path, uid, gid);
1385
1386         do_log(SMB_VFS_OP_LCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1387                path, (long int)uid, (long int)gid);
1388
1389         return result;
1390 }
1391
1392 static int smb_full_audit_chdir(vfs_handle_struct *handle,
1393                        const char *path)
1394 {
1395         int result;
1396
1397         result = SMB_VFS_NEXT_CHDIR(handle, path);
1398
1399         do_log(SMB_VFS_OP_CHDIR, (result >= 0), handle, "chdir|%s", path);
1400
1401         return result;
1402 }
1403
1404 static char *smb_full_audit_getwd(vfs_handle_struct *handle,
1405                          char *path)
1406 {
1407         char *result;
1408
1409         result = SMB_VFS_NEXT_GETWD(handle, path);
1410         
1411         do_log(SMB_VFS_OP_GETWD, (result != NULL), handle, "%s", path);
1412
1413         return result;
1414 }
1415
1416 static int smb_full_audit_ntimes(vfs_handle_struct *handle,
1417                        const char *path, const struct timespec ts[2])
1418 {
1419         int result;
1420
1421         result = SMB_VFS_NEXT_NTIMES(handle, path, ts);
1422
1423         do_log(SMB_VFS_OP_NTIMES, (result >= 0), handle, "%s", path);
1424
1425         return result;
1426 }
1427
1428 static int smb_full_audit_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
1429                            SMB_OFF_T len)
1430 {
1431         int result;
1432
1433         result = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1434
1435         do_log(SMB_VFS_OP_FTRUNCATE, (result >= 0), handle,
1436                "%s", fsp->fsp_name);
1437
1438         return result;
1439 }
1440
1441 static bool smb_full_audit_lock(vfs_handle_struct *handle, files_struct *fsp,
1442                        int op, SMB_OFF_T offset, SMB_OFF_T count, int type)
1443 {
1444         bool result;
1445
1446         result = SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type);
1447
1448         do_log(SMB_VFS_OP_LOCK, result, handle, "%s", fsp->fsp_name);
1449
1450         return result;
1451 }
1452
1453 static int smb_full_audit_kernel_flock(struct vfs_handle_struct *handle,
1454                                        struct files_struct *fsp,
1455                                        uint32 share_mode)
1456 {
1457         int result;
1458
1459         result = SMB_VFS_NEXT_KERNEL_FLOCK(handle, fsp, share_mode);
1460
1461         do_log(SMB_VFS_OP_KERNEL_FLOCK, (result >= 0), handle, "%s",
1462                fsp->fsp_name);
1463
1464         return result;
1465 }
1466
1467 static int smb_full_audit_linux_setlease(vfs_handle_struct *handle, files_struct *fsp,
1468                                  int leasetype)
1469 {
1470         int result;
1471
1472         result = SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
1473
1474         do_log(SMB_VFS_OP_LINUX_SETLEASE, (result >= 0), handle, "%s",
1475                fsp->fsp_name);
1476
1477         return result;
1478 }
1479
1480 static bool smb_full_audit_getlock(vfs_handle_struct *handle, files_struct *fsp,
1481                        SMB_OFF_T *poffset, SMB_OFF_T *pcount, int *ptype, pid_t *ppid)
1482 {
1483         bool result;
1484
1485         result = SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype, ppid);
1486
1487         do_log(SMB_VFS_OP_GETLOCK, result, handle, "%s", fsp->fsp_name);
1488
1489         return result;
1490 }
1491
1492 static int smb_full_audit_symlink(vfs_handle_struct *handle,
1493                          const char *oldpath, const char *newpath)
1494 {
1495         int result;
1496
1497         result = SMB_VFS_NEXT_SYMLINK(handle, oldpath, newpath);
1498
1499         do_log(SMB_VFS_OP_SYMLINK, (result >= 0), handle,
1500                "%s|%s", oldpath, newpath);
1501
1502         return result;
1503 }
1504
1505 static int smb_full_audit_readlink(vfs_handle_struct *handle,
1506                           const char *path, char *buf, size_t bufsiz)
1507 {
1508         int result;
1509
1510         result = SMB_VFS_NEXT_READLINK(handle, path, buf, bufsiz);
1511
1512         do_log(SMB_VFS_OP_READLINK, (result >= 0), handle, "%s", path);
1513
1514         return result;
1515 }
1516
1517 static int smb_full_audit_link(vfs_handle_struct *handle,
1518                       const char *oldpath, const char *newpath)
1519 {
1520         int result;
1521
1522         result = SMB_VFS_NEXT_LINK(handle, oldpath, newpath);
1523
1524         do_log(SMB_VFS_OP_LINK, (result >= 0), handle,
1525                "%s|%s", oldpath, newpath);
1526
1527         return result;
1528 }
1529
1530 static int smb_full_audit_mknod(vfs_handle_struct *handle,
1531                        const char *pathname, mode_t mode, SMB_DEV_T dev)
1532 {
1533         int result;
1534
1535         result = SMB_VFS_NEXT_MKNOD(handle, pathname, mode, dev);
1536
1537         do_log(SMB_VFS_OP_MKNOD, (result >= 0), handle, "%s", pathname);
1538
1539         return result;
1540 }
1541
1542 static char *smb_full_audit_realpath(vfs_handle_struct *handle,
1543                             const char *path, char *resolved_path)
1544 {
1545         char *result;
1546
1547         result = SMB_VFS_NEXT_REALPATH(handle, path, resolved_path);
1548
1549         do_log(SMB_VFS_OP_REALPATH, (result != NULL), handle, "%s", path);
1550
1551         return result;
1552 }
1553
1554 static NTSTATUS smb_full_audit_notify_watch(struct vfs_handle_struct *handle,
1555                         struct sys_notify_context *ctx,
1556                         struct notify_entry *e,
1557                         void (*callback)(struct sys_notify_context *ctx,
1558                                         void *private_data,
1559                                         struct notify_event *ev),
1560                         void *private_data, void *handle_p)
1561 {
1562         NTSTATUS result;
1563
1564         result = SMB_VFS_NEXT_NOTIFY_WATCH(handle, ctx, e, callback, private_data, handle_p);
1565
1566         do_log(SMB_VFS_OP_NOTIFY_WATCH, NT_STATUS_IS_OK(result), handle, "");
1567
1568         return result;
1569 }
1570
1571 static int smb_full_audit_chflags(vfs_handle_struct *handle,
1572                             const char *path, unsigned int flags)
1573 {
1574         int result;
1575
1576         result = SMB_VFS_NEXT_CHFLAGS(handle, path, flags);
1577
1578         do_log(SMB_VFS_OP_CHFLAGS, (result != 0), handle, "%s", path);
1579
1580         return result;
1581 }
1582
1583 static struct file_id smb_full_audit_file_id_create(struct vfs_handle_struct *handle,
1584                                                     SMB_DEV_T dev, SMB_INO_T inode)
1585 {
1586         struct file_id id_zero;
1587         struct file_id result;
1588
1589         ZERO_STRUCT(id_zero);
1590
1591         result = SMB_VFS_NEXT_FILE_ID_CREATE(handle, dev, inode);
1592
1593         do_log(SMB_VFS_OP_FILE_ID_CREATE,
1594                !file_id_equal(&id_zero, &result),
1595                handle, "%s", file_id_string_tos(&result));
1596
1597         return result;
1598 }
1599
1600 static NTSTATUS smb_full_audit_streaminfo(vfs_handle_struct *handle,
1601                                           struct files_struct *fsp,
1602                                           const char *fname,
1603                                           TALLOC_CTX *mem_ctx,
1604                                           unsigned int *pnum_streams,
1605                                           struct stream_struct **pstreams)
1606 {
1607         NTSTATUS result;
1608
1609         result = SMB_VFS_NEXT_STREAMINFO(handle, fsp, fname, mem_ctx,
1610                                          pnum_streams, pstreams);
1611
1612         do_log(SMB_VFS_OP_STREAMINFO, NT_STATUS_IS_OK(result), handle,
1613                "%s", fname);
1614
1615         return result;
1616 }
1617
1618 static NTSTATUS smb_full_audit_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
1619                                 uint32 security_info,
1620                                 SEC_DESC **ppdesc)
1621 {
1622         NTSTATUS result;
1623
1624         result = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info, ppdesc);
1625
1626         do_log(SMB_VFS_OP_FGET_NT_ACL, NT_STATUS_IS_OK(result), handle,
1627                "%s", fsp->fsp_name);
1628
1629         return result;
1630 }
1631
1632 static NTSTATUS smb_full_audit_get_nt_acl(vfs_handle_struct *handle,
1633                                           const char *name,
1634                                           uint32 security_info,
1635                                           SEC_DESC **ppdesc)
1636 {
1637         NTSTATUS result;
1638
1639         result = SMB_VFS_NEXT_GET_NT_ACL(handle, name, security_info, ppdesc);
1640
1641         do_log(SMB_VFS_OP_GET_NT_ACL, NT_STATUS_IS_OK(result), handle,
1642                "%s", name);
1643
1644         return result;
1645 }
1646
1647 static NTSTATUS smb_full_audit_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
1648                               uint32 security_info_sent,
1649                               const SEC_DESC *psd)
1650 {
1651         NTSTATUS result;
1652
1653         result = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
1654
1655         do_log(SMB_VFS_OP_FSET_NT_ACL, NT_STATUS_IS_OK(result), handle, "%s", fsp->fsp_name);
1656
1657         return result;
1658 }
1659
1660 static int smb_full_audit_chmod_acl(vfs_handle_struct *handle,
1661                            const char *path, mode_t mode)
1662 {
1663         int result;
1664         
1665         result = SMB_VFS_NEXT_CHMOD_ACL(handle, path, mode);
1666
1667         do_log(SMB_VFS_OP_CHMOD_ACL, (result >= 0), handle,
1668                "%s|%o", path, mode);
1669
1670         return result;
1671 }
1672
1673 static int smb_full_audit_fchmod_acl(vfs_handle_struct *handle, files_struct *fsp,
1674                                      mode_t mode)
1675 {
1676         int result;
1677         
1678         result = SMB_VFS_NEXT_FCHMOD_ACL(handle, fsp, mode);
1679
1680         do_log(SMB_VFS_OP_FCHMOD_ACL, (result >= 0), handle,
1681                "%s|%o", fsp->fsp_name, mode);
1682
1683         return result;
1684 }
1685
1686 static int smb_full_audit_sys_acl_get_entry(vfs_handle_struct *handle,
1687
1688                                    SMB_ACL_T theacl, int entry_id,
1689                                    SMB_ACL_ENTRY_T *entry_p)
1690 {
1691         int result;
1692
1693         result = SMB_VFS_NEXT_SYS_ACL_GET_ENTRY(handle, theacl, entry_id,
1694                                                 entry_p);
1695
1696         do_log(SMB_VFS_OP_SYS_ACL_GET_ENTRY, (result >= 0), handle,
1697                "");
1698
1699         return result;
1700 }
1701
1702 static int smb_full_audit_sys_acl_get_tag_type(vfs_handle_struct *handle,
1703
1704                                       SMB_ACL_ENTRY_T entry_d,
1705                                       SMB_ACL_TAG_T *tag_type_p)
1706 {
1707         int result;
1708
1709         result = SMB_VFS_NEXT_SYS_ACL_GET_TAG_TYPE(handle, entry_d,
1710                                                    tag_type_p);
1711
1712         do_log(SMB_VFS_OP_SYS_ACL_GET_TAG_TYPE, (result >= 0), handle,
1713                "");
1714
1715         return result;
1716 }
1717
1718 static int smb_full_audit_sys_acl_get_permset(vfs_handle_struct *handle,
1719
1720                                      SMB_ACL_ENTRY_T entry_d,
1721                                      SMB_ACL_PERMSET_T *permset_p)
1722 {
1723         int result;
1724
1725         result = SMB_VFS_NEXT_SYS_ACL_GET_PERMSET(handle, entry_d,
1726                                                   permset_p);
1727
1728         do_log(SMB_VFS_OP_SYS_ACL_GET_PERMSET, (result >= 0), handle,
1729                "");
1730
1731         return result;
1732 }
1733
1734 static void * smb_full_audit_sys_acl_get_qualifier(vfs_handle_struct *handle,
1735
1736                                           SMB_ACL_ENTRY_T entry_d)
1737 {
1738         void *result;
1739
1740         result = SMB_VFS_NEXT_SYS_ACL_GET_QUALIFIER(handle, entry_d);
1741
1742         do_log(SMB_VFS_OP_SYS_ACL_GET_QUALIFIER, (result != NULL), handle,
1743                "");
1744
1745         return result;
1746 }
1747
1748 static SMB_ACL_T smb_full_audit_sys_acl_get_file(vfs_handle_struct *handle,
1749                                         const char *path_p,
1750                                         SMB_ACL_TYPE_T type)
1751 {
1752         SMB_ACL_T result;
1753
1754         result = SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, path_p, type);
1755
1756         do_log(SMB_VFS_OP_SYS_ACL_GET_FILE, (result != NULL), handle,
1757                "%s", path_p);
1758
1759         return result;
1760 }
1761
1762 static SMB_ACL_T smb_full_audit_sys_acl_get_fd(vfs_handle_struct *handle,
1763                                       files_struct *fsp)
1764 {
1765         SMB_ACL_T result;
1766
1767         result = SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp);
1768
1769         do_log(SMB_VFS_OP_SYS_ACL_GET_FD, (result != NULL), handle,
1770                "%s", fsp->fsp_name);
1771
1772         return result;
1773 }
1774
1775 static int smb_full_audit_sys_acl_clear_perms(vfs_handle_struct *handle,
1776
1777                                      SMB_ACL_PERMSET_T permset)
1778 {
1779         int result;
1780
1781         result = SMB_VFS_NEXT_SYS_ACL_CLEAR_PERMS(handle, permset);
1782
1783         do_log(SMB_VFS_OP_SYS_ACL_CLEAR_PERMS, (result >= 0), handle,
1784                "");
1785
1786         return result;
1787 }
1788
1789 static int smb_full_audit_sys_acl_add_perm(vfs_handle_struct *handle,
1790
1791                                   SMB_ACL_PERMSET_T permset,
1792                                   SMB_ACL_PERM_T perm)
1793 {
1794         int result;
1795
1796         result = SMB_VFS_NEXT_SYS_ACL_ADD_PERM(handle, permset, perm);
1797
1798         do_log(SMB_VFS_OP_SYS_ACL_ADD_PERM, (result >= 0), handle,
1799                "");
1800
1801         return result;
1802 }
1803
1804 static char * smb_full_audit_sys_acl_to_text(vfs_handle_struct *handle,
1805                                     SMB_ACL_T theacl,
1806                                     ssize_t *plen)
1807 {
1808         char * result;
1809
1810         result = SMB_VFS_NEXT_SYS_ACL_TO_TEXT(handle, theacl, plen);
1811
1812         do_log(SMB_VFS_OP_SYS_ACL_TO_TEXT, (result != NULL), handle,
1813                "");
1814
1815         return result;
1816 }
1817
1818 static SMB_ACL_T smb_full_audit_sys_acl_init(vfs_handle_struct *handle,
1819
1820                                     int count)
1821 {
1822         SMB_ACL_T result;
1823
1824         result = SMB_VFS_NEXT_SYS_ACL_INIT(handle, count);
1825
1826         do_log(SMB_VFS_OP_SYS_ACL_INIT, (result != NULL), handle,
1827                "");
1828
1829         return result;
1830 }
1831
1832 static int smb_full_audit_sys_acl_create_entry(vfs_handle_struct *handle,
1833                                       SMB_ACL_T *pacl,
1834                                       SMB_ACL_ENTRY_T *pentry)
1835 {
1836         int result;
1837
1838         result = SMB_VFS_NEXT_SYS_ACL_CREATE_ENTRY(handle, pacl, pentry);
1839
1840         do_log(SMB_VFS_OP_SYS_ACL_CREATE_ENTRY, (result >= 0), handle,
1841                "");
1842
1843         return result;
1844 }
1845
1846 static int smb_full_audit_sys_acl_set_tag_type(vfs_handle_struct *handle,
1847
1848                                       SMB_ACL_ENTRY_T entry,
1849                                       SMB_ACL_TAG_T tagtype)
1850 {
1851         int result;
1852
1853         result = SMB_VFS_NEXT_SYS_ACL_SET_TAG_TYPE(handle, entry,
1854                                                    tagtype);
1855
1856         do_log(SMB_VFS_OP_SYS_ACL_SET_TAG_TYPE, (result >= 0), handle,
1857                "");
1858
1859         return result;
1860 }
1861
1862 static int smb_full_audit_sys_acl_set_qualifier(vfs_handle_struct *handle,
1863
1864                                        SMB_ACL_ENTRY_T entry,
1865                                        void *qual)
1866 {
1867         int result;
1868
1869         result = SMB_VFS_NEXT_SYS_ACL_SET_QUALIFIER(handle, entry, qual);
1870
1871         do_log(SMB_VFS_OP_SYS_ACL_SET_QUALIFIER, (result >= 0), handle,
1872                "");
1873
1874         return result;
1875 }
1876
1877 static int smb_full_audit_sys_acl_set_permset(vfs_handle_struct *handle,
1878
1879                                      SMB_ACL_ENTRY_T entry,
1880                                      SMB_ACL_PERMSET_T permset)
1881 {
1882         int result;
1883
1884         result = SMB_VFS_NEXT_SYS_ACL_SET_PERMSET(handle, entry, permset);
1885
1886         do_log(SMB_VFS_OP_SYS_ACL_SET_PERMSET, (result >= 0), handle,
1887                "");
1888
1889         return result;
1890 }
1891
1892 static int smb_full_audit_sys_acl_valid(vfs_handle_struct *handle,
1893
1894                                SMB_ACL_T theacl )
1895 {
1896         int result;
1897
1898         result = SMB_VFS_NEXT_SYS_ACL_VALID(handle, theacl);
1899
1900         do_log(SMB_VFS_OP_SYS_ACL_VALID, (result >= 0), handle,
1901                "");
1902
1903         return result;
1904 }
1905
1906 static int smb_full_audit_sys_acl_set_file(vfs_handle_struct *handle,
1907
1908                                   const char *name, SMB_ACL_TYPE_T acltype,
1909                                   SMB_ACL_T theacl)
1910 {
1911         int result;
1912
1913         result = SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, name, acltype,
1914                                                theacl);
1915
1916         do_log(SMB_VFS_OP_SYS_ACL_SET_FILE, (result >= 0), handle,
1917                "%s", name);
1918
1919         return result;
1920 }
1921
1922 static int smb_full_audit_sys_acl_set_fd(vfs_handle_struct *handle, files_struct *fsp,
1923                                 SMB_ACL_T theacl)
1924 {
1925         int result;
1926
1927         result = SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, theacl);
1928
1929         do_log(SMB_VFS_OP_SYS_ACL_SET_FD, (result >= 0), handle,
1930                "%s", fsp->fsp_name);
1931
1932         return result;
1933 }
1934
1935 static int smb_full_audit_sys_acl_delete_def_file(vfs_handle_struct *handle,
1936
1937                                          const char *path)
1938 {
1939         int result;
1940
1941         result = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, path);
1942
1943         do_log(SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE, (result >= 0), handle,
1944                "%s", path);
1945
1946         return result;
1947 }
1948
1949 static int smb_full_audit_sys_acl_get_perm(vfs_handle_struct *handle,
1950
1951                                   SMB_ACL_PERMSET_T permset,
1952                                   SMB_ACL_PERM_T perm)
1953 {
1954         int result;
1955
1956         result = SMB_VFS_NEXT_SYS_ACL_GET_PERM(handle, permset, perm);
1957
1958         do_log(SMB_VFS_OP_SYS_ACL_GET_PERM, (result >= 0), handle,
1959                "");
1960
1961         return result;
1962 }
1963
1964 static int smb_full_audit_sys_acl_free_text(vfs_handle_struct *handle,
1965
1966                                    char *text)
1967 {
1968         int result;
1969
1970         result = SMB_VFS_NEXT_SYS_ACL_FREE_TEXT(handle, text);
1971
1972         do_log(SMB_VFS_OP_SYS_ACL_FREE_TEXT, (result >= 0), handle,
1973                "");
1974
1975         return result;
1976 }
1977
1978 static int smb_full_audit_sys_acl_free_acl(vfs_handle_struct *handle,
1979
1980                                   SMB_ACL_T posix_acl)
1981 {
1982         int result;
1983
1984         result = SMB_VFS_NEXT_SYS_ACL_FREE_ACL(handle, posix_acl);
1985
1986         do_log(SMB_VFS_OP_SYS_ACL_FREE_ACL, (result >= 0), handle,
1987                "");
1988
1989         return result;
1990 }
1991
1992 static int smb_full_audit_sys_acl_free_qualifier(vfs_handle_struct *handle,
1993                                         void *qualifier,
1994                                         SMB_ACL_TAG_T tagtype)
1995 {
1996         int result;
1997
1998         result = SMB_VFS_NEXT_SYS_ACL_FREE_QUALIFIER(handle, qualifier,
1999                                                      tagtype);
2000
2001         do_log(SMB_VFS_OP_SYS_ACL_FREE_QUALIFIER, (result >= 0), handle,
2002                "");
2003
2004         return result;
2005 }
2006
2007 static ssize_t smb_full_audit_getxattr(struct vfs_handle_struct *handle,
2008                               const char *path,
2009                               const char *name, void *value, size_t size)
2010 {
2011         ssize_t result;
2012
2013         result = SMB_VFS_NEXT_GETXATTR(handle, path, name, value, size);
2014
2015         do_log(SMB_VFS_OP_GETXATTR, (result >= 0), handle,
2016                "%s|%s", path, name);
2017
2018         return result;
2019 }
2020
2021 static ssize_t smb_full_audit_lgetxattr(struct vfs_handle_struct *handle,
2022                                const char *path, const char *name,
2023                                void *value, size_t size)
2024 {
2025         ssize_t result;
2026
2027         result = SMB_VFS_NEXT_LGETXATTR(handle, path, name, value, size);
2028
2029         do_log(SMB_VFS_OP_LGETXATTR, (result >= 0), handle,
2030                "%s|%s", path, name);
2031
2032         return result;
2033 }
2034
2035 static ssize_t smb_full_audit_fgetxattr(struct vfs_handle_struct *handle,
2036                                struct files_struct *fsp,
2037                                const char *name, void *value, size_t size)
2038 {
2039         ssize_t result;
2040
2041         result = SMB_VFS_NEXT_FGETXATTR(handle, fsp, name, value, size);
2042
2043         do_log(SMB_VFS_OP_FGETXATTR, (result >= 0), handle,
2044                "%s|%s", fsp->fsp_name, name);
2045
2046         return result;
2047 }
2048
2049 static ssize_t smb_full_audit_listxattr(struct vfs_handle_struct *handle,
2050                                const char *path, char *list, size_t size)
2051 {
2052         ssize_t result;
2053
2054         result = SMB_VFS_NEXT_LISTXATTR(handle, path, list, size);
2055
2056         do_log(SMB_VFS_OP_LISTXATTR, (result >= 0), handle, "%s", path);
2057
2058         return result;
2059 }
2060
2061 static ssize_t smb_full_audit_llistxattr(struct vfs_handle_struct *handle,
2062                                 const char *path, char *list, size_t size)
2063 {
2064         ssize_t result;
2065
2066         result = SMB_VFS_NEXT_LLISTXATTR(handle, path, list, size);
2067
2068         do_log(SMB_VFS_OP_LLISTXATTR, (result >= 0), handle, "%s", path);
2069
2070         return result;
2071 }
2072
2073 static ssize_t smb_full_audit_flistxattr(struct vfs_handle_struct *handle,
2074                                 struct files_struct *fsp, char *list,
2075                                 size_t size)
2076 {
2077         ssize_t result;
2078
2079         result = SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
2080
2081         do_log(SMB_VFS_OP_FLISTXATTR, (result >= 0), handle,
2082                "%s", fsp->fsp_name);
2083
2084         return result;
2085 }
2086
2087 static int smb_full_audit_removexattr(struct vfs_handle_struct *handle,
2088                              const char *path,
2089                              const char *name)
2090 {
2091         int result;
2092
2093         result = SMB_VFS_NEXT_REMOVEXATTR(handle, path, name);
2094
2095         do_log(SMB_VFS_OP_REMOVEXATTR, (result >= 0), handle,
2096                "%s|%s", path, name);
2097
2098         return result;
2099 }
2100
2101 static int smb_full_audit_lremovexattr(struct vfs_handle_struct *handle,
2102                               const char *path,
2103                               const char *name)
2104 {
2105         int result;
2106
2107         result = SMB_VFS_NEXT_LREMOVEXATTR(handle, path, name);
2108
2109         do_log(SMB_VFS_OP_LREMOVEXATTR, (result >= 0), handle,
2110                "%s|%s", path, name);
2111
2112         return result;
2113 }
2114
2115 static int smb_full_audit_fremovexattr(struct vfs_handle_struct *handle,
2116                               struct files_struct *fsp,
2117                               const char *name)
2118 {
2119         int result;
2120
2121         result = SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, name);
2122
2123         do_log(SMB_VFS_OP_FREMOVEXATTR, (result >= 0), handle,
2124                "%s|%s", fsp->fsp_name, name);
2125
2126         return result;
2127 }
2128
2129 static int smb_full_audit_setxattr(struct vfs_handle_struct *handle,
2130                           const char *path,
2131                           const char *name, const void *value, size_t size,
2132                           int flags)
2133 {
2134         int result;
2135
2136         result = SMB_VFS_NEXT_SETXATTR(handle, path, name, value, size,
2137                                        flags);
2138
2139         do_log(SMB_VFS_OP_SETXATTR, (result >= 0), handle,
2140                "%s|%s", path, name);
2141
2142         return result;
2143 }
2144
2145 static int smb_full_audit_lsetxattr(struct vfs_handle_struct *handle,
2146                            const char *path,
2147                            const char *name, const void *value, size_t size,
2148                            int flags)
2149 {
2150         int result;
2151
2152         result = SMB_VFS_NEXT_LSETXATTR(handle, path, name, value, size,
2153                                         flags);
2154
2155         do_log(SMB_VFS_OP_LSETXATTR, (result >= 0), handle,
2156                "%s|%s", path, name);
2157
2158         return result;
2159 }
2160
2161 static int smb_full_audit_fsetxattr(struct vfs_handle_struct *handle,
2162                            struct files_struct *fsp, const char *name,
2163                            const void *value, size_t size, int flags)
2164 {
2165         int result;
2166
2167         result = SMB_VFS_NEXT_FSETXATTR(handle, fsp, name, value, size, flags);
2168
2169         do_log(SMB_VFS_OP_FSETXATTR, (result >= 0), handle,
2170                "%s|%s", fsp->fsp_name, name);
2171
2172         return result;
2173 }
2174
2175 static int smb_full_audit_aio_read(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
2176 {
2177         int result;
2178
2179         result = SMB_VFS_NEXT_AIO_READ(handle, fsp, aiocb);
2180         do_log(SMB_VFS_OP_AIO_READ, (result >= 0), handle,
2181                 "%s", fsp->fsp_name);
2182
2183         return result;
2184 }
2185
2186 static int smb_full_audit_aio_write(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
2187 {
2188         int result;
2189
2190         result = SMB_VFS_NEXT_AIO_WRITE(handle, fsp, aiocb);
2191         do_log(SMB_VFS_OP_AIO_WRITE, (result >= 0), handle,
2192                 "%s", fsp->fsp_name);
2193
2194         return result;
2195 }
2196
2197 static ssize_t smb_full_audit_aio_return(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
2198 {
2199         int result;
2200
2201         result = SMB_VFS_NEXT_AIO_RETURN(handle, fsp, aiocb);
2202         do_log(SMB_VFS_OP_AIO_RETURN, (result >= 0), handle,
2203                 "%s", fsp->fsp_name);
2204
2205         return result;
2206 }
2207
2208 static int smb_full_audit_aio_cancel(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
2209 {
2210         int result;
2211
2212         result = SMB_VFS_NEXT_AIO_CANCEL(handle, fsp, aiocb);
2213         do_log(SMB_VFS_OP_AIO_CANCEL, (result >= 0), handle,
2214                 "%s", fsp->fsp_name);
2215
2216         return result;
2217 }
2218
2219 static int smb_full_audit_aio_error(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
2220 {
2221         int result;
2222
2223         result = SMB_VFS_NEXT_AIO_ERROR(handle, fsp, aiocb);
2224         do_log(SMB_VFS_OP_AIO_ERROR, (result >= 0), handle,
2225                 "%s", fsp->fsp_name);
2226
2227         return result;
2228 }
2229
2230 static int smb_full_audit_aio_fsync(struct vfs_handle_struct *handle, struct files_struct *fsp, int op, SMB_STRUCT_AIOCB *aiocb)
2231 {
2232         int result;
2233
2234         result = SMB_VFS_NEXT_AIO_FSYNC(handle, fsp, op, aiocb);
2235         do_log(SMB_VFS_OP_AIO_FSYNC, (result >= 0), handle,
2236                 "%s", fsp->fsp_name);
2237
2238         return result;
2239 }
2240
2241 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)
2242 {
2243         int result;
2244
2245         result = SMB_VFS_NEXT_AIO_SUSPEND(handle, fsp, aiocb, n, ts);
2246         do_log(SMB_VFS_OP_AIO_SUSPEND, (result >= 0), handle,
2247                 "%s", fsp->fsp_name);
2248
2249         return result;
2250 }
2251
2252
2253 NTSTATUS vfs_full_audit_init(void);
2254 NTSTATUS vfs_full_audit_init(void)
2255 {
2256         NTSTATUS ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION,
2257                                         "full_audit", audit_op_tuples);
2258         
2259         if (!NT_STATUS_IS_OK(ret))
2260                 return ret;
2261
2262         vfs_full_audit_debug_level = debug_add_class("full_audit");
2263         if (vfs_full_audit_debug_level == -1) {
2264                 vfs_full_audit_debug_level = DBGC_VFS;
2265                 DEBUG(0, ("vfs_full_audit: Couldn't register custom debugging "
2266                           "class!\n"));
2267         } else {
2268                 DEBUG(10, ("vfs_full_audit: Debug class number of "
2269                            "'full_audit': %d\n", vfs_full_audit_debug_level));
2270         }
2271         
2272         return ret;
2273 }