xref: /titanic_50/usr/src/cmd/sendmail/lib/smtp-sendmail (revision 1ae0874509b6811fdde1dfd46f0d93fd09867a3f)
1#!/sbin/sh
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License, Version 1.0 only
7# (the "License").  You may not use this file except in compliance
8# with the License.
9#
10# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11# or http://www.opensolaris.org/os/licensing.
12# See the License for the specific language governing permissions
13# and limitations under the License.
14#
15# When distributing Covered Code, include this CDDL HEADER in each
16# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17# If applicable, add the following below this CDDL HEADER, with the
18# fields enclosed by brackets "[]" replaced with your own identifying
19# information: Portions Copyright [yyyy] [name of copyright owner]
20#
21# CDDL HEADER END
22#
23#
24# Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26#
27# ident	"%Z%%M%	%I%	%E% SMI"
28
29. /lib/svc/share/smf_include.sh
30
31ERRMSG1='WARNING: /var/mail is NFS-mounted without setting actimeo=0,'
32ERRMSG2='this can cause mailbox locking and access problems.'
33SERVER_PID_FILE="/var/run/sendmail.pid"
34CLIENT_PID_FILE="/var/spool/clientmqueue/sm-client.pid"
35DEFAULT_FILE="/etc/default/sendmail"
36ALIASES_FILE="/etc/mail/aliases"
37
38check_queue_interval_syntax()
39{
40	default="15m"
41	if [ $# -lt 1 ]; then
42		answer=$default
43		return
44	fi
45	if echo $1 | egrep '^([0-9]*[1-9][0-9]*[smhdw])+$' >/dev/null 2>&1; then
46		answer=$1
47	else
48		answer=$default
49	fi
50}
51
52check_and_kill()
53{
54	PID=`head -1 $1`
55	kill -0 $PID > /dev/null 2>&1
56	[ $? -eq 0 ] && kill $PID
57}
58
59case "$1" in
60'refresh')
61        [ -f $SERVER_PID_FILE ] && kill -1 `head -1 $SERVER_PID_FILE`
62        [ -f $CLIENT_PID_FILE ] && kill -1 `head -1 $CLIENT_PID_FILE`
63        ;;
64
65'start')
66	if [ ! -f /usr/lib/sendmail -o ! -f /etc/mail/sendmail.cf ]; then
67		exit $SMF_EXIT_ERR_CONFIG
68	fi
69	if [ ! -d /var/spool/mqueue ]; then
70		/usr/bin/mkdir -m 0750 /var/spool/mqueue
71		/usr/bin/chown root:bin /var/spool/mqueue
72	fi
73	if [ ! -f $ALIASES_FILE.db ] && [ ! -f $ALIASES_FILE.dir ] \
74	    && [ ! -f $ALIASES_FILE.pag ]; then
75		/usr/sbin/newaliases
76	fi
77	MODE="-bd"
78	[ -f $DEFAULT_FILE ] && . $DEFAULT_FILE
79	#
80	# * MODE should be "-bd" or null (MODE= or MODE="") or
81	#   left alone.  Anything else and you're on your own.
82	# * QUEUEOPTION should be "p" or null (as above).
83	# * [CLIENT]QUEUEINTERVAL should be set to some legal value;
84	#   sanity checks are done below.
85	# * [CLIENT]OPTIONS are catch-alls; set with care.
86	#
87	if [ -n "$QUEUEOPTION" -a "$QUEUEOPTION" != "p" ]; then
88		QUEUEOPTION=""
89	fi
90	if [ -z "$QUEUEOPTION" -o -n "$QUEUEINTERVAL" ]; then
91		check_queue_interval_syntax $QUEUEINTERVAL
92		QUEUEINTERVAL=$answer
93	fi
94	check_queue_interval_syntax $CLIENTQUEUEINTERVAL
95	CLIENTQUEUEINTERVAL=$answer
96	/usr/lib/sendmail $MODE -q$QUEUEOPTION$QUEUEINTERVAL $OPTIONS &
97	/usr/lib/sendmail -Ac -q$CLIENTQUEUEINTERVAL $CLIENTOPTIONS &
98	#
99	# ETRN_HOSTS should be of the form
100	# "s1:c1.1,c1.2        s2:c2.1 s3:c3.1,c3.2,c3.3"
101	# i.e., white-space separated groups of server:client where
102	# client can be one or more comma-separated names; N.B. that
103	# the :client part is optional; see etrn(1M) for details.
104	# server is the name of the server to prod; a mail queue run
105	# is requested for each client name.  This is comparable to
106	# running "/usr/lib/sendmail -qRclient" on the host server.
107	#
108	# See RFC 1985 for more information.
109	#
110	for i in $ETRN_HOSTS; do
111		SERVER=`echo $i | /usr/bin/sed -e 's/:.*$//'`
112		CLIENTS=`echo $i | /usr/bin/sed -n -e 's/,/ /g' \
113		    -e '/:/s/^.*://p'`
114		/usr/sbin/etrn -b $SERVER $CLIENTS >/dev/null 2>&1 &
115	done
116
117	if /usr/bin/nawk 'BEGIN{s = 1}
118	    $2 == "/var/mail" && $3 == "nfs" && $4 !~ /actimeo=0/ &&
119	    $4 !~ /noac/{s = 0} END{exit s}' /etc/mnttab; then
120
121		/usr/bin/logger -p mail.crit "$ERRMSG1"
122		/usr/bin/logger -p mail.crit "$ERRMSG2"
123	fi
124	;;
125
126'stop')
127	[ -f $SERVER_PID_FILE ] && check_and_kill $SERVER_PID_FILE
128	if [ -f $CLIENT_PID_FILE ]; then
129		check_and_kill $CLIENT_PID_FILE
130		rm -f $CLIENT_PID_FILE
131	fi
132	# Need to kill the entire service contract to kill all sendmail related
133	# processes
134	smf_kill_contract $2 TERM 1 30
135	ret=$?
136	[ $ret -eq 1 ] && exit 1
137
138	# Since sendmail spawns user processes out of .forward files, it is
139	# possible that some of these are not responding to TERM.  If the
140	# contract did not empty after TERM, move on to KILL.
141	if [ $ret -eq 2 ] ; then
142		smf_kill_contract $2 KILL 1
143	fi
144	;;
145
146*)
147	echo "Usage: $0 { start | stop | refresh }"
148	exit 1
149	;;
150esac
151exit 0
152