1--TEST-- 2PAM: SHA-256 3--EXTENSIONS-- 4mysqli 5--SKIPIF-- 6<?php 7ob_start(); 8phpinfo(INFO_MODULES); 9$tmp = ob_get_contents(); 10ob_end_clean(); 11if (!stristr($tmp, "auth_plugin_sha256_password")) 12 die("skip SHA256 auth plugin not built-in to mysqlnd"); 13 14require_once 'connect.inc'; 15if (!$link = @my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) 16 die(sprintf("skip Can't connect to MySQL Server - [%d] %s", mysqli_connect_errno(), mysqli_connect_error())); 17 18if (mysqli_get_server_version($link) < 50606) 19 die("skip: SHA-256 requires MySQL 5.6.6+"); 20 21if (!($res = $link->query("SHOW PLUGINS"))) { 22 die(sprintf("skip [%d] %s\n", $link->errno, $link->error)); 23} 24 25$found = false; 26while ($row = $res->fetch_assoc()) { 27 if (($row['Name'] == 'sha256_password') && ($row['Status'] == 'ACTIVE')) { 28 $found = true; 29 break; 30 } 31} 32if (!$found) 33 die("skip SHA-256 server plugin unavailable"); 34 35if (!($res = $link->query("SHOW STATUS LIKE 'Rsa_public_key'"))) { 36 die(sprintf("skip [%d] %s\n", $link->errno, $link->error)); 37} 38 39if (!($row = $res->fetch_assoc())) { 40 die(sprintf("skip Failed to check RSA pub key, [%d] %s\n", $link->errno, $link->error)); 41} 42 43if (strlen($row['Value']) < 100) { 44 die(sprintf("skip Server misconfiguration? RSA pub key is suspicious, [%d] %s\n", $link->errno, $link->error)); 45} 46 47// Ignore errors because this variable exists only in MySQL 5.6 and 5.7 48$link->query("SET @@session.old_passwords=2"); 49 50$link->query('DROP USER shatest'); 51$link->query("DROP USER shatest@localhost"); 52 53 54if (!$link->query('CREATE USER shatest@"%" IDENTIFIED WITH sha256_password') || 55 !$link->query('CREATE USER shatest@"localhost" IDENTIFIED WITH sha256_password')) { 56 die(sprintf("skip CREATE USER failed [%d] %s", $link->errno, $link->error)); 57} 58 59if (!$link->query('SET PASSWORD FOR shatest@"%" = "shatest"') || 60 !$link->query('SET PASSWORD FOR shatest@"localhost" = "shatest"')) { 61 die(sprintf("skip SET PASSWORD failed [%d] %s", $link->errno, $link->error)); 62} 63 64if (!$link->query("DROP TABLE IF EXISTS test") || 65 !$link->query("CREATE TABLE test (id INT)") || 66 !$link->query("INSERT INTO test(id) VALUES (1), (2), (3)")) 67 die(sprintf("SKIP [%d] %s\n", $link->errno, $link->error)); 68 69 70if (!$link->query(sprintf("GRANT SELECT ON TABLE %s.test TO shatest@'%%'", $db)) || 71 !$link->query(sprintf("GRANT SELECT ON TABLE %s.test TO shatest@'localhost'", $db))) { 72 die(sprintf("skip Cannot grant SELECT to user [%d] %s", mysqli_errno($link), mysqli_error($link))); 73} 74 75$link->close(); 76echo "nocache"; 77?> 78--FILE-- 79<?php 80 require_once "connect.inc"; 81 82 if (!$link = my_mysqli_connect($host, 'shatest', 'shatest', $db, $port, $socket)) { 83 printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", 84 $host, "shatest", $db, $port, $socket); 85 } else { 86 87 if (!$res = $link->query("SELECT id FROM test WHERE id = 1")) 88 printf("[002] [%d] %s\n", $link->errno, $link->error); 89 90 if (!$row = mysqli_fetch_assoc($res)) { 91 printf("[003] [%d] %s\n", $link->errno, $link->error); 92 } 93 94 if ($row['id'] != 1) { 95 printf("[004] Expecting 1 got %s/'%s'", gettype($row['id']), $row['id']); 96 } 97 98 $res->close(); 99 $link->close(); 100 } 101 102 print "done!"; 103?> 104--CLEAN-- 105<?php 106 require_once "clean_table.inc"; 107 $link->query('DROP USER shatest'); 108 $link->query('DROP USER shatest@localhost'); 109?> 110--EXPECT-- 111done! 112