View | Details | Raw Unified | Return to bug 199854
Collapse All | Expand All

(-)contrib/openresolv/Makefile (-17 / +36 lines)
Lines 1-9 Link Here
1
include config.mk
1
PKG=		openresolv
2
VERSION=	3.7.0
2
3
3
NAME=		openresolv
4
# Nasty hack so that make clean works without configure being run
4
VERSION=	3.4.1
5
_CONFIG_MK!=	test -e config.mk && echo config.mk || echo config-null.mk
5
PKG=		${NAME}-${VERSION}
6
CONFIG_MK?=	${_CONFIG_MK}
7
include		${CONFIG_MK}
6
8
9
SBINDIR?=	/sbin
10
SYSCONFDIR?=	/etc
11
LIBEXECDIR?=	/libexec/resolvconf
12
VARDIR?=	/var/run/resolvconf
13
RCDIR?=		/etc/rc.d
14
RESTARTCMD?=	if ${RCDIR}/\1 status >/dev/null 2>\&1; then \
15
			${RCDIR}/\1 restart; \
16
		fi
17
7
INSTALL?=	install
18
INSTALL?=	install
8
SED?=		sed
19
SED?=		sed
9
20
Lines 17-23 Link Here
17
SRCS=		${TARGET:C,$,.in,} # pmake
28
SRCS=		${TARGET:C,$,.in,} # pmake
18
SRCS:=		${TARGET:=.in} # gmake
29
SRCS:=		${TARGET:=.in} # gmake
19
30
20
SED_PREFIX=		-e 's:@PREFIX@:${PREFIX}:g'
31
SED_SBINDIR=		-e 's:@SBINDIR@:${SBINDIR}:g'
21
SED_SYSCONFDIR=		-e 's:@SYSCONFDIR@:${SYSCONFDIR}:g'
32
SED_SYSCONFDIR=		-e 's:@SYSCONFDIR@:${SYSCONFDIR}:g'
22
SED_LIBEXECDIR=		-e 's:@LIBEXECDIR@:${LIBEXECDIR}:g'
33
SED_LIBEXECDIR=		-e 's:@LIBEXECDIR@:${LIBEXECDIR}:g'
23
SED_VARDIR=		-e 's:@VARDIR@:${VARDIR}:g'
34
SED_VARDIR=		-e 's:@VARDIR@:${VARDIR}:g'
Lines 24-47 Link Here
24
SED_RCDIR=		-e 's:@RCDIR@:${RCDIR}:g'
35
SED_RCDIR=		-e 's:@RCDIR@:${RCDIR}:g'
25
SED_RESTARTCMD=		-e 's:@RESTARTCMD \(.*\)@:${RESTARTCMD}:g'
36
SED_RESTARTCMD=		-e 's:@RESTARTCMD \(.*\)@:${RESTARTCMD}:g'
26
37
38
DISTPREFIX?=	${PKG}-${VERSION}
39
DISTFILEGZ?=	${DISTPREFIX}.tar.gz
40
DISTFILE?=	${DISTPREFIX}.tar.bz2
41
FOSSILID?=	current
42
27
.SUFFIXES: .in
43
.SUFFIXES: .in
28
44
29
all: ${TARGET}
45
all: ${TARGET}
30
46
31
.in:
47
.in:
32
	${SED}	${SED_PREFIX} ${SED_SYSCONFDIR} ${SED_LIBEXECDIR} \
48
	${SED}	${SED_SBINDIR} ${SED_SYSCONFDIR} ${SED_LIBEXECDIR} \
33
		${SED_VARDIR} ${SED_RCDIR} ${SED_RESTARTCMD} \
49
		${SED_VARDIR} ${SED_RCDIR} ${SED_RESTARTCMD} \
34
		$< > $@
50
		$< > $@
35
51
36
clean:
52
clean:
37
	rm -f ${TARGET} openresolv-${VERSION}.tar.bz2
53
	rm -f ${TARGET}
38
54
39
distclean: clean
55
distclean: clean
40
	rm -f config.mk
56
	rm -f config.mk ${DISTFILE}
41
57
42
installdirs:
58
installdirs:
43
59
44
install: ${TARGET}
60
proginstall: ${TARGET}
45
	${INSTALL} -d ${DESTDIR}${SBINDIR}
61
	${INSTALL} -d ${DESTDIR}${SBINDIR}
46
	${INSTALL} -m ${BINMODE} resolvconf ${DESTDIR}${SBINDIR}
62
	${INSTALL} -m ${BINMODE} resolvconf ${DESTDIR}${SBINDIR}
47
	${INSTALL} -d ${DESTDIR}${SYSCONFDIR}
63
	${INSTALL} -d ${DESTDIR}${SYSCONFDIR}
Lines 49-66 Link Here
49
	${INSTALL} -m ${DOCMODE} resolvconf.conf ${DESTDIR}${SYSCONFDIR}
65
	${INSTALL} -m ${DOCMODE} resolvconf.conf ${DESTDIR}${SYSCONFDIR}
50
	${INSTALL} -d ${DESTDIR}${LIBEXECDIR}
66
	${INSTALL} -d ${DESTDIR}${LIBEXECDIR}
51
	${INSTALL} -m ${DOCMODE} ${SUBSCRIBERS} ${DESTDIR}${LIBEXECDIR}
67
	${INSTALL} -m ${DOCMODE} ${SUBSCRIBERS} ${DESTDIR}${LIBEXECDIR}
68
69
maninstall:
52
	${INSTALL} -d ${DESTDIR}${MANDIR}/man8
70
	${INSTALL} -d ${DESTDIR}${MANDIR}/man8
53
	${INSTALL} -m ${MANMODE} resolvconf.8 ${DESTDIR}${MANDIR}/man8
71
	${INSTALL} -m ${MANMODE} resolvconf.8 ${DESTDIR}${MANDIR}/man8
54
	${INSTALL} -d ${DESTDIR}${MANDIR}/man5
72
	${INSTALL} -d ${DESTDIR}${MANDIR}/man5
55
	${INSTALL} -m ${MANMODE} resolvconf.conf.5 ${DESTDIR}${MANDIR}/man5
73
	${INSTALL} -m ${MANMODE} resolvconf.conf.5 ${DESTDIR}${MANDIR}/man5
56
74
75
install: proginstall maninstall
76
57
import:
77
import:
58
	rm -rf /tmp/${PKG}
78
	rm -rf /tmp/${DISTPREFIX}
59
	${INSTALL} -d /tmp/${PKG}
79
	${INSTALL} -d /tmp/${DISTPREFIX}
60
	cp README ${SRCS} /tmp/${PKG}
80
	cp README ${SRCS} /tmp/${DISPREFIX}
61
81
62
dist: import
82
dist:
63
	cp configure Makefile resolvconf.conf /tmp/${PKG}
83
	fossil tarball --name ${DISTPREFIX} ${FOSSILID} ${DISTFILEGZ}
64
	tar cvjpf ${PKG}.tar.bz2 -C /tmp ${PKG} 
84
	gunzip -c ${DISTFILEGZ} |  bzip2 >${DISTFILE}
65
	rm -rf /tmp/${PKG} 
85
	rm ${DISTFILEGZ}
66
	ls -l ${PKG}.tar.bz2
(-)contrib/openresolv/configure (-47 / +86 lines)
Lines 18-24 Link Here
18
	--debug) DEBUG=$var;;
18
	--debug) DEBUG=$var;;
19
	--disable-debug) DEBUG=no;;
19
	--disable-debug) DEBUG=no;;
20
	--enable-debug) DEBUG=yes;;
20
	--enable-debug) DEBUG=yes;;
21
	--prefix) prefix=$var;;
21
	--prefix) PREFIX=$var;;
22
	--sysconfdir) SYSCONFDIR=$var;;
22
	--sysconfdir) SYSCONFDIR=$var;;
23
	--bindir|--sbindir) SBINDIR=$var;;
23
	--bindir|--sbindir) SBINDIR=$var;;
24
	--libexecdir) LIBEXECDIR=$var;;
24
	--libexecdir) LIBEXECDIR=$var;;
Lines 41-52 Link Here
41
	esac
41
	esac
42
done
42
done
43
43
44
if [ -z "$LIBEXECDIR" ]; then
45
	printf "Checking for directory /libexec ... "
46
	if [ -d /libexec ]; then
47
		echo "yes"
48
		LIBEXECDIR=$PREFIX/libexec/resolvconf
49
	else
50
		echo "no"
51
		LIBEXECDIR=$PREFIX/lib/resolvconf
52
	fi
53
fi
54
if [ -z "$RUNDIR" ]; then
55
	printf "Checking for directory /run ... "
56
	if [ -d /run ]; then
57
		echo "yes"
58
		RUNDIR=/run
59
	else
60
		echo "no"
61
		RUNDIR=/var/run
62
	fi
63
fi	
64
44
: ${SED:=sed}
65
: ${SED:=sed}
45
66
46
: ${PREFIX:=$prefix}
47
: ${SYSCONFDIR:=$PREFIX/etc}
67
: ${SYSCONFDIR:=$PREFIX/etc}
48
: ${SBINDIR:=$PREFIX/sbin}
68
: ${SBINDIR:=$PREFIX/sbin}
49
: ${LIBEXECDIR:=$PREFIX/libexec}
69
: ${LIBEXECDIR:=$PREFIX/libexec/resolvconf}
50
: ${STATEDIR:=/var}
70
: ${STATEDIR:=/var}
51
: ${RUNDIR:=$STATEDIR/run}
71
: ${RUNDIR:=$STATEDIR/run}
52
: ${MANDIR:=${PREFIX:-/usr}/share/man}
72
: ${MANDIR:=${PREFIX:-/usr}/share/man}
Lines 53-59 Link Here
53
73
54
eval SYSCONFDIR="$SYSCONFDIR"
74
eval SYSCONFDIR="$SYSCONFDIR"
55
eval SBINDIR="$SBINDIR"
75
eval SBINDIR="$SBINDIR"
56
eval LIBEXECDIR="$LIBEXECDIR/resolvconf"
76
eval LIBEXECDIR="$LIBEXECDIR"
57
eval VARDIR="$RUNDIR/resolvconf"
77
eval VARDIR="$RUNDIR/resolvconf"
58
eval MANDIR="$MANDIR"
78
eval MANDIR="$MANDIR"
59
79
Lines 60-108 Link Here
60
CONFIG_MK=config.mk
80
CONFIG_MK=config.mk
61
81
62
if [ -z "$BUILD" ]; then
82
if [ -z "$BUILD" ]; then
63
	BUILD=`uname -m`-`uname -s | tr '[:upper:]' '[:lower:]'`
83
	# autoconf target triplet: cpu-vendor-os
84
	BUILD=$(uname -m)-unknown-$(uname -s | tr '[:upper:]' '[:lower:]')
64
fi
85
fi
65
if [ -z "$HOST" ]; then
86
: ${HOST:=$BUILD}
66
	[ -z "$TARGET" ] && TARGET=$BUILD
67
	HOST=$TARGET
68
fi
69
if [ -z "$TARGET" ]; then
70
	[ -z "$HOST" ] && HOST=$BUILD
71
	TARGET=$HOST
72
fi
73
87
74
# Debian and Slackware have linux in different places when dealing with
75
# autoconf, so we deal with that here.
76
if [ -z "$OS" ]; then
88
if [ -z "$OS" ]; then
77
	case "$TARGET" in
89
	echo "Deriving operating system from ... $HOST"
78
	*-linux-*|linux-*|*-linux|linux) OS=linux;;
90
	# Derive OS from cpu-vendor-[kernel-]os
79
	esac
91
	CPU=${HOST%%-*}
