1#!/usr/local/bin/ksh93 -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# $FreeBSD$
24
25#
26# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
27# Use is subject to license terms.
28#
29# ident	"@(#)history_009_pos.ksh	1.4	09/01/12 SMI"
30#
31
32. $STF_SUITE/tests/history/history_common.kshlib
33
34#################################################################################
35#
36# __stc_assertion_start
37#
38# ID: history_009_pos
39#
40# DESCRIPTION:
41#	Verify the delegation internal history are correctly.
42#
43# 	ul$<id>    identifies permssions granted locally for this userid.
44# 	ud$<id>    identifies permissions granted on descendent datasets for
45#		   this userid.
46#
47#	Ul$<id>    identifies permission sets granted locally for this userid.
48#	Ud$<id>    identifies permission sets granted on descendent datasets for
49#		   this	userid.
50#
51#	gl$<id>    identifies permissions granted locally for this groupid.
52#	gd$<id>    identifies permissions granted on descendent datasets for
53#		   this groupid.
54#
55#	Gl$<id>    identifies permission sets granted locally for this groupid.
56#	Gd$<id>    identifies permission sets granted on descendent datasets for
57#	           this groupid.
58#
59#	el$        identifies permissions granted locally for everyone.
60#	ed$        identifies permissions granted on descendent datasets for
61#		   everyone.
62#
63#	El$        identifies permission sets granted locally for everyone.
64#	Ed$        identifies permission sets granted to descendent datasets
65#		   for everyone.
66#
67#	c-$        identifies permission to create at dataset creation time.
68#	C-$        identifies permission sets to grant locally at dataset
69#		   creation time.
70#
71#	s-$@<name> permissions defined in specified set @<name>
72#	S-$@<name> Sets defined in named set @<name>
73#
74# STRATEGY:
75#	1. Create test group and user.
76#	2. Define permission sets and verify the internal history correctly.
77#	3. Separately verify the internal history above is correct.
78#
79# TESTABILITY: explicit
80#
81# TEST_AUTOMATION_LEVEL: automated
82#
83# CODING_STATUS: COMPLETED (2006-12-26)
84#
85# __stc_assertion_end
86#
87################################################################################
88
89verify_runnable "global"
90
91$ZFS 2>&1 | $GREP "allow" > /dev/null
92(($? != 0)) && log_unsupported
93
94function cleanup
95{
96	if [[ -f $REAL_HISTORY ]]; then
97		log_must $RM -f $REAL_HISTORY
98	fi
99	if [[ -f $ADD_HISTORY ]]; then
100		log_must $RM -f $ADD_HISTORY
101	fi
102	del_user $HIST_USER
103	del_group $HIST_GROUP
104}
105
106log_assert "Verify the delegation internal history are correctly."
107log_onexit cleanup
108
109testfs=$TESTPOOL/$TESTFS
110# Create history test group and user and get user id and group id
111add_group $HIST_GROUP
112add_user $HIST_GROUP $HIST_USER
113
114uid=$($ID $HIST_USER | $AWK -F= '{print $2}'| $AWK -F"(" '{print $1}' )
115gid=$($ID $HIST_USER | $AWK -F= '{print $3}'| $AWK -F"(" '{print $1}' )
116
117# Initial original $REAL_HISTORY
118format_history $TESTPOOL $REAL_HISTORY -i
119
120#
121#	Keyword		subcmd		operating	allow_options
122#
123set -A array \
124	"s-\$@basic"	"allow"		"-s @basic snapshot"    	\
125	"S-\$@set"	"allow"		"-s @set @basic"		\
126	"c-\\$"		"allow"		"-c create"			\
127	"c-\\$"		"unallow"	"-c create"			\
128	"C-\\$ @set"	"allow"		"-c @set"			\
129	"C-\\$ @set"	"unallow"	"-c @set"			\
130	"ul\$$uid"	"allow"		"-l -u $HIST_USER snapshot"	\
131	"ul\$$uid"	"allow"		"-u $HIST_USER snapshot"	\
132	"ul\$$uid"	"unallow"	"-u $HIST_USER snapshot"	\
133	"Ul\$$uid"	"allow"		"-l -u $HIST_USER @set"		\
134	"Ul\$$uid"	"allow"		"-u $HIST_USER @set"		\
135	"Ul\$$uid"	"unallow"	"-u $HIST_USER @set"		\
136	"ud\$$uid"	"allow"		"-d -u $HIST_USER snapshot"	\
137	"ud\$$uid"	"allow"		"-u $HIST_USER snapshot"	\
138	"ud\$$uid"	"unallow"	"-u $HIST_USER snapshot"	\
139	"Ud\$$uid"	"allow"		"-d -u $HIST_USER @set"		\
140	"Ud\$$uid"	"allow"		"-u $HIST_USER @set"		\
141	"Ud\$$uid"	"unallow"	"-u $HIST_USER @set"		\
142	"gl\$$gid"	"allow"		"-l -g $HIST_GROUP snapshot"	\
143	"gl\$$gid"	"allow"		"-g $HIST_GROUP snapshot"	\
144	"gl\$$gid"	"unallow"	"-g $HIST_GROUP snapshot"	\
145	"Gl\$$gid"	"allow"		"-l -g $HIST_GROUP @set"	\
146	"Gl\$$gid"	"allow"		"-g $HIST_GROUP @set"		\
147	"Gl\$$gid"	"unallow"	"-g $HIST_GROUP @set"		\
148	"gd\$$gid"	"allow"		"-d -g $HIST_GROUP snapshot"	\
149	"gd\$$gid"	"allow"		"-g $HIST_GROUP snapshot"	\
150	"gd\$$gid"	"unallow"	"-g $HIST_GROUP snapshot"	\
151	"Gd\$$gid"	"allow"		"-d -g $HIST_GROUP @set"	\
152	"Gd\$$gid"	"allow"		"-g $HIST_GROUP @set"		\
153	"Gd\$$gid"	"unallow"	"-g $HIST_GROUP @set"		\
154	"el\\$"		"allow"		"-l -e snapshot"		\
155	"el\\$"		"allow"		"-e snapshot"			\
156	"el\\$"		"unallow"	"-e snapshot"			\
157	"El\\$"		"allow"		"-l -e @set"			\
158	"El\\$"		"allow"		"-e @set"			\
159	"El\\$"		"unallow"	"-e @set"			\
160	"ed\\$"		"allow"		"-d -e snapshot"		\
161	"ed\\$"		"allow"		"-e snapshot"			\
162	"ed\\$"		"unallow"	"-e snapshot"			\
163	"Ed\\$"		"allow"		"-d -e @set"			\
164	"Ed\\$"		"allow"		"-e @set"			\
165	"Ed\\$"		"unallow"	"-e @set"
166
167typeset -i i=0
168while ((i < ${#array[@]})); do
169	keyword=${array[$i]}
170	subcmd=${array[((i+1))]}
171	options=${array[((i+2))]}
172
173	log_must $ZFS $subcmd $options $testfs
174	additional_history $TESTPOOL $ADD_HISTORY -i
175	log_must verify_history $ADD_HISTORY $subcmd $testfs $keyword
176
177	((i += 3))
178done
179
180log_pass "Verify the delegation internal history are correctly."
181