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