-
Notifications
You must be signed in to change notification settings - Fork 0
/
audit_handler.h
134 lines (112 loc) · 3.4 KB
/
audit_handler.h
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/* 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 */
#ifndef AUDIT_HANDLER_INCLUDED
#define AUDIT_HANDLER_INCLUDED
#include <my_global.h>
#include "logger.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct audit_handler_struct audit_handler_t;
typedef struct audit_handler_file_config_struct audit_handler_file_config_t;
typedef struct audit_handler_syslog_config_struct audit_handler_syslog_config_t;
#ifdef AUDIT_HAVE_MONGO
typedef struct audit_handler_mongo_config_struct audit_handler_mongo_config_t;
#endif
typedef struct audit_handler_buffered_struct audit_handler_buffered_t;
typedef void * audit_handler_data_t;
typedef enum { OPT_ROTATE_ON_SIZE, OPT_ROTATIONS } audit_handler_option_t;
struct audit_handler_struct
{
int (*write)(audit_handler_t *, const char *, size_t);
int (*flush)(audit_handler_t *);
int (*close)(audit_handler_t *);
void (*set_option)(audit_handler_t *, audit_handler_option_t, void *);
audit_handler_data_t data;
};
#ifdef AUDIT_HAVE_MONGO
struct audit_handler_mongo_config_struct
{
const char *uri;
const char *collection;
logger_prolog_func_t header;
logger_epilog_func_t footer;
};
#endif
struct audit_handler_file_config_struct
{
const char *name;
size_t rotate_on_size;
size_t rotations;
my_bool sync_on_write;
my_bool use_buffer;
size_t buffer_size;
my_bool can_drop_data;
logger_prolog_func_t header;
logger_epilog_func_t footer;
};
struct audit_handler_syslog_config_struct
{
const char *ident;
int facility;
int priority;
logger_prolog_func_t header;
logger_epilog_func_t footer;
};
static inline
int audit_handler_write(audit_handler_t *handler, const char *buf, size_t len)
{
if (handler != NULL && handler->write != NULL)
{
return handler->write(handler, buf, len);
}
return len;
}
static inline
int audit_handler_flush(audit_handler_t *handler)
{
if (handler != NULL && handler->flush != NULL)
{
return handler->flush(handler);
}
return 0;
}
static inline
int audit_handler_close(audit_handler_t *handler)
{
if (handler != NULL && handler->close != NULL)
{
return handler->close(handler);
}
return 0;
}
static inline
void audit_handler_set_option(audit_handler_t *handler,
audit_handler_option_t opt, void *val)
{
if (handler != NULL && handler->set_option != NULL)
{
handler->set_option(handler, opt, val);
}
}
audit_handler_t *audit_handler_file_open(audit_handler_file_config_t *opts);
audit_handler_t *audit_handler_syslog_open(audit_handler_syslog_config_t *opts);
#ifdef AUDIT_HAVE_MONGO
audit_handler_t *audit_handler_mongo_open(audit_handler_mongo_config_t *opts);
#endif
// So other audit 'modules' can use this
extern void fprintf_timestamp(FILE *file);
#ifdef __cplusplus
}
#endif
#endif