Skip to content

Commit 4c3610a

Browse files
author
Bharathy Satish
committed
Bug #21464621: MYSQL CLI SHOULD SUGGEST CONNECT-EXPIRED-PASSWORD WHEN ERROR 1862 OCCURS
When mysql connects to server in batch mode with an expired account and executes SET PASSWORD statement the returned error message is not meaningfull. Fix is to report a more descriptive error message.
1 parent b78fc42 commit 4c3610a

File tree

7 files changed

+37
-6
lines changed

7 files changed

+37
-6
lines changed

client/mysql.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373

7474
#include <algorithm>
7575
#include <sql_common.h>
76+
#include <mysqld_error.h>
7677

7778
using std::min;
7879
using std::max;
@@ -4936,6 +4937,12 @@ sql_real_connect(char *host,char *database,char *user,char *password,
49364937
database, opt_mysql_port, opt_mysql_unix_port,
49374938
connect_flag | CLIENT_MULTI_STATEMENTS))
49384939
{
4940+
if(mysql_errno(&mysql) == ER_MUST_CHANGE_PASSWORD_LOGIN)
4941+
{
4942+
tee_fprintf(stdout, "Please use --connect-expired-password option or " \
4943+
"invoke mysql in interactive mode.\n");
4944+
return ignore_errors ? -1 : 1;
4945+
}
49394946
if (!silent ||
49404947
(mysql_errno(&mysql) != CR_CONN_HOST_ERROR &&
49414948
mysql_errno(&mysql) != CR_CONNECTION_ERROR))

mysql-test/r/connect.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ CREATE USER wl6587@localhost IDENTIFIED BY 'wl6587';
333333
ALTER USER wl6587@localhost PASSWORD EXPIRE;
334334
# non-interactive mysql should fail
335335
mysql: [Warning] Using a password on the command line interface can be insecure.
336-
ERROR 1862 (HY000): Your password has expired. To log in you must change it using a client that supports expired passwords.
336+
Please use --connect-expired-password option or invoke mysql in interactive mode.
337337
# mysqladmin non-password should fail
338338
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
339339
mysqladmin: connect to server at 'localhost' failed

mysql-test/r/disconnect_on_expired_password_default.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ALTER USER 'bernt' IDENTIFIED BY 'secret';
77
ALTER USER 'bernt' PASSWORD EXPIRE;
88
# Attempt to login should fail
99
mysql: [Warning] Using a password on the command line interface can be insecure.
10-
ERROR 1862 (HY000): Your password has expired. To log in you must change it using a client that supports expired passwords.
10+
Please use --connect-expired-password option or invoke mysql in interactive mode.
1111
DROP USER 'bernt';
1212
## Test mysqltest
1313
CREATE USER 'bernt';

mysql-test/r/grant.result

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2744,7 +2744,7 @@ UPDATE mysql.user SET password_last_changed = (now() - INTERVAL 3 DAY) where use
27442744
FLUSH PRIVILEGES;
27452745
# Attempt to execute query should fail
27462746
mysql: [Warning] Using a password on the command line interface can be insecure.
2747-
ERROR 1862 (HY000): Your password has expired. To log in you must change it using a client that supports expired passwords.
2747+
Please use --connect-expired-password option or invoke mysql in interactive mode.
27482748
# Doing something should fail
27492749
SELECT 1;
27502750
ERROR HY000: You must reset your password using ALTER USER statement before executing this statement.
@@ -2779,7 +2779,7 @@ NULL
27792779
# This should not pass as default_password_lifetime
27802780
# (which is 2 now) is being used.
27812781
mysql: [Warning] Using a password on the command line interface can be insecure.
2782-
ERROR 1862 (HY000): Your password has expired. To log in you must change it using a client that supports expired passwords.
2782+
Please use --connect-expired-password option or invoke mysql in interactive mode.
27832783
SET GLOBAL default_password_lifetime = 0;
27842784
ALTER USER 'wl7131' PASSWORD EXPIRE INTERVAL 4 DAY;
27852785
# Should report 4
@@ -2788,7 +2788,7 @@ password_lifetime
27882788
4
27892789
# This should not pass.
27902790
mysql: [Warning] Using a password on the command line interface can be insecure.
2791-
ERROR 1862 (HY000): Your password has expired. To log in you must change it using a client that supports expired passwords.
2791+
Please use --connect-expired-password option or invoke mysql in interactive mode.
27922792
SET GLOBAL default_password_lifetime = @saved_value;
27932793
ALTER USER 'wl7131' PASSWORD EXPIRE INTERVAL 6 DAY;
27942794
# Should report 6

mysql-test/r/grant_alter_user.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ CREATE USER u1@localhost PASSWORD EXPIRE;
718718
SELECT password_expired FROM mysql.user where user='u1';
719719
password_expired
720720
Y
721-
ERROR 1862 (HY000): Your password has expired. To log in you must change it using a client that supports expired passwords.
721+
Please use --connect-expired-password option or invoke mysql in interactive mode.
722722
DROP USER u1@localhost;
723723
# CREATE USER with password expire attributes for anonymous user
724724
CREATE USER '' PASSWORD EXPIRE;

mysql-test/r/mysql.result

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,5 +525,16 @@ a
525525
#
526526
mysql: [ERROR] mysql: Empty value for 'port' specified
527527
mysql: [ERROR] mysql: Empty value for 'port' specified
528+
#
529+
# Bug #21464621: MYSQL CLI SHOULD SUGGEST CONNECT-EXPIRED-PASSWORD WHEN ERROR 1862 OCCURS
530+
#
531+
CREATE USER bug21464621 IDENTIFIED BY 'password' PASSWORD EXPIRE;
532+
mysql: [Warning] Using a password on the command line interface can be insecure.
533+
Please use --connect-expired-password option or invoke mysql in interactive mode.
534+
mysql: [Warning] Using a password on the command line interface can be insecure.
535+
mysql: [Warning] Using a password on the command line interface can be insecure.
536+
user()
537+
bug21464621@localhost
538+
DROP USER bug21464621;
528539

529540
End of tests

mysql-test/t/mysql.test

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,19 @@ EOF
644644
--error 5
645645
--exec $MYSQL -P "" -e "SELECT 1" 2>&1
646646

647+
--echo #
648+
--echo # Bug #21464621: MYSQL CLI SHOULD SUGGEST CONNECT-EXPIRED-PASSWORD WHEN ERROR 1862 OCCURS
649+
--echo #
650+
651+
CREATE USER bug21464621 IDENTIFIED BY 'password' PASSWORD EXPIRE;
652+
--error 1
653+
--exec $MYSQL -u bug21464621 --password="password" -e "SET PASSWORD='123';" 2>&1
654+
# change the password using set password
655+
--exec $MYSQL -u bug21464621 --password="password" -e "SET PASSWORD='123';" --connect-expired-password 2>&1
656+
--exec $MYSQL -u bug21464621 --password="123" -e "SELECT user();" 2>&1
657+
658+
#cleanup
659+
DROP USER bug21464621;
647660

648661
--echo
649662
--echo End of tests

0 commit comments

Comments
 (0)