2016-07-14 16 views
0

の表示グループの親は、私はその後、各グループを取り、それぞれのグループであることをするグループを確認するにはどうすればよいPHP LDAP - のmemberOfを表示私は(<a href="https://samjlevy.com/archives/" rel="nofollow">https://samjlevy.com/archives/</a>)から、以下のようなスクリプトを持っているグループ

<?php 
function get_groups($user) { 
// Active Directory server 
    $ldap_server = "****************"; 

// Active Directory DN, base path for our querying user 

$ldap_dn = "dc=registry,dc=otago,dc=ac,dc=nz"; 
// Active Directory user for querying 
$query_user = "*************"; 
$password = "************"; 

// Connect to AD 
$ldap = ldap_connect($ldap_server) or die("Could not connect to LDAP"); 
ldap_bind($ldap,$query_user,$password) or die("Could not bind to LDAP"); 

// Search AD 
$results = ldap_search($ldap,$ldap_dn,"(samaccountname=$user)",array("memberof","primarygroupid")); 
$entries = ldap_get_entries($ldap, $results); 

// No information found, bad user 
if($entries['count'] == 0) return false; 

// Get groups and primary group token 
$output = $entries[0]['memberof']; 
$token = $entries[0]['primarygroupid'][0]; 

// Remove extraneous first entry 
array_shift($output); 

// We need to look up the primary group, get list of all groups 
$results2 = ldap_search($ldap,$ldap_dn,"(objectcategory=group)",array("distinguishedname","primarygrouptoken")); 
$entries2 = ldap_get_entries($ldap, $results2); 

// Remove extraneous first entry 
array_shift($entries2); 

// Loop through and find group with a matching primary group token 
foreach($entries2 as $e) { 
    if($e['primarygrouptoken'][0] == $token) { 
     // Primary group found, add it to output array 
     $output[] = $e['distinguishedname'][0]; 
     // Break loop 
     break; 
    } 
} 

return $output; 
} 

// Example Usage 
echo "<pre>"; 
    print_r(get_groups("ingja44p")); 
echo "</pre>"; 
?> 

属性したがって、メンバーは、ユーザーが関連する各グループを直接的または間接的に表示しますか?

答えて

1

Microsoft Active Directoryの「ユーザーが直接的または間接的に関連付けられているすべてのグループを表示する」最適な方法は、LDAP_MATCHING_RULE_IN_CHAINとよく呼ばれる拡張可能なラッチ規則を使用することです。

ので、クエリはのようになります。

(member:1.2.840.113556.1.4.1941:=(CN=UserName,CN=Users,DC=YOURDOMAIN,DC=NET)) 
関連する問題

 関連する問題