Thanks for all the feedback. I went ahead an wrote a simple recursive
desent for my containers. I made the assumption that they were all
organizationalUnits.
But what if the OU is not the only way you have structured your DIT?
By changing the filter to objectClass=* it will remove your current assumption that each "container" object is an OU. This means you should be able to simply have a startpoint to pass your sub routine and let it rip. :)
So if you have a (contrived) DIT that for example has
ou=sales,ou=factory1,l=location3,l=location2,o=big Org,c=uk
and you wanted to delete all entries under l=location2, your subroutine doesn't have to change.
Just a thought..
I'm not going to claim this will work for everyone, but this works for me:
#-------- # recursively delete a container.
sub container_descend { my $base = shift; my $ldap = shift;
my $mesg = $ldap->search( base => $base, scope=> 'one', filter => 'objectclass=organizationalUnit', );
foreach my $entry ($mesg->all_entries) { &container_descend($entry->dn, $ldap); }
$mesg = $ldap->search( base => $base, scope=> 'one', filter => 'objectclass=*', );
foreach my $entry ($mesg->all_entries) { my $result = $ldap->delete($entry); if (defined $result) { $result->code && warn "failed: ", $result->error ; } }
$debug && print $tag."- deleting $base\n"; my $result = $ldap->delete($base); if (defined $result) { $result->code && warn "failed: ", $result->error ; } }
