Download | Plain Text | No Line Numbers


  1. --- a/main/php_ini.c 2024-04-10 07:53:50.000000000 +0200
  2. +++ b/main/php_ini.c 2024-04-16 13:32:09.299828810 +0200
  3. @@ -806,6 +806,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 07:53:50.000000000 +0200
  61. +++ b/main/php_ini.h 2024-04-16 13:29:58.803807897 +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 13:27:39.912850713 +0200
  71. +++ b/sapi/cgi/cgi_main.c 2024-04-16 13:29:58.804807889 +0200
  72. @@ -866,6 +866,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. @@ -969,6 +972,7 @@
  83. if (php_module_startup(sapi_module, &cgi_module_entry, 1) == FAILURE) {
  84. return FAILURE;
  85. }
  86. + php_parse_extra_ini(getenv("PHP_INI_EXTRA"));
  87. return SUCCESS;
  88. }
  89.  
  90. --- a/sapi/cli/php_cli.c 2024-04-16 13:27:39.953850405 +0200
  91. +++ b/sapi/cli/php_cli.c 2024-04-16 13:29:58.805807882 +0200
  92. @@ -413,6 +413,7 @@
  93. if (php_module_startup(sapi_module, NULL, 0)==FAILURE) {
  94. return FAILURE;
  95. }
  96. + php_parse_extra_ini(getenv("PHP_INI_EXTRA"));
  97. return SUCCESS;
  98. }
  99. /* }}} */
  100. @@ -1392,6 +1393,12 @@
  101. CG(compiler_options) |= ZEND_COMPILE_EXTENDED_INFO;
  102. }
  103.  
  104. + if (php_ini_has_per_host_config()) {
  105. + /* activate our fake host entries. lowercase string required! */
  106. + php_ini_activate_per_host_config(ZEND_STRL("\%fake\%"));
  107. + php_ini_activate_per_host_config(ZEND_STRL("\%cli\%"));
  108. + }
  109. +
  110. zend_first_try {
  111. #ifndef PHP_CLI_WIN32_NO_CONSOLE
  112. if (sapi_module == &cli_sapi_module) {
  113. --- a/sapi/fpm/fpm/fpm_conf.c 2024-04-16 13:27:39.985850165 +0200
  114. +++ b/sapi/fpm/fpm/fpm_conf.c 2024-04-16 13:29:58.805807882 +0200
  115. @@ -153,6 +153,7 @@
  116. { "decorate_workers_output", &fpm_conf_set_boolean, WPO(decorate_workers_output) },
  117. { "clear_env", &fpm_conf_set_boolean, WPO(clear_env) },
  118. { "security.limit_extensions", &fpm_conf_set_string, WPO(security_limit_extensions) },
  119. + { "extra_ini", &fpm_conf_set_string, WPO(extra_ini) },
  120. #ifdef HAVE_APPARMOR
  121. { "apparmor_hat", &fpm_conf_set_string, WPO(apparmor_hat) },
  122. #endif
  123. @@ -667,6 +668,7 @@
  124. free(wpc->chroot);
  125. free(wpc->chdir);
  126. free(wpc->security_limit_extensions);
  127. + free(wpc->extra_ini);
  128. #ifdef HAVE_APPARMOR
  129. free(wpc->apparmor_hat);
  130. #endif
  131. @@ -1066,6 +1068,11 @@
  132. wp->config->request_slowlog_trace_depth = 20;
  133. }
  134.  
  135. + /* extra_ini */
  136. + if (wp->config->extra_ini && *wp->config->extra_ini) {
  137. + fpm_evaluate_full_path(&wp->config->extra_ini, wp, NULL, 0);
  138. + }
  139. +
  140. /* chroot */
  141. if (wp->config->chroot && *wp->config->chroot) {
  142.  
  143. @@ -1745,6 +1752,7 @@
  144. zlog(ZLOG_NOTICE, "\tdecorate_workers_output = %s", BOOL2STR(wp->config->decorate_workers_output));
  145. zlog(ZLOG_NOTICE, "\tclear_env = %s", BOOL2STR(wp->config->clear_env));
  146. zlog(ZLOG_NOTICE, "\tsecurity.limit_extensions = %s", wp->config->security_limit_extensions);
  147. + zlog(ZLOG_NOTICE, "\textra_ini = %s", STR2STR(wp->config->extra_ini));
  148.  
  149. for (kv = wp->config->env; kv; kv = kv->next) {
  150. zlog(ZLOG_NOTICE, "\tenv[%s] = %s", kv->key, kv->value);
  151. --- a/sapi/fpm/fpm/fpm_conf.h 2024-04-16 13:27:39.978850218 +0200
  152. +++ b/sapi/fpm/fpm/fpm_conf.h 2024-04-16 13:29:58.805807882 +0200
  153. @@ -93,6 +93,7 @@
  154. int decorate_workers_output;
  155. int clear_env;
  156. char *security_limit_extensions;
  157. + char *extra_ini;
  158. struct key_value_s *env;
  159. struct key_value_s *php_admin_values;
  160. struct key_value_s *php_values;
  161. --- a/sapi/fpm/fpm/fpm_main.c 2024-04-16 13:27:39.928850593 +0200
  162. +++ b/sapi/fpm/fpm/fpm_main.c 2024-04-16 13:29:58.806807874 +0200
  163. @@ -695,6 +695,9 @@
  164. }
  165.  
  166. if (php_ini_has_per_host_config()) {
  167. + /* activate our fake host entries. lowercase string required! */
  168. + php_ini_activate_per_host_config(ZEND_STRL("\%fake\%"));
  169. +
  170. /* Activate per-host-system-configuration defined in php.ini and stored into configuration_hash during startup */
  171. server_name = FCGI_GETENV(request, "SERVER_NAME");
  172. /* SERVER_NAME should also be defined at this stage..but better check it anyway */
  173. --- a/sapi/fpm/fpm/fpm_php.c 2024-04-16 13:27:39.969850285 +0200
  174. +++ b/sapi/fpm/fpm/fpm_php.c 2024-04-16 13:29:58.806807874 +0200
  175. @@ -237,6 +237,8 @@
  176.  
  177. int fpm_php_init_child(struct fpm_worker_pool_s *wp) /* {{{ */
  178. {
  179. + php_parse_extra_ini(wp->config->extra_ini);
  180. +
  181. if (0 > fpm_php_apply_defines(wp) ||
  182. 0 > fpm_php_set_allowed_clients(wp)) {
  183. return -1;
  184.