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