CVS update: php4

From: Date: Wed, 16 Jun 1999 17:06:51 +0000
Subject: CVS update: php4
Groups: php.version4 
Request: Send a blank email to php-version4+get-1579@lists.php.net to get a copy of this message
Date: Wednesday June 16, 1999 @ 13:06 Author: ssb Update of /repository/php4 In directory php:/tmp/cvs-serv20160 Modified Files: acconfig.h.in config.w32.h configure.in.in fopen-wrappers.c fopen-wrappers.h main.c Log Message: * fixed some #if/#ifdef issues * hand-patched in php3 changes from 3.0.6 to HEAD in these files: fopen-wrappers.[ch] ext/standard/file.[ch] ext/standard/fsock.[ch] ext/standard/php3_string.h ext/standard/string.c * added some new file/socket macros for more readable code: FP_FGETS(buf,len,sock,fp,issock) FP_FREAD(buf,len,sock,fp,issock) FP_FEOF(sock,fp,issock) FP_FGETC(sock,fp,issock) Index: php4/acconfig.h.in diff -u php4/acconfig.h.in:1.17 php4/acconfig.h.in:1.18 --- php4/acconfig.h.in:1.17 Mon May 3 23:42:19 1999 +++ php4/acconfig.h.in Wed Jun 16 13:06:51 1999 @@ -26,10 +26,10 @@ /* Define if you have dirent.h but opendir() resides in libc rather than in libdir */ /* This will cause HAVE_DIRENT_H defined twice sometimes, but it should be problem */ -#define HAVE_DIRENT_H 0 +#undef HAVE_DIRENT_H /* Define if you have the resolv library (-lresolv). */ -#define HAVE_LIBRESOLV 0 +#undef HAVE_LIBRESOLV /* Define if you have the pam library (-lpam). */ #define HAVE_LIBPAM 0 @@ -62,10 +62,10 @@ #define HSREGEX 0 /* Define if you have and want to use libnsl */ -#define HAVE_LIBNSL 0 +#undef HAVE_LIBNSL /* Define if you have and want to use libsocket */ -#define HAVE_LIBSOCKET 0 +#undef HAVE_LIBSOCKET /* Define if you have the sendmail program available */ #define HAVE_SENDMAIL 0 @@ -91,12 +91,6 @@ #ifndef DEBUG /* should be set to ZEND_DEBUG */ #define DEBUG 0 #endif - -/* Define if your system has the gettimeofday() call */ -#define HAVE_GETTIMEOFDAY 0 - -/* Define if your system has the putenv() library call */ -#define HAVE_PUTENV 0 /* Define if you want to enable PHP RPC (experimental) */ #define PHP_RPC 0 Index: php4/config.w32.h diff -u php4/config.w32.h:1.4 php4/config.w32.h:1.5 --- php4/config.w32.h:1.4 Fri Jun 4 06:45:53 1999 +++ php4/config.w32.h Wed Jun 16 13:06:51 1999 @@ -60,7 +60,7 @@ ---------------------------------------------------------------*/ /* Define if you have the link function. */ -#define HAVE_LINK 0 +#undef HAVE_LINK /* Define if you have the lockf function. */ /* #undef HAVE_LOCKF */ @@ -72,10 +72,10 @@ /* #undef HAVE_SRAND48 */ /* Define if you have the symlink function. */ -#define HAVE_SYMLINK 0 +#undef HAVE_SYMLINK /* Define if you have the usleep function. */ -#define HAVE_USLEEP 1 +#undef HAVE_USLEEP #define NEED_ISBLANK 1 /* ---------------------------------------------------------------- @@ -96,7 +96,7 @@ ---------------------------------------------------------------*/ #define DISCARD_PATH 1 -#define HAVE_SETITIMER 0 +#undef HAVE_SETITIMER #define HAVE_IODBC 0 /*getting rid of old odbc*/ #define HAVE_UODBC 0 #define HAVE_LIBDL 1 @@ -107,7 +107,7 @@ #define HAVE_TZSET 1 /* Define if you have the flock function. */ -#define HAVE_FLOCK 0 +#undef HAVE_FLOCK /* Define if using alloca.c. */ /* #undef C_ALLOCA */ @@ -126,7 +126,7 @@ /* #undef HAVE_ALLOCA_H */ /* Define if you have <sys/time.h> */ -#define HAVE_SYS_TIME_H 0 +#undef HAVE_SYS_TIME_H /* Define if you have <signal.h> */ #define HAVE_SIGNAL_H 1 @@ -135,10 +135,10 @@ /* #undef HAVE_DOPRNT */ /* Define if your struct stat has st_blksize. */ -#define HAVE_ST_BLKSIZE 0 +#undef HAVE_ST_BLKSIZE /* Define if your struct stat has st_blocks. */ -#define HAVE_ST_BLOCKS 0 +#undef HAVE_ST_BLOCKS /* Define if your struct stat has st_rdev. */ #define HAVE_ST_RDEV 1 @@ -228,7 +228,7 @@ /* #undef HAVE_CRYPT_H */ /* Define if you have the <dirent.h> header file. */ -#define HAVE_DIRENT_H 0 +#undef HAVE_DIRENT_H /* Define if you have the <fcntl.h> header file. */ #define HAVE_FCNTL_H 1 Index: php4/configure.in.in diff -u php4/configure.in.in:1.35 php4/configure.in.in:1.36 --- php4/configure.in.in:1.35 Fri Jun 11 08:22:53 1999 +++ php4/configure.in.in Wed Jun 16 13:06:51 1999 @@ -1,4 +1,4 @@ -dnl $Id: configure.in.in,v 1.35 1999/06/11 12:22:53 ssb Exp $ -*- sh -*- +dnl $Id: configure.in.in,v 1.36 1999/06/16 17:06:51 ssb Exp $ -*- sh -*- dnl Process this file with autoconf to produce a configure script. @@ -211,7 +211,7 @@ fi AC_MISSING_FCLOSE_DECL dnl QNX requires unix.h to allow functions in libunix to work properly -AC_CHECK_HEADERS(fcntl.h unistd.h crypt.h sys/file.h memory.h pwd.h grp.h sys/socket.h sys/wait.h syslog.h string.h sys/varargs.h stdarg.h sys/time.h signal.h netinet/in.h dlfcn.h limits.h sys/types.h unix.h arpa/inet.h) +AC_CHECK_HEADERS(fcntl.h unistd.h crypt.h sys/file.h memory.h pwd.h grp.h sys/socket.h sys/wait.h syslog.h string.h sys/varargs.h stdarg.h sys/time.h signal.h netinet/in.h dlfcn.h limits.h sys/types.h unix.h arpa/inet.h locale.h) dnl Checks for typedefs, structures, and compiler characteristics. AC_STRUCT_TM Index: php4/fopen-wrappers.c diff -u php4/fopen-wrappers.c:1.14 php4/fopen-wrappers.c:1.15 --- php4/fopen-wrappers.c:1.14 Tue Jun 15 17:50:55 1999 +++ php4/fopen-wrappers.c Wed Jun 16 13:06:51 1999 @@ -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: | @@ -27,8 +27,10 @@ | Jim Winstead <jimw@php.net> | +----------------------------------------------------------------------+ */ -/* $Id: fopen-wrappers.c,v 1.14 1999/06/15 21:50:55 ssb Exp $ */ +/* $Id: fopen-wrappers.c,v 1.15 1999/06/16 17:06:51 ssb Exp $ */ +/* Synced with php3 revision 1.62 1999-06-16 [ssb] */ + #include "php.h" #include "php_globals.h" #include "SAPI.h" @@ -98,80 +100,94 @@ 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 + /* Special case basedir==".": Use script-directory */ + if ((strcmp(PG(open_basedir), ".") == 0) && + SG(request_info).path_translated && + *SG(request_info).path_translated ) { - strcpy(local_open_basedir, request_info.filename); - local_open_basedir_pos = strlen(local_open_basedir) - 1; + strcpy(local_open_basedir, SG(request_info).path_translated); + local_open_basedir_pos = strlen(local_open_basedir) - 1; - /* Strip filename */ - while (( + /* Strip filename */ + while (( #if WIN32|WINNT - (local_open_basedir[local_open_basedir_pos] != '\\') || + (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] != '/') + ) && + (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 (( + local_open_basedir[local_open_basedir_pos--] = 0; + } + } 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 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; - } - } + if (strncasecmp(resolved_basedir, resolved_name, strlen(resolved_basedir)) == 0) { +#else + if (strncmp(resolved_basedir, resolved_name, strlen(resolved_basedir)) == 0) { #endif - + /* File is in the right directory */ + return 0; } else { - /* Else use the unmodified path */ - strcpy(local_open_basedir, PG(open_basedir)); + return -1; } - - /* Resolve the real path into resolved_name */ - if (_php3_realpath(path, resolved_name) != NULL) { - /* Check the path */ + } 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) { #if WIN32|WINNT - if (strncasecmp(local_open_basedir, resolved_name, strlen(local_open_basedir)) == 0) { + end = strchr(ptr, ';'); #else - if (strncmp(local_open_basedir, resolved_name, strlen(local_open_basedir)) == 0) { + end = strchr(ptr, ':'); #endif - /* File is in the right directory */ + if (end != NULL) { + *end = '\0'; + end++; + } + + if (_php3_check_specific_open_basedir(ptr, path) == 0) { + efree(pathbuf); return 0; - } else { - php3_error(E_WARNING, "open_basedir restriction in effect. File is in wrong directory."); - return -1; } - } 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; + + ptr = end; } - } else { - /* open_basedir is not available, return 0 */ - return 0; + 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) @@ -179,6 +195,8 @@ 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); @@ -208,7 +226,7 @@ PLS_FETCH(); SLS_FETCH(); - fn = request_info.filename; + fn = SG(request_info).path_translated; path_info = SG(request_info).request_uri; #if HAVE_PWD_H if (PG(user_dir) && *PG(user_dir) @@ -236,8 +254,8 @@ strcat(fn, PG(user_dir)); /* safe */ strcat(fn, "/"); /* safe */ strcat(fn, s + 1); /* safe (shorter than path_info) */ - STR_FREE(request_info.filename); - request_info.filename = fn; + STR_FREE(SG(request_info).path_translated); + SG(request_info).path_translated = fn; } } } @@ -259,17 +277,17 @@ if ('/' == path_info[0]) l--; strcpy(fn + l, path_info); - STR_FREE(request_info.filename); - request_info.filename = fn; + STR_FREE(SG(request_info).path_translated); + SG(request_info).path_translated = fn; } } /* if doc_root && path_info */ if (!fn) { - /* we have to free request_info.filename here because + /* we have to free SG(request_info).path_translated here because php3_destroy_request_info assumes that it will get freed when the include_names hash is emptied, but we're not adding it in this case */ - STR_FREE(request_info.filename); - request_info.filename = NULL; + STR_FREE(SG(request_info).path_translated); + SG(request_info).path_translated = NULL; return NULL; } fp = fopen(fn, "r"); @@ -281,7 +299,7 @@ } if (!fp) { php3_error(E_CORE_ERROR, "Unable to open %s", fn); - STR_FREE(request_info.filename); /* for same reason as above */ + STR_FREE(SG(request_info).path_translated); /* for same reason as above */ return NULL; } @@ -443,7 +461,6 @@ FILE *fp = NULL; struct sockaddr_in server; unsigned short portno; - char winfeof; if (!strncasecmp(path, "http://", 7)) { resource = url_parse((char *) path); @@ -463,16 +480,15 @@ 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); 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); @@ -554,8 +570,8 @@ /* 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); @@ -629,9 +645,9 @@ 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); @@ -712,6 +728,16 @@ return NULL; } + /* set the connection to be binary */ + SOCK_WRITE("TYPE I\n", *socketd); + result = _php3_getftpresult(*socketd); + if (result > 299 || result < 200) { + free_url(resource); + SOCK_FCLOSE(*socketd); + *socketd = 0; + return NULL; + } + /* find out the size of the file (verifying it exists) */ SOCK_WRITE("SIZE ", *socketd); SOCK_WRITE(resource->path, *socketd); @@ -741,15 +767,6 @@ } } - /* set the connection to be binary */ - SOCK_WRITE("TYPE I\n", *socketd); - result = _php3_getftpresult(*socketd); - if (result > 299 || result < 200) { - free_url(resource); - SOCK_FCLOSE(*socketd); - *socketd = 0; - return NULL; - } /* set up the passive connection */ SOCK_WRITE("PASV\n", *socketd); while (SOCK_FGETS(tmp_line, 256, *socketd) && @@ -841,9 +858,9 @@ 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; Index: php4/fopen-wrappers.h diff -u php4/fopen-wrappers.h:1.4 php4/fopen-wrappers.h:1.5 --- php4/fopen-wrappers.h:1.4 Tue Jun 15 17:50:56 1999 +++ php4/fopen-wrappers.h Wed Jun 16 13:06:51 1999 @@ -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: | @@ -26,8 +26,10 @@ | Authors: Jim Winstead <jimw@php.net> | +----------------------------------------------------------------------+ */ -/* $Id: fopen-wrappers.h,v 1.4 1999/06/15 21:50:56 ssb Exp $ */ +/* $Id: fopen-wrappers.h,v 1.5 1999/06/16 17:06:51 ssb Exp $ */ +/* Synced with php3 revision 1.25 1999-06-16 [ssb] */ + #ifndef _FOPEN_WRAPPERS_H #define _FOPEN_WRAPPERS_H @@ -46,17 +48,27 @@ # 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) + +#define FP_FGETS(buf,len,sock,fp,issock) \ + ((issock)?SOCK_FGETS(buf,len,sock):fgets(buf,len,fp)) +#define FP_FREAD(buf,len,sock,fp,issock) \ + ((issock)?SOCK_FREAD(buf,len,sock):fread(buf,1,len,fp)) +#define FP_FEOF(sock,fp,issock) \ + ((issock)?SOCK_FEOF(sock):feof(fp)) +#define FP_FGETC(sock,fp,issock) \ + ((issock)?SOCK_FGETC(sock):fgetc(fp)) /* values for issock */ #define IS_NOT_SOCKET 0 @@ -72,12 +84,12 @@ 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); Index: php4/main.c diff -u php4/main.c:1.73 php4/main.c:1.74 --- php4/main.c:1.73 Fri Jun 11 07:59:35 1999 +++ php4/main.c Wed Jun 16 13:06:51 1999 @@ -29,7 +29,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: main.c,v 1.73 1999/06/11 11:59:35 zeev Exp $ */ +/* $Id: main.c,v 1.74 1999/06/16 17:06:51 ssb Exp $ */ #include <stdio.h> @@ -465,7 +465,7 @@ -#if HAVE_SETITIMER +#ifdef HAVE_SETITIMER static void php3_timeout(int dummy) { PLS_FETCH(); @@ -483,7 +483,7 @@ { #if WIN32|WINNT #else -# if HAVE_SETITIMER +# ifdef HAVE_SETITIMER struct itimerval t_r; /* timeout requested */ t_r.it_value.tv_sec = seconds; @@ -500,7 +500,7 @@ { #if WIN32|WINNT #else -# if HAVE_SETITIMER +# ifdef HAVE_SETITIMER struct itimerval no_timeout; no_timeout.it_value.tv_sec = no_timeout.it_value.tv_usec = no_timeout.it_interval.tv_sec = no_timeout.it_interval.tv_usec = 0;

« previous php.version4 (#1579) next »