Bug 10384: fall back to normal authentication if LDAP server is not available
authorFridolyn SOMERS <fridolyn.somers@biblibre.com>
Fri, 31 May 2013 08:17:08 +0000 (10:17 +0200)
committerGalen Charlton <gmc@esilibrary.com>
Fri, 5 Jul 2013 16:08:46 +0000 (16:08 +0000)
This fixes a bug where, assuming LDAP authentication is enabled, if a user
tries to log in while the LDAP server is down, the following fatal error
is displayed:

Can't call method "bind" on an undefined value at C4/Auth_with_ldap.pm line 134, <DATA> line 558.

This patch catches this error to allow normal authentication when LDAP connexion fails.

Test plan :
- Configure LDAP connexion with a host not having LDAP. ie :
 <useldapserver>1</useldapserver>
 <ldapserver id="ldapserver">
    <hostname>localhost</hostname>
    <base>dc=test,dc=com</base>
    <user>cn=Manager,dc=test,dc=com</user>
    <pass>passwd</pass>
    <replicate>0</replicate>
    <update>0</update>
    <auth_by_bind>0</auth_by_bind>
    <mapping>
      <firstname    is="givenname"      ></firstname>
      <surname      is="sn"             ></surname>
      <branchcode   is="branch"         >MAIN</branchcode>
      <userid       is="uid"            ></userid>
      <password     is="userpassword"   ></password>
      <email        is="mail"           ></email>
      <categorycode is="employeetype"   >PT</categorycode>
    </mapping>
 </ldapserver>
- Try to connect with mysql user (defined in koha-conf.xml)
- Try to connect with a user defined in borrowers
You may try to connect with working LDAP connexion

Signed-off-by: Chris Cormack <chris@bigballofwax.co.nz>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>

C4/Auth_with_ldap.pm

index 1f2f617..6143c9f 100644 (file)
@@ -103,6 +103,11 @@ sub checkpw_ldap {
     my ($dbh, $userid, $password) = @_;
     my @hosts = split(',', $prefhost);
     my $db = Net::LDAP->new(\@hosts);
+    unless ( $db ) {
+        warn "LDAP connexion failed";
+        return 0;
+    }
+
        #$debug and $db->debug(5);
     my $userldapentry;