2 * Auditing VFS module for samba. Log selected file operations to syslog
5 * Copyright (C) Tim Potter 1999-2000
6 * Copyright (C) Alexander Bokovoy 2002
7 * Copyright (C) Stefan (metze) Metzmacher 2002
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, see <http://www.gnu.org/licenses/>.
25 #include "system/filesys.h"
26 #include "system/syslog.h"
27 #include "smbd/smbd.h"
28 #include "lib/param/loadparm.h"
31 #define DBGC_CLASS DBGC_VFS
33 static int audit_syslog_facility(vfs_handle_struct
*handle
)
35 static const struct enum_list enum_log_facilities
[] = {
37 { LOG_LOCAL0
, "LOCAL0" },
38 { LOG_LOCAL1
, "LOCAL1" },
39 { LOG_LOCAL2
, "LOCAL2" },
40 { LOG_LOCAL3
, "LOCAL3" },
41 { LOG_LOCAL4
, "LOCAL4" },
42 { LOG_LOCAL5
, "LOCAL5" },
43 { LOG_LOCAL6
, "LOCAL6" },
44 { LOG_LOCAL7
, "LOCAL7" },
50 facility
= lp_parm_enum(SNUM(handle
->conn
), "audit", "facility", enum_log_facilities
, LOG_USER
);
56 static int audit_syslog_priority(vfs_handle_struct
*handle
)
58 static const struct enum_list enum_log_priorities
[] = {
59 { LOG_EMERG
, "EMERG" },
60 { LOG_ALERT
, "ALERT" },
63 { LOG_WARNING
, "WARNING" },
64 { LOG_NOTICE
, "NOTICE" },
66 { LOG_DEBUG
, "DEBUG" },
72 priority
= lp_parm_enum(SNUM(handle
->conn
), "audit", "priority",
73 enum_log_priorities
, LOG_NOTICE
);
75 priority
= LOG_WARNING
;
81 /* Implementation of vfs_ops. Pass everything on to the default
82 operation but log event first. */
84 static int audit_connect(vfs_handle_struct
*handle
, const char *svc
, const char *user
)
88 result
= SMB_VFS_NEXT_CONNECT(handle
, svc
, user
);
93 openlog("smbd_audit", LOG_PID
, audit_syslog_facility(handle
));
95 syslog(audit_syslog_priority(handle
), "connect to service %s by user %s\n",
101 static void audit_disconnect(vfs_handle_struct
*handle
)
103 syslog(audit_syslog_priority(handle
), "disconnected\n");
104 SMB_VFS_NEXT_DISCONNECT(handle
);
109 static DIR *audit_opendir(vfs_handle_struct
*handle
,
110 const struct smb_filename
*smb_fname
,
116 result
= SMB_VFS_NEXT_OPENDIR(handle
, smb_fname
, mask
, attr
);
118 syslog(audit_syslog_priority(handle
), "opendir %s %s%s\n",
119 smb_fname
->base_name
,
120 (result
== NULL
) ? "failed: " : "",
121 (result
== NULL
) ? strerror(errno
) : "");
126 static int audit_mkdir(vfs_handle_struct
*handle
,
127 const struct smb_filename
*smb_fname
,
132 result
= SMB_VFS_NEXT_MKDIR(handle
, smb_fname
, mode
);
134 syslog(audit_syslog_priority(handle
), "mkdir %s %s%s\n",
135 smb_fname
->base_name
,
136 (result
< 0) ? "failed: " : "",
137 (result
< 0) ? strerror(errno
) : "");
142 static int audit_rmdir(vfs_handle_struct
*handle
,
143 const struct smb_filename
*smb_fname
)
147 result
= SMB_VFS_NEXT_RMDIR(handle
, smb_fname
);
149 syslog(audit_syslog_priority(handle
), "rmdir %s %s%s\n",
150 smb_fname
->base_name
,
151 (result
< 0) ? "failed: " : "",
152 (result
< 0) ? strerror(errno
) : "");
157 static int audit_open(vfs_handle_struct
*handle
,
158 struct smb_filename
*smb_fname
, files_struct
*fsp
,
159 int flags
, mode_t mode
)
163 result
= SMB_VFS_NEXT_OPEN(handle
, smb_fname
, fsp
, flags
, mode
);
165 syslog(audit_syslog_priority(handle
), "open %s (fd %d) %s%s%s\n",
166 smb_fname
->base_name
, result
,
167 ((flags
& O_WRONLY
) || (flags
& O_RDWR
)) ? "for writing " : "",
168 (result
< 0) ? "failed: " : "",
169 (result
< 0) ? strerror(errno
) : "");
174 static int audit_close(vfs_handle_struct
*handle
, files_struct
*fsp
)
178 result
= SMB_VFS_NEXT_CLOSE(handle
, fsp
);
180 syslog(audit_syslog_priority(handle
), "close fd %d %s%s\n",
182 (result
< 0) ? "failed: " : "",
183 (result
< 0) ? strerror(errno
) : "");
188 static int audit_rename(vfs_handle_struct
*handle
,
189 const struct smb_filename
*smb_fname_src
,
190 const struct smb_filename
*smb_fname_dst
)
194 result
= SMB_VFS_NEXT_RENAME(handle
, smb_fname_src
, smb_fname_dst
);
196 syslog(audit_syslog_priority(handle
), "rename %s -> %s %s%s\n",
197 smb_fname_src
->base_name
,
198 smb_fname_dst
->base_name
,
199 (result
< 0) ? "failed: " : "",
200 (result
< 0) ? strerror(errno
) : "");
205 static int audit_unlink(vfs_handle_struct
*handle
,
206 const struct smb_filename
*smb_fname
)
210 result
= SMB_VFS_NEXT_UNLINK(handle
, smb_fname
);
212 syslog(audit_syslog_priority(handle
), "unlink %s %s%s\n",
213 smb_fname
->base_name
,
214 (result
< 0) ? "failed: " : "",
215 (result
< 0) ? strerror(errno
) : "");
220 static int audit_chmod(vfs_handle_struct
*handle
,
221 const struct smb_filename
*smb_fname
,
226 result
= SMB_VFS_NEXT_CHMOD(handle
, smb_fname
, mode
);
228 syslog(audit_syslog_priority(handle
), "chmod %s mode 0x%x %s%s\n",
229 smb_fname
->base_name
, mode
,
230 (result
< 0) ? "failed: " : "",
231 (result
< 0) ? strerror(errno
) : "");
236 static int audit_chmod_acl(vfs_handle_struct
*handle
,
237 const struct smb_filename
*smb_fname
,
242 result
= SMB_VFS_NEXT_CHMOD_ACL(handle
, smb_fname
, mode
);
244 syslog(audit_syslog_priority(handle
), "chmod_acl %s mode 0x%x %s%s\n",
245 smb_fname
->base_name
, mode
,
246 (result
< 0) ? "failed: " : "",
247 (result
< 0) ? strerror(errno
) : "");
252 static int audit_fchmod(vfs_handle_struct
*handle
, files_struct
*fsp
, mode_t mode
)
256 result
= SMB_VFS_NEXT_FCHMOD(handle
, fsp
, mode
);
258 syslog(audit_syslog_priority(handle
), "fchmod %s mode 0x%x %s%s\n",
259 fsp
->fsp_name
->base_name
, mode
,
260 (result
< 0) ? "failed: " : "",
261 (result
< 0) ? strerror(errno
) : "");
266 static int audit_fchmod_acl(vfs_handle_struct
*handle
, files_struct
*fsp
, mode_t mode
)
270 result
= SMB_VFS_NEXT_FCHMOD_ACL(handle
, fsp
, mode
);
272 syslog(audit_syslog_priority(handle
), "fchmod_acl %s mode 0x%x %s%s\n",
273 fsp
->fsp_name
->base_name
, mode
,
274 (result
< 0) ? "failed: " : "",
275 (result
< 0) ? strerror(errno
) : "");
280 static struct vfs_fn_pointers vfs_audit_fns
= {
281 .connect_fn
= audit_connect
,
282 .disconnect_fn
= audit_disconnect
,
283 .opendir_fn
= audit_opendir
,
284 .mkdir_fn
= audit_mkdir
,
285 .rmdir_fn
= audit_rmdir
,
286 .open_fn
= audit_open
,
287 .close_fn
= audit_close
,
288 .rename_fn
= audit_rename
,
289 .unlink_fn
= audit_unlink
,
290 .chmod_fn
= audit_chmod
,
291 .fchmod_fn
= audit_fchmod
,
292 .chmod_acl_fn
= audit_chmod_acl
,
293 .fchmod_acl_fn
= audit_fchmod_acl
297 NTSTATUS
vfs_audit_init(void)
299 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION
, "audit",