Diff for /embedaddon/php/main/main.c between versions 1.1.1.1 and 1.1.1.2

version 1.1.1.1, 2012/02/21 23:48:05 version 1.1.1.2, 2012/05/29 12:34:35
Line 82 Line 82
 #include "zend_indent.h"  #include "zend_indent.h"
 #include "zend_extensions.h"  #include "zend_extensions.h"
 #include "zend_ini.h"  #include "zend_ini.h"
   #include "zend_dtrace.h"
   
 #include "php_content_types.h"  #include "php_content_types.h"
 #include "php_ticks.h"  #include "php_ticks.h"
Line 91 Line 92
   
 #include "SAPI.h"  #include "SAPI.h"
 #include "rfc1867.h"  #include "rfc1867.h"
 #if SUHOSIN_PATCH  
 #include "suhosin_globals.h"  
 #endif  
   
#if HAVE_MMAP#if HAVE_MMAP || defined(PHP_WIN32)
 # if HAVE_UNISTD_H  # if HAVE_UNISTD_H
 #  include <unistd.h>  #  include <unistd.h>
 #  if defined(_SC_PAGESIZE)  #  if defined(_SC_PAGESIZE)
Line 128  PHPAPI int core_globals_id; Line 126  PHPAPI int core_globals_id;
 #ifdef PHP_WIN32  #ifdef PHP_WIN32
 #include "win32_internal_function_disabled.h"  #include "win32_internal_function_disabled.h"
   
