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 2007 Sun Microsystems, Inc.  All rights reserved.
  25 # Use is subject to license terms.
  26 #
  27 # NFSv4 named attributes: 
  28 # a: Test basic create named attr for dir object using runat, expect OK
  29 # b: Test basic remove of dir object w/named attr using runat, expect OK
  30 # c: Test READDIR of named attr dir using runat command, expect OK
  31 #
  32 
  33 funcs="./attrcmds_funcs"
  34 [ ! -r $funcs ] && echo "$0 ERROR: cannot source $funcs" && exit $UNINITIATED
  35 . $funcs
  36 
  37 setup
  38 
  39 # XXX Assume that xattr mount option is set by default on UFS filesystems
  40 # Use pre-mounted filesystem previously setup by nfs4_gen framework
  41 
  42 # Start test
  43 # --------------------------------------------------------------------
  44 # a: Test basic create named attr for dir object using runat command, \
  45 #expect OK
  46 ASSERTION="Test basic create named attr for dir object using attr commands"
  47 ASSERTION="$ASSERTION, expect successful"
  48 echo "$NAME{a}: $ASSERTION"
  49 
  50 #Check mount point works
  51 ls $MNTPTR > /dev/null 2> $TMPDIR/$NAME.out.$$
  52 ret=$?
  53 ckreturn $ret "mount point $MNTPTR not accessible (ret=$ret)." \
  54         $TMPDIR/$NAME.out.$$ UNINITIATED
  55 [ $? -ne 0 ] && cleanup $UNINITIATED
  56 
  57 cd $MNTPTR > $TMPDIR/$NAME.out.$$ 2>&1
  58 ret=$?
  59 ckreturn $ret "Cannot chdir to [$MNTPTR], returned $ret." $TMPDIR/$NAME.out.$$ \
  60         UNINITIATED
  61 [ $? -ne 0 ] && cleanup $UNINITIATED
  62 
  63 # Create a test directory 
  64 mkdir $MNTPTR/$TESTDIR1 > $TMPDIR/$NAME.out.$$ 2>&1
  65 ret=$?
  66 ckreturn $ret "Cannot create [$TESTDIR1], returned $ret." $TMPDIR/$NAME.out.$$ \
  67         UNINITIATED
  68 [ $? -ne 0 ] && cleanup $UNINITIATED
  69 
  70 sleep 1
  71 # Now Create named attribute for file object 
  72 echo "This is an attribute" | runat $MNTPTR/$TESTDIR1 "cat > attr" > \
  73         $TMPDIR/$NAME.out.$$ 2>&1
  74 ret=$?
  75 ckreturn $ret "Cannot create attr file object, returned $ret." $TMPDIR/$NAME.out.$$
  76 [ $? -ne 0 ] && cleanup $FAIL
  77 
  78 sleep 1
  79 # Verify test file still accessible
  80 RESULT=$($LSATD $MNTPTR/$TESTDIR1 | awk '{print $1}' | cut -c11 \
  81         2> $TMPDIR/$NAME.out.$$)
  82 ret=0 && [ "$RESULT" != "@" ] && ret=1
  83 ckreturn $ret "$LSATD command didn't get attr (res=$RESULT)" \
  84         $TMPDIR/$NAME.out.$$
  85 [ $? -ne 0 ] && cleanup $FAIL
  86 
  87 sleep 1
  88 # Verify attr dir accessible by runat command
  89 runat $MNTPTR/$TESTDIR1 ls -l > $TMPDIR/runat01.out.$$ 2>&1
  90 ret=$?
  91 ckreturn $ret "[$TESTFILE attr dir] not accessible, returned $ret." \
  92         $TMPDIR/runat01.out.$$
  93 [ $? -ne 0 ] && cleanup $FAIL
  94 
  95 sleep 1
  96 # Verify can view an attribute created in file's attribute directory
  97 runat $MNTPTR/$TESTDIR1 cat attr > $TMPDIR/runat02.out.$$ 2>&1
  98 ret=$?
  99 ckreturn $ret "Cannot view [$TESTDIR1 attr], returned $ret" $TMPDIR/runat02.out.$$
 100 [ $? -ne 0 ] && cleanup $FAIL
 101 
 102 echo "\tTest PASS"
 103 
 104 # cleanup here
 105 rm -rf $MNTPTR/$TESTDIR1 $TMPDIR/$NAME.*.$$ $TMPDIR/runat*.out.$$
 106 
 107 # --------------------------------------------------------------------
 108 # b: Test basic remove of dir object w/named attr, expect OK
 109 ASSERTION="Test basic remove of dir object w/named attr"
 110 ASSERTION="$ASSERTION, expect successful"
 111 echo "$NAME{b}: $ASSERTION"
 112 
 113 cd $MNTPTR > $TMPDIR/$NAME.out.$$ 2>&1
 114 ret=$?
 115 ckreturn $ret "Cannot chdir to [$MNTPTR], returned $ret." $TMPDIR/$NAME.out.$$ \
 116         UNINITIATED
 117 [ $? -ne 0 ] && cleanup $UNINITIATED
 118 
 119 # Create a test directory 
 120 mkdir $MNTPTR/$TESTDIR2 > $TMPDIR/$NAME.out.$$ 2>&1
 121 ret=$?
 122 ckreturn $ret "Cannot create [$TESTDIR2], returned $ret." $TMPDIR/$NAME.out.$$ \
 123         UNINITIATED
 124 [ $? -ne 0 ] && cleanup $UNINITIATED
 125 
 126 # Now Create named attribute for file object
 127 echo "This is an attribute for remove" | runat $MNTPTR/$TESTDIR2 \
 128         "cat > attrb" > $TMPDIR/$NAME.out.$$ 2>&1
 129 ret=$?
 130 ckreturn $ret "Cannot create attr file objec, returned $ret." $TMPDIR/$NAME.out.$$
 131 [ $? -ne 0 ] && cleanup $FAIL
 132 
 133 # Verify test dir is still accessible
 134 $LSATD $MNTPTR/$TESTDIR2 > $TMPDIR/$NAME.out.$$ 2>&1
 135 ret=$?
 136 ckreturn $ret "[$TESTDIR2] not accessible, returned $ret." $TMPDIR/$NAME.out.$$
 137 [ $? -ne 0 ] && cleanup $FAIL
 138 
 139 # Verify attr dir accessible by runat command
 140 runat $MNTPTR/$TESTDIR2 ls -l > $TMPDIR/runat02.out.$$ 2>&1
 141 ret=$?
 142 ckreturn $ret "[$TESTDIR2 attr file] not accessible, returned $ret." \
 143         $TMPDIR/runat02.out.$$
 144 [ $? -ne 0 ] && cleanup $FAIL
 145 
 146 # Remove dir and it's attr file object using basic "rm" command
 147 rm -r $MNTPTR/$TESTDIR2 > $TMPDIR/rm02.out.$$ 2>&1
 148 ret=$?
 149 ckreturn $ret "[$TESTDIR2 attr dir] was not removed, returned $ret." \
 150         $TMPDIR/rm02.out.$$
 151 [ $? -ne 0 ] && cleanup $FAIL
 152 
 153 # Verify test dir not accessible
 154 $LSATD $MNTPTR/$TESTDIR2 > $TMPDIR/$NAME.out.$$ 2>&1
 155 ret=$?
 156 ckreturn -r $ret "[$TESTDIR2] still accessible, returned $ret." \
 157         $TMPDIR/$NAME.out.$$
 158 [ $? -eq 0 ] && cleanup $FAIL
 159 
 160 # Verify attr no longer accessible by runat command
 161 runat $MNTPTR/$TESTDIR2 ls -l > $TMPDIR/runat02.out.$$ 2>&1
 162 ret=$? 
 163 ckreturn -r $ret "[$TESTDIR2 attr dir] was not removed, returned $ret." \
 164         $TMPDIR/runat02.out.$$
 165 [ $? -eq 0 ] && cleanup $FAIL
 166 
 167 echo "\tTest PASS"
 168 
 169 # cleanup here
 170 rm -rf $TMPDIR/$NAME.*.$$ $TMPDIR/runat*.out.$$ 
 171 
 172 #---------------------------------------------------------------------:w
 173 # c: Test READDIR of named attr dir using runat command, expect OK
 174 ASSERTION="Test READDIR of named attr dir using runat command, expect OK"
 175 echo "$NAME{c}: $ASSERTION"
 176 
 177 # Create a temporary test directory for this assertion
 178 mkdir $MNTPTR/$TESTDIR3 > $TMPDIR/$NAME.out.$$ 2>&1
 179 ret=$?
 180 ckreturn $ret "Cannot create dir [$MNTPTR/$TESTDIR3], returned $ret." \
 181         $TMPDIR/$NAME.out.$$ UNINITIATED
 182 [ $? -ne 0 ] && cleanup $UNINITIATED
 183 
 184 # Create named attribute for this dir object
 185 Tattr=attrdir.$$
 186 echo "This is an attribute for the dir object of $MNTPTR/$TESTDIR3" | \
 187         runat $MNTPTR/$TESTDIR3 "cat > $Tattr; chmod 600 $Tattr" \
 188         > $TMPDIR/$NAME.out.$$ 2>&1
 189 ret=$?
 190 ckreturn $ret \
 191     "Cannot create attr file [$Tattr] for $MNTPTR/$TESTDIR3, returned $ret." \
 192         $TMPDIR/$NAME.out.$$
 193 [ $? -ne 0 ] && cleanup $FAIL
 194 
 195 # Now Verify attr dir accessible by runat command and list the attr file
 196 runat $MNTPTR/$TESTDIR3 'ls -l' | \
 197         egrep -iv "SUNWattr|total" > $TMPDIR/runatc.out.$$ 2>&1
 198 ret=$?
 199 ckreturn $ret "'runat [$MNTPTR/$TESTDIR3] ls -l' failed, returned $ret." \
 200         $TMPDIR/runatc.out.$$
 201 [ $? -ne 0 ] && cleanup $FAIL
 202 
 203 Tmode=`nawk '{print $1}' $TMPDIR/runatc.out.$$`
 204 Tname=`nawk '{print $9}' $TMPDIR/runatc.out.$$`
 205 ret=0 && [ "$Tmode" != "-rw-------" ] && ret=1
 206 ckreturn $ret \
 207         "'runat $MNTPTR/$TESTDIR3 ls -l' incorrect mode $Tmode." \
 208         $TMPDIR/runatc.out.$$
 209 [ $? -ne 0 ] && cleanup $FAIL
 210 
 211 ret=0 && [ "$Tname" != "$Tattr" ] && ret=1
 212 ckreturn $ret \
 213         "'runat $MNTPTR/$TESTDIR3 ls -l' incorrect attr name $Tname."\
 214         $TMPDIR/runatc.out.$$
 215 [ $? -ne 0 ] && cleanup $FAIL
 216 
 217 
 218 echo "\tTest PASS"
 219 
 220 # cleanup here
 221 cleanup $PASS
 222 
 223 exit $PASS