readdir_variation5.phpt 3.3 KB

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