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 '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
49verify_runnable "both"
50
51function cleanup
52{
53	if datasetexists $TESTPOOL/$TESTFS1; then
54		log_must zfs destroy -f $TESTPOOL/$TESTFS1
55	fi
56
57	(( ${#cwd} != 0 )) && cd $cwd
58	[[ -d $TESTDIR1 ]] && log_must rm -rf $TESTDIR1
59	[[ -d $TESTDIR/ ]] && log_must rm -rf $TESTDIR/*
60}
61
62log_assert "Verify that 'tar' command supports to archive ZFS ACLs."
63
64log_onexit cleanup
65
66set -A ops " A+user:other1:add_file:allow" "A+everyone@:execute:allow" "a-x" "777"
67
68TARFILE=tarfile.$$.tar
69file=$TESTFILE0
70dir=dir.$$
71cwd=$PWD
72
73log_note "Create second zfs file system to restore the tar archive."
74log_must zfs create $TESTPOOL/$TESTFS1
75[[ ! -d $TESTDIR1 ]] && \
76	log_must mkdir -p $TESTDIR1
77log_must zfs set mountpoint=$TESTDIR1 $TESTPOOL/$TESTFS1
78
79log_note "Create a file: $file, and directory: $dir, in zfs filesystem. "
80cd $TESTDIR
81log_must touch $file
82log_must mkdir $dir
83
84typeset -i i=0
85while (( i < ${#ops[*]} ))
86do
87	log_note "Change the ACLs of file and directory with " \
88		"'chmod ${ops[i]}'."
89	cd $TESTDIR
90	for obj in $file $dir; do
91		log_must chmod ${ops[i]} $obj
92	done
93	log_note "Archive the file and directory."
94	log_must tar cpf $TARFILE $file $dir
95
96	log_note "Restore the tar archive."
97	log_must mv $TARFILE $TESTDIR1
98	cd $TESTDIR1
99	log_must tar xpf $TARFILE
100
101	log_note "Verify the ACLs of restored file/directory have no changes."
102	for obj in $file $dir; do
103		log_must compare_modes $TESTDIR/$obj $TESTDIR1/$obj
104		log_must compare_acls $TESTDIR/$obj $TESTDIR1/$obj
105	done
106
107	log_must rm -rf $TESTDIR1/*
108
109	(( i = i + 1 ))
110done
111
112log_pass "'tar' command succeeds to support ZFS ACLs."
113