Merge lp:~sergei.glushchenko/percona-server/5.6-ps-bug1363370 into lp:percona-server/5.6

Proposed by Sergei Glushchenko
Status: Merged
Approved by: Laurynas Biveinis
Approved revision: no longer in the source branch.
Merged at revision: 668
Proposed branch: lp:~sergei.glushchenko/percona-server/5.6-ps-bug1363370
Merge into: lp:percona-server/5.6
Diff against target: 1028 lines (+68/-427)
10 files modified
mysql-test/r/audit_log_rotate.result (+1/-0)
mysql-test/t/audit_log_rotate-master.opt (+8/-0)
mysql-test/t/audit_log_rotate.test (+29/-0)
plugin/audit_log/audit_file.c (+0/-200)
plugin/audit_log/audit_handler.h (+0/-116)
plugin/audit_log/audit_syslog.c (+0/-91)
plugin/audit_log/buffer.c (+7/-8)
plugin/audit_log/buffer.h (+3/-1)
plugin/audit_log/file_logger.c (+14/-10)
plugin/audit_log/logger.h (+6/-1)
To merge this branch: bzr merge lp:~sergei.glushchenko/percona-server/5.6-ps-bug1363370
Reviewer Review Type Date Requested Status
Laurynas Biveinis (community) Approve
Review via email: mp+232843@code.launchpad.net

Description of the change

