Skip to content

HTTPS clone URL

Subversion checkout URL

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