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 DIR=$(dirname $0)
  29 NAME=$(basename $0)
  30 
  31 . ${STF_SUITE}/include/nfsgen.kshlib
  32 
  33 # Turn on debug info, if requested
  34 export _NFS_STF_DEBUG=$_NFS_STF_DEBUG:$NFSGEN_DEBUG
  35 [[ :$NFSGEN_DEBUG: = *:${NAME}:* || :${NFSGEN_DEBUG}: = *:all:* ]] \
  36        && set -x 
  37 
  38 RUN_CHECK mkdir -p -m 0777 $STF_TMPDIR || exit $STF_UNINITIATED
  39 
  40 # Check if needed binaries exist on CLIENT2 if CLIENT2 is set
  41 if [[ -n $CLIENT2 ]]; then
  42         CLIENT2_ARCH=""
  43         CLIENT2_BIN=$STF_SUITE/bin/$CLIENT2_ARCH/chg_usr_exec
  44         if RSH root $CLIENT2 "[[ -x $CLIENT2_BIN ]]"; then
  45                 CLIENT2_BIN_USED=1
  46         elif [[ -x $CLIENT2_BIN ]]; then
  47                 CLIENT2_BIN_USED=0
  48         else
  49                 echo "$NAME: failed to find binary($CLIENT2_BIN) on both $CLIENT2 and local host"
  50                 exit $STF_UNINITIATED
  51         fi
  52 fi
  53 
  54 if [[ $SETUP == "none" ]]; then
  55         echo " SETUP=<$SETUP>"
  56         echo " Use existing setup, check it ..."
  57         RUN_CHECK mount -p > $MNTDIR/testfile 2>&1 || exit $STF_UNINITIATED
  58 
  59         # Get SERVER and UID01,  save them in config file
  60         realMNT=$(get_realMNT $MNTDIR 2> $MNTDIR/testfile2)
  61         (( $? != 0 )) && cat $MNTDIR/testfile* && exit $STF_UNINITIATED
  62         ZNAME=$(zonename)
  63         SERVER=$(grep " $realMNT" $MNTDIR/testfile | cut -d: -f1)
  64         SHRDIR=$(grep " $realMNT" $MNTDIR/testfile | cut -d\  -f1 | cut -d: -f2)
  65         [[ $SHRDIR != "/" ]] && SHRDIR="${SHRDIR%%/}"
  66         MNTOPT=$(grep " $realMNT" $MNTDIR/testfile | cut -d\  -f7)
  67         MNTOPT=$(echo $MNTOPT | sed -e "s/nodevices,*//" \
  68                 -e "s/zone=${ZNAME},*//" -e "s/,$//" -e "s/^,//")
  69         TGID=$(getent group $TGROUP | awk 'BEGIN {FS=":"} {print $3}')
  70         TUID01=$(getent passwd $TUSER01 | awk 'BEGIN {FS=":"} {print $3}')
  71         TUID02=$(getent passwd $TUSER02 | awk 'BEGIN {FS=":"} {print $3}')
  72 
  73         is_IPv6 $SERVER > $STF_TMPDIR/is_IPv6.$$ 2>&1
  74         IS_IPV6=$?
  75         # by default, we assume it's ipv4
  76         [[ $IS_IPV6 != 1 ]] && IS_IPV6=0
  77 
  78         RUN_CHECK rm $MNTDIR/testfile* || exit $STF_UNINITIATED
  79 
  80         nfsstat -m $realMNT | grep Flags: | grep "sec=krb5" > /dev/null 2>&1
  81         (( $? == 0 )) && export IS_KRB5=1 || export IS_KRB5=0
  82 
  83         cat >> $1 <<-EOF
  84 export realMNT="$realMNT"
  85 export SERVER="$SERVER"
  86 export SHRDIR="$SHRDIR"
  87 export MNTDIR="${MNTDIR%%/}"
  88 export MNTOPT="$MNTOPT"
  89 export TGID="$TGID"
  90 export TUID01="$TUID01"
  91 export TUID02="$TUID02"
  92 export TESTVERS="$TESTVERS"
  93 export TestZFS="$TestZFS"
  94 export IS_KRB5="$IS_KRB5"
  95 export IS_IPV6=$IS_IPV6
  96 export CLIENT2_ARCH=$CLIENT2_ARCH
  97 export CLIENT2_BIN_USED=$CLIENT2_BIN_USED
  98 EOF
  99 
 100         exit $STF_PASS
 101 fi
 102 
 103 # Verify the valid SETUP value
 104 if [[ ! -d ${STF_SUITE}/bin/$SETUP ]]; then
 105         echo "$NAME: SETUP=<$SETUP> is not supported."
 106         echo "\tPlease redefine the valid SETUP value: {nfsv4, none}"
 107         exit $STF_UNSUPPORTED
 108 fi
 109 
 110 # Check if needed binaries exist on the server or local host
 111 SERVER_ARCH=""
 112 SERVER_BIN=$STF_SUITE/bin/$SERVER_ARCH/chg_usr_exec
 113 if RSH root $SERVER "[[ -x $SERVER_BIN ]]"; then
 114         SERVER_BIN_USED=1
 115 elif [[ -x $SERVER_BIN ]]; then
 116         SERVER_BIN_USED=0
 117 else
 118         echo "$NAME: failed to find binary($SERVER_BIN) on both $SERVER and local host"
 119         exit $STF_FAIL
 120 fi
 121 
 122 
 123 # Verify "anon=0" is in share options
 124 if [[ -n $SHROPT ]]; then
 125         echo "$SHROPT" | grep "anon" > /dev/null
 126         (( $? != 0 )) && SHROPT="$SHROPT,anon=0" || SHROPT=$SHROPT
 127 else
 128         SHROPT="anon=0"
 129 fi
 130 export SHROPT
 131 
 132 # get dns server from the following sources
 133 #       - user specifid value
 134 #       - /etc/resolv.conf
 135 #       - default("129.145.155.226")
 136 if [[ -z $DNS_SERVER && -f /etc/resolv.conf ]]; then
 137         dns_server=$(grep nameserver /etc/resolv.conf | head -1 | \
 138             awk '{print $2}')
 139         [[ -n $dns_server  ]] && DNS_SERVER=$dns_server
 140 fi
 141 DNS_SERVER=${DNS_SERVER:-129.145.155.226}
 142 
 143 # check if we need to test krb5
 144 echo $SHROPT | grep "sec=krb5" > /dev/null 2>&1
 145 (( $? == 0 )) && export IS_KRB5=1 || export IS_KRB5=0
 146 
 147 # Check TX related info
 148 RUN_CHECK check_for_cipso $SHRDIR $MNTDIR $MNTOPT || return $STF_UNSUPPORTED
 149 
 150 # Get free GID and create a group
 151 TGID=$(get_free_gid $SERVER)
 152 (( $? != 0 )) && echo "$NAME: Can't get a unused gid for $TUSER01" \
 153         && exit $STF_UNINITIATED
 154 groupdel $TGROUP >/dev/null 2>&1
 155 RUN_CHECK groupadd -g $TGID $TGROUP || exit $STF_UNINITIATED
 156 
 157 # Get free UID and create users.
 158 TUID01=$(get_free_uid $SERVER)
 159 (( $? != 0 )) && echo "$NAME: Can't get a unused uid for $TUSER01" \
 160         && exit $STF_UNINITIATED
 161 userdel $TUSER01 >/dev/null 2>&1
 162 RUN_CHECK useradd -u $TUID01 -g $TGROUP -d /tmp $TUSER01 \
 163         || exit $STF_UNINITIATED
 164 TUID02=$(get_free_uid $SERVER)
 165 (( $? != 0 )) && echo "$NAME: Can't get a unused uid for $TUSER02" \
 166         && exit $STF_UNINITIATED
 167 userdel $TUSER02 >/dev/null 2>&1
 168 RUN_CHECK useradd -u $TUID02 -g $TGROUP -d /tmp $TUSER02 \
 169         || exit $STF_UNINITIATED
 170 
 171 # Check if it's ipv6 config.
 172 is_IPv6 $SERVER > $STF_TMPDIR/is_IPv6.$$ 2>&1
 173 IS_IPV6=$?
 174 # by default, we assume it's ipv4
 175 [[ $IS_IPV6 != 1 ]] && IS_IPV6=0
 176 
 177 [[ $SHRDIR != "/" ]] && SHRDIR="${SHRDIR%%/}"
 178 # Save it in config file
 179 cat >> $1 <<-EOF
 180 export SHRDIR=$SHRDIR
 181 export MNTDIR="${MNTDIR%%/}"
 182 export TUID01=$TUID01
 183 export TUID02=$TUID02
 184 export TGID=$TGID
 185 export IS_KRB5=$IS_KRB5
 186 export IS_IPV6=$IS_IPV6
 187 export DNS_SERVER=$DNS_SERVER
 188 export SERVER_ARCH=$SERVER_ARCH
 189 export SERVER_BIN_USED=$SERVER_BIN_USED
 190 export CLIENT2_ARCH=$CLIENT2_ARCH
 191 export CLIENT2_BIN_USED=$CLIENT2_BIN_USED
 192 EOF
 193 
 194 #
 195 # General client side setup
 196 #    - creating test user
 197 #    - setting up mapid domain
 198 #
 199 
 200 # Set mapid domain on client
 201 RUN_CHECK set_nfs_property NFSMAPID_DOMAIN $NFSMAPID_DOMAIN \
 202     $STF_TMPDIR/mapid_backup || exit $STF_UNINITIATED
 203 
 204 #
 205 # General server side setup
 206 #    - creating test user
 207 #    - setting up mapid domain
 208 #
 209 
 210 # Create temp dir on server
 211 RUN_CHECK RSH root $SERVER "mkdir -p -m 0777 $SRV_TMPDIR" \
 212     || exit $STF_UNINITIATED
 213 
 214 # Setup kerberos if needed.
 215 if [[ $IS_KRB5 == 1 ]]; then
 216         print "Checking krb5 setup ..."
 217         RUN_CHECK krb5_config -s || exit $STF_UNINITIATED
 218         # check and reset MNTOPT to match the SHROPT
 219         SecOPT=$(echo $SHROPT | \
 220             nawk -F\, '{for (i=1; i<=NF; i++) {if ($i ~ /sec=/) print $i} }')
 221         SecOPT=$(echo $SecOPT | nawk -F\: '{print $1}')
 222         echo $MNTOPT | grep "sec=krb5" > /dev/null 2>&1
 223         if (( $? == 0 )); then
 224                 MntOPT=$(echo $MNTOPT | \
 225                     nawk -F\, \
 226                         '{for (i=1; i<=NF; i++) {if ($i ~ /sec=/) print $i} }')
 227                 MntOPT=$(echo $MntOPT | nawk -F\: '{print $1}')
 228                 if [[ $MntOPT != $SecOPT ]]; then
 229                         print "user defined unmatched sec= for share and mount"
 230                         print "    SHROPT=<$SHROPT>, MNTOPT=$<$MNTOPT>"
 231                         print "Reset MNTOPT to use same sec= option as share"
 232                         export MNTOPT=$(echo $MNTOPT | sed "s/$MntOPT/$SecOPT/")
 233                         echo "export MNTOPT=$MNTOPT" >> $1
 234                 fi
 235         fi
 236         echo "export SecOPT=$SecOPT" >> $1
 237 fi
 238 
 239 # Copy files
 240 cat > $STF_TMPDIR/srv_env.vars << EOF
 241 export SHRDIR=$SHRDIR
 242 export MNTDIR="${MNTDIR%%/}"
 243 export NFSMAPID_DOMAIN=$NFSMAPID_DOMAIN
 244 export TGROUP=$TGROUP
 245 export TGID=$TGID
 246 export TUSER01=$TUSER01
 247 export TUID01=$TUID01
 248 export TUSER02=$TUSER02
 249 export TUID02=$TUID02
 250 export IS_IPV6=$IS_IPV6
 251 export _NFS_STF_DEBUG=$_NFS_STF_DEBUG
 252 export NFSGEN_DEBUG=$NFSGEN_DEBUG
 253 export PATH=$PATH:/opt/SUNWstc-genutils/bin
 254 EOF
 255 RUN_CHECK scp $DIR/srv_setup                   \
 256     $STF_TMPDIR/srv_env.vars                   \
 257     $STF_TOOLS/contrib/include/libsmf.shlib    \
 258     $STF_TOOLS/contrib/include/nfs-smf.kshlib  \
 259     $STF_SUITE/include/nfs-util.kshlib \
 260     root@$SERVER:$SRV_TMPDIR || exit $STF_UNINITIATED
 261 
 262 # Run server setup script
 263 RUN_CHECK RSH root $SERVER "$SRV_TMPDIR/srv_setup -s" || exit $STF_UNINITIATED
 264 
 265 
 266 #
 267 # General client2 side setup
 268 #       - creating test user
 269 #       - setting up nfsmapid domain
 270 #
 271 
 272 if [[ -n $CLIENT2 && $CLIENT2 != $SERVER && $CLIENT2 != $CLIENT ]]; then
 273         # Create temp dir on client2
 274         RUN_CHECK RSH root $CLIENT2 "mkdir -p -m 0777 $SRV_TMPDIR" \
 275                 || exit $STF_UNINITIATED
 276         # copy files
 277         RUN_CHECK scp $DIR/srv_setup                   \
 278                 $STF_TMPDIR/srv_env.vars                   \
 279                 $STF_TOOLS/contrib/include/libsmf.shlib    \
 280                 $STF_TOOLS/contrib/include/nfs-smf.kshlib  \
 281                 $STF_SUITE/include/nfs-util.kshlib \
 282                 root@$CLIENT2:$SRV_TMPDIR || exit $STF_UNINITIATED
 283 
 284         # Run server setup script
 285         RUN_CHECK RSH root $CLIENT2 "$SRV_TMPDIR/srv_setup -s" \
 286                 || exit $STF_UNINITIATED
 287 fi
 288 
 289 #
 290 # Setup-specific configuration.
 291 #
 292 # We move share and mount operations there for flexibility. However,
 293 # they should use SHRDIR, SHROPT, MNTDIR, and MNTOPT variables.
 294 #
 295 
 296 RUN_CHECK ${STF_SUITE}/bin/$SETUP/configure $1 || exit $STF_UNINITIATED
 297 
 298 # Check the setup
 299 RUN_CHECK touch $MNTDIR/testfile || exit $STF_UNINITIATED
 300 RUN_CHECK rm $MNTDIR/testfile || exit $STF_UNINITIATED
 301 
 302 exit $STF_PASS