summaryrefslogtreecommitdiff
path: root/main/php_ini.c
diff options
context:
space:
mode:
authorIlia Alshanetsky <iliaa@php.net>2003-01-25 21:13:00 +0000
committerIlia Alshanetsky <iliaa@php.net>2003-01-25 21:13:00 +0000
commit8d352d2dd6f86f2f77c7aef9e2662d150c6415b2 (patch)
treed1f66492f0b2582d1c90948b08fbcdeee06847bb /main/php_ini.c
parent564788b6f5aabb3f6bc2851a2d733b879c563d8e (diff)
downloadphp-git-8d352d2dd6f86f2f77c7aef9e2662d150c6415b2.tar.gz
Fixed bug #21625 (When scanning a directory for ini files, do so in
alphabetical order. This gives a user a way to control the order in which the ini files are loaded). Fixed a bug that would make the code try to read files without an extension as ini files.
Diffstat (limited to 'main/php_ini.c')
-rw-r--r--main/php_ini.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/main/php_ini.c b/main/php_ini.c
index e0f6f6c098..0ca2f5841b 100644
--- a/main/php_ini.c
+++ b/main/php_ini.c
@@ -31,6 +31,8 @@
#include "SAPI.h"
#include "php_main.h"
+#include "dirent.h"
+
#ifndef S_ISREG
#define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
#endif
@@ -258,8 +260,6 @@ int php_init_config()
char *open_basedir;
int free_ini_search_path=0;
zend_file_handle fh;
- DIR *dirp = NULL;
- struct dirent *dir_entry;
struct stat sb;
char ini_file[MAXPATHLEN];
char *p;
@@ -425,15 +425,17 @@ int php_init_config()
/* 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 (strlen(PHP_CONFIG_FILE_SCAN_DIR)) {
- dirp = VCWD_OPENDIR(PHP_CONFIG_FILE_SCAN_DIR);
- if (dirp) {
- fh.type = ZEND_HANDLE_FP;
- while ((dir_entry = readdir(dirp)) != NULL) {
+ struct dirent **namelist;
+ int ndir, i;
+
+ if ((ndir = scandir(PHP_CONFIG_FILE_SCAN_DIR, &namelist, 0, alphasort)) > 0) {
+ for (i = 0; i < ndir; i++) {
/* check for a .ini extension */
- if ((p = strrchr(dir_entry->d_name,'.')) && strcmp(p,".ini")) {
+ 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, dir_entry->d_name);
+ snprintf(ini_file, MAXPATHLEN, "%s%c%s", PHP_CONFIG_FILE_SCAN_DIR, 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"))) {
@@ -447,8 +449,10 @@ int php_init_config()
}
}
}
+ free(namelist[i]);
}
- closedir(dirp);
+ free(namelist);
+
/*
* Don't need an extra byte for the \0 in this malloc as the last
* element will not get a trailing , which gives us the byte for the \0