View | Details | Raw Unified | Return to bug 10908
Collapse All | Expand All

(-)a/C4/Auth_with_ldap.pm (-20 / +41 lines)
Lines 111-136 sub checkpw_ldap { Link Here
111
	#$debug and $db->debug(5);
111
	#$debug and $db->debug(5);
112
    my $userldapentry;
112
    my $userldapentry;
113
113
114
  if ( $ldap->{auth_by_bind} ) {
114
    if ( $ldap->{auth_by_bind} ) {
115
    # Perform an anonymous bind
115
        my $principal_name;
116
    my $res = $db->bind;
116
        if ( $ldap->{anonymous_bind} ) {
117
    if ( $res->code ) {
117
118
      $debug and warn "Anonymous LDAP bind failed: ". description($res);
118
            # Perform an anonymous bind
119
      return 0;
119
            my $res = $db->bind;
120
    }
120
            if ( $res->code ) {
121
121
                warn "Anonymous LDAP bind failed: " . description($res);
122
    # Perform a LDAP search for the given username
122
                return 0;
123
    my $search = search_method($db, $userid) or return 0;   # warnings are in the sub
123
            }
124
    $userldapentry = $search->shift_entry;
124
125
125
            # Perform a LDAP search for the given username
126
    # Perform a LDAP bind for the given username using the matched DN
126
            my $search = search_method( $db, $userid )
127
    $res = $db->bind( $userldapentry->dn, password => $password );
127
              or return 0;    # warnings are in the sub
128
    if ( $res->code ) {
128
            $userldapentry = $search->shift_entry;
129
      $debug and warn "LDAP bind failed as kohauser $userid: ". description($res);
129
            $principal_name = $userldapentry->dn;
130
      return 0;
130
        }
131
    }
131
        else {
132
            $principal_name = $ldap->{principal_name};
133
            if ( $principal_name and $principal_name =~ /\%/ ) {
134
                $principal_name = sprintf( $principal_name, $userid );
135
            }
136
            else {
137
                $principal_name = $userid;
138
            }
139
        }
132
140
133
  } else {
141
        # Perform a LDAP bind for the given username using the matched DN
142
        my $res = $db->bind( $principal_name, password => $password );
143
        if ( $res->code ) {
144
            warn "LDAP bind failed as kohauser $userid: " . description($res);
145
            return 0;
146
        }
147
        if ( !defined($userldapentry)
148
            && ( $config{update} or $config{replicate} ) )
149
        {
150
            my $search = search_method( $db, $userid ) or return 0;
151
            $userldapentry = $search->shift_entry;
152
        }
153
    } else {
134
		my $res = ($config{anonymous}) ? $db->bind : $db->bind($ldapname, password=>$ldappassword);
154
		my $res = ($config{anonymous}) ? $db->bind : $db->bind($ldapname, password=>$ldappassword);
135
		if ($res->code) {		# connection refused
155
		if ($res->code) {		# connection refused
136
			warn "LDAP bind failed as ldapuser " . ($ldapname || '[ANONYMOUS]') . ": " . description($res);
156
			warn "LDAP bind failed as ldapuser " . ($ldapname || '[ANONYMOUS]') . ": " . description($res);
Lines 421-426 Example XML stanza for LDAP configuration in KOHA_CONF. Link Here
421
    <update>1</update>             <!-- update existing users in Koha database -->
441
    <update>1</update>             <!-- update existing users in Koha database -->
422
    <auth_by_bind>0</auth_by_bind> <!-- set to 1 to authenticate by binding instead of
442
    <auth_by_bind>0</auth_by_bind> <!-- set to 1 to authenticate by binding instead of
423
                                        password comparison, e.g., to use Active Directory -->
443
                                        password comparison, e.g., to use Active Directory -->
444
    <anonymous_bind>0</anonymous_bind> <!-- set to 1 if users should be searched using
445
                                            an anonymous bind, even when auth_by_bind is on -->
424
    <mapping>                  <!-- match koha SQL field names to your LDAP record field names -->
446
    <mapping>                  <!-- match koha SQL field names to your LDAP record field names -->
425
      <firstname    is="givenname"      ></firstname>
447
      <firstname    is="givenname"      ></firstname>
426
      <surname      is="sn"             ></surname>
448
      <surname      is="sn"             ></surname>
427
- 

Return to bug 10908