1 #! /usr/bin/ksh -p
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 (the "License").
7 # You may not use this file except in compliance with the License.
8 #
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
13 #
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
19 #
20 # CDDL HEADER END
21 #
22
23 #
24 # Copyright 2008 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
26 #
27
28 #
29 # start __stf_assertion__
30 #
31 # ASSERTION: context_039
32 # DESCRIPTION:
33 # should any invalid group names be chosen in the listing of supplemental
34 # groups then the service shall be transitioned to the maintenance state.
35 #
36 # end __stf_assertion__
37 #
38
39 . ${STF_TOOLS}/include/stf.kshlib
40 . ${STF_SUITE}/include/gltest.kshlib
41 . ${STF_SUITE}/include/svc.startd_config.kshlib
42 . ${STF_SUITE}/tests/svc.startd/include/svc.startd_common.kshlib
43
44 typeset service_setup=0
45 function cleanup {
46 common_cleanup
47 }
48
49 trap cleanup 0 1 2 15
50
51 readonly ME=$(whence -p ${0})
52 readonly MYLOC=$(dirname ${ME})
53
54 CTX_UID=`getent passwd $ctx_user | cut -f 3 -d:`
55 CTX_GID=`getent group $ctx_group | cut -f 3 -d:`
56
57 typeset SUPPGROUPS=
58 typeset ngroups=0
59 typeset atgr=0
60
61 echo "--INFO: acquiring the names of at most 5 groups"
62 while [ $ngroups -lt 5 -a $atgr -lt 5000 ]; do
63 gn=$(getent group $atgr | cut -d: -f 1)
64 if [ -n "$gn" ]; then
65 ngroups=$((ngroups + 1))
66 if [ -z "$SUPPGROUPS" ]; then
67 SUPPGROUPS=$gn
68 else
69 SUPPGROUPS="$SUPPGROUPS,$gn"
70 fi
71 fi
72 atgr=$((atgr + 1))
73 done
74
75 # Find an invalid group
76 while [ $ngroups -lt 20 ]; do
77 gn=$(getent group gbogus$ngroups)
78 if [ -z "$gn" ]; then
79 if [ -z "$SUPPGROUPS" ]; then
80 # yeesh, this should not have happened
81 SUPPGROUPS=gbogus$ngroups
82 else
83 SUPPGROUPS="$SUPPGROUPS,gbogus$ngroups"
84 fi
85 break
86 fi
87 ngroups=$((ngroups + 1))
88 done
89
90 DATA=$MYLOC
91
92 readonly registration_template=$DATA/service_039.xml
93
94 extract_assertion_info $ME
95
96 # make sure that the svc.startd is running
97 verify_daemon
98 if [ $? -ne 0 ]; then
99 echo "--DIAG: $assertion: svc.startd is not executing. Cannot "
100 echo " continue"
101 exit $STF_UNRESOLVED
102 fi
103
104 # Make sure the environment is clean - the test service isn't running
105 echo "--INFO: Cleanup any old $test_FMRI state"
106 service_cleanup $test_service
107 if [ $? -ne 0 ]; then
108 echo "--DIAG: $assertion: cleanup of a previous instance failed"
109 exit $STF_UNRESOLVED
110 fi
111
112 echo "--INFO: create world read/writeable log file for the service"
113 rm -f $service_log
114 touch $service_log
115 if [ $? -ne 0 ]; then
116 echo "--DIAG: $assertion: could not create log file"
117 exit $STF_UNRESOLVED
118 fi
119 chmod a+rw $service_log
120 if [ $? -ne 0 ]; then
121 echo "--DIAG: $assertion: could not make log file world writeable"
122 exit $STF_UNRESOLVED
123 fi
124 chmod a+rwx $RUNDIR
125 if [ $? -ne 0 ]; then
126 echo "--DIAG: $assertion: could not make $RUNDIR world rwx"
127 exit $STF_UNRESOLVED
128 fi
129
130 echo "--INFO: generating manifest for importation into repository"
131 manifest_generate $registration_template \
132 TEST_SERVICE=$test_service \
133 TEST_INSTANCE=$test_instance \
134 SERVICE_APP=$service_app \
135 LOGFILE=$service_log \
136 TEST_USER=$CTX_UID \
137 TEST_GROUP=$CTX_GID \
138 TEST_ADDGROUPS="$SUPPGROUPS" \
139 STATEFILE=$service_state > $registration_file
140 manifest_zone_clean $registration_file
141
142 echo "--INFO: Importing service into repository"
143 manifest_purgemd5 $registration_file
144 svccfg -v import $registration_file >$svccfg_errfile 2>&1
145
146 if [ $? -ne 0 ]; then
147 echo "--DIAG: $assertion: Unable to import the service $test_FMRI"
148 echo " error messages from svccfg: \"$(cat $svccfg_errfile)\""
149 exit $STF_UNRESOLVED
150 fi
151 service_setup=1
152
153 echo "--INFO: Wait for $test_FMRI to enter maintenance"
154 service_wait_state $test_FMRI maintenance
155 if [ $? -ne 0 ]; then
156 echo "--DIAG: $assertion: Service $test_FMRI did not go to maintenance"
157 echo " it is in the '$(svcs -H -o STATE $test_FMRI)' state."
158 exit $STF_FAIL
159 fi
160
161 echo "--INFO: Cleaning up service"
162 cleanup
163
164 exit $STF_PASS