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 . ${STF_SUITE}/include/nfsgen.kshlib
29 . ${STF_SUITE}/tests/delegation/include/delegation.kshlib
30
31 NAME=$(basename $0)
32 typeset prog=$STF_SUITE/bin/file_operator
33 typeset chg_usr_exec=$STF_SUITE/bin/chg_usr_exec
34
35 [[ :$NFSGEN_DEBUG: = *:${NAME}:* \
36 || :${NFSGEN_DEBUG}: = *:all:* ]] && set -x
37
38 function cleanup {
39 retcode=$1
40 rm -f $MNTDIR/testfile.$$ $STF_TMPDIR/file_operator.*.$$
41 exit $retcode
42 }
43
44 echo "open a file RDONLY, get read delegation"
45 echo "then reopen the file RDWR as a different user, get write delegation"
46
47 # create test file
48 RUN_CHECK create_file_nodeleg $MNTDIR/testfile.$$ || cleanup $STF_UNRESOLVED
49
50 # read test file over NFS, check delegation type
51 $prog -R -c -d -o 0 -B "1 1 -1" $MNTDIR/testfile.$$ \
52 > $STF_TMPDIR/file_operator.outR.$$ 2>&1
53 deleg_type=$(grep "return_delegation_type" $STF_TMPDIR/file_operator.outR.$$ \
54 | nawk -F\= '{print $2'})
55
56 if [[ $deleg_type -ne $RD ]]; then
57 print -u2 "unexpected delegation type($deleg_type) when reading file"
58 cat $STF_TMPDIR/file_operator.outR.$$
59 cleanup $STF_FAIL
60 fi
61
62 # write test file over NFS as differnt user, check delegation type
63 cd $MNTDIR
64 chgusr_exec $DTESTUSER1 "$prog -W -c -d -o 4 -B \"1 1 -1\" testfile.$$" \
65 > $STF_TMPDIR/file_operator.outW.$$ 2>&1
66 deleg_type=$(grep "return_delegation_type" $STF_TMPDIR/file_operator.outW.$$ \
67 | nawk -F\= '{print $2'})
68
69 if [[ $deleg_type -ne $WR ]]; then
70 print -u2 "unexpected delegation type($deleg_type) when writing file"
71 cat $STF_TMPDIR/file_operator.outW.$$
72 cleanup $STF_FAIL
73 fi
74
75 # clean up
76 cleanup $STF_PASS