|
|
b74969 |
From eb6941e902e02332019d8cba2ed7a9100fd914b3 Mon Sep 17 00:00:00 2001
|
|
|
b74969 |
From: Paul Annesley <paul@annesley.cc>
|
|
|
b74969 |
Date: Wed, 19 Feb 2014 11:48:40 -0800
|
|
|
b74969 |
Subject: [PATCH] add clear_env option to FPM config
|
|
|
b74969 |
|
|
|
b74969 |
This makes it possible to leave the envoronment as is on startup and
|
|
|
b74969 |
pass all the variables to the workers.
|
|
|
b74969 |
The default value of clear_env is "yes", preserving previous behaviour.
|
|
|
b74969 |
Patch by Paul Annesley.
|
|
|
b74969 |
---
|
|
|
b74969 |
sapi/fpm/fpm/fpm_conf.c | 3 +++
|
|
|
b74969 |
sapi/fpm/fpm/fpm_conf.h | 1 +
|
|
|
b74969 |
sapi/fpm/fpm/fpm_env.c | 4 +++-
|
|
|
b74969 |
sapi/fpm/php-fpm.conf.in | 9 +++++++++
|
|
|
b74969 |
4 files changed, 16 insertions(+), 1 deletion(-)
|
|
|
b74969 |
|
|
|
b74969 |
diff --git a/sapi/fpm/fpm/fpm_conf.c b/sapi/fpm/fpm/fpm_conf.c
|
|
|
b74969 |
index cd5fc34d0f2d..688c6402505e 100644
|
|
|
b74969 |
--- a/sapi/fpm/fpm/fpm_conf.c
|
|
|
b74969 |
+++ b/sapi/fpm/fpm/fpm_conf.c
|
|
|
b74969 |
@@ -148,6 +148,7 @@ static struct ini_value_parser_s ini_fpm_pool_options[] = {
|
|
|
b74969 |
{ "chroot", &fpm_conf_set_string, WPO(chroot) },
|
|
|
b74969 |
{ "chdir", &fpm_conf_set_string, WPO(chdir) },
|
|
|
b74969 |
{ "catch_workers_output", &fpm_conf_set_boolean, WPO(catch_workers_output) },
|
|
|
b74969 |
+ { "clear_env", &fpm_conf_set_boolean, WPO(clear_env) },
|
|
|
b74969 |
{ "security.limit_extensions", &fpm_conf_set_string, WPO(security_limit_extensions) },
|
|
|
b74969 |
{ 0, 0, 0 }
|
|
|
b74969 |
};
|
|
|
b74969 |
@@ -603,6 +604,7 @@ static void *fpm_worker_pool_config_alloc() /* {{{ */
|
|
|
b74969 |
wp->config->listen_backlog = FPM_BACKLOG_DEFAULT;
|
|
|
b74969 |
wp->config->pm_process_idle_timeout = 10; /* 10s by default */
|
|
|
b74969 |
wp->config->process_priority = 64; /* 64 means unset */
|
|
|
b74969 |
+ wp->config->clear_env = 1;
|
|
|
b74969 |
|
|
|
b74969 |
if (!fpm_worker_all_pools) {
|
|
|
b74969 |
fpm_worker_all_pools = wp;
|
|
|
b74969 |
@@ -1600,6 +1602,7 @@ static void fpm_conf_dump() /* {{{ */
|
|
|
b74969 |
zlog(ZLOG_NOTICE, "\tchroot = %s", STR2STR(wp->config->chroot));
|
|
|
b74969 |
zlog(ZLOG_NOTICE, "\tchdir = %s", STR2STR(wp->config->chdir));
|
|
|
b74969 |
zlog(ZLOG_NOTICE, "\tcatch_workers_output = %s", BOOL2STR(wp->config->catch_workers_output));
|
|
|
b74969 |
+ zlog(ZLOG_NOTICE, "\tclear_env = %s", BOOL2STR(wp->config->clear_env));
|
|
|
b74969 |
zlog(ZLOG_NOTICE, "\tsecurity.limit_extensions = %s", wp->config->security_limit_extensions);
|
|
|
b74969 |
|
|
|
b74969 |
for (kv = wp->config->env; kv; kv = kv->next) {
|
|
|
b74969 |
diff --git a/sapi/fpm/fpm/fpm_conf.h b/sapi/fpm/fpm/fpm_conf.h
|
|
|
b74969 |
index efd65dc6d9d7..19bd7ff1f806 100644
|
|
|
b74969 |
--- a/sapi/fpm/fpm/fpm_conf.h
|
|
|
b74969 |
+++ b/sapi/fpm/fpm/fpm_conf.h
|
|
|
b74969 |
@@ -83,6 +83,7 @@ struct fpm_worker_pool_config_s {
|
|
|
b74969 |
char *chroot;
|
|
|
b74969 |
char *chdir;
|
|
|
b74969 |
int catch_workers_output;
|
|
|
b74969 |
+ int clear_env;
|
|
|
b74969 |
char *security_limit_extensions;
|
|
|
b74969 |
struct key_value_s *env;
|
|
|
b74969 |
struct key_value_s *php_admin_values;
|
|
|
b74969 |
diff --git a/sapi/fpm/fpm/fpm_env.c b/sapi/fpm/fpm/fpm_env.c
|
|
|
b74969 |
index 6b64fedfec47..2ff0bdc0e4bc 100644
|
|
|
b74969 |
--- a/sapi/fpm/fpm/fpm_env.c
|
|
|
b74969 |
+++ b/sapi/fpm/fpm/fpm_env.c
|
|
|
b74969 |
@@ -143,7 +143,9 @@ int fpm_env_init_child(struct fpm_worker_pool_s *wp) /* {{{ */
|
|
|
b74969 |
fpm_env_setproctitle(title);
|
|
|
b74969 |
efree(title);
|
|
|
b74969 |
|
|
|
b74969 |
- clearenv();
|
|
|
b74969 |
+ if (wp->config->clear_env) {
|
|
|
b74969 |
+ clearenv();
|
|
|
b74969 |
+ }
|
|
|
b74969 |
|
|
|
b74969 |
for (kv = wp->config->env; kv; kv = kv->next) {
|
|
|
b74969 |
setenv(kv->key, kv->value, 1);
|
|
|
b74969 |
diff --git a/sapi/fpm/php-fpm.conf.in b/sapi/fpm/php-fpm.conf.in
|
|
|
b74969 |
index af4f2fa325a3..6ce9b6325636 100644
|
|
|
b74969 |
--- a/sapi/fpm/php-fpm.conf.in
|
|
|
b74969 |
+++ b/sapi/fpm/php-fpm.conf.in
|
|
|
b74969 |
@@ -475,6 +475,15 @@ pm.max_spare_servers = 3
|
|
|
b74969 |
; Default Value: no
|
|
|
b74969 |
;catch_workers_output = yes
|
|
|
b74969 |
|
|
|
b74969 |
+; Clear environment in FPM workers
|
|
|
b74969 |
+; Prevents arbitrary environment variables from reaching FPM worker processes
|
|
|
b74969 |
+; by clearing the environment in workers before env vars specified in this
|
|
|
b74969 |
+; pool configuration are added.
|
|
|
b74969 |
+; Setting to "no" will make all environment variables available to PHP code
|
|
|
b74969 |
+; via getenv(), $_ENV and $_SERVER.
|
|
|
b74969 |
+; Default Value: yes
|
|
|
b74969 |
+;clear_env = no
|
|
|
b74969 |
+
|
|
|
b74969 |
; Limits the extensions of the main script FPM will allow to parse. This can
|
|
|
b74969 |
; prevent configuration mistakes on the web server side. You should only limit
|
|
|
b74969 |
; FPM to .php extensions to prevent malicious users to use other extensions to
|