Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 904 lines (795 sloc) 26.895 kb
651e232 Zeev Suraski Testing 123
zsuraski authored
1 /*
2 +----------------------------------------------------------------------+
dbeb415 andigutmans - A belated happy holidays and PHP 5
andigutmans authored
3 | PHP Version 5 |
651e232 Zeev Suraski Testing 123
zsuraski authored
4 +----------------------------------------------------------------------+
d1dded8 MFH: Bump copyright year, 2 of 2.
Sebastian Bergmann authored
5 | Copyright (c) 1997-2008 The PHP Group |
651e232 Zeev Suraski Testing 123
zsuraski authored
6 +----------------------------------------------------------------------+
5bd9322 bump year and license version
foobar authored
7 | This source file is subject to version 3.01 of the PHP license, |
9d1817e Fix bug: #10323. Every value outputted is now escaped.
foobar authored
8 | that is bundled with this package in the file LICENSE, and is |
f68c7ff updating license information in the headers.
James Cox authored
9 | available through the world-wide-web at the following url: |
5bd9322 bump year and license version
foobar authored
10 | http://www.php.net/license/3_01.txt |
c5724cb Zeev Suraski License update
zsuraski authored
11 | If you did not receive a copy of the PHP license and are unable to |
9d1817e Fix bug: #10323. Every value outputted is now escaped.
foobar authored
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
651e232 Zeev Suraski Testing 123
zsuraski authored
14 +----------------------------------------------------------------------+
9d1817e Fix bug: #10323. Every value outputted is now escaped.
foobar authored
15 | Author: Zeev Suraski <zeev@zend.com> |
651e232 Zeev Suraski Testing 123
zsuraski authored
16 +----------------------------------------------------------------------+
17 */
18
46a7b0c Frank M. Kromann Killing compiler warning on Win32
fmk authored
19 /* $Id$ */
651e232 Zeev Suraski Testing 123
zsuraski authored
20
aceaabc Zeev Suraski PHP 4.0
zsuraski authored
21 #include "php.h"
bc415d5 Zeev Suraski * Finalizing the PHP version of SAPI. Support POST and cookies among ot...
zsuraski authored
22 #include "ext/standard/info.h"
1fd0913 Zeev Suraski Initial steps to move the INI mechanism to the Zend engine
zsuraski authored
23 #include "zend_ini.h"
09b6f37 MFH:
Jani Taskinen authored
24 #include "zend_ini_scanner.h"
78194a4 Zeev Suraski - Complete the move to the new INI parser. (Side effect: at last, peop...
zsuraski authored
25 #include "php_ini.h"
26 #include "ext/standard/dl.h"
27 #include "zend_extensions.h"
9d1817e Fix bug: #10323. Every value outputted is now escaped.
foobar authored
28 #include "zend_highlight.h"
ab25640 Removed CWD from php_ini_search_path when using CLI SAPI.
Edin Kadribasic authored
29 #include "SAPI.h"
46a7b0c Frank M. Kromann Killing compiler warning on Win32
fmk authored
30 #include "php_main.h"
ec11fe0 Fix the possible conflicts with other libs (like libc-client)
foobar authored
31 #include "php_scandir.h"
06aae4b Stanislav Malyshev Enable setting php.ini path via the registry
smalyshev authored
32 #ifdef PHP_WIN32
33 #include "win32/php_registry.h"
34 #endif
78194a4 Zeev Suraski - Complete the move to the new INI parser. (Side effect: at last, peop...
zsuraski authored
35
ec11fe0 Fix the possible conflicts with other libs (like libc-client)
foobar authored
36 #if HAVE_SCANDIR && HAVE_ALPHASORT && HAVE_DIRENT_H
37 #include <dirent.h>
82f6cef Fix broken build by adding scandir and alphasort for win32
Shane Caraveo authored
38 #endif
8d352d2 Fixed bug #21625 (When scanning a directory for ini files, do so in
Ilia Alshanetsky authored
39
989a61e Rasmus Lerdorf As discussed, add --with-config-file-scan-dir compile-time switch defini...
rlerdorf authored
40 #ifndef S_ISREG
41 #define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
42 #endif
43
d294f46 Zeev Suraski - Remove the ini_extension_list global
zsuraski authored
44 typedef struct _php_extension_lists {
42c82bb Revert the last patches.
foobar authored
45 zend_llist engine;
46 zend_llist functions;
d294f46 Zeev Suraski - Remove the ini_extension_list global
zsuraski authored
47 } php_extension_lists;
58e24ac Zeev Suraski - Add PHP Modules workspace
zsuraski authored
48
9db5589 Zeev Suraski Recode delayed loading in a much simpler way (switched back to php_ini.c...
zsuraski authored
49 /* True globals */
02d966c MFH:- Added support for [HOST=www.example.com] special sections
Jani Taskinen authored
50 static int is_special_section = 0;
09b6f37 MFH:
Jani Taskinen authored
51 static HashTable *active_ini_hash;
9db5589 Zeev Suraski Recode delayed loading in a much simpler way (switched back to php_ini.c...
zsuraski authored
52 static HashTable configuration_hash;
ba8e317 Optimized request startup sequence for php.ini without per dir and per h...
Dmitry Stogov authored
53 static int has_per_dir_config = 0;
54 static int has_per_host_config = 0;
9db5589 Zeev Suraski Recode delayed loading in a much simpler way (switched back to php_ini.c...
zsuraski authored
55 PHPAPI char *php_ini_opened_path=NULL;
56 static php_extension_lists extension_lists;
e5e6f55 MFH
Jani Taskinen authored
57 PHPAPI char *php_ini_scanned_path=NULL;
989a61e Rasmus Lerdorf As discussed, add --with-config-file-scan-dir compile-time switch defini...
rlerdorf authored
58 PHPAPI char *php_ini_scanned_files=NULL;
9db5589 Zeev Suraski Recode delayed loading in a much simpler way (switched back to php_ini.c...
zsuraski authored
59
81e2cf0 Rasmus Lerdorf Fix folding and clean up some extensions
rlerdorf authored
60 /* {{{ php_ini_displayer_cb
61 */
09b6f37 MFH:
Jani Taskinen authored
62 static void php_ini_displayer_cb(zend_ini_entry *ini_entry, int type TSRMLS_DC)
bc415d5 Zeev Suraski * Finalizing the PHP version of SAPI. Support POST and cookies among ot...
zsuraski authored
63 {
42c82bb Revert the last patches.
foobar authored
64 if (ini_entry->displayer) {
65 ini_entry->displayer(ini_entry, type);
66 } else {
67 char *display_string;
68 uint display_string_length, esc_html=0;
69
7e3b508 ws/style fixes
foobar authored
70 if (type == ZEND_INI_DISPLAY_ORIG && ini_entry->modified) {
42c82bb Revert the last patches.
foobar authored
71 if (ini_entry->orig_value && ini_entry->orig_value[0]) {
72 display_string = ini_entry->orig_value;
73 display_string_length = ini_entry->orig_value_length;
b5c97d8 fix phpinfo() & php -i
Marcus Boerger authored
74 esc_html = !sapi_module.phpinfo_as_text;
42c82bb Revert the last patches.
foobar authored
75 } else {
b5c97d8 fix phpinfo() & php -i
Marcus Boerger authored
76 if (!sapi_module.phpinfo_as_text) {
d6497fc - reenable "no value" output. thanks to sebastian for pointing that out...
Jan Lehnardt authored
77 display_string = "<i>no value</i>";
7e3b508 ws/style fixes
foobar authored
78 display_string_length = sizeof("<i>no value</i>") - 1;
d6497fc - reenable "no value" output. thanks to sebastian for pointing that out...
Jan Lehnardt authored
79 } else {
80 display_string = "no value";
7e3b508 ws/style fixes
foobar authored
81 display_string_length = sizeof("no value") - 1;
9be89ed MFH: ws fixes
Jani Taskinen authored
82 }
42c82bb Revert the last patches.
foobar authored
83 }
84 } else if (ini_entry->value && ini_entry->value[0]) {
85 display_string = ini_entry->value;
86 display_string_length = ini_entry->value_length;
b5c97d8 fix phpinfo() & php -i
Marcus Boerger authored
87 esc_html = !sapi_module.phpinfo_as_text;
42c82bb Revert the last patches.
foobar authored
88 } else {
b5c97d8 fix phpinfo() & php -i
Marcus Boerger authored
89 if (!sapi_module.phpinfo_as_text) {
d6497fc - reenable "no value" output. thanks to sebastian for pointing that out...
Jan Lehnardt authored
90 display_string = "<i>no value</i>";
7e3b508 ws/style fixes
foobar authored
91 display_string_length = sizeof("<i>no value</i>") - 1;
d6497fc - reenable "no value" output. thanks to sebastian for pointing that out...
Jan Lehnardt authored
92 } else {
93 display_string = "no value";
7e3b508 ws/style fixes
foobar authored
94 display_string_length = sizeof("no value") - 1;
9be89ed MFH: ws fixes
Jani Taskinen authored
95 }
42c82bb Revert the last patches.
foobar authored
96 }
7e3b508 ws/style fixes
foobar authored
97
98 if (esc_html) {
a769454 reenable php_html_puts
Sascha Schumann authored
99 php_html_puts(display_string, display_string_length TSRMLS_CC);
42c82bb Revert the last patches.
foobar authored
100 } else {
101 PHPWRITE(display_string, display_string_length);
102 }
103 }
bc415d5 Zeev Suraski * Finalizing the PHP version of SAPI. Support POST and cookies among ot...
zsuraski authored
104 }
81e2cf0 Rasmus Lerdorf Fix folding and clean up some extensions
rlerdorf authored
105 /* }}} */
bc415d5 Zeev Suraski * Finalizing the PHP version of SAPI. Support POST and cookies among ot...
zsuraski authored
106
81e2cf0 Rasmus Lerdorf Fix folding and clean up some extensions
rlerdorf authored
107 /* {{{ php_ini_displayer
108 */
d76cf1d Zeev Suraski More TSRMLS_FETCH work
zsuraski authored
109 static int php_ini_displayer(zend_ini_entry *ini_entry, int module_number TSRMLS_DC)
bc415d5 Zeev Suraski * Finalizing the PHP version of SAPI. Support POST and cookies among ot...
zsuraski authored
110 {
42c82bb Revert the last patches.
foobar authored
111 if (ini_entry->module_number != module_number) {
112 return 0;
113 }
b5c97d8 fix phpinfo() & php -i
Marcus Boerger authored
114 if (!sapi_module.phpinfo_as_text) {
14a6cc8 Change phpinfo() to use CSS styling instead of HTML code.
Colin Viebrock authored
115 PUTS("<tr>");
c7c275b fix phpinfo() output for better browser BC
Colin Viebrock authored
116 PUTS("<td class=\"e\">");
7e3b508 ws/style fixes
foobar authored
117 PHPWRITE(ini_entry->name, ini_entry->name_length - 1);
c7c275b fix phpinfo() output for better browser BC
Colin Viebrock authored
118 PUTS("</td><td class=\"v\">");
09b6f37 MFH:
Jani Taskinen authored
119 php_ini_displayer_cb(ini_entry, ZEND_INI_DISPLAY_ACTIVE TSRMLS_CC);
c7c275b fix phpinfo() output for better browser BC
Colin Viebrock authored
120 PUTS("</td><td class=\"v\">");
09b6f37 MFH:
Jani Taskinen authored
121 php_ini_displayer_cb(ini_entry, ZEND_INI_DISPLAY_ORIG TSRMLS_CC);
6676617 - add phpinfo() support for CLI.
Jan Lehnardt authored
122 PUTS("</td></tr>\n");
123 } else {
7e3b508 ws/style fixes
foobar authored
124 PHPWRITE(ini_entry->name, ini_entry->name_length - 1);
6676617 - add phpinfo() support for CLI.
Jan Lehnardt authored
125 PUTS(" => ");
09b6f37 MFH:
Jani Taskinen authored
126 php_ini_displayer_cb(ini_entry, ZEND_INI_DISPLAY_ACTIVE TSRMLS_CC);
6676617 - add phpinfo() support for CLI.
Jan Lehnardt authored
127 PUTS(" => ");
09b6f37 MFH:
Jani Taskinen authored
128 php_ini_displayer_cb(ini_entry, ZEND_INI_DISPLAY_ORIG TSRMLS_CC);
6676617 - add phpinfo() support for CLI.
Jan Lehnardt authored
129 PUTS("\n");
9be89ed MFH: ws fixes
Jani Taskinen authored
130 }
42c82bb Revert the last patches.
foobar authored
131 return 0;
bc415d5 Zeev Suraski * Finalizing the PHP version of SAPI. Support POST and cookies among ot...
zsuraski authored
132 }
81e2cf0 Rasmus Lerdorf Fix folding and clean up some extensions
rlerdorf authored
133 /* }}} */
bc415d5 Zeev Suraski * Finalizing the PHP version of SAPI. Support POST and cookies among ot...
zsuraski authored
134
81e2cf0 Rasmus Lerdorf Fix folding and clean up some extensions
rlerdorf authored
135 /* {{{ display_ini_entries
136 */
bc415d5 Zeev Suraski * Finalizing the PHP version of SAPI. Support POST and cookies among ot...
zsuraski authored
137 PHPAPI void display_ini_entries(zend_module_entry *module)
138 {
42c82bb Revert the last patches.
foobar authored
139 int module_number;
140 TSRMLS_FETCH();
141
142 if (module) {
143 module_number = module->module_number;
9be89ed MFH: ws fixes
Jani Taskinen authored
144 } else {
42c82bb Revert the last patches.
foobar authored
145 module_number = 0;
146 }
147 php_info_print_table_start();
148 php_info_print_table_header(3, "Directive", "Local Value", "Master Value");
e1814f0 WIN64 support
Dmitry Stogov authored
149 zend_hash_apply_with_argument(EG(ini_directives), (apply_func_arg_t) php_ini_displayer, (void *) (zend_intptr_t) module_number TSRMLS_CC);
42c82bb Revert the last patches.
foobar authored
150 php_info_print_table_end();
bc415d5 Zeev Suraski * Finalizing the PHP version of SAPI. Support POST and cookies among ot...
zsuraski authored
151 }
81e2cf0 Rasmus Lerdorf Fix folding and clean up some extensions
rlerdorf authored
152 /* }}} */
78194a4 Zeev Suraski - Complete the move to the new INI parser. (Side effect: at last, peop...
zsuraski authored
153
154 /* php.ini support */
02d966c MFH:- Added support for [HOST=www.example.com] special sections
Jani Taskinen authored
155 #define PHP_EXTENSION_TOKEN "extension"
78194a4 Zeev Suraski - Complete the move to the new INI parser. (Side effect: at last, peop...
zsuraski authored
156 #ifdef ZTS
157 # if (ZEND_DEBUG)
5af649e Zeev Suraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
158 # define ZEND_EXTENSION_TOKEN "zend_extension_debug_ts"
78194a4 Zeev Suraski - Complete the move to the new INI parser. (Side effect: at last, peop...
zsuraski authored
159 # else
5af649e Zeev Suraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
160 # define ZEND_EXTENSION_TOKEN "zend_extension_ts"
78194a4 Zeev Suraski - Complete the move to the new INI parser. (Side effect: at last, peop...
zsuraski authored
161 # endif
162 #else
163 # if (ZEND_DEBUG)
5af649e Zeev Suraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
164 # define ZEND_EXTENSION_TOKEN "zend_extension_debug"
78194a4 Zeev Suraski - Complete the move to the new INI parser. (Side effect: at last, peop...
zsuraski authored
165 # else
5af649e Zeev Suraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
166 # define ZEND_EXTENSION_TOKEN "zend_extension"
78194a4 Zeev Suraski - Complete the move to the new INI parser. (Side effect: at last, peop...
zsuraski authored
167 # endif
168 #endif
169
09b6f37 MFH:
Jani Taskinen authored
170 /* {{{ config_zval_dtor
81e2cf0 Rasmus Lerdorf Fix folding and clean up some extensions
rlerdorf authored
171 */
1674976 MFH: Fixed win32 build.
Jani Taskinen authored
172 PHPAPI void config_zval_dtor(zval *zvalue)
78194a4 Zeev Suraski - Complete the move to the new INI parser. (Side effect: at last, peop...
zsuraski authored
173 {
09b6f37 MFH:
Jani Taskinen authored
174 if (Z_TYPE_P(zvalue) == IS_ARRAY) {
175 zend_hash_destroy(Z_ARRVAL_P(zvalue));
176 free(Z_ARRVAL_P(zvalue));
177 } else if (Z_TYPE_P(zvalue) == IS_STRING) {
178 free(Z_STRVAL_P(zvalue));
179 }
180 }
181 /* Reset / free active_ini_sectin global */
182 #define RESET_ACTIVE_INI_HASH() do { \
183 active_ini_hash = NULL; \
184 } while (0)
185 /* }}} */
186
187 /* {{{ php_ini_parser_cb
188 */
189 static void php_ini_parser_cb(zval *arg1, zval *arg2, zval *arg3, int callback_type, HashTable *target_hash)
190 {
191 zval *entry;
192 HashTable *active_hash;
02d966c MFH:- Added support for [HOST=www.example.com] special sections
Jani Taskinen authored
193 char *extension_name;
09b6f37 MFH:
Jani Taskinen authored
194
195 if (active_ini_hash) {
196 active_hash = active_ini_hash;
197 } else {
198 active_hash = target_hash;
199 }
200
42c82bb Revert the last patches.
foobar authored
201 switch (callback_type) {
202 case ZEND_INI_PARSER_ENTRY: {
203 if (!arg2) {
09b6f37 MFH:
Jani Taskinen authored
204 /* bare string - nothing to do */
42c82bb Revert the last patches.
foobar authored
205 break;
206 }
09b6f37 MFH:
Jani Taskinen authored
207
208 /* PHP and Zend extensions are not added into configuration hash! */
02d966c MFH:- Added support for [HOST=www.example.com] special sections
Jani Taskinen authored
209 if (!is_special_section && !strcasecmp(Z_STRVAL_P(arg1), PHP_EXTENSION_TOKEN)) { /* load PHP extension */
210 extension_name = estrndup(Z_STRVAL_P(arg2), Z_STRLEN_P(arg2));
211 zend_llist_add_element(&extension_lists.functions, &extension_name);
212 } else if (!is_special_section && !strcasecmp(Z_STRVAL_P(arg1), ZEND_EXTENSION_TOKEN)) { /* load Zend extension */
213 extension_name = estrndup(Z_STRVAL_P(arg2), Z_STRLEN_P(arg2));
42c82bb Revert the last patches.
foobar authored
214 zend_llist_add_element(&extension_lists.engine, &extension_name);
09b6f37 MFH:
Jani Taskinen authored
215
216 /* All other entries are added into either configuration_hash or active ini section array */
42c82bb Revert the last patches.
foobar authored
217 } else {
09b6f37 MFH:
Jani Taskinen authored
218 /* Store in active hash */
219 zend_hash_update(active_hash, Z_STRVAL_P(arg1), Z_STRLEN_P(arg1) + 1, arg2, sizeof(zval), (void **) &entry);
42c82bb Revert the last patches.
foobar authored
220 Z_STRVAL_P(entry) = zend_strndup(Z_STRVAL_P(entry), Z_STRLEN_P(entry));
221 }
222 }
223 break;
b51b6f0 ini patch to allow 'entry[] = value' entries
Harald Radi authored
224
225 case ZEND_INI_PARSER_POP_ENTRY: {
09b6f37 MFH:
Jani Taskinen authored
226 zval *option_arr;
227 zval *find_arr;
b51b6f0 ini patch to allow 'entry[] = value' entries
Harald Radi authored
228
229 if (!arg2) {
230 /* bare string - nothing to do */
231 break;
232 }
233
09b6f37 MFH:
Jani Taskinen authored
234 /* fprintf(stdout, "ZEND_INI_PARSER_POP_ENTRY: %s[%s] = %s\n",Z_STRVAL_P(arg1), Z_STRVAL_P(arg3), Z_STRVAL_P(arg2)); */
235
236 /* If option not found in hash or is not an array -> create array, otherwise add to existing array */
237 if (zend_hash_find(active_hash, Z_STRVAL_P(arg1), Z_STRLEN_P(arg1) + 1, (void **) &find_arr) == FAILURE || Z_TYPE_P(find_arr) != IS_ARRAY) {
238 option_arr = (zval *) pemalloc(sizeof(zval), 1);
239 INIT_PZVAL(option_arr);
240 Z_TYPE_P(option_arr) = IS_ARRAY;
241 Z_ARRVAL_P(option_arr) = (HashTable *) pemalloc(sizeof(HashTable), 1);
242 zend_hash_init(Z_ARRVAL_P(option_arr), 0, NULL, (dtor_func_t) config_zval_dtor, 1);
243 zend_hash_update(active_hash, Z_STRVAL_P(arg1), Z_STRLEN_P(arg1) + 1, option_arr, sizeof(zval), (void **) &find_arr);
244 free(option_arr);
245 }
b51b6f0 ini patch to allow 'entry[] = value' entries
Harald Radi authored
246
09b6f37 MFH:
Jani Taskinen authored
247 /* arg3 is possible option offset name */
248 if (arg3 && Z_STRLEN_P(arg3) > 0) {
249 zend_symtable_update(Z_ARRVAL_P(find_arr), Z_STRVAL_P(arg3), Z_STRLEN_P(arg3) + 1, arg2, sizeof(zval), (void **) &entry);
b51b6f0 ini patch to allow 'entry[] = value' entries
Harald Radi authored
250 } else {
09b6f37 MFH:
Jani Taskinen authored
251 zend_hash_next_index_insert(Z_ARRVAL_P(find_arr), arg2, sizeof(zval), (void **) &entry);
b51b6f0 ini patch to allow 'entry[] = value' entries
Harald Radi authored
252 }
09b6f37 MFH:
Jani Taskinen authored
253 Z_STRVAL_P(entry) = zend_strndup(Z_STRVAL_P(entry), Z_STRLEN_P(entry));
b51b6f0 ini patch to allow 'entry[] = value' entries
Harald Radi authored
254 }
255 break;
256
09b6f37 MFH:
Jani Taskinen authored
257 case ZEND_INI_PARSER_SECTION: { /* Create an array of entries of each section */
258
259 /* fprintf(stdout, "ZEND_INI_PARSER_SECTION: %s\n",Z_STRVAL_P(arg1)); */
260
261 char *key = NULL;
262 uint key_len;
263
02d966c MFH:- Added support for [HOST=www.example.com] special sections
Jani Taskinen authored
264 /* PATH sections */
09b6f37 MFH:
Jani Taskinen authored
265 if (!strncasecmp(Z_STRVAL_P(arg1), "PATH", sizeof("PATH") - 1)) {
266 key = Z_STRVAL_P(arg1);
267 key = key + sizeof("PATH") - 1;
268 key_len = Z_STRLEN_P(arg1) - sizeof("PATH") + 1;
02d966c MFH:- Added support for [HOST=www.example.com] special sections
Jani Taskinen authored
269 is_special_section = 1;
ba8e317 Optimized request startup sequence for php.ini without per dir and per h...
Dmitry Stogov authored
270 has_per_dir_config = 1;
09b6f37 MFH:
Jani Taskinen authored
271
02d966c MFH:- Added support for [HOST=www.example.com] special sections
Jani Taskinen authored
272 /* HOST sections */
09b6f37 MFH:
Jani Taskinen authored
273 } else if (!strncasecmp(Z_STRVAL_P(arg1), "HOST", sizeof("HOST") - 1)) {
274 key = Z_STRVAL_P(arg1);
275 key = key + sizeof("HOST") - 1;
276 key_len = Z_STRLEN_P(arg1) - sizeof("HOST") + 1;
02d966c MFH:- Added support for [HOST=www.example.com] special sections
Jani Taskinen authored
277 is_special_section = 1;
ba8e317 Optimized request startup sequence for php.ini without per dir and per h...
Dmitry Stogov authored
278 has_per_host_config = 1;
279
02d966c MFH:- Added support for [HOST=www.example.com] special sections
Jani Taskinen authored
280 } else {
281 is_special_section = 0;
09b6f37 MFH:
Jani Taskinen authored
282 }
283
284 if (key && key_len > 0) {
285 /* Strip any trailing slashes */
286 while (key_len > 0 && (key[key_len - 1] == '/' || key[key_len - 1] == '\\')) {
287 key_len--;
288 key[key_len] = 0;
289 }
290
291 /* Strip any leading whitespace and '=' */
292 while (*key && (
293 *key == '=' ||
294 *key == ' ' ||
295 *key == '\t'
296 )) {
297 key++;
298 key_len--;
299 }
300
301 /* Search for existing entry and if it does not exist create one */
302 if (zend_hash_find(target_hash, key, key_len + 1, (void **) &entry) == FAILURE) {
303 zval *section_arr;
304
305 section_arr = (zval *) pemalloc(sizeof(zval), 1);
306 INIT_PZVAL(section_arr);
307 Z_TYPE_P(section_arr) = IS_ARRAY;
308 Z_ARRVAL_P(section_arr) = (HashTable *) pemalloc(sizeof(HashTable), 1);
309 zend_hash_init(Z_ARRVAL_P(section_arr), 0, NULL, (dtor_func_t) config_zval_dtor, 1);
310 zend_hash_update(target_hash, key, key_len + 1, section_arr, sizeof(zval), (void **) &entry);
311 free(section_arr);
312 }
313 active_ini_hash = Z_ARRVAL_P(entry);
314 }
315 }
42c82bb Revert the last patches.
foobar authored
316 break;
317 }
78194a4 Zeev Suraski - Complete the move to the new INI parser. (Side effect: at last, peop...
zsuraski authored
318 }
81e2cf0 Rasmus Lerdorf Fix folding and clean up some extensions
rlerdorf authored
319 /* }}} */
78194a4 Zeev Suraski - Complete the move to the new INI parser. (Side effect: at last, peop...
zsuraski authored
320
02d966c MFH:- Added support for [HOST=www.example.com] special sections
Jani Taskinen authored
321 /* {{{ php_load_php_extension_cb
81e2cf0 Rasmus Lerdorf Fix folding and clean up some extensions
rlerdorf authored
322 */
02d966c MFH:- Added support for [HOST=www.example.com] special sections
Jani Taskinen authored
323 static void php_load_php_extension_cb(void *arg TSRMLS_DC)
db0b8bc Defer loading of extensions until all configuration entries have been
Sascha Schumann authored
324 {
02d966c MFH:- Added support for [HOST=www.example.com] special sections
Jani Taskinen authored
325 php_load_extension(*((char **) arg), MODULE_PERSISTENT, 0 TSRMLS_CC);
d294f46 Zeev Suraski - Remove the ini_extension_list global
zsuraski authored
326 }
81e2cf0 Rasmus Lerdorf Fix folding and clean up some extensions
rlerdorf authored
327 /* }}} */
d294f46 Zeev Suraski - Remove the ini_extension_list global
zsuraski authored
328
81e2cf0 Rasmus Lerdorf Fix folding and clean up some extensions
rlerdorf authored
329 /* {{{ php_load_zend_extension_cb
330 */
d76cf1d Zeev Suraski More TSRMLS_FETCH work
zsuraski authored
331 static void php_load_zend_extension_cb(void *arg TSRMLS_DC)
d294f46 Zeev Suraski - Remove the ini_extension_list global
zsuraski authored
332 {
42c82bb Revert the last patches.
foobar authored
333 zend_load_extension(*((char **) arg));
db0b8bc Defer loading of extensions until all configuration entries have been
Sascha Schumann authored
334 }
81e2cf0 Rasmus Lerdorf Fix folding and clean up some extensions
rlerdorf authored
335 /* }}} */
db0b8bc Defer loading of extensions until all configuration entries have been
Sascha Schumann authored
336
81e2cf0 Rasmus Lerdorf Fix folding and clean up some extensions
rlerdorf authored
337 /* {{{ php_init_config
338 */
64cfbf5 MFH: - Fixed bug #34307 (OnUpdateStringUnempty INI options can be set em...
foobar authored
339 int php_init_config(TSRMLS_D)
78194a4 Zeev Suraski - Complete the move to the new INI parser. (Side effect: at last, peop...
zsuraski authored
340 {
c946b4d In addtion to path to php.ini, PHPRC now may specify full file name
Dmitry Stogov authored
341 char *php_ini_file_name = NULL;
f66d5f0 - Fixed few logic errors in php*.ini search path creation as documented ...
foobar authored
342 char *php_ini_search_path = NULL;
42c82bb Revert the last patches.
foobar authored
343 int safe_mode_state;
344 char *open_basedir;
f66d5f0 - Fixed few logic errors in php*.ini search path creation as documented ...
foobar authored
345 int free_ini_search_path = 0;
42c82bb Revert the last patches.
foobar authored
346 zend_file_handle fh;
347
09b6f37 MFH:
Jani Taskinen authored
348 if (zend_hash_init(&configuration_hash, 0, NULL, (dtor_func_t) config_zval_dtor, 1) == FAILURE) {
1890173 Revert
foobar authored
349 return FAILURE;
350 }
351
63739c7 give sapi modules the possibility to overwrite default ini settings
Marcus Boerger authored
352 if (sapi_module.ini_defaults) {
353 sapi_module.ini_defaults(&configuration_hash);
354 }
355
42c82bb Revert the last patches.
foobar authored
356 zend_llist_init(&extension_lists.engine, sizeof(char *), (llist_dtor_func_t) free_estring, 1);
c75b887 MFH: No zval is stored here
Jani Taskinen authored
357 zend_llist_init(&extension_lists.functions, sizeof(char *), (llist_dtor_func_t) free_estring, 1);
9be89ed MFH: ws fixes
Jani Taskinen authored
358
42c82bb Revert the last patches.
foobar authored
359 safe_mode_state = PG(safe_mode);
360 open_basedir = PG(open_basedir);
361
5af649e Zeev Suraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
362 if (sapi_module.php_ini_path_override) {
c946b4d In addtion to path to php.ini, PHPRC now may specify full file name
Dmitry Stogov authored
363 php_ini_file_name = sapi_module.php_ini_path_override;
5af649e Zeev Suraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
364 php_ini_search_path = sapi_module.php_ini_path_override;
365 free_ini_search_path = 0;
f66d5f0 - Fixed few logic errors in php*.ini search path creation as documented ...
foobar authored
366 } else if (!sapi_module.php_ini_ignore) {
112462d Antony Dovgal MFH
tony2001 authored
367 int search_path_size;
5af649e Zeev Suraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
368 char *default_location;
f66d5f0 - Fixed few logic errors in php*.ini search path creation as documented ...
foobar authored
369 char *env_location;
370 char *binary_location;
e1658ed Minor cleanups to path building and php*.ini search logic.
Preston L. Bannister authored
371 static const char paths_separator[] = { ZEND_PATHS_SEPARATOR, 0 };
2479384 Fixed unused variable warning on *nix.
Ilia Alshanetsky authored
372 #ifdef PHP_WIN32
06aae4b Stanislav Malyshev Enable setting php.ini path via the registry
smalyshev authored
373 char *reg_location;
2479384 Fixed unused variable warning on *nix.
Ilia Alshanetsky authored
374 #endif
6de4f3a Add check for php.ini in same directory as php.exe (or equivalent execut...
Preston L. Bannister authored
375
f66d5f0 - Fixed few logic errors in php*.ini search path creation as documented ...
foobar authored
376 env_location = getenv("PHPRC");
377 if (!env_location) {
378 env_location = "";
379 }
380
381 /*
382 * Prepare search path
383 */
384
112462d Antony Dovgal MFH
tony2001 authored
385 search_path_size = MAXPATHLEN * 4 + strlen(env_location) + 3 + 1;
386 php_ini_search_path = (char *) emalloc(search_path_size);
5af649e Zeev Suraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
387 free_ini_search_path = 1;
388 php_ini_search_path[0] = 0;
6de4f3a Add check for php.ini in same directory as php.exe (or equivalent execut...
Preston L. Bannister authored
389
acb1e07 Changed priority of PHPRC environment variable on win32 to be higher the...
Dmitry Stogov authored
390 /* Add environment location */
391 if (env_location[0]) {
392 if (*php_ini_search_path) {
112462d Antony Dovgal MFH
tony2001 authored
393 strlcat(php_ini_search_path, paths_separator, search_path_size);
acb1e07 Changed priority of PHPRC environment variable on win32 to be higher the...
Dmitry Stogov authored
394 }
112462d Antony Dovgal MFH
tony2001 authored
395 strlcat(php_ini_search_path, env_location, search_path_size);
c946b4d In addtion to path to php.ini, PHPRC now may specify full file name
Dmitry Stogov authored
396 php_ini_file_name = env_location;
acb1e07 Changed priority of PHPRC environment variable on win32 to be higher the...
Dmitry Stogov authored
397 }
398
06aae4b Stanislav Malyshev Enable setting php.ini path via the registry
smalyshev authored
399 #ifdef PHP_WIN32
400 /* Add registry location */
401 reg_location = GetIniPathFromRegistry();
f66d5f0 - Fixed few logic errors in php*.ini search path creation as documented ...
foobar authored
402 if (reg_location != NULL) {
06aae4b Stanislav Malyshev Enable setting php.ini path via the registry
smalyshev authored
403 if (*php_ini_search_path) {
112462d Antony Dovgal MFH
tony2001 authored
404 strlcat(php_ini_search_path, paths_separator, search_path_size);
06aae4b Stanislav Malyshev Enable setting php.ini path via the registry
smalyshev authored
405 }
112462d Antony Dovgal MFH
tony2001 authored
406 strlcat(php_ini_search_path, reg_location, search_path_size);
06aae4b Stanislav Malyshev Enable setting php.ini path via the registry
smalyshev authored
407 efree(reg_location);
408 }
409 #endif
42c82bb Revert the last patches.
foobar authored
410
ef058cd Search for php.ini in CWD in all sapi's *but* CLI.
Edin Kadribasic authored
411 /* Add cwd (not with CLI) */
412 if (strcmp(sapi_module.name, "cli") != 0) {
e1658ed Minor cleanups to path building and php*.ini search logic.
Preston L. Bannister authored
413 if (*php_ini_search_path) {
112462d Antony Dovgal MFH
tony2001 authored
414 strlcat(php_ini_search_path, paths_separator, search_path_size);
e1658ed Minor cleanups to path building and php*.ini search logic.
Preston L. Bannister authored
415 }
112462d Antony Dovgal MFH
tony2001 authored
416 strlcat(php_ini_search_path, ".", search_path_size);
5af649e Zeev Suraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
417 }
42c82bb Revert the last patches.
foobar authored
418
5af649e Zeev Suraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
419 /* Add binary directory */
6de4f3a Add check for php.ini in same directory as php.exe (or equivalent execut...
Preston L. Bannister authored
420 #ifdef PHP_WIN32
b9fd107 Zeev Suraski Use portable #define
zsuraski authored
421 binary_location = (char *) emalloc(MAXPATHLEN);
7e3b508 ws/style fixes
foobar authored
422 if (GetModuleFileName(0, binary_location, MAXPATHLEN) == 0) {
5af649e Zeev Suraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
423 efree(binary_location);
424 binary_location = NULL;
42c82bb Revert the last patches.
foobar authored
425 }
5af649e Zeev Suraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
426 #else
427 if (sapi_module.executable_location) {
0db4f06 Antony Dovgal MFH
tony2001 authored
428 binary_location = (char *)emalloc(MAXPATHLEN);
448dbac Hannes Magnusson MFH: Fixed PHP CLI to use the php.ini from the binary location
bjori authored
429 if (!strchr(sapi_module.executable_location, '/')) {
9098946 Hannes Magnusson MFH: bug#41361 (shell_exec() does not find binaries)
bjori authored
430 char *envpath, *path;
448dbac Hannes Magnusson MFH: Fixed PHP CLI to use the php.ini from the binary location
bjori authored
431 int found = 0;
432
9098946 Hannes Magnusson MFH: bug#41361 (shell_exec() does not find binaries)
bjori authored
433 if ((envpath = getenv("PATH")) != NULL) {
448dbac Hannes Magnusson MFH: Fixed PHP CLI to use the php.ini from the binary location
bjori authored
434 char *search_dir, search_path[MAXPATHLEN];
63c1173 Hannes Magnusson use php_strtok_r() rather than strsep()
bjori authored
435 char *last;
448dbac Hannes Magnusson MFH: Fixed PHP CLI to use the php.ini from the binary location
bjori authored
436
d85fc29 Antony Dovgal MFH
tony2001 authored
437 path = estrdup(envpath);
63c1173 Hannes Magnusson use php_strtok_r() rather than strsep()
bjori authored
438 search_dir = php_strtok_r(path, ":", &last);
d85fc29 Antony Dovgal MFH
tony2001 authored
439
63c1173 Hannes Magnusson use php_strtok_r() rather than strsep()
bjori authored
440 while (search_dir) {
448dbac Hannes Magnusson MFH: Fixed PHP CLI to use the php.ini from the binary location
bjori authored
441 snprintf(search_path, MAXPATHLEN, "%s/%s", search_dir, sapi_module.executable_location);
442 if (VCWD_REALPATH(search_path, binary_location) && !VCWD_ACCESS(binary_location, X_OK)) {
443 found = 1;
444 break;
445 }
63c1173 Hannes Magnusson use php_strtok_r() rather than strsep()
bjori authored
446 search_dir = php_strtok_r(NULL, ":", &last);
448dbac Hannes Magnusson MFH: Fixed PHP CLI to use the php.ini from the binary location
bjori authored
447 }
d85fc29 Antony Dovgal MFH
tony2001 authored
448 efree(path);
448dbac Hannes Magnusson MFH: Fixed PHP CLI to use the php.ini from the binary location
bjori authored
449 }
450 if (!found) {
451 efree(binary_location);
452 binary_location = NULL;
453 }
454 } else if (!VCWD_REALPATH(sapi_module.executable_location, binary_location) || VCWD_ACCESS(binary_location, X_OK)) {
7e071d9 php.ini search logic needs to use the absolute path of the running binar...
Hartmut Holzgraefe authored
455 efree(binary_location);
9be89ed MFH: ws fixes
Jani Taskinen authored
456 binary_location = NULL;
98694f9 Antony Dovgal ws fix
tony2001 authored
457 }
5af649e Zeev Suraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
458 } else {
459 binary_location = NULL;
6de4f3a Add check for php.ini in same directory as php.exe (or equivalent execut...
Preston L. Bannister authored
460 }
5af649e Zeev Suraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
461 #endif
462 if (binary_location) {
463 char *separator_location = strrchr(binary_location, DEFAULT_SLASH);
9be89ed MFH: ws fixes
Jani Taskinen authored
464
882cb20 edge case: do not remove trailing slash for root directory (Bug #33882)
Hartmut Holzgraefe authored
465 if (separator_location && separator_location != binary_location) {
7e071d9 php.ini search logic needs to use the absolute path of the running binar...
Hartmut Holzgraefe authored
466 *(separator_location) = 0;
5af649e Zeev Suraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
467 }
e1658ed Minor cleanups to path building and php*.ini search logic.
Preston L. Bannister authored
468 if (*php_ini_search_path) {
112462d Antony Dovgal MFH
tony2001 authored
469 strlcat(php_ini_search_path, paths_separator, search_path_size);
e1658ed Minor cleanups to path building and php*.ini search logic.
Preston L. Bannister authored
470 }
112462d Antony Dovgal MFH
tony2001 authored
471 strlcat(php_ini_search_path, binary_location, search_path_size);
5af649e Zeev Suraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
472 efree(binary_location);
473 }
474
475 /* Add default location */
476 #ifdef PHP_WIN32
7e3b508 ws/style fixes
foobar authored
477 default_location = (char *) emalloc(MAXPATHLEN + 1);
9be89ed MFH: ws fixes
Jani Taskinen authored
478
e1658ed Minor cleanups to path building and php*.ini search logic.
Preston L. Bannister authored
479 if (0 < GetWindowsDirectory(default_location, MAXPATHLEN)) {
480 if (*php_ini_search_path) {
112462d Antony Dovgal MFH
tony2001 authored
481 strlcat(php_ini_search_path, paths_separator, search_path_size);
e1658ed Minor cleanups to path building and php*.ini search logic.
Preston L. Bannister authored
482 }
112462d Antony Dovgal MFH
tony2001 authored
483 strlcat(php_ini_search_path, default_location, search_path_size);
5af649e Zeev Suraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
484 }
485 efree(default_location);
fcdda2e Wez Furlong Fix a problem resolving the php.ini path under win32 terminal services e...
wez authored
486
487 {
488 /* For people running under terminal services, GetWindowsDirectory will
489 * return their personal Windows directory, so lets add the system
490 * windows directory too */
491 typedef UINT (WINAPI *get_system_windows_directory_func)(char *buffer, UINT size);
492 static get_system_windows_directory_func get_system_windows_directory = NULL;
493 HMODULE kern;
494
495 if (get_system_windows_directory == NULL) {
496 kern = LoadLibrary("kernel32.dll");
497 if (kern) {
498 get_system_windows_directory = (get_system_windows_directory_func)GetProcAddress(kern, "GetSystemWindowsDirectoryA");
499 }
500 }
501 if (get_system_windows_directory != NULL) {
502 default_location = (char *) emalloc(MAXPATHLEN + 1);
503 if (0 < get_system_windows_directory(default_location, MAXPATHLEN)) {
504 if (*php_ini_search_path) {
112462d Antony Dovgal MFH
tony2001 authored
505 strlcat(php_ini_search_path, paths_separator, search_path_size);
fcdda2e Wez Furlong Fix a problem resolving the php.ini path under win32 terminal services e...
wez authored
506 }
112462d Antony Dovgal MFH
tony2001 authored
507 strlcat(php_ini_search_path, default_location, search_path_size);
fcdda2e Wez Furlong Fix a problem resolving the php.ini path under win32 terminal services e...
wez authored
508 }
509 efree(default_location);
510 }
511 }
6de4f3a Add check for php.ini in same directory as php.exe (or equivalent execut...
Preston L. Bannister authored
512 #else
5af649e Zeev Suraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
513 default_location = PHP_CONFIG_FILE_PATH;
e1658ed Minor cleanups to path building and php*.ini search logic.
Preston L. Bannister authored
514 if (*php_ini_search_path) {
112462d Antony Dovgal MFH
tony2001 authored
515 strlcat(php_ini_search_path, paths_separator, search_path_size);
e1658ed Minor cleanups to path building and php*.ini search logic.
Preston L. Bannister authored
516 }
112462d Antony Dovgal MFH
tony2001 authored
517 strlcat(php_ini_search_path, default_location, search_path_size);
6de4f3a Add check for php.ini in same directory as php.exe (or equivalent execut...
Preston L. Bannister authored
518 #endif
5af649e Zeev Suraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
519 }
6de4f3a Add check for php.ini in same directory as php.exe (or equivalent execut...
Preston L. Bannister authored
520
5af649e Zeev Suraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
521 PG(safe_mode) = 0;
522 PG(open_basedir) = NULL;
523
e5e6f55 MFH
Jani Taskinen authored
524 /*
525 * Find and open actual ini file
526 */
527
e52aac9 Wez Furlong Implement simple stream support in the ZE scanners.
wez authored
528 memset(&fh, 0, sizeof(fh));
e5e6f55 MFH
Jani Taskinen authored
529
530 /* If SAPI does not want to ignore all ini files OR an overriding file/path is given.
531 * This allows disabling scanning for ini files in the PHP_CONFIG_FILE_SCAN_DIR but still
532 * load an optional ini file. */
533 if (!sapi_module.php_ini_ignore || sapi_module.php_ini_path_override) {
534
535 /* Check if php_ini_file_name is a file and can be opened */
c946b4d In addtion to path to php.ini, PHPRC now may specify full file name
Dmitry Stogov authored
536 if (php_ini_file_name && php_ini_file_name[0]) {
cecb9df Implemented -n switch to skip parsing ini at startup as suggested by Wez...
Marcus Boerger authored
537 struct stat statbuf;
9be89ed MFH: ws fixes
Jani Taskinen authored
538
c946b4d In addtion to path to php.ini, PHPRC now may specify full file name
Dmitry Stogov authored
539 if (!VCWD_STAT(php_ini_file_name, &statbuf)) {
cecb9df Implemented -n switch to skip parsing ini at startup as suggested by Wez...
Marcus Boerger authored
540 if (!((statbuf.st_mode & S_IFMT) == S_IFDIR)) {
c946b4d In addtion to path to php.ini, PHPRC now may specify full file name
Dmitry Stogov authored
541 fh.handle.fp = VCWD_FOPEN(php_ini_file_name, "r");
542 if (fh.handle.fp) {
543 fh.filename = php_ini_opened_path = expand_filepath(php_ini_file_name, NULL TSRMLS_CC);
544 }
cecb9df Implemented -n switch to skip parsing ini at startup as suggested by Wez...
Marcus Boerger authored
545 }
5af649e Zeev Suraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
546 }
547 }
e5e6f55 MFH
Jani Taskinen authored
548
549 /* Otherwise search for php-%sapi-module-name%.ini file in search path */
cecb9df Implemented -n switch to skip parsing ini at startup as suggested by Wez...
Marcus Boerger authored
550 if (!fh.handle.fp) {
551 const char *fmt = "php-%s.ini";
50ea267 - Avoid sprintf, even when checked copy'n'paste or changes lead to error...
Marcus Boerger authored
552 char *ini_fname;
553 spprintf(&ini_fname, 0, fmt, sapi_module.name);
cecb9df Implemented -n switch to skip parsing ini at startup as suggested by Wez...
Marcus Boerger authored
554 fh.handle.fp = php_fopen_with_path(ini_fname, "r", php_ini_search_path, &php_ini_opened_path TSRMLS_CC);
555 efree(ini_fname);
556 if (fh.handle.fp) {
557 fh.filename = php_ini_opened_path;
558 }
e1658ed Minor cleanups to path building and php*.ini search logic.
Preston L. Bannister authored
559 }
e5e6f55 MFH
Jani Taskinen authored
560
561 /* If still no ini file found, search for php.ini file in search path */
cecb9df Implemented -n switch to skip parsing ini at startup as suggested by Wez...
Marcus Boerger authored
562 if (!fh.handle.fp) {
563 fh.handle.fp = php_fopen_with_path("php.ini", "r", php_ini_search_path, &php_ini_opened_path TSRMLS_CC);
564 if (fh.handle.fp) {
565 fh.filename = php_ini_opened_path;
566 }
8f94a8a First try to open php-SAPI.ini and if it fails fall back to regular
Edin Kadribasic authored
567 }
751cd67 get_cfg_var("get_file_path") didn't work correctly when an alternative
Sander Roobol authored
568 }
7e3b508 ws/style fixes
foobar authored
569
5af649e Zeev Suraski Revert to the old php_ini.c, and reimplement the binary-path searching.
zsuraski authored
570 if (free_ini_search_path) {
571 efree(php_ini_search_path);
572 }
7e3b508 ws/style fixes
foobar authored
573
42c82bb Revert the last patches.
foobar authored
574 PG(safe_mode) = safe_mode_state;
575 PG(open_basedir) = open_basedir;
576
989a61e Rasmus Lerdorf As discussed, add --with-config-file-scan-dir compile-time switch defini...
rlerdorf authored
577 if (fh.handle.fp) {
578 fh.type = ZEND_HANDLE_FP;
09b6f37 MFH:
Jani Taskinen authored
579 RESET_ACTIVE_INI_HASH();
42c82bb Revert the last patches.
foobar authored
580
09b6f37 MFH:
Jani Taskinen authored
581 zend_parse_ini_file(&fh, 1, ZEND_INI_SCANNER_NORMAL, (zend_ini_parser_cb_t) php_ini_parser_cb, &configuration_hash TSRMLS_CC);
9be89ed MFH: ws fixes
Jani Taskinen authored
582
989a61e Rasmus Lerdorf As discussed, add --with-config-file-scan-dir compile-time switch defini...
rlerdorf authored
583 {
584 zval tmp;
9be89ed MFH: ws fixes
Jani Taskinen authored
585
989a61e Rasmus Lerdorf As discussed, add --with-config-file-scan-dir compile-time switch defini...
rlerdorf authored
586 Z_STRLEN(tmp) = strlen(fh.filename);
587 Z_STRVAL(tmp) = zend_strndup(fh.filename, Z_STRLEN(tmp));
588 Z_TYPE(tmp) = IS_STRING;
4b4d634 MFH: Added macros for managing zval refcounts and is_ref statuses
Yiduo (David) Wang authored
589 Z_SET_REFCOUNT(tmp, 0);
09b6f37 MFH:
Jani Taskinen authored
590
989a61e Rasmus Lerdorf As discussed, add --with-config-file-scan-dir compile-time switch defini...
rlerdorf authored
591 zend_hash_update(&configuration_hash, "cfg_file_path", sizeof("cfg_file_path"), (void *) &tmp, sizeof(zval), NULL);
7e3b508 ws/style fixes
foobar authored
592 if (php_ini_opened_path) {
989a61e Rasmus Lerdorf As discussed, add --with-config-file-scan-dir compile-time switch defini...
rlerdorf authored
593 efree(php_ini_opened_path);
7e3b508 ws/style fixes
foobar authored
594 }
989a61e Rasmus Lerdorf As discussed, add --with-config-file-scan-dir compile-time switch defini...
rlerdorf authored
595 php_ini_opened_path = zend_strndup(Z_STRVAL(tmp), Z_STRLEN(tmp));
596 }
cecb9df Implemented -n switch to skip parsing ini at startup as suggested by Wez...
Marcus Boerger authored
597 }
989a61e Rasmus Lerdorf As discussed, add --with-config-file-scan-dir compile-time switch defini...
rlerdorf authored
598
e5e6f55 MFH
Jani Taskinen authored
599 /* Check for PHP_INI_SCAN_DIR environment variable to override/set config file scan directory */
600 php_ini_scanned_path = getenv("PHP_INI_SCAN_DIR");
601 if (!php_ini_scanned_path) {
602 /* Or fall back using possible --with-config-file-scan-dir setting (defaults to empty string!) */
603 php_ini_scanned_path = PHP_CONFIG_FILE_SCAN_DIR;
604 }
605 int php_ini_scanned_path_len = strlen(php_ini_scanned_path);
606
607 /* Scan and parse any .ini files found in scan path if path not empty. */
608 if (!sapi_module.php_ini_ignore && php_ini_scanned_path_len) {
8d352d2 Fixed bug #21625 (When scanning a directory for ini files, do so in
Ilia Alshanetsky authored
609 struct dirent **namelist;
610 int ndir, i;
09b6f37 MFH:
Jani Taskinen authored
611 struct stat sb;
612 char ini_file[MAXPATHLEN];
613 char *p;
614 zend_file_handle fh;
615 zend_llist scanned_ini_list;
616 zend_llist_element *element;
617 int l, total_l = 0;
618
619 /* Reset active ini section */
620 RESET_ACTIVE_INI_HASH();
8d352d2 Fixed bug #21625 (When scanning a directory for ini files, do so in
Ilia Alshanetsky authored
621
e5e6f55 MFH
Jani Taskinen authored
622 if ((ndir = php_scandir(php_ini_scanned_path, &namelist, 0, php_alphasort)) > 0) {
09b6f37 MFH:
Jani Taskinen authored
623 zend_llist_init(&scanned_ini_list, sizeof(char *), (llist_dtor_func_t) free_estring, 1);
624 memset(&fh, 0, sizeof(fh));
625
8d352d2 Fixed bug #21625 (When scanning a directory for ini files, do so in
Ilia Alshanetsky authored
626 for (i = 0; i < ndir; i++) {
09b6f37 MFH:
Jani Taskinen authored
627
628 /* check for any file with .ini extension */
8d352d2 Fixed bug #21625 (When scanning a directory for ini files, do so in
Ilia Alshanetsky authored
629 if (!(p = strrchr(namelist[i]->d_name, '.')) || (p && strcmp(p, ".ini"))) {
630 free(namelist[i]);
d454bec - Whitespace
Derick Rethans authored
631 continue;
632 }
e5e6f55 MFH
Jani Taskinen authored
633 if (IS_SLASH(php_ini_scanned_path[php_ini_scanned_path_len - 1])) {
634 snprintf(ini_file, MAXPATHLEN, "%s%s", php_ini_scanned_path, namelist[i]->d_name);
635 } else {
636 snprintf(ini_file, MAXPATHLEN, "%s%c%s", php_ini_scanned_path, DEFAULT_SLASH, namelist[i]->d_name);
637 }
989a61e Rasmus Lerdorf As discussed, add --with-config-file-scan-dir compile-time switch defini...
rlerdorf authored
638 if (VCWD_STAT(ini_file, &sb) == 0) {
639 if (S_ISREG(sb.st_mode)) {
640 if ((fh.handle.fp = VCWD_FOPEN(ini_file, "r"))) {
641 fh.filename = ini_file;
1ad304c Rasmus Lerdorf MFB config-file-scan-dir crash fix
rlerdorf authored
642 fh.type = ZEND_HANDLE_FP;
09b6f37 MFH:
Jani Taskinen authored
643
644 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) {
645 /* Here, add it to the list of ini files read */
646 l = strlen(ini_file);
647 total_l += l + 2;
648 p = estrndup(ini_file, l);
649 zend_llist_add_element(&scanned_ini_list, &p);
650 }
989a61e Rasmus Lerdorf As discussed, add --with-config-file-scan-dir compile-time switch defini...
rlerdorf authored
651 }
652 }
653 }
8d352d2 Fixed bug #21625 (When scanning a directory for ini files, do so in
Ilia Alshanetsky authored
654 free(namelist[i]);
989a61e Rasmus Lerdorf As discussed, add --with-config-file-scan-dir compile-time switch defini...
rlerdorf authored
655 }
8d352d2 Fixed bug #21625 (When scanning a directory for ini files, do so in
Ilia Alshanetsky authored
656 free(namelist);
657
3781af5 - Fixed zero bytes memory allocation when no extra ini files are found i...
Derick Rethans authored
658 if (total_l) {
09b6f37 MFH:
Jani Taskinen authored
659 int php_ini_scanned_files_len = (php_ini_scanned_files) ? strlen(php_ini_scanned_files) + 1 : 0;
660 php_ini_scanned_files = (char *) realloc(php_ini_scanned_files, php_ini_scanned_files_len + total_l + 1);
661 if (!php_ini_scanned_files_len) {
662 *php_ini_scanned_files = '\0';
663 }
664 total_l += php_ini_scanned_files_len;
3781af5 - Fixed zero bytes memory allocation when no extra ini files are found i...
Derick Rethans authored
665 for (element = scanned_ini_list.head; element; element = element->next) {
09b6f37 MFH:
Jani Taskinen authored
666 if (php_ini_scanned_files_len) {
667 strlcat(php_ini_scanned_files, ",\n", total_l);
668 }
112462d Antony Dovgal MFH
tony2001 authored
669 strlcat(php_ini_scanned_files, *(char **)element->data, total_l);
670 strlcat(php_ini_scanned_files, element->next ? ",\n" : "\n", total_l);
9be89ed MFH: ws fixes
Jani Taskinen authored
671 }
3781af5 - Fixed zero bytes memory allocation when no extra ini files are found i...
Derick Rethans authored
672 }
ac9f4cc - We always need to destroy the llist though.
Derick Rethans authored
673 zend_llist_destroy(&scanned_ini_list);
989a61e Rasmus Lerdorf As discussed, add --with-config-file-scan-dir compile-time switch defini...
rlerdorf authored
674 }
e5e6f55 MFH
Jani Taskinen authored
675 } else {
676 /* Make sure an empty php_ini_scanned_path ends up as NULL */
677 php_ini_scanned_path = NULL;
42c82bb Revert the last patches.
foobar authored
678 }
7d14dad MFH: Fixed mess with CGI/CLI -d command line option (now it works with c...
Dmitry Stogov authored
679
680 if (sapi_module.ini_entries) {
09b6f37 MFH:
Jani Taskinen authored
681 /* Reset active ini section */
682 RESET_ACTIVE_INI_HASH();
683 zend_parse_ini_string(sapi_module.ini_entries, 1, ZEND_INI_SCANNER_NORMAL, (zend_ini_parser_cb_t) php_ini_parser_cb, &configuration_hash TSRMLS_CC);
7d14dad MFH: Fixed mess with CGI/CLI -d command line option (now it works with c...
Dmitry Stogov authored
684 }
685
42c82bb Revert the last patches.
foobar authored
686 return SUCCESS;
78194a4 Zeev Suraski - Complete the move to the new INI parser. (Side effect: at last, peop...
zsuraski authored
687 }
81e2cf0 Rasmus Lerdorf Fix folding and clean up some extensions
rlerdorf authored
688 /* }}} */
78194a4 Zeev Suraski - Complete the move to the new INI parser. (Side effect: at last, peop...
zsuraski authored
689
81e2cf0 Rasmus Lerdorf Fix folding and clean up some extensions
rlerdorf authored
690 /* {{{ php_shutdown_config
691 */
78194a4 Zeev Suraski - Complete the move to the new INI parser. (Side effect: at last, peop...
zsuraski authored
692 int php_shutdown_config(void)
693 {
42c82bb Revert the last patches.
foobar authored
694 zend_hash_destroy(&configuration_hash);
695 if (php_ini_opened_path) {
696 free(php_ini_opened_path);
2a2d49b Fixed bug #30050 (Possible crash inside php_shutdown_config()).
Ilia Alshanetsky authored
697 php_ini_opened_path = NULL;
42c82bb Revert the last patches.
foobar authored
698 }
989a61e Rasmus Lerdorf As discussed, add --with-config-file-scan-dir compile-time switch defini...
rlerdorf authored
699 if (php_ini_scanned_files) {
700 free(php_ini_scanned_files);
2a2d49b Fixed bug #30050 (Possible crash inside php_shutdown_config()).
Ilia Alshanetsky authored
701 php_ini_scanned_files = NULL;
989a61e Rasmus Lerdorf As discussed, add --with-config-file-scan-dir compile-time switch defini...
rlerdorf authored
702 }
42c82bb Revert the last patches.
foobar authored
703 return SUCCESS;
78194a4 Zeev Suraski - Complete the move to the new INI parser. (Side effect: at last, peop...
zsuraski authored
704 }
81e2cf0 Rasmus Lerdorf Fix folding and clean up some extensions
rlerdorf authored
705 /* }}} */
78194a4 Zeev Suraski - Complete the move to the new INI parser. (Side effect: at last, peop...
zsuraski authored
706
f47c784 Improved PHP extension loading mechanism with support for module depende...
Dmitry Stogov authored
707 /* {{{ php_ini_register_extensions
81e2cf0 Rasmus Lerdorf Fix folding and clean up some extensions
rlerdorf authored
708 */
f47c784 Improved PHP extension loading mechanism with support for module depende...
Dmitry Stogov authored
709 void php_ini_register_extensions(TSRMLS_D)
9db5589 Zeev Suraski Recode delayed loading in a much simpler way (switched back to php_ini.c...
zsuraski authored
710 {
42c82bb Revert the last patches.
foobar authored
711 zend_llist_apply(&extension_lists.engine, php_load_zend_extension_cb TSRMLS_CC);
02d966c MFH:- Added support for [HOST=www.example.com] special sections
Jani Taskinen authored
712 zend_llist_apply(&extension_lists.functions, php_load_php_extension_cb TSRMLS_CC);
9db5589 Zeev Suraski Recode delayed loading in a much simpler way (switched back to php_ini.c...
zsuraski authored
713
42c82bb Revert the last patches.
foobar authored
714 zend_llist_destroy(&extension_lists.engine);
715 zend_llist_destroy(&extension_lists.functions);
9db5589 Zeev Suraski Recode delayed loading in a much simpler way (switched back to php_ini.c...
zsuraski authored
716 }
81e2cf0 Rasmus Lerdorf Fix folding and clean up some extensions
rlerdorf authored
717 /* }}} */
9db5589 Zeev Suraski Recode delayed loading in a much simpler way (switched back to php_ini.c...
zsuraski authored
718
09b6f37 MFH:
Jani Taskinen authored
719 /* {{{ php_parse_user_ini_file
720 */
cf7384a Felipe Pena - MFH: Constness (Added const qualifier to several function parameters)
felipensp authored
721 PHPAPI int php_parse_user_ini_file(const char *dirname, char *ini_filename, HashTable *target_hash TSRMLS_DC)
09b6f37 MFH:
Jani Taskinen authored
722 {
723 struct stat sb;
724 char ini_file[MAXPATHLEN];
725 zend_file_handle fh;
726
727 snprintf(ini_file, MAXPATHLEN, "%s%c%s", dirname, DEFAULT_SLASH, ini_filename);
728
729 if (VCWD_STAT(ini_file, &sb) == 0) {
730 if (S_ISREG(sb.st_mode)) {
731 memset(&fh, 0, sizeof(fh));
732 if ((fh.handle.fp = VCWD_FOPEN(ini_file, "r"))) {
733 fh.filename = ini_file;
734 fh.type = ZEND_HANDLE_FP;
735
736 /* Reset active ini section */
737 RESET_ACTIVE_INI_HASH();
738
739 if (zend_parse_ini_file(&fh, 1, ZEND_INI_SCANNER_NORMAL, (zend_ini_parser_cb_t) php_ini_parser_cb, target_hash TSRMLS_CC) == SUCCESS) {
740 /* FIXME: Add parsed file to the list of user files read? */
741 return SUCCESS;
742 }
743 return FAILURE;
744 }
745 }
746 }
747 return FAILURE;
748 }
749 /* }}} */
750
751 /* {{{ php_ini_activate_config
752 */
753 PHPAPI void php_ini_activate_config(HashTable *source_hash, int modify_type, int stage TSRMLS_DC)
754 {
755 char *str;
756 zval *data;
757 uint str_len;
758 ulong num_index;
759
760 /* Walk through config hash and alter matching ini entries using the values found in the hash */
761 for (zend_hash_internal_pointer_reset(source_hash);
762 zend_hash_get_current_key_ex(source_hash, &str, &str_len, &num_index, 0, NULL) == HASH_KEY_IS_STRING;
763 zend_hash_move_forward(source_hash)
764 ) {
765 zend_hash_get_current_data(source_hash, (void **) &data);
766 zend_alter_ini_entry_ex(str, str_len, Z_STRVAL_P(data), Z_STRLEN_P(data), modify_type, stage, 0 TSRMLS_CC);
767 }
768 }
769 /* }}} */
770
ba8e317 Optimized request startup sequence for php.ini without per dir and per h...
Dmitry Stogov authored
771 /* {{{ php_ini_has_per_dir_config
772 */
773 PHPAPI int php_ini_has_per_dir_config(void)
774 {
775 return has_per_dir_config;
776 }
777 /* }}} */
778
09b6f37 MFH:
Jani Taskinen authored
779 /* {{{ php_ini_activate_per_dir_config
780 */
781 PHPAPI void php_ini_activate_per_dir_config(char *path, uint path_len TSRMLS_DC)
782 {
783 zval *tmp;
784 char *ptr;
785
786 /* Walk through each directory in path and apply any found per-dir-system-configuration from configuration_hash */
ba8e317 Optimized request startup sequence for php.ini without per dir and per h...
Dmitry Stogov authored
787 if (has_per_dir_config && path && path_len) {
09b6f37 MFH:
Jani Taskinen authored
788 ptr = path + 1;
789 while ((ptr = strchr(ptr, DEFAULT_SLASH)) != NULL) {
790 *ptr = 0;
791 /* Search for source array matching the path from configuration_hash */
792 if (zend_hash_find(&configuration_hash, path, path_len, (void **) &tmp) == SUCCESS) {
793 php_ini_activate_config(Z_ARRVAL_P(tmp), PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE TSRMLS_CC);
794 }
795 *ptr = '/';
796 ptr++;
797 }
798 }
799 }
800 /* }}} */
801
ba8e317 Optimized request startup sequence for php.ini without per dir and per h...
Dmitry Stogov authored
802 /* {{{ php_ini_has_per_host_config
803 */
804 PHPAPI int php_ini_has_per_host_config(void)
805 {
806 return has_per_host_config;
807 }
808 /* }}} */
809
02d966c MFH:- Added support for [HOST=www.example.com] special sections
Jani Taskinen authored
810 /* {{{ php_ini_activate_per_host_config
811 */
cf7384a Felipe Pena - MFH: Constness (Added const qualifier to several function parameters)
felipensp authored
812 PHPAPI void php_ini_activate_per_host_config(const char *host, uint host_len TSRMLS_DC)
02d966c MFH:- Added support for [HOST=www.example.com] special sections
Jani Taskinen authored
813 {
814 zval *tmp;
815
ba8e317 Optimized request startup sequence for php.ini without per dir and per h...
Dmitry Stogov authored
816 if (has_per_host_config && host && host_len) {
02d966c MFH:- Added support for [HOST=www.example.com] special sections
Jani Taskinen authored
817 /* Search for source array matching the host from configuration_hash */
818 if (zend_hash_find(&configuration_hash, host, host_len, (void **) &tmp) == SUCCESS) {
819 php_ini_activate_config(Z_ARRVAL_P(tmp), PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE TSRMLS_CC);
820 }
821 }
822 }
823 /* }}} */
824
81e2cf0 Rasmus Lerdorf Fix folding and clean up some extensions
rlerdorf authored
825 /* {{{ cfg_get_entry
826 */
cf7384a Felipe Pena - MFH: Constness (Added const qualifier to several function parameters)
felipensp authored
827 PHPAPI zval *cfg_get_entry(const char *name, uint name_length)
78194a4 Zeev Suraski - Complete the move to the new INI parser. (Side effect: at last, peop...
zsuraski authored
828 {
42c82bb Revert the last patches.
foobar authored
829 zval *tmp;
78194a4 Zeev Suraski - Complete the move to the new INI parser. (Side effect: at last, peop...
zsuraski authored
830
7e3b508 ws/style fixes
foobar authored
831 if (zend_hash_find(&configuration_hash, name, name_length, (void **) &tmp) == SUCCESS) {
42c82bb Revert the last patches.
foobar authored
832 return tmp;
833 } else {
834 return NULL;
835 }
78194a4 Zeev Suraski - Complete the move to the new INI parser. (Side effect: at last, peop...
zsuraski authored
836 }
81e2cf0 Rasmus Lerdorf Fix folding and clean up some extensions
rlerdorf authored
837 /* }}} */
78194a4 Zeev Suraski - Complete the move to the new INI parser. (Side effect: at last, peop...
zsuraski authored
838
81e2cf0 Rasmus Lerdorf Fix folding and clean up some extensions
rlerdorf authored
839 /* {{{ cfg_get_long
840 */
cf7384a Felipe Pena - MFH: Constness (Added const qualifier to several function parameters)
felipensp authored
841 PHPAPI int cfg_get_long(const char *varname, long *result)
78194a4 Zeev Suraski - Complete the move to the new INI parser. (Side effect: at last, peop...
zsuraski authored
842 {
42c82bb Revert the last patches.
foobar authored
843 zval *tmp, var;
b9ddb5c MFH
Jani Taskinen authored
844
7e3b508 ws/style fixes
foobar authored
845 if (zend_hash_find(&configuration_hash, varname, strlen(varname) + 1, (void **) &tmp) == FAILURE) {
e1814f0 WIN64 support
Dmitry Stogov authored
846 *result = 0;
42c82bb Revert the last patches.
foobar authored
847 return FAILURE;
848 }
849 var = *tmp;
850 zval_copy_ctor(&var);
851 convert_to_long(&var);
852 *result = Z_LVAL(var);
853 return SUCCESS;
78194a4 Zeev Suraski - Complete the move to the new INI parser. (Side effect: at last, peop...
zsuraski authored
854 }
81e2cf0 Rasmus Lerdorf Fix folding and clean up some extensions
rlerdorf authored
855 /* }}} */
78194a4 Zeev Suraski - Complete the move to the new INI parser. (Side effect: at last, peop...
zsuraski authored
856
81e2cf0 Rasmus Lerdorf Fix folding and clean up some extensions
rlerdorf authored
857 /* {{{ cfg_get_double
858 */
cf7384a Felipe Pena - MFH: Constness (Added const qualifier to several function parameters)
felipensp authored
859 PHPAPI int cfg_get_double(const char *varname, double *result)
78194a4 Zeev Suraski - Complete the move to the new INI parser. (Side effect: at last, peop...
zsuraski authored
860 {
42c82bb Revert the last patches.
foobar authored
861 zval *tmp, var;
b9ddb5c MFH
Jani Taskinen authored
862
7e3b508 ws/style fixes
foobar authored
863 if (zend_hash_find(&configuration_hash, varname, strlen(varname) + 1, (void **) &tmp) == FAILURE) {
864 *result = (double) 0;
42c82bb Revert the last patches.
foobar authored
865 return FAILURE;
866 }
867 var = *tmp;
868 zval_copy_ctor(&var);
869 convert_to_double(&var);
870 *result = Z_DVAL(var);
871 return SUCCESS;
78194a4 Zeev Suraski - Complete the move to the new INI parser. (Side effect: at last, peop...
zsuraski authored
872 }
81e2cf0 Rasmus Lerdorf Fix folding and clean up some extensions
rlerdorf authored
873 /* }}} */
78194a4 Zeev Suraski - Complete the move to the new INI parser. (Side effect: at last, peop...
zsuraski authored
874
81e2cf0 Rasmus Lerdorf Fix folding and clean up some extensions
rlerdorf authored
875 /* {{{ cfg_get_string
876 */
cf7384a Felipe Pena - MFH: Constness (Added const qualifier to several function parameters)
felipensp authored
877 PHPAPI int cfg_get_string(const char *varname, char **result)
78194a4 Zeev Suraski - Complete the move to the new INI parser. (Side effect: at last, peop...
zsuraski authored
878 {
42c82bb Revert the last patches.
foobar authored
879 zval *tmp;
880
7e3b508 ws/style fixes
foobar authored
881 if (zend_hash_find(&configuration_hash, varname, strlen(varname)+1, (void **) &tmp) == FAILURE) {
882 *result = NULL;
42c82bb Revert the last patches.
foobar authored
883 return FAILURE;
884 }
885 *result = Z_STRVAL_P(tmp);
886 return SUCCESS;
78194a4 Zeev Suraski - Complete the move to the new INI parser. (Side effect: at last, peop...
zsuraski authored
887 }
81e2cf0 Rasmus Lerdorf Fix folding and clean up some extensions
rlerdorf authored
888 /* }}} */
2cf1b8d * expanded the following constants and made them available in PHP:
Stig Bakken authored
889
fa94dab - MFH Rename dump_config_hash() to get_config_hash() as it doesn't dump
Marcus Boerger authored
890 PHPAPI HashTable* php_ini_get_configuration_hash(void) /* {{{ */
09b6f37 MFH:
Jani Taskinen authored
891 {
fa94dab - MFH Rename dump_config_hash() to get_config_hash() as it doesn't dump
Marcus Boerger authored
892 return &configuration_hash;
893 } /* }}} */
09b6f37 MFH:
Jani Taskinen authored
894
2cf1b8d * expanded the following constants and made them available in PHP:
Stig Bakken authored
895 /*
896 * Local variables:
897 * tab-width: 4
898 * c-basic-offset: 4
899 * indent-tabs-mode: t
900 * End:
78747bd - Don't wrap lines... this is annoying while coding.
Derick Rethans authored
901 * vim600: sw=4 ts=4 fdm=marker
902 * vim<600: sw=4 ts=4
2cf1b8d * expanded the following constants and made them available in PHP:
Stig Bakken authored
903 */
Something went wrong with that request. Please try again.