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 # Verify that the macro is not already defined.
59 #
60 DATAFILE=/tmp/${TESTNAME}.data.$$
61 /usr/sbin/dhtadm -r ${DHCPRSRC} -p ${DHCPPATH} -P >${DATAFILE} 2>>${OUTFILE}
62 RET=$?
63 if [ "${RET}" != "0" ]
64 then
65 rm ${DATAFILE}
66 echo "Error displaying dhcptab = ${RET}"
67 echo "${TESTNAME} - Test failed!"
68 exit 1
69 fi
70
71 MACRO=`grep "^TestMac" ${DATAFILE}`
72 if [ ! -z "${MACRO}" ]
73 then
74 rm ${DATAFILE}
75 echo "Macro already exists in dhcptab"
76 echo "${TESTNAME} - Test failed!"
77 exit 1
78 fi
79 rm ${DATAFILE}
80
81 #
82 # Create the macro.
83 #
84 /usr/sbin/dhtadm -r ${DHCPRSRC} -p ${DHCPPATH} -A -m TestMac -d ':Rootpath=/usr:' >>${OUTFILE} 2>&1
85 RET=$?
86 if [ "${RET}" != "0" ]
87 then
88 echo "Error creating macro = ${RET}"
89 echo "${TESTNAME} - Test failed!"
90 exit 1
91 fi
92
93 #
94 # Verify that the macro is defined in the dhcptab.
95 #
96 /usr/sbin/dhtadm -r ${DHCPRSRC} -p ${DHCPPATH} -P >${DATAFILE} 2>>${OUTFILE}
97 RET=$?
98 if [ "${RET}" != "0" ]
99 then
100 rm ${DATAFILE}
101 echo "Error displaying dhcptab = ${RET}"
102 echo "${TESTNAME} - Test failed!"
103 exit 1
104 fi
105
106 MACRO=`grep "^TestMac" ${DATAFILE}`
107 if [ -z "${MACRO}" ]
108 then
109 rm ${DATAFILE}
110 echo "Macro not added to dhcptab."
111 echo "${TESTNAME} - Test failed!"
112 exit 1
113 fi
114 rm ${DATAFILE}
115
116 #
117 # Grab the macro definition from the dhcptab
118 #
119 MACRO_DEFINITION=$(get_value ${MACRO})
120
121 #
122 # Verify that the defintion was defined correctly
123 #
124 SRCH=":Rootpath=\/usr:"
125 macro_find_and_replace
126
127 #
128 # Verify that there was nothing else in the definition
129 #
130 if [ "${MACRO_DEFINITION}" != ":" ]
131 then
132 echo "Macro definition has invalid extra symbols: ${MACRO_DEFINITION}"
133 echo "${TESTNAME} - Test failed!"
134 exit 1
135 fi
136
137 echo "${TESTNAME} - Test passed."
138 exit 0