1 : /*
2 : +----------------------------------------------------------------------+
3 : | PHP Version 5 |
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 290567 2009-11-12 00:10:00Z felipe $ */
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 :
85 : #include "php_content_types.h"
86 : #include "php_ticks.h"
87 : #include "php_logos.h"
88 : #include "php_streams.h"
89 : #include "php_open_temporary_file.h"
90 :
91 : #include "SAPI.h"
92 : #include "rfc1867.h"
93 : /* }}} */
94 :
95 : #ifndef ZTS
96 : php_core_globals core_globals;
97 : #else
98 : PHPAPI int core_globals_id;
99 : #endif
100 :
101 : #define SAFE_FILENAME(f) ((f)?(f):"-")
102 :
103 : /* {{{ PHP_INI_MH
104 : */
105 : static PHP_INI_MH(OnSetPrecision)
106 13567 : {
107 13567 : int i = atoi(new_value);
108 13567 : if (i >= 0) {
109 13567 : EG(precision) = i;
110 13567 : return SUCCESS;
111 : } else {
112 0 : return FAILURE;
113 : }
114 : }
115 : /* }}} */
116 :
117 : /* {{{ PHP_INI_MH
118 : */
119 : static PHP_INI_MH(OnChangeMemoryLimit)
120 13569 : {
121 13569 : if (new_value) {
122 13569 : PG(memory_limit) = zend_atoi(new_value, new_value_length);
123 : } else {
124 0 : PG(memory_limit) = 1<<30; /* effectively, no limit */
125 : }
126 13569 : return zend_set_memory_limit(PG(memory_limit));
127 : }
128 : /* }}} */
129 :
130 :
131 : /* {{{ php_disable_functions
132 : */
133 : static void php_disable_functions(TSRMLS_D)
134 13565 : {
135 13565 : char *s = NULL, *e;
136 :
137 13565 : if (!*(INI_STR("disable_functions"))) {
138 13562 : return;
139 : }
140 :
141 3 : e = PG(disable_functions) = strdup(INI_STR("disable_functions"));
142 :
143 27 : while (*e) {
144 21 : switch (*e) {
145 : case ' ':
146 : case ',':
147 0 : if (s) {
148 0 : *e = '\0';
149 0 : zend_disable_function(s, e-s TSRMLS_CC);
150 0 : s = NULL;
151 : }
152 0 : break;
153 : default:
154 21 : if (!s) {
155 3 : s = e;
156 : }
157 : break;
158 : }
159 21 : e++;
160 : }
161 3 : if (s) {
162 3 : zend_disable_function(s, e-s TSRMLS_CC);
163 : }
164 : }
165 : /* }}} */
166 :
167 : /* {{{ php_disable_classes
168 : */
169 : static void php_disable_classes(TSRMLS_D)
170 13565 : {
171 13565 : char *s = NULL, *e;
172 :
173 13565 : if (!*(INI_STR("disable_classes"))) {
174 13564 : return;
175 : }
176 :
177 1 : e = PG(disable_classes) = strdup(INI_STR("disable_classes"));
178 :
179 10 : while (*e) {
180 8 : switch (*e) {
181 : case ' ':
182 : case ',':
183 0 : if (s) {
184 0 : *e = '\0';
185 0 : zend_disable_class(s, e-s TSRMLS_CC);
186 0 : s = NULL;
187 : }
188 0 : break;
189 : default:
190 8 : if (!s) {
191 1 : s = e;
192 : }
193 : break;
194 : }
195 8 : e++;
196 : }
197 1 : if (s) {
198 1 : zend_disable_class(s, e-s TSRMLS_CC);
199 : }
200 : }
201 : /* }}} */
202 :
203 : /* {{{ PHP_INI_MH
204 : */
205 : static PHP_INI_MH(OnUpdateTimeout)
206 13591 : {
207 13591 : if (stage==PHP_INI_STAGE_STARTUP) {
208 : /* Don't set a timeout on startup, only per-request */
209 13565 : EG(timeout_seconds) = atoi(new_value);
210 13565 : return SUCCESS;
211 : }
212 26 : zend_unset_timeout(TSRMLS_C);
213 26 : EG(timeout_seconds) = atoi(new_value);
214 26 : zend_set_timeout(EG(timeout_seconds));
215 26 : return SUCCESS;
216 : }
217 : /* }}} */
218 :
219 : /* {{{ php_get_display_errors_mode() helper function
220 : */
221 : static int php_get_display_errors_mode(char *value, int value_length)
222 13581 : {
223 : int mode;
224 :
225 13581 : if (!value) {
226 0 : return PHP_DISPLAY_ERRORS_STDOUT;
227 : }
228 :
229 13582 : if (value_length == 2 && !strcasecmp("on", value)) {
230 1 : mode = PHP_DISPLAY_ERRORS_STDOUT;
231 13580 : } else if (value_length == 3 && !strcasecmp("yes", value)) {
232 0 : mode = PHP_DISPLAY_ERRORS_STDOUT;
233 13580 : } else if (value_length == 4 && !strcasecmp("true", value)) {
234 0 : mode = PHP_DISPLAY_ERRORS_STDOUT;
235 13580 : } else if (value_length == 6 && !strcasecmp(value, "stderr")) {
236 0 : mode = PHP_DISPLAY_ERRORS_STDERR;
237 13582 : } else if (value_length == 6 && !strcasecmp(value, "stdout")) {
238 2 : mode = PHP_DISPLAY_ERRORS_STDOUT;
239 : } else {
240 13578 : mode = atoi(value);
241 13578 : if (mode && mode != PHP_DISPLAY_ERRORS_STDOUT && mode != PHP_DISPLAY_ERRORS_STDERR) {
242 0 : mode = PHP_DISPLAY_ERRORS_STDOUT;
243 : }
244 : }
245 :
246 13581 : return mode;
247 : }
248 : /* }}} */
249 :
250 : /* {{{ PHP_INI_MH
251 : */
252 : static PHP_INI_MH(OnUpdateDisplayErrors)
253 13575 : {
254 13575 : PG(display_errors) = (zend_bool) php_get_display_errors_mode(new_value, new_value_length);
255 :
256 13575 : return SUCCESS;
257 : }
258 : /* }}} */
259 :
260 : /* {{{ PHP_INI_DISP
261 : */
262 : static PHP_INI_DISP(display_errors_mode)
263 6 : {
264 : int mode, tmp_value_length, cgi_or_cli;
265 : char *tmp_value;
266 : TSRMLS_FETCH();
267 :
268 6 : if (type == ZEND_INI_DISPLAY_ORIG && ini_entry->modified) {
269 0 : tmp_value = (ini_entry->orig_value ? ini_entry->orig_value : NULL );
270 0 : tmp_value_length = ini_entry->orig_value_length;
271 6 : } else if (ini_entry->value) {
272 6 : tmp_value = ini_entry->value;
273 6 : tmp_value_length = ini_entry->value_length;
274 : } else {
275 0 : tmp_value = NULL;
276 0 : tmp_value_length = 0;
277 : }
278 :
279 6 : mode = php_get_display_errors_mode(tmp_value, tmp_value_length);
280 :
281 : /* Display 'On' for other SAPIs instead of STDOUT or STDERR */
282 6 : cgi_or_cli = (!strcmp(sapi_module.name, "cli") || !strcmp(sapi_module.name, "cgi"));
283 :
284 6 : switch (mode) {
285 : case PHP_DISPLAY_ERRORS_STDERR:
286 0 : if (cgi_or_cli ) {
287 0 : PUTS("STDERR");
288 : } else {
289 0 : PUTS("On");
290 : }
291 0 : break;
292 :
293 : case PHP_DISPLAY_ERRORS_STDOUT:
294 6 : if (cgi_or_cli ) {
295 6 : PUTS("STDOUT");
296 : } else {
297 0 : PUTS("On");
298 : }
299 6 : break;
300 :
301 : default:
302 0 : PUTS("Off");
303 : break;
304 : }
305 6 : }
306 : /* }}} */
307 :
308 : /* {{{ PHP_INI_MH
309 : */
310 : static PHP_INI_MH(OnUpdateErrorLog)
311 13568 : {
312 : /* Only do the safemode/open_basedir check at runtime */
313 13568 : if ((stage == PHP_INI_STAGE_RUNTIME || stage == PHP_INI_STAGE_HTACCESS) && new_value && strcmp(new_value, "syslog")) {
314 2 : if (PG(safe_mode) && (!php_checkuid(new_value, NULL, CHECKUID_CHECK_FILE_AND_DIR))) {
315 0 : return FAILURE;
316 : }
317 :
318 2 : if (PG(open_basedir) && php_check_open_basedir(new_value TSRMLS_CC)) {
319 0 : return FAILURE;
320 : }
321 :
322 : }
323 13568 : OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
324 13568 : return SUCCESS;
325 : }
326 : /* }}} */
327 :
328 : /* {{{ PHP_INI_MH
329 : */
330 : static PHP_INI_MH(OnChangeMailForceExtra)
331 13565 : {
332 : /* Don't allow changing it in htaccess */
333 13565 : if (stage == PHP_INI_STAGE_HTACCESS) {
334 0 : return FAILURE;
335 : }
336 13565 : return SUCCESS;
337 : }
338 : /* }}} */
339 :
340 :
341 : /* Need to convert to strings and make use of:
342 : * PHP_SAFE_MODE
343 : *
344 : * Need to be read from the environment (?):
345 : * PHP_AUTO_PREPEND_FILE
346 : * PHP_AUTO_APPEND_FILE
347 : * PHP_DOCUMENT_ROOT
348 : * PHP_USER_DIR
349 : * PHP_INCLUDE_PATH
350 : */
351 :
352 : #ifndef PHP_SAFE_MODE_EXEC_DIR
353 : # define PHP_SAFE_MODE_EXEC_DIR ""
354 : #endif
355 :
356 : /* Windows and Netware use the internal mail */
357 : #if defined(PHP_WIN32) || defined(NETWARE)
358 : # define DEFAULT_SENDMAIL_PATH NULL
359 : #elif defined(PHP_PROG_SENDMAIL)
360 : # define DEFAULT_SENDMAIL_PATH PHP_PROG_SENDMAIL " -t -i "
361 : #else
362 : # define DEFAULT_SENDMAIL_PATH "/usr/sbin/sendmail -t -i"
363 : #endif
364 :
365 : /* {{{ PHP_INI
366 : */
367 : PHP_INI_BEGIN()
368 : PHP_INI_ENTRY_EX("define_syslog_variables", "0", PHP_INI_ALL, NULL, php_ini_boolean_displayer_cb)
369 : PHP_INI_ENTRY_EX("highlight.bg", HL_BG_COLOR, PHP_INI_ALL, NULL, php_ini_color_displayer_cb)
370 : PHP_INI_ENTRY_EX("highlight.comment", HL_COMMENT_COLOR, PHP_INI_ALL, NULL, php_ini_color_displayer_cb)
371 : PHP_INI_ENTRY_EX("highlight.default", HL_DEFAULT_COLOR, PHP_INI_ALL, NULL, php_ini_color_displayer_cb)
372 : PHP_INI_ENTRY_EX("highlight.html", HL_HTML_COLOR, PHP_INI_ALL, NULL, php_ini_color_displayer_cb)
373 : PHP_INI_ENTRY_EX("highlight.keyword", HL_KEYWORD_COLOR, PHP_INI_ALL, NULL, php_ini_color_displayer_cb)
374 : PHP_INI_ENTRY_EX("highlight.string", HL_STRING_COLOR, PHP_INI_ALL, NULL, php_ini_color_displayer_cb)
375 :
376 : STD_PHP_INI_BOOLEAN("allow_call_time_pass_reference", "1", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateBool, allow_call_time_pass_reference, zend_compiler_globals, compiler_globals)
377 : STD_PHP_INI_BOOLEAN("asp_tags", "0", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateBool, asp_tags, zend_compiler_globals, compiler_globals)
378 : STD_PHP_INI_ENTRY_EX("display_errors", "1", PHP_INI_ALL, OnUpdateDisplayErrors, display_errors, php_core_globals, core_globals, display_errors_mode)
379 : STD_PHP_INI_BOOLEAN("display_startup_errors", "0", PHP_INI_ALL, OnUpdateBool, display_startup_errors, php_core_globals, core_globals)
380 : STD_PHP_INI_BOOLEAN("enable_dl", "1", PHP_INI_SYSTEM, OnUpdateBool, enable_dl, php_core_globals, core_globals)
381 : STD_PHP_INI_BOOLEAN("expose_php", "1", PHP_INI_SYSTEM, OnUpdateBool, expose_php, php_core_globals, core_globals)
382 : STD_PHP_INI_ENTRY("docref_root", "", PHP_INI_ALL, OnUpdateString, docref_root, php_core_globals, core_globals)
383 : STD_PHP_INI_ENTRY("docref_ext", "", PHP_INI_ALL, OnUpdateString, docref_ext, php_core_globals, core_globals)
384 : STD_PHP_INI_BOOLEAN("html_errors", "1", PHP_INI_ALL, OnUpdateBool, html_errors, php_core_globals, core_globals)
385 : STD_PHP_INI_BOOLEAN("xmlrpc_errors", "0", PHP_INI_SYSTEM, OnUpdateBool, xmlrpc_errors, php_core_globals, core_globals)
386 : STD_PHP_INI_ENTRY("xmlrpc_error_number", "0", PHP_INI_ALL, OnUpdateLong, xmlrpc_error_number, php_core_globals, core_globals)
387 : STD_PHP_INI_ENTRY("max_input_time", "-1", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateLong, max_input_time, php_core_globals, core_globals)
388 : STD_PHP_INI_BOOLEAN("ignore_user_abort", "0", PHP_INI_ALL, OnUpdateBool, ignore_user_abort, php_core_globals, core_globals)
389 : STD_PHP_INI_BOOLEAN("implicit_flush", "0", PHP_INI_ALL, OnUpdateBool, implicit_flush, php_core_globals, core_globals)
390 : STD_PHP_INI_BOOLEAN("log_errors", "0", PHP_INI_ALL, OnUpdateBool, log_errors, php_core_globals, core_globals)
391 : STD_PHP_INI_ENTRY("log_errors_max_len", "1024", PHP_INI_ALL, OnUpdateLong, log_errors_max_len, php_core_globals, core_globals)
392 : STD_PHP_INI_BOOLEAN("ignore_repeated_errors", "0", PHP_INI_ALL, OnUpdateBool, ignore_repeated_errors, php_core_globals, core_globals)
393 : STD_PHP_INI_BOOLEAN("ignore_repeated_source", "0", PHP_INI_ALL, OnUpdateBool, ignore_repeated_source, php_core_globals, core_globals)
394 : STD_PHP_INI_BOOLEAN("report_memleaks", "1", PHP_INI_ALL, OnUpdateBool, report_memleaks, php_core_globals, core_globals)
395 : STD_PHP_INI_BOOLEAN("report_zend_debug", "1", PHP_INI_ALL, OnUpdateBool, report_zend_debug, php_core_globals, core_globals)
396 : STD_PHP_INI_BOOLEAN("magic_quotes_gpc", "1", PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateBool, magic_quotes_gpc, php_core_globals, core_globals)
397 : STD_PHP_INI_BOOLEAN("magic_quotes_runtime", "0", PHP_INI_ALL, OnUpdateBool, magic_quotes_runtime, php_core_globals, core_globals)
398 : STD_PHP_INI_BOOLEAN("magic_quotes_sybase", "0", PHP_INI_ALL, OnUpdateBool, magic_quotes_sybase, php_core_globals, core_globals)
399 : STD_PHP_INI_ENTRY("output_buffering", "0", PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateLong, output_buffering, php_core_globals, core_globals)
400 : STD_PHP_INI_ENTRY("output_handler", NULL, PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateString, output_handler, php_core_globals, core_globals)
401 : STD_PHP_INI_BOOLEAN("register_argc_argv", "1", PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateBool, register_argc_argv, php_core_globals, core_globals)
402 : STD_PHP_INI_BOOLEAN("register_globals", "0", PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateBool, register_globals, php_core_globals, core_globals)
403 : STD_PHP_INI_BOOLEAN("register_long_arrays", "1", PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateBool, register_long_arrays, php_core_globals, core_globals)
404 : STD_PHP_INI_BOOLEAN("auto_globals_jit", "1", PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateBool, auto_globals_jit, php_core_globals, core_globals)
405 : #if PHP_SAFE_MODE
406 : STD_PHP_INI_BOOLEAN("safe_mode", "1", PHP_INI_SYSTEM, OnUpdateBool, safe_mode, php_core_globals, core_globals)
407 : #else
408 : STD_PHP_INI_BOOLEAN("safe_mode", "0", PHP_INI_SYSTEM, OnUpdateBool, safe_mode, php_core_globals, core_globals)
409 : #endif
410 : STD_PHP_INI_ENTRY("safe_mode_include_dir", NULL, PHP_INI_SYSTEM, OnUpdateString, safe_mode_include_dir, php_core_globals, core_globals)
411 : STD_PHP_INI_BOOLEAN("safe_mode_gid", "0", PHP_INI_SYSTEM, OnUpdateBool, safe_mode_gid, php_core_globals, core_globals)
412 : 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)
413 : STD_PHP_INI_BOOLEAN("sql.safe_mode", "0", PHP_INI_SYSTEM, OnUpdateBool, sql_safe_mode, php_core_globals, core_globals)
414 : STD_PHP_INI_BOOLEAN("track_errors", "0", PHP_INI_ALL, OnUpdateBool, track_errors, php_core_globals, core_globals)
415 : STD_PHP_INI_BOOLEAN("y2k_compliance", "1", PHP_INI_ALL, OnUpdateBool, y2k_compliance, php_core_globals, core_globals)
416 :
417 : STD_PHP_INI_ENTRY("unserialize_callback_func", NULL, PHP_INI_ALL, OnUpdateString, unserialize_callback_func, php_core_globals, core_globals)
418 : STD_PHP_INI_ENTRY("serialize_precision", "100", PHP_INI_ALL, OnUpdateLongGEZero, serialize_precision, php_core_globals, core_globals)
419 : STD_PHP_INI_ENTRY("arg_separator.output", "&", PHP_INI_ALL, OnUpdateStringUnempty, arg_separator.output, php_core_globals, core_globals)
420 : STD_PHP_INI_ENTRY("arg_separator.input", "&", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateStringUnempty, arg_separator.input, php_core_globals, core_globals)
421 :
422 : STD_PHP_INI_ENTRY("auto_append_file", NULL, PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateString, auto_append_file, php_core_globals, core_globals)
423 : STD_PHP_INI_ENTRY("auto_prepend_file", NULL, PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateString, auto_prepend_file, php_core_globals, core_globals)
424 : STD_PHP_INI_ENTRY("doc_root", NULL, PHP_INI_SYSTEM, OnUpdateStringUnempty, doc_root, php_core_globals, core_globals)
425 : STD_PHP_INI_ENTRY("default_charset", SAPI_DEFAULT_CHARSET, PHP_INI_ALL, OnUpdateString, default_charset, sapi_globals_struct,sapi_globals)
426 : STD_PHP_INI_ENTRY("default_mimetype", SAPI_DEFAULT_MIMETYPE, PHP_INI_ALL, OnUpdateString, default_mimetype, sapi_globals_struct,sapi_globals)
427 : STD_PHP_INI_ENTRY("error_log", NULL, PHP_INI_ALL, OnUpdateErrorLog, error_log, php_core_globals, core_globals)
428 : STD_PHP_INI_ENTRY("extension_dir", PHP_EXTENSION_DIR, PHP_INI_SYSTEM, OnUpdateStringUnempty, extension_dir, php_core_globals, core_globals)
429 : STD_PHP_INI_ENTRY("include_path", PHP_INCLUDE_PATH, PHP_INI_ALL, OnUpdateStringUnempty, include_path, php_core_globals, core_globals)
430 : PHP_INI_ENTRY("max_execution_time", "30", PHP_INI_ALL, OnUpdateTimeout)
431 : STD_PHP_INI_ENTRY("open_basedir", NULL, PHP_INI_SYSTEM, OnUpdateString, open_basedir, php_core_globals, core_globals)
432 : STD_PHP_INI_ENTRY("safe_mode_exec_dir", PHP_SAFE_MODE_EXEC_DIR, PHP_INI_SYSTEM, OnUpdateString, safe_mode_exec_dir, php_core_globals, core_globals)
433 :
434 : STD_PHP_INI_BOOLEAN("file_uploads", "1", PHP_INI_SYSTEM, OnUpdateBool, file_uploads, php_core_globals, core_globals)
435 : STD_PHP_INI_ENTRY("upload_max_filesize", "2M", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateLong, upload_max_filesize, php_core_globals, core_globals)
436 : STD_PHP_INI_ENTRY("post_max_size", "8M", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateLong, post_max_size, sapi_globals_struct,sapi_globals)
437 : STD_PHP_INI_ENTRY("upload_tmp_dir", NULL, PHP_INI_SYSTEM, OnUpdateStringUnempty, upload_tmp_dir, php_core_globals, core_globals)
438 : 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)
439 :
440 : STD_PHP_INI_ENTRY("user_dir", NULL, PHP_INI_SYSTEM, OnUpdateString, user_dir, php_core_globals, core_globals)
441 : STD_PHP_INI_ENTRY("variables_order", "EGPCS", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateStringUnempty, variables_order, php_core_globals, core_globals)
442 :
443 : STD_PHP_INI_ENTRY("error_append_string", NULL, PHP_INI_ALL, OnUpdateString, error_append_string, php_core_globals, core_globals)
444 : STD_PHP_INI_ENTRY("error_prepend_string", NULL, PHP_INI_ALL, OnUpdateString, error_prepend_string, php_core_globals, core_globals)
445 :
446 : PHP_INI_ENTRY("SMTP", "localhost",PHP_INI_ALL, NULL)
447 : PHP_INI_ENTRY("smtp_port", "25", PHP_INI_ALL, NULL)
448 : PHP_INI_ENTRY("browscap", NULL, PHP_INI_SYSTEM, NULL)
449 : PHP_INI_ENTRY("memory_limit", "128M", PHP_INI_ALL, OnChangeMemoryLimit)
450 : PHP_INI_ENTRY("precision", "14", PHP_INI_ALL, OnSetPrecision)
451 : PHP_INI_ENTRY("sendmail_from", NULL, PHP_INI_ALL, NULL)
452 : PHP_INI_ENTRY("sendmail_path", DEFAULT_SENDMAIL_PATH, PHP_INI_SYSTEM, NULL)
453 : PHP_INI_ENTRY("mail.force_extra_parameters",NULL, PHP_INI_SYSTEM|PHP_INI_PERDIR, OnChangeMailForceExtra)
454 : PHP_INI_ENTRY("disable_functions", "", PHP_INI_SYSTEM, NULL)
455 : PHP_INI_ENTRY("disable_classes", "", PHP_INI_SYSTEM, NULL)
456 : PHP_INI_ENTRY("max_file_uploads", "20", PHP_INI_SYSTEM, NULL)
457 :
458 : STD_PHP_INI_BOOLEAN("allow_url_fopen", "1", PHP_INI_SYSTEM, OnUpdateBool, allow_url_fopen, php_core_globals, core_globals)
459 : STD_PHP_INI_BOOLEAN("allow_url_include", "0", PHP_INI_SYSTEM, OnUpdateBool, allow_url_include, php_core_globals, core_globals)
460 : 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)
461 :
462 : STD_PHP_INI_ENTRY("realpath_cache_size", "16K", PHP_INI_SYSTEM, OnUpdateLong, realpath_cache_size_limit, virtual_cwd_globals, cwd_globals)
463 : STD_PHP_INI_ENTRY("realpath_cache_ttl", "120", PHP_INI_SYSTEM, OnUpdateLong, realpath_cache_ttl, virtual_cwd_globals, cwd_globals)
464 : PHP_INI_END()
465 : /* }}} */
466 :
467 : /* True globals (no need for thread safety */
468 : /* But don't make them a single int bitfield */
469 : static int module_initialized = 0;
470 : static int module_startup = 1;
471 : static int module_shutdown = 0;
472 :
473 : /* {{{ php_during_module_startup */
474 : static int php_during_module_startup(void)
475 125632 : {
476 125632 : return module_startup;
477 : }
478 : /* }}} */
479 :
480 : /* {{{ php_during_module_shutdown */
481 : static int php_during_module_shutdown(void)
482 125632 : {
483 125632 : return module_shutdown;
484 : }
485 : /* }}} */
486 :
487 : /* {{{ php_log_err
488 : */
489 : PHPAPI void php_log_err(char *log_message TSRMLS_DC)
490 2 : {
491 2 : int fd = -1;
492 : time_t error_time;
493 :
494 2 : if (PG(in_error_log)) {
495 : /* prevent recursive invocation */
496 0 : return;
497 : }
498 2 : PG(in_error_log) = 1;
499 :
500 : /* Try to use the specified logging location. */
501 2 : if (PG(error_log) != NULL) {
502 : #ifdef HAVE_SYSLOG_H
503 0 : if (!strcmp(PG(error_log), "syslog")) {
504 0 : php_syslog(LOG_NOTICE, "%.500s", log_message);
505 0 : PG(in_error_log) = 0;
506 0 : return;
507 : }
508 : #endif
509 0 : fd = VCWD_OPEN_MODE(PG(error_log), O_CREAT | O_APPEND | O_WRONLY, 0644);
510 0 : if (fd != -1) {
511 : char *tmp;
512 : int len;
513 : char *error_time_str;
514 :
515 0 : time(&error_time);
516 0 : error_time_str = php_format_date("d-M-Y H:i:s", 11, error_time, 1 TSRMLS_CC);
517 0 : len = spprintf(&tmp, 0, "[%s] %s%s", error_time_str, log_message, PHP_EOL);
518 : #ifdef PHP_WIN32
519 : php_flock(fd, 2);
520 : #endif
521 0 : write(fd, tmp, len);
522 0 : efree(tmp);
523 0 : efree(error_time_str);
524 0 : close(fd);
525 0 : PG(in_error_log) = 0;
526 0 : return;
527 : }
528 : }
529 :
530 : /* Otherwise fall back to the default logging location, if we have one */
531 :
532 2 : if (sapi_module.log_message) {
533 2 : sapi_module.log_message(log_message);
534 : }
535 2 : PG(in_error_log) = 0;
536 : }
537 : /* }}} */
538 :
539 : /* {{{ php_write
540 : wrapper for modules to use PHPWRITE */
541 : PHPAPI int php_write(void *buf, uint size TSRMLS_DC)
542 728 : {
543 728 : return PHPWRITE(buf, size);
544 : }
545 : /* }}} */
546 :
547 : /* {{{ php_printf
548 : */
549 : PHPAPI int php_printf(const char *format, ...)
550 369827 : {
551 : va_list args;
552 : int ret;
553 : char *buffer;
554 : int size;
555 : TSRMLS_FETCH();
556 :
557 369827 : va_start(args, format);
558 369827 : size = vspprintf(&buffer, 0, format, args);
559 369827 : ret = PHPWRITE(buffer, size);
560 369826 : efree(buffer);
561 369826 : va_end(args);
562 :
563 369826 : return ret;
564 : }
565 : /* }}} */
566 :
567 : /* {{{ php_verror */
568 : /* php_verror is called from php_error_docref<n> functions.
569 : * Its purpose is to unify error messages and automatically generate clickable
570 : * html error messages if correcponding ini setting (html_errors) is activated.
571 : * See: CODING_STANDARDS for details.
572 : */
573 : PHPAPI void php_verror(const char *docref, const char *params, int type, const char *format, va_list args TSRMLS_DC)
574 125632 : {
575 125632 : char *buffer = NULL, *docref_buf = NULL, *target = NULL;
576 125632 : char *docref_target = "", *docref_root = "";
577 : char *p;
578 125632 : int buffer_len = 0;
579 125632 : char *space = "";
580 125632 : char *class_name = "";
581 : char *function;
582 : int origin_len;
583 : char *origin;
584 : char *message;
585 125632 : int is_function = 0;
586 :
587 : /* get error text into buffer and escape for html if necessary */
588 125632 : buffer_len = vspprintf(&buffer, 0, format, args);
589 125632 : if (PG(html_errors)) {
590 : int len;
591 2 : char *replace = php_escape_html_entities(buffer, buffer_len, &len, 0, ENT_COMPAT, NULL TSRMLS_CC);
592 2 : efree(buffer);
593 2 : buffer = replace;
594 2 : buffer_len = len;
595 : }
596 :
597 : /* which function caused the problem if any at all */
598 125632 : if (php_during_module_startup()) {
599 0 : function = "PHP Startup";
600 125632 : } else if (php_during_module_shutdown()) {
601 0 : function = "PHP Shutdown";
602 125652 : } else if (EG(current_execute_data) &&
603 : EG(current_execute_data)->opline &&
604 : EG(current_execute_data)->opline->opcode == ZEND_INCLUDE_OR_EVAL
605 : ) {
606 20 : switch (EG(current_execute_data)->opline->op2.u.constant.value.lval) {
607 : case ZEND_EVAL:
608 0 : function = "eval";
609 0 : is_function = 1;
610 0 : break;
611 : case ZEND_INCLUDE:
612 14 : function = "include";
613 14 : is_function = 1;
614 14 : break;
615 : case ZEND_INCLUDE_ONCE:
616 0 : function = "include_once";
617 0 : is_function = 1;
618 0 : break;
619 : case ZEND_REQUIRE:
620 0 : function = "require";
621 0 : is_function = 1;
622 0 : break;
623 : case ZEND_REQUIRE_ONCE:
624 6 : function = "require_once";
625 6 : is_function = 1;
626 6 : break;
627 : default:
628 0 : function = "Unknown";
629 : }
630 : } else {
631 125612 : function = get_active_function_name(TSRMLS_C);
632 125617 : if (!function || !strlen(function)) {
633 5 : function = "Unknown";
634 : } else {
635 125607 : is_function = 1;
636 125607 : class_name = get_active_class_name(&space TSRMLS_CC);
637 : }
638 : }
639 :
640 : /* if we still have memory then format the origin */
641 125632 : if (is_function) {
642 125627 : origin_len = spprintf(&origin, 0, "%s%s%s(%s)", class_name, space, function, params);
643 : } else {
644 5 : origin_len = spprintf(&origin, 0, "%s", function);
645 : }
646 :
647 125632 : if (PG(html_errors)) {
648 : int len;
649 2 : char *replace = php_escape_html_entities(origin, origin_len, &len, 0, ENT_COMPAT, NULL TSRMLS_CC);
650 2 : efree(origin);
651 2 : origin = replace;
652 : }
653 :
654 : /* origin and buffer available, so lets come up with the error message */
655 125632 : if (docref && docref[0] == '#') {
656 0 : docref_target = strchr(docref, '#');
657 0 : docref = NULL;
658 : }
659 :
660 : /* no docref given but function is known (the default) */
661 125632 : if (!docref && is_function) {
662 : int doclen;
663 125602 : if (space[0] == '\0') {
664 125348 : doclen = spprintf(&docref_buf, 0, "function.%s", function);
665 : } else {
666 254 : doclen = spprintf(&docref_buf, 0, "%s.%s", class_name, function);
667 : }
668 259794 : while((p = strchr(docref_buf, '_')) != NULL) {
669 8590 : *p = '-';
670 : }
671 125602 : docref = php_strtolower(docref_buf, doclen);
672 : }
673 :
674 : /* we have a docref for a function AND
675 : * - we show erroes in html mode OR
676 : * - the user wants to see the links anyway
677 : */
678 125634 : if (docref && is_function && (PG(html_errors) || strlen(PG(docref_root)))) {
679 2 : if (strncmp(docref, "http://", 7)) {
680 : /* We don't have 'http://' so we use docref_root */
681 :
682 : char *ref; /* temp copy for duplicated docref */
683 :
684 2 : docref_root = PG(docref_root);
685 :
686 2 : ref = estrdup(docref);
687 2 : if (docref_buf) {
688 1 : efree(docref_buf);
689 : }
690 2 : docref_buf = ref;
691 : /* strip of the target if any */
692 2 : p = strrchr(ref, '#');
693 2 : if (p) {
694 0 : target = estrdup(p);
695 0 : if (target) {
696 0 : docref_target = target;
697 0 : *p = '\0';
698 : }
699 : }
700 : /* add the extension if it is set in ini */
701 2 : if (PG(docref_ext) && strlen(PG(docref_ext))) {
702 2 : spprintf(&docref_buf, 0, "%s%s", ref, PG(docref_ext));
703 2 : efree(ref);
704 : }
705 2 : docref = docref_buf;
706 : }
707 : /* display html formatted or only show the additional links */
708 2 : if (PG(html_errors)) {
709 2 : spprintf(&message, 0, "%s [<a href='%s%s%s'>%s</a>]: %s", origin, docref_root, docref, docref_target, docref, buffer);
710 : } else {
711 0 : spprintf(&message, 0, "%s [%s%s%s]: %s", origin, docref_root, docref, docref_target, buffer);
712 : }
713 2 : if (target) {
714 0 : efree(target);
715 : }
716 : } else {
717 125630 : spprintf(&message, 0, "%s: %s", origin, buffer);
718 : }
719 125632 : efree(origin);
720 125632 : if (docref_buf) {
721 125603 : efree(docref_buf);
722 : }
723 :
724 125632 : if (PG(track_errors) && module_initialized && EG(active_symbol_table) &&
725 : (!EG(user_error_handler) || !(EG(user_error_handler_error_reporting) & type))) {
726 : zval *tmp;
727 9735 : ALLOC_INIT_ZVAL(tmp);
728 9735 : ZVAL_STRINGL(tmp, buffer, buffer_len, 1);
729 9735 : zend_hash_update(EG(active_symbol_table), "php_errormsg", sizeof("php_errormsg"), (void **) &tmp, sizeof(zval *), NULL);
730 : }
731 125632 : efree(buffer);
732 :
733 125632 : php_error(type, "%s", message);
734 125609 : efree(message);
735 125609 : }
736 : /* }}} */
737 :
738 : /* {{{ php_error_docref0 */
739 : /* See: CODING_STANDARDS for details. */
740 : PHPAPI void php_error_docref0(const char *docref TSRMLS_DC, int type, const char *format, ...)
741 9906 : {
742 : va_list args;
743 :
744 9906 : va_start(args, format);
745 9906 : php_verror(docref, "", type, format, args TSRMLS_CC);
746 9883 : va_end(args);
747 9883 : }
748 : /* }}} */
749 :
750 : /* {{{ php_error_docref1 */
751 : /* See: CODING_STANDARDS for details. */
752 : PHPAPI void php_error_docref1(const char *docref TSRMLS_DC, const char *param1, int type, const char *format, ...)
753 115677 : {
754 : va_list args;
755 :
756 115677 : va_start(args, format);
757 115677 : php_verror(docref, param1, type, format, args TSRMLS_CC);
758 115677 : va_end(args);
759 115677 : }
760 : /* }}} */
761 :
762 : /* {{{ php_error_docref2 */
763 : /* See: CODING_STANDARDS for details. */
764 : PHPAPI void php_error_docref2(const char *docref TSRMLS_DC, const char *param1, const char *param2, int type, const char *format, ...)
765 37 : {
766 : char *params;
767 : va_list args;
768 :
769 37 : spprintf(¶ms, 0, "%s,%s", param1, param2);
770 37 : va_start(args, format);
771 37 : php_verror(docref, params ? params : "...", type, format, args TSRMLS_CC);
772 37 : va_end(args);
773 37 : if (params) {
774 37 : efree(params);
775 : }
776 37 : }
777 : /* }}} */
778 :
779 : /* {{{ php_html_puts */
780 : PHPAPI void php_html_puts(const char *str, uint size TSRMLS_DC)
781 164 : {
782 164 : zend_html_puts(str, size TSRMLS_CC);
783 164 : }
784 : /* }}} */
785 :
786 : /* {{{ php_suppress_errors */
787 : PHPAPI void php_set_error_handling(error_handling_t error_handling, zend_class_entry *exception_class TSRMLS_DC)
788 3589 : {
789 3589 : PG(error_handling) = error_handling;
790 3589 : PG(exception_class) = exception_class;
791 3589 : if (PG(last_error_message)) {
792 148 : free(PG(last_error_message));
793 148 : PG(last_error_message) = NULL;
794 : }
795 3589 : if (PG(last_error_file)) {
796 148 : free(PG(last_error_file));
797 148 : PG(last_error_file) = NULL;
798 : }
799 3589 : PG(last_error_lineno) = 0;
800 3589 : }
801 : /* }}} */
802 :
803 : /* {{{ php_error_cb
804 : extended error handling function */
805 : static void php_error_cb(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args)
806 2055066 : {
807 : char *buffer;
808 : int buffer_len, display;
809 : TSRMLS_FETCH();
810 :
811 2055066 : buffer_len = vspprintf(&buffer, PG(log_errors_max_len), format, args);
812 :
813 : /* check for repeated errors to be ignored */
814 2055066 : if (PG(ignore_repeated_errors) && PG(last_error_message)) {
815 : /* no check for PG(last_error_file) is needed since it cannot
816 : * be NULL if PG(last_error_message) is not NULL */
817 0 : if (strcmp(PG(last_error_message), buffer)
818 : || (!PG(ignore_repeated_source)
819 : && ((PG(last_error_lineno) != (int)error_lineno)
820 : || strcmp(PG(last_error_file), error_filename)))) {
821 0 : display = 1;
822 : } else {
823 0 : display = 0;
824 : }
825 : } else {
826 2055066 : display = 1;
827 : }
828 :
829 : /* store the error if it has changed */
830 2055066 : if (display) {
831 2055066 : if (PG(last_error_message)) {
832 2051439 : free(PG(last_error_message));
833 : }
834 2055066 : if (PG(last_error_file)) {
835 2051439 : free(PG(last_error_file));
836 : }
837 2055066 : if (!error_filename) {
838 1 : error_filename = "Unknown";
839 : }
840 2055066 : PG(last_error_type) = type;
841 2055066 : PG(last_error_message) = strdup(buffer);
842 2055066 : PG(last_error_file) = strdup(error_filename);
843 2055066 : PG(last_error_lineno) = error_lineno;
844 : }
845 :
846 : /* according to error handling mode, suppress error, throw exception or show it */
847 2055066 : if (PG(error_handling) != EH_NORMAL) {
848 114 : switch (type) {
849 : case E_ERROR:
850 : case E_CORE_ERROR:
851 : case E_COMPILE_ERROR:
852 : case E_USER_ERROR:
853 : case E_PARSE:
854 : /* fatal errors are real errors and cannot be made exceptions */
855 0 : break;
856 : case E_STRICT:
857 : /* for the sake of BC to old damaged code */
858 0 : break;
859 : case E_NOTICE:
860 : case E_USER_NOTICE:
861 : /* notices are no errors and are not treated as such like E_WARNINGS */
862 0 : break;
863 : default:
864 : /* throw an exception if we are in EH_THROW mode
865 : * but DO NOT overwrite a pending exception
866 : */
867 114 : if (PG(error_handling) == EH_THROW && !EG(exception)) {
868 114 : zend_throw_error_exception(PG(exception_class), buffer, 0, type TSRMLS_CC);
869 : }
870 114 : efree(buffer);
871 114 : return;
872 : }
873 : }
874 :
875 : /* display/log the error if necessary */
876 2054952 : if (display && (EG(error_reporting) & type || (type & E_CORE))
877 : && (PG(log_errors) || PG(display_errors) || (!module_initialized))) {
878 : char *error_type_str;
879 :
880 17762 : switch (type) {
881 : case E_ERROR:
882 : case E_CORE_ERROR:
883 : case E_COMPILE_ERROR:
884 : case E_USER_ERROR:
885 312 : error_type_str = "Fatal error";
886 312 : break;
887 : case E_RECOVERABLE_ERROR:
888 35 : error_type_str = "Catchable fatal error";
889 35 : break;
890 : case E_WARNING:
891 : case E_CORE_WARNING:
892 : case E_COMPILE_WARNING:
893 : case E_USER_WARNING:
894 15154 : error_type_str = "Warning";
895 15154 : break;
896 : case E_PARSE:
897 19 : error_type_str = "Parse error";
898 19 : break;
899 : case E_NOTICE:
900 : case E_USER_NOTICE:
901 1993 : error_type_str = "Notice";
902 1993 : break;
903 : case E_STRICT:
904 249 : error_type_str = "Strict Standards";
905 249 : break;
906 : default:
907 0 : error_type_str = "Unknown error";
908 : break;
909 : }
910 :
911 17762 : if (!module_initialized || PG(log_errors)) {
912 : char *log_buffer;
913 : #ifdef PHP_WIN32
914 : if ((type == E_CORE_ERROR || type == E_CORE_WARNING) && PG(display_startup_errors)) {
915 : MessageBox(NULL, buffer, error_type_str, MB_OK|ZEND_SERVICE_MB_STYLE);
916 : }
917 : #endif
918 2 : spprintf(&log_buffer, 0, "PHP %s: %s in %s on line %d", error_type_str, buffer, error_filename, error_lineno);
919 2 : php_log_err(log_buffer TSRMLS_CC);
920 2 : efree(log_buffer);
921 : }
922 17762 : if (PG(display_errors)
923 : && ((module_initialized && !PG(during_request_startup))
924 : || (PG(display_startup_errors)
925 : && (OG(php_body_write)==php_default_output_func || OG(php_body_write)==php_ub_body_write_no_header || OG(php_body_write)==php_ub_body_write)
926 : )
927 : )
928 : ) {
929 :
930 17760 : if (PG(xmlrpc_errors)) {
931 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);
932 : } else {
933 17760 : char *prepend_string = INI_STR("error_prepend_string");
934 17760 : char *append_string = INI_STR("error_append_string");
935 :
936 17760 : if (PG(html_errors)) {
937 4 : if (type == E_ERROR) {
938 : int len;
939 1 : char *buf = php_escape_html_entities(buffer, buffer_len, &len, 0, ENT_COMPAT, NULL TSRMLS_CC);
940 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));
941 1 : efree(buf);
942 : } else {
943 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));
944 : }
945 : } else {
946 : /* Write CLI/CGI errors to stderr if display_errors = "stderr" */
947 17756 : if ((!strcmp(sapi_module.name, "cli") || !strcmp(sapi_module.name, "cgi")) &&
948 : PG(display_errors) == PHP_DISPLAY_ERRORS_STDERR
949 : ) {
950 0 : fprintf(stderr, "%s: %s in %s on line %d\n", error_type_str, buffer, error_filename, error_lineno);
951 : } else {
952 17756 : 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));
953 : }
954 : }
955 : }
956 : }
957 : #if ZEND_DEBUG
958 : if (PG(report_zend_debug)) {
959 : zend_bool trigger_break;
960 :
961 : switch (type) {
962 : case E_ERROR:
963 : case E_CORE_ERROR:
964 : case E_COMPILE_ERROR:
965 : case E_USER_ERROR:
966 : trigger_break=1;
967 : break;
968 : default:
969 : trigger_break=0;
970 : break;
971 : }
972 : zend_output_debug_string(trigger_break, "%s(%d) : %s - %s", error_filename, error_lineno, error_type_str, buffer);
973 : }
974 : #endif
975 : }
976 :
977 : /* Bail out if we can't recover */
978 2054952 : switch (type) {
979 : case E_CORE_ERROR:
980 2 : if(!module_initialized) {
981 : /* bad error in module startup - no way we can live with this */
982 0 : exit(-2);
983 : }
984 : /* no break - intentionally */
985 : case E_ERROR:
986 : case E_RECOVERABLE_ERROR:
987 : case E_PARSE:
988 : case E_COMPILE_ERROR:
989 : case E_USER_ERROR:
990 380 : EG(exit_status) = 255;
991 380 : if (module_initialized) {
992 380 : if (!PG(display_errors) &&
993 : !SG(headers_sent) &&
994 : SG(sapi_headers).http_response_code == 200
995 : ) {
996 0 : sapi_header_line ctr = {0};
997 :
998 0 : ctr.line = "HTTP/1.0 500 Internal Server Error";
999 0 : ctr.line_len = strlen(ctr.line);
1000 0 : sapi_header_op(SAPI_HEADER_REPLACE, &ctr TSRMLS_CC);
1001 : }
1002 : /* the parser would return 1 (failure), we can bail out nicely */
1003 380 : if (type != E_PARSE) {
1004 : /* restore memory limit */
1005 360 : zend_set_memory_limit(PG(memory_limit));
1006 360 : efree(buffer);
1007 360 : zend_objects_store_mark_destructed(&EG(objects_store) TSRMLS_CC);
1008 360 : zend_bailout();
1009 0 : return;
1010 : }
1011 : }
1012 : break;
1013 : }
1014 :
1015 : /* Log if necessary */
1016 2054592 : if (!display) {
1017 0 : efree(buffer);
1018 0 : return;
1019 : }
1020 :
1021 2054592 : if (PG(track_errors) && module_initialized && EG(active_symbol_table)) {
1022 : zval *tmp;
1023 20063 : ALLOC_INIT_ZVAL(tmp);
1024 20063 : ZVAL_STRINGL(tmp, buffer, buffer_len, 1);
1025 20063 : zend_hash_update(EG(active_symbol_table), "php_errormsg", sizeof("php_errormsg"), (void **) & tmp, sizeof(zval *), NULL);
1026 : }
1027 :
1028 2054592 : efree(buffer);
1029 : }
1030 : /* }}} */
1031 :
1032 : /* {{{ proto bool set_time_limit(int seconds)
1033 : Sets the maximum time a script can run */
1034 : PHP_FUNCTION(set_time_limit)
1035 13 : {
1036 : zval **new_timeout;
1037 :
1038 13 : if (PG(safe_mode)) {
1039 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot set time limit in safe mode");
1040 0 : RETURN_FALSE;
1041 : }
1042 :
1043 13 : if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &new_timeout) == FAILURE) {
1044 0 : WRONG_PARAM_COUNT;
1045 : }
1046 :
1047 13 : convert_to_string_ex(new_timeout);
1048 13 : if (zend_alter_ini_entry("max_execution_time", sizeof("max_execution_time"), Z_STRVAL_PP(new_timeout), Z_STRLEN_PP(new_timeout), PHP_INI_USER, PHP_INI_STAGE_RUNTIME) == SUCCESS) {
1049 13 : RETURN_TRUE;
1050 : } else {
1051 0 : RETURN_FALSE;
1052 : }
1053 : }
1054 : /* }}} */
1055 :
1056 : /* {{{ php_fopen_wrapper_for_zend
1057 : */
1058 : static FILE *php_fopen_wrapper_for_zend(const char *filename, char **opened_path)
1059 0 : {
1060 : TSRMLS_FETCH();
1061 :
1062 0 : return php_stream_open_wrapper_as_file((char *)filename, "rb", ENFORCE_SAFE_MODE|USE_PATH|IGNORE_URL_WIN|REPORT_ERRORS|STREAM_OPEN_FOR_INCLUDE, opened_path);
1063 : }
1064 : /* }}} */
1065 :
1066 : static void stream_closer_for_zend(void *handle TSRMLS_DC) /* {{{ */
1067 4080 : {
1068 4080 : php_stream_close((php_stream*)handle);
1069 4080 : }
1070 : /* }}} */
1071 :
1072 : static long stream_fteller_for_zend(void *handle TSRMLS_DC) /* {{{ */
1073 2 : {
1074 2 : return (long)php_stream_tell((php_stream*)handle);
1075 : }
1076 : /* }}} */
1077 :
1078 : static int php_stream_open_for_zend(const char *filename, zend_file_handle *handle TSRMLS_DC) /* {{{ */
1079 4121 : {
1080 4121 : return php_stream_open_for_zend_ex(filename, handle, ENFORCE_SAFE_MODE|USE_PATH|REPORT_ERRORS|STREAM_OPEN_FOR_INCLUDE TSRMLS_CC);
1081 : }
1082 : /* }}} */
1083 :
1084 : PHPAPI int php_stream_open_for_zend_ex(const char *filename, zend_file_handle *handle, int mode TSRMLS_DC) /* {{{ */
1085 4136 : {
1086 : php_stream *stream;
1087 :
1088 4136 : stream = php_stream_open_wrapper((char *)filename, "rb", mode, &handle->opened_path);
1089 :
1090 4136 : if (stream) {
1091 4080 : handle->type = ZEND_HANDLE_STREAM;
1092 4080 : handle->filename = (char*)filename;
1093 4080 : handle->free_filename = 0;
1094 4080 : handle->handle.stream.handle = stream;
1095 4080 : handle->handle.stream.reader = (zend_stream_reader_t)_php_stream_read;
1096 4080 : handle->handle.stream.closer = stream_closer_for_zend;
1097 4080 : handle->handle.stream.fteller = stream_fteller_for_zend;
1098 4080 : handle->handle.stream.interactive = 0;
1099 : /* suppress warning if this stream is not explicitly closed */
1100 : php_stream_auto_cleanup(stream);
1101 :
1102 4080 : return SUCCESS;
1103 : }
1104 56 : return FAILURE;
1105 : }
1106 : /* }}} */
1107 :
1108 : /* {{{ php_get_configuration_directive_for_zend
1109 : */
1110 : static int php_get_configuration_directive_for_zend(char *name, uint name_length, zval *contents)
1111 2645567 : {
1112 2645567 : zval *retval = cfg_get_entry(name, name_length);
1113 :
1114 2645567 : if (retval) {
1115 432720 : *contents = *retval;
1116 432720 : return SUCCESS;
1117 : } else {
1118 2212847 : return FAILURE;
1119 : }
1120 : }
1121 : /* }}} */
1122 :
1123 : /* {{{ php_message_handler_for_zend
1124 : */
1125 : static void php_message_handler_for_zend(long message, void *data)
1126 11 : {
1127 : TSRMLS_FETCH();
1128 :
1129 11 : switch (message) {
1130 : case ZMSG_FAILED_INCLUDE_FOPEN:
1131 6 : 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)));
1132 6 : break;
1133 : case ZMSG_FAILED_REQUIRE_FOPEN:
1134 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)));
1135 0 : break;
1136 : case ZMSG_FAILED_HIGHLIGHT_FOPEN:
1137 2 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed opening '%s' for highlighting", php_strip_url_passwd((char *) data));
1138 2 : break;
1139 : case ZMSG_MEMORY_LEAK_DETECTED:
1140 : case ZMSG_MEMORY_LEAK_REPEATED:
1141 : #if ZEND_DEBUG
1142 : if (EG(error_reporting) & E_WARNING) {
1143 : char memory_leak_buf[1024];
1144 :
1145 : if (message==ZMSG_MEMORY_LEAK_DETECTED) {
1146 : zend_leak_info *t = (zend_leak_info *) data;
1147 :
1148 : 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));
1149 : if (t->orig_filename) {
1150 : char relay_buf[512];
1151 :
1152 : snprintf(relay_buf, 512, "%s(%d) : Actual location (location was relayed)\n", t->orig_filename, t->orig_lineno);
1153 : strlcat(memory_leak_buf, relay_buf, sizeof(memory_leak_buf));
1154 : }
1155 : } else {
1156 : unsigned long leak_count = (zend_uintptr_t) data;
1157 :
1158 : snprintf(memory_leak_buf, 512, "Last leak repeated %ld time%s\n", leak_count, (leak_count>1?"s":""));
1159 : }
1160 : # if defined(PHP_WIN32)
1161 : OutputDebugString(memory_leak_buf);
1162 : # else
1163 : fprintf(stderr, "%s", memory_leak_buf);
1164 : # endif
1165 : }
1166 : #endif
1167 0 : break;
1168 : case ZMSG_MEMORY_LEAKS_GRAND_TOTAL:
1169 : #if ZEND_DEBUG
1170 : if (EG(error_reporting) & E_WARNING) {
1171 : char memory_leak_buf[512];
1172 :
1173 : snprintf(memory_leak_buf, 512, "=== Total %d memory leaks detected ===\n", *((zend_uint *) data));
1174 : # if defined(PHP_WIN32)
1175 : OutputDebugString(memory_leak_buf);
1176 : # else
1177 : fprintf(stderr, "%s", memory_leak_buf);
1178 : # endif
1179 : }
1180 : #endif
1181 0 : break;
1182 : case ZMSG_LOG_SCRIPT_NAME: {
1183 : struct tm *ta, tmbuf;
1184 : time_t curtime;
1185 : char *datetime_str, asctimebuf[52];
1186 : char memory_leak_buf[4096];
1187 :
1188 0 : time(&curtime);
1189 0 : ta = php_localtime_r(&curtime, &tmbuf);
1190 0 : datetime_str = php_asctime_r(ta, asctimebuf);
1191 0 : if (datetime_str) {
1192 0 : datetime_str[strlen(datetime_str)-1]=0; /* get rid of the trailing newline */
1193 0 : snprintf(memory_leak_buf, sizeof(memory_leak_buf), "[%s] Script: '%s'\n", datetime_str, SAFE_FILENAME(SG(request_info).path_translated));
1194 : } else {
1195 0 : snprintf(memory_leak_buf, sizeof(memory_leak_buf), "[null] Script: '%s'\n", SAFE_FILENAME(SG(request_info).path_translated));
1196 : }
1197 : # if defined(PHP_WIN32)
1198 : OutputDebugString(memory_leak_buf);
1199 : # else
1200 0 : fprintf(stderr, "%s", memory_leak_buf);
1201 : # endif
1202 : }
1203 : break;
1204 : }
1205 8 : }
1206 : /* }}} */
1207 :
1208 :
1209 : void php_on_timeout(int seconds TSRMLS_DC)
1210 1 : {
1211 1 : PG(connection_status) |= PHP_CONNECTION_TIMEOUT;
1212 1 : zend_set_timeout(EG(timeout_seconds));
1213 1 : }
1214 :
1215 : #if PHP_SIGCHILD
1216 : /* {{{ sigchld_handler
1217 : */
1218 : static void sigchld_handler(int apar)
1219 : {
1220 : while (waitpid(-1, NULL, WNOHANG) > 0);
1221 : signal(SIGCHLD, sigchld_handler);
1222 : }
1223 : /* }}} */
1224 : #endif
1225 :
1226 : /* {{{ php_start_sapi()
1227 : */
1228 : static int php_start_sapi(TSRMLS_D)
1229 0 : {
1230 0 : int retval = SUCCESS;
1231 :
1232 0 : if(!SG(sapi_started)) {
1233 0 : zend_try {
1234 0 : PG(during_request_startup) = 1;
1235 :
1236 : /* initialize global variables */
1237 0 : PG(modules_activated) = 0;
1238 0 : PG(header_is_being_sent) = 0;
1239 0 : PG(connection_status) = PHP_CONNECTION_NORMAL;
1240 :
1241 0 : zend_activate(TSRMLS_C);
1242 0 : zend_set_timeout(EG(timeout_seconds));
1243 0 : zend_activate_modules(TSRMLS_C);
1244 0 : PG(modules_activated)=1;
1245 0 : } zend_catch {
1246 0 : retval = FAILURE;
1247 0 : } zend_end_try();
1248 :
1249 0 : SG(sapi_started) = 1;
1250 : }
1251 0 : return retval;
1252 : }
1253 :
1254 : /* }}} */
1255 :
1256 : /* {{{ php_request_startup
1257 : */
1258 : #ifndef APACHE_HOOKS
1259 : int php_request_startup(TSRMLS_D)
1260 13551 : {
1261 13551 : int retval = SUCCESS;
1262 :
1263 : #ifdef PHP_WIN32
1264 : PG(com_initialized) = 0;
1265 : #endif
1266 :
1267 : #if PHP_SIGCHILD
1268 : signal(SIGCHLD, sigchld_handler);
1269 : #endif
1270 :
1271 13551 : zend_try {
1272 13551 : PG(in_error_log) = 0;
1273 13551 : PG(during_request_startup) = 1;
1274 :
1275 13551 : php_output_activate(TSRMLS_C);
1276 :
1277 : /* initialize global variables */
1278 13551 : PG(modules_activated) = 0;
1279 13551 : PG(header_is_being_sent) = 0;
1280 13551 : PG(connection_status) = PHP_CONNECTION_NORMAL;
1281 13551 : PG(in_user_include) = 0;
1282 :
1283 13551 : zend_activate(TSRMLS_C);
1284 13551 : sapi_activate(TSRMLS_C);
1285 :
1286 13551 : if (PG(max_input_time) == -1) {
1287 13551 : zend_set_timeout(EG(timeout_seconds));
1288 : } else {
1289 0 : zend_set_timeout(PG(max_input_time));
1290 : }
1291 :
1292 : /* Disable realpath cache if safe_mode or open_basedir are set */
1293 13551 : if (PG(safe_mode) || (PG(open_basedir) && *PG(open_basedir))) {
1294 77 : CWDG(realpath_cache_size_limit) = 0;
1295 : }
1296 :
1297 13551 : if (PG(expose_php)) {
1298 13551 : sapi_add_header(SAPI_PHP_VERSION_HEADER, sizeof(SAPI_PHP_VERSION_HEADER)-1, 1);
1299 : }
1300 :
1301 13555 : if (PG(output_handler) && PG(output_handler)[0]) {
1302 4 : php_start_ob_buffer_named(PG(output_handler), 0, 1 TSRMLS_CC);
1303 13547 : } else if (PG(output_buffering)) {
1304 0 : if (PG(output_buffering)>1) {
1305 0 : php_start_ob_buffer(NULL, PG(output_buffering), 1 TSRMLS_CC);
1306 : } else {
1307 0 : php_start_ob_buffer(NULL, 0, 1 TSRMLS_CC);
1308 : }
1309 13547 : } else if (PG(implicit_flush)) {
1310 13448 : php_start_implicit_flush(TSRMLS_C);
1311 : }
1312 :
1313 : /* We turn this off in php_execute_script() */
1314 : /* PG(during_request_startup) = 0; */
1315 :
1316 13551 : php_hash_environment(TSRMLS_C);
1317 13551 : zend_activate_modules(TSRMLS_C);
1318 13551 : PG(modules_activated)=1;
1319 0 : } zend_catch {
1320 0 : retval = FAILURE;
1321 13551 : } zend_end_try();
1322 :
1323 13551 : SG(sapi_started) = 1;
1324 :
1325 13551 : return retval;
1326 : }
1327 : # else
1328 : int php_request_startup(TSRMLS_D)
1329 : {
1330 : int retval = SUCCESS;
1331 :
1332 : #if PHP_SIGCHILD
1333 : signal(SIGCHLD, sigchld_handler);
1334 : #endif
1335 :
1336 : if (php_start_sapi() == FAILURE) {
1337 : return FAILURE;
1338 : }
1339 :
1340 : php_output_activate(TSRMLS_C);
1341 : sapi_activate(TSRMLS_C);
1342 : php_hash_environment(TSRMLS_C);
1343 :
1344 : zend_try {
1345 : PG(during_request_startup) = 1;
1346 : php_output_activate(TSRMLS_C);
1347 : if (PG(expose_php)) {
1348 : sapi_add_header(SAPI_PHP_VERSION_HEADER, sizeof(SAPI_PHP_VERSION_HEADER)-1, 1);
1349 : }
1350 : } zend_catch {
1351 : retval = FAILURE;
1352 : } zend_end_try();
1353 :
1354 : return retval;
1355 : }
1356 : # endif
1357 : /* }}} */
1358 :
1359 : /* {{{ php_request_startup_for_hook
1360 : */
1361 : int php_request_startup_for_hook(TSRMLS_D)
1362 0 : {
1363 0 : int retval = SUCCESS;
1364 :
1365 : #if PHP_SIGCHLD
1366 : signal(SIGCHLD, sigchld_handler);
1367 : #endif
1368 :
1369 0 : if (php_start_sapi(TSRMLS_C) == FAILURE) {
1370 0 : return FAILURE;
1371 : }
1372 :
1373 0 : php_output_activate(TSRMLS_C);
1374 0 : sapi_activate_headers_only(TSRMLS_C);
1375 0 : php_hash_environment(TSRMLS_C);
1376 :
1377 0 : return retval;
1378 : }
1379 : /* }}} */
1380 :
1381 : /* {{{ php_request_shutdown_for_exec
1382 : */
1383 : void php_request_shutdown_for_exec(void *dummy)
1384 0 : {
1385 : TSRMLS_FETCH();
1386 :
1387 : /* used to close fd's in the 3..255 range here, but it's problematic
1388 : */
1389 0 : shutdown_memory_manager(1, 1 TSRMLS_CC);
1390 0 : }
1391 : /* }}} */
1392 :
1393 : /* {{{ php_request_shutdown_for_hook
1394 : */
1395 : void php_request_shutdown_for_hook(void *dummy)
1396 0 : {
1397 : TSRMLS_FETCH();
1398 :
1399 0 : if (PG(modules_activated)) zend_try {
1400 0 : php_call_shutdown_functions(TSRMLS_C);
1401 0 : } zend_end_try();
1402 :
1403 0 : if (PG(modules_activated)) {
1404 0 : zend_deactivate_modules(TSRMLS_C);
1405 0 : php_free_shutdown_functions(TSRMLS_C);
1406 : }
1407 :
1408 0 : zend_try {
1409 : int i;
1410 :
1411 0 : for (i = 0; i < NUM_TRACK_VARS; i++) {
1412 0 : if (PG(http_globals)[i]) {
1413 0 : zval_ptr_dtor(&PG(http_globals)[i]);
1414 : }
1415 : }
1416 0 : } zend_end_try();
1417 :
1418 0 : zend_deactivate(TSRMLS_C);
1419 :
1420 0 : zend_try {
1421 0 : sapi_deactivate(TSRMLS_C);
1422 0 : } zend_end_try();
1423 :
1424 0 : zend_try {
1425 0 : php_shutdown_stream_hashes(TSRMLS_C);
1426 0 : } zend_end_try();
1427 :
1428 0 : zend_try {
1429 0 : shutdown_memory_manager(CG(unclean_shutdown), 0 TSRMLS_CC);
1430 0 : } zend_end_try();
1431 :
1432 0 : zend_try {
1433 0 : zend_unset_timeout(TSRMLS_C);
1434 0 : } zend_end_try();
1435 0 : }
1436 :
1437 : /* }}} */
1438 :
1439 : /* {{{ php_request_shutdown
1440 : */
1441 : void php_request_shutdown(void *dummy)
1442 13584 : {
1443 : zend_bool report_memleaks;
1444 : TSRMLS_FETCH();
1445 :
1446 13584 : report_memleaks = PG(report_memleaks);
1447 :
1448 : /* EG(opline_ptr) points into nirvana and therefore cannot be safely accessed
1449 : * inside zend_executor callback functions.
1450 : */
1451 13584 : EG(opline_ptr) = NULL;
1452 13584 : EG(active_op_array) = NULL;
1453 :
1454 13584 : php_deactivate_ticks(TSRMLS_C);
1455 :
1456 : /* 1. Call all possible shutdown functions registered with register_shutdown_function() */
1457 13584 : if (PG(modules_activated)) zend_try {
1458 13584 : php_call_shutdown_functions(TSRMLS_C);
1459 13584 : } zend_end_try();
1460 :
1461 : /* 2. Call all possible __destruct() functions */
1462 13584 : zend_try {
1463 13584 : zend_call_destructors(TSRMLS_C);
1464 13584 : } zend_end_try();
1465 :
1466 : /* 3. Flush all output buffers */
1467 13584 : zend_try {
1468 13584 : php_end_ob_buffers((zend_bool)(SG(request_info).headers_only?0:1) TSRMLS_CC);
1469 13584 : } zend_end_try();
1470 :
1471 : /* 4. Send the set HTTP headers (note: This must be done AFTER php_end_ob_buffers() !!) */
1472 13584 : zend_try {
1473 13584 : sapi_send_headers(TSRMLS_C);
1474 13584 : } zend_end_try();
1475 :
1476 : /* 5. Call all extensions RSHUTDOWN functions */
1477 13584 : if (PG(modules_activated)) {
1478 13584 : zend_deactivate_modules(TSRMLS_C);
1479 13584 : php_free_shutdown_functions(TSRMLS_C);
1480 : }
1481 :
1482 : /* 6. Destroy super-globals */
1483 13584 : zend_try {
1484 : int i;
1485 :
1486 95088 : for (i=0; i<NUM_TRACK_VARS; i++) {
1487 81504 : if (PG(http_globals)[i]) {
1488 81504 : zval_ptr_dtor(&PG(http_globals)[i]);
1489 : }
1490 : }
1491 13584 : } zend_end_try();
1492 :
1493 : /* 6.5 free last error information */
1494 13584 : if (PG(last_error_message)) {
1495 3479 : free(PG(last_error_message));
1496 3479 : PG(last_error_message) = NULL;
1497 : }
1498 13584 : if (PG(last_error_file)) {
1499 3479 : free(PG(last_error_file));
1500 3479 : PG(last_error_file) = NULL;
1501 : }
1502 :
1503 : /* 7. Shutdown scanner/executor/compiler and restore ini entries */
1504 13584 : zend_deactivate(TSRMLS_C);
1505 :
1506 : /* 8. Call all extensions post-RSHUTDOWN functions */
1507 13584 : zend_try {
1508 13584 : zend_post_deactivate_modules(TSRMLS_C);
1509 13584 : } zend_end_try();
1510 :
1511 : /* 9. SAPI related shutdown (free stuff) */
1512 13584 : zend_try {
1513 13584 : sapi_deactivate(TSRMLS_C);
1514 13584 : } zend_end_try();
1515 :
1516 : /* 10. Destroy stream hashes */
1517 13584 : zend_try {
1518 13584 : php_shutdown_stream_hashes(TSRMLS_C);
1519 13584 : } zend_end_try();
1520 :
1521 : /* 11. Free Willy (here be crashes) */
1522 13584 : zend_try {
1523 13584 : shutdown_memory_manager(CG(unclean_shutdown) || !report_memleaks, 0 TSRMLS_CC);
1524 13584 : } zend_end_try();
1525 :
1526 : /* 12. Reset max_execution_time */
1527 13584 : zend_try {
1528 13584 : zend_unset_timeout(TSRMLS_C);
1529 13584 : } zend_end_try();
1530 :
1531 : #ifdef PHP_WIN32
1532 : if (PG(com_initialized)) {
1533 : CoUninitialize();
1534 : PG(com_initialized) = 0;
1535 : }
1536 : #endif
1537 13584 : }
1538 : /* }}} */
1539 :
1540 : /* {{{ php_com_initialize
1541 : */
1542 : PHPAPI void php_com_initialize(TSRMLS_D)
1543 0 : {
1544 : #ifdef PHP_WIN32
1545 : if (!PG(com_initialized)) {
1546 : CoInitialize(NULL);
1547 : PG(com_initialized) = 1;
1548 : }
1549 : #endif
1550 0 : }
1551 : /* }}} */
1552 :
1553 : /* {{{ php_body_write_wrapper
1554 : */
1555 : static int php_body_write_wrapper(const char *str, uint str_length)
1556 237113 : {
1557 : TSRMLS_FETCH();
1558 237113 : return php_body_write(str, str_length TSRMLS_CC);
1559 : }
1560 : /* }}} */
1561 :
1562 : #ifdef ZTS
1563 : /* {{{ core_globals_ctor
1564 : */
1565 : static void core_globals_ctor(php_core_globals *core_globals TSRMLS_DC)
1566 : {
1567 : memset(core_globals, 0, sizeof(*core_globals));
1568 : }
1569 : /* }}} */
1570 : #endif
1571 :
1572 : /* {{{ core_globals_dtor
1573 : */
1574 : static void core_globals_dtor(php_core_globals *core_globals TSRMLS_DC)
1575 13597 : {
1576 13597 : if (core_globals->last_error_message) {
1577 0 : free(core_globals->last_error_message);
1578 : }
1579 13597 : if (core_globals->last_error_file) {
1580 0 : free(core_globals->last_error_file);
1581 : }
1582 13597 : if (core_globals->disable_functions) {
1583 3 : free(core_globals->disable_functions);
1584 : }
1585 13597 : if (core_globals->disable_classes) {
1586 1 : free(core_globals->disable_classes);
1587 : }
1588 13597 : }
1589 : /* }}} */
1590 :
1591 : /* {{{ php_register_extensions
1592 : */
1593 : int php_register_extensions(zend_module_entry **ptr, int count TSRMLS_DC)
1594 27130 : {
1595 27130 : zend_module_entry **end = ptr + count;
1596 :
1597 868258 : while (ptr < end) {
1598 813998 : if (*ptr) {
1599 813998 : if (zend_register_internal_module(*ptr TSRMLS_CC)==NULL) {
1600 0 : return FAILURE;
1601 : }
1602 : }
1603 813998 : ptr++;
1604 : }
1605 27130 : return SUCCESS;
1606 : }
1607 : /* }}} */
1608 :
1609 : #if defined(PHP_WIN32) && defined(_MSC_VER) && (_MSC_VER >= 1400)
1610 : static _invalid_parameter_handler old_invalid_parameter_handler;
1611 :
1612 : void dummy_invalid_parameter_handler(
1613 : const wchar_t *expression,
1614 : const wchar_t *function,
1615 : const wchar_t *file,
1616 : unsigned int line,
1617 : uintptr_t pEwserved)
1618 : {
1619 : static int called = 0;
1620 : char buf[1024];
1621 : int len;
1622 :
1623 : if (!called) {
1624 : called = 1;
1625 : if (function) {
1626 : if (file) {
1627 : len = _snprintf(buf, sizeof(buf)-1, "Invalid parameter detected in CRT function '%ws' (%ws:%d)", function, file, line);
1628 : } else {
1629 : len = _snprintf(buf, sizeof(buf)-1, "Invalid parameter detected in CRT function '%ws'", function);
1630 : }
1631 : } else {
1632 : len = _snprintf(buf, sizeof(buf)-1, "Invalid CRT parameters detected");
1633 : }
1634 : zend_error(E_WARNING, "%s", buf);
1635 : called = 0;
1636 : }
1637 : }
1638 : #endif
1639 :
1640 : /* {{{ php_module_startup
1641 : */
1642 : int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_modules, uint num_additional_modules)
1643 13565 : {
1644 : zend_utility_functions zuf;
1645 : zend_utility_values zuv;
1646 13565 : int module_number=0; /* for REGISTER_INI_ENTRIES() */
1647 : char *php_os;
1648 : #ifdef ZTS
1649 : zend_executor_globals *executor_globals;
1650 : void ***tsrm_ls;
1651 :
1652 : php_core_globals *core_globals;
1653 : #endif
1654 : #if defined(PHP_WIN32) || (defined(NETWARE) && defined(USE_WINSOCK))
1655 : WORD wVersionRequested = MAKEWORD(2, 0);
1656 : WSADATA wsaData;
1657 : #endif
1658 : #ifdef PHP_WIN32
1659 : {
1660 : DWORD dwVersion = GetVersion();
1661 :
1662 : /* Get build numbers for Windows NT or Win95 */
1663 : if (dwVersion < 0x80000000){
1664 : php_os="WINNT";
1665 : } else {
1666 : php_os="WIN32";
1667 : }
1668 : }
1669 : #if defined(_MSC_VER) && (_MSC_VER >= 1400)
1670 : old_invalid_parameter_handler =
1671 : _set_invalid_parameter_handler(dummy_invalid_parameter_handler);
1672 : if (old_invalid_parameter_handler != NULL) {
1673 : _set_invalid_parameter_handler(old_invalid_parameter_handler);
1674 : }
1675 : #endif
1676 : #else
1677 13565 : php_os=PHP_OS;
1678 : #endif
1679 :
1680 : #ifdef ZTS
1681 : tsrm_ls = ts_resource(0);
1682 : #endif
1683 :
1684 13565 : module_shutdown = 0;
1685 13565 : module_startup = 1;
1686 13565 : sapi_initialize_empty_request(TSRMLS_C);
1687 13565 : sapi_activate(TSRMLS_C);
1688 :
1689 13565 : if (module_initialized) {
1690 0 : return SUCCESS;
1691 : }
1692 :
1693 13565 : sapi_module = *sf;
1694 :
1695 13565 : php_output_startup();
1696 :
1697 13565 : zuf.error_function = php_error_cb;
1698 13565 : zuf.printf_function = php_printf;
1699 13565 : zuf.write_function = php_body_write_wrapper;
1700 13565 : zuf.fopen_function = php_fopen_wrapper_for_zend;
1701 13565 : zuf.message_handler = php_message_handler_for_zend;
1702 13565 : zuf.block_interruptions = sapi_module.block_interruptions;
1703 13565 : zuf.unblock_interruptions = sapi_module.unblock_interruptions;
1704 13565 : zuf.get_configuration_directive = php_get_configuration_directive_for_zend;
1705 13565 : zuf.ticks_function = php_run_ticks;
1706 13565 : zuf.on_timeout = php_on_timeout;
1707 13565 : zuf.stream_open_function = php_stream_open_for_zend;
1708 13565 : zuf.vspprintf_function = vspprintf;
1709 13565 : zuf.getenv_function = sapi_getenv;
1710 13565 : zend_startup(&zuf, NULL, 1);
1711 :
1712 : #ifdef ZTS
1713 : executor_globals = ts_resource(executor_globals_id);
1714 : ts_allocate_id(&core_globals_id, sizeof(php_core_globals), (ts_allocate_ctor) core_globals_ctor, (ts_allocate_dtor) core_globals_dtor);
1715 : core_globals = ts_resource(core_globals_id);
1716 : #ifdef PHP_WIN32
1717 : 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);
1718 : #endif
1719 : #endif
1720 13565 : EG(bailout) = NULL;
1721 13565 : EG(error_reporting) = E_ALL & ~E_NOTICE;
1722 :
1723 13565 : PG(header_is_being_sent) = 0;
1724 13565 : SG(request_info).headers_only = 0;
1725 13565 : SG(request_info).argv0 = NULL;
1726 13565 : SG(request_info).argc=0;
1727 13565 : SG(request_info).argv=(char **)NULL;
1728 13565 : PG(connection_status) = PHP_CONNECTION_NORMAL;
1729 13565 : PG(during_request_startup) = 0;
1730 13565 : PG(last_error_message) = NULL;
1731 13565 : PG(last_error_file) = NULL;
1732 13565 : PG(last_error_lineno) = 0;
1733 13565 : PG(error_handling) = EH_NORMAL;
1734 13565 : PG(disable_functions) = NULL;
1735 13565 : PG(disable_classes) = NULL;
1736 :
1737 : #if HAVE_SETLOCALE
1738 13565 : setlocale(LC_CTYPE, "");
1739 : zend_update_current_locale();
1740 : #endif
1741 :
1742 : #if HAVE_TZSET
1743 13565 : tzset();
1744 : #endif
1745 :
1746 : #if defined(PHP_WIN32) || (defined(NETWARE) && defined(USE_WINSOCK))
1747 : /* start up winsock services */
1748 : if (WSAStartup(wVersionRequested, &wsaData) != 0) {
1749 : php_printf("\nwinsock.dll unusable. %d\n", WSAGetLastError());
1750 : return FAILURE;
1751 : }
1752 : #endif
1753 :
1754 13565 : le_index_ptr = zend_register_list_destructors_ex(NULL, NULL, "index pointer", 0);
1755 :
1756 : /* this will read in php.ini, set up the configuration parameters,
1757 : load zend extensions and register php function extensions
1758 : to be loaded later */
1759 13565 : if (php_init_config(TSRMLS_C) == FAILURE) {
1760 0 : return FAILURE;
1761 : }
1762 :
1763 : /* Register PHP core ini entries */
1764 13565 : REGISTER_INI_ENTRIES();
1765 :
1766 : /* Register Zend ini entries */
1767 13565 : zend_register_standard_ini_entries(TSRMLS_C);
1768 :
1769 : /* Disable realpath cache if safe_mode or open_basedir are set */
1770 13565 : if (PG(safe_mode) || (PG(open_basedir) && *PG(open_basedir))) {
1771 77 : CWDG(realpath_cache_size_limit) = 0;
1772 : }
1773 :
1774 : /* initialize stream wrappers registry
1775 : * (this uses configuration parameters from php.ini)
1776 : */
1777 13565 : if (php_init_stream_wrappers(module_number TSRMLS_CC) == FAILURE) {
1778 0 : php_printf("PHP: Unable to initialize stream url wrappers.\n");
1779 0 : return FAILURE;
1780 : }
1781 :
1782 : /* initialize registry for images to be used in phpinfo()
1783 : (this uses configuration parameters from php.ini)
1784 : */
1785 13565 : if (php_init_info_logos() == FAILURE) {
1786 0 : php_printf("PHP: Unable to initialize info phpinfo logos.\n");
1787 0 : return FAILURE;
1788 : }
1789 :
1790 13565 : zuv.html_errors = 1;
1791 13565 : zuv.import_use_extension = ".php";
1792 13565 : php_startup_auto_globals(TSRMLS_C);
1793 13565 : zend_set_utility_values(&zuv);
1794 13565 : php_startup_sapi_content_types(TSRMLS_C);
1795 :
1796 : /* Register constants */
1797 13565 : REGISTER_MAIN_STRINGL_CONSTANT("PHP_VERSION", PHP_VERSION, sizeof(PHP_VERSION)-1, CONST_PERSISTENT | CONST_CS);
1798 13565 : REGISTER_MAIN_LONG_CONSTANT("PHP_MAJOR_VERSION", PHP_MAJOR_VERSION, CONST_PERSISTENT | CONST_CS);
1799 13565 : REGISTER_MAIN_LONG_CONSTANT("PHP_MINOR_VERSION", PHP_MINOR_VERSION, CONST_PERSISTENT | CONST_CS);
1800 13565 : REGISTER_MAIN_LONG_CONSTANT("PHP_RELEASE_VERSION", PHP_RELEASE_VERSION, CONST_PERSISTENT | CONST_CS);
1801 13565 : REGISTER_MAIN_STRINGL_CONSTANT("PHP_EXTRA_VERSION", PHP_EXTRA_VERSION, sizeof(PHP_EXTRA_VERSION) - 1, CONST_PERSISTENT | CONST_CS);
1802 13565 : REGISTER_MAIN_LONG_CONSTANT("PHP_VERSION_ID", PHP_VERSION_ID, CONST_PERSISTENT | CONST_CS);
1803 : #ifdef ZTS
1804 : REGISTER_MAIN_LONG_CONSTANT("PHP_ZTS", 1, CONST_PERSISTENT | CONST_CS);
1805 : #else
1806 13565 : REGISTER_MAIN_LONG_CONSTANT("PHP_ZTS", 0, CONST_PERSISTENT | CONST_CS);
1807 : #endif
1808 13565 : REGISTER_MAIN_LONG_CONSTANT("PHP_DEBUG", PHP_DEBUG, CONST_PERSISTENT | CONST_CS);
1809 13565 : REGISTER_MAIN_STRINGL_CONSTANT("PHP_OS", php_os, strlen(php_os), CONST_PERSISTENT | CONST_CS);
1810 13565 : REGISTER_MAIN_STRINGL_CONSTANT("PHP_SAPI", sapi_module.name, strlen(sapi_module.name), CONST_PERSISTENT | CONST_CS);
1811 13565 : REGISTER_MAIN_STRINGL_CONSTANT("DEFAULT_INCLUDE_PATH", PHP_INCLUDE_PATH, sizeof(PHP_INCLUDE_PATH)-1, CONST_PERSISTENT | CONST_CS);
1812 13565 : REGISTER_MAIN_STRINGL_CONSTANT("PEAR_INSTALL_DIR", PEAR_INSTALLDIR, sizeof(PEAR_INSTALLDIR)-1, CONST_PERSISTENT | CONST_CS);
1813 13565 : REGISTER_MAIN_STRINGL_CONSTANT("PEAR_EXTENSION_DIR", PHP_EXTENSION_DIR, sizeof(PHP_EXTENSION_DIR)-1, CONST_PERSISTENT | CONST_CS);
1814 13565 : REGISTER_MAIN_STRINGL_CONSTANT("PHP_EXTENSION_DIR", PHP_EXTENSION_DIR, sizeof(PHP_EXTENSION_DIR)-1, CONST_PERSISTENT | CONST_CS);
1815 13565 : REGISTER_MAIN_STRINGL_CONSTANT("PHP_PREFIX", PHP_PREFIX, sizeof(PHP_PREFIX)-1, CONST_PERSISTENT | CONST_CS);
1816 13565 : REGISTER_MAIN_STRINGL_CONSTANT("PHP_BINDIR", PHP_BINDIR, sizeof(PHP_BINDIR)-1, CONST_PERSISTENT | CONST_CS);
1817 13565 : REGISTER_MAIN_STRINGL_CONSTANT("PHP_LIBDIR", PHP_LIBDIR, sizeof(PHP_LIBDIR)-1, CONST_PERSISTENT | CONST_CS);
1818 13565 : REGISTER_MAIN_STRINGL_CONSTANT("PHP_DATADIR", PHP_DATADIR, sizeof(PHP_DATADIR)-1, CONST_PERSISTENT | CONST_CS);
1819 13565 : REGISTER_MAIN_STRINGL_CONSTANT("PHP_SYSCONFDIR", PHP_SYSCONFDIR, sizeof(PHP_SYSCONFDIR)-1, CONST_PERSISTENT | CONST_CS);
1820 13565 : REGISTER_MAIN_STRINGL_CONSTANT("PHP_LOCALSTATEDIR", PHP_LOCALSTATEDIR, sizeof(PHP_LOCALSTATEDIR)-1, CONST_PERSISTENT | CONST_CS);
1821 13565 : REGISTER_MAIN_STRINGL_CONSTANT("PHP_CONFIG_FILE_PATH", PHP_CONFIG_FILE_PATH, strlen(PHP_CONFIG_FILE_PATH), CONST_PERSISTENT | CONST_CS);
1822 13565 : 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);
1823 13565 : REGISTER_MAIN_STRINGL_CONSTANT("PHP_SHLIB_SUFFIX", PHP_SHLIB_SUFFIX, sizeof(PHP_SHLIB_SUFFIX)-1, CONST_PERSISTENT | CONST_CS);
1824 13565 : REGISTER_MAIN_STRINGL_CONSTANT("PHP_EOL", PHP_EOL, sizeof(PHP_EOL)-1, CONST_PERSISTENT | CONST_CS);
1825 13565 : REGISTER_MAIN_LONG_CONSTANT("PHP_INT_MAX", LONG_MAX, CONST_PERSISTENT | CONST_CS);
1826 13565 : REGISTER_MAIN_LONG_CONSTANT("PHP_INT_SIZE", sizeof(long), CONST_PERSISTENT | CONST_CS);
1827 13565 : php_output_register_constants(TSRMLS_C);
1828 13565 : php_rfc1867_register_constants(TSRMLS_C);
1829 :
1830 13565 : if (php_startup_ticks(TSRMLS_C) == FAILURE) {
1831 0 : php_printf("Unable to start PHP ticks\n");
1832 0 : return FAILURE;
1833 : }
1834 :
1835 : /* Register internal Zend classes */
1836 13565 : zend_register_default_classes(TSRMLS_C);
1837 :
1838 : /* startup extensions staticly compiled in */
1839 13565 : if (php_register_internal_extensions(TSRMLS_C) == FAILURE) {
1840 0 : php_printf("Unable to start builtin modules\n");
1841 0 : return FAILURE;
1842 : }
1843 :
1844 : /* start additional PHP extensions */
1845 13565 : php_register_extensions(&additional_modules, num_additional_modules TSRMLS_CC);
1846 :
1847 : /* load and startup extensions compiled as shared objects (aka DLLs)
1848 : as requested by php.ini entries
1849 : theese are loaded after initialization of internal extensions
1850 : as extensions *might* rely on things from ext/standard
1851 : which is always an internal extension and to be initialized
1852 : ahead of all other internals
1853 : */
1854 13565 : php_ini_register_extensions(TSRMLS_C);
1855 13565 : zend_startup_modules(TSRMLS_C);
1856 :
1857 : /* disable certain classes and functions as requested by php.ini */
1858 13565 : php_disable_functions(TSRMLS_C);
1859 13565 : php_disable_classes(TSRMLS_C);
1860 :
1861 : /* start Zend extensions */
1862 13565 : zend_startup_extensions();
1863 :
1864 : #ifdef ZTS
1865 : zend_post_startup(TSRMLS_C);
1866 : #endif
1867 :
1868 13565 : module_initialized = 1;
1869 13565 : sapi_deactivate(TSRMLS_C);
1870 13565 : module_startup = 0;
1871 :
1872 13565 : shutdown_memory_manager(1, 0 TSRMLS_CC);
1873 :
1874 : /* we're done */
1875 13565 : return SUCCESS;
1876 : }
1877 : /* }}} */
1878 :
1879 : void php_module_shutdown_for_exec(void)
1880 0 : {
1881 : /* used to close fd's in the range 3.255 here, but it's problematic */
1882 0 : }
1883 :
1884 : /* {{{ php_module_shutdown_wrapper
1885 : */
1886 : int php_module_shutdown_wrapper(sapi_module_struct *sapi_globals)
1887 0 : {
1888 : TSRMLS_FETCH();
1889 0 : php_module_shutdown(TSRMLS_C);
1890 0 : return SUCCESS;
1891 : }
1892 : /* }}} */
1893 :
1894 : /* {{{ php_module_shutdown
1895 : */
1896 : void php_module_shutdown(TSRMLS_D)
1897 13598 : {
1898 13598 : int module_number=0; /* for UNREGISTER_INI_ENTRIES() */
1899 :
1900 13598 : module_shutdown = 1;
1901 :
1902 13598 : if (!module_initialized) {
1903 0 : return;
1904 : }
1905 :
1906 : #ifdef ZTS
1907 : ts_free_worker_threads();
1908 : #endif
1909 :
1910 : #if defined(PHP_WIN32) || (defined(NETWARE) && defined(USE_WINSOCK))
1911 : /*close winsock */
1912 : WSACleanup();
1913 : #endif
1914 :
1915 13598 : php_shutdown_ticks(TSRMLS_C);
1916 13598 : sapi_flush(TSRMLS_C);
1917 :
1918 13598 : zend_shutdown(TSRMLS_C);
1919 :
1920 : /* Destroys filter & transport registries too */
1921 13597 : php_shutdown_stream_wrappers(module_number TSRMLS_CC);
1922 :
1923 13597 : php_shutdown_info_logos();
1924 13597 : UNREGISTER_INI_ENTRIES();
1925 :
1926 : /* close down the ini config */
1927 13597 : php_shutdown_config();
1928 :
1929 : #ifndef ZTS
1930 13597 : zend_ini_shutdown(TSRMLS_C);
1931 13597 : shutdown_memory_manager(CG(unclean_shutdown), 1 TSRMLS_CC);
1932 13597 : core_globals_dtor(&core_globals TSRMLS_CC);
1933 : #else
1934 : zend_ini_global_shutdown(TSRMLS_C);
1935 : ts_free_id(core_globals_id);
1936 : #endif
1937 :
1938 13597 : php_shutdown_temporary_directory();
1939 :
1940 13597 : module_initialized = 0;
1941 :
1942 : #if defined(PHP_WIN32) && defined(_MSC_VER) && (_MSC_VER >= 1400)
1943 : if (old_invalid_parameter_handler == NULL) {
1944 : _set_invalid_parameter_handler(old_invalid_parameter_handler);
1945 : }
1946 : #endif
1947 : }
1948 : /* }}} */
1949 :
1950 : /* {{{ php_execute_script
1951 : */
1952 : PHPAPI int php_execute_script(zend_file_handle *primary_file TSRMLS_DC)
1953 13483 : {
1954 : zend_file_handle *prepend_file_p, *append_file_p;
1955 13483 : zend_file_handle prepend_file = {0}, append_file = {0};
1956 : #if HAVE_BROKEN_GETCWD
1957 : int old_cwd_fd = -1;
1958 : #else
1959 : char *old_cwd;
1960 : #endif
1961 13483 : int retval = 0;
1962 :
1963 13483 : EG(exit_status) = 0;
1964 13483 : if (php_handle_special_queries(TSRMLS_C)) {
1965 0 : zend_file_handle_dtor(primary_file);
1966 0 : return 0;
1967 : }
1968 : #ifndef HAVE_BROKEN_GETCWD
1969 : # define OLD_CWD_SIZE 4096
1970 13483 : old_cwd = do_alloca(OLD_CWD_SIZE);
1971 13483 : old_cwd[0] = '\0';
1972 : #endif
1973 :
1974 13483 : zend_try {
1975 : char realfile[MAXPATHLEN];
1976 :
1977 : #ifdef PHP_WIN32
1978 : UpdateIniFromRegistry(primary_file->filename TSRMLS_CC);
1979 : #endif
1980 :
1981 13483 : PG(during_request_startup) = 0;
1982 :
1983 13483 : if ((primary_file->type == ZEND_HANDLE_FILENAME || primary_file->type == ZEND_HANDLE_STREAM) && primary_file->filename) {
1984 : #if HAVE_BROKEN_GETCWD
1985 : /* this looks nasty to me */
1986 : old_cwd_fd = open(".", 0);
1987 : #else
1988 0 : VCWD_GETCWD(old_cwd, OLD_CWD_SIZE-1);
1989 : #endif
1990 0 : VCWD_CHDIR_FILE(primary_file->filename);
1991 : }
1992 :
1993 : /* Only lookup the real file path and add it to the included_files list if already opened
1994 : * otherwise it will get opened and added to the included_files list in zend_execute_scripts
1995 : */
1996 13483 : if (primary_file->filename &&
1997 : primary_file->opened_path == NULL &&
1998 : primary_file->type != ZEND_HANDLE_FILENAME
1999 : ) {
2000 : int realfile_len;
2001 13399 : int dummy = 1;
2002 :
2003 13399 : if (expand_filepath(primary_file->filename, realfile TSRMLS_CC)) {
2004 13399 : realfile_len = strlen(realfile);
2005 13399 : zend_hash_add(&EG(included_files), realfile, realfile_len+1, (void *)&dummy, sizeof(int), NULL);
2006 13399 : primary_file->opened_path = estrndup(realfile, realfile_len);
2007 : }
2008 : }
2009 :
2010 13484 : if (PG(auto_prepend_file) && PG(auto_prepend_file)[0]) {
2011 1 : prepend_file.filename = PG(auto_prepend_file);
2012 1 : prepend_file.opened_path = NULL;
2013 1 : prepend_file.free_filename = 0;
2014 1 : prepend_file.type = ZEND_HANDLE_FILENAME;
2015 1 : prepend_file_p = &prepend_file;
2016 : } else {
2017 13482 : prepend_file_p = NULL;
2018 : }
2019 :
2020 13483 : if (PG(auto_append_file) && PG(auto_append_file)[0]) {
2021 0 : append_file.filename = PG(auto_append_file);
2022 0 : append_file.opened_path = NULL;
2023 0 : append_file.free_filename = 0;
2024 0 : append_file.type = ZEND_HANDLE_FILENAME;
2025 0 : append_file_p = &append_file;
2026 : } else {
2027 13483 : append_file_p = NULL;
2028 : }
2029 13483 : if (PG(max_input_time) != -1) {
2030 : #ifdef PHP_WIN32
2031 : zend_unset_timeout(TSRMLS_C);
2032 : #endif
2033 0 : zend_set_timeout(INI_INT("max_execution_time"));
2034 : }
2035 13483 : retval = (zend_execute_scripts(ZEND_REQUIRE TSRMLS_CC, NULL, 3, prepend_file_p, primary_file, append_file_p) == SUCCESS);
2036 :
2037 13519 : } zend_end_try();
2038 :
2039 : #if HAVE_BROKEN_GETCWD
2040 : if (old_cwd_fd != -1) {
2041 : fchdir(old_cwd_fd);
2042 : close(old_cwd_fd);
2043 : }
2044 : #else
2045 13519 : if (old_cwd[0] != '\0') {
2046 0 : VCWD_CHDIR(old_cwd);
2047 : }
2048 : free_alloca(old_cwd);
2049 : #endif
2050 13519 : return retval;
2051 : }
2052 : /* }}} */
2053 :
2054 : /* {{{ php_execute_simple_script
2055 : */
2056 : PHPAPI int php_execute_simple_script(zend_file_handle *primary_file, zval **ret TSRMLS_DC)
2057 0 : {
2058 : char *old_cwd;
2059 :
2060 0 : EG(exit_status) = 0;
2061 : #define OLD_CWD_SIZE 4096
2062 0 : old_cwd = do_alloca(OLD_CWD_SIZE);
2063 0 : old_cwd[0] = '\0';
2064 :
2065 0 : zend_try {
2066 : #ifdef PHP_WIN32
2067 : UpdateIniFromRegistry(primary_file->filename TSRMLS_CC);
2068 : #endif
2069 :
2070 0 : PG(during_request_startup) = 0;
2071 :
2072 0 : if (primary_file->type == ZEND_HANDLE_FILENAME && primary_file->filename) {
2073 0 : VCWD_GETCWD(old_cwd, OLD_CWD_SIZE-1);
2074 0 : VCWD_CHDIR_FILE(primary_file->filename);
2075 : }
2076 0 : zend_execute_scripts(ZEND_REQUIRE TSRMLS_CC, ret, 1, primary_file);
2077 0 : } zend_end_try();
2078 :
2079 0 : if (old_cwd[0] != '\0') {
2080 0 : VCWD_CHDIR(old_cwd);
2081 : }
2082 :
2083 : free_alloca(old_cwd);
2084 0 : return EG(exit_status);
2085 : }
2086 : /* }}} */
2087 :
2088 : /* {{{ php_handle_aborted_connection
2089 : */
2090 : PHPAPI void php_handle_aborted_connection(void)
2091 3 : {
2092 : TSRMLS_FETCH();
2093 :
2094 3 : PG(connection_status) = PHP_CONNECTION_ABORTED;
2095 3 : php_output_set_status(0 TSRMLS_CC);
2096 :
2097 3 : if (!PG(ignore_user_abort)) {
2098 3 : zend_bailout();
2099 : }
2100 0 : }
2101 : /* }}} */
2102 :
2103 : /* {{{ php_handle_auth_data
2104 : */
2105 : PHPAPI int php_handle_auth_data(const char *auth TSRMLS_DC)
2106 59 : {
2107 59 : int ret = -1;
2108 :
2109 59 : if (auth && auth[0] != '\0' && strncmp(auth, "Basic ", 6) == 0) {
2110 : char *pass;
2111 : char *user;
2112 :
2113 0 : user = php_base64_decode(auth + 6, strlen(auth) - 6, NULL);
2114 0 : if (user) {
2115 0 : pass = strchr(user, ':');
2116 0 : if (pass) {
2117 0 : *pass++ = '\0';
2118 0 : SG(request_info).auth_user = user;
2119 0 : SG(request_info).auth_password = estrdup(pass);
2120 0 : ret = 0;
2121 : } else {
2122 0 : efree(user);
2123 : }
2124 : }
2125 : }
2126 :
2127 59 : if (ret == -1) {
2128 59 : SG(request_info).auth_user = SG(request_info).auth_password = NULL;
2129 : } else {
2130 0 : SG(request_info).auth_digest = NULL;
2131 : }
2132 :
2133 59 : if (ret == -1 && auth && auth[0] != '\0' && strncmp(auth, "Digest ", 7) == 0) {
2134 0 : SG(request_info).auth_digest = estrdup(auth + 7);
2135 0 : ret = 0;
2136 : }
2137 :
2138 59 : if (ret == -1) {
2139 59 : SG(request_info).auth_digest = NULL;
2140 : }
2141 :
2142 59 : return ret;
2143 : }
2144 : /* }}} */
2145 :
2146 : /* {{{ php_lint_script
2147 : */
2148 : PHPAPI int php_lint_script(zend_file_handle *file TSRMLS_DC)
2149 5 : {
2150 : zend_op_array *op_array;
2151 5 : int retval = FAILURE;
2152 :
2153 5 : zend_try {
2154 5 : op_array = zend_compile_file(file, ZEND_INCLUDE TSRMLS_CC);
2155 3 : zend_destroy_file_handle(file TSRMLS_CC);
2156 :
2157 3 : if (op_array) {
2158 3 : destroy_op_array(op_array TSRMLS_CC);
2159 3 : efree(op_array);
2160 3 : retval = SUCCESS;
2161 : }
2162 5 : } zend_end_try();
2163 :
2164 5 : return retval;
2165 : }
2166 : /* }}} */
2167 :
2168 : #ifdef PHP_WIN32
2169 : /* {{{ dummy_indent
2170 : just so that this symbol gets exported... */
2171 : PHPAPI void dummy_indent(void)
2172 : {
2173 : zend_indent();
2174 : }
2175 : /* }}} */
2176 : #endif
2177 :
2178 : /*
2179 : * Local variables:
2180 : * tab-width: 4
2181 : * c-basic-offset: 4
2182 : * End:
2183 : * vim600: sw=4 ts=4 fdm=marker
2184 : * vim<600: sw=4 ts=4
2185 : */
|