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(
|
my $ext_users = ldap2hashref(
|
||||||
$ext_user_search,
|
$ext_user_search,
|
||||||
$conf->{domains}->{$domain}->{users}->{key},
|
$conf->{domains}->{$domain}->{users}->{key},
|
||||||
( $conf->{domains}->{$domain}->{users}->{alias_attr} ),
|
[ $conf->{domains}->{$domain}->{users}->{alias_attr} ],
|
||||||
@single
|
\@single
|
||||||
);
|
);
|
||||||
my $zim_users = ldap2hashref(
|
my $zim_users = ldap2hashref(
|
||||||
$zim_user_search,
|
$zim_user_search,
|
||||||
'uid',
|
'uid',
|
||||||
('mail')
|
[ 'mail' ]
|
||||||
);
|
);
|
||||||
|
|
||||||
# First loop : Check users which exist in external LDAP but not in Zimbra
|
# 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(
|
my $ext_groups = ldap2hashref(
|
||||||
$ext_group_search,
|
$ext_group_search,
|
||||||
$conf->{domains}->{$domain}->{groups}->{key},
|
$conf->{domains}->{$domain}->{groups}->{key},
|
||||||
(
|
[
|
||||||
$conf->{domains}->{$domain}->{groups}->{members_attr},
|
$conf->{domains}->{$domain}->{groups}->{members_attr},
|
||||||
$conf->{domains}->{$domain}->{groups}->{alias_attr}
|
$conf->{domains}->{$domain}->{groups}->{alias_attr}
|
||||||
),
|
],
|
||||||
@single
|
\@single
|
||||||
);
|
);
|
||||||
my $zim_dl = ldap2hashref(
|
my $zim_dl = ldap2hashref(
|
||||||
$zim_dl_search,
|
$zim_dl_search,
|
||||||
'uid',
|
'uid',
|
||||||
('zimbraMailForwardingAddress', 'mail')
|
[ 'zimbraMailForwardingAddress', 'mail' ]
|
||||||
);
|
);
|
||||||
|
|
||||||
# Build a dn2id hashref to lookup users or groups by their DN
|
# 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.
|
# It'll return a hashref. The key will be unaccentuated and lower cased.
|
||||||
|
|
||||||
sub ldap2hashref {
|
sub ldap2hashref {
|
||||||
my ( $search, $key, @want_array, @want_single ) = @_;
|
my $search = shift;
|
||||||
my $return = {};
|
my $key = shift;
|
||||||
|
my $want_array = shift;
|
||||||
|
my $want_single = shift;
|
||||||
|
my $return = {};
|
||||||
|
|
||||||
|
$want_array ||= [];
|
||||||
|
$want_single ||= [];
|
||||||
|
|
||||||
foreach my $entry ( $search->entries ) {
|
foreach my $entry ( $search->entries ) {
|
||||||
$return->{unidecode( lc $entry->get_value($key) )}->{dn} = $entry->dn;
|
$return->{unidecode( lc $entry->get_value($key) )}->{dn} = $entry->dn;
|
||||||
foreach my $attr ( $entry->attributes ) {
|
foreach my $attr ( $entry->attributes ) {
|
||||||
my @values = $entry->get_value($attr);
|
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;
|
$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];
|
$return->{unidecode( lc $entry->get_value($key) )}->{$attr} = $values[0];
|
||||||
} else {
|
} else {
|
||||||
$return->{unidecode( lc $entry->get_value($key) )}->{$attr} = ( scalar @values == 1 ) ?
|
$return->{unidecode( lc $entry->get_value($key) )}->{$attr} = ( scalar @values == 1 ) ?
|
||||||
\@values : $values[0];
|
$values[0] : \@values;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue