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

使用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条)

报告相同问题?

悬赏问题

  • ¥20 电脑拓展屏桌面被莫名遮挡
  • ¥20 ensp,用局域网解决
  • ¥15 Python语言实验
  • ¥15 我每周要在投影仪优酷上自动连续播放112场电影,我每一周遥控操作一次投影仪,并使得电影永远不重复播放,请问怎样操作好呢?有那么多电影看吗?
  • ¥20 电脑重启停留在grub界面,引导出错需修复
  • ¥15 matlab透明图叠加
  • ¥50 基于stm32l4系列 使用blunrg-ms的ble gatt 创建 hid 服务失败
  • ¥150 计算DC/DC变换器平均模型中的参数mu
  • ¥25 C语言代码,大家帮帮我
  • ¥50 关于#html5#的问题:H5页面用户手机返回的时候跳转到指定页面例如(语言-javascript)