cvs: php4 /main fopen-wrappers.c fopen-wrappers.h

From: Date: Tue, 08 Aug 2000 16:36:26 +0000
Subject: cvs: php4 /main fopen-wrappers.c fopen-wrappers.h
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-1104@lists.php.net to get a copy of this message
stas Tue Aug 8 09:36:26 2000 EDT Modified files: /php4/main fopen-wrappers.c fopen-wrappers.h Log: Standartize full path handling - everything now goes via expand_filepath Add errno to open_basedir checking function Index: php4/main/fopen-wrappers.c diff -u php4/main/fopen-wrappers.c:1.74 php4/main/fopen-wrappers.c:1.75 --- php4/main/fopen-wrappers.c:1.74 Sun Aug 6 09:22:07 2000 +++ php4/main/fopen-wrappers.c Tue Aug 8 09:36:25 2000 @@ -16,7 +16,7 @@ | Jim Winstead <jimw@php.net> | +----------------------------------------------------------------------+ */ -/* $Id: fopen-wrappers.c,v 1.74 2000/08/06 16:22:07 andi Exp $ */ +/* $Id: fopen-wrappers.c,v 1.75 2000/08/08 16:36:25 stas Exp $ */ #include "php.h" #include "php_globals.h" @@ -187,7 +187,7 @@ } /* Resolve the real path into resolved_name */ - if ((V_REALPATH(path, resolved_name) != NULL) && (V_REALPATH(local_open_basedir, resolved_basedir) != NULL)) { + if ((expand_filepath(path, resolved_name) != NULL) && (expand_filepath(local_open_basedir, resolved_basedir) != NULL)) { /* Check the path */ #ifdef PHP_WIN32 if (strncasecmp(resolved_basedir, resolved_name, strlen(resolved_basedir)) == 0) { @@ -239,6 +239,7 @@ } php_error(E_WARNING, "open_basedir restriction in effect. File is in wrong directory."); efree(pathbuf); + errno = EPERM; /* we deny permission to open it */ return -1; } @@ -275,7 +276,7 @@ } fp = V_FOPEN(path, mode); if (fp && opened_path) { - *opened_path = expand_filepath(path); + *opened_path = expand_filepath(path,NULL); } return fp; } @@ -405,7 +406,7 @@ if (php_check_open_basedir(filename)) return NULL; fp = V_FOPEN(filename, mode); if (fp && opened_path) { - *opened_path = expand_filepath(filename); + *opened_path = expand_filepath(filename,NULL); } return fp; } @@ -427,7 +428,7 @@ if (php_check_open_basedir(trypath)) return NULL; fp = V_FOPEN(trypath, mode); if (fp && opened_path) { - *opened_path = expand_filepath(trypath); + *opened_path = expand_filepath(trypath,NULL); } return fp; } else { @@ -436,7 +437,7 @@ } fp = V_FOPEN(filename, mode); if (fp && opened_path) { - *opened_path = expand_filepath(filename); + *opened_path = expand_filepath(filename,NULL); } return fp; } @@ -482,7 +483,7 @@ return NULL; } if (opened_path) { - *opened_path = expand_filepath(trypath); + *opened_path = expand_filepath(trypath,NULL); } efree(pathbuf); return fp; @@ -1099,7 +1100,7 @@ #if 1 -PHPAPI char *expand_filepath(char *filepath) +PHPAPI char *expand_filepath(char *filepath, char *real_path) { cwd_state new_state; char cwd[MAXPATHLEN+1]; @@ -1113,8 +1114,19 @@ new_state.cwd = strdup(cwd); new_state.cwd_length = strlen(cwd); - virtual_file_ex(&new_state, filepath, NULL); - return new_state.cwd; + if(virtual_file_ex(&new_state, filepath, NULL)) { + return NULL; + } + + if(real_path) { + int copy_len = new_state.cwd_length>MAXPATHLEN-1?MAXPATHLEN-1:new_state.cwd_length; + memcpy(real_path,new_state.cwd,copy_len); + real_path[copy_len]='\0'; + } else { + real_path = new_state.cwd; + } + + return real_path; } #else Index: php4/main/fopen-wrappers.h diff -u php4/main/fopen-wrappers.h:1.20 php4/main/fopen-wrappers.h:1.21 --- php4/main/fopen-wrappers.h:1.20 Sun Jul 2 17:45:20 2000 +++ php4/main/fopen-wrappers.h Tue Aug 8 09:36:25 2000 @@ -15,7 +15,7 @@ | Authors: Jim Winstead <jimw@php.net> | +----------------------------------------------------------------------+ */ -/* $Id: fopen-wrappers.h,v 1.20 2000/07/03 00:45:20 sas Exp $ */ +/* $Id: fopen-wrappers.h,v 1.21 2000/08/08 16:36:25 stas Exp $ */ #ifndef FOPEN_WRAPPERS_H #define FOPEN_WRAPPERS_H @@ -76,7 +76,7 @@ PHPAPI int php_is_url(char *path); PHPAPI char *php_strip_url_passwd(char *path); -PHPAPI char *expand_filepath(char *filepath); +PHPAPI char *expand_filepath(char *filepath,char *real_path); int php_init_fopen_wrappers(void); int php_shutdown_fopen_wrappers(void);

« previous php.cvs (#1104) next »