#!/usr/local/bin/perl
#
# $Id: userdelete,v 1.1 2002/05/03 21:44:51 visick Exp $
#
# userdelete - delete user from LDAP
#
# Copyright (C) 2002 Steven Barrus
# Copyright (C) 2002 Dana Dahlstrom
# Copyright (C) 2002 Robert Ricci
# Copyright (C) 2002 Spencer Visick
#
# See the AUTHORS file for contact info
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA


exit &usage if (!@ARGV or $ARGV[0] =~ /^-h/);

require 'usertools.ph';
use strict;
no strict "vars";

$ldap = ldap_connect();

foreach (@ARGV) {
  $search = "(uid=$_)";
  $mesg = $ldap->search( base => $config{userbase}, filter => $search);
  my $entry = $mesg->entry();
  unless ($entry) {print "$_: LDAP entry not found.\n"; exit;}
  $mesg = $ldap->delete($entry);
  print $mesg->error if $mesg->code;
}


sub usage {

  print << "EOSTR";
Usage: userdelete USER...
Delete USER from LDAP.

You will be prompted for a password with which to bind; if you succeed
in binding, all USERs will be deleted. Be careful!
EOSTR

  1;
}

__END__
=head1 NAME

userdelete - delete user from LDAP

=head1 SYNOPSIS

userdelete USER ...
     
userdelete -h

=head1 DESCRIPTION

B<userdelete> simply removes a user from the LDAP directory specified 
in /etc/usertools.conf or $HOME/.usertoolsrc. You will be prompted 
for a password with which to bind; if you succeed in binding, all 
USERs will be deleted. Be careful!

=head1 OPTIONS

B<-h>

Print out usage information.

=head1 EXAMPLES
     
userdelete visick

Deletes I<visick> from LDAP directory

=head1 BUGS

lots probably, sorry. Contact AUTHORS if you find any.

=head1 AUTHORS

The usertools were written at the CADE by various opers. See the AUTHORS file 
for details.

=head1 SEE ALSO

usercreate(1), usermodify(1), userrevert(1), usersearch(1).
groupcreate(1), groupmodify(1), groupsearch(1),


=cut 
