MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
audit_null.c
1 /* Copyright (c) 2010, Oracle 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 as
5  published by the Free Software Foundation; version 2 of the
6  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 <stdio.h>
18 #include <mysql/plugin.h>
19 #include <mysql/plugin_audit.h>
20 
21 #if !defined(__attribute__) && (defined(__cplusplus) || !defined(__GNUC__) || __GNUC__ == 2 && __GNUC_MINOR__ < 8)
22 #define __attribute__(A)
23 #endif
24 
25 static volatile int number_of_calls; /* for SHOW STATUS, see below */
26 /* Count MYSQL_AUDIT_GENERAL_CLASS event instances */
27 static volatile int number_of_calls_general_log;
28 static volatile int number_of_calls_general_error;
29 static volatile int number_of_calls_general_result;
30 static volatile int number_of_calls_general_status;
31 /* Count MYSQL_AUDIT_CONNECTION_CLASS event instances */
32 static volatile int number_of_calls_connection_connect;
33 static volatile int number_of_calls_connection_disconnect;
34 static volatile int number_of_calls_connection_change_user;
35 
36 
37 /*
38  Initialize the plugin at server start or plugin installation.
39 
40  SYNOPSIS
41  audit_null_plugin_init()
42 
43  DESCRIPTION
44  Does nothing.
45 
46  RETURN VALUE
47  0 success
48  1 failure (cannot happen)
49 */
50 
51 static int audit_null_plugin_init(void *arg __attribute__((unused)))
52 {
53  number_of_calls= 0;
54  number_of_calls_general_log= 0;
55  number_of_calls_general_error= 0;
56  number_of_calls_general_result= 0;
57  number_of_calls_general_status= 0;
58  number_of_calls_connection_connect= 0;
59  number_of_calls_connection_disconnect= 0;
60  number_of_calls_connection_change_user= 0;
61  return(0);
62 }
63 
64 
65 /*
66  Terminate the plugin at server shutdown or plugin deinstallation.
67 
68  SYNOPSIS
69  audit_null_plugin_deinit()
70  Does nothing.
71 
72  RETURN VALUE
73  0 success
74  1 failure (cannot happen)
75 
76 */
77 
78 static int audit_null_plugin_deinit(void *arg __attribute__((unused)))
79 {
80  return(0);
81 }
82 
83 
84 /*
85  Foo
86 
87  SYNOPSIS
88  audit_null_notify()
89  thd connection context
90 
91  DESCRIPTION
92 */
93 
94 static void audit_null_notify(MYSQL_THD thd __attribute__((unused)),
95  unsigned int event_class,
96  const void *event)
97 {
98  /* prone to races, oh well */
99  number_of_calls++;
100  if (event_class == MYSQL_AUDIT_GENERAL_CLASS)
101  {
102  const struct mysql_event_general *event_general=
103  (const struct mysql_event_general *) event;
104  switch (event_general->event_subclass)
105  {
106  case MYSQL_AUDIT_GENERAL_LOG:
107  number_of_calls_general_log++;
108  break;
109  case MYSQL_AUDIT_GENERAL_ERROR:
110  number_of_calls_general_error++;
111  break;
112  case MYSQL_AUDIT_GENERAL_RESULT:
113  number_of_calls_general_result++;
114  break;
115  case MYSQL_AUDIT_GENERAL_STATUS:
116  number_of_calls_general_status++;
117  break;
118  default:
119  break;
120  }
121  }
122  else if (event_class == MYSQL_AUDIT_CONNECTION_CLASS)
123  {
124  const struct mysql_event_connection *event_connection=
125  (const struct mysql_event_connection *) event;
126  switch (event_connection->event_subclass)
127  {
128  case MYSQL_AUDIT_CONNECTION_CONNECT:
129  number_of_calls_connection_connect++;
130  break;
131  case MYSQL_AUDIT_CONNECTION_DISCONNECT:
132  number_of_calls_connection_disconnect++;
133  break;
134  case MYSQL_AUDIT_CONNECTION_CHANGE_USER:
135  number_of_calls_connection_change_user++;
136  break;
137  default:
138  break;
139  }
140  }
141 }
142 
143 
144 /*
145  Plugin type-specific descriptor
146 */
147 
148 static struct st_mysql_audit audit_null_descriptor=
149 {
150  MYSQL_AUDIT_INTERFACE_VERSION, /* interface version */
151  NULL, /* release_thd function */
152  audit_null_notify, /* notify function */
153  { (unsigned long) MYSQL_AUDIT_GENERAL_CLASSMASK |
154  MYSQL_AUDIT_CONNECTION_CLASSMASK } /* class mask */
155 };
156 
157 /*
158  Plugin status variables for SHOW STATUS
159 */
160 
161 static struct st_mysql_show_var simple_status[]=
162 {
163  { "Audit_null_called",
164  (char *) &number_of_calls,
165  SHOW_INT },
166  { "Audit_null_general_log",
167  (char *) &number_of_calls_general_log,
168  SHOW_INT },
169  { "Audit_null_general_error",
170  (char *) &number_of_calls_general_error,
171  SHOW_INT },
172  { "Audit_null_general_result",
173  (char *) &number_of_calls_general_result,
174  SHOW_INT },
175  { "Audit_null_general_status",
176  (char *) &number_of_calls_general_status,
177  SHOW_INT },
178  { "Audit_null_connection_connect",
179  (char *) &number_of_calls_connection_connect,
180  SHOW_INT },
181  { "Audit_null_connection_disconnect",
182  (char *) &number_of_calls_connection_disconnect,
183  SHOW_INT },
184  { "Audit_null_connection_change_user",
185  (char *) &number_of_calls_connection_change_user,
186  SHOW_INT },
187  { 0, 0, 0}
188 };
189 
190 
191 /*
192  Plugin library descriptor
193 */
194 
195 mysql_declare_plugin(audit_null)
196 {
197  MYSQL_AUDIT_PLUGIN, /* type */
198  &audit_null_descriptor, /* descriptor */
199  "NULL_AUDIT", /* name */
200  "Oracle Corp", /* author */
201  "Simple NULL Audit", /* description */
202  PLUGIN_LICENSE_GPL,
203  audit_null_plugin_init, /* init function (when loaded) */
204  audit_null_plugin_deinit, /* deinit function (when unloaded) */
205  0x0003, /* version */
206  simple_status, /* status variables */
207  NULL, /* system variables */
208  NULL,
209  0,
210 }
211 mysql_declare_plugin_end;
212