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