Ldap如何获得memberof

时间:2014-04-04 22:49:48

标签: php filter ldap memberof

如何获取用户过滤器的成员?并非所有用户都有成员。

$ds = `000.000.000.000`;
$ldaprdn  = `CN=Users,dc=xxx,dc=xx,dc=xx,dc=xx`;    
$user = `CN=UserSystem,`;
$ldappass = `pass`;

// connect to ldap server
$ldapconn = ldap_connect("000.000.000.000") or die(`Could not connect to LDAP server.`);

if ($ldapconn) {
    // binding to ldap server
    $ldapbind = ldap_bind($ldapconn, $user.``.$ldaprdn, $ldappass);
    // verify binding
    if ($ldapbind) {        
        ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION,3);
        ldap_set_option($ldapconn, LDAP_OPT_REFERRALS,0);

        $sr=ldap_search($ldapconn, $ldaprdn, `(&(objectClass=user)(sAMAccountName=testuser))`);
        $info = ldap_get_entries($ldapconn, $sr);

        $ii=0;
         for ($i=0; $ii`;
              if ($data == `memberof`) {
            $membrog = explode(`,`, $info[$i][$data][0]);
            $membrode = explode(`=`, $membrog[0]);
            echo $membrode[1].`
`; } } ldap_close($ldapconn); } else { echo `Connection to LDAP Failed`; } }

1 个答案:

答案 0 :(得分:0)

如果您正在查看用户是来自LDAP的成员OF,则由于群组嵌套,您可能需要使用利用MATCHING_RULE_IN_CHAIN, like shown on this page.的过滤器

-Jim