Commit 8b77e6c6 authored by Robert Bindar's avatar Robert Bindar

MDEV-24114 SHOW CREATE USER doesnt display correct password expiry status

Given PASSWORD EXPIRE and PASSWORD EXPIRE [NEVER|INTERVAL x DAY] are
two different mechanisms, SHOW CREATE USER should display all the
information required to restore the state of an account which
includes both a manual expired state and an automatic policy.

The solution proposed here keeps a CREATE USER ... PASSWORD EXPIRE
statement and adds an aditional
ALTER USER .. PASSWORD EXPIRE [NEVER|INTERVAL x DAY] when necessary

This way a tool can restore almost the complete state of an account
as it was before a dump. The only information left still is the
value of the password_last_changed column from mysql.global_priv
parent 7b8dacc4
......@@ -156,6 +156,7 @@ alter user user1@localhost PASSWORD EXPIRE NEVER ACCOUNT UNLOCK ;
show create user user1@localhost;
CREATE USER for user1@localhost
CREATE USER `user1`@`localhost` PASSWORD EXPIRE
ALTER USER `user1`@`localhost` PASSWORD EXPIRE NEVER
alter user user1@localhost ACCOUNT LOCK PASSWORD EXPIRE DEFAULT;
show create user user1@localhost;
CREATE USER for user1@localhost
......@@ -167,5 +168,6 @@ localhost user1 {"access":0,"plugin":"mysql_native_password","authentication_str
show create user user1@localhost;
CREATE USER for user1@localhost
CREATE USER `user1`@`localhost` PASSWORD EXPIRE
ALTER USER `user1`@`localhost` PASSWORD EXPIRE INTERVAL 60 DAY
drop user user1@localhost;
drop user user2@localhost;
......@@ -125,6 +125,7 @@ alter user user1@localhost password expire;
show create user user1@localhost;
CREATE USER for user1@localhost
CREATE USER `user1`@`localhost` PASSWORD EXPIRE
ALTER USER `user1`@`localhost` PASSWORD EXPIRE INTERVAL 123 DAY
set password for user1@localhost= password('');
show create user user1@localhost;
CREATE USER for user1@localhost
......@@ -151,10 +152,12 @@ alter user user1@localhost password expire;
show create user user1@localhost;
CREATE USER for user1@localhost
CREATE USER `user1`@`localhost` PASSWORD EXPIRE
ALTER USER `user1`@`localhost` PASSWORD EXPIRE NEVER
flush privileges;
show create user user1@localhost;
CREATE USER for user1@localhost
CREATE USER `user1`@`localhost` PASSWORD EXPIRE
ALTER USER `user1`@`localhost` PASSWORD EXPIRE NEVER
set password for user1@localhost= password('');
alter user user1@localhost password expire default;
show create user user1@localhost;
......@@ -184,10 +187,12 @@ alter user user1@localhost password expire;
show create user user1@localhost;
CREATE USER for user1@localhost
CREATE USER `user1`@`localhost` PASSWORD EXPIRE
ALTER USER `user1`@`localhost` PASSWORD EXPIRE NEVER
flush privileges;
show create user user1@localhost;
CREATE USER for user1@localhost
CREATE USER `user1`@`localhost` PASSWORD EXPIRE
ALTER USER `user1`@`localhost` PASSWORD EXPIRE NEVER
set global disconnect_on_expired_password=ON;
connect(localhost,user1,,test,MYSQL_PORT,MYSQL_SOCK);
connect con1,localhost,user1;
......
......@@ -214,6 +214,7 @@ alter user user@localhost password expire;
show create user user@localhost;
CREATE USER for user@localhost
CREATE USER `user`@`localhost` PASSWORD EXPIRE
ALTER USER `user`@`localhost` PASSWORD EXPIRE INTERVAL 123 DAY
set password for user@localhost= password('');
show create user user@localhost;
CREATE USER for user@localhost
......
......@@ -8896,6 +8896,16 @@ static bool print_grants_for_role(THD *thd, ACL_ROLE * role)
}
static void append_auto_expiration_policy(ACL_USER *acl_user, String *r) {
if (!acl_user->password_lifetime)
r->append(STRING_WITH_LEN(" PASSWORD EXPIRE NEVER"));
else if (acl_user->password_lifetime > 0)
{
r->append(STRING_WITH_LEN(" PASSWORD EXPIRE INTERVAL "));
r->append_longlong(acl_user->password_lifetime);
r->append(STRING_WITH_LEN(" DAY"));
}
}
bool mysql_show_create_user(THD *thd, LEX_USER *lex_user)
{
......@@ -8955,14 +8965,8 @@ bool mysql_show_create_user(THD *thd, LEX_USER *lex_user)
if (acl_user->password_expired)
result.append(STRING_WITH_LEN(" PASSWORD EXPIRE"));
else if (!acl_user->password_lifetime)
result.append(STRING_WITH_LEN(" PASSWORD EXPIRE NEVER"));
else if (acl_user->password_lifetime > 0)
{
result.append(STRING_WITH_LEN(" PASSWORD EXPIRE INTERVAL "));
result.append_longlong(acl_user->password_lifetime);
result.append(STRING_WITH_LEN(" DAY"));
}
else
append_auto_expiration_policy(acl_user, &result);
protocol->prepare_for_resend();
protocol->store(result.ptr(), result.length(), result.charset());
......@@ -8970,6 +8974,28 @@ bool mysql_show_create_user(THD *thd, LEX_USER *lex_user)
{
error= true;
}
/* MDEV-24114 - PASSWORD EXPIRE and PASSWORD EXPIRE [NEVER | INTERVAL X DAY]
are two different mechanisms. To make sure a tool can restore the state
of a user account, including both the manual expiration state of the
account and the automatic expiration policy attached to it, we should
print two statements here, a CREATE USER (printed above) and an ALTER USER */
if (acl_user->password_expired && acl_user->password_lifetime > -1) {
result.length(0);
result.append("ALTER USER ");
append_identifier(thd, &result, username, strlen(username));
result.append('@');
append_identifier(thd, &result, acl_user->host.hostname,
acl_user->hostname_length);
append_auto_expiration_policy(acl_user, &result);
protocol->prepare_for_resend();
protocol->store(result.ptr(), result.length(), result.charset());
if (protocol->write())
{
error= true;
}
}
my_eof(thd);
end:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment