1 | #define PLUGIN_CONTEXT |
2 | |
3 | /* Can't use <my_global.h> as this includes plugin.h */ |
4 | #include <stdio.h> |
5 | |
6 | typedef void *MYSQL_THD; |
7 | struct st_mysql_const_lex_string |
8 | { |
9 | const char *str; |
10 | size_t length; |
11 | }; |
12 | typedef struct st_mysql_const_lex_string MYSQL_LEX_CSTRING; |
13 | enum enum_sql_command{ SQLCOM_A, SQLCOM_B }; |
14 | enum enum_server_command{ SERVCOM_A, SERVCOM_B }; |
15 | |
16 | #include "plugin_audit_v4.h" |
17 | |
18 | extern void auditing(MYSQL_THD thd, unsigned int event_class, const void *ev); |
19 | extern int get_db_mysql57(MYSQL_THD thd, char **name, int *len); |
20 | |
21 | |
22 | struct mysql_event_general_302 |
23 | { |
24 | unsigned int event_subclass; |
25 | int general_error_code; |
26 | unsigned long general_thread_id; |
27 | const char *general_user; |
28 | unsigned int general_user_length; |
29 | const char *general_command; |
30 | unsigned int general_command_length; |
31 | const char *general_query; |
32 | unsigned int general_query_length; |
33 | struct charset_info_st *general_charset; |
34 | unsigned long long general_time; |
35 | unsigned long long general_rows; |
36 | unsigned long long query_id; |
37 | char *database; |
38 | int database_length; |
39 | }; |
40 | |
41 | |
42 | static int auditing_v4(MYSQL_THD thd, mysql_event_class_t class, const void *ev) |
43 | { |
44 | int *subclass= (int *)ev; |
45 | struct mysql_event_general_302 ev_302; |
46 | int subclass_v3, subclass_orig; |
47 | |
48 | if (class != MYSQL_AUDIT_GENERAL_CLASS && |
49 | class != MYSQL_AUDIT_CONNECTION_CLASS) |
50 | return 0; |
51 | |
52 | subclass_orig= *subclass; |
53 | |
54 | if (class == MYSQL_AUDIT_GENERAL_CLASS) |
55 | { |
56 | struct mysql_event_general *event= (struct mysql_event_general *) ev; |
57 | ev_302.general_error_code= event->general_error_code; |
58 | ev_302.general_thread_id= event->general_thread_id; |
59 | ev_302.general_user= event->general_user.str; |
60 | ev_302.general_user_length= (unsigned int)event->general_user.length; |
61 | ev_302.general_command= event->general_command.str; |
62 | ev_302.general_command_length= (unsigned int)event->general_command.length; |
63 | ev_302.general_query= event->general_query.str; |
64 | ev_302.general_query_length= (unsigned int)event->general_query.length; |
65 | ev_302.general_charset= event->general_charset; |
66 | ev_302.general_time= event->general_time; |
67 | ev_302.general_rows= event->general_rows; |
68 | if (get_db_mysql57(thd, &ev_302.database, &ev_302.database_length)) |
69 | { |
70 | ev_302.database= 0; |
71 | ev_302.database_length= 0; |
72 | } |
73 | ev= &ev_302; |
74 | switch (subclass_orig) |
75 | { |
76 | case MYSQL_AUDIT_GENERAL_LOG: |
77 | subclass_v3= 0; |
78 | ev_302.event_subclass= 0; |
79 | break; |
80 | case MYSQL_AUDIT_GENERAL_ERROR: |
81 | subclass_v3= 1; |
82 | ev_302.event_subclass= 1; |
83 | break; |
84 | case MYSQL_AUDIT_GENERAL_RESULT: |
85 | subclass_v3= 2; |
86 | ev_302.event_subclass= 2; |
87 | break; |
88 | case MYSQL_AUDIT_GENERAL_STATUS: |
89 | { |
90 | subclass_v3= 3; |
91 | ev_302.event_subclass= 3; |
92 | break; |
93 | } |
94 | default: |
95 | return 0; |
96 | } |
97 | } |
98 | else /* if (class == MYSQL_AUDIT_CONNECTION_CLASS) */ |
99 | { |
100 | switch (subclass_orig) |
101 | { |
102 | case MYSQL_AUDIT_CONNECTION_CONNECT: |
103 | subclass_v3= 0; |
104 | break; |
105 | case MYSQL_AUDIT_CONNECTION_DISCONNECT: |
106 | subclass_v3= 1; |
107 | break; |
108 | default: |
109 | return 0; |
110 | } |
111 | } |
112 | |
113 | *subclass= subclass_v3; |
114 | |
115 | auditing(thd, (int) class, ev); |
116 | |
117 | *subclass= subclass_orig; |
118 | return 0; |
119 | } |
120 | |
121 | |
122 | static struct st_mysql_audit mysql_descriptor = |
123 | { |
124 | MYSQL_AUDIT_INTERFACE_VERSION, |
125 | NULL, |
126 | auditing_v4, |
127 | { (unsigned long) MYSQL_AUDIT_GENERAL_ALL, |
128 | (unsigned long) MYSQL_AUDIT_CONNECTION_ALL, |
129 | (unsigned long) MYSQL_AUDIT_PARSE_ALL, |
130 | 0, /* This event class is currently not supported. */ |
131 | 0, /* This event class is currently not supported. */ |
132 | (unsigned long) MYSQL_AUDIT_GLOBAL_VARIABLE_ALL, |
133 | (unsigned long) MYSQL_AUDIT_SERVER_STARTUP_ALL, |
134 | (unsigned long) MYSQL_AUDIT_SERVER_SHUTDOWN_ALL, |
135 | (unsigned long) MYSQL_AUDIT_COMMAND_ALL, |
136 | (unsigned long) MYSQL_AUDIT_QUERY_ALL, |
137 | (unsigned long) MYSQL_AUDIT_STORED_PROGRAM_ALL } |
138 | #ifdef WHEN_MYSQL_BUG_FIXED |
139 | /* |
140 | By this moment MySQL just sends no notifications at all |
141 | when we request only those we actually need. |
142 | So we have to request everything and filter them inside the |
143 | handling function. |
144 | */ |
145 | { (unsigned long) MYSQL_AUDIT_GENERAL_ALL, |
146 | (unsigned long) (MYSQL_AUDIT_CONNECTION_CONNECT | |
147 | MYSQL_AUDIT_CONNECTION_DISCONNECT), |
148 | 0, |
149 | 0, /* This event class is currently not supported. */ |
150 | 0, /* This event class is currently not supported. */ |
151 | 0, |
152 | 0, |
153 | 0, |
154 | 0, |
155 | 0, |
156 | 0 |
157 | } |
158 | #endif /*WHEN_MYSQL_BUG_FIXED*/ |
159 | }; |
160 | |
161 | |
162 | void *mysql_v4_descriptor= &mysql_descriptor; |
163 | |
164 | |