Annotation of embedaddon/php/ext/standard/tests/dir/dir_variation7.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test dir() function : usage variations - directories with restricted permissions
3: --SKIPIF--
4: <?php
5: if( 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');
11: fclose($fp);
12: if(fileowner($filename) == 0) {
13: unlink ($filename);
14: die('skip...cannot be run as root\n');
15: }
16: unlink($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:
32: echo "*** 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);
42: chmod($parent_dir_path, 0777);
43:
44: // create sub_dir
45: $sub_dir_path = $parent_dir_path."/sub_dir";
46: @mkdir($sub_dir_path);
47: chmod($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
54: chmod($sub_dir_path, 0444);
55: echo "-- After restricting 1st level parent directory --\n";
56: $d = dir($child_dir_path); // try to open, expected failure
57: var_dump( $d ); // dump it
58:
59: // remove the execute permisson from parent dir, allowing all permission for sub dir
60: chmod($sub_dir_path, 0777); // all permisson to sub dir
61: chmod($parent_dir_path, 0666); // restricting parent directory
62: echo "-- After restricting parent directory --\n";
63: $d = dir($child_dir_path); // try to open, expected failure
64: var_dump( $d ); // dump it
65:
66: echo "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
76: chmod($parent_dir_path, 0777);
77: chmod($sub_dir_path, 0777);
78: chmod($child_dir_path, 0777);
79:
80: rmdir($child_dir_path);
81: rmdir($sub_dir_path);
82: rmdir($parent_dir_path);
83: ?>
84: --EXPECTF--
85: *** Testing dir() : remove execute permission from the parent dir ***
86: -- After restricting 1st level parent directory --
87:
88: Warning: dir(%s/dir_variation7/sub_dir/child_dir): failed to open dir: %s in %s on line %d
89: bool(false)
90: -- After restricting parent directory --
91:
92: Warning: dir(%s/dir_variation7/sub_dir/child_dir): failed to open dir: %s in %s on line %d
93: bool(false)
94: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>