svn cleanup
[anytun.git] / openvpn / contrib / pull-resolv-conf / client.down
blobd51472f51407b820a44935064d23099798c33846
1 #!/bin/bash
3 # Copyright (c) 2005 by OpenVPN Solutions LLC
4 # Licensed under the GPL version 2
6 # First version by Jesse Adelman
7 # someone at boldandbusted dink com
8 # http://www.boldandbusted.com/
10 # PURPOSE: This script automatically removes the /etc/resolv.conf entries previously
11 # set by the companion script "client.up".
13 # INSTALL NOTES:
14 # Place this in /etc/openvpn/client.down
15 # Then, add the following to your /etc/openvpn/<clientconfig>.conf:
16 # client
17 # pull dhcp-options
18 # up /etc/openvpn/client.up
19 # down /etc/openvpn/client.down
20 # Next, "chmod a+x /etc/openvpn/client.down"
22 # USAGE NOTES:
23 # Note that this script is best served with the companion "client.up"
24 # script.
26 # Only tested on Gentoo Linux 2005.0 with OpenVPN 2.0
27 # It should work with any GNU/Linux with /etc/resolv.conf
29 # This runs with the context of the OpenVPN UID/GID
30 # at the time of execution. This generally means that
31 # the client "up" script will run fine, but the "down" script
32 # will require the use of the OpenVPN "down-root" plugin
33 # which is in the plugins/ directory of the OpenVPN source tree
35 # A horrid work around, from a security perspective,
36 # is to run OpenVPN as root. THIS IS NOT RECOMMENDED. You have
37 # been WARNED.
39 # init variables
41 i=1
42 j=1
43 unset fopt
44 unset dns
45 unset opt
47 # Convert ENVs to an array
49 while fopt=foreign_option_$i; [ -n "${!fopt}" ]; do
51 opt[i-1]=${!fopt}
52 case ${opt[i-1]} in
53 *DOMAIN* ) domain=`echo ${opt[i-1]} | \
54 sed -e 's/dhcp-option DOMAIN //g'` ;;
55 *DNS* ) dns[j-1]=`echo ${opt[i-1]} | \
56 sed -e 's/dhcp-option DNS //g'`
57 let j++ ;;
58 esac
59 let i++
61 done
63 # Now, do the work
65 if [ -n "${dns[*]}" ]; then
66 for i in "${dns[@]}"; do
67 sed -i -e "/nameserver ${i}/D" /etc/resolv.conf || die
68 done
71 if [ -n "${domain}" ]; then
72 sed -i -e "/search ${domain}/D" /etc/resolv.conf || die
75 # all done...
76 exit 0