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