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 # uidmapping_pos04.ksh
28 # This file contains positive testcases for the setup that domains
29 # mismatch. They are:
30 #
31 # {a} - create a file and verify the file was created and with
32 # correct user id on both server side and client side
33
34 [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
35
36 trap "cleanup" EXIT
37 trap "exit 1" HUP INT QUIT PIPE TERM
38
39 NAME=`basename $0`
40 UIDMAPENV="./uid_proc"
41 UNINITIATED=6
42
43 # set up script running environment
44 if [ ! -f $UIDMAPENV ]; then
45 echo "$NAME: UIDMAPENV[$UIDMAPENV] not found; test UNINITIATED."
46 exit $UNINITIATED
47 fi
48 . $UIDMAPENV
49
50 ASSERTIONS=${ASSERTIONS:-"a b c"}
51 DESC="client and server mapid domains mismatch, "
52
53 function setup
54 {
55 [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
56
57 # run test cases on shared directory
58 cd $TESTDIR
59
60 # set up client domain
61 Ndomain="nonexistent.at.all"
62 set_local_domain $Ndomain 2>$ERRLOG
63 ckreturn $? "could not set up domain $Ndomain on client" \
64 $ERRLOG "ERROR" || return 1
65 }
66
67 function cleanup
68 {
69 [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
70
71 # we don't want user can interrupt cleanup procedure
72 trap '' HUP INT QUIT PIPE TERM
73
74 # remove testfile
75 rm -f $TESTFILE 2>$ERRLOG
76 ckreturn $? "could not remove $TESTFILE" $ERRLOG "WARNING"
77
78 # Change to other directory
79 cd $TESTROOT
80
81 restore_local_domain 2>$ERRLOG
82 ckreturn $? "could not restore local domain" $ERRLOG "WARNING"
83
84 # remove temporary file
85 rm -f $ERRLOG
86 ckreturn $? "could not remove $ERRLOG" /dev/null "WARNING"
87 }
88
89 # Assertions
90
91 # a: create NFS file with mismatch mapid domain
92 function as_a
93 {
94 [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
95
96 exp=0
97 desc="$DESC""create a file over NFS as root, "
98 desc="$desc""file is created successfully, "
99 desc="$desc""check it on server side, file owner is root, "
100 desc="$desc""check it on client side, file owner is nobody"
101 assertion a "$desc" $exp
102
103 touch $TESTFILE 2>$ERRLOG
104 res=$?
105
106 if [ $exp -ne $res ]; then
107 # print error message
108 ckres2 uidmapping "$res" $exp "could not create file"
109 return $FAIL
110 fi
111
112 # check it on server side
113 exp=0
114 execute $SERVER root "ls -l $ROOTDIR/$TESTFILE" 1>/dev/null 2>$ERRLOG
115 res=$?
116
117 if [ $exp -ne $res ]; then
118 ckres2 uidmapping "$res" $exp "could not found file on server"
119 return $FAIL
120 fi
121
122 # check file owner on server side
123 exp=0
124 execute $SERVER root "ls -l $ROOTDIR/$TESTFILE \
125 | awk \"{print \\\$3, \\\$4}\" \
126 | grep root.*root" 1>/dev/null 2>$ERRLOG
127 res=$?
128
129 if [ $exp -ne $res ]; then
130 ckres2 uidmapping "$res" $exp "wrong file owner/group"
131 return $FAIL
132 fi
133
134 # check file owner on client side
135 exp="nobody"
136 res=$(get_val $OWN $TESTFILE)
137 rm -f $TESTFILE
138 ckres2 uidmapping "$res" $exp "unexpected file owner"
139 }
140
141 # b: create NFS directory with mismatched mapid domain
142 function as_b
143 {
144 [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
145
146 exp=0
147 desc="$DESC""create a directory over NFS as root, "
148 desc="$desc""file is created successfully, "
149 desc="$desc""check it on server side, file owner is root, "
150 desc="$desc""check it on client side, file owner is nobody"
151 assertion b "$desc" $exp
152
153 typeset TESTDIR=uidmapping.$$.testdir
154 mkdir $TESTDIR 2>$ERRLOG
155 ckres2 -s mkdir $? $exp "could not create directory" $ERRLOG \
156 || return $FAIL
157
158 # check it on server side
159 exp=0
160 tmp=$(execute $SERVER root "ls -ld $ROOTDIR/$TESTDIR" 2>$ERRLOG)
161 ckres2 -s "ls" $? $exp "could not found directory on server" $ERRLOG \
162 || return $FAIL
163
164 # check file owner on server side
165 exp=0
166 echo $tmp | awk '{print $3, $4}' | grep root.*root 1>/dev/null 2>&1
167 ckres2 -s "ls" $? $exp "incorrect file owner" || return $FAIL
168
169 # check file owner on client side
170 exp="nobody"
171 res=$(ls -ld $TESTDIR \
172 | awk '{print $3}' 2>&1)
173 rm -rf $TESTDIR
174 ckres2 uidmapping "$res" $exp "unexpected file owner"
175 }
176
177 # c: create attribute file over NFS with mismatch mapid domain
178 function as_c
179 {
180 [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
181
182 exp=0
183 desc="$DESC""create a attribute file over NFS as root, "
184 desc="$desc""file is created successfully, "
185 desc="$desc""check it on server side, file owner is root, "
186 desc="$desc""check it on client side, file owner is nobody"
187 assertion c "$desc" $exp
188
189 # create a normal file
190 touch $TESTFILE 2>$ERRLOG
191 ckreturn $? "failed to create $TESTFILE" $ERRLOG "UNRESOLVED" ||
192 return $UNRESOLVED
193
194 ATTRFILE=$NAME.$$.attr
195 # create a attribute file for the above file
196 runat $TESTFILE touch $ATTRFILE > $ERRLOG
197 ckres2 -s runat $? 0 "failed to create attribute file" \
198 $ERRLOG || return $FAIL
199
200 # check it on server side
201 tmp=$(execute $SERVER root "runat $ROOTDIR/$TESTFILE ls -l $ATTRFILE" \
202 2>$ERRLOG)
203 ckres2 -s execute $? 0 "attr file not exist" $ERRLOG \
204 || return $FAIL
205
206 # check file owner on server side
207 echo $tmp | awk '{print $3, $4}' | grep root.*root >/dev/null 2>&1
208 ckres2 -s execute $? 0 "incorrect file owner on server side" \
209 || return $FAIL
210
211 # check it on client side
212 exp="nobody"
213 res=$(runat $TESTDIR/$TESTFILE ls -l $ATTRFILE \
214 | awk '{print $3}' 2>&1)
215 rm -f $TESTFILE
216 ckres2 runat "$res" $exp "unexpected file owner" || return $FAIL
217 }
218
219 # setup
220 setup || return 1
221
222 # main loop
223 for i in $ASSERTIONS
224 do
225 as_$i || print_state
226 done