1999-04-22 08:25:57 +08:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
2001-12-11 23:32:16 +08:00
|
|
|
| PHP Version 4 |
|
1999-04-22 08:25:57 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2003-01-01 00:08:15 +08:00
|
|
|
| Copyright (c) 1997-2003 The PHP Group |
|
1999-04-22 08:25:57 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2000-05-18 23:34:45 +08:00
|
|
|
| This source file is subject to version 2.02 of the PHP license, |
|
1999-07-16 21:13:16 +08:00
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
|
|
|
| available at through the world-wide-web at |
|
2000-05-18 23:34:45 +08:00
|
|
|
| http://www.php.net/license/2_02.txt. |
|
1999-07-16 21:13:16 +08:00
|
|
|
| If you did not receive a copy of the PHP license and are unable to |
|
|
|
|
| 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-22 08:25:57 +08:00
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Authors: Brian Schaffner <brian@tool.net> |
|
|
|
|
| Shane Caraveo <shane@caraveo.com> |
|
|
|
|
| Zeev Suraski <zeev@zend.com> |
|
|
|
|
+----------------------------------------------------------------------+
|
2000-07-24 09:40:02 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* $Id$ */
|
1999-04-22 08:25:57 +08:00
|
|
|
|
|
|
|
#include "php.h"
|
|
|
|
#include "dl.h"
|
|
|
|
#include "php_globals.h"
|
2000-04-06 05:43:03 +08:00
|
|
|
#include "ext/standard/info.h"
|
2000-06-27 02:27:12 +08:00
|
|
|
#include "SAPI.h"
|
2000-11-06 14:31:00 +08:00
|
|
|
|
2002-04-04 08:24:34 +08:00
|
|
|
#if defined(HAVE_LIBDL) || HAVE_MACH_O_DYLD_H
|
1999-04-22 08:25:57 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2000-03-19 00:16:15 +08:00
|
|
|
|
2002-09-05 22:25:07 +08:00
|
|
|
#ifdef HAVE_STRING_H
|
1999-04-22 08:25:57 +08:00
|
|
|
#include <string.h>
|
|
|
|
#else
|
|
|
|
#include <strings.h>
|
|
|
|
#endif
|
2000-02-11 23:59:30 +08:00
|
|
|
#ifdef PHP_WIN32
|
1999-04-22 08:25:57 +08:00
|
|
|
#include "win32/param.h"
|
|
|
|
#include "win32/winutil.h"
|
2000-06-13 04:22:17 +08:00
|
|
|
#define GET_DL_ERROR() php_win_err()
|
2002-09-05 22:25:07 +08:00
|
|
|
#elif defined(NETWARE)
|
|
|
|
#ifdef NEW_LIBC
|
|
|
|
#include <sys/param.h>
|
|
|
|
#else
|
|
|
|
#include "netware/param.h"
|
|
|
|
#endif
|
|
|
|
#define GET_DL_ERROR() dlerror()
|
1999-04-22 08:25:57 +08:00
|
|
|
#else
|
|
|
|
#include <sys/param.h>
|
2002-04-04 08:24:34 +08:00
|
|
|
#define GET_DL_ERROR() DL_ERROR()
|
1999-04-22 08:25:57 +08:00
|
|
|
#endif
|
|
|
|
|
2002-04-04 08:24:34 +08:00
|
|
|
#endif /* defined(HAVE_LIBDL) || HAVE_MACH_O_DYLD_H */
|
1999-04-22 08:25:57 +08:00
|
|
|
|
2000-06-13 04:22:17 +08:00
|
|
|
|
1999-04-22 08:25:57 +08:00
|
|
|
/* {{{ proto int dl(string extension_filename)
|
|
|
|
Load a PHP extension at runtime */
|
2000-03-07 04:37:11 +08:00
|
|
|
PHP_FUNCTION(dl)
|
1999-04-22 08:25:57 +08:00
|
|
|
{
|
1999-10-14 03:55:25 +08:00
|
|
|
pval **file;
|
1999-04-22 08:25:57 +08:00
|
|
|
|
2000-06-27 02:27:12 +08:00
|
|
|
#ifdef ZTS
|
2003-01-29 23:39:10 +08:00
|
|
|
if ((strncmp(sapi_module.name, "cgi", 3)!=0) &&
|
|
|
|
(strcmp(sapi_module.name, "cli")!=0) &&
|
|
|
|
(strncmp(sapi_module.name, "embed", 5)!=0)) {
|
2002-10-13 22:14:34 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Not supported in multithreaded Web servers - use extension statements in your php.ini");
|
|
|
|
RETURN_FALSE;
|
2000-06-27 02:27:12 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-04-22 08:25:57 +08:00
|
|
|
/* obtain arguments */
|
2000-06-06 03:47:54 +08:00
|
|
|
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &file) == FAILURE) {
|
1999-04-22 08:25:57 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
|
1999-10-14 03:55:25 +08:00
|
|
|
convert_to_string_ex(file);
|
1999-04-22 08:25:57 +08:00
|
|
|
|
|
|
|
if (!PG(enable_dl)) {
|
2002-10-13 22:14:34 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Dynamically loaded extentions aren't enabled");
|
1999-04-22 08:25:57 +08:00
|
|
|
} else if (PG(safe_mode)) {
|
2002-10-13 22:14:34 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Dynamically loaded extensions aren't allowed when running in Safe Mode");
|
1999-04-22 08:25:57 +08:00
|
|
|
} else {
|
2001-08-08 04:13:54 +08:00
|
|
|
php_dl(*file, MODULE_TEMPORARY, return_value TSRMLS_CC);
|
2001-10-23 09:18:54 +08:00
|
|
|
EG(full_tables_cleanup) = 1;
|
1999-04-22 08:25:57 +08:00
|
|
|
}
|
|
|
|
}
|
1999-10-14 03:55:25 +08:00
|
|
|
|
1999-04-22 08:25:57 +08:00
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
2002-04-04 08:24:34 +08:00
|
|
|
#if defined(HAVE_LIBDL) || HAVE_MACH_O_DYLD_H
|
1999-04-22 08:25:57 +08:00
|
|
|
|
2000-03-12 00:23:30 +08:00
|
|
|
#ifdef ZTS
|
|
|
|
#define USING_ZTS 1
|
|
|
|
#else
|
|
|
|
#define USING_ZTS 0
|
|
|
|
#endif
|
|
|
|
|
2001-06-06 21:06:12 +08:00
|
|
|
/* {{{ php_dl
|
|
|
|
*/
|
2001-08-08 04:13:54 +08:00
|
|
|
void php_dl(pval *file, int type, pval *return_value TSRMLS_DC)
|
1999-04-22 08:25:57 +08:00
|
|
|
{
|
|
|
|
void *handle;
|
2000-03-07 11:43:03 +08:00
|
|
|
char *libpath;
|
2001-08-12 01:03:37 +08:00
|
|
|
zend_module_entry *module_entry, *tmp;
|
1999-12-18 04:55:31 +08:00
|
|
|
zend_module_entry *(*get_module)(void);
|
2000-06-13 04:22:17 +08:00
|
|
|
int error_type;
|
2000-06-13 05:01:03 +08:00
|
|
|
char *extension_dir;
|
2000-05-02 22:44:08 +08:00
|
|
|
|
2000-06-13 05:01:03 +08:00
|
|
|
if (type==MODULE_PERSISTENT) {
|
2000-11-05 23:03:41 +08:00
|
|
|
/* Use the configuration hash directly, the INI mechanism is not yet initialized */
|
2000-06-13 05:01:03 +08:00
|
|
|
if (cfg_get_string("extension_dir", &extension_dir)==FAILURE) {
|
2000-11-05 23:03:41 +08:00
|
|
|
extension_dir = PHP_EXTENSION_DIR;
|
2000-06-13 05:01:03 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
extension_dir = PG(extension_dir);
|
|
|
|
}
|
|
|
|
|
2000-06-13 04:22:17 +08:00
|
|
|
if (type==MODULE_TEMPORARY) {
|
|
|
|
error_type = E_WARNING;
|
|
|
|
} else {
|
|
|
|
error_type = E_CORE_WARNING;
|
|
|
|
}
|
|
|
|
|
2000-06-13 05:01:03 +08:00
|
|
|
if (extension_dir && extension_dir[0]){
|
|
|
|
int extension_dir_len = strlen(extension_dir);
|
1999-04-22 08:25:57 +08:00
|
|
|
|
2001-09-26 05:58:48 +08:00
|
|
|
libpath = emalloc(extension_dir_len+Z_STRLEN_P(file)+2);
|
2000-03-07 11:43:03 +08:00
|
|
|
|
2000-06-13 05:01:03 +08:00
|
|
|
if (IS_SLASH(extension_dir[extension_dir_len-1])) {
|
2001-09-26 05:58:48 +08:00
|
|
|
sprintf(libpath, "%s%s", extension_dir, Z_STRVAL_P(file)); /* SAFE */
|
2000-06-09 08:43:43 +08:00
|
|
|
} else {
|
2002-11-04 20:53:24 +08:00
|
|
|
sprintf(libpath, "%s%c%s", extension_dir, DEFAULT_SLASH, Z_STRVAL_P(file)); /* SAFE */
|
2000-06-09 08:43:43 +08:00
|
|
|
}
|
1999-04-22 08:25:57 +08:00
|
|
|
} else {
|
2001-09-26 05:58:48 +08:00
|
|
|
libpath = estrndup(Z_STRVAL_P(file), Z_STRLEN_P(file));
|
1999-04-22 08:25:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* load dynamic symbol */
|
2000-02-11 03:41:21 +08:00
|
|
|
handle = DL_LOAD(libpath);
|
1999-04-22 08:25:57 +08:00
|
|
|
if (!handle) {
|
2002-08-24 09:19:28 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, error_type, "Unable to load dynamic library '%s' - %s", libpath, GET_DL_ERROR());
|
2000-03-07 11:43:03 +08:00
|
|
|
efree(libpath);
|
1999-04-22 08:25:57 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
2000-03-07 11:43:03 +08:00
|
|
|
|
|
|
|
efree(libpath);
|
|
|
|
|
2002-09-05 22:25:07 +08:00
|
|
|
#ifndef NETWARE
|
2000-03-30 09:21:03 +08:00
|
|
|
get_module = (zend_module_entry *(*)(void)) DL_FETCH_SYMBOL(handle, "get_module");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* some OS prepend _ to symbol names while their dynamic linker
|
|
|
|
* does not do that automatically. Thus we check manually for
|
|
|
|
* _get_module.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!get_module)
|
|
|
|
get_module = (zend_module_entry *(*)(void)) DL_FETCH_SYMBOL(handle, "_get_module");
|
2002-09-05 22:32:47 +08:00
|
|
|
#else
|
2002-09-05 22:25:07 +08:00
|
|
|
/* NetWare doesn't support two NLMs exporting same symbol */
|
2002-09-05 22:32:47 +08:00
|
|
|
{
|
|
|
|
char symbol_name[64] = "\0";
|
|
|
|
int module_name_length = Z_STRLEN_P(file) - 4; /* '.nlm' is 4 characters; knock it off */
|
2002-09-05 22:25:07 +08:00
|
|
|
|
2002-09-05 22:32:47 +08:00
|
|
|
/* Take the module name (e.g.: 'php_ldap') and append '@get_module' to it */
|
|
|
|
strncpy(symbol_name, Z_STRVAL_P(file), module_name_length);
|
|
|
|
symbol_name[module_name_length] = '\0';
|
|
|
|
strcat(symbol_name, "@");
|
|
|
|
strcat(symbol_name, "get_module");
|
2002-09-05 22:25:07 +08:00
|
|
|
|
2002-09-05 22:32:47 +08:00
|
|
|
get_module = (zend_module_entry *(*)(void)) DL_FETCH_SYMBOL(handle, symbol_name);
|
2002-09-05 22:25:07 +08:00
|
|
|
}
|
2002-09-05 22:32:47 +08:00
|
|
|
/* NetWare doesn't prepend '_' to symbol names; so the corresponding portion of code is also
|
2002-09-05 22:25:07 +08:00
|
|
|
not required for NetWare */
|
|
|
|
#endif
|
2000-03-30 09:21:03 +08:00
|
|
|
|
1999-04-22 08:25:57 +08:00
|
|
|
if (!get_module) {
|
2000-02-11 03:41:21 +08:00
|
|
|
DL_UNLOAD(handle);
|
2002-08-24 09:19:28 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, error_type, "Invalid library (maybe not a PHP library) '%s' ", Z_STRVAL_P(file));
|
1999-04-22 08:25:57 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
module_entry = get_module();
|
2000-03-13 14:00:36 +08:00
|
|
|
if ((module_entry->zend_debug != ZEND_DEBUG) || (module_entry->zts != USING_ZTS)
|
|
|
|
|| (module_entry->zend_api != ZEND_MODULE_API_NO)) {
|
2002-03-23 23:37:27 +08:00
|
|
|
/* Check for pre-4.1.0 module which has a slightly different module_entry structure :( */
|
|
|
|
struct pre_4_1_0_module_entry {
|
|
|
|
char *name;
|
|
|
|
zend_function_entry *functions;
|
|
|
|
int (*module_startup_func)(INIT_FUNC_ARGS);
|
|
|
|
int (*module_shutdown_func)(SHUTDOWN_FUNC_ARGS);
|
|
|
|
int (*request_startup_func)(INIT_FUNC_ARGS);
|
|
|
|
int (*request_shutdown_func)(SHUTDOWN_FUNC_ARGS);
|
|
|
|
void (*info_func)(ZEND_MODULE_INFO_FUNC_ARGS);
|
|
|
|
int (*global_startup_func)(void);
|
|
|
|
int (*global_shutdown_func)(void);
|
|
|
|
int globals_id;
|
|
|
|
int module_started;
|
|
|
|
unsigned char type;
|
|
|
|
void *handle;
|
|
|
|
int module_number;
|
|
|
|
unsigned char zend_debug;
|
|
|
|
unsigned char zts;
|
|
|
|
unsigned int zend_api;
|
|
|
|
};
|
|
|
|
|
|
|
|
char *name;
|
|
|
|
int zend_api;
|
|
|
|
unsigned char zend_debug, zts;
|
|
|
|
|
|
|
|
if(( ((struct pre_4_1_0_module_entry *)module_entry)->zend_api > 20000000)
|
|
|
|
&&(((struct pre_4_1_0_module_entry *)module_entry)->zend_api < 20010901)) {
|
|
|
|
name = ((struct pre_4_1_0_module_entry *)module_entry)->name;
|
|
|
|
zend_api = ((struct pre_4_1_0_module_entry *)module_entry)->zend_api;
|
|
|
|
zend_debug = ((struct pre_4_1_0_module_entry *)module_entry)->zend_debug;
|
|
|
|
zts = ((struct pre_4_1_0_module_entry *)module_entry)->zts;
|
|
|
|
} else {
|
|
|
|
name = module_entry->name;
|
|
|
|
zend_api = module_entry->zend_api;
|
|
|
|
zend_debug = module_entry->zend_debug;
|
|
|
|
zts = module_entry->zts;
|
|
|
|
}
|
|
|
|
|
2002-12-06 04:59:49 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, error_type,
|
2002-03-23 23:37:27 +08:00
|
|
|
"%s: Unable to initialize module\n"
|
|
|
|
"Module compiled with module API=%d, debug=%d, thread-safety=%d\n"
|
|
|
|
"PHP compiled with module API=%d, debug=%d, thread-safety=%d\n"
|
|
|
|
"These options need to match\n",
|
|
|
|
name, zend_api, zend_debug, zts,
|
2002-09-05 22:32:47 +08:00
|
|
|
ZEND_MODULE_API_NO, ZEND_DEBUG, USING_ZTS);
|
2002-03-23 23:37:27 +08:00
|
|
|
DL_UNLOAD(handle);
|
|
|
|
RETURN_FALSE;
|
2000-03-12 00:23:30 +08:00
|
|
|
}
|
2001-09-26 05:58:48 +08:00
|
|
|
Z_TYPE_P(module_entry) = type;
|
1999-04-22 08:25:57 +08:00
|
|
|
module_entry->module_number = zend_next_free_module();
|
|
|
|
if (module_entry->module_startup_func) {
|
2001-07-27 18:16:41 +08:00
|
|
|
if (module_entry->module_startup_func(type, module_entry->module_number TSRMLS_CC)==FAILURE) {
|
2002-08-24 09:19:28 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, error_type, "Unable to initialize module '%s'", module_entry->name);
|
2000-02-11 03:41:21 +08:00
|
|
|
DL_UNLOAD(handle);
|
1999-04-22 08:25:57 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
zend_register_module(module_entry);
|
|
|
|
|
2000-04-24 23:40:07 +08:00
|
|
|
if ((type == MODULE_TEMPORARY) && module_entry->request_startup_func) {
|
2001-07-27 18:16:41 +08:00
|
|
|
if (module_entry->request_startup_func(type, module_entry->module_number TSRMLS_CC)) {
|
2002-08-24 09:19:28 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, error_type, "Unable to initialize module '%s'", module_entry->name);
|
2000-02-11 03:41:21 +08:00
|
|
|
DL_UNLOAD(handle);
|
1999-04-22 08:25:57 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* update the .request_started property... */
|
2001-08-12 01:03:37 +08:00
|
|
|
if (zend_hash_find(&module_registry, module_entry->name, strlen(module_entry->name)+1, (void **) &tmp)==FAILURE) {
|
2002-08-24 09:19:28 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, error_type, "Loaded module '%s' got lost", module_entry->name);
|
1999-04-22 08:25:57 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
tmp->handle = handle;
|
|
|
|
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
2001-06-06 21:06:12 +08:00
|
|
|
/* }}} */
|
1999-04-24 08:12:00 +08:00
|
|
|
|
1999-07-27 04:09:08 +08:00
|
|
|
PHP_MINFO_FUNCTION(dl)
|
1999-04-24 08:12:00 +08:00
|
|
|
{
|
2001-07-30 14:18:13 +08:00
|
|
|
php_info_print_table_row(2, "Dynamic Library Support", "enabled");
|
1999-04-22 08:25:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2002-01-31 18:21:24 +08:00
|
|
|
void php_dl(pval *file, int type, pval *return_value TSRMLS_DC)
|
1999-04-22 08:25:57 +08:00
|
|
|
{
|
2002-08-24 09:19:28 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot dynamically load %s - dynamic modules are not supported", Z_STRVAL_P(file));
|
1999-04-22 08:25:57 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2000-03-07 04:37:11 +08:00
|
|
|
PHP_MINFO_FUNCTION(dl)
|
|
|
|
{
|
2001-10-07 04:13:39 +08:00
|
|
|
PUTS("Dynamic Library support not available<br />.\n");
|
2000-03-07 04:37:11 +08:00
|
|
|
}
|
|
|
|
|
1999-04-22 08:25:57 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* tab-width: 4
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* End:
|
2001-09-09 21:29:31 +08:00
|
|
|
* vim600: sw=4 ts=4 fdm=marker
|
|
|
|
* vim<600: sw=4 ts=4
|
1999-04-22 08:25:57 +08:00
|
|
|
*/
|