1--TEST-- 2Test dir() function : usage variations - directories with restricted 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__)."/dir_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/* 21 * Prototype : object dir(string $directory[, resource $context]) 22 * Description: Directory class with properties, handle and class and methods read, rewind and close 23 * Source code: ext/standard/dir.c 24 */ 25 26/* 27 * remove the execute permission from the parent dir and test dir() on child dir 28 * 1) remove write & execute permission from the 1st parent and test dir() 29 * 2) remove execute permission from 2nd parent and test dir() 30 */ 31 32echo "*** Testing dir() : remove execute permission from the parent dir ***\n"; 33 34/* create the temporary directory : 35 dir_variation7 ( parent ) 36 |-> sub_dir ( sub parent ) 37 |-> child_dir ( child dir) 38*/ 39$file_path = dirname(__FILE__); 40$parent_dir_path = $file_path."/dir_variation7"; 41@mkdir($parent_dir_path); 42chmod($parent_dir_path, 0777); 43 44// create sub_dir 45$sub_dir_path = $parent_dir_path."/sub_dir"; 46@mkdir($sub_dir_path); 47chmod($sub_dir_path, 0777); 48 49//create sub_sub_dir 50$child_dir_path = $sub_dir_path."/child_dir"; 51@mkdir($child_dir_path); 52 53// remove the write and execute permisson from sub parent 54chmod($sub_dir_path, 0444); 55echo "-- After restricting 1st level parent directory --\n"; 56$d = dir($child_dir_path); // try to open, expected failure 57var_dump( $d ); // dump it 58 59// remove the execute permisson from parent dir, allowing all permission for sub dir 60chmod($sub_dir_path, 0777); // all permisson to sub dir 61chmod($parent_dir_path, 0666); // restricting parent directory 62echo "-- After restricting parent directory --\n"; 63$d = dir($child_dir_path); // try to open, expected failure 64var_dump( $d ); // dump it 65 66echo "Done"; 67?> 68--CLEAN-- 69<?php 70$file_path = dirname(__FILE__); 71$parent_dir_path = $file_path."/dir_variation7"; 72$sub_dir_path = $parent_dir_path."/sub_dir"; 73$child_dir_path = $sub_dir_path."/child_dir"; 74 75// changing permissions for each temporary directory to delete them 76chmod($parent_dir_path, 0777); 77chmod($sub_dir_path, 0777); 78chmod($child_dir_path, 0777); 79 80rmdir($child_dir_path); 81rmdir($sub_dir_path); 82rmdir($parent_dir_path); 83?> 84--EXPECTF-- 85*** Testing dir() : remove execute permission from the parent dir *** 86-- After restricting 1st level parent directory -- 87 88Warning: dir(%s/dir_variation7/sub_dir/child_dir): failed to open dir: %s in %s on line %d 89bool(false) 90-- After restricting parent directory -- 91 92Warning: dir(%s/dir_variation7/sub_dir/child_dir): failed to open dir: %s in %s on line %d 93bool(false) 94Done