cvs: php4 /main main.c php.h php_realpath.c php_virtual_cwd.c php_virtual_cwd.h
| From: | Andi Gutmans | Date: | Sun, 27 Aug 2000 18:01:17 +0000 |
| Subject: | cvs: php4 /main main.c php.h php_realpath.c php_virtual_cwd.c php_virtual_cwd.h | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-1411@lists.php.net to get a copy of this message | ||
andi Sun Aug 27 11:01:17 2000 EDT
Modified files:
/php4/main main.c php.h php_realpath.c php_virtual_cwd.c
php_virtual_cwd.h
Log:
- Try and fix problem with opening wrong file.
Index: php4/main/main.c
diff -u php4/main/main.c:1.297 php4/main/main.c:1.298
--- php4/main/main.c:1.297 Mon Aug 21 02:50:53 2000
+++ php4/main/main.c Sun Aug 27 11:01:17 2000
@@ -19,7 +19,7 @@
*/
-/* $Id: main.c,v 1.297 2000/08/21 09:50:53 sas Exp $ */
+/* $Id: main.c,v 1.298 2000/08/27 18:01:17 andi Exp $ */
#include <stdio.h>
@@ -1146,16 +1146,8 @@
if (primary_file->type == ZEND_HANDLE_FILENAME
&& primary_file->filename) {
- char *filename;
-
- filename = strrchr(primary_file->filename, PHP_DIR_SEPARATOR);
-
- if (filename) {
- filename++;
- V_GETCWD(old_cwd, sizeof(old_cwd)-1);
- V_CHDIR_FILE(primary_file->filename);
- primary_file->filename = filename;
- }
+ V_GETCWD(old_cwd, sizeof(old_cwd)-1);
+ V_CHDIR_FILE(primary_file->filename);
}
if (PG(auto_prepend_file) && PG(auto_prepend_file)[0]) {
Index: php4/main/php.h
diff -u php4/main/php.h:1.118 php4/main/php.h:1.119
--- php4/main/php.h:1.118 Sun Aug 27 02:38:33 2000
+++ php4/main/php.h Sun Aug 27 11:01:17 2000
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php.h,v 1.118 2000/08/27 09:38:33 sas Exp $ */
+/* $Id: php.h,v 1.119 2000/08/27 18:01:17 andi Exp $ */
#ifndef PHP_H
#define PHP_H
@@ -316,7 +316,7 @@
#define V_OPEN(open_args) virtual_open open_args
#define V_CREAT(path, mode) virtual_creat(path, mode)
#define V_CHDIR(path) virtual_chdir(path)
-#define V_CHDIR_FILE(path) virtual_chdir_file(path)
+#define V_CHDIR_FILE(path) virtual_chdir_file(path, virtual_chdir)
#define V_GETWD(buf)
#define V_REALPATH(path,real_path) virtual_realpath(path,real_path)
#define V_STAT(path, buff) virtual_stat(path, buff)
@@ -344,7 +344,7 @@
#define V_OPEN(open_args) open open_args
#define V_CREAT(path, mode) creat(path, mode)
#define V_CHDIR(path) chdir(path)
-#define V_CHDIR_FILE(path) virtual_real_chdir_file(path)
+#define V_CHDIR_FILE(path) virtual_real_chdir_file(path, chdir)
#define V_GETWD(buf) getwd(buf)
#define V_STAT(path, buff) stat(path, buff)
#define V_LSTAT(path, buff) lstat(path, buff)
Index: php4/main/php_realpath.c
diff -u /dev/null php4/main/php_realpath.c:1.13
--- /dev/null Sun Aug 27 11:01:17 2000
+++ php4/main/php_realpath.c Sun Aug 27 11:01:17 2000
@@ -0,0 +1,283 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP version 4.0 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997, 1998, 1999, 2000 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 2.02 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_02.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. |
+ +----------------------------------------------------------------------+
+ | Author: Sander Steffann (sander@steffann.nl) |
+ +----------------------------------------------------------------------+
+ */
+
+#include "php.h"
+
+#if HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#include <sys/stat.h>
+
+#ifndef MAXSYMLINKS
+#define MAXSYMLINKS 32
+#endif
+
+#ifndef S_ISDIR
+#define S_ISDIR(mode) (((mode)&S_IFMT) == S_IFDIR)
+#endif
+
+char *php_realpath(char *path, char resolved_path[]);
+
+#ifdef PHP_WIN32
+#define IS_SLASH(p) ((p) == '/' || (p) == '\\')
+#else
+#define IS_SLASH(p) ((p) == '/')
+#endif
+
+char *php_realpath(char *path, char resolved_path []) {
+ char path_construction[MAXPATHLEN]; /* We build the result in here */
+ char *writepos; /* Position to write next char */
+
+ char path_copy[MAXPATHLEN]; /* A work-copy of the path */
+ char *workpos; /* working position in *path */
+
+#if !defined(PHP_WIN32)
+ char buf[MAXPATHLEN]; /* Buffer for readlink */
+ int linklength; /* The result from readlink */
+#endif
+ int linkcount = 0; /* Count symlinks to avoid loops */
+
+ struct stat filestat; /* result from stat */
+
+#ifdef PHP_WIN32
+ char *temppos; /* position while counting '.' */
+ int dotcount; /* number of '.' */
+ int t; /* counter */
+#endif
+
+ /* Set the work-position to the beginning of the given path */
+ strcpy(path_copy, path);
+ workpos = path_copy;
+
+#ifdef PHP_WIN32
+ /* Find out where we start - Windows version */
+ if (IS_SLASH(*workpos)) {
+ /* We start at the root of the current drive */
+ /* Get the current directory */
+ if (V_GETCWD(path_construction, MAXPATHLEN-1) == NULL) {
+ /* Unable to get cwd */
+ resolved_path[0] = 0;
+ return NULL;
+ }
+ /* We only need the first three chars (for example "C:\") */
+ path_construction[3] = 0;
+ workpos++;
+ } else if (workpos[1] == ':') {
+ /* A drive-letter is specified, copy it */
+ strncpy(path_construction, path, 2);
+ strcat(path_construction, "\\");
+ workpos++;
+ workpos++;
+ } else {
+ /* Use the current directory */
+ if (V_GETCWD(path_construction, MAXPATHLEN-1) == NULL) {
+ /* Unable to get cwd */
+ resolved_path[0] = 0;
+ return NULL;
+ }
+ strcat(path_construction, "\\");
+ }
+#else
+ /* Find out where we start - Unix version */
+ if (*workpos == '/') {
+ /* We start at the root */
+ strcpy(path_construction, "/");
+ workpos++;
+ } else {
+ /* Use the current directory */
+ if (V_GETCWD(path_construction, MAXPATHLEN-1) == NULL) {
+ /* Unable to get cwd */
+ resolved_path[0] = 0;
+ return NULL;
+ }
+ strcat(path_construction, "/");
+ }
+#endif
+
+ /* Set the next-char-position */
+ writepos = &path_construction[strlen(path_construction)];
+
+ /* Go to the end, then stop */
+ while(*workpos != 0) {
+ /* Strip (back)slashes */
+ while(IS_SLASH(*workpos)) workpos++;
+
+#ifdef PHP_WIN32
+ /* reset dotcount */
+ dotcount = 0;
+
+ /* Look for .. */
+ if ((workpos[0] == '.') && (workpos[1] != 0)) {
+ /* Windows accepts \...\ as \..\..\, \....\ as \..\..\..\, etc */
+ /* At least Win98 does */
+
+ temppos = workpos;
+ while(*temppos++ == '.') {
+ dotcount++;
+ if (!IS_SLASH(*temppos) && (*temppos != 0) && (*temppos != '.')) {
+ /* This is not a /../ component, but a filename that starts with '.' */
+ dotcount = 0;
+ }
+ }
+
+ /* Go back dotcount-1 times */
+ for (t=0 ; t<(dotcount-1) ; t++) {
+ workpos++; /* move to next '.' */
+
+ /* Can we still go back? */
+ if ((writepos-3) <= path_construction) return NULL;
+
+ /* Go back */
+ writepos--; /* move to '\' */
+ writepos--;
+ while(!IS_SLASH(*writepos)) writepos--; /* skip until previous '\\' */
+ }
+ workpos++;
+ }
+
+ /* No special case */
+ if (dotcount == 0) {
+ /* Append */
+ while(!IS_SLASH(*workpos) && (*workpos != 0)) {
+ *writepos++ = *workpos++;
+ }
+ }
+
+ /* Just one '.', go to next element */
+ if (dotcount == 1) {
+ while(!IS_SLASH(*workpos) && (*workpos != 0)) {
+ *workpos++;
+ }
+
+ /* Avoid double \ in the result */
+ writepos--;
+ }
+
+ /* If it was a directory, append a slash */
+ if (IS_SLASH(*workpos)) {
+ *writepos++ = *workpos++;
+ }
+ *writepos = 0;
+#else /* defined(PHP_WIN32) */
+ /* Look for .. */
+ if ((workpos[0] == '.') && (workpos[1] != 0)) {
+ if ((workpos[1] == '.') && ((workpos[2] == '/') || (workpos[2] ==
0))) {
+ /* One directory back */
+ /* Set pointers to right position */
+ workpos++; /* move to second '.' */
+ workpos++; /* move to '/' */
+
+ /* Only apply .. if not in root */
+ if ((writepos-1) > path_construction) {
+ writepos--; /* move to '/' */
+ while(*--writepos != '/') ; /* skip until previous '/' */
+ }
+ } else {
+ if (workpos[1] == '/') {
+ /* Found a /./ skip it */
+ workpos++; /* move to '/' */
+
+ /* Avoid double / in the result */
+ writepos--;
+ } else {
+ /* No special case, the name just started with a . */
+ /* Append */
+ while((*workpos != '/') && (*workpos != 0)) {
+ *writepos++ = *workpos++;
+ }
+ }
+ }
+ } else {
+ /* No special case */
+ /* Append */
+ while((*workpos != '/') && (*workpos != 0)) {
+ *writepos++ = *workpos++;
+ }
+ }
+
+#if HAVE_SYMLINK
+ /* We are going to use path_construction, so close it */
+ *writepos = 0;
+
+ /* Check the current location to see if it is a symlink */
+ if((linklength = readlink(path_construction, buf, MAXPATHLEN)) != -1) {
+ /* Check linkcount */
+ if (linkcount > MAXSYMLINKS) return NULL;
+
+ /* Count this symlink */
+ linkcount++;
+
+ /* Set end of buf */
+ buf[linklength] = 0;
+
+ /* Check for overflow */
+ if ((strlen(workpos) + strlen(buf) + 1) >= MAXPATHLEN) return NULL;
+
+ /* Remove the symlink-component wrom path_construction */
+ writepos--; /* move to '/' */
+ while(*--writepos != '/') ; /* skip until previous '/' */
+ *++writepos = 0; /* end of string after '/' */
+
+ /* If the symlink starts with a '/', empty path_construction */
+ if (*buf == '/') {
+ *path_construction = 0;
+ writepos = path_construction;
+ }
+
+ /* Insert symlink into path_copy */
+ strcat(buf, workpos);
+ strcpy(path_copy, buf);
+ workpos = path_copy;
+ }
+#endif /* HAVE_SYMLINK */
+
+ /* If it was a directory, append a slash */
+ if (*workpos == '/') {
+ *writepos++ = *workpos++;
+ }
+ *writepos = 0;
+#endif /* defined(PHP_WIN32) */
+ }
+
+ /* Check if the resolved path is a directory */
+ if (V_STAT(path_construction, &filestat) != 0) {
+ if (errno != ENOENT) return NULL;
+ } else {
+ if (S_ISDIR(filestat.st_mode)) {
+ /* It's a directory, append a / if needed */
+ if (*(writepos-1) != '/') {
+ /* Check for overflow */
+ if ((strlen(workpos) + 2) >= MAXPATHLEN) {
+ return NULL;
+ }
+ *writepos++ = '/';
+ *writepos = 0;
+ }
+ }
+ }
+
+ strcpy(resolved_path, path_construction);
+ return resolved_path;
+}
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ */
Index: php4/main/php_virtual_cwd.c
diff -u php4/main/php_virtual_cwd.c:1.70 php4/main/php_virtual_cwd.c:1.71
--- php4/main/php_virtual_cwd.c:1.70 Sun Aug 20 12:49:10 2000
+++ php4/main/php_virtual_cwd.c Sun Aug 27 11:01:17 2000
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_virtual_cwd.c,v 1.70 2000/08/20 19:49:10 andi Exp $ */
+/* $Id: php_virtual_cwd.c,v 1.71 2000/08/27 18:01:17 andi Exp $ */
#include <sys/types.h>
#include <sys/stat.h>
@@ -31,6 +31,7 @@
#ifdef ZEND_WIN32
#include "win95nt.h"
+#include <sys/utime.h>
#endif
#include "php_virtual_cwd.h"
@@ -396,7 +397,7 @@
return virtual_file_ex(&CWDG(cwd), path, php_is_dir_ok)?-1:0;
}
-CWD_API int virtual_chdir_file(const char *path)
+CWD_API int virtual_chdir_file(const char *path, int (*p_chdir)(const char *path))
{
int length = strlen(path);
char *temp;
@@ -421,7 +422,7 @@
#if VIRTUAL_CWD_DEBUG
fprintf (stderr, "Changing directory to %s\n", temp);
#endif
- retval = virtual_chdir(temp);
+ retval = p_chdir(temp);
free(temp);
return retval;
}
@@ -732,6 +733,7 @@
#endif
+#if 0
/* taken from Apache 1.3 */
CWD_API void virtual_real_chdir_file(const char *file)
@@ -751,6 +753,8 @@
/* XXX: well, this is a silly function, no method of reporting an
* error... ah well. */
}
+
+#endif
#if 0
Index: php4/main/php_virtual_cwd.h
diff -u php4/main/php_virtual_cwd.h:1.36 php4/main/php_virtual_cwd.h:1.37
--- php4/main/php_virtual_cwd.h:1.36 Sun Aug 20 11:12:16 2000
+++ php4/main/php_virtual_cwd.h Sun Aug 27 11:01:17 2000
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_virtual_cwd.h,v 1.36 2000/08/20 18:12:16 andi Exp $ */
+/* $Id: php_virtual_cwd.h,v 1.37 2000/08/27 18:01:17 andi Exp $ */
#ifndef VIRTUAL_CWD_H
#define VIRTUAL_CWD_H
@@ -76,8 +76,8 @@
CWD_API char *virtual_getcwd_ex(int *length);
CWD_API char *virtual_getcwd(char *buf, size_t size);
CWD_API int virtual_chdir(const char *path);
-CWD_API int virtual_chdir_file(const char *path);
-CWD_API void virtual_real_chdir_file(const char *path);
+CWD_API int virtual_chdir_file(const char *path, int (*p_chdir)(const char *path));
+/* CWD_API void virtual_real_chdir_file(const char *path); */
CWD_API int virtual_filepath(const char *path, char **filepath);
CWD_API char *virtual_realpath(const char *path, char *real_path);
CWD_API FILE *virtual_fopen(const char *path, const char *mode);