Download | Plain Text | No Line Numbers


  1. diff -Naur a/main/php_ini.c b/main/php_ini.c
  2. --- a/main/php_ini.c 2020-07-21 10:49:31.000000000 +0200
  3. +++ b/main/php_ini.c 2020-07-24 12:28:52.695502405 +0200
  4. @@ -805,6 +805,57 @@
  5. }
  6. /* }}} */
  7.  
  8. +
  9. +/* {{{ php_parse_extra_ini
  10. + */
  11. +PHPAPI int php_parse_extra_ini(const char *ini_file)
  12. +{
  13. + if (!sapi_module.php_ini_ignore && ini_file) {
  14. + zend_stat_t sb;
  15. + zend_file_handle fh;
  16. +
  17. + if (VCWD_STAT(ini_file, &sb) == 0) {
  18. + if (S_ISREG(sb.st_mode)) {
  19. + memset(&fh, 0, sizeof(fh));
  20. + if ((fh.handle.fp = VCWD_FOPEN(ini_file, "r"))) {
  21. + fh.filename = ini_file;
  22. + fh.type = ZEND_HANDLE_FP;
  23. +
  24. + /* Reset active ini section */
  25. + RESET_ACTIVE_INI_HASH();
  26. +
  27. + /* add a fake-host section so our settings will be changed to PHP_INI_SYSTEM during merge */
  28. + zval fakehost;
  29. + ZVAL_NEW_STR(&fakehost, zend_string_init(ZEND_STRL("HOST=\%fake\%"), 0));
  30. + php_ini_parser_cb(&fakehost, NULL, NULL, ZEND_INI_PARSER_SECTION, &configuration_hash);
  31. +
  32. + if (zend_parse_ini_file(&fh, 1, ZEND_INI_SCANNER_NORMAL, (zend_ini_parser_cb_t) php_ini_parser_cb, &configuration_hash) == SUCCESS) {
  33. + /* add the file to the list of ini files read */
  34. + int add_len = (int)strlen(ini_file) + 2;
  35. +
  36. + int php_ini_scanned_files_len = (php_ini_scanned_files) ? (int)strlen(php_ini_scanned_files) + 1 : 0;
  37. + php_ini_scanned_files = (char *) realloc(php_ini_scanned_files, php_ini_scanned_files_len + add_len + 1);
  38. + if (!php_ini_scanned_files_len) {
  39. + *php_ini_scanned_files = '\0';
  40. + }
  41. + add_len += php_ini_scanned_files_len;
  42. + if (php_ini_scanned_files_len) {
  43. + php_ini_scanned_files[php_ini_scanned_files_len - 2] = '\0';
  44. + strlcat(php_ini_scanned_files, ",\n", add_len);
  45. + }
  46. + strlcat(php_ini_scanned_files, ini_file, add_len);
  47. + strlcat(php_ini_scanned_files, "\n", add_len);
  48. + return SUCCESS;
  49. + }
  50. + }
  51. + }
  52. + }
  53. + }
  54. + return FAILURE;
  55. +}
  56. +/* }}} */
  57. +
  58. +
  59. /* {{{ php_ini_activate_config */
  60. PHPAPI void php_ini_activate_config(HashTable *source_hash, int modify_type, int stage)
  61. {
  62. diff -Naur a/main/php_ini.h b/main/php_ini.h
  63. --- a/main/php_ini.h 2020-07-21 10:49:31.000000000 +0200
  64. +++ b/main/php_ini.h 2020-07-24 12:26:47.102488994 +0200
  65. @@ -30,6 +30,7 @@
  66. PHPAPI int cfg_get_double(const char *varname, double *result);
  67. PHPAPI int cfg_get_string(const char *varname, char **result);
  68. PHPAPI int php_parse_user_ini_file(const char *dirname, const char *ini_filename, HashTable *target_hash);
  69. +PHPAPI int php_parse_extra_ini(const char *ini_file);
  70. PHPAPI void php_ini_activate_config(HashTable *source_hash, int modify_type, int stage);
  71. PHPAPI int php_ini_has_per_dir_config(void);
  72. PHPAPI int php_ini_has_per_host_config(void);
  73. diff -Naur a/sapi/cgi/cgi_main.c b/sapi/cgi/cgi_main.c
  74. --- a/sapi/cgi/cgi_main.c 2020-07-21 10:49:31.000000000 +0200
  75. +++ b/sapi/cgi/cgi_main.c 2020-07-24 12:26:10.064773335 +0200
  76. @@ -866,6 +866,9 @@
  77. if (php_ini_has_per_host_config()) {
  78. char *server_name;
  79.  
  80. + /* activate our fake host entries. lowercase string required! */
  81. + php_ini_activate_per_host_config(ZEND_STRL("\%fake\%"));
  82. +
  83. /* Activate per-host-system-configuration defined in php.ini and stored into configuration_hash during startup */
  84. if (fcgi_is_fastcgi()) {
  85. fcgi_request *request = (fcgi_request*) SG(server_context);
  86. @@ -969,6 +972,7 @@
  87. if (php_module_startup(sapi_module, &cgi_module_entry, 1) == FAILURE) {
  88. return FAILURE;
  89. }
  90. + php_parse_extra_ini(getenv("PHP_INI_EXTRA"));
  91. return SUCCESS;
  92. }
  93.  
  94. diff -Naur a/sapi/cli/php_cli.c b/sapi/cli/php_cli.c
  95. --- a/sapi/cli/php_cli.c 2020-07-21 10:49:31.000000000 +0200
  96. +++ b/sapi/cli/php_cli.c 2020-07-24 12:26:10.065773327 +0200
  97. @@ -413,6 +413,7 @@
  98. if (php_module_startup(sapi_module, NULL, 0)==FAILURE) {
  99. return FAILURE;
  100. }
  101. + php_parse_extra_ini(getenv("PHP_INI_EXTRA"));
  102. return SUCCESS;
  103. }
  104. /* }}} */
  105. @@ -1392,6 +1393,12 @@
  106. CG(compiler_options) |= ZEND_COMPILE_EXTENDED_INFO;
  107. }
  108.  
  109. + if (php_ini_has_per_host_config()) {
  110. + /* activate our fake host entries. lowercase string required! */
  111. + php_ini_activate_per_host_config(ZEND_STRL("\%fake\%"));
  112. + php_ini_activate_per_host_config(ZEND_STRL("\%cli\%"));
  113. + }
  114. +
  115. zend_first_try {
  116. #ifndef PHP_CLI_WIN32_NO_CONSOLE
  117. if (sapi_module == &cli_sapi_module) {
  118. diff -Naur a/sapi/fpm/fpm/fpm_conf.c b/sapi/fpm/fpm/fpm_conf.c
  119. --- a/sapi/fpm/fpm/fpm_conf.c 2020-07-21 10:49:31.000000000 +0200
  120. +++ b/sapi/fpm/fpm/fpm_conf.c 2020-07-24 12:26:10.066773319 +0200
  121. @@ -153,6 +153,7 @@
  122. { "decorate_workers_output", &fpm_conf_set_boolean, WPO(decorate_workers_output) },
  123. { "clear_env", &fpm_conf_set_boolean, WPO(clear_env) },
  124. { "security.limit_extensions", &fpm_conf_set_string, WPO(security_limit_extensions) },
  125. + { "extra_ini", &fpm_conf_set_string, WPO(extra_ini) },
  126. #ifdef HAVE_APPARMOR
  127. { "apparmor_hat", &fpm_conf_set_string, WPO(apparmor_hat) },
  128. #endif
  129. @@ -668,6 +669,7 @@
  130. free(wpc->chroot);
  131. free(wpc->chdir);
  132. free(wpc->security_limit_extensions);
  133. + free(wpc->extra_ini);
  134. #ifdef HAVE_APPARMOR
  135. free(wpc->apparmor_hat);
  136. #endif
  137. @@ -1067,6 +1069,11 @@
  138. wp->config->request_slowlog_trace_depth = 20;
  139. }
  140.  
  141. + /* extra_ini */
  142. + if (wp->config->extra_ini && *wp->config->extra_ini) {
  143. + fpm_evaluate_full_path(&wp->config->extra_ini, wp, NULL, 0);
  144. + }
  145. +
  146. /* chroot */
  147. if (wp->config->chroot && *wp->config->chroot) {
  148.  
  149. @@ -1745,6 +1752,7 @@
  150. zlog(ZLOG_NOTICE, "\tdecorate_workers_output = %s", BOOL2STR(wp->config->decorate_workers_output));
  151. zlog(ZLOG_NOTICE, "\tclear_env = %s", BOOL2STR(wp->config->clear_env));
  152. zlog(ZLOG_NOTICE, "\tsecurity.limit_extensions = %s", wp->config->security_limit_extensions);
  153. + zlog(ZLOG_NOTICE, "\textra_ini = %s", STR2STR(wp->config->extra_ini));
  154.  
  155. for (kv = wp->config->env; kv; kv = kv->next) {
  156. zlog(ZLOG_NOTICE, "\tenv[%s] = %s", kv->key, kv->value);
  157. diff -Naur a/sapi/fpm/fpm/fpm_conf.h b/sapi/fpm/fpm/fpm_conf.h
  158. --- a/sapi/fpm/fpm/fpm_conf.h 2020-07-21 10:49:31.000000000 +0200
  159. +++ b/sapi/fpm/fpm/fpm_conf.h 2020-07-24 12:26:10.066773319 +0200
  160. @@ -93,6 +93,7 @@
  161. int decorate_workers_output;
  162. int clear_env;
  163. char *security_limit_extensions;
  164. + char *extra_ini;
  165. struct key_value_s *env;
  166. struct key_value_s *php_admin_values;
  167. struct key_value_s *php_values;
  168. diff -Naur a/sapi/fpm/fpm/fpm_main.c b/sapi/fpm/fpm/fpm_main.c
  169. --- a/sapi/fpm/fpm/fpm_main.c 2020-07-21 10:49:31.000000000 +0200
  170. +++ b/sapi/fpm/fpm/fpm_main.c 2020-07-24 12:26:10.067773312 +0200
  171. @@ -695,6 +695,9 @@
  172. }
  173.  
  174. if (php_ini_has_per_host_config()) {
  175. + /* activate our fake host entries. lowercase string required! */
  176. + php_ini_activate_per_host_config(ZEND_STRL("\%fake\%"));
  177. +
  178. /* Activate per-host-system-configuration defined in php.ini and stored into configuration_hash during startup */
  179. server_name = FCGI_GETENV(request, "SERVER_NAME");
  180. /* SERVER_NAME should also be defined at this stage..but better check it anyway */
  181. diff -Naur a/sapi/fpm/fpm/fpm_php.c b/sapi/fpm/fpm/fpm_php.c
  182. --- a/sapi/fpm/fpm/fpm_php.c 2020-07-21 10:49:31.000000000 +0200
  183. +++ b/sapi/fpm/fpm/fpm_php.c 2020-07-24 12:26:10.067773312 +0200
  184. @@ -226,6 +226,8 @@
  185.  
  186. int fpm_php_init_child(struct fpm_worker_pool_s *wp) /* {{{ */
  187. {
  188. + php_parse_extra_ini(wp->config->extra_ini);
  189. +
  190. if (0 > fpm_php_apply_defines(wp) ||
  191. 0 > fpm_php_set_allowed_clients(wp)) {
  192. return -1;
  193.