#!/bin/bash
#deny users
#Hahazhu 24/12/06
UserNum="0"
echo "Do you want add deny users list?[Y|N]"
read ANS
case $ANS in
y|Y)
if [ -r /etc/deny.users ];then
rm -f /etc/deny.users
fi
touch /etc/deny.users
savepath="/etc/deny.users"
Account=`cat /etc/passwd|awk -F: '{ print $1 }'`
echo -n "Do you want numbers users:"
read Num
while [ $UserNum -lt $Num ]
do
echo "please input `expr $UserNum + 1` user name:"
read Username
for user in $Account
do
if [ "$user" = "$Username" ];then
echo $Username >>$savepath
fi
done
UserNum=`expr $UserNum + 1`
done
echo "Current Information:"
echo "Limit users numbers:`more /etc/deny.users|wc -l`"
echo "Deny users List:`more /etc/deny.users`"
;;
n|N)
rm -f $savepath
exit 1
;;
q|Q)
exit 1
;;
esac
echo "Do you want auto add /etc/profile?[Y|N]"
read NS
case $NS in
Y|y)
if [ ! -e /etc/profile.bak ];then
cp /etc/profile /etc/profile.bak
fi
echo 'logname=`whoami`'>>/etc/profile
echo 'while read i; do'>>/etc/profile
echo 'if [ $i = $logname ]; then'>>/etc/profile
echo 'echo "Sorry,$logname can not login" &&sleep 2 &&exit 1'>>/etc/profile
echo 'fi'>>/etc/profile
echo 'done </etc/deny.users'>>/etc/profile
;;
N|n)
rm -f $savepath
mv -f /etc/profile.bak /etc/profile
;;
esac