php 使用 ldap 列出用户的组

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3783179/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 11:05:11  来源:igfitidea点击:

list groups from user with ldap

phpldap

提问by Marwelln

I'm really new to LDAP and just got a connection between my php server and my ad server. I've succefully been able to authenticate users. Now I want to list all groups the users are in to see if he's an admin or not (or there might be another way?).

我对 LDAP 真的很陌生,刚刚在我的 php 服务器和我的广告服务器之间建立了连接。我已经成功地对用户进行了身份验证。现在我想列出用户所在的所有组,看看他是否是管理员(或者可能有其他方式?)。

I have this so far:

到目前为止我有这个:

    $ldap = ldap_connect("192.168.1.108");
    if ($ldap && $bind = @ldap_bind($ldap, $name."@foobar.com", $pw)) {
        // ldap_search and ldap_get_entries here i guess, but how?
    }

I've tried with ldap_search by reading the manual at php.net but I couldn't get it to work at all. Can somebody show me how to get it to work?

我已经通过阅读 php.net 上的手册尝试使用 ldap_search,但我根本无法让它工作。有人可以告诉我如何让它工作吗?

回答by Marwelln

I got it working with this post: http://www.php.net/manual/en/ref.ldap.php#99347Thanks anyway Aaron.

我在这篇文章中得到了它:http://www.php.net/manual/en/ref.ldap.php#99347 无论如何感谢 Aaron。

回答by Aaron W.

You may want to check out the ldap_get_entriesfunction. Below is maybe some code that can help you out that I used to scan memberships. membermay be something different on your config so I suggest printing the entire $dataarray if you get errors. Hopefully a starting point for you.

您可能想查看ldap_get_entries函数。下面是一些可以帮助您解决我用来扫描会员资格的代码。member您的配置可能有所不同,因此$data如果出现错误,我建议打印整个数组。希望是你的起点。

// Users
$query = ldap_search($ldap, "cn=Users, dc=test, dc=local", "cn=*");
// Read all results from search
$data = ldap_get_entries($ldap, $query);

// Loop over 
for ($i=0; $i < $data['count']; $i++) {
    print_r($data[$i]['member']);
    echo "\n\n";    
}