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