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