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