mirror of
https://github.com/php/php-src.git
synced 2024-11-25 10:54:15 +08:00
* now using php4.ini instead of php3.ini
* re-imported fopen-wrappers, fsock and string code from php3 NB! I have not tested all of the imported functions yet.
This commit is contained in:
parent
7719f86292
commit
336392ea6c
@ -145,7 +145,7 @@ static void php_cgi_usage(char *argv0)
|
||||
" -s Display colour syntax highlighted source.\n"
|
||||
" -f<file> Parse <file>. Implies `-q'\n"
|
||||
" -v Version number\n"
|
||||
" -c<path> Look for php3.ini file in this directory\n"
|
||||
" -c<path> Look for php4.ini file in this directory\n"
|
||||
#if SUPPORT_INTERACTIVE
|
||||
" -a Run interactively\n"
|
||||
#endif
|
||||
@ -235,7 +235,7 @@ set. This variable is set, for example, by Apache's Action directive redirect.\
|
||||
--disable-force-cgi-redirect switch. If you do this and you have your PHP CGI\n\
|
||||
binary accessible somewhere in your web tree, people will be able to circumvent\n\
|
||||
.htaccess security by loading files through the PHP parser. A good way around\n\
|
||||
this is to define doc_root in your php3.ini file to something other than your\n\
|
||||
this is to define doc_root in your php4.ini file to something other than your\n\
|
||||
top-level DOCUMENT_ROOT. This way you can separate the part of your web space\n\n\
|
||||
which uses PHP from the normal part using .htaccess security. If you do not have\n\
|
||||
any .htaccess restrictions anywhere on your site you can leave doc_root undefined.\n\
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -2,7 +2,7 @@
|
||||
+----------------------------------------------------------------------+
|
||||
| PHP HTML Embedded Scripting Language Version 3.0 |
|
||||
+----------------------------------------------------------------------+
|
||||
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
|
||||
| Copyright (c) 1997-1999 PHP Development Team (See Credits file) |
|
||||
+----------------------------------------------------------------------+
|
||||
| This program is free software; you can redistribute it and/or modify |
|
||||
| it under the terms of one of the following licenses: |
|
||||
@ -32,37 +32,38 @@
|
||||
#ifndef _FILE_H
|
||||
#define _FILE_H
|
||||
|
||||
extern php3_module_entry php3_file_module_entry;
|
||||
#define php3_file_module_ptr &php3_file_module_entry
|
||||
#ifndef INIT_FUNC_ARGS
|
||||
#include "modules.h"
|
||||
#endif
|
||||
|
||||
extern int php3_minit_file(INIT_FUNC_ARGS);
|
||||
PHP_FUNCTION(tempnam);
|
||||
PHP_FUNCTION(fopen);
|
||||
PHP_FUNCTION(fclose);
|
||||
PHP_FUNCTION(popen);
|
||||
PHP_FUNCTION(pclose);
|
||||
PHP_FUNCTION(feof);
|
||||
PHP_FUNCTION(fread);
|
||||
PHP_FUNCTION(fgetc);
|
||||
PHP_FUNCTION(fgets);
|
||||
PHP_FUNCTION(fgetss);
|
||||
PHP_FUNCTION(fgetcsv);
|
||||
PHP_FUNCTION(fwrite);
|
||||
PHP_FUNCTION(rewind);
|
||||
PHP_FUNCTION(ftell);
|
||||
PHP_FUNCTION(fseek);
|
||||
PHP_FUNCTION(mkdir);
|
||||
PHP_FUNCTION(rmdir);
|
||||
PHP_FUNCTION(fpassthru);
|
||||
PHP_FUNCTION(readfile);
|
||||
PHP_FUNCTION(fileumask);
|
||||
PHP_FUNCTION(rename);
|
||||
PHP_FUNCTION(file_copy);
|
||||
PHP_FUNCTION(file);
|
||||
PHP_FUNCTION(set_socket_blocking);
|
||||
PHP_FUNCTION(set_socket_timeout);
|
||||
PHP_FUNCTION(get_meta_tags);
|
||||
PHP_FUNCTION(flock);
|
||||
extern void php3_tempnam(INTERNAL_FUNCTION_PARAMETERS);
|
||||
extern void php3_fopen(INTERNAL_FUNCTION_PARAMETERS);
|
||||
extern void php3_fclose(INTERNAL_FUNCTION_PARAMETERS);
|
||||
extern void php3_popen(INTERNAL_FUNCTION_PARAMETERS);
|
||||
extern void php3_pclose(INTERNAL_FUNCTION_PARAMETERS);
|
||||
extern void php3_feof(INTERNAL_FUNCTION_PARAMETERS);
|
||||
extern void php3_fread(INTERNAL_FUNCTION_PARAMETERS);
|
||||
extern void php3_fgetc(INTERNAL_FUNCTION_PARAMETERS);
|
||||
extern void php3_fgets(INTERNAL_FUNCTION_PARAMETERS);
|
||||
extern void php3_fgetss(INTERNAL_FUNCTION_PARAMETERS);
|
||||
extern void php3_fgetcsv(INTERNAL_FUNCTION_PARAMETERS);
|
||||
extern void php3_fwrite(INTERNAL_FUNCTION_PARAMETERS);
|
||||
extern void php3_set_file_buffer(INTERNAL_FUNCTION_PARAMETERS);
|
||||
extern void php3_rewind(INTERNAL_FUNCTION_PARAMETERS);
|
||||
extern void php3_ftell(INTERNAL_FUNCTION_PARAMETERS);
|
||||
extern void php3_fseek(INTERNAL_FUNCTION_PARAMETERS);
|
||||
extern void php3_mkdir(INTERNAL_FUNCTION_PARAMETERS);
|
||||
extern void php3_rmdir(INTERNAL_FUNCTION_PARAMETERS);
|
||||
extern void php3_fpassthru(INTERNAL_FUNCTION_PARAMETERS);
|
||||
extern void php3_readfile(INTERNAL_FUNCTION_PARAMETERS);
|
||||
extern void php3_fileumask(INTERNAL_FUNCTION_PARAMETERS);
|
||||
extern void php3_rename(INTERNAL_FUNCTION_PARAMETERS);
|
||||
extern void php3_file_copy(INTERNAL_FUNCTION_PARAMETERS);
|
||||
extern void php3_file(INTERNAL_FUNCTION_PARAMETERS);
|
||||
extern void php3_set_socket_blocking(INTERNAL_FUNCTION_PARAMETERS);
|
||||
extern void php3_set_socket_timeout(INTERNAL_FUNCTION_PARAMETERS);
|
||||
extern void php3_get_meta_tags(INTERNAL_FUNCTION_PARAMETERS);
|
||||
extern PHP_FUNCTION(flock);
|
||||
|
||||
#define phpext_file_ptr php3_file_module_ptr
|
||||
#endif /* _FILE_H */
|
||||
|
@ -28,13 +28,22 @@
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
/* $Id$ */
|
||||
|
||||
#include "php.h"
|
||||
#include "php_globals.h"
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_FCNTL_H
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_SYS_TIME_H
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#if HAVE_SYS_SOCKET_H
|
||||
#include <sys/socket.h>
|
||||
@ -84,11 +93,15 @@ function_entry fsock_functions[] = {
|
||||
|
||||
struct php3i_sockbuf {
|
||||
int socket;
|
||||
char *readbuf;
|
||||
unsigned char *readbuf;
|
||||
size_t readbuflen;
|
||||
size_t readpos;
|
||||
size_t writepos;
|
||||
struct php3i_sockbuf *next;
|
||||
struct php3i_sockbuf *prev;
|
||||
char eof;
|
||||
char persistent;
|
||||
char is_blocked;
|
||||
};
|
||||
|
||||
static struct php3i_sockbuf *phpsockbuf;
|
||||
@ -141,27 +154,102 @@ int _php3_is_persistent_sock(int sock)
|
||||
return 0;
|
||||
}
|
||||
/* }}} */
|
||||
/* {{{ _php3_fsockopen() */
|
||||
|
||||
|
||||
/* {{{ connect_nonb */
|
||||
PHPAPI int connect_nonb(int sockfd, struct sockaddr *addr, int addrlen, struct timeval *timeout)
|
||||
|
||||
/* probably won't work on Win32, someone else might try it (read: fix it ;) */
|
||||
#if !defined(WIN32) && (defined(O_NONBLOCK) || defined(O_NDELAY))
|
||||
|
||||
#ifndef O_NONBLOCK
|
||||
#define O_NONBLOCK O_NDELAY
|
||||
#endif
|
||||
|
||||
{
|
||||
int flags;
|
||||
int n;
|
||||
int error = 0;
|
||||
int len;
|
||||
int ret = 0;
|
||||
fd_set rset;
|
||||
fd_set wset;
|
||||
|
||||
flags = fcntl(sockfd, F_GETFL, 0);
|
||||
fcntl(sockfd, F_SETFL, flags | O_NONBLOCK);
|
||||
|
||||
if((n = connect(sockfd, addr, addrlen)) < 0)
|
||||
if(errno != EINPROGRESS)
|
||||
return -1;
|
||||
|
||||
if(n == 0)
|
||||
goto ok;
|
||||
|
||||
FD_ZERO(&rset);
|
||||
FD_SET(sockfd, &rset);
|
||||
|
||||
wset = rset;
|
||||
|
||||
if((n = select(sockfd + 1, &rset, &wset, NULL, timeout)) == 0) {
|
||||
error = ETIMEDOUT;
|
||||
}
|
||||
|
||||
if(FD_ISSET(sockfd, &rset) || FD_ISSET(sockfd, &wset)) {
|
||||
len = sizeof(error);
|
||||
/*
|
||||
BSD-derived systems set errno correctly
|
||||
Solaris returns -1 from getsockopt in case of error
|
||||
*/
|
||||
if(getsockopt(sockfd, SOL_SOCKET, SO_ERROR, &error, &len) < 0)
|
||||
ret = -1;
|
||||
} else {
|
||||
/* whoops: sockfd has disappeared */
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
ok:
|
||||
fcntl(sockfd, F_SETFL, flags);
|
||||
|
||||
if(error) {
|
||||
errno = error;
|
||||
ret = -1;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#else
|
||||
//#warning "compiling without nonblocking connect support"
|
||||
{
|
||||
return connect(sockfd, addr, addrlen);
|
||||
}
|
||||
#endif
|
||||
/* }}} */
|
||||
|
||||
|
||||
/* {{{ _php3_fsockopen() */
|
||||
/*
|
||||
This function takes an optional third argument which should be
|
||||
passed by reference. The error code from the connect call is written
|
||||
to this variable.
|
||||
*/
|
||||
static void _php3_fsockopen(INTERNAL_FUNCTION_PARAMETERS, int persistent) {
|
||||
pval *args[4];
|
||||
pval *args[5];
|
||||
int *sock=emalloc(sizeof(int));
|
||||
int *sockp;
|
||||
int id, arg_count=ARG_COUNT(ht);
|
||||
int socketd = -1;
|
||||
struct timeval timeout = { 60, 0 };
|
||||
unsigned short portno;
|
||||
char *key = NULL;
|
||||
PLS_FETCH();
|
||||
|
||||
if (arg_count > 4 || arg_count < 2 || getParametersArray(ht,arg_count,args)==FAILURE) {
|
||||
if (arg_count > 5 || arg_count < 2 || getParametersArray(ht,arg_count,args)==FAILURE) {
|
||||
FREE_SOCK;
|
||||
WRONG_PARAM_COUNT;
|
||||
}
|
||||
switch(arg_count) {
|
||||
case 5:
|
||||
convert_to_long(args[4]);
|
||||
timeout.tv_sec = args[4]->value.lval;
|
||||
case 4:
|
||||
if(!ParameterPassedByReference(ht,4)) {
|
||||
php3_error(E_WARNING,"error string argument to fsockopen not passed by reference");
|
||||
@ -188,7 +276,7 @@ static void _php3_fsockopen(INTERNAL_FUNCTION_PARAMETERS, int persistent) {
|
||||
|
||||
if (persistent && _php3_hash_find(&ht_keys, key, strlen(key) + 1,
|
||||
(void *) &sockp) == SUCCESS) {
|
||||
efree(key);
|
||||
FREE_SOCK;
|
||||
*sock = *sockp;
|
||||
RETURN_LONG(php3_list_insert(sock, wsa_fp));
|
||||
}
|
||||
@ -212,7 +300,7 @@ static void _php3_fsockopen(INTERNAL_FUNCTION_PARAMETERS, int persistent) {
|
||||
|
||||
server.sin_port = htons(portno);
|
||||
|
||||
if (connect(socketd, (struct sockaddr *)&server, sizeof(server)) == SOCK_CONN_ERR) {
|
||||
if (connect_nonb(socketd, (struct sockaddr *)&server, sizeof(server), &timeout) == SOCK_CONN_ERR) {
|
||||
FREE_SOCK;
|
||||
if(arg_count>2) args[2]->value.lval = errno;
|
||||
if(arg_count>3) {
|
||||
@ -235,7 +323,7 @@ static void _php3_fsockopen(INTERNAL_FUNCTION_PARAMETERS, int persistent) {
|
||||
unix_addr.sun_family = AF_UNIX;
|
||||
strcpy(unix_addr.sun_path, args[0]->value.str.val);
|
||||
|
||||
if (connect(socketd, (struct sockaddr *) &unix_addr, sizeof(unix_addr)) == SOCK_CONN_ERR) {
|
||||
if (connect_nonb(socketd, (struct sockaddr *) &unix_addr, sizeof(unix_addr), &timeout) == SOCK_CONN_ERR) {
|
||||
FREE_SOCK;
|
||||
if(arg_count>2) args[2]->value.lval = errno;
|
||||
if(arg_count>3) {
|
||||
@ -267,19 +355,19 @@ static void _php3_fsockopen(INTERNAL_FUNCTION_PARAMETERS, int persistent) {
|
||||
key, strlen(key) + 1, NULL);
|
||||
}
|
||||
if(key) efree(key);
|
||||
id = php3_list_insert(sock,wsa_fp);
|
||||
id = php3_list_insert(sock, wsa_fp);
|
||||
RETURN_LONG(id);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto int fsockopen(string hostname, int port [, int errno [, string errstr]])
|
||||
/* {{{ proto int fsockopen(string hostname, int port [, int errno [, string errstr [, int timeout]]])
|
||||
Open Internet or Unix domain socket connection */
|
||||
PHP_FUNCTION(fsockopen)
|
||||
{
|
||||
_php3_fsockopen(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
|
||||
}
|
||||
/* }}} */
|
||||
/* {{{ proto int pfsockopen(string hostname, int port [, int errno [, string errstr]])
|
||||
/* {{{ proto int pfsockopen(string hostname, int port [, int errno [, string errstr [, int timeout]]])
|
||||
Open persistent Internet or Unix domain socket connection */
|
||||
PHP_FUNCTION(pfsockopen)
|
||||
{
|
||||
@ -287,16 +375,37 @@ PHP_FUNCTION(pfsockopen)
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* Known issues with the socket buffering code:
|
||||
* - does not work reliably with persistent sockets yet
|
||||
* (buffered data is not persistent)
|
||||
* - php3_fopen_url_wrapper() is still doing single-byte lookahead/read
|
||||
*/
|
||||
#define SOCK_DESTROY(sock) \
|
||||
if(sock->readbuf) pefree(sock->readbuf, sock->persistent); \
|
||||
if(sock->prev) sock->prev->next = sock->next; \
|
||||
if(sock->next) sock->next->prev = sock->prev; \
|
||||
if(sock == phpsockbuf) \
|
||||
phpsockbuf = sock->next; \
|
||||
pefree(sock, sock->persistent)
|
||||
|
||||
static php3i_sockbuf *_php3_sock_findsock(int socket)
|
||||
static void php_cleanup_sockbuf(int persistent)
|
||||
{
|
||||
/* FIXME: O(n) could be improved */
|
||||
php3i_sockbuf *now, *next;
|
||||
|
||||
for(now = phpsockbuf; now; now = next) {
|
||||
next = now->next;
|
||||
if(now->persistent == persistent) {
|
||||
SOCK_DESTROY(now);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#define TOREAD(sock) ((sock)->writepos - (sock)->readpos)
|
||||
#define READPTR(sock) ((sock)->readbuf + (sock)->readpos)
|
||||
#define WRITEPTR(sock) ((sock)->readbuf + (sock)->writepos)
|
||||
|
||||
#define SOCK_FIND(sock,socket) \
|
||||
php3i_sockbuf *sock; \
|
||||
sock = _php3_sock_find(socket); \
|
||||
if(!sock) sock = _php3_sock_create(socket)
|
||||
|
||||
static php3i_sockbuf *_php3_sock_find(int socket)
|
||||
{
|
||||
php3i_sockbuf *buf = NULL, *tmp;
|
||||
|
||||
for(tmp = phpsockbuf; tmp; tmp = tmp->next)
|
||||
@ -306,146 +415,223 @@ static php3i_sockbuf *_php3_sock_findsock(int socket)
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
static php3i_sockbuf *_php3_sock_create(int socket)
|
||||
{
|
||||
php3i_sockbuf *sock;
|
||||
int persistent = _php3_is_persistent_sock(socket);
|
||||
|
||||
sock = pecalloc(sizeof(*sock), 1, persistent);
|
||||
sock->socket = socket;
|
||||
if((sock->next = phpsockbuf))
|
||||
phpsockbuf->prev = sock;
|
||||
sock->persistent = persistent;
|
||||
sock->is_blocked = 1;
|
||||
phpsockbuf = sock;
|
||||
|
||||
return sock;
|
||||
}
|
||||
|
||||
int _php3_sock_eof(int socket)
|
||||
int _php3_sock_destroy(int socket)
|
||||
{
|
||||
php3i_sockbuf *sockbuf;
|
||||
int ret = 0;
|
||||
php3i_sockbuf *sock;
|
||||
|
||||
sockbuf = _php3_sock_findsock(socket);
|
||||
if(sockbuf) {
|
||||
ret = (sockbuf->writepos - sockbuf->readpos) == 0 ? 1 : 0;
|
||||
sock = _php3_sock_find(socket);
|
||||
if(sock) {
|
||||
ret = 1;
|
||||
SOCK_DESTROY(sock);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* {{{ _php3_sock_fgets() */
|
||||
int _php3_sock_fgets(char *buf, int maxlen, int socket)
|
||||
int _php3_sock_close(int socket)
|
||||
{
|
||||
struct php3i_sockbuf *sockbuf;
|
||||
int bytesread, toread, len, buflen, count = 0;
|
||||
char *nl;
|
||||
int ret = 0;
|
||||
php3i_sockbuf *sock;
|
||||
|
||||
sock = _php3_sock_find(socket);
|
||||
if(sock) {
|
||||
if(!sock->persistent) {
|
||||
#if HAVE_SHUTDOWN
|
||||
shutdown(sock->socket, 0);
|
||||
#endif
|
||||
#if WIN32||WINNT
|
||||
closesocket(sock->socket);
|
||||
#else
|
||||
close(sock->socket);
|
||||
#endif
|
||||
SOCK_DESTROY(sock);
|
||||
}
|
||||
}
|
||||
|
||||
sockbuf = _php3_sock_findsock(socket);
|
||||
|
||||
if (sockbuf) {
|
||||
toread = sockbuf->writepos - sockbuf->readpos;
|
||||
if (toread > maxlen) {
|
||||
toread = maxlen;
|
||||
}
|
||||
if ((nl = memchr(sockbuf->readbuf + sockbuf->readpos, '\n', toread)) != NULL) {
|
||||
toread = (nl - (sockbuf->readbuf + sockbuf->readpos)) + 1;
|
||||
}
|
||||
memcpy(buf, sockbuf->readbuf + sockbuf->readpos, toread);
|
||||
sockbuf->readpos += toread;
|
||||
count += toread;
|
||||
buf += toread;
|
||||
if (sockbuf->readpos >= sockbuf->writepos) {
|
||||
sockbuf->readpos = sockbuf->writepos = 0;
|
||||
}
|
||||
if (nl != NULL) {
|
||||
/* if a newline was found, skip the recv() loop */
|
||||
goto sock_fgets_exit;
|
||||
}
|
||||
}
|
||||
|
||||
nl = NULL;
|
||||
buflen = 0;
|
||||
while (count < maxlen && nl == NULL) {
|
||||
toread = maxlen - count;
|
||||
bytesread = recv(socket, buf, toread, 0);
|
||||
if (bytesread <= 0) {
|
||||
break;
|
||||
}
|
||||
if ((nl = memchr(buf, '\n', bytesread)) != NULL) {
|
||||
len = (nl - buf) + 1;
|
||||
count += len;
|
||||
buf += len;
|
||||
if (len < bytesread) {
|
||||
buflen = bytesread - len;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
count += bytesread;
|
||||
buf += bytesread;
|
||||
}
|
||||
}
|
||||
|
||||
if (buflen > 0) { /* there was data after the "\n" ... */
|
||||
if (sockbuf == NULL) {
|
||||
sockbuf = emalloc(sizeof(struct php3i_sockbuf));
|
||||
sockbuf->socket = socket;
|
||||
sockbuf->readbuf = emalloc(maxlen);
|
||||
sockbuf->readbuflen = maxlen;
|
||||
sockbuf->readpos = sockbuf->writepos = 0;
|
||||
sockbuf->next = phpsockbuf;
|
||||
phpsockbuf = sockbuf;
|
||||
} else {
|
||||
uint needlen = sockbuf->writepos + buflen;
|
||||
|
||||
if (needlen > sockbuf->readbuflen) {
|
||||
sockbuf->readbuflen += maxlen;
|
||||
sockbuf->readbuf = erealloc(sockbuf->readbuf, sockbuf->readbuflen);
|
||||
}
|
||||
}
|
||||
memcpy(sockbuf->readbuf + sockbuf->writepos, buf, buflen);
|
||||
sockbuf->writepos += buflen;
|
||||
}
|
||||
|
||||
sock_fgets_exit:
|
||||
*buf = '\0';
|
||||
return count;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* }}} */
|
||||
/* {{{ _php3_sock_fread() */
|
||||
#define CHUNK_SIZE 2048
|
||||
#define MAX_CHUNKS_PER_READ 10
|
||||
|
||||
int _php3_sock_fread(char *buf, int maxlen, int socket)
|
||||
|
||||
static size_t _php3_sock_read_limited(php3i_sockbuf *sock, size_t max)
|
||||
{
|
||||
struct php3i_sockbuf *sockbuf = phpsockbuf;
|
||||
int bytesread, toread, count = 0;
|
||||
|
||||
while (sockbuf) {
|
||||
if (sockbuf->socket == socket) {
|
||||
toread = sockbuf->writepos - sockbuf->readpos;
|
||||
if (toread > maxlen) {
|
||||
toread = maxlen;
|
||||
}
|
||||
memcpy(buf, sockbuf->readbuf + sockbuf->readpos, toread);
|
||||
sockbuf->readpos += toread;
|
||||
count += toread;
|
||||
buf += toread;
|
||||
break;
|
||||
char buf[CHUNK_SIZE];
|
||||
int nr_bytes;
|
||||
size_t nr_read = 0;
|
||||
|
||||
if(sock->eof || max > CHUNK_SIZE) return nr_read;
|
||||
|
||||
nr_bytes = recv(sock->socket, buf, max, 0);
|
||||
if(nr_bytes > 0) {
|
||||
if(sock->writepos + nr_bytes > sock->readbuflen) {
|
||||
sock->readbuflen += CHUNK_SIZE;
|
||||
sock->readbuf = perealloc(sock->readbuf, sock->readbuflen,
|
||||
sock->persistent);
|
||||
}
|
||||
sockbuf = sockbuf->next;
|
||||
memcpy(WRITEPTR(sock), buf, nr_bytes);
|
||||
sock->writepos += nr_bytes;
|
||||
nr_read = nr_bytes;
|
||||
} else if(nr_bytes == 0 || (nr_bytes < 0 && errno != EWOULDBLOCK)) {
|
||||
sock->eof = 1;
|
||||
}
|
||||
|
||||
while (count < maxlen) {
|
||||
toread = maxlen - count;
|
||||
bytesread = recv(socket, buf, toread, 0);
|
||||
if (bytesread <= 0) {
|
||||
break;
|
||||
}
|
||||
count += bytesread;
|
||||
buf += bytesread;
|
||||
}
|
||||
|
||||
*buf = '\0';
|
||||
return count;
|
||||
return nr_read;
|
||||
}
|
||||
|
||||
/* }}} */
|
||||
static size_t _php3_sock_read(php3i_sockbuf *sock)
|
||||
{
|
||||
size_t nr_bytes;
|
||||
size_t nr_read = 0;
|
||||
int i;
|
||||
|
||||
for(i = 0; !sock->eof && i < MAX_CHUNKS_PER_READ; i++) {
|
||||
nr_bytes = _php3_sock_read_limited(sock, CHUNK_SIZE);
|
||||
if(nr_bytes == 0) break;
|
||||
nr_read += nr_bytes;
|
||||
}
|
||||
|
||||
return nr_read;
|
||||
}
|
||||
|
||||
int _php3_sock_set_blocking(int socket, int mode)
|
||||
{
|
||||
int old;
|
||||
SOCK_FIND(sock, socket);
|
||||
|
||||
old = sock->is_blocked;
|
||||
|
||||
sock->is_blocked = mode;
|
||||
|
||||
return old;
|
||||
}
|
||||
|
||||
#define SOCK_FIND_AND_READ \
|
||||
SOCK_FIND(sock,socket); \
|
||||
_php3_sock_read(sock)
|
||||
|
||||
#define SOCK_FIND_AND_READ_MAX(max) \
|
||||
SOCK_FIND(sock, socket); \
|
||||
if(sock->is_blocked) _php3_sock_read_limited(sock, max); else _php3_sock_read(sock)
|
||||
|
||||
/*
|
||||
* FIXME: fgets depends on '\n' as line delimiters
|
||||
*/
|
||||
|
||||
char *_php3_sock_fgets(char *buf, size_t maxlen, int socket)
|
||||
{
|
||||
char *p = NULL;
|
||||
char *ret = NULL;
|
||||
size_t amount = 0;
|
||||
size_t nr_read;
|
||||
SOCK_FIND_AND_READ_MAX(1);
|
||||
|
||||
if(maxlen < 0) return ret;
|
||||
|
||||
if(sock->is_blocked) {
|
||||
for(nr_read = 1; !sock->eof && nr_read < maxlen; ) {
|
||||
nr_read += _php3_sock_read_limited(sock, 1);
|
||||
if((p = memchr(READPTR(sock), '\n', TOREAD(sock))) != NULL) break;
|
||||
}
|
||||
} else {
|
||||
p = memchr(READPTR(sock), '\n', MIN(TOREAD(sock), maxlen - 1));
|
||||
}
|
||||
|
||||
if(p) {
|
||||
amount = (ptrdiff_t) p - (ptrdiff_t) READPTR(sock) + 1;
|
||||
} else {
|
||||
amount = MIN(TOREAD(sock), maxlen - 1);
|
||||
}
|
||||
|
||||
if(amount > 0) {
|
||||
memcpy(buf, READPTR(sock), amount);
|
||||
sock->readpos += amount;
|
||||
}
|
||||
buf[amount] = '\0';
|
||||
|
||||
/* signal error only, if we don't return data from this call and
|
||||
if there is no data to read and if the eof flag is set */
|
||||
if(amount || TOREAD(sock) || !sock->eof)
|
||||
ret = buf;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* FIXME: fgetc returns EOF, if no data is available on a nonblocking socket.
|
||||
* I don't have any documentation on the semantics of fgetc in this case.
|
||||
*
|
||||
* ss@2ns.de 19990528
|
||||
*/
|
||||
|
||||
int _php3_sock_fgetc(int socket)
|
||||
{
|
||||
int ret = EOF;
|
||||
SOCK_FIND_AND_READ_MAX(1);
|
||||
|
||||
if(TOREAD(sock) > 0) {
|
||||
ret = *READPTR(sock);
|
||||
sock->readpos++;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int _php3_sock_feof(int socket)
|
||||
{
|
||||
int ret = 0;
|
||||
SOCK_FIND_AND_READ_MAX(1);
|
||||
|
||||
if(!TOREAD(sock) && sock->eof)
|
||||
ret = 1;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
size_t _php3_sock_fread(char *ptr, size_t size, int socket)
|
||||
{
|
||||
size_t ret = 0;
|
||||
SOCK_FIND_AND_READ_MAX(size);
|
||||
|
||||
if(size < 0) return ret;
|
||||
|
||||
ret = MIN(TOREAD(sock), size);
|
||||
if(ret) {
|
||||
memcpy(ptr, READPTR(sock), ret);
|
||||
sock->readpos += ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/* {{{ module start/shutdown functions */
|
||||
|
||||
/* {{{ _php3_sock_destroy */
|
||||
#ifndef THREAD_SAFE
|
||||
static void _php3_sock_destroy(void *data)
|
||||
static void _php3_msock_destroy(int *data)
|
||||
{
|
||||
int *sock = (int *) data;
|
||||
close(*sock);
|
||||
close(*data);
|
||||
}
|
||||
#endif
|
||||
/* }}} */
|
||||
/* {{{ php3_minit_fsock */
|
||||
|
||||
@ -453,7 +639,7 @@ static int php3_minit_fsock(INIT_FUNC_ARGS)
|
||||
{
|
||||
#ifndef THREAD_SAFE
|
||||
_php3_hash_init(&ht_keys, 0, NULL, NULL, 1);
|
||||
_php3_hash_init(&ht_socks, 0, NULL, _php3_sock_destroy, 1);
|
||||
_php3_hash_init(&ht_socks, 0, NULL, (void (*)(void *))_php3_msock_destroy, 1);
|
||||
#endif
|
||||
return SUCCESS;
|
||||
}
|
||||
@ -466,6 +652,7 @@ static int php3_mshutdown_fsock(SHUTDOWN_FUNC_ARGS)
|
||||
_php3_hash_destroy(&ht_socks);
|
||||
_php3_hash_destroy(&ht_keys);
|
||||
#endif
|
||||
php_cleanup_sockbuf(1);
|
||||
return SUCCESS;
|
||||
}
|
||||
/* }}} */
|
||||
@ -473,15 +660,7 @@ static int php3_mshutdown_fsock(SHUTDOWN_FUNC_ARGS)
|
||||
|
||||
static int php3_rshutdown_fsock(SHUTDOWN_FUNC_ARGS)
|
||||
{
|
||||
struct php3i_sockbuf *sockbuf = phpsockbuf, *this;
|
||||
|
||||
while (sockbuf) {
|
||||
this = sockbuf;
|
||||
sockbuf = this->next;
|
||||
efree(this->readbuf);
|
||||
efree(this);
|
||||
}
|
||||
phpsockbuf = NULL;
|
||||
php_cleanup_sockbuf(0);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -32,29 +32,21 @@
|
||||
#ifndef _FSOCK_H
|
||||
#define _FSOCK_H
|
||||
|
||||
#if WIN32|WINNT
|
||||
# ifndef WINNT
|
||||
# define WINNT 1
|
||||
# endif
|
||||
#undef FD_SETSIZE
|
||||
#include "arpa/inet.h"
|
||||
#endif
|
||||
|
||||
#if HAVE_NETINET_IN_H
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
|
||||
extern php3_module_entry fsock_module_entry;
|
||||
#define fsock_module_ptr &fsock_module_entry
|
||||
|
||||
PHP_FUNCTION(fsockopen);
|
||||
PHP_FUNCTION(pfsockopen);
|
||||
extern int lookup_hostname(const char *addr, struct in_addr *in);
|
||||
extern int _php3_sock_fgets(char *buf, int maxlen, int socket);
|
||||
extern int _php3_sock_fread(char *buf, int maxlen, int socket);
|
||||
extern int _php3_is_persistent_sock(int);
|
||||
int _php3_sock_eof(int socket);
|
||||
int lookup_hostname(const char *addr, struct in_addr *in);
|
||||
char *_php3_sock_fgets(char *buf, size_t maxlen, int socket);
|
||||
size_t _php3_sock_fread(char *buf, size_t maxlen, int socket);
|
||||
int _php3_sock_feof(int socket);
|
||||
int _php3_sock_fgetc(int socket);
|
||||
int _php3_is_persistent_sock(int);
|
||||
int _php3_sock_set_blocking(int socket, int mode);
|
||||
int _php3_sock_destroy(int socket);
|
||||
int _php3_sock_close(int socket);
|
||||
|
||||
#define phpext_fsock_ptr fsock_module_ptr
|
||||
PHPAPI int connect_nonb(int sockfd, struct sockaddr *addr, int addrlen, struct timeval *timeout);
|
||||
|
||||
#endif /* _FSOCK_H */
|
||||
|
@ -2,7 +2,7 @@
|
||||
+----------------------------------------------------------------------+
|
||||
| PHP HTML Embedded Scripting Language Version 3.0 |
|
||||
+----------------------------------------------------------------------+
|
||||
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
|
||||
| Copyright (c) 1997-1999 PHP Development Team (See Credits file) |
|
||||
+----------------------------------------------------------------------+
|
||||
| This program is free software; you can redistribute it and/or modify |
|
||||
| it under the terms of one of the following licenses: |
|
||||
@ -24,7 +24,7 @@
|
||||
| contact core@php.net. |
|
||||
+----------------------------------------------------------------------+
|
||||
| Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
|
||||
| Stig Sæther Bakken <ssb@guardian.no> |
|
||||
| Stig Sæther Bakken <ssb@fast.no> |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
@ -47,7 +47,8 @@ PHP_FUNCTION(str_replace);
|
||||
PHP_FUNCTION(chop);
|
||||
PHP_FUNCTION(trim);
|
||||
PHP_FUNCTION(ltrim);
|
||||
void soundex(INTERNAL_FUNCTION_PARAMETERS);
|
||||
PHP_FUNCTION(similar_text);
|
||||
extern void soundex(INTERNAL_FUNCTION_PARAMETERS);
|
||||
|
||||
PHP_FUNCTION(explode);
|
||||
PHP_FUNCTION(implode);
|
||||
@ -78,15 +79,30 @@ PHP_FUNCTION(newline_to_br);
|
||||
PHP_FUNCTION(setlocale);
|
||||
PHP_FUNCTION(stristr);
|
||||
PHP_FUNCTION(chunk_split);
|
||||
PHP_FUNCTION(strip_tags);
|
||||
PHP_FUNCTION(parsestr);
|
||||
PHP_FUNCTION(bin2hex);
|
||||
|
||||
#if HAVE_CRYPT
|
||||
extern php3_module_entry crypt_module_entry;
|
||||
#define crypt_module_ptr &crypt_module_entry
|
||||
PHP_FUNCTION(crypt);
|
||||
extern int php3_minit_crypt(INIT_FUNC_ARGS);
|
||||
#else
|
||||
#define crypt_module_ptr NULL
|
||||
#endif
|
||||
|
||||
extern PHPAPI char *_php3_strtoupper(char *s);
|
||||
extern PHPAPI char *_php3_strtolower(char *s);
|
||||
extern char *_StrTr(char *string, char *str_from, char *str_to);
|
||||
extern PHPAPI char *_php3_strtr(char *string, int len, char *str_from, char *str_to, int trlen);
|
||||
extern PHPAPI char *_php3_addslashes(char *string, int length, int *new_length, int freeit);
|
||||
extern PHPAPI void _php3_stripslashes(char *string, int *len);
|
||||
extern PHPAPI void _php3_dirname(char *str, int len);
|
||||
extern PHPAPI char *php3i_stristr(unsigned char *s, unsigned char *t);
|
||||
extern PHPAPI void _php3_trim(pval *str, pval * return_value);
|
||||
extern PHPAPI void _php3_strip_tags(char *rbuf, int state);
|
||||
extern PHPAPI void _php3_char_to_str(char *str,uint len,char from,char *to,int to_len,pval *result);
|
||||
extern PHPAPI void _php3_implode(pval *delim, pval *arr, pval *return_value);
|
||||
extern PHPAPI void _php3_explode(pval *delim, pval *str, pval *return_value);
|
||||
|
||||
#endif /* _PHPSTRING_H */
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -491,7 +491,7 @@ PHP_FUNCTION(unserialize)
|
||||
}
|
||||
}
|
||||
|
||||
/* }}} *
|
||||
/* }}} */
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
|
@ -2,7 +2,7 @@
|
||||
+----------------------------------------------------------------------+
|
||||
| PHP HTML Embedded Scripting Language Version 3.0 |
|
||||
+----------------------------------------------------------------------+
|
||||
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
|
||||
| Copyright (c) 1997-1999 PHP Development Team (See Credits file) |
|
||||
+----------------------------------------------------------------------+
|
||||
| This program is free software; you can redistribute it and/or modify |
|
||||
| it under the terms of one of the following licenses: |
|
||||
@ -51,7 +51,6 @@
|
||||
|
||||
#include "safe_mode.h"
|
||||
#include "php3_realpath.h"
|
||||
#include "ext/standard/head.h"
|
||||
#include "ext/standard/php3_standard.h"
|
||||
#include "zend_compile.h"
|
||||
|
||||
@ -88,97 +87,128 @@
|
||||
#include <sys/un.h>
|
||||
#endif
|
||||
|
||||
static FILE *php3_fopen_url_wrapper(const char *path, char *mode, int options, int *issock, int *socketd);
|
||||
static FILE *php3_fopen_url_wrapper(char *path, char *mode, int options, int *issock, int *socketd);
|
||||
|
||||
int _php3_getftpresult(int socketd);
|
||||
|
||||
|
||||
/*
|
||||
When open_basedir is not NULL, check if the given filename is located in
|
||||
open_basedir. Returns -1 if error or not in the open_basedir, else 0
|
||||
|
||||
When open_basedir is NULL, always return 0
|
||||
*/
|
||||
PHPAPI int _php3_check_open_basedir(char *path)
|
||||
PHPAPI int _php3_check_specific_open_basedir(char *basedir, char *path)
|
||||
{
|
||||
char resolved_name[MAXPATHLEN];
|
||||
char resolved_basedir[MAXPATHLEN];
|
||||
char local_open_basedir[MAXPATHLEN];
|
||||
int local_open_basedir_pos;
|
||||
PLS_FETCH();
|
||||
|
||||
/* Only check when open_basedir is available */
|
||||
if (PG(open_basedir) && *PG(open_basedir)) {
|
||||
|
||||
/* Special case basedir==".": Use script-directory */
|
||||
if ((strcmp(PG(open_basedir), ".") == 0) &&
|
||||
request_info.filename &&
|
||||
*request_info.filename
|
||||
) {
|
||||
strcpy(local_open_basedir, request_info.filename);
|
||||
local_open_basedir_pos = strlen(local_open_basedir) - 1;
|
||||
/* Special case basedir==".": Use script-directory */
|
||||
if ((strcmp(basedir, ".") == 0) &&
|
||||
request_info.filename &&
|
||||
*request_info.filename
|
||||
) {
|
||||
strcpy(local_open_basedir, request_info.filename);
|
||||
local_open_basedir_pos = strlen(local_open_basedir) - 1;
|
||||
|
||||
/* Strip filename */
|
||||
/* Strip filename */
|
||||
while ((
|
||||
#if WIN32|WINNT
|
||||
(local_open_basedir[local_open_basedir_pos] != '\\') ||
|
||||
#endif
|
||||
(local_open_basedir[local_open_basedir_pos] != '/')
|
||||
) &&
|
||||
(local_open_basedir_pos >= 0)
|
||||
) {
|
||||
local_open_basedir[local_open_basedir_pos--] = 0;
|
||||
}
|
||||
/* stripping unnecessary slashes is left
|
||||
as an exercise to the underlying OS */
|
||||
#if 0
|
||||
/* Strip double (back)slashes */
|
||||
if (local_open_basedir_pos > 0) {
|
||||
while ((
|
||||
#if WIN32|WINNT
|
||||
(local_open_basedir[local_open_basedir_pos] != '\\') ||
|
||||
(local_open_basedir[local_open_basedir_pos-1] == '\\') ||
|
||||
#endif
|
||||
(local_open_basedir[local_open_basedir_pos] != '/')
|
||||
(local_open_basedir[local_open_basedir_pos-1] == '/')
|
||||
) &&
|
||||
(local_open_basedir_pos >= 0)
|
||||
(local_open_basedir_pos > 0)
|
||||
) {
|
||||
local_open_basedir[local_open_basedir_pos--] = 0;
|
||||
}
|
||||
|
||||
#if 0
|
||||
/* Strip double (back)slashes */
|
||||
if (local_open_basedir_pos > 0) {
|
||||
while ((
|
||||
#if WIN32|WINNT
|
||||
(local_open_basedir[local_open_basedir_pos-1] == '\\') ||
|
||||
#endif
|
||||
(local_open_basedir[local_open_basedir_pos-1] == '/')
|
||||
) &&
|
||||
(local_open_basedir_pos > 0)
|
||||
) {
|
||||
local_open_basedir[local_open_basedir_pos--] = 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
} else {
|
||||
/* Else use the unmodified path */
|
||||
strcpy(local_open_basedir, PG(open_basedir));
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
/* Else use the unmodified path */
|
||||
strcpy(local_open_basedir, basedir);
|
||||
}
|
||||
|
||||
/* Resolve the real path into resolved_name */
|
||||
if (_php3_realpath(path, resolved_name) != NULL) {
|
||||
/* Check the path */
|
||||
/* Resolve the real path into resolved_name */
|
||||
if ((_php3_realpath(path, resolved_name) != NULL) && (_php3_realpath(local_open_basedir, resolved_basedir) != NULL)) {
|
||||
/* Check the path */
|
||||
#if WIN32|WINNT
|
||||
if (strncasecmp(local_open_basedir, resolved_name, strlen(local_open_basedir)) == 0) {
|
||||
if (strncasecmp(resolved_basedir, resolved_name, strlen(resolved_basedir)) == 0) {
|
||||
#else
|
||||
if (strncmp(local_open_basedir, resolved_name, strlen(local_open_basedir)) == 0) {
|
||||
if (strncmp(resolved_basedir, resolved_name, strlen(resolved_basedir)) == 0) {
|
||||
#endif
|
||||
/* File is in the right directory */
|
||||
return 0;
|
||||
} else {
|
||||
php3_error(E_WARNING, "open_basedir restriction in effect. File is in wrong directory.");
|
||||
return -1;
|
||||
}
|
||||
/* File is in the right directory */
|
||||
return 0;
|
||||
} else {
|
||||
/* Unable to resolve the real path, return -1 */
|
||||
php3_error(E_WARNING, "open_basedir restriction in effect. Unable to verify location of file.");
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
/* open_basedir is not available, return 0 */
|
||||
return 0;
|
||||
/* Unable to resolve the real path, return -1 */
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
PHPAPI int _php3_check_open_basedir(char *path)
|
||||
{
|
||||
/* Only check when open_basedir is available */
|
||||
if (PG(open_basedir) && *PG(open_basedir)) {
|
||||
char *pathbuf;
|
||||
char *ptr;
|
||||
char *end;
|
||||
|
||||
pathbuf = estrdup(PG(open_basedir));
|
||||
|
||||
ptr = pathbuf;
|
||||
|
||||
while (ptr && *ptr) {
|
||||
#if WIN32|WINNT
|
||||
end = strchr(ptr, ';');
|
||||
#else
|
||||
end = strchr(ptr, ':');
|
||||
#endif
|
||||
if (end != NULL) {
|
||||
*end = '\0';
|
||||
end++;
|
||||
}
|
||||
|
||||
if (_php3_check_specific_open_basedir(ptr, path) == 0) {
|
||||
efree(pathbuf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
ptr = end;
|
||||
}
|
||||
php3_error(E_WARNING, "open_basedir restriction in effect. File is in wrong directory.");
|
||||
efree(pathbuf);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Nothing to check... */
|
||||
return 0;
|
||||
}
|
||||
|
||||
PHPAPI FILE *php3_fopen_wrapper(char *path, char *mode, int options, int *issock, int *socketd)
|
||||
{
|
||||
int cm=2; /* checkuid mode: 2 = if file does not exist, check directory */
|
||||
PLS_FETCH();
|
||||
|
||||
/* FIXME Lets not get in the habit of doing stuff like this. This should
|
||||
be runtime enabled, NOT compile time. */
|
||||
#if PHP3_URL_FOPEN
|
||||
if (!(options & IGNORE_URL)) {
|
||||
return php3_fopen_url_wrapper(path, mode, options, issock, socketd);
|
||||
@ -199,17 +229,17 @@ PHPAPI FILE *php3_fopen_wrapper(char *path, char *mode, int options, int *issock
|
||||
|
||||
#if CGI_BINARY || FHTTPD || USE_SAPI
|
||||
|
||||
PHPAPI FILE *php3_fopen_for_parser(void)
|
||||
FILE *php3_fopen_for_parser(void)
|
||||
{
|
||||
FILE *fp;
|
||||
struct stat st;
|
||||
char *temp, *path_info, *fn;
|
||||
int l;
|
||||
PLS_FETCH();
|
||||
SLS_FETCH();
|
||||
|
||||
|
||||
fn = request_info.filename;
|
||||
path_info = SG(request_info).request_uri;
|
||||
path_info = request_info.path_info;
|
||||
#if HAVE_PWD_H
|
||||
if (PG(user_dir) && *PG(user_dir)
|
||||
&& path_info && '/' == path_info[0] && '~' == path_info[1]) {
|
||||
@ -280,17 +310,17 @@ PHPAPI FILE *php3_fopen_for_parser(void)
|
||||
fp = NULL;
|
||||
}
|
||||
if (!fp) {
|
||||
php3_error(E_CORE_ERROR, "Unable to open %s", fn);
|
||||
php3_error(E_ERROR, "Unable to open %s", fn);
|
||||
STR_FREE(request_info.filename); /* for same reason as above */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
temp = estrdup(fn);
|
||||
_php3_hash_index_update(&include_names, 0, (void *) &fn, sizeof(char *), NULL);
|
||||
|
||||
temp = strdup(fn);
|
||||
_php3_dirname(temp, strlen(temp));
|
||||
if (*temp) {
|
||||
if (*temp)
|
||||
chdir(temp);
|
||||
}
|
||||
efree(temp);
|
||||
free(temp);
|
||||
|
||||
return fp;
|
||||
}
|
||||
@ -417,7 +447,7 @@ PHPAPI FILE *php3_fopen_with_path(char *filename, char *mode, char *path, char *
|
||||
* Otherwise, fopen is called as usual and the file pointer is returned.
|
||||
*/
|
||||
|
||||
static FILE *php3_fopen_url_wrapper(const char *path, char *mode, int options, int *issock, int *socketd)
|
||||
static FILE *php3_fopen_url_wrapper(char *path, char *mode, int options, int *issock, int *socketd)
|
||||
{
|
||||
url *resource;
|
||||
int result;
|
||||
@ -443,10 +473,9 @@ static FILE *php3_fopen_url_wrapper(const char *path, char *mode, int options, i
|
||||
FILE *fp = NULL;
|
||||
struct sockaddr_in server;
|
||||
unsigned short portno;
|
||||
char winfeof;
|
||||
|
||||
if (!strncasecmp(path, "http://", 7)) {
|
||||
resource = url_parse((char *) path);
|
||||
resource = url_parse(path);
|
||||
if (resource == NULL) {
|
||||
php3_error(E_WARNING, "Invalid URL specified, %s", path);
|
||||
*issock = BAD_URL;
|
||||
@ -463,9 +492,9 @@ static FILE *php3_fopen_url_wrapper(const char *path, char *mode, int options, i
|
||||
free_url(resource);
|
||||
return NULL;
|
||||
}
|
||||
lookup_hostname(resource->host, &server.sin_addr);
|
||||
server.sin_family = AF_INET;
|
||||
|
||||
if (server.sin_addr.s_addr == -1) {
|
||||
if (lookup_hostname(resource->host, &server.sin_addr)) {
|
||||
SOCK_FCLOSE(*socketd);
|
||||
*socketd = 0;
|
||||
free_url(resource);
|
||||
@ -553,8 +582,8 @@ static FILE *php3_fopen_url_wrapper(const char *path, char *mode, int options, i
|
||||
/* Read past http header */
|
||||
body = 0;
|
||||
location[0] = '\0';
|
||||
while (!body && recv(*socketd, (char *) &winfeof, 1, MSG_PEEK)) {
|
||||
if (SOCK_FGETC(buf, *socketd) == SOCK_RECV_ERR) {
|
||||
while (!body && !SOCK_FEOF(*socketd)) {
|
||||
if ((buf[0] = SOCK_FGETC(*socketd)) == EOF) {
|
||||
SOCK_FCLOSE(*socketd);
|
||||
*socketd = 0;
|
||||
free_url(resource);
|
||||
@ -606,7 +635,7 @@ static FILE *php3_fopen_url_wrapper(const char *path, char *mode, int options, i
|
||||
*issock = 1;
|
||||
return (fp);
|
||||
} else if (!strncasecmp(path, "ftp://", 6)) {
|
||||
resource = url_parse((char *) path);
|
||||
resource = url_parse(path);
|
||||
if (resource == NULL) {
|
||||
php3_error(E_WARNING, "Invalid URL specified, %s", path);
|
||||
*issock = BAD_URL;
|
||||
@ -628,9 +657,9 @@ static FILE *php3_fopen_url_wrapper(const char *path, char *mode, int options, i
|
||||
free_url(resource);
|
||||
return NULL;
|
||||
}
|
||||
lookup_hostname(resource->host, &server.sin_addr);
|
||||
server.sin_family = AF_INET;
|
||||
|
||||
if (server.sin_addr.s_addr == -1) {
|
||||
if (lookup_hostname(resource->host, &server.sin_addr)) {
|
||||
SOCK_FCLOSE(*socketd);
|
||||
*socketd = 0;
|
||||
free_url(resource);
|
||||
@ -840,9 +869,9 @@ static FILE *php3_fopen_url_wrapper(const char *path, char *mode, int options, i
|
||||
free_url(resource);
|
||||
return NULL;
|
||||
}
|
||||
lookup_hostname(resource->host, &server.sin_addr);
|
||||
server.sin_family = AF_INET;
|
||||
|
||||
if (server.sin_addr.s_addr == -1) {
|
||||
if (lookup_hostname(resource->host, &server.sin_addr)) {
|
||||
free_url(resource);
|
||||
SOCK_FCLOSE(*socketd);
|
||||
*socketd = 0;
|
||||
@ -881,17 +910,15 @@ static FILE *php3_fopen_url_wrapper(const char *path, char *mode, int options, i
|
||||
return (fp);
|
||||
|
||||
} else {
|
||||
PLS_FETCH();
|
||||
|
||||
if (options & USE_PATH) {
|
||||
fp = php3_fopen_with_path((char *) path, mode, PG(include_path), NULL);
|
||||
fp = php3_fopen_with_path(path, mode, PG(include_path), NULL);
|
||||
} else {
|
||||
int cm=2;
|
||||
if(!strcmp(mode,"r") || !strcmp(mode,"r+")) cm=0;
|
||||
if (options & ENFORCE_SAFE_MODE && PG(safe_mode) && (!_php3_checkuid(path, cm))) {
|
||||
fp = NULL;
|
||||
} else {
|
||||
if (_php3_check_open_basedir((char *) path)) {
|
||||
if (_php3_check_open_basedir(path)) {
|
||||
fp = NULL;
|
||||
} else {
|
||||
fp = fopen(path, mode);
|
||||
|
@ -2,7 +2,7 @@
|
||||
+----------------------------------------------------------------------+
|
||||
| PHP HTML Embedded Scripting Language Version 3.0 |
|
||||
+----------------------------------------------------------------------+
|
||||
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
|
||||
| Copyright (c) 1997-1999 PHP Development Team (See Credits file) |
|
||||
+----------------------------------------------------------------------+
|
||||
| This program is free software; you can redistribute it and/or modify |
|
||||
| it under the terms of one of the following licenses: |
|
||||
@ -46,17 +46,18 @@
|
||||
# define SOCK_ERR INVALID_SOCKET
|
||||
# define SOCK_CONN_ERR SOCKET_ERROR
|
||||
# define SOCK_RECV_ERR SOCKET_ERROR
|
||||
# define SOCK_FCLOSE(s) closesocket(s)
|
||||
#else
|
||||
# define SOCK_ERR -1
|
||||
# define SOCK_CONN_ERR -1
|
||||
# define SOCK_RECV_ERR -1
|
||||
# define SOCK_FCLOSE(s) close(s)
|
||||
#endif
|
||||
#define SOCK_WRITE(d,s) send(s,d,strlen(d),0)
|
||||
#define SOCK_WRITEL(d,l,s) send(s,d,l,0)
|
||||
#define SOCK_FGETC(c,s) recv(s,c,1,0)
|
||||
#define SOCK_FGETC(s) _php3_sock_fgetc((s))
|
||||
#define SOCK_FGETS(b,l,s) _php3_sock_fgets((b),(l),(s))
|
||||
#define SOCK_FEOF(sock) _php3_sock_feof((sock))
|
||||
#define SOCK_FREAD(ptr,size,sock) _php3_sock_fread((ptr),(size),(sock))
|
||||
#define SOCK_FCLOSE(s) _php3_sock_close(s)
|
||||
|
||||
/* values for issock */
|
||||
#define IS_NOT_SOCKET 0
|
||||
@ -69,15 +70,15 @@ extern int wsa_fp; /* a list for open sockets */
|
||||
|
||||
extern PHPAPI FILE *php3_fopen_wrapper(char *filename, char *mode, int options, int *issock, int *socketd);
|
||||
|
||||
PHPAPI FILE *php3_fopen_for_parser(void);
|
||||
extern FILE *php3_fopen_for_parser(void);
|
||||
|
||||
extern PHPAPI int _php3_check_open_basedir(char *path);
|
||||
extern PHPAPI int _php3_check_specific_open_basedir(char *basedir, char *path);
|
||||
|
||||
extern PHPAPI FILE *php3_fopen_with_path(char *filename, char *mode, char *path, char **opened_path);
|
||||
|
||||
extern PHPAPI int php3_isurl(char *path);
|
||||
extern PHPAPI char *php3_strip_url_passwd(char *path);
|
||||
extern PHPAPI int php3_write(void *buf, int size);
|
||||
|
||||
extern PHPAPI char *expand_filepath(char *filepath);
|
||||
|
||||
|
@ -29,13 +29,13 @@ struct _php_core_globals {
|
||||
long magic_quotes_runtime;
|
||||
long magic_quotes_sybase;
|
||||
|
||||
long asp_tags;
|
||||
long short_tags;
|
||||
long asp_tags;
|
||||
long short_tags;
|
||||
|
||||
long safe_mode;
|
||||
long sql_safe_mode;
|
||||
char *safe_mode_exec_dir;
|
||||
long enable_dl;
|
||||
long safe_mode;
|
||||
long sql_safe_mode;
|
||||
char *safe_mode_exec_dir;
|
||||
long enable_dl;
|
||||
|
||||
long memory_limit;
|
||||
|
||||
@ -47,11 +47,11 @@ struct _php_core_globals {
|
||||
char *doc_root;
|
||||
char *user_dir;
|
||||
char *include_path;
|
||||
char *open_basedir;
|
||||
char *open_basedir;
|
||||
char *extension_dir;
|
||||
|
||||
char *upload_tmp_dir;
|
||||
long upload_max_filesize;
|
||||
long upload_max_filesize;
|
||||
|
||||
char *auto_prepend_file;
|
||||
char *auto_append_file;
|
||||
@ -63,8 +63,15 @@ struct _php_core_globals {
|
||||
|
||||
long y2k_compliance;
|
||||
|
||||
unsigned char header_is_being_sent;
|
||||
unsigned char header_is_being_sent;
|
||||
};
|
||||
|
||||
|
||||
#endif /* _PHP_GLOBALS_H */
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
* c-basic-offset: 4
|
||||
* End:
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user