php LDAP 过滤器 - 查找特定 OU 的所有用户
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19302165/
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
LDAP Filter - Find all users of specific OU
提问by Nic Hubbard
I am having trouble with an LDAP Search Filter
. What I am needing to retrieve is all the users of a specific LDAP
group that is OU=Staff,OU=Users,OU=Accounts,DC=test,DC=local
我在使用LDAP Search Filter
. 我需要检索的是特定LDAP
组的所有用户OU=Staff,OU=Users,OU=Accounts,DC=test,DC=local
My search is:
我的搜索是:
(&(objectCategory=user)(OU=Staff,OU=Users,OU=Accounts,DC=test,DC=local))
Currently it is returning no results. What am I missing?
目前它没有返回任何结果。我错过了什么?
回答by ixe013
You must do two things
你必须做两件事
- Set the base of the search
OU=Staff,OU=Users,OU=Accounts,DC=test,DC=local
- Search for the objects with the
objectClass
.
- 设置搜索基础
OU=Staff,OU=Users,OU=Accounts,DC=test,DC=local
- 搜索带有 的对象
objectClass
。
Using PHP, the search would look like this (based on this PHP sample):
使用 PHP,搜索将如下所示(基于此 PHP 示例):
<?php
//You must bind, first
// using ldap bind
$ldaprdn = 'yourdomain\nic_hubbard'; // ldap rdn or dn
$ldappass = 'password'; // associated password
// connect to ldap server
$ldapconn = ldap_connect("yourad.test.local")
or die("Could not connect to LDAP server.");
if ($ldapconn) {
// binding to ldap server
$ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass);
$dn = "OU=Staff,OU=Users,OU=Accounts,DC=test,DC=local";
$filter="(objectClass=user)";
$justthese = array("cn", "sn", "givenname", "mail");
$sr=ldap_search($ldapconn, $dn, $filter, $justthese);
$info = ldap_get_entries($ldapconn, $sr);
echo $info["count"]." entries returned\n";
}
?>
You can test on the command line with this (exact options varies, this works with recent openldap's client tools) :
您可以在命令行上进行测试(具体选项各不相同,这适用于最近的 openldap 客户端工具):
ldapsearch -H ldap://yourad.test.local -x -D "yourdomain\nic_hubbard" -W -b "OU=Staff,OU=Users,OU=Accounts,DC=test,DC=local" -s sub "(objectClass=user)"