2 * Auditing VFS module for samba. Log selected file operations to syslog
5 * Copyright (C) Tim Potter, 1999-2001
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 static struct vfs_ops default_vfs_ops
;
50 /* Implementation of vfs_ops. Pass everything on to the default
51 operation but log event first. */
53 static int audit_connect(struct connection_struct
*conn
, const char *svc
,
56 syslog(SYSLOG_PRIORITY
, "connect to service %s by user %s\n",
59 return 0; /* Success */
62 static void audit_disconnect(struct connection_struct
*conn
)
64 syslog(SYSLOG_PRIORITY
, "disconnected\n");
67 static DIR *audit_opendir(struct connection_struct
*conn
, const char *fname
)
69 DIR *result
= default_vfs_ops
.opendir(conn
, fname
);
71 syslog(SYSLOG_PRIORITY
, "opendir %s %s%s\n",
73 (result
== NULL
) ? "failed: " : "",
74 (result
== NULL
) ? strerror(errno
) : "");
79 static int audit_mkdir(struct connection_struct
*conn
, const char *path
,
82 int result
= default_vfs_ops
.mkdir(conn
, path
, mode
);
84 syslog(SYSLOG_PRIORITY
, "mkdir %s %s%s\n",
86 (result
< 0) ? "failed: " : "",
87 (result
< 0) ? strerror(errno
) : "");
92 static int audit_rmdir(struct connection_struct
*conn
, const char *path
)
94 int result
= default_vfs_ops
.rmdir(conn
, path
);
96 syslog(SYSLOG_PRIORITY
, "rmdir %s %s%s\n",
98 (result
< 0) ? "failed: " : "",
99 (result
< 0) ? strerror(errno
) : "");
104 static int audit_open(struct connection_struct
*conn
, const char *fname
,
105 int flags
, mode_t mode
)
107 int result
= default_vfs_ops
.open(conn
, fname
, flags
, mode
);
109 syslog(SYSLOG_PRIORITY
, "open %s (fd %d) %s%s%s\n",
111 ((flags
& O_WRONLY
) || (flags
& O_RDWR
)) ? "for writing " : "",
112 (result
< 0) ? "failed: " : "",
113 (result
< 0) ? strerror(errno
) : "");
118 static int audit_close(struct files_struct
*fsp
, int fd
)
120 int result
= default_vfs_ops
.close(fsp
, fd
);
122 syslog(SYSLOG_PRIORITY
, "close fd %d %s%s\n",
124 (result
< 0) ? "failed: " : "",
125 (result
< 0) ? strerror(errno
) : "");
130 static int audit_rename(struct connection_struct
*conn
, const char *old
,
133 int result
= default_vfs_ops
.rename(conn
, old
, new);
135 syslog(SYSLOG_PRIORITY
, "rename %s -> %s %s%s\n",
137 (result
< 0) ? "failed: " : "",
138 (result
< 0) ? strerror(errno
) : "");
143 static int audit_unlink(struct connection_struct
*conn
, const char *path
)
145 int result
= default_vfs_ops
.unlink(conn
, path
);
147 syslog(SYSLOG_PRIORITY
, "unlink %s %s%s\n",
149 (result
< 0) ? "failed: " : "",
150 (result
< 0) ? strerror(errno
) : "");
155 static int audit_chmod(struct connection_struct
*conn
, const char *path
,
158 int result
= default_vfs_ops
.chmod(conn
, path
, mode
);
160 syslog(SYSLOG_PRIORITY
, "chmod %s mode 0x%x %s%s\n",
162 (result
< 0) ? "failed: " : "",
163 (result
< 0) ? strerror(errno
) : "");
168 /* VFS initialisation function. Return initialised vfs_ops structure
171 struct vfs_ops
*vfs_init(int *vfs_version
, struct vfs_ops
*ops
)
173 *vfs_version
= SMB_VFS_INTERFACE_VERSION
;
175 openlog("smbd_audit", LOG_PID
, SYSLOG_FACILITY
);
176 syslog(SYSLOG_PRIORITY
, "initialised\n");
178 /* Save a copy of the default ops */
180 default_vfs_ops
= *ops
;
182 /* Override our ones */
184 ops
->connect
= audit_connect
;
185 ops
->disconnect
= audit_disconnect
;
186 ops
->opendir
= audit_opendir
;
187 ops
->mkdir
= audit_mkdir
;
188 ops
->rmdir
= audit_rmdir
;
189 ops
->open
= audit_open
;
190 ops
->close
= audit_close
;
191 ops
->rename
= audit_rename
;
192 ops
->unlink
= audit_unlink
;
193 ops
->chmod
= audit_chmod
;