summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrancois Laupretre <francois@tekwire.net>2016-01-28 19:50:18 +0100
committerSara Golemon <pollita@php.net>2017-06-22 12:58:15 -0400
commitfe5c8f2b80e57c6470a56a8d775947fe0ded182e (patch)
tree171a791b6e1576002dff8d9624bbca3e40329d97
parent0f15a0302679fc100c06ad5f81af9117d6fa2a22 (diff)
downloadphp-git-fe5c8f2b80e57c6470a56a8d775947fe0ded182e.tar.gz
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
-rw-r--r--NEWS6
-rw-r--r--ext/standard/dl.c33
-rw-r--r--main/php_ini.c38
-rw-r--r--php.ini-development95
-rw-r--r--php.ini-production95
5 files changed, 162 insertions, 105 deletions
diff --git a/NEWS b/NEWS
index 3984a5949a..2496664ddf 100644
--- a/NEWS
+++ b/NEWS
@@ -6,10 +6,16 @@ PHP NEWS
. Fixed bug #74780 (parse_url() borken when query string contains colon).
(jhdxr)
. 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:
. 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
- Core:
diff --git a/ext/standard/dl.c b/ext/standard/dl.c
index f7933855b0..35a71ab2a5 100644
--- a/ext/standard/dl.c
+++ b/ext/standard/dl.c
@@ -81,10 +81,10 @@ PHPAPI PHP_FUNCTION(dl)
PHPAPI int php_load_extension(char *filename, int type, int start_now)
{
void *handle;
- char *libpath;
+ char *libpath, *orig_libpath;
zend_module_entry *module_entry;
zend_module_entry *(*get_module)(void);
- int error_type;
+ int error_type, slash_suffix;
char *extension_dir;
if (type == MODULE_PERSISTENT) {
@@ -109,12 +109,37 @@ PHPAPI int php_load_extension(char *filename, int type, int start_now)
libpath = estrdup(filename);
} else if (extension_dir && extension_dir[0]) {
int extension_dir_len = (int)strlen(extension_dir);
-
- if (IS_SLASH(extension_dir[extension_dir_len-1])) {
+ slash_suffix = IS_SLASH(extension_dir[extension_dir_len-1]);
+ /* Try as filename first */
+ if (slash_suffix) {
spprintf(&libpath, 0, "%s%s", extension_dir, filename); /* SAFE */
} else {
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 {
return FAILURE; /* Not full path given or extension_dir is not set */
}
diff --git a/main/php_ini.c b/main/php_ini.c
index 75b1695ec4..a378ce1926 100644
--- a/main/php_ini.c
+++ b/main/php_ini.c
@@ -362,15 +362,43 @@ static void php_load_zend_extension_cb(void *arg)
if (IS_ABSOLUTE_PATH(filename, length)) {
zend_load_extension(filename);
} else {
- char *libpath;
+ char *libpath, *orig_libpath;
char *extension_dir = INI_STR("extension_dir");
int extension_dir_len = (int)strlen(extension_dir);
-
- if (IS_SLASH(extension_dir[extension_dir_len-1])) {
- spprintf(&libpath, 0, "%s%s", extension_dir, filename);
+ int slash_suffix = IS_SLASH(extension_dir[extension_dir_len-1]);
+ /* Try as filename first */
+ if (slash_suffix) {
+ spprintf(&libpath, 0, "%s%s", extension_dir, filename); /* SAFE */
} 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);
efree(libpath);
}
diff --git a/php.ini-development b/php.ini-development
index f04277c676..8ba304b8c0 100644
--- a/php.ini-development
+++ b/php.ini-development
@@ -860,64 +860,63 @@ default_socket_timeout = 60
; If you wish to have an extension loaded automatically, use the following
; syntax:
;
-; extension=modulename.extension
+; extension=modulename
;
-; For example, on Windows:
+; For example:
;
-; extension=mysqli.dll
-;
-; ... or under UNIX:
-;
-; extension=mysqli.so
-;
-; ... or with a path:
+; extension=mysqli
+;
+; 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=/path/to/extension/mysqli.so
;
-; If you only provide the name of the extension, PHP will look for it in its
-; default extension directory.
+; Note : The syntax used in previous PHP versions ('extension=<ext>.so' and
+; '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.
+;
+; Notes for Windows environments :
;
-; Windows Extensions
-; 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+)
-; extension folders as well as the separate PECL DLL download (PHP 5+).
-; Be sure to appropriately set the extension_dir directive.
+; - 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+).
+; Be sure to appropriately set the extension_dir directive.
;
-;extension=php_bz2.dll
-;extension=php_curl.dll
-;extension=php_fileinfo.dll
-;extension=php_ftp.dll
-;extension=php_gd2.dll
-;extension=php_gettext.dll
-;extension=php_gmp.dll
-;extension=php_intl.dll
-;extension=php_imap.dll
-;extension=php_interbase.dll
-;extension=php_ldap.dll
-;extension=php_mbstring.dll
-;extension=php_exif.dll ; Must be after mbstring as it depends on it
-;extension=php_mysqli.dll
-;extension=php_oci8_12c.dll ; Use with Oracle Database 12c Instant Client
-;extension=php_openssl.dll
-;extension=php_pdo_firebird.dll
-;extension=php_pdo_mysql.dll
-;extension=php_pdo_oci.dll
-;extension=php_pdo_odbc.dll
-;extension=php_pdo_pgsql.dll
-;extension=php_pdo_sqlite.dll
-;extension=php_pgsql.dll
-;extension=php_shmop.dll
+;extension=bz2
+;extension=curl
+;extension=fileinfo
+;extension=gd2
+;extension=gettext
+;extension=gmp
+;extension=intl
+;extension=imap
+;extension=interbase
+;extension=ldap
+;extension=mbstring
+;extension=exif ; Must be after mbstring as it depends on it
+;extension=mysqli
+;extension=oci8_12c ; Use with Oracle Database 12c Instant Client
+;extension=openssl
+;extension=pdo_firebird
+;extension=pdo_mysql
+;extension=pdo_oci
+;extension=pdo_odbc
+;extension=pdo_pgsql
+;extension=pdo_sqlite
+;extension=pgsql
+;extension=shmop
; The MIBS data available in the PHP distribution must be installed.
; See http://www.php.net/manual/en/snmp.installation.php
-;extension=php_snmp.dll
-
-;extension=php_soap.dll
-;extension=php_sockets.dll
-;extension=php_sqlite3.dll
-;extension=php_tidy.dll
-;extension=php_xmlrpc.dll
-;extension=php_xsl.dll
+;extension=snmp
+
+;extension=soap
+;extension=sockets
+;extension=sqlite3
+;extension=tidy
+;extension=xmlrpc
+;extension=xsl
;;;;;;;;;;;;;;;;;;;
; Module Settings ;
diff --git a/php.ini-production b/php.ini-production
index 857ef6ee61..fb08287fa6 100644
--- a/php.ini-production
+++ b/php.ini-production
@@ -867,64 +867,63 @@ default_socket_timeout = 60
; If you wish to have an extension loaded automatically, use the following
; syntax:
;
-; extension=modulename.extension
+; extension=modulename
;
-; For example, on Windows:
+; For example:
;
-; extension=mysqli.dll
-;
-; ... or under UNIX:
-;
-; extension=mysqli.so
-;
-; ... or with a path:
+; extension=mysqli
+;
+; 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=/path/to/extension/mysqli.so
;
-; If you only provide the name of the extension, PHP will look for it in its
-; default extension directory.
+; Note : The syntax used in previous PHP versions ('extension=<ext>.so' and
+; '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.
+;
+; Notes for Windows environments :
;
-; Windows Extensions
-; 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+)
-; extension folders as well as the separate PECL DLL download (PHP 5+).
-; Be sure to appropriately set the extension_dir directive.
+; - 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+).
+; Be sure to appropriately set the extension_dir directive.
;
-;extension=php_bz2.dll
-;extension=php_curl.dll
-;extension=php_fileinfo.dll
-;extension=php_ftp.dll
-;extension=php_gd2.dll
-;extension=php_gettext.dll
-;extension=php_gmp.dll
-;extension=php_intl.dll
-;extension=php_imap.dll
-;extension=php_interbase.dll
-;extension=php_ldap.dll
-;extension=php_mbstring.dll
-;extension=php_exif.dll ; Must be after mbstring as it depends on it
-;extension=php_mysqli.dll
-;extension=php_oci8_12c.dll ; Use with Oracle Database 12c Instant Client
-;extension=php_openssl.dll
-;extension=php_pdo_firebird.dll
-;extension=php_pdo_mysql.dll
-;extension=php_pdo_oci.dll
-;extension=php_pdo_odbc.dll
-;extension=php_pdo_pgsql.dll
-;extension=php_pdo_sqlite.dll
-;extension=php_pgsql.dll
-;extension=php_shmop.dll
+;extension=bz2
+;extension=curl
+;extension=fileinfo
+;extension=gd2
+;extension=gettext
+;extension=gmp
+;extension=intl
+;extension=imap
+;extension=interbase
+;extension=ldap
+;extension=mbstring
+;extension=exif ; Must be after mbstring as it depends on it
+;extension=mysqli
+;extension=oci8_12c ; Use with Oracle Database 12c Instant Client
+;extension=openssl
+;extension=pdo_firebird
+;extension=pdo_mysql
+;extension=pdo_oci
+;extension=pdo_odbc
+;extension=pdo_pgsql
+;extension=pdo_sqlite
+;extension=pgsql
+;extension=shmop
; The MIBS data available in the PHP distribution must be installed.
; See http://www.php.net/manual/en/snmp.installation.php
-;extension=php_snmp.dll
-
-;extension=php_soap.dll
-;extension=php_sockets.dll
-;extension=php_sqlite3.dll
-;extension=php_tidy.dll
-;extension=php_xmlrpc.dll
-;extension=php_xsl.dll
+;extension=snmp
+
+;extension=soap
+;extension=sockets
+;extension=sqlite3
+;extension=tidy
+;extension=xmlrpc
+;extension=xsl
;;;;;;;;;;;;;;;;;;;
; Module Settings ;