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