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 2009 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 option '-c' will be granted locally to the creator on any
38#	newly-created descendent file systems.
39#
40# STRATEGY:
41#	1. Allow create permissions to everyone on $ROOT_TESTFS locally.
42#	2. Allow '-c' create to $ROOT_TESTFS.
43#	3. chmod 777 the mountpoint of $ROOT_TESTFS
44#	4. Verify only creator can create descendent dataset on
45#	   $ROOT_TESTFS/$user.
46#
47
48verify_runnable "both"
49
50log_assert "Verify option '-c' will be granted locally to the creator."
51log_onexit restore_root_datasets
52
53eval set -A dataset $DATASETS
54typeset perms="snapshot,reservation,compression,checksum,userprop"
55
56log_must zfs allow -l everyone create,mount $ROOT_TESTFS
57log_must zfs allow -c $perms $ROOT_TESTFS
58
59#
60# Verify section headers are correct in allow output
61#
62typeset sortedperms=$(echo "$perms" | tr ',' '\n' |
63			  sort | tr '\n' ',' | sed 's/,$//')
64verify_allow_output $ROOT_TESTFS \
65		    "Create time permissions" "$sortedperms" \
66		    "Local permissions" "everyone create,mount"
67
68mntpnt=$(get_prop mountpoint $ROOT_TESTFS)
69log_must chmod 777 $mntpnt
70
71for user in $EVERYONE; do
72	childfs=$ROOT_TESTFS/$user
73
74	user_run $user zfs create $childfs
75
76	for other in $EVERYONE; do
77		#
78		# Verify only the creator has the $perm time permissions.
79		#
80		if [[ $other == $user ]]; then
81			log_must verify_perm $childfs $perms $user
82		else
83			log_must verify_noperm $childfs $perms $other
84		fi
85	done
86done
87
88log_pass "Verify option '-c' will be granted locally to the creator passed."
89