Skip to content

Commit

Permalink
10.2 integration fixes:
Browse files Browse the repository at this point in the history
- renamed/prefixed password functions
- prepared statement fixes for mysql_client_test
  • Loading branch information
9EOR9 committed Feb 19, 2016
1 parent 56f9809 commit c014b9f
Show file tree
Hide file tree
Showing 13 changed files with 186 additions and 117 deletions.
2 changes: 1 addition & 1 deletion cmake/plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ ENDIF()

# AUTHENTICATION
REGISTER_PLUGIN("AUTH_NATIVE" "${CMAKE_SOURCE_DIR}/plugins/auth/my_auth.c" "native_password_client_plugin" "STATIC" "" 0)
REGISTER_PLUGIN("AUTH_OLDPASSWORD" "${CMAKE_SOURCE_DIR}/plugins/auth/old_password.c" "old_password_client_plugin" "DYNAMIC" "old_password" 1)
REGISTER_PLUGIN("AUTH_OLDPASSWORD" "${CMAKE_SOURCE_DIR}/plugins/auth/old_password.c" "old_password_client_plugin" "DYNAMIC" "mysql_old_password" 1)
REGISTER_PLUGIN("AUTH_DIALOG" "${CMAKE_SOURCE_DIR}/plugins/auth/dialog.c" "auth_dialog_plugin" "DYNAMIC" dialog 1)
REGISTER_PLUGIN("AUTH_CLEARTEXT" "${CMAKE_SOURCE_DIR}/plugins/auth/mariadb_clear_text.c" "auth_cleartext_plugin" "DYNAMIC" "mysql_clear_password" 1)
IF(WIN32)
Expand Down
2 changes: 1 addition & 1 deletion include/ma_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -275,5 +275,5 @@
#cmakedefine HAVE_THREADS 1
#cmakedefine SHAREDIR "@SHAREDIR@"
#cmakedefine DEFAULT_CHARSET_HOME "@DEFAULT_CHARSET_HOME@"
#cmakedefine PLUGINDIR "@PREFIX_INSTALL_DIR@/@PLUGIN_INSTALL_DIR@"
#cmakedefine MARIADB_PLUGINDIR "@PREFIX_INSTALL_DIR@/@PLUGIN_INSTALL_DIR@"

15 changes: 4 additions & 11 deletions include/mariadb_com.h
Original file line number Diff line number Diff line change
Expand Up @@ -412,17 +412,10 @@ typedef struct st_udf_init
extern "C" {
#endif

void randominit(struct rand_struct *,unsigned long seed1,
unsigned long seed2);
double rnd(struct rand_struct *);
void make_scrambled_password(char *to,const char *password);
void get_salt_from_password(unsigned long *res,const char *password);
void make_password_from_salt(char *to, unsigned long *hash_res);
char *scramble_323(char *to,const char *message,const char *password);
void my_scramble_41(const unsigned char *buffer, const char *scramble, const char *password);
my_bool check_scramble(const char *, const char *message,
unsigned long *salt,my_bool old_ver);
void hash_password(unsigned long *result, const char *password, size_t len);
char *ma_scramble_323(char *to,const char *message,const char *password);
void ma_scramble_41(const unsigned char *buffer, const char *scramble, const char *password);
void ma_hash_password(unsigned long *result, const char *password, size_t len);
void ma_make_scrambled_password(char *to,const char *password);

/* Some other useful functions */

Expand Down
5 changes: 3 additions & 2 deletions include/mysql.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ extern unsigned int mariadb_deinitialize_ssl;
MYSQL_STATUS_FETCHING_DATA,
MYSQL_STATUS_NEXT_RESULT_PENDING,
MYSQL_STATUS_QUIT_SENT, /* object is "destroyed" at this stage */
MYSQL_STATUS_STMT_RESULT
};

