]>
Commit | Line | Data |
---|---|---|
00938eac ER |
1 | --- php-7.0.0beta1/main/php_ini.c~ 2015-07-13 16:04:48.000000000 +0300 |
2 | +++ php-7.0.0beta1/main/php_ini.c 2015-07-13 16:10:07.496198519 +0300 | |
f4ee12ea | 3 | @@ -379,12 +379,19 @@ |
c0240cb1 | 4 | } |
5 | /* }}} */ | |
6 | ||
7 | +static int php_csort(const struct dirent **a, const struct dirent **b) | |
8 | +{ | |
9 | + return strcmp((*a)->d_name,(*b)->d_name); | |
10 | +} | |
11 | + | |
12 | /* {{{ php_init_config | |
13 | */ | |
f4ee12ea | 14 | int php_init_config(void) |
762ec2eb ER |
15 | { |
16 | char *php_ini_file_name = NULL; | |
17 | char *php_ini_search_path = NULL; | |
18 | + // value for php_ini_loaded_file() to be stored into php_ini_opened_path | |
19 | + char *php_ini_loaded_file = NULL; | |
20 | int php_ini_scanned_path_len; | |
21 | char *open_basedir; | |
22 | int free_ini_search_path = 0; | |
23 | @@ -561,8 +568,29 @@ | |
c0240cb1 | 24 | } |
25 | } | |
26 | } | |
27 | + /* Search (global) php.ini file in search path */ | |
28 | + if (!fh.handle.fp) { | |
29 | + fh.handle.fp = php_fopen_with_path("php.ini", "r", php_ini_search_path, &php_ini_opened_path TSRMLS_CC); | |
30 | + if (fh.handle.fp) { | |
31 | + fh.filename = php_ini_opened_path; | |
762ec2eb ER |
32 | + |
33 | + // parse the ini file now | |
c0240cb1 | 34 | + PG(open_basedir) = open_basedir; |
35 | + fh.type = ZEND_HANDLE_FP; | |
36 | + zend_parse_ini_file(&fh, 1, ZEND_INI_SCANNER_NORMAL, (zend_ini_parser_cb_t) php_ini_parser_cb, &configuration_hash TSRMLS_CC); | |
c0240cb1 | 37 | + open_basedir = PG(open_basedir); |
c0240cb1 | 38 | + PG(open_basedir) = NULL; |
39 | + fh.handle.fp = NULL; | |
762ec2eb ER |
40 | |
41 | - /* Otherwise search for php-%sapi-module-name%.ini file in search path */ | |
42 | + // save this for later | |
43 | + php_ini_loaded_file = estrdup(php_ini_opened_path); | |
44 | + | |
c0240cb1 | 45 | + efree(php_ini_opened_path); |
46 | + fh.filename = php_ini_opened_path = NULL; | |
47 | + } | |
48 | + } | |
762ec2eb ER |
49 | + |
50 | + /* Also search for php-%sapi-module-name%.ini file in search path */ | |
c0240cb1 | 51 | if (!fh.handle.fp) { |
762ec2eb ER |
52 | const char *fmt = "php-%s.ini"; |
53 | char *ini_fname; | |
00938eac | 54 | @@ -597,15 +597,12 @@ |
762ec2eb | 55 | if (fh.handle.fp) { |
00938eac | 56 | fh.filename = ZSTR_VAL(opened_path); |
c0240cb1 | 57 | } |
762ec2eb ER |
58 | - } |
59 | ||
c0240cb1 | 60 | - /* If still no ini file found, search for php.ini file in search path */ |
61 | - if (!fh.handle.fp) { | |
f4ee12ea | 62 | - fh.handle.fp = php_fopen_with_path("php.ini", "r", php_ini_search_path, &opened_path); |
c0240cb1 | 63 | - if (fh.handle.fp) { |
00938eac | 64 | - fh.filename = ZSTR_VAL(opened_path); |
f4ee12ea ER |
65 | - } |
66 | - } | |
762ec2eb ER |
67 | + // restore previous value, so php_ini_loaded_file() works as expected |
68 | + if (php_ini_loaded_file) { | |
69 | + php_ini_opened_path = php_ini_loaded_file; | |
f4ee12ea ER |
70 | + } |
71 | + } | |
c0240cb1 | 72 | } |
f4ee12ea ER |
73 | |
74 | if (free_ini_search_path) { | |
762ec2eb ER |
75 | @@ -597,6 +622,10 @@ |
76 | ||
77 | { | |
78 | zval tmp; | |
79 | + // use main php.ini if loaded | |
80 | + if (php_ini_loaded_file) { | |
81 | + fh.filename = php_ini_loaded_file; | |
82 | + } | |
c0240cb1 | 83 | |
762ec2eb ER |
84 | Z_STRLEN(tmp) = strlen(fh.filename); |
85 | Z_STRVAL(tmp) = zend_strndup(fh.filename, Z_STRLEN(tmp)); | |
86 | @@ -630,13 +659,15 @@ | |
c0240cb1 | 87 | zend_llist scanned_ini_list; |
88 | zend_llist_element *element; | |
89 | int l, total_l = 0; | |
90 | + const char *fmt = "%s:" PHP_CONFIG_FILE_PATH "/%s.d"; | |
2e0e7ed6 AM |
91 | char *bufpath, *debpath, *endpath; |
92 | int lenpath; | |
c0240cb1 | 93 | |
c0240cb1 | 94 | zend_llist_init(&scanned_ini_list, sizeof(char *), (llist_dtor_func_t) free_estring, 1); |
2e0e7ed6 | 95 | memset(&fh2, 0, sizeof(fh2)); |
b4025702 | 96 | |
2e0e7ed6 AM |
97 | - bufpath = estrdup(php_ini_scanned_path); |
98 | + bufpath = emalloc(strlen(php_ini_scanned_path) + strlen(fmt) + strlen(sapi_module.name)); | |
99 | + sprintf(bufpath, fmt, php_ini_scanned_path, sapi_module.name); | |
100 | for (debpath = bufpath ; debpath ; debpath=endpath) { | |
101 | endpath = strchr(debpath, DEFAULT_DIR_SEPARATOR); | |
102 | if (endpath) { | |
762ec2eb | 103 | @@ -649,7 +680,7 @@ |
2e0e7ed6 AM |
104 | } |
105 | lenpath = strlen(debpath); | |
c0240cb1 | 106 | |
2e0e7ed6 AM |
107 | - if (lenpath > 0 && (ndir = php_scandir(debpath, &namelist, 0, php_alphasort)) > 0) { |
108 | + if (lenpath > 0 && (ndir = php_scandir(debpath, &namelist, 0, php_csort)) > 0) { | |
c0240cb1 | 109 | |
110 | for (i = 0; i < ndir; i++) { | |
2e0e7ed6 | 111 |