summaryrefslogtreecommitdiff
path: root/main/php_ini.c
diff options
context:
space:
mode:
authorSean Finney <seanius@debian.org>2009-04-10 14:09:48 +0200
committerSean Finney <seanius@debian.org>2009-04-10 14:09:48 +0200
commitcd0b49c72aee33b3e44a9c589fcd93b9e1c7a64f (patch)
tree1315c623bb7d9dfa8d366fa9cd2c6834ceeb5da5 /main/php_ini.c
parent9ea47aab740772adf0c69d8c94b208a464e599ea (diff)
downloadphp-cd0b49c72aee33b3e44a9c589fcd93b9e1c7a64f.tar.gz
Imported Upstream version 5.2.9.dfsg.1upstream/5.2.9.dfsg.1
Diffstat (limited to 'main/php_ini.c')
-rw-r--r--main/php_ini.c49
1 files changed, 38 insertions, 11 deletions
diff --git a/main/php_ini.c b/main/php_ini.c
index e70e03b65..cfa850353 100644
--- a/main/php_ini.c
+++ b/main/php_ini.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2008 The PHP Group |
+ | Copyright (c) 1997-2009 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_ini.c,v 1.136.2.4.2.16 2007/12/31 07:20:15 sebastian Exp $ */
+/* $Id: php_ini.c,v 1.136.2.4.2.19 2008/12/31 11:17:47 sebastian Exp $ */
#include "php.h"
#include "ext/standard/info.h"
@@ -50,6 +50,7 @@ typedef struct _php_extension_lists {
static HashTable configuration_hash;
PHPAPI char *php_ini_opened_path=NULL;
static php_extension_lists extension_lists;
+PHPAPI char *php_ini_scanned_path=NULL;
PHPAPI char *php_ini_scanned_files=NULL;
/* {{{ php_ini_displayer_cb
@@ -260,6 +261,7 @@ int php_init_config(TSRMLS_D)
{
char *php_ini_file_name = NULL;
char *php_ini_search_path = NULL;
+ int php_ini_scanned_path_len;
int safe_mode_state;
char *open_basedir;
int free_ini_search_path = 0;
@@ -448,9 +450,18 @@ int php_init_config(TSRMLS_D)
PG(safe_mode) = 0;
PG(open_basedir) = NULL;
+ /*
+ * Find and open actual ini file
+ */
+
memset(&fh, 0, sizeof(fh));
- /* Check if php_ini_path_override is a file */
- if (!sapi_module.php_ini_ignore) {
+
+ /* If SAPI does not want to ignore all ini files OR an overriding file/path is given.
+ * This allows disabling scanning for ini files in the PHP_CONFIG_FILE_SCAN_DIR but still
+ * load an optional ini file. */
+ if (!sapi_module.php_ini_ignore || sapi_module.php_ini_path_override) {
+
+ /* Check if php_ini_file_name is a file and can be opened */
if (php_ini_file_name && php_ini_file_name[0]) {
struct stat statbuf;
@@ -463,7 +474,8 @@ int php_init_config(TSRMLS_D)
}
}
}
- /* Search php-%sapi-module-name%.ini file in search path */
+
+ /* Otherwise search for php-%sapi-module-name%.ini file in search path */
if (!fh.handle.fp) {
const char *fmt = "php-%s.ini";
char *ini_fname;
@@ -474,7 +486,8 @@ int php_init_config(TSRMLS_D)
fh.filename = php_ini_opened_path;
}
}
- /* Search php.ini file in search path */
+
+ /* If still no ini file found, search for 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 (fh.handle.fp) {
@@ -509,20 +522,31 @@ int php_init_config(TSRMLS_D)
}
}
- /* If the config_file_scan_dir is set at compile-time, go and scan this directory and
- * parse any .ini files found in this directory. */
- if (!sapi_module.php_ini_ignore && strlen(PHP_CONFIG_FILE_SCAN_DIR)) {
+ /* Check for PHP_INI_SCAN_DIR environment variable to override/set config file scan directory */
+ php_ini_scanned_path = getenv("PHP_INI_SCAN_DIR");
+ if (!php_ini_scanned_path) {
+ /* Or fall back using possible --with-config-file-scan-dir setting (defaults to empty string!) */
+ php_ini_scanned_path = PHP_CONFIG_FILE_SCAN_DIR;
+ }
+ php_ini_scanned_path_len = strlen(php_ini_scanned_path);
+
+ /* Scan and parse any .ini files found in scan path if path not empty. */
+ if (!sapi_module.php_ini_ignore && php_ini_scanned_path_len) {
struct dirent **namelist;
int ndir, i;
- if ((ndir = php_scandir(PHP_CONFIG_FILE_SCAN_DIR, &namelist, 0, php_alphasort)) > 0) {
+ if ((ndir = php_scandir(php_ini_scanned_path, &namelist, 0, php_alphasort)) > 0) {
for (i = 0; i < ndir; i++) {
/* check for a .ini extension */
if (!(p = strrchr(namelist[i]->d_name, '.')) || (p && strcmp(p, ".ini"))) {
free(namelist[i]);
continue;
}
- snprintf(ini_file, MAXPATHLEN, "%s%c%s", PHP_CONFIG_FILE_SCAN_DIR, DEFAULT_SLASH, namelist[i]->d_name);
+ if (IS_SLASH(php_ini_scanned_path[php_ini_scanned_path_len - 1])) {
+ snprintf(ini_file, MAXPATHLEN, "%s%s", php_ini_scanned_path, namelist[i]->d_name);
+ } else {
+ snprintf(ini_file, MAXPATHLEN, "%s%c%s", php_ini_scanned_path, DEFAULT_SLASH, namelist[i]->d_name);
+ }
if (VCWD_STAT(ini_file, &sb) == 0) {
if (S_ISREG(sb.st_mode)) {
if ((fh.handle.fp = VCWD_FOPEN(ini_file, "r"))) {
@@ -555,6 +579,9 @@ int php_init_config(TSRMLS_D)
}
zend_llist_destroy(&scanned_ini_list);
}
+ } else {
+ /* Make sure an empty php_ini_scanned_path ends up as NULL */
+ php_ini_scanned_path = NULL;
}
if (sapi_module.ini_entries) {