1999-04-10 05:04:12 +08:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
2004-01-08 16:18:22 +08:00
|
|
|
| PHP Version 5 |
|
1999-04-10 05:04:12 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2004-01-08 16:18:22 +08:00
|
|
|
| Copyright (c) 1997-2004 The PHP Group |
|
1999-04-10 05:04:12 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2003-06-11 04:04:29 +08:00
|
|
|
| This source file is subject to version 3.0 of the PHP license, |
|
2001-05-06 23:20:56 +08:00
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
2003-06-11 04:04:29 +08:00
|
|
|
| available through the world-wide-web at the following url: |
|
|
|
|
| http://www.php.net/license/3_0.txt. |
|
1999-07-16 21:13:16 +08:00
|
|
|
| If you did not receive a copy of the PHP license and are unable to |
|
2001-05-06 23:20:56 +08:00
|
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
|
|
| license@php.net so we can mail you a copy immediately. |
|
1999-04-10 05:04:12 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2001-05-06 23:20:56 +08:00
|
|
|
| Author: Zeev Suraski <zeev@zend.com> |
|
1999-04-10 05:04:12 +08:00
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
|
2002-03-05 08:21:28 +08:00
|
|
|
/* $Id$ */
|
1999-04-10 05:04:12 +08:00
|
|
|
|
2002-05-11 11:41:17 +08:00
|
|
|
/* Check CWD for php.ini */
|
|
|
|
#define INI_CHECK_CWD
|
|
|
|
|
1999-04-08 05:05:13 +08:00
|
|
|
#include "php.h"
|
1999-05-09 16:48:05 +08:00
|
|
|
#include "ext/standard/info.h"
|
2000-10-29 19:38:26 +08:00
|
|
|
#include "zend_ini.h"
|
2000-10-31 07:39:14 +08:00
|
|
|
#include "php_ini.h"
|
|
|
|
#include "ext/standard/dl.h"
|
|
|
|
#include "zend_extensions.h"
|
2001-05-06 23:20:56 +08:00
|
|
|
#include "zend_highlight.h"
|
2002-02-28 20:12:39 +08:00
|
|
|
#include "SAPI.h"
|
2002-03-05 08:21:28 +08:00
|
|
|
#include "php_main.h"
|
2003-02-19 17:25:16 +08:00
|
|
|
#include "php_scandir.h"
|
2003-10-19 18:39:27 +08:00
|
|
|
#ifdef PHP_WIN32
|
|
|
|
#include "win32/php_registry.h"
|
|
|
|
#endif
|
2000-10-31 07:39:14 +08:00
|
|
|
|
2003-02-19 17:25:16 +08:00
|
|
|
#if HAVE_SCANDIR && HAVE_ALPHASORT && HAVE_DIRENT_H
|
|
|
|
#include <dirent.h>
|
2003-01-26 09:39:18 +08:00
|
|
|
#endif
|
2003-01-26 05:13:00 +08:00
|
|
|
|
2002-10-04 12:47:35 +08:00
|
|
|
#ifndef S_ISREG
|
|
|
|
#define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
|
|
|
|
#endif
|
|
|
|
|
2001-01-15 18:52:02 +08:00
|
|
|
typedef struct _php_extension_lists {
|
2002-05-10 04:03:36 +08:00
|
|
|
zend_llist engine;
|
|
|
|
zend_llist functions;
|
2001-01-15 18:52:02 +08:00
|
|
|
} php_extension_lists;
|
1999-08-14 05:03:27 +08:00
|
|
|
|
2001-03-18 07:35:32 +08:00
|
|
|
|
|
|
|
/* True globals */
|
|
|
|
static HashTable configuration_hash;
|
|
|
|
PHPAPI char *php_ini_opened_path=NULL;
|
|
|
|
static php_extension_lists extension_lists;
|
2002-10-04 12:47:35 +08:00
|
|
|
PHPAPI char *php_ini_scanned_files=NULL;
|
2001-03-18 07:35:32 +08:00
|
|
|
|
2001-06-06 21:06:12 +08:00
|
|
|
/* {{{ php_ini_displayer_cb
|
|
|
|
*/
|
2000-10-29 19:38:26 +08:00
|
|
|
static void php_ini_displayer_cb(zend_ini_entry *ini_entry, int type)
|
1999-05-09 16:48:05 +08:00
|
|
|
{
|
2002-05-10 04:03:36 +08:00
|
|
|
if (ini_entry->displayer) {
|
|
|
|
ini_entry->displayer(ini_entry, type);
|
|
|
|
} else {
|
|
|
|
char *display_string;
|
|
|
|
uint display_string_length, esc_html=0;
|
|
|
|
TSRMLS_FETCH();
|
|
|
|
|
2003-02-19 17:38:11 +08:00
|
|
|
if (type == ZEND_INI_DISPLAY_ORIG && ini_entry->modified) {
|
2002-05-10 04:03:36 +08:00
|
|
|
if (ini_entry->orig_value && ini_entry->orig_value[0]) {
|
|
|
|
display_string = ini_entry->orig_value;
|
|
|
|
display_string_length = ini_entry->orig_value_length;
|
2003-03-30 05:25:03 +08:00
|
|
|
esc_html = !sapi_module.phpinfo_as_text;
|
2002-05-10 04:03:36 +08:00
|
|
|
} else {
|
2003-03-30 05:25:03 +08:00
|
|
|
if (!sapi_module.phpinfo_as_text) {
|
2002-08-29 18:24:02 +08:00
|
|
|
display_string = "<i>no value</i>";
|
2003-02-19 17:38:11 +08:00
|
|
|
display_string_length = sizeof("<i>no value</i>") - 1;
|
2002-08-29 18:24:02 +08:00
|
|
|
} else {
|
|
|
|
display_string = "no value";
|
2003-02-19 17:38:11 +08:00
|
|
|
display_string_length = sizeof("no value") - 1;
|
2002-08-29 18:24:02 +08:00
|
|
|
}
|
2002-05-10 04:03:36 +08:00
|
|
|
}
|
|
|
|
} else if (ini_entry->value && ini_entry->value[0]) {
|
|
|
|
display_string = ini_entry->value;
|
|
|
|
display_string_length = ini_entry->value_length;
|
2003-03-30 05:25:03 +08:00
|
|
|
esc_html = !sapi_module.phpinfo_as_text;
|
2002-05-10 04:03:36 +08:00
|
|
|
} else {
|
2003-03-30 05:25:03 +08:00
|
|
|
if (!sapi_module.phpinfo_as_text) {
|
2002-08-29 18:24:02 +08:00
|
|
|
display_string = "<i>no value</i>";
|
2003-02-19 17:38:11 +08:00
|
|
|
display_string_length = sizeof("<i>no value</i>") - 1;
|
2002-08-29 18:24:02 +08:00
|
|
|
} else {
|
|
|
|
display_string = "no value";
|
2003-02-19 17:38:11 +08:00
|
|
|
display_string_length = sizeof("no value") - 1;
|
2002-08-29 18:24:02 +08:00
|
|
|
}
|
2002-05-10 04:03:36 +08:00
|
|
|
}
|
2003-02-19 17:38:11 +08:00
|
|
|
|
|
|
|
if (esc_html) {
|
2002-05-12 22:48:22 +08:00
|
|
|
php_html_puts(display_string, display_string_length TSRMLS_CC);
|
2002-05-10 04:03:36 +08:00
|
|
|
} else {
|
|
|
|
PHPWRITE(display_string, display_string_length);
|
|
|
|
}
|
|
|
|
}
|
1999-05-09 16:48:05 +08:00
|
|
|
}
|
2001-06-06 21:06:12 +08:00
|
|
|
/* }}} */
|
1999-05-09 16:48:05 +08:00
|
|
|
|
2001-06-06 21:06:12 +08:00
|
|
|
/* {{{ php_ini_displayer
|
|
|
|
*/
|
2001-07-31 12:53:54 +08:00
|
|
|
static int php_ini_displayer(zend_ini_entry *ini_entry, int module_number TSRMLS_DC)
|
1999-05-09 16:48:05 +08:00
|
|
|
{
|
2002-05-10 04:03:36 +08:00
|
|
|
if (ini_entry->module_number != module_number) {
|
|
|
|
return 0;
|
|
|
|
}
|
2003-03-30 05:25:03 +08:00
|
|
|
if (!sapi_module.phpinfo_as_text) {
|
2002-09-20 05:57:25 +08:00
|
|
|
PUTS("<tr>");
|
2002-09-27 01:54:54 +08:00
|
|
|
PUTS("<td class=\"e\">");
|
2003-02-19 17:38:11 +08:00
|
|
|
PHPWRITE(ini_entry->name, ini_entry->name_length - 1);
|
2002-09-27 01:54:54 +08:00
|
|
|
PUTS("</td><td class=\"v\">");
|
2002-08-29 06:31:51 +08:00
|
|
|
php_ini_displayer_cb(ini_entry, ZEND_INI_DISPLAY_ACTIVE);
|
2002-09-27 01:54:54 +08:00
|
|
|
PUTS("</td><td class=\"v\">");
|
2002-08-29 06:31:51 +08:00
|
|
|
php_ini_displayer_cb(ini_entry, ZEND_INI_DISPLAY_ORIG);
|
|
|
|
PUTS("</td></tr>\n");
|
|
|
|
} else {
|
2003-02-19 17:38:11 +08:00
|
|
|
PHPWRITE(ini_entry->name, ini_entry->name_length - 1);
|
2002-08-29 06:31:51 +08:00
|
|
|
PUTS(" => ");
|
|
|
|
php_ini_displayer_cb(ini_entry, ZEND_INI_DISPLAY_ACTIVE);
|
|
|
|
PUTS(" => ");
|
|
|
|
php_ini_displayer_cb(ini_entry, ZEND_INI_DISPLAY_ORIG);
|
|
|
|
PUTS("\n");
|
|
|
|
}
|
2002-05-10 04:03:36 +08:00
|
|
|
return 0;
|
1999-05-09 16:48:05 +08:00
|
|
|
}
|
2001-06-06 21:06:12 +08:00
|
|
|
/* }}} */
|
1999-05-09 16:48:05 +08:00
|
|
|
|
2001-06-06 21:06:12 +08:00
|
|
|
/* {{{ display_ini_entries
|
|
|
|
*/
|
1999-05-09 16:48:05 +08:00
|
|
|
PHPAPI void display_ini_entries(zend_module_entry *module)
|
|
|
|
{
|
2002-05-10 04:03:36 +08:00
|
|
|
int module_number;
|
|
|
|
TSRMLS_FETCH();
|
|
|
|
|
|
|
|
if (module) {
|
|
|
|
module_number = module->module_number;
|
2002-05-11 11:41:17 +08:00
|
|
|
} else {
|
2002-05-10 04:03:36 +08:00
|
|
|
module_number = 0;
|
|
|
|
}
|
|
|
|
php_info_print_table_start();
|
|
|
|
php_info_print_table_header(3, "Directive", "Local Value", "Master Value");
|
2002-09-23 20:10:07 +08:00
|
|
|
zend_hash_apply_with_argument(EG(ini_directives), (apply_func_arg_t) php_ini_displayer, (void *) (long) module_number TSRMLS_CC);
|
2002-05-10 04:03:36 +08:00
|
|
|
php_info_print_table_end();
|
1999-05-09 16:48:05 +08:00
|
|
|
}
|
2001-06-06 21:06:12 +08:00
|
|
|
/* }}} */
|
2000-10-31 07:39:14 +08:00
|
|
|
|
|
|
|
/* php.ini support */
|
|
|
|
|
|
|
|
#ifdef ZTS
|
|
|
|
# if (ZEND_DEBUG)
|
2002-05-11 11:41:17 +08:00
|
|
|
# define ZEND_EXTENSION_TOKEN "zend_extension_debug_ts"
|
2000-10-31 07:39:14 +08:00
|
|
|
# else
|
2002-05-11 11:41:17 +08:00
|
|
|
# define ZEND_EXTENSION_TOKEN "zend_extension_ts"
|
2000-10-31 07:39:14 +08:00
|
|
|
# endif
|
|
|
|
#else
|
|
|
|
# if (ZEND_DEBUG)
|
2002-05-11 11:41:17 +08:00
|
|
|
# define ZEND_EXTENSION_TOKEN "zend_extension_debug"
|
2000-10-31 07:39:14 +08:00
|
|
|
# else
|
2002-05-11 11:41:17 +08:00
|
|
|
# define ZEND_EXTENSION_TOKEN "zend_extension"
|
2000-10-31 07:39:14 +08:00
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2001-06-06 21:06:12 +08:00
|
|
|
/* {{{ pvalue_config_destructor
|
|
|
|
*/
|
2000-10-31 07:39:14 +08:00
|
|
|
static void pvalue_config_destructor(zval *pvalue)
|
2002-05-11 11:41:17 +08:00
|
|
|
{
|
2003-02-19 17:38:11 +08:00
|
|
|
if (Z_TYPE_P(pvalue) == IS_STRING && Z_STRVAL_P(pvalue) != empty_string) {
|
|
|
|
free(Z_STRVAL_P(pvalue));
|
|
|
|
}
|
2000-10-31 07:39:14 +08:00
|
|
|
}
|
2001-06-06 21:06:12 +08:00
|
|
|
/* }}} */
|
2000-10-31 07:39:14 +08:00
|
|
|
|
2001-06-06 21:06:12 +08:00
|
|
|
/* {{{ php_config_ini_parser_cb
|
|
|
|
*/
|
2001-03-18 07:35:32 +08:00
|
|
|
static void php_config_ini_parser_cb(zval *arg1, zval *arg2, int callback_type, void *arg)
|
2000-10-31 07:39:14 +08:00
|
|
|
{
|
2002-05-10 04:03:36 +08:00
|
|
|
switch (callback_type) {
|
|
|
|
case ZEND_INI_PARSER_ENTRY: {
|
|
|
|
zval *entry;
|
|
|
|
|
|
|
|
if (!arg2) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!strcasecmp(Z_STRVAL_P(arg1), "extension")) { /* load function module */
|
|
|
|
zval copy;
|
2002-05-11 11:41:17 +08:00
|
|
|
|
2002-05-10 04:03:36 +08:00
|
|
|
copy = *arg2;
|
|
|
|
zval_copy_ctor(©);
|
|
|
|
copy.refcount = 0;
|
2002-05-11 11:41:17 +08:00
|
|
|
zend_llist_add_element(&extension_lists.functions, ©);
|
2002-05-10 04:03:36 +08:00
|
|
|
} else if (!strcasecmp(Z_STRVAL_P(arg1), ZEND_EXTENSION_TOKEN)) { /* load Zend extension */
|
|
|
|
char *extension_name = estrndup(Z_STRVAL_P(arg2), Z_STRLEN_P(arg2));
|
2002-05-11 11:41:17 +08:00
|
|
|
|
2002-05-10 04:03:36 +08:00
|
|
|
zend_llist_add_element(&extension_lists.engine, &extension_name);
|
|
|
|
} else {
|
2003-02-19 17:38:11 +08:00
|
|
|
zend_hash_update(&configuration_hash, Z_STRVAL_P(arg1), Z_STRLEN_P(arg1) + 1, arg2, sizeof(zval), (void **) &entry);
|
2002-05-10 04:03:36 +08:00
|
|
|
Z_STRVAL_P(entry) = zend_strndup(Z_STRVAL_P(entry), Z_STRLEN_P(entry));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2003-01-19 20:18:46 +08:00
|
|
|
|
|
|
|
case ZEND_INI_PARSER_POP_ENTRY: {
|
|
|
|
zval *hash;
|
|
|
|
zval **find_hash;
|
|
|
|
zval *element;
|
|
|
|
|
|
|
|
if (!arg2) {
|
|
|
|
/* bare string - nothing to do */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-02-19 17:38:11 +08:00
|
|
|
if (zend_hash_find(&configuration_hash, Z_STRVAL_P(arg1), Z_STRLEN_P(arg1) + 1, (void **) &find_hash) == FAILURE) {
|
2003-01-19 20:18:46 +08:00
|
|
|
ALLOC_ZVAL(hash);
|
|
|
|
array_init(hash);
|
|
|
|
|
2003-02-19 17:38:11 +08:00
|
|
|
zend_hash_update(&configuration_hash, Z_STRVAL_P(arg1), Z_STRLEN_P(arg1) + 1, &hash, sizeof(zval *), NULL);
|
2003-01-19 20:18:46 +08:00
|
|
|
} else {
|
|
|
|
hash = *find_hash;
|
|
|
|
}
|
|
|
|
|
|
|
|
ALLOC_ZVAL(element);
|
|
|
|
*element = *arg2;
|
|
|
|
zval_copy_ctor(element);
|
|
|
|
INIT_PZVAL(element);
|
|
|
|
add_next_index_zval(hash, element);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2002-05-10 04:03:36 +08:00
|
|
|
case ZEND_INI_PARSER_SECTION:
|
|
|
|
break;
|
|
|
|
}
|
2000-10-31 07:39:14 +08:00
|
|
|
}
|
2001-06-06 21:06:12 +08:00
|
|
|
/* }}} */
|
2000-10-31 07:39:14 +08:00
|
|
|
|
2001-06-06 21:06:12 +08:00
|
|
|
/* {{{ php_load_function_extension_cb
|
|
|
|
*/
|
2001-07-31 12:53:54 +08:00
|
|
|
static void php_load_function_extension_cb(void *arg TSRMLS_DC)
|
2001-01-15 11:21:05 +08:00
|
|
|
{
|
2002-05-10 04:03:36 +08:00
|
|
|
zval *extension = (zval *) arg;
|
|
|
|
zval zval;
|
2001-01-15 11:21:05 +08:00
|
|
|
|
2002-05-10 04:03:36 +08:00
|
|
|
php_dl(extension, MODULE_PERSISTENT, &zval TSRMLS_CC);
|
2001-01-15 18:52:02 +08:00
|
|
|
}
|
2001-06-06 21:06:12 +08:00
|
|
|
/* }}} */
|
2001-01-15 18:52:02 +08:00
|
|
|
|
2001-06-06 21:06:12 +08:00
|
|
|
/* {{{ php_load_zend_extension_cb
|
|
|
|
*/
|
2001-07-31 12:53:54 +08:00
|
|
|
static void php_load_zend_extension_cb(void *arg TSRMLS_DC)
|
2001-01-15 18:52:02 +08:00
|
|
|
{
|
2002-05-10 04:03:36 +08:00
|
|
|
zend_load_extension(*((char **) arg));
|
2001-01-15 11:21:05 +08:00
|
|
|
}
|
2001-06-06 21:06:12 +08:00
|
|
|
/* }}} */
|
2001-01-15 11:21:05 +08:00
|
|
|
|
2001-06-06 21:06:12 +08:00
|
|
|
/* {{{ php_init_config
|
|
|
|
*/
|
2002-05-11 11:41:17 +08:00
|
|
|
int php_init_config()
|
2000-10-31 07:39:14 +08:00
|
|
|
{
|
2002-05-11 11:41:17 +08:00
|
|
|
char *env_location, *php_ini_search_path;
|
|
|
|
char *binary_location;
|
2002-05-10 04:03:36 +08:00
|
|
|
int safe_mode_state;
|
|
|
|
char *open_basedir;
|
2002-05-11 11:41:17 +08:00
|
|
|
int free_ini_search_path=0;
|
2002-05-10 04:03:36 +08:00
|
|
|
zend_file_handle fh;
|
2002-10-04 12:47:35 +08:00
|
|
|
struct stat sb;
|
|
|
|
char ini_file[MAXPATHLEN];
|
|
|
|
char *p;
|
|
|
|
zend_llist scanned_ini_list;
|
|
|
|
int l, total_l=0;
|
|
|
|
zend_llist_element *element;
|
2002-05-10 04:03:36 +08:00
|
|
|
TSRMLS_FETCH();
|
|
|
|
|
2003-02-19 17:38:11 +08:00
|
|
|
if (zend_hash_init(&configuration_hash, 0, NULL, (dtor_func_t) pvalue_config_destructor, 1) == FAILURE) {
|
2002-05-10 04:03:36 +08:00
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
|
2003-03-18 23:53:33 +08:00
|
|
|
if (sapi_module.ini_defaults) {
|
|
|
|
sapi_module.ini_defaults(&configuration_hash);
|
|
|
|
}
|
|
|
|
|
2002-05-10 04:03:36 +08:00
|
|
|
zend_llist_init(&extension_lists.engine, sizeof(char *), (llist_dtor_func_t) free_estring, 1);
|
|
|
|
zend_llist_init(&extension_lists.functions, sizeof(zval), (llist_dtor_func_t) ZVAL_DESTRUCTOR, 1);
|
2002-10-04 12:47:35 +08:00
|
|
|
zend_llist_init(&scanned_ini_list, sizeof(char *), (llist_dtor_func_t) free_estring, 1);
|
2002-05-11 11:41:17 +08:00
|
|
|
|
2002-05-10 04:03:36 +08:00
|
|
|
safe_mode_state = PG(safe_mode);
|
|
|
|
open_basedir = PG(open_basedir);
|
|
|
|
|
2002-05-11 11:41:17 +08:00
|
|
|
env_location = getenv("PHPRC");
|
|
|
|
if (!env_location) {
|
2003-02-19 17:38:11 +08:00
|
|
|
env_location = "";
|
2002-05-10 04:34:53 +08:00
|
|
|
}
|
2002-05-11 11:41:17 +08:00
|
|
|
if (sapi_module.php_ini_path_override) {
|
|
|
|
php_ini_search_path = sapi_module.php_ini_path_override;
|
|
|
|
free_ini_search_path = 0;
|
|
|
|
} else {
|
|
|
|
char *default_location;
|
2002-08-12 13:37:03 +08:00
|
|
|
static const char paths_separator[] = { ZEND_PATHS_SEPARATOR, 0 };
|
2003-10-20 10:21:25 +08:00
|
|
|
#ifdef PHP_WIN32
|
2003-10-19 18:39:27 +08:00
|
|
|
char *reg_location;
|
2003-10-20 10:21:25 +08:00
|
|
|
#endif
|
2002-05-10 04:34:53 +08:00
|
|
|
|
2003-10-19 18:39:27 +08:00
|
|
|
php_ini_search_path = (char *) emalloc(MAXPATHLEN * 4 + strlen(env_location) + 3 + 1);
|
2002-05-11 11:41:17 +08:00
|
|
|
free_ini_search_path = 1;
|
|
|
|
php_ini_search_path[0] = 0;
|
2002-05-10 04:34:53 +08:00
|
|
|
|
2003-10-19 18:39:27 +08:00
|
|
|
#ifdef PHP_WIN32
|
|
|
|
/* Add registry location */
|
|
|
|
reg_location = GetIniPathFromRegistry();
|
|
|
|
if(reg_location != NULL) {
|
|
|
|
if (*php_ini_search_path) {
|
|
|
|
strcat(php_ini_search_path, paths_separator);
|
|
|
|
}
|
|
|
|
strcat(php_ini_search_path, reg_location);
|
|
|
|
efree(reg_location);
|
|
|
|
}
|
|
|
|
#endif
|
2002-05-11 11:41:17 +08:00
|
|
|
/*
|
|
|
|
* Prepare search path
|
|
|
|
*/
|
2002-05-10 04:03:36 +08:00
|
|
|
|
2003-03-23 02:54:35 +08:00
|
|
|
/* Add environment location */
|
|
|
|
if (env_location[0]) {
|
|
|
|
if (*php_ini_search_path) {
|
|
|
|
strcat(php_ini_search_path, paths_separator);
|
|
|
|
}
|
|
|
|
strcat(php_ini_search_path, env_location);
|
|
|
|
}
|
|
|
|
|
2002-05-11 11:41:17 +08:00
|
|
|
/* Add cwd */
|
2002-05-10 04:34:53 +08:00
|
|
|
#ifdef INI_CHECK_CWD
|
2003-02-19 17:38:11 +08:00
|
|
|
if (strcmp(sapi_module.name, "cli") != 0) {
|
2002-08-12 13:37:03 +08:00
|
|
|
if (*php_ini_search_path) {
|
|
|
|
strcat(php_ini_search_path, paths_separator);
|
|
|
|
}
|
2002-05-11 11:41:17 +08:00
|
|
|
strcat(php_ini_search_path, ".");
|
|
|
|
}
|
2002-05-10 04:34:53 +08:00
|
|
|
#endif
|
2002-05-10 04:03:36 +08:00
|
|
|
|
2002-05-11 11:41:17 +08:00
|
|
|
/* Add binary directory */
|
2002-05-10 04:34:53 +08:00
|
|
|
#ifdef PHP_WIN32
|
2002-05-11 21:49:44 +08:00
|
|
|
binary_location = (char *) emalloc(MAXPATHLEN);
|
2003-02-19 17:38:11 +08:00
|
|
|
if (GetModuleFileName(0, binary_location, MAXPATHLEN) == 0) {
|
2002-05-11 11:41:17 +08:00
|
|
|
efree(binary_location);
|
|
|
|
binary_location = NULL;
|
2002-05-10 04:03:36 +08:00
|
|
|
}
|
2002-05-11 11:41:17 +08:00
|
|
|
#else
|
|
|
|
if (sapi_module.executable_location) {
|
|
|
|
binary_location = estrdup(sapi_module.executable_location);
|
|
|
|
} else {
|
|
|
|
binary_location = NULL;
|
2002-05-10 04:34:53 +08:00
|
|
|
}
|
2002-05-11 11:41:17 +08:00
|
|
|
#endif
|
|
|
|
if (binary_location) {
|
|
|
|
char *separator_location = strrchr(binary_location, DEFAULT_SLASH);
|
|
|
|
|
|
|
|
if (separator_location) {
|
|
|
|
*(separator_location+1) = 0;
|
|
|
|
}
|
2002-08-12 13:37:03 +08:00
|
|
|
if (*php_ini_search_path) {
|
|
|
|
strcat(php_ini_search_path, paths_separator);
|
|
|
|
}
|
2002-05-11 11:41:17 +08:00
|
|
|
strcat(php_ini_search_path, binary_location);
|
|
|
|
efree(binary_location);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add default location */
|
|
|
|
#ifdef PHP_WIN32
|
2003-02-19 17:38:11 +08:00
|
|
|
default_location = (char *) emalloc(MAXPATHLEN + 1);
|
2002-05-11 11:41:17 +08:00
|
|
|
|
2002-08-12 13:37:03 +08:00
|
|
|
if (0 < GetWindowsDirectory(default_location, MAXPATHLEN)) {
|
|
|
|
if (*php_ini_search_path) {
|
|
|
|
strcat(php_ini_search_path, paths_separator);
|
|
|
|
}
|
|
|
|
strcat(php_ini_search_path, default_location);
|
2002-05-11 11:41:17 +08:00
|
|
|
}
|
|
|
|
efree(default_location);
|
2003-12-07 00:04:34 +08:00
|
|
|
|
|
|
|
{
|
|
|
|
/* For people running under terminal services, GetWindowsDirectory will
|
|
|
|
* return their personal Windows directory, so lets add the system
|
|
|
|
* windows directory too */
|
|
|
|
typedef UINT (WINAPI *get_system_windows_directory_func)(char *buffer, UINT size);
|
|
|
|
static get_system_windows_directory_func get_system_windows_directory = NULL;
|
|
|
|
HMODULE kern;
|
|
|
|
|
|
|
|
if (get_system_windows_directory == NULL) {
|
|
|
|
kern = LoadLibrary("kernel32.dll");
|
|
|
|
if (kern) {
|
|
|
|
get_system_windows_directory = (get_system_windows_directory_func)GetProcAddress(kern, "GetSystemWindowsDirectoryA");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (get_system_windows_directory != NULL) {
|
|
|
|
default_location = (char *) emalloc(MAXPATHLEN + 1);
|
|
|
|
if (0 < get_system_windows_directory(default_location, MAXPATHLEN)) {
|
|
|
|
if (*php_ini_search_path) {
|
|
|
|
strcat(php_ini_search_path, paths_separator);
|
|
|
|
}
|
|
|
|
strcat(php_ini_search_path, default_location);
|
|
|
|
}
|
|
|
|
efree(default_location);
|
|
|
|
}
|
|
|
|
}
|
2002-05-10 04:34:53 +08:00
|
|
|
#else
|
2002-05-11 11:41:17 +08:00
|
|
|
default_location = PHP_CONFIG_FILE_PATH;
|
2002-08-12 13:37:03 +08:00
|
|
|
if (*php_ini_search_path) {
|
|
|
|
strcat(php_ini_search_path, paths_separator);
|
|
|
|
}
|
2002-05-11 11:41:17 +08:00
|
|
|
strcat(php_ini_search_path, default_location);
|
2002-05-10 04:34:53 +08:00
|
|
|
#endif
|
2002-05-11 11:41:17 +08:00
|
|
|
}
|
2002-05-10 04:34:53 +08:00
|
|
|
|
2002-05-11 11:41:17 +08:00
|
|
|
PG(safe_mode) = 0;
|
|
|
|
PG(open_basedir) = NULL;
|
|
|
|
|
2003-02-18 17:37:54 +08:00
|
|
|
memset(&fh, 0, sizeof(fh));
|
2002-05-11 11:41:17 +08:00
|
|
|
/* Check if php_ini_path_override is a file */
|
2002-11-13 04:56:47 +08:00
|
|
|
if (!sapi_module.php_ini_ignore) {
|
|
|
|
if (sapi_module.php_ini_path_override && sapi_module.php_ini_path_override[0]) {
|
|
|
|
struct stat statbuf;
|
|
|
|
|
|
|
|
if (!VCWD_STAT(sapi_module.php_ini_path_override, &statbuf)) {
|
|
|
|
if (!((statbuf.st_mode & S_IFMT) == S_IFDIR)) {
|
|
|
|
fh.handle.fp = VCWD_FOPEN(sapi_module.php_ini_path_override, "r");
|
|
|
|
fh.filename = sapi_module.php_ini_path_override;
|
|
|
|
}
|
2002-05-11 11:41:17 +08:00
|
|
|
}
|
|
|
|
}
|
2002-11-13 04:56:47 +08:00
|
|
|
/* Search php-%sapi-module-name%.ini file in search path */
|
|
|
|
if (!fh.handle.fp) {
|
|
|
|
const char *fmt = "php-%s.ini";
|
2003-02-19 17:38:11 +08:00
|
|
|
char *ini_fname = emalloc(strlen(fmt) + strlen(sapi_module.name));
|
2002-11-13 04:56:47 +08:00
|
|
|
sprintf(ini_fname, fmt, sapi_module.name);
|
|
|
|
fh.handle.fp = php_fopen_with_path(ini_fname, "r", php_ini_search_path, &php_ini_opened_path TSRMLS_CC);
|
|
|
|
efree(ini_fname);
|
|
|
|
if (fh.handle.fp) {
|
|
|
|
fh.filename = php_ini_opened_path;
|
|
|
|
}
|
2002-08-12 13:37:03 +08:00
|
|
|
}
|
2002-11-13 04:56:47 +08:00
|
|
|
/* 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 (fh.handle.fp) {
|
|
|
|
fh.filename = php_ini_opened_path;
|
|
|
|
}
|
2002-07-29 20:17:34 +08:00
|
|
|
}
|
2002-05-19 22:45:31 +08:00
|
|
|
}
|
2003-02-19 17:38:11 +08:00
|
|
|
|
2002-05-11 11:41:17 +08:00
|
|
|
if (free_ini_search_path) {
|
|
|
|
efree(php_ini_search_path);
|
|
|
|
}
|
2003-02-19 17:38:11 +08:00
|
|
|
|
2002-05-10 04:03:36 +08:00
|
|
|
PG(safe_mode) = safe_mode_state;
|
|
|
|
PG(open_basedir) = open_basedir;
|
|
|
|
|
2002-10-04 12:47:35 +08:00
|
|
|
if (fh.handle.fp) {
|
|
|
|
fh.type = ZEND_HANDLE_FP;
|
2002-05-10 04:03:36 +08:00
|
|
|
|
2002-10-04 12:47:35 +08:00
|
|
|
zend_parse_ini_file(&fh, 1, php_config_ini_parser_cb, &extension_lists);
|
2002-05-11 11:41:17 +08:00
|
|
|
|
2002-10-04 12:47:35 +08:00
|
|
|
{
|
|
|
|
zval tmp;
|
2002-05-11 11:41:17 +08:00
|
|
|
|
2002-10-04 12:47:35 +08:00
|
|
|
Z_STRLEN(tmp) = strlen(fh.filename);
|
|
|
|
Z_STRVAL(tmp) = zend_strndup(fh.filename, Z_STRLEN(tmp));
|
|
|
|
Z_TYPE(tmp) = IS_STRING;
|
|
|
|
zend_hash_update(&configuration_hash, "cfg_file_path", sizeof("cfg_file_path"), (void *) &tmp, sizeof(zval), NULL);
|
2003-02-19 17:38:11 +08:00
|
|
|
if (php_ini_opened_path) {
|
2002-10-04 12:47:35 +08:00
|
|
|
efree(php_ini_opened_path);
|
2003-02-19 17:38:11 +08:00
|
|
|
}
|
2002-10-04 12:47:35 +08:00
|
|
|
php_ini_opened_path = zend_strndup(Z_STRVAL(tmp), Z_STRLEN(tmp));
|
|
|
|
}
|
2002-11-13 04:56:47 +08:00
|
|
|
}
|
2002-10-04 12:47:35 +08:00
|
|
|
|
|
|
|
/* 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. */
|
2003-02-03 20:25:28 +08:00
|
|
|
if (!sapi_module.php_ini_ignore && strlen(PHP_CONFIG_FILE_SCAN_DIR)) {
|
2003-01-26 05:13:00 +08:00
|
|
|
struct dirent **namelist;
|
|
|
|
int ndir, i;
|
|
|
|
|
2003-02-19 17:25:16 +08:00
|
|
|
if ((ndir = php_scandir(PHP_CONFIG_FILE_SCAN_DIR, &namelist, 0, php_alphasort)) > 0) {
|
2003-01-26 05:13:00 +08:00
|
|
|
for (i = 0; i < ndir; i++) {
|
2002-10-04 12:47:35 +08:00
|
|
|
/* check for a .ini extension */
|
2003-01-26 05:13:00 +08:00
|
|
|
if (!(p = strrchr(namelist[i]->d_name, '.')) || (p && strcmp(p, ".ini"))) {
|
|
|
|
free(namelist[i]);
|
2002-12-30 23:03:50 +08:00
|
|
|
continue;
|
|
|
|
}
|
2003-01-26 05:13:00 +08:00
|
|
|
snprintf(ini_file, MAXPATHLEN, "%s%c%s", PHP_CONFIG_FILE_SCAN_DIR, DEFAULT_SLASH, namelist[i]->d_name);
|
2002-10-04 12:47:35 +08:00
|
|
|
if (VCWD_STAT(ini_file, &sb) == 0) {
|
|
|
|
if (S_ISREG(sb.st_mode)) {
|
|
|
|
if ((fh.handle.fp = VCWD_FOPEN(ini_file, "r"))) {
|
|
|
|
fh.filename = ini_file;
|
2003-03-01 04:48:38 +08:00
|
|
|
fh.type = ZEND_HANDLE_FP;
|
2002-10-04 12:47:35 +08:00
|
|
|
zend_parse_ini_file(&fh, 1, php_config_ini_parser_cb, &extension_lists);
|
|
|
|
/* Here, add it to the list of ini files read */
|
|
|
|
l = strlen(ini_file);
|
2003-02-19 17:38:11 +08:00
|
|
|
total_l += l + 2;
|
|
|
|
p = estrndup(ini_file, l);
|
2002-10-04 12:47:35 +08:00
|
|
|
zend_llist_add_element(&scanned_ini_list, &p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-01-26 05:13:00 +08:00
|
|
|
free(namelist[i]);
|
2002-10-04 12:47:35 +08:00
|
|
|
}
|
2003-01-26 05:13:00 +08:00
|
|
|
free(namelist);
|
|
|
|
|
2002-10-04 12:47:35 +08:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*/
|
2003-02-19 17:38:11 +08:00
|
|
|
php_ini_scanned_files = (char *) malloc(total_l);
|
2002-10-04 12:47:35 +08:00
|
|
|
*php_ini_scanned_files = '\0';
|
2003-02-19 17:38:11 +08:00
|
|
|
for (element = scanned_ini_list.head; element; element = element->next) {
|
|
|
|
strcat(php_ini_scanned_files, *(char **)element->data);
|
|
|
|
strcat(php_ini_scanned_files, element->next ? ",\n" : "\n");
|
2002-10-04 12:47:35 +08:00
|
|
|
}
|
|
|
|
zend_llist_destroy(&scanned_ini_list);
|
|
|
|
}
|
2002-05-10 04:03:36 +08:00
|
|
|
}
|
|
|
|
return SUCCESS;
|
2000-10-31 07:39:14 +08:00
|
|
|
}
|
2001-06-06 21:06:12 +08:00
|
|
|
/* }}} */
|
2000-10-31 07:39:14 +08:00
|
|
|
|
2001-06-06 21:06:12 +08:00
|
|
|
/* {{{ php_shutdown_config
|
|
|
|
*/
|
2000-10-31 07:39:14 +08:00
|
|
|
int php_shutdown_config(void)
|
|
|
|
{
|
2002-05-10 04:03:36 +08:00
|
|
|
zend_hash_destroy(&configuration_hash);
|
|
|
|
if (php_ini_opened_path) {
|
|
|
|
free(php_ini_opened_path);
|
|
|
|
}
|
2002-10-04 12:47:35 +08:00
|
|
|
if (php_ini_scanned_files) {
|
|
|
|
free(php_ini_scanned_files);
|
|
|
|
}
|
2002-05-10 04:03:36 +08:00
|
|
|
return SUCCESS;
|
2000-10-31 07:39:14 +08:00
|
|
|
}
|
2001-06-06 21:06:12 +08:00
|
|
|
/* }}} */
|
2000-10-31 07:39:14 +08:00
|
|
|
|
2001-06-06 21:06:12 +08:00
|
|
|
/* {{{ php_ini_delayed_modules_startup
|
|
|
|
*/
|
2001-07-31 12:53:54 +08:00
|
|
|
void php_ini_delayed_modules_startup(TSRMLS_D)
|
2001-03-18 07:35:32 +08:00
|
|
|
{
|
2002-05-10 04:03:36 +08:00
|
|
|
zend_llist_apply(&extension_lists.engine, php_load_zend_extension_cb TSRMLS_CC);
|
|
|
|
zend_llist_apply(&extension_lists.functions, php_load_function_extension_cb TSRMLS_CC);
|
2001-03-18 07:35:32 +08:00
|
|
|
|
2002-05-10 04:03:36 +08:00
|
|
|
zend_llist_destroy(&extension_lists.engine);
|
|
|
|
zend_llist_destroy(&extension_lists.functions);
|
2001-03-18 07:35:32 +08:00
|
|
|
}
|
2001-06-06 21:06:12 +08:00
|
|
|
/* }}} */
|
2001-03-18 07:35:32 +08:00
|
|
|
|
2001-06-06 21:06:12 +08:00
|
|
|
/* {{{ cfg_get_entry
|
|
|
|
*/
|
2000-10-31 07:39:14 +08:00
|
|
|
zval *cfg_get_entry(char *name, uint name_length)
|
|
|
|
{
|
2002-05-10 04:03:36 +08:00
|
|
|
zval *tmp;
|
2000-10-31 07:39:14 +08:00
|
|
|
|
2003-02-19 17:38:11 +08:00
|
|
|
if (zend_hash_find(&configuration_hash, name, name_length, (void **) &tmp) == SUCCESS) {
|
2002-05-10 04:03:36 +08:00
|
|
|
return tmp;
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
2000-10-31 07:39:14 +08:00
|
|
|
}
|
2001-06-06 21:06:12 +08:00
|
|
|
/* }}} */
|
2000-10-31 07:39:14 +08:00
|
|
|
|
2001-06-06 21:06:12 +08:00
|
|
|
/* {{{ cfg_get_long
|
|
|
|
*/
|
2001-08-05 09:43:02 +08:00
|
|
|
PHPAPI int cfg_get_long(char *varname, long *result)
|
2000-10-31 07:39:14 +08:00
|
|
|
{
|
2002-05-10 04:03:36 +08:00
|
|
|
zval *tmp, var;
|
2002-05-11 11:41:17 +08:00
|
|
|
|
2003-02-19 17:38:11 +08:00
|
|
|
if (zend_hash_find(&configuration_hash, varname, strlen(varname) + 1, (void **) &tmp) == FAILURE) {
|
|
|
|
*result = (long) NULL;
|
2002-05-10 04:03:36 +08:00
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
var = *tmp;
|
|
|
|
zval_copy_ctor(&var);
|
|
|
|
convert_to_long(&var);
|
|
|
|
*result = Z_LVAL(var);
|
|
|
|
return SUCCESS;
|
2000-10-31 07:39:14 +08:00
|
|
|
}
|
2001-06-06 21:06:12 +08:00
|
|
|
/* }}} */
|
2000-10-31 07:39:14 +08:00
|
|
|
|
2001-06-06 21:06:12 +08:00
|
|
|
/* {{{ cfg_get_double
|
|
|
|
*/
|
2001-08-05 09:43:02 +08:00
|
|
|
PHPAPI int cfg_get_double(char *varname, double *result)
|
2000-10-31 07:39:14 +08:00
|
|
|
{
|
2002-05-10 04:03:36 +08:00
|
|
|
zval *tmp, var;
|
2002-05-11 11:41:17 +08:00
|
|
|
|
2003-02-19 17:38:11 +08:00
|
|
|
if (zend_hash_find(&configuration_hash, varname, strlen(varname) + 1, (void **) &tmp) == FAILURE) {
|
|
|
|
*result = (double) 0;
|
2002-05-10 04:03:36 +08:00
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
var = *tmp;
|
|
|
|
zval_copy_ctor(&var);
|
|
|
|
convert_to_double(&var);
|
|
|
|
*result = Z_DVAL(var);
|
|
|
|
return SUCCESS;
|
2000-10-31 07:39:14 +08:00
|
|
|
}
|
2001-06-06 21:06:12 +08:00
|
|
|
/* }}} */
|
2000-10-31 07:39:14 +08:00
|
|
|
|
2001-06-06 21:06:12 +08:00
|
|
|
/* {{{ cfg_get_string
|
|
|
|
*/
|
2000-10-31 07:39:14 +08:00
|
|
|
PHPAPI int cfg_get_string(char *varname, char **result)
|
|
|
|
{
|
2002-05-10 04:03:36 +08:00
|
|
|
zval *tmp;
|
|
|
|
|
2003-02-19 17:38:11 +08:00
|
|
|
if (zend_hash_find(&configuration_hash, varname, strlen(varname)+1, (void **) &tmp) == FAILURE) {
|
|
|
|
*result = NULL;
|
2002-05-10 04:03:36 +08:00
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
*result = Z_STRVAL_P(tmp);
|
|
|
|
return SUCCESS;
|
2000-10-31 07:39:14 +08:00
|
|
|
}
|
2001-06-06 21:06:12 +08:00
|
|
|
/* }}} */
|
2001-04-22 09:09:14 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* tab-width: 4
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* indent-tabs-mode: t
|
|
|
|
* End:
|
2001-09-09 21:29:31 +08:00
|
|
|
* vim600: sw=4 ts=4 fdm=marker
|
|
|
|
* vim<600: sw=4 ts=4
|
2001-04-22 09:09:14 +08:00
|
|
|
*/
|