[go: up one dir, main page]

File: dhcpcd.exe

package info (click to toggle)
dhcpcd 1%3A1.3.22pl4-21sarge1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 784 kB
  • ctags: 313
  • sloc: sh: 3,590; ansic: 3,583; makefile: 93
file content (121 lines) | stat: -rwxr-xr-x 3,316 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/bin/bash
#
#  This is a sample /etc/dhcpc/dhcpcd.exe script.
#  /etc/dhcpc/dhcpcd.exe script is executed by dhcpcd daemon
#  any time it configures or shuts down interface.
#  The following parameters are passed to dhcpcd.exe script:
#  $1 = HostInfoFilePath, e.g  "/var/lib/dhcpc/dhcpcd-eth0.info"
#  $2 = "up" if interface has been configured with the same
#       IP address as before reboot;
#  $2 = "down" if interface has been shut down;
#  $2 = "new" if interface has been configured with new IP address;
#  $3 (optional) = "-d" debug flag passed if dhcpcd daemon has been
#       invoked with "-d" flag
#
# This script sources /var/lib/dhcpc/dhcpcd-<interface>.info which defines 
# a set of variables. 
# NOTE THAT THE DATA IN SOME OF THESE VARIABLES COME FROM 
# UNTRUSTED SOURCES AND ARE UNCHECKED.
# The variables in question are HOSTNAME, DOMAIN, NISDOMAIN, 
# ROOTPATH DNSSEARCH and DHCPSNAME. Enough quoting is done to ensure that
# execution of this script is safe, but beware if you pass the value of any of
# these variables to another shell or perl script - there is nothing to
# stop an attacker putting dangerous characters in these variables. 
#
# This is important: if noglob not set a filename expansion metachar may be
# included in one of the variables set in the info file and executed
# if that variable is used.
# Try this to see the effect:
# TEST='*'; echo $TEST
set -o noglob

#  Sanity checks

if [ $# -lt 2 ]; then
  logger -s -p local0.err -t dhcpcd.exe "wrong usage"
  exit 1
fi

hostinfo="$1"
state="$2"
debug="$3"

# Reading HostInfo file for configuration parameters
if ! [ -f ${hostinfo} ]; then
   logger -s -p local0.err -t dhcpcd.exe "No hostinfo file"
   exit 1
fi

. ${hostinfo}

write_resolv_info()
{
    dnsservs=${DNS//,/ }
    r=""
    [ "$dnsservs" != "" ] && [ "$DNSSEARCH" != "" ] && r="${r}search $DNSSEARCH
"
    [ "$dnsservs" != "" ] && [ "$DNSSEARCH" == "" ] && [ "$DOMAIN" != "" ] && r="${r}search $DOMAIN
"
    for serv in $dnsservs; do
        r="${r}nameserver $serv
"
    done
    if [ -x /sbin/resolvconf ] ; then
        echo -n "$r" | /sbin/resolvconf -a "$INTERFACE"
    else
        # set /etc/dhcpc/resolv.conf for compatiblity with older packages
        echo -n "$r" >| /etc/dhcpc/resolv.conf
        chmod 644 /etc/dhcpc/resolv.conf
    fi
}

delete_resolv_info()
{
    if [ -x /sbin/resolvconf ] ; then
        /sbin/resolvconf -d "$INTERFACE"
    fi
}

case ${INTERFACE} in
  eth*) ;;
 wlan*) ;;
     *) logger -s -p local0.err -t dhcpcd.exe "wrong interface name \"${INTERFACE}\""
	exit 1
	;;
esac

case ${state} in
 up) logger -s -p local0.info -t dhcpcd.exe "interface ${INTERFACE} has been configured with old IP=${IPADDR}"
     write_resolv_info

# ====  Put your code for the case interface has been brought up with old IP address here




# ====  End
     ;;

 new) logger -s -p local0.info -t dhcpcd.exe "interface ${INTERFACE} has been configured with new IP=${IPADDR}"
     write_resolv_info

# ====  Put your code for the case interface has been brought up with new IP address here




# ====  End
     ;;

 down) logger -s -p local0.info -t dhcpcd.exe "interface ${INTERFACE} has been brought down"
     delete_resolv_info
# ====  Put your code for the case interface has been shut down here




# ====  End
     ;;
esac

exit 0