pcntl_unshare_03.phpt 938 B

12345678910111213141516171819202122232425262728293031323334
  1. --TEST--
  2. pcntl_unshare() with CLONE_NEWNET
  3. --EXTENSIONS--
  4. pcntl
  5. posix
  6. --SKIPIF--
  7. <?php
  8. if (!function_exists("pcntl_unshare")) die("skip pcntl_unshare is not available");
  9. if (!defined("CLONE_NEWNET")) die("skip flag unavailable");
  10. if (posix_getuid() !== 0 &&
  11. (!defined("CLONE_NEWUSER") ||
  12. (pcntl_unshare(CLONE_NEWUSER) == false && pcntl_get_last_error() == PCNTL_EPERM))) {
  13. die("skip Insufficient privileges for CLONE_NEWUSER");
  14. }
  15. if (@pcntl_unshare(CLONE_NEWNET) == false && pcntl_get_last_error() == PCNTL_EPERM) {
  16. die("skip Insufficient privileges for CLONE_NEWPID");
  17. }
  18. if (getenv("SKIP_ONLINE_TESTS")) die("skip online test");
  19. if (getenv("SKIP_REPEAT")) die("skip cannot be repeated");
  20. ?>
  21. --FILE--
  22. <?php
  23. if(posix_getuid() !== 0) {
  24. pcntl_unshare(CLONE_NEWUSER);
  25. }
  26. var_dump(gethostbyname('php.net'));
  27. pcntl_unshare(CLONE_NEWNET);
  28. var_dump(gethostbyname('php.net'));
  29. ?>
  30. --EXPECTF--
  31. string(%d) %s
  32. string(7) "php.net"