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