mysqli_auth_pam.phpt 2.8 KB

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