To post a comment you must log in.
Revision history for this message
Sergei Glushchenko (sergei.glushchenko) wrote :
Revision history for this message
Sergei Glushchenko (sergei.glushchenko) wrote :
Revision history for this message
Laurynas Biveinis (laurynas-biveinis) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added file 'mysql-test/r/audit_log_rotate.result'
--- mysql-test/r/audit_log_rotate.result 1970-01-01 00:00:00 +0000
+++ mysql-test/r/audit_log_rotate.result 2014-09-26 09:26:38 +0000
@@ -0,0 +1,1 @@
1success
02
=== added file 'mysql-test/t/audit_log_rotate-master.opt'
--- mysql-test/t/audit_log_rotate-master.opt 1970-01-01 00:00:00 +0000
+++ mysql-test/t/audit_log_rotate-master.opt 2014-09-26 09:26:38 +0000
@@ -0,0 +1,8 @@
1$AUDIT_LOG_OPT
2$AUDIT_LOG_LOAD
3--audit_log_file=test_audit.log
4--audit_log_format=JSON
5--audit_log_strategy=ASYNCHRONOUS
6--audit_log_rotate_on_size=4096
7--audit_log_buffer_size=5000
8--audit_log_rotations=10
09
=== added file 'mysql-test/t/audit_log_rotate.test'
--- mysql-test/t/audit_log_rotate.test 1970-01-01 00:00:00 +0000
+++ mysql-test/t/audit_log_rotate.test 2014-09-26 09:26:38 +0000
@@ -0,0 +1,29 @@
1--source include/not_embedded.inc
2
3let $MYSQLD_DATADIR= `select @@datadir`;
4let MYSQLD_DATADIR= $MYSQLD_DATADIR;
5
6--disable_result_log
7--disable_query_log
8--source include/audit_log_events.inc
9--source include/audit_log_events.inc
10--source include/audit_log_events.inc
11--source include/audit_log_events.inc
12--enable_query_log
13--enable_result_log
14
15perl;
16 eval "use JSON qw(decode_json); 1" or exit 0;
17 my @files = glob ($ENV{'MYSQLD_DATADIR'} . "/test_audit.log.*");
18 foreach (@files) {
19 open my $file, $_ or die "Could not open log: $!";
20 while (my $line = <$file>) {
21 decode_json($line);
22 }
23 close $file;
24 }
25 die "Rotation doesn't wrok!" unless scalar(@files) > 1
26EOF
27--remove_files_wildcard $MYSQLD_DATADIR test_audit.log*
28
29--echo success
030
=== added file 'plugin/audit_log/audit_file.c'
--- plugin/audit_log/audit_file.c 1970-01-01 00:00:00 +0000
+++ plugin/audit_log/audit_file.c 2014-09-26 09:26:38 +0000
@@ -0,0 +1,204 @@
1/* Copyright (c) 2014 Percona LLC and/or its affiliates. All rights reserved.
2
3 This program is free software; you can redistribute it and/or
4 modify it under the terms of the GNU General Public License
5 as published by the Free Software Foundation; version 2 of
6 the License.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
16
17#include "audit_handler.h"
18#include "buffer.h"
19
20typedef struct audit_handler_file_data_struct audit_handler_file_data_t;
21
22struct audit_handler_file_data_struct
23{
24 size_t struct_size;
25 LOGGER_HANDLE *logger;
26 logger_prolog_func_t header;
27 logger_epilog_func_t footer;
28 my_bool sync_on_write;
29 my_bool use_buffer;
30 audit_log_buffer_t *buffer;
31};
32
33static
34int audit_handler_file_write(audit_handler_t *handler,
35 const char *buf, size_t len);
36static
37int audit_handler_file_flush(audit_handler_t *handler);
38static
39int audit_handler_file_close(audit_handler_t *handler);
40static
41int audit_handler_file_write_nobuf(LOGGER_HANDLE *logger,
42 const char *buf, size_t len,
43 log_record_state_t state);
44static
45int audit_handler_file_write_buf(audit_log_buffer_t *buffer,
46 const char *buf, size_t len);
47static
48void audit_handler_file_set_option(audit_handler_t *handler,
49 audit_handler_option_t opt, void *val);
50
51static
52int write_callback(void *data, const char *buf, size_t len,
53 log_record_state_t state)
54{
55 audit_handler_t *handler= (audit_handler_t *) data;
56 audit_handler_file_data_t *hdata= (audit_handler_file_data_t*) handler->data;
57
58 DBUG_ASSERT(hdata->struct_size == sizeof(audit_handler_file_data_t));
59
60 return audit_handler_file_write_nobuf(hdata->logger, buf, len, state);
61}
62
63
64audit_handler_t *audit_handler_file_open(audit_handler_file_config_t *opts)
65{
66 audit_handler_t *handler= (audit_handler_t*)
67 calloc(sizeof(audit_handler_t) + sizeof(audit_handler_file_data_t), 1);
68 if (handler != NULL)
69 {
70 audit_handler_file_data_t *data= (audit_handler_file_data_t*) (handler + 1);
71 data->struct_size= sizeof(audit_handler_file_data_t);
72 data->footer= opts->footer;
73 data->header= opts->header;
74 data->sync_on_write= opts->sync_on_write;
75 data->use_buffer= opts->use_buffer;
76 if (data->use_buffer)
77 {
78 data->buffer= audit_log_buffer_init(opts->buffer_size,
79 opts->can_drop_data,
80 write_callback, handler);
81 if (data->buffer == NULL)
82 goto error;
83 }
84 data->logger= logger_open(opts->name, opts->rotate_on_size,
85 opts->rotate_on_size ? opts->rotations : 0,
86 !opts->use_buffer, opts->header);
87 if (data->logger == NULL)
88 {
89 goto error;
90 }
91 handler->data= data;
92 handler->write= audit_handler_file_write;
93 handler->flush= audit_handler_file_flush;
94 handler->close= audit_handler_file_close;
95 handler->set_option= audit_handler_file_set_option;
96 goto success;
97error:
98 if (data->use_buffer)
99 {
100 free(data->buffer);
101 }
102 free(handler);
103 handler= NULL;
104 }
105success:
106 return handler;
107}
108
109static
110int audit_handler_file_write_nobuf(LOGGER_HANDLE *logger,
111 const char *buf, size_t len,
112 log_record_state_t state)
113{
114 return logger_write(logger, buf, len, state);
115}
116
117static
118int audit_handler_file_write_buf(audit_log_buffer_t *buffer,
119 const char *buf, size_t len)
120{
121 return audit_log_buffer_write(buffer, buf, len);
122}
123
124static
125int audit_handler_file_write(audit_handler_t *handler,
126 const char *buf, size_t len)
127{
128 audit_handler_file_data_t *data= (audit_handler_file_data_t*) handler->data;
129 int res;
130
131 DBUG_ASSERT(data->struct_size == sizeof(audit_handler_file_data_t));
132
133 if (data->use_buffer)
134 {
135 DBUG_ASSERT(data->buffer);
136 res= audit_handler_file_write_buf(data->buffer, buf, len);
137 }
138 else
139 {
140 DBUG_ASSERT(data->logger);
141 res= audit_handler_file_write_nobuf(data->logger, buf, len,
142 LOG_RECORD_COMPLETE);
143
144 if (data->sync_on_write)
145 {
146 logger_sync(data->logger);
147 }
148 }
149
150 return res;
151}
152
153static
154int audit_handler_file_flush(audit_handler_t *handler)
155{
156 audit_handler_file_data_t *data= (audit_handler_file_data_t*) handler->data;
157 LOGGER_HANDLE* logger;
158
159 DBUG_ASSERT(data->struct_size == sizeof(audit_handler_file_data_t));
160
161 logger= data->logger;
162
163 return logger_reopen(logger, data->header, data->footer);
164}
165
166static
167int audit_handler_file_close(audit_handler_t *handler)
168{
169 audit_handler_file_data_t *data= (audit_handler_file_data_t*) handler->data;
170 int res;
171 LOGGER_HANDLE* logger;
172
173 DBUG_ASSERT(data->struct_size == sizeof(audit_handler_file_data_t));
174
175 logger= data->logger;
176
177 if (data->use_buffer)
178 {
179 audit_log_buffer_shutdown(data->buffer);
180 }
181
182 res= logger_close(logger, data->footer);
183
184 free(handler);
185
186 return res;
187}
188
189static
190void audit_handler_file_set_option(audit_handler_t *handler,
191 audit_handler_option_t opt, void *val)
192{
193 audit_handler_file_data_t *data= (audit_handler_file_data_t*) handler->data;
194
195 switch (opt)
196 {
197 case OPT_ROTATIONS:
198 logger_set_size_limit(data->logger, *(ulonglong*)(val));
199 break;
200 case OPT_ROTATE_ON_SIZE:
201 logger_set_rotations(data->logger, *(ulonglong*)(val));
202 break;
203 }
204}
0205
=== removed file 'plugin/audit_log/audit_file.c'
--- plugin/audit_log/audit_file.c 2014-07-30 16:48:53 +0000
+++ plugin/audit_log/audit_file.c 1970-01-01 00:00:00 +0000
@@ -1,200 +0,0 @@
1/* Copyright (c) 2014 Percona LLC and/or its affiliates. All rights reserved.
2
3 This program is free software; you can redistribute it and/or
4 modify it under the terms of the GNU General Public License
5 as published by the Free Software Foundation; version 2 of
6 the License.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
16
17#include "audit_handler.h"
18#include "buffer.h"
19
20typedef struct audit_handler_file_data_struct audit_handler_file_data_t;
21
22struct audit_handler_file_data_struct
23{
24 size_t struct_size;
25 LOGGER_HANDLE *logger;
26 logger_prolog_func_t header;
27 logger_epilog_func_t footer;
28 my_bool sync_on_write;
29 my_bool use_buffer;
30 audit_log_buffer_t *buffer;
31};
32
33static
34int audit_handler_file_write(audit_handler_t *handler,
35 const char *buf, size_t len);
36static
37int audit_handler_file_flush(audit_handler_t *handler);
38static
39int audit_handler_file_close(audit_handler_t *handler);
40static
41int audit_handler_file_write_nobuf(LOGGER_HANDLE *logger,
42 const char *buf, size_t len);
43static
44int audit_handler_file_write_buf(audit_log_buffer_t *buffer,
45 const char *buf, size_t len);
46static
47void audit_handler_file_set_option(audit_handler_t *handler,
48 audit_handler_option_t opt, void *val);
49
50static
51int write_callback(void *data, const char *buf, size_t len)
52{
53 audit_handler_t *handler= (audit_handler_t *) data;
54 audit_handler_file_data_t *hdata= (audit_handler_file_data_t*) handler->data;
55
56 DBUG_ASSERT(hdata->struct_size == sizeof(audit_handler_file_data_t));
57
58 return audit_handler_file_write_nobuf(hdata->logger, buf, len);
59}
60
61
62audit_handler_t *audit_handler_file_open(audit_handler_file_config_t *opts)
63{
64 audit_handler_t *handler= (audit_handler_t*)
65 calloc(sizeof(audit_handler_t) + sizeof(audit_handler_file_data_t), 1);
66 if (handler != NULL)
67 {
68 audit_handler_file_data_t *data= (audit_handler_file_data_t*) (handler + 1);
69 data->struct_size= sizeof(audit_handler_file_data_t);
70 data->footer= opts->footer;
71 data->header= opts->header;
72 data->sync_on_write= opts->sync_on_write;
73 data->use_buffer= opts->use_buffer;
74 if (data->use_buffer)
75 {
76 data->buffer= audit_log_buffer_init(opts->buffer_size,
77 opts->can_drop_data,
78 write_callback, handler);
79 if (data->buffer == NULL)
80 goto error;
81 }
82 data->logger= logger_open(opts->name, opts->rotate_on_size,
83 opts->rotate_on_size ? opts->rotations : 0,
84 !opts->use_buffer, opts->header);
85 if (data->logger == NULL)
86 {
87 goto error;
88 }
89 handler->data= data;
90 handler->write= audit_handler_file_write;
91 handler->flush= audit_handler_file_flush;
92 handler->close= audit_handler_file_close;
93 handler->set_option= audit_handler_file_set_option;
94 goto success;
95error:
96 if (data->use_buffer)
97 {
98 free(data->buffer);
99 }
100 free(handler);
101 handler= NULL;
102 }
103success:
104 return handler;
105}
106
107static
108int audit_handler_file_write_nobuf(LOGGER_HANDLE *logger,
109 const char *buf, size_t len)
110{
111 return logger_write(logger, buf, len);
112}
113
114static
115int audit_handler_file_write_buf(audit_log_buffer_t *buffer,
116 const char *buf, size_t len)
117{
118 return audit_log_buffer_write(buffer, buf, len);
119}
120
121static
122int audit_handler_file_write(audit_handler_t *handler,
123 const char *buf, size_t len)
124{
125 audit_handler_file_data_t *data= (audit_handler_file_data_t*) handler->data;
126 int res;
127
128 DBUG_ASSERT(data->struct_size == sizeof(audit_handler_file_data_t));
129
130 if (data->use_buffer)
131 {
132 DBUG_ASSERT(data->buffer);
133 res= audit_handler_file_write_buf(data->buffer, buf, len);
134 }
135 else
136 {
137 DBUG_ASSERT(data->logger);
138 res= audit_handler_file_write_nobuf(data->logger, buf, len);
139
140 if (data->sync_on_write)
141 {
142 logger_sync(data->logger);
143 }
144 }
145
146 return res;
147}
148
149static
150int audit_handler_file_flush(audit_handler_t *handler)
151{
152 audit_handler_file_data_t *data= (audit_handler_file_data_t*) handler->data;
153 LOGGER_HANDLE* logger;
154
155 DBUG_ASSERT(data->struct_size == sizeof(audit_handler_file_data_t));
156
157 logger= data->logger;
158
159 return logger_reopen(logger, data->header, data->footer);
160}
161
162static
163int audit_handler_file_close(audit_handler_t *handler)
164{
165 audit_handler_file_data_t *data= (audit_handler_file_data_t*) handler->data;
166 int res;
167 LOGGER_HANDLE* logger;
168
169 DBUG_ASSERT(data->struct_size == sizeof(audit_handler_file_data_t));
170
171 logger= data->logger;
172
173 if (data->use_buffer)
174 {
175 audit_log_buffer_shutdown(data->buffer);
176 }
177
178 res= logger_close(logger, data->footer);
179
180 free(handler);
181
182 return res;
183}
184
185static
186void audit_handler_file_set_option(audit_handler_t *handler,
187 audit_handler_option_t opt, void *val)
188{
189 audit_handler_file_data_t *data= (audit_handler_file_data_t*) handler->data;
190
191 switch (opt)
192 {
193 case OPT_ROTATIONS:
194 logger_set_size_limit(data->logger, *(ulonglong*)(val));
195 break;
196 case OPT_ROTATE_ON_SIZE:
197 logger_set_rotations(data->logger, *(ulonglong*)(val));
198 break;
199 }
200}
2010
=== added file 'plugin/audit_log/audit_handler.h'
--- plugin/audit_log/audit_handler.h 1970-01-01 00:00:00 +0000
+++ plugin/audit_log/audit_handler.h 2014-09-26 09:26:38 +0000
@@ -0,0 +1,116 @@
1/* Copyright (c) 2014 Percona LLC and/or its affiliates. All rights reserved.
2
3 This program is free software; you can redistribute it and/or
4 modify it under the terms of the GNU General Public License
5 as published by the Free Software Foundation; version 2 of
6 the License.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
16
17
18#ifndef AUDIT_HANDLER_INCLUDED
19#define AUDIT_HANDLER_INCLUDED
20
21#include <my_global.h>
22
23#include "logger.h"
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
29typedef struct audit_handler_struct audit_handler_t;
30typedef struct audit_handler_file_config_struct audit_handler_file_config_t;
31typedef struct audit_handler_syslog_config_struct audit_handler_syslog_config_t;
32typedef struct audit_handler_buffered_struct audit_handler_buffered_t;
33typedef void * audit_handler_data_t;
34
35
36typedef enum { OPT_ROTATE_ON_SIZE, OPT_ROTATIONS } audit_handler_option_t;
37
38struct audit_handler_struct
39{
40 int (*write)(audit_handler_t *, const char *, size_t);
41 int (*flush)(audit_handler_t *);
42 int (*close)(audit_handler_t *);
43 void (*set_option)(audit_handler_t *, audit_handler_option_t, void *);
44 audit_handler_data_t data;
45};
46
47struct audit_handler_file_config_struct
48{
49 const char *name;
50 size_t rotate_on_size;
51 size_t rotations;
52 my_bool sync_on_write;
53 my_bool use_buffer;
54 size_t buffer_size;
55 my_bool can_drop_data;
56 logger_prolog_func_t header;
57 logger_epilog_func_t footer;
58};
59
60struct audit_handler_syslog_config_struct
61{
62 const char *ident;
63 int facility;
64 int priority;
65 logger_prolog_func_t header;
66 logger_epilog_func_t footer;
67};
68
69static inline
70int audit_handler_write(audit_handler_t *handler, const char *buf, size_t len)
71{
72 if (handler->write != NULL)
73 {
74 return handler->write(handler, buf, len);
75 }
76 return len;
77}
78
79static inline
80int audit_handler_flush(audit_handler_t *handler)
81{
82 if (handler->flush != NULL)
83 {
84 return handler->flush(handler);
85 }
86 return 0;
87}
88
89static inline
90int audit_handler_close(audit_handler_t *handler)
91{
92 if (handler->close != NULL)
93 {
94 return handler->close(handler);
95 }
96 return 0;
97}
98
99static inline
100void audit_handler_set_option(audit_handler_t *handler,
101 audit_handler_option_t opt, void *val)
102{
103 if (handler->set_option != NULL)
104 {
105 handler->set_option(handler, opt, val);
106 }
107}
108
109audit_handler_t *audit_handler_file_open(audit_handler_file_config_t *opts);
110audit_handler_t *audit_handler_syslog_open(audit_handler_syslog_config_t *opts);
111
112#ifdef __cplusplus
113}
114#endif
115
116#endif
0117
=== removed file 'plugin/audit_log/audit_handler.h'
--- plugin/audit_log/audit_handler.h 2014-07-30 16:48:53 +0000
+++ plugin/audit_log/audit_handler.h 1970-01-01 00:00:00 +0000
@@ -1,116 +0,0 @@
1/* Copyright (c) 2014 Percona LLC and/or its affiliates. All rights reserved.
2
3 This program is free software; you can redistribute it and/or
4 modify it under the terms of the GNU General Public License
5 as published by the Free Software Foundation; version 2 of
6 the License.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
16
17
18#ifndef AUDIT_HANDLER_INCLUDED
19#define AUDIT_HANDLER_INCLUDED
20
21#include <my_global.h>
22
23#include "logger.h"
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
29typedef struct audit_handler_struct audit_handler_t;
30typedef struct audit_handler_file_config_struct audit_handler_file_config_t;
31typedef struct audit_handler_syslog_config_struct audit_handler_syslog_config_t;
32typedef struct audit_handler_buffered_struct audit_handler_buffered_t;
33typedef void * audit_handler_data_t;
34
35
36typedef enum { OPT_ROTATE_ON_SIZE, OPT_ROTATIONS } audit_handler_option_t;
37
38struct audit_handler_struct
39{
40 int (*write)(audit_handler_t *, const char *, size_t);
41 int (*flush)(audit_handler_t *);
42 int (*close)(audit_handler_t *);
43 void (*set_option)(audit_handler_t *, audit_handler_option_t, void *);
44 audit_handler_data_t data;
45};
46
47struct audit_handler_file_config_struct
48{
49 const char *name;
50 size_t rotate_on_size;
51 size_t rotations;
52 my_bool sync_on_write;
53 my_bool use_buffer;
54 size_t buffer_size;
55 my_bool can_drop_data;
56 logger_prolog_func_t header;
57 logger_epilog_func_t footer;
58};
59
60struct audit_handler_syslog_config_struct
61{
62 const char *ident;
63 int facility;
64 int priority;
65 logger_prolog_func_t header;
66 logger_epilog_func_t footer;
67};
68
69static inline
70int audit_handler_write(audit_handler_t *handler, const char *buf, size_t len)
71{
72 if (handler->write != NULL)
73 {
74 return handler->write(handler, buf, len);
75 }
76 return len;
77}
78
79static inline
80int audit_handler_flush(audit_handler_t *handler)
81{
82 if (handler->flush != NULL)
83 {
84 return handler->flush(handler);
85 }
86 return 0;
87}
88
89static inline
90int audit_handler_close(audit_handler_t *handler)
91{
92 if (handler->close != NULL)
93 {
94 return handler->close(handler);
95 }
96 return 0;
97}
98
99static inline
100void audit_handler_set_option(audit_handler_t *handler,
101 audit_handler_option_t opt, void *val)
102{
103 if (handler->set_option != NULL)
104 {
105 handler->set_option(handler, opt, val);
106 }
107}
108
109audit_handler_t *audit_handler_file_open(audit_handler_file_config_t *opts);
110audit_handler_t *audit_handler_syslog_open(audit_handler_syslog_config_t *opts);
111
112#ifdef __cplusplus
113}
114#endif
115
116#endif
1170
=== added file 'plugin/audit_log/audit_syslog.c'
--- plugin/audit_log/audit_syslog.c 1970-01-01 00:00:00 +0000
+++ plugin/audit_log/audit_syslog.c 2014-09-26 09:26:38 +0000
@@ -0,0 +1,91 @@
1/* Copyright (c) 2014 Percona LLC and/or its affiliates. All rights reserved.
2
3 This program is free software; you can redistribute it and/or
4 modify it under the terms of the GNU General Public License
5 as published by the Free Software Foundation; version 2 of
6 the License.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
16
17#include <syslog.h>
18#include <string.h>
19#include "audit_handler.h"
20
21typedef struct audit_handler_syslog_data_struct audit_handler_syslog_data_t;
22
23struct audit_handler_syslog_data_struct
24{
25 size_t struct_size;
26 int priority;
27 logger_prolog_func_t header;
28 logger_epilog_func_t footer;
29};
30
31int audit_handler_syslog_write(audit_handler_t *handler,
32 const char *buf, size_t len);
33int audit_handler_syslog_flush(audit_handler_t *handler);
34int audit_handler_syslog_close(audit_handler_t *handler);
35
36
37audit_handler_t *audit_handler_syslog_open(audit_handler_syslog_config_t *opts)
38{
39 audit_handler_t *handler= (audit_handler_t*)
40 calloc(sizeof(audit_handler_t) + sizeof(audit_handler_syslog_data_t), 1);
41 if (handler != NULL)
42 {
43 audit_handler_syslog_data_t *data=
44 (audit_handler_syslog_data_t*) (handler + 1);
45 MY_STAT stat_arg;
46
47 data->struct_size= sizeof(audit_handler_syslog_data_t);
48 data->priority= opts->priority;
49 data->header= opts->header;
50 data->footer= opts->footer;
51 openlog(opts->ident, 0, opts->facility);
52 memset(&stat_arg, 0, sizeof(stat_arg));
53 opts->header(&stat_arg, NULL, 0);
54 handler->data= data;
55 handler->write= audit_handler_syslog_write;
56 handler->flush= audit_handler_syslog_flush;
57 handler->close= audit_handler_syslog_close;
58 }
59 return handler;
60}
61
62int audit_handler_syslog_write(audit_handler_t *handler,
63 const char *buf, size_t len)
64{
65 audit_handler_syslog_data_t *data=
66 (audit_handler_syslog_data_t*) handler->data;
67 DBUG_ASSERT(data->struct_size == sizeof(audit_handler_syslog_data_t));
68 syslog(data->priority, "%s", buf);
69 return len;
70}
71
72int audit_handler_syslog_flush(audit_handler_t *handler)
73{
74 audit_handler_syslog_data_t *data=
75 (audit_handler_syslog_data_t*) handler->data;
76 MY_STAT stat_arg;
77 memset(&stat_arg, 0, sizeof(stat_arg));
78 data->header(&stat_arg, NULL, 0);
79 data->footer(NULL, 0);
80 return 0;
81}
82
83int audit_handler_syslog_close(audit_handler_t *handler)
84{
85 audit_handler_syslog_data_t *data=
86 (audit_handler_syslog_data_t*) handler->data;
87 data->footer(NULL, 0);
88 closelog();
89 free(handler);
90 return 0;
91}
092
=== removed file 'plugin/audit_log/audit_syslog.c'
--- plugin/audit_log/audit_syslog.c 2014-07-30 16:48:53 +0000
+++ plugin/audit_log/audit_syslog.c 1970-01-01 00:00:00 +0000
@@ -1,91 +0,0 @@
1/* Copyright (c) 2014 Percona LLC and/or its affiliates. All rights reserved.
2
3 This program is free software; you can redistribute it and/or
4 modify it under the terms of the GNU General Public License
5 as published by the Free Software Foundation; version 2 of
6 the License.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
16
17#include <syslog.h>
18#include <string.h>
19#include "audit_handler.h"
20
21typedef struct audit_handler_syslog_data_struct audit_handler_syslog_data_t;
22
23struct audit_handler_syslog_data_struct
24{
25 size_t struct_size;
26 int priority;
27 logger_prolog_func_t header;
28 logger_epilog_func_t footer;
29};
30
31int audit_handler_syslog_write(audit_handler_t *handler,
32 const char *buf, size_t len);
33int audit_handler_syslog_flush(audit_handler_t *handler);
34int audit_handler_syslog_close(audit_handler_t *handler);
35
36
37audit_handler_t *audit_handler_syslog_open(audit_handler_syslog_config_t *opts)
38{
39 audit_handler_t *handler= (audit_handler_t*)
40 calloc(sizeof(audit_handler_t) + sizeof(audit_handler_syslog_data_t), 1);
41 if (handler != NULL)
42 {
43 audit_handler_syslog_data_t *data=
44 (audit_handler_syslog_data_t*) (handler + 1);
45 MY_STAT stat_arg;
46
47 data->struct_size= sizeof(audit_handler_syslog_data_t);
48 data->priority= opts->priority;
49 data->header= opts->header;
50 data->footer= opts->footer;
51 openlog(opts->ident, 0, opts->facility);
52 memset(&stat_arg, 0, sizeof(stat_arg));
53 opts->header(&stat_arg, NULL, 0);
54 handler->data= data;
55 handler->write= audit_handler_syslog_write;
56 handler->flush= audit_handler_syslog_flush;
57 handler->close= audit_handler_syslog_close;
58 }
59 return handler;
60}
61
62int audit_handler_syslog_write(audit_handler_t *handler,
63 const char *buf, size_t len)
64{
65 audit_handler_syslog_data_t *data=
66 (audit_handler_syslog_data_t*) handler->data;
67 DBUG_ASSERT(data->struct_size == sizeof(audit_handler_syslog_data_t));
68 syslog(data->priority, "%s", buf);
69 return len;
70}
71
72int audit_handler_syslog_flush(audit_handler_t *handler)
73{
74 audit_handler_syslog_data_t *data=
75 (audit_handler_syslog_data_t*) handler->data;
76 MY_STAT stat_arg;
77 memset(&stat_arg, 0, sizeof(stat_arg));
78 data->header(&stat_arg, NULL, 0);
79 data->footer(NULL, 0);
80 return 0;
81}
82
83int audit_handler_syslog_close(audit_handler_t *handler)
84{
85 audit_handler_syslog_data_t *data=
86 (audit_handler_syslog_data_t*) handler->data;
87 data->footer(NULL, 0);
88 closelog();
89 free(handler);
90 return 0;
91}
920
=== modified file 'plugin/audit_log/buffer.c'
--- plugin/audit_log/buffer.c 2014-04-21 12:07:45 +0000
+++ plugin/audit_log/buffer.c 2014-09-26 09:26:38 +0000
@@ -73,26 +73,25 @@
73 mysql_mutex_unlock(&log->mutex);73 mysql_mutex_unlock(&log->mutex);
74 log->write_func(log->write_func_data,74 log->write_func(log->write_func_data,
75 log->buf + log->flush_pos,75 log->buf + log->flush_pos,
76 log->size - log->flush_pos);76 log->size - log->flush_pos,
77 LOG_RECORD_INCOMPLETE);
77 mysql_mutex_lock(&log->mutex);78 mysql_mutex_lock(&log->mutex);
78 log->flush_pos= 0;79 log->flush_pos= 0;
79 log->write_pos%= log->size;80 log->write_pos%= log->size;
80 DBUG_ASSERT(log->write_pos >= log->flush_pos);
81 mysql_cond_broadcast(&log->flushed_cond);
82 mysql_mutex_unlock(&log->mutex);
83 }81 }
84 else82 else
85 {83 {
86 size_t flushlen= log->write_pos - log->flush_pos;84 size_t flushlen= log->write_pos - log->flush_pos;
87 mysql_mutex_unlock(&log->mutex);85 mysql_mutex_unlock(&log->mutex);
88 log->write_func(log->write_func_data,86 log->write_func(log->write_func_data,
89 log->buf + log->flush_pos, flushlen);87 log->buf + log->flush_pos, flushlen,
88 LOG_RECORD_COMPLETE);
90 mysql_mutex_lock(&log->mutex);89 mysql_mutex_lock(&log->mutex);
91 log->flush_pos+= flushlen;90 log->flush_pos+= flushlen;
92 DBUG_ASSERT(log->write_pos >= log->flush_pos);
93 mysql_cond_broadcast(&log->flushed_cond);
94 mysql_mutex_unlock(&log->mutex);
95 }91 }
92 DBUG_ASSERT(log->write_pos >= log->flush_pos);
93 mysql_cond_broadcast(&log->flushed_cond);
94 mysql_mutex_unlock(&log->mutex);
96}95}
9796
9897
9998
=== modified file 'plugin/audit_log/buffer.h'
--- plugin/audit_log/buffer.h 2014-08-22 13:31:49 +0000
+++ plugin/audit_log/buffer.h 2014-09-26 09:26:38 +0000
@@ -19,6 +19,7 @@
19#define AUDIT_LOG_BUFFER_INCLUDED19#define AUDIT_LOG_BUFFER_INCLUDED
2020
21#include <string.h> // for size_t21#include <string.h> // for size_t
22#include "logger.h"
2223
23#ifdef __cplusplus24#ifdef __cplusplus
24extern "C" {25extern "C" {
@@ -26,7 +27,8 @@
2627
27typedef struct audit_log_buffer audit_log_buffer_t;28typedef struct audit_log_buffer audit_log_buffer_t;
2829
29typedef int (*audit_log_write_func)(void *data, const char *buf, size_t len);30typedef int (*audit_log_write_func)(void *data, const char *buf, size_t len,
31 log_record_state_t state);
3032
31audit_log_buffer_t *audit_log_buffer_init(size_t size, int drop_if_full,33audit_log_buffer_t *audit_log_buffer_init(size_t size, int drop_if_full,
32 audit_log_write_func write_func, void *data);34 audit_log_write_func write_func, void *data);
3335
=== modified file 'plugin/audit_log/file_logger.c'
--- plugin/audit_log/file_logger.c 2014-07-30 17:12:20 +0000
+++ plugin/audit_log/file_logger.c 2014-09-26 09:26:38 +0000
@@ -279,24 +279,28 @@
279}279}
280280
281281
282int logger_write(LOGGER_HANDLE *log, const char *buffer, size_t size)282int logger_write(LOGGER_HANDLE *log, const char *buffer, size_t size,
283 log_record_state_t state)
283{284{
284 int result;285 int result;
285 my_off_t filesize;286 my_off_t filesize;
286287
287 flogger_mutex_lock(log);288 flogger_mutex_lock(log);
288 if (log->rotations > 0)
289 if ((filesize= my_tell(log->file, MYF(0))) == (my_off_t) -1 ||
290 ((unsigned long long)filesize >= log->size_limit &&
291 do_rotate(log)))
292 {
293 result= -1;
294 errno= my_errno;
295 goto exit; /* Log rotation needed but failed */
296 }
297289
298 result= my_write(log->file, (uchar *) buffer, size, MYF(0));290 result= my_write(log->file, (uchar *) buffer, size, MYF(0));
299291
292 if (state == LOG_RECORD_COMPLETE && log->rotations > 0)
293 {
294 if ((filesize= my_tell(log->file, MYF(0))) == (my_off_t) -1 ||
295 ((unsigned long long)filesize >= log->size_limit &&
296 do_rotate(log)))
297 {
298 result= -1;
299 errno= my_errno;
300 goto exit; /* Log rotation needed but failed */
301 }
302 }
303
300exit:304exit:
301 flogger_mutex_unlock(log);305 flogger_mutex_unlock(log);
302 return result;306 return result;
303307
=== modified file 'plugin/audit_log/logger.h'
--- plugin/audit_log/logger.h 2014-08-22 13:31:49 +0000
+++ plugin/audit_log/logger.h 2014-09-26 09:26:38 +0000
@@ -62,6 +62,10 @@
62typedef struct logger_handle_st LOGGER_HANDLE;62typedef struct logger_handle_st LOGGER_HANDLE;
63typedef size_t (*logger_prolog_func_t)(MY_STAT *, char *buf, size_t buflen);63typedef size_t (*logger_prolog_func_t)(MY_STAT *, char *buf, size_t buflen);
64typedef size_t (*logger_epilog_func_t)(char *buf, size_t buflen);64typedef size_t (*logger_epilog_func_t)(char *buf, size_t buflen);
65typedef enum {
66 LOG_RECORD_COMPLETE,
67 LOG_RECORD_INCOMPLETE
68} log_record_state_t;
6569
66void logger_init_mutexes();70void logger_init_mutexes();
67LOGGER_HANDLE *logger_open(const char *path,71LOGGER_HANDLE *logger_open(const char *path,
@@ -72,7 +76,8 @@
72int logger_close(LOGGER_HANDLE *log, logger_epilog_func_t footer);76int logger_close(LOGGER_HANDLE *log, logger_epilog_func_t footer);
73int logger_vprintf(LOGGER_HANDLE *log, const char *fmt, va_list argptr);77int logger_vprintf(LOGGER_HANDLE *log, const char *fmt, va_list argptr);
74int logger_printf(LOGGER_HANDLE *log, const char *fmt, ...);78int logger_printf(LOGGER_HANDLE *log, const char *fmt, ...);
75int logger_write(LOGGER_HANDLE *log, const char *buffer, size_t size);79int logger_write(LOGGER_HANDLE *log, const char *buffer, size_t size,
80 log_record_state_t state);
76int logger_rotate(LOGGER_HANDLE *log); 81int logger_rotate(LOGGER_HANDLE *log);
77int logger_sync(LOGGER_HANDLE *log);82int logger_sync(LOGGER_HANDLE *log);
78int logger_reopen(LOGGER_HANDLE *log, logger_prolog_func_t header,83int logger_reopen(LOGGER_HANDLE *log, logger_prolog_func_t header,

Subscribers

People subscribed via source and target branches