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();
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);
}
}
char *pathbuf, *ptr, *end;
char trypath[MAXPATHLEN + 1];
struct stat sb;
- FILE *fp;
PLS_FETCH();
if (opened_path) {
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
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)) {
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);
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;
}
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);
}
#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];