Errors/warning on PHP 5.5 #33

Open
opened 2015-09-25 04:55:09 +00:00 by deon · 0 comments
deon commented 2015-09-25 04:55:09 +00:00 (Migrated from gitlab.dege.au)

Hi, There are two issues related to phpldapadmin + python 5.5.

The first one is, that lib/functions.php defines a function named 'password_hash', but such function appears in PHP 5.5 which lead to name clash and error. See: http://www.php.net/manual/en/function.password-hash.php

The second issue is related to the '/e' modifier of preg_replace, which is deprecated in PHP 5.5. See http://www.php.net/manual/en/function.preg-replace.php.

Please consider the following patch:

diff -ur a/lib/ds_ldap.php b/lib/ds_ldap.php
--- a/lib/ds_ldap.php   2013-06-03 01:37:17.000000000 +0200
+++ b/lib/ds_ldap.php   2013-06-03 03:28:19.000000000 +0200
@@ -1117,12 +1117,14 @@
                if (is_array($dn)) {
                        $a = array();
                        foreach ($dn as $key => $rdn)
-                               $a[$key] = preg_replace('/\\\([0-9A-Fa-f]{2})/e',"''.chr(hexdec('\\1')).''",$rdn);
+                               $a[$key] = preg_replace_callback('/\\\([0-9A-Fa-f]{2})/',
+                                       function ($matches) { return chr(hexdec($matches[1])); }, $rdn);
 
                        return $a;
 
                } else
-                       return preg_replace('/\\\([0-9A-Fa-f]{2})/e',"''.chr(hexdec('\\1')).''",$dn);
+                       return preg_replace_callback('/\\\([0-9A-Fa-f]{2})/',
+                                       function ($matches) { return chr(hexdec($matches[1])); }, $dn);
        }
 
        public function getRootDSE($method=null) {
diff -ur a/lib/functions.php b/lib/functions.php
--- a/lib/functions.php 2013-06-03 01:30:25.000000000 +0200
+++ b/lib/functions.php 2013-06-03 02:01:12.000000000 +0200
@@ -2126,7 +2126,7 @@
  *        crypt, ext_des, md5crypt, blowfish, md5, sha, smd5, ssha, or clear.
  * @return string The hashed password.
  */
-function password_hash($password_clear,$enc_type) {
+function pla_password_hash($password_clear,$enc_type) {
        if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
                debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs);
 
@@ -2307,7 +2307,7 @@
 
                # SHA crypted passwords
                case 'sha':
-                       if (strcasecmp(password_hash($plainpassword,'sha'),'{SHA}'.$cryptedpassword) == 0)
+                       if (strcasecmp(pla_password_hash($plainpassword,'sha'),'{SHA}'.$cryptedpassword) == 0)
                                return true;
                        else
                                return false;
@@ -2316,7 +2316,7 @@
 
                # MD5 crypted passwords
                case 'md5':
-                       if( strcasecmp(password_hash($plainpassword,'md5'),'{MD5}'.$cryptedpassword) == 0)
+                       if( strcasecmp(pla_password_hash($plainpassword,'md5'),'{MD5}'.$cryptedpassword) == 0)
                                return true;
                        else
                                return false;
@@ -2545,12 +2545,14 @@
                $a = array();
 
                foreach ($dn as $key => $rdn)
-                       $a[$key] = preg_replace('/\\\([0-9A-Fa-f]{2})/e',"''.chr(hexdec('\\1')).''",$rdn);
+                       $a[$key] = preg_replace_callback('/\\\([0-9A-Fa-f]{2})/', 
+                               function ($matches) { return chr(hexdec($matches[1])); }, $rdn );
 
                return $a;
 
        } else {
-               return preg_replace('/\\\([0-9A-Fa-f]{2})/e',"''.chr(hexdec('\\1')).''",$dn);
+               return preg_replace_callback('/\\\([0-9A-Fa-f]{2})/',
+                               function ($matches) { return chr(hexdec($matches[1])); }, $dn);
        }
 }

Ah, and this patch is against PLA 1.2.2.

Hi, There are two issues related to phpldapadmin + python 5.5. The first one is, that lib/functions.php defines a function named 'password_hash', but such function appears in PHP 5.5 which lead to name clash and error. See: http://www.php.net/manual/en/function.password-hash.php The second issue is related to the '/e' modifier of preg_replace, which is deprecated in PHP 5.5. See http://www.php.net/manual/en/function.preg-replace.php. Please consider the following patch: ```diff diff -ur a/lib/ds_ldap.php b/lib/ds_ldap.php --- a/lib/ds_ldap.php 2013-06-03 01:37:17.000000000 +0200 +++ b/lib/ds_ldap.php 2013-06-03 03:28:19.000000000 +0200 @@ -1117,12 +1117,14 @@ if (is_array($dn)) { $a = array(); foreach ($dn as $key => $rdn) - $a[$key] = preg_replace('/\\\([0-9A-Fa-f]{2})/e',"''.chr(hexdec('\\1')).''",$rdn); + $a[$key] = preg_replace_callback('/\\\([0-9A-Fa-f]{2})/', + function ($matches) { return chr(hexdec($matches[1])); }, $rdn); return $a; } else - return preg_replace('/\\\([0-9A-Fa-f]{2})/e',"''.chr(hexdec('\\1')).''",$dn); + return preg_replace_callback('/\\\([0-9A-Fa-f]{2})/', + function ($matches) { return chr(hexdec($matches[1])); }, $dn); } public function getRootDSE($method=null) { diff -ur a/lib/functions.php b/lib/functions.php --- a/lib/functions.php 2013-06-03 01:30:25.000000000 +0200 +++ b/lib/functions.php 2013-06-03 02:01:12.000000000 +0200 @@ -2126,7 +2126,7 @@ * crypt, ext_des, md5crypt, blowfish, md5, sha, smd5, ssha, or clear. * @return string The hashed password. */ -function password_hash($password_clear,$enc_type) { +function pla_password_hash($password_clear,$enc_type) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); @@ -2307,7 +2307,7 @@ # SHA crypted passwords case 'sha': - if (strcasecmp(password_hash($plainpassword,'sha'),'{SHA}'.$cryptedpassword) == 0) + if (strcasecmp(pla_password_hash($plainpassword,'sha'),'{SHA}'.$cryptedpassword) == 0) return true; else return false; @@ -2316,7 +2316,7 @@ # MD5 crypted passwords case 'md5': - if( strcasecmp(password_hash($plainpassword,'md5'),'{MD5}'.$cryptedpassword) == 0) + if( strcasecmp(pla_password_hash($plainpassword,'md5'),'{MD5}'.$cryptedpassword) == 0) return true; else return false; @@ -2545,12 +2545,14 @@ $a = array(); foreach ($dn as $key => $rdn) - $a[$key] = preg_replace('/\\\([0-9A-Fa-f]{2})/e',"''.chr(hexdec('\\1')).''",$rdn); + $a[$key] = preg_replace_callback('/\\\([0-9A-Fa-f]{2})/', + function ($matches) { return chr(hexdec($matches[1])); }, $rdn ); return $a; } else { - return preg_replace('/\\\([0-9A-Fa-f]{2})/e',"''.chr(hexdec('\\1')).''",$dn); + return preg_replace_callback('/\\\([0-9A-Fa-f]{2})/', + function ($matches) { return chr(hexdec($matches[1])); }, $dn); } } ``` Ah, and this patch is against PLA 1.2.2.
Sign in to join this conversation.
No Label
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: deon/phpldapadmin#33
No description provided.