]> granicus.if.org Git - php/commitdiff
cgi.* and fastcgi.* directives are moved to INI subsystem. The new directive cgi...
authorDmitry Stogov <dmitry@php.net>
Tue, 14 Nov 2006 10:31:47 +0000 (10:31 +0000)
committerDmitry Stogov <dmitry@php.net>
Tue, 14 Nov 2006 10:31:47 +0000 (10:31 +0000)
NEWS
sapi/cgi/cgi_main.c

diff --git a/NEWS b/NEWS
index 513aa3f11eecae77bef87f962956b3cd3f2ddb3e..447e6db603e01ac41a748717be3d01257c84b269 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,9 @@
 PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? ??? 2007, PHP 5.2.1
+- cgi.* and fastcgi.* directives are moved to INI subsystem.
+  The new directive cgi.check_shebang_line can be used to ommiting checnk
+  for "#! /usr/bin/php" line. (Dmitry).
 - Windows related optimizations (Dmitry, Stas)
   . removed unnecessary checks for ISREG file and corresponding stat() calls
   . opendir() is reimplemented using GetFistFile/GetNextFile those are faster
index 866ccd90c7760a1bf380aa46ecb1f0cd670830b9..2341be38e2a1272f44b5289c6f41d1919eac8ec7 100644 (file)
@@ -145,17 +145,32 @@ static const opt_struct OPTIONS[] = {
        {'-', 0, NULL} /* end of args */
 };
 
+typedef struct _php_cgi_globals_struct {
+       zend_bool rfc2616_headers;
+       zend_bool nph;
+       zend_bool check_shebang_line;
 #if ENABLE_PATHINFO_CHECK
-/* true global.  this is retreived once only, even for fastcgi */
-long fix_pathinfo = 1;
+       zend_bool fix_pathinfo;
+#endif
+#if FORCE_CGI_REDIRECT
+       zend_bool force_redirect;
+       char *redirect_status_env;
 #endif
-
 #if PHP_FASTCGI
-long fcgi_logging = 1;
+       zend_bool fcgi_logging;
+# ifdef PHP_WIN32
+       zend_bool impersonate;
+# endif
 #endif
+} php_cgi_globals_struct;
 
-static long rfc2616_headers = 0;
-static long cgi_nph = 0;
+#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
 
 #ifdef PHP_WIN32
 #define TRANSLATE_SLASHES(path) \
@@ -304,11 +319,11 @@ static int sapi_cgi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC)
                return  SAPI_HEADER_SENT_SUCCESSFULLY;
        }
 
