mirror of
https://github.com/MariaDB/server.git
synced 2025-04-18 13:15:32 +02:00
thd_rnd service
This commit is contained in:
parent
6305533de2
commit
0877eff401
14 changed files with 148 additions and 4 deletions
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
62
include/mysql/service_thd_rnd.h
Normal file
62
include/mysql/service_thd_rnd.h
Normal file
|
@ -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
|
|
@ -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>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
17
libservices/thd_rnd_service.c
Normal file
17
libservices/thd_rnd_service.c
Normal file
|
@ -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;
|
|
@ -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 */
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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 },
|
||||
|
|
Loading…
Add table
Reference in a new issue