~ubuntu-branches/ubuntu/precise/openvpn/precise-security

« back to all changes in this revision

Viewing changes to contrib/pull-resolv-conf/client.down

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2011-06-16 18:33:37 UTC
  • mfrom: (1.1.17 upstream) (10.2.13 sid)
  • Revision ID: james.westby@ubuntu.com-20110616183337-fv50u3kmiabewjq0
Tags: 2.2.0-2ubuntu1
* Merge from debian unstable.  Remaining changes:
 + debian/openvpn.init.d:
    - Do not use start-stop-daemon and </dev/null to avoid blocking boot.
    - Show per-VPN result messages.
    - Add "--script-security 2" by default for backwards compatabliity.
  + debian/control: Add lsb-base >= 3.2-14 to allow status_of_proc()
  + debian/update-resolv-conf: Support multiple domains.
  + fix bug where '--script-security 2' would be passed for all
    daemons after the first. (LP: #794916

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/bash
 
1
#!/bin/sh
2
2
 
3
3
# Copyright (c) 2005-2010 OpenVPN Technologies, Inc.
4
4
# Licensed under the GPL version 2
14
14
# Place this in /etc/openvpn/client.down
15
15
# Then, add the following to your /etc/openvpn/<clientconfig>.conf:
16
16
#   client
17
 
#   pull dhcp-options
18
17
#   up /etc/openvpn/client.up
19
18
#   down /etc/openvpn/client.down
20
19
# Next, "chmod a+x /etc/openvpn/client.down"
23
22
# Note that this script is best served with the companion "client.up"
24
23
# script.
25
24
 
26
 
# Only tested on Gentoo Linux 2005.0 with OpenVPN 2.0
27
 
# It should work with any GNU/Linux with /etc/resolv.conf
 
25
# Tested under Debian lenny with OpenVPN 2.1_rc11
 
26
# It should work with any UNIX with a POSIX sh, /etc/resolv.conf or resolvconf
28
27
 
29
28
# This runs with the context of the OpenVPN UID/GID 
30
29
# at the time of execution. This generally means that
35
34
# A horrid work around, from a security perspective,
36
35
# is to run OpenVPN as root. THIS IS NOT RECOMMENDED. You have
37
36
# been WARNED.
38
 
 
39
 
# init variables
40
 
 
41
 
i=1
42
 
j=1
43
 
unset fopt
44
 
unset dns
45
 
unset opt
46
 
 
47
 
# Convert ENVs to an array
48
 
 
49
 
while fopt=foreign_option_$i; [ -n "${!fopt}" ]; do
50
 
{
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++
60
 
}
61
 
done
62
 
 
63
 
# Now, do the work
64
 
 
65
 
if [ -n "${dns[*]}" ]; then
66
 
        for i in "${dns[@]}"; do
67
 
                sed -i -e "/nameserver ${i}/D" /etc/resolv.conf || die
68
 
        done
69
 
fi
70
 
 
71
 
if [ -n "${domain}" ]; then
72
 
        sed -i -e "/search ${domain}/D" /etc/resolv.conf || die
73
 
fi
74
 
 
75
 
# all done...
 
37
PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin
 
38
 
 
39
if type resolvconf >/dev/null 2>&1; then
 
40
  resolvconf -d "${1}" -f
 
41
elif [ -e /etc/resolv.conf.ovpnsave ] ; then
 
42
  # cp + rm rather than mv in case it's a symlink
 
43
  cp /etc/resolv.conf.ovpnsave /etc/resolv.conf
 
44
  rm -f /etc/resolv.conf.ovpnsave
 
45
fi
 
46
 
76
47
exit 0