80
fi
92
	REST=${HOST#*-}
81
82
if [ -z "$OS" ]; then
83
	# Derive OS from cpu-manufacturer-os-kernel
84
	CPU=${TARGET%%-*}
85
	REST=${TARGET#*-}
86
	if [ "$CPU" != "$REST" ]; then
93
	if [ "$CPU" != "$REST" ]; then
87
		MANU=${REST%%-*}
94
		VENDOR=${REST%%-*}
88
		REST=${REST#*-}
95
		REST=${REST#*-}
89
		if [ "$MANU" != "$REST" ]; then
96
		if [ "$VENDOR" != "$REST" ]; then
97
			# Use kernel if given, otherwise os
90
			OS=${REST%%-*}
98
			OS=${REST%%-*}
91
			REST=${REST#*-}
92
			if [ "$OS" != "$REST" ]; then
93
				KERNEL=${REST%%-*}
94
			else
95
				# 3 tupple
96
				KERNEL=$OS
97
				OS=$MANU
98
				MANU=
99
			fi
100
		else
99
		else
101
			# 2 tupple
100
			# 2 tupple
102
			OS=$MANU
101
			OS=$VENDOR
103
			MANU=
102
			VENDOR=
104
		fi
103
		fi
105
	fi
104
	fi
105
106
        # Work with cpu-kernel-os, ie Debian
107
	case "$VENDOR" in
108
	linux*|kfreebsd*) OS=$VENDOR; VENDOR= ;;
109
	esac
110
	# Special case
111
	case "$OS" in
112
	gnu*) OS=hurd;; # No HURD support as yet
113
	esac
106
fi
114
fi
107
115
108
echo "Configuring openresolv for ... $OS"
116
echo "Configuring openresolv for ... $OS"
Lines 118-134 Link Here
118
	echo "$x=$t	$v" >>$CONFIG_MK
126
	echo "$x=$t	$v" >>$CONFIG_MK
119
done
127
done
120
128
121
if [ -e /etc/arch-release -a -d /etc/rc.d ]; then
129
if [ -z "$RESTARTCMD" ]; then
122
	echo "Overriding service status check for Arch Linux"
130
	printf "Checking for systemd ... "
123
	RCDIR=/etc/rc.d
131
	if [ -x /bin/systemctl ]; then
124
	RESTARTCMD="[ -e /var/run/daemons/\1 ] \&\& /etc/rc.d/\1 restart"
132
		RESTARTCMD="/bin/systemctl try-restart \1"
125
	echo "yes"
133
		echo "yes"
134
	elif [ -x /usr/bin/systemctl ]; then
135
		RESTARTCMD="/usr/bin/systemctl try-restart \1"
136
		echo "yes"
137
	else
138
		echo "no"
139
	fi
126
fi
140
fi
127
141
142
# Arch upgraded to systemd, so this check has to be just after systemd
143
# but higher than the others
128
if [ -z "$RESTARTCMD" ]; then
144
if [ -z "$RESTARTCMD" ]; then
145
	printf "Checking for Arch ... "
146
	if [ -e /etc/arch-release -a -d /etc/rc.d ]; then
147
		RCDIR=/etc/rc.d
148
		RESTARTCMD="[ -e /var/run/daemons/\1 ] \&\& /etc/rc.d/\1 restart"
149
		echo "yes"
150
	else
151
		echo "no"
152
	fi
153
fi
154
155
if [ -z "$RESTARTCMD" ]; then
129
	printf "Checking for OpenRC ... "
156
	printf "Checking for OpenRC ... "
130
	if [ -x /sbin/rc-service ]; then
157
	if [ -x /sbin/rc-service ]; then
131
		RESTARTCMD="/sbin/rc-service -e \1 \&\& /sbin/rc-service \1 -- -Ds restart"
158
		RESTARTCMD="if /sbin/rc-service -e \1; then /sbin/rc-service \1 -- -Ds restart; fi"
132
		echo "yes"
159
		echo "yes"
133
	else
160
	else
134
		echo "no"
161
		echo "no"
Lines 138-144 Link Here
138
	printf "Checking for invoke-rc.d ... "
165
	printf "Checking for invoke-rc.d ... "
139
	if [ -x /usr/sbin/invoke-rc.d ]; then
166
	if [ -x /usr/sbin/invoke-rc.d ]; then
140
		RCDIR=/etc/init.d
167
		RCDIR=/etc/init.d
141
		RESTARTCMD="/usr/sbin/invoke-rc.d --quiet \1 status >/dev/null 2>\&1 \&\& /usr/sbin/invoke-rc.d \1 restart"
168
		RESTARTCMD="if /usr/sbin/invoke-rc.d --quiet \1 status >/dev/null 2>\&1; then /usr/sbin/invoke-rc.d \1 restart; fi"
142
		echo "yes"
169
		echo "yes"
143
	else
170
	else
144
		echo "no"
171
		echo "no"
Lines 148-154 Link Here
148
	printf "Checking for service ... "
175
	printf "Checking for service ... "
149
	if [ -x /sbin/service ]; then
176
	if [ -x /sbin/service ]; then
150
		RCDIR=/etc/init.d
177
		RCDIR=/etc/init.d
151
		RESTARTCMD="/sbin/service \1 \&\& /sbin/service \1 restart"
178
		RESTARTCMD="if /sbin/service \1; then /sbin/service \1 restart; fi"
152
		echo "yes"
179
		echo "yes"
153
	else
180
	else
154
		echo "no"
181
		echo "no"
Lines 155-165 Link Here
155
	fi
182
	fi
156
fi
183
fi
157
if [ -z "$RESTARTCMD" ]; then
184
if [ -z "$RESTARTCMD" ]; then
185
	printf "Checking for runit... "
186
	if [ -x /bin/sv ]; then
187
		RESTARTCMD="/bin/sv try-restart \1"
188
		echo "yes"
189
	elif [ -x /usr/bin/sv ]; then
190
		RESTARTCMD="/usr/bin/sv try-restart \1"
191
		echo "yes"
192
	else
193
		echo "no"
194
	fi
195
fi
196
if [ -z "$RESTARTCMD" ]; then
158
	for x in /etc/init.d/rc.d /etc/rc.d /etc/init.d; do
197
	for x in /etc/init.d/rc.d /etc/rc.d /etc/init.d; do
159
		printf "Checking for $x ... "
198
		printf "Checking for $x ... "
160
		if [ -d $x ]; then
199
		if [ -d $x ]; then
161
			RCDIR=$x
200
			RCDIR=$x
162
			RESTARTCMD="$x/\1 status >/dev/null 2>\&1 \&\& $x/\1 restart"
201
			RESTARTCMD="if $x/\1 status >/dev/null 2>\&1; then $x/\1 restart; fi"
163
			echo "yes"
202
			echo "yes"
164
			break
203
			break
165
		else
204
		else
Lines 169-175 Link Here
169
fi
208
fi
170
209
171
if [ -z "$RESTARTCMD" ]; then
210
if [ -z "$RESTARTCMD" ]; then
172
	echo "WARNING! No means of interacting with system services detected!"
211
	echo "$0: WARNING: No means of interacting with system services detected!"
173
	exit 1
212
	exit 1
174
fi
213
fi
175
214
(-)contrib/openresolv/dnsmasq.in (-34 / +109 lines)
Lines 1-5 Link Here
1
#!/bin/sh
1
#!/bin/sh
2
# Copyright (c) 2007-2009 Roy Marples
2
# Copyright (c) 2007-2012 Roy Marples
3
# All rights reserved
3
# All rights reserved
4
4
5
# dnsmasq subscriber for resolvconf
5
# dnsmasq subscriber for resolvconf
Lines 29-40 Link Here
29
[ -f "@SYSCONFDIR@"/resolvconf.conf ] || exit 0
29
[ -f "@SYSCONFDIR@"/resolvconf.conf ] || exit 0
30
. "@SYSCONFDIR@/resolvconf.conf" || exit 1
30
. "@SYSCONFDIR@/resolvconf.conf" || exit 1
31
[ -z "$dnsmasq_conf" -a -z "$dnsmasq_resolv" ] && exit 0
31
[ -z "$dnsmasq_conf" -a -z "$dnsmasq_resolv" ] && exit 0
32
[ -z "$RESOLVCONF" ] && eval "$(@PREFIX@/sbin/resolvconf -v)"
32
[ -z "$RESOLVCONF" ] && eval "$(@SBINDIR@/resolvconf -v)"
33
NL="
33
NL="
34
"
34
"
35
35
36
: ${dnsmasq_pid:=/var/run/dnsmasq.pid}
36
: ${dnsmasq_pid:=/var/run/dnsmasq.pid}
37
[ -s "$dnsmasq_pid" ] || dnsmasq_pid=/var/run/dnsmasq/dnsmasq.pid
37
[ -s "$dnsmasq_pid" ] || dnsmasq_pid=/var/run/dnsmasq/dnsmasq.pid
38
[ -s "$dnsmasq_pid" ] || unset dnsmasq_pid
38
: ${dnsmasq_service:=dnsmasq}
39
: ${dnsmasq_service:=dnsmasq}
39
: ${dnsmasq_restart:=@RESTARTCMD ${dnsmasq_service}@}
40
: ${dnsmasq_restart:=@RESTARTCMD ${dnsmasq_service}@}
40
newconf="# Generated by resolvconf$NL"
41
newconf="# Generated by resolvconf$NL"
Lines 46-66 Link Here
46
# so we need to validate a few things first.
47
# so we need to validate a few things first.
47
# Check for DBus support in the binary
48
# Check for DBus support in the binary
48
dbus=false
49
dbus=false
49
: ${dbus_pid:=/var/run/dbus/dbus.pid}
50
dbus_ex=false
50
[ -s "$dbus_pid" ] || dbus_pid=/var/run/dbus.pid
51
dbus_introspect=$(dbus-send --print-reply --system \
51
[ -s "$dbus_pid" ] || dbus_pid=/var/run/dbus/pid
52
	--dest=uk.org.thekelleys.dnsmasq \
52
if [ -s "$dbus_pid" -a -s "$dnsmasq_pid" ]; then
53
	/uk/org/thekelleys/dnsmasq \
53
	if dnsmasq --version 2>/dev/null | \
54
	org.freedesktop.DBus.Introspectable.Introspect \
54
		grep -q "^Compile time options.*[[:space:]]DBus[[:space:]]"
55
	2>/dev/null)
56
if [ $? = 0 ]; then
57
	dbus=true
58
	if printf %s "$dbus_introspect" | \
59
	    grep -q '<method name="SetDomainServers">'
55
	then
60
	then
56
		# Sanity - check that dnsmasq and dbus are running
61
		dbus_ex=true
57
		if kill -0 $(cat "$dbus_pid") 2>/dev/null && \
58
			kill -0 $(cat "$dnsmasq_pid") 2>/dev/null
59
		then
60
			dbus=true
61
			newconf="$newconf$NL# Domain specific servers will"
62
			newconf="$newconf be sent over dbus${NL}enable-dbus$NL"
63
		fi
64
	fi
62
	fi
65
fi
63
fi
66
64
Lines 69-98 Link Here
69
done
67
done
70
68
71
dbusdest=
69
dbusdest=
70
dbusdest_ex=
71
conf=
72
for d in $DOMAINS; do
72
for d in $DOMAINS; do
73
	dn="${d%%:*}"
73
	dn="${d%%:*}"
74
	ns="${d#*:}"
74
	ns="${d#*:}"
75
	while [ -n "$ns" ]; do
75
	while [ -n "$ns" ]; do
76
		if $dbus; then
76
		n="${ns%%,*}"
77
			SIFS=${IFS-y} OIFS=$IFS
77
		if $dbus && ! $dbus_ex; then
78
			IFS=.
78
			case "$n" in
79
			set -- ${ns%%,*}
79
			*.*.*.*)
80
			num="0x$(printf %02x $1 $2 $3 $4)"
80
				SIFS=${IFS-y} OIFS=$IFS
81
			if [ "$SIFS" = yi ]; then
81
				IFS=.
82
				unset IFS
82
				set -- $n
83
			else
83
				num="0x$(printf %02x $1 $2 $3 $4)"
84
				IFS=$OIFS
84
				if [ "$SIFS" = y ]; then
85
			fi
85
					unset IFS
86
			dbusdest="$dbusdest uint32:$(printf %u $num)"
86
				else
87
			dbusdest="$dbusdest string:$dn"
87
					IFS=$OIFS
88
		else
88
				fi
89
			newconf="${newconf}server=/$dn/${ns%%,*}$NL"
89
				dbusdest="$dbusdest uint32:$(printf %u $num)"
90
				dbusdest="$dbusdest string:$dn"
91
				;;
92
			*:*%*)
93
				# This version of dnsmasq won't accept
94
				# scoped IPv6 addresses
95
				dbus=false
96
				;;
97
			*:*)
98
				SIFS=${IFS-y} OIFS=$IFS bytes= front= back=
99
				empty=false i=0
100
				IFS=:
101
				set -- $n
102
				while [ -n "$1" -o -n "$2" ]; do
103
					addr="$1"
104
					shift
105
					if [ -z "$addr" ]; then
106
						empty=true
107
						continue
108
					fi
109
					i=$(($i + 1))
