Skip to content

Commit 7b555ff

Browse files
committed
MDEV-27341 Use SET PASSWORD to change PAM service
SET PASSWORD = PASSWORD('foo') would fail for pam plugin with ERROR HY000: SET PASSWORD is ignored for users authenticating via pam plugin but SET PASSWORD = 'foo' would not. Now it will.
1 parent da76d25 commit 7b555ff

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed

include/mysql/plugin_auth.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ struct st_mysql_auth
147147
148148
@return 0 for ok, 1 for error
149149
150-
Can be NULL.
150+
Can be NULL, in this case one will not be able to use SET PASSWORD or
151+
PASSWORD('...') in GRANT, CREATE USER, ALTER USER.
151152
*/
152153
int (*hash_password)(const char *password, size_t password_length,
153154
char *hash, size_t *hash_length);

mysql-test/suite/plugins/r/pam.result

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,21 @@ select user(), current_user(), database();
9191
user() current_user() database()
9292
PAM_TEST@localhost PAM_TEST@% test
9393
drop user PAM_TEST;
94+
#
95+
# MDEV-27341 Use SET PASSWORD to change PAM service
96+
#
97+
create user pam_test identified via pam using 'mariadb_mtr';
98+
Challenge input first.
99+
Enter: *************************
100+
Now, the magic number!
101+
PIN: 9225
102+
select user(), current_user(), database();
103+
user() current_user() database()
104+
pam_test@localhost pam_test@% test
105+
set password='foo';
106+
ERROR HY000: SET PASSWORD is ignored for users authenticating via pam plugin
107+
show create user;
108+
CREATE USER for pam_test@%
109+
CREATE USER `pam_test`@`%` IDENTIFIED VIA pam USING 'mariadb_mtr'
110+
drop user pam_test;
94111
uninstall plugin pam;

mysql-test/suite/plugins/t/pam.test

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ EOF
4545
--echo #
4646
--echo # athentication is successful
4747
--echo #
48-
--error 0
4948
--exec $MYSQL_TEST -u test_pam -pgoodpassword --plugin-dir=$plugindir < $MYSQLTEST_VARDIR/tmp/pam_good2.txt
5049

5150
--echo #
@@ -106,6 +105,22 @@ set global pam_winbind_workaround=1;
106105
--remove_file $MYSQLTEST_VARDIR/tmp/pam_ugly.txt
107106
drop user PAM_TEST;
108107

108+
--echo #
109+
--echo # MDEV-27341 Use SET PASSWORD to change PAM service
110+
--echo #
111+
create user pam_test identified via pam using 'mariadb_mtr';
112+
--write_file $MYSQLTEST_VARDIR/tmp/setpwd.txt
113+
not very secret challenge
114+
9225
115+
select user(), current_user(), database();
116+
error ER_SET_PASSWORD_AUTH_PLUGIN;
117+
set password='foo';
118+
show create user;
119+
EOF
120+
--exec $MYSQL_TEST -u pam_test < $MYSQLTEST_VARDIR/tmp/setpwd.txt
121+
--remove_file $MYSQLTEST_VARDIR/tmp/setpwd.txt
122+
drop user pam_test;
123+
109124
let $count_sessions= 1;
110125
--source include/wait_until_count_sessions.inc
111126
uninstall plugin pam;

sql/sql_acl.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2135,6 +2135,12 @@ static int set_user_auth(THD *thd, const LEX_CSTRING &user,
21352135
goto end;
21362136
}
21372137

2138+
if (thd->lex->sql_command == SQLCOM_SET_OPTION && !info->hash_password)
2139+
{
2140+
res= ER_SET_PASSWORD_AUTH_PLUGIN;
2141+
goto end;
2142+
}
2143+
21382144
if (info->hash_password &&
21392145
validate_password(thd, user, pwtext, auth->auth_string.length))
21402146
{

0 commit comments

Comments
 (0)