1--TEST-- 2recvmsg(): receive SCM_CREDENTIALS messages 3--EXTENSIONS-- 4sockets 5--SKIPIF-- 6<?php 7 8if (strtolower(substr(PHP_OS, 0, 3)) == 'win') { 9die('skip not for Microsoft Windows'); 10} 11if (strtolower(substr(PHP_OS, 0, 3)) == 'aix') { 12die('skip not for AIX'); 13} 14?> 15--FILE-- 16<?php 17include __DIR__."/mcast_helpers.php.inc"; 18$path = sys_get_temp_dir() . "/socket_cmsg_rights.sock"; 19 20@unlink($path); 21 22echo "creating send socket\n"; 23$sends1 = socket_create(AF_UNIX, SOCK_DGRAM, 0) or die("err"); 24var_dump($sends1); 25socket_set_nonblock($sends1) or die("Could not put in non-blocking mode"); 26 27echo "creating receive socket\n"; 28$s = socket_create(AF_UNIX, SOCK_DGRAM, 0) or die("err"); 29var_dump($s); 30$br = socket_bind($s, $path) or die("err"); 31var_dump($br); 32socket_set_nonblock($s) or die("Could not put in non-blocking mode"); 33 34$r = socket_sendmsg($sends1, [ 35 "name" => [ "path" => $path ], 36 "iov" => ["test ", "thing", "\n"], 37 "control" => [ 38 [ 39 "level" => SOL_SOCKET, 40 "type" => SCM_RIGHTS, 41 "data" => [$sends1, STDIN, STDOUT, STDERR], 42 ] 43 ] 44], 0); 45var_dump($r); 46checktimeout($s, 500); 47 48$data = [ 49 "name" => [], 50 "buffer_size" => 2000, 51 "controllen" => socket_cmsg_space(SOL_SOCKET, SCM_RIGHTS, 4) 52]; 53var_dump($data); 54if (!socket_recvmsg($s, $data, 0)) die("recvmsg"); 55 56if ($data["control"]) { 57 $control = $data["control"][0]; 58 if ($control["level"] == SOL_SOCKET && 59 $control["type"] == SCM_RIGHTS) { 60 foreach ($control["data"] as $resource) { 61 if (!is_resource($resource)) { 62 echo "FAIL RES\n"; 63 var_dump($data); 64 exit; 65 } 66 } 67 echo "OK"; 68 } else { 69 echo "FAIL RIGHTS\n"; 70 var_dump($data); 71 exit; 72 } 73} else { 74 echo "FAIL CONTROL\n"; 75 var_dump($data); 76} 77?> 78--CLEAN-- 79<?php 80$path = sys_get_temp_dir() . "/socket_cmsg_rights.sock"; 81@unlink($path); 82?> 83--EXPECTF-- 84creating send socket 85object(Socket)#%d (0) { 86} 87creating receive socket 88object(Socket)#%d (0) { 89} 90bool(true) 91int(11) 92array(3) { 93 ["name"]=> 94 array(0) { 95 } 96 ["buffer_size"]=> 97 int(2000) 98 ["controllen"]=> 99 int(%d) 100} 101OK 102