diff options
author | Mark Haywood <Mark.Haywood@Oracle.COM> | 2010-07-27 20:35:25 -0400 |
---|---|---|
committer | Mark Haywood <Mark.Haywood@Oracle.COM> | 2010-07-27 20:35:25 -0400 |
commit | 9b5bf10ab04b9be5564d70a57980cfb68b6372e7 (patch) | |
tree | 4eb6a11161f8b5338c1411a51a71cd00004c3ca1 /usr/src/lib/libresolv2 | |
parent | ae3d7f90695ef456a6da4f7bdccd448ebe0b99e1 (diff) | |
download | illumos-joyent-9b5bf10ab04b9be5564d70a57980cfb68b6372e7.tar.gz |
PSARC/2010/164 interfaces for basic install network configuration
6923163 Automated Install requires mechanism for configuring static IP addresses
6923168 Automated Install requires a mechanism for configuring name services for clients
Diffstat (limited to 'usr/src/lib/libresolv2')
-rw-r--r-- | usr/src/lib/libresolv2/Makefile | 21 | ||||
-rw-r--r-- | usr/src/lib/libresolv2/dns-install | 204 | ||||
-rw-r--r-- | usr/src/lib/libresolv2/install.xml | 137 |
3 files changed, 357 insertions, 5 deletions
diff --git a/usr/src/lib/libresolv2/Makefile b/usr/src/lib/libresolv2/Makefile index b6bc1c7076..2e9e919762 100644 --- a/usr/src/lib/libresolv2/Makefile +++ b/usr/src/lib/libresolv2/Makefile @@ -19,21 +19,25 @@ # CDDL HEADER END # # -# Copyright 2010 Sun Microsystems, Inc. All rights reserved. -# Use is subject to license terms. -# +# Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved. # include ../../Makefile.master include ../Makefile.lib -MANIFEST= client.xml +MANIFEST= client.xml install.xml MANIFESTDIR= $(ROOT)/lib/svc/manifest/network/dns ROOTMANIFEST= $(MANIFEST:%=$(MANIFESTDIR)/%) $(ROOTMANIFEST) := FILEMODE = 444 +SVCMETHOD= dns-install +SVCMETHODDIR= $(ROOT)/lib/svc/method +ROOTSVCMETHOD= $(SVCMETHOD:%=$(SVCMETHODDIR)/%) + +$(ROOTSVCMETHOD) := FILEMODE = 0555 + CHKMANIFEST= $(MANIFEST:%.xml=%.xmlchk) SUBDIRS= include $(MACH) @@ -59,7 +63,7 @@ GREP= grep all clean clobber lint: $(SUBDIRS) -install: $(SUBDIRS) $(ROOTMANIFEST) +install: $(SUBDIRS) $(ROOTMANIFEST) $(ROOTSVCMETHOD) $(ROOTMANIFEST): $(MANIFESTDIR) @@ -68,6 +72,13 @@ $(MANIFESTDIR): $(MANIFESTDIR)/%: % $(INS.file) +$(ROOTSVCMETHOD): $(SVCMETHODDIR) + +$(SVCMETHODDIR): + $(INS.dir) + +$(SVCMETHODDIR)/%: % + $(INS.file) # install rule for install_h target $(ROOTHDRDIR)/%: % diff --git a/usr/src/lib/libresolv2/dns-install b/usr/src/lib/libresolv2/dns-install new file mode 100644 index 0000000000..d5c17e205d --- /dev/null +++ b/usr/src/lib/libresolv2/dns-install @@ -0,0 +1,204 @@ +#!/sbin/sh +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License (the "License"). +# You may not use this file except in compliance with the License. +# +# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE +# or http://www.opensolaris.org/os/licensing. +# See the License for the specific language governing permissions +# and limitations under the License. +# +# When distributing Covered Code, include this CDDL HEADER in each +# file and include the License file at usr/src/OPENSOLARIS.LICENSE. +# If applicable, add the following below this CDDL HEADER, with the +# fields enclosed by brackets "[]" replaced with your own identifying +# information: Portions Copyright [yyyy] [name of copyright owner] +# +# CDDL HEADER END +# +# +# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. +# + +# +# Install DNS client service +# + +. /lib/svc/share/smf_include.sh +. /lib/svc/share/net_include.sh + +SVCCFG=/usr/sbin/svccfg +SVCPROP=/usr/bin/svcprop +SVCADM=/usr/sbin/svcadm + +DNS_NWAM_FMRI="svc:/network/physical:nwam" +DNS_INSTALL_FMRI=$SMF_FMRI + +DNS_INSTALL_PG="install_props" + +DNS_UNDEFINED_STRING_PROP="\"\"" + +dns_install_debug=0 + +unset dns_install_domain dns_install_servers dns_install_search + +dns_process_install_pg() +{ + dns_install_domain="" + dns_install_servers="" + dns_install_search="" + config=0 + + # + # Retrieve the name server property values. + # + prop=`$SVCPROP -p $DNS_INSTALL_PG/nameserver $DNS_INSTALL_FMRI` + if [ $? -eq 0 -a "$prop" != "$NET_INADDR_ANY" ]; then + dns_install_servers=$prop + config=1 + fi + + # + # Retrieve the name service domain. + # + prop=`$SVCPROP -p $DNS_INSTALL_PG/domain $DNS_INSTALL_FMRI` + if [ $? -eq 0 -a "$prop" != "$DNS_UNDEFINED_STRING_PROP" ]; then + dns_install_domain=$prop + config=1 + fi + + # + # Retrieve the search list. + # + prop=`$SVCPROP -p $DNS_INSTALL_PG/search $DNS_INSTALL_FMRI` + if [ $? -eq 0 -a "$prop" != "$DNS_UNDEFINED_STRING_PROP" ]; then + dns_install_search=$prop + config=1 + fi + + [ $config -ne 0 ] || return $SMF_EXIT_OK + + # + # Create the resolv.conf file. + # + /usr/bin/touch /etc/resolv.conf.$$ + if [ $? -ne 0 ]; then + net_record_err "Error creating \"/etc/resolv.conf.$$\"" $? + return $SMF_EXIT_ERR_FATAL + fi + + for j in $dns_install_servers + do + server=`echo $j | /usr/bin/sed s/\"//g` + echo "nameserver $server" >>/etc/resolv.conf.$$ + done + + if [ "$dns_install_domain" != "" ]; then + echo "domain $dns_install_domain" >>/etc/resolv.conf.$$ + fi + + if [ "$dns_install_search" != "" ]; then + list="search" + for j in $dns_install_search + do + domain=`echo $j | /usr/bin/sed s/\"//g` + list="$list $domain" + done + echo $list >>/etc/resolv.conf.$$ + fi + + /usr/bin/mv /etc/resolv.conf.$$ /etc/resolv.conf + if [ $? -ne 0 ]; then + err=$? + msg="Error moving /etc/resolv.conf.$$ to \"/etc/resolv.conf\"" + net_record_err "$msg" $err + return $SMF_EXIT_ERR_FATAL + fi + + /usr/bin/chmod 644 /etc/resolv.conf + if [ $? -ne 0 ]; then + err=$? + msg="Error setting permissions on \"/etc/resolv.conf\"" + net_record_err "$msg" $err + return $SMF_EXIT_ERR_FATAL + fi + + # + # Create the nsswitch.conf file + # + /usr/bin/cp -f /etc/nsswitch.dns /etc/nsswitch.conf + if [ $? -ne 0 ]; then + err=$? + msg="Error copying /etc/nsswitch.dns to \"/etc/nsswitch.conf\"" + net_record_err "$msg" $err + return $SMF_EXIT_ERR_FATAL + fi + + /usr/bin/chmod 644 /etc/nsswitch.conf + if [ $? -ne 0 ]; then + err=$? + msg="Error setting permissions on \"/etc/nsswitch.conf\"" + net_record_err "$msg" $err + return $SMF_EXIT_ERR_FATAL + fi + + return $SMF_EXIT_OK +} + +dns_process_install() +{ + vout=`$SVCCFG -s $DNS_INSTALL_FMRI validate 2>&1` + if [ "$vout" != "" ]; then + msg="Validation errors in $DNS_INSTALL_FMRI:\n$vout" + net_record_err "$msg" 0 + return $SMF_EXIT_ERR_CONFIG + fi + + ecode=$SMF_EXIT_OK + errs=0 + cnt=0 + pg=`$SVCPROP -p $DNS_INSTALL_PG $DNS_INSTALL_FMRI` + if [ $? -eq 0 ]; then + if service_is_enabled $DNS_NWAM_FMRI; then + echo "NWAM enabled. Install static" \ + "DNS configuration ignored." | smf_console + errs=`expr $errs + 1` + ecode=$SMF_EXIT_ERR_CONFIG + else + dns_process_install_pg + if [ $? -ne $SMF_EXIT_OK ]; then + ecode=$? + errs=`expr $errs + 1` + else + cnt=`expr $cnt + 1` + fi + + fi + $SVCCFG -s $DNS_INSTALL_FMRI delpg $DNS_INSTALL_PG + $SVCCFG -s $DNS_INSTALL_FMRI refresh + fi + + if [ $dns_install_debug -eq 1 ]; then + if [ $errs -ne 0 ]; then + echo "$errs errors encountered" \ + "configuring DNS on behalf of install" + fi + + if [ $cntf -ne 0 ]; then + echo "DNS configured on behalf of install" + fi + fi + + return $ecode +} + +# +# Script execution starts here. +# +dns_process_install || exit $? + +$SVCADM disable $DNS_INSTALL_FMRI +exit $SMF_EXIT_OK diff --git a/usr/src/lib/libresolv2/install.xml b/usr/src/lib/libresolv2/install.xml new file mode 100644 index 0000000000..a01a2b83cf --- /dev/null +++ b/usr/src/lib/libresolv2/install.xml @@ -0,0 +1,137 @@ +<?xml version="1.0"?> +<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1"> +<!-- + Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + + CDDL HEADER START + + The contents of this file are subject to the terms of the + Common Development and Distribution License (the "License"). + You may not use this file except in compliance with the License. + + You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + or http://www.opensolaris.org/os/licensing. + See the License for the specific language governing permissions + and limitations under the License. + + When distributing Covered Code, include this CDDL HEADER in each + file and include the License file at usr/src/OPENSOLARIS.LICENSE. + If applicable, add the following below this CDDL HEADER, with the + fields enclosed by brackets "[]" replaced with your own identifying + information: Portions Copyright [yyyy] [name of copyright owner] + + CDDL HEADER END + + NOTE: This service manifest is not editable; its contents will + be overwritten by package or patch operations, including + operating system upgrade. Make customizations in a different + file. +--> + +<service_bundle type='manifest' name='SUNWcsr:dns-install'> + +<service + name='network/dns/install' + type='service' + version='1'> + + <create_default_instance enabled='false' /> + + <single_instance /> + + <dependency + name='filesystem' + grouping='require_all' + restart_on='none' + type='service'> + <service_fmri value='svc:/system/filesystem/root' /> + <service_fmri value='svc:/system/filesystem/usr' /> + <service_fmri value='svc:/system/filesystem/minimal' /> + </dependency> + + <dependent name='network-service' + grouping='optional_all' + restart_on='none'> + <service_fmri value='svc:/network/service' /> + </dependent> + + <dependent name='dns-client' + grouping='optional_all' + restart_on='none'> + <service_fmri value='svc:/network/dns/client' /> + </dependent> + + <exec_method + type='method' + name='start' + exec='/lib/svc/method/dns-install' + timeout_seconds='30' /> + + <exec_method + type='method' + name='stop' + exec=':true' + timeout_seconds='0' /> + + <property_group name='startd' type='framework'> + <propval name='duration' type='astring' value='transient' /> + </property_group> + + <property_group name='install_props' type='application'> + <property name='nameserver' type='net_address'> + <net_address_list> + <value_node value='0.0.0.0' /> + </net_address_list> + </property> + <propval name='domain' type='astring' value='' /> + <property name='search' type='astring'> + <astring_list> + <value_node value='' /> + </astring_list> + </property> + </property_group> + + <stability value='Unstable' /> + + <template> + <common_name> + <loctext xml:lang='C'> + DNS resolver install + </loctext> + </common_name> + <documentation> + <manpage title='resolver' section='3RESOLV' + manpath='/usr/share/man' /> + </documentation> + <pg_pattern name='install_props' type='application' + target='this' required='false'> + <description> <loctext xml:lang='C'> + Install derived configuration data used to configure an initial DNS client. + </loctext> </description> + <prop_pattern name='nameserver' type='net_address' + required='true'> + <description> <loctext xml:lang='C'> + The value used to construct the "nameserver" directive in resolv.conf(4). + </loctext> </description> + <cardinality min='1' max='3'/> + </prop_pattern> + <prop_pattern name='domain' type='astring' + required='false'> + <description> <loctext xml:lang='C'> + The value used to construct the "domain" directive in resolv.conf(4). + </loctext> </description> + <cardinality min='1' max='1'/> + </prop_pattern> + <prop_pattern name='search' type='astring' + required='false'> + <description> <loctext xml:lang='C'> + The value used to construct the "search" directive in resolv.conf(4). + </loctext> </description> + <cardinality min='1' max='6'/> + </prop_pattern> + </pg_pattern> + </template> + +</service> + +</service_bundle> |