Commit cd95eb70 authored by Francesc Guasch's avatar Francesc Guasch
Browse files

get LDAP dc base from the domain name

parent 05c27cd3
......@@ -4,21 +4,24 @@ use strict;
use warnings;
use Net::LDAP;
use Net::Domain qw(hostdomain);
our $LDAP;
our $BASE;
sub login {
my ($username, $password) = @_;
_init_ldap();
my $base = _dc_base();
my $search = $LDAP->search( # Search for the user
base => 'DC=casa,DC=guru',
base => $base,
scope => 'sub',
filter => "(&(uid=$username))",
attrs => ['dn']
);
die "not found" if not $search->count;
die "not found '$username' at '$base'" if not $search->count;
my $user_dn = $search->entry->dn;
......@@ -31,6 +34,17 @@ sub login {
return;
}
sub _dc_base {
# TODO: from config
my $base = '';
for my $part (split /\./,hostdomain()) {
$base .= "," if $base;
$base .= "dc=$part";
}
return $base;
}
sub _init_ldap {
# TODO ping ldap and reconnect
return if $LDAP;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment