1--TEST-- 2Test opendir() 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} 8require __DIR__ . '/../skipif_root.inc'; 9?> 10--FILE-- 11<?php 12/* 13 * remove the execute permission from the parent dir and test opendir() on child dir 14 * 1) remove write & execute permission from the 1st parent and test opendir() 15 * 2) remove execute permission from 2nd parent and test opendir() 16 */ 17 18echo "*** Testing opendir() : usage variations ***\n"; 19 20/* create the temporary directory : 21 * opendir_variation5 ( parent ) 22 * |-> sub_dir ( sub parent ) 23 * |-> child_dir ( child dir) 24 */ 25 26$parent_dir_path = __DIR__ . "/opendir_variation5"; 27mkdir($parent_dir_path); 28chmod($parent_dir_path, 0777); 29 30// create sub_dir 31$sub_dir_path = $parent_dir_path . "/sub_dir"; 32mkdir($sub_dir_path); 33chmod($sub_dir_path, 0777); 34 35//create sub_sub_dir 36$child_dir_path = $sub_dir_path."/child_dir"; 37mkdir($child_dir_path); 38 39// remove the write and execute permission from sub parent 40chmod($sub_dir_path, 0444); 41 42echo "\n-- After restricting 1st level parent directory --\n"; 43$dir_handle1 = opendir($child_dir_path); 44var_dump( $dir_handle1 ); 45 46// remove the execute permission from parent dir, allowing all permission for sub dir 47chmod($sub_dir_path, 0777); // all permission to sub dir 48chmod($parent_dir_path, 0666); // restricting parent directory 49 50echo "\n-- After restricting parent directory --\n"; 51$dir_handle2 = opendir($child_dir_path); // try to open, expected failure 52var_dump( $dir_handle2 ); // dump it 53 54if (is_resource($dir_handle1)) { 55 closedir($dir_handle1); 56} 57if (is_resource($dir_handle2)) { 58 closedir($dir_handle2); 59} 60?> 61--CLEAN-- 62<?php 63$parent_dir_path = __DIR__ . "/opendir_variation5"; 64$sub_dir_path = $parent_dir_path."/sub_dir"; 65$child_dir_path = $sub_dir_path."/child_dir"; 66 67// changing permissions for each temporary directory to delete them 68chmod($parent_dir_path, 0777); 69chmod($sub_dir_path, 0777); 70chmod($child_dir_path, 0777); 71 72rmdir($child_dir_path); 73rmdir($sub_dir_path); 74rmdir($parent_dir_path); 75?> 76--EXPECTF-- 77*** Testing opendir() : usage variations *** 78 79-- After restricting 1st level parent directory -- 80 81Warning: opendir(%s/opendir_variation5/sub_dir/child_dir): Failed to open directory: %s in %s on line %d 82bool(false) 83 84-- After restricting parent directory -- 85 86Warning: opendir(%s/opendir_variation5/sub_dir/child_dir): Failed to open directory: %s in %s on line %d 87bool(false) 88