net-svc revision 032ae3d9dc781b45931a4e8b7c4c527ff1419ddc
82391de567696f10b21a762fde6a06fe3c266d28vboxsync# CDDL HEADER START
82391de567696f10b21a762fde6a06fe3c266d28vboxsync# The contents of this file are subject to the terms of the
82391de567696f10b21a762fde6a06fe3c266d28vboxsync# Common Development and Distribution License (the "License").
82391de567696f10b21a762fde6a06fe3c266d28vboxsync# You may not use this file except in compliance with the License.
82391de567696f10b21a762fde6a06fe3c266d28vboxsync# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
82391de567696f10b21a762fde6a06fe3c266d28vboxsync# See the License for the specific language governing permissions
82391de567696f10b21a762fde6a06fe3c266d28vboxsync# and limitations under the License.
82391de567696f10b21a762fde6a06fe3c266d28vboxsync# When distributing Covered Code, include this CDDL HEADER in each
82391de567696f10b21a762fde6a06fe3c266d28vboxsync# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
82391de567696f10b21a762fde6a06fe3c266d28vboxsync# If applicable, add the following below this CDDL HEADER, with the
82391de567696f10b21a762fde6a06fe3c266d28vboxsync# fields enclosed by brackets "[]" replaced with your own identifying
82391de567696f10b21a762fde6a06fe3c266d28vboxsync# information: Portions Copyright [yyyy] [name of copyright owner]
82391de567696f10b21a762fde6a06fe3c266d28vboxsync# CDDL HEADER END
82391de567696f10b21a762fde6a06fe3c266d28vboxsync# Copyright 2007 Sun Microsystems, Inc. All rights reserved.
82391de567696f10b21a762fde6a06fe3c266d28vboxsync# Use is subject to license terms.
82391de567696f10b21a762fde6a06fe3c266d28vboxsync#ident "%Z%%M% %I% %E% SMI"
82391de567696f10b21a762fde6a06fe3c266d28vboxsync# This is third phase of TCP/IP startup/configuration. This script
82391de567696f10b21a762fde6a06fe3c266d28vboxsync# runs after the NIS/NIS+ startup script. We run things here that may
82391de567696f10b21a762fde6a06fe3c266d28vboxsync# depend on NIS/NIS+ maps.
82391de567696f10b21a762fde6a06fe3c266d28vboxsync # In a shared-IP zone we need this service to be up, but all of the
82391de567696f10b21a762fde6a06fe3c266d28vboxsync # work it tries to do is irrelevant (and will actually lead to the
82391de567696f10b21a762fde6a06fe3c266d28vboxsync # service failing if we try to do it), so just bail out.
82391de567696f10b21a762fde6a06fe3c266d28vboxsync # In the global zone and exclusive-IP zones we proceed.
82391de567696f10b21a762fde6a06fe3c266d28vboxsync ;; # Fall through -- rest of script is the initialization code
82391de567696f10b21a762fde6a06fe3c266d28vboxsync echo "Usage: $0 { start | stop }"
82391de567696f10b21a762fde6a06fe3c266d28vboxsync# If boot variables are not set, set variables we use
82391de567696f10b21a762fde6a06fe3c266d28vboxsync[ -z "$_INIT_UTS_NODENAME" ] && _INIT_UTS_NODENAME=`/usr/bin/uname -n`
82391de567696f10b21a762fde6a06fe3c266d28vboxsync# Wait up to 5 seconds for ypbind to obtain a binding.
82391de567696f10b21a762fde6a06fe3c266d28vboxsync for i in 1 2 3 4 5; do
82391de567696f10b21a762fde6a06fe3c266d28vboxsync [ $? -eq 0 -a -n "$server" ] && return 0 || sleep 1
82391de567696f10b21a762fde6a06fe3c266d28vboxsync# This function takes two file names and the file mode as input. The two
82391de567696f10b21a762fde6a06fe3c266d28vboxsync# files are compared for differences (using cmp(1)) and if different, the
82391de567696f10b21a762fde6a06fe3c266d28vboxsync# second file is over written with the first. A chmod is done with the file
82391de567696f10b21a762fde6a06fe3c266d28vboxsync# mode passed in. If the files are equal, the first file passed
82391de567696f10b21a762fde6a06fe3c266d28vboxsync# in (the /tmp file) is deleted.
82391de567696f10b21a762fde6a06fe3c266d28vboxsync if [ $? -eq 1 ]; then
82391de567696f10b21a762fde6a06fe3c266d28vboxsync # The umask during boot is configurable, which requires
82391de567696f10b21a762fde6a06fe3c266d28vboxsync # explicit setting of file permission modes when we
82391de567696f10b21a762fde6a06fe3c266d28vboxsync# update_nss
82391de567696f10b21a762fde6a06fe3c266d28vboxsync# This routine takes as a parameter, the name of the respective policy
82391de567696f10b21a762fde6a06fe3c266d28vboxsync# to change in the nsswitch.conf (hosts or ipnodes) to update with dns.
82391de567696f10b21a762fde6a06fe3c266d28vboxsync # Add dns to the nsswitch file, if it isn't already there.
82391de567696f10b21a762fde6a06fe3c266d28vboxsync n = split($0, a);
82391de567696f10b21a762fde6a06fe3c266d28vboxsync newl = a[1];
82391de567696f10b21a762fde6a06fe3c266d28vboxsync if ($0 !~ /dns/) {
82391de567696f10b21a762fde6a06fe3c266d28vboxsync printf("#%s # Commented out by DHCP\n", $0);
82391de567696f10b21a762fde6a06fe3c266d28vboxsync updated = 0;
82391de567696f10b21a762fde6a06fe3c266d28vboxsync for (i = 2; i <= n; i++) {
82391de567696f10b21a762fde6a06fe3c266d28vboxsync if (updated == 0 && index(a[i], "[") == 1) {
82391de567696f10b21a762fde6a06fe3c266d28vboxsync newl = newl" dns";
82391de567696f10b21a762fde6a06fe3c266d28vboxsync newl = newl" "a[i];
82391de567696f10b21a762fde6a06fe3c266d28vboxsync if (updated == 0) {
82391de567696f10b21a762fde6a06fe3c266d28vboxsync newl = newl" dns";
82391de567696f10b21a762fde6a06fe3c266d28vboxsync if (updated != 0)
82391de567696f10b21a762fde6a06fe3c266d28vboxsync newl = newl" # Added by DHCP";
82391de567696f10b21a762fde6a06fe3c266d28vboxsync printf("%s\n", newl);
82391de567696f10b21a762fde6a06fe3c266d28vboxsync printf("%s\n", $0);
82391de567696f10b21a762fde6a06fe3c266d28vboxsync } $1 !~ /^'${policy}':/ { printf("%s\n", $0); }' /etc/nsswitch.conf \
82391de567696f10b21a762fde6a06fe3c266d28vboxsync mv_file /tmp/nsswitch.conf.$$ /etc/nsswitch.conf 644
82391de567696f10b21a762fde6a06fe3c266d28vboxsync# We now need to reset the netmask and broadcast address for our network
82391de567696f10b21a762fde6a06fe3c266d28vboxsync# interfaces. Since this may result in a name service lookup, we want to
82391de567696f10b21a762fde6a06fe3c266d28vboxsync# now wait for NIS to come up if we previously started it.
82391de567696f10b21a762fde6a06fe3c266d28vboxsync[ -z "$domain" ] || [ ! -d /var/yp/binding/$domain ] || wait_nis || \
82391de567696f10b21a762fde6a06fe3c266d28vboxsync echo "WARNING: Timed out waiting for NIS to come up" >& 2
82391de567696f10b21a762fde6a06fe3c266d28vboxsync# Re-set the netmask and broadcast addr for all IP interfaces. This ifconfig
82391de567696f10b21a762fde6a06fe3c266d28vboxsync# is run here, after waiting for name services, so that "netmask +" will find
82391de567696f10b21a762fde6a06fe3c266d28vboxsync# the netmask if it lives in a NIS map. The 'D' in -auD tells ifconfig NOT to
82391de567696f10b21a762fde6a06fe3c266d28vboxsync# mess with the interface if it is under DHCP control
82391de567696f10b21a762fde6a06fe3c266d28vboxsync# Uncomment these lines to print complete network interface configuration
82391de567696f10b21a762fde6a06fe3c266d28vboxsync# echo "network interface configuration:"
82391de567696f10b21a762fde6a06fe3c266d28vboxsync if [ -n "$interface" ]; then
82391de567696f10b21a762fde6a06fe3c266d28vboxsyncif [ -n "$dnsservers" ]; then
82391de567696f10b21a762fde6a06fe3c266d28vboxsync # Go through /etc/resolv.conf and replace any existing
82391de567696f10b21a762fde6a06fe3c266d28vboxsync # domain or nameserver entries with new ones derived
82391de567696f10b21a762fde6a06fe3c266d28vboxsync # from DHCP. Note that it is important to preserve
82391de567696f10b21a762fde6a06fe3c266d28vboxsync # order of domain entries vs. search entries; the search
82391de567696f10b21a762fde6a06fe3c266d28vboxsync # entries are reserved for administrator customization
82391de567696f10b21a762fde6a06fe3c266d28vboxsync # and if placed after the domain entry will override it.
82391de567696f10b21a762fde6a06fe3c266d28vboxsync if [ -n "$interface" ]; then
82391de567696f10b21a762fde6a06fe3c266d28vboxsync /usr/bin/nawk </etc/resolv.conf >/tmp/resolv.conf.$$ '
82391de567696f10b21a762fde6a06fe3c266d28vboxsync function writedomain() {
82391de567696f10b21a762fde6a06fe3c266d28vboxsync if (updated == 0) {
82391de567696f10b21a762fde6a06fe3c266d28vboxsync # Use only first domain, not a search list
82391de567696f10b21a762fde6a06fe3c266d28vboxsync split(ENVIRON["dnsdomain"], d)
82391de567696f10b21a762fde6a06fe3c266d28vboxsync if(length(d[1]) != 0)
82391de567696f10b21a762fde6a06fe3c266d28vboxsync printf("domain %s\n", d[1])
82391de567696f10b21a762fde6a06fe3c266d28vboxsync $1 == "domain" { writedomain(); next }
82391de567696f10b21a762fde6a06fe3c266d28vboxsync $1 != "nameserver" { print $0 }
82391de567696f10b21a762fde6a06fe3c266d28vboxsync writedomain()
82391de567696f10b21a762fde6a06fe3c266d28vboxsync n = split(ENVIRON["dnsservers"], s)
82391de567696f10b21a762fde6a06fe3c266d28vboxsync for (i = 1; i <= n; ++i)
82391de567696f10b21a762fde6a06fe3c266d28vboxsync printf("nameserver %s\n", s[i])
82391de567696f10b21a762fde6a06fe3c266d28vboxsync # Add dns to the nsswitch file, if it isn't already there.
82391de567696f10b21a762fde6a06fe3c266d28vboxsyncelif /usr/bin/grep '# Added by DHCP$' /etc/nsswitch.conf >/dev/null 2>&1; then
82391de567696f10b21a762fde6a06fe3c266d28vboxsync # If we added DNS to the hosts and ipnodes policy in the nsswitch,
82391de567696f10b21a762fde6a06fe3c266d28vboxsync # remove it.
82391de567696f10b21a762fde6a06fe3c266d28vboxsync -e '/# Added by DHCP$/d' \
82391de567696f10b21a762fde6a06fe3c266d28vboxsync -e 's/^\(#hosts:\)\(.*[^#]\)\(#.*\)$/hosts: \2/' \
82391de567696f10b21a762fde6a06fe3c266d28vboxsync -e 's/^\(#ipnodes:\)\(.*[^#]\)\(#.*\)$/ipnodes: \2/' \
82391de567696f10b21a762fde6a06fe3c266d28vboxsync mv_file /tmp/nsswitch.conf.$$ /etc/nsswitch.conf 644
82391de567696f10b21a762fde6a06fe3c266d28vboxsync# Clean up any old DHCP-added entries (except loopback) in the hosts file.
82391de567696f10b21a762fde6a06fe3c266d28vboxsyncif /usr/bin/grep '# Added by DHCP$' /etc/inet/hosts >/dev/null 2>&1; then
82391de567696f10b21a762fde6a06fe3c266d28vboxsync if (index($0, "# Added by DHCP") == 0 ||
82391de567696f10b21a762fde6a06fe3c266d28vboxsync $1 == "127.0.0.1" || $1 == "::1") {