--- main/fopen_wrappers.c.orig Thu Oct 24 13:33:50 2002 +++ main/fopen_wrappers.c Fri Nov 1 11:45:25 2002 @@ -30,6 +30,7 @@ #include #include #include +#include #ifdef PHP_WIN32 #include @@ -202,13 +203,24 @@ /* Only check when open_basedir is available */ if (PG(open_basedir) && *PG(open_basedir)) { char *pathbuf; + char *newpath; char *ptr; char *end; + struct stat statbuf; - pathbuf = estrdup(PG(open_basedir)); + end = ptr = newpath = pathbuf = NULL; - ptr = pathbuf; + if (PG(open_basedir) != NULL) + pathbuf = estrdup(PG(open_basedir)); + if (zend_is_executing(TSRMLS_C)) { + if ((newpath = zend_get_executed_filename(TSRMLS_C)) != NULL && + *newpath != '\0') + newpath = estrdup(zend_get_executed_filename(TSRMLS_C)); + } else { + newpath = estrdup(""); + } + ptr = pathbuf; while (ptr && *ptr) { end = strchr(ptr, DEFAULT_DIR_SEPARATOR); if (end != NULL) { @@ -216,15 +228,51 @@ end++; } - if (php_check_specific_open_basedir(ptr, path TSRMLS_CC) == 0) { - efree(pathbuf); + if (path != NULL && php_check_specific_open_basedir(ptr, path TSRMLS_CC) == 0) { + if (pathbuf != NULL) + efree(pathbuf); + efree(newpath); return 0; } + if (( stat (path, &statbuf)) < 0) { + + if (path == NULL) { + syslog(LOG_WARNING, + "open_basedir: Used openbasedir %s, file (NULL) executed_filename (%s)", + pathbuf, newpath); + } else if (pathbuf == NULL) { + syslog(LOG_WARNING, + "open_basedir: Used openbasedir (NULL), file %s executed_filename (%s)", + path, newpath); + } else if (newpath == NULL) { + syslog(LOG_WARNING, + "open_basedir: Used openbasedir %s, file %s executed_filename (NULL)", + pathbuf, path); + } else { + syslog(LOG_WARNING, + "open_basedir: Used openbasedir %s, file %s executed_filename (%s)", + pathbuf, path, newpath); + } + + if (newpath != NULL && php_check_specific_open_basedir(ptr, newpath TSRMLS_CC) == 0) { + if (pathbuf != NULL) + efree(pathbuf); + efree(newpath); + return 0; + } + } + ptr = end; } php_error(E_WARNING, "open_basedir restriction in effect. File is in wrong directory"); - efree(pathbuf); + syslog(LOG_WARNING, "open_basedir restriction in effect. File is in wrong directory %s", path); + + if (pathbuf) + efree(pathbuf); + if (newpath) + efree(newpath); + errno = EPERM; /* we deny permission to open it */ return -1; }