HEX
Server: Apache/2.4.54 (Unix) OpenSSL/1.0.2k-fips
System: Linux f17.eelserver.com 3.10.0-1160.80.1.el7.x86_64 #1 SMP Tue Nov 8 15:48:59 UTC 2022 x86_64
User: zulfiqar (1155)
PHP: 8.2.0
Disabled: mail, exec, system, popen, proc_open, shell_exec, passthru, show_source
Upload Files
File: //usr/share/doc/perl-LDAP-0.56/contrib/recursive-ldap-delete.pl
#!/usr/bin/perl -w
#
# recursive-ldap-delete.pl
#
# originally by Mike Jackson <[email protected]>
# shortened by Peter Marschall <[email protected]>
# based on ideas by Norbert Kiesel <[email protected]>
#
# 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();