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
28#
29# Copyright (c) 2013, 2016 by Delphix. All rights reserved.
30#
31
32. $STF_SUITE/tests/functional/delegate/delegate_common.kshlib
33
34#
35# DESCRIPTION:
36#	non-root user can allow any permissions which he is holding to
37#	other else user when it get 'allow' permission.
38#
39# STRATEGY:
40#	1. Set two set permissions to two datasets locally.
41#	2. Verify the non-root user can allow permission if he has allow
42#	   permission.
43#
44
45verify_runnable "both"
46
47log_assert "Verify non-root user can allow permissions."
48log_onexit restore_root_datasets
49
50perms1="snapshot,reservation"
51perms2="send,compression,checksum,userprop"
52childfs=$ROOT_TESTFS/childfs
53
54log_must zfs create $childfs
55
56for dtst in $DATASETS ; do
57	# Delegate local permission to $STAFF1
58	log_must zfs allow -l $STAFF1 $perms1 $dtst
59	log_must zfs allow -l $STAFF1 allow $dtst
60
61	if [[ $dtst == $ROOT_TESTFS ]]; then
62		log_must zfs allow -l $STAFF1 $perms2 $childfs
63		# $perms1 is local permission in $ROOT_TESTFS
64		log_mustnot user_run $STAFF1 zfs allow $OTHER1 $perms1 $childfs
65		log_must verify_noperm $childfs $perms1 $OTHER1
66	fi
67
68	# Verify 'allow' give non-privilege user delegated permission.
69	log_must user_run $STAFF1 zfs allow -l $OTHER1 $perms1 $dtst
70	log_must verify_perm $dtst $perms1 $OTHER1
71
72	# $perms2 was not allow to $STAFF1, so he have no permission to
73	# delegate permission to other else.
74	log_mustnot user_run $STAFF1 zfs allow $OTHER1 $perms2 $dtst
75	log_must verify_noperm $dtst $perms2 $OTHER1
76done
77
78log_pass "Verify non-root user can allow permissions passed."
79