1*9b5bf10aSMark Haywood#!/sbin/sh
2*9b5bf10aSMark Haywood#
3*9b5bf10aSMark Haywood# CDDL HEADER START
4*9b5bf10aSMark Haywood#
5*9b5bf10aSMark Haywood# The contents of this file are subject to the terms of the
6*9b5bf10aSMark Haywood# Common Development and Distribution License (the "License").
7*9b5bf10aSMark Haywood# You may not use this file except in compliance with the License.
8*9b5bf10aSMark Haywood#
9*9b5bf10aSMark Haywood# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*9b5bf10aSMark Haywood# or http://www.opensolaris.org/os/licensing.
11*9b5bf10aSMark Haywood# See the License for the specific language governing permissions
12*9b5bf10aSMark Haywood# and limitations under the License.
13*9b5bf10aSMark Haywood#
14*9b5bf10aSMark Haywood# When distributing Covered Code, include this CDDL HEADER in each
15*9b5bf10aSMark Haywood# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*9b5bf10aSMark Haywood# If applicable, add the following below this CDDL HEADER, with the
17*9b5bf10aSMark Haywood# fields enclosed by brackets "[]" replaced with your own identifying
18*9b5bf10aSMark Haywood# information: Portions Copyright [yyyy] [name of copyright owner]
19*9b5bf10aSMark Haywood#
20*9b5bf10aSMark Haywood# CDDL HEADER END
21*9b5bf10aSMark Haywood#
22*9b5bf10aSMark Haywood#
23*9b5bf10aSMark Haywood# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
24*9b5bf10aSMark Haywood#
25*9b5bf10aSMark Haywood
26*9b5bf10aSMark Haywood#
27*9b5bf10aSMark Haywood# Install DNS client service
28*9b5bf10aSMark Haywood#
29*9b5bf10aSMark Haywood
30*9b5bf10aSMark Haywood. /lib/svc/share/smf_include.sh
31*9b5bf10aSMark Haywood. /lib/svc/share/net_include.sh
32*9b5bf10aSMark Haywood
33*9b5bf10aSMark HaywoodSVCCFG=/usr/sbin/svccfg
34*9b5bf10aSMark HaywoodSVCPROP=/usr/bin/svcprop
35*9b5bf10aSMark HaywoodSVCADM=/usr/sbin/svcadm
36*9b5bf10aSMark Haywood
37*9b5bf10aSMark HaywoodDNS_NWAM_FMRI="svc:/network/physical:nwam"
38*9b5bf10aSMark HaywoodDNS_INSTALL_FMRI=$SMF_FMRI
39*9b5bf10aSMark Haywood
40*9b5bf10aSMark HaywoodDNS_INSTALL_PG="install_props"
41*9b5bf10aSMark Haywood
42*9b5bf10aSMark HaywoodDNS_UNDEFINED_STRING_PROP="\"\""
43*9b5bf10aSMark Haywood
44*9b5bf10aSMark Haywooddns_install_debug=0
45*9b5bf10aSMark Haywood
46*9b5bf10aSMark Haywoodunset dns_install_domain dns_install_servers dns_install_search
47*9b5bf10aSMark Haywood
48*9b5bf10aSMark Haywooddns_process_install_pg()
49*9b5bf10aSMark Haywood{
50*9b5bf10aSMark Haywood	dns_install_domain=""
51*9b5bf10aSMark Haywood	dns_install_servers=""
52*9b5bf10aSMark Haywood	dns_install_search=""
53*9b5bf10aSMark Haywood	config=0
54*9b5bf10aSMark Haywood
55*9b5bf10aSMark Haywood	#
56*9b5bf10aSMark Haywood	# Retrieve the name server property values.
57*9b5bf10aSMark Haywood	#
58*9b5bf10aSMark Haywood	prop=`$SVCPROP -p $DNS_INSTALL_PG/nameserver $DNS_INSTALL_FMRI`
59*9b5bf10aSMark Haywood	if [ $? -eq 0 -a "$prop" != "$NET_INADDR_ANY" ]; then
60*9b5bf10aSMark Haywood		dns_install_servers=$prop
61*9b5bf10aSMark Haywood		config=1
62*9b5bf10aSMark Haywood	fi
63*9b5bf10aSMark Haywood
64*9b5bf10aSMark Haywood	#
65*9b5bf10aSMark Haywood	# Retrieve the name service domain.
66*9b5bf10aSMark Haywood	#
67*9b5bf10aSMark Haywood	prop=`$SVCPROP -p $DNS_INSTALL_PG/domain $DNS_INSTALL_FMRI`
68*9b5bf10aSMark Haywood	if [ $? -eq 0 -a "$prop" != "$DNS_UNDEFINED_STRING_PROP" ]; then
69*9b5bf10aSMark Haywood		dns_install_domain=$prop
70*9b5bf10aSMark Haywood		config=1
71*9b5bf10aSMark Haywood	fi
72*9b5bf10aSMark Haywood
73*9b5bf10aSMark Haywood	#
74*9b5bf10aSMark Haywood	# Retrieve the search list.
75*9b5bf10aSMark Haywood	#
76*9b5bf10aSMark Haywood	prop=`$SVCPROP -p $DNS_INSTALL_PG/search $DNS_INSTALL_FMRI`
77*9b5bf10aSMark Haywood	if [ $? -eq 0 -a "$prop" != "$DNS_UNDEFINED_STRING_PROP" ]; then
78*9b5bf10aSMark Haywood		dns_install_search=$prop
79*9b5bf10aSMark Haywood		config=1
80*9b5bf10aSMark Haywood	fi
81*9b5bf10aSMark Haywood
82*9b5bf10aSMark Haywood	[ $config -ne 0 ] || return $SMF_EXIT_OK
83*9b5bf10aSMark Haywood
84*9b5bf10aSMark Haywood	#
85*9b5bf10aSMark Haywood	# Create the resolv.conf file.
86*9b5bf10aSMark Haywood	#
87*9b5bf10aSMark Haywood	/usr/bin/touch /etc/resolv.conf.$$
88*9b5bf10aSMark Haywood	if [ $? -ne 0 ]; then
89*9b5bf10aSMark Haywood		net_record_err "Error creating \"/etc/resolv.conf.$$\"" $?
90*9b5bf10aSMark Haywood		return $SMF_EXIT_ERR_FATAL
91*9b5bf10aSMark Haywood	fi
92*9b5bf10aSMark Haywood
93*9b5bf10aSMark Haywood	for j in $dns_install_servers
94*9b5bf10aSMark Haywood	do
95*9b5bf10aSMark Haywood		server=`echo $j | /usr/bin/sed s/\"//g`
96*9b5bf10aSMark Haywood		echo "nameserver $server" >>/etc/resolv.conf.$$
97*9b5bf10aSMark Haywood	done
98*9b5bf10aSMark Haywood
99*9b5bf10aSMark Haywood	if [ "$dns_install_domain" != "" ]; then
100*9b5bf10aSMark Haywood		echo "domain $dns_install_domain" >>/etc/resolv.conf.$$
101*9b5bf10aSMark Haywood	fi
102*9b5bf10aSMark Haywood
103*9b5bf10aSMark Haywood	if [ "$dns_install_search" != "" ]; then
104*9b5bf10aSMark Haywood		list="search"
105*9b5bf10aSMark Haywood		for j in $dns_install_search
106*9b5bf10aSMark Haywood		do
107*9b5bf10aSMark Haywood			domain=`echo $j | /usr/bin/sed s/\"//g`
108*9b5bf10aSMark Haywood			list="$list $domain"
109*9b5bf10aSMark Haywood		done
110*9b5bf10aSMark Haywood		echo $list >>/etc/resolv.conf.$$
111*9b5bf10aSMark Haywood	fi
112*9b5bf10aSMark Haywood
113*9b5bf10aSMark Haywood	/usr/bin/mv /etc/resolv.conf.$$ /etc/resolv.conf
114*9b5bf10aSMark Haywood	if [ $? -ne 0 ]; then
115*9b5bf10aSMark Haywood		err=$?
116*9b5bf10aSMark Haywood		msg="Error moving /etc/resolv.conf.$$ to \"/etc/resolv.conf\""
117*9b5bf10aSMark Haywood		net_record_err "$msg" $err
118*9b5bf10aSMark Haywood		return $SMF_EXIT_ERR_FATAL
119*9b5bf10aSMark Haywood	fi
120*9b5bf10aSMark Haywood
121*9b5bf10aSMark Haywood	/usr/bin/chmod 644 /etc/resolv.conf
122*9b5bf10aSMark Haywood	if [ $? -ne 0 ]; then
123*9b5bf10aSMark Haywood		err=$?
124*9b5bf10aSMark Haywood		msg="Error setting permissions on \"/etc/resolv.conf\""
125*9b5bf10aSMark Haywood		net_record_err "$msg" $err
126*9b5bf10aSMark Haywood		return $SMF_EXIT_ERR_FATAL
127*9b5bf10aSMark Haywood	fi
128*9b5bf10aSMark Haywood
129*9b5bf10aSMark Haywood	#
130*9b5bf10aSMark Haywood	# Create the nsswitch.conf file
131*9b5bf10aSMark Haywood	#
132*9b5bf10aSMark Haywood	/usr/bin/cp -f /etc/nsswitch.dns /etc/nsswitch.conf
133*9b5bf10aSMark Haywood	if [ $? -ne 0 ]; then
134*9b5bf10aSMark Haywood		err=$?
135*9b5bf10aSMark Haywood		msg="Error copying /etc/nsswitch.dns to \"/etc/nsswitch.conf\""
136*9b5bf10aSMark Haywood		net_record_err "$msg" $err
137*9b5bf10aSMark Haywood		return $SMF_EXIT_ERR_FATAL
138*9b5bf10aSMark Haywood	fi
139*9b5bf10aSMark Haywood
140*9b5bf10aSMark Haywood	/usr/bin/chmod 644 /etc/nsswitch.conf
141*9b5bf10aSMark Haywood	if [ $? -ne 0 ]; then
142*9b5bf10aSMark Haywood		err=$?
143*9b5bf10aSMark Haywood		msg="Error setting permissions on \"/etc/nsswitch.conf\""
144*9b5bf10aSMark Haywood		net_record_err "$msg" $err
145*9b5bf10aSMark Haywood		return $SMF_EXIT_ERR_FATAL
146*9b5bf10aSMark Haywood	fi
147*9b5bf10aSMark Haywood
148*9b5bf10aSMark Haywood	return $SMF_EXIT_OK
149*9b5bf10aSMark Haywood}
150*9b5bf10aSMark Haywood
151*9b5bf10aSMark Haywooddns_process_install()
152*9b5bf10aSMark Haywood{
153*9b5bf10aSMark Haywood	vout=`$SVCCFG -s $DNS_INSTALL_FMRI validate 2>&1`
154*9b5bf10aSMark Haywood	if [ "$vout" != "" ]; then
155*9b5bf10aSMark Haywood		msg="Validation errors in $DNS_INSTALL_FMRI:\n$vout"
156*9b5bf10aSMark Haywood		net_record_err "$msg" 0
157*9b5bf10aSMark Haywood		return $SMF_EXIT_ERR_CONFIG
158*9b5bf10aSMark Haywood	fi
159*9b5bf10aSMark Haywood
160*9b5bf10aSMark Haywood	ecode=$SMF_EXIT_OK
161*9b5bf10aSMark Haywood	errs=0
162*9b5bf10aSMark Haywood	cnt=0
163*9b5bf10aSMark Haywood	pg=`$SVCPROP -p $DNS_INSTALL_PG $DNS_INSTALL_FMRI`
164*9b5bf10aSMark Haywood	if [ $? -eq 0 ]; then
165*9b5bf10aSMark Haywood		if service_is_enabled $DNS_NWAM_FMRI; then
166*9b5bf10aSMark Haywood			echo "NWAM enabled. Install static" \
167*9b5bf10aSMark Haywood			    "DNS configuration ignored." | smf_console
168*9b5bf10aSMark Haywood			errs=`expr $errs +  1`
169*9b5bf10aSMark Haywood			ecode=$SMF_EXIT_ERR_CONFIG
170*9b5bf10aSMark Haywood		else
171*9b5bf10aSMark Haywood			dns_process_install_pg
172*9b5bf10aSMark Haywood			if [ $? -ne $SMF_EXIT_OK ]; then
173*9b5bf10aSMark Haywood				ecode=$?
174*9b5bf10aSMark Haywood				errs=`expr $errs +  1`
175*9b5bf10aSMark Haywood			else
176*9b5bf10aSMark Haywood				cnt=`expr $cnt +  1`
177*9b5bf10aSMark Haywood			fi
178*9b5bf10aSMark Haywood
179*9b5bf10aSMark Haywood		fi
180*9b5bf10aSMark Haywood		$SVCCFG -s $DNS_INSTALL_FMRI delpg $DNS_INSTALL_PG
181*9b5bf10aSMark Haywood		$SVCCFG -s $DNS_INSTALL_FMRI refresh
182*9b5bf10aSMark Haywood	fi
183*9b5bf10aSMark Haywood
184*9b5bf10aSMark Haywood	if [ $dns_install_debug -eq 1 ]; then
185*9b5bf10aSMark Haywood		if [ $errs -ne 0 ]; then
186*9b5bf10aSMark Haywood			echo "$errs errors encountered" \
187*9b5bf10aSMark Haywood			    "configuring DNS on behalf of install"
188*9b5bf10aSMark Haywood		fi
189*9b5bf10aSMark Haywood
190*9b5bf10aSMark Haywood		if [ $cntf -ne 0 ]; then
191*9b5bf10aSMark Haywood			echo "DNS configured on behalf of install"
192*9b5bf10aSMark Haywood		fi
193*9b5bf10aSMark Haywood	fi
194*9b5bf10aSMark Haywood
195*9b5bf10aSMark Haywood	return $ecode
196*9b5bf10aSMark Haywood}
197*9b5bf10aSMark Haywood
198*9b5bf10aSMark Haywood#
199*9b5bf10aSMark Haywood# Script execution starts here.
200*9b5bf10aSMark Haywood#
201*9b5bf10aSMark Haywooddns_process_install || exit $?
202*9b5bf10aSMark Haywood
203*9b5bf10aSMark Haywood$SVCADM disable $DNS_INSTALL_FMRI
204*9b5bf10aSMark Haywoodexit $SMF_EXIT_OK