Skip to content

Commit 4d3ac32

Browse files
vaintroubvuvova
authored andcommitted
MDEV-27093 Do not pass root password in HEX(clear text) from mariadb-install-db.exe to bootstrap
Previously, password was passed as hex(clear_text_password). The hex encoding was used to avoid masking apostrophe and backslash etc. However, bootstrap still manages to misinterpert UTF8 password, so that root would not connect later. So the fix is to compute the native password hash inside mysql_install_db already instead, and create user with that hash, rather than letting bootstrap calculate it by using PASSWORD() function.
1 parent ea0a5cb commit 4d3ac32

File tree

2 files changed

+11
-19
lines changed

2 files changed

+11
-19
lines changed

sql/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,10 +481,11 @@ IF(WIN32)
481481
MYSQL_ADD_EXECUTABLE(mariadb-install-db
482482
mysql_install_db.cc
483483
${CMAKE_CURRENT_BINARY_DIR}/mysql_bootstrap_sql.c
484+
password.c
484485
COMPONENT Server
485486
)
486487
SET_TARGET_PROPERTIES(mariadb-install-db PROPERTIES COMPILE_FLAGS -DINSTALL_PLUGINDIR=${INSTALL_PLUGINDIR})
487-
TARGET_LINK_LIBRARIES(mariadb-install-db mysys shlwapi)
488+
TARGET_LINK_LIBRARIES(mariadb-install-db mysys mysys_ssl shlwapi)
488489

489490
ADD_LIBRARY(winservice STATIC winservice.c)
490491
TARGET_LINK_LIBRARIES(winservice shell32)

sql/mysql_install_db.cc

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "mariadb.h"
2222
#include <my_getopt.h>
2323
#include <m_string.h>
24+
#include <password.h>
2425

2526
#include <windows.h>
2627
#include <shellapi.h>
@@ -443,16 +444,14 @@ static int create_myini()
443444
}
444445

445446

446-
static const char update_root_passwd_part1[]=
447+
static constexpr const char* update_root_passwd=
447448
"UPDATE mysql.global_priv SET priv=json_set(priv,"
448449
"'$.password_last_changed', UNIX_TIMESTAMP(),"
449450
"'$.plugin','mysql_native_password',"
450-
"'$.authentication_string',PASSWORD(";
451-
static const char update_root_passwd_part2[]=
452-
")) where User='root';\n";
453-
static const char remove_default_user_cmd[]=
451+
"'$.authentication_string','%s') where User='root';\n";
452+
static constexpr char remove_default_user_cmd[]=
454453
"DELETE FROM mysql.user where User='';\n";
455-
static const char allow_remote_root_access_cmd[]=
454+
static constexpr char allow_remote_root_access_cmd[]=
456455
"CREATE TEMPORARY TABLE tmp_user LIKE global_priv;\n"
457456
"INSERT INTO tmp_user SELECT * from global_priv where user='root' "
458457
" AND host='localhost';\n"
@@ -871,18 +870,10 @@ static int create_db_instance(const char *datadir)
871870
/* Change root password if requested. */
872871
if (opt_password && opt_password[0])
873872
{
874-
verbose("Setting root password",remove_default_user_cmd);
875-
fputs(update_root_passwd_part1, in);
876-
877-
/* Use hex encoding for password, to avoid escaping problems.*/
878-
fputc('0', in);
879-
fputc('x', in);
880-
for(int i= 0; opt_password[i]; i++)
881-
{
882-
fprintf(in,"%02x",opt_password[i]);
883-
}
884-
885-
fputs(update_root_passwd_part2, in);
873+
verbose("Setting root password");
874+
char buf[2 * MY_SHA1_HASH_SIZE + 2];
875+
my_make_scrambled_password(buf, opt_password, strlen(opt_password));
876+
fprintf(in, update_root_passwd, buf);
886877
fflush(in);
887878
}
888879

0 commit comments

Comments
 (0)