start-method revision 4173
#!/usr/sbin/sh
#
# 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 (c) 1991, 2015, Oracle and/or its affiliates. All rights reserved.
. /lib/svc/share/smf_include.sh
SWITCH_FMRI=svc:/system/name-service/switch:default
tweak_aliases()
{
aliasprop=$(/usr/bin/svcprop -p config/alias $SWITCH_FMRI 2>/dev/null)
# Check the alias configuration. Per
# http://www.postfix.org/postconf.5.html
# On systems with NIS, the default is to search the local alias
# database, then the NIS alias database.
# All Solaris systems ship "with NIS", but unless NIS is configured for
# aliases, this will cause problems, so check and tweak the default if
# NIS is not configured.
alias_maps=$(/usr/sbin/postconf -h alias_maps)
if [[ $alias_maps == "hash:/etc/mail/aliases, nis:mail.aliases" ]]; then
# We have the default Postfix setting.
if [[ "$aliasprop" == "${aliasprop/nis}" ]]; then
# NIS is not configured, so change the Postfix setting.
alias_maps="hash:/etc/mail/aliases"
/usr/sbin/postconf alias_maps=$alias_maps
fi
fi
# Check for LDAP: if configured via the switch, then (if needed)
# create $LDAP_ALIASES and configure in alias_maps.
LDAP_ALIASES=/etc/postfix/ldap-aliases.cf
if [[ $aliasprop != ${aliasprop/ldap} ]]; then
# LDAP is configured for aliases.
if [[ ! -f $LDAP_ALIASES ]]; then
# $LDAP_ALIASES does not exist yet, so create it.
servers=$(/usr/sbin/ldapclient list | \
grep NS_LDAP_SERVERS | \
sed -e 's/^.*=//' -e 's/,//g')
basedn=$(/usr/sbin/ldapclient list | \
grep NS_LDAP_SEARCH_BASEDN | sed -e 's/^.*= //')
echo "server_host = $servers" > $LDAP_ALIASES
echo "search_base = $basedn" >> $LDAP_ALIASES
echo "query_filter = mail=%s" >> $LDAP_ALIASES
echo "result_attribute = mgrpRFC822MailMember" >> \
$LDAP_ALIASES
fi
if [[ "$alias_maps" == "${alias_maps/ldap:}" ]]; then
# No "ldap:" entry yet in alias_maps, so add one.
/usr/sbin/postconf \
alias_maps="$alias_maps, ldap:$LDAP_ALIASES"
fi
fi
# Sendmail in Solaris 11 is linked with an old Berkeley DB version.
/usr/bin/db_upgrade /etc/mail/aliases.db
}
# First, make sure we have a valid domain name.
myhostname=$(/usr/bin/hostname)
case $myhostname in
*.*)
# Fully qualified: we're set.
;;
*)
# Unqualified; fall back to postconf.
mydomain=$(/usr/sbin/postconf -h mydomain)
case $mydomain in
*.*)
# Fully qualified: we're set.
;;
localdomain)
echo "Domain name cannot be determined."
echo "Either set hostname to a fully-qualified value,"
echo "or run '/usr/sbin/postconf mydomain=YOUR.DOMAIN'."
exit $SMF_EXIT_ERR_CONFIG
;;
esac
esac
# Second, tweak aliases for NIS and LDAP as needed.
auto=`/usr/bin/svcprop -c -p config/automatic $SMF_FMRI 2>/dev/null`
if [[ $auto == true ]]; then
tweak_aliases
fi
# Finally, start the daemon.
/usr/sbin/postfix start
exit 0