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