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