#!/usr/bin/perl -w
use strict;
my $BASE = "dc=skole,dc=skolelinux,dc=no";
my $GROUPBASE = "ou=Group,$BASE";
my $USERBASE = "ou=People,$BASE";

my %groups;
open (my $fh, "ldapsearch -x -b $GROUPBASE groupType=private cn |");
while (<$fh>) {
  /^cn: (.*)$/ and $groups{$1} = 1;
}
close $fh;

my %users;
open ($fh, "ldapsearch -x -b $USERBASE uid |");
while (<$fh>) {
  /^uid: (.*)$/ and $users{$1} = 1;
}
close $fh;

foreach my $group (keys %groups) {
  defined $users{$group} or
    print "dn: cn=$group,$GROUPBASE
changetype: delete

";
}
