Skip to content

Commit 2103e09

Browse files
committed
Merge branch 'PHP-8.2'
2 parents 4a6f31b + 94702c5 commit 2103e09

File tree

6 files changed

+80
-8
lines changed

6 files changed

+80
-8
lines changed

sapi/fpm/fpm/fpm_unix.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,11 @@ static int fpm_unix_conf_wp(struct fpm_worker_pool_s *wp) /* {{{ */
281281
if (wp->config->user && *wp->config->user) {
282282
if (strlen(wp->config->user) == strspn(wp->config->user, "0123456789")) {
283283
wp->set_uid = strtoul(wp->config->user, 0, 10);
284+
pwd = getpwuid(wp->set_uid);
285+
if (pwd) {
286+
wp->set_gid = pwd->pw_gid;
287+
wp->set_user = strdup(pwd->pw_name);
288+
}
284289
} else {
285290
struct passwd *pwd;
286291

@@ -404,7 +409,7 @@ int fpm_unix_init_child(struct fpm_worker_pool_s *wp) /* {{{ */
404409
}
405410
}
406411
if (wp->set_uid) {
407-
if (0 > initgroups(wp->config->user, wp->set_gid)) {
412+
if (0 > initgroups(wp->set_user ? wp->set_user : wp->config->user, wp->set_gid)) {
408413
zlog(ZLOG_SYSERROR, "[pool %s] failed to initgroups(%s, %d)", wp->config->name, wp->config->user, wp->set_gid);
409414
return -1;
410415
}

sapi/fpm/fpm/fpm_worker_pool.c

+3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ void fpm_worker_pool_free(struct fpm_worker_pool_s *wp) /* {{{ */
3434
if (wp->user) {
3535
free(wp->user);
3636
}
37+
if (wp->set_user) {
38+
free(wp->set_user);
39+
}
3740
if (wp->home) {
3841
free(wp->home);
3942
}

sapi/fpm/fpm/fpm_worker_pool.h

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ struct fpm_worker_pool_s {
2424
enum fpm_address_domain listen_address_domain;
2525
int listening_socket;
2626
int set_uid, set_gid; /* config uid and gid */
27+
char *set_user; /* config user name */
2728
int socket_uid, socket_gid, socket_mode;
2829

2930
/* runtime */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
--TEST--
2+
FPM: Process user setting ignored when FPM is not running as root
3+
--SKIPIF--
4+
<?php
5+
include "skipif.inc";
6+
FPM\Tester::skipIfNotRoot();
7+
FPM\Tester::skipIfUserDoesNotExist('www-data');
8+
?>
9+
--FILE--
10+
<?php
11+
12+
require_once "tester.inc";
13+
14+
$pw = posix_getpwnam('www-data');
15+
$uid = $pw['uid'];
16+
$gid = $pw['gid'];
17+
18+
$cfg = <<<EOT
19+
[global]
20+
error_log = {{FILE:LOG}}
21+
[unconfined]
22+
listen = {{ADDR}}
23+
user = $uid
24+
pm = dynamic
25+
pm.max_children = 5
26+
pm.start_servers = 1
27+
pm.min_spare_servers = 1
28+
pm.max_spare_servers = 3
29+
EOT;
30+
31+
$code = <<<EOT
32+
<?php
33+
echo posix_getgid();
34+
EOT;
35+
36+
$tester = new FPM\Tester($cfg, $code);
37+
$tester->start();
38+
$tester->expectLogStartNotices();
39+
$tester->request()->expectBody((string) $gid);
40+
$tester->terminate();
41+
$tester->expectLogTerminatingNotices();
42+
$tester->close();
43+
44+
?>
45+
Done
46+
--EXPECT--
47+
Done
48+
--CLEAN--
49+
<?php
50+
require_once "tester.inc";
51+
FPM\Tester::clean();
52+
?>

sapi/fpm/tests/response.inc

+5-5
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ class Response
7171
$body = implode("\n", $body);
7272
}
7373

74-
if (
75-
$this->checkIfValid() &&
76-
$this->checkDefaultHeaders($contentType) &&
77-
$body !== $this->rawBody
78-
) {
74+
if (!$this->checkIfValid()) {
75+
$this->error('Response is invalid');
76+
} elseif (!$this->checkDefaultHeaders($contentType)) {
77+
$this->error('Response default headers not found');
78+
} elseif ($body !== $this->rawBody) {
7979
if ($multiLine) {
8080
$this->error(
8181
"==> The expected body:\n$body\n" .

sapi/fpm/tests/tester.inc

+13-2
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ class Tester
304304
*/
305305
static public function skipIfNotRoot()
306306
{
307-
if (getmyuid() != 0) {
307+
if (exec('whoami') !== 'root') {
308308
die('skip not running as root');
309309
}
310310
}
@@ -314,7 +314,7 @@ class Tester
314314
*/
315315
static public function skipIfRoot()
316316
{
317-
if (getmyuid() == 0) {
317+
if (exec('whoami') === 'root') {
318318
die('skip running as root');
319319
}
320320
}
@@ -329,6 +329,17 @@ class Tester
329329
}
330330
}
331331

332+
/**
333+
* Skip if posix extension not loaded.
334+
*/
335+
static public function skipIfUserDoesNotExist($userName)
336+
{
337+
self::skipIfPosixNotLoaded();
338+
if (posix_getpwnam($userName) === false) {
339+
die("skip user $userName does not exist");
340+
}
341+
}
342+
332343
/**
333344
* Tester constructor.
334345
*

0 commit comments

Comments
 (0)