Debian Codegraph @

examples/scripts/wins_hook/dns_update

raw symbols SCIP
1 #!/bin/shscip-shell filesystem . . `/bin/sh`.
2 #
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 # re-adding all the expected 'A' records.
7 #
8 # Written by Stephen Rothwell <[email protected]>
9 #
10
11 #
12 # Configurable things
13 #
14 # The domain in which to create names
15 # YOU MUST CHANGE THIS
16 # N.B. include the trailing dot
17 #
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
20 # your network.
21 DOMAIN=wins.example.com.
22
23 #
24 # The DNS TTL to give the records (in seconds)
25 #
26 TTL=3600
27 #
28 # NETBIOS name types that we want to create DNS records for:
29 # 20 is server
30 # 00 is workstation
31 # 03 is user
32 #
33 USEFUL_TYPES="20 00 03"
34 #
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.
38 #
39 #CACHE_FILE=/usr/local/samba/var/wins_update.cache
40
41 if [scip-shell system . . `[`. $# -lt 4 ]; then
42 echoscip-shell system . . echo. "Usage: $0 op name type ttl [ip_addr ...]" 1>&2
43 echoscip-shell system . . echo. " op is one of add, refresh, delete" 1>&2
44 echoscip-shell system . . echo. " name is the NETBIOS name" 1>&2
45 echoscip-shell system . . echo. " type is the NETBIOS name type" 1>&2
46 echoscip-shell system . . echo. " ttl is the NETBIOS time to live" 1>&2
47 echoscip-shell system . . echo. " ip_addr's are the remaining IP addresses for this name" 1>&2
48 exit 1
49 fi
50
51 NSUPDATE=$(whichscip-shell system . . which. nsupdate)
52 [scip-shell system . . `[`. -x "$NSUPDATE" ] || NSUPDATE=/usr/bin/nsupdatescip-shell filesystem . . `/usr/bin/nsupdate`.
53 [scip-shell system . . `[`. -x "$NSUPDATE" ] || NSUPDATE=/sbin/nsupdatescip-shell filesystem . . `/sbin/nsupdate`.
54 [scip-shell system . . `[`. -x "$NSUPDATE" ] || NSUPDATE=/usr/sbin/nsupdatescip-shell filesystem . . `/usr/sbin/nsupdate`.
55 [scip-shell system . . `[`. -x "$NSUPDATE" ] || {
56 echoscip-shell system . . echo. "Cannot find nsupdate." 1>&2
57 exit 1
58 }
59
60 OP=$1
61 NAME=$2
62 TYPE=$3
63 WINS_TTL=$4
64 shift 4
65 IP_ADDRS="$@"
66
67 do_update=0
68 for i in $USEFUL_TYPES; do
69 [scip-shell system . . `[`. "$TYPE" = "$i" ] && do_update=1
70 done
71 [scip-shell system . . `[`. $do_update = 1 ] || exit 0
72
73 if [scip-shell system . . `[`. -n "$CACHE_FILE" ]; then
74 if [scip-shell system . . `[`. -r "$CACHE_FILE" ]; then
75 fgrepscip-shell system . . fgrep. -q -x -i "$NAME $IP_ADDRS" "$CACHE_FILE" &&
76 exit 0
77 grepscip-shell system . . grep. -v -i "^$NAME " "$CACHE_FILE" >"$CACHE_FILE".$$
78 fi
79 echoscip-shell system . . echo. "$NAME $IP_ADDRS" >>"$CACHE_FILE".$$
80 mvscip-shell system . . mv. "$CACHE_FILE" "$CACHE_FILE".old 2>/dev/nullscip-shell filesystem . . `/dev/null`.
81 mvscip-shell system . . mv. "$CACHE_FILE".$$ "$CACHE_FILE"
82 fi
83
84 {
85 echoscip-shell system . . echo. update delete $NAME.$DOMAIN
86 for i in $IP_ADDRS; do
87 echoscip-shell system . . echo. update add $NAME.$DOMAIN $TTL A $i
88 done
89 echoscip-shell system . . echo.
90 } 2>/dev/nullscip-shell filesystem . . `/dev/null`. | $NSUPDATE >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 &
91
92 exit 0