mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-06-19 16:47:14 +02:00
Integrate MySQL module.
This commit is contained in:
6
module/Vendor/MDBC/plugins/CMakeLists.txt
vendored
Normal file
6
module/Vendor/MDBC/plugins/CMakeLists.txt
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
FILE(GLOB plugin_dirs ${CC_SOURCE_DIR}/plugins/*)
|
||||
FOREACH(dir ${plugin_dirs})
|
||||
IF (EXISTS ${dir}/CMakeLists.txt)
|
||||
ADD_SUBDIRECTORY(${dir})
|
||||
ENDIF()
|
||||
ENDFOREACH()
|
44
module/Vendor/MDBC/plugins/auth/CMakeLists.txt
vendored
Normal file
44
module/Vendor/MDBC/plugins/auth/CMakeLists.txt
vendored
Normal file
@ -0,0 +1,44 @@
|
||||
INCLUDE_DIRECTORIES(${CC_SOURCE_DIR}/include)
|
||||
|
||||
# Dialog plugin
|
||||
SET(DIALOG_SOURCES dialog.c ${CC_SOURCE_DIR}/libmariadb/get_password.c)
|
||||
IF(WIN32)
|
||||
SET_VERSION_INFO("TARGET:dialog"
|
||||
"FILE_TYPE:VFT_DLL"
|
||||
"SOURCE_FILE:plugins/auth/dialog.c"
|
||||
"ORIGINAL_FILE_NAME:dialog.dll"
|
||||
"FILE_DESCRIPTION:Authentication plugin")
|
||||
SET(DIALOG_SOURCES ${DIALOG_SOURCES} ${CC_SOURCE_DIR}/plugins/plugin.def)
|
||||
ENDIF()
|
||||
ADD_LIBRARY(dialog SHARED ${dialog_RC} ${DIALOG_SOURCES})
|
||||
SET_TARGET_PROPERTIES(dialog PROPERTIES PREFIX "")
|
||||
SIGN_TARGET(dialog)
|
||||
|
||||
INSTALL(TARGETS
|
||||
dialog
|
||||
RUNTIME DESTINATION "${PLUGIN_INSTALL_DIR}"
|
||||
LIBRARY DESTINATION "${PLUGIN_INSTALL_DIR}"
|
||||
ARCHIVE DESTINATION "${PLUGIN_INSTALL_DIR}")
|
||||
|
||||
# Cleartext
|
||||
# Dialog plugin
|
||||
SET(CTEXT_SOURCES mariadb_cleartext.c)
|
||||
IF(WIN32)
|
||||
SET_VERSION_INFO("TARGET:mysql_clear_password"
|
||||
"FILE_TYPE:VFT_DLL"
|
||||
"SOURCE_FILE:plugins/auth/mariadb_cleartext.c"
|
||||
"ORIGINAL_FILE_NAME:mysql_clear_password.dll"
|
||||
"FILE_DESCRIPTION:Authentication plugin")
|
||||
SET(CTEXT_SOURCES ${CTEXT_SOURCES} ${CC_SOURCE_DIR}/plugins/plugin.def)
|
||||
ENDIF()
|
||||
ADD_LIBRARY(mysql_clear_password SHARED ${mysql_clear_password_RC} ${CTEXT_SOURCES})
|
||||
SET_TARGET_PROPERTIES(mysql_clear_password PROPERTIES PREFIX "")
|
||||
SIGN_TARGET(mysql_clear_password)
|
||||
|
||||
INSTALL(TARGETS
|
||||
mysql_clear_password
|
||||
RUNTIME DESTINATION "${PLUGIN_INSTALL_DIR}"
|
||||
LIBRARY DESTINATION "${PLUGIN_INSTALL_DIR}"
|
||||
ARCHIVE DESTINATION "${PLUGIN_INSTALL_DIR}")
|
||||
|
||||
# Cleartext
|
215
module/Vendor/MDBC/plugins/auth/dialog.c
vendored
Normal file
215
module/Vendor/MDBC/plugins/auth/dialog.c
vendored
Normal file
@ -0,0 +1,215 @@
|
||||
/************************************************************************************
|
||||
Copyright (C) 2014 MariaDB Corporation AB
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not see <http://www.gnu.org/licenses>
|
||||
or write to the Free Software Foundation, Inc.,
|
||||
51 Franklin St., Fifth Floor, Boston, MA 02110, USA
|
||||
*************************************************************************************/
|
||||
#ifndef _WIN32
|
||||
#define _GNU_SOURCE 1
|
||||
#endif
|
||||
|
||||
#include <my_global.h>
|
||||
#include <mysql.h>
|
||||
#include <mysql/client_plugin.h>
|
||||
#include <string.h>
|
||||
#include <memory.h>
|
||||
|
||||
#ifndef WIN32
|
||||
#include <dlfcn.h>
|
||||
#endif
|
||||
|
||||
|
||||
/* function prototypes */
|
||||
extern char *get_tty_password(char *opt_message, char *buff, int bufflen);
|
||||
static int auth_dialog_open(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql);
|
||||
static int auth_dialog_init(char *unused1,
|
||||
size_t unused2,
|
||||
int unused3,
|
||||
va_list);
|
||||
|
||||
mysql_authentication_dialog_ask_t auth_dialog_func;
|
||||
|
||||
mysql_declare_client_plugin(AUTHENTICATION)
|
||||
"dialog",
|
||||
"Sergei Golubchik, Georg Richter",
|
||||
"Dialog Client Authentication Plugin",
|
||||
{0,1,0},
|
||||
"LGPL",
|
||||
NULL,
|
||||
auth_dialog_init,
|
||||
NULL,
|
||||
NULL,
|
||||
auth_dialog_open
|
||||
mysql_end_client_plugin;
|
||||
|
||||
|
||||
/* {{{ static char *auth_dialog_native_prompt */
|
||||
/*
|
||||
Native dialog prompt via stdin
|
||||
|
||||
SYNOPSIS
|
||||
auth_dialog_native_prompt
|
||||
mysql connection handle
|
||||
type input type
|
||||
prompt prompt
|
||||
buffer Input buffer
|
||||
buffer_len Input buffer length
|
||||
|
||||
DESCRIPTION
|
||||
|
||||
RETURNS
|
||||
Input buffer
|
||||
*/
|
||||
static char *auth_dialog_native_prompt(MYSQL *mysql,
|
||||
int type,
|
||||
const char *prompt,
|
||||
char *buffer,
|
||||
int buffer_len)
|
||||
{
|
||||
/* display prompt */
|
||||
fprintf(stdout, "%s", prompt);
|
||||
|
||||
memset(buffer, 0, buffer_len);
|
||||
|
||||
/* for type 2 (password) don't display input */
|
||||
if (type != 2)
|
||||
{
|
||||
if (fgets(buffer, buffer_len - 1, stdin))
|
||||
{
|
||||
/* remove trailing line break */
|
||||
size_t length= strlen(buffer);
|
||||
if (length && buffer[length - 1] == '\n')
|
||||
buffer[length - 1]= 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
get_tty_password("", buffer, buffer_len - 1);
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ static int auth_dialog_open */
|
||||
/*
|
||||
opens dialog
|
||||
|
||||
SYNOPSIS
|
||||
vio Vio
|
||||
mysql connection handle
|
||||
|
||||
DESCRIPTION
|
||||
reads prompt from server, waits for input and sends
|
||||
input to server.
|
||||
Note that first byte of prompt indicates if we have a
|
||||
password which should not be echoed to stdout.
|
||||
|
||||
RETURN
|
||||
CR_ERROR if an error occurs
|
||||
CR_OK
|
||||
CR_OK_HANDSHAKE_COMPLETE
|
||||
*/
|
||||
static int auth_dialog_open(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql)
|
||||
{
|
||||
uchar *packet;
|
||||
uchar type;
|
||||
char dialog_buffer[1024];
|
||||
char *response;
|
||||
int packet_length;
|
||||
my_bool first_loop= TRUE;
|
||||
|
||||
do {
|
||||
if ((packet_length= vio->read_packet(vio, &packet)) < 0)
|
||||
/* read error */
|
||||
return CR_ERROR;
|
||||
|
||||
if (packet_length > 0)
|
||||
{
|
||||
type= *packet;
|
||||
packet++;
|
||||
|
||||
/* check for protocol packet */
|
||||
if (!type || type == 254)
|
||||
return CR_OK_HANDSHAKE_COMPLETE;
|
||||
|
||||
if ((type >> 1) == 2 &&
|
||||
first_loop &&
|
||||
mysql->passwd && mysql->passwd[0])
|
||||
response= mysql->passwd;
|
||||
else
|
||||
response= auth_dialog_func(mysql, type >> 1,
|
||||
(const char *)packet,
|
||||
dialog_buffer, 1024);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* in case mysql_change_user was called the client needs
|
||||
to send packet first */
|
||||
response= mysql->passwd;
|
||||
}
|
||||
if (!response ||
|
||||
vio->write_packet(vio, response, strlen(response) + 1))
|
||||
return CR_ERROR;
|
||||
|
||||
first_loop= FALSE;
|
||||
|
||||
} while((type & 1) != 1);
|
||||
return CR_OK;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ static int auth_dialog_init */
|
||||
/*
|
||||
Initialization routine
|
||||
|
||||
SYNOPSIS
|
||||
auth_dialog_init
|
||||
unused1
|
||||
unused2
|
||||
unused3
|
||||
unused4
|
||||
|
||||
DESCRIPTION
|
||||
Init function checks if the caller provides own dialog function.
|
||||
The function name must be mariadb_auth_dialog or
|
||||
mysql_authentication_dialog_ask. If the function cannot be found,
|
||||
we will use owr own simple command line input.
|
||||
|
||||
RETURN
|
||||
0 success
|
||||
*/
|
||||
static int auth_dialog_init(char *unused1 __attribute__((unused)),
|
||||
size_t unused2 __attribute__((unused)),
|
||||
int unused3 __attribute__((unused)),
|
||||
va_list unused4 __attribute__((unused)))
|
||||
{
|
||||
void *func;
|
||||
#ifdef WIN32
|
||||
if (!(func= GetProcAddress(GetModuleHandle(NULL), "mariadb_auth_dialog")))
|
||||
/* for MySQL users */
|
||||
func= GetProcAddress(GetModuleHandle(NULL), "mysql_authentication_dialog_ask");
|
||||
#else
|
||||
if (!(func= dlsym(RTLD_DEFAULT, "mariadb_auth_dialog")))
|
||||
/* for MySQL users */
|
||||
func= dlsym(RTLD_DEFAULT, "mysql_authentication_dialog_ask");
|
||||
#endif
|
||||
if (func)
|
||||
auth_dialog_func= (mysql_authentication_dialog_ask_t)func;
|
||||
else
|
||||
auth_dialog_func= auth_dialog_native_prompt;
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* }}} */
|
69
module/Vendor/MDBC/plugins/auth/mariadb_cleartext.c
vendored
Normal file
69
module/Vendor/MDBC/plugins/auth/mariadb_cleartext.c
vendored
Normal file
@ -0,0 +1,69 @@
|
||||
/************************************************************************************
|
||||
Copyright (C) 2014 MariaDB Corporation AB
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not see <http://www.gnu.org/licenses>
|
||||
or write to the Free Software Foundation, Inc.,
|
||||
51 Franklin St., Fifth Floor, Boston, MA 02110, USA
|
||||
*************************************************************************************/
|
||||
#include <my_global.h>
|
||||
#include <mysql.h>
|
||||
#include <mysql/client_plugin.h>
|
||||
#include <string.h>
|
||||
|
||||
/* clear text plugin submits the password without opening a dialog.
|
||||
This will be the case if pam-use-cleartext-plugin option is
|
||||
enabled on server side */
|
||||
|
||||
/* {{{ auth_send_plain_password() */
|
||||
/*
|
||||
sends an unencrypted password to server
|
||||
|
||||
SYNOPSIS
|
||||
auth_send_plain_password()
|
||||
vio pointer to vio structure
|
||||
mysql connection handle
|
||||
|
||||
DESCRIPTION
|
||||
sends an unencrypted password (which was specified either in
|
||||
mysql_real_connect or mysql_change_user) to server.
|
||||
|
||||
RETURN
|
||||
CR_OK
|
||||
CR_ERROR if an error occured
|
||||
*/
|
||||
static int clear_password_auth_client(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql)
|
||||
{
|
||||
if (!vio || !mysql || !mysql->passwd)
|
||||
return CR_ERROR;
|
||||
|
||||
/* write password including terminating zero character */
|
||||
return vio->write_packet(vio, (const unsigned char *) mysql->passwd, strlen(mysql->passwd) + 1) ?
|
||||
CR_ERROR : CR_OK;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
mysql_declare_client_plugin(AUTHENTICATION)
|
||||
"mysql_clear_password",
|
||||
"Georg Richter",
|
||||
"MariaDB clear password authentication plugin",
|
||||
{0,1,0},
|
||||
"LGPL",
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
clear_password_auth_client
|
||||
mysql_end_client_plugin;
|
||||
|
||||
|
2
module/Vendor/MDBC/plugins/plugin.def
vendored
Normal file
2
module/Vendor/MDBC/plugins/plugin.def
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
EXPORTS
|
||||
_mysql_client_plugin_declaration_ DATA
|
Reference in New Issue
Block a user