1 #!/usr/bin/ksh
2 #
3 # CDDL HEADER START
4 #
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License, Version 1.0 only
7 # (the "License"). You may not use this file except in compliance
8 # with the License.
9 #
10 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11 # or http://www.opensolaris.org/os/licensing.
12 # See the License for the specific language governing permissions
13 # and limitations under the License.
14 #
15 # When distributing Covered Code, include this CDDL HEADER in each
16 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17 # If applicable, add the following below this CDDL HEADER, with the
18 # fields enclosed by brackets "[]" replaced with your own identifying
19 # information: Portions Copyright [yyyy] [name of copyright owner]
20 #
21 # CDDL HEADER END
22 #
23 #
24 # Copyright (c) 2001 by Sun Microsystems, Inc.
25 # All rights reserved.
26 #
27
28 #
29 # Source the utilities.
30 #
31 DIRNAME=`dirname $0`
32 . ${DIRNAME}/utilities.san
33
34 #
35 # Process the input arguments.
36 #
37 VALIDOPTS=dr:p:
38 process_args $@
39
40 #
41 # In case the tester wants to see script output, allow them
42 # to run in debug mode.
43 #
44 TESTNAME=`basename $0`
45 if [ ! -z "${DEBUG}" ]
46 then
47 OUTFILE=/tmp/${TESTNAME}.$$
48 echo "Output from test: ${TESTNAME}" >${OUTFILE}
49 echo >>${OUTFILE}
50 echo "debug output can be found at ${OUTFILE}"
51 else
52 OUTFILE=/dev/null
53 fi
54
55 #
56 # Set DNSSERV and DNSDMAIN if server has a resolv.conf. Return 0 if it does,
57 # nonzero otherwise.
58 #
59 get_dns_parms()
60 {
61 if [ ! -f /etc/resolv.conf ]
62 then
63 return 1
64 fi
65
66 nsr=0
67 dmn=0
68 DNSRV=""
69 DNAME=""
70 for item in `cat /etc/resolv.conf`
71 do
72 if [ "${item}" = "nameserver" ]
73 then
74 nsr=1
75 continue
76 fi
77 if [ "${item}" = "domain" ]
78 then
79 dmn=1
80 continue
81 fi
82 if [ ${nsr} -eq 1 ]
83 then
84 if [ -z "${DNSRV}" ]
85 then
86 DNSRV=${item}
87 else
88 DNSRV="${DNSRV} ${item}"
89 fi
90 nsr=0
91 continue
92 fi
93 if [ ${dmn} -eq 1 ]
94 then
95 DNAME="${item}"
96 dmn=0
97 continue
98 fi
99 done
100 if [ ! -z "${DNSRV}" ]
101 then
102 DNSSERV="DNSserv=${DNSRV}"
103 fi
104 if [ ! -z "${DNAME}" ]
105 then
106 DNSDMAIN="DNSdmain=\"${DNAME}\""
107 fi
108 if [ ! -z "${DNSSERV}" -o ! -z "${DNSDMAIN}" ]
109 then
110 return 0
111 fi
112 return 1
113 }
114
115 #
116 # Set variables.
117 #
118 SRVNAME=`uname -n`
119 SRVADDR=`get_server_ip`
120 DHCP_DEFAULTS=/etc/inet/dhcpsvc.conf
121
122 #
123 # If the DHCP server is running, kill it.
124 #
125 pkill -x -u 0 in.dhcpd
126
127 #
128 # Make sure to clean up before we configure.
129 #
130 /usr/sbin/dhcpconfig -U -f -x >>${OUTFILE} 2>&1
131 rm -f ${DHCP_DEFAULTS} >>${OUTFILE} 2>&1
132
133 #
134 # Config.
135 #
136 /usr/sbin/dhcpconfig -D -r ${DHCPRSRC} -p ${DHCPPATH} >>${OUTFILE} 2>&1
137 RET=$?
138 if [ "${RET}" != "0" ]
139 then
140 echo "Error configuring DHCP = ${RET}"
141 echo "${TESTNAME} - Test failed!"
142 exit 1
143 fi
144
145 #
146 # Verify that the dhcp defaults file was created.
147 #
148 if [ ! -f ${DHCP_DEFAULTS} ]
149 then
150 echo "${DHCP_DEFAULTS} not created."
151 echo "${TESTNAME} - Test failed!"
152 exit 1
153 fi
154
155 #
156 # Verify that the run mode was defined in the defaults file
157 #
158 DEFLINE=`grep "RUN_MODE=server" ${DHCP_DEFAULTS}`
159 if [ -z "${DEFLINE}" ]
160 then
161 echo "RUN_MODE not set correctly in ${DHCP_DEFAULTS}"
162 echo "${TESTNAME} - Test failed!"
163 exit 1
164 fi
165
166 #
167 # Verify that the datastore resource was defined in the defaults file
168 #
169 DEFLINE=`grep "RESOURCE=${DHCPRSRC}" ${DHCP_DEFAULTS}`
170 if [ -z "${DEFLINE}" ]
171 then
172 echo "RESOURCE not set correctly in ${DHCP_DEFAULTS}"
173 echo "${TESTNAME} - Test failed!"
174 exit 1
175 fi
176
177 #
178 # Verify that the datastore path was defined in the defaults file
179 #
180 DEFLINE=`grep "PATH=${DHCPPATH}" ${DHCP_DEFAULTS}`
181 if [ -z "${DEFLINE}" ]
182 then
183 echo "PATH not set correctly in ${DHCP_DEFAULTS}"
184 echo "${TESTNAME} - Test failed!"
185 exit 1
186 fi
187
188 #
189 # Verify that the dhcptab data was created.
190 #
191 DATAFILE=/tmp/${TESTNAME}.data.$$
192 /usr/sbin/dhtadm -r ${DHCPRSRC} -p ${DHCPPATH} -P >${DATAFILE} 2>>${OUTFILE}
193 RET=$?
194 if [ "${RET}" != "0" ]
195 then
196 rm ${DATAFILE}
197 echo "Error displaying dhcptab = ${RET}"
198 echo "${TESTNAME} - Test failed!"
199 exit 1
200 fi
201
202 #
203 # Verify that the Locale symbol is defined in the dhcptab.
204 #
205 LOCALE=`grep "^Locale" ${DATAFILE}`
206 if [ -z "${LOCALE}" ]
207 then
208 rm ${DATAFILE}
209 echo "Locale macro does not exist in dhcptab"
210 echo "${TESTNAME} - Test failed!"
211 exit 1
212 fi
213
214 #
215 # Verify that the server macro is defined in the dhcptab.
216 #
217 SERVER_MACRO=`grep "^${SRVNAME}" ${DATAFILE}`
218 if [ -z "${SERVER_MACRO}" ]
219 then
220 rm ${DATAFILE}
221 echo "Server macro does not exist in dhcptab"
222 echo "${TESTNAME} - Test failed!"
223 exit 1
224 fi
225 rm ${DATAFILE}
226
227 #
228 # Grab the server macro definition
229 #
230 MACRO_DEFINITION=$(get_value ${SERVER_MACRO})
231
232 #
233 # Verify that the Locale symbol is defined as part of the macro definition
234 #
235 SRCH=":Include=Locale:"
236 macro_find_and_replace
237
238 #
239 # Verify that the LeaseTim symbol is defined as part of the macro definition
240 #
241 SRCH=":LeaseTim=86400:"
242 macro_find_and_replace
243
244 #
245 # Verify that the LeaseNeg symbol is defined as part of the macro definition
246 #
247 SRCH=":LeaseNeg:"
248 macro_find_and_replace
249
250 #
251 # Verify that the Timeserv symbol is defined as part of the macro definition
252 #
253 SRCH=":Timeserv=${SRVADDR}:"
254 macro_find_and_replace
255
256 #
257 # Go get the DNS settings
258 #
259 get_dns_parms
260
261 #
262 # Verify that the DNSdmain symbol is defined as part of the macro definition
263 #
264 SRCH=:${DNSDMAIN}:
265 macro_find_and_replace
266
267 #
268 # Verify that the DNSserv symbol is defined as part of the macro definition
269 #
270 SRCH=:${DNSSERV}:
271 macro_find_and_replace
272
273 #
274 # Verify that all symbols have been accounted for
275 #
276 if [ "${MACRO_DEFINITION}" != ":" ]
277 then
278 echo "Server macro definition has invalid extra symbols: ${MACRO_DEFINITION}"
279 echo "${TESTNAME} - Test failed!"
280 exit 1
281 fi
282
283 #
284 # Verify that the dhcp server was started.
285 #
286 PID=`pgrep -x -u 0 in.dhcpd`
287 if [ -z "${PID}" ]
288 then
289 echo "DHCP Server was not started."
290 echo "${TESTNAME} - Test failed!"
291 exit 1
292 fi
293
294 echo "${TESTNAME} - Test passed."
295 exit 0