static php_win32_disable_functions() {static php_win32_disable_functions(TSRMLS_D)
 {
         int i;          int i;
         TSRMLS_FETCH();  
   
         if (EG(windows_version_info).dwMajorVersion < 5) {          if (EG(windows_version_info).dwMajorVersion < 5) {
                 for (i = 0; i < function_name_cnt_5; i++) {                  for (i = 0; i < function_name_cnt_5; i++) {
Line 257  static void php_disable_classes(TSRMLS_D) Line 255  static void php_disable_classes(TSRMLS_D)
 }  }
 /* }}} */  /* }}} */
   
   /* {{{ php_binary_init
    */
   static void php_binary_init(TSRMLS_D) 
   {
           char *binary_location;
   #ifdef PHP_WIN32
           binary_location = (char *)malloc(MAXPATHLEN);
           if (GetModuleFileName(0, binary_location, MAXPATHLEN) == 0) {
                   free(binary_location);
                   PG(php_binary) = NULL;
           }
   #else
           if (sapi_module.executable_location) {
                   binary_location = (char *)malloc(MAXPATHLEN);
                   if (!strchr(sapi_module.executable_location, '/')) {
                           char *envpath, *path;
                           int found = 0;
   
                           if ((envpath = getenv("PATH")) != NULL) {
                                   char *search_dir, search_path[MAXPATHLEN];
                                   char *last = NULL;
   
                                   path = estrdup(envpath);
                                   search_dir = php_strtok_r(path, ":", &last);
   
                                   while (search_dir) {
                                           snprintf(search_path, MAXPATHLEN, "%s/%s", search_dir, sapi_module.executable_location);
                                           if (VCWD_REALPATH(search_path, binary_location) && !VCWD_ACCESS(binary_location, X_OK)) {
                                                   found = 1;
                                                   break;
                                           }
                                           search_dir = php_strtok_r(NULL, ":", &last);
                                   }
                                   efree(path);
                           }
                           if (!found) {
                                   free(binary_location);
                                   binary_location = NULL;
                           }
                   } else if (!VCWD_REALPATH(sapi_module.executable_location, binary_location) || VCWD_ACCESS(binary_location, X_OK)) {
                           free(binary_location);
                           binary_location = NULL;
                   }
           } else {
                   binary_location = NULL;
           }
   #endif
           PG(php_binary) = binary_location;
   }
   /* }}} */
   
 /* {{{ PHP_INI_MH  /* {{{ PHP_INI_MH
  */   */
 static PHP_INI_MH(OnUpdateTimeout)  static PHP_INI_MH(OnUpdateTimeout)
Line 368  static PHP_INI_MH(OnUpdateErrorLog) Line 417  static PHP_INI_MH(OnUpdateErrorLog)
 {  {
         /* Only do the safemode/open_basedir check at runtime */          /* Only do the safemode/open_basedir check at runtime */
         if ((stage == PHP_INI_STAGE_RUNTIME || stage == PHP_INI_STAGE_HTACCESS) && new_value && strcmp(new_value, "syslog")) {          if ((stage == PHP_INI_STAGE_RUNTIME || stage == PHP_INI_STAGE_HTACCESS) && new_value && strcmp(new_value, "syslog")) {
                 if (PG(safe_mode) && (!php_checkuid(new_value, NULL, CHECKUID_CHECK_FILE_AND_DIR))) {  
                         return FAILURE;  
                 }  
   
                 if (PG(open_basedir) && php_check_open_basedir(new_value TSRMLS_CC)) {                  if (PG(open_basedir) && php_check_open_basedir(new_value TSRMLS_CC)) {
                         return FAILURE;                          return FAILURE;
                 }                  }
   
         }          }
         OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);          OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
         return SUCCESS;          return SUCCESS;
Line 388  static PHP_INI_MH(OnUpdateMailLog) Line 432  static PHP_INI_MH(OnUpdateMailLog)
 {  {
         /* Only do the safemode/open_basedir check at runtime */          /* Only do the safemode/open_basedir check at runtime */
         if ((stage == PHP_INI_STAGE_RUNTIME || stage == PHP_INI_STAGE_HTACCESS) && new_value) {          if ((stage == PHP_INI_STAGE_RUNTIME || stage == PHP_INI_STAGE_HTACCESS) && new_value) {
                 if (PG(safe_mode) && (!php_checkuid(new_value, NULL, CHECKUID_CHECK_FILE_AND_DIR))) {  
                         return FAILURE;  
                 }  
   
                 if (PG(open_basedir) && php_check_open_basedir(new_value TSRMLS_CC)) {                  if (PG(open_basedir) && php_check_open_basedir(new_value TSRMLS_CC)) {
                         return FAILURE;                          return FAILURE;
                 }                  }
   
         }          }
         OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);          OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
         return SUCCESS;          return SUCCESS;
Line 417  static PHP_INI_MH(OnChangeMailForceExtra) Line 456  static PHP_INI_MH(OnChangeMailForceExtra)
 /* defined in browscap.c */  /* defined in browscap.c */
 PHP_INI_MH(OnChangeBrowscap);  PHP_INI_MH(OnChangeBrowscap);
   
/* Need to convert to strings and make use of:
 * PHP_SAFE_MODE/* Need to be read from the environment (?):
 * 
 * Need to be read from the environment (?): 
  * PHP_AUTO_PREPEND_FILE   * PHP_AUTO_PREPEND_FILE
  * PHP_AUTO_APPEND_FILE   * PHP_AUTO_APPEND_FILE
  * PHP_DOCUMENT_ROOT   * PHP_DOCUMENT_ROOT
Line 428  PHP_INI_MH(OnChangeBrowscap); Line 465  PHP_INI_MH(OnChangeBrowscap);
  * PHP_INCLUDE_PATH   * PHP_INCLUDE_PATH
  */   */
   
 #ifndef PHP_SAFE_MODE_EXEC_DIR  
 #       define PHP_SAFE_MODE_EXEC_DIR ""  
 #endif  
   
  /* Windows and Netware use the internal mail */   /* Windows and Netware use the internal mail */
 #if defined(PHP_WIN32) || defined(NETWARE)  #if defined(PHP_WIN32) || defined(NETWARE)
 # define DEFAULT_SENDMAIL_PATH NULL  # define DEFAULT_SENDMAIL_PATH NULL
Line 444  PHP_INI_MH(OnChangeBrowscap); Line 477  PHP_INI_MH(OnChangeBrowscap);
 /* {{{ PHP_INI  /* {{{ PHP_INI
  */   */
 PHP_INI_BEGIN()  PHP_INI_BEGIN()
         PHP_INI_ENTRY_EX("define_syslog_variables",     "0",                            PHP_INI_ALL,    NULL,                   php_ini_boolean_displayer_cb)  
         PHP_INI_ENTRY_EX("highlight.bg",                        HL_BG_COLOR,            PHP_INI_ALL,    NULL,                   php_ini_color_displayer_cb)  
         PHP_INI_ENTRY_EX("highlight.comment",           HL_COMMENT_COLOR,       PHP_INI_ALL,    NULL,                   php_ini_color_displayer_cb)          PHP_INI_ENTRY_EX("highlight.comment",           HL_COMMENT_COLOR,       PHP_INI_ALL,    NULL,                   php_ini_color_displayer_cb)
         PHP_INI_ENTRY_EX("highlight.default",           HL_DEFAULT_COLOR,       PHP_INI_ALL,    NULL,                   php_ini_color_displayer_cb)          PHP_INI_ENTRY_EX("highlight.default",           HL_DEFAULT_COLOR,       PHP_INI_ALL,    NULL,                   php_ini_color_displayer_cb)
         PHP_INI_ENTRY_EX("highlight.html",                      HL_HTML_COLOR,          PHP_INI_ALL,    NULL,                   php_ini_color_displayer_cb)          PHP_INI_ENTRY_EX("highlight.html",                      HL_HTML_COLOR,          PHP_INI_ALL,    NULL,                   php_ini_color_displayer_cb)
         PHP_INI_ENTRY_EX("highlight.keyword",           HL_KEYWORD_COLOR,       PHP_INI_ALL,    NULL,                   php_ini_color_displayer_cb)          PHP_INI_ENTRY_EX("highlight.keyword",           HL_KEYWORD_COLOR,       PHP_INI_ALL,    NULL,                   php_ini_color_displayer_cb)
         PHP_INI_ENTRY_EX("highlight.string",            HL_STRING_COLOR,        PHP_INI_ALL,    NULL,                   php_ini_color_displayer_cb)          PHP_INI_ENTRY_EX("highlight.string",            HL_STRING_COLOR,        PHP_INI_ALL,    NULL,                   php_ini_color_displayer_cb)
   
         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)  
         STD_PHP_INI_BOOLEAN("asp_tags",                         "0",            PHP_INI_SYSTEM|PHP_INI_PERDIR,          OnUpdateBool,                   asp_tags,                               zend_compiler_globals,  compiler_globals)          STD_PHP_INI_BOOLEAN("asp_tags",                         "0",            PHP_INI_SYSTEM|PHP_INI_PERDIR,          OnUpdateBool,                   asp_tags,                               zend_compiler_globals,  compiler_globals)
         STD_PHP_INI_ENTRY_EX("display_errors",          "1",            PHP_INI_ALL,            OnUpdateDisplayErrors,  display_errors,                 php_core_globals,       core_globals, display_errors_mode)          STD_PHP_INI_ENTRY_EX("display_errors",          "1",            PHP_INI_ALL,            OnUpdateDisplayErrors,  display_errors,                 php_core_globals,       core_globals, display_errors_mode)
         STD_PHP_INI_BOOLEAN("display_startup_errors",   "0",    PHP_INI_ALL,            OnUpdateBool,                   display_startup_errors, php_core_globals,       core_globals)          STD_PHP_INI_BOOLEAN("display_startup_errors",   "0",    PHP_INI_ALL,            OnUpdateBool,                   display_startup_errors, php_core_globals,       core_globals)
Line 472  PHP_INI_BEGIN() Line 502  PHP_INI_BEGIN()
         STD_PHP_INI_BOOLEAN("ignore_repeated_source",   "0",    PHP_INI_ALL,            OnUpdateBool,                   ignore_repeated_source, php_core_globals,       core_globals)          STD_PHP_INI_BOOLEAN("ignore_repeated_source",   "0",    PHP_INI_ALL,            OnUpdateBool,                   ignore_repeated_source, php_core_globals,       core_globals)
         STD_PHP_INI_BOOLEAN("report_memleaks",          "1",            PHP_INI_ALL,            OnUpdateBool,                   report_memleaks,                php_core_globals,       core_globals)          STD_PHP_INI_BOOLEAN("report_memleaks",          "1",            PHP_INI_ALL,            OnUpdateBool,                   report_memleaks,                php_core_globals,       core_globals)
         STD_PHP_INI_BOOLEAN("report_zend_debug",        "1",            PHP_INI_ALL,            OnUpdateBool,                   report_zend_debug,              php_core_globals,       core_globals)          STD_PHP_INI_BOOLEAN("report_zend_debug",        "1",            PHP_INI_ALL,            OnUpdateBool,                   report_zend_debug,              php_core_globals,       core_globals)
         STD_PHP_INI_BOOLEAN("magic_quotes_gpc",         "1",            PHP_INI_PERDIR|PHP_INI_SYSTEM,  OnUpdateBool,   magic_quotes_gpc,               php_core_globals,       core_globals)  
         STD_PHP_INI_BOOLEAN("magic_quotes_runtime",     "0",            PHP_INI_ALL,            OnUpdateBool,                   magic_quotes_runtime,   php_core_globals,       core_globals)  
         STD_PHP_INI_BOOLEAN("magic_quotes_sybase",      "0",            PHP_INI_ALL,            OnUpdateBool,                   magic_quotes_sybase,    php_core_globals,       core_globals)  
         STD_PHP_INI_ENTRY("output_buffering",           "0",            PHP_INI_PERDIR|PHP_INI_SYSTEM,  OnUpdateLong,   output_buffering,               php_core_globals,       core_globals)          STD_PHP_INI_ENTRY("output_buffering",           "0",            PHP_INI_PERDIR|PHP_INI_SYSTEM,  OnUpdateLong,   output_buffering,               php_core_globals,       core_globals)
         STD_PHP_INI_ENTRY("output_handler",                     NULL,           PHP_INI_PERDIR|PHP_INI_SYSTEM,  OnUpdateString, output_handler,         php_core_globals,       core_globals)          STD_PHP_INI_ENTRY("output_handler",                     NULL,           PHP_INI_PERDIR|PHP_INI_SYSTEM,  OnUpdateString, output_handler,         php_core_globals,       core_globals)
         STD_PHP_INI_BOOLEAN("register_argc_argv",       "1",            PHP_INI_PERDIR|PHP_INI_SYSTEM,  OnUpdateBool,   register_argc_argv,             php_core_globals,       core_globals)          STD_PHP_INI_BOOLEAN("register_argc_argv",       "1",            PHP_INI_PERDIR|PHP_INI_SYSTEM,  OnUpdateBool,   register_argc_argv,             php_core_globals,       core_globals)
         STD_PHP_INI_BOOLEAN("register_globals",         "0",            PHP_INI_PERDIR|PHP_INI_SYSTEM,  OnUpdateBool,   register_globals,               php_core_globals,       core_globals)  
         STD_PHP_INI_BOOLEAN("register_long_arrays",     "1",            PHP_INI_PERDIR|PHP_INI_SYSTEM,  OnUpdateBool,   register_long_arrays,   php_core_globals,       core_globals)  
         STD_PHP_INI_BOOLEAN("auto_globals_jit",         "1",            PHP_INI_PERDIR|PHP_INI_SYSTEM,  OnUpdateBool,   auto_globals_jit,       php_core_globals,       core_globals)          STD_PHP_INI_BOOLEAN("auto_globals_jit",         "1",            PHP_INI_PERDIR|PHP_INI_SYSTEM,  OnUpdateBool,   auto_globals_jit,       php_core_globals,       core_globals)
 #if PHP_SAFE_MODE  
         STD_PHP_INI_BOOLEAN("safe_mode",                        "1",            PHP_INI_SYSTEM,         OnUpdateBool,                   safe_mode,                              php_core_globals,       core_globals)  
 #else  
         STD_PHP_INI_BOOLEAN("safe_mode",                        "0",            PHP_INI_SYSTEM,         OnUpdateBool,                   safe_mode,                              php_core_globals,       core_globals)  
 #endif  
         STD_PHP_INI_ENTRY("safe_mode_include_dir",      NULL,           PHP_INI_SYSTEM,         OnUpdateString,                 safe_mode_include_dir,  php_core_globals,       core_globals)  
         STD_PHP_INI_BOOLEAN("safe_mode_gid",            "0",            PHP_INI_SYSTEM,         OnUpdateBool,                   safe_mode_gid,                  php_core_globals,       core_globals)  
         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)          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)
         STD_PHP_INI_BOOLEAN("sql.safe_mode",            "0",            PHP_INI_SYSTEM,         OnUpdateBool,                   sql_safe_mode,                  php_core_globals,       core_globals)          STD_PHP_INI_BOOLEAN("sql.safe_mode",            "0",            PHP_INI_SYSTEM,         OnUpdateBool,                   sql_safe_mode,                  php_core_globals,       core_globals)
         STD_PHP_INI_BOOLEAN("track_errors",                     "0",            PHP_INI_ALL,            OnUpdateBool,                   track_errors,                   php_core_globals,       core_globals)          STD_PHP_INI_BOOLEAN("track_errors",                     "0",            PHP_INI_ALL,            OnUpdateBool,                   track_errors,                   php_core_globals,       core_globals)
         STD_PHP_INI_BOOLEAN("y2k_compliance",           "1",            PHP_INI_ALL,            OnUpdateBool,                   y2k_compliance,                 php_core_globals,       core_globals)  
   
         STD_PHP_INI_ENTRY("unserialize_callback_func",  NULL,   PHP_INI_ALL,            OnUpdateString,                 unserialize_callback_func,      php_core_globals,       core_globals)          STD_PHP_INI_ENTRY("unserialize_callback_func",  NULL,   PHP_INI_ALL,            OnUpdateString,                 unserialize_callback_func,      php_core_globals,       core_globals)
         STD_PHP_INI_ENTRY("serialize_precision",        "17",   PHP_INI_ALL,            OnUpdateLongGEZero,                     serialize_precision,    php_core_globals,       core_globals)          STD_PHP_INI_ENTRY("serialize_precision",        "17",   PHP_INI_ALL,            OnUpdateLongGEZero,                     serialize_precision,    php_core_globals,       core_globals)
Line 507  PHP_INI_BEGIN() Line 524  PHP_INI_BEGIN()
         STD_PHP_INI_ENTRY("extension_dir",                      PHP_EXTENSION_DIR,              PHP_INI_SYSTEM,         OnUpdateStringUnempty,  extension_dir,                  php_core_globals,       core_globals)          STD_PHP_INI_ENTRY("extension_dir",                      PHP_EXTENSION_DIR,              PHP_INI_SYSTEM,         OnUpdateStringUnempty,  extension_dir,                  php_core_globals,       core_globals)
         STD_PHP_INI_ENTRY("include_path",                       PHP_INCLUDE_PATH,               PHP_INI_ALL,            OnUpdateStringUnempty,  include_path,                   php_core_globals,       core_globals)          STD_PHP_INI_ENTRY("include_path",                       PHP_INCLUDE_PATH,               PHP_INI_ALL,            OnUpdateStringUnempty,  include_path,                   php_core_globals,       core_globals)
         PHP_INI_ENTRY("max_execution_time",                     "30",           PHP_INI_ALL,                    OnUpdateTimeout)          PHP_INI_ENTRY("max_execution_time",                     "30",           PHP_INI_ALL,                    OnUpdateTimeout)
        PHP_INI_ENTRY("open_basedir",                   NULL,           PHP_INI_ALL,            OnUpdateBaseDir)        STD_PHP_INI_ENTRY("open_basedir",                   NULL,           PHP_INI_ALL,            OnUpdateBaseDir,                       open_basedir,                    php_core_globals,       core_globals)
        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) 
   
         STD_PHP_INI_BOOLEAN("file_uploads",                     "1",            PHP_INI_SYSTEM,         OnUpdateBool,                   file_uploads,                   php_core_globals,       core_globals)          STD_PHP_INI_BOOLEAN("file_uploads",                     "1",            PHP_INI_SYSTEM,         OnUpdateBool,                   file_uploads,                   php_core_globals,       core_globals)
         STD_PHP_INI_ENTRY("upload_max_filesize",        "2M",           PHP_INI_SYSTEM|PHP_INI_PERDIR,          OnUpdateLong,                   upload_max_filesize,    php_core_globals,       core_globals)          STD_PHP_INI_ENTRY("upload_max_filesize",        "2M",           PHP_INI_SYSTEM|PHP_INI_PERDIR,          OnUpdateLong,                   upload_max_filesize,    php_core_globals,       core_globals)
Line 536  PHP_INI_BEGIN() Line 552  PHP_INI_BEGIN()
         PHP_INI_ENTRY("mail.force_extra_parameters",NULL,               PHP_INI_SYSTEM|PHP_INI_PERDIR,          OnChangeMailForceExtra)          PHP_INI_ENTRY("mail.force_extra_parameters",NULL,               PHP_INI_SYSTEM|PHP_INI_PERDIR,          OnChangeMailForceExtra)
         PHP_INI_ENTRY("disable_functions",                      "",                     PHP_INI_SYSTEM,         NULL)          PHP_INI_ENTRY("disable_functions",                      "",                     PHP_INI_SYSTEM,         NULL)
         PHP_INI_ENTRY("disable_classes",                        "",                     PHP_INI_SYSTEM,         NULL)          PHP_INI_ENTRY("disable_classes",                        "",                     PHP_INI_SYSTEM,         NULL)
        PHP_INI_ENTRY("max_file_uploads",                       "20",                   PHP_INI_SYSTEM,               NULL)        PHP_INI_ENTRY("max_file_uploads",                       "20",           PHP_INI_SYSTEM|PHP_INI_PERDIR,               NULL)
   
         STD_PHP_INI_BOOLEAN("allow_url_fopen",          "1",            PHP_INI_SYSTEM,         OnUpdateBool,           allow_url_fopen,                php_core_globals,               core_globals)          STD_PHP_INI_BOOLEAN("allow_url_fopen",          "1",            PHP_INI_SYSTEM,         OnUpdateBool,           allow_url_fopen,                php_core_globals,               core_globals)
         STD_PHP_INI_BOOLEAN("allow_url_include",        "0",            PHP_INI_SYSTEM,         OnUpdateBool,           allow_url_include,              php_core_globals,               core_globals)          STD_PHP_INI_BOOLEAN("allow_url_include",        "0",            PHP_INI_SYSTEM,         OnUpdateBool,           allow_url_include,              php_core_globals,               core_globals)
           STD_PHP_INI_BOOLEAN("enable_post_data_reading", "1",    PHP_INI_SYSTEM|PHP_INI_PERDIR,  OnUpdateBool,   enable_post_data_reading,       php_core_globals,       core_globals)
         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)          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)
   
         STD_PHP_INI_ENTRY("realpath_cache_size",        "16K",          PHP_INI_SYSTEM,         OnUpdateLong,   realpath_cache_size_limit,      virtual_cwd_globals,    cwd_globals)          STD_PHP_INI_ENTRY("realpath_cache_size",        "16K",          PHP_INI_SYSTEM,         OnUpdateLong,   realpath_cache_size_limit,      virtual_cwd_globals,    cwd_globals)
