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