duandie5707 2013-07-24 20:10
浏览 94
已采纳

使用LDAP和PHP检查Active Directory中的组成员身份

I am pretty new to LDAP and Active Directory, and I think this should be a simple question. I am connecting to AD using the following code:

$ad = ldap_connect("domain.com") or die("Could not connect to AD");
//bind to the server
$uname = $uid . "@domain.com";
if (!ldap_bind($ad, "$uname", "$pwd") and $uid != "guest") {
    code...
}

and I need to check to see if the user is a member of one of three groups: ECSDocket_Admin, ECSDocket_User, or ECSDocket_Viewer. I have been searching around and most of the answers I have found use CN= and DN= and DC= in their queries, but I don't know what those mean. If someone could explain how it works, and what I need to do to figure out the group membership, that would be awesome!

  • 写回答

2条回答 默认 最新

  • dsjbest2015 2013-07-25 21:18
    关注

    If anyone cares, I was able to do a search like this:

    $dn = "CN=$uid,CN=Users,DC=domain,DC=com";
    $filter = "(memberOf=CN=ECSDocket_Admin,OU=Groups,DC=domain,DC=com)";
    $justthese = array("memberOf");
    
    $sr = ldap_search($ad, $dn, $filter, $justthese);
    $info = ldap_get_entries($ad, $sr);
    echo $info["count"]." entries returned.
    ";
    

    And by checking the count, I was able to determine if the inputted username was a part of the group -- if there was one, then it was a part of the group since I had already used ldap_connect under that username to check if it was valid within AD. For the filter, since memberOf is an array you need to specify the entire path. For example if you just needed to query the sn (surname) you could just have something like:

    $filter = "(sn=smith)";
    

    A site that helped me know exactly the right attributes was this one: http://www.selfadsi.org/user-attributes-w2k8.htm

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