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) Stefan (metze) Metzmacher 2002
|
---|
8 | *
|
---|
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.
|
---|
13 | *
|
---|
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.
|
---|
18 | *
|
---|
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/>.
|
---|
21 | */
|
---|
22 |
|
---|
23 |
|
---|
24 | #include "includes.h"
|
---|
25 |
|
---|
26 | #undef DBGC_CLASS
|
---|
27 | #define DBGC_CLASS DBGC_VFS
|
---|
28 |
|
---|
29 | static int audit_syslog_facility(vfs_handle_struct *handle)
|
---|
30 | {
|
---|
31 | static const struct enum_list enum_log_facilities[] = {
|
---|
32 | { LOG_USER, "USER" },
|
---|
33 | { LOG_LOCAL0, "LOCAL0" },
|
---|
34 | { LOG_LOCAL1, "LOCAL1" },
|
---|
35 | { LOG_LOCAL2, "LOCAL2" },
|
---|
36 | { LOG_LOCAL3, "LOCAL3" },
|
---|
37 | { LOG_LOCAL4, "LOCAL4" },
|
---|
38 | { LOG_LOCAL5, "LOCAL5" },
|
---|
39 | { LOG_LOCAL6, "LOCAL6" },
|
---|
40 | { LOG_LOCAL7, "LOCAL7" }
|
---|
41 | };
|
---|
42 |
|
---|
43 | int facility;
|
---|
44 |
|
---|
45 | facility = lp_parm_enum(SNUM(handle->conn), "audit", "facility", enum_log_facilities, LOG_USER);
|
---|
46 |
|
---|
47 | return facility;
|
---|
48 | }
|
---|
49 |
|
---|
50 |
|
---|
51 | static int audit_syslog_priority(vfs_handle_struct *handle)
|
---|
52 | {
|
---|
53 | static const struct enum_list enum_log_priorities[] = {
|
---|
54 | { LOG_EMERG, "EMERG" },
|
---|
55 | { LOG_ALERT, "ALERT" },
|
---|
56 | { LOG_CRIT, "CRIT" },
|
---|
57 | { LOG_ERR, "ERR" },
|
---|
58 | { LOG_WARNING, "WARNING" },
|
---|
59 | { LOG_NOTICE, "NOTICE" },
|
---|
60 | { LOG_INFO, "INFO" },
|
---|
61 | { LOG_DEBUG, "DEBUG" }
|
---|
62 | };
|
---|
63 |
|
---|
64 | int priority;
|
---|
65 |
|
---|
66 | priority = lp_parm_enum(SNUM(handle->conn), "audit", "priority",
|
---|
67 | enum_log_priorities, LOG_NOTICE);
|
---|
68 | if (priority == -1) {
|
---|
69 | priority = LOG_WARNING;
|
---|
70 | }
|
---|
71 |
|
---|
72 | return priority;
|
---|
73 | }
|
---|
74 |
|
---|
75 | /* Implementation of vfs_ops. Pass everything on to the default
|
---|
76 | operation but log event first. */
|
---|
77 |
|
---|
78 | static int audit_connect(vfs_handle_struct *handle, const char *svc, const char *user)
|
---|
79 | {
|
---|
80 | int result;
|
---|
81 |
|
---|
82 | result = SMB_VFS_NEXT_CONNECT(handle, svc, user);
|
---|
83 | if (result < 0) {
|
---|
84 | return result;
|
---|
85 | }
|
---|
86 |
|
---|
87 | openlog("smbd_audit", LOG_PID, audit_syslog_facility(handle));
|
---|
88 |
|
---|
89 | syslog(audit_syslog_priority(handle), "connect to service %s by user %s\n",
|
---|
90 | svc, user);
|
---|
91 |
|
---|
92 | return 0;
|
---|
93 | }
|
---|
94 |
|
---|
95 | static void audit_disconnect(vfs_handle_struct *handle)
|
---|
96 | {
|
---|
97 | syslog(audit_syslog_priority(handle), "disconnected\n");
|
---|
98 | SMB_VFS_NEXT_DISCONNECT(handle);
|
---|
99 |
|
---|
100 | return;
|
---|
101 | }
|
---|
102 |
|
---|
103 | static SMB_STRUCT_DIR *audit_opendir(vfs_handle_struct *handle, const char *fname, const char *mask, uint32 attr)
|
---|
104 | {
|
---|
105 | SMB_STRUCT_DIR *result;
|
---|
106 |
|
---|
107 | result = SMB_VFS_NEXT_OPENDIR(handle, fname, mask, attr);
|
---|
108 |
|
---|
109 | syslog(audit_syslog_priority(handle), "opendir %s %s%s\n",
|
---|
110 | fname,
|
---|
111 | (result == NULL) ? "failed: " : "",
|
---|
112 | (result == NULL) ? strerror(errno) : "");
|
---|
113 |
|
---|
114 | return result;
|
---|
115 | }
|
---|
116 |
|
---|
117 | static int audit_mkdir(vfs_handle_struct *handle, const char *path, mode_t mode)
|
---|
118 | {
|
---|
119 | int result;
|
---|
120 |
|
---|
121 | result = SMB_VFS_NEXT_MKDIR(handle, path, mode);
|
---|
122 |
|
---|
123 | syslog(audit_syslog_priority(handle), "mkdir %s %s%s\n",
|
---|
124 | path,
|
---|
125 | (result < 0) ? "failed: " : "",
|
---|
126 | (result < 0) ? strerror(errno) : "");
|
---|
127 |
|
---|
128 | return result;
|
---|
129 | }
|
---|
130 |
|
---|
131 | static int audit_rmdir(vfs_handle_struct *handle, const char *path)
|
---|
132 | {
|
---|
133 | int result;
|
---|
134 |
|
---|
135 | result = SMB_VFS_NEXT_RMDIR(handle, path);
|
---|
136 |
|
---|
137 | syslog(audit_syslog_priority(handle), "rmdir %s %s%s\n",
|
---|
138 | path,
|
---|
139 | (result < 0) ? "failed: " : "",
|
---|
140 | (result < 0) ? strerror(errno) : "");
|
---|
141 |
|
---|
142 | return result;
|
---|
143 | }
|
---|
144 |
|
---|
145 | static int audit_open(vfs_handle_struct *handle,
|
---|
146 | struct smb_filename *smb_fname, files_struct *fsp,
|
---|
147 | int flags, mode_t mode)
|
---|
148 | {
|
---|
149 | int result;
|
---|
150 |
|
---|
151 | result = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
|
---|
152 |
|
---|
153 | syslog(audit_syslog_priority(handle), "open %s (fd %d) %s%s%s\n",
|
---|
154 | smb_fname->base_name, result,
|
---|
155 | ((flags & O_WRONLY) || (flags & O_RDWR)) ? "for writing " : "",
|
---|
156 | (result < 0) ? "failed: " : "",
|
---|
157 | (result < 0) ? strerror(errno) : "");
|
---|
158 |
|
---|
159 | return result;
|
---|
160 | }
|
---|
161 |
|
---|
162 | static int audit_close(vfs_handle_struct *handle, files_struct *fsp)
|
---|
163 | {
|
---|
164 | int result;
|
---|
165 |
|
---|
166 | result = SMB_VFS_NEXT_CLOSE(handle, fsp);
|
---|
167 |
|
---|
168 | syslog(audit_syslog_priority(handle), "close fd %d %s%s\n",
|
---|
169 | fsp->fh->fd,
|
---|
170 | (result < 0) ? "failed: " : "",
|
---|
171 | (result < 0) ? strerror(errno) : "");
|
---|
172 |
|
---|
173 | return result;
|
---|
174 | }
|
---|
175 |
|
---|
176 | static int audit_rename(vfs_handle_struct *handle,
|
---|
177 | const struct smb_filename *smb_fname_src,
|
---|
178 | const struct smb_filename *smb_fname_dst)
|
---|
179 | {
|
---|
180 | int result;
|
---|
181 |
|
---|
182 | result = SMB_VFS_NEXT_RENAME(handle, smb_fname_src, smb_fname_dst);
|
---|
183 |
|
---|
184 | syslog(audit_syslog_priority(handle), "rename %s -> %s %s%s\n",
|
---|
185 | smb_fname_src->base_name,
|
---|
186 | smb_fname_dst->base_name,
|
---|
187 | (result < 0) ? "failed: " : "",
|
---|
188 | (result < 0) ? strerror(errno) : "");
|
---|
189 |
|
---|
190 | return result;
|
---|
191 | }
|
---|
192 |
|
---|
193 | static int audit_unlink(vfs_handle_struct *handle,
|
---|
194 | const struct smb_filename *smb_fname)
|
---|
195 | {
|
---|
196 | int result;
|
---|
197 |
|
---|
198 | result = SMB_VFS_NEXT_UNLINK(handle, smb_fname);
|
---|
199 |
|
---|
200 | syslog(audit_syslog_priority(handle), "unlink %s %s%s\n",
|
---|
201 | smb_fname->base_name,
|
---|
202 | (result < 0) ? "failed: " : "",
|
---|
203 | (result < 0) ? strerror(errno) : "");
|
---|
204 |
|
---|
205 | return result;
|
---|
206 | }
|
---|
207 |
|
---|
208 | static int audit_chmod(vfs_handle_struct *handle, const char *path, mode_t mode)
|
---|
209 | {
|
---|
210 | int result;
|
---|
211 |
|
---|
212 | result = SMB_VFS_NEXT_CHMOD(handle, path, mode);
|
---|
213 |
|
---|
214 | syslog(audit_syslog_priority(handle), "chmod %s mode 0x%x %s%s\n",
|
---|
215 | path, mode,
|
---|
216 | (result < 0) ? "failed: " : "",
|
---|
217 | (result < 0) ? strerror(errno) : "");
|
---|
218 |
|
---|
219 | return result;
|
---|
220 | }
|
---|
221 |
|
---|
222 | static int audit_chmod_acl(vfs_handle_struct *handle, const char *path, mode_t mode)
|
---|
223 | {
|
---|
224 | int result;
|
---|
225 |
|
---|
226 | result = SMB_VFS_NEXT_CHMOD_ACL(handle, path, mode);
|
---|
227 |
|
---|
228 | syslog(audit_syslog_priority(handle), "chmod_acl %s mode 0x%x %s%s\n",
|
---|
229 | path, mode,
|
---|
230 | (result < 0) ? "failed: " : "",
|
---|
231 | (result < 0) ? strerror(errno) : "");
|
---|
232 |
|
---|
233 | return result;
|
---|
234 | }
|
---|
235 |
|
---|
236 | static int audit_fchmod(vfs_handle_struct *handle, files_struct *fsp, mode_t mode)
|
---|
237 | {
|
---|
238 | int result;
|
---|
239 |
|
---|
240 | result = SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
|
---|
241 |
|
---|
242 | syslog(audit_syslog_priority(handle), "fchmod %s mode 0x%x %s%s\n",
|
---|
243 | fsp->fsp_name->base_name, mode,
|
---|
244 | (result < 0) ? "failed: " : "",
|
---|
245 | (result < 0) ? strerror(errno) : "");
|
---|
246 |
|
---|
247 | return result;
|
---|
248 | }
|
---|
249 |
|
---|
250 | static int audit_fchmod_acl(vfs_handle_struct *handle, files_struct *fsp, mode_t mode)
|
---|
251 | {
|
---|
252 | int result;
|
---|
253 |
|
---|
254 | result = SMB_VFS_NEXT_FCHMOD_ACL(handle, fsp, mode);
|
---|
255 |
|
---|
256 | syslog(audit_syslog_priority(handle), "fchmod_acl %s mode 0x%x %s%s\n",
|
---|
257 | fsp->fsp_name->base_name, mode,
|
---|
258 | (result < 0) ? "failed: " : "",
|
---|
259 | (result < 0) ? strerror(errno) : "");
|
---|
260 |
|
---|
261 | return result;
|
---|
262 | }
|
---|
263 |
|
---|
264 | static struct vfs_fn_pointers vfs_audit_fns = {
|
---|
265 | .connect_fn = audit_connect,
|
---|
266 | .disconnect = audit_disconnect,
|
---|
267 | .opendir = audit_opendir,
|
---|
268 | .mkdir = audit_mkdir,
|
---|
269 | .rmdir = audit_rmdir,
|
---|
270 | .open = audit_open,
|
---|
271 | .close_fn = audit_close,
|
---|
272 | .rename = audit_rename,
|
---|
273 | .unlink = audit_unlink,
|
---|
274 | .chmod = audit_chmod,
|
---|
275 | .fchmod = audit_fchmod,
|
---|
276 | .chmod_acl = audit_chmod_acl,
|
---|
277 | .fchmod_acl = audit_fchmod_acl
|
---|
278 | };
|
---|
279 |
|
---|
280 | NTSTATUS vfs_audit_init(void)
|
---|
281 | {
|
---|
282 | return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "audit",
|
---|
283 | &vfs_audit_fns);
|
---|
284 | }
|
---|