110
					while [ ${#addr} -lt 4 ]; do
111
						addr="0${addr}"
112
					done
113
					byte1="$(printf %d 0x${addr%??})"
114
					byte2="$(printf %d 0x${addr#??})"
115
					if $empty; then
116
						back="$back byte:$byte1 byte:$byte2"
117
					else
118
						front="$front byte:$byte1 byte:$byte2"
119
					fi
120
				done
121
				while [ $i != 8 ]; do
122
				i=$(($i + 1))
123
					front="$front byte:0 byte:0"
124
				done
125
				front="${front}$back"
126
				if [ "$SIFS" = y ]; then
127
					unset IFS
128
				else
129
					IFS=$OIFS
130
				fi
131
				dbusdest="${dbusdest}$front string:$dn"
132
				;;
133
			*)
134
				if ! $dbus_ex; then
135
					dbus=false
136
				fi
137
				;;
138
			esac
90
		fi
139
		fi
140
		dbusdest_ex="$dbusdest_ex${dbusdest_ex:+,}/$dn/$n"
141
		conf="${conf}server=/$dn/$n$NL"
91
		[ "$ns" = "${ns#*,}" ] && break
142
		[ "$ns" = "${ns#*,}" ] && break
92
		ns="${ns#*,}"
143
		ns="${ns#*,}"
93
	done
144
	done
94
done
145
done
95
146
147
if $dbus; then
148
	newconf="$newconf$NL# Domain specific servers will"
149
	newconf="$newconf be sent over dbus${NL}"
150
else
151
	newconf="$newconf$conf"
152
fi
153
154
# Try to ensure that config dirs exist
155
if type config_mkdirs >/dev/null 2>&1; then
156
	config_mkdirs "$dnsmasq_conf" "$dnsmasq_resolv"
157
else
158
	@SBINDIR@/resolvconf -D "$dnsmasq_conf" "$dnsmasq_resolv"
159
fi
160
96
changed=false
161
changed=false
97
if [ -n "$dnsmasq_conf" ]; then
162
if [ -n "$dnsmasq_conf" ]; then
98
	if [ ! -f "$dnsmasq_conf" ] || \
163
	if [ ! -f "$dnsmasq_conf" ] || \
Lines 103-116 Link Here
103
	fi
168
	fi
104
fi
169
fi
105
if [ -n "$dnsmasq_resolv" ]; then
170
if [ -n "$dnsmasq_resolv" ]; then
171
	# dnsmasq polls this file so no need to set changed=true
106
	if [ -f "$dnsmasq_resolv" ]; then
172
	if [ -f "$dnsmasq_resolv" ]; then
107
		if [ "$(cat "$dnsmasq_resolv")" != "$(printf %s "$newresolv")" ]
173
		if [ "$(cat "$dnsmasq_resolv")" != "$(printf %s "$newresolv")" ]
108
		then
174
		then
109
			changed=true
110
			printf %s "$newresolv" >"$dnsmasq_resolv"
175
			printf %s "$newresolv" >"$dnsmasq_resolv"
111
		fi
176
		fi
112
	else
177
	else
113
		# dnsmasq polls this file so no need to set changed=true
114
		printf %s "$newresolv" >"$dnsmasq_resolv"
178
		printf %s "$newresolv" >"$dnsmasq_resolv"
115
	fi
179
	fi
116
fi
180
fi
Lines 119-127 Link Here
119
	eval $dnsmasq_restart
183
	eval $dnsmasq_restart
120
fi
184
fi
121
if $dbus; then
185
if $dbus; then
122
	$changed || kill -HUP $(cat "$dnsmasq_pid")
186
	if [ -s "$dnsmasq_pid" ]; then
187
        	$changed || kill -HUP $(cat "$dnsmasq_pid")
188
	fi
123
	# Send even if empty so old servers are cleared
189
	# Send even if empty so old servers are cleared
190
	if $dbus_ex; then
191
		method=SetDomainServers
192
		if [ -n "$dbusdest_ex" ]; then
193
			dbusdest_ex="array:string:$dbusdest_ex"
194
		fi
195
		dbusdest="$dbusdest_ex"
196
	else
197
		method=SetServers
198
	fi
124
	dbus-send --system --dest=uk.org.thekelleys.dnsmasq \
199
	dbus-send --system --dest=uk.org.thekelleys.dnsmasq \
125
 		/uk/org/thekelleys/dnsmasq uk.org.thekelleys.SetServers \
200
 		/uk/org/thekelleys/dnsmasq uk.org.thekelleys.$method \
126
  		$dbusdest
201
  		$dbusdest
127
fi
202
fi
(-)contrib/openresolv/libc.in (-24 / +100 lines)
Lines 1-5 Link Here
1
#!/bin/sh
1
#!/bin/sh
2
# Copyright (c) 2007-2009 Roy Marples
2
# Copyright (c) 2007-2014 Roy Marples
3
# All rights reserved
3
# All rights reserved
4
4
5
# libc subscriber for resolvconf
5
# libc subscriber for resolvconf
Lines 36-46 Link Here
36
# sed may not be available, and this is faster on small files
36
# sed may not be available, and this is faster on small files
37
key_get_value()
37
key_get_value()
38
{
38
{
39
	local key="$1" value= x= line=
39
	local key="$1" x= line=
40
40
41
	shift
41
	shift
42
	if [ $# -eq 0 ]; then
42
	if [ $# -eq 0 ]; then
43
		while read line; do
43
		while read -r line; do
44
			case "$line" in
44
			case "$line" in
45
			"$key"*) echo "${line##$key}";;
45
			"$key"*) echo "${line##$key}";;
46
			esac
46
			esac
Lines 47-53 Link Here
47
		done
47
		done
48
	else
48
	else
49
		for x; do
49
		for x; do
50
			while read line; do
50
			while read -r line; do
51
				case "$line" in
51
				case "$line" in
52
				"$key"*) echo "${line##$key}";;
52
				"$key"*) echo "${line##$key}";;
53
				esac
53
				esac
Lines 56-61 Link Here
56
	fi
56
	fi
57
}
57
}
58
58
59
keys_remove()
60
{
61
	local key x line found
62
63
	while read -r line; do
64
		found=false
65
		for key do
66
			case "$line" in
67
			"$key"*|"#"*|" "*|"	"*|"") found=true;;
68
			esac
69
			$found && break
70
		done
71
		$found || echo "$line"
72
	done
73
}
74
75
local_nameservers="127.* 0.0.0.0 255.255.255.255 ::1"
76
59
# Support original resolvconf configuration layout
77
# Support original resolvconf configuration layout
60
# as well as the openresolv config file
78
# as well as the openresolv config file
61
if [ -f "$SYSCONFDIR"/resolvconf.conf ]; then
79
if [ -f "$SYSCONFDIR"/resolvconf.conf ]; then
Lines 64-75 Link Here
64
	SYSCONFDIR="$SYSCONFDIR/resolvconf/resolv.conf.d"
82
	SYSCONFDIR="$SYSCONFDIR/resolvconf/resolv.conf.d"
65
	base="$SYSCONFDIR/resolv.conf.d/base"
83
	base="$SYSCONFDIR/resolv.conf.d/base"
66
	if [ -f "$base" ]; then
84
	if [ -f "$base" ]; then
67
		name_servers="$(key_get_value "nameserver " "$base")"
85
		prepend_nameservers="$(key_get_value "nameserver " "$base")"
68
		search_domains="$(key_get_value "search " "$base")"
86
		domain="$(key_get_value "domain " "$base")"
69
		if [ -z "$search_domains" ]; then
87
		prepend_search="$(key_get_value "search " "$base")"
70
			search_domains="$(key_get_value "domain " "$base")"
71
		fi
72
		resolv_conf_options="$(key_get_value "options " "$base")"
88
		resolv_conf_options="$(key_get_value "options " "$base")"
89
		resolv_conf_sortlist="$(key_get_value "sortlist " "$base")"
73
	fi
90
	fi
74
	if [ -f "$SYSCONFDIR"/resolv.conf.d/head ]; then
91
	if [ -f "$SYSCONFDIR"/resolv.conf.d/head ]; then
75
		resolv_conf_head="$(cat "${SYSCONFDIR}"/resolv.conf.d/head)"
92
		resolv_conf_head="$(cat "${SYSCONFDIR}"/resolv.conf.d/head)"
Lines 81-87 Link Here
81
: ${resolv_conf:=/etc/resolv.conf}
98
: ${resolv_conf:=/etc/resolv.conf}
82
: ${libc_service:=nscd}
99
: ${libc_service:=nscd}
83
: ${libc_restart:=@RESTARTCMD ${libc_service}@}
100
: ${libc_restart:=@RESTARTCMD ${libc_service}@}
84
: ${list_resolv:=@PREFIX@/sbin/resolvconf -l}
101
: ${list_resolv:=@SBINDIR@/resolvconf -l}
85
if [ "${resolv_conf_head-x}" = x -a -f "$SYSCONFDIR"/resolv.conf.head ]; then
102
if [ "${resolv_conf_head-x}" = x -a -f "$SYSCONFDIR"/resolv.conf.head ]; then
86
	resolv_conf_head="$(cat "${SYSCONFDIR}"/resolv.conf.head)"
103
	resolv_conf_head="$(cat "${SYSCONFDIR}"/resolv.conf.head)"
87
fi
104
fi
Lines 89-94 Link Here
89
	resolv_conf_tail="$(cat "$SYSCONFDIR"/resolv.conf.tail)"
106
	resolv_conf_tail="$(cat "$SYSCONFDIR"/resolv.conf.tail)"
90
fi
107
fi
91
108
109
backup=true
110
signature="# Generated by resolvconf"
111
 
