Bug 9299: fix LDAP login breakage when ExtendedPatronAttributes is on

To test:
- Configure an LDAP server and $KOHA_CONF, etc.
- Make sure ExtendedPatronAttributes is defined and that
  there is no attribute defined that is specified to be
  a unique ID.
- Try to log in using an account originating from the
  LDAP directory.
- You will got a software error:
  Can't use an undefined value as an ARRAY reference at
  /home/koha/src/C4/Auth_with_ldap.pm line 183.
- Apply the patch.
- Try to log in again; this time it should work.

Signed-off-by: Nuño López Ansótegui <nunyo@masmedios.com>
Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
This commit is contained in:
Srdjan 2013-06-05 16:34:29 +12:00 committed by Galen Charlton
parent 40a150f94e
commit 4d75243e27
1 changed files with 17 additions and 21 deletions

View File

@ -170,29 +170,25 @@ sub checkpw_ldap {
} else {
return 0; # B2, D2
}
if (C4::Context->preference('ExtendedPatronAttributes') && $borrowernumber && ($config{update} ||$config{replicate})) {
my $extended_patron_attributes;
if (C4::Context->preference('ExtendedPatronAttributes') && $borrowernumber && ($config{update} ||$config{replicate})) {
my @extended_patron_attributes;
foreach my $attribute_type ( C4::Members::AttributeTypes::GetAttributeTypes() ) {
my $code = $attribute_type->{code};
if ( exists($borrower{$code}) && $borrower{$code} !~ m/^\s*$/ ) { # skip empty values
push @$extended_patron_attributes, { code => $code, value => $borrower{$code} };
}
my $code = $attribute_type->{code};
if ( exists($borrower{$code}) && $borrower{$code} !~ m/^\s*$/ ) { # skip empty values
push @extended_patron_attributes, { code => $code, value => $borrower{$code} };
}
}
my @errors;
#Check before add
for (my $i; $i< scalar(@$extended_patron_attributes)-1;$i++) {
my $attr=$extended_patron_attributes->[$i];
unless (C4::Members::Attributes::CheckUniqueness($attr->{code}, $attr->{value}, $borrowernumber)) {
unshift @errors, $i;
warn "ERROR_extended_unique_id_failed $attr->{code} $attr->{value}";
}
}
#Removing erroneous attributes
foreach my $index (@errors){
@$extended_patron_attributes=splice(@$extended_patron_attributes,$index,1);
}
C4::Members::Attributes::SetBorrowerAttributes($borrowernumber, $extended_patron_attributes);
}
#Check before add
my @unique_attr;
foreach my $attr ( @extended_patron_attributes ) {
if (C4::Members::Attributes::CheckUniqueness($attr->{code}, $attr->{value}, $borrowernumber)) {
push @unique_attr, $attr;
} else {
warn "ERROR_extended_unique_id_failed $attr->{code} $attr->{value}";
}
}
C4::Members::Attributes::SetBorrowerAttributes($borrowernumber, \@unique_attr);
}
return(1, $cardnumber, $userid);
}