简体   繁体   English

如何获取所有LDAP条目?

[英]how can I get ALL LDAP entries?

I know how to LDAP bind for authentication which uses search but what can I do if I want ALL of the entries of Full Names...So how can I get the Full names or emails of ALL the people?? 我知道LDAP绑定如何使用搜索进行身份验证,但如果我想要所有的全名条目,我该怎么办...那么如何才能获得所有人的全名或电子邮件?

Below I use LDAP bind for authentication and I can search for one person but what if I want them all? 下面我使用LDAP绑定进行身份验证,我可以搜索一个人,但如果我想要它们怎么办?

<?php

// using ldap bind
$ldaprdn  = 'uname';     // ldap rdn or dn
$ldappass = 'password';  // associated password

// connect to ldap server
$ldapconn = ldap_connect("ldap.example.com")
    or die("Could not connect to LDAP server.");

if ($ldapconn) {

    // binding to ldap server
    $ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass);

    // verify binding
    if ($ldapbind) {
        echo "LDAP bind successful...";
    } else {
        echo "LDAP bind failed...";
    }

}

?>

This is some MySQL code I have that populates an html list: 这是我的一些MySQL代码填充html列表:

<ol>     

<?php
mysql_connect("kool", "ohjoa", "sampa") or die(mysql_error());
mysql_select_db("DBtest") or die(mysql_error());

$query = "SELECT * FROM EditOnCall"; 

$result = mysql_query($query) or die(mysql_error());


while($row = mysql_fetch_array($result)){
    echo "<li>".$row['Email']."</li>";
    echo "<br />";
}


?>

</ol>

Now this displays a html list of emails. 现在显示一个电子邮件的HTML列表。 What I want to do is the same thing with LDAP except display the Full Name of all the ldap users in a directory...MY LDAP only has 200 people in it so its not too big. 除了在目录中显示所有ldap用户的全名外,我想做的事情与LDAP相同...我的LDAP只有200个人,所以它不是太大。

Any Ideas? 有任何想法吗?

A bind is one type of LDAP request, and a search is another type of request. 绑定是一种LDAP请求,搜索是另一种类型的请求。 A bind establishes the authentication state of a connection, and a search uses a base object, a scope, a filter, and other optional parameters to build a candidate list of entries which are filtered and returned to the LDAP client. 绑定建立连接的身份验证状态,搜索使用基础对象,范围,过滤器和其他可选参数来构建筛选并返回到LDAP客户端的条目候选列表。 The authentication state of the connection will also establish certain access capabilities such as which entries can be retrieved, how many entries can be retrieved in a search, how much time is spent on a search, how many entries should be examined in the process of fulfilling a search request, and other capabilities. 连接的身份验证状态还将建立某些访问功能,例如可以检索哪些条目,可以在搜索中检索多少条目,在搜索上花费了多少时间,在完成过程中应检查多少条目搜索请求和其他功能。 Without using the root DN, it may not be possible to retrieve all entries in a directory, and your LDAP administrator may forbid non-root DN authentication states from retrieving more than a few entries. 如果不使用根DN,则可能无法检索目录中的所有条目,并且LDAP管理员可能会禁止非根DN身份验证状态检索多个条目。 For more information about search, see " LDAP: Using ldapsearch ". 有关搜索的详细信息,请参阅“ LDAP:使用ldapsearch ”。 For more general information about programming with LDAP, see "LDAP: Programming Practices" . 有关使用LDAP编程的更多常规信息,请参阅“LDAP:编程实践” For more detailed information see LDAP Search Best Practices . 有关更多详细信息,请参阅LDAP搜索最佳实践

With regard to filters, an asterisk is not a wildcard in the sense described (cn=*) . 关于过滤器,星号不是所描述意义上的通配符(cn=*) This is known as a presence filter and indicates whether the attribute used in the assertion - in this case cn - is present in an entry when filtering the candidate list. 这称为存在过滤器,用于指示在过滤候选列表时,断言中使用的属性(在本例中为cn )是否存在于条目中。 The asterisk can be used as part of a substring filter, for example, (cn=abc*) or (mail=user@example*) . 星号可以用作子字符串过滤器的一部分,例如, (cn=abc*)(mail=user@example*)

In any case, substring filters should be avoided where possible in large directories, are probably forbidden anyway, as would be 'trawling' the directory. 在任何情况下,应尽可能避免在大型目录中使用子字符串过滤器,无论如何都可能被禁止,就像“拖网”目录一样。

This is not about how you bind, it's about how you search. 这不是关于你如何绑定,而是关于你如何搜索。 You need to learn about LDAP filters (this link relates to AD but all the information in it can be applied to any LDAP node). 您需要了解LDAP过滤器 (此链接与AD相关,但其中的所有信息都可以应用于任何LDAP节点)。

You can use * as a wildcard in an LDAP filter. 您可以在LDAP过滤器中使用*作为通配符。 Say you wanted to get all the objects of objectClass=User which are identified by an attribute cn from a root container called cn=Users - you would do this: 假设您想要获取objectClass=User所有对象,这些对象由名为cn=Users的根容器中的属性cn标识 - 您将执行此操作:

$searchResult = ldap_search($ldapconn,'cn=Users','(&(objectClass=User)(cn=*))',array('cn','guid'));

The only way that the way you bind can affect this principle is if the user you use to bind does not have permissions to access the objects you are looking for in the directory. 绑定方式的唯一方法可能会影响此原则,即用于绑定的用户无权访问您在目录中查找的对象。

If you show some more code of exactly what you are trying to do, I will edit this answer with more detail. 如果您显示更多正是您要执行的操作的代码,我将更详细地编辑此答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM