mysqli_auth_pam.phpt 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. --TEST--
  2. PAM auth plugin
  3. --SKIPIF--
  4. <?php
  5. require_once('skipif.inc');
  6. require_once('skipifemb.inc');
  7. require_once('connect.inc');
  8. if (version_compare(PHP_VERSION, '5.3.99') >= 0) {
  9. die("SKIP Available as of PHP 5.3.99");
  10. }
  11. if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
  12. die(sprintf("SKIP Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
  13. $host, $user, $db, $port, $socket));
  14. }
  15. if ($link->server_version < 50500)
  16. die(sprintf("SKIP Needs MySQL 5.5 or newer, found MySQL %s\n", $link->server_info));
  17. if (!$res = $link->query("SHOW PLUGINS"))
  18. die(sprintf("SKIP [%d] %s\n", $link->errno, $link->error));
  19. $have_pam = false;
  20. while ($row = $res->fetch_assoc()) {
  21. if (isset($row['Name']) && ('mysql_clear_password' == $row['Name'])) {
  22. $have_pam = true;
  23. break;
  24. }
  25. }
  26. $res->close();
  27. if (!$have_pam)
  28. die("SKIP Server PAM plugin not installed");
  29. mysqli_query($link, 'DROP USER pamtest');
  30. mysqli_query($link, 'DROP USER pamtest@localhost');
  31. if (!mysqli_query($link, 'CREATE USER pamtest@"%" IDENTIFIED WITH mysql_clear_password') ||
  32. !mysqli_query($link, 'CREATE USER pamtest@"localhost" IDENTIFIED WITH mysql_clear_password')) {
  33. printf("skip Cannot create second DB user [%d] %s", mysqli_errno($link), mysqli_error($link));
  34. mysqli_close($link);
  35. die("skip CREATE USER failed");
  36. }
  37. if (!$link->query("CREATE TABLE test (id INT)") || !$link->query("INSERT INTO test(id) VALUES (1)"))
  38. die(sprintf("SKIP [%d] %s\n", $link->errno, $link->error));
  39. if (!mysqli_query($link, sprintf("GRANT SELECT ON TABLE %s.test TO pamtest@'%%'", $db)) ||
  40. !mysqli_query($link, sprintf("GRANT SELECT ON TABLE %s.test TO pamtest@'localhost'", $db))) {
  41. printf("skip Cannot grant SELECT to user [%d] %s", mysqli_errno($link), mysqli_error($link));
  42. mysqli_close($link);
  43. die("skip GRANT failed");
  44. }
  45. ?>
  46. --INI--
  47. max_execution_time=240
  48. --FILE--
  49. <?php
  50. require_once('connect.inc');
  51. require_once('table.inc');
  52. if (!$link = my_mysqli_connect($host, 'pamtest', 'pamtest', $db, $port, $socket)) {
  53. printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
  54. $host, $user, $db, $port, $socket);
  55. } else {
  56. if (!$res = $link->query("SELECT id FROM test WHERE id = 1"))
  57. printf("[002] [%d] %s\n", $link->errno, $link->error);
  58. if (!$row = mysqli_fetch_assoc($res)) {
  59. printf("[003] [%d] %s\n", $link->errno, $link->error);
  60. }
  61. if ($row['id'] != 1) {
  62. printf("[004] Expecting 1 got %s/'%s'", gettype($row['id']), $row['id']);
  63. }
  64. $res->close();
  65. $link->close();
  66. }
  67. print "done!";
  68. ?>
  69. --CLEAN--
  70. <?php
  71. require_once("clean_table.inc");
  72. mysqli_query($link, 'DROP USER pamtest');
  73. mysqli_query($link, 'DROP USER pamtest@localhost');
  74. ?>
  75. --EXPECTF--
  76. Warning: mysqli_real_connect(): (28000/1045): Access denied for user %s
  77. [001] Cannot connect to the server using host=%s
  78. done!