Skip site navigation (1)Skip section navigation (2)
Date:      13 Oct 2001 18:27:08 +0200
From:      Dag-Erling Smorgrav <des@ofug.org>
To:        arch@freebsd.org
Subject:   Generating host.conf for backward compatibility
Message-ID:  <xzplmifh5er.fsf_-_@flood.ping.uio.no>
In-Reply-To: <xzp4rp3ippr.fsf@flood.ping.uio.no>
References:  <3BC67CBD.1DAAC031@DougBarton.net> <xzpr8s9av9n.fsf@flood.ping.uio.no> <3BC7EA21.15F43811@DougBarton.net> <xzp8zefiqhz.fsf@flood.ping.uio.no> <xzp4rp3ippr.fsf@flood.ping.uio.no>

next in thread | previous in thread | raw e-mail | index | archive | help
--=-=-=

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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?xzplmifh5er.fsf_-_>