1129650Sdes#!/bin/sh 2129650Sdes# 3129650Sdes# Copyright (c) 1993 - 2004 The FreeBSD Project. All rights reserved. 4129650Sdes# 5129650Sdes# Redistribution and use in source and binary forms, with or without 6129650Sdes# modification, are permitted provided that the following conditions 7129650Sdes# are met: 8129650Sdes# 1. Redistributions of source code must retain the above copyright 9129650Sdes# notice, this list of conditions and the following disclaimer. 10129650Sdes# 2. Redistributions in binary form must reproduce the above copyright 11129650Sdes# notice, this list of conditions and the following disclaimer in the 12129650Sdes# documentation and/or other materials provided with the distribution. 13129650Sdes# 14129650Sdes# THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 15129650Sdes# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16129650Sdes# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17129650Sdes# ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 18129650Sdes# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19129650Sdes# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20129650Sdes# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21129650Sdes# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22129650Sdes# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23129650Sdes# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24129650Sdes# SUCH DAMAGE. 25129650Sdes# 26129650Sdes# $FreeBSD: releng/10.2/etc/rc.d/nsswitch 213202 2010-09-27 15:55:39Z imp $ 27129650Sdes# 28129650Sdes 29129650Sdes# PROVIDE: nsswitch 30129650Sdes# REQUIRE: root 31135305Skeramida# BEFORE: NETWORK 32129650Sdes 33129650Sdes. /etc/rc.subr 34129650Sdes 35129650Sdesname="nsswitch" 36129650Sdesstart_cmd="nsswitch_start" 37129650Sdesstop_cmd=":" 38129650Sdes 39129650Sdesgenerate_host_conf() 40129650Sdes{ 41165664Syar local _cont _sources 42165664Syar 43129650Sdes nsswitch_conf=$1; shift; 44129650Sdes host_conf=$1; shift; 45129650Sdes 46156917Sflz _cont=0 47156917Sflz _sources="" 48156917Sflz while read line; do 49156917Sflz line=${line##[ ]} 50156917Sflz case $line in 51156917Sflz hosts:*) 52156917Sflz ;; 53156917Sflz *) 54156917Sflz if [ $_cont -ne 1 ]; then 55156917Sflz continue 56156917Sflz fi 57156917Sflz ;; 58156917Sflz esac 59156917Sflz if [ "${line%\\}" = "${line}\\" ]; then 60156917Sflz _cont=1 61156917Sflz fi 62156917Sflz line=${line#hosts:} 63156917Sflz line=${line%\\} 64156917Sflz line=${line%%#*} 65156917Sflz _sources="${_sources}${_sources:+ }$line" 66156917Sflz done < $nsswitch_conf 67156917Sflz 68157682Sume echo "# Auto-generated from nsswitch.conf" > $host_conf 69156917Sflz for _s in ${_sources}; do 70156917Sflz case $_s in 71156917Sflz files) 72156917Sflz echo "hosts" >> $host_conf 73156917Sflz ;; 74156917Sflz dns) 75156917Sflz echo "dns" >> $host_conf 76156917Sflz ;; 77156917Sflz nis) 78156917Sflz echo "nis" >> $host_conf 79156917Sflz ;; 80201440Sgavin cache | *=*) 81156917Sflz ;; 82156917Sflz *) 83213202Simp echo "Warning: unrecognized source [$_s]" >&2 84156917Sflz ;; 85156917Sflz esac 86156917Sflz done 87129650Sdes} 88129650Sdes 89129650Sdesnsswitch_start() 90129650Sdes{ 91129651Sdes # Generate host.conf for compatibility 92129651Sdes # 93158211Sdes if [ ! -f "/etc/host.conf" -o \ 94158211Sdes "/etc/host.conf" -ot "/etc/nsswitch.conf" ] 95158211Sdes then 96129651Sdes echo 'Generating host.conf.' 97129651Sdes generate_host_conf /etc/nsswitch.conf /etc/host.conf 98129651Sdes fi 99129651Sdes 100129650Sdes} 101129650Sdes 102129650Sdesload_rc_config $name 103129650Sdesrun_rc_command "$1" 104