Allow loading PHP and Zend extensions by name

Allow extension name as INI 'extension=' and dl() argument
No BC break, as file name is still accepted.
When using the '-z' command line option (CLI/CGI), an absolute file name must still be provided (nothing changed here)
Change comments in example INI files
This commit is contained in:
Francois Laupretre 2016-01-28 19:50:18 +01:00 committed by Sara Golemon
parent 0f15a03026
commit fe5c8f2b80
5 changed files with 160 additions and 103 deletions

6
NEWS
View file

@ -6,10 +6,16 @@ PHP NEWS
. Fixed bug #74780 (parse_url() borken when query string contains colon). . Fixed bug #74780 (parse_url() borken when query string contains colon).
(jhdxr) (jhdxr)
. Fixed bug #74761 (Unary operator expected error on some systems). (petk) . Fixed bug #74761 (Unary operator expected error on some systems). (petk)
. Allow loading PHP/Zend extensions by name in ini files (extension=<name>).
(francois at tekwire dot net)
- SPL: - SPL:
. Fixed bug #73471 (PHP freezes with AppendIterator). (jhdxr) . Fixed bug #73471 (PHP freezes with AppendIterator). (jhdxr)
- Standard:
. Add support for extension name as argument to dl().
(francois at tekwire dot net)
22 Jun 2017, PHP 7.2.0alpha2 22 Jun 2017, PHP 7.2.0alpha2
- Core: - Core:

View file