92
uniqify()
112
uniqify()
93
{
113
{
94
	local result=
114
	local result=
Lines 104-109 Link Here
104
124
105
case "${resolv_conf_passthrough:-NO}" in
125
case "${resolv_conf_passthrough:-NO}" in
106
[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
126
[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
127
	backup=false
107
	newest=
128
	newest=
108
	for conf in "$IFACEDIR"/*; do
129
	for conf in "$IFACEDIR"/*; do
109
		if [ -z "$newest" -o "$conf" -nt "$newest" ]; then
130
		if [ -z "$newest" -o "$conf" -nt "$newest" ]; then
Lines 113-145 Link Here
113
	[ -z "$newest" ] && exit 0
134
	[ -z "$newest" ] && exit 0
114
	newconf="$(cat "$newest")$NL"
135
	newconf="$(cat "$newest")$NL"
115
	;;
136
	;;
137
/dev/null|[Nn][Uu][Ll][Ll])
138
	: ${resolv_conf_local_only:=NO}
139
	if [ "$local_nameservers" = "127.* 0.0.0.0 255.255.255.255 ::1" ]; then
140
		local_nameservers=
141
	fi
142
	# Need to overwrite our variables.
143
	eval "$(@SBINDIR@/resolvconf -V)"
144
	;;
145
116
*)
146
*)
117
	[ -z "$RESOLVCONF" ] && eval "$(@PREFIX@/sbin/resolvconf -v)"
147
	[ -z "$RESOLVCONF" ] && eval "$(@SBINDIR@/resolvconf -v)"
118
	newsearch="$(uniqify $search_domains $SEARCH $search_domains_append)"
148
	;;
149
esac
150
case "${resolv_conf_passthrough:-NO}" in
151
[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) ;;
152
*)
153
	: ${domain:=$DOMAIN}
154
	newsearch="$(uniqify $prepend_search $SEARCH $append_search)"
119
	NS="$LOCALNAMESERVERS $NAMESERVERS"
155
	NS="$LOCALNAMESERVERS $NAMESERVERS"
120
	newns="$(uniqify $name_servers $NS $name_servers_append)"
156
	newns=
157
	gotlocal=false
158
	for n in $(uniqify $prepend_nameservers $NS $append_nameservers); do
159
		add=true
160
		islocal=false
161
		for l in $local_nameservers; do
162
			case "$n" in
163
			$l) islocal=true; gotlocal=true; break;;
164
			esac
165
		done
166
		if ! $islocal; then
167
			case "${resolv_conf_local_only:-YES}" in
168
			[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
169
				$gotlocal && add=false;;
170
			esac
171
		fi
172
		$add && newns="$newns $n"
173
	done
121
174
122
	# Hold our new resolv.conf in a variable to save on temporary files
175
	# Hold our new resolv.conf in a variable to save on temporary files
123
	newconf="# Generated by resolvconf$NL"
176
	newconf="$signature$NL"
124
	if [ -n "$resolv_conf_head" ]; then
177
	if [ -n "$resolv_conf_head" ]; then
125
		newconf="$newconf$resolv_conf_head$NL"
178
		newconf="$newconf$resolv_conf_head$NL"
126
	fi
179
	fi
127
	[ -n "$newsearch" ] && newconf="${newconf}search $newsearch$NL"
180
181
	[ -n "$domain" ] && newconf="${newconf}domain $domain$NL"
182
	if [ -n "$newsearch" -a "$newsearch" != "$domain" ]; then
183
		newconf="${newconf}search $newsearch$NL"
184
	fi
128
	for n in $newns; do
185
	for n in $newns; do
129
		newconf="${newconf}nameserver $n$NL"
186
		newconf="${newconf}nameserver $n$NL"
130
	done
187
	done
131
188
132
	# Now get any configured options
189
	# Now add anything we don't care about such as sortlist and options
133
	opts="$resolv_conf_options${resolv_conf_options:+ }"
190
	stuff="$($list_resolv | keys_remove nameserver domain search)"
134
	opts="$opts$($list_resolv | key_get_value "options ")"
191
	if [ -n "$stuff" ]; then
135
	if [ -n "$opts" ]; then
192
		newconf="$newconf$stuff$NL"
136
		newconf="${newconf}options"
137
		for opt in $(uniqify $opts); do
138
			newconf="${newconf} $opt"
139
		done
140
		newconf="$newconf$NL"
141
	fi
193
	fi
142
194
195
	# Append any user defined ones
196
	if [ -n "$resolv_conf_options" ]; then
197
		newconf="${newconf}options $resolv_conf_options$NL"
198
	fi
199
	if [ -n "$resolv_conf_sortlist" ]; then
200
		newconf="${newconf}sortlist $resolv_conf_sortlist$NL"
201
	fi
202
143
	if [ -n "$resolv_conf_tail" ]; then
203
	if [ -n "$resolv_conf_tail" ]; then
144
		newconf="$newconf$resolv_conf_tail$NL"
204
		newconf="$newconf$resolv_conf_tail$NL"
145
	fi
205
	fi
Lines 151-156 Link Here
151
	[ "$(cat "$resolv_conf")" = "$(printf %s "$newconf")" ] && exit 0
211
	[ "$(cat "$resolv_conf")" = "$(printf %s "$newconf")" ] && exit 0
152
fi
212
fi
153
213
214
# Change is good.
215
# If the old file does not have our signature, back it up.
216
# If the new file just has our signature, restore the backup.
217
if $backup; then
218
	if [ "$newconf" = "$signature$NL" ]; then
219
		if [ -e "$resolv_conf.bak" ]; then
220
			newconf="$(cat "$resolv_conf.bak")"
221
		fi
222
	elif [ -e "$resolv_conf" ]; then
223
		read line <"$resolv_conf"
224
		if [ "$line" != "$signature" ]; then
225
			cp "$resolv_conf" "$resolv_conf.bak"
226
		fi
227
	fi
228
fi
229
154
# Create our resolv.conf now
230
# Create our resolv.conf now
155
(umask 022; echo "$newconf" >"$resolv_conf")
231
(umask 022; echo "$newconf" >"$resolv_conf")
156
eval $libc_restart
232
eval $libc_restart
(-)contrib/openresolv/named.in (-2 / +12 lines)
Lines 1-5 Link Here
1
#!/bin/sh
1
#!/bin/sh
2
# Copyright (c) 2007-2009 Roy Marples
2
# Copyright (c) 2007-2012 Roy Marples
3
# All rights reserved
3
# All rights reserved
4
4
5
# named subscriber for resolvconf
5
# named subscriber for resolvconf
Lines 29-35 Link Here
29
[ -f "@SYSCONFDIR@"/resolvconf.conf ] || exit 0
29
[ -f "@SYSCONFDIR@"/resolvconf.conf ] || exit 0
30
. "@SYSCONFDIR@/resolvconf.conf" || exit 1
30
. "@SYSCONFDIR@/resolvconf.conf" || exit 1
31
[ -z "$named_zones" -a -z "$named_options" ] && exit 0
31
[ -z "$named_zones" -a -z "$named_options" ] && exit 0
32
[ -z "$RESOLVCONF" ] && eval "$(@PREFIX@/sbin/resolvconf -v)"
32
[ -z "$RESOLVCONF" ] && eval "$(@SBINDIR@/resolvconf -v)"
33
NL="
33
NL="
34
"
34
"
35
35
Lines 40-45 Link Here
40
	if [ -x "@RCDIR@"/bind9 ]; then
40
	if [ -x "@RCDIR@"/bind9 ]; then
41
		# Debian and derivatives
41
		# Debian and derivatives
42
		named_service=bind9
42
		named_service=bind9
43
	elif [ -x "@RCDIR@"/rc.bind ]; then
44
		# Slackware
45
		named_service=rc.bind
43
	fi
46
	fi
44
fi
47
fi
45
: ${named_service:=named}
48
: ${named_service:=named}
Lines 71-76 Link Here
71
	newzones="$newzones	};$NL};$NL"
74
	newzones="$newzones	};$NL};$NL"
72
done
75
done
73
76
77
# Try to ensure that config dirs exist
78
if type config_mkdirs >/dev/null 2>&1; then
79
	config_mkdirs "$named_options" "$named_zones"
80
else
81
	@SBINDIR@/resolvconf -D "$named_options" "$named_zones"
82
fi
83
74
# No point in changing files or reloading bind if the end result has not
84
# No point in changing files or reloading bind if the end result has not
75
# changed
85
# changed
76
changed=false
86
changed=false
(-)contrib/openresolv/pdnsd.in (-17 / +27 lines)
Lines 1-5 Link Here
1
#!/bin/sh
1
#!/bin/sh
2
# Copyright (c) 2010 Roy Marples
2
# Copyright (c) 2010-2013 Roy Marples
3
# All rights reserved
3
# All rights reserved
4
4
5
# pdnsd subscriber for resolvconf
5
# pdnsd subscriber for resolvconf
Lines 29-35 Link Here
29
[ -f "@SYSCONFDIR@"/resolvconf.conf ] || exit 0
29
[ -f "@SYSCONFDIR@"/resolvconf.conf ] || exit 0
30
. "@SYSCONFDIR@/resolvconf.conf" || exit 1
30
. "@SYSCONFDIR@/resolvconf.conf" || exit 1
31
[ -z "$pdnsd_conf" -a -z "$pdnsd_resolv" ] && exit 0
31
[ -z "$pdnsd_conf" -a -z "$pdnsd_resolv" ] && exit 0
32
[ -z "$RESOLVCONF" ] && eval "$(@PREFIX@/sbin/resolvconf -v)"
32
[ -z "$RESOLVCONF" ] && eval "$(@SBINDIR@/resolvconf -v)"
33
NL="
34
"
33
35
34
: ${pdnsd_restart:=pdnsd-ctl config $pdnsd_conf}
36
: ${pdnsd_restart:=pdnsd-ctl config $pdnsd_conf}
35
signature="# Generated by resolvconf"
37
signature="# Generated by resolvconf"
Lines 46-52 Link Here
46
		sed "/^$m1/,/^$m2/d" $@
48
		sed "/^$m1/,/^$m2/d" $@
47
	else
49
	else
48
		for x; do
50
		for x; do
49
			while read line; do
51
			while read -r line; do
50
				case "$line" in
52
				case "$line" in
51
				"$m1"*) in_marker=1;;
53
				"$m1"*) in_marker=1;;
52
				"$m2"*) in_marker=0;;
54
				"$m2"*) in_marker=0;;
Lines 80-103 Link Here
80
	return 0
82
	return 0
81
}
83
}
82
84
83
newresolv="# Generated by resolvconf\n"
85
newresolv="# Generated by resolvconf$NL"
84
changed=false
86
changed=false
85
87
88
# Try to ensure that config dirs exist
89
if type config_mkdirs >/dev/null 2>&1; then
90
	config_mkdirs "$pdnsd_resolv" "$pdnsd_conf"
91
else
92
	@SBINDIR@/resolvconf -D "$pdnsd_resolv" "$pdnsd_conf"
93
fi
94
86
if [ -n "$pdnsd_resolv" ]; then
95
if [ -n "$pdnsd_resolv" ]; then
87
	for n in $NAMESERVERS; do
96
	for n in $NAMESERVERS; do
88
		newresolv="${newresolv}nameserver $n\n"
97
		newresolv="${newresolv}nameserver $n$NL"
89
	done
98
	done
90
fi
99
fi
91
100
92
if [ -n "$pdnsd_conf" ]; then
101
# Only modify the configuration if it exists and we can write to it
102
if [ -w "$pdnsd_conf" ]; then
93
	cf="$pdnsd_conf.new"
103
	cf="$pdnsd_conf.new"
94
	newconf=
104
	newconf=
95
105
96
	if [ -z "$pdnsd_resolv" ]; then
106
	if [ -z "$pdnsd_resolv" ]; then
97
		newconf="${newconf}server {\n"
107
		newconf="${newconf}server {$NL"
98
		newconf="${newconf}\tlabel=resolvconf;\n"
108
		newconf="${newconf}	label=resolvconf;$NL"
99
		if [ -n "$NAMESERVERS" ]; then
109
		if [ -n "$NAMESERVERS" ]; then
100
			newconf="${newconf}\tip="
110
			newconf="${newconf}	ip="
101
			first=true
111
			first=true
102
			for n in $NAMESERVERS; do
112
			for n in $NAMESERVERS; do
103
				if $first; then
113
				if $first; then
Lines 107-122 Link Here
107
				fi
117
				fi
108
				newconf="$newconf$n"
118
				newconf="$newconf$n"
109
			done
119
			done
110
			newconf="${newconf};\n"
120
			newconf="${newconf};$NL"
111
		fi
121
		fi
112
		newconf="${newconf}}\n"
122
		newconf="${newconf}}$NL"
113
	fi
123
	fi
114
124
115
	for d in $DOMAINS; do
125
	for d in $DOMAINS; do
116
		newconf="${newconf}server {\n"
126
		newconf="${newconf}server {$NL"
117
		newconf="${newconf}\tinclude=.${d%%:*}.;\n"
127
		newconf="${newconf}	include=.${d%%:*}.;$NL"
118
		newconf="${newconf}\tpolicy=excluded;\n"
128
		newconf="${newconf}	policy=excluded;$NL"
119
		newconf="${newconf}\tip="
129
		newconf="${newconf}	ip="
120
		ns="${d#*:}"
130
		ns="${d#*:}"
121
		while [ -n "$ns" ]; do
131
		while [ -n "$ns" ]; do
122
			newconf="${newconf}${ns%%,*}"
132
			newconf="${newconf}${ns%%,*}"
Lines 124-130 Link Here
124
			ns="${ns#*,}"
134
			ns="${ns#*,}"
125
			newconf="${newconf},"
135
			newconf="${newconf},"
126
		done
136
		done
127
		newconf="${newconf};\n}\n"
137
		newconf="${newconf};$NL}$NL"
128
	done
138
	done
129
139
130
	rm -f "$cf"
140
	rm -f "$cf"
Lines 136-142 Link Here
136
	fi
146
	fi
137
	if change_file "$pdnsd_conf" "$cf"; then
147
	if change_file "$pdnsd_conf" "$cf"; then
138
		changed=true
148
		changed=true
139
	fi	
149
	fi
140
fi
150
fi
141
151
142
if [ -n "$pdnsd_resolv" ]; then
152
if [ -n "$pdnsd_resolv" ]; then
(-)contrib/openresolv/resolvconf.8.in (-13 / +78 lines)
Lines 1-4 Link Here
1
.\" Copyright (c) 2007-2009 Roy Marples
1
.\" Copyright (c) 2007-2015 Roy Marples
2
.\" All rights reserved
2
.\" All rights reserved
3
.\"
3
.\"
4
.\" Redistribution and use in source and binary forms, with or without
4
.\" Redistribution and use in source and binary forms, with or without
Lines 22-29 Link Here
22
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
22
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23
.\" SUCH DAMAGE.
23
.\" SUCH DAMAGE.
24
.\"
24
.\"
25
.Dd December 3, 2009
25
.Dd April 27, 2014
26
.Dt RESOLVCONF 8 SMM
26
.Dt RESOLVCONF 8
27
.Os
27
.Os
28
.Sh NAME
28
.Sh NAME
29
.Nm resolvconf
29
.Nm resolvconf
Lines 34-44 Link Here
34
.Nm
34
.Nm
35
.Op Fl m Ar metric
35
.Op Fl m Ar metric
36
.Op Fl p
36
.Op Fl p
37
.Fl a Ar interface No < Ns Pa file
37
.Op Fl x
38
.Fl a Ar interface Ns Op Ar .protocol
39
.No < Ns Pa file
38
.Nm
40
.Nm
39
.Op Fl f
41
.Op Fl f
40
.Fl d Ar interface
42
.Fl d Ar interface Ns Op Ar .protocol
41
.Nm
43
.Nm
44
.Op Fl x
42
.Fl il Ar pattern
45
.Fl il Ar pattern
43
.Nm
46
.Nm
44
.Fl u
47
.Fl u
Lines 63-69 Link Here
63
via
66
via
64
.Xr stdin 3
67
.Xr stdin 3
65
with the argument
68
with the argument
66
.Fl a Ar interface
69
.Fl a Ar interface Ns Op Ar .protocol
67
instead of the filesystem.
70
instead of the filesystem.
68
.Nm
71
.Nm
69
then updates
72
then updates
Lines 78-83 Link Here
78
will supply files that the resolver should be configured to include.
81
will supply files that the resolver should be configured to include.
79
.Pp
82
.Pp
80
.Nm
83
.Nm
84
assumes it has a job to do.
85
In some situations
86
.Nm
87
needs to act as a deterrent to writing to
88
.Pa /etc/resolv.conf .
89
Where this file cannot be made immutable or you just need to toggle this
90
behaviour,
91
.Nm
92
can be disabled by adding
93
.Sy resolvconf Ns = Ns NO
94
to
95
.Xr resolvconf.conf 5 .
96
.Pp
97
.Nm
81
can mark an interfaces
98
can mark an interfaces
82
.Pa resolv.conf
99
.Pa resolv.conf
83
as private.
100
as private.
Lines 91-103 Link Here
91
.Nm
108
.Nm
92
to use a local name server.
109
to use a local name server.
93
.Pp
110
.Pp
111
.Nm
112
can mark an interfaces
113
.Pa resolv.conf
114
as exclusive.
115
Only the latest exclusive interface is used for processing, otherwise all are.
116
.Pp
94
When an interface goes down, it should then call
117
When an interface goes down, it should then call
95
.Nm
118
.Nm
96
with
119
with
97
.Fl d Ar interface
120
.Fl d Ar interface.*
98
arguments to delete the
121
arguments to delete the
99
.Pa resolv.conf
122
.Pa resolv.conf
100
file for the
123
file(s) for all the
124
.Ar protocols
125
on the
101
.Ar interface .
126
.Ar interface .
102
.Pp
127
.Pp
103
Here are some more options that
128
Here are some more options that
Lines 119-125 Link Here
119
Ignore non existant interfaces.
144
Ignore non existant interfaces.
120
Only really useful for deleting interfaces.
145
Only really useful for deleting interfaces.
121
.It Fl i Ar pattern
146
.It Fl i Ar pattern
122
List the interfaces, optionally matching
147
List the interfaces and protocols, optionally matching
123
.Ar pattern ,
148
.Ar pattern ,
124
we have
149
we have
125
.Pa resolv.conf
150
.Pa resolv.conf
Lines 130-136 Link Here
130
files we have.
155
files we have.
131
If
156
If
132
.Ar pattern
157
.Ar pattern
133
is specified then we list the files for the interfaces that match it.
158
is specified then we list the files for the interfaces and protocols
159
that match it.
134
.It Fl m Ar metric
160
.It Fl m Ar metric
135
Set the metric of the interface when adding it, default of 0.
161
Set the metric of the interface when adding it, default of 0.
136
Lower metrics take precedence.
162
Lower metrics take precedence.
Lines 142-159 Link Here
142
.It Fl u
168
.It Fl u
143
Force
169
Force
144
.Nm
170
.Nm
145
to update all it's subscribers.
171
to update all its subscribers.
146
.Nm
172
.Nm
147
does not update the subscribers when adding a resolv.conf that matches
173
does not update the subscribers when adding a resolv.conf that matches
148
what it already has for that interface.
174
what it already has for that interface.
175
.It Fl x
176
Mark the interface
177
.Pa resolv.conf
178
as exclusive when adding, otherwise only use the latest exclusive interface.
149
.El
179
.El
150
.Pp
180
.Pp
151
.Nm
181
.Nm
152
also has some options designed to be used by it's subscribers:-
182
also has some options designed to be used by its subscribers:-
153
.Bl -tag -width indent
183
.Bl -tag -width indent
154
.It Fl v
184
.It Fl v
155
Echo variables DOMAINS, SEARCH and NAMESERVERS so that the subscriber can
185
Echo variables DOMAINS, SEARCH and NAMESERVERS so that the subscriber can
156
configure the resolver easily.
186
configure the resolver easily.
187
.It Fl V
188
Same as
189
.Fl v
190
except that only the information configured in
191
.Xr resolvconf.conf 5
192
is set.
157
.El
193
.El
158
.Sh INTERFACE ORDERING
194
.Sh INTERFACE ORDERING
159
For
195
For
Lines 170-175 Link Here
170
See
206
See
171
.Xr resolvconf.conf 5
207
.Xr resolvconf.conf 5
172
for details on these lists.
208
for details on these lists.
209
.Sh PROTOCOLS
210
Here are some suggested protocol tags to use for each
211
.Pa resolv.conf
212
file registered on an
213
.Ar interface Ns No :-
214
.Bl -tag -width indent
215
.It dhcp
216
Dynamic Host Configuration Protocol.
217
Initial versions of
218
.Nm
219
did not recommend a
220
.Ar protocol
221
tag be appended to the
222
.Ar interface
223
name.
224
When the protocol is absent, it is assumed to be the DHCP protocol.
225
.It ppp
226
Point-to-Point Protocol.
227
.It ra
228
IPv6 Router Advertisement.
229
.It dhcp6
230
Dynamic Host Configuration Protocol, version 6.
231
.El
173
.Sh IMPLEMENTATION NOTES
232
.Sh IMPLEMENTATION NOTES
174
If a subscriber has the executable bit then it is executed otherwise it is
233
If a subscriber has the executable bit then it is executed otherwise it is
175
assumed to be a shell script and sourced into the current environment in a
234
assumed to be a shell script and sourced into the current environment in a
Lines 197-205 Link Here
197
Marks the interface
256
Marks the interface
198
.Pa resolv.conf
257
.Pa resolv.conf
199
as private.
258
as private.
259
.It Va IF_EXCLUSIVE
260
Marks the interface
261
.Pa resolv.conf
262
as exclusive.
200
.El
263
.El
201
.Sh FILES
264
.Sh FILES
202
.Bl -ohang
265
.Bl -ohang
266
.It Pa /etc/resolv.conf.bak
267
Backup file of the original resolv.conf.
203
.It Pa @SYSCONFDIR@/resolvconf.conf
268
.It Pa @SYSCONFDIR@/resolvconf.conf
204
Configuration file for
269
Configuration file for
205
.Nm .
270
.Nm .
Lines 218-224 Link Here
218
.Nm
283
.Nm
219
is called openresolv and is fully command line compatible with Debian's
284
is called openresolv and is fully command line compatible with Debian's
220
resolvconf, as written by Thomas Hood.
285
resolvconf, as written by Thomas Hood.
221
.Sh BUGS
286
.Sh NOTES
222
.Nm
287
.Nm
223
does not validate any of the files given to it.
288
does not validate any of the files given to it.
224
.Pp
289
.Pp
(-)contrib/openresolv/resolvconf.conf.5.in (-13 / +139 lines)
Lines 1-4 Link Here
1
.\" Copyright (c) 2009-2010 Roy Marples
1
.\" Copyright (c) 2009-2015 Roy Marples
2
.\" All rights reserved
2
.\" All rights reserved
3
.\"
3
.\"
4
.\" Redistribution and use in source and binary forms, with or without
4
.\" Redistribution and use in source and binary forms, with or without
Lines 22-29 Link Here
22
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
22
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23
.\" SUCH DAMAGE.
23
.\" SUCH DAMAGE.
24
.\"
24
.\"
25
.Dd October 29, 2010
25
.Dd March 20, 2015
26
.Dt RESOLVCONF.CONF 5 SMM
26
.Dt RESOLVCONF.CONF 5
27
.Os
27
.Os
28
.Sh NAME
28
.Sh NAME
29
.Nm resolvconf.conf
29
.Nm resolvconf.conf
Lines 42-53 Link Here
42
Listed below are the standard
42
Listed below are the standard
43
.Nm
43
.Nm
44
variables that may be set.
44
variables that may be set.
45
If the values contain white space for special shell characters,
46
ensure they are quoted and escaped correctly.
45
.Pp
47
.Pp
46
After updating this file, you may wish to run
48
After updating this file, you may wish to run
47
.Nm resolvconf -u
49
.Nm resolvconf -u
48
to apply the new configuration.
50
to apply the new configuration.
51
.Pp
52
When a dynamically generated list is appended or prepended to, the whole
53
is made unique where left-most wins.
49
.Sh RESOLVCONF OPTIONS
54
.Sh RESOLVCONF OPTIONS
50
.Bl -tag -width indent
55
.Bl -tag -width indent
56
.It Sy resolvconf
57
Set to NO to disable
58
.Nm resolvconf
59
from running any subscribers.
60
Defaults to YES.
51
.It Sy interface_order
61
.It Sy interface_order
52
These interfaces will always be processed first.
62
These interfaces will always be processed first.
53
If unset, defaults to the following:-
63
If unset, defaults to the following:-
Lines 56-65 Link Here
56
These interfaces will be processed next, unless they have a metric.
66
These interfaces will be processed next, unless they have a metric.
57
If unset, defaults to the following:-
67
If unset, defaults to the following:-
58
.D1 tap[0-9]* tun[0-9]* vpn vpn[0-9]* ppp[0-9]* ippp[0-9]*
68
.D1 tap[0-9]* tun[0-9]* vpn vpn[0-9]* ppp[0-9]* ippp[0-9]*
69
.It Sy local_nameservers
70
If unset, defaults to the following:-
71
.D1 127.* 0.0.0.0 255.255.255.255 ::1
59
.It Sy search_domains
72
.It Sy search_domains
60
Prepend search domains to the dynamically generated list.
73
Prepend search domains to the dynamically generated list.
61
.It Sy search_domains_append
74
.It Sy search_domains_append
62
Append search domains to the dynamically generated list.
75
Append search domains to the dynamically generated list.
76
.It Sy domain_blacklist
77
A list of domains to be removed from consideration.
78
To remove a domain, you can use foo.*
79
To remove a sub domain, you can use *.bar
63
.It Sy name_servers
80
.It Sy name_servers
64
Prepend name servers to the dynamically generated list.
81
Prepend name servers to the dynamically generated list.
65
You should set this to 127.0.0.1 if you use a local name server other than
82
You should set this to 127.0.0.1 if you use a local name server other than
Lines 66-71 Link Here
66
libc.
83
libc.
67
.It Sy name_servers_append
84
.It Sy name_servers_append
68
Append name servers to the dynamically generated list.
85
Append name servers to the dynamically generated list.
86
.It Sy name_server_blacklist
87
A list of name servers to be removed from consideration.
88
The default is 0.0.0.0 as some faulty routers send it via DHCP.
89
To remove a block, you can use 192.168.*
69
.It Sy private_interfaces
90
.It Sy private_interfaces
70
These interfaces name servers will only be queried for the domains listed
91
These interfaces name servers will only be queried for the domains listed
71
in their resolv.conf.
92
in their resolv.conf.
Lines 73-78 Link Here
73
This is equivalent to the
94
This is equivalent to the
74
.Nm resolvconf -p
95
.Nm resolvconf -p
75
option.
96
option.
97
.It Sy replace
98
Is a space separated list of replacement keywords. The syntax is this:
99
.Va $keyword Ns / Ns Va $match Ns / Ns Va $replacement
100
.Pp
101
Example, given this resolv.conf:
102
.D1 domain foo.org
103
.D1 search foo.org dead.beef
104
.D1 nameserver 1.2.3.4
105
.D1 nameserver 2.3.4.5
106
and this configuaration:
107
.D1 replace="search/foo*/bar.com nameserver/1.2.3.4/5.6.7.8 nameserver/2.3.4.5/"
108
you would get this resolv.conf instead:
109
.D1 domain foo.org
110
.D1 search bar.com
111
.D1 nameserver 5.6.7.8
112
.It Sy replace_sub
113
Works the same way as
114
.Sy replace
115
except it works on each space separated value rather than the whole line,
116
so it's useful for the replacing a single domain within the search directive.
117
Using the same example resolv.conf and changing
118
.Sy replace
119
to
120
.Sy replace_sub ,
121
you would get this resolv.conf instead:
122
.D1 domain foo.org
123
.D1 search bar.com dead.beef
124
.D1 nameserver 5.6.7.8
76
.It Sy state_dir
125
.It Sy state_dir
77
Override the default state directory of
126
Override the default state directory of
78
.Pa @VARDIR@ .
127
.Pa @VARDIR@ .
Lines 96-101 Link Here
96
When set to YES the latest resolv.conf is written to
145
When set to YES the latest resolv.conf is written to
97
.Sy resolv_conf
146
.Sy resolv_conf
98
without any alteration.
147
without any alteration.
148
When set to /dev/null or NULL,
149
.Sy resolv_conf_local_only
150
is defaulted to NO,
151
.Sy local_nameservers
152
is unset unless overriden and only the information set in
153
.Nm
154
is written to
155
.Sy resolv_conf .
156
.It Sy resolv_conf_sortlist
157
A libc resolver sortlist, as specified in
158
.Xr resolv.conf 5 .
159
.It Sy resolv_conf_local_only
160
If a local name server is configured then the default is just to specify that
161
and ignore all other entries as they will be configured for the local
162
name server.
163
Set this to NO to also list non-local nameservers.
164
This will give you working DNS even if the local nameserver stops functioning
165
at the expense of duplicated server queries.
166
.It Sy append_nameservers
167
Append name servers to the dynamically generated list.
168
.It Sy prepend_nameservers
169
Prepend name servers to the dynamically generated list.
170
.It Sy append_search
171
Append search domains to the dynamically generated list.
172
.It Sy prepend_search
173
Prepend search domains to the dynamically generated list.
99
.El
174
.El
100
.Sh SUBSCRIBER OPTIONS
175
.Sh SUBSCRIBER OPTIONS
101
openresolv ships with subscribers for the name servers
176
openresolv ships with subscribers for the name servers
Lines 106-116 Link Here
106
.Xr unbound 8 .
181
.Xr unbound 8 .
107
Each subscriber can create configuration files which should be included in
182
Each subscriber can create configuration files which should be included in
108
in the subscribers main configuration file.
183
in the subscribers main configuration file.
184
.Pp
185
To disable a subscriber, simply set it's name to NO.
186
For example, to disable the libc subscriber you would set:
187
.D1 libc=NO
109
.Bl -tag -width indent
188
.Bl -tag -width indent
110
.It Sy dnsmasq_conf
189
.It Sy dnsmasq_conf
111
This file tells dnsmasq which nameservers to use for specific domains.
190
This file tells dnsmasq which name servers to use for specific domains.
112
.It Sy dnsmasq_resolv
191
.It Sy dnsmasq_resolv
113
This file tells dnsmasq which nameservers to use for global lookups.
192
This file tells dnsmasq which name servers to use for global lookups.
114
.Pp
193
.Pp
115
Example resolvconf.conf for dnsmasq:
194
Example resolvconf.conf for dnsmasq:
116
.D1 name_servers=127.0.0.1
195
.D1 name_servers=127.0.0.1
Lines 119-132 Link Here
119
.Pp
198
.Pp
120
Example dnsmasq.conf:
199
Example dnsmasq.conf:
121
.D1 listen-address=127.0.0.1
200
.D1 listen-address=127.0.0.1
201
.D1 # If dnsmasq is compiled for DBus then we can take
202
.D1 # advantage of not having to restart dnsmasq.
203
.D1 enable-dbus
122
.D1 conf-file=/etc/dnsmasq-conf.conf
204
.D1 conf-file=/etc/dnsmasq-conf.conf
123
.D1 resolv-file=/etc/dnsmasq-resolv.conf
205
.D1 resolv-file=/etc/dnsmasq-resolv.conf
124
.It Sy named_options
206
.It Sy named_options
125
Include this file in the named options block.
207
Include this file in the named options block.
126
This file tells named which nameservers to use for global lookups.
208
This file tells named which name servers to use for global lookups.
127
.It Sy named_zones
209
.It Sy named_zones
128
Include this file in the named global scope, after the options block.
210
Include this file in the named global scope, after the options block.
129
This file tells named which nameservers to use for specific domains.
211
This file tells named which name servers to use for specific domains.
130
.Pp
212
.Pp
131
Example resolvconf.conf for named:
213
Example resolvconf.conf for named:
132
.D1 name_servers=127.0.0.1
214
.D1 name_servers=127.0.0.1
Lines 147-153 Link Here
147
.Pa pdnsd_resolv
229
.Pa pdnsd_resolv
148
as documented below.
230
as documented below.
149
.It Sy pdnsd_resolv
231
.It Sy pdnsd_resolv
150
This file tells pdnsd about global nameservers.
232
This file tells pdnsd about global name servers.
151
If this variable is not set then it's written to
233
If this variable is not set then it's written to
152
.Pa pdnsd_conf .
234
.Pa pdnsd_conf .
153
.Pp
235
.Pp
Lines 168-174 Link Here
168
.D1 	# file="/etc/pdnsd-resolv.conf";
250
.D1 	# file="/etc/pdnsd-resolv.conf";
169
.D1 }
251
.D1 }
170
.It Sy unbound_conf
252
.It Sy unbound_conf
171
This file tells unbound about specific and global nameservers.
253
This file tells unbound about specific and global name servers.
254
.It Sy unbound_insecure
255
When set to YES, unbound marks the domains as insecure, thus ignoring DNSSEC.
172
.Pp
256
.Pp
173
Example resolvconf.conf for unbound:
257
Example resolvconf.conf for unbound:
174
.D1 name_servers=127.0.0.1
258
.D1 name_servers=127.0.0.1
Lines 177-187 Link Here
177
Example unbound.conf:
261
Example unbound.conf:
178
.D1 include: /etc/unbound-resolvconf.conf
262
.D1 include: /etc/unbound-resolvconf.conf
179
.El
263
.El
264
.Sh SUBSCRIBER INTEGRATION
265
Not all distributions store the files the subscribers need in the same
266
locations.
267
For example, named service scripts have been called named, bind and rc.bind
268
and they could be located in a directory called /etc/rc.d, /etc/init.d or
269
similar.
270
Each subscriber attempts to automatically configure itself, but not every
271
distribution has been catered for.
272
Also, users could equally want to use a different version from the one
273
installed by default, such as bind8 and bind9.
274
To accomodate this, the subscribers have these files in configurable
275
variables, documented below.
276
.Pp
277
.Bl -tag -width indent
278
.It Sy dnsmasq_service
279
Location of the dnsmasq service.
280
.It Sy dnsmasq_restart
281
Command to restart the dnsmasq service.
282
.It Sy dnsmasq_pid
283
Location of the dnsmasq pidfile.
284
.It Sy libc_service
285
Location of the libc service.
286
.It Sy libc_restart
287
Command to restart the libc service.
288
.It Sy named_service
289
Location of the named service.
290
.It Sy named_restart
291
Command to restart the named service.
292
.It Sy pdnsd_restart
293
Command to restart the pdnsd service.
294
.It Sy unbound_service
295
Location of the unbound service.
296
.It Sy unbound_restart
297
Command to restart the unbound service.
298
.It Sy unbound_pid
299
Location of the unbound pidfile.
300
.El
180
.Sh SEE ALSO
301
.Sh SEE ALSO
181
.Xr resolv.conf 5
302
.Xr resolv.conf 5 ,
303
.Xr resolvconf 8
182
and
304
and
183
.Xr resolvconf 8 .
305
.Xr sh 1 .
184
.Sh AUTHORS
306
.Sh AUTHORS
185
.An Roy Marples Aq roy@marples.name
307
.An Roy Marples Aq Mt roy@marples.name
186
.Sh BUGS
308
.Sh BUGS
187
Please report them to http://roy.marples.name/projects/openresolv
309
Each distribution is a special snowflake and likes to name the same thing
310
differently, namely the named service script.
311
.Pp
312
Please report them to
313
.Lk http://roy.marples.name/projects/openresolv
(-)contrib/openresolv/resolvconf.in (-87 / +437 lines)
Lines 1-5 Link Here
1
#!/bin/sh
1
#!/bin/sh
2
# Copyright (c) 2007-2009 Roy Marples
2
# Copyright (c) 2007-2015 Roy Marples
3
# All rights reserved
3
# All rights reserved
4
4
5
# Redistribution and use in source and binary forms, with or without
5
# Redistribution and use in source and binary forms, with or without
Lines 28-33 Link Here
28
SYSCONFDIR=@SYSCONFDIR@
28
SYSCONFDIR=@SYSCONFDIR@
29
LIBEXECDIR=@LIBEXECDIR@
29
LIBEXECDIR=@LIBEXECDIR@
30
VARDIR=@VARDIR@
30
VARDIR=@VARDIR@
31
32
# Disregard dhcpcd setting
33
unset interface_order state_dir
34
35
# If you change this, change the test in VFLAG and libc.in as well
36
local_nameservers="127.* 0.0.0.0 255.255.255.255 ::1"
37
38
dynamic_order="tap[0-9]* tun[0-9]* vpn vpn[0-9]* ppp[0-9]* ippp[0-9]*"
39
interface_order="lo lo[0-9]*"
40
name_server_blacklist="0.0.0.0"
41
31
# Support original resolvconf configuration layout
42
# Support original resolvconf configuration layout
32
# as well as the openresolv config file
43
# as well as the openresolv config file
33
if [ -f "$SYSCONFDIR"/resolvconf.conf ]; then
44
if [ -f "$SYSCONFDIR"/resolvconf.conf ]; then
Lines 39-54 Link Here
39
		interface_order="$(cat "$SYSCONFDIR"/interface-order)"
50
		interface_order="$(cat "$SYSCONFDIR"/interface-order)"
40
	fi
51
	fi
41
fi
52
fi
53
TMPDIR="$VARDIR/tmp"
42
IFACEDIR="$VARDIR/interfaces"
54
IFACEDIR="$VARDIR/interfaces"
43
METRICDIR="$VARDIR/metrics"
55
METRICDIR="$VARDIR/metrics"
44
PRIVATEDIR="$VARDIR/private"
56
PRIVATEDIR="$VARDIR/private"
57
EXCLUSIVEDIR="$VARDIR/exclusive"
58
LOCKDIR="$VARDIR/lock"
45
59
46
: ${dynamic_order:=tap[0-9]* tun[0-9]* vpn vpn[0-9]* ppp[0-9]* ippp[0-9]*}
60
warn()
47
: ${interface_order:=lo lo[0-9]*}
61
{
62
	echo "$@" >&2
63
}
48
64
49
error_exit()
65
error_exit()
50
{
66
{
51
	echo "$*" >&2
67
	echo "$@" >&2
52
	exit 1
68
	exit 1
53
}
69
}
54
70
Lines 64-69 Link Here
64
	                   (DNS supplied via stdin in resolv.conf format)
80
	                   (DNS supplied via stdin in resolv.conf format)
65
	  -m metric        Give the added DNS information a metric
81
	  -m metric        Give the added DNS information a metric
66
	  -p               Mark the interface as private
82
	  -p               Mark the interface as private
83
	  -x               Mark the interface as exclusive
67
	  -d \$INTERFACE    Delete DNS information from the specified interface
84
	  -d \$INTERFACE    Delete DNS information from the specified interface
68
	  -f               Ignore non existant interfaces
85
	  -f               Ignore non existant interfaces
69
	  -I               Init the state dir
86
	  -I               Init the state dir
Lines 79-99 Link Here
79
	EOF
96
	EOF
80
	[ -z "$1" ] && exit 0
97
	[ -z "$1" ] && exit 0
81
	echo
98
	echo
82
	error_exit "$*"
99
	error_exit "$@"
83
}
100
}
84
101
85
echo_resolv()
102
echo_resolv()
86
{
103
{
87
	local line=
104
	local line= OIFS="$IFS"
88
	[ -n "$1" -a -e "$IFACEDIR/$1" ] || return 1
105
106
	[ -n "$1" -a -f "$IFACEDIR/$1" ] || return 1
89
	echo "# resolv.conf from $1"
107
	echo "# resolv.conf from $1"
90
	# Our variable maker works of the fact each resolv.conf per interface
108
	# Our variable maker works of the fact each resolv.conf per interface
91
	# is separated by blank lines.
109
	# is separated by blank lines.
92
	# So we remove them when echoing them.
110
	# So we remove them when echoing them.
93
	while read line; do
111
	while read -r line; do
94
		[ -n "$line" ] && echo "$line"
112
		IFS="$OIFS"
113
		if [ -n "$line" ]; then
114
			# We need to set IFS here to preserve any whitespace
115
			IFS=''
116
			printf "%s\n" "$line"
117
		fi
95
	done < "$IFACEDIR/$1"
118
	done < "$IFACEDIR/$1"
96
	echo
119
	echo
120
	IFS="$OIFS"
97
}
121
}
98
122
99
# Parse resolv.conf's and make variables
123
# Parse resolv.conf's and make variables
Lines 101-122 Link Here
101
parse_resolv()
125
parse_resolv()
102
{
126
{
103
	local line= ns= ds= search= d= n= newns=
127
	local line= ns= ds= search= d= n= newns=
104
	local new=true iface= private=false p=
128
	local new=true iface= private=false p= domain= l= islocal=
105
129
106
	echo "DOMAINS="
107
	echo "SEARCH=\"$search_domains\""
108
	# let our subscribers know about global nameservers
109
	for n in $name_servers; do
110
		case "$n" in
111
		127.*|0.0.0.0|255.255.255.255|::1) :;;
112
		*) newns="$newns${newns:+ }$n";;
