voil� mon vacation.sh
aucune garantie, et j'aimerais bien des commentaires sur les probl�mes de
s�curit� caus�s par $SENDER
#!/bin/sh
# vacation.sh V1.4 MSC00, 13/08/00
#
# NAME
# vacation
# SYNOPSYS
# vacation.sh filename logfile historyfile
# USAGE
# in your .forward file, add, if your username is user,
# \user, "|/share/bin/vacation.sh /users/user/vacation.message
/users/user/vacation.log /users/user/vacation.history /users/user/tmpdir"
# DESCRIPTION
# Secure vacation program, it will not create mail loops nor send
# messages to mailer-daemons, and so on. Uses the historyfile to
# prevent sending the message twice. Logs any action taken or any
# errors to the logfile. Replies to a canonicalized form of the $SENDER
# with the rfcize program.
# CREDIT
# [EMAIL PROTECTED] (Marc SCHAEFER)
# NOTE
# The history file is used to be sure that only one occurence of
# this message will be sent, to avoid loops and other problems.
# When you change the content of filename (the explanation) you should
# always remove the historyfile.
# WARNINGS
# - This utility does NOT log the messages nor their content. You should
# have set up your .forward file to archive one copy on your standard
# mailbox, see above.
# - $HOME/tmp shall not be on NFS, and shall not be a softlink.
# DEPENDENCY
# Depends on your mailsystem setting $SENDER and running under your UID.
# Needs the rfcize package.
# UPDATE FROM VERSION 1.0 from 11/08/93
# Added more invalid addresses, and throwing of the pipe to prevent errors.
# UPDATE FROM VERSION 1.1 from 02/09/94
# rfcize canonicalization.
# UPDATE FROM VERSION 1.2 to 1.3 (23/02/97)
# - sendmail
# UPDATE FROM VERSION 1.3 to 1.4 (13/08/00)
# added locking and using a lock dir in $HOME
# BUGS
# - Maybe some security issues.
# $Id: vacation.sh,v 1.3 2000/08/13 11:00:32 schaefer Exp $
SENDER=`head -1 | awk '{print $2}'`
if [ $# != 4 ]; then
echo "$0 filename logfile historyfile tmpdir." >&2
echo "$0: bad arg count" >&2
exit 0 # yep
fi
TMPDIR=$4
if [ ! -d $TMPDIR ]; then
mkdir $TMPDIR && chmod 700 $TMPDIR
if [ $? != 0 ]; then
echo "$0: can't read secure directory." >&2
exit 0 # yep
fi
fi
LOCKFILE=$TMPDIR/lockfile-vacation
TMP_LOCKFILE=$LOCKFILE.tmp-$$
rm -f TMP_LOCKFILE && touch $TMP_LOCKFILE
if [ $? != 0 ]; then
echo "$0: can't create tmp lockfile." >&2
exit 0 # yep
fi
while ! ln $TMP_LOCKFILE $LOCKFILE 2> /dev/null;
do
sleep 5
done
# ahem, could use a trap for exit?
date >> $2 "+%d/%m/%Y %H:%M:%S Received mail from $SENDER"
# Checking for loops
cat > /dev/null # Empty pipe.
case $SENDER in
*Mailer-*|*uucp*|*Postmaster*|*news*|*root*|*MAILER*|*DAEMON*|*postmaster*)
echo >> $2 "Bad address."
rm -f $LOCKFILE $TMP_LOCKFILE
exit 0;; # yep
esac
# Checking for already-sent messages
if [ -f $3 ]; then
grep > /dev/null "$SENDER" $3 # security risk here
if [ $? = 0 ]; then
echo >> $2 "Message already sent."
rm -f $LOCKFILE $TMP_LOCKFILE
exit 0 # yep
fi
fi
echo >> $3 "$SENDER" # security risk here
(echo "Subject: Automated reply"
echo
cat $1) | /usr/lib/sendmail "$SENDER" # security risk here
if [ $? = 0 ]; then
echo >> $2 "Autoreply sent."
fi
rm -f $LOCKFILE $TMP_LOCKFILE
exit 0
--
http://www-internal.alphanet.ch/linux-leman/ avant de poser
une question.