#!/bin/sh

# OpenVAS
# $Id: openvas-rmuser.in 1728 2008-11-14 10:03:22Z mwiegand $
# Description: shellscript to remove an openvas user.
#
# Authors: - Renaud Deraison <deraison@nessus.org> (Original pre-fork develoment)
#          - Tim Brown <mailto:timb@openvas.org> (Initial fork)
#          - Laban Mwangi <mailto:labanm@openvas.org> (Renaming work)
#          - Tarik El-Yassem <mailto:tarik@openvas.org> (Headers section)
#
# Copyright:
# Portions Copyright (C) 2006 Software in the Public Interest, Inc.
# Based on work Copyright (C) 1998 - 2006 Tenable Network Security, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2,
# as published by the Free Software Foundation
#
# 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
#
#


prefix=/usr
exec_prefix=${prefix}
bindir=${exec_prefix}/bin
sbindir=${exec_prefix}/sbin
libexecdir=${exec_prefix}/libexec
datarootdir=${prefix}/share
datadir=${datarootdir}
sysconfdir=/etc
sharedstatedir=${prefix}/com
localstatedir=/var
libdir=${exec_prefix}/lib
includedir=${prefix}/include
oldincludedir=/usr/include
infodir=${prefix}/share/info
mandir=${prefix}/share/man

openvasd=${exec_prefix}/sbin/openvasd
openvasd_users=/etc/openvas/openvasd.users

# check if gettext is present

if [ -f /usr/bin/gettext.sh ];
then

  # initialize gettext

  . gettext.sh
  export TEXTDOMAIN=nessus-scripts
  export TEXTDOMAINDIR=${datarootdir}/locale

else

  # define dummy functions

  gettext () {
    echo $1
  }

  eval_gettext () {
    echo $1
  }

fi

#
# check whether we have echo -n, depending
# on the current shell, used
case `echo -n` in
\-n)	Xn=   ; Xc='\c' ;;
*)	Xn=-n ; Xc=
esac

# make sure that we are root
case `id` in uid=0*) ;; *)
   gettext "Only root should use openvas-rmuser."; echo
   exit 1
esac


login="$1"

test -z "$login" && {
echo $Xn "`gettext "Login to remove :"` $Xc"
read login
}

test -z "$login" && {
 gettext "No login entered"
 exit 1
}

if [ -d "$localstatedir/lib/openvas/users/$login" ];
then
 rm -rf "$localstatedir/lib/openvas/users/$login"
 gettext "user removed."; echo
else
 gettext "user does not exist"; echo
fi

exit 0
