CVS update: php4
| From: | ssb | Date: | Tue, 15 Jun 1999 21:50:58 +0000 |
| Subject: | CVS update: php4 | ||
| Groups: | php.version4 | ||
| Request: | Send a blank email to php-version4+get-1575@lists.php.net to get a copy of this message | ||
Date: Tuesday June 15, 1999 @ 17:50
Author: ssb
Update of /repository/php4
In directory php:/tmp/cvs-serv11599
Modified Files:
fopen-wrappers.c fopen-wrappers.h
Log Message:
* reverse fsock/string import patches
Index: php4/fopen-wrappers.c
diff -u php4/fopen-wrappers.c:1.13 php4/fopen-wrappers.c:1.14
--- php4/fopen-wrappers.c:1.13 Tue Jun 15 13:06:21 1999
+++ php4/fopen-wrappers.c Tue Jun 15 17:50:55 1999
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-1999 PHP Development Team (See Credits file) |
+ | Copyright (c) 1997,1998 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: |
@@ -27,7 +27,7 @@
| Jim Winstead <jimw@php.net> |
+----------------------------------------------------------------------+
*/
-/* $Id: fopen-wrappers.c,v 1.13 1999/06/15 17:06:21 ssb Exp $ */
+/* $Id: fopen-wrappers.c,v 1.14 1999/06/15 21:50:55 ssb Exp $ */
#include "php.h"
#include "php_globals.h"
@@ -51,6 +51,7 @@
#include "safe_mode.h"
#include "php3_realpath.h"
+#include "ext/standard/head.h"
#include "ext/standard/php3_standard.h"
#include "zend_compile.h"
@@ -87,128 +88,97 @@
#include <sys/un.h>
#endif
-static FILE *php3_fopen_url_wrapper(char *path, char *mode, int options, int *issock, int
*socketd);
+static FILE *php3_fopen_url_wrapper(const 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_specific_open_basedir(char *basedir, char *path)
+PHPAPI int _php3_check_open_basedir(char *path)
{
char resolved_name[MAXPATHLEN];
- char resolved_basedir[MAXPATHLEN];
char local_open_basedir[MAXPATHLEN];
int local_open_basedir_pos;
+ PLS_FETCH();
- /* 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 */
- while ((
-#if WIN32|WINNT
- (local_open_basedir[local_open_basedir_pos] != '\\') ||
-#endif
- (local_open_basedir[local_open_basedir_pos] != '/')
- ) &&
- (local_open_basedir_pos >= 0)
+ /* 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
) {
- 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) {
+ strcpy(local_open_basedir, request_info.filename);
+ local_open_basedir_pos = strlen(local_open_basedir) - 1;
+
+ /* Strip filename */
while ((
#if WIN32|WINNT
- (local_open_basedir[local_open_basedir_pos-1] == '\\') ||
+ (local_open_basedir[local_open_basedir_pos] != '\\') ||
#endif
- (local_open_basedir[local_open_basedir_pos-1] == '/')
+ (local_open_basedir[local_open_basedir_pos] != '/')
) &&
- (local_open_basedir_pos > 0)
+ (local_open_basedir_pos >= 0)
) {
local_open_basedir[local_open_basedir_pos--] = 0;
}
- }
-#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) && (_php3_realpath(local_open_basedir,
resolved_basedir) != NULL)) {
- /* Check the path */
+
+#if 0
+ /* Strip double (back)slashes */
+ if (local_open_basedir_pos > 0) {
+ while ((
#if WIN32|WINNT
- if (strncasecmp(resolved_basedir, resolved_name, strlen(resolved_basedir)) == 0) {
-#else
- if (strncmp(resolved_basedir, resolved_name, strlen(resolved_basedir)) == 0) {
+ (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
- /* File is in the right directory */
- return 0;
+
} else {
- return -1;
+ /* Else use the unmodified path */
+ strcpy(local_open_basedir, PG(open_basedir));
}
- } else {
- /* 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) {
+
+ /* Resolve the real path into resolved_name */
+ if (_php3_realpath(path, resolved_name) != NULL) {
+ /* Check the path */
#if WIN32|WINNT
- end = strchr(ptr, ';');
+ if (strncasecmp(local_open_basedir, resolved_name, strlen(local_open_basedir)) == 0) {
#else
- end = strchr(ptr, ':');
+ if (strncmp(local_open_basedir, resolved_name, strlen(local_open_basedir)) == 0) {
#endif
- if (end != NULL) {
- *end = '\0';
- end++;
- }
-
- if (_php3_check_specific_open_basedir(ptr, path) == 0) {
- efree(pathbuf);
+ /* 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;
}
-
- ptr = end;
+ } 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;
}
- php3_error(E_WARNING, "open_basedir restriction in effect. File is in wrong
directory.");
- efree(pathbuf);
- return -1;
+ } else {
+ /* open_basedir is not available, return 0 */
+ return 0;
}
-
- /* 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 */
- /* FIXME Lets not get in the habit of doing stuff like this. This should
- be runtime enabled, NOT compile time. */
+ PLS_FETCH();
+
#if PHP3_URL_FOPEN
if (!(options & IGNORE_URL)) {
return php3_fopen_url_wrapper(path, mode, options, issock, socketd);
@@ -229,17 +199,17 @@
#if CGI_BINARY || FHTTPD || USE_SAPI
-FILE *php3_fopen_for_parser(void)
+PHPAPI 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 = request_info.path_info;
+ path_info = SG(request_info).request_uri;
#if HAVE_PWD_H
if (PG(user_dir) && *PG(user_dir)
&& path_info && '/' == path_info[0] && '~' ==
path_info[1]) {
@@ -310,17 +280,17 @@
fp = NULL;
}
if (!fp) {
- php3_error(E_ERROR, "Unable to open %s", fn);
+ php3_error(E_CORE_ERROR, "Unable to open %s", fn);
STR_FREE(request_info.filename); /* for same reason as above */
return NULL;
}
- _php3_hash_index_update(&include_names, 0, (void *) &fn, sizeof(char *), NULL);
-
- temp = strdup(fn);
+
+ temp = estrdup(fn);
_php3_dirname(temp, strlen(temp));
- if (*temp)
+ if (*temp) {
chdir(temp);
- free(temp);
+ }
+ efree(temp);
return fp;
}
@@ -447,7 +417,7 @@
* Otherwise, fopen is called as usual and the file pointer is returned.
*/
-static FILE *php3_fopen_url_wrapper(char *path, char *mode, int options, int *issock, int *socketd)
+static FILE *php3_fopen_url_wrapper(const char *path, char *mode, int options, int *issock, int
*socketd)
{
url *resource;
int result;
@@ -473,9 +443,10 @@
FILE *fp = NULL;
struct sockaddr_in server;
unsigned short portno;
+ char winfeof;
if (!strncasecmp(path, "http://", 7)) {
- resource = url_parse(path);
+ resource = url_parse((char *) path);
if (resource == NULL) {
php3_error(E_WARNING, "Invalid URL specified, %s", path);
*issock = BAD_URL;
@@ -492,15 +463,16 @@
free_url(resource);
return NULL;
}
- server.sin_family = AF_INET;
+ lookup_hostname(resource->host, &server.sin_addr);
- if (lookup_hostname(resource->host, &server.sin_addr)) {
+ if (server.sin_addr.s_addr == -1) {
SOCK_FCLOSE(*socketd);
*socketd = 0;
free_url(resource);
return NULL;
}
server.sin_port = htons(resource->port);
+ server.sin_family = AF_INET;
if (connect(*socketd, (struct sockaddr *) &server, sizeof(server)) == SOCK_CONN_ERR) {
SOCK_FCLOSE(*socketd);
@@ -582,8 +554,8 @@
/* Read past http header */
body = 0;
location[0] = '\0';
- while (!body && !SOCK_FEOF(*socketd)) {
- if ((buf[0] = SOCK_FGETC(*socketd)) == EOF) {
+ while (!body && recv(*socketd, (char *) &winfeof, 1, MSG_PEEK)) {
+ if (SOCK_FGETC(buf, *socketd) == SOCK_RECV_ERR) {
SOCK_FCLOSE(*socketd);
*socketd = 0;
free_url(resource);
@@ -635,7 +607,7 @@
*issock = 1;
return (fp);
} else if (!strncasecmp(path, "ftp://", 6)) {
- resource = url_parse(path);
+ resource = url_parse((char *) path);
if (resource == NULL) {
php3_error(E_WARNING, "Invalid URL specified, %s", path);
*issock = BAD_URL;
@@ -657,9 +629,9 @@
free_url(resource);
return NULL;
}
- server.sin_family = AF_INET;
+ lookup_hostname(resource->host, &server.sin_addr);
- if (lookup_hostname(resource->host, &server.sin_addr)) {
+ if (server.sin_addr.s_addr == -1) {
SOCK_FCLOSE(*socketd);
*socketd = 0;
free_url(resource);
@@ -869,9 +841,9 @@
free_url(resource);
return NULL;
}
- server.sin_family = AF_INET;
+ lookup_hostname(resource->host, &server.sin_addr);
- if (lookup_hostname(resource->host, &server.sin_addr)) {
+ if (server.sin_addr.s_addr == -1) {
free_url(resource);
SOCK_FCLOSE(*socketd);
*socketd = 0;
@@ -910,15 +882,17 @@
return (fp);
} else {
+ PLS_FETCH();
+
if (options & USE_PATH) {
- fp = php3_fopen_with_path(path, mode, PG(include_path), NULL);
+ fp = php3_fopen_with_path((char *) 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(path)) {
+ if (_php3_check_open_basedir((char *) path)) {
fp = NULL;
} else {
fp = fopen(path, mode);
Index: php4/fopen-wrappers.h
diff -u php4/fopen-wrappers.h:1.3 php4/fopen-wrappers.h:1.4
--- php4/fopen-wrappers.h:1.3 Tue Jun 15 13:06:21 1999
+++ php4/fopen-wrappers.h Tue Jun 15 17:50:56 1999
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-1999 PHP Development Team (See Credits file) |
+ | Copyright (c) 1997,1998 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: |
@@ -26,7 +26,7 @@
| Authors: Jim Winstead <jimw@php.net> |
+----------------------------------------------------------------------+
*/
-/* $Id: fopen-wrappers.h,v 1.3 1999/06/15 17:06:21 ssb Exp $ */
+/* $Id: fopen-wrappers.h,v 1.4 1999/06/15 21:50:56 ssb Exp $ */
#ifndef _FOPEN_WRAPPERS_H
#define _FOPEN_WRAPPERS_H
@@ -46,18 +46,17 @@
# 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(s) _php3_sock_fgetc((s))
+#define SOCK_FGETC(c,s) recv(s,c,1,0)
#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
@@ -70,15 +69,15 @@
extern PHPAPI FILE *php3_fopen_wrapper(char *filename, char *mode, int options, int *issock, int
*socketd);
-extern FILE *php3_fopen_for_parser(void);
+PHPAPI 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);