1--TEST-- 2MySQL 5.6 EXPIRE PASSWORD protocol change 3--SKIPIF-- 4<?php 5require_once('skipif.inc'); 6require_once('skipifemb.inc'); 7require_once('connect.inc'); 8 9if ($IS_MYSQLND && !version_compare(PHP_VERSION, '5.4.12-dev', ">=")) { 10 die("SKIP Available in mysqlnd as of PHP 5.4.12-dev"); 11} 12 13if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) { 14 die(sprintf("SKIP Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", 15 $host, $user, $db, $port, $socket)); 16} 17 18if ($link->server_version < 50610) 19 die(sprintf("SKIP Needs MySQL 5.6.10 or newer, found MySQL %s\n", $link->server_info)); 20 21if (!$IS_MYSQLND && (mysqli_get_client_version() < 50610)) { 22 die(sprintf("SKIP Needs libmysql 5.6.10 or newer, found %s\n", mysqli_get_client_version())); 23} 24 25mysqli_query($link, 'DROP USER expiretest'); 26mysqli_query($link, 'DROP USER expiretest@localhost'); 27 28if (!mysqli_query($link, 'CREATE USER expiretest@"%"') || 29 !mysqli_query($link, 'CREATE USER expiretest@"localhost"')) { 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 35if (!mysqli_query($link, 'ALTER USER expiretest@"%" PASSWORD EXPIRE') || 36 !mysqli_query($link, 'ALTER USER expiretest@"localhost" PASSWORD EXPIRE')) { 37 printf("skip Cannot modify second DB user [%d] %s", mysqli_errno($link), mysqli_error($link)); 38 mysqli_close($link); 39 die("skip ALTER USER failed"); 40} 41 42if (!$link->query("DROP TABLE IF EXISTS test") || 43 !$link->query("CREATE TABLE test (id INT)") || !$link->query("INSERT INTO test(id) VALUES (1)")) 44 die(sprintf("SKIP [%d] %s\n", $link->errno, $link->error)); 45 46 47 48if (!mysqli_query($link, sprintf("GRANT SELECT ON TABLE %s.test TO expiretest@'%%'", $db)) || 49 !mysqli_query($link, sprintf("GRANT SELECT ON TABLE %s.test TO expiretest@'localhost'", $db))) { 50 printf("skip Cannot grant SELECT to user [%d] %s", mysqli_errno($link), mysqli_error($link)); 51 mysqli_close($link); 52 die("skip GRANT failed"); 53} 54?> 55--FILE-- 56<?php 57 require_once('connect.inc'); 58 require_once('table.inc'); 59 60 /* default */ 61 if (!$link = my_mysqli_connect($host, 'expiretest', "", $db, $port, $socket)) { 62 printf("[001] Cannot connect [%d] %s\n", 63 mysqli_connect_errno(), mysqli_connect_error()); 64 } else { 65 $link->query("SELECT id FROM test WHERE id = 1"); 66 printf("[002] Connect should fail, [%d] %s\n", $link->errno, $link->error); 67 } 68 69 /* explicitly requesting default */ 70 $link = mysqli_init(); 71 $link->options(MYSQLI_OPT_CAN_HANDLE_EXPIRED_PASSWORDS, 0); 72 if (!my_mysqli_real_connect($link, $host, 'expiretest', "", $db, $port, $socket)) { 73 printf("[003] Cannot connect [%d] %s\n", 74 mysqli_connect_errno(), mysqli_connect_error()); 75 } else { 76 $link->query("SELECT id FROM test WHERE id = 1"); 77 printf("[004] Connect should fail, [%d] %s\n", $link->errno, $link->error); 78 } 79 80 /* allow connect */ 81 $link = mysqli_init(); 82 $link->options(MYSQLI_OPT_CAN_HANDLE_EXPIRED_PASSWORDS, 1); 83 if (!my_mysqli_real_connect($link, $host, 'expiretest', "", $db, $port, $socket)) { 84 printf("[005] Cannot connect [%d] %s\n", 85 mysqli_connect_errno(), mysqli_connect_error()); 86 } else { 87 $link->query("SELECT id FROM test WHERE id = 1"); 88 printf("[006] Connect allowed, query fail, [%d] %s\n", $link->errno, $link->error); 89 $link->close(); 90 } 91 92 /* allow connect, fix pw */ 93 $link = mysqli_init(); 94 $link->options(MYSQLI_OPT_CAN_HANDLE_EXPIRED_PASSWORDS, 1); 95 if (!my_mysqli_real_connect($link, $host, 'expiretest', "", $db, $port, $socket)) { 96 printf("[007] Cannot connect [%d] %s\n", 97 mysqli_connect_errno(), mysqli_connect_error()); 98 } else { 99 $link->query("SET PASSWORD=PASSWORD('expiretest')"); 100 printf("[008] Connect allowed, pw set, [%d] %s\n", $link->errno, $link->error); 101 if ($res = $link->query("SELECT id FROM test WHERE id = 1")) 102 var_dump($res->fetch_assoc()); 103 $link->close(); 104 } 105 106 107 /* check login */ 108 if (!$link = my_mysqli_connect($host, 'expiretest', "expiretest", $db, $port, $socket)) { 109 printf("[001] Cannot connect [%d] %s\n", 110 mysqli_connect_errno(), mysqli_connect_error()); 111 } else { 112 $link->query("SELECT id FROM test WHERE id = 1"); 113 if ($res = $link->query("SELECT id FROM test WHERE id = 1")) 114 var_dump($res->fetch_assoc()); 115 $link->close(); 116 } 117 118 119 120 print "done!"; 121?> 122--CLEAN-- 123<?php 124 require_once("clean_table.inc"); 125 mysqli_query($link, 'DROP USER expiretest'); 126 mysqli_query($link, 'DROP USER expiretest@localhost'); 127?> 128--EXPECTF-- 129 130Warning: mysqli_real_connect(): (HY000/1820): %s in %s on line %d 131[001] Cannot connect [1820] %s 132 133Warning: mysqli_real_connect(): (HY000/1820): %s in %s on line %d 134[003] Cannot connect [1820] %s 135[006] Connect allowed, query fail, [1820] %s 136[008] Connect allowed, pw set, [0%A 137array(1) { 138 ["id"]=> 139 string(1) "1" 140} 141array(1) { 142 ["id"]=> 143 string(1) "1" 144} 145done! 146