Skip to content

Commit 9ca3571

Browse files
committed
MDEV-18686 Add option to PAM authentication plugin to allow case insensitive username matching
add a new option --pam-windbind-workaround for a pam plugin to work around pam_winbind unconditional username lowercasing
1 parent ed866e9 commit 9ca3571

File tree

3 files changed

+49
-5
lines changed

3 files changed

+49
-5
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,24 @@ Now, the magic number!
2222
PIN: ****
2323
drop user test_pam;
2424
drop user pam_test;
25+
create user PAM_TEST identified via pam using 'mariadb_mtr';
26+
#
27+
# athentication is unsuccessful
28+
#
29+
Challenge input first.
30+
Enter: not very secret challenge
31+
Now, the magic number!
32+
PIN: ****
33+
set global pam_winbind_workaround=1;
34+
#
35+
# athentication is successful
36+
#
37+
Challenge input first.
38+
Enter: not very secret challenge
39+
Now, the magic number!
40+
PIN: ****
41+
select user(), current_user(), database();
42+
user() current_user() database()
43+
PAM_TEST@localhost PAM_TEST@% test
44+
drop user PAM_TEST;
2545
uninstall plugin pam;

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

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,34 @@ EOF
1717
--echo # athentication is successful, challenge/pin are ok
1818
--echo # note that current_user() differs from user()
1919
--echo #
20-
--exec $MYSQL_TEST -u test_pam --plugin-dir=$plugindir < $MYSQLTEST_VARDIR/tmp/pam_good.txt
20+
--exec $MYSQL_TEST -u test_pam < $MYSQLTEST_VARDIR/tmp/pam_good.txt
2121

2222
--echo #
2323
--echo # athentication is unsuccessful
2424
--echo #
2525
--error 1
26-
--exec $MYSQL_TEST -u test_pam --plugin-dir=$plugindir < $MYSQLTEST_VARDIR/tmp/pam_bad.txt
26+
--exec $MYSQL_TEST -u test_pam < $MYSQLTEST_VARDIR/tmp/pam_bad.txt
2727

28-
--remove_file $MYSQLTEST_VARDIR/tmp/pam_good.txt
29-
--remove_file $MYSQLTEST_VARDIR/tmp/pam_bad.txt
3028
drop user test_pam;
3129
drop user pam_test;
30+
create user PAM_TEST identified via pam using 'mariadb_mtr';
31+
32+
--echo #
33+
--echo # athentication is unsuccessful
34+
--echo #
35+
--error 1
36+
--exec $MYSQL_TEST -u PAM_TEST < $MYSQLTEST_VARDIR/tmp/pam_good.txt
37+
38+
set global pam_winbind_workaround=1;
39+
--echo #
40+
--echo # athentication is successful
41+
--echo #
42+
--exec $MYSQL_TEST -u PAM_TEST < $MYSQLTEST_VARDIR/tmp/pam_good.txt
43+
44+
--remove_file $MYSQLTEST_VARDIR/tmp/pam_good.txt
45+
--remove_file $MYSQLTEST_VARDIR/tmp/pam_bad.txt
46+
drop user PAM_TEST;
47+
3248
let $count_sessions= 1;
3349
--source include/wait_until_count_sessions.inc
3450
uninstall plugin pam;

plugin/auth_pam/auth_pam.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ static char pam_debug = 0;
5252
#define PAM_DEBUG(X) /* no-op */
5353
#endif
5454

55+
static char winbind_hack = 0;
56+
5557
static int conv(int n, const struct pam_message **msg,
5658
struct pam_response **resp, void *data)
5759
{
@@ -159,7 +161,8 @@ static int pam_auth(MYSQL_PLUGIN_VIO *vio, MYSQL_SERVER_AUTH_INFO *info)
159161
PAM_DEBUG((stderr, "PAM: pam_get_item(PAM_USER)\n"));
160162
DO( pam_get_item(pamh, PAM_USER, (pam_get_item_3_arg) &new_username) );
161163

162-
if (new_username && strcmp(new_username, info->user_name))
164+
if (new_username &&
165+
(winbind_hack ? strcasecmp : strcmp)(new_username, info->user_name))
163166
strncpy(info->authenticated_as, new_username,
164167
sizeof(info->authenticated_as)-1);
165168
info->authenticated_as[sizeof(info->authenticated_as)-1]= 0;
@@ -185,6 +188,10 @@ static MYSQL_SYSVAR_BOOL(use_cleartext_plugin, use_cleartext_plugin,
185188
"supports simple PAM policies that don't require anything besides "
186189
"a password", NULL, NULL, 0);
187190

191+
static MYSQL_SYSVAR_BOOL(winbind_workaround, winbind_hack, PLUGIN_VAR_OPCMDARG,
192+
"Compare usernames case insensitively to work around pam_winbind "
193+
"unconditional username lowercasing", NULL, NULL, 0);
194+
188195
#ifndef DBUG_OFF
189196
static MYSQL_SYSVAR_BOOL(debug, pam_debug, PLUGIN_VAR_OPCMDARG,
190197
"Log all PAM activity", NULL, NULL, 0);
@@ -193,6 +200,7 @@ static MYSQL_SYSVAR_BOOL(debug, pam_debug, PLUGIN_VAR_OPCMDARG,
193200

194201
static struct st_mysql_sys_var* vars[] = {
195202
MYSQL_SYSVAR(use_cleartext_plugin),
203+
MYSQL_SYSVAR(winbind_workaround),
196204
#ifndef DBUG_OFF
197205
MYSQL_SYSVAR(debug),
198206
#endif

0 commit comments

Comments
 (0)