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