#!/bin/sh # description: start/stop Clam AntiVirus filter for sendmail # # default: S/K40 0/K40 1/K40 2/S87 # CDDL (http://hub.opensolaris.org/bin/view/Main/licensing) terms apply. # Copyright (c) 2006-2011 Jens Elkner. All rights reserved. # $Id: milter.method 445 2011-08-25 23:08:01Z elkner $ # ACCOUNT, under which the milter should run. # Default: smmsp ACCOUNT=smmsp # milter configuration file to use CONF=/etc/clamav/milter.conf # # no further changes should be required # if [ `uname -s` = "SunOS" -a -x /usr/bin/svcprop ]; then . /lib/svc/share/smf_include.sh if [ -n "$SMF_FMRI" ]; then val=`svcprop -p start/user $SMF_FMRI` [ -n "$val" ] && [ "$val" != "\"\"" ] && ACCOUNT="$val" val=`svcprop -p config-file/entities $SMF_FMRI | cut -f4- -d/` [ -n "$val" ] && [ "$val" != "\"\"" ] && CONF="/$val" fi ID=/usr/xpg4/bin/id ZN=`/sbin/zonename` if [ "$ZN" = "global" ]; then ZPPID=1 else ZPPID=`pgrep -x zsched 2>/dev/null` fi else SMF_EXIT_OK=0 SMF_EXIT_ERR_FATAL=95 SMF_EXIT_ERR_CONFIG=96 SMF_EXIT_ERR_PERM=100 ZPPID=1 ID=/usr/bin/id fi NAME="Clam AntiVirus mail filter daemon" SPATH=@CLIENT_BASEDIR@/sbin DAEMON="clamav-milter" case "$1" in 'start') if [ ! -f ${CONF} ]; then echo "Missing config file $CONF" exit $SMF_EXIT_ERR_CONFIG fi if [ ! -x $SPATH/$DAEMON ]; then echo "failed (unable to execute $SPATH/$DAEMON)." exit $SMF_EXIT_ERR_FATAL fi PIDS=`pgrep -x -u $ACCOUNT -P $ZPPID $DAEMON` if [ -n "$PIDS" ]; then echo "is already running." exit $SMF_EXIT_OK; fi # in case FixStaleSocket is not enabled, not doing this would # prevent the filter to work on the next start SOCK=`egrep '^[[:space:]]*MilterSocket[[:space:]]' $CONF | \ awk '{ print $2 }' | cut -f2 -d:` if [ -n "$SOCK" -a -r "$SOCK" ]; then rm -f $SOCK if [ $? -ne 0 ]; then echo "Unable to remove $SOCK - as long as it exist, $DAEMON would not start. So remove it manually, please." exit $SMF_EXIT_ERR_PERM fi fi echo "Starting $NAME ..." if [ `$ID -un` != "$ACCOUNT" ]; then /usr/bin/su - $ACCOUNT -c "$SPATH/$DAEMON -c $CONF" else $SPATH/$DAEMON -c $CONF fi if [ $? -ne 0 ]; then echo "$SPATH/$DAEMON -c $CONF failed." exit $SMF_EXIT_ERR_FATAL fi echo "done." ;; 'stop') echo "Stopping $NAME ..." pkill -KILL -x -u $ACCOUNT -P $ZPPID $DAEMON echo "done." ;; *) echo "Usage: $0 { start | stop }" exit $SMF_EXIT_ERR_FATAL ;; esac exit $SMF_EXIT_OK