113
		esac
114
	done
115
	echo "NAMESERVERS=\"$newns\""
116
	echo "LOCALNAMESERVERS="
117
	newns=
130
	newns=
118
131
119
	while read line; do
132
	while read -r line; do
120
		case "$line" in
133
		case "$line" in
121
		"# resolv.conf from "*)
134
		"# resolv.conf from "*)
122
			if ${new}; then
135
			if ${new}; then
Lines 129-154 Link Here
129
					cd "$IFACEDIR"
142
					cd "$IFACEDIR"
130
					private=false
143
					private=false
131
					for p in $private_interfaces; do
144
					for p in $private_interfaces; do
132
						if [ "$p" = "$iface" ]; then
145
						case "$iface" in
133
							private=true
146
						"$p"|"$p":*) private=true; break;;
134
							break
147
						esac
135
						fi
136
					done
148
					done
137
				fi
149
				fi
138
			fi
150
			fi
139
			;;
151
			;;
140
		"nameserver "*)
152
		"nameserver "*)
141
			case "${line#* }" in
153
			islocal=false
142
			127.*|0.0.0.0|255.255.255.255|::1)
154
			for l in $local_nameservers; do
143
				echo "LOCALNAMESERVERS=\"\$LOCALNAMESERVERS ${line#* }\""
