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