Skip to content

Commit

Permalink
Allow loading PHP and Zend extensions by name
Browse files Browse the repository at this point in the history
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
  • Loading branch information
flaupretre authored and sgolemon committed Jun 22, 2017
1 parent 0f15a03 commit fe5c8f2
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 105 deletions.
6 changes: 6 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
33 changes: 29 additions & 4 deletions ext/standard/dl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 */
}
Expand Down
38 changes: 33 additions & 5 deletions main/php_ini.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
95 changes: 47 additions & 48 deletions php.ini-development
Original file line number Diff line number Diff line change
Expand Up @@ -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 ;
Expand Down
95 changes: 47 additions & 48 deletions php.ini-production
Original file line number Diff line number Diff line change
Expand Up @@ -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 ;
Expand Down

0 comments on commit fe5c8f2

Please sign in to comment.