raz3r
raz3r

Reputation: 3131

How to query Organizational Units from a given DN in Perl

I need to retrieve all Organizational Units from a given DN stringh, I am using Net::LDAP module and this little script:

my $msg = $ldap->search(
    base=>'DC=sample1,DC=sample2',
    filter=>'(objectclass=User)',
);
foreach $entry ($msg->entries) {
    $dn = $entry->dn;
    #how can i retrieve OUs?
}

For example if dn returns that string:

CN=Sample Sample,OU=One,OU=Two,DC=sample1,DC=sample2

I want to retrieve One and Two.

Upvotes: 1

Views: 7403

Answers (2)

dorancemc
dorancemc

Reputation: 163

Most detailed "(&(ou=*)(objectClass=organizationalunit))"

Upvotes: 0

Terry Gardner
Terry Gardner

Reputation: 11132

Issue a one level search request using the base object dc=example1,dc=sample2 and a presence filter of (ou=*). Given those results, issue a one level search using each returned ou with a presence filter of (ou=*). For each of these searches, specify a size limit and a time limit. For more information on search requests, see "LDAP: Using ldapsearch" and "LDAP: programming practices".

Upvotes: 3

Related Questions