diff options
author | foobar <sniper@php.net> | 2002-05-09 20:03:36 +0000 |
---|---|---|
committer | foobar <sniper@php.net> | 2002-05-09 20:03:36 +0000 |
commit | 42c82bb40dbfa8f1e219a5ffd7e1ebf96150c9d0 (patch) | |
tree | 27f36d139dfa45020d9add633fa1c7a11701f50b | |
parent | 375d7960a789e233ea56e8a6e3f750291a7cdc1e (diff) | |
download | php-git-42c82bb40dbfa8f1e219a5ffd7e1ebf96150c9d0.tar.gz |
Revert the last patches.
-rw-r--r-- | main/php_ini.c | 466 | ||||
-rw-r--r-- | main/php_open_temporary_file.c | 189 | ||||
-rw-r--r-- | sapi/cgi/cgi_main.c | 1470 |
3 files changed, 1046 insertions, 1079 deletions
diff --git a/main/php_ini.c b/main/php_ini.c index aaad0942c9..623d21d8b4 100644 --- a/main/php_ini.c +++ b/main/php_ini.c @@ -32,8 +32,8 @@ #include "php_main.h" typedef struct _php_extension_lists { - zend_llist engine; - zend_llist functions; + zend_llist engine; + zend_llist functions; } php_extension_lists; @@ -46,36 +46,36 @@ static php_extension_lists extension_lists; */ static void php_ini_displayer_cb(zend_ini_entry *ini_entry, int type) { - if (ini_entry->displayer) { - ini_entry->displayer(ini_entry, type); - } else { - char *display_string; - uint display_string_length, esc_html=0; - TSRMLS_FETCH(); - - if (type==ZEND_INI_DISPLAY_ORIG && ini_entry->modified) { - if (ini_entry->orig_value && ini_entry->orig_value[0]) { - display_string = ini_entry->orig_value; - display_string_length = ini_entry->orig_value_length; - esc_html=1; - } else { - display_string = "<i>no value</i>"; - display_string_length = sizeof("<i>no value</i>")-1; - } - } else if (ini_entry->value && ini_entry->value[0]) { - display_string = ini_entry->value; - display_string_length = ini_entry->value_length; - esc_html=1; - } else { - display_string = "<i>no value</i>"; - display_string_length = sizeof("<i>no value</i>")-1; - } - if(esc_html) { - php_html_puts(display_string, display_string_length TSRMLS_CC); - } else { - PHPWRITE(display_string, display_string_length); - } - } + if (ini_entry->displayer) { + ini_entry->displayer(ini_entry, type); + } else { + char *display_string; + uint display_string_length, esc_html=0; + TSRMLS_FETCH(); + + if (type==ZEND_INI_DISPLAY_ORIG && ini_entry->modified) { + if (ini_entry->orig_value && ini_entry->orig_value[0]) { + display_string = ini_entry->orig_value; + display_string_length = ini_entry->orig_value_length; + esc_html=1; + } else { + display_string = "<i>no value</i>"; + display_string_length = sizeof("<i>no value</i>")-1; + } + } else if (ini_entry->value && ini_entry->value[0]) { + display_string = ini_entry->value; + display_string_length = ini_entry->value_length; + esc_html=1; + } else { + display_string = "<i>no value</i>"; + display_string_length = sizeof("<i>no value</i>")-1; + } + if(esc_html) { + php_html_puts(display_string, display_string_length TSRMLS_CC); + } else { + PHPWRITE(display_string, display_string_length); + } + } } /* }}} */ @@ -83,19 +83,19 @@ static void php_ini_displayer_cb(zend_ini_entry *ini_entry, int type) */ static int php_ini_displayer(zend_ini_entry *ini_entry, int module_number TSRMLS_DC) { - if (ini_entry->module_number != module_number) { - return 0; - } - - PUTS("<tr valign=\"baseline\" bgcolor=\"" PHP_CONTENTS_COLOR "\">"); - PUTS("<td bgcolor=\"" PHP_ENTRY_NAME_COLOR "\"><b>"); - PHPWRITE(ini_entry->name, ini_entry->name_length-1); - PUTS("</b><br /></td><td align=\"center\">"); - php_ini_displayer_cb(ini_entry, ZEND_INI_DISPLAY_ACTIVE); - PUTS("</td><td align=\"center\">"); - php_ini_displayer_cb(ini_entry, ZEND_INI_DISPLAY_ORIG); - PUTS("</td></tr>\n"); - return 0; + if (ini_entry->module_number != module_number) { + return 0; + } + + PUTS("<tr valign=\"baseline\" bgcolor=\"" PHP_CONTENTS_COLOR "\">"); + PUTS("<td bgcolor=\"" PHP_ENTRY_NAME_COLOR "\"><b>"); + PHPWRITE(ini_entry->name, ini_entry->name_length-1); + PUTS("</b><br /></td><td align=\"center\">"); + php_ini_displayer_cb(ini_entry, ZEND_INI_DISPLAY_ACTIVE); + PUTS("</td><td align=\"center\">"); + php_ini_displayer_cb(ini_entry, ZEND_INI_DISPLAY_ORIG); + PUTS("</td></tr>\n"); + return 0; } /* }}} */ @@ -103,18 +103,18 @@ static int php_ini_displayer(zend_ini_entry *ini_entry, int module_number TSRMLS */ PHPAPI void display_ini_entries(zend_module_entry *module) { - int module_number; - TSRMLS_FETCH(); - - if (module) { - module_number = module->module_number; - } else { - module_number = 0; - } - php_info_print_table_start(); - php_info_print_table_header(3, "Directive", "Local Value", "Master Value"); - zend_hash_apply_with_argument(&EG(ini_directives), (apply_func_arg_t) php_ini_displayer, (void *) (long) module_number TSRMLS_CC); - php_info_print_table_end(); + int module_number; + TSRMLS_FETCH(); + + if (module) { + module_number = module->module_number; + } else { + module_number = 0; + } + php_info_print_table_start(); + php_info_print_table_header(3, "Directive", "Local Value", "Master Value"); + zend_hash_apply_with_argument(&EG(ini_directives), (apply_func_arg_t) php_ini_displayer, (void *) (long) module_number TSRMLS_CC); + php_info_print_table_end(); } /* }}} */ @@ -122,22 +122,22 @@ PHPAPI void display_ini_entries(zend_module_entry *module) #ifdef ZTS # if (ZEND_DEBUG) -# define ZEND_EXTENSION_TOKEN "zend_extension_debug_ts" +# define ZEND_EXTENSION_TOKEN "zend_extension_debug_ts" # else -# define ZEND_EXTENSION_TOKEN "zend_extension_ts" +# define ZEND_EXTENSION_TOKEN "zend_extension_ts" # endif #else # if (ZEND_DEBUG) -# define ZEND_EXTENSION_TOKEN "zend_extension_debug" +# define ZEND_EXTENSION_TOKEN "zend_extension_debug" # else -# define ZEND_EXTENSION_TOKEN "zend_extension" +# define ZEND_EXTENSION_TOKEN "zend_extension" # endif #endif /* {{{ pvalue_config_destructor */ static void pvalue_config_destructor(zval *pvalue) -{ +{ if (Z_TYPE_P(pvalue) == IS_STRING && Z_STRVAL_P(pvalue) != empty_string) { free(Z_STRVAL_P(pvalue)); } @@ -148,33 +148,33 @@ static void pvalue_config_destructor(zval *pvalue) */ static void php_config_ini_parser_cb(zval *arg1, zval *arg2, int callback_type, void *arg) { - switch (callback_type) { - case ZEND_INI_PARSER_ENTRY: { - zval *entry; - - if (!arg2) { - break; - } - if (!strcasecmp(Z_STRVAL_P(arg1), "extension")) { /* load function module */ - zval copy; - - copy = *arg2; - zval_copy_ctor(©); - copy.refcount = 0; - zend_llist_add_element(&extension_lists.functions, ©); - } else if (!strcasecmp(Z_STRVAL_P(arg1), ZEND_EXTENSION_TOKEN)) { /* load Zend extension */ - char *extension_name = estrndup(Z_STRVAL_P(arg2), Z_STRLEN_P(arg2)); - - zend_llist_add_element(&extension_lists.engine, &extension_name); - } else { - zend_hash_update(&configuration_hash, Z_STRVAL_P(arg1), Z_STRLEN_P(arg1)+1, arg2, sizeof(zval), (void **) &entry); - Z_STRVAL_P(entry) = zend_strndup(Z_STRVAL_P(entry), Z_STRLEN_P(entry)); - } - } - break; - case ZEND_INI_PARSER_SECTION: - break; - } + switch (callback_type) { + case ZEND_INI_PARSER_ENTRY: { + zval *entry; + + if (!arg2) { + break; + } + if (!strcasecmp(Z_STRVAL_P(arg1), "extension")) { /* load function module */ + zval copy; + + copy = *arg2; + zval_copy_ctor(©); + copy.refcount = 0; + zend_llist_add_element(&extension_lists.functions, ©); + } else if (!strcasecmp(Z_STRVAL_P(arg1), ZEND_EXTENSION_TOKEN)) { /* load Zend extension */ + char *extension_name = estrndup(Z_STRVAL_P(arg2), Z_STRLEN_P(arg2)); + + zend_llist_add_element(&extension_lists.engine, &extension_name); + } else { + zend_hash_update(&configuration_hash, Z_STRVAL_P(arg1), Z_STRLEN_P(arg1)+1, arg2, sizeof(zval), (void **) &entry); + Z_STRVAL_P(entry) = zend_strndup(Z_STRVAL_P(entry), Z_STRLEN_P(entry)); + } + } + break; + case ZEND_INI_PARSER_SECTION: + break; + } } /* }}} */ @@ -182,10 +182,10 @@ static void php_config_ini_parser_cb(zval *arg1, zval *arg2, int callback_type, */ static void php_load_function_extension_cb(void *arg TSRMLS_DC) { - zval *extension = (zval *) arg; - zval zval; + zval *extension = (zval *) arg; + zval zval; - php_dl(extension, MODULE_PERSISTENT, &zval TSRMLS_CC); + php_dl(extension, MODULE_PERSISTENT, &zval TSRMLS_CC); } /* }}} */ @@ -193,7 +193,7 @@ static void php_load_function_extension_cb(void *arg TSRMLS_DC) */ static void php_load_zend_extension_cb(void *arg TSRMLS_DC) { - zend_load_extension(*((char **) arg)); + zend_load_extension(*((char **) arg)); } /* }}} */ @@ -201,103 +201,107 @@ static void php_load_zend_extension_cb(void *arg TSRMLS_DC) */ int php_init_config(char *php_ini_path_override) { - int safe_mode_state; - char *open_basedir; - zend_file_handle fh; - TSRMLS_FETCH(); - - if (zend_hash_init(&configuration_hash, 0, NULL, (dtor_func_t) pvalue_config_destructor, 1)==FAILURE) { - return FAILURE; - } - - zend_llist_init(&extension_lists.engine, sizeof(char *), (llist_dtor_func_t) free_estring, 1); - zend_llist_init(&extension_lists.functions, sizeof(zval), (llist_dtor_func_t) ZVAL_DESTRUCTOR, 1); - - safe_mode_state = PG(safe_mode); - open_basedir = PG(open_basedir); - PG(safe_mode) = 0; - PG(open_basedir) = NULL; - - fh.handle.fp = NULL; - - /* If no override given (usually from the command line) then check the environment. */ - if (!php_ini_path_override) { - php_ini_path_override = getenv("PHPRC"); - } - if (php_ini_path_override && *php_ini_path_override) { - - /* Try to open php_ini_path_override if not a directory. */ - struct stat st; - if ((0 == VCWD_STAT(php_ini_path_override, &st)) && (S_IFDIR != (st.st_mode & S_IFMT))) { - fh.handle.fp = VCWD_FOPEN(php_ini_path_override, "r"); - if (fh.handle.fp) { - php_ini_opened_path = estrdup(php_ini_path_override); - } - } - - /* If we did not manage to open php_ini_path_override then search it as a directory. */ - if (!fh.handle.fp) { - fh.handle.fp = php_fopen_with_path("php.ini", "r", php_ini_path_override, &php_ini_opened_path TSRMLS_CC); - } - - } - -#define INI_CHECK_CWD -#ifdef INI_CHECK_CWD - if (!fh.handle.fp && (0 != strcmp(sapi_module.name, "cli"))) { - /* Search the current directory - possible security risk? */ - fh.handle.fp = php_fopen_with_path("php.ini", "r", ".", &php_ini_opened_path TSRMLS_CC); - } -#endif + char *env_location, *php_ini_search_path; + int safe_mode_state; + char *open_basedir; + int free_ini_search_path=0; + zend_file_handle fh; + TSRMLS_FETCH(); + + if (zend_hash_init(&configuration_hash, 0, NULL, (dtor_func_t) pvalue_config_destructor, 1)==FAILURE) { + return FAILURE; + } + + zend_llist_init(&extension_lists.engine, sizeof(char *), (llist_dtor_func_t) free_estring, 1); + zend_llist_init(&extension_lists.functions, sizeof(zval), (llist_dtor_func_t) ZVAL_DESTRUCTOR, 1); + + safe_mode_state = PG(safe_mode); + open_basedir = PG(open_basedir); + + env_location = getenv("PHPRC"); + if (!env_location) { + env_location=""; + } + if (php_ini_path_override) { + php_ini_search_path = php_ini_path_override; + free_ini_search_path = 0; + } else { + char *default_location; + int free_default_location; #ifdef PHP_WIN32 - if (!fh.handle.fp) { - /* Search for php.ini in the same directory as the executable. */ - char search_path[MAX_PATH]; - if (GetModuleFileName(0,search_path,sizeof(search_path))) { - char* p = strrchr(search_path,'\\'); - if (p) *++p = 0; - fh.handle.fp = php_fopen_with_path("php.ini", "r", search_path, &php_ini_opened_path TSRMLS_CC); - } - } - if (!fh.handle.fp) { - /* Search for php.ini in the Windows base directory. */ - char search_path[MAX_PATH]; - if (GetWindowsDirectory(search_path,sizeof(search_path))) { - fh.handle.fp = php_fopen_with_path("php.ini", "r", search_path, &php_ini_opened_path TSRMLS_CC); - } - } + default_location = (char *) emalloc(512); + + if (!GetWindowsDirectory(default_location, 255)) { + default_location[0]=0; + } + free_default_location=1; #else - if (!fh.handle.fp) { - /* Search for php.ini in the (platform-specific) default places. */ - fh.handle.fp = php_fopen_with_path("php.ini", "r", PHP_CONFIG_FILE_PATH, &php_ini_opened_path TSRMLS_CC); - } + default_location = PHP_CONFIG_FILE_PATH; + free_default_location=0; #endif - - PG(safe_mode) = safe_mode_state; - PG(open_basedir) = open_basedir; - - if (!fh.handle.fp) { - return SUCCESS; /* having no configuration file is ok */ - } - fh.type = ZEND_HANDLE_FP; - fh.filename = php_ini_opened_path; - - zend_parse_ini_file(&fh, 1, php_config_ini_parser_cb, &extension_lists); - - /* If we succeeded in opening an INI file, preserve the name of the file opened. */ - if (php_ini_opened_path) { - zval tmp; - - Z_STRLEN(tmp) = strlen(php_ini_opened_path); - Z_STRVAL(tmp) = zend_strndup(php_ini_opened_path, Z_STRLEN(tmp)); - Z_TYPE(tmp) = IS_STRING; - zend_hash_update(&configuration_hash, "cfg_file_path", sizeof("cfg_file_path"), (void *) &tmp, sizeof(zval), NULL); - efree(php_ini_opened_path); - php_ini_opened_path = zend_strndup(Z_STRVAL(tmp), Z_STRLEN(tmp)); - } - - return SUCCESS; + php_ini_search_path = (char *) emalloc(sizeof(".")+strlen(env_location)+strlen(default_location)+2+1); + free_ini_search_path = 1; + if (strcmp(sapi_module.name, "cli")==0) { + if(env_location && env_location[0]) { + sprintf(php_ini_search_path, "%s%c%s", env_location, ZEND_PATHS_SEPARATOR, default_location); + } else { + sprintf(php_ini_search_path, "%s", default_location); + } + } else { + if(env_location && env_location[0]) { + sprintf(php_ini_search_path, ".%c%s%c%s", ZEND_PATHS_SEPARATOR, env_location, ZEND_PATHS_SEPARATOR, default_location); + } else { + sprintf(php_ini_search_path, ".%c%s", ZEND_PATHS_SEPARATOR, default_location); + } + } + if (free_default_location) { + efree(default_location); + } + } + + PG(safe_mode) = 0; + PG(open_basedir) = NULL; + + fh.handle.fp = NULL; + /* Check if php_ini_path_override is a file */ + if (php_ini_path_override && php_ini_path_override[0]) { + struct stat statbuf; + if (!VCWD_STAT(php_ini_path_override, &statbuf)) { + if (!((statbuf.st_mode & S_IFMT) == S_IFDIR)) { + fh.handle.fp = VCWD_FOPEN(php_ini_path_override, "r"); + } + } + } + /* Search php.ini file in search path */ + if (!fh.handle.fp) + fh.handle.fp = php_fopen_with_path("php.ini", "r", php_ini_search_path, &php_ini_opened_path TSRMLS_CC); + if (free_ini_search_path) { + efree(php_ini_search_path); + } + PG(safe_mode) = safe_mode_state; + PG(open_basedir) = open_basedir; + + if (!fh.handle.fp) { + return SUCCESS; /* having no configuration file is ok */ + } + fh.type = ZEND_HANDLE_FP; + fh.filename = php_ini_opened_path; + + zend_parse_ini_file(&fh, 1, php_config_ini_parser_cb, &extension_lists); + + if (php_ini_opened_path) { + zval tmp; + + Z_STRLEN(tmp) = strlen(php_ini_opened_path); + Z_STRVAL(tmp) = zend_strndup(php_ini_opened_path, Z_STRLEN(tmp)); + Z_TYPE(tmp) = IS_STRING; + zend_hash_update(&configuration_hash, "cfg_file_path", sizeof("cfg_file_path"), (void *) &tmp, sizeof(zval), NULL); + efree(php_ini_opened_path); + php_ini_opened_path = zend_strndup(Z_STRVAL(tmp), Z_STRLEN(tmp)); + } + + return SUCCESS; } /* }}} */ @@ -305,11 +309,11 @@ int php_init_config(char *php_ini_path_override) */ int php_shutdown_config(void) { - zend_hash_destroy(&configuration_hash); - if (php_ini_opened_path) { - free(php_ini_opened_path); - } - return SUCCESS; + zend_hash_destroy(&configuration_hash); + if (php_ini_opened_path) { + free(php_ini_opened_path); + } + return SUCCESS; } /* }}} */ @@ -317,11 +321,11 @@ int php_shutdown_config(void) */ void php_ini_delayed_modules_startup(TSRMLS_D) { - zend_llist_apply(&extension_lists.engine, php_load_zend_extension_cb TSRMLS_CC); - zend_llist_apply(&extension_lists.functions, php_load_function_extension_cb TSRMLS_CC); + zend_llist_apply(&extension_lists.engine, php_load_zend_extension_cb TSRMLS_CC); + zend_llist_apply(&extension_lists.functions, php_load_function_extension_cb TSRMLS_CC); - zend_llist_destroy(&extension_lists.engine); - zend_llist_destroy(&extension_lists.functions); + zend_llist_destroy(&extension_lists.engine); + zend_llist_destroy(&extension_lists.functions); } /* }}} */ @@ -329,13 +333,13 @@ void php_ini_delayed_modules_startup(TSRMLS_D) */ zval *cfg_get_entry(char *name, uint name_length) { - zval *tmp; + zval *tmp; - if (zend_hash_find(&configuration_hash, name, name_length, (void **) &tmp)==SUCCESS) { - return tmp; - } else { - return NULL; - } + if (zend_hash_find(&configuration_hash, name, name_length, (void **) &tmp)==SUCCESS) { + return tmp; + } else { + return NULL; + } } /* }}} */ @@ -343,17 +347,17 @@ zval *cfg_get_entry(char *name, uint name_length) */ PHPAPI int cfg_get_long(char *varname, long *result) { - zval *tmp, var; - - if (zend_hash_find(&configuration_hash, varname, strlen(varname)+1, (void **) &tmp)==FAILURE) { - *result=(long)NULL; - return FAILURE; - } - var = *tmp; - zval_copy_ctor(&var); - convert_to_long(&var); - *result = Z_LVAL(var); - return SUCCESS; + zval *tmp, var; + + if (zend_hash_find(&configuration_hash, varname, strlen(varname)+1, (void **) &tmp)==FAILURE) { + *result=(long)NULL; + return FAILURE; + } + var = *tmp; + zval_copy_ctor(&var); + convert_to_long(&var); + *result = Z_LVAL(var); + return SUCCESS; } /* }}} */ @@ -361,17 +365,17 @@ PHPAPI int cfg_get_long(char *varname, long *result) */ PHPAPI int cfg_get_double(char *varname, double *result) { - zval *tmp, var; - - if (zend_hash_find(&configuration_hash, varname, strlen(varname)+1, (void **) &tmp)==FAILURE) { - *result=(double)0; - return FAILURE; - } - var = *tmp; - zval_copy_ctor(&var); - convert_to_double(&var); - *result = Z_DVAL(var); - return SUCCESS; + zval *tmp, var; + + if (zend_hash_find(&configuration_hash, varname, strlen(varname)+1, (void **) &tmp)==FAILURE) { + *result=(double)0; + return FAILURE; + } + var = *tmp; + zval_copy_ctor(&var); + convert_to_double(&var); + *result = Z_DVAL(var); + return SUCCESS; } /* }}} */ @@ -379,14 +383,14 @@ PHPAPI int cfg_get_double(char *varname, double *result) */ PHPAPI int cfg_get_string(char *varname, char **result) { - zval *tmp; - - if (zend_hash_find(&configuration_hash, varname, strlen(varname)+1, (void **) &tmp)==FAILURE) { - *result=NULL; - return FAILURE; - } - *result = Z_STRVAL_P(tmp); - return SUCCESS; + zval *tmp; + + if (zend_hash_find(&configuration_hash, varname, strlen(varname)+1, (void **) &tmp)==FAILURE) { + *result=NULL; + return FAILURE; + } + *result = Z_STRVAL_P(tmp); + return SUCCESS; } /* }}} */ diff --git a/main/php_open_temporary_file.c b/main/php_open_temporary_file.c index 945d2e6019..258e920a4f 100644 --- a/main/php_open_temporary_file.c +++ b/main/php_open_temporary_file.c @@ -87,108 +87,60 @@ * SUCH DAMAGE. */ -static FILE *php_do_open_temporary_file(const char *path, const char *pfx, char **opened_path_p TSRMLS_DC) +static FILE *php_do_open_temporary_file(char *path, const char *pfx, char **opened_path_p TSRMLS_DC) { - char *trailing_slash; - FILE *fp; - char *opened_path; + char *trailing_slash; + FILE *fp; + char *opened_path; #ifndef PHP_WIN32 - int fd; + int fd; #endif - if (!path) { - return NULL; - } + if (!path) { + return NULL; + } - if (!(opened_path = emalloc(MAXPATHLEN))) { - return NULL; - } + if (!(opened_path = emalloc(MAXPATHLEN))) { + return NULL; + } - if (path[strlen(path)-1] == '/') { - trailing_slash = ""; - } else { - trailing_slash = "/"; - } + if (path[strlen(path)-1] == '/') { + trailing_slash = ""; + } else { + trailing_slash = "/"; + } - (void)snprintf(opened_path, MAXPATHLEN, "%s%s%sXXXXXX", path, trailing_slash, pfx); + (void)snprintf(opened_path, MAXPATHLEN, "%s%s%sXXXXXX", path, trailing_slash, pfx); #ifdef PHP_WIN32 - if (GetTempFileName(path, pfx, 0, opened_path)) { - fp = VCWD_FOPEN(opened_path, "wb"); - } else { - fp = NULL; - } + if (GetTempFileName(path, pfx, 0, opened_path)) { + fp = VCWD_FOPEN(opened_path, "wb"); + } else { + fp = NULL; + } #elif defined(HAVE_MKSTEMP) - fd = mkstemp(opened_path); - if (fd==-1) { - fp = NULL; - } else { - fp = fdopen(fd, "wb"); - } + fd = mkstemp(opened_path); + if (fd==-1) { + fp = NULL; + } else { + fp = fdopen(fd, "wb"); + } #else - if (mktemp(opened_path)) { - fp = VCWD_FOPEN(opened_path, "wb"); - } else { - fp = NULL; - } + if (mktemp(opened_path)) { + fp = VCWD_FOPEN(opened_path, "wb"); + } else { + fp = NULL; + } #endif - if (!fp || !opened_path_p) { - efree(opened_path); - } else { - *opened_path_p = opened_path; - } - return fp; + if (!fp || !opened_path_p) { + efree(opened_path); + } else { + *opened_path_p = opened_path; + } + return fp; } /* }}} */ -/* - * Determine where to place temporary files. - */ -const char* get_temporary_directory() -{ - /* Cache the chosen temporary directory. */ - static char* temporary_directory; - - /* Did we determine the temporary directory already? */ - if (temporary_directory) { - return temporary_directory; - } - -#ifdef PHP_WIN32 - /* We can't count on the environment variables TEMP or TMP, - * and so must make the Win32 API call to get the default - * directory for temporary files. Note this call checks - * the environment values TMP and TEMP (in order) first. - */ - { - char sTemp[MAX_PATH]; - DWORD n = GetTempPath(sizeof(sTemp),sTemp); - assert(0 < n); /* should *never* fail! */ - temporary_directory = strdup(sTemp); - return temporary_directory; - } -#else - /* On Unix use the (usual) TMPDIR environment variable. */ - { - char* s = getenv("TMPDIR"); - if (s) { - temporary_directory = strdup(s); - return temporary_directory; - } - } -#ifdef P_tmpdir - /* Use the standard default temporary directory. */ - if (P_tmpdir) { - temporary_directory = P_tmpdir; - return temporary_directory; - } -#endif - /* Shouldn't ever(!) end up here ... last ditch default. */ - temporary_directory = "/tmp"; - return temporary_directory; -#endif -} - /* {{{ php_open_temporary_file * * Unlike tempnam(), the supplied dir argument takes precedence @@ -198,28 +150,47 @@ const char* get_temporary_directory() */ PHPAPI FILE *php_open_temporary_file(const char *dir, const char *pfx, char **opened_path_p TSRMLS_DC) { - FILE* fp = 0; - - if (!pfx) { - pfx = "tmp."; - } - if (opened_path_p) { - *opened_path_p = NULL; - } - - /* Try the directory given as parameter. */ - fp = php_do_open_temporary_file(dir, pfx, opened_path_p TSRMLS_CC); - if (fp) { - return fp; - } - - /* Use default temporary directory. */ - fp = php_do_open_temporary_file(get_temporary_directory(), pfx, opened_path_p TSRMLS_CC); - if (fp) { - return fp; - } - - return 0; + static char path_tmp[] = "/tmp"; + FILE *fp; + + + if (!pfx) { + pfx = "tmp."; + } + + if (opened_path_p) { + *opened_path_p = NULL; + } + + if ((fp=php_do_open_temporary_file((char *) dir, pfx, opened_path_p TSRMLS_CC))) { + return fp; + } + + if ((fp=php_do_open_temporary_file(getenv("TMPDIR"), pfx, opened_path_p TSRMLS_CC))) { + return fp; + } +#if PHP_WIN32 + { + char *TempPath; + + TempPath = (char *) emalloc(MAXPATHLEN); + if (GetTempPath(MAXPATHLEN, TempPath)) { + fp = php_do_open_temporary_file(TempPath, pfx, opened_path_p TSRMLS_CC); + } + efree(TempPath); + return fp; + } +#else + if ((fp=php_do_open_temporary_file(P_tmpdir, pfx, opened_path_p TSRMLS_CC))) { + return fp; + } + + if ((fp=php_do_open_temporary_file(path_tmp, pfx, opened_path_p TSRMLS_CC))) { + return fp; + } +#endif + + return NULL; } /* }}} */ diff --git a/sapi/cgi/cgi_main.c b/sapi/cgi/cgi_main.c index 140be613fa..d044c95dd1 100644 --- a/sapi/cgi/cgi_main.c +++ b/sapi/cgi/cgi_main.c @@ -116,11 +116,11 @@ static pid_t pgroup; #endif -#define PHP_MODE_STANDARD 1 -#define PHP_MODE_HIGHLIGHT 2 -#define PHP_MODE_INDENT 3 -#define PHP_MODE_LINT 4 -#define PHP_MODE_STRIP 5 +#define PHP_MODE_STANDARD 1 +#define PHP_MODE_HIGHLIGHT 2 +#define PHP_MODE_INDENT 3 +#define PHP_MODE_LINT 4 +#define PHP_MODE_STRIP 5 extern char *ap_php_optarg; extern int ap_php_optind; @@ -129,14 +129,14 @@ extern int ap_php_optind; static int _print_module_info(zend_module_entry *module, void *arg TSRMLS_DC) { - php_printf("%s\n", module->name); - return 0; + php_printf("%s\n", module->name); + return 0; } static int _print_extension_info(zend_extension *module, void *arg TSRMLS_DC) { - php_printf("%s\n", module->name); - return 0; + php_printf("%s\n", module->name); + return 0; } #ifndef STDOUT_FILENO @@ -146,170 +146,170 @@ static int _print_extension_info(zend_extension *module, void *arg TSRMLS_DC) static inline size_t sapi_cgibin_single_write(const char *str, uint str_length) { #ifdef PHP_WRITE_STDOUT - long ret; + long ret; #else - size_t ret; + size_t ret; #endif #ifdef PHP_FASTCGI - if (!FCGX_IsCGI()) { - return FCGX_PutStr( str, str_length, out ); - } + if (!FCGX_IsCGI()) { + return FCGX_PutStr( str, str_length, out ); + } #endif #ifdef PHP_WRITE_STDOUT - ret = write(STDOUT_FILENO, str, str_length); - if (ret <= 0) return 0; - return ret; + ret = write(STDOUT_FILENO, str, str_length); + if (ret <= 0) return 0; + return ret; #else - ret = fwrite(str, 1, MIN(str_length, 16384), stdout); - return ret; + ret = fwrite(str, 1, MIN(str_length, 16384), stdout); + return ret; #endif } static int sapi_cgibin_ub_write(const char *str, uint str_length TSRMLS_DC) { - const char *ptr = str; - uint remaining = str_length; - size_t ret; - - while (remaining > 0) - { - ret = sapi_cgibin_single_write(ptr, remaining); - if (!ret) { - php_handle_aborted_connection(); - } - ptr += ret; - remaining -= ret; - } - - return str_length; + const char *ptr = str; + uint remaining = str_length; + size_t ret; + + while (remaining > 0) + { + ret = sapi_cgibin_single_write(ptr, remaining); + if (!ret) { + php_handle_aborted_connection(); + } + ptr += ret; + remaining -= ret; + } + + return str_length; } static void sapi_cgibin_flush(void *server_context) { #ifdef PHP_FASTCGI - if (!FCGX_IsCGI()) { - if( FCGX_FFlush( out ) == -1 ) { - php_handle_aborted_connection(); - } - } else + if (!FCGX_IsCGI()) { + if( FCGX_FFlush( out ) == -1 ) { + php_handle_aborted_connection(); + } + } else #endif - if (fflush(stdout)==EOF) { - php_handle_aborted_connection(); - } + if (fflush(stdout)==EOF) { + php_handle_aborted_connection(); + } } static void sapi_cgi_send_header(sapi_header_struct *sapi_header, void *server_context TSRMLS_DC) { - if (sapi_header) { - PHPWRITE_H(sapi_header->header, sapi_header->header_len); - } - PHPWRITE_H("\r\n", 2); + if (sapi_header) { + PHPWRITE_H(sapi_header->header, sapi_header->header_len); + } + PHPWRITE_H("\r\n", 2); } static int sapi_cgi_read_post(char *buffer, uint count_bytes TSRMLS_DC) { - uint read_bytes=0, tmp_read_bytes; + uint read_bytes=0, tmp_read_bytes; #ifdef PHP_FASTCGI - char *pos = buffer; + char *pos = buffer; #endif - count_bytes = MIN(count_bytes, (uint)SG(request_info).content_length-SG(read_post_bytes)); - while (read_bytes < count_bytes) { + count_bytes = MIN(count_bytes, (uint)SG(request_info).content_length-SG(read_post_bytes)); + while (read_bytes < count_bytes) { #ifdef PHP_FASTCGI - if (!FCGX_IsCGI()) { - tmp_read_bytes = FCGX_GetStr( pos, count_bytes-read_bytes, in ); - pos += tmp_read_bytes; - } else + if (!FCGX_IsCGI()) { + tmp_read_bytes = FCGX_GetStr( pos, count_bytes-read_bytes, in ); + pos += tmp_read_bytes; + } else #endif - tmp_read_bytes = read(0, buffer+read_bytes, count_bytes-read_bytes); - - if (tmp_read_bytes<=0) { - break; - } - read_bytes += tmp_read_bytes; - } - return read_bytes; + tmp_read_bytes = read(0, buffer+read_bytes, count_bytes-read_bytes); + + if (tmp_read_bytes<=0) { + break; + } + read_bytes += tmp_read_bytes; + } + return read_bytes; } static char *sapi_cgi_read_cookies(TSRMLS_D) { - return getenv("HTTP_COOKIE"); + return getenv("HTTP_COOKIE"); } static void sapi_cgi_register_variables(zval *track_vars_array TSRMLS_DC) { - /* In CGI mode, we consider the environment to be a part of the server - * variables - */ - php_import_environment_variables(track_vars_array TSRMLS_CC); + /* In CGI mode, we consider the environment to be a part of the server + * variables + */ + php_import_environment_variables(track_vars_array TSRMLS_CC); - /* Build the special-case PHP_SELF variable for the CGI version */ - php_register_variable("PHP_SELF", (SG(request_info).request_uri ? SG(request_info).request_uri:""), track_vars_array TSRMLS_CC); + /* Build the special-case PHP_SELF variable for the CGI version */ + php_register_variable("PHP_SELF", (SG(request_info).request_uri ? SG(request_info).request_uri:""), track_vars_array TSRMLS_CC); } static void sapi_cgi_log_message(char *message) { - if (php_header()) { - fprintf(stderr, "%s", message); - fprintf(stderr, "\n"); - } + if (php_header()) { + fprintf(stderr, "%s", message); + fprintf(stderr, "\n"); + } } static int sapi_cgi_deactivate(TSRMLS_D) { - fflush(stdout); - if(SG(request_info).argv0) { - free(SG(request_info).argv0); - SG(request_info).argv0 = NULL; - } - return SUCCESS; + fflush(stdout); + if(SG(request_info).argv0) { + free(SG(request_info).argv0); + SG(request_info).argv0 = NULL; + } + return SUCCESS; } /* {{{ sapi_module_struct cgi_sapi_module */ static sapi_module_struct cgi_sapi_module = { - "cgi", /* name */ + "cgi", /* name */ #ifdef PHP_FASTCGI - "CGI/FastCGI", /* pretty name */ + "CGI/FastCGI", /* pretty name */ #else - "CGI", /* pretty name */ + "CGI", /* pretty name */ #endif + + php_module_startup, /* startup */ + php_module_shutdown_wrapper, /* shutdown */ - php_module_startup, /* startup */ - php_module_shutdown_wrapper, /* shutdown */ + NULL, /* activate */ + sapi_cgi_deactivate, /* deactivate */ - NULL, /* activate */ - sapi_cgi_deactivate, /* deactivate */ + sapi_cgibin_ub_write, /* unbuffered write */ + sapi_cgibin_flush, /* flush */ + NULL, /* get uid */ + NULL, /* getenv */ - sapi_cgibin_ub_write, /* unbuffered write */ - sapi_cgibin_flush, /* flush */ - NULL, /* get uid */ - NULL, /* getenv */ + php_error, /* error handler */ - php_error, /* error handler */ + NULL, /* header handler */ + NULL, /* send headers handler */ + sapi_cgi_send_header, /* send header handler */ - NULL, /* header handler */ - NULL, /* send headers handler */ - sapi_cgi_send_header, /* send header handler */ + sapi_cgi_read_post, /* read POST data */ + sapi_cgi_read_cookies, /* read Cookies */ - sapi_cgi_read_post, /* read POST data */ - sapi_cgi_read_cookies, /* read Cookies */ + sapi_cgi_register_variables, /* register server variables */ + sapi_cgi_log_message, /* Log message */ - sapi_cgi_register_variables, /* register server variables */ - sapi_cgi_log_message, /* Log message */ + NULL, /* Block interruptions */ + NULL, /* Unblock interruptions */ - NULL, /* Block interruptions */ - NULL, /* Unblock interruptions */ - - STANDARD_SAPI_MODULE_PROPERTIES + STANDARD_SAPI_MODULE_PROPERTIES }; /* }}} */ @@ -317,31 +317,31 @@ static sapi_module_struct cgi_sapi_module = { */ static void php_cgi_usage(char *argv0) { - char *prog; - - prog = strrchr(argv0, '/'); - if (prog) { - prog++; - } else { - prog = "php"; - } - - php_printf("Usage: %s [-q] [-h] [-s [-v] [-i] [-f <file>] | {<file> [args...]}\n" - " -q Quiet-mode. Suppress HTTP Header output.\n" - " -s Display colour syntax highlighted source.\n" - " -w Display source with stripped comments and whitespace.\n" - " -f <file> Parse <file>. Implies `-q'\n" - " -v Version number\n" - " -C Do not chdir to the script's directory\n" - " -c <path>|<file> Look for php.ini file in this directory\n" - " -a Run interactively\n" - " -d foo[=bar] Define INI entry foo with value 'bar'\n" - " -e Generate extended information for debugger/profiler\n" - " -z <file> Load Zend extension <file>.\n" - " -l Syntax check only (lint)\n" - " -m Show compiled in modules\n" - " -i PHP information\n" - " -h This help\n", prog); + char *prog; + + prog = strrchr(argv0, '/'); + if (prog) { + prog++; + } else { + prog = "php"; + } + + php_printf("Usage: %s [-q] [-h] [-s [-v] [-i] [-f <file>] | {<file> [args...]}\n" + " -q Quiet-mode. Suppress HTTP Header output.\n" + " -s Display colour syntax highlighted source.\n" + " -w Display source with stripped comments and whitespace.\n" + " -f <file> Parse <file>. Implies `-q'\n" + " -v Version number\n" + " -C Do not chdir to the script's directory\n" + " -c <path>|<file> Look for php.ini file in this directory\n" + " -a Run interactively\n" + " -d foo[=bar] Define INI entry foo with value 'bar'\n" + " -e Generate extended information for debugger/profiler\n" + " -z <file> Load Zend extension <file>.\n" + " -l Syntax check only (lint)\n" + " -m Show compiled in modules\n" + " -i PHP information\n" + " -h This help\n", prog); } /* }}} */ @@ -349,260 +349,252 @@ static void php_cgi_usage(char *argv0) */ static void init_request_info(TSRMLS_D) { - char *content_length = getenv("CONTENT_LENGTH"); - char *content_type = getenv("CONTENT_TYPE"); - const char *auth; + char *content_length = getenv("CONTENT_LENGTH"); + char *content_type = getenv("CONTENT_TYPE"); + const char *auth; #if 0 /* SG(request_info).path_translated is always set to NULL at the end of this function call so why the hell did this code exist in the first place? Am I missing something? */ - char *script_filename; + char *script_filename; - script_filename = getenv("SCRIPT_FILENAME"); - /* Hack for annoying servers that do not set SCRIPT_FILENAME for us */ - if (!script_filename) { - script_filename = SG(request_info).argv0; - } + script_filename = getenv("SCRIPT_FILENAME"); + /* Hack for annoying servers that do not set SCRIPT_FILENAME for us */ + if (!script_filename) { + script_filename = SG(request_info).argv0; + } #ifdef PHP_WIN32 - /* FIXME WHEN APACHE NT IS FIXED */ - /* a hack for apache nt because it does not appear to set argv[1] and sets - script filename to php.exe thus makes us parse php.exe instead of file.php - requires we get the info from path translated. This can be removed at - such a time that apache nt is fixed */ - if (!script_filename) { - script_filename = getenv("PATH_TRANSLATED"); - } + /* FIXME WHEN APACHE NT IS FIXED */ + /* a hack for apache nt because it does not appear to set argv[1] and sets + script filename to php.exe thus makes us parse php.exe instead of file.php + requires we get the info from path translated. This can be removed at + such a time that apache nt is fixed */ + if (!script_filename) { + script_filename = getenv("PATH_TRANSLATED"); + } #endif - /* doc_root configuration variable is currently ignored, - as it is with every other access method currently also. */ + /* doc_root configuration variable is currently ignored, + as it is with every other access method currently also. */ - /* We always need to emalloc() filename, since it gets placed into - the include file hash table, and gets freed with that table. - Notice that this means that we don't need to efree() it in - php_destroy_request_info()! */ + /* We always need to emalloc() filename, since it gets placed into + the include file hash table, and gets freed with that table. + Notice that this means that we don't need to efree() it in + php_destroy_request_info()! */ #if DISCARD_PATH - if (script_filename) { - SG(request_info).path_translated = estrdup(script_filename); - } else { - SG(request_info).path_translated = NULL; - } + if (script_filename) { + SG(request_info).path_translated = estrdup(script_filename); + } else { + SG(request_info).path_translated = NULL; + } #endif #endif /* 0 */ - SG(request_info).request_method = getenv("REQUEST_METHOD"); - SG(request_info).query_string = getenv("QUERY_STRING"); - SG(request_info).request_uri = getenv("PATH_INFO"); - if (!SG(request_info).request_uri) { - SG(request_info).request_uri = getenv("SCRIPT_NAME"); - } - SG(request_info).path_translated = NULL; /* we have to update it later, when we have that information */ - SG(request_info).content_type = (content_type ? content_type : "" ); - SG(request_info).content_length = (content_length?atoi(content_length):0); - SG(sapi_headers).http_response_code = 200; - - /* The CGI RFC allows servers to pass on unvalidated Authorization data */ - auth = getenv("HTTP_AUTHORIZATION"); - php_handle_auth_data(auth TSRMLS_CC); + SG(request_info).request_method = getenv("REQUEST_METHOD"); + SG(request_info).query_string = getenv("QUERY_STRING"); + SG(request_info).request_uri = getenv("PATH_INFO"); + if (!SG(request_info).request_uri) { + SG(request_info).request_uri = getenv("SCRIPT_NAME"); + } + SG(request_info).path_translated = NULL; /* we have to update it later, when we have that information */ + SG(request_info).content_type = (content_type ? content_type : "" ); + SG(request_info).content_length = (content_length?atoi(content_length):0); + SG(sapi_headers).http_response_code = 200; + + /* The CGI RFC allows servers to pass on unvalidated Authorization data */ + auth = getenv("HTTP_AUTHORIZATION"); + php_handle_auth_data(auth TSRMLS_CC); } /* }}} */ static void define_command_line_ini_entry(char *arg) { - char *name, *value; - - name = arg; - value = strchr(arg, '='); - if (value) { - *value = 0; - value++; - } else { - value = "1"; - } - zend_alter_ini_entry(name, strlen(name)+1, value, strlen(value), PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE); + char *name, *value; + + name = arg; + value = strchr(arg, '='); + if (value) { + *value = 0; + value++; + } else { + value = "1"; + } + zend_alter_ini_entry(name, strlen(name)+1, value, strlen(value), PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE); } static void php_register_command_line_global_vars(char **arg TSRMLS_DC) { - char *var, *val; - - var = *arg; - val = strchr(var, '='); - if (!val) { - printf("No value specified for variable '%s'\n", var); - } else { - *val++ = '\0'; - php_register_variable(var, val, NULL TSRMLS_CC); - } - efree(*arg); + char *var, *val; + + var = *arg; + val = strchr(var, '='); + if (!val) { + printf("No value specified for variable '%s'\n", var); + } else { + *val++ = '\0'; + php_register_variable(var, val, NULL TSRMLS_CC); + } + efree(*arg); } /* {{{ main */ int main(int argc, char *argv[]) { - int exit_status = SUCCESS; - int cgi = 0, c, i, len; - zend_file_handle file_handle; - int retval = FAILURE; - char *s; + int exit_status = SUCCESS; + int cgi = 0, c, i, len; + zend_file_handle file_handle; + int retval = FAILURE; + char *s; /* temporary locals */ - int behavior=PHP_MODE_STANDARD; - int no_headers=0; - int orig_optind=ap_php_optind; - char *orig_optarg=ap_php_optarg; - char *argv0=NULL; - char *script_file=NULL; - zend_llist global_vars; - int interactive=0; + int behavior=PHP_MODE_STANDARD; + int no_headers=0; + int orig_optind=ap_php_optind; + char *orig_optarg=ap_php_optarg; + char *argv0=NULL; + char *script_file=NULL; + zend_llist global_vars; + int interactive=0; #if FORCE_CGI_REDIRECT - int force_redirect = 1; - char *redirect_status_env = NULL; + int force_redirect = 1; + char *redirect_status_env = NULL; #endif /* end of temporary locals */ #ifdef ZTS - zend_compiler_globals *compiler_globals; - zend_executor_globals *executor_globals; - php_core_globals *core_globals; - sapi_globals_struct *sapi_globals; - void ***tsrm_ls; + zend_compiler_globals *compiler_globals; + zend_executor_globals *executor_globals; + php_core_globals *core_globals; + sapi_globals_struct *sapi_globals; + void ***tsrm_ls; #endif #ifdef PHP_FASTCGI - int env_size, cgi_env_size; - int max_requests = 500; - int requests = 0; - int fastcgi = !FCGX_IsCGI(); + int env_size, cgi_env_size; + int max_requests = 500; + int requests = 0; + int fastcgi = !FCGX_IsCGI(); #ifdef PHP_WIN32 - int impersonate = 0; + int impersonate = 0; #endif - if (fastcgi) { - /* Calculate environment size */ - env_size = 0; - while( environ[ env_size ] ) { env_size++; } - /* Also include the final NULL pointer */ - env_size++; - - /* Allocate for our environment */ - orig_env = malloc( env_size * sizeof( char *)); - if( !orig_env ) { - perror( "Can't malloc environment" ); - exit( 1 ); - } - memcpy( orig_env, environ, env_size * sizeof( char *)); - } + if (fastcgi) { + /* Calculate environment size */ + env_size = 0; + while( environ[ env_size ] ) { env_size++; } + /* Also include the final NULL pointer */ + env_size++; + + /* Allocate for our environment */ + orig_env = malloc( env_size * sizeof( char *)); + if( !orig_env ) { + perror( "Can't malloc environment" ); + exit( 1 ); + } + memcpy( orig_env, environ, env_size * sizeof( char *)); + } #endif #ifdef HAVE_SIGNAL_H #if defined(SIGPIPE) && defined(SIG_IGN) - signal(SIGPIPE, SIG_IGN); /* ignore SIGPIPE in standalone mode so - that sockets created via fsockopen() - don't kill PHP if the remote site - closes it. in apache|apxs mode apache - does that for us! thies@thieso.net - 20000419 */ + signal(SIGPIPE, SIG_IGN); /* ignore SIGPIPE in standalone mode so + that sockets created via fsockopen() + don't kill PHP if the remote site + closes it. in apache|apxs mode apache + does that for us! thies@thieso.net + 20000419 */ #endif #endif #ifdef ZTS - tsrm_startup(1, 1, 0, NULL); + tsrm_startup(1, 1, 0, NULL); #endif - sapi_startup(&cgi_sapi_module); + sapi_startup(&cgi_sapi_module); #ifdef PHP_WIN32 - _fmode = _O_BINARY; /*sets default for file streams to binary */ - setmode(_fileno(stdin), O_BINARY); /* make the stdio mode be binary */ - setmode(_fileno(stdout), O_BINARY); /* make the stdio mode be binary */ - setmode(_fileno(stderr), O_BINARY); /* make the stdio mode be binary */ + _fmode = _O_BINARY; /*sets default for file streams to binary */ + setmode(_fileno(stdin), O_BINARY); /* make the stdio mode be binary */ + setmode(_fileno(stdout), O_BINARY); /* make the stdio mode be binary */ + setmode(_fileno(stderr), O_BINARY); /* make the stdio mode be binary */ #endif - /* Make sure we detect we are a cgi - a bit redundancy here, - but the default case is that we have to check only the first one. */ - if (getenv("SERVER_SOFTWARE") - || getenv("SERVER_NAME") - || getenv("GATEWAY_INTERFACE") - || getenv("REQUEST_METHOD")) { - cgi = 1; - if (argc > 1) { - argv0 = strdup(argv[1]); - } else { - argv0 = NULL; - } - } - - if (!cgi + /* Make sure we detect we are a cgi - a bit redundancy here, + but the default case is that we have to check only the first one. */ + if (getenv("SERVER_SOFTWARE") + || getenv("SERVER_NAME") + || getenv("GATEWAY_INTERFACE") + || getenv("REQUEST_METHOD")) { + cgi = 1; + if (argc > 1) { + argv0 = strdup(argv[1]); + } else { + argv0 = NULL; + } + } + + if (!cgi #ifdef PHP_FASTCGI - /* allow ini override for fastcgi */ + /* allow ini override for fastcgi */ #endif - ) { - while ((c=ap_php_getopt(argc, argv, OPTSTRING))!=-1) { - switch (c) { - case 'c': - cgi_sapi_module.php_ini_path_override = strdup(ap_php_optarg); - break; - } + ) { + while ((c=ap_php_getopt(argc, argv, OPTSTRING))!=-1) { + switch (c) { + case 'c': + cgi_sapi_module.php_ini_path_override = strdup(ap_php_optarg); + break; + } - } - ap_php_optind = orig_optind; - ap_php_optarg = orig_optarg; - } + } + ap_php_optind = orig_optind; + ap_php_optarg = orig_optarg; + } #ifdef ZTS - compiler_globals = ts_resource(compiler_globals_id); - executor_globals = ts_resource(executor_globals_id); - core_globals = ts_resource(core_globals_id); - sapi_globals = ts_resource(sapi_globals_id); - tsrm_ls = ts_resource(0); + compiler_globals = ts_resource(compiler_globals_id); + executor_globals = ts_resource(executor_globals_id); + core_globals = ts_resource(core_globals_id); + sapi_globals = ts_resource(sapi_globals_id); + tsrm_ls = ts_resource(0); #endif - /* startup after we get the above ini override se we get things right */ - if (php_module_startup(&cgi_sapi_module)==FAILURE) { + /* startup after we get the above ini override se we get things right */ + if (php_module_startup(&cgi_sapi_module)==FAILURE) { #ifdef ZTS - tsrm_shutdown(); + tsrm_shutdown(); #endif - return FAILURE; - } + return FAILURE; + } #if FORCE_CGI_REDIRECT - /* check force_cgi after startup, so we have proper output */ - if (cfg_get_long("cgi.force_redirect", &force_redirect) == FAILURE) { + /* check force_cgi after startup, so we have proper output */ + if (cfg_get_long("cgi.force_redirect", &force_redirect) == FAILURE) { force_redirect = 1; - { - /* We don't need force_cgi on if running under IIS. */ - char* sServerSoftware = getenv("SERVER_SOFTWARE"); - char* sExpected = "Microsoft-IIS"; - if (sServerSoftware && (0 == strncmp(sServerSoftware,sExpected,strlen(sExpected)))) { - force_redirect = 0; - } - } - } - if (cgi && force_redirect) { + } + if (cgi && force_redirect) { if (cfg_get_string("cgi.redirect_status_env", &redirect_status_env) == FAILURE) { redirect_status_env = NULL; } - /* Apache will generate REDIRECT_STATUS, - * Netscape and redirect.so will generate HTTP_REDIRECT_STATUS. - * redirect.so and installation instructions available from - * http://www.koehntopp.de/php. - * -- kk@netuse.de - */ - if (!getenv("REDIRECT_STATUS") - && !getenv ("HTTP_REDIRECT_STATUS") - /* this is to allow a different env var to be configured - in case some server does something different than above */ - && (!redirect_status_env || !getenv(redirect_status_env)) - ) { - PUTS("<b>Security Alert!</b> The PHP CGI cannot be accessed directly.\n\n\ + /* Apache will generate REDIRECT_STATUS, + * Netscape and redirect.so will generate HTTP_REDIRECT_STATUS. + * redirect.so and installation instructions available from + * http://www.koehntopp.de/php. + * -- kk@netuse.de + */ + if (!getenv("REDIRECT_STATUS") + && !getenv ("HTTP_REDIRECT_STATUS") + /* this is to allow a different env var to be configured + in case some server does something different than above */ + && (!redirect_status_env || !getenv(redirect_status_env)) + ) { + PUTS("<b>Security Alert!</b> The PHP CGI cannot be accessed directly.\n\n\ <p>This PHP CGI binary was compiled with force-cgi-redirect enabled. This\n\ means that a page will only be served up if the REDIRECT_STATUS CGI variable is\n\ set, e.g. via an Apache Action directive.</p>\n\ @@ -613,506 +605,506 @@ consult the installation file that came with this distribution, or visit \n\ <a href=\"http://php.net/install.windows\">the manual page</a>.</p>\n"); #ifdef ZTS - tsrm_shutdown(); + tsrm_shutdown(); #endif - return FAILURE; - } - } -#endif /* FORCE_CGI_REDIRECT */ + return FAILURE; + } + } +#endif /* FORCE_CGI_REDIRECT */ #ifdef PHP_FASTCGI - /* How many times to run PHP scripts before dying */ - if( getenv( "PHP_FCGI_MAX_REQUESTS" )) { - max_requests = atoi( getenv( "PHP_FCGI_MAX_REQUESTS" )); - if( !max_requests ) { - fprintf( stderr, - "PHP_FCGI_MAX_REQUESTS is not valid\n" ); - exit( 1 ); - } - } + /* How many times to run PHP scripts before dying */ + if( getenv( "PHP_FCGI_MAX_REQUESTS" )) { + max_requests = atoi( getenv( "PHP_FCGI_MAX_REQUESTS" )); + if( !max_requests ) { + fprintf( stderr, + "PHP_FCGI_MAX_REQUESTS is not valid\n" ); + exit( 1 ); + } + } #ifndef PHP_WIN32 - /* Pre-fork, if required */ - if( getenv( "PHP_FCGI_CHILDREN" )) { - children = atoi( getenv( "PHP_FCGI_CHILDREN" )); - if( !children ) { - fprintf( stderr, - "PHP_FCGI_CHILDREN is not valid\n" ); - exit( 1 ); - } - } - - if( children ) { - int running = 0; - int i; - pid_t pid; - - /* Create a process group for ourself & children */ - setsid(); - pgroup = getpgrp(); + /* Pre-fork, if required */ + if( getenv( "PHP_FCGI_CHILDREN" )) { + children = atoi( getenv( "PHP_FCGI_CHILDREN" )); + if( !children ) { + fprintf( stderr, + "PHP_FCGI_CHILDREN is not valid\n" ); + exit( 1 ); + } + } + + if( children ) { + int running = 0; + int i; + pid_t pid; + + /* Create a process group for ourself & children */ + setsid(); + pgroup = getpgrp(); #ifdef DEBUG_FASTCGI - fprintf( stderr, "Process group %d\n", pgroup ); + fprintf( stderr, "Process group %d\n", pgroup ); #endif - /* Set up handler to kill children upon exit */ - act.sa_flags = 0; - act.sa_handler = fastcgi_cleanup; - if( sigaction( SIGTERM, &act, &old_term ) || - sigaction( SIGINT, &act, &old_int ) || - sigaction( SIGQUIT, &act, &old_quit )) { - perror( "Can't set signals" ); - exit( 1 ); - } - - while( parent ) { - do { + /* Set up handler to kill children upon exit */ + act.sa_flags = 0; + act.sa_handler = fastcgi_cleanup; + if( sigaction( SIGTERM, &act, &old_term ) || + sigaction( SIGINT, &act, &old_int ) || + sigaction( SIGQUIT, &act, &old_quit )) { + perror( "Can't set signals" ); + exit( 1 ); + } + + while( parent ) { + do { #ifdef DEBUG_FASTCGI - fprintf( stderr, "Forking, %d running\n", - running ); + fprintf( stderr, "Forking, %d running\n", + running ); #endif - pid = fork(); - switch( pid ) { - case 0: - /* One of the children. - * Make sure we don't go round the - * fork loop any more - */ - parent = 0; - - /* don't catch our signals */ - sigaction( SIGTERM, &old_term, 0 ); - sigaction( SIGQUIT, &old_quit, 0 ); - sigaction( SIGINT, &old_int, 0 ); - break; - case -1: - perror( "php (pre-forking)" ); - exit( 1 ); - break; - default: - /* Fine */ - running++; - break; - } - } while( parent && ( running < children )); - - if( parent ) { + pid = fork(); + switch( pid ) { + case 0: + /* One of the children. + * Make sure we don't go round the + * fork loop any more + */ + parent = 0; + + /* don't catch our signals */ + sigaction( SIGTERM, &old_term, 0 ); + sigaction( SIGQUIT, &old_quit, 0 ); + sigaction( SIGINT, &old_int, 0 ); + break; + case -1: + perror( "php (pre-forking)" ); + exit( 1 ); + break; + default: + /* Fine */ + running++; + break; + } + } while( parent && ( running < children )); + + if( parent ) { #ifdef DEBUG_FASTCGI - fprintf( stderr, "Wait for kids, pid %d\n", - getpid() ); + fprintf( stderr, "Wait for kids, pid %d\n", + getpid() ); #endif - wait( &status ); - running--; - } - } - } + wait( &status ); + running--; + } + } + } #endif /* WIN32 */ #endif - zend_first_try { - if (!cgi + zend_first_try { + if (!cgi #ifdef PHP_FASTCGI - && !fastcgi + && !fastcgi #endif - ) { - while ((c=ap_php_getopt(argc, argv, OPTSTRING))!=-1) { - switch (c) { - case '?': - no_headers = 1; - php_output_startup(); - php_output_activate(TSRMLS_C); - SG(headers_sent) = 1; - php_cgi_usage(argv[0]); - php_end_ob_buffers(1 TSRMLS_CC); - exit(1); - break; - } - } - ap_php_optind = orig_optind; - ap_php_optarg = orig_optarg; - } + ) { + while ((c=ap_php_getopt(argc, argv, OPTSTRING))!=-1) { + switch (c) { + case '?': + no_headers = 1; + php_output_startup(); + php_output_activate(TSRMLS_C); + SG(headers_sent) = 1; + php_cgi_usage(argv[0]); + php_end_ob_buffers(1 TSRMLS_CC); + exit(1); + break; + } + } + ap_php_optind = orig_optind; + ap_php_optarg = orig_optarg; + } #ifdef PHP_FASTCGI - /* start of FAST CGI loop */ + /* start of FAST CGI loop */ #ifdef PHP_WIN32 - /* attempt to set security impersonation for fastcgi - will only happen on NT based OS, others will ignore it. */ - if (fastcgi) { - if (cfg_get_long("fastcgi.impersonate", &impersonate) == FAILURE) { - impersonate = 0; - } - if (impersonate) OS_SetImpersonate(); - } + /* attempt to set security impersonation for fastcgi + will only happen on NT based OS, others will ignore it. */ + if (fastcgi) { + if (cfg_get_long("fastcgi.impersonate", &impersonate) == FAILURE) { + impersonate = 0; + } + if (impersonate) OS_SetImpersonate(); + } #endif - while (!fastcgi - || FCGX_Accept( &in, &out, &err, &cgi_env ) >= 0) { - - if (fastcgi) { - /* set up environment */ - cgi_env_size = 0; - while( cgi_env[ cgi_env_size ] ) { cgi_env_size++; } - merge_env = malloc( (env_size+cgi_env_size)*sizeof(char*) ); - if( !merge_env ) { - perror( "Can't malloc environment" ); - exit( 1 ); - } - memcpy( merge_env, orig_env, (env_size-1)*sizeof(char *) ); - memcpy( merge_env + env_size - 1, - cgi_env, (cgi_env_size+1)*sizeof(char *) ); - environ = merge_env; - } + while (!fastcgi + || FCGX_Accept( &in, &out, &err, &cgi_env ) >= 0) { + + if (fastcgi) { + /* set up environment */ + cgi_env_size = 0; + while( cgi_env[ cgi_env_size ] ) { cgi_env_size++; } + merge_env = malloc( (env_size+cgi_env_size)*sizeof(char*) ); + if( !merge_env ) { + perror( "Can't malloc environment" ); + exit( 1 ); + } + memcpy( merge_env, orig_env, (env_size-1)*sizeof(char *) ); + memcpy( merge_env + env_size - 1, + cgi_env, (cgi_env_size+1)*sizeof(char *) ); + environ = merge_env; + } #endif - init_request_info(TSRMLS_C); - SG(server_context) = (void *) 1; /* avoid server_context==NULL checks */ + init_request_info(TSRMLS_C); + SG(server_context) = (void *) 1; /* avoid server_context==NULL checks */ - SG(request_info).argv0 = argv0; + SG(request_info).argv0 = argv0; - zend_llist_init(&global_vars, sizeof(char *), NULL, 0); + zend_llist_init(&global_vars, sizeof(char *), NULL, 0); - if (!cgi + if (!cgi #ifdef PHP_FASTCGI - && !fastcgi + && !fastcgi #endif - ) { /* never execute the arguments if you are a CGI */ - if (SG(request_info).argv0) { - free(SG(request_info).argv0); - SG(request_info).argv0 = NULL; - } - while ((c = ap_php_getopt(argc, argv, OPTSTRING)) != -1) { - switch (c) { - - case 'a': /* interactive mode */ - printf("Interactive mode enabled\n\n"); - interactive=1; - break; - - case 'C': /* don't chdir to the script directory */ - SG(options) |= SAPI_OPTION_NO_CHDIR; - break; - case 'd': /* define ini entries on command line */ - define_command_line_ini_entry(ap_php_optarg); - break; - - case 'e': /* enable extended info output */ - CG(extended_info) = 1; - break; - - case 'f': /* parse file */ - script_file = estrdup(ap_php_optarg); - no_headers = 1; - break; - - case 'g': /* define global variables on command line */ - { - char *arg = estrdup(ap_php_optarg); - - zend_llist_add_element(&global_vars, &arg); - } - break; - - case 'h': /* help & quit */ - case '?': - no_headers = 1; - php_output_startup(); - php_output_activate(TSRMLS_C); - SG(headers_sent) = 1; - php_cgi_usage(argv[0]); - php_end_ob_buffers(1 TSRMLS_CC); - exit(1); - break; - - case 'i': /* php info & quit */ - if (php_request_startup(TSRMLS_C)==FAILURE) { - php_module_shutdown(TSRMLS_C); - return FAILURE; - } - if (no_headers) { - SG(headers_sent) = 1; - SG(request_info).no_headers = 1; - } - php_print_info(0xFFFFFFFF TSRMLS_CC); - php_end_ob_buffers(1 TSRMLS_CC); - exit(1); - break; - - case 'l': /* syntax check mode */ - no_headers = 1; - behavior=PHP_MODE_LINT; - break; - - case 'm': /* list compiled in modules */ - php_output_startup(); - php_output_activate(TSRMLS_C); - SG(headers_sent) = 1; - php_printf("Running PHP %s\n%s\n", PHP_VERSION , get_zend_version()); - php_printf("[PHP Modules]\n"); - zend_hash_apply_with_argument(&module_registry, (apply_func_arg_t) _print_module_info, NULL TSRMLS_CC); - php_printf("\n[Zend Modules]\n"); - zend_llist_apply_with_argument(&zend_extensions, (llist_apply_with_arg_func_t) _print_extension_info, NULL TSRMLS_CC); - php_printf("\n"); - php_end_ob_buffers(1 TSRMLS_CC); - exit(1); - break; + ) { /* never execute the arguments if you are a CGI */ + if (SG(request_info).argv0) { + free(SG(request_info).argv0); + SG(request_info).argv0 = NULL; + } + while ((c = ap_php_getopt(argc, argv, OPTSTRING)) != -1) { + switch (c) { + + case 'a': /* interactive mode */ + printf("Interactive mode enabled\n\n"); + interactive=1; + break; + + case 'C': /* don't chdir to the script directory */ + SG(options) |= SAPI_OPTION_NO_CHDIR; + break; + case 'd': /* define ini entries on command line */ + define_command_line_ini_entry(ap_php_optarg); + break; + + case 'e': /* enable extended info output */ + CG(extended_info) = 1; + break; + + case 'f': /* parse file */ + script_file = estrdup(ap_php_optarg); + no_headers = 1; + break; + + case 'g': /* define global variables on command line */ + { + char *arg = estrdup(ap_php_optarg); + + zend_llist_add_element(&global_vars, &arg); + } + break; + + case 'h': /* help & quit */ + case '?': + no_headers = 1; + php_output_startup(); + php_output_activate(TSRMLS_C); + SG(headers_sent) = 1; + php_cgi_usage(argv[0]); + php_end_ob_buffers(1 TSRMLS_CC); + exit(1); + break; + + case 'i': /* php info & quit */ + if (php_request_startup(TSRMLS_C)==FAILURE) { + php_module_shutdown(TSRMLS_C); + return FAILURE; + } + if (no_headers) { + SG(headers_sent) = 1; + SG(request_info).no_headers = 1; + } + php_print_info(0xFFFFFFFF TSRMLS_CC); + php_end_ob_buffers(1 TSRMLS_CC); + exit(1); + break; + + case 'l': /* syntax check mode */ + no_headers = 1; + behavior=PHP_MODE_LINT; + break; + + case 'm': /* list compiled in modules */ + php_output_startup(); + php_output_activate(TSRMLS_C); + SG(headers_sent) = 1; + php_printf("Running PHP %s\n%s\n", PHP_VERSION , get_zend_version()); + php_printf("[PHP Modules]\n"); + zend_hash_apply_with_argument(&module_registry, (apply_func_arg_t) _print_module_info, NULL TSRMLS_CC); + php_printf("\n[Zend Modules]\n"); + zend_llist_apply_with_argument(&zend_extensions, (llist_apply_with_arg_func_t) _print_extension_info, NULL TSRMLS_CC); + php_printf("\n"); + php_end_ob_buffers(1 TSRMLS_CC); + exit(1); + break; #if 0 /* not yet operational, see also below ... */ - case 'n': /* generate indented source mode*/ - behavior=PHP_MODE_INDENT; - break; + case 'n': /* generate indented source mode*/ + behavior=PHP_MODE_INDENT; + break; #endif - case 'q': /* do not generate HTTP headers */ - no_headers = 1; - break; - - case 's': /* generate highlighted HTML from source */ - behavior=PHP_MODE_HIGHLIGHT; - break; - - case 'v': /* show php version & quit */ - no_headers = 1; - if (php_request_startup(TSRMLS_C)==FAILURE) { - php_module_shutdown(TSRMLS_C); - return FAILURE; - } - if (no_headers) { - SG(headers_sent) = 1; - SG(request_info).no_headers = 1; - } - php_printf("%s (%s)\n", PHP_VERSION, sapi_module.name); - php_end_ob_buffers(1 TSRMLS_CC); - exit(1); - break; - - case 'w': - behavior=PHP_MODE_STRIP; - break; - - case 'z': /* load extension file */ - zend_load_extension(ap_php_optarg); - break; - - default: - break; - } - } - } /* not cgi */ - - CG(interactive) = interactive; - - if (!cgi + case 'q': /* do not generate HTTP headers */ + no_headers = 1; + break; + + case 's': /* generate highlighted HTML from source */ + behavior=PHP_MODE_HIGHLIGHT; + break; + + case 'v': /* show php version & quit */ + no_headers = 1; + if (php_request_startup(TSRMLS_C)==FAILURE) { + php_module_shutdown(TSRMLS_C); + return FAILURE; + } + if (no_headers) { + SG(headers_sent) = 1; + SG(request_info).no_headers = 1; + } + php_printf("%s (%s)\n", PHP_VERSION, sapi_module.name); + php_end_ob_buffers(1 TSRMLS_CC); + exit(1); + break; + + case 'w': + behavior=PHP_MODE_STRIP; + break; + + case 'z': /* load extension file */ + zend_load_extension(ap_php_optarg); + break; + + default: + break; + } + } + } /* not cgi */ + + CG(interactive) = interactive; + + if (!cgi #ifdef PHP_FASTCGI - && !fastcgi + && !fastcgi #endif - ) { - if (!SG(request_info).query_string) { - len = 0; - if (script_file) { - len += strlen(script_file) + 1; - } - for (i = ap_php_optind; i < argc; i++) { - len += strlen(argv[i]) + 1; - } - - s = malloc(len + 1); /* leak - but only for command line version, so ok */ - *s = '\0'; /* we are pretending it came from the environment */ - if (script_file) { - strcpy(s, script_file); - if (ap_php_optind<argc) { - strcat(s, "+"); - } - } - for (i = ap_php_optind, len = 0; i < argc; i++) { - strcat(s, argv[i]); - if (i < (argc - 1)) { - strcat(s, "+"); - } - } - SG(request_info).query_string = s; - } - } - - if (script_file) { - SG(request_info).path_translated = script_file; - } - - if (php_request_startup(TSRMLS_C)==FAILURE) { - php_module_shutdown(TSRMLS_C); - return FAILURE; - } - if (no_headers) { - SG(headers_sent) = 1; - SG(request_info).no_headers = 1; - } + ) { + if (!SG(request_info).query_string) { + len = 0; + if (script_file) { + len += strlen(script_file) + 1; + } + for (i = ap_php_optind; i < argc; i++) { + len += strlen(argv[i]) + 1; + } + + s = malloc(len + 1); /* leak - but only for command line version, so ok */ + *s = '\0'; /* we are pretending it came from the environment */ + if (script_file) { + strcpy(s, script_file); + if (ap_php_optind<argc) { + strcat(s, "+"); + } + } + for (i = ap_php_optind, len = 0; i < argc; i++) { + strcat(s, argv[i]); + if (i < (argc - 1)) { + strcat(s, "+"); + } + } + SG(request_info).query_string = s; + } + } + + if (script_file) { + SG(request_info).path_translated = script_file; + } + + if (php_request_startup(TSRMLS_C)==FAILURE) { + php_module_shutdown(TSRMLS_C); + return FAILURE; + } + if (no_headers) { + SG(headers_sent) = 1; + SG(request_info).no_headers = 1; + } #ifdef PHP_FASTCGI - if (fastcgi) { - file_handle.type = ZEND_HANDLE_FILENAME; - file_handle.filename = SG(request_info).path_translated; - } else { + if (fastcgi) { + file_handle.type = ZEND_HANDLE_FILENAME; + file_handle.filename = SG(request_info).path_translated; + } else { #endif - file_handle.filename = "-"; - file_handle.type = ZEND_HANDLE_FP; - file_handle.handle.fp = stdin; + file_handle.filename = "-"; + file_handle.type = ZEND_HANDLE_FP; + file_handle.handle.fp = stdin; #ifdef PHP_FASTCGI - } + } #endif - file_handle.opened_path = NULL; - file_handle.free_filename = 0; + file_handle.opened_path = NULL; + file_handle.free_filename = 0; - /* This actually destructs the elements of the list - ugly hack */ - zend_llist_apply(&global_vars, (llist_apply_func_t) php_register_command_line_global_vars TSRMLS_CC); - zend_llist_destroy(&global_vars); + /* This actually destructs the elements of the list - ugly hack */ + zend_llist_apply(&global_vars, (llist_apply_func_t) php_register_command_line_global_vars TSRMLS_CC); + zend_llist_destroy(&global_vars); - if (!cgi + if (!cgi #ifdef PHP_FASTCGI - && !fastcgi + && !fastcgi #endif - ) { - if (!SG(request_info).path_translated && argc > ap_php_optind) { - SG(request_info).path_translated = estrdup(argv[ap_php_optind]); - } - } else { - /* If for some reason the CGI interface is not setting the - PATH_TRANSLATED correctly, SG(request_info).path_translated is NULL. - We still call php_fopen_primary_script, because if you set doc_root - or user_dir configuration directives, PATH_INFO is used to construct - the filename as a side effect of php_fopen_primary_script. - */ - char *env_path_translated=NULL; + ) { + if (!SG(request_info).path_translated && argc > ap_php_optind) { + SG(request_info).path_translated = estrdup(argv[ap_php_optind]); + } + } else { + /* If for some reason the CGI interface is not setting the + PATH_TRANSLATED correctly, SG(request_info).path_translated is NULL. + We still call php_fopen_primary_script, because if you set doc_root + or user_dir configuration directives, PATH_INFO is used to construct + the filename as a side effect of php_fopen_primary_script. + */ + char *env_path_translated=NULL; #if DISCARD_PATH - env_path_translated = getenv("SCRIPT_FILENAME"); + env_path_translated = getenv("SCRIPT_FILENAME"); #else - env_path_translated = getenv("PATH_TRANSLATED"); + env_path_translated = getenv("PATH_TRANSLATED"); #endif - if(env_path_translated) { + if(env_path_translated) { #ifdef __riscos__ - /* Convert path to unix format*/ - __riscosify_control|=__RISCOSIFY_DONT_CHECK_DIR; - env_path_translated=__unixify(env_path_translated,0,NULL,1,0); + /* Convert path to unix format*/ + __riscosify_control|=__RISCOSIFY_DONT_CHECK_DIR; + env_path_translated=__unixify(env_path_translated,0,NULL,1,0); #endif - SG(request_info).path_translated = estrdup(env_path_translated); - } - } - if (cgi || SG(request_info).path_translated) { - retval = php_fopen_primary_script(&file_handle TSRMLS_CC); - } - - if (cgi && (retval == FAILURE)) { - if(!argv0 || !(file_handle.handle.fp = VCWD_FOPEN(argv0, "rb"))) { - PUTS("No input file specified.\n"); - php_request_shutdown((void *) 0); - php_module_shutdown(TSRMLS_C); - return FAILURE; - } - file_handle.filename = argv0; - file_handle.opened_path = expand_filepath(argv0, NULL TSRMLS_CC); - } - - if (file_handle.handle.fp && (file_handle.handle.fp != stdin)) { - /* #!php support */ - c = fgetc(file_handle.handle.fp); - if (c == '#') { - while (c != 10 && c != 13) { - c = fgetc(file_handle.handle.fp); /* skip to end of line */ - } - CG(zend_lineno)++; - } else { - rewind(file_handle.handle.fp); - } - } - - switch (behavior) { - case PHP_MODE_STANDARD: - if (php_execute_script(&file_handle TSRMLS_CC)) { - exit_status = EG(exit_status); - } else { - exit_status = 255; - } - break; - case PHP_MODE_LINT: - PG(during_request_startup) = 0; - exit_status = php_lint_script(&file_handle TSRMLS_CC); - if (exit_status==SUCCESS) { - zend_printf("No syntax errors detected in %s\n", file_handle.filename); - } else { - zend_printf("Errors parsing %s\n", file_handle.filename); - } - break; - case PHP_MODE_STRIP: - if (open_file_for_scanning(&file_handle TSRMLS_CC)==SUCCESS) { - zend_strip(TSRMLS_C); - fclose(file_handle.handle.fp); - } - return SUCCESS; - break; - case PHP_MODE_HIGHLIGHT: - { - zend_syntax_highlighter_ini syntax_highlighter_ini; - - if (open_file_for_scanning(&file_handle TSRMLS_CC)==SUCCESS) { - php_get_highlight_struct(&syntax_highlighter_ini); - zend_highlight(&syntax_highlighter_ini TSRMLS_CC); - fclose(file_handle.handle.fp); - } - return SUCCESS; - } - break; + SG(request_info).path_translated = estrdup(env_path_translated); + } + } + if (cgi || SG(request_info).path_translated) { + retval = php_fopen_primary_script(&file_handle TSRMLS_CC); + } + + if (cgi && (retval == FAILURE)) { + if(!argv0 || !(file_handle.handle.fp = VCWD_FOPEN(argv0, "rb"))) { + PUTS("No input file specified.\n"); + php_request_shutdown((void *) 0); + php_module_shutdown(TSRMLS_C); + return FAILURE; + } + file_handle.filename = argv0; + file_handle.opened_path = expand_filepath(argv0, NULL TSRMLS_CC); + } + + if (file_handle.handle.fp && (file_handle.handle.fp != stdin)) { + /* #!php support */ + c = fgetc(file_handle.handle.fp); + if (c == '#') { + while (c != 10 && c != 13) { + c = fgetc(file_handle.handle.fp); /* skip to end of line */ + } + CG(zend_lineno)++; + } else { + rewind(file_handle.handle.fp); + } + } + + switch (behavior) { + case PHP_MODE_STANDARD: + if (php_execute_script(&file_handle TSRMLS_CC)) { + exit_status = EG(exit_status); + } else { + exit_status = 255; + } + break; + case PHP_MODE_LINT: + PG(during_request_startup) = 0; + exit_status = php_lint_script(&file_handle TSRMLS_CC); + if (exit_status==SUCCESS) { + zend_printf("No syntax errors detected in %s\n", file_handle.filename); + } else { + zend_printf("Errors parsing %s\n", file_handle.filename); + } + break; + case PHP_MODE_STRIP: + if (open_file_for_scanning(&file_handle TSRMLS_CC)==SUCCESS) { + zend_strip(TSRMLS_C); + fclose(file_handle.handle.fp); + } + return SUCCESS; + break; + case PHP_MODE_HIGHLIGHT: + { + zend_syntax_highlighter_ini syntax_highlighter_ini; + + if (open_file_for_scanning(&file_handle TSRMLS_CC)==SUCCESS) { + php_get_highlight_struct(&syntax_highlighter_ini); + zend_highlight(&syntax_highlighter_ini TSRMLS_CC); + fclose(file_handle.handle.fp); + } + return SUCCESS; + } + break; #if 0 - /* Zeev might want to do something with this one day */ - case PHP_MODE_INDENT: - open_file_for_scanning(&file_handle TSRMLS_CC); - zend_indent(); - fclose(file_handle.handle.fp); - return SUCCESS; - break; + /* Zeev might want to do something with this one day */ + case PHP_MODE_INDENT: + open_file_for_scanning(&file_handle TSRMLS_CC); + zend_indent(); + fclose(file_handle.handle.fp); + return SUCCESS; + break; #endif - } + } - if (SG(request_info).path_translated) { - persist_alloc(SG(request_info).path_translated); - } + if (SG(request_info).path_translated) { + persist_alloc(SG(request_info).path_translated); + } - php_request_shutdown((void *) 0); + php_request_shutdown((void *) 0); - STR_FREE(SG(request_info).path_translated); + STR_FREE(SG(request_info).path_translated); #ifdef PHP_FASTCGI - if (!fastcgi) break; - /* only fastcgi will get here */ - - /* TODO: We should free our environment here, but - * some platforms are unhappy if they've altered our - * existing environment and we then free() the new - * environ pointer - */ - - requests++; - if( max_requests && ( requests == max_requests )) { - FCGX_Finish(); - break; - } - /* end of fastcgi loop */ - } + if (!fastcgi) break; + /* only fastcgi will get here */ + + /* TODO: We should free our environment here, but + * some platforms are unhappy if they've altered our + * existing environment and we then free() the new + * environ pointer + */ + + requests++; + if( max_requests && ( requests == max_requests )) { + FCGX_Finish(); + break; + } + /* end of fastcgi loop */ + } #endif - if (cgi_sapi_module.php_ini_path_override) { - free(cgi_sapi_module.php_ini_path_override); - } - } zend_catch { - exit_status = 255; - } zend_end_try(); + if (cgi_sapi_module.php_ini_path_override) { + free(cgi_sapi_module.php_ini_path_override); + } + } zend_catch { + exit_status = 255; + } zend_end_try(); - php_module_shutdown(TSRMLS_C); + php_module_shutdown(TSRMLS_C); #ifdef ZTS - tsrm_shutdown(); + tsrm_shutdown(); #endif - return exit_status; + return exit_status; } /* }}} */ |