douqi0090 2013-10-29 04:43
浏览 77
已采纳

LDAP - 列出组

I need to list all groups within a certain group using PHP. This is what I have so far:

<?php
$ldap_dn = "ou=People,dc=something,dc=something,dc=something,dc=au";
$ldap_svr = "ldap.server.somewhere";
$ldap_domain = "domain.somewhere";
$conn=ldap_connect($ldap_svr) or die("Cannot connect to LDAP server!");

ldap_set_option ($conn, LDAP_OPT_REFERRALS, 0);
ldap_set_option($conn, LDAP_OPT_PROTOCOL_VERSION, 3);

ldap_bind($conn,"user@domain.somewhere","password");


$filter ="(ou=*)";
$justthese = array("ou");

$result=ldap_list($conn, $ldap_dn, $filter, $justthese) or die("No search data found."); 

$info = ldap_get_entries($conn, $result);

for ($i=0; $i < $info["count"]; $i++) {
    echo $info[$i]["ou"][0] . '<br />';
}
?>

This returns a list of groups, one of whch is 'Students', but I want to list all groups within 'Students'. How can I do this?

EDIT

Thanks to Fluffeh the Microsoft LDAP plugin allows me to search active directorys so I can tailor my PHP script accordingly, e.g. $ldap_dn = "ou=Units,ou=Groups,dc=somewhere,dc=somewher,dc=somewhere,dc=au";

So my mostly working code is:

<?php
$ldap_dn = "ou=Units,ou=Groups,dc=somewhere,dc=somewher,dc=somewhere,dc=au";
$ldap_svr = "ldap.server.somewhere";
$ldap_domain = "domain.somewhere";
$conn=ldap_connect($ldap_svr) or die("Cannot connect to LDAP server!");

ldap_set_option ($conn, LDAP_OPT_REFERRALS, 0);
ldap_set_option($conn, LDAP_OPT_PROTOCOL_VERSION, 3);

ldap_bind($conn,"user@domain.somewhere","password");


$filter ="(cn=*)";
$justthese = array('cn');

$result=ldap_list($conn, $ldap_dn, $filter, $justthese) or die("No search data found."); 

$info = ldap_get_entries($conn, $result);

for ($i=0; $i < $info["count"]; $i++) {
    echo $info[$i]["cn"][0] . '<br />';
}
?>
  • 写回答

1条回答 默认 最新

  • doudou1897 2013-10-29 04:47
    关注

    You need to actually pass the search to it. Currently you are using:

    $filter ="(ou=*)";
    

    This will need to change to contain 'Students'. While I am no LDAP expert, I would guess at the following:

    $filter ="(cn=Students)";
    

    Most of the LDAP stuff I have done has been sheer trial and error rather than knowing what I am doing, but this might put you on the right path.

    There is also a Microsoft plugin - Active Directory Explorer you can use to at least browse the LDAP so that you know what to search for and under what branch.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 keepalive配置业务服务双机单活的方法。业务服务一定是要双机单活的方式
  • ¥50 关于多次提交POST数据后,无法获取到POST数据参数的问题
  • ¥15 win10,这种情况怎么办
  • ¥15 如何在配置使用Prettier的VSCode中通过Better Align插件来对齐等式?(相关搜索:格式化)
  • ¥100 在连接内网VPN时,如何同时保持互联网连接
  • ¥15 MATLAB中使用parfor,矩阵Removal的有效索引在parfor循环中受限制
  • ¥20 Win 10 LTSC 1809版本如何无损提升到20H1版本
  • ¥50 win10 LTSC 虚拟键盘不弹出
  • ¥30 微信小程序请求失败,网页能正常带锁访问
  • ¥15 Matlab求解微分方程,如何用fish2d进行预优?