cvs: php4 /main fopen-wrappers.c fopen-wrappers.h
| From: | Andi Gutmans | Date: | Wed, 16 Aug 2000 19:26:21 +0000 |
| Subject: | cvs: php4 /main fopen-wrappers.c fopen-wrappers.h | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-1199@lists.php.net to get a copy of this message | ||
andi Wed Aug 16 12:26:21 2000 EDT
Modified files:
/php4/main fopen-wrappers.c fopen-wrappers.h
Log:
- 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.
Index: php4/main/fopen-wrappers.c
diff -u php4/main/fopen-wrappers.c:1.75 php4/main/fopen-wrappers.c:1.76
--- php4/main/fopen-wrappers.c:1.75 Tue Aug 8 09:36:25 2000
+++ php4/main/fopen-wrappers.c Wed Aug 16 12:26:21 2000
@@ -16,7 +16,7 @@
| Jim Winstead <jimw@php.net> |
+----------------------------------------------------------------------+
*/
-/* $Id: fopen-wrappers.c,v 1.75 2000/08/08 16:36:25 stas Exp $ */
+/* $Id: fopen-wrappers.c,v 1.76 2000/08/16 19:26:21 andi Exp $ */
#include "php.h"
#include "php_globals.h"
@@ -247,6 +247,17 @@
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 @@
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 @@
char *pathbuf, *ptr, *end;
char trypath[MAXPATHLEN + 1];
struct stat sb;
- FILE *fp;
PLS_FETCH();
if (opened_path) {
@@ -404,11 +408,8 @@
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 @@
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)) {
@@ -448,12 +441,8 @@
}
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 @@
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 @@
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 @@
#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];
Index: php4/main/fopen-wrappers.h
diff -u php4/main/fopen-wrappers.h:1.21 php4/main/fopen-wrappers.h:1.22
--- php4/main/fopen-wrappers.h:1.21 Tue Aug 8 09:36:25 2000
+++ php4/main/fopen-wrappers.h Wed Aug 16 12:26:21 2000
@@ -15,16 +15,16 @@
| Authors: Jim Winstead <jimw@php.net> |
+----------------------------------------------------------------------+
*/
-/* $Id: fopen-wrappers.h,v 1.21 2000/08/08 16:36:25 stas Exp $ */
+/* $Id: fopen-wrappers.h,v 1.22 2000/08/16 19:26:21 andi Exp $ */
#ifndef FOPEN_WRAPPERS_H
#define FOPEN_WRAPPERS_H
#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 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);