@ -81,10 +81,10 @@ PHPAPI PHP_FUNCTION(dl)
PHPAPI int php_load_extension(char *filename, int type, int start_now) PHPAPI int php_load_extension(char *filename, int type, int start_now)
{ {
void *handle; void *handle;
char *libpath; char *libpath, *orig_libpath;
zend_module_entry *module_entry; zend_module_entry *module_entry;
zend_module_entry *(*get_module)(void); zend_module_entry *(*get_module)(void);
int error_type; int error_type, slash_suffix;
char *extension_dir; char *extension_dir;
if (type == MODULE_PERSISTENT) { if (type == MODULE_PERSISTENT) {
@ -109,12 +109,37 @@ PHPAPI int php_load_extension(char *filename, int type, int start_now)
libpath = estrdup(filename); libpath = estrdup(filename);
} else if (extension_dir && extension_dir[0]) { } else if (extension_dir && extension_dir[0]) {
int extension_dir_len = (int)strlen(extension_dir); int extension_dir_len = (int)strlen(extension_dir);
slash_suffix = IS_SLASH(extension_dir[extension_dir_len-1]);
if (IS_SLASH(extension_dir[extension_dir_len-1])) { /* Try as filename first */
if (slash_suffix) {
spprintf(&libpath, 0, "%s%s", extension_dir, filename); /* SAFE */ spprintf(&libpath, 0, "%s%s", extension_dir, filename); /* SAFE */
} else { } else {
spprintf(&libpath, 0, "%s%c%s", extension_dir, DEFAULT_SLASH, filename); /* SAFE */ spprintf(&libpath, 0, "%s%c%s", extension_dir, DEFAULT_SLASH, filename); /* SAFE */
} }
if (VCWD_ACCESS(libpath, F_OK)) {
/* If file does not exist, consider as extension name and build file name */
orig_libpath = libpath;
#if PHP_WIN32
if (slash_suffix) {
spprintf(&libpath, 0, "%sphp_%s." PHP_SHLIB_SUFFIX, extension_dir, filename); /* SAFE */
} else {
spprintf(&libpath, 0, "%s%cphp_%s." PHP_SHLIB_SUFFIX, extension_dir, DEFAULT_SLASH, filename); /* SAFE */
}
#else
if (slash_suffix) {
spprintf(&libpath, 0, "%s%s." PHP_SHLIB_SUFFIX, extension_dir, filename); /* SAFE */
} else {
spprintf(&libpath, 0, "%s%c%s." PHP_SHLIB_SUFFIX, extension_dir, DEFAULT_SLASH, filename); /* SAFE */
}
#endif
if (VCWD_ACCESS(libpath, F_OK)) {
php_error_docref(NULL TSRMLS_CC, error_type, "Cannot access dynamic library '%s' (tried : %s, %s)", filename, orig_libpath, libpath);
efree(orig_libpath);
efree(libpath);
return FAILURE;
}
efree(orig_libpath);
}
} else { } else {
return FAILURE; /* Not full path given or extension_dir is not set */ return FAILURE; /* Not full path given or extension_dir is not set */
} }

View file

@ -362,15 +362,43 @@ static void php_load_zend_extension_cb(void *arg)
if (IS_ABSOLUTE_PATH(filename, length)) { if (IS_ABSOLUTE_PATH(filename, length)) {
zend_load_extension(filename); zend_load_extension(filename);
} else { } else {
char *libpath; char *libpath, *orig_libpath;
char *extension_dir = INI_STR("extension_dir"); char *extension_dir = INI_STR("extension_dir");
int extension_dir_len = (int)strlen(extension_dir); int extension_dir_len = (int)strlen(extension_dir);
int slash_suffix = IS_SLASH(extension_dir[extension_dir_len-1]);
if (IS_SLASH(extension_dir[extension_dir_len-1])) { /* Try as filename first */
spprintf(&libpath, 0, "%s%s", extension_dir, filename); if (slash_suffix) {
spprintf(&libpath, 0, "%s%s", extension_dir, filename); /* SAFE */
} else { } else {
spprintf(&libpath, 0, "%s%c%s", extension_dir, DEFAULT_SLASH, filename); spprintf(&libpath, 0, "%s%c%s", extension_dir, DEFAULT_SLASH, filename); /* SAFE */
} }
if (VCWD_ACCESS(libpath, F_OK)) {
/* If file does not exist, consider as extension name and build file name */
orig_libpath = libpath;
#if PHP_WIN32
if (slash_suffix) {
spprintf(&libpath, 0, "%sphp_%s." PHP_SHLIB_SUFFIX, extension_dir, filename); /* SAFE */
} else {
spprintf(&libpath, 0, "%s%cphp_%s." PHP_SHLIB_SUFFIX, extension_dir, DEFAULT_SLASH, filename); /* SAFE */
}
#else
if (slash_suffix) {
spprintf(&libpath, 0, "%s%s." PHP_SHLIB_SUFFIX, extension_dir, filename); /* SAFE */
} else {
spprintf(&libpath, 0, "%s%c%s." PHP_SHLIB_SUFFIX, extension_dir, DEFAULT_SLASH, filename); /* SAFE */
}
#endif
if (VCWD_ACCESS(libpath, F_OK)) {
fprintf(stderr, "Cannot access Zend extension %s (Tried: %s, %s)\n", filename, orig_libpath, libpath);
/* See http://support.microsoft.com/kb/190351 */
fflush(stderr);
efree(orig_libpath);
efree(libpath);
return;
}
efree(orig_libpath);
}
zend_load_extension(libpath); zend_load_extension(libpath);
efree(libpath); efree(libpath);
} }

View file

@ -860,64 +860,63 @@ default_socket_timeout = 60
; If you wish to have an extension loaded automatically, use the following ; If you wish to have an extension loaded automatically, use the following
; syntax: ; syntax:
; ;
; extension=modulename.extension ; extension=modulename
; ;
; For example, on Windows: ; For example:
; ;
; extension=mysqli.dll ; extension=mysqli
; ;
; ... or under UNIX: ; When the extension library to load is not located in the default extension
; ; directory, You may specify an absolute path to the library file:
; extension=mysqli.so
;
; ... or with a path:
; ;
; extension=/path/to/extension/mysqli.so ; extension=/path/to/extension/mysqli.so
; ;
; If you only provide the name of the extension, PHP will look for it in its ; Note : The syntax used in previous PHP versions ('extension=<ext>.so' and
; default extension directory. ; 'extension='php_<ext>.dll') is supported for legacy reasons and may be
; deprecated in a future PHP major version. So, when it is possible, please
; move to the new ('extension=<ext>) syntax.
; ;
; Windows Extensions ; Notes for Windows environments :
; Note that ODBC support is built in, so no dll is needed for it. ;
; Note that many DLL files are located in the extensions/ (PHP 4) ext/ (PHP 5+) ; - ODBC support is built in, so no dll is needed for it.
; - Many DLL files are located in the extensions/ (PHP 4) or ext/ (PHP 5+)
; extension folders as well as the separate PECL DLL download (PHP 5+). ; extension folders as well as the separate PECL DLL download (PHP 5+).
; Be sure to appropriately set the extension_dir directive. ; Be sure to appropriately set the extension_dir directive.
; ;
;extension=php_bz2.dll ;extension=bz2
;extension=php_curl.dll ;extension=curl
;extension=php_fileinfo.dll ;extension=fileinfo
;extension=php_ftp.dll ;extension=gd2
;extension=php_gd2.dll ;extension=gettext
;extension=php_gettext.dll ;extension=gmp
;extension=php_gmp.dll ;extension=intl
;extension=php_intl.dll ;extension=imap
;extension=php_imap.dll ;extension=interbase
;extension=php_interbase.dll ;extension=ldap
;extension=php_ldap.dll ;extension=mbstring
;extension=php_mbstring.dll ;extension=exif ; Must be after mbstring as it depends on it
;extension=php_exif.dll ; Must be after mbstring as it depends on it ;extension=mysqli
;extension=php_mysqli.dll ;extension=oci8_12c ; Use with Oracle Database 12c Instant Client
;extension=php_oci8_12c.dll ; Use with Oracle Database 12c Instant Client ;extension=openssl
;extension=php_openssl.dll ;extension=pdo_firebird
;extension=php_pdo_firebird.dll ;extension=pdo_mysql
;extension=php_pdo_mysql.dll ;extension=pdo_oci
;extension=php_pdo_oci.dll ;extension=pdo_odbc
;extension=php_pdo_odbc.dll ;extension=pdo_pgsql
;extension=php_pdo_pgsql.dll ;extension=pdo_sqlite
;extension=php_pdo_sqlite.dll ;extension=pgsql
;extension=php_pgsql.dll ;extension=shmop
;extension=php_shmop.dll
; The MIBS data available in the PHP distribution must be installed. ; The MIBS data available in the PHP distribution must be installed.
; See http://www.php.net/manual/en/snmp.installation.php ; See http://www.php.net/manual/en/snmp.installation.php
;extension=php_snmp.dll ;extension=snmp
;extension=php_soap.dll ;extension=soap
;extension=php_sockets.dll ;extension=sockets
;extension=php_sqlite3.dll ;extension=sqlite3
;extension=php_tidy.dll ;extension=tidy
;extension=php_xmlrpc.dll ;extension=xmlrpc
;extension=php_xsl.dll ;extension=xsl
;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;
; Module Settings ; ; Module Settings ;

View file

@ -867,64 +867,63 @@ default_socket_timeout = 60
; If you wish to have an extension loaded automatically, use the following ; If you wish to have an extension loaded automatically, use the following
; syntax: ; syntax:
; ;
; extension=modulename.extension ; extension=modulename
; ;
; For example, on Windows: ; For example:
; ;
; extension=mysqli.dll ; extension=mysqli
; ;
; ... or under UNIX: ; When the extension library to load is not located in the default extension
; ; directory, You may specify an absolute path to the library file:
; extension=mysqli.so
;
; ... or with a path:
; ;
; extension=/path/to/extension/mysqli.so ; extension=/path/to/extension/mysqli.so
; ;
; If you only provide the name of the extension, PHP will look for it in its ; Note : The syntax used in previous PHP versions ('extension=<ext>.so' and
; default extension directory. ; 'extension='php_<ext>.dll') is supported for legacy reasons and may be
; deprecated in a future PHP major version. So, when it is possible, please
; move to the new ('extension=<ext>) syntax.
; ;
; Windows Extensions ; Notes for Windows environments :
; Note that ODBC support is built in, so no dll is needed for it. ;
; Note that many DLL files are located in the extensions/ (PHP 4) ext/ (PHP 5+) ; - ODBC support is built in, so no dll is needed for it.
; - Many DLL files are located in the extensions/ (PHP 4) or ext/ (PHP 5+)
; extension folders as well as the separate PECL DLL download (PHP 5+). ; extension folders as well as the separate PECL DLL download (PHP 5+).
; Be sure to appropriately set the extension_dir directive. ; Be sure to appropriately set the extension_dir directive.
; ;
;extension=php_bz2.dll ;extension=bz2
;extension=php_curl.dll ;extension=curl
;extension=php_fileinfo.dll ;extension=fileinfo
;extension=php_ftp.dll ;extension=gd2
;extension=php_gd2.dll ;extension=gettext
;extension=php_gettext.dll ;extension=gmp
;extension=php_gmp.dll ;extension=intl
;extension=php_intl.dll ;extension=imap
;extension=php_imap.dll ;extension=interbase
;extension=php_interbase.dll ;extension=ldap
;extension=php_ldap.dll ;extension=mbstring
;extension=php_mbstring.dll ;extension=exif ; Must be after mbstring as it depends on it
;extension=php_exif.dll ; Must be after mbstring as it depends on it ;extension=mysqli
;extension=php_mysqli.dll ;extension=oci8_12c ; Use with Oracle Database 12c Instant Client
;extension=php_oci8_12c.dll ; Use with Oracle Database 12c Instant Client ;extension=openssl
;extension=php_openssl.dll ;extension=pdo_firebird
;extension=php_pdo_firebird.dll ;extension=pdo_mysql
;extension=php_pdo_mysql.dll ;extension=pdo_oci
;extension=php_pdo_oci.dll ;extension=pdo_odbc
;extension=php_pdo_odbc.dll ;extension=pdo_pgsql
;extension=php_pdo_pgsql.dll ;extension=pdo_sqlite
;extension=php_pdo_sqlite.dll ;extension=pgsql
;extension=php_pgsql.dll ;extension=shmop
;extension=php_shmop.dll
; The MIBS data available in the PHP distribution must be installed. ; The MIBS data available in the PHP distribution must be installed.
; See http://www.php.net/manual/en/snmp.installation.php ; See http://www.php.net/manual/en/snmp.installation.php
;extension=php_snmp.dll ;extension=snmp
;extension=php_soap.dll ;extension=soap
;extension=php_sockets.dll ;extension=sockets
;extension=php_sqlite3.dll ;extension=sqlite3
;extension=php_tidy.dll ;extension=tidy
;extension=php_xmlrpc.dll ;extension=xmlrpc
;extension=php_xsl.dll ;extension=xsl
;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;
; Module Settings ; ; Module Settings ;