1d583b39bSJohn Wren Kennedy#!/bin/ksh -p 2d583b39bSJohn Wren Kennedy# 3d583b39bSJohn Wren Kennedy# CDDL HEADER START 4d583b39bSJohn Wren Kennedy# 5d583b39bSJohn Wren Kennedy# The contents of this file are subject to the terms of the 6d583b39bSJohn Wren Kennedy# Common Development and Distribution License (the "License"). 7d583b39bSJohn Wren Kennedy# You may not use this file except in compliance with the License. 8d583b39bSJohn Wren Kennedy# 9d583b39bSJohn Wren Kennedy# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10d583b39bSJohn Wren Kennedy# or http://www.opensolaris.org/os/licensing. 11d583b39bSJohn Wren Kennedy# See the License for the specific language governing permissions 12d583b39bSJohn Wren Kennedy# and limitations under the License. 13d583b39bSJohn Wren Kennedy# 14d583b39bSJohn Wren Kennedy# When distributing Covered Code, include this CDDL HEADER in each 15d583b39bSJohn Wren Kennedy# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16d583b39bSJohn Wren Kennedy# If applicable, add the following below this CDDL HEADER, with the 17d583b39bSJohn Wren Kennedy# fields enclosed by brackets "[]" replaced with your own identifying 18d583b39bSJohn Wren Kennedy# information: Portions Copyright [yyyy] [name of copyright owner] 19d583b39bSJohn Wren Kennedy# 20d583b39bSJohn Wren Kennedy# CDDL HEADER END 21d583b39bSJohn Wren Kennedy# 22d583b39bSJohn Wren Kennedy 23d583b39bSJohn Wren Kennedy# 24d583b39bSJohn Wren Kennedy# Copyright 2007 Sun Microsystems, Inc. All rights reserved. 25d583b39bSJohn Wren Kennedy# Use is subject to license terms. 26d583b39bSJohn Wren Kennedy# 27d583b39bSJohn Wren Kennedy# Copyright (c) 2012 by Marcelo Leal. All rights reserved. 28d583b39bSJohn Wren Kennedy# 29d583b39bSJohn Wren Kennedy 301d32ba66SJohn Wren Kennedy# 31*a01b7f54SJohn Wren Kennedy# Copyright (c) 2016, 2018 by Delphix. All rights reserved. 321d32ba66SJohn Wren Kennedy# 331d32ba66SJohn Wren Kennedy 34d583b39bSJohn Wren Kennedy. $STF_SUITE/tests/functional/acl/acl_common.kshlib 35d583b39bSJohn Wren Kennedy 36d583b39bSJohn Wren Kennedy# 37d583b39bSJohn Wren Kennedy# DESCRIPTION: 381d32ba66SJohn Wren Kennedy# Verify that 'tar' command with -p@ option supports to archive ZFS ACLs 39d583b39bSJohn Wren Kennedy# & xattrs 40d583b39bSJohn Wren Kennedy# 41d583b39bSJohn Wren Kennedy# STRATEGY: 42d583b39bSJohn Wren Kennedy# 1. Create file and directory in zfs filesystem 43d583b39bSJohn Wren Kennedy# 2. Add new ACE in ACL of file and directory 44d583b39bSJohn Wren Kennedy# 3. Create xattr of the file and directory 451d32ba66SJohn Wren Kennedy# 4. Use tar cf@ to archive file and directory 461d32ba66SJohn Wren Kennedy# 5. Use tar xf@ to extract the archive file 47d583b39bSJohn Wren Kennedy# 6. Verify that the restored ACLs & xttrs of file and directory identify 48d583b39bSJohn Wren Kennedy# with the origional ones. 49d583b39bSJohn Wren Kennedy# 50d583b39bSJohn Wren Kennedy 51d583b39bSJohn Wren Kennedyverify_runnable "both" 52d583b39bSJohn Wren Kennedy 53d583b39bSJohn Wren Kennedyfunction cleanup 54d583b39bSJohn Wren Kennedy{ 55d583b39bSJohn Wren Kennedy if datasetexists $TESTPOOL/$TESTFS1; then 561d32ba66SJohn Wren Kennedy log_must zfs destroy -f $TESTPOOL/$TESTFS1 57d583b39bSJohn Wren Kennedy fi 58d583b39bSJohn Wren Kennedy 59d583b39bSJohn Wren Kennedy (( ${#cwd} != 0 )) && cd $cwd 60*a01b7f54SJohn Wren Kennedy log_must rm -rf $TESTDIR1 $TESTDIR/* $mytestfile 61d583b39bSJohn Wren Kennedy} 62d583b39bSJohn Wren Kennedy 631d32ba66SJohn Wren Kennedylog_assert "Verify that 'tar' command supports to archive ZFS ACLs & xattrs." 64d583b39bSJohn Wren Kennedy 65d583b39bSJohn Wren Kennedylog_onexit cleanup 66d583b39bSJohn Wren Kennedy 67d583b39bSJohn Wren Kennedyset -A ops " A+user:other1:add_file:allow" "A+everyone@:execute:allow" "a-x" \ 68d583b39bSJohn Wren Kennedy "777" 69*a01b7f54SJohn Wren Kennedymytestfile=$(mktemp -t file.XXXX) 70*a01b7f54SJohn Wren Kennedylog_must dd if=/dev/urandom of=$mytestfile bs=1024k count=1 71*a01b7f54SJohn Wren Kennedylog_must chmod 644 $mytestfile 72d583b39bSJohn Wren Kennedy 73d583b39bSJohn Wren KennedyTARFILE=tarfile.$$.tar 74d583b39bSJohn Wren Kennedycwd=$PWD 75d583b39bSJohn Wren Kennedy 76d583b39bSJohn Wren Kennedylog_note "Create second zfs file system to restore the tar archive." 771d32ba66SJohn Wren Kennedylog_must zfs create $TESTPOOL/$TESTFS1 78d583b39bSJohn Wren Kennedy[[ ! -d $TESTDIR1 ]] && \ 791d32ba66SJohn Wren Kennedy log_must mkdir -p $TESTDIR1 801d32ba66SJohn Wren Kennedylog_must zfs set mountpoint=$TESTDIR1 $TESTPOOL/$TESTFS1 81d583b39bSJohn Wren Kennedy 82d583b39bSJohn Wren Kennedylog_note "Create a file: $testfile, and directory: $testdir, in zfs " \ 83d583b39bSJohn Wren Kennedy "filesystem. And prepare for there xattr files." 84d583b39bSJohn Wren Kennedy 85d583b39bSJohn Wren Kennedyfor user in root $ZFS_ACL_STAFF1; do 86d583b39bSJohn Wren Kennedy # Set the current user 87d583b39bSJohn Wren Kennedy log_must set_cur_usr $user 88d583b39bSJohn Wren Kennedy 89d583b39bSJohn Wren Kennedy # Create source object and target directroy 90d583b39bSJohn Wren Kennedy cd $TESTDIR 911d32ba66SJohn Wren Kennedy log_must usr_exec touch $testfile 921d32ba66SJohn Wren Kennedy log_must usr_exec mkdir $testdir 93d583b39bSJohn Wren Kennedy 941d32ba66SJohn Wren Kennedy log_must usr_exec runat $testfile cp $mytestfile attr.0 951d32ba66SJohn Wren Kennedy log_must usr_exec runat $testdir cp $mytestfile attr.0 96d583b39bSJohn Wren Kennedy 97d583b39bSJohn Wren Kennedy # Add the new ACE on the head. 98d583b39bSJohn Wren Kennedy log_note "Change the ACLs of file and directory with " \ 991d32ba66SJohn Wren Kennedy "'chmod ${ops[0]}'." 1001d32ba66SJohn Wren Kennedy log_must usr_exec chmod ${ops[0]} $testfile 1011d32ba66SJohn Wren Kennedy log_must usr_exec chmod ${ops[0]} $testdir 102d583b39bSJohn Wren Kennedy 103d583b39bSJohn Wren Kennedy log_note "Archive the file and directory." 1041d32ba66SJohn Wren Kennedy log_must tar cpf@ $TARFILE ${testfile#$TESTDIR/} ${testdir#$TESTDIR/} 105d583b39bSJohn Wren Kennedy 106d583b39bSJohn Wren Kennedy log_note "Restore the tar archive." 107d583b39bSJohn Wren Kennedy cd $TESTDIR1 1081d32ba66SJohn Wren Kennedy log_must tar xpf@ $TESTDIR/$TARFILE 109d583b39bSJohn Wren Kennedy 110d583b39bSJohn Wren Kennedy log_note "Verify the ACLs of restored file/directory have no changes." 111d583b39bSJohn Wren Kennedy for obj in $testfile $testdir; do 112d583b39bSJohn Wren Kennedy log_must compare_modes $obj $TESTDIR1/${obj##*/} 113d583b39bSJohn Wren Kennedy log_must compare_acls $obj $TESTDIR1/${obj##*/} 114d583b39bSJohn Wren Kennedy log_must compare_xattrs $obj $TESTDIR1/${obj##*/} 115d583b39bSJohn Wren Kennedy done 116d583b39bSJohn Wren Kennedy 1171d32ba66SJohn Wren Kennedy log_must rm -rf $TESTDIR/* $TESTDIR1/* 118d583b39bSJohn Wren Kennedydone 119d583b39bSJohn Wren Kennedy 1201d32ba66SJohn Wren Kennedylog_pass "'tar' command succeeds to support ZFS ACLs." 121