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