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