can_write_to_file() does now take share permissions into account. Fix comment.
[Samba/gebeck_regimport.git] / source4 / scripting / devel / rebuild_zone.sh
blobbac64be5f0f8235ad1bcf12dea365222aef2b70e
1 #!/bin/sh
2 # rebuild a zone file, adding all DCs
4 [ $# -eq 2 ] || {
5 echo "rebuild_zone.sh <sam.ldb> <zonefile>"
6 exit 1
9 LDB="$1"
10 ZFILE="$2"
12 dnshostname=$(bin/ldbsearch -H $LDB -s base -b '' dnsHostname | grep ^dns | cut -d' ' -f2)
13 host=$(echo $dnshostname | cut -d. -f1)
14 realm=$(echo $dnshostname | cut -d. -f2-)
15 GUIDs=$(bin/ldbsearch -H $LDB objectclass=ntdsdsa objectguid --cross-ncs|grep ^objectGUID| cut -d' ' -f2)
16 DOMAINGUID=$(bin/ldbsearch -H $LDB -s base objectguid |grep ^objectGUID| cut -d' ' -f2)
18 dcname() {
19 GUID=$1
20 echo $(bin/ldbsearch -H $LDB objectguid=$GUID dn --cross-ncs|grep CN=NTDS.Settings| cut -d, -f2| cut -d= -f2)
23 getip() {
24 NAME=$1
25 ret=$(nmblookup $NAME| egrep '^[0-9]' | head -1 | cut -d' ' -f1)
26 test -n "$ret" || {
27 echo "Unable to find IP for $NAME. Using XX.XX.XX.XX. Please edit" 1>&2
28 echo "XX.XX.XX.XX"
30 echo $ret
33 echo "Generating header for host $host in realm $realm"
34 cat <<EOF > $ZFILE
35 ; -*- zone -*-
36 ; generated by rebuild_zone.sh
37 \$ORIGIN $realm.
38 \$TTL 1W
39 @ IN SOA @ hostmaster (
40 $(date +%Y%m%d%H) ; serial
41 2D ; refresh
42 4H ; retry
43 6W ; expiry
44 1W ) ; minimum
45 IN NS $host
47 EOF
49 for GUID in $GUIDs; do
50 dc=$(dcname $GUID)
51 echo "Generating IP for DC $dc"
52 ip=$(getip $dc)
53 test -n "$ip" || exit 1
54 echo " IN A $ip" >> $ZFILE
55 done
57 echo "; IP Addresses" >> $ZFILE
58 for GUID in $GUIDs; do
59 dc=$(dcname $GUID)
60 ip=$(getip $dc)
61 test -n "$ip" || exit 1
62 echo "$dc IN A $ip" >> $ZFILE
63 done
65 for GUID in $GUIDs; do
66 dc=$(dcname $GUID)
67 ip=$(getip $dc)
68 test -n "$ip" || exit 1
69 echo "Generating zone body for DC $dc with IP $ip"
70 cat <<EOF >> $ZFILE
72 ; Entries for $dc
73 gc._msdcs IN A $ip
74 $GUID._msdcs IN CNAME $dc
75 _gc._tcp IN SRV 0 100 3268 $dc
76 _gc._tcp.Default-First-Site-Name._sites IN SRV 0 100 3268 $dc
77 _ldap._tcp.gc._msdcs IN SRV 0 100 389 $dc
78 _ldap._tcp.Default-First-Site-Name._sites.gc._msdcs IN SRV 0 100 389 $dc
79 _ldap._tcp IN SRV 0 100 389 $dc
80 _ldap._tcp.dc._msdcs IN SRV 0 100 389 $dc
81 _ldap._tcp.pdc._msdcs IN SRV 0 100 389 $dc
82 _ldap._tcp.$DOMAINGUID.domains._msdcs IN SRV 0 100 389 $dc
83 _ldap._tcp.Default-First-Site-Name._sites IN SRV 0 100 389 $dc
84 _ldap._tcp.Default-First-Site-Name._sites.dc._msdcs IN SRV 0 100 389 $dc
85 _kerberos._tcp IN SRV 0 100 88 $dc
86 _kerberos._tcp.dc._msdcs IN SRV 0 100 88 $dc
87 _kerberos._tcp.Default-First-Site-Name._sites IN SRV 0 100 88 $dc
88 _kerberos._tcp.Default-First-Site-Name._sites.dc._msdcs IN SRV 0 100 88 $dc
89 _kerberos._udp IN SRV 0 100 88 $dc
90 _kerberos-master._tcp IN SRV 0 100 88 $dc
91 _kerberos-master._udp IN SRV 0 100 88 $dc
92 _kpasswd._tcp IN SRV 0 100 464 $dc
93 _kpasswd._udp IN SRV 0 100 464 $dc
94 EOF
95 done
97 cat <<EOF >> $ZFILE
99 ; kerberos hack
100 _kerberos IN TXT $(echo $realm | tr [a-z] [A-Z])
103 echo "Rebuilt zone file $ZFILE OK"
105 echo "Reloading bind config"
106 PATH="/usr/sbin:$PATH" rndc reload
107 exit 0