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 NAME=$(basename $0)
  29 CDIR=$(dirname $0)
  30 
  31 . $CDIR/${CDIR##*/}.vars
  32 . $STF_SUITE/include/sharemnt.kshlib
  33 . $STC_GENUTILS/include/libsmf.shlib
  34 . $STC_GENUTILS/include/nfs-tx.kshlib
  35 
  36 export STC_GENUTILS_DEBUG=$STC_GENUTILS_DEBUG:$SHAREMNT_DEBUG
  37 [[ :$SHAREMNT_DEBUG: == *:$NAME:* \
  38         || :$SHAREMNT_DEBUG: == *:all:* ]] && set -x
  39 
  40 # check again if proto=rdma tests should be generated
  41 echo "$TESTRDMA" | grep -i no > /dev/null 2>&1
  42 (( $? != 0 )) && . $STF_CONFIG/stf_config.suite
  43 
  44 typeset -i so_flg=0
  45 Share_opts=$(gen_opt_list "$SHROPTS")
  46 Mount_opts="$MNTOPTS"
  47 Versions="$VEROPTS"
  48 
  49 acc_host=$CLIENT_S
  50 oth_host=$SERVER_S
  51 acc_netgroup=""
  52 oth_netgroup="NotExistGroup"
  53 acc_domain=""
  54 oth_domain=".NotExistDomain"
  55 
  56 # share_nfs doesn't support using IPv6 address
  57 # hard-coded with IPv4 address for the access network
  58 [[ -z $acc_host ]] && acc_host=$(hostname)
  59 hostip=$(is_IPv6 $acc_host)
  60 if (( $? == 0 )); then
  61     acc_network="@$(echo $hostip | awk -F\. '{print $1"."$2"."$3}')/24"
  62     oth_network="@$(echo $hostip | awk -F\. '{print $1"."$2"."($3+1)}')/24"
  63     acc_hostIP="@$hostip"
  64 elif (( $? == 1 )); then
  65     # now IPv6 isn't supported in access list, we should set the
  66     # following variables with IPv6 address once 6481391 is fixed
  67     acc_network=""
  68     oth_network=""
  69     acc_hostIP=""
  70 else
  71     echo "$NAME: $hostip"
  72     exit 1
  73 fi
  74 
  75 # create a list with each element includes the client test machine
  76 acc_list="$acc_host $acc_netgroup $acc_domain $acc_network $acc_hostIP"
  77 
  78 # create a list with each element excludes the client test machine
  79 den_list=""
  80 for i in $acc_list; do
  81     den_list="$den_list -$i"
  82 done
  83 
  84 # create a list with each element doesn't include the client test machine
  85 oth_list="$oth_host $oth_netgroup $oth_domain $oth_network"
  86 
  87 
  88 # test the client in "ro/rw/root" access list
  89 for i in $acc_list "null"; do
  90     for mo in $Mount_opts; do
  91         for v in $Versions; do
  92             [[ $v == "default" ]] && mo2=${mo} || mo2=${mo},${v}
  93 
  94             for j in "ro" "rw"; do
  95                 [[ $i == "null" ]] && so="$j" || so="$j=$i"
  96 
  97                 # "share -o ro|rw[=access_foo][,root=access_foo]"
  98                 for root_i in $acc_list; do
  99                     so2="$so,root=$root_i"
 100                     Tname=$(echo ACCESS_SH${so2}_MNT${mo2} | \
 101                                 sed "s%$acc_host%CLNT%g")
 102                     [[ -n $acc_network ]] && Tname=$(echo $Tname | \
 103                                 sed "s%$acc_network%CLNTIP%g")
 104                     [[ -n $acc_hostIP ]] && Tname=$(echo $Tname | \
 105                                 sed "s%$acc_hostIP%HOSTIP%g")
 106                     echo "adding $Tname test"
 107                     stf_addassert -u root -t $Tname -c access_test \
 108                         "$Tname $so2 $mo2 $j root"
 109                 done
 110 
 111                 # "share -o ro|rw[=access_foo]
 112                 #           [,root=not_access_foo|deny_access_foo]"
 113                 for root_i in $den_list $oth_list "null"; do
 114                     [[ $root_i == "null" ]] && so2="$so" \
 115                                             || so2="$so,root=$root_i"
 116                     Tname=$(echo ACCESS_SH${so2}_MNT${mo2} | \
 117                             sed -e "s%$acc_host%CLNT%g" \
 118                                 -e "s%$oth_host%SRV%g")
 119                     [[ -n $acc_network ]] && Tname=$(echo $Tname | \
 120                                 sed "s%$acc_network%CLNTIP%g")
 121                     [[ -n $oth_network ]] && Tname=$(echo $Tname | \
 122                                 sed "s%$oth_network%SRVIP%g")
 123                     [[ -n $acc_hostIP ]] && Tname=$(echo $Tname | \
 124                                 sed "s%$acc_hostIP%HOSTIP%g")
 125                     echo "adding $Tname test"
 126                     stf_addassert -u root -t $Tname -c access_test \
 127                         "$Tname $so2 $mo2 $j noroot"
 128                 done
 129             done
 130 
 131             if [[ $i != "null" ]]; then
 132                 for j in "rw,ro" "ro,rw"; do
 133                     [[ $j == *"ro" ]] && expopt=ro || expopt=rw
 134                     so="$j=$i"
 135 
 136                     # "share -o <rw,ro>|<ro,rw>=access_foo[,root=access_foo]"
 137                     for root_i in $acc_list; do
 138                         so1="$so,root=$root_i"
 139                         Tname=$(echo ACCESS_SH${so1}_MNT${mo2} | \
 140                                 sed "s%$acc_host%CLNT%g")
 141                         [[ -n $acc_network ]] && Tname=$(echo $Tname | \
 142                                 sed "s%$acc_network%CLNTIP%g")
 143                         [[ -n $acc_hostIP ]] && Tname=$(echo $Tname | \
 144                                 sed "s%$acc_hostIP%HOSTIP%g")
 145                         echo "adding $Tname test"
 146                         stf_addassert -u root -t $Tname -c access_test \
 147                             "$Tname $so1 $mo2 $expopt root"
 148                     done
 149 
 150                     # "share -o <rw,ro>|<ro,rw>=access_foo
 151                     #           [,root=not_access_foo|deny_access_foo]"
 152                     for root_i in $den_list $oth_list "null"; do
 153                         [[ $root_i == "null" ]] && so1="$so" \
 154                                                 || so1="$so,root=$root_i"
 155                         Tname=$(echo ACCESS_SH${so1}_MNT${mo2} | \
 156                                 sed -e "s%$acc_host%CLNT%g" \
 157                                     -e "s%$oth_host%SRV%g")
 158                         [[ -n $acc_network ]] && Tname=$(echo $Tname | \
 159                                 sed "s%$acc_network%CLNTIP%g")
 160                         [[ -n $oth_network ]] && Tname=$(echo $Tname | \
 161                                 sed "s%$oth_network%SRVIP%g")
 162                         [[ -n $acc_hostIP ]] && Tname=$(echo $Tname | \
 163                                 sed "s%$acc_hostIP%HOSTIP%g")
 164                         echo "adding $Tname test"
 165                         stf_addassert -u root -t $Tname -c access_test \
 166                             "$Tname $so1 $mo2 $expopt noroot"
 167                     done
 168                 done
 169             fi
 170         done
 171     done
 172 done
 173 
 174 # test combination options
 175 so=$(echo $oth_list | sed 's/ /:/g')
 176 for i in $acc_list "null"; do
 177     for mo in $Mount_opts; do
 178         for v in $Versions; do
 179             [[ $v == "default" ]] && mo2=${mo} || mo2=${mo},${v}
 180 
 181             if [[ $i == "null" ]]; then
 182                 so1=$(echo $den_list | sed 's/ /:/g')
 183 
 184                 # "share -o ro|rw=not_access_foo:deny_access_foo"
 185                 # "share -o ro=not_access_foo,rw=deny_access_foo"
 186                 # "share -o rw=not_access_foo,ro=deny_access_foo"
 187                 for so2 in "ro=$so:$so1" "rw=$so:$so1" \
 188                     "ro=$so,rw=$so1" "rw=$so,ro=$so1"; do
 189                     tag="NEG_ACCESS"
 190                     Tname=$(echo ${tag}_SH${so2}_MNT${mo2} | \
 191                         sed -e "s%$acc_host%CLNT%g" \
 192                             -e "s%$oth_host%SRV%g")
 193                     [[ -n $acc_network ]] && Tname=$(echo $Tname | \
 194                                 sed "s%$acc_network%CLNTIP%g")
 195                     [[ -n $oth_network ]] && Tname=$(echo $Tname | \
 196                                 sed "s%$oth_network%SRVIP%g")
 197                     [[ -n $acc_hostIP ]] && Tname=$(echo $Tname | \
 198                                 sed "s%$acc_hostIP%HOSTIP%g")
 199                     echo "adding $Tname test"
 200                     stf_addassert -u root -t $Tname -c neg_access \
 201                         "$Tname $mo2 $so2"
 202                 done
 203             else
 204                 # "share -o ro|rw=not_access_foo:access_foo"
 205                 for so2 in "ro=$so:$i" "rw=$so:$i"; do
 206                     expopt=$(echo $so2 | awk -F= '{print $1}')
 207                     Tname=$(echo ACCESS_SH${so2}_MNT${mo2} | \
 208                         sed -e "s%$acc_host%CLNT%g" \
 209                             -e "s%$oth_host%SRV%g")
 210                     [[ -n $acc_network ]] && Tname=$(echo $Tname | \
 211                                 sed "s%$acc_network%CLNTIP%g")
 212                     [[ -n $oth_network ]] && Tname=$(echo $Tname | \
 213                                 sed "s%$oth_network%SRVIP%g")
 214                     [[ -n $acc_hostIP ]] && Tname=$(echo $Tname | \
 215                                 sed "s%$acc_hostIP%HOSTIP%g")
 216                     echo "adding $Tname test"
 217                     stf_addassert -u root -t $Tname -c access_test \
 218                         "$Tname $so2 $mo2 $expopt noroot"
 219                 done
 220             fi
 221         done
 222     done
 223 done
 224 
 225 tag="NEG_ACCESS"
 226 so="anon=-1"
 227 for v in $Versions; do
 228         [[ $v == "default" ]] && mo=rw || mo=rw,${v}
 229         Tname=${tag}_SH${so}_MNT${mo}
 230         echo "adding $Tname test"
 231         stf_addassert -u root -t $Tname -c neg_access "$Tname $mo $so"
 232 done
 233 
 234 
 235 exit 0