1#!/usr/local/bin/ksh93 -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. $STF_SUITE/tests/acl/acl_common.kshlib
27
28################################################################################
29#
30# __stc_assertion_start
31#
32# ID: zfs_acl_tar_001_pos
33#
34# DESCRIPTION:
35# Verify that '$TAR' command with -p option supports to archive ZFS ACLs
36#
37# STRATEGY:
38# 1. Create file and directory in zfs filesystem
39# 2. Add new ACE in ACL of file and directory
40# 3. Use $TAR to archive file and directory
41# 4. Extract the archive file
42# 5. Verify that the restored ACLs of file and directory identify
43#    with the origional ones.
44#
45# TESTABILITY: explicit
46#
47# TEST_AUTOMATION_LEVEL: automated
48#
49# CODING_STATUS: COMPLETED (2005-09-26)
50#
51# __stc_assertion_end
52#
53################################################################################
54
55verify_runnable "both"
56
57function cleanup
58{
59	if datasetexists $TESTPOOL/$TESTFS1; then
60		log_must $ZFS destroy -f $TESTPOOL/$TESTFS1
61	fi
62
63	(( ${#cwd} != 0 )) && cd $cwd
64	[[ -d $TESTDIR1 ]] && log_must $RM -rf $TESTDIR1
65	[[ -d $TESTDIR/ ]] && log_must $RM -rf $TESTDIR/*
66}
67
68log_assert "Verify that '$TAR' command supports to archive ZFS ACLs."
69log_onexit cleanup
70
71test_requires ZFS_ACL
72
73set -A ops " A+everyone@:execute:allow" "a-x" "777"
74
75TARFILE=tarfile.${TESTCASE_ID}.tar
76file=$TESTFILE0
77dir=dir.${TESTCASE_ID}
78cwd=$PWD
79
80log_note "Create second zfs file system to restore the tar archive."
81log_must $ZFS create $TESTPOOL/$TESTFS1
82[[ ! -d $TESTDIR1 ]] && \
83	log_must $MKDIR -p $TESTDIR1
84log_must $ZFS set mountpoint=$TESTDIR1 $TESTPOOL/$TESTFS1
85
86log_note "Create a file: $file, and directory: $dir, in zfs filesystem. "
87cd $TESTDIR
88log_must $TOUCH $file
89log_must $MKDIR $dir
90
91typeset -i i=0
92while (( i < ${#ops[*]} ))
93do
94	log_note "Change the ACLs of file and directory with " \
95		"'$CHMOD ${ops[i]}'."
96	cd $TESTDIR
97	for obj in $file $dir; do
98		log_must $CHMOD ${ops[i]} $obj
99	done
100	log_note "Archive the file and directory."
101	log_must $TAR cpf $TARFILE $file $dir
102
103	log_note "Restore the tar archive."
104	log_must $MV $TARFILE $TESTDIR1
105	cd $TESTDIR1
106	log_must $TAR xpf $TARFILE
107
108	log_note "Verify the ACLs of restored file/directory have no changes."
109	for obj in $file $dir; do
110		log_must compare_modes $TESTDIR/$obj $TESTDIR1/$obj
111		log_must compare_acls $TESTDIR/$obj $TESTDIR1/$obj
112	done
113
114	log_must $RM -rf $TESTDIR1/*
115
116	(( i = i + 1 ))
117done
118
119log_pass "'$TAR' command succeeds to support ZFS ACLs."
120