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