Permalink
Browse files

Tried to centralize global variable registration as much as possible:

- Added $HTTP_ENV_VARS[] and $HTTP_SERVER_VARS[] support, which similarly
  to $HTTP_GET_VARS[], contain environment and server variables.  Setting
  register_globals to Off will now also prevent registration of the
  environment and server variables into the global scope (Zeev)
- Renamed gpc_globals to register_globals (Zeev)
- Introduced variables_order that deprecates gpc_order, and allows control
  over the server and environment variables, in addition to GET/POST/Cookies
  (Zeev)
  • Loading branch information...
1 parent 270eff1 commit 9ab35ae39367bcd30037c6bfc73ae0c77c35d872 @zsuraski zsuraski committed Jan 28, 2000
View
@@ -14,7 +14,7 @@ LTLIBRARY_SOURCES = \
configuration-parser.c configuration-scanner.c request_info.c \
safe_mode.c fopen-wrappers.c php_realpath.c alloca.c \
php_ini.c SAPI.c rfc1867.c dlist.c php_content_types.c strlcpy.c \
- strlcat.c mergesort.c reentrancy.c php_gpce.c
+ strlcat.c mergesort.c reentrancy.c php_variables.c
LTLIBRARY_DEPENDENCIES = \
Zend/libZend.la \
View
8 NEWS
@@ -2,6 +2,14 @@ PHP 4.0 NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ?? ????, Version 4.0 Beta 4
+- Added $HTTP_ENV_VARS[] and $HTTP_SERVER_VARS[] support, which similarly
+ to $HTTP_GET_VARS[], contain environment and server variables. Setting
+ register_globals to Off will now also prevent registration of the
+ environment and server variables into the global scope (Zeev)
+- Renamed gpc_globals to register_globals (Zeev)
+- Introduced variables_order that deprecates gpc_order, and allows control
+ over the server and environment variables, in addition to GET/POST/Cookies
+ (Zeev)
- new function cpdf_set_document_limits() (Uwe)
- Applied safe-mode patch to popen(). (Patch by Kristian K�hntopp)
- str_repeat() now returns correct length. (Thies)
View
@@ -416,6 +416,7 @@ PHP_FUNCTION(apache_lookup_uri)
}
/* }}} */
+
#if 0
This function is most likely a bad idea. Just playing with it for now.
View
@@ -26,7 +26,7 @@
#include "php.h"
#include "reg.h"
#include "php_string.h"
-#include "php_gpce.h"
+#include "php_variables.h"
#ifdef HAVE_LOCALE_H
# include <locale.h>
#endif
View
@@ -147,6 +147,8 @@ struct _sapi_module_struct {
int (*read_post)(char *buffer, uint count_bytes SLS_DC);
char *(*read_cookies)(SLS_D);
+ void (*register_server_variables)(zval *track_vars_array ELS_DC SLS_DC PLS_DC);
+
void (*default_post_reader)(char *content_type_dup SLS_DC);
};
View
@@ -50,7 +50,7 @@
#include "fopen-wrappers.h"
#include "ext/standard/php_standard.h"
#include "snprintf.h"
-#include "php_gpce.h"
+#include "php_variables.h"
#if WIN32|WINNT
#include <io.h>
#include <fcntl.h>
@@ -251,8 +251,9 @@ PHP_INI_BEGIN()
#endif
STD_PHP_INI_BOOLEAN("gpc_globals", "1", PHP_INI_ALL, OnUpdateBool, gpc_globals, php_core_globals, core_globals)
- STD_PHP_INI_ENTRY("gpc_order", "GPC", PHP_INI_ALL, OnUpdateStringUnempty, gpc_order, php_core_globals, core_globals)
- STD_PHP_INI_ENTRY("arg_separator", "&", PHP_INI_ALL, OnUpdateStringUnempty, arg_separator, php_core_globals, core_globals)
+ STD_PHP_INI_ENTRY("gpc_order", "GPC", PHP_INI_ALL, OnUpdateStringUnempty, gpc_order, php_core_globals, core_globals)
+ STD_PHP_INI_ENTRY("variables_order", NULL, PHP_INI_ALL, OnUpdateStringUnempty, variables_order, php_core_globals, core_globals)
+ STD_PHP_INI_ENTRY("arg_separator", "&", PHP_INI_ALL, OnUpdateStringUnempty, arg_separator, php_core_globals, core_globals)
STD_PHP_INI_BOOLEAN("ignore_user_abort", "1", PHP_INI_ALL, OnUpdateBool, ignore_user_abort, php_core_globals, core_globals)
PHP_INI_END()
@@ -702,24 +703,10 @@ int php_request_startup(CLS_D ELS_DC PLS_DC SLS_DC)
}
if (SG(request_info).auth_user) {
- zval *auth_user;
-
- MAKE_STD_ZVAL(auth_user);
- auth_user->type = IS_STRING;
- auth_user->value.str.val = SG(request_info).auth_user;
- auth_user->value.str.len = strlen(auth_user->value.str.val);
-
- zend_hash_update(&EG(symbol_table), "PHP_AUTH_USER", sizeof("PHP_AUTH_USER"), &auth_user, sizeof(zval *), NULL);
+ php_register_variable(SG(request_info).auth_user, "PHP_AUTH_USER", NULL ELS_CC PLS_CC);
}
if (SG(request_info).auth_password) {
- zval *auth_password;
-
- MAKE_STD_ZVAL(auth_password);
- auth_password->type = IS_STRING;
- auth_password->value.str.val = SG(request_info).auth_password;
- auth_password->value.str.len = strlen(auth_password->value.str.val);
-
- zend_hash_update(&EG(symbol_table), "PHP_AUTH_PW", sizeof("PHP_AUTH_PW"), &auth_password, sizeof(zval *), NULL);
+ php_register_variable(SG(request_info).auth_password, "PHP_AUTH_PW", NULL ELS_CC PLS_CC);
}
return SUCCESS;
@@ -1009,14 +996,35 @@ void php_module_shutdown()
}
-/* in 3.1 some of this should move into sapi */
-static int zend_hash_environment(PLS_D ELS_DC SLS_DC)
+static inline void php_register_server_variables(ELS_D SLS_DC PLS_DC)
+{
+ zval *array_ptr=NULL;
+
+ if (PG(track_vars)) {
+ ALLOC_ZVAL(array_ptr);
+ array_init(array_ptr);
+ INIT_PZVAL(array_ptr);
+ zend_hash_add(&EG(symbol_table), "HTTP_SERVER_VARS", sizeof("HTTP_ENV_VARS"), &array_ptr, sizeof(pval *),NULL);
+ }
+ sapi_module.register_server_variables(array_ptr ELS_CC SLS_CC PLS_CC);
+}
+
+
+static int zend_hash_environment(ELS_D SLS_DC PLS_DC)
{
- char **env, *p, *t;
+ char *p;
unsigned char _gpc_flags[3] = {0,0,0};
- pval *tmp;
-
- p = PG(gpc_order);
+ zend_bool have_variables_order;
+
+ if (PG(variables_order)) {
+ p = PG(variables_order);
+ have_variables_order=1;
+ } else {
+ p = PG(gpc_order);
+ have_variables_order=0;
+ php_import_environment_variables(ELS_C PLS_CC);
+ }
+
while(*p) {
switch(*p++) {
case 'p':
@@ -1040,94 +1048,27 @@ static int zend_hash_environment(PLS_D ELS_DC SLS_DC)
_gpc_flags[2]=1;
}
break;
+ case 'e':
+ case 'E':
+ if (have_variables_order) {
+ php_import_environment_variables(ELS_C PLS_CC);
+ } else {
+ php_error(E_CORE_WARNING, "Unsupported 'e' element (environment) used in gpc_order - use variables_order instead");
+ }
+ break;
+ case 's':
+ case 'S':
+ if (sapi_module.register_server_variables) {
+ php_register_server_variables(ELS_C SLS_CC PLS_CC);
+ }
+ break;
}
}
-
- for (env = environ; env != NULL && *env != NULL; env++) {
- p = strchr(*env, '=');
- if (!p) { /* malformed entry? */
- continue;
- }
- t = estrndup(*env, p - *env);
- ALLOC_ZVAL(tmp);
- tmp->value.str.len = strlen(p + 1);
- tmp->value.str.val = estrndup(p + 1, tmp->value.str.len);
- tmp->type = IS_STRING;
- INIT_PZVAL(tmp);
- /* environmental variables never take precedence over get/post/cookie variables */
- zend_hash_add(&EG(symbol_table), t, p - *env + 1, &tmp, sizeof(pval *), NULL);
- efree(t);
- }
-#if APACHE
- {
- pval **tmp_ptr;
- register int i;
- array_header *arr = table_elts(((request_rec *) SG(server_context))->subprocess_env);
- table_entry *elts = (table_entry *) arr->elts;
- int len;
-
- for (i = 0; i < arr->nelts; i++) {
- len = strlen(elts[i].key);
- t = elts[i].key;
- ALLOC_ZVAL(tmp);
- if (elts[i].val) {
- tmp->value.str.len = strlen(elts[i].val);
- tmp->value.str.val = estrndup(elts[i].val, tmp->value.str.len);
- } else {
- tmp->value.str.len = 0;
- tmp->value.str.val = empty_string;
- }
- INIT_PZVAL(tmp);
- tmp->type = IS_STRING;
- zend_hash_update(&EG(symbol_table), t, strlen(t)+1, &tmp, sizeof(pval *), NULL);
- }
- /* insert special variables */
- if (zend_hash_find(&EG(symbol_table), "SCRIPT_FILENAME", sizeof("SCRIPT_FILENAME"), (void **) &tmp_ptr) == SUCCESS) {
- (*tmp_ptr)->refcount++;
- zend_hash_update(&EG(symbol_table), "PATH_TRANSLATED", sizeof("PATH_TRANSLATED"), tmp_ptr, sizeof(pval *), NULL);
- }
- ALLOC_ZVAL(tmp);
- tmp->value.str.len = strlen(((request_rec *) SG(server_context))->uri);
- tmp->value.str.val = estrndup(((request_rec *) SG(server_context))->uri, tmp->value.str.len);
- INIT_PZVAL(tmp);
- tmp->type = IS_STRING;
- zend_hash_update(&EG(symbol_table), "PHP_SELF", sizeof("PHP_SELF"), (void *) &tmp, sizeof(pval *), NULL);
+ if (!have_variables_order) {
+ php_register_server_variables(ELS_C SLS_CC PLS_CC);
}
-#else
- {
- /* Build the special-case PHP_SELF variable for the CGI version */
- char *pi;
-#if FORCE_CGI_REDIRECT
- pi = SG(request_info).request_uri;
- ALLOC_ZVAL(tmp);
- tmp->value.str.val = emalloc(((pi)?strlen(pi):0) + 1);
- tmp->value.str.len = php_sprintf(tmp->value.str.val, "%s", (pi ? pi : "")); /* SAFE */
- tmp->type = IS_STRING;
- INIT_PZVAL(tmp);
-#else
- int l = 0;
- char *sn;
- sn = request_info.script_name;
- pi = SG(request_info).request_uri;
- if (sn)
- l += strlen(sn);
- if (pi)
- l += strlen(pi);
- if (pi && sn && !strcmp(pi, sn)) {
- l -= strlen(pi);
- pi = NULL;
- }
- ALLOC_ZVAL(tmp);
- tmp->value.str.val = emalloc(l + 1);
- tmp->value.str.len = php_sprintf(tmp->value.str.val, "%s%s", (sn ? sn : ""), (pi ? pi : "")); /* SAFE */
- tmp->type = IS_STRING;
- INIT_PZVAL(tmp);
-#endif
- zend_hash_update(&EG(symbol_table), "PHP_SELF", sizeof("PHP_SELF"), (void *) & tmp, sizeof(pval *), NULL);
- }
-#endif
/* need argc/argv support as well */
@@ -1136,6 +1077,7 @@ static int zend_hash_environment(PLS_D ELS_DC SLS_DC)
return SUCCESS;
}
+
void _php_build_argv(char *s ELS_DC)
{
pval *arr, *tmp;
@@ -1193,6 +1135,7 @@ PHPAPI void php_execute_script(zend_file_handle *primary_file CLS_DC ELS_DC PLS_
zend_file_handle prepend_file, append_file;
SLS_FETCH();
+ zend_hash_environment(ELS_C SLS_CC PLS_CC);
zend_activate_modules();
if (SG(request_info).query_string && SG(request_info).query_string[0]=='='
&& PG(expose_php)) {
@@ -1240,7 +1183,6 @@ PHPAPI void php_execute_script(zend_file_handle *primary_file CLS_DC ELS_DC PLS_
}
EG(main_op_array) = zend_compile_files(0 CLS_CC, 3, prepend_file_p, primary_file, append_file_p);
if (EG(main_op_array)) {
- zend_hash_environment(PLS_C ELS_CC SLS_CC);
EG(active_op_array) = EG(main_op_array);
zend_execute(EG(main_op_array) ELS_CC);
}
View
@@ -81,6 +81,7 @@ struct _php_core_globals {
char *arg_separator;
char *gpc_order;
+ char *variables_order;
zend_bool expose_php;
@@ -21,14 +21,14 @@
#include <stdio.h>
#include "php.h"
#include "ext/standard/php_standard.h"
-#include "php_gpce.h"
+#include "php_variables.h"
#include "php_globals.h"
#include "SAPI.h"
#include "zend_globals.h"
-void php_register_variable(char *val, char *var, pval *track_vars_array ELS_DC PLS_DC)
+PHPAPI void php_register_variable(char *val, char *var, pval *track_vars_array ELS_DC PLS_DC)
{
char *p = NULL;
char *ip; /* index pointer */
@@ -265,7 +265,7 @@ void php_treat_data(int arg, char *str ELS_DC PLS_DC SLS_DC)
/* FIXME: XXX: not binary safe, discards returned length */
php_url_decode(var, strlen(var));
php_url_decode(val, strlen(val));
- php_register_variable(val,var,array_ptr ELS_CC PLS_CC);
+ php_register_variable(val, var, array_ptr ELS_CC PLS_CC);
}
if (arg == PARSE_COOKIE) {
var = strtok_r(NULL, ";", &strtok_buf);
@@ -284,6 +284,31 @@ void php_treat_data(int arg, char *str ELS_DC PLS_DC SLS_DC)
}
+
+void php_import_environment_variables(ELS_D PLS_DC)
+{
+ char **env, *p, *t;
+ zval *array_ptr=NULL;
+
+ if (PG(track_vars)) {
+ ALLOC_ZVAL(array_ptr);
+ array_init(array_ptr);
+ INIT_PZVAL(array_ptr);
+ zend_hash_add(&EG(symbol_table), "HTTP_ENV_VARS", sizeof("HTTP_ENV_VARS"), &array_ptr, sizeof(pval *),NULL);
+ }
+
+ for (env = environ; env != NULL && *env != NULL; env++) {
+ p = strchr(*env, '=');
+ if (!p) { /* malformed entry? */
+ continue;
+ }
+ t = estrndup(*env, p - *env);
+ php_register_variable(p+1, t, array_ptr ELS_CC PLS_CC);
+ efree(t);
+ }
+}
+
+
/*
* Local variables:
* tab-width: 4
@@ -24,13 +24,15 @@
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
+ | Zeev Suraski <zeev@zend.com> |
+----------------------------------------------------------------------+
*/
/* $Id$ */
-#ifndef _POST_H
-#define _POST_H
+#ifndef _PHP_VARIABLES_H
+#define _PHP_VARIABLES_H
+#include "php.h"
#include "SAPI.h"
#define PARSE_POST 0
@@ -39,6 +41,7 @@
#define PARSE_STRING 3
void php_treat_data(int arg, char *str ELS_DC PLS_DC SLS_DC);
-void php_register_variable(char *val, char *var, pval *track_vars_array ELS_DC PLS_DC);
+void php_import_environment_variables(ELS_D PLS_DC);
+PHPAPI void php_register_variable(char *val, char *var, pval *track_vars_array ELS_DC PLS_DC);
-#endif
+#endif /* _PHP_VARIABLES_H */
View
@@ -23,7 +23,7 @@
#include "ext/standard/file.h" /* for php_file_le_uploads() */
#include "zend_globals.h"
#include "php_globals.h"
-#include "php_gpce.h"
+#include "php_variables.h"
#include "rfc1867.h"
Oops, something went wrong.

0 comments on commit 9ab35ae

Please sign in to comment.