1999-04-22 10:48:28 +08:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
1999-07-16 21:13:16 +08:00
|
|
|
| PHP version 4.0 |
|
1999-04-22 10:48:28 +08:00
|
|
|
+----------------------------------------------------------------------+
|
1999-07-16 21:13:16 +08:00
|
|
|
| Copyright (c) 1997, 1998, 1999 The PHP Group |
|
1999-04-22 10:48:28 +08:00
|
|
|
+----------------------------------------------------------------------+
|
1999-07-16 21:13:16 +08:00
|
|
|
| This source file is subject to version 2.0 of the PHP license, |
|
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
|
|
|
| available at through the world-wide-web at |
|
|
|
|
| http://www.php.net/license/2_0.txt. |
|
|
|
|
| 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. |
|
1999-04-22 10:48:28 +08:00
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
/* $Id: */
|
1999-04-24 04:06:01 +08:00
|
|
|
|
1999-04-22 10:48:28 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include "php.h"
|
|
|
|
#include "php3_standard.h"
|
|
|
|
#include "php_globals.h"
|
1999-04-27 01:26:37 +08:00
|
|
|
#include "SAPI.h"
|
1999-04-22 10:48:28 +08:00
|
|
|
|
|
|
|
#include "zend_globals.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* php3_getpost()
|
|
|
|
*
|
|
|
|
* This reads the post form data into a string.
|
|
|
|
* Remember to free this pointer when done with it.
|
|
|
|
*/
|
1999-05-09 21:57:09 +08:00
|
|
|
#if 0
|
1999-04-22 10:48:28 +08:00
|
|
|
static char *php3_getpost(pval *http_post_vars PLS_DC)
|
|
|
|
{
|
|
|
|
char *buf = NULL;
|
|
|
|
const char *ctype;
|
|
|
|
#if MODULE_MAGIC_NUMBER > 19961007
|
|
|
|
char argsbuffer[HUGE_STRING_LEN];
|
|
|
|
#else
|
|
|
|
int bytes;
|
|
|
|
#endif
|
|
|
|
int length, cnt;
|
|
|
|
int file_upload = 0;
|
|
|
|
char *mb;
|
|
|
|
char boundary[100];
|
1999-04-27 01:26:37 +08:00
|
|
|
SLS_FETCH();
|
1999-04-22 10:48:28 +08:00
|
|
|
|
1999-04-24 08:12:00 +08:00
|
|
|
ctype = request_info.content_type;
|
1999-04-22 10:48:28 +08:00
|
|
|
if (!ctype) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING, "POST Error: content-type missing");
|
1999-04-22 10:48:28 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (strncasecmp(ctype, "application/x-www-form-urlencoded", 33) && strncasecmp(ctype, "multipart/form-data", 19)
|
|
|
|
#if HAVE_FDFLIB
|
|
|
|
&& strncasecmp(ctype, "application/vnd.fdf", 19)
|
|
|
|
#endif
|
|
|
|
) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING, "Unsupported content-type: %s", ctype);
|
1999-04-22 10:48:28 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (!strncasecmp(ctype, "multipart/form-data", 19)) {
|
|
|
|
file_upload = 1;
|
|
|
|
mb = strchr(ctype, '=');
|
|
|
|
if (mb) {
|
|
|
|
strncpy(boundary, mb + 1, sizeof(boundary));
|
|
|
|
} else {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING, "File Upload Error: No MIME boundary found");
|
|
|
|
php_error(E_WARNING, "There should have been a \"boundary=something\" in the Content-Type string");
|
|
|
|
php_error(E_WARNING, "The Content-Type string was: \"%s\"", ctype);
|
1999-04-22 10:48:28 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
1999-04-24 08:12:00 +08:00
|
|
|
length = request_info.content_length;
|
1999-04-22 10:48:28 +08:00
|
|
|
cnt = length;
|
|
|
|
buf = (char *) emalloc((length + 1) * sizeof(char));
|
|
|
|
if (!buf) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING, "Unable to allocate memory in php3_getpost()");
|
1999-04-22 10:48:28 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#if FHTTPD
|
|
|
|
memcpy(buf,req->databuffer,length);
|
|
|
|
buf[length]=0;
|
|
|
|
#else
|
|
|
|
#if MODULE_MAGIC_NUMBER > 19961007
|
1999-04-27 01:26:37 +08:00
|
|
|
if (should_client_block(SG(server_context))) {
|
1999-04-22 10:48:28 +08:00
|
|
|
void (*handler) (int);
|
|
|
|
int dbsize, len_read, dbpos = 0;
|
|
|
|
|
1999-04-27 01:26:37 +08:00
|
|
|
hard_timeout("copy script args", ((request_rec *) SG(server_context))); /* start timeout timer */
|
1999-04-22 10:48:28 +08:00
|
|
|
handler = signal(SIGPIPE, SIG_IGN); /* Ignore sigpipes for now */
|
1999-04-27 01:26:37 +08:00
|
|
|
while ((len_read = get_client_block(((request_rec *) SG(server_context)), argsbuffer, HUGE_STRING_LEN)) > 0) {
|
1999-04-22 10:48:28 +08:00
|
|
|
if ((dbpos + len_read) > length)
|
|
|
|
dbsize = length - dbpos;
|
|
|
|
else
|
|
|
|
dbsize = len_read;
|
1999-04-27 01:26:37 +08:00
|
|
|
reset_timeout(((request_rec *) SG(server_context))); /* Make sure we don't timeout */
|
1999-04-22 10:48:28 +08:00
|
|
|
memcpy(buf + dbpos, argsbuffer, dbsize);
|
|
|
|
dbpos += dbsize;
|
|
|
|
}
|
|
|
|
signal(SIGPIPE, handler); /* restore normal sigpipe handling */
|
1999-04-27 01:26:37 +08:00
|
|
|
kill_timeout(((request_rec *) SG(server_context))); /* stop timeout timer */
|
1999-04-22 10:48:28 +08:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
cnt = 0;
|
|
|
|
do {
|
|
|
|
#if APACHE
|
1999-04-27 01:26:37 +08:00
|
|
|
bytes = read_client_block(((request_rec *) SG(server_context)), buf + cnt, length - cnt);
|
1999-04-22 10:48:28 +08:00
|
|
|
#endif
|
|
|
|
#if CGI_BINARY
|
|
|
|
bytes = fread(buf + cnt, 1, length - cnt, stdin);
|
|
|
|
#endif
|
|
|
|
#if USE_SAPI
|
1999-04-24 08:12:00 +08:00
|
|
|
bytes = sapi_rqst->readclient(sapi_rqst->scid,buf + cnt, 1, length - cnt);
|
1999-04-22 10:48:28 +08:00
|
|
|
#endif
|
|
|
|
cnt += bytes;
|
|
|
|
} while (bytes && cnt < length);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
if (file_upload) {
|
|
|
|
php3_mime_split(buf, cnt, boundary, http_post_vars PLS_CC);
|
|
|
|
efree(buf);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
buf[cnt] = '\0';
|
|
|
|
|
|
|
|
#if HAVE_FDFLIB
|
|
|
|
if (!strncasecmp(ctype, "application/vnd.fdf", 19)) {
|
|
|
|
pval *postdata_ptr = (pval *) emalloc(sizeof(pval));
|
|
|
|
|
|
|
|
postdata_ptr->type = IS_STRING;
|
|
|
|
postdata_ptr->value.str.val = (char *) estrdup(buf);
|
|
|
|
postdata_ptr->value.str.len = cnt;
|
1999-07-10 04:45:55 +08:00
|
|
|
INIT_PZVAL(postdata_ptr);
|
1999-08-03 03:17:14 +08:00
|
|
|
zend_hash_add(&symbol_table, "HTTP_FDF_DATA", sizeof("HTTP_FDF_DATA"), postdata_ptr, sizeof(pval *),NULL);
|
1999-04-22 10:48:28 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return (buf);
|
|
|
|
}
|
1999-05-09 16:48:05 +08:00
|
|
|
#else
|
|
|
|
static char *php3_getpost(pval *http_post_vars PLS_DC)
|
|
|
|
{
|
|
|
|
SLS_FETCH();
|
|
|
|
|
|
|
|
return SG(request_info).post_data;
|
|
|
|
}
|
|
|
|
#endif
|
1999-04-22 10:48:28 +08:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* parse Get/Post/Cookie string and create appropriate variable
|
|
|
|
*
|
|
|
|
* This is a tad ugly because it was yanked out of the middle of
|
|
|
|
* the old TreatData function. This is a temporary measure filling
|
|
|
|
* the gap until a more flexible parser can be built to do this.
|
|
|
|
*/
|
|
|
|
void _php3_parse_gpc_data(char *val, char *var, pval *track_vars_array)
|
|
|
|
{
|
|
|
|
int var_type;
|
|
|
|
char *ind, *tmp = NULL, *ret = NULL;
|
1999-05-07 02:09:50 +08:00
|
|
|
int var_len, val_len;
|
1999-04-22 10:48:28 +08:00
|
|
|
pval *entry;
|
|
|
|
ELS_FETCH();
|
|
|
|
PLS_FETCH();
|
|
|
|
|
|
|
|
var_type = php3_check_ident_type(var);
|
|
|
|
if (var_type == GPC_INDEXED_ARRAY) {
|
|
|
|
ind = php3_get_ident_index(var);
|
|
|
|
if (PG(magic_quotes_gpc)) {
|
1999-09-04 21:18:59 +08:00
|
|
|
ret = php_addslashes(ind, 0, NULL, 1);
|
1999-04-22 10:48:28 +08:00
|
|
|
} else {
|
|
|
|
ret = ind;
|
|
|
|
}
|
|
|
|
}
|
1999-05-07 02:09:50 +08:00
|
|
|
if (var_type & GPC_ARRAY) { /* array (indexed or not) */
|
1999-04-22 10:48:28 +08:00
|
|
|
tmp = strchr(var, '[');
|
|
|
|
if (tmp) {
|
|
|
|
*tmp = '\0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* ignore leading spaces in the variable name */
|
|
|
|
while (*var && *var==' ') {
|
|
|
|
var++;
|
|
|
|
}
|
|
|
|
var_len = strlen(var);
|
|
|
|
if (var_len==0) { /* empty variable name, or variable name with a space in it */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ensure that we don't have spaces or dots in the variable name (not binary safe) */
|
|
|
|
for (tmp=var; *tmp; tmp++) {
|
|
|
|
switch(*tmp) {
|
|
|
|
case ' ':
|
|
|
|
case '.':
|
|
|
|
*tmp='_';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-05-07 02:09:50 +08:00
|
|
|
val_len = strlen(val);
|
|
|
|
if (PG(magic_quotes_gpc)) {
|
1999-09-04 21:18:59 +08:00
|
|
|
val = php_addslashes(val, val_len, &val_len, 0);
|
1999-05-07 02:09:50 +08:00
|
|
|
} else {
|
|
|
|
val = estrndup(val, val_len);
|
|
|
|
}
|
|
|
|
|
1999-04-22 10:48:28 +08:00
|
|
|
if (var_type & GPC_ARRAY) {
|
|
|
|
pval *arr1, *arr2;
|
|
|
|
pval **arr_ptr;
|
|
|
|
|
|
|
|
/* If the array doesn't exist, create it */
|
1999-08-03 03:17:14 +08:00
|
|
|
if (zend_hash_find(EG(active_symbol_table), var, var_len+1, (void **) &arr_ptr) == FAILURE) {
|
1999-04-22 10:48:28 +08:00
|
|
|
arr1 = (pval *) emalloc(sizeof(pval));
|
1999-07-10 04:45:55 +08:00
|
|
|
INIT_PZVAL(arr1);
|
1999-04-22 10:48:28 +08:00
|
|
|
if (array_init(arr1)==FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
1999-08-03 03:17:14 +08:00
|
|
|
zend_hash_update(EG(active_symbol_table), var, var_len+1, &arr1, sizeof(pval *), NULL);
|
1999-04-22 10:48:28 +08:00
|
|
|
if (track_vars_array) {
|
|
|
|
arr2 = (pval *) emalloc(sizeof(pval));
|
1999-07-10 04:45:55 +08:00
|
|
|
INIT_PZVAL(arr2);
|
1999-04-22 10:48:28 +08:00
|
|
|
if (array_init(arr2)==FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
1999-08-03 03:17:14 +08:00
|
|
|
zend_hash_update(track_vars_array->value.ht, var, var_len+1, (void *) &arr2, sizeof(pval *),NULL);
|
1999-04-22 10:48:28 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ((*arr_ptr)->type!=IS_ARRAY) {
|
|
|
|
if (--(*arr_ptr) > 0) {
|
|
|
|
*arr_ptr = (pval *) emalloc(sizeof(pval));
|
1999-07-10 04:45:55 +08:00
|
|
|
INIT_PZVAL(*arr_ptr);
|
1999-04-22 10:48:28 +08:00
|
|
|
} else {
|
|
|
|
pval_destructor(*arr_ptr);
|
|
|
|
}
|
|
|
|
if (array_init(*arr_ptr)==FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (track_vars_array) {
|
|
|
|
arr2 = (pval *) emalloc(sizeof(pval));
|
1999-07-10 04:45:55 +08:00
|
|
|
INIT_PZVAL(arr2);
|
1999-04-22 10:48:28 +08:00
|
|
|
if (array_init(arr2)==FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
1999-08-03 03:17:14 +08:00
|
|
|
zend_hash_update(track_vars_array->value.ht, var, var_len+1, (void *) &arr2, sizeof(pval *),NULL);
|
1999-04-22 10:48:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
arr1 = *arr_ptr;
|
1999-08-03 03:17:14 +08:00
|
|
|
if (track_vars_array && zend_hash_find(track_vars_array->value.ht, var, var_len+1, (void **) &arr_ptr) == FAILURE) {
|
1999-04-22 10:48:28 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
arr2 = *arr_ptr;
|
|
|
|
}
|
|
|
|
/* Now create the element */
|
|
|
|
entry = (pval *) emalloc(sizeof(pval));
|
1999-07-10 04:45:55 +08:00
|
|
|
INIT_PZVAL(entry);
|
1999-05-07 02:09:50 +08:00
|
|
|
entry->value.str.val = val;
|
|
|
|
entry->value.str.len = val_len;
|
1999-04-22 10:48:28 +08:00
|
|
|
entry->type = IS_STRING;
|
|
|
|
|
|
|
|
/* And then insert it */
|
1999-05-07 02:09:50 +08:00
|
|
|
if (ret) { /* array */
|
|
|
|
if (php3_check_type(ret) == IS_LONG) { /* numeric index */
|
1999-08-03 03:17:14 +08:00
|
|
|
zend_hash_index_update(arr1->value.ht, atol(ret), &entry, sizeof(pval *),NULL); /* s[ret]=tmp */
|
1999-04-22 10:48:28 +08:00
|
|
|
if (track_vars_array) {
|
1999-08-03 03:17:14 +08:00
|
|
|
zend_hash_index_update(arr2->value.ht, atol(ret), &entry, sizeof(pval *),NULL);
|
1999-04-22 10:48:28 +08:00
|
|
|
entry->refcount++;
|
|
|
|
}
|
1999-05-07 02:09:50 +08:00
|
|
|
} else { /* associative index */
|
1999-08-03 03:17:14 +08:00
|
|
|
zend_hash_update(arr1->value.ht, ret, strlen(ret)+1, &entry, sizeof(pval *),NULL); /* s["ret"]=tmp */
|
1999-04-22 10:48:28 +08:00
|
|
|
if (track_vars_array) {
|
1999-08-03 03:17:14 +08:00
|
|
|
zend_hash_update(arr2->value.ht, ret, strlen(ret)+1, &entry, sizeof(pval *),NULL);
|
1999-04-22 10:48:28 +08:00
|
|
|
entry->refcount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
efree(ret);
|
|
|
|
ret = NULL;
|
|
|
|
} else { /* non-indexed array */
|
1999-08-03 03:17:14 +08:00
|
|
|
zend_hash_next_index_insert(arr1->value.ht, &entry, sizeof(pval *),NULL);
|
1999-04-22 10:48:28 +08:00
|
|
|
if (track_vars_array) {
|
1999-08-03 03:17:14 +08:00
|
|
|
zend_hash_next_index_insert(arr2->value.ht, &entry, sizeof(pval *),NULL);
|
1999-04-22 10:48:28 +08:00
|
|
|
entry->refcount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else { /* we have a normal variable */
|
|
|
|
pval *entry = (pval *) emalloc(sizeof(pval));
|
|
|
|
|
|
|
|
entry->type = IS_STRING;
|
1999-07-10 04:45:55 +08:00
|
|
|
INIT_PZVAL(entry);
|
1999-05-07 02:09:50 +08:00
|
|
|
entry->value.str.val = val;
|
|
|
|
entry->value.str.len = val_len;
|
1999-08-03 03:17:14 +08:00
|
|
|
zend_hash_update(EG(active_symbol_table), var, var_len+1, (void *) &entry, sizeof(pval *),NULL);
|
1999-04-22 10:48:28 +08:00
|
|
|
if (track_vars_array) {
|
1999-05-07 02:09:50 +08:00
|
|
|
entry->refcount++;
|
1999-08-03 03:17:14 +08:00
|
|
|
zend_hash_update(track_vars_array->value.ht, var, var_len+1, (void *) &entry, sizeof(pval *), NULL);
|
1999-04-22 10:48:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void php3_treat_data(int arg, char *str)
|
|
|
|
{
|
|
|
|
char *res = NULL, *var, *val;
|
|
|
|
pval *array_ptr;
|
1999-05-11 08:01:47 +08:00
|
|
|
int free_buffer=0;
|
1999-04-22 10:48:28 +08:00
|
|
|
ELS_FETCH();
|
|
|
|
PLS_FETCH();
|
1999-05-03 02:07:41 +08:00
|
|
|
SLS_FETCH();
|
1999-04-22 10:48:28 +08:00
|
|
|
|
|
|
|
switch (arg) {
|
|
|
|
case PARSE_POST:
|
|
|
|
case PARSE_GET:
|
|
|
|
case PARSE_COOKIE:
|
|
|
|
if (PG(track_vars)) {
|
|
|
|
array_ptr = (pval *) emalloc(sizeof(pval));
|
|
|
|
array_init(array_ptr);
|
1999-07-10 04:45:55 +08:00
|
|
|
INIT_PZVAL(array_ptr);
|
1999-04-22 10:48:28 +08:00
|
|
|
switch (arg) {
|
|
|
|
case PARSE_POST:
|
1999-08-03 03:17:14 +08:00
|
|
|
zend_hash_add(&EG(symbol_table), "HTTP_POST_VARS", sizeof("HTTP_POST_VARS"), &array_ptr, sizeof(pval *),NULL);
|
1999-04-22 10:48:28 +08:00
|
|
|
break;
|
|
|
|
case PARSE_GET:
|
1999-08-03 03:17:14 +08:00
|
|
|
zend_hash_add(&EG(symbol_table), "HTTP_GET_VARS", sizeof("HTTP_GET_VARS"), &array_ptr, sizeof(pval *),NULL);
|
1999-04-22 10:48:28 +08:00
|
|
|
break;
|
|
|
|
case PARSE_COOKIE:
|
1999-08-03 03:17:14 +08:00
|
|
|
zend_hash_add(&EG(symbol_table), "HTTP_COOKIE_VARS", sizeof("HTTP_COOKIE_VARS"), &array_ptr, sizeof(pval *),NULL);
|
1999-04-22 10:48:28 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
array_ptr=NULL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
array_ptr=NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1999-05-10 02:40:59 +08:00
|
|
|
if (arg == PARSE_POST) { /* POST data */
|
1999-04-22 10:48:28 +08:00
|
|
|
res = php3_getpost(array_ptr PLS_CC);
|
1999-05-10 02:40:59 +08:00
|
|
|
free_buffer = 0;
|
|
|
|
} else if (arg == PARSE_GET) { /* GET data */
|
1999-05-03 02:07:41 +08:00
|
|
|
var = SG(request_info).query_string;
|
1999-04-22 10:48:28 +08:00
|
|
|
if (var && *var) {
|
|
|
|
res = (char *) estrdup(var);
|
1999-05-10 02:40:59 +08:00
|
|
|
free_buffer = 1;
|
|
|
|
} else {
|
|
|
|
free_buffer = 0;
|
1999-04-22 10:48:28 +08:00
|
|
|
}
|
|
|
|
} else if (arg == PARSE_COOKIE) { /* Cookie data */
|
1999-05-09 16:48:05 +08:00
|
|
|
var = SG(request_info).cookie_data;
|
1999-04-22 10:48:28 +08:00
|
|
|
if (var && *var) {
|
|
|
|
res = (char *) estrdup(var);
|
1999-05-10 02:40:59 +08:00
|
|
|
free_buffer = 1;
|
|
|
|
} else {
|
|
|
|
free_buffer = 0;
|
1999-04-22 10:48:28 +08:00
|
|
|
}
|
|
|
|
} else if (arg == PARSE_STRING) { /* String data */
|
|
|
|
res = str;
|
1999-05-10 02:40:59 +08:00
|
|
|
free_buffer = 1;
|
1999-04-22 10:48:28 +08:00
|
|
|
}
|
|
|
|
if (!res) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (arg == PARSE_COOKIE) {
|
|
|
|
var = strtok(res, ";");
|
|
|
|
} else if (arg == PARSE_POST) {
|
|
|
|
var = strtok(res, "&");
|
|
|
|
} else {
|
|
|
|
var = strtok(res, PG(arg_separator));
|
|
|
|
}
|
|
|
|
|
|
|
|
while (var) {
|
|
|
|
val = strchr(var, '=');
|
|
|
|
if (val) { /* have a value */
|
|
|
|
*val++ = '\0';
|
|
|
|
/* FIXME: XXX: not binary safe, discards returned length */
|
|
|
|
_php3_urldecode(var, strlen(var));
|
|
|
|
_php3_urldecode(val, strlen(val));
|
|
|
|
_php3_parse_gpc_data(val,var,array_ptr);
|
|
|
|
}
|
|
|
|
if (arg == PARSE_COOKIE) {
|
|
|
|
var = strtok(NULL, ";");
|
|
|
|
} else if (arg == PARSE_POST) {
|
|
|
|
var = strtok(NULL, "&");
|
|
|
|
} else {
|
|
|
|
var = strtok(NULL, PG(arg_separator));
|
|
|
|
}
|
|
|
|
}
|
1999-05-10 02:40:59 +08:00
|
|
|
if (free_buffer) {
|
|
|
|
efree(res);
|
|
|
|
}
|
1999-04-22 10:48:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-04-26 22:00:49 +08:00
|
|
|
PHPAPI void php3_TreatHeaders(void)
|
1999-04-22 10:48:28 +08:00
|
|
|
{
|
1999-05-13 06:49:23 +08:00
|
|
|
#if 0
|
1999-04-22 10:48:28 +08:00
|
|
|
#if APACHE
|
|
|
|
#if MODULE_MAGIC_NUMBER > 19961007
|
|
|
|
const char *s = NULL;
|
|
|
|
#else
|
|
|
|
char *s = NULL;
|
|
|
|
#endif
|
|
|
|
char *t;
|
|
|
|
char *user, *type;
|
|
|
|
int len;
|
|
|
|
char *escaped_str;
|
1999-04-27 01:26:37 +08:00
|
|
|
request_rec *r;
|
1999-04-22 10:48:28 +08:00
|
|
|
PLS_FETCH();
|
1999-04-27 01:26:37 +08:00
|
|
|
SLS_FETCH();
|
1999-04-22 10:48:28 +08:00
|
|
|
|
1999-04-27 01:26:37 +08:00
|
|
|
r = ((request_rec *) SG(server_context));
|
|
|
|
|
|
|
|
if (r->headers_in)
|
|
|
|
s = table_get(r->headers_in, "Authorization");
|
1999-04-22 10:48:28 +08:00
|
|
|
if (!s)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Check to make sure that this URL isn't authenticated
|
|
|
|
using a traditional auth module mechanism */
|
1999-04-27 01:26:37 +08:00
|
|
|
if (auth_type(r)) {
|
1999-08-03 03:17:14 +08:00
|
|
|
/*php_error(E_WARNING, "Authentication done by server module\n");*/
|
1999-04-22 10:48:28 +08:00
|
|
|
return;
|
|
|
|
}
|
1999-04-27 01:26:37 +08:00
|
|
|
if (strcmp(t=getword(r->pool, &s, ' '), "Basic")) {
|
1999-04-22 10:48:28 +08:00
|
|
|
/* Client tried to authenticate using wrong auth scheme */
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING, "client used wrong authentication scheme (%s)", t);
|
1999-04-22 10:48:28 +08:00
|
|
|
return;
|
|
|
|
}
|
1999-04-27 01:26:37 +08:00
|
|
|
t = uudecode(r->pool, s);
|
1999-04-22 10:48:28 +08:00
|
|
|
#if MODULE_MAGIC_NUMBER > 19961007
|
1999-04-27 01:26:37 +08:00
|
|
|
user = getword_nulls_nc(r->pool, &t, ':');
|
1999-04-22 10:48:28 +08:00
|
|
|
#else
|
1999-04-27 01:26:37 +08:00
|
|
|
user = getword(r->pool, &t, ':');
|
1999-04-22 10:48:28 +08:00
|
|
|
#endif
|
|
|
|
type = "Basic";
|
|
|
|
|
|
|
|
if (user) {
|
|
|
|
if (PG(magic_quotes_gpc)) {
|
1999-09-04 21:18:59 +08:00
|
|
|
escaped_str = php_addslashes(user, 0, &len, 0);
|
1999-04-22 10:48:28 +08:00
|
|
|
SET_VAR_STRINGL("PHP_AUTH_USER", escaped_str, len);
|
|
|
|
} else {
|
|
|
|
SET_VAR_STRING("PHP_AUTH_USER", estrdup(user));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (t) {
|
|
|
|
if (PG(magic_quotes_gpc)) {
|
1999-09-04 21:18:59 +08:00
|
|
|
escaped_str = php_addslashes(t, 0, &len, 0);
|
1999-04-22 10:48:28 +08:00
|
|
|
SET_VAR_STRINGL("PHP_AUTH_PW", escaped_str, len);
|
|
|
|
} else {
|
|
|
|
SET_VAR_STRING("PHP_AUTH_PW", estrdup(t));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (type) {
|
|
|
|
if (PG(magic_quotes_gpc)) {
|
1999-09-04 21:18:59 +08:00
|
|
|
escaped_str = php_addslashes(type, 0, &len, 0);
|
1999-04-22 10:48:28 +08:00
|
|
|
SET_VAR_STRINGL("PHP_AUTH_TYPE", escaped_str, len);
|
|
|
|
} else {
|
|
|
|
SET_VAR_STRING("PHP_AUTH_TYPE", estrdup(type));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if FHTTPD
|
|
|
|
int i,len;
|
|
|
|
struct rline *l;
|
|
|
|
char *type;
|
|
|
|
char *escaped_str;
|
|
|
|
|
|
|
|
if(req && req->remote_user){
|
|
|
|
for(i=0; i < req->nlines; i++){
|
|
|
|
l=req->lines+i;
|
|
|
|
if((l->paramc > 1)&&!strcasecmp(l->params[0], "REMOTE_PW")){
|
|
|
|
type = "Basic";
|
|
|
|
if (PG(magic_quotes_gpc)) {
|
1999-09-04 21:18:59 +08:00
|
|
|
escaped_str = php_addslashes(type, 0, &len, 0);
|
1999-04-22 10:48:28 +08:00
|
|
|
SET_VAR_STRINGL("PHP_AUTH_TYPE", escaped_str, len);
|
1999-09-04 21:18:59 +08:00
|
|
|
escaped_str = php_addslashes(l->params[1], 0, &len, 0);
|
1999-04-22 10:48:28 +08:00
|
|
|
SET_VAR_STRINGL("PHP_AUTH_PW", escaped_str, len);
|
1999-09-04 21:18:59 +08:00
|
|
|
escaped_str = php_addslashes(req->remote_user, 0, &len, 0);
|
1999-04-22 10:48:28 +08:00
|
|
|
SET_VAR_STRINGL("PHP_AUTH_USER", escaped_str, len);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
SET_VAR_STRING("PHP_AUTH_TYPE", estrdup(type));
|
|
|
|
SET_VAR_STRING("PHP_AUTH_PW", estrdup(l->params[1]));
|
|
|
|
SET_VAR_STRING("PHP_AUTH_USER", estrdup(req->remote_user));
|
|
|
|
}
|
|
|
|
i=req->nlines;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
1999-05-13 06:49:23 +08:00
|
|
|
#endif
|
1999-04-22 10:48:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* tab-width: 4
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* End:
|
|
|
|
*/
|