#!/bin/ksh93 # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # Copyright 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # Portions Copyright 2007, 2014, Jens Elkner. . /lib/svc/share/smf_include.sh # Actually there is no reason to phase out this part into a separate file. # However, for compatibility reasons we need to bloat the system as well :((( . /lib/svc/share/sendmail_include.sh NEWALIASES='/usr/sbin/newaliases' ALIASES_FILE='/etc/mail/aliases' ETRN='/usr/sbin/etrn' typeset -r DEFAULTS=( [qdir]='/var/spool/mqueue' [qown]='root' [qgrp]='bin' [qperm]='0750' [cf]='/etc/mail/sendmail.cf' [mc]='/etc/mail/sendmail.mc' [aliases]='/etc/mail/aliases' [pidfile]="${SMF_SYSVOL_FS:-/var/run}/sendmail.pid" [mode]='-bd' [prop_mc]='config/path_to_sendmail_mc' [prop_cf]='config/path_to_cf' ) typeset -r CLIENTDEFAULTS=( [qdir]='/var/spool/clientmqueue' [qown]='smmsp' [qgrp]='smmsp' [qperm]='0770' [cf]='/etc/mail/submit.cf' [mc]='/etc/mail/submit.mc' [pidfile]='/var/spool/clientmqueue/sm-client.pid' [mode]='-Ac' [prop_mc]='config/path_to_submit_mc' [prop_cf]='config/path_to_cf' ) # determine the target function getTarget { typeset BN typeset -n VAL=$1 VAL=-1 if [[ -n ${SMF_FMRI} ]]; then BN=${SMF_FMRI%:*} if [[ ${BN: -6:6} == 'sendmail-client' ]]; then VAL=0 elif [[ ${SMF_FMRI##*/} == 'smtp:sendmail' ]]; then VAL=1 fi fi if (( VAL == -1 )); then BN=${.sh.file##*/} # this script or link basename name starts with ... ? if [[ ${BN:0:13} == 'smtp-sendmail' ]]; then VAL=1 elif [[ ${BN:0:15} == 'sendmail-client' ]]; then VAL=0 else print -u2 'WARNING: Unable to determine, whether to apply the' \ 'command to the client or server. Falling back to client.' VAL=0 fi fi } # IPS does not support postinstall scripts =8-( function postInstall { typeset X FILES="trusted-users ${SMDEFAULTS[mc]##*/}" if (( SERVER )); then FILES+=' aliases local-host-names' [[ ! -e /var/log/sendmail.st ]] && touch /var/log/sendmail.st # enable stats fi for X in ${FILES} ; do [[ ! -e /etc/mail/$X ]] && cp -p "${CF_BASEDIR}/defaults/$X" /etc/mail/ done typeset -A S typeset SVC PP TAIL while read SVC PP TAIL ; do [[ -z ${SVC} || ${SVC:0:1} == '#' ]] && continue S["${SVC}"]="${PP}" done < /etc/services typeset -A SVCS SVCS[smtp]=( pp='25/tcp mail' desc='# Simple Mail Transfer Protocol' ) SVCS[ident]=( pp='113/tcp auth' desc='# Identification Protocol' ) SVCS[submission]=( pp='587/tcp' desc='# Mail Submission Agent' ) TAIL='' for SVC in ${!SVCS[@]} ; do PP="${S[${SVC}]}" [[ -z ${PP} || ${PP: -4} != '/tcp' ]] && \ TAIL+="${SVC}\t\t${SVCS[${SVC}].pp}\t\t${SVCS[${SVC}].desc}\n" done [[ -n ${TAIL} ]] && print -n "${TAIL}" >>/etc/services } # just in case, one want's to see, what's going on here ;-) #set -x ; typeset -ft ${ typeset +f ; } integer SERVER getTarget SERVER (( SERVER )) && PREFIX='' || PREFIX=CLIENT typeset -n SMDEFAULTS=${PREFIX}DEFAULTS \ QOPT=${PREFIX}QUEUEOPTION QINTERVAL=${PREFIX}QUEUEINTERVAL \ OPTS=${PREFIX}OPTIONS DMODE=${PREFIX}MODE case "$1" in 'refresh') check_and_kill ${SMDEFAULTS[pidfile]} HUP ;; 'start') exist_or_exit ${SENDMAIL} DMODE=${SMDEFAULTS[mode]} # Source in "tweakings": # * MODE should be '-bd' or null (MODE= or MODE='') or # left alone. Anything else and you're on your own. # * CLIENTMODE should be '-Ac' or null (as above) or # left alone. Anything else and you're on your own. # * [CLIENT]QUEUEOPTION should be "p" or null (as above). # * [CLIENT]QUEUEINTERVAL should be set to some legal value; # sanity checks are done below. # * [CLIENT]OPTIONS are catch-alls; set with care. [[ -f ${DEFAULT_FILE} ]] && . ${DEFAULT_FILE} getSvcProp config/mode X [[ -n $X ]] && DMODE="$X" getSvcProp config/prunner X if [[ -n $X ]]; then [[ $X == 'true' ]] && QOPT='p' || QOPT='' elif [[ ${QOPT} != 'p' ]]; then QOPT='' fi getSvcProp config/qinterval X [[ -n $X ]] && QINTERVAL="$X" [[ -z ${QOPT} || -n ${QINTERVAL} ]] && \ check_queue_interval_syntax "${QINTERVAL}" QINTERVAL # ensure *.cf file is availavble typeset MC CF getSvcProp ${SMDEFAULTS[prop_mc]} MC getSvcProp ${SMDEFAULTS[prop_cf]} CF || CF=${SMDEFAULTS[cf]} if [[ -z ${MC} || ! -e ${MC} ]] && [[ ! -e ${CF} ]]; then postInstall [[ -z ${MC} ]] && MC=${SMDEFAULTS[mc]} fi turn_m4_crank "${CF}" "${MC}" exist_or_exit "${CF}" # ensure queue dir exists if [[ ! -d ${SMDEFAULTS[qdir]} ]]; then mkdir -m ${SMDEFAULTS[perm]} ${SMDEFAULTS[qdir]} chown ${SMDEFAULTS[qown]}:${SMDEFAULTS[qgrp]} ${SMDEFAULTS[qdir]} fi if (( SERVER )) ; then # run newaliases if db file[s] are missing [[ -f ${ALIASES_FILE}.db || \ ( -f ${ALIASES_FILE}.dir && -f ${ALIASES_FILE}.pag ) ]] || \ ${NEWALIASES} # check for 'listen to loopback, only' mode getSvcProp 'config/local_only' LOCAL [[ ${LOCAL} == 'true' ]] && DMODE='-bl' fi unset SVCOPTS # make sure we don't cary any other stuff typeset -a SVCOPTS getSvcProps config/options SVCOPTS (( ${#SVCOPTS[@]} )) && OPTS='' ${SENDMAIL} ${DMODE} -q${QOPT}${QINTERVAL} "${SVCOPTS[@]}" ${OPTS} & if (( SERVER )) ; then # ETRN_HOSTS should be of the form # "s1:c1.1,c1.2 s2:c2.1 s3:c3.1,c3.2,c3.3" # i.e., white-space separated groups of server:client where # client can be one or more comma-separated names; N.B. that # the :client part is optional; see etrn(1M) for details. # server is the name of the server to prod; a mail queue run # is requested for each client name. This is comparable to # running "/usr/lib/sendmail -qRclient" on the host server. # # See RFC 1985 for more information. X=${ whence perl ; } # no perl, no etrn [[ -n $X ]] && getSvcProp config/etrn X || X='' [[ -n $X ]] && ETRN_HOSTS="$X" for I in ${ETRN_HOSTS}; do SERVER={I%%:*} CLIENTS={.sh.match#:} CLIENTS={CLIENTS//,/ } ${ETRN} -b ${SERVER} ${CLIENTS} >/dev/null 2>&1 & done while read DEV MPNT FS MOPTS TAIL ; do if [[ ${MPNT} == '/var/mail' ]]; then [[ ${FS} != 'nfs' || ${MOPTS} =~ (actimeo=0|noac) ]] || \ /usr/bin/logger -p mail.crit \ 'WARNING: /var/mail is NFS-mounted without setting actimeo=0,' \ 'this can cause mailbox locking and access problems.' break fi done < /etc/mnttab fi ;; 'stop') check_and_kill ${SMDEFAULTS[pidfile]} # Need to kill the entire service contract to kill all sendmail related # processes smf_kill_contract $2 TERM 1 30 I=$? (( I == 1 )) && exit 1 # Since sendmail spawns user processes out of .forward files, it is # possible that some of these are not responding to TERM or that it is # waiting for things like child processes and SMTP connections to clean # up. If the contract did not empty after TERM, move on to KILL. (( I == 2 )) && smf_kill_contract $2 KILL 1 ;; *) print -u2 "Usage: $0 { start | stop | refresh }" exit 1 ;; esac exit ${SMF_EXIT_OK}