- # Perform a LDAP bind for the given username using the matched DN
- $res = $db->bind( $userldapentry->dn, password => $password );
- if ( $res->code ) {
- $debug and warn "LDAP bind failed as kohauser $userid: ". description($res);
- return 0;
- }
+ # Perform a LDAP search for the given username
+ my $search = search_method( $db, $userid )
+ or return 0; # warnings are in the sub
+ $userldapentry = $search->shift_entry;
+ $principal_name = $userldapentry->dn;
+ }
+ else {
+ $principal_name = $ldap->{principal_name};
+ if ( $principal_name and $principal_name =~ /\%/ ) {
+ $principal_name = sprintf( $principal_name, $userid );
+ }
+ else {
+ $principal_name = $userid;
+ }
+ }