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

报告相同问题?

悬赏问题

  • ¥15 在若依框架下实现人脸识别
  • ¥15 网络科学导论,网络控制
  • ¥100 安卓tv程序连接SQLSERVER2008问题
  • ¥15 利用Sentinel-2和Landsat8做一个水库的长时序NDVI的对比,为什么Snetinel-2计算的结果最小值特别小,而Lansat8就很平均
  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同