1#!/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# Copyright (c) 2012 by Marcelo Leal. All rights reserved. 28# 29 30# 31# Copyright (c) 2016, 2018 by Delphix. All rights reserved. 32# 33 34. $STF_SUITE/tests/functional/acl/acl_common.kshlib 35 36# 37# DESCRIPTION: 38# Verify that 'tar' command with -p@ option supports to archive ZFS ACLs 39# & xattrs 40# 41# STRATEGY: 42# 1. Create file and directory in zfs filesystem 43# 2. Add new ACE in ACL of file and directory 44# 3. Create xattr of the file and directory 45# 4. Use tar cf@ to archive file and directory 46# 5. Use tar xf@ to extract the archive file 47# 6. Verify that the restored ACLs & xttrs of file and directory identify 48# with the origional ones. 49# 50 51verify_runnable "both" 52 53function cleanup 54{ 55 if datasetexists $TESTPOOL/$TESTFS1; then 56 log_must zfs destroy -f $TESTPOOL/$TESTFS1 57 fi 58 59 (( ${#cwd} != 0 )) && cd $cwd 60 log_must rm -rf $TESTDIR1 $TESTDIR/* $mytestfile 61} 62 63log_assert "Verify that 'tar' command supports to archive ZFS ACLs & xattrs." 64 65log_onexit cleanup 66 67set -A ops " A+user:other1:add_file:allow" "A+everyone@:execute:allow" "a-x" \ 68 "777" 69mytestfile=$(mktemp -t file.XXXX) 70log_must dd if=/dev/urandom of=$mytestfile bs=1024k count=1 71log_must chmod 644 $mytestfile 72 73TARFILE=tarfile.$$.tar 74cwd=$PWD 75 76log_note "Create second zfs file system to restore the tar archive." 77log_must zfs create $TESTPOOL/$TESTFS1 78[[ ! -d $TESTDIR1 ]] && \ 79 log_must mkdir -p $TESTDIR1 80log_must zfs set mountpoint=$TESTDIR1 $TESTPOOL/$TESTFS1 81 82log_note "Create a file: $testfile, and directory: $testdir, in zfs " \ 83 "filesystem. And prepare for there xattr files." 84 85for user in root $ZFS_ACL_STAFF1; do 86 # Set the current user 87 log_must set_cur_usr $user 88 89 # Create source object and target directroy 90 cd $TESTDIR 91 log_must usr_exec touch $testfile 92 log_must usr_exec mkdir $testdir 93 94 log_must usr_exec runat $testfile cp $mytestfile attr.0 95 log_must usr_exec runat $testdir cp $mytestfile attr.0 96 97 # Add the new ACE on the head. 98 log_note "Change the ACLs of file and directory with " \ 99 "'chmod ${ops[0]}'." 100 log_must usr_exec chmod ${ops[0]} $testfile 101 log_must usr_exec chmod ${ops[0]} $testdir 102 103 log_note "Archive the file and directory." 104 log_must tar cpf@ $TARFILE ${testfile#$TESTDIR/} ${testdir#$TESTDIR/} 105 106 log_note "Restore the tar archive." 107 cd $TESTDIR1 108 log_must tar xpf@ $TESTDIR/$TARFILE 109 110 log_note "Verify the ACLs of restored file/directory have no changes." 111 for obj in $testfile $testdir; do 112 log_must compare_modes $obj $TESTDIR1/${obj##*/} 113 log_must compare_acls $obj $TESTDIR1/${obj##*/} 114 log_must compare_xattrs $obj $TESTDIR1/${obj##*/} 115 done 116 117 log_must rm -rf $TESTDIR/* $TESTDIR1/* 118done 119 120log_pass "'tar' command succeeds to support ZFS ACLs." 121