diff options
author | Andi Gutmans <andi@php.net> | 2000-08-16 19:26:21 +0000 |
---|---|---|
committer | Andi Gutmans <andi@php.net> | 2000-08-16 19:26:21 +0000 |
commit | c675a39b73019acd2e6495e081473977069d2bcd (patch) | |
tree | a69f9999926c5cb9528a5bbb74795952e3a6c09f /main | |
parent | ffad41019ebc74b1fbbfad3f87c4b97bb1c7af1b (diff) | |
download | php-git-c675a39b73019acd2e6495e081473977069d2bcd.tar.gz |
- The beginning of an attempt to cleanup fopen-wrappers.
- I started with trying to localize the V_FOPEN's so that we can have a
- version which won't really open the file for include_once/require_once to
- work faster and have less chance of a race which would cause a fd leak.
- What I did will, therefore, change but I want to do this step by step
- because the code is extremley messy so first of all I want to make sure
- that the isolating of the V_FOPEN code doesn't break anything.
- How about moving URL stuff out of this file?
- php_fopen_url_wrapper() copy and pasted the second part of
- php_fopen_wrapper() (incorrectly). Please try not to copy&paste code but
- centralize functionality. Need to think of a nice way to nuke one of the
- copies and have both functions use the same one.
Diffstat (limited to 'main')
-rw-r--r-- | main/fopen_wrappers.c | 63 | ||||
-rw-r--r-- | main/fopen_wrappers.h | 8 |
2 files changed, 25 insertions, 46 deletions
diff --git a/main/fopen_wrappers.c b/main/fopen_wrappers.c index 6a111245a5..5c3ec5e752 100644 --- a/main/fopen_wrappers.c +++ b/main/fopen_wrappers.c @@ -247,6 +247,17 @@ PHPAPI int php_check_open_basedir(char *path) return 0; } +FILE *php_fopen_and_set_opened_path(const char *path, char *mode, char **opened_path) +{ + FILE *fp; + + fp = V_FOPEN(path, mode); + if (fp && opened_path) { + *opened_path = expand_filepath(path,NULL); + } + return fp; +} + PHPAPI FILE *php_fopen_wrapper(char *path, char *mode, int options, int *issock, int *socketd, char **opened_path) { PLS_FETCH(); @@ -266,19 +277,13 @@ PHPAPI FILE *php_fopen_wrapper(char *path, char *mode, int options, int *issock, if (options & USE_PATH && PG(include_path) != NULL) { return php_fopen_with_path(path, mode, PG(include_path), opened_path); } else { - FILE *fp; - if (options & ENFORCE_SAFE_MODE && PG(safe_mode) && (!php_checkuid(path, mode, 0))) { return NULL; } if (php_check_open_basedir(path)) { return NULL; } - fp = V_FOPEN(path, mode); - if (fp && opened_path) { - *opened_path = expand_filepath(path,NULL); - } - return fp; + return php_fopen_and_set_opened_path(path, mode, opened_path); } } @@ -391,7 +396,6 @@ PHPAPI FILE *php_fopen_with_path(char *filename, char *mode, char *path, char ** char *pathbuf, *ptr, *end; char trypath[MAXPATHLEN + 1]; struct stat sb; - FILE *fp; PLS_FETCH(); if (opened_path) { @@ -404,11 +408,8 @@ PHPAPI FILE *php_fopen_with_path(char *filename, char *mode, char *path, char ** return NULL; } if (php_check_open_basedir(filename)) return NULL; - fp = V_FOPEN(filename, mode); - if (fp && opened_path) { - *opened_path = expand_filepath(filename,NULL); - } - return fp; + + return php_fopen_and_set_opened_path(filename, mode, opened_path); } /* Absolute path open - prepend document_root in safe mode */ #ifdef PHP_WIN32 @@ -426,20 +427,12 @@ PHPAPI FILE *php_fopen_with_path(char *filename, char *mode, char *path, char ** return NULL; } if (php_check_open_basedir(trypath)) return NULL; - fp = V_FOPEN(trypath, mode); - if (fp && opened_path) { - *opened_path = expand_filepath(trypath,NULL); - } - return fp; + return php_fopen_and_set_opened_path(filename, mode, opened_path); } else { if (php_check_open_basedir(filename)) { return NULL; } - fp = V_FOPEN(filename, mode); - if (fp && opened_path) { - *opened_path = expand_filepath(filename,NULL); - } - return fp; + return php_fopen_and_set_opened_path(filename, mode, opened_path); } } if (!path || (path && !*path)) { @@ -449,11 +442,7 @@ PHPAPI FILE *php_fopen_with_path(char *filename, char *mode, char *path, char ** if (php_check_open_basedir(filename)) { return NULL; } - fp = V_FOPEN(filename, mode); - if (fp && opened_path) { - *opened_path = strdup(filename); - } - return fp; + return php_fopen_and_set_opened_path(filename, mode, opened_path); } pathbuf = estrdup(path); @@ -476,17 +465,9 @@ PHPAPI FILE *php_fopen_with_path(char *filename, char *mode, char *path, char ** return NULL; } } - if ((fp = V_FOPEN(trypath, mode)) != NULL) { - if (php_check_open_basedir(trypath)) { - fclose(fp); - efree(pathbuf); - return NULL; - } - if (opened_path) { - *opened_path = expand_filepath(trypath,NULL); - } + if (!php_check_open_basedir(trypath)) { efree(pathbuf); - return fp; + return php_fopen_and_set_opened_path(trypath, mode, opened_path); } ptr = end; } @@ -1036,12 +1017,10 @@ static FILE *php_fopen_url_wrapper(const char *path, char *mode, int options, in if (php_check_open_basedir((char *) path)) { fp = NULL; } else { - fp = V_FOPEN(path, mode); + fp = php_fopen_and_set_opened_path(path, mode, opened_path); } } } - - return (fp); } @@ -1100,7 +1079,7 @@ PHPAPI char *php_strip_url_passwd(char *url) #if 1 -PHPAPI char *expand_filepath(char *filepath, char *real_path) +PHPAPI char *expand_filepath(const char *filepath, char *real_path) { cwd_state new_state; char cwd[MAXPATHLEN+1]; diff --git a/main/fopen_wrappers.h b/main/fopen_wrappers.h index 919cf04010..7d119bd35a 100644 --- a/main/fopen_wrappers.h +++ b/main/fopen_wrappers.h @@ -22,9 +22,9 @@ #include "php_globals.h" -#define IGNORE_PATH 0 -#define USE_PATH 1 -#define IGNORE_URL 2 +#define IGNORE_PATH 0 +#define USE_PATH 1 +#define IGNORE_URL 2 /* There's no USE_URL. */ #ifdef PHP_WIN32 # define IGNORE_URL_WIN 2 @@ -76,7 +76,7 @@ PHPAPI FILE *php_fopen_with_path(char *filename, char *mode, char *path, char ** PHPAPI int php_is_url(char *path); PHPAPI char *php_strip_url_passwd(char *path); -PHPAPI char *expand_filepath(char *filepath,char *real_path); +PHPAPI char *expand_filepath(const char *filepath,char *real_path); int php_init_fopen_wrappers(void); int php_shutdown_fopen_wrappers(void); |