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}
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/* Prototype  : mixed opendir(string $path[, resource $context])
21 * Description: Open a directory and return a dir_handle
22 * Source code: ext/standard/dir.c
23 */
24
25/*
26 * remove the execute permission from the parent dir and test opendir() on child dir
27 *   1) remove write & execute permission from the 1st parent and test opendir()
28 *   2) remove execute permission from 2nd parent and test opendir()
29 */
30
31echo "*** Testing opendir() : usage variations ***\n";
32
33/* create the temporary directory :
34 * opendir_variation5  ( parent )
35 *  |-> sub_dir    ( sub parent )
36 *      |-> child_dir  ( child dir)
37 */
38
39$parent_dir_path = dirname(__FILE__) . "/opendir_variation5";
40mkdir($parent_dir_path);
41chmod($parent_dir_path, 0777);
42
43// create sub_dir
44$sub_dir_path = $parent_dir_path . "/sub_dir";
45mkdir($sub_dir_path);
46chmod($sub_dir_path, 0777);
47
48//create sub_sub_dir
49$child_dir_path = $sub_dir_path."/child_dir";
50mkdir($child_dir_path);
51
52// remove the write and execute permisson from sub parent
53chmod($sub_dir_path, 0444);
54
55echo "\n-- After restricting 1st level parent directory --\n";
56$dir_handle1 = opendir($child_dir_path);
57var_dump( $dir_handle1 );
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
62
63echo "\n-- After restricting parent directory --\n";
64$dir_handle2 = opendir($child_dir_path); // try to open, expected failure
65var_dump( $dir_handle2 ); // dump it
66
67if (is_resource($dir_handle1)) {
68	closedir($dir_handle1);
69}
70if (is_resource($dir_handle2)) {
71	closedir($dir_handle2);
72}
73?>
74===DONE===
75--CLEAN--
76<?php
77$parent_dir_path = dirname(__FILE__) . "/opendir_variation5";
78$sub_dir_path = $parent_dir_path."/sub_dir";
79$child_dir_path = $sub_dir_path."/child_dir";
80
81// changing permissions for each temporary directory to delete them
82chmod($parent_dir_path, 0777);
83chmod($sub_dir_path, 0777);
84chmod($child_dir_path, 0777);
85
86rmdir($child_dir_path);
87rmdir($sub_dir_path);
88rmdir($parent_dir_path);
89?>
90--EXPECTF--
91*** Testing opendir() : usage variations ***
92
93-- After restricting 1st level parent directory --
94
95Warning: opendir(%s/opendir_variation5/sub_dir/child_dir): failed to open dir: %s in %s on line %d
96bool(false)
97
98-- After restricting parent directory --
99
100Warning: opendir(%s/opendir_variation5/sub_dir/child_dir): failed to open dir: %s in %s on line %d
101bool(false)
102===DONE===
103