diff options
author | Sergei Golubchik <serg@mariadb.org> | 2017-03-06 19:34:22 +0100 |
---|---|---|
committer | Sergei Golubchik <serg@mariadb.org> | 2017-03-10 18:21:27 +0100 |
commit | 0877eff4012ab1184112814a3492d23bf266f848 (patch) | |
tree | 1b34a6bbbd9c1e2d505a0806b85bdc521620083a | |
parent | 6305533de2fd38d43c149d4d7c847f65d68205c7 (diff) | |
download | mariadb-git-0877eff4012ab1184112814a3492d23bf266f848.tar.gz |
thd_rnd service
-rw-r--r-- | include/mysql/plugin_audit.h.pp | 6 | ||||
-rw-r--r-- | include/mysql/plugin_auth.h.pp | 6 | ||||
-rw-r--r-- | include/mysql/plugin_encryption.h.pp | 6 | ||||
-rw-r--r-- | include/mysql/plugin_ftparser.h.pp | 6 | ||||
-rw-r--r-- | include/mysql/plugin_password_validation.h.pp | 6 | ||||
-rw-r--r-- | include/mysql/service_thd_rnd.h | 62 | ||||
-rw-r--r-- | include/mysql/services.h | 1 | ||||
-rw-r--r-- | include/service_versions.h | 1 | ||||
-rw-r--r-- | libservices/CMakeLists.txt | 1 | ||||
-rw-r--r-- | libservices/thd_rnd_service.c | 17 | ||||
-rw-r--r-- | sql/password.c | 6 | ||||
-rw-r--r-- | sql/sql_acl.cc | 6 | ||||
-rw-r--r-- | sql/sql_class.cc | 22 | ||||
-rw-r--r-- | sql/sql_plugin_services.ic | 6 |
14 files changed, 148 insertions, 4 deletions
diff --git a/include/mysql/plugin_audit.h.pp b/include/mysql/plugin_audit.h.pp index 309bae1a0b0..c74fa4bacb7 100644 --- a/include/mysql/plugin_audit.h.pp +++ b/include/mysql/plugin_audit.h.pp @@ -219,6 +219,12 @@ extern struct thd_autoinc_service_st { } *thd_autoinc_service; void thd_get_autoinc(const void* thd, unsigned long* off, unsigned long* inc); +extern struct thd_rnd_service_st { + double (*thd_rnd_ptr)(void* thd); + void (*thd_c_r_p_ptr)(void* thd, char *to, size_t length); +} *thd_rnd_service; +double thd_rnd(void* thd); +void thd_create_random_password(void* thd, char *to, size_t length); extern struct thd_error_context_service_st { const char *(*thd_get_error_message_func)(const void* thd); unsigned int (*thd_get_error_number_func)(const void* thd); diff --git a/include/mysql/plugin_auth.h.pp b/include/mysql/plugin_auth.h.pp index 63ad776314d..c3e90210dd6 100644 --- a/include/mysql/plugin_auth.h.pp +++ b/include/mysql/plugin_auth.h.pp @@ -219,6 +219,12 @@ extern struct thd_autoinc_service_st { } *thd_autoinc_service; void thd_get_autoinc(const void* thd, unsigned long* off, unsigned long* inc); +extern struct thd_rnd_service_st { + double (*thd_rnd_ptr)(void* thd); + void (*thd_c_r_p_ptr)(void* thd, char *to, size_t length); +} *thd_rnd_service; +double thd_rnd(void* thd); +void thd_create_random_password(void* thd, char *to, size_t length); extern struct thd_error_context_service_st { const char *(*thd_get_error_message_func)(const void* thd); unsigned int (*thd_get_error_number_func)(const void* thd); diff --git a/include/mysql/plugin_encryption.h.pp b/include/mysql/plugin_encryption.h.pp index 86d4427bc03..3d027e58389 100644 --- a/include/mysql/plugin_encryption.h.pp +++ b/include/mysql/plugin_encryption.h.pp @@ -219,6 +219,12 @@ extern struct thd_autoinc_service_st { } *thd_autoinc_service; void thd_get_autoinc(const void* thd, unsigned long* off, unsigned long* inc); +extern struct thd_rnd_service_st { + double (*thd_rnd_ptr)(void* thd); + void (*thd_c_r_p_ptr)(void* thd, char *to, size_t length); +} *thd_rnd_service; +double thd_rnd(void* thd); +void thd_create_random_password(void* thd, char *to, size_t length); extern struct thd_error_context_service_st { const char *(*thd_get_error_message_func)(const void* thd); unsigned int (*thd_get_error_number_func)(const void* thd); diff --git a/include/mysql/plugin_ftparser.h.pp b/include/mysql/plugin_ftparser.h.pp index 595735f0cf5..44ac17fbc7b 100644 --- a/include/mysql/plugin_ftparser.h.pp +++ b/include/mysql/plugin_ftparser.h.pp @@ -219,6 +219,12 @@ extern struct thd_autoinc_service_st { } *thd_autoinc_service; void thd_get_autoinc(const void* thd, unsigned long* off, unsigned long* inc); +extern struct thd_rnd_service_st { + double (*thd_rnd_ptr)(void* thd); + void (*thd_c_r_p_ptr)(void* thd, char *to, size_t length); +} *thd_rnd_service; +double thd_rnd(void* thd); +void thd_create_random_password(void* thd, char *to, size_t length); extern struct thd_error_context_service_st { const char *(*thd_get_error_message_func)(const void* thd); unsigned int (*thd_get_error_number_func)(const void* thd); diff --git a/include/mysql/plugin_password_validation.h.pp b/include/mysql/plugin_password_validation.h.pp index 23a56273e51..8851ae77b4a 100644 --- a/include/mysql/plugin_password_validation.h.pp +++ b/include/mysql/plugin_password_validation.h.pp @@ -219,6 +219,12 @@ extern struct thd_autoinc_service_st { } *thd_autoinc_service; void thd_get_autoinc(const void* thd, unsigned long* off, unsigned long* inc); +extern struct thd_rnd_service_st { + double (*thd_rnd_ptr)(void* thd); + void (*thd_c_r_p_ptr)(void* thd, char *to, size_t length); +} *thd_rnd_service; +double thd_rnd(void* thd); +void thd_create_random_password(void* thd, char *to, size_t length); extern struct thd_error_context_service_st { const char *(*thd_get_error_message_func)(const void* thd); unsigned int (*thd_get_error_number_func)(const void* thd); diff --git a/include/mysql/service_thd_rnd.h b/include/mysql/service_thd_rnd.h new file mode 100644 index 00000000000..21133c7889f --- /dev/null +++ b/include/mysql/service_thd_rnd.h @@ -0,0 +1,62 @@ +#ifndef MYSQL_SERVICE_THD_RND_INCLUDED +/* Copyright (C) 2017 MariaDB Corporation + + 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 access to the thd-local random number generator. + + It's preferrable over the global one, because concurrent threads + can generate random numbers without fighting each other over the access + to the shared rnd state. +*/ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef MYSQL_ABI_CHECK +#include <stdlib.h> +#endif + +extern struct thd_rnd_service_st { + double (*thd_rnd_ptr)(MYSQL_THD thd); + void (*thd_c_r_p_ptr)(MYSQL_THD thd, char *to, size_t length); +} *thd_rnd_service; + +#ifdef MYSQL_DYNAMIC_PLUGIN +#define thd_rnd(A) thd_rnd_service->thd_rnd_ptr(A) +#define thd_create_random_password(A,B,C) thd_rnd_service->thd_c_r_p_ptr(A,B,C) +#else + +double thd_rnd(MYSQL_THD thd); + +/** + Generate string of printable random characters of requested length. + + @param to[out] Buffer for generation; must be at least length+1 bytes + long; result string is always null-terminated + @param length[in] How many random characters to put in buffer +*/ +void thd_create_random_password(MYSQL_THD thd, char *to, size_t length); + +#endif + +#ifdef __cplusplus +} +#endif + +#define MYSQL_SERVICE_THD_RND_INCLUDED +#endif diff --git a/include/mysql/services.h b/include/mysql/services.h index 3ba0ce6511c..6cb5f50dc82 100644 --- a/include/mysql/services.h +++ b/include/mysql/services.h @@ -32,6 +32,7 @@ extern "C" { #include <mysql/service_base64.h> #include <mysql/service_logger.h> #include <mysql/service_thd_autoinc.h> +#include <mysql/service_thd_rnd.h> #include <mysql/service_thd_error_context.h> #include <mysql/service_thd_specifics.h> #include <mysql/service_encryption.h> diff --git a/include/service_versions.h b/include/service_versions.h index f78697d277c..a0831792643 100644 --- a/include/service_versions.h +++ b/include/service_versions.h @@ -34,6 +34,7 @@ #define VERSION_wsrep 0x0201 #define VERSION_logger 0x0100 #define VERSION_base64 0x0100 +#define VERSION_thd_rnd 0x0100 #define VERSION_thd_autoinc 0x0100 #define VERSION_thd_error_context 0x0100 #define VERSION_thd_specifics 0x0100 diff --git a/libservices/CMakeLists.txt b/libservices/CMakeLists.txt index 04f3cb4b69b..5c789885b50 100644 --- a/libservices/CMakeLists.txt +++ b/libservices/CMakeLists.txt @@ -22,6 +22,7 @@ SET(MYSQLSERVICES_SOURCES thd_timezone_service.c thd_autoinc_service.c thd_error_context_service.c + thd_rnd_service.c thd_specifics_service.c progress_report_service.c debug_sync_service.c diff --git a/libservices/thd_rnd_service.c b/libservices/thd_rnd_service.c new file mode 100644 index 00000000000..fbba611a8ff --- /dev/null +++ b/libservices/thd_rnd_service.c @@ -0,0 +1,17 @@ +/* Copyright (C) 2017 MariaDB Corporation + + 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 thd_rnd_service= (void *) VERSION_thd_rnd; diff --git a/sql/password.c b/sql/password.c index 8d05f7d2375..02e4a0c37c7 100644 --- a/sql/password.c +++ b/sql/password.c @@ -38,7 +38,7 @@ The new authentication is performed in following manner: - SERVER: public_seed=create_random_string() + SERVER: public_seed=thd_create_random_password() send(public_seed) CLIENT: recv(public_seed) @@ -278,6 +278,7 @@ void make_password_from_salt_323(char *to, const ulong *salt) **************** MySQL 4.1.1 authentication routines ************* */ +#if MYSQL_VERSION_ID < 0x100200 /** Generate string of printable random characters of requested length. @@ -296,6 +297,9 @@ void create_random_string(char *to, uint length, *to= (char) (my_rnd(rand_st)*94+33); *to= '\0'; } +#else +#error +#endif /* Character to use as version identifier for version 4.1 */ diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index 142e2ecc198..8376d5cc767 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -11313,7 +11313,7 @@ static bool send_server_handshake_packet(MPVIO_EXT *mpvio, native_password_plugin will have to send it in a separate packet, adding one more round trip. */ - create_random_string(thd->scramble, SCRAMBLE_LENGTH, &thd->rand); + thd_create_random_password(thd, thd->scramble, SCRAMBLE_LENGTH); data= thd->scramble; } data_len= SCRAMBLE_LENGTH; @@ -12671,7 +12671,7 @@ static int native_password_authenticate(MYSQL_PLUGIN_VIO *vio, /* generate the scramble, or reuse the old one */ if (thd->scramble[SCRAMBLE_LENGTH]) { - create_random_string(thd->scramble, SCRAMBLE_LENGTH, &thd->rand); + thd_create_random_password(thd, thd->scramble, SCRAMBLE_LENGTH); /* and send it to the client */ if (mpvio->write_packet(mpvio, (uchar*)thd->scramble, SCRAMBLE_LENGTH + 1)) DBUG_RETURN(CR_AUTH_HANDSHAKE); @@ -12755,7 +12755,7 @@ static int old_password_authenticate(MYSQL_PLUGIN_VIO *vio, /* generate the scramble, or reuse the old one */ if (thd->scramble[SCRAMBLE_LENGTH]) { - create_random_string(thd->scramble, SCRAMBLE_LENGTH, &thd->rand); + thd_create_random_password(thd, thd->scramble, SCRAMBLE_LENGTH); /* and send it to the client */ if (mpvio->write_packet(mpvio, (uchar*)thd->scramble, SCRAMBLE_LENGTH + 1)) return CR_AUTH_HANDSHAKE; diff --git a/sql/sql_class.cc b/sql/sql_class.cc index fb58519b816..3a7e501c6c2 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -4475,6 +4475,28 @@ extern "C" int thd_is_connected(MYSQL_THD thd) } +extern "C" double thd_rnd(MYSQL_THD thd) +{ + return my_rnd(&thd->rand); +} + + +/** + Generate string of printable random characters of requested length. + + @param to[out] Buffer for generation; must be at least length+1 bytes + long; result string is always null-terminated + @param length[in] How many random characters to put in buffer +*/ +extern "C" void thd_create_random_password(MYSQL_THD thd, + char *to, size_t length) +{ + for (char *end= to + length; to < end; to++) + *to= (char) (my_rnd(&thd->rand)*94 + 33); + *to= '\0'; +} + + #ifdef INNODB_COMPATIBILITY_HOOKS extern "C" const struct charset_info_st *thd_charset(MYSQL_THD thd) { diff --git a/sql/sql_plugin_services.ic b/sql/sql_plugin_services.ic index e08870e9f98..564276a852a 100644 --- a/sql/sql_plugin_services.ic +++ b/sql/sql_plugin_services.ic @@ -119,6 +119,11 @@ static struct thd_autoinc_service_st thd_autoinc_handler= { thd_get_autoinc }; +static struct thd_rnd_service_st thd_rnd_handler= { + thd_rnd, + thd_create_random_password +}; + static struct base64_service_st base64_handler= { base64_needed_encoded_length, base64_encode_max_arg_length, @@ -205,6 +210,7 @@ static struct st_service_ref list_of_services[]= { "my_md5_service", VERSION_my_md5, &my_md5_handler}, { "logger_service", VERSION_logger, &logger_service_handler }, { "base64_service", VERSION_base64, &base64_handler }, + { "thd_rnd_service", VERSION_thd_rnd, &thd_rnd_handler }, { "thd_autoinc_service", VERSION_thd_autoinc, &thd_autoinc_handler }, { "wsrep_service", VERSION_wsrep, &wsrep_handler }, { "encryption_service", VERSION_encryption, &encryption_handler }, |