Some fixes with multi or single valued attr
This commit is contained in:
parent
57a6ff5e38
commit
4bf1cfa163
|
@ -301,13 +301,13 @@ DOMAIN: foreach my $domain ( keys $conf->{domains} ) {
|
|||
my $ext_users = ldap2hashref(
|
||||
$ext_user_search,
|
||||
$conf->{domains}->{$domain}->{users}->{key},
|
||||
( $conf->{domains}->{$domain}->{users}->{alias_attr} ),
|
||||
@single
|
||||
[ $conf->{domains}->{$domain}->{users}->{alias_attr} ],
|
||||
\@single
|
||||
);
|
||||
my $zim_users = ldap2hashref(
|
||||
$zim_user_search,
|
||||
'uid',
|
||||
('mail')
|
||||
[ 'mail' ]
|
||||
);
|
||||
|
||||
# First loop : Check users which exist in external LDAP but not in Zimbra
|
||||
|
@ -509,16 +509,16 @@ DOMAIN: foreach my $domain ( keys $conf->{domains} ) {
|
|||
my $ext_groups = ldap2hashref(
|
||||
$ext_group_search,
|
||||
$conf->{domains}->{$domain}->{groups}->{key},
|
||||
(
|
||||
[
|
||||
$conf->{domains}->{$domain}->{groups}->{members_attr},
|
||||
$conf->{domains}->{$domain}->{groups}->{alias_attr}
|
||||
),
|
||||
@single
|
||||
],
|
||||
\@single
|
||||
);
|
||||
my $zim_dl = ldap2hashref(
|
||||
$zim_dl_search,
|
||||
'uid',
|
||||
('zimbraMailForwardingAddress', 'mail')
|
||||
[ 'zimbraMailForwardingAddress', 'mail' ]
|
||||
);
|
||||
|
||||
# Build a dn2id hashref to lookup users or groups by their DN
|
||||
|
@ -752,20 +752,26 @@ sub handle_error {
|
|||
# It'll return a hashref. The key will be unaccentuated and lower cased.
|
||||
|
||||
sub ldap2hashref {
|
||||
my ( $search, $key, @want_array, @want_single ) = @_;
|
||||
my $return = {};
|
||||
my $search = shift;
|
||||
my $key = shift;
|
||||
my $want_array = shift;
|
||||
my $want_single = shift;
|
||||
my $return = {};
|
||||
|
||||
$want_array ||= [];
|
||||
$want_single ||= [];
|
||||
|
||||
foreach my $entry ( $search->entries ) {
|
||||
$return->{unidecode( lc $entry->get_value($key) )}->{dn} = $entry->dn;
|
||||
foreach my $attr ( $entry->attributes ) {
|
||||
my @values = $entry->get_value($attr);
|
||||
if ( grep { $attr eq $_ } @want_array ) {
|
||||
if ( grep { $attr eq $_ } @{ $want_array } ) {
|
||||
$return->{unidecode( lc $entry->get_value($key) )}->{$attr} = \@values;
|
||||
} elsif ( grep { $attr eq $_ } @want_single ) {
|
||||
} elsif ( grep { $attr eq $_ } @{ $want_single } ) {
|
||||
$return->{unidecode( lc $entry->get_value($key) )}->{$attr} = $values[0];
|
||||
} else {
|
||||
$return->{unidecode( lc $entry->get_value($key) )}->{$attr} = ( scalar @values == 1 ) ?
|
||||
\@values : $values[0];
|
||||
$values[0] : \@values;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue