3 # Example script for "wins hook". This attempts to update the DNS with
4 # new A records for the NETBIOS name that Samba passes us. We do this
5 # the simple way, by deleting all DNS records for the name and then
6 # readding all the expected 'A' records.
8 # Written by Stephen Rothwell <sfr@linuxcare.com>
14 # The domain in which to create names
15 # YOU MUST CHANGE THIS
16 # N.B. include the trailing dot
18 # It is a good idea to use a subdomain of your primary domain to ensure
19 # that rogue machines can't take over (or delete) important names on
21 DOMAIN
=wins.example.com.
24 # The DNS TTL to give the records (in seconds)
28 # NETBIOS name types that we want to create DNS records for:
33 USEFUL_TYPES
="20 00 03"
35 # The name of a cache file to use to avoid continual updates
36 # of the same name and IP addresses. If you comment this out
37 # then the cache is not kept at all.
39 #CACHE_FILE=/usr/local/samba/var/wins_update.cache
42 echo "Usage: $0 op name type ttl [ip_addr ...]" 1>&2
43 echo " op is one of add, refresh, delete" 1>&2
44 echo " name is the NETBIOS name" 1>&2
45 echo " type is the NETBIOS name type" 1>&2
46 echo " ttl is the NETBIOS time to live" 1>&2
47 echo " ip_addr's are the remaining IP addresses for this name" 1>&2
51 NSUPDATE
=`which nsupdate`
52 [ -x "$NSUPDATE" ] || NSUPDATE
=/usr
/bin
/nsupdate
53 [ -x "$NSUPDATE" ] || NSUPDATE
=/sbin
/nsupdate
54 [ -x "$NSUPDATE" ] || NSUPDATE
=/usr
/sbin
/nsupdate
55 [ -x "$NSUPDATE" ] ||
{
56 echo "Cannot find nsupdate." 1>&2
68 for i
in $USEFUL_TYPES
70 [ "$TYPE" = "$i" ] && do_update
=1
72 [ $do_update = 1 ] ||
exit 0
74 if [ -n "$CACHE_FILE" ]; then
75 if [ -r "$CACHE_FILE" ]; then
76 fgrep
-q -x -i "$NAME $IP_ADDRS" "$CACHE_FILE" &&
78 grep -v -i "^$NAME " "$CACHE_FILE" >"$CACHE_FILE".$$
80 echo "$NAME $IP_ADDRS" >>"$CACHE_FILE".$$
81 mv "$CACHE_FILE" "$CACHE_FILE".old
2>/dev
/null
82 mv "$CACHE_FILE".$$
"$CACHE_FILE"
86 echo update delete
$NAME.
$DOMAIN
89 echo update add
$NAME.
$DOMAIN $TTL A
$i
92 } 2>/dev
/null |
$NSUPDATE >/dev
/null
2>&1 &