Add create_file to vfs_op_names
[jra/samba/.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
725         prefix = talloc_strdup(ctx,
726                         lp_parm_const_string(SNUM(conn), "full_audit",
727                                              "prefix", "%u|%I"));
728         if (!prefix) {
729                 return NULL;
730         }
731         return talloc_sub_advanced(ctx,
732                         lp_servicename(SNUM(conn)),
733                         conn->server_info->unix_name,
734                         conn->connectpath,
735                         conn->server_info->utok.gid,
736                         conn->server_info->sanitized_username,
737                         pdb_get_domain(conn->server_info->sam_account),
738                         prefix);
739 }
740
741 static bool log_success(vfs_handle_struct *handle, vfs_op_type op)
742 {
743         struct vfs_full_audit_private_data *pd = NULL;
744
745         SMB_VFS_HANDLE_GET_DATA(handle, pd,
746                 struct vfs_full_audit_private_data,
747                 return True);
748
749         if (pd->success_ops == NULL) {
750                 return True;
751         }
752
753         return bitmap_query(pd->success_ops, op);
754 }
755
756 static bool log_failure(vfs_handle_struct *handle, vfs_op_type op)
757 {
758         struct vfs_full_audit_private_data *pd = NULL;
759
760         SMB_VFS_HANDLE_GET_DATA(handle, pd,
761                 struct vfs_full_audit_private_data,
762                 return True);
763
764         if (pd->failure_ops == NULL)
765                 return True;
766
767         return bitmap_query(pd->failure_ops, op);
768 }
769
770 static void init_bitmap(struct bitmap **bm, const char **ops)
771 {
772         bool log_all = False;
773
774         if (*bm != NULL)
775                 return;
776
777         *bm = bitmap_allocate(SMB_VFS_OP_LAST);
778
779         if (*bm == NULL) {
780                 DEBUG(0, ("Could not alloc bitmap -- "
781                           "defaulting to logging everything\n"));
782                 return;
783         }
784
785         while (*ops != NULL) {
786                 int i;
787                 bool found = False;
788
789                 if (strequal(*ops, "all")) {
790                         log_all = True;
791                         break;
792                 }
793
794                 if (strequal(*ops, "none")) {
795                         break;
796                 }
797
798                 for (i=0; i<SMB_VFS_OP_LAST; i++) {
799                         if (vfs_op_names[i].name == NULL) {
800                                 smb_panic("vfs_full_audit.c: name table not "
801                                           "in sync with vfs.h\n");
802                         }
803
804                         if (strequal(*ops, vfs_op_names[i].name)) {
805                                 bitmap_set(*bm, i);
806                                 found = True;
807                         }
808                 }
809                 if (!found) {
810                         DEBUG(0, ("Could not find opname %s, logging all\n",
811                                   *ops));
812                         log_all = True;
813                         break;
814                 }
815                 ops += 1;
816         }
817
818         if (log_all) {
819                 /* The query functions default to True */
820                 bitmap_free(*bm);
821                 *bm = NULL;
822         }
823 }
824
825 static const char *audit_opname(vfs_op_type op)
826 {
827         if (op >= SMB_VFS_OP_LAST)
828                 return "INVALID VFS OP";
829         return vfs_op_names[op].name;
830 }
831
832 static void do_log(vfs_op_type op, bool success, vfs_handle_struct *handle,
833                    const char *format, ...)
834 {
835         fstring err_msg;
836         char *audit_pre = NULL;
837         va_list ap;
838         char *op_msg = NULL;
839
840         if (success && (!log_success(handle, op)))
841                 return;
842
843         if (!success && (!log_failure(handle, op)))
844                 return;
845
846         if (success)
847                 fstrcpy(err_msg, "ok");
848         else
849                 fstr_sprintf(err_msg, "fail (%s)", strerror(errno));
850
851         va_start(ap, format);
852         op_msg = talloc_vasprintf(NULL, format, ap);
853         va_end(ap);
854
855         if (!op_msg) {
856                 return;
857         }
858
859         audit_pre = audit_prefix(NULL, handle->conn);
860         syslog(audit_syslog_priority(handle), "%s|%s|%s|%s\n",
861                 audit_pre ? audit_pre : "",
862                 audit_opname(op), err_msg, op_msg);
863
864         TALLOC_FREE(audit_pre);
865         TALLOC_FREE(op_msg);
866
867         return;
868 }
869
870 /* Free function for the private data. */
871
872 static void free_private_data(void **p_data)
873 {
874         struct vfs_full_audit_private_data *pd = *(struct vfs_full_audit_private_data **)p_data;
875
876         if (pd->success_ops) {
877                 bitmap_free(pd->success_ops);
878         }
879         if (pd->failure_ops) {
880                 bitmap_free(pd->failure_ops);
881         }
882         SAFE_FREE(pd);
883         *p_data = NULL;
884 }
885
886 /* Implementation of vfs_ops.  Pass everything on to the default
887    operation but log event first. */
888
889 static int smb_full_audit_connect(vfs_handle_struct *handle,
890                          const char *svc, const char *user)
891 {
892         int result;
893         struct vfs_full_audit_private_data *pd = NULL;
894         const char *none[] = { NULL };
895         const char *all [] = { "all" };
896
897         if (!handle) {
898                 return -1;
899         }
900
901         pd = SMB_MALLOC_P(struct vfs_full_audit_private_data);
902         if (!pd) {
903                 return -1;
904         }
905         ZERO_STRUCTP(pd);
906
907         openlog("smbd_audit", 0, audit_syslog_facility(handle));
908
909         init_bitmap(&pd->success_ops,
910                     lp_parm_string_list(SNUM(handle->conn), "full_audit", "success",
911                                         none));
912         init_bitmap(&pd->failure_ops,
913                     lp_parm_string_list(SNUM(handle->conn), "full_audit", "failure",
914                                         all));
915
916         /* Store the private data. */
917         SMB_VFS_HANDLE_SET_DATA(handle, pd, free_private_data,
918                                 struct vfs_full_audit_private_data, return -1);
919
920         result = SMB_VFS_NEXT_CONNECT(handle, svc, user);
921
922         do_log(SMB_VFS_OP_CONNECT, True, handle,
923                "%s", svc);
924
925         return result;
926 }
927
928 static void smb_full_audit_disconnect(vfs_handle_struct *handle)
929 {
930         SMB_VFS_NEXT_DISCONNECT(handle);
931
932         do_log(SMB_VFS_OP_DISCONNECT, True, handle,
933                "%s", lp_servicename(SNUM(handle->conn)));
934
935         /* The bitmaps will be disconnected when the private
936            data is deleted. */
937
938         return;
939 }
940
941 static uint64_t smb_full_audit_disk_free(vfs_handle_struct *handle,
942                                     const char *path,
943                                     bool small_query, uint64_t *bsize, 
944                                     uint64_t *dfree, uint64_t *dsize)
945 {
946         uint64_t result;
947
948         result = SMB_VFS_NEXT_DISK_FREE(handle, path, small_query, bsize,
949                                         dfree, dsize);
950
951         /* Don't have a reasonable notion of failure here */
952
953         do_log(SMB_VFS_OP_DISK_FREE, True, handle, "%s", path);
954
955         return result;
956 }
957
958 static int smb_full_audit_get_quota(struct vfs_handle_struct *handle,
959                            enum SMB_QUOTA_TYPE qtype, unid_t id,
960                            SMB_DISK_QUOTA *qt)
961 {
962         int result;
963
964         result = SMB_VFS_NEXT_GET_QUOTA(handle, qtype, id, qt);
965
966         do_log(SMB_VFS_OP_GET_QUOTA, (result >= 0), handle, "");
967
968         return result;
969 }
970
971         
972 static int smb_full_audit_set_quota(struct vfs_handle_struct *handle,
973                            enum SMB_QUOTA_TYPE qtype, unid_t id,
974                            SMB_DISK_QUOTA *qt)
975 {
976         int result;
977
978         result = SMB_VFS_NEXT_SET_QUOTA(handle, qtype, id, qt);
979
980         do_log(SMB_VFS_OP_SET_QUOTA, (result >= 0), handle, "");
981
982         return result;
983 }
984
985 static int smb_full_audit_get_shadow_copy_data(struct vfs_handle_struct *handle,
986                                 struct files_struct *fsp,
987                                 SHADOW_COPY_DATA *shadow_copy_data, bool labels)
988 {
989         int result;
990
991         result = SMB_VFS_NEXT_GET_SHADOW_COPY_DATA(handle, fsp, shadow_copy_data, labels);
992
993         do_log(SMB_VFS_OP_GET_SHADOW_COPY_DATA, (result >= 0), handle, "");
994
995         return result;
996 }
997
998 static int smb_full_audit_statvfs(struct vfs_handle_struct *handle,
999                                 const char *path,
1000                                 struct vfs_statvfs_struct *statbuf)
1001 {
1002         int result;
1003
1004         result = SMB_VFS_NEXT_STATVFS(handle, path, statbuf);
1005
1006         do_log(SMB_VFS_OP_STATVFS, (result >= 0), handle, "");
1007
1008         return result;
1009 }
1010
1011 static SMB_STRUCT_DIR *smb_full_audit_opendir(vfs_handle_struct *handle,
1012                           const char *fname, const char *mask, uint32 attr)
1013 {
1014         SMB_STRUCT_DIR *result;
1015
1016         result = SMB_VFS_NEXT_OPENDIR(handle, fname, mask, attr);
1017
1018         do_log(SMB_VFS_OP_OPENDIR, (result != NULL), handle, "%s", fname);
1019
1020         return result;
1021 }
1022
1023 static SMB_STRUCT_DIRENT *smb_full_audit_readdir(vfs_handle_struct *handle,
1024                                     SMB_STRUCT_DIR *dirp)
1025 {
1026         SMB_STRUCT_DIRENT *result;
1027
1028         result = SMB_VFS_NEXT_READDIR(handle, dirp);
1029
1030         /* This operation has no reasonable error condition
1031          * (End of dir is also failure), so always succeed.
1032          */
1033         do_log(SMB_VFS_OP_READDIR, True, handle, "");
1034
1035         return result;
1036 }
1037
1038 static void smb_full_audit_seekdir(vfs_handle_struct *handle,
1039                         SMB_STRUCT_DIR *dirp, long offset)
1040 {
1041         SMB_VFS_NEXT_SEEKDIR(handle, dirp, offset);
1042
1043         do_log(SMB_VFS_OP_SEEKDIR, True, handle, "");
1044         return;
1045 }
1046
1047 static long smb_full_audit_telldir(vfs_handle_struct *handle,
1048                         SMB_STRUCT_DIR *dirp)
1049 {
1050         long result;
1051
1052         result = SMB_VFS_NEXT_TELLDIR(handle, dirp);
1053
1054         do_log(SMB_VFS_OP_TELLDIR, True, handle, "");
1055
1056         return result;
1057 }
1058
1059 static void smb_full_audit_rewinddir(vfs_handle_struct *handle,
1060                         SMB_STRUCT_DIR *dirp)
1061 {
1062         SMB_VFS_NEXT_REWINDDIR(handle, dirp);
1063
1064         do_log(SMB_VFS_OP_REWINDDIR, True, handle, "");
1065         return;
1066 }
1067
1068 static int smb_full_audit_mkdir(vfs_handle_struct *handle,
1069                        const char *path, mode_t mode)
1070 {
1071         int result;
1072         
1073         result = SMB_VFS_NEXT_MKDIR(handle, path, mode);
1074         
1075         do_log(SMB_VFS_OP_MKDIR, (result >= 0), handle, "%s", path);
1076
1077         return result;
1078 }
1079
1080 static int smb_full_audit_rmdir(vfs_handle_struct *handle,
1081                        const char *path)
1082 {
1083         int result;
1084         
1085         result = SMB_VFS_NEXT_RMDIR(handle, path);
1086
1087         do_log(SMB_VFS_OP_RMDIR, (result >= 0), handle, "%s", path);
1088
1089         return result;
1090 }
1091
1092 static int smb_full_audit_closedir(vfs_handle_struct *handle,
1093                           SMB_STRUCT_DIR *dirp)
1094 {
1095         int result;
1096
1097         result = SMB_VFS_NEXT_CLOSEDIR(handle, dirp);
1098         
1099         do_log(SMB_VFS_OP_CLOSEDIR, (result >= 0), handle, "");
1100
1101         return result;
1102 }
1103
1104 static int smb_full_audit_open(vfs_handle_struct *handle,
1105                       const char *fname, files_struct *fsp, int flags, mode_t mode)
1106 {
1107         int result;
1108         
1109         result = SMB_VFS_NEXT_OPEN(handle, fname, fsp, flags, mode);
1110
1111         do_log(SMB_VFS_OP_OPEN, (result >= 0), handle, "%s|%s",
1112                ((flags & O_WRONLY) || (flags & O_RDWR))?"w":"r",
1113                fname);
1114
1115         return result;
1116 }
1117
1118 static NTSTATUS smb_full_audit_create_file(vfs_handle_struct *handle,
1119                                       struct smb_request *req,
1120                                       uint16_t root_dir_fid,
1121                                       const char *fname,
1122                                       uint32_t create_file_flags,
1123                                       uint32_t access_mask,
1124                                       uint32_t share_access,
1125                                       uint32_t create_disposition,
1126                                       uint32_t create_options,
1127                                       uint32_t file_attributes,
1128                                       uint32_t oplock_request,
1129                                       uint64_t allocation_size,
1130                                       struct security_descriptor *sd,
1131                                       struct ea_list *ea_list,
1132                                       files_struct **result_fsp,
1133                                       int *pinfo,
1134                                       SMB_STRUCT_STAT *psbuf)
1135 {
1136         NTSTATUS result;
1137
1138         result = SMB_VFS_NEXT_CREATE_FILE(
1139                 handle,                                 /* handle */
1140                 req,                                    /* req */
1141                 root_dir_fid,                           /* root_dir_fid */
1142                 fname,                                  /* fname */
1143                 create_file_flags,                      /* create_file_flags */
1144                 access_mask,                            /* access_mask */
1145                 share_access,                           /* share_access */
1146                 create_disposition,                     /* create_disposition*/
1147                 create_options,                         /* create_options */
1148                 file_attributes,                        /* file_attributes */
1149                 oplock_request,                         /* oplock_request */
1150                 allocation_size,                        /* allocation_size */
1151                 sd,                                     /* sd */
1152                 ea_list,                                /* ea_list */
1153                 result_fsp,                             /* result */
1154                 pinfo,                                  /* pinfo */
1155                 psbuf);                                 /* psbuf */
1156
1157         do_log(SMB_VFS_OP_CREATE_FILE, (NT_STATUS_IS_OK(result)), handle, "0x%x|%s",
1158                access_mask, fname);
1159
1160         return result;
1161 }
1162
1163 static int smb_full_audit_close(vfs_handle_struct *handle, files_struct *fsp)
1164 {
1165         int result;
1166         
1167         result = SMB_VFS_NEXT_CLOSE(handle, fsp);
1168
1169         do_log(SMB_VFS_OP_CLOSE, (result >= 0), handle, "%s", fsp->fsp_name);
1170
1171         return result;
1172 }
1173
1174 static ssize_t smb_full_audit_read(vfs_handle_struct *handle, files_struct *fsp,
1175                           void *data, size_t n)
1176 {
1177         ssize_t result;
1178
1179         result = SMB_VFS_NEXT_READ(handle, fsp, data, n);
1180
1181         do_log(SMB_VFS_OP_READ, (result >= 0), handle, "%s", fsp->fsp_name);
1182
1183         return result;
1184 }
1185
1186 static ssize_t smb_full_audit_pread(vfs_handle_struct *handle, files_struct *fsp,
1187                            void *data, size_t n, SMB_OFF_T offset)
1188 {
1189         ssize_t result;
1190
1191         result = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
1192
1193         do_log(SMB_VFS_OP_PREAD, (result >= 0), handle, "%s", fsp->fsp_name);
1194
1195         return result;
1196 }
1197
1198 static ssize_t smb_full_audit_write(vfs_handle_struct *handle, files_struct *fsp,
1199                            const void *data, size_t n)
1200 {
1201         ssize_t result;
1202
1203         result = SMB_VFS_NEXT_WRITE(handle, fsp, data, n);
1204
1205         do_log(SMB_VFS_OP_WRITE, (result >= 0), handle, "%s", fsp->fsp_name);
1206
1207         return result;
1208 }
1209
1210 static ssize_t smb_full_audit_pwrite(vfs_handle_struct *handle, files_struct *fsp,
1211                             const void *data, size_t n,
1212                             SMB_OFF_T offset)
1213 {
1214         ssize_t result;
1215
1216         result = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
1217
1218         do_log(SMB_VFS_OP_PWRITE, (result >= 0), handle, "%s", fsp->fsp_name);
1219
1220         return result;
1221 }
1222
1223 static SMB_OFF_T smb_full_audit_lseek(vfs_handle_struct *handle, files_struct *fsp,
1224                              SMB_OFF_T offset, int whence)
1225 {
1226         ssize_t result;
1227
1228         result = SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence);
1229
1230         do_log(SMB_VFS_OP_LSEEK, (result != (ssize_t)-1), handle,
1231                "%s", fsp->fsp_name);
1232
1233         return result;
1234 }
1235
1236 static ssize_t smb_full_audit_sendfile(vfs_handle_struct *handle, int tofd,
1237                               files_struct *fromfsp,
1238                               const DATA_BLOB *hdr, SMB_OFF_T offset,
1239                               size_t n)
1240 {
1241         ssize_t result;
1242
1243         result = SMB_VFS_NEXT_SENDFILE(handle, tofd, fromfsp, hdr, offset, n);
1244
1245         do_log(SMB_VFS_OP_SENDFILE, (result >= 0), handle,
1246                "%s", fromfsp->fsp_name);
1247
1248         return result;
1249 }
1250
1251 static ssize_t smb_full_audit_recvfile(vfs_handle_struct *handle, int fromfd,
1252                       files_struct *tofsp,
1253                               SMB_OFF_T offset,
1254                               size_t n)
1255 {
1256         ssize_t result;
1257
1258         result = SMB_VFS_NEXT_RECVFILE(handle, fromfd, tofsp, offset, n);
1259
1260         do_log(SMB_VFS_OP_RECVFILE, (result >= 0), handle,
1261                "%s", tofsp->fsp_name);
1262
1263         return result;
1264 }
1265
1266 static int smb_full_audit_rename(vfs_handle_struct *handle,
1267                         const char *oldname, const char *newname)
1268 {
1269         int result;
1270         
1271         result = SMB_VFS_NEXT_RENAME(handle, oldname, newname);
1272
1273         do_log(SMB_VFS_OP_RENAME, (result >= 0), handle, "%s|%s", oldname, newname);
1274
1275         return result;    
1276 }
1277
1278 static int smb_full_audit_fsync(vfs_handle_struct *handle, files_struct *fsp)
1279 {
1280         int result;
1281         
1282         result = SMB_VFS_NEXT_FSYNC(handle, fsp);
1283
1284         do_log(SMB_VFS_OP_FSYNC, (result >= 0), handle, "%s", fsp->fsp_name);
1285
1286         return result;    
1287 }
1288
1289 static int smb_full_audit_stat(vfs_handle_struct *handle,
1290                       const char *fname, SMB_STRUCT_STAT *sbuf)
1291 {
1292         int result;
1293         
1294         result = SMB_VFS_NEXT_STAT(handle, fname, sbuf);
1295
1296         do_log(SMB_VFS_OP_STAT, (result >= 0), handle, "%s", fname);
1297
1298         return result;    
1299 }
1300
1301 static int smb_full_audit_fstat(vfs_handle_struct *handle, files_struct *fsp,
1302                        SMB_STRUCT_STAT *sbuf)
1303 {
1304         int result;
1305         
1306         result = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1307
1308         do_log(SMB_VFS_OP_FSTAT, (result >= 0), handle, "%s", fsp->fsp_name);
1309
1310         return result;
1311 }
1312
1313 static int smb_full_audit_lstat(vfs_handle_struct *handle,
1314                        const char *path, SMB_STRUCT_STAT *sbuf)
1315 {
1316         int result;
1317         
1318         result = SMB_VFS_NEXT_LSTAT(handle, path, sbuf);
1319
1320         do_log(SMB_VFS_OP_LSTAT, (result >= 0), handle, "%s", path);
1321
1322         return result;    
1323 }
1324
1325 static int smb_full_audit_unlink(vfs_handle_struct *handle,
1326                         const char *path)
1327 {
1328         int result;
1329         
1330         result = SMB_VFS_NEXT_UNLINK(handle, path);
1331
1332         do_log(SMB_VFS_OP_UNLINK, (result >= 0), handle, "%s", path);
1333
1334         return result;
1335 }
1336
1337 static int smb_full_audit_chmod(vfs_handle_struct *handle,
1338                        const char *path, mode_t mode)
1339 {
1340         int result;
1341
1342         result = SMB_VFS_NEXT_CHMOD(handle, path, mode);
1343
1344         do_log(SMB_VFS_OP_CHMOD, (result >= 0), handle, "%s|%o", path, mode);
1345
1346         return result;
1347 }
1348
1349 static int smb_full_audit_fchmod(vfs_handle_struct *handle, files_struct *fsp,
1350                         mode_t mode)
1351 {
1352         int result;
1353         
1354         result = SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1355
1356         do_log(SMB_VFS_OP_FCHMOD, (result >= 0), handle,
1357                "%s|%o", fsp->fsp_name, mode);
1358
1359         return result;
1360 }
1361
1362 static int smb_full_audit_chown(vfs_handle_struct *handle,
1363                        const char *path, uid_t uid, gid_t gid)
1364 {
1365         int result;
1366
1367         result = SMB_VFS_NEXT_CHOWN(handle, path, uid, gid);
1368
1369         do_log(SMB_VFS_OP_CHOWN, (result >= 0), handle, "%s|%ld|%ld",
1370                path, (long int)uid, (long int)gid);
1371
1372         return result;
1373 }
1374
1375 static int smb_full_audit_fchown(vfs_handle_struct *handle, files_struct *fsp,
1376                         uid_t uid, gid_t gid)
1377 {
1378         int result;
1379
1380         result = SMB_VFS_NEXT_FCHOWN(handle, fsp, uid, gid);
1381
1382         do_log(SMB_VFS_OP_FCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1383                fsp->fsp_name, (long int)uid, (long int)gid);
1384
1385         return result;
1386 }
1387
1388 static int smb_full_audit_lchown(vfs_handle_struct *handle,
1389                        const char *path, uid_t uid, gid_t gid)
1390 {
1391         int result;
1392
1393         result = SMB_VFS_NEXT_LCHOWN(handle, path, uid, gid);
1394
1395         do_log(SMB_VFS_OP_LCHOWN, (result >= 0), handle, "%s|%ld|%ld",
1396                path, (long int)uid, (long int)gid);
1397
1398         return result;
1399 }
1400
1401 static int smb_full_audit_chdir(vfs_handle_struct *handle,
1402                        const char *path)
1403 {
1404         int result;
1405
1406         result = SMB_VFS_NEXT_CHDIR(handle, path);
1407
1408         do_log(SMB_VFS_OP_CHDIR, (result >= 0), handle, "chdir|%s", path);
1409
1410         return result;
1411 }
1412
1413 static char *smb_full_audit_getwd(vfs_handle_struct *handle,
1414                          char *path)
1415 {
1416         char *result;
1417
1418         result = SMB_VFS_NEXT_GETWD(handle, path);
1419         
1420         do_log(SMB_VFS_OP_GETWD, (result != NULL), handle, "%s", path);
1421
1422         return result;
1423 }
1424
1425 static int smb_full_audit_ntimes(vfs_handle_struct *handle,
1426                        const char *path, const struct timespec ts[2])
1427 {
1428         int result;
1429
1430         result = SMB_VFS_NEXT_NTIMES(handle, path, ts);
1431
1432         do_log(SMB_VFS_OP_NTIMES, (result >= 0), handle, "%s", path);
1433
1434         return result;
1435 }
1436
1437 static int smb_full_audit_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
1438                            SMB_OFF_T len)
1439 {
1440         int result;
1441
1442         result = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1443
1444         do_log(SMB_VFS_OP_FTRUNCATE, (result >= 0), handle,
1445                "%s", fsp->fsp_name);
1446
1447         return result;
1448 }
1449
1450 static bool smb_full_audit_lock(vfs_handle_struct *handle, files_struct *fsp,
1451                        int op, SMB_OFF_T offset, SMB_OFF_T count, int type)
1452 {
1453         bool result;
1454
1455         result = SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type);
1456
1457         do_log(SMB_VFS_OP_LOCK, result, handle, "%s", fsp->fsp_name);
1458
1459         return result;
1460 }
1461
1462 static int smb_full_audit_kernel_flock(struct vfs_handle_struct *handle,
1463                                        struct files_struct *fsp,
1464                                        uint32 share_mode)
1465 {
1466         int result;
1467
1468         result = SMB_VFS_NEXT_KERNEL_FLOCK(handle, fsp, share_mode);
1469
1470         do_log(SMB_VFS_OP_KERNEL_FLOCK, (result >= 0), handle, "%s",
1471                fsp->fsp_name);
1472
1473         return result;
1474 }
1475
1476 static int smb_full_audit_linux_setlease(vfs_handle_struct *handle, files_struct *fsp,
1477                                  int leasetype)
1478 {
1479         int result;
1480
1481         result = SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
1482
1483         do_log(SMB_VFS_OP_LINUX_SETLEASE, (result >= 0), handle, "%s",
1484                fsp->fsp_name);
1485
1486         return result;
1487 }
1488
1489 static bool smb_full_audit_getlock(vfs_handle_struct *handle, files_struct *fsp,
1490                        SMB_OFF_T *poffset, SMB_OFF_T *pcount, int *ptype, pid_t *ppid)
1491 {
1492         bool result;
1493
1494         result = SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype, ppid);
1495
1496         do_log(SMB_VFS_OP_GETLOCK, result, handle, "%s", fsp->fsp_name);
1497
1498         return result;
1499 }
1500
1501 static int smb_full_audit_symlink(vfs_handle_struct *handle,
1502                          const char *oldpath, const char *newpath)
1503 {
1504         int result;
1505
1506         result = SMB_VFS_NEXT_SYMLINK(handle, oldpath, newpath);
1507
1508         do_log(SMB_VFS_OP_SYMLINK, (result >= 0), handle,
1509                "%s|%s", oldpath, newpath);
1510
1511         return result;
1512 }
1513
1514 static int smb_full_audit_readlink(vfs_handle_struct *handle,
1515                           const char *path, char *buf, size_t bufsiz)
1516 {
1517         int result;
1518
1519         result = SMB_VFS_NEXT_READLINK(handle, path, buf, bufsiz);
1520
1521         do_log(SMB_VFS_OP_READLINK, (result >= 0), handle, "%s", path);
1522
1523         return result;
1524 }
1525
1526 static int smb_full_audit_link(vfs_handle_struct *handle,
1527                       const char *oldpath, const char *newpath)
1528 {
1529         int result;
1530
1531         result = SMB_VFS_NEXT_LINK(handle, oldpath, newpath);
1532
1533         do_log(SMB_VFS_OP_LINK, (result >= 0), handle,
1534                "%s|%s", oldpath, newpath);
1535
1536         return result;
1537 }
1538
1539 static int smb_full_audit_mknod(vfs_handle_struct *handle,
1540                        const char *pathname, mode_t mode, SMB_DEV_T dev)
1541 {
1542         int result;
1543
1544         result = SMB_VFS_NEXT_MKNOD(handle, pathname, mode, dev);
1545
1546         do_log(SMB_VFS_OP_MKNOD, (result >= 0), handle, "%s", pathname);
1547
1548         return result;
1549 }
1550
1551 static char *smb_full_audit_realpath(vfs_handle_struct *handle,
1552                             const char *path, char *resolved_path)
1553 {
1554         char *result;
1555
1556         result = SMB_VFS_NEXT_REALPATH(handle, path, resolved_path);
1557
1558         do_log(SMB_VFS_OP_REALPATH, (result != NULL), handle, "%s", path);
1559
1560         return result;
1561 }
1562
1563 static NTSTATUS smb_full_audit_notify_watch(struct vfs_handle_struct *handle,
1564                         struct sys_notify_context *ctx,
1565                         struct notify_entry *e,
1566                         void (*callback)(struct sys_notify_context *ctx,
1567                                         void *private_data,
1568                                         struct notify_event *ev),
1569                         void *private_data, void *handle_p)
1570 {
1571         NTSTATUS result;
1572
1573         result = SMB_VFS_NEXT_NOTIFY_WATCH(handle, ctx, e, callback, private_data, handle_p);
1574
1575         do_log(SMB_VFS_OP_NOTIFY_WATCH, NT_STATUS_IS_OK(result), handle, "");
1576
1577         return result;
1578 }
1579
1580 static int smb_full_audit_chflags(vfs_handle_struct *handle,
1581                             const char *path, unsigned int flags)
1582 {
1583         int result;
1584
1585         result = SMB_VFS_NEXT_CHFLAGS(handle, path, flags);
1586
1587         do_log(SMB_VFS_OP_CHFLAGS, (result != 0), handle, "%s", path);
1588
1589         return result;
1590 }
1591
1592 static struct file_id smb_full_audit_file_id_create(struct vfs_handle_struct *handle,
1593                                                     SMB_DEV_T dev, SMB_INO_T inode)
1594 {
1595         struct file_id id_zero;
1596         struct file_id result;
1597
1598         ZERO_STRUCT(id_zero);
1599
1600         result = SMB_VFS_NEXT_FILE_ID_CREATE(handle, dev, inode);
1601
1602         do_log(SMB_VFS_OP_FILE_ID_CREATE,
1603                !file_id_equal(&id_zero, &result),
1604                handle, "%s", file_id_string_tos(&result));
1605
1606         return result;
1607 }
1608
1609 static NTSTATUS smb_full_audit_streaminfo(vfs_handle_struct *handle,
1610                                           struct files_struct *fsp,
1611                                           const char *fname,
1612                                           TALLOC_CTX *mem_ctx,
1613                                           unsigned int *pnum_streams,
1614                                           struct stream_struct **pstreams)
1615 {
1616         NTSTATUS result;
1617
1618         result = SMB_VFS_NEXT_STREAMINFO(handle, fsp, fname, mem_ctx,
1619                                          pnum_streams, pstreams);
1620
1621         do_log(SMB_VFS_OP_STREAMINFO, NT_STATUS_IS_OK(result), handle,
1622                "%s", fname);
1623
1624         return result;
1625 }
1626
1627 static int smb_full_audit_get_real_filename(struct vfs_handle_struct *handle,
1628                                             const char *path,
1629                                             const char *name,
1630                                             TALLOC_CTX *mem_ctx,
1631                                             char **found_name)
1632 {
1633         int result;
1634
1635         result = SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name, mem_ctx,
1636                                                 found_name);
1637
1638         do_log(SMB_VFS_OP_GET_REAL_FILENAME, (result == 0), handle,
1639                "%s/%s->%s", path, name, (result == 0) ? "" : *found_name);
1640
1641         return result;
1642 }
1643
1644 static NTSTATUS smb_full_audit_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
1645                                 uint32 security_info,
1646                                 SEC_DESC **ppdesc)
1647 {
1648         NTSTATUS result;
1649
1650         result = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info, ppdesc);
1651
1652         do_log(SMB_VFS_OP_FGET_NT_ACL, NT_STATUS_IS_OK(result), handle,
1653                "%s", fsp->fsp_name);
1654
1655         return result;
1656 }
1657
1658 static NTSTATUS smb_full_audit_get_nt_acl(vfs_handle_struct *handle,
1659                                           const char *name,
1660                                           uint32 security_info,
1661                                           SEC_DESC **ppdesc)
1662 {
1663         NTSTATUS result;
1664
1665         result = SMB_VFS_NEXT_GET_NT_ACL(handle, name, security_info, ppdesc);
1666
1667         do_log(SMB_VFS_OP_GET_NT_ACL, NT_STATUS_IS_OK(result), handle,
1668                "%s", name);
1669
1670         return result;
1671 }
1672
1673 static NTSTATUS smb_full_audit_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
1674                               uint32 security_info_sent,
1675                               const SEC_DESC *psd)
1676 {
1677         NTSTATUS result;
1678
1679         result = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
1680
1681         do_log(SMB_VFS_OP_FSET_NT_ACL, NT_STATUS_IS_OK(result), handle, "%s", fsp->fsp_name);
1682
1683         return result;
1684 }
1685
1686 static int smb_full_audit_chmod_acl(vfs_handle_struct *handle,
1687                            const char *path, mode_t mode)
1688 {
1689         int result;
1690         
1691         result = SMB_VFS_NEXT_CHMOD_ACL(handle, path, mode);
1692
1693         do_log(SMB_VFS_OP_CHMOD_ACL, (result >= 0), handle,
1694                "%s|%o", path, mode);
1695
1696         return result;
1697 }
1698
1699 static int smb_full_audit_fchmod_acl(vfs_handle_struct *handle, files_struct *fsp,
1700                                      mode_t mode)
1701 {
1702         int result;
1703         
1704         result = SMB_VFS_NEXT_FCHMOD_ACL(handle, fsp, mode);
1705
1706         do_log(SMB_VFS_OP_FCHMOD_ACL, (result >= 0), handle,
1707                "%s|%o", fsp->fsp_name, mode);
1708
1709         return result;
1710 }
1711
1712 static int smb_full_audit_sys_acl_get_entry(vfs_handle_struct *handle,
1713
1714                                    SMB_ACL_T theacl, int entry_id,
1715                                    SMB_ACL_ENTRY_T *entry_p)
1716 {
1717         int result;
1718
1719         result = SMB_VFS_NEXT_SYS_ACL_GET_ENTRY(handle, theacl, entry_id,
1720                                                 entry_p);
1721
1722         do_log(SMB_VFS_OP_SYS_ACL_GET_ENTRY, (result >= 0), handle,
1723                "");
1724
1725         return result;
1726 }
1727
1728 static int smb_full_audit_sys_acl_get_tag_type(vfs_handle_struct *handle,
1729
1730                                       SMB_ACL_ENTRY_T entry_d,
1731                                       SMB_ACL_TAG_T *tag_type_p)
1732 {
1733         int result;
1734
1735         result = SMB_VFS_NEXT_SYS_ACL_GET_TAG_TYPE(handle, entry_d,
1736                                                    tag_type_p);
1737
1738         do_log(SMB_VFS_OP_SYS_ACL_GET_TAG_TYPE, (result >= 0), handle,
1739                "");
1740
1741         return result;
1742 }
1743
1744 static int smb_full_audit_sys_acl_get_permset(vfs_handle_struct *handle,
1745
1746                                      SMB_ACL_ENTRY_T entry_d,
1747                                      SMB_ACL_PERMSET_T *permset_p)
1748 {
1749         int result;
1750
1751         result = SMB_VFS_NEXT_SYS_ACL_GET_PERMSET(handle, entry_d,
1752                                                   permset_p);
1753
1754         do_log(SMB_VFS_OP_SYS_ACL_GET_PERMSET, (result >= 0), handle,
1755                "");
1756
1757         return result;
1758 }
1759
1760 static void * smb_full_audit_sys_acl_get_qualifier(vfs_handle_struct *handle,
1761
1762                                           SMB_ACL_ENTRY_T entry_d)
1763 {
1764         void *result;
1765
1766         result = SMB_VFS_NEXT_SYS_ACL_GET_QUALIFIER(handle, entry_d);
1767
1768         do_log(SMB_VFS_OP_SYS_ACL_GET_QUALIFIER, (result != NULL), handle,
1769                "");
1770
1771         return result;
1772 }
1773
1774 static SMB_ACL_T smb_full_audit_sys_acl_get_file(vfs_handle_struct *handle,
1775                                         const char *path_p,
1776                                         SMB_ACL_TYPE_T type)
1777 {
1778         SMB_ACL_T result;
1779
1780         result = SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, path_p, type);
1781
1782         do_log(SMB_VFS_OP_SYS_ACL_GET_FILE, (result != NULL), handle,
1783                "%s", path_p);
1784
1785         return result;
1786 }
1787
1788 static SMB_ACL_T smb_full_audit_sys_acl_get_fd(vfs_handle_struct *handle,
1789                                       files_struct *fsp)
1790 {
1791         SMB_ACL_T result;
1792
1793         result = SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp);
1794
1795         do_log(SMB_VFS_OP_SYS_ACL_GET_FD, (result != NULL), handle,
1796                "%s", fsp->fsp_name);
1797
1798         return result;
1799 }
1800
1801 static int smb_full_audit_sys_acl_clear_perms(vfs_handle_struct *handle,
1802
1803                                      SMB_ACL_PERMSET_T permset)
1804 {
1805         int result;
1806
1807         result = SMB_VFS_NEXT_SYS_ACL_CLEAR_PERMS(handle, permset);
1808
1809         do_log(SMB_VFS_OP_SYS_ACL_CLEAR_PERMS, (result >= 0), handle,
1810                "");
1811
1812         return result;
1813 }
1814
1815 static int smb_full_audit_sys_acl_add_perm(vfs_handle_struct *handle,
1816
1817                                   SMB_ACL_PERMSET_T permset,
1818                                   SMB_ACL_PERM_T perm)
1819 {
1820         int result;
1821
1822         result = SMB_VFS_NEXT_SYS_ACL_ADD_PERM(handle, permset, perm);
1823
1824         do_log(SMB_VFS_OP_SYS_ACL_ADD_PERM, (result >= 0), handle,
1825                "");
1826
1827         return result;
1828 }
1829
1830 static char * smb_full_audit_sys_acl_to_text(vfs_handle_struct *handle,
1831                                     SMB_ACL_T theacl,
1832                                     ssize_t *plen)
1833 {
1834         char * result;
1835
1836         result = SMB_VFS_NEXT_SYS_ACL_TO_TEXT(handle, theacl, plen);
1837
1838         do_log(SMB_VFS_OP_SYS_ACL_TO_TEXT, (result != NULL), handle,
1839                "");
1840
1841         return result;
1842 }
1843
1844 static SMB_ACL_T smb_full_audit_sys_acl_init(vfs_handle_struct *handle,
1845
1846                                     int count)
1847 {
1848         SMB_ACL_T result;
1849
1850         result = SMB_VFS_NEXT_SYS_ACL_INIT(handle, count);
1851
1852         do_log(SMB_VFS_OP_SYS_ACL_INIT, (result != NULL), handle,
1853                "");
1854
1855         return result;
1856 }
1857
1858 static int smb_full_audit_sys_acl_create_entry(vfs_handle_struct *handle,
1859                                       SMB_ACL_T *pacl,
1860                                       SMB_ACL_ENTRY_T *pentry)
1861 {
1862         int result;
1863
1864         result = SMB_VFS_NEXT_SYS_ACL_CREATE_ENTRY(handle, pacl, pentry);
1865
1866         do_log(SMB_VFS_OP_SYS_ACL_CREATE_ENTRY, (result >= 0), handle,
1867                "");
1868
1869         return result;
1870 }
1871
1872 static int smb_full_audit_sys_acl_set_tag_type(vfs_handle_struct *handle,
1873
1874                                       SMB_ACL_ENTRY_T entry,
1875                                       SMB_ACL_TAG_T tagtype)
1876 {
1877         int result;
1878
1879         result = SMB_VFS_NEXT_SYS_ACL_SET_TAG_TYPE(handle, entry,
1880                                                    tagtype);
1881
1882         do_log(SMB_VFS_OP_SYS_ACL_SET_TAG_TYPE, (result >= 0), handle,
1883                "");
1884
1885         return result;
1886 }
1887
1888 static int smb_full_audit_sys_acl_set_qualifier(vfs_handle_struct *handle,
1889
1890                                        SMB_ACL_ENTRY_T entry,
1891                                        void *qual)
1892 {
1893         int result;
1894
1895         result = SMB_VFS_NEXT_SYS_ACL_SET_QUALIFIER(handle, entry, qual);
1896
1897         do_log(SMB_VFS_OP_SYS_ACL_SET_QUALIFIER, (result >= 0), handle,
1898                "");
1899
1900         return result;
1901 }
1902
1903 static int smb_full_audit_sys_acl_set_permset(vfs_handle_struct *handle,
1904
1905                                      SMB_ACL_ENTRY_T entry,
1906                                      SMB_ACL_PERMSET_T permset)
1907 {
1908         int result;
1909
1910         result = SMB_VFS_NEXT_SYS_ACL_SET_PERMSET(handle, entry, permset);
1911
1912         do_log(SMB_VFS_OP_SYS_ACL_SET_PERMSET, (result >= 0), handle,
1913                "");
1914
1915         return result;
1916 }
1917
1918 static int smb_full_audit_sys_acl_valid(vfs_handle_struct *handle,
1919
1920                                SMB_ACL_T theacl )
1921 {
1922         int result;
1923
1924         result = SMB_VFS_NEXT_SYS_ACL_VALID(handle, theacl);
1925
1926         do_log(SMB_VFS_OP_SYS_ACL_VALID, (result >= 0), handle,
1927                "");
1928
1929         return result;
1930 }
1931
1932 static int smb_full_audit_sys_acl_set_file(vfs_handle_struct *handle,
1933
1934                                   const char *name, SMB_ACL_TYPE_T acltype,
1935                                   SMB_ACL_T theacl)
1936 {
1937         int result;
1938
1939         result = SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, name, acltype,
1940                                                theacl);
1941
1942         do_log(SMB_VFS_OP_SYS_ACL_SET_FILE, (result >= 0), handle,
1943                "%s", name);
1944
1945         return result;
1946 }
1947
1948 static int smb_full_audit_sys_acl_set_fd(vfs_handle_struct *handle, files_struct *fsp,
1949                                 SMB_ACL_T theacl)
1950 {
1951         int result;
1952
1953         result = SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, theacl);
1954
1955         do_log(SMB_VFS_OP_SYS_ACL_SET_FD, (result >= 0), handle,
1956                "%s", fsp->fsp_name);
1957
1958         return result;
1959 }
1960
1961 static int smb_full_audit_sys_acl_delete_def_file(vfs_handle_struct *handle,
1962
1963                                          const char *path)
1964 {
1965         int result;
1966
1967         result = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, path);
1968
1969         do_log(SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE, (result >= 0), handle,
1970                "%s", path);
1971
1972         return result;
1973 }
1974
1975 static int smb_full_audit_sys_acl_get_perm(vfs_handle_struct *handle,
1976
1977                                   SMB_ACL_PERMSET_T permset,
1978                                   SMB_ACL_PERM_T perm)
1979 {
1980         int result;
1981
1982         result = SMB_VFS_NEXT_SYS_ACL_GET_PERM(handle, permset, perm);
1983
1984         do_log(SMB_VFS_OP_SYS_ACL_GET_PERM, (result >= 0), handle,
1985                "");
1986
1987         return result;
1988 }
1989
1990 static int smb_full_audit_sys_acl_free_text(vfs_handle_struct *handle,
1991
1992                                    char *text)
1993 {
1994         int result;
1995
1996         result = SMB_VFS_NEXT_SYS_ACL_FREE_TEXT(handle, text);
1997
1998         do_log(SMB_VFS_OP_SYS_ACL_FREE_TEXT, (result >= 0), handle,
1999                "");
2000
2001         return result;
2002 }
2003
2004 static int smb_full_audit_sys_acl_free_acl(vfs_handle_struct *handle,
2005
2006                                   SMB_ACL_T posix_acl)
2007 {
2008         int result;
2009
2010         result = SMB_VFS_NEXT_SYS_ACL_FREE_ACL(handle, posix_acl);
2011
2012         do_log(SMB_VFS_OP_SYS_ACL_FREE_ACL, (result >= 0), handle,
2013                "");
2014
2015         return result;
2016 }
2017
2018 static int smb_full_audit_sys_acl_free_qualifier(vfs_handle_struct *handle,
2019                                         void *qualifier,
2020                                         SMB_ACL_TAG_T tagtype)
2021 {
2022         int result;
2023
2024         result = SMB_VFS_NEXT_SYS_ACL_FREE_QUALIFIER(handle, qualifier,
2025                                                      tagtype);
2026
2027         do_log(SMB_VFS_OP_SYS_ACL_FREE_QUALIFIER, (result >= 0), handle,
2028                "");
2029
2030         return result;
2031 }
2032
2033 static ssize_t smb_full_audit_getxattr(struct vfs_handle_struct *handle,
2034                               const char *path,
2035                               const char *name, void *value, size_t size)
2036 {
2037         ssize_t result;
2038
2039         result = SMB_VFS_NEXT_GETXATTR(handle, path, name, value, size);
2040
2041         do_log(SMB_VFS_OP_GETXATTR, (result >= 0), handle,
2042                "%s|%s", path, name);
2043
2044         return result;
2045 }
2046
2047 static ssize_t smb_full_audit_lgetxattr(struct vfs_handle_struct *handle,
2048                                const char *path, const char *name,
2049                                void *value, size_t size)
2050 {
2051         ssize_t result;
2052
2053         result = SMB_VFS_NEXT_LGETXATTR(handle, path, name, value, size);
2054
2055         do_log(SMB_VFS_OP_LGETXATTR, (result >= 0), handle,
2056                "%s|%s", path, name);
2057
2058         return result;
2059 }
2060
2061 static ssize_t smb_full_audit_fgetxattr(struct vfs_handle_struct *handle,
2062                                struct files_struct *fsp,
2063                                const char *name, void *value, size_t size)
2064 {
2065         ssize_t result;
2066
2067         result = SMB_VFS_NEXT_FGETXATTR(handle, fsp, name, value, size);
2068
2069         do_log(SMB_VFS_OP_FGETXATTR, (result >= 0), handle,
2070                "%s|%s", fsp->fsp_name, name);
2071
2072         return result;
2073 }
2074
2075 static ssize_t smb_full_audit_listxattr(struct vfs_handle_struct *handle,
2076                                const char *path, char *list, size_t size)
2077 {
2078         ssize_t result;
2079
2080         result = SMB_VFS_NEXT_LISTXATTR(handle, path, list, size);
2081
2082         do_log(SMB_VFS_OP_LISTXATTR, (result >= 0), handle, "%s", path);
2083
2084         return result;
2085 }
2086
2087 static ssize_t smb_full_audit_llistxattr(struct vfs_handle_struct *handle,
2088                                 const char *path, char *list, size_t size)
2089 {
2090         ssize_t result;
2091
2092         result = SMB_VFS_NEXT_LLISTXATTR(handle, path, list, size);
2093
2094         do_log(SMB_VFS_OP_LLISTXATTR, (result >= 0), handle, "%s", path);
2095
2096         return result;
2097 }
2098
2099 static ssize_t smb_full_audit_flistxattr(struct vfs_handle_struct *handle,
2100                                 struct files_struct *fsp, char *list,
2101                                 size_t size)
2102 {
2103         ssize_t result;
2104
2105         result = SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
2106
2107         do_log(SMB_VFS_OP_FLISTXATTR, (result >= 0), handle,
2108                "%s", fsp->fsp_name);
2109
2110         return result;
2111 }
2112
2113 static int smb_full_audit_removexattr(struct vfs_handle_struct *handle,
2114                              const char *path,
2115                              const char *name)
2116 {
2117         int result;
2118
2119         result = SMB_VFS_NEXT_REMOVEXATTR(handle, path, name);
2120
2121         do_log(SMB_VFS_OP_REMOVEXATTR, (result >= 0), handle,
2122                "%s|%s", path, name);
2123
2124         return result;
2125 }
2126
2127 static int smb_full_audit_lremovexattr(struct vfs_handle_struct *handle,
2128                               const char *path,
2129                               const char *name)
2130 {
2131         int result;
2132
2133         result = SMB_VFS_NEXT_LREMOVEXATTR(handle, path, name);
2134
2135         do_log(SMB_VFS_OP_LREMOVEXATTR, (result >= 0), handle,
2136                "%s|%s", path, name);
2137
2138         return result;
2139 }
2140
2141 static int smb_full_audit_fremovexattr(struct vfs_handle_struct *handle,
2142                               struct files_struct *fsp,
2143                               const char *name)
2144 {
2145         int result;
2146
2147         result = SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, name);
2148
2149         do_log(SMB_VFS_OP_FREMOVEXATTR, (result >= 0), handle,
2150                "%s|%s", fsp->fsp_name, name);
2151
2152         return result;
2153 }
2154
2155 static int smb_full_audit_setxattr(struct vfs_handle_struct *handle,
2156                           const char *path,
2157                           const char *name, const void *value, size_t size,
2158                           int flags)
2159 {
2160         int result;
2161
2162         result = SMB_VFS_NEXT_SETXATTR(handle, path, name, value, size,
2163                                        flags);
2164
2165         do_log(SMB_VFS_OP_SETXATTR, (result >= 0), handle,
2166                "%s|%s", path, name);
2167
2168         return result;
2169 }
2170
2171 static int smb_full_audit_lsetxattr(struct vfs_handle_struct *handle,
2172                            const char *path,
2173                            const char *name, const void *value, size_t size,
2174                            int flags)
2175 {
2176         int result;
2177
2178         result = SMB_VFS_NEXT_LSETXATTR(handle, path, name, value, size,
2179                                         flags);
2180
2181         do_log(SMB_VFS_OP_LSETXATTR, (result >= 0), handle,
2182                "%s|%s", path, name);
2183
2184         return result;
2185 }
2186
2187 static int smb_full_audit_fsetxattr(struct vfs_handle_struct *handle,
2188                            struct files_struct *fsp, const char *name,
2189                            const void *value, size_t size, int flags)
2190 {
2191         int result;
2192
2193         result = SMB_VFS_NEXT_FSETXATTR(handle, fsp, name, value, size, flags);
2194
2195         do_log(SMB_VFS_OP_FSETXATTR, (result >= 0), handle,
2196                "%s|%s", fsp->fsp_name, name);
2197
2198         return result;
2199 }
2200
2201 static int smb_full_audit_aio_read(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
2202 {
2203         int result;
2204
2205         result = SMB_VFS_NEXT_AIO_READ(handle, fsp, aiocb);
2206         do_log(SMB_VFS_OP_AIO_READ, (result >= 0), handle,
2207                 "%s", fsp->fsp_name);
2208
2209         return result;
2210 }
2211
2212 static int smb_full_audit_aio_write(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
2213 {
2214         int result;
2215
2216         result = SMB_VFS_NEXT_AIO_WRITE(handle, fsp, aiocb);
2217         do_log(SMB_VFS_OP_AIO_WRITE, (result >= 0), handle,
2218                 "%s", fsp->fsp_name);
2219
2220         return result;
2221 }
2222
2223 static ssize_t smb_full_audit_aio_return(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
2224 {
2225         int result;
2226
2227         result = SMB_VFS_NEXT_AIO_RETURN(handle, fsp, aiocb);
2228         do_log(SMB_VFS_OP_AIO_RETURN, (result >= 0), handle,
2229                 "%s", fsp->fsp_name);
2230
2231         return result;
2232 }
2233
2234 static int smb_full_audit_aio_cancel(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
2235 {
2236         int result;
2237
2238         result = SMB_VFS_NEXT_AIO_CANCEL(handle, fsp, aiocb);
2239         do_log(SMB_VFS_OP_AIO_CANCEL, (result >= 0), handle,
2240                 "%s", fsp->fsp_name);
2241
2242         return result;
2243 }
2244
2245 static int smb_full_audit_aio_error(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
2246 {
2247         int result;
2248
2249         result = SMB_VFS_NEXT_AIO_ERROR(handle, fsp, aiocb);
2250         do_log(SMB_VFS_OP_AIO_ERROR, (result >= 0), handle,
2251                 "%s", fsp->fsp_name);
2252
2253         return result;
2254 }
2255
2256 static int smb_full_audit_aio_fsync(struct vfs_handle_struct *handle, struct files_struct *fsp, int op, SMB_STRUCT_AIOCB *aiocb)
2257 {
2258         int result;
2259
2260         result = SMB_VFS_NEXT_AIO_FSYNC(handle, fsp, op, aiocb);
2261         do_log(SMB_VFS_OP_AIO_FSYNC, (result >= 0), handle,
2262                 "%s", fsp->fsp_name);
2263
2264         return result;
2265 }
2266
2267 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)
2268 {
2269         int result;
2270
2271         result = SMB_VFS_NEXT_AIO_SUSPEND(handle, fsp, aiocb, n, ts);
2272         do_log(SMB_VFS_OP_AIO_SUSPEND, (result >= 0), handle,
2273                 "%s", fsp->fsp_name);
2274
2275         return result;
2276 }
2277
2278
2279 NTSTATUS vfs_full_audit_init(void);
2280 NTSTATUS vfs_full_audit_init(void)
2281 {
2282         NTSTATUS ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION,
2283                                         "full_audit", audit_op_tuples);
2284         
2285         if (!NT_STATUS_IS_OK(ret))
2286                 return ret;
2287
2288         vfs_full_audit_debug_level = debug_add_class("full_audit");
2289         if (vfs_full_audit_debug_level == -1) {
2290                 vfs_full_audit_debug_level = DBGC_VFS;
2291                 DEBUG(0, ("vfs_full_audit: Couldn't register custom debugging "
2292                           "class!\n"));
2293         } else {
2294                 DEBUG(10, ("vfs_full_audit: Debug class number of "
2295                            "'full_audit': %d\n", vfs_full_audit_debug_level));
2296         }
2297         
2298         return ret;
2299 }