cvs: php4 /ext/standard file.c filestat.c /main fopen-wrappers.c php.h php_virtual_cwd.c php_virtual_cwd.h
| From: | Andi Gutmans | Date: | Sun, 06 Aug 2000 16:22:08 +0000 |
| Subject: | cvs: php4 /ext/standard file.c filestat.c /main fopen-wrappers.c php.h php_virtual_cwd.c php_virtual_cwd.h | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-1060@lists.php.net to get a copy of this message | ||
andi Sun Aug 6 09:22:08 2000 EDT
Modified files:
/php4/main php_virtual_cwd.h php.h fopen-wrappers.c
php_virtual_cwd.c
/php4/ext/standard file.c filestat.c
Log:
Virtualize realpath, chmod, chown and utime
This should fix #5935 and #5904
@- Virtualize realpath, chmod, chown and utime (Stas)
Index: php4/main/php_virtual_cwd.h
diff -u php4/main/php_virtual_cwd.h:1.28 php4/main/php_virtual_cwd.h:1.29
--- php4/main/php_virtual_cwd.h:1.28 Sun Jul 23 22:41:00 2000
+++ php4/main/php_virtual_cwd.h Sun Aug 6 09:22:07 2000
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_virtual_cwd.h,v 1.28 2000/07/24 05:41:00 david Exp $ */
+/* $Id: php_virtual_cwd.h,v 1.29 2000/08/06 16:22:07 andi Exp $ */
#ifndef VIRTUAL_CWD_H
#define VIRTUAL_CWD_H
@@ -69,6 +69,7 @@
CWD_API int virtual_chdir(char *path);
CWD_API int virtual_chdir_file(char *path);
CWD_API int virtual_filepath(char *path, char **filepath);
+CWD_API char *virtual_realpath(char *path, char *real_path);
CWD_API FILE *virtual_fopen(const char *path, const char *mode);
CWD_API int virtual_open(const char *path, int flags, ...);
CWD_API int virtual_creat(const char *path, mode_t mode);
@@ -81,6 +82,13 @@
CWD_API int virtual_rmdir(const char *pathname);
CWD_API DIR *virtual_opendir(const char *pathname);
CWD_API FILE *virtual_popen(const char *command, const char *type);
+#if HAVE_UTIME
+CWD_API int virtual_utime(const char *filename, struct utimbuf *buf);
+#endif
+CWD_API int virtual_chmod(const char *filename, mode_t mode);
+#ifndef PHP_WIN32
+CWD_API int virtual_chown(const char *filename, uid_t owner, gid_t group);
+#endif
CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func verify_path);
Index: php4/main/php.h
diff -u php4/main/php.h:1.108 php4/main/php.h:1.109
--- php4/main/php.h:1.108 Sat Aug 5 21:55:17 2000
+++ php4/main/php.h Sun Aug 6 09:22:07 2000
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php.h,v 1.108 2000/08/06 04:55:17 rasmus Exp $ */
+/* $Id: php.h,v 1.109 2000/08/06 16:22:07 andi Exp $ */
#ifndef PHP_H
#define PHP_H
@@ -303,6 +303,7 @@
#define V_CHDIR(path) virtual_chdir(path)
#define V_CHDIR_FILE(path) virtual_chdir_file(path)
#define V_GETWD(buf)
+#define V_REALPATH(path,realpath) virtual_realpath(path,realpath)
#define V_STAT(path, buff) virtual_stat(path, buff)
#ifdef PHP_WIN32
#define V_LSTAT(path, buff) virtual_stat(path, buff)
@@ -314,7 +315,13 @@
#define V_RMDIR(pathname) virtual_rmdir(pathname)
#define V_OPENDIR(pathname) virtual_opendir(pathname)
#define V_POPEN(command, type) virtual_popen(command, type)
-
+#if HAVE_UTIME
+#define V_UTIME(path,time) virtual_utime(path,time)
+#endif
+#define V_CHMOD(path,mode) virtual_chmod(path,mode)
+#ifndef PHP_WIN32
+#define V_CHOWN(path,owner,group) virtual_chown(path,owner,group)
+#endif
#else
#define V_GETCWD(buff, size) getcwd(buff,size)
@@ -331,7 +338,14 @@
#define V_RMDIR(pathname) rmdir(pathname)
#define V_OPENDIR(pathname) opendir(pathname)
#define V_POPEN(command, type) popen(command, type)
-
+#define V_REALPATH(path,realpath) realpath(path,realpath)
+#if HAVE_UTIME
+#define V_UTIME(path,time) utime(path,time)
+#endif
+#define V_CHMOD(path,mode) chmod(path,mode)
+#ifndef PHP_WIN32
+#define V_CHOWN(path,owner,group) chown(path,owner,group)
+#endif
#endif
#include "zend_constants.h"
Index: php4/main/fopen-wrappers.c
diff -u php4/main/fopen-wrappers.c:1.73 php4/main/fopen-wrappers.c:1.74
--- php4/main/fopen-wrappers.c:1.73 Thu Aug 3 08:09:27 2000
+++ php4/main/fopen-wrappers.c Sun Aug 6 09:22:07 2000
@@ -16,7 +16,7 @@
| Jim Winstead <jimw@php.net> |
+----------------------------------------------------------------------+
*/
-/* $Id: fopen-wrappers.c,v 1.73 2000/08/03 15:09:27 stas Exp $ */
+/* $Id: fopen-wrappers.c,v 1.74 2000/08/06 16:22:07 andi Exp $ */
#include "php.h"
#include "php_globals.h"
@@ -187,7 +187,7 @@
}
/* Resolve the real path into resolved_name */
- if ((php_realpath(path, resolved_name) != NULL) && (php_realpath(local_open_basedir,
resolved_basedir) != NULL)) {
+ if ((V_REALPATH(path, resolved_name) != NULL) && (V_REALPATH(local_open_basedir,
resolved_basedir) != NULL)) {
/* Check the path */
#ifdef PHP_WIN32
if (strncasecmp(resolved_basedir, resolved_name, strlen(resolved_basedir)) == 0) {
Index: php4/main/php_virtual_cwd.c
diff -u php4/main/php_virtual_cwd.c:1.63 php4/main/php_virtual_cwd.c:1.64
--- php4/main/php_virtual_cwd.c:1.63 Sat Jul 29 03:48:57 2000
+++ php4/main/php_virtual_cwd.c Sun Aug 6 09:22:07 2000
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_virtual_cwd.c,v 1.63 2000/07/29 10:48:57 zeev Exp $ */
+/* $Id: php_virtual_cwd.c,v 1.64 2000/08/06 16:22:07 andi Exp $ */
#include <sys/types.h>
#include <sys/stat.h>
@@ -33,6 +33,15 @@
#include "win95nt.h"
#endif
+#if HAVE_UTIME
+# ifdef PHP_WIN32
+# include <sys/utime.h>
+# else
+# include <utime.h>
+# endif
+#endif
+
+
#include "php_virtual_cwd.h"
#include "php_reentrancy.h" /* for php_strtok_r */
@@ -390,6 +399,7 @@
ret = 1;
} else {
CWD_STATE_FREE(old_state);
+ ret = (verify_path)? 0:1;
}
free(old_state);
@@ -438,6 +448,24 @@
return retval;
}
+CWD_API char *virtual_realpath(char *path, char *real_path)
+{
+ cwd_state new_state;
+ int retval;
+ CWDLS_FETCH();
+
+ CWD_STATE_COPY(&new_state, &CWDG(cwd));
+ retval = virtual_file_ex(&new_state, path, NULL);
+
+ if(retval) {
+ int len = min(MAXPATHLEN-1,new_state.cwd_length);
+ memcpy(real_path, new_state.cwd, len);
+ real_path[len] = '\0';
+ return real_path;
+ }
+
+ return NULL;
+}
CWD_API int virtual_filepath(char *path, char **filepath)
{
@@ -471,6 +499,55 @@
CWD_STATE_FREE(&new_state);
return f;
}
+
+#if HAVE_UTIME
+CWD_API int virtual_utime(const char *filename, struct utimbuf *buf)
+{
+ cwd_state new_state;
+ int ret;
+ CWDLS_FETCH();
+
+ CWD_STATE_COPY(&new_state, &CWDG(cwd));
+ virtual_file_ex(&new_state, filename, NULL);
+
+ ret = utime(new_state.cwd, buf);
+
+ CWD_STATE_FREE(&new_state);
+ return ret;
+}
+#endif
+
+CWD_API int virtual_chmod(const char *filename, mode_t mode)
+{
+ cwd_state new_state;
+ int ret;
+ CWDLS_FETCH();
+
+ CWD_STATE_COPY(&new_state, &CWDG(cwd));
+ virtual_file_ex(&new_state, filename, NULL);
+
+ ret = chmod(new_state.cwd, mode);
+
+ CWD_STATE_FREE(&new_state);
+ return ret;
+}
+
+#ifndef PHP_WIN32
+CWD_API int virtual_chown(const char *filename, uid_t owner, gid_t group)
+{
+ cwd_state new_state;
+ int ret;
+ CWDLS_FETCH();
+
+ CWD_STATE_COPY(&new_state, &CWDG(cwd));
+ virtual_file_ex(&new_state, filename, NULL);
+
+ ret = chown(new_state.cwd, owner, group);
+
+ CWD_STATE_FREE(&new_state);
+ return ret;
+}
+#endif
CWD_API int virtual_open(const char *path, int flags, ...)
{
Index: php4/ext/standard/file.c
diff -u php4/ext/standard/file.c:1.102 php4/ext/standard/file.c:1.103
--- php4/ext/standard/file.c:1.102 Thu Aug 3 09:37:35 2000
+++ php4/ext/standard/file.c Sun Aug 6 09:22:07 2000
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: file.c,v 1.102 2000/08/03 16:37:35 stas Exp $ */
+/* $Id: file.c,v 1.103 2000/08/06 16:22:07 andi Exp $ */
/* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
@@ -1979,15 +1979,16 @@
PHP_FUNCTION(realpath)
{
zval **path;
- char resolved_path[MAXPATHLEN];
+ char resolved_path_buff[MAXPATHLEN];
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(ZEND_NUM_ARGS(), &path) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_string_ex(path);
- if (php_realpath((*path)->value.str.val, resolved_path)) {
- RETURN_STRING(resolved_path, 1);
+
+ if (V_REALPATH((*path)->value.str.val, resolved_path_buff)) {
+ RETURN_STRING(resolved_path_buff, 1);
} else {
RETURN_FALSE;
}
Index: php4/ext/standard/filestat.c
diff -u php4/ext/standard/filestat.c:1.43 php4/ext/standard/filestat.c:1.44
--- php4/ext/standard/filestat.c:1.43 Thu Jul 27 06:47:03 2000
+++ php4/ext/standard/filestat.c Sun Aug 6 09:22:07 2000
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: filestat.c,v 1.43 2000/07/27 13:47:03 stas Exp $ */
+/* $Id: filestat.c,v 1.44 2000/08/06 16:22:07 andi Exp $ */
#include "php.h"
#include "safe_mode.h"
@@ -260,7 +260,7 @@
if (php_check_open_basedir((*filename)->value.str.val))
RETURN_FALSE;
- ret = chown((*filename)->value.str.val, -1, gid);
+ ret = V_CHOWN((*filename)->value.str.val, -1, gid);
if (ret == -1) {
php_error(E_WARNING, "chgrp failed: %s", strerror(errno));
RETURN_FALSE;
@@ -308,7 +308,7 @@
if (php_check_open_basedir((*filename)->value.str.val))
RETURN_FALSE;
- ret = chown((*filename)->value.str.val, uid, -1);
+ ret = V_CHOWN((*filename)->value.str.val, uid, -1);
if (ret == -1) {
php_error(E_WARNING, "chown failed: %s", strerror(errno));
RETURN_FALSE;
@@ -349,7 +349,7 @@
if(PG(safe_mode))
imode &= 0777;
- ret = chmod((*filename)->value.str.val, imode);
+ ret = V_CHMOD((*filename)->value.str.val, imode);
if (ret == -1) {
php_error(E_WARNING, "chmod failed: %s", strerror(errno));
RETURN_FALSE;
@@ -419,7 +419,7 @@
fclose(file);
}
- ret = utime((*filename)->value.str.val, newtime);
+ ret = V_UTIME((*filename)->value.str.val, newtime);
if (newtime) efree(newtime);
if (ret == -1) {
php_error(E_WARNING, "utime failed: %s", strerror(errno));