1999-04-22 00:25:57 +00:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
1999-07-16 13:13:16 +00:00
|
|
|
| PHP version 4.0 |
|
1999-04-22 00:25:57 +00:00
|
|
|
+----------------------------------------------------------------------+
|
2001-02-26 06:11:02 +00:00
|
|
|
| Copyright (c) 1997-2001 The PHP Group |
|
1999-04-22 00:25:57 +00:00
|
|
|
+----------------------------------------------------------------------+
|
2000-05-18 15:34:45 +00:00
|
|
|
| This source file is subject to version 2.02 of the PHP license, |
|
1999-07-16 13:13:16 +00:00
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
|
|
|
| available at through the world-wide-web at |
|
2000-05-18 15:34:45 +00:00
|
|
|
| http://www.php.net/license/2_02.txt. |
|
1999-07-16 13:13:16 +00: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 00:25:57 +00:00
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Authors: Brian Schaffner <brian@tool.net> |
|
|
|
|
| Shane Caraveo <shane@caraveo.com> |
|
|
|
|
| Zeev Suraski <zeev@zend.com> |
|
|
|
|
+----------------------------------------------------------------------+
|
2000-07-24 01:40:02 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* $Id$ */
|
1999-04-22 00:25:57 +00:00
|
|
|
|
|
|
|
#include "php.h"
|
|
|
|
#include "dl.h"
|
|
|
|
#include "php_globals.h"
|
2000-04-05 21:43:03 +00:00
|
|
|
#include "ext/standard/info.h"
|
2000-06-26 18:27:12 +00:00
|
|
|
#include "SAPI.h"
|
2000-11-06 06:31:00 +00:00
|
|
|
|
|
|
|
#ifndef PHP_WIN32
|
2000-11-05 15:10:47 +00:00
|
|
|
#include "build-defs.h"
|
2000-11-06 06:31:00 +00:00
|
|
|
#endif
|
1999-04-22 00:25:57 +00:00
|
|
|
|
1999-12-04 20:55:33 +00:00
|
|
|
#ifdef HAVE_LIBDL
|
1999-04-22 00:25:57 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2000-03-18 16:16:15 +00:00
|
|
|
|
1999-04-22 00:25:57 +00:00
|
|
|
#if HAVE_STRING_H
|
|
|
|
#include <string.h>
|
|
|
|
#else
|
|
|
|
#include <strings.h>
|
|
|
|
#endif
|
2000-02-11 15:59:30 +00:00
|
|
|
#ifdef PHP_WIN32
|
1999-04-22 00:25:57 +00:00
|
|
|
#include "win32/param.h"
|
|
|
|
#include "win32/winutil.h"
|
2000-06-12 20:22:17 +00:00
|
|
|
#define GET_DL_ERROR() php_win_err()
|
1999-04-22 00:25:57 +00:00
|
|
|
#else
|
|
|
|
#include <sys/param.h>
|
2000-06-12 20:22:17 +00:00
|
|
|
#define GET_DL_ERROR() dlerror()
|
1999-04-22 00:25:57 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2000-06-12 20:22:17 +00:00
|
|
|
|
1999-04-22 00:25:57 +00:00
|
|
|
/* {{{ proto int dl(string extension_filename)
|
|
|
|
Load a PHP extension at runtime */
|
2000-03-06 20:37:11 +00:00
|
|
|
PHP_FUNCTION(dl)
|
1999-04-22 00:25:57 +00:00
|
|
|
{
|
1999-10-13 19:55:25 +00:00
|
|
|
pval **file;
|
1999-04-22 00:25:57 +00:00
|
|
|
|
2000-06-26 18:27:12 +00:00
|
|
|
#ifdef ZTS
|
|
|
|
if (strcmp(sapi_module.name, "cgi")!=0) {
|
|
|
|
php_error(E_ERROR, "dl() is not supported in multithreaded Web servers - use extension statements in your php.ini");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-04-22 00:25:57 +00:00
|
|
|
/* obtain arguments */
|
2000-06-05 19:47:54 +00:00
|
|
|
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &file) == FAILURE) {
|
1999-04-22 00:25:57 +00:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
|
1999-10-13 19:55:25 +00:00
|
|
|
convert_to_string_ex(file);
|
1999-04-22 00:25:57 +00:00
|
|
|
|
|
|
|
if (!PG(enable_dl)) {
|
1999-08-02 19:17:14 +00:00
|
|
|
php_error(E_ERROR, "Dynamically loaded extentions aren't enabled.");
|
1999-04-22 00:25:57 +00:00
|
|
|
} else if (PG(safe_mode)) {
|
1999-08-02 19:17:14 +00:00
|
|
|
php_error(E_ERROR, "Dynamically loaded extensions aren't allowed when running in SAFE MODE.");
|
1999-04-22 00:25:57 +00:00
|
|
|
} else {
|
2001-08-07 20:13:54 +00:00
|
|
|
php_dl(*file, MODULE_TEMPORARY, return_value TSRMLS_CC);
|
1999-04-22 00:25:57 +00:00
|
|
|
}
|
|
|
|
}
|
1999-10-13 19:55:25 +00:00
|
|
|
|
1999-04-22 00:25:57 +00:00
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
1999-12-04 20:55:33 +00:00
|
|
|
#ifdef HAVE_LIBDL
|
1999-04-22 00:25:57 +00:00
|
|
|
|
2000-03-11 16:23:30 +00:00
|
|
|
#ifdef ZTS
|
|
|
|
#define USING_ZTS 1
|
|
|
|
#else
|
|
|
|
#define USING_ZTS 0
|
|
|
|
#endif
|
|
|
|
|
2001-06-06 13:06:12 +00:00
|
|
|
/* {{{ php_dl
|
|
|
|
*/
|
2001-08-07 20:13:54 +00:00
|
|
|
void php_dl(pval *file, int type, pval *return_value TSRMLS_DC)
|
1999-04-22 00:25:57 +00:00
|
|
|
{
|
|
|
|
void *handle;
|
2000-03-07 03:43:03 +00:00
|
|
|
char *libpath;
|
2001-08-11 17:03:37 +00:00
|
|
|
zend_module_entry *module_entry, *tmp;
|
1999-12-17 20:55:31 +00:00
|
|
|
zend_module_entry *(*get_module)(void);
|
2000-06-12 20:22:17 +00:00
|
|
|
int error_type;
|
2000-06-12 21:01:03 +00:00
|
|
|
char *extension_dir;
|
2000-05-02 14:44:08 +00:00
|
|
|
|
2000-06-12 21:01:03 +00:00
|
|
|
if (type==MODULE_PERSISTENT) {
|
2000-11-05 15:03:41 +00:00
|
|
|
/* Use the configuration hash directly, the INI mechanism is not yet initialized */
|
2000-06-12 21:01:03 +00:00
|
|
|
if (cfg_get_string("extension_dir", &extension_dir)==FAILURE) {
|
2000-11-05 15:03:41 +00:00
|
|
|
extension_dir = PHP_EXTENSION_DIR;
|
2000-06-12 21:01:03 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
extension_dir = PG(extension_dir);
|
|
|
|
}
|
|
|
|
|
2000-06-12 20:22:17 +00:00
|
|
|
if (type==MODULE_TEMPORARY) {
|
|
|
|
error_type = E_WARNING;
|
|
|
|
} else {
|
|
|
|
error_type = E_CORE_WARNING;
|
|
|
|
}
|
|
|
|
|
2000-06-12 21:01:03 +00:00
|
|
|
if (extension_dir && extension_dir[0]){
|
|
|
|
int extension_dir_len = strlen(extension_dir);
|
1999-04-22 00:25:57 +00:00
|
|
|
|
2000-03-30 12:55:59 +00:00
|
|
|
libpath = emalloc(extension_dir_len+file->value.str.len+2);
|
2000-03-07 03:43:03 +00:00
|
|
|
|
2000-06-12 21:01:03 +00:00
|
|
|
if (IS_SLASH(extension_dir[extension_dir_len-1])) {
|
2001-08-11 17:03:37 +00:00
|
|
|
sprintf(libpath, "%s%s", extension_dir, file->value.str.val); /* SAFE */
|
2000-06-09 00:43:43 +00:00
|
|
|
} else {
|
2001-08-11 17:03:37 +00:00
|
|
|
sprintf(libpath, "%s/%s", extension_dir, file->value.str.val); /* SAFE */
|
2000-06-09 00:43:43 +00:00
|
|
|
}
|
1999-04-22 00:25:57 +00:00
|
|
|
} else {
|
2000-03-07 15:50:51 +00:00
|
|
|
libpath = estrndup(file->value.str.val, file->value.str.len);
|
1999-04-22 00:25:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* load dynamic symbol */
|
2000-02-10 19:41:21 +00:00
|
|
|
handle = DL_LOAD(libpath);
|
1999-04-22 00:25:57 +00:00
|
|
|
if (!handle) {
|
2000-06-12 20:22:17 +00:00
|
|
|
php_error(error_type, "Unable to load dynamic library '%s' - %s", libpath, GET_DL_ERROR());
|
2000-03-07 03:43:03 +00:00
|
|
|
efree(libpath);
|
1999-04-22 00:25:57 +00:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
2000-03-07 03:43:03 +00:00
|
|
|
|
|
|
|
efree(libpath);
|
|
|
|
|
1999-04-22 00:25:57 +00:00
|
|
|
|
2000-03-30 01:21:03 +00: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");
|
|
|
|
|
1999-04-22 00:25:57 +00:00
|
|
|
if (!get_module) {
|
2000-02-10 19:41:21 +00:00
|
|
|
DL_UNLOAD(handle);
|
2000-06-12 20:22:17 +00:00
|
|
|
php_error(error_type, "Invalid library (maybe not a PHP library) '%s' ", file->value.str.val);
|
1999-04-22 00:25:57 +00:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
module_entry = get_module();
|
2000-03-13 06:00:36 +00:00
|
|
|
if ((module_entry->zend_debug != ZEND_DEBUG) || (module_entry->zts != USING_ZTS)
|
|
|
|
|| (module_entry->zend_api != ZEND_MODULE_API_NO)) {
|
2000-06-12 20:22:17 +00:00
|
|
|
php_error(error_type,
|
2000-03-11 16:23:30 +00:00
|
|
|
"%s: Unable to initialize module\n"
|
2000-03-13 06:00:36 +00:00
|
|
|
"Module compiled with debug=%d, thread-safety=%d module API=%d\n"
|
|
|
|
"PHP compiled with debug=%d, thread-safety=%d module API=%d\n"
|
2000-03-11 16:23:30 +00:00
|
|
|
"These options need to match\n",
|
2000-03-13 06:00:36 +00:00
|
|
|
module_entry->name, module_entry->zend_debug, module_entry->zts, module_entry->zend_api,
|
|
|
|
ZEND_DEBUG, USING_ZTS, ZEND_MODULE_API_NO);
|
2000-03-11 16:23:30 +00:00
|
|
|
DL_UNLOAD(handle);
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
1999-04-22 00:25:57 +00:00
|
|
|
module_entry->type = type;
|
|
|
|
module_entry->module_number = zend_next_free_module();
|
|
|
|
if (module_entry->module_startup_func) {
|
2001-07-27 10:16:41 +00:00
|
|
|
if (module_entry->module_startup_func(type, module_entry->module_number TSRMLS_CC)==FAILURE) {
|
2000-06-12 20:22:17 +00:00
|
|
|
php_error(error_type, "%s: Unable to initialize module", module_entry->name);
|
2000-02-10 19:41:21 +00:00
|
|
|
DL_UNLOAD(handle);
|
1999-04-22 00:25:57 +00:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
zend_register_module(module_entry);
|
|
|
|
|
2000-04-24 15:40:07 +00:00
|
|
|
if ((type == MODULE_TEMPORARY) && module_entry->request_startup_func) {
|
2001-07-27 10:16:41 +00:00
|
|
|
if (module_entry->request_startup_func(type, module_entry->module_number TSRMLS_CC)) {
|
2000-06-12 20:22:17 +00:00
|
|
|
php_error(error_type, "%s: Unable to initialize module", module_entry->name);
|
2000-02-10 19:41:21 +00:00
|
|
|
DL_UNLOAD(handle);
|
1999-04-22 00:25:57 +00:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* update the .request_started property... */
|
2001-08-11 17:03:37 +00:00
|
|
|
if (zend_hash_find(&module_registry, module_entry->name, strlen(module_entry->name)+1, (void **) &tmp)==FAILURE) {
|
|
|
|
php_error(error_type, "%s: Loaded module got lost", module_entry->name);
|
1999-04-22 00:25:57 +00:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
tmp->handle = handle;
|
|
|
|
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
2001-06-06 13:06:12 +00:00
|
|
|
/* }}} */
|
1999-04-24 00:12:00 +00:00
|
|
|
|
1999-07-26 20:09:08 +00:00
|
|
|
PHP_MINFO_FUNCTION(dl)
|
1999-04-24 00:12:00 +00:00
|
|
|
{
|
2001-07-30 06:18:13 +00:00
|
|
|
php_info_print_table_row(2, "Dynamic Library Support", "enabled");
|
1999-04-22 00:25:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2000-06-12 20:22:17 +00:00
|
|
|
void php_dl(pval *file, int type, pval *return_value)
|
1999-04-22 00:25:57 +00:00
|
|
|
{
|
2001-08-11 17:03:37 +00:00
|
|
|
php_error(E_WARNING, "Cannot dynamically load %s - dynamic modules are not supported", file->value.str.val);
|
1999-04-22 00:25:57 +00:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2000-03-06 20:37:11 +00:00
|
|
|
PHP_MINFO_FUNCTION(dl)
|
|
|
|
{
|
|
|
|
PUTS("Dynamic Library support not available<br>.\n");
|
|
|
|
}
|
|
|
|
|
1999-04-22 00:25:57 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* tab-width: 4
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* End:
|
2001-06-06 13:06:12 +00:00
|
|
|
* vim600: sw=4 ts=4 tw=78 fdm=marker
|
|
|
|
* vim<600: sw=4 ts=4 tw=78
|
1999-04-22 00:25:57 +00:00
|
|
|
*/
|