resolv.conf and gnupg2

Christian Franke Christian.Franke@t-online.de
Tue Aug 9 12:58:16 GMT 2022


Brian Inglis wrote:
> I've been running with /etc/resolv.conf for a few years now, generated 
> from the ISP info from ipconfig and lists of public DNS servers and 
> suffixes.
>
> The attached postinstall script 0p_l_etc_resolv_conf.dash generates a 
> new resolv.conf and replaces the current if different every update.
> It is also run at cron startup and that covers system startup.
>
> The AWK script collects names and addresses from ipconfig ouput and 
> adds lists of public DNS servers and public suffixes in the proper order.
>
> How this works with other ISPs or in other network environments is not 
> anything I ever thought of testing externally.
> Feel feel to try it and change it if curious or interested.

This is an interesting approach, thanks for sharing.

Unfortunately the ipconfig output is always localized, so this does only 
work OOTB with English versions of Windows. The ipconfig parsing is also 
broken due to two reasons:

- The current Cygwin versions of awk, grep and sed no longer convert 
CR/LF -> LF on stdin, so '/FooBar$/' patterns never match.

- ipconfig may output scoped IPv6 addresses ("fe80::1%12") which are not 
matched by the awk script.

A draft patch is attached. It also avoids the tmp file and uses shell 
builtins where possible.

-- 
Regards,
Christian

-------------- next part --------------
diff -ru cyg-resolv.orig/0p_l_etc_resolv_conf.dash cyg-resolv/0p_l_etc_resolv_conf.dash
--- cyg-resolv.orig/0p_l_etc_resolv_conf.dash	2022-08-09 13:52:07.293134900 +0200
+++ cyg-resolv/0p_l_etc_resolv_conf.dash	2022-08-09 14:29:56.429564700 +0200
@@ -9,14 +9,13 @@
 conf=$SYSCONFDIR/$r.conf
 
 /bin/mkdir -pv		-- $run/		&& \
-ip=$(/usr/bin/which	-- ipconfig)		&& \
-tmp=$(/bin/mktemp -t	-- .XXXXXXXX.)		&& \
-$ip /all | $cr	 > $tmp				&& \
-[ -s $tmp ]					&& \
-[ -w $rrc ]	|| : > $rrc
-if ! /usr/bin/cmp -s	-- $tmp $rrc; then
-    /bin/cp -fv		-- $tmp $rrc
+ip=$(command -v ipconfig)			&& \
+a=$(/bin/cat $rrc 2>/dev/null || :) 		&& \
+b=$("$ip" /all | /bin/tr -d '\r' | $cr)		&& \
+[ "${b:+set}" = "set" ]				&& \
+[ -w $rrc ]	|| a= : > $rrc
+if [ "$a" != "$b" ]; then
+    echo "$cr > $rrc"
+    echo "$b" > $rrc
     /bin/ln -frsTv	-- $rrc $conf
 fi
-
-/bin/rm -f		-- $tmp
diff -ru cyg-resolv.orig/cyg-resolv.awk cyg-resolv/cyg-resolv.awk
--- cyg-resolv.orig/cyg-resolv.awk	2022-08-09 13:52:07.293348300 +0200
+++ cyg-resolv/cyg-resolv.awk	2022-08-09 14:15:51.164139100 +0200
@@ -156,7 +156,7 @@
 # collect DNS server IP V4 addresses
 /DNS\sServers[^:]*:\s\S/	{ dns = 1 }		# start - enable
 
-dns && $NF ~ /^([0-9A-Fa-f]{0,4}:){1,7}[0-9A-Fa-f]{0,4}$/ { next } # skip IP V6
+dns && $NF ~ /^([0-9A-Fa-f]{0,4}:){1,7}[0-9A-Fa-f]{0,4}(%.*)?$/ { next } # skip IP V6
 
 
 dns && $NF ~ /^([0-9]{1,3}\.){3}[0-9]{1,3}$/	{		# collect IP V4
@@ -164,7 +164,7 @@
     last = ""
 }
 
-dns && $NF !~ /^([0-9A-Fa-f]{0,4}:){1,7}[0-9A-Fa-f]{0,4}$/ && \
+dns && $NF !~ /^([0-9A-Fa-f]{0,4}:){1,7}[0-9A-Fa-f]{0,4}(%.*)$/ && \
 	$NF !~ /^([0-9]{1,3}\.){3}[0-9]{1,3}$/	{ dns = 0 }	# non-IP disable
 
 


More information about the Cygwin mailing list