Download | Plain Text | No Line Numbers


  1. diff -Naur php-5.4.31.orig/main/php_ini.c php-5.4.31/main/php_ini.c
  2. --- php-5.4.31.orig/main/php_ini.c 2014-07-23 02:59:30.000000000 +0200
  3. +++ php-5.4.31/main/php_ini.c 2014-08-13 23:15:13.818946358 +0200
  4. @@ -746,6 +746,54 @@
  5. }
  6. /* }}} */
  7.  
  8. +/* {{{ php_parse_extra_ini
  9. + */
  10. +PHPAPI int php_parse_extra_ini(const char *ini_file) {
  11. + if (!sapi_module.php_ini_ignore && ini_file) {
  12. + struct stat sb;
  13. + zend_file_handle fh;
  14. + RESET_ACTIVE_INI_HASH();
  15. + memset(&fh, 0, sizeof(fh));
  16. +
  17. + if (VCWD_STAT(ini_file, &sb) == 0) {
  18. + if (S_ISREG(sb.st_mode)) {
  19. + if ((fh.handle.fp = VCWD_FOPEN(ini_file, "r"))) {
  20. + fh.filename = ini_file;
  21. + fh.type = ZEND_HANDLE_FP;
  22. +
  23. + /* add a fake-host section so our settings will be changed to PHP_INI_SYSTEM during merge */
  24. + zval fakehost;
  25. + Z_STRLEN(fakehost) = sizeof("HOST=\%fake\%") - 1;
  26. + Z_STRVAL(fakehost) = zend_strndup("HOST=\%fake\%", Z_STRLEN(fakehost));
  27. + Z_TYPE(fakehost) = IS_STRING;
  28. + php_ini_parser_cb(&fakehost, NULL, NULL, ZEND_INI_PARSER_SECTION, &configuration_hash TSRMLS_CC);
  29. +
  30. + if (zend_parse_ini_file(&fh, 1, ZEND_INI_SCANNER_NORMAL, (zend_ini_parser_cb_t) php_ini_parser_cb, &configuration_hash TSRMLS_CC) == SUCCESS) {
  31. + /* add the file to the list of ini files read */
  32. + int add_len = strlen(ini_file) + 2;
  33. +
  34. + int php_ini_scanned_files_len = (php_ini_scanned_files) ? 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. + return SUCCESS;
  47. + }
  48. + }
  49. + }
  50. + }
  51. + }
  52. + return FAILURE;
  53. +}
  54. +/* }}} */
  55. +
  56. /* {{{ php_ini_activate_config
  57. */
  58. PHPAPI void php_ini_activate_config(HashTable *source_hash, int modify_type, int stage TSRMLS_DC)
  59. diff -Naur php-5.4.31.orig/main/php_ini.h php-5.4.31/main/php_ini.h
  60. --- php-5.4.31.orig/main/php_ini.h 2014-07-23 02:59:30.000000000 +0200
  61. +++ php-5.4.31/main/php_ini.h 2014-08-13 23:15:13.818946358 +0200
  62. @@ -33,6 +33,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, char *ini_filename, HashTable *target_hash TSRMLS_DC);
  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 TSRMLS_DC);
  68. PHPAPI int php_ini_has_per_dir_config(void);
  69. PHPAPI int php_ini_has_per_host_config(void);
  70. diff -Naur php-5.4.31.orig/sapi/cgi/cgi_main.c php-5.4.31/sapi/cgi/cgi_main.c
  71. --- php-5.4.31.orig/sapi/cgi/cgi_main.c 2014-07-23 02:59:30.000000000 +0200
  72. +++ php-5.4.31/sapi/cgi/cgi_main.c 2014-08-13 23:15:13.819946375 +0200
  73. @@ -836,6 +836,9 @@
  74. }
  75.  
  76. if (php_ini_has_per_host_config()) {
  77. + /* activate our fake host entries. lowercase string required! */
  78. + php_ini_activate_per_host_config("\%fake\%", sizeof("\%fake\%") TSRMLS_CC);
  79. +
  80. /* Activate per-host-system-configuration defined in php.ini and stored into configuration_hash during startup */
  81. if (fcgi_is_fastcgi()) {
  82. fcgi_request *request = (fcgi_request*) SG(server_context);
  83. @@ -937,6 +940,7 @@
  84. if (php_module_startup(sapi_module, &cgi_module_entry, 1) == FAILURE) {
  85. return FAILURE;
  86. }
  87. + php_parse_extra_ini(getenv("PHP_INI_EXTRA"));
  88. return SUCCESS;
  89. }
  90.  
  91. diff -Naur php-5.4.31.orig/sapi/cli/php_cli.c php-5.4.31/sapi/cli/php_cli.c
  92. --- php-5.4.31.orig/sapi/cli/php_cli.c 2014-07-23 02:59:30.000000000 +0200
  93. +++ php-5.4.31/sapi/cli/php_cli.c 2014-08-13 23:15:13.819946375 +0200
  94. @@ -414,6 +414,7 @@
  95. if (php_module_startup(sapi_module, NULL, 0)==FAILURE) {
  96. return FAILURE;
  97. }
  98. + php_parse_extra_ini(getenv("PHP_INI_EXTRA"));
  99. return SUCCESS;
  100. }
  101. /* }}} */
  102. @@ -1358,6 +1359,11 @@
  103. CG(compiler_options) |= ZEND_COMPILE_EXTENDED_INFO;
  104. }
  105.  
  106. + if (php_ini_has_per_host_config()) {
  107. + /* activate our fake host entries. lowercase string required! */
  108. + php_ini_activate_per_host_config("\%fake\%", sizeof("\%fake\%") TSRMLS_CC);
  109. + }
  110. +
  111. zend_first_try {
  112. #ifndef PHP_CLI_WIN32_NO_CONSOLE
  113. if (sapi_module == &cli_sapi_module) {
  114. diff -Naur php-5.4.31.orig/sapi/fpm/fpm/fpm_conf.c php-5.4.31/sapi/fpm/fpm/fpm_conf.c
  115. --- php-5.4.31.orig/sapi/fpm/fpm/fpm_conf.c 2014-07-23 02:59:30.000000000 +0200
  116. +++ php-5.4.31/sapi/fpm/fpm/fpm_conf.c 2014-08-13 23:15:13.819946375 +0200
  117. @@ -150,6 +150,7 @@
  118. { "catch_workers_output", &fpm_conf_set_boolean, WPO(catch_workers_output) },
  119. { "clear_env", &fpm_conf_set_boolean, WPO(clear_env) },
  120. { "security.limit_extensions", &fpm_conf_set_string, WPO(security_limit_extensions) },
  121. + { "extra_ini", &fpm_conf_set_string, WPO(extra_ini) },
  122. { 0, 0, 0 }
  123. };
  124.  
  125. @@ -646,6 +647,7 @@
  126. free(wpc->chroot);
  127. free(wpc->chdir);
  128. free(wpc->security_limit_extensions);
  129. + free(wpc->extra_ini);
  130.  
  131. for (kv = wpc->php_values; kv; kv = kv_next) {
  132. kv_next = kv->next;
  133. @@ -1055,6 +1057,11 @@
  134. }
  135. }
  136.  
  137. + /* extra_ini */
  138. + if (wp->config->extra_ini && *wp->config->extra_ini) {
  139. + fpm_evaluate_full_path(&wp->config->extra_ini, wp, NULL, 0);
  140. + }
  141. +
  142. /* env[], php_value[], php_admin_values[] */
  143. if (!wp->config->chroot) {
  144. struct key_value_s *kv;
  145. @@ -1607,6 +1614,7 @@
  146. zlog(ZLOG_NOTICE, "\tcatch_workers_output = %s", BOOL2STR(wp->config->catch_workers_output));
  147. zlog(ZLOG_NOTICE, "\tclear_env = %s", BOOL2STR(wp->config->clear_env));
  148. zlog(ZLOG_NOTICE, "\tsecurity.limit_extensions = %s", wp->config->security_limit_extensions);
  149. + zlog(ZLOG_NOTICE, "\textra_ini = %s", STR2STR(wp->config->extra_ini));
  150.  
  151. for (kv = wp->config->env; kv; kv = kv->next) {
  152. zlog(ZLOG_NOTICE, "\tenv[%s] = %s", kv->key, kv->value);
  153. diff -Naur php-5.4.31.orig/sapi/fpm/fpm/fpm_conf.h php-5.4.31/sapi/fpm/fpm/fpm_conf.h
  154. --- php-5.4.31.orig/sapi/fpm/fpm/fpm_conf.h 2014-07-23 02:59:30.000000000 +0200
  155. +++ php-5.4.31/sapi/fpm/fpm/fpm_conf.h 2014-08-13 23:15:13.819946375 +0200
  156. @@ -85,6 +85,7 @@
  157. int catch_workers_output;
  158. int clear_env;
  159. char *security_limit_extensions;
  160. + char *extra_ini;
  161. struct key_value_s *env;
  162. struct key_value_s *php_admin_values;
  163. struct key_value_s *php_values;
  164. diff -Naur php-5.4.31.orig/sapi/fpm/fpm/fpm_main.c php-5.4.31/sapi/fpm/fpm/fpm_main.c
  165. --- php-5.4.31.orig/sapi/fpm/fpm/fpm_main.c 2014-07-23 02:59:30.000000000 +0200
  166. +++ php-5.4.31/sapi/fpm/fpm/fpm_main.c 2014-08-13 23:15:13.819946375 +0200
  167. @@ -773,6 +773,9 @@
  168. }
  169.  
  170. if (php_ini_has_per_host_config()) {
  171. + /* activate our fake host entries. lowercase string required! */
  172. + php_ini_activate_per_host_config("\%fake\%", sizeof("\%fake\%") TSRMLS_CC);
  173. +
  174. /* Activate per-host-system-configuration defined in php.ini and stored into configuration_hash during startup */
  175. server_name = sapi_cgibin_getenv("SERVER_NAME", sizeof("SERVER_NAME") - 1 TSRMLS_CC);
  176. /* SERVER_NAME should also be defined at this stage..but better check it anyway */
  177. diff -Naur php-5.4.31.orig/sapi/fpm/fpm/fpm_php.c php-5.4.31/sapi/fpm/fpm/fpm_php.c
  178. --- php-5.4.31.orig/sapi/fpm/fpm/fpm_php.c 2014-07-23 02:59:30.000000000 +0200
  179. +++ php-5.4.31/sapi/fpm/fpm/fpm_php.c 2014-08-13 23:15:13.820946392 +0200
  180. @@ -218,6 +218,8 @@
  181.  
  182. int fpm_php_init_child(struct fpm_worker_pool_s *wp) /* {{{ */
  183. {
  184. + php_parse_extra_ini(wp->config->extra_ini);
  185. +
  186. if (0 > fpm_php_apply_defines(wp) ||
  187. 0 > fpm_php_set_allowed_clients(wp)) {
  188. return -1;
  189.