Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 33 lines (26 sloc) 1.024 kb
3477ef1 @gbarr Add example script for recursive deletes
gbarr authored
1 #!/usr/bin/perl -w
2 #
3 # recursive-ldap-delete.pl
4 #
4fbd3e0 @marschap shorten recursive-ldap-delete.pl and make it more "elegant"
marschap authored
5 # originally by Mike Jackson <mj@sci.fi>
6 # shortened by Peter Marschall <peter@adpm.de>
7 # based on ideas by Norbert Kiesel <nkiesel@tbdetworks.com>
3477ef1 @gbarr Add example script for recursive deletes
gbarr authored
8 #
4fbd3e0 @marschap shorten recursive-ldap-delete.pl and make it more "elegant"
marschap authored
9 # ToDo: check errors, handle references, ....
3477ef1 @gbarr Add example script for recursive deletes
gbarr authored
10
11 use strict;
12 use Net::LDAP;
13
14 my $server = "localhost";
15 my $binddn = "cn=directory manager";
16 my $bindpasswd = "foobar";
4fbd3e0 @marschap shorten recursive-ldap-delete.pl and make it more "elegant"
marschap authored
17 my $delbranch = "ou=users,dc=bigcorp,dc=com"; # branch to remove
3477ef1 @gbarr Add example script for recursive deletes
gbarr authored
18
19 my $ldap = Net::LDAP->new( $server ) or die "$@";
20 $ldap->bind( $binddn, password => $bindpasswd, version => 3 );
21
4fbd3e0 @marschap shorten recursive-ldap-delete.pl and make it more "elegant"
marschap authored
22 my $search = $ldap->search( base => $delbranch,
23 filter => "(objectclass=*)" );
3477ef1 @gbarr Add example script for recursive deletes
gbarr authored
24
4fbd3e0 @marschap shorten recursive-ldap-delete.pl and make it more "elegant"
marschap authored
25 # delete the entries found in a sorted way:
26 # those with more "," (= more elements) in their DN, which are deeper in the DIT, first
27 # trick for the sorting: tr/,// returns number of , (see perlfaq4 for details)
28 foreach my $e (sort { $b->dn =~ tr/,// <=> $a->dn =~ tr/,// } $search->entries()) {
29 $ldap->delete($e);
30 }
3477ef1 @gbarr Add example script for recursive deletes
gbarr authored
31
4fbd3e0 @marschap shorten recursive-ldap-delete.pl and make it more "elegant"
marschap authored
32 $ldap->unbind();
Something went wrong with that request. Please try again.