ldap filter for distinguishedName

倖福魔咒の 提交于 2019-12-10 04:17:00

问题


I am successfully querying our Active Directory for a user with the following code:

$filter = (&(objectCategory=person)(samaccountname=someusername));
$fields = array("samaccountname","mail","manager","department","displayname","objectGUID");

$user = ldap_search($ldapconnection, $baseDn, $filter, $fields);

The resulting array gives this value for the manager attribute:

CN=McBossy\, Boss,OU=Users,OU=CentralOffice,DC=ds,DC=example,DC=com

This looks like a distinguishedName to me. But when I try to query for the manager's record,

$filter = (&(objectCategory=person)(dn='CN=McBossy\, Boss,OU=Users,OU=CentralOffice,DC=ds,DC=example,DC=com'));

$manager = ldap_search($ldapconnection, $baseDn, $filter, $fields);

the query fails with PHP Warning: ldap_search(): Search: Bad search filter

I've tried a number of possibilities including different quotation, more parentheses, using distinguishedName rather than dn, etc.

What am I doing wrong and what is the right way to get the manager's record?


回答1:


dn is not an attribute. Only attribute types, OIDs, and names can be used in filters.

When you get the manager attribute, to get the attributes for the DN that is the manager, use the value of the manager attribute as the base object in a search request. Set the scope of the search to BASE, the filter to either (&) or (objectClass=*) and request the attributes required. Then transmit than search request to the server and interpret the response.



来源:https://stackoverflow.com/questions/17303967/ldap-filter-for-distinguishedname

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!