mirror of
https://github.com/php/php-src.git
synced 2024-09-21 18:07:23 +00:00
Add check for php.ini in same directory as php.exe (or equivalent executable that loaded php4ts.dll). Check is done before looking in the Windows directory. This allows distinct php.ini files when different applications using PHP are installed on the same system. Should be backwards compatible.
Note that checking for in CWD php.ini may be a security risk(?), and can now be made compile-time configurable by removing a single #define. (This time with tabs for leading indent).
This commit is contained in:
parent
42c82bb40d
commit
6de4f3a459
106
main/php_ini.c
106
main/php_ini.c
@ -201,10 +201,8 @@ static void php_load_zend_extension_cb(void *arg TSRMLS_DC)
|
||||
*/
|
||||
int php_init_config(char *php_ini_path_override)
|
||||
{
|
||||
char *env_location, *php_ini_search_path;
|
||||
int safe_mode_state;
|
||||
char *open_basedir;
|
||||
int free_ini_search_path=0;
|
||||
zend_file_handle fh;
|
||||
TSRMLS_FETCH();
|
||||
|
||||
@ -217,68 +215,65 @@ int php_init_config(char *php_ini_path_override)
|
||||
|
||||
safe_mode_state = PG(safe_mode);
|
||||
open_basedir = PG(open_basedir);
|
||||
|
||||
env_location = getenv("PHPRC");
|
||||
if (!env_location) {
|
||||
env_location="";
|
||||
}
|
||||
if (php_ini_path_override) {
|
||||
php_ini_search_path = php_ini_path_override;
|
||||
free_ini_search_path = 0;
|
||||
} else {
|
||||
char *default_location;
|
||||
int free_default_location;
|
||||
|
||||
#ifdef PHP_WIN32
|
||||
default_location = (char *) emalloc(512);
|
||||
|
||||
if (!GetWindowsDirectory(default_location, 255)) {
|
||||
default_location[0]=0;
|
||||
}
|
||||
free_default_location=1;
|
||||
#else
|
||||
default_location = PHP_CONFIG_FILE_PATH;
|
||||
free_default_location=0;
|
||||
#endif
|
||||
php_ini_search_path = (char *) emalloc(sizeof(".")+strlen(env_location)+strlen(default_location)+2+1);
|
||||
free_ini_search_path = 1;
|
||||
if (strcmp(sapi_module.name, "cli")==0) {
|
||||
if(env_location && env_location[0]) {
|
||||
sprintf(php_ini_search_path, "%s%c%s", env_location, ZEND_PATHS_SEPARATOR, default_location);
|
||||
} else {
|
||||
sprintf(php_ini_search_path, "%s", default_location);
|
||||
}
|
||||
} else {
|
||||
if(env_location && env_location[0]) {
|
||||
sprintf(php_ini_search_path, ".%c%s%c%s", ZEND_PATHS_SEPARATOR, env_location, ZEND_PATHS_SEPARATOR, default_location);
|
||||
} else {
|
||||
sprintf(php_ini_search_path, ".%c%s", ZEND_PATHS_SEPARATOR, default_location);
|
||||
}
|
||||
}
|
||||
if (free_default_location) {
|
||||
efree(default_location);
|
||||
}
|
||||
}
|
||||
|
||||
PG(safe_mode) = 0;
|
||||
PG(open_basedir) = NULL;
|
||||
|
||||
fh.handle.fp = NULL;
|
||||
/* Check if php_ini_path_override is a file */
|
||||
if (php_ini_path_override && php_ini_path_override[0]) {
|
||||
struct stat statbuf;
|
||||
if (!VCWD_STAT(php_ini_path_override, &statbuf)) {
|
||||
if (!((statbuf.st_mode & S_IFMT) == S_IFDIR)) {
|
||||
|
||||
/* If no override given (usually from the command line) then check the environment. */
|
||||
if (!php_ini_path_override) {
|
||||
php_ini_path_override = getenv("PHPRC");
|
||||
}
|
||||
if (php_ini_path_override && *php_ini_path_override) {
|
||||
|
||||
/* Try to open php_ini_path_override if not a directory. */
|
||||
struct stat st;
|
||||
if ((0 == VCWD_STAT(php_ini_path_override, &st)) && (S_IFDIR != (st.st_mode & S_IFMT))) {
|
||||
fh.handle.fp = VCWD_FOPEN(php_ini_path_override, "r");
|
||||
if (fh.handle.fp) {
|
||||
php_ini_opened_path = estrdup(php_ini_path_override);
|
||||
}
|
||||
}
|
||||
|
||||
/* If we did not manage to open php_ini_path_override then search it as a directory. */
|
||||
if (!fh.handle.fp) {
|
||||
fh.handle.fp = php_fopen_with_path("php.ini", "r", php_ini_path_override, &php_ini_opened_path TSRMLS_CC);
|
||||
}
|
||||
/* Search php.ini file in search path */
|
||||
if (!fh.handle.fp)
|
||||
fh.handle.fp = php_fopen_with_path("php.ini", "r", php_ini_search_path, &php_ini_opened_path TSRMLS_CC);
|
||||
if (free_ini_search_path) {
|
||||
efree(php_ini_search_path);
|
||||
|
||||
}
|
||||
|
||||
#define INI_CHECK_CWD
|
||||
#ifdef INI_CHECK_CWD
|
||||
if (!fh.handle.fp && (0 != strcmp(sapi_module.name, "cli"))) {
|
||||
/* Search the current directory - possible security risk? */
|
||||
fh.handle.fp = php_fopen_with_path("php.ini", "r", ".", &php_ini_opened_path TSRMLS_CC);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PHP_WIN32
|
||||
if (!fh.handle.fp) {
|
||||
/* Search for php.ini in the same directory as the executable. */
|
||||
char search_path[MAX_PATH];
|
||||
if (GetModuleFileName(0,search_path,sizeof(search_path))) {
|
||||
char* p = strrchr(search_path,'\\');
|
||||
if (p) *++p = 0;
|
||||
fh.handle.fp = php_fopen_with_path("php.ini", "r", search_path, &php_ini_opened_path TSRMLS_CC);
|
||||
}
|
||||
}
|
||||
if (!fh.handle.fp) {
|
||||
/* Search for php.ini in the Windows base directory. */
|
||||
char search_path[MAX_PATH];
|
||||
if (GetWindowsDirectory(search_path,sizeof(search_path))) {
|
||||
fh.handle.fp = php_fopen_with_path("php.ini", "r", search_path, &php_ini_opened_path TSRMLS_CC);
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (!fh.handle.fp) {
|
||||
/* Search for php.ini in the (platform-specific) default places. */
|
||||
fh.handle.fp = php_fopen_with_path("php.ini", "r", PHP_CONFIG_FILE_PATH, &php_ini_opened_path TSRMLS_CC);
|
||||
}
|
||||
#endif
|
||||
|
||||
PG(safe_mode) = safe_mode_state;
|
||||
PG(open_basedir) = open_basedir;
|
||||
|
||||
@ -290,6 +285,7 @@ int php_init_config(char *php_ini_path_override)
|
||||
|
||||
zend_parse_ini_file(&fh, 1, php_config_ini_parser_cb, &extension_lists);
|
||||
|
||||
/* If we succeeded in opening an INI file, preserve the name of the file opened. */
|
||||
if (php_ini_opened_path) {
|
||||
zval tmp;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user