Topic on Extension talk:LDAP Authentication

PHP 5.6.10 updated to PHP 5.6.11 causes LdapAuthentication module to stop working

12
CipherWizard (talkcontribs)

I am having an issue with the LdapAuthentication module working on PHP 5.6.11. I know it was working fine on PHP 5.6.10.

I am using the docker container synctree/mediawiki as my base. I then have updated mediawiki from 2.24 to 2.25 and installed the LdapAuthentication module.

The synctree/mediawiki container uses the official php container as it's base. On July 10, 2015 they updated this container from php 2.6.10 to php 2.6.11. This is when I noticed the LdapAuthentication module stop working.

I am using this download of MediaWiki:

https://releases.wikimedia.org/mediawiki/1.25/mediawiki-1.25.1.tar.gz

I am using this download of LdapAuthentication module:

https://extdist.wmflabs.org/dist/extensions/LdapAuthentication-REL1_25-d4db6f0.tar.gz

The error message I am getting from the error log:

PHP's LDAP connect method returned null, this likely implies a misconfiguration of the plugin.

When I change line 605 in extensions/LdapAuthentication/LdapAuthentication.php from :

$this->ldapconn = LdapAuthenticationPlugin::ldap_connect( $servers );

to:

$this->ldapconn = LdapAuthenticationPlugin::ldap_connect( "ldap://wiki_ldap:389" );

The connection works. ("ldap://wiki_ldap:389" is what is displayed as the value of $servers on the debug line on linenumber 602)

86.110.8.131 (talkcontribs)

Real error is two lines above:

Instead of

$servers = rtrim( $servers );

Must be

$servers = lrtrim( $servers );

91.64.85.78 (talkcontribs)

Same here after Upgrade to PHP 5.6.11. Entering the Server as string as described above works.

This post was hidden by 212.44.128.130 (history)
194.176.105.7 (talkcontribs)

Yes exact same problem. Upgraded to 5.6.11

changing from "rtrim" to "trim" on line 600 in extensions/LdapAuthentication/LdapAuthentication.php solved the issue.

thank you CipherWizard and 91.64.85.78

129.94.63.39 (talkcontribs)

Yes I have seen this problem when attempting to upgrade from PHP 5.4.44 to 5.6.12. The fix described here works. Leaving the fix in place and rolling back PHP version to 5.4.44 did not cause any issues, I think the extension should be patched accordingly.

Uckelman (talkcontribs)

I can confirm that changing 'rtrim' to 'trim' at LdapAuthentication.php:600 fixed the problem which started after we upgraded PHP.

130.75.68.136 (talkcontribs)

I had the same Issue and changing 'rtrim' to 'trim' at LdapAuthentication.php:600 fixed the problem for me. Thx

202.81.18.30 (talkcontribs)

Another "vote" for this fix. Could not get LDAP authentication to work at all -- thank you CipherWizard and 91.64.85.78, changing LdapAuthentication.php as described worked.

198.91.70.120 (talkcontribs)

Put another "me too" on the trim/rtrim fix. I've been tearing my hair out over this one for a day and a half assuming I had made a mistake in my configuration.

Schrotti12 (talkcontribs)

Finally my wiki is up and running again. Thanks for the hint!

Is it only me or is it time to update the plugin on GIT? Can somebody take care of that?

I mean the plugin is great and I can live with updating it manually every time I'm going to install a wiki but it would be great to keep it up to date. Thanks for the effort.

Foss lover (talkcontribs)

I figured this out. This is due to the way PHP 5.6's ldap_connect function works and the way the LDAP extension is using it.

There is a bug in the way PHP handles URIs: https://www.netways.org/issues/2931

To fix this, you must edit the file LdapAuthentication.php that is part of the extension download. Replace the code:

        public static function ldap_connect( $hostname=null, $port=389 ) {
                wfSuppressWarnings();
                $ret = ldap_connect( $hostname, $port );
                wfRestoreWarnings();
                return $ret;

with:

       public static function ldap_connect( $hostname=null, $port=389 ) {
               wfSuppressWarnings();
               $ldap_server = preg_replace('/:[0-9]*$/', , $hostname);
               if( preg_match( '/[0-9]*$/', $hostname, $port_array ) ) {
                           $port = $port_array[0];
               }
               $ret = ldap_connect( $ldap_server, $port );
               wfRestoreWarnings();
               return $ret;
       }
Reply to "PHP 5.6.10 updated to PHP 5.6.11 causes LdapAuthentication module to stop working"