]>
git.proxmox.com Git - pve-access-control.git/blob - AD.pm
eb502f7bbf3a3348dc8fb44568fe5c1af641ea04
8 use base
qw(PVE::Auth::Plugin);
17 description
=> "Server IP address (or DNS name)",
19 pattern
=> '[\w\d]+(.[\w\d]+)*',
23 description
=> "Fallback Server IP address (or DNS name)",
26 pattern
=> '[\w\d]+(.[\w\d]+)*',
30 description
=> "Use secure LDAPS protocol.",
36 description
=> "Use this as default realm",
41 description
=> "Description.",
47 description
=> "Server port.",
54 description
=> "AD domain name",
66 server2
=> { optional
=> 1 },
68 port
=> { optional
=> 1 },
69 secure
=> { optional
=> 1 },
70 default => { optional
=> 1 },,
71 comment
=> { optional
=> 1 },
75 my $authenticate_user_ad = sub {
76 my ($config, $server, $username, $password) = @_;
78 my $default_port = $config->{secure
} ?
636: 389;
79 my $port = $config->{port
} ?
$config->{port
} : $default_port;
80 my $scheme = $config->{secure
} ?
'ldaps' : 'ldap';
81 my $conn_string = "$scheme://${server}:$port";
83 my $ldap = Net
::LDAP-
>new($server) || die "$@\n";
85 $username = "$username\@$config->{domain}"
86 if $username !~ m/@/ && $config->{domain
};
88 my $res = $ldap->bind($username, password
=> $password);
90 my $code = $res->code();
91 my $err = $res->error;
95 die "$err\n" if ($code);
98 sub authenticate_user
{
99 my ($class, $config, $realm, $username, $password) = @_;
101 eval { &$authenticate_user_ad($config, $config->{server1
}, $username, $password); };
104 die $err if !$config->{server2
};
105 &$authenticate_user_ad($config, $config->{server2
}, $username, $password);