155
				case "${line#* }" in
144
				continue
156
				$l)
145
				;;
157
					islocal=true
146
			esac
158
					echo "LOCALNAMESERVERS=\"\$LOCALNAMESERVERS ${line#* }\""
147
			ns="$ns${line#* } "
159
					break
160
					;;
161
				esac
162
			done
163
			$islocal || ns="$ns${line#* } "
148
			;;
164
			;;
149
		"domain "*|"search "*)
165
		"domain "*)
166
			if [ -z "$domain" ]; then
167
				domain="${line#* }"
168
				echo "DOMAIN=\"$domain\""
169
			fi
150
			search="${line#* }"
170
			search="${line#* }"
151
			;;
171
			;;
172
		"search "*)
173
			search="${line#* }"
174
			;;
152
		*)
175
		*)
153
			[ -n "$line" ] && continue
176
			[ -n "$line" ] && continue
154
			if [ -n "$ns" -a -n "$search" ]; then
177
			if [ -n "$ns" -a -n "$search" ]; then
Lines 187-218 Link Here
187
	echo "${result# *}"
210
	echo "${result# *}"
188
}
211
}
189
212
213
dirname()
214
{
215
	local dir= OIFS="$IFS"
216
	local IFS=/
217
	set -- $@
218
	IFS="$OIFS"
219
	if [ -n "$1" ]; then
220
		printf %s .
221
	else
222
		shift
223
	fi
224
	while [ -n "$2" ]; do
225
		printf "/%s" "$1"
226
		shift
227
	done
228
	printf "\n"
229
}
230
231
config_mkdirs()
232
{
233
	local e=0 f d
234
	for f; do
235
		[ -n "$f" ] || continue
236
		d="$(dirname "$f")"
237
		if [ ! -d "$d" ]; then
238
			if type install >/dev/null 2>&1; then
239
				install -d "$d" || e=$?
240
			else
241
				mkdir "$d" || e=$?
242
			fi
243
		fi
244
	done
245
	return $e
246
}
247
190
list_resolv()
248
list_resolv()
191
{
249
{
192
	[ -d "$IFACEDIR" ] || return 0
250
	[ -d "$IFACEDIR" ] || return 0
193
251
194
	local report=false list= retval=0 cmd="$1"
252
	local report=false list= retval=0 cmd="$1" excl=
195
	shift
253
	shift
196
254
255
	case "$IF_EXCLUSIVE" in
256
	[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
257
		if [ -d "$EXCLUSIVEDIR" ]; then
258
			cd "$EXCLUSIVEDIR"
259
			for i in *; do
260
				if [ -f "$i" ]; then
261
					list="${i#* }"
262
					break
263
				fi
264
			done
265
		fi
266
		excl=true
267
		;;
268
	*)
269
		excl=false
270
		;;
271
	esac
272
197
	# If we have an interface ordering list, then use that.
273
	# If we have an interface ordering list, then use that.
198
	# It works by just using pathname expansion in the interface directory.
274
	# It works by just using pathname expansion in the interface directory.
199
	if [ -n "$1" ]; then
275
	if [ -n "$1" ]; then
200
		list="$@"
276
		list="$@"
201
		$force || report=true
277
		$force || report=true
202
	else
278
	elif ! $excl; then
203
		cd "$IFACEDIR"
279
		cd "$IFACEDIR"
204
		for i in $interface_order; do
280
		for i in $interface_order; do
205
			[ -e "$i" ] && list="$list $i"
281
			[ -f "$i" ] && list="$list $i"
282
			for ii in "$i":* "$i".*; do
283
				[ -f "$ii" ] && list="$list $ii"
284
			done
206
		done
285
		done
207
		for i in $dynamic_order; do
286
		for i in $dynamic_order; do
208
			if [ -e "$i" -a ! -e "$METRICDIR/"*" $i" ]; then
287
			if [ -e "$i" -a ! -e "$METRICDIR/"*" $i" ]; then
209
				list="$list $i"
288
				list="$list $i"
210
			fi
289
			fi
290
			for ii in "$i":* "$i".*; do
291
				if [ -f "$ii" -a ! -e "$METRICDIR/"*" $ii" ]; then
292
					list="$list $ii"
293
				fi
294
			done
211
		done
295
		done
212
		if [ -d "$METRICDIR" ]; then
296
		if [ -d "$METRICDIR" ]; then
213
			cd "$METRICDIR"
297
			cd "$METRICDIR"
214
			for i in *; do
298
			for i in *; do
215
				list="$list ${i#* }"
299
				[ -f "$i" ] && list="$list ${i#* }"
216
			done
300
			done
217
		fi
301
		fi
218
		list="$list *"
302
		list="$list *"
Lines 219-256 Link Here
219
	fi
303
	fi
220
304
221
	cd "$IFACEDIR"
305
	cd "$IFACEDIR"
306
	retval=1
222
	for i in $(uniqify $list); do
307
	for i in $(uniqify $list); do
223
		# Only list interfaces which we really have
308
		# Only list interfaces which we really have
224
		if ! [ -e "$i" ]; then
309
		if ! [ -f "$i" ]; then
225
			if $report; then
310
			if $report; then
226
				echo "No resolv.conf for interface $i" >&2
311
				echo "No resolv.conf for interface $i" >&2
227
				retval=$(($retval + 1))
312
				retval=2
228
			fi
313
			fi
229
			continue
314
			continue
230
		fi
315
		fi
231
		
316
		
232
		if [ "$cmd" = i -o "$cmd" = "-i" ]; then
317
		if [ "$cmd" = i -o "$cmd" = "-i" ]; then
233
			printf "$i "
318
			printf %s "$i "
234
		else
319
		else
235
			echo_resolv "$i"
320
			echo_resolv "$i"
236
		fi
321
		fi
322
		[ $? = 0 -a "$retval" = 1 ] && retval=0
237
	done
323
	done
238
	[ "$cmd" = i -o "$cmd" = "-i" ] && echo
324
	[ "$cmd" = i -o "$cmd" = "-i" ] && echo
239
	return $retval
325
	return $retval
240
}
326
}
241
327
328
list_remove() {
329
	local list= e= l= result= found= retval=0
330
331
	[ -z "$2" ] && return 0
332
	eval list=\"\$$1\"
333
	shift
334
335
	set -f
336
	for e; do
337
		found=false
338
		for l in $list; do
339
			case "$e" in
340
			$l) found=true;;
