On Fri, Aug 13, 2004 at 08:24:25AM +0200, Jama Poulsen wrote:
> On Tue, Aug 10, 2004 at 04:53:33PM +0000, Brian Reichert wrote:
> > With Net::LDAP, what is the best way to delete a subtree?
>
> See this thread: http://www.mail-archive.com/perl-ldap%40perl.org/msg00564.html
>
> Its all still a bit messy. A simpler, less flexible/portable option, is to just
> use OpenLDAP's 'ldapdelete -r' command.
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.
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 ; }
}
--
Brian Reichert <[EMAIL PROTECTED]>
37 Crystal Ave. #303 Daytime number: (603) 434-6842
Derry NH 03038-1713 USA BSD admin/developer at large