1 : /*
2 : +----------------------------------------------------------------------+
3 : | PHP Version 6 |
4 : +----------------------------------------------------------------------+
5 : | Copyright (c) 1997-2009 The PHP Group |
6 : +----------------------------------------------------------------------+
7 : | This source file is subject to version 3.01 of the PHP license, |
8 : | that is bundled with this package in the file LICENSE, and is |
9 : | available through the world-wide-web at the following url: |
10 : | http://www.php.net/license/3_01.txt |
11 : | If you did not receive a copy of the PHP license and are unable to |
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. |
14 : +----------------------------------------------------------------------+
15 : | Authors: Andi Gutmans <andi@zend.com> |
16 : | Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
17 : | Zeev Suraski <zeev@zend.com> |
18 : +----------------------------------------------------------------------+
19 : */
20 :
21 : /* $Id: main.c 290768 2009-11-15 00:31:42Z jani $ */
22 :
23 : /* {{{ includes
24 : */
25 :
26 : #define ZEND_INCLUDE_FULL_WINDOWS_HEADERS
27 :
28 : #include "php.h"
29 : #include <stdio.h>
30 : #include <fcntl.h>
31 : #ifdef PHP_WIN32
32 : #include "win32/time.h"
33 : #include "win32/signal.h"
34 : #include "win32/php_win32_globals.h"
35 : #include <process.h>
36 : #elif defined(NETWARE)
37 : #include <sys/timeval.h>
38 : #ifdef USE_WINSOCK
39 : #include <novsock2.h>
40 : #endif
41 : #endif
42 : #if HAVE_SYS_TIME_H
43 : #include <sys/time.h>
44 : #endif
45 : #if HAVE_UNISTD_H
46 : #include <unistd.h>
47 : #endif
48 : #if HAVE_SIGNAL_H
49 : #include <signal.h>
50 : #endif
51 : #if HAVE_SETLOCALE
52 : #include <locale.h>
53 : #endif
54 : #include "zend.h"
55 : #include "zend_extensions.h"
56 : #include "php_ini.h"
57 : #include "php_globals.h"
58 : #include "php_main.h"
59 : #include "fopen_wrappers.h"
60 : #include "ext/standard/php_standard.h"
61 : #include "ext/standard/php_string.h"
62 : #include "ext/date/php_date.h"
63 : #include "php_variables.h"
64 : #include "ext/standard/credits.h"
65 : #ifdef PHP_WIN32
66 : #include <io.h>
67 : #include "win32/php_registry.h"
68 : #include "ext/standard/flock_compat.h"
69 : #endif
70 : #include "php_syslog.h"
71 : #include "Zend/zend_exceptions.h"
72 :
73 : #if PHP_SIGCHILD
74 : #include <sys/types.h>
75 : #include <sys/wait.h>
76 : #endif
77 :
78 : #include "zend_compile.h"
79 : #include "zend_execute.h"
80 : #include "zend_highlight.h"
81 : #include "zend_indent.h"
82 : #include "zend_extensions.h"
83 : #include "zend_ini.h"
84 : #include "zend_dtrace.h"
85 :
86 : #include "php_content_types.h"
87 : #include "php_ticks.h"
88 : #include "php_logos.h"
89 : #include "php_streams.h"
90 : #include "php_open_temporary_file.h"
91 :
92 : #include "SAPI.h"
93 : #include "rfc1867.h"
94 :
95 : #if HAVE_SYS_MMAN_H
96 : # include <sys/mman.h>
97 : # ifndef PAGE_SIZE
98 : # define PAGE_SIZE 4096
99 : # endif
100 : #endif
101 : #ifdef PHP_WIN32
102 : # define PAGE_SIZE 4096
103 : #endif
104 : /* }}} */
105 :
106 : PHPAPI int (*php_register_internal_extensions_func)(TSRMLS_D) = php_register_internal_extensions;
107 :
108 : #ifndef ZTS
109 : php_core_globals core_globals;
110 : #else
111 : PHPAPI int core_globals_id;
112 : #endif
113 :
114 : #ifdef PHP_WIN32
115 : #include "win32_internal_function_disabled.h"
116 :
117 : static php_win32_disable_functions() {
118 : int i;
119 : TSRMLS_FETCH();
120 :
121 : if (EG(windows_version_info).dwMajorVersion < 5) {
122 : for (i = 0; i < function_name_cnt_5; i++) {
123 : if (zend_hash_del(CG(function_table), function_name_5[i], strlen(function_name_5[i]) + 1)==FAILURE) {
124 : php_printf("Unable to disable function '%s'\n", function_name_5[i]);
125 : return FAILURE;
126 : }
127 : }
128 : }
129 :
130 : if (EG(windows_version_info).dwMajorVersion < 6) {
131 : for (i = 0; i < function_name_cnt_6; i++) {
132 : if (zend_hash_del(CG(function_table), function_name_6[i], strlen(function_name_6[i]) + 1)==FAILURE) {
133 : php_printf("Unable to disable function '%s'\n", function_name_6[i]);
134 : return FAILURE;
135 : }
136 : }
137 : }
138 : return SUCCESS;
139 : }
140 : #endif
141 :
142 : #define SAFE_FILENAME(f) ((f)?(f):"-")
143 :
144 : /* {{{ PHP_INI_MH
145 : */
146 : static PHP_INI_MH(OnSetPrecision)
147 17009 : {
148 17009 : int i = atoi(new_value);
149 17009 : if (i >= 0) {
150 17009 : EG(precision) = i;
151 17009 : return SUCCESS;
152 : } else {
153 0 : return FAILURE;
154 : }
155 : }
156 : /* }}} */
157 :
158 : /* {{{ PHP_INI_MH
159 : */
160 : static PHP_INI_MH(OnChangeMemoryLimit)
161 17013 : {
162 17013 : if (new_value) {
163 17013 : PG(memory_limit) = zend_atol(new_value, new_value_length);
164 : } else {
165 0 : PG(memory_limit) = 1<<30; /* effectively, no limit */
166 : }
167 17013 : return zend_set_memory_limit(PG(memory_limit));
168 : }
169 : /* }}} */
170 :
171 : /* {{{ php_disable_functions
172 : */
173 : static void php_disable_functions(TSRMLS_D)
174 17007 : {
175 17007 : char *s = NULL, *e;
176 :
177 17007 : if (!*(INI_STR("disable_functions"))) {
178 17004 : return;
179 : }
180 :
181 3 : e = PG(disable_functions) = strdup(INI_STR("disable_functions"));
182 :
183 27 : while (*e) {
184 21 : switch (*e) {
185 : case ' ':
186 : case ',':
187 0 : if (s) {
188 0 : *e = '\0';
189 0 : zend_disable_function(s, e-s TSRMLS_CC);
190 0 : s = NULL;
191 : }
192 0 : break;
193 : default:
194 21 : if (!s) {
195 3 : s = e;
196 : }
197 : break;
198 : }
199 21 : e++;
200 : }
201 3 : if (s) {
202 3 : zend_disable_function(s, e-s TSRMLS_CC);
203 : }
204 : }
205 : /* }}} */
206 :
207 : /* {{{ php_disable_classes
208 : */
209 : static void php_disable_classes(TSRMLS_D)
210 17007 : {
211 17007 : char *s = NULL, *e;
212 :
213 17007 : if (!*(INI_STR("disable_classes"))) {
214 17006 : return;
215 : }
216 :
217 1 : e = PG(disable_classes) = strdup(INI_STR("disable_classes"));
218 :
219 10 : while (*e) {
220 8 : switch (*e) {
221 : case ' ':
222 : case ',':
223 0 : if (s) {
224 0 : *e = '\0';
225 0 : zend_disable_class(s, e-s TSRMLS_CC);
226 0 : s = NULL;
227 : }
228 0 : break;
229 : default:
230 8 : if (!s) {
231 1 : s = e;
232 : }
233 : break;
234 : }
235 8 : e++;
236 : }
237 1 : if (s) {
238 1 : zend_disable_class(s, e-s TSRMLS_CC);
239 : }
240 : }
241 : /* }}} */
242 :
243 : /* {{{ PHP_INI_MH
244 : */
245 : static PHP_INI_MH(OnUpdateTimeout)
246 17039 : {
247 17039 : if (stage==PHP_INI_STAGE_STARTUP) {
248 : /* Don't set a timeout on startup, only per-request */
249 17007 : EG(timeout_seconds) = atoi(new_value);
250 17007 : return SUCCESS;
251 : }
252 32 : zend_unset_timeout(TSRMLS_C);
253 32 : EG(timeout_seconds) = atoi(new_value);
254 32 : zend_set_timeout(EG(timeout_seconds), 0);
255 32 : return SUCCESS;
256 : }
257 : /* }}} */
258 :
259 : /* {{{ PHP_INI_MH
260 : */
261 : static ZEND_INI_MH(OnUpdateOutputEncoding)
262 17007 : {
263 17007 : if (new_value) {
264 16884 : if (zend_set_converter_encoding(&UG(output_encoding_conv), new_value) == FAILURE) {
265 0 : zend_error(E_CORE_ERROR, "Unrecognized encoding '%s' used for %s", new_value ? new_value : "null", entry->name);
266 0 : return FAILURE;
267 : }
268 : } else {
269 123 : if (UG(output_encoding_conv)) {
270 0 : ucnv_close(UG(output_encoding_conv));
271 : }
272 123 : UG(output_encoding_conv) = NULL;
273 : }
274 17007 : if (UG(output_encoding_conv)) {
275 16884 : zend_set_converter_error_mode(UG(output_encoding_conv), ZEND_FROM_UNICODE, UG(from_error_mode));
276 16884 : zend_set_converter_subst_char(UG(output_encoding_conv), UG(from_subst_char));
277 16884 : if (stage == ZEND_INI_STAGE_RUNTIME) {
278 0 : sapi_update_default_charset(TSRMLS_C);
279 : }
280 : }
281 :
282 17007 : return SUCCESS;
283 : }
284 : /* }}} */
285 :
286 : #define PHP_INI_OPTION_HEADERS_SENT(option_name) \
287 : if (SG(headers_sent)) { \
288 : char *output_start_filename = php_output_get_start_filename(TSRMLS_C); \
289 : int output_start_lineno = php_output_get_start_lineno(TSRMLS_C); \
290 : if (output_start_filename) { \
291 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Option " #option_name " cannot be changed after headers have been sent (output started at %s:%d)", \
292 : output_start_filename, output_start_lineno); \
293 : } else { \
294 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Option " #option_name " cannot be changed after headers have been sent"); \
295 : } \
296 : return FAILURE; \
297 : }
298 :
299 : /* {{{ PHP_INI_MH
300 : */
301 : static PHP_INI_MH(OnUpdateDefaultCharset)
302 17007 : {
303 17007 : if (stage == PHP_INI_STAGE_RUNTIME && !SG(request_info).no_headers) {
304 0 : sapi_header_line ctr = {0};
305 : int mimetype_len;
306 :
307 0 : PHP_INI_OPTION_HEADERS_SENT(default_charset)
308 :
309 0 : mimetype_len = SG(default_mimetype) ? strlen(SG(default_mimetype)) : 0;
310 :
311 0 : if (new_value_length) {
312 0 : ctr.line = emalloc( sizeof("Content-type: ")-1 + mimetype_len + sizeof("; charset=")-1 + new_value_length + 1);
313 :
314 0 : memcpy(ctr.line, "Content-type: ", sizeof("Content-type: "));
315 0 : memcpy(ctr.line + sizeof("Content-type: ")-1, SG(default_mimetype), mimetype_len);
316 0 : memcpy(ctr.line + sizeof("Content-type: ")-1 + mimetype_len, "; charset=", sizeof("; charset="));
317 0 : memcpy(ctr.line + sizeof("Content-type: ")-1 + mimetype_len + sizeof("; charset=")-1, new_value, new_value_length);
318 :
319 0 : ctr.line_len = sizeof("Content-type: ")-1 + mimetype_len + sizeof("; charset=")-1 + new_value_length;
320 : } else {
321 0 : ctr.line = emalloc( sizeof("Content-type: ")-1 + mimetype_len + 1);
322 :
323 0 : memcpy(ctr.line, "Content-type: ", sizeof("Content-type: "));
324 0 : memcpy(ctr.line + sizeof("Content-type: ")-1, SG(default_mimetype), mimetype_len);
325 :
326 0 : ctr.line_len = sizeof("Content-type: ")-1 + mimetype_len;
327 : }
328 0 : ctr.line[ctr.line_len] = 0;
329 :
330 0 : sapi_header_op(SAPI_HEADER_REPLACE, &ctr TSRMLS_CC);
331 0 : efree(ctr.line);
332 : }
333 :
334 17007 : OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
335 17007 : return SUCCESS;
336 : }
337 : /* }}} */
338 :
339 : /* {{{ PHP_INI_MH
340 : */
341 : static PHP_INI_MH(OnUpdateDefaultMimetype)
342 17007 : {
343 17007 : if (stage == PHP_INI_STAGE_RUNTIME && !SG(request_info).no_headers) {
344 0 : sapi_header_line ctr = {0};
345 : int charset_len;
346 :
347 0 : PHP_INI_OPTION_HEADERS_SENT(default_mimetype)
348 :
349 0 : charset_len = SG(default_charset) ? strlen(SG(default_charset)) : 0;
350 :
351 0 : if (charset_len) {
352 0 : ctr.line = emalloc( sizeof("Content-type: ")-1 + new_value_length + sizeof("; charset=")-1 + charset_len + 1);
353 :
354 0 : memcpy(ctr.line, "Content-type: ", sizeof("Content-type: "));
355 0 : memcpy(ctr.line + sizeof("Content-type: ")-1, new_value, new_value_length);
356 0 : memcpy(ctr.line + sizeof("Content-type: ")-1 + new_value_length, "; charset=", sizeof("; charset="));
357 0 : memcpy(ctr.line + sizeof("Content-type: ")-1 + new_value_length + sizeof("; charset=")-1, SG(default_charset), charset_len);
358 :
359 0 : ctr.line_len = sizeof("Content-type: ")-1 + new_value_length + sizeof("; charset=")-1 + new_value_length;
360 : } else {
361 0 : ctr.line = emalloc( sizeof("Content-type: ")-1 + new_value_length + 1);
362 :
363 0 : memcpy(ctr.line, "Content-type: ", sizeof("Content-type: "));
364 0 : memcpy(ctr.line + sizeof("Content-type: ")-1, new_value, new_value_length);
365 :
366 0 : ctr.line_len = sizeof("Content-type: ")-1 + new_value_length;
367 : }
368 0 : ctr.line[ctr.line_len] = 0;
369 :
370 0 : sapi_header_op(SAPI_HEADER_REPLACE, &ctr TSRMLS_CC);
371 0 : efree(ctr.line);
372 : }
373 :
374 17007 : OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
375 17007 : return SUCCESS;
376 : }
377 : /* }}} */
378 :
379 : /* {{{ php_get_display_errors_mode() helper function
380 : */
381 : static int php_get_display_errors_mode(char *value, int value_length)
382 17105 : {
383 : int mode;
384 :
385 17105 : if (!value) {
386 0 : return PHP_DISPLAY_ERRORS_STDOUT;
387 : }
388 :
389 17106 : if (value_length == 2 && !strcasecmp("on", value)) {
390 1 : mode = PHP_DISPLAY_ERRORS_STDOUT;
391 17104 : } else if (value_length == 3 && !strcasecmp("yes", value)) {
392 0 : mode = PHP_DISPLAY_ERRORS_STDOUT;
393 17104 : } else if (value_length == 4 && !strcasecmp("true", value)) {
394 0 : mode = PHP_DISPLAY_ERRORS_STDOUT;
395 17105 : } else if (value_length == 6 && !strcasecmp(value, "stderr")) {
396 1 : mode = PHP_DISPLAY_ERRORS_STDERR;
397 17105 : } else if (value_length == 6 && !strcasecmp(value, "stdout")) {
398 2 : mode = PHP_DISPLAY_ERRORS_STDOUT;
399 : } else {
400 17101 : mode = atoi(value);
401 17101 : if (mode && mode != PHP_DISPLAY_ERRORS_STDOUT && mode != PHP_DISPLAY_ERRORS_STDERR) {
402 0 : mode = PHP_DISPLAY_ERRORS_STDOUT;
403 : }
404 : }
405 17105 : return mode;
406 : }
407 : /* }}} */
408 :
409 : /* {{{ PHP_INI_MH
410 : */
411 : static PHP_INI_MH(OnUpdateDisplayErrors)
412 17019 : {
413 17019 : PG(display_errors) = (zend_bool) php_get_display_errors_mode(new_value, new_value_length);
414 :
415 17019 : return SUCCESS;
416 : }
417 : /* }}} */
418 :
419 : /* {{{ PHP_INI_DISP
420 : */
421 : static PHP_INI_DISP(display_errors_mode)
422 86 : {
423 : int mode, tmp_value_length, cgi_or_cli;
424 : char *tmp_value;
425 : TSRMLS_FETCH();
426 :
427 86 : if (type == ZEND_INI_DISPLAY_ORIG && ini_entry->modified) {
428 0 : tmp_value = (ini_entry->orig_value ? ini_entry->orig_value : NULL );
429 0 : tmp_value_length = ini_entry->orig_value_length;
430 86 : } else if (ini_entry->value) {
431 86 : tmp_value = ini_entry->value;
432 86 : tmp_value_length = ini_entry->value_length;
433 : } else {
434 0 : tmp_value = NULL;
435 0 : tmp_value_length = 0;
436 : }
437 :
438 86 : mode = php_get_display_errors_mode(tmp_value, tmp_value_length);
439 :
440 : /* Display 'On' for other SAPIs instead of STDOUT or STDERR */
441 86 : cgi_or_cli = (!strcmp(sapi_module.name, "cli") || !strcmp(sapi_module.name, "cgi"));
442 :
443 86 : switch (mode) {
444 : case PHP_DISPLAY_ERRORS_STDERR:
445 0 : if (cgi_or_cli ) {
446 0 : PUTS("STDERR");
447 : } else {
448 0 : PUTS("On");
449 : }
450 0 : break;
451 :
452 : case PHP_DISPLAY_ERRORS_STDOUT:
453 86 : if (cgi_or_cli ) {
454 84 : PUTS("STDOUT");
455 : } else {
456 2 : PUTS("On");
457 : }
458 86 : break;
459 :
460 : default:
461 0 : PUTS("Off");
462 : break;
463 : }
464 86 : }
465 : /* }}} */
466 :
467 : /* {{{ PHP_INI_MH
468 : */
469 : static PHP_INI_MH(OnUpdateErrorLog)
470 17010 : {
471 : /* Only do the safemode/open_basedir check at runtime */
472 17010 : if ((stage == PHP_INI_STAGE_RUNTIME || stage == PHP_INI_STAGE_HTACCESS) && new_value && strcmp(new_value, "syslog")) {
473 2 : if (PG(open_basedir) && php_check_open_basedir(new_value TSRMLS_CC)) {
474 0 : return FAILURE;
475 : }
476 : }
477 17010 : OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
478 17010 : return SUCCESS;
479 : }
480 : /* }}} */
481 :
482 : /* {{{ PHP_INI_MH
483 : */
484 : static PHP_INI_MH(OnUpdateMailLog)
485 17007 : {
486 : /* Only do the safemode/open_basedir check at runtime */
487 17007 : if ((stage == PHP_INI_STAGE_RUNTIME || stage == PHP_INI_STAGE_HTACCESS) && new_value) {
488 0 : if (PG(open_basedir) && php_check_open_basedir(new_value TSRMLS_CC)) {
489 0 : return FAILURE;
490 : }
491 : }
492 17007 : OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
493 17007 : return SUCCESS;
494 : }
495 : /* }}} */
496 :
497 :
498 : /* {{{ PHP_INI_MH
499 : */
500 : static PHP_INI_MH(OnChangeMailForceExtra)
501 17007 : {
502 : /* Don't allow changing it in htaccess */
503 17007 : if (stage == PHP_INI_STAGE_HTACCESS) {
504 0 : return FAILURE;
505 : }
506 17007 : return SUCCESS;
507 : }
508 : /* }}} */
509 :
510 : /*
511 : * Need to be read from the environment (?):
512 : * PHP_AUTO_PREPEND_FILE
513 : * PHP_AUTO_APPEND_FILE
514 : * PHP_DOCUMENT_ROOT
515 : * PHP_USER_DIR
516 : * PHP_INCLUDE_PATH
517 : */
518 :
519 : /* Windows and Netware use the internal mail */
520 : #if defined(PHP_WIN32) || defined(NETWARE)
521 : # define DEFAULT_SENDMAIL_PATH NULL
522 : #elif defined(PHP_PROG_SENDMAIL)
523 : # define DEFAULT_SENDMAIL_PATH PHP_PROG_SENDMAIL " -t -i "
524 : #else
525 : # define DEFAULT_SENDMAIL_PATH "/usr/sbin/sendmail -t -i"
526 : #endif
527 :
528 : /* {{{ PHP_INI
529 : */
530 : PHP_INI_BEGIN()
531 : PHP_INI_ENTRY_EX("highlight.comment", HL_COMMENT_COLOR, PHP_INI_ALL, NULL, php_ini_color_displayer_cb)
532 : PHP_INI_ENTRY_EX("highlight.default", HL_DEFAULT_COLOR, PHP_INI_ALL, NULL, php_ini_color_displayer_cb)
533 : PHP_INI_ENTRY_EX("highlight.html", HL_HTML_COLOR, PHP_INI_ALL, NULL, php_ini_color_displayer_cb)
534 : PHP_INI_ENTRY_EX("highlight.keyword", HL_KEYWORD_COLOR, PHP_INI_ALL, NULL, php_ini_color_displayer_cb)
535 : PHP_INI_ENTRY_EX("highlight.string", HL_STRING_COLOR, PHP_INI_ALL, NULL, php_ini_color_displayer_cb)
536 :
537 : STD_PHP_INI_BOOLEAN("asp_tags", "0", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateBool, asp_tags, zend_compiler_globals, compiler_globals)
538 : STD_PHP_INI_ENTRY_EX("display_errors", "1", PHP_INI_ALL, OnUpdateDisplayErrors, display_errors, php_core_globals, core_globals, display_errors_mode)
539 : STD_PHP_INI_BOOLEAN("display_startup_errors", "0", PHP_INI_ALL, OnUpdateBool, display_startup_errors, php_core_globals, core_globals)
540 : STD_PHP_INI_BOOLEAN("expose_php", "1", PHP_INI_SYSTEM, OnUpdateBool, expose_php, php_core_globals, core_globals)
541 : STD_PHP_INI_ENTRY("docref_root", "", PHP_INI_ALL, OnUpdateString, docref_root, php_core_globals, core_globals)
542 : STD_PHP_INI_ENTRY("docref_ext", "", PHP_INI_ALL, OnUpdateString, docref_ext, php_core_globals, core_globals)
543 : STD_PHP_INI_BOOLEAN("html_errors", "1", PHP_INI_ALL, OnUpdateBool, html_errors, php_core_globals, core_globals)
544 : STD_PHP_INI_BOOLEAN("xmlrpc_errors", "0", PHP_INI_SYSTEM, OnUpdateBool, xmlrpc_errors, php_core_globals, core_globals)
545 : STD_PHP_INI_ENTRY("xmlrpc_error_number", "0", PHP_INI_ALL, OnUpdateLong, xmlrpc_error_number, php_core_globals, core_globals)
546 : STD_PHP_INI_ENTRY("max_input_time", "-1", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateLong, max_input_time, php_core_globals, core_globals)
547 : STD_PHP_INI_BOOLEAN("ignore_user_abort", "0", PHP_INI_ALL, OnUpdateBool, ignore_user_abort, php_core_globals, core_globals)
548 : STD_PHP_INI_BOOLEAN("implicit_flush", "0", PHP_INI_ALL, OnUpdateBool, implicit_flush, php_core_globals, core_globals)
549 : STD_PHP_INI_BOOLEAN("log_errors", "0", PHP_INI_ALL, OnUpdateBool, log_errors, php_core_globals, core_globals)
550 : STD_PHP_INI_ENTRY("log_errors_max_len", "1024", PHP_INI_ALL, OnUpdateLong, log_errors_max_len, php_core_globals, core_globals)
551 : STD_PHP_INI_BOOLEAN("ignore_repeated_errors", "0", PHP_INI_ALL, OnUpdateBool, ignore_repeated_errors, php_core_globals, core_globals)
552 : STD_PHP_INI_BOOLEAN("ignore_repeated_source", "0", PHP_INI_ALL, OnUpdateBool, ignore_repeated_source, php_core_globals, core_globals)
553 : STD_PHP_INI_BOOLEAN("report_memleaks", "1", PHP_INI_ALL, OnUpdateBool, report_memleaks, php_core_globals, core_globals)
554 : STD_PHP_INI_BOOLEAN("report_zend_debug", "1", PHP_INI_ALL, OnUpdateBool, report_zend_debug, php_core_globals, core_globals)
555 : STD_PHP_INI_ENTRY("output_buffering", "0", PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateLong, output_buffering, php_core_globals, core_globals)
556 : STD_PHP_INI_ENTRY("output_handler", NULL, PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateString, output_handler, php_core_globals, core_globals)
557 : STD_PHP_INI_BOOLEAN("register_argc_argv", "1", PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateBool, register_argc_argv, php_core_globals, core_globals)
558 : STD_PHP_INI_BOOLEAN("auto_globals_jit", "1", PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateBool, auto_globals_jit, php_core_globals, core_globals)
559 : STD_PHP_INI_BOOLEAN("short_open_tag", DEFAULT_SHORT_OPEN_TAG, PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateBool, short_tags, zend_compiler_globals, compiler_globals)
560 : STD_PHP_INI_BOOLEAN("sql.safe_mode", "0", PHP_INI_SYSTEM, OnUpdateBool, sql_safe_mode, php_core_globals, core_globals)
561 : STD_PHP_INI_BOOLEAN("track_errors", "0", PHP_INI_ALL, OnUpdateBool, track_errors, php_core_globals, core_globals)
562 : STD_PHP_INI_BOOLEAN("y2k_compliance", "1", PHP_INI_ALL, OnUpdateBool, y2k_compliance, php_core_globals, core_globals)
563 :
564 : STD_PHP_INI_ENTRY("unserialize_callback_func", NULL, PHP_INI_ALL, OnUpdateString, unserialize_callback_func, php_core_globals, core_globals)
565 : STD_PHP_INI_ENTRY("serialize_precision", "100", PHP_INI_ALL, OnUpdateLongGEZero, serialize_precision, php_core_globals, core_globals)
566 : STD_PHP_INI_ENTRY("arg_separator.output", "&", PHP_INI_ALL, OnUpdateStringUnempty, arg_separator.output, php_core_globals, core_globals)
567 : STD_PHP_INI_ENTRY("arg_separator.input", "&", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateStringUnempty, arg_separator.input, php_core_globals, core_globals)
568 :
569 : STD_PHP_INI_ENTRY("auto_append_file", NULL, PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateString, auto_append_file, php_core_globals, core_globals)
570 : STD_PHP_INI_ENTRY("auto_prepend_file", NULL, PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateString, auto_prepend_file, php_core_globals, core_globals)
571 : STD_PHP_INI_ENTRY("doc_root", NULL, PHP_INI_SYSTEM, OnUpdateStringUnempty, doc_root, php_core_globals, core_globals)
572 : STD_PHP_INI_ENTRY("default_charset", SAPI_DEFAULT_CHARSET, PHP_INI_ALL, OnUpdateDefaultCharset, default_charset, sapi_globals_struct,sapi_globals)
573 : STD_PHP_INI_ENTRY("default_mimetype", SAPI_DEFAULT_MIMETYPE, PHP_INI_ALL, OnUpdateDefaultMimetype, default_mimetype, sapi_globals_struct,sapi_globals)
574 : ZEND_INI_ENTRY("unicode.output_encoding", NULL, ZEND_INI_ALL, OnUpdateOutputEncoding)
575 : STD_PHP_INI_ENTRY("error_log", NULL, PHP_INI_ALL, OnUpdateErrorLog, error_log, php_core_globals, core_globals)
576 : STD_PHP_INI_ENTRY("extension_dir", PHP_EXTENSION_DIR, PHP_INI_SYSTEM, OnUpdateStringUnempty, extension_dir, php_core_globals, core_globals)
577 : STD_PHP_INI_ENTRY("include_path", PHP_INCLUDE_PATH, PHP_INI_ALL, OnUpdateStringUnempty, include_path, php_core_globals, core_globals)
578 : PHP_INI_ENTRY("max_execution_time", "30", PHP_INI_ALL, OnUpdateTimeout)
579 : STD_PHP_INI_ENTRY("open_basedir", NULL, PHP_INI_ALL, OnUpdateBaseDir, open_basedir, php_core_globals, core_globals)
580 :
581 : STD_PHP_INI_BOOLEAN("file_uploads", "1", PHP_INI_SYSTEM, OnUpdateBool, file_uploads, php_core_globals, core_globals)
582 : STD_PHP_INI_ENTRY("upload_max_filesize", "2M", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateLong, upload_max_filesize, php_core_globals, core_globals)
583 : STD_PHP_INI_ENTRY("post_max_size", "8M", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateLong, post_max_size, sapi_globals_struct,sapi_globals)
584 : STD_PHP_INI_ENTRY("upload_tmp_dir", NULL, PHP_INI_SYSTEM, OnUpdateStringUnempty, upload_tmp_dir, php_core_globals, core_globals)
585 : STD_PHP_INI_ENTRY("max_input_nesting_level", "64", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateLongGEZero, max_input_nesting_level, php_core_globals, core_globals)
586 :
587 : STD_PHP_INI_ENTRY("user_dir", NULL, PHP_INI_SYSTEM, OnUpdateString, user_dir, php_core_globals, core_globals)
588 : STD_PHP_INI_ENTRY("variables_order", "EGPCS", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateStringUnempty, variables_order, php_core_globals, core_globals)
589 : STD_PHP_INI_ENTRY("request_order", NULL, PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateString, request_order, php_core_globals, core_globals)
590 :
591 : STD_PHP_INI_ENTRY("error_append_string", NULL, PHP_INI_ALL, OnUpdateString, error_append_string, php_core_globals, core_globals)
592 : STD_PHP_INI_ENTRY("error_prepend_string", NULL, PHP_INI_ALL, OnUpdateString, error_prepend_string, php_core_globals, core_globals)
593 :
594 : PHP_INI_ENTRY("SMTP", "localhost",PHP_INI_ALL, NULL)
595 : PHP_INI_ENTRY("smtp_port", "25", PHP_INI_ALL, NULL)
596 : STD_PHP_INI_BOOLEAN("mail.add_x_header", "0", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateBool, mail_x_header, php_core_globals, core_globals)
597 : STD_PHP_INI_ENTRY("mail.log", NULL, PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateMailLog, mail_log, php_core_globals, core_globals)
598 : PHP_INI_ENTRY("browscap", NULL, PHP_INI_SYSTEM, NULL)
599 : PHP_INI_ENTRY("memory_limit", "128M", PHP_INI_ALL, OnChangeMemoryLimit)
600 : PHP_INI_ENTRY("precision", "14", PHP_INI_ALL, OnSetPrecision)
601 : PHP_INI_ENTRY("sendmail_from", NULL, PHP_INI_ALL, NULL)
602 : PHP_INI_ENTRY("sendmail_path", DEFAULT_SENDMAIL_PATH, PHP_INI_SYSTEM, NULL)
603 : PHP_INI_ENTRY("mail.force_extra_parameters",NULL, PHP_INI_SYSTEM|PHP_INI_PERDIR, OnChangeMailForceExtra)
604 : PHP_INI_ENTRY("disable_functions", "", PHP_INI_SYSTEM, NULL)
605 : PHP_INI_ENTRY("disable_classes", "", PHP_INI_SYSTEM, NULL)
606 : PHP_INI_ENTRY("max_file_uploads", "20", PHP_INI_SYSTEM, NULL)
607 :
608 : STD_PHP_INI_BOOLEAN("allow_url_fopen", "1", PHP_INI_ALL, OnUpdateAllowUrl, allow_url_fopen_list, php_core_globals, core_globals)
609 : STD_PHP_INI_BOOLEAN("allow_url_include", "0", PHP_INI_ALL, OnUpdateAllowUrl, allow_url_include_list, php_core_globals, core_globals)
610 : STD_PHP_INI_BOOLEAN("always_populate_raw_post_data", "0", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateBool, always_populate_raw_post_data, php_core_globals, core_globals)
611 :
612 : STD_PHP_INI_ENTRY("realpath_cache_size", "16K", PHP_INI_SYSTEM, OnUpdateLong, realpath_cache_size_limit, virtual_cwd_globals, cwd_globals)
613 : STD_PHP_INI_ENTRY("realpath_cache_ttl", "120", PHP_INI_SYSTEM, OnUpdateLong, realpath_cache_ttl, virtual_cwd_globals, cwd_globals)
614 :
615 : STD_PHP_INI_ENTRY("user_ini.filename", ".user.ini", PHP_INI_SYSTEM, OnUpdateString, user_ini_filename, php_core_globals, core_globals)
616 : STD_PHP_INI_ENTRY("user_ini.cache_ttl", "300", PHP_INI_SYSTEM, OnUpdateLong, user_ini_cache_ttl, php_core_globals, core_globals)
617 : STD_PHP_INI_BOOLEAN("exit_on_timeout", "0", PHP_INI_ALL, OnUpdateBool, exit_on_timeout, php_core_globals, core_globals)
618 : PHP_INI_END()
619 : /* }}} */
620 :
621 : /* True globals (no need for thread safety */
622 : /* But don't make them a single int bitfield */
623 : static int module_initialized = 0;
624 : static int module_startup = 1;
625 : static int module_shutdown = 0;
626 :
627 : /* {{{ php_during_module_startup */
628 : static int php_during_module_startup(void)
629 161246 : {
630 161246 : return module_startup;
631 : }
632 : /* }}} */
633 :
634 : /* {{{ php_during_module_shutdown */
635 : static int php_during_module_shutdown(void)
636 161242 : {
637 161242 : return module_shutdown;
638 : }
639 : /* }}} */
640 :
641 : /* {{{ php_log_err
642 : */
643 : PHPAPI void php_log_err(char *log_message TSRMLS_DC)
644 10 : {
645 10 : int fd = -1;
646 : time_t error_time;
647 :
648 10 : if (PG(in_error_log)) {
649 : /* prevent recursive invocation */
650 0 : return;
651 : }
652 10 : PG(in_error_log) = 1;
653 :
654 : /* Try to use the specified logging location. */
655 10 : if (PG(error_log) != NULL) {
656 : #ifdef HAVE_SYSLOG_H
657 0 : if (!strcmp(PG(error_log), "syslog")) {
658 0 : php_syslog(LOG_NOTICE, "%.500s", log_message);
659 0 : PG(in_error_log) = 0;
660 0 : return;
661 : }
662 : #endif
663 0 : fd = VCWD_OPEN_MODE(PG(error_log), O_CREAT | O_APPEND | O_WRONLY, 0644);
664 0 : if (fd != -1) {
665 : char *tmp;
666 : int len;
667 : char *error_time_str;
668 :
669 0 : time(&error_time);
670 0 : error_time_str = php_format_date("d-M-Y H:i:s", 11, error_time, 1 TSRMLS_CC);
671 0 : len = spprintf(&tmp, 0, "[%s] %s%s", error_time_str, log_message, PHP_EOL);
672 : #ifdef PHP_WIN32
673 : php_flock(fd, 2);
674 : #endif
675 0 : write(fd, tmp, len);
676 0 : efree(tmp);
677 0 : efree(error_time_str);
678 0 : close(fd);
679 0 : PG(in_error_log) = 0;
680 0 : return;
681 : }
682 : }
683 :
684 : /* Otherwise fall back to the default logging location, if we have one */
685 :
686 10 : if (sapi_module.log_message) {
687 10 : sapi_module.log_message(log_message);
688 : }
689 10 : PG(in_error_log) = 0;
690 : }
691 : /* }}} */
692 :
693 : /* {{{ php_write
694 : wrapper for modules to use PHPWRITE */
695 : PHPAPI int php_write(void *buf, uint size TSRMLS_DC)
696 724 : {
697 724 : return PHPWRITE(buf, size);
698 : }
699 : /* }}} */
700 :
701 : /* {{{ php_printf
702 : */
703 : PHPAPI int php_printf(const char *format, ...)
704 435140 : {
705 : va_list args;
706 : int ret;
707 : char *buffer;
708 : int size;
709 : TSRMLS_FETCH();
710 :
711 435140 : va_start(args, format);
712 435140 : size = vspprintf(&buffer, 0, format, args);
713 435140 : ret = PHPWRITE(buffer, size);
714 435139 : efree(buffer);
715 435139 : va_end(args);
716 :
717 435139 : return ret;
718 : }
719 : /* }}} */
720 :
721 : /* {{{ php_verror */
722 : /* php_verror is called from php_error_docref<n> functions.
723 : * Its purpose is to unify error messages and automatically generate clickable
724 : * html error messages if correcponding ini setting (html_errors) is activated.
725 : * See: CODING_STANDARDS for details.
726 : */
727 : PHPAPI void php_verror(const char *docref, const char *params, int type, const char *format, va_list args TSRMLS_DC)
728 161246 : {
729 161246 : char *buffer = NULL, *docref_buf = NULL, *target = NULL;
730 161246 : char *docref_target = "", *docref_root = "";
731 : char *p;
732 161246 : int buffer_len = 0;
733 161246 : char *space = "";
734 161246 : zstr class_name = EMPTY_ZSTR;
735 : int origin_len;
736 161246 : zstr function = NULL_ZSTR;
737 : char *origin;
738 : char *message;
739 161246 : char *stage = "Unknown";
740 161246 : int function_name_is_string = 1;
741 :
742 : /* get error text into buffer and escape for html if necessary */
743 161246 : buffer_len = vspprintf(&buffer, 0, format, args);
744 161246 : if (PG(html_errors)) {
745 : int len;
746 2 : char *replace = php_escape_html_entities(buffer, buffer_len, &len, 0, ENT_COMPAT, NULL TSRMLS_CC);
747 2 : efree(buffer);
748 2 : buffer = replace;
749 2 : buffer_len = len;
750 : }
751 :
752 : /* which function caused the problem if any at all */
753 161246 : if (php_during_module_startup()) {
754 4 : stage = "PHP Startup";
755 161242 : } else if (php_during_module_shutdown()) {
756 0 : stage = "PHP Shutdown";
757 161306 : } else if (EG(current_execute_data) &&
758 : EG(current_execute_data)->opline &&
759 : EG(current_execute_data)->opline->opcode == ZEND_INCLUDE_OR_EVAL
760 : ) {
761 64 : switch (EG(current_execute_data)->opline->op2.u.constant.value.lval) {
762 : case ZEND_EVAL:
763 0 : function.s = "eval";
764 0 : break;
765 : case ZEND_INCLUDE:
766 58 : function.s = "include";
767 58 : break;
768 : case ZEND_INCLUDE_ONCE:
769 0 : function.s = "include_once";
770 0 : break;
771 : case ZEND_REQUIRE:
772 0 : function.s = "require";
773 0 : break;
774 : case ZEND_REQUIRE_ONCE:
775 6 : function.s = "require_once";
776 6 : break;
777 : default:
778 0 : stage = "Unknown";
779 : }
780 : } else {
781 161178 : function_name_is_string = 0;
782 161178 : function = get_active_function_name(TSRMLS_C);
783 161185 : if (!function.v || !USTR_LEN(function)) {
784 7 : stage = "Unknown";
785 7 : function.v = NULL;
786 : } else {
787 161171 : class_name = get_active_class_name(&space TSRMLS_CC);
788 : }
789 : }
790 :
791 : /* if we still have memory then format the origin */
792 161246 : if (function.v) {
793 161235 : if (function_name_is_string) {
794 64 : origin_len = spprintf(&origin, 0, "%v%s%s(%s)", class_name, space, function.s, params);
795 : } else {
796 161171 : origin_len = spprintf(&origin, 0, "%v%s%v(%s)", class_name, space, function, params);
797 : }
798 : } else {
799 11 : origin_len = spprintf(&origin, 0, "%s", stage);
800 : }
801 :
802 161246 : if (PG(html_errors)) {
803 : int len;
804 2 : char *replace = php_escape_html_entities(origin, origin_len, &len, 0, ENT_COMPAT, NULL TSRMLS_CC);
805 2 : efree(origin);
806 2 : origin = replace;
807 : }
808 :
809 : /* origin and buffer available, so lets come up with the error message */
810 161246 : if (docref && docref[0] == '#') {
811 0 : docref_target = strchr(docref, '#');
812 0 : docref = NULL;
813 : }
814 :
815 : /* no docref given but function is known (the default) */
816 161246 : if (!docref && function.v) {
817 : int doclen;
818 161165 : if (space[0] == '\0') {
819 159959 : if (function_name_is_string) {
820 35 : doclen = spprintf(&docref_buf, 0, "function.%s", function.s);
821 : } else {
822 159924 : doclen = spprintf(&docref_buf, 0, "function.%v", function);
823 : }
824 : } else {
825 1206 : if (function_name_is_string) {
826 0 : doclen = spprintf(&docref_buf, 0, "%v.%s", class_name, function.s);
827 : } else {
828 1206 : doclen = spprintf(&docref_buf, 0, "%v.%v", class_name, function);
829 : }
830 : }
831 330277 : while((p = strchr(docref_buf, '_')) != NULL) {
832 7947 : *p = '-';
833 : }
834 161165 : docref = php_strtolower(docref_buf, doclen);
835 : }
836 :
837 : /* we have a docref for a function AND
838 : * - we show erroes in html mode OR
839 : * - the user wants to see the links anyway
840 : */
841 161248 : if (docref && function.v && (PG(html_errors) || strlen(PG(docref_root)))) {
842 2 : if (strncmp(docref, "http://", 7)) {
843 : /* We don't have 'http://' so we use docref_root */
844 :
845 : char *ref; /* temp copy for duplicated docref */
846 :
847 2 : docref_root = PG(docref_root);
848 :
849 2 : ref = estrdup(docref);
850 2 : if (docref_buf) {
851 1 : efree(docref_buf);
852 : }
853 2 : docref_buf = ref;
854 : /* strip of the target if any */
855 2 : p = strrchr(ref, '#');
856 2 : if (p) {
857 0 : target = estrdup(p);
858 0 : if (target) {
859 0 : docref_target = target;
860 0 : *p = '\0';
861 : }
862 : }
863 : /* add the extension if it is set in ini */
864 2 : if (PG(docref_ext) && strlen(PG(docref_ext))) {
865 2 : spprintf(&docref_buf, 0, "%s%s", ref, PG(docref_ext));
866 2 : efree(ref);
867 : }
868 2 : docref = docref_buf;
869 : }
870 : /* display html formatted or only show the additional links */
871 2 : if (PG(html_errors)) {
872 2 : spprintf(&message, 0, "%s [<a href='%s%s%s'>%s</a>]: %s", origin, docref_root, docref, docref_target, docref, buffer);
873 : } else {
874 0 : spprintf(&message, 0, "%s [%s%s%s]: %s", origin, docref_root, docref, docref_target, buffer);
875 : }
876 2 : if (target) {
877 0 : efree(target);
878 : }
879 : } else {
880 161244 : spprintf(&message, 0, "%s: %s", origin, buffer);
881 : }
882 161246 : efree(origin);
883 161246 : if (docref_buf) {
884 161166 : efree(docref_buf);
885 : }
886 161246 : php_error(type, "%s", message);
887 161224 : efree(message);
888 :
889 161224 : if (PG(track_errors) && module_initialized &&
890 : (!EG(user_error_handler) || !(EG(user_error_handler_error_reporting) & type))) {
891 18999 : if (!EG(active_symbol_table)) {
892 2 : zend_rebuild_symbol_table(TSRMLS_C);
893 : }
894 18999 : if (EG(active_symbol_table)) {
895 : zval *tmp;
896 18998 : ALLOC_INIT_ZVAL(tmp);
897 18998 : ZVAL_RT_STRINGL(tmp, buffer, buffer_len, 1);
898 18998 : zend_ascii_hash_update(EG(active_symbol_table), "php_errormsg", sizeof("php_errormsg"), (void **) &tmp, sizeof(zval *), NULL);
899 : }
900 : }
901 161224 : efree(buffer);
902 161224 : }
903 : /* }}} */
904 :
905 : /* {{{ php_error_docref0 */
906 : /* See: CODING_STANDARDS for details. */
907 : PHPAPI void php_error_docref0(const char *docref TSRMLS_DC, int type, const char *format, ...)
908 18885 : {
909 : va_list args;
910 :
911 18885 : va_start(args, format);
912 18885 : php_verror(docref, "", type, format, args TSRMLS_CC);
913 18863 : va_end(args);
914 18863 : }
915 : /* }}} */
916 :
917 : /* {{{ php_error_docref1 */
918 : /* See: CODING_STANDARDS for details. */
919 : PHPAPI void php_error_docref1(const char *docref TSRMLS_DC, const char *param1, int type, const char *format, ...)
920 142312 : {
921 : va_list args;
922 :
923 142312 : va_start(args, format);
924 142312 : php_verror(docref, param1, type, format, args TSRMLS_CC);
925 142312 : va_end(args);
926 142312 : }
927 : /* }}} */
928 :
929 : /* {{{ php_error_docref2 */
930 : /* See: CODING_STANDARDS for details. */
931 : PHPAPI void php_error_docref2(const char *docref TSRMLS_DC, const char *param1, const char *param2, int type, const char *format, ...)
932 37 : {
933 : char *params;
934 : va_list args;
935 :
936 37 : spprintf(¶ms, 0, "%s,%s", param1, param2);
937 37 : va_start(args, format);
938 37 : php_verror(docref, params ? params : "...", type, format, args TSRMLS_CC);
939 37 : va_end(args);
940 37 : if (params) {
941 37 : efree(params);
942 : }
943 37 : }
944 : /* }}} */
945 :
946 : /* {{{ php_html_puts */
947 : PHPAPI void php_html_puts(const char *str, uint size TSRMLS_DC)
948 210 : {
949 210 : zend_html_puts(str, size TSRMLS_CC);
950 210 : }
951 : /* }}} */
952 :
953 : /* {{{ php_error_cb
954 : extended error handling function */
955 : static void php_error_cb(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args)
956 2724336 : {
957 : char *buffer;
958 : int buffer_len, display;
959 : TSRMLS_FETCH();
960 :
961 2724336 : buffer_len = vspprintf(&buffer, PG(log_errors_max_len), format, args);
962 :
963 : /* check for repeated errors to be ignored */
964 2724336 : if (PG(ignore_repeated_errors) && PG(last_error_message)) {
965 : /* no check for PG(last_error_file) is needed since it cannot
966 : * be NULL if PG(last_error_message) is not NULL */
967 0 : if (strcmp(PG(last_error_message), buffer)
968 : || (!PG(ignore_repeated_source)
969 : && ((PG(last_error_lineno) != error_lineno)
970 : || strcmp(PG(last_error_file), error_filename)))) {
971 0 : display = 1;
972 : } else {
973 0 : display = 0;
974 : }
975 : } else {
976 2724336 : display = 1;
977 : }
978 :
979 : /* store the error if it has changed */
980 2724336 : if (display) {
981 2724336 : if (PG(last_error_message)) {
982 2719455 : free(PG(last_error_message));
983 : }
984 2724336 : if (PG(last_error_file)) {
985 2719455 : free(PG(last_error_file));
986 : }
987 2724336 : if (!error_filename) {
988 1 : error_filename = "Unknown";
989 : }
990 2724336 : PG(last_error_type) = type;
991 2724336 : PG(last_error_message) = strdup(buffer);
992 2724336 : PG(last_error_file) = strdup(error_filename);
993 2724336 : PG(last_error_lineno) = error_lineno;
994 : }
995 :
996 : /* according to error handling mode, suppress error, throw exception or show it */
997 2724336 : if (EG(error_handling) != EH_NORMAL) {
998 135 : switch (type) {
999 : case E_ERROR:
1000 : case E_CORE_ERROR:
1001 : case E_COMPILE_ERROR:
1002 : case E_USER_ERROR:
1003 : case E_PARSE:
1004 : /* fatal errors are real errors and cannot be made exceptions */
1005 0 : break;
1006 : case E_STRICT:
1007 : case E_DEPRECATED:
1008 : case E_USER_DEPRECATED:
1009 : /* for the sake of BC to old damaged code */
1010 0 : break;
1011 : case E_NOTICE:
1012 : case E_USER_NOTICE:
1013 : /* notices are no errors and are not treated as such like E_WARNINGS */
1014 1 : break;
1015 : default:
1016 : /* throw an exception if we are in EH_THROW mode
1017 : * but DO NOT overwrite a pending exception
1018 : */
1019 134 : if (EG(error_handling) == EH_THROW && !EG(exception)) {
1020 131 : zend_throw_error_exception(EG(exception_class), buffer, 0, type TSRMLS_CC);
1021 : }
1022 134 : efree(buffer);
1023 134 : return;
1024 : }
1025 : }
1026 :
1027 : /* display/log the error if necessary */
1028 2724202 : if (display && (EG(error_reporting) & type || (type & E_CORE))
1029 : && (PG(log_errors) || PG(display_errors) || (!module_initialized))) {
1030 : char *error_type_str;
1031 :
1032 26703 : switch (type) {
1033 : case E_ERROR:
1034 : case E_CORE_ERROR:
1035 : case E_COMPILE_ERROR:
1036 : case E_USER_ERROR:
1037 540 : error_type_str = "Fatal error";
1038 540 : break;
1039 : case E_RECOVERABLE_ERROR:
1040 48 : error_type_str = "Catchable fatal error";
1041 48 : break;
1042 : case E_WARNING:
1043 : case E_CORE_WARNING:
1044 : case E_COMPILE_WARNING:
1045 : case E_USER_WARNING:
1046 21950 : error_type_str = "Warning";
1047 21950 : break;
1048 : case E_PARSE:
1049 28 : error_type_str = "Parse error";
1050 28 : break;
1051 : case E_NOTICE:
1052 : case E_USER_NOTICE:
1053 3833 : error_type_str = "Notice";
1054 3833 : break;
1055 : case E_STRICT:
1056 166 : error_type_str = "Strict Standards";
1057 166 : break;
1058 : case E_DEPRECATED:
1059 : case E_USER_DEPRECATED:
1060 138 : error_type_str = "Deprecated";
1061 138 : break;
1062 : default:
1063 0 : error_type_str = "Unknown error";
1064 : break;
1065 : }
1066 :
1067 26703 : if (!module_initialized || PG(log_errors)) {
1068 : char *log_buffer;
1069 : #ifdef PHP_WIN32
1070 : if ((type == E_CORE_ERROR || type == E_CORE_WARNING) && PG(display_startup_errors)) {
1071 : MessageBox(NULL, buffer, error_type_str, MB_OK|ZEND_SERVICE_MB_STYLE);
1072 : }
1073 : #endif
1074 10 : spprintf(&log_buffer, 0, "PHP %s: %s in %s on line %d", error_type_str, buffer, error_filename, error_lineno);
1075 10 : php_log_err(log_buffer TSRMLS_CC);
1076 10 : efree(log_buffer);
1077 : }
1078 26703 : if (PG(display_errors) && ((module_initialized && !PG(during_request_startup)) || (PG(display_startup_errors)))) {
1079 26696 : if (PG(xmlrpc_errors)) {
1080 0 : php_printf("<?xml version=\"1.0\"?><methodResponse><fault><value><struct><member><name>faultCode</name><value><int>%ld</int></value></member><member><name>faultString</name><value><string>%s:%s in %s on line %d</string></value></member></struct></value></fault></methodResponse>", PG(xmlrpc_error_number), error_type_str, buffer, error_filename, error_lineno);
1081 : } else {
1082 26696 : char *prepend_string = INI_STR("error_prepend_string");
1083 26696 : char *append_string = INI_STR("error_append_string");
1084 :
1085 26696 : if (PG(html_errors)) {
1086 4 : if (type == E_ERROR) {
1087 : int len;
1088 1 : char *buf = php_escape_html_entities(buffer, buffer_len, &len, 0, ENT_COMPAT, NULL TSRMLS_CC);
1089 1 : php_printf("%s<br />\n<b>%s</b>: %s in <b>%s</b> on line <b>%d</b><br />\n%s", STR_PRINT(prepend_string), error_type_str, buf, error_filename, error_lineno, STR_PRINT(append_string));
1090 1 : efree(buf);
1091 : } else {
1092 3 : php_printf("%s<br />\n<b>%s</b>: %s in <b>%s</b> on line <b>%d</b><br />\n%s", STR_PRINT(prepend_string), error_type_str, buffer, error_filename, error_lineno, STR_PRINT(append_string));
1093 : }
1094 : } else {
1095 : /* Write CLI/CGI errors to stderr if display_errors = "stderr" */
1096 26692 : if ((!strcmp(sapi_module.name, "cli") || !strcmp(sapi_module.name, "cgi")) &&
1097 : PG(display_errors) == PHP_DISPLAY_ERRORS_STDERR
1098 : ) {
1099 0 : fprintf(stderr, "%s: %s in %s on line %d\n", error_type_str, buffer, error_filename, error_lineno);
1100 : } else {
1101 26692 : php_printf("%s\n%s: %s in %s on line %d\n%s", STR_PRINT(prepend_string), error_type_str, buffer, error_filename, error_lineno, STR_PRINT(append_string));
1102 : }
1103 : }
1104 : }
1105 : }
1106 : #if ZEND_DEBUG
1107 : if (PG(report_zend_debug)) {
1108 : zend_bool trigger_break;
1109 :
1110 : switch (type) {
1111 : case E_ERROR:
1112 : case E_CORE_ERROR:
1113 : case E_COMPILE_ERROR:
1114 : case E_USER_ERROR:
1115 : trigger_break=1;
1116 : break;
1117 : default:
1118 : trigger_break=0;
1119 : break;
1120 : }
1121 : zend_output_debug_string(trigger_break, "%s(%d) : %s - %s", error_filename, error_lineno, error_type_str, buffer);
1122 : }
1123 : #endif
1124 : }
1125 :
1126 : /* Bail out if we can't recover */
1127 2724202 : switch (type) {
1128 : case E_CORE_ERROR:
1129 1 : if(!module_initialized) {
1130 : /* bad error in module startup - no way we can live with this */
1131 0 : exit(-2);
1132 : }
1133 : /* no break - intentionally */
1134 : case E_ERROR:
1135 : case E_RECOVERABLE_ERROR:
1136 : case E_PARSE:
1137 : case E_COMPILE_ERROR:
1138 : case E_USER_ERROR:
1139 629 : EG(exit_status) = 255;
1140 629 : if (module_initialized) {
1141 625 : if (!PG(display_errors) &&
1142 : !SG(headers_sent) &&
1143 : SG(sapi_headers).http_response_code == 200
1144 : ) {
1145 0 : sapi_header_line ctr = {0};
1146 :
1147 0 : ctr.line = "HTTP/1.0 500 Internal Server Error";
1148 0 : ctr.line_len = strlen(ctr.line);
1149 0 : sapi_header_op(SAPI_HEADER_REPLACE, &ctr TSRMLS_CC);
1150 : }
1151 : /* the parser would return 1 (failure), we can bail out nicely */
1152 625 : if (type != E_PARSE) {
1153 : /* restore memory limit */
1154 596 : zend_set_memory_limit(PG(memory_limit));
1155 596 : efree(buffer);
1156 596 : zend_objects_store_mark_destructed(&EG(objects_store) TSRMLS_CC);
1157 596 : zend_bailout();
1158 0 : return;
1159 : }
1160 : }
1161 : break;
1162 : }
1163 :
1164 : /* Log if necessary */
1165 2723606 : if (!display) {
1166 0 : efree(buffer);
1167 0 : return;
1168 : }
1169 2723606 : if (PG(track_errors) && module_initialized) {
1170 37954 : if (!EG(active_symbol_table)) {
1171 4427 : zend_rebuild_symbol_table(TSRMLS_C);
1172 : }
1173 37954 : if (EG(active_symbol_table)) {
1174 : zval *tmp;
1175 :
1176 37953 : ALLOC_INIT_ZVAL(tmp);
1177 37953 : ZVAL_RT_STRINGL(tmp, buffer, buffer_len, 1);
1178 37953 : zend_ascii_hash_update(EG(active_symbol_table), "php_errormsg", sizeof("php_errormsg"), (void **) & tmp, sizeof(zval *), NULL);
1179 : }
1180 : }
1181 2723606 : efree(buffer);
1182 : }
1183 : /* }}} */
1184 :
1185 : /* {{{ proto bool set_time_limit(int seconds) U
1186 : Sets the maximum time a script can run */
1187 : PHP_FUNCTION(set_time_limit)
1188 16 : {
1189 : long new_timeout;
1190 : char *new_timeout_str;
1191 : int new_timeout_strlen;
1192 :
1193 16 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &new_timeout) == FAILURE) {
1194 0 : return;
1195 : }
1196 :
1197 16 : new_timeout_strlen = zend_spprintf(&new_timeout_str, 0, "%ld", new_timeout);
1198 :
1199 16 : if (zend_alter_ini_entry_ex("max_execution_time", sizeof("max_execution_time"), new_timeout_str, new_timeout_strlen, PHP_INI_USER, PHP_INI_STAGE_RUNTIME, 0 TSRMLS_CC) == SUCCESS) {
1200 16 : RETVAL_TRUE;
1201 : } else {
1202 0 : RETVAL_FALSE;
1203 : }
1204 16 : efree(new_timeout_str);
1205 : }
1206 : /* }}} */
1207 :
1208 : /* {{{ php_path_encode_for_zend
1209 : */
1210 : static int php_path_encode_for_zend(char **encpath, int *encpath_len, const UChar *path, int path_len TSRMLS_DC)
1211 7987 : {
1212 7987 : return php_stream_path_encode(NULL, encpath, encpath_len, path, path_len, 0, NULL);
1213 : }
1214 : /* }}} */
1215 :
1216 : /* {{{ php_path_decode_for_zend
1217 : */
1218 : static int php_path_decode_for_zend(UChar **decpath, int *decpath_len, const char *path, int path_len TSRMLS_DC)
1219 15 : {
1220 15 : return php_stream_path_decode(NULL, decpath, decpath_len, path, path_len, 0, NULL);
1221 : }
1222 : /* }}} */
1223 :
1224 : /* {{{ php_fopen_wrapper_for_zend
1225 : */
1226 : static FILE *php_fopen_wrapper_for_zend(const char *filename, char **opened_path TSRMLS_DC)
1227 0 : {
1228 0 : return php_stream_open_wrapper_as_file((char *)filename, "rb", USE_PATH|IGNORE_URL_WIN|REPORT_ERRORS|STREAM_OPEN_FOR_INCLUDE, opened_path);
1229 : }
1230 : /* }}} */
1231 :
1232 : static void php_zend_stream_closer(void *handle TSRMLS_DC) /* {{{ */
1233 7530 : {
1234 7530 : php_stream_close((php_stream*)handle);
1235 7530 : }
1236 : /* }}} */
1237 :
1238 : static void php_zend_stream_mmap_closer(void *handle TSRMLS_DC) /* {{{ */
1239 7250 : {
1240 7250 : php_stream_mmap_unmap((php_stream*)handle);
1241 7250 : php_zend_stream_closer(handle TSRMLS_CC);
1242 7250 : }
1243 : /* }}} */
1244 :
1245 : static size_t php_zend_stream_fsizer(void *handle TSRMLS_DC) /* {{{ */
1246 7809 : {
1247 : php_stream_statbuf ssb;
1248 7809 : if (php_stream_stat((php_stream*)handle, &ssb) == 0) {
1249 7807 : return ssb.sb.st_size;
1250 : }
1251 2 : return 0;
1252 : }
1253 : /* }}} */
1254 :
1255 : static int php_stream_open_for_zend(const char *filename, zend_file_handle *handle TSRMLS_DC) /* {{{ */
1256 7578 : {
1257 7578 : return php_stream_open_for_zend_ex(filename, handle, ENFORCE_SAFE_MODE|USE_PATH|REPORT_ERRORS|STREAM_OPEN_FOR_INCLUDE TSRMLS_CC);
1258 : }
1259 : /* }}} */
1260 :
1261 : PHPAPI int php_stream_open_for_zend_ex(const char *filename, zend_file_handle *handle, int mode TSRMLS_DC) /* {{{ */
1262 7593 : {
1263 : char *p;
1264 : size_t len, mapped_len;
1265 7593 : php_stream *stream = php_stream_open_wrapper((char *)filename, "rb", mode, &handle->opened_path);
1266 :
1267 7593 : if (stream) {
1268 7530 : handle->filename = (char*)filename;
1269 7530 : handle->free_filename = 0;
1270 7530 : handle->handle.stream.handle = stream;
1271 7530 : handle->handle.stream.reader = (zend_stream_reader_t)_php_stream_read;
1272 7530 : handle->handle.stream.fsizer = php_zend_stream_fsizer;
1273 7530 : handle->handle.stream.isatty = 0;
1274 : /* can we mmap immeadiately? */
1275 7530 : memset(&handle->handle.stream.mmap, 0, sizeof(handle->handle.stream.mmap));
1276 7530 : len = php_zend_stream_fsizer(stream TSRMLS_CC);
1277 14780 : if (len != 0
1278 : && ((len - 1) % PAGE_SIZE) <= PAGE_SIZE - ZEND_MMAP_AHEAD
1279 : && php_stream_mmap_possible(stream)
1280 : && (p = php_stream_mmap_range(stream, 0, len, PHP_STREAM_MAP_MODE_SHARED_READONLY, &mapped_len)) != NULL) {
1281 7250 : handle->handle.stream.closer = php_zend_stream_mmap_closer;
1282 7250 : handle->handle.stream.mmap.buf = p;
1283 7250 : handle->handle.stream.mmap.len = mapped_len;
1284 7250 : handle->type = ZEND_HANDLE_MAPPED;
1285 : } else {
1286 280 : handle->handle.stream.closer = php_zend_stream_closer;
1287 280 : handle->type = ZEND_HANDLE_STREAM;
1288 : }
1289 : /* suppress warning if this stream is not explicitly closed */
1290 : php_stream_auto_cleanup(stream);
1291 :
1292 7530 : return SUCCESS;
1293 : }
1294 63 : return FAILURE;
1295 : }
1296 : /* }}} */
1297 :
1298 : static char *php_resolve_path_for_zend(const char *filename, int filename_len TSRMLS_DC) /* {{{ */
1299 13413 : {
1300 13413 : return php_resolve_path(filename, filename_len, PG(include_path) TSRMLS_CC);
1301 : }
1302 : /* }}} */
1303 :
1304 : /* {{{ php_get_configuration_directive_for_zend
1305 : */
1306 : static int php_get_configuration_directive_for_zend(const char *name, uint name_length, zval *contents)
1307 3710152 : {
1308 3710152 : zval *retval = cfg_get_entry(name, name_length);
1309 :
1310 3710152 : if (retval) {
1311 576845 : *contents = *retval;
1312 576845 : return SUCCESS;
1313 : } else {
1314 3133307 : return FAILURE;
1315 : }
1316 : }
1317 : /* }}} */
1318 :
1319 : /* {{{ php_message_handler_for_zend
1320 : */
1321 : static void php_message_handler_for_zend(long message, void *data TSRMLS_DC)
1322 31 : {
1323 31 : switch (message) {
1324 : case ZMSG_FAILED_INCLUDE_FOPEN:
1325 26 : php_error_docref("function.include" TSRMLS_CC, E_WARNING, "Failed opening '%s' for inclusion (include_path='%s')", php_strip_url_passwd((char *) data), STR_PRINT(PG(include_path)));
1326 26 : break;
1327 : case ZMSG_FAILED_REQUIRE_FOPEN:
1328 3 : php_error_docref("function.require" TSRMLS_CC, E_COMPILE_ERROR, "Failed opening required '%s' (include_path='%s')", php_strip_url_passwd((char *) data), STR_PRINT(PG(include_path)));
1329 0 : break;
1330 : case ZMSG_FAILED_HIGHLIGHT_FOPEN:
1331 2 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed opening '%s' for highlighting", php_strip_url_passwd((char *) data));
1332 2 : break;
1333 : case ZMSG_MEMORY_LEAK_DETECTED:
1334 : case ZMSG_MEMORY_LEAK_REPEATED:
1335 : #if ZEND_DEBUG
1336 : if (EG(error_reporting) & E_WARNING) {
1337 : char memory_leak_buf[1024];
1338 :
1339 : if (message==ZMSG_MEMORY_LEAK_DETECTED) {
1340 : zend_leak_info *t = (zend_leak_info *) data;
1341 :
1342 : snprintf(memory_leak_buf, 512, "%s(%d) : Freeing 0x%.8lX (%zu bytes), script=%s\n", t->filename, t->lineno, (zend_uintptr_t)t->addr, t->size, SAFE_FILENAME(SG(request_info).path_translated));
1343 : if (t->orig_filename) {
1344 : char relay_buf[512];
1345 :
1346 : snprintf(relay_buf, 512, "%s(%d) : Actual location (location was relayed)\n", t->orig_filename, t->orig_lineno);
1347 : strlcat(memory_leak_buf, relay_buf, sizeof(memory_leak_buf));
1348 : }
1349 : } else {
1350 : unsigned long leak_count = (zend_uintptr_t) data;
1351 :
1352 : snprintf(memory_leak_buf, 512, "Last leak repeated %ld time%s\n", leak_count, (leak_count>1?"s":""));
1353 : }
1354 : # if defined(PHP_WIN32)
1355 : OutputDebugString(memory_leak_buf);
1356 : # else
1357 : fprintf(stderr, "%s", memory_leak_buf);
1358 : # endif
1359 : }
1360 : #endif
1361 0 : break;
1362 : case ZMSG_MEMORY_LEAKS_GRAND_TOTAL:
1363 : #if ZEND_DEBUG
1364 : if (EG(error_reporting) & E_WARNING) {
1365 : char memory_leak_buf[512];
1366 :
1367 : snprintf(memory_leak_buf, 512, "=== Total %d memory leaks detected ===\n", *((zend_uint *) data));
1368 : # if defined(PHP_WIN32)
1369 : OutputDebugString(memory_leak_buf);
1370 : # else
1371 : fprintf(stderr, "%s", memory_leak_buf);
1372 : # endif
1373 : }
1374 : #endif
1375 0 : break;
1376 : case ZMSG_LOG_SCRIPT_NAME: {
1377 : struct tm *ta, tmbuf;
1378 : time_t curtime;
1379 : char *datetime_str, asctimebuf[52];
1380 : char memory_leak_buf[4096];
1381 :
1382 0 : time(&curtime);
1383 0 : ta = php_localtime_r(&curtime, &tmbuf);
1384 0 : datetime_str = php_asctime_r(ta, asctimebuf);
1385 0 : if (datetime_str) {
1386 0 : datetime_str[strlen(datetime_str)-1]=0; /* get rid of the trailing newline */
1387 0 : snprintf(memory_leak_buf, sizeof(memory_leak_buf), "[%s] Script: '%s'\n", datetime_str, SAFE_FILENAME(SG(request_info).path_translated));
1388 : } else {
1389 0 : snprintf(memory_leak_buf, sizeof(memory_leak_buf), "[null] Script: '%s'\n", SAFE_FILENAME(SG(request_info).path_translated));
1390 : }
1391 : # if defined(PHP_WIN32)
1392 : OutputDebugString(memory_leak_buf);
1393 : # else
1394 0 : fprintf(stderr, "%s", memory_leak_buf);
1395 : # endif
1396 : }
1397 : break;
1398 : }
1399 28 : }
1400 : /* }}} */
1401 :
1402 : void php_on_timeout(int seconds TSRMLS_DC) /* {{{ */
1403 3 : {
1404 3 : PG(connection_status) |= PHP_CONNECTION_TIMEOUT;
1405 3 : zend_set_timeout(EG(timeout_seconds), 1);
1406 3 : if(PG(exit_on_timeout)) sapi_terminate_process(TSRMLS_C);
1407 3 : }
1408 : /* }}} */
1409 :
1410 : #if PHP_SIGCHILD
1411 : /* {{{ sigchld_handler
1412 : */
1413 : static void sigchld_handler(int apar)
1414 : {
1415 : while (waitpid(-1, NULL, WNOHANG) > 0);
1416 : signal(SIGCHLD, sigchld_handler);
1417 : }
1418 : /* }}} */
1419 : #endif
1420 :
1421 : /* {{{ php_start_sapi()
1422 : */
1423 : static int php_start_sapi(TSRMLS_D)
1424 0 : {
1425 0 : int retval = SUCCESS;
1426 :
1427 0 : if(!SG(sapi_started)) {
1428 0 : zend_try {
1429 0 : PG(during_request_startup) = 1;
1430 :
1431 : /* initialize global variables */
1432 0 : PG(modules_activated) = 0;
1433 0 : PG(header_is_being_sent) = 0;
1434 0 : PG(connection_status) = PHP_CONNECTION_NORMAL;
1435 :
1436 0 : zend_activate(TSRMLS_C);
1437 0 : zend_set_timeout(EG(timeout_seconds), 1);
1438 0 : zend_activate_modules(TSRMLS_C);
1439 0 : PG(modules_activated)=1;
1440 0 : } zend_catch {
1441 0 : retval = FAILURE;
1442 0 : } zend_end_try();
1443 :
1444 0 : SG(sapi_started) = 1;
1445 : }
1446 0 : return retval;
1447 : }
1448 :
1449 : /* }}} */
1450 :
1451 : /* {{{ php_request_startup
1452 : */
1453 : #ifndef APACHE_HOOKS
1454 : int php_request_startup(TSRMLS_D)
1455 16993 : {
1456 16993 : int retval = SUCCESS;
1457 :
1458 : #ifdef HAVE_DTRACE
1459 : DTRACE_REQUEST_STARTUP(SAFE_FILENAME(SG(request_info).path_translated), SAFE_FILENAME(SG(request_info).request_uri), SAFE_FILENAME(SG(request_info).request_method));
1460 : #endif /* HAVE_DTRACE */
1461 :
1462 : #ifdef PHP_WIN32
1463 : PG(com_initialized) = 0;
1464 : #endif
1465 :
1466 : #if PHP_SIGCHILD
1467 : signal(SIGCHLD, sigchld_handler);
1468 : #endif
1469 :
1470 16993 : zend_try {
1471 16993 : PG(in_error_log) = 0;
1472 16993 : PG(during_request_startup) = 1;
1473 :
1474 16993 : php_output_activate(TSRMLS_C);
1475 :
1476 : /* initialize global variables */
1477 16993 : PG(modules_activated) = 0;
1478 16993 : PG(header_is_being_sent) = 0;
1479 16993 : PG(connection_status) = PHP_CONNECTION_NORMAL;
1480 16993 : PG(in_user_include) = 0;
1481 :
1482 16993 : zend_activate(TSRMLS_C);
1483 16993 : sapi_activate(TSRMLS_C);
1484 :
1485 16993 : if (PG(max_input_time) == -1) {
1486 16993 : zend_set_timeout(EG(timeout_seconds), 1);
1487 : } else {
1488 0 : zend_set_timeout(PG(max_input_time), 1);
1489 : }
1490 :
1491 : /* Disable realpath cache if open_basedir is set */
1492 16993 : if (PG(open_basedir) && *PG(open_basedir)) {
1493 73 : CWDG(realpath_cache_size_limit) = 0;
1494 : }
1495 :
1496 16993 : if (PG(expose_php)) {
1497 16993 : sapi_add_header(SAPI_PHP_VERSION_HEADER, sizeof(SAPI_PHP_VERSION_HEADER)-1, 1);
1498 : }
1499 :
1500 16995 : if (PG(output_handler) && PG(output_handler)[0]) {
1501 : zval *oh;
1502 :
1503 2 : MAKE_STD_ZVAL(oh);
1504 2 : ZVAL_ASCII_STRING(oh, PG(output_handler), ZSTR_DUPLICATE);
1505 2 : php_output_start_user(oh, 0, PHP_OUTPUT_HANDLER_STDFLAGS TSRMLS_CC);
1506 2 : zval_ptr_dtor(&oh);
1507 16991 : } else if (PG(output_buffering)) {
1508 0 : php_output_start_user(NULL, PG(output_buffering) > 1 ? PG(output_buffering) : 0, PHP_OUTPUT_HANDLER_STDFLAGS TSRMLS_CC);
1509 16991 : } else if (PG(implicit_flush)) {
1510 16665 : php_output_set_implicit_flush(1 TSRMLS_CC);
1511 : }
1512 :
1513 : /* We turn this off in php_execute_script() */
1514 : /* PG(during_request_startup) = 0; */
1515 :
1516 16993 : sapi_update_default_charset(TSRMLS_C);
1517 :
1518 16993 : php_hash_environment(TSRMLS_C);
1519 16993 : zend_activate_modules(TSRMLS_C);
1520 16993 : PG(modules_activated)=1;
1521 0 : } zend_catch {
1522 0 : retval = FAILURE;
1523 16993 : } zend_end_try();
1524 :
1525 16993 : SG(sapi_started) = 1;
1526 :
1527 16993 : return retval;
1528 : }
1529 : # else
1530 : int php_request_startup(TSRMLS_D)
1531 : {
1532 : int retval = SUCCESS;
1533 :
1534 : #if PHP_SIGCHILD
1535 : signal(SIGCHLD, sigchld_handler);
1536 : #endif
1537 :
1538 : if (php_start_sapi() == FAILURE) {
1539 : return FAILURE;
1540 : }
1541 :
1542 : php_output_activate(TSRMLS_C);
1543 : sapi_activate(TSRMLS_C);
1544 : php_hash_environment(TSRMLS_C);
1545 :
1546 : zend_try {
1547 : PG(during_request_startup) = 1;
1548 : if (PG(expose_php)) {
1549 : sapi_add_header(SAPI_PHP_VERSION_HEADER, sizeof(SAPI_PHP_VERSION_HEADER)-1, 1);
1550 : }
1551 : } zend_catch {
1552 : retval = FAILURE;
1553 : } zend_end_try();
1554 :
1555 : return retval;
1556 : }
1557 : # endif
1558 : /* }}} */
1559 :
1560 : /* {{{ php_request_startup_for_hook
1561 : */
1562 : int php_request_startup_for_hook(TSRMLS_D)
1563 0 : {
1564 0 : int retval = SUCCESS;
1565 :
1566 : #if PHP_SIGCHLD
1567 : signal(SIGCHLD, sigchld_handler);
1568 : #endif
1569 :
1570 0 : if (php_start_sapi(TSRMLS_C) == FAILURE) {
1571 0 : return FAILURE;
1572 : }
1573 :
1574 0 : php_output_activate(TSRMLS_C);
1575 0 : sapi_activate_headers_only(TSRMLS_C);
1576 0 : php_hash_environment(TSRMLS_C);
1577 :
1578 0 : return retval;
1579 : }
1580 : /* }}} */
1581 :
1582 : /* {{{ php_request_shutdown_for_exec
1583 : */
1584 : void php_request_shutdown_for_exec(void *dummy)
1585 0 : {
1586 : TSRMLS_FETCH();
1587 :
1588 : /* used to close fd's in the 3..255 range here, but it's problematic
1589 : */
1590 0 : shutdown_memory_manager(1, 1 TSRMLS_CC);
1591 0 : }
1592 : /* }}} */
1593 :
1594 : /* {{{ php_request_shutdown_for_hook
1595 : */
1596 : void php_request_shutdown_for_hook(void *dummy)
1597 0 : {
1598 : TSRMLS_FETCH();
1599 :
1600 0 : if (PG(modules_activated)) zend_try {
1601 0 : php_call_shutdown_functions(TSRMLS_C);
1602 0 : } zend_end_try();
1603 :
1604 0 : if (PG(modules_activated)) {
1605 0 : zend_deactivate_modules(TSRMLS_C);
1606 0 : php_free_shutdown_functions(TSRMLS_C);
1607 : }
1608 :
1609 0 : zend_try {
1610 : int i;
1611 :
1612 0 : for (i = 0; i < NUM_TRACK_VARS; i++) {
1613 0 : if (PG(http_globals)[i]) {
1614 0 : zval_ptr_dtor(&PG(http_globals)[i]);
1615 : }
1616 : }
1617 0 : } zend_end_try();
1618 :
1619 0 : zend_deactivate(TSRMLS_C);
1620 :
1621 0 : zend_try {
1622 0 : sapi_deactivate(TSRMLS_C);
1623 0 : } zend_end_try();
1624 :
1625 0 : zend_try {
1626 0 : php_shutdown_stream_hashes(TSRMLS_C);
1627 0 : } zend_end_try();
1628 :
1629 0 : zend_try {
1630 0 : shutdown_memory_manager(CG(unclean_shutdown), 0 TSRMLS_CC);
1631 0 : } zend_end_try();
1632 :
1633 0 : zend_try {
1634 0 : zend_unset_timeout(TSRMLS_C);
1635 0 : } zend_end_try();
1636 0 : }
1637 :
1638 : /* }}} */
1639 :
1640 : /* {{{ php_request_shutdown
1641 : */
1642 : void php_request_shutdown(void *dummy)
1643 17025 : {
1644 : zend_bool report_memleaks;
1645 : TSRMLS_FETCH();
1646 :
1647 17025 : report_memleaks = PG(report_memleaks);
1648 :
1649 : /* EG(opline_ptr) points into nirvana and therefore cannot be safely accessed
1650 : * inside zend_executor callback functions.
1651 : */
1652 17025 : EG(opline_ptr) = NULL;
1653 17025 : EG(active_op_array) = NULL;
1654 :
1655 17025 : php_deactivate_ticks(TSRMLS_C);
1656 :
1657 : /* 1. Call all possible __destruct() functions */
1658 17025 : zend_try {
1659 17025 : zend_call_destructors(TSRMLS_C);
1660 17025 : } zend_end_try();
1661 :
1662 : /* 2. Call all possible shutdown functions registered with register_shutdown_function() */
1663 17025 : if (PG(modules_activated)) zend_try {
1664 17025 : php_call_shutdown_functions(TSRMLS_C);
1665 17025 : } zend_end_try();
1666 :
1667 : /* 3. Flush all output buffers */
1668 17025 : zend_try {
1669 17025 : if (SG(request_info).headers_only) {
1670 0 : php_output_discard_all(TSRMLS_C);
1671 : } else {
1672 17025 : php_output_end_all(TSRMLS_C);
1673 : }
1674 17022 : php_output_deactivate(TSRMLS_C);
1675 17025 : } zend_end_try();
1676 :
1677 : /* 4. Send the set HTTP headers (note: This must be done AFTER php_end_ob_buffers() !!) */
1678 17025 : zend_try {
1679 17025 : sapi_send_headers(TSRMLS_C);
1680 17025 : } zend_end_try();
1681 :
1682 : /* 5. Call all extensions RSHUTDOWN functions */
1683 17025 : if (PG(modules_activated)) {
1684 17025 : zend_deactivate_modules(TSRMLS_C);
1685 17025 : php_free_shutdown_functions(TSRMLS_C);
1686 : }
1687 :
1688 : /* 6. Destroy super-globals */
1689 17025 : zend_try {
1690 : int i;
1691 :
1692 119175 : for (i=0; i<NUM_TRACK_VARS; i++) {
1693 102150 : if (PG(http_globals)[i]) {
1694 86191 : zval_ptr_dtor(&PG(http_globals)[i]);
1695 : }
1696 : }
1697 17025 : } zend_end_try();
1698 :
1699 : /* 6.5 free last error information */
1700 17025 : if (PG(last_error_message)) {
1701 4879 : free(PG(last_error_message));
1702 4879 : PG(last_error_message) = NULL;
1703 : }
1704 17025 : if (PG(last_error_file)) {
1705 4879 : free(PG(last_error_file));
1706 4879 : PG(last_error_file) = NULL;
1707 : }
1708 :
1709 : /* 7. Shutdown scanner/executor/compiler and restore ini entries */
1710 17025 : zend_deactivate(TSRMLS_C);
1711 :
1712 : /* 8. Call all extensions post-RSHUTDOWN functions */
1713 17025 : zend_try {
1714 17025 : zend_post_deactivate_modules(TSRMLS_C);
1715 17025 : } zend_end_try();
1716 :
1717 : /* 9. SAPI related shutdown (free stuff) */
1718 17025 : zend_try {
1719 17025 : sapi_deactivate(TSRMLS_C);
1720 17025 : } zend_end_try();
1721 :
1722 : /* 10. Destroy stream hashes */
1723 17025 : zend_try {
1724 17025 : php_shutdown_stream_hashes(TSRMLS_C);
1725 17025 : } zend_end_try();
1726 :
1727 : /* 11. Free Willy (here be crashes) */
1728 17025 : zend_try {
1729 17025 : shutdown_memory_manager(CG(unclean_shutdown) || !report_memleaks, 0 TSRMLS_CC);
1730 17025 : } zend_end_try();
1731 :
1732 : /* 12. Reset max_execution_time */
1733 17025 : zend_try {
1734 17025 : zend_unset_timeout(TSRMLS_C);
1735 17025 : } zend_end_try();
1736 :
1737 : #ifdef PHP_WIN32
1738 : if (PG(com_initialized)) {
1739 : CoUninitialize();
1740 : PG(com_initialized) = 0;
1741 : }
1742 : #endif
1743 :
1744 : #ifdef HAVE_DTRACE
1745 : DTRACE_REQUEST_SHUTDOWN(SAFE_FILENAME(SG(request_info).path_translated), SAFE_FILENAME(SG(request_info).request_uri), SAFE_FILENAME(SG(request_info).request_method));
1746 : #endif /* HAVE_DTRACE */
1747 17025 : }
1748 : /* }}} */
1749 :
1750 : /* {{{ php_com_initialize
1751 : */
1752 : PHPAPI void php_com_initialize(TSRMLS_D)
1753 0 : {
1754 : #ifdef PHP_WIN32
1755 : if (!PG(com_initialized)) {
1756 : CoInitialize(NULL);
1757 : PG(com_initialized) = 1;
1758 : }
1759 : #endif
1760 0 : }
1761 : /* }}} */
1762 :
1763 : /* {{{ php_output_wrapper
1764 : */
1765 : static int php_output_wrapper(const char *str, uint str_length)
1766 383234 : {
1767 : TSRMLS_FETCH();
1768 383234 : return php_output_write(str, str_length TSRMLS_CC);
1769 : }
1770 : /* }}} */
1771 :
1772 : #ifdef ZTS
1773 : /* {{{ core_globals_ctor
1774 : */
1775 : static void core_globals_ctor(php_core_globals *core_globals TSRMLS_DC)
1776 : {
1777 : memset(core_globals, 0, sizeof(*core_globals));
1778 :
1779 : php_startup_ticks(TSRMLS_C);
1780 : }
1781 : /* }}} */
1782 : #endif
1783 :
1784 : /* {{{ core_globals_dtor
1785 : */
1786 : static void core_globals_dtor(php_core_globals *core_globals TSRMLS_DC)
1787 17039 : {
1788 17039 : if (core_globals->last_error_message) {
1789 1 : free(core_globals->last_error_message);
1790 : }
1791 17039 : if (core_globals->last_error_file) {
1792 1 : free(core_globals->last_error_file);
1793 : }
1794 17039 : if (core_globals->disable_functions) {
1795 3 : free(core_globals->disable_functions);
1796 : }
1797 17039 : if (core_globals->disable_classes) {
1798 1 : free(core_globals->disable_classes);
1799 : }
1800 17039 : if (core_globals->allow_url_fopen_list) {
1801 17038 : free(core_globals->allow_url_fopen_list);
1802 : }
1803 17039 : if (core_globals->allow_url_include_list) {
1804 4 : free(core_globals->allow_url_include_list);
1805 : }
1806 :
1807 17039 : php_shutdown_ticks(TSRMLS_C);
1808 17039 : }
1809 : /* }}} */
1810 :
1811 43 : PHP_MINFO_FUNCTION(php_core) { /* {{{ */
1812 43 : php_info_print_table_start();
1813 43 : php_info_print_table_row(2, "PHP Version", PHP_VERSION);
1814 43 : php_info_print_table_end();
1815 43 : DISPLAY_INI_ENTRIES();
1816 43 : }
1817 : /* }}} */
1818 :
1819 : /* {{{ php_register_extensions
1820 : */
1821 : int php_register_extensions(zend_module_entry **ptr, int count TSRMLS_DC)
1822 34014 : {
1823 34014 : zend_module_entry **end = ptr + count;
1824 :
1825 1207822 : while (ptr < end) {
1826 1139794 : if (*ptr) {
1827 1139794 : if (zend_register_internal_module(*ptr TSRMLS_CC)==NULL) {
1828 0 : return FAILURE;
1829 : }
1830 : }
1831 1139794 : ptr++;
1832 : }
1833 34014 : return SUCCESS;
1834 : }
1835 : /* }}} */
1836 :
1837 : #if defined(PHP_WIN32) && defined(_MSC_VER) && (_MSC_VER >= 1400)
1838 : static _invalid_parameter_handler old_invalid_parameter_handler;
1839 :
1840 : void dummy_invalid_parameter_handler(
1841 : const wchar_t *expression,
1842 : const wchar_t *function,
1843 : const wchar_t *file,
1844 : unsigned int line,
1845 : uintptr_t pEwserved)
1846 : {
1847 : static int called = 0;
1848 : char buf[1024];
1849 : int len;
1850 :
1851 : if (!called) {
1852 : called = 1;
1853 : if (function) {
1854 : if (file) {
1855 : len = _snprintf(buf, sizeof(buf)-1, "Invalid parameter detected in CRT function '%ws' (%ws:%d)", function, file, line);
1856 : } else {
1857 : len = _snprintf(buf, sizeof(buf)-1, "Invalid parameter detected in CRT function '%ws'", function);
1858 : }
1859 : } else {
1860 : len = _snprintf(buf, sizeof(buf)-1, "Invalid CRT parameters detected");
1861 : }
1862 : zend_error(E_WARNING, "%s", buf);
1863 : called = 0;
1864 : }
1865 : }
1866 : #endif
1867 :
1868 : /* {{{ php_module_startup
1869 : */
1870 : int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_modules, uint num_additional_modules)
1871 17007 : {
1872 : zend_utility_functions zuf;
1873 : zend_utility_values zuv;
1874 17007 : int module_number=0; /* for REGISTER_INI_ENTRIES() */
1875 : char *php_os;
1876 : zend_module_entry *module;
1877 : #ifdef ZTS
1878 : zend_executor_globals *executor_globals;
1879 : void ***tsrm_ls;
1880 : php_core_globals *core_globals;
1881 : #endif
1882 : #if defined(PHP_WIN32) || (defined(NETWARE) && defined(USE_WINSOCK))
1883 : WORD wVersionRequested = MAKEWORD(2, 0);
1884 : WSADATA wsaData;
1885 : #endif
1886 : #ifdef PHP_WIN32
1887 : DWORD dwVersion = GetVersion();
1888 : /* Get build numbers for Windows NT or Win95 */
1889 : if (dwVersion < 0x80000000){
1890 : php_os="WINNT";
1891 : } else {
1892 : php_os="WIN32";
1893 : }
1894 : #if defined(_MSC_VER) && (_MSC_VER >= 1400)
1895 : old_invalid_parameter_handler =
1896 : _set_invalid_parameter_handler(dummy_invalid_parameter_handler);
1897 : if (old_invalid_parameter_handler != NULL) {
1898 : _set_invalid_parameter_handler(old_invalid_parameter_handler);
1899 : }
1900 : #endif
1901 : #else
1902 17007 : php_os=PHP_OS;
1903 : #endif
1904 :
1905 : #ifdef ZTS
1906 : tsrm_ls = ts_resource(0);
1907 : #endif
1908 :
1909 17007 : module_shutdown = 0;
1910 17007 : module_startup = 1;
1911 17007 : sapi_initialize_empty_request(TSRMLS_C);
1912 17007 : sapi_activate(TSRMLS_C);
1913 :
1914 17007 : if (module_initialized) {
1915 0 : return SUCCESS;
1916 : }
1917 :
1918 17007 : sapi_module = *sf;
1919 :
1920 17007 : php_output_startup();
1921 :
1922 17007 : zuf.error_function = php_error_cb;
1923 17007 : zuf.printf_function = php_printf;
1924 17007 : zuf.write_function = php_output_wrapper;
1925 17007 : zuf.path_encode_function = php_path_encode_for_zend;
1926 17007 : zuf.path_decode_function = php_path_decode_for_zend;
1927 17007 : zuf.fopen_function = php_fopen_wrapper_for_zend;
1928 17007 : zuf.message_handler = php_message_handler_for_zend;
1929 17007 : zuf.block_interruptions = sapi_module.block_interruptions;
1930 17007 : zuf.unblock_interruptions = sapi_module.unblock_interruptions;
1931 17007 : zuf.get_configuration_directive = php_get_configuration_directive_for_zend;
1932 17007 : zuf.ticks_function = php_run_ticks;
1933 17007 : zuf.on_timeout = php_on_timeout;
1934 17007 : zuf.stream_open_function = php_stream_open_for_zend;
1935 17007 : zuf.vspprintf_function = vspprintf;
1936 17007 : zuf.getenv_function = sapi_getenv;
1937 17007 : zuf.resolve_path_function = php_resolve_path_for_zend;
1938 17007 : zend_startup(&zuf, NULL TSRMLS_CC);
1939 :
1940 : #ifdef ZTS
1941 : executor_globals = ts_resource(executor_globals_id);
1942 : ts_allocate_id(&core_globals_id, sizeof(php_core_globals), (ts_allocate_ctor) core_globals_ctor, (ts_allocate_dtor) core_globals_dtor);
1943 : core_globals = ts_resource(core_globals_id);
1944 : #ifdef PHP_WIN32
1945 : ts_allocate_id(&php_win32_core_globals_id, sizeof(php_win32_core_globals), (ts_allocate_ctor) php_win32_core_globals_ctor, (ts_allocate_dtor) php_win32_core_globals_dtor);
1946 : #endif
1947 : #else
1948 17007 : php_startup_ticks(TSRMLS_C);
1949 : #endif
1950 17007 : gc_globals_ctor(TSRMLS_C);
1951 :
1952 : #ifdef PHP_WIN32
1953 : {
1954 : OSVERSIONINFOEX *osvi = &EG(windows_version_info);
1955 :
1956 : ZeroMemory(osvi, sizeof(OSVERSIONINFOEX));
1957 : osvi->dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
1958 : if( !GetVersionEx((OSVERSIONINFO *) osvi)) {
1959 : php_printf("\nGetVersionEx unusable. %d\n", GetLastError());
1960 : return FAILURE;
1961 : }
1962 : }
1963 : #endif
1964 17007 : EG(bailout) = NULL;
1965 17007 : EG(error_reporting) = E_ALL & ~E_NOTICE;
1966 :
1967 17007 : PG(header_is_being_sent) = 0;
1968 17007 : SG(request_info).headers_only = 0;
1969 17007 : SG(request_info).argv0 = NULL;
1970 17007 : SG(request_info).argc=0;
1971 17007 : SG(request_info).argv=(char **)NULL;
1972 17007 : PG(connection_status) = PHP_CONNECTION_NORMAL;
1973 17007 : PG(during_request_startup) = 0;
1974 17007 : PG(last_error_message) = NULL;
1975 17007 : PG(last_error_file) = NULL;
1976 17007 : PG(last_error_lineno) = 0;
1977 17007 : EG(error_handling) = EH_NORMAL;
1978 17007 : EG(exception_class) = NULL;
1979 17007 : PG(disable_functions) = NULL;
1980 17007 : PG(disable_classes) = NULL;
1981 17007 : PG(allow_url_fopen_list) = NULL;
1982 17007 : PG(allow_url_include_list) = NULL;
1983 :
1984 : #if HAVE_SETLOCALE
1985 17007 : setlocale(LC_CTYPE, "");
1986 : zend_update_current_locale();
1987 : #endif
1988 :
1989 : #if HAVE_TZSET
1990 17007 : tzset();
1991 : #endif
1992 :
1993 : #if defined(PHP_WIN32) || (defined(NETWARE) && defined(USE_WINSOCK))
1994 : /* start up winsock services */
1995 : if (WSAStartup(wVersionRequested, &wsaData) != 0) {
1996 : php_printf("\nwinsock.dll unusable. %d\n", WSAGetLastError());
1997 : return FAILURE;
1998 : }
1999 : #endif
2000 :
2001 17007 : le_index_ptr = zend_register_list_destructors_ex(NULL, NULL, "index pointer", 0);
2002 :
2003 : /* Register constants */
2004 : #ifdef ZTS
2005 : REGISTER_MAIN_LONG_CONSTANT("PHP_ZTS", 1, CONST_PERSISTENT | CONST_CS);
2006 : #else
2007 17007 : REGISTER_MAIN_LONG_CONSTANT("PHP_ZTS", 0, CONST_PERSISTENT | CONST_CS);
2008 : #endif
2009 17007 : REGISTER_MAIN_LONG_CONSTANT("PHP_MAJOR_VERSION", PHP_MAJOR_VERSION, CONST_PERSISTENT | CONST_CS);
2010 17007 : REGISTER_MAIN_LONG_CONSTANT("PHP_MINOR_VERSION", PHP_MINOR_VERSION, CONST_PERSISTENT | CONST_CS);
2011 17007 : REGISTER_MAIN_LONG_CONSTANT("PHP_RELEASE_VERSION", PHP_RELEASE_VERSION, CONST_PERSISTENT | CONST_CS);
2012 17007 : REGISTER_MAIN_STRINGL_CONSTANT("PHP_EXTRA_VERSION", PHP_EXTRA_VERSION, sizeof(PHP_EXTRA_VERSION) - 1, CONST_PERSISTENT | CONST_CS);
2013 17007 : REGISTER_MAIN_LONG_CONSTANT("PHP_VERSION_ID", PHP_VERSION_ID, CONST_PERSISTENT | CONST_CS);
2014 17007 : REGISTER_MAIN_LONG_CONSTANT("PHP_DEBUG", PHP_DEBUG, CONST_PERSISTENT | CONST_CS);
2015 17007 : REGISTER_MAIN_STRINGL_CONSTANT("PHP_VERSION", PHP_VERSION, sizeof(PHP_VERSION)-1, CONST_PERSISTENT | CONST_CS);
2016 17007 : REGISTER_MAIN_STRINGL_CONSTANT("PHP_OS", php_os, strlen(php_os), CONST_PERSISTENT | CONST_CS);
2017 17007 : REGISTER_MAIN_STRINGL_CONSTANT("PHP_SAPI", sapi_module.name, strlen(sapi_module.name), CONST_PERSISTENT | CONST_CS);
2018 17007 : REGISTER_MAIN_STRINGL_CONSTANT("DEFAULT_INCLUDE_PATH", PHP_INCLUDE_PATH, sizeof(PHP_INCLUDE_PATH)-1, CONST_PERSISTENT | CONST_CS);
2019 17007 : REGISTER_MAIN_STRINGL_CONSTANT("PHP_EXTENSION_DIR", PHP_EXTENSION_DIR, sizeof(PHP_EXTENSION_DIR)-1, CONST_PERSISTENT | CONST_CS);
2020 17007 : REGISTER_MAIN_STRINGL_CONSTANT("PHP_PREFIX", PHP_PREFIX, sizeof(PHP_PREFIX)-1, CONST_PERSISTENT | CONST_CS);
2021 17007 : REGISTER_MAIN_STRINGL_CONSTANT("PHP_BINDIR", PHP_BINDIR, sizeof(PHP_BINDIR)-1, CONST_PERSISTENT | CONST_CS);
2022 17007 : REGISTER_MAIN_STRINGL_CONSTANT("PHP_LIBDIR", PHP_LIBDIR, sizeof(PHP_LIBDIR)-1, CONST_PERSISTENT | CONST_CS);
2023 17007 : REGISTER_MAIN_STRINGL_CONSTANT("PHP_DATADIR", PHP_DATADIR, sizeof(PHP_DATADIR)-1, CONST_PERSISTENT | CONST_CS);
2024 17007 : REGISTER_MAIN_STRINGL_CONSTANT("PHP_SYSCONFDIR", PHP_SYSCONFDIR, sizeof(PHP_SYSCONFDIR)-1, CONST_PERSISTENT | CONST_CS);
2025 17007 : REGISTER_MAIN_STRINGL_CONSTANT("PHP_LOCALSTATEDIR", PHP_LOCALSTATEDIR, sizeof(PHP_LOCALSTATEDIR)-1, CONST_PERSISTENT | CONST_CS);
2026 17007 : REGISTER_MAIN_STRINGL_CONSTANT("PHP_CONFIG_FILE_PATH", PHP_CONFIG_FILE_PATH, strlen(PHP_CONFIG_FILE_PATH), CONST_PERSISTENT | CONST_CS);
2027 17007 : REGISTER_MAIN_STRINGL_CONSTANT("PHP_CONFIG_FILE_SCAN_DIR", PHP_CONFIG_FILE_SCAN_DIR, sizeof(PHP_CONFIG_FILE_SCAN_DIR)-1, CONST_PERSISTENT | CONST_CS);
2028 17007 : REGISTER_MAIN_STRINGL_CONSTANT("PHP_SHLIB_SUFFIX", PHP_SHLIB_SUFFIX, sizeof(PHP_SHLIB_SUFFIX)-1, CONST_PERSISTENT | CONST_CS);
2029 17007 : REGISTER_MAIN_STRINGL_CONSTANT("PHP_EOL", PHP_EOL, sizeof(PHP_EOL)-1, CONST_PERSISTENT | CONST_CS);
2030 17007 : REGISTER_MAIN_LONG_CONSTANT("PHP_MAXPATHLEN", MAXPATHLEN, CONST_PERSISTENT | CONST_CS);
2031 17007 : REGISTER_MAIN_LONG_CONSTANT("PHP_INT_MAX", LONG_MAX, CONST_PERSISTENT | CONST_CS);
2032 17007 : REGISTER_MAIN_LONG_CONSTANT("PHP_INT_SIZE", sizeof(long), CONST_PERSISTENT | CONST_CS);
2033 :
2034 : #ifdef PHP_WIN32
2035 : REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_VERSION_MAJOR", EG(windows_version_info).dwMajorVersion, CONST_PERSISTENT | CONST_CS);
2036 : REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_VERSION_MINOR", EG(windows_version_info).dwMinorVersion, CONST_PERSISTENT | CONST_CS);
2037 : REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_VERSION_BUILD", EG(windows_version_info).dwBuildNumber, CONST_PERSISTENT | CONST_CS);
2038 : REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_VERSION_PLATFORM", EG(windows_version_info).dwPlatformId, CONST_PERSISTENT | CONST_CS);
2039 : REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_VERSION_SP_MAJOR", EG(windows_version_info).wServicePackMajor, CONST_PERSISTENT | CONST_CS);
2040 : REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_VERSION_SP_MINOR", EG(windows_version_info).wServicePackMinor, CONST_PERSISTENT | CONST_CS);
2041 : REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_VERSION_SUITEMASK", EG(windows_version_info).wSuiteMask, CONST_PERSISTENT | CONST_CS);
2042 : REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_VERSION_PRODUCTTYPE", EG(windows_version_info).wProductType, CONST_PERSISTENT | CONST_CS);
2043 : REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_NT_DOMAIN_CONTROLLER", VER_NT_DOMAIN_CONTROLLER, CONST_PERSISTENT | CONST_CS);
2044 : REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_NT_SERVER", VER_NT_SERVER, CONST_PERSISTENT | CONST_CS);
2045 : REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_NT_WORKSTATION", VER_NT_WORKSTATION, CONST_PERSISTENT | CONST_CS);
2046 : #endif
2047 :
2048 17007 : php_output_register_constants(TSRMLS_C);
2049 17007 : php_rfc1867_register_constants(TSRMLS_C);
2050 :
2051 : /* this will read in php.ini, set up the configuration parameters,
2052 : load zend extensions and register php function extensions
2053 : to be loaded later */
2054 17007 : if (php_init_config(TSRMLS_C) == FAILURE) {
2055 0 : return FAILURE;
2056 : }
2057 :
2058 : /* Check for removed directives */
2059 : {
2060 : static const char *directives[] = {
2061 : "define_syslog_variables",
2062 : "register_globals",
2063 : "register_long_arrays",
2064 : "safe_mode",
2065 : "magic_quotes_gpc",
2066 : "magic_quotes_runtime",
2067 : "magic_quotes_sybase",
2068 : "zend.ze1_compatibility_mode",
2069 : NULL
2070 : };
2071 17007 : const char **p = directives;
2072 : long val;
2073 :
2074 170070 : while (*p) {
2075 136056 : if (cfg_get_long((char*)*p, &val) == SUCCESS && val) {
2076 4 : zend_error(E_ERROR, "Directive '%s' no longer exist in PHP 6 and greater", *p);
2077 : }
2078 136056 : ++p;
2079 : }
2080 : }
2081 :
2082 : /* Register PHP core ini entries */
2083 17007 : REGISTER_INI_ENTRIES();
2084 :
2085 : /* Register Zend ini entries */
2086 17007 : zend_register_standard_ini_entries(TSRMLS_C);
2087 :
2088 : /* Disable realpath cache if open_basedir are set */
2089 17007 : if ((PG(open_basedir) && *PG(open_basedir))) {
2090 73 : CWDG(realpath_cache_size_limit) = 0;
2091 : }
2092 :
2093 : /* initialize stream wrappers registry
2094 : * (this uses configuration parameters from php.ini)
2095 : */
2096 17007 : if (php_init_stream_wrappers(module_number TSRMLS_CC) == FAILURE) {
2097 0 : php_printf("PHP: Unable to initialize stream url wrappers.\n");
2098 0 : return FAILURE;
2099 : }
2100 :
2101 : /* Initialize unicode filters */
2102 17007 : if (php_stream_filter_register_factory("unicode.*", &php_unicode_filter_factory TSRMLS_CC) == FAILURE) {
2103 0 : php_printf("PHP: Unable to initialize unicode stream filters.\n");
2104 0 : return FAILURE;
2105 : }
2106 :
2107 : /* initialize registry for images to be used in phpinfo()
2108 : (this uses configuration parameters from php.ini)
2109 : */
2110 17007 : if (php_init_info_logos() == FAILURE) {
2111 0 : php_printf("PHP: Unable to initialize info phpinfo logos.\n");
2112 0 : return FAILURE;
2113 : }
2114 :
2115 17007 : zuv.html_errors = 1;
2116 17007 : zuv.import_use_extension = ".php";
2117 17007 : php_startup_auto_globals(TSRMLS_C);
2118 17007 : zend_set_utility_values(&zuv);
2119 17007 : php_startup_sapi_content_types(TSRMLS_C);
2120 :
2121 : /* startup extensions staticly compiled in */
2122 17007 : if (php_register_internal_extensions_func(TSRMLS_C) == FAILURE) {
2123 0 : php_printf("Unable to start builtin modules\n");
2124 0 : return FAILURE;
2125 : }
2126 :
2127 : /* start additional PHP extensions */
2128 17007 : php_register_extensions(&additional_modules, num_additional_modules TSRMLS_CC);
2129 :
2130 : /* load and startup extensions compiled as shared objects (aka DLLs)
2131 : as requested by php.ini entries
2132 : theese are loaded after initialization of internal extensions
2133 : as extensions *might* rely on things from ext/standard
2134 : which is always an internal extension and to be initialized
2135 : ahead of all other internals
2136 : */
2137 17007 : php_ini_register_extensions(TSRMLS_C);
2138 17007 : zend_startup_modules(TSRMLS_C);
2139 :
2140 : /* start Zend extensions */
2141 17007 : zend_startup_extensions();
2142 :
2143 : /* register additional functions */
2144 17007 : if (sapi_module.additional_functions) {
2145 16840 : if (zend_hash_find(&module_registry, "standard", sizeof("standard"), (void**)&module)==SUCCESS) {
2146 16840 : EG(current_module) = module;
2147 16840 : zend_register_functions(NULL, sapi_module.additional_functions, NULL, MODULE_PERSISTENT TSRMLS_CC);
2148 16840 : EG(current_module) = NULL;
2149 : }
2150 : }
2151 :
2152 : /* disable certain classes and functions as requested by php.ini */
2153 17007 : php_disable_functions(TSRMLS_C);
2154 17007 : php_disable_classes(TSRMLS_C);
2155 :
2156 : /* make core report what it should */
2157 17007 : if (zend_hash_find(&module_registry, "core", sizeof("core"), (void**)&module)==SUCCESS) {
2158 17007 : module->version = PHP_VERSION;
2159 17007 : module->info_func = PHP_MINFO(php_core);
2160 : }
2161 :
2162 :
2163 : #ifdef PHP_WIN32
2164 : /* Disable incompatible functions for the running platform */
2165 : if (php_win32_disable_functions() == FAILURE) {
2166 : php_printf("Unable to disable unsupported functions\n");
2167 : return FAILURE;
2168 : }
2169 : #endif
2170 :
2171 : #ifdef ZTS
2172 : zend_post_startup(TSRMLS_C);
2173 : #endif
2174 :
2175 17007 : module_initialized = 1;
2176 17007 : sapi_deactivate(TSRMLS_C);
2177 17007 : module_startup = 0;
2178 :
2179 17007 : shutdown_memory_manager(1, 0 TSRMLS_CC);
2180 :
2181 : /* we're done */
2182 17007 : return SUCCESS;
2183 : }
2184 : /* }}} */
2185 :
2186 : void php_module_shutdown_for_exec(void)
2187 0 : {
2188 : /* used to close fd's in the range 3.255 here, but it's problematic */
2189 0 : }
2190 :
2191 : /* {{{ php_module_shutdown_wrapper
2192 : */
2193 : int php_module_shutdown_wrapper(sapi_module_struct *sapi_globals)
2194 0 : {
2195 : TSRMLS_FETCH();
2196 0 : php_module_shutdown(TSRMLS_C);
2197 0 : return SUCCESS;
2198 : }
2199 : /* }}} */
2200 :
2201 : /* {{{ php_module_shutdown
2202 : */
2203 : void php_module_shutdown(TSRMLS_D)
2204 17039 : {
2205 17039 : int module_number=0; /* for UNREGISTER_INI_ENTRIES() */
2206 :
2207 17039 : module_shutdown = 1;
2208 :
2209 17039 : if (!module_initialized) {
2210 0 : return;
2211 : }
2212 :
2213 : #ifdef ZTS
2214 : ts_free_worker_threads();
2215 : #endif
2216 :
2217 : #if defined(PHP_WIN32) || (defined(NETWARE) && defined(USE_WINSOCK))
2218 : /*close winsock */
2219 : WSACleanup();
2220 : #endif
2221 :
2222 17039 : sapi_flush(TSRMLS_C);
2223 :
2224 17039 : zend_shutdown(TSRMLS_C);
2225 :
2226 : /* Destroys filter & transport registries too */
2227 17039 : php_shutdown_stream_wrappers(module_number TSRMLS_CC);
2228 :
2229 17039 : php_shutdown_info_logos();
2230 17039 : UNREGISTER_INI_ENTRIES();
2231 :
2232 : /* close down the ini config */
2233 17039 : php_shutdown_config();
2234 :
2235 : #ifndef ZTS
2236 17039 : zend_ini_shutdown(TSRMLS_C);
2237 17039 : shutdown_memory_manager(CG(unclean_shutdown), 1 TSRMLS_CC);
2238 : #else
2239 : zend_ini_global_shutdown(TSRMLS_C);
2240 : #endif
2241 :
2242 17039 : php_output_shutdown();
2243 17039 : php_shutdown_temporary_directory();
2244 :
2245 17039 : module_initialized = 0;
2246 :
2247 : #ifndef ZTS
2248 17039 : core_globals_dtor(&core_globals TSRMLS_CC);
2249 17039 : gc_globals_dtor(TSRMLS_C);
2250 : #else
2251 : ts_free_id(core_globals_id);
2252 : #endif
2253 :
2254 : #if defined(PHP_WIN32) && defined(_MSC_VER) && (_MSC_VER >= 1400)
2255 : if (old_invalid_parameter_handler == NULL) {
2256 : _set_invalid_parameter_handler(old_invalid_parameter_handler);
2257 : }
2258 : #endif
2259 : }
2260 : /* }}} */
2261 :
2262 : /* {{{ php_execute_script
2263 : */
2264 : PHPAPI int php_execute_script(zend_file_handle *primary_file TSRMLS_DC)
2265 16913 : {
2266 : zend_file_handle *prepend_file_p, *append_file_p;
2267 16913 : zend_file_handle prepend_file = {0}, append_file = {0};
2268 : #if HAVE_BROKEN_GETCWD
2269 : int old_cwd_fd = -1;
2270 : #else
2271 : char *old_cwd;
2272 : ALLOCA_FLAG(use_heap)
2273 : #endif
2274 16913 : int retval = 0;
2275 :
2276 16913 : EG(exit_status) = 0;
2277 16913 : if (php_handle_special_queries(TSRMLS_C)) {
2278 0 : zend_file_handle_dtor(primary_file TSRMLS_CC);
2279 0 : return 0;
2280 : }
2281 : #ifndef HAVE_BROKEN_GETCWD
2282 : # define OLD_CWD_SIZE 4096
2283 16913 : old_cwd = do_alloca(OLD_CWD_SIZE, use_heap);
2284 16913 : old_cwd[0] = '\0';
2285 : #endif
2286 :
2287 16913 : zend_try {
2288 : char realfile[MAXPATHLEN];
2289 :
2290 : #ifdef PHP_WIN32
2291 : if(primary_file->filename) {
2292 : UpdateIniFromRegistry(primary_file->filename TSRMLS_CC);
2293 : }
2294 : #endif
2295 :
2296 16913 : PG(during_request_startup) = 0;
2297 :
2298 16913 : if (primary_file->filename && !(SG(options) & SAPI_OPTION_NO_CHDIR)) {
2299 : #if HAVE_BROKEN_GETCWD
2300 : /* this looks nasty to me */
2301 : old_cwd_fd = open(".", 0);
2302 : #else
2303 187 : VCWD_GETCWD(old_cwd, OLD_CWD_SIZE-1);
2304 : #endif
2305 187 : VCWD_CHDIR_FILE(primary_file->filename);
2306 : }
2307 :
2308 : /* Only lookup the real file path and add it to the included_files list if already opened
2309 : * otherwise it will get opened and added to the included_files list in zend_execute_scripts
2310 : */
2311 16913 : if (primary_file->filename &&
2312 : primary_file->opened_path == NULL &&
2313 : primary_file->type != ZEND_HANDLE_FILENAME
2314 : ) {
2315 : int realfile_len;
2316 16602 : int dummy = 1;
2317 16602 : if (VCWD_REALPATH(primary_file->filename, realfile)) {
2318 16598 : realfile_len = strlen(realfile);
2319 16598 : zend_hash_add(&EG(included_files), realfile, realfile_len+1, (void *)&dummy, sizeof(int), NULL);
2320 16598 : primary_file->opened_path = estrndup(realfile, realfile_len);
2321 : }
2322 : }
2323 :
2324 16914 : if (PG(auto_prepend_file) && PG(auto_prepend_file)[0]) {
2325 1 : prepend_file.filename = PG(auto_prepend_file);
2326 1 : prepend_file.opened_path = NULL;
2327 1 : prepend_file.free_filename = 0;
2328 1 : prepend_file.type = ZEND_HANDLE_FILENAME;
2329 1 : prepend_file_p = &prepend_file;
2330 : } else {
2331 16912 : prepend_file_p = NULL;
2332 : }
2333 :
2334 16913 : if (PG(auto_append_file) && PG(auto_append_file)[0]) {
2335 0 : append_file.filename = PG(auto_append_file);
2336 0 : append_file.opened_path = NULL;
2337 0 : append_file.free_filename = 0;
2338 0 : append_file.type = ZEND_HANDLE_FILENAME;
2339 0 : append_file_p = &append_file;
2340 : } else {
2341 16913 : append_file_p = NULL;
2342 : }
2343 16913 : if (PG(max_input_time) != -1) {
2344 : #ifdef PHP_WIN32
2345 : zend_unset_timeout(TSRMLS_C);
2346 : #endif
2347 0 : zend_set_timeout(INI_INT("max_execution_time"), 0);
2348 : }
2349 16913 : retval = (zend_execute_scripts(ZEND_REQUIRE TSRMLS_CC, NULL, 3, prepend_file_p, primary_file, append_file_p) == SUCCESS);
2350 :
2351 16948 : } zend_end_try();
2352 :
2353 : #if HAVE_BROKEN_GETCWD
2354 : if (old_cwd_fd != -1) {
2355 : fchdir(old_cwd_fd);
2356 : close(old_cwd_fd);
2357 : }
2358 : #else
2359 16948 : if (old_cwd[0] != '\0') {
2360 187 : VCWD_CHDIR(old_cwd);
2361 : }
2362 16948 : free_alloca(old_cwd, use_heap);
2363 : #endif
2364 16948 : return retval;
2365 : }
2366 : /* }}} */
2367 :
2368 : /* {{{ php_execute_simple_script
2369 : */
2370 : PHPAPI int php_execute_simple_script(zend_file_handle *primary_file, zval **ret TSRMLS_DC)
2371 0 : {
2372 : char *old_cwd;
2373 : ALLOCA_FLAG(use_heap)
2374 :
2375 0 : EG(exit_status) = 0;
2376 : #define OLD_CWD_SIZE 4096
2377 0 : old_cwd = do_alloca(OLD_CWD_SIZE, use_heap);
2378 0 : old_cwd[0] = '\0';
2379 :
2380 0 : zend_try {
2381 : #ifdef PHP_WIN32
2382 : if(primary_file->filename) {
2383 : UpdateIniFromRegistry(primary_file->filename TSRMLS_CC);
2384 : }
2385 : #endif
2386 :
2387 0 : PG(during_request_startup) = 0;
2388 :
2389 0 : if (primary_file->filename && !(SG(options) & SAPI_OPTION_NO_CHDIR)) {
2390 0 : VCWD_GETCWD(old_cwd, OLD_CWD_SIZE-1);
2391 0 : VCWD_CHDIR_FILE(primary_file->filename);
2392 : }
2393 0 : zend_execute_scripts(ZEND_REQUIRE TSRMLS_CC, ret, 1, primary_file);
2394 0 : } zend_end_try();
2395 :
2396 0 : if (old_cwd[0] != '\0') {
2397 0 : VCWD_CHDIR(old_cwd);
2398 : }
2399 :
2400 0 : free_alloca(old_cwd, use_heap);
2401 0 : return EG(exit_status);
2402 : }
2403 : /* }}} */
2404 :
2405 : /* {{{ php_handle_aborted_connection
2406 : */
2407 : PHPAPI void php_handle_aborted_connection(void)
2408 3 : {
2409 : TSRMLS_FETCH();
2410 :
2411 3 : PG(connection_status) = PHP_CONNECTION_ABORTED;
2412 3 : php_output_set_status(PHP_OUTPUT_DISABLED TSRMLS_CC);
2413 :
2414 3 : if (!PG(ignore_user_abort)) {
2415 3 : zend_bailout();
2416 : }
2417 0 : }
2418 : /* }}} */
2419 :
2420 : /* {{{ php_handle_auth_data
2421 : */
2422 : PHPAPI int php_handle_auth_data(const char *auth TSRMLS_DC)
2423 171 : {
2424 171 : int ret = -1;
2425 :
2426 171 : if (auth && auth[0] != '\0' && strncmp(auth, "Basic ", 6) == 0) {
2427 : char *pass;
2428 : char *user;
2429 :
2430 0 : user = (char*)php_base64_decode((unsigned char*)auth + 6, strlen(auth) - 6, NULL);
2431 0 : if (user) {
2432 0 : pass = strchr(user, ':');
2433 0 : if (pass) {
2434 0 : *pass++ = '\0';
2435 0 : SG(request_info).auth_user = user;
2436 0 : SG(request_info).auth_password = estrdup(pass);
2437 0 : ret = 0;
2438 : } else {
2439 0 : efree(user);
2440 : }
2441 : }
2442 : }
2443 :
2444 171 : if (ret == -1) {
2445 171 : SG(request_info).auth_user = SG(request_info).auth_password = NULL;
2446 : } else {
2447 0 : SG(request_info).auth_digest = NULL;
2448 : }
2449 :
2450 171 : if (ret == -1 && auth && auth[0] != '\0' && strncmp(auth, "Digest ", 7) == 0) {
2451 0 : SG(request_info).auth_digest = estrdup(auth + 7);
2452 0 : ret = 0;
2453 : }
2454 :
2455 171 : if (ret == -1) {
2456 171 : SG(request_info).auth_digest = NULL;
2457 : }
2458 :
2459 171 : return ret;
2460 : }
2461 : /* }}} */
2462 :
2463 : /* {{{ php_lint_script
2464 : */
2465 : PHPAPI int php_lint_script(zend_file_handle *file TSRMLS_DC)
2466 5 : {
2467 : zend_op_array *op_array;
2468 5 : int retval = FAILURE;
2469 :
2470 5 : zend_try {
2471 5 : op_array = zend_compile_file(file, ZEND_INCLUDE TSRMLS_CC);
2472 3 : zend_destroy_file_handle(file TSRMLS_CC);
2473 :
2474 3 : if (op_array) {
2475 3 : destroy_op_array(op_array TSRMLS_CC);
2476 3 : efree(op_array);
2477 3 : retval = SUCCESS;
2478 : }
2479 5 : } zend_end_try();
2480 :
2481 5 : return retval;
2482 : }
2483 : /* }}} */
2484 :
2485 : #ifdef PHP_WIN32
2486 : /* {{{ dummy_indent
2487 : just so that this symbol gets exported... */
2488 : PHPAPI void dummy_indent(void)
2489 : {
2490 : zend_indent();
2491 : }
2492 : /* }}} */
2493 : #endif
2494 :
2495 : /*
2496 : * Local variables:
2497 : * tab-width: 4
2498 : * c-basic-offset: 4
2499 : * End:
2500 : * vim600: sw=4 ts=4 fdm=marker
2501 : * vim<600: sw=4 ts=4
2502 : */
|