doushang1880 2015-03-10 16:30
浏览 87
已采纳

如果我需要在LDAP和PHP中搜索两个子文件夹,我可以为$ base_dn添加什么

I only have a very basic understanding of doing LDAP searches. I'm using PHP with Laravel.

I'm trying to do a search for all users within my my OU=USERS directory. I have two subfolders within that: OU=STAFF and OU="STUDENTS. I want to be able to search for a specific DN by username within both of those directories. The problem is that I can only make my search work if I specify either the STAFF or STUDENTS directories. I currently have:

...
$base_dn = 'OU=USERS,DC=mysite,DC=mydomain,DC=edu';
$filter = "(&(objectClass=person)(sAMAccountName=$username))";

$result = ldap_search($connection, $base_dn, $filter);
$entries = ldap_get_entries($connection, $result);


foreach ($entries as $entry) {
    $ldapUsername = $entry["sAMAccountName"][0];
    echo $ldapUsername;
    return;
}

It will work if I specify either

$base_dn = 'OU=STAFF,OU=MMM_USERS,DC=mmc,DC=mmm,DC=edu';

or

$base_dn = 'OU=STUDENTS,OU=MMM_USERS,DC=mmc,DC=mmm,DC=edu';

but not without them.

Overall, I'm just trying to validate a user based off of their username, which is also their cn, and their LDAP password. As far as I've been able to tell, however, I need to first get their DN, to try to bind to the connection with the DN and password, taken from a PHP form input.

Any advice on the specifics or the overall method of going about this would be greatly appreciated.

  • 写回答

1条回答 默认 最新

  • douyanqu9722 2015-03-11 10:44
    关注

    Depending on your LDAP Server Implementation you could use an extensible matching filter.

    However, I suspect you are using Microsoft Active Directory and it does NOT support extensible matching as you wish to perform.

    -jim

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题