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 
  34 [[ :$_NFS_STF_DEBUG: = *:${NAME}:* \
  35         || :${_NFS_STF_DEBUG}: = *:all:* ]] && set -x
  36 
  37 function cleanup {
  38         retcode=$1
  39         rm -f $MNTDIR/testfile.$$ $STF_TMPDIR/file_operator.*
  40         exit $retcode
  41 }
  42 
  43 echo "open a file RDONLY, get read delegation then try to reopen the file"
  44 echo "as a differnt user which has no permission, verify it fails"
  45 
  46 cd $MNTDIR
  47 # create test file and set its permission
  48 RUN_CHECK create_file_nodeleg testfile.$$ || cleanup $STF_UNRESOLVED
  49 RUN_CHECK chown $DTESTUID1 testfile.$$ || cleanup $STF_UNRESOLVED
  50 RUN_CHECK chmod 700 testfile.$$ || cleanup $STF_UNRESOLVED
  51 
  52 # read test file over NFS, check delegation type
  53 chgusr_exec $DTESTUSER1 "$prog -R -c -d -o 0 -B \"1 1 -1\" testfile.$$" \
  54         > $STF_TMPDIR/file_operator.outR.$$ 2>&1
  55 deleg_type=$(grep "return_delegation_type" $STF_TMPDIR/file_operator.outR.$$ \
  56         | nawk -F\= '{print $2'})
  57 if [[ $deleg_type -ne $RD ]]; then
  58         print -u2 "unexpected delegation type($deleg_type) when reading file"
  59         cleanup $STF_FAIL
  60 fi
  61 
  62 # read test file as a different user, expect it fails
  63 RUN_CHECKNEG chgusr_exec $DTESTUSER2 "cat testfile.$$ > /dev/null" \
  64         || cleanup $STF_FAIL
  65 
  66 # clean up 
  67 cleanup $STF_PASS