@@ -18,8 +18,8 @@ if (!$res = $link->query("SHOW PLUGINS"))
18
18
19
19
$ have_pam = false ;
20
20
while ($ row = $ res ->fetch_assoc ()) {
21
- if (isset ($ row ['Name ' ]) && ( ' mysql_clear_password ' == $ row ['Name ' ])) {
22
- $ have_pam = true ;
21
+ if (isset ($ row ['Name ' ]) && in_array ( $ row ['Name ' ], array ( ' pam ' , ' authentication_pam ' , ' auth_pam_compat ' ) )) {
22
+ $ have_pam = $ row [ ' Name ' ] ;
23
23
break ;
24
24
}
25
25
}
@@ -28,12 +28,54 @@ $res->close();
28
28
if (!$ have_pam )
29
29
die ("SKIP Server PAM plugin not installed " );
30
30
31
+ if ($ have_pam == 'pam ' ) {
32
+ /* MariaDB - needs system variable pam_use_cleartext_plugin=ON to be set */
33
+ if (!$ res = mysqli_query ($ link , 'SHOW GLOBAL VARIABLES LIKE "pam_use_cleartext_plugin" ' ))
34
+ die (sprintf ("SKIP MariaDB probe of GLOBAL VARIABLES failed [%d] %s \n" ,
35
+ mysqli_errno ($ link ), mysqli_error ($ link )));
36
+ $ pam_use_cleartext_plugin = mysqli_fetch_row ($ res );
37
+ mysqli_free_result ($ res );
38
+ if (!$ pam_use_cleartext_plugin or $ pam_use_cleartext_plugin [1 ]!='ON ' )
39
+ die ("SKIP Server setting pam_use_cleartext_plugin!=ON " );
40
+
41
+ $ pam_service = file_get_contents ('/etc/pam.d/mysql ' );
42
+ } elseif ($ have_pam == 'authentication_pam ' ) {
43
+ /*
44
+ required MySQL syntax:
45
+ https://dev.mysql.com/doc/refman/8.0/en/pam-pluggable-authentication.html#pam-pluggable-authentication-usage
46
+ */
47
+ $ have_pam .= " AS 'mysql-unix' " ;
48
+ $ pam_service = file_get_contents ('/etc/pam.d/mysql-unix ' );
49
+ } else {
50
+ $ pam_service = file_get_contents ('/etc/pam.d/mysql ' );
51
+ }
52
+ $ auth = 0 ;
53
+ $ account = 0 ;
54
+ foreach (explode ("\n" , $ pam_service ) as $ line )
55
+ {
56
+ if (preg_match ('/^auth/ ' , $ line )) {
57
+ $ auth = 1 ;
58
+ } elseif (preg_match ('/^account/ ' , $ line )) {
59
+ $ account = 1 ;
60
+ }
61
+ }
62
+ if (!$ auth ) {
63
+ die ("SKIP pam service file missing 'auth' directive " );
64
+ }
65
+ if (!$ account ) {
66
+ die ("SKIP pam service file missing 'account' directive " );
67
+ }
68
+
69
+ if (!posix_getpwnam ('pamtest ' )) {
70
+ die ("SKIP no pamtest user " );
71
+ }
72
+ /* Password of user 'pamtest' should be set to 'pamtest' */
31
73
32
74
mysqli_query ($ link , 'DROP USER pamtest ' );
33
75
mysqli_query ($ link , 'DROP USER pamtest@localhost ' );
34
76
35
- if (!mysqli_query ($ link , ' CREATE USER pamtest@"%" IDENTIFIED WITH mysql_clear_password ' ) ||
36
- !mysqli_query ($ link , ' CREATE USER pamtest@" localhost" IDENTIFIED WITH mysql_clear_password ' )) {
77
+ if (!mysqli_query ($ link , " CREATE USER pamtest@'%' IDENTIFIED WITH $ have_pam " ) ||
78
+ !mysqli_query ($ link , " CREATE USER pamtest@' localhost' IDENTIFIED WITH $ have_pam " )) {
37
79
printf ("skip Cannot create second DB user [%d] %s " , mysqli_errno ($ link ), mysqli_error ($ link ));
38
80
mysqli_close ($ link );
39
81
die ("skip CREATE USER failed " );
@@ -87,6 +129,4 @@ max_execution_time=240
87
129
mysqli_query ($ link , 'DROP USER pamtest@localhost ' );
88
130
?>
89
131
--EXPECTF--
90
- Warning: mysqli_real_connect(): (28000/1045): Access denied for user %s
91
- [001] Cannot connect to the server using host=%s
92
132
done!
0 commit comments