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# $FreeBSD$
24
25#
26# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
27# Use is subject to license terms.
28#
29# ident	"@(#)zfs_acl_tar_002_pos.ksh	1.2	07/01/09 SMI"
30#
31
32. $STF_SUITE/tests/acl/acl_common.kshlib
33
34################################################################################
35#
36# __stc_assertion_start
37#
38# ID: zfs_acl_tar_002_pos
39#
40# DESCRIPTION:
41# Verify that '$TAR' command with -p@ option supports to archive ZFS ACLs
42#	& xattrs
43#
44# STRATEGY:
45# 1. Create file and directory in zfs filesystem
46# 2. Add new ACE in ACL of file and directory
47# 3. Create xattr of the file and directory
48# 4. Use $TAR cf@ to archive file and directory
49# 5. Use $TAR xf@ to extract the archive file
50# 6. Verify that the restored ACLs & xttrs of file and directory identify
51#    with the origional ones.
52#
53# TESTABILITY: explicit
54#
55# TEST_AUTOMATION_LEVEL: automated
56#
57# CODING_STATUS: COMPLETED (2005-12-16)
58#
59# __stc_assertion_end
60#
61################################################################################
62
63verify_runnable "both"
64
65function cleanup
66{
67	if datasetexists $TESTPOOL/$TESTFS1; then
68		log_must $ZFS destroy -f $TESTPOOL/$TESTFS1
69	fi
70
71	(( ${#cwd} != 0 )) && cd $cwd
72	[[ -d $TESTDIR1 ]] && log_must $RM -rf $TESTDIR1
73	[[ -d $TESTDIR/ ]] && log_must $RM -rf $TESTDIR/*
74}
75
76log_assert "Verify that '$TAR' command supports to archive ZFS ACLs & xattrs."
77log_onexit cleanup
78
79test_requires RUNAT ZFS_ACL ZFS_XATTR
80
81set -A ops " A+everyone@:execute:allow" "a-x" "777"
82MYTESTFILE=$STF_SUITE/include/default.cfg
83
84TARFILE=tarfile.${TESTCASE_ID}.tar
85cwd=$PWD
86
87log_note "Create second zfs file system to restore the tar archive."
88log_must $ZFS create $TESTPOOL/$TESTFS1
89[[ ! -d $TESTDIR1 ]] && \
90	log_must $MKDIR -p $TESTDIR1
91log_must $ZFS set mountpoint=$TESTDIR1 $TESTPOOL/$TESTFS1
92
93log_note "Create a file: $testfile, and directory: $testdir, in zfs filesystem. " \
94	"And prepare for there xattr files."
95
96for user in root $ZFS_ACL_STAFF1; do
97	# Set the current user
98	log_must set_cur_usr $user
99
100	# Create source object and target directroy
101	cd $TESTDIR
102	log_must usr_exec $TOUCH $testfile
103	log_must usr_exec $MKDIR $testdir
104
105	log_must usr_exec $RUNAT $testfile $CP $MYTESTFILE attr.0
106	log_must usr_exec $RUNAT $testdir $CP $MYTESTFILE attr.0
107
108	# Add the new ACE on the head.
109	log_note "Change the ACLs of file and directory with " \
110		"'$CHMOD ${ops[0]}'."
111	log_must usr_exec $CHMOD ${ops[0]} $testfile
112	log_must usr_exec $CHMOD ${ops[0]} $testdir
113
114	log_note "Archive the file and directory."
115	log_must $TAR cpf@ $TARFILE ${testfile#$TESTDIR/} ${testdir#$TESTDIR/}
116
117	log_note "Restore the tar archive."
118	cd $TESTDIR1
119	log_must $TAR xpf@ $TESTDIR/$TARFILE
120
121	log_note "Verify the ACLs of restored file/directory have no changes."
122	for obj in $testfile $testdir; do
123		log_must compare_modes $obj $TESTDIR1/${obj##*/}
124		log_must compare_acls $obj $TESTDIR1/${obj##*/}
125		log_must compare_xattrs $obj $TESTDIR1/${obj##*/}
126	done
127
128	log_must $RM -rf $TESTDIR/* $TESTDIR1/*
129done
130
131log_pass "'$TAR' command succeeds to support ZFS ACLs."
132