2 * Auditing VFS module for samba. Log select 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.
21 * $Id: audit.c,v 1.2 2000/02/04 05:08:16 tpot Exp $
41 #ifndef SYSLOG_FACILITY
42 #define SYSLOG_FACILITY LOG_USER
45 #ifndef SYSLOG_PRIORITY
46 #define SYSLOG_PRIORITY LOG_NOTICE
49 /* Function prototypes */
51 int audit_connect(struct vfs_connection_struct
*conn
, char *svc
, char *user
);
52 void audit_disconnect(void);
53 DIR *audit_opendir(char *fname
);
54 int audit_mkdir(char *path
, mode_t mode
);
55 int audit_rmdir(char *path
);
56 int audit_open(char *fname
, int flags
, mode_t mode
);
57 int audit_close(int fd
);
58 int audit_rename(char *old
, char *new);
59 int audit_unlink(char *path
);
60 int audit_chmod(char *path
, mode_t mode
);
64 extern struct vfs_ops default_vfs_ops
; /* For passthrough operation */
66 struct vfs_ops audit_ops
= {
74 /* Directory operations */
99 /* VFS initialisation function. Return initialised vfs_ops structure
102 struct vfs_ops
*vfs_init(void)
104 openlog("smbd_audit", LOG_PID
, SYSLOG_FACILITY
);
108 /* Implementation of vfs_ops. Pass everything on to the default
109 operation but log event first. */
111 int audit_connect(struct vfs_connection_struct
*conn
, char *svc
, char *user
)
113 syslog(SYSLOG_PRIORITY
, "connect to service %s by user %s\n", svc
, user
);
115 return default_vfs_ops
.connect(conn
, svc
, user
);
118 void audit_disconnect(void)
120 syslog(SYSLOG_PRIORITY
, "disconnected\n");
121 default_vfs_ops
.disconnect();
124 DIR *audit_opendir(char *fname
)
126 DIR *result
= default_vfs_ops
.opendir(fname
);
128 syslog(SYSLOG_PRIORITY
, "opendir %s %s%s\n",
130 (result
== NULL
) ? "failed: " : "",
131 (result
== NULL
) ? strerror(errno
) : "");
136 int audit_mkdir(char *path
, mode_t mode
)
138 int result
= default_vfs_ops
.mkdir(path
, mode
);
140 syslog(SYSLOG_PRIORITY
, "mkdir %s %s%s\n",
142 (result
< 0) ? "failed: " : "",
143 (result
< 0) ? strerror(errno
) : "");
148 int audit_rmdir(char *path
)
150 int result
= default_vfs_ops
.rmdir(path
);
152 syslog(SYSLOG_PRIORITY
, "rmdir %s %s%s\n",
154 (result
< 0) ? "failed: " : "",
155 (result
< 0) ? strerror(errno
) : "");
160 int audit_open(char *fname
, int flags
, mode_t mode
)
162 int result
= default_vfs_ops
.open(fname
, flags
, mode
);
164 syslog(SYSLOG_PRIORITY
, "open %s (fd %d) %s%s%s\n",
166 ((flags
& O_WRONLY
) || (flags
& O_RDWR
)) ? "for writing " : "",
167 (result
< 0) ? "failed: " : "",
168 (result
< 0) ? strerror(errno
) : "");
173 int audit_close(int fd
)
175 int result
= default_vfs_ops
.close(fd
);
177 syslog(SYSLOG_PRIORITY
, "close fd %d %s%s\n",
179 (result
< 0) ? "failed: " : "",
180 (result
< 0) ? strerror(errno
) : "");
185 int audit_rename(char *old
, char *new)
187 int result
= default_vfs_ops
.rename(old
, new);
189 syslog(SYSLOG_PRIORITY
, "rename %s -> %s %s%s\n",
191 (result
< 0) ? "failed: " : "",
192 (result
< 0) ? strerror(errno
) : "");
197 int audit_unlink(char *path
)
199 int result
= default_vfs_ops
.unlink(path
);
201 syslog(SYSLOG_PRIORITY
, "unlink %s %s%s\n",
203 (result
< 0) ? "failed: " : "",
204 (result
< 0) ? strerror(errno
) : "");