author | akshay.kale@oracle.com <akshay.kale@oracle.com> |
Fri, 14 Oct 2016 13:13:27 -0700 | |
changeset 7112 | dab9beb5bc49 |
parent 4153 | cac8dc6507e3 |
permissions | -rw-r--r-- |
4079 | 1 |
#!/usr/sbin/sh |
2 |
# |
|
3 |
# CDDL HEADER START |
|
4 |
# |
|
5 |
# The contents of this file are subject to the terms of the |
|
6 |
# Common Development and Distribution License (the "License"). |
|
7 |
# You may not use this file except in compliance with the License. |
|
8 |
# |
|
9 |
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
|
10 |
# or http://www.opensolaris.org/os/licensing. |
|
11 |
# See the License for the specific language governing permissions |
|
12 |
# and limitations under the License. |
|
13 |
# |
|
14 |
# When distributing Covered Code, include this CDDL HEADER in each |
|
15 |
# file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
|
16 |
# If applicable, add the following below this CDDL HEADER, with the |
|
17 |
# fields enclosed by brackets "[]" replaced with your own identifying |
|
18 |
# information: Portions Copyright [yyyy] [name of copyright owner] |
|
19 |
# |
|
20 |
# CDDL HEADER END |
|
21 |
# |
|
22 |
# Copyright (c) 1991, 2015, Oracle and/or its affiliates. All rights reserved. |
|
23 |
||
24 |
. /lib/svc/share/smf_include.sh |
|
25 |
||
26 |
SWITCH_FMRI=svc:/system/name-service/switch:default |
|
27 |
||
28 |
tweak_aliases() |
|
29 |
{ |
|
4153
cac8dc6507e3
20918093 postfix manifests & start method need tweaks
John Beck <John.Beck@Oracle.COM>
parents:
4079
diff
changeset
|
30 |
aliasprop=$(/usr/bin/svcprop -p config/alias $SWITCH_FMRI 2>/dev/null) |
4079 | 31 |
|
32 |
# Check the alias configuration. Per |
|
33 |
# http://www.postfix.org/postconf.5.html |
|
34 |
# On systems with NIS, the default is to search the local alias |
|
35 |
# database, then the NIS alias database. |
|
36 |
# All Solaris systems ship "with NIS", but unless NIS is configured for |
|
37 |
# aliases, this will cause problems, so check and tweak the default if |
|
38 |
# NIS is not configured. |
|
39 |
alias_maps=$(/usr/sbin/postconf -h alias_maps) |
|
40 |
if [[ $alias_maps == "hash:/etc/mail/aliases, nis:mail.aliases" ]]; then |
|
41 |
# We have the default Postfix setting. |
|
4153
cac8dc6507e3
20918093 postfix manifests & start method need tweaks
John Beck <John.Beck@Oracle.COM>
parents:
4079
diff
changeset
|
42 |
if [[ "$aliasprop" == "${aliasprop/nis}" ]]; then |
4079 | 43 |
# NIS is not configured, so change the Postfix setting. |
44 |
alias_maps="hash:/etc/mail/aliases" |
|
45 |
/usr/sbin/postconf alias_maps=$alias_maps |
|
46 |
fi |
|
47 |
fi |
|
48 |
||
49 |
# Check for LDAP: if configured via the switch, then (if needed) |
|
50 |
# create $LDAP_ALIASES and configure in alias_maps. |
|
51 |
LDAP_ALIASES=/etc/postfix/ldap-aliases.cf |
|
4153
cac8dc6507e3
20918093 postfix manifests & start method need tweaks
John Beck <John.Beck@Oracle.COM>
parents:
4079
diff
changeset
|
52 |
if [[ $aliasprop != ${aliasprop/ldap} ]]; then |
4079 | 53 |
# LDAP is configured for aliases. |
54 |
if [[ ! -f $LDAP_ALIASES ]]; then |
|
55 |
# $LDAP_ALIASES does not exist yet, so create it. |
|
56 |
servers=$(/usr/sbin/ldapclient list | \ |
|
57 |
grep NS_LDAP_SERVERS | \ |
|
58 |
sed -e 's/^.*=//' -e 's/,//g') |
|
59 |
basedn=$(/usr/sbin/ldapclient list | \ |
|
60 |
grep NS_LDAP_SEARCH_BASEDN | sed -e 's/^.*= //') |
|
61 |
echo "server_host = $servers" > $LDAP_ALIASES |
|
62 |
echo "search_base = $basedn" >> $LDAP_ALIASES |
|
63 |
echo "query_filter = mail=%s" >> $LDAP_ALIASES |
|
64 |
echo "result_attribute = mgrpRFC822MailMember" >> \ |
|
65 |
$LDAP_ALIASES |
|
66 |
||
67 |
fi |
|
4153
cac8dc6507e3
20918093 postfix manifests & start method need tweaks
John Beck <John.Beck@Oracle.COM>
parents:
4079
diff
changeset
|
68 |
if [[ "$alias_maps" == "${alias_maps/ldap:}" ]]; then |
4079 | 69 |
# No "ldap:" entry yet in alias_maps, so add one. |
70 |
/usr/sbin/postconf \ |
|
71 |
alias_maps="$alias_maps, ldap:$LDAP_ALIASES" |
|
72 |
fi |
|
73 |
fi |
|
74 |
} |
|
75 |
||
76 |
# First, make sure we have a valid domain name. |
|
77 |
myhostname=$(/usr/bin/hostname) |
|
78 |
case $myhostname in |
|
79 |
*.*) |
|
80 |
# Fully qualified: we're set. |
|
81 |
;; |
|
82 |
*) |
|
83 |
# Unqualified; fall back to postconf. |
|
84 |
mydomain=$(/usr/sbin/postconf -h mydomain) |
|
85 |
case $mydomain in |
|
86 |
*.*) |
|
87 |
# Fully qualified: we're set. |
|
88 |
;; |
|
89 |
localdomain) |
|
90 |
echo "Domain name cannot be determined." |
|
91 |
echo "Either set hostname to a fully-qualified value," |
|
92 |
echo "or run '/usr/sbin/postconf mydomain=YOUR.DOMAIN'." |
|
93 |
exit $SMF_EXIT_ERR_CONFIG |
|
94 |
;; |
|
95 |
esac |
|
96 |
esac |
|
97 |
||
98 |
# Second, tweak aliases for NIS and LDAP as needed. |
|
99 |
auto=`/usr/bin/svcprop -c -p config/automatic $SMF_FMRI 2>/dev/null` |
|
100 |
if [[ $auto == true ]]; then |
|
101 |
tweak_aliases |
|
102 |
fi |
|
103 |
||
104 |
# Finally, start the daemon. |
|
105 |
/usr/sbin/postfix start |
|
106 |
||
107 |
exit 0 |