From owner-freebsd-arch Sat Oct 13 9:35:20 2001 Delivered-To: freebsd-arch@freebsd.org Received: from flood.ping.uio.no (flood.ping.uio.no [129.240.78.31]) by hub.freebsd.org (Postfix) with ESMTP id BDFCB37B40B; Sat, 13 Oct 2001 09:27:10 -0700 (PDT) Received: by flood.ping.uio.no (Postfix, from userid 2602) id 676B614C3E; Sat, 13 Oct 2001 18:27:09 +0200 (CEST) X-URL: http://www.ofug.org/~des/ X-Disclaimer: The views expressed in this message do not necessarily coincide with those of any organisation or company with which I am or have been affiliated. To: arch@freebsd.org Subject: Generating host.conf for backward compatibility References: <3BC67CBD.1DAAC031@DougBarton.net> <3BC7EA21.15F43811@DougBarton.net> From: Dag-Erling Smorgrav Date: 13 Oct 2001 18:27:08 +0200 In-Reply-To: Message-ID: Lines: 18 User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Sender: owner-freebsd-arch@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG --=-=-= In our eagerness to switch from host.conf to nsswitch.conf, we forgot that old binaries and libraries (COMPAT_* and tons of third-party software for which sources might not even be available) still expect to find /etc/host.conf, and may not work (correctly) if it doesn't exist. The attached patch creates host.conf from nsswitch.conf if it detects the latter. The first time you boot after upgrading from -STABLE or an old -CURRENT, nsswitch.conf will be created, and host.conf won't be touched; all subsequent times, host.conf will be auto-generated from the information contained in nsswitch.conf. DES -- Dag-Erling Smorgrav - des@ofug.org --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=host_conf.diff Index: etc/rc.network =================================================================== RCS file: /home/ncvs/src/etc/rc.network,v retrieving revision 1.105 diff -u -r1.105 rc.network --- etc/rc.network 10 Oct 2001 20:36:51 -0000 1.105 +++ etc/rc.network 13 Oct 2001 16:23:35 -0000 @@ -38,16 +38,21 @@ network_pass1() { echo -n 'Doing initial network setup:' + # Generate host.conf for compatibility + # + if [ -f "/etc/nsswitch.conf" ]; then + echo '' + echo 'Generating /etc/host.conf for compatibility' + generate_host_conf /etc/nsswitch.conf /etc/host.conf + fi + # Convert host.conf to nsswitch.conf if necessary - if [ -f "/etc/host.conf" ]; then + # + if [ -f "/etc/host.conf" -a ! -f "/etc/nsswitch.conf" ]; then echo '' echo 'Warning: /etc/host.conf is no longer used' - if [ -f "/etc/nsswitch.conf" ]; then - echo ' /etc/nsswitch.conf will be used instead' - else - echo ' /etc/nsswitch.conf will be created for you' - convert_host_conf /etc/host.conf /etc/nsswitch.conf - fi + echo ' /etc/nsswitch.conf will be created for you' + convert_host_conf /etc/host.conf /etc/nsswitch.conf fi # Set the host name if it is not already set @@ -827,3 +832,25 @@ }' < $host_conf > $nsswitch_conf } +generate_host_conf() { + nsswitch_conf=$1; shift; + host_conf=$1; shift; + + awk ' +BEGIN { + xlat["files"] = "hosts"; + xlat["dns"] = "bind"; + xlat["nis"] = "nis"; +} +/^hosts:/ { + print "# Auto-generated, do not edit"; + for (n = 2; n <= NF; ++n) + if ($n in xlat) + print xlat[$n]; + quit; +} +// { + next; +} +' <$nsswitch_conf >$host_conf +} --=-=-=-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-arch" in the body of the message