【发布时间】:2021-01-18 13:36:07
【问题描述】:
我目前正在尝试使用 LDAP 过滤器限制我的 LDAP 登录,但由于某种原因,过滤器不起作用。我的目标是,只有“示例”组中的用户才能登录。所以 LDAP 过滤器是
(&(objectclass=user)(department=example))
这是我的 PHP 代码:
<?php
if(isset($_POST['username']) && isset($_POST['password'])){
$adServer = "ldap://ldap.domain.com";
$ldap = ldap_connect($adServer);
$username = $_POST['username'];
$password = $_POST['password'];
$ldaprdn = 'ad' . "\\" . $username;
ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);
$bind = @ldap_bind($ldap, $ldaprdn, $password);
if ($bind) {
$filter="(department=example)"; //also tried "(|(sAMAccountName=user1)(sAMAccountName=user2))";
$result = ldap_search($ldap,"OU=example,DC=ad,DC=domain,DC=com",$filter);
ldap_sort($ldap,$result);
$info = ldap_get_entries($ldap,$result);
for ($i=0; $i<$info["count"]; $i++)
{
if($info['count'] > 1)
break;
}
@ldap_close($ldap);
session_start();
$_SESSION['sid']=session_id();
header('Location: https://domain.example.com/success.php');
} else {
$msg = "Invalid username / password";
echo $msg;
}
}else{
?>
<html>
Form...
</html>
<?php } ?>
我的 LDAP 过滤器是否错误,或者为什么没有应用它们?我也尝试只允许某些用户访问,但这也不起作用。无论我设置什么过滤器,每个用户都可以登录(使用正确的凭据)。
提前感谢所有答案,如果您需要任何进一步的信息/日志,请告诉我
###设置:
NAME="Debian GNU/Linux"
VERSION_ID="10"
VERSION="10 (破坏者)"
VERSION_CODENAME=buster
ID=debian
nginx版本:nginx/1.14.2
PHP 7.3.19-1~deb10u1 (cli)(构建时间:2020 年 7 月 5 日 06:46:45)(NTS)
PHP 7.3.19-1~deb10u1 (fpm-fcgi)(构建时间:2020 年 7 月 5 日 06:46:45)
【问题讨论】: