-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaudit_syslog.c
91 lines (78 loc) · 2.99 KB
/
audit_syslog.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/* Copyright (c) 2014 Percona LLC and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; version 2 of
the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
#include <syslog.h>
#include <string.h>
#include "audit_handler.h"
typedef struct audit_handler_syslog_data_struct audit_handler_syslog_data_t;
struct audit_handler_syslog_data_struct
{
size_t struct_size;
int priority;
logger_prolog_func_t header;
logger_epilog_func_t footer;
};
int audit_handler_syslog_write(audit_handler_t *handler,
const char *buf, size_t len);
int audit_handler_syslog_flush(audit_handler_t *handler);
int audit_handler_syslog_close(audit_handler_t *handler);
audit_handler_t *audit_handler_syslog_open(audit_handler_syslog_config_t *opts)
{
audit_handler_t *handler= (audit_handler_t*)
calloc(sizeof(audit_handler_t) + sizeof(audit_handler_syslog_data_t), 1);
if (handler != NULL)
{
audit_handler_syslog_data_t *data=
(audit_handler_syslog_data_t*) (handler + 1);
MY_STAT stat_arg;
data->struct_size= sizeof(audit_handler_syslog_data_t);
data->priority= opts->priority;
data->header= opts->header;
data->footer= opts->footer;
openlog(opts->ident, 0, opts->facility);
memset(&stat_arg, 0, sizeof(stat_arg));
opts->header(&stat_arg, NULL, 0);
handler->data= data;
handler->write= audit_handler_syslog_write;
handler->flush= audit_handler_syslog_flush;
handler->close= audit_handler_syslog_close;
}
return handler;
}
int audit_handler_syslog_write(audit_handler_t *handler,
const char *buf, size_t len)
{
audit_handler_syslog_data_t *data=
(audit_handler_syslog_data_t*) handler->data;
DBUG_ASSERT(data->struct_size == sizeof(audit_handler_syslog_data_t));
syslog(data->priority, "%s", buf);
return len;
}
int audit_handler_syslog_flush(audit_handler_t *handler)
{
audit_handler_syslog_data_t *data=
(audit_handler_syslog_data_t*) handler->data;
MY_STAT stat_arg;
memset(&stat_arg, 0, sizeof(stat_arg));
data->header(&stat_arg, NULL, 0);
data->footer(NULL, 0);
return 0;
}
int audit_handler_syslog_close(audit_handler_t *handler)
{
audit_handler_syslog_data_t *data=
(audit_handler_syslog_data_t*) handler->data;
data->footer(NULL, 0);
closelog();
free(handler);
return 0;
}