From 85c9d676b5eec2f4dd34a4b3f858dd6414c9b783 Mon Sep 17 00:00:00 2001 From: Bill Fenner Date: Wed, 7 Nov 2001 00:33:56 +0000 Subject: [PATCH] Update the nsswitch.conf -> host.conf generator to handle criteria, continuation lines, extra whitespace, and to use the last matching line in the file. This syncs the host.conf generation with how the nsswitch.conf is parsed. Only print " host.conf" instead of a multi-line message, since this happens on every boot. --- etc/network.subr | 26 ++++++++++++++++---------- etc/rc.d/netoptions | 26 ++++++++++++++++---------- etc/rc.d/network1 | 26 ++++++++++++++++---------- etc/rc.d/network2 | 26 ++++++++++++++++---------- etc/rc.d/network3 | 26 ++++++++++++++++---------- etc/rc.d/routing | 26 ++++++++++++++++---------- etc/rc.network | 26 ++++++++++++++++---------- 7 files changed, 112 insertions(+), 70 deletions(-) diff --git a/etc/network.subr b/etc/network.subr index 1ca57d56db08..db566996768c 100644 --- a/etc/network.subr +++ b/etc/network.subr @@ -41,8 +41,7 @@ network_pass1() { # Generate host.conf for compatibility # if [ -f "/etc/nsswitch.conf" ]; then - echo '' - echo 'Generating /etc/host.conf for compatibility' + echo -n ' host.conf' generate_host_conf /etc/nsswitch.conf /etc/host.conf fi @@ -880,16 +879,23 @@ BEGIN { xlat["files"] = "hosts"; xlat["dns"] = "bind"; xlat["nis"] = "nis"; + cont = 0; } -/^hosts:/ { - print "# Auto-generated, do not edit"; - for (n = 2; n <= NF; ++n) - if ($n in xlat) - print xlat[$n]; - quit; +sub(/^[\t ]*hosts:/, "") || cont { + if (!cont) + srcs = "" + sub(/#.*/, "") + gsub(/[][]/, " & ") + cont = sub(/\\$/, "") + srcs = srcs " " $0 } -// { - next; +END { + print "# Auto-generated from nsswitch.conf, do not edit" + ns = split(srcs, s) + for (n = 1; n <= ns; ++n) { + if (s[n] in xlat) + print xlat[s[n]] + } } ' <$nsswitch_conf >$host_conf } diff --git a/etc/rc.d/netoptions b/etc/rc.d/netoptions index 1ca57d56db08..db566996768c 100644 --- a/etc/rc.d/netoptions +++ b/etc/rc.d/netoptions @@ -41,8 +41,7 @@ network_pass1() { # Generate host.conf for compatibility # if [ -f "/etc/nsswitch.conf" ]; then - echo '' - echo 'Generating /etc/host.conf for compatibility' + echo -n ' host.conf' generate_host_conf /etc/nsswitch.conf /etc/host.conf fi @@ -880,16 +879,23 @@ BEGIN { xlat["files"] = "hosts"; xlat["dns"] = "bind"; xlat["nis"] = "nis"; + cont = 0; } -/^hosts:/ { - print "# Auto-generated, do not edit"; - for (n = 2; n <= NF; ++n) - if ($n in xlat) - print xlat[$n]; - quit; +sub(/^[\t ]*hosts:/, "") || cont { + if (!cont) + srcs = "" + sub(/#.*/, "") + gsub(/[][]/, " & ") + cont = sub(/\\$/, "") + srcs = srcs " " $0 } -// { - next; +END { + print "# Auto-generated from nsswitch.conf, do not edit" + ns = split(srcs, s) + for (n = 1; n <= ns; ++n) { + if (s[n] in xlat) + print xlat[s[n]] + } } ' <$nsswitch_conf >$host_conf } diff --git a/etc/rc.d/network1 b/etc/rc.d/network1 index 1ca57d56db08..db566996768c 100644 --- a/etc/rc.d/network1 +++ b/etc/rc.d/network1 @@ -41,8 +41,7 @@ network_pass1() { # Generate host.conf for compatibility # if [ -f "/etc/nsswitch.conf" ]; then - echo '' - echo 'Generating /etc/host.conf for compatibility' + echo -n ' host.conf' generate_host_conf /etc/nsswitch.conf /etc/host.conf fi @@ -880,16 +879,23 @@ BEGIN { xlat["files"] = "hosts"; xlat["dns"] = "bind"; xlat["nis"] = "nis"; + cont = 0; } -/^hosts:/ { - print "# Auto-generated, do not edit"; - for (n = 2; n <= NF; ++n) - if ($n in xlat) - print xlat[$n]; - quit; +sub(/^[\t ]*hosts:/, "") || cont { + if (!cont) + srcs = "" + sub(/#.*/, "") + gsub(/[][]/, " & ") + cont = sub(/\\$/, "") + srcs = srcs " " $0 } -// { - next; +END { + print "# Auto-generated from nsswitch.conf, do not edit" + ns = split(srcs, s) + for (n = 1; n <= ns; ++n) { + if (s[n] in xlat) + print xlat[s[n]] + } } ' <$nsswitch_conf >$host_conf } diff --git a/etc/rc.d/network2 b/etc/rc.d/network2 index 1ca57d56db08..db566996768c 100644 --- a/etc/rc.d/network2 +++ b/etc/rc.d/network2 @@ -41,8 +41,7 @@ network_pass1() { # Generate host.conf for compatibility # if [ -f "/etc/nsswitch.conf" ]; then - echo '' - echo 'Generating /etc/host.conf for compatibility' + echo -n ' host.conf' generate_host_conf /etc/nsswitch.conf /etc/host.conf fi @@ -880,16 +879,23 @@ BEGIN { xlat["files"] = "hosts"; xlat["dns"] = "bind"; xlat["nis"] = "nis"; + cont = 0; } -/^hosts:/ { - print "# Auto-generated, do not edit"; - for (n = 2; n <= NF; ++n) - if ($n in xlat) - print xlat[$n]; - quit; +sub(/^[\t ]*hosts:/, "") || cont { + if (!cont) + srcs = "" + sub(/#.*/, "") + gsub(/[][]/, " & ") + cont = sub(/\\$/, "") + srcs = srcs " " $0 } -// { - next; +END { + print "# Auto-generated from nsswitch.conf, do not edit" + ns = split(srcs, s) + for (n = 1; n <= ns; ++n) { + if (s[n] in xlat) + print xlat[s[n]] + } } ' <$nsswitch_conf >$host_conf } diff --git a/etc/rc.d/network3 b/etc/rc.d/network3 index 1ca57d56db08..db566996768c 100644 --- a/etc/rc.d/network3 +++ b/etc/rc.d/network3 @@ -41,8 +41,7 @@ network_pass1() { # Generate host.conf for compatibility # if [ -f "/etc/nsswitch.conf" ]; then - echo '' - echo 'Generating /etc/host.conf for compatibility' + echo -n ' host.conf' generate_host_conf /etc/nsswitch.conf /etc/host.conf fi @@ -880,16 +879,23 @@ BEGIN { xlat["files"] = "hosts"; xlat["dns"] = "bind"; xlat["nis"] = "nis"; + cont = 0; } -/^hosts:/ { - print "# Auto-generated, do not edit"; - for (n = 2; n <= NF; ++n) - if ($n in xlat) - print xlat[$n]; - quit; +sub(/^[\t ]*hosts:/, "") || cont { + if (!cont) + srcs = "" + sub(/#.*/, "") + gsub(/[][]/, " & ") + cont = sub(/\\$/, "") + srcs = srcs " " $0 } -// { - next; +END { + print "# Auto-generated from nsswitch.conf, do not edit" + ns = split(srcs, s) + for (n = 1; n <= ns; ++n) { + if (s[n] in xlat) + print xlat[s[n]] + } } ' <$nsswitch_conf >$host_conf } diff --git a/etc/rc.d/routing b/etc/rc.d/routing index 1ca57d56db08..db566996768c 100644 --- a/etc/rc.d/routing +++ b/etc/rc.d/routing @@ -41,8 +41,7 @@ network_pass1() { # Generate host.conf for compatibility # if [ -f "/etc/nsswitch.conf" ]; then - echo '' - echo 'Generating /etc/host.conf for compatibility' + echo -n ' host.conf' generate_host_conf /etc/nsswitch.conf /etc/host.conf fi @@ -880,16 +879,23 @@ BEGIN { xlat["files"] = "hosts"; xlat["dns"] = "bind"; xlat["nis"] = "nis"; + cont = 0; } -/^hosts:/ { - print "# Auto-generated, do not edit"; - for (n = 2; n <= NF; ++n) - if ($n in xlat) - print xlat[$n]; - quit; +sub(/^[\t ]*hosts:/, "") || cont { + if (!cont) + srcs = "" + sub(/#.*/, "") + gsub(/[][]/, " & ") + cont = sub(/\\$/, "") + srcs = srcs " " $0 } -// { - next; +END { + print "# Auto-generated from nsswitch.conf, do not edit" + ns = split(srcs, s) + for (n = 1; n <= ns; ++n) { + if (s[n] in xlat) + print xlat[s[n]] + } } ' <$nsswitch_conf >$host_conf } diff --git a/etc/rc.network b/etc/rc.network index 1ca57d56db08..db566996768c 100644 --- a/etc/rc.network +++ b/etc/rc.network @@ -41,8 +41,7 @@ network_pass1() { # Generate host.conf for compatibility # if [ -f "/etc/nsswitch.conf" ]; then - echo '' - echo 'Generating /etc/host.conf for compatibility' + echo -n ' host.conf' generate_host_conf /etc/nsswitch.conf /etc/host.conf fi @@ -880,16 +879,23 @@ BEGIN { xlat["files"] = "hosts"; xlat["dns"] = "bind"; xlat["nis"] = "nis"; + cont = 0; } -/^hosts:/ { - print "# Auto-generated, do not edit"; - for (n = 2; n <= NF; ++n) - if ($n in xlat) - print xlat[$n]; - quit; +sub(/^[\t ]*hosts:/, "") || cont { + if (!cont) + srcs = "" + sub(/#.*/, "") + gsub(/[][]/, " & ") + cont = sub(/\\$/, "") + srcs = srcs " " $0 } -// { - next; +END { + print "# Auto-generated from nsswitch.conf, do not edit" + ns = split(srcs, s) + for (n = 1; n <= ns; ++n) { + if (s[n] in xlat) + print xlat[s[n]] + } } ' <$nsswitch_conf >$host_conf }