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