]>
git.proxmox.com Git - pve-access-control.git/blob - PVE/Auth/AD.pm
9 use base
qw(PVE::Auth::Plugin);
18 description
=> "Server IP address (or DNS name)",
24 description
=> "Fallback Server IP address (or DNS name)",
31 description
=> "Use secure LDAPS protocol.",
37 description
=> "Use this as default realm",
42 description
=> "Description.",
48 description
=> "Server port.",
55 description
=> "AD domain name",
61 tfa
=> PVE
::JSONSchema
::get_standard_option
('tfa'),
68 server2
=> { optional
=> 1 },
70 port
=> { optional
=> 1 },
71 secure
=> { optional
=> 1 },
72 default => { optional
=> 1 },,
73 comment
=> { optional
=> 1 },
74 tfa
=> { optional
=> 1 },
78 my $authenticate_user_ad = sub {
79 my ($config, $server, $username, $password) = @_;
81 my $default_port = $config->{secure
} ?
636: 389;
82 my $port = $config->{port
} ?
$config->{port
} : $default_port;
83 my $scheme = $config->{secure
} ?
'ldaps' : 'ldap';
84 $server = "[$server]" if Net
::IP
::ip_is_ipv6
($server);
85 my $conn_string = "$scheme://${server}:$port";
87 my $ldap = Net
::LDAP-
>new($conn_string) || die "$@\n";
89 $username = "$username\@$config->{domain}"
90 if $username !~ m/@/ && $config->{domain
};
92 my $res = $ldap->bind($username, password
=> $password);
94 my $code = $res->code();
95 my $err = $res->error;
99 die "$err\n" if ($code);
102 sub authenticate_user
{
103 my ($class, $config, $realm, $username, $password) = @_;
105 eval { &$authenticate_user_ad($config, $config->{server1
}, $username, $password); };
108 die $err if !$config->{server2
};
109 &$authenticate_user_ad($config, $config->{server2
}, $username, $password);