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