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

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

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用