#At file:///Users/kgeorge/mysql/work/wl2940-trunk-bugfixing/ based on revid:jorgen.loland@stripped
3545 Georgi Kodinov 2011-01-21
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.
Fixed function signatures and some typos.
Moved the include guard define on top
Removed uncecessary casts.
Now with the new files.
added:
include/mysql/service_error_reporting.h
libservices/error_reporting_service.c
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 2011-01-21 14:03:58 +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-12-14 14:34:23 +0000
+++ b/include/mysql/plugin_audit.h.pp 2011-01-21 14:03:58 +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 *, ...);
+ int (*log_message)(void *, enum plugin_log_level, const char *, ...);
+} *error_reporting_service;
+void my_plugin_error(void *plugin, int code, const char *format, ...);
+int my_plugin_log_message(void *plugin, enum plugin_log_level level,
+ const char *format, ...);
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 2011-01-21 14:03:58 +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 *, ...);
+ int (*log_message)(void *, enum plugin_log_level, const char *, ...);
+} *error_reporting_service;
+void my_plugin_error(void *plugin, int code, const char *format, ...);
+int my_plugin_log_message(void *plugin, enum plugin_log_level level,
+ const char *format, ...);
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 2011-01-21 14:03:58 +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 *, ...);
+ int (*log_message)(void *, enum plugin_log_level, const char *, ...);
+} *error_reporting_service;
+void my_plugin_error(void *plugin, int code, const char *format, ...);
+int my_plugin_log_message(void *plugin, enum plugin_log_level level,
+ const char *format, ...);
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;
=== added file 'include/mysql/service_error_reporting.h'
--- a/include/mysql/service_error_reporting.h 1970-01-01 00:00:00 +0000
+++ b/include/mysql/service_error_reporting.h 2011-01-21 14:03:58 +0000
@@ -0,0 +1,71 @@
+/* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; version 2 of the
+ License.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
+
+/**
+ @file
+ This service provides functions to report error conditions and log to
+ mysql error log.
+*/
+
+#ifndef MYSQL_SERVICE_ERROR_REPORTING_INCLUDED
+#define MYSQL_SERVICE_ERROR_REPORTING_INCLUDED
+
+#ifndef MYSQL_ABI_CHECK
+#include <stdarg.h>
+#endif
+
+/* Max length of a error message. Should be kept in sync with MYSQL_ERRMSG_SIZE. */
+#define ERRMSGSIZE (512)
+
+/* keep in sync with the loglevel enum in my_sys.h */
+enum plugin_log_level
+{
+ MY_ERROR_LEVEL,
+ MY_WARNING_LEVEL,
+ MY_INFORMATION_LEVEL
+};
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern struct error_reporting_service
+{
+ /** send an error back to the user */
+ void (*error)(void *, int, const char *, ...);
+ /** write a message to the log */
+ int (*log_message)(void *, enum plugin_log_level, const char *, ...);
+} *error_reporting_service;
+
+#ifdef MYSQL_DYNAMIC_PLUGIN
+
+#define my_plugin_error error_reporting_service->error
+#define my_plugin_log_message error_reporting_service->log_message
+
+#else
+
+void my_plugin_error(void *plugin, int code, const char *format, ...);
+int my_plugin_log_message(void *plugin, enum plugin_log_level level,
+ const char *format, ...);
+
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
=== modified file 'include/mysql/services.h'
--- a/include/mysql/services.h 2010-06-07 14:01:39 +0000
+++ b/include/mysql/services.h 2011-01-21 14:03:58 +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 2011-01-21 14:03:58 +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 2011-01-21 14:03:58 +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})
=== added file 'libservices/error_reporting_service.c'
--- a/libservices/error_reporting_service.c 1970-01-01 00:00:00 +0000
+++ b/libservices/error_reporting_service.c 2011-01-21 14:03:58 +0000
@@ -0,0 +1,18 @@
+/* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; version 2 of the
+ License.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
+
+#include <service_versions.h>
+SERVICE_VERSION *error_reporting_service= (void*)VERSION_error_reporting;
=== modified file 'mysql-test/r/plugin_auth.result'
--- a/mysql-test/r/plugin_auth.result 2011-01-16 04:02:29 +0000
+++ b/mysql-test/r/plugin_auth.result 2011-01-21 14:03:58 +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 2011-01-21 14:03:58 +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 2011-01-16 04:02:29 +0000
+++ b/mysql-test/t/plugin_auth.test 2011-01-21 14:03:58 +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 2011-01-21 14:03:58 +0000
@@ -45,6 +45,20 @@
/********************* SERVER SIDE ****************************************/
/**
+ Handle assigned when loading the plugin.
+ Used with 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
*/
static int auth_test_plugin(MYSQL_PLUGIN_VIO *vio, MYSQL_SERVER_AUTH_INFO *info)
@@ -64,7 +78,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 +90,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 +110,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 2011-01-07 19:54:11 +0000
+++ b/sql/log.cc 2011-01-21 14:03:58 +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>
@@ -1879,7 +1880,6 @@ const char *MYSQL_LOG::generate_name(con
}
-
int error_log_print(enum loglevel level, const char *format,
va_list args)
{
@@ -2199,6 +2199,29 @@ void sql_print_information(const char *f
}
+extern "C"
+int my_plugin_log_message(void *plugin_ptr, plugin_log_level level,
+ const char *format, ...)
+{
+ char format2[ERRMSGSIZE];
+ int ret, lvl= level;
+ struct st_plugin_int *plugin = (st_plugin_int *) plugin_ptr;
+ va_list args;
+
+ DBUG_ASSERT(lvl >= ERROR_LEVEL || lvl <= INFORMATION_LEVEL);
+
+ if (lvl < ERROR_LEVEL || lvl > INFORMATION_LEVEL)
+ return 1;
+
+ va_start(args, format);
+ snprintf(format2, sizeof (format2) - 1, "Plugin %.*s reported message %s",
+ (int) plugin->name.length, plugin->name.str, format);
+ ret= error_log_print((loglevel) lvl, format2, args);
+ va_end(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-12-05 22:51:49 +0000
+++ b/sql/share/errmsg-utf8.txt 2011-01-21 14:03:58 +0000
@@ -6454,3 +6454,6 @@ ER_STMT_CACHE_FULL
eng "Multi-row statements required more than 'max_binlog_stmt_cache_size' bytes of storage; increase this mysqld variable and try again"
ER_BINLOG_STMT_CACHE_SIZE_GREATER_THAN_MAX
eng "Option binlog_stmt_cache_size (%lu) is greater than max_binlog_stmt_cache_size (%lu); setting binlog_stmt_cache_size equal to max_binlog_stmt_cache_size."
+
+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 2011-01-21 14:03:58 +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,25 @@ 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, ...)
+{
+ char message[ERRMSGSIZE];
+ struct st_plugin_int *plugin = (st_plugin_int *) plugin_ptr;
+ va_list args;
+
+ va_start(args, format);
+ my_vsnprintf(message, sizeof(message) - 1, format, args);
+ va_end(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 2011-01-21 14:03:58 +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-20110121140358-whdfeuxm1009n72g.bundle
| Thread |
|---|
| • bzr commit into mysql-trunk branch (Georgi.Kodinov:3545) WL#2940 | Georgi Kodinov | 24 Jan |