enum mysql_protocol_type
Expand Down Expand Up @@ -580,9 +581,9 @@ int STDCALL mysql_rollback_start(my_bool *ret, MYSQL * mysql);
int STDCALL mysql_rollback_cont(my_bool *ret, MYSQL * mysql, int status);
int STDCALL mysql_autocommit_start(my_bool *ret, MYSQL * mysql,
my_bool auto_mode);
int STDCALL mysql_list_fields_cont(MYSQL_RES **ret, MYSQL *mysql, int status);
int STDCALL mysql_list_fields_cont(MYSQL_RES **ret, MYSQL *mysql, int ready_status);
int STDCALL mysql_list_fields_start(MYSQL_RES **ret, MYSQL *mysql, const char *table,
const char *wild);
const char *wild);
int STDCALL mysql_autocommit_cont(my_bool *ret, MYSQL * mysql, int status);
int STDCALL mysql_next_result_start(int *ret, MYSQL *mysql);
int STDCALL mysql_next_result_cont(int *ret, MYSQL *mysql, int status);
Expand Down
4 changes: 2 additions & 2 deletions libmariadb/ma_client_plugin.c.in
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ mysql_load_plugin_v(MYSQL *mysql, const char *name, int type,
struct st_mysql_client_plugin *plugin;
char *env_plugin_dir= getenv("MARIADB_PLUGIN_DIR");

CLEAR_CLIENT_ERROR(mysql);
if (is_not_initialized(mysql, name))
return NULL;

Expand All @@ -391,7 +392,7 @@ mysql_load_plugin_v(MYSQL *mysql, const char *name, int type,
snprintf(dlpath, sizeof(dlpath) - 1, "%s/%s%s",
mysql->options.extension && mysql->options.extension->plugin_dir ?
mysql->options.extension->plugin_dir : (env_plugin_dir) ? env_plugin_dir :
PLUGINDIR, name, SO_EXT);
MARIADB_PLUGINDIR, name, SO_EXT);

/* Open new dll handle */
if (!(dlhandle= dlopen((const char *)dlpath, RTLD_NOW)))
Expand Down Expand Up @@ -486,4 +487,3 @@ mysql_client_find_plugin(MYSQL *mysql, const char *name, int type)
return mysql_load_plugin(mysql, name, type, 0);
}


1 change: 0 additions & 1 deletion libmariadb/ma_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ int ma_net_init(NET *net, MARIADB_PVIO* pvio)

/* We don't allocate memory for multi buffer, since we don't know in advance if the server
* supports COM_MULTI comand. It will be allocated on demand in net_add_multi_command */

max_allowed_packet= net->max_packet_size= MAX(net_buffer_length, max_allowed_packet);
net->buff_end=net->buff+(net->max_packet=net_buffer_length);
net->pvio = pvio;
Expand Down
78 changes: 10 additions & 68 deletions libmariadb/ma_password.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
#include "mysql.h"


void randominit(struct rand_struct *rand_st,ulong seed1, ulong seed2)
void ma_randominit(struct rand_struct *rand_st,ulong seed1, ulong seed2)
{ /* For mysql 3.21.# */
#ifdef HAVE_purify
memset((char*) rand_st, 0m sizeof(*rand_st)); /* Avoid UMC varnings */
Expand All @@ -54,7 +54,7 @@ void randominit(struct rand_struct *rand_st,ulong seed1, ulong seed2)
rand_st->seed2=seed2%rand_st->max_value;
}

static void old_randominit(struct rand_struct *rand_st,ulong seed1)
static void ma_old_randominit(struct rand_struct *rand_st,ulong seed1)
{ /* For mysql 3.20.# */
rand_st->max_value= 0x01FFFFFFL;
rand_st->max_value_dbl=(double) rand_st->max_value;
Expand All @@ -69,7 +69,7 @@ double rnd(struct rand_struct *rand_st)
return (((double) rand_st->seed1)/rand_st->max_value_dbl);
}

