現在のユーザーで検索を実行して、LDAP/PHP を使用して Active Directory 内の関連グループを含むすべての属性を取得する最良の方法は何ですか?
属性については、主に名、姓、および表示名のみ。
関連付けられたグループの場合、memberOf 関数など、ユーザーがメンバーになっているグループのみ。
いくつかのオプションを試しましたが、適切なフィルターと検索の組み合わせが得られないようで、ほとんどの例は、既知のグループがあるユーザーのリストの取得をカバーしています。
バインドが成功した後、これを実行しようとしました:
$attributes = array("displayname");
$filter = "(&(sAMAccountName=$username))";
$result = ldap_search($ds, $ldapconfig['basedn'], $filter, $attributes);
$entries = ldap_get_entries($ds, $result);
if($entries["count"] > 0){
echo "displayName: ".$entries[0]['displayname'][0]."<br/>";
} else {
echo("msg:'".ldap_error($ds)."'</br>");
}
次のエラーが返されます:「そのようなオブジェクトはありません」。
アップデート:
これは私が試した最新のブロックで、$info 変数を print_r すると結果を取得できますが、for 句はまだどこかでエラーになっています。basedn を dc 属性だけに変更しました。
$filter="($SearchField=$SearchFor)";
$sr=ldap_search($ds, $basedn, $filter, $LDAPFieldsToFind);
$info = ldap_get_entries($ds, $sr);
if($info["count"] > 0) {
for ($x=0; $x<$info["count"]; $x++) {
$sam=$info[$x]['samaccountname'][0];
$giv=$info[$x]['givenname'][0];
$tel=$info[$x]['telephonenumber'][0];
$email=$info[$x]['mail'][0];
$nam=$info[$x]['cn'][0];
$dir=$info[$x]['homedirectory'][0];
$dir=strtolower($dir);
$pos=strpos($dir,"home");
$pos=$pos+5;
if (stristr($sam, $SearchFor) && (strlen($dir) > 8)) {
print "\nActive Directory says that:\n";
print "CN is: ".$nam." \n";
print "SAMAccountName is: ".$sam." \n";
print "Given Name is: ".$giv." \n";
print "Telephone is: ".$tel." \n";
print "Home Directory is: ".$dir." \n";
}
}
}
結果の print_r は次のとおりです。
( [count] => 1 [0] => Array ( [cn] => Array ( [count] => 1 [0] => George ) [0] => cn [givenname] => Array ( [count] => 1 [0] => George ) [1] => givenname [memberof] => Array ( [count] => 4 [0] => CN=EQCStaff,CN=Users,DC=EQC,DC=local [1] => CN=RDS Users,OU=Security Groups,OU=Service,DC=EQC,DC=local [2] => CN=SFTP Client Folders,OU=Security Groups,OU=Service,DC=EQC,DC=local [3] => CN=EQC Staff,OU=Security Groups,OU=Service,DC=EQC,DC=local ) [2] => memberof [samaccountname] => Array ( [count] => 1 [0] => gortiz ) [3] => samaccountname [mail] => Array ( [count] => 1 [0] => user@domain.com ) [4] => mail [count] => 5 [dn] => CN=George,OU=Users,OU=Accounts,DC=EQC,DC=local ) )