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