1999-07-16 13:13:16 +00:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
2004-01-08 08:18:22 +00:00
|
|
|
| PHP Version 5 |
|
1999-07-16 13:13:16 +00:00
|
|
|
+----------------------------------------------------------------------+
|
2007-01-01 09:36:18 +00:00
|
|
|
| Copyright (c) 1997-2007 The PHP Group |
|
1999-07-16 13:13:16 +00:00
|
|
|
+----------------------------------------------------------------------+
|
2006-01-01 12:51:34 +00:00
|
|
|
| This source file is subject to version 3.01 of the PHP license, |
|
1999-07-16 13:13:16 +00:00
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
2003-06-10 20:04:29 +00:00
|
|
|
| available through the world-wide-web at the following url: |
|
2006-01-01 12:51:34 +00:00
|
|
|
| http://www.php.net/license/3_01.txt |
|
1999-07-16 13:13:16 +00:00
|
|
|
| If you did not receive a copy of the PHP license and are unable to |
|
|
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
|
|
| license@php.net so we can mail you a copy immediately. |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
|
2003-03-18 12:06:09 +00:00
|
|
|
| Stig Bakken <ssb@php.net> |
|
1999-07-16 13:13:16 +00:00
|
|
|
| Zeev Suraski <zeev@zend.com> |
|
2002-03-10 22:08:09 +00:00
|
|
|
| FastCGI: Ben Mansell <php@slimyhorror.com> |
|
|
|
|
| Shane Caraveo <shane@caraveo.com> |
|
2006-05-15 14:30:31 +00:00
|
|
|
| Dmitry Stogov <dmitry@zend.com> |
|
1999-07-16 13:13:16 +00:00
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
|
2003-02-14 14:38:20 +00:00
|
|
|
/* $Id$ */
|
1999-07-16 13:13:16 +00:00
|
|
|
|
1999-04-25 19:36:57 +00:00
|
|
|
#include "php.h"
|
|
|
|
#include "php_globals.h"
|
2000-01-28 17:24:53 +00:00
|
|
|
#include "php_variables.h"
|
2001-02-26 18:14:50 +00:00
|
|
|
#include "zend_modules.h"
|
1999-04-25 19:36:57 +00:00
|
|
|
|
|
|
|
#include "SAPI.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "php.h"
|
2000-02-11 15:59:30 +00:00
|
|
|
#ifdef PHP_WIN32
|
1999-04-25 19:36:57 +00:00
|
|
|
#include "win32/time.h"
|
|
|
|
#include "win32/signal.h"
|
|
|
|
#include <process.h>
|
|
|
|
#endif
|
|
|
|
#if HAVE_SYS_TIME_H
|
|
|
|
#include <sys/time.h>
|
|
|
|
#endif
|
|
|
|
#if HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
#if HAVE_SIGNAL_H
|
|
|
|
#include <signal.h>
|
|
|
|
#endif
|
|
|
|
#if HAVE_SETLOCALE
|
|
|
|
#include <locale.h>
|
|
|
|
#endif
|
2004-02-10 17:44:31 +00:00
|
|
|
#if HAVE_SYS_TYPES_H
|
|
|
|
#include <sys/types.h>
|
|
|
|
#endif
|
|
|
|
#if HAVE_SYS_WAIT_H
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#endif
|
1999-04-25 19:36:57 +00:00
|
|
|
#include "zend.h"
|
2000-05-05 07:18:50 +00:00
|
|
|
#include "zend_extensions.h"
|
1999-04-25 19:36:57 +00:00
|
|
|
#include "php_ini.h"
|
|
|
|
#include "php_globals.h"
|
2000-06-05 23:24:42 +00:00
|
|
|
#include "php_main.h"
|
2001-02-23 22:07:16 +00:00
|
|
|
#include "fopen_wrappers.h"
|
1999-12-04 19:19:57 +00:00
|
|
|
#include "ext/standard/php_standard.h"
|
2000-04-20 13:23:19 +00:00
|
|
|
#ifdef PHP_WIN32
|
1999-04-25 19:36:57 +00:00
|
|
|
#include <io.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include "win32/php_registry.h"
|
|
|
|
#endif
|
|
|
|
|
2001-11-04 12:46:30 +00:00
|
|
|
#ifdef __riscos__
|
|
|
|
#include <unixlib/local.h>
|
2006-03-07 22:37:53 +00:00
|
|
|
int __riscosify_control = __RISCOSIFY_STRICT_UNIX_SPECS;
|
2001-11-04 12:46:30 +00:00
|
|
|
#endif
|
|
|
|
|
1999-04-25 19:36:57 +00:00
|
|
|
#include "zend_compile.h"
|
|
|
|
#include "zend_execute.h"
|
|
|
|
#include "zend_highlight.h"
|
|
|
|
#include "zend_indent.h"
|
|
|
|
|
1999-05-29 13:53:59 +00:00
|
|
|
#include "php_getopt.h"
|
1999-04-25 19:36:57 +00:00
|
|
|
|
2002-11-26 05:51:16 +00:00
|
|
|
#if PHP_FASTCGI
|
2006-02-02 08:17:23 +00:00
|
|
|
#include "fastcgi.h"
|
2006-05-15 14:30:31 +00:00
|
|
|
|
|
|
|
#ifndef PHP_WIN32
|
2003-01-07 16:33:28 +00:00
|
|
|
/* XXX this will need to change later when threaded fastcgi is
|
2002-11-26 05:51:16 +00:00
|
|
|
implemented. shane */
|
|
|
|
struct sigaction act, old_term, old_quit, old_int;
|
2002-10-13 09:40:44 +00:00
|
|
|
#endif
|
2002-03-18 04:48:34 +00:00
|
|
|
|
2002-10-13 09:40:44 +00:00
|
|
|
static void (*php_php_import_environment_variables)(zval *array_ptr TSRMLS_DC);
|
2002-03-10 21:39:28 +00:00
|
|
|
|
2002-10-13 09:40:44 +00:00
|
|
|
#ifndef PHP_WIN32
|
|
|
|
/* these globals used for forking children on unix systems */
|
2002-03-10 21:39:28 +00:00
|
|
|
/**
|
|
|
|
* Number of child processes that will get created to service requests
|
|
|
|
*/
|
2004-07-05 11:41:31 +00:00
|
|
|
static int children = 0;
|
2002-03-10 21:39:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set to non-zero if we are the parent process
|
|
|
|
*/
|
|
|
|
static int parent = 1;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process group
|
|
|
|
*/
|
|
|
|
static pid_t pgroup;
|
2002-10-13 09:40:44 +00:00
|
|
|
#endif
|
2002-03-10 21:39:28 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2002-05-09 20:03:36 +00:00
|
|
|
#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
|
1999-04-25 19:36:57 +00:00
|
|
|
|
2004-02-11 21:00:46 +00:00
|
|
|
static char *php_optarg = NULL;
|
|
|
|
static int php_optind = 1;
|
2003-02-16 01:23:11 +00:00
|
|
|
|
|
|
|
static const opt_struct OPTIONS[] = {
|
|
|
|
{'a', 0, "interactive"},
|
2003-06-29 20:45:38 +00:00
|
|
|
#ifndef PHP_WIN32
|
|
|
|
{'b', 1, "bindpath"},
|
|
|
|
#endif
|
2003-02-16 01:23:11 +00:00
|
|
|
{'C', 0, "no-chdir"},
|
|
|
|
{'c', 1, "php-ini"},
|
|
|
|
{'d', 1, "define"},
|
|
|
|
{'e', 0, "profile-info"},
|
|
|
|
{'f', 1, "file"},
|
|
|
|
{'h', 0, "help"},
|
|
|
|
{'i', 0, "info"},
|
|
|
|
{'l', 0, "syntax-check"},
|
|
|
|
{'m', 0, "modules"},
|
|
|
|
{'n', 0, "no-php-ini"},
|
|
|
|
{'q', 0, "no-header"},
|
|
|
|
{'s', 0, "syntax-highlight"},
|
|
|
|
{'s', 0, "syntax-highlighting"},
|
|
|
|
{'w', 0, "strip"},
|
|
|
|
{'?', 0, "usage"},/* help alias (both '?' and 'usage') */
|
|
|
|
{'v', 0, "version"},
|
|
|
|
{'z', 1, "zend-extension"},
|
|
|
|
{'-', 0, NULL} /* end of args */
|
|
|
|
};
|
1999-04-25 19:36:57 +00:00
|
|
|
|
2006-11-14 10:31:47 +00:00
|
|
|
typedef struct _php_cgi_globals_struct {
|
|
|
|
zend_bool rfc2616_headers;
|
|
|
|
zend_bool nph;
|
|
|
|
zend_bool check_shebang_line;
|
2002-12-01 21:37:14 +00:00
|
|
|
#if ENABLE_PATHINFO_CHECK
|
2006-11-14 10:31:47 +00:00
|
|
|
zend_bool fix_pathinfo;
|
|
|
|
#endif
|
|
|
|
#if FORCE_CGI_REDIRECT
|
|
|
|
zend_bool force_redirect;
|
|
|
|
char *redirect_status_env;
|
2002-12-01 21:37:14 +00:00
|
|
|
#endif
|
2006-03-17 09:32:30 +00:00
|
|
|
#if PHP_FASTCGI
|
2006-11-14 10:31:47 +00:00
|
|
|
zend_bool fcgi_logging;
|
|
|
|
# ifdef PHP_WIN32
|
|
|
|
zend_bool impersonate;
|
|
|
|
# endif
|
2006-03-17 09:32:30 +00:00
|
|
|
#endif
|
2006-11-14 10:31:47 +00:00
|
|
|
} php_cgi_globals_struct;
|
2006-03-17 09:32:30 +00:00
|
|
|
|
2006-11-14 10:31:47 +00:00
|
|
|
#ifdef ZTS
|
|
|
|
static int php_cgi_globals_id;
|
|
|
|
#define CGIG(v) TSRMG(php_cgi_globals_id, php_cgi_globals_struct *, v)
|
|
|
|
#else
|
|
|
|
static php_cgi_globals_struct php_cgi_globals;
|
|
|
|
#define CGIG(v) (php_cgi_globals.v)
|
|
|
|
#endif
|
2006-03-17 09:32:30 +00:00
|
|
|
|
2002-12-01 21:37:14 +00:00
|
|
|
#ifdef PHP_WIN32
|
|
|
|
#define TRANSLATE_SLASHES(path) \
|
|
|
|
{ \
|
|
|
|
char *tmp = path; \
|
|
|
|
while (*tmp) { \
|
|
|
|
if (*tmp == '\\') *tmp = '/'; \
|
|
|
|
tmp++; \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define TRANSLATE_SLASHES(path)
|
|
|
|
#endif
|
|
|
|
|
2002-11-14 20:32:28 +00:00
|
|
|
static int print_module_info(zend_module_entry *module, void *arg TSRMLS_DC)
|
2001-07-31 04:53:54 +00:00
|
|
|
{
|
2002-05-09 20:03:36 +00:00
|
|
|
php_printf("%s\n", module->name);
|
|
|
|
return 0;
|
2000-10-26 22:31:06 +00:00
|
|
|
}
|
1999-04-25 19:36:57 +00:00
|
|
|
|
2002-11-14 20:32:28 +00:00
|
|
|
static int module_name_cmp(const void *a, const void *b TSRMLS_DC)
|
2002-01-18 20:27:09 +00:00
|
|
|
{
|
2002-11-14 20:32:28 +00:00
|
|
|
Bucket *f = *((Bucket **) a);
|
|
|
|
Bucket *s = *((Bucket **) b);
|
|
|
|
|
2004-07-14 22:30:29 +00:00
|
|
|
return strcasecmp(((zend_module_entry *)f->pData)->name,
|
2005-06-03 23:11:51 +00:00
|
|
|
((zend_module_entry *)s->pData)->name);
|
2002-11-14 20:32:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void print_modules(TSRMLS_D)
|
|
|
|
{
|
|
|
|
HashTable sorted_registry;
|
|
|
|
zend_module_entry tmp;
|
|
|
|
|
|
|
|
zend_hash_init(&sorted_registry, 50, NULL, NULL, 1);
|
|
|
|
zend_hash_copy(&sorted_registry, &module_registry, NULL, &tmp, sizeof(zend_module_entry));
|
|
|
|
zend_hash_sort(&sorted_registry, zend_qsort, module_name_cmp, 0 TSRMLS_CC);
|
|
|
|
zend_hash_apply_with_argument(&sorted_registry, (apply_func_arg_t) print_module_info, NULL TSRMLS_CC);
|
|
|
|
zend_hash_destroy(&sorted_registry);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int print_extension_info(zend_extension *ext, void *arg TSRMLS_DC)
|
|
|
|
{
|
|
|
|
php_printf("%s\n", ext->name);
|
2002-05-09 20:03:36 +00:00
|
|
|
return 0;
|
2002-01-18 20:27:09 +00:00
|
|
|
}
|
|
|
|
|
2002-11-15 00:31:10 +00:00
|
|
|
static int extension_name_cmp(const zend_llist_element **f,
|
|
|
|
const zend_llist_element **s TSRMLS_DC)
|
2002-11-14 20:32:28 +00:00
|
|
|
{
|
2002-11-15 00:32:42 +00:00
|
|
|
return strcmp(((zend_extension *)(*f)->data)->name,
|
|
|
|
((zend_extension *)(*s)->data)->name);
|
2002-11-14 20:32:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void print_extensions(TSRMLS_D)
|
|
|
|
{
|
|
|
|
zend_llist sorted_exts;
|
|
|
|
|
|
|
|
zend_llist_copy(&sorted_exts, &zend_extensions);
|
|
|
|
zend_llist_sort(&sorted_exts, extension_name_cmp TSRMLS_CC);
|
|
|
|
zend_llist_apply_with_argument(&sorted_exts, (llist_apply_with_arg_func_t) print_extension_info, NULL TSRMLS_CC);
|
|
|
|
zend_llist_destroy(&sorted_exts);
|
|
|
|
}
|
|
|
|
|
2001-05-19 14:30:33 +00:00
|
|
|
#ifndef STDOUT_FILENO
|
|
|
|
#define STDOUT_FILENO 1
|
|
|
|
#endif
|
|
|
|
|
2002-10-13 09:40:44 +00:00
|
|
|
static inline size_t sapi_cgibin_single_write(const char *str, uint str_length TSRMLS_DC)
|
2001-05-19 14:30:33 +00:00
|
|
|
{
|
|
|
|
#ifdef PHP_WRITE_STDOUT
|
2002-05-09 20:03:36 +00:00
|
|
|
long ret;
|
2002-03-10 21:39:28 +00:00
|
|
|
#else
|
2002-05-09 20:03:36 +00:00
|
|
|
size_t ret;
|
2002-03-10 21:39:28 +00:00
|
|
|
#endif
|
2001-05-19 14:30:33 +00:00
|
|
|
|
2002-11-26 05:51:16 +00:00
|
|
|
#if PHP_FASTCGI
|
2006-05-15 14:30:31 +00:00
|
|
|
if (fcgi_is_fastcgi()) {
|
|
|
|
fcgi_request *request = (fcgi_request*) SG(server_context);
|
|
|
|
long ret = fcgi_write(request, FCGI_STDOUT, str, str_length);
|
2002-10-13 09:40:44 +00:00
|
|
|
if (ret <= 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return ret;
|
2002-05-09 20:03:36 +00:00
|
|
|
}
|
2002-03-10 21:39:28 +00:00
|
|
|
#endif
|
|
|
|
#ifdef PHP_WRITE_STDOUT
|
2002-05-09 20:03:36 +00:00
|
|
|
ret = write(STDOUT_FILENO, str, str_length);
|
|
|
|
if (ret <= 0) return 0;
|
|
|
|
return ret;
|
2001-05-19 14:30:33 +00:00
|
|
|
#else
|
2002-05-09 20:03:36 +00:00
|
|
|
ret = fwrite(str, 1, MIN(str_length, 16384), stdout);
|
|
|
|
return ret;
|
2001-05-19 14:30:33 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2001-08-05 15:29:47 +00:00
|
|
|
static int sapi_cgibin_ub_write(const char *str, uint str_length TSRMLS_DC)
|
1999-04-25 19:36:57 +00:00
|
|
|
{
|
2002-05-09 20:03:36 +00:00
|
|
|
const char *ptr = str;
|
|
|
|
uint remaining = str_length;
|
|
|
|
size_t ret;
|
|
|
|
|
2003-03-29 16:13:51 +00:00
|
|
|
while (remaining > 0) {
|
2002-10-13 09:40:44 +00:00
|
|
|
ret = sapi_cgibin_single_write(ptr, remaining TSRMLS_CC);
|
2002-05-09 20:03:36 +00:00
|
|
|
if (!ret) {
|
|
|
|
php_handle_aborted_connection();
|
2003-03-07 14:48:28 +00:00
|
|
|
return str_length - remaining;
|
2002-05-09 20:03:36 +00:00
|
|
|
}
|
|
|
|
ptr += ret;
|
|
|
|
remaining -= ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return str_length;
|
1999-04-25 19:36:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-01-13 17:37:25 +00:00
|
|
|
static void sapi_cgibin_flush(void *server_context)
|
|
|
|
{
|
2002-11-26 05:51:16 +00:00
|
|
|
#if PHP_FASTCGI
|
2006-05-15 14:30:31 +00:00
|
|
|
if (fcgi_is_fastcgi()) {
|
|
|
|
fcgi_request *request = (fcgi_request*) server_context;
|
2004-02-10 17:44:31 +00:00
|
|
|
if (
|
2004-02-11 14:52:12 +00:00
|
|
|
#ifndef PHP_WIN32
|
2004-02-10 17:44:31 +00:00
|
|
|
!parent &&
|
|
|
|
#endif
|
2006-05-24 09:42:21 +00:00
|
|
|
request && !fcgi_flush(request, 0)) {
|
2002-05-09 20:03:36 +00:00
|
|
|
php_handle_aborted_connection();
|
|
|
|
}
|
2003-03-29 16:13:51 +00:00
|
|
|
return;
|
|
|
|
}
|
2002-03-10 21:39:28 +00:00
|
|
|
#endif
|
2005-06-03 23:11:51 +00:00
|
|
|
if (fflush(stdout) == EOF) {
|
2002-05-09 20:03:36 +00:00
|
|
|
php_handle_aborted_connection();
|
|
|
|
}
|
2000-01-13 17:37:25 +00:00
|
|
|
}
|
|
|
|
|
2002-11-22 15:47:39 +00:00
|
|
|
#define SAPI_CGI_MAX_HEADER_LENGTH 1024
|
2000-01-13 17:37:25 +00:00
|
|
|
|
2002-07-03 11:44:48 +00:00
|
|
|
static int sapi_cgi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC)
|
1999-05-05 21:05:44 +00:00
|
|
|
{
|
2002-11-22 15:47:39 +00:00
|
|
|
char buf[SAPI_CGI_MAX_HEADER_LENGTH];
|
2002-07-03 11:44:48 +00:00
|
|
|
sapi_header_struct *h;
|
|
|
|
zend_llist_position pos;
|
2002-11-22 10:15:47 +00:00
|
|
|
|
2005-06-03 23:11:51 +00:00
|
|
|
if (SG(request_info).no_headers == 1) {
|
2002-12-25 20:38:37 +00:00
|
|
|
return SAPI_HEADER_SENT_SUCCESSFULLY;
|
|
|
|
}
|
2004-02-10 00:02:38 +00:00
|
|
|
|
2006-11-14 10:31:47 +00:00
|
|
|
if (CGIG(nph) || SG(sapi_headers).http_response_code != 200)
|
2005-06-03 23:11:51 +00:00
|
|
|
{
|
2002-11-22 13:55:27 +00:00
|
|
|
int len;
|
2003-01-07 16:33:28 +00:00
|
|
|
|
2006-11-14 10:31:47 +00:00
|
|
|
if (CGIG(rfc2616_headers) && SG(sapi_headers).http_status_line) {
|
2003-01-07 16:33:28 +00:00
|
|
|
len = snprintf(buf, SAPI_CGI_MAX_HEADER_LENGTH,
|
2002-11-22 15:47:39 +00:00
|
|
|
"%s\r\n", SG(sapi_headers).http_status_line);
|
|
|
|
|
|
|
|
if (len > SAPI_CGI_MAX_HEADER_LENGTH) {
|
|
|
|
len = SAPI_CGI_MAX_HEADER_LENGTH;
|
|
|
|
}
|
|
|
|
|
2002-11-22 13:55:27 +00:00
|
|
|
} else {
|
|
|
|
len = sprintf(buf, "Status: %d\r\n", SG(sapi_headers).http_response_code);
|
|
|
|
}
|
2002-11-22 10:15:47 +00:00
|
|
|
|
2002-11-22 13:55:27 +00:00
|
|
|
PHPWRITE_H(buf, len);
|
|
|
|
}
|
2002-07-03 11:44:48 +00:00
|
|
|
|
2006-06-13 14:22:46 +00:00
|
|
|
h = (sapi_header_struct*)zend_llist_get_first_ex(&sapi_headers->headers, &pos);
|
2005-06-03 23:11:51 +00:00
|
|
|
while (h) {
|
2005-11-02 14:38:13 +00:00
|
|
|
/* prevent CRLFCRLF */
|
|
|
|
if (h->header_len) {
|
|
|
|
PHPWRITE_H(h->header, h->header_len);
|
|
|
|
PHPWRITE_H("\r\n", 2);
|
|
|
|
}
|
2006-06-13 14:22:46 +00:00
|
|
|
h = (sapi_header_struct*)zend_llist_get_next_ex(&sapi_headers->headers, &pos);
|
2002-05-09 20:03:36 +00:00
|
|
|
}
|
2002-07-03 11:46:37 +00:00
|
|
|
PHPWRITE_H("\r\n", 2);
|
2002-07-03 11:44:48 +00:00
|
|
|
|
|
|
|
return SAPI_HEADER_SENT_SUCCESSFULLY;
|
1999-05-05 21:05:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-28 11:36:37 +00:00
|
|
|
static int sapi_cgi_read_post(char *buffer, uint count_bytes TSRMLS_DC)
|
1999-05-09 08:48:05 +00:00
|
|
|
{
|
2002-05-09 20:03:36 +00:00
|
|
|
uint read_bytes=0, tmp_read_bytes;
|
2002-11-26 05:51:16 +00:00
|
|
|
#if PHP_FASTCGI
|
2002-05-09 20:03:36 +00:00
|
|
|
char *pos = buffer;
|
2002-03-10 21:39:28 +00:00
|
|
|
#endif
|
1999-05-09 08:48:05 +00:00
|
|
|
|
2005-06-03 23:11:51 +00:00
|
|
|
count_bytes = MIN(count_bytes, (uint) SG(request_info).content_length - SG(read_post_bytes));
|
2002-05-09 20:03:36 +00:00
|
|
|
while (read_bytes < count_bytes) {
|
2002-11-26 05:51:16 +00:00
|
|
|
#if PHP_FASTCGI
|
2006-05-15 14:30:31 +00:00
|
|
|
if (fcgi_is_fastcgi()) {
|
|
|
|
fcgi_request *request = (fcgi_request*) SG(server_context);
|
|
|
|
tmp_read_bytes = fcgi_read(request, pos, count_bytes - read_bytes);
|
2002-05-09 20:03:36 +00:00
|
|
|
pos += tmp_read_bytes;
|
2003-03-29 16:13:51 +00:00
|
|
|
} else {
|
2005-06-03 23:11:51 +00:00
|
|
|
tmp_read_bytes = read(0, buffer + read_bytes, count_bytes - read_bytes);
|
2003-03-29 16:13:51 +00:00
|
|
|
}
|
2003-03-29 16:18:04 +00:00
|
|
|
#else
|
2005-06-03 23:11:51 +00:00
|
|
|
tmp_read_bytes = read(0, buffer + read_bytes, count_bytes - read_bytes);
|
2003-03-29 16:18:04 +00:00
|
|
|
#endif
|
2002-05-09 20:03:36 +00:00
|
|
|
|
2005-06-03 23:11:51 +00:00
|
|
|
if (tmp_read_bytes <= 0) {
|
2002-05-09 20:03:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
read_bytes += tmp_read_bytes;
|
|
|
|
}
|
|
|
|
return read_bytes;
|
1999-05-09 08:48:05 +00:00
|
|
|
}
|
|
|
|
|
2002-10-13 09:40:44 +00:00
|
|
|
static char *sapi_cgibin_getenv(char *name, size_t name_len TSRMLS_DC)
|
|
|
|
{
|
2002-11-26 05:51:16 +00:00
|
|
|
#if PHP_FASTCGI
|
2002-10-13 09:40:44 +00:00
|
|
|
/* when php is started by mod_fastcgi, no regular environment
|
|
|
|
is provided to PHP. It is always sent to PHP at the start
|
|
|
|
of a request. So we have to do our own lookup to get env
|
|
|
|
vars. This could probably be faster somehow. */
|
2006-05-15 14:30:31 +00:00
|
|
|
if (fcgi_is_fastcgi()) {
|
|
|
|
fcgi_request *request = (fcgi_request*) SG(server_context);
|
|
|
|
return fcgi_getenv(request, name, name_len);
|
2002-10-13 09:40:44 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
/* if cgi, or fastcgi and not found in fcgi env
|
|
|
|
check the regular environment */
|
|
|
|
return getenv(name);
|
|
|
|
}
|
1999-05-09 08:48:05 +00:00
|
|
|
|
2003-01-25 22:01:53 +00:00
|
|
|
static char *_sapi_cgibin_putenv(char *name, char *value TSRMLS_DC)
|
2002-12-01 21:37:14 +00:00
|
|
|
{
|
2006-05-15 14:30:31 +00:00
|
|
|
int name_len;
|
2006-06-19 11:39:02 +00:00
|
|
|
#if !HAVE_SETENV || !HAVE_UNSETENV
|
2006-05-15 14:30:31 +00:00
|
|
|
int len;
|
|
|
|
char *buf;
|
2006-06-19 11:39:02 +00:00
|
|
|
#endif
|
|
|
|
|
2003-03-29 16:13:51 +00:00
|
|
|
if (!name) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2006-05-15 14:30:31 +00:00
|
|
|
name_len = strlen(name);
|
|
|
|
|
2002-12-01 21:37:14 +00:00
|
|
|
#if PHP_FASTCGI
|
|
|
|
/* when php is started by mod_fastcgi, no regular environment
|
|
|
|
is provided to PHP. It is always sent to PHP at the start
|
|
|
|
of a request. So we have to do our own lookup to get env
|
|
|
|
vars. This could probably be faster somehow. */
|
2006-05-15 14:30:31 +00:00
|
|
|
if (fcgi_is_fastcgi()) {
|
|
|
|
fcgi_request *request = (fcgi_request*) SG(server_context);
|
|
|
|
return fcgi_putenv(request, name, name_len, value);
|
2002-12-01 21:37:14 +00:00
|
|
|
}
|
|
|
|
#endif
|
2006-06-17 11:08:05 +00:00
|
|
|
#if HAVE_SETENV
|
|
|
|
if (value) {
|
|
|
|
setenv(name, value, 1);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if HAVE_UNSETENV
|
|
|
|
if (!value) {
|
|
|
|
unsetenv(name);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !HAVE_SETENV || !HAVE_UNSETENV
|
2002-12-01 21:37:14 +00:00
|
|
|
/* if cgi, or fastcgi and not found in fcgi env
|
2003-01-25 22:01:53 +00:00
|
|
|
check the regular environment
|
|
|
|
this leaks, but it's only cgi anyway, we'll fix
|
|
|
|
it for 5.0
|
|
|
|
*/
|
2006-05-15 14:30:31 +00:00
|
|
|
len = name_len + (value ? strlen(value) : 0) + sizeof("=") + 2;
|
|
|
|
buf = (char *) malloc(len);
|
|
|
|
if (buf == NULL) {
|
|
|
|
return getenv(name);
|
|
|
|
}
|
2006-06-17 11:08:05 +00:00
|
|
|
#endif
|
|
|
|
#if !HAVE_SETENV
|
2006-05-15 14:30:31 +00:00
|
|
|
if (value) {
|
|
|
|
len = snprintf(buf, len - 1, "%s=%s", name, value);
|
2006-06-17 11:08:05 +00:00
|
|
|
putenv(buf);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if !HAVE_UNSETENV
|
|
|
|
if (!value) {
|
2006-05-15 14:30:31 +00:00
|
|
|
len = snprintf(buf, len - 1, "%s=", name);
|
2006-06-17 11:08:05 +00:00
|
|
|
putenv(buf);
|
2006-05-15 14:30:31 +00:00
|
|
|
}
|
2006-06-17 11:08:05 +00:00
|
|
|
#endif
|
2003-01-25 22:01:53 +00:00
|
|
|
return getenv(name);
|
2002-12-01 21:37:14 +00:00
|
|
|
}
|
|
|
|
|
2001-07-28 11:36:37 +00:00
|
|
|
static char *sapi_cgi_read_cookies(TSRMLS_D)
|
1999-05-09 08:48:05 +00:00
|
|
|
{
|
2006-05-15 14:30:31 +00:00
|
|
|
return sapi_cgibin_getenv((char *) "HTTP_COOKIE", sizeof("HTTP_COOKIE")-1 TSRMLS_CC);
|
1999-05-09 08:48:05 +00:00
|
|
|
}
|
|
|
|
|
2002-11-26 05:51:16 +00:00
|
|
|
#if PHP_FASTCGI
|
2002-10-13 09:40:44 +00:00
|
|
|
void cgi_php_import_environment_variables(zval *array_ptr TSRMLS_DC)
|
|
|
|
{
|
2006-04-07 13:45:23 +00:00
|
|
|
if (PG(http_globals)[TRACK_VARS_ENV] &&
|
2006-05-24 07:55:19 +00:00
|
|
|
array_ptr != PG(http_globals)[TRACK_VARS_ENV] &&
|
|
|
|
Z_TYPE_P(PG(http_globals)[TRACK_VARS_ENV]) == IS_ARRAY &&
|
|
|
|
zend_hash_num_elements(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_ENV])) > 0) {
|
2006-04-18 06:58:43 +00:00
|
|
|
zval_dtor(array_ptr);
|
2006-04-07 13:45:23 +00:00
|
|
|
*array_ptr = *PG(http_globals)[TRACK_VARS_ENV];
|
2006-04-18 06:58:43 +00:00
|
|
|
INIT_PZVAL(array_ptr);
|
2006-04-07 13:45:23 +00:00
|
|
|
zval_copy_ctor(array_ptr);
|
|
|
|
return;
|
|
|
|
} else if (PG(http_globals)[TRACK_VARS_SERVER] &&
|
2006-05-24 07:55:19 +00:00
|
|
|
array_ptr != PG(http_globals)[TRACK_VARS_SERVER] &&
|
|
|
|
Z_TYPE_P(PG(http_globals)[TRACK_VARS_SERVER]) == IS_ARRAY &&
|
|
|
|
zend_hash_num_elements(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER])) > 0) {
|
2006-04-18 06:58:43 +00:00
|
|
|
zval_dtor(array_ptr);
|
2006-04-07 13:45:23 +00:00
|
|
|
*array_ptr = *PG(http_globals)[TRACK_VARS_SERVER];
|
2006-04-18 06:58:43 +00:00
|
|
|
INIT_PZVAL(array_ptr);
|
2006-04-07 13:45:23 +00:00
|
|
|
zval_copy_ctor(array_ptr);
|
|
|
|
return;
|
|
|
|
}
|
2006-08-31 13:11:58 +00:00
|
|
|
|
|
|
|
/* call php's original import as a catch-all */
|
|
|
|
php_php_import_environment_variables(array_ptr TSRMLS_CC);
|
|
|
|
|
2006-05-15 14:30:31 +00:00
|
|
|
if (fcgi_is_fastcgi()) {
|
|
|
|
fcgi_request *request = (fcgi_request*) SG(server_context);
|
|
|
|
HashPosition pos;
|
2003-03-23 20:16:41 +00:00
|
|
|
int magic_quotes_gpc = PG(magic_quotes_gpc);
|
2006-05-15 14:30:31 +00:00
|
|
|
char *var, **val;
|
|
|
|
uint var_len;
|
|
|
|
ulong idx;
|
2006-11-15 11:13:02 +00:00
|
|
|
int filter_arg = (array_ptr == PG(http_globals)[TRACK_VARS_ENV])?PARSE_ENV:PARSE_SERVER;
|
2002-10-13 09:40:44 +00:00
|
|
|
|
2005-06-03 23:11:51 +00:00
|
|
|
/* turn off magic_quotes while importing environment variables */
|
|
|
|
PG(magic_quotes_gpc) = 0;
|
2006-05-15 14:30:31 +00:00
|
|
|
for (zend_hash_internal_pointer_reset_ex(&request->env, &pos);
|
|
|
|
zend_hash_get_current_key_ex(&request->env, &var, &var_len, &idx, 0, &pos) == HASH_KEY_IS_STRING &&
|
|
|
|
zend_hash_get_current_data_ex(&request->env, (void **) &val, &pos) == SUCCESS;
|
|
|
|
zend_hash_move_forward_ex(&request->env, &pos)) {
|
2006-11-15 11:13:02 +00:00
|
|
|
unsigned int new_val_len;
|
|
|
|
if (sapi_module.input_filter(filter_arg, var, val, strlen(*val), &new_val_len TSRMLS_CC)) {
|
2006-11-03 16:40:52 +00:00
|
|
|
php_register_variable_safe(var, *val, new_val_len, array_ptr TSRMLS_CC);
|
2006-11-03 13:51:48 +00:00
|
|
|
}
|
2002-10-13 09:40:44 +00:00
|
|
|
}
|
2003-03-23 20:16:41 +00:00
|
|
|
PG(magic_quotes_gpc) = magic_quotes_gpc;
|
2002-10-13 09:40:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
1999-05-09 08:48:05 +00:00
|
|
|
|
2001-07-28 11:36:37 +00:00
|
|
|
static void sapi_cgi_register_variables(zval *track_vars_array TSRMLS_DC)
|
2000-01-28 17:24:53 +00:00
|
|
|
{
|
2006-11-15 11:13:02 +00:00
|
|
|
unsigned int new_val_len;
|
2006-11-03 13:51:48 +00:00
|
|
|
char *val = SG(request_info).request_uri ? SG(request_info).request_uri : "";
|
2002-05-09 20:03:36 +00:00
|
|
|
/* 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 */
|
2006-11-03 13:51:48 +00:00
|
|
|
if (sapi_module.input_filter(PARSE_SERVER, "PHP_SELF", &val, strlen(val), &new_val_len TSRMLS_CC)) {
|
|
|
|
php_register_variable_safe("PHP_SELF", val, new_val_len, track_vars_array TSRMLS_CC);
|
|
|
|
}
|
2000-01-28 17:24:53 +00:00
|
|
|
}
|
|
|
|
|
2000-02-10 15:55:10 +00:00
|
|
|
static void sapi_cgi_log_message(char *message)
|
|
|
|
{
|
2005-01-10 15:38:24 +00:00
|
|
|
#if PHP_FASTCGI
|
2006-11-14 10:31:47 +00:00
|
|
|
TSRMLS_FETCH();
|
|
|
|
|
|
|
|
if (fcgi_is_fastcgi() && CGIG(fcgi_logging)) {
|
2006-05-15 14:30:31 +00:00
|
|
|
fcgi_request *request;
|
2006-03-17 09:32:30 +00:00
|
|
|
|
2006-05-15 14:30:31 +00:00
|
|
|
request = (fcgi_request*) SG(server_context);
|
|
|
|
if (request) {
|
|
|
|
int len = strlen(message);
|
|
|
|
char *buf = malloc(len+2);
|
|
|
|
|
|
|
|
memcpy(buf, message, len);
|
|
|
|
memcpy(buf + len, "\n", sizeof("\n"));
|
|
|
|
fcgi_write(request, FCGI_STDERR, buf, len+1);
|
|
|
|
free(buf);
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "%s\n", message);
|
2005-06-16 14:54:51 +00:00
|
|
|
}
|
2005-01-10 15:38:24 +00:00
|
|
|
/* ignore return code */
|
|
|
|
} else
|
|
|
|
#endif /* PHP_FASTCGI */
|
2003-05-26 23:22:05 +00:00
|
|
|
fprintf(stderr, "%s\n", message);
|
2000-02-10 15:55:10 +00:00
|
|
|
}
|
|
|
|
|
2001-07-28 11:36:37 +00:00
|
|
|
static int sapi_cgi_deactivate(TSRMLS_D)
|
2000-02-10 16:44:59 +00:00
|
|
|
{
|
2004-05-06 15:23:53 +00:00
|
|
|
/* flush only when SAPI was started. The reasons are:
|
|
|
|
1. SAPI Deactivate is called from two places: module init and request shutdown
|
|
|
|
2. When the first call occurs and the request is not set up, flush fails on
|
|
|
|
FastCGI.
|
|
|
|
*/
|
2005-06-03 23:11:51 +00:00
|
|
|
if (SG(sapi_started)) {
|
2004-05-06 15:23:53 +00:00
|
|
|
sapi_cgibin_flush(SG(server_context));
|
|
|
|
}
|
2002-05-09 20:03:36 +00:00
|
|
|
return SUCCESS;
|
2000-02-10 16:44:59 +00:00
|
|
|
}
|
|
|
|
|
2002-09-18 21:57:42 +00:00
|
|
|
static int php_cgi_startup(sapi_module_struct *sapi_module)
|
|
|
|
{
|
2003-03-29 16:13:51 +00:00
|
|
|
if (php_module_startup(sapi_module, NULL, 0) == FAILURE) {
|
2002-09-18 21:57:42 +00:00
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-06 13:06:12 +00:00
|
|
|
/* {{{ sapi_module_struct cgi_sapi_module
|
|
|
|
*/
|
2001-01-02 22:49:31 +00:00
|
|
|
static sapi_module_struct cgi_sapi_module = {
|
2002-11-26 05:51:16 +00:00
|
|
|
#if PHP_FASTCGI
|
2002-10-13 09:40:44 +00:00
|
|
|
"cgi-fcgi", /* name */
|
2002-05-09 20:03:36 +00:00
|
|
|
"CGI/FastCGI", /* pretty name */
|
2002-03-10 21:39:28 +00:00
|
|
|
#else
|
2002-10-13 09:40:44 +00:00
|
|
|
"cgi", /* name */
|
2002-05-09 20:03:36 +00:00
|
|
|
"CGI", /* pretty name */
|
2002-03-10 21:39:28 +00:00
|
|
|
#endif
|
2003-01-07 16:33:28 +00:00
|
|
|
|
2002-09-18 21:57:42 +00:00
|
|
|
php_cgi_startup, /* startup */
|
2002-05-09 20:03:36 +00:00
|
|
|
php_module_shutdown_wrapper, /* shutdown */
|
1999-05-02 18:07:41 +00:00
|
|
|
|
2002-05-09 20:03:36 +00:00
|
|
|
NULL, /* activate */
|
|
|
|
sapi_cgi_deactivate, /* deactivate */
|
2000-02-10 16:44:59 +00:00
|
|
|
|
2002-05-09 20:03:36 +00:00
|
|
|
sapi_cgibin_ub_write, /* unbuffered write */
|
|
|
|
sapi_cgibin_flush, /* flush */
|
|
|
|
NULL, /* get uid */
|
2002-10-13 09:40:44 +00:00
|
|
|
sapi_cgibin_getenv, /* getenv */
|
1999-05-05 21:05:44 +00:00
|
|
|
|
2002-05-09 20:03:36 +00:00
|
|
|
php_error, /* error handler */
|
1999-05-06 21:58:49 +00:00
|
|
|
|
2002-05-09 20:03:36 +00:00
|
|
|
NULL, /* header handler */
|
2002-07-03 11:44:48 +00:00
|
|
|
sapi_cgi_send_headers, /* send headers handler */
|
|
|
|
NULL, /* send header handler */
|
1999-05-09 08:48:05 +00:00
|
|
|
|
2002-05-09 20:03:36 +00:00
|
|
|
sapi_cgi_read_post, /* read POST data */
|
|
|
|
sapi_cgi_read_cookies, /* read Cookies */
|
1999-09-16 23:18:15 +00:00
|
|
|
|
2002-05-09 20:03:36 +00:00
|
|
|
sapi_cgi_register_variables, /* register server variables */
|
|
|
|
sapi_cgi_log_message, /* Log message */
|
2004-12-20 19:33:41 +00:00
|
|
|
NULL, /* Get request time */
|
2000-01-28 17:24:53 +00:00
|
|
|
|
2002-05-09 20:03:36 +00:00
|
|
|
STANDARD_SAPI_MODULE_PROPERTIES
|
1999-04-25 19:36:57 +00:00
|
|
|
};
|
2001-06-06 13:06:12 +00:00
|
|
|
/* }}} */
|
1999-04-25 19:36:57 +00:00
|
|
|
|
2001-06-06 13:06:12 +00:00
|
|
|
/* {{{ php_cgi_usage
|
|
|
|
*/
|
1999-04-26 14:00:49 +00:00
|
|
|
static void php_cgi_usage(char *argv0)
|
|
|
|
{
|
2002-05-09 20:03:36 +00:00
|
|
|
char *prog;
|
|
|
|
|
|
|
|
prog = strrchr(argv0, '/');
|
|
|
|
if (prog) {
|
|
|
|
prog++;
|
|
|
|
} else {
|
|
|
|
prog = "php";
|
|
|
|
}
|
|
|
|
|
2003-02-16 01:23:11 +00:00
|
|
|
php_printf("Usage: %s [-q] [-h] [-s] [-v] [-i] [-f <file>]\n"
|
2002-10-25 09:28:55 +00:00
|
|
|
" %s <file> [args...]\n"
|
|
|
|
" -a Run interactively\n"
|
2003-10-31 01:29:59 +00:00
|
|
|
#if PHP_FASTCGI && !defined(PHP_WIN32)
|
2002-10-13 09:40:44 +00:00
|
|
|
" -b <address:port>|<port> Bind Path for external FASTCGI Server mode\n"
|
|
|
|
#endif
|
2002-10-25 09:28:55 +00:00
|
|
|
" -C Do not chdir to the script's directory\n"
|
|
|
|
" -c <path>|<file> Look for php.ini file in this directory\n"
|
2002-11-12 20:56:47 +00:00
|
|
|
" -n No php.ini file will be used\n"
|
2002-05-09 20:03:36 +00:00
|
|
|
" -d foo[=bar] Define INI entry foo with value 'bar'\n"
|
|
|
|
" -e Generate extended information for debugger/profiler\n"
|
2002-10-25 09:28:55 +00:00
|
|
|
" -f <file> Parse <file>. Implies `-q'\n"
|
2002-10-25 14:33:46 +00:00
|
|
|
" -h This help\n"
|
2002-10-25 09:28:55 +00:00
|
|
|
" -i PHP information\n"
|
2002-05-09 20:03:36 +00:00
|
|
|
" -l Syntax check only (lint)\n"
|
|
|
|
" -m Show compiled in modules\n"
|
2002-10-25 09:28:55 +00:00
|
|
|
" -q Quiet-mode. Suppress HTTP Header output.\n"
|
|
|
|
" -s Display colour syntax highlighted source.\n"
|
|
|
|
" -v Version number\n"
|
|
|
|
" -w Display source with stripped comments and whitespace.\n"
|
2002-10-25 14:33:46 +00:00
|
|
|
" -z <file> Load Zend extension <file>.\n",
|
2002-10-25 09:28:55 +00:00
|
|
|
prog, prog);
|
1999-04-26 14:00:49 +00:00
|
|
|
}
|
2001-06-06 13:06:12 +00:00
|
|
|
/* }}} */
|
1999-04-26 14:00:49 +00:00
|
|
|
|
2001-06-06 13:06:12 +00:00
|
|
|
/* {{{ init_request_info
|
2003-01-25 22:01:53 +00:00
|
|
|
|
|
|
|
initializes request_info structure
|
|
|
|
|
|
|
|
specificly in this section we handle proper translations
|
|
|
|
for:
|
|
|
|
|
|
|
|
PATH_INFO
|
|
|
|
derived from the portion of the URI path following
|
|
|
|
the script name but preceding any query data
|
|
|
|
may be empty
|
|
|
|
|
|
|
|
PATH_TRANSLATED
|
|
|
|
derived by taking any path-info component of the
|
|
|
|
request URI and performing any virtual-to-physical
|
|
|
|
translation appropriate to map it onto the server's
|
|
|
|
document repository structure
|
|
|
|
|
|
|
|
empty if PATH_INFO is empty
|
|
|
|
|
|
|
|
The env var PATH_TRANSLATED **IS DIFFERENT** than the
|
|
|
|
request_info.path_translated variable, the latter should
|
|
|
|
match SCRIPT_FILENAME instead.
|
|
|
|
|
|
|
|
SCRIPT_NAME
|
|
|
|
set to a URL path that could identify the CGI script
|
|
|
|
rather than the interpreter. PHP_SELF is set to this.
|
|
|
|
|
|
|
|
REQUEST_URI
|
|
|
|
uri section following the domain:port part of a URI
|
|
|
|
|
|
|
|
SCRIPT_FILENAME
|
|
|
|
The virtual-to-physical translation of SCRIPT_NAME (as per
|
|
|
|
PATH_TRANSLATED)
|
|
|
|
|
|
|
|
These settings are documented at
|
|
|
|
http://cgi-spec.golux.com/
|
|
|
|
|
|
|
|
|
|
|
|
Based on the following URL request:
|
|
|
|
|
|
|
|
http://localhost/info.php/test?a=b
|
|
|
|
|
|
|
|
should produce, which btw is the same as if
|
|
|
|
we were running under mod_cgi on apache (ie. not
|
|
|
|
using ScriptAlias directives):
|
|
|
|
|
|
|
|
PATH_INFO=/test
|
|
|
|
PATH_TRANSLATED=/docroot/test
|
|
|
|
SCRIPT_NAME=/info.php
|
|
|
|
REQUEST_URI=/info.php/test?a=b
|
|
|
|
SCRIPT_FILENAME=/docroot/info.php
|
|
|
|
QUERY_STRING=a=b
|
|
|
|
|
|
|
|
but what we get is (cgi/mod_fastcgi under apache):
|
|
|
|
|
|
|
|
PATH_INFO=/info.php/test
|
|
|
|
PATH_TRANSLATED=/docroot/info.php/test
|
|
|
|
SCRIPT_NAME=/php/php-cgi (from the Action setting I suppose)
|
|
|
|
REQUEST_URI=/info.php/test?a=b
|
|
|
|
SCRIPT_FILENAME=/path/to/php/bin/php-cgi (Action setting translated)
|
|
|
|
QUERY_STRING=a=b
|
|
|
|
|
|
|
|
Comments in the code below refer to using the above URL in a request
|
|
|
|
|
2001-06-06 13:24:17 +00:00
|
|
|
*/
|
2001-07-28 11:36:37 +00:00
|
|
|
static void init_request_info(TSRMLS_D)
|
1999-05-02 19:54:02 +00:00
|
|
|
{
|
2006-05-15 14:30:31 +00:00
|
|
|
char *env_script_filename = sapi_cgibin_getenv("SCRIPT_FILENAME", sizeof("SCRIPT_FILENAME")-1 TSRMLS_CC);
|
|
|
|
char *env_path_translated = sapi_cgibin_getenv("PATH_TRANSLATED", sizeof("PATH_TRANSLATED")-1 TSRMLS_CC);
|
2003-01-25 22:01:53 +00:00
|
|
|
char *script_path_translated = env_script_filename;
|
2002-12-01 21:37:14 +00:00
|
|
|
|
2003-02-13 18:21:12 +00:00
|
|
|
#if !DISCARD_PATH
|
2003-01-25 22:01:53 +00:00
|
|
|
/* some broken servers do not have script_filename or argv0
|
|
|
|
an example, IIS configured in some ways. then they do more
|
|
|
|
broken stuff and set path_translated to the cgi script location */
|
2003-03-29 16:13:51 +00:00
|
|
|
if (!script_path_translated && env_path_translated) {
|
|
|
|
script_path_translated = env_path_translated;
|
|
|
|
}
|
2003-02-13 18:21:12 +00:00
|
|
|
#endif
|
2002-12-01 21:37:14 +00:00
|
|
|
|
2003-01-25 22:01:53 +00:00
|
|
|
/* initialize the defaults */
|
|
|
|
SG(request_info).path_translated = NULL;
|
|
|
|
SG(request_info).request_method = NULL;
|
2005-03-14 19:25:39 +00:00
|
|
|
SG(request_info).proto_num = 1000;
|
2003-01-25 22:01:53 +00:00
|
|
|
SG(request_info).query_string = NULL;
|
|
|
|
SG(request_info).request_uri = NULL;
|
|
|
|
SG(request_info).content_type = NULL;
|
|
|
|
SG(request_info).content_length = 0;
|
|
|
|
SG(sapi_headers).http_response_code = 200;
|
2003-01-07 16:33:28 +00:00
|
|
|
|
2003-01-25 22:01:53 +00:00
|
|
|
/* script_path_translated being set is a good indication that
|
|
|
|
we are running in a cgi environment, since it is always
|
|
|
|
null otherwise. otherwise, the filename
|
|
|
|
of the script will be retreived later via argc/argv */
|
|
|
|
if (script_path_translated) {
|
|
|
|
const char *auth;
|
2006-05-15 14:30:31 +00:00
|
|
|
char *content_length = sapi_cgibin_getenv("CONTENT_LENGTH", sizeof("CONTENT_LENGTH")-1 TSRMLS_CC);
|
|
|
|
char *content_type = sapi_cgibin_getenv("CONTENT_TYPE", sizeof("CONTENT_TYPE")-1 TSRMLS_CC);
|
|
|
|
char *env_path_info = sapi_cgibin_getenv("PATH_INFO", sizeof("PATH_INFO")-1 TSRMLS_CC);
|
|
|
|
char *env_script_name = sapi_cgibin_getenv("SCRIPT_NAME", sizeof("SCRIPT_NAME")-1 TSRMLS_CC);
|
2003-02-13 18:21:12 +00:00
|
|
|
#if ENABLE_PATHINFO_CHECK
|
|
|
|
struct stat st;
|
2006-05-15 14:30:31 +00:00
|
|
|
char *env_redirect_url = sapi_cgibin_getenv("REDIRECT_URL", sizeof("REDIRECT_URL")-1 TSRMLS_CC);
|
|
|
|
char *env_document_root = sapi_cgibin_getenv("DOCUMENT_ROOT", sizeof("DOCUMENT_ROOT")-1 TSRMLS_CC);
|
2003-01-25 22:01:53 +00:00
|
|
|
|
2006-11-14 10:31:47 +00:00
|
|
|
if (CGIG(fix_pathinfo)) {
|
2006-11-15 13:33:41 +00:00
|
|
|
char *real_path;
|
|
|
|
char *orig_path_translated = env_path_translated;
|
|
|
|
char *orig_path_info = env_path_info;
|
|
|
|
char *orig_script_name = env_script_name;
|
|
|
|
char *orig_script_filename = env_script_filename;
|
|
|
|
|
|
|
|
if (!env_document_root && PG(doc_root)) {
|
|
|
|
env_document_root = _sapi_cgibin_putenv("DOCUMENT_ROOT", PG(doc_root) TSRMLS_CC);
|
|
|
|
/* fix docroot */
|
|
|
|
TRANSLATE_SLASHES(env_document_root);
|
|
|
|
}
|
2000-02-10 20:03:17 +00:00
|
|
|
|
2003-05-17 18:47:17 +00:00
|
|
|
if (env_path_translated != NULL && env_redirect_url != NULL) {
|
2003-01-25 22:01:53 +00:00
|
|
|
/*
|
|
|
|
pretty much apache specific. If we have a redirect_url
|
|
|
|
then our script_filename and script_name point to the
|
|
|
|
php executable
|
|
|
|
*/
|
|
|
|
script_path_translated = env_path_translated;
|
|
|
|
/* we correct SCRIPT_NAME now in case we don't have PATH_INFO */
|
2006-11-15 13:33:41 +00:00
|
|
|
env_script_name = env_redirect_url;
|
2003-01-25 22:01:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef __riscos__
|
|
|
|
/* Convert path to unix format*/
|
2005-06-03 23:11:51 +00:00
|
|
|
__riscosify_control |= __RISCOSIFY_DONT_CHECK_DIR;
|
|
|
|
script_path_translated = __unixify(script_path_translated, 0, NULL, 1, 0);
|
2003-01-25 22:01:53 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* if the file doesn't exist, try to extract PATH_INFO out
|
|
|
|
* of it by stat'ing back through the '/'
|
|
|
|
* this fixes url's like /info.php/test
|
|
|
|
*/
|
2006-11-15 13:33:41 +00:00
|
|
|
if (script_path_translated &&
|
|
|
|
(real_path = tsrm_realpath(script_path_translated, NULL TSRMLS_CC)) == NULL) {
|
2003-01-25 22:01:53 +00:00
|
|
|
char *pt = estrdup(script_path_translated);
|
2002-12-01 21:37:14 +00:00
|
|
|
int len = strlen(pt);
|
|
|
|
char *ptr;
|
|
|
|
|
2005-06-03 23:11:51 +00:00
|
|
|
while ((ptr = strrchr(pt, '/')) || (ptr = strrchr(pt, '\\'))) {
|
2002-12-01 21:37:14 +00:00
|
|
|
*ptr = 0;
|
2005-06-03 23:11:51 +00:00
|
|
|
if (stat(pt, &st) == 0 && S_ISREG(st.st_mode)) {
|
2002-12-01 21:37:14 +00:00
|
|
|
/*
|
|
|
|
* okay, we found the base script!
|
|
|
|
* work out how many chars we had to strip off;
|
|
|
|
* then we can modify PATH_INFO
|
|
|
|
* accordingly
|
|
|
|
*
|
2003-01-07 16:33:28 +00:00
|
|
|
* we now have the makings of
|
2002-12-01 21:37:14 +00:00
|
|
|
* PATH_INFO=/test
|
|
|
|
* SCRIPT_FILENAME=/docroot/info.php
|
|
|
|
*
|
|
|
|
* we now need to figure out what docroot is.
|
|
|
|
* if DOCUMENT_ROOT is set, this is easy, otherwise,
|
|
|
|
* we have to play the game of hide and seek to figure
|
|
|
|
* out what SCRIPT_NAME should be
|
|
|
|
*/
|
|
|
|
int slen = len - strlen(pt);
|
2005-06-03 23:11:51 +00:00
|
|
|
int pilen = strlen(env_path_info);
|
2002-12-01 21:37:14 +00:00
|
|
|
char *path_info = env_path_info + pilen - slen;
|
|
|
|
|
2006-11-15 13:33:41 +00:00
|
|
|
if (orig_path_info != path_info) {
|
|
|
|
if (orig_path_info) {
|
|
|
|
_sapi_cgibin_putenv("ORIG_PATH_INFO", orig_path_info TSRMLS_CC);
|
|
|
|
}
|
|
|
|
env_path_info = _sapi_cgibin_putenv("PATH_INFO", path_info TSRMLS_CC);
|
|
|
|
}
|
|
|
|
if (!orig_script_filename ||
|
|
|
|
strcmp(orig_script_filename, pt) != 0) {
|
|
|
|
if (orig_script_filename) {
|
|
|
|
_sapi_cgibin_putenv("ORIG_SCRIPT_FILENAME", orig_script_filename TSRMLS_CC);
|
|
|
|
}
|
|
|
|
script_path_translated = _sapi_cgibin_putenv("SCRIPT_FILENAME", pt TSRMLS_CC);
|
|
|
|
}
|
2002-12-01 21:37:14 +00:00
|
|
|
TRANSLATE_SLASHES(pt);
|
|
|
|
|
|
|
|
/* figure out docroot
|
|
|
|
SCRIPT_FILENAME minus SCRIPT_NAME
|
2005-06-03 23:11:51 +00:00
|
|
|
*/
|
2003-01-25 22:01:53 +00:00
|
|
|
|
2005-06-03 23:11:51 +00:00
|
|
|
if (env_document_root)
|
|
|
|
{
|
2002-12-01 21:37:14 +00:00
|
|
|
int l = strlen(env_document_root);
|
|
|
|
int path_translated_len = 0;
|
|
|
|
char *path_translated = NULL;
|
2005-06-03 23:11:51 +00:00
|
|
|
|
2006-12-28 22:36:53 +00:00
|
|
|
if (l && env_document_root[l - 1] == '/') {
|
2003-03-29 16:13:51 +00:00
|
|
|
--l;
|
|
|
|
}
|
2002-12-01 21:37:14 +00:00
|
|
|
|
|
|
|
/* we have docroot, so we should have:
|
|
|
|
* DOCUMENT_ROOT=/docroot
|
|
|
|
* SCRIPT_FILENAME=/docroot/info.php
|
|
|
|
*
|
|
|
|
* SCRIPT_NAME is the portion of the path beyond docroot
|
|
|
|
*/
|
2006-11-15 13:33:41 +00:00
|
|
|
env_script_name = pt + l;
|
2002-12-01 21:37:14 +00:00
|
|
|
|
2005-06-03 23:11:51 +00:00
|
|
|
/* PATH_TRANSATED = DOCUMENT_ROOT + PATH_INFO */
|
2003-01-25 22:01:53 +00:00
|
|
|
path_translated_len = l + strlen(env_path_info) + 2;
|
2005-06-03 23:11:51 +00:00
|
|
|
path_translated = (char *) emalloc(path_translated_len);
|
2002-12-01 21:37:14 +00:00
|
|
|
*path_translated = 0;
|
2005-06-03 23:11:51 +00:00
|
|
|
strncat(path_translated, env_document_root, l);
|
|
|
|
strcat(path_translated, env_path_info);
|
2006-11-15 13:33:41 +00:00
|
|
|
if (orig_path_translated) {
|
|
|
|
_sapi_cgibin_putenv("ORIG_PATH_TRANSLATED", orig_path_translated TSRMLS_CC);
|
|
|
|
}
|
2005-06-03 23:11:51 +00:00
|
|
|
env_path_translated = _sapi_cgibin_putenv("PATH_TRANSLATED", path_translated TSRMLS_CC);
|
2002-12-01 21:37:14 +00:00
|
|
|
efree(path_translated);
|
2005-06-03 23:11:51 +00:00
|
|
|
} else if (env_script_name &&
|
|
|
|
strstr(pt, env_script_name)
|
|
|
|
) {
|
|
|
|
/* PATH_TRANSATED = PATH_TRANSATED - SCRIPT_NAME + PATH_INFO */
|
|
|
|
int ptlen = strlen(pt) - strlen(env_script_name);
|
2003-01-25 22:01:53 +00:00
|
|
|
int path_translated_len = ptlen + strlen(env_path_info) + 2;
|
2002-12-01 21:37:14 +00:00
|
|
|
char *path_translated = NULL;
|
2005-06-03 23:11:51 +00:00
|
|
|
|
|
|
|
path_translated = (char *) emalloc(path_translated_len);
|
2002-12-01 21:37:14 +00:00
|
|
|
*path_translated = 0;
|
2005-06-03 23:11:51 +00:00
|
|
|
strncat(path_translated, pt, ptlen);
|
|
|
|
strcat(path_translated, env_path_info);
|
2006-11-15 13:33:41 +00:00
|
|
|
if (orig_path_translated) {
|
|
|
|
_sapi_cgibin_putenv("ORIG_PATH_TRANSLATED", orig_path_translated TSRMLS_CC);
|
|
|
|
}
|
2005-06-03 23:11:51 +00:00
|
|
|
env_path_translated = _sapi_cgibin_putenv("PATH_TRANSLATED", path_translated TSRMLS_CC);
|
2002-12-01 21:37:14 +00:00
|
|
|
efree(path_translated);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2003-01-25 22:01:53 +00:00
|
|
|
if (!ptr) {
|
|
|
|
/*
|
|
|
|
* if we stripped out all the '/' and still didn't find
|
|
|
|
* a valid path... we will fail, badly. of course we would
|
|
|
|
* have failed anyway... we output 'no input file' now.
|
|
|
|
*/
|
2006-11-15 13:33:41 +00:00
|
|
|
if (orig_script_filename) {
|
|
|
|
_sapi_cgibin_putenv("ORIG_SCRIPT_FILENAME", orig_script_filename TSRMLS_CC);
|
|
|
|
}
|
2005-06-03 23:11:51 +00:00
|
|
|
script_path_translated = _sapi_cgibin_putenv("SCRIPT_FILENAME", NULL TSRMLS_CC);
|
2003-01-25 22:01:53 +00:00
|
|
|
SG(sapi_headers).http_response_code = 404;
|
|
|
|
}
|
2006-11-15 13:33:41 +00:00
|
|
|
if (!orig_script_name ||
|
|
|
|
strcmp(orig_script_name, env_script_name) != 0) {
|
|
|
|
if (orig_script_name) {
|
|
|
|
_sapi_cgibin_putenv("ORIG_SCRIPT_NAME", orig_script_name TSRMLS_CC);
|
|
|
|
}
|
|
|
|
SG(request_info).request_uri = _sapi_cgibin_putenv("SCRIPT_NAME", env_script_name TSRMLS_CC);
|
|
|
|
} else {
|
|
|
|
SG(request_info).request_uri = orig_script_name;
|
|
|
|
}
|
2003-03-29 16:13:51 +00:00
|
|
|
if (pt) {
|
|
|
|
efree(pt);
|
|
|
|
}
|
2003-01-25 22:01:53 +00:00
|
|
|
} else {
|
|
|
|
/* make sure path_info/translated are empty */
|
2006-11-15 13:33:41 +00:00
|
|
|
if (!orig_script_filename ||
|
|
|
|
(script_path_translated != orig_script_filename) ||
|
|
|
|
strcmp(script_path_translated, orig_script_filename) != 0) {
|
|
|
|
if (orig_script_filename) {
|
|
|
|
_sapi_cgibin_putenv("ORIG_SCRIPT_FILENAME", orig_script_filename TSRMLS_CC);
|
|
|
|
}
|
|
|
|
script_path_translated = _sapi_cgibin_putenv("SCRIPT_FILENAME", script_path_translated TSRMLS_CC);
|
|
|
|
}
|
|
|
|
if (orig_path_info) {
|
|
|
|
_sapi_cgibin_putenv("ORIG_PATH_INFO", orig_path_info TSRMLS_CC);
|
|
|
|
_sapi_cgibin_putenv("PATH_INFO", NULL TSRMLS_CC);
|
|
|
|
}
|
|
|
|
if (orig_path_translated) {
|
|
|
|
_sapi_cgibin_putenv("ORIG_PATH_TRANSLATED", orig_path_translated TSRMLS_CC);
|
|
|
|
_sapi_cgibin_putenv("PATH_TRANSLATED", NULL TSRMLS_CC);
|
|
|
|
}
|
|
|
|
if (env_script_name != orig_script_name) {
|
|
|
|
if (orig_script_name) {
|
|
|
|
_sapi_cgibin_putenv("ORIG_SCRIPT_NAME", orig_script_name TSRMLS_CC);
|
|
|
|
}
|
|
|
|
SG(request_info).request_uri = _sapi_cgibin_putenv("SCRIPT_NAME", env_script_name TSRMLS_CC);
|
|
|
|
} else {
|
|
|
|
SG(request_info).request_uri = env_script_name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(real_path);
|
2003-02-13 18:21:12 +00:00
|
|
|
} else {
|
|
|
|
#endif
|
|
|
|
/* pre 4.3 behaviour, shouldn't be used but provides BC */
|
2003-03-29 16:13:51 +00:00
|
|
|
if (env_path_info) {
|
2003-02-13 18:21:12 +00:00
|
|
|
SG(request_info).request_uri = env_path_info;
|
2003-03-29 16:13:51 +00:00
|
|
|
} else {
|
2003-02-13 18:21:12 +00:00
|
|
|
SG(request_info).request_uri = env_script_name;
|
2003-03-29 16:13:51 +00:00
|
|
|
}
|
2003-02-13 18:21:12 +00:00
|
|
|
#if !DISCARD_PATH
|
2003-08-04 19:05:20 +00:00
|
|
|
if (env_path_translated)
|
|
|
|
script_path_translated = env_path_translated;
|
2003-02-13 18:21:12 +00:00
|
|
|
#endif
|
|
|
|
#if ENABLE_PATHINFO_CHECK
|
2002-12-01 21:37:14 +00:00
|
|
|
}
|
2003-01-25 22:01:53 +00:00
|
|
|
#endif
|
2006-05-15 14:30:31 +00:00
|
|
|
SG(request_info).request_method = sapi_cgibin_getenv("REQUEST_METHOD", sizeof("REQUEST_METHOD")-1 TSRMLS_CC);
|
2005-03-14 19:25:39 +00:00
|
|
|
/* FIXME - Work out proto_num here */
|
2006-05-15 14:30:31 +00:00
|
|
|
SG(request_info).query_string = sapi_cgibin_getenv("QUERY_STRING", sizeof("QUERY_STRING")-1 TSRMLS_CC);
|
2003-03-27 17:52:33 +00:00
|
|
|
/* some server configurations allow '..' to slip through in the
|
|
|
|
translated path. We'll just refuse to handle such a path. */
|
2003-03-29 16:13:51 +00:00
|
|
|
if (script_path_translated && !strstr(script_path_translated, "..")) {
|
2003-01-25 22:01:53 +00:00
|
|
|
SG(request_info).path_translated = estrdup(script_path_translated);
|
2003-03-29 16:13:51 +00:00
|
|
|
}
|
2003-01-25 22:01:53 +00:00
|
|
|
SG(request_info).content_type = (content_type ? content_type : "" );
|
2005-06-03 23:11:51 +00:00
|
|
|
SG(request_info).content_length = (content_length ? atoi(content_length) : 0);
|
2003-01-25 22:01:53 +00:00
|
|
|
|
|
|
|
/* The CGI RFC allows servers to pass on unvalidated Authorization data */
|
2006-05-15 14:30:31 +00:00
|
|
|
auth = sapi_cgibin_getenv("HTTP_AUTHORIZATION", sizeof("HTTP_AUTHORIZATION")-1 TSRMLS_CC);
|
2003-01-25 22:01:53 +00:00
|
|
|
php_handle_auth_data(auth TSRMLS_CC);
|
2002-12-01 21:37:14 +00:00
|
|
|
}
|
1999-05-02 19:54:02 +00:00
|
|
|
}
|
2001-06-06 13:06:12 +00:00
|
|
|
/* }}} */
|
1999-05-02 19:54:02 +00:00
|
|
|
|
2002-11-26 05:51:16 +00:00
|
|
|
#if PHP_FASTCGI
|
|
|
|
/**
|
|
|
|
* Clean up child processes upon exit
|
|
|
|
*/
|
|
|
|
void fastcgi_cleanup(int signal)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_FASTCGI
|
2005-06-03 23:11:51 +00:00
|
|
|
fprintf(stderr, "FastCGI shutdown, pid %d\n", getpid());
|
2002-11-26 05:51:16 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef PHP_WIN32
|
2005-06-03 23:11:51 +00:00
|
|
|
sigaction(SIGTERM, &old_term, 0);
|
2002-11-26 05:51:16 +00:00
|
|
|
|
|
|
|
/* Kill all the processes in our process group */
|
2005-06-03 23:11:51 +00:00
|
|
|
kill(-pgroup, SIGTERM);
|
2002-11-26 05:51:16 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* We should exit at this point, but MacOSX doesn't seem to */
|
2005-06-03 23:11:51 +00:00
|
|
|
exit(0);
|
2002-11-26 05:51:16 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-03-23 10:19:30 +00:00
|
|
|
#if PHP_FASTCGI
|
|
|
|
#ifndef PHP_WIN32
|
2006-03-23 10:15:01 +00:00
|
|
|
static int is_port_number(const char *bindpath)
|
|
|
|
{
|
|
|
|
while (*bindpath) {
|
|
|
|
if (*bindpath < '0' || *bindpath > '9') {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
bindpath++;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
2006-03-23 10:19:30 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
2006-03-23 10:15:01 +00:00
|
|
|
|
2006-11-14 10:31:47 +00:00
|
|
|
PHP_INI_BEGIN()
|
|
|
|
STD_PHP_INI_ENTRY("cgi.rfc2616_headers", "0", PHP_INI_ALL, OnUpdateBool, rfc2616_headers, php_cgi_globals_struct, php_cgi_globals)
|
|
|
|
STD_PHP_INI_ENTRY("cgi.nph", "0", PHP_INI_ALL, OnUpdateBool, nph, php_cgi_globals_struct, php_cgi_globals)
|
|
|
|
STD_PHP_INI_ENTRY("cgi.check_shebang_line", "1", PHP_INI_SYSTEM, OnUpdateBool, check_shebang_line, php_cgi_globals_struct, php_cgi_globals)
|
|
|
|
#if FORCE_CGI_REDIRECT
|
|
|
|
STD_PHP_INI_ENTRY("cgi.force_redirect", "1", PHP_INI_SYSTEM, OnUpdateBool, force_redirect, php_cgi_globals_struct, php_cgi_globals)
|
|
|
|
STD_PHP_INI_ENTRY("cgi.redirect_status_env", NULL, PHP_INI_SYSTEM, OnUpdateString, redirect_status_env, php_cgi_globals_struct, php_cgi_globals)
|
|
|
|
#endif
|
|
|
|
#if ENABLE_PATHINFO_CHECK
|
|
|
|
STD_PHP_INI_ENTRY("cgi.fix_pathinfo", "1", PHP_INI_SYSTEM, OnUpdateBool, fix_pathinfo, php_cgi_globals_struct, php_cgi_globals)
|
|
|
|
#endif
|
|
|
|
#if PHP_FASTCGI
|
|
|
|
STD_PHP_INI_ENTRY("fastcgi.logging", "1", PHP_INI_SYSTEM, OnUpdateBool, fcgi_logging, php_cgi_globals_struct, php_cgi_globals)
|
|
|
|
# ifdef PHP_WIN32
|
|
|
|
STD_PHP_INI_ENTRY("fastcgi.impersonate", "0", PHP_INI_SYSTEM, OnUpdateBool, impersonate, php_cgi_globals_struct, php_cgi_globals)
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
PHP_INI_END()
|
|
|
|
|
|
|
|
/* {{{ php_cgi_globals_ctor
|
|
|
|
*/
|
|
|
|
static void php_cgi_globals_ctor(php_cgi_globals_struct *php_cgi_globals TSRMLS_DC)
|
|
|
|
{
|
|
|
|
php_cgi_globals->rfc2616_headers = 0;
|
|
|
|
php_cgi_globals->nph = 0;
|
|
|
|
php_cgi_globals->check_shebang_line = 1;
|
|
|
|
#if FORCE_CGI_REDIRECT
|
|
|
|
php_cgi_globals->force_redirect = 1;
|
|
|
|
php_cgi_globals->redirect_status_env = NULL;
|
|
|
|
#endif
|
|
|
|
#if ENABLE_PATHINFO_CHECK
|
|
|
|
php_cgi_globals->fix_pathinfo = 1;
|
|
|
|
#endif
|
|
|
|
#if PHP_FASTCGI
|
|
|
|
php_cgi_globals->fcgi_logging = 1;
|
|
|
|
# ifdef PHP_WIN32
|
|
|
|
php_cgi_globals->impersonate = 0;
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ PHP_MINIT_FUNCTION
|
|
|
|
*/
|
|
|
|
static PHP_MINIT_FUNCTION(cgi)
|
|
|
|
{
|
|
|
|
#ifdef ZTS
|
|
|
|
ts_allocate_id(&php_cgi_globals_id, sizeof(php_cgi_globals_struct), (ts_allocate_ctor) php_cgi_globals_ctor, NULL);
|
|
|
|
#else
|
|
|
|
php_cgi_globals_ctor(&php_cgi_globals TSRMLS_CC);
|
|
|
|
#endif
|
|
|
|
REGISTER_INI_ENTRIES();
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ PHP_MSHUTDOWN_FUNCTION
|
|
|
|
*/
|
|
|
|
static PHP_MSHUTDOWN_FUNCTION(cgi)
|
|
|
|
{
|
|
|
|
UNREGISTER_INI_ENTRIES();
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ PHP_MINFO_FUNCTION
|
|
|
|
*/
|
|
|
|
static PHP_MINFO_FUNCTION(cgi)
|
|
|
|
{
|
|
|
|
DISPLAY_INI_ENTRIES();
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
static zend_module_entry cgi_module_entry = {
|
|
|
|
STANDARD_MODULE_HEADER,
|
|
|
|
#if PHP_FASTCGI
|
|
|
|
"cgi-fcgi",
|
|
|
|
#else
|
|
|
|
"cgi",
|
|
|
|
#endif
|
|
|
|
NULL,
|
|
|
|
PHP_MINIT(cgi),
|
|
|
|
PHP_MSHUTDOWN(cgi),
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
PHP_MINFO(cgi),
|
|
|
|
NO_VERSION_YET,
|
|
|
|
STANDARD_MODULE_PROPERTIES
|
|
|
|
};
|
|
|
|
|
2001-06-06 13:06:12 +00:00
|
|
|
/* {{{ main
|
|
|
|
*/
|
1999-04-25 19:36:57 +00:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2006-06-19 17:49:26 +00:00
|
|
|
int free_query_string = 0;
|
2002-05-09 20:03:36 +00:00
|
|
|
int exit_status = SUCCESS;
|
2002-11-12 16:41:14 +00:00
|
|
|
int cgi = 0, c, i, len;
|
2002-05-09 20:03:36 +00:00
|
|
|
zend_file_handle file_handle;
|
|
|
|
int retval = FAILURE;
|
|
|
|
char *s;
|
1999-04-25 19:36:57 +00:00
|
|
|
/* temporary locals */
|
2005-06-03 23:11:51 +00:00
|
|
|
int behavior = PHP_MODE_STANDARD;
|
|
|
|
int no_headers = 0;
|
|
|
|
int orig_optind = php_optind;
|
|
|
|
char *orig_optarg = php_optarg;
|
|
|
|
char *script_file = NULL;
|
2006-09-19 20:33:12 +00:00
|
|
|
int ini_entries_len = 0;
|
2002-03-06 13:25:25 +00:00
|
|
|
|
1999-04-25 19:36:57 +00:00
|
|
|
/* end of temporary locals */
|
|
|
|
#ifdef ZTS
|
2002-05-09 20:03:36 +00:00
|
|
|
zend_compiler_globals *compiler_globals;
|
|
|
|
zend_executor_globals *executor_globals;
|
|
|
|
php_core_globals *core_globals;
|
|
|
|
sapi_globals_struct *sapi_globals;
|
|
|
|
void ***tsrm_ls;
|
1999-04-25 19:36:57 +00:00
|
|
|
#endif
|
|
|
|
|
2002-11-26 05:51:16 +00:00
|
|
|
#if PHP_FASTCGI
|
2002-05-09 20:03:36 +00:00
|
|
|
int max_requests = 500;
|
|
|
|
int requests = 0;
|
2006-05-15 14:30:31 +00:00
|
|
|
int fastcgi = fcgi_is_fastcgi();
|
2003-06-29 20:45:38 +00:00
|
|
|
#ifndef PHP_WIN32
|
2002-10-13 09:40:44 +00:00
|
|
|
char *bindpath = NULL;
|
2003-06-29 20:45:38 +00:00
|
|
|
#endif
|
2002-10-13 09:40:44 +00:00
|
|
|
int fcgi_fd = 0;
|
2006-05-15 14:30:31 +00:00
|
|
|
fcgi_request request;
|
2006-11-14 10:31:47 +00:00
|
|
|
#ifndef PHP_WIN32
|
2005-06-03 23:11:51 +00:00
|
|
|
int status = 0;
|
2002-03-18 04:48:34 +00:00
|
|
|
#endif
|
2002-10-13 09:40:44 +00:00
|
|
|
#endif /* PHP_FASTCGI */
|
1999-04-25 19:36:57 +00:00
|
|
|
|
2003-03-25 07:43:30 +00:00
|
|
|
#if 0 && defined(PHP_DEBUG)
|
|
|
|
/* IIS is always making things more difficult. This allows
|
|
|
|
us to stop PHP and attach a debugger before much gets started */
|
|
|
|
{
|
|
|
|
char szMessage [256];
|
|
|
|
wsprintf (szMessage, "Please attach a debugger to the process 0x%X [%d] (%s) and click OK",
|
2005-06-03 23:11:51 +00:00
|
|
|
GetCurrentProcessId(), GetCurrentProcessId(), argv[0]);
|
|
|
|
MessageBox(NULL, szMessage, "CGI Debug Time!", MB_OK|MB_SERVICE_NOTIFICATION);
|
2003-03-25 07:43:30 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2000-08-27 19:46:06 +00:00
|
|
|
#ifdef HAVE_SIGNAL_H
|
2000-04-20 07:35:22 +00:00
|
|
|
#if defined(SIGPIPE) && defined(SIG_IGN)
|
2002-05-09 20:03:36 +00:00
|
|
|
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 */
|
2000-04-19 15:37:43 +00:00
|
|
|
#endif
|
2000-04-19 17:28:23 +00:00
|
|
|
#endif
|
2000-04-19 15:37:43 +00:00
|
|
|
|
1999-05-02 19:01:45 +00:00
|
|
|
#ifdef ZTS
|
2002-05-09 20:03:36 +00:00
|
|
|
tsrm_startup(1, 1, 0, NULL);
|
1999-05-02 19:01:45 +00:00
|
|
|
#endif
|
|
|
|
|
2002-05-09 20:03:36 +00:00
|
|
|
sapi_startup(&cgi_sapi_module);
|
1999-05-02 18:07:41 +00:00
|
|
|
|
2000-04-20 13:43:48 +00:00
|
|
|
#ifdef PHP_WIN32
|
2005-06-03 23:11:51 +00:00
|
|
|
_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 */
|
1999-04-25 19:36:57 +00:00
|
|
|
#endif
|
|
|
|
|
2002-11-26 05:51:16 +00:00
|
|
|
#if PHP_FASTCGI
|
2002-10-13 09:40:44 +00:00
|
|
|
if (!fastcgi) {
|
|
|
|
#endif
|
2002-05-09 20:03:36 +00:00
|
|
|
/* 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. */
|
2005-06-03 23:11:51 +00:00
|
|
|
if (getenv("SERVER_SOFTWARE") ||
|
|
|
|
getenv("SERVER_NAME") ||
|
|
|
|
getenv("GATEWAY_INTERFACE") ||
|
|
|
|
getenv("REQUEST_METHOD")
|
|
|
|
) {
|
2002-05-09 20:03:36 +00:00
|
|
|
cgi = 1;
|
|
|
|
}
|
2002-11-26 05:51:16 +00:00
|
|
|
#if PHP_FASTCGI
|
2002-10-13 09:40:44 +00:00
|
|
|
}
|
|
|
|
#endif
|
2002-05-09 20:03:36 +00:00
|
|
|
|
2005-06-03 23:11:51 +00:00
|
|
|
while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0)) != -1) {
|
2004-02-27 23:31:28 +00:00
|
|
|
switch (c) {
|
|
|
|
case 'c':
|
|
|
|
cgi_sapi_module.php_ini_path_override = strdup(php_optarg);
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
cgi_sapi_module.php_ini_ignore = 1;
|
|
|
|
break;
|
2006-09-19 20:33:12 +00:00
|
|
|
case 'd': {
|
|
|
|
/* define ini entries on command line */
|
|
|
|
int len = strlen(php_optarg);
|
2006-09-22 17:41:09 +00:00
|
|
|
char *val;
|
|
|
|
|
|
|
|
if ((val = strchr(php_optarg, '='))) {
|
|
|
|
val++;
|
|
|
|
if (!isalnum(*val) && *val != '"' && *val != '\'' && *val != '\0') {
|
2006-09-23 12:27:40 +00:00
|
|
|
cgi_sapi_module.ini_entries = realloc(cgi_sapi_module.ini_entries, ini_entries_len + len + sizeof("\"\"\n\0"));
|
|
|
|
memcpy(cgi_sapi_module.ini_entries + ini_entries_len, php_optarg, (val - php_optarg));
|
2006-09-22 17:41:09 +00:00
|
|
|
ini_entries_len += (val - php_optarg);
|
2006-09-23 12:27:40 +00:00
|
|
|
memcpy(cgi_sapi_module.ini_entries + ini_entries_len, "\"", 1);
|
2006-09-22 17:41:09 +00:00
|
|
|
ini_entries_len++;
|
2006-09-23 12:27:40 +00:00
|
|
|
memcpy(cgi_sapi_module.ini_entries + ini_entries_len, val, len - (val - php_optarg));
|
2006-09-22 17:41:09 +00:00
|
|
|
ini_entries_len += len - (val - php_optarg);
|
2006-09-23 12:27:40 +00:00
|
|
|
memcpy(cgi_sapi_module.ini_entries + ini_entries_len, "\"\n\0", sizeof("\"\n\0"));
|
2006-09-22 17:41:09 +00:00
|
|
|
ini_entries_len += sizeof("\n\0\"") - 2;
|
|
|
|
} else {
|
2006-09-23 12:27:40 +00:00
|
|
|
cgi_sapi_module.ini_entries = realloc(cgi_sapi_module.ini_entries, ini_entries_len + len + sizeof("\n\0"));
|
|
|
|
memcpy(cgi_sapi_module.ini_entries + ini_entries_len, php_optarg, len);
|
|
|
|
memcpy(cgi_sapi_module.ini_entries + ini_entries_len + len, "\n\0", sizeof("\n\0"));
|
2006-09-22 17:41:09 +00:00
|
|
|
ini_entries_len += len + sizeof("\n\0") - 2;
|
|
|
|
}
|
2006-09-19 20:33:12 +00:00
|
|
|
} else {
|
|
|
|
cgi_sapi_module.ini_entries = realloc(cgi_sapi_module.ini_entries, ini_entries_len + len + sizeof("=1\n\0"));
|
|
|
|
memcpy(cgi_sapi_module.ini_entries + ini_entries_len, php_optarg, len);
|
|
|
|
memcpy(cgi_sapi_module.ini_entries + ini_entries_len + len, "=1\n\0", sizeof("=1\n\0"));
|
|
|
|
ini_entries_len += len + sizeof("=1\n\0") - 2;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2002-11-26 05:51:16 +00:00
|
|
|
#if PHP_FASTCGI
|
2003-06-29 20:45:38 +00:00
|
|
|
#ifndef PHP_WIN32
|
2004-02-27 23:31:28 +00:00
|
|
|
/* if we're started on command line, check to see if
|
|
|
|
we are being started as an 'external' fastcgi
|
|
|
|
server by accepting a bindpath parameter. */
|
|
|
|
case 'b':
|
|
|
|
if (!fastcgi) {
|
|
|
|
bindpath = strdup(php_optarg);
|
|
|
|
}
|
|
|
|
break;
|
2003-06-29 20:45:38 +00:00
|
|
|
#endif
|
2003-01-25 22:01:53 +00:00
|
|
|
#endif
|
2002-10-13 09:40:44 +00:00
|
|
|
}
|
2004-02-27 23:31:28 +00:00
|
|
|
|
2002-10-13 09:40:44 +00:00
|
|
|
}
|
2004-02-27 23:31:28 +00:00
|
|
|
php_optind = orig_optind;
|
|
|
|
php_optarg = orig_optarg;
|
2002-03-01 00:19:01 +00:00
|
|
|
|
|
|
|
#ifdef ZTS
|
2002-05-09 20:03:36 +00:00
|
|
|
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);
|
2003-03-25 07:43:30 +00:00
|
|
|
SG(request_info).path_translated = NULL;
|
2002-03-01 00:19:01 +00:00
|
|
|
#endif
|
|
|
|
|
2002-05-11 03:41:17 +00:00
|
|
|
cgi_sapi_module.executable_location = argv[0];
|
|
|
|
|
2002-05-09 20:03:36 +00:00
|
|
|
/* startup after we get the above ini override se we get things right */
|
2006-11-14 10:31:47 +00:00
|
|
|
if (php_module_startup(&cgi_sapi_module, &cgi_module_entry, 1) == FAILURE) {
|
2002-03-01 00:19:01 +00:00
|
|
|
#ifdef ZTS
|
2002-05-09 20:03:36 +00:00
|
|
|
tsrm_shutdown();
|
2002-03-01 00:19:01 +00:00
|
|
|
#endif
|
2002-05-09 20:03:36 +00:00
|
|
|
return FAILURE;
|
|
|
|
}
|
2001-05-22 23:05:08 +00:00
|
|
|
|
1999-04-25 19:36:57 +00:00
|
|
|
#if FORCE_CGI_REDIRECT
|
2002-05-09 20:03:36 +00:00
|
|
|
/* check force_cgi after startup, so we have proper output */
|
2006-11-14 10:31:47 +00:00
|
|
|
if (cgi && CGIG(force_redirect)) {
|
2002-05-09 20:03:36 +00:00
|
|
|
/* 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
|
|
|
|
*/
|
2003-01-07 16:33:28 +00:00
|
|
|
if (!getenv("REDIRECT_STATUS")
|
2002-05-09 20:03:36 +00:00
|
|
|
&& !getenv ("HTTP_REDIRECT_STATUS")
|
|
|
|
/* this is to allow a different env var to be configured
|
2005-06-03 23:11:51 +00:00
|
|
|
in case some server does something different than above */
|
2006-11-14 10:31:47 +00:00
|
|
|
&& (!CGIG(redirect_status_env) || !getenv(CGIG(redirect_status_env)))
|
2002-05-09 20:03:36 +00:00
|
|
|
) {
|
2004-03-12 14:05:59 +00:00
|
|
|
SG(sapi_headers).http_response_code = 400;
|
2002-05-09 20:03:36 +00:00
|
|
|
PUTS("<b>Security Alert!</b> The PHP CGI cannot be accessed directly.\n\n\
|
2002-04-02 01:34:15 +00:00
|
|
|
<p>This PHP CGI binary was compiled with force-cgi-redirect enabled. This\n\
|
1999-04-25 19:36:57 +00:00
|
|
|
means that a page will only be served up if the REDIRECT_STATUS CGI variable is\n\
|
2002-05-02 17:19:42 +00:00
|
|
|
set, e.g. via an Apache Action directive.</p>\n\
|
2002-05-02 15:18:26 +00:00
|
|
|
<p>For more information as to <i>why</i> this behaviour exists, see the <a href=\"http://php.net/security.cgi-bin\">\
|
2002-05-02 17:19:42 +00:00
|
|
|
manual page for CGI security</a>.</p>\n\
|
2002-04-02 01:34:15 +00:00
|
|
|
<p>For more information about changing this behaviour or re-enabling this webserver,\n\
|
|
|
|
consult the installation file that came with this distribution, or visit \n\
|
2002-05-02 17:19:42 +00:00
|
|
|
<a href=\"http://php.net/install.windows\">the manual page</a>.</p>\n");
|
1999-04-25 19:36:57 +00:00
|
|
|
|
2003-03-25 07:43:30 +00:00
|
|
|
#if defined(ZTS) && !defined(PHP_DEBUG)
|
2005-06-03 23:11:51 +00:00
|
|
|
/* XXX we're crashing here in msvc6 debug builds at
|
|
|
|
php_message_handler_for_zend:839 because
|
|
|
|
SG(request_info).path_translated is an invalid pointer.
|
|
|
|
It still happens even though I set it to null, so something
|
|
|
|
weird is going on.
|
|
|
|
*/
|
|
|
|
tsrm_shutdown();
|
2002-03-01 00:19:01 +00:00
|
|
|
#endif
|
2002-05-09 20:03:36 +00:00
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
}
|
2005-06-03 23:11:51 +00:00
|
|
|
#endif /* FORCE_CGI_REDIRECT */
|
2000-07-13 09:17:39 +00:00
|
|
|
|
2002-11-26 05:51:16 +00:00
|
|
|
#if PHP_FASTCGI
|
2003-06-29 20:45:38 +00:00
|
|
|
#ifndef PHP_WIN32
|
|
|
|
/* for windows, socket listening is broken in the fastcgi library itself
|
|
|
|
so dissabling this feature on windows till time is available to fix it */
|
2002-10-13 09:40:44 +00:00
|
|
|
if (bindpath) {
|
|
|
|
/* Pass on the arg to the FastCGI library, with one exception.
|
|
|
|
* If just a port is specified, then we prepend a ':' onto the
|
|
|
|
* path (it's what the fastcgi library expects)
|
2006-05-15 14:30:31 +00:00
|
|
|
*/
|
2006-03-23 10:15:01 +00:00
|
|
|
if (strchr(bindpath, ':') == NULL && is_port_number(bindpath)) {
|
2003-09-03 08:15:09 +00:00
|
|
|
char *tmp;
|
|
|
|
|
|
|
|
tmp = malloc(strlen(bindpath) + 2);
|
|
|
|
tmp[0] = ':';
|
|
|
|
memcpy(tmp + 1, bindpath, strlen(bindpath) + 1);
|
|
|
|
|
2006-05-15 14:30:31 +00:00
|
|
|
fcgi_fd = fcgi_listen(tmp, 128);
|
2003-09-03 08:15:09 +00:00
|
|
|
free(tmp);
|
2002-10-13 09:40:44 +00:00
|
|
|
} else {
|
2006-05-15 14:30:31 +00:00
|
|
|
fcgi_fd = fcgi_listen(bindpath, 128);
|
2002-10-13 09:40:44 +00:00
|
|
|
}
|
2005-06-03 23:11:51 +00:00
|
|
|
if (fcgi_fd < 0) {
|
2003-03-29 16:13:51 +00:00
|
|
|
fprintf(stderr, "Couldn't create FastCGI listen socket on port %s\n", bindpath);
|
2002-10-13 09:40:44 +00:00
|
|
|
#ifdef ZTS
|
2005-06-03 23:11:51 +00:00
|
|
|
tsrm_shutdown();
|
2002-10-13 09:40:44 +00:00
|
|
|
#endif
|
|
|
|
return FAILURE;
|
2002-05-09 20:03:36 +00:00
|
|
|
}
|
2006-05-15 14:30:31 +00:00
|
|
|
fastcgi = fcgi_is_fastcgi();
|
2002-05-09 20:03:36 +00:00
|
|
|
}
|
2003-06-29 20:45:38 +00:00
|
|
|
#endif
|
2002-10-13 09:40:44 +00:00
|
|
|
if (fastcgi) {
|
|
|
|
/* How many times to run PHP scripts before dying */
|
2005-06-03 23:11:51 +00:00
|
|
|
if (getenv("PHP_FCGI_MAX_REQUESTS")) {
|
|
|
|
max_requests = atoi(getenv("PHP_FCGI_MAX_REQUESTS"));
|
2006-05-15 14:30:31 +00:00
|
|
|
if (max_requests < 0) {
|
2005-06-03 23:11:51 +00:00
|
|
|
fprintf(stderr, "PHP_FCGI_MAX_REQUESTS is not valid\n");
|
2002-10-13 09:40:44 +00:00
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* make php call us to get _ENV vars */
|
|
|
|
php_php_import_environment_variables = php_import_environment_variables;
|
|
|
|
php_import_environment_variables = cgi_php_import_environment_variables;
|
|
|
|
|
|
|
|
/* library is already initialized, now init our request */
|
2006-05-15 14:30:31 +00:00
|
|
|
fcgi_init_request(&request, fcgi_fd);
|
2002-03-10 21:39:28 +00:00
|
|
|
|
|
|
|
#ifndef PHP_WIN32
|
2002-05-09 20:03:36 +00:00
|
|
|
/* Pre-fork, if required */
|
2005-06-03 23:11:51 +00:00
|
|
|
if (getenv("PHP_FCGI_CHILDREN")) {
|
|
|
|
children = atoi(getenv("PHP_FCGI_CHILDREN"));
|
2006-05-15 14:30:31 +00:00
|
|
|
if (children < 0) {
|
2005-06-03 23:11:51 +00:00
|
|
|
fprintf(stderr, "PHP_FCGI_CHILDREN is not valid\n");
|
2002-10-13 09:40:44 +00:00
|
|
|
return FAILURE;
|
2002-05-09 20:03:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-03 23:11:51 +00:00
|
|
|
if (children) {
|
2002-05-09 20:03:36 +00:00
|
|
|
int running = 0;
|
|
|
|
pid_t pid;
|
|
|
|
|
|
|
|
/* Create a process group for ourself & children */
|
|
|
|
setsid();
|
|
|
|
pgroup = getpgrp();
|
2002-03-10 21:39:28 +00:00
|
|
|
#ifdef DEBUG_FASTCGI
|
2005-06-03 23:11:51 +00:00
|
|
|
fprintf(stderr, "Process group %d\n", pgroup);
|
2002-03-10 21:39:28 +00:00
|
|
|
#endif
|
|
|
|
|
2002-05-09 20:03:36 +00:00
|
|
|
/* Set up handler to kill children upon exit */
|
|
|
|
act.sa_flags = 0;
|
|
|
|
act.sa_handler = fastcgi_cleanup;
|
2005-06-03 23:11:51 +00:00
|
|
|
if (sigaction(SIGTERM, &act, &old_term) ||
|
|
|
|
sigaction(SIGINT, &act, &old_int) ||
|
|
|
|
sigaction(SIGQUIT, &act, &old_quit)) {
|
|
|
|
perror("Can't set signals");
|
|
|
|
exit(1);
|
2002-05-09 20:03:36 +00:00
|
|
|
}
|
|
|
|
|
2005-06-03 23:11:51 +00:00
|
|
|
while (parent) {
|
2002-05-09 20:03:36 +00:00
|
|
|
do {
|
2002-03-10 21:39:28 +00:00
|
|
|
#ifdef DEBUG_FASTCGI
|
2005-06-03 23:11:51 +00:00
|
|
|
fprintf(stderr, "Forking, %d running\n", running);
|
2002-03-10 21:39:28 +00:00
|
|
|
#endif
|
2002-05-09 20:03:36 +00:00
|
|
|
pid = fork();
|
2005-06-03 23:11:51 +00:00
|
|
|
switch (pid) {
|
2002-05-09 20:03:36 +00:00
|
|
|
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 */
|
2005-06-03 23:11:51 +00:00
|
|
|
sigaction(SIGTERM, &old_term, 0);
|
|
|
|
sigaction(SIGQUIT, &old_quit, 0);
|
|
|
|
sigaction(SIGINT, &old_int, 0);
|
2002-05-09 20:03:36 +00:00
|
|
|
break;
|
|
|
|
case -1:
|
2005-06-03 23:11:51 +00:00
|
|
|
perror("php (pre-forking)");
|
|
|
|
exit(1);
|
2002-05-09 20:03:36 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* Fine */
|
|
|
|
running++;
|
|
|
|
break;
|
|
|
|
}
|
2005-06-03 23:11:51 +00:00
|
|
|
} while (parent && (running < children));
|
2002-05-09 20:03:36 +00:00
|
|
|
|
2005-06-03 23:11:51 +00:00
|
|
|
if (parent) {
|
2002-03-10 21:39:28 +00:00
|
|
|
#ifdef DEBUG_FASTCGI
|
2005-06-03 23:11:51 +00:00
|
|
|
fprintf(stderr, "Wait for kids, pid %d\n", getpid());
|
2002-03-10 21:39:28 +00:00
|
|
|
#endif
|
2006-02-03 16:30:09 +00:00
|
|
|
while (wait(&status) < 0) {
|
|
|
|
}
|
2002-05-09 20:03:36 +00:00
|
|
|
running--;
|
|
|
|
}
|
|
|
|
}
|
2005-12-09 17:01:50 +00:00
|
|
|
} else {
|
|
|
|
parent = 0;
|
2002-05-09 20:03:36 +00:00
|
|
|
}
|
2002-03-10 21:39:28 +00:00
|
|
|
|
|
|
|
#endif /* WIN32 */
|
2002-10-13 09:40:44 +00:00
|
|
|
}
|
|
|
|
#endif /* FASTCGI */
|
2000-05-05 07:21:48 +00:00
|
|
|
|
2002-05-09 20:03:36 +00:00
|
|
|
zend_first_try {
|
2005-06-03 23:11:51 +00:00
|
|
|
while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 1)) != -1) {
|
2004-02-27 23:31:28 +00:00
|
|
|
switch (c) {
|
|
|
|
case 'h':
|
|
|
|
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;
|
2002-05-09 20:03:36 +00:00
|
|
|
}
|
|
|
|
}
|
2004-02-27 23:31:28 +00:00
|
|
|
php_optind = orig_optind;
|
|
|
|
php_optarg = orig_optarg;
|
1999-04-25 19:36:57 +00:00
|
|
|
|
2002-11-26 05:51:16 +00:00
|
|
|
#if PHP_FASTCGI
|
2002-05-09 20:03:36 +00:00
|
|
|
/* start of FAST CGI loop */
|
2002-10-13 09:40:44 +00:00
|
|
|
/* Initialise FastCGI request structure */
|
2002-03-18 04:48:34 +00:00
|
|
|
#ifdef PHP_WIN32
|
2002-05-09 20:03:36 +00:00
|
|
|
/* attempt to set security impersonation for fastcgi
|
|
|
|
will only happen on NT based OS, others will ignore it. */
|
2006-11-14 10:31:47 +00:00
|
|
|
if (fastcgi && CGIG(impersonate)) {
|
|
|
|
fcgi_impersonate();
|
2002-05-09 20:03:36 +00:00
|
|
|
}
|
2002-03-18 04:48:34 +00:00
|
|
|
#endif
|
2006-05-15 14:30:31 +00:00
|
|
|
while (!fastcgi || fcgi_accept_request(&request) >= 0) {
|
2002-03-10 21:39:28 +00:00
|
|
|
#endif
|
|
|
|
|
2002-11-26 05:51:16 +00:00
|
|
|
#if PHP_FASTCGI
|
2002-10-13 09:40:44 +00:00
|
|
|
SG(server_context) = (void *) &request;
|
|
|
|
#else
|
2002-05-09 20:03:36 +00:00
|
|
|
SG(server_context) = (void *) 1; /* avoid server_context==NULL checks */
|
2002-10-13 09:40:44 +00:00
|
|
|
#endif
|
|
|
|
init_request_info(TSRMLS_C);
|
2002-12-01 21:37:14 +00:00
|
|
|
CG(interactive) = 0;
|
|
|
|
|
2002-11-12 16:41:14 +00:00
|
|
|
if (!cgi
|
2002-11-26 05:51:16 +00:00
|
|
|
#if PHP_FASTCGI
|
2002-05-09 20:03:36 +00:00
|
|
|
&& !fastcgi
|
2002-03-10 21:39:28 +00:00
|
|
|
#endif
|
2005-06-03 23:11:51 +00:00
|
|
|
) {
|
2002-11-12 20:56:47 +00:00
|
|
|
if (cgi_sapi_module.php_ini_path_override && cgi_sapi_module.php_ini_ignore) {
|
2003-01-07 16:33:28 +00:00
|
|
|
no_headers = 1;
|
2002-11-12 20:56:47 +00:00
|
|
|
php_output_startup();
|
|
|
|
php_output_activate(TSRMLS_C);
|
|
|
|
SG(headers_sent) = 1;
|
|
|
|
php_printf("You cannot use both -n and -c switch. Use -h for help.\n");
|
|
|
|
php_end_ob_buffers(1 TSRMLS_CC);
|
|
|
|
exit(1);
|
|
|
|
}
|
2003-01-07 16:33:28 +00:00
|
|
|
|
2004-02-11 21:00:46 +00:00
|
|
|
while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0)) != -1) {
|
2002-05-09 20:03:36 +00:00
|
|
|
switch (c) {
|
2003-01-07 16:33:28 +00:00
|
|
|
|
2002-05-09 20:03:36 +00:00
|
|
|
case 'a': /* interactive mode */
|
|
|
|
printf("Interactive mode enabled\n\n");
|
2003-08-17 18:36:27 +00:00
|
|
|
CG(interactive) = 1;
|
2002-05-09 20:03:36 +00:00
|
|
|
break;
|
2003-01-07 16:33:28 +00:00
|
|
|
|
2002-05-09 20:03:36 +00:00
|
|
|
case 'C': /* don't chdir to the script directory */
|
|
|
|
SG(options) |= SAPI_OPTION_NO_CHDIR;
|
|
|
|
break;
|
2003-01-07 16:33:28 +00:00
|
|
|
|
2002-05-09 20:03:36 +00:00
|
|
|
case 'e': /* enable extended info output */
|
|
|
|
CG(extended_info) = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'f': /* parse file */
|
2004-02-11 21:00:46 +00:00
|
|
|
script_file = estrdup(php_optarg);
|
2002-05-09 20:03:36 +00:00
|
|
|
no_headers = 1;
|
2003-05-19 06:46:19 +00:00
|
|
|
/* arguments after the file are considered script args */
|
2005-06-03 23:11:51 +00:00
|
|
|
SG(request_info).argc = argc - (php_optind - 1);
|
|
|
|
SG(request_info).argv = &argv[php_optind - 1];
|
2002-05-09 20:03:36 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'i': /* php info & quit */
|
2003-03-29 16:13:51 +00:00
|
|
|
if (php_request_startup(TSRMLS_C) == FAILURE) {
|
2002-05-09 20:03:36 +00:00
|
|
|
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);
|
2005-10-06 20:29:41 +00:00
|
|
|
exit(0);
|
2002-05-09 20:03:36 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'l': /* syntax check mode */
|
|
|
|
no_headers = 1;
|
2005-06-03 23:11:51 +00:00
|
|
|
behavior = PHP_MODE_LINT;
|
2002-05-09 20:03:36 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'm': /* list compiled in modules */
|
|
|
|
php_output_startup();
|
|
|
|
php_output_activate(TSRMLS_C);
|
|
|
|
SG(headers_sent) = 1;
|
|
|
|
php_printf("[PHP Modules]\n");
|
2002-11-14 20:32:28 +00:00
|
|
|
print_modules(TSRMLS_C);
|
2002-05-09 20:03:36 +00:00
|
|
|
php_printf("\n[Zend Modules]\n");
|
2002-11-14 20:32:28 +00:00
|
|
|
print_extensions(TSRMLS_C);
|
2002-05-09 20:03:36 +00:00
|
|
|
php_printf("\n");
|
|
|
|
php_end_ob_buffers(1 TSRMLS_CC);
|
2005-10-06 20:29:41 +00:00
|
|
|
exit(0);
|
2002-05-09 20:03:36 +00:00
|
|
|
break;
|
2000-07-28 15:21:20 +00:00
|
|
|
|
|
|
|
#if 0 /* not yet operational, see also below ... */
|
2003-01-07 16:33:28 +00:00
|
|
|
case '': /* generate indented source mode*/
|
2002-05-09 20:03:36 +00:00
|
|
|
behavior=PHP_MODE_INDENT;
|
|
|
|
break;
|
1999-04-25 19:36:57 +00:00
|
|
|
#endif
|
2000-07-28 15:21:20 +00:00
|
|
|
|
2002-05-09 20:03:36 +00:00
|
|
|
case 'q': /* do not generate HTTP headers */
|
|
|
|
no_headers = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 's': /* generate highlighted HTML from source */
|
2005-06-03 23:11:51 +00:00
|
|
|
behavior = PHP_MODE_HIGHLIGHT;
|
2002-05-09 20:03:36 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'v': /* show php version & quit */
|
|
|
|
no_headers = 1;
|
2003-03-29 16:13:51 +00:00
|
|
|
if (php_request_startup(TSRMLS_C) == FAILURE) {
|
2002-05-09 20:03:36 +00:00
|
|
|
php_module_shutdown(TSRMLS_C);
|
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
if (no_headers) {
|
|
|
|
SG(headers_sent) = 1;
|
|
|
|
SG(request_info).no_headers = 1;
|
|
|
|
}
|
2003-05-30 16:10:58 +00:00
|
|
|
#if ZEND_DEBUG
|
2007-01-01 09:36:18 +00:00
|
|
|
php_printf("PHP %s (%s) (built: %s %s) (DEBUG)\nCopyright (c) 1997-2007 The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version());
|
2003-05-30 16:10:58 +00:00
|
|
|
#else
|
2007-01-01 09:36:18 +00:00
|
|
|
php_printf("PHP %s (%s) (built: %s %s)\nCopyright (c) 1997-2007 The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version());
|
2003-05-30 16:10:58 +00:00
|
|
|
#endif
|
2002-05-09 20:03:36 +00:00
|
|
|
php_end_ob_buffers(1 TSRMLS_CC);
|
2005-10-06 20:29:41 +00:00
|
|
|
exit(0);
|
2002-05-09 20:03:36 +00:00
|
|
|
break;
|
|
|
|
|
2003-01-07 16:33:28 +00:00
|
|
|
case 'w':
|
2005-06-03 23:11:51 +00:00
|
|
|
behavior = PHP_MODE_STRIP;
|
2002-05-09 20:03:36 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'z': /* load extension file */
|
2004-02-11 21:00:46 +00:00
|
|
|
zend_load_extension(php_optarg);
|
2002-05-09 20:03:36 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-05-19 03:40:33 +00:00
|
|
|
if (script_file) {
|
|
|
|
/* override path_translated if -f on command line */
|
2006-05-03 19:40:58 +00:00
|
|
|
STR_FREE(SG(request_info).path_translated);
|
2003-05-19 03:40:33 +00:00
|
|
|
SG(request_info).path_translated = script_file;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (no_headers) {
|
|
|
|
SG(headers_sent) = 1;
|
|
|
|
SG(request_info).no_headers = 1;
|
|
|
|
}
|
|
|
|
|
2004-02-11 21:00:46 +00:00
|
|
|
if (!SG(request_info).path_translated && argc > php_optind) {
|
2003-05-19 06:46:19 +00:00
|
|
|
/* arguments after the file are considered script args */
|
2004-02-11 21:00:46 +00:00
|
|
|
SG(request_info).argc = argc - php_optind;
|
|
|
|
SG(request_info).argv = &argv[php_optind];
|
2003-05-19 03:40:33 +00:00
|
|
|
/* file is on command line, but not in -f opt */
|
2004-02-11 21:00:46 +00:00
|
|
|
SG(request_info).path_translated = estrdup(argv[php_optind++]);
|
2003-05-19 03:40:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* all remaining arguments are part of the query string
|
|
|
|
this section of code concatenates all remaining arguments
|
|
|
|
into a single string, seperating args with a &
|
|
|
|
this allows command lines like:
|
|
|
|
|
|
|
|
test.php v1=test v2=hello+world!
|
|
|
|
test.php "v1=test&v2=hello world!"
|
|
|
|
test.php v1=test "v2=hello world!"
|
|
|
|
*/
|
2004-02-11 21:00:46 +00:00
|
|
|
if (!SG(request_info).query_string && argc > php_optind) {
|
2002-05-09 20:03:36 +00:00
|
|
|
len = 0;
|
2004-02-11 21:00:46 +00:00
|
|
|
for (i = php_optind; i < argc; i++) {
|
2002-05-09 20:03:36 +00:00
|
|
|
len += strlen(argv[i]) + 1;
|
|
|
|
}
|
|
|
|
|
2006-06-19 17:49:26 +00:00
|
|
|
s = malloc(len + 1);
|
2002-05-09 20:03:36 +00:00
|
|
|
*s = '\0'; /* we are pretending it came from the environment */
|
2004-02-11 21:00:46 +00:00
|
|
|
for (i = php_optind, len = 0; i < argc; i++) {
|
2002-05-09 20:03:36 +00:00
|
|
|
strcat(s, argv[i]);
|
|
|
|
if (i < (argc - 1)) {
|
2003-05-30 22:31:12 +00:00
|
|
|
strcat(s, PG(arg_separator).input);
|
2002-05-09 20:03:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
SG(request_info).query_string = s;
|
2006-06-19 17:49:26 +00:00
|
|
|
free_query_string = 1;
|
2002-05-09 20:03:36 +00:00
|
|
|
}
|
2003-02-13 18:21:12 +00:00
|
|
|
} /* end !cgi && !fastcgi */
|
|
|
|
|
|
|
|
/*
|
|
|
|
we never take stdin if we're (f)cgi, always
|
|
|
|
rely on the web server giving us the info
|
|
|
|
we need in the environment.
|
|
|
|
*/
|
2003-05-26 00:46:24 +00:00
|
|
|
if (SG(request_info).path_translated || cgi
|
2002-11-26 05:51:16 +00:00
|
|
|
#if PHP_FASTCGI
|
2003-02-13 19:46:40 +00:00
|
|
|
|| fastcgi
|
2003-02-13 18:21:12 +00:00
|
|
|
#endif
|
2003-02-13 19:46:40 +00:00
|
|
|
)
|
2003-02-13 18:21:12 +00:00
|
|
|
{
|
2002-05-09 20:03:36 +00:00
|
|
|
file_handle.type = ZEND_HANDLE_FILENAME;
|
|
|
|
file_handle.filename = SG(request_info).path_translated;
|
2003-01-25 22:01:53 +00:00
|
|
|
file_handle.handle.fp = NULL;
|
2002-05-09 20:03:36 +00:00
|
|
|
} else {
|
|
|
|
file_handle.filename = "-";
|
|
|
|
file_handle.type = ZEND_HANDLE_FP;
|
|
|
|
file_handle.handle.fp = stdin;
|
|
|
|
}
|
2003-02-13 18:21:12 +00:00
|
|
|
|
2002-05-09 20:03:36 +00:00
|
|
|
file_handle.opened_path = NULL;
|
|
|
|
file_handle.free_filename = 0;
|
2001-07-21 14:27:56 +00:00
|
|
|
|
2002-12-01 21:37:14 +00:00
|
|
|
/* request startup only after we've done all we can to
|
|
|
|
get path_translated */
|
2005-06-03 23:11:51 +00:00
|
|
|
if (php_request_startup(TSRMLS_C) == FAILURE) {
|
2003-06-29 20:09:36 +00:00
|
|
|
#if PHP_FASTCGI
|
|
|
|
if (fastcgi) {
|
2006-05-15 14:30:31 +00:00
|
|
|
fcgi_finish_request(&request);
|
2003-06-29 20:09:36 +00:00
|
|
|
}
|
|
|
|
#endif
|
2002-12-25 21:18:37 +00:00
|
|
|
php_module_shutdown(TSRMLS_C);
|
|
|
|
return FAILURE;
|
|
|
|
}
|
2002-12-25 20:38:37 +00:00
|
|
|
if (no_headers) {
|
|
|
|
SG(headers_sent) = 1;
|
|
|
|
SG(request_info).no_headers = 1;
|
|
|
|
}
|
2002-11-26 05:51:16 +00:00
|
|
|
|
2003-02-13 18:21:12 +00:00
|
|
|
/*
|
|
|
|
at this point path_translated will be set if:
|
|
|
|
1. we are running from shell and got filename was there
|
|
|
|
2. we are running as cgi or fastcgi
|
|
|
|
*/
|
2002-05-09 20:03:36 +00:00
|
|
|
if (cgi || SG(request_info).path_translated) {
|
|
|
|
retval = php_fopen_primary_script(&file_handle TSRMLS_CC);
|
|
|
|
}
|
2003-02-13 18:21:12 +00:00
|
|
|
/*
|
|
|
|
if we are unable to open path_translated and we are not
|
|
|
|
running from shell (so fp == NULL), then fail.
|
|
|
|
*/
|
2003-02-17 03:39:58 +00:00
|
|
|
if (retval == FAILURE && file_handle.handle.fp == NULL) {
|
2003-02-13 18:21:12 +00:00
|
|
|
SG(sapi_headers).http_response_code = 404;
|
|
|
|
PUTS("No input file specified.\n");
|
2003-06-29 20:09:36 +00:00
|
|
|
#if PHP_FASTCGI
|
|
|
|
/* we want to serve more requests if this is fastcgi
|
|
|
|
so cleanup and continue, request shutdown is
|
|
|
|
handled later */
|
|
|
|
if (fastcgi) {
|
|
|
|
goto fastcgi_request_done;
|
|
|
|
}
|
|
|
|
#endif
|
2003-02-13 18:21:12 +00:00
|
|
|
php_request_shutdown((void *) 0);
|
|
|
|
php_module_shutdown(TSRMLS_C);
|
|
|
|
return FAILURE;
|
2003-01-07 16:33:28 +00:00
|
|
|
}
|
2002-05-09 20:03:36 +00:00
|
|
|
|
2006-11-14 10:31:47 +00:00
|
|
|
if (CGIG(check_shebang_line) && file_handle.handle.fp && (file_handle.handle.fp != stdin)) {
|
2002-05-09 20:03:36 +00:00
|
|
|
/* #!php support */
|
|
|
|
c = fgetc(file_handle.handle.fp);
|
|
|
|
if (c == '#') {
|
2006-06-27 08:27:10 +00:00
|
|
|
while (c != '\n' && c != '\r') {
|
2002-05-09 20:03:36 +00:00
|
|
|
c = fgetc(file_handle.handle.fp); /* skip to end of line */
|
|
|
|
}
|
2003-01-08 00:41:53 +00:00
|
|
|
/* handle situations where line is terminated by \r\n */
|
2006-06-27 08:27:10 +00:00
|
|
|
if (c == '\r') {
|
|
|
|
if (fgetc(file_handle.handle.fp) != '\n') {
|
2003-01-08 00:41:53 +00:00
|
|
|
long pos = ftell(file_handle.handle.fp);
|
|
|
|
fseek(file_handle.handle.fp, pos - 1, SEEK_SET);
|
|
|
|
}
|
|
|
|
}
|
2003-01-05 16:10:35 +00:00
|
|
|
CG(start_lineno) = 2;
|
2002-05-09 20:03:36 +00:00
|
|
|
} else {
|
|
|
|
rewind(file_handle.handle.fp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (behavior) {
|
|
|
|
case PHP_MODE_STANDARD:
|
2002-05-26 13:12:30 +00:00
|
|
|
php_execute_script(&file_handle TSRMLS_CC);
|
2002-05-09 20:03:36 +00:00
|
|
|
break;
|
|
|
|
case PHP_MODE_LINT:
|
|
|
|
PG(during_request_startup) = 0;
|
|
|
|
exit_status = php_lint_script(&file_handle TSRMLS_CC);
|
2003-03-29 16:13:51 +00:00
|
|
|
if (exit_status == SUCCESS) {
|
2002-05-09 20:03:36 +00:00
|
|
|
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:
|
2003-03-29 16:13:51 +00:00
|
|
|
if (open_file_for_scanning(&file_handle TSRMLS_CC) == SUCCESS) {
|
2002-05-09 20:03:36 +00:00
|
|
|
zend_strip(TSRMLS_C);
|
|
|
|
fclose(file_handle.handle.fp);
|
2003-08-13 02:01:46 +00:00
|
|
|
php_end_ob_buffers(1 TSRMLS_CC);
|
2002-05-09 20:03:36 +00:00
|
|
|
}
|
|
|
|
return SUCCESS;
|
|
|
|
break;
|
|
|
|
case PHP_MODE_HIGHLIGHT:
|
|
|
|
{
|
|
|
|
zend_syntax_highlighter_ini syntax_highlighter_ini;
|
|
|
|
|
2003-03-29 16:13:51 +00:00
|
|
|
if (open_file_for_scanning(&file_handle TSRMLS_CC) == SUCCESS) {
|
2002-05-09 20:03:36 +00:00
|
|
|
php_get_highlight_struct(&syntax_highlighter_ini);
|
|
|
|
zend_highlight(&syntax_highlighter_ini TSRMLS_CC);
|
|
|
|
fclose(file_handle.handle.fp);
|
2003-08-13 02:01:46 +00:00
|
|
|
php_end_ob_buffers(1 TSRMLS_CC);
|
2002-05-09 20:03:36 +00:00
|
|
|
}
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
break;
|
2000-06-26 15:55:59 +00:00
|
|
|
#if 0
|
2002-05-09 20:03:36 +00:00
|
|
|
/* 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;
|
2000-06-26 15:55:59 +00:00
|
|
|
#endif
|
2002-05-09 20:03:36 +00:00
|
|
|
}
|
1999-04-25 19:36:57 +00:00
|
|
|
|
2003-06-29 20:09:36 +00:00
|
|
|
#if PHP_FASTCGI
|
|
|
|
fastcgi_request_done:
|
|
|
|
#endif
|
2002-06-22 13:53:44 +00:00
|
|
|
{
|
|
|
|
char *path_translated;
|
2003-01-07 16:33:28 +00:00
|
|
|
|
2002-06-22 13:53:44 +00:00
|
|
|
/* Go through this trouble so that the memory manager doesn't warn
|
|
|
|
* about SG(request_info).path_translated leaking
|
|
|
|
*/
|
|
|
|
if (SG(request_info).path_translated) {
|
|
|
|
path_translated = strdup(SG(request_info).path_translated);
|
|
|
|
STR_FREE(SG(request_info).path_translated);
|
|
|
|
SG(request_info).path_translated = path_translated;
|
|
|
|
}
|
2003-01-07 16:33:28 +00:00
|
|
|
|
2002-06-22 13:53:44 +00:00
|
|
|
php_request_shutdown((void *) 0);
|
2003-08-01 16:52:49 +00:00
|
|
|
if (exit_status == 0) {
|
|
|
|
exit_status = EG(exit_status);
|
|
|
|
}
|
2001-08-14 23:17:02 +00:00
|
|
|
|
2002-06-22 13:53:44 +00:00
|
|
|
if (SG(request_info).path_translated) {
|
|
|
|
free(SG(request_info).path_translated);
|
2002-12-01 21:37:14 +00:00
|
|
|
SG(request_info).path_translated = NULL;
|
2002-06-22 13:53:44 +00:00
|
|
|
}
|
2006-06-19 17:49:26 +00:00
|
|
|
if (free_query_string && SG(request_info).query_string) {
|
|
|
|
free(SG(request_info).query_string);
|
|
|
|
SG(request_info).query_string = NULL;
|
|
|
|
}
|
|
|
|
|
2002-06-22 13:53:44 +00:00
|
|
|
}
|
2001-08-14 23:17:02 +00:00
|
|
|
|
2002-11-26 05:51:16 +00:00
|
|
|
#if PHP_FASTCGI
|
2002-05-09 20:03:36 +00:00
|
|
|
if (!fastcgi) break;
|
|
|
|
/* only fastcgi will get here */
|
|
|
|
requests++;
|
2005-06-03 23:11:51 +00:00
|
|
|
if (max_requests && (requests == max_requests)) {
|
2006-05-15 14:30:31 +00:00
|
|
|
fcgi_finish_request(&request);
|
2003-06-29 20:45:38 +00:00
|
|
|
#ifndef PHP_WIN32
|
2003-03-29 16:13:51 +00:00
|
|
|
if (bindpath) {
|
|
|
|
free(bindpath);
|
|
|
|
}
|
2003-06-29 20:45:38 +00:00
|
|
|
#endif
|
2002-05-09 20:03:36 +00:00
|
|
|
break;
|
|
|
|
}
|
2002-10-13 09:40:44 +00:00
|
|
|
/* end of fastcgi loop */
|
2002-05-09 20:03:36 +00:00
|
|
|
}
|
2002-03-10 21:39:28 +00:00
|
|
|
#endif
|
|
|
|
|
2002-05-09 20:03:36 +00:00
|
|
|
if (cgi_sapi_module.php_ini_path_override) {
|
|
|
|
free(cgi_sapi_module.php_ini_path_override);
|
|
|
|
}
|
2006-09-19 20:33:12 +00:00
|
|
|
if (cgi_sapi_module.ini_entries) {
|
|
|
|
free(cgi_sapi_module.ini_entries);
|
|
|
|
}
|
2002-05-09 20:03:36 +00:00
|
|
|
} zend_catch {
|
|
|
|
exit_status = 255;
|
|
|
|
} zend_end_try();
|
2001-05-18 14:40:02 +00:00
|
|
|
|
2006-02-03 16:30:09 +00:00
|
|
|
SG(server_context) = NULL;
|
2002-05-09 20:03:36 +00:00
|
|
|
php_module_shutdown(TSRMLS_C);
|
2003-01-07 16:33:28 +00:00
|
|
|
sapi_shutdown();
|
2001-08-05 14:07:33 +00:00
|
|
|
|
2001-07-27 07:37:16 +00:00
|
|
|
#ifdef ZTS
|
2003-02-17 13:29:59 +00:00
|
|
|
/*tsrm_shutdown();*/
|
2001-07-27 07:37:16 +00:00
|
|
|
#endif
|
|
|
|
|
2005-12-03 01:28:16 +00:00
|
|
|
#if defined(PHP_WIN32) && ZEND_DEBUG && 0
|
2005-06-03 23:11:51 +00:00
|
|
|
_CrtDumpMemoryLeaks();
|
2002-08-07 18:16:44 +00:00
|
|
|
#endif
|
|
|
|
|
2002-05-09 20:03:36 +00:00
|
|
|
return exit_status;
|
1999-04-25 19:36:57 +00:00
|
|
|
}
|
2001-06-06 13:06:12 +00:00
|
|
|
/* }}} */
|
1999-04-26 19:48:10 +00:00
|
|
|
|
2000-08-27 19:46:06 +00:00
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* tab-width: 4
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* End:
|
2001-09-09 13:29:31 +00:00
|
|
|
* vim600: sw=4 ts=4 fdm=marker
|
|
|
|
* vim<600: sw=4 ts=4
|
2000-08-27 19:46:06 +00:00
|
|
|
*/
|