named.in revision 219736
1#!/bin/sh
2# Copyright (c) 2007-2009 Roy Marples
3# All rights reserved
4
5# named subscriber for resolvconf
6
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions
9# are met:
10#     * Redistributions of source code must retain the above copyright
11#       notice, this list of conditions and the following disclaimer.
12#     * Redistributions in binary form must reproduce the above
13#       copyright notice, this list of conditions and the following
14#       disclaimer in the documentation and/or other materials provided
15#       with the distribution.
16#
17# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
28
29[ -f "@SYSCONFDIR@"/resolvconf.conf ] || exit 0
30. "@SYSCONFDIR@/resolvconf.conf" || exit 1
31[ -z "$named_zones" -a -z "$named_options" ] && exit 0
32[ -z "$RESOLVCONF" ] && eval "$(@PREFIX@/sbin/resolvconf -v)"
33
34# Platform specific kludges
35if [ -z "$named_service" -a -z "$named_restart" -a \
36	-d "@RCDIR@" -a ! -x "@RCDIR@"/named ]
37then
38	if [ -x "@RCDIR@"/bind9 ]; then
39		# Debian and derivatives
40		named_service=bind9
41	fi
42fi
43: ${named_service:=named}
44: ${named_restart:=@RESTARTCMD ${named_service}@}
45newoptions="# Generated by resolvconf\n"
46newzones="$newoptions"
47
48forward=
49for n in $NAMESERVERS; do
50	case "$forward" in
51	*"\n\t$n;"*);;
52	*) forward="$forward\n\t$n;";;
53	esac
54done
55if [ -n "$forward" ]; then
56	newoptions="${newoptions}forward first;\nforwarders {$forward\n};\n"
57fi
58
59for d in $DOMAINS; do
60	newzones="${newzones}zone \"${d%%:*}\" {\n"
61	newzones="$newzones\ttype forward;\n"
62	newzones="$newzones\tforward first;\n\tforwarders {\n"
63	ns="${d#*:}"
64	while [ -n "$ns" ]; do
65		newzones="$newzones\t\t${ns%%,*};\n"
66		[ "$ns" = "${ns#*,}" ] && break
67		ns="${ns#*,}"
68	done
69	newzones="$newzones\t};\n};\n"
70done
71
72# No point in changing files or reloading bind if the end result has not
73# changed
74changed=false
75if [ -n "$named_options" ]; then
76	if [ ! -f "$named_options" ] || \
77		[ "$(cat "$named_options")" != "$(printf "$newoptions")" ]
78	then
79		printf "$newoptions" >"$named_options"
80		changed=true
81	fi
82fi
83if [ -n "$named_zones" ]; then
84	if [ ! -f "$named_zones" ] || \
85		[ "$(cat "$named_zones")" != "$(printf "$newzones")" ]
86	then
87		printf "$newzones" >"$named_zones"
88		changed=true
89	fi
90fi
91
92if $changed; then
93	eval $named_restart
94fi
95