Download | Plain Text | No Line Numbers


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