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 2009 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
26 #
27
28 NAME=$(basename $0)
29
30 . $STF_SUITE/include/sharemnt.kshlib
31 . $STC_GENUTILS/include/nfs-tx.kshlib
32
33 export STC_GENUTILS_DEBUG=$STC_GENUTILS_DEBUG:$SHAREMNT_DEBUG
34 [[ :${SHAREMNT_DEBUG}: == *:${NAME}:* \
35 || :${SHAREMNT_DEBUG}: == *:all:* ]] && set -x
36
37 ################################################################################
38 #
39 # __stc_assertion_start
40 #
41 # ID: access_test
42 #
43 # DESCRIPTION:
44 # For the mount and export the SERVER's filesystems with
45 # ro|rw|root=access-list
46 #
47 # STRATEGY:
48 # verify the share and mount/automount behaviors
49 #
50 # TESTABILITY: explicit
51 #
52 # TEST_AUTOMATION_LEVEL: automated
53 #
54 # __stc_assertion_end
55 #
56 ################################################################################
57
58 # Function to do root permission testing in the NFS mount point
59 # and auto mount point
60 # Usage: do_root_test exp_root exp_rw auto_mntdir
61 #
62 function do_root_test {
63 Fname=do_root_test
64 [[ :$SHAREMNT_DEBUG: == *:${NAME}:* \
65 || :${SHAREMNT_DEBUG}: == *:all:* ]] && set -x
66 typeset exp_root=${1}
67 typeset exp_rw=${2}
68 typeset auto_mntdir=${3}
69
70 for mntdir in $MNTDIR $auto_mntdir; do
71 echo "Doing ROOT access testing at $mntdir ... \c"
72 ls -lv $mntdir/nopermfile 2> $STF_TMPDIR/ls.out.$$ | \
73 grep "nopermfile" > /dev/null 2>&1
74 if [[ $? != 0 ]]; then
75 echo "\n$Fname: READDIR of <nopermfile> in $mntdir failed"
76 cat $STF_TMPDIR/ls.out.$$
77 cleanup $STF_FAIL
78 fi
79 typeset -i TLine=22
80 typeset -i fline
81 fline=$(wc -l 2> $STF_TMPDIR/wc.out.$$ < $mntdir/nopermfile)
82 [[ $? == 0 ]] && rc=0 || rc=1
83 if [[ $rc != $exp_root ]]; then
84 echo "\n$Fname: not the expected result: "
85 if [[ $rc == 0 ]]; then
86 echo "\texpected READ of <nopermfile> failed"
87 else
88 echo "\texpected READ of <nopermfile> successful"
89 cat $STF_TMPDIR/wc.out.$$
90 fi
91 cleanup $STF_FAIL
92 fi
93
94 if (( $rc == 0 && TLine != fline )); then
95 echo "\n$Fname: number of line of nopermfile is wrong"
96 echo "\t it is $fline instead of $TLine"
97 cleanup $STF_FAIL
98 fi
99
100 if [[ $exp_rw == "rw" ]]; then
101 echo "Checking root can create new file at $mntdir if the \c"
102 echo "client is granted with rw access;"
103 echo "and checking the created file is owned by root if it \c"
104 echo "is granted with root access ..."
105 typeset TData="ROOT WRITE tests at $mntdir"
106 echo "$TData" > $mntdir/tfile.$$ 2> $STF_TMPDIR/wr.out.$$
107 if [[ $? != 0 ]]; then
108 echo "\n$Fname: WRITE to $mntdir failed"
109 cat $STF_TMPDIR/wr.out.$$
110 cleanup $STF_FAIL
111 fi
112 owner=$(ls -l $mntdir/tfile.$$ 2> $STF_TMPDIR/ls.out.$$ | \
113 awk '{print $3}')
114 if [[ $? != 0 ]]; then
115 echo "\n$Fname: READDIR of <tfile.$$> in $mntdir failed"
116 cat $STF_TMPDIR/ls.out.$$
117 cleanup $STF_FAIL
118 fi
119 [[ $owner == "root" ]] && rc=0 || rc=1
120 if [[ $rc != $exp_root ]]; then
121 echo "\n$Fname: not the expected result: "
122 if [[ $rc == 0 ]]; then
123 echo "\texpected the file owner is not root"
124 else
125 echo "\texpected the file owner is root"
126 fi
127 ls -l $mntdir/tfile.$$
128 cleanup $STF_FAIL
129 fi
130 fi
131 done
132 echo "OK"
133 }
134
135 USAGE="Usage: $0 Test_name Share_opt Mnt_opts Shrexp_opt Root_opt"
136
137 if (( $# < 5 )); then
138 echo "$USAGE"
139 exit $STF_UNRESOLVED
140 fi
141
142 typeset Tname=$1
143 typeset Shropt=$2
144 typeset Mntopts=$3
145 typeset Shrexpopt=$4
146 typeset Rootopt=$5
147 # Rootopt=root --> have root permission
148 # Rootopt=noroot --> don't have root permission
149
150 # Check TX related info
151 check_for_cipso "$SHRDIR" "$MNTDIR" "$Mntopts" || return $STF_UNSUPPORTED
152
153 [[ ${Mntopts%,*} == "ro" ]] && clnt_opt=ro || clnt_opt=rw
154
155 # get what type operation is valid on client
156 [[ $Shrexpopt == "rw" && $clnt_opt == "rw" ]] && exp_opt=rw || exp_opt=ro
157
158 # whether grant root access on client
159 [[ $Rootopt == "root" ]] && root_opt=0 || root_opt=1
160
161 share_check "$Shropt"
162 domount_check "$Mntopts" "$Shropt"
163 automount_check "$Mntopts" "$Shropt" "ACCESS"
164
165 typeset an=$(echo "$Mntopts" | sed -e 's/sec=//g' -e 's/://g')
166 do_root_test $root_opt $exp_opt "$AUTOIND/SM_ACCESS_$$_$an"
167
168 if [[ $exp_opt == "ro" ]]; then
169 do_ro_test
170
171 set -A molist remount remount,rw rw,remount
172 domount_check ${molist[$((RANDOM % 3 ))]}
173 echo $Shropt | grep -w ro > /dev/null 2>&1
174 (( $? != 0 )) && do_rw_test
175 else
176 do_rw_test
177
178 set -A molist remount,ro ro,remount
179 do_neg_mount_check ${molist[$((RANDOM % 2 ))]}
180 fi
181
182 unmount_check
183
184 echo "$NAME: testing complete - Result PASS"
185 cleanup $STF_PASS