#!/bin/sh # abiff 2.41 # by Adam M. Costello # # # Usage (in a .forward file): # # "| HOME=/path/to/home/dir /path/to/abiff [-c] user@host ..." # # The quote marks are literal, and necessary. Any number of user@host # arguments may be supplied. Be sure to forward your mail somewhere # else as well, such as \username (the backslash prevents an infinite # alias loop). # # abiff looks for elligible terminals in use by each user on the # corresponding host. To each terminal it finds, it writes a message # including the first few lines of the arriving mail. The remote # accounts must have .rhost files set up so that abiff can rsh to each # host using the corresponding user name. # # Without the -c option, eligible terminals are ones with group-execute # permission that are writable. With the -c option, eligible terminals # are ones with owner-execute permission that are writable. The latter # criterion is the same one used by normal biff (comsat). # # If -c is supplied, and any of the hosts in the argument list are the # same host on which abiff is running (i.e., the host to which the mail # was sent), then abiff will skip that host, because it assumes that # regular biff will take care of it. For performance reasons, the test # for equality of the hosts does not use the name service. See the # seekout() function below for the actual test. # # When -c is supplied in the .forward file, the biff command may # be used to to turn on and off both biff and abiff notification. # Otherwise, the commands "abiff y" and "abiff n" turn on and off abiff # notification. The command "abiff" outputs "is y" or "is n", depending # on the group-execute bit of the tty. # # I have tried to make abiff secure, but I make no guarantees. If you # find a security hole, please tell me! # # abiff depends on awk, cat, chmod, ls, mkdir, rsh, sort, tty, and # either /bin/hostname or uname. umask 077 if [ $# -eq 0 ]; then tty=`tty` || exit $? perm=`ls -lL $tty` || exit $? case $perm in ??????x*) echo "is y" ;; *) echo "is n" ;; esac exit 0 fi if [ $# -eq 1 ]; then if [ "$1" = y ]; then tty=`tty` || exit $? chmod g+x $tty exit $? fi if [ "$1" = n ]; then tty=`tty` || exit $? chmod g-x $tty exit $? fi fi if [ "$1" = -c ]; then compat=yes shift else compat=no fi export compat seekout () { oldIFS=$IFS IFS=@$oldIFS set -- $1 IFS=$oldIFS if [ $compat = yes ]; then [ "$2" != "$host" ] || return 0 case "$2" in "$host".*) return 0 ;; esac case "$host" in "$2".*) return 0 ;; esac fi cat $scriptfile | rsh -l "$1" "$2" /bin/sh -s "$1" } [ "$HOME" != "" ] || { echo "abiff error: HOME is not set" exit 1 } [ -d "$HOME"/.abiff ] || mkdir "$HOME"/.abiff tmpbase="$HOME"/.abiff/$$ scriptfile="$tmpbase"-s export scriptfile [ $compat = no ] || { if [ -x /bin/hostname ]; then host=`/bin/hostname` else host=`uname -n` fi export host } cat > $scriptfile << 'endcat' devs=` who | while read user tty junk; do [ $user != "$1" ] || echo /dev/$tty done | sort ` perms=` ls -lL $devs | while read perm junk; do echo $perm done ` set -- $perms for dev in $devs; do case $1 in endcat { if [ $compat = yes ]; then echo ' ???x*)' else echo ' ??????x*)' fi echo ' [ ! -w $dev ] || cat > $dev << "EnDcAt"' echo '' # You probably want to customize this part to your tastes: # echo "New mail has just arrived at ${host}:" awk 'inbody != "yes" && /^(To:|From:|Subject:)/ inbody != "yes" && /^$/ { inbody = "yes"; numbody = 0; } inbody == "yes" && $0 != "EnDcAt" && ! /^[ \t]*$/ { if (++numbody > 5) exit; print; }' echo 'EnDcAt' echo ' ;;' echo ' esac' echo ' shift' echo 'done' } >> $scriptfile for arg do case "$arg" in *@*) seekout "$arg" & ;; *) echo "abiff error: unexpected argument $arg" exit 1; ;; esac done wait rm $scriptfile