@@ -1017,10 +1017,12 @@ static int execute_commands(MYSQL *mysql,int argc, char **argv)
1017
1017
}
1018
1018
case ADMIN_PASSWORD:
1019
1019
{
1020
- char buff[128 ],crypted_pw[ 64 ] ;
1020
+ char buff[128 ];
1021
1021
time_t start_time;
1022
- char *typed_password= NULL , *verified= NULL ;
1023
- bool log_off= true , err= false ;
1022
+ char *typed_password= NULL , *verified= NULL , *tmp= NULL ;
1023
+ bool log_off= true , err= false , ssl_conn= false ;
1024
+ uint ssl_enforce= 0 ;
1025
+ size_t password_len;
1024
1026
1025
1027
/* Do initialization the same way as we do in mysqld */
1026
1028
start_time=time ((time_t *) 0 );
@@ -1042,6 +1044,11 @@ static int execute_commands(MYSQL *mysql,int argc, char **argv)
1042
1044
err= true ;
1043
1045
goto error;
1044
1046
}
1047
+ /* escape quotes if password has any special characters */
1048
+ password_len= strlen (typed_password);
1049
+ tmp= (char *) my_malloc (PSI_NOT_INSTRUMENTED, password_len*2 +1 , MYF (MY_WME));
1050
+ mysql_real_escape_string (mysql, tmp, typed_password, password_len);
1051
+ typed_password= tmp;
1045
1052
}
1046
1053
else
1047
1054
{
@@ -1074,12 +1081,21 @@ static int execute_commands(MYSQL *mysql,int argc, char **argv)
1074
1081
TODO: make sure this always uses SSL and then let the server
1075
1082
calculate the scramble.
1076
1083
*/
1077
- make_scrambled_password (crypted_pw, typed_password);
1078
1084
}
1079
- else
1080
- crypted_pw[0 ]=0 ; /* No password */
1081
1085
1082
- sprintf (buff, " set password='%s'" , crypted_pw);
1086
+ /* Warn about password being set in non ssl connection */
1087
+ #if defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY)
1088
+ mysql_get_option (mysql, MYSQL_OPT_SSL_ENFORCE, &ssl_enforce);
1089
+ if (opt_use_ssl && ssl_enforce)
1090
+ ssl_conn= true ;
1091
+ if (!ssl_conn)
1092
+ {
1093
+ fprintf (stderr, " Warning: Since password will be sent to server in "
1094
+ " plain text, use ssl connection to ensure password safety.\n " );
1095
+ }
1096
+ #endif
1097
+ memset (buff, 0 , sizeof (buff));
1098
+ sprintf (buff, " ALTER USER USER() IDENTIFIED BY '%s'" , typed_password);
1083
1099
1084
1100
if (mysql_query (mysql,buff))
1085
1101
{
0 commit comments