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 https://opensource.org/licenses/CDDL-1.0.
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) 2011, 2016 by Delphix. All rights reserved.
30#
31
32. $STF_SUITE/include/libtest.shlib
33
34#
35# DESCRIPTION:
36# 'zfs inherit' should return an error with bad parameters in one command.
37#
38# STRATEGY:
39# 1. Set an array of bad options and invalid properties to 'zfs inherit'
40# 2. Execute 'zfs inherit' with bad options and passing invalid properties
41# 3. Verify an error is returned.
42#
43
44verify_runnable "both"
45
46function cleanup
47{
48	snapexists $TESTPOOL/$TESTFS@$TESTSNAP && \
49		destroy_dataset $TESTPOOL/$TESTFS@$TESTSNAP
50}
51
52log_assert "'zfs inherit' should return an error with bad parameters in" \
53    "one command."
54log_onexit cleanup
55
56set -A badopts "r" "R" "-R" "-rR" "-a" "-" "-?" "-1" "-2" "-v" "-n"
57set -A props "recordsize" "mountpoint" "sharenfs" "checksum" "compression" \
58    "atime" "devices" "exec" "setuid" "readonly" "snapdir" "aclmode" \
59    "aclinherit" "xattr" "copies"
60if is_freebsd; then
61	props+=("jailed")
62else
63	props+=("zoned")
64fi
65set -A illprops "recordsiz" "mountpont" "sharen" "compres" "atme" "blah"
66
67log_must zfs snapshot $TESTPOOL/$TESTFS@$TESTSNAP
68
69typeset -i i=0
70for ds in $TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL \
71	$TESTPOOL/$TESTFS@$TESTSNAP; do
72
73	# zfs inherit should fail with bad options
74	for opt in ${badopts[@]}; do
75		for prop in ${props[@]}; do
76			log_mustnot eval "zfs inherit $opt $prop $ds \
77			    >/dev/null 2>&1"
78		done
79	done
80
81	# zfs inherit should fail with invalid properties
82	for prop in "${illprops[@]}"; do
83		log_mustnot eval "zfs inherit $prop $ds >/dev/null 2>&1"
84		log_mustnot eval "zfs inherit -r $prop $ds >/dev/null 2>&1"
85	done
86
87	# zfs inherit should fail with too many arguments
88	(( i = 0 ))
89	while (( i < ${#props[*]} -1 )); do
90		log_mustnot eval "zfs inherit ${props[(( i ))]} \
91				${props[(( i + 1 ))]} $ds >/dev/null 2>&1"
92		log_mustnot eval "zfs inherit -r ${props[(( i ))]} \
93				${props[(( i + 1 ))]} $ds >/dev/null 2>&1"
94
95		(( i = i + 2 ))
96	done
97
98done
99
100# zfs inherit should fail with missing datasets
101for prop in ${props[@]}; do
102	log_mustnot eval "zfs inherit $prop >/dev/null 2>&1"
103	log_mustnot eval "zfs inherit -r $prop >/dev/null 2>&1"
104done
105
106log_pass "'zfs inherit' failed as expected when passing illegal arguments."
107