341
			esac
342
			$found && break
343
		done
344
		if $found; then
345
			retval=$(($retval + 1))
346
		else
347
			result="$result $e"
348
		fi
349
	done
350
	set +f
351
	echo "${result# *}"
352
	return $retval
353
}
354
355
echo_prepend()
356
{
357
	echo "# Generated by resolvconf"
358
	if [ -n "$search_domains" ]; then
359
		echo "search $search_domains"
360
	fi
361
	for n in $name_servers; do
362
		echo "nameserver $n"
363
	done
364
	echo
365
}
366
367
echo_append()
368
{
369
	echo "# Generated by resolvconf"
370
	if [ -n "$search_domains_append" ]; then
371
		echo "search $search_domains_append"
372
	fi
373
	for n in $name_servers_append; do
374
		echo "nameserver $n"
375
	done
376
	echo
377
}
378
379
replace()
380
{
381
	local r= k= f= v= val= sub=
382
383
	while read -r keyword value; do
384
		for r in $replace; do
385
			k="${r%%/*}"
386
			r="${r#*/}"
387
			f="${r%%/*}"
388
			r="${r#*/}"
389
			v="${r%%/*}"
390
			case "$keyword" in
391
			$k)
392
				case "$value" in
393
				$f) value="$v";;
394
				esac
395
				;;
396
			esac
397
		done
398
		val=
399
		for sub in $value; do
400
			for r in $replace_sub; do
401
				k="${r%%/*}"
402
				r="${r#*/}"
403
				f="${r%%/*}"
404
				r="${r#*/}"
405
				v="${r%%/*}"
406
				case "$keyword" in
407
				$k)
408
					case "$sub" in
409
					$f) sub="$v";;
410
					esac
411
					;;
412
				esac
413
			done
414
			val="$val${val:+ }$sub"
415
		done
416
		printf "%s %s\n" "$keyword" "$val"
417
	done
418
}
419
242
make_vars()
420
make_vars()
243
{
421
{
244
	eval "$(list_resolv -l "$@" | parse_resolv)"
422
	local newdomains= d= dn= newns= ns=
245
423
424
	# Clear variables
425
	DOMAIN=
426
	DOMAINS=
427
	SEARCH=
428
	NAMESERVERS=
429
	LOCALNAMESERVERS=
430
	
431
	if [ -n "$name_servers" -o -n "$search_domains" ]; then
432
		eval "$(echo_prepend | parse_resolv)"
433
	fi
434
	if [ -z "$VFLAG" ]; then
435
		IF_EXCLUSIVE=1
436
		list_resolv -i "$@" >/dev/null || IF_EXCLUSIVE=0
437
		eval "$(list_resolv -l "$@" | replace | parse_resolv)"
438
	fi
439
	if [ -n "$name_servers_append" -o -n "$search_domains_append" ]; then
440
		eval "$(echo_append | parse_resolv)"
441
	fi
442
246
	# Ensure that we only list each domain once
443
	# Ensure that we only list each domain once
247
	newdomains=
248
	for d in $DOMAINS; do
444
	for d in $DOMAINS; do
249
		dn="${d%%:*}"
445
		dn="${d%%:*}"
446
		list_remove domain_blacklist "$dn" >/dev/null || continue
250
		case " $newdomains" in
447
		case " $newdomains" in
251
		*" ${dn}:"*) continue;;
448
		*" ${dn}:"*) continue;;
252
		esac
449
		esac
253
		newdomains="$newdomains${newdomains:+ }$dn:"
254
		newns=
450
		newns=
255
		for nd in $DOMAINS; do
451
		for nd in $DOMAINS; do
256
			if [ "$dn" = "${nd%%:*}" ]; then
452
			if [ "$dn" = "${nd%%:*}" ]; then
Lines 258-264 Link Here
258
				while [ -n "$ns" ]; do
454
				while [ -n "$ns" ]; do
259
					case ",$newns," in
455
					case ",$newns," in
260
					*,${ns%%,*},*) ;;
456
					*,${ns%%,*},*) ;;
261
					*) newns="$newns${newns:+,}${ns%%,*}";;
457
					*) list_remove name_server_blacklist \
458
						"${ns%%,*}" >/dev/null \
459
					&& newns="$newns${newns:+,}${ns%%,*}";;
262
					esac
460
					esac
263
					[ "$ns" = "${ns#*,}" ] && break
461
					[ "$ns" = "${ns#*,}" ] && break
264
					ns="${ns#*,}"
462
					ns="${ns#*,}"
Lines 265-285 Link Here
265
				done
463
				done
266
			fi
464
			fi
267
		done
465
		done
268
		newdomains="$newdomains$newns"
466
		if [ -n "$newns" ]; then
467
			newdomains="$newdomains${newdomains:+ }$dn:$newns"
468
		fi
269
	done
469
	done
470
	DOMAIN="$(list_remove domain_blacklist $DOMAIN)"
471
	SEARCH="$(uniqify $SEARCH)"
472
	SEARCH="$(list_remove domain_blacklist $SEARCH)"
473
	NAMESERVERS="$(uniqify $NAMESERVERS)"
474
	NAMESERVERS="$(list_remove name_server_blacklist $NAMESERVERS)"
475
	LOCALNAMESERVERS="$(uniqify $LOCALNAMESERVERS)"
476
	LOCALNAMESERVERS="$(list_remove name_server_blacklist $LOCALNAMESERVERS)"
477
	echo "DOMAIN='$DOMAIN'"
478
	echo "SEARCH='$SEARCH'"
479
	echo "NAMESERVERS='$NAMESERVERS'"
480
	echo "LOCALNAMESERVERS='$LOCALNAMESERVERS'"
270
	echo "DOMAINS='$newdomains'"
481
	echo "DOMAINS='$newdomains'"
271
	echo "SEARCH='$(uniqify $SEARCH)'"
272
	echo "NAMESERVERS='$(uniqify $NAMESERVERS)'"
273
	echo "LOCALNAMESERVERS='$(uniqify $LOCALNAMESERVERS)'"
274
}
482
}
275
483
276
force=false
484
force=false
277
while getopts a:d:fhIilm:puv OPT; do
485
VFLAG=
486
while getopts a:Dd:fhIilm:puvVx OPT; do
278
	case "$OPT" in
487
	case "$OPT" in
279
	f) force=true;;
488
	f) force=true;;
280
	h) usage;;
489
	h) usage;;
281
	m) IF_METRIC="$OPTARG";;
490
	m) IF_METRIC="$OPTARG";;
282
	p) IF_PRIVATE=1;;
491
	p) IF_PRIVATE=1;;
492
	V)
493
		VFLAG=1
494
		if [ "$local_nameservers" = \
495
		    "127.* 0.0.0.0 255.255.255.255 ::1" ]
496
		then
497
			local_nameservers=
498
		fi
499
		;;
500
	x) IF_EXCLUSIVE=1;;
283
	'?') ;;
501
	'?') ;;
284
	*) cmd="$OPT"; iface="$OPTARG";;
502
	*) cmd="$OPT"; iface="$OPTARG";;
285
	esac
503
	esac
Lines 295-300 Link Here
295
	exit $?
513
	exit $?
296
fi
514
fi
297
515
516
# -D ensures that the listed config file base dirs exist
517
if [ "$cmd" = D ]; then
518
	config_mkdirs "$@"
519
	exit $?
520
fi
521
298
# -l lists our resolv files, optionally for a specific interface
522
# -l lists our resolv files, optionally for a specific interface
299
if [ "$cmd" = l -o "$cmd" = i ]; then
523
if [ "$cmd" = l -o "$cmd" = i ]; then
300
	list_resolv "$cmd" "$args"
524
	list_resolv "$cmd" "$args"
Lines 302-308 Link Here
302
fi
526
fi
303
527
304
# Not normally needed, but subscribers should be able to run independently
528
# Not normally needed, but subscribers should be able to run independently
305
if [ "$cmd" = v ]; then
529
if [ "$cmd" = v -o -n "$VFLAG" ]; then
306
	make_vars "$iface"
530
	make_vars "$iface"
307
	exit $?
531
	exit $?
308
fi
532
fi
Lines 316-321 Link Here
316
	[ -n "$cmd" -a "$cmd" != h ] && usage "Unknown option $cmd"
540
	[ -n "$cmd" -a "$cmd" != h ] && usage "Unknown option $cmd"
317
	usage
541
	usage
318
fi
542
fi
543
319
if [ "$cmd" = a ]; then
544
if [ "$cmd" = a ]; then
320
	for x in '/' \\ ' ' '*'; do
545
	for x in '/' \\ ' ' '*'; do
321
		case "$iface" in
546
		case "$iface" in
Lines 331-393 Link Here
331
	[ "$cmd" = a -a -t 0 ] && error_exit "No file given via stdin"
556
	[ "$cmd" = a -a -t 0 ] && error_exit "No file given via stdin"
332
fi
557
fi
333
558
334
if [ ! -d "$IFACEDIR" ]; then
559
if [ ! -d "$VARDIR" ]; then
335
	if [ ! -d "$VARDIR" ]; then
560
	if [ -L "$VARDIR" ]; then
336
		if [ -L "$VARDIR" ]; then
561
		dir="$(readlink "$VARDIR")"
337
			dir="$(readlink "$VARDIR")"
562
		# link maybe relative
338
			# link maybe relative
563
		cd "${VARDIR%/*}"
339
			cd "${VARDIR%/*}"
564
		if ! mkdir -m 0755 -p "$dir"; then
340
			if ! mkdir -m 0755 -p "$dir"; then
