move authentication_windows_client and mysql_clear_password clear client auth plugins
out of libmysql into separate dynamic plugins in the plugin/ directory. move dialog and auth_socket plugins out of the plugin directory with examples into dedicated directories in plugin/
This commit is contained in:
parent
55d13e8dc7
commit
c97f938bcf
56
include/mysql/auth_dialog_client.h
Normal file
56
include/mysql/auth_dialog_client.h
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
#ifndef MYSQL_AUTH_DIALOG_CLIENT_INCLUDED
|
||||||
|
/* Copyright (C) 2010 Sergei Golubchik and Monty Program Ab
|
||||||
|
|
||||||
|
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
||||||
|
|
||||||
|
/**
|
||||||
|
@file
|
||||||
|
|
||||||
|
Definitions needed to use Dialog client authentication plugin
|
||||||
|
*/
|
||||||
|
|
||||||
|
struct st_mysql;
|
||||||
|
|
||||||
|
#define MYSQL_AUTH_DIALOG_CLIENT_INCLUDED
|
||||||
|
|
||||||
|
/**
|
||||||
|
type of the mysql_authentication_dialog_ask function
|
||||||
|
|
||||||
|
@param mysql mysql
|
||||||
|
@param type type of the input
|
||||||
|
1 - ordinary string input
|
||||||
|
2 - password string
|
||||||
|
@param prompt prompt
|
||||||
|
@param buf a buffer to store the use input
|
||||||
|
@param buf_len the length of the buffer
|
||||||
|
|
||||||
|
@retval a pointer to the user input string.
|
||||||
|
It may be equal to 'buf' or to 'mysql->password'.
|
||||||
|
In all other cases it is assumed to be an allocated
|
||||||
|
string, and the "dialog" plugin will free() it.
|
||||||
|
*/
|
||||||
|
typedef char *(*mysql_authentication_dialog_ask_t)(struct st_mysql *mysql,
|
||||||
|
int type, const char *prompt, char *buf, int buf_len);
|
||||||
|
|
||||||
|
/**
|
||||||
|
first byte of the question string is the question "type".
|
||||||
|
It can be an "ordinary" or a "password" question.
|
||||||
|
The last bit set marks a last question in the authentication exchange.
|
||||||
|
*/
|
||||||
|
#define ORDINARY_QUESTION "\2"
|
||||||
|
#define LAST_QUESTION "\3"
|
||||||
|
#define PASSWORD_QUESTION "\4"
|
||||||
|
#define LAST_PASSWORD "\5"
|
||||||
|
|
||||||
|
#endif
|
@ -23,6 +23,30 @@
|
|||||||
*/
|
*/
|
||||||
#define MYSQL_CLIENT_PLUGIN_INCLUDED
|
#define MYSQL_CLIENT_PLUGIN_INCLUDED
|
||||||
|
|
||||||
|
/*
|
||||||
|
On Windows, exports from DLL need to be declared
|
||||||
|
Also, plugin needs to be declared as extern "C" because MSVC
|
||||||
|
unlike other compilers, uses C++ mangling for variables not only
|
||||||
|
for functions.
|
||||||
|
*/
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
#if defined(MYSQL_DYNAMIC_PLUGIN)
|
||||||
|
#ifdef __cplusplus
|
||||||
|
#define MYSQL_PLUGIN_EXPORT extern "C" __declspec(dllexport)
|
||||||
|
#else
|
||||||
|
#define MYSQL_PLUGIN_EXPORT __declspec(dllexport)
|
||||||
|
#endif
|
||||||
|
#else /* MYSQL_DYNAMIC_PLUGIN */
|
||||||
|
#ifdef __cplusplus
|
||||||
|
#define MYSQL_PLUGIN_EXPORT extern "C"
|
||||||
|
#else
|
||||||
|
#define MYSQL_PLUGIN_EXPORT
|
||||||
|
#endif
|
||||||
|
#endif /*MYSQL_DYNAMIC_PLUGIN */
|
||||||
|
#else /*_MSC_VER */
|
||||||
|
#define MYSQL_PLUGIN_EXPORT
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef MYSQL_ABI_CHECK
|
#ifndef MYSQL_ABI_CHECK
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -74,24 +98,8 @@ struct st_mysql_client_plugin_AUTHENTICATION
|
|||||||
int (*authenticate_user)(MYSQL_PLUGIN_VIO *vio, struct st_mysql *mysql);
|
int (*authenticate_user)(MYSQL_PLUGIN_VIO *vio, struct st_mysql *mysql);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
#include <mysql/auth_dialog_client.h>
|
||||||
type of the mysql_authentication_dialog_ask function
|
|
||||||
|
|
||||||
@param mysql mysql
|
|
||||||
@param type type of the input
|
|
||||||
1 - ordinary string input
|
|
||||||
2 - password string
|
|
||||||
@param prompt prompt
|
|
||||||
@param buf a buffer to store the use input
|
|
||||||
@param buf_len the length of the buffer
|
|
||||||
|
|
||||||
@retval a pointer to the user input string.
|
|
||||||
It may be equal to 'buf' or to 'mysql->password'.
|
|
||||||
In all other cases it is assumed to be an allocated
|
|
||||||
string, and the "dialog" plugin will free() it.
|
|
||||||
*/
|
|
||||||
typedef char *(*mysql_authentication_dialog_ask_t)(struct st_mysql *mysql,
|
|
||||||
int type, const char *prompt, char *buf, int buf_len);
|
|
||||||
/******** using plugins ************/
|
/******** using plugins ************/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -24,6 +24,8 @@ struct st_mysql_client_plugin_AUTHENTICATION
|
|||||||
int type; unsigned int interface_version; const char *name; const char *author; const char *desc; unsigned int version[3]; const char *license; void *mysql_api; int (*init)(char *, size_t, int, va_list); int (*deinit)(); int (*options)(const char *option, const void *);
|
int type; unsigned int interface_version; const char *name; const char *author; const char *desc; unsigned int version[3]; const char *license; void *mysql_api; int (*init)(char *, size_t, int, va_list); int (*deinit)(); int (*options)(const char *option, const void *);
|
||||||
int (*authenticate_user)(MYSQL_PLUGIN_VIO *vio, struct st_mysql *mysql);
|
int (*authenticate_user)(MYSQL_PLUGIN_VIO *vio, struct st_mysql *mysql);
|
||||||
};
|
};
|
||||||
|
#include <mysql/auth_dialog_client.h>
|
||||||
|
struct st_mysql;
|
||||||
typedef char *(*mysql_authentication_dialog_ask_t)(struct st_mysql *mysql,
|
typedef char *(*mysql_authentication_dialog_ask_t)(struct st_mysql *mysql,
|
||||||
int type, const char *prompt, char *buf, int buf_len);
|
int type, const char *prompt, char *buf, int buf_len);
|
||||||
struct st_mysql_client_plugin *
|
struct st_mysql_client_plugin *
|
||||||
|
@ -134,12 +134,6 @@ CACHE INTERNAL "Functions exported by client API"
|
|||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
IF(WIN32)
|
|
||||||
ADD_SUBDIRECTORY(authentication_win)
|
|
||||||
SET(WITH_AUTHENTICATION_WIN 1)
|
|
||||||
ADD_DEFINITIONS(-DAUTHENTICATION_WIN)
|
|
||||||
ENDIF(WIN32)
|
|
||||||
|
|
||||||
SET(CLIENT_SOURCES
|
SET(CLIENT_SOURCES
|
||||||
get_password.c
|
get_password.c
|
||||||
libmysql.c
|
libmysql.c
|
||||||
|
17
plugin/auth_dialog/CMakeLists.txt
Normal file
17
plugin/auth_dialog/CMakeLists.txt
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
# Copyright (c) 2010, 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
|
||||||
|
|
||||||
|
MYSQL_ADD_PLUGIN(dialog dialog.c MODULE_ONLY)
|
@ -43,138 +43,13 @@
|
|||||||
# define _GNU_SOURCE /* for RTLD_DEFAULT */
|
# define _GNU_SOURCE /* for RTLD_DEFAULT */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <mysql/plugin_auth.h>
|
|
||||||
#include <mysql/client_plugin.h>
|
#include <mysql/client_plugin.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <mysql.h>
|
||||||
|
#include <dlfcn.h>
|
||||||
|
|
||||||
/**
|
|
||||||
first byte of the question string is the question "type".
|
|
||||||
It can be an "ordinary" or a "password" question.
|
|
||||||
The last bit set marks a last question in the authentication exchange.
|
|
||||||
*/
|
|
||||||
#define ORDINARY_QUESTION "\2"
|
|
||||||
#define LAST_QUESTION "\3"
|
|
||||||
#define PASSWORD_QUESTION "\4"
|
|
||||||
#define LAST_PASSWORD "\5"
|
|
||||||
|
|
||||||
/********************* SERVER SIDE ****************************************/
|
|
||||||
|
|
||||||
/**
|
|
||||||
dialog demo with two questions, one password and one, the last, ordinary.
|
|
||||||
*/
|
|
||||||
static int two_questions(MYSQL_PLUGIN_VIO *vio, MYSQL_SERVER_AUTH_INFO *info)
|
|
||||||
{
|
|
||||||
unsigned char *pkt;
|
|
||||||
int pkt_len;
|
|
||||||
|
|
||||||
/* send a password question */
|
|
||||||
if (vio->write_packet(vio,
|
|
||||||
(const unsigned char *) PASSWORD_QUESTION "Password, please:",
|
|
||||||
18))
|
|
||||||
return CR_ERROR;
|
|
||||||
|
|
||||||
/* read the answer */
|
|
||||||
if ((pkt_len= vio->read_packet(vio, &pkt)) < 0)
|
|
||||||
return CR_ERROR;
|
|
||||||
|
|
||||||
info->password_used= PASSWORD_USED_YES;
|
|
||||||
|
|
||||||
/* fail if the password is wrong */
|
|
||||||
if (strcmp((const char *) pkt, info->auth_string))
|
|
||||||
return CR_ERROR;
|
|
||||||
|
|
||||||
/* send the last, ordinary, question */
|
|
||||||
if (vio->write_packet(vio,
|
|
||||||
(const unsigned char *) LAST_QUESTION "Are you sure ?",
|
|
||||||
15))
|
|
||||||
return CR_ERROR;
|
|
||||||
|
|
||||||
/* read the answer */
|
|
||||||
if ((pkt_len= vio->read_packet(vio, &pkt)) < 0)
|
|
||||||
return CR_ERROR;
|
|
||||||
|
|
||||||
/* check the reply */
|
|
||||||
return strcmp((const char *) pkt, "yes, of course") ? CR_ERROR : CR_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct st_mysql_auth two_handler=
|
|
||||||
{
|
|
||||||
MYSQL_AUTHENTICATION_INTERFACE_VERSION,
|
|
||||||
"dialog", /* requires dialog client plugin */
|
|
||||||
two_questions
|
|
||||||
};
|
|
||||||
|
|
||||||
/* dialog demo where the number of questions is not known in advance */
|
|
||||||
static int three_attempts(MYSQL_PLUGIN_VIO *vio, MYSQL_SERVER_AUTH_INFO *info)
|
|
||||||
{
|
|
||||||
unsigned char *pkt;
|
|
||||||
int pkt_len, i;
|
|
||||||
|
|
||||||
for (i= 0; i < 3; i++)
|
|
||||||
{
|
|
||||||
/* send the prompt */
|
|
||||||
if (vio->write_packet(vio,
|
|
||||||
(const unsigned char *) PASSWORD_QUESTION "Password, please:", 18))
|
|
||||||
return CR_ERROR;
|
|
||||||
|
|
||||||
/* read the password */
|
|
||||||
if ((pkt_len= vio->read_packet(vio, &pkt)) < 0)
|
|
||||||
return CR_ERROR;
|
|
||||||
|
|
||||||
info->password_used= PASSWORD_USED_YES;
|
|
||||||
|
|
||||||
/*
|
|
||||||
finish, if the password is correct.
|
|
||||||
note, that we did not mark the prompt packet as "last"
|
|
||||||
*/
|
|
||||||
if (strcmp((const char *) pkt, info->auth_string) == 0)
|
|
||||||
return CR_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
return CR_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct st_mysql_auth three_handler=
|
|
||||||
{
|
|
||||||
MYSQL_AUTHENTICATION_INTERFACE_VERSION,
|
|
||||||
"dialog", /* requires dialog client plugin */
|
|
||||||
three_attempts
|
|
||||||
};
|
|
||||||
|
|
||||||
mysql_declare_plugin(dialog)
|
|
||||||
{
|
|
||||||
MYSQL_AUTHENTICATION_PLUGIN,
|
|
||||||
&two_handler,
|
|
||||||
"two_questions",
|
|
||||||
"Sergei Golubchik",
|
|
||||||
"Dialog plugin demo 1",
|
|
||||||
PLUGIN_LICENSE_GPL,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
0x0100,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
NULL
|
|
||||||
},
|
|
||||||
{
|
|
||||||
MYSQL_AUTHENTICATION_PLUGIN,
|
|
||||||
&three_handler,
|
|
||||||
"three_attempts",
|
|
||||||
"Sergei Golubchik",
|
|
||||||
"Dialog plugin demo 2",
|
|
||||||
PLUGIN_LICENSE_GPL,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
0x0100,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
NULL
|
|
||||||
}
|
|
||||||
mysql_declare_plugin_end;
|
|
||||||
|
|
||||||
/********************* CLIENT SIDE ***************************************/
|
|
||||||
/*
|
/*
|
||||||
This plugin performs a dialog with the user, asking questions and
|
This plugin performs a dialog with the user, asking questions and
|
||||||
reading answers. Depending on the client it may be desirable to do it
|
reading answers. Depending on the client it may be desirable to do it
|
||||||
@ -186,9 +61,6 @@ mysql_declare_plugin_end;
|
|||||||
dialog plugin will use it for communication with the user. Otherwise
|
dialog plugin will use it for communication with the user. Otherwise
|
||||||
a default fgets() based implementation will be used.
|
a default fgets() based implementation will be used.
|
||||||
*/
|
*/
|
||||||
#include <mysql.h>
|
|
||||||
#include <dlfcn.h>
|
|
||||||
|
|
||||||
static mysql_authentication_dialog_ask_t ask;
|
static mysql_authentication_dialog_ask_t ask;
|
||||||
|
|
||||||
static char *builtin_ask(MYSQL *mysql __attribute__((unused)),
|
static char *builtin_ask(MYSQL *mysql __attribute__((unused)),
|
@ -14,7 +14,7 @@
|
|||||||
# along with this program; if not, write to the Free Software
|
# along with this program; if not, write to the Free Software
|
||||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
MYSQL_ADD_PLUGIN(auth dialog.c
|
MYSQL_ADD_PLUGIN(dialog_examples dialog_examples.c
|
||||||
MODULE_ONLY)
|
MODULE_ONLY)
|
||||||
MYSQL_ADD_PLUGIN(auth_test_plugin test_plugin.c
|
MYSQL_ADD_PLUGIN(auth_test_plugin test_plugin.c
|
||||||
MODULE_ONLY)
|
MODULE_ONLY)
|
||||||
@ -27,15 +27,5 @@ MYSQL_ADD_PLUGIN(qa_auth_server qa_auth_server.c
|
|||||||
MYSQL_ADD_PLUGIN(qa_auth_client qa_auth_client.c
|
MYSQL_ADD_PLUGIN(qa_auth_client qa_auth_client.c
|
||||||
MODULE_ONLY)
|
MODULE_ONLY)
|
||||||
|
|
||||||
CHECK_CXX_SOURCE_COMPILES(
|
MYSQL_ADD_PLUGIN(mysql_clear_password clear_password_client.c
|
||||||
"#define _GNU_SOURCE
|
|
||||||
#include <sys/socket.h>
|
|
||||||
int main() {
|
|
||||||
struct ucred cred;
|
|
||||||
getsockopt(0, SOL_SOCKET, SO_PEERCRED, &cred, 0);
|
|
||||||
}" HAVE_PEERCRED)
|
|
||||||
|
|
||||||
IF(HAVE_PEERCRED)
|
|
||||||
MYSQL_ADD_PLUGIN(auth_socket auth_socket.c
|
|
||||||
MODULE_ONLY)
|
MODULE_ONLY)
|
||||||
ENDIF()
|
|
47
plugin/auth_examples/clear_password_client.c
Normal file
47
plugin/auth_examples/clear_password_client.c
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
/* Copyright (c) 2000, 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
||||||
|
|
||||||
|
#include <mysql/client_plugin.h>
|
||||||
|
#include <mysql.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
The main function of the mysql_clear_password authentication plugin.
|
||||||
|
*/
|
||||||
|
|
||||||
|
static int clear_password_auth_client(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql)
|
||||||
|
{
|
||||||
|
int res;
|
||||||
|
|
||||||
|
/* send password in clear text */
|
||||||
|
res= vio->write_packet(vio, (const unsigned char *) mysql->passwd,
|
||||||
|
strlen(mysql->passwd) + 1);
|
||||||
|
|
||||||
|
return res ? CR_ERROR : CR_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
mysql_declare_client_plugin(AUTHENTICATION)
|
||||||
|
"mysql_clear_password",
|
||||||
|
"Georgi Kodinov",
|
||||||
|
"Clear password authentication plugin",
|
||||||
|
{0,1,0},
|
||||||
|
"GPL",
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
clear_password_auth_client
|
||||||
|
mysql_end_client_plugin;
|
||||||
|
|
154
plugin/auth_examples/dialog_examples.c
Normal file
154
plugin/auth_examples/dialog_examples.c
Normal file
@ -0,0 +1,154 @@
|
|||||||
|
/* Copyright (C) 2010 Sergei Golubchik and Monty Program Ab
|
||||||
|
Copyright (c) 2010, 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
|
||||||
|
|
||||||
|
examples for dialog client authentication plugin
|
||||||
|
|
||||||
|
Two examples are provided: two_questions server plugin, that asks
|
||||||
|
the password and an "Are you sure?" question with a reply "yes, of course".
|
||||||
|
It demonstrates the usage of "password" (input is hidden) and "ordinary"
|
||||||
|
(input can be echoed) questions, and how to mark the last question,
|
||||||
|
to avoid an extra roundtrip.
|
||||||
|
|
||||||
|
And three_attempts plugin that gives the user three attempts to enter
|
||||||
|
a correct password. It shows the situation when a number of questions
|
||||||
|
is not known in advance.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <mysql/plugin_auth.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <mysql/auth_dialog_client.h>
|
||||||
|
|
||||||
|
/********************* SERVER SIDE ****************************************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
dialog demo with two questions, one password and one, the last, ordinary.
|
||||||
|
*/
|
||||||
|
static int two_questions(MYSQL_PLUGIN_VIO *vio, MYSQL_SERVER_AUTH_INFO *info)
|
||||||
|
{
|
||||||
|
unsigned char *pkt;
|
||||||
|
int pkt_len;
|
||||||
|
|
||||||
|
/* send a password question */
|
||||||
|
if (vio->write_packet(vio,
|
||||||
|
(const unsigned char *) PASSWORD_QUESTION "Password, please:",
|
||||||
|
18))
|
||||||
|
return CR_ERROR;
|
||||||
|
|
||||||
|
/* read the answer */
|
||||||
|
if ((pkt_len= vio->read_packet(vio, &pkt)) < 0)
|
||||||
|
return CR_ERROR;
|
||||||
|
|
||||||
|
info->password_used= PASSWORD_USED_YES;
|
||||||
|
|
||||||
|
/* fail if the password is wrong */
|
||||||
|
if (strcmp((const char *) pkt, info->auth_string))
|
||||||
|
return CR_ERROR;
|
||||||
|
|
||||||
|
/* send the last, ordinary, question */
|
||||||
|
if (vio->write_packet(vio,
|
||||||
|
(const unsigned char *) LAST_QUESTION "Are you sure ?",
|
||||||
|
15))
|
||||||
|
return CR_ERROR;
|
||||||
|
|
||||||
|
/* read the answer */
|
||||||
|
if ((pkt_len= vio->read_packet(vio, &pkt)) < 0)
|
||||||
|
return CR_ERROR;
|
||||||
|
|
||||||
|
/* check the reply */
|
||||||
|
return strcmp((const char *) pkt, "yes, of course") ? CR_ERROR : CR_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct st_mysql_auth two_handler=
|
||||||
|
{
|
||||||
|
MYSQL_AUTHENTICATION_INTERFACE_VERSION,
|
||||||
|
"dialog", /* requires dialog client plugin */
|
||||||
|
two_questions
|
||||||
|
};
|
||||||
|
|
||||||
|
/* dialog demo where the number of questions is not known in advance */
|
||||||
|
static int three_attempts(MYSQL_PLUGIN_VIO *vio, MYSQL_SERVER_AUTH_INFO *info)
|
||||||
|
{
|
||||||
|
unsigned char *pkt;
|
||||||
|
int pkt_len, i;
|
||||||
|
|
||||||
|
for (i= 0; i < 3; i++)
|
||||||
|
{
|
||||||
|
/* send the prompt */
|
||||||
|
if (vio->write_packet(vio,
|
||||||
|
(const unsigned char *) PASSWORD_QUESTION "Password, please:", 18))
|
||||||
|
return CR_ERROR;
|
||||||
|
|
||||||
|
/* read the password */
|
||||||
|
if ((pkt_len= vio->read_packet(vio, &pkt)) < 0)
|
||||||
|
return CR_ERROR;
|
||||||
|
|
||||||
|
info->password_used= PASSWORD_USED_YES;
|
||||||
|
|
||||||
|
/*
|
||||||
|
finish, if the password is correct.
|
||||||
|
note, that we did not mark the prompt packet as "last"
|
||||||
|
*/
|
||||||
|
if (strcmp((const char *) pkt, info->auth_string) == 0)
|
||||||
|
return CR_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
return CR_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct st_mysql_auth three_handler=
|
||||||
|
{
|
||||||
|
MYSQL_AUTHENTICATION_INTERFACE_VERSION,
|
||||||
|
"dialog", /* requires dialog client plugin */
|
||||||
|
three_attempts
|
||||||
|
};
|
||||||
|
|
||||||
|
mysql_declare_plugin(dialog)
|
||||||
|
{
|
||||||
|
MYSQL_AUTHENTICATION_PLUGIN,
|
||||||
|
&two_handler,
|
||||||
|
"two_questions",
|
||||||
|
"Sergei Golubchik",
|
||||||
|
"Dialog plugin demo 1",
|
||||||
|
PLUGIN_LICENSE_GPL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
0x0100,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MYSQL_AUTHENTICATION_PLUGIN,
|
||||||
|
&three_handler,
|
||||||
|
"three_attempts",
|
||||||
|
"Sergei Golubchik",
|
||||||
|
"Dialog plugin demo 2",
|
||||||
|
PLUGIN_LICENSE_GPL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
0x0100,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL
|
||||||
|
}
|
||||||
|
mysql_declare_plugin_end;
|
||||||
|
|
@ -21,16 +21,6 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
/**
|
|
||||||
first byte of the question string is the question "type".
|
|
||||||
It can be a "ordinary" or a "password" question.
|
|
||||||
The last bit set marks a last question in the authentication exchange.
|
|
||||||
*/
|
|
||||||
#define ORDINARY_QUESTION "\2"
|
|
||||||
#define LAST_QUESTION "\3"
|
|
||||||
#define LAST_PASSWORD "\4"
|
|
||||||
#define PASSWORD_QUESTION "\5"
|
|
||||||
|
|
||||||
/********************* CLIENT SIDE ***************************************/
|
/********************* CLIENT SIDE ***************************************/
|
||||||
/*
|
/*
|
||||||
client plugin used for testing the plugin API
|
client plugin used for testing the plugin API
|
@ -21,16 +21,6 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
/**
|
|
||||||
first byte of the question string is the question "type".
|
|
||||||
It can be a "ordinary" or a "password" question.
|
|
||||||
The last bit set marks a last question in the authentication exchange.
|
|
||||||
*/
|
|
||||||
#define ORDINARY_QUESTION "\2"
|
|
||||||
#define LAST_QUESTION "\3"
|
|
||||||
#define LAST_PASSWORD "\4"
|
|
||||||
#define PASSWORD_QUESTION "\5"
|
|
||||||
|
|
||||||
/********************* SERVER SIDE ****************************************/
|
/********************* SERVER SIDE ****************************************/
|
||||||
|
|
||||||
static int qa_auth_interface (MYSQL_PLUGIN_VIO *vio, MYSQL_SERVER_AUTH_INFO *info)
|
static int qa_auth_interface (MYSQL_PLUGIN_VIO *vio, MYSQL_SERVER_AUTH_INFO *info)
|
@ -21,16 +21,6 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
/**
|
|
||||||
first byte of the question string is the question "type".
|
|
||||||
It can be a "ordinary" or a "password" question.
|
|
||||||
The last bit set marks a last question in the authentication exchange.
|
|
||||||
*/
|
|
||||||
#define ORDINARY_QUESTION "\2"
|
|
||||||
#define LAST_QUESTION "\3"
|
|
||||||
#define LAST_PASSWORD "\4"
|
|
||||||
#define PASSWORD_QUESTION "\5"
|
|
||||||
|
|
||||||
/********************* SERVER SIDE ****************************************/
|
/********************* SERVER SIDE ****************************************/
|
||||||
|
|
||||||
static int qa_auth_interface (MYSQL_PLUGIN_VIO *vio, MYSQL_SERVER_AUTH_INFO *info)
|
static int qa_auth_interface (MYSQL_PLUGIN_VIO *vio, MYSQL_SERVER_AUTH_INFO *info)
|
@ -32,16 +32,6 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
/**
|
|
||||||
first byte of the question string is the question "type".
|
|
||||||
It can be a "ordinary" or a "password" question.
|
|
||||||
The last bit set marks a last question in the authentication exchange.
|
|
||||||
*/
|
|
||||||
#define ORDINARY_QUESTION "\2"
|
|
||||||
#define LAST_QUESTION "\3"
|
|
||||||
#define LAST_PASSWORD "\4"
|
|
||||||
#define PASSWORD_QUESTION "\5"
|
|
||||||
|
|
||||||
/********************* SERVER SIDE ****************************************/
|
/********************* SERVER SIDE ****************************************/
|
||||||
|
|
||||||
/**
|
/**
|
27
plugin/auth_socket/CMakeLists.txt
Normal file
27
plugin/auth_socket/CMakeLists.txt
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
# Copyright (c) 2010, 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
|
||||||
|
|
||||||
|
CHECK_CXX_SOURCE_COMPILES(
|
||||||
|
"#define _GNU_SOURCE
|
||||||
|
#include <sys/socket.h>
|
||||||
|
int main() {
|
||||||
|
struct ucred cred;
|
||||||
|
getsockopt(0, SOL_SOCKET, SO_PEERCRED, &cred, 0);
|
||||||
|
}" HAVE_PEERCRED)
|
||||||
|
|
||||||
|
IF(HAVE_PEERCRED)
|
||||||
|
MYSQL_ADD_PLUGIN(auth_socket auth_socket.c MODULE_ONLY)
|
||||||
|
ENDIF()
|
@ -13,21 +13,22 @@
|
|||||||
# along with this program; if not, write to the Free Software
|
# along with this program; if not, write to the Free Software
|
||||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
#
|
IF(WIN32)
|
||||||
# Configuration for building Windows Authentication Plugin (client-side)
|
#
|
||||||
#
|
# Configuration for building Windows Authentication Plugin (client-side)
|
||||||
|
#
|
||||||
|
|
||||||
ADD_DEFINITIONS(-DSECURITY_WIN32)
|
ADD_DEFINITIONS(-DSECURITY_WIN32)
|
||||||
ADD_DEFINITIONS(-DDEBUG_ERRROR_LOG) # no error logging in production builds
|
ADD_DEFINITIONS(-DDEBUG_ERRROR_LOG) # no error logging in production builds
|
||||||
ADD_DEFINITIONS(-DWINAUTH_USE_DBUG_LIB) # it is OK to use dbug library in statically
|
#ADD_DEFINITIONS(-DWINAUTH_USE_DBUG_LIB) # it is OK to use dbug library in statically
|
||||||
# linked plugin
|
# # linked plugin
|
||||||
|
|
||||||
SET(HEADERS common.h handshake.h)
|
SET(HEADERS common.h handshake.h)
|
||||||
SET(PLUGIN_SOURCES plugin_client.cc handshake_client.cc log_client.cc common.cc handshake.cc)
|
SET(PLUGIN_SOURCES plugin_client.cc handshake_client.cc
|
||||||
|
log_client.cc common.cc handshake.cc)
|
||||||
|
|
||||||
ADD_CONVENIENCE_LIBRARY(auth_win_client ${PLUGIN_SOURCES} ${HEADERS})
|
MYSQL_ADD_PLUGIN(authentication_windows_client ${PLUGIN_SOURCES} ${HEADERS}
|
||||||
TARGET_LINK_LIBRARIES(auth_win_client Secur32)
|
LINK_LIBRARUES Secur32
|
||||||
|
MODULE_ONLY)
|
||||||
|
|
||||||
# In IDE, group headers in a separate folder.
|
ENDIF(WIN32)
|
||||||
|
|
||||||
SOURCE_GROUP(Headers REGULAR_EXPRESSION ".*h$")
|
|
@ -2272,7 +2272,6 @@ typedef struct st_mysql_client_plugin_AUTHENTICATION auth_plugin_t;
|
|||||||
static int client_mpvio_write_packet(struct st_plugin_vio*, const uchar*, int);
|
static int client_mpvio_write_packet(struct st_plugin_vio*, const uchar*, int);
|
||||||
static int native_password_auth_client(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql);
|
static int native_password_auth_client(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql);
|
||||||
static int old_password_auth_client(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql);
|
static int old_password_auth_client(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql);
|
||||||
static int clear_password_auth_client(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql);
|
|
||||||
|
|
||||||
static auth_plugin_t native_password_client_plugin=
|
static auth_plugin_t native_password_client_plugin=
|
||||||
{
|
{
|
||||||
@ -2306,39 +2305,13 @@ static auth_plugin_t old_password_client_plugin=
|
|||||||
old_password_auth_client
|
old_password_auth_client
|
||||||
};
|
};
|
||||||
|
|
||||||
static auth_plugin_t clear_password_client_plugin=
|
|
||||||
{
|
|
||||||
MYSQL_CLIENT_AUTHENTICATION_PLUGIN,
|
|
||||||
MYSQL_CLIENT_AUTHENTICATION_PLUGIN_INTERFACE_VERSION,
|
|
||||||
"mysql_clear_password",
|
|
||||||
"Georgi Kodinov",
|
|
||||||
"Clear password authentication plugin",
|
|
||||||
{0,1,0},
|
|
||||||
"GPL",
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
clear_password_auth_client
|
|
||||||
};
|
|
||||||
|
|
||||||
#ifdef AUTHENTICATION_WIN
|
|
||||||
extern auth_plugin_t win_auth_client_plugin;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct st_mysql_client_plugin *mysql_client_builtins[]=
|
struct st_mysql_client_plugin *mysql_client_builtins[]=
|
||||||
{
|
{
|
||||||
(struct st_mysql_client_plugin *)&native_password_client_plugin,
|
(struct st_mysql_client_plugin *)&native_password_client_plugin,
|
||||||
(struct st_mysql_client_plugin *)&old_password_client_plugin,
|
(struct st_mysql_client_plugin *)&old_password_client_plugin,
|
||||||
(struct st_mysql_client_plugin *)&clear_password_client_plugin,
|
|
||||||
#ifdef AUTHENTICATION_WIN
|
|
||||||
(struct st_mysql_client_plugin *)&win_auth_client_plugin,
|
|
||||||
#endif
|
|
||||||
0
|
0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* this is a "superset" of MYSQL_PLUGIN_VIO, in C++ I use inheritance */
|
/* this is a "superset" of MYSQL_PLUGIN_VIO, in C++ I use inheritance */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int (*read_packet)(struct st_plugin_vio *vio, uchar **buf);
|
int (*read_packet)(struct st_plugin_vio *vio, uchar **buf);
|
||||||
@ -4342,18 +4315,3 @@ static int old_password_auth_client(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql)
|
|||||||
DBUG_RETURN(CR_OK);
|
DBUG_RETURN(CR_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
The main function of the mysql_clear_password authentication plugin.
|
|
||||||
*/
|
|
||||||
|
|
||||||
static int clear_password_auth_client(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql)
|
|
||||||
{
|
|
||||||
int res;
|
|
||||||
|
|
||||||
/* send password in clear text */
|
|
||||||
res= vio->write_packet(vio, (const unsigned char *) mysql->passwd,
|
|
||||||
strlen(mysql->passwd) + 1);
|
|
||||||
|
|
||||||
return res ? CR_ERROR : CR_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user