2
* audispd-builtins.c - some common builtin plugins
3
* Copyright (c) 2007 Red Hat Inc., Durham, North Carolina.
6
* This software may be freely redistributed and/or modified under the
7
* terms of the GNU General Public License as published by the Free
8
* Software Foundation; either version 2, or (at your option) any
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; see the file COPYING. If not, write to the
18
* Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21
* Steve Grubb <sgrubb@redhat.com>
35
#include "audispd-pconfig.h"
36
#include "audispd-builtins.h"
39
static int sock = -1, conn = -1;
40
static int syslog_started = 0, priority;
41
static char *path = NULL;
44
static void init_af_unix(const plugin_conf_t *conf);
45
static void init_syslog(const plugin_conf_t *conf);
48
void start_builtin(plugin_conf_t *conf)
50
if (strcasecmp("builtin_af_unix", conf->path) == 0)
52
else if (strcasecmp("builtin_syslog", conf->path) == 0)
55
syslog(LOG_ERR, "Unknown builtin %s", conf->path);
58
static void init_af_unix(const plugin_conf_t *conf)
64
while (conf->args[i]) {
67
// is all nums - do mode
70
if (!isdigit(*base)) {
78
mode = strtoul(conf->args[i], NULL, 8);
80
syslog(LOG_ERR, "Error converting %s (%s)",
81
conf->args[i], strerror(errno));
85
rc = chmod(path, mode);
88
"Couldn't chmod %s to %04o (%s)",
97
base = strchr(conf->args[i], '/');
101
char *dir = strdup(conf->args[i]);
105
struct sockaddr_un addr;
110
unlink(conf->args[i]);
111
sock = socket(PF_UNIX, SOCK_STREAM, 0);
114
"Couldn't open af_unix socket (%s)",
118
memset(&addr, 0, sizeof(addr));
119
addr.sun_family = AF_UNIX;
120
strcpy(&addr.sun_path[0],conf->args[i]);
123
(const struct sockaddr *)&addr,
127
"Couldn't bind af_unix socket (%s)",
133
rc = chmod(conf->args[i], mode);
136
"Couldn't chmod %s to %04o (%s)",
145
rc = listen(sock, 5);
148
"Couldn't listen on af_unix socket (%s)",
153
// Put socket in nonblock mode
154
cmd = fcntl(sock, F_GETFL);
155
fcntl(sock, F_SETFL, cmd|FNDELAY);
156
// don't leak the descriptor
157
cmd = fcntl(sock, F_GETFD);
158
fcntl(sock, F_SETFD, cmd|FD_CLOEXEC);
159
path = strdup(conf->args[i]);
162
syslog(LOG_ERR, "Couldn't open %s (%s)",
163
base, strerror(errno));
166
syslog(LOG_ERR, "Malformed path %s",
175
syslog(LOG_INFO, "af_unix plugin initialized");
178
void send_af_unix(const char *s)
183
struct sockaddr_un peer_addr;
184
socklen_t peer_addr_size = sizeof(peer_addr);
185
conn = accept(sock, &peer_addr, &peer_addr_size);
188
write(sock, s, strlen(s));
192
void destroy_af_unix(void)
209
static void init_syslog(const plugin_conf_t *conf)
212
if (strcasecmp(conf->args[1], "LOG_DEBUG") == 0)
213
priority = LOG_DEBUG;
214
else if (strcasecmp(conf->args[1], "LOG_INFO") == 0)
216
else if (strcasecmp(conf->args[1], "LOG_NOTICE") == 0)
217
priority = LOG_NOTICE;
218
else if (strcasecmp(conf->args[1], "LOG_WARNING") == 0)
219
priority = LOG_WARNING;
220
else if (strcasecmp(conf->args[1], "LOG_ERR") == 0)
222
else if (strcasecmp(conf->args[1], "LOG_CRIT") == 0)
224
else if (strcasecmp(conf->args[1], "LOG_ALERT") == 0)
225
priority = LOG_ALERT;
226
else if (strcasecmp(conf->args[1], "LOG_EMERG") == 0)
227
priority = LOG_EMERG;
229
syslog(LOG_ERR, "Unknown log priority %s",
237
syslog(LOG_INFO, "syslog plugin initialized");
240
void send_syslog(const char *s)
242
if (syslog_started) {
243
syslog(priority, "%s", s);
247
void destroy_syslog(void)