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 #ident "%Z%%M% %I% %E% SMI"
25 #
26 # Copyright (c) 2001 by Sun Microsystems, Inc.
27 # All rights reserved.
28 #
29
30 #
31 # Source the utilities.
32 #
33 DIRNAME=`dirname $0`
34 . ${DIRNAME}/utilities.san
35
36 #
37 # Process the input arguments.
38 #
39 VALIDOPTS=dr:p:
40 process_args $@
41
42 #
43 # In case the tester wants to see script output, allow them
44 # to run in debug mode.
45 #
46 TESTNAME=`basename $0`
47 if [ ! -z "${DEBUG}" ]
48 then
49 OUTFILE=/tmp/${TESTNAME}.$$
50 echo "Output from test: ${TESTNAME}" >${OUTFILE}
51 echo >>${OUTFILE}
52 echo "debug output can be found at ${OUTFILE}"
53 else
54 OUTFILE=/dev/null
55 fi
56
57 #
58 # Set NISSERV and NISDMAIN if NIS or NIS+ in YP compat mode.
59 # Returns 0 if these variables are set, nonzero otherwise.
60 #
61 get_nis_parms()
62 {
63 unset NISSERV
64 unset NISDMAIN
65 NSSHOSTS=`grep '^hosts:' /etc/nsswitch.conf`
66 for TMP in ${NSSHOSTS}
67 do
68 case "${TMP}" in
69 "nis")
70 ypwhich >/dev/null 2>&1
71 if [ ${?} -eq 0 ]
72 then
73 X=`ypwhich -m hosts`
74 NISSERV=""
75 for NSERV in `ypmatch ${X} hosts.byname | awk '{ print $1 }'`
76 do
77 if [ -z "${NISSERV}" ]
78 then
79 NISSERV=${NSERV}
80 else
81 NISSERV="${NISSERV} ${NSERV}"
82 fi
83 done
84 unset NSERV
85 NISDMAIN=`domainname`
86 fi
87 ;;
88 esac
89 unset TMP
90 done
91 }
92
93 #
94 # Set variables.
95 #
96 SRVNAME=`uname -n`
97 SRVADDR=`get_server_ip`
98
99 #
100 # Determine subnet, netmask, and broadcast address.
101 #
102 get_default_class ${SRVADDR} | read DEFNET DEFMASK
103 SUBNET=`get_netmask ${SRVADDR}`
104 if [ -z "${SUBNET}" ]
105 then
106 if [ "${DEFNET}" != "${SRVADDR}" ]
107 then
108 # likely subnetted/supernetted.
109 print - "\n\n###\tWarning\t###\n"
110 print - "Network ${SRVADDR} is netmasked, but no entry was found in the 'netmasks'\ntable; please update the 'netmasks' table in the appropriate\nnameservice before continuing (see /etc/nsswitch.conf).\n" >&2
111 return 1
112 else
113 # use the default.
114 SUBNET="${DEFMASK}"
115 fi
116 fi
117
118 BCAST=`get_bcast_addr ${SRVADDR} ${SUBNET}`
119 SUBNETADDR=`get_subnet_addr ${SRVADDR} ${SUBNET}`
120
121 #
122 # Make sure to clean up before we configure.
123 #
124 /usr/sbin/pntadm -r ${DHCPRSRC} -p ${DHCPPATH} -R ${SUBNETADDR} >>${OUTFILE} 2>&1
125 /usr/sbin/dhtadm -r ${DHCPRSRC} -p ${DHCPPATH} -D -m ${SUBNETADDR} >>${OUTFILE} 2>&1
126
127 #
128 # Configure.
129 #
130 /usr/sbin/dhcpconfig -N ${SUBNETADDR} >>${OUTFILE} 2>&1
131 RET=$?
132 if [ "${RET}" != "0" ]
133 then
134 echo "Error configuring ${SUBNETADDR} table = ${RET}"
135 echo "${TESTNAME} - Test failed!"
136 exit 1
137 fi
138
139 #
140 # Verify that the network table was created.
141 #
142 NETTABS=`/usr/sbin/pntadm -r ${DHCPRSRC} -p ${DHCPPATH} -L 2>>${OUTFILE}`
143 NETTAB=`echo ${NETTABS} | fgrep ${SUBNETADDR}`
144 if [ -z ${NETTAB} ]
145 then
146 echo "Network table for ${SUBNETADDR} not created."
147 echo "${TESTNAME} - Test failed!"
148 exit 1
149 fi
150
151 #
152 # Verify that the network macro was created.
153 #
154 DATAFILE=/tmp/${TESTNAME}.data.$$
155 /usr/sbin/dhtadm -r ${DHCPRSRC} -p ${DHCPPATH} -P >${DATAFILE} 2>>${OUTFILE}
156 RET=$?
157 if [ "${RET}" != "0" ]
158 then
159 rm ${DATAFILE}
160 echo "Error displaying dhcptab = ${RET}"
161 echo "${TESTNAME} - Test failed!"
162 exit 1
163 fi
164
165 NETWORK_MACRO=`grep "^${SUBNETADDR}" ${DATAFILE}`
166 if [ -z "${NETWORK_MACRO}" ]
167 then
168 rm ${DATAFILE}
169 echo "Server macro does not exist in dhcptab"
170 echo "${TESTNAME} - Test failed!"
171 exit 1
172 fi
173 rm ${DATAFILE}
174
175 #
176 # Grab the server macro definition
177 #
178 MACRO_DEFINITION=$(get_value ${NETWORK_MACRO})
179
180 #
181 # Verify that the Subnet symbol is defined as part of the macro definition
182 #
183 SRCH=":Subnet=${SUBNET}:"
184 macro_find_and_replace
185
186 #
187 # Verify that the RDiscvyF symbol is defined as part of the macro definition
188 #
189 SRCH=":RDiscvyF=1:"
190 macro_find_and_replace
191
192 #
193 # Verify that the Broadcst symbol is defined as part of the macro definition
194 #
195 SRCH=":Broadcst=${BCAST}:"
196 macro_find_and_replace
197
198 #
199 # Get the NIS info
200 #
201 get_nis_parms
202
203 #
204 # Verify that the DNSdmain symbol is defined as part of the macro definition
205 #
206 if [ ! -z "${NISDMAIN}" ]
207 then
208 SRCH=":NISdmain=\"${NISDMAIN}\":"
209 macro_find_and_replace
210 fi
211
212 if [ ! -z "${NISSERV}" ]
213 then
214 SRCH=":NISservs=${NISSERV}:"
215 macro_find_and_replace
216 fi
217
218 #
219 # Verify that all symbols have been accounted for
220 #
221 if [ "${MACRO_DEFINITION}" != ":" ]
222 then
223 echo "Network macro definition has invalid extra symbols: ${MACRO_DEFINITION}"
224 echo "${TESTNAME} - Test failed!"
225 exit 1
226 fi
227
228 echo "${TESTNAME} - Test passed."
229 exit 0