4172N/A#!/usr/sbin/sh
4172N/A#
4172N/A# CDDL HEADER START
4172N/A#
4172N/A# The contents of this file are subject to the terms of the
4172N/A# Common Development and Distribution License (the "License").
4172N/A# You may not use this file except in compliance with the License.
4172N/A#
4172N/A# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
4172N/A# or http://www.opensolaris.org/os/licensing.
4172N/A# See the License for the specific language governing permissions
4172N/A# and limitations under the License.
4172N/A#
4172N/A# When distributing Covered Code, include this CDDL HEADER in each
4172N/A# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
4172N/A# If applicable, add the following below this CDDL HEADER, with the
4172N/A# fields enclosed by brackets "[]" replaced with your own identifying
4172N/A# information: Portions Copyright [yyyy] [name of copyright owner]
4172N/A#
4172N/A# CDDL HEADER END
4172N/A#
4172N/A# Copyright (c) 1991, 2015, Oracle and/or its affiliates. All rights reserved.
4172N/A
4172N/A. /lib/svc/share/smf_include.sh
4172N/A
4172N/ASWITCH_FMRI=svc:/system/name-service/switch:default
4172N/A
4172N/Atweak_aliases()
4172N/A{
4173N/A aliasprop=$(/usr/bin/svcprop -p config/alias $SWITCH_FMRI 2>/dev/null)
4172N/A
4172N/A # Check the alias configuration. Per
4172N/A # http://www.postfix.org/postconf.5.html
4172N/A # On systems with NIS, the default is to search the local alias
4172N/A # database, then the NIS alias database.
4172N/A # All Solaris systems ship "with NIS", but unless NIS is configured for
4172N/A # aliases, this will cause problems, so check and tweak the default if
4172N/A # NIS is not configured.
4172N/A alias_maps=$(/usr/sbin/postconf -h alias_maps)
4172N/A if [[ $alias_maps == "hash:/etc/mail/aliases, nis:mail.aliases" ]]; then
4172N/A # We have the default Postfix setting.
4173N/A if [[ "$aliasprop" == "${aliasprop/nis}" ]]; then
4172N/A # NIS is not configured, so change the Postfix setting.
4172N/A alias_maps="hash:/etc/mail/aliases"
4172N/A /usr/sbin/postconf alias_maps=$alias_maps
4172N/A fi
4172N/A fi
4172N/A
4172N/A # Check for LDAP: if configured via the switch, then (if needed)
4172N/A # create $LDAP_ALIASES and configure in alias_maps.
4172N/A LDAP_ALIASES=/etc/postfix/ldap-aliases.cf
4173N/A if [[ $aliasprop != ${aliasprop/ldap} ]]; then
4172N/A # LDAP is configured for aliases.
4172N/A if [[ ! -f $LDAP_ALIASES ]]; then
4172N/A # $LDAP_ALIASES does not exist yet, so create it.
4172N/A servers=$(/usr/sbin/ldapclient list | \
4172N/A grep NS_LDAP_SERVERS | \
4172N/A sed -e 's/^.*=//' -e 's/,//g')
4172N/A basedn=$(/usr/sbin/ldapclient list | \
4172N/A grep NS_LDAP_SEARCH_BASEDN | sed -e 's/^.*= //')
4172N/A echo "server_host = $servers" > $LDAP_ALIASES
4172N/A echo "search_base = $basedn" >> $LDAP_ALIASES
4172N/A echo "query_filter = mail=%s" >> $LDAP_ALIASES
4172N/A echo "result_attribute = mgrpRFC822MailMember" >> \
4172N/A $LDAP_ALIASES
4172N/A
4172N/A fi
4173N/A if [[ "$alias_maps" == "${alias_maps/ldap:}" ]]; then
4172N/A # No "ldap:" entry yet in alias_maps, so add one.
4172N/A /usr/sbin/postconf \
4172N/A alias_maps="$alias_maps, ldap:$LDAP_ALIASES"
4172N/A fi
4172N/A fi
4173N/A
4173N/A # Sendmail in Solaris 11 is linked with an old Berkeley DB version.
4173N/A /usr/bin/db_upgrade /etc/mail/aliases.db
4172N/A}
4172N/A
4172N/A# First, make sure we have a valid domain name.
4172N/Amyhostname=$(/usr/bin/hostname)
4172N/Acase $myhostname in
4172N/A*.*)
4172N/A # Fully qualified: we're set.
4172N/A ;;
4172N/A*)
4172N/A # Unqualified; fall back to postconf.
4172N/A mydomain=$(/usr/sbin/postconf -h mydomain)
4172N/A case $mydomain in
4172N/A *.*)
4172N/A # Fully qualified: we're set.
4172N/A ;;
4172N/A localdomain)
4172N/A echo "Domain name cannot be determined."
4172N/A echo "Either set hostname to a fully-qualified value,"
4172N/A echo "or run '/usr/sbin/postconf mydomain=YOUR.DOMAIN'."
4172N/A exit $SMF_EXIT_ERR_CONFIG
4172N/A ;;
4172N/A esac
4172N/Aesac
4172N/A
4172N/A# Second, tweak aliases for NIS and LDAP as needed.
4172N/Aauto=`/usr/bin/svcprop -c -p config/automatic $SMF_FMRI 2>/dev/null`
4172N/Aif [[ $auto == true ]]; then
4172N/A tweak_aliases
4172N/Afi
4172N/A
4172N/A# Finally, start the daemon.
4172N/A/usr/sbin/postfix start
4172N/A
4172N/Aexit 0