1--TEST-- 2Test readdir() function : usage variations - different permissions 3--SKIPIF-- 4<?php 5if( substr(PHP_OS, 0, 3) == 'WIN') { 6 die('skip Not for Windows'); 7} 8// Skip if being run by root (files are always readable, writeable and executable) 9$filename = dirname(__FILE__)."/readdir_root_check.tmp"; 10$fp = fopen($filename, 'w'); 11fclose($fp); 12if(fileowner($filename) == 0) { 13 unlink ($filename); 14 die('skip...cannot be run as root\n'); 15} 16unlink($filename); 17?> 18--FILE-- 19<?php 20/* Prototype : string readdir([resource $dir_handle]) 21 * Description: Read directory entry from dir_handle 22 * Source code: ext/standard/dir.c 23 */ 24 25/* 26 * Open a directory with different premissions then try to read it 27 * to test behaviour of readdir() 28 */ 29 30echo "*** Testing readdir() : usage variations ***\n"; 31 32// create the temporary directory 33$dir_path = dirname(__FILE__) . "/readdir_variation5"; 34mkdir($dir_path); 35 36/* different values for directory permissions */ 37$permission_values = array( 38/*1*/ 0477, // owner has read only, other and group has rwx 39 0677, // owner has rw only, other and group has rwx 40 41/*3*/ 0444, // all have read only 42 0666, // all have rw only 43 44/*5*/ 0400, // owner has read only, group and others have no permission 45 0600, // owner has rw only, group and others have no permission 46 47/*7*/ 0470, // owner has read only, group has rwx & others have no permission 48 0407, // owner has read only, other has rwx & group has no permission 49 50/*9*/ 0670, // owner has rw only, group has rwx & others have no permission 51/*10*/ 0607 // owner has rw only, group has no permission and others have rwx 52); 53 54// Open directory with different permission values, read and close, expected: none of them to succeed. 55$iterator = 1; 56foreach($permission_values as $perm) { 57 echo "\n-- Iteration $iterator --\n"; 58 59 if (is_dir($dir_path)) { 60 chmod ($dir_path, 0777); // change dir permission to allow all operation 61 rmdir ($dir_path); 62 } 63 mkdir($dir_path); 64 65 // change the dir permisson to test dir on it 66 var_dump( chmod($dir_path, $perm) ); 67 var_dump($dh = opendir($dir_path)); 68 69 echo "-- Calling readdir() --\n"; 70 var_dump(readdir($dh)); 71 72 closedir($dh); 73 $iterator++; 74} 75?> 76===DONE=== 77--CLEAN-- 78<?php 79$dir_path = dirname(__FILE__) . "/readdir_variation5"; 80rmdir($dir_path); 81?> 82--EXPECTF-- 83*** Testing readdir() : usage variations *** 84 85-- Iteration 1 -- 86bool(true) 87resource(%d) of type (stream) 88-- Calling readdir() -- 89string(%d) "%s" 90 91-- Iteration 2 -- 92bool(true) 93resource(%d) of type (stream) 94-- Calling readdir() -- 95string(%d) "%s" 96 97-- Iteration 3 -- 98bool(true) 99resource(%d) of type (stream) 100-- Calling readdir() -- 101string(%d) "%s" 102 103-- Iteration 4 -- 104bool(true) 105resource(%d) of type (stream) 106-- Calling readdir() -- 107string(%d) "%s" 108 109-- Iteration 5 -- 110bool(true) 111resource(%d) of type (stream) 112-- Calling readdir() -- 113string(%d) "%s" 114 115-- Iteration 6 -- 116bool(true) 117resource(%d) of type (stream) 118-- Calling readdir() -- 119string(%d) "%s" 120 121-- Iteration 7 -- 122bool(true) 123resource(%d) of type (stream) 124-- Calling readdir() -- 125string(%d) "%s" 126 127-- Iteration 8 -- 128bool(true) 129resource(%d) of type (stream) 130-- Calling readdir() -- 131string(%d) "%s" 132 133-- Iteration 9 -- 134bool(true) 135resource(%d) of type (stream) 136-- Calling readdir() -- 137string(%d) "%s" 138 139-- Iteration 10 -- 140bool(true) 141resource(%d) of type (stream) 142-- Calling readdir() -- 143string(%d) "%s" 144===DONE=== 145