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 2008 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26#
27
28#
29# Copyright (c) 2013, 2016 by Delphix. All rights reserved.
30# Copyright 2023 Bill Sommerfeld <sommerfeld@alum.mit.edu>
31#
32
33. $STF_SUITE/tests/functional/delegate/delegate_common.kshlib
34
35#
36# DESCRIPTION:
37#	Verify the permissions set will be masked on its descendent
38#	datasets by same name set.
39#
40# STRATEGY:
41#	1. Create $ROOT_TESTFS/childfs
42#	2. Set permission $perms1 to @set on $ROOT_TESTFS
43#	3. Reset permission $perms2 to @set on $ROOT_TESTFS/childfs
44#	4. Allow @set to $STAFF1 on $ROOT_TESTFS/childfs
45#	5. Verify $perms2 is delegated on $ROOT_TESTFS/childfs and its
46#	   descendent.
47#	6. Allow @set to $STAFF1 on $ROOT_TESTFS
48#	7. Verify $perms1 is not appended to $STAFF1 on $ROOT_TESTFS/childfs and
49#	   its descendent since it is masked
50#
51
52verify_runnable "both"
53
54log_assert "Verify permission set can be masked on descendent dataset."
55log_onexit restore_root_datasets
56
57typeset perms1="snapshot,reservation,compression"
58eval set -A dataset $DATASETS
59typeset perms2="checksum,send,userprop"
60
61#
62# Define three level filesystems
63#
64childfs=$ROOT_TESTFS/childfs
65grandchild=$childfs/grandchild
66log_must zfs create $childfs
67log_must zfs create $grandchild
68
69#
70# Setting different permissions to the same set on two level.
71# But only assign the user at one level.
72#
73log_must zfs allow -s @set $perms1 $ROOT_TESTFS
74log_must zfs allow -s @set $perms2 $childfs
75log_must zfs allow $STAFF1 @set $childfs
76
77#
78# Verify section header is correct in output
79#
80
81typeset sortedperms=$(echo "$perms1" | tr ',' '\n' |
82			  sort | tr '\n' ',' | sed 's/,$//')
83verify_allow_output $ROOT_TESTFS \
84		    "Permission sets" "@set $sortedperms"
85
86#
87# Verify only perms2 is valid to user on the level which he was assigned.
88#
89log_must verify_noperm $ROOT_TESTFS $perms1 $STAFF1
90for fs in $childfs $grandchild ; do
91	log_must verify_noperm $fs $perms1 $STAFF1
92	log_must verify_perm $fs $perms2 $STAFF1
93done
94
95#
96# Delegate @set to STAFF1 on ROOT_TESTFS, verify $perms1 will not be appended
97# to its descendent datasets since it is masked
98#
99log_must zfs allow $STAFF1 @set $ROOT_TESTFS
100log_must verify_perm $ROOT_TESTFS $perms1 $STAFF1
101for fs in $childfs $grandchild ; do
102	log_must verify_noperm $fs $perms1 $STAFF1
103	log_must verify_perm $fs $perms2 $STAFF1
104done
105
106# Remove the mask, $perms1 will be allowed to its descendent datasets
107log_must zfs unallow -s @set $childfs
108for fs in $childfs $grandchild ; do
109	log_must verify_noperm $fs $perms2 $STAFF1
110	log_must verify_perm $fs $perms1 $STAFF1
111done
112
113log_pass "Verify permission set can be masked on descendent dataset pass."
114