1999-04-22 00:25:57 +00:00
/*
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2004-01-08 08:18:22 +00:00
| PHP Version 5 |
1999-04-22 00:25:57 +00:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2013-01-01 08:37:09 +00:00
| Copyright ( c ) 1997 - 2013 The PHP Group |
1999-04-22 00:25:57 +00:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2006-01-01 12:51:34 +00:00
| This source file is subject to version 3.01 of the PHP license , |
1999-07-16 13:13:16 +00:00
| that is bundled with this package in the file LICENSE , and is |
2003-06-10 20:04:29 +00:00
| available through the world - wide - web at the following url : |
2006-01-01 12:51:34 +00:00
| http : //www.php.net/license/3_01.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"
2005-07-29 13:25:33 +00:00
# include "php_ini.h"
2000-04-05 21:43:03 +00:00
# include "ext/standard/info.h"
2005-07-29 13:25:33 +00:00
2000-06-26 18:27:12 +00:00
# include "SAPI.h"
2000-11-06 06:31:00 +00:00
2009-08-06 01:33:54 +00:00
# if defined(HAVE_LIBDL)
1999-04-22 00:25:57 +00:00
# include <stdlib.h>
# include <stdio.h>
2002-09-05 14:25:07 +00:00
# ifdef HAVE_STRING_H
1999-04-22 00:25:57 +00:00
# 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()
2002-09-05 14:25:07 +00:00
# elif defined(NETWARE)
# include <sys/param.h>
# define GET_DL_ERROR() dlerror()
1999-04-22 00:25:57 +00:00
# else
# include <sys/param.h>
2002-04-04 00:24:34 +00:00
# define GET_DL_ERROR() DL_ERROR()
1999-04-22 00:25:57 +00:00
# endif
2009-08-06 01:33:54 +00:00
# endif /* defined(HAVE_LIBDL) */
1999-04-22 00:25:57 +00:00
/* {{{ proto int dl(string extension_filename)
Load a PHP extension at runtime */
2009-01-07 13:02:43 +00:00
PHPAPI PHP_FUNCTION ( dl )
1999-04-22 00:25:57 +00:00
{
2008-05-16 12:18:43 +00:00
char * filename ;
int filename_len ;
1999-04-22 00:25:57 +00:00
2008-05-16 12:18:43 +00:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " s " , & filename , & filename_len ) = = FAILURE ) {
2007-11-09 13:49:15 +00:00
return ;
2004-05-25 13:25:22 +00:00
}
2005-06-16 15:36:39 +00:00
if ( ! PG ( enable_dl ) ) {
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Dynamically loaded extensions aren't enabled " ) ;
RETURN_FALSE ;
}
2008-05-16 12:18:43 +00:00
if ( filename_len > = MAXPATHLEN ) {
2007-09-18 20:19:34 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " File name exceeds the maximum allowed length of %d characters " , MAXPATHLEN ) ;
RETURN_FALSE ;
}
2007-11-09 13:49:15 +00:00
if ( ( strncmp ( sapi_module . name , " cgi " , 3 ) ! = 0 ) & &
( strcmp ( sapi_module . name , " cli " ) ! = 0 ) & &
( strncmp ( sapi_module . name , " embed " , 5 ) ! = 0 )
) {
2005-06-16 15:36:39 +00:00
# ifdef ZTS
2008-05-16 12:18:43 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Not supported in multithreaded Web servers - use extension=%s in your php.ini " , filename ) ;
2002-10-13 14:14:34 +00:00
RETURN_FALSE ;
2005-06-16 15:36:39 +00:00
# else
2008-05-16 12:18:43 +00:00
php_error_docref ( NULL TSRMLS_CC , E_DEPRECATED , " dl() is deprecated - use extension=%s in your php.ini " , filename ) ;
2000-06-26 18:27:12 +00:00
# endif
1999-04-22 00:25:57 +00:00
}
2005-06-16 15:36:39 +00:00
2007-11-09 13:49:15 +00:00
php_dl ( filename , MODULE_TEMPORARY , return_value , 0 TSRMLS_CC ) ;
2008-02-28 16:59:10 +00:00
if ( Z_LVAL_P ( return_value ) = = 1 ) {
EG ( full_tables_cleanup ) = 1 ;
}
1999-04-22 00:25:57 +00:00
}
/* }}} */
2009-08-06 01:33:54 +00:00
# if defined(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
2011-09-07 13:46:45 +00:00
/* {{{ php_load_extension
2008-02-23 17:06:22 +00:00
*/
2011-09-07 13:46:45 +00:00
PHPAPI int php_load_extension ( char * filename , int type , int start_now TSRMLS_DC )
1999-04-22 00:25:57 +00:00
{
void * handle ;
2000-03-07 03:43:03 +00:00
char * libpath ;
2004-05-25 13:51:00 +00:00
zend_module_entry * module_entry ;
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
2005-07-29 13:25:33 +00:00
if ( type = = MODULE_PERSISTENT ) {
extension_dir = INI_STR ( " extension_dir " ) ;
2000-06-12 21:01:03 +00:00
} else {
extension_dir = PG ( extension_dir ) ;
}
2005-07-29 13:25:33 +00:00
if ( type = = MODULE_TEMPORARY ) {
2000-06-12 20:22:17 +00:00
error_type = E_WARNING ;
} else {
error_type = E_CORE_WARNING ;
}
2007-11-09 16:27:43 +00:00
/* Check if passed filename contains directory separators */
if ( strchr ( filename , ' / ' ) ! = NULL | | strchr ( filename , DEFAULT_SLASH ) ! = NULL ) {
/* Passing modules with full path is not supported for dynamically loaded extensions */
2007-09-13 07:42:12 +00:00
if ( type = = MODULE_TEMPORARY ) {
2007-11-09 16:27:43 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Temporary module name should contain only filename " ) ;
return FAILURE ;
2007-09-13 00:56:31 +00:00
}
2007-11-09 16:27:43 +00:00
libpath = estrdup ( filename ) ;
} else if ( extension_dir & & extension_dir [ 0 ] ) {
int extension_dir_len = strlen ( extension_dir ) ;
2007-09-13 00:56:31 +00:00
2000-06-12 21:01:03 +00:00
if ( IS_SLASH ( extension_dir [ extension_dir_len - 1 ] ) ) {
2007-11-09 13:49:15 +00:00
spprintf ( & libpath , 0 , " %s%s " , extension_dir , filename ) ; /* SAFE */
2000-06-09 00:43:43 +00:00
} else {
2007-11-09 13:49:15 +00:00
spprintf ( & libpath , 0 , " %s%c%s " , extension_dir , DEFAULT_SLASH , filename ) ; /* SAFE */
2000-06-09 00:43:43 +00:00
}
1999-04-22 00:25:57 +00:00
} else {
2007-11-09 16:27:43 +00:00
return FAILURE ; /* Not full path given or extension_dir is not set */
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 ) {
2009-10-21 06:42:08 +00:00
# if PHP_WIN32
char * err = GET_DL_ERROR ( ) ;
2011-05-26 14:37:13 +00:00
if ( err & & ( * err ! = " " ) ) {
2009-10-21 06:42:08 +00:00
php_error_docref ( NULL TSRMLS_CC , error_type , " Unable to load dynamic library '%s' - %s " , libpath , err ) ;
LocalFree ( err ) ;
} else {
php_error_docref ( NULL TSRMLS_CC , error_type , " Unable to load dynamic library '%s' - %s " , libpath , " Unknown reason " ) ;
}
# else
2002-08-24 01:19:28 +00:00
php_error_docref ( NULL TSRMLS_CC , error_type , " Unable to load dynamic library '%s' - %s " , libpath , GET_DL_ERROR ( ) ) ;
2003-12-17 11:20:35 +00:00
GET_DL_ERROR ( ) ; /* free the buffer storing the error */
2009-10-21 06:42:08 +00:00
# endif
2000-03-07 03:43:03 +00:00
efree ( libpath ) ;
2007-11-09 16:27:43 +00:00
return FAILURE ;
1999-04-22 00:25:57 +00:00
}
2000-03-07 03:43:03 +00:00
efree ( libpath ) ;
2000-03-30 01:21:03 +00:00
get_module = ( zend_module_entry * ( * ) ( void ) ) DL_FETCH_SYMBOL ( handle , " get_module " ) ;
2007-11-09 13:49:15 +00:00
/* Some OS prepend _ to symbol names while their dynamic linker
2000-03-30 01:21:03 +00:00
* does not do that automatically . Thus we check manually for
2007-11-09 13:49:15 +00:00
* _get_module . */
2000-03-30 01:21:03 +00:00
2007-11-09 13:49:15 +00:00
if ( ! get_module ) {
2000-03-30 01:21:03 +00:00
get_module = ( zend_module_entry * ( * ) ( void ) ) DL_FETCH_SYMBOL ( handle , " _get_module " ) ;
2007-11-09 13:49:15 +00:00
}
2000-03-30 01:21:03 +00:00
1999-04-22 00:25:57 +00:00
if ( ! get_module ) {
2013-04-03 08:59:37 +00:00
if ( DL_FETCH_SYMBOL ( handle , " zend_extension_entry " ) | | DL_FETCH_SYMBOL ( handle , " _zend_extension_entry " ) ) {
DL_UNLOAD ( handle ) ;
php_error_docref ( NULL TSRMLS_CC , error_type , " Invalid library (appears to be a Zend Extension, try loading using zend_extension=%s from php.ini) " , filename ) ;
return FAILURE ;
}
2000-02-10 19:41:21 +00:00
DL_UNLOAD ( handle ) ;
2007-11-09 16:27:43 +00:00
php_error_docref ( NULL TSRMLS_CC , error_type , " Invalid library (maybe not a PHP library) '%s' " , filename ) ;
return FAILURE ;
1999-04-22 00:25:57 +00:00
}
module_entry = get_module ( ) ;
2009-01-17 02:05:13 +00:00
if ( module_entry - > zend_api ! = ZEND_MODULE_API_NO ) {
2002-03-23 15:37:27 +00:00
/* Check for pre-4.1.0 module which has a slightly different module_entry structure :( */
struct pre_4_1_0_module_entry {
2007-11-09 13:49:15 +00:00
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 ;
2002-03-23 15:37:27 +00:00
} ;
2007-09-27 18:00:48 +00:00
const char * name ;
2002-03-23 15:37:27 +00:00
int zend_api ;
2007-09-13 07:42:12 +00:00
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 )
) {
2007-11-09 13:49:15 +00:00
name = ( ( struct pre_4_1_0_module_entry * ) module_entry ) - > name ;
zend_api = ( ( struct pre_4_1_0_module_entry * ) module_entry ) - > zend_api ;
} else {
name = module_entry - > name ;
zend_api = module_entry - > zend_api ;
2002-03-23 15:37:27 +00:00
}
2002-12-05 20:59:49 +00:00
php_error_docref ( NULL TSRMLS_CC , error_type ,
2007-11-09 13:49:15 +00:00
" %s: Unable to initialize module \n "
2009-01-17 02:05:13 +00:00
" Module compiled with module API=%d \n "
" PHP compiled with module API=%d \n "
2007-11-09 13:49:15 +00:00
" These options need to match \n " ,
2009-01-17 02:05:13 +00:00
name , zend_api , ZEND_MODULE_API_NO ) ;
2002-03-23 15:37:27 +00:00
DL_UNLOAD ( handle ) ;
2007-11-09 16:27:43 +00:00
return FAILURE ;
2000-03-11 16:23:30 +00:00
}
2009-01-17 02:05:13 +00:00
if ( strcmp ( module_entry - > build_id , ZEND_MODULE_BUILD_ID ) ) {
php_error_docref ( NULL TSRMLS_CC , error_type ,
" %s: Unable to initialize module \n "
" Module compiled with build ID=%s \n "
" PHP compiled with build ID=%s \n "
" These options need to match \n " ,
module_entry - > name , module_entry - > build_id , ZEND_MODULE_BUILD_ID ) ;
DL_UNLOAD ( handle ) ;
return FAILURE ;
}
2004-05-18 16:13:57 +00:00
module_entry - > type = type ;
1999-04-22 00:25:57 +00:00
module_entry - > module_number = zend_next_free_module ( ) ;
2004-07-20 19:23:55 +00:00
module_entry - > handle = handle ;
2005-07-18 16:20:08 +00:00
if ( ( module_entry = zend_register_module_ex ( module_entry TSRMLS_CC ) ) = = NULL ) {
2004-05-21 17:08:36 +00:00
DL_UNLOAD ( handle ) ;
2007-11-09 16:27:43 +00:00
return FAILURE ;
1999-04-22 00:25:57 +00:00
}
2004-05-21 17:17:55 +00:00
2005-08-08 16:49:44 +00:00
if ( ( type = = MODULE_TEMPORARY | | start_now ) & & zend_startup_module_ex ( module_entry TSRMLS_CC ) = = FAILURE ) {
2005-06-17 09:39:23 +00:00
DL_UNLOAD ( handle ) ;
2007-11-09 16:27:43 +00:00
return FAILURE ;
2005-06-17 09:39:23 +00:00
}
2005-08-08 16:49:44 +00:00
if ( ( type = = MODULE_TEMPORARY | | start_now ) & & module_entry - > request_startup_func ) {
2005-06-17 09:39:23 +00:00
if ( module_entry - > request_startup_func ( type , module_entry - > module_number TSRMLS_CC ) = = FAILURE ) {
2004-05-21 17:17:55 +00:00
php_error_docref ( NULL TSRMLS_CC , error_type , " Unable to initialize module '%s' " , module_entry - > name ) ;
DL_UNLOAD ( handle ) ;
2007-11-09 16:27:43 +00:00
return FAILURE ;
2004-05-21 17:17:55 +00:00
}
}
2007-11-09 16:27:43 +00:00
return SUCCESS ;
}
/* }}} */
/* {{{ php_dl
*/
2008-05-16 12:18:43 +00:00
PHPAPI void php_dl ( char * file , int type , zval * return_value , int start_now TSRMLS_DC )
2007-11-09 16:27:43 +00:00
{
/* Load extension */
2008-05-16 12:18:43 +00:00
if ( php_load_extension ( file , type , start_now TSRMLS_CC ) = = FAILURE ) {
2007-11-09 16:27:43 +00:00
RETVAL_FALSE ;
} else {
RETVAL_TRUE ;
}
1999-04-22 00:25:57 +00:00
}
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
2008-05-16 12:18:43 +00:00
PHPAPI void php_dl ( char * file , int type , zval * return_value , int start_now TSRMLS_DC )
1999-04-22 00:25:57 +00:00
{
2008-05-16 12:18:43 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Cannot dynamically load %s - dynamic modules are not supported " , file ) ;
1999-04-22 00:25:57 +00:00
RETURN_FALSE ;
}
2000-03-06 20:37:11 +00:00
PHP_MINFO_FUNCTION ( dl )
{
2001-10-06 20:13:39 +00:00
PUTS ( " Dynamic Library support not available<br />. \n " ) ;
2000-03-06 20:37:11 +00:00
}
1999-04-22 00:25:57 +00:00
# endif
/*
* Local variables :
* tab - width : 4
* c - basic - offset : 4
* End :
2001-09-09 13:29:31 +00:00
* vim600 : sw = 4 ts = 4 fdm = marker
* vim < 600 : sw = 4 ts = 4
1999-04-22 00:25:57 +00:00
*/