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}
8require __DIR__ . '/../skipif_root.inc';
9?>
10--FILE--
11<?php
12/* Prototype  : string readdir([resource $dir_handle])
13 * Description: Read directory entry from dir_handle
14 * Source code: ext/standard/dir.c
15 */
16
17/*
18 * Open a directory with different premissions then try to read it
19 * to test behaviour of readdir()
20 */
21
22echo "*** Testing readdir() : usage variations ***\n";
23
24// create the temporary directory
25$dir_path = __DIR__ . "/readdir_variation5";
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$iterator = 1;
48foreach($permission_values as $perm) {
49	echo "\n-- Iteration $iterator --\n";
50
51	if (is_dir($dir_path)) {
52		chmod ($dir_path, 0777); // change dir permission to allow all operation
53		rmdir ($dir_path);
54	}
55	mkdir($dir_path);
56
57	// change the dir permisson to test dir on it
58	var_dump( chmod($dir_path, $perm) );
59	var_dump($dh = opendir($dir_path));
60
61	echo "-- Calling readdir() --\n";
62	var_dump(readdir($dh));
63
64	closedir($dh);
65	$iterator++;
66}
67?>
68===DONE===
69--CLEAN--
70<?php
71$dir_path = __DIR__ . "/readdir_variation5";
72rmdir($dir_path);
73?>
74--EXPECTF--
75*** Testing readdir() : usage variations ***
76
77-- Iteration 1 --
78bool(true)
79resource(%d) of type (stream)
80-- Calling readdir() --
81string(%d) "%s"
82
83-- Iteration 2 --
84bool(true)
85resource(%d) of type (stream)
86-- Calling readdir() --
87string(%d) "%s"
88
89-- Iteration 3 --
90bool(true)
91resource(%d) of type (stream)
92-- Calling readdir() --
93string(%d) "%s"
94
95-- Iteration 4 --
96bool(true)
97resource(%d) of type (stream)
98-- Calling readdir() --
99string(%d) "%s"
100
101-- Iteration 5 --
102bool(true)
103resource(%d) of type (stream)
104-- Calling readdir() --
105string(%d) "%s"
106
107-- Iteration 6 --
108bool(true)
109resource(%d) of type (stream)
110-- Calling readdir() --
111string(%d) "%s"
112
113-- Iteration 7 --
114bool(true)
115resource(%d) of type (stream)
116-- Calling readdir() --
117string(%d) "%s"
118
119-- Iteration 8 --
120bool(true)
121resource(%d) of type (stream)
122-- Calling readdir() --
123string(%d) "%s"
124
125-- Iteration 9 --
126bool(true)
127resource(%d) of type (stream)
128-- Calling readdir() --
129string(%d) "%s"
130
131-- Iteration 10 --
132bool(true)
133resource(%d) of type (stream)
134-- Calling readdir() --
135string(%d) "%s"
136===DONE===
137