Import of openresolv 3.4.4.

Obtained from:	http://roy.marples.name/projects/openresolv
Approved by:	re (kib)
This commit is contained in:
Hiroki Sato 2011-09-13 02:41:09 +00:00
parent 8e56b8ee7b
commit 093c93c350
10 changed files with 166 additions and 86 deletions

View File

@ -1,7 +1,7 @@
include config.mk
NAME= openresolv
VERSION= 3.4.1
VERSION= 3.4.4
PKG= ${NAME}-${VERSION}
INSTALL?= install

2
configure vendored
View File

@ -9,7 +9,7 @@ TARGET=
RESTARTCMD=
RCDIR=
for x; do
for x do
opt=${x%%=*}
var=${x#*=}
case "$opt" in

View File

@ -1,5 +1,5 @@
#!/bin/sh
# Copyright (c) 2007-2009 Roy Marples
# Copyright (c) 2007-2011 Roy Marples
# All rights reserved
# dnsmasq subscriber for resolvconf
@ -30,12 +30,14 @@
. "@SYSCONFDIR@/resolvconf.conf" || exit 1
[ -z "$dnsmasq_conf" -a -z "$dnsmasq_resolv" ] && exit 0
[ -z "$RESOLVCONF" ] && eval "$(@PREFIX@/sbin/resolvconf -v)"
NL="
"
: ${dnsmasq_pid:=/var/run/dnsmasq.pid}
[ -s "$dnsmasq_pid" ] || dnsmasq_pid=/var/run/dnsmasq/dnsmasq.pid
: ${dnsmasq_service:=dnsmasq}
: ${dnsmasq_restart:=@RESTARTCMD ${dnsmasq_service}@}
newconf="# Generated by resolvconf\n"
newconf="# Generated by resolvconf$NL"
newresolv="$newconf"
# Using dbus means that we never have to restart the daemon
@ -56,14 +58,14 @@ if [ -s "$dbus_pid" -a -s "$dnsmasq_pid" ]; then
kill -0 $(cat "$dnsmasq_pid") 2>/dev/null
then
dbus=true
newconf="$newconf\n# Domain specific servers will"
newconf="$newconf be sent over dbus\nenable-dbus\n"
newconf="$newconf$NL# Domain specific servers will"
newconf="$newconf be sent over dbus${NL}enable-dbus$NL"
fi
fi
fi
for n in $NAMESERVERS; do
newresolv="${newresolv}nameserver $n\n"
newresolv="${newresolv}nameserver $n$NL"
done
dbusdest=
@ -75,41 +77,48 @@ for d in $DOMAINS; do
SIFS=${IFS-y} OIFS=$IFS
IFS=.
set -- ${ns%%,*}
num="0x$(printf "%02x" $1 $2 $3 $4)"
num="0x$(printf %02x $1 $2 $3 $4)"
if [ "$SIFS" = yi ]; then
unset IFS
else
IFS=$OIFS
fi
dbusdest="$dbusdest uint32:$(printf "%u" $num)"
dbusdest="$dbusdest uint32:$(printf %u $num)"
dbusdest="$dbusdest string:$dn"
else
newconf="${newconf}server=/$dn/${ns%%,*}\n"
newconf="${newconf}server=/$dn/${ns%%,*}$NL"
fi
[ "$ns" = "${ns#*,}" ] && break
ns="${ns#*,}"
done
done
# Try to ensure that config dirs exist
if type config_mkdirs >/dev/null 2>&1; then
config_mkdirs "$dnsmasq_conf" "$dnsmasq_resolv"
else
@PREFIX@/sbin/resolvconf -D "$dnsmasq_conf" "$dnsmasq_resolv"
fi
changed=false
if [ -n "$dnsmasq_conf" ]; then
if [ ! -f "$dnsmasq_conf" ] || \
[ "$(cat "$dnsmasq_conf")" != "$(printf "$newconf")" ]
[ "$(cat "$dnsmasq_conf")" != "$(printf %s "$newconf")" ]
then
changed=true
printf "$newconf" >"$dnsmasq_conf"
printf %s "$newconf" >"$dnsmasq_conf"
fi
fi
if [ -n "$dnsmasq_resolv" ]; then
if [ -f "$dnsmasq_resolv" ]; then
if [ "$(cat "$dnsmasq_resolv")" != "$(printf "$newresolv")" ]
if [ "$(cat "$dnsmasq_resolv")" != "$(printf %s "$newresolv")" ]
then
changed=true
printf "$newresolv" >"$dnsmasq_resolv"
printf %s "$newresolv" >"$dnsmasq_resolv"
fi
else
# dnsmasq polls this file so no need to set changed=true
printf "$newresolv" >"$dnsmasq_resolv"
printf %s "$newresolv" >"$dnsmasq_resolv"
fi
fi

24
libc.in
View File

@ -1,5 +1,5 @@
#!/bin/sh
# Copyright (c) 2007-2009 Roy Marples
# Copyright (c) 2007-2011 Roy Marples
# All rights reserved
# libc subscriber for resolvconf
@ -30,6 +30,8 @@ SYSCONFDIR=@SYSCONFDIR@
LIBEXECDIR=@LIBEXECDIR@
VARDIR=@VARDIR@
IFACEDIR="$VARDIR/interfaces"
NL="
"
# sed may not be available, and this is faster on small files
key_get_value()
@ -109,7 +111,7 @@ case "${resolv_conf_passthrough:-NO}" in
fi
done
[ -z "$newest" ] && exit 0
newconf="$(cat "$newest")\n"
newconf="$(cat "$newest")$NL"
;;
*)
[ -z "$RESOLVCONF" ] && eval "$(@PREFIX@/sbin/resolvconf -v)"
@ -118,13 +120,13 @@ case "${resolv_conf_passthrough:-NO}" in
newns="$(uniqify $name_servers $NS $name_servers_append)"
# Hold our new resolv.conf in a variable to save on temporary files
newconf="# Generated by resolvconf\n"
newconf="# Generated by resolvconf$NL"
if [ -n "$resolv_conf_head" ]; then
newconf="$newconf$resolv_conf_head\n"
newconf="$newconf$resolv_conf_head$NL"
fi
[ -n "$newsearch" ] && newconf="${newconf}search $newsearch\n"
[ -n "$newsearch" ] && newconf="${newconf}search $newsearch$NL"
for n in $newns; do
newconf="${newconf}nameserver $n\n"
newconf="${newconf}nameserver $n$NL"
done
# Now get any configured options
@ -135,22 +137,22 @@ case "${resolv_conf_passthrough:-NO}" in
for opt in $(uniqify $opts); do
newconf="${newconf} $opt"
done
newconf="$newconf\n"
newconf="$newconf$NL"
fi
if [ -n "$resolv_conf_tail" ]; then
newconf="$newconf$resolv_conf_tail\n"
newconf="$newconf$resolv_conf_tail$NL"
fi
;;
esac
# Check if the file has actually changed or not
if [ -e "$resolv_conf" ]; then
[ "$(cat "$resolv_conf")" = "$(printf "$newconf")" ] && exit 0
[ "$(cat "$resolv_conf")" = "$(printf %s "$newconf")" ] && exit 0
fi
# Create our resolv.conf now
(umask 022; printf "$newconf" >"$resolv_conf")
(umask 022; printf %s "$newconf" >"$resolv_conf")
eval $libc_restart
retval=0
@ -160,7 +162,7 @@ for script in "$LIBEXECDIR"/libc.d/*; do
if [ -x "$script" ]; then
"$script" "$@"
else
(. "$script" "$@")
(. "$script")
fi
retval=$(($retval + $?))
fi

View File

@ -1,5 +1,5 @@
#!/bin/sh
# Copyright (c) 2007-2009 Roy Marples
# Copyright (c) 2007-2011 Roy Marples
# All rights reserved
# named subscriber for resolvconf
@ -30,6 +30,8 @@
. "@SYSCONFDIR@/resolvconf.conf" || exit 1
[ -z "$named_zones" -a -z "$named_options" ] && exit 0
[ -z "$RESOLVCONF" ] && eval "$(@PREFIX@/sbin/resolvconf -v)"
NL="
"
# Platform specific kludges
if [ -z "$named_service" -a -z "$named_restart" -a \
@ -42,49 +44,56 @@ then
fi
: ${named_service:=named}
: ${named_restart:=@RESTARTCMD ${named_service}@}
newoptions="# Generated by resolvconf\n"
newoptions="# Generated by resolvconf$NL"
newzones="$newoptions"
forward=
for n in $NAMESERVERS; do
case "$forward" in
*"\n\t$n;"*);;
*) forward="$forward\n\t$n;";;
*"$NL $n;"*);;
*) forward="$forward$NL $n;";;
esac
done
if [ -n "$forward" ]; then
newoptions="${newoptions}forward first;\nforwarders {$forward\n};\n"
newoptions="${newoptions}forward first;${NL}forwarders {$forward${NL}};$NL"
fi
for d in $DOMAINS; do
newzones="${newzones}zone \"${d%%:*}\" {\n"
newzones="$newzones\ttype forward;\n"
newzones="$newzones\tforward first;\n\tforwarders {\n"
newzones="${newzones}zone \"${d%%:*}\" {$NL"
newzones="$newzones type forward;$NL"
newzones="$newzones forward first;$NL forwarders {$NL"
ns="${d#*:}"
while [ -n "$ns" ]; do
newzones="$newzones\t\t${ns%%,*};\n"
newzones="$newzones ${ns%%,*};$NL"
[ "$ns" = "${ns#*,}" ] && break
ns="${ns#*,}"
done
newzones="$newzones\t};\n};\n"
newzones="$newzones };$NL};$NL"
done
# Try to ensure that config dirs exist
if type config_mkdirs >/dev/null 2>&1; then
config_mkdirs "$named_options" "$named_zones"
else
@PREFIX@/sbin/resolvconf -D "$named_options" "$named_zones"
fi
# No point in changing files or reloading bind if the end result has not
# changed
changed=false
if [ -n "$named_options" ]; then
if [ ! -f "$named_options" ] || \
[ "$(cat "$named_options")" != "$(printf "$newoptions")" ]
[ "$(cat "$named_options")" != "$(printf %s "$newoptions")" ]
then
printf "$newoptions" >"$named_options"
printf %s "$newoptions" >"$named_options"
changed=true
fi
fi
if [ -n "$named_zones" ]; then
if [ ! -f "$named_zones" ] || \
[ "$(cat "$named_zones")" != "$(printf "$newzones")" ]
[ "$(cat "$named_zones")" != "$(printf %s "$newzones")" ]
then
printf "$newzones" >"$named_zones"
printf %s "$newzones" >"$named_zones"
changed=true
fi
fi

View File

@ -1,5 +1,5 @@
#!/bin/sh
# Copyright (c) 2010 Roy Marples
# Copyright (c) 2010-2011 Roy Marples
# All rights reserved
# pdnsd subscriber for resolvconf
@ -30,6 +30,8 @@
. "@SYSCONFDIR@/resolvconf.conf" || exit 1
[ -z "$pdnsd_conf" -a -z "$pdnsd_resolv" ] && exit 0
[ -z "$RESOLVCONF" ] && eval "$(@PREFIX@/sbin/resolvconf -v)"
NL="
"
: ${pdnsd_restart:=pdnsd-ctl config $pdnsd_conf}
signature="# Generated by resolvconf"
@ -83,21 +85,29 @@ change_file()
newresolv="# Generated by resolvconf\n"
changed=false
# Try to ensure that config dirs exist
if type config_mkdirs >/dev/null 2>&1; then
config_mkdirs "$pdnsd_resolv" "$pdnsd_conf"
else
@PREFIX@/sbin/resolvconf -D "$pdnsd_resolv" "$pdnsd_conf"
fi
if [ -n "$pdnsd_resolv" ]; then
for n in $NAMESERVERS; do
newresolv="${newresolv}nameserver $n\n"
done
fi
if [ -n "$pdnsd_conf" ]; then
# Only modify the configuration if it exists and we can write to it
if [ -w "$pdnsd_conf" ]; then
cf="$pdnsd_conf.new"
newconf=
if [ -z "$pdnsd_resolv" ]; then
newconf="${newconf}server {\n"
newconf="${newconf}\tlabel=resolvconf;\n"
newconf="${newconf}server {$NL"
newconf="${newconf} label=resolvconf;$NL"
if [ -n "$NAMESERVERS" ]; then
newconf="${newconf}\tip="
newconf="${newconf} ip="
first=true
for n in $NAMESERVERS; do
if $first; then
@ -107,16 +117,16 @@ if [ -n "$pdnsd_conf" ]; then
fi
newconf="$newconf$n"
done
newconf="${newconf};\n"
newconf="${newconf};$NL"
fi
newconf="${newconf}}\n"
newconf="${newconf}}$NL"
fi
for d in $DOMAINS; do
newconf="${newconf}server {\n"
newconf="${newconf}\tinclude=.${d%%:*}.;\n"
newconf="${newconf}\tpolicy=excluded;\n"
newconf="${newconf}\tip="
newconf="${newconf}server {$NL"
newconf="${newconf} include=.${d%%:*}.;$NL"
newconf="${newconf} policy=excluded;$NL"
newconf="${newconf} ip="
ns="${d#*:}"
while [ -n "$ns" ]; do
newconf="${newconf}${ns%%,*}"
@ -124,14 +134,14 @@ if [ -n "$pdnsd_conf" ]; then
ns="${ns#*,}"
newconf="${newconf},"
done
newconf="${newconf};\n}\n"
newconf="${newconf};$NL}$NL"
done
rm -f "$cf"
remove_markers "$signature" "$signature_end" "$pdnsd_conf" > "$cf"
if [ -n "$newconf" ]; then
echo "$signature" >> "$cf"
printf "$newconf" >> "$cf"
printf %s "$newconf" >> "$cf"
echo "$signature_end" >> "$cf"
fi
if change_file "$pdnsd_conf" "$cf"; then
@ -141,10 +151,10 @@ fi
if [ -n "$pdnsd_resolv" ]; then
if [ ! -f "$pdnsd_resolv" ] || \
[ "$(cat "$pdnsd_resolv")" != "$(printf "$newresolv")" ]
[ "$(cat "$pdnsd_resolv")" != "$(printf %s "$newresolv")" ]
then
changed=true
printf "$newresolv" >"$pdnsd_resolv"
printf %s "$newresolv" >"$pdnsd_resolv"
fi
fi

View File

@ -1,4 +1,4 @@
.\" Copyright (c) 2007-2009 Roy Marples
.\" Copyright (c) 2007-2011 Roy Marples
.\" All rights reserved
.\"
.\" Redistribution and use in source and binary forms, with or without
@ -22,7 +22,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd December 3, 2009
.Dd May 13, 2011
.Dt RESOLVCONF 8 SMM
.Os
.Sh NAME
@ -218,7 +218,16 @@ This implementation of
.Nm
is called openresolv and is fully command line compatible with Debian's
resolvconf, as written by Thomas Hood.
.Sh SEE ALSO
.Xr resolv.conf 5 ,
.Xr resolvconf.conf 5 ,
.Xr resolver 3 ,
.Xr stdin 3
.Sh AUTHORS
.An Roy Marples Aq roy@marples.name
.Sh BUGS
Please report them to http://roy.marples.name/projects/openresolv
.Pp
.Nm
does not validate any of the files given to it.
.Pp
@ -229,12 +238,3 @@ will generate.
You should consult
.Xr resolvconf.conf 5
for instructions on how to configure your resolver.
.Sh SEE ALSO
.Xr resolv.conf 5 ,
.Xr resolvconf.conf 5 ,
.Xr resolver 3 ,
.Xr stdin 3
.Sh AUTHORS
.An Roy Marples Aq roy@marples.name
.Sh BUGS
Please report them to http://roy.marples.name/projects/openresolv

View File

@ -1,4 +1,4 @@
.\" Copyright (c) 2009-2010 Roy Marples
.\" Copyright (c) 2009-2011 Roy Marples
.\" All rights reserved
.\"
.\" Redistribution and use in source and binary forms, with or without
@ -22,7 +22,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd October 29, 2010
.Dd April 21, 2011
.Dt RESOLVCONF.CONF 5 SMM
.Os
.Sh NAME
@ -43,7 +43,7 @@ Listed below are the standard
.Nm
variables that may be set.
.Pp
After updaing this file, you may wish to run
After updating this file, you may wish to run
.Nm resolvconf -u
to apply the new configuration.
.Sh RESOLVCONF OPTIONS

View File

@ -1,5 +1,5 @@
#!/bin/sh
# Copyright (c) 2007-2009 Roy Marples
# Copyright (c) 2007-2011 Roy Marples
# All rights reserved
# Redistribution and use in source and binary forms, with or without
@ -187,6 +187,41 @@ uniqify()
echo "${result# *}"
}
dirname()
{
local dir= OIFS="$IFS"
local IFS=/
set -- $@
IFS="$OIFS"
if [ -n "$1" ]; then
printf %s .
else
shift
fi
while [ -n "$2" ]; do
printf "/%s" "$1"
shift
done
printf "\n"
}
config_mkdirs()
{
local e=0 f d
for f; do
[ -n "$f" ] || continue
d="$(dirname "$f")"
if [ ! -d "$d" ]; then
if type install >/dev/null 2>&1; then
install -d "$d" || e=$?
else
mkdir "$d" || e=$?
fi
fi
done
return $e
}
list_resolv()
{
[ -d "$IFACEDIR" ] || return 0
@ -197,7 +232,7 @@ list_resolv()
# If we have an interface ordering list, then use that.
# It works by just using pathname expansion in the interface directory.
if [ -n "$1" ]; then
list="$@"
list="$*"
$force || report=true
else
cd "$IFACEDIR"
@ -230,7 +265,7 @@ list_resolv()
fi
if [ "$cmd" = i -o "$cmd" = "-i" ]; then
printf "$i "
printf %s "$i "
else
echo_resolv "$i"
fi
@ -274,7 +309,7 @@ make_vars()
}
force=false
while getopts a:d:fhIilm:puv OPT; do
while getopts a:Dd:fhIilm:puv OPT; do
case "$OPT" in
f) force=true;;
h) usage;;
@ -285,7 +320,7 @@ while getopts a:d:fhIilm:puv OPT; do
esac
done
shift $(($OPTIND - 1))
args="$iface${iface:+ }$@"
args="$iface${iface:+ }$*"
# -I inits the state dir
if [ "$cmd" = I ]; then
@ -295,6 +330,12 @@ if [ "$cmd" = I ]; then
exit $?
fi
# -D ensures that the listed config file base dirs exist
if [ "$cmd" = D ]; then
config_mkdirs "$@"
exit $?
fi
# -l lists our resolv files, optionally for a specific interface
if [ "$cmd" = l -o "$cmd" = i ]; then
list_resolv "$cmd" "$args"
@ -368,17 +409,17 @@ fi
if [ "$cmd" = a ]; then
# Read resolv.conf from stdin
resolv="$(cat)\n"
resolv="$(cat)"
# If what we are given matches what we have, then do nothing
if [ -e "$IFACEDIR/$iface" ]; then
if [ "$(printf "$resolv")" = \
if [ "$(echo "$resolv")" = \
"$(cat "$IFACEDIR/$iface")" ]
then
exit 0
fi
rm "$IFACEDIR/$iface"
fi
printf "$resolv" >"$IFACEDIR/$iface" || exit $?
echo "$resolv" >"$IFACEDIR/$iface" || exit $?
[ ! -d "$METRICDIR" ] && mkdir "$METRICDIR"
rm -f "$METRICDIR/"*" $iface"
if [ -n "$IF_METRIC" ]; then
@ -413,7 +454,7 @@ for script in "$LIBEXECDIR"/*; do
if [ -x "$script" ]; then
"$script" "$cmd" "$iface"
else
(. "$script" "$cmd" "$iface")
(set -- "$cmd" "$iface"; . "$script")
fi
retval=$(($retval + $?))
fi

View File

@ -1,5 +1,5 @@
#!/bin/sh
# Copyright (c) 2009 Roy Marples
# Copyright (c) 2009-2011 Roy Marples
# All rights reserved
# unbound subscriber for resolvconf
@ -30,34 +30,43 @@
. "@SYSCONFDIR@/resolvconf.conf" || exit 1
[ -z "$unbound_conf" ] && exit 0
[ -z "$RESOLVCONF" ] && eval "$(@PREFIX@/sbin/resolvconf -v)"
NL="
"
: ${unbound_pid:=/var/run/unbound.pid}
: ${unbound_service:=unbound}
: ${unbound_restart:=@RESTARTCMD ${unbound_service}@}
newconf="# Generated by resolvconf\n"
newconf="# Generated by resolvconf$NL"
for d in $DOMAINS; do
dn="${d%%:*}"
ns="${d#*:}"
newconf="${newconf}\nforward-zone:\n\tname: \"$dn\"\n"
newconf="$newconf${NL}forward-zone:$NL name: \"$dn\"$NL"
while [ -n "$ns" ]; do
newconf="${newconf}\tforward-addr: ${ns%%,*}\n"
newconf="$newconf forward-addr: ${ns%%,*}$NL"
[ "$ns" = "${ns#*,}" ] && break
ns="${ns#*,}"
done
done
if [ -n "$NAMESERVERS" ]; then
newconf="${newconf}\nforward-zone:\n\tname: \".\"\n"
newconf="$newconf${NL}forward-zone:$NL name: \".\"$NL"
for n in $NAMESERVERS; do
newconf="${newconf}\tforward-addr: $n\n"
newconf="$newconf forward-addr: $n$NL"
done
fi
# Try to ensure that config dirs exist
if type config_mkdirs >/dev/null 2>&1; then
config_mkdirs "$unbound_conf"
else
@PREFIX@/sbin/resolvconf -D "$unbound_conf"
fi
if [ ! -f "$unbound_conf" ] || \
[ "$(cat "$unbound_conf")" != "$(printf "$newconf")" ]
[ "$(cat "$unbound_conf")" != "$(printf %s "$newconf")" ]
then
printf "$newconf" >"$unbound_conf"
printf %s "$newconf" >"$unbound_conf"
# If we can't sent a HUP then force a restart
if [ -s "$unbound_pid" ]; then
if ! kill -HUP $(cat "$unbound_pid") 2>/dev/null; then