MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
plugin_audit.h
1 /* Copyright (c) 2007, 2011, 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
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 #ifndef _my_audit_h
18 #define _my_audit_h
19 
20 /*************************************************************************
21  API for Audit plugin. (MYSQL_AUDIT_PLUGIN)
22 */
23 
24 #include "plugin.h"
25 
26 #define MYSQL_AUDIT_CLASS_MASK_SIZE 1
27 
28 #define MYSQL_AUDIT_INTERFACE_VERSION 0x0301
29 
30 
31 /*************************************************************************
32  AUDIT CLASS : GENERAL
33 
34  LOG events occurs before emitting to the general query log.
35  ERROR events occur before transmitting errors to the user.
36  RESULT events occur after transmitting a resultset to the user.
37  STATUS events occur after transmitting a resultset or errors
38  to the user.
39 */
40 
41 #define MYSQL_AUDIT_GENERAL_CLASS 0
42 #define MYSQL_AUDIT_GENERAL_CLASSMASK (1 << MYSQL_AUDIT_GENERAL_CLASS)
43 #define MYSQL_AUDIT_GENERAL_LOG 0
44 #define MYSQL_AUDIT_GENERAL_ERROR 1
45 #define MYSQL_AUDIT_GENERAL_RESULT 2
46 #define MYSQL_AUDIT_GENERAL_STATUS 3
47 
49 {
50  unsigned int event_subclass;
51  int general_error_code;
52  unsigned long general_thread_id;
53  const char *general_user;
54  unsigned int general_user_length;
55  const char *general_command;
56  unsigned int general_command_length;
57  const char *general_query;
58  unsigned int general_query_length;
59  struct charset_info_st *general_charset;
60  unsigned long long general_time;
61  unsigned long long general_rows;
62  MYSQL_LEX_STRING general_host;
63  MYSQL_LEX_STRING general_sql_command;
64  MYSQL_LEX_STRING general_external_user;
65  MYSQL_LEX_STRING general_ip;
66 };
67 
68 
69 /*
70  AUDIT CLASS : CONNECTION
71 
72  CONNECT occurs after authentication phase is completed.
73  DISCONNECT occurs after connection is terminated.
74  CHANGE_USER occurs after COM_CHANGE_USER RPC is completed.
75 */
76 
77 #define MYSQL_AUDIT_CONNECTION_CLASS 1
78 #define MYSQL_AUDIT_CONNECTION_CLASSMASK (1 << MYSQL_AUDIT_CONNECTION_CLASS)
79 #define MYSQL_AUDIT_CONNECTION_CONNECT 0
80 #define MYSQL_AUDIT_CONNECTION_DISCONNECT 1
81 #define MYSQL_AUDIT_CONNECTION_CHANGE_USER 2
82 
84 {
85  unsigned int event_subclass;
86  int status;
87  unsigned long thread_id;
88  const char *user;
89  unsigned int user_length;
90  const char *priv_user;
91  unsigned int priv_user_length;
92  const char *external_user;
93  unsigned int external_user_length;
94  const char *proxy_user;
95  unsigned int proxy_user_length;
96  const char *host;
97  unsigned int host_length;
98  const char *ip;
99  unsigned int ip_length;
100  const char *database;
101  unsigned int database_length;
102 };
103 
104 
105 /*************************************************************************
106  Here we define the descriptor structure, that is referred from
107  st_mysql_plugin.
108 
109  release_thd() event occurs when the event class consumer is to be
110  disassociated from the specified THD. This would typically occur
111  before some operation which may require sleeping - such as when
112  waiting for the next query from the client.
113 
114  event_notify() is invoked whenever an event occurs which is of any
115  class for which the plugin has interest. The second argument
116  indicates the specific event class and the third argument is data
117  as required for that class.
118 
119  class_mask is an array of bits used to indicate what event classes
120  that this plugin wants to receive.
121 */
122 
124 {
125  int interface_version;
126  void (*release_thd)(MYSQL_THD);
127  void (*event_notify)(MYSQL_THD, unsigned int, const void *);
128  unsigned long class_mask[MYSQL_AUDIT_CLASS_MASK_SIZE];
129 };
130 
131 
132 #endif