]>
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 },
75 verify
=> { optional
=> 1 },
76 capath
=> { optional
=> 1 },
77 cert
=> { optional
=> 1 },
78 certkey
=> { optional
=> 1 },
82 my $authenticate_user_ad = sub {
83 my ($config, $server, $username, $password) = @_;
85 my $default_port = $config->{secure
} ?
636: 389;
86 my $port = $config->{port
} ?
$config->{port
} : $default_port;
87 my $scheme = $config->{secure
} ?
'ldaps' : 'ldap';
88 $server = "[$server]" if Net
::IP
::ip_is_ipv6
($server);
89 my $conn_string = "$scheme://${server}:$port";
92 if ($config->{verify
}) {
93 $ad_args{verify
} = 'require';
94 if (defined(my $cert = $config->{cert
})) {
95 $ad_args{clientcert
} = $cert;
97 if (defined(my $key = $config->{certkey
})) {
98 $ad_args{clientkey
} = $key;
100 if (defined(my $capath = $config->{capath
})) {
102 $ad_args{capath
} = $capath;
104 $ad_args{cafile
} = $capath;
107 } elsif (defined($config->{verify
})) {
108 $ad_args{verify
} = 'none';
111 my $ldap = Net
::LDAP-
>new($conn_string, %ad_args) || die "$@\n";
113 $username = "$username\@$config->{domain}"
114 if $username !~ m/@/ && $config->{domain
};
116 my $res = $ldap->bind($username, password
=> $password);
118 my $code = $res->code();
119 my $err = $res->error;
123 die "$err\n" if ($code);
126 sub authenticate_user
{
127 my ($class, $config, $realm, $username, $password) = @_;
129 eval { &$authenticate_user_ad($config, $config->{server1
}, $username, $password); };
132 die $err if !$config->{server2
};
133 &$authenticate_user_ad($config, $config->{server2
}, $username, $password);