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 . $STF_SUITE/tests/acl/acl_common.kshlib
  29 
  30 ################################################################################
  31 #
  32 # __stc_assertion_start
  33 #
  34 # ID: acl_mv_pos001
  35 #
  36 # DESCRIPTION:
  37 # Verify that '/usr/bin/mv' supports NFSv4 ACL
  38 #
  39 # STRATEGY:
  40 # 1. Create file and  directory in nfs filesystem
  41 # 2. Set special ACE to the file and directory
  42 # 3. Copy the file/directory to another directory
  43 # 4. Verify that the ACL of file/directroy is not changed
  44 #
  45 # TESTABILITY: explicit
  46 #
  47 # TEST_AUTOMATION_LEVEL: automated
  48 #
  49 # __stc_assertion_end
  50 #
  51 ################################################################################
  52 
  53 [[ :$NFSGEN_DEBUG: = *:${NAME}:* || :${NFSGEN_DEBUG}: = *:all:* ]] \
  54         && set -x
  55 
  56 function case_cleanup
  57 {
  58         [[ :$NFSGEN_DEBUG: = *:${NAME}:* || :${NFSGEN_DEBUG}: = *:all:* ]] \
  59                 && set -x
  60 
  61         (( ${#cwd} != 0 )) && cd $cwd
  62         (( ${#mask} != 0 )) && RUN_CHECK $UMASK $mask
  63         cleanup $1
  64 }
  65 
  66 function testing_mv #<flag for file|dir> <file1|dir1> <file2|dir2>
  67 {
  68         [[ :$NFSGEN_DEBUG: = *:${NAME}:* || :${NFSGEN_DEBUG}: = *:all:* ]] \
  69                 && set -x
  70 
  71         typeset flag=$1
  72         set -A obj $2 $3
  73         typeset -i i=0
  74         typeset orig_acl=""
  75         typeset orig_mode=""
  76         typeset dst_acl=""
  77         typeset dst_mode=""
  78 
  79         if [[ $flag == "f" ]]; then     
  80         while (( i < ${#obj[*]} ))
  81         do      
  82                 orig_acl="$(get_acl ${obj[i]})" || case_cleanup $STF_FAIL
  83                 orig_mode="$(get_mode ${obj[i]})" || case_cleanup $STF_FAIL
  84                 if (( i < 1 )); then
  85                         RUN_CHECK $MV ${obj[i]} $dst_file \
  86                                 || case_cleanup $STF_FAIL
  87                         dst_acl=$(get_acl $dst_file) || case_cleanup $STF_FAIL
  88                         dst_mode=$(get_mode $dst_file) || case_cleanup $STF_FAIL
  89                 else
  90                         RUN_CHECK $MV ${obj[i]} $TESTDIR1 || case_cleanup $STF_FAIL
  91                         dst_acl=$(get_acl $TESTDIR1/${obj[i]}) \
  92                                 || case_cleanup $STF_FAIL
  93                         dst_mode=$(get_mode $TESTDIR1/${obj[i]}) \
  94                                 || case_cleanup $STF_FAIL
  95                 fi
  96                         
  97                 if [[ "$dst_mode" != "$orig_mode" ]] || \
  98                         [[ "$dst_acl" != "$orig_acl" ]]; then
  99                         echo "$MV fails to keep the acl for file."
 100                         case_cleanup $STF_FAIL
 101                 fi
 102                         
 103                 (( i = i + 1 ))
 104         done
 105         else
 106         while (( i < ${#obj[*]} ))
 107         do
 108                 typeset orig_nested_acl=""
 109                 typeset orig_nested_mode=""
 110                 typeset dst_nested_acl=""
 111                 typeset dst_nested_mode=""
 112 
 113                 orig_acl=$(get_acl ${obj[i]}) || case_cleanup $STF_FAIL
 114                 orig_mode=$(get_mode ${obj[i]}) || case_cleanup $STF_FAIL
 115                 orig_nested_acl=$(get_acl ${obj[i]}/$nestedfile) \
 116                         || case_cleanup $STF_FAIL
 117                 orig_nested_mode=$(get_mode ${obj[i]}/$nestedfile) \
 118                         || case_cleanup $STF_FAIL
 119                 if (( i < 1 )); then
 120                         RUN_CHECK $MV ${obj[i]} $dst_dir \
 121                                 || case_cleanup $STF_FAIL
 122                         dst_acl=$(get_acl $dst_dir) || case_cleanup $STF_FAIL
 123                         dst_mode=$(get_mode $dst_dir) || case_cleanup $STF_FAIL
 124                         dst_nested_acl=$(get_acl $dst_dir/$nestedfile) \
 125                                 || case_cleanup $STF_FAIL
 126                         dst_nested_mode=$(get_mode $dst_dir/$nestedfile) \
 127                                 || case_cleanup $STF_FAIL
 128                 else
 129                         RUN_CHECK $MV ${obj[i]} $TESTDIR1 \
 130                                 || case_cleanup $STF_FAIL
 131                         dst_acl=$(get_acl $TESTDIR1/${obj[i]}) \
 132                                 || case_cleanup $STF_FAIL
 133                         dst_mode=$(get_mode $TESTDIR1/${obj[i]}) \
 134                                 || case_cleanup $STF_FAIL
 135                         dst_nested_acl=$(get_acl \
 136                                 $TESTDIR1/${obj[i]}/$nestedfile) \
 137                                 || case_cleanup $STF_FAIL
 138                         dst_nested_mode=$(get_mode \
 139                                 $TESTDIR1/${obj[i]}/$nestedfile) \
 140                                 || case_cleanup $STF_FAIL
 141                 fi
 142                         
 143                 if [[ "$orig_mode" != "$dst_mode" ]] || \
 144                    [[ "$orig_acl" != "$dst_acl" ]] || \
 145                    [[ "$dst_nested_mode" != "$orig_nested_mode" ]] || \
 146                    [[ "$dst_nested_acl" != "$orig_nested_acl" ]]; then  
 147                         echo "$MV fails to recursively keep the acl for " \
 148                                 "directory." 
 149                         case_cleanup $STF_FAIL
 150                 fi
 151                         
 152                 (( i = i + 1 ))
 153         done
 154         fi
 155 }
 156 
 157 echo "ASSERTION: Verify that '$MV' supports NFSv4 ACLs."
 158 
 159 spec_ace="everyone@:execute:allow" 
 160 set -A orig_file "origfile1.$$" "origfile2.$$"
 161 set -A orig_dir "origdir1.$$" "origdir2.$$"
 162 nestedfile="nestedfile.$$"
 163 dst_file=dstfile.$$
 164 dst_dir=dstdir.$$ 
 165 cwd=$PWD
 166 mask=`$UMASK`
 167 $UMASK 0022
 168 
 169 #
 170 # This assertion should only test 'mv' within the same filesystem
 171 #
 172 TESTDIR1=$MNTDIR/$TESTDIR/testdir1$$
 173 
 174 if [[ ! -d $TESTDIR1 ]]; then
 175         RUN_CHECK $MKDIR -p $TESTDIR1 || case_cleanup $STF_FAIL
 176 fi
 177 
 178 # Create files and directories and set special ace on them for testing.
 179 cd $TESTDIR
 180 typeset -i i=0
 181 while (( i < ${#orig_file[*]} ))
 182 do
 183         RUN_CHECK $TOUCH ${orig_file[i]} || case_cleanup $STF_FAIL
 184         RUN_CHECK $CHMOD A0+$spec_ace ${orig_file[i]} || case_cleanup $STF_FAIL
 185 
 186         (( i = i + 1 ))
 187 done
 188 i=0
 189 while (( i < ${#orig_dir[*]} ))
 190 do
 191         RUN_CHECK $MKDIR ${orig_dir[i]} || case_cleanup $STF_FAIL
 192         RUN_CHECK $TOUCH ${orig_dir[i]}/$nestedfile || case_cleanup $STF_FAIL
 193 
 194         for obj in ${orig_dir[i]} ${orig_dir[i]}/$nestedfile; do
 195                 RUN_CHECK $CHMOD A0+$spec_ace $obj || case_cleanup $STF_FAIL
 196         done
 197 
 198         (( i = i + 1 ))
 199 done
 200 
 201 testing_mv "f" ${orig_file[0]} ${orig_file[1]}
 202 testing_mv "d" ${orig_dir[0]} ${orig_dir[1]}
 203 
 204 # '$MV' succeeds to support NFSv4 ACLs.
 205 case_cleanup $STF_PASS