]> granicus.if.org Git - php/commitdiff
Allow loading PHP and Zend extensions by name
authorFrancois Laupretre <francois@tekwire.net>
Thu, 28 Jan 2016 18:50:18 +0000 (19:50 +0100)
committerSara Golemon <pollita@php.net>
Thu, 22 Jun 2017 16:58:15 +0000 (12:58 -0400)
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

NEWS
ext/standard/dl.c
main/php_ini.c
php.ini-development
php.ini-production

diff --git a/NEWS b/NEWS
index 3984a5949a0ecc953602fea4ffdab596228256f0..2496664ddf91cbea8a0bab283a42e593234be9b7 100644 (file)
--- 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:
index f7933855b0a25322b4901aa63661c02d58e76b42..35a71ab2a57aaeac27c24af818b94608990bdf11 100644 (file)
@@ -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 */
        }
index 75b1695ec4b3982a31153210c7c5a494653e84e7..a378ce1926d414f4159cadbfb80255d62855fea4 100644 (file)
@@ -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);
        }
index f04277c6764214e1c42aec6b151dfb70f97ffa7a..8ba304b8c0228ffce364627a0047240f73b01608 100644 (file)
@@ -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 ;
index 857ef6ee61905e2504442456a71a992428d7a79f..fb08287fa6e11ed32b49f23a2a102538a1dfe6da 100644 (file)
@@ -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 ;