Skip to content

Commit cc04a9f

Browse files
committed
MDEV-9835 Valid password is not working after server restart
On SET PASSWORD if the plugin is mysql_native_password or mysql_old_password, do reset plugin and auth_str fields.
1 parent 608c0e1 commit cc04a9f

File tree

3 files changed

+298
-5
lines changed

3 files changed

+298
-5
lines changed
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
create user natauth@localhost identified via 'mysql_native_password' using '*94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29';
2+
create user newpass@localhost identified by password '*94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29';
3+
create user newpassnat@localhost identified via 'mysql_native_password';
4+
set password for newpassnat@localhost = '*94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29';
5+
create user oldauth@localhost identified with 'mysql_old_password' using '378b243e220ca493';
6+
create user oldpass@localhost identified by password '378b243e220ca493';
7+
create user oldpassold@localhost identified with 'mysql_old_password';
8+
set password for oldpassold@localhost = '378b243e220ca493';
9+
select user, host, password, plugin, authentication_string from mysql.user where user != 'root';
10+
user host password plugin authentication_string
11+
natauth localhost mysql_native_password *94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29
12+
newpass localhost *94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29
13+
newpassnat localhost *94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29
14+
oldauth localhost mysql_old_password 378b243e220ca493
15+
oldpass localhost 378b243e220ca493
16+
oldpassold localhost 378b243e220ca493
17+
connect con,localhost,natauth,test,;
18+
select current_user();
19+
current_user()
20+
natauth@localhost
21+
disconnect con;
22+
connect con,localhost,newpass,test,;
23+
select current_user();
24+
current_user()
25+
newpass@localhost
26+
disconnect con;
27+
connect con,localhost,newpassnat,test,;
28+
select current_user();
29+
current_user()
30+
newpassnat@localhost
31+
disconnect con;
32+
connect con,localhost,oldauth,test,;
33+
select current_user();
34+
current_user()
35+
oldauth@localhost
36+
disconnect con;
37+
connect con,localhost,oldpass,test,;
38+
select current_user();
39+
current_user()
40+
oldpass@localhost
41+
disconnect con;
42+
connect con,localhost,oldpassold,test,;
43+
select current_user();
44+
current_user()
45+
oldpassold@localhost
46+
disconnect con;
47+
connection default;
48+
flush privileges;
49+
connect con,localhost,natauth,test,;
50+
select current_user();
51+
current_user()
52+
natauth@localhost
53+
disconnect con;
54+
connect con,localhost,newpass,test,;
55+
select current_user();
56+
current_user()
57+
newpass@localhost
58+
disconnect con;
59+
connect con,localhost,newpassnat,test,;
60+
select current_user();
61+
current_user()
62+
newpassnat@localhost
63+
disconnect con;
64+
connect con,localhost,oldauth,test,;
65+
select current_user();
66+
current_user()
67+
oldauth@localhost
68+
disconnect con;
69+
connect con,localhost,oldpass,test,;
70+
select current_user();
71+
current_user()
72+
oldpass@localhost
73+
disconnect con;
74+
connect con,localhost,oldpassold,test,;
75+
select current_user();
76+
current_user()
77+
oldpassold@localhost
78+
disconnect con;
79+
connection default;
80+
set password for natauth@localhost = PASSWORD('test2');
81+
set password for newpass@localhost = PASSWORD('test2');
82+
set password for newpassnat@localhost = PASSWORD('test2');
83+
set password for oldauth@localhost = PASSWORD('test2');
84+
set password for oldpass@localhost = PASSWORD('test2');
85+
set password for oldpassold@localhost = PASSWORD('test2');
86+
select user, host, password, plugin, authentication_string from mysql.user where user != 'root';
87+
user host password plugin authentication_string
88+
natauth localhost *7CEB3FDE5F7A9C4CE5FBE610D7D8EDA62EBE5F4E
89+
newpass localhost *7CEB3FDE5F7A9C4CE5FBE610D7D8EDA62EBE5F4E
90+
newpassnat localhost *7CEB3FDE5F7A9C4CE5FBE610D7D8EDA62EBE5F4E
91+
oldauth localhost *7CEB3FDE5F7A9C4CE5FBE610D7D8EDA62EBE5F4E
92+
oldpass localhost *7CEB3FDE5F7A9C4CE5FBE610D7D8EDA62EBE5F4E
93+
oldpassold localhost *7CEB3FDE5F7A9C4CE5FBE610D7D8EDA62EBE5F4E
94+
connect con,localhost,natauth,test2,;
95+
select current_user();
96+
current_user()
97+
natauth@localhost
98+
disconnect con;
99+
connect con,localhost,newpass,test2,;
100+
select current_user();
101+
current_user()
102+
newpass@localhost
103+
disconnect con;
104+
connect con,localhost,newpassnat,test2,;
105+
select current_user();
106+
current_user()
107+
newpassnat@localhost
108+
disconnect con;
109+
connect con,localhost,oldauth,test2,;
110+
select current_user();
111+
current_user()
112+
oldauth@localhost
113+
disconnect con;
114+
connect con,localhost,oldpass,test2,;
115+
select current_user();
116+
current_user()
117+
oldpass@localhost
118+
disconnect con;
119+
connect con,localhost,oldpassold,test2,;
120+
select current_user();
121+
current_user()
122+
oldpassold@localhost
123+
disconnect con;
124+
connection default;
125+
flush privileges;
126+
connect con,localhost,natauth,test2,;
127+
select current_user();
128+
current_user()
129+
natauth@localhost
130+
disconnect con;
131+
connect con,localhost,newpass,test2,;
132+
select current_user();
133+
current_user()
134+
newpass@localhost
135+
disconnect con;
136+
connect con,localhost,newpassnat,test2,;
137+
select current_user();
138+
current_user()
139+
newpassnat@localhost
140+
disconnect con;
141+
connect con,localhost,oldauth,test2,;
142+
select current_user();
143+
current_user()
144+
oldauth@localhost
145+
disconnect con;
146+
connect con,localhost,oldpass,test2,;
147+
select current_user();
148+
current_user()
149+
oldpass@localhost
150+
disconnect con;
151+
connect con,localhost,oldpassold,test2,;
152+
select current_user();
153+
current_user()
154+
oldpassold@localhost
155+
disconnect con;
156+
connection default;
157+
drop user natauth@localhost, newpass@localhost, newpassnat@localhost;
158+
drop user oldauth@localhost, oldpass@localhost, oldpassold@localhost;
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
#
2+
# MDEV-9835 Valid password is not working after server restart.
3+
#
4+
# Various combinations of SET PASSWORD and not-empty mysql.user.plugin field
5+
#
6+
--source include/not_embedded.inc
7+
8+
--enable_connect_log
9+
10+
# The hash (old and new) is for 'test'
11+
create user natauth@localhost identified via 'mysql_native_password' using '*94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29';
12+
13+
create user newpass@localhost identified by password '*94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29';
14+
15+
create user newpassnat@localhost identified via 'mysql_native_password';
16+
set password for newpassnat@localhost = '*94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29';
17+
18+
create user oldauth@localhost identified with 'mysql_old_password' using '378b243e220ca493';
19+
20+
create user oldpass@localhost identified by password '378b243e220ca493';
21+
22+
create user oldpassold@localhost identified with 'mysql_old_password';
23+
set password for oldpassold@localhost = '378b243e220ca493';
24+
25+
--sorted_result
26+
select user, host, password, plugin, authentication_string from mysql.user where user != 'root';
27+
28+
--connect(con,localhost,natauth,test,)
29+
select current_user();
30+
--disconnect con
31+
--connect(con,localhost,newpass,test,)
32+
select current_user();
33+
--disconnect con
34+
--connect(con,localhost,newpassnat,test,)
35+
select current_user();
36+
--disconnect con
37+
--connect(con,localhost,oldauth,test,)
38+
select current_user();
39+
--disconnect con
40+
--connect(con,localhost,oldpass,test,)
41+
select current_user();
42+
--disconnect con
43+
--connect(con,localhost,oldpassold,test,)
44+
select current_user();
45+
--disconnect con
46+
47+
--connection default
48+
49+
flush privileges;
50+
51+
--connect(con,localhost,natauth,test,)
52+
select current_user();
53+
--disconnect con
54+
--connect(con,localhost,newpass,test,)
55+
select current_user();
56+
--disconnect con
57+
--connect(con,localhost,newpassnat,test,)
58+
select current_user();
59+
--disconnect con
60+
--connect(con,localhost,oldauth,test,)
61+
select current_user();
62+
--disconnect con
63+
--connect(con,localhost,oldpass,test,)
64+
select current_user();
65+
--disconnect con
66+
--connect(con,localhost,oldpassold,test,)
67+
select current_user();
68+
--disconnect con
69+
70+
--connection default
71+
72+
# changing to the NEW password hash
73+
set password for natauth@localhost = PASSWORD('test2');
74+
set password for newpass@localhost = PASSWORD('test2');
75+
set password for newpassnat@localhost = PASSWORD('test2');
76+
set password for oldauth@localhost = PASSWORD('test2');
77+
set password for oldpass@localhost = PASSWORD('test2');
78+
set password for oldpassold@localhost = PASSWORD('test2');
79+
80+
--sorted_result
81+
select user, host, password, plugin, authentication_string from mysql.user where user != 'root';
82+
83+
--connect(con,localhost,natauth,test2,)
84+
select current_user();
85+
--disconnect con
86+
--connect(con,localhost,newpass,test2,)
87+
select current_user();
88+
--disconnect con
89+
--connect(con,localhost,newpassnat,test2,)
90+
select current_user();
91+
--disconnect con
92+
--connect(con,localhost,oldauth,test2,)
93+
select current_user();
94+
--disconnect con
95+
--connect(con,localhost,oldpass,test2,)
96+
select current_user();
97+
--disconnect con
98+
--connect(con,localhost,oldpassold,test2,)
99+
select current_user();
100+
--disconnect con
101+
102+
--connection default
103+
104+
flush privileges;
105+
106+
--connect(con,localhost,natauth,test2,)
107+
select current_user();
108+
--disconnect con
109+
--connect(con,localhost,newpass,test2,)
110+
select current_user();
111+
--disconnect con
112+
--connect(con,localhost,newpassnat,test2,)
113+
select current_user();
114+
--disconnect con
115+
--connect(con,localhost,oldauth,test2,)
116+
select current_user();
117+
--disconnect con
118+
--connect(con,localhost,oldpass,test2,)
119+
select current_user();
120+
--disconnect con
121+
--connect(con,localhost,oldpassold,test2,)
122+
select current_user();
123+
--disconnect con
124+
125+
--connection default
126+
drop user natauth@localhost, newpass@localhost, newpassnat@localhost;
127+
drop user oldauth@localhost, oldpass@localhost, oldpassold@localhost;
128+

