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_cpio_pos002
  35 #
  36 # DESCRIPTION:
  37 # Verify that '$CPIO' command with -P@ option supports to archive ZFS ACLs
  38 #
  39 # STRATEGY:
  40 # 1. Create file and directory in nfs filesystem
  41 # 2. Add new ACE in ACL or change mode of file and directory
  42 # 3. Create xattr of the file and directory
  43 # 4. Use $CPIO to archive file and directory
  44 # 5. Extract the archive file
  45 # 6. Verify that the restored ACLs of file and directory identify
  46 #    with the origional ones. 
  47 #
  48 # TESTABILITY: explicit
  49 #
  50 # TEST_AUTOMATION_LEVEL: automated
  51 #
  52 # __stc_assertion_end
  53 #
  54 ################################################################################
  55 
  56 [[ :$NFSGEN_DEBUG: = *:${NAME}:* || :${NFSGEN_DEBUG}: = *:all:* ]] \
  57         && set -x
  58 
  59 echo "ASSERTION: Verify that '$CPIO' command supports to archive NFSv4 ACLs & xattrs."
  60 
  61 set -A ops "A+everyone@:execute:allow" \
  62         "A3+user:$ACL_OTHER1:write_data:deny" \
  63         "A5+group:$ACL_OTHER_GROUP:read_data:deny" \
  64         "A0+user:$ACL_OTHER1:write_data:deny"
  65 
  66 # Create second directory to restore the cpio archive.
  67 RUN_CHECK $MKDIR -p $TESTDIR1 || cleanup $STF_FAIL
  68 RUN_CHECK $CHMOD 777 $TESTDIR1 || cleanup $STF_FAIL
  69 
  70 # Define test fine and record the original directory.
  71 CPIOFILE=cpiofile.$$
  72 file=$TESTFILE0
  73 dir=dir.$$
  74 orig_dir=$PWD
  75 MYTESTFILE=$STF_SUITE/STF.INFO
  76 
  77 typeset user
  78 for user in root $ACL_STAFF1; do
  79         # Set the current user
  80         RUN_CHECK set_cur_usr $user || cleanup $STF_FAIL
  81 
  82         typeset -i i=0
  83         while (( i < ${#ops[*]} )); do
  84                 # Create file $file and directory $dir in nfs filesystem.
  85                 cd $TESTDIR
  86                 RUN_CHECK usr_exec $TOUCH $file || cleanup $STF_FAIL
  87                 RUN_CHECK usr_exec $MKDIR $dir || cleanup $STF_FAIL
  88                 RUN_CHECK usr_exec $RUNAT $file $CP $MYTESTFILE attr.0 \
  89                         || cleanup $STF_FAIL
  90                 RUN_CHECK usr_exec $RUNAT $dir $CP $MYTESTFILE attr.0 \
  91                         || cleanup $STF_FAIL
  92 
  93                 # Change the ACLs of file and directory with '$CHMOD ${ops[i]}'.
  94                 for obj in $file $dir; do
  95                         RUN_CHECK usr_exec $CHMOD ${ops[i]} $obj \
  96                                 || cleanup $STF_FAIL
  97                 done
  98 
  99                 # Archive the file and directory.
 100                 RUN_CHECK usr_exec $LS | $CPIO -ocP@ -O $CPIOFILE \
 101                         > $STF_TMPDIR/cpio.$$ 2>&1 \
 102                         || cleanup $STF_FAIL $STF_TMPDIR/cpio.$$
 103 
 104                 # Restore the cpio archive.
 105                 cd $MNTDIR
 106                 RUN_CHECK usr_exec $MV $TESTDIR/$CPIOFILE $TESTDIR1 || cleanup $STF_FAIL
 107                 cd $TESTDIR1
 108                 RUN_CHECK usr_exec $CAT $CPIOFILE | $CPIO -icP@ \
 109                         > $STF_TMPDIR/cpio.$$ 2>&1 \
 110                         || cleanup $STF_FAIL $STF_TMPDIR/cpio.$$
 111 
 112                 # Verify that the ACLs of restored file/directory have no change
 113                 cd $MNTDIR
 114                 for obj in $file $dir; do
 115                         RUN_CHECK compare_modes $TESTDIR/$obj $TESTDIR1/$obj \
 116                                 || cleanup $STF_FAIL
 117                         RUN_CHECK compare_acls $TESTDIR/$obj $TESTDIR1/$obj \
 118                                 || cleanup $STF_FAIL
 119                         RUN_CHECK compare_xattrs $TESTDIR/$obj $TESTDIR1/$obj \
 120                                 || cleanup $STF_FAIL
 121                 done
 122 
 123                 RUN_CHECK usr_exec $RM -rf $TESTDIR/* $TESTDIR1/* \
 124                         || cleanup $STF_FAIL
 125 
 126                 (( i = i + 1 ))
 127         done
 128 done
 129 
 130 # '$CPIO' command succeeds to support NFSv4 ACLs & xattrs.
 131 cleanup $STF_PASS