2 * Auditing VFS module for samba. Log selected file operations to syslog
5 * Copyright (C) Tim Potter, 1999-2000
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
40 #ifndef SYSLOG_FACILITY
41 #define SYSLOG_FACILITY LOG_USER
44 #ifndef SYSLOG_PRIORITY
45 #define SYSLOG_PRIORITY LOG_NOTICE
48 /* Function prototypes */
50 int audit_connect(struct connection_struct *conn, const char *svc, const char *user);
51 void audit_disconnect(struct connection_struct *conn);
52 DIR *audit_opendir(struct connection_struct *conn, const char *fname);
53 int audit_mkdir(struct connection_struct *conn, const char *path, mode_t mode);
54 int audit_rmdir(struct connection_struct *conn, const char *path);
55 int audit_open(struct connection_struct *conn, const char *fname, int flags, mode_t mode);
56 int audit_close(struct files_struct *fsp, int fd);
57 int audit_rename(struct connection_struct *conn, const char *old, const char *new);
58 int audit_unlink(struct connection_struct *conn, const char *path);
59 int audit_chmod(struct connection_struct *conn, const char *path, mode_t mode);
60 int audit_chmod_acl(struct connection_struct *conn, const char *name, mode_t mode);
61 int audit_fchmod(struct files_struct *fsp, int fd, mode_t mode);
62 int audit_fchmod_acl(struct files_struct *fsp, int fd, mode_t mode);
66 extern struct vfs_ops default_vfs_ops; /* For passthrough operation */
68 struct vfs_ops audit_ops = {
76 /* Directory operations */
104 NULL, /* ftruncate */
111 NULL, /* fget_nt_acl */
112 NULL, /* get_nt_acl */
113 NULL, /* fset_nt_acl */
114 NULL, /* set_nt_acl */
116 audit_chmod_acl, /* chmod_acl */
117 audit_fchmod_acl, /* fchmod_acl */
119 NULL, /* sys_acl_get_entry */
120 NULL, /* sys_acl_get_tag_type */
121 NULL, /* sys_acl_get_permset */
122 NULL, /*sys_acl_get_qualifier */
123 NULL, /* sys_acl_get_file */
124 NULL, /* sys_acl_get_fd */
125 NULL, /* sys_acl_clear_perms */
126 NULL, /* sys_acl_add_perm */
127 NULL, /* sys_acl_to_text */
128 NULL, /* sys_acl_init */
129 NULL, /* sys_acl_create_entry */
130 NULL, /* sys_acl_set_tag_type */
131 NULL, /* sys_acl_set_qualifier */
132 NULL, /* sys_acl_set_permset */
133 NULL, /* sys_acl_valid */
134 NULL, /* sys_acl_set_file */
135 NULL, /* sys_acl_set_fd */
136 NULL, /* sys_acl_delete_def_file */
137 NULL, /* sys_acl_get_perm */
138 NULL, /* sys_acl_free_text */
139 NULL, /* sys_acl_free_acl */
140 NULL /* sys_acl_free_qualifier */
143 /* VFS initialisation function. Return initialised vfs_ops structure
146 struct vfs_ops *vfs_init(int *vfs_version, struct vfs_ops *def_vfs_ops)
148 struct vfs_ops tmp_ops;
150 *vfs_version = SMB_VFS_INTERFACE_VERSION;
151 memcpy(&tmp_ops, def_vfs_ops, sizeof(struct vfs_ops));
153 tmp_ops.connect = audit_connect;
154 tmp_ops.disconnect = audit_disconnect;
155 tmp_ops.opendir = audit_opendir;
156 tmp_ops.mkdir = audit_mkdir;
157 tmp_ops.rmdir = audit_rmdir;
158 tmp_ops.open = audit_open;
159 tmp_ops.close = audit_close;
160 tmp_ops.rename = audit_rename;
161 tmp_ops.unlink = audit_unlink;
162 tmp_ops.chmod = audit_chmod;
163 tmp_ops.chmod_acl = audit_chmod_acl;
164 tmp_ops.fchmod = audit_fchmod;
165 tmp_ops.fchmod_acl = audit_fchmod_acl;
167 memcpy(&audit_ops, &tmp_ops, sizeof(struct vfs_ops));
169 openlog("smbd_audit", LOG_PID, SYSLOG_FACILITY);
170 syslog(SYSLOG_PRIORITY, "VFS_INIT: vfs_ops loaded\n");
174 /* Implementation of vfs_ops. Pass everything on to the default
175 operation but log event first. */
177 int audit_connect(struct connection_struct *conn, const char *svc, const char *user)
179 syslog(SYSLOG_PRIORITY, "connect to service %s by user %s\n",
182 return default_vfs_ops.connect(conn, svc, user);
185 void audit_disconnect(struct connection_struct *conn)
187 syslog(SYSLOG_PRIORITY, "disconnected\n");
188 default_vfs_ops.disconnect(conn);
191 DIR *audit_opendir(struct connection_struct *conn, const char *fname)
193 DIR *result = default_vfs_ops.opendir(conn, fname);
195 syslog(SYSLOG_PRIORITY, "opendir %s %s%s\n",
197 (result == NULL) ? "failed: " : "",
198 (result == NULL) ? strerror(errno) : "");
203 int audit_mkdir(struct connection_struct *conn, const char *path, mode_t mode)
205 int result = default_vfs_ops.mkdir(conn, path, mode);
207 syslog(SYSLOG_PRIORITY, "mkdir %s %s%s\n",
209 (result < 0) ? "failed: " : "",
210 (result < 0) ? strerror(errno) : "");
215 int audit_rmdir(struct connection_struct *conn, const char *path)
217 int result = default_vfs_ops.rmdir(conn, path);
219 syslog(SYSLOG_PRIORITY, "rmdir %s %s%s\n",
221 (result < 0) ? "failed: " : "",
222 (result < 0) ? strerror(errno) : "");
227 int audit_open(struct connection_struct *conn, const char *fname, int flags, mode_t mode)
229 int result = default_vfs_ops.open(conn, fname, flags, mode);
231 syslog(SYSLOG_PRIORITY, "open %s (fd %d) %s%s%s\n",
233 ((flags & O_WRONLY) || (flags & O_RDWR)) ? "for writing " : "",
234 (result < 0) ? "failed: " : "",
235 (result < 0) ? strerror(errno) : "");
240 int audit_close(struct files_struct *fsp, int fd)
242 int result = default_vfs_ops.close(fsp, fd);
244 syslog(SYSLOG_PRIORITY, "close fd %d %s%s\n",
246 (result < 0) ? "failed: " : "",
247 (result < 0) ? strerror(errno) : "");
252 int audit_rename(struct connection_struct *conn, const char *old, const char *new)
254 int result = default_vfs_ops.rename(conn, old, new);
256 syslog(SYSLOG_PRIORITY, "rename %s -> %s %s%s\n",
258 (result < 0) ? "failed: " : "",
259 (result < 0) ? strerror(errno) : "");
264 int audit_unlink(struct connection_struct *conn, const char *path)
266 int result = default_vfs_ops.unlink(conn, path);
268 syslog(SYSLOG_PRIORITY, "unlink %s %s%s\n",
270 (result < 0) ? "failed: " : "",
271 (result < 0) ? strerror(errno) : "");
276 int audit_chmod(struct connection_struct *conn, const char *path, mode_t mode)
278 int result = default_vfs_ops.chmod(conn, path, mode);
280 syslog(SYSLOG_PRIORITY, "chmod %s mode 0x%x %s%s\n",
282 (result < 0) ? "failed: " : "",
283 (result < 0) ? strerror(errno) : "");
288 int audit_chmod_acl(struct connection_struct *conn, const char *path, mode_t mode)
290 int result = default_vfs_ops.chmod_acl(conn, path, mode);
292 syslog(SYSLOG_PRIORITY, "chmod_acl %s mode 0x%x %s%s\n",
294 (result < 0) ? "failed: " : "",
295 (result < 0) ? strerror(errno) : "");
300 int audit_fchmod(struct files_struct *fsp, int fd, mode_t mode)
302 int result = default_vfs_ops.fchmod(fsp, fd, mode);
304 syslog(SYSLOG_PRIORITY, "fchmod %s mode 0x%x %s%s\n",
306 (result < 0) ? "failed: " : "",
307 (result < 0) ? strerror(errno) : "");
312 int audit_fchmod_acl(struct files_struct *fsp, int fd, mode_t mode)
314 int result = default_vfs_ops.fchmod_acl(fsp, fd, mode);
316 syslog(SYSLOG_PRIORITY, "fchmod_acl %s mode 0x%x %s%s\n",
318 (result < 0) ? "failed: " : "",
319 (result < 0) ? strerror(errno) : "");