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