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