1 /* Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is also distributed with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23 #include <stdio.h>
24 #include <mysql/plugin.h>
25 #include <mysql/plugin_audit.h>
26
27 #include "my_attribute.h"
28
29 static volatile int number_of_calls; /* for SHOW STATUS, see below */
30 /* Count MYSQL_AUDIT_GENERAL_CLASS event instances */
31 static volatile int number_of_calls_general_log;
32 static volatile int number_of_calls_general_error;
33 static volatile int number_of_calls_general_result;
34 static volatile int number_of_calls_general_status;
35 /* Count MYSQL_AUDIT_CONNECTION_CLASS event instances */
36 static volatile int number_of_calls_connection_connect;
37 static volatile int number_of_calls_connection_disconnect;
38 static volatile int number_of_calls_connection_change_user;
39
40
41 /*
42 Initialize the plugin at server start or plugin installation.
43
44 SYNOPSIS
45 audit_null_plugin_init()
46
47 DESCRIPTION
48 Does nothing.
49
50 RETURN VALUE
51 0 success
52 1 failure (cannot happen)
53 */
54
audit_null_plugin_init(void * arg MY_ATTRIBUTE ((unused)))55 static int audit_null_plugin_init(void *arg MY_ATTRIBUTE((unused)))
56 {
57 number_of_calls= 0;
58 number_of_calls_general_log= 0;
59 number_of_calls_general_error= 0;
60 number_of_calls_general_result= 0;
61 number_of_calls_general_status= 0;
62 number_of_calls_connection_connect= 0;
63 number_of_calls_connection_disconnect= 0;
64 number_of_calls_connection_change_user= 0;
65 return(0);
66 }
67
68
69 /*
70 Terminate the plugin at server shutdown or plugin deinstallation.
71
72 SYNOPSIS
73 audit_null_plugin_deinit()
74 Does nothing.
75
76 RETURN VALUE
77 0 success
78 1 failure (cannot happen)
79
80 */
81
audit_null_plugin_deinit(void * arg MY_ATTRIBUTE ((unused)))82 static int audit_null_plugin_deinit(void *arg MY_ATTRIBUTE((unused)))
83 {
84 return(0);
85 }
86
87
88 /*
89 Foo
90
91 SYNOPSIS
92 audit_null_notify()
93 thd connection context
94
95 DESCRIPTION
96 */
97
audit_null_notify(MYSQL_THD thd MY_ATTRIBUTE ((unused)),unsigned int event_class,const void * event)98 static void audit_null_notify(MYSQL_THD thd MY_ATTRIBUTE((unused)),
99 unsigned int event_class,
100 const void *event)
101 {
102 /* prone to races, oh well */
103 number_of_calls++;
104 if (event_class == MYSQL_AUDIT_GENERAL_CLASS)
105 {
106 const struct mysql_event_general *event_general=
107 (const struct mysql_event_general *) event;
108 switch (event_general->event_subclass)
109 {
110 case MYSQL_AUDIT_GENERAL_LOG:
111 number_of_calls_general_log++;
112 break;
113 case MYSQL_AUDIT_GENERAL_ERROR:
114 number_of_calls_general_error++;
115 break;
116 case MYSQL_AUDIT_GENERAL_RESULT:
117 number_of_calls_general_result++;
118 break;
119 case MYSQL_AUDIT_GENERAL_STATUS:
120 number_of_calls_general_status++;
121 break;
122 default:
123 break;
124 }
125 }
126 else if (event_class == MYSQL_AUDIT_CONNECTION_CLASS)
127 {
128 const struct mysql_event_connection *event_connection=
129 (const struct mysql_event_connection *) event;
130 switch (event_connection->event_subclass)
131 {
132 case MYSQL_AUDIT_CONNECTION_CONNECT:
133 number_of_calls_connection_connect++;
134 break;
135 case MYSQL_AUDIT_CONNECTION_DISCONNECT:
136 number_of_calls_connection_disconnect++;
137 break;
138 case MYSQL_AUDIT_CONNECTION_CHANGE_USER:
139 number_of_calls_connection_change_user++;
140 break;
141 default:
142 break;
143 }
144 }
145 }
146
147
148 /*
149 Plugin type-specific descriptor
150 */
151
152 static struct st_mysql_audit audit_null_descriptor=
153 {
154 MYSQL_AUDIT_INTERFACE_VERSION, /* interface version */
155 NULL, /* release_thd function */
156 audit_null_notify, /* notify function */
157 { (unsigned long) MYSQL_AUDIT_GENERAL_CLASSMASK |
158 MYSQL_AUDIT_CONNECTION_CLASSMASK } /* class mask */
159 };
160
161 /*
162 Plugin status variables for SHOW STATUS
163 */
164
165 static struct st_mysql_show_var simple_status[]=
166 {
167 { "Audit_null_called",
168 (char *) &number_of_calls,
169 SHOW_INT },
170 { "Audit_null_general_log",
171 (char *) &number_of_calls_general_log,
172 SHOW_INT },
173 { "Audit_null_general_error",
174 (char *) &number_of_calls_general_error,
175 SHOW_INT },
176 { "Audit_null_general_result",
177 (char *) &number_of_calls_general_result,
178 SHOW_INT },
179 { "Audit_null_general_status",
180 (char *) &number_of_calls_general_status,
181 SHOW_INT },
182 { "Audit_null_connection_connect",
183 (char *) &number_of_calls_connection_connect,
184 SHOW_INT },
185 { "Audit_null_connection_disconnect",
186 (char *) &number_of_calls_connection_disconnect,
187 SHOW_INT },
188 { "Audit_null_connection_change_user",
189 (char *) &number_of_calls_connection_change_user,
190 SHOW_INT },
191 { 0, 0, 0}
192 };
193
194
195 /*
196 Plugin library descriptor
197 */
198
mysql_declare_plugin(audit_null)199 mysql_declare_plugin(audit_null)
200 {
201 MYSQL_AUDIT_PLUGIN, /* type */
202 &audit_null_descriptor, /* descriptor */
203 "NULL_AUDIT", /* name */
204 "Oracle Corp", /* author */
205 "Simple NULL Audit", /* description */
206 PLUGIN_LICENSE_GPL,
207 audit_null_plugin_init, /* init function (when loaded) */
208 audit_null_plugin_deinit, /* deinit function (when unloaded) */
209 0x0003, /* version */
210 simple_status, /* status variables */
211 NULL, /* system variables */
212 NULL,
213 0,
214 }
215 mysql_declare_plugin_end;
216
217