Skip to content

Commit 6382339

Browse files
committed
MDEV-34311: Alter USER should reset all account limit counters
This commit introduces a reset of password errors counter on any alter user command for the altered user. This is done so as to not require a complete privilege system reload.
1 parent 2d8d813 commit 6382339

File tree

4 files changed

+50
-10
lines changed

4 files changed

+50
-10
lines changed

mysql-test/main/max_password_errors.result

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ connect con1, localhost, u, bad_pass;
99
ERROR 28000: Access denied for user 'u'@'localhost' (using password: YES)
1010
connect(localhost,u,good_pass,test,MASTER_PORT,MASTER_SOCKET);
1111
connect con1, localhost, u, good_pass;
12-
ERROR HY000: User is blocked because of too many credential errors; unblock with 'FLUSH PRIVILEGES'
12+
ERROR HY000: User is blocked because of too many credential errors; unblock with 'ALTER USER / FLUSH PRIVILEGES'
1313
connect(localhost,u,bad_pass,test,MASTER_PORT,MASTER_SOCKET);
1414
connect con1, localhost, u, bad_pass;
15-
ERROR HY000: User is blocked because of too many credential errors; unblock with 'FLUSH PRIVILEGES'
15+
ERROR HY000: User is blocked because of too many credential errors; unblock with 'ALTER USER / FLUSH PRIVILEGES'
1616
FLUSH PRIVILEGES;
1717
connect con1, localhost, u, good_pass;
1818
disconnect con1;
@@ -27,7 +27,7 @@ ERROR 28000: Access denied for user 'u'@'localhost' (using password: YES)
2727
connect con1, localhost, u, good_pass;
2828
ERROR 28000: Access denied for user 'u'@'localhost' (using password: YES)
2929
ERROR 28000: Access denied for user 'u'@'localhost' (using password: YES)
30-
ERROR HY000: User is blocked because of too many credential errors; unblock with 'FLUSH PRIVILEGES'
30+
ERROR HY000: User is blocked because of too many credential errors; unblock with 'ALTER USER / FLUSH PRIVILEGES'
3131
disconnect con1;
3232
connection default;
3333
FLUSH PRIVILEGES;
@@ -40,6 +40,21 @@ ERROR 28000: Access denied for user 'root'@'localhost' (using password: YES)
4040
connect con1, localhost, u, good_pass;
4141
disconnect con1;
4242
connection default;
43+
connect(localhost,u,bad_password,test,MASTER_PORT,MASTER_SOCKET);
44+
connect con1, localhost, u, bad_password;
45+
ERROR 28000: Access denied for user 'u'@'localhost' (using password: YES)
46+
connect(localhost,u,bad_password,test,MASTER_PORT,MASTER_SOCKET);
47+
connect con1, localhost, u, bad_password;
48+
ERROR 28000: Access denied for user 'u'@'localhost' (using password: YES)
49+
connect(localhost,u,good_pass,test,MASTER_PORT,MASTER_SOCKET);
50+
connect con1, localhost, u, good_pass;
51+
ERROR HY000: User is blocked because of too many credential errors; unblock with 'ALTER USER / FLUSH PRIVILEGES'
52+
ALTER USER u ACCOUNT UNLOCK;
53+
connect(localhost,u,bad_password,test,MASTER_PORT,MASTER_SOCKET);
54+
connect con1, localhost, u, bad_password;
55+
ERROR 28000: Access denied for user 'u'@'localhost' (using password: YES)
56+
connect con1, localhost, u, good_pass;
57+
disconnect con1;
58+
connection default;
4359
DROP USER u;
44-
FLUSH PRIVILEGES;
4560
set global max_password_errors=@old_max_password_errors;

mysql-test/main/max_password_errors.test

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,28 @@ connect (con1, localhost, root, bad_pass);
5959
connect (con1, localhost, u, good_pass);
6060
disconnect con1;
6161
connection default;
62+
63+
# Block u again
64+
--replace_result $MASTER_MYSOCK MASTER_SOCKET $MASTER_MYPORT MASTER_PORT
65+
error ER_ACCESS_DENIED_ERROR;
66+
connect(con1, localhost, u, bad_password);
67+
--replace_result $MASTER_MYSOCK MASTER_SOCKET $MASTER_MYPORT MASTER_PORT
68+
error ER_ACCESS_DENIED_ERROR;
69+
connect(con1, localhost, u, bad_password);
70+
--replace_result $MASTER_MYSOCK MASTER_SOCKET $MASTER_MYPORT MASTER_PORT
71+
error ER_USER_IS_BLOCKED;
72+
connect(con1, localhost, u, good_pass);
73+
74+
# Unblock foo
75+
ALTER USER u ACCOUNT UNLOCK;
76+
77+
--replace_result $MASTER_MYSOCK MASTER_SOCKET $MASTER_MYPORT MASTER_PORT
78+
error ER_ACCESS_DENIED_ERROR;
79+
connect(con1, localhost, u, bad_password);
80+
81+
connect(con1, localhost, u, good_pass);
82+
disconnect con1;
83+
connection default;
84+
6285
DROP USER u;
63-
FLUSH PRIVILEGES;
64-
set global max_password_errors=@old_max_password_errors;
86+
set global max_password_errors=@old_max_password_errors;

sql/share/errmsg-utf8.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9922,9 +9922,9 @@ ER_BACKUP_UNKNOWN_STAGE
99229922
eng "Unknown backup stage: '%s'. Stage should be one of START, FLUSH, BLOCK_DDL, BLOCK_COMMIT or END"
99239923
spa "Fase de respaldo desconocida: '%s'. La fase debería de ser una de START, FLUSH, BLOCK_DDL, BLOCK_COMMIT o END"
99249924
ER_USER_IS_BLOCKED
9925-
chi "由于凭证错误太多,用户被阻止;用'FLUSH PRIVILEGES'解锁"
9926-
eng "User is blocked because of too many credential errors; unblock with 'FLUSH PRIVILEGES'"
9927-
spa "El usuario está bloqueado a causa de demasiados errores de credenciales; desbloquee mediante 'FLUSH PRIVILEGES'"
9925+
chi "由于凭证错误太多,用户被阻止;用'ALTER USER / FLUSH PRIVILEGES'解锁"
9926+
eng "User is blocked because of too many credential errors; unblock with 'ALTER USER / FLUSH PRIVILEGES'"
9927+
spa "El usuario está bloqueado a causa de demasiados errores de credenciales; desbloquee mediante 'ALTER USER / FLUSH PRIVILEGES'"
99289928
ER_ACCOUNT_HAS_BEEN_LOCKED
99299929
chi "访问拒绝,此帐户已锁定"
99309930
eng "Access denied, this account is locked"

sql/sql_acl.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ class ACL_USER :public ACL_USER_BASE,
263263
PASSWD_ERROR_INCREMENT
264264
};
265265

266-
inline void update_password_errors(PASSWD_ERROR_ACTION action)
266+
void update_password_errors(PASSWD_ERROR_ACTION action)
267267
{
268268
switch (action)
269269
{
@@ -3560,6 +3560,9 @@ static int acl_user_update(THD *thd, ACL_USER *acl_user, uint nauth,
35603560
break;
35613561
}
35623562

3563+
// Any alter user resets password_errors;
3564+
acl_user->update_password_errors(ACL_USER::PASSWD_ERROR_CLEAR);
3565+
35633566
return 0;
35643567
}
35653568

0 commit comments

Comments
 (0)