xref: /illumos-gate/usr/src/test/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_cpio_002_pos.ksh (revision 5f82aa32fbc5dc2c59bca6ff315f44a4c4c9ea86)
1#!/bin/ksh -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# Copyright (c) 2012 by Marcelo Leal. All rights reserved.
28#
29
30#
31# Copyright (c) 2016 by Delphix. All rights reserved.
32#
33
34. $STF_SUITE/tests/functional/acl/acl_common.kshlib
35
36#
37# DESCRIPTION:
38# Verify that 'cpio' 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 or change mode of file and directory
43# 3. Create xattr of the file and directory
44# 4. Use cpio to archive file and directory
45# 5. Extract the archive file
46# 6. Verify that the restored ACLs of file and directory identify
47#    with the origional ones.
48#
49
50verify_runnable "both"
51
52function cleanup
53{
54	if datasetexists $TESTPOOL/$TESTFS1; then
55		log_must zfs destroy -f $TESTPOOL/$TESTFS1
56	fi
57	if (( ${#orig_dir} != 0 )); then
58		cd $orig_dir
59	fi
60	[[ -d $TESTDIR1 ]] && log_must rm -rf $TESTDIR1
61	[[ -d $TESTDIR ]] && log_must rm -rf $TESTDIR/*
62}
63
64log_assert "Verify that 'cpio' command supports to archive ZFS ACLs & xattrs."
65log_onexit cleanup
66
67set -A ops "A+user:$ZFS_ACL_OTHER1:execute:allow" \
68	"A3+user:$ZFS_ACL_OTHER1:write_data:deny" \
69	"A0+user:$ZFS_ACL_OTHER1:write_data:deny" \
70	"A3+group:$ZFS_ACL_OTHER_GROUP:read_data:deny" \
71	"A1=user:$ZFS_ACL_STAFF1:write_data:deny" \
72	"A1=group:$ZFS_ACL_STAFF_GROUP:write_data:deny"
73
74log_note "Create second zfs file system to restore the cpio archive."
75log_must zfs create $TESTPOOL/$TESTFS1
76log_must zfs set mountpoint=$TESTDIR1 $TESTPOOL/$TESTFS1
77log_must chmod 777 $TESTDIR1
78
79# Define test fine and record the original directory.
80CPIOFILE=cpiofile.$$
81file=$TESTFILE0
82dir=dir.$$
83orig_dir=$PWD
84mytestfile=/kernel/drv/zfs
85
86typeset user
87for user in root $ZFS_ACL_STAFF1; do
88	# Set the current user
89	log_must set_cur_usr $user
90
91	typeset -i i=0
92	while (( i < ${#ops[*]} )); do
93		log_note "Create file $file and directory $dir " \
94			"in zfs filesystem. "
95		cd $TESTDIR
96		log_must usr_exec touch $file
97		log_must usr_exec mkdir $dir
98		log_must usr_exec runat $file cp $mytestfile attr.0
99		log_must usr_exec runat $dir cp $mytestfile attr.0
100
101		log_note "Change the ACLs of file and directory with " \
102			"'chmod ${ops[i]}'."
103		for obj in $file $dir; do
104			log_must usr_exec chmod ${ops[i]} $obj
105		done
106
107		log_note "Archive the file and directory."
108		cd $TESTDIR
109		log_must eval "usr_exec ls | " \
110			"usr_exec cpio -ocP@ -O $CPIOFILE > /dev/null 2>&1"
111
112		log_note "Restore the cpio archive."
113		log_must usr_exec mv $CPIOFILE $TESTDIR1
114		cd $TESTDIR1
115		log_must eval "usr_exec cat $CPIOFILE | " \
116			"usr_exec cpio -icP@ > /dev/null 2>&1"
117
118		log_note "Verify that the ACLs of restored file/directory " \
119			"have no changes."
120		for obj in $file $dir; do
121			log_must compare_modes $TESTDIR/$obj $TESTDIR1/$obj
122			log_must compare_acls $TESTDIR/$obj $TESTDIR1/$obj
123			log_must compare_xattrs $TESTDIR/$obj $TESTDIR1/$obj
124		done
125
126		log_must usr_exec rm -rf $TESTDIR/* $TESTDIR1/*
127
128		(( i = i + 1 ))
129	done
130done
131
132log_pass "'cpio' command succeeds to support ZFS ACLs & xattrs."
133