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_040
32 # DESCRIPTION:
33 # Should a supplemental group entry contain a group id that does not
34 # exist in the name service then the service shall be executed with that
35 # group ID
36 #
37 # end __stf_assertion__
38 #
39
40 . ${STF_TOOLS}/include/stf.kshlib
41 . ${STF_SUITE}/include/gltest.kshlib
42 . ${STF_SUITE}/include/svc.startd_config.kshlib
43 . ${STF_SUITE}/tests/svc.startd/include/svc.startd_common.kshlib
44
45 typeset service_setup=0
46 function cleanup {
47 common_cleanup
48 }
49
50 trap cleanup 0 1 2 15
51
52 readonly ME=$(whence -p ${0})
53 readonly MYLOC=$(dirname ${ME})
54
55 CTX_UID=`getent passwd $ctx_user | cut -f 3 -d:`
56 CTX_GID=`getent group $ctx_group | cut -f 3 -d:`
57
58 DATA=$MYLOC
59
60 readonly registration_template=$DATA/service_040.xml
61
62 extract_assertion_info $ME
63
64 typeset SUPPGROUPS=
65 typeset ngroups=0
66 typeset atgr=0
67 typeset lostgroup=
68
69 echo "--INFO: acquiring the ids of at most 5 groups"
70 while [ $ngroups -lt 5 -a $atgr -lt 5000 ]; do
71 gn=`getent group $atgr | cut -d: -f 3`
72 if [ -n "$gn" ]; then
73 ngroups=$((ngroups + 1))
74 if [ -z "$SUPPGROUPS" ]; then
75 SUPPGROUPS=$gn
76 else
77 SUPPGROUPS="$SUPPGROUPS,$gn"
78 fi
79 fi
80 atgr=$((atgr + 1))
81 done
82
83 typeset lostg=0
84 # add 2 lost groups
85 while [ $atgr -lt 10000 -a $lostg -lt 2 ]; do
86 gn=$(getent group $atgr)
87 if [ -z "$gn" ]; then
88 if [ -z "$SUPPGROUPS" ]; then
89 # yeesh - only one group
90 SUPPGROUPS=$atgr
91 else
92 SUPPGROUPS="$SUPPGROUPS,$atgr"
93 fi
94 lostg=$((lostg + 1))
95 fi
96 atgr=$((atgr + 1))
97 done
98
99
100 # make sure that the svc.startd is running
101 verify_daemon
102 if [ $? -ne 0 ]; then
103 echo "--DIAG: $assertion: svc.startd is not executing. Cannot "
104 echo " continue"
105 exit $STF_UNRESOLVED
106 fi
107
108 # Make sure the environment is clean - the test service isn't running
109 echo "--INFO: Cleanup any old $test_FMRI state"
110 service_cleanup $test_service
111 if [ $? -ne 0 ]; then
112 echo "--DIAG: $assertion: cleanup of a previous instance failed"
113 exit $STF_UNRESOLVED
114 fi
115
116 echo "--INFO: create world read/writeable log file for the service"
117 rm -f $service_log
118 touch $service_log
119 if [ $? -ne 0 ]; then
120 echo "--DIAG: $assertion: could not create log file"
121 exit $STF_UNRESOLVED
122 fi
123 chmod a+rw $service_log
124 if [ $? -ne 0 ]; then
125 echo "--DIAG: $assertion: could not make log file world writeable"
126 exit $STF_UNRESOLVED
127 fi
128 chmod a+rwx $RUNDIR
129 if [ $? -ne 0 ]; then
130 echo "--DIAG: $assertion: could not make $RUNDIR world rwx"
131 exit $STF_UNRESOLVED
132 fi
133
134 echo "--INFO: generating manifest for importation into repository"
135 manifest_generate $registration_template \
136 TEST_SERVICE=$test_service \
137 TEST_INSTANCE=$test_instance \
138 SERVICE_APP=$service_app \
139 LOGFILE=$service_log \
140 TEST_USER=$CTX_UID \
141 TEST_GROUP=$CTX_GID \
142 TEST_ADDGROUPS="$SUPPGROUPS" \
143 STATEFILE=$service_state > $registration_file
144 manifest_zone_clean $registration_file
145
146 echo "--INFO: Importing service into repository"
147 manifest_purgemd5 $registration_file
148 svccfg -v import $registration_file >$svccfg_errfile 2>&1
149
150 if [ $? -ne 0 ]; then
151 echo "--DIAG: $assertion: Unable to import the service $test_FMRI"
152 echo " error messages from svccfg: \"$(cat $svccfg_errfile)\""
153 exit $STF_UNRESOLVED
154 fi
155 service_setup=1
156
157 echo "--INFO: Wait for $test_FMRI to come online"
158 service_wait_state $test_FMRI online
159 if [ $? -ne 0 ]; then
160 echo "--DIAG: $assertion: Service $test_FMRI did not enter online"
161 echo " It is in the '$(svcs -H -o STATE $test_FMRI)' state."
162 exit $STF_FAIL
163 fi
164
165 echo "--INFO: Verifying supplemental group ID's are correct ($SUPPGROUPS)"
166 line=$(grep_logline_entry $test_service $test_instance start suppgroupids)
167 if [ $? -ne 0 ]; then
168 echo "--DIAG: $assertion: Could not find suppemental group information"
169 echo " in service log"
170 exit $STF_FAIL
171 fi
172
173 if [ "$line" != "$SUPPGROUPS" ]; then
174 echo "--DIAG: $assertion: found supplemental groups '$line'"
175 echo " expected: '$SUPPGROUPS'"
176 exit $STF_FAIL
177 fi
178
179 echo "--INFO: Cleaning up service"
180 cleanup
181
182 exit $STF_PASS