如何使用 Perl 从 LDAP 检索所有组

发布于 2024-12-21 23:01:09 字数 322 浏览 0 评论 0原文

我有一个 Perl 脚本,它绑定到 LDAP 服务器并检索所有用户。到目前为止,它运行良好,但我想过滤该搜索以收集所有组。一旦我拥有所有组,用户就可以选择这些组之一,我将只向他显示属于该组成员的用户。我该如何进行这些查询?我尝试了这个:

my $mesg = $ldap->search(
    base => $base,
    filter => '(objectclass=user)',
    attrs => ['memberOf']
);

但是有些组会重复,我将不得不手动过滤结果(我想避免这种情况)。那么第二个查询呢?

I have a Perl script wich binds to an LDAP server and retrieves all users. So far it works good but I want to filter that search in order to gather all groups. Once I have all groups the user can select one of these groups and I'll show him only users that are member of that group. How can I do those queries? I tryed this one:

my $mesg = $ldap->search(
    base => $base,
    filter => '(objectclass=user)',
    attrs => ['memberOf']
);

But then some groups are repeated and I will have to manually filter the result (and I'd like to avoid that). And what about the second query?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

为人所爱 2024-12-28 23:01:09

cn 获取所有组的过滤器是“(objectclass=group)”,您可以仅检索一个组织单位 (scope => 'one') 或所有子组织 (scope => 'sub') 中的组)

$mesg = $ldap->search(  filter=>"(&(objectclass=group)(cn=the group choosen by the user)", 
                        base=>"ou=Monou,dc=societe,dc=fr"
                        scope=>"sub"
                        attrs=> ['cn', 'member']);
@entries = $mesg->entries;
foreach $entry (@entries)
{
    $entry->dump;
    @member = $entry->get_value("member");  # returns all members 
}

有关更多帮助,请参阅 Perl-ldap 简介


编辑

如下您正在寻找的过滤器是:

(&(objectClass=user)(memberof=CN=Mongroupe,OU=MonOU,DC=societe,DC=fr))

cnThe filter to get all groups is "(objectclass=group)" you can retreive groups in only one organizationalUnit (scope => 'one') or in all suborganization (scope => 'sub')

$mesg = $ldap->search(  filter=>"(&(objectclass=group)(cn=the group choosen by the user)", 
                        base=>"ou=Monou,dc=societe,dc=fr"
                        scope=>"sub"
                        attrs=> ['cn', 'member']);
@entries = $mesg->entries;
foreach $entry (@entries)
{
    $entry->dump;
    @member = $entry->get_value("member");  # returns all members 
}

For more help see An Introduction to perl-ldap


Edited

So the filter you were looking for is :

(&(objectClass=user)(memberof=CN=Mongroupe,OU=MonOU,DC=societe,DC=fr))
偏爱自由 2024-12-28 23:01:09

使用 objectclass=* 获取全部。

my $msg = $ldap->search(base => $dn,
            scope => 'one',
            filter => "(objectclass=*)");
$msg->all_entries;          

Use objectclass=* to get all.

my $msg = $ldap->search(base => $dn,
            scope => 'one',
            filter => "(objectclass=*)");
$msg->all_entries;          
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文