~ubuntu-branches/ubuntu/trusty/dhcpcd/trusty-security

« back to all changes in this revision

Viewing changes to debian/dhcpcd.exe

  • Committer: Bazaar Package Importer
  • Author(s): Simon Kelley
  • Date: 2005-09-30 02:21:51 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050930022151-vq3xlcazj0bdpyf4
Tags: 1:2.0.0-2
Clear out /etc/dhcpc/resolv.conf and /var/lib/dhcpc/* 
during purge. (closes: #330515)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
#
 
3
#  This is a sample /etc/dhcpc/dhcpcd.exe script.
 
4
#  /etc/dhcpc/dhcpcd.exe script is executed by dhcpcd daemon
 
5
#  any time it configures or shuts down interface.
 
6
#  The following parameters are passed to dhcpcd.exe script:
 
7
#  $1 = HostInfoFilePath, e.g  "/var/lib/dhcpc/dhcpcd-eth0.info"
 
8
#  $2 = "up" if interface has been configured with the same
 
9
#       IP address as before reboot;
 
10
#  $2 = "down" if interface has been shut down;
 
11
#  $2 = "new" if interface has been configured with new IP address;
 
12
#  $3 (optional) = "-d" debug flag passed if dhcpcd daemon has been
 
13
#       invoked with "-d" flag
 
14
#
 
15
# This script sources /var/lib/dhcpc/dhcpcd-<interface>.info which defines 
 
16
# a set of variables. 
 
17
# NOTE THAT THE DATA IN SOME OF THESE VARIABLES COME FROM 
 
18
# UNTRUSTED SOURCES AND ARE UNCHECKED.
 
19
# The variables in question are HOSTNAME, DOMAIN, NISDOMAIN, 
 
20
# ROOTPATH DNSSEARCH and DHCPSNAME. Enough quoting is done to ensure that
 
21
# execution of this script is safe, but beware if you pass the value of any of
 
22
# these variables to another shell or perl script - there is nothing to
 
23
# stop an attacker putting dangerous characters in these variables. 
 
24
#
 
25
# This is important: if noglob not set a filename expansion metachar may be
 
26
# included in one of the variables set in the info file and executed
 
27
# if that variable is used.
 
28
# Try this to see the effect:
 
29
# TEST='*'; echo $TEST
 
30
set -o noglob
 
31
 
 
32
#  Sanity checks
 
33
 
 
34
if [ $# -lt 2 ]; then
 
35
  logger -s -p local0.err -t dhcpcd.exe "wrong usage"
 
36
  exit 1
 
37
fi
 
38
 
 
39
hostinfo="$1"
 
40
state="$2"
 
41
debug="$3"
 
42
 
 
43
# Reading HostInfo file for configuration parameters
 
44
if ! [ -f ${hostinfo} ]; then
 
45
   logger -s -p local0.err -t dhcpcd.exe "No hostinfo file"
 
46
   exit 1
 
47
fi
 
48
 
 
49
. ${hostinfo}
 
50
 
 
51
write_resolv_info()
 
52
{
 
53
    dnsservs=${DNS//,/ }
 
54
    r=""
 
55
    [ "$dnsservs" != "" ] && [ "$DNSSEARCH" != "" ] && r="${r}search $DNSSEARCH
 
56
"
 
57
    [ "$dnsservs" != "" ] && [ "$DNSSEARCH" == "" ] && [ "$DOMAIN" != "" ] && r="${r}search $DOMAIN
 
58
"
 
59
    for serv in $dnsservs; do
 
60
        r="${r}nameserver $serv
 
61
"
 
62
    done
 
63
    if [ -x /sbin/resolvconf ] ; then
 
64
        echo -n "$r" | /sbin/resolvconf -a "$INTERFACE"
 
65
    else
 
66
        # set /etc/dhcpc/resolv.conf for compatiblity with older packages
 
67
        echo -n "$r" >| /etc/dhcpc/resolv.conf
 
68
        chmod 644 /etc/dhcpc/resolv.conf
 
69
    fi
 
70
}
 
71
 
 
72
delete_resolv_info()
 
73
{
 
74
    if [ -x /sbin/resolvconf ] ; then
 
75
        /sbin/resolvconf -d "$INTERFACE"
 
76
    fi
 
77
}
 
78
 
 
79
case ${INTERFACE} in
 
80
  eth*) ;;
 
81
 wlan*) ;;
 
82
     *) logger -s -p local0.err -t dhcpcd.exe "wrong interface name \"${INTERFACE}\""
 
83
        exit 1
 
84
        ;;
 
85
esac
 
86
 
 
87
case ${state} in
 
88
 up) logger -s -p local0.info -t dhcpcd.exe "interface ${INTERFACE} has been configured with old IP=${IPADDR}"
 
89
     write_resolv_info
 
90
 
 
91
# ====  Put your code for the case interface has been brought up with old IP address here
 
92
 
 
93
 
 
94
 
 
95
 
 
96
# ====  End
 
97
     ;;
 
98
 
 
99
 new) logger -s -p local0.info -t dhcpcd.exe "interface ${INTERFACE} has been configured with new IP=${IPADDR}"
 
100
     write_resolv_info
 
101
 
 
102
# ====  Put your code for the case interface has been brought up with new IP address here
 
103
 
 
104
 
 
105
 
 
106
 
 
107
# ====  End
 
108
     ;;
 
109
 
 
110
 down) logger -s -p local0.info -t dhcpcd.exe "interface ${INTERFACE} has been brought down"
 
111
     delete_resolv_info
 
112
# ====  Put your code for the case interface has been shut down here
 
113
 
 
114
 
 
115
 
 
116
 
 
117
# ====  End
 
118
     ;;
 
119
esac
 
120
 
 
121
exit 0