]>
git.proxmox.com Git - pve-access-control.git/blob - PVE/Auth/LDAP.pm
1 package PVE
::Auth
::LDAP
;
8 use base
qw(PVE::Auth::Plugin);
17 description
=> "LDAP base domain name",
19 pattern
=> '\w+=[^,]+(,\s*\w+=[^,]+)*',
24 description
=> "LDAP user attribute name",
36 server2
=> { optional
=> 1 },
39 port
=> { optional
=> 1 },
40 secure
=> { optional
=> 1 },
41 default => { optional
=> 1 },
42 comment
=> { optional
=> 1 },
46 my $authenticate_user_ldap = sub {
47 my ($config, $server, $username, $password) = @_;
49 my $default_port = $config->{secure
} ?
636: 389;
50 my $port = $config->{port
} ?
$config->{port
} : $default_port;
51 my $scheme = $config->{secure
} ?
'ldaps' : 'ldap';
52 my $conn_string = "$scheme://${server}:$port";
54 my $ldap = Net
::LDAP-
>new($conn_string, verify
=> 'none') || die "$@\n";
55 my $search = $config->{user_attr
} . "=" . $username;
56 my $result = $ldap->search( base
=> "$config->{base_dn}",
61 die "no entries returned\n" if !$result->entries;
62 my @entries = $result->entries;
63 my $res = $ldap->bind($entries[0]->dn, password
=> $password);
65 my $code = $res->code();
66 my $err = $res->error;
70 die "$err\n" if ($code);
73 sub authenticate_user
{
74 my ($class, $config, $realm, $username, $password) = @_;
76 eval { &$authenticate_user_ldap($config, $config->{server1
}, $username, $password); };
79 die $err if !$config->{server2
};
80 &$authenticate_user_ldap($config, $config->{server2
}, $username, $password);