Line 574  static int php_during_module_shutdown(void) Line 591  static int php_during_module_shutdown(void)
 }  }
 /* }}} */  /* }}} */
   
   /* {{{ php_get_module_initialized
    */
   PHPAPI int php_get_module_initialized(void)
   {
           return module_initialized;
   }
   
 /* {{{ php_log_err  /* {{{ php_log_err
  */   */
 PHPAPI void php_log_err(char *log_message TSRMLS_DC)  PHPAPI void php_log_err(char *log_message TSRMLS_DC)
Line 608  PHPAPI void php_log_err(char *log_message TSRMLS_DC) Line 632  PHPAPI void php_log_err(char *log_message TSRMLS_DC)
 #ifdef PHP_WIN32  #ifdef PHP_WIN32
                         php_flock(fd, 2);                          php_flock(fd, 2);
 #endif  #endif
                        write(fd, tmp, len);                        php_ignore_value(write(fd, tmp, len));
                         efree(tmp);                          efree(tmp);
                         efree(error_time_str);                          efree(error_time_str);
                         close(fd);                          close(fd);
Line 620  PHPAPI void php_log_err(char *log_message TSRMLS_DC) Line 644  PHPAPI void php_log_err(char *log_message TSRMLS_DC)
         /* Otherwise fall back to the default logging location, if we have one */          /* Otherwise fall back to the default logging location, if we have one */
   
         if (sapi_module.log_message) {          if (sapi_module.log_message) {
                sapi_module.log_message(log_message);                sapi_module.log_message(log_message TSRMLS_CC);
         }          }
         PG(in_error_log) = 0;          PG(in_error_log) = 0;
 }  }
