xref: /PHP-7.0/sapi/fpm/tests/021-uds-acl.phpt (revision eb02876e)
1--TEST--
2FPM: Test Unix Domain Socket with Posix ACL
3--SKIPIF--
4<?php
5include "skipif.inc";
6if (!(file_exists('/usr/bin/getfacl') && file_exists('/etc/passwd') && file_exists('/etc/group'))) die ("skip missing getfacl command");
7$cfg = <<<EOT
8[global]
9error_log = /dev/null
10[unconfined]
11listen = 127.0.0.1:9999
12listen.acl_users = nobody
13listen.acl_groups = nobody
14listen.mode = 0600
15pm = dynamic
16pm.max_children = 5
17pm.start_servers = 2
18pm.min_spare_servers = 1
19pm.max_spare_servers = 3
20EOT;
21if (test_fpm_conf($cfg, $msg) == false) { die("skip " .  $msg); }
22?>
23--FILE--
24<?php
25
26include "include.inc";
27
28$logfile = dirname(__FILE__).'/php-fpm.log.tmp';
29$socket  = dirname(__FILE__).'/php-fpm.sock';
30
31// Select 3 users and 2 groups known by system (avoid root)
32$users = $groups = [];
33$tmp = file('/etc/passwd');
34for ($i=1 ; $i<=3 ; $i++) {
35	$tab = explode(':', $tmp[$i]);
36	$users[] = $tab[0];
37}
38$users = implode(',', $users);
39$tmp = file('/etc/group');
40for ($i=1 ; $i<=2 ; $i++) {
41	$tab = explode(':', $tmp[$i]);
42	$groups[] = $tab[0];
43}
44$groups = implode(',', $groups);
45
46$cfg = <<<EOT
47[global]
48error_log = $logfile
49[unconfined]
50listen = $socket
51listen.acl_users = $users
52listen.acl_groups = $groups
53listen.mode = 0600
54ping.path = /ping
55ping.response = pong
56pm = dynamic
57pm.max_children = 5
58pm.start_servers = 2
59pm.min_spare_servers = 1
60pm.max_spare_servers = 3
61EOT;
62
63$fpm = run_fpm($cfg, $tail);
64if (is_resource($fpm)) {
65    fpm_display_log($tail, 2);
66    try {
67		var_dump(strpos(run_request('unix://'.$socket, -1), 'pong'));
68		echo "UDS ok\n";
69	} catch (Exception $e) {
70		echo "UDS error\n";
71	}
72	passthru("/usr/bin/getfacl -cp $socket");
73
74	proc_terminate($fpm);
75    fpm_display_log($tail, -1);
76    fclose($tail);
77    proc_close($fpm);
78}
79
80?>
81--EXPECTF--
82[%s] NOTICE: fpm is running, pid %d
83[%s] NOTICE: ready to handle connections
84int(%d)
85UDS ok
86user::rw-
87user:%s:rw-
88user:%s:rw-
89user:%s:rw-
90group::---
91group:%s:rw-
92group:%s:rw-
93mask::rw-
94other::---
95
96[%s] NOTICE: Terminating ...
97[%s] NOTICE: exiting, bye-bye!
98--CLEAN--
99<?php
100    $logfile = dirname(__FILE__).'/php-fpm.log.tmp';
101    @unlink($logfile);
102?>
103