#!/bin/bash ################################################################# # # qnuke # # Another sheBANG bin BASH! production. # # A utility that will wipe jobs from the mail queue by user. # "I was inspired to write this after encountering a mail queue # containing 2000+ SirCam virii amongst legit mail jobs" # # chux0r - Copyright 2001, licensed under the LGPL # http://www.gnu.org/copyleft/lesser.txt # 1 Nov 2001 # # ################################################################# _vrfy_user() { if [ -f /etc/passwd ]; then USERLIST="/etc/passwd" elif [ -f /etc/security/passwd ]; then USERLIST="/etc/security/passwd" else echo "No passwd file found to verify existance of $2!" exit fi MATCH=`cut -d: -f1 $USERLIST | grep -c "^$USER$"` echo "MATCH ==$MATCH==" if [ $MATCH = "0" -o $MATCH = NULL ]; then echo "No matches for $USER found in $USERLIST." exit elif [ $MATCH -gt 1 ]; then echo "Multiple matches found for $USER:" cut -d: -f1 $USERLIST | grep "^$USER$" |uniq echo "...Exiting." exit fi VRFY=1 } USAGE="qnuke [-q \$PATH/dir|-h|-auto \$USERNAME]" QDIR="/var/spool/mqueue" TMPF="/tmp/rmfile" INTERACT=1 VRFY=0 if [ $# -gt 0 ]; then if [ $# -gt 1 ]; then if [ $1 = "-q" -a $# -eq 2 ]; then if [ -d $2 ]; then QDIR=$2 else echo "Queue Directory $2: Not found." exit fi elif [ $1 = "-auto" -a $# -eq 2 ]; then INTERACT=0 USER=$2 else echo $USAGE exit fi fi if [ $1 = "-h" ]; then echo $USAGE echo "-q specifies a queue directory other than the default /var/spool/mqueue" echo "-h lists this help" echo "-auto runs qnuke in non-interactive mode when a username is specified." echo " NOTE: NO username error-checking done in -auto mode, so you can use this" echo " to delete jobs by users spoofing addresses (ie. root@microsoft.com), but" echo " you MUST enter the address EXACTLY as it appears in the mailq listing." echo " One can also use this to nuke MAILER-DAEMON foo as well." exit fi fi if [ $INTERACT -eq 1 ]; then echo "Enter target user for mailqueue obliteration: " read USER _vrfy_user fi cd $QDIR if [ $VRFY -eq 0 ]; then mailq |grep "<$USER>" |cut -d" " -f1 > $TMPF else mailq |grep "<$USER@" |cut -d" " -f1 > $TMPF fi if [ -s $TMPF ]; then for QFILE in `cat $TMPF` do #rm -f df$QFILE #comment out to test #rm -f qf$QFILE #comment out to test ls -al df$QFILE #test line. done rm -f $TMPF else echo "No jobs beloging to $USER found in $QDIR" fi