1--TEST--
2Test opendir() function : usage variations - different directory 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/* Prototype  : mixed opendir(string $path[, resource $context])
13 * Description: Open a directory and return a dir_handle
14 * Source code: ext/standard/dir.c
15 */
16
17/*
18 * Open a directory using opendir() with different directory permissions
19 */
20
21echo "*** Testing opendir() : usage variations ***\n";
22
23// create the temporary directory
24$file_path = __DIR__;
25$dir_path = $file_path . "/opendir_variation7";
26mkdir($dir_path);
27
28/* different values for directory permissions */
29$permission_values = array(
30/*1*/  0477,  // owner has read only, other and group has rwx
31       0677,  // owner has rw only, other and group has rwx
32
33/*3*/  0444,  // all have read only
34       0666,  // all have rw only
35
36/*5*/  0400,  // owner has read only, group and others have no permission
37       0600,   // owner has rw only, group and others have no permission
38
39/*7*/  0470,  // owner has read only, group has rwx & others have no permission
40       0407,  // owner has read only, other has rwx & group has no permission
41
42/*9*/  0670,  // owner has rw only, group has rwx & others have no permission
43/*10*/ 0607   // owner has rw only, group has no permission and others have rwx
44);
45
46// Open directory with different permission values, read and close, expected: none of them to succeed.
47
48$iterator = 1;
49foreach ($permission_values as $perm) {
50
51	echo "\n-- Iteration $iterator --\n";
52	// try to remove the dir if exists  & create
53	if (is_dir($dir_path)){
54		chmod ($dir_path, 0777); // change dir permission to allow all operation
55		rmdir ($dir_path);
56	}
57	mkdir($dir_path);
58
59	// change the dir permisson to test dir on it
60	var_dump( chmod($dir_path, $perm) );
61
62	var_dump($dh = opendir($dir_path));
63
64	if (is_resource($dh)) {
65		closedir($dh);
66	}
67	$iterator++;
68}
69?>
70===DONE===
71--CLEAN--
72<?php
73// deleting temporary directory
74$dir_path = __DIR__ . "/opendir_variation7";
75rmdir($dir_path);
76?>
77--EXPECTF--
78*** Testing opendir() : usage variations ***
79
80-- Iteration 1 --
81bool(true)
82resource(%d) of type (stream)
83
84-- Iteration 2 --
85bool(true)
86resource(%d) of type (stream)
87
88-- Iteration 3 --
89bool(true)
90resource(%d) of type (stream)
91
92-- Iteration 4 --
93bool(true)
94resource(%d) of type (stream)
95
96-- Iteration 5 --
97bool(true)
98resource(%d) of type (stream)
99
100-- Iteration 6 --
101bool(true)
102resource(%d) of type (stream)
103
104-- Iteration 7 --
105bool(true)
106resource(%d) of type (stream)
107
108-- Iteration 8 --
109bool(true)
110resource(%d) of type (stream)
111
112-- Iteration 9 --
113bool(true)
114resource(%d) of type (stream)
115
116-- Iteration 10 --
117bool(true)
118resource(%d) of type (stream)
119===DONE===
120