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