sql/sql_acl.cc

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -557,9 +557,8 @@ static void init_check_host(void);
557557
static void rebuild_check_host(void);
558558
static ACL_USER *find_acl_user(const char *host, const char *user,
559559
my_bool exact);
560-
static bool update_user_table(THD *thd, TABLE *table, const char *host,
561-
const char *user, const char *new_password,
562-
uint new_password_len);
560+
static bool update_user_table(THD *, TABLE *, const char *, const char *, const
561+
char *, uint, bool);
563562
static my_bool acl_load(THD *thd, TABLE_LIST *tables);
564563
static my_bool grant_load(THD *thd, TABLE_LIST *tables);
565564
static inline void get_grantor(THD *thd, char* grantor);
@@ -1912,6 +1911,7 @@ bool change_password(THD *thd, const char *host, const char *user,
19121911
bool save_binlog_row_based;
19131912
uint new_password_len= (uint) strlen(new_password);
19141913
bool result= 1;
1914+
bool use_salt= 0;
19151915
DBUG_ENTER("change_password");
19161916
DBUG_PRINT("enter",("host: '%s' user: '%s' new_password: '%s'",
19171917
host,user,new_password));
@@ -1967,6 +1967,7 @@ bool change_password(THD *thd, const char *host, const char *user,
19671967
acl_user->auth_string.length= new_password_len;
19681968
set_user_salt(acl_user, new_password, new_password_len);
19691969
set_user_plugin(acl_user, new_password_len);
1970+
use_salt= 1;
19701971
}
19711972
else
19721973
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
@@ -1975,7 +1976,7 @@ bool change_password(THD *thd, const char *host, const char *user,
19751976
if (update_user_table(thd, table,
19761977
acl_user->host.hostname ? acl_user->host.hostname : "",
19771978
acl_user->user ? acl_user->user : "",
1978-
new_password, new_password_len))
1979+
new_password, new_password_len, use_salt))
19791980
{
19801981
mysql_mutex_unlock(&acl_cache->lock); /* purecov: deadcode */
19811982
goto end;
@@ -2223,7 +2224,8 @@ bool hostname_requires_resolving(const char *hostname)
22232224

22242225
static bool update_user_table(THD *thd, TABLE *table,
22252226
const char *host, const char *user,
2226-
const char *new_password, uint new_password_len)
2227+
const char *new_password, uint new_password_len,
2228+
bool reset_plugin)
22272229
{
22282230
char user_key[MAX_KEY_LENGTH];
22292231
int error;
@@ -2246,6 +2248,11 @@ static bool update_user_table(THD *thd, TABLE *table,
22462248
}
22472249
store_record(table,record[1]);
22482250
table->field[2]->store(new_password, new_password_len, system_charset_info);
2251+
if (reset_plugin && table->s->fields >= 41)
2252+
{
2253+
table->field[40]->reset();
2254+
table->field[41]->reset();
2255+
}
22492256
if ((error=table->file->ha_update_row(table->record[1],table->record[0])) &&
22502257
error != HA_ERR_RECORD_IS_THE_SAME)
22512258
{

0 commit comments

Comments
 (0)