posix_mkfifo_safemode.phpt 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. --TEST--
  2. Test posix_mkfifo() with safe_mode.
  3. --DESCRIPTION--
  4. The test attempts to enable safe_mode, catches all the relevant E_WARNING's and tries to create a fifo in /tmp.
  5. The first attempt (writing to /tmp) should effectively fail because /tmp is owned by root.
  6. The second attempt (writing to a local created file) works.
  7. --CREDITS--
  8. Till Klampaeckel, till@php.net
  9. TestFest Berlin 2009
  10. --SKIPIF--
  11. <?php
  12. if (!extension_loaded('posix')) {
  13. die('SKIP The posix extension is not loaded.');
  14. }
  15. if (posix_geteuid() == 0) {
  16. die('SKIP Cannot run test as root.');
  17. }
  18. if (PHP_VERSION_ID < 503099) {
  19. die('SKIP Safe mode is no longer available.');
  20. }
  21. ?>
  22. --FILE--
  23. <?php
  24. var_dump(posix_mkfifo('/tmp/foobar', 0644));
  25. $dir = dirname(__FILE__) . '/foo';
  26. mkdir ($dir);
  27. var_dump(posix_mkfifo($dir . '/bar', 0644));
  28. ?>
  29. ===DONE===
  30. --CLEAN--
  31. <?php
  32. $dir = dirname(__FILE__) . '/foo';
  33. unlink($dir . '/bar');
  34. rmdir($dir);
  35. ?>
  36. --EXPECTF--
  37. Deprecated: Directive 'safe_mode' is deprecated in PHP 5.3 and greater in %s on line %d
  38. Warning: posix_mkfifo(): SAFE MODE Restriction in effect. The script whose uid is %d is not allowed to access /tmp owned by uid %d in %s on line %d
  39. bool(false)
  40. bool(true)
  41. ===DONE===