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}
14if (!defined('SO_PASSCRED')) {
15die('skip SO_PASSCRED is not defined');
16}
17?>
18--FILE--
19<?php
20include __DIR__."/mcast_helpers.php.inc";
21$path = sys_get_temp_dir() . "/socket_cmsg_credentials.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");
36socket_set_option($s, SOL_SOCKET, SO_PASSCRED, 1) or die("could not set SO_PASSCRED");
37
38
39//$r = socket_sendmsg($sends1, [
40//  "iov" => ["test ", "thing", "\n"],
41//], 0);
42$r = socket_sendto($sends1, $msg = "dread", strlen($msg), 0, $path);
43var_dump($r);
44checktimeout($s, 500);
45
46$data = [
47    "name" => [],
48    "buffer_size" => 2000,
49    "controllen" => socket_cmsg_space(SOL_SOCKET, SCM_CREDENTIALS)
50];
51if (!socket_recvmsg($s, $data, 0)) die("recvmsg");
52print_r($data);
53
54$pid = getmypid();
55var_dump($data['control'][0]['data']['pid'] === $pid);
56?>
57--CLEAN--
58<?php
59$path = sys_get_temp_dir() . "/socket_cmsg_credentials.sock";
60@unlink($path);
61?>
62--EXPECTF--
63creating send socket
64object(Socket)#%d (0) {
65}
66creating receive socket
67object(Socket)#%d (0) {
68}
69bool(true)
70int(5)
71Array
72(
73    [name] =>
74    [control] => Array
75        (
76            [0] => Array
77                (
78                    [level] => %d
79                    [type] => %d
80                    [data] => Array
81                        (
82                            [pid] => %d
83                            [uid] => %d
84                            [gid] => %d
85                        )
86
87                )
88
89        )
90
91    [iov] => Array
92        (
93            [0] => dread
94        )
95
96    [flags] => 0
97)
98bool(true)
99