void hash_password(ulong *result, const char *password, size_t len)
void ma_hash_password(ulong *result, const char *password, size_t len)
{
register ulong nr=1345345333L, add=7, nr2=0x12345671L;
ulong tmp;
Expand Down Expand Up @@ -113,7 +113,7 @@ void my_crypt(unsigned char *buffer, const unsigned char *s1, const unsigned cha
}
}

void my_scramble_41(const unsigned char *buffer, const char *scramble, const char *password)
void ma_scramble_41(const unsigned char *buffer, const char *scramble, const char *password)
{
_MA_SHA1_CTX context;
unsigned char sha1[SHA1_MAX_LENGTH];
Expand Down Expand Up @@ -141,46 +141,18 @@ void my_scramble_41(const unsigned char *buffer, const char *scramble, const cha
}
/* }}} */

void make_scrambled_password(char *to,const char *password)
void ma_make_scrambled_password(char *to,const char *password)
{
ulong hash_res[2];
hash_password(hash_res,password, strlen(password));
ma_hash_password(hash_res,password, strlen(password));
sprintf(to,"%08lx%08lx",hash_res[0],hash_res[1]);
}

/*
** This code assumes that len(password) is divideable with 8 and that
** res is big enough (2 in mysql)
*/

void get_salt_from_password(ulong *res,const char *password)
{
res[0]=res[1]=0;
if (password)
{
while (*password)
{
ulong val=0;
uint i;
for (i=0 ; i < 8 ; i++)
val=(val << 4)+char_val(*password++);
*res++=val;
}
}
return;
}

void make_password_from_salt(char *to, ulong *hash_res)
{
sprintf(to,"%08lx%08lx",hash_res[0],hash_res[1]);
}


/*
* Genererate a new message based on message and password
* The same thing is done in client and server and the results are checked.
*/
char *scramble_323(char *to, const char *message, const char *password)
char *ma_scramble_323(char *to, const char *message, const char *password)
{
struct rand_struct rand_st;
ulong hash_pass[2], hash_message[2];
Expand All @@ -189,10 +161,10 @@ char *scramble_323(char *to, const char *message, const char *password)
{
char extra, *to_start=to;
const char *end_scramble323= message + SCRAMBLE_LENGTH_323;
hash_password(hash_pass,password, (uint) strlen(password));
ma_hash_password(hash_pass,password, (uint) strlen(password));
/* Don't use strlen, could be > SCRAMBLE_LENGTH_323 ! */
hash_password(hash_message, message, SCRAMBLE_LENGTH_323);
randominit(&rand_st, hash_pass[0] ^ hash_message[0],
ma_hash_password(hash_message, message, SCRAMBLE_LENGTH_323);
ma_randominit(&rand_st, hash_pass[0] ^ hash_message[0],
hash_pass[1] ^ hash_message[1]);
for (; message < end_scramble323; message++)
*to++= (char) (floor(rnd(&rand_st) * 31) + 64);
Expand All @@ -203,33 +175,3 @@ char *scramble_323(char *to, const char *message, const char *password)
*to= 0;
return to;
}

my_bool check_scramble(const char *scrambled, const char *message,
ulong *hash_pass, my_bool old_ver)
{
struct rand_struct rand_st;
ulong hash_message[2];
char buff[16],*to,extra; /* Big enough for check */
const char *pos;

hash_password(hash_message,message, strlen(message));
if (old_ver)
old_randominit(&rand_st,hash_pass[0] ^ hash_message[0]);
else
randominit(&rand_st,hash_pass[0] ^ hash_message[0],
hash_pass[1] ^ hash_message[1]);
to=buff;
for (pos=scrambled ; *pos ; pos++)
*to++=(char) (floor(rnd(&rand_st)*31)+64);
if (old_ver)
extra=0;
else
extra=(char) (floor(rnd(&rand_st)*31));
to=buff;
while (*scrambled)
{
if (*scrambled++ != (char) (*to++ ^ extra))
return 1; /* Wrong password */
}
return 0;
}
Loading

0 comments on commit c014b9f

Please sign in to comment.