#!/bin/sh -
#
# @(#)mk-afs-wrap-sendmail	1.4 (hursley) 11/1/96
# /afs/hursley.ibm.com/common/src/afs/@cell/rs_aix32/usr/local/sbin/mk-afs-wrap-sendmail/SCCS/s.mk-afs-wrap-sendmail
#
# NAME		mk-afs-wrap-sendmail
# AUTHOR	Paul Blackburn <mpb@acm.org>
# PURPOSE	Wrapper to get AFS authentication and then start sendmail.
#
# USAGE		After mk-afs-odmfix-sendmail has changed the sendmail invocation
#		for srcmstr (in the AIX ODM),  normal srcmstr commands
#               to be used to stop and start the AFS authenticated sendmail
#		daemon via mk-afs-wrap-sendmail
#
#		    stopsrc -s sendmail
#		    startsrc -s sendmail  -a "-bd -q30m"
#
# CAUTION	Do not attempt to use the mk-afs-wrap-sendmail wrapper program
#		unless you have:
#		a) a working reauth installed (eg: /usr/etc/mk-afs-reauth)
#		b) configured mk-afs-wrap-sendmail to authenticate as an AFS ID
#		   (eg postman) authorised to append to $HOME/.mail
#		c) Set an ACL on $HOME/.mail to allow write access
#		   (eg: fs sa $HOME postman rliwk)
#
#		See: ftp://grand.central.org:/pub/afs-contrib/tools/reauth

CMD=`basename ${0}`
LOGDIR=/var/log
LOG=${LOGDIR}/${CMD}

# functions

tstamp() {
	echo "`date '+''%H''%M'':%S'` ${CMD}: ${1}"
}

warning() {
	echo "${CMD} warning: ${1}" >&2
}

error() {
        echo "${CMD} error: ${1}" >&2
}

fatal() {
        echo "${CMD} fatal: ${1}" >&2
	exit 1
}

doit() {
	tstamp "${1}"
	eval ${1}

	retcode=$?
	if [ ${retcode} != 0 ]; then
		error "\$?=${retcode}"
	fi
}

mkdir -p ${LOGDIR} 2>/dev/null          # make sure we have a LOGDIR

echo "stdout and stderr now being written to ${LOG}"
exec 4>&2
exec 3>&1
exec 1>>${LOG}
exec 2>&1

tstamp "version 1.4 commenced on `date '+%a %d %h %y'`"

WRAPPER=${afs_install_base}/usr/local/sbin/mk-afs-wrapper

if [ ! -x "${WRAPPER}" ]; then
	fatal "unable to execute ${WRAPPER}"
fi

daemon=/usr/lib/sendmail
afs_id=postman
pwfile=/etc/security/afs_pw_postman

doit "${WRAPPER} -d ${daemon} -dargs \"-bd -q30m\" -id ${afs_id} -p ${pwfile}"

tstamp "completed"
