1234287Sdim#!/bin/sh 2234287Sdim# 3353358Sdim# Copyright (c) 1993 - 2004 The FreeBSD Project. All rights reserved. 4353358Sdim# 5353358Sdim# Redistribution and use in source and binary forms, with or without 6234287Sdim# modification, are permitted provided that the following conditions 7234287Sdim# are met: 8234287Sdim# 1. Redistributions of source code must retain the above copyright 9234287Sdim# notice, this list of conditions and the following disclaimer. 10234287Sdim# 2. Redistributions in binary form must reproduce the above copyright 11234287Sdim# notice, this list of conditions and the following disclaimer in the 12234287Sdim# documentation and/or other materials provided with the distribution. 13234287Sdim# 14234287Sdim# THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 15234287Sdim# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16234287Sdim# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17234287Sdim# ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 18234287Sdim# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19234287Sdim# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20234287Sdim# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21249423Sdim# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22234287Sdim# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23234287Sdim# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24234287Sdim# SUCH DAMAGE. 25234287Sdim# 26234287Sdim# $FreeBSD$ 27234287Sdim# 28234287Sdim 29234287Sdim# PROVIDE: nsswitch 30234287Sdim# REQUIRE: root 31234287Sdim# BEFORE: NETWORK 32234287Sdim 33249423Sdim. /etc/rc.subr 34249423Sdim 35341825Sdimname="nsswitch" 36234287Sdimdesc="Name-service switch" 37341825Sdimstart_cmd="nsswitch_start" 38234287Sdimstop_cmd=":" 39249423Sdim 40249423Sdimgenerate_host_conf() 41234287Sdim{ 42234287Sdim local _cont _sources 43234287Sdim 44234287Sdim nsswitch_conf=$1; shift; 45234287Sdim host_conf=$1; shift; 46234287Sdim 47234287Sdim _cont=0 48276479Sdim _sources="" 49276479Sdim while read line; do 50276479Sdim line=${line##[ ]} 51276479Sdim case $line in 52341825Sdim hosts:*) 53341825Sdim ;; 54234287Sdim *) 55276479Sdim if [ $_cont -ne 1 ]; then 56234287Sdim continue 57234287Sdim fi 58341825Sdim ;; 59234287Sdim esac 60234287Sdim if [ "${line%\\}" = "${line}\\" ]; then 61234287Sdim _cont=1 62234287Sdim fi 63234287Sdim line=${line#hosts:} 64360784Sdim line=${line%\\} 65280031Sdim line=${line%%#*} 66234287Sdim _sources="${_sources}${_sources:+ }$line" 67234287Sdim done < $nsswitch_conf 68341825Sdim 69341825Sdim echo "# Auto-generated from nsswitch.conf" > $host_conf 70341825Sdim for _s in ${_sources}; do 71341825Sdim case $_s in 72341825Sdim files) 73341825Sdim echo "hosts" >> $host_conf 74341825Sdim ;; 75341825Sdim dns) 76341825Sdim echo "dns" >> $host_conf 77341825Sdim ;; 78341825Sdim nis) 79234287Sdim echo "nis" >> $host_conf 80234287Sdim ;; 81341825Sdim cache | *=*) 82234287Sdim ;; 83234287Sdim *) 84234287Sdim echo "Warning: unrecognized source [$_s]" >&2 85276479Sdim ;; 86234287Sdim esac 87234287Sdim done 88234287Sdim} 89341825Sdim 90234287Sdimnsswitch_start() 91234287Sdim{ 92234287Sdim # Generate host.conf for compatibility 93234287Sdim # 94249423Sdim if [ ! -f "/etc/host.conf" -o \ 95249423Sdim "/etc/host.conf" -ot "/etc/nsswitch.conf" ] 96234287Sdim then 97234287Sdim echo 'Generating host.conf.' 98234287Sdim generate_host_conf /etc/nsswitch.conf /etc/host.conf 99234287Sdim fi 100234287Sdim 101234287Sdim} 102280031Sdim 103360784Sdimload_rc_config $name 104280031Sdimrun_rc_command "$1" 105280031Sdim