-       if (cgi_nph || SG(sapi_headers).http_response_code != 200)
+       if (CGIG(nph) || SG(sapi_headers).http_response_code != 200)
        {
                int len;
 
-               if (rfc2616_headers && SG(sapi_headers).http_status_line) {
+               if (CGIG(rfc2616_headers) && SG(sapi_headers).http_status_line) {
                        len = snprintf(buf, SAPI_CGI_MAX_HEADER_LENGTH,
                                                   "%s\r\n", SG(sapi_headers).http_status_line);
 
@@ -517,9 +532,10 @@ static void sapi_cgi_register_variables(zval *track_vars_array TSRMLS_DC)
 static void sapi_cgi_log_message(char *message)
 {
 #if PHP_FASTCGI
-       if (fcgi_is_fastcgi() && fcgi_logging) {
+       TSRMLS_FETCH();
+
+       if (fcgi_is_fastcgi() && CGIG(fcgi_logging)) {
                fcgi_request *request;
-               TSRMLS_FETCH();
                
                request = (fcgi_request*) SG(server_context);
                if (request) {                  
@@ -744,7 +760,7 @@ static void init_request_info(TSRMLS_D)
                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);
 
-               if (fix_pathinfo) {
+               if (CGIG(fix_pathinfo)) {
 
                        /* save the originals first for anything we change later */
                        if (env_path_translated) {
@@ -963,6 +979,96 @@ static int is_port_number(const char *bindpath)
 #endif
 #endif
 
+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
+};
+
 /* {{{ main
  */
 int main(int argc, char *argv[])
@@ -980,10 +1086,6 @@ int main(int argc, char *argv[])
        char *orig_optarg = php_optarg;
        char *script_file = NULL;
        int ini_entries_len = 0;
-#if FORCE_CGI_REDIRECT
-       long force_redirect = 1;
-       char *redirect_status_env = NULL;
-#endif
 
 /* end of temporary locals */
 #ifdef ZTS
@@ -1003,9 +1105,7 @@ int main(int argc, char *argv[])
 #endif
        int fcgi_fd = 0;
        fcgi_request request;
-#ifdef PHP_WIN32
-       long impersonate = 0;
-#else
+#ifndef PHP_WIN32
        int status = 0;
 #endif
 #endif /* PHP_FASTCGI */
@@ -1130,7 +1230,7 @@ int main(int argc, char *argv[])
        cgi_sapi_module.executable_location = argv[0];
 
        /* startup after we get the above ini override se we get things right */
-       if (php_module_startup(&cgi_sapi_module, NULL, 0) == FAILURE) {
+       if (php_module_startup(&cgi_sapi_module, &cgi_module_entry, 1) == FAILURE) {
 #ifdef ZTS
                tsrm_shutdown();
 #endif
@@ -1139,13 +1239,7 @@ int main(int argc, char *argv[])
 
 #if FORCE_CGI_REDIRECT
        /* check force_cgi after startup, so we have proper output */
-       if (cfg_get_long("cgi.force_redirect", &force_redirect) == FAILURE) {
-               force_redirect = 1;
-       }
-       if (cgi && force_redirect) {
-               if (cfg_get_string("cgi.redirect_status_env", &redirect_status_env) == FAILURE) {
-                       redirect_status_env = NULL;
-               }
+       if (cgi && CGIG(force_redirect)) {
                /* Apache will generate REDIRECT_STATUS,
                 * Netscape and redirect.so will generate HTTP_REDIRECT_STATUS.
                 * redirect.so and installation instructions available from
@@ -1156,7 +1250,7 @@ int main(int argc, char *argv[])
                        && !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))
+                       && (!CGIG(redirect_status_env) || !getenv(CGIG(redirect_status_env)))
                        ) {
                        SG(sapi_headers).http_response_code = 400;
                        PUTS("<b>Security Alert!</b> The PHP CGI cannot be accessed directly.\n\n\
@@ -1183,31 +1277,6 @@ consult the installation file that came with this distribution, or visit \n\
        }
 #endif /* FORCE_CGI_REDIRECT */
 
-#if ENABLE_PATHINFO_CHECK
-       if (cfg_get_long("cgi.fix_pathinfo", &fix_pathinfo) == FAILURE) {
-               fix_pathinfo = 1;
-       }
-#endif
-
-#if PHP_FASTCGI
-       if (cfg_get_long("fastcgi.logging", &fcgi_logging) == FAILURE) {
-               fcgi_logging = 1;
-       }
-#endif
-
-       /* Check wheater to send RFC2616 style headers compatible with
-        * PHP versions 4.2.3 and earlier compatible with web servers
-        * such as IIS. Default is informal CGI RFC header compatible
-        * with Apache.
-        */
-       if (cfg_get_long("cgi.rfc2616_headers", &rfc2616_headers) == FAILURE) {
-               rfc2616_headers = 0;
-       }
-
-       if (cfg_get_long("cgi.nph", &cgi_nph) == FAILURE) {
-               cgi_nph = 0;
-       }
-
 #if PHP_FASTCGI
 #ifndef PHP_WIN32
        /* for windows, socket listening is broken in the fastcgi library itself
@@ -1358,11 +1427,8 @@ consult the installation file that came with this distribution, or visit \n\
 #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) fcgi_impersonate();
+               if (fastcgi && CGIG(impersonate)) {
+                       fcgi_impersonate();
                }
 #endif
                while (!fastcgi || fcgi_accept_request(&request) >= 0) {
@@ -1607,7 +1673,7 @@ consult the installation file that came with this distribution, or visit \n\
                        return FAILURE;
                }
 
-               if (file_handle.handle.fp && (file_handle.handle.fp != stdin)) {
+               if (CGIG(check_shebang_line) && file_handle.handle.fp && (file_handle.handle.fp != stdin)) {
                        /* #!php support */
                        c = fgetc(file_handle.handle.fp);
                        if (c == '#') {