#At file:///Users/kgeorge/mysql/work/wl2940-trunk-bugfixing/ based on revid:marc.alff@stripped
3387 Georgi Kodinov 2010-12-03
WL#2940: plugin service: error reporting
Implement an error_reporting service.
Added tests to the authentication plugin to return a custom
error and to log a info message.
modified:
include/mysql/plugin.h
include/mysql/plugin_audit.h.pp
include/mysql/plugin_auth.h.pp
include/mysql/plugin_ftparser.h.pp
include/mysql/services.h
include/service_versions.h
libservices/CMakeLists.txt
mysql-test/r/plugin_auth.result
mysql-test/r/plugin_auth_qa_1.result
mysql-test/t/plugin_auth.test
plugin/auth/test_plugin.c
sql/log.cc
sql/share/errmsg-utf8.txt
sql/sql_error.cc
sql/sql_plugin_services.h
=== modified file 'include/mysql/plugin.h'
--- a/include/mysql/plugin.h 2010-10-21 09:49:16 +0000
+++ b/include/mysql/plugin.h 2010-12-03 12:56:00 +0000
@@ -48,6 +48,8 @@ class Item;
#define MYSQL_THD void*
#endif
+typedef void * MYSQL_PLUGIN;
+
#include <mysql/services.h>
#define MYSQL_XIDDATASIZE 128
@@ -409,8 +411,8 @@ struct st_mysql_plugin
const char *author; /* plugin author (for I_S.PLUGINS) */
const char *descr; /* general descriptive text (for I_S.PLUGINS) */
int license; /* the plugin license (PLUGIN_LICENSE_XXX) */
- int (*init)(void *); /* the function to invoke when plugin is loaded */
- int (*deinit)(void *);/* the function to invoke when plugin is unloaded */
+ int (*init)(MYSQL_PLUGIN); /* the function to invoke when plugin is loaded */
+ int (*deinit)(MYSQL_PLUGIN);/* the function to invoke when plugin is unloaded */
unsigned int version; /* plugin version (for I_S.PLUGINS) */
struct st_mysql_show_var *status_vars;
struct st_mysql_sys_var **system_vars;
=== modified file 'include/mysql/plugin_audit.h.pp'
--- a/include/mysql/plugin_audit.h.pp 2010-08-30 14:07:40 +0000
+++ b/include/mysql/plugin_audit.h.pp 2010-12-03 12:56:00 +0000
@@ -1,4 +1,5 @@
#include "plugin.h"
+typedef void * MYSQL_PLUGIN;
#include <mysql/services.h>
#include <mysql/service_my_snprintf.h>
extern struct my_snprintf_service_st {
@@ -52,6 +53,21 @@ extern struct my_thread_scheduler_servic
} *my_thread_scheduler_service;
int my_thread_scheduler_set(struct scheduler_functions *scheduler);
int my_thread_scheduler_reset();
+#include <mysql/service_error_reporting.h>
+enum plugin_log_level
+{
+ MY_ERROR_LEVEL,
+ MY_WARNING_LEVEL,
+ MY_INFORMATION_LEVEL
+};
+extern struct error_reporting_service
+{
+ void (*error)(void *, int, const char *, va_list);
+ int (*log_message)(void *, enum plugin_log_level, const char *, va_list);
+} *error_reporting_service;
+void my_plugin_error(void *plugin, int code, const char *format, va_list args);
+int my_plugin_log_message(void *plugin, enum plugin_log_level level,
+ const char *format, va_list args);
struct st_mysql_xid {
long formatID;
long gtrid_length;
@@ -88,8 +104,8 @@ struct st_mysql_plugin
const char *author;
const char *descr;
int license;
- int (*init)(void *);
- int (*deinit)(void *);
+ int (*init)(MYSQL_PLUGIN);
+ int (*deinit)(MYSQL_PLUGIN);
unsigned int version;
struct st_mysql_show_var *status_vars;
struct st_mysql_sys_var **system_vars;
=== modified file 'include/mysql/plugin_auth.h.pp'
--- a/include/mysql/plugin_auth.h.pp 2010-10-05 12:26:49 +0000
+++ b/include/mysql/plugin_auth.h.pp 2010-12-03 12:56:00 +0000
@@ -1,4 +1,5 @@
#include <mysql/plugin.h>
+typedef void * MYSQL_PLUGIN;
#include <mysql/services.h>
#include <mysql/service_my_snprintf.h>
extern struct my_snprintf_service_st {
@@ -52,6 +53,21 @@ extern struct my_thread_scheduler_servic
} *my_thread_scheduler_service;
int my_thread_scheduler_set(struct scheduler_functions *scheduler);
int my_thread_scheduler_reset();
+#include <mysql/service_error_reporting.h>
+enum plugin_log_level
+{
+ MY_ERROR_LEVEL,
+ MY_WARNING_LEVEL,
+ MY_INFORMATION_LEVEL
+};
+extern struct error_reporting_service
+{
+ void (*error)(void *, int, const char *, va_list);
+ int (*log_message)(void *, enum plugin_log_level, const char *, va_list);
+} *error_reporting_service;
+void my_plugin_error(void *plugin, int code, const char *format, va_list args);
+int my_plugin_log_message(void *plugin, enum plugin_log_level level,
+ const char *format, va_list args);
struct st_mysql_xid {
long formatID;
long gtrid_length;
@@ -88,8 +104,8 @@ struct st_mysql_plugin
const char *author;
const char *descr;
int license;
- int (*init)(void *);
- int (*deinit)(void *);
+ int (*init)(MYSQL_PLUGIN);
+ int (*deinit)(MYSQL_PLUGIN);
unsigned int version;
struct st_mysql_show_var *status_vars;
struct st_mysql_sys_var **system_vars;
=== modified file 'include/mysql/plugin_ftparser.h.pp'
--- a/include/mysql/plugin_ftparser.h.pp 2010-08-30 14:07:40 +0000
+++ b/include/mysql/plugin_ftparser.h.pp 2010-12-03 12:56:00 +0000
@@ -1,4 +1,5 @@
#include "plugin.h"
+typedef void * MYSQL_PLUGIN;
#include <mysql/services.h>
#include <mysql/service_my_snprintf.h>
extern struct my_snprintf_service_st {
@@ -52,6 +53,21 @@ extern struct my_thread_scheduler_servic
} *my_thread_scheduler_service;
int my_thread_scheduler_set(struct scheduler_functions *scheduler);
int my_thread_scheduler_reset();
+#include <mysql/service_error_reporting.h>
+enum plugin_log_level
+{
+ MY_ERROR_LEVEL,
+ MY_WARNING_LEVEL,
+ MY_INFORMATION_LEVEL
+};
+extern struct error_reporting_service
+{
+ void (*error)(void *, int, const char *, va_list);
+ int (*log_message)(void *, enum plugin_log_level, const char *, va_list);
+} *error_reporting_service;
+void my_plugin_error(void *plugin, int code, const char *format, va_list args);
+int my_plugin_log_message(void *plugin, enum plugin_log_level level,
+ const char *format, va_list args);
struct st_mysql_xid {
long formatID;
long gtrid_length;
@@ -88,8 +104,8 @@ struct st_mysql_plugin
const char *author;
const char *descr;
int license;
- int (*init)(void *);
- int (*deinit)(void *);
+ int (*init)(MYSQL_PLUGIN);
+ int (*deinit)(MYSQL_PLUGIN);
unsigned int version;
struct st_mysql_show_var *status_vars;
struct st_mysql_sys_var **system_vars;
=== modified file 'include/mysql/services.h'
--- a/include/mysql/services.h 2010-06-07 14:01:39 +0000
+++ b/include/mysql/services.h 2010-12-03 12:56:00 +0000
@@ -22,6 +22,7 @@ extern "C" {
#include <mysql/service_thd_alloc.h>
#include <mysql/service_thd_wait.h>
#include <mysql/service_thread_scheduler.h>
+#include <mysql/service_error_reporting.h>
#ifdef __cplusplus
}
=== modified file 'include/service_versions.h'
--- a/include/service_versions.h 2010-06-07 14:01:39 +0000
+++ b/include/service_versions.h 2010-12-03 12:56:00 +0000
@@ -23,3 +23,4 @@
#define VERSION_thd_alloc 0x0100
#define VERSION_thd_wait 0x0100
#define VERSION_my_thread_scheduler 0x0100
+#define VERSION_error_reporting 0x0100
=== modified file 'libservices/CMakeLists.txt'
--- a/libservices/CMakeLists.txt 2010-11-13 22:16:52 +0000
+++ b/libservices/CMakeLists.txt 2010-12-03 12:56:00 +0000
@@ -19,6 +19,7 @@ SET(MYSQLSERVICES_SOURCES
my_snprintf_service.c
thd_alloc_service.c
thd_wait_service.c
+ error_reporting_service.c
my_thread_scheduler_service.c)
ADD_LIBRARY(mysqlservices ${MYSQLSERVICES_SOURCES})
=== modified file 'mysql-test/r/plugin_auth.result'
--- a/mysql-test/r/plugin_auth.result 2010-11-19 14:35:04 +0000
+++ b/mysql-test/r/plugin_auth.result 2010-12-03 12:56:00 +0000
@@ -74,7 +74,7 @@ REVOKE ALL PRIVILEGES ON test_grant_db.*
GRANT ALL PRIVILEGES ON test_grant_db.* TO new_grant_user
IDENTIFIED BY 'unused_password';
# make sure password doesn't take precendence
-ERROR 28000: Access denied for user 'new_grant_user'@'localhost' (using password: YES)
+ERROR HY000: Plugin test_plugin_server reported error (code: 42000) : Wrong password supplied for plug_dest
#make sure plugin auth still available
select USER(),CURRENT_USER();
USER() CURRENT_USER()
=== modified file 'mysql-test/r/plugin_auth_qa_1.result'
--- a/mysql-test/r/plugin_auth_qa_1.result 2010-10-20 14:56:09 +0000
+++ b/mysql-test/r/plugin_auth_qa_1.result 2010-12-03 12:56:00 +0000
@@ -70,7 +70,7 @@ plug_user@localhost
RENAME USER plug_dest TO new_dest;
ERROR 1045 (28000): Access denied for user 'plug_user'@'localhost' (using password: YES)
GRANT PROXY ON new_dest TO plug_user;
-ERROR 1045 (28000): Access denied for user 'plug_user'@'localhost' (using password: YES)
+ERROR 1719 (HY000): Plugin test_plugin_server reported error (code: 42000) : Wrong password supplied for plug_dest
SELECT user,plugin,authentication_string FROM mysql.user WHERE user != 'root';
user plugin authentication_string
new_dest
@@ -88,7 +88,7 @@ plug_user@localhost
RENAME USER plug_dest TO new_dest;
ERROR 1045 (28000): Access denied for user 'plug_user'@'localhost' (using password: YES)
GRANT PROXY ON new_dest TO plug_user;
-ERROR 1045 (28000): Access denied for user 'plug_user'@'localhost' (using password: YES)
+ERROR 1719 (HY000): Plugin test_plugin_server reported error (code: 42000) : Wrong password supplied for plug_dest
SELECT user,plugin,authentication_string FROM mysql.user WHERE user != 'root';
user plugin authentication_string
new_dest
=== modified file 'mysql-test/t/plugin_auth.test'
--- a/mysql-test/t/plugin_auth.test 2010-11-19 14:35:04 +0000
+++ b/mysql-test/t/plugin_auth.test 2010-12-03 12:56:00 +0000
@@ -101,7 +101,7 @@ GRANT ALL PRIVILEGES ON test_grant_db.*
--echo # make sure password doesn't take precendence
--disable_query_log
---error ER_ACCESS_DENIED_ERROR
+--error ER_PLUGIN_ERROR
connect(plug_con_grant_deny,localhost,new_grant_user,unused_password);
--enable_query_log
=== modified file 'plugin/auth/test_plugin.c'
--- a/plugin/auth/test_plugin.c 2010-10-27 15:12:17 +0000
+++ b/plugin/auth/test_plugin.c 2010-12-03 12:56:00 +0000
@@ -44,6 +44,17 @@
/********************* SERVER SIDE ****************************************/
+/* needed for the error reporting functions */
+static MYSQL_PLUGIN plugin_info_ptr;
+
+static int
+test_plugin_init (MYSQL_PLUGIN plugin_info)
+{
+ plugin_info_ptr= plugin_info;
+ return 0;
+}
+
+
/**
dialog test plugin mimicking the ordinary auth mechanism. Used to test the auth plugin API
*/
@@ -64,7 +75,11 @@ static int auth_test_plugin(MYSQL_PLUGIN
/* fail if the password is wrong */
if (strcmp((const char *) pkt, info->auth_string))
+ {
+ my_plugin_error (plugin_info_ptr, 42000,
+ "Wrong password supplied for %s", info->auth_string);
return CR_ERROR;
+ }
/* copy auth string as a destination name to check it */
strcpy (info->authenticated_as, info->auth_string);
@@ -72,6 +87,8 @@ static int auth_test_plugin(MYSQL_PLUGIN
/* copy something into the external user name */
strcpy (info->external_user, info->auth_string);
+ my_plugin_log_message(plugin_info_ptr, MY_INFORMATION_LEVEL,
+ "successfully authenticated user %s", info->authenticated_as);
return CR_OK;
}
@@ -90,7 +107,7 @@ mysql_declare_plugin(test_plugin)
"Georgi Kodinov",
"plugin API test plugin",
PLUGIN_LICENSE_GPL,
- NULL,
+ test_plugin_init,
NULL,
0x0100,
NULL,
=== modified file 'sql/log.cc'
--- a/sql/log.cc 2010-11-16 12:38:17 +0000
+++ b/sql/log.cc 2010-12-03 12:56:00 +0000
@@ -34,6 +34,7 @@
#include "tztime.h" // my_tz_OFFSET0, struct Time_zone
#include "sql_acl.h" // SUPER_ACL
#include "sql_audit.h"
+#include "mysql/service_error_reporting.h"
#include <my_dir.h>
#include <stdarg.h>
@@ -1875,7 +1876,6 @@ const char *MYSQL_LOG::generate_name(con
}
-
int error_log_print(enum loglevel level, const char *format,
va_list args)
{
@@ -2251,6 +2251,26 @@ void sql_print_information(const char *f
}
+extern "C"
+int my_plugin_log_message(void *plugin_ptr, enum plugin_log_level level,
+ const char *format, va_list args)
+{
+ char format2[ERRMSGSIZE];
+ int ret, lvl= (int) level;
+ struct st_plugin_int *plugin = (st_plugin_int *) plugin_ptr;
+
+ DBUG_ASSERT(lvl >= (int) ERROR_LEVEL || lvl <= (int) INFORMATION_LEVEL);
+
+ if (lvl < (int) ERROR_LEVEL || lvl > (int) INFORMATION_LEVEL)
+ return 1;
+
+ snprintf (format2, sizeof (format2) - 1, "Plugin %.*s reported message %s",
+ (int) plugin->name.length, plugin->name.str, format);
+ ret= error_log_print((enum loglevel) lvl, format2, args);
+ return ret;
+}
+
+
/********* transaction coordinator log for 2pc - mmap() based solution *******/
/*
=== modified file 'sql/share/errmsg-utf8.txt'
--- a/sql/share/errmsg-utf8.txt 2010-10-29 09:43:58 +0000
+++ b/sql/share/errmsg-utf8.txt 2010-12-03 12:56:00 +0000
@@ -6439,3 +6439,6 @@ ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE_MA
ER_PARTITION_EXCHANGE_FOREIGN_KEY
eng "Table to exchange with partition has foreign key references: '%-.64s'"
swe "Tabellen att byta ut mot partition har foreign key referenser: '%-.64s'"
+
+ER_PLUGIN_ERROR
+ eng "Plugin %.*s reported error (code: %d) : %s"
=== modified file 'sql/sql_error.cc'
--- a/sql/sql_error.cc 2010-11-18 16:34:56 +0000
+++ b/sql/sql_error.cc 2010-12-03 12:56:00 +0000
@@ -45,6 +45,7 @@ This file contains the implementation of
#include "unireg.h"
#include "sql_error.h"
#include "sp_rcontext.h"
+#include "mysql/service_error_reporting.h"
/*
Design notes about MYSQL_ERROR::m_message_text.
@@ -622,6 +623,22 @@ void push_warning_printf(THD *thd, MYSQL
}
+/*
+ Keep in sync with the definition in ../include/mysql/service_error_reporting.h
+*/
+extern "C"
+void my_plugin_error(void *plugin_ptr, int code, const char *format, va_list args)
+{
+ char message[ERRMSGSIZE];
+ struct st_plugin_int *plugin = (st_plugin_int *) plugin_ptr;
+
+ my_vsnprintf(message, sizeof(message) - 1, format, args);
+
+ my_error(ER_PLUGIN_ERROR, MYF(0),
+ (int) plugin->name.length, plugin->name.str, code, message);
+}
+
+
/*
Send all notes, errors or warnings to the client in a result set
=== modified file 'sql/sql_plugin_services.h'
--- a/sql/sql_plugin_services.h 2010-09-01 13:05:01 +0000
+++ b/sql/sql_plugin_services.h 2010-12-03 12:56:00 +0000
@@ -46,6 +46,12 @@ static struct my_thread_scheduler_servic
my_thread_scheduler_reset,
};
+static struct error_reporting_service error_reporting_handler= {
+ my_plugin_error,
+ my_plugin_log_message
+};
+
+
static struct st_service_ref list_of_services[]=
{
@@ -54,5 +60,7 @@ static struct st_service_ref list_of_ser
{ "thd_wait_service", VERSION_thd_wait, &thd_wait_handler },
{ "my_thread_scheduler_service",
VERSION_my_thread_scheduler, &my_thread_scheduler_handler },
+ { "error_reporting_service",
+ VERSION_error_reporting, &error_reporting_handler },
};
Attachment: [text/bzr-bundle] bzr/georgi.kodinov@oracle.com-20101203125600-kl7pbe00yhxvmqsb.bundle
| Thread |
|---|
| • bzr commit into mysql-trunk-bugfixing branch (Georgi.Kodinov:3387) WL#2940 | Georgi Kodinov | 3 Dec |