|
21 | 21 | #include "mariadb.h"
|
22 | 22 | #include <my_getopt.h>
|
23 | 23 | #include <m_string.h>
|
| 24 | +#include <password.h> |
24 | 25 |
|
25 | 26 | #include <windows.h>
|
26 | 27 | #include <shellapi.h>
|
@@ -443,16 +444,14 @@ static int create_myini()
|
443 | 444 | }
|
444 | 445 |
|
445 | 446 |
|
446 |
| -static const char update_root_passwd_part1[]= |
| 447 | +static constexpr const char* update_root_passwd= |
447 | 448 | "UPDATE mysql.global_priv SET priv=json_set(priv,"
|
448 | 449 | "'$.password_last_changed', UNIX_TIMESTAMP(),"
|
449 | 450 | "'$.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[]= |
454 | 453 | "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[]= |
456 | 455 | "CREATE TEMPORARY TABLE tmp_user LIKE global_priv;\n"
|
457 | 456 | "INSERT INTO tmp_user SELECT * from global_priv where user='root' "
|
458 | 457 | " AND host='localhost';\n"
|
@@ -871,18 +870,10 @@ static int create_db_instance(const char *datadir)
|
871 | 870 | /* Change root password if requested. */
|
872 | 871 | if (opt_password && opt_password[0])
|
873 | 872 | {
|
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); |
886 | 877 | fflush(in);
|
887 | 878 | }
|
888 | 879 |
|
|
0 commit comments