douzhaiyuan1731 2015-07-19 20:26
浏览 732

通过LDAP使用PHP从AD获取所有用户的组

I am trying to grab all groups that a user belongs to using PHP. I am able to grab all of the groups that are listed in the memberof attribute, but not the user's inherited groups.

I've tried modifying the code to also do an ldap_search for the group name/samaccount name but I've not been successful in searching for the group's memberof attribute.

Below is the code that I'm using.

$checkDn=$this->setDn(true); 
$results[0]=$attribute; 

// We need to search for this user in order to get their entry.
$this->result=@ldap_search($this->connection,$checkDn,$this->getUserIdentifier()."=$uname",$results);
$info=ldap_get_entries($this->connection, $this->result);

// Only one entry should ever be returned(no user will have the same uid) 
$entry=ldap_first_entry($this->connection, $this->result);

if(!$entry){
 $this->ldapErrorCode=-1;
 $this->ldapErrorText="Couldn't find user";
 return false; // Couldn't find the user...
}

// Get all the member DNs
if(!$values=@ldap_get_values($this->connection,$entry,$attribute)){
 $this->ldapErrorCode=ldap_errno($this->connection);
 $this->ldapErrorText=ldap_error($this->connection);
 return false; // No matching attributes 
}

// Return an array containing the attributes. 
return $values; 

Here is a sample group that they belong to.

CN=Business Operations,OU=Groups,OU=Operations,OU=Corporate,OU=company name,DC=website,DC=com

Thanks for any assistance with this!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 自动转发微信群信息到另外一个微信群
    • ¥15 outlook无法配置成功
    • ¥30 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换