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 # Verify NFsv2/v3 clients unable to crossing NFSv4 server mount points 
  28 #
  29 
  30 [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
  31 
  32 NAME=`basename $0`
  33 CDIR=`pwd`
  34 
  35 # Source for common functions
  36 . $TESTROOT/testsh
  37 
  38 # check for root to run 
  39 is_root $NAME "NFSv2/v3 client crossing server mount points tests."
  40 
  41 TMPmnt=$ZONE_PATH/$NAME.$$
  42 mkdir -m 0777 -p $TMPmnt
  43 
  44 # in case user wants to run IPv6
  45 [[ $TRANSPORT == *6 ]] && tUDP=udp6 || tUDP=udp
  46 
  47 # Start test assertions here
  48 # ----------------------------------------------------------------------
  49 # a: Verify v2 mount of server's exported point, expect successful
  50 function assertion_a
  51 {
  52     [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
  53     ASSERTION="Verify v2 mount of server's exported point, expect successful"
  54     echo "$NAME{a}: $ASSERTION"
  55     SRVPATH=$BASEDIR
  56 
  57     is_cipso "vers=2" $SERVER
  58     if [ $? -eq $CIPSO_NFSV2 ]; then
  59         echo "$NAME{a}: CIPSO NFSv2 is not supported under Trusted Extensions."
  60         echo "\t Test UNSUPPORTED"
  61         return $FAIL
  62     fi
  63 
  64     # Do the mount on the $SRVPATH
  65     mount -o vers=2,rw $SERVER:$SRVPATH $TMPmnt > $TMPDIR/$NAME.mnt.$$ 2>&1
  66     ckreturn $? "mount did not succeed" $TMPDIR/$NAME.mnt.$$
  67     [ $? -ne 0 ] && return $FAIL
  68 
  69     # verify the mount point is access'ble
  70     ls $TMPmnt/$LARGEDIR > $TMPDIR/$NAME.ck.$$ 2>&1
  71     ckreturn $? "unable to access ($TMPmnt/$LARGEDIR)" $TMPDIR/$NAME.ck.$$
  72     [ $? -ne 0 ] && return $FAIL
  73 
  74     # finally umount it
  75     umount $TMPmnt > $TMPDIR/$NAME.umnt.$$ 2>&1
  76     ckreturn $? "umount failed" $TMPDIR/$NAME.umnt.$$
  77     [ $? -ne 0 ] && return $FAIL
  78 
  79     echo "\t Test PASS"
  80 }
  81 
  82 
  83 # b: Verify v3 mount of dir below server's exported point, expect successful
  84 function assertion_b
  85 {
  86     [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
  87     ASSERTION="Verify v3 mount of dir below exported point, expect successful"
  88     echo "$NAME{b}: $ASSERTION"
  89     SRVPATH=$BASEDIR/$DIR0777
  90 
  91     # Do the mount on the $SRVPATH
  92     mount -o vers=3,proto=$tUDP $SERVER:$SRVPATH $TMPmnt \
  93         > $TMPDIR/$NAME.mnt.$$ 2>&1
  94     ckreturn $? "mount did not succeed" $TMPDIR/$NAME.mnt.$$
  95     [ $? -ne 0 ] && return $FAIL
  96 
  97     # verify the mount point is access'ble
  98     cat $TMPmnt/$RWFILE > $TMPDIR/$NAME.ck.$$ 2>&1
  99     ckreturn $? "unable to access ($TMPmnt/$RWFILE)" $TMPDIR/$NAME.ck.$$
 100     [ $? -ne 0 ] && return $FAIL
 101 
 102     # finally umount it
 103     umount $TMPmnt > $TMPDIR/$NAME.umnt.$$ 2>&1
 104     ckreturn $? "umount failed" $TMPDIR/$NAME.umnt.$$
 105     [ $? -ne 0 ] && return $FAIL
 106 
 107     echo "\t Test PASS"
 108 }
 109 
 110 
 111 # c: Verify v3 mount of dir above server's exported point, expect fail
 112 function assertion_c
 113 {
 114     [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
 115     ASSERTION="Verify v3 mount of dir above exported point, expect fail"
 116     echo "$NAME{c}: $ASSERTION"
 117     SRVPATH=`dirname $BASEDIR`
 118 
 119     # Do the mount on the $SRVPATH
 120     mount -o vers=3,noac,ro $SERVER:$SRVPATH $TMPmnt \
 121         > $TMPDIR/$NAME.mnt.$$ 2>&1
 122     if [ $? -eq 0 ]; then
 123         echo "\t Test FAIL: mount v3 succeeded above exported point"
 124         return $FAIL
 125     fi
 126         
 127     # should not be mounted umount it
 128     df $TMPmnt | grep $SERVER > /dev/null 2>&1
 129     if [ $? -eq 0 ]; then
 130         echo "\t Test FAIL: mount failed, but ($TMPmnt) is mounted"
 131         umount $TMPmnt > /dev/null 2>&1
 132         return $FAIL
 133     fi
 134 
 135     echo "\t Test PASS"
 136 }
 137 
 138 
 139 # d: Verify public v3 mount of dir below exported point, expect successful
 140 function assertion_d
 141 {
 142     [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
 143     ASSERTION="public v3 mount of dir below exported point, expect successful"
 144     echo "$NAME{d}: $ASSERTION"
 145     SRVPATH=$PUBTDIR/$DIR0777
 146 
 147     # Do the mount on the $SRVPATH
 148     mount -o vers=3,proto=$tUDP nfs://$SERVER$SRVPATH $TMPmnt \
 149         > $TMPDIR/$NAME.mnt.$$ 2>&1
 150     ckreturn $? "mount nfsURL did not succeed" $TMPDIR/$NAME.mnt.$$
 151     [ $? -ne 0 ] && return $FAIL
 152 
 153     # verify the mount point is access'ble
 154     cat $TMPmnt/$RWFILE > $TMPDIR/$NAME.ck.$$ 2>&1
 155     ckreturn $? "unable to access ($TMPmnt/$RWFILE)" $TMPDIR/$NAME.ck.$$
 156     [ $? -ne 0 ] && return $FAIL
 157 
 158     # finally umount it
 159     umount $TMPmnt > $TMPDIR/$NAME.umnt.$$ 2>&1
 160     ckreturn $? "umount failed" $TMPDIR/$NAME.umnt.$$
 161     [ $? -ne 0 ] && return $FAIL
 162 
 163     echo "\t Test PASS"
 164 }
 165 
 166 
 167 # e: Verify public v3 mount of dir above server's exported point, expect fail
 168 #    if the dir is not "/", otherwise, expect successful
 169 function assertion_e
 170 {
 171     [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
 172     SRVPATH=`dirname $BASEDIR`
 173     [[ $SRVPATH == "/" ]] && expres="successful" || expres="fail"
 174     ASSERTION="Public v3 mount of dir above exported point, expect $expres"
 175     echo "$NAME{e}: $ASSERTION"
 176 
 177     # Do the mount on the $SRVPATH
 178     mount -o vers=3,noac,ro nfs://$SERVER$SRVPATH $TMPmnt \
 179         > $TMPDIR/$NAME.mnt.$$ 2>&1
 180     typeset ret=$?
 181     if [[ $SRVPATH == "/" ]]; then
 182         ckreturn $ret "mount nfsURL did not succeed" $TMPDIR/$NAME.mnt.$$
 183         [ $? -ne 0 ] && return $FAIL
 184 
 185         # verify the mount point is access'ble
 186         cat $TMPmnt/$ROFILE > $TMPDIR/$NAME.ck.$$ 2>&1
 187         ckreturn $? "unable to access ($TMPmnt/$ROFILE)" $TMPDIR/$NAME.ck.$$
 188         [ $? -ne 0 ] && return $FAIL
 189 
 190         # finally umount it
 191         umount $TMPmnt > $TMPDIR/$NAME.umnt.$$ 2>&1
 192         ckreturn $? "umount failed" $TMPDIR/$NAME.umnt.$$
 193         [ $? -ne 0 ] && return $FAIL
 194     else
 195         if [ $ret -eq 0 ]; then
 196             echo "\t Test FAIL: mount v3 succeeded above exported point"
 197             return $FAIL
 198         fi
 199             
 200         # should not be mounted umount it
 201         df $TMPmnt | grep $SERVER > /dev/null 2>&1
 202         if [ $? -eq 0 ]; then
 203             echo "\t Test FAIL: mount failed, but ($TMPmnt) is mounted"
 204             umount $TMPmnt > /dev/null 2>&1
 205             return $FAIL
 206         fi
 207     fi
 208 
 209     echo "\t Test PASS"
 210 }
 211 
 212 
 213 # Start main program here:
 214 # ----------------------------------------------------------------------
 215 
 216 assertion_a
 217 [ $? -ne 0 ] && umount -f $TMPmnt > /dev/null 2>&1
 218 assertion_b
 219 [ $? -ne 0 ] && umount -f $TMPmnt > /dev/null 2>&1
 220 assertion_c
 221 [ $? -ne 0 ] && umount -f $TMPmnt > /dev/null 2>&1
 222 assertion_d
 223 [ $? -ne 0 ] && umount -f $TMPmnt > /dev/null 2>&1
 224 assertion_e
 225 [ $? -ne 0 ] && umount -f $TMPmnt > /dev/null 2>&1
 226 
 227 # cleanup here
 228 rmdir $TMPmnt
 229 rm -f $TMPDIR/$NAME.*.$$
 230 
 231 exit 0