~ubuntu-branches/ubuntu/oneiric/isc-dhcp/oneiric-security

« back to all changes in this revision

Viewing changes to client/scripts/macos

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Pollock
  • Date: 2009-09-02 22:34:25 UTC
  • Revision ID: james.westby@ubuntu.com-20090902223425-nypo7bkftxffq41m
Tags: upstream-4.1.0
ImportĀ upstreamĀ versionĀ 4.1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
#
 
3
# $Id: macos,v 1.2 2008/11/03 23:32:12 dhankins Exp $
 
4
#
 
5
# automous run of this script will commit the DNS setting
 
6
#
 
7
 
 
8
if [ -x /usr/bin/logger ]; then
 
9
        LOGGER="/usr/bin/logger -s -p user.notice -t dhclient"
 
10
else
 
11
        LOGGER=echo
 
12
fi
 
13
 
 
14
to_commit="yes"
 
15
 
 
16
make_resolv_conf() {
 
17
  to_commit="no"
 
18
  if [ "x${new_dhcp6_name_servers}" != x ]; then
 
19
    ( cat /dev/null > /var/run/resolv.conf.dhclient6 )
 
20
    exit_status=$?
 
21
    if [ $exit_status -ne 0 ]; then
 
22
      $LOGGER "Unable to create /var/run/resolv.conf.dhclient6: Error $exit_status"
 
23
    else
 
24
      if [ "x${new_dhcp6_domain_search}" != x ]; then
 
25
        ( echo search ${new_dhcp6_domain_search} >> /var/run/resolv.conf.dhclient6 )
 
26
        exit_status=$?
 
27
      fi
 
28
      for nameserver in ${new_dhcp6_name_servers} ; do
 
29
        if [ $exit_status -ne 0 ]; then
 
30
          break
 
31
        fi
 
32
        ( echo nameserver ${nameserver} >> /var/run/resolv.conf.dhclient6 )
 
33
        exit_status=$?
 
34
      done
 
35
 
 
36
      if [ $exit_status -eq 0 ]; then
 
37
        to_commit="force"
 
38
        commit_resolv_conf
 
39
      fi
 
40
    fi
 
41
  fi
 
42
}
 
43
 
 
44
# Try to commit /var/run/resolv.conf.dhclient6 contents to
 
45
# SystemConfiguration Dynamic Store
 
46
# Note this will be cleared by the next location change
 
47
commit_resolv_conf() {
 
48
  if [ -f /var/run/resolv.conf.dhclient6 ]; then
 
49
    if [ -x /usr/sbin/scutil ]; then
 
50
      serviceID=`echo show State:/Network/Global/IPv6 | \
 
51
          /usr/sbin/scutil | \
 
52
          awk '/PrimaryService/ { print $3 }'`
 
53
      echo $serviceID
 
54
      if [ x$serviceID = x ]; then
 
55
        $LOGGER "Can't find the primary IPv6 service"
 
56
      else
 
57
        tmp=`mktemp SC_dhclient6.XXXXXXXXXX`
 
58
        echo list | /usr/sbin/scutil > /tmp/$tmp
 
59
        grep -q State:/Network/Service/$serviceID/DNS /tmp/$tmp
 
60
        grep_status=$?
 
61
        if [ $grep_status -eq 0 ]; then
 
62
          $LOGGER "DNS service already set in primary IPv6 service"
 
63
          rm /tmp/$tmp
 
64
        else
 
65
          res=/var/run/resolv.conf.dhclient6
 
66
          cp /dev/null /tmp/$tmp
 
67
          grep -q '^nameserver' $res
 
68
          grep_status=$?
 
69
          if [ $grep_status -eq 0 ]; then
 
70
            echo d.add ServerAddresses '*' \
 
71
                 `awk 'BEGIN { n="" } \
 
72
                       /^nameserver/ { n=n " " $2 } \
 
73
                       END { print n}' < $res` >> /tmp/$tmp
 
74
          fi
 
75
          grep -q '^search' $res
 
76
          grep_status=$?
 
77
          if [ $grep_status -eq 0 ]; then
 
78
            echo d.add SearchDomains '*' \
 
79
                 `sed 's/^search//' < $res` >> /tmp/$tmp
 
80
          fi
 
81
          echo set State:/Network/Service/$serviceID/DNS >> /tmp/$tmp
 
82
          echo quit >> /tmp/$tmp
 
83
          cat /tmp/$tmp
 
84
          /usr/sbin/scutil < /tmp/$tmp
 
85
          rm /tmp/$tmp
 
86
        fi
 
87
      fi
 
88
    else
 
89
      $LOGGER "Can't find SystemConfiguration tools."
 
90
    fi
 
91
  else
 
92
    if [ $to_commit = force ]; then
 
93
      $LOGGER "Can't find /var/run/resolv.conf.dhclient6"
 
94
    fi
 
95
  fi
 
96
  to_commit="done"
 
97
}
 