Line 666  PHPAPI void php_verror(const char *docref, const char  Line 690  PHPAPI void php_verror(const char *docref, const char 
         char *docref_target = "", *docref_root = "";          char *docref_target = "", *docref_root = "";
         char *p;          char *p;
         int buffer_len = 0;          int buffer_len = 0;
        char *space = "";        const char *space = "";
        char *class_name = "";        const char *class_name = "";
        char *function;        const char *function;
         int origin_len;          int origin_len;
         char *origin;          char *origin;
         char *message;          char *message;
Line 676  PHPAPI void php_verror(const char *docref, const char  Line 700  PHPAPI void php_verror(const char *docref, const char 
   
         /* get error text into buffer and escape for html if necessary */          /* get error text into buffer and escape for html if necessary */
         buffer_len = vspprintf(&buffer, 0, format, args);          buffer_len = vspprintf(&buffer, 0, format, args);
   
         if (PG(html_errors)) {          if (PG(html_errors)) {
                int len;                size_t len;
                 char *replace = php_escape_html_entities(buffer, buffer_len, &len, 0, ENT_COMPAT, NULL TSRMLS_CC);                  char *replace = php_escape_html_entities(buffer, buffer_len, &len, 0, ENT_COMPAT, NULL TSRMLS_CC);
                 efree(buffer);                  efree(buffer);
                 buffer = replace;                  buffer = replace;
Line 693  PHPAPI void php_verror(const char *docref, const char  Line 718  PHPAPI void php_verror(const char *docref, const char 
                                 EG(current_execute_data)->opline &&                                  EG(current_execute_data)->opline &&
                                 EG(current_execute_data)->opline->opcode == ZEND_INCLUDE_OR_EVAL                                  EG(current_execute_data)->opline->opcode == ZEND_INCLUDE_OR_EVAL
         ) {          ) {
                switch (EG(current_execute_data)->opline->op2.u.constant.value.lval) {                switch (EG(current_execute_data)->opline->extended_value) {
                         case ZEND_EVAL:                          case ZEND_EVAL:
                                 function = "eval";                                  function = "eval";
                                 is_function = 1;                                  is_function = 1;
Line 735  PHPAPI void php_verror(const char *docref, const char  Line 760  PHPAPI void php_verror(const char *docref, const char 
         }          }
   
         if (PG(html_errors)) {          if (PG(html_errors)) {
                int len;                size_t len;
                 char *replace = php_escape_html_entities(origin, origin_len, &len, 0, ENT_COMPAT, NULL TSRMLS_CC);                  char *replace = php_escape_html_entities(origin, origin_len, &len, 0, ENT_COMPAT, NULL TSRMLS_CC);
                 efree(origin);                  efree(origin);
                 origin = replace;                  origin = replace;
Line 762  PHPAPI void php_verror(const char *docref, const char  Line 787  PHPAPI void php_verror(const char *docref, const char 
         }          }
   
         /* we have a docref for a function AND          /* we have a docref for a function AND
         * - we show erroes in html mode OR         * - we show errors in html mode AND
         * - the user wants to see the links anyway         * - the user wants to see the links
          */           */
        if (docref && is_function && (PG(html_errors) || strlen(PG(docref_root)))) {        if (docref && is_function && PG(html_errors) && strlen(PG(docref_root))) {
                 if (strncmp(docref, "http://", 7)) {                  if (strncmp(docref, "http://", 7)) {
                         /* We don't have 'http://' so we use docref_root */                          /* We don't have 'http://' so we use docref_root */
   
Line 927  static void php_error_cb(int type, const char *error_f Line 952  static void php_error_cb(int type, const char *error_f
   
         /* store the error if it has changed */          /* store the error if it has changed */
         if (display) {          if (display) {
   #ifdef ZEND_SIGNALS
                   HANDLE_BLOCK_INTERRUPTIONS();   
   #endif
                 if (PG(last_error_message)) {                  if (PG(last_error_message)) {
                         free(PG(last_error_message));                          free(PG(last_error_message));
                         PG(last_error_message) = NULL;                          PG(last_error_message) = NULL;
Line 935  static void php_error_cb(int type, const char *error_f Line 963  static void php_error_cb(int type, const char *error_f
                         free(PG(last_error_file));                          free(PG(last_error_file));
                         PG(last_error_file) = NULL;                          PG(last_error_file) = NULL;
                 }                  }
   #ifdef ZEND_SIGNALS
                   HANDLE_UNBLOCK_INTERRUPTIONS();
   #endif
                 if (!error_filename) {                  if (!error_filename) {
                         error_filename = "Unknown";                          error_filename = "Unknown";
                 }                  }
Line 1027  static void php_error_cb(int type, const char *error_f Line 1058  static void php_error_cb(int type, const char *error_f
                         efree(log_buffer);                          efree(log_buffer);
                 }                  }
   
                if (PG(display_errors)                if (PG(display_errors) && ((module_initialized && !PG(during_request_startup)) || (PG(display_startup_errors)))) {
                        && ((module_initialized && !PG(during_request_startup)) 
                                || (PG(display_startup_errors)  
                                        && (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) 
                                        ) 
                                ) 
                        ) { 
 
                         if (PG(xmlrpc_errors)) {                          if (PG(xmlrpc_errors)) {
                                 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);                                  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);
                         } else {                          } else {
Line 1042  static void php_error_cb(int type, const char *error_f Line 1066  static void php_error_cb(int type, const char *error_f
                                 char *append_string = INI_STR("error_append_string");                                  char *append_string = INI_STR("error_append_string");
   
                                 if (PG(html_errors)) {                                  if (PG(html_errors)) {
                                        if (type == E_ERROR) {                                        if (type == E_ERROR || type == E_PARSE) {
                                                int len;                                                size_t len;
                                                 char *buf = php_escape_html_entities(buffer, buffer_len, &len, 0, ENT_COMPAT, NULL TSRMLS_CC);                                                  char *buf = php_escape_html_entities(buffer, buffer_len, &len, 0, ENT_COMPAT, NULL TSRMLS_CC);
                                                 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));                                                  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));
                                                 efree(buf);                                                  efree(buf);
Line 1109  static void php_error_cb(int type, const char *error_f Line 1133  static void php_error_cb(int type, const char *error_f
                                         sapi_header_line ctr = {0};                                          sapi_header_line ctr = {0};
   
                                         ctr.line = "HTTP/1.0 500 Internal Server Error";                                          ctr.line = "HTTP/1.0 500 Internal Server Error";
                                        ctr.line_len = strlen(ctr.line);                                        ctr.line_len = sizeof("HTTP/1.0 500 Internal Server Error") - 1;
                                         sapi_header_op(SAPI_HEADER_REPLACE, &ctr TSRMLS_CC);                                          sapi_header_op(SAPI_HEADER_REPLACE, &ctr TSRMLS_CC);
                                 }                                  }
                                 /* the parser would return 1 (failure), we can bail out nicely */                                  /* the parser would return 1 (failure), we can bail out nicely */
                                if (type != E_PARSE) {                                if (type == E_PARSE) {
                                         CG(parse_error) = 0;
                                 } else {
                                         /* restore memory limit */                                          /* restore memory limit */
                                         zend_set_memory_limit(PG(memory_limit));                                          zend_set_memory_limit(PG(memory_limit));
                                         efree(buffer);                                          efree(buffer);
Line 1147  static void php_error_cb(int type, const char *error_f Line 1173  static void php_error_cb(int type, const char *error_f
 }  }
 /* }}} */  /* }}} */
   
   /* {{{ php_get_current_user
    */
   PHPAPI char *php_get_current_user(TSRMLS_D)
   {
           struct stat *pstat;
   
           if (SG(request_info).current_user) {
                   return SG(request_info).current_user;
           }
   
           /* FIXME: I need to have this somehow handled if
           USE_SAPI is defined, because cgi will also be
           interfaced in USE_SAPI */
   
           pstat = sapi_get_stat(TSRMLS_C);
   
           if (!pstat) {
                   return "";
           } else {
   #ifdef PHP_WIN32
                   char name[256];
                   DWORD len = sizeof(name)-1;
   
                   if (!GetUserName(name, &len)) {
                           return "";
                   }
                   name[len] = '\0';
                   SG(request_info).current_user_length = len;
                   SG(request_info).current_user = estrndup(name, len);
                   return SG(request_info).current_user;           
   #else
                   struct passwd *pwd;
   #if defined(ZTS) && defined(HAVE_GETPWUID_R) && defined(_SC_GETPW_R_SIZE_MAX)
                   struct passwd _pw;
                   struct passwd *retpwptr = NULL;
                   int pwbuflen = sysconf(_SC_GETPW_R_SIZE_MAX);
                   char *pwbuf;
   
                   if (pwbuflen < 1) {
                           return "";
                   }
                   pwbuf = emalloc(pwbuflen);
                   if (getpwuid_r(pstat->st_uid, &_pw, pwbuf, pwbuflen, &retpwptr) != 0) {
                           efree(pwbuf);
                           return "";
                   }
                   pwd = &_pw;
   #else
                   if ((pwd=getpwuid(pstat->st_uid))==NULL) {
                           return "";
                   }
   #endif
                   SG(request_info).current_user_length = strlen(pwd->pw_name);
                   SG(request_info).current_user = estrndup(pwd->pw_name, SG(request_info).current_user_length);
   #if defined(ZTS) && defined(HAVE_GETPWUID_R) && defined(_SC_GETPW_R_SIZE_MAX)
                   efree(pwbuf);
   #endif
                   return SG(request_info).current_user;           
   #endif
           }       
   }
   /* }}} */
   
 /* {{{ proto bool set_time_limit(int seconds)  /* {{{ proto bool set_time_limit(int seconds)
    Sets the maximum time a script can run */     Sets the maximum time a script can run */
 PHP_FUNCTION(set_time_limit)  PHP_FUNCTION(set_time_limit)
Line 1155  PHP_FUNCTION(set_time_limit) Line 1244  PHP_FUNCTION(set_time_limit)
         char *new_timeout_str;          char *new_timeout_str;
         int new_timeout_strlen;          int new_timeout_strlen;
   
         if (PG(safe_mode)) {  
                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot set time limit in safe mode");  
                 RETURN_FALSE;  
         }  
   
         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &new_timeout) == FAILURE) {          if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &new_timeout) == FAILURE) {
                 return;                  return;
         }          }
Line 1179  PHP_FUNCTION(set_time_limit) Line 1263  PHP_FUNCTION(set_time_limit)
  */   */
 static FILE *php_fopen_wrapper_for_zend(const char *filename, char **opened_path TSRMLS_DC)  static FILE *php_fopen_wrapper_for_zend(const char *filename, char **opened_path TSRMLS_DC)
 {  {
        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);        return php_stream_open_wrapper_as_file((char *)filename, "rb", USE_PATH|IGNORE_URL_WIN|REPORT_ERRORS|STREAM_OPEN_FOR_INCLUDE, opened_path);
 }  }
 /* }}} */  /* }}} */
   
Line 1208  static size_t php_zend_stream_fsizer(void *handle TSRM Line 1292  static size_t php_zend_stream_fsizer(void *handle TSRM
   
 static int php_stream_open_for_zend(const char *filename, zend_file_handle *handle TSRMLS_DC) /* {{{ */  static int php_stream_open_for_zend(const char *filename, zend_file_handle *handle TSRMLS_DC) /* {{{ */
 {  {
        return php_stream_open_for_zend_ex(filename, handle, ENFORCE_SAFE_MODE|USE_PATH|REPORT_ERRORS|STREAM_OPEN_FOR_INCLUDE TSRMLS_CC);        return php_stream_open_for_zend_ex(filename, handle, USE_PATH|REPORT_ERRORS|STREAM_OPEN_FOR_INCLUDE TSRMLS_CC);
 }  }
 /* }}} */  /* }}} */
   
Line 1219  PHPAPI int php_stream_open_for_zend_ex(const char *fil Line 1303  PHPAPI int php_stream_open_for_zend_ex(const char *fil
         php_stream *stream = php_stream_open_wrapper((char *)filename, "rb", mode, &handle->opened_path);          php_stream *stream = php_stream_open_wrapper((char *)filename, "rb", mode, &handle->opened_path);
   
         if (stream) {          if (stream) {
#if HAVE_MMAP#if HAVE_MMAP || defined(PHP_WIN32)
                 size_t page_size = REAL_PAGE_SIZE;                  size_t page_size = REAL_PAGE_SIZE;
 #endif  #endif
   
Line 1233  PHPAPI int php_stream_open_for_zend_ex(const char *fil Line 1317  PHPAPI int php_stream_open_for_zend_ex(const char *fil
                 memset(&handle->handle.stream.mmap, 0, sizeof(handle->handle.stream.mmap));                  memset(&handle->handle.stream.mmap, 0, sizeof(handle->handle.stream.mmap));
                 len = php_zend_stream_fsizer(stream TSRMLS_CC);                  len = php_zend_stream_fsizer(stream TSRMLS_CC);
                 if (len != 0                  if (len != 0
#if HAVE_MMAP#if HAVE_MMAP || defined(PHP_WIN32)
                 && ((len - 1) % page_size) <= page_size - ZEND_MMAP_AHEAD                  && ((len - 1) % page_size) <= page_size - ZEND_MMAP_AHEAD
 #endif  #endif
                 && php_stream_mmap_possible(stream)                  && php_stream_mmap_possible(stream)
Line 1278  static int php_get_configuration_directive_for_zend(co Line 1362  static int php_get_configuration_directive_for_zend(co
   
 /* {{{ php_message_handler_for_zend  /* {{{ php_message_handler_for_zend
  */   */
static void php_message_handler_for_zend(long message, void *data TSRMLS_DC)static void php_message_handler_for_zend(long message, const void *data TSRMLS_DC)
 {  {
         switch (message) {          switch (message) {
                 case ZMSG_FAILED_INCLUDE_FOPEN:                  case ZMSG_FAILED_INCLUDE_FOPEN:
Line 1372  void php_on_timeout(int seconds TSRMLS_DC) Line 1456  void php_on_timeout(int seconds TSRMLS_DC)
  */   */
 static void sigchld_handler(int apar)  static void sigchld_handler(int apar)
 {  {
           int errno_save = errno;
   
         while (waitpid(-1, NULL, WNOHANG) > 0);          while (waitpid(-1, NULL, WNOHANG) > 0);
         signal(SIGCHLD, sigchld_handler);          signal(SIGCHLD, sigchld_handler);
   
           errno = errno_save;
 }  }
 /* }}} */  /* }}} */
 #endif  #endif
Line 1415  int php_request_startup(TSRMLS_D) Line 1503  int php_request_startup(TSRMLS_D)
 {  {
         int retval = SUCCESS;          int retval = SUCCESS;
   
   #ifdef HAVE_DTRACE
           DTRACE_REQUEST_STARTUP(SAFE_FILENAME(SG(request_info).path_translated), SAFE_FILENAME(SG(request_info).request_uri), SAFE_FILENAME(SG(request_info).request_method));
   #endif /* HAVE_DTRACE */
   
 #ifdef PHP_WIN32  #ifdef PHP_WIN32
         PG(com_initialized) = 0;          PG(com_initialized) = 0;
 #endif  #endif
Line 1438  int php_request_startup(TSRMLS_D) Line 1530  int php_request_startup(TSRMLS_D)
                 zend_activate(TSRMLS_C);                  zend_activate(TSRMLS_C);
                 sapi_activate(TSRMLS_C);                  sapi_activate(TSRMLS_C);
   
   #ifdef ZEND_SIGNALS
                   zend_signal_activate(TSRMLS_C);
   #endif
   
                 if (PG(max_input_time) == -1) {                  if (PG(max_input_time) == -1) {
                         zend_set_timeout(EG(timeout_seconds), 1);                          zend_set_timeout(EG(timeout_seconds), 1);
                 } else {                  } else {
                         zend_set_timeout(PG(max_input_time), 1);                          zend_set_timeout(PG(max_input_time), 1);
                 }                  }
   
                /* Disable realpath cache if safe_mode or open_basedir are set */                /* Disable realpath cache if an open_basedir is set */
                if (PG(safe_mode) || (PG(open_basedir) && *PG(open_basedir))) {                if (PG(open_basedir) && *PG(open_basedir)) {
                         CWDG(realpath_cache_size_limit) = 0;                          CWDG(realpath_cache_size_limit) = 0;
                 }                  }
   
Line 1454  int php_request_startup(TSRMLS_D) Line 1550  int php_request_startup(TSRMLS_D)
                 }                  }
   
                 if (PG(output_handler) && PG(output_handler)[0]) {                  if (PG(output_handler) && PG(output_handler)[0]) {
                        php_start_ob_buffer_named(PG(output_handler), 0, 1 TSRMLS_CC);                        zval *oh;
 
                         MAKE_STD_ZVAL(oh);
                         ZVAL_STRING(oh, PG(output_handler), 1);
                         php_output_start_user(oh, 0, PHP_OUTPUT_HANDLER_STDFLAGS TSRMLS_CC);
                         zval_ptr_dtor(&oh);
                 } else if (PG(output_buffering)) {                  } else if (PG(output_buffering)) {
                        if (PG(output_buffering)>1) {                        php_output_start_user(NULL, PG(output_buffering) > 1 ? PG(output_buffering) : 0, PHP_OUTPUT_HANDLER_STDFLAGS TSRMLS_CC);
                                php_start_ob_buffer(NULL, PG(output_buffering), 1 TSRMLS_CC); 
                        } else { 
                                php_start_ob_buffer(NULL, 0, 1 TSRMLS_CC); 
                        } 
                 } else if (PG(implicit_flush)) {                  } else if (PG(implicit_flush)) {
                        php_start_implicit_flush(TSRMLS_C);                        php_output_set_implicit_flush(1 TSRMLS_CC);
                 }                  }
   
                 /* We turn this off in php_execute_script() */                  /* We turn this off in php_execute_script() */
Line 1498  int php_request_startup(TSRMLS_D) Line 1595  int php_request_startup(TSRMLS_D)
   
         zend_try {          zend_try {
                 PG(during_request_startup) = 1;                  PG(during_request_startup) = 1;
                 php_output_activate(TSRMLS_C);  
                 if (PG(expose_php)) {                  if (PG(expose_php)) {
                         sapi_add_header(SAPI_PHP_VERSION_HEADER, sizeof(SAPI_PHP_VERSION_HEADER)-1, 1);                          sapi_add_header(SAPI_PHP_VERSION_HEADER, sizeof(SAPI_PHP_VERSION_HEADER)-1, 1);
                 }                  }
Line 1542  void php_request_shutdown_for_exec(void *dummy) Line 1638  void php_request_shutdown_for_exec(void *dummy)
         /* used to close fd's in the 3..255 range here, but it's problematic          /* used to close fd's in the 3..255 range here, but it's problematic
          */           */
         shutdown_memory_manager(1, 1 TSRMLS_CC);          shutdown_memory_manager(1, 1 TSRMLS_CC);
           zend_interned_strings_restore(TSRMLS_C);
 }  }
 /* }}} */  /* }}} */
   
Line 1561  void php_request_shutdown_for_hook(void *dummy) Line 1658  void php_request_shutdown_for_hook(void *dummy)
         }          }
   
         zend_try {          zend_try {
                   zend_unset_timeout(TSRMLS_C);
           } zend_end_try();
   
           zend_try {
                 int i;                  int i;
   
                 for (i = 0; i < NUM_TRACK_VARS; i++) {                  for (i = 0; i < NUM_TRACK_VARS; i++) {
Line 1584  void php_request_shutdown_for_hook(void *dummy) Line 1685  void php_request_shutdown_for_hook(void *dummy)
                 shutdown_memory_manager(CG(unclean_shutdown), 0 TSRMLS_CC);                  shutdown_memory_manager(CG(unclean_shutdown), 0 TSRMLS_CC);
         } zend_end_try();          } zend_end_try();
   
           zend_interned_strings_restore(TSRMLS_C);
   
   #ifdef ZEND_SIGNALS
         zend_try {          zend_try {
                zend_unset_timeout(TSRMLS_C);                zend_signal_deactivate(TSRMLS_C);
         } zend_end_try();          } zend_end_try();
   #endif
 }  }
   
 /* }}} */  /* }}} */
Line 1621  void php_request_shutdown(void *dummy) Line 1726  void php_request_shutdown(void *dummy)
         /* 3. Flush all output buffers */          /* 3. Flush all output buffers */
         zend_try {          zend_try {
                 zend_bool send_buffer = SG(request_info).headers_only ? 0 : 1;                  zend_bool send_buffer = SG(request_info).headers_only ? 0 : 1;
   
                 if (CG(unclean_shutdown) && PG(last_error_type) == E_ERROR &&                  if (CG(unclean_shutdown) && PG(last_error_type) == E_ERROR &&
                                OG(ob_nesting_level) && !OG(active_ob_buffer).chunk_size && PG(memory_limit) < zend_memory_usage(1 TSRMLS_CC)) {                        (size_t)PG(memory_limit) < zend_memory_usage(1 TSRMLS_CC)
                 ) {
                         send_buffer = 0;                          send_buffer = 0;
                 }                  }
                php_end_ob_buffers(send_buffer TSRMLS_CC);
                 if (!send_buffer) {
                         php_output_discard_all(TSRMLS_C);
                 } else {
                         php_output_end_all(TSRMLS_C);
                 }
         } zend_end_try();          } zend_end_try();
   
        /* 4. Send the set HTTP headers (note: This must be done AFTER php_end_ob_buffers() !!) */        /* 4. Shutdown output layer (send the set HTTP headers, cleanup output handlers, etc.) */
         zend_try {          zend_try {
                sapi_send_headers(TSRMLS_C);                php_output_deactivate(TSRMLS_C);
         } zend_end_try();          } zend_end_try();
   
        /* 5. Call all extensions RSHUTDOWN functions */        /* 5. Reset max_execution_time (no longer executing php code after response sent) */
         zend_try {
                 zend_unset_timeout(TSRMLS_C);
         } zend_end_try();
 
         /* 6. Call all extensions RSHUTDOWN functions */
         if (PG(modules_activated)) {          if (PG(modules_activated)) {
                 zend_deactivate_modules(TSRMLS_C);                  zend_deactivate_modules(TSRMLS_C);
                 php_free_shutdown_functions(TSRMLS_C);                  php_free_shutdown_functions(TSRMLS_C);
         }          }
   
        /* 6. Destroy super-globals */        /* 7. Destroy super-globals */
         zend_try {          zend_try {
                 int i;                  int i;
   
Line 1650  void php_request_shutdown(void *dummy) Line 1767  void php_request_shutdown(void *dummy)
                 }                  }
         } zend_end_try();          } zend_end_try();
   
        /* 6.5 free last error information */        /* 7.5 free last error information */
         if (PG(last_error_message)) {          if (PG(last_error_message)) {
                 free(PG(last_error_message));                  free(PG(last_error_message));
                 PG(last_error_message) = NULL;                  PG(last_error_message) = NULL;
Line 1682  void php_request_shutdown(void *dummy) Line 1799  void php_request_shutdown(void *dummy)
         zend_try {          zend_try {
                 shutdown_memory_manager(CG(unclean_shutdown) || !report_memleaks, 0 TSRMLS_CC);                  shutdown_memory_manager(CG(unclean_shutdown) || !report_memleaks, 0 TSRMLS_CC);
         } zend_end_try();          } zend_end_try();
           zend_interned_strings_restore(TSRMLS_C);
   
         /* 12. Reset max_execution_time */          /* 12. Reset max_execution_time */
         zend_try {          zend_try {
Line 1694  void php_request_shutdown(void *dummy) Line 1812  void php_request_shutdown(void *dummy)
                 PG(com_initialized) = 0;                  PG(com_initialized) = 0;
         }          }
 #endif  #endif
   
   #ifdef HAVE_DTRACE
           DTRACE_REQUEST_SHUTDOWN(SAFE_FILENAME(SG(request_info).path_translated), SAFE_FILENAME(SG(request_info).request_uri), SAFE_FILENAME(SG(request_info).request_method));
   #endif /* HAVE_DTRACE */
 }  }
 /* }}} */  /* }}} */
   
Line 1711  PHPAPI void php_com_initialize(TSRMLS_D) Line 1833  PHPAPI void php_com_initialize(TSRMLS_D)
 }  }
 /* }}} */  /* }}} */
   
/* {{{ php_body_write_wrapper/* {{{ php_output_wrapper
  */   */
static int php_body_write_wrapper(const char *str, uint str_length)static int php_output_wrapper(const char *str, uint str_length)
 {  {
         TSRMLS_FETCH();          TSRMLS_FETCH();
        return php_body_write(str, str_length TSRMLS_CC);        return php_output_write(str, str_length TSRMLS_CC);
 }  }
 /* }}} */  /* }}} */
   
Line 1748  static void core_globals_dtor(php_core_globals *core_g Line 1870  static void core_globals_dtor(php_core_globals *core_g
         if (core_globals->disable_classes) {          if (core_globals->disable_classes) {
                 free(core_globals->disable_classes);                  free(core_globals->disable_classes);
         }          }
           if (core_globals->php_binary) {
                   free(core_globals->php_binary);
           }
   
         php_shutdown_ticks(TSRMLS_C);          php_shutdown_ticks(TSRMLS_C);
 }  }
Line 1779  int php_register_extensions(zend_module_entry **ptr, i Line 1904  int php_register_extensions(zend_module_entry **ptr, i
 }  }
 /* }}} */  /* }}} */
   
#if defined(PHP_WIN32) && defined(_MSC_VER) && (_MSC_VER >= 1400)#if defined(PHP_WIN32) && _MSC_VER >= 1400
 static _invalid_parameter_handler old_invalid_parameter_handler;  static _invalid_parameter_handler old_invalid_parameter_handler;
   
 void dummy_invalid_parameter_handler(  void dummy_invalid_parameter_handler(
Line 1813  void dummy_invalid_parameter_handler( Line 1938  void dummy_invalid_parameter_handler(
 }  }
 #endif  #endif
   
 #if SUHOSIN_PATCH  
 PHPAPI void suhosin_startup();  
 #endif  
   
 /* {{{ php_module_startup  /* {{{ php_module_startup
  */   */
 int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_modules, uint num_additional_modules)  int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_modules, uint num_additional_modules)
 {  {
         zend_utility_functions zuf;          zend_utility_functions zuf;
         zend_utility_values zuv;          zend_utility_values zuv;
        int module_number=0;       /* for REGISTER_INI_ENTRIES() */        int retval = SUCCESS, module_number=0;       /* for REGISTER_INI_ENTRIES() */
         char *php_os;          char *php_os;
         zend_module_entry *module;          zend_module_entry *module;
 #ifdef ZTS  #ifdef ZTS
Line 1831  int php_module_startup(sapi_module_struct *sf, zend_mo Line 1952  int php_module_startup(sapi_module_struct *sf, zend_mo
         void ***tsrm_ls;          void ***tsrm_ls;
         php_core_globals *core_globals;          php_core_globals *core_globals;
 #endif  #endif
   
 #if defined(PHP_WIN32) || (defined(NETWARE) && defined(USE_WINSOCK))  #if defined(PHP_WIN32) || (defined(NETWARE) && defined(USE_WINSOCK))
         WORD wVersionRequested = MAKEWORD(2, 0);          WORD wVersionRequested = MAKEWORD(2, 0);
         WSADATA wsaData;          WSADATA wsaData;
 #endif  #endif
 #ifdef PHP_WIN32  #ifdef PHP_WIN32
        DWORD dwVersion = GetVersion();        php_os = "WINNT";
        /* Get build numbers for Windows NT or Win95 */#if _MSC_VER >= 1400
        if (dwVersion < 0x80000000){ 
                php_os="WINNT"; 
        } else { 
                php_os="WIN32"; 
        } 
#if defined(_MSC_VER) && (_MSC_VER >= 1400) 
         old_invalid_parameter_handler =          old_invalid_parameter_handler =
                 _set_invalid_parameter_handler(dummy_invalid_parameter_handler);                  _set_invalid_parameter_handler(dummy_invalid_parameter_handler);
         if (old_invalid_parameter_handler != NULL) {          if (old_invalid_parameter_handler != NULL) {
Line 1865  int php_module_startup(sapi_module_struct *sf, zend_mo Line 1981  int php_module_startup(sapi_module_struct *sf, zend_mo
         php_win32_init_rng_lock();          php_win32_init_rng_lock();
 #endif  #endif
   
 #if SUHOSIN_PATCH  
         suhosin_startup();  
 #endif  
   
         module_shutdown = 0;          module_shutdown = 0;
         module_startup = 1;          module_startup = 1;
         sapi_initialize_empty_request(TSRMLS_C);          sapi_initialize_empty_request(TSRMLS_C);
Line 1884  int php_module_startup(sapi_module_struct *sf, zend_mo Line 1996  int php_module_startup(sapi_module_struct *sf, zend_mo
   
         zuf.error_function = php_error_cb;          zuf.error_function = php_error_cb;
         zuf.printf_function = php_printf;          zuf.printf_function = php_printf;
        zuf.write_function = php_body_write_wrapper;        zuf.write_function = php_output_wrapper;
         zuf.fopen_function = php_fopen_wrapper_for_zend;          zuf.fopen_function = php_fopen_wrapper_for_zend;
         zuf.message_handler = php_message_handler_for_zend;          zuf.message_handler = php_message_handler_for_zend;
         zuf.block_interruptions = sapi_module.block_interruptions;          zuf.block_interruptions = sapi_module.block_interruptions;
Line 1991  int php_module_startup(sapi_module_struct *sf, zend_mo Line 2103  int php_module_startup(sapi_module_struct *sf, zend_mo
         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);          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);
         REGISTER_MAIN_STRINGL_CONSTANT("PHP_SHLIB_SUFFIX", PHP_SHLIB_SUFFIX, sizeof(PHP_SHLIB_SUFFIX)-1, CONST_PERSISTENT | CONST_CS);          REGISTER_MAIN_STRINGL_CONSTANT("PHP_SHLIB_SUFFIX", PHP_SHLIB_SUFFIX, sizeof(PHP_SHLIB_SUFFIX)-1, CONST_PERSISTENT | CONST_CS);
         REGISTER_MAIN_STRINGL_CONSTANT("PHP_EOL", PHP_EOL, sizeof(PHP_EOL)-1, CONST_PERSISTENT | CONST_CS);          REGISTER_MAIN_STRINGL_CONSTANT("PHP_EOL", PHP_EOL, sizeof(PHP_EOL)-1, CONST_PERSISTENT | CONST_CS);
#if SUHOSIN_PATCH        REGISTER_MAIN_LONG_CONSTANT("PHP_MAXPATHLEN", MAXPATHLEN, CONST_PERSISTENT | CONST_CS);
        REGISTER_MAIN_LONG_CONSTANT("SUHOSIN_PATCH", 1, CONST_PERSISTENT | CONST_CS); 
        REGISTER_MAIN_STRINGL_CONSTANT("SUHOSIN_PATCH_VERSION", SUHOSIN_PATCH_VERSION, sizeof(SUHOSIN_PATCH_VERSION)-1, CONST_PERSISTENT | CONST_CS); 
#endif         
        REGISTER_MAIN_LONG_CONSTANT("PHP_MAXPATHLEN", MAXPATHLEN, CONST_PERSISTENT | CONST_CS); 
         REGISTER_MAIN_LONG_CONSTANT("PHP_INT_MAX", LONG_MAX, CONST_PERSISTENT | CONST_CS);          REGISTER_MAIN_LONG_CONSTANT("PHP_INT_MAX", LONG_MAX, CONST_PERSISTENT | CONST_CS);
         REGISTER_MAIN_LONG_CONSTANT("PHP_INT_SIZE", sizeof(long), CONST_PERSISTENT | CONST_CS);          REGISTER_MAIN_LONG_CONSTANT("PHP_INT_SIZE", sizeof(long), CONST_PERSISTENT | CONST_CS);
 #ifdef ZEND_MULTIBYTE  
         REGISTER_MAIN_LONG_CONSTANT("ZEND_MULTIBYTE", 1, CONST_PERSISTENT | CONST_CS);  
 #else  
         REGISTER_MAIN_LONG_CONSTANT("ZEND_MULTIBYTE", 0, CONST_PERSISTENT | CONST_CS);  
 #endif  
   
 #ifdef PHP_WIN32  #ifdef PHP_WIN32
         REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_VERSION_MAJOR",      EG(windows_version_info).dwMajorVersion, CONST_PERSISTENT | CONST_CS);          REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_VERSION_MAJOR",      EG(windows_version_info).dwMajorVersion, CONST_PERSISTENT | CONST_CS);
Line 2018  int php_module_startup(sapi_module_struct *sf, zend_mo Line 2121  int php_module_startup(sapi_module_struct *sf, zend_mo
         REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_NT_WORKSTATION", VER_NT_WORKSTATION, CONST_PERSISTENT | CONST_CS);          REGISTER_MAIN_LONG_CONSTANT("PHP_WINDOWS_NT_WORKSTATION", VER_NT_WORKSTATION, CONST_PERSISTENT | CONST_CS);
 #endif  #endif
   
           php_binary_init(TSRMLS_C);
           if (PG(php_binary)) {
                   REGISTER_MAIN_STRINGL_CONSTANT("PHP_BINARY", PG(php_binary), strlen(PG(php_binary)), CONST_PERSISTENT | CONST_CS);
           } else {
                   REGISTER_MAIN_STRINGL_CONSTANT("PHP_BINARY", "", 0, CONST_PERSISTENT | CONST_CS);
           }
   
         php_output_register_constants(TSRMLS_C);          php_output_register_constants(TSRMLS_C);
         php_rfc1867_register_constants(TSRMLS_C);          php_rfc1867_register_constants(TSRMLS_C);
   
Line 2034  int php_module_startup(sapi_module_struct *sf, zend_mo Line 2144  int php_module_startup(sapi_module_struct *sf, zend_mo
         /* Register Zend ini entries */          /* Register Zend ini entries */
         zend_register_standard_ini_entries(TSRMLS_C);          zend_register_standard_ini_entries(TSRMLS_C);
   
        /* Disable realpath cache if safe_mode or open_basedir are set */        /* Disable realpath cache if an open_basedir is set */
        if (PG(safe_mode) || (PG(open_basedir) && *PG(open_basedir))) {        if (PG(open_basedir) && *PG(open_basedir)) {
                 CWDG(realpath_cache_size_limit) = 0;                  CWDG(realpath_cache_size_limit) = 0;
         }          }
   
Line 2083  int php_module_startup(sapi_module_struct *sf, zend_mo Line 2193  int php_module_startup(sapi_module_struct *sf, zend_mo
         /* start Zend extensions */          /* start Zend extensions */
         zend_startup_extensions();          zend_startup_extensions();
   
           zend_collect_module_handlers(TSRMLS_C);
   
         /* register additional functions */          /* register additional functions */
         if (sapi_module.additional_functions) {          if (sapi_module.additional_functions) {
                 if (zend_hash_find(&module_registry, "standard", sizeof("standard"), (void**)&module)==SUCCESS) {                  if (zend_hash_find(&module_registry, "standard", sizeof("standard"), (void**)&module)==SUCCESS) {
Line 2105  int php_module_startup(sapi_module_struct *sf, zend_mo Line 2217  int php_module_startup(sapi_module_struct *sf, zend_mo
   
 #ifdef PHP_WIN32  #ifdef PHP_WIN32
         /* Disable incompatible functions for the running platform */          /* Disable incompatible functions for the running platform */
        if (php_win32_disable_functions() == FAILURE) {        if (php_win32_disable_functions(TSRMLS_C) == FAILURE) {
                 php_printf("Unable to disable unsupported functions\n");                  php_printf("Unable to disable unsupported functions\n");
                 return FAILURE;                  return FAILURE;
         }          }
Line 2118  int php_module_startup(sapi_module_struct *sf, zend_mo Line 2230  int php_module_startup(sapi_module_struct *sf, zend_mo
         module_initialized = 1;          module_initialized = 1;
   
         /* Check for deprecated directives */          /* Check for deprecated directives */
        /* NOTE: If you add anything here, remember to add it also in Makefile.global! */        /* NOTE: If you add anything here, remember to add it to Makefile.global! */
         {          {
                static const char *directives[] = {                struct {
                        "define_syslog_variables",                         const long error_level;
                        "register_globals",                         const char *phrase;
                        "register_long_arrays",                         const char *directives[16]; /* Remember to change this if the number of directives change */
                        "safe_mode",                 } directives[2] = {
                        "magic_quotes_gpc",                         {
                        "magic_quotes_runtime",                                 E_DEPRECATED, 
                        "magic_quotes_sybase",                                 "Directive '%s' is deprecated in PHP 5.3 and greater", 
                        NULL                                {
                                         NULL
                                 }
                         }, 
                         {
                                 E_CORE_ERROR, 
                                 "Directive '%s' is no longer available in PHP", 
                                 {
                                         "allow_call_time_pass_reference",
                                         "define_syslog_variables", 
                                         "highlight.bg", 
                                         "magic_quotes_gpc", 
                                         "magic_quotes_runtime", 
                                         "magic_quotes_sybase", 
                                         "register_globals", 
                                         "register_long_arrays", 
                                         "safe_mode", 
                                         "safe_mode_gid", 
                                         "safe_mode_include_dir", 
                                         "safe_mode_exec_dir", 
                                         "safe_mode_allowed_env_vars", 
                                         "safe_mode_protected_env_vars", 
                                         "zend.ze1_compatibility_mode", 
                                         NULL
                                 }
                         }
                 };                  };
                 const char **p = directives;  
                 long val;  
   
                while (*p) {                unsigned int i;
                        if (cfg_get_long((char*)*p, &val) == SUCCESS && val) {                
                                zend_error(E_DEPRECATED, "Directive '%s' is deprecated in PHP 5.3 and greater", *p);                zend_try {
                        }                        /* 2 = Count of deprecation structs */
                        ++p;                        for (i = 0; i < 2; i++) {
                }                                const char **p = directives[i].directives;
   
                /* This is not too nice, but since its the only one theres no need for extra stuff here */                                while(*p) {
                if (cfg_get_long("zend.ze1_compatibility_mode", &val) == SUCCESS && val) {                                        long value;
                        zend_error(E_CORE_ERROR, "zend.ze1_compatibility_mode is no longer supported in PHP 5.3 and greater");
                }                                        if (cfg_get_long((char*)*p, &value) == SUCCESS && value) {
                                                 zend_error(directives[i].error_level, directives[i].phrase, *p);
                                         }
 
                                         ++p;
                                 }
                         }
                 } zend_catch {
                         retval = FAILURE;
                 } zend_end_try();
         }          }
                   
         sapi_deactivate(TSRMLS_C);          sapi_deactivate(TSRMLS_C);
         module_startup = 0;          module_startup = 0;
   
         shutdown_memory_manager(1, 0 TSRMLS_CC);          shutdown_memory_manager(1, 0 TSRMLS_CC);
           zend_interned_strings_snapshot(TSRMLS_C);
   
         /* we're done */          /* we're done */
        return SUCCESS;        return retval;
 }  }
 /* }}} */  /* }}} */
   
Line 2212  void php_module_shutdown(TSRMLS_D) Line 2357  void php_module_shutdown(TSRMLS_D)
 #ifndef ZTS  #ifndef ZTS
         zend_ini_shutdown(TSRMLS_C);          zend_ini_shutdown(TSRMLS_C);
         shutdown_memory_manager(CG(unclean_shutdown), 1 TSRMLS_CC);          shutdown_memory_manager(CG(unclean_shutdown), 1 TSRMLS_CC);
         core_globals_dtor(&core_globals TSRMLS_CC);  
         gc_globals_dtor(TSRMLS_C);  
 #else  #else
         zend_ini_global_shutdown(TSRMLS_C);          zend_ini_global_shutdown(TSRMLS_C);
         ts_free_id(core_globals_id);  
 #endif  #endif
   
           php_output_shutdown();
         php_shutdown_temporary_directory();          php_shutdown_temporary_directory();
   
         module_initialized = 0;          module_initialized = 0;
   
   #ifndef ZTS
           core_globals_dtor(&core_globals TSRMLS_CC);
           gc_globals_dtor(TSRMLS_C);
   #else
           ts_free_id(core_globals_id);
   #endif
   
 #if defined(PHP_WIN32) && defined(_MSC_VER) && (_MSC_VER >= 1400)  #if defined(PHP_WIN32) && defined(_MSC_VER) && (_MSC_VER >= 1400)
         if (old_invalid_parameter_handler == NULL) {          if (old_invalid_parameter_handler == NULL) {
                 _set_invalid_parameter_handler(old_invalid_parameter_handler);                  _set_invalid_parameter_handler(old_invalid_parameter_handler);
Line 2272  PHPAPI int php_execute_script(zend_file_handle *primar Line 2422  PHPAPI int php_execute_script(zend_file_handle *primar
                         /* this looks nasty to me */                          /* this looks nasty to me */
                         old_cwd_fd = open(".", 0);                          old_cwd_fd = open(".", 0);
 #else  #else
                        VCWD_GETCWD(old_cwd, OLD_CWD_SIZE-1);                        php_ignore_value(VCWD_GETCWD(old_cwd, OLD_CWD_SIZE-1));
 #endif  #endif
                         VCWD_CHDIR_FILE(primary_file->filename);                          VCWD_CHDIR_FILE(primary_file->filename);
                 }                  }
Line 2331  PHPAPI int php_execute_script(zend_file_handle *primar Line 2481  PHPAPI int php_execute_script(zend_file_handle *primar
         }          }
 #else  #else
         if (old_cwd[0] != '\0') {          if (old_cwd[0] != '\0') {
                VCWD_CHDIR(old_cwd);                php_ignore_value(VCWD_CHDIR(old_cwd));
         }          }
         free_alloca(old_cwd, use_heap);          free_alloca(old_cwd, use_heap);
 #endif  #endif
Line 2361  PHPAPI int php_execute_simple_script(zend_file_handle  Line 2511  PHPAPI int php_execute_simple_script(zend_file_handle 
                 PG(during_request_startup) = 0;                  PG(during_request_startup) = 0;
   
                 if (primary_file->filename && !(SG(options) & SAPI_OPTION_NO_CHDIR)) {                  if (primary_file->filename && !(SG(options) & SAPI_OPTION_NO_CHDIR)) {
                        VCWD_GETCWD(old_cwd, OLD_CWD_SIZE-1);                        php_ignore_value(VCWD_GETCWD(old_cwd, OLD_CWD_SIZE-1));
                         VCWD_CHDIR_FILE(primary_file->filename);                          VCWD_CHDIR_FILE(primary_file->filename);
                 }                  }
                 zend_execute_scripts(ZEND_REQUIRE TSRMLS_CC, ret, 1, primary_file);                  zend_execute_scripts(ZEND_REQUIRE TSRMLS_CC, ret, 1, primary_file);
         } zend_end_try();          } zend_end_try();
   
         if (old_cwd[0] != '\0') {          if (old_cwd[0] != '\0') {
                VCWD_CHDIR(old_cwd);                php_ignore_value(VCWD_CHDIR(old_cwd));
         }          }
   
         free_alloca(old_cwd, use_heap);          free_alloca(old_cwd, use_heap);
Line 2383  PHPAPI void php_handle_aborted_connection(void) Line 2533  PHPAPI void php_handle_aborted_connection(void)
         TSRMLS_FETCH();          TSRMLS_FETCH();
   
         PG(connection_status) = PHP_CONNECTION_ABORTED;          PG(connection_status) = PHP_CONNECTION_ABORTED;
        php_output_set_status(0 TSRMLS_CC);        php_output_set_status(PHP_OUTPUT_DISABLED TSRMLS_CC);
   
         if (!PG(ignore_user_abort)) {          if (!PG(ignore_user_abort)) {
                 zend_bailout();                  zend_bailout();

Removed from v.1.1.1.1  
changed lines
  Added in v.1.1.1.2


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>