如何从LDAP中的所有组用Perl [英] How to retrieve all Groups from LDAP with Perl
问题描述
我有一个Perl脚本至极绑定到LDAP服务器并检索所有用户。到目前为止,它的作品不错,但我想,以收集所有组过滤搜索。一旦我把所有组的用户可以选择其中一个组,我会告诉他只有作为该组成员的用户。我该怎么办的疑问?我tryed这一个:
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?
推荐答案
cnThe过滤器让所有组是(对象类=组)
你可以retreive组只1组织单位(范围=>一),或在所有子组织(范围=>'子')
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
}
有关更多帮助,请参见介绍到perl-LDAP
For more help see An Introduction to perl-ldap
编辑
所以,你要找的过滤器是:
So the filter you were looking for is :
(&(objectClass=user)(memberof=CN=Mongroupe,OU=MonOU,DC=societe,DC=fr))
这篇关于如何从LDAP中的所有组用Perl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!