>From ecba7a9f5ee5169c33db9cb83a99ba7ebc46e10f Mon Sep 17 00:00:00 2001 From: Eygene Ryabinkin Date: Sat, 12 Apr 2008 21:43:44 +0400 Subject: [PATCH] rc.d/resolv: implement creation of resolv.conf from rc.conf variables. Two new variables for rc.conf: - resolv_domain, the name of the default DNS domain, - resolv_nameservers, the list of the name servers separated by ',' or ' '. If there are no kenv variables dhcp.domain-name-servers and dhcp.domain-name, but any of rc.conf variables mentioned above are set, then /etc/resolv.conf will be built from the contents of these variables. Signed-off-by: Eygene Ryabinkin --- etc/defaults/rc.conf | 6 ++++++ etc/rc.d/resolv | 35 +++++++++++++++++++++++++---------- share/man/man5/rc.conf.5 | 10 ++++++++++ 3 files changed, 41 insertions(+), 10 deletions(-) diff --git a/etc/defaults/rc.conf b/etc/defaults/rc.conf index 1a23b72..cd9c142 100644 --- a/etc/defaults/rc.conf +++ b/etc/defaults/rc.conf @@ -237,6 +237,12 @@ named_chroot_autoupdate="YES" # Automatically install/update chrooted named_symlink_enable="YES" # Symlink the chrooted pid file # +# resolv. Build /etc/resolv.conf programmatically. +# +resolv_domain="" # DNS domain we're in. +resolv_nameservers="" # List of DNS server IPs, separated by comma or space. + +# # kerberos. Do not run the admin daemons on slave servers # kerberos5_server_enable="NO" # Run a kerberos 5 master server (or NO). diff --git a/etc/rc.d/resolv b/etc/rc.d/resolv index 00c2f49..3f36a0c 100644 --- a/etc/rc.d/resolv +++ b/etc/rc.d/resolv @@ -38,20 +38,35 @@ stop_cmd=':' load_rc_config $name +# Helper that echoes the contents of the resolv.conf to the stdout. +# Arguments: +# 1. domain name, +# 2. list of name servers separated by ',' or ' '. +# Either argument can be empty. If so, it won't be included to the output. + +build_resolv () { + if [ -n "$1" ]; then + echo domain "$1" + fi + + set -- "$2" + for ns in `IFS=', '; echo $*`; do + echo nameserver $ns + done +} + # if the info is available via dhcp/kenv # build the resolv.conf # if [ ! -e /etc/resolv.conf -a \ -n "`/bin/kenv dhcp.domain-name-servers 2> /dev/null`" ]; then - > /etc/resolv.conf - - if [ -n "`/bin/kenv dhcp.domain-name 2> /dev/null`" ]; then - echo domain `/bin/kenv dhcp.domain-name` > /etc/resolv.conf - fi - - set -- `/bin/kenv dhcp.domain-name-servers` - for ns in `IFS=','; echo $*`; do - echo nameserver $ns >> /etc/resolv.conf; - done + build_resolv \ + "`/bin/kenv dhcp.domain-name 2> /dev/null`" \ + "`/bin/kenv dhcp.domain-name-servers`" \ + > /etc/resolv.conf +elif [ -n "${resolv_domain}" -o -n "${resolv_nameservers}" ]; then + build_resolv \ + "${resolv_domain}" "${resolv_nameservers}" \ + > /etc/resolv.conf fi diff --git a/share/man/man5/rc.conf.5 b/share/man/man5/rc.conf.5 index a900d6a..af5d61f 100644 --- a/share/man/man5/rc.conf.5 +++ b/share/man/man5/rc.conf.5 @@ -1602,6 +1602,16 @@ daemon's PID file into the .Xr chroot 8 environment. +.It Va resolv_domain +.Pq Vt str +name of the local domain. +Used for the programmatical building of +.Pa /etc/resolv.conf . +.It Va resolv_nameservers +.Pq Vt str +comma- or space-separated list of nameservers. +Used for the programmatical building of +.Pa /etc/resolv.conf . .It Va kerberos5_server_enable .Pq Vt bool Set to -- 1.5.3.8