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 # the file is designed for "get delegation" tests on multi-clients
  29 # setup. It it called in the following way:
  30 #
  31 #    getdeleg <testfile> <remote_cmd> <local_cmd> <deleg_type>
  32 #
  33 # the script will first create $testfile, and execute $remote_cmd,
  34 # and then execute $local_cmd and verify the expected delegation
  35 # is granted.
  36 
  37 . ${STF_SUITE}/include/nfsgen.kshlib
  38 . ${STF_SUITE}/tests/delegation/include/delegation.kshlib
  39 
  40 NAME=$(basename $0)
  41 [[ :$NFSGEN_DEBUG: = *:${NAME}:* \
  42         || :${NFSGEN_DEBUG}: = *:all:* ]] && set -x
  43 
  44 local_testfile=$1
  45 remote_cmd=$2
  46 local_cmd=$3
  47 dtype=$4
  48 run_remote_on_backgd=$5
  49 typeset pid
  50 
  51 function cleanup {
  52         retcode=$1
  53         RSH root $CLIENT2 "pkill file_operator"
  54         rm -f $local_testfile $STF_TMPDIR/local.out.$$ $STF_TMPDIR/$NAME.*
  55         exit $retcode
  56 }
  57 
  58 remote_cmdname=$(echo $remote_cmd | cut -d\  -f1)
  59 remote_cmdname=$(basename $remote_cmdname)
  60 
  61 # create test file
  62 RUN_CHECK create_file_nodeleg $local_testfile || cleanup $STF_UNRESOLVED
  63 
  64 if (( $run_remote_on_backgd == 1 )); then 
  65         RSH root $CLIENT2 "$remote_cmd > $SRV_TMPDIR/$NAME.remote_cmd.$$" \
  66                 > $STF_TMPDIR/$NAME.err.$$ 2>&1 &
  67         pid=$!
  68         
  69         # make sure the remote_cmd is ready
  70         wait_now 100 "RSH root $CLIENT2 grep I_am_ready $SRV_TMPDIR/$NAME.remote_cmd.$$" \
  71                 > /dev/null 2>&1
  72         if (( $? != 0 )); then
  73                 echo "remote_command failed to be ready within 100 seconds"
  74                 cat $STF_TMPDIR/$NAME.err.$$
  75                 cleanup $STF_FAIL
  76         fi
  77 else
  78         RSH root $CLIENT2 "$remote_cmd" 
  79         if (( $? != 0 )); then
  80                 printf -u2 "failed to execute \"$remoted_cmd\" on $CLIENT2"
  81                 cleanup $STF_FAIL
  82         fi
  83 fi
  84 
  85 # run local comand, verify the expected delegation is granted 
  86 eval $local_cmd > $STF_TMPDIR/local.out.$$ 2>&1
  87 deleg_type=$(grep "return_delegation_type" $STF_TMPDIR/local.out.$$ \
  88         | nawk -F\= '{print $2'})
  89 if [[ $deleg_type -ne $dtype ]]; then
  90         print -u2 "unexpected delegation type($deleg_type)" 
  91         cat $STF_TMPDIR/local.out.$$
  92         cleanup $STF_FAIL
  93 fi
  94 
  95 # clean up 
  96 cleanup $STF_PASS