1 /* Copyright (C) 2019, Alexey Botchkov and MariaDB Corporation
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 as published by
5 the Free Software Foundation; version 2 of the License.
6
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
11
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software
14 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */
15
16
17 #define PLUGIN_VERSION 0x100
18 #define PLUGIN_STR_VERSION "1.0.0"
19
20 #define _my_thread_var loc_thread_var
21
22 #include <my_config.h>
23 #include <assert.h>
24 #include <my_global.h>
25 #include <my_base.h>
26 #include <typelib.h>
27 //#include <mysql_com.h> /* for enum enum_server_command */
28 #include <mysql/plugin.h>
29 #include <mysql/plugin_audit.h>
30 //#include <string.h>
31
32
33 LEX_STRING * thd_query_string (MYSQL_THD thd);
34 unsigned long long thd_query_id(const MYSQL_THD thd);
35 size_t thd_query_safe(MYSQL_THD thd, char *buf, size_t buflen);
36 const char *thd_user_name(MYSQL_THD thd);
37 const char *thd_client_host(MYSQL_THD thd);
38 const char *thd_client_ip(MYSQL_THD thd);
39 LEX_CSTRING *thd_current_db(MYSQL_THD thd);
40 int thd_current_status(MYSQL_THD thd);
41 enum enum_server_command thd_current_command(MYSQL_THD thd);
42
43 int maria_compare_hostname(const char *wild_host, long wild_ip, long ip_mask,
44 const char *host, const char *ip);
45 void maria_update_hostname(const char **wild_host, long *wild_ip, long *ip_mask,
46 const char *host);
47
48 /* Status variables for SHOW STATUS */
49 static long test_passed= 0;
50 static struct st_mysql_show_var test_sql_status[]=
51 {
52 {"test_sql_service_passed", (char *)&test_passed, SHOW_LONG},
53 {0,0,0}
54 };
55
56 static my_bool do_test= TRUE;
57 static void run_test(MYSQL_THD thd, struct st_mysql_sys_var *var,
58 void *var_ptr, const void *save);
59 static MYSQL_SYSVAR_BOOL(run_test, do_test, PLUGIN_VAR_OPCMDARG,
60 "Perform the test now.", NULL, run_test, FALSE);
61 static struct st_mysql_sys_var* test_sql_vars[]=
62 {
63 MYSQL_SYSVAR(run_test),
64 NULL
65 };
66
67
68 extern int execute_sql_command(const char *command,
69 char *hosts, char *names, char *filters);
70
71
72
do_tests()73 static int do_tests()
74 {
75 char plugins[1024];
76 char names[1024];
77 char dl[2048];
78 int result;
79
80 result= execute_sql_command("select 'plugin', name, dl from mysql.plugin",
81 plugins, names, dl);
82
83 return result;
84 }
85
86
auditing(MYSQL_THD thd,unsigned int event_class,const void * ev)87 void auditing(MYSQL_THD thd, unsigned int event_class, const void *ev)
88 {
89 }
90
91
run_test(MYSQL_THD thd,struct st_mysql_sys_var * var,void * var_ptr,const void * save)92 static void run_test(MYSQL_THD thd __attribute__((unused)),
93 struct st_mysql_sys_var *var __attribute__((unused)),
94 void *var_ptr __attribute__((unused)),
95 const void *save __attribute__((unused)))
96 {
97 test_passed= do_tests();
98 }
99
100
101 static int init_done= 0;
102
test_sql_service_plugin_init(void * p)103 static int test_sql_service_plugin_init(void *p __attribute__((unused)))
104 {
105 init_done= 1;
106 return 0;
107 }
108
109
test_sql_service_plugin_deinit(void * p)110 static int test_sql_service_plugin_deinit(void *p __attribute__((unused)))
111 {
112 if (!init_done)
113 return 0;
114
115 return 0;
116 }
117
118
119 static struct st_mysql_audit maria_descriptor =
120 {
121 MYSQL_AUDIT_INTERFACE_VERSION,
122 NULL,
123 auditing,
124 { MYSQL_AUDIT_GENERAL_CLASSMASK |
125 MYSQL_AUDIT_TABLE_CLASSMASK |
126 MYSQL_AUDIT_CONNECTION_CLASSMASK }
127 };
maria_declare_plugin(test_sql_service)128 maria_declare_plugin(test_sql_service)
129 {
130 MYSQL_AUDIT_PLUGIN,
131 &maria_descriptor,
132 "TEST_SQL_SERVICE",
133 "Alexey Botchkov (MariaDB Corporation)",
134 "Test SQL service",
135 PLUGIN_LICENSE_GPL,
136 test_sql_service_plugin_init,
137 test_sql_service_plugin_deinit,
138 PLUGIN_VERSION,
139 test_sql_status,
140 test_sql_vars,
141 PLUGIN_STR_VERSION,
142 MariaDB_PLUGIN_MATURITY_STABLE
143 }
144 maria_declare_plugin_end;
145
146