Strip trailing dot from search and domain names, fixes [2b60f8c312].
authorRoy Marples <roy@marples.name>
Sat, 20 Feb 2016 10:34:57 +0000 (10:34 +0000)
committerRoy Marples <roy@marples.name>
Sat, 20 Feb 2016 10:34:57 +0000 (10:34 +0000)
resolvconf.in

index 69e6df9150563b3b722f9e31e6d29654f4d95809..829321e16e8fc26a6fc5c7db1fc33fd0deadb426 100644 (file)
@@ -1,5 +1,5 @@
 #!/bin/sh
-# Copyright (c) 2007-2015 Roy Marples
+# Copyright (c) 2007-2016 Roy Marples
 # All rights reserved
 
 # Redistribution and use in source and binary forms, with or without
@@ -120,6 +120,21 @@ echo_resolv()
        IFS="$OIFS"
 }
 
+# Strip any trailing dot from each name as a FQDN does not belong
+# in resolv.conf(5)
+# If you think otherwise, capture a DNS trace and you'll see libc
+# will strip it regardless.
+# This also solves setting up duplicate zones in our subscribers.
+strip_trailing_dots()
+{
+       local n=
+
+       for n; do
+               printf "%s" "${n%.}"
+       done
+       printf "\n"
+}
+
 # Parse resolv.conf's and make variables
 # for domain name servers, search name servers and global nameservers
 parse_resolv()
@@ -163,14 +178,14 @@ parse_resolv()
                        $islocal || ns="$ns${line#* } "
                        ;;
                "domain "*)
+                       search="$(strip_trailing_dots ${line#* })"
                        if [ -z "$domain" ]; then
-                               domain="${line#* }"
+                               domain="$search"
                                echo "DOMAIN=\"$domain\""
                        fi
-                       search="${line#* }"
                        ;;
                "search "*)
-                       search="${line#* }"
+                       search="$(strip_trailing_dots ${line#* })"
                        ;;
                *)
                        [ -n "$line" ] && continue