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

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

Return to bug 10908