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_cpio_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_cpio_002_pos
39#
40# DESCRIPTION:
41# Verify that '$CPIO' command with -P@ option supports to archive ZFS ACLs
42#
43# STRATEGY:
44# 1. Create file and directory in zfs filesystem
45# 2. Add new ACE in ACL or change mode of file and directory
46# 3. Create xattr of the file and directory
47# 4. Use $CPIO to archive file and directory
48# 5. Extract the archive file
49# 6. Verify that the restored ACLs of file and directory identify
50#    with the origional ones.
51#
52# TESTABILITY: explicit
53#
54# TEST_AUTOMATION_LEVEL: automated
55#
56# CODING_STATUS: COMPLETED (2005-09-26)
57#
58# __stc_assertion_end
59#
60################################################################################
61
62verify_runnable "both"
63
64function cleanup
65{
66	if datasetexists $TESTPOOL/$TESTFS1; then
67		log_must $ZFS destroy -f $TESTPOOL/$TESTFS1
68	fi
69	if (( ${#orig_dir} != 0 )); then
70		cd $orig_dir
71	fi
72	[[ -d $TESTDIR1 ]] && log_must $RM -rf $TESTDIR1
73	[[ -d $TESTDIR ]] && log_must $RM -rf $TESTDIR/*
74}
75
76log_assert "Verify that '$CPIO' 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" \
82	"A3+user:$ZFS_ACL_OTHER1:write_data:deny" \
83	"A5+group:$ZFS_ACL_OTHER_GROUP:read_data:deny" \
84	"A0+user:$ZFS_ACL_OTHER1:write_data:deny"
85
86log_note "Create second zfs file system to restore the cpio archive."
87log_must $ZFS create $TESTPOOL/$TESTFS1
88log_must $ZFS set mountpoint=$TESTDIR1 $TESTPOOL/$TESTFS1
89log_must $CHMOD 777 $TESTDIR1
90
91# Define test fine and record the original directory.
92CPIOFILE=cpiofile.${TESTCASE_ID}
93file=$TESTFILE0
94dir=dir.${TESTCASE_ID}
95orig_dir=$PWD
96MYTESTFILE=$STF_SUITE/include/default.cfg
97
98typeset user
99for user in root $ZFS_ACL_STAFF1; do
100	# Set the current user
101	log_must set_cur_usr $user
102
103	typeset -i i=0
104	while (( i < ${#ops[*]} )); do
105		log_note "Create file $file and directory $dir " \
106			"in zfs filesystem. "
107		cd $TESTDIR
108		log_must usr_exec $TOUCH $file
109		log_must usr_exec $MKDIR $dir
110		log_must usr_exec $RUNAT $file $CP $MYTESTFILE attr.0
111		log_must usr_exec $RUNAT $dir $CP $MYTESTFILE attr.0
112
113		log_note "Change the ACLs of file and directory with " \
114			"'$CHMOD ${ops[i]}'."
115		for obj in $file $dir; do
116			log_must usr_exec $CHMOD ${ops[i]} $obj
117		done
118
119		log_note "Archive the file and directory."
120		cd $TESTDIR
121		log_must eval "usr_exec $LS | " \
122			"usr_exec $CPIO -ocP@ -O $CPIOFILE > /dev/null 2>&1"
123
124		log_note "Restore the cpio archive."
125		log_must usr_exec $MV $CPIOFILE $TESTDIR1
126		cd $TESTDIR1
127		log_must eval "usr_exec $CAT $CPIOFILE | " \
128			"usr_exec $CPIO -icP@ > /dev/null 2>&1"
129
130		log_note "Verify that the ACLs of restored file/directory " \
131			"have no changes."
132		for obj in $file $dir; do
133			log_must compare_modes $TESTDIR/$obj $TESTDIR1/$obj
134			log_must compare_acls $TESTDIR/$obj $TESTDIR1/$obj
135			log_must compare_xattrs $TESTDIR/$obj $TESTDIR1/$obj
136		done
137
138		log_must usr_exec $RM -rf $TESTDIR/* $TESTDIR1/*
139
140		(( i = i + 1 ))
141	done
142done
143
144log_pass "'$CPIO' command succeeds to support ZFS ACLs & xattrs."
145