File: ldap2bind

package info (click to toggle)
ldap2zone 0.1-7%2Bsqueeze1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 148 kB
  • ctags: 20
  • sloc: sh: 394; ansic: 325; makefile: 58
file content (58 lines) | stat: -rwxr-xr-x 1,436 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/sh

[ -r /etc/default/ldap2zone ] && . /etc/default/ldap2zone

[[ ${LDAP_URI} =~ 'ldap''s'?'://''.'* ]] || LDAP_URI="ldap://${LDAP_URI}"
LDAPSEARCH=`which ldapsearch`
LDAP_URI_PARAM=${LDAP_URI:+"-H $LDAP_URI"}
ALLOW_UPDATE_PARAM=${ALLOW_UPDATE:+"allow-update {$ALLOW_UPDATE};"}

ZONES=`ldapsearch -LLL $LDAP_HOST_PARAM -x "(objectClass=dNSZone)" zoneName | grep zoneName: | sort | uniq | awk '{print $2}'`
ldap2zone=`which ldap2zone`
rndc=`which rndc`

if [ -z "${ZONES}" ]; then
	echo "No domains configured. Exiting..."
	exit 0
fi

if [ -z "${rndc}" ]; then
	echo "rndc utilty not in $PATH. Exiting..."
	exit 1
fi

if [ -z "${ldap2zone}" ]; then
	echo "ldap2zone utilty not in $PATH. Exiting..."
	exit 1
fi

if [ ! -d $BIND_DIR ]; then
	echo "The directory specified as BIND_DIR does not exist. Exiting..."
	exit 1
fi

if [ -w $BIND_DIR/named.conf.ldap2zone ]; then
	>${BIND_DIR}/named.conf.ldap2zone
	for domain in $ZONES; do
		cat << EOF >> ${BIND_DIR}/named.conf.ldap2zone
zone "${domain}" {
	type master;
	file "${BIND_DIR}/${PREFIX}${domain}";
	$ALLOW_UPDATE_PARAM
};
EOF
	done
	$rndc reconfig
fi

for domain in $ZONES; do
	if $ldap2zone $domain $LDAP_URI $TTL > /tmp/$domain; then
		lines=$(cat /tmp/$domain | wc -l)
		[ $lines -gt 1 ] && mv /tmp/$domain $BIND_DIR/${PREFIX}${domain}
	fi

	result=$($rndc reload $domain 2>&1)
	if [ $? -ne 0 ]; then
		echo -e "Reloading the zone '$domain' failed:\n$result" 1>&2
	fi
done