98
 
 
99
# Must be used on exit.   Invokes the local dhcp client exit hooks, if any.
 
100
exit_with_hooks() {
 
101
  exit_status=$1
 
102
  if [ -f /etc/dhclient-exit-hooks ]; then
 
103
    . /etc/dhclient-exit-hooks
 
104
  fi
 
105
# probably should do something with exit status of the local script
 
106
  exit $exit_status
 
107
}
 
108
 
 
109
# Invoke the local dhcp client enter hooks, if they exist.
 
110
if [ -f /etc/dhclient-enter-hooks ]; then
 
111
  exit_status=0
 
112
  . /etc/dhclient-enter-hooks
 
113
  # allow the local script to abort processing of this state
 
114
  # local script must set exit_status variable to nonzero.
 
115
  if [ $exit_status -ne 0 ]; then
 
116
    exit $exit_status
 
117
  fi
 
118
fi
 
119
 
 
120
if [ x$reason = xMEDIUM ]; then
 
121
  eval "ifconfig $interface $medium"
 
122
  eval "ifconfig $interface inet -alias 0.0.0.0 $medium" >/dev/null 2>&1
 
123
  sleep 1
 
124
  exit_with_hooks 0
 
125
fi
 
126
 
 
127
###
 
128
### DHCPv6 Handlers
 
129
###
 
130
 
 
131
if [ x$reason = xPREINIT6 ]; then
 
132
  # Ensure interface is up.
 
133
  ifconfig ${interface} up
 
134
 
 
135
  # XXX: Remove any stale addresses from aborted clients.
 
136
 
 
137
  exit_with_hooks 0
 
138
fi
 
139
 
 
140
if [ x${old_ip6_prefix} != x ] || [ x${new_ip6_prefix} != x ]; then
 
141
    echo Prefix $reason old=${old_ip6_prefix} new=${new_ip6_prefix}
 
142
 
 
143
    exit_with_hooks 0
 
144
fi
 
145
 
 
146
if [ x$reason = xBOUND6 ]; then
 
147
  if [ x${new_ip6_address} = x ] || [ x${new_ip6_prefixlen} = x ]; then
 
148
    exit_with_hooks 2;
 
149
  fi
 
150
 
 
151
  ifconfig ${interface} inet6 ${new_ip6_address}/${new_ip6_prefixlen} alias
 
152
 
 
153
  # Check for nameserver options.
 
154
  make_resolv_conf
 
155
 
 
156
  exit_with_hooks 0
 
157
fi
 
158
 
 
159
if [ x$reason = xRENEW6 ] || [ x$reason = xREBIND6 ]; then
 
160
  # Make sure nothing has moved around on us.
 
161
 
 
162
  # Nameservers/domains/etc.
 
163
  if [ "x${new_dhcp6_name_servers}" != "x${old_dhcp6_name_servers}" ] ||
 
164
     [ "x${new_dhcp6_domain_search}" != "x${old_dhcp6_domain_search}" ]; then
 
165
    make_resolv_conf
 
166
  fi
 
167
 
 
168
  exit_with_hooks 0
 
169
fi
 
170
 
 
171
if [ x$reason = xDEPREF6 ]; then
 
172
  if [ x${new_ip6_address} = x ]; then
 
173
    exit_with_hooks 2;
 
174
  fi
 
175
 
 
176
  ifconfig ${interface} inet6 ${new_ip6_address} deprecated
 
177
 
 
178
  exit_with_hooks 0
 
179
fi
 
180
 
 
181
if [ x$reason = xEXPIRE6 -o x$reason = xRELEASE6 -o x$reason = xSTOP6 ]; then
 
182
  if [ x${old_ip6_address} = x ] || [ x${old_ip6_prefixlen} = x ]; then
 
183
    exit_with_hooks 2;
 
184
  fi
 
185
 
 
186
  ifconfig ${interface} inet6 ${old_ip6_address}/${old_ip6_prefixlen} -alias
 
187
 
 
188
  exit_with_hooks 0
 
189
fi
 
190
 
 
191
if [ $to_commit = yes ]; then
 
192
  commit_resolv_conf
 
193
fi
 
194
 
 
195
exit_with_hooks 0