565
			error_exit "Failed to create needed" \
341
				error_exit "Failed to create needed" \
566
				"directory $dir"
342
					"directory $dir"
343
			fi
344
		else
345
			if ! mkdir -m 0755 -p "$VARDIR"; then
346
				error_exit "Failed to create needed" \
347
					"directory $VARDIR"
348
			fi
349
		fi
567
		fi
568
	else
569
		if ! mkdir -m 0755 -p "$VARDIR"; then
570
			error_exit "Failed to create needed" \
571
				"directory $VARDIR"
572
		fi
350
	fi
573
	fi
574
fi
575
576
if [ ! -d "$IFACEDIR" ]; then
351
	mkdir -m 0755 -p "$IFACEDIR" || \
577
	mkdir -m 0755 -p "$IFACEDIR" || \
352
		error_exit "Failed to create needed directory $IFACEDIR"
578
		error_exit "Failed to create needed directory $IFACEDIR"
353
else
354
	# Delete any existing information about the interface
355
	if [ "$cmd" = d ]; then
579
	if [ "$cmd" = d ]; then
356
		cd "$IFACEDIR"
580
		# Provide the same error messages as below
357
		for i in $args; do
581
		if ! ${force}; then
358
			if [ "$cmd" = d -a ! -e "$i" ]; then
582
			cd "$IFACEDIR"
359
				$force && continue
583
			for i in $args; do
360
				error_exit "No resolv.conf for" \
584
				warn "No resolv.conf for interface $i"
361
					"interface $i"
585
			done
362
			fi
586
		fi
363
			rm -f "$i" "$METRICDIR/"*" $i" \
587
		${force}
364
				"$PRIVATEDIR/$i" || exit $?
588
		exit $?
365
		done
366
	fi
589
	fi
367
fi
590
fi
368
591
369
if [ "$cmd" = a ]; then
592
# An interface was added, changed, deleted or a general update was called.
593
# Due to exclusivity we need to ensure that this is an atomic operation.
594
# Our subscribers *may* need this as well if the init system is sub par.
595
# As such we spinlock at this point as best we can.
596
# We don't use flock(1) because it's not widely available and normally resides
597
# in /usr which we do our very best to operate without.
598
[ -w "$VARDIR" ] || error_exit "Cannot write to $LOCKDIR"
599
: ${lock_timeout:=10}
600
while true; do
601
	if mkdir "$LOCKDIR" 2>/dev/null; then
602
		trap 'rm -rf "$LOCKDIR";' EXIT
603
		trap 'rm -rf "$LOCKDIR"; exit 1' INT QUIT ABRT SEGV ALRM TERM
604
		echo $$ >"$LOCKDIR/pid"
605
		break
606
	fi
607
	pid=$(cat "$LOCKDIR/pid")
608
	if ! kill -0 "$pid"; then
609
		warn "clearing stale lock pid $pid"
610
		rm -rf "$LOCKDIR"
611
		continue
612
	fi
613
	lock_timeout=$(($lock_timeout - 1))
614
	if [ "$lock_timeout" -le 0 ]; then
615
		error_exit "timed out waiting for lock from pid $pid"
616
	fi
617
	sleep 1
618
done
619
620
case "$cmd" in
621
a)
370
	# Read resolv.conf from stdin
622
	# Read resolv.conf from stdin
371
	resolv="$(cat)"
623
	resolv="$(cat)"
624
	changed=false
625
	changedfile=false
372
	# If what we are given matches what we have, then do nothing
626
	# If what we are given matches what we have, then do nothing
373
	if [ -e "$IFACEDIR/$iface" ]; then
627
	if [ -e "$IFACEDIR/$iface" ]; then
374
		if [ "$(echo "$resolv")" = \
628
		if [ "$(echo "$resolv")" != \
375
			"$(cat "$IFACEDIR/$iface")" ]
629
			"$(cat "$IFACEDIR/$iface")" ]
376
		then
630
		then
377
			exit 0
631
			changed=true
632
			changedfile=true
378
		fi
633
		fi
379
		rm "$IFACEDIR/$iface"
634
	else
635
		changed=true
636
		changedfile=true
380
	fi
637
	fi
381
	echo "$resolv" >"$IFACEDIR/$iface" || exit $?
638
639
	# Set metric and private before creating the interface resolv.conf file
640
	# to ensure that it will have the correct flags
382
	[ ! -d "$METRICDIR" ] && mkdir "$METRICDIR"
641
	[ ! -d "$METRICDIR" ] && mkdir "$METRICDIR"
383
	rm -f "$METRICDIR/"*" $iface"
642
	oldmetric="$METRICDIR/"*" $iface"
643
	newmetric=
384
	if [ -n "$IF_METRIC" ]; then
644
	if [ -n "$IF_METRIC" ]; then
385
		# Pad metric to 6 characters, so 5 is less than 10
645
		# Pad metric to 6 characters, so 5 is less than 10
386
		while [ ${#IF_METRIC} -le 6 ]; do
646
		while [ ${#IF_METRIC} -le 6 ]; do
387
			IF_METRIC="0$IF_METRIC"
647
			IF_METRIC="0$IF_METRIC"
388
		done
648
		done
389
		echo " " >"$METRICDIR/$IF_METRIC $iface"
649
		newmetric="$METRICDIR/$IF_METRIC $iface"
390
	fi
650
	fi
651
	rm -f "$METRICDIR/"*" $iface"
652
	[ "$oldmetric" != "$newmetric" -a \
653
	    "$oldmetric" != "$METRICDIR/* $iface" ] &&
654
		changed=true
655
	[ -n "$newmetric" ] && echo " " >"$newmetric"
656
391
	case "$IF_PRIVATE" in
657
	case "$IF_PRIVATE" in
392
	[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
658
	[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
393
		if [ ! -d "$PRIVATEDIR" ]; then
659
		if [ ! -d "$PRIVATEDIR" ]; then
Lines 394-409 Link Here
394
			[ -e "$PRIVATEDIR" ] && rm "$PRIVATEDIR"
660
			[ -e "$PRIVATEDIR" ] && rm "$PRIVATEDIR"
395
			mkdir "$PRIVATEDIR"
661
			mkdir "$PRIVATEDIR"
396
		fi
662
		fi
663
		[ -e "$PRIVATEDIR/$iface" ] || changed=true
397
		[ -d "$PRIVATEDIR" ] && echo " " >"$PRIVATEDIR/$iface"
664
		[ -d "$PRIVATEDIR" ] && echo " " >"$PRIVATEDIR/$iface"
398
		;;
665
		;;
399
	*)
666
	*)
400
		if [ -e "$PRIVATEDIR/$iface" ]; then
667
		if [ -e "$PRIVATEDIR/$iface" ]; then
401
			rm -f "$PRIVATEDIR/$iface"
668
			rm -f "$PRIVATEDIR/$iface"
669
			changed=true
402
		fi
670
		fi
403
		;;
671
		;;
404
	esac
672
	esac
405
fi
406
673
674
	oldexcl=
675
	for x in "$EXCLUSIVEDIR/"*" $iface"; do
676
		if [ -f "$x" ]; then
677
			oldexcl="$x"
678
			break
679
		fi
680
	done
681
	case "$IF_EXCLUSIVE" in
682
	[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
683
		if [ ! -d "$EXCLUSIVEDIR" ]; then
684
			[ -e "$EXCLUSIVEDIR" ] && rm "$EXCLUSIVEDIR"
685
			mkdir "$EXCLUSIVEDIR"
686
		fi
687
		cd "$EXCLUSIVEDIR"
688
		for x in *; do
689
			[ -f "$x" ] && break
690
		done
691
		if [ "${x#* }" != "$iface" ]; then
692
			if [ "$x" = "${x% *}" ]; then
693
				x=10000000
694
			else
695
				x="${x% *}"
696
			fi
697
			if [ "$x" = "0000000" ]; then
698
				warn "exclusive underflow"
699
			else
700
				x=$(($x - 1))
701
			fi
702
			if [ -d "$EXCLUSIVEDIR" ]; then
703
				echo " " >"$EXCLUSIVEDIR/$x $iface"
704
			fi
705
			changed=true
706
		fi
707
		;;
708
	*)
709
		if [ -f "$oldexcl" ]; then
710
			rm -f "$oldexcl"
711
			changed=true
712
		fi
713
		;;
714
	esac
715
716
	if $changedfile; then
717
		printf "%s\n" "$resolv" >"$IFACEDIR/$iface" || exit $?
718
	elif ! $changed; then
719
		exit 0
720
	fi
721
	unset changed changedfile oldmetric newmetric x oldexcl
722
	;;
723
724
d)
725
	# Delete any existing information about the interface
726
	cd "$IFACEDIR"
727
	changed=false
728
	for i in $args; do
729
		if [ -e "$i" ]; then
730
			changed=true
731
		elif ! ${force}; then
732
			warn "No resolv.conf for interface $i"
733
		fi
734
		rm -f "$i" "$METRICDIR/"*" $i" \
735
			"$PRIVATEDIR/$i" \
736
			"$EXCLUSIVEDIR/"*" $i" || exit $?
737
	done
738
	if ! ${changed}; then
739
		# Set the return code based on the forced flag
740
		${force}
741
		exit $?
742
	fi
743
	unset changed i
744
	;;
745
esac
746
747
case "${resolvconf:-YES}" in
748
[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) ;;
749
*) exit 0;;
750
esac
751
407
eval "$(make_vars)"
752
eval "$(make_vars)"
408
export RESOLVCONF DOMAINS SEARCH NAMESERVERS LOCALNAMESERVERS
753
export RESOLVCONF DOMAINS SEARCH NAMESERVERS LOCALNAMESERVERS
409
: ${list_resolv:=list_resolv -l}
754
: ${list_resolv:=list_resolv -l}
Lines 410-419 Link Here
410
retval=0
755
retval=0
411
for script in "$LIBEXECDIR"/*; do
756
for script in "$LIBEXECDIR"/*; do
412
	if [ -f "$script" ]; then
757
	if [ -f "$script" ]; then
758
		eval script_enabled="\$${script##*/}"
759
		case "${script_enabled:-YES}" in
760
		[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) ;;
761
		*) continue;;
762
		esac
413
		if [ -x "$script" ]; then
763
		if [ -x "$script" ]; then
414
			"$script" "$cmd" "$iface"
764
			"$script" "$cmd" "$iface"
415
		else
765
		else
416
			(. "$script" "$cmd" "$iface")
766
			(set -- "$cmd" "$iface"; . "$script")
417
		fi
767
		fi
418
		retval=$(($retval + $?))
768
		retval=$(($retval + $?))
419
	fi
769
	fi
(-)contrib/openresolv/unbound.in (-2 / +16 lines)
Lines 1-5 Link Here
1
#!/bin/sh
1
#!/bin/sh
2
# Copyright (c) 2009 Roy Marples
2
# Copyright (c) 2009-2014 Roy Marples
3
# All rights reserved
3
# All rights reserved
4
4
5
# unbound subscriber for resolvconf
5
# unbound subscriber for resolvconf
Lines 26-35 Link Here
26
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
28
29
unbound_insecure=
30
29
[ -f "@SYSCONFDIR@"/resolvconf.conf ] || exit 0
31
[ -f "@SYSCONFDIR@"/resolvconf.conf ] || exit 0
30
. "@SYSCONFDIR@/resolvconf.conf" || exit 1
32
. "@SYSCONFDIR@/resolvconf.conf" || exit 1
31
[ -z "$unbound_conf" ] && exit 0
33
[ -z "$unbound_conf" ] && exit 0
32
[ -z "$RESOLVCONF" ] && eval "$(@PREFIX@/sbin/resolvconf -v)"
34
[ -z "$RESOLVCONF" ] && eval "$(@SBINDIR@/resolvconf -v)"
33
NL="
35
NL="
34
"
36
"
35
37
Lines 41-46 Link Here
41
for d in $DOMAINS; do
43
for d in $DOMAINS; do
42
	dn="${d%%:*}"
44
	dn="${d%%:*}"
43
	ns="${d#*:}"
45
	ns="${d#*:}"
46
	case "$unbound_insecure" in
47
	[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
48
		newconf="$newconf${NL}domain-insecure: \"$dn\""
49
		;;
50
	esac
44
	newconf="$newconf${NL}forward-zone:$NL	name: \"$dn\"$NL"
51
	newconf="$newconf${NL}forward-zone:$NL	name: \"$dn\"$NL"
45
	while [ -n "$ns" ]; do
52
	while [ -n "$ns" ]; do
46
		newconf="$newconf	forward-addr: ${ns%%,*}$NL"
53
		newconf="$newconf	forward-addr: ${ns%%,*}$NL"
Lines 56-61 Link Here
56
	done
63
	done
57
fi
64
fi
58
65
66
# Try to ensure that config dirs exist
67
if type config_mkdirs >/dev/null 2>&1; then
68
	config_mkdirs "$unbound_conf"
69
else
70
	@SBINDIR@/resolvconf -D "$unbound_conf"
71
fi
72
59
if [ ! -f "$unbound_conf" ] || \
73
if [ ! -f "$unbound_conf" ] || \
60
	[ "$(cat "$unbound_conf")" != "$(printf %s "$newconf")" ]
74
	[ "$(cat "$unbound_conf")" != "$(printf %s "$newconf")" ]
61
then
75
then

Return to bug 199854