#!/bin/sh # # deluser+shadow 1.1: a utility to remove users from the system with optional # shadow support. # # Copyright (C) 1997 hf # # 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., 675 Mass Ave, Cambridge, MA 02139, USA. # MAILDIR="/var/spool/mail" HOMEDIR="/home" PASSWD="/etc/passwd" SHADOW="/etc/shadow" # Dont need to modify if you dont have shadow support. UNAME="$1" LOCKDIR="/tmp/.lockdir" # Lockdir for shadowfile. TMP="/tmp" # users' tmp dir if [ `id -u` != "0" ]; then echo "you have to be root to run this." exit 1 fi if [ "" = "$1" ]; then echo Usage: deluser username exit 1 fi echo -n "Delete $1? [n] " read yes if [ "$yes" != "y" ]; then echo >/dev/null exit 1 fi # Check for user if grep "^$UNAME:" $PASSWD > /dev/null; then echo >/dev/null else echo -n "hmm...can't seem to find that user. delete $UNAME anyway? " read delete if [ "$delete" != "y" ]; then echo >/dev/null exit 1 fi fi if [ "$yes" = "y" ]; then cp /etc/passwd /etc/passwd.backup cat $PASSWD |grep -v "^$UNAME:" >/tmp/passwd.tmp mv -f /tmp/passwd.tmp /etc/passwd if test -f $SHADOW; then if test -d $LOCKDIR; then rm -rf $LOCKDIR fi # This avoids leaving the shadow file vulnerable. mkdir $LOCKDIR; chmod og-x $LOCKDIR cat $SHADOW |grep -v "^$UNAME:" >$LOCKDIR/shadow chmod 600 $LOCKDIR/shadow mv -f $LOCKDIR/shadow $SHADOW; rm -rf $LOCKDIR fi fi echo deleting home directory... rm -rf $HOMEDIR/$UNAME if test -f $MAILDIR/$UNAME; then echo deleting mail folder... rm -rf $MAILDIR/$UNAME fi