tidy ldap code

This commit is contained in:
Oliver Gorwits
2013-08-24 15:26:11 +01:00
parent d0553e24d5
commit 91b985bf0a

View File

@@ -102,8 +102,8 @@ sub match_with_ldap {
my $result = _ldap_search($ldapuser, $attrs, $user, $pass); my $result = _ldap_search($ldapuser, $attrs, $user, $pass);
$ldapuser = $result->[0] if ($result->[0]); $ldapuser = $result->[0] if ($result->[0]);
} }
# otherwise, if we can't search and aren't using AD and then construct DN by # otherwise, if we can't search and aren't using AD and then construct DN
# appending base # by appending base
elsif ($ldapuser =~ m/=/) { elsif ($ldapuser =~ m/=/) {
$ldapuser = "$ldapuser,$conf->{base}"; $ldapuser = "$ldapuser,$conf->{base}";
} }
@@ -128,13 +128,11 @@ sub match_with_ldap {
sub _ldap_search { sub _ldap_search {
my ($filter, $attrs, $user, $pass) = @_; my ($filter, $attrs, $user, $pass) = @_;
my $conf = setting('ldap');
return undef unless defined($filter); return undef unless defined($filter);
return undef if (defined $attrs and ref [] ne ref $attrs); return undef if (defined $attrs and ref [] ne ref $attrs);
return unless setting('ldap') and ref {} eq ref setting('ldap');
my $conf = setting('ldap');
foreach my $server (@{$conf->{server}}) { foreach my $server (@{$conf->{server}}) {
my $opts = $conf->{opts} || {}; my $opts = $conf->{opts} || {};
my $ldap = Net::LDAP->new($server, %$opts) or next; my $ldap = Net::LDAP->new($server, %$opts) or next;